P4C
The P4 Compiler
Loading...
Searching...
No Matches
PHV::AlignedCluster Class Reference

#include <utils.h>

Inheritance diagram for PHV::AlignedCluster:
[legend]

Public Types

using const_iterator = ordered_set<PHV::FieldSlice>::const_iterator
 

Public Member Functions

template<typename Iterable >
 AlignedCluster (PHV::Kind kind, Iterable slices)
 
size_t aggregate_size () const override
 
std::optional< unsigned > alignment () const
 
const_iterator begin () const
 
bool contains (const PHV::Field *f) const override
 
bool contains (const PHV::FieldSlice &slice) const override
 
bool deparsed () const override
 
const_iterator end () const
 
int exact_containers () const override
 
gress_t gress () const override
 
int id () const
 
PHV::Kind kind ()
 
int max_width () const override
 
int num_constraints () const override
 
bool okIn (PHV::Kind kind) const override
 
bool operator== (const AlignedCluster &other) const
 
std::optional< SliceResult< AlignedCluster > > slice (int pos) const
 
const ordered_set< PHV::FieldSlice > & slices () const
 
bitvec validContainerStart (PHV::Size container_size) const
 
- Public Member Functions inherited from PHV::ClusterStats

Static Public Member Functions

static bitvec validContainerStart (PHV::FieldSlice slice, PHV::Size container_size)
 Valid start positions for slice in container_size sized containers.
 

Additional Inherited Members

- Public Attributes inherited from PHV::ClusterStats
int uid = nextId++
 

Detailed Description

An AlignedCluster groups slices that are involved in the same MAU operations and, therefore, must be placed at the same alignment in containers in the same MAU container group.

For example, suppose a P4 program includes the following operations:

 a = b + c;
 d = e + a;

Fields a, b, c, d, and e must start at the same bit position and be placed in the same MAU container group.

Note that the set instruction (which translates to the deposit_field ALU operation) is a special case, because deposit_field can optionally rotate its source operand; hence, the operands do not need to be aligned.

Member Function Documentation

◆ aggregate_size()

size_t PHV::AlignedCluster::aggregate_size ( ) const
inlineoverridevirtual
Returns
the sum of the widths of slices in this cluster.

Implements PHV::ClusterStats.

◆ alignment()

std::optional< unsigned > PHV::AlignedCluster::alignment ( ) const
inline
Returns
the (little Endian) byte-relative alignment constraint (if any) for all slices in this cluster.

◆ contains() [1/2]

bool PHV::AlignedCluster::contains ( const PHV::Field * f) const
overridevirtual
Returns
true if this cluster contains f.

Implements PHV::ClusterStats.

◆ contains() [2/2]

bool PHV::AlignedCluster::contains ( const PHV::FieldSlice & slice) const
overridevirtual
Returns
true if this cluster contains slice.

Implements PHV::ClusterStats.

◆ deparsed()

bool PHV::AlignedCluster::deparsed ( ) const
inlineoverridevirtual
Returns
true if any slice in the cluster is deparsed (either to the wire or the TM).

Implements PHV::ClusterStats.

◆ exact_containers()

int PHV::AlignedCluster::exact_containers ( ) const
inlineoverridevirtual
Returns
the number of slices in this container with the exact_containers constraint.

Implements PHV::ClusterStats.

◆ gress()

gress_t PHV::AlignedCluster::gress ( ) const
inlineoverridevirtual
Returns
the gress requirement of this cluster.

Implements PHV::ClusterStats.

◆ id()

int PHV::AlignedCluster::id ( ) const
inline
Returns
id of this cluster

◆ kind()

PHV::Kind PHV::AlignedCluster::kind ( )
inline
Returns
The kind of PHV container representing the minimum requirements for all slices in this container.

◆ max_width()

int PHV::AlignedCluster::max_width ( ) const
inlineoverridevirtual
Returns
the width of the widest slice in this cluster.

Implements PHV::ClusterStats.

◆ num_constraints()

int PHV::AlignedCluster::num_constraints ( ) const
inlineoverridevirtual
Returns
the total number of constraints summed over all slices in this cluster.

Implements PHV::ClusterStats.

◆ okIn()

bool PHV::AlignedCluster::okIn ( PHV::Kind kind) const
overridevirtual
Returns
true if this cluster can be assigned to containers of kind kind.

Implements PHV::ClusterStats.

◆ operator==()

bool PHV::AlignedCluster::operator== ( const AlignedCluster & other) const

Two aligned clusters are equivalent if they contain the same slices and can be assigned to the same kind of PHV containers.

◆ slice()

std::optional< PHV::SliceResult< PHV::AlignedCluster > > PHV::AlignedCluster::slice ( int pos) const

Slices this cluster at the relative field bit pos. For example, if a cluster contains a field slice [3..7] and pos == 2, then slice will produce two clusters, one with [3..4] and the other with [5..7].

If pos is larger than the size of a field slice in this cluster, then the slice is placed entirely in the lo cluster. If pos is larger than all field sizes, then the hi cluster will not contain any fields.

Parameters
posthe position to split, i.e. the first bit of the upper slice. pos must be non-negative.
Returns
a pair of (lo, hi) clusters if the cluster can be split at pos or std::nullopt otherwise.

◆ slices()

const ordered_set< PHV::FieldSlice > & PHV::AlignedCluster::slices ( ) const
inline
Returns
the slices in this cluster.

◆ validContainerStart()

bitvec PHV::AlignedCluster::validContainerStart ( PHV::Size container_size) const

Combines AlignedCluster::alignment() and AlignedCluster::validContainerStartRange(container_size) to compute the valid lo bit positions where slices of this cluster can be placed in containers of size container_size, or std::nullopt if no valid start positions exist or if any slice is too large to fit in containers of container_size.

If any slice in this cluster has the deparsed_bottom_bits constraint, then the bitvec will be [0, 0], or empty if any slice cannot be started at container bit 0.

Returns
the set of bit positions at which all slices in this cluster all slices can be placed, if any.