@@ -5731,12 +5731,7 @@ pub const FuncGen = struct {
5731
5731
// The payload and the optional are the same value.
5732
5732
return operand ;
5733
5733
}
5734
- const index_type = self .context .intType (32 );
5735
- const indices : [2 ]* const llvm.Value = .{
5736
- index_type .constNull (), // dereference the pointer
5737
- index_type .constNull (), // first field is the payload
5738
- };
5739
- return self .builder .buildInBoundsGEP (operand , & indices , indices .len , "" );
5734
+ return self .builder .buildStructGEP (operand , 0 , "" );
5740
5735
}
5741
5736
5742
5737
fn airOptionalPayloadPtrSet (self : * FuncGen , inst : Air.Inst.Index ) ! ? * const llvm.Value {
@@ -5760,24 +5755,17 @@ pub const FuncGen = struct {
5760
5755
// Setting to non-null will be done when the payload is set.
5761
5756
return operand ;
5762
5757
}
5763
- const index_type = self .context .intType (32 );
5764
- {
5765
- // First set the non-null bit.
5766
- const indices : [2 ]* const llvm.Value = .{
5767
- index_type .constNull (), // dereference the pointer
5768
- index_type .constInt (1 , .False ), // second field is the non-null bit
5769
- };
5770
- const non_null_ptr = self .builder .buildInBoundsGEP (operand , & indices , indices .len , "" );
5771
- _ = self .builder .buildStore (non_null_bit , non_null_ptr );
5772
- }
5758
+
5759
+ // First set the non-null bit.
5760
+ const non_null_ptr = self .builder .buildStructGEP (operand , 1 , "" );
5761
+ // TODO set alignment on this store
5762
+ _ = self .builder .buildStore (non_null_bit , non_null_ptr );
5763
+
5773
5764
// Then return the payload pointer (only if it's used).
5774
5765
if (self .liveness .isUnused (inst ))
5775
5766
return null ;
5776
- const indices : [2 ]* const llvm.Value = .{
5777
- index_type .constNull (), // dereference the pointer
5778
- index_type .constNull (), // first field is the payload
5779
- };
5780
- return self .builder .buildInBoundsGEP (operand , & indices , indices .len , "" );
5767
+
5768
+ return self .builder .buildStructGEP (operand , 0 , "" );
5781
5769
}
5782
5770
5783
5771
fn airOptionalPayload (self : * FuncGen , inst : Air.Inst.Index ) ! ? * const llvm.Value {
@@ -5873,16 +5861,11 @@ pub const FuncGen = struct {
5873
5861
_ = self .builder .buildStore (non_error_val , operand );
5874
5862
return operand ;
5875
5863
}
5876
- const index_type = self .context .intType (32 );
5877
5864
const target = self .dg .module .getTarget ();
5878
5865
{
5879
5866
const error_offset = errUnionErrorOffset (payload_ty , target );
5880
5867
// First set the non-error value.
5881
- const indices : [2 ]* const llvm.Value = .{
5882
- index_type .constNull (), // dereference the pointer
5883
- index_type .constInt (error_offset , .False ),
5884
- };
5885
- const non_null_ptr = self .builder .buildInBoundsGEP (operand , & indices , indices .len , "" );
5868
+ const non_null_ptr = self .builder .buildStructGEP (operand , error_offset , "" );
5886
5869
const store_inst = self .builder .buildStore (non_error_val , non_null_ptr );
5887
5870
store_inst .setAlignment (Type .anyerror .abiAlignment (target ));
5888
5871
}
@@ -5891,11 +5874,7 @@ pub const FuncGen = struct {
5891
5874
return null ;
5892
5875
5893
5876
const payload_offset = errUnionPayloadOffset (payload_ty , target );
5894
- const indices : [2 ]* const llvm.Value = .{
5895
- index_type .constNull (), // dereference the pointer
5896
- index_type .constInt (payload_offset , .False ),
5897
- };
5898
- return self .builder .buildInBoundsGEP (operand , & indices , indices .len , "" );
5877
+ return self .builder .buildStructGEP (operand , payload_offset , "" );
5899
5878
}
5900
5879
5901
5880
fn airErrReturnTrace (self : * FuncGen , _ : Air.Inst.Index ) ! ? * const llvm.Value {
@@ -6390,8 +6369,30 @@ pub const FuncGen = struct {
6390
6369
const overflow_bit = self .builder .buildExtractValue (result_struct , 1 , "" );
6391
6370
6392
6371
var ty_buf : Type.Payload.Pointer = undefined ;
6393
- const partial = self .builder .buildInsertValue (llvm_dest_ty .getUndef (), result , llvmFieldIndex (dest_ty , 0 , tg , & ty_buf ).? , "" );
6394
- return self .builder .buildInsertValue (partial , overflow_bit , llvmFieldIndex (dest_ty , 1 , tg , & ty_buf ).? , "" );
6372
+ const result_index = llvmFieldIndex (dest_ty , 0 , tg , & ty_buf ).? ;
6373
+ const overflow_index = llvmFieldIndex (dest_ty , 1 , tg , & ty_buf ).? ;
6374
+
6375
+ if (isByRef (dest_ty )) {
6376
+ const target = self .dg .module .getTarget ();
6377
+ const alloca_inst = self .buildAlloca (llvm_dest_ty );
6378
+ const result_alignment = dest_ty .abiAlignment (target );
6379
+ alloca_inst .setAlignment (result_alignment );
6380
+ {
6381
+ const field_ptr = self .builder .buildStructGEP (alloca_inst , result_index , "" );
6382
+ const store_inst = self .builder .buildStore (result , field_ptr );
6383
+ store_inst .setAlignment (result_alignment );
6384
+ }
6385
+ {
6386
+ const field_ptr = self .builder .buildStructGEP (alloca_inst , overflow_index , "" );
6387
+ const store_inst = self .builder .buildStore (overflow_bit , field_ptr );
6388
+ store_inst .setAlignment (1 );
6389
+ }
6390
+
6391
+ return alloca_inst ;
6392
+ }
6393
+
6394
+ const partial = self .builder .buildInsertValue (llvm_dest_ty .getUndef (), result , result_index , "" );
6395
+ return self .builder .buildInsertValue (partial , overflow_bit , overflow_index , "" );
6395
6396
}
6396
6397
6397
6398
fn buildElementwiseCall (
@@ -6720,8 +6721,30 @@ pub const FuncGen = struct {
6720
6721
const overflow_bit = self .builder .buildICmp (.NE , lhs , reconstructed , "" );
6721
6722
6722
6723
var ty_buf : Type.Payload.Pointer = undefined ;
6723
- const partial = self .builder .buildInsertValue (llvm_dest_ty .getUndef (), result , llvmFieldIndex (dest_ty , 0 , tg , & ty_buf ).? , "" );
6724
- return self .builder .buildInsertValue (partial , overflow_bit , llvmFieldIndex (dest_ty , 1 , tg , & ty_buf ).? , "" );
6724
+ const result_index = llvmFieldIndex (dest_ty , 0 , tg , & ty_buf ).? ;
6725
+ const overflow_index = llvmFieldIndex (dest_ty , 1 , tg , & ty_buf ).? ;
6726
+
6727
+ if (isByRef (dest_ty )) {
6728
+ const target = self .dg .module .getTarget ();
6729
+ const alloca_inst = self .buildAlloca (llvm_dest_ty );
6730
+ const result_alignment = dest_ty .abiAlignment (target );
6731
+ alloca_inst .setAlignment (result_alignment );
6732
+ {
6733
+ const field_ptr = self .builder .buildStructGEP (alloca_inst , result_index , "" );
6734
+ const store_inst = self .builder .buildStore (result , field_ptr );
6735
+ store_inst .setAlignment (result_alignment );
6736
+ }
6737
+ {
6738
+ const field_ptr = self .builder .buildStructGEP (alloca_inst , overflow_index , "" );
6739
+ const store_inst = self .builder .buildStore (overflow_bit , field_ptr );
6740
+ store_inst .setAlignment (1 );
6741
+ }
6742
+
6743
+ return alloca_inst ;
6744
+ }
6745
+
6746
+ const partial = self .builder .buildInsertValue (llvm_dest_ty .getUndef (), result , result_index , "" );
6747
+ return self .builder .buildInsertValue (partial , overflow_bit , overflow_index , "" );
6725
6748
}
6726
6749
6727
6750
fn airAnd (self : * FuncGen , inst : Air.Inst.Index ) ! ? * const llvm.Value {
@@ -8332,14 +8355,7 @@ pub const FuncGen = struct {
8332
8355
/// Assumes the optional is not pointer-like and payload has bits.
8333
8356
fn optIsNonNull (self : * FuncGen , opt_handle : * const llvm.Value , is_by_ref : bool ) * const llvm.Value {
8334
8357
if (is_by_ref ) {
8335
- const index_type = self .context .intType (32 );
8336
-
8337
- const indices : [2 ]* const llvm.Value = .{
8338
- index_type .constNull (),
8339
- index_type .constInt (1 , .False ),
8340
- };
8341
-
8342
- const field_ptr = self .builder .buildInBoundsGEP (opt_handle , & indices , indices .len , "" );
8358
+ const field_ptr = self .builder .buildStructGEP (opt_handle , 1 , "" );
8343
8359
return self .builder .buildLoad (field_ptr , "" );
8344
8360
}
8345
8361
@@ -8357,12 +8373,7 @@ pub const FuncGen = struct {
8357
8373
8358
8374
if (isByRef (opt_ty )) {
8359
8375
// We have a pointer and we need to return a pointer to the first field.
8360
- const index_type = fg .context .intType (32 );
8361
- const indices : [2 ]* const llvm.Value = .{
8362
- index_type .constNull (), // dereference the pointer
8363
- index_type .constNull (), // first field is the payload
8364
- };
8365
- const payload_ptr = fg .builder .buildInBoundsGEP (opt_handle , & indices , indices .len , "" );
8376
+ const payload_ptr = fg .builder .buildStructGEP (opt_handle , 0 , "" );
8366
8377
8367
8378
if (isByRef (payload_ty )) {
8368
8379
return payload_ptr ;
@@ -8392,22 +8403,13 @@ pub const FuncGen = struct {
8392
8403
const payload_alignment = optional_ty .abiAlignment (target );
8393
8404
alloca_inst .setAlignment (payload_alignment );
8394
8405
8395
- const index_type = self .context .intType (32 );
8396
8406
{
8397
- const indices : [2 ]* const llvm.Value = .{
8398
- index_type .constNull (), // dereference the pointer
8399
- index_type .constNull (), // first field is the payload
8400
- };
8401
- const field_ptr = self .builder .buildInBoundsGEP (alloca_inst , & indices , indices .len , "" );
8407
+ const field_ptr = self .builder .buildStructGEP (alloca_inst , 0 , "" );
8402
8408
const store_inst = self .builder .buildStore (payload , field_ptr );
8403
8409
store_inst .setAlignment (payload_alignment );
8404
8410
}
8405
8411
{
8406
- const indices : [2 ]* const llvm.Value = .{
8407
- index_type .constNull (), // dereference the pointer
8408
- index_type .constInt (1 , .False ), // second field is the non-null bit
8409
- };
8410
- const field_ptr = self .builder .buildInBoundsGEP (alloca_inst , & indices , indices .len , "" );
8412
+ const field_ptr = self .builder .buildStructGEP (alloca_inst , 1 , "" );
8411
8413
const store_inst = self .builder .buildStore (non_null_bit , field_ptr );
8412
8414
store_inst .setAlignment (1 );
8413
8415
}
@@ -9328,7 +9330,7 @@ fn ccAbiPromoteInt(
9328
9330
fn isByRef (ty : Type ) bool {
9329
9331
// For tuples and structs, if there are more than this many non-void
9330
9332
// fields, then we make it byref, otherwise byval.
9331
- const max_fields_byval = 2 ;
9333
+ const max_fields_byval = 0 ;
9332
9334
9333
9335
switch (ty .zigTypeTag ()) {
9334
9336
.Type ,
0 commit comments