// 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;
}
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;
}
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;
// 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;
// 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;
if (!hasEH(I->getParent()))
InstructionsToHoist.push_back(I);
- if (InstructionsToHoist.size())
+ if (!InstructionsToHoist.empty())
partitionCandidates(InstructionsToHoist, HPL, K);
}
}
// 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;
}
// 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());
}
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;
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) {