P4C
The P4 Compiler
Loading...
Searching...
No Matches
fold_constant_hashes.h
1
19#ifndef BF_P4C_MIDEND_FOLD_CONSTANT_HASHES_H_
20#define BF_P4C_MIDEND_FOLD_CONSTANT_HASHES_H_
21
22/* clang-format off */
23#include "ir/ir.h"
24#include "backends/tofino/bf-p4c/midend/type_checker.h"
25#include "backends/tofino/bf-p4c/mau/hash_function.h"
26#include "backends/tofino/bf-utils/include/dynamic_hash/dynamic_hash.h"
27
28namespace BFN {
29
59 P4::ReferenceMap *refMap = nullptr;
60 P4::TypeMap *typeMap = nullptr;
61
62 // The set of declid's of the Hash or CRCPolynomial objects that are candidates for removal
63 std::set<int> candidatesToRemove;
64 // The set of method call statements to be removed
65 std::set<int> methodCallStatementsToRemove;
66
67 class DoFoldConstantHashes : public Transform {
69
70 bool checkConstantInput(const IR::Expression *expr);
71 void foldListToConstant(uint64_t &value, size_t &shift, const IR::ListExpression *list);
72 void foldListToConstant(uint64_t &value, size_t &shift, const IR::StructExpression *list);
73 const IR::Expression *substituteIdentityHash(const IR::ListExpression *hash_list,
74 const IR::Type *hash_type);
75 const IR::Expression *substituteIdentityHash(const IR::StructExpression *hash_list,
76 const IR::Type *hash_type);
77
78 hash_seed_t computeHash(IR::MAU::HashFunction &hash_function,
79 const IR::ListExpression *hash_list, const IR::Type *hash_type);
80 hash_seed_t computeHash(IR::MAU::HashFunction &hash_function,
81 const IR::StructExpression *hash_list, const IR::Type *hash_type);
82 const IR::Expression *substituteCustomHash(const IR::PathExpression *crc_poly_path,
83 const IR::ListExpression *hash_list,
84 const IR::Type *hash_type);
85 const IR::Expression *substituteCustomHash(const IR::PathExpression *crc_poly_path,
86 const IR::StructExpression *hash_list,
87 const IR::Type *hash_type);
88 const IR::Expression *substituteOtherHash(const IR::Expression *hash_algo_expr,
89 const IR::ListExpression *hash_list,
90 const IR::Type *hash_type);
91 const IR::Expression *substituteOtherHash(const IR::Expression *hash_algo_expr,
92 const IR::StructExpression *hash_list,
93 const IR::Type *hash_type);
94
95 public:
96 explicit DoFoldConstantHashes(FoldConstantHashes &self) : self(self) {}
97 const IR::Node *preorder(IR::MethodCallExpression *mce) override;
98 };
99
100 class CheckCandidesToRemove : public Transform {
101 FoldConstantHashes &self;
102
103 public:
104 explicit CheckCandidesToRemove(FoldConstantHashes &self) : self(self) {}
105 const IR::Node *preorder(IR::PathExpression *path) override;
106 };
107
108 class RemoveHangingCandidates : public Transform {
109 FoldConstantHashes &self;
110
111 public:
112 explicit RemoveHangingCandidates(FoldConstantHashes &self) : self(self) {}
113 const IR::Node *preorder(IR::Declaration_Instance *decl) override;
114 const IR::Node *preorder(IR::MethodCallStatement *mcs) override;
115 };
116
117 const IR::Type *checkHashExtern(const IR::Declaration_Instance *decl);
118
119 public:
121 BFN::TypeChecking *typeChecking = nullptr)
122 : refMap(refMap), typeMap(typeMap) {
123 if (!typeChecking) typeChecking = new BFN::TypeChecking(refMap, typeMap);
124 addPasses({typeChecking, new DoFoldConstantHashes(*this), new P4::ClearTypeMap(typeMap),
125 typeChecking, new CheckCandidesToRemove(*this),
126 new RemoveHangingCandidates(*this), new P4::ClearTypeMap(typeMap)});
127 }
128};
129
130} // namespace BFN
131
132/* clang-format on */
133
134#endif // BF_P4C_MIDEND_FOLD_CONSTANT_HASHES_H_
Definition typeChecker.h:32
Definition node.h:94
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition visitor.h:424
Definition typeChecker.h:55
Definition typeMap.h:41
PassManager that substitutes the calls of the get methods of the Hash externs whose inputs are consta...
Definition fold_constant_hashes.h:58
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
Definition hash_function.h:28
Definition dynamic_hash.h:122