From 432603d94f05f7b0efea0cb35f41ff69c793efba Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Tue, 21 May 2019 18:20:08 +0000 Subject: [PATCH] [OPENMP]Use the attributes for dso locality when building for device. Currently, we ignore all dso locality attributes/info when building for the device and thus all symblos are externally visible and can be preemted at the runtime. It may lead to incorrect results. We need to follow the same logic, compiler uses for static/pie builds. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361283 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 2 +- test/OpenMP/declare_target_codegen.cpp | 12 ++++++------ test/OpenMP/nvptx_allocate_codegen.cpp | 12 ++++++------ ...vptx_declare_target_var_ctor_dtor_codegen.cpp | 16 ++++++++-------- test/OpenMP/nvptx_target_codegen.cpp | 2 +- test/OpenMP/nvptx_unsupported_type_codegen.cpp | 12 ++++++------ 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index e592442e6b..f062f83425 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -798,7 +798,7 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM, const auto &CGOpts = CGM.getCodeGenOpts(); llvm::Reloc::Model RM = CGOpts.RelocationModel; const auto &LOpts = CGM.getLangOpts(); - if (RM != llvm::Reloc::Static && !LOpts.PIE) + if (RM != llvm::Reloc::Static && !LOpts.PIE && !LOpts.OpenMPIsDevice) return false; // A definition cannot be preempted from an executable. diff --git a/test/OpenMP/declare_target_codegen.cpp b/test/OpenMP/declare_target_codegen.cpp index 933af34d84..d4b209ff05 100644 --- a/test/OpenMP/declare_target_codegen.cpp +++ b/test/OpenMP/declare_target_codegen.cpp @@ -16,22 +16,22 @@ // CHECK-DAG: Bake // CHECK-NOT: @{{hhh|ggg|fff|eee}} = // CHECK-DAG: @aaa = external global i32, -// CHECK-DAG: @bbb = global i32 0, +// CHECK-DAG: @bbb ={{ dso_local | }}global i32 0, // CHECK-DAG: weak constant %struct.__tgt_offload_entry { i8* bitcast (i32* @bbb to i8*), // CHECK-DAG: @ccc = external global i32, -// CHECK-DAG: @ddd = global i32 0, +// CHECK-DAG: @ddd ={{ dso_local | }}global i32 0, // CHECK-DAG: @hhh_decl_tgt_link_ptr = common global i32* null // CHECK-DAG: @ggg_decl_tgt_link_ptr = common global i32* null // CHECK-DAG: @fff_decl_tgt_link_ptr = common global i32* null // CHECK-DAG: @eee_decl_tgt_link_ptr = common global i32* null // CHECK-DAG: @{{.*}}maini1{{.*}}aaa = internal global i64 23, -// CHECK-DAG: @b = global i32 15, -// CHECK-DAG: @d = global i32 0, +// CHECK-DAG: @b ={{ dso_local | }}global i32 15, +// CHECK-DAG: @d ={{ dso_local | }}global i32 0, // CHECK-DAG: @c = external global i32, -// CHECK-DAG: @globals = global %struct.S zeroinitializer, +// CHECK-DAG: @globals ={{ dso_local | }}global %struct.S zeroinitializer, // CHECK-DAG: [[STAT:@.+stat]] = internal global %struct.S zeroinitializer, // CHECK-DAG: [[STAT_REF:@.+]] = internal constant %struct.S* [[STAT]] -// CHECK-DAG: @out_decl_target = global i32 0, +// CHECK-DAG: @out_decl_target ={{ dso_local | }}global i32 0, // CHECK-DAG: @llvm.used = appending global [6 x i8*] [i8* bitcast (void ()* @__omp_offloading__{{.+}}_globals_l[[@LINE+80]]_ctor to i8*), i8* bitcast (void ()* @__omp_offloading__{{.+}}_stat_l[[@LINE+81]]_ctor to i8*), // CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (%struct.S** [[STAT_REF]] to i8*)], diff --git a/test/OpenMP/nvptx_allocate_codegen.cpp b/test/OpenMP/nvptx_allocate_codegen.cpp index 1214845a42..647bc1d96e 100644 --- a/test/OpenMP/nvptx_allocate_codegen.cpp +++ b/test/OpenMP/nvptx_allocate_codegen.cpp @@ -17,11 +17,11 @@ extern const omp_allocator_handle_t omp_pteam_mem_alloc; extern const omp_allocator_handle_t omp_thread_mem_alloc; // CHECK-DAG: @{{.+}}St1{{.+}}b{{.+}} = external global i32, -// CHECK-DAG: @a = global i32 0, -// CHECK-DAG: @b = addrspace(4) global i32 0, -// CHECK-DAG: @c = global i32 0, -// CHECK-DAG: @d = global %struct.St1 zeroinitializer, -// CHECK-DAG: @{{.+}}ns{{.+}}a{{.+}} = addrspace(3) global i32 0, +// CHECK-DAG: @a ={{ dso_local | }}global i32 0, +// CHECK-DAG: @b ={{ dso_local | }}addrspace(4) global i32 0, +// CHECK-DAG: @c ={{ dso_local | }}global i32 0, +// CHECK-DAG: @d ={{ dso_local | }}global %struct.St1 zeroinitializer, +// CHECK-DAG: @{{.+}}ns{{.+}}a{{.+}} ={{ dso_local | }}addrspace(3) global i32 0, // CHECK-DAG: @{{.+}}main{{.+}}a{{.*}} = internal global i32 0, // CHECK-DAG: @{{.+}}ST{{.+}}m{{.+}} = external global i32, // CHECK-DAG: @bar_c = internal global i32 0, @@ -79,7 +79,7 @@ extern template int ST::m; void baz(float &); -// CHECK: define void @{{.+}}bar{{.+}}() +// CHECK: define{{ dso_local | }}void @{{.+}}bar{{.+}}() void bar() { // CHECK: alloca float, float bar_a; diff --git a/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp b/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp index b9049a4028..03520e17a6 100644 --- a/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp +++ b/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp @@ -16,9 +16,9 @@ // SIMD-ONLY-NOT: {{__kmpc|__tgt}} // DEVICE-DAG: [[C_ADDR:.+]] = internal global i32 0, -// DEVICE-DAG: [[CD_ADDR:@.+]] = global %struct.S zeroinitializer, +// DEVICE-DAG: [[CD_ADDR:@.+]] ={{ dso_local | }}global %struct.S zeroinitializer, // HOST-DAG: @[[C_ADDR:.+]] = internal global i32 0, -// HOST-DAG: @[[CD_ADDR:.+]] = global %struct.S zeroinitializer, +// HOST-DAG: @[[CD_ADDR:.+]] ={{ dso_local | }}global %struct.S zeroinitializer, #pragma omp declare target int foo() { return 0; } @@ -34,12 +34,12 @@ int car() { return 0; } #pragma omp declare target (bar) int caz() { return 0; } -// DEVICE-DAG: define i32 [[FOO:@.*foo.*]]() -// DEVICE-DAG: define i32 [[BAR:@.*bar.*]]() -// DEVICE-DAG: define i32 [[BAZ:@.*baz.*]]() -// DEVICE-DAG: define i32 [[DOO:@.*doo.*]]() -// DEVICE-DAG: define i32 [[CAR:@.*car.*]]() -// DEVICE-DAG: define i32 [[CAZ:@.*caz.*]]() +// DEVICE-DAG: define{{ dso_local | }}i32 [[FOO:@.*foo.*]]() +// DEVICE-DAG: define{{ dso_local | }}i32 [[BAR:@.*bar.*]]() +// DEVICE-DAG: define{{ dso_local | }}i32 [[BAZ:@.*baz.*]]() +// DEVICE-DAG: define{{ dso_local | }}i32 [[DOO:@.*doo.*]]() +// DEVICE-DAG: define{{ dso_local | }}i32 [[CAR:@.*car.*]]() +// DEVICE-DAG: define{{ dso_local | }}i32 [[CAZ:@.*caz.*]]() static int c = foo() + bar() + baz(); #pragma omp declare target (c) diff --git a/test/OpenMP/nvptx_target_codegen.cpp b/test/OpenMP/nvptx_target_codegen.cpp index 85c85a3078..84ff991006 100644 --- a/test/OpenMP/nvptx_target_codegen.cpp +++ b/test/OpenMP/nvptx_target_codegen.cpp @@ -573,7 +573,7 @@ int baz(int f, double &a) { // CHECK: [[EXIT]] // CHECK: ret void - // CHECK: define i32 [[BAZ]](i32 [[F:%.*]], double* dereferenceable{{.*}}) + // CHECK: define{{ dso_local | }}i32 [[BAZ]](i32 [[F:%.*]], double* dereferenceable{{.*}}) // CHECK: alloca i32, // CHECK: [[LOCAL_F_PTR:%.+]] = alloca i32, // CHECK: [[ZERO_ADDR:%.+]] = alloca i32, diff --git a/test/OpenMP/nvptx_unsupported_type_codegen.cpp b/test/OpenMP/nvptx_unsupported_type_codegen.cpp index 61accc3c72..e3a4cd3703 100644 --- a/test/OpenMP/nvptx_unsupported_type_codegen.cpp +++ b/test/OpenMP/nvptx_unsupported_type_codegen.cpp @@ -26,18 +26,18 @@ struct T1 { #pragma omp declare target T a = T(); T f = a; -// CHECK: define void @{{.+}}foo{{.+}}([[T]]* byval align {{.+}}) +// CHECK: define{{ dso_local | }}void @{{.+}}foo{{.+}}([[T]]* byval align {{.+}}) void foo(T a = T()) { return; } -// CHECK: define [6 x i64] @{{.+}}bar{{.+}}() +// CHECK: define{{ dso_local | }}[6 x i64] @{{.+}}bar{{.+}}() T bar() { // CHECK: bitcast [[T]]* %{{.+}} to [6 x i64]* // CHECK-NEXT: load [6 x i64], [6 x i64]* %{{.+}}, // CHECK-NEXT: ret [6 x i64] return T(); } -// CHECK: define void @{{.+}}baz{{.+}}() +// CHECK: define{{ dso_local | }}void @{{.+}}baz{{.+}}() void baz() { // CHECK: call [6 x i64] @{{.+}}bar{{.+}}() // CHECK-NEXT: bitcast [[T]]* %{{.+}} to [6 x i64]* @@ -46,17 +46,17 @@ void baz() { } T1 a1 = T1(); T1 f1 = a1; -// CHECK: define void @{{.+}}foo1{{.+}}([[T1]]* byval align {{.+}}) +// CHECK: define{{ dso_local | }}void @{{.+}}foo1{{.+}}([[T1]]* byval align {{.+}}) void foo1(T1 a = T1()) { return; } -// CHECK: define [[T1]] @{{.+}}bar1{{.+}}() +// CHECK: define{{ dso_local | }}[[T1]] @{{.+}}bar1{{.+}}() T1 bar1() { // CHECK: load [[T1]], [[T1]]* // CHECK-NEXT: ret [[T1]] return T1(); } -// CHECK: define void @{{.+}}baz1{{.+}}() +// CHECK: define{{ dso_local | }}void @{{.+}}baz1{{.+}}() void baz1() { // CHECK: call [[T1]] @{{.+}}bar1{{.+}}() T1 t = bar1(); -- 2.40.0