Skip to content

Commit 448179a

Browse files
committed
Move FunctionCallOp verification to verifySymbolUses
1 parent 8c6d4c8 commit 448179a

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define MLIR_DIALECT_SPIRV_IR_CONTROLFLOW_OPS
1616

1717
include "mlir/Dialect/SPIRV/IR/SPIRVBase.td"
18+
include "mlir/IR/SymbolInterfaces.td"
1819
include "mlir/Interfaces/CallInterfaces.td"
1920
include "mlir/Interfaces/ControlFlowInterfaces.td"
2021
include "mlir/Interfaces/SideEffectInterfaces.td"
@@ -187,7 +188,8 @@ def SPIRV_BranchConditionalOp : SPIRV_Op<"BranchConditional", [
187188
// -----
188189

189190
def SPIRV_FunctionCallOp : SPIRV_Op<"FunctionCall", [
190-
InFunctionScope, DeclareOpInterfaceMethods<CallOpInterface>]> {
191+
InFunctionScope, DeclareOpInterfaceMethods<CallOpInterface>,
192+
DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
191193
let summary = "Call a function.";
192194

193195
let description = [{

mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,27 @@ LogicalResult BranchConditionalOp::verify() {
151151
//===----------------------------------------------------------------------===//
152152

153153
LogicalResult FunctionCallOp::verify() {
154+
if (getNumResults() > 1) {
155+
return emitOpError(
156+
"expected callee function to have 0 or 1 result, but provided ")
157+
<< getNumResults();
158+
}
159+
return success();
160+
}
161+
162+
LogicalResult
163+
FunctionCallOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
154164
auto fnName = getCalleeAttr();
155165

156-
auto funcOp = dyn_cast_or_null<spirv::FuncOp>(
157-
SymbolTable::lookupNearestSymbolFrom((*this)->getParentOp(), fnName));
166+
auto funcOp =
167+
symbolTable.lookupNearestSymbolFrom<spirv::FuncOp>(*this, fnName);
158168
if (!funcOp) {
159169
return emitOpError("callee function '")
160170
<< fnName.getValue() << "' not found in nearest symbol table";
161171
}
162172

163173
auto functionType = funcOp.getFunctionType();
164174

165-
if (getNumResults() > 1) {
166-
return emitOpError(
167-
"expected callee function to have 0 or 1 result, but provided ")
168-
<< getNumResults();
169-
}
170-
171175
if (functionType.getNumInputs() != getNumOperands()) {
172176
return emitOpError("has incorrect number of operands for callee: expected ")
173177
<< functionType.getNumInputs() << ", but provided "

0 commit comments

Comments
 (0)