@@ -4423,8 +4423,34 @@ void IRGenModule::addProtocolConformance(ConformanceDescription &&record) {
4423
4423
}
4424
4424
}
4425
4425
4426
- void IRGenModule::addAccessibleFunction (SILFunction *func) {
4427
- AccessibleFunctions.push_back (func);
4426
+ AccessibleFunction AccessibleFunction::forSILFunction (IRGenModule &IGM,
4427
+ SILFunction *func) {
4428
+ assert (!func->isDistributed () && " use forDistributed(...) instead" );
4429
+
4430
+ llvm::Constant *funcAddr = nullptr ;
4431
+ if (func->isAsync ()) {
4432
+ funcAddr = IGM.getAddrOfAsyncFunctionPointer (func);
4433
+ } else {
4434
+ funcAddr = IGM.getAddrOfSILFunction (func, NotForDefinition);
4435
+ }
4436
+
4437
+ return AccessibleFunction (
4438
+ /* recordName=*/ LinkEntity::forAccessibleFunctionRecord (func)
4439
+ .mangleAsString (),
4440
+ /* funcName=*/ LinkEntity::forSILFunction (func).mangleAsString (),
4441
+ /* isDistributed=*/ false , func->getLoweredFunctionType (), funcAddr);
4442
+ }
4443
+
4444
+ AccessibleFunction AccessibleFunction::forDistributed (std::string recordName,
4445
+ std::string accessorName,
4446
+ CanSILFunctionType type,
4447
+ llvm::Constant *address) {
4448
+ return AccessibleFunction (recordName, accessorName,
4449
+ /* isDistributed=*/ true , type, address);
4450
+ }
4451
+
4452
+ void IRGenModule::addAccessibleFunction (AccessibleFunction func) {
4453
+ AccessibleFunctions.push_back (std::move (func));
4428
4454
}
4429
4455
4430
4456
// / Emit the protocol conformance list and return it (if asContiguousArray is
@@ -4648,17 +4674,12 @@ llvm::Constant *IRGenModule::emitTypeMetadataRecords(bool asContiguousArray) {
4648
4674
return nullptr ;
4649
4675
}
4650
4676
4651
- void IRGenModule::emitAccessibleFunction (
4652
- StringRef sectionName, SILFunction* func) {
4653
- std::string mangledRecordName =
4654
- LinkEntity::forAccessibleFunctionRecord (func).mangleAsString ();
4655
- std::string mangledFunctionName =
4656
- LinkEntity::forSILFunction (func).mangleAsString ();
4657
-
4677
+ void IRGenModule::emitAccessibleFunction (StringRef sectionName,
4678
+ const AccessibleFunction &func) {
4658
4679
auto var = new llvm::GlobalVariable (
4659
4680
Module, AccessibleFunctionRecordTy, /* isConstant=*/ true ,
4660
4681
llvm::GlobalValue::PrivateLinkage, /* initializer=*/ nullptr ,
4661
- mangledRecordName );
4682
+ func. getRecordName () );
4662
4683
4663
4684
ConstantInitBuilder builder (*this );
4664
4685
@@ -4669,47 +4690,36 @@ void IRGenModule::emitAccessibleFunction(
4669
4690
// -- Field: Name (record name)
4670
4691
{
4671
4692
llvm::Constant *name =
4672
- getAddrOfGlobalString (mangledFunctionName ,
4693
+ getAddrOfGlobalString (func. getFunctionName () ,
4673
4694
/* willBeRelativelyAddressed=*/ true );
4674
4695
fields.addRelativeAddress (name);
4675
4696
}
4676
4697
4677
4698
// -- Field: GenericEnvironment
4678
4699
llvm::Constant *genericEnvironment = nullptr ;
4679
4700
4680
- GenericSignature signature;
4681
- if (auto *env = func-> getGenericEnvironment () ) {
4701
+ GenericSignature signature = func. getType ()-> getInvocationGenericSignature () ;
4702
+ if (signature ) {
4682
4703
// Drop all the marker protocols because they are effect-less
4683
4704
// at runtime.
4684
- signature = env-> getGenericSignature () .withoutMarkerProtocols ();
4705
+ signature = signature .withoutMarkerProtocols ();
4685
4706
4686
4707
genericEnvironment =
4687
4708
getAddrOfGenericEnvironment (signature.getCanonicalSignature ());
4688
4709
}
4689
4710
fields.addRelativeAddressOrNull (genericEnvironment);
4690
4711
4691
4712
// -- Field: FunctionType
4692
- llvm::Constant *type = getTypeRef (func->getLoweredFunctionType (), signature,
4693
- MangledTypeRefRole::Metadata)
4694
- .first ;
4713
+ llvm::Constant *type =
4714
+ getTypeRef (func.getType (), signature, MangledTypeRefRole::Metadata).first ;
4695
4715
fields.addRelativeAddress (type);
4696
4716
4697
4717
// -- Field: Function
4698
- llvm::Constant *funcAddr = nullptr ;
4699
- if (func->isDistributed ()) {
4700
- funcAddr = getAddrOfAsyncFunctionPointer (
4701
- LinkEntity::forDistributedTargetAccessor (func));
4702
- } else if (func->isAsync ()) {
4703
- funcAddr = getAddrOfAsyncFunctionPointer (func);
4704
- } else {
4705
- funcAddr = getAddrOfSILFunction (func, NotForDefinition);
4706
- }
4707
-
4708
- fields.addRelativeAddress (funcAddr);
4718
+ fields.addRelativeAddress (func.getAddress ());
4709
4719
4710
4720
// -- Field: Flags
4711
4721
AccessibleFunctionFlags flags;
4712
- flags.setDistributed (func-> isDistributed ());
4722
+ flags.setDistributed (func. isDistributed ());
4713
4723
fields.addInt32 (flags.getOpaqueValue ());
4714
4724
4715
4725
// ---- End of 'TargetAccessibleFunctionRecord' fields
@@ -4746,7 +4756,7 @@ void IRGenModule::emitAccessibleFunctions() {
4746
4756
break ;
4747
4757
}
4748
4758
4749
- for (auto * func : AccessibleFunctions) {
4759
+ for (const auto & func : AccessibleFunctions) {
4750
4760
emitAccessibleFunction (fnsSectionName, func);
4751
4761
}
4752
4762
}
0 commit comments