P4C
The P4 Compiler
Loading...
Searching...
No Matches
action_phv_constraints.h
1
19#ifndef BF_P4C_PHV_ACTION_PHV_CONSTRAINTS_H_
20#define BF_P4C_PHV_ACTION_PHV_CONSTRAINTS_H_
21
22#include <optional>
23
24#include "backends/tofino/bf-p4c/common/map_tables_to_actions.h"
25#include "backends/tofino/bf-p4c/ir/bitrange.h"
26#include "backends/tofino/bf-p4c/lib/union_find.hpp"
27#include "backends/tofino/bf-p4c/mau/action_analysis.h"
28#include "backends/tofino/bf-p4c/mau/table_dependency_graph.h"
29#include "backends/tofino/bf-p4c/phv/analysis/pack_conflicts.h"
30#include "backends/tofino/bf-p4c/phv/phv_fields.h"
31#include "backends/tofino/bf-p4c/phv/phv_parde_mau_use.h"
32#include "backends/tofino/bf-p4c/phv/utils/utils.h"
33#include "ir/ir.h"
34#include "lib/safe_vector.h"
35
36using ::P4::operator<<;
37
39 int error;
40};
41
47 std::optional<ActionPhvConstraintLogging> logging;
48 std::optional<PHV::Allocation::ConditionalConstraint> conditional_constraints;
49};
50
51enum class CanPackErrorCode : unsigned {
52 NO_ERROR = 0,
53 SLICE_EMPTY = 1,
54 PACK_CONSTRAINT_PRESENT = 2,
55 STATEFUL_DEST_CONSTRAINT = 3,
56 BITMASK_CONSTRAINT = 4,
57 SPECIALTY_DATA = 5,
58 MIXED_OPERAND = 6,
59 NONE_ADJACENT_FIELD = 7,
60 COMPLEX_AD_PACKING = 8,
61 BITWISE_MIXED_AD = 9,
62 TF2_MORE_THAN_ONE_SOURCE = 10,
63 TF2_ALL_WRITTEN_TOGETHER = 11,
64 MORE_THAN_TWO_SOURCES = 12,
65 TWO_SOURCES_AND_CONSTANT = 13,
66 MOVE_AND_UNALLOCATED_SOURCE = 14,
67 BITWISE_AND_UNALLOCATED_SOURCE = 15,
68 SLICE_ALIGNMENT = 16,
69 PACK_AND_ALIGNED = 17,
70 INVALID_MASK = 18,
71 SLICE_DIFF_OFFSET = 19,
72 COPACK_UNSATISFIED = 20,
73 MULTIPLE_ALIGNMENTS = 21,
74 OVERLAPPING_SLICES = 22,
75 CONSTRAINT_CHECKER_FAILED = 23,
76};
77
78std::ostream &operator<<(std::ostream &out, const CanPackErrorCode &info);
79
80using CanPackReturnType =
81 std::tuple<CanPackErrorCode, std::optional<PHV::Allocation::ConditionalConstraints>>;
82
88 CanPackErrorCode code;
89 cstring msg;
90 bool remove_align_req = false;
91 const std::vector<PHV::AllocSlice> *invalid_dest_packing = nullptr;
92 CanPackErrorV2(CanPackErrorCode code) : code(code) {} // NOLINT
93 CanPackErrorV2(CanPackErrorCode code, bool clear_align)
94 : code(code), remove_align_req(clear_align) {}
95 CanPackErrorV2(CanPackErrorCode code, cstring msg) : code(code), msg(msg) {}
96 CanPackErrorV2(CanPackErrorCode code, cstring msg,
97 const std::vector<PHV::AllocSlice> *dest_cont)
98 : code(code), msg(msg), invalid_dest_packing(dest_cont) {}
99 bool ok() const { return code == CanPackErrorCode::NO_ERROR; }
100};
101
108 private:
109 const PhvInfo &phv;
110 const PhvUse &uses;
111 const PackConflicts &conflicts;
112 const MapTablesToActions &tableActionsMap;
113 const DependencyGraph &dg;
114
116
117 bool prelim_constraints_ok = true;
118
119 struct ClassifiedSource {
120 bool exist = false;
121 PHV::Container container;
123 bool aligned = true;
124 int offset = 0;
125 };
126 friend std::ostream &operator<<(std::ostream &out,
127 const ActionPhvConstraints::ClassifiedSource &src);
128
129 using ClassifiedSources = std::array<ClassifiedSource, 2>;
130
133 struct NumContainers {
134 size_t num_allocated;
135 size_t num_unallocated;
136 bool double_unallocated = false;
137
138 explicit NumContainers(const size_t numAlloc, const size_t numUnalloc)
139 : num_allocated(numAlloc), num_unallocated(numUnalloc) {}
140
141 NumContainers() : num_allocated(0), num_unallocated(0) {}
142 };
143
144 typedef enum action_data_uses_t {
145 SOME_AD_CONSTANT = 0,
146 ALL_AD_CONSTANT = 1,
147 COMPLEX_AD_PACKING_REQ = 2,
148 NO_AD_CONSTANT = 3
149 } ActionDataUses;
150
152 // TODO: Will we ever need a boolean indicating read or write in this
153 // struct?
154 struct OperandInfo {
155 int unique_action_id = -1;
156 enum field_read_flags_t {
157 MOVE = 1,
158 BITWISE = (1 << 1),
159 WHOLE_CONTAINER = (1 << 2),
160 ANOTHER_OPERAND = (1 << 3),
161 MIXED = (1 << 4),
162 WHOLE_CONTAINER_SAME_FIELD = (1 << 5),
163 PART_OF_CONTAINER = (1 << 6),
164 };
165 uint8_t flags = 0;
166
167 // An operand is either action data (ad), a constant (constant), or
168 // drawn from a PHV container (phv_used).
169 bool ad = false;
170 unsigned special_ad = ActionAnalysis::ActionParam::NO_SPECIAL;
171 bool constant = false;
172 int64_t const_value = 0;
173 std::optional<PHV::FieldSlice> phv_used = std::nullopt;
174 cstring action_name;
175 cstring operation;
176
177 bool operator<(OperandInfo other) const {
178 // TODO: What if ad == other.ad?
179 if (ad && !other.ad)
180 return true;
181 else if (!ad && other.ad)
182 return false;
183 else if (constant && !other.constant)
184 return true;
185 else if (!constant && other.constant)
186 return false;
187 else if (constant && other.constant)
188 return const_value < other.const_value;
189 else if (phv_used && !other.phv_used)
190 return true;
191 else if (!phv_used && other.phv_used)
192 return false;
193 else if (!phv_used && !other.phv_used)
194 return false;
195 else if (phv_used->field()->id != other.phv_used->field()->id)
196 return phv_used->field()->id < other.phv_used->field()->id;
197 else if (phv_used->range().lo != other.phv_used->range().lo)
198 return phv_used->range().lo < other.phv_used->range().lo;
199 else
200 return phv_used->range().hi < other.phv_used->range().hi;
201 }
202
203 bool operator==(OperandInfo other) const {
204 return phv_used == other.phv_used && ad == other.ad && constant == other.constant &&
205 const_value == other.const_value;
206 }
207
208 bool operator==(const PHV::Field *field) const {
209 return phv_used && phv_used->field()->id == field->id;
210 }
211
212 std::string toString() const {
213 std::stringstream ss;
214 ss << *this;
215 return ss.str();
216 }
217
218 explicit OperandInfo(PHV::FieldSlice slice, int id = -1)
219 : unique_action_id(id), phv_used(slice) {}
220
221 OperandInfo() {}
222 };
223
224 friend std::ostream &operator<<(std::ostream &out,
225 const ActionPhvConstraints::OperandInfo &info);
226
227 friend std::ostream &operator<<(std::ostream &out,
229
230 class ConstraintTracker {
231 const PhvInfo &phv;
233
236 ordered_map<const PHV::Field *,
238 field_writes_to_actions;
239
243
247
250
253 ordered_map<const PHV::Field *,
254 ordered_map<const IR::MAU::Action *,
256 write_to_reads_per_action;
257
258 ordered_map<const PHV::Field *,
259 ordered_map<const IR::MAU::Action *,
261 read_to_writes_per_action;
262
265 ordered_map<const PHV::Field *,
266 ordered_map<le_bitrange, ordered_map<const IR::MAU::Action *,
268 statefulWrites;
269
271 static int current_action;
272
273 public:
274 ConstraintTracker(const PhvInfo &phv, ActionPhvConstraints &self) : phv(phv), self(self) {}
275
277 void clear();
278
280 void add_action(const IR::MAU::Action *act,
281 const ActionAnalysis::FieldActionsMap field_actions_map,
282 const IR::MAU::Table *tbl);
283
287 std::optional<bool> hasPHVSource(const PHV::Field *field, const IR::MAU::Action *act) const;
288
292 std::optional<bool> hasActionDataOrConstantSource(const PHV::Field *field,
293 const IR::MAU::Action *act) const;
294
300 std::vector<OperandInfo> sources(const PHV::FieldSlice &dst,
301 const IR::MAU::Action *act) const;
302
305 std::vector<OperandInfo> sources(const PHV::AllocSlice &dst,
306 const IR::MAU::Action *act) const {
307 return sources(PHV::FieldSlice(dst.field(), dst.field_slice()), act);
308 }
309
316 const IR::MAU::Action *act) const;
317
321 const IR::MAU::Action *act) const {
322 return destinations(PHV::FieldSlice(src.field(), src.field_slice()), act);
323 }
324
327
331 return read_in(PHV::FieldSlice(src.field(), src.field_slice()));
332 }
333
336
340 return written_in(PHV::FieldSlice(dst.field(), dst.field_slice()));
341 }
342
344 const ordered_set<OperandInfo> &writes(const IR::MAU::Action *act) const;
345
347 const ordered_set<PHV::FieldSlice> &reads(const IR::MAU::Action *act) const;
348
353 std::optional<OperandInfo> is_written(PHV::FieldSlice slice,
354 const IR::MAU::Action *act) const;
355
360 std::optional<OperandInfo> is_written(PHV::AllocSlice slice,
361 const IR::MAU::Action *act) const {
362 return is_written(PHV::FieldSlice(slice.field(), slice.field_slice()), act);
363 }
364
385 ordered_set<int> source_alignment(PHV::AllocSlice dst, PHV::FieldSlice src) const;
386
387 std::optional<int> can_be_both_sources(const std::vector<PHV::AllocSlice> &slices,
388 ordered_set<PHV::FieldSlice> &packing_slices,
389 PHV::FieldSlice src) const;
390
392 void printMapStates() const;
393
397 void print_field_ordering(const std::vector<PHV::AllocSlice> &slices) const;
398
401 const ordered_map<const PHV::Field *,
402 ordered_map<le_bitrange, ordered_map<const IR::MAU::Action *,
404 getStatefulWrites() const {
405 return statefulWrites;
406 }
407
409 const IR::MAU::Table *action_table(const IR::MAU::Action *) const;
410 };
411
412 ConstraintTracker constraint_tracker;
413
415 struct ActionContainerProperty {
416 unsigned op_type;
417 NumContainers sources;
418 bool must_be_aligned; // a phv source must be aligned
419 int num_sources; // the number of allocated container sources.
420 int num_unallocated; // the number of unallocated slices.
421 bool use_ad; // true if action data is used.
422
425 bool aligned_one_unallocated = false;
426 bool aligned_two_unallocated = false;
427 bool aligned_unallocated_requires_aligment = false;
428 };
429
430 using ActionPropertyMap =
432
434 profile_t init_apply(const IR::Node *root) override;
435
440 bool preorder(const IR::MAU::Action *act) override;
441
443 void end_apply() override;
444
445 void determine_same_byte_fields();
446
447 const ordered_set<PHV::FieldSlice> get_slices_in_same_byte(const PHV::FieldSlice &slice) const;
448
453 bool early_check_ok(const IR::MAU::Action *action);
454
458 UnionFind<PHV::FieldSlice> classify_PHV_sources(
459 const ordered_set<PHV::FieldSlice> &phvSlices,
461
467 bool diagnoseInvalidPacking(
468 const IR::MAU::Action *action, const PHV::SuperCluster::SliceList *list,
469 const ordered_map<PHV::FieldSlice, unsigned> &fieldAlignments,
471 std::stringstream &ss) const;
472
481 void throw_too_many_sources_error(
482 const ordered_set<PHV::FieldSlice> &actionDataWrittenSlices,
483 const ordered_set<PHV::FieldSlice> &notWrittenSlices,
484 const UnionFind<PHV::FieldSlice> &phvSources,
485 const ordered_map<PHV::FieldSlice, std::pair<int, int>> &phvAlignedSlices,
486 const IR::MAU::Action *action, std::stringstream &ss) const;
487
492 void throw_non_contiguous_mask_error(
493 const ordered_set<PHV::FieldSlice> &notWrittenSlices,
495 const ordered_map<PHV::FieldSlice, unsigned> &fieldAlignments, cstring action_name,
496 std::stringstream &ss) const;
497
500
505 NumContainers num_container_sources(const PHV::Allocation &alloc,
506 const PHV::Allocation::MutuallyLiveSlices &container_state,
507 const IR::MAU::Action *action) const;
508
514 std::optional<PHV::AllocSlice> getSourcePHVSlice(const PHV::Allocation &alloc,
515 const std::vector<PHV::AllocSlice> &slices,
516 const PHV::AllocSlice &dst,
517 const IR::MAU::Action *action,
518 const int stage) const;
519
523 bool has_ad_or_constant_sources(
524 const PHV::Allocation::MutuallyLiveSlices &slices, const IR::MAU::Action *action,
525 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
526
531 ActionDataUses all_or_none_constant_sources(
532 const PHV::Allocation::MutuallyLiveSlices &slices, const IR::MAU::Action *act,
533 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
534
537 bool fields_share_container(const PHV::Field *, const PHV::Field *);
538
542 int unallocated_bits(PHV::Allocation::MutuallyLiveSlices, const PHV::Container) const;
543
546 bool are_adjacent_field_slices(const PHV::Allocation::MutuallyLiveSlices &state) const;
547
551 unsigned count_container_holes(const PHV::Allocation::MutuallyLiveSlices &state) const;
552
557 bool valid_container_operation_type(const IR::MAU::Action *act,
558 const ordered_set<PHV::FieldSlice> &slices,
559 std::stringstream &ss) const;
560
568 unsigned container_operation_type(const IR::MAU::Action *,
571
582 bool pack_slices_together(const PHV::Allocation &alloc,
583 const PHV::Allocation::MutuallyLiveSlices &container_state,
584 PackingConstraints *packing_constraints,
585 const IR::MAU::Action *action, bool pack_unallocated_only,
586 bool has_ad_source = false) const;
587
591 std::optional<ClassifiedSources> verify_two_container_alignment(
592 const PHV::Allocation &alloc, const PHV::Allocation::MutuallyLiveSlices &container_state,
593 const IR::MAU::Action *action, const PHV::Container destination,
594 ActionContainerProperty *action_prop) const;
595
600 inline int getOffset(le_bitrange a, le_bitrange b, PHV::Container c) const;
601
604 bool masks_valid(const ClassifiedSources &sources) const;
605
609 bool is_aligned(const PHV::Allocation::MutuallyLiveSlices &container_state,
610 const IR::MAU::Action *act, const PHV::Allocation &alloc) const;
611
617 bool masks_valid(const PHV::Allocation::MutuallyLiveSlices &container_state,
618 const IR::MAU::Action *action, bool actionDataOnly,
619 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
620
624 bool masks_valid(const PHV::Allocation::MutuallyLiveSlices &container_state,
625 const IR::MAU::Action *action) const;
626
632 bool assign_containers_to_unallocated_sources(
633 const PHV::Allocation &alloc, const UnionFind<PHV::FieldSlice> &copacking_constraints,
635
636 // (xxx)Deep [Specific Case Alert]: This will probably be subsumed by another function that
637 // handles the general case of producing conditional constraints for n unallocated sources
638 // packed into 2 containers.
649 std::optional<PHV::FieldSlice> get_smaller_source_slice(
650 const PHV::Allocation &alloc, const UnionFind<PHV::FieldSlice> &copacking_constraints,
651 const ordered_set<PHV::FieldSlice> &container_state) const;
652
653 std::optional<PHV::FieldSlice> get_unallocated_slice(
654 const PHV::Allocation &alloc, const UnionFind<PHV::FieldSlice> &copacking_constraints,
655 const ordered_set<PHV::FieldSlice> &container_state) const;
656
658 ordered_set<const PHV::Field *> meter_color_destinations;
659
663 ordered_set<const PHV::Field *> meter_color_destinations_8bit;
664
669
673 bool check_speciality_packing(const PHV::Allocation::MutuallyLiveSlices &container_state) const;
674
683 bool check_and_generate_constraints_for_move_with_unallocated_sources(
684 const PHV::Allocation &alloc, const IR::MAU::Action *action, const PHV::Container &c,
685 const PHV::Allocation::MutuallyLiveSlices &container_state,
687 ActionContainerProperty *action_props, PackingConstraints *copacking_constraints) const;
688
691 bool generate_conditional_constraints_for_bitwise_op(
692 const PHV::Allocation::MutuallyLiveSlices &container_state, const IR::MAU::Action *action,
693 const ordered_set<PHV::FieldSlice> &sources,
694 PackingConstraints *copacking_constraints) const;
695
704 bool check_and_generate_constraints_for_bitwise_op_with_unallocated_sources(
705 const IR::MAU::Action *action, const PHV::Allocation::MutuallyLiveSlices &container_state,
706 const NumContainers &sources, PackingConstraints *copacking_constraints) const;
707
729 CanPackErrorCode check_and_generate_constraints_for_bitwise_or_move(
730 const PHV::Allocation &alloc, const PHV::ActionSet &actions,
731 const PHV::Allocation::MutuallyLiveSlices &container_state, const PHV::Container &c,
732 const PHV::Allocation::LiveRangeShrinkingMap &initActions, ActionPropertyMap *action_props,
733 PackingConstraints *copack_constraints) const;
734
736 CanPackErrorCode check_and_generate_rotational_alignment_constraints(
737 const PHV::Allocation &alloc, const std::vector<PHV::AllocSlice> &slices,
738 const PHV::ActionSet &actions, const PHV::Allocation::MutuallyLiveSlices &container_state,
739 const PHV::Container &c, ActionPropertyMap *action_props) const;
740
742 CanPackErrorCode check_and_generate_copack_set(
743 const PHV::Allocation &alloc, const PHV::Allocation::MutuallyLiveSlices &container_state,
744 const PackingConstraints &copack_constraints, const ActionPropertyMap &action_props,
745 ordered_map<int, ordered_set<PHV::FieldSlice>> *copacking_set,
747
749 CanPackReturnType check_and_generate_conditional_constraints(
750 const PHV::Allocation &alloc, const std::vector<PHV::AllocSlice> &slices,
751 const PHV::Allocation::MutuallyLiveSlices &container_state,
752 const ordered_map<int, ordered_set<PHV::FieldSlice>> &copacking_set,
753 const ordered_map<PHV::FieldSlice, PHV::Container> &req_container) const;
754
756 bool stateful_destinations_constraints_violated(
757 const PHV::Allocation::MutuallyLiveSlices &container_state) const;
758
761 bool check_speciality_read_and_bitmask(
762 const PHV::Allocation::MutuallyLiveSlices &container_state,
763 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
764
767 PHV::ActionSet make_writing_action_set(
768 const PHV::Allocation &alloc, const PHV::Allocation::MutuallyLiveSlices &container_state,
769 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
770
772 ActionPropertyMap make_action_container_properties(
773 const PHV::Allocation &alloc, const PHV::ActionSet &actions,
774 const PHV::Allocation::MutuallyLiveSlices &container_state,
775 const PHV::Allocation::LiveRangeShrinkingMap &initActions, bool is_mocha_or_dark) const;
776
778 PackingConstraints make_initial_copack_constraints(
779 const PHV::ActionSet &actions,
780 const PHV::Allocation::MutuallyLiveSlices &container_state) const;
781
785 std::set<int> stages(const IR::MAU::Action *action, bool physical_stage) const;
786
787 public:
788 // Summary of sources for an action
790 bool has_ad = false;
791 bool has_const = false;
792
793 // Allocated sources
795
796 // Number of unallocated sources
797 int unalloc = 0;
798
799 // Destinations
800 bitvec dest_bits;
801 };
802
803 explicit ActionPhvConstraints(const PhvInfo &p, const PhvUse &u, const PackConflicts &c,
804 const MapTablesToActions &m, const DependencyGraph &d)
805 : phv(p),
806 uses(u),
807 conflicts(c),
808 tableActionsMap(m),
809 dg(d),
810 constraint_tracker(ConstraintTracker(p, *this)) {}
811
814 return meter_color_destinations.count(f) > 0;
815 }
816
821 return meter_color_destinations_8bit.count(f) > 0;
822 }
823
825 bool hasPackConflict(const PHV::FieldSlice fs1, const PHV::FieldSlice fs2) const {
826 return conflicts.hasPackConflict(fs1, fs2);
827 }
828
831 bool hasSpecialityReads(const PHV::Field *f) const { return special_no_pack.count(f) > 0; }
832
834 ordered_set<const PHV::Field *> &meter_color_dests() { return meter_color_destinations; }
835
838 return meter_color_destinations;
839 }
840
843 return meter_color_destinations_8bit;
844 }
845
848 return meter_color_destinations_8bit;
849 }
850
853 return constraint_tracker.written_in(PHV::FieldSlice(f, StartLen(0, f->size)));
854 }
855
857 const PHV::AllocSlice &slice) const {
858 PHV::FieldSlice fieldSlice(slice.field(), slice.field_slice());
859 return constraint_tracker.written_in(fieldSlice);
860 }
861
864 return constraint_tracker.read_in(PHV::FieldSlice(f, StartLen(0, f->size)));
865 }
866
874 const PHV::Field *dest, const std::vector<PHV::FieldSlice> &slices) const;
875
882 const PHV::Field *src, const std::vector<PHV::FieldSlice> &slices) const;
883
886 std::optional<const PHV::Field *> field_destination(const PHV::Field *f,
887 const IR::MAU::Action *action) const;
888
890 bool move_only_operations(const PHV::Field *f) const;
891
897 const PHV::Allocation::MutuallyLiveSlices &container_state,
898 const PHV::ActionSet &set_of_actions,
899 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
900
903 const std::vector<PHV::AllocSlice> &slices) const;
904
912 const PHV::Container &c, const PHV::Allocation::MutuallyLiveSlices &container_state) const;
913
931 CanPackReturnType can_pack(const PHV::Allocation &alloc,
932 const std::vector<PHV::AllocSlice> &slices,
933 const PHV::Allocation::MutuallyLiveSlices &original_container_state,
934 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
935
939 const PHV::ActionSet &actions, const PHV::Allocation::MutuallyLiveSlices &container_state,
940 const ActionPropertyMap *action_props) const;
941
944 const std::vector<PHV::AllocSlice> &slices) const;
945
951 const MapTablesToActions &tableActionsMap) const;
952
956 const std::vector<PHV::AllocSlice> &slices,
957 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
958
962 bool is_bitmasked_set(const std::vector<PHV::AllocSlice> &container_state,
963 const ordered_set<PHV::AllocSlice> &fields_not_written_to) const;
964
972 void sort(std::list<const PHV::SuperCluster::SliceList *> &slice_list) const;
973
977 void sort(std::vector<PHV::FieldSlice> &slice_list) const;
978
986 void dest_first_sort(std::vector<const PHV::SuperCluster::SliceList *> &slice_list) const;
987
990 ordered_set<const PHV::Field *> actionReads(const IR::MAU::Action *act) const;
991
992 const ordered_set<PHV::FieldSlice> &actionReadsSlices(const IR::MAU::Action *act) const {
993 return constraint_tracker.reads(act);
994 }
995
998 ordered_set<const PHV::Field *> actionWrites(const IR::MAU::Action *act) const;
999
1000 const ordered_set<PHV::FieldSlice> actionWritesSlices(const IR::MAU::Action *act) const {
1002 auto &writtenSlices = constraint_tracker.writes(act);
1003 for (auto &info : writtenSlices)
1004 if (info.phv_used != std::nullopt) rs.insert(*(info.phv_used));
1005 return rs;
1006 }
1007
1012
1016 bool cannot_initialize(const PHV::Container &c, const IR::MAU::Action *action,
1017 const PHV::Allocation &alloc) const;
1018
1022 bool can_pack_pov(const PHV::SuperCluster::SliceList *slice_list, const PHV::Field *f) const;
1023
1030 const ordered_map<PHV::FieldSlice, unsigned> &fieldAlignments,
1031 std::stringstream &error_msg) const;
1032
1035 bool written_in(const PHV::Field *f, const IR::MAU::Action *act) const;
1036
1039 bool written_in(const PHV::AllocSlice &slice, const IR::MAU::Action *act) const {
1040 PHV::FieldSlice field_slice(slice.field(), slice.field_slice());
1041 return constraint_tracker.written_in(field_slice).count(act);
1042 }
1043
1046 bool written_by_ad_constant(const PHV::Field *f, const IR::MAU::Action *act) const;
1047
1051 bool is_in_field_writes_to_actions(cstring, const IR::MAU::Action *) const;
1055 bool is_in_action_to_writes(const IR::MAU::Action *, cstring) const;
1059 bool is_in_write_to_reads(cstring, const IR::MAU::Action *, cstring) const;
1060
1087 const ordered_map<const PHV::Field *, std::vector<PHV::FieldSlice>> &fields) const;
1088
1101 ActionSources getActionSources(const IR::MAU::Action *act, const PHV::Container &c,
1102 ordered_set<PHV::AllocSlice> &new_slices,
1103 const PHV::Allocation &alloc) const;
1104
1112 const PHV::Allocation &alloc, const IR::MAU::Action *action,
1113 const std::vector<PHV::AllocSlice> &slices,
1114 const PHV::Allocation::MutuallyLiveSlices &container_state, const PHV::Container &c,
1115 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
1116
1128 CanPackErrorCode check_ara_move_constraints(
1129 const PHV::Allocation &alloc, const PHV::Allocation::MutuallyLiveSlices &container_state,
1130 const PHV::Container &c, const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
1131
1136 const PHV::Allocation &alloc, const std::vector<PHV::AllocSlice> &candidates,
1137 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
1138
1142 const PHV::Allocation &alloc, const std::vector<PHV::AllocSlice> &candidates,
1143 const IR::MAU::Action *action,
1144 const PHV::Allocation::LiveRangeShrinkingMap &initActions) const;
1145
1149 const PHV::Allocation &alloc, const std::vector<PHV::AllocSlice> &candidates,
1150 const IR::MAU::Action *action) const;
1151};
1152
1153std::ostream &operator<<(std::ostream &out, const ActionPhvConstraints::OperandInfo &info);
1154std::ostream &operator<<(std::ostream &out,
1156std::ostream &operator<<(std::ostream &out, const ActionPhvConstraints::ClassifiedSource &src);
1157
1158#endif /* BF_P4C_PHV_ACTION_PHV_CONSTRAINTS_H_ */
Definition action_phv_constraints.h:107
CanPackErrorV2 can_pack_v2(const PHV::Allocation &alloc, const std::vector< PHV::AllocSlice > &slices) const
can_pack_v2 checks whether allocating slices will violate any action constraints.
Definition action_phv_constraints.cpp:2765
ordered_set< const PHV::Field * > actionWrites(const IR::MAU::Action *act) const
Definition action_phv_constraints.cpp:3495
bool diagnoseSuperCluster(const ordered_set< const PHV::SuperCluster::SliceList * > &sc, const ordered_map< PHV::FieldSlice, unsigned > &fieldAlignments, std::stringstream &error_msg) const
Definition action_phv_constraints.cpp:3877
int count_bitmasked_set_instructions(const std::vector< PHV::AllocSlice > &slices, const PHV::Allocation::LiveRangeShrinkingMap &initActions) const
Definition action_phv_constraints.cpp:1509
bool is_meter_color_destination(const PHV::Field *f) const
Track all the meter color destination to prioritize 8-bit PHV for such field.
Definition action_phv_constraints.h:813
ordered_set< const PHV::Field * > actionReads(const IR::MAU::Action *act) const
Definition action_phv_constraints.cpp:3488
CanPackErrorV2 check_move_constraints(const PHV::Allocation &alloc, const IR::MAU::Action *action, const std::vector< PHV::AllocSlice > &slices, const PHV::Allocation::MutuallyLiveSlices &container_state, const PHV::Container &c, const PHV::Allocation::LiveRangeShrinkingMap &initActions) const
Definition action_phv_constraints.cpp:4317
void dest_first_sort(std::vector< const PHV::SuperCluster::SliceList * > &slice_list) const
Definition action_phv_constraints.cpp:647
bool creates_container_conflicts(const PHV::Allocation::MutuallyLiveSlices &container_state, const PHV::Allocation::LiveRangeShrinkingMap &initActions, const MapTablesToActions &tableActionsMap) const
Definition action_phv_constraints.cpp:2861
bool is_in_action_to_writes(const IR::MAU::Action *, cstring) const
Definition action_phv_constraints.cpp:3987
bool written_by_ad_constant(const PHV::Field *f, const IR::MAU::Action *act) const
Definition action_phv_constraints.cpp:3416
ordered_set< const PHV::Field * > & meter_color_dests()
Definition action_phv_constraints.h:834
bool all_field_slices_written_together(const PHV::Allocation::MutuallyLiveSlices &container_state, const PHV::ActionSet &set_of_actions, const PHV::Allocation::LiveRangeShrinkingMap &initActions) const
Definition action_phv_constraints.cpp:3295
bool is_in_field_writes_to_actions(cstring, const IR::MAU::Action *) const
Definition action_phv_constraints.cpp:3978
ordered_set< const PHV::Field * > slices_destinations(const PHV::Field *src, const std::vector< PHV::FieldSlice > &slices) const
Definition action_phv_constraints.cpp:3521
bool move_only_operations(const PHV::Field *f) const
Definition action_phv_constraints.cpp:3546
bool hasPackConflict(const PHV::FieldSlice fs1, const PHV::FieldSlice fs2) const
Definition action_phv_constraints.h:825
CanPackErrorV2 check_move_constraints_from_read(const PHV::Allocation &alloc, const std::vector< PHV::AllocSlice > &candidates, const PHV::Allocation::LiveRangeShrinkingMap &initActions) const
Definition action_phv_constraints.cpp:4209
ordered_set< const PHV::Field * > slices_sources(const PHV::Field *dest, const std::vector< PHV::FieldSlice > &slices) const
Definition action_phv_constraints.cpp:3504
void sort(std::list< const PHV::SuperCluster::SliceList * > &slice_list) const
Definition action_phv_constraints.cpp:538
ordered_set< const IR::MAU::Action * > actions_reading_fields(const PHV::Field *f) const
Definition action_phv_constraints.h:863
CanPackErrorV2 check_read_action_move_constraints(const PHV::Allocation &alloc, const std::vector< PHV::AllocSlice > &candidates, const IR::MAU::Action *action, const PHV::Allocation::LiveRangeShrinkingMap &initActions) const
Definition action_phv_constraints.cpp:4082
bool parser_constant_extract_satisfied(const PHV::Container &c, const PHV::Allocation::MutuallyLiveSlices &container_state) const
Definition action_phv_constraints.cpp:1697
bool pack_conflicts_present(const PHV::Allocation::MutuallyLiveSlices &container_state, const std::vector< PHV::AllocSlice > &slices) const
Definition action_phv_constraints.cpp:1563
bool is_in_write_to_reads(cstring, const IR::MAU::Action *, cstring) const
Definition action_phv_constraints.cpp:3997
bool is_bitmasked_set(const std::vector< PHV::AllocSlice > &container_state, const ordered_set< PHV::AllocSlice > &fields_not_written_to) const
Definition action_phv_constraints.cpp:1546
CanPackErrorV2 check_read_action_num_source_constraints(const PHV::Allocation &alloc, const std::vector< PHV::AllocSlice > &candidates, const IR::MAU::Action *action) const
Definition action_phv_constraints.cpp:4132
ordered_set< const IR::MAU::Action * > actions_writing_fields(const PHV::Field *f) const
Definition action_phv_constraints.h:852
bool written_in(const PHV::AllocSlice &slice, const IR::MAU::Action *act) const
Definition action_phv_constraints.h:1039
CanPackErrorV2 check_bitwise_and_basic_move_constraints(const PHV::ActionSet &actions, const PHV::Allocation::MutuallyLiveSlices &container_state, const ActionPropertyMap *action_props) const
Definition action_phv_constraints.cpp:2115
bool can_pack_pov(const PHV::SuperCluster::SliceList *slice_list, const PHV::Field *f) const
Definition action_phv_constraints.cpp:3557
ordered_set< const PHV::Field * > & meter_color_dests_8bit()
Definition action_phv_constraints.h:842
const ordered_set< const PHV::Field * > & meter_color_dests() const
Definition action_phv_constraints.h:837
ActionSources getActionSources(const IR::MAU::Action *act, const PHV::Container &c, ordered_set< PHV::AllocSlice > &new_slices, const PHV::Allocation &alloc) const
Definition action_phv_constraints.cpp:4036
bool hasSpecialityReads(const PHV::Field *f) const
Definition action_phv_constraints.h:831
bool written_in(const PHV::Field *f, const IR::MAU::Action *act) const
Definition action_phv_constraints.cpp:3408
CanPackErrorCode check_ara_move_constraints(const PHV::Allocation &alloc, const PHV::Allocation::MutuallyLiveSlices &container_state, const PHV::Container &c, const PHV::Allocation::LiveRangeShrinkingMap &initActions) const
Definition action_phv_constraints.cpp:4242
bool is_meter_color_destination_8bit(const PHV::Field *f) const
Definition action_phv_constraints.h:820
ordered_map< const PHV::Field *, int > compute_sources_first_order(const ordered_map< const PHV::Field *, std::vector< PHV::FieldSlice > > &fields) const
Definition action_phv_constraints.cpp:4009
std::optional< const PHV::Field * > field_destination(const PHV::Field *f, const IR::MAU::Action *action) const
Definition action_phv_constraints.cpp:3533
bool checkBridgedPackingConstraints(const ordered_set< const PHV::Field * > &packing) const
Definition action_phv_constraints.cpp:3328
CanPackReturnType can_pack(const PHV::Allocation &alloc, const std::vector< PHV::AllocSlice > &slices, const PHV::Allocation::MutuallyLiveSlices &original_container_state, const PHV::Allocation::LiveRangeShrinkingMap &initActions) const
Definition action_phv_constraints.cpp:2605
bool cannot_initialize(const PHV::Container &c, const IR::MAU::Action *action, const PHV::Allocation &alloc) const
Definition action_phv_constraints.cpp:3450
const ordered_set< const PHV::Field * > & meter_color_dests_8bit() const
Definition action_phv_constraints.h:847
Definition action_phv_constraints.h:789
Definition map_tables_to_actions.h:29
Definition node.h:94
Definition visitor.h:400
Definition visitor.h:78
Definition bitvec.h:120
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition safe_vector.h:27
Definition slice_alloc.h:136
Definition phv/utils/utils.h:117
Definition phv.h:176
Definition phv_fields.h:154
int size
Total size of Field in bits.
Definition phv_fields.h:194
int id
Unique field ID.
Definition phv_fields.h:164
Definition phv_fields.h:898
const PHV::Field * field() const override
Definition phv_fields.h:977
Definition pack_conflicts.h:36
Definition phv_fields.h:1095
Definition phv_parde_mau_use.h:154
void info(const int kind, const char *format, const T *node, Args &&...args)
Report info messages of type kind. Requires that the node argument have source info.
Definition lib/error.h:148
Definition action_phv_constraints.h:46
Definition action_phv_constraints.h:38
Definition action_phv_constraints.h:87
Definition table_dependency_graph.h:52
Definition lib/bitrange.h:158
Definition common/field_defuse.cpp:590