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
stdlib, SIL optimizer: use the SIL copy-on-write representation in the Array types. #32134
Conversation
@swift-ci test |
@swift-ci benchmark |
Build failed |
@swift-ci test macOS |
Performance: -O
Code size: -O
Performance: -Osize
Code size: -Osize
Performance: -Onone
Code size: -swiftlibs
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
Build failed |
Build failed |
@swift-ci test |
1 similar comment
@swift-ci test |
Build failed |
Build failed |
@swift-ci clean test |
Build failed |
Build failed |
@swift-ci clean test |
Build failed |
@swift-ci clean test |
Build failed |
Build failed |
@swift-ci clean test macOS |
1 similar comment
@swift-ci clean test macOS |
@swift-ci clean test linux |
Build failed |
Build failed |
@swift-ci test |
@swift-ci clean test |
1 similar comment
@swift-ci clean test |
Build failed |
Build failed |
@swift-ci clean test |
Build failed |
Build failed |
@swift-ci clean test macOS |
@swift-ci smoke test macOS |
1 similar comment
@swift-ci smoke test macOS |
Build failed |
@swift-ci clean smoke test macOS |
@swift-ci smoke test macOS |
Update differentiation to handle `array.finalize_intrinsic` applications. `VJPEmitter::visitApplyInst` does standard cloning for these applications. `PullbackEmitter::visitApplyInst` treats the intrinsic like an identity function, accumulating result's adjoint into argument's adjoint. This fixes array literal initialization differentiation.
This fixes a correctness issue. The begin_cow_mutation instruction has dependencies with instructions which retain the buffer operand. This prevents optimizations from moving begin_cow_mutation instructions across such retain instructions.
For COW support in SIL it's required to "finalize" array literals. _finalizeUninitializedArray is a compiler known stdlib function which is called after all elements of an array literal are stored. This runtime function marks the array literal as finished. %uninitialized_result_tuple = apply %_allocateUninitializedArray(%count) %mutable_array = tuple_extract %uninitialized_result_tuple, 0 %elem_base_address = tuple_extract %uninitialized_result_tuple, 1 ... store %elem_0 to %elem_addr_0 store %elem_1 to %elem_addr_1 ... %final_array = apply %_finalizeUninitializedArray(%mutable_array) In this commit _finalizeUninitializedArray is still a no-op because the COW support is not used in the Array implementation yet.
…COW buffer runtime checking. In an assert built of the library, store an extra boolean flag (isImmutable) in the object side-buffer table. This flag can be set and get by the Array implementation to sanity check the immutability status of the buffer object.
…e Array types. Use the new builtins for COW representation in Array, ContiguousArray and ArraySlice. The basic idea is to strictly separate code which mutates an array buffer from code which reads from an array. The concept is explained in more detail in docs/SIL.rst, section "Copy-on-Write Representation". The main change is to use beginCOWMutation() instead of isUniquelyReferenced() and insert endCOWMutation() at the end of all mutating functions. Also, reading from the array buffer must be done differently, depending on if the buffer is in a mutable or immutable state. All the required invariants are enforced by runtime checks - but only in an assert-build of the library: a bit in the buffer object side-table indicates if the buffer is mutable or not. Along with the library changes, also two optimizations needed to be updated: COWArrayOpt and ObjectOutliner.
@swift-ci test |
1 similar comment
@swift-ci test |
Build failed |
Some lldb tests are failing with that.
@swift-ci clean smoke test |
1 similar comment
@swift-ci clean smoke test |
Use the new builtins for COW representation in Array, ContiguousArray and ArraySlice.
The basic idea is to strictly separate code which mutates an array buffer from code which reads from an array.
The concept is explained in more detail in docs/SIL.rst, section "Copy-on-Write Representation".
The main change is to use beginCOWMutation() instead of isUniquelyReferenced() and insert endCOWMutation() at the end of all mutating functions. Also, reading from the array buffer must be done differently, depending on if the buffer is in a mutable or immutable state.
All the required invariants are enforced by runtime checks - but only in an assert-build of the library: a bit in the buffer flags indicates if the buffer is mutable or not.
Along with the library changes, also two optimizations needed to be updated: COWArrayOpt and ObjectOutliner.
Another notable change is the new library intrinsic to "finalize" array literals: for COW support in SIL it's required to "finalize" array literals.
_finalizeUninitializedArray
is a compiler known stdlib function which is called after all elements of an array literal are stored.This runtime function marks the array literal as finished.