P4C
The P4 Compiler
Loading...
Searching...
No Matches
parser_dominator_builder.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PARDE_PARSER_DOMINATOR_BUILDER_H_
20#define BACKENDS_TOFINO_BF_P4C_PARDE_PARSER_DOMINATOR_BUILDER_H_
21
22#include <optional>
23
24#include <boost/graph/adjacency_list.hpp>
25#include <boost/graph/dominator_tree.hpp>
26#include <boost/graph/graph_utility.hpp>
27#include <boost/graph/reverse_graph.hpp>
28
29#include "bf-p4c/logging/event_logger.h"
30#include "bf-p4c/parde/parser_info.h"
31#include "ir/ir.h"
32#include "ir/visitor.h"
33
44 public:
48 using Graph = ReversibleParserGraph::Graph;
49 using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
50 using IndexMap = boost::property_map<Graph, boost::vertex_index_t>::type;
51 using PredMap = boost::iterator_property_map<std::vector<Vertex>::iterator, IndexMap>;
52
53 protected:
57 std::set<const IR::BFN::ParserState *> states;
58
59 private:
63 bool preorder(const IR::BFN::Parser *parser) override;
64
68 bool preorder(const IR::BFN::ParserState *parser_state) override;
69
81 template <typename G>
82 IndexImmediateDominatorMap get_immediate_dominators(G graph, Vertex entry,
83 bool get_post_dominators) {
84 std::vector<Vertex> dom_tree_pred_vector;
85 IndexMap index_map(boost::get(boost::vertex_index, graph));
86 dom_tree_pred_vector =
87 std::vector<Vertex>(boost::num_vertices(graph), boost::graph_traits<G>::null_vertex());
88 PredMap dom_tree_pred_map =
89 boost::make_iterator_property_map(dom_tree_pred_vector.begin(), index_map);
90 boost::lengauer_tarjan_dominator_tree(graph, entry, dom_tree_pred_map);
91
92 typename boost::graph_traits<G>::vertex_iterator it, end;
94 std::string out = get_post_dominators ? "post-dominator" : "dominator";
95 LOG7("Building " << out << " int map");
96 for (std::tie(it, end) = boost::vertices(graph); it != end; ++it) {
97 if (boost::get(dom_tree_pred_map, *it) != boost::graph_traits<G>::null_vertex()) {
98 idom[boost::get(index_map, *it)] =
99 boost::get(index_map, boost::get(dom_tree_pred_map, *it));
100 LOG7(TAB1 << "Setting " << out << " for " << boost::get(index_map, *it) << " to "
101 << boost::get(index_map, boost::get(dom_tree_pred_map, *it)));
102 } else {
103 idom[boost::get(index_map, *it)] = -1;
104 LOG7(TAB1 << "Setting " << out << " for " << boost::get(index_map, *it)
105 << " to -1");
106 }
107 }
108 return idom;
109 }
110
121 IndexImmediateDominatorMap get_immediate_dominators(Graph graph, Vertex entry);
122
133 IndexImmediateDominatorMap get_immediate_post_dominators(boost::reverse_graph<Graph> graph,
134 Vertex entry);
135
145 StateImmediateDominatorMap index_map_to_state_map(IndexImmediateDominatorMap &idom,
147
157 std::set<const IR::BFN::ParserState *> get_all_dominatees(const IR::BFN::ParserState *state,
158 gress_t gress,
159 bool get_post_dominatees);
160
170 std::set<const IR::BFN::ParserState *> get_all_dominators(const IR::BFN::ParserState *state,
171 gress_t gress,
172 bool get_post_dominators);
173
177 void build_dominator_maps();
178
179 protected:
188 std::set<const IR::BFN::ParserState *> get_all_dominatees(const IR::BFN::ParserState *state,
189 gress_t gress = INGRESS);
190
199 std::set<const IR::BFN::ParserState *> get_all_post_dominatees(
200 const IR::BFN::ParserState *state, gress_t gress = INGRESS);
201
210 std::set<const IR::BFN::ParserState *> get_all_dominators(const IR::BFN::ParserState *state,
211 gress_t gress = INGRESS);
212
221 std::set<const IR::BFN::ParserState *> get_all_post_dominators(
222 const IR::BFN::ParserState *state, gress_t gress = INGRESS);
223
224 profile_t init_apply(const IR::Node *root) override;
225 void end_apply() override;
226
227 public:
229};
230
231#endif /* BACKENDS_TOFINO_BF_P4C_PARDE_PARSER_DOMINATOR_BUILDER_H_ */
Definition node.h:95
profile_t init_apply(const IR::Node *root) override
Definition parser_dominator_builder.cpp:21
std::set< const IR::BFN::ParserState * > get_all_post_dominatees(const IR::BFN::ParserState *state, gress_t gress=INGRESS)
Get all parser states that are post-dominated by state.
Definition parser_dominator_builder.cpp:126
std::set< const IR::BFN::ParserState * > get_all_post_dominators(const IR::BFN::ParserState *state, gress_t gress=INGRESS)
Get all post-dominators of a given parser state.
Definition parser_dominator_builder.cpp:136
Definition parde_visitor.h:27
Builds parser graphs and determines the dominators and post-dominators of all parser states....
Definition parser_dominator_builder.h:43
Definition parser_info.h:56