summaryrefslogtreecommitdiff
path: root/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
AgeCommit message (Collapse)Author
2025-11-21[OpenMP][OMPIRBuilder] Use runtime CC for runtime calls (#168608)Nick Sarnie
Some targets have a specific calling convention that should be used for generated calls to runtime functions. Pass that down and use it. Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
2025-11-19[mlir][LLVM] Resync memory effect attribute with LLVM IR (#168568)darkbuck
- Add missing locations, namely 'ErrnoMem', 'TargetMem0', and 'TargetMem1'.
2025-10-27[MLIR] Apply clang-tidy fixes for llvm-else-after-return in ↵Mehdi Amini
ModuleTranslation.cpp (NFC)
2025-10-21[mlir][LLVMIR] Remove "unsafe-fp-math" attribute support (#162782)paperchalice
These global flags block furthur improvements for clang, users should always use fast-math flags see also https://discourse.llvm.org/t/rfc-honor-pragmas-with-ffp-contract-fast/80797 Remove them incrementally, this is the mlir part.
2025-10-16[MLIR][LLVM] Add inline_hint as a first class function attribute (#163324)Morris Hafner
We have `noinline` and `alwaysinline` present as first class function attributes. Add `inline_hint` to the list of function attributes as well. Update the module import and translation to support the new attribute. The verifier does not need to be changed as `inlinehint` does not conflict with `noinline` or `alwaysinline`. `inline_hint` is needed to support the `inline` C/C++ keyword in CIR.
2025-10-11[mlir] Use llvm accumulate wrappers. NFCI. (#162957)Jakub Kuderski
Use wrappers around `std::accumulate` to make the code more concise and less bug-prone: https://github.com/llvm/llvm-project/pull/162129. With `std::accumulate`, it's the initial value that determines the accumulator type. `llvm::sum_of` and `llvm::product_of` pick the right accumulator type based on the range element type. Found some funny bugs like a local accumulate helper that calculated a sum with initial value of 1 -- we didn't hit the bug because the code was actually dead...
2025-09-25[MLIR][MLIRToLLVM] Fix zero fp value to array translation (#160713)Alexey Bataev
The translator should not generate zeroinitilizer on fp all zero values, since it may affect signedness of zeroes Fixes #160437
2025-09-16[MLIR][OpenMP] Set default address space for OpenMPIRBuilder (#158689)Nick Sarnie
Extension of https://github.com/llvm/llvm-project/pull/158152 for MLIR. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-09-01[MLIR] Add target_specific_attrs attribute to mlir.global (#154706)Vadim Curcă
Adds a `target_specific_attrs` optional array attribute to `mlir.global`, as well as conversions to and from LLVM attributes on `llvm::GlobalVariable` objects. This is necessary to preserve unknown attributes on global variables when converting to and from the LLVM Dialect. Previously, any attributes on an `llvm::GlobalVariable` not explicitly modeled by `mlir.global` were dropped during conversion.
2025-08-29[mlir][debug] Convert DbgIntrOp to DebugRecords directly. (#154926)Abid Qadeer
Currently the `DbgDeclareOP/DbgValueOP/DbgLabelOp` are first converted to llvm debug intrinsics which are later translated to debug records by a call of `convertToNewDbgValues`. This is not only inefficient but also makes the code that works on intermediate IR unnecessarily complicated. The debug intrinsics are also being phased out. This PR converts these Ops directly to debug records. The conversion is relatively simple but there is a bit of code repetition due to how the APIs in the `DIBuilders` are named. There are few `cast<>` which I would like to do without but could not see a good way around them. Any suggestions welcome here. Also noticed that `DISubprogramAttr` is inherited from `DIScopeAttr` while in llvm, the `DISubprogram` inherits from `DILocalScope`. I am going to fix this separately and then we could use `FusedLocWith<LLVM::DILocalScopeAttr>` and cast to `DILocalScope` will be much safer. As the output remains the same, the existing tests cover this change. I also ran the `GDB` tests with flang and there was no regression. --------- Co-authored-by: Tobias Gysi <tobias.gysi@nextsilicon.com>
2025-08-29[IR][CodeGen] Remove "approx-func-fp-math" attribute (#155740)paperchalice
Remove "approx-func-fp-math" attribute and related command line option, users should always use afn flag in IR. Resolve FIXME in `TargetMachine::resetTargetOptions` partially.
2025-07-31[mlir][llvm] adds an attribute for the module level assembly (#151318)gitoleg
Adds support for the module level assembly in the LLVM IR dialect. --------- Co-authored-by: Tobias Gysi <tobias.gysi@nextsilicon.com>
2025-07-30Reapply "[mlir][llvm] Add intrinsic arg and result attribute support … ↵Tobias Gysi
(#151324) …(… (#151099) This reverts commit 2780b8f22058b35a8e70045858b87a1966df8df3 and relands b7bfbc0c4c7b20d6623a5b0b4a7fea8ae08a62da. Adds the following fixes compared to the original PR (https://github.com/llvm/llvm-project/pull/150783): - A bazel fix - Use `let methods` instead of `list<InterfaceMethod> methods` The missing forward declaration has been added in meantime: https://github.com/llvm/llvm-project/commit/9164d206b33d61c93f5fc4628797485f96d654ca.
2025-07-30Revert "Reland "[mlir][llvm] Add intrinsic arg and result attribute support ↵Mehdi Amini
(…" (#151316) Reverts llvm/llvm-project#151125 Broke the gcc-7 build: include/mlir/Target/LLVMIR/ModuleTranslation.h:318:34: error: no type named 'CallBase' in namespace 'llvm' llvm::CallBase *call, ~~~~~~^
2025-07-30Reland "[mlir][llvm] Add intrinsic arg and result attribute support (… ↵Tobias Gysi
(#151125) …… (#151099) This reverts commit 2780b8f22058b35a8e70045858b87a1966df8df3 to reland 59013d44058ef423a117f95092150e16e16fdb09. In addition to the original commit this one includes: - This includes a bazel fix - Use `let methods` instead of `list<InterfaceMethod> methods` The original commit message was: This patch extends the LLVM dialect's intrinsic infra to support argument and result attributes. Initial support is added for the memory intrinsics llvm.intr.memcpy, llvm.intr.memmove, and llvm.intr.memset. Additionally, an ArgAndResultAttrsOpInterface is factored out of CallOpInterface and CallableOpInterface, enabling operations to have argument and result attributes without requiring them to be a call or a callable operation.
2025-07-29Revert "[mlir][llvm] Add intrinsic arg and result attribute support (… ↵Tobias Gysi
(#151099) …#150783)" This reverts commit 59013d44058ef423a117f95092150e16e16fdb09. The change breaks a flang build bot: https://lab.llvm.org/buildbot/#/builders/207/builds/4441
2025-07-29[mlir][llvm] Add intrinsic arg and result attribute support (#150783)Tobias Gysi
This patch extends the LLVM dialect's intrinsic infra to support argument and result attributes. Initial support is added for the memory intrinsics `llvm.intr.memcpy`, `llvm.intr.memmove`, and `llvm.intr.memset`. Additionally, an ArgAndResultAttrsOpInterface is factored out of CallOpInterface and CallableOpInterface, enabling operations to have argument and result attributes without requiring them to be a call or a callable operation.
2025-07-17[mlir][LLVMIR] Add IFuncOp to LLVM dialect (#147697)Robert Konicar
Add IFunc to LLVM dialect and add support for lifting/exporting LLVMIR IFunc.
2025-07-05[mlir] Remove unused includes (NFC) (#147158)Kazu Hirata
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-06-26[mlir] Use a new constructor of ArrayRef (NFC) (#146009)Kazu Hirata
ArrayRef now has a new constructor that takes a parameter whose type has data() and size(). This patch migrates: ArrayRef<T>(X.data(), X.size() to: ArrayRef<T>(X)
2025-06-26[mlir] Migrate away from std::nullopt (NFC) (#145842)Kazu Hirata
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. This patch replaces {} with std::nullopt.
2025-06-25[Utils][mlir] Fix interaction between CodeExtractor and OpenMPIRBuilder ↵Kajetan Puchalski
(#145051) CodeExtractor can currently erroneously insert an alloca into a different function than it inserts its users into, in cases where code is being extracted out of a function that has already been outlined. Add an assertion that the two blocks being inserted into are actually in the same function. Add a check to findAllocaInsertPoint in OpenMP to LLVMIR translation to prevent the aforementioned scenario from happening. OpenMPIRBuilder relies on a callback mechanism to fix-up a module later on during the finaliser step. In some cases this results in the module being invalid prior to the finalise step running. Remove calls to verifyModule wrapped in LLVM_DEBUG from CodeExtractor, as the presence of those results in the compiler crashing with -mllvm -debug due to premature module verification where it would not crash without -debug. Call ompBuilder->finalize() the end of mlir::translateModuleToLLVMIR, in order to make sure the module has actually been finalized prior to trying to verify it. Resolves https://github.com/llvm/llvm-project/issues/138102. --------- Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-06-24[mlir][NFC] Move LLVM::ModuleTranslation::SaveStack to a shared header (#144897)Tom Eccles
This is so that we can re-use the same code in Flang.
2025-06-17[mlir][flang] Added Weighted[Region]BranchOpInterface's. (#142079)Slava Zakharin
The new interfaces provide getters and setters for the weight information about the branches of BranchOpInterface and RegionBranchOpInterface operations. These interfaces are done the same way as LLVM dialect's BranchWeightOpInterface. The plan is to produce this information in Flang, e.g. mark most probably "cold" code as such and allow LLVM to order basic blocks accordingly. An example of such a code is copy loops generated for arrays repacking - we can mark it as "cold" assuming that the copy will not happen dynamically. If the copy actually happens the overhead of the copy is probably high enough so that we may not care about the little overhead of jumping to the "cold" code and fetching it.
2025-06-12[DebugInfo][RemoveDIs] Delete debug-info-format flag (#143746)Jeremy Morse
This flag was used to let us incrementally introduce debug records into LLVM, however everything is now using records. It serves no purpose now, so delete it.
2025-06-10[flang] Add support for -mrecip[=<list>] (#143418)Cameron McInally
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-09[DebugInfo][RemoveDIs] Rip out the UseNewDbgInfoFormat flag (#143207)Jeremy Morse
Start removing debug intrinsics support -- starting with the flag that controls production of their replacement, debug records. This patch removes the command-line-flag and with it the ability to switch back to intrinsics. The module / function / block level "IsNewDbgInfoFormat" flags get hardcoded to true, I'll to incrementally remove things that depend on those flags.
2025-05-30[flang] Add support for -mprefer-vector-width=<value> (#142073)Cameron McInally
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-28[MLIR][LLVM][DLTI] Handle data layout token 'n32:64' (#141299)Bruno Cardoso Lopes
2025-05-23[MLIR][LLVM][DLTI] Handle data layout token 'Fn32' (#141167)Bruno Cardoso Lopes
2025-05-20[mlir][LLVM] handle ArrayAttr for constant array of structs (#139724)jeanPerier
While LLVM IR dialect has a way to represent arbitrary LLVM constant array of structs via an insert chain, it is in practice very expensive for the compilation time as soon as the array is bigger than a couple hundred elements. This is because generating and later folding such insert chain is really not cheap. This patch allows representing array of struct constants via ArrayAttr in the LLVM dialect.
2025-05-14[MLIR][LLVM] Fix blockaddress mapping to LLVM blocks (#139814)Bruno Cardoso Lopes
After each function is translated, both value and block maps are erased, which makes the current mapping of blockaddresses to llvm blocks broken - the patching happens only after *all* functions are translated. Simplify the overall mapping, update comments, variable names and fix the bug. --------- Co-authored-by: Christian Ulmann <christianulmann@gmail.com>
2025-05-11[mlir] Use StringRef::consume_front (NFC) (#139459)Kazu Hirata
2025-04-30[llvm][mlir] Adding instrument function entry and instrument function exit ↵Anchu Rajendran S
attributes (#137856)
2025-04-21Reapply [MLIR][LLVM] Support for indirectbr (#136378)Bruno Cardoso Lopes
Fix msan issue that caused revert in https://github.com/llvm/llvm-project/pull/135695 ### Original message Now that LLVM dialect has `blockaddress` support, introduce import/translation for `indirectbr` instruction.
2025-04-17[MLIR:LLVM] Add UWTableKind attribute (#135811)Will Froom
Add `UWTableKind` enum and corresponding attribute to `llvm.func` including translation to `llvm::Function` attribute.
2025-04-14Revert "[MLIR][LLVM] Support for indirectbr" (#135695)Bruno Cardoso Lopes
Reverts llvm/llvm-project#135092, broke https://lab.llvm.org/buildbot/#/builders/169/builds/10469
2025-04-14[MLIR][LLVM] Support for indirectbr (#135092)Bruno Cardoso Lopes
Now that LLVM dialect has `blockaddress` support, introduce import/translation for `indirectbr` instruction.
2025-04-07[MLIR][LLVM] Block address support (#134335)Bruno Cardoso Lopes
Add support for import and translate. MLIR does not support using basic block references outside a function (like LLVM does), This PR does not consider changes to MLIR to that respect. It instead introduces two new ops: `llvm.blockaddress` and `llvm.blocktag`. Here's an example: ``` llvm.func @ba() -> !llvm.ptr { %0 = llvm.blockaddress <function = @ba, tag = <id = 1>> : !llvm.ptr llvm.br ^bb1 ^bb1: // pred: ^bb0 llvm.blocktag <id = 1> llvm.return %0 : !llvm.ptr } ``` Value `%0` hold the address of block tagged as `id = 1` in function `@ba`. Block tags need to be unique within a function and use of `llvm.blockaddress` requires a matching tag in a `llvm.blocktag`.
2025-04-04[mlir][llvm] Add `LLVM_DependentLibrariesAttr` (#133385)Iris
https://llvm.org/docs/LangRef.html#dependent-libs-named-metadata --------- Co-authored-by: Tobias Gysi <tobias.gysi@nextsilicon.com>
2025-03-17[MLIR][LLVM] Avoid duplicated module flags in the export (#131627)Christian Ulmann
This commit resolves an issue in the LLVMIR export that caused the duplication of the "Debug Info Version" module flag, when it was already in MLIR.
2025-03-14[MLIR][LLVM] Import dereferenceable metadata from LLVM IR (#130974)mihailo-stojanovic
Add support for importing `dereferenceable` and `dereferenceable_or_null` metadata into LLVM dialect. Add a new attribute which models these two metadata nodes and a new OpInterface.
2025-03-07[MLIR][LLVMIR] Translation: honor target-features fn attribute (#130343)Bruno Cardoso Lopes
2025-03-07[MLIR][LLVMIR] Translation: honor frame-pointer fn attribute (#130335)Bruno Cardoso Lopes
2025-03-06[IR] Store Triple in Module (NFC) (#129868)Nikita Popov
The module currently stores the target triple as a string. This means that any code that wants to actually use the triple first has to instantiate a Triple, which is somewhat expensive. The change in #121652 caused a moderate compile-time regression due to this. While it would be easy enough to work around, I think that architecturally, it makes more sense to store the parsed Triple in the module, so that it can always be directly queried. For this change, I've opted not to add any magic conversions between std::string and Triple for backwards-compatibilty purses, and instead write out needed Triple()s or str()s explicitly. This is because I think a decent number of them should be changed to work on Triple as well, to avoid unnecessary conversions back and forth. The only interesting part in this patch is that the default triple is Triple("") instead of Triple() to preserve existing behavior. The former defaults to using the ELF object format instead of unknown object format. We should fix that as well.
2025-03-05[MLIR][LLVMIR] llvm.call_intrinsic: support operand/result attributes (#129640)Bruno Cardoso Lopes
Basically catch up with llvm.call and add support for translate and import to LLVM IR. This PR is split into two commits in case it's easier to review the refactoring part, which comes first (happy to split the PR if necessary). --------- Co-authored-by: Tobias Gysi <tobias.gysi@nextsilicon.com>
2025-03-05[MLIR][DLTI] Add mangling style (#125875)Guojin
Add mangling style as a spec entry to datalayout, and implemented importing and exporting LLVM IR to MLIR (LLVM dialect). Its represented as string as the scope of this PR is to preserve info from LLVM IR, so client in MLIR still need to map deduce the meaning of the string, like "e" means ELF, "o" for Mach-O, etc. it addresses one of issues mentioned in this [issue](https://github.com/llvm/llvm-project/issues/126046)
2025-02-28[MLIR][LLVMIR] Add support for empty global ctor/dtor lists (#128969)Bruno Cardoso Lopes
LLVM IR emitted in from C++ may contain `@llvm.global_ctors = appending global [0 x { i32, ptr, ptr }] zeroinitializer`. Before this PR, if we try to roundtrip code like this from the importer, we'll end up with nothing in place. Note that `llvm::appendToGlobalCtors` ignores empty lists and this PR uses the same approach as `llvm-as`, which doesn't use the utilities from `llvm/lib/Transforms/Utils/ModuleUtils.cpp` in order to build this - it calls into creating a global variable from scratch.
2025-02-13[MLIR][LLVMIR] Fix use-after-moveNikita Popov
Fix an issue introduced in #126929: The LLVM module is moved into the ModuleTranslator, so query the DataLayout from there.
2025-02-13[MLIR][LLVMIR] Always use TargetFolder in IRBuilder (#126929)Nikita Popov
This is a followup to https://github.com/llvm/llvm-project/pull/126745, generalizing it to always use TargetFolder, including inside function bodies. This avoids generating non-canonical constant expressions that can be folded away.