19#ifndef BACKENDS_TOFINO_BF_P4C_PHV_LIVE_RANGE_SPLIT_H_
20#define BACKENDS_TOFINO_BF_P4C_PHV_LIVE_RANGE_SPLIT_H_
25#include "phv/analysis/dark_live_range.h"
26#include "phv/fieldslice_live_range.h"
27#include "phv/phv_fields.h"
41 std::vector<bitvec> vec;
42 unsigned containerWidth;
45 unsigned vecIdx(PHV::StageAndAccess sa)
const {
46 BUG_CHECK(sa.first >= minStage && sa.first <= maxStage,
47 "vecIdx (%1%) out of stage range [%2%, %3%]", sa.first, minStage, maxStage);
48 int stage = sa.first - minStage;
49 int offset = sa.second.isWrite() ? 1 : 0;
50 int val = stage * 2 + offset;
51 BUG_CHECK(val >= 0,
"Invalid StageAndAccess stage %1%", val);
52 return static_cast<unsigned>(val);
66 std::vector<le_bitrange> availBitsAt(
unsigned i,
unsigned minLength);
76 vec((maxStage - minStage + 1) * 2),
77 containerWidth(containerWidth) {
78 BUG_CHECK(minStage >= -1,
"ContainerOccupancy minStage (%1%) must be >= -1");
79 BUG_CHECK(maxStage >= minStage,
"Invalid ContainerOccupancy stage range (%1% > %2%)",
89 std::vector<le_bitrange>
availBitsAt(PHV::StageAndAccess sa,
unsigned minLength = 0) {
90 return availBitsAt(vecIdx(sa), minLength);
93 bool isRangeAvailable(StageAndAccess begin, StageAndAccess end,
le_bitrange range);
104 bool operator==(
const FreeSlice &c)
const {
105 return container == c.container && range == c.range && lr.start == c.lr.start &&
108 bool operator!=(
const FreeSlice &c)
const {
return !(*
this == c); }
109 bool operator<(
const FreeSlice &c)
const {
110 if (container != c.container)
return container < c.container;
111 if (range != c.range)
return range < c.range;
112 if (lr.start != c.lr.start)
return lr.start < c.lr.start;
113 if (lr.end != c.lr.end)
return lr.end < c.lr.end;
120 if (lr.start.first > stage || (lr.start.first == stage && !lr.start.second.isRead())) {
123 if (lr.end.first < stage || (lr.end.first == stage && !lr.end.second.isWrite())) {
129 friend std::ostream &operator<<(std::ostream &,
const FreeSlice &);
139 using ContainerSequences = std::set<ContainerSequence>;
149 const std::list<ContainerGroup *> containerGroups;
153 std::map<Container, ContainerGroup *> groupForContainer;
154 std::map<const Field *, std::set<StageAndAccess>> nonMochaStagesForField;
155 std::map<const Field *, std::set<StageAndAccess>> nonDarkStagesForField;
157 std::set<StageAndAccess> getMochaIncompatibleStagesForField(
const Field *field)
const;
158 std::set<StageAndAccess> getDarkIncompatibleStagesForField(
const Field *field)
const;
163 const std::list<ContainerGroup *> &containerGroups,
172 ContainerSequences
buildContainerSeqs(
const std::set<FreeSlice> &avail, StageAndAccess begin,
173 StageAndAccess end)
const;
182 static void report(
const ContainerSequences &splits);
199 const std::list<const PHV::SuperCluster *> &unallocated;
206 const IR::Node *apply_visitor(
const IR::Node *root,
const char *name = 0)
override;
210 const std::list<const PHV::SuperCluster *> &unallocated,
PhvInfo &phv,
214 : getAllocFn(getAllocFn),
215 unallocated(unallocated),
219 liveRangeMap(liveRangeMap),
220 nonMochaDark(nonMochaDark) {}
Definition dark_live_range.h:40
Definition non_mocha_dark_fields.h:29
Definition ordered_set.h:32
Definition phv/utils/utils.h:117
Definition phv/utils/utils.h:506
Definition live_range_split.h:35
void setRange(StageAndAccess begin, StageAndAccess end, le_bitrange range)
Set bits in range for stage span [begin, end].
Definition live_range_split.cpp:64
std::vector< le_bitrange > availBitsAt(PHV::StageAndAccess sa, unsigned minLength=0)
Definition live_range_split.h:89
Definition phv_fields.h:154
Definition phv_fields.h:898
Definition fieldslice_live_range.h:35
Definition live_range_split.h:134
ContainerSequences buildContainerSeqs(const std::set< FreeSlice > &avail, StageAndAccess begin, StageAndAccess end) const
Builds a list of all possible allocations.
Definition live_range_split.cpp:460
std::set< FreeSlice > buildContainerOccupancy(StageAndAccess begin, StageAndAccess end, const FieldSlice &fs) const
For each stage, find container (slices) that are available at each one.
Definition live_range_split.cpp:213
ContainerSequences findLiveRangeSplits(StageAndAccess begin, StageAndAccess end, const FieldSlice &fs) const
Definition live_range_split.cpp:567
Definition live_range_split.h:197
Definition phv_fields.h:1095
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Definition table_dependency_graph.h:52
Definition allocate_phv.h:55
Definition live_range_split.h:99
bool isFullyAvailableAt(int stage) const
Definition live_range_split.h:119