@@ -643,7 +643,7 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
643
643
NonTypeDependentOperandValueRange getNonTypeDependentOperandValues () const ;
644
644
645
645
TransformedOperandValueRange
646
- getOperandValues (std::function<SILValue(SILValue )> transformFn,
646
+ getOperandValues (std::function<SILValue(const Operand * )> transformFn,
647
647
bool skipTypeDependentOperands) const ;
648
648
649
649
SILValue getOperand (unsigned Num) const {
@@ -720,8 +720,9 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
720
720
// / Returns true if the given instruction is completely identical to RHS,
721
721
// / using \p opEqual to compare operands.
722
722
// /
723
- template <typename OpCmp>
724
- bool isIdenticalTo (const SILInstruction *RHS, OpCmp &&opEqual) const {
723
+ bool
724
+ isIdenticalTo (const SILInstruction *RHS,
725
+ llvm::function_ref<bool (SILValue, SILValue)> opEqual) const {
725
726
// Quick check if both instructions have the same kind, number of operands,
726
727
// and types. This should filter out most cases.
727
728
if (getKind () != RHS->getKind () ||
@@ -742,6 +743,29 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
742
743
return hasIdenticalState (RHS);
743
744
}
744
745
746
+ bool isIdenticalTo (const SILInstruction *RHS,
747
+ llvm::function_ref<bool (const Operand *, const Operand *)>
748
+ opEqual) const {
749
+ // Quick check if both instructions have the same kind, number of operands,
750
+ // and types. This should filter out most cases.
751
+ if (getKind () != RHS->getKind () ||
752
+ getNumOperands () != RHS->getNumOperands ()) {
753
+ return false ;
754
+ }
755
+
756
+ if (!getResults ().hasSameTypes (RHS->getResults ()))
757
+ return false ;
758
+
759
+ // Check operands.
760
+ for (unsigned i = 0 , e = getNumOperands (); i != e; ++i)
761
+ if (!opEqual (&getOperandRef (i), &RHS->getOperandRef (i)))
762
+ return false ;
763
+
764
+ // Check any special state of instructions that are not represented in the
765
+ // instructions operands/type.
766
+ return hasIdenticalState (RHS);
767
+ }
768
+
745
769
// / Returns true if the instruction may have side effects.
746
770
// /
747
771
// / Instructions that store into memory or change retain counts as well as
@@ -972,19 +996,20 @@ struct SILInstruction::NonTypeDependentOperandToValue {
972
996
973
997
struct SILInstruction ::OperandToTransformedValue {
974
998
const SILInstruction &i;
975
- std::function<SILValue(SILValue )> transformFn;
999
+ std::function<SILValue(const Operand * )> transformFn;
976
1000
bool skipTypeDependentOps;
977
1001
978
- OperandToTransformedValue (const SILInstruction &i,
979
- std::function<SILValue(SILValue)> transformFn,
980
- bool skipTypeDependentOps)
1002
+ OperandToTransformedValue (
1003
+ const SILInstruction &i,
1004
+ std::function<SILValue(const Operand *)> transformFn,
1005
+ bool skipTypeDependentOps)
981
1006
: i(i), transformFn(transformFn),
982
1007
skipTypeDependentOps (skipTypeDependentOps) {}
983
1008
984
1009
Optional<SILValue> operator ()(const Operand &use) const {
985
1010
if (skipTypeDependentOps && i.isTypeDependentOperand (use))
986
1011
return None;
987
- return transformFn (use. get () );
1012
+ return transformFn (& use);
988
1013
}
989
1014
};
990
1015
@@ -1005,10 +1030,9 @@ SILInstruction::getNonTypeDependentOperandValues() const
1005
1030
NonTypeDependentOperandToValue (*this ));
1006
1031
}
1007
1032
1008
- inline auto
1009
- SILInstruction::getOperandValues (std::function<SILValue(SILValue)> transformFn,
1010
- bool skipTypeDependentOperands) const
1011
- -> TransformedOperandValueRange {
1033
+ inline auto SILInstruction::getOperandValues (
1034
+ std::function<SILValue(const Operand *)> transformFn,
1035
+ bool skipTypeDependentOperands) const -> TransformedOperandValueRange {
1012
1036
return TransformedOperandValueRange (
1013
1037
getAllOperands (),
1014
1038
OperandToTransformedValue (*this , transformFn, skipTypeDependentOperands));
@@ -6561,7 +6585,8 @@ class SelectEnumInstBase
6561
6585
6562
6586
SILValue getOperand () const { return getAllOperands ()[0 ].get (); }
6563
6587
SILValue getEnumOperand () const { return getOperand (); }
6564
-
6588
+ const Operand &getEnumOperandRef () const { return getAllOperands ()[0 ]; }
6589
+
6565
6590
std::pair<EnumElementDecl*, SILValue>
6566
6591
getCase (unsigned i) const {
6567
6592
return std::make_pair (getEnumElementDeclStorage ()[i],
@@ -8743,6 +8768,8 @@ class IndexingInst : public SingleValueInstruction {
8743
8768
ArrayRef<Operand> getAllOperands () const { return Operands.asArray (); }
8744
8769
MutableArrayRef<Operand> getAllOperands () { return Operands.asArray (); }
8745
8770
8771
+ const Operand &getBaseOperandRef () const { return getAllOperands ()[Base]; }
8772
+
8746
8773
DEFINE_ABSTRACT_SINGLE_VALUE_INST_BOILERPLATE (IndexingInst)
8747
8774
};
8748
8775
0 commit comments