2003-08-31 01:54:59 +00:00
|
|
|
//===- CallGraphSCCPass.cpp - Pass that operates BU on call graph ---------===//
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-08-31 01:54:59 +00:00
|
|
|
//
|
|
|
|
// This file implements the CallGraphSCCPass class, which is used for passes
|
|
|
|
// which are implemented as bottom-up traversals on the call graph. Because
|
|
|
|
// there may be cycles in the call graph, passes of this type operate on the
|
|
|
|
// call-graph in SCC order: that is, they process function bottom-up, except for
|
|
|
|
// recursive functions, which they process all at once.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
#define DEBUG_TYPE "cgscc-passmgr"
|
2003-08-31 01:54:59 +00:00
|
|
|
#include "llvm/CallGraphSCCPass.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/SCCIterator.h"
|
2010-04-21 00:47:40 +00:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/IntrinsicInst.h"
|
|
|
|
#include "llvm/PassManagers.h"
|
2010-04-21 00:47:40 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2010-03-30 04:03:22 +00:00
|
|
|
#include "llvm/Support/Timer.h"
|
2009-08-23 06:03:38 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2004-04-20 21:30:06 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2010-04-21 00:47:40 +00:00
|
|
|
static cl::opt<unsigned>
|
Implement rdar://6295824 and PR6724 with two tiny changes
that can have a big effect :). The first is to enable the
iterative SCC passmanager juice that kicks in when the
scc passmgr detects that a function pass has devirtualized
a call. In this case, it will rerun all the passes it
manages on the SCC, up to the iteration count limit (4). This
is useful because a function pass may devirualize a call, and
we want the inliner to inline it, or pruneeh to infer stuff
about it, etc.
The second patch is to add *all* call sites to the
DevirtualizedCalls list the inliner uses. This list is
about to get renamed, but the jist of this is that the
inliner now reconsiders *all* inlined call sites as candidates
for further inlining. The intuition is this that in cases
like this:
f() { g(1); } g(int x) { h(x); }
We analyze this bottom up, and may decide that it isn't
profitable to inline H into G. Next step, we decide that it is
profitable to inline G into F, and do so, which means that F
now calls H. Even though the call from G -> H may not have been
profitable to inline, the call from F -> H may be (in this case
because a constant allows folding etc).
In my spot checks, this doesn't have a big impact on code. For
example, the LLC output for 252.eon grew from 0.02% (from
317252 to 317308) and 176.gcc actually shrunk by .3% (from 1525612
to 1520964 bytes). 252.eon never iterated in the SCC Passmgr,
176.gcc iterated at most 1 time.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102823 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-01 01:15:56 +00:00
|
|
|
MaxIterations("max-cg-scc-iterations", cl::ReallyHidden, cl::init(4));
|
2010-04-21 00:47:40 +00:00
|
|
|
|
|
|
|
STATISTIC(MaxSCCIterations, "Maximum CGSCCPassMgr iterations on one SCC");
|
|
|
|
|
2007-01-17 21:45:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CGPassManager
|
|
|
|
//
|
2009-09-10 22:01:32 +00:00
|
|
|
/// CGPassManager manages FPPassManagers and CallGraphSCCPasses.
|
2007-01-17 21:45:01 +00:00
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-01-17 21:45:01 +00:00
|
|
|
class CGPassManager : public ModulePass, public PMDataManager {
|
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2011-08-29 17:07:00 +00:00
|
|
|
explicit CGPassManager()
|
|
|
|
: ModulePass(ID), PMDataManager() { }
|
2007-01-17 21:45:01 +00:00
|
|
|
|
|
|
|
/// run - Execute all of the passes scheduled for execution. Keep track of
|
|
|
|
/// whether any of the passes modifies the module, and if so, return true.
|
|
|
|
bool runOnModule(Module &M);
|
|
|
|
|
2012-11-15 00:14:15 +00:00
|
|
|
using ModulePass::doInitialization;
|
|
|
|
using ModulePass::doFinalization;
|
|
|
|
|
2009-02-11 18:19:24 +00:00
|
|
|
bool doInitialization(CallGraph &CG);
|
|
|
|
bool doFinalization(CallGraph &CG);
|
2007-01-17 21:45:01 +00:00
|
|
|
|
|
|
|
/// Pass Manager itself does not invalidate any analysis info.
|
|
|
|
void getAnalysisUsage(AnalysisUsage &Info) const {
|
|
|
|
// CGPassManager walks SCC and it needs CallGraph.
|
|
|
|
Info.addRequired<CallGraph>();
|
|
|
|
Info.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2007-02-01 22:09:37 +00:00
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "CallGraph Pass Manager";
|
|
|
|
}
|
|
|
|
|
2010-01-22 05:24:46 +00:00
|
|
|
virtual PMDataManager *getAsPMDataManager() { return this; }
|
|
|
|
virtual Pass *getAsPass() { return this; }
|
|
|
|
|
2007-01-17 21:45:01 +00:00
|
|
|
// Print passes managed by this manager
|
|
|
|
void dumpPassStructure(unsigned Offset) {
|
2009-12-23 23:09:39 +00:00
|
|
|
errs().indent(Offset*2) << "Call Graph SCC Pass Manager\n";
|
2007-01-17 21:45:01 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
Pass *P = getContainedPass(Index);
|
2010-08-19 01:29:07 +00:00
|
|
|
P->dumpPassStructure(Offset + 1);
|
2007-01-17 21:45:01 +00:00
|
|
|
dumpLastUses(P, Offset+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Pass *getContainedPass(unsigned N) {
|
2009-08-23 06:03:38 +00:00
|
|
|
assert(N < PassVector.size() && "Pass number out of range!");
|
|
|
|
return static_cast<Pass *>(PassVector[N]);
|
2007-01-17 21:45:01 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 15:00:39 +00:00
|
|
|
virtual PassManagerType getPassManagerType() const {
|
2007-01-17 21:45:01 +00:00
|
|
|
return PMT_CallGraphPassManager;
|
|
|
|
}
|
2009-08-31 06:01:21 +00:00
|
|
|
|
|
|
|
private:
|
2010-04-21 00:47:40 +00:00
|
|
|
bool RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,
|
|
|
|
bool &DevirtualizedCall);
|
|
|
|
|
2010-04-16 22:42:17 +00:00
|
|
|
bool RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,
|
2010-04-21 00:47:40 +00:00
|
|
|
CallGraph &CG, bool &CallGraphUpToDate,
|
|
|
|
bool &DevirtualizedCall);
|
|
|
|
bool RefreshCallGraph(CallGraphSCC &CurSCC, CallGraph &CG,
|
2009-09-01 18:32:03 +00:00
|
|
|
bool IsCheckingMode);
|
2007-01-17 21:45:01 +00:00
|
|
|
};
|
|
|
|
|
2009-08-31 06:01:21 +00:00
|
|
|
} // end anonymous namespace.
|
2008-05-13 00:00:25 +00:00
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char CGPassManager::ID = 0;
|
2009-08-31 06:01:21 +00:00
|
|
|
|
2010-04-02 23:17:14 +00:00
|
|
|
|
2010-04-16 22:42:17 +00:00
|
|
|
bool CGPassManager::RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,
|
2010-04-21 00:47:40 +00:00
|
|
|
CallGraph &CG, bool &CallGraphUpToDate,
|
|
|
|
bool &DevirtualizedCall) {
|
2009-08-31 06:01:21 +00:00
|
|
|
bool Changed = false;
|
2010-01-22 05:46:59 +00:00
|
|
|
PMDataManager *PM = P->getAsPMDataManager();
|
|
|
|
|
|
|
|
if (PM == 0) {
|
|
|
|
CallGraphSCCPass *CGSP = (CallGraphSCCPass*)P;
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
if (!CallGraphUpToDate) {
|
2010-04-21 00:47:40 +00:00
|
|
|
DevirtualizedCall |= RefreshCallGraph(CurSCC, CG, false);
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
CallGraphUpToDate = true;
|
|
|
|
}
|
2009-09-01 20:33:43 +00:00
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
{
|
|
|
|
TimeRegion PassTimer(getPassTimer(CGSP));
|
|
|
|
Changed = CGSP->runOnSCC(CurSCC);
|
|
|
|
}
|
2009-09-01 18:32:03 +00:00
|
|
|
|
|
|
|
// After the CGSCCPass is done, when assertions are enabled, use
|
|
|
|
// RefreshCallGraph to verify that the callgraph was correctly updated.
|
|
|
|
#ifndef NDEBUG
|
|
|
|
if (Changed)
|
|
|
|
RefreshCallGraph(CurSCC, CG, true);
|
|
|
|
#endif
|
|
|
|
|
2009-08-31 06:01:21 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2010-01-22 05:46:59 +00:00
|
|
|
|
|
|
|
assert(PM->getPassManagerType() == PMT_FunctionPassManager &&
|
|
|
|
"Invalid CGPassManager member");
|
|
|
|
FPPassManager *FPP = (FPPassManager*)P;
|
2009-08-31 06:01:21 +00:00
|
|
|
|
|
|
|
// Run pass P on all functions in the current SCC.
|
2010-04-16 22:42:17 +00:00
|
|
|
for (CallGraphSCC::iterator I = CurSCC.begin(), E = CurSCC.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (Function *F = (*I)->getFunction()) {
|
2009-08-31 06:01:21 +00:00
|
|
|
dumpPassInfo(P, EXECUTION_MSG, ON_FUNCTION_MSG, F->getName());
|
2010-03-30 04:03:22 +00:00
|
|
|
TimeRegion PassTimer(getPassTimer(FPP));
|
2009-08-31 06:01:21 +00:00
|
|
|
Changed |= FPP->runOnFunction(*F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-31 17:08:30 +00:00
|
|
|
// The function pass(es) modified the IR, they may have clobbered the
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
// callgraph.
|
|
|
|
if (Changed && CallGraphUpToDate) {
|
2009-12-23 20:10:59 +00:00
|
|
|
DEBUG(dbgs() << "CGSCCPASSMGR: Pass Dirtied SCC: "
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
<< P->getPassName() << '\n');
|
|
|
|
CallGraphUpToDate = false;
|
|
|
|
}
|
2009-08-31 06:01:21 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-09-01 18:32:03 +00:00
|
|
|
|
|
|
|
/// RefreshCallGraph - Scan the functions in the specified CFG and resync the
|
|
|
|
/// callgraph with the call sites found in it. This is used after
|
|
|
|
/// FunctionPasses have potentially munged the callgraph, and can be used after
|
|
|
|
/// CallGraphSCC passes to verify that they correctly updated the callgraph.
|
|
|
|
///
|
2010-04-21 00:47:40 +00:00
|
|
|
/// This function returns true if it devirtualized an existing function call,
|
|
|
|
/// meaning it turned an indirect call into a direct call. This happens when
|
|
|
|
/// a function pass like GVN optimizes away stuff feeding the indirect call.
|
|
|
|
/// This never happens in checking mode.
|
|
|
|
///
|
|
|
|
bool CGPassManager::RefreshCallGraph(CallGraphSCC &CurSCC,
|
2009-09-01 18:32:03 +00:00
|
|
|
CallGraph &CG, bool CheckingMode) {
|
2009-09-01 06:31:31 +00:00
|
|
|
DenseMap<Value*, CallGraphNode*> CallSites;
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
|
2009-12-23 20:10:59 +00:00
|
|
|
DEBUG(dbgs() << "CGSCCPASSMGR: Refreshing SCC with " << CurSCC.size()
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
<< " nodes:\n";
|
2010-04-16 22:42:17 +00:00
|
|
|
for (CallGraphSCC::iterator I = CurSCC.begin(), E = CurSCC.end();
|
|
|
|
I != E; ++I)
|
|
|
|
(*I)->dump();
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
bool MadeChange = false;
|
2010-04-21 00:47:40 +00:00
|
|
|
bool DevirtualizedCall = false;
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
|
|
|
|
// Scan all functions in the SCC.
|
2010-04-16 22:42:17 +00:00
|
|
|
unsigned FunctionNo = 0;
|
|
|
|
for (CallGraphSCC::iterator SCCIdx = CurSCC.begin(), E = CurSCC.end();
|
|
|
|
SCCIdx != E; ++SCCIdx, ++FunctionNo) {
|
|
|
|
CallGraphNode *CGN = *SCCIdx;
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
Function *F = CGN->getFunction();
|
|
|
|
if (F == 0 || F->isDeclaration()) continue;
|
|
|
|
|
|
|
|
// Walk the function body looking for call sites. Sync up the call sites in
|
|
|
|
// CGN with those actually in the function.
|
2010-05-01 06:38:43 +00:00
|
|
|
|
|
|
|
// Keep track of the number of direct and indirect calls that were
|
|
|
|
// invalidated and removed.
|
|
|
|
unsigned NumDirectRemoved = 0, NumIndirectRemoved = 0;
|
2009-09-01 18:13:40 +00:00
|
|
|
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
// Get the set of call sites currently in the function.
|
2009-09-02 03:48:41 +00:00
|
|
|
for (CallGraphNode::iterator I = CGN->begin(), E = CGN->end(); I != E; ) {
|
2009-09-01 06:31:31 +00:00
|
|
|
// If this call site is null, then the function pass deleted the call
|
2009-09-01 18:13:40 +00:00
|
|
|
// entirely and the WeakVH nulled it out.
|
2009-09-01 06:31:31 +00:00
|
|
|
if (I->first == 0 ||
|
|
|
|
// If we've already seen this call site, then the FunctionPass RAUW'd
|
|
|
|
// one call with another, which resulted in two "uses" in the edge
|
|
|
|
// list of the same call.
|
|
|
|
CallSites.count(I->first) ||
|
|
|
|
|
|
|
|
// If the call edge is not from a call or invoke, then the function
|
|
|
|
// pass RAUW'd a call with another value. This can happen when
|
|
|
|
// constant folding happens of well known functions etc.
|
2010-07-28 12:35:54 +00:00
|
|
|
!CallSite(I->first)) {
|
2009-09-01 18:32:03 +00:00
|
|
|
assert(!CheckingMode &&
|
|
|
|
"CallGraphSCCPass did not update the CallGraph correctly!");
|
|
|
|
|
2010-05-01 06:38:43 +00:00
|
|
|
// If this was an indirect call site, count it.
|
|
|
|
if (I->second->getFunction() == 0)
|
|
|
|
++NumIndirectRemoved;
|
|
|
|
else
|
|
|
|
++NumDirectRemoved;
|
|
|
|
|
2009-09-02 04:39:04 +00:00
|
|
|
// Just remove the edge from the set of callees, keep track of whether
|
|
|
|
// I points to the last element of the vector.
|
|
|
|
bool WasLast = I + 1 == E;
|
2009-09-01 06:31:31 +00:00
|
|
|
CGN->removeCallEdge(I);
|
2009-09-02 04:34:06 +00:00
|
|
|
|
2009-09-02 04:39:04 +00:00
|
|
|
// If I pointed to the last element of the vector, we have to bail out:
|
|
|
|
// iterator checking rejects comparisons of the resultant pointer with
|
|
|
|
// end.
|
|
|
|
if (WasLast)
|
|
|
|
break;
|
2009-09-01 06:31:31 +00:00
|
|
|
E = CGN->end();
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-01 18:13:40 +00:00
|
|
|
|
2009-09-01 06:31:31 +00:00
|
|
|
assert(!CallSites.count(I->first) &&
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
"Call site occurs in node multiple times");
|
2009-09-01 06:31:31 +00:00
|
|
|
CallSites.insert(std::make_pair(I->first, I->second));
|
2009-09-01 18:13:40 +00:00
|
|
|
++I;
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
}
|
2009-09-01 18:13:40 +00:00
|
|
|
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
// Loop over all of the instructions in the function, getting the callsites.
|
2010-05-01 06:38:43 +00:00
|
|
|
// Keep track of the number of direct/indirect calls added.
|
|
|
|
unsigned NumDirectAdded = 0, NumIndirectAdded = 0;
|
|
|
|
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
|
|
|
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
|
2011-06-09 19:46:27 +00:00
|
|
|
CallSite CS(cast<Value>(I));
|
2012-06-29 17:49:32 +00:00
|
|
|
if (!CS) continue;
|
|
|
|
Function *Callee = CS.getCalledFunction();
|
|
|
|
if (Callee && Callee->isIntrinsic()) continue;
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
|
|
|
|
// If this call site already existed in the callgraph, just verify it
|
|
|
|
// matches up to expectations and remove it from CallSites.
|
2009-09-01 06:31:31 +00:00
|
|
|
DenseMap<Value*, CallGraphNode*>::iterator ExistingIt =
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
CallSites.find(CS.getInstruction());
|
|
|
|
if (ExistingIt != CallSites.end()) {
|
|
|
|
CallGraphNode *ExistingNode = ExistingIt->second;
|
|
|
|
|
|
|
|
// Remove from CallSites since we have now seen it.
|
|
|
|
CallSites.erase(ExistingIt);
|
|
|
|
|
|
|
|
// Verify that the callee is right.
|
|
|
|
if (ExistingNode->getFunction() == CS.getCalledFunction())
|
|
|
|
continue;
|
|
|
|
|
2009-09-01 18:32:03 +00:00
|
|
|
// If we are in checking mode, we are not allowed to actually mutate
|
|
|
|
// the callgraph. If this is a case where we can infer that the
|
|
|
|
// callgraph is less precise than it could be (e.g. an indirect call
|
|
|
|
// site could be turned direct), don't reject it in checking mode, and
|
|
|
|
// don't tweak it to be more precise.
|
|
|
|
if (CheckingMode && CS.getCalledFunction() &&
|
|
|
|
ExistingNode->getFunction() == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert(!CheckingMode &&
|
|
|
|
"CallGraphSCCPass did not update the CallGraph correctly!");
|
|
|
|
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
// If not, we either went from a direct call to indirect, indirect to
|
|
|
|
// direct, or direct to different direct.
|
|
|
|
CallGraphNode *CalleeNode;
|
2010-04-21 00:47:40 +00:00
|
|
|
if (Function *Callee = CS.getCalledFunction()) {
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
CalleeNode = CG.getOrInsertFunction(Callee);
|
2010-04-21 00:47:40 +00:00
|
|
|
// Keep track of whether we turned an indirect call into a direct
|
|
|
|
// one.
|
|
|
|
if (ExistingNode->getFunction() == 0) {
|
|
|
|
DevirtualizedCall = true;
|
|
|
|
DEBUG(dbgs() << " CGSCCPASSMGR: Devirtualized call to '"
|
|
|
|
<< Callee->getName() << "'\n");
|
|
|
|
}
|
|
|
|
} else {
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
CalleeNode = CG.getCallsExternalNode();
|
2010-04-21 00:47:40 +00:00
|
|
|
}
|
2009-09-01 20:33:43 +00:00
|
|
|
|
|
|
|
// Update the edge target in CGN.
|
2010-04-22 20:42:33 +00:00
|
|
|
CGN->replaceCallEdge(CS, CS, CalleeNode);
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
MadeChange = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-09-01 18:32:03 +00:00
|
|
|
assert(!CheckingMode &&
|
|
|
|
"CallGraphSCCPass did not update the CallGraph correctly!");
|
|
|
|
|
2010-05-01 06:38:43 +00:00
|
|
|
// If the call site didn't exist in the CGN yet, add it.
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
CallGraphNode *CalleeNode;
|
2010-05-01 06:38:43 +00:00
|
|
|
if (Function *Callee = CS.getCalledFunction()) {
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
CalleeNode = CG.getOrInsertFunction(Callee);
|
2010-05-01 06:38:43 +00:00
|
|
|
++NumDirectAdded;
|
|
|
|
} else {
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
CalleeNode = CG.getCallsExternalNode();
|
2010-05-01 06:38:43 +00:00
|
|
|
++NumIndirectAdded;
|
|
|
|
}
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
|
|
|
|
CGN->addCalledFunction(CS, CalleeNode);
|
|
|
|
MadeChange = true;
|
|
|
|
}
|
|
|
|
|
2010-05-01 06:38:43 +00:00
|
|
|
// We scanned the old callgraph node, removing invalidated call sites and
|
|
|
|
// then added back newly found call sites. One thing that can happen is
|
|
|
|
// that an old indirect call site was deleted and replaced with a new direct
|
|
|
|
// call. In this case, we have devirtualized a call, and CGSCCPM would like
|
|
|
|
// to iteratively optimize the new code. Unfortunately, we don't really
|
|
|
|
// have a great way to detect when this happens. As an approximation, we
|
|
|
|
// just look at whether the number of indirect calls is reduced and the
|
|
|
|
// number of direct calls is increased. There are tons of ways to fool this
|
|
|
|
// (e.g. DCE'ing an indirect call and duplicating an unrelated block with a
|
|
|
|
// direct call) but this is close enough.
|
|
|
|
if (NumIndirectRemoved > NumIndirectAdded &&
|
|
|
|
NumDirectRemoved < NumDirectAdded)
|
|
|
|
DevirtualizedCall = true;
|
|
|
|
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
// After scanning this function, if we still have entries in callsites, then
|
2009-09-01 06:31:31 +00:00
|
|
|
// they are dangling pointers. WeakVH should save us for this, so abort if
|
|
|
|
// this happens.
|
|
|
|
assert(CallSites.empty() && "Dangling pointers found in call sites map");
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
|
2009-09-01 06:31:31 +00:00
|
|
|
// Periodically do an explicit clear to remove tombstones when processing
|
|
|
|
// large scc's.
|
2010-04-16 22:42:17 +00:00
|
|
|
if ((FunctionNo & 15) == 15)
|
2009-09-01 06:31:31 +00:00
|
|
|
CallSites.clear();
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG(if (MadeChange) {
|
2009-12-23 20:10:59 +00:00
|
|
|
dbgs() << "CGSCCPASSMGR: Refreshed SCC is now:\n";
|
2010-04-16 22:42:17 +00:00
|
|
|
for (CallGraphSCC::iterator I = CurSCC.begin(), E = CurSCC.end();
|
|
|
|
I != E; ++I)
|
|
|
|
(*I)->dump();
|
2010-05-01 06:38:43 +00:00
|
|
|
if (DevirtualizedCall)
|
|
|
|
dbgs() << "CGSCCPASSMGR: Refresh devirtualized a call!\n";
|
|
|
|
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
} else {
|
2009-12-23 20:10:59 +00:00
|
|
|
dbgs() << "CGSCCPASSMGR: SCC Refresh didn't change call graph.\n";
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
}
|
|
|
|
);
|
2011-08-12 14:54:45 +00:00
|
|
|
(void)MadeChange;
|
2010-04-21 00:47:40 +00:00
|
|
|
|
|
|
|
return DevirtualizedCall;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// RunAllPassesOnSCC - Execute the body of the entire pass manager on the
|
|
|
|
/// specified SCC. This keeps track of whether a function pass devirtualizes
|
|
|
|
/// any calls and returns it in DevirtualizedCall.
|
|
|
|
bool CGPassManager::RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,
|
|
|
|
bool &DevirtualizedCall) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
// CallGraphUpToDate - Keep track of whether the callgraph is known to be
|
|
|
|
// up-to-date or not. The CGSSC pass manager runs two types of passes:
|
|
|
|
// CallGraphSCC Passes and other random function passes. Because other
|
|
|
|
// random function passes are not CallGraph aware, they may clobber the
|
|
|
|
// call graph by introducing new calls or deleting other ones. This flag
|
|
|
|
// is set to false when we run a function pass so that we know to clean up
|
|
|
|
// the callgraph when we need to run a CGSCCPass again.
|
|
|
|
bool CallGraphUpToDate = true;
|
|
|
|
|
|
|
|
// Run all passes on current SCC.
|
|
|
|
for (unsigned PassNo = 0, e = getNumContainedPasses();
|
|
|
|
PassNo != e; ++PassNo) {
|
|
|
|
Pass *P = getContainedPass(PassNo);
|
|
|
|
|
|
|
|
// If we're in -debug-pass=Executions mode, construct the SCC node list,
|
|
|
|
// otherwise avoid constructing this string as it is expensive.
|
|
|
|
if (isPassDebuggingExecutionsOrMore()) {
|
|
|
|
std::string Functions;
|
|
|
|
#ifndef NDEBUG
|
|
|
|
raw_string_ostream OS(Functions);
|
|
|
|
for (CallGraphSCC::iterator I = CurSCC.begin(), E = CurSCC.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (I != CurSCC.begin()) OS << ", ";
|
|
|
|
(*I)->print(OS);
|
|
|
|
}
|
|
|
|
OS.flush();
|
|
|
|
#endif
|
|
|
|
dumpPassInfo(P, EXECUTION_MSG, ON_CG_MSG, Functions);
|
|
|
|
}
|
|
|
|
dumpRequiredSet(P);
|
|
|
|
|
|
|
|
initializeAnalysisImpl(P);
|
|
|
|
|
|
|
|
// Actually run this pass on the current SCC.
|
|
|
|
Changed |= RunPassOnSCC(P, CurSCC, CG,
|
|
|
|
CallGraphUpToDate, DevirtualizedCall);
|
|
|
|
|
|
|
|
if (Changed)
|
|
|
|
dumpPassInfo(P, MODIFICATION_MSG, ON_CG_MSG, "");
|
|
|
|
dumpPreservedSet(P);
|
|
|
|
|
|
|
|
verifyPreservedAnalysis(P);
|
|
|
|
removeNotPreservedAnalysis(P);
|
|
|
|
recordAvailableAnalysis(P);
|
|
|
|
removeDeadPasses(P, "", ON_CG_MSG);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the callgraph was left out of date (because the last pass run was a
|
|
|
|
// functionpass), refresh it before we move on to the next SCC.
|
|
|
|
if (!CallGraphUpToDate)
|
|
|
|
DevirtualizedCall |= RefreshCallGraph(CurSCC, CG, false);
|
|
|
|
return Changed;
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
}
|
2009-08-31 06:01:21 +00:00
|
|
|
|
2007-01-17 21:45:01 +00:00
|
|
|
/// run - Execute all of the passes scheduled for execution. Keep track of
|
|
|
|
/// whether any of the passes modifies the module, and if so, return true.
|
|
|
|
bool CGPassManager::runOnModule(Module &M) {
|
|
|
|
CallGraph &CG = getAnalysis<CallGraph>();
|
2009-02-11 18:19:24 +00:00
|
|
|
bool Changed = doInitialization(CG);
|
2010-04-21 00:47:40 +00:00
|
|
|
|
2009-08-31 06:01:21 +00:00
|
|
|
// Walk the callgraph in bottom-up SCC order.
|
2010-04-16 22:59:24 +00:00
|
|
|
scc_iterator<CallGraph*> CGI = scc_begin(&CG);
|
|
|
|
|
|
|
|
CallGraphSCC CurSCC(&CGI);
|
|
|
|
while (!CGI.isAtEnd()) {
|
2009-08-31 00:19:58 +00:00
|
|
|
// Copy the current SCC and increment past it so that the pass can hack
|
|
|
|
// on the SCC if it wants to without invalidating our iterator.
|
2010-04-16 22:42:17 +00:00
|
|
|
std::vector<CallGraphNode*> &NodeVec = *CGI;
|
|
|
|
CurSCC.initialize(&NodeVec[0], &NodeVec[0]+NodeVec.size());
|
2009-08-31 00:19:58 +00:00
|
|
|
++CGI;
|
|
|
|
|
2010-04-21 00:47:40 +00:00
|
|
|
// At the top level, we run all the passes in this pass manager on the
|
|
|
|
// functions in this SCC. However, we support iterative compilation in the
|
|
|
|
// case where a function pass devirtualizes a call to a function. For
|
|
|
|
// example, it is very common for a function pass (often GVN or instcombine)
|
|
|
|
// to eliminate the addressing that feeds into a call. With that improved
|
|
|
|
// information, we would like the call to be an inline candidate, infer
|
|
|
|
// mod-ref information etc.
|
|
|
|
//
|
|
|
|
// Because of this, we allow iteration up to a specified iteration count.
|
|
|
|
// This only happens in the case of a devirtualized call, so we only burn
|
|
|
|
// compile time in the case that we're making progress. We also have a hard
|
|
|
|
// iteration count limit in case there is crazy code.
|
|
|
|
unsigned Iteration = 0;
|
|
|
|
bool DevirtualizedCall = false;
|
|
|
|
do {
|
2010-04-22 20:42:33 +00:00
|
|
|
DEBUG(if (Iteration)
|
|
|
|
dbgs() << " SCCPASSMGR: Re-visiting SCC, iteration #"
|
|
|
|
<< Iteration << '\n');
|
2010-04-21 00:47:40 +00:00
|
|
|
DevirtualizedCall = false;
|
|
|
|
Changed |= RunAllPassesOnSCC(CurSCC, CG, DevirtualizedCall);
|
|
|
|
} while (Iteration++ < MaxIterations && DevirtualizedCall);
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
|
2010-04-21 00:47:40 +00:00
|
|
|
if (DevirtualizedCall)
|
|
|
|
DEBUG(dbgs() << " CGSCCPASSMGR: Stopped iteration after " << Iteration
|
|
|
|
<< " times, due to -max-cg-scc-iterations\n");
|
|
|
|
|
|
|
|
if (Iteration > MaxSCCIterations)
|
|
|
|
MaxSCCIterations = Iteration;
|
Step #1 to giving Callgraph some sane invariants. The problems with callgraph
stem from the fact that we have two types of passes that need to update it:
1. callgraphscc and module passes that are explicitly aware of it
2. Functionpasses (and loop passes etc) that are interlaced with CGSCC passes
by the CGSCC Passmgr.
In the case of #1, we can reasonably expect the passes to update the call
graph just like any analysis. However, functionpasses are not and generally
should not be CG aware. This has caused us no end of problems, so this takes
a new approach. Logically, the CGSCC Pass manager can rescan every function
after it runs a function pass over it to see if the functionpass made any
updates to the IR that affect the callgraph. This allows it to catch new calls
introduced by the functionpass.
In practice, doing this would be slow. This implementation keeps track of
whether or not the current scc is dirtied by a function pass, and, if so,
delays updating the callgraph until it is actually needed again. This was
we avoid extraneous rescans, but we still have good invariants when the
callgraph is needed.
Step #2 of the "give Callgraph some sane invariants" is to change CallGraphNode
to use a CallBackVH for the callsite entry of the CallGraphNode. This way
we can immediately remove entries from the callgraph when a FunctionPass is
active instead of having dangling pointers. The current pass tries to tolerate
these dangling pointers, but it is just an evil hack.
This is related to PR3601/4835/4029. This also reverts r80541, a hack working
around the sad lack of invariants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80566 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 07:23:46 +00:00
|
|
|
|
2007-01-17 21:45:01 +00:00
|
|
|
}
|
2009-02-11 18:19:24 +00:00
|
|
|
Changed |= doFinalization(CG);
|
2007-01-17 21:45:01 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2010-04-21 00:47:40 +00:00
|
|
|
|
2007-01-17 21:45:01 +00:00
|
|
|
/// Initialize CG
|
2009-02-11 18:19:24 +00:00
|
|
|
bool CGPassManager::doInitialization(CallGraph &CG) {
|
2007-01-17 21:45:01 +00:00
|
|
|
bool Changed = false;
|
2010-01-22 05:46:59 +00:00
|
|
|
for (unsigned i = 0, e = getNumContainedPasses(); i != e; ++i) {
|
|
|
|
if (PMDataManager *PM = getContainedPass(i)->getAsPMDataManager()) {
|
|
|
|
assert(PM->getPassManagerType() == PMT_FunctionPassManager &&
|
|
|
|
"Invalid CGPassManager member");
|
|
|
|
Changed |= ((FPPassManager*)PM)->doInitialization(CG.getModule());
|
2009-02-13 07:15:53 +00:00
|
|
|
} else {
|
2010-01-22 05:46:59 +00:00
|
|
|
Changed |= ((CallGraphSCCPass*)getContainedPass(i))->doInitialization(CG);
|
2009-02-13 07:15:53 +00:00
|
|
|
}
|
2007-01-17 21:45:01 +00:00
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Finalize CG
|
2009-02-11 18:19:24 +00:00
|
|
|
bool CGPassManager::doFinalization(CallGraph &CG) {
|
2007-01-17 21:45:01 +00:00
|
|
|
bool Changed = false;
|
2010-01-22 05:46:59 +00:00
|
|
|
for (unsigned i = 0, e = getNumContainedPasses(); i != e; ++i) {
|
|
|
|
if (PMDataManager *PM = getContainedPass(i)->getAsPMDataManager()) {
|
|
|
|
assert(PM->getPassManagerType() == PMT_FunctionPassManager &&
|
|
|
|
"Invalid CGPassManager member");
|
|
|
|
Changed |= ((FPPassManager*)PM)->doFinalization(CG.getModule());
|
2009-02-13 07:15:53 +00:00
|
|
|
} else {
|
2010-01-22 05:46:59 +00:00
|
|
|
Changed |= ((CallGraphSCCPass*)getContainedPass(i))->doFinalization(CG);
|
2009-02-13 07:15:53 +00:00
|
|
|
}
|
2007-01-17 21:45:01 +00:00
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2010-04-16 22:42:17 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CallGraphSCC Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-04-16 22:59:24 +00:00
|
|
|
/// ReplaceNode - This informs the SCC and the pass manager that the specified
|
|
|
|
/// Old node has been deleted, and New is to be used in its place.
|
|
|
|
void CallGraphSCC::ReplaceNode(CallGraphNode *Old, CallGraphNode *New) {
|
|
|
|
assert(Old != New && "Should not replace node with self");
|
|
|
|
for (unsigned i = 0; ; ++i) {
|
|
|
|
assert(i != Nodes.size() && "Node not in SCC");
|
|
|
|
if (Nodes[i] != Old) continue;
|
|
|
|
Nodes[i] = New;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-16 23:04:30 +00:00
|
|
|
|
|
|
|
// Update the active scc_iterator so that it doesn't contain dangling
|
|
|
|
// pointers to the old CallGraphNode.
|
|
|
|
scc_iterator<CallGraph*> *CGI = (scc_iterator<CallGraph*>*)Context;
|
|
|
|
CGI->ReplaceNode(Old, New);
|
2010-04-16 22:59:24 +00:00
|
|
|
}
|
2010-04-16 22:42:17 +00:00
|
|
|
|
|
|
|
|
2010-04-16 21:43:55 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CallGraphSCCPass Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-04-02 23:17:14 +00:00
|
|
|
|
2007-01-23 21:55:17 +00:00
|
|
|
/// Assign pass manager to manage this pass.
|
2007-01-23 21:52:35 +00:00
|
|
|
void CallGraphSCCPass::assignPassManager(PMStack &PMS,
|
2007-04-16 18:10:23 +00:00
|
|
|
PassManagerType PreferredType) {
|
2007-01-23 21:52:35 +00:00
|
|
|
// Find CGPassManager
|
2007-07-19 09:42:01 +00:00
|
|
|
while (!PMS.empty() &&
|
|
|
|
PMS.top()->getPassManagerType() > PMT_CallGraphPassManager)
|
|
|
|
PMS.pop();
|
2007-01-23 21:52:35 +00:00
|
|
|
|
2010-01-22 05:37:10 +00:00
|
|
|
assert(!PMS.empty() && "Unable to handle Call Graph Pass");
|
|
|
|
CGPassManager *CGP;
|
|
|
|
|
|
|
|
if (PMS.top()->getPassManagerType() == PMT_CallGraphPassManager)
|
|
|
|
CGP = (CGPassManager*)PMS.top();
|
|
|
|
else {
|
|
|
|
// Create new Call Graph SCC Pass Manager if it does not exist.
|
|
|
|
assert(!PMS.empty() && "Unable to create Call Graph Pass Manager");
|
2007-01-23 21:52:35 +00:00
|
|
|
PMDataManager *PMD = PMS.top();
|
|
|
|
|
|
|
|
// [1] Create new Call Graph Pass Manager
|
2011-08-29 17:07:00 +00:00
|
|
|
CGP = new CGPassManager();
|
2007-01-23 21:52:35 +00:00
|
|
|
|
|
|
|
// [2] Set up new manager's top level manager
|
|
|
|
PMTopLevelManager *TPM = PMD->getTopLevelManager();
|
|
|
|
TPM->addIndirectPassManager(CGP);
|
|
|
|
|
|
|
|
// [3] Assign manager to manage this new manager. This may create
|
|
|
|
// and push new managers into PMS
|
2010-01-22 05:37:10 +00:00
|
|
|
Pass *P = CGP;
|
2007-06-21 22:29:02 +00:00
|
|
|
TPM->schedulePass(P);
|
2007-01-23 21:52:35 +00:00
|
|
|
|
|
|
|
// [4] Push new manager into PMS
|
|
|
|
PMS.push(CGP);
|
|
|
|
}
|
|
|
|
|
|
|
|
CGP->add(this);
|
|
|
|
}
|
|
|
|
|
2003-08-31 01:54:59 +00:00
|
|
|
/// getAnalysisUsage - For this class, we declare that we require and preserve
|
|
|
|
/// the call graph. If the derived class implements this method, it should
|
|
|
|
/// always explicitly call the implementation here.
|
|
|
|
void CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequired<CallGraph>();
|
|
|
|
AU.addPreserved<CallGraph>();
|
|
|
|
}
|
2010-04-16 21:43:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PrintCallGraphPass Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
/// PrintCallGraphPass - Print a Module corresponding to a call graph.
|
|
|
|
///
|
|
|
|
class PrintCallGraphPass : public CallGraphSCCPass {
|
|
|
|
std::string Banner;
|
|
|
|
raw_ostream &Out; // raw_ostream to print on.
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
PrintCallGraphPass(const std::string &B, raw_ostream &o)
|
2010-08-06 18:33:48 +00:00
|
|
|
: CallGraphSCCPass(ID), Banner(B), Out(o) {}
|
2010-04-16 21:43:55 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2010-04-16 22:42:17 +00:00
|
|
|
bool runOnSCC(CallGraphSCC &SCC) {
|
2010-04-16 21:43:55 +00:00
|
|
|
Out << Banner;
|
2010-04-16 22:42:17 +00:00
|
|
|
for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I)
|
|
|
|
(*I)->getFunction()->print(Out);
|
2010-04-16 21:43:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace.
|
|
|
|
|
|
|
|
char PrintCallGraphPass::ID = 0;
|
|
|
|
|
|
|
|
Pass *CallGraphSCCPass::createPrinterPass(raw_ostream &O,
|
|
|
|
const std::string &Banner) const {
|
|
|
|
return new PrintCallGraphPass(Banner, O);
|
|
|
|
}
|
|
|
|
|