llir-opt
0.0.1
Low-Level Post-Link Optimiser for OCaml and C
|
7 #include <llvm/ADT/GraphTraits.h>
8 #include <llvm/ADT/PointerUnion.h>
9 #include <llvm/Support/DOTGraphTraits.h>
11 #include "core/func.h"
12 #include "core/inst.h"
13 #include "core/prog.h"
28 class iterator :
public std::iterator<std::forward_iterator_tag, const Node *> {
37 bool operator!=(
const iterator &that)
const {
return !(*
this == that); }
38 bool operator==(
const iterator &that)
const;
49 const Node *operator*()
const;
55 llvm::PointerUnion<Inst *, Func *> it_;
66 iterator
begin()
const;
67 iterator end()
const {
return iterator(); }
76 friend class iterator;
80 llvm::PointerUnion<Func *, Prog *> node_;
84 using NodeMap = std::unordered_map<const Func *, std::unique_ptr<Node>>;
90 , NodeMap::const_iterator
91 , std::random_access_iterator_tag
96 : iterator_adaptor_base(it)
100 const Node *operator*()
const {
return I->second.get(); }
101 const Node *operator->()
const {
return I->second.get(); }
118 const_node_iterator end()
const {
return const_node_iterator(nodes_.end()); }
121 friend class Node::iterator;
125 mutable NodeMap nodes_;
151 struct DOTGraphTraits<
CallGraph*> :
public DefaultDOTGraphTraits {
152 DOTGraphTraits(
bool isSimple =
false) : DefaultDOTGraphTraits(isSimple) {}
154 static std::string getNodeLabel(
159 return std::string(f->GetName());
bool IsRecursive() const
Checks if the node is a tail-recursive function.
Definition: call_graph.cpp:129
Graph traits for call graph nodes.
Definition: call_graph.h:129
Iterator over the nodes of the call graph.
Definition: call_graph.h:88
Node(const CallGraph *graph, Prog *prog)
Entry node.
Definition: call_graph.cpp:95
Definition: call_graph.h:25
Definition: call_graph.h:20
const Node * Entry() const
Returns the virtual the entry node.
Definition: call_graph.h:112
iterator()
End iterator.
Definition: call_graph.h:35
const Node * operator[](Func *f) const
Returns the node for a function.
Definition: call_graph.cpp:156
iterator begin() const
Return iterators over the callees.
Definition: call_graph.cpp:107
const_node_iterator begin() const
Iterator over nodes.
Definition: call_graph.h:117
CallGraph(Prog &p)
Creates a call graph for a program.
Definition: call_graph.cpp:142
~CallGraph()
Cleanup.
Definition: call_graph.cpp:151
Iterator over call site targets.
Definition: call_graph.h:28
Func * GetCaller() const
Returns the function, null for entry.
Definition: call_graph.cpp:123
Definition: call_graph.h:132