|
14 | 14 | #ifndef LLVMIR_OP_BASE
|
15 | 15 | #define LLVMIR_OP_BASE
|
16 | 16 |
|
| 17 | +include "mlir/Dialect/LLVMIR/LLVMAttrDefs.td" |
17 | 18 | include "mlir/Dialect/LLVMIR/LLVMInterfaces.td"
|
18 |
| -include "mlir/IR/EnumAttr.td" |
19 | 19 | include "mlir/IR/OpBase.td"
|
20 | 20 | include "mlir/Interfaces/SideEffectInterfaces.td"
|
21 | 21 |
|
22 |
| -//===----------------------------------------------------------------------===// |
23 |
| -// LLVM Dialect. |
24 |
| -//===----------------------------------------------------------------------===// |
25 |
| - |
26 |
| -def LLVM_Dialect : Dialect { |
27 |
| - let name = "llvm"; |
28 |
| - let cppNamespace = "::mlir::LLVM"; |
29 |
| - |
30 |
| - let useDefaultAttributePrinterParser = 1; |
31 |
| - let hasRegionArgAttrVerify = 1; |
32 |
| - let hasRegionResultAttrVerify = 1; |
33 |
| - let hasOperationAttrVerify = 1; |
34 |
| - |
35 |
| - let extraClassDeclaration = [{ |
36 |
| - /// Name of the data layout attributes. |
37 |
| - static StringRef getDataLayoutAttrName() { return "llvm.data_layout"; } |
38 |
| - static StringRef getNoAliasScopesAttrName() { return "noalias_scopes"; } |
39 |
| - static StringRef getAliasScopesAttrName() { return "alias_scopes"; } |
40 |
| - static StringRef getAccessGroupsAttrName() { return "access_groups"; } |
41 |
| - |
42 |
| - /// Names of llvm parameter attributes. |
43 |
| - static StringRef getAlignAttrName() { return "llvm.align"; } |
44 |
| - static StringRef getAllocAlignAttrName() { return "llvm.allocalign"; } |
45 |
| - static StringRef getAllocatedPointerAttrName() { return "llvm.allocptr"; } |
46 |
| - static StringRef getByValAttrName() { return "llvm.byval"; } |
47 |
| - static StringRef getByRefAttrName() { return "llvm.byref"; } |
48 |
| - static StringRef getNoUndefAttrName() { return "llvm.noundef"; } |
49 |
| - static StringRef getDereferenceableAttrName() { return "llvm.dereferenceable"; } |
50 |
| - static StringRef getDereferenceableOrNullAttrName() { return "llvm.dereferenceable_or_null"; } |
51 |
| - static StringRef getInAllocaAttrName() { return "llvm.inalloca"; } |
52 |
| - static StringRef getInRegAttrName() { return "llvm.inreg"; } |
53 |
| - static StringRef getNestAttrName() { return "llvm.nest"; } |
54 |
| - static StringRef getNoAliasAttrName() { return "llvm.noalias"; } |
55 |
| - static StringRef getNoCaptureAttrName() { return "llvm.nocapture"; } |
56 |
| - static StringRef getNoFreeAttrName() { return "llvm.nofree"; } |
57 |
| - static StringRef getNonNullAttrName() { return "llvm.nonnull"; } |
58 |
| - static StringRef getPreallocatedAttrName() { return "llvm.preallocated"; } |
59 |
| - static StringRef getReadonlyAttrName() { return "llvm.readonly"; } |
60 |
| - static StringRef getReturnedAttrName() { return "llvm.returned"; } |
61 |
| - static StringRef getSExtAttrName() { return "llvm.signext"; } |
62 |
| - static StringRef getStackAlignmentAttrName() { return "llvm.alignstack"; } |
63 |
| - static StringRef getStructRetAttrName() { return "llvm.sret"; } |
64 |
| - static StringRef getWriteOnlyAttrName() { return "llvm.writeonly"; } |
65 |
| - static StringRef getZExtAttrName() { return "llvm.zeroext"; } |
66 |
| - // TODO Restrict the usage of this to parameter attributes once there is an |
67 |
| - // alternative way of modeling memory effects on FunctionOpInterface. |
68 |
| - /// Name of the attribute that will cause the creation of a readnone memory |
69 |
| - /// effect when lowering to the LLVMDialect. |
70 |
| - static StringRef getReadnoneAttrName() { return "llvm.readnone"; } |
71 |
| - |
72 |
| - /// Verifies if the given string is a well-formed data layout descriptor. |
73 |
| - /// Uses `reportError` to report errors. |
74 |
| - static LogicalResult verifyDataLayoutString( |
75 |
| - StringRef descr, llvm::function_ref<void (const Twine &)> reportError); |
76 |
| - |
77 |
| - /// Name of the target triple attribute. |
78 |
| - static StringRef getTargetTripleAttrName() { return "llvm.target_triple"; } |
79 |
| - |
80 |
| - /// Name of the C wrapper emission attribute. |
81 |
| - static StringRef getEmitCWrapperAttrName() { |
82 |
| - return "llvm.emit_c_interface"; |
83 |
| - } |
84 |
| - |
85 |
| - /// Returns `true` if the given type is compatible with the LLVM dialect. |
86 |
| - static bool isCompatibleType(Type); |
87 |
| - |
88 |
| - |
89 |
| - Type parseType(DialectAsmParser &p) const override; |
90 |
| - void printType(Type, DialectAsmPrinter &p) const override; |
91 |
| - |
92 |
| - private: |
93 |
| - /// Verifies a parameter attribute attached to a parameter of type |
94 |
| - /// paramType. |
95 |
| - LogicalResult verifyParameterAttribute(Operation *op, |
96 |
| - Type paramType, |
97 |
| - NamedAttribute paramAttr); |
98 |
| - |
99 |
| - /// Register all types. |
100 |
| - void registerTypes(); |
101 |
| - |
102 |
| - /// A cache storing compatible LLVM types that have been verified. This |
103 |
| - /// can save us lots of verification time if there are many occurrences |
104 |
| - /// of some deeply-nested aggregate types in the program. |
105 |
| - ThreadLocalCache<DenseSet<Type>> compatibleTypes; |
106 |
| - |
107 |
| - /// Register the attributes of this dialect. |
108 |
| - void registerAttributes(); |
109 |
| - }]; |
110 |
| -} |
111 |
| - |
112 | 22 | //===----------------------------------------------------------------------===//
|
113 | 23 | // LLVM dialect type constraints.
|
114 | 24 | //===----------------------------------------------------------------------===//
|
@@ -268,59 +178,6 @@ class LLVM_OpBase<Dialect dialect, string mnemonic, list<Trait> traits = []> :
|
268 | 178 | list<int> llvmArgIndices = [];
|
269 | 179 | }
|
270 | 180 |
|
271 |
| -//===----------------------------------------------------------------------===// |
272 |
| -// Base classes for LLVM enum attributes. |
273 |
| -//===----------------------------------------------------------------------===// |
274 |
| - |
275 |
| -// Case of the LLVM enum attribute backed by I64Attr with customized string |
276 |
| -// representation that corresponds to what is visible in the textual IR form. |
277 |
| -// The parameters are as follows: |
278 |
| -// - `cppSym`: name of the C++ enumerant for this case in MLIR API; |
279 |
| -// - `irSym`: keyword used in the custom form of MLIR operation; |
280 |
| -// - `llvmSym`: name of the C++ enumerant for this case in LLVM API. |
281 |
| -// For example, `LLVM_EnumAttrCase<"Weak", "weak", "WeakAnyLinkage">` is usable |
282 |
| -// as `<MlirEnumName>::Weak` in MLIR API, `WeakAnyLinkage` in LLVM API and |
283 |
| -// is printed/parsed as `weak` in MLIR custom textual format. |
284 |
| -class LLVM_EnumAttrCase<string cppSym, string irSym, string llvmSym, int val> : |
285 |
| - I64EnumAttrCase<cppSym, val, irSym> { |
286 |
| - // The name of the equivalent enumerant in LLVM. |
287 |
| - string llvmEnumerant = llvmSym; |
288 |
| -} |
289 |
| - |
290 |
| -// LLVM enum attribute backed by I64Attr with string representation |
291 |
| -// corresponding to what is visible in the textual IR form. |
292 |
| -// The parameters are as follows: |
293 |
| -// - `name`: name of the C++ enum class in MLIR API; |
294 |
| -// - `llvmName`: name of the C++ enum in LLVM API; |
295 |
| -// - `description`: textual description for documentation purposes; |
296 |
| -// - `cases`: list of enum cases; |
297 |
| -// - `unsupportedCases`: optional list of unsupported enum cases. |
298 |
| -// For example, `LLVM_EnumAttr<Linkage, "::llvm::GlobalValue::LinkageTypes` |
299 |
| -// produces `mlir::LLVM::Linkage` enum class in MLIR API that corresponds to (a |
300 |
| -// subset of) values in the `llvm::GlobalValue::LinkageTypes` in LLVM API. |
301 |
| -// All unsupported cases are excluded from the MLIR enum and trigger an error |
302 |
| -// during the import from LLVM IR. They are useful to handle sentinel values |
303 |
| -// such as `llvm::AtomicRMWInst::BinOp::BAD_BINOP` that LLVM commonly uses to |
304 |
| -// terminate its enums. |
305 |
| -class LLVM_EnumAttr<string name, string llvmName, string description, |
306 |
| - list<LLVM_EnumAttrCase> cases, |
307 |
| - list<LLVM_EnumAttrCase> unsupportedCases = []> : |
308 |
| - I64EnumAttr<name, description, cases> { |
309 |
| - // List of unsupported cases that have no conversion to an MLIR value. |
310 |
| - list<LLVM_EnumAttrCase> unsupported = unsupportedCases; |
311 |
| - |
312 |
| - // The equivalent enum class name in LLVM. |
313 |
| - string llvmClassName = llvmName; |
314 |
| -} |
315 |
| - |
316 |
| -// LLVM_CEnumAttr is functionally identical to LLVM_EnumAttr, but to be used for |
317 |
| -// non-class enums. |
318 |
| -class LLVM_CEnumAttr<string name, string llvmNS, string description, |
319 |
| - list<LLVM_EnumAttrCase> cases> : |
320 |
| - I64EnumAttr<name, description, cases> { |
321 |
| - string llvmClassName = llvmNS; |
322 |
| -} |
323 |
| - |
324 | 181 | //===----------------------------------------------------------------------===//
|
325 | 182 | // Patterns for LLVM dialect operations.
|
326 | 183 | //===----------------------------------------------------------------------===//
|
|
0 commit comments