P4C
The P4 Compiler
Loading...
Searching...
No Matches
jbay_phv_analysis.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PHV_ANALYSIS_JBAY_PHV_ANALYSIS_H_
20#define BACKENDS_TOFINO_BF_P4C_PHV_ANALYSIS_JBAY_PHV_ANALYSIS_H_
21
22#include <optional>
23
24#include "bf-p4c/common/field_defuse.h"
25#include "bf-p4c/mau/table_dependency_graph.h"
26#include "bf-p4c/phv/action_phv_constraints.h"
27#include "bf-p4c/phv/phv_fields.h"
28#include "bf-p4c/phv/utils/utils.h"
29#include "ir/ir.h"
30
31class JbayPhvAnalysis : public Inspector {
32 private:
33 const PhvInfo &phv;
34 const PhvUse &uses;
35 const DependencyGraph &dg;
36 // const FieldDefUse &defuse;
37 ActionPhvConstraints &actions;
38
39 enum field_uses_t {
40 PARDE = 1,
41 MAU = (1 << 1),
42 STAGE1 = (1 << 2),
43 STAGEN = (1 << 3),
44 IPXBAR = (1 << 4),
45 ALU = (1 << 5)
46 };
47
48 enum phv_types_t { NORMAL = 1, MOCHA = (1 << 1), DARK = (1 << 2), TPHV = (1 << 3) };
49
50 enum field_types_t { HEADER = 1, METADATA = (1 << 1), POV = (1 << 2) };
51
52 enum use_types_t { MATCH = 1, READ = (1 << 1), WRITE = (1 << 2) };
53
56
58 std::vector<const IR::MAU::Table *> tableStack;
60
64
67
68 ordered_map<int, size_t> stageNormal;
69 ordered_map<int, size_t> stageEither;
70 ordered_map<int, size_t> stageMocha;
72
73 profile_t init_apply(const IR::Node *root) override;
74 bool preorder(const IR::MAU::Table *tbl) override;
75 bool preorder(const IR::MAU::TableKey *read) override;
76 bool preorder(const IR::MAU::Action *act) override;
77 void postorder(const IR::MAU::Table *tbl) override;
78 void end_apply() override;
79
80 size_t totalBits() const;
81 size_t totalAllocatedBits() const;
82 size_t totalPhvBits() const;
83 size_t totalTPhvBits();
84 size_t totalHeaderBits() const;
85 size_t totalMetadataBits() const;
86 size_t totalPOVBits() const;
87
88 size_t usedInPardeMetadata() const;
89 size_t usedInParde();
90 size_t usedInMau() const;
91 size_t usedInPardeHeader() const;
92 size_t usedInPardePOV() const;
93
94 size_t ingressPhvBits() const;
95 size_t egressPhvBits() const;
96 size_t ingressTPhvBits() const;
97 size_t egressTPhvBits() const;
98
99 size_t aluUseBits();
100 size_t aluUseBitsHeader() const;
101 size_t aluUseBitsMetadata() const;
102 size_t aluUseBitsPOV() const;
103
104 size_t matchingBitsTotal();
105
106 size_t determineDarkCandidates();
107 size_t determineMochaCandidates();
108
109 int longestDependenceChain() const;
110 void printFieldLiveness(int maxStages);
111
112 void assessCandidacy(const PHV::Field *f, int maxStages);
113 void printCandidacy(int maxStages);
114 void printStagewiseStats(int maxStages);
115 void fixPHVAllocation(const PHV::Field *f, int maxStages);
116 void fixMochaAllocation(const PHV::Field *f, int maxStages);
117
118 bool isPHV(const PHV::Field *f) const;
119 bool isHeader(const PHV::Field *f) const;
120 bool isGress(const PHV::Field *f, gress_t gress) const;
121
122 public:
123 explicit JbayPhvAnalysis(const PhvInfo &p, const PhvUse &u, const DependencyGraph &g,
125 : phv(p), uses(u), dg(g), /* defuse(du), */ actions(a) {}
126};
127
128#endif /* BACKENDS_TOFINO_BF_P4C_PHV_ANALYSIS_JBAY_PHV_ANALYSIS_H_ */
Definition action_phv_constraints.h:107
Definition jbay_phv_analysis.h:31
Definition node.h:95
Definition visitor.h:400
Definition visitor.h:78
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv_fields.h:154
Definition phv_fields.h:1095
Definition phv_parde_mau_use.h:154
Definition field_defuse.h:77
Definition table_dependency_graph.h:52