Skip to content

Commit 67affbd

Browse files
Merge pull request #4940 from swiftwasm/katei/merge-main-2022-09-24
Merge main 2022-09-24
2 parents d818dc6 + 1403f85 commit 67affbd

File tree

270 files changed

+15857
-4874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

270 files changed

+15857
-4874
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/FunctionUses.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ struct FunctionUses {
134134

135135
for witnessTable in context.witnessTables {
136136
for entry in witnessTable.entries {
137-
if entry.kind == .Method, let f = entry.methodFunction {
137+
if entry.kind == .method, let f = entry.methodFunction {
138138
markUnknown(f)
139139
}
140140
}
141141
}
142142

143143
for witnessTable in context.defaultWitnessTables {
144144
for entry in witnessTable.entries {
145-
if entry.kind == .Method, let f = entry.methodFunction {
145+
if entry.kind == .method, let f = entry.methodFunction {
146146
markUnknown(f)
147147
}
148148
}

SwiftCompilerSources/Sources/Optimizer/ModulePasses/StackProtection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private struct StackProtectionOptimization {
124124
mustFixStackNesting: inout Bool, _ context: PassContext) {
125125

126126
// `withUnsafeTemporaryAllocation(of:capacity:_:)` is compiled to a `builtin "stackAlloc"`.
127-
if let bi = instruction as? BuiltinInst, bi.id == .StackAlloc {
127+
if let bi = instruction as? BuiltinInst, bi.id == .stackAlloc {
128128
function.setNeedsStackProtection(context)
129129
return
130130
}
@@ -332,7 +332,7 @@ private struct StackProtectionOptimization {
332332
/// Moves the value of a `beginAccess` to a temporary stack location, if possible.
333333
private func moveToTemporary(scope beginAccess: BeginAccessInst, mustFixStackNesting: inout Bool,
334334
_ context: PassContext) {
335-
if beginAccess.accessKind != .Modify {
335+
if beginAccess.accessKind != .modify {
336336
// We can only move from a `modify` access.
337337
// Also, read-only accesses shouldn't be subject to buffer overflows (because
338338
// no one should ever write to such a storage).

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
422422
return walkDownUses(ofAddress: pta, path: path.with(knownType: nil))
423423
case let bi as BuiltinInst:
424424
switch bi.id {
425-
case .DestroyArray:
425+
case .destroyArray:
426426
// If it's not the array base pointer operand -> bail. Though, that shouldn't happen
427427
// because the other operands (metatype, count) shouldn't be visited anyway.
428428
if operand.index != 1 { return isEscaping }

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,19 @@ final public class LoadUnownedInst : SingleValueInstruction, UnaryInstruction {}
319319
final public class LoadBorrowInst : SingleValueInstruction, UnaryInstruction {}
320320

321321
final public class BuiltinInst : SingleValueInstruction {
322-
public typealias ID = swift.BuiltinValueKind
322+
// TODO: find a way to directly reuse the BuiltinValueKind enum
323+
public enum ID {
324+
case none
325+
case destroyArray
326+
case stackAlloc
327+
}
323328

324329
public var id: ID {
325-
return BuiltinInst_getID(bridged)
330+
switch BuiltinInst_getID(bridged) {
331+
case DestroyArrayBuiltin: return .destroyArray
332+
case StackAllocBuiltin: return .stackAlloc
333+
default: return .none
334+
}
326335
}
327336
}
328337

@@ -533,12 +542,34 @@ final public class BridgeObjectToRefInst : SingleValueInstruction,
533542
final public class BridgeObjectToWordInst : SingleValueInstruction,
534543
UnaryInstruction {}
535544

536-
public typealias AccessKind = swift.SILAccessKind
545+
public enum AccessKind {
546+
case initialize
547+
case read
548+
case modify
549+
case deinitialize
550+
}
551+
552+
extension BridgedAccessKind {
553+
var kind: AccessKind {
554+
switch self {
555+
case AccessKind_Init:
556+
return .initialize
557+
case AccessKind_Read:
558+
return .read
559+
case AccessKind_Modify:
560+
return .modify
561+
case AccessKind_Deinit:
562+
return .deinitialize
563+
default:
564+
fatalError("unsupported access kind")
565+
}
566+
}
567+
}
537568

538569

539570
// TODO: add support for begin_unpaired_access
540571
final public class BeginAccessInst : SingleValueInstruction, UnaryInstruction {
541-
public var accessKind: AccessKind { BeginAccessInst_getAccessKind(bridged) }
572+
public var accessKind: AccessKind { BeginAccessInst_getAccessKind(bridged).kind }
542573
}
543574

544575
public protocol ScopedInstruction {

SwiftCompilerSources/Sources/SIL/WitnessTable.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,28 @@ public struct WitnessTable : CustomStringConvertible, CustomReflectable {
2020
public struct Entry : CustomStringConvertible, CustomReflectable {
2121
fileprivate let bridged: BridgedWitnessTableEntry
2222

23-
public typealias Kind = swift.SILWitnessTable.WitnessKind
23+
public enum Kind {
24+
case invalid
25+
case method
26+
case associatedType
27+
case associatedTypeProtocol
28+
case baseProtocol
29+
}
2430

2531
public var kind: Kind {
26-
return SILWitnessTableEntry_getKind(bridged)
32+
switch SILWitnessTableEntry_getKind(bridged) {
33+
case SILWitnessTableEntry_Invalid: return .invalid
34+
case SILWitnessTableEntry_Method: return .method
35+
case SILWitnessTableEntry_AssociatedType: return .associatedType
36+
case SILWitnessTableEntry_AssociatedTypeProtocol: return .associatedTypeProtocol
37+
case SILWitnessTableEntry_BaseProtocol: return .baseProtocol
38+
default:
39+
fatalError("unknown witness table kind")
40+
}
2741
}
2842

2943
public var methodFunction: Function? {
30-
assert(kind == .Method)
44+
assert(kind == .method)
3145
return SILWitnessTableEntry_getMethodFunction(bridged).function
3246
}
3347

benchmark/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ set(SWIFT_BENCH_MODULES
162162
single-source/RomanNumbers
163163
single-source/SIMDRandomMask
164164
single-source/SIMDReduceInteger
165+
single-source/SimpleArraySpecialization
165166
single-source/SequenceAlgos
166167
single-source/SetTests
167168
single-source/SevenBoom
@@ -215,6 +216,7 @@ endif()
215216

216217
set(BENCH_LIBRARY_MODULES
217218
utils/TestsUtils
219+
utils/SimpleArray
218220
)
219221

220222
set(BENCH_DRIVER_LIBRARY_MODULES

benchmark/Package.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ var multiSourceLibraries: [(parentSubDir: String, name: String)] = multiSourceLi
7878

7979
var products: [Product] = []
8080
products.append(.library(name: "TestsUtils", type: .static, targets: ["TestsUtils"]))
81+
products.append(.library(name: "SimpleArray", type: .static, targets: ["SimpleArray"]))
8182
products.append(.library(name: "DriverUtils", type: .static, targets: ["DriverUtils"]))
8283
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
8384
products.append(.library(name: "ObjectiveCTests", type: .static, targets: ["ObjectiveCTests"]))
@@ -96,6 +97,12 @@ products += multiSourceLibraries.map {
9697

9798
var targets: [Target] = []
9899
targets.append(.target(name: "TestsUtils", path: "utils", sources: ["TestsUtils.swift"]))
100+
targets.append(.target(
101+
name: "SimpleArray",
102+
path: "utils",
103+
sources: ["SimpleArray.swift"],
104+
swiftSettings: [.unsafeFlags(["-Xfrontend",
105+
"-enable-experimental-layout-prespecialization"])]))
99106
targets.append(.systemLibrary(name: "LibProc", path: "utils/LibProc"))
100107
targets.append(
101108
.target(name: "DriverUtils",
@@ -129,7 +136,7 @@ targets.append(
129136
publicHeadersPath: "."))
130137
#endif
131138

132-
var singleSourceDeps: [Target.Dependency] = [.target(name: "TestsUtils")]
139+
var singleSourceDeps: [Target.Dependency] = [.target(name: "TestsUtils"), .target(name: "SimpleArray")]
133140
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
134141
singleSourceDeps.append(.target(name: "ObjectiveCTests"))
135142
#endif
@@ -147,7 +154,9 @@ targets += singleSourceLibraries.map { name in
147154
return .target(name: name,
148155
dependencies: singleSourceDeps,
149156
path: "single-source",
150-
sources: ["\(name).swift"])
157+
sources: ["\(name).swift"],
158+
swiftSettings: [.unsafeFlags(["-Xfrontend",
159+
"-enable-experimental-layout-prespecialization"])])
151160
}
152161

153162
targets += cxxSingleSourceLibraries.map { name in

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ function (swift_benchmark_compile_archopts)
354354
set(common_options
355355
"-c"
356356
"-target" "${target}"
357-
"-${BENCH_COMPILE_ARCHOPTS_OPT}" ${PAGE_ALIGNMENT_OPTION})
357+
"-${BENCH_COMPILE_ARCHOPTS_OPT}" ${PAGE_ALIGNMENT_OPTION}
358+
"-Xfrontend" "-enable-experimental-layout-prespecialization")
358359

359360
if(SWIFT_BENCHMARK_GENERATE_DEBUG_INFO)
360361
list(APPEND common_options "-g")
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// This benchmark tests prespecialization of a simplified array type
14+
15+
import TestsUtils
16+
import SimpleArray
17+
18+
public let benchmarks = [
19+
BenchmarkInfo(
20+
name: "SimpleArraySpecialization",
21+
runFunction: run_SimpleArraySpecializationBenchmarks,
22+
tags: [.abstraction, .runtime, .cpubench]
23+
),
24+
BenchmarkInfo(
25+
name: "SimpleArraySpecialization2",
26+
runFunction: run_SimpleArraySpecializationBenchmarks2,
27+
tags: [.abstraction, .runtime, .cpubench]
28+
),
29+
BenchmarkInfo(
30+
name: "SimpleArraySpecialization3",
31+
runFunction: run_SimpleArraySpecializationBenchmarks3,
32+
tags: [.abstraction, .runtime, .cpubench]
33+
),
34+
BenchmarkInfo(
35+
name: "SimpleArraySpecialization4",
36+
runFunction: run_SimpleArraySpecializationBenchmarks4,
37+
tags: [.abstraction, .runtime, .cpubench]
38+
),
39+
]
40+
41+
let xs = SimpleArray<MyClass>(capacity: 100_000)
42+
43+
@_silgen_name("_swift_stdlib_immortalize")
44+
func _stdlib_immortalize(_ obj: AnyObject)
45+
46+
import Foundation
47+
48+
49+
public final class MyClass {
50+
public var x: Int = 23
51+
}
52+
53+
54+
@inline(never)
55+
public func run_SimpleArraySpecializationBenchmarks(_ n: Int) {
56+
let myObject = MyClass()
57+
58+
// prevent refcount overflow
59+
_stdlib_immortalize(myObject)
60+
61+
for _ in 0..<n {
62+
for i in 0..<100_000 {
63+
xs.append(myObject)
64+
}
65+
xs.clear()
66+
}
67+
68+
blackHole(xs)
69+
}
70+
71+
@inline(never)
72+
public func run_SimpleArraySpecializationBenchmarks2(_ n: Int) {
73+
let myObject = MyClass()
74+
75+
// prevent refcount overflow
76+
_stdlib_immortalize(myObject)
77+
78+
for _ in 0..<n {
79+
for i in 0..<100_000 {
80+
xs.append2(myObject)
81+
}
82+
xs.clear()
83+
}
84+
85+
blackHole(xs)
86+
}
87+
88+
@inline(never)
89+
public func run_SimpleArraySpecializationBenchmarks3(_ n: Int) {
90+
let myObject = MyClass()
91+
92+
// prevent refcount overflow
93+
_stdlib_immortalize(myObject)
94+
95+
for _ in 0..<n {
96+
for i in 0..<100_000 {
97+
xs.append3(myObject)
98+
}
99+
xs.clear()
100+
}
101+
102+
blackHole(xs)
103+
}
104+
105+
@inline(never)
106+
public func run_SimpleArraySpecializationBenchmarks4(_ n: Int) {
107+
let myObject = MyClass()
108+
109+
// prevent refcount overflow
110+
_stdlib_immortalize(myObject)
111+
112+
for _ in 0..<n {
113+
for i in 0..<100_000 {
114+
xs.append4(myObject)
115+
}
116+
xs.clear()
117+
}
118+
119+
blackHole(xs)
120+
}

benchmark/utils/DriverUtils.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,7 @@ final class TestRunner {
665665
(c.logMemory ? [r.meta?.maxRSS].compactMap { $0 } : []) +
666666
(c.logMeta ? r.meta.map {
667667
[$0.pages, $0.ics, $0.yields] } ?? [] : [])
668-
return values.map {
669-
(c.delta && $0 == 0) ? "" : String($0) } // drop 0s in deltas
668+
return values.map { String($0) }
670669
}
671670
let benchmarkStats = (
672671
[index, t.name] + (results.map(values) ?? ["Unsupported"])

0 commit comments

Comments
 (0)