@@ -30,9 +30,13 @@ using namespace mlir;
30
30
#define DEBUG_TYPE " dlti"
31
31
32
32
// ===----------------------------------------------------------------------===//
33
- // parsing
33
+ // Common parsing utility functions.
34
34
// ===----------------------------------------------------------------------===//
35
35
36
+ // / Parse an entry which can either be of the form `key = value` or a
37
+ // / #dlti.dl_entry attribute. When `tryType=true` the key can be a type,
38
+ // / otherwise only quoted strings are allowed. The grammar is as follows:
39
+ // / entry ::= ((type | quoted-string) `=` attr) | dl-entry-attr
36
40
static ParseResult parseKeyValuePair (AsmParser &parser,
37
41
DataLayoutEntryInterface &entry,
38
42
bool tryType = false ) {
@@ -79,6 +83,12 @@ static ParseResult parseKeyValuePair(AsmParser &parser,
79
83
<< " failed to parse DLTI entry" ;
80
84
}
81
85
86
+ // / Construct a requested attribute by parsing list of entries occurring within
87
+ // / a pair of `<` and `>`, optionally allow types as keys and an empty list.
88
+ // / The grammar is as follows:
89
+ // / bracketed-entry-list ::=`<` entry-list `>`
90
+ // / entry-list ::= | entry | entry `,` entry-list
91
+ // / entry ::= ((type | quoted-string) `=` attr) | dl-entry-attr
82
92
template <class Attr >
83
93
static Attribute parseAngleBracketedEntries (AsmParser &parser, Type ty,
84
94
bool tryType = false ,
@@ -100,18 +110,19 @@ static Attribute parseAngleBracketedEntries(AsmParser &parser, Type ty,
100
110
}
101
111
102
112
// ===----------------------------------------------------------------------===//
103
- // printing
113
+ // Common printing utility functions.
104
114
// ===----------------------------------------------------------------------===//
105
115
116
+ // / Convert pointer-union keys to strings.
106
117
static inline std::string keyToStr (DataLayoutEntryKey key) {
107
118
std::string buf;
108
- llvm:: TypeSwitch<DataLayoutEntryKey>(key)
119
+ TypeSwitch<DataLayoutEntryKey>(key)
109
120
.Case <StringAttr, Type>( // The only two kinds of key we know of.
110
- [&](auto key) { llvm::raw_string_ostream (buf) << key; })
111
- .Default ([](auto ) { llvm_unreachable (" unexpected entry key kind" ); });
121
+ [&](auto key) { llvm::raw_string_ostream (buf) << key; });
112
122
return buf;
113
123
}
114
124
125
+ // / Pretty-print entries, each in `key = value` format, separated by commas.
115
126
template <class T >
116
127
static void printAngleBracketedEntries (AsmPrinter &os, T &&entries) {
117
128
os << " <" ;
@@ -122,9 +133,10 @@ static void printAngleBracketedEntries(AsmPrinter &os, T &&entries) {
122
133
}
123
134
124
135
// ===----------------------------------------------------------------------===//
125
- // verifying
136
+ // Common verifying utility functions.
126
137
// ===----------------------------------------------------------------------===//
127
138
139
+ // / Verify entries, with the option to disallow types as keys.
128
140
static LogicalResult verifyEntries (function_ref<InFlightDiagnostic()> emitError,
129
141
ArrayRef<DataLayoutEntryInterface> entries,
130
142
bool allowTypes = true) {
@@ -135,7 +147,7 @@ static LogicalResult verifyEntries(function_ref<InFlightDiagnostic()> emitError,
135
147
DataLayoutEntryKey key = entry.getKey ();
136
148
if (key.isNull ())
137
149
return emitError () << " contained invalid DLTI key" ;
138
- if (!allowTypes && llvm:: dyn_cast<Type>(key))
150
+ if (!allowTypes && dyn_cast<Type>(key))
139
151
return emitError () << " type as DLIT key is not allowed" ;
140
152
if (!keys.insert (key).second )
141
153
return emitError () << " repeated DLTI key: " << keyToStr (key);
@@ -306,7 +318,7 @@ combineOneSpec(DataLayoutSpecInterface spec,
306
318
typeSample.getContext ()->getLoadedDialect <BuiltinDialect>() &&
307
319
" unexpected data layout entry for built-in type" );
308
320
309
- auto interface = llvm:: cast<DataLayoutTypeInterface>(typeSample);
321
+ auto interface = cast<DataLayoutTypeInterface>(typeSample);
310
322
if (!interface.areCompatible (entriesForType.lookup (kvp.first ), kvp.second ))
311
323
return failure ();
312
324
@@ -340,7 +352,7 @@ DataLayoutSpecAttr
340
352
DataLayoutSpecAttr::combineWith (ArrayRef<DataLayoutSpecInterface> specs) const {
341
353
// Only combine with attributes of the same kind.
342
354
// TODO: reconsider this when the need arises.
343
- if (llvm:: any_of (specs, [](DataLayoutSpecInterface spec) {
355
+ if (any_of (specs, [](DataLayoutSpecInterface spec) {
344
356
return !llvm::isa<DataLayoutSpecAttr>(spec);
345
357
}))
346
358
return {};
@@ -488,7 +500,7 @@ getClosestQueryable(Operation *op) {
488
500
// Search op and its ancestors for the first attached DLTIQueryInterface attr.
489
501
do {
490
502
for (NamedAttribute attr : op->getAttrs ())
491
- if ((queryable = llvm:: dyn_cast<DLTIQueryInterface>(attr.getValue ())))
503
+ if ((queryable = dyn_cast<DLTIQueryInterface>(attr.getValue ())))
492
504
break ;
493
505
} while (!queryable && (op = op->getParentOp ()));
494
506
@@ -519,7 +531,7 @@ dlti::query(Operation *op, ArrayRef<DataLayoutEntryKey> keys, bool emitError) {
519
531
520
532
Attribute currentAttr = queryable;
521
533
for (auto &&[idx, key] : llvm::enumerate (keys)) {
522
- if (auto map = llvm:: dyn_cast<DLTIQueryInterface>(currentAttr)) {
534
+ if (auto map = dyn_cast<DLTIQueryInterface>(currentAttr)) {
523
535
auto maybeAttr = map.query (key);
524
536
if (failed (maybeAttr)) {
525
537
if (emitError) {
@@ -565,7 +577,7 @@ class TargetDataLayoutInterface : public DataLayoutDialectInterface {
565
577
Location loc) const final {
566
578
StringRef entryName = entry.getKey ().get <StringAttr>().strref ();
567
579
if (entryName == DLTIDialect::kDataLayoutEndiannessKey ) {
568
- auto value = llvm:: dyn_cast<StringAttr>(entry.getValue ());
580
+ auto value = dyn_cast<StringAttr>(entry.getValue ());
569
581
if (value &&
570
582
(value.getValue () == DLTIDialect::kDataLayoutEndiannessBig ||
571
583
value.getValue () == DLTIDialect::kDataLayoutEndiannessLittle ))
0 commit comments