Skip to content

Commit 2e95c7c

Browse files
committed
[SIL] Add SILInstruction::getRealOperands.
1 parent 5513dd1 commit 2e95c7c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,16 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
612612
/// Return the array of mutable type dependent operands for this instruction.
613613
MutableArrayRef<Operand> getTypeDependentOperands();
614614

615+
private:
616+
struct FilterOperandToRealOperand;
617+
618+
public:
619+
using RealOperandRange =
620+
OptionalTransformRange<ArrayRef<Operand>, FilterOperandToRealOperand>;
621+
622+
/// The array of real (i.e. not type-dependent) operands.
623+
RealOperandRange getRealOperands() const;
624+
615625
unsigned getNumOperands() const { return getAllOperands().size(); }
616626

617627
unsigned getNumTypeDependentOperands() const {
@@ -1005,6 +1015,18 @@ struct SILInstruction::OperandRefToValue {
10051015
}
10061016
};
10071017

1018+
struct SILInstruction::FilterOperandToRealOperand {
1019+
const SILInstruction &i;
1020+
1021+
FilterOperandToRealOperand(const SILInstruction &i) : i(i) {}
1022+
1023+
llvm::Optional<Operand *> operator()(const Operand &use) const {
1024+
if (i.isTypeDependentOperand(use))
1025+
return llvm::None;
1026+
return {const_cast<Operand *>(&use)};
1027+
}
1028+
};
1029+
10081030
struct SILInstruction::NonTypeDependentOperandToValue {
10091031
const SILInstruction &i;
10101032

@@ -1036,6 +1058,11 @@ struct SILInstruction::OperandToTransformedValue {
10361058
}
10371059
};
10381060

1061+
inline SILInstruction::RealOperandRange
1062+
SILInstruction::getRealOperands() const {
1063+
return RealOperandRange(getAllOperands(), FilterOperandToRealOperand(*this));
1064+
}
1065+
10391066
inline SILInstruction::OperandValueRange
10401067
SILInstruction::getOperandValues(ArrayRef<Operand*> operands) {
10411068
return OperandValueRange(operands, OperandToValue());

0 commit comments

Comments
 (0)