P4C
The P4 Compiler
Loading...
Searching...
No Matches
pa_container_size.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PHV_PRAGMA_PA_CONTAINER_SIZE_H_
20#define BACKENDS_TOFINO_BF_P4C_PHV_PRAGMA_PA_CONTAINER_SIZE_H_
21
22#include <map>
23#include <optional>
24
25#include "bf-p4c/phv/phv_fields.h"
26#include "bf-p4c/phv/utils/utils.h"
27#include "ir/ir.h"
28
29using namespace P4;
30
40 // This pass may mutate field properties, e.g., add no_split on field.
41 PhvInfo &phv_i;
42 // alt-phv-alloc ONLY
43 // this is a set of pa_container_size to fix problematic tables during alt-phv-alloc's table
44 // replay stage.
45 const ordered_map<cstring, std::vector<PHV::Size>> &container_size_constr;
46 // pa_container_sizes_i pragmas collected from program.
48 // field_layouts_i is the expected container layout of the field. It is different
49 // from the above raw pa_container_sizes, e.g. @pa_container_size("f1<32>", 8) will make
50 // pa_container_sizes_i = {f1: [B]}
51 // field_layouts_i = {f1: [8, 8, 8, 8]}.
53
54 profile_t init_apply(const IR::Node *root) override {
55 profile_t rv = Inspector::init_apply(root);
56 pa_container_sizes_i.clear();
57 field_layouts_i.clear();
58 return rv;
59 }
60
62 bool preorder(const IR::BFN::Pipe *pipe) override;
63
65 void end_apply() override;
66
67 // Add no-split constraint if the field has only one container size associated with it adn the
68 // size of the container is larger than or equal to the size of the field. The pragma also
69 // implies that the entire field must be packed into a single specified size container.
70 void check_and_add_no_split(PHV::Field *field) const;
71
72 public:
74 const ordered_map<cstring, std::vector<PHV::Size>> &container_size_constr)
75 : phv_i(phv), container_size_constr(container_size_constr) {}
76 explicit PragmaContainerSize(PhvInfo &phv)
77 : phv_i(phv), container_size_constr(*(new ordered_map<cstring, std::vector<PHV::Size>>)) {}
78
80 static const char *name;
81 static const char *description;
82 static const char *help;
83
84 const ordered_map<const PHV::Field *, std::vector<PHV::Size>> &field_to_sizes() const {
85 return pa_container_sizes_i;
86 }
87
88 // field_to_layout return the container layout of the field.
89 // e.g.
90 // "f1" => [8,8,8,8], @pa_container_size("f1<32>", 8)
91 // "f2" => [8,16], @pa_container_size("f2<16>", 8, 16).
92 const ordered_map<const PHV::Field *, std::vector<int>> &field_to_layout() const {
93 return field_layouts_i;
94 }
95
96 // expected_container_size returns the expected container size for this fs.
97 // if not specified, return std::nullopt, and
98 // if @p fs spans over more than one container, return PHV::Size::null
99 std::optional<PHV::Size> expected_container_size(const PHV::FieldSlice &fs) const;
100
101 bool is_specified(const PHV::Field *field) const { return pa_container_sizes_i.count(field); }
102
106 void add_constraint(const PHV::Field *field, std::vector<PHV::Size> sizes);
107
110 cstring printSizeConstraints(const std::vector<PHV::Size> &sizes) const;
111
116 bool check_and_add_constraint(const PHV::Field *field, std::vector<PHV::Size> sizes);
117};
118
119std::ostream &operator<<(std::ostream &out, const PragmaContainerSize &pa_cs);
120
121#endif /* BACKENDS_TOFINO_BF_P4C_PHV_PRAGMA_PA_CONTAINER_SIZE_H_ */
Definition node.h:95
Definition visitor.h:400
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
Definition phv_fields.h:154
Definition phv_fields.h:898
Definition phv_fields.h:1095
Definition pa_container_size.h:39
static const char * name
BFN::Pragma interface.
Definition pa_container_size.h:80
cstring printSizeConstraints(const std::vector< PHV::Size > &sizes) const
Definition phv/pragma/pa_container_size.cpp:266
bool check_and_add_constraint(const PHV::Field *field, std::vector< PHV::Size > sizes)
Definition phv/pragma/pa_container_size.cpp:275
void add_constraint(const PHV::Field *field, std::vector< PHV::Size > sizes)
Definition phv/pragma/pa_container_size.cpp:259
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24