P4C
The P4 Compiler
Loading...
Searching...
No Matches
drop_packet_with_mirror_engine.h
1
32#ifndef BACKENDS_TOFINO_BF_P4C_MIDEND_DROP_PACKET_WITH_MIRROR_ENGINE_H_
33#define BACKENDS_TOFINO_BF_P4C_MIDEND_DROP_PACKET_WITH_MIRROR_ENGINE_H_
34
35#include "backends/tofino/bf-p4c/common/pragma/all_pragmas.h"
36#include "backends/tofino/bf-p4c/common/pragma/collect_global_pragma.h"
37#include "backends/tofino/bf-p4c/common/pragma/pragma.h"
38#include "backends/tofino/bf-p4c/device.h"
39#include "frontends/common/resolveReferences/resolveReferences.h"
40#include "ir/ir.h"
41#include "type_checker.h"
42
43namespace BFN {
44
45/*
46 This pass inserts the following code template into ingress deparser
47
48 Mirror() reserved_mirror;
49
50 apply {
51 ...
52 if (ig_dprsr_md.mirror_type == RESERVED_MIRROR_TYPE) {
53 reserved_mirror.emit(meta.reserved_mirror_session);
54 }
55 ...
56 }
57
58
59*/
61 cstring igIntrMdForDprsrName;
62 std::set<cstring> unique_names;
63
64 public:
66 const IR::Node *preorder(IR::P4Program *p) override {
67 // This pass only applies to TNA architecture
68 if (BackendOptions().arch == "v1model" || BackendOptions().arch == "psa") prune();
69 // collect and set global_pragmas
70 CollectGlobalPragma collect_pragma;
71 p->apply(collect_pragma);
72 // Workaround can be disabled by pragma
73 if (collect_pragma.exists(PragmaDisableI2EReservedDropImplementation::name)) prune();
74 return p;
75 }
76 // const IR::Node* preorder(IR::BFN::TnaControl*) override;
77 const IR::Node *preorder(IR::Declaration_Instance *) override;
78 const IR::Node *postorder(IR::BFN::TnaDeparser *) override;
79 const IR::Node *preorder(IR::BFN::TnaParser *parser) override {
80 prune();
81 return parser;
82 }
83
84 profile_t init_apply(const IR::Node *root) override { return Transform::init_apply(root); }
85};
86
88 public:
90 addPasses({new PassIf(
91 []() {
92 // TOFINO1, 2 has the same hardware bug that need this workaround.
93 return Device::currentDevice() == Device::TOFINO ||
94 Device::currentDevice() == Device::JBAY;
95 },
97 new P4::ResolveReferences(refMap),
98 new BFN::TypeInference(typeMap, false), /* extended P4::TypeInference */
99 new P4::ApplyTypesToExpressions(typeMap), new P4::ResolveReferences(refMap)})});
100 setName("DropPacketWithMirrorEngine");
101 }
102};
103
104} // namespace BFN
105
106#endif /* BACKENDS_TOFINO_BF_P4C_MIDEND_DROP_PACKET_WITH_MIRROR_ENGINE_H_ */
Definition drop_packet_with_mirror_engine.h:60
Definition drop_packet_with_mirror_engine.h:87
Definition collect_global_pragma.h:28
const IR::Annotation * exists(const char *pragma_name) const
Check if pragma exists.
Definition collect_global_pragma.cpp:120
Definition typeChecker.h:620
Definition typeChecker.h:32
Definition node.h:94
Definition ir/pass_manager.h:172
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition resolveReferences.h:123
Definition visitor.h:424
Definition typeChecker.h:483
Definition typeMap.h:41
Definition visitor.h:78
Definition cstring.h:85
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21