Files
swift-mirror/test/SILOptimizer/globalopt-iter.sil
Erik Eckstein 71a642e51b stdlib, SIL optimizer: use the SIL copy-on-write representation in the 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.
2020-06-08 15:02:22 +02:00

28 lines
691 B
Plaintext

// RUN: %target-sil-opt -enable-sil-verify-all %s -object-outliner | %FileCheck %s
import Builtin
import Swift
class B { }
class E : B { }
// CHECK: sil @patatino : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK-NEXT: integer_literal
// CHECK-NEXT: global_value @patatinoTv_ : $B
// CHECK-NEXT: strong_retain
// CHECK-NEXT: strong_release
// CHECK-NEXT: tuple ()
// CHECK-NEXT: return
// CHECK-NEXT: }
sil @patatino : $@convention(thin) () -> () {
%0 = integer_literal $Builtin.Word, 0
%1 = alloc_ref [tail_elems $Int64 * %0 : $Builtin.Word] $B
%2 = end_cow_mutation %1 : $B
set_deallocating %2 : $B
dealloc_ref %2 : $B
%45 = tuple ()
return %45 : $()
}