@@ -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,8 @@ 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 isIdenticalTo ( const SILInstruction *RHS,
724
+ std::function< bool (SILValue, SILValue)> opEqual) const {
725
725
// Quick check if both instructions have the same kind, number of operands,
726
726
// and types. This should filter out most cases.
727
727
if (getKind () != RHS->getKind () ||
@@ -742,6 +742,29 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
742
742
return hasIdenticalState (RHS);
743
743
}
744
744
745
+ bool isIdenticalTo (
746
+ const SILInstruction *RHS,
747
+ std::function<bool (const Operand *, const Operand *)> opEqual) const {
748
+ // Quick check if both instructions have the same kind, number of operands,
749
+ // and types. This should filter out most cases.
750
+ if (getKind () != RHS->getKind () ||
751
+ getNumOperands () != RHS->getNumOperands ()) {
752
+ return false ;
753
+ }
754
+
755
+ if (!getResults ().hasSameTypes (RHS->getResults ()))
756
+ return false ;
757
+
758
+ // Check operands.
759
+ for (unsigned i = 0 , e = getNumOperands (); i != e; ++i)
760
+ if (!opEqual (&getOperandRef (i), &RHS->getOperandRef (i)))
761
+ return false ;
762
+
763
+ // Check any special state of instructions that are not represented in the
764
+ // instructions operands/type.
765
+ return hasIdenticalState (RHS);
766
+ }
767
+
745
768
// / Returns true if the instruction may have side effects.
746
769
// /
747
770
// / Instructions that store into memory or change retain counts as well as
@@ -972,19 +995,20 @@ struct SILInstruction::NonTypeDependentOperandToValue {
972
995
973
996
struct SILInstruction ::OperandToTransformedValue {
974
997
const SILInstruction &i;
975
- std::function<SILValue(SILValue )> transformFn;
998
+ std::function<SILValue(const Operand * )> transformFn;
976
999
bool skipTypeDependentOps;
977
1000
978
- OperandToTransformedValue (const SILInstruction &i,
979
- std::function<SILValue(SILValue)> transformFn,
980
- bool skipTypeDependentOps)
1001
+ OperandToTransformedValue (
1002
+ const SILInstruction &i,
1003
+ std::function<SILValue(const Operand *)> transformFn,
1004
+ bool skipTypeDependentOps)
981
1005
: i(i), transformFn(transformFn),
982
1006
skipTypeDependentOps (skipTypeDependentOps) {}
983
1007
984
1008
Optional<SILValue> operator ()(const Operand &use) const {
985
1009
if (skipTypeDependentOps && i.isTypeDependentOperand (use))
986
1010
return None;
987
- return transformFn (use. get () );
1011
+ return transformFn (& use);
988
1012
}
989
1013
};
990
1014
@@ -1005,10 +1029,9 @@ SILInstruction::getNonTypeDependentOperandValues() const
1005
1029
NonTypeDependentOperandToValue (*this ));
1006
1030
}
1007
1031
1008
- inline auto
1009
- SILInstruction::getOperandValues (std::function<SILValue(SILValue)> transformFn,
1010
- bool skipTypeDependentOperands) const
1011
- -> TransformedOperandValueRange {
1032
+ inline auto SILInstruction::getOperandValues (
1033
+ std::function<SILValue(const Operand *)> transformFn,
1034
+ bool skipTypeDependentOperands) const -> TransformedOperandValueRange {
1012
1035
return TransformedOperandValueRange (
1013
1036
getAllOperands (),
1014
1037
OperandToTransformedValue (*this , transformFn, skipTypeDependentOperands));
@@ -6539,7 +6562,8 @@ class SelectEnumInstBase
6539
6562
6540
6563
SILValue getOperand () const { return getAllOperands ()[0 ].get (); }
6541
6564
SILValue getEnumOperand () const { return getOperand (); }
6542
-
6565
+ const Operand &getEnumOperandRef () const { return getAllOperands ()[0 ]; }
6566
+
6543
6567
std::pair<EnumElementDecl*, SILValue>
6544
6568
getCase (unsigned i) const {
6545
6569
return std::make_pair (getEnumElementDeclStorage ()[i],
0 commit comments