llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
scc.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include <functional>
8 #include <stack>
9 #include <vector>
10 
11 class GraphNode;
12 class Graph;
13 
14 
15 
19 class SCCSolver final {
20 public:
21  using SetIter = std::vector<std::unique_ptr<SetNode>>::iterator;
22  using Group = std::vector<GraphNode *>;
23 
24 public:
26  SCCSolver(Graph *graph);
27 
29  SCCSolver &Full();
30 
32  SCCSolver &Single(SetNode *node);
33 
35  void Solve(std::function<void(const Group &)> &&f);
36 
37 private:
39  void VisitFull(GraphNode *node);
40 
42  void VisitSingle(SetNode *node);
43 
45  void Pop(GraphNode *node);
46 
47 private:
49  Graph *graph_;
51  uint32_t epoch_;
53  uint32_t index_;
55  std::stack<GraphNode *> stack_;
57  std::vector<std::vector<GraphNode *>> sccs_;
58 };
SCCSolver::Solve
void Solve(std::function< void(const Group &)> &&f)
Traverses the groups.
Definition: scc.cpp:58
SCCSolver::SCCSolver
SCCSolver(Graph *graph)
Initialises the SCC solver.
Definition: scc.cpp:12
SCCSolver
Definition: scc.h:19
SCCSolver::Single
SCCSolver & Single(SetNode *node)
Finds SCCs in a single node.
Definition: scc.cpp:43
SetNode
Definition: node.h:116
SCCSolver::Full
SCCSolver & Full()
Finds SCCs in the whole graph.
Definition: scc.cpp:19
GraphNode
Definition: node.h:73
Graph
Definition: graph.h:23