P4C
The P4 Compiler
Loading...
Searching...
No Matches
add_always_run.h
1
19#ifndef BF_P4C_MAU_ADD_ALWAYS_RUN_H_
20#define BF_P4C_MAU_ADD_ALWAYS_RUN_H_
21
22#include <optional>
23
24#include "bf-p4c/logging/pass_manager.h"
25#include "bf-p4c/mau/table_flow_graph.h"
26#include "bf-p4c/phv/phv_fields.h"
27
28using namespace P4;
29
33class AddAlwaysRun : public PassManager {
34 friend class AddAlwaysRunTest;
35
36 private:
38 const ordered_map<gress_t, ConstraintMap> &allTablesToAdd;
39
43
49 std::map<gress_t, ordered_map<const UniqueId, unsigned>> globalOrderings;
50
71 std::map<const UniqueId, std::optional<UniqueId>> subsequentTables;
72
77 int compare(const IR::MAU::Table *t1, const IR::MAU::Table *t2) const;
78 int compare(const IR::MAU::Table *t1, std::optional<UniqueId> t2) const;
79
82 class PrepareToAdd : public MauInspector {
83 AddAlwaysRun &self;
84
86 const IR::MAU::Table *subsequentTable = nullptr;
87
89 std::map<const IR::MAU::Table *, const IR::MAU::Table *> minSubsequentTables;
90
91 profile_t init_apply(const IR::Node *root) override;
92 bool preorder(const IR::MAU::TableSeq *) override;
93 bool preorder(const IR::MAU::Table *) override;
94 void end_apply(const IR::Node *root) override;
95
96 public:
97 explicit PrepareToAdd(AddAlwaysRun &self) : self(self) {}
98 };
99
101 class AddTables : public MauTransform, ControlFlowVisitor {
102 AddAlwaysRun &self;
103
107 //
108 // Invariant: this is empty at the start and end of each visit to each gress.
109 std::list<const IR::MAU::Table *> tablesToAdd;
110
112 std::optional<UniqueId> subsequentTable;
113
114 const IR::BFN::Pipe *preorder(IR::BFN::Pipe *) override;
115 const IR::Node *preorder(IR::MAU::TableSeq *) override;
116
117 AddTables *clone() const override;
118 AddTables &flow_clone() override;
119 void flow_merge(Visitor &v) override;
120 void flow_copy(::ControlFlowVisitor &v) override;
121
122 AddTables(const AddTables &) = default;
123 AddTables(AddTables &&) = default;
124
125 public:
126 explicit AddTables(AddAlwaysRun &self) : self(self) {}
127 };
128
129 public:
130 explicit AddAlwaysRun(const ordered_map<gress_t, ConstraintMap> &tablesToAdd);
131};
132
133#endif /* BF_P4C_MAU_ADD_ALWAYS_RUN_H_ */
Definition add_always_run.h:33
Definition mau_visitor.h:29
Definition mau_visitor.h:55
Definition visitor.h:463
Definition node.h:95
Definition ir/pass_manager.h:40
Definition visitor.h:78
Definition visitor.h:75
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24