From 7b0baf3769febc656d3337330c739ab6913f65fb Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Thu, 29 Nov 2018 21:21:32 +0000 Subject: [PATCH] [OPENMP][NVPTX]Call get __kmpc_global_thread_num in worker after initialization. Function __kmpc_global_thread_num should be called only after initialization, not earlier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347919 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp | 4 ++++ test/OpenMP/nvptx_target_codegen.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp b/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp index d4b599eeff..2bc98f6178 100644 --- a/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp +++ b/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp @@ -1504,6 +1504,8 @@ void CGOpenMPRuntimeNVPTX::emitWorkerLoop(CodeGenFunction &CGF, // Signal start of parallel region. CGF.EmitBlock(ExecuteBB); + // Skip initialization. + setLocThreadIdInsertPt(CGF, /*AtCurrentPoint=*/true); // Process work items: outlined parallel functions. for (llvm::Function *W : Work) { @@ -1564,6 +1566,8 @@ void CGOpenMPRuntimeNVPTX::emitWorkerLoop(CodeGenFunction &CGF, // Exit target region. CGF.EmitBlock(ExitBB); + // Skip initialization. + clearLocThreadIdInsertPt(CGF); } /// Returns specified OpenMP runtime function for the current OpenMP diff --git a/test/OpenMP/nvptx_target_codegen.cpp b/test/OpenMP/nvptx_target_codegen.cpp index 4c17361e44..4f85be2f55 100644 --- a/test/OpenMP/nvptx_target_codegen.cpp +++ b/test/OpenMP/nvptx_target_codegen.cpp @@ -466,7 +466,6 @@ int baz(int f, double &a) { // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+S1.+l348}}_worker() // CHECK-DAG: [[OMP_EXEC_STATUS:%.+]] = alloca i8, // CHECK-DAG: [[OMP_WORK_FN:%.+]] = alloca i8*, - // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* [[NONSPMD]] // CHECK: store i8* null, i8** [[OMP_WORK_FN]], // CHECK: store i8 0, i8* [[OMP_EXEC_STATUS]], // CHECK: br label {{%?}}[[AWAIT_WORK:.+]] @@ -483,6 +482,7 @@ int baz(int f, double &a) { // CHECK: br i1 [[IS_ACTIVE]], label {{%?}}[[EXEC_PARALLEL:.+]], label {{%?}}[[BAR_PARALLEL:.+]] // // CHECK: [[EXEC_PARALLEL]] + // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* [[NONSPMD]] // CHECK: [[WORK_FN:%.+]] = bitcast i8* [[WORK]] to void (i16, i32)* // CHECK: call void [[WORK_FN]](i16 0, i32 [[GTID]]) // CHECK: br label {{%?}}[[TERM_PARALLEL:.+]] -- 2.40.0