@@ -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,
@@ -4293,9 +4319,6 @@ void IRGenModule::generateCallToOutlinedCopyAddr(
4293
4319
llvm::Type *llvmType = dest->getType ();
4294
4320
auto *outlinedF =
4295
4321
(this ->*MethodToCall)(objectTI, llvmType, T, typeToMetadataVec);
4296
- llvm::Function *fn = dyn_cast<llvm::Function>(outlinedF);
4297
- assert (fn && " Expected llvm::Function" );
4298
- fn->setLinkage (llvm::GlobalValue::InternalLinkage);
4299
4322
llvm::CallInst *call = IGF.Builder .CreateCall (outlinedF, argsVec);
4300
4323
call->setCallingConv (DefaultCC);
4301
4324
}
@@ -4304,8 +4327,10 @@ void IRGenModule::generateCallToOutlinedDestroy(
4304
4327
IRGenFunction &IGF, const TypeInfo &objectTI, Address addr, SILType T,
4305
4328
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4306
4329
IRGenMangler mangler;
4307
- CanType canType = T.getSwiftRValueType ();
4308
- std::string funcName = mangler.mangleOutlinedDestroyFunction (canType, this );
4330
+ auto manglingBits =
4331
+ getTypeAndGenericSignatureForManglingOutlineFunction (T);
4332
+ auto funcName = mangler.mangleOutlinedDestroyFunction (manglingBits.first ,
4333
+ manglingBits.second );
4309
4334
4310
4335
llvm::SmallVector<llvm::Type *, 4 > argsTysVec;
4311
4336
llvm::SmallVector<llvm::Value *, 4 > argsVec;
@@ -4339,12 +4364,6 @@ void IRGenModule::generateCallToOutlinedDestroy(
4339
4364
},
4340
4365
true /* setIsNoInline*/ );
4341
4366
4342
- if (T.hasArchetype ()) {
4343
- llvm::Function *fn = dyn_cast<llvm::Function>(outlinedF);
4344
- assert (fn && " Expected llvm::Function" );
4345
- fn->setLinkage (llvm::GlobalValue::InternalLinkage);
4346
- }
4347
-
4348
4367
llvm::CallInst *call = IGF.Builder .CreateCall (outlinedF, argsVec);
4349
4368
call->setCallingConv (DefaultCC);
4350
4369
}
@@ -4388,9 +4407,10 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedInitializeWithTakeFunction(
4388
4407
const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy,
4389
4408
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4390
4409
IRGenMangler mangler;
4391
- CanType canType = addrTy.getSwiftRValueType ();
4392
- std::string funcName =
4393
- mangler.mangleOutlinedInitializeWithTakeFunction (canType, this );
4410
+ auto manglingBits =
4411
+ getTypeAndGenericSignatureForManglingOutlineFunction (addrTy);
4412
+ auto funcName = mangler.mangleOutlinedInitializeWithTakeFunction (manglingBits.first ,
4413
+ manglingBits.second );
4394
4414
auto GenFunc = [](const TypeInfo &objectTI, IRGenFunction &IGF, Address dest,
4395
4415
Address src, SILType T) {
4396
4416
objectTI.initializeWithTake (IGF, dest, src, T, true );
@@ -4403,9 +4423,11 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedInitializeWithCopyFunction(
4403
4423
const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy,
4404
4424
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4405
4425
IRGenMangler mangler;
4406
- CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
4407
- std::string funcName =
4408
- mangler.mangleOutlinedInitializeWithCopyFunction (canType, this );
4426
+ auto manglingBits =
4427
+ getTypeAndGenericSignatureForManglingOutlineFunction (addrTy);
4428
+ auto funcName =
4429
+ mangler.mangleOutlinedInitializeWithCopyFunction (manglingBits.first ,
4430
+ manglingBits.second );
4409
4431
auto GenFunc = [](const TypeInfo &objectTI, IRGenFunction &IGF, Address dest,
4410
4432
Address src, SILType T) {
4411
4433
objectTI.initializeWithCopy (IGF, dest, src, T, true );
@@ -4418,9 +4440,11 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedAssignWithTakeFunction(
4418
4440
const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy,
4419
4441
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4420
4442
IRGenMangler mangler;
4421
- CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
4422
- std::string funcName =
4423
- mangler.mangleOutlinedAssignWithTakeFunction (canType, this );
4443
+ auto manglingBits =
4444
+ getTypeAndGenericSignatureForManglingOutlineFunction (addrTy);
4445
+ auto funcName =
4446
+ mangler.mangleOutlinedAssignWithTakeFunction (manglingBits.first ,
4447
+ manglingBits.second );
4424
4448
auto GenFunc = [](const TypeInfo &objectTI, IRGenFunction &IGF, Address dest,
4425
4449
Address src, SILType T) {
4426
4450
objectTI.assignWithTake (IGF, dest, src, T, true );
@@ -4433,29 +4457,15 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedAssignWithCopyFunction(
4433
4457
const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy,
4434
4458
const llvm::MapVector<CanType, llvm::Value *> *typeToMetadataVec) {
4435
4459
IRGenMangler mangler;
4436
- CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
4437
- std::string funcName =
4438
- mangler.mangleOutlinedAssignWithCopyFunction (canType, this );
4460
+ auto manglingBits =
4461
+ getTypeAndGenericSignatureForManglingOutlineFunction (addrTy);
4462
+ auto funcName =
4463
+ mangler.mangleOutlinedAssignWithCopyFunction (manglingBits.first ,
4464
+ manglingBits.second );
4439
4465
auto GenFunc = [](const TypeInfo &objectTI, IRGenFunction &IGF, Address dest,
4440
4466
Address src, SILType T) {
4441
4467
objectTI.assignWithCopy (IGF, dest, src, T, true );
4442
4468
};
4443
4469
return getOrCreateOutlinedCopyAddrHelperFunction (
4444
4470
objectTI, llvmType, addrTy, funcName, GenFunc, typeToMetadataVec);
4445
4471
}
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