Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define MLIR_DIALECT_SPIRV_IR_CONTROLFLOW_OPS

include "mlir/Dialect/SPIRV/IR/SPIRVBase.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/CallInterfaces.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
Expand Down Expand Up @@ -187,7 +188,8 @@ def SPIRV_BranchConditionalOp : SPIRV_Op<"BranchConditional", [
// -----

def SPIRV_FunctionCallOp : SPIRV_Op<"FunctionCall", [
InFunctionScope, DeclareOpInterfaceMethods<CallOpInterface>]> {
InFunctionScope, DeclareOpInterfaceMethods<CallOpInterface>,
DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
let summary = "Call a function.";

let description = [{
Expand Down
20 changes: 12 additions & 8 deletions mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,27 @@ LogicalResult BranchConditionalOp::verify() {
//===----------------------------------------------------------------------===//

LogicalResult FunctionCallOp::verify() {
if (getNumResults() > 1) {
return emitOpError(
"expected callee function to have 0 or 1 result, but provided ")
<< getNumResults();
}
return success();
}

LogicalResult
FunctionCallOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
auto fnName = getCalleeAttr();

auto funcOp = dyn_cast_or_null<spirv::FuncOp>(
SymbolTable::lookupNearestSymbolFrom((*this)->getParentOp(), fnName));
auto funcOp =
symbolTable.lookupNearestSymbolFrom<spirv::FuncOp>(*this, fnName);
if (!funcOp) {
return emitOpError("callee function '")
<< fnName.getValue() << "' not found in nearest symbol table";
}

auto functionType = funcOp.getFunctionType();

if (getNumResults() > 1) {
return emitOpError(
"expected callee function to have 0 or 1 result, but provided ")
<< getNumResults();
}

if (functionType.getNumInputs() != getNumOperands()) {
return emitOpError("has incorrect number of operands for callee: expected ")
<< functionType.getNumInputs() << ", but provided "
Expand Down
29 changes: 29 additions & 0 deletions mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,35 @@ spirv.module Logical GLSL450 {

// -----

"builtin.module"() ({
"spirv.module"() <{
addressing_model = #spirv.addressing_model<Logical>,
memory_model = #spirv.memory_model<GLSL450>
}> ({
"spirv.func"() <{
function_control = #spirv.function_control<None>,
function_type = (f32) -> f32,
sym_name = "bar"
}> ({
^bb0(%arg0: f32):
%0 = "spirv.FunctionCall"(%arg0) <{callee = @foo}> : (f32) -> f32
"spirv.ReturnValue"(%0) : (f32) -> ()
}) : () -> ()
// expected-error @+1 {{requires attribute 'function_type'}}
"spirv.func"() <{
function_control = #spirv.function_control<None>,
message = "2nd parent",
sym_name = "foo"
// This is invalid MLIR because function_type is missing from spirv.func.
}> ({
^bb0(%arg0: f32):
"spirv.ReturnValue"(%arg0) : (f32) -> ()
}) : () -> ()
}) : () -> ()
}) : () -> ()

// -----

//===----------------------------------------------------------------------===//
// spirv.mlir.loop
//===----------------------------------------------------------------------===//
Expand Down