P4C
The P4 Compiler
Loading...
Searching...
No Matches
copacker.h
1
19#ifndef BF_P4C_PHV_V2_COPACKER_H_
20#define BF_P4C_PHV_V2_COPACKER_H_
21
22#include "bf-p4c/phv/action_source_tracker.h"
23#include "bf-p4c/phv/utils/utils.h"
24#include "bf-p4c/phv/v2/utils_v2.h"
25
26namespace PHV {
27namespace v2 {
28
31struct SrcPackVec {
33 std::optional<PHV::Container> container = std::nullopt;
34
37
40 // bool left_shiftable = false;
41
43 bool empty() const { return fs_starts.empty(); }
44
46 size_t size() const { return fs_starts.size(); }
47};
48std::ostream &operator<<(std::ostream &, const SrcPackVec &);
49std::ostream &operator<<(std::ostream &, const SrcPackVec *);
50
54struct CoPackHint {
56 std::vector<SrcPackVec *> pack_sources;
58 bool required = false;
60 cstring reason = ""_cs;
61};
62std::ostream &operator<<(std::ostream &, const CoPackHint &);
63std::ostream &operator<<(std::ostream &, const CoPackHint *);
64
69std::ostream &operator<<(std::ostream &, const ActionSourceCoPackMap &);
70std::ostream &operator<<(std::ostream &, const ActionSourceCoPackMap *);
71
74 ActionSourceCoPackMap action_hints;
75 const AllocError *err = nullptr;
76 bool ok() const { return err == nullptr; }
77};
78
80class CoPacker {
81 const ActionSourceTracker &sources_i;
82 const SuperCluster *sc_i;
83 const ScAllocAlignment *alignment_i;
85
88 using DestSrcsKv = std::pair<AllocSlice, safe_vector<SourceOp>>;
89
91 struct CoPackHintOrErr {
92 const AllocError *err = nullptr;
93 const CoPackHint *hint = nullptr;
94 bool ok() const { return err == nullptr; }
95 explicit CoPackHintOrErr(const AllocError *err) : err(err) {}
96 explicit CoPackHintOrErr(const CoPackHint *c) : hint(c) {}
97 };
98
100 std::optional<int> get_decided_start_index(const FieldSlice &fs) const;
101
103 bool ok_to_pack(const FieldSliceAllocStartMap &existing, const FieldSlice &new_fs,
104 const int new_fs_start_index, const Container &c) const;
105
107 bool skip_source_packing(const FieldSlice &fs) const;
108
119 const CoPackHint *gen_bitwise_copack(const Allocation &allocated_tx,
120 const IR::MAU::Action *action, const DestSrcsMap &writes,
121 const Container &c) const;
122
126 CoPackHintOrErr gen_whole_container_set_copack(const Allocation &allocated_tx,
127 const IR::MAU::Action *action,
128 const DestSrcsMap &writes,
129 const Container &c) const;
130
133 // The algorithm is
140 CoPackHintOrErr gen_move_copack(const Allocation &allocated_tx, const IR::MAU::Action *action,
141 const DestSrcsMap &writes, const Container &c) const;
142
143 public:
144 CoPacker(const ActionSourceTracker &sources, const SuperCluster *sc,
145 const ScAllocAlignment *alignment);
146
151 CoPackResult gen_copack_hints(const Allocation &allocated_tx,
152 const std::vector<AllocSlice> &slices, const Container &c) const;
153};
154
155} // namespace v2
156} // namespace PHV
157
158#endif /* BF_P4C_PHV_V2_COPACKER_H_ */
Definition cstring.h:85
ActionSourceTracker collects all source-to-destination for all field slices.
Definition action_source_tracker.h:49
Definition phv/utils/utils.h:117
Definition phv.h:176
Definition phv_fields.h:898
Definition phv/utils/utils.h:1049
CoPacker is the method that compute and generates copack constraints.
Definition copacker.h:80
CoPackResult gen_copack_hints(const Allocation &allocated_tx, const std::vector< AllocSlice > &slices, const Container &c) const
Definition copacker.cpp:486
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Definition utils_v2.h:92
Definition copacker.h:54
cstring reason
reason of this copack constraint.
Definition copacker.h:60
bool required
true if this packing is the only option and required.
Definition copacker.h:58
std::vector< SrcPackVec * > pack_sources
1 or 2 source packing vector.
Definition copacker.h:56
Result type that either has some copack hints, or an error.
Definition copacker.h:73
Definition utils_v2.h:134
Definition copacker.h:31
FieldSliceAllocStartMap fs_starts
field slices and their starting indexes.
Definition copacker.h:36
std::optional< PHV::Container > container
pack to this container.
Definition copacker.h:33
size_t size() const
Definition copacker.h:46
bool empty() const
Definition copacker.h:43