[Mlir-commits] [flang] [mlir] [MLIR][LLVMIR][DLTI] Add #llvm.target, #llvm.data_layout and TargetAttrInterface (PR #145899)

Renato Golin llvmlistbot at llvm.org
Thu Jun 26 12:06:29 PDT 2025


================
@@ -13,13 +13,118 @@ include "mlir/Dialect/LLVMIR/LLVMDialect.td"
 include "mlir/Dialect/LLVMIR/LLVMInterfaces.td"
 include "mlir/IR/AttrTypeBase.td"
 include "mlir/IR/CommonAttrConstraints.td"
+include "mlir/Interfaces/DataLayoutInterfaces.td"
 
-// All of the attributes will extend this class.
-class LLVM_Attr<string name, string attrMnemonic,
-                list<Trait> traits = [],
-                string baseCppClass = "::mlir::Attribute">
-    : AttrDef<LLVM_Dialect, name, traits, baseCppClass> {
-  let mnemonic = attrMnemonic;
+//===----------------------------------------------------------------------===//
+// LLVM_TargetAttr
+//===----------------------------------------------------------------------===//
+
+def LLVM_TargetAttr : LLVM_Attr<"Target", "target", [LLVM_TargetAttrInterface]> {
----------------
rengolin wrote:

One problem we faced on our side earlier was that it's not that easy to know you're constructing an invalid `TargetMachine` ([link](https://discourse.llvm.org/t/generating-riscv-code-from-mlir/85863)). But validating all possible combinations is just not viable. For downstream targets, you'd have to overload some verification to match their alternatives.

Other tools don't verify much either (other than completely crash if the strings are invalid), so I guess we can start with that. The discussion about which combinations are valid ([link](https://discourse.llvm.org/t/move-remove-vcix-dialect/86920/46)) are generally higher in the pipeline (front-end). At the IR level, we can only treat them as "gospel" and crash if we really can't build a `TargetMachine`.

https://github.com/llvm/llvm-project/pull/145899


More information about the Mlir-commits mailing list