aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend
AgeCommit message (Collapse)AuthorFilesLines
44 hours[Flang] Add -ffast-real-mod and direct code for MOD on REAL types (#160660)Michael Klemm2-0/+11
This patch adds direct code-gen support for a faster MOD intrinsic for REAL types. Flang has maintained and keeps maintaining a high-precision implementation of the MOD intrinsic as part of the Fortran runtime. With the -ffast-real-mod flag, users can opt to avoid calling into the Fortran runtime, but instead trigger code-gen that produces faster code by avoiding the runtime call, at the expense of potentially risking bit cancelation by having the compiler use the MOD formula a specified by ISO Fortran.
8 days[flang][Driver] Support -gsplit-dwarf. (#160540)Abid Qadeer2-1/+23
This flags enables the compiler to generate most of the debug information in a separate file which can be useful for executable size and link times. Clang already supports this flag. I have tried to follow the logic of the clang implementation where possible. Some functions were moved where they could be used by both clang and flang. The `addOtherOptions` was renamed to `addDebugOptions` to better reflect its purpose. Clang also set the `splitDebugFilename` field of the `DICompileUnit` in the IR when this option is present. That part is currently missing from this patch and will come in a follow-up PR.
8 days[llvm] Add `vfs::FileSystem` to `PassBuilder` (#160188)Jan Svoboda1-4/+2
Some LLVM passes need access to the filesystem to read configuration files and similar. In some places, this is achieved by grabbing the VFS from `PGOOptions`, but some passes don't have access to these and resort to just calling `vfs::getRealFileSystem()`. This PR allows setting the VFS directly on `PassBuilder` that's able to pass it down to all passes that need it.
12 days[Remarks] Restructure bitstream remarks to be fully standalone (#156715)Tobias Stadler1-3/+2
Currently there are two serialization modes for bitstream Remarks: standalone and separate. The separate mode splits remark metadata (e.g. the string table) from actual remark data. The metadata is written into the object file by the AsmPrinter, while the remark data is stored in a separate remarks file. This means we can't use bitstream remarks with tools like opt that don't generate an object file. Also, it is confusing to post-process bitstream remarks files, because only the standalone files can be read by llvm-remarkutil. We always need to use dsymutil to convert the separate files to standalone files, which only works for MachO. It is not possible for clang/opt to directly emit bitstream remark files in standalone mode, because the string table can only be serialized after all remarks were emitted. Therefore, this change completely removes the separate serialization mode. Instead, the remark string table is now always written to the end of the remarks file. This requires us to tell the serializer when to finalize remark serialization. This automatically happens when the serializer goes out of scope. However, often the remark file goes out of scope before the serializer is destroyed. To diagnose this, I have added an assert to alert users that they need to explicitly call finalizeLLVMOptimizationRemarks. This change paves the way for further improvements to the remark infrastructure, including more tooling (e.g. #159784), size optimizations for bitstream remarks, and more. Pull Request: https://github.com/llvm/llvm-project/pull/156715
2025-09-19[Flang] Add new ConvertComplexPow pass for Flang (#158642)Akash Banerjee1-0/+2
This PR introduces a new `ConvertComplexPow` pass for Flang that handles complex power operations. The change forces lowering to complex.pow operations when `--math-runtime=precise` is not used, then uses the `ConvertComplexPow` pass to convert these operations back to library calls. - Adds a new `ConvertComplexPow` pass that converts complex.pow ops to appropriate runtime library calls - Updates complex power lowering to use `complex.pow` operations by default instead of direct library calls #158722 Adds a new `complex.powi` op enabling algebraic optimisations.
2025-09-18[flang][Driver] Enables lto-partitions and fat-lto-object. (#158125)Anchu Rajendran S2-13/+37
2025-09-17[flang] Lowering support for -gdwarf-N flag. (#159137)Abid Qadeer1-2/+1
This PR builds on the https://github.com/llvm/llvm-project/pull/158314 and adds the lowering support for `-gdwarf-N` flag. The changes to pass the information to `AddDebugInfo` pass are mostly mechanical. The `AddDebugInfo` pass adds `ModuleFlagsOp` in the module which gets translated to correct llvm metadata during mlir->llvmir translation. There is minor correction where the version is set to 0 in case no -debug-version flag is provided. Previously it was set to 2 in this case due to misreading of clang code.
2025-09-16Reapply "Introduce -fexperimental-loop-fusion to clang and flang (#158844)Madhur Amilkanthwar2-0/+4
This PR is a reapplication of https://github.com/llvm/llvm-project/pull/142686
2025-09-16Revert "Introduce -fexperimental-loop-fuse to clang and flang (#142686)" ↵Vitaly Buka2-4/+0
(#158764) This reverts commit 895cda70a95529fd22aac05eee7c34f7624996af. And fix attempt: 06f671e57a574ba1c5127038eff8e8773273790e. Performance regressions and broken sanitizers, see #142686.
2025-09-15[flang][driver] Support -gdwarf-N option. (#158314)Abid Qadeer1-0/+4
This PR adds the support for -gdwarf-N option where allows user to choose the version of the dwarf. Currently N can be 2, 3, 4, or 5. This is only the driver part of the change. Later PRs will propogate it to the IR. Fixes https://github.com/llvm/llvm-project/issues/112910.
2025-09-15Introduce -fexperimental-loop-fuse to clang and flang (#142686)Sebastian Pop2-0/+4
This patch adds the flag -fexperimental-loop-fuse to the clang and flang drivers. This is primarily useful for experiments as we envision to enable the pass one day. The options are based on the same principles and reason on which we have `floop-interchange`. --------- Co-authored-by: Madhur Amilkanthwar <madhura@nvidia.com>
2025-09-02[flang] Fix build after #150124Jan Svoboda1-1/+2
2025-08-28[flang][cuda] Define _CUDA only when preprocessor is enabled (#155913)Valentin Clement (バレンタイン クレメン)1-0/+5
From the CUDA Fortran programming guide: > If CUDA Fortran is enabled in compilation, either by specifying -⁠cuda on the command line, and pre-processing is enabled by either the -⁠Mpreprocess compiler option or by using capital letters in the filename extension (.CUF, .F90, etc.) then the _CUDA macro is defined. Move the definition of `_CUDA` to the compiler invocation.
2025-08-27[AMDGPU] More radical feature initialization refactoring (#155222)Stanislav Mekhanoshin1-9/+6
Factoring in flang, just have a single fillAMDGPUFeatureMap function doing it all as an external interface and returing an error.
2025-08-18[Frontend][OpenMP] Add 6.1 as a valid OpenMP version (#153628)Krzysztof Parzyszek1-1/+16
Co-authored-by: Michael Klemm <michael.klemm@amd.com>
2025-08-15[flang] Adding support of -fcoarray flang and init PRIF (#151675)Jean-Didier PAILLEUX1-0/+11
In relation to the approval and merge of the [PRIF](https://github.com/llvm/llvm-project/pull/76088) specification about multi-image features in Flang, here is a first PR to add support for the `-fcoarray` compilation flag and the initialization of the PRIF environment. Other PRs will follow for adding support of lowering to PRIF.
2025-08-14[Flang][Driver] Predefine pic/pie macros based on configured level (#153449)Ian McInerney1-0/+14
Predefine the `__pic__/__pie__/__PIC__/__PIE__` macros based on the configured relocation level. This logic mirrors that of the clang driver, where `__pic__/__PIC__` are defined for both PIC and PIE modes, but `__pie__/__PIE__` are only defined for PIE mode. Fixes https://github.com/llvm/llvm-project/issues/135275
2025-08-14[flang][OpenMP] Add -f[no]-openmp-simd (#150269)Kajetan Puchalski2-11/+25
Both clang and gfortran support the -fopenmp-simd flag, which enables OpenMP support only for simd constructs, while disabling the rest of OpenMP. Implement the appropriate parse tree rewriting to remove non-SIMD OpenMP constructs at the parsing stage. Add a new SimdOnly flang OpenMP IR pass which rewrites generated OpenMP FIR to handle untangling composite simd constructs, and clean up OpenMP operations leftover after the parse tree rewriting stage. With this approach, the two parts of the logic required to make the flag work can be self-contained within the parse tree rewriter and the MLIR pass, respectively. It does not need to be implemented within the core lowering logic itself. The flag is expected to have no effect if -fopenmp is passed explicitly, and is only expected to remove OpenMP constructs, not things like OpenMP library functions calls. This matches the behaviour of other compilers. --------- Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-07-31NFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151545)James Y Knight1-4/+2
Handles clang::DiagnosticsEngine and clang::DiagnosticIDs. For DiagnosticIDs, this mostly migrates from `new DiagnosticIDs` to convenience method `DiagnosticIDs::create()`. Part of cleanup https://github.com/llvm/llvm-project/issues/151026
2025-07-28[flang][MLIR][OpenMP][llvm]Atomic Control Support (#150860)Anchu Rajendran S1-0/+10
2025-07-25[mlir][LLVM] Remove `llvm` deps from the LLVM dialect (#150692)Fabian Mora1-0/+1
This patch removes spurious includes of `llvm/IR` files, and unnecessary link components in the LLVM dialect. The only major dependencies still coming from LLVM are `llvm::DataLayout`, which is used by `verifyDataLayoutString` and some `dwarf` symbols in some attributes. Both of them should likely be removed in the future. Finally, I also removed one constructor from `LLVM::AssumeOp` that used [OperandBundleDefT](https://llvm.org/doxygen/classllvm_1_1OperandBundleDefT.html) without good reason and introduced a header unnecessarily.
2025-07-24[mlir][NFC] update `flang/lib` create APIs (12/n) (#149914)Maksim Levental1-2/+3
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-24Revert "[flang][flang-driver][mlir][OpenMP] atomic control support" (#150504)Kiran Chandramohan1-10/+0
Reverts llvm/llvm-project#143441 Reverting due to CI failure https://lab.llvm.org/buildbot/#/builders/53/builds/18055.
2025-07-24[flang][flang-driver][mlir][OpenMP] atomic control support (#143441)Anchu Rajendran S1-0/+10
Atomic Control Options are used to specify architectural characteristics to help lowering of atomic operations. The options used are: `-f[no-]atomic-remote-memory`, `-f[no-]atomic-fine-grained-memory`, `-f[no-]atomic-ignore-denormal-mode`. Legacy option `-m[no-]unsafe-fp-atomics` is aliased to `-f[no-]ignore-denormal-mode`. More details can be found in https://github.com/llvm/llvm-project/pull/102569. This PR implements the frontend support for these options with OpenMP atomic in flang. Backend changes are available in the draft PR: https://github.com/llvm/llvm-project/pull/143769 which will be raised after this merged.
2025-07-16[flang][driver] -Werror promotes warnings to error and interopts with ↵Andre Kuhlenschmidt1-5/+4
-Wfatal-errors (#148748) This PR changes how `-Werror` promotes warnings to errors so that it interoperates with `-Wfatal-error`. It maintains the property that warnings and other messages promoted to errors are displayed as there original message.
2025-07-09[flang][driver] add -Wfatal-errors (#147614)Andre Kuhlenschmidt2-7/+13
Adds the flag `-Wfatal-errors` which truncates the error messages at 1 error.
2025-07-09[flang] Add -fcomplex-arithmetic= option and select complex division ↵Shunsuke Watanabe2-0/+23
algorithm (#146641) This patch adds an option to select the method for computing complex number division. It uses `LoweringOptions` to determine whether to lower complex division to a runtime function call or to MLIR's `complex.div`, and `CodeGenOptions` to select the computation algorithm for `complex.div`. The available option values and their corresponding algorithms are as follows: - `full`: Lower to a runtime function call. (Default behavior) - `improved`: Lower to `complex.div` and expand to Smith's algorithm. - `basic`: Lower to `complex.div` and expand to the algebraic algorithm. See also the discussion in the following discourse post: https://discourse.llvm.org/t/optimization-of-complex-number-division/83468 --------- Co-authored-by: Tarun Prabhu <tarunprabhu@gmail.com>
2025-07-07[flang] Correctly handle -mframe-pointer=reserved (#146937)Daniel Paoliello1-1/+2
Fixes `#146802` #146582 started using the `Reserved` Frame Pointer kind for Arm64 Windows, but this revealed a bug in Flang where it copied the `-mframe-pointer=reserved` flag from Clang, but didn't correctly handle it in its own command line parser and subsequent compilation pipeline. This change adds support for `-mframe-pointer=reserved` and adds a test to make sure that functions are correctly marked when the flag is set.
2025-07-04[Clang] Introduce `--offload-targets` for `-fopenmp-targets` (#146594)Joseph Huber1-1/+1
Summary: This patch is mostly an NFC that renames the existing `-fopenmp-targets` into `--offload-targets`. Doing this early to simplify a follow-up patch that will hopefully allow this syntax to be used more generically over the existing `--offload` syntax (which I think is mostly unmaintained now.). Following in the well-trodden path of trying to pull language specific offload options into generic ones, but right now this is still just OpenMP specific.
2025-06-30[flang][CLI] Have the CLI hint the flag to disable a warning (#144767)Andre Kuhlenschmidt1-3/+10
Adds a hint to the warning message to disable a warning and updates the tests to expect this. Also fixes a bug in the storage of canonical spelling of error flags so that they are not used after free.
2025-06-30[flang] add option to generate runtime type info as external (#146071)jeanPerier1-0/+2
Reland #145901 with a fix for shared library builds. So far flang generates runtime derived type info global definitions (as opposed to declarations) for all the types used in the current compilation unit even when the derived types are defined in other compilation units. It is using linkonce_odr to achieve derived type descriptor address "uniqueness" aspect needed to match two derived type inside the runtime. This comes at a big compile time cost because of all the extra globals and their definitions in apps with many and complex derived types. This patch adds and experimental option to only generate the rtti definition for the types defined in the current compilation unit and to only generate external declaration for the derived type descriptor object of types defined elsewhere. Note that objects compiled with this option are not compatible with object files compiled without because files compiled without it may drop the rtti for type they defined if it is not used in the compilation unit because of the linkonce_odr aspect. I am adding the option so that we can better measure the extra cost of the current approach on apps and allow speeding up some compilation where devirtualization does not matter (and the build config links to all module file object anyway).
2025-06-26[flang][OpenMP] Remove experimental warning (#144915)Tom Eccles1-2/+6
RFC: https://discourse.llvm.org/t/rfc-removing-the-openmp-experimental-warning-for-llvm-21/86455 Fixes: #110008
2025-06-25[flang][OpenMP] Verify that N in -fopenmp-version=N is valid (#145725)Krzysztof Parzyszek1-4/+38
For historical versions that are unsupported, emit a warning and assume the currently default version. For values of N that are not integers or that don't correspond to any OpenMP version (old or newer), emit an error.
2025-06-24[llvm] fix extern cl::opt definitions for DLL export (#145374)Andrew Rogers1-4/+0
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch ensures a few `cl::opt` declarations are properly annotated with `LLVM_ABI`. The annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). ## Overview - Remove local `extern` declarations of `llvm::PrintPipelinePasses` because it is already correctly declared with an `LLVM_ABI` annotation in `llvm\Passes\PassBuilder.h`. Leaving these declarations results in a gcc compile warning unless they are also annotated with `LLVM_ABI`. - Similarly, remove local `extern` declarations of `ProfileSummaryCutoffHot` and `UseContextLessSummary` from `llvm/tools/llvm-profgen/ProfileGenerator.cpp` since they are declared with `LLVM_ABI` in `llvm\ProfileData\ProfileCommon.h`. - Explicitly annotate the extern declaration of `ProfileCorrelate` in `clang/lib/CodeGen/BackendUtil.cpp` since it is not declared in a header. The definition of `ProfileCorrelate` in `llvm\lib\Transforms\Instrumentation\InstrProfiling.cpp` is already annotated with `LLVM_ABI`. ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
2025-06-18[flang][driver] add ability to look up feature flags without setting them ↵Andre Kuhlenschmidt1-1/+1
(#144559) This just adds some convenience methods to feature control and rewrites old code in terms of those methods. Also cleans up some names that I just realize were overloads of another method.
2025-06-13Fix and reapply IR PGO support for Flang (#142892)FYK2-0/+36
This PR resubmits the changes from #136098, which was previously reverted due to a build failure during the linking stage: ``` undefined reference to `llvm::DebugInfoCorrelate' undefined reference to `llvm::ProfileCorrelate' ``` The root cause was that `llvm/lib/Frontend/Driver/CodeGenOptions.cpp` references symbols from the `Instrumentation` component, but the `LINK_COMPONENTS` in the `llvm/lib/Frontend/CMakeLists.txt` for `LLVMFrontendDriver` did not include it. As a result, linking failed in configurations where these components were not transitively linked. ### Fix: This updated patch explicitly adds `Instrumentation` to `LINK_COMPONENTS` in the relevant `llvm/lib/Frontend/CMakeLists.txt` file to ensure the required symbols are properly resolved. --------- Co-authored-by: ict-ql <168183727+ict-ql@users.noreply.github.com> Co-authored-by: Chyaka <52224511+liliumshade@users.noreply.github.com> Co-authored-by: Tarun Prabhu <tarunprabhu@gmail.com>
2025-06-10[flang] Add support for -mrecip[=<list>] (#143418)Cameron McInally2-1/+4
This patch adds support for the -mrecip command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "reciprocal-estimates" function attribute. Also move the ParseMRecip(...) function to CommonArgs, so that Flang is able to make use of it as well. --------- Co-authored-by: Cameron McInally <cmcinally@nvidia.com>
2025-06-10[flang][cli] Add diagnostic flags to the CLI (#142022)Andre Kuhlenschmidt1-34/+30
This change allows the flang CLI to accept `-W[no-]<feature>` flags matching the clang syntax and enable and disable usage and language feature warnings.
2025-06-06[Driver] Move CommonArgs to a location visible by the Frontend Drivers (#142800)Cameron McInally1-13/+3
This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --------- Co-authored-by: Cameron McInally <cmcinally@nvidia.com> Co-authored-by: Shafik Yaghmour <shafik.yaghmour@intel.com>
2025-06-04[flang] Add aarch64 processor defines (#142606)David Truby1-0/+4
This patch adds aarch64 specific processor defines when targeting aarch64, similar to the ones for ppc64 and x86_64
2025-05-30Revert "Add IR Profile-Guided Optimization (IR PGO) support to the Flang ↵Tarun Prabhu2-36/+0
compiler" (#142159) Reverts llvm/llvm-project#136098
2025-05-30Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler ↵FYK2-0/+36
(#136098) This patch implements IR-based Profile-Guided Optimization support in Flang through the following flags: - `-fprofile-generate` for instrumentation-based profile generation - `-fprofile-use=<dir>/file` for profile-guided optimization Resolves #74216 (implements IR PGO support phase) **Key changes:** - Frontend flag handling aligned with Clang/GCC semantics - Instrumentation hooks into LLVM PGO infrastructure - LIT tests verifying: - Instrumentation metadata generation - Profile loading from specified path - Branch weight attribution (IR checks) **Tests:** - Added gcc-flag-compatibility.f90 test module verifying: - Flag parsing boundary conditions - IR-level profile annotation consistency - Profile input path normalization rules - SPEC2006 benchmark results will be shared in comments For details on LLVM's PGO framework, refer to [Clang PGO Documentation](https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization). This implementation was developed by [XSCC Compiler Team](https://github.com/orgs/OpenXiangShan/teams/xscc). --------- Co-authored-by: ict-ql <168183727+ict-ql@users.noreply.github.com> Co-authored-by: Tom Eccles <t@freedommail.info>
2025-05-30[flang] Add support for -mprefer-vector-width=<value> (#142073)Cameron McInally2-0/+16
This patch adds support for the -mprefer-vector-width= command line option. The parsing of this options is equivalent to Clang's and it is implemented by setting the "prefer-vector-width" function attribute. Co-authored-by: Cameron McInally <cmcinally@nvidia.com>
2025-05-22[flang] Fix build after 9e306ad4 (#141134)Jan Svoboda2-7/+6
2025-05-21[flang] add -floop-interchange and enable it with opt levels (#140182)Sebastian Pop2-0/+4
Enable the use of -floop-interchange from the flang driver. Enable in flang LLVM's loop interchange at levels -O2, -O3, -Ofast, and -Os.
2025-05-20[flang][veclib] Adding AMDLIBM target to fveclib (#140533)shivaramaarao1-0/+1
This commit adds AMDLIBM support to fveclib targets. The support is already present in clang and this patch extends it to flang.
2025-05-09[flang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139131)Krzysztof Parzyszek1-1/+2
The OpenMP version is stored in LangOptions in SemanticsContext. Use the fallback version where SemanticsContext is unavailable (mostly in case of debug dumps). RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507 Reland with a fix for build break in f18-parse-demo.
2025-05-09Revert "[flang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139131)"Krzysztof Parzyszek1-2/+1
This reverts commit 41aa67488c3ca33334ec79fb5216145c3644277c. Breaks build: https://lab.llvm.org/buildbot/#/builders/140/builds/22826
2025-05-09[flang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139131)Krzysztof Parzyszek1-1/+2
The OpenMP version is stored in LangOptions in SemanticsContext. Use the fallback version where SemanticsContext is unavailable (mostly in case of debug dumps). RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
2025-05-09[flang][driver] do not crash when fc1 process multiple files (#138875)jeanPerier3-3/+8
This is a fix for the issue https://github.com/llvm/llvm-project/issues/137126 that turned out to be a driver issue. FrontendActions has a loop to process multiple input files and `flang -fc1` accept multiple files, but the semantic, lowering, and llvm codegen actions were not re-entrant, and crash or weird behaviors occurred when processing multiple files with `-fc1`. This patch makes the actions reentrant by cleaning-up the contexts/modules if needed on entry.