P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
dpdkProgramStructure.h
1#ifndef BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_
2#define BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_
3
4#include "frontends/common/resolveReferences/referenceMap.h"
5#include "frontends/p4/typeMap.h"
6#include "ir/ir.h"
7
8// DPDK target implementation treats tables with keys lying non-contiguous in underlying
9// structure as wildcard even if all keys are exact match keys.
10// Learner tables are special table with contiguous and exact match keys.
11enum InternalTableType { REGULAR_EXACT, LEARNER, WILDCARD };
12
13/* Collect information related to P4 programs targeting dpdk */
15 cstring p4arch; // 'pna' or 'psa'
17 unsigned scalars_width = 0;
18
19 std::map<const IR::StructField *, cstring> scalarMetadataFields;
28
29 // table and action info for learner tables
30 ordered_set<cstring> learner_tables;
31 ordered_set<cstring> learner_actions;
33 ordered_map<cstring, std::vector<cstring>> learner_action_params;
37
38 IR::IndexedVector<IR::DpdkDeclaration> variables;
39
46
47 std::map<const cstring, IR::IndexedVector<IR::Parameter> *> args_struct_map;
48 std::map<const IR::Declaration_Instance *, cstring> csum_map;
49 std::map<cstring, int> error_map;
50 std::vector<const IR::Declaration_Instance *> externDecls;
51 std::map<cstring, std::vector<std::pair<cstring, cstring>>> key_map;
52 std::map<cstring, const IR::P4Table *> group_tables;
53 std::map<cstring, const IR::P4Table *> member_tables;
54
55 std::set<cstring> pipeline_controls;
56 std::set<cstring> non_pipeline_controls;
57
58 IR::Type_Struct *metadataStruct;
59 IR::Expression *ipsec_header;
60 cstring local_metadata_type = "";
61 cstring header_type = "";
62 IR::IndexedVector<IR::StructField> compiler_added_fields;
63 IR::IndexedVector<IR::StructField> key_fields;
64 IR::Vector<IR::Type> used_metadata;
67
68 void push_variable(const IR::DpdkDeclaration *d) { variables.push_back(d); }
69 IR::IndexedVector<IR::DpdkDeclaration> &get_globals() { return variables; }
70
71 bool hasVisited(const IR::Type_StructLike *st) {
72 if (auto h = st->to<IR::Type_Header>())
73 return header_types.count(h->getName());
74 else if (auto s = st->to<IR::Type_Struct>())
75 return metadata_types.count(s->getName());
76 else if (auto u = st->to<IR::Type_HeaderUnion>())
77 return header_union_types.count(u->getName());
78 return false;
79 }
80
89 bool isPSA(void) { return (p4arch == "psa") ? true : false; }
90
99 bool isPNA(void) { return (p4arch == "pna") ? true : false; }
100};
101
103 cstring modifiedName;
104 cstring headerStr;
105 unsigned modifiedWidth;
106 unsigned offset;
107 unsigned lsb;
108 unsigned msb;
109 unsigned fieldWidth;
110 hdrFieldInfo() {
111 modifiedName = "";
112 headerStr = "";
113 modifiedWidth = 0;
114 offset = 0;
115 lsb = 0;
116 msb = 0;
117 fieldWidth = 0;
118 }
119};
120
121class ParseDpdkArchitecture : public Inspector {
122 DpdkProgramStructure *structure;
123
124 public:
125 explicit ParseDpdkArchitecture(DpdkProgramStructure *structure) : structure(structure) {
126 CHECK_NULL(structure);
127 }
128
129 bool preorder(const IR::ToplevelBlock *block) override;
130 bool preorder(const IR::PackageBlock *block) override;
131 void parse_psa_block(const IR::PackageBlock *);
132 void parse_pna_block(const IR::PackageBlock *);
133
134 profile_t init_apply(const IR::Node *root) override {
135 structure->variables.clear();
136 structure->header_types.clear();
137 structure->metadata_types.clear();
138 structure->parsers.clear();
139 structure->deparsers.clear();
140 structure->pipelines.clear();
141 structure->actions.clear();
142 return Inspector::init_apply(root);
143 }
144};
145
146class InspectDpdkProgram : public Inspector {
147 P4::ReferenceMap *refMap;
148 P4::TypeMap *typeMap;
149 DpdkProgramStructure *structure;
150
151 public:
153 DpdkProgramStructure *structure)
154 : refMap(refMap), typeMap(typeMap), structure(structure) {
155 CHECK_NULL(structure);
156 }
157
158 bool isHeaders(const IR::Type_StructLike *st);
159 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
160 void addHeaderType(const IR::Type_StructLike *st);
161 void addHeaderInstance(const IR::Type_StructLike *st, cstring name);
162 bool preorder(const IR::Declaration_Variable *dv) override;
163 bool preorder(const IR::Parameter *parameter) override;
164 bool preorder(const IR::P4Action *) override;
165 bool isStandardMetadata(cstring);
166};
167
168#endif /* BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_ */
Definition externInstance.h:33
Definition dpdkProgramStructure.h:146
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeMap.h:42
Definition dpdkProgramStructure.h:121
bool preorder(const IR::ToplevelBlock *block) override
Definition dpdkProgramStructure.cpp:6
Definition cstring.h:72
Definition ordered_map.h:30
Definition ordered_set.h:30
Definition dpdkProgramStructure.h:14
bool isPSA(void)
Predicate that states whether architecture is PSA or not.
Definition dpdkProgramStructure.h:89
bool isPNA(void)
Predicate that states whether architecture is PNA or not.
Definition dpdkProgramStructure.h:99
Definition dpdkProgramStructure.h:102