P4C
The P4 Compiler
Loading...
Searching...
No Matches
collect_bridged_fields.h
1
19#ifndef BF_P4C_ARCH_COLLECT_BRIDGED_FIELDS_H_
20#define BF_P4C_ARCH_COLLECT_BRIDGED_FIELDS_H_
21
22#include <optional>
23#include <utility>
24
25#include "ir/control_flow_visitor.h"
26#include "ir/ir.h"
27#include "lib/cstring.h"
28#include "lib/ordered_map.h"
29#include "lib/ordered_set.h"
30
31namespace P4 {
32class ReferenceMap;
33class TypeMap;
34} // namespace P4
35
36namespace BFN {
37
38using FieldRef = std::pair<cstring, cstring>;
39
41 const IR::Type *type;
42 const IR::Expression *refTemplate;
43};
44
47 protected P4WriteContext {
49 using TnaContext = std::pair<gress_t, const TnaParams &>;
50
52
53 ordered_set<FieldRef> mayReadUninitialized[2];
54 ordered_set<FieldRef> mayWrite[2];
55 ordered_set<FieldRef> mustWrite[2]; // TODO: Not much use testing this...
56
58 std::set<FieldRef> fieldsToBridge; // using set here to avoid pathological case with
59 // tofino/switch_generic_int_leaf that happens with
60 // ordered_set (visit order)
61 ordered_set<cstring> doNotBridge;
62
63 private:
64 CollectBridgedFields *clone() const override;
65 void flow_merge(Visitor &otherVisitor) override;
66 void flow_copy(::ControlFlowVisitor &otherVisitor) override;
67
68 std::optional<TnaContext> findTnaContext() const;
69 bool analyzePathlikeExpression(const IR::Expression *expr);
70
71 // skip non-TNA controls/parsers
72 bool preorder(const IR::P4Parser *) override { return false; }
73 bool preorder(const IR::P4Control *) override { return false; }
74 bool preorder(const IR::BFN::TnaControl *) override;
75 bool preorder(const IR::BFN::TnaParser *) override;
76 bool preorder(const IR::BFN::TnaDeparser *) override;
77 bool preorder(const IR::P4Table *) override;
78 bool preorder(const IR::Annotation *annot) override;
79 bool preorder(const IR::Member *member) override;
80 bool preorder(const IR::PathExpression *path) override;
81 bool preorder(const IR::MethodCallExpression *) override;
82 void end_apply() override;
83
84 // ignore parser and declaration loops for now
85 void loop_revisit(const IR::ParserState *) override {}
86 void loop_revisit(const IR::Declaration_Instance *) override {}
87
88 P4::ReferenceMap *refMap;
89 P4::TypeMap *typeMap;
90
93 int uid;
94 static int uid_counter;
95};
96
97} // namespace BFN
98
99#endif /* BF_P4C_ARCH_COLLECT_BRIDGED_FIELDS_H_ */
Definition visitor.h:463
Definition visitor.h:400
Definition visitor.h:788
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeMap.h:41
Definition visitor.h:75
Definition ordered_set.h:32
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
Definition collect_bridged_fields.h:40
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition collect_bridged_fields.h:47