19#ifndef BF_P4C_MAU_SIMPLE_POWER_GRAPH_H_
20#define BF_P4C_MAU_SIMPLE_POWER_GRAPH_H_
29#include "backends/tofino/bf-p4c/mau/mau_power.h"
38 std::set<const Node *> nodes;
39 std::set<const Edge *> edges;
51 cstring to_string()
const {
return name_; }
52 bool is_equivalent(
const Edge *other)
const;
61 explicit Edge(
size_t id,
cstring name, std::vector<Node *> &child_nodes)
62 : id_(
id), name_(name) {
63 for (
auto n : child_nodes) {
64 child_nodes_.push_back(n);
68 std::vector<Node *> child_nodes_;
70 void dbprint(std::ostream &out)
const {
85 std::vector<Edge *> out_edges_;
87 explicit Node(
UniqueId uniq_id,
int id) : unique_id_(uniq_id), id_(
id) {}
89 for (
auto e : out_edges_)
delete e;
91 Node(
const Node &n) : unique_id_(n.unique_id_), id_(n.id_) {
92 for (
auto e : n.out_edges_) add_edge(e);
94 Node &operator=(
const Node &n) =
delete;
96 Node &operator=(
const Node &&n) =
delete;
105 bool is_equivalent(
const Node *other)
const;
106 cstring to_string()
const {
return "" + unique_id_.build_name(); }
108 void dbprint(std::ostream &out)
const {
114 void add_edge(
Edge *e);
127 std::map<UniqueId, Node *> nodes_ = {};
128 std::map<UniqueId, std::set<UniqueId>> pred_ = {};
135 root_uid.name =
"$root"_cs;
136 root_ =
new Node(root_uid, 0);
137 nodes_.emplace(root_uid, root_);
139 Node *get_root()
const {
return root_; }
152 void to_dot(
const std::filesystem::path &filename);
181 if (pred_.count(child))
return pred_.at(child);
182 static std::set<UniqueId> empty;
196 const std::map<UniqueId, PowerMemoryAccess> &table_memory_access, std::set<Node *> &rv);
199 void dbprint(std::ostream &out)
const {
208 std::map<std::pair<int, int>,
bool> found_reachable_ = {};
210 std::map<std::pair<int, int>,
bool> found_simultaneous_ = {};
212 std::map<int, double> computed_power_ = {};
214 std::map<int, std::set<UniqueId>> computed_worst_path_ = {};
216 std::map<Node *, Edge *> worst_path_edges_ = {};
223 int get_next_id() {
return running_id_++; }
224 void topo_visit(Node *node, std::stack<Node *> *stack, std::map<Node *, bool> *visited);
231 double visit_node_power(Node *n,
const std::map<UniqueId, PowerMemoryAccess> &tma,
232 std::set<UniqueId> &worst_path);
Definition simple_power_graph.h:47
std::string get_edge_color() const
Definition simple_power_graph.cpp:52
Definition simple_power_graph.h:81
void create_and_add_edge(cstring edge_name, std::vector< Node * > &child_nodes)
Definition simple_power_graph.cpp:61
Definition simple_power_graph.h:126
void to_dot(const std::filesystem::path &filename)
Definition simple_power_graph.cpp:130
bool can_reach(UniqueId parent, UniqueId child)
Definition simple_power_graph.cpp:221
const std::set< UniqueId > & predecessors(UniqueId child) const
Definition simple_power_graph.h:180
void add_connection(UniqueId parent, ordered_set< UniqueId > activated, cstring edge_name)
Definition simple_power_graph.cpp:112
double get_tables_on_worst_path(const std::map< UniqueId, PowerMemoryAccess > &table_memory_access, std::set< Node * > &rv)
Definition simple_power_graph.cpp:296
bool active_simultaneously(UniqueId parent, UniqueId child)
Definition simple_power_graph.cpp:256
void get_leaves(UniqueId n, std::vector< UniqueId > &leaves)
Definition simple_power_graph.cpp:161
std::vector< Node * > topo_sort()
Definition simple_power_graph.cpp:207
Definition stringify.h:33
Definition unique_id.h:168
Definition ordered_set.h:32
Definition mau/asm_output.h:39
Definition simple_power_graph.h:37