P4C
The P4 Compiler
Loading...
Searching...
No Matches
phv_logging.h
1
19#ifndef BF_P4C_LOGGING_PHV_LOGGING_H_
20#define BF_P4C_LOGGING_PHV_LOGGING_H_
21
22#include <algorithm>
23#include <string>
24
25#include "backends/tofino/bf-p4c/common/field_defuse.h"
26#include "backends/tofino/bf-p4c/device.h"
27#include "backends/tofino/bf-p4c/ir/tofino_write_context.h"
28#include "backends/tofino/bf-p4c/logging/constrained_fields.h"
29#include "backends/tofino/bf-p4c/logging/group_constraint_extractor.h"
30#include "backends/tofino/bf-p4c/logging/logging.h"
31#include "backends/tofino/bf-p4c/mau/action_analysis.h"
32#include "backends/tofino/bf-p4c/mau/table_summary.h"
33#include "backends/tofino/bf-p4c/parde/clot/clot_info.h"
34#include "backends/tofino/bf-p4c/phv/constraints/constraints.h"
35#include "backends/tofino/bf-p4c/phv/make_clusters.h"
36#include "backends/tofino/bf-p4c/phv/phv_fields.h"
37#include "backends/tofino/bf-p4c/phv/phv_parde_mau_use.h"
38#include "backends/tofino/bf-p4c/phv/phv_spec.h"
39#include "backends/tofino/bf-p4c/phv/pragma/phv_pragmas.h"
40#include "backends/tofino/bf-p4c/phv/utils/utils.h"
41#include "ir/ir.h"
42#include "phv_schema.h"
43
44using Logging::Phv_Schema_Logger;
45using namespace P4;
46
54 const PhvInfo &phv;
55 const PhvUse &uses;
56 const ReductionOrInfo &red_info;
57
60
64
67
70
73
76 ConstrainedFieldMap fieldConstraints;
77
79 const std::list<PHV::SuperCluster *> *superclusters = nullptr;
80
82 const PHV::Pragmas *pragmas = nullptr;
83
86
89
90 EquivalentAlignExtractor *equivAlignConstraints = nullptr;
91
92 void collectConstraints();
93
95 profile_t init_apply(const IR::Node *root) override;
97 bool preorder(const IR::MAU::Table *tbl) override;
99 bool preorder(const IR::MAU::Action *act) override;
101 bool preorder(const IR::MAU::TableKey *read) override;
102
103 CollectPhvLoggingInfo(const PhvInfo &p, const PhvUse &u, const ReductionOrInfo &ri)
104 : phv(p), uses(u), red_info(ri) {}
105
106 private:
109 ordered_set<PHV::FieldSlice> getSlices(const IR::Expression *, const IR::MAU::Table *);
110};
111
115class PhvLogging : public MauInspector {
116 public:
117 using Phv_Schema_Logger = Logging::Phv_Schema_Logger;
118 using Structure = Phv_Schema_Logger::Structure;
119 using Container = Phv_Schema_Logger::Container;
120 using FieldInfo = Phv_Schema_Logger::FieldInfo;
121 using FieldGroupItem = Phv_Schema_Logger::FieldGroupItem;
122 using Field = Phv_Schema_Logger::Field;
123 using Slice = Phv_Schema_Logger::Slice;
124 using FieldSlice = Phv_Schema_Logger::FieldSlice;
125 using SourceLocation = Phv_Schema_Logger::SourceLocation;
126 using BoolConstraint = Phv_Schema_Logger::BoolConstraint;
127 using IntConstraint = Phv_Schema_Logger::IntConstraint;
128 using ListConstraint = Phv_Schema_Logger::ListConstraint;
129 using Constraint = Phv_Schema_Logger::Constraint;
130 using ParserLocation = Phv_Schema_Logger::ParserLocation;
131 using DeparserLocation = Phv_Schema_Logger::DeparserLocation;
132 using MAULocation = Phv_Schema_Logger::MAULocation;
133 using ContainerSlice = Phv_Schema_Logger::ContainerSlice;
134 using Access = Phv_Schema_Logger::Access;
135 using Resources = Phv_Schema_Logger::Resources;
136 struct PardeInfo {
137 std::string unit;
138 std::string parserState;
139
140 bool operator<(PardeInfo other) const {
141 if (unit != other.unit) return unit < other.unit;
142 return parserState < other.parserState;
143 }
144
145 bool operator==(PardeInfo other) const {
146 return (unit == other.unit && parserState == other.parserState);
147 }
148
149 explicit PardeInfo(std::string u, std::string name = "") : unit(u), parserState(name) {}
150 };
151
157 class CollectDefUseInfo : public Visitor {
159 const FieldDefUse &defuse;
160
161 const IR::Node *apply_visitor(const IR::Node *n, const char *name = 0) override;
162
163 public:
164 void replace_parser_state_name(cstring old_name, cstring new_name);
173
174 explicit CollectDefUseInfo(const FieldDefUse &du) : defuse(du) {}
175 };
176
177 enum class ConstraintReason : std::size_t {
178 SolitaryAlu = 0,
179 SolitaryIntrinsic,
180 SolitaryChecksum,
181 SolitaryLastByte,
182 SolitaryMirror,
183 SolitaryContainerSize,
184 SolitaryPragma,
185 SolitaryExceptSameDigest,
186 DifferentContainer,
187 MAUGroup,
188 NoSplit,
189 ContainerSize,
190 Alignment,
191 NoOverlay,
192 ExactContainer,
193 EquivalentAlignment,
194 NoHoles,
195 SameContainerGroup
196 };
197
198 private:
200 const PhvInfo &phv;
202 const ClotInfo &clot;
204 const CollectPhvLoggingInfo &info;
206 const CollectDefUseInfo &defuseInfo;
208 const ordered_map<cstring, ordered_set<int>> &tableAlloc;
210 const TableSummary &tableSummary;
211
213 ordered_set<PHV::FieldSlice> unallocatedSlices;
214
216 Phv_Schema_Logger logger;
217
218 profile_t init_apply(const IR::Node *root) override {
219 unallocatedSlices.clear();
220 return Inspector::init_apply(root);
221 }
222
223 void end_apply(const IR::Node *root) override;
224
226 void populateContainerGroups(cstring groupType);
227
229
231 const char *containerType(const PHV::Container c) const;
232
235 const char *getFieldType(const PHV::Field *f) const;
236
238 const char *getGress(const PHV::Field *f) const;
239
240 const char *getDeparserAccessType(const PHV::Field *f) const;
241
242 // @returns the name with the prefix '.' stripped out
243 std::string stripDotPrefix(const cstring name) const;
244
245 void getAllParserDefs(const PHV::Field *f, ordered_set<PardeInfo> &rv) const;
246 void getAllDeparserUses(const PHV::Field *f, ordered_set<PardeInfo> &rv) const;
247
248 void addPardeReadsAndWrites(const PHV::Field *f, ordered_set<PardeInfo> &rv,
249 ContainerSlice *cs) const;
250 void addTableKeys(const PHV::FieldSlice &sl, ContainerSlice *cs) const;
251 void addVLIWReads(const PHV::FieldSlice &sl, ContainerSlice *cs) const;
252 void addVLIWWrites(const PHV::FieldSlice &sl, ContainerSlice *cs) const;
253 void addMutexFields(const PHV::AllocSlice &sl, ContainerSlice *cs) const;
254
255 PHV::Field::AllocState getAllocatedState(const PHV::Field *f);
256
262
266
270 FieldInfo *getFieldInfo(const PHV::Field *f) const;
271
276 SourceLocation *getSourceLoc(const PHV::Field *f) const;
277
282 FieldSlice *logFieldSlice(const PHV::Field *f, bool use_alias);
283
288 FieldSlice *logFieldSlice(const PHV::AllocSlice &sl, bool use_alias);
289
295 ContainerSlice *logContainerSlice(const PHV::AllocSlice &sl, bool use_alias);
296
298 void logHeaders();
299
301 void logFields();
302
304 void logContainers();
305
306 // Add database of constraint reasons
307 void logConstraintReasons();
308
309 // Add field constraint information to the logger object
310 void logFieldConstraints(const cstring &fieldName, Field *logger);
311
312 void logSolitaryConstraints(ConstrainedField &field, const SourceLocation *srcLoc);
313
314 void logNoPackConstraint(ConstrainedField &field, const FieldInfo *fieldInfo,
315 const SourceLocation *srcLoc);
316
317 void logGroupConstraint(ConstrainedField &field, ListConstraint *c,
318 std::vector<ConstrainedSlice> &group);
319
320 void logMauGroupConstraint(ConstrainedField &field, const SourceLocation *srcLoc);
321
322 void logNoSplitConstraint(ConstrainedField &field, const SourceLocation *srcLoc);
323
324 void logContainerSizeConstraint(ConstrainedField &field, const SourceLocation *srcLoc);
325
326 void logAlignmentConstraint(ConstrainedField &field, const SourceLocation *srcLoc);
327
328 void logNoOverlayConstraint(ConstrainedField &field, const SourceLocation *srcLoc);
329
330 void logExactContainerConstraint(ConstrainedField &field, const SourceLocation *srcLoc);
331
332 void logEquivalentAlignConstraint(ConstrainedField &field, const SourceLocation *srcLoc);
333
334 void logNoHolesConstraint(ConstrainedField &field, const SourceLocation *srcLoc);
335
336 void logSameContainerGroup(ConstrainedField &field, const SourceLocation *srcLoc);
337
338 // Looks up item in db. If item is not there, it is added.
339 // Index of the item is then returned.
340 // This template is supposed to be used with FieldGroupItem
341 // and FieldGroups
342 template <typename T>
343 int getDatabaseIndex(std::vector<T> &db, T item);
344
345 public:
346 explicit PhvLogging(const char *filename, const PhvInfo &p, const ClotInfo &ci,
347 const CollectPhvLoggingInfo &c, const CollectDefUseInfo &cdu,
348 const ordered_map<cstring, ordered_set<int>> &t, const TableSummary &ts);
349};
350
351#endif /* BF_P4C_LOGGING_PHV_LOGGING_H_ */
Definition clot_info.h:41
Class representing PHV::Field with constraints and handle for constraint logging. Contains non-group ...
Definition constrained_fields.h:80
Definition group_constraint_extractor.h:71
Definition group_constraint_extractor.h:56
Definition mau_visitor.h:29
Definition node.h:94
Definition visitor.h:78
Definition visitor.h:75
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_fields.h:898
Definition phv_pragmas.h:46
Definition phv_fields.h:1095
Definition phv_logging.h:157
ordered_map< int, ordered_set< cstring > > parser_defs
Definition phv_logging.h:168
ordered_map< int, ordered_set< cstring > > deparser_uses
Definition phv_logging.h:172
Definition phv_logging.h:115
Definition phv_parde_mau_use.h:154
Definition common/asm_output.h:47
Definition table_summary.h:158
Definition field_defuse.h:77
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition phv_logging.h:52
const std::list< PHV::SuperCluster * > * superclusters
Superclusters used to extract certain group constraints (MAU groups, equivalent alignment)
Definition phv_logging.h:79
ordered_map< cstring, ordered_map< cstring, bool > > noPackConstraints
Extracted no pack (different container) constraints.
Definition phv_logging.h:85
ConstrainedFieldMap fieldConstraints
Definition phv_logging.h:76
void collectConstraints()
Definition phv_logging.cpp:26
ordered_map< const IR::MAU::Action *, const IR::MAU::Table * > actionsToTables
Definition phv_logging.h:63
const PHV::Pragmas * pragmas
Pointer to pragma object computed during PHV Analysis.
Definition phv_logging.h:82
ordered_map< cstring, cstring > tableNames
Mapping of table names in the backend to the P4 name.
Definition phv_logging.h:59
ordered_map< const PHV::FieldSlice, ordered_set< const IR::MAU::Action * > > sliceWriteToActions
Mapping from a FieldSlice to all the actions in which it is written.
Definition phv_logging.h:66
ordered_map< const PHV::FieldSlice, ordered_set< cstring > > sliceXbarToTables
Mapping from a FieldSlice to all the tables in which it is used in the input crossbar.
Definition phv_logging.h:72
bool preorder(const IR::MAU::Table *tbl) override
Gather the P4 names of all tables allocated.
Definition phv_logging.cpp:68
ordered_map< const PHV::FieldSlice, ordered_set< const IR::MAU::Action * > > sliceReadToActions
Mapping from a FieldSlice to all the actions in which it is read.
Definition phv_logging.h:69
const PhvInfo & phv
Information about PHV fields.
Definition phv_logging.h:54
profile_t init_apply(const IR::Node *root) override
Clear all local state.
Definition phv_logging.cpp:52
MauGroupExtractor * mauGroupConstraints
Extracted MAU group constraints.
Definition phv_logging.h:88
Definition phv_logging.h:136
Definition reduction_or.h:47