@@ -13,13 +13,118 @@ include "mlir/Dialect/LLVMIR/LLVMDialect.td"
13
13
include "mlir/Dialect/LLVMIR/LLVMInterfaces.td"
14
14
include "mlir/IR/AttrTypeBase.td"
15
15
include "mlir/IR/CommonAttrConstraints.td"
16
+ include "mlir/Interfaces/DataLayoutInterfaces.td"
16
17
17
- // All of the attributes will extend this class.
18
- class LLVM_Attr<string name, string attrMnemonic,
19
- list<Trait> traits = [],
20
- string baseCppClass = "::mlir::Attribute">
21
- : AttrDef<LLVM_Dialect, name, traits, baseCppClass> {
22
- let mnemonic = attrMnemonic;
18
+ //===----------------------------------------------------------------------===//
19
+ // LLVM_TargetAttr
20
+ //===----------------------------------------------------------------------===//
21
+
22
+ def LLVM_TargetAttr : LLVM_Attr<"Target", "target", [LLVM_TargetAttrInterface]> {
23
+ let mnemonic = "target";
24
+ let summary = "TODO";
25
+ let description = [{
26
+ TODO
27
+ }];
28
+ let parameters = (ins "StringAttr":$triple,
29
+ "StringAttr":$cpu,
30
+ "TargetFeaturesAttr":$target_features);
31
+
32
+ let assemblyFormat = "`<` $triple `,` $cpu `,` qualified($target_features) `>`";
33
+
34
+ let extraClassDeclaration = [{
35
+ std::optional<llvm::TargetMachine *> targetMachine = std::nullopt;
36
+
37
+ FailureOr<llvm::TargetMachine *> getTargetMachine();
38
+
39
+ std::optional<llvm::DataLayout> dataLayout = std::nullopt;
40
+ FailureOr<llvm::DataLayout> getDataLayout();
41
+ FailureOr<Attribute> query(DataLayoutEntryKey key);
42
+ }];
43
+ }
44
+
45
+ //===----------------------------------------------------------------------===//
46
+ // LLVM_DataLayoutAttr
47
+ //===----------------------------------------------------------------------===//
48
+
49
+ def LLVM_DataLayoutAttr
50
+ : LLVM_Attr<"DataLayout", "data_layout", [DataLayoutSpecInterface]> {
51
+ let summary = "TODO";
52
+ let description = [{
53
+ TODO
54
+ }];
55
+ let parameters = (ins "StringAttr":$data_layout_str,
56
+ OptionalParameter<"DataLayoutSpecInterface", "{}">:$data_layout_spec);
57
+ let builders = [
58
+ AttrBuilder<(ins "llvm::StringRef":$data_layout_str), [{
59
+ auto importer = LLVM::DataLayoutImporter($_ctxt, data_layout_str);
60
+ auto dataLayoutSpec = importer.getDataLayout();
61
+ return $_get($_ctxt, mlir::StringAttr::get($_ctxt, data_layout_str), dataLayoutSpec);
62
+ }]>
63
+ ];
64
+ let assemblyFormat = "`<` $data_layout_str `>`";
65
+ let extraClassDeclaration = [{
66
+ template <typename Ty>
67
+ DataLayoutEntryList getSpecForType() {
68
+ return getDataLayoutSpec().getSpecForType(TypeID::get<Ty>());
69
+ }
70
+
71
+ inline ::mlir::FailureOr<::mlir::Attribute>
72
+ queryHelper(::mlir::DataLayoutEntryKey key) const {
73
+ return getDataLayoutSpec().queryHelper(key);
74
+ }
75
+
76
+ void bucketEntriesByType(
77
+ ::llvm::MapVector<::mlir::TypeID, ::mlir::DataLayoutEntryList> &types,
78
+ ::llvm::MapVector<::mlir::StringAttr,
79
+ ::mlir::DataLayoutEntryInterface> &ids) {
80
+ getDataLayoutSpec().bucketEntriesByType(types, ids);
81
+ };
82
+
83
+ ::mlir::DataLayoutSpecInterface
84
+ combineWith(ArrayRef<::mlir::DataLayoutSpecInterface> specs) const {
85
+ return getDataLayoutSpec().combineWith(specs);
86
+ }
87
+ DataLayoutEntryListRef getEntries() const { return getDataLayoutSpec().getEntries(); }
88
+ LogicalResult verifySpec(Location loc) {
89
+ return getDataLayoutSpec().verifySpec(loc);
90
+ }
91
+ StringAttr getEndiannessIdentifier(MLIRContext *context) const {
92
+ return getDataLayoutSpec().getEndiannessIdentifier(context);
93
+ }
94
+ StringAttr getDefaultMemorySpaceIdentifier(MLIRContext *context) const {
95
+ return getDataLayoutSpec().getDefaultMemorySpaceIdentifier(context);
96
+ }
97
+ StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const {
98
+ return getDataLayoutSpec().getAllocaMemorySpaceIdentifier(context);
99
+ }
100
+ StringAttr getManglingModeIdentifier(MLIRContext *context) const {
101
+ return getDataLayoutSpec().getManglingModeIdentifier(context);
102
+ }
103
+ StringAttr getProgramMemorySpaceIdentifier(MLIRContext *context) const {
104
+ return getDataLayoutSpec().getProgramMemorySpaceIdentifier(context);
105
+ }
106
+ StringAttr getGlobalMemorySpaceIdentifier(MLIRContext *context) const {
107
+ return getDataLayoutSpec().getGlobalMemorySpaceIdentifier(context);
108
+ }
109
+ StringAttr getStackAlignmentIdentifier(MLIRContext *context) const {
110
+ return getDataLayoutSpec().getStackAlignmentIdentifier(context);
111
+ }
112
+ StringAttr getFunctionPointerAlignmentIdentifier(MLIRContext *context) const {
113
+ return getDataLayoutSpec().getFunctionPointerAlignmentIdentifier(context);
114
+ }
115
+ StringAttr getLegalIntWidthsIdentifier(MLIRContext *context) const {
116
+ return getDataLayoutSpec().getLegalIntWidthsIdentifier(context);
117
+ }
118
+ ::mlir::DataLayoutEntryList getSpecForType(TypeID type) const {
119
+ return getDataLayoutSpec().getSpecForType(type);
120
+ }
121
+ ::mlir::DataLayoutEntryInterface getSpecForIdentifier(StringAttr identifier) const {
122
+ return getDataLayoutSpec().getSpecForIdentifier(identifier);
123
+ }
124
+ FailureOr<Attribute> query(DataLayoutEntryKey key) const {
125
+ return getDataLayoutSpec().query(key);
126
+ }
127
+ }];
23
128
}
24
129
25
130
//===----------------------------------------------------------------------===//
@@ -1241,69 +1346,6 @@ def LLVM_VScaleRangeAttr : LLVM_Attr<"VScaleRange", "vscale_range"> {
1241
1346
let assemblyFormat = "`<` struct(params) `>`";
1242
1347
}
1243
1348
1244
- //===----------------------------------------------------------------------===//
1245
- // TargetFeaturesAttr
1246
- //===----------------------------------------------------------------------===//
1247
-
1248
- def LLVM_TargetFeaturesAttr : LLVM_Attr<"TargetFeatures", "target_features">
1249
- {
1250
- let summary = "LLVM target features attribute";
1251
-
1252
- let description = [{
1253
- Represents the LLVM target features as a list that can be checked within
1254
- passes/rewrites.
1255
-
1256
- Example:
1257
- ```mlir
1258
- #llvm.target_features<["+sme", "+sve", "+sme-f64f64"]>
1259
- ```
1260
-
1261
- Then within a pass or rewrite the features active at an op can be queried:
1262
-
1263
- ```c++
1264
- auto targetFeatures = LLVM::TargetFeaturesAttr::featuresAt(op);
1265
-
1266
- if (!targetFeatures.contains("+sme-f64f64"))
1267
- return failure();
1268
- ```
1269
- }];
1270
-
1271
- let parameters = (ins OptionalArrayRefParameter<"StringAttr">:$features);
1272
-
1273
- let builders = [
1274
- TypeBuilder<(ins "::llvm::StringRef":$features)>,
1275
- TypeBuilder<(ins "::llvm::ArrayRef<::llvm::StringRef>":$features)>
1276
- ];
1277
-
1278
- let extraClassDeclaration = [{
1279
- /// Checks if a feature is contained within the features list.
1280
- /// Note: Using a StringAttr allows doing pointer-comparisons.
1281
- bool contains(::mlir::StringAttr feature) const;
1282
- bool contains(::llvm::StringRef feature) const;
1283
-
1284
- bool nullOrEmpty() const {
1285
- // Checks if this attribute is null, or the features are empty.
1286
- return !bool(*this) || getFeatures().empty();
1287
- }
1288
-
1289
- /// Returns the list of features as an LLVM-compatible string.
1290
- std::string getFeaturesString() const;
1291
-
1292
- /// Finds the target features on the parent FunctionOpInterface.
1293
- /// Note: This assumes the attribute name matches the return value of
1294
- /// `getAttributeName()`.
1295
- static TargetFeaturesAttr featuresAt(Operation* op);
1296
-
1297
- /// Canonical name for this attribute within MLIR.
1298
- static constexpr StringLiteral getAttributeName() {
1299
- return StringLiteral("target_features");
1300
- }
1301
- }];
1302
-
1303
- let assemblyFormat = "`<` `[` (`]`) : ($features^ `]`)? `>`";
1304
- let genVerifyDecl = 1;
1305
- }
1306
-
1307
1349
//===----------------------------------------------------------------------===//
1308
1350
// UndefAttr
1309
1351
//===----------------------------------------------------------------------===//
0 commit comments