[C++11] Use foreach iterator for blocks and operands

llvm-svn: 202707
This commit is contained in:
Tobias Grosser 2014-03-03 13:13:55 +00:00
parent 43e978234a
commit 1d191909a8
4 changed files with 34 additions and 58 deletions

View File

@ -380,13 +380,9 @@ bool ScopDetection::isInvariant(const Value &Val, const Region &Reg) const {
if (isa<PHINode>(*I))
return false;
// Check that all operands of the instruction are
// themselves invariant.
const Instruction::const_op_iterator OE = I->op_end();
for (Instruction::const_op_iterator OI = I->op_begin(); OI != OE; ++OI) {
if (!isInvariant(**OI, Reg))
for (const auto &Operand : I->operands())
if (!isInvariant(*Operand, Reg))
return false;
}
// When the instruction is a load instruction, check that no write to memory
// in the region aliases with the load.
@ -395,11 +391,9 @@ bool ScopDetection::isInvariant(const Value &Val, const Region &Reg) const {
const Region::const_block_iterator BE = Reg.block_end();
// Check if any basic block in the region can modify the location pointed to
// by 'Loc'. If so, 'Val' is (likely) not invariant in the region.
for (Region::const_block_iterator BI = Reg.block_begin(); BI != BE; ++BI) {
const BasicBlock &BB = **BI;
if (AA->canBasicBlockModify(BB, Loc))
for (const auto &BB : Reg.blocks())
if (AA->canBasicBlockModify(*BB, Loc))
return false;
}
}
return true;
@ -592,9 +586,8 @@ Region *ScopDetection::expandRegion(Region &R) {
return LastValidRegion;
}
static bool regionWithoutLoops(Region &R, LoopInfo *LI) {
for (Region::block_iterator I = R.block_begin(), E = R.block_end(); I != E;
++I)
if (R.contains(LI->getLoopFor(*I)))
for (const auto &BB : R.blocks())
if (R.contains(LI->getLoopFor(BB)))
return false;
return true;
@ -671,22 +664,18 @@ void ScopDetection::findScops(Region &R) {
bool ScopDetection::allBlocksValid(DetectionContext &Context) const {
Region &R = Context.CurRegion;
for (Region::block_iterator I = R.block_begin(), E = R.block_end(); I != E;
++I) {
Loop *L = LI->getLoopFor(*I);
if (L && L->getHeader() == *I && !isValidLoop(L, Context))
for (const auto &BB : R.blocks()) {
Loop *L = LI->getLoopFor(BB);
if (L && L->getHeader() == BB && !isValidLoop(L, Context))
return false;
}
for (Region::block_iterator I = R.block_begin(), E = R.block_end(); I != E;
++I)
if (!isValidCFG(**I, Context))
for (const auto &BB : R.blocks())
if (!isValidCFG(*BB, Context))
return false;
for (Region::block_iterator BI = R.block_begin(), E = R.block_end(); BI != E;
++BI)
for (BasicBlock::iterator I = (*BI)->begin(), E = --(*BI)->end(); I != E;
++I)
for (const auto &BB : R.blocks())
for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; ++I)
if (!isValidInstruction(*I, Context))
return false;
@ -779,9 +768,8 @@ void ScopDetection::getDebugLocation(const Region *R, unsigned &LineBegin,
LineBegin = -1;
LineEnd = 0;
for (Region::const_block_iterator RI = R->block_begin(), RE = R->block_end();
RI != RE; ++RI)
for (BasicBlock::iterator BI = (*RI)->begin(), BE = (*RI)->end(); BI != BE;
for (const auto &BB : R->blocks())
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;
++BI) {
DebugLoc DL = BI->getDebugLoc();
if (DL.isUnknown())

View File

@ -139,18 +139,16 @@ struct DOTGraphTraits<ScopDetection *> : public DOTGraphTraits<RegionNode *> {
O.indent(2 * (depth + 1)) << "color = " << color << "\n";
}
for (Region::const_iterator RI = R->begin(), RE = R->end(); RI != RE; ++RI)
printRegionCluster(SD, *RI, O, depth + 1);
for (const auto &SubRegion : *R)
printRegionCluster(SD, SubRegion, O, depth + 1);
RegionInfo *RI = R->getRegionInfo();
for (Region::const_block_iterator BI = R->block_begin(),
BE = R->block_end();
BI != BE; ++BI)
if (RI->getRegionFor(*BI) == R)
for (const auto &BB : R->blocks())
if (RI->getRegionFor(BB) == R)
O.indent(2 * (depth + 1))
<< "Node"
<< static_cast<void *>(RI->getTopLevelRegion()->getBBNode(*BI))
<< static_cast<void *>(RI->getTopLevelRegion()->getBBNode(BB))
<< ";\n";
O.indent(2 * depth) << "}\n";

View File

@ -79,11 +79,7 @@ void TempScop::printDetail(raw_ostream &OS, ScalarEvolution *SE, LoopInfo *LI,
const Region *CurR, unsigned ind) const {
// FIXME: Print other details rather than memory accesses.
typedef Region::const_block_iterator bb_iterator;
for (bb_iterator I = CurR->block_begin(), E = CurR->block_end(); I != E;
++I) {
BasicBlock *CurBlock = *I;
for (const auto &CurBlock : CurR->blocks()) {
AccFuncMapType::const_iterator AccSetIt = AccFuncMap.find(CurBlock);
// Ignore trivial blocks that do not contain any memory access.
@ -200,9 +196,8 @@ void TempScopInfo::buildLoopBounds(TempScop &Scop) {
Region &R = Scop.getMaxRegion();
unsigned MaxLoopDepth = 0;
for (Region::block_iterator I = R.block_begin(), E = R.block_end(); I != E;
++I) {
Loop *L = LI->getLoopFor(*I);
for (auto const &BB : R.blocks()) {
Loop *L = LI->getLoopFor(BB);
if (!L || !R.contains(L))
continue;
@ -307,10 +302,9 @@ void TempScopInfo::buildCondition(BasicBlock *BB, BasicBlock *RegionEntry) {
TempScop *TempScopInfo::buildTempScop(Region &R) {
TempScop *TScop = new TempScop(R, LoopBounds, BBConds, AccFuncMap);
for (Region::block_iterator I = R.block_begin(), E = R.block_end(); I != E;
++I) {
buildAccessFunctions(R, **I);
buildCondition(*I, R.getEntry());
for (const auto &BB : R.blocks()) {
buildAccessFunctions(R, *BB);
buildCondition(BB, R.getEntry());
}
buildLoopBounds(*TScop);

View File

@ -264,9 +264,8 @@ bool IndependentBlocks::createIndependentBlocks(BasicBlock *BB,
bool IndependentBlocks::createIndependentBlocks(const Region *R) {
bool Changed = false;
for (Region::const_block_iterator SI = R->block_begin(), SE = R->block_end();
SI != SE; ++SI)
Changed |= createIndependentBlocks(*SI, R);
for (const auto &BB : R->blocks())
Changed |= createIndependentBlocks(BB, R);
return Changed;
}
@ -275,9 +274,8 @@ bool IndependentBlocks::eliminateDeadCode(const Region *R) {
std::vector<Instruction *> WorkList;
// Find all trivially dead instructions.
for (Region::const_block_iterator SI = R->block_begin(), SE = R->block_end();
SI != SE; ++SI)
for (BasicBlock::iterator I = (*SI)->begin(), E = (*SI)->end(); I != E; ++I)
for (const auto &BB : R->blocks())
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
if (isInstructionTriviallyDead(I))
WorkList.push_back(I);
@ -353,9 +351,8 @@ bool IndependentBlocks::splitExitBlock(Region *R) {
bool IndependentBlocks::translateScalarToArray(const Region *R) {
bool Changed = false;
for (Region::const_block_iterator SI = R->block_begin(), SE = R->block_end();
SI != SE; ++SI)
Changed |= translateScalarToArray(*SI, R);
for (const auto &BB : R->blocks())
Changed |= translateScalarToArray(BB, R);
return Changed;
}
@ -495,9 +492,8 @@ bool IndependentBlocks::isIndependentBlock(const Region *R,
}
bool IndependentBlocks::areAllBlocksIndependent(const Region *R) const {
for (Region::const_block_iterator SI = R->block_begin(), SE = R->block_end();
SI != SE; ++SI)
if (!isIndependentBlock(R, *SI))
for (const auto &BB : R->blocks())
if (!isIndependentBlock(R, BB))
return false;
return true;