Skip to content

Commit 6ef1064

Browse files
committed
Optimizer: add ModuleTest
1 parent 751e52c commit 6ef1064

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public func initializeSwiftModules() {
2323
registerOptimizerTests()
2424
}
2525

26-
private func registerPass(
26+
func registerPass(
2727
_ pass: ModulePass,
2828
_ runFn: @escaping (@convention(c) (BridgedContext) -> ())) {
2929
pass.name._withBridgedStringRef { nameStr in

SwiftCompilerSources/Sources/Optimizer/Utilities/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ swift_compiler_sources(Optimizer
1111
Devirtualization.swift
1212
EscapeUtils.swift
1313
FunctionSignatureTransforms.swift
14-
FunctionTest.swift
1514
GenericSpecialization.swift
1615
LifetimeDependenceUtils.swift
1716
LocalVariableUtils.swift
1817
OptUtils.swift
1918
OwnershipLiveness.swift
19+
Test.swift
2020
)

SwiftCompilerSources/Sources/Optimizer/Utilities/FunctionTest.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===----------- FunctionTest.swift ---------------------------------------===//
1+
//===----------- Test.swift -----------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -14,15 +14,15 @@
1414
//
1515
// For general documentation on how to write tests see `Test.swift` in the
1616
// SIL module.
17-
// To add an optimizer test, use `FunctionTest` instead of `Test` and register
18-
// it in `registerOptimizerTests`.
17+
// To add an optimizer test, use `FunctionTest` or `ModuleTest` instead of `Test`
18+
// and register it in `registerOptimizerTests`.
1919
//
2020
//===----------------------------------------------------------------------===//
2121

2222
import SIL
2323
import OptimizerBridging
2424

25-
/// Like `SIL.Test`, but provides a `FunctionPass` to the invocation closure.
25+
/// Like `SIL.Test`, but provides a `FunctionPassContext` to the invocation closure.
2626
struct FunctionTest {
2727
let name: String
2828
let invocation: FunctionTestInvocation
@@ -33,6 +33,17 @@ struct FunctionTest {
3333
}
3434
}
3535

36+
/// Like `SIL.Test`, but provides a `ModulePassContext` to the invocation closure.
37+
/// This is just a wrapper around a `ModulePass` with the name "test-<testname>".
38+
/// Therefore, module tests must also be added to `Passes.def`.
39+
struct ModuleTest {
40+
let pass: ModulePass
41+
42+
public init(_ name: String, invocation: @escaping (ModulePassContext) -> ()) {
43+
self.pass = ModulePass(name: "test-" + name, invocation)
44+
}
45+
}
46+
3647
/// The type of the closure passed to a FunctionTest.
3748
typealias FunctionTestInvocation = @convention(thin) (Function, TestArguments, FunctionPassContext) -> ()
3849

@@ -74,6 +85,10 @@ private func registerFunctionTest(_ test: FunctionTest) {
7485
}
7586
}
7687

88+
private func registerModuleTest(_ test: ModuleTest, _ runFn: @escaping (@convention(c) (BridgedContext) -> ())) {
89+
registerPass(test.pass, runFn)
90+
}
91+
7792
/// The function called by the swift::test::FunctionTest which invokes the
7893
/// actual test function.
7994
///

0 commit comments

Comments
 (0)