-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Optimize Specializations of Variadic Generics by Eliminating Parameter Packs #84513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/PassManager/FunctionPassContext.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
bf95a88 to
a84ca01
Compare
|
@swift-ci smoke test macOS |
1 similar comment
|
@swift-ci smoke test macOS |
SwiftCompilerSources/Sources/Optimizer/PassManager/FunctionPassContext.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
|
|
||
| public var packExpansionPatternType: Type { bridged.getPackExpansionPatternType().type } | ||
|
|
||
| public var hasParameterPack: Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to move (most of) these APIs to TypeProperties so that they are also available for AST.Type and AST.CanonicalType. The SILType implementation forwards them to the AST type, anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift
Show resolved
Hide resolved
9e37826 to
6b9f9ec
Compare
|
@swift-ci test |
|
@swift-ci smoke test linux |
|
@swift-ci smoke test macos |
|
@swift-ci smoke test |
|
@swift-ci smoke test macos |
|
@swift-ci smoke test linux |
Many changes have been made since this approval.
|
*a few |
|
@swift-ci test windows |
|
@swift-ci please smoke benchmark |
|
@swift-ci smoke test macos |
|
@swift-ci smoke test macos |
|
@swift-ci smoke test linux |
|
@swift-ci test windows |
|
@swift-ci test macos |
|
@swift-ci test windows |
|
@swift-ci smoke test |
|
@swift-ci smoke test macos |
|
@swift-ci Please Test Source Compatibility Release |
|
@swift-ci test macos |
1 similar comment
|
@swift-ci test macos |
rdar://161182876
There are two key barriers that prevent variadic generic specialisations from being optimised in most cases:
Targeted modifications to eliminate these barriers will allow other passes to fully optimise variadic generic specialisations.
This PR only addresses the first barrier, indirect packs as function arguments.
The simplest way to eliminate indirect packs from the calling convention is effectively to move the stack allocations for the packs and pack elements inside the callee, and use the addresses of these local allocations in the main body, which is otherwise unchanged. These allocations can be eliminated by other passes once dynamic pack loops are optimised.
This transformation is performed by a function pass (currently called pack-specialization). For example, it would transform the following specialisation like so:
Note that the return values are all now direct, so bb0 only needs arguments corresponding to the xs parameter pack.
To optimise a pack loop, it must be unrolled. The pack element type is then statically known in each unrolled instance of the body. The existing loop unrolling pass can consistently do this in variadic generic specialisations, since the (known constant) pack length is used as the number of iterations. This still leaves constructs like the following:
In this context, we could easily replace all instances of the @pack_element type with Int. This would allow the appropriate witness method to be inlined. We will perform this in an instruction simplification for open_pack_element.