Skip to content

Commit fca49fe

Browse files
author
George Rokos
committed
[clang-offload-wrapper] Lower priority of __tgt_register_lib in favor of __tgt_register_requires
Lower priority of __tgt_register_lib in order to make sure that __tgt_register_requires is called before loading a libomptarget plugin. We want to know beforehand which requirements the user has asked for so that upon loading the plugin libomptarget can report how many devices there are that can satisfy these requirements. Differential Revision: https://reviews.llvm.org/D75223
1 parent 8fc3e5c commit fca49fe

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939

4040
// CHECK-IR: [[DESC:@.+]] = internal constant [[DESCTY]] { i32 1, [[IMAGETY]]* getelementptr inbounds ([1 x [[IMAGETY]]], [1 x [[IMAGETY]]]* [[IMAGES]], i64 0, i64 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }
4141

42-
// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* [[REGFN:@.+]], i8* null }]
43-
// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* [[UNREGFN:@.+]], i8* null }]
42+
// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* [[REGFN:@.+]], i8* null }]
43+
// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* [[UNREGFN:@.+]], i8* null }]
4444

4545
// CHECK-IR: define internal void [[REGFN]]()
4646
// CHECK-IR: call void @__tgt_register_lib([[DESCTY]]* [[DESC]])

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,12 @@ class BinaryWrapper {
262262
Builder.CreateRetVoid();
263263

264264
// Add this function to constructors.
265-
appendToGlobalCtors(M, Func, 0);
265+
// Set priority to 1 so that __tgt_register_lib is executed AFTER
266+
// __tgt_register_requires (we want to know what requirements have been
267+
// asked for before we load a libomptarget plugin so that by the time the
268+
// plugin is loaded it can report how many devices there are which can
269+
// satisfy these requirements).
270+
appendToGlobalCtors(M, Func, /*Priority*/ 1);
266271
}
267272

268273
void createUnregisterFunction(GlobalVariable *BinDesc) {
@@ -283,7 +288,8 @@ class BinaryWrapper {
283288
Builder.CreateRetVoid();
284289

285290
// Add this function to global destructors.
286-
appendToGlobalDtors(M, Func, 0);
291+
// Match priority of __tgt_register_lib
292+
appendToGlobalDtors(M, Func, /*Priority*/ 1);
287293
}
288294

289295
public:

0 commit comments

Comments
 (0)