1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/../Inputs/resilient_struct.swift -enable-library-evolution -emit-module -emit-module-path %t/resilient_struct.swiftmodule
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -enable-library-evolution -I %t -emit-ir %s | %FileCheck %s
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -enable-library-evolution -I %t -emit-ir -O %s
// CHECK: %swift.type = type { [[INT:i32|i64]] }
sil_stage canonical
import Builtin
import Swift
import SwiftShims
import resilient_struct
//
// Fits inside a buffer's inline storage.
//
public struct SmallResilientStruct {
let x: Int32 = 0
}
// CHECK: @smallGlobal = {{(dllexport )?}}{{(protected )?}}global [[BUFFER:\[(12|24) x i8\]]] zeroinitializer{{.*}}align {{(8|4)}}
sil_global [let] @smallGlobal : $SmallResilientStruct
//
// Requires out-of-line allocation.
//
public struct LargeResilientStruct {
let w: Int64 = 0
let x: Int64 = 0
let y: Int64 = 0
let z: Int64 = 0
}
// CHECK: @largeGlobal = {{(dllexport )?}}{{(protected )?}}global [[BUFFER]] zeroinitializer
sil_global [let] @largeGlobal : $LargeResilientStruct
//
// Size is known in this resilience domain, and global is hidden,
// so allocate it directly.
//
// CHECK: @fixedGlobal = hidden global %T17global_resilience20LargeResilientStructV zeroinitializer
sil_global hidden @fixedGlobal : $LargeResilientStruct
//
// Unknown size -- must call value witness functions for buffer
// management.
//
// CHECK: @otherGlobal = {{(dllexport )?}}{{(protected )?}}global [[BUFFER]] zeroinitializer
sil_global [let] @otherGlobal : $Size
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc i32 @testSmallGlobal()
sil @testSmallGlobal : $@convention(thin) () -> Int32 {
bb0:
// This is just a no-op
alloc_global @smallGlobal
%addr = global_addr @smallGlobal : $*SmallResilientStruct
// CHECK: [[VALUE:%.*]] = load i32, ptr @smallGlobal
%x_addr = struct_element_addr %addr : $*SmallResilientStruct, #SmallResilientStruct.x
%x = load %x_addr : $*Int32
// CHECK: ret i32 [[VALUE]]
return %x : $Int32
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @testLargeGlobal()
sil @testLargeGlobal : $@convention(thin) () -> () {
bb0:
// CHECK: [[ALLOC:%.*]] = call noalias ptr @swift_slowAlloc([[INT]] 32, [[INT]] 7)
// CHECK: store ptr [[ALLOC]], ptr @largeGlobal, align {{(8|4)}}
alloc_global @largeGlobal
// CHECK: [[VALUE:%.*]] = load ptr, ptr @largeGlobal
%addr = global_addr @largeGlobal : $*LargeResilientStruct
%tuple = tuple ()
// CHECK: ret void
return %tuple : $()
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc i64 @testFixedGlobal()
sil @testFixedGlobal : $@convention(thin) () -> Int64 {
bb0:
alloc_global @fixedGlobal
%addr = global_addr @fixedGlobal : $*LargeResilientStruct
// CHECK: [[VALUE:%.*]] = load i64, ptr getelementptr inbounds (%T17global_resilience20LargeResilientStructV, ptr @fixedGlobal, i32 0, i32 1)
%x_addr = struct_element_addr %addr : $*LargeResilientStruct, #LargeResilientStruct.x
%x = load %x_addr : $*Int64
// CHECK: ret i64 [[VALUE]]
return %x : $Int64
}
// CHECK-LABEL: define {{.*}} @testOtherGlobal
sil @testOtherGlobal : $@convention(thin) () -> () {
bb0:
// CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s16resilient_struct4SizeVMa"([[INT]] 0)
// CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[T0]], 0
// CHECK: call ptr @__swift_allocate_value_buffer(ptr [[METADATA]], ptr @otherGlobal)
alloc_global @otherGlobal
// CHECK: call ptr @__swift_project_value_buffer(ptr [[METADATA]], ptr @otherGlobal)
%addr = global_addr @otherGlobal : $*Size
%tuple = tuple ()
// CHECK: ret void
return %tuple : $()
}
// CHECK-LABEL: define linkonce_odr hidden ptr @__swift_allocate_value_buffer(ptr %0, ptr %1)
// CHECK: entry:
// CHECK: [[VWT_ADDR:%.*]] = getelementptr inbounds ptr, ptr %0, {{.*}} -1
// CHECK: [[VWT:%.*]] = load ptr, ptr [[VWT_ADDR]]
// CHECK: [[FLAGS_ADDR:%.*]] = getelementptr inbounds %swift.vwtable, ptr [[VWT]], i32 0, i32 10
// CHECK: [[FLAGS:%.*]] = load i32, ptr [[FLAGS_ADDR]]
// CHECK: [[ISNOTINLINE:%.*]] = and i32 [[FLAGS]], 131072
// CHECK: [[ISINLINE:%.*]] = icmp eq i32 [[ISNOTINLINE]], 0
// CHECK: br i1 [[ISINLINE]], label %done, label %outline.allocateValueInBuffer
//
// CHECK: outline.allocateValueInBuffer:
// CHECK: [[VWT_ADDR:%.*]] = getelementptr inbounds ptr, ptr %0, {{.*}} -1
// CHECK: [[VWT:%.*]] = load ptr, ptr [[VWT_ADDR]]
// CHECK: [[SIZE_ADDR:%.*]] = getelementptr inbounds %swift.vwtable, ptr [[VWT]], i32 0, i32 8
// CHECK: [[SIZE:%.*]] = load [[INT]], ptr [[SIZE_ADDR]]
// CHECK: [[ALIGN:%.*]] = and {{.*}}, 255
// CHECK: [[PTR:%.*]] = call noalias ptr @swift_slowAlloc({{.*}} [[SIZE]], {{.*}} [[ALIGN]])
// CHECK: store ptr [[PTR]], ptr %1
// CHECK: br label %done
//
// CHECK: done:
// CHECK: [[PHI:%.*]] = phi ptr [ %1, %entry ], [ [[PTR]], %outline.allocateValueInBuffer ]
// CHECK: ret ptr [[PHI]]
// CHECK-LABEL: define linkonce_odr hidden ptr @__swift_project_value_buffer(ptr %0, ptr %1)
// CHECK: [[VWT_ADDR:%.*]] = getelementptr inbounds ptr, ptr %0, {{.*}} -1
// CHECK: [[VWT:%.*]] = load ptr, ptr [[VWT_ADDR]]
// CHECK: [[FLAGS_ADDR:%.*]] = getelementptr inbounds %swift.vwtable, ptr [[VWT]], i32 0, i32 10
// CHECK: [[FLAGS:%.*]] = load i32, ptr [[FLAGS_ADDR]]
// CHECK: [[ISNOTINLINE:%.*]] = and i32 [[FLAGS]], 131072
// CHECK: [[ISINLINE:%.*]] = icmp eq i32 [[ISNOTINLINE]], 0
// CHECK: br i1 [[ISINLINE]], label %done, label %outline.projectValueInBuffer
//
// CHECK: outline.projectValueInBuffer:
// CHECK: [[PTR_TO_BUFFER:%.*]] = load ptr, ptr %1
// CHECK: br label %done
//
// CHECK: done:
// CHECK: [[PHI:%.*]] = phi ptr [ %1, %entry ], [ [[PTR_TO_BUFFER]], %outline.projectValueInBuffer ]
// CHECK: ret ptr [[PHI]]
|