P4C
The P4 Compiler
Loading...
Searching...
No Matches
table_replay_friendly_constraints.h
1
19#ifndef BF_P4C_PHV_V2_TABLE_REPLAY_FRIENDLY_CONSTRAINTS_H_
20#define BF_P4C_PHV_V2_TABLE_REPLAY_FRIENDLY_CONSTRAINTS_H_
21
22#include <algorithm>
23
24#include "bf-p4c/common/field_defuse.h"
25#include "bf-p4c/common/utils.h"
26#include "bf-p4c/phv/mau_backtracker.h"
27#include "bf-p4c/phv/pragma/pa_no_init.h"
28
29struct AllocInfo {
30 int length;
31 size_t container_size;
32 ordered_set<cstring> pack_with;
33 bool perfectly_aligned;
34};
35
36std::ostream &operator<<(std::ostream &out, const AllocInfo &ai);
37
38namespace PHV {
39namespace v2 {
40
41// This pass adds a few pa_container_size constraints based on the feedback from table summary after
42// table replay failure. These pa_container_size constraints are trying to replay the trivial
43// allocation result for the problematic table provided by table summary. And this can potentially
44// fix the problematic's fitting issue and advance the table replay.
46 MauBacktracker &mau_backtracker;
47 PhvInfo &phv;
48 const ordered_map<cstring, ordered_map<int, AllocInfo>> &trivial_allocation_info;
49 const ordered_map<cstring, ordered_map<int, AllocInfo>> &real_allocation_info;
50 // extra pa_container_size pragmas to fix table replay
52 // extra pa_no_pack pragmas to fix table replay
54 // problematic_table during table replay found by table_summary
55 const IR::MAU::Table *problematic_table = nullptr;
56 // field candidates to fix in the problematic table
57 ordered_set<const PHV::Field *> field_candidates;
58 // a map from action to a set of fields in this action
60 // a set of field that has the same phv size allocation in both trivial and real phv allocation
61 ordered_set<const PHV::Field *> container_size_ok;
62
63 public:
64 const ordered_map<cstring, std::vector<PHV::Size>> &get_container_size_constr() {
65 return add_pa_container_size;
66 }
67 const ordered_map<cstring, ordered_set<cstring>> &get_no_pack_constr() {
68 return add_pa_no_pack;
69 }
71 MauBacktracker &mau_backtracker, PhvInfo &phv,
72 const ordered_map<cstring, ordered_map<int, AllocInfo>> &trivial_allocation_info,
73 const ordered_map<cstring, ordered_map<int, AllocInfo>> &real_allocation_info)
74 : mau_backtracker(mau_backtracker),
75 phv(phv),
76 trivial_allocation_info(trivial_allocation_info),
77 real_allocation_info(real_allocation_info) {}
78
79 const IR::Node *preorder(IR::BFN::Pipe *pipe) override;
80 const IR::Node *preorder(IR::Expression *expr) override;
81
82 const IR::Node *postorder(IR::BFN::Pipe *pipe) override {
83 LOG5("print all pa container size");
84 LOG5("pipe is " + pipe->canon_name());
85 for (auto &it : add_pa_container_size) {
86 LOG5(it.first);
87 for (auto size : it.second) {
88 LOG5(size);
89 }
90 }
91 return pipe;
92 }
93 void end_apply(const IR::Node *) override;
94};
95
96// This table collects PHV allocation results after phv analysis. It provides information for
97// TableReplayFriendlyPhvConstraints, so that it can replay trivial phv allocation result for some
98// table
100 // This data structure maps the name of a field to a map that maps alignment to AllocInfo.
101 // For example, if a field's name is f and it has two AllocSlice, one is allocating [7:0] to a
102 // 8-bit container, another is allocation [8:15] to another 8-bit container. Then one entry of
103 // allocation info is f -> { { 0 -> { length = 8, container_size = 8 },
104 // { 8 -> { length = 8, container_size = 8 } } }}
107 PhvInfo &phv;
108 MauBacktracker &mau_backtracker;
109
110 public:
112 : phv(phv), mau_backtracker(mau_backtracker) {}
113 void end_apply(const IR::Node *) override;
114 const ordered_map<cstring, ordered_map<int, AllocInfo>> &get_trivial_allocation_info() {
115 return trivial_allocation_info;
116 }
117 const ordered_map<cstring, ordered_map<int, AllocInfo>> &get_real_allocation_info() {
118 return real_allocation_info;
119 }
120};
121
122} // namespace v2
123} // namespace PHV
124
125#endif /* BF_P4C_PHV_V2_TABLE_REPLAY_FRIENDLY_CONSTRAINTS_H_ */
Definition mau_backtracker.h:29
Definition node.h:95
Definition visitor.h:400
Definition visitor.h:424
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition table_replay_friendly_constraints.h:99
Definition table_replay_friendly_constraints.h:45
Definition phv_fields.h:1095
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Definition table_replay_friendly_constraints.h:29