Skip to content

Commit 53363c7

Browse files
committed
WalkUtils: add UnusedWalkingPath
Which is a walking path which matches everything. Useful for walkers which don't care about the path and unconditionally walk to all defs/uses.
1 parent 81ac311 commit 53363c7

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ReleaseDevirtualizer.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,17 @@ private struct FindAllocationOfRelease : ValueUseDefWalker {
113113
private let allocInst: AllocRefInstBase
114114
private var allocFound = false
115115

116-
var walkUpCache = WalkerCache<SmallProjectionPath>()
116+
var walkUpCache = WalkerCache<UnusedWalkingPath>()
117117

118118
init(allocation: AllocRefInstBase) { allocInst = allocation }
119119

120120
/// The top-level entry point: returns true if the root of `value` is the `allocInst`.
121121
mutating func allocationIsRoot(of value: Value) -> Bool {
122-
let path = SmallProjectionPath().push(.anyValueFields)
123-
return walkUp(value: value, path: path) != .abortWalk &&
122+
return walkUp(value: value, path: UnusedWalkingPath()) != .abortWalk &&
124123
allocFound
125124
}
126125

127-
mutating func rootDef(value: Value, path: SmallProjectionPath) -> WalkResult {
126+
mutating func rootDef(value: Value, path: UnusedWalkingPath) -> WalkResult {
128127
if value == allocInst {
129128
allocFound = true
130129
return .continueWalk
@@ -134,7 +133,7 @@ private struct FindAllocationOfRelease : ValueUseDefWalker {
134133

135134
// This function is called for `struct` and `tuple` instructions in case the `path` doesn't select
136135
// a specific operand but all operands.
137-
mutating func walkUpAllOperands(of def: Instruction, path: SmallProjectionPath) -> WalkResult {
136+
mutating func walkUpAllOperands(of def: Instruction, path: UnusedWalkingPath) -> WalkResult {
138137

139138
// Instead of walking up _all_ operands (which would be the default behavior), require that only a
140139
// _single_ operand is not trivial and walk up that operand.

SwiftCompilerSources/Sources/Optimizer/Utilities/WalkUtils.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ extension SmallProjectionWalkingPath {
106106
}
107107
}
108108

109+
/// A walking path which matches everything.
110+
///
111+
/// Useful for walkers which don't care about the path and unconditionally walk to all defs/uses.
112+
struct UnusedWalkingPath : WalkingPath {
113+
func merge(with: Self) -> Self { self }
114+
func pop(kind: FieldKind) -> (index: Int, path: Self)? { nil }
115+
func popIfMatches(_ kind: FieldKind, index: Int?) -> Self? { self }
116+
func push(_ kind: FieldKind, index: Int) -> Self { self }
117+
}
118+
109119
/// Caches the state of a walk.
110120
///
111121
/// A client must provide this cache in a `walkUpCache` or `walkDownCache` property.

0 commit comments

Comments
 (0)