P4C
The P4 Compiler
Loading...
Searching...
No Matches
check_header_alignment.h
1
19#ifndef BF_P4C_MIDEND_CHECK_HEADER_ALIGNMENT_H_
20#define BF_P4C_MIDEND_CHECK_HEADER_ALIGNMENT_H_
21
22#include "backends/tofino/bf-p4c/midend/type_checker.h"
23#include "frontends/common/resolveReferences/resolveReferences.h"
24#include "frontends/p4/methodInstance.h"
25#include "frontends/p4/typeMap.h"
26#include "ir/ir.h"
27
28namespace P4 {
29class TypeMap;
30class ReferenceMap;
31} // namespace P4
32
33namespace BFN {
34
42class CheckPadAssignment final : public Inspector {
43 private:
44 bool preorder(const IR::AssignmentStatement *statement) override;
45
46 public:
48};
49
67class CheckHeaderAlignment final : public Inspector {
68 P4::TypeMap *typeMap;
69
70 private:
71 bool preorder(const IR::Type_Header *header) override;
72
73 public:
74 explicit CheckHeaderAlignment(P4::ReferenceMap *, P4::TypeMap *typeMap) : typeMap(typeMap) {}
75};
76
78using HeaderToPad = std::unordered_set<cstring>;
79using ResubmitHeaders = std::unordered_set<cstring>;
80
82 P4::ReferenceMap *refMap;
83 P4::TypeMap *typeMap;
84 HeaderToPad *headers_to_pad;
85 ResubmitHeaders *resubmit_headers;
86 HeaderTypeMap *all_header_types;
87
88 public:
89 std::vector<cstring> find_headers_to_pad(P4::MethodInstance *mi);
90 std::vector<const IR::Type_StructLike *> find_all_headers(P4::MethodInstance *mi);
91 void check_mirror(P4::MethodInstance *mi);
92 void check_digest(P4::MethodInstance *mi);
93 void check_resubmit(P4::MethodInstance *mi);
94 bool preorder(const IR::MethodCallExpression *expr) override;
95 bool preorder(const IR::Type_Header *) override;
96 explicit FindPaddingCandidate(P4::ReferenceMap *refMap, P4::TypeMap *typeMap,
97 HeaderToPad *headers_to_pad, ResubmitHeaders *resubmit_headers,
98 HeaderTypeMap *all_header_types)
99 : refMap(refMap),
100 typeMap(typeMap),
101 headers_to_pad(headers_to_pad),
102 resubmit_headers(resubmit_headers),
103 all_header_types(all_header_types) {}
104};
105
107 P4::TypeMap *typeMap;
108 HeaderToPad *headers_to_pad;
109 ResubmitHeaders *resubmit_headers;
110 HeaderTypeMap *all_header_types;
111
112 public:
113 explicit AddPaddingFields(P4::ReferenceMap *, P4::TypeMap *typeMap, HeaderToPad *headers_to_pad,
114 ResubmitHeaders *resubmit_headers, HeaderTypeMap *all_header_types)
115 : typeMap(typeMap),
116 headers_to_pad(headers_to_pad),
117 resubmit_headers(resubmit_headers),
118 all_header_types(all_header_types) {}
119
120 const IR::Node *preorder(IR::Type_Header *st) override;
121 const IR::Node *preorder(IR::StructExpression *) override;
122};
123
124// This pass transforms all resubmit headers from Type_Header to Type_FixedSizeHeader
126 ResubmitHeaders *resubmit_headers;
127
128 public:
129 explicit TransformResubmitHeaders(ResubmitHeaders *resubmit_headers)
130 : resubmit_headers(resubmit_headers) {}
131 const IR::Node *preorder(IR::Type_Header *) override;
132};
133
135 // headers used in mirror, resubmit and digest
136 HeaderToPad headers_to_pad;
137 // all header types before padding is added.
138 HeaderTypeMap all_header_types;
139 ResubmitHeaders resubmit_headers;
140
141 public:
143 addPasses({
144 new FindPaddingCandidate(refMap, typeMap, &headers_to_pad, &resubmit_headers,
145 &all_header_types),
146 new AddPaddingFields(refMap, typeMap, &headers_to_pad, &resubmit_headers,
147 &all_header_types),
148 new TransformResubmitHeaders(&resubmit_headers),
149 // After padding the TypeInference might
150 // change new ListExpressions to StructExpressions
151 new P4::ClearTypeMap(typeMap),
152 new P4::ResolveReferences(refMap),
153 new BFN::TypeInference(typeMap, false),
154 new P4::ClearTypeMap(typeMap),
155 new BFN::TypeChecking(refMap, typeMap, true),
156 new CheckHeaderAlignment(refMap, typeMap),
157 new CheckPadAssignment(),
158 });
159 setName("PadFlexibleField");
160 }
161};
162
163} // namespace BFN
164
165#endif /* BF_P4C_MIDEND_CHECK_HEADER_ALIGNMENT_H_ */
Definition check_header_alignment.h:106
Definition check_header_alignment.h:67
Definition check_header_alignment.h:42
Definition check_header_alignment.h:81
std::vector< cstring > find_headers_to_pad(P4::MethodInstance *mi)
Definition check_header_alignment.cpp:64
Definition check_header_alignment.h:134
Definition check_header_alignment.h:125
const IR::Node * preorder(IR::Type_Header *) override
Definition check_header_alignment.cpp:253
Definition typeChecker.h:32
Definition node.h:94
Definition visitor.h:400
Definition methodInstance.h:56
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition resolveReferences.h:123
Definition visitor.h:424
Definition typeChecker.h:55
Definition typeChecker.h:483
Definition typeMap.h:41
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24