llir-opt
0.0.1
Low-Level Post-Link Optimiser for OCaml and C
|
9 #include <unordered_map>
10 #include <unordered_set>
12 #include <llvm/ADT/iterator_range.h>
14 #include "core/adt/hash.h"
15 #include "core/analysis/union_find.h"
37 using LoopIter = std::vector<Loop *>::iterator;
40 llvm::iterator_range<LoopIter> loops()
42 return llvm::make_range(loop_begin(), loop_end());
46 using BlockIter = std::vector<const Block *>::iterator;
49 llvm::iterator_range<BlockIter> blocks()
51 return llvm::make_range(block_begin(), block_end());
78 std::set<Loop *>::iterator
begin() {
return roots_.begin(); }
79 std::set<Loop *>::iterator end() {
return roots_.end(); }
82 void dump(llvm::raw_ostream &os = llvm::errs());
86 void FindLoop(
unsigned header);
89 bool IsCrossEdge(
unsigned a,
unsigned b);
91 bool IsTreeEdge(
unsigned a,
unsigned b);
93 bool IsForwardEdge(
unsigned a,
unsigned b);
95 bool IsBackEdge(
unsigned a,
unsigned b);
98 unsigned DFS(
const Block *block,
unsigned parent);
100 void LCA(
unsigned node);
103 void MarkIrreducibleLoops(
unsigned node);
106 void HnCA(Loop *loop, std::set<const Block *> blocks);
110 using Edge = std::pair<unsigned, unsigned>;
117 const Block *BlockPtr;
133 std::vector<unsigned> Pred;
135 std::vector<unsigned> Children;
137 std::vector<unsigned> CrossForwardCandidates;
139 std::vector<Edge> CrossForwardEdges;
146 std::vector<GraphNode> graph_;
148 std::unordered_map<const Block *, unsigned> blockToId_;
160 std::vector<bool> lcaVisited_;
162 std::vector<unsigned> lcaAncestor_;
165 std::vector<bool> irreducibleLoopHeader_;
167 std::vector<std::optional<unsigned>> loopParent_;
170 std::set<Loop *> roots_;
172 std::unordered_map<const Block *, std::unique_ptr<Loop>> blockToLoop_;
LoopNesting(const Func *func)
Builds the loop nesting forest.
Definition: loop_nesting.cpp:16
Definition: loop_nesting.h:28
std::vector< const Block * > blocks_
Nodes in the loop.
Definition: loop_nesting.h:65
void dump(llvm::raw_ostream &os=llvm::errs())
Prints the loop nesting information.
Definition: loop_nesting.cpp:245
std::vector< Loop * >::iterator LoopIter
Iterator over loop children.
Definition: loop_nesting.h:37
const Block * header_
Header of the loop.
Definition: loop_nesting.h:61
std::vector< Loop * > loops_
Loops in the loop.
Definition: loop_nesting.h:63
std::vector< const Block * >::iterator BlockIter
Iterator over loop children.
Definition: loop_nesting.h:46
Structure representing a loop.
Definition: loop_nesting.h:31
bool IsLoopEdge(const Block *a, const Block *b)
Checks if an edge is a loop edge.
Definition: loop_nesting.cpp:72
const Block * HighestAncestor(const Block *s, const Block *t)
Returns the highest non-common ancestor of s and t.
Definition: loop_nesting.cpp:90
std::set< Loop * >::iterator begin()
Iterator over the loop nesting forest.
Definition: loop_nesting.h:78
const Block * GetHeader() const
Returns the loop header.
Definition: loop_nesting.h:34
Definition: union_find.h:18