[PATCH] D79677: [clang][OpenMP][OMPIRBuilder] Adding some Privatization clauses to OpenMP `parallel` Directive

Fady Ghanim via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 9 10:25:35 PDT 2020


fghanim updated this revision to Diff 269589.
fghanim added a comment.
Herald added subscribers: aaron.ballman, sstefan1.

- rebase
- splitting patch into 4 ( this, D81482 <https://reviews.llvm.org/D81482> , D81483 <https://reviews.llvm.org/D81483> , D81484 <https://reviews.llvm.org/D81484> )
- addressing reviewer's comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79677/new/

https://reviews.llvm.org/D79677

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===================================================================
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1683,13 +1683,65 @@
     const CapturedStmt *CS = S.getCapturedStmt(OMPD_parallel);
     const Stmt *ParallelRegionBodyStmt = CS->getCapturedStmt();
 
-    auto BodyGenCB = [ParallelRegionBodyStmt,
-                      this](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
-                            llvm::BasicBlock &ContinuationBB) {
+    OMPParallelScope Scope(*this, S);
+    llvm::SmallDenseMap<const VarDecl *, OMPBuilderCBHelpers::CapturedVarInfo>
+        CapturedVarsInfoMap;
+
+    OMPBuilderCBHelpers::GenerateOpenMPCapturedVars(*this, *CS,
+                                                    CapturedVarsInfoMap);
+
+    auto BodyGenCB = [ParallelRegionBodyStmt, &S, this, &OMPBuilder,
+                      &CapturedVarsInfoMap](InsertPointTy AllocaIP,
+                                            InsertPointTy CodeGenIP,
+                                            llvm::BasicBlock &ContinuationBB) {
       OMPBuilderCBHelpers::OutlinedRegionBodyRAII ORB(*this, AllocaIP,
                                                       ContinuationBB);
+
+      OMPPrivateScope PrivateScope(*this);
+      llvm::BasicBlock *OMP_Entry = AllocaIP.getBlock();
+      // Emitting Copyin clause
+      Builder.SetInsertPoint(OMP_Entry->getTerminator());
+      bool Copyins =
+          OMPBuilderCBHelpers::EmitOMPCopyinClause(*this, S, AllocaIP);
+
+      // restoring alloca insertion point to entry block since it moved while
+      // emitting 'copyin' blocks
+      AllocaInsertPt = OMP_Entry->getFirstNonPHIOrDbgOrLifetime();
+      llvm::BranchInst *EntryBI =
+          cast<llvm::BranchInst>(OMP_Entry->getTerminator());
+      EntryBI->removeFromParent();
+
+      if (Builder.GetInsertBlock() == OMP_Entry)
+        Builder.SetInsertPoint(OMP_Entry);
+      OMPBuilderCBHelpers::EmitOMPFirstprivateClause(*this, S, PrivateScope,
+                                                     CapturedVarsInfoMap);
+      if (Copyins) {
+        // Emit implicit barrier to synchronize threads and avoid data races on
+        // propagation master's thread values of threadprivate variables to
+        // local instances of that variables of all other implicit threads.
+        OMPBuilder->CreateBarrier(Builder, OMPD_barrier, /*EmitChecks=*/false,
+                                  /*ForceSimpleCall=*/true);
+      }
+
+      EmitOMPPrivateClause(S, PrivateScope);
+      (void)PrivateScope.Privatize();
+
+      if (!OMP_Entry->getTerminator()) {
+        OMP_Entry->getInstList().push_back(EntryBI);
+      } else if (Builder.GetInsertBlock()->getTerminator()) {
+        EntryBI->dropAllReferences();
+        EntryBI->deleteValue();
+      } else {
+        Builder.Insert(EntryBI);
+      }
+
       OMPBuilderCBHelpers::EmitOMPRegionBody(*this, ParallelRegionBodyStmt,
                                              CodeGenIP, ContinuationBB);
+      llvm::Instruction *ContTI = ContinuationBB.getTerminator();
+      ContTI->removeFromParent();
+      Builder.SetInsertPoint(&ContinuationBB);
+      PrivateScope.ForceCleanup();
+      Builder.Insert(ContTI);
     };
 
     CGCapturedStmtInfo CGSI(*CS, CR_OpenMP);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79677.269589.patch
Type: text/x-patch
Size: 3332 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200609/9b0088c9/attachment.bin>


More information about the cfe-commits mailing list