summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorJonas Hahnfeld <hahnjo@hahnjo.de>2017-10-20 20:16:17 +0000
committerJonas Hahnfeld <hahnjo@hahnjo.de>2017-10-20 20:16:17 +0000
commitc95a6985bd4e57cbf2ba39a897e2af2e8edbba08 (patch)
treecf053e0929d0288a09a2a76e4e39de83035a93f4 /clang/lib
parent7b16ae201f16aaafc3bded2e829c1221b8c0f6c4 (diff)
downloadbcm5719-llvm-c95a6985bd4e57cbf2ba39a897e2af2e8edbba08.tar.gz
bcm5719-llvm-c95a6985bd4e57cbf2ba39a897e2af2e8edbba08.zip
Revert "[OpenMP] Avoid VLAs for some reductions on array sections"
This breaks at least two buildbots: http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux/builds/1175 http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/10478 This reverts commit r316229 during local investigation. llvm-svn: 316235
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGOpenMPRuntime.cpp10
-rw-r--r--clang/lib/CodeGen/CGStmtOpenMP.cpp7
-rw-r--r--clang/lib/Sema/SemaOpenMP.cpp83
3 files changed, 9 insertions, 91 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 3396c63cd62..f98ff85565f 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -925,7 +925,7 @@ void ReductionCodeGen::emitAggregateType(CodeGenFunction &CGF, unsigned N) {
cast<VarDecl>(cast<DeclRefExpr>(ClausesData[N].Private)->getDecl());
QualType PrivateType = PrivateVD->getType();
bool AsArraySection = isa<OMPArraySectionExpr>(ClausesData[N].Ref);
- if (!PrivateType->isVariablyModifiedType()) {
+ if (!AsArraySection && !PrivateType->isVariablyModifiedType()) {
Sizes.emplace_back(
CGF.getTypeSize(
SharedAddresses[N].first.getType().getNonReferenceType()),
@@ -963,9 +963,10 @@ void ReductionCodeGen::emitAggregateType(CodeGenFunction &CGF, unsigned N,
auto *PrivateVD =
cast<VarDecl>(cast<DeclRefExpr>(ClausesData[N].Private)->getDecl());
QualType PrivateType = PrivateVD->getType();
- if (!PrivateType->isVariablyModifiedType()) {
+ bool AsArraySection = isa<OMPArraySectionExpr>(ClausesData[N].Ref);
+ if (!AsArraySection && !PrivateType->isVariablyModifiedType()) {
assert(!Size && !Sizes[N].second &&
- "Size should be nullptr for non-variably modified reduction "
+ "Size should be nullptr for non-variably modified redution "
"items.");
return;
}
@@ -993,7 +994,8 @@ void ReductionCodeGen::emitInitialization(
CGF.ConvertTypeForMem(SharedType)),
SharedType, SharedAddresses[N].first.getBaseInfo(),
CGF.CGM.getTBAAAccessInfo(SharedType));
- if (CGF.getContext().getAsArrayType(PrivateVD->getType())) {
+ if (isa<OMPArraySectionExpr>(ClausesData[N].Ref) ||
+ CGF.getContext().getAsArrayType(PrivateVD->getType())) {
emitAggregateInitialization(CGF, N, PrivateAddr, SharedLVal, DRD);
} else if (DRD && (DRD->getInitializer() || !PrivateVD->hasInit())) {
emitInitWithReductionInitializer(CGF, DRD, ClausesData[N].ReductionOp,
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 0e5ea798ebd..cdec3e35f97 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -996,9 +996,7 @@ void CodeGenFunction::EmitOMPReductionClauseInit(
auto *LHSVD = cast<VarDecl>(cast<DeclRefExpr>(*ILHS)->getDecl());
auto *RHSVD = cast<VarDecl>(cast<DeclRefExpr>(*IRHS)->getDecl());
- QualType Type = PrivateVD->getType();
- bool isaOMPArraySectionExpr = isa<OMPArraySectionExpr>(IRef);
- if (isaOMPArraySectionExpr && Type->isVariablyModifiedType()) {
+ if (isa<OMPArraySectionExpr>(IRef)) {
// Store the address of the original variable associated with the LHS
// implicit variable.
PrivateScope.addPrivate(LHSVD, [&RedCG, Count]() -> Address {
@@ -1007,8 +1005,7 @@ void CodeGenFunction::EmitOMPReductionClauseInit(
PrivateScope.addPrivate(RHSVD, [this, PrivateVD]() -> Address {
return GetAddrOfLocalVar(PrivateVD);
});
- } else if ((isaOMPArraySectionExpr && Type->isScalarType()) ||
- isa<ArraySubscriptExpr>(IRef)) {
+ } else if (isa<ArraySubscriptExpr>(IRef)) {
// Store the address of the original variable associated with the LHS
// implicit variable.
PrivateScope.addPrivate(LHSVD, [&RedCG, Count]() -> Address {
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index bf89eb0b2f2..a024888fbf0 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -9330,68 +9330,6 @@ struct ReductionData {
};
} // namespace
-static bool CheckOMPArraySectionConstantForReduction(
- ASTContext &Context, const OMPArraySectionExpr *OASE, bool &SingleElement,
- SmallVectorImpl<llvm::APSInt> &ArraySizes) {
- const Expr *Length = OASE->getLength();
- if (Length == nullptr) {
- // For array sections of the form [1:] or [:], we would need to analyze
- // the lower bound...
- if (OASE->getColonLoc().isValid())
- return false;
-
- // This is an array subscript which has implicit length 1!
- SingleElement = true;
- ArraySizes.push_back(llvm::APSInt::get(1));
- } else {
- llvm::APSInt ConstantLengthValue;
- if (!Length->EvaluateAsInt(ConstantLengthValue, Context))
- return false;
-
- SingleElement = (ConstantLengthValue.getSExtValue() == 1);
- ArraySizes.push_back(ConstantLengthValue);
- }
-
- // Get the base of this array section and walk up from there.
- const Expr *Base = OASE->getBase()->IgnoreParenImpCasts();
-
- // We require length = 1 for all array sections except the right-most to
- // guarantee that the memory region is contiguous and has no holes in it.
- while (const auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) {
- Length = TempOASE->getLength();
- if (Length == nullptr) {
- // For array sections of the form [1:] or [:], we would need to analyze
- // the lower bound...
- if (OASE->getColonLoc().isValid())
- return false;
-
- // This is an array subscript which has implicit length 1!
- ArraySizes.push_back(llvm::APSInt::get(1));
- } else {
- llvm::APSInt ConstantLengthValue;
- if (!Length->EvaluateAsInt(ConstantLengthValue, Context) ||
- ConstantLengthValue.getSExtValue() != 1)
- return false;
-
- ArraySizes.push_back(ConstantLengthValue);
- }
- Base = TempOASE->getBase()->IgnoreParenImpCasts();
- }
-
- // If we have a single element, we don't need to add the implicit lengths.
- if (!SingleElement) {
- while (const auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) {
- // Has implicit length 1!
- ArraySizes.push_back(llvm::APSInt::get(1));
- Base = TempASE->getBase()->IgnoreParenImpCasts();
- }
- }
-
- // This array section can be privatized as a single value or as a constant
- // sized array.
- return true;
-}
-
static bool ActOnOMPReductionKindClause(
Sema &S, DSAStackTy *Stack, OpenMPClauseKind ClauseKind,
ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc,
@@ -9690,26 +9628,7 @@ static bool ActOnOMPReductionKindClause(
auto *RHSVD = buildVarDecl(S, ELoc, Type, D->getName(),
D->hasAttrs() ? &D->getAttrs() : nullptr);
auto PrivateTy = Type;
-
- // Try if we can determine constant lengths for all array sections and avoid
- // the VLA.
- bool ConstantLengthOASE = false;
- if (OASE) {
- bool SingleElement;
- llvm::SmallVector<llvm::APSInt, 4> ArraySizes;
- ConstantLengthOASE = CheckOMPArraySectionConstantForReduction(
- Context, OASE, SingleElement, ArraySizes);
-
- // If we don't have a single element, we must emit a constant array type.
- if (ConstantLengthOASE && !SingleElement) {
- for (auto &Size : ArraySizes) {
- PrivateTy = Context.getConstantArrayType(
- PrivateTy, Size, ArrayType::Normal, /*IndexTypeQuals=*/0);
- }
- }
- }
-
- if ((OASE && !ConstantLengthOASE) ||
+ if (OASE ||
(!ASE &&
D->getType().getNonReferenceType()->isVariablyModifiedType())) {
// For arrays/array sections only:
OpenPOWER on IntegriCloud