Commit Graph

5358 Commits

Author SHA1 Message Date
Valentin Clement
06b4ce66d8
[flang] Add fir.select_type conversion to if-then-else ladder
Convert fir.select_type operation to an if-then-else ladder.
The type guards are sorted before the conversion so it follows the
execution of SELECT TYPE construct as mentioned in 11.1.11.2 point 4
of the Fortran standard.

Depends on D138279

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138280
2022-11-21 10:01:42 +01:00
Thomas Preud'homme
ad485b71b5 Add version to all LLVM cmake package
Add a version to non-LLVM cmake package so that users needing an exact
version match can use the version parameter to find_package. Also adjust
the find_package(LLVM) to use an exact version match as well.

Reviewed By: arsenm, stellaraccident

Differential Revision: https://reviews.llvm.org/D138274
2022-11-20 21:09:50 +00:00
Peixin Qiao
6ed85a62bd [flang] Support lowering of intrinsic GET_COMMAND
As Fortran 2018 16.9.82, all the arguments of GET_COMMAND are optional.
When they are all absent, do nothing so to be consistent with gfortran
and ifort. The semantic analysis and runtime have been supported.

This intrinsic was introduced from F2003, and this supports the lowering
of it.

Reviewed By: PeteSteinfeld, jeanPerier

Differential Revision: https://reviews.llvm.org/D137887
2022-11-19 19:26:17 +08:00
Slava Zakharin
1dd5ca2452 Revert "[flang] Use proper attributes for runtime calls with 'i1' arguments/returns."
Buildbot might be failing because of this:
https://lab.llvm.org/buildbot/#/builders/65/builds/7283

This reverts commit 396ead93e3.
2022-11-18 20:12:33 -08:00
Peixin Qiao
ae0e5a502b Revert "[flang] Support lowering of intrinsic GET_COMMAND"
This reverts commit 86ea67ed4e.
2022-11-19 11:51:25 +08:00
Peixin Qiao
86ea67ed4e [flang] Support lowering of intrinsic GET_COMMAND
As Fortran 2018 16.9.82, all the arguments of GET_COMMAND are optional.
When they are all absent, do nothing so to be consistent with gfortran
and ifort. The semantic analysis and runtime have been supported.

This intrinsic was introduced from F2003, and this supports the lowering
of it.

Reviewed By: PeteSteinfeld, jeanPerier

Differential Revision: https://reviews.llvm.org/D137887
2022-11-19 11:03:52 +08:00
Jennifer Yu
9d90cf2fca [OPENMP5.1] Initial support for message clause. 2022-11-18 17:59:23 -08:00
Slava Zakharin
396ead93e3 [flang] Use proper attributes for runtime calls with 'i1' arguments/returns.
Clang uses signext/zeroext attributes for integer arguments shorter than
the default 'int' type on a target. So Flang has to match this for functions
from Fortran runtime and also for BIND(C) routines. This patch implements
ABI adjustments only for Fortran runtime calls. BIND(C) part will be done
separately.

This resolves https://github.com/llvm/llvm-project/issues/58579

Differential Revision: https://reviews.llvm.org/D137050
2022-11-18 12:52:57 -08:00
Valentin Clement
8dfd883531
[flang] Add ClassIs runtime function
Add a `ClassIs` function that takes a descriptor and a
type desc to implement the check needed by the CLASS IS type guard
in SELECT TYPE construct.
Since the kind type parameter are directly folded in the type itself
in Flang and the type descriptor is a global, the function just check
if the type descriptor address of the descriptor is equivalent to
the type descriptor address of the global. If not, it check in the
parents of the descriptor's type descriptor.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138279
2022-11-18 21:17:15 +01:00
Kelvin Li
aaea4e38ab [flang] Add more diagnostic for MAX/MIN intrinsic
Fix https://github.com/llvm/llvm-project/issues/56303

