P4C
The P4 Compiler
Loading...
Searching...
No Matches
dpdkProgramStructure.h
1/*
2 * SPDX-FileCopyrightText: 2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_
8#define BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_
9
10#include "frontends/common/resolveReferences/referenceMap.h"
11#include "frontends/p4/typeMap.h"
12#include "ir/ir.h"
13
14namespace P4 {
15
19enum InternalTableType { REGULAR_EXACT, LEARNER, WILDCARD };
20
23 cstring p4arch; // 'pna' or 'psa'
25 unsigned scalars_width = 0;
26
27 std::map<const IR::StructField *, cstring> scalarMetadataFields;
36
39 ordered_set<cstring> learner_actions;
41 ordered_map<cstring, std::vector<cstring>> learner_action_params;
46
48
55
56 std::map<const cstring, IR::IndexedVector<IR::Parameter> *> args_struct_map;
57 std::map<const IR::Declaration_Instance *, cstring> csum_map;
58 std::map<cstring, int> error_map;
59 std::vector<const IR::Declaration_Instance *> externDecls;
60 std::map<cstring, std::vector<std::pair<cstring, cstring>>> key_map;
61 std::map<cstring, const IR::P4Table *> group_tables;
62 std::map<cstring, const IR::P4Table *> member_tables;
63
64 std::set<cstring> pipeline_controls;
65 std::set<cstring> non_pipeline_controls;
66
67 IR::Type_Struct *metadataStruct;
68 IR::Expression *ipsec_header;
69 cstring local_metadata_type = cstring::empty;
70 cstring header_type = cstring::empty;
71 IR::IndexedVector<IR::StructField> compiler_added_fields;
73 IR::Vector<IR::Type> used_metadata;
76
77 void push_variable(const IR::DpdkDeclaration *d) { variables.push_back(d); }
78 IR::IndexedVector<IR::DpdkDeclaration> &get_globals() { return variables; }
79
80 void addHeaderInstances(const IR::DpdkHeaderInstance *d) {
81 if (header_instances.find(d->name->toString()) == header_instances.end()) {
82 header_instances.emplace(d->name->toString(), d);
83 }
84 }
85
86 bool hasVisited(const IR::Type_StructLike *st) {
87 if (auto h = st->to<IR::Type_Header>())
88 return header_types.count(h->getName());
89 else if (auto s = st->to<IR::Type_Struct>())
90 return metadata_types.count(s->getName());
91 else if (auto u = st->to<IR::Type_HeaderUnion>())
92 return header_union_types.count(u->getName());
93 return false;
94 }
95
102 bool isPSA(void) { return (p4arch == "psa") ? true : false; }
103
110 bool isPNA(void) { return (p4arch == "pna") ? true : false; }
111};
112
113struct hdrFieldInfo {
114 cstring modifiedName;
115 cstring headerStr;
116 unsigned modifiedWidth;
117 unsigned offset;
118 unsigned lsb;
119 unsigned msb;
120 unsigned fieldWidth;
121 hdrFieldInfo() {
122 modifiedName = cstring::empty;
123 headerStr = cstring::empty;
124 modifiedWidth = 0;
125 offset = 0;
126 lsb = 0;
127 msb = 0;
128 fieldWidth = 0;
129 }
130};
131
132class ParseDpdkArchitecture : public Inspector {
133 DpdkProgramStructure *structure;
134
135 public:
136 explicit ParseDpdkArchitecture(DpdkProgramStructure *structure) : structure(structure) {
137 CHECK_NULL(structure);
138 }
139
140 bool preorder(const IR::ToplevelBlock *block) override;
141 bool preorder(const IR::PackageBlock *block) override;
142 void parse_psa_block(const IR::PackageBlock *);
143 void parse_pna_block(const IR::PackageBlock *);
144
145 profile_t init_apply(const IR::Node *root) override {
146 structure->variables.clear();
147 structure->header_types.clear();
148 structure->metadata_types.clear();
149 structure->parsers.clear();
150 structure->deparsers.clear();
151 structure->pipelines.clear();
152 structure->actions.clear();
153 return Inspector::init_apply(root);
154 }
155};
156
157class InspectDpdkProgram : public Inspector {
158 P4::ReferenceMap *refMap;
159 P4::TypeMap *typeMap;
160 DpdkProgramStructure *structure;
161
162 public:
163 InspectDpdkProgram(P4::ReferenceMap *refMap, P4::TypeMap *typeMap,
164 DpdkProgramStructure *structure)
165 : refMap(refMap), typeMap(typeMap), structure(structure) {
166 CHECK_NULL(structure);
167 }
168
169 bool isHeaders(const IR::Type_StructLike *st);
170 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
171 void addHeaderType(const IR::Type_StructLike *st);
172 void addHeaderInstance(const IR::Type_StructLike *st, cstring name);
173 bool preorder(const IR::Declaration_Variable *dv) override;
174 bool preorder(const IR::Parameter *parameter) override;
175 bool preorder(const IR::P4Action *) override;
176 bool isStandardMetadata(cstring);
177};
178
179} // namespace P4
180
181#endif /* BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_ */
Definition indexed_vector.h:31
Definition node.h:53
Definition ir/vector.h:59
Definition visitor.h:418
Class used to encode maps from paths to declarations.
Definition referenceMap.h:67
Definition typeMap.h:32
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
InternalTableType
Definition dpdkProgramStructure.h:19
Collect information related to P4 programs targeting dpdk.
Definition dpdkProgramStructure.h:22
ordered_set< cstring > learner_tables
Table and action info for learner tables.
Definition dpdkProgramStructure.h:38
bool isPNA(void)
Predicate that states whether architecture is PNA or not.
Definition dpdkProgramStructure.h:110
bool isPSA(void)
Predicate that states whether architecture is PSA or not.
Definition dpdkProgramStructure.h:102