17#ifndef BACKENDS_TC_EBPFCODEGEN_H_
18#define BACKENDS_TC_EBPFCODEGEN_H_
28class ConvertToBackendIR;
68 bool preorder(
const IR::Type_Error *errors)
override {
70 for (
auto decl : errors->members) {
72 if (decl->srcInfo.isValid()) {
73 auto sourceFile = decl->srcInfo.getSourceFile();
75 if (sourceFile.endsWith(
"p4include/core.p4"))
continue;
78 builder->emitIndent();
79 builder->appendFormat(
"static const ParserError_t %v = %d", decl->name,
id);
80 builder->endOfStatement(
true);
85 "%1%: Reached maximum number of possible errors", decl);
130 bool preorder(
const IR::Member *expression)
override;
133 void compileExtractField(
const IR::Expression *expr,
const IR::StructField *field,
135 void compileLookahead(
const IR::Expression *destination)
override;
144 void emitDeclaration(
EBPF::CodeBuilder *builder,
const IR::Declaration *decl)
override;
153 const IR::P4Action *action,
154 bool isDefaultAction)
const;
156 void initDirectCounters();
157 void initDirectMeters();
164 initDirectCounters();
174 bool isMatchTypeSupported(
const IR::Declaration_ID *matchType)
override {
175 if (matchType->name.name ==
"range" || matchType->name.name ==
"rangelist" ||
176 matchType->name.name ==
"optional")
178 return EBPF::EBPFTable::isMatchTypeSupported(matchType);
181 cstring actionRunVariable)
override;
183 cstring p4ActionToActionIDName(
const IR::P4Action *action)
const;
191 const IR::Parameter *parserHeaders,
const IR::Parameter *istd)
194 bool addExternDeclaration =
false;
195 bool build()
override;
198 void emitDeclaration(
EBPF::CodeBuilder *builder,
const IR::Declaration *decl)
override;
201 if (addExternDeclaration) {
202 builder->emitIndent();
203 builder->appendLine(
"struct p4tc_ext_bpf_params ext_params = {};");
221 : options(options), typemap(typemap), refmap(refmap), ebpf_program(
nullptr), tcIR(tcIR) {}
224 const IR::Node *preorder(IR::ToplevelBlock *p)
override;
232 const EBPF::pipeline_type type;
234 const IR::ParserBlock *parserBlock;
235 const IR::ControlBlock *controlBlock;
236 const IR::ControlBlock *deparserBlock;
244 const IR::ParserBlock *parserBlock,
245 const IR::ControlBlock *controlBlock,
251 parserBlock(parserBlock),
252 controlBlock(controlBlock),
253 deparserBlock(deparserBlock),
259 bool preorder(
const IR::PackageBlock *block)
override;
272 : program(program), typemap(typemap), parser(
nullptr) {}
274 bool preorder(
const IR::ParserBlock *prsr)
override;
275 bool preorder(
const IR::P4ValueSet *pvs)
override;
281 bool addExternDeclaration =
false;
282 std::map<cstring, EBPFRegisterPNA *> pna_registers;
283 std::map<cstring, EBPFHashPNA *> pna_hashes;
286 const IR::Parameter *parserHeaders)
290 auto result = ::P4::get(pna_registers, name);
291 BUG_CHECK(result !=
nullptr,
"No register named %1%", name);
295 auto result = ::P4::get(pna_hashes, name);
299 if (addExternDeclaration) {
300 builder->emitIndent();
301 builder->appendLine(
"struct p4tc_ext_bpf_params ext_params = {};");
302 builder->emitIndent();
303 builder->appendLine(
"struct p4tc_ext_bpf_val ext_val = {};");
304 builder->emitIndent();
305 builder->appendLine(
"struct p4tc_ext_bpf_val *ext_val_ptr;");
308 void emitTableTypes(
EBPF::CodeBuilder *builder) { EBPF::EBPFControl::emitTableTypes(builder); }
316 EBPF::pipeline_type type;
319 const IR::Parameter *parserHeaders;
331 parserHeaders(parserHeaders),
335 bool preorder(
const IR::TableBlock *)
override;
336 bool preorder(
const IR::ControlBlock *)
override;
337 bool preorder(
const IR::Declaration_Variable *)
override;
338 bool preorder(
const IR::Member *m)
override;
339 bool preorder(
const IR::IfStatement *a)
override;
340 bool preorder(
const IR::ExternBlock *instance)
override;
341 bool checkPnaTimestampMem(
const IR::Member *m);
349 const IR::Parameter *parserHeaders;
350 const IR::Parameter *istd;
358 parserHeaders(parserHeaders),
363 bool preorder(
const IR::ControlBlock *)
override;
364 bool preorder(
const IR::Declaration_Instance *)
override;
381 virtual cstring getParamName(
const IR::PathExpression *);
382 bool preorder(
const IR::AssignmentStatement *a)
override;
384 bool preorder(
const IR::Member *)
override;
385 bool IsTableAddOnMiss(
const IR::P4Table *table);
386 const IR::P4Action *GetAddOnMissHitAction(
cstring actionName);
387 void ValidateAddOnMissMissAction(
const IR::P4Action *act);
396 bool isDefaultAction;
402 const IR::P4Action *act,
bool isDefaultAction);
403 bool preorder(
const IR::PathExpression *pe)
override;
404 bool isActionParameter(
const IR::Expression *expression)
const;
407 cstring getParamInstanceName(
const IR::Expression *expression)
const override;
408 cstring getParamName(
const IR::PathExpression *)
override;
Definition methodInstance.h:129
Definition ebpfTable.h:26
Definition ebpf/codeGen.h:33
Definition ebpf/codeGen.h:41
Definition ebpfControl.h:28
This translator emits buffer preparation (eg. which headers will be emitted)
Definition ebpfDeparser.h:38
Definition ebpfPsaControl.h:58
Definition ebpfDeparser.h:63
Definition ebpfPsaDeparser.h:39
Definition ebpfPsaHashAlgorithm.h:26
Definition ebpfPsaHashAlgorithm.h:172
Definition ebpfParser.h:79
EBPFPipeline represents a single eBPF program in the TC/XDP hook.
Definition ebpfPipeline.h:28
cstring name
A custom name of eBPF program.
Definition ebpfPipeline.h:31
Definition ebpfProgram.h:39
Definition ebpfPsaParser.h:40
Definition ebpfPsaTable.h:29
Base class for EBPF types.
Definition ebpfType.h:29
Definition ebpfPsaGen.h:31
Definition ebpfPsaParser.h:29
Definition ebpfPipeline.h:199
Definition xdpHelpProgram.h:24
Definition ebpfOptions.h:26
Definition methodInstance.h:194
Definition methodInstance.h:168
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition ebpfCodeGen.h:393
Definition ebpfCodeGen.h:370
Definition tc/backend.h:49
Definition ebpfCodeGen.h:314
Definition ebpfCodeGen.h:347
Definition ebpfCodeGen.h:265
Definition ebpfCodeGen.h:211
Definition ebpfCodeGen.h:230
Definition ebpfCodeGen.h:413
Definition ebpfCodeGen.h:279
Definition ebpfCodeGen.h:425
Definition tcExterns.h:180
Definition ebpfCodeGen.h:138
Definition tcExterns.h:53
Definition ebpfCodeGen.h:149
void validateKeys() const override
Definition ebpfCodeGen.cpp:2155
Definition ebpfCodeGen.h:188
void emitPreDeparser(EBPF::CodeBuilder *builder) override
Definition ebpfCodeGen.cpp:1179
Definition ebpfCodeGen.h:95
void emit(EBPF::CodeBuilder *builder) const override
Definition ebpfCodeGen.cpp:169
void emitParser(EBPF::CodeBuilder *builder) const override
Definition ebpfCodeGen.cpp:215
Definition ebpfCodeGen.h:35
Definition ebpfCodeGen.h:62
Definition ebpfCodeGen.h:124
Definition ebpfCodeGen.h:110
void emitLocalVariables(EBPF::CodeBuilder *builder) override
Generates a set of helper variables that are used during packet processing.
Definition ebpfCodeGen.cpp:514
void emitGlobalMetadataInitializer(EBPF::CodeBuilder *builder) override
Definition ebpfCodeGen.cpp:442
void emitTrafficManager(EBPF::CodeBuilder *builder) override
Definition ebpfCodeGen.cpp:483
This file defines functions for the pass to generate the introspection file.
Definition tc/backend.cpp:24
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51