Jlm
Loading...
Searching...
No Matches
cfg-structure.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_LLVM_IR_CFG_STRUCTURE_HPP
7#define JLM_LLVM_IR_CFG_STRUCTURE_HPP
8
12
13#include <memory>
14#include <unordered_set>
15#include <vector>
16
17namespace jlm::llvm
18{
19
20class ControlFlowGraph;
21class ControlFlowGraphEdge;
22class ControlFlowGraphNode;
23
27{
28 using constiterator = util::
29 PtrIterator<ControlFlowGraphNode, std::unordered_set<ControlFlowGraphNode *>::const_iterator>;
30
31public:
32 explicit StronglyConnectedComponent(const std::unordered_set<ControlFlowGraphNode *> & nodes)
33 : nodes_(nodes)
34 {}
35
37 begin() const;
38
40 end() const;
41
42 bool
44 {
45 return nodes_.find(node) != nodes_.end();
46 }
47
48 size_t
49 nnodes() const noexcept
50 {
51 return nodes_.size();
52 }
53
54private:
55 std::unordered_set<ControlFlowGraphNode *> nodes_{};
56};
57
70{
73
76
77public:
78 size_t
79 NumEntryNodes() const noexcept
80 {
81 return EntryNodes_.Size();
82 }
83
84 size_t
85 NumExitNodes() const noexcept
86 {
87 return ExitNodes_.Size();
88 }
89
90 size_t
91 NumEntryEdges() const noexcept
92 {
93 return EntryEdges_.Size();
94 }
95
96 size_t
97 NumRepetitionEdges() const noexcept
98 {
99 return RepetitionEdges_.Size();
100 }
101
102 size_t
103 NumExitEdges() const noexcept
104 {
105 return ExitEdges_.Size();
106 }
107
110 {
111 return { EntryNodes_.Items().begin(), EntryNodes_.Items().end() };
112 }
113
115 ExitNodes() const
116 {
117 return { ExitNodes_.Items().begin(), ExitNodes_.Items().end() };
118 }
119
122 {
123 return { EntryEdges_.Items().begin(), EntryEdges_.Items().end() };
124 }
125
128 {
129 return { RepetitionEdges_.Items().begin(), RepetitionEdges_.Items().end() };
130 }
131
133 ExitEdges() const
134 {
135 return { ExitEdges_.Items().begin(), ExitEdges_.Items().end() };
136 }
137
141 static std::unique_ptr<StronglyConnectedComponentStructure>
143
149 bool
150 IsTailControlledLoop() const noexcept;
151
152private:
158};
159
160bool
161is_valid(const ControlFlowGraph & cfg);
162
163bool
164is_closed(const ControlFlowGraph & cfg);
165
166bool
167is_linear(const ControlFlowGraph & cfg);
168
172std::vector<StronglyConnectedComponent>
173find_sccs(const ControlFlowGraph & cfg);
174
179std::vector<StronglyConnectedComponent>
180find_sccs(ControlFlowGraphNode * entry, ControlFlowGraphNode * exit);
181
182static inline bool
184{
185 auto sccs = find_sccs(cfg);
186 return sccs.size() == 0;
187}
188
189bool
190is_structured(const ControlFlowGraph & cfg);
191
192bool
193is_proper_structured(const ControlFlowGraph & cfg);
194
195bool
196is_reducible(const ControlFlowGraph & cfg);
197
209void
210straighten(ControlFlowGraph & cfg);
211
214void
215purge(ControlFlowGraph & cfg);
216
221void
222prune(ControlFlowGraph & cfg);
223
224}
225
226#endif
std::vector< rvsdg::Node * > nodes
Strongly Connected Component Structure.
util::IteratorRange< CfgEdgeConstIterator > EdgeIteratorRange
util::HashSet< ControlFlowGraphEdge * > EntryEdges_
util::HashSet< ControlFlowGraphEdge * > ExitEdges_
util::HashSet< ControlFlowGraphNode * > EntryNodes_
static std::unique_ptr< StronglyConnectedComponentStructure > Create(const StronglyConnectedComponent &scc)
util::IteratorRange< CfgNodeConstIterator > NodeIteratorRange
util::HashSet< ControlFlowGraphEdge * > RepetitionEdges_
util::HashSet< ControlFlowGraphNode * > ExitNodes_
Strongly Connected Component.
std::unordered_set< ControlFlowGraphNode * > nodes_
StronglyConnectedComponent(const std::unordered_set< ControlFlowGraphNode * > &nodes)
bool contains(ControlFlowGraphNode *node) const
util::PtrIterator< ControlFlowGraphNode, std::unordered_set< ControlFlowGraphNode * >::const_iterator > constiterator
Global memory state passed between functions.
std::vector< StronglyConnectedComponent > find_sccs(const ControlFlowGraph &cfg)
bool is_structured(const ControlFlowGraph &cfg)
static bool is_linear(const ControlFlowGraphNode *node) noexcept
bool is_reducible(const ControlFlowGraph &cfg)
bool is_valid(const ControlFlowGraph &cfg)
void straighten(ControlFlowGraph &cfg)
bool is_proper_structured(const ControlFlowGraph &cfg)
void purge(ControlFlowGraph &cfg)
Remove all basic blocks without instructions.
bool is_closed(const ControlFlowGraph &cfg)
static bool is_acyclic(const ControlFlowGraph &cfg)
void prune(ControlFlowGraph &cfg)