Index: lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- lib/CodeGen/CGOpenMPRuntime.cpp +++ lib/CodeGen/CGOpenMPRuntime.cpp @@ -2563,7 +2563,12 @@ SmallString<64> PtrName; { llvm::raw_svector_ostream OS(PtrName); - OS << CGM.getMangledName(GlobalDecl(VD)) << "_decl_tgt_ref_ptr"; + std::hash HashFn; + size_t hash = 0; + if (!CGM.getCodeGenOpts().MainFileName.empty()) + hash = HashFn(CGM.getCodeGenOpts().MainFileName); + OS << CGM.getMangledName(GlobalDecl(VD)) << "_" << \ + llvm::Twine(hash) << "_decl_tgt_ref_ptr"; } llvm::Value *Ptr = CGM.getModule().getNamedValue(PtrName); if (!Ptr) { Index: lib/Sema/SemaOpenMP.cpp =================================================================== --- lib/Sema/SemaOpenMP.cpp +++ lib/Sema/SemaOpenMP.cpp @@ -2621,9 +2621,12 @@ // Skip internally declared static variables. llvm::Optional Res = OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD); + bool IsUsingUnifiedMemory = + Stack->hasRequiresDeclWithClause(); if (VD->hasGlobalStorage() && CS && !CS->capturesVariable(VD) && - (Stack->hasRequiresDeclWithClause() || - !Res || *Res != OMPDeclareTargetDeclAttr::MT_Link)) + ((!IsUsingUnifiedMemory && + (!Res || *Res != OMPDeclareTargetDeclAttr::MT_Link)) || + (IsUsingUnifiedMemory && !Res))) return; SourceLocation ELoc = E->getExprLoc(); Index: test/OpenMP/declare_target_codegen.cpp =================================================================== --- test/OpenMP/declare_target_codegen.cpp +++ test/OpenMP/declare_target_codegen.cpp @@ -20,10 +20,10 @@ // CHECK-DAG: weak constant %struct.__tgt_offload_entry { i8* bitcast (i32* @bbb to i8*), // CHECK-DAG: @ccc = external global i32, // CHECK-DAG: @ddd ={{ dso_local | }}global i32 0, -// CHECK-DAG: @hhh_decl_tgt_ref_ptr = common global i32* null -// CHECK-DAG: @ggg_decl_tgt_ref_ptr = common global i32* null -// CHECK-DAG: @fff_decl_tgt_ref_ptr = common global i32* null -// CHECK-DAG: @eee_decl_tgt_ref_ptr = common global i32* null +// CHECK-DAG: @hhh_0_decl_tgt_ref_ptr = common global i32* null +// CHECK-DAG: @ggg_0_decl_tgt_ref_ptr = common global i32* null +// CHECK-DAG: @fff_0_decl_tgt_ref_ptr = common global i32* null +// CHECK-DAG: @eee_0_decl_tgt_ref_ptr = common global i32* null // CHECK-DAG: @{{.*}}maini1{{.*}}aaa = internal global i64 23, // CHECK-DAG: @b ={{ dso_local | }}global i32 15, // CHECK-DAG: @d ={{ dso_local | }}global i32 0, Index: test/OpenMP/declare_target_link_codegen.cpp =================================================================== --- test/OpenMP/declare_target_link_codegen.cpp +++ test/OpenMP/declare_target_link_codegen.cpp @@ -18,15 +18,15 @@ #define HEADER // HOST-DAG: @c = external global i32, -// HOST-DAG: @c_decl_tgt_ref_ptr = global i32* @c +// HOST-DAG: @c_0_decl_tgt_ref_ptr = global i32* @c // DEVICE-NOT: @c = -// DEVICE: @c_decl_tgt_ref_ptr = common global i32* null +// DEVICE: @c_0_decl_tgt_ref_ptr = common global i32* null // HOST: [[SIZES:@.+]] = private unnamed_addr constant [2 x i64] [i64 4, i64 4] // HOST: [[MAPTYPES:@.+]] = private unnamed_addr constant [2 x i64] [i64 35, i64 531] -// HOST: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_decl_tgt_ref_ptr\00" -// HOST: @.omp_offloading.entry.c_decl_tgt_ref_ptr = weak constant %struct.__tgt_offload_entry { i8* bitcast (i32** @c_decl_tgt_ref_ptr to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name, i32 0, i32 0), i64 8, i32 1, i32 0 }, section ".omp_offloading.entries", align 1 -// DEVICE-NOT: internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_decl_tgt_ref_ptr\00" -// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32** @c_decl_tgt_ref_ptr to i8*)] +// HOST: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_0_decl_tgt_ref_ptr\00" +// HOST: @.omp_offloading.entry.c_0_decl_tgt_ref_ptr = weak constant %struct.__tgt_offload_entry { i8* bitcast (i32** @c_0_decl_tgt_ref_ptr to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name, i32 0, i32 0), i64 8, i32 1, i32 0 }, section ".omp_offloading.entries", align 1 +// DEVICE-NOT: internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_0_decl_tgt_ref_ptr\00" +// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32** @c_0_decl_tgt_ref_ptr to i8*)] extern int c; #pragma omp declare target link(c) @@ -44,7 +44,7 @@ } // DEVICE: define weak void @__omp_offloading_{{.*}}_{{.*}}maini1{{.*}}_l[[@LINE-10]](i32* dereferenceable{{[^,]*}} -// DEVICE: [[C_REF:%.+]] = load i32*, i32** @c_decl_tgt_ref_ptr, +// DEVICE: [[C_REF:%.+]] = load i32*, i32** @c_0_decl_tgt_ref_ptr, // DEVICE: [[C:%.+]] = load i32, i32* [[C_REF]], // DEVICE: store i32 [[C]], i32* % @@ -55,7 +55,7 @@ // HOST: getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 // HOST: [[BP1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BASEPTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 // HOST: [[BP1_CAST:%.+]] = bitcast i8** [[BP1]] to i32*** -// HOST: store i32** @c_decl_tgt_ref_ptr, i32*** [[BP1_CAST]], +// HOST: store i32** @c_0_decl_tgt_ref_ptr, i32*** [[BP1_CAST]], // HOST: [[P1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 // HOST: [[P1_CAST:%.+]] = bitcast i8** [[P1]] to i32** // HOST: store i32* @c, i32** [[P1_CAST]], @@ -69,5 +69,5 @@ // HOST: [[C:%.*]] = load i32, i32* @c, // HOST: store i32 [[C]], i32* % -// CHECK: !{i32 1, !"c_decl_tgt_ref_ptr", i32 1, i32 {{[0-9]+}}} +// CHECK: !{i32 1, !"c_0_decl_tgt_ref_ptr", i32 1, i32 {{[0-9]+}}} #endif // HEADER Index: test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp =================================================================== --- test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp +++ test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp @@ -39,11 +39,11 @@ // CHECK-HOST: [[OFFLOAD_SIZES:@.+]] = private unnamed_addr constant [2 x i64] [i64 4, i64 8] // CHECK-HOST: [[OFFLOAD_MAPTYPES:@.+]] = private unnamed_addr constant [2 x i64] [i64 800, i64 800] -// CHECK-HOST: [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [21 x i8] -// CHECK-HOST: [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_LINK_PTR]] to i8*), i8* getelementptr inbounds ([21 x i8], [21 x i8]* [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 1, i32 0 }, section ".omp_offloading.entries" +// CHECK-HOST: [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [23 x i8] +// CHECK-HOST: [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_LINK_PTR]] to i8*), i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 1, i32 0 }, section ".omp_offloading.entries" -// CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [24 x i8] -// CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*), i8* getelementptr inbounds ([24 x i8], [24 x i8]* [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 0, i32 0 }, section ".omp_offloading.entries" +// CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [26 x i8] +// CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*), i8* getelementptr inbounds ([26 x i8], [26 x i8]* [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 0, i32 0 }, section ".omp_offloading.entries" // CHECK-HOST: @llvm.used = appending global [2 x i8*] [i8* bitcast (double** [[VAR_DECL_TGT_LINK_PTR]] to i8*), i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*)], section "llvm.metadata"