summaryrefslogtreecommitdiff
path: root/flang/lib/Optimizer/CodeGen/Target.cpp
AgeCommit message (Collapse)Author
2025-07-16[OpenMP] Add TargetAMDGPU support for Complex argument and return types ↵Akash Banerjee
(#144924)
2025-04-25[flang] Use correct int extension flags for C-ABI calls on aarch64 (#137105)Asher Mancinelli
The AArch64 procedure call standard does not mandate that the callee extends the return value. Clang does not add signext to functions returning i8 or i16 on linux aarch64, but flang does. This means that runtime routines returning i8's will have signext on the callsite/declaration, but not on the implementation, and the call site will assume the return value has already been sign extended when it has not. This showed up in a test case calling MINVAL on an array of INTEGER*1. Adjust our integer extension flags to match clang and aarch64pcs on linux. The behavior on Darwin should be preserved. This is listed on the apple developer guide as a divergence from aarch64pcs.
2025-04-17[flang] Add 32-bit AIX target specific in order to build 32-bit flang-rt ↵Daniel Chen
(#136051)
2025-03-03[flang] handle passing bind(c) derived type by value for ppc64le and ↵Kelvin Li
powerpc64-aix (#128780)
2025-02-21[flang] fix AArch64 PCS for struct following pointer (#127802)David Truby
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
2025-01-16[mlir][IR] Remove factory methods from `FloatType` (#123026)Matthias Springer
This commit removes convenience methods from `FloatType` to make it independent of concrete interface implementations. See discussion here: https://discourse.llvm.org/t/rethink-on-approach-to-low-precision-fp-types/82361 Note for LLVM integration: Replace `FloatType::getF32(` with `Float32Type::get(` etc.
2024-12-18[flang] AArch64 ABI for BIND(C) VALUE parameters (#118305)David Truby
This patch adds handling for derived type VALUE parameters in BIND(C) functions for AArch64.
2024-12-02[flang][fir] fix ABI bug 116844 (#118121)jeanPerier
Fix issue #116844. The issue came from a look-up on the func.func for the sret attribute when lowering fir.call with character arguments. This was broken because the func.func may or may not have been rewritten when dealing with the fir.call, but the lookup assumed it had not been rewritten yet. If the func.func was rewritten and the result moved to a sret argument, the call was lowered as if the character was meant to be the result, leading to bad call code and an assert. It turns out that the whole logic is actually useless since fir.boxchar are never lowered as sret arguments, instead, lowering directly breaks the character result into the first two `fir.ref<>, i64` arguments. So, the sret case was actually never used, except in this bug. Hence, instead of fixing the logic (probably by looking for argument attributes on the call itself), just remove this logic that brings unnecessary complexity.
2024-11-29[Flang] LoongArch64 support for BIND(C) derived types in mabi=lp64d. (#117108)Zhaoxin Yang
This patch: - Supports both the passing and returning of BIND(C) type parameters. - Adds `mabi` check for LoongArch64. Currently, flang only supports `mabi=` option set to `lp64d` in LoongArch64, other ABIs will report an error and may be supported in the future. Reference ABI: https://github.com/loongson/la-abi-specs/blob/release/lapcs.adoc#subroutine-calling-sequence
2024-11-25[flang] AArch64 support for BIND(C) derived return types (#114051)David Truby
This patch adds support for BIND(C) derived types as return values matching the AArch64 Procedure Call Standard for C. Support for BIND(C) derived types as value parameters will be in a separate patch.
2024-11-19[Flang][LoongArch] Add sign extension for i32 arguments and returns in ↵Zhaoxin Yang
function signatures. (#116146) In loongarch64 LP64D ABI, `unsigned 32-bit` types, such as unsigned int, are stored in general-purpose registers as proper sign extensions of their 32-bit values. Therefore, Flang also follows it if a function needs to be interoperable with C. Reference: https://github.com/loongson/la-abi-specs/blob/release/lapcs.adoc#Fundamental-types
2024-11-13[Flang][LoongArch] Add support for complex16 params/returns. (#114732)Zhaoxin Yang
In LoongArch64, the passing and returning of type `complex16` is similar to that of structure type like `struct {fp128, fp128}`, meaning they are passed and returned by reference. This behavior is similar to clang, so it can implement conveniently `iso_c_binding`. Additionally, this patch fixes the failure in flang test Integration/debug-complex-1.f90: ``` llvm-project/flang/lib/Optimizer/codeGen/Target.cpp:56: not yet implemented: complex for this precision for return type
2024-10-14[flang] correctly deal with bind(c) derived type result ABI (#111969)jeanPerier
Derived type results of BIND(C) function should be returned according the the C ABI for returning the related C struct type. This currently did not happen since the abstract-result pass was forcing the Fortran ABI for all derived type results. use the bind_c attribute that was added on call/func/dispatch in FIR to prevent such rewrite in the abstract result pass, and update the target-rewrite pass to deal with the struct return ABI. So far, the target specific part of the target-rewrite is only implemented for X86-64 according to the "System V Application Binary Interface AMD64 v1", the other targets will hit a TODO, just like for BIND(C), VALUE derived type arguments. This intends to deal with #102113. This is a re-land of #111678 with an extra commit to keep rewriting `type(c_ptr)` results to `!fir.ref<none>` in the abstract result pass regardless of the ABIs.
2024-10-10Revert "[flang] correctly deal with bind(c) derived type result ABI" (#111858)jeanPerier
Reverts llvm/llvm-project#111678 Causes ARM failure in test suite. TYPE(C_PTR) result should not regress even if struct ABI no implemented for the target. https://lab.llvm.org/buildbot/#/builders/143/builds/2731 I need to revisit this.
2024-10-10[flang] correctly deal with bind(c) derived type result ABI (#111678)jeanPerier
Derived type results of BIND(C) function should be returned according the the C ABI for returning the related C struct type. This currently did not happen since the abstract-result pass was forcing the Fortran ABI for all derived type results. use the bind_c attribute that was added on call/func/dispatch in FIR to prevent such rewrite in the abstract result pass, and update the target-rewrite pass to deal with the struct return ABI. So far, the target specific part of the target-rewrite is only implemented for X86-64 according to the "System V Application Binary Interface AMD64 v1", the other targets will hit a TODO, just like for BIND(C), VALUE derived type arguments. This intends to deal with https://github.com/llvm/llvm-project/issues/102113.
2024-10-04[flang][FIR] remove fir.complex type and its fir.real element type (#111025)jeanPerier
Final patch of https://discourse.llvm.org/t/rfc-flang-replace-usages-of-fir-complex-by-mlir-complex-type/82292 Since fir.real was only still used as fir.complex element type, this patch removes it at the same time.
2024-10-03[flang] replace fir.complex usages with mlir complex (#110850)jeanPerier
Core patch of https://discourse.llvm.org/t/rfc-flang-replace-usages-of-fir-complex-by-mlir-complex-type/82292. After that, the last step is to remove fir.complex from FIR types.
2024-08-27[flang][debug] Support derived types. (#99476)Abid Qadeer
This PR adds initial debug support for derived type. It handles `RecordType` and generates appropriate `DICompositeTypeAttr`. The `TypeInfoOp` is used to get information about the parent and location of the derived type. We use `getTypeSizeAndAlignment` to get the size and alignment of the components of the derived types. This function needed a few changes to be suitable to be used here: 1. The `getTypeSizeAndAlignment` errored out on unsupported type which would not work with incremental way we are building debug support. A new variant of this function has been that returns an std::optional. The original function has been renamed to `getTypeSizeAndAlignmentOrCrash` as it will call `TODO()` for unsupported types. 2. The Character type was returning size of just element and not the whole string which has been fixed. The testcase checks for offsets of the components which had to be hardcoded in the test. So the testcase is currently enabled on x86_64. With this PR in place, this is how the debugging of derived types look like: ``` type :: t_date integer :: year, month, day end type type :: t_address integer :: house_number end type type, extends(t_address) :: t_person character(len=20) name end type type, extends(t_person) :: t_employee type(t_date) :: hired_date real :: monthly_salary end type type(t_employee) :: employee (gdb) p employee $1 = ( t_person = ( t_address = ( house_number = 1 ), name = 'John', ' ' <repeats 16 times> ), hired_date = ( year = 2020, month = 1, day = 20 ), monthly_salary = 3.1400001 ) ```
2024-07-16Add basic -mtune support (#98517)Alexis Perry-Holby
Initial implementation for the -mtune flag in Flang. This PR is a clean version of PR #96688, which is a re-land of PR #95043
2024-06-25Revert "[flang] Add basic -mtune support" (#96678)Tarun Prabhu
Reverts llvm/llvm-project#95043
2024-06-25[flang] Add basic -mtune support (#95043)Alexis Perry-Holby
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-04-28Reapply "[mlir] Mark `isa/dyn_cast/cast/...` member functions depreca… ↵Christian Sigg
(#90406) …ted. (#89998)" (#90250) This partially reverts commit 7aedd7dc754c74a49fe84ed2640e269c25414087. This change removes calls to the deprecated member functions. It does not mark the functions deprecated yet and does not disable the deprecation warning in TypeSwitch. This seems to cause problems with MSVC.
2024-04-26Revert "[mlir] Mark `isa/dyn_cast/cast/...` member functions deprecated. ↵dyung
(#89998)" (#90250) This reverts commit 950b7ce0b88318f9099e9a7c9817d224ebdc6337. This change is causing build failures on a bot https://lab.llvm.org/buildbot/#/builders/216/builds/38157
2024-04-26[mlir] Mark `isa/dyn_cast/cast/...` member functions deprecated. (#89998)Christian Sigg
See https://mlir.llvm.org/deprecation and https://discourse.llvm.org/t/preferred-casting-style-going-forward.
2024-03-08[Flang][AArch64] Add support for complex16 params/returns (#84217)Kiran Chandramohan
Fixes #84088
2024-02-20[flang] Resolve "possible performance problem" issue spam (#79769)Peter Klausler
Four "issues" on GitHub report possible performance problems, likely detected by static analysis. None of them would ever make a measureable difference in compilation time, but I'm resolving them to clean up the open issues list. Fixes https://github.com/llvm/llvm-project/issues/79703, .../79705, .../79706, & .../79707.
2024-01-30[Flang][Lower] Attach target_cpu and target_features attributes to MLIR ↵Sergio Afonso
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-29[flang] Use DataLayout for computing type size in LoopVersioning. (#79778)Slava Zakharin
The existing type size computation in LoopVersioning does not work for REAL*10, because the compute element size is 10 bytes, which violates the power-of-two assertion. We'd better use the DataLayout for computing the storage size of each element of an array of the given type.
2024-01-12[flang] finish BIND(C) VALUE derived type passing ABI on X86-64 (#77742)jeanPerier
Derived type passed with VALUE in BIND(C) context must be passed like C struct and LLVM is not implementing the ABI for this (it is up to the frontends like clang). Previous patch #75802 implemented the simple cases where the derived type have one field, this patch implements the general case. Note that the generated LLVM IR is compliant from a X86-64 C ABI point of view and compatible with clang generated assembly, but that it is not guaranteed to match the LLVM IR signatures generated by clang for the C equivalent functions because several LLVM IR signatures may lead to the same X86-64 signature.
2023-12-19[flang] Pass one element struct by register on X86-64 (#75802)jeanPerier
Implement the C struct passing ABI on X86-64 for the trivial case where the structs have one element. This is required to cover some cases of BIND(C) derived type pass with the VALUE attribute.
2023-12-12[flang] Add struct passing target rewrite hooks and partial X86-64 impl (#74829)jeanPerier
In the context of C/Fortran interoperability (BIND(C)), it is possible to give the VALUE attribute to a BIND(C) derived type dummy, which according to Fortran 2018 18.3.6 - 2. (4) implies that it must be passed like the equivalent C structure value. The way C structure value are passed is ABI dependent. LLVM does not implement the C struct ABI passing for LLVM aggregate type arguments. It is up to the front-end, like clang is doing, to split the struct into registers or pass the struct on the stack (llvm "byval") as required by the target ABI. So the logic for C struct passing sits in clang. Using it from flang requires setting up a lot of clang context and to bridge FIR/MLIR representation to clang AST representation for function signatures (in both directions). It is a non trivial task. See https://stackoverflow.com/questions/39438033/passing-structs-by-value-in-llvm-ir/75002581#75002581. Since BIND(C) struct are rather limited as opposed to generic C struct (e.g. no bit fields). It is easier to provide a limited implementation of it for the case that matter to Fortran. This patch: - Updates the generic target rewrite pass to keep track of both the new argument type and attributes. The motivation for this is to be able to tell if a previously marshalled argument is passed in memory (it is a C pointer), or if it is being passed on the stack (has the byval llvm attributes). - Adds an entry point in the target specific codegen to marshal struct arguments, and use it in the generic target rewrite pass. - Implements limited support for the X86-64 case. So far, the support allows telling if a struct must be passed in register or on the stack, and to deal with the stack case. The register case is left TODO in this patch. The X86-64 ABI implemented is the System V ABI for AMD64 version 1.0
2023-12-04[flang] Implement COMPLEX(10) passing and return ABI for X86-64 linux (#74094)jeanPerier
COMPLEX(10) passing by value and returning follows C complex passing/returning ABI. Cover the COMPLEX(10) case (X87 / __Complex long double on X86-64). Implements System V ABI for AMD64 version 1.0. The LLVM signatures match the one generated by clang for the __Complex long double case. Note that a FIXME is added for the COMPLEX(8) case that is incorrect in a corner case. This will be fixed when dealing with passing derived type by value in BIND(C) context.
2023-11-29[flang] Cleanup of NYI messages (#73740)Pete Steinfeld
This update makes the user visible messages relating to features that are not yet implemented be more consistent. I also cleaned up some of the code. For NYI messages that refer to intrinsics, I made sure the the message begins with "not yet implemented: intrinsic:" to make them easier to recognize. I created some utility functions for NYI reporting that I put into .../include/Optimizer/Support/Utils.h. These mainly convert MLIR types to their Fortran equivalents. I converted the NYI code to use the newly created utility functions.
2023-11-16[flang][NVPTX] Add initial support to the NVPTX target (#71992)Fabian Mora
This patch adds initial support to the NVPTX target, enabling `flang` to produce OpenMP offload code for NVPTX targets.
2023-04-17[flang] Complex numbers in function arguments on WindowsMarkus Mützel
Function arguments or return values that are complex floating point values aren't correctly lowered for Windows x86 32-bit and 64-bit targets. See: https://github.com/llvm/llvm-project/issues/61976 Add targets that are specific for these platforms and OS. With thanks to @mstorsjo for pointing out the fix. Reviewed By: vzakhari Differential Revision: https://reviews.llvm.org/D147768
2023-04-10[flang][NFC] Move TypeConverter.h header file to include dirValentin Clement
After the extraction of the TypeConverter, move the header files to the include dir so the shared library build is fine. Reviewed By: PeteSteinfeld Differential Revision: https://reviews.llvm.org/D147979
2023-03-09Break circular dependency between FIR dialect and utilitiesRenaud-K
2023-02-08[flang] Add LoongArch64 support to lib/Optimizer/CodeGen/Target.cppWeining Lu
Add LoongArch64 linux target specifics to Target.cpp which is similar to RISCV-64 in D136547. For LoongArch, a complex floating-point number, or a structure containing just one complex floating-point number, is passed as though it were a structure containing two floating-point reals. Reviewed By: vzakhari Differential Revision: https://reviews.llvm.org/D143131
2023-02-07[flang] Add AMDGPU target in flangJan Sjodin
This is the first patch of several that will enable generating code for AMD GPUs. It adds the AMDGPU target so it can be used with the --target and -mcpu options. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D143102
2023-01-30[flang] Use proper attributes for runtime calls with 'i1' arguments/returns.Slava Zakharin
Clang uses signext/zeroext attributes for integer arguments shorter than the default 'int' type on a target. So Flang has to match this for functions from Fortran runtime and also for BIND(C) routines. This patch implements ABI adjustments only for Fortran runtime calls. BIND(C) part will be done separately. This resolves https://github.com/llvm/llvm-project/issues/58579 Differential Revision: https://reviews.llvm.org/D142677
2022-12-30[Flang] Add ppc64 support to Optimizer/CodeGen/Target.cpp for AIX 64 bitMark Danial
Adding support for ppc64 (big endian) in order to support flang on 64 bit AIX Reviewed By: clementval, kiranchandramohan Differential Revision: https://reviews.llvm.org/D138390
2022-12-01Revert "[flang] Use proper attributes for runtime calls with 'i1' ↵Slava Zakharin
arguments/returns." This reverts commit d5b0de35bdd9a3f4d4a093e7938b06add34678eb.
2022-11-30[flang] Use proper attributes for runtime calls with 'i1' arguments/returns.Slava Zakharin
Clang uses signext/zeroext attributes for integer arguments shorter than the default 'int' type on a target. So Flang has to match this for functions from Fortran runtime and also for BIND(C) routines. This patch implements ABI adjustments only for Fortran runtime calls. BIND(C) part will be done separately. This resolves https://github.com/llvm/llvm-project/issues/58579 Differential Revision: https://reviews.llvm.org/D137050
2022-11-29[flang] Add RISCV-64 support to Optimizer/CodeGen/Target.cppQihan Cai
As an attempt to fix errors in Flang regression tests on RISCV64 platform, RISCV64 target was added, and subsequent tests were provided. Reviewed By: vzakhari Differential Revision: https://reviews.llvm.org/D136547
2022-11-18Revert "[flang] Use proper attributes for runtime calls with 'i1' ↵Slava Zakharin
arguments/returns." Buildbot might be failing because of this: https://lab.llvm.org/buildbot/#/builders/65/builds/7283 This reverts commit 396ead93e3cead59727947afdea1fc2b49f0fc34.
2022-11-18[flang] Use proper attributes for runtime calls with 'i1' arguments/returns.Slava Zakharin
Clang uses signext/zeroext attributes for integer arguments shorter than the default 'int' type on a target. So Flang has to match this for functions from Fortran runtime and also for BIND(C) routines. This patch implements ABI adjustments only for Fortran runtime calls. BIND(C) part will be done separately. This resolves https://github.com/llvm/llvm-project/issues/58579 Differential Revision: https://reviews.llvm.org/D137050
2022-10-24[flang] Allow all OSes in fir::CodeGenSpecifics::getFangrui Song
This allows all ELF operating systems to use target specifics tuned for Linux, since they use mostly the same ABIs. If some triples are to excluded, it's better done at the driver layer. Reviewed By: emaste Differential Revision: https://reviews.llvm.org/D135100
2022-10-03[flang] Add Sparc support to Optimizer/CodeGen/Target.cppRainer Orth
As described in Issue #57642, `flang` currently lacks SPARC support in `Optimizer/CodeGen/Target.cpp`, which causes a considerable number of tests to `FAIL` with error: flang/lib/Optimizer/CodeGen/Target.cpp:310: not yet implemented: target not implemented This patch fixes this by following GCC`s documentation of the ABI described in the Issue. Tested on `sparcv9-sun-solaris2.11`. Differential Revision: https://reviews.llvm.org/D133561
2022-08-17[flang] Add Solaris/x86 support to Optimizer/CodeGen/Target.cppRainer Orth
When testing LLVM 15.0.0 rc1 on Solaris, I found that 50+ flang tests `FAIL`ed with error: /vol/llvm/src/llvm-project/local/flang/lib/Optimizer/CodeGen/Target.cpp:310: not yet implemented: target not implemented This patch fixes that for Solaris/x86, where the fix is trivial (just handling it like the other x86 OSes). Tested on `amd64-pc-solaris2.11`; only a single failure remains now. Differential Revision: https://reviews.llvm.org/D131054
2022-06-22[flang] Add FIR tests missing from fir-devValentin Clement
This patch is part of the upstreaming effort from fir-dev branch. Reviewed By: jeanPerier, PeteSteinfeld Differential Revision: https://reviews.llvm.org/D128331 Co-authored-by: Jean Perier <jperier@nvidia.com> Co-authored-by: Eric Schweitz <eschweitz@nvidia.com> Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>