@@ -523,12 +523,20 @@ class SILInstruction
523
523
private:
524
524
// / Predicate used to filter OperandValueRange.
525
525
struct OperandToValue ;
526
+ // / Predicate used to filter TransformedOperandValueRange.
527
+ struct OperandToTransformedValue ;
526
528
527
529
public:
528
530
using OperandValueRange =
529
531
OptionalTransformRange<ArrayRef<Operand>, OperandToValue>;
532
+ using TransformedOperandValueRange =
533
+ OptionalTransformRange<ArrayRef<Operand>, OperandToTransformedValue>;
534
+
530
535
OperandValueRange
531
536
getOperandValues (bool skipTypeDependentOperands = false ) const ;
537
+ TransformedOperandValueRange
538
+ getOperandValues (std::function<SILValue(SILValue)> transformFn,
539
+ bool skipTypeDependentOperands) const ;
532
540
533
541
SILValue getOperand (unsigned Num) const {
534
542
return getAllOperands ()[Num].get ();
@@ -727,13 +735,40 @@ struct SILInstruction::OperandToValue {
727
735
}
728
736
};
729
737
738
+ struct SILInstruction ::OperandToTransformedValue {
739
+ const SILInstruction &i;
740
+ std::function<SILValue(SILValue)> transformFn;
741
+ bool skipTypeDependentOps;
742
+
743
+ OperandToTransformedValue (const SILInstruction &i,
744
+ std::function<SILValue(SILValue)> transformFn,
745
+ bool skipTypeDependentOps)
746
+ : i(i), transformFn(transformFn),
747
+ skipTypeDependentOps (skipTypeDependentOps) {}
748
+
749
+ Optional<SILValue> operator ()(const Operand &use) const {
750
+ if (skipTypeDependentOps && i.isTypeDependentOperand (use))
751
+ return None;
752
+ return transformFn (use.get ());
753
+ }
754
+ };
755
+
730
756
inline auto
731
757
SILInstruction::getOperandValues (bool skipTypeDependentOperands) const
732
758
-> OperandValueRange {
733
759
return OperandValueRange (getAllOperands (),
734
760
OperandToValue (*this , skipTypeDependentOperands));
735
761
}
736
762
763
+ inline auto
764
+ SILInstruction::getOperandValues (std::function<SILValue(SILValue)> transformFn,
765
+ bool skipTypeDependentOperands) const
766
+ -> TransformedOperandValueRange {
767
+ return TransformedOperandValueRange (
768
+ getAllOperands (),
769
+ OperandToTransformedValue (*this , transformFn, skipTypeDependentOperands));
770
+ }
771
+
737
772
struct SILInstruction ::OperandToType {
738
773
const SILInstruction &i;
739
774
0 commit comments