@@ -3643,13 +3643,10 @@ void IRGenFunction::setDereferenceableLoad(llvm::LoadInst *load,
3643
3643
}
3644
3644
3645
3645
// / Emit a load from the given metadata at a constant index.
3646
- // /
3647
- // / The load is marked invariant. This function should not be called
3648
- // / on metadata objects that are in the process of being initialized.
3649
- static llvm::LoadInst *emitInvariantLoadFromMetadataAtIndex (IRGenFunction &IGF,
3650
- llvm::Value *metadata,
3651
- int index,
3652
- llvm::PointerType *objectTy,
3646
+ static llvm::LoadInst *emitLoadFromMetadataAtIndex (IRGenFunction &IGF,
3647
+ llvm::Value *metadata,
3648
+ int index,
3649
+ llvm::Type *objectTy,
3653
3650
const llvm::Twine &suffix = " " ){
3654
3651
// Require the metadata to be some type that we recognize as a
3655
3652
// metadata pointer.
@@ -3658,6 +3655,8 @@ static llvm::LoadInst *emitInvariantLoadFromMetadataAtIndex(IRGenFunction &IGF,
3658
3655
// We require objectType to be a pointer type so that the GEP will
3659
3656
// scale by the right amount. We could load an arbitrary type using
3660
3657
// some extra bitcasting.
3658
+ assert (IGF.IGM .DataLayout .getTypeStoreSize (objectTy) ==
3659
+ IGF.IGM .DataLayout .getTypeStoreSize (IGF.IGM .SizeTy ));
3661
3660
3662
3661
// Cast to T*.
3663
3662
auto objectPtrTy = objectTy->getPointerTo ();
@@ -3670,8 +3669,21 @@ static llvm::LoadInst *emitInvariantLoadFromMetadataAtIndex(IRGenFunction &IGF,
3670
3669
IGF.IGM .getPointerAlignment ());
3671
3670
3672
3671
// Load.
3673
- auto result = IGF.Builder .CreateLoad (slot,
3674
- metadata->getName () + suffix);
3672
+ return IGF.Builder .CreateLoad (slot, metadata->getName () + suffix);
3673
+ }
3674
+
3675
+ // / Emit a load from the given metadata at a constant index.
3676
+ // /
3677
+ // / The load is marked invariant. This function should not be called
3678
+ // / on metadata objects that are in the process of being initialized.
3679
+ static llvm::LoadInst *emitInvariantLoadFromMetadataAtIndex (IRGenFunction &IGF,
3680
+ llvm::Value *metadata,
3681
+ int index,
3682
+ llvm::Type *objectTy,
3683
+ const llvm::Twine &suffix = " " ){
3684
+
3685
+ auto result = emitLoadFromMetadataAtIndex (IGF, metadata, index, objectTy,
3686
+ suffix);
3675
3687
IGF.setInvariantLoad (result);
3676
3688
return result;
3677
3689
}
@@ -3696,8 +3708,8 @@ IRGenFunction::emitValueWitnessTableRef(CanType type) {
3696
3708
llvm::Value *
3697
3709
IRGenFunction::emitValueWitnessTableRefForMetadata (llvm::Value *metadata) {
3698
3710
auto witness = emitInvariantLoadFromMetadataAtIndex (*this , metadata, -1 ,
3699
- IGM.WitnessTablePtrTy ,
3700
- " .valueWitnesses" );
3711
+ IGM.WitnessTablePtrTy ,
3712
+ " .valueWitnesses" );
3701
3713
// A value witness table is dereferenceable to the number of value witness
3702
3714
// pointers.
3703
3715
@@ -3733,15 +3745,15 @@ static llvm::Value *emitLoadOfMetadataRefAtIndex(IRGenFunction &IGF,
3733
3745
llvm::Value *metadata,
3734
3746
int index) {
3735
3747
return emitInvariantLoadFromMetadataAtIndex (IGF, metadata, index,
3736
- IGF.IGM .TypeMetadataPtrTy );
3748
+ IGF.IGM .TypeMetadataPtrTy );
3737
3749
}
3738
3750
3739
3751
// / Load the protocol witness table reference at the given index.
3740
3752
static llvm::Value *emitLoadOfWitnessTableRefAtIndex (IRGenFunction &IGF,
3741
3753
llvm::Value *metadata,
3742
3754
int index) {
3743
3755
return emitInvariantLoadFromMetadataAtIndex (IGF, metadata, index,
3744
- IGF.IGM .WitnessTablePtrTy );
3756
+ IGF.IGM .WitnessTablePtrTy );
3745
3757
}
3746
3758
3747
3759
namespace {
@@ -3935,8 +3947,8 @@ llvm::Value *irgen::emitClassFieldOffset(IRGenFunction &IGF,
3935
3947
llvm::Value *metadata) {
3936
3948
irgen::Size offset = getClassFieldOffset (IGF.IGM , theClass, field);
3937
3949
int index = getOffsetInWords (IGF.IGM , offset);
3938
- llvm::Value *val = emitLoadOfWitnessTableRefAtIndex (IGF, metadata, index);
3939
- return IGF. Builder . CreatePtrToInt (val, IGF.IGM .SizeTy );
3950
+ return emitInvariantLoadFromMetadataAtIndex (IGF, metadata, index,
3951
+ IGF.IGM .SizeTy );
3940
3952
}
3941
3953
3942
3954
// / Given a reference to class metadata of the given type,
@@ -4200,7 +4212,8 @@ llvm::Value *irgen::emitClassHeapMetadataRefForMetatype(IRGenFunction &IGF,
4200
4212
// a select here instead, which might be profitable.
4201
4213
IGF.Builder .emitBlock (wrapBB);
4202
4214
auto classFromWrapper =
4203
- emitInvariantLoadFromMetadataAtIndex (IGF, metatype, 1 , IGF.IGM .TypeMetadataPtrTy );
4215
+ emitInvariantLoadFromMetadataAtIndex (IGF, metatype, 1 ,
4216
+ IGF.IGM .TypeMetadataPtrTy );
4204
4217
IGF.Builder .CreateBr (contBB);
4205
4218
4206
4219
// Continuation block.
0 commit comments