Skip to content

Commit e4903d8

Browse files
committedApr 9, 2022
[CUDA/HIP] Remove argument from module ctor/dtor signatures
In theory, constructors can take arguments when called via .init_array where at least glibc passes in (argc, argv, envp). This isn't used in the generated code and if it was, the first argument should be an integer, not a pointer. For destructors registered via atexit, the function should never take an argument. Differential Revision: https://reviews.llvm.org/D123370
1 parent f49a763 commit e4903d8

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed
 

‎clang/lib/CodeGen/CGCUDANV.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,15 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
659659
///
660660
/// For CUDA:
661661
/// \code
662-
/// void __cuda_module_ctor(void*) {
662+
/// void __cuda_module_ctor() {
663663
/// Handle = __cudaRegisterFatBinary(GpuBinaryBlob);
664664
/// __cuda_register_globals(Handle);
665665
/// }
666666
/// \endcode
667667
///
668668
/// For HIP:
669669
/// \code
670-
/// void __hip_module_ctor(void*) {
670+
/// void __hip_module_ctor() {
671671
/// if (__hip_gpubin_handle == 0) {
672672
/// __hip_gpubin_handle = __hipRegisterFatBinary(GpuBinaryBlob);
673673
/// __hip_register_globals(__hip_gpubin_handle);
@@ -717,7 +717,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
717717
}
718718

719719
llvm::Function *ModuleCtorFunc = llvm::Function::Create(
720-
llvm::FunctionType::get(VoidTy, VoidPtrTy, false),
720+
llvm::FunctionType::get(VoidTy, false),
721721
llvm::GlobalValue::InternalLinkage,
722722
addUnderscoredPrefixToName("_module_ctor"), &TheModule);
723723
llvm::BasicBlock *CtorEntryBB =
@@ -931,14 +931,14 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
931931
///
932932
/// For CUDA:
933933
/// \code
934-
/// void __cuda_module_dtor(void*) {
934+
/// void __cuda_module_dtor() {
935935
/// __cudaUnregisterFatBinary(Handle);
936936
/// }
937937
/// \endcode
938938
///
939939
/// For HIP:
940940
/// \code
941-
/// void __hip_module_dtor(void*) {
941+
/// void __hip_module_dtor() {
942942
/// if (__hip_gpubin_handle) {
943943
/// __hipUnregisterFatBinary(__hip_gpubin_handle);
944944
/// __hip_gpubin_handle = 0;
@@ -956,7 +956,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleDtorFunction() {
956956
addUnderscoredPrefixToName("UnregisterFatBinary"));
957957

958958
llvm::Function *ModuleDtorFunc = llvm::Function::Create(
959-
llvm::FunctionType::get(VoidTy, VoidPtrTy, false),
959+
llvm::FunctionType::get(VoidTy, false),
960960
llvm::GlobalValue::InternalLinkage,
961961
addUnderscoredPrefixToName("_module_dtor"), &TheModule);
962962

‎clang/test/CodeGenCUDA/device-stub.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ void hostfunc(void) { kernelfunc<<<1, 1>>>(1, 1, 1); }
257257
// CUDANORDC-NEXT: call void @__[[PREFIX]]_register_globals
258258
// HIP-NEXT: call void @__[[PREFIX]]_register_globals
259259
// * In separate mode we also register a destructor.
260-
// CUDANORDC-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
261-
// HIP-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
260+
// CUDANORDC-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
261+
// HIP-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
262262

263263
// With relocatable device code we call __[[PREFIX]]RegisterLinkedBinary%NVModuleID%
264264
// CUDARDC: call{{.*}}__[[PREFIX]]RegisterLinkedBinary[[MODULE_ID]](

0 commit comments

Comments
 (0)
Please sign in to comment.