-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support #131838
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 30 commits
1703aa6
5ae3ffe
daf681c
bc3c018
b83e0ba
997fe7c
182d026
dca846e
26427bf
e379325
bab22e6
00ac6cf
ff2f370
de5b7cc
5d5b152
817f6df
984446d
4cb7bdd
bd2e38a
c1a83cc
07354f0
f204bc4
ce9bff0
bb176c8
d217bc5
8fba558
5ec20c3
cd8fae5
f47769a
503222e
de8b736
f1e91f0
b2571fa
b60c252
d23c523
f186576
fd150c2
07d8827
4206c6e
6a35664
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 |
|---|---|---|
|
|
@@ -11888,6 +11888,9 @@ def err_omp_clause_requires_dispatch_construct : Error< | |
| "'%0' clause requires 'dispatch' context selector">; | ||
| def err_omp_append_args_with_varargs : Error< | ||
| "'append_args' is not allowed with varargs functions">; | ||
| def warn_omp_dispatch_clause_novariants_nocontext : Warning< | ||
|
||
| "'nocontext' clause is ignored, only 'novariants' clause is applied">, | ||
| InGroup<SourceUsesOpenMP>; | ||
| def err_openmp_vla_in_task_untied : Error< | ||
| "variable length arrays are not supported in OpenMP tasking regions with 'untied' clause">; | ||
| def warn_omp_unterminated_declare_target : Warning< | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4528,6 +4528,115 @@ void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) { | |
| emitMaster(*this, S); | ||
| } | ||
|
|
||
| static Expr *getInitialExprFromCapturedExpr(Expr *Cond) { | ||
|
||
|
|
||
| Expr *SubExpr = Cond->IgnoreParenImpCasts(); | ||
|
|
||
| if (auto *DeclRef = dyn_cast<DeclRefExpr>(SubExpr)) { | ||
| if (auto *CapturedExprDecl = | ||
| dyn_cast<OMPCapturedExprDecl>(DeclRef->getDecl())) { | ||
|
|
||
| // Retrieve the initial expression from the captured expression | ||
| return CapturedExprDecl->getInit(); | ||
| } | ||
| } | ||
| return Cond; | ||
| } | ||
|
|
||
| static Expr *replaceWithNewTraitsOrDirectCall(Stmt *AssocExpr, | ||
| CallExpr *ReplacementFunction) { | ||
| Expr *FinalCall = ReplacementFunction; | ||
|
|
||
| if (BinaryOperator *BinaryCopyOpr = dyn_cast<BinaryOperator>(AssocExpr)) { | ||
| BinaryCopyOpr->setRHS(FinalCall); | ||
| return BinaryCopyOpr; | ||
| } | ||
|
|
||
| return FinalCall; | ||
| } | ||
|
|
||
| static void transformCallInStmt(Stmt *StmtP) { | ||
| if (auto *AssocStmt = dyn_cast<CapturedStmt>(StmtP)) { | ||
| CapturedDecl *CDecl = AssocStmt->getCapturedDecl(); | ||
|
|
||
| // Access AnnotateAttr | ||
| CallExpr *NewCallExpr = nullptr; | ||
| for (const auto *attr : CDecl->attrs()) { | ||
| if (const auto *annotateAttr = llvm::dyn_cast<clang::AnnotateAttr>(attr); | ||
| annotateAttr && | ||
| annotateAttr->getAnnotation() == "NoContextInvariant") { | ||
| NewCallExpr = llvm::dyn_cast<CallExpr>(*annotateAttr->args_begin()); | ||
| } | ||
| } | ||
|
|
||
| Stmt *CallExprStmt = CDecl->getBody(); | ||
| Stmt *NewCallExprStmt = | ||
| replaceWithNewTraitsOrDirectCall(CallExprStmt, NewCallExpr); | ||
| CDecl->setBody(NewCallExprStmt); | ||
| } | ||
| } | ||
|
|
||
| static void EmitIfElse(CodeGenFunction *CGF, Expr *Condition, | ||
SunilKuravinakop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Stmt *AssociatedStmt) { | ||
| llvm::Value *CondValue = CGF->EvaluateExprAsBool(Condition); | ||
| llvm::BasicBlock *ThenBlock = CGF->createBasicBlock("if.then"); | ||
| llvm::BasicBlock *ElseBlock = CGF->createBasicBlock("if.else"); | ||
| llvm::BasicBlock *MergeBlock = CGF->createBasicBlock("if.end"); | ||
|
|
||
| CGF->Builder.CreateCondBr(CondValue, ThenBlock, ElseBlock); | ||
|
|
||
| // Emit the else block. | ||
| Stmt *ElseStmt = AssociatedStmt; | ||
| CGF->EmitBlock(ElseBlock); | ||
| CGF->EmitStmt(ElseStmt); | ||
| CGF->Builder.CreateBr(MergeBlock); | ||
|
|
||
| // Emit the then block. | ||
| Stmt *ThenStmt = AssociatedStmt; | ||
| transformCallInStmt(ThenStmt); | ||
| CGF->EmitBlock(ThenBlock); | ||
| CGF->EmitStmt(ThenStmt); | ||
| CGF->Builder.CreateBr(MergeBlock); | ||
| CGF->EmitBlock(MergeBlock); | ||
| } | ||
|
|
||
| void CodeGenFunction::EmitOMPDispatchDirective(const OMPDispatchDirective &S) { | ||
| ArrayRef<OMPClause *> Clauses = S.clauses(); | ||
|
|
||
| Stmt *AssociatedStmt = const_cast<Stmt *>(S.getAssociatedStmt()); | ||
| if (auto *AssocStmt = dyn_cast<CapturedStmt>(AssociatedStmt)) | ||
| if (auto *InnerCapturedStmt = | ||
| dyn_cast<CapturedStmt>(AssocStmt->getCapturedStmt())) { | ||
| AssociatedStmt = InnerCapturedStmt; | ||
| } | ||
SunilKuravinakop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| CodeGenFunction::CGCapturedStmtInfo CapStmtInfo; | ||
| if (!CapturedStmtInfo) | ||
| CapturedStmtInfo = &CapStmtInfo; | ||
|
|
||
| if (!Clauses.empty()) { | ||
| if (S.hasClausesOfKind<OMPDependClause>()) | ||
| EmitOMPDispatchToTaskwaitDirective(S); | ||
SunilKuravinakop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (S.hasClausesOfKind<OMPNovariantsClause>() || | ||
| S.hasClausesOfKind<OMPNocontextClause>()) { | ||
| Expr *Condition = nullptr; | ||
| if (const OMPNovariantsClause *NoVariantsC = | ||
| OMPExecutableDirective::getSingleClause<OMPNovariantsClause>( | ||
| Clauses)) { | ||
| Condition = getInitialExprFromCapturedExpr(NoVariantsC->getCondition()); | ||
| } else { | ||
| const OMPNocontextClause *NoContextC = | ||
| OMPExecutableDirective::getSingleClause<OMPNocontextClause>( | ||
| Clauses); | ||
| Condition = getInitialExprFromCapturedExpr(NoContextC->getCondition()); | ||
| } | ||
| /* OMPC_novariants or OMPC_nocontext present */ | ||
| EmitIfElse(this, Condition, AssociatedStmt); | ||
| } | ||
| } else | ||
| EmitStmt(AssociatedStmt); | ||
SunilKuravinakop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| static void emitMasked(CodeGenFunction &CGF, const OMPExecutableDirective &S) { | ||
| auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) { | ||
| Action.Enter(CGF); | ||
|
|
@@ -5548,6 +5657,15 @@ void CodeGenFunction::EmitOMPBarrierDirective(const OMPBarrierDirective &S) { | |
| CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getBeginLoc(), OMPD_barrier); | ||
| } | ||
|
|
||
| void CodeGenFunction::EmitOMPDispatchToTaskwaitDirective( | ||
| const OMPDispatchDirective &S) { | ||
| OMPTaskDataTy Data; | ||
| // Build list of dependences | ||
| buildDependences(S, Data); | ||
| Data.HasNowaitClause = S.hasClausesOfKind<OMPNowaitClause>(); | ||
| CGM.getOpenMPRuntime().emitTaskwaitCall(*this, S.getBeginLoc(), Data); | ||
| } | ||
|
|
||
| void CodeGenFunction::EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S) { | ||
| OMPTaskDataTy Data; | ||
| // Build list of dependences | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.