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 @@ -321,6 +321,10 @@ class ForwardingOperation {
321
321
// / Return true if the forwarded value is address-only either before or after
322
322
// / forwarding.
323
323
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);
324
328
};
325
329
} // end namespace swift
326
330
Original file line number Diff line number Diff line change @@ -70,3 +70,28 @@ bool ForwardingOperation::isAddressOnly() const {
70
70
return forwardingInst->getOperand (0 )->getType ().isAddressOnly (
71
71
*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