Differential Revision: https://reviews.llvm.org/D137742
2022-11-18 14:37:37 -05:00
Valentin Clement
6f81795fca
[flang][NFC] Remove unused DispatchTableop fct
Remove `appendTableEntry` as it is not used.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138293
2022-11-18 20:32:43 +01:00
Dominik Adamski
163dbfe869 [mlir][OpenMP] Add order clause definition to simd construct
Update simd construct definition and add mlir tests to prove
that order(concurrent) clause is correctly modeled for simd
construct.
2022-11-18 06:08:04 -06:00
Jean Perier
07b8927394 [flang] Lower ArrayRef to hlfir.designate
Also add support for fir.boxchar in HLFIRTools so that character
designator with none constant lengths can be processed/converted to
fir::ExtendedValue.

Differential Revision: https://reviews.llvm.org/D138190
2022-11-18 10:09:12 +01:00
Jean Perier
4bb9d28cc4 [flang] Add hlfir.designate definition
Add hlfir.designate operation definition. This is the HLFIR building
blocks to represent Fortran designator. An hlfir.designator is a
Fortran "part-ref" and an optional susbstring or part ref.
See the operation added description for more detail, and
https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md
for the rational of this operation.

Differential Revision: https://reviews.llvm.org/D138121
2022-11-18 08:41:38 +01:00
Jennifer Yu
1e054e6b52 [OPENMP5.1] Initial support for severity clause
Differential Revision:https://reviews.llvm.org/D138227
2022-11-17 16:05:02 -08:00
Slava Zakharin
ffe1661fab [flang] Propagate fastmath flags during intrinsics simplification.
In general, the meaning of fastmath flags on a call during inlining
is that the call's operation flags must be ignored. For user functions
that means that the fastmath flags used for the function definition
override any call site's fastmath flags. For intrinsic functions
we can use the call site's fastmath flags, but we have to make sure
that the call sites with different flags produce/use different
simplified versions of the same intrinsic function.

Differential Revision: https://reviews.llvm.org/D138048
2022-11-17 10:16:47 -08:00
Tom Eccles
4cc9437a7e [flang] Set default to -ffpcontract=fast
Following RFC at
https://discourse.llvm.org/t/rfc-ffp-contract-default-value/66301

This adds the `fastmath<contract>` attribute to `fir.call` and some
floating point arithmetic operations (hence the many test changes).
Instead of testing for this specific attribute, I am using a regular
expression to match any attributes.
2022-11-17 15:49:51 +00:00
Valentin Clement
6393d2ea24
[flang] Create fir.dispatch_table and fir.dt_entry operations
Create the fir.dispatch_table operation based on semantics
information. The fir.dispatch_table will be used for static devirtualization
as well as for fir.select_type conversion.

Depends on D138129

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138131
2022-11-17 10:53:43 +01:00
Valentin Clement
ded52a44d0
[flang] Make CollectBindings available to lowering
Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138129
2022-11-17 10:46:15 +01:00
Jennifer Yu
628fdc3f57 [OPENMP]Initial support for at clause
Error directive is allowed in both declared and executable contexts.
The function ActOnOpenMPAtClause is called in both places during the
parsers.

Adding a param "bool InExContext" to identify context which is used to
emit error massage.

Differential Revision: https://reviews.llvm.org/D137851
2022-11-15 14:06:50 -08:00
Jean Perier
dd73bfa6d6 [flang] Lower intrinsic assignment to fir.assign
Lower intrinsic assignment to hlfir.assign, except when the LHS
is a whole allocatable (this part will be done later to keep patch
simpler).

Differential Revision: https://reviews.llvm.org/D138013
2022-11-15 12:01:57 +01:00
Jean Perier
b9c78b2c59 [flang] Add hlfir.assign definition
Add hlfir.assign that represent Fortran assignment.
See https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md.
Operation attributes will be added later when they can be used.

