Skip to content

Commit fac7259

Browse files
committed
Revert "[OPENMP50]Codegen for scan directive in simd loops."
This reverts commit fb80e67 to resolve the issue with asan buildbots.
1 parent e82eff7 commit fac7259

File tree

3 files changed

+21
-420
lines changed

3 files changed

+21
-420
lines changed

clang/lib/CodeGen/CGStmtOpenMP.cpp

+3-112
Original file line numberDiff line numberDiff line change
@@ -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

20972088
void CodeGenFunction::EmitOMPSimdFinal(
@@ -2287,8 +2278,6 @@ static void emitOMPSimdRegion(CodeGenFunction &CGF, const OMPLoopDirective &S,
22872278
}
22882279

22892280
void 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

42124201
void 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)) {

clang/lib/Sema/SemaOpenMP.cpp

+18-31
Original file line numberDiff line numberDiff line change
@@ -15150,37 +15150,24 @@ static bool actOnOMPReductionKindClause(
1515015150
S.ActOnFinishFullExpr(CopyOpRes.get(), /*DiscardedValue=*/true);
1515115151
if (!CopyOpRes.isUsable())
1515215152
continue;
15153-
// For simd directive and simd-based directives in simd mode no need to
15154-
// construct temp array, need just a single temp element.
15155-
if (Stack->getCurrentDirective() == OMPD_simd ||
15156-
(S.getLangOpts().OpenMPSimd &&
15157-
isOpenMPSimdDirective(Stack->getCurrentDirective()))) {
15158-
VarDecl *TempArrayVD =
15159-
buildVarDecl(S, ELoc, PrivateTy, D->getName(),
15160-
D->hasAttrs() ? &D->getAttrs() : nullptr);
15161-
// Add a constructor to the temp decl.
15162-
S.ActOnUninitializedDecl(TempArrayVD);
15163-
TempArrayRes = buildDeclRefExpr(S, TempArrayVD, PrivateTy, ELoc);
15164-
} else {
15165-
// Build temp array for prefix sum.
15166-
auto *Dim = new (S.Context)
15167-
OpaqueValueExpr(ELoc, S.Context.getSizeType(), VK_RValue);
15168-
QualType ArrayTy =
15169-
S.Context.getVariableArrayType(PrivateTy, Dim, ArrayType::Normal,
15170-
/*IndexTypeQuals=*/0, {ELoc, ELoc});
15171-
VarDecl *TempArrayVD =
15172-
buildVarDecl(S, ELoc, ArrayTy, D->getName(),
15173-
D->hasAttrs() ? &D->getAttrs() : nullptr);
15174-
// Add a constructor to the temp decl.
15175-
S.ActOnUninitializedDecl(TempArrayVD);
15176-
TempArrayRes = buildDeclRefExpr(S, TempArrayVD, ArrayTy, ELoc);
15177-
TempArrayElem =
15178-
S.DefaultFunctionArrayLvalueConversion(TempArrayRes.get());
15179-
auto *Idx = new (S.Context)
15180-
OpaqueValueExpr(ELoc, S.Context.getSizeType(), VK_RValue);
15181-
TempArrayElem = S.CreateBuiltinArraySubscriptExpr(TempArrayElem.get(),
15182-
ELoc, Idx, ELoc);
15183-
}
15153+
// Build temp array for prefix sum.
15154+
auto *Dim = new (S.Context)
15155+
OpaqueValueExpr(ELoc, S.Context.getSizeType(), VK_RValue);
15156+
QualType ArrayTy =
15157+
S.Context.getVariableArrayType(PrivateTy, Dim, ArrayType::Normal,
15158+
/*IndexTypeQuals=*/0, {ELoc, ELoc});
15159+
VarDecl *TempArrayVD =
15160+
buildVarDecl(S, ELoc, ArrayTy, D->getName(),
15161+
D->hasAttrs() ? &D->getAttrs() : nullptr);
15162+
// Add a constructor to the temp decl.
15163+
S.ActOnUninitializedDecl(TempArrayVD);
15164+
TempArrayRes = buildDeclRefExpr(S, TempArrayVD, ArrayTy, ELoc);
15165+
TempArrayElem =
15166+
S.DefaultFunctionArrayLvalueConversion(TempArrayRes.get());
15167+
auto *Idx = new (S.Context)
15168+
OpaqueValueExpr(ELoc, S.Context.getSizeType(), VK_RValue);
15169+
TempArrayElem = S.CreateBuiltinArraySubscriptExpr(TempArrayElem.get(),
15170+
ELoc, Idx, ELoc);
1518415171
}
1518515172

1518615173
// OpenMP [2.15.4.6, Restrictions, p.2]

0 commit comments

Comments
 (0)