Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
lib/Support/ScopHelper.cpp
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | BasicBlock *polly::createSingleExitEdge(Region *R, Pass *P) { | ||||
SmallVector<BasicBlock *, 4> Preds; | SmallVector<BasicBlock *, 4> Preds; | ||||
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) | for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) | ||||
if (R->contains(*PI)) | if (R->contains(*PI)) | ||||
Preds.push_back(*PI); | Preds.push_back(*PI); | ||||
return SplitBlockPredecessors(BB, Preds, ".region", P); | return SplitBlockPredecessors(BB, Preds, ".region", P); | ||||
} | } | ||||
void polly::simplifyRegion(Scop *S, Pass *P) { | BasicBlock *polly::simplifyRegion(Scop *S, Pass *P) { | ||||
Region *R = &S->getRegion(); | Region *R = &S->getRegion(); | ||||
// The entering block for the region. | |||||
BasicBlock *EnteringBB = R->getEnteringBlock(); | |||||
// Create single entry edge if the region has multiple entry edges. | // Create single entry edge if the region has multiple entry edges. | ||||
if (!R->getEnteringBlock()) { | if (!EnteringBB) { | ||||
BasicBlock *OldEntry = R->getEntry(); | BasicBlock *OldEntry = R->getEntry(); | ||||
BasicBlock *NewEntry = SplitBlock(OldEntry, OldEntry->begin(), P); | BasicBlock *NewEntry = SplitBlock(OldEntry, OldEntry->begin(), P); | ||||
for (ScopStmt *Stmt : *S) | for (ScopStmt *Stmt : *S) | ||||
if (Stmt->getBasicBlock() == OldEntry) { | if (Stmt->getBasicBlock() == OldEntry) { | ||||
Stmt->setBasicBlock(NewEntry); | Stmt->setBasicBlock(NewEntry); | ||||
break; | break; | ||||
} | } | ||||
R->replaceEntryRecursive(NewEntry); | R->replaceEntryRecursive(NewEntry); | ||||
EnteringBB = OldEntry; | |||||
} | } | ||||
// Create single exit edge if the region has multiple exit edges. | // Create single exit edge if the region has multiple exit edges. | ||||
if (!R->getExitingBlock()) { | if (!R->getExitingBlock()) { | ||||
BasicBlock *NewExit = createSingleExitEdge(R, P); | BasicBlock *NewExit = createSingleExitEdge(R, P); | ||||
for (auto &&SubRegion : *R) | for (auto &&SubRegion : *R) | ||||
SubRegion->replaceExitRecursive(NewExit); | SubRegion->replaceExitRecursive(NewExit); | ||||
} | } | ||||
return EnteringBB; | |||||
} | } | ||||
void polly::splitEntryBlockForAlloca(BasicBlock *EntryBlock, Pass *P) { | void polly::splitEntryBlockForAlloca(BasicBlock *EntryBlock, Pass *P) { | ||||
// Find first non-alloca instruction. Every basic block has a non-alloc | // Find first non-alloca instruction. Every basic block has a non-alloc | ||||
// instruction, as every well formed basic block has a terminator. | // instruction, as every well formed basic block has a terminator. | ||||
BasicBlock::iterator I = EntryBlock->begin(); | BasicBlock::iterator I = EntryBlock->begin(); | ||||
while (isa<AllocaInst>(I)) | while (isa<AllocaInst>(I)) | ||||
++I; | ++I; | ||||
// SplitBlock updates DT, DF and LI. | // SplitBlock updates DT, DF and LI. | ||||
BasicBlock *NewEntry = SplitBlock(EntryBlock, I, P); | BasicBlock *NewEntry = SplitBlock(EntryBlock, I, P); | ||||
if (RegionInfoPass *RIP = P->getAnalysisIfAvailable<RegionInfoPass>()) | if (RegionInfoPass *RIP = P->getAnalysisIfAvailable<RegionInfoPass>()) | ||||
RIP->getRegionInfo().splitBlock(NewEntry, EntryBlock); | RIP->getRegionInfo().splitBlock(NewEntry, EntryBlock); | ||||
} | } |