P4C
The P4 Compiler
Loading...
Searching...
No Matches
check_uninitialized_read.h
1
19#ifndef BF_P4C_COMMON_CHECK_UNINITIALIZED_READ_H_
20#define BF_P4C_COMMON_CHECK_UNINITIALIZED_READ_H_
21
22#include "backends/tofino/bf-p4c/arch/bridge_metadata.h"
23#include "backends/tofino/bf-p4c/common/field_defuse.h"
24#include "backends/tofino/bf-p4c/mau/table_dependency_graph.h"
25#include "backends/tofino/bf-p4c/phv/phv_parde_mau_use.h"
26#include "backends/tofino/bf-p4c/phv/pragma/phv_pragmas.h"
27#include "ir/ir.h"
28
29using namespace P4;
30
31/* FindUninitializedAndOverlayedReads Pass does the following
32 * - Checks all field slices for overlays
33 * - Throws a warning message if uninitialized fields can cause data corruption due to overlay
34 * - Skips field slices which are
35 * - with a pa_no_init pragma
36 * - pov bits
37 * - padding fields
38 * - deparser zero candidates
39 * - overlayable fields
40 * - pov bit protected fields (which are not overlayable)
41 */
43 const FieldDefUse &defuse;
44 const PhvInfo &phv;
45 const PHV::Pragmas &pragmas;
46 const DependencyGraph &deps;
47
48 ordered_set<const PHV::Field *> pov_protected_fields;
49
50 struct uninit_read {
51 cstring field_slice;
52 cstring overlay_slice;
53 cstring field_cont_slice;
54 cstring overlay_cont_slice;
55 cstring loc;
56
57 // Less than function for std::set comparison to skip adding duplicates
58 bool operator<(const uninit_read &other) const {
59 return std::tie(field_slice, overlay_slice, field_cont_slice, overlay_cont_slice, loc) <
60 std::tie(other.field_slice, other.overlay_slice, other.field_cont_slice,
61 other.overlay_cont_slice, loc);
62 }
63
64 uninit_read(cstring fs, cstring os, cstring fcs, cstring ocs, cstring loc)
65 : field_slice(fs),
66 overlay_slice(os),
67 field_cont_slice(fcs),
68 overlay_cont_slice(ocs),
69 loc(loc) {}
70 };
71
72 public:
74 const PHV::Pragmas &pragmas, const DependencyGraph &deps)
75 : defuse(defuse), phv(phv), pragmas(pragmas), deps(deps) {}
76
77 bool preorder(const IR::BFN::DeparserParameter *param) override;
78 bool preorder(const IR::BFN::Digest *digest) override;
79
80 void end_apply() override;
81};
82
84 public:
86 const PHV::Pragmas &pragmas, const BFN_Options &options);
87};
88#endif /* BF_P4C_COMMON_CHECK_UNINITIALIZED_READ_H_ */
Definition bf-p4c-options.h:28
Definition check_uninitialized_read.h:83
Definition check_uninitialized_read.h:42
bool preorder(const IR::BFN::DeparserParameter *param) override
Definition check_uninitialized_read.cpp:26
Definition visitor.h:400
Definition ir/pass_manager.h:40
Definition cstring.h:85
Definition ordered_set.h:32
Definition phv_pragmas.h:46
Definition phv_fields.h:1095
Definition field_defuse.h:77
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition table_dependency_graph.h:52