File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -311,6 +311,10 @@ class ForwardingOperation {
311
311
// / Return true if the forwarded value is address-only either before or after
312
312
// / forwarding.
313
313
bool isAddressOnly () const ;
314
+
315
+ // Call \p visitor on all forwarded results of the current forwarding
316
+ // operation.
317
+ bool visitForwardedValues (function_ref<bool (SILValue)> visitor);
314
318
};
315
319
} // end namespace swift
316
320
Original file line number Diff line number Diff line change @@ -70,3 +70,28 @@ bool ForwardingOperation::isAddressOnly() const {
70
70
// If any of the operands are address-only, then the aggregate must be.
71
71
return aggregate->getType ().isAddressOnly (*forwardingInst->getFunction ());
72
72
}
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
+ }
You can’t perform that action at this time.
0 commit comments