Commit Graph

5461 Commits

Author SHA1 Message Date
Jean Perier 89af7de9de [flang] Lower power to HLFIR
Differential Revision: https://reviews.llvm.org/D139117
2022-12-01 17:49:36 +01:00
Jean Perier 440e9baa62 [flang] Lower add, mul, div, and sub to HLFIR
Only lower operations when the operands are scalar for now.

Differential Revision: https://reviews.llvm.org/D139108
2022-12-01 17:39:53 +01:00
Valentin Clement 6008520b14
[flang][NFC] Remove debugging line in convert op
This line should not have made it to the final patch.
2022-12-01 15:25:43 +01:00
Valentin Clement d4d4942911
[flang] Avoid verifier error when emboxing trivial type to unlimited polymorphic entity
Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138989
2022-12-01 14:27:30 +01:00
Jean Perier e78e4a1761 [flang] lower F77 calls in HLFIR
Use recently added hlfir.associate/hlfir.end_associate to deal
with the cases where the actual argument is an expression.

Differential Revision: https://reviews.llvm.org/D139009
2022-12-01 11:22:38 +01:00
Valentin Clement ef06327063
[flang] Make sure PointerNullifyDerived is called on pointer array
Record type was not correctly retrived so the runtime call was not
produced correctly.
Fix how the record type is retrived so the correct call is
produced.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139084
2022-12-01 11:18:28 +01:00
Valentin Clement 131585ab0f
[flang] Use genExprBox for the rhs when calling PointerAssociate for unlimited polymorphic pointer
In D139019 the assumption was made that the rhs was also the MutableBox
but this is not a constraint. Use genExprBox instead. Also the allowed
conversion in D139019 was not correct. Remoed it since it is not needed anymore.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139081
2022-12-01 11:12:24 +01:00
Slava Zakharin d5b0de35bd [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-30 11:51:34 -08:00
Valentin Clement abefd87e70
[flang] Delegate pointer association to class(*) pointer to the runtime
Pointer association with an unlimited polymorphic pointer on the lhs
requires more than just updating the base_addr. Delegate the association to
the runtime function `PointerAssociation`.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D139019
2022-11-30 18:57:57 +01:00
Valentin Clement 1bd0ff7a90
[flang] Allow non polymorphic pointer assignment with polymorphic rhs
Remove the TODO and allow pointer assignment with non
polymorphic entity on the lhs. The assignment follow the same scheme
as derived-type pointer assignment to parent component.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138998
2022-11-30 15:53:34 +01:00
Jean Perier d71c1de0ff [flang][NFC] add genType(FunctionRef<T>) entry points in lowering
This will help lowering to HLFIR to not use the AsGenericExpr/AsExpr
patterns that copies sub-expresssions into evaluate::SomeExpr so that
they can be passed to helpers. Sub-expressions like FunctionRef can
be heavy (hundreds of arguments, constant array expression arguments...).

Differential Revision: https://reviews.llvm.org/D138997
2022-11-30 14:44:27 +01:00
Jean Perier 6eb8ee9835 [flang] Add hlfir.associate and hlfir.end_associate definitions
These operations allow creating an HLFIR variable from a HLFIR value and
destroying it at the end of the variable lifetime.
This will both be used to implement procedure reference arguments association
when the actual is an expression, and to implement the Fortran associate
construct when the associated entity is an expression.

See https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md
for more details.

Differential Revision: https://reviews.llvm.org/D138996
2022-11-30 13:43:56 +01:00
Muhammad Omair Javaid c687c2cce5 [FLANG] Fix MSVC + clang-cl build
Flang build on windows with MSVC environment and clang-cl compiler
requires clang_rt.builtin.${target} library. This patch allows us to
locate and include this link library. This is mostly needed for flang
runtime and associated unittests as it requires the uint128 division
builtin function __udivti3.

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D138023
2022-11-30 16:29:26 +05:00
Tom Eccles 3a1b409254 [flang] fix unused variables 2022-11-30 10:37:23 +00:00
Valentin Clement b9e53b96e0
[flang] Handle polymorphic value when creating temporary
Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138921
2022-11-30 09:58:57 +01:00
Valentin Clement aa47103898
[flang] Use BaseBoxType in component by component assignment
Use BaseBoxType in `genComponentByComponentAssignment`
so the component by component assignment involving polymorphic entities
does not fall back to scalar assignment.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138927
2022-11-29 20:45:05 +01:00
Kelvin Li b42cb2d601 [flang][doc] Remove DCMPLX intrinsic from the Intrinsic Procedures Lacking Support list
Differential Revision: https://reviews.llvm.org/D138848
2022-11-29 14:15:02 -05:00
Kelvin Li 93196654f5 [flang] Add support for LSHIFT and RSHIFT intrinsics
The functionality of LSHIFT and RSHIFT intrinsics is the same as the
standard SHIFTL and SHIFTA intrinsics respectively. The patch is to
alias the two intrinsics to the standardized ones.

Differential Revision: https://reviews.llvm.org/D138839
2022-11-29 14:03:31 -05:00
Tarun Prabhu d43a2f09de [flang] Lower F08 FINDLOC intrinsic
The implementation follows the patterns established by the lowering of other
similar intrinsics.

In addition to the code for lowering, the DoTotalReduction template had to be
fixed to correctly break when signaled to do so by the accumulator function.

Differential Revision: https://reviews.llvm.org/D138140
2022-11-29 10:18:38 -07:00
Tom Eccles 6841c43f36 [flang] Remove warnings that fast-math options are unimplemented
These are now fully implemented, see
https://reviews.llvm.org/D137390
https://reviews.llvm.org/D137391
https://reviews.llvm.org/D137456
https://reviews.llvm.org/D137580
https://reviews.llvm.org/D137602
https://reviews.llvm.org/D138048

These flags are still tested in
flang/test/Driver/frontend-forwarding.f90 and
flang/test/Lower/fast-math-arithmetic.f90

Differential revision: https://reviews.llvm.org/D138907
2022-11-29 17:15:05 +00:00
Valentin Clement 391efeb538
[flang][NFC] Retrieve binding table from fir.dispatch_table operations
Change how the binding tables are retrived. Use the newly lowered
fir.dispatch_table operations instead of the fir.global type infos.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138903
2022-11-29 13:22:16 +01:00
Qihan Cai 1147e70e7e [flang] Enable RISC-V for x86CompatibleBehavior in floating point flag
Fixes #59132 by mitigating the behavior of not setting underflow flag on RISC-V platform.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D138503
2022-11-29 21:15:19 +11:00
Usman Nadeem 54dc764db7 [Flang][Test] Add support to change the default target triple for tests
In this patch I added support to change the default target triple used
by flang tests using the cmake variable: FLANG_TEST_TARGET_TRIPLE.

This functionality is implemented using the LLVM_TARGET_TRIPLE_ENV
variable, so that must be defined as well.

An example use:
`-DLLVM_TARGET_TRIPLE_ENV="LLVM_TARGET_TRIPLE_ENV" -DFLANG_TEST_TARGET_TRIPLE="aarch64-linux-gnu"`

Differential revision: https://reviews.llvm.org/D138530

Change-Id: I38e4a46a65109d415a9b72c8a0bf8a955e937280
2022-11-28 16:02:22 -08:00
Qihan Cai bac88e898f [flang] Add RISCV-64 support to Optimizer/CodeGen/Target.cpp
As an attempt to fix errors in Flang regression tests on RISCV64 platform, RISCV64 target was added, and subsequent tests were provided.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D136547
2022-11-29 09:49:26 +11:00
Valentin Clement 545db9c41f
[flang] Handle polymorphic argument when expecting boxed derived-type
Perform a rebox instead of a convert operation when the input type is
polymorphic and the output type is a boxed derived-type.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138831
2022-11-28 20:56:27 +01:00
Valentin Clement 1ea66eefec
[flang] Adapt target rewrite for fir.dispatch operation
Handle rewriting dispatch operation with complex arguments or
return.

sret will be done in a separate patch.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138820
2022-11-28 17:36:03 +01:00
Valentin Clement afb34cf307
[flang] Hanlde disptach op in abstract result pass
Update the call conversion pattern to support fir.dispatch
operation as well. The first operand of fir.dispatch op is always the
polymoprhic object. The pass_arg_pos attribute needs to be shifted when
the result is added as argument.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138799
2022-11-28 16:49:51 +01:00
Thomas Preud'homme ecfa2d3d99 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, mceier

Differential Revision: https://reviews.llvm.org/D138274
2022-11-25 21:57:58 +00:00
Valentin Clement e6319cdcb9
[flang] Update fir.dispatch op lowering for tbp with character result
Take into account the result passed as arguments when computing
the pass object index.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138712
2022-11-25 21:25:09 +01:00
Valentin Clement e1eb81f470
[flang] Allow fir.rebox to unlimited polymorphic box
This patch relaxes the verifier for the fir.rebox operation
to allow reboxing to unlimited polymoprhic box.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138695
2022-11-25 14:42:51 +01:00
Valentin Clement 8d692b4b8d
[flang] Avoid crash in lowering for unlimited polymorphic function return
The dynamic type of an unlimited polymorphic entity has the
derived category but does not have derived type spec. This leads
to a crash for a nullptr dereference. This patch avoids this crash
by checking if that the dynamic type is not unlimited polymorphic
before dereferencing the derived type spec.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138691
2022-11-25 13:47:50 +01:00
Thomas Preud'homme b62c8d396f Revert: Add version to all LLVM cmake package
Summary: This reverts commit ad485b71b5.

Reviewers:

Subscribers:
2022-11-25 10:54:58 +00:00
Jean Perier 36f61d14fb [flang] Add hlfir.concat codegen
hlfir.concat codegen happens in the "bufferization" pass: the pass
that place hlfir.expr in memory and transform all operations producing
or accepting hlfir.expr arguments into operations operating on memory.
Since this pass gets rid of the hlfir.expr type, this is a full
translation pass.

So far hlfir.concat codegen re-uses the current concatenation lowering helper
and only supports concatenation of two strings at a time. This matches
what lowering to HLFIR without any optimization produces. More optimized
versions will be developed later.

Differential Revision: https://reviews.llvm.org/D138673
2022-11-25 09:39:39 +01:00
Jean Perier 94b9fbabe8 [flang] Lower concatenation to hlfir.concat
Differential Revision: https://reviews.llvm.org/D138664
2022-11-25 09:36:58 +01:00
Jean Perier 8dea00f4e7 [flang] Add hlfir.concat operation definition
This operation represents scalar character concatenation. This is
added as part of flang lowering update described in
https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md

A notable difference with Fortran concatenation is that hlfir.concat can
take two or more operands. This will be used to optimize concatenation
chains.

Differential Revision: https://reviews.llvm.org/D138650
2022-11-25 09:34:15 +01:00
Valentin Clement fa3587d63e
[flang] Remove debug option
Remove debug option added by mistake in D138587
2022-11-25 09:30:17 +01:00
Evgeniy Brevnov 721f975d35 Use PassGate from LLVMContext if any otherwise global one
Differential Revision: https://reviews.llvm.org/D137149
2022-11-25 15:13:04 +07:00
Valentin Clement c1b7e9c962
[flang] Adapt descriptor codegen to support unlimited polymorphic entities
Code generation to create and populate the descriptor (element size and
type code) is based on the boxed result type. This does not work well with
unlimited polymorphic entities since the fir type does not represent what is
actually emboxed or reboxed.
In the case of emboxing, the input type will be used to populate
the descriptor element size and type code.
When reboxing an unlimited polymorphic to a unlimited polymorphic entities, the
element size and type code is retrieve from the input box.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138587
2022-11-24 20:47:21 +01:00
Kelvin Li 1094254716 [flang] Lowering LOC intrinsic
This patch is to implement the lowering of the LOC intrinsic.

Differential Revision: https://reviews.llvm.org/D138572
2022-11-24 10:33:27 -05:00
Rainer Orth dfa7f4ca8b [flang][test] Adjust Driver/pass-plugin-not-found.f90 error message
The `Driver/pass-plugin-not-found.f90` test `FAIL`s on Solaris since part
of the error message differs from what the test expects: Solaris has

  error: unable to load plugin 'X.Y': 'Could not load library 'X.Y':
ld.so.1: flang-new: X.Y: open failed: No such file or directory'

while the test expects

  error: unable to load plugin 'X.Y': 'Could not load library 'X.Y': X.Y:
cannot open shared object file: No such file or directory'

The last part is emitted by the system `dlerror` and is thus unportable.
Hopefully the error text itself is the same everywhere.

The following patch adjusts the expected message accordingly.

Tested on `x86_64-pc-linux-gnu` and `amd64-pc-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D138663
2022-11-24 16:20:33 +01:00
Jean Perier 011b2af0f4 [flang][NFC] move genCallOpAndResult into new ConvertCall.cpp file
Move genCallOpAndResult from ConvertExpr.cpp into a new file so that
it can be shared with lowering to FIR and HLFIR during the transition.
After the transition, call lowering to HLFIR will be implemented in
this new file.

Differential Revision: https://reviews.llvm.org/D138643
2022-11-24 12:38:53 +01:00
Michał Górny 02a2e18e60 [flang] Harmonize standalone gtest support with other projects
Use the CMake rules of unittest libraries via `add_subdirectory()`
when using standalone builds, similarly to how e.g. Clang does that.
Besides making things more consistent, I hope this also unblocks D137035
and effectively we'll be able to simplify things further and have LLVM
semi-automatically include gtest support for us in the future.

Differential Revision: https://reviews.llvm.org/D138573
2022-11-24 03:29:15 +01:00
Michał Górny 58d1988b19 [flang] Fix unittests in standalone build for third-party move
Update external unittest rules for flang standalone builds to account
for the unittest components (gtest, gmock) being moved to `third-party`
directory, in a11cd0d94e.

Differential Revision: https://reviews.llvm.org/D138562
2022-11-23 15:11:09 +01:00
Kelvin Li 0c08418d4b [Flang] Removing Float Bessel functions for AIX
AIX libc only provides bessel functions j0,j1,jn and y0,y1,yn but
does not have their float equivalents j0f,j1f,jnf and y0f,y1f,ynf.

Committed on behalf of madanial

Differential Revision: https://reviews.llvm.org/D136128
2022-11-22 10:43:03 -05:00
Valentin Clement d38735e601
[flang][NFC] Switch CollectBindings return to SymbolVector
As suggested on D138129, switching rteurn of CollectBindings
function to SymbolVector.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138419
2022-11-22 15:14:03 +01:00
Valentin Clement 9d395e79a6
[flang] Set initial size and type code for unlimited polymorphic descriptor
Initialization of unlimited polymorphic descriptor was raising an error.
This patch sets a default size and type code for unlimited polymoprhic descriptor
that will be updated once allocated/assigned.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138479
2022-11-22 14:48:34 +01:00
Valentin Clement 81bd5e2ef7
Revert "[flang][NFC] Switch CollectBindings return to SymbolVector"
This reverts commit 97e8eeb758.
2022-11-22 10:12:14 +01:00
Valentin Clement 97e8eeb758
[flang][NFC] Switch CollectBindings return to SymbolVector
As suggested on D138129, switching rteurn of CollectBindings
function to SymbolVector.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138419
2022-11-22 09:43:11 +01:00
Valentin Clement fedf4dcd80
[flang] Do not propagate type desc when box type is not polymorphic
When the rhs is non-polymorphic the type descriptor should not
be propagated. An error in the EmboxOp verifier was raised in that case.
This patch propagate the type descriptor only if the result type of the
EmboxOp operation is polymorphic.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138442
2022-11-22 09:41:50 +01:00
Valentin Clement 3b257a6373
[flang] Accept BaseBoxType in couple of fir.array_* operations
Couple of operation are expecting BoxType but can totally handle
ClassType as well. This patch updates couple of locations to support
BaseBoxType instead of BoxType only.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138422
2022-11-21 16:54:47 +01:00
Aliia Khasanova 399638f98c Merge kDynamicSize and kDynamicSentinel into one constant.
resolve conflicts

Differential Revision: https://reviews.llvm.org/D138282
2022-11-21 13:01:26 +00:00
Jean Perier ee8c653c21 [flang] Add hlfir.designate codegen for Fortran ArrayRef
Differential Revision: https://reviews.llvm.org/D138198
2022-11-21 10:17:38 +01:00
Valentin Clement 147fe9de29
[flang][NFC] Update TODOs list 2022-11-21 10:05:18 +01:00
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