[PATCH] D71475: [WIP][OPENMP] Try to fix linear clause crash by emitting alloca for step

Alexey Bataev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 17 07:28:35 PST 2019


ABataev added a comment.

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 =



================
Comment at: clang/lib/Sema/SemaOpenMP.cpp:1128
+           (A == OMPC_firstprivate && (Data.Attributes == OMPC_lastprivate ||
+                                       Data.Attributes == OMPC_linear)) ||
            (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) ||
----------------
What is this change for?


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