P4C
The P4 Compiler
Loading...
Searching...
No Matches
field_use.h
1
19#ifndef BF_P4C_MAU_FIELD_USE_H_
20#define BF_P4C_MAU_FIELD_USE_H_
21
22#include <iostream>
23
24#include "backends/tofino/bf-p4c/ir/tofino_write_context.h"
25#include "backends/tofino/bf-p4c/phv/phv_fields.h"
26#include "lib/bitvec.h"
27#include "lib/safe_vector.h"
28#include "mau_visitor.h"
29
30using namespace P4;
31
33 const PhvInfo &phv;
34 safe_vector<cstring> field_names;
35 std::map<cstring, int> field_index;
36 struct rw_t {
37 bitvec reads, writes;
38 };
39 std::map<cstring, rw_t> table_use;
40 void access_field(cstring field);
41 bool preorder(const IR::MAU::Table *t) override;
42 bool preorder(const IR::Member *f) override;
43 bool preorder(const IR::HeaderStackItemRef *f) override;
44 bool preorder(const IR::TempVar *t) override;
45 friend std::ostream &operator<<(std::ostream &, const FieldUse &);
46 profile_t init_apply(const IR::Node *root) override {
47 static int counter;
48 auto rv = MauInspector::init_apply(root);
49 LOG1("Field Use call #" << ++counter);
50 return rv;
51 }
52 void end_apply() override { LOG3(*this); }
53
54 public:
55 explicit FieldUse(const PhvInfo &p) : phv(p) { visitDagOnce = false; }
56 bitvec tables_modify(const IR::MAU::TableSeq *t) const;
57 bitvec tables_access(const IR::MAU::TableSeq *t) const;
58 bitvec tables_modify(const IR::MAU::Table *t) const;
59 bitvec tables_access(const IR::MAU::Table *t) const;
60 bitvec table_reads(const IR::MAU::Table *t) const { return table_use.at(t->name).reads; }
61 bitvec table_writes(const IR::MAU::Table *t) const { return table_use.at(t->name).writes; }
62 void cloning_table(cstring name, cstring newname) {
63 assert(table_use.count(name) && !table_use.count(newname));
64 table_use[newname] = table_use[name];
65 }
66};
67
68#endif /* BF_P4C_MAU_FIELD_USE_H_ */
Definition field_use.h:32
Definition mau_visitor.h:29
Definition node.h:94
Definition visitor.h:78
Definition bitvec.h:120
Definition cstring.h:85
Definition safe_vector.h:27
Definition phv_fields.h:1095
Definition tofino_write_context.h:24
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24