mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Static initializers are now represented by a list of literal and aggregate instructions in a SILGlobalVariable. For details see SIL.rst. This representation is cleaner than what we did so far (point to the initializer function and do some pattern matching). One implication of that change is that now (a subset of) instructions not necessarily have a parent function. Regarding the generated code it's a NFC. Also the swift module format didn't change because so far we don't serializer global variables.
38 lines
1.2 KiB
Plaintext
38 lines
1.2 KiB
Plaintext
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil %s | %FileCheck %s
|
|
|
|
// Generated from
|
|
// var x : Int32 = 2
|
|
// public func f() -> Int32 { return x }
|
|
// with swiftc -O -parse-as-library -emit-sil
|
|
|
|
import Builtin
|
|
import Swift
|
|
|
|
// CHECK: sil_global private @globalinit_token0 : $Builtin.Word
|
|
sil_global private @globalinit_token0 : $Builtin.Word
|
|
|
|
// CHECK: sil_global @_Tv2ch1xSi : $Int32 = {
|
|
// CHECK-NEXT: %0 = integer_literal $Builtin.Int32, 2
|
|
// CHECK-NEXT: %initval = struct $Int32 (%0 : $Builtin.Int32)
|
|
// CHECK-NEXT: }
|
|
sil_global @_Tv2ch1xSi : $Int32 = {
|
|
%0 = integer_literal $Builtin.Int32, 2
|
|
%initval = struct $Int32 (%0 : $Builtin.Int32)
|
|
}
|
|
|
|
// CHECK-LABEL: sil [global_init] @_TF2cha1xSi : $@convention(thin) () -> Builtin.RawPointer {
|
|
sil [global_init] @_TF2cha1xSi : $@convention(thin) () -> Builtin.RawPointer {
|
|
bb0:
|
|
%0 = global_addr @_Tv2ch1xSi : $*Int32
|
|
%1 = address_to_pointer %0 : $*Int32 to $Builtin.RawPointer
|
|
return %1 : $Builtin.RawPointer
|
|
}
|
|
|
|
// CHECK-LABEL: sil @_TF2ch1fFT_Si : $@convention(thin) () -> Int32 {
|
|
sil @_TF2ch1fFT_Si : $@convention(thin) () -> Int32 {
|
|
bb0:
|
|
%0 = global_addr @_Tv2ch1xSi : $*Int32
|
|
%1 = load %0 : $*Int32
|
|
return %1 : $Int32
|
|
}
|