Differential Revision: https://reviews.llvm.org/D138012
2022-11-15 12:00:16 +01:00
Jean Perier
34d3f3fbed [flang] Lower symbols to hlfir.declare
Update lowering to generate hlfir.declare instead of fir.declare.
Introduce the hlfir::Entity class that will be used to work with
Fortran objects in HLFIR transformation.

Fix lower bounds that where swapped with extents in fir.declare
generation.

Update tests that expected fir.declare.

Differential Revision: https://reviews.llvm.org/D137951
2022-11-15 09:50:00 +01:00
Valentin Clement
044fcfa1ed
[flang][NFC] Fix typo in fir.box_typecode op description 2022-11-14 14:28:06 +01:00
Jean Perier
3b29159da0 [flang] Add hlfir.declare codegen
hlfir.declare codegen generates a fir.declare, and may generate a
fir.embox/fir.rebox/fir.emboxchar if the base value does not convey
all the variable bounds and length parameter information.

Leave OPTIONAL as a TODO to keep this patch simple. It will require
making the embox/rebox optional to preserve the optionality aspects.

Differential Revision: https://reviews.llvm.org/D137789
2022-11-14 11:19:35 +01:00
Valentin Clement
49ee5634e7
[flang] Add fir.box_typecode operation
`fir.box_typecode` operation allows to retrieve the type code
from a boxed value. This will be used in the `fir.select_type` conversion
to if-then-else ladder for type guard statement with intrinsic type spec
instead of using a runtime call.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D137829
2022-11-14 10:51:18 +01:00
Valentin Clement
f677c5ee97
[flang] Initial lowering of SELECT TYPE construct to fir.select_type operation
This patch is the initial path to lower the SELECT TYPE construct to the
fir.select_type operation. More work is required in the AssocEntity
mapping but it will be done in a follow up patch to ease the review.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D137728
2022-11-14 10:48:41 +01:00
Jean Perier
7a1bd01493 [flang][RFC] Do not rely on attributes to tag HLFIR variable uses
After more considerations and experience, switch to one of the
alternative plan for HLFIR variable that will avoid requiring naming
designators and having to maintain and update names in attributes after
inlining of code duplication.

The cost is the increase of fir.box usage, which in most cases should
be removed when lowering from HLFIR to FIR.

Differential Revision: https://reviews.llvm.org/D137634
2022-11-14 10:39:11 +01:00
Jean Perier
fcfb620db5 [flang][NFC] rename hlfir::FortranEntity into EntityWithAttributes
This reflects the fact that Attributes will not always be visible when
looking at an HLFIR variable. The EntityWithAttributes class is used
to denote in the compiler code that the value at hand has visible
attributes. It is intended to be used in lowering so that the code
can query about operands attributes when generating code.

Differential Revision: https://reviews.llvm.org/D137792
2022-11-14 10:37:16 +01:00
Jean Perier
32e7e17d86 [flang] Add hlfir.declare operation
This operation will be used to declare named variables in HLFIR.
See the added description in HLFIROpBase.td for more info about it.

The motivation behind this operation is described in https://reviews.llvm.org/D137634.

The FortranVariableInterface verifier is changed a bit. It used to
operate using the result type to verify the provided shape and length
parameters. This is a bit incorrect because what matters to verify the
information is the input address (This worked OK with fir.declare where
the input memref type is the same as the output result). Also, not all
operation defining variables will have an input memref with the same
meaning (hlfir.designate and hlfir.associate for instance).
Hence, this verifier is now optional and must be provided a memref to
operate.

Differential Revision: https://reviews.llvm.org/D137781
2022-11-14 10:27:12 +01:00
Usman Nadeem
d34dce25d9 [Flang] Allow registering plugin extensions with the pass builder
Pass plugins are compiled and linked dynamically by default. Setting
`LLVM_${NAME}_LINK_INTO_TOOLS` to `ON` turns the project into a
statically linked extension. Projects like Polly can be used this way by
adding `-DLLVM_POLLY_LINK_INTO_TOOLS=ON` to the `cmake` command.

