35 #define DEBUG_NAME "compiler2/PassDependencyGraphPrinter"
43 struct AddEdge :
public std::unary_function<PassInfo::IDTy,void> {
44 typedef std::pair<argument_type,argument_type> EdgeType;
46 alloc::set<EdgeType>::type &
set;
50 AddEdge(std::set<EdgeType> &
edges, alloc::set<EdgeType>::type &
set, argument_type
from,
bool reverse=
false)
53 void operator()(
const argument_type &to) {
56 edge = std::make_pair(to,
from);
59 edge = std::make_pair(
from,to);
66 template <
class InputIterator,
class ValueType>
67 inline bool contains(InputIterator begin, InputIterator end,
const ValueType &val) {
68 return std::find(begin,end,val) != end;
71 class PassDependencyGraphPrinter :
public PrintableGraph<PassManager,PassInfo::IDTy> {
73 alloc::map<PassInfo::IDTy,const char*>::type
names;
74 alloc::set<EdgeType>::type
req;
75 alloc::set<EdgeType>::type
mod;
76 alloc::set<EdgeType>::type
dstr;
82 PassDependencyGraphPrinter(PassManager &PM) {
84 e = PM.registered_end();
i !=
e; ++
i) {
86 names[PI] =
i->second->get_name();
87 nodes.insert(
i->first);
89 LOG(
"Pass: " <<
i->second->get_name() <<
" ID: " << PI <<
nl);
92 Pass *pass =
i->second->create_Pass();
94 pass->get_PassUsage(PU);
96 std::for_each(PU.requires_begin(), PU.requires_end(),AddEdge(
edges,
req,PI));
97 std::for_each(PU.modifies_begin(), PU.modifies_end(),AddEdge(
edges,
mod,PI));
98 std::for_each(PU.destroys_begin(), PU.destroys_end(),AddEdge(
edges,
dstr,PI));
99 std::for_each(PU.schedule_after_begin(), PU.schedule_after_end(),AddEdge(
edges,
schedule_after,PI));
100 std::for_each(PU.run_before_begin(), PU.run_before_end(),AddEdge(
edges,
run_before,PI,
true));
101 std::for_each(PU.schedule_before_begin(), PU.schedule_before_end(),AddEdge(
edges,
schedule_before,PI,
true));
105 virtual OStream& getGraphName(OStream&
OS)
const {
106 return OS <<
"PassDependencyGraph";
109 virtual OStream& getNodeLabel(OStream&
OS,
const PassInfo::IDTy &node)
const {
110 return OS <<
names.find(node)->second;
112 virtual OStream& getEdgeLabel(OStream& OS,
const EdgeType &edge)
const {
113 if (contains(
req.begin(),
req.end(),edge)) OS <<
"r";
114 if (contains(
mod.begin(),
mod.end(),edge)) OS <<
"m";
115 if (contains(
dstr.begin(),
dstr.end(),edge)) OS <<
"d";
alloc::set< EdgeType >::type run_before
alloc::set< EdgeType >::type req
static void print(const char *filename, const PrintableGraphTy &G)
void print_PassDependencyGraph(PassManager &PM)
alloc::set< EdgeType >::type mod
_Base::const_iterator const_iterator
alloc::set< EdgeType >::type schedule_after
alloc::set< EdgeType >::type & set
std::set< EdgeType > & edges
alloc::set< EdgeType >::type dstr
Manage the execution of compiler passes.
#define LOG(STMT)
Analogous to DEBUG.
alloc::map< PassInfo::IDTy, const char * >::type names
alloc::set< EdgeType >::type schedule_before