Skip to content

Commit

Permalink
Bail as early as possible
Browse files Browse the repository at this point in the history
  Instead of waiting for the domain construction to finish we will now
  bail as early as possible in case a complexity problem is encountered.
  This might save compile time but more importantly it makes the "abort"
  explicit. While we can always check if we invalidated the assumed
  context we can simply propagate the result of the construction back.
  This also removes the HasComplexCFG flag that was used for the very
  same reason.

Differential Revision: http://reviews.llvm.org/D18504

llvm-svn: 264775
  • Loading branch information
Johannes Doerfert committed Mar 29, 2016
1 parent 4884dcf commit 5fb9b21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
11 changes: 6 additions & 5 deletions polly/include/polly/ScopInfo.h
Expand Up @@ -1287,9 +1287,6 @@ class Scop {
/// @brief Flag to remember if the SCoP contained an error block or not.
bool HasErrorBlock;

/// @brief Flag to indicate if the SCop has a complex control flow.
bool HasComplexCFG;

/// Max loop depth.
unsigned MaxLoopDepth;

Expand Down Expand Up @@ -1436,7 +1433,9 @@ class Scop {
/// @param SD The ScopDetection analysis for the current function.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
void buildDomainsWithBranchConstraints(Region *R, ScopDetection &SD,
///
/// @returns True if there was no problem and false otherwise.
bool buildDomainsWithBranchConstraints(Region *R, ScopDetection &SD,
DominatorTree &DT, LoopInfo &LI);

/// @brief Propagate the domain constraints through the region @p R.
Expand All @@ -1463,7 +1462,9 @@ class Scop {
/// @param SD The ScopDetection analysis for the current function.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
void buildDomains(Region *R, ScopDetection &SD, DominatorTree &DT,
///
/// @returns True if there was no problem and false otherwise.
bool buildDomains(Region *R, ScopDetection &SD, DominatorTree &DT,
LoopInfo &LI);

/// @brief Check if a region part should be represented in the SCoP or not.
Expand Down
51 changes: 27 additions & 24 deletions polly/lib/Analysis/ScopInfo.cpp
Expand Up @@ -2143,7 +2143,7 @@ void Scop::removeErrorBlockDomains(ScopDetection &SD, DominatorTree &DT,
removeDomains(BB);
}

void Scop::buildDomains(Region *R, ScopDetection &SD, DominatorTree &DT,
bool Scop::buildDomains(Region *R, ScopDetection &SD, DominatorTree &DT,
LoopInfo &LI) {

bool IsOnlyNonAffineRegion = SD.isNonAffineSubRegion(R, R);
Expand All @@ -2160,9 +2160,11 @@ void Scop::buildDomains(Region *R, ScopDetection &SD, DominatorTree &DT,
DomainMap[EntryBB] = S;

if (IsOnlyNonAffineRegion)
return;
return true;

if (!buildDomainsWithBranchConstraints(R, SD, DT, LI))
return false;

buildDomainsWithBranchConstraints(R, SD, DT, LI);
propagateDomainConstraints(R, SD, DT, LI);

// Error blocks and blocks dominated by them have been assumed to never be
Expand All @@ -2174,9 +2176,10 @@ void Scop::buildDomains(Region *R, ScopDetection &SD, DominatorTree &DT,
// instructions in the error block which, if the error block is not modeled,
// can themselves not be constructed properly.
removeErrorBlockDomains(SD, DT, LI);
return true;
}

void Scop::buildDomainsWithBranchConstraints(Region *R, ScopDetection &SD,
bool Scop::buildDomainsWithBranchConstraints(Region *R, ScopDetection &SD,
DominatorTree &DT, LoopInfo &LI) {
auto &BoxedLoops = *SD.getBoxedLoops(&getRegion());

Expand All @@ -2199,7 +2202,8 @@ void Scop::buildDomainsWithBranchConstraints(Region *R, ScopDetection &SD,
if (RN->isSubRegion()) {
Region *SubRegion = RN->getNodeAs<Region>();
if (!SD.isNonAffineSubRegion(SubRegion, &getRegion())) {
buildDomainsWithBranchConstraints(SubRegion, SD, DT, LI);
if (!buildDomainsWithBranchConstraints(SubRegion, SD, DT, LI))
return false;
continue;
}
}
Expand Down Expand Up @@ -2279,25 +2283,24 @@ void Scop::buildDomainsWithBranchConstraints(Region *R, ScopDetection &SD,
// successor block.
isl_set *&SuccDomain = DomainMap[SuccBB];

if (HasComplexCFG) {
isl_set_free(CondSet);
continue;
}
if (!SuccDomain)
SuccDomain = CondSet;
else
SuccDomain = isl_set_union(SuccDomain, CondSet);

SuccDomain = isl_set_coalesce(SuccDomain);
if (isl_set_n_basic_set(SuccDomain) > MaxConjunctsInDomain) {
auto *Empty = isl_set_empty(isl_set_get_space(SuccDomain));
isl_set_free(SuccDomain);
SuccDomain = Empty;
HasComplexCFG = true;
invalidate(COMPLEXITY, DebugLoc());
}
SuccDomain = isl_set_coalesce(isl_set_union(SuccDomain, CondSet));

// Check if the maximal number of domain conjuncts was reached.
// In case this happens we will clean up and bail.
if (isl_set_n_basic_set(SuccDomain) <= MaxConjunctsInDomain)
continue;

invalidate(COMPLEXITY, DebugLoc());
while (++u < ConditionSets.size())
isl_set_free(ConditionSets[u]);
return false;
}
}

return true;
}

/// @brief Return the domain for @p BB wrt @p DomainMap.
Expand Down Expand Up @@ -2771,10 +2774,9 @@ Scop::Scop(Region &R, ScalarEvolution &ScalarEvolution, LoopInfo &LI,
unsigned MaxLoopDepth)
: SE(&ScalarEvolution), R(R), IsOptimized(false),
HasSingleExitEdge(R.getExitingBlock()), HasErrorBlock(false),
HasComplexCFG(false), MaxLoopDepth(MaxLoopDepth),
IslCtx(isl_ctx_alloc(), isl_ctx_free), Context(nullptr),
Affinator(this, LI), AssumedContext(nullptr), InvalidContext(nullptr),
Schedule(nullptr) {
MaxLoopDepth(MaxLoopDepth), IslCtx(isl_ctx_alloc(), isl_ctx_free),
Context(nullptr), Affinator(this, LI), AssumedContext(nullptr),
InvalidContext(nullptr), Schedule(nullptr) {
isl_options_set_on_error(getIslCtx(), ISL_ON_ERROR_ABORT);
buildContext();
}
Expand All @@ -2784,7 +2786,8 @@ void Scop::init(AliasAnalysis &AA, AssumptionCache &AC, ScopDetection &SD,
addUserAssumptions(AC, DT, LI);
buildInvariantEquivalenceClasses(SD);

buildDomains(&R, SD, DT, LI);
if (!buildDomains(&R, SD, DT, LI))
return;

// Remove empty and ignored statements.
// Exit early in case there are no executable statements left in this scop.
Expand Down

0 comments on commit 5fb9b21

Please sign in to comment.