9671 Commits

Author SHA1 Message Date
David Truby
350e0e2b45 [flang] fix AArch64 PCS for struct following pointer (#127802)
Pointers are already handled as taking up a register in the ABI
handling, but the handling for structs was not taking this into account.
This patch changes the struct handling to acknowledge that pointer
arguments take up an integer register.

Fixes #123075

(cherry picked from commit 449f84fea652e31de418c3087d7e3628809241b4)
2025-02-25 08:27:06 -08:00
Nikita Popov
160e6ace3e [mlir][cmake] Do not export MLIR_MAIN_SRC_DIR and MLIR_INCLUDE_DIR (#125842)
MLIR_MAIN_SRC_DIR and MLIR_INCLUDE_DIR point to the source directory,
which is not installed. As such, the installed MLIRConfig.cmake also
should not reference it.

The comment indicates that these are needed for mlir_tablegen(), but I
don't see any related uses.

The motivation for this is the use in flang, where we end up inheriting
a meaningless MLIR_MAIN_SRC_DIR from a previous MLIR build, whose source
directory doesn't exist anymore, and that cannot be overridden with the
correct path, because it's not a cached variable.

Instead do what all the other projects do for LLVM_MAIN_SRC_DIR and
initialize MLIR_MAIN_SRC_DIR to CMAKE_CURRENT_SOURCE_DIR/../mlir.

For MLIR_INCLUDE_DIR there already is an exported MLIR_INCLUDE_DIRS,
which can be used instead.

(cherry picked from commit 82bd148a3f25439d7f52a32422dc1bcd2da03803)
2025-02-25 08:05:37 -08:00
Tom Stellard
2b70b17d30 flang: Fix build with latest libc++ (#127362)
I think this first stopped working with
954836634abb446f18719b14120c386a929a42d1. This patch fixes the following
error:

/home/runner/work/llvm-project/llvm-project/flang/runtime/io-api-minimal.cpp:153:11:
error: '__libcpp_verbose_abort' is missing exception specification
'noexcept'
   153 | void std::__libcpp_verbose_abort(char const *format, ...) {
       |           ^
| noexcept
/mnt/build/bin/../include/c++/v1/__verbose_abort:30:28: note: previous
declaration is here
30 | __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format,
...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT;
       |                            ^
1 error generated.

(cherry picked from commit 2b340c10a611d929fee25e6222909c8915e3d6b6)
2025-02-19 14:59:21 +00:00
Nikita Popov
4c4ed5e2f5 [flang][cmake] Fix bcc dependencies (#125822)
The Fortran libraries are not part of MLIR, so they should use
target_link_libraries() rather than mlir_target_link_libraries().

This fixes an issue introduced in
https://github.com/llvm/llvm-project/pull/120966.

(cherry picked from commit f9af5c145f40480d46874b643ca2b1237e9fbb2a)
2025-02-11 14:59:41 +01:00
Nikita Popov
dfa60a77e0 [flang] Move FIRSupport dependency to correct place (#125697)
This library is provided by flang, not MLIR, so it should not be part of
MLIR_LIBS.

Fixes an issue introduced in https://github.com/llvm/llvm-project/pull/120966.

(cherry picked from commit ee76bdac192ce86c5d13e4c712e0327aaefda45f)
2025-02-11 14:59:41 +01:00
Nikita Popov
7fda02c09d [flang] Use clang_target_link_libraries() for clang dependency (#126037)
This dependency is part of libclang-cpp, so it should use
clang_target_link_libraries.

(cherry picked from commit 7c695e4906300a11208d7979c470d63b0d037bb2)
2025-02-10 14:14:15 -08:00
Brad Smith
7bcfaa1c4d [flang][Driver] When linking with the Fortran runtime also link with libexecinfo (#125998)
Also link with libexecinfo on FreeBSD, NetBSD, OpenBSD and DragonFly
for the backtrace functions.

(cherry picked from commit d1de75acea0da55316cd7827563e064105868f0f)
2025-02-07 13:08:01 -08:00
Brad Smith
8fe8a86920 [flang][runtime] Make sure to link libexecinfo if it exists (#125344)
Fixes building the backtrace support on FreeBSD/NetBSD/OpenBSD/DragonFly and musl
libc with libexecinfo.

(cherry picked from commit cb2598dda1aae5096a77bc8a9f6679ca1b350e5e)
2025-02-05 13:44:03 -08:00
Brad Smith
c560d6f2c7 [flang] Fix building on aarch64 *BSD and musl libc after 9d8dc45d17088300e9e2086594ca581b119193c8 (#125183)
The fpu_control.h header appears to be GLIBC specific.

(cherry picked from commit e31c6c97b795e57a7b1ee31ad37eced40c6305ed)
2025-01-31 17:30:29 -08:00
vdonaldson
d5333f265b [flang] Build fix (#125087)
Reinstate a preprocessor define for a nonstandard exception.

[124978](https://github.com/llvm/llvm-project/issues/124978#event-16113621403)

(cherry picked from commit 7fa1257c35581268deb5f0fc2faa3ae46358f958)
2025-01-31 17:17:12 -08:00
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