30
30
#include " llvm/IR/Module.h"
31
31
32
32
#include " swift/AST/ExistentialLayout.h"
33
+ #include " swift/AST/IRGenOptions.h"
33
34
#include " swift/SIL/DynamicCasts.h"
34
35
#include " swift/SIL/SILInstruction.h"
35
36
#include " swift/SIL/SILModule.h"
@@ -1061,8 +1062,8 @@ llvm::Value *irgen::emitFastClassCastIfPossible(IRGenFunction &IGF,
1061
1062
llvm::Value *instance,
1062
1063
CanType sourceFormalType,
1063
1064
CanType targetFormalType) {
1064
- if (!doesCastPreserveOwnershipForTypes (IGF.IGM .getSILModule (), sourceFormalType,
1065
- targetFormalType)) {
1065
+ if (!doesCastPreserveOwnershipForTypes (IGF.IGM .getSILModule (),
1066
+ sourceFormalType, targetFormalType)) {
1066
1067
return nullptr ;
1067
1068
}
1068
1069
@@ -1089,6 +1090,17 @@ llvm::Value *irgen::emitFastClassCastIfPossible(IRGenFunction &IGF,
1089
1090
1090
1091
// Get the metadata pointer of the destination class type.
1091
1092
llvm::Value *destMetadata = IGF.IGM .getAddrOfTypeMetadata (targetFormalType);
1093
+ if (IGF.IGM .IRGen .Opts .LazyInitializeClassMetadata ) {
1094
+ llvm::Function *accessor =
1095
+ IGF.IGM .getAddrOfTypeMetadataAccessFunction (targetFormalType,
1096
+ NotForDefinition);
1097
+ auto request = DynamicMetadataRequest (MetadataState::Complete);
1098
+ // We know that we are not in a gneric class context, so we can safely
1099
+ // determine that the call here does not need to take that into account.
1100
+ auto response =
1101
+ IGF.emitGenericTypeMetadataAccessFunctionCall (accessor, {}, request);
1102
+ destMetadata = response.getMetadata ();
1103
+ }
1092
1104
llvm::Value *lhs = IGF.Builder .CreateBitCast (destMetadata, IGF.IGM .Int8PtrTy );
1093
1105
1094
1106
// Load the isa pointer.
0 commit comments