Skip to content

Commit 151ab48

Browse files
committed
[MemorySSA] Refactor removing multiple trivial phis [NFC].
Summary: Create a method to clean up multiple potentially trivial phis, since we will need this often. Reviewers: george.burgess.iv Subscribers: jlebar, Prazek, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61471 llvm-svn: 359842
1 parent 1db0f0c commit 151ab48

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

llvm/include/llvm/Analysis/MemorySSAUpdater.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class MemorySSAUpdater {
261261
MemoryAccess *recursePhi(MemoryAccess *Phi);
262262
template <class RangeType>
263263
MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi, RangeType &Operands);
264+
void tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs);
264265
void fixupDefs(const SmallVectorImpl<WeakVH> &);
265266
// Clone all uses and defs from BB to NewBB given a 1:1 map of all
266267
// instructions and blocks cloned, and a map of MemoryPhi : Definition

llvm/lib/Analysis/MemorySSAUpdater.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,9 @@ void MemorySSAUpdater::insertDef(MemoryDef *MD, bool RenameUses) {
355355
}
356356

357357
// Optimize potentially non-minimal phis added in this method.
358-
for (unsigned Idx = NewPhiIndex; Idx < NewPhiIndexEnd; ++Idx) {
359-
if (auto *MPhi = cast_or_null<MemoryPhi>(InsertedPHIs[Idx])) {
360-
auto OperRange = MPhi->operands();
361-
tryRemoveTrivialPhi(MPhi, OperRange);
362-
}
363-
}
358+
unsigned NewPhiSize = NewPhiIndexEnd - NewPhiIndex;
359+
if (NewPhiSize)
360+
tryRemoveTrivialPhis(ArrayRef<WeakVH>(&InsertedPHIs[NewPhiIndex], NewPhiSize));
364361

365362
// Now that all fixups are done, rename all uses if we are asked.
366363
if (RenameUses) {
@@ -1215,6 +1212,14 @@ void MemorySSAUpdater::removeBlocks(
12151212
}
12161213
}
12171214

1215+
void MemorySSAUpdater::tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs) {
1216+
for (auto &VH : UpdatedPHIs)
1217+
if (auto *MPhi = cast_or_null<MemoryPhi>(VH)) {
1218+
auto OperRange = MPhi->operands();
1219+
tryRemoveTrivialPhi(MPhi, OperRange);
1220+
}
1221+
}
1222+
12181223
MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB(
12191224
Instruction *I, MemoryAccess *Definition, const BasicBlock *BB,
12201225
MemorySSA::InsertionPlace Point) {

0 commit comments

Comments
 (0)