Skip to content

Commit fea1b97

Browse files
committed
Fix ForwardingInstruction::getSingleForwardingOperand
1 parent f181da9 commit fea1b97

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

include/swift/SIL/InstWrappers.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ struct LoadOperation {
6969
};
7070

7171
/// A wrapper type for writing generic code against conversion instructions.
72+
///
73+
/// Forwards a single operand in first operand position to a single result.
7274
struct ConversionOperation {
7375
SingleValueInstruction *inst = nullptr;
7476

@@ -259,19 +261,33 @@ class ForwardingOperation {
259261
case SILInstructionKind::LinearFunctionInst:
260262
case SILInstructionKind::DifferentiableFunctionInst:
261263
return nullptr;
264+
case SILInstructionKind::MarkDependenceInst:
265+
return &forwardingInst->getOperandRef(MarkDependenceInst::Value);
266+
case SILInstructionKind::RefToBridgeObjectInst:
267+
return
268+
&forwardingInst->getOperandRef(RefToBridgeObjectInst::ConvertedOperand);
269+
case SILInstructionKind::TuplePackExtractInst:
270+
return &forwardingInst->getOperandRef(TuplePackExtractInst::TupleOperand);
271+
case SILInstructionKind::SelectEnumInst:
272+
// ignore trailing case operands
273+
return &forwardingInst->getOperandRef(0);
262274
default:
263-
if (forwardingInst->getNumRealOperands() == 0) {
275+
int numRealOperands = forwardingInst->getNumRealOperands();
276+
if (numRealOperands == 0) {
264277
// This can happen with enum instructions that have no payload.
265278
return nullptr;
266279
}
280+
assert(numRealOperands == 1);
267281
return &forwardingInst->getOperandRef(0);
268282
}
269283
}
270284

271285
ArrayRef<Operand> getForwardedOperands() const {
286+
// Some instructions have multiple real operands but only forward one.
272287
if (auto *singleForwardingOp = getSingleForwardingOperand()) {
273288
return *singleForwardingOp;
274289
}
290+
// All others forward all operands (for enum, this may be zero operands).
275291
return forwardingInst->getAllOperands();
276292
}
277293

include/swift/SIL/SILInstruction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5693,6 +5693,10 @@ class RefToBridgeObjectInst
56935693
OwnershipForwardingSingleValueInstruction> {
56945694
friend SILBuilder;
56955695

5696+
public:
5697+
enum { ConvertedOperand = 0, MaskOperand = 1 };
5698+
5699+
private:
56965700
FixedOperandList<2> Operands;
56975701
RefToBridgeObjectInst(SILDebugLocation DebugLoc, SILValue ConvertedValue,
56985702
SILValue MaskValue, SILType BridgeObjectTy,

0 commit comments

Comments
 (0)