P4C
The P4 Compiler
Loading...
Searching...
No Matches
instruction_memory.h
1
19#ifndef BF_P4C_MAU_INSTRUCTION_MEMORY_H_
20#define BF_P4C_MAU_INSTRUCTION_MEMORY_H_
21
22/* clang-format off */
23#include "bf-p4c/mau/table_layout.h"
24#include "bf-p4c/ir/gress.h"
25#include "bf-p4c/common/alloc.h"
26
27using namespace P4;
28
30 PhvInfo &phv;
31 ActionData::FormatType_t format_type;
32 SplitAttachedInfo &split_attached;
33 const IR::MAU::Table* tbl;
34
35 void generate_for_action(const IR::MAU::Action *);
37 ordered_map<const IR::MAU::Action *, bool> table_instrs_has_unalloc_tempvar;
38
39 public:
40 bitvec get_instr(const IR::MAU::Action *act) {
41 return table_instrs[act];
42 }
43 bool instr_has_unalloc_tempvar(const IR::MAU::Action *act) {
44 return table_instrs_has_unalloc_tempvar[act];
45 }
47 SplitAttachedInfo &sai, const IR::MAU::Table* tbl);
48};
49
83 static constexpr int NOOP_ROW = 0;
84 static constexpr int NOOP_COLOR = 0;
85 const IMemSpec &spec;
86
87 protected:
88 explicit InstructionMemory(const IMemSpec &s) : spec(s) {}
89
90 InstructionMemory(const InstructionMemory &) = delete;
91 InstructionMemory &operator=(const InstructionMemory &) = delete;
92
93 public:
94 virtual ~InstructionMemory() = default;
95
96 std::set<cstring> atcam_updates;
97
111 struct Use {
113 bitvec non_noop_instructions;
114 int row;
115 int color;
116 int mem_code = -1;
117
118 // The address for the RAM line is in this format
119 unsigned gen_addr() const {
120 return color | row << Device::imemSpec().color_bits();
121 }
122 VLIW_Instruction(bitvec nni, int r, int c)
123 : non_noop_instructions(nni), row(r), color(c) {}
124
125 bool operator==(const VLIW_Instruction &v) const {
126 return (non_noop_instructions == v.non_noop_instructions) && \
127 (row == v.row) && \
128 (color == v.color) && \
129 (mem_code == v.mem_code);
130 }
131
132 friend std::ostream & operator<<(std::ostream &out, const VLIW_Instruction &i);
133 };
134 std::map<cstring, VLIW_Instruction> all_instrs;
135
136 void clear() {
137 all_instrs.clear();
138 }
139 void merge(const Use &alloc);
140
141 bool operator==(const Use &u) const {
142 return all_instrs == u.all_instrs;
143 }
144
145 bool operator!=(const Use &u) const {
146 return all_instrs != u.all_instrs;
147 }
148
149 friend std::ostream & operator<<(std::ostream &out, const Use &u);
150 };
151
152 std::map<const IR::MAU::ActionData *, const Use *> shared_action_profiles;
153 // std::map<cstring, InstructionMemory::Use::VLIW_Instruction>> shared_action_profiles;
154
155 virtual BFN::Alloc2Dbase<cstring> &imem_use(gress_t gress) = 0;
156 const BFN::Alloc2Dbase<cstring> &imem_use(gress_t gress) const {
157 return const_cast<InstructionMemory *>(this)->imem_use(gress); }
158 virtual BFN::Alloc2Dbase<bitvec> &imem_slot_inuse(gress_t gress) = 0;
159 const BFN::Alloc2Dbase<bitvec> &imem_slot_inuse(gress_t gress) const {
160 return const_cast<InstructionMemory *>(this)->imem_slot_inuse(gress); }
161
162 bool is_noop_slot(int row, int color);
163 bool find_row_and_color(bitvec current_bv, gress_t gress, int &row, int &color,
164 bool &first_noop, bool has_unalloc_temp = false);
165 bool shared_instr(const IR::MAU::Table *tbl, Use &alloc, bool gw_linked);
166 bool alloc_always_run_instr(const IR::MAU::Table *tbl, Use &alloc, bitvec current_bv);
167
168 public:
169 bool allocate_imem(const IR::MAU::Table *tbl, Use &alloc, PhvInfo &phv, bool gw_linked,
171 void update_always_run(const Use &alloc, gress_t gress);
172 void update(cstring name, const Use &alloc, gress_t gress);
173 void update(cstring name, const TableResourceAlloc *alloc, gress_t gress);
174 void update(cstring name, const TableResourceAlloc *alloc, const IR::MAU::Table *tbl);
175 void update(const IR::MAU::Table *tbl);
176
177 static InstructionMemory *create();
178};
179
180/* clang-format on */
181
182#endif /* BF_P4C_MAU_INSTRUCTION_MEMORY_H_ */
Definition attached_info.h:32
Definition alloc.h:76
Definition instruction_memory.h:29
GenerateVLIWInstructions(PhvInfo &p, ActionData::FormatType_t ft, SplitAttachedInfo &sai, const IR::MAU::Table *tbl)
Definition instruction_memory.cpp:29
Definition mau_spec.h:27
Definition bitvec.h:120
Definition cstring.h:85
Definition ordered_map.h:32
Definition phv_fields.h:1095
Definition attached_info.h:235
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition instruction_memory.h:112
Definition instruction_memory.h:111
Definition instruction_memory.h:82
bool shared_instr(const IR::MAU::Table *tbl, Use &alloc, bool gw_linked)
Definition instruction_memory.cpp:192
Definition resource.h:37