From: Alexey Bataev Date: Thu, 16 Nov 2017 18:20:21 +0000 (+0000) Subject: [OPENMP] Add support for cancelling inside target parallel for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a91f170c9b7c962d2555735560cd538292d11a1;p=clang [OPENMP] Add support for cancelling inside target parallel for directive. Added missed support for cancelling of target parallel for construct. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318434 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index 85a9211917..5186b20210 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1291,6 +1291,8 @@ static llvm::Value *emitParallelOrTeamsOutlinedFunction( HasCancel = OPSD->hasCancel(); else if (auto *OPFD = dyn_cast(&D)) HasCancel = OPFD->hasCancel(); + else if (auto *OPFD = dyn_cast(&D)) + HasCancel = OPFD->hasCancel(); CGOpenMPOutlinedRegionInfo CGInfo(*CS, ThreadIDVar, CodeGen, InnermostKind, HasCancel, OutlinedHelperName); CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo); diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index b7a01390c3..873c752583 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -3794,7 +3794,7 @@ void CodeGenFunction::EmitOMPTeamsDirective(const OMPTeamsDirective &S) { CGF.EmitStmt(cast(S.getAssociatedStmt())->getCapturedStmt()); CGF.EmitOMPReductionClauseFinal(S, /*ReductionKind=*/OMPD_teams); }; - emitCommonOMPTeamsDirective(*this, S, OMPD_teams, CodeGen); + emitCommonOMPTeamsDirective(*this, S, OMPD_distribute, CodeGen); emitPostUpdateForReductionClause( *this, S, [](CodeGenFunction &) -> llvm::Value * { return nullptr; }); } @@ -4128,6 +4128,8 @@ static void emitTargetParallelForRegion(CodeGenFunction &CGF, // Emit directive as a combined directive that consists of two implicit // directives: 'parallel' with 'for' directive. auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &) { + CodeGenFunction::OMPCancelStackRAII CancelRegion( + CGF, OMPD_target_parallel_for, S.hasCancel()); CGF.EmitOMPWorksharingLoop(S, S.getEnsureUpperBound(), emitForLoopBounds, emitDispatchForLoopBounds); }; diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 6a2c8ab780..01c35bbd31 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1167,19 +1167,6 @@ private: }; OpenMPCancelExitStack OMPCancelStack; - /// Controls insertion of cancellation exit blocks in worksharing constructs. - class OMPCancelStackRAII { - CodeGenFunction &CGF; - - public: - OMPCancelStackRAII(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, - bool HasCancel) - : CGF(CGF) { - CGF.OMPCancelStack.enter(CGF, Kind, HasCancel); - } - ~OMPCancelStackRAII() { CGF.OMPCancelStack.exit(CGF); } - }; - CodeGenPGO PGO; /// Calculate branch weights appropriate for PGO data @@ -2679,6 +2666,19 @@ public: void EmitCXXForRangeStmt(const CXXForRangeStmt &S, ArrayRef Attrs = None); + /// Controls insertion of cancellation exit blocks in worksharing constructs. + class OMPCancelStackRAII { + CodeGenFunction &CGF; + + public: + OMPCancelStackRAII(CodeGenFunction &CGF, OpenMPDirectiveKind Kind, + bool HasCancel) + : CGF(CGF) { + CGF.OMPCancelStack.enter(CGF, Kind, HasCancel); + } + ~OMPCancelStackRAII() { CGF.OMPCancelStack.exit(CGF); } + }; + /// Returns calculated size of the specified type. llvm::Value *getTypeSize(QualType Ty); LValue InitCapturedStruct(const CapturedStmt &S); diff --git a/test/OpenMP/target_parallel_for_codegen.cpp b/test/OpenMP/target_parallel_for_codegen.cpp index 3766413f33..1df6e04682 100644 --- a/test/OpenMP/target_parallel_for_codegen.cpp +++ b/test/OpenMP/target_parallel_for_codegen.cpp @@ -105,6 +105,7 @@ int foo(int n) { // CHECK: [[END]] #pragma omp target parallel for for (int i = 3; i < 32; i += 5) { +#pragma omp cancel for } // CHECK: call void [[HVT1:@.+]](i[[SZ]] {{[^,]+}}, i{{32|64}}{{[*]*}} {{[^)]+}}) @@ -323,8 +324,9 @@ int foo(int n) { // // // CHECK: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias %.global_tid., i32* noalias %.bound_tid.) +// CHECK: call i32 @__kmpc_cancel(%ident_t* @ // CHECK: ret void -// CHECK-NEXT: } +// CHECK: } // CHECK: define internal void [[HVT1]](i[[SZ]] %{{.+}}, i{{32|64}}{{[*]*.*}} %{{.+}})