P4C
The P4 Compiler
Loading...
Searching...
No Matches
phv_kit.h
1
19#ifndef BF_P4C_PHV_V2_PHV_KIT_H_
20#define BF_P4C_PHV_V2_PHV_KIT_H_
21
22#include "backends/tofino/bf-p4c/common/field_defuse.h"
23#include "backends/tofino/bf-p4c/mau/table_mutex.h"
24#include "backends/tofino/bf-p4c/parde/clot/clot_info.h"
25#include "backends/tofino/bf-p4c/phv/action_phv_constraints.h"
26#include "backends/tofino/bf-p4c/phv/action_source_tracker.h"
27#include "backends/tofino/bf-p4c/phv/alloc_setting.h"
28#include "backends/tofino/bf-p4c/phv/analysis/critical_path_clusters.h"
29#include "backends/tofino/bf-p4c/phv/collect_strided_headers.h"
30#include "backends/tofino/bf-p4c/phv/collect_table_keys.h"
31#include "backends/tofino/bf-p4c/phv/fieldslice_live_range.h"
32#include "backends/tofino/bf-p4c/phv/make_clusters.h"
33#include "backends/tofino/bf-p4c/phv/phv.h"
34#include "backends/tofino/bf-p4c/phv/phv_fields.h"
35#include "backends/tofino/bf-p4c/phv/phv_parde_mau_use.h"
36#include "backends/tofino/bf-p4c/phv/pragma/phv_pragmas.h"
37#include "backends/tofino/bf-p4c/phv/slicing/types.h"
38#include "backends/tofino/bf-p4c/phv/v2/action_packing_validator.h"
39#include "backends/tofino/bf-p4c/phv/v2/parser_packing_validator.h"
40
41namespace PHV {
42namespace v2 {
43
46struct PhvKit {
47 // PHV fields and clot info.
48 const PhvInfo &phv;
49 const ClotInfo &clot;
50
51 // clustering results (super clusters) and no_pack constraint found during clustering.
52 const Clustering &clustering;
53
54 // defuses and action constraints.
55 const PhvUse &uses;
56 const FieldDefUse &defuse;
57
58 // action-related constraints
59 const ActionPhvConstraints &actions;
60 const ActionSourceTracker &source_tracker;
61 const CollectTableKeys &tb_keys;
62 const TablesMutuallyExclusive &table_mutex;
63 const DependencyGraph &deps;
64
65 // packing validator that checks whether a set of packing is valid
66 // in terms of action phv constraints.
67 const ActionPackingValidator *packing_validator;
68
69 // Set of fieldSlice's that require explicit initialization in MAU
70 // (selected during trivial allocation in alt-phv-alloc flow)
71 std::set<PHV::FieldRange> &mauInitFields;
72
75
76 // parser-related
77 const MapFieldToParserStates &field_to_parser_states;
78 const CalcParserCriticalPath &parser_critical_path;
79 const CollectParserInfo &parser_info;
80 const CollectStridedHeaders &strided_headers;
81
82 // physical live range (available only after table has been allocated)
83 const PHV::FieldSliceLiveRangeDB &physical_liverange_db;
84
85 // pragma
86 const PHV::Pragmas &pragmas;
87
88 // misc allocation settings.
89 const AllocSetting &settings;
90
91 // provide access to information of last round of table placement.
92 const MauBacktracker &mau;
93
94 PhvKit(const PhvInfo &phv, const ClotInfo &clot, const Clustering &clustering,
95 const PhvUse &uses, const FieldDefUse &defuse, const ActionPhvConstraints &actions,
96 const MapFieldToParserStates &field_to_parser_states,
97 const CalcParserCriticalPath &parser_critical_path, const CollectParserInfo &parser_info,
98 const CollectStridedHeaders &strided_headers,
99 const FieldSliceLiveRangeDB &physical_liverange_db,
100 const ActionSourceTracker &source_tracker, const CollectTableKeys &tb_keys,
101 const TablesMutuallyExclusive &table_mutex, const DependencyGraph &deps,
102 std::set<PHV::FieldRange> &mauInitFields, const Pragmas &pragmas,
103 const AllocSetting &settings, const MauBacktracker &mau)
104 : phv(phv),
105 clot(clot),
106 clustering(clustering),
107 uses(uses),
108 defuse(defuse),
109 actions(actions),
110 source_tracker(source_tracker),
111 tb_keys(tb_keys),
112 table_mutex(table_mutex),
113 deps(deps),
114 packing_validator(new ActionPackingValidator(source_tracker, uses)),
115 mauInitFields(mauInitFields),
116 parser_packing_validator(new ParserPackingValidator(phv, field_to_parser_states,
117 parser_info, defuse,
118 pragmas.pa_no_init(), mauInitFields)),
119 field_to_parser_states(field_to_parser_states),
120 parser_critical_path(parser_critical_path),
121 parser_info(parser_info),
122 strided_headers(strided_headers),
123 physical_liverange_db(physical_liverange_db),
124 pragmas(pragmas),
125 settings(settings),
126 mau(mau) {}
127
128 const SymBitMatrix &mutex() const { return phv.field_mutex(); }
129
130 // has_pack_conflict should be used as the only source of pack conflict checks.
131 // It checks mutex + pack conflict from mau + no pack constraint from cluster.
132 bool has_pack_conflict(const PHV::FieldSlice &fs1, const PHV::FieldSlice &fs2) const;
133
134 HasPackConflict get_has_pack_conflict() const {
135 return [this](const PHV::FieldSlice &fs1, const PHV::FieldSlice &fs2) {
136 return this->has_pack_conflict(fs1, fs2);
137 };
138 }
139
140 // return true if field is used and not padding.
141 bool is_referenced(const PHV::Field *f) const { return !f->padding && uses.is_referenced(f); };
142
144 std::list<PHV::SuperCluster *> make_superclusters() const {
145 return clustering.cluster_groups();
146 }
147
148 // @returns a slicing iterator.
149 PHV::Slicing::IteratorInterface *make_slicing_ctx(const PHV::SuperCluster *sc) const;
150
151 // @returns true if @p a and @p b can be overlaid,
152 // because of their logical live ranges are disjoint and both fieldslices are
153 // qualified to be overlaid. This is important that we don't have cross dependencies between
154 // @p a and @p b if we need to redo table placement.
155 bool can_logical_liverange_be_overlaid(const PHV::AllocSlice &a,
156 const PHV::AllocSlice &b) const;
157 // @returns true if @p a and @p b can be overlaid,
158 // because of their physical live ranges are disjoint and both fieldslices are
159 // qualified to be overlaid:
160 // (1) not pov, deparsed_to_tm, nor is_invalidate_from_arch.
161 // (2) not in pa_no_overlay.
162 bool can_physical_liverange_be_overlaid(const PHV::AllocSlice &a,
163 const PHV::AllocSlice &b) const;
164
166 static bool is_clot_allocated(const ClotInfo &clots, const PHV::SuperCluster &sc);
167
170 static std::list<PHV::ContainerGroup *> make_device_container_groups();
171
173 static void clear_slices(PhvInfo &phv);
174
177 static void bind_slices(const PHV::ConcreteAllocation &alloc, PhvInfo &phv);
178
182 static void sort_and_merge_alloc_slices(PhvInfo &phv);
183
188 static std::list<PHV::SuperCluster *> remove_singleton_metadata_slicelist(
189 const std::list<PHV::SuperCluster *> &cluster_groups);
190
193 static std::list<PHV::SuperCluster *> remove_unref_clusters(
194 const PhvUse &uses, const std::list<PHV::SuperCluster *> &cluster_groups_input);
195
197 static std::list<PHV::SuperCluster *> remove_clot_allocated_clusters(
198 const ClotInfo &clot, std::list<PHV::SuperCluster *> clusters);
199
202 static std::list<PHV::SuperCluster *> create_strided_clusters(
203 const CollectStridedHeaders &strided_headers,
204 const std::list<PHV::SuperCluster *> &cluster_groups);
205
207 static bool is_ternary(const IR::MAU::Table *tbl);
208};
209
210} // namespace v2
211} // namespace PHV
212
213#endif /* BF_P4C_PHV_V2_PHV_KIT_H_ */
Definition action_phv_constraints.h:107
Definition parser_critical_path.h:131
Definition clot_info.h:41
Builds "clusters" of field slices that must be placed in the same group.
Definition make_clusters.h:67
const std::list< PHV::SuperCluster * > & cluster_groups() const
Definition make_clusters.h:548
Definition mau_backtracker.h:29
Definition symbitmatrix.h:27
ActionSourceTracker collects all source-to-destination for all field slices.
Definition action_source_tracker.h:49
Definition slice_alloc.h:136
Definition collect_table_keys.h:27
Definition phv/utils/utils.h:506
Definition phv_fields.h:154
bool padding
True if this Field is a padding field.
Definition phv_fields.h:222
Definition phv_fields.h:898
Definition fieldslice_live_range.h:152
Definition phv_pragmas.h:46
The interface that the iterator must satisfy.
Definition slicing/types.h:108
Definition phv/utils/utils.h:1049
Definition action_packing_validator.h:34
Definition parser_packing_validator.h:42
bool is_referenced(const PHV::Field *f) const
Definition phv_parde_mau_use.cpp:179
Definition phv_fields.h:1095
Definition phv_parde_mau_use.h:154
Definition mau/table_mutex.h:110
Definition field_defuse.h:77
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Definition alloc_setting.h:25
Collects header stacks that require strided allocation (in a parser loop).
Definition collect_strided_headers.h:28
Definition table_dependency_graph.h:52
Map field to the parser states in which they are extracted or assigned from checksums.
Definition phv_fields.h:1755
Definition phv_kit.h:46
static std::list< PHV::SuperCluster * > remove_unref_clusters(const PhvUse &uses, const std::list< PHV::SuperCluster * > &cluster_groups_input)
Definition phv_kit.cpp:244
const ParserPackingValidator * parser_packing_validator
parser packing validator checks whether a packing would break parser constraints.
Definition phv_kit.h:74
std::list< PHV::SuperCluster * > make_superclusters() const
Definition phv_kit.h:144
static void sort_and_merge_alloc_slices(PhvInfo &phv)
Definition phv_kit.cpp:359
static bool is_ternary(const IR::MAU::Table *tbl)
Definition phv_kit.cpp:391
static std::list< PHV::SuperCluster * > create_strided_clusters(const CollectStridedHeaders &strided_headers, const std::list< PHV::SuperCluster * > &cluster_groups)
Definition phv_kit.cpp:315
static void clear_slices(PhvInfo &phv)
clear alloc_slices allocated in phv, if any.
Definition phv_kit.cpp:300
static bool is_clot_allocated(const ClotInfo &clots, const PHV::SuperCluster &sc)
Definition phv_kit.cpp:176
static void bind_slices(const PHV::ConcreteAllocation &alloc, PhvInfo &phv)
Definition phv_kit.cpp:305
static std::list< PHV::SuperCluster * > remove_singleton_metadata_slicelist(const std::list< PHV::SuperCluster * > &cluster_groups)
Definition phv_kit.cpp:205
static std::list< PHV::ContainerGroup * > make_device_container_groups()
Definition phv_kit.cpp:267
static std::list< PHV::SuperCluster * > remove_clot_allocated_clusters(const ClotInfo &clot, std::list< PHV::SuperCluster * > clusters)
Definition phv_kit.cpp:258