File tree 3 files changed +45
-2
lines changed
3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 54
54
// CHECK: #loc1 = loc(fused<memref<1xi32>
55
55
// CHECK-NOT: #map
56
56
" test.op" () {alias_test = loc(fused<memref <1 xi32 , affine_map <(d0 ) -> (d0 )>>>[" test.mlir" :10 :8 ])} : () -> ()
57
+
58
+ // -----
59
+
60
+ #unalias_me = " goodbye"
61
+ #keep_aliased = " alias_test:dot_in_name"
62
+
63
+ // CHECK: #test.conditional_alias<hello>
64
+ " test.op" () {attr = #test.conditional_alias <" hello" >} : () -> ()
65
+ // CHECK-NEXT: #test.conditional_alias<#test_encoding>
66
+ " test.op" () {attr = #test.conditional_alias <" alias_test:tensor_encoding" >} : () -> ()
67
+ // CHECK: #test.conditional_alias<goodbye>
68
+ " test.op" () {attr = #test.conditional_alias <#unalias_me >} : () -> ()
69
+ // CHECK-NEXT: #test.conditional_alias<#test2Ealias>
70
+ " test.op" () {attr = #test.conditional_alias <#keep_aliased >} : () -> ()
Original file line number Diff line number Diff line change @@ -332,7 +332,12 @@ def TestCopyCount : Test_Attr<"TestCopyCount"> {
332
332
let assemblyFormat = "`<` $copy_count `>`";
333
333
}
334
334
335
-
336
-
335
+ def TestConditionalAliasAttr : Test_Attr<"TestConditionalAlias"> {
336
+ let mnemonic = "conditional_alias";
337
+ let parameters = (ins "mlir::StringAttr":$value);
338
+ let assemblyFormat = [{
339
+ `<` custom<ConditionalAlias>($value) `>`
340
+ }];
341
+ }
337
342
338
343
#endif // TEST_ATTRDEFS
Original file line number Diff line number Diff line change @@ -215,6 +215,30 @@ llvm::hash_code hash_value(const test::CopyCount ©Count) {
215
215
return llvm::hash_value (copyCount.value );
216
216
}
217
217
} // namespace test
218
+
219
+ // ===----------------------------------------------------------------------===//
220
+ // TestConditionalAliasAttr
221
+ // ===----------------------------------------------------------------------===//
222
+
223
+ // / Attempt to parse the conditionally-aliased string attribute as a keyword or
224
+ // / string, else try to parse an alias.
225
+ static ParseResult parseConditionalAlias (AsmParser &p, StringAttr &value) {
226
+ std::string str;
227
+ if (succeeded (p.parseOptionalKeywordOrString (&str))) {
228
+ value = StringAttr::get (p.getContext (), str);
229
+ return success ();
230
+ }
231
+ return p.parseAttribute (value);
232
+ }
233
+
234
+ // / Print the string attribute as an alias if it has one, otherwise print it as
235
+ // / a keyword if possible.
236
+ static void printConditionalAlias (AsmPrinter &p, StringAttr value) {
237
+ if (succeeded (p.printAlias (value)))
238
+ return ;
239
+ p.printKeywordOrString (value);
240
+ }
241
+
218
242
// ===----------------------------------------------------------------------===//
219
243
// Tablegen Generated Definitions
220
244
// ===----------------------------------------------------------------------===//
You can’t perform that action at this time.
0 commit comments