Skip to content

Commit 7eacae8

Browse files
committed
[mlir] Add symbol user attribute interface.
Enables verification of attributes, independent of op, that references symbols. RFC: this enables verifying Attribute with symbol usage indpendent of operation attached to (e.g., the validity is on the Attribute independent of the operation).
1 parent bfce025 commit 7eacae8

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

mlir/include/mlir/IR/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
add_mlir_interface(SymbolInterfaces)
2+
set(LLVM_TARGET_DEFINITIONS SymbolInterfaces.td)
3+
mlir_tablegen(SymbolInterfacesAttrInterface.h.inc -gen-attr-interface-decls)
4+
mlir_tablegen(SymbolInterfacesAttrInterface.cpp.inc -gen-attr-interface-defs)
25
add_mlir_interface(RegionKindInterface)
36

47
set(LLVM_TARGET_DEFINITIONS OpAsmInterface.td)

mlir/include/mlir/IR/SymbolInterfaces.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,24 @@ def SymbolUserOpInterface : OpInterface<"SymbolUserOpInterface"> {
222222
];
223223
}
224224

225+
def SymbolUserAttrInterface : AttrInterface<"SymbolUserAttrInterface"> {
226+
let description = [{
227+
This interface describes an attrivute that may use a `Symbol`. This
228+
interface allows for users of symbols to hook into verification and other
229+
symbol related utilities that are either costly or otherwise disallowed
230+
within a traditional operation.
231+
}];
232+
let cppNamespace = "::mlir";
233+
234+
let methods = [
235+
InterfaceMethod<"Verify the symbol uses held by this attribute of this operation.",
236+
"::llvm::LogicalResult", "verifySymbolUses",
237+
(ins "::mlir::Operation *":$op,
238+
"::mlir::SymbolTableCollection &":$symbolTable)
239+
>,
240+
];
241+
}
242+
225243
//===----------------------------------------------------------------------===//
226244
// Symbol Traits
227245
//===----------------------------------------------------------------------===//

mlir/include/mlir/IR/SymbolTable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,5 +499,6 @@ ParseResult parseOptionalVisibilityKeyword(OpAsmParser &parser,
499499

500500
/// Include the generated symbol interfaces.
501501
#include "mlir/IR/SymbolInterfaces.h.inc"
502+
#include "mlir/IR/SymbolInterfacesAttrInterface.h.inc"
502503

503504
#endif // MLIR_IR_SYMBOLTABLE_H

mlir/lib/IR/SymbolTable.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,14 @@ LogicalResult detail::verifySymbolTable(Operation *op) {
511511
SymbolTableCollection symbolTable;
512512
auto verifySymbolUserFn = [&](Operation *op) -> std::optional<WalkResult> {
513513
if (SymbolUserOpInterface user = dyn_cast<SymbolUserOpInterface>(op))
514-
return WalkResult(user.verifySymbolUses(symbolTable));
514+
if (failed(user.verifySymbolUses(symbolTable)))
515+
return WalkResult::interrupt();
516+
for (auto &attr : op->getRawDictionaryAttrs()) {
517+
if (auto user = dyn_cast<SymbolUserAttrInterface>(attr.getValue())) {
518+
if (failed(user.verifySymbolUses(op, symbolTable)))
519+
return WalkResult::interrupt();
520+
}
521+
}
515522
return WalkResult::advance();
516523
};
517524

@@ -1132,3 +1139,4 @@ ParseResult impl::parseOptionalVisibilityKeyword(OpAsmParser &parser,
11321139

11331140
/// Include the generated symbol interfaces.
11341141
#include "mlir/IR/SymbolInterfaces.cpp.inc"
1142+
#include "mlir/IR/SymbolInterfacesAttrInterface.cpp.inc"

utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ exports_files(glob(["include/**/*.td"]))
8585
tbl_outs = {
8686
"include/mlir/IR/" + name + ".h.inc": ["-gen-op-interface-decls"],
8787
"include/mlir/IR/" + name + ".cpp.inc": ["-gen-op-interface-defs"],
88+
"include/mlir/IR/" + name + "AttrInterface.h.inc": ["-gen-attr-interface-decls"],
89+
"include/mlir/IR/" + name + "AttrInterface.cpp.inc": ["-gen-attr-interface-defs"],
8890
},
8991
tblgen = ":mlir-tblgen",
9092
td_file = "include/mlir/IR/" + name + ".td",

0 commit comments

Comments
 (0)