Add SIL support for [dynamic_replacement_for: ] functions

This commit is contained in:
Arnold Schwaighofer
2018-11-05 08:15:47 -08:00
parent 7e32c68e1d
commit 52c1903e54
13 changed files with 188 additions and 23 deletions

View File

@@ -128,6 +128,11 @@ SILFunction::~SILFunction() {
// an allocator that may recycle freed memory.
dropAllReferences();
if (ReplacedFunction) {
ReplacedFunction->decrementRefCount();
ReplacedFunction = nullptr;
}
auto &M = getModule();
for (auto &BB : *this) {
for (auto I = BB.begin(), E = BB.end(); I != E;) {
@@ -489,6 +494,9 @@ SILFunction::isPossiblyUsedExternally() const {
if (linkage == SILLinkage::Hidden && hasCReferences())
return true;
if (ReplacedFunction)
return true;
return swift::isPossiblyUsedExternally(linkage, getModule().isWholeModule());
}
@@ -517,6 +525,24 @@ bool SILFunction::shouldVerifyOwnership() const {
return !hasSemanticsAttr("verify.ownership.sil.never");
}
static Identifier getIdentifierForObjCSelector(ObjCSelector selector, ASTContext &Ctxt) {
SmallVector<char, 64> buffer;
auto str = selector.getString(buffer);
return Ctxt.getIdentifier(str);
}
void SILFunction::setObjCReplacement(AbstractFunctionDecl *replacedFunc) {
assert(ReplacedFunction == nullptr && ObjCReplacementFor.empty());
assert(replacedFunc != nullptr);
ObjCReplacementFor = getIdentifierForObjCSelector(
replacedFunc->getObjCSelector(), getASTContext());
}
void SILFunction::setObjCReplacement(Identifier replacedFunc) {
assert(ReplacedFunction == nullptr && ObjCReplacementFor.empty());
ObjCReplacementFor = replacedFunc;
}
// See swift/Basic/Statistic.h for declaration: this enables tracing
// SILFunctions, is defined here to avoid too much layering violation / circular
// linkage dependency.