53 bool assignZeroToDestination;
55 std::unique_ptr<AllocSlice> sourceSlice;
56 bool alwaysInitInLastMAUStage;
57 bool alwaysRunActionPrim;
61 std::vector<DarkInitEntry *> priorPrims;
62 std::vector<DarkInitEntry *> postPrims;
66 : assignZeroToDestination(
false),
69 alwaysInitInLastMAUStage(
false),
70 alwaysRunActionPrim(
false) {}
80 bool isEmpty()
const {
81 if (!nop && !sourceSlice && !assignZeroToDestination)
return true;
90 assignZeroToDestination =
false;
93 void addPriorUnits(
const UnitSet &units,
bool append =
true) {
97 priorUnits.insert(units.begin(), units.end());
100 void addPostUnits(
const UnitSet &units,
bool append =
true) {
104 postUnits.insert(units.begin(), units.end());
107 void addPriorPrims(
DarkInitEntry *prims,
bool append =
true) {
111 priorPrims.push_back(prims);
113 void addPostPrims(
DarkInitEntry *prims,
bool append =
true) {
117 postPrims.push_back(prims);
120 void setLastStageAlwaysInit() { alwaysInitInLastMAUStage = alwaysRunActionPrim =
true; }
121 void setAlwaysRunActionPrim() { alwaysRunActionPrim =
true; }
122 void setAssignZeroToDest();
123 bool isNOP()
const {
return nop; }
124 bool destAssignedToZero()
const {
return assignZeroToDestination; }
125 bool mustInitInLastMAUStage()
const {
return alwaysInitInLastMAUStage; }
126 bool isAlwaysRunActionPrim()
const {
return alwaysRunActionPrim; }
127 AllocSlice *getSourceSlice()
const {
return sourceSlice.get(); }
128 bool setSourceLatestLiveness(StageAndAccess max);
129 const ActionSet &getInitPoints()
const {
return actions; }
130 const UnitSet &getARApriorUnits()
const {
return priorUnits; }
131 const UnitSet &getARApostUnits()
const {
return postUnits; }
132 const std::vector<DarkInitEntry *> getARApriorPrims()
const {
return priorPrims; }
133 const std::vector<DarkInitEntry *> getARApostPrims()
const {
return postPrims; }
137 const Field *field_i;
140 int container_bit_lo_i;
143 StageAndAccess min_stage_i;
144 StageAndAccess max_stage_i;
150 bool shadow_always_run_i =
false;
153 bool shadow_init_i =
false;
155 bool has_meta_init_i =
false;
159 bool is_physical_stage_based_i =
false;
162 bool physical_deparser_stage_i =
false;
165 bool physical_deparser_stage_exceeded_i =
false;
173 static const int NOTSET = -2;
180 bool operator==(
const AllocSlice &other)
const;
181 bool operator!=(
const AllocSlice &other)
const;
182 bool operator<(
const AllocSlice &other)
const;
184 bool same_alloc_fieldslice(
const AllocSlice &other)
const;
192 std::optional<AllocSlice> sub_alloc_by_field(
int start,
int len)
const;
194 const Field *field()
const {
return field_i; }
195 Container container()
const {
return container_i; }
199 bool is_initialized()
const;
200 int width()
const {
return width_i; }
203 const StageAndAccess &getEarliestLiveness()
const {
return min_stage_i; }
204 const StageAndAccess &getLatestLiveness()
const {
return max_stage_i; }
205 std::pair<Container, int> container_byte()
const {
206 BUG_CHECK(container_bit_lo_i % 8U + width_i <= 8U,
"%s is not in one container byte",
208 return std::make_pair(container_i, container_bit_lo_i & ~7);
211 bool hasInitPrimitive()
const;
214 void get_ref_lr(StageAndAccess &minStg, StageAndAccess &maxStg)
const;
217 bool isLiveAt(
int stage,
const FieldUse &use)
const;
220 bool isLiveRangeDisjoint(
const AllocSlice &other,
int gap = 0)
const;
222 bool representsSameFieldSlice(
const AllocSlice &other)
const {
223 if (field_i != other.field())
return false;
224 if (field_slice() != other.field_slice())
return false;
225 if (width_i != other.width())
return false;
229 bool extends_live_range(
const AllocSlice &other)
const {
230 if ((min_stage_i.first < other.getEarliestLiveness().first) ||
231 (max_stage_i.first > other.getLatestLiveness().first) ||
232 ((min_stage_i.first == other.getEarliestLiveness().first) &&
233 (min_stage_i.second < other.getEarliestLiveness().second)) ||
234 ((max_stage_i.first == other.getLatestLiveness().first) &&
235 (max_stage_i.second > other.getLatestLiveness().second)))
240 void setLiveness(
const StageAndAccess &min,
const StageAndAccess &max) {
241 min_stage_i = std::make_pair(min.first, min.second);
242 max_stage_i = std::make_pair(max.first, max.second);
245 void setLatestLiveness(
const StageAndAccess &max) {
246 max_stage_i = std::make_pair(max.first, max.second);
249 void setEarliestLiveness(
const StageAndAccess &min) {
250 min_stage_i = std::make_pair(min.first, min.second);
255 bool hasMetaInit()
const {
return has_meta_init_i; }
256 void setMetaInit() { has_meta_init_i =
true; }
257 const ActionSet &getInitPoints()
const {
return init_points_i; }
258 void setInitPoints(
const ActionSet &init_points) { init_points_i = init_points; }
259 void setShadowAlwaysRun(
bool val) { shadow_always_run_i = val; }
260 bool getShadowAlwaysRun()
const {
return shadow_always_run_i; }
261 void setShadowInit(
bool val) { shadow_init_i = val; }
262 bool getShadowInit()
const {
return shadow_init_i; }
263 const RefsMap &getRefs()
const {
return refs; }
264 void clearRefs() { refs.clear(); }
265 void addRefs(
const RefsMap &sl_refs,
bool clear_refs =
false) {
266 if (clear_refs) refs.clear();
267 for (
auto ref_entry : sl_refs) addRef(ref_entry.first, ref_entry.second);
272 bool isUsedDeparser()
const;
273 bool isUsedParser()
const;
275 bool isPhysicalStageBased()
const {
return is_physical_stage_based_i; }
276 void setIsPhysicalStageBased(
bool v) { is_physical_stage_based_i = v; }
278 bool isPhysicalDeparserStage()
const {
return physical_deparser_stage_i; }
279 void setPhysicalDeparserStage(
bool v) { physical_deparser_stage_i = v; }
281 bool isPhysicalDeparserStageExceeded()
const {
return physical_deparser_stage_exceeded_i; }
282 void setPhysicalDeparserStageExceeded(
bool v) { physical_deparser_stage_exceeded_i = v; }
284 bool isUninitializedRead()
const {
285 return (getEarliestLiveness().second.isRead() && getLatestLiveness().second.isRead());
290 SliceMatch match = SliceMatch::DFLT)
const;
291 std::string toString()
const;
296 int parser_stage_idx()
const;
297 int deparser_stage_idx()
const;
308 : destinationSlice(dest), initInfo(initPoints) {}
310 : destinationSlice(dest), initInfo(src) {}
312 : destinationSlice(dest), initInfo(src, init) {}
314 : destinationSlice(dest), initInfo(src) {}
316 void addSource(
AllocSlice sl) { initInfo.addSource(sl); }
317 void setNop() { initInfo.setNop(); }
318 void setLastStageAlwaysInit() { initInfo.setLastStageAlwaysInit(); }
319 void setAlwaysRunInit() { initInfo.setAlwaysRunActionPrim(); }
320 bool isNOP()
const {
return initInfo.isNOP(); }
321 bool destAssignedToZero()
const {
return initInfo.destAssignedToZero(); }
322 bool mustInitInLastMAUStage()
const {
return initInfo.mustInitInLastMAUStage(); }
323 AllocSlice *getSourceSlice()
const {
return initInfo.getSourceSlice(); }
325 void addPriorUnits(
const UnitSet &units,
bool append =
true) {
326 initInfo.addPriorUnits(units, append);
328 void addPostUnits(
const UnitSet &units,
bool append =
true) {
329 initInfo.addPostUnits(units, append);
332 void addPriorPrims(
DarkInitEntry *prims,
bool append =
true) {
333 initInfo.addPriorPrims(prims, append);
335 void addPostPrims(
DarkInitEntry *prims,
bool append =
true) {
336 initInfo.addPostPrims(prims, append);
339 const ActionSet &getInitPoints()
const {
return initInfo.getInitPoints(); }
340 const AllocSlice &getDestinationSlice()
const {
return destinationSlice; }
341 AllocSlice getDestinationSlice() {
return destinationSlice; }
344 void setDestinationLatestLiveness(
const StageAndAccess &max) {
345 destinationSlice.setLatestLiveness(max);
347 void setDestinationEarliestLiveness(
const StageAndAccess &min) {
348 destinationSlice.setEarliestLiveness(min);
351 void addRefs(
const RefsMap &sl_refs,
bool clear_refs =
false) {
352 destinationSlice.addRefs(sl_refs, clear_refs);
355 void addDestinationUnit(
cstring tName,
FieldUse tRef) { destinationSlice.addRef(tName, tRef); }
358 if (destinationSlice != other.getDestinationSlice())
359 return destinationSlice < other.getDestinationSlice();
360 if (getSourceSlice() && other.getSourceSlice() &&
361 *(getSourceSlice()) != *(other.getSourceSlice()))
362 return *(getSourceSlice()) < *(other.getSourceSlice());
363 if (getSourceSlice() && !other.getSourceSlice())
return true;
368 LOG4(
"DarkInitEntry == : " << &destinationSlice <<
" <-> ");
370 return (destinationSlice == other.getDestinationSlice()) &&
371 (initInfo == other.getInitPrimitive());
374 bool operator!=(
const DarkInitEntry &other)
const {
return !this->operator==(other); }
Represents a PHV-allocation context: a parser, a table, or a deparser.
Definition phv_fields.h:83
Definition slice_alloc.h:300