diff options
Diffstat (limited to 'clang/lib/CodeGen/CGStmtOpenMP.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGStmtOpenMP.cpp | 101 |
1 files changed, 41 insertions, 60 deletions
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index ae783f5dde7..66641c2cacb 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -2312,18 +2312,30 @@ void CodeGenFunction::EmitOMPParallelSectionsDirective( void CodeGenFunction::EmitOMPTaskBasedDirective(const OMPExecutableDirective &S, const RegionCodeGenTy &BodyGen, const TaskGenTy &TaskGen, - bool Tied) { + OMPTaskDataTy &Data) { // Emit outlined function for task construct. auto CS = cast<CapturedStmt>(S.getAssociatedStmt()); auto *I = CS->getCapturedDecl()->param_begin(); auto *PartId = std::next(I); auto *TaskT = std::next(I, 4); + // Check if the task is final + if (const auto *Clause = S.getSingleClause<OMPFinalClause>()) { + // If the condition constant folds and can be elided, try to avoid emitting + // the condition and the dead arm of the if/else. + auto *Cond = Clause->getCondition(); + bool CondConstant; + if (ConstantFoldsToSimpleInteger(Cond, CondConstant)) + Data.Final.setInt(CondConstant); + else + Data.Final.setPointer(EvaluateExprAsBool(Cond)); + } else { + // By default the task is not final. + Data.Final.setInt(/*IntVal=*/false); + } // The first function argument for tasks is a thread id, the second one is a // part id (0 for tied tasks, >=0 for untied task). llvm::DenseSet<const VarDecl *> EmittedAsPrivate; // Get list of private variables. - OMPPrivateDataTy Data; - Data.Tied = Tied; for (const auto *C : S.getClausesOfKind<OMPPrivateClause>()) { auto IRef = C->varlist_begin(); for (auto *IInit : C->private_copies()) { @@ -2406,23 +2418,6 @@ void CodeGenFunction::EmitOMPTaskDirective(const OMPTaskDirective &S) { // Emit outlined function for task construct. auto CS = cast<CapturedStmt>(S.getAssociatedStmt()); auto CapturedStruct = GenerateCapturedStmtArgument(*CS); - // Check if we should emit tied or untied task. - bool Tied = !S.getSingleClause<OMPUntiedClause>(); - // Check if the task is final - llvm::PointerIntPair<llvm::Value *, 1, bool> Final; - if (const auto *Clause = S.getSingleClause<OMPFinalClause>()) { - // If the condition constant folds and can be elided, try to avoid emitting - // the condition and the dead arm of the if/else. - auto *Cond = Clause->getCondition(); - bool CondConstant; - if (ConstantFoldsToSimpleInteger(Cond, CondConstant)) - Final.setInt(CondConstant); - else - Final.setPointer(EvaluateExprAsBool(Cond)); - } else { - // By default the task is not final. - Final.setInt(/*IntVal=*/false); - } auto SharedsTy = getContext().getRecordType(CS->getCapturedRecordDecl()); const Expr *IfCond = nullptr; for (const auto *C : S.getClausesOfKind<OMPIfClause>()) { @@ -2433,19 +2428,20 @@ void CodeGenFunction::EmitOMPTaskDirective(const OMPTaskDirective &S) { } } + OMPTaskDataTy Data; + // Check if we should emit tied or untied task. + Data.Tied = !S.getSingleClause<OMPUntiedClause>(); auto &&BodyGen = [CS](CodeGenFunction &CGF, PrePostActionTy &) { CGF.EmitStmt(CS->getCapturedStmt()); }; - auto &&TaskGen = [&S, &Final, SharedsTy, CapturedStruct, + auto &&TaskGen = [&S, SharedsTy, CapturedStruct, IfCond](CodeGenFunction &CGF, llvm::Value *OutlinedFn, - const OMPPrivateDataTy &Data) { - CGF.CGM.getOpenMPRuntime().emitTaskCall( - CGF, S.getLocStart(), S, Data.Tied, Final, Data.NumberOfParts, - OutlinedFn, SharedsTy, CapturedStruct, IfCond, Data.PrivateVars, - Data.PrivateCopies, Data.FirstprivateVars, Data.FirstprivateCopies, - Data.FirstprivateInits, Data.Dependences); + const OMPTaskDataTy &Data) { + CGF.CGM.getOpenMPRuntime().emitTaskCall(CGF, S.getLocStart(), S, OutlinedFn, + SharedsTy, CapturedStruct, IfCond, + Data); }; - EmitOMPTaskBasedDirective(S, BodyGen, TaskGen, Tied); + EmitOMPTaskBasedDirective(S, BodyGen, TaskGen, Data); } void CodeGenFunction::EmitOMPTaskyieldDirective( @@ -3345,34 +3341,21 @@ void CodeGenFunction::EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S) { break; } } - bool Nogroup = S.getSingleClause<OMPNogroupClause>(); + + OMPTaskDataTy Data; + // Check if taskloop must be emitted without taskgroup. + Data.Nogroup = S.getSingleClause<OMPNogroupClause>(); // TODO: Check if we should emit tied or untied task. - // Check if the task is final - llvm::PointerIntPair<llvm::Value *, 1, bool> Final; - if (const auto *Clause = S.getSingleClause<OMPFinalClause>()) { - // If the condition constant folds and can be elided, try to avoid emitting - // the condition and the dead arm of the if/else. - auto *Cond = Clause->getCondition(); - bool CondConstant; - if (ConstantFoldsToSimpleInteger(Cond, CondConstant)) - Final.setInt(CondConstant); - else - Final.setPointer(EvaluateExprAsBool(Cond)); - } else { - // By default the task is not final. - Final.setInt(/*IntVal=*/false); - } - llvm::PointerIntPair<llvm::Value * /*no grainsize/num_tasks=nullptr*/, 1, - bool /*Grainsize=false, NumTasks=true*/> - Schedule; + Data.Tied = true; + // Set scheduling for taskloop if (const auto* Clause = S.getSingleClause<OMPGrainsizeClause>()) { // grainsize clause - Schedule.setInt(/*IntVal=*/false); - Schedule.setPointer(EmitScalarExpr(Clause->getGrainsize())); + Data.Schedule.setInt(/*IntVal=*/false); + Data.Schedule.setPointer(EmitScalarExpr(Clause->getGrainsize())); } else if (const auto* Clause = S.getSingleClause<OMPNumTasksClause>()) { // num_tasks clause - Schedule.setInt(/*IntVal=*/true); - Schedule.setPointer(EmitScalarExpr(Clause->getNumTasks())); + Data.Schedule.setInt(/*IntVal=*/true); + Data.Schedule.setPointer(EmitScalarExpr(Clause->getNumTasks())); } auto &&BodyGen = [CS, &S](CodeGenFunction &CGF, PrePostActionTy &) { @@ -3445,21 +3428,19 @@ void CodeGenFunction::EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S) { CGF.EmitBlock(ContBlock, true); } }; - auto &&TaskGen = [&S, SharedsTy, CapturedStruct, IfCond, &Final, &Schedule, - Nogroup](CodeGenFunction &CGF, llvm::Value *OutlinedFn, - const OMPPrivateDataTy &Data) { + auto &&TaskGen = [&S, SharedsTy, CapturedStruct, + IfCond](CodeGenFunction &CGF, llvm::Value *OutlinedFn, + const OMPTaskDataTy &Data) { auto &&CodeGen = [&](CodeGenFunction &CGF, PrePostActionTy &) { OMPLoopScope PreInitScope(CGF, S); - CGF.CGM.getOpenMPRuntime().emitTaskLoopCall( - CGF, S.getLocStart(), S, Data.Tied, Final, Schedule, Nogroup, - Data.NumberOfParts, OutlinedFn, SharedsTy, CapturedStruct, IfCond, - Data.PrivateVars, Data.PrivateCopies, Data.FirstprivateVars, - Data.FirstprivateCopies, Data.FirstprivateInits); + CGF.CGM.getOpenMPRuntime().emitTaskLoopCall(CGF, S.getLocStart(), S, + OutlinedFn, SharedsTy, + CapturedStruct, IfCond, Data); }; CGF.CGM.getOpenMPRuntime().emitInlinedDirective(CGF, OMPD_taskloop, CodeGen); }; - EmitOMPTaskBasedDirective(S, BodyGen, TaskGen, /*Tied=*/true); + EmitOMPTaskBasedDirective(S, BodyGen, TaskGen, Data); } void CodeGenFunction::EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S) { |