P4C
The P4 Compiler
Loading...
Searching...
No Matches
CoreAllocation Class Reference

#include <allocate_phv.h>

Public Member Functions

 CoreAllocation (const PHV::AllocUtils &utils, bool disable_metainit)
 
bool can_physical_liverange_overlay (const PHV::AllocSlice &slice, const ordered_set< PHV::AllocSlice > &allocated) const
 
bool checkDarkOverlay (const std::vector< PHV::AllocSlice > &candidate_slices, const PHV::Transaction &alloc) const
 
bool checkParserExtractions (const std::vector< PHV::AllocSlice > &candidate_slices, const PHV::Transaction &alloc) const
 
std::optional< const PHV::SuperCluster::SliceList * > find_first_unallocated_slicelist (const PHV::Allocation &alloc, const std::list< PHV::ContainerGroup * > &container_groups, const PHV::SuperCluster &cluster) const
 
bool generateNewAllocSlices (const PHV::AllocSlice &origSlice, const ordered_set< PHV::AllocSlice > &alloced_slices, PHV::DarkInitMap &slices, ordered_set< PHV::AllocSlice > &new_candidate_slices, PHV::Transaction &alloc_attempt, const PHV::Allocation::MutuallyLiveSlices &container_state) const
 
bool get_prioririze_ARA_inits ()
 
bool get_single_gress_parser_group ()
 
bool hasARAinits (ordered_set< PHV::AllocSlice > slices) const
 @look for ARA inits in set of slices
 
bool hasCrossingLiveranges (std::vector< PHV::AllocSlice > candidate_slices, ordered_set< PHV::AllocSlice > alloc_slices) const
 
PHV::Transaction make_speculated_alloc (const PHV::Transaction &alloc, const PHV::SuperCluster &sc, const std::vector< PHV::AllocSlice > &candidates, const PHV::Container &c) const
 
bool rangesOverlap (const PHV::AllocSlice &slice, const IR::BFN::ParserPrimitive *prim) const
 Do the slice and prim have overlapping field ranges.
 
bool satisfies_constraints (const PHV::Allocation &alloc, const PHV::AllocSlice &slice, ordered_set< PHV::AllocSlice > &initFields, std::vector< PHV::AllocSlice > &candidate_slices) const
 
bool satisfies_constraints (const PHV::ContainerGroup &group, const PHV::Field *f) const
 
bool satisfies_constraints (const PHV::ContainerGroup &group, const PHV::FieldSlice &slice) const
 
bool satisfies_constraints (std::vector< PHV::AllocSlice > slices, const PHV::Allocation &alloc) const
 
void set_prioritize_ARA_inits ()
 
void set_single_gress_parser_group ()
 
std::optional< PHV::Transactiontry_alloc (const PHV::Allocation &alloc, const PHV::ContainerGroup &group, PHV::SuperCluster &cluster, int max_alignment_tries, const ScoreContext &score_ctx) const
 
std::optional< PHV::Transactiontry_deparser_zero_alloc (const PHV::Allocation &alloc, PHV::SuperCluster &cluster, PhvInfo &phv) const
 
std::optional< PHV::TransactiontryAllocSliceList (const PHV::Allocation &alloc, const PHV::ContainerGroup &group, const PHV::SuperCluster &super_cluster, const PHV::Allocation::ConditionalConstraint &start_positions, const ScoreContext &score_ctx) const
 
std::optional< PHV::TransactiontryAllocSliceList (const PHV::Allocation &alloc, const PHV::ContainerGroup &group, const PHV::SuperCluster &super_cluster, const PHV::SuperCluster::SliceList &slice_list, const ordered_map< PHV::FieldSlice, int > &start_positions, const ScoreContext &score_ctx) const
 

Static Public Member Functions

static bool can_overlay (const SymBitMatrix &mutually_exclusive_field_ids, const PHV::Field *f, const ordered_set< PHV::AllocSlice > &slices)
 
static bool satisfies_constraints (const PHV::ContainerGroup &container_group, const PHV::SuperCluster &cluster_group)
 
static bool some_overlay (const SymBitMatrix &mutually_exclusive_field_ids, const PHV::Field *f, const ordered_set< PHV::AllocSlice > &slices)
 

Detailed Description

A set of functions used in PHV allocation.

Member Function Documentation

◆ can_overlay()

bool CoreAllocation::can_overlay ( const SymBitMatrix & mutually_exclusive_field_ids,
const PHV::Field * f,
const ordered_set< PHV::AllocSlice > & slices )
static
Returns
true if f can overlay all fields in slices.

◆ can_physical_liverange_overlay()

bool CoreAllocation::can_physical_liverange_overlay ( const PHV::AllocSlice & slice,
const ordered_set< PHV::AllocSlice > & allocated ) const
Returns
true if slice can overlay all fields in allocated in terms of physical liveranges.

◆ checkParserExtractions()

bool CoreAllocation::checkParserExtractions ( const std::vector< PHV::AllocSlice > & candidate_slices,
const PHV::Transaction & alloc ) const

Verify whether the candidate_slices will produce parser extractions that will lead to data corruption

◆ make_speculated_alloc()

PHV::Transaction CoreAllocation::make_speculated_alloc ( const PHV::Transaction & alloc,
const PHV::SuperCluster & sc,
const std::vector< PHV::AllocSlice > & candidates,
const PHV::Container & c ) const

Generate pseudo AllocSlices for field slices that have not been allocated, but their allocation can be speculated upfront: when there is only one valid starting position.

