Skip to content

Commit

Permalink
[ScopInfo] Do not use ScopStmt in Domain derivation of ScopInfo. NFC
Browse files Browse the repository at this point in the history
ScopStmts were being used in the computation of the Domain of the SCoPs
in ScopInfo. Once statements are split, there will not be a 1-to-1
correspondence between Stmts and Basic blocks. Thus this patch avoids
the use of getStmtFor() by creating a map of BB to InvalidDomain and
using it to compute the domain of the statements.

Contributed-by: Nanidini Singhal <cs15mtech01004@iith.ac.in>

Differential Revision: https://reviews.llvm.org/D33942

llvm-svn: 306667
  • Loading branch information
Meinersbur committed Jun 29, 2017
1 parent 8996346 commit 476f855
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 118 deletions.
88 changes: 53 additions & 35 deletions polly/include/polly/ScopInfo.h
Expand Up @@ -1540,14 +1540,6 @@ class ScopStmt {
/// @param NewDomain The new statement domain.
void restrictDomain(__isl_take isl_set *NewDomain);

/// Compute the isl representation for the SCEV @p E in this stmt.
///
/// @param E The SCEV that should be translated.
/// @param NonNegative Flag to indicate the @p E has to be non-negative.
///
/// Note that this function will also adjust the invalid context accordingly.
__isl_give isl_pw_aff *getPwAff(const SCEV *E, bool NonNegative = false);

/// Get the loop for a dimension.
///
/// @param Dimension The dimension of the induction variable
Expand Down Expand Up @@ -1837,14 +1829,17 @@ class Scop {
/// block in the @p FinishedExitBlocks set so we can later skip edges from
/// within the region to that block.
///
/// @param BB The block for which the domain is currently propagated.
/// @param BBLoop The innermost affine loop surrounding @p BB.
/// @param BB The block for which the domain is currently
/// propagated.
/// @param BBLoop The innermost affine loop surrounding @p BB.
/// @param FinishedExitBlocks Set of region exits the domain was set for.
/// @param LI The LoopInfo for the current function.
///
/// @param LI The LoopInfo for the current function.
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
/// region.
void propagateDomainConstraintsToRegionExit(
BasicBlock *BB, Loop *BBLoop,
SmallPtrSetImpl<BasicBlock *> &FinishedExitBlocks, LoopInfo &LI);
SmallPtrSetImpl<BasicBlock *> &FinishedExitBlocks, LoopInfo &LI,
DenseMap<BasicBlock *, __isl_keep isl_set *> &InvalidDomainMap);

/// Compute the union of predecessor domains for @p BB.
///
Expand All @@ -1864,30 +1859,43 @@ class Scop {

/// Add loop carried constraints to the header block of the loop @p L.
///
/// @param L The loop to process.
/// @param LI The LoopInfo for the current function.
/// @param L The loop to process.
/// @param LI The LoopInfo for the current function.
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
/// region.
///
/// @returns True if there was no problem and false otherwise.
bool addLoopBoundsToHeaderDomain(Loop *L, LoopInfo &LI);
bool addLoopBoundsToHeaderDomain(
Loop *L, LoopInfo &LI,
DenseMap<BasicBlock *, __isl_keep isl_set *> &InvalidDomainMap);

/// Compute the branching constraints for each basic block in @p R.
///
/// @param R The region we currently build branching conditions for.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
/// @param R The region we currently build branching conditions
/// for.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
/// region.
///
/// @returns True if there was no problem and false otherwise.
bool buildDomainsWithBranchConstraints(Region *R, DominatorTree &DT,
LoopInfo &LI);
bool buildDomainsWithBranchConstraints(
Region *R, DominatorTree &DT, LoopInfo &LI,
DenseMap<BasicBlock *, __isl_keep isl_set *> &InvalidDomainMap);

/// Propagate the domain constraints through the region @p R.
///
/// @param R The region we currently build branching conditions for.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
/// @param R The region we currently build branching conditions
/// for.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
/// region.
///
/// @returns True if there was no problem and false otherwise.
bool propagateDomainConstraints(Region *R, DominatorTree &DT, LoopInfo &LI);
bool propagateDomainConstraints(
Region *R, DominatorTree &DT, LoopInfo &LI,
DenseMap<BasicBlock *, __isl_keep isl_set *> &InvalidDomainMap);

/// Propagate invalid domains of statements through @p R.
///
Expand All @@ -1896,21 +1904,29 @@ class Scop {
/// of error statements and those only reachable via error statements will be
/// replaced by an empty set. Later those will be removed completely.
///
/// @param R The currently traversed region.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
///
/// @param R The currently traversed region.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
/// region.
//
/// @returns True if there was no problem and false otherwise.
bool propagateInvalidStmtDomains(Region *R, DominatorTree &DT, LoopInfo &LI);
bool propagateInvalidStmtDomains(
Region *R, DominatorTree &DT, LoopInfo &LI,
DenseMap<BasicBlock *, __isl_keep isl_set *> &InvalidDomainMap);

/// Compute the domain for each basic block in @p R.
///
/// @param R The region we currently traverse.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
/// @param R The region we currently traverse.
/// @param DT The DominatorTree for the current function.
/// @param LI The LoopInfo for the current function.
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
/// region.
///
/// @returns True if there was no problem and false otherwise.
bool buildDomains(Region *R, DominatorTree &DT, LoopInfo &LI);
bool
buildDomains(Region *R, DominatorTree &DT, LoopInfo &LI,
DenseMap<BasicBlock *, __isl_keep isl_set *> &InvalidDomainMap);

/// Add parameter constraints to @p C that imply a non-empty domain.
__isl_give isl_set *addNonEmptyDomainConstraints(__isl_take isl_set *C) const;
Expand Down Expand Up @@ -2018,7 +2034,9 @@ class Scop {
void buildContext();

/// Add user provided parameter constraints to context (source code).
void addUserAssumptions(AssumptionCache &AC, DominatorTree &DT, LoopInfo &LI);
void addUserAssumptions(
AssumptionCache &AC, DominatorTree &DT, LoopInfo &LI,
DenseMap<BasicBlock *, __isl_keep isl_set *> &InvalidDomainMap);

/// Add user provided parameter constraints to context (command line).
void addUserContext();
Expand Down
21 changes: 20 additions & 1 deletion polly/include/polly/Support/ScopHelper.h
Expand Up @@ -426,5 +426,24 @@ llvm::BasicBlock *getUseBlock(llvm::Use &U);
std::tuple<std::vector<const llvm::SCEV *>, std::vector<int>>
getIndexExpressionsFromGEP(llvm::GetElementPtrInst *GEP,
llvm::ScalarEvolution &SE);

// If the loop is nonaffine/boxed, return the first non-boxed surrounding loop
// for Polly. If the loop is affine, return the loop itself.
//
// @param L Pointer to the Loop object to analyze.
// @param LI Reference to the LoopInfo.
// @param BoxedLoops Set of Boxed Loops we get from the SCoP.
llvm::Loop *getFirstNonBoxedLoopFor(llvm::Loop *L, llvm::LoopInfo &LI,
const BoxedLoopsSetTy &BoxedLoops);

// If the Basic Block belongs to a loop that is nonaffine/boxed, return the
// first non-boxed surrounding loop for Polly. If the loop is affine, return
// the loop itself.
//
// @param BB Pointer to the Basic Block to analyze.
// @param LI Reference to the LoopInfo.
// @param BoxedLoops Set of Boxed Loops we get from the SCoP.
llvm::Loop *getFirstNonBoxedLoopFor(llvm::BasicBlock *BB, llvm::LoopInfo &LI,
const BoxedLoopsSetTy &BoxedLoops);
} // namespace polly
#endif
#endif
35 changes: 29 additions & 6 deletions polly/lib/Analysis/ScopBuilder.cpp
Expand Up @@ -627,10 +627,8 @@ void ScopBuilder::buildAccessFunctions() {

void ScopBuilder::buildStmts(Region &SR) {
if (scop->isNonAffineSubRegion(&SR)) {
Loop *SurroundingLoop = LI.getLoopFor(SR.getEntry());
auto &BoxedLoops = scop->getBoxedLoops();
while (BoxedLoops.count(SurroundingLoop))
SurroundingLoop = SurroundingLoop->getParentLoop();
Loop *SurroundingLoop =
getFirstNonBoxedLoopFor(SR.getEntry(), LI, scop->getBoxedLoops());
scop->addScopStmt(&SR, SurroundingLoop);
return;
}
Expand Down Expand Up @@ -930,6 +928,12 @@ static void verifyUses(Scop *S, LoopInfo &LI, DominatorTree &DT) {
}
#endif

/// Return the block that is the representing block for @p RN.
static inline BasicBlock *getRegionNodeBasicBlock(RegionNode *RN) {
return RN->isSubRegion() ? RN->getNodeAs<Region>()->getEntry()
: RN->getNodeAs<BasicBlock>();
}

void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
scop.reset(new Scop(R, SE, LI, *SD.getDetectionContext(&R)));

Expand Down Expand Up @@ -959,10 +963,29 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {

scop->buildInvariantEquivalenceClasses();

if (!scop->buildDomains(&R, DT, LI))
/// A map from basic blocks to their invalid domains.
DenseMap<BasicBlock *, isl_set *> InvalidDomainMap;

if (!scop->buildDomains(&R, DT, LI, InvalidDomainMap)) {
for (auto It : InvalidDomainMap)
isl_set_free(It.second);
return;
}

scop->addUserAssumptions(AC, DT, LI, InvalidDomainMap);

// Initialize the invalid domain.
for (ScopStmt &Stmt : scop->Stmts)
if (Stmt.isBlockStmt())
Stmt.setInvalidDomain(
isl_set_copy(InvalidDomainMap[Stmt.getEntryBlock()]));
else
Stmt.setInvalidDomain(
isl_set_copy(InvalidDomainMap[getRegionNodeBasicBlock(
Stmt.getRegion()->getNode())]));

scop->addUserAssumptions(AC, DT, LI);
for (auto It : InvalidDomainMap)
isl_set_free(It.second);

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

0 comments on commit 476f855

Please sign in to comment.