P4C
The P4 Compiler
Loading...
Searching...
No Matches
phv_pragmas.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PHV_PRAGMA_PHV_PRAGMAS_H_
20#define BACKENDS_TOFINO_BF_P4C_PHV_PRAGMA_PHV_PRAGMAS_H_
21
22#include "bf-p4c/bf-p4c-options.h"
23#include "bf-p4c/phv/pragma/pa_alias.h"
24#include "bf-p4c/phv/pragma/pa_atomic.h"
25#include "bf-p4c/phv/pragma/pa_byte_pack.h"
26#include "bf-p4c/phv/pragma/pa_container_size.h"
27#include "bf-p4c/phv/pragma/pa_container_type.h"
28#include "bf-p4c/phv/pragma/pa_deparser_zero.h"
29#include "bf-p4c/phv/pragma/pa_mutually_exclusive.h"
30#include "bf-p4c/phv/pragma/pa_no_init.h"
31#include "bf-p4c/phv/pragma/pa_no_overlay.h"
32#include "bf-p4c/phv/pragma/pa_no_pack.h"
33#include "bf-p4c/phv/pragma/pa_solitary.h"
34
35using namespace P4;
36
37namespace PHV {
38namespace pragma {
39
40constexpr const char *NOT_PARSED = "not_parsed";
41constexpr const char *NOT_DEPARSED = "not_deparsed";
42constexpr const char *DISABLE_DEPARSE_ZERO = "pa_disable_deparse_0_optimization";
43
44} // namespace pragma
45
46class Pragmas : public PassManager {
47 public:
48 static bool gressValid(cstring gress);
50 unsigned &expr_index, unsigned &required_args,
51 const IR::StringLiteral *&pipe_arg,
52 const IR::StringLiteral *&gress_arg);
53 static bool checkStringLiteralArgs(const IR::Vector<IR::Expression> &exprs);
54 static bool checkNumberArgs(const IR::Annotation *annotation, unsigned required_args,
55 const unsigned min_required_args, bool exact_number_of_args,
56 cstring pragma_name, cstring pragma_args_wo_pipe);
57 static bool checkPipeApplication(const IR::Annotation *annotation, const IR::BFN::Pipe *pipe,
58 const IR::StringLiteral *pipe_arg);
59 static void reportNoMatchingPHV(const IR::BFN::Pipe *pipe, const IR::Expression *expr,
60 cstring field_name = ""_cs);
61
62 private:
63 PragmaContainerSize pa_container_sizes_i;
64 PragmaMutuallyExclusive pa_mutually_exclusive_i;
65 PragmaSolitary pa_solitary_i;
66 PragmaAtomic pa_atomic_i;
67 PragmaNoOverlay pa_no_overlay_i;
68 PragmaContainerType pa_container_type_i;
69 PragmaNoInit pa_no_init_i;
70 PragmaDeparserZero pa_deparser_zero_i;
71 PragmaNoPack pa_no_pack_i;
72 PragmaBytePack pa_byte_pack_i;
73
74 public:
75 const PragmaContainerSize &pa_container_sizes() const { return pa_container_sizes_i; }
76 PragmaContainerSize &pa_container_sizes() { return pa_container_sizes_i; }
77
78 const PragmaMutuallyExclusive &pa_mutually_exclusive() const { return pa_mutually_exclusive_i; }
79 PragmaMutuallyExclusive &pa_mutually_exclusive() { return pa_mutually_exclusive_i; }
80
81 const PragmaSolitary &pa_solitary() const { return pa_solitary_i; }
82 PragmaSolitary &pa_solitary() { return pa_solitary_i; }
83
84 const PragmaAtomic &pa_atomic() const { return pa_atomic_i; }
85 PragmaAtomic &pa_atomic() { return pa_atomic_i; }
86
87 const PragmaNoOverlay &pa_no_overlay() const { return pa_no_overlay_i; }
88 PragmaNoOverlay &pa_no_overlay() { return pa_no_overlay_i; }
89
90 const PragmaContainerType &pa_container_type() const { return pa_container_type_i; }
91 PragmaContainerType &pa_container_type() { return pa_container_type_i; }
92
93 const PragmaNoInit &pa_no_init() const { return pa_no_init_i; }
94 PragmaNoInit &pa_no_init() { return pa_no_init_i; }
95
96 const PragmaDeparserZero &pa_deparser_zero() const { return pa_deparser_zero_i; }
97 PragmaDeparserZero &pa_deparser_zero() { return pa_deparser_zero_i; }
98
99 const PragmaNoPack &pa_no_pack() const { return pa_no_pack_i; }
100 PragmaNoPack &pa_no_pack() { return pa_no_pack_i; }
101
102 const PragmaBytePack &pa_byte_pack() const { return pa_byte_pack_i; }
103 PragmaBytePack &pa_byte_pack() { return pa_byte_pack_i; }
104
105 explicit Pragmas(PhvInfo &phv)
106 : pa_container_sizes_i(phv, *(new ordered_map<cstring, std::vector<PHV::Size>>)),
107 pa_mutually_exclusive_i(phv),
108 pa_solitary_i(phv),
109 pa_atomic_i(phv),
110 pa_no_overlay_i(phv),
111 pa_container_type_i(phv),
112 pa_no_init_i(phv),
113 pa_deparser_zero_i(phv),
114 pa_no_pack_i(phv),
115 pa_byte_pack_i(phv) {
116 addPasses({
117 &pa_container_sizes_i,
118 &pa_mutually_exclusive_i,
119 &pa_solitary_i,
120 &pa_atomic_i,
121 &pa_no_overlay_i,
122 &pa_container_type_i,
123 &pa_no_init_i,
124 &pa_deparser_zero_i,
125 &pa_no_pack_i,
126 &pa_byte_pack_i,
127 });
128 }
129 Pragmas(PhvInfo &phv, const ordered_map<cstring, std::vector<PHV::Size>> &container_size_constr,
130 const ordered_map<cstring, ordered_set<cstring>> &no_pack_constr)
131 : pa_container_sizes_i(phv, container_size_constr),
132 pa_mutually_exclusive_i(phv),
133 pa_solitary_i(phv),
134 pa_atomic_i(phv),
135 pa_no_overlay_i(phv),
136 pa_container_type_i(phv),
137 pa_no_init_i(phv),
138 pa_deparser_zero_i(phv),
139 pa_no_pack_i(phv, no_pack_constr),
140 pa_byte_pack_i(phv) {
141 addPasses({
142 &pa_container_sizes_i,
143 &pa_mutually_exclusive_i,
144 &pa_solitary_i,
145 &pa_atomic_i,
146 &pa_no_overlay_i,
147 &pa_container_type_i,
148 &pa_no_init_i,
149 &pa_deparser_zero_i,
150 &pa_no_pack_i,
151 &pa_byte_pack_i,
152 });
153 }
154};
155
156} // namespace PHV
157
158#endif /* BACKENDS_TOFINO_BF_P4C_PHV_PRAGMA_PHV_PRAGMAS_H_ */
Definition vector.h:59
Definition ir/pass_manager.h:40
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv_pragmas.h:46
static bool checkStringLiteralArgs(const IR::Vector< IR::Expression > &exprs)
Definition phv_pragmas.cpp:76
static bool checkPipeApplication(const IR::Annotation *annotation, const IR::BFN::Pipe *pipe, const IR::StringLiteral *pipe_arg)
Definition phv_pragmas.cpp:130
static bool checkNumberArgs(const IR::Annotation *annotation, unsigned required_args, const unsigned min_required_args, bool exact_number_of_args, cstring pragma_name, cstring pragma_args_wo_pipe)
Definition phv_pragmas.cpp:97
static void reportNoMatchingPHV(const IR::BFN::Pipe *pipe, const IR::Expression *expr, cstring field_name=""_cs)
Definition phv_pragmas.cpp:146
static bool gressValid(cstring gress)
Definition phv_pragmas.cpp:22
static bool determinePipeGressArgs(const IR::Vector< IR::Expression > &exprs, unsigned &expr_index, unsigned &required_args, const IR::StringLiteral *&pipe_arg, const IR::StringLiteral *&gress_arg)
Definition phv_pragmas.cpp:34
Definition phv_fields.h:1095
Definition pa_atomic.h:30
Definition pa_byte_pack.h:39
Definition pa_container_size.h:39
Definition pa_container_type.h:35
Definition pa_deparser_zero.h:30
Definition pa_mutually_exclusive.h:37
Definition pa_no_overlay.h:33
Definition pa_no_pack.h:28
Definition pa_solitary.h:27
Adds the no_init pragma to the specified fields with the specified gress.
Definition pa_no_init.h:35
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32