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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Take into account the result passed as arguments when computing
the pass object index.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D138712
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
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
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
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
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
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
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
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
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
As suggested on D138129, switching rteurn of CollectBindings
function to SymbolVector.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D138419
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
As suggested on D138129, switching rteurn of CollectBindings
function to SymbolVector.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D138419
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
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
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
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
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
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
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
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
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
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
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.
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
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
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
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
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
`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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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