P4C
The P4 Compiler
Loading...
Searching...
No Matches
elim_unused.h
1
19#ifndef BF_P4C_COMMON_ELIM_UNUSED_H_
20#define BF_P4C_COMMON_ELIM_UNUSED_H_
21
22#include "field_defuse.h"
23
24using namespace P4;
25
26class ReplaceMember : public Transform {
27 const IR::BFN::AliasMember *preorder(IR::BFN::AliasMember *m) { return m; }
28 const IR::BFN::AliasMember *preorder(IR::Member *m) { return new IR::BFN::AliasMember(m, m); }
29};
30
31class ElimUnused : public PassManager {
32 const PhvInfo &phv;
33 FieldDefUse &defuse;
34 std::set<cstring> &zeroInitFields;
35
36 class Instructions;
37 class CollectEmptyTables;
38 class Tables;
39 class Headers;
40
41 public:
42 ElimUnused(const PhvInfo &phv, FieldDefUse &defuse, std::set<cstring> &zeroInitFields);
43};
44
46 protected:
47 const FieldDefUse &defuse;
48
50 std::set<cstring> eliminated;
51
52 const IR::MAU::StatefulAlu *preorder(IR::MAU::StatefulAlu *salu) override {
53 // Don't go through these.
54 prune();
55 return salu;
56 }
57
58 const IR::GlobalRef *preorder(IR::GlobalRef *gr) override {
59 // Don't go through these.
60 prune();
61 return gr;
62 }
63
65 virtual bool elim_extract(const IR::BFN::Unit *unit, const IR::BFN::Extract *extract) = 0;
66
67 const IR::BFN::Extract *preorder(IR::BFN::Extract *extract) override;
68 const IR::BFN::FieldLVal *preorder(IR::BFN::FieldLVal *lval) override;
69
70 explicit AbstractElimUnusedInstructions(const FieldDefUse &defuse) : defuse(defuse) {}
71};
72
73#endif /* BF_P4C_COMMON_ELIM_UNUSED_H_ */
Definition elim_unused.h:45
virtual bool elim_extract(const IR::BFN::Unit *unit, const IR::BFN::Extract *extract)=0
Determines whether the given extract, occurring in the given unit, should be eliminated.
std::set< cstring > eliminated
Names of fields whose extracts have been eliminated.
Definition elim_unused.h:50
Definition elim_unused.cpp:208
Definition elim_unused.cpp:68
Removes no-op tables that have the @hidden annotation.
Definition elim_unused.cpp:118
Definition elim_unused.h:31
Definition ir/pass_manager.h:40
Definition visitor.h:424
Definition phv_fields.h:1095
Definition elim_unused.h:26
Definition field_defuse.h:77
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24