-
Notifications
You must be signed in to change notification settings - Fork 0
Target in reduction #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4915,6 +4915,17 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective( | |||||||||||||||||||||||||||||
| ++IElemInitRef; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| SmallVector<const Expr *, 4> LHSs; | ||||||||||||||||||||||||||||||
| SmallVector<const Expr *, 4> RHSs; | ||||||||||||||||||||||||||||||
| for (const auto *C : S.getClausesOfKind<OMPInReductionClause>()) { | ||||||||||||||||||||||||||||||
| Data.ReductionVars.append(C->varlist_begin(), C->varlist_end()); | ||||||||||||||||||||||||||||||
| Data.ReductionOrigs.append(C->varlist_begin(), C->varlist_end()); | ||||||||||||||||||||||||||||||
| Data.ReductionCopies.append(C->privates().begin(), C->privates().end()); | ||||||||||||||||||||||||||||||
| Data.ReductionOps.append(C->reduction_ops().begin(), | ||||||||||||||||||||||||||||||
| C->reduction_ops().end()); | ||||||||||||||||||||||||||||||
| LHSs.append(C->lhs_exprs().begin(), C->lhs_exprs().end()); | ||||||||||||||||||||||||||||||
| RHSs.append(C->rhs_exprs().begin(), C->rhs_exprs().end()); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| OMPPrivateScope TargetScope(*this); | ||||||||||||||||||||||||||||||
| VarDecl *BPVD = nullptr; | ||||||||||||||||||||||||||||||
| VarDecl *PVD = nullptr; | ||||||||||||||||||||||||||||||
|
|
@@ -4995,8 +5006,7 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective( | |||||||||||||||||||||||||||||
| Scope.addPrivate(Pair.first, Replacement); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| // Privatize all private variables except for in_reduction items. | ||||||||||||||||||||||||||||||
| (void)Scope.Privatize(); | ||||||||||||||||||||||||||||||
| CGF.processInReduction(S,Data,CGF,CS,Scope); | ||||||||||||||||||||||||||||||
| if (InputInfo.NumberOfTargetItems > 0) { | ||||||||||||||||||||||||||||||
| InputInfo.BasePointersArray = CGF.Builder.CreateConstArrayGEP( | ||||||||||||||||||||||||||||||
| CGF.GetAddrOfLocalVar(BPVD), /*Index=*/0); | ||||||||||||||||||||||||||||||
|
|
@@ -5021,11 +5031,108 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective( | |||||||||||||||||||||||||||||
| IntegerLiteral IfCond(getContext(), TrueOrFalse, | ||||||||||||||||||||||||||||||
| getContext().getIntTypeForBitwidth(32, /*Signed=*/0), | ||||||||||||||||||||||||||||||
| SourceLocation()); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if(S.hasClausesOfKind<OMPInReductionClause>()){ | ||||||||||||||||||||||||||||||
| llvm::APInt TrueOrFalse(32, S.hasClausesOfKind<OMPInReductionClause>() ? 0 : 1); | ||||||||||||||||||||||||||||||
| IntegerLiteral IfCond(getContext(), TrueOrFalse, | ||||||||||||||||||||||||||||||
| getContext().getIntTypeForBitwidth(32, /*Signed=*/0), | ||||||||||||||||||||||||||||||
| SourceLocation()); | ||||||||||||||||||||||||||||||
| CGM.getOpenMPRuntime().emitTaskCall(*this, S.getBeginLoc(), S, OutlinedFn, | ||||||||||||||||||||||||||||||
| SharedsTy, CapturedStruct, &IfCond, Data); | ||||||||||||||||||||||||||||||
|
Comment on lines
+5039
to
+5040
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| CGM.getOpenMPRuntime().emitTaskCall(*this, S.getBeginLoc(), S, OutlinedFn, | ||||||||||||||||||||||||||||||
| SharedsTy, CapturedStruct, &IfCond, Data); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| void CodeGenFunction::processInReduction(const OMPExecutableDirective &S, | ||||||||||||||||||||||||||||||
| OMPTaskDataTy &Data, | ||||||||||||||||||||||||||||||
| CodeGenFunction &CGF, | ||||||||||||||||||||||||||||||
| const CapturedStmt *CS, | ||||||||||||||||||||||||||||||
| OMPPrivateScope &Scope){ | ||||||||||||||||||||||||||||||
| if (Data.Reductions) { | ||||||||||||||||||||||||||||||
| OpenMPDirectiveKind CapturedRegion = S.getDirectiveKind(); | ||||||||||||||||||||||||||||||
| OMPLexicalScope LexScope(CGF, S, CapturedRegion); | ||||||||||||||||||||||||||||||
| ReductionCodeGen RedCG(Data.ReductionVars, Data.ReductionVars, | ||||||||||||||||||||||||||||||
| Data.ReductionCopies, Data.ReductionOps); | ||||||||||||||||||||||||||||||
| llvm::Value *ReductionsPtr = CGF.Builder.CreateLoad( | ||||||||||||||||||||||||||||||
| CGF.GetAddrOfLocalVar(CS->getCapturedDecl()->getParam(4))); | ||||||||||||||||||||||||||||||
| for (unsigned Cnt = 0, E = Data.ReductionVars.size(); Cnt < E; ++Cnt) { | ||||||||||||||||||||||||||||||
| RedCG.emitSharedOrigLValue(CGF, Cnt); | ||||||||||||||||||||||||||||||
| RedCG.emitAggregateType(CGF, Cnt); | ||||||||||||||||||||||||||||||
| // FIXME: This must removed once the runtime library is fixed. | ||||||||||||||||||||||||||||||
| // Emit required threadprivate variables for | ||||||||||||||||||||||||||||||
| // initializer/combiner/finalizer. | ||||||||||||||||||||||||||||||
| CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF, S.getBeginLoc(), | ||||||||||||||||||||||||||||||
| RedCG, Cnt); | ||||||||||||||||||||||||||||||
| Address Replacement = CGF.CGM.getOpenMPRuntime().getTaskReductionItem( | ||||||||||||||||||||||||||||||
| CGF, S.getBeginLoc(), ReductionsPtr, RedCG.getSharedLValue(Cnt)); | ||||||||||||||||||||||||||||||
| Replacement = | ||||||||||||||||||||||||||||||
| Address(CGF.EmitScalarConversion( | ||||||||||||||||||||||||||||||
| Replacement.getPointer(), CGF.getContext().VoidPtrTy, | ||||||||||||||||||||||||||||||
| CGF.getContext().getPointerType( | ||||||||||||||||||||||||||||||
| Data.ReductionCopies[Cnt]->getType()), | ||||||||||||||||||||||||||||||
| Data.ReductionCopies[Cnt]->getExprLoc()), | ||||||||||||||||||||||||||||||
| CGF.ConvertTypeForMem(Data.ReductionCopies[Cnt]->getType()), | ||||||||||||||||||||||||||||||
| Replacement.getAlignment()); | ||||||||||||||||||||||||||||||
|
Comment on lines
+5070
to
+5076
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| Replacement = RedCG.adjustPrivateAddress(CGF, Cnt, Replacement); | ||||||||||||||||||||||||||||||
| Scope.addPrivate(RedCG.getBaseDecl(Cnt),Replacement); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| (void)Scope.Privatize(); | ||||||||||||||||||||||||||||||
| SmallVector<const Expr *, 4> InRedVars; | ||||||||||||||||||||||||||||||
| SmallVector<const Expr *, 4> InRedPrivs; | ||||||||||||||||||||||||||||||
| SmallVector<const Expr *, 4> InRedOps; | ||||||||||||||||||||||||||||||
| SmallVector<const Expr *, 4> TaskgroupDescriptors; | ||||||||||||||||||||||||||||||
| for (const auto *C : S.getClausesOfKind<OMPInReductionClause>()) { | ||||||||||||||||||||||||||||||
| auto IPriv = C->privates().begin(); | ||||||||||||||||||||||||||||||
| auto IRed = C->reduction_ops().begin(); | ||||||||||||||||||||||||||||||
| auto ITD = C->taskgroup_descriptors().begin(); | ||||||||||||||||||||||||||||||
| for (const Expr *Ref : C->varlists()) { | ||||||||||||||||||||||||||||||
| InRedVars.emplace_back(Ref); | ||||||||||||||||||||||||||||||
| InRedPrivs.emplace_back(*IPriv); | ||||||||||||||||||||||||||||||
| InRedOps.emplace_back(*IRed); | ||||||||||||||||||||||||||||||
| TaskgroupDescriptors.emplace_back(*ITD); | ||||||||||||||||||||||||||||||
| std::advance(IPriv, 1); | ||||||||||||||||||||||||||||||
| std::advance(IRed, 1); | ||||||||||||||||||||||||||||||
| std::advance(ITD, 1); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| OMPPrivateScope InRedScope(CGF); | ||||||||||||||||||||||||||||||
| if (!InRedVars.empty()) { | ||||||||||||||||||||||||||||||
| ReductionCodeGen RedCG(InRedVars, InRedVars, InRedPrivs, InRedOps); | ||||||||||||||||||||||||||||||
| for (unsigned Cnt = 0, E = InRedVars.size(); Cnt < E; ++Cnt) { | ||||||||||||||||||||||||||||||
| RedCG.emitSharedOrigLValue(CGF, Cnt); | ||||||||||||||||||||||||||||||
| RedCG.emitAggregateType(CGF, Cnt); | ||||||||||||||||||||||||||||||
| // The taskgroup descriptor variable is always implicit firstprivate and | ||||||||||||||||||||||||||||||
| // privatized already during processing of the firstprivates. | ||||||||||||||||||||||||||||||
| // FIXME: This must removed once the runtime library is fixed. | ||||||||||||||||||||||||||||||
| // Emit required threadprivate variables for | ||||||||||||||||||||||||||||||
| // initializer/combiner/finalizer. | ||||||||||||||||||||||||||||||
| CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF, S.getBeginLoc(), | ||||||||||||||||||||||||||||||
| RedCG, Cnt); | ||||||||||||||||||||||||||||||
| llvm::Value *ReductionsPtr; | ||||||||||||||||||||||||||||||
| if (const Expr *TRExpr = TaskgroupDescriptors[Cnt]) { | ||||||||||||||||||||||||||||||
| ReductionsPtr = CGF.EmitLoadOfScalar(CGF.EmitLValue(TRExpr), | ||||||||||||||||||||||||||||||
| TRExpr->getExprLoc()); | ||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||
| ReductionsPtr = llvm::ConstantPointerNull::get(CGF.VoidPtrTy); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Address Replacement = CGF.CGM.getOpenMPRuntime().getTaskReductionItem( | ||||||||||||||||||||||||||||||
| CGF, S.getBeginLoc(), ReductionsPtr, RedCG.getSharedLValue(Cnt)); | ||||||||||||||||||||||||||||||
| Replacement = Address( | ||||||||||||||||||||||||||||||
| CGF.EmitScalarConversion( | ||||||||||||||||||||||||||||||
| Replacement.getPointer(), CGF.getContext().VoidPtrTy, | ||||||||||||||||||||||||||||||
| CGF.getContext().getPointerType(InRedPrivs[Cnt]->getType()), | ||||||||||||||||||||||||||||||
| InRedPrivs[Cnt]->getExprLoc()), | ||||||||||||||||||||||||||||||
| CGF.ConvertTypeForMem(InRedPrivs[Cnt]->getType()), | ||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| Replacement.getAlignment()); | ||||||||||||||||||||||||||||||
| Replacement = RedCG.adjustPrivateAddress(CGF, Cnt, Replacement); | ||||||||||||||||||||||||||||||
| InRedScope.addPrivate(RedCG.getBaseDecl(Cnt), Replacement); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| (void)InRedScope.Privatize(); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| void CodeGenFunction::EmitOMPTaskDirective(const OMPTaskDirective &S) { | ||||||||||||||||||||||||||||||
| // Emit outlined function for task construct. | ||||||||||||||||||||||||||||||
| const CapturedStmt *CS = S.getCapturedStmt(OMPD_task); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3497,8 +3497,12 @@ class CodeGenFunction : public CodeGenTypeCache { | |||||||||||||||||
| }; | ||||||||||||||||||
| void EmitOMPTargetTaskBasedDirective(const OMPExecutableDirective &S, | ||||||||||||||||||
| const RegionCodeGenTy &BodyGen, | ||||||||||||||||||
| OMPTargetDataInfo &InputInfo); | ||||||||||||||||||
|
|
||||||||||||||||||
| OMPTargetDataInfo &InputInfo); | ||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is an unnecessary change |
||||||||||||||||||
| void processInReduction(const OMPExecutableDirective &S, | ||||||||||||||||||
| OMPTaskDataTy &Data, | ||||||||||||||||||
| CodeGenFunction &CGF, | ||||||||||||||||||
| const CapturedStmt *CS, | ||||||||||||||||||
| OMPPrivateScope &Scope); | ||||||||||||||||||
|
Comment on lines
+3502
to
+3505
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| void EmitOMPMetaDirective(const OMPMetaDirective &S); | ||||||||||||||||||
| void EmitOMPParallelDirective(const OMPParallelDirective &S); | ||||||||||||||||||
| void EmitOMPSimdDirective(const OMPSimdDirective &S); | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4567,7 +4567,8 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, | |||||||||
| // This is required for proper codegen. | ||||||||||
| for (OMPClause *Clause : Clauses) { | ||||||||||
| if (!LangOpts.OpenMPSimd && | ||||||||||
| isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) && | ||||||||||
| (isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) || | ||||||||||
| DSAStack->getCurrentDirective() == OMPD_target) && | ||||||||||
|
Comment on lines
+4570
to
+4571
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| Clause->getClauseKind() == OMPC_in_reduction) { | ||||||||||
| // Capture taskgroup task_reduction descriptors inside the tasking regions | ||||||||||
| // with the corresponding in_reduction items. | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.