P4C
The P4 Compiler
Loading...
Searching...
No Matches
container_equivalence.h
1
19#pragma once
20
21#include "backends/tofino/bf-p4c/phv/utils/utils.h"
22
23namespace PHV {
24
30 using GressAssignment = PHV::Allocation::GressAssignment;
31 using ExtractSource = PHV::Allocation::ExtractSource;
32 using ContainerAllocStatus = PHV::Allocation::ContainerAllocStatus;
33 enum class Parity : int8_t { Zero = 0, One = 1, Unspecified = -1 };
34
35 struct ContainerClass {
36 bool is_empty;
37 Parity parity;
38 PHV::Kind kind;
39 GressAssignment gress;
40 GressAssignment parser_group_gress;
41 GressAssignment deparser_group_gress;
42 ExtractSource parser_extract_group_source;
43
44 ContainerClass(const PHV::Allocation &alloc, PHV::Container c, bool track_parity) {
45 auto cstat = alloc.getStatus(c);
46 BUG_CHECK(cstat, "no allocation status for container %1%", c);
47 is_empty = cstat->alloc_status == ContainerAllocStatus::EMPTY;
48 parity = track_parity ? Parity(c.index() % 2) : Parity::Unspecified;
49 kind = c.type().kind();
50 gress = cstat->gress;
51 parser_group_gress = cstat->parserGroupGress;
52 deparser_group_gress = cstat->deparserGroupGress;
53 parser_extract_group_source = cstat->parserExtractGroupSource;
54 }
55
56 bool operator==(const ContainerClass &o) const { return as_tuple() == o.as_tuple(); }
57
58 bool operator<(const ContainerClass &o) const { return as_tuple() < o.as_tuple(); }
59
60 std::tuple<bool, Parity, PHV::Kind, GressAssignment, GressAssignment, GressAssignment,
61 ExtractSource>
62 as_tuple() const {
63 return std::make_tuple(is_empty, parity, kind, gress, parser_group_gress,
64 deparser_group_gress, parser_extract_group_source);
65 }
66 };
67
68 public:
69 explicit ContainerEquivalenceTracker(const PHV::Allocation &alloc);
70
75 std::optional<PHV::Container> find_equivalent_tried_container(PHV::Container c);
76
80 if (c != PHV::Container()) excluded.insert(c);
81 }
82
88
91 void set_is_wide_arith() { wideArith = true; }
92
96 void set_is_wide_arith_low() { wideArithLow = true; }
97
98 private:
99 std::optional<PHV::Container> find_single(PHV::Container);
100 ContainerClass get_class(PHV::Container c) {
101 return ContainerClass(alloc, c, wideArith || (restrictW0 && c.is(PHV::Size::b8)));
102 }
103
104 std::map<ContainerClass, PHV::Container> equivalenceClasses;
105 std::set<PHV::Container> excluded;
106 const PHV::Allocation &alloc;
107 bool wideArith = false;
108 bool wideArithLow = false;
119 bool restrictW0;
120};
121
122} // namespace PHV
Definition phv/utils/utils.h:117
virtual const ContainerStatus * getStatus(const PHV::Container &c) const =0
Definition container_equivalence.h:29
void exclude(PHV::Container c)
Definition container_equivalence.h:79
std::optional< PHV::Container > find_equivalent_tried_container(PHV::Container c)
Definition container_equivalence.cpp:26
void set_is_wide_arith_low()
Definition container_equivalence.h:96
void set_is_wide_arith()
Definition container_equivalence.h:91
void invalidate(PHV::Container c)
Definition container_equivalence.cpp:50
Definition phv.h:176
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Kind
Definition phv.h:44