Skip to content

Commit 16c277f

Browse files
committed
Add new api replaceAllTypeDependentUsesWith
1 parent 8962da9 commit 16c277f

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

include/swift/SIL/SILValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
377377
/// same type as the result of this instruction.
378378
void replaceAllUsesWithUndef();
379379

380+
void replaceAllTypeDependentUsesWith(ValueBase *RHS);
381+
380382
/// Is this value a direct result of the given instruction?
381383
bool isResultOf(SILInstruction *I) const;
382384

lib/SIL/IR/SILValue.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ void ValueBase::replaceAllUsesWithUndef() {
6565
}
6666
}
6767

68+
void ValueBase::replaceAllTypeDependentUsesWith(ValueBase *RHS) {
69+
SmallVector<Operand *, 4> typeUses(getTypeDependentUses());
70+
for (Operand *use : typeUses) {
71+
use->set(RHS);
72+
}
73+
}
74+
6875
SILInstruction *ValueBase::getDefiningInstruction() {
6976
if (auto *inst = dyn_cast<SingleValueInstruction>(this))
7077
return inst;

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,15 +2625,7 @@ void UseRewriter::visitOpenExistentialValueInst(
26252625
openExistential->getType().getAddressType(),
26262626
OpenedExistentialAccess::Immutable);
26272627

2628-
SmallVector<Operand *, 4> typeUses;
2629-
for (Operand *use : openExistential->getUses()) {
2630-
if (use->isTypeDependent()) {
2631-
typeUses.push_back(use);
2632-
}
2633-
}
2634-
for (Operand *use : typeUses) {
2635-
use->set(openAddr);
2636-
}
2628+
openExistential->replaceAllTypeDependentUsesWith(openAddr);
26372629
markRewritten(openExistential, openAddr);
26382630
}
26392631

0 commit comments

Comments
 (0)