10 #include <type_traits>
11 #include <unordered_map>
12 #include <unordered_set>
15 #include <hilti/ast/all.h>
16 #include <hilti/ast/forward.h>
17 #include <hilti/base/graph.h>
22 constexpr Tag MetaNode = 20000;
23 constexpr Tag Start = 20001;
24 constexpr Tag End = 20002;
25 constexpr Tag Flow = 20003;
28 namespace detail::cfg {
38 #pragma GCC diagnostic push
39 #pragma GCC diagnostic ignored "-Wpragmas"
40 #pragma GCC diagnostic ignored "-Wunknown-warning-option"
41 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
42 MetaNode(node::Tags node_tags) :
Node(
nullptr, node_tags, {}, {}) {}
43 #pragma GCC diagnostic pop
84 GraphNode(operator_::function::Call* x) : node(x) {}
103 Node* operator->() {
return node; }
104 const Node* operator->()
const {
return node; }
106 Node* value()
const {
return node; }
108 friend bool operator==(
const GraphNode& a,
const GraphNode& b) {
return a.node == b.node; }
109 friend bool operator!=(
const GraphNode& a,
const GraphNode& b) {
return ! (a.node == b.node); }
111 friend bool operator<(
const GraphNode& a,
const GraphNode& b) {
return a.node < b.node; }
114 Node* node =
nullptr;
122 struct hash<hilti::detail::cfg::GraphNode> {
127 namespace hilti::detail::cfg {
134 std::unordered_map<Declaration*, std::unordered_set<GraphNode>>
in;
137 std::unordered_map<Declaration*, std::unordered_set<GraphNode>>
out;
140 std::unordered_map<Declaration*, std::unordered_set<GraphNode>>
kill;
151 std::unordered_map<Declaration*, GraphNode>
gen;
154 std::unordered_set<Declaration*>
read;
157 std::unordered_set<Declaration*>
write;
171 using NodeId = uint64_t;
200 std::string
dot()
const;
211 void _populateDataflow();
234 template<
typename T,
typename... Args>
235 MetaNode* _createMetaNode(Args... args)
236 requires(std::is_base_of_v<MetaNode, T>)
238 auto n = std::make_unique<T>(args...);
240 _meta_nodes.insert(std::move(n));
246 std::unordered_set<std::unique_ptr<MetaNode>> _meta_nodes;
247 std::unordered_map<GraphNode, Transfer> _dataflow;
Definition: expression.h:15
uint64_t identity() const
Definition: node.h:361
Node(ASTContext *ctx, node::Tags node_tags, Nodes children, Meta meta)
Definition: node.h:922
Definition: forward.h:758
Definition: statement.h:15
Definition: global-variable.h:17
Definition: local-variable.h:32
const Graph & graph() const
Definition: cfg.h:206
const auto & dataflow() const
Definition: cfg.h:203
void removeNode(Node *node)
Definition: cfg.cc:374
util::graph::DirectedGraph< GraphNode, NodeId > Graph
Definition: cfg.h:174
CFG(const Node *root)
Definition: cfg.cc:85
std::string dot() const
Definition: cfg.cc:389
std::unordered_map< Declaration *, std::unordered_set< GraphNode > > in
Definition: cfg.h:134
std::unordered_map< Declaration *, std::unordered_set< GraphNode > > kill
Definition: cfg.h:140
std::unordered_map< Declaration *, std::unordered_set< GraphNode > > out
Definition: cfg.h:137
std::unordered_set< Declaration * > read
Definition: cfg.h:154
std::unordered_set< Declaration * > write
Definition: cfg.h:157
std::unordered_set< Declaration * > maybe_alias
Definition: cfg.h:143
std::unordered_map< Declaration *, GraphNode > gen
Definition: cfg.h:151
bool keep
Definition: cfg.h:163