[rebranch] Pass memory effects through to getRuntimeFn

These were being lost in the `IRGenModule::get##ID##Fn()`
implementation.
This commit is contained in:
Ben Barham
2023-08-08 11:55:27 -07:00
parent 67c00cba23
commit b4ad633de7
3 changed files with 38 additions and 27 deletions

View File

@@ -975,15 +975,12 @@ llvm::FunctionType *swift::getRuntimeFnType(llvm::Module &Module,
/*isVararg*/ false);
}
llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
llvm::Constant *&cache,
const char *name,
llvm::CallingConv::ID cc,
RuntimeAvailability availability,
llvm::ArrayRef<llvm::Type*> retTypes,
llvm::ArrayRef<llvm::Type*> argTypes,
ArrayRef<Attribute::AttrKind> attrs,
IRGenModule *IGM) {
llvm::Constant *swift::getRuntimeFn(
llvm::Module &Module, llvm::Constant *&cache, const char *name,
llvm::CallingConv::ID cc, RuntimeAvailability availability,
llvm::ArrayRef<llvm::Type *> retTypes,
llvm::ArrayRef<llvm::Type *> argTypes, ArrayRef<Attribute::AttrKind> attrs,
ArrayRef<llvm::MemoryEffects> memEffects, IRGenModule *IGM) {
if (cache)
return cache;
@@ -1036,7 +1033,7 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
if (!isStandardLibrary(Module) && IsExternal &&
::useDllStorage(llvm::Triple(Module.getTargetTriple())))
fn->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
if (IsExternal && isWeakLinked
&& !::useDllStorage(llvm::Triple(Module.getTargetTriple())))
fn->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
@@ -1053,6 +1050,16 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
else
buildFnAttr.addAttribute(Attr);
}
if (!memEffects.empty()) {
llvm::MemoryEffects mergedEffects = llvm::MemoryEffects::none();
for (auto effect : memEffects) {
mergedEffects |= effect;
}
buildFnAttr.addAttribute(llvm::Attribute::getWithMemoryEffects(
Module.getContext(), mergedEffects));
}
fn->addFnAttrs(buildFnAttr);
fn->addRetAttrs(buildRetAttr);
fn->addParamAttrs(0, buildFirstParamAttr);
@@ -1112,8 +1119,8 @@ void IRGenModule::registerRuntimeEffect(ArrayRef<RuntimeEffect> effect,
#define ATTRS(...) { __VA_ARGS__ }
#define NO_ATTRS {}
#define EFFECT(...) { __VA_ARGS__ }
#define UNKNOWN_MEMEFFECTS \
{ llvm::MemoryEffects::unknown() }
#define UNKNOWN_MEMEFFECTS \
{}
#define MEMEFFECTS(...) \
{ __VA_ARGS__ }
@@ -1124,15 +1131,12 @@ void IRGenModule::registerRuntimeEffect(ArrayRef<RuntimeEffect> effect,
registerRuntimeEffect(EFFECT, #NAME); \
return getRuntimeFn(Module, ID##Fn, #NAME, CC, \
AVAILABILITY(this->Context), RETURNS, ARGS, ATTRS, \
this); \
MEMEFFECTS, this); \
} \
FunctionPointer IRGenModule::get##ID##FunctionPointer() { \
using namespace RuntimeConstants; \
auto fn = get##ID##Fn(); \
auto fnTy = get##ID##FnType(); \
llvm::MemoryEffects effects = llvm::MemoryEffects::none(); \
for (auto effect : MEMEFFECTS) \
effects |= effect; \
llvm::AttributeList attrs; \
SmallVector<llvm::Attribute::AttrKind, 8> theAttrs(ATTRS); \
for (auto Attr : theAttrs) { \
@@ -1143,9 +1147,15 @@ void IRGenModule::registerRuntimeEffect(ArrayRef<RuntimeEffect> effect,
else \
attrs = attrs.addFnAttribute(getLLVMContext(), Attr); \
} \
attrs = attrs.addFnAttribute( \
getLLVMContext(), \
llvm::Attribute::getWithMemoryEffects(getLLVMContext(), effects)); \
ArrayRef<llvm::MemoryEffects> memEffects(MEMEFFECTS); \
if (!memEffects.empty()) { \
llvm::MemoryEffects effects = llvm::MemoryEffects::none(); \
for (auto effect : memEffects) \
effects |= effect; \
attrs = attrs.addFnAttribute( \
getLLVMContext(), \
llvm::Attribute::getWithMemoryEffects(getLLVMContext(), effects)); \
} \
auto sig = Signature(fnTy, attrs, CC); \
return FunctionPointer::forDirect(FunctionPointer::Kind::Function, fn, \
nullptr, sig); \