P4C
The P4 Compiler
Loading...
Searching...
No Matches
eliminate_tuples.h
1
19#ifndef BF_P4C_MIDEND_ELIMINATE_TUPLES_H_
20#define BF_P4C_MIDEND_ELIMINATE_TUPLES_H_
21
22#include "frontends/common/resolveReferences/resolveReferences.h"
23#include "frontends/p4/typeChecking/typeChecker.h"
24#include "ir/ir.h"
25#include "midend/eliminateTuples.h"
26
27namespace BFN {
28
29// Finds all of the HashListExpressions and saves their data
30// so it is not lost during TupleReplacement->TypeInference
31// (which converts ListExpression to StructExpression,
32// and since HashListExpression is also ListExpression
33// it gets transformed and the extra data are lost)
35 public:
36 std::map<const IR::Expression *, const IR::HashListExpression *> update_hashes;
37
38 bool preorder(const IR::HashListExpression *hle) override;
39};
40
41// Inserts back the information from HashListExpressions to new HashStructExpressions
43 std::map<const IR::Expression *, const IR::HashListExpression *> *update_hashes;
44
45 public:
47 std::map<const IR::Expression *, const IR::HashListExpression *> *update_hashes)
48 : update_hashes(update_hashes){};
49
50 const IR::Node *preorder(IR::StructExpression *se) override;
51};
52
56class EliminateTuples final : public PassManager {
57 public:
59 P4::TypeChecking *typeChecking = nullptr,
60 P4::TypeInference *typeInference = nullptr) {
61 if (!typeChecking) typeChecking = new P4::TypeChecking(refMap, typeMap);
62 passes.push_back(typeChecking);
63 passes.push_back(new P4::DoReplaceTuples(typeMap));
64 // Save any HashListExpressions
65 auto shle = new SaveHashListExpression();
66 passes.push_back(shle);
67 passes.push_back(new P4::ClearTypeMap(typeMap));
68 // We do a round of type-checking which may mutate the program.
69 // This will convert some ListExpressions
70 // into StructExpression where tuples were converted
71 // to structs.
72 passes.push_back(new P4::ResolveReferences(refMap));
73 if (!typeInference) typeInference = new P4::TypeInference(typeMap, false);
74 passes.push_back(typeInference);
75 // Reinsert HashListExpression information
76 passes.push_back(new InsertHashStructExpression(&shle->update_hashes));
77 setName("EliminateTuples");
78 }
79};
80
81} // namespace BFN
82
83#endif /* BF_P4C_MIDEND_ELIMINATE_TUPLES_H_ */
Definition eliminate_tuples.h:42
Definition eliminate_tuples.h:34
Definition typeChecker.h:32
Definition eliminateTuples.h:77
Definition eliminateTuples.h:117
Definition node.h:95
Definition visitor.h:400
Definition ir/pass_manager.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition resolveReferences.h:123
Definition visitor.h:424
Definition typeChecker.h:55
Definition typeChecker.h:483
Definition typeMap.h:41
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21