mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[rebranch] Pass memory effects through to getRuntimeFn
These were being lost in the `IRGenModule::get##ID##Fn()` implementation.
This commit is contained in:
@@ -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); \
|
||||
|
||||
Reference in New Issue
Block a user