TrackingVH<MemoryAccess> Res(Phi);
SmallVector<TrackingVH<Value>, 8> Uses;
std::copy(Phi->user_begin(), Phi->user_end(), std::back_inserter(Uses));
- for (auto &U : Uses) {
- if (MemoryPhi *UsePhi = dyn_cast<MemoryPhi>(&*U)) {
- auto OperRange = UsePhi->operands();
- tryRemoveTrivialPhi(UsePhi, OperRange);
- }
- }
+ for (auto &U : Uses)
+ if (MemoryPhi *UsePhi = dyn_cast<MemoryPhi>(&*U))
+ tryRemoveTrivialPhi(UsePhi);
return Res;
}
// argument.
// IE phi(a, a) or b = phi(a, b) or c = phi(a, a, c)
// We recursively try to remove them.
+MemoryAccess *MemorySSAUpdater::tryRemoveTrivialPhi(MemoryPhi *Phi) {
+ assert(Phi && "Can only remove concrete Phi.");
+ auto OperRange = Phi->operands();
+ return tryRemoveTrivialPhi(Phi, OperRange);
+}
template <class RangeType>
MemoryAccess *MemorySSAUpdater::tryRemoveTrivialPhi(MemoryPhi *Phi,
RangeType &Operands) {
void MemorySSAUpdater::removeEdge(BasicBlock *From, BasicBlock *To) {
if (MemoryPhi *MPhi = MSSA->getMemoryAccess(To)) {
MPhi->unorderedDeleteIncomingBlock(From);
- if (MPhi->getNumIncomingValues() == 1)
- removeMemoryAccess(MPhi);
+ tryRemoveTrivialPhi(MPhi);
}
}
Found = true;
return false;
});
- if (MPhi->getNumIncomingValues() == 1)
- removeMemoryAccess(MPhi);
+ tryRemoveTrivialPhi(MPhi);
}
}
// If NewMPhi is a trivial phi, remove it. Its use in the header MPhi will be
// replaced with the unique value.
- if (HasUniqueIncomingValue)
- removeMemoryAccess(NewMPhi);
+ tryRemoveTrivialPhi(MPhi);
}
void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,
return false;
});
Phi->addIncoming(NewPhi, New);
- if (onlySingleValue(NewPhi))
- removeMemoryAccess(NewPhi);
+ tryRemoveTrivialPhi(NewPhi);
}
}
unsigned PhisSize = PhisToOptimize.size();
while (PhisSize-- > 0)
if (MemoryPhi *MP =
- cast_or_null<MemoryPhi>(PhisToOptimize.pop_back_val())) {
- auto OperRange = MP->operands();
- tryRemoveTrivialPhi(MP, OperRange);
- }
+ cast_or_null<MemoryPhi>(PhisToOptimize.pop_back_val()))
+ tryRemoveTrivialPhi(MP);
}
}
if (!DeadBlocks.count(Succ))
if (MemoryPhi *MP = MSSA->getMemoryAccess(Succ)) {
MP->unorderedDeleteIncomingBlock(BB);
- if (MP->getNumIncomingValues() == 1)
- removeMemoryAccess(MP);
+ tryRemoveTrivialPhi(MP);
}
// Drop all references of all accesses in BB
if (MemorySSA::AccessList *Acc = MSSA->getWritableBlockAccesses(BB))
void MemorySSAUpdater::tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs) {
for (auto &VH : UpdatedPHIs)
- if (auto *MPhi = cast_or_null<MemoryPhi>(VH)) {
- auto OperRange = MPhi->operands();
- tryRemoveTrivialPhi(MPhi, OperRange);
- }
+ if (auto *MPhi = cast_or_null<MemoryPhi>(VH))
+ tryRemoveTrivialPhi(MPhi);
}
void MemorySSAUpdater::changeToUnreachable(const Instruction *I) {