P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
dpdkMetadata.h
1/*
2Copyright 2022 Intel Corp.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef BACKENDS_DPDK_DPDKMETADATA_H_
18#define BACKENDS_DPDK_DPDKMETADATA_H_
19
20#include "dpdkUtils.h"
21#include "frontends/common/resolveReferences/referenceMap.h"
22#include "ir/ir.h"
23
24namespace DPDK {
25
26class IsDirectionMetadataUsed : public Inspector {
27 bool &is_direction_used;
28
29 public:
30 explicit IsDirectionMetadataUsed(bool &is_direction_used)
31 : is_direction_used(is_direction_used) {}
32 bool preorder(const IR::Member *m) override {
33 if (!is_direction_used && isDirection(m)) {
34 is_direction_used = true;
35 }
36 return false;
37 }
38};
39
40// This pass adds decl instance of Register extern in dpdk pna program which will
41// be used by dpdk backend for initializing the mask for calculating packet direction
42// at beginning of pipeline
43class DirectionToRegRead : public Transform {
44 ordered_map<cstring, cstring> dirToDirMapping;
45 ordered_map<cstring, cstring> inputToInputPortMapping;
46 ordered_set<cstring> usedNames;
47 cstring registerInstanceName;
48
49 public:
51 // dpdk currently only uses pna_main_input_metadata_direction
52 // and pna_main_input_metadata_input_port
53 // so even when we use any other direction or input port metadata we
54 // replace it like below
55 dirToDirMapping.insert(std::make_pair(cstring("pna_main_input_metadata_direction"),
56 cstring("pna_main_input_metadata_direction")));
57 dirToDirMapping.insert(std::make_pair(cstring("pna_pre_input_metadata_direction"),
58 cstring("pna_main_input_metadata_direction")));
59 dirToDirMapping.insert(std::make_pair(cstring("pna_main_parser_input_metadata_direction"),
60 cstring("pna_main_input_metadata_direction")));
61 inputToInputPortMapping.insert(
62 std::make_pair(cstring("pna_main_input_metadata_input_port"),
63 cstring("pna_main_input_metadata_input_port")));
64 inputToInputPortMapping.insert(
65 std::make_pair(cstring("pna_pre_input_metadata_direction"),
66 cstring("pna_main_input_metadata_input_port")));
67 inputToInputPortMapping.insert(
68 std::make_pair(cstring("pna_main_parser_input_metadata_direction"),
69 cstring("pna_main_input_metadata_input_port")));
70 }
71 const IR::Node *preorder(IR::DpdkAsmProgram *p) override;
72 const IR::Node *preorder(IR::Member *m) override;
73
74 void uniqueNames(IR::DpdkAsmProgram *p);
75 IR::DpdkExternDeclaration *addRegDeclInstance(cstring instanceName);
76 IR::DpdkListStatement *replaceDirection(IR::DpdkListStatement *l);
77 IR::IndexedVector<IR::DpdkAsmStatement> addRegReadStmtForDirection(
78 IR::IndexedVector<IR::DpdkAsmStatement> stmts);
79};
80
81// DPDK implements pass metadata using "recircid" instruction.
82// All occurrences of pass metadata usage should be prepended with recircid instruction to fetch
83// the latest pass_id from the target.
84class PrependPassRecircId : public Transform {
85 IR::IndexedVector<IR::DpdkAsmStatement> newStmts;
86
87 public:
89 bool isPass(const IR::Member *m);
90 const IR::Node *postorder(IR::DpdkAction *a) override;
91 const IR::Node *postorder(IR::DpdkListStatement *l) override;
92 IR::IndexedVector<IR::DpdkAsmStatement> prependPassWithRecircid(
93 IR::IndexedVector<IR::DpdkAsmStatement> stmts);
94};
95
96} // namespace DPDK
97#endif // BACKENDS_DPDK_DPDKMETADATA_H_
Definition dpdkMetadata.h:43
Definition dpdkMetadata.h:26
Definition dpdkMetadata.h:84
Definition cstring.h:72
Definition ordered_map.h:30
Definition ordered_set.h:30
Definition backend.cpp:35