[llvm] 095c48f - [AMDGPU] Use "hostcall" module flag instead of searching for ockl_hostcall_internal() declaration.
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 5 06:56:22 PDT 2021
Author: kpyzhov
Date: 2021-10-05T09:56:04-04:00
New Revision: 095c48fdf3d27a4f346f8680d1d7e89449bb557b
URL: https://github.com/llvm/llvm-project/commit/095c48fdf3d27a4f346f8680d1d7e89449bb557b
DIFF: https://github.com/llvm/llvm-project/commit/095c48fdf3d27a4f346f8680d1d7e89449bb557b.diff
LOG: [AMDGPU] Use "hostcall" module flag instead of searching for ockl_hostcall_internal() declaration.
The current way to detect hostcalls by looking for "ockl_hostcall_internal()" function in the module seems to be not reliable enough. The LTO may rename the "ockl_hostcall_internal()" function when an application is compiled with "-fgpu-rdc", and MetadataStreamer pass to fail to detect hostcalls, therefore it does not set the "hidden_hostcall_buffer" kernel argument.
This change adds a new module flag: hostcall that can be used to detect whether GPU functions use host calls for printf.
Differential revision: https://reviews.llvm.org/D110337
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp b/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
index a50093f5bb08..cc9d68c20012 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
@@ -798,7 +798,8 @@ void MetadataStreamerV3::emitHiddenKernelArgs(const Function &Func,
if (!HiddenArgNumBytes)
return;
- auto &DL = Func.getParent()->getDataLayout();
+ const Module *M = Func.getParent();
+ auto &DL = M->getDataLayout();
auto Int64Ty = Type::getInt64Ty(Func.getContext());
if (HiddenArgNumBytes >= 8)
@@ -814,16 +815,16 @@ void MetadataStreamerV3::emitHiddenKernelArgs(const Function &Func,
auto Int8PtrTy =
Type::getInt8PtrTy(Func.getContext(), AMDGPUAS::GLOBAL_ADDRESS);
- // Emit "printf buffer" argument if printf is used, otherwise emit dummy
- // "none" argument.
+ // Emit "printf buffer" argument if printf is used, emit "hostcall buffer"
+ // if "hostcall" module flag is set, otherwise emit dummy "none" argument.
if (HiddenArgNumBytes >= 32) {
- if (Func.getParent()->getNamedMetadata("llvm.printf.fmts"))
+ if (M->getNamedMetadata("llvm.printf.fmts"))
emitKernelArg(DL, Int8PtrTy, Align(8), "hidden_printf_buffer", Offset,
Args);
- else if (Func.getParent()->getFunction("__ockl_hostcall_internal")) {
+ else if (M->getModuleFlag("amdgpu_hostcall")) {
// The printf runtime binding pass should have ensured that hostcall and
// printf are not used in the same module.
- assert(!Func.getParent()->getNamedMetadata("llvm.printf.fmts"));
+ assert(!M->getNamedMetadata("llvm.printf.fmts"));
emitKernelArg(DL, Int8PtrTy, Align(8), "hidden_hostcall_buffer", Offset,
Args);
} else
diff --git a/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp b/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
index 8cd16ca3906f..a0d655320988 100644
--- a/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
+++ b/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
@@ -63,6 +63,7 @@ static Value *callPrintfBegin(IRBuilder<> &Builder, Value *Version) {
auto Int64Ty = Builder.getInt64Ty();
auto M = Builder.GetInsertBlock()->getModule();
auto Fn = M->getOrInsertFunction("__ockl_printf_begin", Int64Ty, Int64Ty);
+ M->addModuleFlag(llvm::Module::Override, "amdgpu_hostcall", 1);
return Builder.CreateCall(Fn, Version);
}
diff --git a/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3.ll b/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3.ll
index 11123e0624f3..15186b389c8b 100644
--- a/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3.ll
+++ b/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3.ll
@@ -29,8 +29,6 @@
; CHECK: .name: test_kernel
; CHECK: .symbol: test_kernel.kd
-declare <2 x i64> @__ockl_hostcall_internal(i8*, i32, i64, i64, i64, i64, i64, i64, i64, i64)
-
define amdgpu_kernel void @test_kernel(i8 %a) #0
!kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3
!kernel_arg_base_type !3 !kernel_arg_type_qual !4 {
@@ -51,4 +49,7 @@ attributes #0 = { "amdgpu-implicitarg-num-bytes"="48" }
!opencl.ocl.version = !{!90}
!90 = !{i32 2, i32 0}
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"amdgpu_hostcall", i32 1}
+
; PARSER: AMDGPU HSA Metadata Parser Test: PASS
More information about the llvm-commits
mailing list