Skip to content

Commit ff7896e

Browse files
authored
[MLIR] Add verification that symbol operations must not have results (#168390)
This patch adds verification to the `SymbolOpInterface` to enforce the design constraint that symbol operations must not produce SSA results, as documented in [Symbols and SymbolTables](https://mlir.llvm.org/docs/SymbolsAndSymbolTables/#defining-or-declaring-a-symbol). This is a follow-up of #168376
1 parent d65be16 commit ff7896e

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

mlir/include/mlir/IR/SymbolInterfaces.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ def Symbol : OpInterface<"SymbolOpInterface"> {
171171
if (concreteOp.isDeclaration() && concreteOp.isPublic())
172172
return concreteOp.emitOpError("symbol declaration cannot have public "
173173
"visibility");
174+
if ($_op->getNumResults() != 0)
175+
return concreteOp.emitOpError("symbols must not have results");
174176
auto parent = $_op->getParentOp();
175177
if (parent && !parent->hasTrait<OpTrait::SymbolTable>() && parent->isRegistered()) {
176178
return concreteOp.emitOpError("symbol's parent must have the SymbolTable "

mlir/test/IR/invalid-ops.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,11 @@ func.func @verify_fail_3() {
145145
%r = "arith.constant"() {value = -3 : si32} : () -> si32
146146
return
147147
}
148+
149+
// -----
150+
151+
// Verify that symbols with results are rejected
152+
module {
153+
// expected-error@+1 {{'test.symbol_with_result' op symbols must not have results}}
154+
%0 = "test.symbol_with_result"() <{sym_name = "test_symbol"}> : () -> i32
155+
}

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ def SymbolOp : TEST_Op<"symbol", [NoMemoryEffect, Symbol]> {
120120
OptionalAttr<StrAttr>:$sym_visibility);
121121
}
122122

123+
def SymbolWithResultOp : TEST_Op<"symbol_with_result", [Symbol]> {
124+
let summary = "invalid symbol operation that produces an SSA result";
125+
let arguments = (ins StrAttr:$sym_name,
126+
OptionalAttr<StrAttr>:$sym_visibility);
127+
let results = (outs AnyType:$result);
128+
}
129+
123130
def OverriddenSymbolVisibilityOp : TEST_Op<"overridden_symbol_visibility", [
124131
DeclareOpInterfaceMethods<Symbol, ["getVisibility", "setVisibility"]>,
125132
]> {

0 commit comments

Comments
 (0)