Skip to content

Commit 069e8bc

Browse files
authored
[OpenMP][libc] Remove special handling for OpenMP printf (#98940)
Summary: Currently there are several layers to handle `printf`. Since we now have varargs and an implementation of `printf` this can be heavily simplified. 1. The frontend renames `printf` into `omp_vprintf` and gives it an argument buffer. Removing 1. triggered some code in the AMDGPU backend menat for HIP / OpenCL, so I hadded an exception to it. 2. Forward this to CUDA vprintf or ignore it. We no longer need special handling for it since we have varargs. So now we just forward this to CUDA vprintf if we have libc, otherwise just leave `printf` as an external function and expect that `libc` will be linked in.
1 parent 26d9282 commit 069e8bc

File tree

11 files changed

+16
-183
lines changed

11 files changed

+16
-183
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5986,8 +5986,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
59865986
getTarget().getTriple().isAMDGCN() ||
59875987
(getTarget().getTriple().isSPIRV() &&
59885988
getTarget().getTriple().getVendor() == Triple::VendorType::AMD)) {
5989-
if (getLangOpts().OpenMPIsTargetDevice)
5990-
return EmitOpenMPDevicePrintfCallExpr(E);
59915989
if (getTarget().getTriple().isNVPTX())
59925990
return EmitNVPTXDevicePrintfCallExpr(E);
59935991
if ((getTarget().getTriple().isAMDGCN() ||

clang/lib/CodeGen/CGGPUBuiltin.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,6 @@ llvm::Function *GetVprintfDeclaration(llvm::Module &M) {
4242
VprintfFuncType, llvm::GlobalVariable::ExternalLinkage, "vprintf", &M);
4343
}
4444

45-
llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule &CGM) {
46-
const char *Name = "__llvm_omp_vprintf";
47-
llvm::Module &M = CGM.getModule();
48-
llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
49-
llvm::PointerType::getUnqual(M.getContext()),
50-
llvm::Type::getInt32Ty(M.getContext())};
51-
llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
52-
llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
53-
54-
if (auto *F = M.getFunction(Name)) {
55-
if (F->getFunctionType() != VprintfFuncType) {
56-
CGM.Error(SourceLocation(),
57-
"Invalid type declaration for __llvm_omp_vprintf");
58-
return nullptr;
59-
}
60-
return F;
61-
}
62-
63-
return llvm::Function::Create(
64-
VprintfFuncType, llvm::GlobalVariable::ExternalLinkage, Name, &M);
65-
}
66-
6745
// Transforms a call to printf into a call to the NVPTX vprintf syscall (which
6846
// isn't particularly special; it's invoked just like a regular function).
6947
// vprintf takes two args: A format string, and a pointer to a buffer containing
@@ -213,10 +191,3 @@ RValue CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E) {
213191
Builder.SetInsertPoint(IRB.GetInsertBlock(), IRB.GetInsertPoint());
214192
return RValue::get(Printf);
215193
}
216-
217-
RValue CodeGenFunction::EmitOpenMPDevicePrintfCallExpr(const CallExpr *E) {
218-
assert(getTarget().getTriple().isNVPTX() ||
219-
getTarget().getTriple().isAMDGCN());
220-
return EmitDevicePrintfCallExpr(E, this, GetOpenMPVprintfDeclaration(CGM),
221-
true);
222-
}

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4536,7 +4536,6 @@ class CodeGenFunction : public CodeGenTypeCache {
45364536

45374537
RValue EmitNVPTXDevicePrintfCallExpr(const CallExpr *E);
45384538
RValue EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E);
4539-
RValue EmitOpenMPDevicePrintfCallExpr(const CallExpr *E);
45404539

45414540
RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
45424541
const CallExpr *E, ReturnValueSlot ReturnValue);

libc/config/gpu/entrypoints.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ set(TARGET_LIBC_ENTRYPOINTS
226226

227227
# gpu/rpc.h entrypoints
228228
libc.src.gpu.rpc_host_call
229-
libc.src.gpu.rpc_fprintf
230229
)
231230

232231
set(TARGET_LIBM_ENTRYPOINTS

libc/spec/gpu_ext.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ def GPUExtensions : StandardSpec<"GPUExtensions"> {
1010
RetValSpec<VoidType>,
1111
[ArgSpec<VoidPtr>, ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
1212
>,
13-
FunctionSpec<
14-
"rpc_fprintf",
15-
RetValSpec<IntType>,
16-
[ArgSpec<FILERestrictedPtr>,
17-
ArgSpec<ConstCharRestrictedPtr>,
18-
ArgSpec<VoidPtr>,
19-
ArgSpec<SizeTType>]
20-
>,
2113
]
2214
>;
2315
let Headers = [

libc/src/gpu/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,3 @@ add_entrypoint_object(
88
libc.src.__support.RPC.rpc_client
99
libc.src.__support.GPU.utils
1010
)
11-
12-
add_entrypoint_object(
13-
rpc_fprintf
14-
SRCS
15-
rpc_fprintf.cpp
16-
HDRS
17-
rpc_fprintf.h
18-
DEPENDS
19-
libc.src.stdio.gpu.gpu_file
20-
libc.src.__support.RPC.rpc_client
21-
libc.src.__support.GPU.utils
22-
)

libc/src/gpu/rpc_fprintf.cpp

Lines changed: 0 additions & 75 deletions
This file was deleted.

libc/src/gpu/rpc_fprintf.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ bool AMDGPUPrintfRuntimeBindingImpl::run(Module &M) {
437437
return false;
438438

439439
auto PrintfFunction = M.getFunction("printf");
440-
if (!PrintfFunction || !PrintfFunction->isDeclaration())
440+
if (!PrintfFunction || !PrintfFunction->isDeclaration() ||
441+
M.getModuleFlag("openmp"))
441442
return false;
442443

443444
for (auto &U : PrintfFunction->uses()) {

offload/DeviceRTL/include/LibC.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern "C" {
1818

1919
int memcmp(const void *lhs, const void *rhs, size_t count);
2020
void memset(void *dst, int C, size_t count);
21-
2221
int printf(const char *format, ...);
2322
}
2423

0 commit comments

Comments
 (0)