mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
run the TargetConstantFolding pass also at -Onone
This is important for performance diagnostics: it’s assumed that (non-generic) MemoryLayout constants do not need to create metadata at runtime. At Onone this is only guaranteed if the TargetConstantFolding pass runs. rdar://94836837
This commit is contained in:
@@ -67,9 +67,6 @@ private:
|
||||
// Scan all instructions in the module for constant foldable instructions.
|
||||
for (SILFunction &function : *module) {
|
||||
|
||||
if (!function.shouldOptimize())
|
||||
continue;
|
||||
|
||||
bool changed = false;
|
||||
for (SILBasicBlock &block : function) {
|
||||
InstructionDeleter deleter;
|
||||
|
||||
@@ -978,6 +978,9 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
|
||||
P.startPipeline("Rest of Onone");
|
||||
P.addUsePrespecialized();
|
||||
|
||||
// Needed to fold MemoryLayout constants in performance-annotated functions.
|
||||
P.addTargetConstantFolding();
|
||||
|
||||
// Has only an effect if the -assume-single-thread option is specified.
|
||||
if (P.getOptions().AssumeSingleThreaded) {
|
||||
P.addAssumeSingleThreaded();
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
// RUN: mkdir -p %t/Mods/Foo.swiftmodule
|
||||
// RUN: mkdir -p %t/Mods/Bar.swiftmodule
|
||||
|
||||
// RUN: %target-swift-frontend %s -DFoo -emit-module -o %t/Mods/Foo.swiftmodule/armv7s-apple-ios.swiftmodule -emit-module-interface-path %t/Mods/Foo.swiftmodule/armv7s-apple-ios.swiftinterface -target armv7s-apple-ios10 -module-name Foo -enable-library-evolution -parse-stdlib
|
||||
// RUN: %target-swift-frontend %s -DFoo -emit-module -o %t/Mods/Foo.swiftmodule/arm.swiftmodule -emit-module-interface-path %t/Mods/Foo.swiftmodule/arm.swiftinterface -target arm-apple-ios10 -module-name Foo -enable-library-evolution -parse-stdlib
|
||||
// RUN: %target-swift-frontend %s -DBar -typecheck -emit-module-interface-path %t/Mods/Bar.swiftmodule/arm.swiftinterface -I %t/Mods -target arm-apple-ios10 -module-name Bar -enable-library-evolution -parse-stdlib
|
||||
// RUN: %target-swift-frontend %s -DFooBar -typecheck -emit-loaded-module-trace-path - -I %t/Mods -target armv7s-apple-ios10 -parse-stdlib
|
||||
// RUN: %target-swift-frontend %s -DFoo -emit-module -o %t/Mods/Foo.swiftmodule/armv7s-apple-ios.swiftmodule -emit-module-interface-path %t/Mods/Foo.swiftmodule/armv7s-apple-ios.swiftinterface -target armv7s-apple-ios10 -module-name Foo -enable-library-evolution -parse-stdlib -Xllvm -sil-disable-pass=target-constant-folding
|
||||
// RUN: %target-swift-frontend %s -DFoo -emit-module -o %t/Mods/Foo.swiftmodule/arm.swiftmodule -emit-module-interface-path %t/Mods/Foo.swiftmodule/arm.swiftinterface -target arm-apple-ios10 -module-name Foo -enable-library-evolution -parse-stdlib -Xllvm -sil-disable-pass=target-constant-folding
|
||||
// RUN: %target-swift-frontend %s -DBar -typecheck -emit-module-interface-path %t/Mods/Bar.swiftmodule/arm.swiftinterface -I %t/Mods -target arm-apple-ios10 -module-name Bar -enable-library-evolution -parse-stdlib -Xllvm -sil-disable-pass=target-constant-folding
|
||||
// RUN: %target-swift-frontend %s -DFooBar -typecheck -emit-loaded-module-trace-path - -I %t/Mods -target armv7s-apple-ios10 -parse-stdlib -Xllvm -sil-disable-pass=target-constant-folding
|
||||
|
||||
#if Foo
|
||||
#endif
|
||||
|
||||
35
test/SILOptimizer/memory-layout.swift
Normal file
35
test/SILOptimizer/memory-layout.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
// RUN: %target-swift-frontend -experimental-performance-annotations %s -O -sil-verify-all -module-name=test -emit-sil | %FileCheck %s
|
||||
|
||||
// Check that constant propagation of MemoryLayout is also done at -Onone to ensure that
|
||||
// no metadate is created at runtime - which would violate the performance annotation.
|
||||
|
||||
// CHECK-LABEL: sil [no_locks] @$s4test7getSizeSiyF
|
||||
// CHECK: [[I:%[0-9]+]] = integer_literal {{.*}}, 4
|
||||
// CHECK: [[S:%[0-9]+]] = struct {{.*}}([[I]]
|
||||
// CHECK: return [[S]]
|
||||
// CHECK: } // end sil function '$s4test7getSizeSiyF'
|
||||
@_noLocks
|
||||
public func getSize() -> Int {
|
||||
return MemoryLayout<Int32>.size
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil [no_locks] @$s4test12getAlignmentSiyF
|
||||
// CHECK: [[I:%[0-9]+]] = integer_literal {{.*}}, 4
|
||||
// CHECK: [[S:%[0-9]+]] = struct {{.*}}([[I]]
|
||||
// CHECK: return [[S]]
|
||||
// CHECK: } // end sil function '$s4test12getAlignmentSiyF'
|
||||
@_noLocks
|
||||
public func getAlignment() -> Int {
|
||||
return MemoryLayout<Int32>.alignment
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil [no_locks] @$s4test9getStrideSiyF
|
||||
// CHECK: [[I:%[0-9]+]] = integer_literal {{.*}}, 4
|
||||
// CHECK: [[S:%[0-9]+]] = struct {{.*}}([[I]]
|
||||
// CHECK: return [[S]]
|
||||
// CHECK: } // end sil function '$s4test9getStrideSiyF'
|
||||
@_noLocks
|
||||
public func getStride() -> Int {
|
||||
return MemoryLayout<Int32>.stride
|
||||
}
|
||||
|
||||
@@ -139,3 +139,12 @@ func callFuncWithMetatypeArg() {
|
||||
metatypeArg(Int.self, false) // expected-note {{called from here}}
|
||||
}
|
||||
|
||||
struct GenStruct<A> {
|
||||
var a: A
|
||||
}
|
||||
|
||||
@_noAllocation
|
||||
func memoryLayout() -> Int? {
|
||||
return MemoryLayout<GenStruct<Int>>.size
|
||||
}
|
||||
|
||||
|
||||
@@ -34,47 +34,46 @@ public func noConstantSize<T>(_ t: T.Type) -> Int {
|
||||
return MemoryLayout<T>.size
|
||||
}
|
||||
|
||||
// Check that there is not constant propagation if optimizations are disabled.
|
||||
// This is important for the runtime check to make sure that we are comparing
|
||||
// It's important to not constant propagate here to make sure that we are comparing
|
||||
// SIL constant propagated values with IRGen values.
|
||||
|
||||
// CHECK-LABEL: sil {{.*}} @$s4test7getSizeSiyF
|
||||
// CHECK: builtin "sizeof"<S>
|
||||
// CHECK: } // end sil function '$s4test7getSizeSiyF'
|
||||
// CHECK-LABEL: sil {{.*}} @$s4test7getSizeySixmlF
|
||||
// CHECK: builtin "sizeof"<T>
|
||||
// CHECK: } // end sil function '$s4test7getSizeySixmlF'
|
||||
@_optimize(none)
|
||||
func getSize() -> Int {
|
||||
return MemoryLayout<S>.size
|
||||
func getSize<T>(_ t: T.Type) -> Int {
|
||||
return MemoryLayout<T>.size
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil {{.*}} @$s4test12getAlignmentSiyF
|
||||
// CHECK: builtin "alignof"<S>
|
||||
// CHECK: } // end sil function '$s4test12getAlignmentSiyF'
|
||||
// CHECK-LABEL: sil {{.*}} @$s4test12getAlignmentySixmlF
|
||||
// CHECK: builtin "alignof"<T>
|
||||
// CHECK: } // end sil function '$s4test12getAlignmentySixmlF'
|
||||
@_optimize(none)
|
||||
func getAlignment() -> Int {
|
||||
return MemoryLayout<S>.alignment
|
||||
func getAlignment<T>(_ t: T.Type) -> Int {
|
||||
return MemoryLayout<T>.alignment
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil {{.*}} @$s4test9getStrideSiyF
|
||||
// CHECK: builtin "strideof"<S>
|
||||
// CHECK: } // end sil function '$s4test9getStrideSiyF'
|
||||
// CHECK-LABEL: sil {{.*}} @$s4test9getStrideySixmlF
|
||||
// CHECK: builtin "strideof"<T>
|
||||
// CHECK: } // end sil function '$s4test9getStrideySixmlF'
|
||||
@_optimize(none)
|
||||
func getStride() -> Int {
|
||||
return MemoryLayout<S>.stride
|
||||
func getStride<T>(_ t: T.Type) -> Int {
|
||||
return MemoryLayout<T>.stride
|
||||
}
|
||||
|
||||
@inline(never)
|
||||
func testit() {
|
||||
// CHECK-OUTPUT: size: true
|
||||
print("size: \(S.size == getSize())")
|
||||
print("size: \(S.size == getSize(S.self))")
|
||||
|
||||
// CHECK-OUTPUT: alignment: true
|
||||
print("alignment: \(S.alignment == getAlignment())")
|
||||
print("alignment: \(S.alignment == getAlignment(S.self))")
|
||||
|
||||
// CHECK-OUTPUT: stride: true
|
||||
print("stride: \(S.stride == getStride())")
|
||||
print("stride: \(S.stride == getStride(S.self))")
|
||||
|
||||
// CHECK-OUTPUT: doubleSize: true
|
||||
print("doubleSize: \(S.doubleSize == getSize() * 2)")
|
||||
print("doubleSize: \(S.doubleSize == getSize(S.self) * 2)")
|
||||
}
|
||||
|
||||
testit()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// RUN: %swift -target x86_64-unknown-darwin14 -o %t/mips-template.swiftmodule -parse-stdlib -emit-module -module-name mips %S/../Inputs/empty.swift
|
||||
// RUN: %swift -target x86_64-unknown-darwin14 -o %t/mips-template.swiftmodule -parse-stdlib -emit-module -module-name mips -Xllvm -sil-disable-pass=target-constant-folding %S/../Inputs/empty.swift
|
||||
// RUN: %{python} -u %S/Inputs/binary_sub.py x86_64-unknown-darwin14 mips64-unknown-darwin14 < %t/mips-template.swiftmodule > %t/mips.swiftmodule
|
||||
// RUN: not %target-swift-frontend -I %t -typecheck -parse-stdlib %s -DMIPS 2>&1 | %FileCheck -check-prefix=CHECK-MIPS %s
|
||||
|
||||
// RUN: %swift -target x86_64-unknown-darwin14 -o %t/solaris-template.swiftmodule -parse-stdlib -emit-module -module-name solaris %S/../Inputs/empty.swift
|
||||
// RUN: %swift -target x86_64-unknown-darwin14 -o %t/solaris-template.swiftmodule -parse-stdlib -emit-module -module-name solaris -Xllvm -sil-disable-pass=target-constant-folding %S/../Inputs/empty.swift
|
||||
// RUN: %{python} -u %S/Inputs/binary_sub.py x86_64-unknown-darwin14 x86_64-unknown-solaris8 < %t/solaris-template.swiftmodule > %t/solaris.swiftmodule
|
||||
// RUN: not %target-swift-frontend -I %t -typecheck -parse-stdlib %s -DSOLARIS 2>&1 | %FileCheck -check-prefix=CHECK-SOLARIS %s
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
// These checks should still hold with -enable-library-evolution.
|
||||
|
||||
// RUN: %swift -target x86_64-unknown-darwin14 -o %t/mips-template.swiftmodule -parse-stdlib -emit-module -module-name mips %S/../Inputs/empty.swift -enable-library-evolution
|
||||
// RUN: %swift -target x86_64-unknown-darwin14 -o %t/mips-template.swiftmodule -parse-stdlib -emit-module -module-name mips -Xllvm -sil-disable-pass=target-constant-folding %S/../Inputs/empty.swift -enable-library-evolution
|
||||
// RUN: %{python} -u %S/Inputs/binary_sub.py x86_64-unknown-darwin14 mips64-unknown-darwin14 < %t/mips-template.swiftmodule > %t/mips.swiftmodule
|
||||
// RUN: not %target-swift-frontend -I %t -typecheck -parse-stdlib %s -DMIPS 2>&1 | %FileCheck -check-prefix=CHECK-MIPS %s
|
||||
|
||||
// RUN: %swift -target x86_64-unknown-darwin14 -o %t/solaris-template.swiftmodule -parse-stdlib -emit-module -module-name solaris %S/../Inputs/empty.swift -enable-library-evolution
|
||||
// RUN: %swift -target x86_64-unknown-darwin14 -o %t/solaris-template.swiftmodule -parse-stdlib -emit-module -module-name solaris -Xllvm -sil-disable-pass=target-constant-folding %S/../Inputs/empty.swift -enable-library-evolution
|
||||
// RUN: %{python} -u %S/Inputs/binary_sub.py x86_64-unknown-darwin14 x86_64-unknown-solaris8 < %t/solaris-template.swiftmodule > %t/solaris.swiftmodule
|
||||
// RUN: not %target-swift-frontend -I %t -typecheck -parse-stdlib %s -DSOLARIS 2>&1 | %FileCheck -check-prefix=CHECK-SOLARIS %s
|
||||
|
||||
|
||||
@@ -10,5 +10,5 @@
|
||||
// CHECK-NEXT: "ownership-model-eliminator" ]
|
||||
// CHECK: ---
|
||||
// CHECK: name: Rest of Onone
|
||||
// CHECK: passes: [ "use-prespecialized", "sil-debuginfo-gen" ]
|
||||
// CHECK: passes: [ "use-prespecialized", "target-constant-folding", "sil-debuginfo-gen" ]
|
||||
// CHECK: ...
|
||||
|
||||
Reference in New Issue
Block a user