Skip to content

Commit ac875d0

Browse files
authored
Merge pull request swiftlang#40947 from xedin/generic-dist-funcs
[Distributed] Augment accessor to support calling generic distributed thunks
2 parents bc74ac7 + 708bead commit ac875d0

16 files changed

+1014
-268
lines changed

include/swift/ABI/Metadata.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,6 +3096,8 @@ class TargetGenericEnvironment
30963096
}
30973097
};
30983098

3099+
using GenericEnvironmentDescriptor = TargetGenericEnvironment<InProcess>;
3100+
30993101
/// CRTP class for a context descriptor that includes trailing generic
31003102
/// context description.
31013103
template<class Self,
@@ -5145,6 +5147,10 @@ struct TargetAccessibleFunctionRecord final {
51455147
/// function so it can be looked up later.
51465148
RelativeDirectPointer<const char, /*nullable*/ false> Name;
51475149

5150+
/// The generic environment associated with this accessor function.
5151+
RelativeDirectPointer<GenericEnvironmentDescriptor, /*nullable*/ true>
5152+
GenericEnvironment;
5153+
51485154
/// The Swift function type, encoded as a mangled name.
51495155
RelativeDirectPointer<const char, /*nullable*/ false> FunctionType;
51505156

lib/IRGen/GenDecl.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,21 +4152,31 @@ void IRGenModule::emitAccessibleFunctions() {
41524152
llvm::GlobalValue::PrivateLinkage, /*initializer*/ nullptr,
41534153
mangledRecordName);
41544154

4155+
ConstantInitBuilder builder(*this);
4156+
ConstantStructBuilder fields =
4157+
builder.beginStruct(AccessibleFunctionRecordTy);
4158+
41554159
std::string mangledFunctionName =
41564160
LinkEntity::forSILFunction(func).mangleAsString();
41574161
llvm::Constant *name = getAddrOfGlobalString(
41584162
mangledFunctionName, /*willBeRelativelyAddressed*/ true);
4159-
llvm::Constant *relativeName = emitDirectRelativeReference(name, var, {});
4163+
fields.addRelativeAddress(name);
4164+
4165+
llvm::Constant *genericEnvironment = nullptr;
41604166

41614167
GenericSignature signature;
41624168
if (auto *env = func->getGenericEnvironment()) {
41634169
signature = env->getGenericSignature();
4170+
genericEnvironment =
4171+
getAddrOfGenericEnvironment(signature.getCanonicalSignature());
41644172
}
41654173

4174+
fields.addRelativeAddressOrNull(genericEnvironment);
4175+
41664176
llvm::Constant *type = getTypeRef(func->getLoweredFunctionType(), signature,
41674177
MangledTypeRefRole::Metadata)
41684178
.first;
4169-
llvm::Constant *relativeType = emitDirectRelativeReference(type, var, {1});
4179+
fields.addRelativeAddress(type);
41704180

41714181
llvm::Constant *funcAddr = nullptr;
41724182
if (func->isDistributed()) {
@@ -4178,20 +4188,13 @@ void IRGenModule::emitAccessibleFunctions() {
41784188
funcAddr = getAddrOfSILFunction(func, NotForDefinition);
41794189
}
41804190

4181-
llvm::Constant *relativeFuncAddr =
4182-
emitDirectRelativeReference(funcAddr, var, {2});
4183-
4184-
AccessibleFunctionFlags flagsVal;
4185-
flagsVal.setDistributed(func->isDistributed());
4191+
fields.addRelativeAddress(funcAddr);
41864192

4187-
llvm::Constant *flags =
4188-
llvm::ConstantInt::get(Int32Ty, flagsVal.getOpaqueValue());
4193+
AccessibleFunctionFlags flags;
4194+
flags.setDistributed(func->isDistributed());
4195+
fields.addInt32(flags.getOpaqueValue());
41894196

4190-
llvm::Constant *recordFields[] = {relativeName, relativeType,
4191-
relativeFuncAddr, flags};
4192-
auto record =
4193-
llvm::ConstantStruct::get(AccessibleFunctionRecordTy, recordFields);
4194-
var->setInitializer(record);
4197+
fields.finishAndSetAsInitializer(var);
41954198
var->setSection(sectionName);
41964199
var->setAlignment(llvm::MaybeAlign(4));
41974200
disableAddressSanitizer(*this, var);

0 commit comments

Comments
 (0)