17#ifndef BACKENDS_TC_EBPFCODEGEN_H_
18#define BACKENDS_TC_EBPFCODEGEN_H_
28class ConvertToBackendIR;
67 bool preorder(
const IR::Type_Error *errors)
override {
69 for (
auto decl : errors->members) {
71 if (decl->srcInfo.isValid()) {
72 auto sourceFile = decl->srcInfo.getSourceFile();
74 if (sourceFile.endsWith(
"p4include/core.p4"))
continue;
77 builder->emitIndent();
78 builder->appendFormat(
"static const ParserError_t %s = %d", decl->name.name,
id);
79 builder->endOfStatement(
true);
84 "%1%: Reached maximum number of possible errors", decl);
130 void compileExtractField(
const IR::Expression *expr,
const IR::StructField *field,
132 void compileLookahead(
const IR::Expression *destination)
override;
141 void emitDeclaration(
EBPF::CodeBuilder *builder,
const IR::Declaration *decl)
override;
150 const IR::P4Action *action,
151 bool isDefaultAction)
const;
153 void initDirectCounters();
160 initDirectCounters();
169 bool isMatchTypeSupported(
const IR::Declaration_ID *matchType)
override {
170 if (matchType->name.name ==
"range" || matchType->name.name ==
"rangelist" ||
171 matchType->name.name ==
"optional")
173 return EBPF::EBPFTable::isMatchTypeSupported(matchType);
176 cstring actionRunVariable)
override;
178 cstring p4ActionToActionIDName(
const IR::P4Action *action)
const;
186 const IR::Parameter *parserHeaders,
const IR::Parameter *istd)
189 bool addExternDeclaration =
false;
190 bool build()
override;
193 void emitDeclaration(
EBPF::CodeBuilder *builder,
const IR::Declaration *decl)
override;
196 if (addExternDeclaration) {
197 builder->emitIndent();
198 builder->appendLine(
"struct p4tc_ext_bpf_params ext_params = {};");
216 : options(options), typemap(typemap), refmap(refmap), ebpf_program(
nullptr), tcIR(tcIR) {}
219 const IR::Node *preorder(IR::ToplevelBlock *p)
override;
227 const EBPF::pipeline_type type;
229 const IR::ParserBlock *parserBlock;
230 const IR::ControlBlock *controlBlock;
231 const IR::ControlBlock *deparserBlock;
239 const IR::ParserBlock *parserBlock,
240 const IR::ControlBlock *controlBlock,
246 parserBlock(parserBlock),
247 controlBlock(controlBlock),
248 deparserBlock(deparserBlock),
254 bool preorder(
const IR::PackageBlock *block)
override;
267 : program(program), typemap(typemap), parser(
nullptr) {}
269 bool preorder(
const IR::ParserBlock *prsr)
override;
270 bool preorder(
const IR::P4ValueSet *pvs)
override;
276 bool addExternDeclaration =
false;
277 std::map<cstring, EBPFRegisterPNA *> pna_registers;
280 const IR::Parameter *parserHeaders)
284 auto result = ::P4::get(pna_registers, name);
285 BUG_CHECK(result !=
nullptr,
"No register named %1%", name);
289 if (addExternDeclaration) {
290 builder->emitIndent();
291 builder->appendLine(
"struct p4tc_ext_bpf_params ext_params = {};");
292 builder->emitIndent();
293 builder->appendLine(
"struct p4tc_ext_bpf_val ext_val = {};");
294 builder->emitIndent();
295 builder->appendLine(
"struct p4tc_ext_bpf_val *ext_val_ptr;");
304 EBPF::pipeline_type type;
307 const IR::Parameter *parserHeaders;
319 parserHeaders(parserHeaders),
323 bool preorder(
const IR::TableBlock *)
override;
324 bool preorder(
const IR::ControlBlock *)
override;
325 bool preorder(
const IR::Declaration_Variable *)
override;
326 bool preorder(
const IR::Member *m)
override;
327 bool preorder(
const IR::IfStatement *a)
override;
328 bool preorder(
const IR::ExternBlock *instance)
override;
329 bool checkPnaTimestampMem(
const IR::Member *m);
337 const IR::Parameter *parserHeaders;
338 const IR::Parameter *istd;
346 parserHeaders(parserHeaders),
351 bool preorder(
const IR::ControlBlock *)
override;
352 bool preorder(
const IR::Declaration_Instance *)
override;
369 virtual cstring getParamName(
const IR::PathExpression *);
370 bool preorder(
const IR::AssignmentStatement *a)
override;
372 bool preorder(
const IR::Member *)
override;
373 bool IsTableAddOnMiss(
const IR::P4Table *table);
374 const IR::P4Action *GetAddOnMissHitAction(
cstring actionName);
375 void ValidateAddOnMissMissAction(
const IR::P4Action *act);
384 bool isDefaultAction;
390 const IR::P4Action *act,
bool isDefaultAction);
391 bool preorder(
const IR::PathExpression *pe)
override;
392 bool isActionParameter(
const IR::Expression *expression)
const;
395 cstring getParamInstanceName(
const IR::Expression *expression)
const override;
396 cstring getParamName(
const IR::PathExpression *)
override;
425 initialValue =
"0"_cs;
428 polynomial =
"0xA001"_cs;
429 updateMethod =
"crc16_update"_cs;
430 finalizeMethod =
"crc16_finalize"_cs;
440 initialValue =
"0xffffffff"_cs;
443 polynomial =
"0xEDB88320"_cs;
444 updateMethod =
"crc32_update"_cs;
445 finalizeMethod =
"crc32_finalize"_cs;
459 CRC16ChecksumAlgorithmPNA::emitGlobals(builder);
460 CRC32ChecksumAlgorithmPNA::emitGlobals(builder);
Definition methodInstance.h:129
Definition ebpfTable.h:26
Definition ebpfPsaHashAlgorithm.h:74
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:181
Definition methodInstance.h:149
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition ebpfCodeGen.h:381
Definition ebpfCodeGen.h:421
Definition ebpfCodeGen.h:436
Definition ebpfCodeGen.h:413
Definition ebpfCodeGen.h:358
Definition tc/backend.h:49
Definition ebpfCodeGen.h:302
Definition ebpfCodeGen.h:335
Definition ebpfCodeGen.h:260
Definition ebpfCodeGen.h:206
Definition ebpfCodeGen.h:225
Definition ebpfCodeGen.h:401
Definition ebpfCodeGen.h:274
Definition ebpfCodeGen.h:451
Definition ebpfCodeGen.h:135
Definition tcExterns.h:53
Definition ebpfCodeGen.h:146
void validateKeys() const override
Definition ebpfCodeGen.cpp:2112
Definition ebpfCodeGen.h:183
void emitPreDeparser(EBPF::CodeBuilder *builder) override
Definition ebpfCodeGen.cpp:1175
Definition ebpfCodeGen.h:94
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:34
Definition ebpfCodeGen.h:61
Definition ebpfCodeGen.h:123
Definition ebpfCodeGen.h:109
void emitLocalVariables(EBPF::CodeBuilder *builder) override
Generates a set of helper variables that are used during packet processing.
Definition ebpfCodeGen.cpp:515
void emitGlobalMetadataInitializer(EBPF::CodeBuilder *builder) override
Definition ebpfCodeGen.cpp:443
void emitTrafficManager(EBPF::CodeBuilder *builder) override
Definition ebpfCodeGen.cpp:484
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 error.h:51