@@ -252,44 +252,34 @@ class ForwardingOperation {
252252 ValueOwnershipKind getForwardingOwnershipKind ();
253253 bool preservesOwnership ();
254254
255- // FIXME: Find a better name. Even unary instructions like struct_extract
256- // forward "all" operands.
257- bool canForwardAllOperands () const {
255+ Operand *getSingleForwardingOperand () const {
258256 switch (forwardingInst->getKind ()) {
259257 case SILInstructionKind::StructInst:
260258 case SILInstructionKind::TupleInst:
261259 case SILInstructionKind::LinearFunctionInst:
262260 case SILInstructionKind::DifferentiableFunctionInst:
263- return true ;
261+ return nullptr ;
264262 default :
265- return false ;
263+ if (forwardingInst->getNumRealOperands () == 0 ) {
264+ // This can happen with enum instructions that have no payload.
265+ return nullptr ;
266+ }
267+ return &forwardingInst->getOperandRef (0 );
266268 }
267269 }
268270
269- // FIXME: Find a better name. Even instructions that forward all operands can
270- // forward the first operand.
271- bool canForwardFirstOperandOnly () const {
272- return !canForwardAllOperands () && forwardingInst->getNumRealOperands () > 0 ;
273- }
274-
275271 ArrayRef<Operand> getForwardedOperands () const {
276- if (canForwardAllOperands ()) {
277- return forwardingInst-> getAllOperands () ;
272+ if (auto *singleForwardingOp = getSingleForwardingOperand ()) {
273+ return *singleForwardingOp ;
278274 }
279- if (canForwardFirstOperandOnly ()) {
280- return forwardingInst->getOperandRef (0 );
281- }
282- return {};
275+ return forwardingInst->getAllOperands ();
283276 }
284277
285278 MutableArrayRef<Operand> getForwardedOperands () {
286- if (canForwardAllOperands ()) {
287- return forwardingInst->getAllOperands ();
288- }
289- if (canForwardFirstOperandOnly ()) {
290- return forwardingInst->getOperandRef (0 );
279+ if (auto *singleForwardingOp = getSingleForwardingOperand ()) {
280+ return *singleForwardingOp;
291281 }
292- return {} ;
282+ return forwardingInst-> getAllOperands () ;
293283 }
294284
295285 bool canForwardOwnedCompatibleValuesOnly () {
@@ -321,6 +311,10 @@ class ForwardingOperation {
321311 // / Return true if the forwarded value is address-only either before or after
322312 // / forwarding.
323313 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);
324318};
325319} // end namespace swift
326320
0 commit comments