File tree Expand file tree Collapse file tree 4 files changed +52
-2
lines changed
Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Original file line number Diff line number Diff line change 1+ // RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+ // Test basic symbol verification using discardable attribute.
4+ module {
5+ func.func @existing_symbol () { return }
6+
7+ func.func @test () attributes {symbol_ref = #test.symbol_ref_attr <@existing_symbol >} { return }
8+ }
9+
10+ // -----
11+
12+ // Test invalid symbol reference, symbol does not exist.
13+ module {
14+ // expected-error@+1 {{TestSymbolRefAttr::verifySymbolUses: '@non_existent_symbol' does not reference a valid symbol}}
15+ func.func @test () attributes {symbol_ref = #test.symbol_ref_attr <@non_existent_symbol >} { return }
16+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ include "mlir/IR/AttrTypeBase.td"
2222include "mlir/IR/BuiltinAttributeInterfaces.td"
2323include "mlir/IR/EnumAttr.td"
2424include "mlir/IR/OpAsmInterface.td"
25+ include "mlir/IR/SymbolInterfaces.td"
2526
2627// All of the attributes will extend this class.
2728class Test_Attr<string name, list<Trait> traits = []>
@@ -439,4 +440,17 @@ def TestCustomStorageCtorAttr : Test_Attr<"TestCustomStorageCtorAttr"> {
439440 let hasStorageCustomConstructor = 1;
440441}
441442
443+ // Test attribute that implements SymbolUserAttrInterface.
444+ def TestSymbolRefAttr : Test_Attr<"TestSymbolRef",
445+ [DeclareAttrInterfaceMethods<SymbolUserAttrInterface>]> {
446+ let mnemonic = "symbol_ref_attr";
447+ let summary = "Test attribute that references a symbol";
448+ let description = [{
449+ This attribute holds a reference to a symbol and implements
450+ SymbolUserAttrInterface to verify that the referenced symbol exists.
451+ }];
452+ let parameters = (ins "::mlir::FlatSymbolRefAttr":$symbol);
453+ let assemblyFormat = "`<` $symbol `>`";
454+ }
455+
442456#endif // TEST_ATTRDEFS
Original file line number Diff line number Diff line change @@ -223,6 +223,25 @@ LogicalResult TestCopyCountAttr::verify(
223223 return success ();
224224}
225225
226+ // ===----------------------------------------------------------------------===//
227+ // TestSymbolRefAttr
228+ // ===----------------------------------------------------------------------===//
229+
230+ LogicalResult
231+ TestSymbolRefAttr::verifySymbolUses (Operation *op,
232+ SymbolTableCollection &symbolTable) const {
233+ // Verify that the referenced symbol exists
234+ if (!symbolTable.lookupNearestSymbolFrom <SymbolOpInterface>(op, getSymbol ()))
235+ return op->emitOpError ()
236+ << " TestSymbolRefAttr::verifySymbolUses: '" << getSymbol ()
237+ << " ' does not reference a valid symbol" ;
238+ return success ();
239+ }
240+
241+ // ===----------------------------------------------------------------------===//
242+ // Generated Attribute Definitions
243+ // ===----------------------------------------------------------------------===//
244+
226245// ===----------------------------------------------------------------------===//
227246// CopyCountAttr Implementation
228247// ===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change 2020#include " mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
2121#include " mlir/Dialect/Utils/StructuredOpsUtils.h"
2222#include " mlir/IR/Attributes.h"
23- #include " mlir/IR/Diagnostics .h"
23+ #include " mlir/IR/BuiltinAttributes .h"
2424#include " mlir/IR/Dialect.h"
25- #include " mlir/IR/DialectImplementation.h"
2625#include " mlir/IR/DialectResourceBlobManager.h"
26+ #include " mlir/IR/OpImplementation.h"
27+ #include " mlir/IR/SymbolTable.h"
2728
2829// generated files require above includes to come first
2930#include " TestAttrInterfaces.h.inc"
You can’t perform that action at this time.
0 commit comments