Skip to content

Commit 2bb3212

Browse files
meg-guptanate-chandler
authored andcommitted
Add ForwardingOperation::visitForwardedValues api
1 parent 99a36b3 commit 2bb3212

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/swift/SIL/InstWrappers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ class ForwardingOperation {
321321
/// Return true if the forwarded value is address-only either before or after
322322
/// forwarding.
323323
bool isAddressOnly() const;
324+
325+
// Call \p visitor on all forwarded results of the current forwarding
326+
// operation.
327+
bool visitForwardedValues(function_ref<bool(SILValue)> visitor);
324328
};
325329
} // end namespace swift
326330

lib/SIL/Utils/InstWrappers.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,28 @@ bool ForwardingOperation::isAddressOnly() const {
7070
return forwardingInst->getOperand(0)->getType().isAddressOnly(
7171
*forwardingInst->getFunction());
7272
}
73+
74+
bool ForwardingOperation::visitForwardedValues(
75+
function_ref<bool(SILValue)> visitor) {
76+
if (auto *svi = dyn_cast<SingleValueInstruction>(forwardingInst)) {
77+
return visitor(svi);
78+
}
79+
if (auto *mvri = dyn_cast<MultipleValueInstruction>(forwardingInst)) {
80+
return llvm::all_of(mvri->getResults(), [&](SILValue value) {
81+
if (value->getOwnershipKind() == OwnershipKind::None)
82+
return true;
83+
return visitor(value);
84+
});
85+
}
86+
auto *ti = cast<TermInst>(forwardingInst);
87+
assert(ti->mayHaveTerminatorResult());
88+
return llvm::all_of(ti->getSuccessorBlocks(), [&](SILBasicBlock *succBlock) {
89+
// If we do not have any arguments, then continue.
90+
if (succBlock->args_empty())
91+
return true;
92+
93+
auto args = succBlock->getSILPhiArguments();
94+
assert(args.size() == 1 && "Transforming terminator with multiple args?!");
95+
return visitor(args[0]);
96+
});
97+
}

0 commit comments

Comments
 (0)