Skip to content

Commit bfb43b0

Browse files
author
Artem Kroviakov
committed
[Func][GPU] Create func::ConstantOp using parents with SymbolTable trait
1 parent bc59b63 commit bfb43b0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

mlir/lib/Dialect/Func/IR/FuncOps.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ LogicalResult ConstantOp::verify() {
128128
Type type = getType();
129129

130130
// Try to find the referenced function.
131-
auto fn = (*this)->getParentOfType<ModuleOp>().lookupSymbol<FuncOp>(fnName);
131+
SymbolTable symbolTable(
132+
(*this)->getParentWithTrait<mlir::OpTrait::SymbolTable>());
133+
auto fn = symbolTable.lookup<FuncOp>(fnName);
132134
if (!fn)
133135
return emitOpError() << "reference to undefined function '" << fnName
134136
<< "'";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: mlir-opt -test-gpu-rewrite -convert-func-to-llvm %s | FileCheck %s
2+
3+
gpu.module @kernels {
4+
// CHECK-LABEL: @hello
5+
// CHECK-SAME: %[[ARG0:.*]]: f32
6+
func.func @hello(%arg0 : f32) {
7+
%tid_x = gpu.thread_id x
8+
%csti8 = arith.constant 2 : i8
9+
gpu.printf "Hello from %lld, %d, %f\n" %tid_x, %csti8, %arg0 : index, i8, f32
10+
return
11+
}
12+
// CHECK-LABEL: @hello_indirect
13+
gpu.func @hello_indirect() kernel {
14+
%cstf32 = arith.constant 3.0 : f32
15+
// CHECK: %[[DEVICE_FUNC_ADDR:.*]] = llvm.mlir.addressof @hello : !llvm.ptr
16+
%func_ref = func.constant @hello : (f32) -> ()
17+
// CHECK: llvm.call %[[DEVICE_FUNC_ADDR]](%{{.*}}) : !llvm.ptr, (f32) -> ()
18+
func.call_indirect %func_ref(%cstf32) : (f32) -> ()
19+
gpu.return
20+
}
21+
}

0 commit comments

Comments
 (0)