Skip to content

Commit 46bed7c

Browse files
committed
Add SinkAddressProjections::newProjections
1 parent 37d8586 commit 46bed7c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

include/swift/SILOptimizer/Utils/BasicBlockOptUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,19 @@ bool canCloneTerminator(TermInst *termInst);
136136
class SinkAddressProjections {
137137
// Projections ordered from last to first in the chain.
138138
SmallVector<SingleValueInstruction *, 4> oldProjections;
139+
// Cloned projections to avoid address phis.
140+
SmallVectorImpl<SingleValueInstruction *> *newProjections;
139141
SmallSetVector<SILValue, 4> inBlockDefs;
140142

141143
// Transient per-projection data for use during cloning.
142144
SmallVector<Operand *, 4> usesToReplace;
143145
llvm::SmallDenseMap<SILBasicBlock *, Operand *, 4> firstBlockUse;
144146

145147
public:
148+
SinkAddressProjections(
149+
SmallVectorImpl<SingleValueInstruction *> *newProjections = nullptr)
150+
: newProjections(newProjections) {}
151+
146152
/// Check for an address projection chain ending at \p inst. Return true if
147153
/// the given instruction is successfully analyzed.
148154
///
@@ -163,6 +169,7 @@ class SinkAddressProjections {
163169
ArrayRef<SILValue> getInBlockDefs() const {
164170
return inBlockDefs.getArrayRef();
165171
}
172+
166173
/// Clone the chain of projections at their use sites.
167174
///
168175
/// Return true if anything was done.

lib/SILOptimizer/Utils/BasicBlockOptUtils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,12 @@ bool SinkAddressProjections::cloneProjections() {
297297
auto *useBB = use->getUser()->getParent();
298298
auto *firstUse = firstBlockUse.lookup(useBB);
299299
SingleValueInstruction *newProj;
300-
if (use == firstUse)
300+
if (use == firstUse) {
301301
newProj = cast<SingleValueInstruction>(oldProj->clone(use->getUser()));
302-
else {
302+
if (newProjections) {
303+
newProjections->push_back(newProj);
304+
}
305+
} else {
303306
newProj = cast<SingleValueInstruction>(firstUse->get());
304307
assert(newProj->getParent() == useBB);
305308
newProj->moveFront(useBB);

0 commit comments

Comments
 (0)