P4C
The P4 Compiler
Loading...
Searching...
No Matches
action_data_bus.h
1
19#ifndef BF_P4C_MAU_ACTION_DATA_BUS_H_
20#define BF_P4C_MAU_ACTION_DATA_BUS_H_
21
22#include "backends/tofino/bf-p4c/mau/action_format.h"
23#include "backends/tofino/bf-p4c/mau/table_layout.h"
24#include "lib/safe_vector.h"
25
26using namespace P4;
27
60 public:
61 struct Loc : public IHasDbPrint {
62 int byte;
63 ActionData::SlotType_t type;
64 Loc(int b, ActionData::SlotType_t t) : byte(b), type(t) {}
65 void dbprint(std::ostream &out) const {
66 int slot_size = (8 << type);
67 out << "ADB[" << byte << ":" << ((byte + slot_size / 8) - 1) << "]";
68 }
69 bool operator==(const Loc &loc) const {
70 if (byte != loc.byte) return false;
71 if (type != loc.type) return false;
72 return true;
73 };
74 bool operator!=(const Loc &loc) const { return !(*this == loc); }
75 };
79 struct FullShare {
80 bool full_in_use = false;
81 unsigned shared_status = 0;
82 int shared_byte[2] = {-1, -1};
83 bool full_bitmasked_set = false;
84 int full_bitmasked_index = -1;
85 void init_full_bitmask(int fbi) {
86 full_bitmasked_set = true;
87 full_bitmasked_index = fbi;
88 }
89 };
90
92 struct Use {
95 Loc location;
96 int byte_offset = -1;
99 ActionData::Location_t source = ActionData::ALL_LOCATIONS;
100 ReservedSpace(Loc l, int bo, bitvec bu)
101 : location(l), byte_offset(bo), bytes_used(bu) {}
102 ReservedSpace(Loc l, int bo, bitvec bu, ActionData::Location_t src)
103 : location(l), byte_offset(bo), bytes_used(bu), source(src) {}
104 void dbprint(std::ostream &out) const {
105 out << "Source:Offset " << source << ":" << byte_offset << " : " << location;
106 }
107 bool operator==(const ReservedSpace &rs) const {
108 if (location != rs.location) return false;
109 if (byte_offset != rs.byte_offset) return false;
110 if (bytes_used != rs.bytes_used) return false;
111 if (source != rs.source) return false;
112 return true;
113 }
114 bool operator!=(const ReservedSpace &rs) const { return !(*this == rs); }
115 };
116 // Locations of action data where the ALUs will pull action data
117 safe_vector<ReservedSpace> action_data_locs;
118 // Slots reserved because unused action data was needed
119 safe_vector<ReservedSpace> clobber_locs;
120 virtual ~Use() {}
121 virtual void clear() {
122 action_data_locs.clear();
123 clobber_locs.clear();
124 }
125 virtual Use *clone() const = 0;
126 virtual bool emit_adb_asm(std::ostream &, const IR::MAU::Table *, bitvec source) const = 0;
127 virtual bool empty() const { return action_data_locs.empty() && clobber_locs.empty(); }
128 virtual int rng_unit() const = 0;
129 bool operator==(const Use &use) const {
130 if (action_data_locs != use.action_data_locs) return false;
131 if (clobber_locs != use.clobber_locs) return false;
132 return true;
133 };
134 bool operator!=(const Use &use) const { return !(*this == use); }
135 friend std::ostream &operator<<(std::ostream &out, const Use &u);
136 };
137
140 FIND_NORMAL,
141 FIND_LOWER,
142 FIND_FULL,
143 FIND_IMMED_UPPER,
144 FIND_FULL_HALF,
145 FIND_FULL_BYTE
146 };
147
148 virtual void clear();
149
150 protected:
151 // Holds information on already allocated ActionProfiles, Meters, and Stateful Alus
153 // Holds information on already allocated stateful ALUs in the same reduction or group
154 ordered_map<cstring, const Use &> reduction_or_mapping;
155
156 public:
157 virtual ~ActionDataBus() {}
158
159 virtual bool alloc_action_data_bus(const IR::MAU::Table *tbl,
160 const ActionData::Format::Use *use,
161 TableResourceAlloc &alloc) = 0;
162 virtual bool alloc_action_data_bus(const IR::MAU::Table *tbl, const MeterALU::Format::Use *use,
163 TableResourceAlloc &alloc) = 0;
164 virtual void update(cstring name, const Use &alloc);
165 virtual void update(cstring name, const Use::ReservedSpace &rs) = 0;
166 virtual void update(const IR::MAU::Table *tbl);
167 virtual void update(cstring name, const TableResourceAlloc *alloc, const IR::MAU::Table *tbl);
168 virtual void update_action_data(cstring name, const TableResourceAlloc *alloc,
169 const IR::MAU::Table *tbl);
170 virtual void update_meter(cstring name, const TableResourceAlloc *alloc,
171 const IR::MAU::Table *tbl);
172
173 static ActionDataBus *create();
174 static int getAdbSize();
175 friend std::ostream &operator<<(std::ostream &out, const ActionDataBus &adb);
176};
177
178#endif /* BF_P4C_MAU_ACTION_DATA_BUS_H_*/
Definition stringify.h:33
Definition bitvec.h:120
Definition cstring.h:85
Definition ordered_map.h:32
Definition safe_vector.h:27
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition action_format.h:979
Definition action_data_bus.h:79
Definition action_data_bus.h:61
Definition action_data_bus.h:94
ReservedSpace(Loc l, int bo, bitvec bu)
Definition action_data_bus.h:100
bitvec bytes_used
Definition action_data_bus.h:97
ActionData::Location_t source
Definition action_data_bus.h:99
Definition action_data_bus.h:92
Definition action_data_bus.h:59
loc_alg_t
Definition action_data_bus.h:139
virtual void clear()
Definition action_data_bus.cpp:24
virtual void update(cstring name, const Use &alloc)
Definition action_data_bus.cpp:32
Definition attached_output.h:42
Definition resource.h:37