@@ -4231,13 +4231,35 @@ IRGenModule::getOrCreateHelperFunction(StringRef fnName, llvm::Type *resultTy,
4231
4231
return fn;
4232
4232
}
4233
4233
4234
+ std::pair<CanType, CanGenericSignature>
4235
+ irgen::getTypeAndGenericSignatureForManglingOutlineFunction (SILType type) {
4236
+ auto loweredType = type.getSwiftRValueType ();
4237
+ if (loweredType->hasArchetype ()) {
4238
+ GenericEnvironment *env = nullptr ;
4239
+ loweredType.findIf ([&env](Type t) -> bool {
4240
+ if (auto arch = t->getAs <ArchetypeType>()) {
4241
+ env = arch->getGenericEnvironment ();
4242
+ return true ;
4243
+ }
4244
+ return false ;
4245
+ });
4246
+ assert (env && " has archetype but no archetype?!" );
4247
+ return {loweredType->mapTypeOutOfContext ()->getCanonicalType (),
4248
+ env->getGenericSignature ()->getCanonicalSignature ()};
4249
+ }
4250
+ return {loweredType, nullptr };
4251
+ }
4252
+
4234
4253
llvm::Constant *IRGenModule::getOrCreateRetainFunction (const TypeInfo &objectTI,
4235
- Type t,
4254
+ SILType t,
4236
4255
llvm::Type *llvmType) {
4237
4256
auto *loadableTI = dyn_cast<LoadableTypeInfo>(&objectTI);
4238
4257
assert (loadableTI && " Should only be called on Loadable types" );
4239
4258
IRGenMangler mangler;
4240
- std::string funcName = mangler.mangleOutlinedRetainFunction (t);
4259
+ auto manglingBits =
4260
+ getTypeAndGenericSignatureForManglingOutlineFunction (t);
4261
+ auto funcName = mangler.mangleOutlinedRetainFunction (manglingBits.first ,
4262
+ manglingBits.second );
4241
4263
llvm::Type *argTys[] = {llvmType};
4242
4264
return getOrCreateHelperFunction (
4243
4265
funcName, llvmType, argTys,
@@ -4255,12 +4277,16 @@ llvm::Constant *IRGenModule::getOrCreateRetainFunction(const TypeInfo &objectTI,
4255
4277
}
4256
4278
4257
4279
llvm::Constant *
4258
- IRGenModule::getOrCreateReleaseFunction (const TypeInfo &objectTI, Type t,
4280
+ IRGenModule::getOrCreateReleaseFunction (const TypeInfo &objectTI,
4281
+ SILType t,
4259
4282
llvm::Type *llvmType) {
4260
4283
auto *loadableTI = dyn_cast<LoadableTypeInfo>(&objectTI);
4261
4284
assert (loadableTI && " Should only be called on Loadable types" );
4262
4285
IRGenMangler mangler;
4263
- std::string funcName = mangler.mangleOutlinedReleaseFunction (t);
4286
+ auto manglingBits =
4287
+ getTypeAndGenericSignatureForManglingOutlineFunction (t);
4288
+ auto funcName = mangler.mangleOutlinedReleaseFunction (manglingBits.first ,
4289
+ manglingBits.second );
4264
4290
llvm::Type *argTys[] = {llvmType};
4265
4291
return getOrCreateHelperFunction (
4266
4292
funcName, llvmType, argTys,
@@ -4304,8 +4330,10 @@ void IRGenModule::generateCallToOutlinedDestroy(
4304
4330
IRGenFunction &IGF, const TypeInfo &objectTI, Address addr, SILType T,
4305
4331
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4306
4332
IRGenMangler mangler;
4307
- CanType canType = T.getSwiftRValueType ();
4308
- std::string funcName = mangler.mangleOutlinedDestroyFunction (canType, this );
4333
+ auto manglingBits =
4334
+ getTypeAndGenericSignatureForManglingOutlineFunction (T);
4335
+ auto funcName = mangler.mangleOutlinedDestroyFunction (manglingBits.first ,
4336
+ manglingBits.second );
4309
4337
4310
4338
llvm::SmallVector<llvm::Type *, 4 > argsTysVec;
4311
4339
llvm::SmallVector<llvm::Value *, 4 > argsVec;
@@ -4388,9 +4416,10 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedInitializeWithTakeFunction(
4388
4416
const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy,
4389
4417
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4390
4418
IRGenMangler mangler;
4391
- CanType canType = addrTy.getSwiftRValueType ();
4392
- std::string funcName =
4393
- mangler.mangleOutlinedInitializeWithTakeFunction (canType, this );
4419
+ auto manglingBits =
4420
+ getTypeAndGenericSignatureForManglingOutlineFunction (addrTy);
4421
+ auto funcName = mangler.mangleOutlinedInitializeWithTakeFunction (manglingBits.first ,
4422
+ manglingBits.second );
4394
4423
auto GenFunc = [](const TypeInfo &objectTI, IRGenFunction &IGF, Address dest,
4395
4424
Address src, SILType T) {
4396
4425
objectTI.initializeWithTake (IGF, dest, src, T, true );
@@ -4403,9 +4432,11 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedInitializeWithCopyFunction(
4403
4432
const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy,
4404
4433
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4405
4434
IRGenMangler mangler;
4406
- CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
4407
- std::string funcName =
4408
- mangler.mangleOutlinedInitializeWithCopyFunction (canType, this );
4435
+ auto manglingBits =
4436
+ getTypeAndGenericSignatureForManglingOutlineFunction (addrTy);
4437
+ auto funcName =
4438
+ mangler.mangleOutlinedInitializeWithCopyFunction (manglingBits.first ,
4439
+ manglingBits.second );
4409
4440
auto GenFunc = [](const TypeInfo &objectTI, IRGenFunction &IGF, Address dest,
4410
4441
Address src, SILType T) {
4411
4442
objectTI.initializeWithCopy (IGF, dest, src, T, true );
@@ -4418,9 +4449,11 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedAssignWithTakeFunction(
4418
4449
const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy,
4419
4450
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4420
4451
IRGenMangler mangler;
4421
- CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
4422
- std::string funcName =
4423
- mangler.mangleOutlinedAssignWithTakeFunction (canType, this );
4452
+ auto manglingBits =
4453
+ getTypeAndGenericSignatureForManglingOutlineFunction (addrTy);
4454
+ auto funcName =
4455
+ mangler.mangleOutlinedAssignWithTakeFunction (manglingBits.first ,
4456
+ manglingBits.second );
4424
4457
auto GenFunc = [](const TypeInfo &objectTI, IRGenFunction &IGF, Address dest,
4425
4458
Address src, SILType T) {
4426
4459
objectTI.assignWithTake (IGF, dest, src, T, true );
@@ -4433,29 +4466,15 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedAssignWithCopyFunction(
4433
4466
const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy,
4434
4467
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4435
4468
IRGenMangler mangler;
4436
- CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
4437
- std::string funcName =
4438
- mangler.mangleOutlinedAssignWithCopyFunction (canType, this );
4469
+ auto manglingBits =
4470
+ getTypeAndGenericSignatureForManglingOutlineFunction (addrTy);
4471
+ auto funcName =
4472
+ mangler.mangleOutlinedAssignWithCopyFunction (manglingBits.first ,
4473
+ manglingBits.second );
4439
4474
auto GenFunc = [](const TypeInfo &objectTI, IRGenFunction &IGF, Address dest,
4440
4475
Address src, SILType T) {
4441
4476
objectTI.assignWithCopy (IGF, dest, src, T, true );
4442
4477
};
4443
4478
return getOrCreateOutlinedCopyAddrHelperFunction (
4444
4479
objectTI, llvmType, addrTy, funcName, GenFunc, typeToMetadataVec);
4445
4480
}
4446
-
4447
- // IRGen is only multi-threaded during LLVM part
4448
- // We don't need to be thread safe even
4449
- // We are working on the primary module *before* LLVM
4450
- unsigned IRGenModule::getCanTypeID (const CanType type) {
4451
- if (this != IRGen.getPrimaryIGM ()) {
4452
- return IRGen.getPrimaryIGM ()->getCanTypeID (type);
4453
- }
4454
- auto it = typeToUniqueID.find (type.getPointer ());
4455
- if (it != typeToUniqueID.end ()) {
4456
- return it->second ;
4457
- }
4458
- ++currUniqueID;
4459
- typeToUniqueID[type.getPointer ()] = currUniqueID;
4460
- return currUniqueID;
4461
- }
0 commit comments