Skip to content

[Func][GPU] Use SymbolUserOpInterface in func::ConstantOp #107748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2024
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
2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/Func/IR/FuncOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def CallIndirectOp : Func_Op<"call_indirect", [

def ConstantOp : Func_Op<"constant",
[ConstantLike, Pure,
DeclareOpInterfaceMethods<SymbolUserOpInterface>,
DeclareOpInterfaceMethods<OpAsmOpInterface, ["getAsmResultNames"]>]> {
let summary = "constant";
let description = [{
Expand Down Expand Up @@ -216,7 +217,6 @@ def ConstantOp : Func_Op<"constant",
}];

let hasFolder = 1;
let hasVerifier = 1;
}

//===----------------------------------------------------------------------===//
Expand Down
5 changes: 3 additions & 2 deletions mlir/lib/Dialect/Func/IR/FuncOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ LogicalResult CallIndirectOp::canonicalize(CallIndirectOp indirectCall,
// ConstantOp
//===----------------------------------------------------------------------===//

LogicalResult ConstantOp::verify() {
LogicalResult ConstantOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
StringRef fnName = getValue();
Type type = getType();

// Try to find the referenced function.
auto fn = (*this)->getParentOfType<ModuleOp>().lookupSymbol<FuncOp>(fnName);
auto fn = symbolTable.lookupNearestSymbolFrom<FuncOp>(
this->getOperation(), StringAttr::get(getContext(), fnName));
if (!fn)
return emitOpError() << "reference to undefined function '" << fnName
<< "'";
Expand Down
21 changes: 21 additions & 0 deletions mlir/test/Dialect/GPU/indirect-device-func-call.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: mlir-opt -test-gpu-rewrite -convert-func-to-llvm %s | FileCheck %s

gpu.module @kernels {
// CHECK-LABEL: @hello
// CHECK-SAME: %[[ARG0:.*]]: f32
func.func @hello(%arg0 : f32) {
%tid_x = gpu.thread_id x
%csti8 = arith.constant 2 : i8
gpu.printf "Hello from %lld, %d, %f\n" %tid_x, %csti8, %arg0 : index, i8, f32
return
}
// CHECK-LABEL: @hello_indirect
gpu.func @hello_indirect() kernel {
%cstf32 = arith.constant 3.0 : f32
// CHECK: %[[DEVICE_FUNC_ADDR:.*]] = llvm.mlir.addressof @hello : !llvm.ptr
%func_ref = func.constant @hello : (f32) -> ()
// CHECK: llvm.call %[[DEVICE_FUNC_ADDR]](%{{.*}}) : !llvm.ptr, (f32) -> ()
func.call_indirect %func_ref(%cstf32) : (f32) -> ()
gpu.return
}
}
Loading