Index: lib/Analysis/ScopBuilder.cpp =================================================================== --- lib/Analysis/ScopBuilder.cpp +++ lib/Analysis/ScopBuilder.cpp @@ -102,6 +102,18 @@ cl::desc("Disable multiplicative reductions"), cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::cat(PollyCategory)); +enum class GranularityChoice { BasicBlocks, Stores }; + +static cl::opt + StmtGranularity("polly-stmt-granularity", + cl::desc("Select the statement granularity algorithm"), + cl::values(clEnumValN(GranularityChoice::BasicBlocks, "bb", + "Entire basic blocks granularity"), + clEnumValN(GranularityChoice::Stores, "store", + "Store-level granularity")), + cl::init(GranularityChoice::BasicBlocks), + cl::cat(PollyCategory)); + void ScopBuilder::buildPHIAccesses(ScopStmt *PHIStmt, PHINode *PHI, Region *NonAffineSubRegion, bool IsExitBlock) { @@ -686,7 +698,9 @@ Loop *L = LI.getLoopFor(Inst.getParent()); if (shouldModelInst(&Inst, L)) Instructions.push_back(&Inst); - if (Inst.getMetadata("polly_split_after")) { + if (Inst.getMetadata("polly_split_after") || + (StmtGranularity == GranularityChoice::Stores && + isa(Inst))) { Loop *SurroundingLoop = LI.getLoopFor(I->getNodeAs()); scop->addScopStmt(I->getNodeAs(), SurroundingLoop, Instructions, Count); @@ -694,9 +708,11 @@ Instructions.clear(); } } - Loop *SurroundingLoop = LI.getLoopFor(I->getNodeAs()); - scop->addScopStmt(I->getNodeAs(), SurroundingLoop, - Instructions, Count); + if (Count == 0 || !Instructions.empty()) { + Loop *SurroundingLoop = LI.getLoopFor(I->getNodeAs()); + scop->addScopStmt(I->getNodeAs(), SurroundingLoop, + Instructions, Count); + } } } @@ -720,9 +736,13 @@ Split = false; Count++; } - if (Inst.getMetadata("polly_split_after")) + if (Inst.getMetadata("polly_split_after") || + (StmtGranularity == GranularityChoice::Stores && isa(Inst))) Split = true; + if (Count > scop->getStmtListFor(&BB).size() - 1) + break; + if (Stmt && Stmt->isBlockStmt() && Stmt != scop->getStmtListFor(&BB)[Count]) continue;