@@ -4423,8 +4423,34 @@ void IRGenModule::addProtocolConformance(ConformanceDescription &&record) {
44234423 }
44244424}
44254425
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));
44284454}
44294455
44304456// / Emit the protocol conformance list and return it (if asContiguousArray is
@@ -4648,17 +4674,12 @@ llvm::Constant *IRGenModule::emitTypeMetadataRecords(bool asContiguousArray) {
46484674 return nullptr ;
46494675}
46504676
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) {
46584679 auto var = new llvm::GlobalVariable (
46594680 Module, AccessibleFunctionRecordTy, /* isConstant=*/ true ,
46604681 llvm::GlobalValue::PrivateLinkage, /* initializer=*/ nullptr ,
4661- mangledRecordName );
4682+ func. getRecordName () );
46624683
46634684 ConstantInitBuilder builder (*this );
46644685
@@ -4669,47 +4690,36 @@ void IRGenModule::emitAccessibleFunction(
46694690 // -- Field: Name (record name)
46704691 {
46714692 llvm::Constant *name =
4672- getAddrOfGlobalString (mangledFunctionName ,
4693+ getAddrOfGlobalString (func. getFunctionName () ,
46734694 /* willBeRelativelyAddressed=*/ true );
46744695 fields.addRelativeAddress (name);
46754696 }
46764697
46774698 // -- Field: GenericEnvironment
46784699 llvm::Constant *genericEnvironment = nullptr ;
46794700
4680- GenericSignature signature;
4681- if (auto *env = func-> getGenericEnvironment () ) {
4701+ GenericSignature signature = func. getType ()-> getInvocationGenericSignature () ;
4702+ if (signature ) {
46824703 // Drop all the marker protocols because they are effect-less
46834704 // at runtime.
4684- signature = env-> getGenericSignature () .withoutMarkerProtocols ();
4705+ signature = signature .withoutMarkerProtocols ();
46854706
46864707 genericEnvironment =
46874708 getAddrOfGenericEnvironment (signature.getCanonicalSignature ());
46884709 }
46894710 fields.addRelativeAddressOrNull (genericEnvironment);
46904711
46914712 // -- 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 ;
46954715 fields.addRelativeAddress (type);
46964716
46974717 // -- 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 ());
47094719
47104720 // -- Field: Flags
47114721 AccessibleFunctionFlags flags;
4712- flags.setDistributed (func-> isDistributed ());
4722+ flags.setDistributed (func. isDistributed ());
47134723 fields.addInt32 (flags.getOpaqueValue ());
47144724
47154725 // ---- End of 'TargetAccessibleFunctionRecord' fields
@@ -4746,7 +4756,7 @@ void IRGenModule::emitAccessibleFunctions() {
47464756 break ;
47474757 }
47484758
4749- for (auto * func : AccessibleFunctions) {
4759+ for (const auto & func : AccessibleFunctions) {
47504760 emitAccessibleFunction (fnsSectionName, func);
47514761 }
47524762}
0 commit comments