Commit Graph

8599 Commits

Author SHA1 Message Date
Pete Steinfeld
bf5a2a99b1 [flang] Fix build problem caused by #96807 (#97450)
I had erroneously used a bitwise '&' with boolean operands which caused
a warning on the ARM build. This change fixes that.
2024-07-02 10:46:15 -07:00
Michael Klemm
5e564d97e3 [Flang][runtime] Fix compilation errors introduced with PR #96652 (#97442) 2024-07-02 19:25:23 +02:00
Michael Klemm
7359edbc09 [Flang][runtime] Distinguish CPU time and elapsed time for cpu_time and system_clock (#96652)
The current implementation for `system_clock()` returns the CPU time
instead of elapsed wallclock time. This PR fixes the issue and makes
`system_clock()` correctly return elapsed time.
2024-07-02 18:37:33 +02:00
Pete Steinfeld
70969df73d [flang] Improve warnings for invalid arguments when folding host runtime (#96807)
This is another attempt at a change that Jean made to Phabricator in
https://reviews.llvm.org/D116934. That attempt ran into problems with
building on Windows.

This change improves the messages that are produced when running into
invalid arguments during constant folding.

Note that the original attempt at implementing this contained additional
code in .../llvm-project/flang/test/Evaluate/folding04.f90:
```
  !WARN: warning: argument 'x' must be strictly positive
  real(8), parameter :: nan_r8_dlog1 = dlog(-0.1_8)
  TEST_ISNAN(nan_r8_dlog1)
```
For reasons I don't understand, this additional code caused the Windows
build to fail. So this new version of the update does not contain that
code.
2024-07-02 08:38:43 -07:00
jeanPerier
66d5ca2a3d Reland "[flang] add extra component information in fir.type_info" (#97404)
Reland #96746 with the proper Support/CMakelist.txt change.

fir.type does not contain all Fortran level information about
components. For instance, component lower bounds and default initial
value are lost. For correctness purpose, this does not matter because
this information is "applied" in lowering (e.g., when addressing the
components, the lower bounds are reflected in the hlfir.designate).

However, this "loss" of information will prevent the generation of
correct debug info for the type (needs to know about lower bounds). The
initial value could help building some optimization pass to get rid of
initialization runtime calls.

This patch adds lower bound and initial value information into
fir.type_info via a new fir.dt_component operation. This operation is
generated only for component that needs it, which helps keeping the IR
small for "boring" types.

In general, adding Fortran level info in fir.type_info will allow
delaying the generation of "type descriptors" gobals that are very
verbose in FIR and make it hard to work with FIR dumps from applications
with many derived types.
2024-07-02 15:19:49 +02:00
Slava Zakharin
17bd3120ad [flang] Use 0 for unknown function pointer result length. (#97035) 2024-07-02 03:14:44 -07:00
Ramkumar Ramachandra
db791b278a mlir/LogicalResult: move into llvm (#97309)
This patch is part of a project to move the Presburger library into
LLVM.
2024-07-02 10:42:33 +01:00
harishch4
471ca9496f [Flang][OpenMP]Make Do concurrent indices private (#93785)
Fixes: #85538
2024-07-02 09:21:24 +05:30
Kazu Hirata
0a8d5f4e59 [flang] Use std::make_unique (NFC) (#97238)
This patch is based on clang-tidy's modernize-make-unique but limited
to those cases where type names are mentioned twice like
std::unique_ptr<Type>(new Type()), which is a bit mouthful.
2024-07-01 14:41:06 -07:00
Leandro Lupori
29cdc8f9ca [flang][OpenMP] Fix nested privatization of allocatable (#96968)
In nested constructs where a given variable is privatized more than
once, using the default clause, the innermost host association symbol
will point to the previous host association symbol.
Such symbol lacks the allocatable attribute and can't be used to
generate the type of the symbol to be cloned. Use the ultimate
symbol instead.

Fixes #85594, #80398
2024-07-01 14:10:35 -03:00
Sergio Afonso
03d9a31772 [Flang][OpenMP] Update flang with changes to the OpenMP dialect (#92524)
This patch applies fixes after the updates to OpenMP clause operands, as
well as updating some tests that were impacted by changes to the
ordering or assembly format of some clauses in MLIR.
2024-07-01 11:08:14 +01:00
Peter Klausler
259ce11999 [flang] Accept a compiler directive sentinel after a semicolon (#96966)
Don't treat !DIR$ or an active !$ACC, !$OMP, &c. as a comment when they
appear after a semicolon, but instead treat them as a compiler directive
sentinel.
2024-06-28 12:16:41 -07:00
Peter Klausler
cddbcd15a0 [flang][preprocessor] Expand some keyword macros in quoted character … (#96987)
…literals

To help port codes from compilers using pre-ANSI C preprocessors, which
didn't care much about context when replacing macros, support the
replacement of keyword macros in quoted character literals when (and
only when) the name of the keyword macro constitutes the entire
significant portion of a free form continuation line. See the new test
case for a motivating example.

Fixes https://github.com/llvm/llvm-project/issues/96781.
2024-06-28 12:14:23 -07:00
Peter Klausler
72c801f843 [flang] Handle BOZ as right-hand side of assignment (#96672)
F'2023 allows BOZ to appear in more contexts, including the common
extension of the right-hand side of an assignment to an INTEGER or REAL
variable. Implement that one case now.
2024-06-28 11:46:54 -07:00
Peter Klausler
084d943663 [flang] Fix excess allocation (#96663)
A recent patch introduced an error in an aligned byte size calculation
that causes an extra word to be allocated when the original byte size is
already aligned (including the case of zero). Fix.
2024-06-28 11:32:09 -07:00
Michael Klemm
66f55a7f48 [Flang] Re-enable -print-resource-dir compiler option (#96799)
This PR re-enables the command line option `-print-resources-dir` after
PR #96557 has reverted the changes made.

The way this works now, is that it simply prints the current resource
dir, which points to clang/$version.
2024-06-28 16:22:00 +02:00
Lucas Duarte Prates
bb83a3df25 Re-land: "[AArch64] Add ability to list extensions enabled for a target" (#95805) (#96795)
This introduces the new `--print-enabled-extensions` command line option
to AArch64, which prints the list of extensions that are enabled for the
target specified by the combination of `--target`/`-march`/`-mcpu`
values.

The goal of the this option is both to enable the manual inspection of
the enabled extensions by users and to enhance the testability of
architecture versions and CPU targets implemented in the compiler.

As part of this change, a new field for `FEAT_*` architecture feature
names was added to the TableGen entries. The output of the existing
`--print-supported-extensions` option was updated accordingly to show
these in a separate column.
2024-06-28 09:20:16 +01:00
Kareem Ergawy
4a746e50b1 [NFC][flang] Remove unused converter parameter. (#96854)
Removes an unused parameter in 2 utils that generate bounds ops.
2024-06-28 05:20:59 +02:00
Pete Steinfeld
e55aa027f8 [flang] Fix runtime error messages for the MATMUL intrinsic (#96928)
There are three forms of MATMUL -- where the first argument is a rank 1
array, where the second argument is a rank 1 array, and where both
arguments are rank 2 arrays. There's code in the runtime that detects
when the array shapes are incorrect. But the code that emits an error
message assumes that both arguments are rank 2 arrays.

This change contains code for the other two cases.
2024-06-27 14:54:02 -07:00
jeanPerier
6a66b8224d Revert "[flang] add extra component information in fir.type_info" (#96937)
Reverts llvm/llvm-project#96746
Breaking shared library buillds:
https://lab.llvm.org/buildbot/#/builders/89/builds/931
2024-06-27 19:22:48 +02:00
jeanPerier
1448ed2000 [flang] add extra component information in fir.type_info (#96746)
fir.type does not contain all Fortran level information about
components. For instance, component lower bounds and default initial
value are lost. For correctness purpose, this does not matter because
this information is "applied" in lowering (e.g., when addressing the
components, the lower bounds are reflected in the hlfir.designate).

However, this "loss" of information will prevent the generation of
correct debug info for the type (needs to know about lower bounds). The
initial value could help building some optimization pass to get rid of
initialization runtime calls.

This patch adds lower bound and initial value information into
fir.type_info via a new fir.dt_component operation. This operation is
generated only for component that needs it, which helps keeping the IR
small for "boring" types.

In general, adding Fortran level info in fir.type_info will allow
delaying the generation of "type descriptors" gobals that are very
verbose in FIR and make it hard to work with FIR dumps from applications
with many derived types.
2024-06-27 18:59:03 +02:00
Tom Eccles
d4e9ba59d6 [mlir][OpenMP] Standardise representation of reduction clause (#96215)
Now all operations with a reduction clause have an array of bools
controlling whether each reduction variable should be passed by
reference or value.

This was already supported for Wsloop and Parallel. The new operations
modified here currently have no flang lowering or translation to LLVMIR
and so further changes are not needed.

It isn't possible to check the verifier in
mlir/test/Dialect/OpenMP/invalid.mlir because there is no way of parsing
an operation to have an incorrect number of byref attributes. The
verifier exists to pick up buggy operation builders or in-place
operation modification.
2024-06-27 12:06:22 +01:00
Yi Wu
dfd2711f8f Revert "Revert "[flang] Fix execute_command_line cmdstat is not set when error occurs" (#96365)" (#96774)
The fix broke llvm-test-suite, so it was reverted previously. With test
fixes added in https://github.com/llvm/llvm-test-suite/pull/137, it
should now pass the tests

This reverts commit 435635652f.
2024-06-27 10:53:56 +01:00
harishch4
b4ab52c8e7 [Flang][OpenMP] Lowering Order clause to MLIR (#96730) 2024-06-27 11:58:12 +05:30
Lucas Duarte Prates
b579aacc30 Revert "[AArch64] Add ability to list extensions enabled for a target" (#96768)
Reverts llvm/llvm-project#95805 due to test failures caught by the
buildbots.
2024-06-26 14:59:01 +01:00
Lucas Duarte Prates
b6240c3715 [AArch64] Add ability to list extensions enabled for a target (#95805)
This introduces the new `--print-enabled-extensions` command line option
to AArch64, which prints the list of extensions that are enabled for the
target specified by the combination of `--target`/`-march`/`-mcpu`
values.

The goal of the this option is both to enable the manual inspection of
the enabled extensions by users and to enhance the testability of
architecture versions and CPU targets implemented in the compiler.

As part of this change, a new field for `FEAT_*` architecture feature
names was added to the TableGen entries. The output of the existing
`--print-supported-extensions` option was updated accordingly to show
these in a separate column.
2024-06-26 14:28:26 +01:00
dpalermo
55e60c3521 [flang] Fix BoxAnalyzer.h for LLVM_ENABLE_EXPENSIVE_CHECKS (#96675)
Fixes assert seen trying to use default number of inlined elements for
`SmallVector<T>` but `sizeof(T)` is really big. Seen with
-DLLVM_ENABLE_EXPENSIVE_CHECKS.
2024-06-25 21:12:32 -04:00
Tarun Prabhu
8dd9494056 Revert "[flang] Add basic -mtune support" (#96678)
Reverts llvm/llvm-project#95043
2024-06-25 13:25:39 -06:00
agozillon
aec735cf47 [Flang][OpenMP][MLIR] Fix common block mapping for regular and declare target link (#91829)
This PR attempts to fix common block mapping for regular mapping of
these types as well as when they have been marked as "declare target
link". This PR should allow correct mapping of both the members of a
common block and the full common block via its block symbol.

The main changes were some adjustments to the Fortran OpenMP lowering to
HLFIR/FIR, the lowering of the LLVM+OpenMP dialect to LLVM-IR and
adjustments to the way the we handle target kernel map argument
rebinding inside of the OMPIRBuilder.

For the Fortran OpenMP lowering were two changes, one to prevent the
implicit capture of common block members when the common block symbol
itself has been marked and the other creates intermediate member access
inside of the target region to be used in-place of those external to the
target region, this prevents external usages breaking the
IsolatedFromAbove pact.

In the latter case, there was an adjustment to the size calculation for
types to better handle cases where we pass an array as the type of a map
(as opposed to the bounds and the type of the element), which occurs in
the case of common blocks. There is also some adjustment to how
handleDeclareTargetMapVar handles renaming of declare target symbols in
the module to the reference pointer, now it will only apply to those
within the kernel that is currently being generated and we also perform
a modification to replace constants with instructions as necessary as we
cannot replace these with our reference pointer (non-constant and
constants do not mix nicely).

In the case of the OpenMPIRBuilder some changes were made to defer
global symbol rebinding to kernel arguments until all other arguments
have been rebound. This makes sure we do not replace uses that may refer
to the global (e.g. a GEP) but are themselves actually a separate
argument that needs bound.

Currently "declare target to" still needs some work, but this may be the
case for all types in conjunction with "declare target to" at the
moment.
2024-06-25 20:54:04 +02:00
Alexis Perry-Holby
a790279bf2 [flang] Add basic -mtune support (#95043)
This PR adds -mtune as a valid flang flag and passes the information
through to LLVM IR as an attribute on all functions. No specific
architecture optimizations are added at this time.
2024-06-25 18:39:35 +01:00
Mats Petersson
de528ffb17 [Flang] Extracting internal constants from scalar literals (#73829)
Constants actual arguments in function/subroutine calls are currently
lowered as allocas + store. This can sometimes inhibit LTO and the
constant will not be propagated to the called function. Particularly in
cases where the function/subroutine call happens inside a condition.

This patch changes the lowering of these constant actual arguments to a
global constant + fir.address_of_op. This lowering makes it easier for
LTO to propagate the constant.

The optimization must be enabled explicitly to run. Use -mmlir
--enable-constant-argument-globalisation to enable.

---------

Co-authored-by: Dmitriy Smirnov <dmitriy.smirnov@arm.com>
2024-06-25 15:42:02 +01:00
Leandro Lupori
952bdaaf79 [flang][OpenMP] Fix copyprivate allocatable/pointer lowering (#95975)
The lowering of copyprivate clauses with allocatable or pointer
variables was incorrect. This happened because the values passed to
copyVar() are always wrapped in SymbolBox::Intrinsic, which
resulted in allocatable/pointer variables being handled as regular
ones.

This is fixed by providing to copyVar() the attributes of the
variables being copied, to make it possible to detect and handle
allocatable/pointer variables correctly.

Fixes #95801
2024-06-25 09:25:41 -03:00
Abid Qadeer
919b1ecafc [flang][debug] Support pointer type. (#96153)
The handling of `PointerType` is similar to `HeapType`. The only
difference is that allocated flag is generated for `HeapType` and
associated flag for `PointerType`. The tests for pointer to allocatable
strings are disabled for now. I will enable them once #95906 is merged.

The debugging in GDB looks like this:
    
      integer, pointer :: par2(:)
      integer, target, allocatable :: ar2(:) 
      integer, target :: sc
      integer, pointer :: psc
      allocate(ar2(4))
      par2 => ar2
      psc => sc
    
    19        par2 => ar2
    (gdb) p par2
    $3 = <not associated>
    (gdb) n
    20        do i=1,5
    (gdb) p par2
    $4 = (0, 0, 0, 0)
    (gdb) ptype par2
    type = integer (4)
    (gdb) p sc
    $5 = 3
    (gdb) p psc
    $6 = (PTR TO -> ( integer )) 0x7fffffffda24
    (gdb) p *psc
    $7 = 3
2024-06-25 10:00:45 +01:00
David Truby
954b692bd7 [flang] Allow derf as alternate spelling for erf (#95784)
This patch adds derf as an alternate spelling for the erf intrinsic.
This spelling is supported by multiple other compilers and used by WRF.
2024-06-25 01:24:49 +01:00
David Truby
a2d340ba16 Revert "[Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory" (#96557)
Reverts llvm/llvm-project#90886

These changes broke linking to compiler-rt on Windows
2024-06-25 00:46:50 +01:00
Peter Klausler
514c1ec547 [flang][runtime] Interoperable POINTER deallocation validation (#96100)
Extend the runtime validation of deallocated pointers so that it also
works when pointers are allocated &/or deallocated outside Fortran.
Previously, bogus runtime errors would be reported for pointers
allocated via CFI_allocate() and deallocated in Fortran, and
CFI_deallocate() did not check that it was deallocating a whole
contiguous pointer that was allocated as such.
2024-06-24 10:46:30 -07:00
Peter Klausler
eac925fb81 [flang][runtime] Better handling of "fort.N" opening errors (#96347)
When a data transfer statement references a unit number that hasn't been
explicitly OPENed, the runtime I/O support library opens a local
"fort.N" file where N is the unit number. If that name exists in the
current working directory but is not a readable or writable file (as
appropriate), the runtime needs to catch the error at the point of the
READ or WRITE statement rather than leaving an open unit in the unit map
without a valid file descriptor.
2024-06-24 10:34:37 -07:00
Peter Klausler
5d15f606da [flang][preprocessing] Mix preprocessing directives with free form li… (#96244)
…ne continuation

Allow preprocessing directives to appear between a source line and its
continuation, including conditional compilation directives (#if, #ifdef,
&c.).

Fixes https://github.com/llvm/llvm-project/issues/95476.
2024-06-24 10:18:50 -07:00
Abid Qadeer
3a57925b07 [flang][debug] Handle allocatable strings. (#95906)
The allocatable strings also use DIStringType but provide dwarf
expressions to find the location and length of the string. With this
change in place, the debugging of the allocatable strings looks like
this:

  character(len=:), allocatable :: first
  character(len=:), allocatable :: second
  character(len=:), allocatable :: third

  first = 'Mount'
  second = 'Everest'
  third = first // " " // second
  print *, third

(gdb) p third
$1 = ""
(gdb) n
18        print *, third
(gdb) p third
$2 = 'Mount Everest'
(gdb) ptype third
type = character (13)
2024-06-24 18:04:19 +01:00
Peter Klausler
9ab292d726 [flang] Add/fix some semantic checks for assumed-rank (#96194)
Catch some cases where assumed rank dummy arguments are not allowed.
2024-06-24 09:57:30 -07:00
Peter Klausler
317277e4f9 [flang] Better error reporting for MOD/MODULO/NEAREST (#96114)
When the second argument to these intrinsic functions is a scalar
constant zero, emit a warning (if enabled) even if the first argument is
not a constant.
2024-06-24 09:21:06 -07:00
Peter Klausler
3602efa78d [flang] Silence errors on C_LOC/C_FUNLOC in specification expressions (#96108)
Transformational functions from the intrinsic module ISO_C_BINDING are
allowed in specification expressions, so tweak some general checks that
would otherwise trigger error messages about inadmissible targets, dummy
procedures in specification expressions, and pure procedures with impure
dummy procedures.
2024-06-24 09:06:32 -07:00
jeanPerier
73cf014223 [flang] harden TypeAndShape for assumed-ranks (#96234)
SIZEOF and C_SIZEOF were broken for assumed-ranks because
`TypeAndShape::MeasureSizeInBytes` behaved as a scalar because the
`TypeAndShape::shape_` member was the same for scalar and assumed-ranks.

The easy fix would have been to add special handling in
`MeasureSizeInBytes` for assumed-ranks using the TypeAndShape
attributes, but I think this solution would leave `TypeAndShape::shape_`
manipulation fragile to future developers. Hence, I went for the
solution that turn shape_ into a `std::optional<Shape>`.
2024-06-24 10:21:04 +02:00
Kiran Chandramohan
435635652f Revert "[flang] Fix execute_command_line cmdstat is not set when error occurs" (#96365)
Reverts llvm/llvm-project#93023

Reverting due to buildbot failure.
https://lab.llvm.org/buildbot/#/builders/41/builds/227
test-suite ::
Fortran/gfortran/regression/gfortran-regression-execute-regression__execute_command_line_3_f90
2024-06-21 23:47:13 +01:00
Kelvin Li
b284ced069 [flang] Use %flang_fc1 to avoid options being inserted between %flang and -fc1 (NFC) (#96320) 2024-06-21 15:29:06 -04:00
Yi Wu
4232dd586b [flang] Fix execute_command_line cmdstat is not set when error occurs (#93023)
Fixes: https://github.com/llvm/llvm-project/issues/92929
Also added cmdstat for common linux return code 1, 126, 127
2024-06-21 14:42:07 +01:00
Abid Qadeer
c2a22f1a72 [flang][debug] Cleanup tests. (NFC) (#96189)
@kiranchandramohan mentioned
[here](https://github.com/llvm/llvm-project/pull/91582#discussion_r1606046605)
that LLVM IR tests should go in the Integration folder. He also
mentioned
[here](https://github.com/llvm/llvm-project/pull/91582#discussion_r1606684034)
that tests for `add-debug-info` pass should test that pass only. There
were some tests which were added before his comments so I have cleaned
them in this PR. The following changes were made.

1. Move LLVM IR tests to `Integration` folder.
2. Change tests from f90 to fir and only test changes done by
`add-debug-info` pass.
2024-06-21 10:16:53 +01:00
Anchu Rajendran S
826bde5d8a Adding parsing support for omp loop, target loop directives (#93517)
Change adds parsing support for omp loop, omp target loop, omp target
parallel loop and omp target teams loop.
2024-06-21 09:40:34 +05:30
jeanPerier
8f90258a51 [flang] implement assumed-rank in ENTRY (#96111)
With `createUnallocatedBox` utility change from #96106 , the TODO for assumed-rank in entry
can simply be lifted and test is added.

The key is that a unallocated assumed-rank descriptor is created with
rank zero in the entry where an assumed-rank dummy from some other entry
do not appear as a dummy (the symbol must still be mapped to some valid
value because the symbol could be used in code that would be unreachable
at runtime, but that the compiler must still generate).
2024-06-20 15:11:09 +02:00
jeanPerier
4abbf99579 [flang] lower assumed-ranks captured in internal procedures (#96106)
Note: the added test fails because it needs the `associateMutableBox`
change from https://github.com/llvm/llvm-project/pull/96082. I will
rebase this PR once the other is merged.
2024-06-20 14:51:16 +02:00