[PATCH] D71475: [WIP][OPENMP] Try to fix linear clause crash by emitting alloca for step
Chi Chun Chen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 17 08:53:10 PST 2019
cchen added a comment.
In D71475#1787914 <https://reviews.llvm.org/D71475#1787914>, @ABataev wrote:
> Here is more proper fix. We don't need to capture just `k` here, instead, we need to capture the whole expression.
> Linear clause has a little bit different processing rather than all other clauses caused by a non-perfect design. Add codegen tests for all combined constructs that may require capturing of the linear step expression. Probably, some additional work in codegen may be required.
>
> diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
> index afe0f1a..cb55ace 100644
> --- a/clang/lib/Sema/SemaOpenMP.cpp
> +++ b/clang/lib/Sema/SemaOpenMP.cpp
> @@ -3830,6 +3830,9 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
> MarkDeclarationsReferencedInExpr(E);
> }
> }
> + if (auto *LC = dyn_cast<OMPLinearClause>(Clause))
> + if (Expr *E = LC->getStep())
> + MarkDeclarationsReferencedInExpr(E);
> DSAStack->setForceVarCapturing(/*V=*/false);
> } else if (CaptureRegions.size() > 1 ||
> CaptureRegions.back() != OMPD_unknown) {
> @@ -11396,12 +11399,87 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
> llvm_unreachable("Unknown OpenMP directive");
> }
> break;
> + case OMPC_linear:
> + switch (DKind) {
> + case OMPD_taskloop_simd:
> + case OMPD_master_taskloop_simd:
> + case OMPD_parallel_master_taskloop_simd:
> + CaptureRegion = OMPD_taskloop;
> + break;
> + case OMPD_target_simd:
> + CaptureRegion = OMPD_target;
> + break;
> + case OMPD_target_teams_distribute_simd:
> + case OMPD_teams_distribute_simd:
> + CaptureRegion = OMPD_teams;
> + break;
> + case OMPD_target_parallel_for:
> + case OMPD_target_parallel_for_simd:
> + case OMPD_target_teams_distribute_parallel_for:
> + case OMPD_target_teams_distribute_parallel_for_simd:
> + case OMPD_teams_distribute_parallel_for:
> + case OMPD_teams_distribute_parallel_for_simd:
> + case OMPD_distribute_parallel_for:
> + case OMPD_distribute_parallel_for_simd:
> + case OMPD_parallel_for:
> + case OMPD_parallel_for_simd:
> + CaptureRegion = OMPD_parallel;
> + break;
> + case OMPD_parallel_master_taskloop:
> + case OMPD_task:
> + case OMPD_taskloop:
> + case OMPD_master_taskloop:
> + case OMPD_target_update:
> + case OMPD_target_enter_data:
> + case OMPD_target_exit_data:
> + case OMPD_target:
> + case OMPD_target_teams:
> + case OMPD_target_parallel:
> + case OMPD_target_teams_distribute:
> + case OMPD_target_data:
> + case OMPD_teams:
> + case OMPD_teams_distribute:
> + case OMPD_cancel:
> + case OMPD_parallel:
> + case OMPD_parallel_master:
> + case OMPD_parallel_sections:
> + case OMPD_threadprivate:
> + case OMPD_allocate:
> + case OMPD_taskyield:
> + case OMPD_barrier:
> + case OMPD_taskwait:
> + case OMPD_cancellation_point:
> + case OMPD_flush:
> + case OMPD_declare_reduction:
> + case OMPD_declare_mapper:
> + case OMPD_declare_simd:
> + case OMPD_declare_variant:
> + case OMPD_declare_target:
> + case OMPD_end_declare_target:
> + case OMPD_simd:
> + case OMPD_for:
> + case OMPD_for_simd:
> + case OMPD_sections:
> + case OMPD_section:
> + case OMPD_single:
> + case OMPD_master:
> + case OMPD_critical:
> + case OMPD_taskgroup:
> + case OMPD_distribute:
> + case OMPD_ordered:
> + case OMPD_atomic:
> + case OMPD_distribute_simd:
> + case OMPD_requires:
> + llvm_unreachable("Unexpected OpenMP directive with linear-clause");
> + case OMPD_unknown:
> + llvm_unreachable("Unknown OpenMP directive");
> + }
> + break;
> case OMPC_firstprivate:
> case OMPC_lastprivate:
> case OMPC_reduction:
> case OMPC_task_reduction:
> case OMPC_in_reduction:
> - case OMPC_linear:
> case OMPC_default:
> case OMPC_proc_bind:
> case OMPC_safelen:
> @@ -14377,6 +14455,16 @@ OMPClause *Sema::ActOnOpenMPLinearClause(
> if (Val.isInvalid())
> return nullptr;
> StepExpr = Val.get();
> + OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
> + OpenMPDirectiveKind CaptureRegion =
> + getOpenMPCaptureRegionForClause(DKind, OMPC_linear, LangOpts.OpenMP);
> + if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) {
> + StepExpr = MakeFullExpr(StepExpr).get();
> + llvm::MapVector<const Expr *, DeclRefExpr *> Captures;
> + StepExpr = tryBuildCapture(*this, StepExpr, Captures).get();
> + for (const auto &Pair : Captures)
> + ExprCaptures.push_back(Pair.second->getDecl());
> + }
>
> // Build var to save the step value.
> VarDecl *SaveVar =
>
>
Applying this will make many tests fail on `llvm_unreachable("Unexpected OpenMP directive with linear-clause");`.
Test failed:
Clang :: OpenMP/distribute_simd_ast_print.cpp
Clang :: OpenMP/distribute_simd_linear_messages.cpp
Clang :: OpenMP/for_ast_print.cpp
Clang :: OpenMP/for_linear_codegen.cpp
Clang :: OpenMP/for_linear_messages.cpp
Clang :: OpenMP/for_simd_ast_print.cpp
Clang :: OpenMP/for_simd_codegen.cpp
Clang :: OpenMP/for_simd_linear_messages.cpp
Clang :: OpenMP/for_simd_misc_messages.c
Clang :: OpenMP/loops_explicit_clauses_codegen.cpp
Clang :: OpenMP/master_taskloop_simd_linear_messages.cpp
Clang :: OpenMP/parallel_for_linear_codegen.cpp
Clang :: OpenMP/parallel_for_linear_messages.cpp
Clang :: OpenMP/parallel_for_simd_codegen.cpp
Clang :: OpenMP/parallel_for_simd_linear_messages.cpp
Clang :: OpenMP/parallel_master_taskloop_simd_linear_messages.cpp
Clang :: OpenMP/simd_ast_print.cpp
Clang :: OpenMP/simd_codegen.cpp
Clang :: OpenMP/simd_linear_messages.cpp
Clang :: OpenMP/simd_misc_messages.c
Clang :: OpenMP/target_parallel_for_codegen.cpp
Clang :: OpenMP/target_parallel_for_linear_messages.cpp
Clang :: OpenMP/target_parallel_for_simd_codegen.cpp
Clang :: OpenMP/target_parallel_for_simd_linear_messages.cpp
Clang :: OpenMP/target_simd_codegen.cpp
Clang :: OpenMP/target_simd_linear_messages.cpp
Clang :: OpenMP/target_teams_distribute_parallel_for_simd_codegen.cpp
Clang :: OpenMP/target_teams_distribute_parallel_for_simd_linear_messages.cpp
Clang :: OpenMP/target_teams_distribute_simd_linear_messages.cpp
Clang :: OpenMP/taskloop_simd_linear_messages.cpp
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71475/new/
https://reviews.llvm.org/D71475
More information about the cfe-commits
mailing list