2003-08-31 01:54:59 +00:00
|
|
|
//===- CallGraphSCCPass.h - Pass that operates BU on call graph -*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-08-31 01:54:59 +00:00
|
|
|
//
|
|
|
|
// This file defines 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.
|
|
|
|
//
|
|
|
|
// These passes are inherently interprocedural, and are required to keep the
|
|
|
|
// call graph up-to-date if they do anything which could modify it.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CALL_GRAPH_SCC_PASS_H
|
|
|
|
#define LLVM_CALL_GRAPH_SCC_PASS_H
|
|
|
|
|
|
|
|
#include "llvm/Pass.h"
|
2009-07-16 18:04:31 +00:00
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
2003-08-31 01:54:59 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2003-08-31 01:54:59 +00:00
|
|
|
class CallGraphNode;
|
2004-04-20 21:52:07 +00:00
|
|
|
class CallGraph;
|
2007-01-23 21:52:35 +00:00
|
|
|
class PMStack;
|
2010-04-16 22:42:17 +00:00
|
|
|
class CallGraphSCC;
|
|
|
|
|
|
|
|
class CallGraphSCCPass : public Pass {
|
|
|
|
public:
|
2010-08-06 00:23:35 +00:00
|
|
|
explicit CallGraphSCCPass(intptr_t pid) : Pass(PT_CallGraphSCC, pid) {}
|
|
|
|
explicit CallGraphSCCPass(void *pid) : Pass(PT_CallGraphSCC, pid) {}
|
2007-05-01 21:15:47 +00:00
|
|
|
|
2010-04-02 23:17:14 +00:00
|
|
|
/// createPrinterPass - Get a pass that prints the Module
|
|
|
|
/// corresponding to a CallGraph.
|
|
|
|
Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const;
|
|
|
|
|
2004-04-20 21:30:06 +00:00
|
|
|
/// doInitialization - This method is called before the SCC's of the program
|
|
|
|
/// has been processed, allowing the pass to do initialization as necessary.
|
2004-04-20 21:52:07 +00:00
|
|
|
virtual bool doInitialization(CallGraph &CG) {
|
2004-04-20 21:30:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-08-31 01:54:59 +00:00
|
|
|
/// runOnSCC - This method should be implemented by the subclass to perform
|
|
|
|
/// whatever action is necessary for the specified SCC. Note that
|
|
|
|
/// non-recursive (or only self-recursive) functions will have an SCC size of
|
|
|
|
/// 1, where recursive portions of the call graph will have SCC size > 1.
|
|
|
|
///
|
2009-08-31 00:19:58 +00:00
|
|
|
/// SCC passes that add or delete functions to the SCC are required to update
|
|
|
|
/// the SCC list, otherwise stale pointers may be dereferenced.
|
|
|
|
///
|
2010-04-16 22:42:17 +00:00
|
|
|
virtual bool runOnSCC(CallGraphSCC &SCC) = 0;
|
2003-08-31 01:54:59 +00:00
|
|
|
|
2004-04-20 21:30:06 +00:00
|
|
|
/// doFinalization - This method is called after the SCC's of the program has
|
|
|
|
/// been processed, allowing the pass to do final cleanup as necessary.
|
2004-04-20 21:52:07 +00:00
|
|
|
virtual bool doFinalization(CallGraph &CG) {
|
2004-04-20 21:30:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-01-23 21:52:35 +00:00
|
|
|
/// Assign pass manager to manager this pass
|
|
|
|
virtual void assignPassManager(PMStack &PMS,
|
2010-04-16 22:42:17 +00:00
|
|
|
PassManagerType PMT =PMT_CallGraphPassManager);
|
2003-08-31 01:54:59 +00:00
|
|
|
|
2007-04-16 18:51:25 +00:00
|
|
|
/// Return what kind of Pass Manager can manage this pass.
|
|
|
|
virtual PassManagerType getPotentialPassManagerType() const {
|
|
|
|
return PMT_CallGraphPassManager;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &Info) const;
|
|
|
|
};
|
|
|
|
|
2010-04-16 22:42:17 +00:00
|
|
|
/// CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
|
|
|
|
class CallGraphSCC {
|
|
|
|
void *Context; // The CGPassManager object that is vending this.
|
|
|
|
std::vector<CallGraphNode*> Nodes;
|
|
|
|
public:
|
|
|
|
CallGraphSCC(void *context) : Context(context) {}
|
|
|
|
|
|
|
|
void initialize(CallGraphNode*const*I, CallGraphNode*const*E) {
|
|
|
|
Nodes.assign(I, E);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSingular() const { return Nodes.size() == 1; }
|
|
|
|
unsigned size() const { return Nodes.size(); }
|
|
|
|
|
|
|
|
/// 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.
|
2010-04-16 22:59:24 +00:00
|
|
|
void ReplaceNode(CallGraphNode *Old, CallGraphNode *New);
|
2010-04-16 22:42:17 +00:00
|
|
|
|
|
|
|
typedef std::vector<CallGraphNode*>::const_iterator iterator;
|
|
|
|
iterator begin() const { return Nodes.begin(); }
|
|
|
|
iterator end() const { return Nodes.end(); }
|
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-08-31 01:54:59 +00:00
|
|
|
#endif
|