[llvm] r275743 - [GVNHoist] Some small cleanups
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 17 17:34:58 PDT 2016
Author: majnemer
Date: Sun Jul 17 19:34:58 2016
New Revision: 275743
URL: http://llvm.org/viewvc/llvm-project?rev=275743&view=rev
Log:
[GVNHoist] Some small cleanups
No functional change is intended, just trying to clean things up a
little.
Modified:
llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp?rev=275743&r1=275742&r2=275743&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp Sun Jul 17 19:34:58 2016
@@ -257,21 +257,19 @@ public:
// Return true when there are users of Def in BB.
bool hasMemoryUseOnPath(MemoryAccess *Def, const BasicBlock *BB,
const Instruction *OldPt) {
- Value::user_iterator UI = Def->user_begin();
- Value::user_iterator UE = Def->user_end();
const BasicBlock *DefBB = Def->getBlock();
const BasicBlock *OldBB = OldPt->getParent();
- for (; UI != UE; ++UI)
- if (MemoryUse *U = dyn_cast<MemoryUse>(*UI)) {
- BasicBlock *UBB = U->getBlock();
+ for (User *U : Def->users())
+ if (auto *MU = dyn_cast<MemoryUse>(U)) {
+ BasicBlock *UBB = MU->getBlock();
// Only analyze uses in BB.
if (BB != UBB)
continue;
// A use in the same block as the Def is on the path.
if (UBB == DefBB) {
- assert(MSSA->locallyDominates(Def, U) && "def not dominating use");
+ assert(MSSA->locallyDominates(Def, MU) && "def not dominating use");
return true;
}
@@ -279,7 +277,7 @@ public:
return true;
// It is only harmful to hoist when the use is before OldPt.
- if (firstInBB(UBB, U->getMemoryInst(), OldPt))
+ if (firstInBB(UBB, MU->getMemoryInst(), OldPt))
return true;
}
@@ -392,7 +390,7 @@ public:
return false;
if (NewBB == DBB && !MSSA->isLiveOnEntryDef(D))
- if (MemoryUseOrDef *UD = dyn_cast<MemoryUseOrDef>(D))
+ if (auto *UD = dyn_cast<MemoryUseOrDef>(D))
if (firstInBB(DBB, NewPt, UD->getMemoryInst()))
// Cannot move the load or store to NewPt above its definition in D.
return false;
@@ -513,7 +511,7 @@ public:
// At this point it is not safe to extend the current hoisting to
// NewHoistPt: save the hoisting list so far.
if (std::distance(Start, II) > 1)
- HPL.push_back(std::make_pair(HoistBB, SmallVecInsn(Start, II)));
+ HPL.push_back({HoistBB, SmallVecInsn(Start, II)});
// Start over from BB.
Start = II;
@@ -526,17 +524,17 @@ public:
// Save the last partition.
if (std::distance(Start, II) > 1)
- HPL.push_back(std::make_pair(HoistBB, SmallVecInsn(Start, II)));
+ HPL.push_back({HoistBB, SmallVecInsn(Start, II)});
}
// Initialize HPL from Map.
void computeInsertionPoints(const VNtoInsns &Map, HoistingPointList &HPL,
InsKind K) {
- for (VNtoInsns::const_iterator It = Map.begin(); It != Map.end(); ++It) {
+ for (const auto &Entry : Map) {
if (MaxHoistedThreshold != -1 && ++HoistedCtr > MaxHoistedThreshold)
return;
- const SmallVecInsn &V = It->second;
+ const SmallVecInsn &V = Entry.second;
if (V.size() < 2)
continue;
@@ -546,7 +544,7 @@ public:
if (!hasEH(I->getParent()))
InstructionsToHoist.push_back(I);
- if (InstructionsToHoist.size())
+ if (!InstructionsToHoist.empty())
partitionCandidates(InstructionsToHoist, HPL, K);
}
}
@@ -557,12 +555,10 @@ public:
// expression, make sure that all its operands are available at insert point.
bool allOperandsAvailable(const Instruction *I,
const BasicBlock *HoistPt) const {
- for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
- const Value *Op = I->getOperand(i);
- const Instruction *Inst = dyn_cast<Instruction>(Op);
- if (Inst && !DT->dominates(Inst->getParent(), HoistPt))
- return false;
- }
+ for (const Use &Op : I->operands())
+ if (const auto *Inst = dyn_cast<Instruction>(&Op))
+ if (!DT->dominates(Inst->getParent(), HoistPt))
+ return false;
return true;
}
@@ -591,9 +587,9 @@ public:
// Check whether the GEP of a ld/st can be synthesized at HoistPt.
Instruction *Gep = nullptr;
Instruction *Val = nullptr;
- if (LoadInst *Ld = dyn_cast<LoadInst>(Repl))
+ if (auto *Ld = dyn_cast<LoadInst>(Repl))
Gep = dyn_cast<Instruction>(Ld->getPointerOperand());
- if (StoreInst *St = dyn_cast<StoreInst>(Repl)) {
+ if (auto *St = dyn_cast<StoreInst>(Repl)) {
Gep = dyn_cast<Instruction>(St->getPointerOperand());
Val = dyn_cast<Instruction>(St->getValueOperand());
}
@@ -699,12 +695,12 @@ public:
CallInfo CI;
for (BasicBlock *BB : depth_first(&F.getEntryBlock())) {
for (Instruction &I1 : *BB) {
- if (LoadInst *Load = dyn_cast<LoadInst>(&I1))
+ if (auto *Load = dyn_cast<LoadInst>(&I1))
LI.insert(Load, VN);
- else if (StoreInst *Store = dyn_cast<StoreInst>(&I1))
+ else if (auto *Store = dyn_cast<StoreInst>(&I1))
SI.insert(Store, VN);
- else if (CallInst *Call = dyn_cast<CallInst>(&I1)) {
- if (IntrinsicInst *Intr = dyn_cast<IntrinsicInst>(Call)) {
+ else if (auto *Call = dyn_cast<CallInst>(&I1)) {
+ if (auto *Intr = dyn_cast<IntrinsicInst>(Call)) {
if (isa<DbgInfoIntrinsic>(Intr) ||
Intr->getIntrinsicID() == Intrinsic::assume)
continue;
@@ -744,7 +740,7 @@ public:
unsigned I = 0;
for (const BasicBlock *BB : depth_first(&F.getEntryBlock()))
- DFSNumber.insert(std::make_pair(BB, ++I));
+ DFSNumber.insert({BB, ++I});
// FIXME: use lazy evaluation of VN to avoid the fix-point computation.
while (1) {
More information about the llvm-commits
mailing list