19#ifndef BF_P4C_LOGGING_PHV_LOGGING_H_
20#define BF_P4C_LOGGING_PHV_LOGGING_H_
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"
42#include "phv_schema.h"
44using Logging::Phv_Schema_Logger;
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;
104 :
phv(p), uses(u), red_info(ri) {}
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;
138 std::string parserState;
141 if (unit != other.unit)
return unit < other.unit;
142 return parserState < other.parserState;
146 return (unit == other.unit && parserState == other.parserState);
149 explicit PardeInfo(std::string u, std::string name =
"") : unit(u), parserState(name) {}
161 const IR::Node *apply_visitor(
const IR::Node *n,
const char *name = 0)
override;
164 void replace_parser_state_name(
cstring old_name,
cstring new_name);
177 enum class ConstraintReason : std::size_t {
183 SolitaryContainerSize,
185 SolitaryExceptSameDigest,
206 const CollectDefUseInfo &defuseInfo;
216 Phv_Schema_Logger logger;
218 profile_t init_apply(
const IR::Node *root)
override {
219 unallocatedSlices.clear();
220 return Inspector::init_apply(root);
223 void end_apply(
const IR::Node *root)
override;
226 void populateContainerGroups(
cstring groupType);
235 const char *getFieldType(
const PHV::Field *f)
const;
238 const char *getGress(
const PHV::Field *f)
const;
240 const char *getDeparserAccessType(
const PHV::Field *f)
const;
243 std::string stripDotPrefix(
const cstring name)
const;
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;
255 PHV::Field::AllocState getAllocatedState(
const PHV::Field *f);
270 FieldInfo *getFieldInfo(
const PHV::Field *f)
const;
276 SourceLocation *getSourceLoc(
const PHV::Field *f)
const;
282 FieldSlice *logFieldSlice(
const PHV::Field *f,
bool use_alias);
295 ContainerSlice *logContainerSlice(
const PHV::AllocSlice &sl,
bool use_alias);
304 void logContainers();
307 void logConstraintReasons();
310 void logFieldConstraints(
const cstring &fieldName, Field *logger);
312 void logSolitaryConstraints(
ConstrainedField &field,
const SourceLocation *srcLoc);
314 void logNoPackConstraint(
ConstrainedField &field,
const FieldInfo *fieldInfo,
315 const SourceLocation *srcLoc);
318 std::vector<ConstrainedSlice> &group);
320 void logMauGroupConstraint(
ConstrainedField &field,
const SourceLocation *srcLoc);
322 void logNoSplitConstraint(
ConstrainedField &field,
const SourceLocation *srcLoc);
324 void logContainerSizeConstraint(
ConstrainedField &field,
const SourceLocation *srcLoc);
326 void logAlignmentConstraint(
ConstrainedField &field,
const SourceLocation *srcLoc);
328 void logNoOverlayConstraint(
ConstrainedField &field,
const SourceLocation *srcLoc);
330 void logExactContainerConstraint(
ConstrainedField &field,
const SourceLocation *srcLoc);
332 void logEquivalentAlignConstraint(
ConstrainedField &field,
const SourceLocation *srcLoc);
334 void logNoHolesConstraint(
ConstrainedField &field,
const SourceLocation *srcLoc);
336 void logSameContainerGroup(
ConstrainedField &field,
const SourceLocation *srcLoc);
342 template <
typename T>
343 int getDatabaseIndex(std::vector<T> &db, T item);
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 mau_visitor.h:29
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition slice_alloc.h:136
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