@@ -2083,15 +2083,6 @@ void CodeGenFunction::EmitOMPSimdInit(const OMPLoopDirective &D,
20832083 if (const auto *C = D.getSingleClause <OMPOrderClause>())
20842084 if (C->getKind () == OMPC_ORDER_concurrent)
20852085 LoopStack.setParallel (/* Enable=*/ true );
2086- if ((D.getDirectiveKind () == OMPD_simd ||
2087- (getLangOpts ().OpenMPSimd &&
2088- isOpenMPSimdDirective (D.getDirectiveKind ()))) &&
2089- llvm::any_of (D.getClausesOfKind <OMPReductionClause>(),
2090- [](const OMPReductionClause *C) {
2091- return C->getModifier () == OMPC_REDUCTION_inscan;
2092- }))
2093- // Disable parallel access in case of prefix sum.
2094- LoopStack.setParallel (/* Enable=*/ false );
20952086}
20962087
20972088void CodeGenFunction::EmitOMPSimdFinal (
@@ -2287,8 +2278,6 @@ static void emitOMPSimdRegion(CodeGenFunction &CGF, const OMPLoopDirective &S,
22872278}
22882279
22892280void CodeGenFunction::EmitOMPSimdDirective (const OMPSimdDirective &S) {
2290- ParentLoopDirectiveForScanRegion ScanRegion (*this , S);
2291- OMPFirstScanLoop = true ;
22922281 auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
22932282 emitOMPSimdRegion (CGF, S, Action);
22942283 };
@@ -4210,15 +4199,14 @@ void CodeGenFunction::EmitOMPDepobjDirective(const OMPDepobjDirective &S) {
42104199}
42114200
42124201void CodeGenFunction::EmitOMPScanDirective (const OMPScanDirective &S) {
4213- if (!OMPParentLoopDirectiveForScan)
4202+ // Do not emit code for non-simd directives in simd-only mode.
4203+ if (getLangOpts ().OpenMPSimd && !OMPParentLoopDirectiveForScan)
42144204 return ;
42154205 const OMPExecutableDirective &ParentDir = *OMPParentLoopDirectiveForScan;
4216- bool IsInclusive = S.hasClausesOfKind <OMPInclusiveClause>();
42174206 SmallVector<const Expr *, 4 > Shareds;
42184207 SmallVector<const Expr *, 4 > Privates;
42194208 SmallVector<const Expr *, 4 > LHSs;
42204209 SmallVector<const Expr *, 4 > RHSs;
4221- SmallVector<const Expr *, 4 > ReductionOps;
42224210 SmallVector<const Expr *, 4 > CopyOps;
42234211 SmallVector<const Expr *, 4 > CopyArrayTemps;
42244212 SmallVector<const Expr *, 4 > CopyArrayElems;
@@ -4229,109 +4217,13 @@ void CodeGenFunction::EmitOMPScanDirective(const OMPScanDirective &S) {
42294217 Privates.append (C->privates ().begin (), C->privates ().end ());
42304218 LHSs.append (C->lhs_exprs ().begin (), C->lhs_exprs ().end ());
42314219 RHSs.append (C->rhs_exprs ().begin (), C->rhs_exprs ().end ());
4232- ReductionOps.append (C->reduction_ops ().begin (), C->reduction_ops ().end ());
42334220 CopyOps.append (C->copy_ops ().begin (), C->copy_ops ().end ());
42344221 CopyArrayTemps.append (C->copy_array_temps ().begin (),
42354222 C->copy_array_temps ().end ());
42364223 CopyArrayElems.append (C->copy_array_elems ().begin (),
42374224 C->copy_array_elems ().end ());
42384225 }
4239- if (ParentDir.getDirectiveKind () == OMPD_simd ||
4240- (getLangOpts ().OpenMPSimd &&
4241- isOpenMPSimdDirective (ParentDir.getDirectiveKind ()))) {
4242- // For simd directive and simd-based directives in simd only mode, use the
4243- // following codegen:
4244- // int x = 0;
4245- // #pragma omp simd reduction(inscan, +: x)
4246- // for (..) {
4247- // <first part>
4248- // #pragma omp scan inclusive(x)
4249- // <second part>
4250- // }
4251- // is transformed to:
4252- // int x = 0;
4253- // for (..) {
4254- // int x_priv = 0;
4255- // <first part>
4256- // x = x_priv + x;
4257- // x_priv = x;
4258- // <second part>
4259- // }
4260- // and
4261- // int x = 0;
4262- // #pragma omp simd reduction(inscan, +: x)
4263- // for (..) {
4264- // <first part>
4265- // #pragma omp scan exclusive(x)
4266- // <second part>
4267- // }
4268- // to
4269- // int x = 0;
4270- // for (..) {
4271- // int x_priv = 0;
4272- // <second part>
4273- // int temp = x;
4274- // x = x_priv + x;
4275- // x_priv = temp;
4276- // <first part>
4277- // }
4278- llvm::BasicBlock *OMPScanReduce = createBasicBlock (" omp.inscan.reduce" );
4279- EmitBranch (IsInclusive
4280- ? OMPScanReduce
4281- : BreakContinueStack.back ().ContinueBlock .getBlock ());
4282- EmitBlock (OMPScanDispatch);
4283- {
4284- // New scope for correct construction/destruction of temp variables for
4285- // exclusive scan.
4286- LexicalScope Scope (*this , S.getSourceRange ());
4287- EmitBranch (IsInclusive ? OMPBeforeScanBlock : OMPAfterScanBlock);
4288- EmitBlock (OMPScanReduce);
4289- if (!IsInclusive) {
4290- // Create temp var and copy LHS value to this temp value.
4291- // TMP = LHS;
4292- for (unsigned I = 0 , E = CopyArrayElems.size (); I < E; ++I) {
4293- const Expr *PrivateExpr = Privates[I];
4294- const Expr *TempExpr = CopyArrayTemps[I];
4295- EmitAutoVarDecl (
4296- *cast<VarDecl>(cast<DeclRefExpr>(TempExpr)->getDecl ()));
4297- LValue DestLVal = EmitLValue (TempExpr);
4298- LValue SrcLVal = EmitLValue (LHSs[I]);
4299- EmitOMPCopy (PrivateExpr->getType (), DestLVal.getAddress (*this ),
4300- SrcLVal.getAddress (*this ),
4301- cast<VarDecl>(cast<DeclRefExpr>(LHSs[I])->getDecl ()),
4302- cast<VarDecl>(cast<DeclRefExpr>(RHSs[I])->getDecl ()),
4303- CopyOps[I]);
4304- }
4305- }
4306- CGM.getOpenMPRuntime ().emitReduction (
4307- *this , ParentDir.getEndLoc (), Privates, LHSs, RHSs, ReductionOps,
4308- {/* WithNowait=*/ true , /* SimpleReduction=*/ true , OMPD_simd});
4309- for (unsigned I = 0 , E = CopyArrayElems.size (); I < E; ++I) {
4310- const Expr *PrivateExpr = Privates[I];
4311- LValue DestLVal;
4312- LValue SrcLVal;
4313- if (IsInclusive) {
4314- DestLVal = EmitLValue (RHSs[I]);
4315- SrcLVal = EmitLValue (LHSs[I]);
4316- } else {
4317- const Expr *TempExpr = CopyArrayTemps[I];
4318- DestLVal = EmitLValue (RHSs[I]);
4319- SrcLVal = EmitLValue (TempExpr);
4320- }
4321- EmitOMPCopy (PrivateExpr->getType (), DestLVal.getAddress (*this ),
4322- SrcLVal.getAddress (*this ),
4323- cast<VarDecl>(cast<DeclRefExpr>(LHSs[I])->getDecl ()),
4324- cast<VarDecl>(cast<DeclRefExpr>(RHSs[I])->getDecl ()),
4325- CopyOps[I]);
4326- }
4327- }
4328- EmitBranch (IsInclusive ? OMPAfterScanBlock : OMPBeforeScanBlock);
4329- OMPScanExitBlock = IsInclusive
4330- ? BreakContinueStack.back ().ContinueBlock .getBlock ()
4331- : OMPScanReduce;
4332- EmitBlock (OMPAfterScanBlock);
4333- return ;
4334- }
4226+ bool IsInclusive = S.hasClausesOfKind <OMPInclusiveClause>();
43354227 if (!IsInclusive) {
43364228 EmitBranch (BreakContinueStack.back ().ContinueBlock .getBlock ());
43374229 EmitBlock (OMPScanExitBlock);
@@ -6485,7 +6377,6 @@ void CodeGenFunction::EmitSimpleOMPExecutableDirective(
64856377 }
64866378 if (isOpenMPSimdDirective (D.getDirectiveKind ())) {
64876379 (void )GlobalsScope.Privatize ();
6488- ParentLoopDirectiveForScanRegion ScanRegion (CGF, D);
64896380 emitOMPSimdRegion (CGF, cast<OMPLoopDirective>(D), Action);
64906381 } else {
64916382 if (const auto *LD = dyn_cast<OMPLoopDirective>(&D)) {
0 commit comments