Skip to content

Commit 5fc50a0

Browse files
committed
AddressUtils: refactor the findSingleInitializer API.
1 parent a3cbc28 commit 5fc50a0

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/AddressUtils.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ extension AccessBase {
192192
/// with the initialized address. This does not guarantee that all
193193
/// uses of that address are dominated by the store or even that the
194194
/// store is a direct use of `address`.
195-
func findSingleInitializer(_ context: some Context)
196-
-> (initialAddress: Value, initializingStore: Instruction)? {
195+
func findSingleInitializer(_ context: some Context) -> (initialAddress: Value, initializingStore: Instruction)? {
197196
let baseAddr: Value
198197
switch self {
199198
case let .stack(allocStack):
@@ -206,15 +205,7 @@ extension AccessBase {
206205
default:
207206
return nil
208207
}
209-
var walker = AddressInitializationWalker(context: context)
210-
if walker.walkDownUses(ofAddress: baseAddr, path: SmallProjectionPath())
211-
== .abortWalk {
212-
return nil
213-
}
214-
guard let initializingStore = walker.initializingStore else {
215-
return nil
216-
}
217-
return (initialAddress: baseAddr, initializingStore: initializingStore)
208+
return AddressInitializationWalker.findSingleInitializer(ofAddress: baseAddr, context: context)
218209
}
219210
}
220211

@@ -223,6 +214,9 @@ extension AccessBase {
223214
// Implements AddressUseVisitor to guarantee that we can't miss any
224215
// stores. This separates escapingAddressUse from leafAddressUse.
225216
//
217+
// Main entry point:
218+
// static func findSingleInitializer(ofAddress: Value, context: some Context)
219+
//
226220
// TODO: Make AddressDefUseWalker always conform to AddressUseVisitor once we're
227221
// ready to debug changes to escape analysis etc...
228222
//
@@ -249,6 +243,19 @@ struct AddressInitializationWalker: AddressDefUseWalker, AddressUseVisitor {
249243
var isProjected = false
250244
var initializingStore: Instruction?
251245

246+
static func findSingleInitializer(ofAddress baseAddr: Value, context: some Context)
247+
-> (initialAddress: Value, initializingStore: Instruction)? {
248+
249+
var walker = AddressInitializationWalker(context: context)
250+
if walker.walkDownUses(ofAddress: baseAddr, path: SmallProjectionPath()) == .abortWalk {
251+
return nil
252+
}
253+
guard let initializingStore = walker.initializingStore else {
254+
return nil
255+
}
256+
return (initialAddress: baseAddr, initializingStore: initializingStore)
257+
}
258+
252259
private mutating func setInitializer(instruction: Instruction) -> WalkResult {
253260
// An initializer must be unique and store the full value.
254261
if initializingStore != nil || isProjected {

0 commit comments

Comments
 (0)