P4C
The P4 Compiler
Loading...
Searching...
No Matches
collect_pipelines.h
1
22#ifndef BACKENDS_TOFINO_BF_P4C_MIDEND_COLLECT_PIPELINES_H_
23#define BACKENDS_TOFINO_BF_P4C_MIDEND_COLLECT_PIPELINES_H_
24
25#include <set>
26#include <unordered_map>
27#include <vector>
28
29#include "frontends/common/resolveReferences/referenceMap.h"
30#include "ir/ir.h"
31
32namespace BFN {
33
43 // Checks the "main"
44 bool preorder(const IR::Declaration_Instance *) override;
45
46 public:
48 struct FullGress {
49 const IR::BFN::TnaParser *parser = nullptr;
50 const IR::BFN::TnaControl *control = nullptr;
51 const IR::BFN::TnaDeparser *deparser = nullptr;
52
53 bool operator==(const FullGress &) const;
54 };
55
58 class Pipe {
59 friend class CollectPipelines;
60 void set(unsigned count, unsigned idx, const IR::IDeclaration *ty);
61
62 public:
63 FullGress ingress, egress;
64 const IR::BFN::TnaControl *ghost = nullptr;
65 const IR::Declaration_Instance *dec = nullptr;
66
69 bool operator==(const Pipe &) const;
70
72 bool operator<(const Pipe &) const;
73 };
74
75 using PipeSet = std::set<Pipe>;
76
80 class Pipelines {
81 friend class CollectPipelines;
82 std::vector<Pipe> pipes;
83 std::map<const IR::Type_Declaration *, std::unordered_set<int>,
85 declarationToPipe;
86
87 PipeSet _get(const IR::Type_Declaration *dec) const {
88 auto it = declarationToPipe.find(dec);
89 BUG_CHECK(it != declarationToPipe.end(), "Declaration %1% not found in pipes", dec);
90 PipeSet out;
91 for (int idx : it->second) out.insert(pipes[idx]);
92 return out;
93 }
94
95 public:
96 std::vector<Pipe>::const_iterator begin() const { return pipes.begin(); }
97 std::vector<Pipe>::const_iterator end() const { return pipes.end(); }
98
100 PipeSet get(const IR::BFN::TnaParser *p) const { return _get(p); }
102 PipeSet get(const IR::BFN::TnaDeparser *d) const { return _get(d); }
104 PipeSet get(const IR::BFN::TnaControl *c) const { return _get(c); }
105 };
106
107 private:
108 P4::ReferenceMap *refMap;
109 Pipelines *pipelines;
110 std::unordered_map<const IR::IDeclaration *, Pipe> pipesByDec;
111
112 public:
115 explicit CollectPipelines(P4::ReferenceMap *refMap, Pipelines *pipelines)
116 : refMap(refMap), pipelines(pipelines) {}
117};
118
119} // namespace BFN
120
121#endif // BACKENDS_TOFINO_BF_P4C_MIDEND_COLLECT_PIPELINES_H_
Definition collect_pipelines.h:58
bool operator==(const Pipe &) const
Definition collect_pipelines.cpp:73
bool operator<(const Pipe &) const
A total order given by declaration names (i.e. consistent with ==).
Definition collect_pipelines.cpp:77
Definition collect_pipelines.h:80
PipeSet get(const IR::BFN::TnaControl *c) const
Set of all pipes using this control.
Definition collect_pipelines.h:104
PipeSet get(const IR::BFN::TnaParser *p) const
Set of all pipes using this parser.
Definition collect_pipelines.h:100
PipeSet get(const IR::BFN::TnaDeparser *d) const
Set of all pipes using this deparser.
Definition collect_pipelines.h:102
Definition cmp.h:97
The Declaration interface, representing objects with names.
Definition declaration.h:26
Definition visitor.h:400
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
CollectPipelines(P4::ReferenceMap *refMap, Pipelines *pipelines)
Definition collect_pipelines.h:115
Inspector pass that collects information about all pipelines declared in the Switch....
Definition collect_pipelines.h:42
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
Description ingress or egress.
Definition collect_pipelines.h:48