P4C
The P4 Compiler
Loading...
Searching...
No Matches
build_mutex.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PHV_ANALYSIS_BUILD_MUTEX_H_
20#define BACKENDS_TOFINO_BF_P4C_PHV_ANALYSIS_BUILD_MUTEX_H_
21
22#include "bf-p4c/ir/control_flow_visitor.h"
23#include "bf-p4c/phv/phv_fields.h"
24#include "bf-p4c/phv/pragma/phv_pragmas.h"
25#include "ir/ir.h"
26#include "ir/visitor.h"
27#include "lib/bitvec.h"
28#include "lib/cstring.h"
29#include "lib/symbitmatrix.h"
30
31/* Produces a SymBitMatrix where keys are PHV::Field ids and values indicate
32 * whether two fields are mutually exclusive, based on analyzing the structure
33 * of the control flow graph to identify fields that are not live at the same
34 * time.
35 *
36 * ALGORITHM: Build @mutually_inclusive, which denotes pairs of fields that are
37 * live on the same control-flow path. All fields in @fields_encountered that
38 * are not mutually inclusive are mutually exclusive.
39 *
40 * For example, BuildParserOverlay inherits from BuildMutex, traversing the
41 * parser control flow graph (and nothing else), and ignoring non-header
42 * fields, to produce header fields that cannot be parsed from the same packet.
43 *
44 * @warning Take care when traversing a subset of the IR, because this might
45 * produce fields that are mutually exclusive in that subgraph but not
46 * throughout the entire IR. For example, header fields that are mutually
47 * exclusive in the parser may be added to the same packet in the MAU pipeline.
48 *
49 * Takes as an argument a set of fields that can be added in the MAU pipeline.
50 * These fields are never considered to be mutually exclusive with any other
51 * field based on this analysis of the parser.
52 *
53 * For example, many P4 parsers accept packets that have either an IPv4 or IPv6
54 * header, but not both. These headers are considered mutually exclusive.
55 * However, suppose an `add_header(ipv4)` instruction exists in the MAU
56 * pipeline, and fields in the IPv4 header are supplied to this pass. In that
57 * case, IPv4 and IPv6 header fields are not considered mutually exclusive.
58 *
59 * This class is intended to be specialized in two ways: to tailor which parts
60 * of the pipeline are visited, and to tailor which kinds of fields are
61 * considered. @see BuildParserOverlay, BuildMetadataOverlay.
62 */
64 public:
65 using FieldFilter_t = std::function<bool(const PHV::Field *f)>;
66
67 protected:
68 PhvInfo &phv;
69 const bitvec &neverOverlay;
70 const PragmaNoOverlay &pragma;
71
75
79
81 FieldFilter_t IgnoreField;
82
85
86 virtual void mark(const PHV::Field *);
87
88 profile_t init_apply(const IR::Node *root) override;
89 bool preorder(const IR::Expression *) override;
90 bool preorder(const IR::MAU::Action *act) override;
91 void flow_merge(Visitor &) override;
92 void flow_copy(::ControlFlowVisitor &) override;
93 void end_apply() override;
94
95 public:
96 BuildMutex(PhvInfo &phv, const bitvec &neverOverlay, const PragmaNoOverlay &pragma,
97 FieldFilter_t ignore_field)
98 : phv(phv),
99 neverOverlay(neverOverlay),
100 pragma(pragma),
101 mutually_exclusive(phv.field_mutex()),
102 IgnoreField(ignore_field) {
103 joinFlows = true;
104 visitDagOnce = false;
105 BackwardsCompatibleBroken = true;
106 }
107
108 BuildMutex *clone() const override { return new BuildMutex(*this); }
109};
110
111#endif /* BACKENDS_TOFINO_BF_P4C_PHV_ANALYSIS_BUILD_MUTEX_H_ */
Definition build_mutex.h:63
profile_t init_apply(const IR::Node *root) override
Definition build_mutex.cpp:21
FieldFilter_t IgnoreField
Definition build_mutex.h:81
SymBitMatrix mutually_inclusive
Definition build_mutex.h:74
SymBitMatrix & mutually_exclusive
Definition build_mutex.h:78
void flow_merge(Visitor &) override
Definition build_mutex.cpp:56
bitvec fields_encountered
Tracks the fields encountered (and not ignored) during this analysis.
Definition build_mutex.h:84
Definition visitor.h:463
Definition node.h:95
Definition visitor.h:400
Definition symbitmatrix.h:27
Definition visitor.h:78
Definition visitor.h:75
Definition bitvec.h:120
Definition phv_fields.h:154
Definition phv_fields.h:1095
Definition pa_no_overlay.h:33