mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add a new overload of SILInstruction::getOperandValues to get
transformed values of the operands
This commit is contained in:
@@ -523,12 +523,20 @@ public:
|
||||
private:
|
||||
/// Predicate used to filter OperandValueRange.
|
||||
struct OperandToValue;
|
||||
/// Predicate used to filter TransformedOperandValueRange.
|
||||
struct OperandToTransformedValue;
|
||||
|
||||
public:
|
||||
using OperandValueRange =
|
||||
OptionalTransformRange<ArrayRef<Operand>, OperandToValue>;
|
||||
using TransformedOperandValueRange =
|
||||
OptionalTransformRange<ArrayRef<Operand>, OperandToTransformedValue>;
|
||||
|
||||
OperandValueRange
|
||||
getOperandValues(bool skipTypeDependentOperands = false) const;
|
||||
TransformedOperandValueRange
|
||||
getOperandValues(std::function<SILValue(SILValue)> transformFn,
|
||||
bool skipTypeDependentOperands) const;
|
||||
|
||||
SILValue getOperand(unsigned Num) const {
|
||||
return getAllOperands()[Num].get();
|
||||
@@ -727,6 +735,24 @@ struct SILInstruction::OperandToValue {
|
||||
}
|
||||
};
|
||||
|
||||
struct SILInstruction::OperandToTransformedValue {
|
||||
const SILInstruction &i;
|
||||
std::function<SILValue(SILValue)> transformFn;
|
||||
bool skipTypeDependentOps;
|
||||
|
||||
OperandToTransformedValue(const SILInstruction &i,
|
||||
std::function<SILValue(SILValue)> transformFn,
|
||||
bool skipTypeDependentOps)
|
||||
: i(i), transformFn(transformFn),
|
||||
skipTypeDependentOps(skipTypeDependentOps) {}
|
||||
|
||||
Optional<SILValue> operator()(const Operand &use) const {
|
||||
if (skipTypeDependentOps && i.isTypeDependentOperand(use))
|
||||
return None;
|
||||
return transformFn(use.get());
|
||||
}
|
||||
};
|
||||
|
||||
inline auto
|
||||
SILInstruction::getOperandValues(bool skipTypeDependentOperands) const
|
||||
-> OperandValueRange {
|
||||
@@ -734,6 +760,15 @@ SILInstruction::getOperandValues(bool skipTypeDependentOperands) const
|
||||
OperandToValue(*this, skipTypeDependentOperands));
|
||||
}
|
||||
|
||||
inline auto
|
||||
SILInstruction::getOperandValues(std::function<SILValue(SILValue)> transformFn,
|
||||
bool skipTypeDependentOperands) const
|
||||
-> TransformedOperandValueRange {
|
||||
return TransformedOperandValueRange(
|
||||
getAllOperands(),
|
||||
OperandToTransformedValue(*this, transformFn, skipTypeDependentOperands));
|
||||
}
|
||||
|
||||
struct SILInstruction::OperandToType {
|
||||
const SILInstruction &i;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user