79 std::list<PHV::AlignedCluster *> aligned_clusters_i;
83 std::list<PHV::RotationalCluster *> rotational_clusters_i;
87 std::list<PHV::SuperCluster *> super_clusters_i;
92 inconsistent_extract_no_packs_i;
101 UnionFind<const PHV::Field *> complex_validity_bits_i;
113 class ClearClusteringStructs :
public Inspector {
118 explicit ClearClusteringStructs(
Clustering &self) : self(self) {}
127 class FindComplexValidityBits :
public Inspector {
131 bool preorder(
const IR::MAU::Instruction *)
override;
132 void end_apply()
override;
135 explicit FindComplexValidityBits(
Clustering &self) : self(self), phv_i(self.phv_i) {}
165 std::vector<ordered_set<PHV::FieldSlice>> equivalences_i;
171 bool preorder(
const IR::MAU::Table *tbl)
override;
175 bool preorder(
const IR::Expression *)
override;
179 void postorder(
const IR::MAU::Instruction *)
override;
185 void end_apply()
override;
189 : self(self), phv_i(self.phv_i), pa_sizes_i(pa) {}
199 class MakeAlignedClusters :
public Inspector {
205 UnionFind<PHV::FieldSlice> union_find_i;
211 bool preorder(
const IR::MAU::Instruction *inst)
override;
217 bool preorder(
const IR::MAU::Table *tbl)
override;
220 void end_apply()
override;
223 explicit MakeAlignedClusters(
Clustering &self)
224 : self(self), phv_i(self.phv_i), uses_i(self.uses_i) {}
227 class MakeRotationalClusters :
public Inspector {
233 UnionFind<PHV::AlignedCluster *> union_find_i;
245 bool preorder(
const IR::MAU::Instruction *)
override;
249 void end_apply()
override;
252 explicit MakeRotationalClusters(
Clustering &self) : self(self), phv_i(self.phv_i) {}
293 class CollectInconsistentFlexibleFieldExtract :
public Inspector {
296 std::map<int, std::vector<const PHV::Field *>> headers_i;
297 using ExtractVec = std::set<std::pair<nw_bitrange, const PHV::Field *>>;
298 std::vector<ExtractVec> extracts_i;
301 auto rv = Inspector::init_apply(root);
307 void save_header_layout(
const IR::HeaderRef *hr);
308 bool preorder(
const IR::ConcreteHeaderRef *)
override;
309 bool preorder(
const IR::HeaderStackItemRef *)
override;
310 bool preorder(
const IR::BFN::ParserState *state)
override;
311 void end_apply()
override;
314 explicit CollectInconsistentFlexibleFieldExtract(
Clustering &self,
const PhvInfo &phv)
315 : self(self), phv_i(phv) {}
323 class CollectPlaceTogetherConstraints :
public Inspector {
328 const CollectInconsistentFlexibleFieldExtract &inconsistent_extract_i;
333 enum class Reason :
int {
347 std::map<Reason, std::vector<PHV::SuperCluster::SliceList *>> place_together_i;
363 auto rv = Inspector::init_apply(root);
364 place_together_i.clear();
365 slice_lists_i.clear();
367 bridged_extracted_together_i.clear();
372 void end_apply()
override;
383 void solve_place_together_constraints();
387 void pack_pa_byte_pack_and_update_alignment();
390 void pack_pa_container_sized_metadata();
396 void pack_constrained_metadata();
400 void pack_bridged_extracted_together();
403 void pack_pov_bits();
406 void visit_header_ref(
const IR::HeaderRef *hr);
409 void visit_digest_fieldlist(
const IR::BFN::DigestFieldList *fl,
int skip, Reason reason);
412 bool preorder(
const IR::ConcreteHeaderRef *)
override;
415 bool preorder(
const IR::HeaderStackItemRef *)
override;
418 bool preorder(
const IR::BFN::Digest *)
override;
422 bool preorder(
const IR::BFN::ParserState *state)
override;
425 explicit CollectPlaceTogetherConstraints(
427 const CollectInconsistentFlexibleFieldExtract &inconsistent)
430 conflicts_i(self.conflicts_i),
432 inconsistent_extract_i(inconsistent) {}
435 return slice_lists_i;
439 class MakeSuperClusters :
public Inspector {
442 const CollectPlaceTogetherConstraints &place_togethers_i;
449 void end_apply()
override;
460 const CollectPlaceTogetherConstraints &place_togethers)
461 : self(self), phv_i(self.phv_i), place_togethers_i(place_togethers) {}
464 class ValidateClusters :
public Inspector {
472 static void validate_basics(
const std::list<PHV::SuperCluster *> &clusters);
478 static void validate_deparsed_zero_clusters(
const std::list<PHV::SuperCluster *> &clusters);
481 static std::optional<cstring> validate_exact_container_lists(
482 const std::list<PHV::SuperCluster *> &clusters,
const PhvUse &uses);
485 static void validate_alignments(
const std::list<PHV::SuperCluster *> &clusters,
489 static void validate_extract_from_flexible(
490 const std::list<PHV::SuperCluster *> &clusters,
495 static void validate_same_container_group_fields(
496 const std::list<PHV::SuperCluster *> &clusters,
501 : self(c), mau_bt(mau_bt) {}
504 class UpdateSameContainerAllocConstraint :
public Inspector {
511 explicit UpdateSameContainerAllocConstraint(
Clustering &c) : self(c) {}
523 pa_container_sizes_i(pa_sz),
524 pa_byte_pack_i(pa_byte_pack),
527 table_mutex_i(table_mutex),
528 settings_i(settings),
529 slice_i(*
this, pa_sz) {
530 auto *inconsistent_extracts =
531 new CollectInconsistentFlexibleFieldExtract(*
this, this->phv_i);
532 auto *place_togethers =
533 new CollectPlaceTogetherConstraints(*
this, a, *inconsistent_extracts);
535 new ClearClusteringStructs(*
this),
536 new FindComplexValidityBits(*
this),
538 new MakeAlignedClusters(*
this),
539 new MakeRotationalClusters(*
this),
540 inconsistent_extracts, place_togethers,
541 new MakeSuperClusters(*
this, *place_togethers),
542 new ValidateClusters(*
this, mau_bt),
543 new UpdateSameContainerAllocConstraint(*
this)
548 const std::list<PHV::SuperCluster *> &
cluster_groups()
const {
return super_clusters_i; }
553 return inconsistent_extract_no_packs_i.count(a) &&
554 inconsistent_extract_no_packs_i.at(a).count(b);