19#ifndef BF_P4C_COMMON_HEADER_STACK_H_
20#define BF_P4C_COMMON_HEADER_STACK_H_
23#include "ir/pass_manager.h"
36struct CollectHeaderStackInfo :
public Modifier {
37 CollectHeaderStackInfo();
41 void postorder(IR::HeaderStack *stack)
override;
42 void postorder(IR::MAU::Primitive *primitive)
override;
43 void postorder(IR::BFN::Pipe *pipe)
override;
50class ElimUnusedHeaderStackInfo :
public PassManager {
55 ElimUnusedHeaderStackInfo &self;
59 explicit Find(ElimUnusedHeaderStackInfo &self) : self(self) {}
64 return Inspector::init_apply(root);
67 bool preorder(
const IR::BFN::Pipe *pipe)
override {
68 BUG_CHECK(pipe->headerStackInfo !=
nullptr,
69 "Running ElimUnusedHeaderStackInfo without running "
70 "CollectHeaderStackInfo first?");
71 stacks = pipe->headerStackInfo;
75 void postorder(
const IR::HeaderStack *stack)
override;
76 void end_apply()
override;
81 ElimUnusedHeaderStackInfo &self;
82 explicit Elim(ElimUnusedHeaderStackInfo &self) : self(self) {}
84 void postorder(IR::BFN::Pipe *pipe)
override;
88 ElimUnusedHeaderStackInfo() { addPasses({
new Find(*
this),
new Elim(*
this)}); }
117 friend struct ::CollectHeaderStackInfo;
118 friend class ::ElimUnusedHeaderStackInfo;
122 auto begin() const -> decltype(Values(info).begin()) {
return Values(info).begin(); }
123 auto begin() ->
decltype(Values(
info).begin()) {
return Values(
info).begin(); }
124 auto end() const -> decltype(Values(
info).end()) {
return Values(
info).end(); }
125 auto end() ->
decltype(Values(info).end()) {
return Values(info).end(); }
126 auto at(cstring n)
const ->
decltype(info.at(n)) {
return info.at(n); }
127 auto at(cstring n) ->
decltype(info.at(n)) {
return info.at(n); }
128 auto count(cstring n)
const ->
decltype(info.count(n)) {
return info.count(n); }
129 const Info *get(cstring n)
const {
130 if (
auto it = info.find(n); it != info.end())
return &it->second;
149 IR::Node *preorder(IR::MAU::Action *act)
override;
152 RemovePushInitialization() {}
164 IR::Node *preorder(IR::BFN::Pipe *pipe)
override;
168 IR::Node *postorder(IR::Member *member)
override;
179 IR::Node *postorder(IR::BFN::Extract *extract)
override;
182 explicit ValidToStkvalid(
PhvInfo &) {}
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv_fields.h:1095
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void info(const int kind, const char *format, const T *node, Args &&...args)
Report info messages of type kind. Requires that the node argument have source info.
Definition lib/error.h:155