The changes in this patch makes the PassBuilder in Flang aware of
statically linked pass plugins, see the documentation for more details:
https://github.com/llvm/llvm-project/blob/main/llvm/docs/WritingAnLLVMNewPMPass.rst#id21

Differential Revision: https://reviews.llvm.org/D137673

Change-Id: Id1aa501dcb4821d0ec779f375cc8e8d6b0b92fce
2022-11-10 14:16:15 -08:00
Renaud-K
4d183b48c3 Add constant time mapping from enumeration to string in ENUM_CLASS
macro

Differential revision: https://reviews.llvm.org/D137577
2022-11-10 08:56:20 -08:00
Renaud-K
5f9e049111 In the case the function body is empty, shifting attributes as inserting argument is not supported
Differential revision: https://reviews.llvm.org/D137757
2022-11-10 08:53:34 -08:00
Andrzej Warzynski
69665c4b27 [flang][nfc] Add missing REQUIRES flag in a test
D129156 has caused a buildbot failure:
  * https://lab.llvm.org/buildbot/#/builders/175/builds/20472.
Clearly `examples` is missing from the `REQUIRES` list. Sending this
without a review as a quick fix.
2022-11-10 15:54:57 +00:00
Tarun Prabhu
c3821b8d2a [flang] Add -fpass-plugin option to flang
This patch adds the -fpass-plugin option to flang which dynamically loads LLVM
passes from the shared object passed as the argument to the flag. The behavior
of the option is designed to replicate that of the same option in clang and
thus has the same capabilities and limitations.

Features:

  Multiple instances of -fpass-plugin=path-to-file can be specified and each
  of the files will be loaded in that order.

  The flag can be passed to both flang-new and flang-new -fc1.

  The flag will be listed when the -help flag is passed to both flang-new and
  flang-new -fc1. It will also be listed when the --help-hidden flag is passed.

Limitations:

  Dynamically loaded plugins are not supported in clang on Windows and are not
  supported in flang either.

Addenda:

  Some minor stylistic changes are made in the files that were modified to
  enable this functionality. Those changes make the naming of functions more
  consistent, but do not change any functionality that is not directly
  related to enabling -fpass-plugin.

Differential Revision: https://reviews.llvm.org/D129156
2022-11-10 08:03:46 -07:00
Valentin Clement
4299ff548e
[flang][NFC] Rename RewriteLoop.cpp to ControlFlowConverter.cpp
RewriteLoop.cpp is containing more than just loop conversion. It will
soon contains the fir.select_type conversion as well. This patch
renames the file so it is in line with the pass name.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D137773
2022-11-10 15:03:18 +01:00
Sergio Afonso
d5fb5960d0 [flang][OpenMP] Add parser support for Requires directive
OpenMP 5.0 adds support for the "requires" directive. This patch adds parser support for it in flang.

Differential revision: https://reviews.llvm.org/D136867
2022-11-10 05:38:31 -06:00
Slava Zakharin
bc955cae35 [flang] Support arith::FastMathFlagsAttr for fir::CallOp.
The main purpose of this patch is to propagate fastmath attribute
to SimplifyIntrinsicsPass, so that the inline code can inherit
the call operation's attributes. Even though I added translation
of fastmath from fir::CallOp to LLVM::CallOp, there are no fastmath
attributes in LLVM IR. It looks like the translation drops it.
This will need additional commits.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D137602
2022-11-09 15:31:09 -08:00
Slava Zakharin
3538ca3f1b [flang] Propagate more FastMath flags to lowering.
Plugged in propagation of nnan/nsz/arcp/afn/reassoc related options
to lowering/FirOpBuilder.

Reviewed By: jeanPerier, tblah, awarzynski

Differential Revision: https://reviews.llvm.org/D137580
2022-11-09 15:01:47 -08:00
Renaud-K
4d5a9c1d17 Using higher level interface to insert new arguments so arguments
and their corresponding attributes are moved together

