Commit Graph

273 Commits

Author SHA1 Message Date
Jie Fu
3f2f700633 [flang] Fix -Wunused-but-set-variable in Bridge.cpp (NFC)
llvm-project/flang/lib/Lower/Bridge.cpp:3775:14:
error: variable 'nbDeviceResidentObject' set but not used [-Werror,-Wunused-but-set-variable]
    unsigned nbDeviceResidentObject = 0;
             ^
1 error generated.
2024-04-06 07:31:53 +08:00
Valentin Clement (バレンタイン クレメン)
953aa102a9 [flang][cuda] Lower device to host and device to device transfer (#87387)
Add more support for CUDA data transfer in assignment. This patch adds
device to device and device to host support. If device symbols are
present on the rhs, some implicit data transfer are initiated. A
temporary is created and the data are transferred to the host. The
expression is evaluated on the host and the assignment is done.
2024-04-05 09:11:37 -07:00
jeanPerier
a4798bb0b6 [flang][NFC] use mlir::SymbolTable in lowering (#86673)
Whenever lowering is checking if a function or global already exists in
the mlir::Module, it was doing module->lookup.

On big programs (~5000 globals and functions), this causes important
slowdowns because these lookups are linear. Use mlir::SymbolTable to
speed-up these lookups. The SymbolTable has to be created from the
ModuleOp and maintained in sync. It is therefore placed in the
converter, and FirOPBuilders can take a pointer to it to speed-up the
lookups.

This patch does not bring mlir::SymbolTable to FIR/HLFIR passes, but
some passes creating a lot of runtime calls could benefit from it too.
More analysis will be needed.

As an example of the speed-ups, this patch speeds-up compilation of
Whizard compare_amplitude_UFO.F90 from 5 mins to 2 mins on my machine
(there is still room for speed-ups).
2024-04-02 14:29:29 +02:00
Daniel Chen
4998587e6f [Flang] Support for passing procedure pointer, reference to a function that returns a procedure pointer to structure constructor. (#86533)
This PR fixes `not yet implemented: procedure pointer component in
structure constructor` as shown in the following test case.

```
  MODULE M
    TYPE :: DT
      PROCEDURE(Fun), POINTER, NOPASS :: pp1
    END TYPE

    CONTAINS

    INTEGER FUNCTION Fun(Arg)
    INTEGER :: Arg
      Fun = Arg
    END FUNCTION

  END MODULE

  PROGRAM MAIN
  USE M
  IMPLICIT NONE
  TYPE (DT) :: v2
  PROCEDURE(FUN), POINTER :: pp2
  v2 = DT(pp2)
  v2 = DT(bar())
  CONTAINS
    FUNCTION BAR() RESULT(res)
      PROCEDURE(FUN), POINTER :: res
    END
  END
  ```
2024-03-26 11:29:24 -04:00
Valentin Clement (バレンタイン クレメン)
4e6745cc4d [flang][cuda] Lower simple host to device data transfer (#85960)
In CUDA Fortran data transfer can be done via assignment statements
between host and device variables.

This patch introduces a `fir.cuda_data_transfer` operation that
materialized the data transfer between two memory references.

Simple transfer not involving descriptors from host to device are also
lowered in this patch. When the rhs is an expression that required an
evaluation, a temporary is created. The evaluation is done on the host
and then the transfer is initiated.

Implicit transfer when device symbol are present on the rhs is not part
of this patch. Transfer from device to host is not part of this patch.
2024-03-25 11:53:39 -07:00
jeanPerier
de7a50fb88 [flang] Fix lowering of host associated cray pointee symbols (#86121)
Cray pointee symbols can be host associated from a module or host
procedure while the related cray pointer is not explicitly associated.
This caused the "not yet implemented: lowering symbol to HLFIR" to fire
when lowering a reference to the cray pointee and fetching the cray
pointer.

This patch:
- Ensures cray pointers are always instantiated when instantiating a
cray pointee.
- Fix internal procedure lowering to deal with cray pointee host
association like it does for pointers (the lowering strategy for cray
pointee is to create a pointer that is updated with the cray pointer
value before being fetched).

This should fix the bug reported in
https://github.com/llvm/llvm-project/issues/85420.
2024-03-22 11:13:04 +01:00
Valentin Clement (バレンタイン クレメン)
f6a2a55ba1 [flang][cuda] Handle lowering of stars in cuf kernel launch parameters (#85695)
Parsing of the cuf kernel loop directive has been updated to handle
variants with the * syntax. This patch updates the lowering to make use
of them.

- If the grid or block syntax uses only stars then the operation
variadic operand remains empty.
- If there is values and stars, then stars are represented as a zero
constant value.
2024-03-18 19:46:11 -07:00
Valentin Clement (バレンタイン クレメン)
8a6a0f1954 [flang][cuda] Add proper TODO for cuda fortran assignment (#85705)
Data transfer between host and device can be done with assignment
statements in CUDA Fortran. This is currently not lowered so adding a
proper TODO.


https://docs.nvidia.com/hpc-sdk/archive/24.3/compilers/cuda-fortran-prog-guide/index.html#cfref-data-trans-assgn-statemts
2024-03-18 17:11:04 -07:00
Kareem Ergawy
87cee71b37 [flang][MLIR][OpenMP] Extend delayed privatization for scalar allocatables and pointers (#84740)
One more step in extending support for delayed privatization. This diff
adds support for scalar allocatables and pointers.
2024-03-18 10:44:44 +01:00
Peter Klausler
60fa2b0670 [flang] Parse !$CUF KERNEL DO <<< (*) (#85338)
Accept and represent asterisks within the parenthesized grid and block
specification lists.
2024-03-15 13:57:42 -07:00
Kareem Ergawy
3b30559c08 [flang][OpenMP] Only use HLFIR base in privatization logic (#84123)
Modifies the privatization logic so that the emitted code only used the
HLFIR base (i.e. SSA value `#0` returned from `hlfir.declare`). Before
that, that emitted privatization logic was a mix of using `#0` and `#1`
which leads to some difficulties trying to move to delayed privatization
(see the discussion on #84033).
2024-03-11 10:38:28 +01:00
agozillon
afb05cd646 [Flang][MLIR][OpenMP] Create a deferred declare target marking process for Bridge.cpp (#78502)
This patch seeks to create a process that happens on module finalization
for OpenMP, in which a list of operations that had declare target
directives applied to them and were not generated at the time of
processing the original declare target directive are re-checked to apply
the appropriate declare target semantics.

This works by maintaining a vector of declare target related data inside
of the FIR converter, in this case the symbol and the two relevant
unsigned integers representing the enumerators. This vector is added to
via a new function called from Bridge.cpp, insertDeferredDeclareTargets,
which happens prior to the processing of the directive (similarly to
getDeclareTargetFunctionDevice currently for requires), it effectively
checks if the Operation the declare target directive is applied to
currently exists, if it doesn't it appends to the vector. This is a
seperate function to the processing of the declare target via the
overloaded genOMP as we unfortunately do not have access to the list
without passing it through every call, as the AbstractConverter we pass
will not allow access to it (I've seen no other cases of casting it to a
FirConverter, so I opted to not do that).

The list is then processed at the end of the module in the
finalizeOpenMPLowering function in Bridge by calling a new function
markDelayedDeclareTargetFunctions which marks the latently generated
operations. In certain cases, some still will not be generated, e.g. if
an interface is defined, marked as declare target, but has no definition
or usage in the module then it will not be emitted to the module, so due
to these cases we must silently ignore when an operation has not been
found via it's symbol.

The main use-case for this (although, I imagine there is others) is for
processing interfaces that have been declared in a module with a declare
target directive but do not have their implementation defined in the
same module. For example, inside of a seperate C++ module that will be
linked in. In cases where the interface is called inside of a target
region it'll be marked as used on device appropriately (although,
realistically a user should explicitly mark it to match the
corresponding definition), however, in cases where it's used in a
non-clear manner through something like a function pointer passed to an
external call we require this explicit marking, which this patch adds
support for (currently will cause the compiler to crash).

This patch also adds documentation on the declare target process and 
mechanisms within the compiler currently.
2024-03-05 17:27:16 +01:00
jeanPerier
06f775a82f [flang] Give internal linkage to internal procedures (#81929)
Internal procedures cannot be called directly from outside the host
procedure, so there is no point giving them external linkage. The only
reason flang did is because it is the default in MLIR.

Giving external linkage to them:
- prevents deleting them when not used/inlined by LLVM
- causes bugs with shared libraries (at least on linux x86-64) because
the call to the internal function could lead to a dynamic loader call
that would overwrite r10 register (the static chain pointer) due to
system calls and did not restore (it seems it does not expect r10 to be
used for PLT calls).

This patch gives internal linkage to internal procedures:

Note: the llvm.linkage attribute name cannot be obtained via a
getLinkageAttrName since it is not the same name as the one used in the
LLVM dialect. It is just a placeholder defined in
mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp until the func dialect
gets a real linkage model. So simply avoid hard coding it too many times
in lowering.
2024-02-28 14:30:29 +01:00
Kareem Ergawy
26b8be201e [flang][OpenMP][MLIR] Basic support for delayed privatization code-gen (#81833)
Adds basic support for emitting delayed privatizers from flang. So far,
only types of symbols are supported (i.e. scalars), support for more
complicated types will be added later. This also makes sure that
reduction and delayed privatization work properly together by merging
the
body-gen callbacks for both in case both clauses are present on the
parallel construct.
2024-02-28 10:15:57 +01:00
Valentin Clement (バレンタイン クレメン)
b3189b13b2 [flang][cuda] CUF kernel loop directive (#82836)
This patch introduces a new operation to represent the CUDA Fortran
kernel loop directive. This operation is modeled as a LoopLikeOp
operation in a similar way to acc.loop.

The CUFKernelDoConstruct parse tree node is also placed correctly in the
PFTBuilder to be available in PFT evaluations.

Lowering from the flang parse-tree to MLIR is also done.
2024-02-27 11:23:17 -08:00
Leandro Lupori
e50a231dcd [flang][OpenMP] Add support for copyprivate (#80485)
Add initial handling of OpenMP copyprivate clause in Flang.

When lowering copyprivate, Flang generates the copy function
needed by each variable and builds the appropriate
omp.single's CopyPrivateVarList.

This is patch 3 of 4, to add support for COPYPRIVATE in Flang.
Original PR: https://github.com/llvm/llvm-project/pull/73128
2024-02-21 14:51:37 -03:00
jeanPerier
e769fb8699 [flang] prevent legacy lowering from being called in pointer assignment (#81750)
When doing a pointer assignment with an RHS that is an array section,
the code fell in the legacy lowering code even with HLFIR enabled.
Escape this old code when HLFIR is on.

Should fix #80884.
2024-02-15 09:06:42 +01:00
Krzysztof Parzyszek
1af073a11c [flang][OpenMP] Pass semantics context to all generating functions in… (#81269)
… lower

The convention is to pass it after "symTable" if present, otherwise
after "converter":
- converter, symTable, semaCtx
- converter, semaCtx

This makes the interfaces more uniform---some of these functions were
already taking the semantics context, while others were not.

The context will be used in future patches.
2024-02-12 19:15:55 -06:00
Daniel Chen
b081e9d4ca [Flang] Fix NULLIFY statement that returns too early for multiple procedure pointer objects. (#81164)
The current code that handles NULLIFY statement for procedure pointer
returns after the 1st object.
This PR is to remove the `return` so it can nullify multiple procedure
pointer objects.
2024-02-09 10:56:57 -05:00
jeanPerier
0a45d172d3 [flang] Do not instantiate runtime info globals in functions (#80447)
Runtime globals are compiler generated globals injected in user scopes.
They are never referred to directly in lowering code, we only need th
fur.global for them. Yet lowering was creating hlfir.declare for them in
module procedures. In modern fortran apps, this blows up the generated
IR for nothing (Types with dozens of components, type bound procedures
and parents can create in the order of 10 000 runtime info globals to
describe them, if there is a 100 module procedure, that is that is a few
million operations generated and processed in each pass for nothing).
2024-02-05 10:12:33 +01:00
Daniel Chen
bd8bec27e2 [Flang] Support NULL(procptr): null intrinsic that has procedure pointer argument. (#80072)
This PR adds support for NULL intrinsic to have a procedure pointer
argument.
2024-01-31 11:24:17 -05:00
Sergio Afonso
837bff11cb [Flang][Lower] Attach target_cpu and target_features attributes to MLIR functions (#78289)
This patch forwards the target CPU and features information from the
Flang frontend to MLIR func.func operation attributes, which are later
used to populate the target_cpu and target_features llvm.func
attributes.

This is achieved in two stages:

1. Introduce the `fir.target_cpu` and `fir.target_features` module
attributes with information from the target machine immediately after
the initial creation of the MLIR module in the lowering bridge.

2. Update the target rewrite flang pass to get this information from the
module and pass it along to all func.func MLIR operations, respectively
as attributes named `target_cpu` and `target_features`. These attributes
will be automatically picked up during Func to LLVM dialect lowering and
used to initialize the corresponding llvm.func named attributes.

The target rewrite and FIR to LLVM lowering passes are updated with the
ability to override these module attributes, and the `CodeGenSpecifics`
optimizer class is augmented to make this information available to
target-specific MLIR transformations.

This completes a full flow by which target CPU and features make it all
the way from compiler options to LLVM IR function attributes.
2024-01-30 13:45:56 +00:00
jeanPerier
181eab27d2 [flang] Set KIND in compiler generated COUNT for SIZE(PACK) (#79801)
Compiler was rewriting SIZE(PACK(x, MASK)) to COUNT(MASK). It was
wrapping the COUNT call without a KIND argument (leading to INTEGER(4)
result in the characteristics) in an Expr<ExtentType> (implying
INTEGER(8) result), this lead to inconsistencies that later hit verifier
errors in lowering.

Set the KIND argument to the KIND of ExtentType to ensure the built
expression is consistent.

This requires giving access to some safe place where the "kind" name can
be saved and turned into a CharBlock (count has a DIM argument that
require using the KIND keyword here). For the FoldingContext that belong
to SemanticsContext, this is the same string set as the one used by
SemanticsContext for similar purposes.
2024-01-29 18:28:56 +01:00
Valentin Clement (バレンタイン クレメン)
5062a178bf [flang][openacc] Lower loop directive to the new acc.loop op design (#65417)
acc.loop was redesigned in https://reviews.llvm.org/D159229. This patch
updates the lowering to match the new op.

DO CONCURRENT construct will be added in a follow up patch.

Note that the pre-commit ci will fail until D159229 is merged. 

Depends on #67355
2024-01-22 10:31:37 -08:00
Krzysztof Parzyszek
c5a9e35437 [Flang][OpenMP] Push genEval calls to individual operations, NFC (#77758)
Introduce `genNestedEvaluations` that will lower all evaluations nested
in the given, accouting for a potential COLLAPSE directive.

Recursive lowering [2/5]
2024-01-15 08:01:41 -06:00
Katherine Rasmussen
a2d7af757b [flang] Add notify-type and notify-wait-stmt (#76594)
Add `notify-type` to `iso_fortran_env` module. Add `notify-wait-stmt` to
the parser and add checks for constraints on the statement, `C1177` and
`C1178`, from the Fortran 2023 standard. Add three semantics tests for
`notify-wait-stmt`.
2024-01-02 10:40:47 -08:00
jeanPerier
c373f58134 [flang] Lower procedure pointer components (#75453)
Lower procedure pointer components, except in the context of structure
constructor (left TODO).

Procedure pointer components lowering share most of the lowering logic
of procedure poionters with the following particularities:
- They are components, so an hlfir.designate must be generated to
retrieve the procedure pointer address from its derived type base.
- They may have a PASS argument. While there is no dispatching as with
type bound procedure, special care must be taken to retrieve the derived
type component base in this case since semantics placed it in the
argument list and not in the evaluate::ProcedureDesignator.

These components also bring a new level of recursive MLIR types since a
fir.type may now contain a component with an MLIR function type where
one of the argument is the fir.type itself. This required moving the
"derived type in construction" stackto the converter so that the object
and function type lowering utilities share the same state (currently the
function type utilty would end-up creating a new stack when lowering its
arguments, leading to infinite loops). The BoxedProcedurePass also
needed an update to deal with this recursive aspect.
2023-12-19 17:17:09 +01:00
Krzysztof Parzyszek
82e91b91ca [flang][OpenMP] Move handling of OpenMP symbol flags to OpenMP.cpp (#75523)
The function `instantiateVariable` in Bridge.cpp has the following code:
```
  if (var.getSymbol().test(
          Fortran::semantics::Symbol::Flag::OmpThreadprivate))
    Fortran::lower::genThreadprivateOp(*this, var);

  if (var.getSymbol().test(
          Fortran::semantics::Symbol::Flag::OmpDeclareTarget))
    Fortran::lower::genDeclareTargetIntGlobal(*this, var);
```

Implement `handleOpenMPSymbolProperties` in OpenMP.cpp, move the above
code there, and have `instantiateVariable` call this function instead.

This would further separate OpenMP-related details into OpenMP.cpp.
2023-12-15 09:32:57 -06:00
Krzysztof Parzyszek
aeb482106c [flang][OpenMP] Move nested eval conversion to OpenMP.cpp, NFC (#75502)
This is the first step towards exploiting `genEval` functionality from
inside of OpenMP-generating functions.

This follows discourse discussion:
https://discourse.llvm.org/t/openmp-lowering-from-pft-to-fir/75263
2023-12-15 09:01:08 -06:00
Valentin Clement (バレンタイン クレメン)
fedc54bf35 [flang] Add genEval to the AbstractConverter (#75140)
There was some discussion on discourse[1] about allowing call to FIR
generation functions from other part of lowering belonging to OpenMP.

This solution exposes a simple `genEval` member function on the
`AbstractConverter` so that IR generation for PFT Evaluation objects can
be called from lowering outside of the FirConverter but not exposing it.

[1] https://discourse.llvm.org/t/openmp-lowering-from-pft-to-fir/75263
2023-12-14 09:25:27 -08:00
jeanPerier
e59e848805 [flang] Updating drivers to create data layout before semantics (#73301)
Preliminary patch to change lowering/code generation to use
llvm::DataLayout information instead of generating "sizeof" GEP (see
https://github.com/llvm/llvm-project/issues/71507).

Fortran Semantic analysis needs to know about the target type size and
alignment to deal with common blocks, and intrinsics like
C_SIZEOF/TRANSFER. This information should be obtained from the
llvm::DataLayout so that it is consistent during the whole compilation
flow.

This change is changing flang-new and bbc drivers to:
1. Create the llvm::TargetMachine so that the data layout of the target
can be obtained before semantics.
2. Sharing bbc/flang-new set-up of the
SemanticConstext.targetCharateristics from the llvm::TargetMachine. For
now, the actual part that set-up the Fortran type size and alignment
from the llvm::DataLayout is left TODO so that this change is mostly an
NFC impacting the drivers.
3. Let the lowering bridge set-up the mlir::Module datalayout attributes
since it is doing it for the target attribute, and that allows the llvm
data layout information to be available during lowering.

For flang-new, the changes are code shuffling: the `llvm::TargetMachine`
instance is moved to `CompilerInvocation` class so that it can be used
to set-up the semantic contexts. `setMLIRDataLayout` is moved to
`flang/Optimizer/Support/DataLayout.h` (it will need to be used from
codegen pass for fir-opt target independent testing.)), and the code
setting-up semantics targetCharacteristics is moved to
`Tools/TargetSetup.h` so that it can be shared with bbc.

As a consequence, LLVM targets must be registered when running
semantics, and it is not possible to run semantics for a target that is
not registered with the -triple option (hence the power pc specific
modules can only be built if the PowerPC target is available.
2023-12-06 14:20:06 +01:00
vdonaldson
3aba9264b3 [flang] IEEE_ARITHMETIC and IEEE_EXCEPTIONS intrinsic module procedures (#74138)
Implement a selection of intrinsic module procedures that involve
exceptions.

 - IEEE_GET_FLAG
 - IEEE_GET_HALTING_MODE
 - IEEE_GET_MODES
 - IEEE_GET_STATUS
 - IEEE_LOGB
 - [f23] IEEE_MAX, IEEE_MAX_MAG, IEEE_MAX_NUM, IEEE_MAX_NUM_MAG
 - [f23] IEEE_MIN, IEEE_MIN_MAG, IEEE_MIN_NUM, IEEE_MIN_NUM_MAG
 - IEEE_QUIET_EQ, IEEE_QUIET_GE, IEEE_QUIET_GT,
 - IEEE_QUIET_LE, IEEE_QUIET_LT, IEEE_QUIET_NE
 - IEEE_SET_FLAG
 - IEEE_SET_HALTING_MODE
 - IEEE_SET_MODES
 - IEEE_SET_STATUS
 - IEEE_SIGNALING_EQ, IEEE_SIGNALING_GE, IEEE_SIGNALING_GT,
 - IEEE_SIGNALING_LE, IEEE_SIGNALING_LT, IEEE_SIGNALING_NE
 - IEEE_SUPPORT_FLAG
 - IEEE_SUPPORT_HALTING
2023-12-04 09:55:54 -08:00
Krzysztof Parzyszek
dd376f8595 [flang] Fix move-assign operator for struct IncrementLoopInfo (#74137) 2023-12-04 08:27:57 -06:00
Valentin Clement (バレンタイン クレメン)
a9a5af8270 [flang][openacc] Support early return in acc.loop (#73841)
Early return is accepted in OpenACC loop not directly nested in a
compute construct. Since acc.loop operation has a region, the
`func.return` operation cannot be directly used inside the region.
An early return is materialized by an `acc.yield` operation returning a
`true` value. The standard end of the `acc.loop` region yield a `false`
value in this case.
A conditional branch operation on the `acc.loop` result will branch to
the `finalBlock` or just to the continue block whether an early exit was
produce in the acc.loop.
2023-11-30 14:25:03 -08:00
Mats Petersson
0ccef6a723 [flang] Make adapt.valuebyref attribute work again (#73658)
This got "lost" in the HLFIR transformation. This patch applies the old
attribute to the AssociateOp that needs it, and forwards it to the
AllocaOp that is generated when lowering to FIR.
2023-11-29 16:15:43 +00:00
Daniel Chen
af09219edd [Flang] Add partial support for lowering procedure pointer assignment. (#70461)
**Scope of the PR:**
1. Lowering global and local procedure pointer declaration statement
with explicit or implicit interface. The explicit interface can be from
an interface block, a module procedure or an internal procedure.
2. Lowering procedure pointer assignment, where the target procedure
could be external, module or internal procedures.
3. Lowering reference to procedure pointers so that it works end to end.

**PR notes:**
1. The first commit of the PR does not include testing. I would like to
collect some comments first, which may alter the output. Once I confirm
the implementation, I will add some testing as a follow up commit to
this PR.
2. No special handling of the host-associated entities when an internal
procedure is the target of a procedure pointer assignment in this PR.

**Implementation notes:**
1. The implementation is using the HLFIR path.
2. Flang currently uses `getUntypedBoxProcType` to get the
`fir::BoxProcType` for `ProcedureDesignator` when getting the address of
a procedure in order to pass it as an actual argument. This PR inherits
the same design decision for procedure pointer as the `fir::StoreOp`
requires the same memory type.

Note: this commit is actually resubmitting the original commit from
PR #70461 that was reverted. See PR #73221.
2023-11-23 13:43:35 +01:00
Muhammad Omair Javaid
49f55d1075 Revert "[Flang] Add partial support for lowering procedure pointer assignment. (#70461)"
This reverts commit e07fec10ac.

This change appears to have broken following buildbots:
https://lab.llvm.org/buildbot/#/builders/176
https://lab.llvm.org/buildbot/#/builders/179
https://lab.llvm.org/buildbot/#/builders/184
https://lab.llvm.org/buildbot/#/builders/197
https://lab.llvm.org/buildbot/#/builders/198

All bots fails in testsuite where following tests seems broken:
(eg: https://lab.llvm.org/buildbot/#/builders/176/builds/7131)

test-suite::gfortran-regression-compile-regression__proc_ptr_46_f90.test
test-suite::gfortran-regression-compile-regression__proc_ptr_37_f90.test
2023-11-23 12:30:40 +05:00
Daniel Chen
e07fec10ac [Flang] Add partial support for lowering procedure pointer assignment. (#70461)
**Scope of the PR:**
1. Lowering global and local procedure pointer declaration statement
with explicit or implicit interface. The explicit interface can be from
an interface block, a module procedure or an internal procedure.
2. Lowering procedure pointer assignment, where the target procedure
could be external, module or internal procedures.
3. Lowering reference to procedure pointers so that it works end to end.

**PR notes:**
1. The first commit of the PR does not include testing. I would like to
collect some comments first, which may alter the output. Once I confirm
the implementation, I will add some testing as a follow up commit to
this PR.
2. No special handling of the host-associated entities when an internal
procedure is the target of a procedure pointer assignment in this PR.

**Implementation notes:**
1. The implementation is using the HLFIR path.
2. Flang currently uses `getUntypedBoxProcType` to get the
`fir::BoxProcType` for `ProcedureDesignator` when getting the address of
a procedure in order to pass it as an actual argument. This PR inherits
the same design decision for procedure pointer as the `fir::StoreOp`
requires the same memory type.
2023-11-22 11:51:12 -05:00
Valentin Clement (バレンタイン クレメン)
a3700cc29d [flang][openacc] Make implicit declare region unstructured (#71591)
Using an op with a region cause some issue with unstructured code. This
patch make use of acc.declare_enter and acc.declare_exit to represent
the implicit declare region.
2023-11-14 14:42:11 -08:00
Peter Klausler
1c91d9bdea [flang] Ensure that portability warnings are conditional (#71857)
Before emitting a warning message, code should check that the usage in
question should be diagnosed by calling ShouldWarn(). A fair number of
sites in the code do not, and can emit portability warnings
unconditionally, which can confuse a user that hasn't asked for them
(-pedantic) and isn't terribly concerned about portability *to* other
compilers.

Add calls to ShouldWarn() or IsEnabled() around messages that need them,
and add -pedantic to tests that now require it to test their portability
messages, and add more expected message lines to those tests when
-pedantic causes other diagnostics to fire.
2023-11-13 16:13:50 -08:00
NimishMishra
91f92e6a6b [flang][OpenMP] Fix common block missing symbol crash (#67330)
Fixes #65034 by skipping copy of host-association information if the
concerned symbol is missing from the inner construct
2023-11-10 00:17:47 -08:00
Kiran Chandramohan
d0ef94bc83 Revert "Revert "[Flang][OpenMP] Fix to support privatisation of alloc strings (#71204)""
This reverts commit ba116ff41d.

This relands https://github.com/llvm/llvm-project/pull/71204 with a fix
in the test.
2023-11-07 12:25:24 +00:00
Kiran Chandramohan
ba116ff41d Revert "[Flang][OpenMP] Fix to support privatisation of alloc strings (#71204)"
This reverts commit 192bee0db1.
Reverting to fix the CI.  https://lab.llvm.org/buildbot/#/builders/21/builds/84995
2023-11-07 11:50:24 +00:00
Kiran Chandramohan
192bee0db1 [Flang][OpenMP] Fix to support privatisation of alloc strings (#71204) 2023-11-07 11:40:25 +00:00
jeanPerier
7046202c3d [flang] Move whole allocatable assignment implicit conversion to lowering (#70317)
The front-end is making implicit conversions explicit in assignment and
structure constructors.

While this generally helps and is needed by semantics to fold structure
constructors correctly, this is incorrect when the LHS or component is
an allocatable. The RHS may have non default lower bounds that should be
propagated to the LHS, and making the conversion explicit changes the
semantics. In the structure constructor, the situation is even worse
since Fortran 2018 7.5.10 point 7 allows the value to be a reference to
an unallocated allocatable, and adding an explicit conversion in
semantics will cause a segfault.

This patch removes the explicit convert in semantics when the
LHS/component is a whole allocatable, and update lowering to deal with
the conversion insertion, dealing with preserving the lower bounds and
the tricky structure constructor case.
2023-10-27 09:07:48 +02:00
jeanPerier
b6b0756ce5 [flang] Allow lowering of sub-expressions to be overridden (#69944)
OpenACC/OpenMP atomic lowering needs a finer control over expression
lowering. This patch allows mapping evaluate::Expr<T> to mlir::Value so
that any subsequent expression lowering will use these values when an
operand is a mapped Expr<T>.

This is an alternative to
https://github.com/llvm/llvm-project/pull/69866 From which I took the
test and some of the logic to extract the non-atomic sub-expression.

---------

Co-authored-by: Nimish Mishra <neelam.nimish@gmail.com>
2023-10-25 09:22:23 +02:00
Valentin Clement (バレンタイン クレメン)
828674395b [flang][openacc] Allow acc routine at the top level (#69936)
Some compilers allow the `$acc routine(<name>)` to be placed at the
program unit level. To be compatible, this patch enables the use of acc
routine at this level. These acc routine directives must have a name.
2023-10-24 09:17:48 -07:00
jeanPerier
2ef370b771 [flang][openmp] Update copyHostAssociateVar to use hlfir.assign for HLFIR (#69441)
The code in `copyHostAssociateVar` is using `createSomeArrayAssignment`
for arrays which is using the soon legacy expression lowering. Update
the copy to use hlfir.assign instead.

I used the temporary_lhs flag to mimic the current behavior, but maybe
user defined assignment should be called when needed .This flag also
prevents any finalizers to be called on the LHS if the LHS type has
finalizers (which would occur otherwise in normal intrinsic assignment).
Again, I am not sure what the OpenMP spec wants here.

Also, I added special handling for ALLOCATABLE, the current code seems
broken to me since it is basically copying the descriptor which would
lead to memory leak given the TEMP was previously allocated with the
shape of the variable in createHostAssociateVarClone. So copying the
DATA instead seemed like the right thing to do.
2023-10-20 11:11:52 +02:00
jeanPerier
bfcd05317d [flang][hlfir] Do not emit extra declare for dummy used in BLOCK (#69184)
When a variable is used in a specification expression in a scope, it is
added to the list of variables that must be instantiated when lowering
the scope. When lowering a BLOCK, this caused instantiateVar to be
called again on all the host block variables appearing in block variable
specification expressions. This caused an extra declare to be emitted
for dummy inside block (for non dummy, instantiateVar is a no-op if the
symbol is already mapped).

Only call instantiateVar if the symbol is not mapped when lowering BLOCK
variables.
2023-10-17 09:11:53 +02:00
Pete Steinfeld
5db4779c3f [flang] Regularize TODO messages for coarray related features (#69227)
I want to make "not yet implemented" messages for features related to
coarrays easy to identify and make them easy for users to read.
2023-10-16 12:37:57 -07:00