Skip to content

Commit 484fc77

Browse files
authored
Merge pull request swiftlang#70301 from eeckstein/fixed-array
Add experimental support for fixed arrays
2 parents 665eb4f + ae27805 commit 484fc77

File tree

69 files changed

+1938
-46
lines changed

Some content is hidden

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

69 files changed

+1938
-46
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AllocVectorLowering.swift

Lines changed: 457 additions & 0 deletions
Large diffs are not rendered by default.

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
swift_compiler_sources(Optimizer
10+
AllocVectorLowering.swift
1011
AssumeSingleThreaded.swift
1112
AsyncDemotion.swift
1213
CleanupDebugSteps.swift

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ObjectOutliner.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -394,27 +394,6 @@ private extension InstructionWorklist {
394394
}
395395
}
396396

397-
private extension Value {
398-
/// Returns true if this value is a valid in a static initializer, including all its operands.
399-
var isValidGlobalInitValue: Bool {
400-
guard let svi = self as? SingleValueInstruction else {
401-
return false
402-
}
403-
if let beginAccess = svi as? BeginAccessInst {
404-
return beginAccess.address.isValidGlobalInitValue
405-
}
406-
if !svi.isValidInStaticInitializerOfGlobal {
407-
return false
408-
}
409-
for op in svi.operands {
410-
if !op.value.isValidGlobalInitValue {
411-
return false
412-
}
413-
}
414-
return true
415-
}
416-
}
417-
418397
private extension AllocRefInstBase {
419398
var fieldsKnownStatically: Bool {
420399
if let allocDynamic = self as? AllocRefDynamicInst,

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/SimplificationPasses.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protocol LateOnoneSimplifyable : Instruction {
3737
let ononeSimplificationPass = FunctionPass(name: "onone-simplification") {
3838
(function: Function, context: FunctionPassContext) in
3939

40-
_ = runSimplification(on: function, context, preserveDebugInfo: true) {
40+
runSimplification(on: function, context, preserveDebugInfo: true) {
4141
if let i = $0 as? OnoneSimplifyable {
4242
i.simplify($1)
4343
}
@@ -47,7 +47,7 @@ let ononeSimplificationPass = FunctionPass(name: "onone-simplification") {
4747
let simplificationPass = FunctionPass(name: "simplification") {
4848
(function: Function, context: FunctionPassContext) in
4949

50-
_ = runSimplification(on: function, context, preserveDebugInfo: false) {
50+
runSimplification(on: function, context, preserveDebugInfo: false) {
5151
if let i = $0 as? Simplifyable {
5252
i.simplify($1)
5353
}
@@ -57,7 +57,7 @@ let simplificationPass = FunctionPass(name: "simplification") {
5757
let lateOnoneSimplificationPass = FunctionPass(name: "late-onone-simplification") {
5858
(function: Function, context: FunctionPassContext) in
5959

60-
_ = runSimplification(on: function, context, preserveDebugInfo: true) {
60+
runSimplification(on: function, context, preserveDebugInfo: true) {
6161
if let i = $0 as? LateOnoneSimplifyable {
6262
i.simplifyLate($1)
6363
} else if let i = $0 as? OnoneSimplifyable {
@@ -70,7 +70,7 @@ let lateOnoneSimplificationPass = FunctionPass(name: "late-onone-simplification"
7070
// Pass implementation
7171
//===--------------------------------------------------------------------===//
7272

73-
73+
@discardableResult
7474
func runSimplification(on function: Function, _ context: FunctionPassContext,
7575
preserveDebugInfo: Bool,
7676
_ simplify: (Instruction, SimplifyContext) -> ()) -> Bool {

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBuiltin.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extension BuiltinInst : OnoneSimplifyable {
4141
.AssignCopyArrayFrontToBack,
4242
.AssignCopyArrayBackToFront,
4343
.AssignTakeArray,
44+
.AllocVector,
4445
.IsPOD:
4546
optimizeArgumentToThinMetatype(argument: 0, context)
4647
case .CreateAsyncTask:

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ extension Context {
4343
}
4444
}
4545

46+
var moduleIsSerialized: Bool { _bridged.moduleIsSerialized() }
47+
4648
func lookupDeinit(ofNominal: NominalTypeDecl) -> Function? {
4749
_bridged.lookUpNominalDeinitFunction(ofNominal.bridged).function
4850
}
51+
52+
func getBuiltinIntegerType(bitWidth: Int) -> Type { _bridged.getBuiltinIntegerType(bitWidth).type }
4953
}
5054

5155
/// A context which allows mutation of a function's SIL.
@@ -494,6 +498,11 @@ extension Instruction {
494498
bridged.setOperand(index, value.bridged)
495499
context.notifyInstructionChanged(self)
496500
}
501+
502+
func move(before otherInstruction: Instruction, _ context: some MutatingContext) {
503+
BridgedPassContext.moveInstructionBefore(bridged, otherInstruction.bridged)
504+
context.notifyInstructionsChanged()
505+
}
497506
}
498507

499508
extension BuiltinInst {

SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ struct Options {
2929
}
3030

3131
var enableEmbeddedSwift: Bool {
32-
_bridged.enableEmbeddedSwift()
32+
_bridged.hasFeature(.Embedded)
33+
}
34+
35+
func hasFeature(_ feature: BridgedPassContext.Feature) -> Bool {
36+
_bridged.hasFeature(feature)
3337
}
3438

3539
enum AssertConfiguration {

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private func registerSwiftPasses() {
6565
registerPass(stackProtection, { stackProtection.run($0) })
6666

6767
// Function passes
68+
registerPass(allocVectorLowering, { allocVectorLowering.run($0) })
6869
registerPass(asyncDemotion, { asyncDemotion.run($0) })
6970
registerPass(letPropertyLowering, { letPropertyLowering.run($0) })
7071
registerPass(mergeCondFailsPass, { mergeCondFailsPass.run($0) })

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,37 @@ extension Value {
131131
}
132132
return builder.createCopyValue(operand: self)
133133
}
134+
135+
/// True if this value is a valid in a static initializer, including all its operands.
136+
var isValidGlobalInitValue: Bool {
137+
guard let svi = self as? SingleValueInstruction else {
138+
return false
139+
}
140+
if let beginAccess = svi as? BeginAccessInst {
141+
return beginAccess.address.isValidGlobalInitValue
142+
}
143+
if !svi.isValidInStaticInitializerOfGlobal {
144+
return false
145+
}
146+
for op in svi.operands {
147+
if !op.value.isValidGlobalInitValue {
148+
return false
149+
}
150+
}
151+
return true
152+
}
153+
}
154+
155+
extension FullApplySite {
156+
func isSemanticCall(_ name: StaticString, withArgumentCount: Int) -> Bool {
157+
if arguments.count == withArgumentCount,
158+
let callee = referencedFunction,
159+
callee.hasSemanticsAttribute(name)
160+
{
161+
return true
162+
}
163+
return false
164+
}
134165
}
135166

136167
extension Builder {

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public struct Builder {
7373
}
7474
}
7575

76+
@discardableResult
7677
public func createCondFail(condition: Value, message: String) -> CondFailInst {
7778
return message._withBridgedStringRef { messageStr in
7879
let cf = bridged.createCondFail(condition.bridged, messageStr)
@@ -91,6 +92,11 @@ public struct Builder {
9192
return notifyNew(dr.getAs(AllocStackInst.self))
9293
}
9394

95+
public func createAllocVector(capacity: Value, elementType: Type) -> AllocVectorInst {
96+
let dr = bridged.createAllocVector(capacity.bridged, elementType.bridged)
97+
return notifyNew(dr.getAs(AllocVectorInst.self))
98+
}
99+
94100
@discardableResult
95101
public func createDeallocStack(_ operand: Value) -> DeallocStackInst {
96102
let dr = bridged.createDeallocStack(operand.bridged)
@@ -103,6 +109,12 @@ public struct Builder {
103109
return notifyNew(dr.getAs(DeallocStackRefInst.self))
104110
}
105111

112+
public func createAddressToPointer(address: Value, pointerType: Type,
113+
needStackProtection: Bool) -> AddressToPointerInst {
114+
let dr = bridged.createAddressToPointer(address.bridged, pointerType.bridged, needStackProtection)
115+
return notifyNew(dr.getAs(AddressToPointerInst.self))
116+
}
117+
106118
public func createUncheckedRefCast(from value: Value, to type: Type) -> UncheckedRefCastInst {
107119
let cast = bridged.createUncheckedRefCast(value.bridged, type.bridged)
108120
return notifyNew(cast.getAs(UncheckedRefCastInst.self))
@@ -118,6 +130,11 @@ public struct Builder {
118130
return notifyNew(load.getAs(LoadInst.self))
119131
}
120132

133+
public func createLoadBorrow(fromAddress: Value) -> LoadBorrowInst {
134+
let load = bridged.createLoadBorrow(fromAddress.bridged)
135+
return notifyNew(load.getAs(LoadBorrowInst.self))
136+
}
137+
121138
public func createBeginDeallocRef(reference: Value, allocation: AllocRefInstBase) -> BeginDeallocRefInst {
122139
let beginDealloc = bridged.createBeginDeallocRef(reference.bridged, allocation.bridged)
123140
return notifyNew(beginDealloc.getAs(BeginDeallocRefInst.self))
@@ -280,6 +297,14 @@ public struct Builder {
280297
return notifyNew(objectInst.getAs(ObjectInst.self))
281298
}
282299

300+
@discardableResult
301+
public func createVector(type: Type, arguments: [Value]) -> VectorInst {
302+
let vectorInst = arguments.withBridgedValues { valuesRef in
303+
return bridged.createVector(valuesRef)
304+
}
305+
return notifyNew(vectorInst.getAs(VectorInst.self))
306+
}
307+
283308
public func createGlobalAddr(global: GlobalVariable) -> GlobalAddrInst {
284309
return notifyNew(bridged.createGlobalAddr(global.bridged).getAs(GlobalAddrInst.self))
285310
}

0 commit comments

Comments
 (0)