Returns
a transaction that contains the pseudo AllocSlices. we can infer that field slices will be allocated to a container with corresponding starting positions. This will allow can_pack function to check constraints from action reading side, even if destination has not been allocated yet. This is enabled only when utils_i.settings_.trivial_alloc is true, otherwise, it simply returns alloc.

◆ satisfies_constraints() [1/5]

bool CoreAllocation::satisfies_constraints ( const PHV::Allocation & alloc,
const PHV::AllocSlice & slice,
ordered_set< PHV::AllocSlice > & initFields,
std::vector< PHV::AllocSlice > & candidate_slices ) const
Returns
true if slice is a valid allocation move given the allocation status in alloc. initFields contains a list of fields in this container that will be initialized via metadata initialization.

◆ satisfies_constraints() [2/5]

bool CoreAllocation::satisfies_constraints ( const PHV::ContainerGroup & container_group,
const PHV::SuperCluster & cluster_group )
static
Returns
true if container_group and cluster_group satisfy constraints. TODO: figure out what, if any, constraints should go here.

◆ satisfies_constraints() [3/5]

bool CoreAllocation::satisfies_constraints ( const PHV::ContainerGroup & group,
const PHV::Field * f ) const
Returns
true if field<-->group constraints are satisfied.

◆ satisfies_constraints() [4/5]

bool CoreAllocation::satisfies_constraints ( const PHV::ContainerGroup & group,
const PHV::FieldSlice & slice ) const
Returns
true if field slice<-->group constraints are satisfied.

◆ satisfies_constraints() [5/5]

bool CoreAllocation::satisfies_constraints ( std::vector< PHV::AllocSlice > slices,
const PHV::Allocation & alloc ) const
Returns
true if slice list<-->container constraints are satisfied.

FIXME(vstill): the mutex check seems to be needed also in cases where the data are not comming from the packet

◆ some_overlay()

bool CoreAllocation::some_overlay ( const SymBitMatrix & mutually_exclusive_field_ids,
const PHV::Field * f,
const ordered_set< PHV::AllocSlice > & slices )
static
Returns
true if f can overlay at least one field in slices.

◆ try_alloc()

std::optional< PHV::Transaction > CoreAllocation::try_alloc ( const PHV::Allocation & alloc,
const PHV::ContainerGroup & group,
PHV::SuperCluster & cluster,
int max_alignment_tries,
const ScoreContext & score_ctx ) const

Try to allocate all fields in cluster to containers in group, using the following techniques (when permissible by constraints), assuming alloc is the allocation so far, possibly including allocations to containers in group:

  • splitting fields across different containers
  • packing different fields (or field slices) into the same container
  • overlaying fields
Returns
an allocation of cluster to group or std::nullopt if no allocation could be found.

Caveats and TODOs:

  • Only does container_no_pack + overlay so far.
  • Does not handle partially-allocated clusters, eg. from pragmas.
  • Does not slice clusters.
  • Does not slice fields into non-container sized slices.

Uses mutex_i and uses_i.

◆ try_deparser_zero_alloc()

std::optional< PHV::Transaction > CoreAllocation::try_deparser_zero_alloc ( const PHV::Allocation & alloc,
PHV::SuperCluster & cluster,
PhvInfo & phv ) const

Helper function that tries to allocate all fields in the deparser zero supercluster cluster to containers B0 (for ingress) and B16 (for egress). The DeparserZero analysis earlier in PHV allocation already ensures that these fields can be safely allocated to the zero-ed containers.

◆ tryAllocSliceList() [1/2]

std::optional< PHV::Transaction > CoreAllocation::tryAllocSliceList ( const PHV::Allocation & alloc,
const PHV::ContainerGroup & group,
const PHV::SuperCluster & super_cluster,
const PHV::Allocation::ConditionalConstraint & start_positions,
const ScoreContext & score_ctx ) const

Helper function for tryAlloc that tries to allocate all fields in start_positions simultaneously. Deparsed fields in particular need to be placed simultaneously with their neighbors; otherwise, the deparsed constraint cannot be satisfied.

For example, consider a header with two 8-bit fields:

header h { bit<4> f1; bit<4> f2; }

Fields f1 and f2 are deparsed, meaning that each must be placed in a container alone or with other deparsed fields (in order) such that no container bits are unallocated. However, if we check this constraint one field at a time, then neither field can be placed—one must be placed first, but it only occupies half the container, violating the constraint.

Additionally, start_positions also includes the conditional constraints generated by ActionPhvConstraints.

Uses mutex_i and uses_i.

Parameters
allocthe allocation computed so far.
groupthe container group to which the slice list is to be allocated.
super_cluster???
start_positionsa map. Keys are the field slices to be allocated. Values are the corresponding conditional constraint on the field slice.
score_ctxTODO TODO: there is an assumption that only fieldslice of the slice list, shows up in the start_positions map (as there is no slice list passed as args). Better to remove this.
  1. no overlapped slice.
  1. directly overlaid.

◆ tryAllocSliceList() [2/2]

std::optional< PHV::Transaction > CoreAllocation::tryAllocSliceList ( const PHV::Allocation & alloc,
const PHV::ContainerGroup & group,
const PHV::SuperCluster & super_cluster,
const PHV::SuperCluster::SliceList & slice_list,
const ordered_map< PHV::FieldSlice, int > & start_positions,
const ScoreContext & score_ctx ) const

Convenience method that transforms start_positions map into a map of ConditionalConstraint, which is passed to tryAllocSliceList above.