[C++11,ARM64] Range based for loops in address type promotion.

No functional change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205437 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Grosbach
2014-04-02 18:00:36 +00:00
parent a5084593ba
commit 68c150834b

View File

@@ -371,10 +371,8 @@ ARM64AddressTypePromotion::propagateSignExtension(Instructions &SExtInsts) {
mergeSExts(ValToSExtendedUses, ToRemove); mergeSExts(ValToSExtendedUses, ToRemove);
// Remove all instructions marked as ToRemove. // Remove all instructions marked as ToRemove.
for (SetOfInstructions::iterator ToRemoveIt = ToRemove.begin(), for (auto I: ToRemove)
EndToRemoveIt = ToRemove.end(); I->eraseFromParent();
ToRemoveIt != EndToRemoveIt; ++ToRemoveIt)
(*ToRemoveIt)->eraseFromParent();
return LocalChange; return LocalChange;
} }
@@ -382,42 +380,37 @@ void ARM64AddressTypePromotion::mergeSExts(ValueToInsts &ValToSExtendedUses,
SetOfInstructions &ToRemove) { SetOfInstructions &ToRemove) {
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
for (ValueToInsts::iterator It = ValToSExtendedUses.begin(), for (auto &Entry: ValToSExtendedUses) {
EndIt = ValToSExtendedUses.end(); Instructions &Insts = Entry.second;
It != EndIt; ++It) {
Instructions &Insts = It->second;
Instructions CurPts; Instructions CurPts;
for (Instructions::iterator IIt = Insts.begin(), EndIIt = Insts.end(); for (auto Inst : Insts) {
IIt != EndIIt; ++IIt) { if (ToRemove.count(Inst))
if (ToRemove.count(*IIt))
continue; continue;
bool inserted = false; bool inserted = false;
for (Instructions::iterator CurPtsIt = CurPts.begin(), for (auto Pt : CurPts) {
EndCurPtsIt = CurPts.end(); if (DT.dominates(Inst, Pt)) {
CurPtsIt != EndCurPtsIt; ++CurPtsIt) { DEBUG(dbgs() << "Replace all uses of:\n" << *Pt << "\nwith:\n"
if (DT.dominates(*IIt, *CurPtsIt)) { << *Inst << '\n');
DEBUG(dbgs() << "Replace all uses of:\n" << **CurPtsIt << "\nwith:\n" (Pt)->replaceAllUsesWith(Inst);
<< **IIt << '\n'); ToRemove.insert(Pt);
(*CurPtsIt)->replaceAllUsesWith(*IIt); Pt = Inst;
ToRemove.insert(*CurPtsIt);
*CurPtsIt = *IIt;
inserted = true; inserted = true;
break; break;
} }
if (!DT.dominates(*CurPtsIt, *IIt)) if (!DT.dominates(Pt, Inst))
// Give up if we need to merge in a common dominator as the // Give up if we need to merge in a common dominator as the
// expermients show it is not profitable. // expermients show it is not profitable.
continue; continue;
DEBUG(dbgs() << "Replace all uses of:\n" << **IIt << "\nwith:\n" DEBUG(dbgs() << "Replace all uses of:\n" << *Inst << "\nwith:\n"
<< **CurPtsIt << '\n'); << *Pt << '\n');
(*IIt)->replaceAllUsesWith(*CurPtsIt); Inst->replaceAllUsesWith(Pt);
ToRemove.insert(*IIt); ToRemove.insert(Inst);
inserted = true; inserted = true;
break; break;
} }
if (!inserted) if (!inserted)
CurPts.push_back(*IIt); CurPts.push_back(Inst);
} }
} }
} }
@@ -427,17 +420,15 @@ void ARM64AddressTypePromotion::analyzeSExtension(Instructions &SExtInsts) {
DenseMap<Value *, Instruction *> SeenChains; DenseMap<Value *, Instruction *> SeenChains;
for (Function::iterator IBB = Func->begin(), IEndBB = Func->end(); for (auto &BB : *Func) {
IBB != IEndBB; ++IBB) { for (auto &II: BB) {
for (BasicBlock::iterator II = IBB->begin(), IEndI = IBB->end(); Instruction *SExt = &II;
II != IEndI; ++II) {
// Collect all sext operation per type. // Collect all sext operation per type.
if (!isa<SExtInst>(II) || !shouldConsiderSExt(II)) if (!isa<SExtInst>(SExt) || !shouldConsiderSExt(SExt))
continue; continue;
Instruction *SExt = II;
DEBUG(dbgs() << "Found:\n" << (*II) << '\n'); DEBUG(dbgs() << "Found:\n" << (*SExt) << '\n');
// Cases where we actually perform the optimization: // Cases where we actually perform the optimization:
// 1. SExt is used in a getelementptr with more than 2 operand => // 1. SExt is used in a getelementptr with more than 2 operand =>
@@ -477,7 +468,7 @@ void ARM64AddressTypePromotion::analyzeSExtension(Instructions &SExtInsts) {
SeenChains.find(Last); SeenChains.find(Last);
if (insert || AlreadySeen != SeenChains.end()) { if (insert || AlreadySeen != SeenChains.end()) {
DEBUG(dbgs() << "Insert\n"); DEBUG(dbgs() << "Insert\n");
SExtInsts.push_back(II); SExtInsts.push_back(SExt);
if (AlreadySeen != SeenChains.end() && AlreadySeen->second != NULL) { if (AlreadySeen != SeenChains.end() && AlreadySeen->second != NULL) {
DEBUG(dbgs() << "Insert chain member\n"); DEBUG(dbgs() << "Insert chain member\n");
SExtInsts.push_back(AlreadySeen->second); SExtInsts.push_back(AlreadySeen->second);