[clang] fca49fe - [clang-offload-wrapper] Lower priority of __tgt_register_lib in favor of __tgt_register_requires
George Rokos via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 3 12:32:02 PST 2020
Author: George Rokos
Date: 2020-03-03T12:31:40-08:00
New Revision: fca49fe8e34f13632c42e68aad4b14e3e00bdcc8
URL: https://github.com/llvm/llvm-project/commit/fca49fe8e34f13632c42e68aad4b14e3e00bdcc8
DIFF: https://github.com/llvm/llvm-project/commit/fca49fe8e34f13632c42e68aad4b14e3e00bdcc8.diff
LOG: [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
Added:
Modified:
clang/test/Driver/clang-offload-wrapper.c
clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
Removed:
################################################################################
diff --git a/clang/test/Driver/clang-offload-wrapper.c b/clang/test/Driver/clang-offload-wrapper.c
index c8c17bd8a514..9a36559e34dd 100644
--- a/clang/test/Driver/clang-offload-wrapper.c
+++ b/clang/test/Driver/clang-offload-wrapper.c
@@ -39,8 +39,8 @@
// 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]] }
-// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* [[REGFN:@.+]], i8* null }]
-// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* [[UNREGFN:@.+]], i8* null }]
+// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* [[REGFN:@.+]], i8* null }]
+// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* [[UNREGFN:@.+]], i8* null }]
// CHECK-IR: define internal void [[REGFN]]()
// CHECK-IR: call void @__tgt_register_lib([[DESCTY]]* [[DESC]])
diff --git a/clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp b/clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
index c3863422adf6..78d96539f47e 100644
--- a/clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
+++ b/clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
@@ -262,7 +262,12 @@ class BinaryWrapper {
Builder.CreateRetVoid();
// Add this function to constructors.
- appendToGlobalCtors(M, Func, 0);
+ // Set priority to 1 so that __tgt_register_lib is executed AFTER
+ // __tgt_register_requires (we want to know what requirements have been
+ // asked for before we load a libomptarget plugin so that by the time the
+ // plugin is loaded it can report how many devices there are which can
+ // satisfy these requirements).
+ appendToGlobalCtors(M, Func, /*Priority*/ 1);
}
void createUnregisterFunction(GlobalVariable *BinDesc) {
@@ -283,7 +288,8 @@ class BinaryWrapper {
Builder.CreateRetVoid();
// Add this function to global destructors.
- appendToGlobalDtors(M, Func, 0);
+ // Match priority of __tgt_register_lib
+ appendToGlobalDtors(M, Func, /*Priority*/ 1);
}
public:
More information about the cfe-commits
mailing list