[PATCH] D91054: [LLVM][OpenMP] Frontend work for sections - D89671
Chirag Khandelwal via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 01:03:33 PST 2020
AMDChirag created this revision.
AMDChirag added reviewers: anchu-rajendran, fghanim, jdoerfert, kiranchandramohan, kiranktp, SouraVX, AlexisPerry, Meinersbur.
Herald added subscribers: cfe-commits, guansong, yaxunl.
Herald added a project: clang.
AMDChirag requested review of this revision.
Herald added a subscriber: sstefan1.
Primary Author: @anchu-rajendran
This patch is child of D89671 <https://reviews.llvm.org/D89671>, contains the clang
implementation to use the OpenMP IRBuilder's section
construct.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91054
Files:
clang/lib/CodeGen/CGStmtOpenMP.cpp
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===================================================================
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -3546,12 +3546,68 @@
}
void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) {
- {
- auto LPCRegion =
- CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
- OMPLexicalScope Scope(*this, S, OMPD_unknown);
- EmitSections(S);
+ if (CGM.getLangOpts().OpenMPIRBuilder) {
+ llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
+ using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
+ using BodyGenCallbackTy =
+ llvm::function_ref<void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
+ llvm::BasicBlock & ContinuationBB)>;
+
+ auto FiniCB = [this](InsertPointTy IP) {
+ OMPBuilderCBHelpers::FinalizeOMPRegion(*this, IP);
+ };
+
+ const Stmt *CapturedStmt = S.getInnermostCapturedStmt()->getCapturedStmt();
+ const auto *CS = dyn_cast<CompoundStmt>(CapturedStmt);
+ llvm::SmallVector<BodyGenCallbackTy, 4> SectionCBVector;
+ if (CS) {
+ for (const Stmt *SubStmt : CS->children()) {
+ auto SectionCB = [this, SubStmt](InsertPointTy AllocaIP,
+ InsertPointTy CodeGenIP,
+ llvm::BasicBlock &FiniBB) {
+ OMPBuilderCBHelpers::InlinedRegionBodyRAII IRB(*this, AllocaIP,
+ FiniBB);
+ OMPBuilderCBHelpers::EmitOMPRegionBody(*this, SubStmt, CodeGenIP,
+ FiniBB);
+ };
+ SectionCBVector.push_back(SectionCB);
+ }
+ } else {
+ auto SectionCB = [this, CS](InsertPointTy AllocaIP,
+ InsertPointTy CodeGenIP,
+ llvm::BasicBlock &FiniBB) {
+ OMPBuilderCBHelpers::InlinedRegionBodyRAII IRB(*this, AllocaIP, FiniBB);
+ OMPBuilderCBHelpers::EmitOMPRegionBody(*this, CS, CodeGenIP, FiniBB);
+ };
+ SectionCBVector.push_back(SectionCB);
+ }
+ ArrayRef<BodyGenCallbackTy> SectionCBs = makeArrayRef(SectionCBVector);
+
+ // Privatization callback that performs appropriate action for
+ // shared/private/firstprivate/lastprivate/copyin/... variables.
+ //
+ // TODO: This defaults to shared right now.
+ auto PrivCB = [](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
+ llvm::Value &Val, llvm::Value *&ReplVal) {
+ // The next line is appropriate only for variables (Val) with the
+ // data-sharing attribute "shared".
+ ReplVal = &Val;
+
+ return CodeGenIP;
+ };
+
+ llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
+ AllocaInsertPt->getParent(), AllocaInsertPt->getIterator());
+ Builder.restoreIP(OMPBuilder.CreateSections(
+ Builder, AllocaIP, SectionCBs, PrivCB, FiniCB, S.hasCancel(),
+ S.getSingleClause<OMPNowaitClause>()));
+
+ return;
}
+ auto LPCRegion =
+ CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
+ OMPLexicalScope Scope(*this, S, OMPD_unknown);
+ EmitSections(S);
// Emit an implicit barrier at the end.
if (!S.getSingleClause<OMPNowaitClause>()) {
CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getBeginLoc(),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91054.303770.patch
Type: text/x-patch
Size: 3417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201109/643456b0/attachment.bin>
More information about the cfe-commits
mailing list