Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,25 @@ let objectOutliner = FunctionPass(name: "object-outliner") {
return
}

for inst in function.instructions {
if let ari = inst as? AllocRefInstBase {
if !context.continueWithNextSubpassRun(for: inst) {
var allocRefs = Stack<AllocRefInstBase>(context)
defer { allocRefs.deinitialize() }

allocRefs.append(contentsOf: function.instructions.lazy.compactMap { $0 as? AllocRefInstBase })

// Try multiple iterations to handle multi-dimensional arrays.
var changed: Bool
repeat {
changed = false
for ari in allocRefs where !ari.isDeleted {
if !context.continueWithNextSubpassRun(for: ari) {
return
}
if let globalValue = optimizeObjectAllocation(allocRef: ari, context) {
optimizeFindStringCall(stringArray: globalValue, context)
changed = true
}
}
}
} while changed
}

private func optimizeObjectAllocation(allocRef: AllocRefInstBase, _ context: FunctionPassContext) -> GlobalValueInst? {
Expand Down
6 changes: 5 additions & 1 deletion test/SILOptimizer/readonly_arrays.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// CHECK-DAG: @"$s4test3StrV9staticLet_WZTv_r" = {{.*}} constant {{.*}} @"$ss20__StaticArrayStorageCN", {{.*}} @_swiftImmortalRefCount
// CHECK-DAG: @"$s4test3StrV9staticVar_WZTv_r" = {{.*}} constant {{.*}} @"$ss20__StaticArrayStorageCN", {{.*}} @_swiftImmortalRefCount
// CHECK-DAG: @"$s4test3StrV9staticVarSaySiGvpZ" = global %TSa <{ %Ts12_ArrayBufferV <{ %Ts14_BridgeStorageV <{ ptr @"$s4test3StrV9staticVar_WZTv_r" }> }> }>
// CHECK-NOT: swift_initStaticObject
// CHECK-DAG: @"$s4test3StrV14twoDimensionalSaySaySiGGvpZ" = global %TSa <{ %Ts12_ArrayBufferV <{ %Ts14_BridgeStorageV <{ ptr @"$s4test3StrV14twoDimensional_WZTv{{[0-9]*}}_r" }> }> }>, align 8

// UNSUPPORTED: use_os_stdlib

Expand All @@ -28,6 +28,7 @@
public struct Str {
public static let staticLet = [ 200, 201, 202 ]
public static var staticVar = [ 300, 301, 302 ]
public static var twoDimensional = [[1, 2], [3, 4], [5, 6]]
}

@inline(never)
Expand Down Expand Up @@ -72,6 +73,9 @@ print(Str.staticLet)
// CHECK-OUTPUT: [300, 301, 302]
print(Str.staticVar)

// CHECK-OUTPUT{LITERAL}: [[1, 2], [3, 4], [5, 6]]
print(Str.twoDimensional)

// CHECK-OUTPUT-NEXT: 11
print(arrayLookup(1))

Expand Down