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();
154 void initDirectMeters();
161 initDirectCounters();
171 bool isMatchTypeSupported(
const IR::Declaration_ID *matchType)
override {
172 if (matchType->name.name ==
"range" || matchType->name.name ==
"rangelist" ||
173 matchType->name.name ==
"optional")
175 return EBPF::EBPFTable::isMatchTypeSupported(matchType);
178 cstring actionRunVariable)
override;
180 cstring p4ActionToActionIDName(
const IR::P4Action *action)
const;
188 const IR::Parameter *parserHeaders,
const IR::Parameter *istd)
191 bool addExternDeclaration =
false;
192 bool build()
override;
195 void emitDeclaration(
EBPF::CodeBuilder *builder,
const IR::Declaration *decl)
override;
198 if (addExternDeclaration) {
199 builder->emitIndent();
200 builder->appendLine(
"struct p4tc_ext_bpf_params ext_params = {};");
218 : options(options), typemap(typemap), refmap(refmap), ebpf_program(
nullptr), tcIR(tcIR) {}
221 const IR::Node *preorder(IR::ToplevelBlock *p)
override;
229 const EBPF::pipeline_type type;
231 const IR::ParserBlock *parserBlock;
232 const IR::ControlBlock *controlBlock;
233 const IR::ControlBlock *deparserBlock;
241 const IR::ParserBlock *parserBlock,
242 const IR::ControlBlock *controlBlock,
248 parserBlock(parserBlock),
249 controlBlock(controlBlock),
250 deparserBlock(deparserBlock),
256 bool preorder(
const IR::PackageBlock *block)
override;
269 : program(program), typemap(typemap), parser(
nullptr) {}
271 bool preorder(
const IR::ParserBlock *prsr)
override;
272 bool preorder(
const IR::P4ValueSet *pvs)
override;
278 bool addExternDeclaration =
false;
279 std::map<cstring, EBPFRegisterPNA *> pna_registers;
282 const IR::Parameter *parserHeaders)
286 auto result = ::P4::get(pna_registers, name);
287 BUG_CHECK(result !=
nullptr,
"No register named %1%", name);
291 if (addExternDeclaration) {
292 builder->emitIndent();
293 builder->appendLine(
"struct p4tc_ext_bpf_params ext_params = {};");
294 builder->emitIndent();
295 builder->appendLine(
"struct p4tc_ext_bpf_val ext_val = {};");
296 builder->emitIndent();
297 builder->appendLine(
"struct p4tc_ext_bpf_val *ext_val_ptr;");
300 void emitTableTypes(
EBPF::CodeBuilder *builder) { EBPF::EBPFControl::emitTableTypes(builder); }
307 EBPF::pipeline_type type;
310 const IR::Parameter *parserHeaders;
322 parserHeaders(parserHeaders),
326 bool preorder(
const IR::TableBlock *)
override;
327 bool preorder(
const IR::ControlBlock *)
override;
328 bool preorder(
const IR::Declaration_Variable *)
override;
329 bool preorder(
const IR::Member *m)
override;
330 bool preorder(
const IR::IfStatement *a)
override;
331 bool preorder(
const IR::ExternBlock *instance)
override;
332 bool checkPnaTimestampMem(
const IR::Member *m);
340 const IR::Parameter *parserHeaders;
341 const IR::Parameter *istd;
349 parserHeaders(parserHeaders),
354 bool preorder(
const IR::ControlBlock *)
override;
355 bool preorder(
const IR::Declaration_Instance *)
override;
372 virtual cstring getParamName(
const IR::PathExpression *);
373 bool preorder(
const IR::AssignmentStatement *a)
override;
375 bool preorder(
const IR::Member *)
override;
376 bool IsTableAddOnMiss(
const IR::P4Table *table);
377 const IR::P4Action *GetAddOnMissHitAction(
cstring actionName);
378 void ValidateAddOnMissMissAction(
const IR::P4Action *act);
387 bool isDefaultAction;
393 const IR::P4Action *act,
bool isDefaultAction);
394 bool preorder(
const IR::PathExpression *pe)
override;
395 bool isActionParameter(
const IR::Expression *expression)
const;
398 cstring getParamInstanceName(
const IR::Expression *expression)
const override;
399 cstring getParamName(
const IR::PathExpression *)
override;
428 initialValue =
"0"_cs;
431 polynomial =
"0xA001"_cs;
432 updateMethod =
"crc16_update"_cs;
433 finalizeMethod =
"crc16_finalize"_cs;
443 initialValue =
"0xffffffff"_cs;
446 polynomial =
"0xEDB88320"_cs;
447 updateMethod =
"crc32_update"_cs;
448 finalizeMethod =
"crc32_finalize"_cs;
462 CRC16ChecksumAlgorithmPNA::emitGlobals(builder);
463 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:384
Definition ebpfCodeGen.h:424
Definition ebpfCodeGen.h:439
Definition ebpfCodeGen.h:416
Definition ebpfCodeGen.h:361
Definition tc/backend.h:49
Definition ebpfCodeGen.h:305
Definition ebpfCodeGen.h:338
Definition ebpfCodeGen.h:262
Definition ebpfCodeGen.h:208
Definition ebpfCodeGen.h:227
Definition ebpfCodeGen.h:404
Definition ebpfCodeGen.h:276
Definition ebpfCodeGen.h:454
Definition ebpfCodeGen.h:135
Definition tcExterns.h:53
Definition ebpfCodeGen.h:146
void validateKeys() const override
Definition ebpfCodeGen.cpp:2147
Definition ebpfCodeGen.h:185
void emitPreDeparser(EBPF::CodeBuilder *builder) override
Definition ebpfCodeGen.cpp:1173
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