P4C
The P4 Compiler
Loading...
Searching...
No Matches
handle_assign.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_MAU_HANDLE_ASSIGN_H_
20#define BACKENDS_TOFINO_BF_P4C_MAU_HANDLE_ASSIGN_H_
21
22#include "bf-p4c/mau/ixbar_expr.h"
23#include "bf-p4c/mau/mau_visitor.h"
24#include "bf-p4c/phv/phv_fields.h"
25
26using namespace P4;
27
38 class ActionProfileImposedConstraints : public MauInspector {
40 bool preorder(const IR::MAU::ActionData *) override;
41 bool preorder(const IR::MAU::Table *) override {
42 visitOnce();
43 return true;
44 }
45
46 public:
47 ActionProfileImposedConstraints() { visitDagOnce = false; }
48 };
49
51 HandleAssignments handle_assignments;
52
53 class DetermineHandle : public MauInspector {
54 // 0 - phase0 table action handle
55 static constexpr unsigned INIT_ACTION_HANDLE = (0x20 << 24) + 1;
56 unsigned handle_position = 0;
57
59 typedef ordered_map<cstring, unsigned> ProfileAssignment;
61 bool preorder(const IR::MAU::Action *) override;
62 profile_t init_apply(const IR::Node *root) override;
63 unsigned next_handle() {
64 unsigned rv = INIT_ACTION_HANDLE + handle_position;
65 handle_position++;
66 return rv;
67 }
68
69 public:
70 explicit DetermineHandle(AssignActionHandle &aah) : self(aah) {}
71 };
72
73 class AssignHandle : public MauModifier {
74 const AssignActionHandle &self;
75 bool preorder(IR::MAU::Action *) override;
76
77 public:
78 explicit AssignHandle(const AssignActionHandle &aah) : self(aah) {}
79 };
80
81 class GuaranteeUniqueHandle : public MauInspector {
83 std::map<unsigned, const IR::MAU::Action *> unique_handle;
84 profile_t init_apply(const IR::Node *root) override;
85 bool preorder(const IR::MAU::Action *) override;
86
87 public:
88 GuaranteeUniqueHandle() {}
89 };
90
91 class ValidateSelectors : public PassManager {
95 const PhvInfo &phv;
96
97 profile_t init_apply(const IR::Node *root) override;
98
99 class ValidateKey : public MauInspector {
100 ValidateSelectors &self;
101
102 bool preorder(const IR::MAU::Selector *sel) override;
103 bool preorder(const IR::MAU::Table *) override {
104 visitOnce();
105 return true;
106 }
107
108 public:
109 explicit ValidateKey(ValidateSelectors &s) : self(s) { visitDagOnce = false; }
110 };
111
112 class SetSymmetricSelectorKeys : public MauModifier {
113 ValidateSelectors &self;
114 bool preorder(IR::MAU::Table *tbl) override;
115
116 public:
117 explicit SetSymmetricSelectorKeys(ValidateSelectors &s) : self(s) {}
118 };
119
120 public:
121 explicit ValidateSelectors(const PhvInfo &phv) : phv(phv) {
122 addPasses({new ValidateKey(*this), new SetSymmetricSelectorKeys(*this)});
123 }
124 };
125
126 public:
127 explicit AssignActionHandle(const PhvInfo &phv) {
128 addPasses({new ValidateSelectors(phv), new ActionProfileImposedConstraints,
129 new DetermineHandle(*this), new AssignHandle(*this), new GuaranteeUniqueHandle});
130 }
131};
132
133#endif /* BACKENDS_TOFINO_BF_P4C_MAU_HANDLE_ASSIGN_H_ */
Definition handle_assign.h:37
Definition mau_visitor.h:29
Definition mau_visitor.h:45
Definition node.h:95
Definition ir/pass_manager.h:40
Definition visitor.h:78
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv_fields.h:1095
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24