P4C
The P4 Compiler
Loading...
Searching...
No Matches
next_table.h
1
19#ifndef BF_P4C_MAU_NEXT_TABLE_H_
20#define BF_P4C_MAU_NEXT_TABLE_H_
21
22#include "ir/ir.h"
23
24using namespace P4;
25
26class NextTable : public virtual Visitor {
27 public:
28 virtual ordered_set<UniqueId> next_for(const IR::MAU::Table *tbl, cstring what) const = 0;
29 virtual bool uses_next_table(const IR::MAU::Table *tbl) const = 0;
30 virtual void dbprint(std::ostream &) const = 0;
31 virtual const std::unordered_map<int, std::set<UniqueId>> &long_branches(UniqueId) const {
32 static std::unordered_map<int, std::set<UniqueId>> empty;
33 return empty;
34 }
35 virtual std::pair<ssize_t, ssize_t> get_live_range_for_lb_with_dest(UniqueId) const {
36 return {-1, -1};
37 }
38 int long_branch_tag_for(UniqueId from, UniqueId to) const {
39 for (auto &lb : long_branches(from))
40 if (lb.second.count(to)) return lb.first;
41 return -1;
42 }
43};
44
45class DynamicNextTable : public DynamicVisitor, public NextTable, public IHasDbPrint {
46 NextTable *pass = nullptr;
47
48 public:
49 ordered_set<UniqueId> next_for(const IR::MAU::Table *tbl, cstring what) const override {
50 return pass->next_for(tbl, what);
51 }
52 bool uses_next_table(const IR::MAU::Table *tbl) const override {
53 return pass->uses_next_table(tbl);
54 }
55 void dbprint(std::ostream &out) const override { pass->dbprint(out); }
56 const std::unordered_map<int, std::set<UniqueId>> &long_branches(UniqueId id) const override {
57 return pass->long_branches(id);
58 }
59 std::pair<ssize_t, ssize_t> get_live_range_for_lb_with_dest(UniqueId id) const override {
60 return pass->get_live_range_for_lb_with_dest(id);
61 }
62 void setVisitor(NextTable *v) { DynamicVisitor::setVisitor((pass = v)); }
63 DynamicNextTable *clone() const override { BUG("DynamicNextTable not cloneable"); }
64};
65
66#endif /* BF_P4C_MAU_NEXT_TABLE_H_ */
Definition next_table.h:45
Definition next_table.h:26
Definition ir/pass_manager.h:202
Definition stringify.h:33
Definition unique_id.h:168
Definition visitor.h:75
Definition cstring.h:85
Definition ordered_set.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24