Skip to content

Commit 2945f11

Browse files
committed
[OpenMP] Only generate runtime flags with host input
This patch changes the code generation of runtime flags to only occur if a host bitcode file was passed in. This is a cheap way to determine if we are compiling the OpenMP device runtime itself or user code. This is needed because the global flags we generate for the device runtime e.g. __omp_rtl_debug_kind were being generated with default values when we compiled the runtime library. This would then invalidate the ones we want to be able to add in when the user defines it. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D118399
1 parent 1e3a021 commit 2945f11

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,8 @@ CGOpenMPRuntimeGPU::CGOpenMPRuntimeGPU(CodeGenModule &CGM)
11981198
llvm_unreachable("OpenMP can only handle device code.");
11991199

12001200
llvm::OpenMPIRBuilder &OMPBuilder = getOMPBuilder();
1201-
if (CGM.getLangOpts().OpenMPTargetNewRuntime) {
1201+
if (CGM.getLangOpts().OpenMPTargetNewRuntime &&
1202+
!CGM.getLangOpts().OMPHostIRFile.empty()) {
12021203
OMPBuilder.createGlobalFlag(CGM.getLangOpts().OpenMPTargetDebug,
12031204
"__omp_rtl_debug_kind");
12041205
OMPBuilder.createGlobalFlag(CGM.getLangOpts().OpenMPTeamSubscription,

clang/test/OpenMP/target_globals_codegen.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-target-new-runtime -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=CHECK-DEFAULT
77
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-target-new-runtime -fopenmp-assume-threads-oversubscription -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=CHECK-THREADS
88
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-target-new-runtime -fopenmp-assume-teams-oversubscription -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=CHECK-TEAMS
9+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-target-new-runtime -fopenmp-assume-teams-oversubscription -fopenmp-is-device -o - | FileCheck %s --check-prefix=CHECK-RUNTIME
910
// expected-no-diagnostics
1011

1112
#ifndef HEADER
@@ -32,6 +33,10 @@
3233
// CHECK-TEAMS: @__omp_rtl_assume_teams_oversubscription = weak_odr hidden constant i32 1
3334
// CHECK-TEAMS: @__omp_rtl_assume_threads_oversubscription = weak_odr hidden constant i32 0
3435
//.
36+
// CHECK-RUNTIME-NOT: @__omp_rtl_debug_kind = weak_odr hidden constant i32 0
37+
// CHECK-RUNTIME-NOT: @__omp_rtl_assume_teams_oversubscription = weak_odr hidden constant i32 1
38+
// CHECK-RUNTIME-NOT: @__omp_rtl_assume_threads_oversubscription = weak_odr hidden constant i32 0
39+
//.
3540
void foo() {
3641
#pragma omp target
3742
{ }

0 commit comments

Comments
 (0)