r333301 - [OPENMP, NVPTX] Fixed codegen for orphaned parallel region.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Fri May 25 13:16:03 PDT 2018


Author: abataev
Date: Fri May 25 13:16:03 2018
New Revision: 333301

URL: http://llvm.org/viewvc/llvm-project?rev=333301&view=rev
Log:
[OPENMP, NVPTX] Fixed codegen for orphaned parallel region.

If orphaned parallel region is found, the next code must be emitted:
```
if(__kmpc_is_spmd_exec_mode() || __kmpc_parallel_level(loc, gtid))
  Serialized execution.
else if (IsMasterThread())
  Prepare and signal worker.
else
  Outined function call.
```

Modified:
    cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
    cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=333301&r1=333300&r2=333301&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Fri May 25 13:16:03 2018
@@ -1845,35 +1845,21 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
       RCG(CGF);
     } else {
       // Check for master and then parallelism:
-      // if (__kmpc_is_spmd_exec_mode()) {
+      // if (__kmpc_is_spmd_exec_mode() || __kmpc_parallel_level(loc, gtid)) {
       //  Serialized execution.
-      // } else if (is_master) {
+      // } else if (master) {
       //   Worker call.
-      // } else if (__kmpc_parallel_level(loc, gtid)) {
-      //   Serialized execution.
       // } else {
       //   Outlined function call.
       // }
       CGBuilderTy &Bld = CGF.Builder;
       llvm::BasicBlock *ExitBB = CGF.createBasicBlock(".exit");
-      llvm::BasicBlock *SPMDCheckBB = CGF.createBasicBlock(".spmdcheck");
+      llvm::BasicBlock *SeqBB = CGF.createBasicBlock(".sequential");
+      llvm::BasicBlock *ParallelCheckBB = CGF.createBasicBlock(".parcheck");
       llvm::BasicBlock *MasterCheckBB = CGF.createBasicBlock(".mastercheck");
-      llvm::BasicBlock *ParallelCheckBB =
-          CGF.createBasicBlock(".parallelcheck");
       llvm::Value *IsSPMD = Bld.CreateIsNotNull(CGF.EmitNounwindRuntimeCall(
           createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_is_spmd_exec_mode)));
-      Bld.CreateCondBr(IsSPMD, SPMDCheckBB, MasterCheckBB);
-      CGF.EmitBlock(SPMDCheckBB);
-      SeqGen(CGF, Action);
-      CGF.EmitBranch(ExitBB);
-      CGF.EmitBlock(MasterCheckBB);
-      llvm::BasicBlock *MasterThenBB = CGF.createBasicBlock("master.then");
-      llvm::Value *IsMaster =
-          Bld.CreateICmpEQ(getNVPTXThreadID(CGF), getMasterThreadID(CGF));
-      Bld.CreateCondBr(IsMaster, MasterThenBB, ParallelCheckBB);
-      CGF.EmitBlock(MasterThenBB);
-      L0ParallelGen(CGF, Action);
-      CGF.EmitBranch(ExitBB);
+      Bld.CreateCondBr(IsSPMD, SeqBB, ParallelCheckBB);
       // There is no need to emit line number for unconditional branch.
       (void)ApplyDebugLocation::CreateEmpty(CGF);
       CGF.EmitBlock(ParallelCheckBB);
@@ -1883,15 +1869,23 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
           createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_parallel_level),
           {RTLoc, ThreadID});
       llvm::Value *Res = Bld.CreateIsNotNull(PL);
-      llvm::BasicBlock *ThenBlock = CGF.createBasicBlock("omp_if.then");
-      llvm::BasicBlock *ElseBlock = CGF.createBasicBlock("omp_if.else");
-      Bld.CreateCondBr(Res, ThenBlock, ElseBlock);
-      // Emit the 'then' code.
-      CGF.EmitBlock(ThenBlock);
+      Bld.CreateCondBr(Res, SeqBB, MasterCheckBB);
+      CGF.EmitBlock(SeqBB);
       SeqGen(CGF, Action);
+      CGF.EmitBranch(ExitBB);
+      // There is no need to emit line number for unconditional branch.
+      (void)ApplyDebugLocation::CreateEmpty(CGF);
+      CGF.EmitBlock(MasterCheckBB);
+      llvm::BasicBlock *MasterThenBB = CGF.createBasicBlock("master.then");
+      llvm::BasicBlock *ElseBlock = CGF.createBasicBlock("omp_if.else");
+      llvm::Value *IsMaster =
+          Bld.CreateICmpEQ(getNVPTXThreadID(CGF), getMasterThreadID(CGF));
+      Bld.CreateCondBr(IsMaster, MasterThenBB, ElseBlock);
+      CGF.EmitBlock(MasterThenBB);
+      L0ParallelGen(CGF, Action);
+      CGF.EmitBranch(ExitBB);
       // There is no need to emit line number for unconditional branch.
       (void)ApplyDebugLocation::CreateEmpty(CGF);
-      // Emit the 'else' code.
       CGF.EmitBlock(ElseBlock);
       RCG(CGF);
       // There is no need to emit line number for unconditional branch.

Modified: cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp?rev=333301&r1=333300&r2=333301&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp Fri May 25 13:16:03 2018
@@ -566,6 +566,10 @@ int baz(int f, double &a) {
   // CHECK: icmp ne i8 [[RES]], 0
   // CHECK: br i1
 
+  // CHECK: [[RES:%.+]] = call i16 @__kmpc_parallel_level(%struct.ident_t* @{{.+}}, i32 [[GTID]])
+  // CHECK: icmp ne i16 [[RES]], 0
+  // CHECK: br i1
+
   // CHECK: call void @__kmpc_serialized_parallel(%struct.ident_t* @{{.+}}, i32 [[GTID]])
   // CHECK: call void [[OUTLINED:@.+]](i32* [[GTID_ADDR]], i32* [[ZERO_ADDR]], i32* [[F_PTR]], double* %{{.+}})
   // CHECK: call void @__kmpc_end_serialized_parallel(%struct.ident_t* @{{.+}}, i32 [[GTID]])
@@ -585,15 +589,6 @@ int baz(int f, double &a) {
   // CHECK: call void @__kmpc_end_sharing_variables()
   // CHECK: br label
 
-  // CHECK: [[RES:%.+]] = call i16 @__kmpc_parallel_level(%struct.ident_t* @{{.+}}, i32 [[GTID]])
-  // CHECK: icmp ne i16 [[RES]], 0
-  // CHECK: br i1
-
-  // CHECK: call void @__kmpc_serialized_parallel(%struct.ident_t* @{{.+}}, i32 [[GTID]])
-  // CHECK: call void [[OUTLINED:@.+]](i32* [[GTID_ADDR]], i32* [[ZERO_ADDR]], i32* [[F_PTR]], double* %{{.+}})
-  // CHECK: call void @__kmpc_end_serialized_parallel(%struct.ident_t* @{{.+}}, i32 [[GTID]])
-  // CHECK: br label
-
   // CHECK: call void [[OUTLINED]](i32* [[GTID_ADDR]], i32* [[ZERO_ADDR]], i32* [[F_PTR]], double* %{{.+}})
   // CHECK: br label
 




More information about the cfe-commits mailing list