Skip to content

Commit 82fd970

Browse files
sndmitrievbader
authored andcommitted
[SYCL] Rename sycl target image registration functions (#1048)
To avoid conflict with OpenMP registration functions. Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent 2a000d9 commit 82fd970

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

clang/test/Driver/clang-offload-wrapper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@
120120
// CHECK-IR: declare void @__tgt_unregister_lib([[DESCTY]]*)
121121

122122
// CHECK-IR: define internal void [[SYCL_REGFN]]()
123-
// CHECK-IR: call void @__tgt_register_lib([[DESCTY]]* bitcast ([[SYCL_DESCTY]]* [[SYCL_DESC]] to [[DESCTY]]*))
123+
// CHECK-IR: call void @__sycl_register_lib([[SYCL_DESCTY]]* [[SYCL_DESC]])
124124
// CHECK-IR: ret void
125125

126+
// CHECK-IR: declare void @__sycl_register_lib([[SYCL_DESCTY]]*)
127+
126128
// CHECK-IR: define internal void [[SYCL_UNREGFN]]()
127-
// CHECK-IR: call void @__tgt_unregister_lib([[DESCTY]]* bitcast ([[SYCL_DESCTY]]* [[SYCL_DESC]] to [[DESCTY]]*))
129+
// CHECK-IR: call void @__sycl_unregister_lib([[SYCL_DESCTY]]* [[SYCL_DESC]])
128130
// CHECK-IR: ret void
129131

132+
// CHECK-IR: declare void @__sycl_unregister_lib([[SYCL_DESCTY]]*)
133+
130134
// -------
131135
// Check options' effects: -emit-reg-funcs, -desc-name
132136
//

clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -756,15 +756,18 @@ class BinaryWrapper {
756756
Func->setSection(".text.startup");
757757

758758
// Get RegFuncName function declaration.
759-
auto *RegFuncTy = FunctionType::get(Type::getVoidTy(C), getBinDescPtrTy(),
760-
/*isVarArg*/ false);
759+
auto *RegFuncTy = FunctionType::get(
760+
Type::getVoidTy(C),
761+
Kind == OffloadKind::SYCL ? getSyclBinDescPtrTy() : getBinDescPtrTy(),
762+
/*isVarArg=*/false);
761763
FunctionCallee RegFuncC =
762-
M.getOrInsertFunction("__tgt_register_lib", RegFuncTy);
764+
M.getOrInsertFunction(Kind == OffloadKind::SYCL ? "__sycl_register_lib"
765+
: "__tgt_register_lib",
766+
RegFuncTy);
763767

764768
// Construct function body
765769
IRBuilder<> Builder(BasicBlock::Create(C, "entry", Func));
766-
Builder.CreateCall(RegFuncC,
767-
Builder.CreatePointerCast(BinDesc, getBinDescPtrTy()));
770+
Builder.CreateCall(RegFuncC, BinDesc);
768771
Builder.CreateRetVoid();
769772

770773
// Add this function to constructors.
@@ -779,15 +782,18 @@ class BinaryWrapper {
779782
Func->setSection(".text.startup");
780783

781784
// Get UnregFuncName function declaration.
782-
auto *UnRegFuncTy = FunctionType::get(Type::getVoidTy(C), getBinDescPtrTy(),
783-
/*isVarArg*/ false);
784-
FunctionCallee UnRegFuncC =
785-
M.getOrInsertFunction("__tgt_unregister_lib", UnRegFuncTy);
785+
auto *UnRegFuncTy = FunctionType::get(
786+
Type::getVoidTy(C),
787+
Kind == OffloadKind::SYCL ? getSyclBinDescPtrTy() : getBinDescPtrTy(),
788+
/*isVarArg=*/false);
789+
FunctionCallee UnRegFuncC = M.getOrInsertFunction(
790+
Kind == OffloadKind::SYCL ? "__sycl_unregister_lib"
791+
: "__tgt_unregister_lib",
792+
UnRegFuncTy);
786793

787794
// Construct function body
788795
IRBuilder<> Builder(BasicBlock::Create(C, "entry", Func));
789-
Builder.CreateCall(UnRegFuncC,
790-
Builder.CreatePointerCast(BinDesc, getBinDescPtrTy()));
796+
Builder.CreateCall(UnRegFuncC, BinDesc);
791797
Builder.CreateRetVoid();
792798

793799
// Add this function to global destructors.

sycl/include/CL/sycl/detail/program_manager/program_manager.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
/// Executed as a part of current module's (.exe, .dll) static initialization.
2222
/// Registers device executable images with the runtime.
23-
extern "C" void __tgt_register_lib(pi_device_binaries desc);
23+
extern "C" void __sycl_register_lib(pi_device_binaries desc);
2424

2525
/// Executed as a part of current module's (.exe, .dll) static
2626
/// de-initialization.
2727
/// Unregisters device executable images with the runtime.
28-
extern "C" void __tgt_unregister_lib(pi_device_binaries desc);
28+
extern "C" void __sycl_unregister_lib(pi_device_binaries desc);
2929

3030
// +++ }
3131

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,11 @@ void ProgramManager::dumpImage(const DeviceImage &Img, KernelSetId KSId) const {
831831
} // namespace sycl
832832
} // namespace cl
833833

834-
extern "C" void __tgt_register_lib(pi_device_binaries desc) {
834+
extern "C" void __sycl_register_lib(pi_device_binaries desc) {
835835
cl::sycl::detail::ProgramManager::getInstance().addImages(desc);
836836
}
837837

838838
// Executed as a part of current module's (.exe, .dll) static initialization
839-
extern "C" void __tgt_unregister_lib(pi_device_binaries desc) {
839+
extern "C" void __sycl_unregister_lib(pi_device_binaries desc) {
840840
// TODO implement the function
841841
}

sycl/source/ld-version-script.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
_Z20__spirv_ocl_prefetch*;
2525

2626
/* Export offload image hooks */
27-
__tgt_register_lib;
28-
__tgt_unregister_lib;
27+
__sycl_register_lib;
28+
__sycl_unregister_lib;
2929

3030
local:
3131
*;

0 commit comments

Comments
 (0)