Skip to content

Commit 9ac1dc8

Browse files
authored
Merge pull request #14232 from xedin/rdar-36560486
[IRGen] Reorder generic struct metadata so that field offsets follow …
2 parents 04630a3 + 6d3c298 commit 9ac1dc8

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

lib/IRGen/StructMetadataVisitor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ template <class Impl> class StructMetadataVisitor
5050

5151
// If changing this layout, you must update the magic number in
5252
// emitParentMetadataRef.
53-
53+
54+
// Instantiation-specific.
55+
asImpl().addGenericFields(Target, Target->getDeclaredTypeInContext());
56+
5457
// Struct field offsets.
5558
asImpl().noteStartOfFieldOffsets();
5659
for (VarDecl *prop : Target->getStoredProperties())
5760
asImpl().addFieldOffset(prop);
58-
59-
// Instantiation-specific.
60-
asImpl().addGenericFields(Target, Target->getDeclaredTypeInContext());
6161
}
6262

6363
// Note the start of the field offset vector.

test/IRGen/field_type_vectors.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Foo {
1515
// CHECK-LABEL: @"$S18field_type_vectors3BarVMP" = internal global
1616
// -- There should be 1 word between the field type vector slot, with type %swift.type**,
1717
// and the address point
18-
// CHECK: %swift.type**, i8**, i64, <{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32 }>*, i64, %swift.type*
18+
// CHECK: %swift.type**, i8**, i64, <{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32 }>*, %swift.type*, i64
1919
struct Bar<T> {
2020
var y: Int
2121
}
@@ -25,7 +25,7 @@ struct Bar<T> {
2525
// CHECK-LABEL: @"$S18field_type_vectors3BasVMP" = internal global
2626
// -- There should be 1 word between the field type vector slot, with type %swift.type**,
2727
// and the address point
28-
// CHECK: %swift.type**, i8**, i64, <{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32 }>*, i64, i64, %swift.type*, %swift.type*
28+
// CHECK: %swift.type**, i8**, i64, <{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32 }>*, %swift.type*, %swift.type*, i64, i64
2929
struct Bas<T, U> {
3030
var foo: Foo
3131
var bar: Bar<T>

test/IRGen/generic_structs.sil

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ import Builtin
2525
// -- field count
2626
// CHECK-SAME: i32 1,
2727
// -- field offset vector offset
28-
// CHECK-SAME: i32 2,
28+
// CHECK-SAME: i32 3,
2929
// -- field names
3030
// CHECK-SAME: [3 x i8]* [[SINGLEDYNAMIC_FIELDS]]
3131
// -- kind 1 (struct)
3232
// CHECK-SAME: i32 1
3333
// -- generic parameter vector offset
34-
// CHECK-SAME: i32 3,
34+
// CHECK-SAME: i32 2,
3535
// -- generic parameter count, primary count
3636
// CHECK-SAME: i32 1, i32 1
3737
// -- nesting depth
@@ -50,7 +50,7 @@ import Builtin
5050
// -- address point
5151
// CHECK-SAME: i64 1, {{.*}}* @"$S15generic_structs13SingleDynamicVMn"
5252
// -- field offset vector; generic parameter vector
53-
// CHECK-SAME: i64 0, %swift.type* null }>
53+
// CHECK-SAME: %swift.type* null, i64 0 }>
5454

5555
// -- Nominal type descriptor for generic struct with protocol requirements
5656
// FIXME: Strings should be unnamed_addr. rdar://problem/22674524
@@ -62,13 +62,13 @@ import Builtin
6262
// -- field count
6363
// CHECK-SAME: i32 2,
6464
// -- field offset vector offset
65-
// CHECK-SAME: i32 2,
65+
// CHECK-SAME: i32 6,
6666
// -- field names
6767
// CHECK-SAME: [5 x i8]* [[DYNAMICWITHREQUIREMENTS_FIELDS]]
6868
// -- kind 1 (struct)
6969
// CHECK-SAME: i32 1,
7070
// -- generic parameter vector offset
71-
// CHECK-SAME: i32 4,
71+
// CHECK-SAME: i32 2,
7272
// -- generic requirements count; generic arguments count
7373
// CHECK-SAME: i32 4, i32 2
7474
// -- nesting depth
@@ -81,7 +81,7 @@ import Builtin
8181

8282
// CHECK: @"$S15generic_structs23DynamicWithRequirementsVMP" = internal global <{ {{.*}} }> <{
8383
// -- field offset vector; generic parameter vector
84-
// CHECK: i64 0, i64 0, %swift.type* null, %swift.type* null, i8** null, i8** null }>
84+
// CHECK: %swift.type* null, %swift.type* null, i8** null, i8** null, i64 0, i64 0 }>
8585

8686
// -- Fixed-layout struct metadata contains fixed field offsets
8787
// CHECK: @"$S15generic_structs6IntishVMf" = internal constant <{ {{.*}} i64 }> <{
@@ -144,7 +144,7 @@ entry(%0 : $*ComplexDynamic<A, B>, %1 : $*Byteful, %2 : $*A, %3 : $*B, %4 : $*Ch
144144
%a = struct_element_addr %0 : $*ComplexDynamic<A, B>, #ComplexDynamic.a2
145145

146146
// CHECK: [[METADATA:%.*]] = bitcast %swift.type* {{%.*}} to i64*
147-
// CHECK: [[FIELD_OFFSET_VECTOR:%.*]] = getelementptr inbounds i64, i64* [[METADATA]], i64 2
147+
// CHECK: [[FIELD_OFFSET_VECTOR:%.*]] = getelementptr inbounds i64, i64* [[METADATA]], i64 4
148148
// CHECK: [[FIELD_OFFSET_ADDR:%.*]] = getelementptr inbounds i64, i64* [[FIELD_OFFSET_VECTOR]], i32 2
149149
// CHECK: [[FIELD_OFFSET:%.*]] = load i64, i64* [[FIELD_OFFSET_ADDR]], align 8
150150
// CHECK: [[BYTES:%.*]] = bitcast %T15generic_structs14ComplexDynamicV* %0 to i8*
@@ -153,7 +153,7 @@ entry(%0 : $*ComplexDynamic<A, B>, %1 : $*Byteful, %2 : $*A, %3 : $*B, %4 : $*Ch
153153
%b = struct_element_addr %0 : $*ComplexDynamic<A, B>, #ComplexDynamic.b
154154

155155
// CHECK: [[METADATA:%.*]] = bitcast %swift.type* {{%.*}} to i64*
156-
// CHECK: [[FIELD_OFFSET_VECTOR:%.*]] = getelementptr inbounds i64, i64* [[METADATA]], i64 2
156+
// CHECK: [[FIELD_OFFSET_VECTOR:%.*]] = getelementptr inbounds i64, i64* [[METADATA]], i64 4
157157
// CHECK: [[FIELD_OFFSET_ADDR:%.*]] = getelementptr inbounds i64, i64* [[FIELD_OFFSET_VECTOR]], i32 3
158158
// CHECK: [[FIELD_OFFSET:%.*]] = load i64, i64* [[FIELD_OFFSET_ADDR]], align 8
159159
// CHECK: [[BYTES:%.*]] = bitcast %T15generic_structs14ComplexDynamicV* %0 to i8*
@@ -163,7 +163,7 @@ entry(%0 : $*ComplexDynamic<A, B>, %1 : $*Byteful, %2 : $*A, %3 : $*B, %4 : $*Ch
163163
%c = struct_element_addr %5 : $*SingleDynamic<B>, #SingleDynamic.x
164164

165165
// CHECK: [[METADATA:%.*]] = bitcast %swift.type* {{%.*}} to i64*
166-
// CHECK: [[FIELD_OFFSET_VECTOR:%.*]] = getelementptr inbounds i64, i64* [[METADATA]], i64 2
166+
// CHECK: [[FIELD_OFFSET_VECTOR:%.*]] = getelementptr inbounds i64, i64* [[METADATA]], i64 4
167167
// CHECK: [[FIELD_OFFSET_ADDR:%.*]] = getelementptr inbounds i64, i64* [[FIELD_OFFSET_VECTOR]], i32 4
168168
// CHECK: [[FIELD_OFFSET:%.*]] = load i64, i64* [[FIELD_OFFSET_ADDR]], align 8
169169
// CHECK: [[BYTES:%.*]] = bitcast %T15generic_structs14ComplexDynamicV* %0 to i8*
@@ -214,12 +214,12 @@ entry(%0 : $*ComplexDynamic<A, B>, %1 : $*Byteful, %2 : $*A, %3 : $*B, %4 : $*Ch
214214
// CHECK: [[METADATA:%.*]] = call %swift.type* @swift_allocateGenericValueMetadata(%swift.type_pattern* %0, i8** %1)
215215
// CHECK: [[SELF_ARRAY:%.*]] = bitcast %swift.type* [[METADATA]] to i8**
216216
// Fill type argument.
217-
// CHECK: [[T1:%.*]] = getelementptr inbounds i8*, i8** [[SELF_ARRAY]], i64 3
217+
// CHECK: [[T1:%.*]] = getelementptr inbounds i8*, i8** [[SELF_ARRAY]], i64 2
218218
// CHECK: [[T0:%.*]] = bitcast %swift.type* %T to i8*
219219
// CHECK: store i8* [[T0]], i8** [[T1]], align 8
220220
// Lay out fields.
221221
// CHECK: [[T0:%.*]] = bitcast %swift.type* [[METADATA]] to i64*
222-
// CHECK: [[T1:%.*]] = getelementptr inbounds i64, i64* [[T0]], i64 2
222+
// CHECK: [[T1:%.*]] = getelementptr inbounds i64, i64* [[T0]], i64 3
223223
// CHECK: [[T2:%.*]] = getelementptr inbounds i8**, i8*** [[TYPES:%.*]], i32 0
224224
// CHECK: call void @swift_initStructMetadata(%swift.type* [[METADATA]], i64 0, i64 1, i8*** [[TYPES]], i64* [[T1]])
225225
// CHECK: ret %swift.type* [[METADATA]]

test/IRGen/generic_structs.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public struct GenericStruct<T : Proto> {
4141
// CHECK-32-LABEL: define{{.*}} swiftcc void @"$S15generic_structs13GenericStructVACyxGycfC"
4242
// CHECK-32: [[TYPE:%.*]] = call %swift.type* @"$S15generic_structs13GenericStructVMa"(%swift.type* %T, i8** %T.Proto)
4343
// CHECK-32: [[PTR:%.*]] = bitcast %swift.type* [[TYPE]] to i32*
44-
// CHECK-32: [[FIELDOFFSETS:%.*]] = getelementptr inbounds i32, i32* [[PTR]], i32 2
44+
// CHECK-32: [[FIELDOFFSETS:%.*]] = getelementptr inbounds i32, i32* [[PTR]], i32 4
4545
// CHECK-32: [[FIELDOFFSET:%.*]] = getelementptr inbounds i32, i32* [[FIELDOFFSETS]], i32 2
4646
// CHECK-32: [[OFFSET:%.*]] = load i32, i32* [[FIELDOFFSET]]
4747
// CHECK-32: [[ADDROFOPT:%.*]] = getelementptr inbounds i8, i8* {{.*}}, i32 [[OFFSET]]
@@ -51,7 +51,7 @@ public struct GenericStruct<T : Proto> {
5151
// CHECK-64-LABEL: define{{.*}} swiftcc void @"$S15generic_structs13GenericStructVACyxGycfC"
5252
// CHECK-64: [[TYPE:%.*]] = call %swift.type* @"$S15generic_structs13GenericStructVMa"(%swift.type* %T, i8** %T.Proto)
5353
// CHECK-64: [[PTR:%.*]] = bitcast %swift.type* [[TYPE]] to i64*
54-
// CHECK-64: [[FIELDOFFSETS:%.*]] = getelementptr inbounds i64, i64* [[PTR]], i64 2
54+
// CHECK-64: [[FIELDOFFSETS:%.*]] = getelementptr inbounds i64, i64* [[PTR]], i64 4
5555
// CHECK-64: [[FIELDOFFSET:%.*]] = getelementptr inbounds i64, i64* [[FIELDOFFSETS]], i32 2
5656
// CHECK-64: [[OFFSET:%.*]] = load i64, i64* [[FIELDOFFSET]]
5757
// CHECK-64: [[ADDROFOPT:%.*]] = getelementptr inbounds i8, i8* {{.*}}, i64 [[OFFSET]]

test/IRGen/keypaths.sil

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ sil_vtable C {}
200200
// CHECK-64-SAME: [4 x i8] zeroinitializer,
201201
// -- struct with runtime-resolved offset
202202
// CHECK-SAME: <i32 0x1ffffffe>,
203-
// CHECK-32-SAME: i32 8 }>
204-
// CHECK-64-SAME: i32 16 }>
203+
// CHECK-32-SAME: i32 16 }>
204+
// CHECK-64-SAME: i32 32 }>
205205

206206
// -- %j: Gen<A>.y
207207
// CHECK: [[KP_J:@keypath.*]] = private global <{ {{.*}} }> <{
@@ -213,8 +213,8 @@ sil_vtable C {}
213213
// CHECK-64-SAME: [4 x i8] zeroinitializer,
214214
// -- struct with runtime-resolved offset
215215
// CHECK-SAME: <i32 0x1ffffffe>,
216-
// CHECK-32-SAME: i32 12 }>
217-
// CHECK-64-SAME: i32 24 }>
216+
// CHECK-32-SAME: i32 20 }>
217+
// CHECK-64-SAME: i32 40 }>
218218

219219
// CHECK-LABEL: define{{( protected)?}} swiftcc void @stored_property_fixed_offsets()
220220
sil @stored_property_fixed_offsets : $@convention(thin) () -> () {

0 commit comments

Comments
 (0)