@@ -3643,13 +3643,10 @@ void IRGenFunction::setDereferenceableLoad(llvm::LoadInst *load,
36433643}
36443644
36453645// / 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,
36533650 const llvm::Twine &suffix = " " ){
36543651 // Require the metadata to be some type that we recognize as a
36553652 // metadata pointer.
@@ -3658,6 +3655,8 @@ static llvm::LoadInst *emitInvariantLoadFromMetadataAtIndex(IRGenFunction &IGF,
36583655 // We require objectType to be a pointer type so that the GEP will
36593656 // scale by the right amount. We could load an arbitrary type using
36603657 // some extra bitcasting.
3658+ assert (IGF.IGM .DataLayout .getTypeStoreSize (objectTy) ==
3659+ IGF.IGM .DataLayout .getTypeStoreSize (IGF.IGM .SizeTy ));
36613660
36623661 // Cast to T*.
36633662 auto objectPtrTy = objectTy->getPointerTo ();
@@ -3670,8 +3669,21 @@ static llvm::LoadInst *emitInvariantLoadFromMetadataAtIndex(IRGenFunction &IGF,
36703669 IGF.IGM .getPointerAlignment ());
36713670
36723671 // 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);
36753687 IGF.setInvariantLoad (result);
36763688 return result;
36773689}
@@ -3696,8 +3708,8 @@ IRGenFunction::emitValueWitnessTableRef(CanType type) {
36963708llvm::Value *
36973709IRGenFunction::emitValueWitnessTableRefForMetadata (llvm::Value *metadata) {
36983710 auto witness = emitInvariantLoadFromMetadataAtIndex (*this , metadata, -1 ,
3699- IGM.WitnessTablePtrTy ,
3700- " .valueWitnesses" );
3711+ IGM.WitnessTablePtrTy ,
3712+ " .valueWitnesses" );
37013713 // A value witness table is dereferenceable to the number of value witness
37023714 // pointers.
37033715
@@ -3733,15 +3745,15 @@ static llvm::Value *emitLoadOfMetadataRefAtIndex(IRGenFunction &IGF,
37333745 llvm::Value *metadata,
37343746 int index) {
37353747 return emitInvariantLoadFromMetadataAtIndex (IGF, metadata, index,
3736- IGF.IGM .TypeMetadataPtrTy );
3748+ IGF.IGM .TypeMetadataPtrTy );
37373749}
37383750
37393751// / Load the protocol witness table reference at the given index.
37403752static llvm::Value *emitLoadOfWitnessTableRefAtIndex (IRGenFunction &IGF,
37413753 llvm::Value *metadata,
37423754 int index) {
37433755 return emitInvariantLoadFromMetadataAtIndex (IGF, metadata, index,
3744- IGF.IGM .WitnessTablePtrTy );
3756+ IGF.IGM .WitnessTablePtrTy );
37453757}
37463758
37473759namespace {
@@ -3935,8 +3947,8 @@ llvm::Value *irgen::emitClassFieldOffset(IRGenFunction &IGF,
39353947 llvm::Value *metadata) {
39363948 irgen::Size offset = getClassFieldOffset (IGF.IGM , theClass, field);
39373949 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 );
39403952}
39413953
39423954// / Given a reference to class metadata of the given type,
@@ -4200,7 +4212,8 @@ llvm::Value *irgen::emitClassHeapMetadataRefForMetatype(IRGenFunction &IGF,
42004212 // a select here instead, which might be profitable.
42014213 IGF.Builder .emitBlock (wrapBB);
42024214 auto classFromWrapper =
4203- emitInvariantLoadFromMetadataAtIndex (IGF, metatype, 1 , IGF.IGM .TypeMetadataPtrTy );
4215+ emitInvariantLoadFromMetadataAtIndex (IGF, metatype, 1 ,
4216+ IGF.IGM .TypeMetadataPtrTy );
42044217 IGF.Builder .CreateBr (contBB);
42054218
42064219 // Continuation block.
0 commit comments