9661 Commits

Author SHA1 Message Date
vdonaldson
9d8dc45d17
[flang] IEEE underflow control for Arm (#124807)
Update IEEE_SUPPORT_UNDERFLOW_CONTROL, IEEE_GET_UNDERFLOW_MODE, and
IEEE_SET_UNDERFLOW_MODE code for Arm.
2025-01-28 15:41:04 -05:00
Slava Zakharin
0b80491cd5
[flang] Support non-index shape/shift/slice for CG box operations. (#124625)
That is another problem uncovered during hlfir.reshape inlining,
where the shape bits could be any integer type.
This patch adds explicit convertions to `index` type where needed.
2025-01-28 09:38:33 -08:00
Slava Zakharin
2f077dfbdf
[flang] Support non-index shape in hlfir.get_extent codegen. (#124622)
hlfir.reshape inlining uncovered an existing bug that non-index shapes
result in failures during hlfir.get_extent conversion to FIR.
I could have "fixed" the shape during hlfir.reshape inlining,
but this seems like a better fix.
2025-01-28 09:25:36 -08:00
Renaud Kauffmann
56a0a7f6d1
[flang][cuda] Adding support for more atomic calls (#124671)
The PR follows the earlier
https://github.com/llvm/llvm-project/pull/123840 PR for atomic operation
support in CUF
2025-01-28 08:36:43 -08:00
David Truby
6cb71d7e85
[flang][NFC] Restrict -funroll-loops tests to known working targets (#124594)
If -funroll-loops tests are not restricted to specific targets the tests
may behave differently based on the host platform. This patch restricts
the tests to aarch64 and x86_64, and removes the PowerPC XFAIL.
2025-01-28 14:41:15 +00:00
Abid Qadeer
afa4681ce4
[flang][debug] Add support for common blocks. (#112398)
This PR adds debug support for common block in flang. As variable which
are part of a common block don't have a special marker to recognize
them, we use the following check to find them.

%0 = fir.address_of(@a)
%1 = fir.convert %0
%2 = fir.coordinate_of %1, %c0
%3 = fir.convert %2
%4 = fircg.ext_declare %3

If the memref of a fircg.ext_declare points to a fir.coordinate_of and
that in turn points to an fir.address_of (ignoring immediate
fir.convert) then we assume that it is a common block variable. The
fir.address_of gives us the global symbol which is the storage for
common block and fir.coordinate_of provides the offset in this storage.

The debug hierarchy looks like as

subroutine f3
  integer :: x, y
  common /a/ x, y
end subroutine

@a_ = global { ... } { ... }, !dbg !26, !dbg !28

!23 = !DISubprogram(name: "f3"...)
!24 = !DICommonBlock(scope: !23, name: "a", ...)
!25 = !DIGlobalVariable(name: "x", scope: !24 ...)
!26 = !DIGlobalVariableExpression(var: !25, expr: !DIExpression())
!27 = !DIGlobalVariable(name: "y", scope: !24 ...)
!28 = !DIGlobalVariableExpression(var: !27, expr:
!DIExpression(DW_OP_plus_uconst, 4))

This required following changes:

1. Instead of using DIGlobalVariableAttr in the FusedLoc of GlobalOp, we
use DIGlobalVariableExpressionAttr. This allows us the generate the
DIExpression where we have the information.

2. Previously, only one DIGlobalVariableExpressionAttr could be linked
to one global op. I recently removed this restriction in mlir. To make
use of it, we add an ArrayAttr to the FusedLoc of a GlobalOp. This
allows us to pass multiple DIGlobalVariableExpressionAttr.

3. I was depending on the name of global for the name of the common
block. The name gets a '_' appended. I could not find a utility function
in flang to remove it so I have to brute force it.
2025-01-28 12:54:15 +00:00
Muhammad Omair Javaid
c0861e9cbb Revert "[flang] IEEE underflow control for Arm (#124617)"
This reverts commit c4c76eabb88f8ee5b92fa9a84452875b0cb67d0d.

This breaks LLVM build on Windows:
https://lab.llvm.org/buildbot/#/builders/161/builds/4322
2025-01-28 17:32:45 +05:00
Nikolas Klauser
0865ecc515
[clang] Extend diagnose_if to accept more detailed warning information, take 2 (#119712)
This is take two of #70976. This iteration of the patch makes sure that
custom
diagnostics without any warning group don't get promoted by `-Werror` or
`-Wfatal-errors`.

This implements parts of the extension proposed in
https://discourse.llvm.org/t/exposing-the-diagnostic-engine-to-c/73092/7.

Specifically, this makes it possible to specify a diagnostic group in an
optional third argument.
2025-01-28 08:41:31 +01:00
Thirumalai Shaktivel
ba789c6f82
[Flang] Add semantics checks for CrayPointer usage in DSA list (#123171)
Follow-up PR to fix the failure caused here:
https://github.com/llvm/llvm-project/pull/121028

Failure:
https://lab.llvm.org/buildbot/#/builders/89/builds/14474

Problems:
- Cray pointee cannot be used in the DSA list (If used results in segmentation fault)
- Cray pointer has to be in the DSA list when Cray pointee is used in the default (none) region

Fix: Added required semantic checks along the tests
Reference from the documentation (OpenMP 5.0: 2.19.1):
- Cray pointees have the same data-sharing attribute as the storage with
which their Cray pointers are associated.
2025-01-28 08:27:42 +05:30
Slava Zakharin
c489108912
[flang] Added hlfir.reshape definition/lowering/codegen. (#124226)
Lower Fortran RESHAPE intrinsic into hlfir.reshape, and then lower
hlfir.reshape into a runtime call.
A later patch will add hlfir.reshape inlining as hlfir.elemental.
2025-01-27 18:14:02 -08:00
vdonaldson
c4c76eabb8
[flang] IEEE underflow control for Arm (#124617)
Update IEEE_SUPPORT_UNDERFLOW_CONTROL, IEEE_GET_UNDERFLOW_MODE, and
IEEE_SET_UNDERFLOW_MODE code for Arm.
2025-01-27 15:11:24 -05:00
Peter Klausler
d732c86c92
[flang] Don't take corank from actual intrinsic argument (#124029)
When constructing the characteristics of a particular reference to an
intrinsic procedure that was passed a non-coindexed reference to local
coarray data as an actual argument, don't add the corank of the actual
argument to those characteristics.

Also clean up the TypeAndShape characteristics class a little; the
Attr::Coarray is redundant since the corank() accessor can be used to
the same effect.
2025-01-27 11:57:01 -08:00
Peter Klausler
1e9b60cfa4
[flang] Recognize and check EVENT_QUERY (#123429)
Recognize the intrinsic subroutine EVENT_QUERY and enforce semantic
requirements on calls to it.
2025-01-27 11:56:41 -08:00
Abid Qadeer
2e5a5237da
[flang][debug] Avoid redundant debug data generation for derived types. (#124473)
Since https://github.com/llvm/llvm-project/pull/122770, we have seen
that compile time have become extremely slow for cyclic derived types.
In #122770, we made the criteria to cache a derived type very strict. As
a result, some types which are safe to cache were also being
re-generated every type they were required. This increased the compile
time and also the size of the debug info.

Please see the description of PR# 122770. We decided that when
processing `t1`, the type generated for `t2` and `t3` were not safe to
cached. But our algorithm also denied caching to `t1` which as top level
type was safe.

```
type t1
  type(t2), pointer :: p1
end type
type t2
  type(t3), pointer :: p2
end type
type t3
  type(t1), pointer :: p3
end type
```

I have tinkered the check a bit so that top level type is always cached.
To detect a top level type, we use a depth counter that get incremented
before call to `convertRecordType` and decremented after it returns.

After this change, the following
[file](https://github.com/fujitsu/compiler-test-suite/blob/main/Fortran/0394/0394_0031.f90)
from Fujitsu get compiled around 40s which is same as it was before
#122770.


The smaller testcase present in issue #124049 takes less than half a
second. I also added check to make sure that duplicate entries of the
`DICompositeType` are not present in the IR.

Fixes #124049 and #123960.
2025-01-27 19:38:24 +00:00
Peter Klausler
08c364280a
[flang] Improve error message on bad complex literal. (#124331)
A complex literal constant can have one BOZ component, since the type
and value of the literal can be determined by converting the BOZ value
to the type of the other component. But a complex literal constant with
two BOZ components doesn't have a well-defined type. The error message
was confusing in the case; emit a better one.

Fixes https://github.com/llvm/llvm-project/issues/124201.
2025-01-27 09:00:10 -08:00
Peter Klausler
e252c40210
[flang] Fix spurious error due to bad expression shape calculation (#124323)
GetShape() needed to be called with a FoldingContext in order to
properly construct an extent expression for the shape of an array
constructor whose elements (nested in an implied DO loop) were not
scalars.

Fixes https://github.com/llvm/llvm-project/issues/124191.
2025-01-27 08:59:43 -08:00
Peter Klausler
fee393e4ea
[flang][runtime] Don't crash on ASYNCHRONOUS='NO' in child I/O (#124208)
When ASYNCHRONOUS='NO' appears in a data transfer statement control item
list, don't crash if it isn't appropriate for the kind of I/O under way
(such as child I/O).

Fixes https://github.com/llvm/llvm-project/issues/124135.
2025-01-27 08:59:15 -08:00
Peter Klausler
b0fab14e9c
[flang] Fix spurious error in character sequence association (#124204)
When an allocatable or pointer was being associated as a storage
sequence with a dummy argument, the checks were using the actual storage
size of the allocatable or pointer's descriptor, not the size of the
storage that it references.

Fixes https://github.com/llvm/llvm-project/issues/123807.
2025-01-27 08:58:20 -08:00
Peter Klausler
c596aae47a
[flang] Catch assumed-length interoperability error (#124179)
An assumed-length character dummy argument is interoperable only if it
is neither a pointer nor allocatable.
2025-01-27 08:57:48 -08:00
Peter Klausler
d1d952c206
[flang] Interpret 'Q' exponent letter as kind=16 even on x86 (#124158)
The compiler was interpreting 'Q' as an exponent letter in a literal
real constant as meaning real(kind=10) on x86-64, which is the legacy
80387 80-bit extended precision floating-point type. It turns out that
'Q' means kind=16 with all other compilers, even for x86-64 targets.
Change to conform.
2025-01-27 08:57:27 -08:00
Peter Klausler
ec6b2c63d9
[flang] Fold character array constructor with unknown length (#123983)
When a character array constructor does not have an explicit type with a
constant length, the compiler can still fold it if all of its elements
are constants. These array constructors will have been wrapped up in the
internal %SET_LENGTH operation, which will determine the final length of
the folded value, so use the maximum length of the constant elements as
the length of the folded array constructor.

Fixes https://github.com/llvm/llvm-project/issues/123766.
2025-01-27 08:56:58 -08:00
Peter Klausler
f5ddb1012d
[flang] Fix crash in module file generation (#123859)
An assertion in module file generation didn't allow for a case that has
arisen in a test; remove it, extend commentary, and add a regression
test.

Fixes https://github.com/llvm/llvm-project/issues/123534.
2025-01-27 08:56:25 -08:00
Peter Klausler
3ac00784ac
[flang] Fix crash on erroneous program (#123843)
Catch and report multiple initializations of the same procedure pointer
rather than assuming that control wouldn't reach a given point in name
resolution in that case.

Fixes https://github.com/llvm/llvm-project/issues/123538.
2025-01-27 08:55:56 -08:00
Peter Klausler
b16c989697
[flang] Fix check for coarray actual passed to implicit interface (#123836)
The check for a coarray actual argument being passed to a procedure with
an implicit interface was incorrect, yielding false positives for
coindexed objects. Fix.
2025-01-27 08:55:20 -08:00
Peter Klausler
210e675cfd
[flang] Accept CHANGE TEAM/END TEAM as branch target (#123822)
It is valid to jump to a CHANGE TEAM statement from anywhere in the
containing executable part, and valid to jump to an END TEAM statement
from within the construct.
2025-01-27 08:54:56 -08:00
Peter Klausler
73f9034036
[flang] Fix failure to fold character array (#123418)
When a character component reference is applied to a constant array of
derived type, ensure that the length of the resulting character array is
properly defined.

Fixes https://github.com/llvm/llvm-project/issues/123362.
2025-01-27 08:46:02 -08:00
Peter Klausler
2625510ef8
[flang] Refine EVENT_TYPE/LOCK_TYPE usage checks (#123244)
The event variable in an EVENT POST/WAIT statement can be a coarray
reference, and need not be an entire coarray.

Variables and potential subobject components with EVENT_TYPE/LOCK_TYPE
must be coarrays, unless they are potential subobjects nested within
coarrays or pointers.
2025-01-27 08:45:11 -08:00
Peter Klausler
512b44d5e1
[flang] Define ATOMIC_ADD as an intrinsic procedure (#122993)
This one appears to have been omitted when other ATOMIC_xxx intrinsic
procedures were defined. There's already tests for it, but they
apparently work even when ATOMIC_ADD must be interpreted as an external
procedure with an implicit interface. Extend the tests with INTRINSIC
NONE(EXTERNAL, TYPE) statements to ensure that they require the
intrinsic interpretation.
2025-01-27 08:44:39 -08:00
Peter Klausler
038b42ba5b
[flang] Safer hermetic module file reading (#121002)
When a hermetic module file is read, use a new scope to hold its
dependent modules so that they don't conflict with any modules in the
global scope.
2025-01-27 08:43:41 -08:00
ssijaric-nv
16e9601e19
[Flang] Adjust the trampoline size for AArch64 and PPC (#118678)
Set  the trampoline size to match that in compiler-rt/lib/builtins/trampoline_setup.c
and AArch64 and PPC lowering.
2025-01-27 08:02:18 -08:00
Kareem Ergawy
1e2d5f7943
[NFC][mlir][OpenMP] Remove mentions of target from generic loop rewrite (#124528)
This removes mentions of `target` from the generic `loop` rewrite pass
since there is not need for it anyway. It is enough to detect `loop`'s
nesting within `teams` or `parallel` directives.
2025-01-27 16:44:17 +01:00
vdonaldson
3322ba493a
Revert "[flang] IEEE underflow control for Arm" (#124570)
Reverts llvm/llvm-project#124170
2025-01-27 10:40:23 -05:00
vdonaldson
20f72d19fc
Revert "[flang] arm build fix" (#124569)
Reverts llvm/llvm-project#124562
2025-01-27 10:38:42 -05:00
vdonaldson
1eb4e9f88b
[flang] arm build fix (#124562) 2025-01-27 10:32:13 -05:00
vdonaldson
3684ec4259
[flang] IEEE underflow control for Arm (#124170)
Update IEEE_SUPPORT_UNDERFLOW_CONTROL, IEEE_GET_UNDERFLOW_MODE, and
IEEE_SET_UNDERFLOW_MODE code for Arm.
2025-01-27 09:18:47 -05:00
Kareem Ergawy
d7e561b913
[flang][OpenMP] Support bind clause code-gen for standalone loops (#122674)
Extends rewriting of `loop` directives by supporting `bind` clause for
standalone directives. This follows both the spec and the current state
of clang as follows:
* No `bind` or `bind(thread)`: the `loop` is rewritten to `simd`.
* `bind(parallel)`: the `loop` is rewritten to `do`.
* `bind(teams)`: the `loop` is rewritten to `distribute`.

This is a follow-up PR for
https://github.com/llvm/llvm-project/pull/122632, only the latest commit
in this PR is relevant to the PR.
2025-01-27 15:02:38 +01:00
David Truby
98e52db4a5
Revert "[flang][NFC] Restrict -funroll-loops tests to known working targets" (#124536)
Reverts llvm/llvm-project#123939
2025-01-27 12:37:58 +00:00
David Truby
b8d921003d
[flang][NFC] Restrict -funroll-loops tests to known working targets (#123939)
If -funroll-loops tests are not restricted to specific targets the tests
may behave differently based on the host platform. This patch restricts
the tests to aarch64 and x86_64, and removes the PowerPC XFAIL.
2025-01-27 12:23:03 +00:00
Ivan Butygin
ac87d6b036
[mlir][arith] Fold arith.cmpi eq, %val, %one : i1 -> %val and arith.cmpi ne, %val, %zero : i1 -> %val (#124436)
https://alive2.llvm.org/ce/z/dNZMdC
2025-01-27 14:28:09 +03:00
jeanPerier
7211bf48a6
[flang][driver] add negative from of -fsave-main-program (#124110)
Add the `-fno` form for consistency and to make it easy to switch the
default for downstream users.
2025-01-27 10:51:23 +01:00
Mats Petersson
8035d38daa
[Flang][OpenMP]Add parsing support for DISPATCH construct (#121982)
This allows the Flang parser to accept the !$OMP DISPATCH and related
clauses.

Lowering is currently not implemented. Tests for unparse and parse-tree
dump is provided, and one for checking that the lowering ends in a "not
yet implemented"

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2025-01-26 09:44:04 +00:00
Valentin Clement (バレンタイン クレメン)
48657bf29b
[flang][cuda] Handle launch of cooperative kernel (#124362)
Add `CUFLaunchCooperativeKernel` entry points and lower gpu.launch_func
with grid_global attribute to this entry point.
2025-01-24 15:52:05 -08:00
Valentin Clement (バレンタイン クレメン)
05fd4d5775
[flang][cuda] Perform inlined assignment when field is c_devptr (#124322)
When a field in a derived type is `c_devptr`, keep check if we can do a
memcpy instead of falling back to the runtime assignment.

Many internal CUDA Fortran derived type have a `c_devptr` field and this
would lead to stack overflow on the device if the assignment is
performed by the runtime function.
2025-01-24 14:32:07 -08:00
Valentin Clement (バレンタイン クレメン)
ee054404df
[flang][cuda] Carry over the cuf.proc_attr attribute to gpu.launch_func (#124325) 2025-01-24 13:09:58 -08:00
Valentin Clement (バレンタイン クレメン)
544a3cb65b
[flang][cuda] Handle variable with initialization in device global pass (#124307) 2025-01-24 10:09:38 -08:00
Slava Zakharin
3da7de34a2
[flang][runtime] Disable optimization for traceback related functions. (#124172)
The backtrace may at least print the backtrace name in the call stack,
but this does not happen with the release builds of the runtime.
Surprisingly, specifying "no-omit-frame-pointer" did not work
with GCC, so I decided to fall back to -O0 for these functions.
2025-01-24 08:49:35 -08:00
Tom Eccles
9cf52fe1f9
[flang][OpenMP][NFC] test the current private dealloc runtime calls (#124017)
It looks like in most cases we still don't make calls to deallocate
allocatable members of derived types which have been privatized.

This is just intended to add a test for the one case where we do, to
make sure this doesn't regress with my upcoming changes.
2025-01-24 14:48:47 +00:00
Kiran Chandramohan
9bb3c62948
[Flang][Driver] Deprecate Ofast (#101701)
This is subject to agreement by the Flang community
(https://discourse.llvm.org/t/rfc-deprecate-ofast-in-flang/80243).
2025-01-24 10:18:14 +00:00
Jianjian Guan
990837f91d
[mlir][arith][tensor] Disable index type for bitcast (#121455)
Fixes #121397.
2025-01-24 16:53:04 +08:00
Kazu Hirata
df3bc54eff
[flang] Avoid repeated hash lookups (NFC) (#124230) 2025-01-24 00:50:07 -08:00