Differential revision: https://reviews.llvm.org/D13767
2022-11-09 11:05:53 -08:00
Jean Perier
a621e79916 [flang][NFC] move fir namespace into FortranVariableOpInterface ODS declaration
This will be needed to be able to use this interface in HLFIR ODS operation definition
and get the right namespaces.

Differential Revision: https://reviews.llvm.org/D137702
2022-11-09 11:41:24 +01:00
Jean Perier
af8cec4c16 [flang][NFC] move HLFIR dialect definition in IR
Transforms will need to be put in a different library to avoid circular
dependencies with other parts of the compiler. So create an IR
directory, this (flat include directory, IR and Transform directories in
lib) matches how dialects like LLVM dialect are implemented.

Differential Revision: https://reviews.llvm.org/D137701
2022-11-09 11:39:12 +01:00
Peixin-Qiao
c336e72c82 [flang] Fix function result rewrite for CPTR type
Not all derived type can be taken as abstract result. The CPTR type
should be treated as return by value so to interoperable with C
functions. Fix the function result rewrite for CPTR type, but it
should be generalized for all derived types. The ABI of
interoperability with C for derived type is architecture dependent,
which should be supported later.

Reviewed By: PeteSteinfeld, jeanPerier

Differential Revision: https://reviews.llvm.org/D137548
2022-11-09 09:24:38 +08:00
Fangrui Song
8c2c62282f [Driver] Refactor err_drv_unsupported_option_argument call sites to use llvm::opt::Arg::getSpelling
For `-foo=bar`, getSpelling return `-foo=` which is exactly what we need from
the diagnostic. Drop `-` from the err_drv_unsupported_option_argument template.
This change makes `--` long option diagnostics more convenient.

Reviewed By: lenary

Differential Revision: https://reviews.llvm.org/D137659
2022-11-08 14:39:09 -08:00
Katherine Rasmussen
ecedc4d710 [flang] Add atomic_xor to list of intrinsics
Add the atomic subroutine, atomic_xor, to the list of
intrinsic subroutines, add its last dummy argument to a check
for a coindexed-object, and update test.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D137196
2022-11-07 16:52:59 -08:00
Slava Zakharin
8f3f15c1a2 [flang] Configure FirOpBuilder based on math driver options.
Added MathOptionsBase to share fastmath config between different
components. Frontend driver translates LangOptions into MathOptionsBase.
FirConverter configures FirOpBuilder using MathOptionsBase
config passed to it via LoweringOptions.

Depends on D137390

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D137391
2022-11-07 09:26:46 -08:00
Valentin Clement
fe2069284d
[flang] Allow fir.class as fir.save_result operand #0
Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D137546
2022-11-07 18:23:43 +01:00
Slava Zakharin
ddb68f36ae [flang] Initial support for FastMathAttr setup in FirOpBuilder.
Provide FirOpBuilder::setFastMathFlags() to configure FastMathFlags
for the builder. Set FastMathAttr for operations based on FirOpBuilder
configuration via mlir::OpBuilder::Listener.

This is a little bit hacky solution, because we lose the ability
to hook other listeners to FirOpBuilder. There are also potential
issues with OpBuilder::clone() - the hook will be invoked for cloned
operations and will effectively overwrite FastMathAttr with the ones
configured in FirOpBuilder, which should not be happening.
We should teach mlir::OpBuilder about FastMathAttr setup in future.

Reviewed By: jeanPerier, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D137390
2022-11-07 09:03:46 -08:00
Kazu Hirata
c63465bd06 [flang] Use llvm::is_contained (NFC) 2022-11-06 19:58:51 -08:00
Valentin Clement
ad980b5702
[flang] Fix controlSuccessor chain for select rank construct
Represent the select rank statement + select rank case statement
the same way the select case statement and case statement are represented.
controlSuccessor was not correctly attributed to the next type guard stmt.
Similar to D137460 for select type construct.

Reviewed By: vdonaldson

Differential Revision: https://reviews.llvm.org/D137490
2022-11-06 09:56:46 +01:00