Skip to content

Commit cae97a8

Browse files
authored
Merge pull request swiftlang#68792 from atrick/fix-forwarding-operand
Fix ForwardingInstruction::getSingleForwardingOperand
2 parents 6f551cc + aa1c976 commit cae97a8

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
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
@@ -5711,6 +5711,10 @@ class RefToBridgeObjectInst
57115711
OwnershipForwardingSingleValueInstruction> {
57125712
friend SILBuilder;
57135713

5714+
public:
5715+
enum { ConvertedOperand = 0, MaskOperand = 1 };
5716+
5717+
private:
57145718
FixedOperandList<2> Operands;
57155719
RefToBridgeObjectInst(SILDebugLocation DebugLoc, SILValue ConvertedValue,
57165720
SILValue MaskValue, SILType BridgeObjectTy,

lib/SIL/Utils/InstWrappers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ bool ForwardingOperation::hasSameRepresentation() const {
5454
case SILInstructionKind::SelectEnumInst:
5555
case SILInstructionKind::StructExtractInst:
5656
case SILInstructionKind::TupleExtractInst:
57+
case SILInstructionKind::TuplePackExtractInst:
5758
return true;
5859
}
5960
}
@@ -94,4 +95,4 @@ bool ForwardingOperation::visitForwardedValues(
9495
assert(args.size() == 1 && "Transforming terminator with multiple args?!");
9596
return visitor(args[0]);
9697
});
97-
}
98+
}

0 commit comments

Comments
 (0)