P4C
The P4 Compiler
Loading...
Searching...
No Matches
action_mutex.h
1
19#ifndef BF_P4C_MAU_ACTION_MUTEX_H_
20#define BF_P4C_MAU_ACTION_MUTEX_H_
21
22#include <map>
23
24#include "backends/tofino/bf-p4c/mau/mau_visitor.h"
25#include "lib/symbitmatrix.h"
26
27using namespace P4;
28
30 // map action to ids
31 std::map<const IR::MAU::Action *, int> action_ids;
32 // map table to all actions that will be executed after applying it.
33 std::map<const IR::MAU::Table *, bitvec> action_succ;
34 // action mutex matrix
35 SymBitMatrix not_mutex;
36 bool preorder(const IR::MAU::Table *t) override {
37 for (const auto *act : Values(t->actions)) {
38 if (!action_ids.count(act)) action_ids.emplace(act, action_ids.size());
39 name_actions[t->externalName() + "." + act->name] = act;
40 }
41 return true;
42 }
43 void postorder(const IR::MAU::Table *tbl) override;
44 void postorder(const IR::MAU::TableSeq *seq) override;
45
46 profile_t init_apply(const IR::Node *root) override {
47 profile_t rv = MauInspector::init_apply(root);
48 action_ids.clear();
49 action_succ.clear();
50 not_mutex.clear();
51 return rv;
52 }
53
54 public:
55 bool operator()(const IR::MAU::Action *a, const IR::MAU::Action *b) const {
56 return !not_mutex(action_ids.at(a), action_ids.at(b));
57 }
58
59 // For unit-tests
60 const std::map<const IR::MAU::Action *, int> &actions() const { return action_ids; }
61 // Maping action names to pointers
62 std::map<cstring, const IR::MAU::Action *> name_actions;
63};
64
65#endif /* BF_P4C_MAU_ACTION_MUTEX_H_ */
Definition action_mutex.h:29
Definition mau_visitor.h:29
Definition node.h:94
Definition symbitmatrix.h:27
Definition visitor.h:78
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24