Skip to content

Cross module optimization #28407

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

Merged
merged 4 commits into from
Dec 3, 2019

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Nov 21, 2019

This is a first version of cross module optimization (CMO).

The basic idea for CMO is to use the existing library evolution compiler features, but in an automated way. A new SIL module pass "annotates" functions and types with @inlinable and @usableFromInline. This results in functions being serialized into the swiftmodule file and thus available for optimizations in client modules.
The annotation is done with a worklist-algorithm, starting from public functions and continuing with entities which are used from already selected functions. A heuristic performs a preselection on which functions to consider - currently just generic functions are selected.

The serializer then writes annotated functions (including function bodies) into the swiftmodule file of the compiled module. Client modules are able to de-serialize such functions from their imported modules and use them for optimiations, like generic specialization.

The optimization is gated by a new compiler option -cross-module-optimization (also available in the swift driver).
By default this option is off. Without turning the option on, this change is (almost) a NFC.

rdar://problem/22591518

@eeckstein eeckstein force-pushed the cross-module-optimization branch from 63da35b to 1432022 Compare November 25, 2019 10:06
@eeckstein eeckstein changed the title [DNM] Cross module optimization Cross module optimization Nov 25, 2019
@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1432022753aadfd282a1719c78e896adc1fddc1d

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1432022753aadfd282a1719c78e896adc1fddc1d

@eeckstein eeckstein force-pushed the cross-module-optimization branch from 1432022 to d33e5b1 Compare November 25, 2019 13:29
@eeckstein
Copy link
Contributor Author

@swift-ci test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein force-pushed the cross-module-optimization branch from d33e5b1 to 9a7370e Compare December 2, 2019 10:53
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein force-pushed the cross-module-optimization branch 2 times, most recently from 0855d29 to aa9f0ee Compare December 2, 2019 19:30
…) function from inlinable code.

This problem can show up with cross module optimization.
…ly visible.

This is needed for cross-module-optimization: CMO marks functions as inlinable. If a private or internal method is referenced from such an inlinable function, it must not be eliminated by dead function elimination after serialization (a method is basically an AbstractFunctionDecl).
For SILFunctions we can do this by simply setting the linkage, but for methods we need another mechanism.
…th components into a general utility.

This is a NFC
This is a first version of cross module optimization (CMO).

The basic idea for CMO is to use the existing library evolution compiler features, but in an automated way. A new SIL module pass "annotates" functions and types with @inlinable and @usableFromInline. This results in functions being serialized into the swiftmodule file and thus available for optimizations in client modules.
The annotation is done with a worklist-algorithm, starting from public functions and continuing with entities which are used from already selected functions. A heuristic performs a preselection on which functions to consider - currently just generic functions are selected.

The serializer then writes annotated functions (including function bodies) into the swiftmodule file of the compiled module. Client modules are able to de-serialize such functions from their imported modules and use them for optimiations, like generic specialization.

The optimization is gated by a new compiler option -cross-module-optimization (also available in the swift driver).
By default this option is off. Without turning the option on, this change is (almost) a NFC.

rdar://problem/22591518
@eeckstein eeckstein force-pushed the cross-module-optimization branch from aa9f0ee to a5397b4 Compare December 3, 2019 13:38
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein merged commit 835c701 into swiftlang:master Dec 3, 2019
@eeckstein eeckstein deleted the cross-module-optimization branch December 3, 2019 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants