Skip to content

Commit 5b317ea

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 6d4a093 commit 5b317ea

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
@@ -220,6 +220,24 @@ def SymbolUserOpInterface : OpInterface<"SymbolUserOpInterface"> {
220220
];
221221
}
222222

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

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
@@ -82,6 +82,8 @@ exports_files(glob(["include/**/*.td"]))
8282
tbl_outs = {
8383
"include/mlir/IR/" + name + ".h.inc": ["-gen-op-interface-decls"],
8484
"include/mlir/IR/" + name + ".cpp.inc": ["-gen-op-interface-defs"],
85+
"include/mlir/IR/" + name + "AttrInterface.h.inc": ["-gen-attr-interface-decls"],
86+
"include/mlir/IR/" + name + "AttrInterface.cpp.inc": ["-gen-attr-interface-defs"],
8587
},
8688
tblgen = ":mlir-tblgen",
8789
td_file = "include/mlir/IR/" + name + ".td",

0 commit comments

Comments
 (0)