P4C
The P4 Compiler
Loading...
Searching...
No Matches
field_pov_analysis.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_FIELD_POV_ANALYSIS_H_
20#define BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_FIELD_POV_ANALYSIS_H_
21
22#include "bf-p4c/parde/clot/clot_info.h"
23#include "bf-p4c/parde/parser_info.h"
24
25/* This pass is a parser data flow analysis to find if a field is extracted from
26 * the packet in every path that sets the field's valid bit. If there exists a path
27 * where valid bit is set but no fields of the corresponding header is extracted
28 * from the packet then such fields should not be placed in clots.
29 *
30 * The analysis proceeds in topological sorted order.
31 * Every state has two bitvectors :
32 * 1. field_vec : Contains fields that are definitely extracted from the packet before
33 * the current state
34 * 2. pov_vec : Valid bits that are set before the current state and are waiting for
35 corresponding fields to be extracted.
36 *
37 * The current state will add a field in its field_vec if any of these conditions are met:
38 * 1. Field is extracted from the packet in the current state
39 * 2. The field is present in all the immediate predecessors' field_vec
40 *
41 * Subsequently, the current state will add a valid bit in its pov_vec if
42 * any of these conditions are met:
43 * 1. The valid bit is set in current state and the field is not present in the
44 field_vec of the current state
45 * 2. Valid bit is set in any immediate predecessors' pov_vec and the field is not present
46 * in the field_vec for the current state.
47 *
48 * If the current state transitions to end, then the povbits that are set in pov_vec
49 * are added in pov_extracted_without_fields.
50 */
52 ClotInfo &clotInfo;
53 const PhvInfo &phv;
54 std::set<const IR::BFN::Parser *> parsers;
55 std::map<const PHV::Field *, std::set<const PHV::Field *>> pov_to_fields;
56
58 std::map<cstring, std::pair<bitvec, bitvec>> state_to_field_pov;
59 bool preorder(const IR::BFN::Parser *parser) override;
60 bool preorder(const IR::BFN::EmitField *emit) override;
61 void end_apply() override;
62
63 public:
64 std::set<const PHV::Field *> pov_extracted_without_fields;
65 FieldPovAnalysis(ClotInfo &clotInfo, const PhvInfo &phv) : clotInfo(clotInfo), phv(phv) {}
66 Visitor::profile_t init_apply(const IR::Node *root) override {
67 profile_t rv = Inspector::init_apply(root);
68 pov_to_fields.clear();
69 state_to_field_pov.clear();
70 parsers.clear();
71 return rv;
72 }
73};
74
75#endif /* BACKENDS_TOFINO_BF_P4C_PARDE_CLOT_FIELD_POV_ANALYSIS_H_ */
Definition clot_info.h:41
Definition field_pov_analysis.h:51
Definition node.h:95
Definition visitor.h:400
Definition visitor.h:78
Definition phv_fields.h:1095