Skip to content

Commit 540882f

Browse files
committed
[NFC] SIL: Promote OperandToUser to SILInstruction
Put it alongsidde OperandToValue and friends.
1 parent 573607f commit 540882f

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
670670
using TransformedOperandValueRange =
671671
OptionalTransformRange<ArrayRef<Operand>, OperandToTransformedValue>;
672672

673+
/// Functor for Operand::getUser()
674+
struct OperandToUser;
675+
using OperandUserRange = TransformRange<ArrayRef<Operand *>, OperandToUser>;
676+
673677
static OperandValueRange getOperandValues(ArrayRef<Operand*> operands);
674678

675679
OperandRefValueRange getOperandValues() const;
@@ -1021,6 +1025,12 @@ struct SILInstruction::OperandRefToValue {
10211025
}
10221026
};
10231027

1028+
struct SILInstruction::OperandToUser {
1029+
SILInstruction *operator()(const Operand *use) const {
1030+
return const_cast<Operand *>(use)->getUser();
1031+
}
1032+
};
1033+
10241034
struct SILInstruction::FilterOperandToRealOperand {
10251035
const SILInstruction &i;
10261036

lib/SILOptimizer/SemanticARC/OwnershipLiveRange.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,14 @@ OwnershipLiveRange::hasUnknownConsumingUse(bool assumingAtFixPoint) const {
363363
return HasConsumingUse_t::YesButAllPhiArgs;
364364
}
365365

366-
OwnershipLiveRange::DestroyingInstsRange
366+
SILInstruction::OperandUserRange
367367
OwnershipLiveRange::getDestroyingInsts() const {
368-
return DestroyingInstsRange(getDestroyingUses(), OperandToUser());
368+
return SILInstruction::OperandUserRange(getDestroyingUses(),
369+
SILInstruction::OperandToUser());
369370
}
370371

371-
OwnershipLiveRange::ConsumingInstsRange
372+
SILInstruction::OperandUserRange
372373
OwnershipLiveRange::getAllConsumingInsts() const {
373-
return ConsumingInstsRange(consumingUses, OperandToUser());
374+
return SILInstruction::OperandUserRange(consumingUses,
375+
SILInstruction::OperandToUser());
374376
}

lib/SILOptimizer/SemanticARC/OwnershipLiveRange.h

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,9 @@ class LLVM_LIBRARY_VISIBILITY OwnershipLiveRange {
113113
return unknownConsumingUses;
114114
}
115115

116-
private:
117-
struct OperandToUser;
116+
SILInstruction::OperandUserRange getDestroyingInsts() const;
118117

119-
public:
120-
using DestroyingInstsRange =
121-
TransformRange<ArrayRef<Operand *>, OperandToUser>;
122-
DestroyingInstsRange getDestroyingInsts() const;
123-
124-
using ConsumingInstsRange =
125-
TransformRange<ArrayRef<Operand *>, OperandToUser>;
126-
ConsumingInstsRange getAllConsumingInsts() const;
118+
SILInstruction::OperandUserRange getAllConsumingInsts() const;
127119

128120
/// If this LiveRange has a single destroying use, return that use. Otherwise,
129121
/// return nullptr.
@@ -198,16 +190,6 @@ class LLVM_LIBRARY_VISIBILITY OwnershipLiveRange {
198190
DeadEndBlocks &deadEndBlocks,
199191
ValueLifetimeAnalysis::Frontier &scratch);
200192
};
201-
202-
struct OwnershipLiveRange::OperandToUser {
203-
OperandToUser() {}
204-
205-
SILInstruction *operator()(const Operand *use) const {
206-
auto *nonConstUse = const_cast<Operand *>(use);
207-
return nonConstUse->getUser();
208-
}
209-
};
210-
211193
} // namespace semanticarc
212194
} // namespace swift
213195

0 commit comments

Comments
 (0)