P4C
The P4 Compiler
Loading...
Searching...
No Matches
live_range_shrinking.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PHV_ANALYSIS_LIVE_RANGE_SHRINKING_H_
20#define BACKENDS_TOFINO_BF_P4C_PHV_ANALYSIS_LIVE_RANGE_SHRINKING_H_
21
22#include "backends/tofino/bf-p4c/common/field_defuse.h"
23#include "backends/tofino/bf-p4c/common/map_tables_to_actions.h"
24#include "backends/tofino/bf-p4c/mau/table_dependency_graph.h"
25#include "backends/tofino/bf-p4c/mau/table_flow_graph.h"
26#include "backends/tofino/bf-p4c/mau/table_mutex.h"
27#include "backends/tofino/bf-p4c/phv/action_phv_constraints.h"
28#include "backends/tofino/bf-p4c/phv/analysis/dominator_tree.h"
29#include "backends/tofino/bf-p4c/phv/analysis/meta_live_range.h"
30#include "backends/tofino/bf-p4c/phv/mau_backtracker.h"
31#include "backends/tofino/bf-p4c/phv/phv_fields.h"
32#include "backends/tofino/bf-p4c/phv/pragma/pa_no_init.h"
33#include "backends/tofino/bf-p4c/phv/transforms/auto_alias.h"
34#include "backends/tofino/bf-p4c/phv/utils/utils.h"
35
39 private:
40 const BuildDominatorTree &domTree;
41 const PhvInfo &phv;
42 const FieldDefUse &defuse;
43 const DependencyGraph &dg;
45 const MapTablesToActions &tablesToActions;
46 const MetadataLiveRange &metaLiveMap;
47 const ActionPhvConstraints &actionConstraints;
48 const TablesMutuallyExclusive &tableMutex;
49 const ordered_map<gress_t, FlowGraph> &flowGraph;
50 const DetermineCandidateHeaders &noInitPacketFields;
51 const MauBacktracker &tableAlloc;
52
54 // therefore, cannot have a bitmasked-set operation in them).
55 // TODO: For now, disable initialization at all such actions (and tables that contain those
56 // actions). In the longer term, change this to recognize when a bitmasked-set operation/action
57 // data is necessary to realize the initialization operation.
59
61 int maxStages = -1;
62
63 profile_t init_apply(const IR::Node *root) override;
64 bool preorder(const IR::MAU::Table *tbl) override;
65 bool preorder(const IR::MAU::Action *act) override;
66
69 bool ignoreDeparserUseForPacketField(const PHV::Field *f,
70 const PHV::UnitSet &f_dominators) const;
71
76 bool summarizeUseDefs(
77 const PHV::Field *f, const ordered_set<const IR::BFN::Unit *> &initPoints,
79 PHV::UnitSet &f_dominators) const;
80
82 bool canInitTableReachGUnits(const IR::MAU::Table *table, const PHV::UnitSet &g_units) const;
83
85 bool canFUsesReachInitTable(const IR::MAU::Table *initTable, const PHV::UnitSet &f_units) const;
86
91 std::optional<const PHV::ActionSet> getInitializationCandidates(
92 const PHV::Container &c, const PHV::Field *f, const IR::MAU::Table *t,
93 const ordered_map<const IR::BFN::Unit *, unsigned> &u, const int lastAllowedStage,
94 const ordered_set<const IR::MAU::Table *> &fStrictDominators, const PHV::Field *prevField,
96 const PHV::Allocation::MutuallyLiveSlices &container_state,
97 const PHV::Transaction &alloc) const;
98
107 bool mayViolatePackConflict(const IR::MAU::Table *initTable, const PHV::Field *initField,
108 const PHV::Allocation::MutuallyLiveSlices &container_state,
109 const PHV::Transaction &alloc) const;
110
112 std::optional<const PHV::ActionSet> getInitPointsForTable(
113 const PHV::Container &c, const IR::MAU::Table *t, const PHV::Field *f,
115 const PHV::Allocation::MutuallyLiveSlices &container_state, const PHV::Transaction &alloc,
116 bool ignoreMutex = false) const;
117
122 bool increasesDependenceCriticalPath(const IR::MAU::Table *use,
123 const IR::MAU::Table *init) const;
124
127 ordered_set<const IR::MAU::Table *> getTableUsesForField(const PHV::Field *f, bool uses = true,
128 bool defs = true) const;
129
138 bool filterOutMutexFields(std::vector<const PHV::Field *> &fields,
139 const ordered_map<int, std::pair<int, int>> &livemap) const;
140
142 bool cannotInitInAction(const PHV::Container &c, const IR::MAU::Action *action,
143 const PHV::Transaction &alloc) const;
144
145 public:
149 std::optional<PHV::Allocation::LiveRangeShrinkingMap> findInitializationNodes(
150 const PHV::Container c, const ordered_set<PHV::AllocSlice> &alloced,
151 const PHV::Transaction &alloc,
152 const PHV::Allocation::MutuallyLiveSlices &container_state) const;
153
157 cstring indent) const;
158
159 explicit FindInitializationNode(const BuildDominatorTree &d, const PhvInfo &p,
160 const FieldDefUse &u, const DependencyGraph &g,
162 const MapTablesToActions &t, const MetadataLiveRange &l,
165 const DetermineCandidateHeaders &c, const MauBacktracker &bt)
166 : domTree(d),
167 phv(p),
168 defuse(u),
169 dg(g),
170 noInit(i),
171 tablesToActions(t),
172 metaLiveMap(l),
173 actionConstraints(a),
174 tableMutex(m),
175 flowGraph(fg),
176 noInitPacketFields(c),
177 tableAlloc(bt) {}
178};
179
184 private:
185 TablesMutuallyExclusive tableMutex;
186 MapTablesToActions tableActionsMap;
187 DetermineCandidateHeaders noInitPacketFields;
188 FindInitializationNode initNode;
189
190 public:
191 const MapTablesToActions &getTableActionsMap() const { return tableActionsMap; }
192
193 std::optional<PHV::Allocation::LiveRangeShrinkingMap> findInitializationNodes(
194 const ordered_set<PHV::AllocSlice> &alloced, const PHV::Transaction &alloc,
195 const PHV::Allocation::MutuallyLiveSlices &container_state) const {
197 for (auto &sl : alloced) {
198 if (c == PHV::Container()) {
199 c = sl.container();
200 } else {
201 BUG_CHECK(c == sl.container(),
202 "Containers for metadata overlay candidates are different");
203 }
204 }
205 BUG_CHECK(c != PHV::Container(),
206 "Container candidate for metadata overlay cannot be NULL.");
207 return initNode.findInitializationNodes(c, alloced, alloc, container_state);
208 }
209
210 std::optional<PHV::Allocation::LiveRangeShrinkingMap> findInitializationNodes(
211 const ordered_set<PHV::AllocSlice> &alloced, const PHV::AllocSlice &slice,
212 const PHV::Transaction &alloc,
213 const PHV::Allocation::MutuallyLiveSlices &container_state) const {
215 candidates.insert(alloced.begin(), alloced.end());
216 candidates.insert(slice);
217 return findInitializationNodes(candidates, alloc, container_state);
218 }
219
223 cstring indent) const {
224 return initNode.printLiveRangeShrinkingMap(m, indent);
225 }
226
227 explicit LiveRangeShrinking(const PhvInfo &p, const FieldDefUse &u, const DependencyGraph &g,
228 const PragmaNoInit &i, const MetadataLiveRange &l,
229 const ActionPhvConstraints &a, const BuildDominatorTree &d,
230 const MauBacktracker &bt);
231};
232
233#endif /* BACKENDS_TOFINO_BF_P4C_PHV_ANALYSIS_LIVE_RANGE_SHRINKING_H_ */
Definition action_phv_constraints.h:107
Definition dominator_tree.h:32
Definition auto_alias.h:27
Definition live_range_shrinking.h:38
std::optional< PHV::Allocation::LiveRangeShrinkingMap > findInitializationNodes(const PHV::Container c, const ordered_set< PHV::AllocSlice > &alloced, const PHV::Transaction &alloc, const PHV::Allocation::MutuallyLiveSlices &container_state) const
Definition live_range_shrinking.cpp:611
cstring printLiveRangeShrinkingMap(const PHV::Allocation::LiveRangeShrinkingMap &m, cstring indent) const
Definition live_range_shrinking.cpp:1079
Definition live_range_shrinking.h:183
cstring printLiveRangeShrinkingMap(const PHV::Allocation::LiveRangeShrinkingMap &m, cstring indent) const
Definition live_range_shrinking.h:222
Definition map_tables_to_actions.h:29
Definition mau_backtracker.h:29
Definition meta_live_range.h:41
Definition node.h:94
Definition visitor.h:400
Definition ir/pass_manager.h:40
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition slice_alloc.h:136
Definition phv.h:176
Definition phv_fields.h:154
Definition phv/utils/utils.h:561
Definition phv_fields.h:1095
Definition mau/table_mutex.h:110
Adds the no_init pragma to the specified fields with the specified gress.
Definition pa_no_init.h:35
Definition field_defuse.h:77
Definition table_dependency_graph.h:52