SILFunction: add getMemoryBehavior

This retrieves the side effect information from the function effects.
This commit is contained in:
Erik Eckstein
2022-10-19 19:10:17 +02:00
parent 143d432e56
commit 698196b1eb
4 changed files with 35 additions and 2 deletions

View File

@@ -146,6 +146,7 @@ static FunctionWriteFn writeFunction = nullptr;
static FunctionParseFn parseFunction = nullptr;
static FunctionCopyEffectsFn copyEffectsFunction = nullptr;
static FunctionGetEffectInfoFn getEffectInfoFunction = nullptr;
static FunctionGetMemBehviorFn getMemBehvaiorFunction = nullptr;
SILFunction::SILFunction(
SILModule &Module, SILLinkage Linkage, StringRef Name,
@@ -932,7 +933,8 @@ void Function_register(SwiftMetatype metatype,
FunctionRegisterFn initFn, FunctionRegisterFn destroyFn,
FunctionWriteFn writeFn, FunctionParseFn parseFn,
FunctionCopyEffectsFn copyEffectsFn,
FunctionGetEffectInfoFn effectInfoFn) {
FunctionGetEffectInfoFn effectInfoFn,
FunctionGetMemBehviorFn memBehaviorFn) {
functionMetatype = metatype;
initFunction = initFn;
destroyFunction = destroyFn;
@@ -940,6 +942,7 @@ void Function_register(SwiftMetatype metatype,
parseFunction = parseFn;
copyEffectsFunction = copyEffectsFn;
getEffectInfoFunction = effectInfoFn;
getMemBehvaiorFunction = memBehaviorFn;
}
std::pair<const char *, int> SILFunction::
@@ -1020,6 +1023,14 @@ visitArgEffects(std::function<void(int, int, bool)> c) const {
}
}
SILInstruction::MemoryBehavior SILFunction::getMemoryBehavior(bool observeRetains) {
if (!getMemBehvaiorFunction)
return SILInstruction::MemoryBehavior::MayHaveSideEffects;
auto b = getMemBehvaiorFunction({this}, observeRetains);
return (SILInstruction::MemoryBehavior)b;
}
SILFunction *SILFunction::getFunction(SILDeclRef ref, SILModule &M) {
swift::Lowering::SILGenModule SILGenModule(M, ref.getModuleContext());
return SILGenModule.getFunction(ref, swift::NotForDefinition);