Skip to content

Commit

Permalink
Make the linking pass add new functions to the call graph.
Browse files Browse the repository at this point in the history
If we already have a call graph built, we should add any newly
deserialized functions to it. This is happening in other places we're
deserializing, but wasn't happening in the linking pass, and we've been
getting away with it because we invalidate the entire call graph and
rebuild it when we next need it.

An upcoming change will invalidate only the call graph node for the
current function, so we really need to add these new functions to the
call graph as we deserialize them.
  • Loading branch information
rudkx committed Nov 3, 2015
1 parent f14e75c commit 734d1b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
21 changes: 13 additions & 8 deletions lib/SIL/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@ bool SILLinkerVisitor::processFunction(SILFunction *F) {
return false;

// If F is a declaration, first deserialize it.
auto *NewFn = F->isExternalDeclaration() ? Loader->lookupSILFunction(F) : F;
if (!NewFn || NewFn->isExternalDeclaration())
return false;
if (F->isExternalDeclaration()) {
auto *NewFn = Loader->lookupSILFunction(F);

// Notify client of new deserialized function.
if (Callback)
Callback(NewFn);
if (!NewFn || NewFn->isExternalDeclaration())
return false;

if (Callback)
Callback(NewFn);

F = NewFn;
}

++NumFuncLinked;

// Try to transitively deserialize everything referenced by NewFn.
Worklist.push_back(NewFn);
// Try to transitively deserialize everything referenced by this
// function.
Worklist.push_back(F);
process();

// Since we successfully processed at least one function, return true.
Expand Down
10 changes: 8 additions & 2 deletions lib/SILPasses/UtilityPasses/Link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
//
//===----------------------------------------------------------------------===//

#include "swift/SILAnalysis/CallGraph.h"
#include "swift/SILAnalysis/CallGraphAnalysis.h"
#include "swift/SILPasses/Passes.h"
#include "swift/SILPasses/Transforms.h"
#include "swift/SIL/SILModule.h"
Expand Down Expand Up @@ -42,10 +44,14 @@ class SILLinker : public SILModuleTransform {
void run() override {
// Copies code from the standard library into the user program to enable
// optimizations.
auto *CGA = PM->getAnalysis<CallGraphAnalysis>();
auto *CG = CGA->getCallGraphOrNull();
CallGraphLinkerEditor Editor(CG);
SILModule &M = *getModule();
for (auto &Fn : M)
if (M.linkFunction(&Fn, SILModule::LinkingMode::LinkAll))
invalidateAnalysis(&Fn, SILAnalysis::PreserveKind::Branches);
if (M.linkFunction(&Fn, SILModule::LinkingMode::LinkAll,
Editor.getCallback()))
invalidateAnalysis(&Fn, SILAnalysis::PreserveKind::ProgramFlow);
}

StringRef getName() override { return "SIL Linker"; }
Expand Down

0 comments on commit 734d1b4

Please sign in to comment.