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

#include <phv_fields.h>

Classes

struct  DumpPhvFields
 Pretty-print all fields. More...
 
struct  SameContainerAllocConstraint
 
struct  StructInfo
 PHV-related info about structs, i.e. collections of header or metadata fields. More...
 

Public Types

typedef ordered_map< PHV::Container, std::vector< PHV::AllocSlice > > ContainterToSliceMap
 

Public Member Functions

PHV::Fieldadd (cstring fieldName, gress_t gress, int size, int offset, bool isMetadata, bool isPOV, bool bridged=false, bool isPad=false, bool isOverlayable=false, bool isFlexible=false, bool isFixedSizeHeader=false, std::optional< Util::SourceInfo > srcInfo=std::nullopt)
 
void add_container_to_field_entry (const PHV::Container c, const PHV::Field *f)
 
bool add_table_constraints (gress_t grs, IR::MAU::Table *tbl, InsertionConstraints cnstrs)
 
void addAliasMapEntry (const PHV::Field *f1, const PHV::Field *f2)
 Adds an entry to the aliasMap.
 
void addDarkMutex (const PHV::Field *f1, const PHV::Field *f2)
 
void addDeparserNoPack (const PHV::Field *f1, const PHV::Field *f2)
 
void addDigestNoPack (const PHV::Field *f1, const PHV::Field *f2)
 
void addExternalNameMapEntry (PHV::Field *f, cstring externalName)
 Adds an entry to the externalNameMap.
 
void addFieldMutex (const PHV::Field *f1, const PHV::Field *f2)
 
void addFieldNoPack (const PHV::Field *f1, const PHV::Field *f2)
 
void addMetadataDependency (const IR::MAU::Table *t1, const IR::MAU::Table *t2, const PHV::FieldSlice *slice=nullptr)
 
void addMetadataMutex (const PHV::Field *f1, const PHV::Field *f2)
 
void addMutuallyAligned (const PHV::Field *f1, const PHV::Field *f2)
 
void addTempVar (const IR::TempVar *tempVar, gress_t gress)
 
void addZeroContainer (gress_t gr, PHV::Container c)
 adds container to the set of deparsed zero containers.
 
bool alloc_done () const
 
bool are_bridged_extracted_together (const PHV::Field *f1, const PHV::Field *f2) const
 
bool are_mutually_aligned (const PHV::Field *f1, const PHV::Field *f2) const
 
iterator< safe_vector< PHV::Field * >::iterator > begin ()
 
iterator< safe_vector< PHV::Field * >::const_iterator > begin () const
 
bitvec bits_allocated (const PHV::Container container, const IR::MAU::Table *ctxt, const PHV::FieldUse *use=nullptr) const
 
bitvec bits_allocated (const PHV::Container container, const ordered_set< const PHV::Field * > &fields, const IR::MAU::Table *ctxt, const PHV::FieldUse *use=nullptr) const
 
bitvec bits_allocated (const PHV::Container container, const PHV::Field *field, const IR::MAU::Table *ctxt, const PHV::FieldUse *use=nullptr) const
 
bitvec bits_allocated (const PHV::Container, const ordered_set< const PHV::Field * > &, const PHV::AllocContext *ctxt=nullptr, const PHV::FieldUse *use=nullptr) const
 
bitvec bits_allocated (const PHV::Container, const PHV::AllocContext *ctxt=nullptr, const PHV::FieldUse *use=nullptr) const
 
bitvec bits_allocated (const PHV::Container, const PHV::Field *field, const PHV::AllocContext *ctxt=nullptr, const PHV::FieldUse *use=nullptr) const
 
void clear_container_to_fields ()
 
void clearARAconstraints ()
 
void clearConstantExtractionState ()
 Clear the state maintained corresponding to constant extractors.
 
PHV::Fieldcreate_dummy_padding (size_t sz, gress_t gress, bool overlayable=true)
 
SymBitMatrixdark_mutex ()
 
const SymBitMatrixdark_mutex () const
 
bool darkLivenessOkay (const IR::MAU::Table *gateway, const IR::MAU::Table *t) const
 
SymBitMatrixdeparser_no_pack_mutex ()
 
const SymBitMatrixdeparser_no_pack_mutex () const
 
SymBitMatrixdigest_no_pack_mutex ()
 
const SymBitMatrixdigest_no_pack_mutex () const
 
iterator< safe_vector< PHV::Field * >::iterator > end ()
 
iterator< safe_vector< PHV::Field * >::const_iterator > end () const
 
const PHV::Fieldfield (const cstring &) const
 
PHV::Fieldfield (const cstring &name)
 
const PHV::Fieldfield (const IR::Expression *, le_bitrange *bits=0) const
 
PHV::Fieldfield (const IR::Expression *e, le_bitrange *bits=0)
 
const PHV::Fieldfield (const IR::Member *, le_bitrange *bits=0) const
 
PHV::Fieldfield (const IR::Member *fr, le_bitrange *bits=0)
 
PHV::Fieldfield (int idx)
 
const PHV::Fieldfield (int idx) const
 
SymBitMatrixfield_mutex ()
 
const SymBitMatrixfield_mutex () const
 
const ordered_set< const PHV::Field * > & fields_in_container (const PHV::Container c) const
 
cstring full_hdr_name (const cstring &name) const
 
std::optional< cstringget_alias_name (const IR::Expression *expr) const
 
const std::map< cstring, PHV::Field > & get_all_fields () const
 
std::vector< PHV::AllocSliceget_alloc (const IR::Expression *f, const PHV::AllocContext *ctxt=nullptr, const PHV::FieldUse *use=nullptr) const
 
std::vector< PHV::AllocSliceget_alloc (const PHV::Field *phv_field, le_bitrange *bits=nullptr, const PHV::AllocContext *ctxt=nullptr, const PHV::FieldUse *use=nullptr) const
 
void get_hdr_fields (cstring name_, ordered_set< const PHV::Field * > &flds) const
 
std::vector< PHV::AllocSliceget_slices_in_container (const PHV::Container c) const
 
std::vector< PHV::AllocSliceget_slices_in_container (const PHV::Container c, const PHV::AllocContext *ctxt, const PHV::FieldUse *use) const
 
const PHV::FieldgetAliasDestination (const PHV::Field *f) const
 
const ordered_map< const PHV::Field *, const PHV::Field * > & getAliasMap () const
 
const ordered_map< gress_t, ConstraintMap > & getARAConstraints () const
 
SymBitMatrixgetBridgedExtractedTogether ()
 
const SymBitMatrixgetBridgedExtractedTogether () const
 
ContainterToSliceMap getContainerToSlicesMap (std::function< bool(const PHV::Field *)> *f=nullptr, std::function< bool(const PHV::AllocSlice *)> *s=nullptr) const
 
const ordered_map< tpair, const PHV::FieldSlice * > & getMetadataDepFields () const
 
const ordered_map< cstring, ordered_set< cstring > > & getMetadataDeps () const
 
SymBitMatrixgetMutuallyAligned ()
 
const SymBitMatrixgetMutuallyAligned () const
 
const ordered_map< cstring, ordered_set< cstring > > & getReverseMetadataDeps () const
 
const ordered_set< cstringgetReverseMetadataDeps (const IR::MAU::Table *t) const
 
UnionFind< PHV::Field * > & getSameSetConstantExtraction ()
 
const UnionFind< PHV::Field * > & getSameSetConstantExtraction () const
 
const IR::TempVar * getTempVar (const PHV::Field *f) const
 
const std::set< PHV::Container > & getZeroContainers (gress_t gr) const
 
bool has_struct_info (cstring name) const
 
bool hasParserConstantExtract (const PHV::Field *f) const
 
const PhvInfo::StructInfohdr (const cstring &name_) const
 Get information about a collection of header or metadata fields, based on the partial or complete name_ of the collection or of a field in the collection.
 
void insertConstantExtractField (PHV::Field *f)
 
bool isDarkMutex (const PHV::Field *f1, const PHV::Field *f2) const
 
bool isDeparserNoPack (const PHV::Field *f1, const PHV::Field *f2) const
 
bool isDigestNoPack (const PHV::Field *f1, const PHV::Field *f2) const
 
bool isFieldMutex (const PHV::Field *f1, const PHV::Field *f2) const
 
bool isFieldNoPack (const PHV::Field *f1, const PHV::Field *f2) const
 
bool isMetadataMutex (const PHV::Field *f1, const PHV::Field *f2) const
 
bool isTempVar (const PHV::Field *f) const
 
void mergeConstantExtracts (PHV::Field *f, PHV::Field *g)
 
SymBitMatrixmetadata_mutex ()
 
const SymBitMatrixmetadata_mutex () const
 
bool must_alloc_same_container (const PHV::FieldSlice &a, const PHV::FieldSlice &b) const
 
size_t num_fields () const
 
void removeDigestNoPack (const PHV::Field *f1, const PHV::Field *f2)
 
void removeFieldMutex (const PHV::Field *f1, const PHV::Field *f2)
 
void removeFieldNoPack (const PHV::Field *f1, const PHV::Field *f2)
 
SameContainerAllocConstraintsame_container_alloc_constraint ()
 
const SameContainerAllocConstraintsame_container_alloc_constraint () const
 
void set_done (bool trivial=false)
 
unsigned sizeFieldNoPack ()
 
const StructInfo struct_info (const IR::HeaderRef *hr) const
 
const StructInfo struct_info (cstring name) const
 
bool trivial_alloc () const
 

Static Public Member Functions

static void addMinStageEntry (const IR::MAU::Table *tbl, int stage, bool remove_prev_stages=false)
 
static void clearMinStageInfo ()
 
static void clearPhysicalStageInfo ()
 
static int getDeparserStage ()
 
static bool hasMinStageEntry (const IR::MAU::Table *tbl)
 
static std::set< int > minStages (const IR::MAU::Table *tbl)
 
static std::set< int > physicalStages (const IR::MAU::Table *tbl)
 
static cstring reportMinStages ()
 
static void resetDarkSpillARA ()
 
static void resetDeparserStage ()
 
static void setDeparserStage (int stage)
 
static void setPhysicalStages (const IR::MAU::Table *tbl, const std::set< int > &stage)
 

Static Public Attributes

static const bool DARK_SPILL_ARA_DEFAULT = true
 
static bool darkSpillARA = PhvInfo::DARK_SPILL_ARA_DEFAULT
 
static int deparser_stage = -1
 
static ordered_map< cstring, std::set< int > > table_to_min_stages
 
static ordered_map< cstring, std::set< int > > table_to_physical_stages
 

Friends

struct AllocatePOVBits
 
class ClearPhvInfo
 
class CollectPhvFields
 
struct MarkBridgedMetadataFields
 

Detailed Description

PhvInfo stores information about the PHV-backed storage in the program - fields of header and metadata instances, header stacks, TempVars, and POV bits. These items are all represented as PHV::Field objects.

Prior to PHV allocation, PhvInfo provides a central place to discover information about Fields; this includes their name, size and alignment, the ways in which they're used in the program and the PHV allocation constraints that apply to them.

After PHV allocation, PhvInfo additionally stores the allocation results for each Field.

PhvInfo is read throughout the backend, but it should be written to only by CollectPhvInfo and the PHV analysis and PHV bind passes. If you need to store new information in PhvInfo, add a pass that collects it from the IR in CollectPhvInfo.

See also
CollectPhvInfo for more information.

Member Typedef Documentation

◆ ContainterToSliceMap

Returns
a map of container to slices filtered based on field & slice filtering functions

Member Function Documentation

◆ add_container_to_field_entry()

void PhvInfo::add_container_to_field_entry ( const PHV::Container c,
const PHV::Field * f )

Add new field to a container

Parameters
ffield stored within container c
ccontainer to store field f

◆ addMetadataDependency()

void PhvInfo::addMetadataDependency ( const IR::MAU::Table * t1,
const IR::MAU::Table * t2,
const PHV::FieldSlice * slice = nullptr )
inline

notes down a required dependence from table t1 to table t2, induced by metadata initialization to enable live range shrinking. Updates both the metadataDeps and reverseMetadataDeps members.

◆ bits_allocated() [1/3]

bitvec PhvInfo::bits_allocated ( const PHV::Container c,
const ordered_set< const PHV::Field * > & writes,
const PHV::AllocContext * ctxt = nullptr,
const PHV::FieldUse * use = nullptr ) const
Returns
a bitvec showing the currently allocated bits in a container corresponding to fields simultaneously live with the fields passed in the argument set, within the context ctxt. The context is one of ParserState, Table/Stage, Deparser. A null context represents the entire pipeline. Note that one common bitvec is used to represent all fields that may be in a container

◆ bits_allocated() [2/3]

bitvec PhvInfo::bits_allocated ( const PHV::Container c,
const PHV::AllocContext * ctxt = nullptr,
const PHV::FieldUse * use = nullptr ) const
Returns
a bitvec showing all potentially allocated bits within a container, within the ctxt context. The context is one of ParserState, Table/Stage, Deparser. A null context represents the entire pipeline.

◆ bits_allocated() [3/3]

bitvec PhvInfo::bits_allocated ( const PHV::Container c,
const PHV::Field * field,
const PHV::AllocContext * ctxt = nullptr,
const PHV::FieldUse * use = nullptr ) const
Returns
a bitvec showing all potentially allocated bits within a container for the given field field, within the ctxt context. The context is one of ParserState, Table/Stage, Deparser. A null context represents the entire pipeline.

◆ clear_container_to_fields()

void PhvInfo::clear_container_to_fields ( )
inline

Container_to_fields map related functions Clear the container_to_fields map

◆ fields_in_container()

const ordered_set< const PHV::Field * > & PhvInfo::fields_in_container ( const PHV::Container c) const
Returns
the set of fields assigned (partially or entirely) to c

◆ full_hdr_name()

cstring PhvInfo::full_hdr_name ( const cstring & name_) const

Look up the fully qualified name of a header or metadata collection PHV header names are fully qualified, but we sometimes look up a partial name when it's unique. Eg. using "ingress::bar" to find

"ingress::foo.bar" when there are no other "bar" suffixes.

◆ get_alias_name()

std::optional< cstring > PhvInfo::get_alias_name ( const IR::Expression * expr) const
Returns
the alias source name, if the given expression is either a IR::BFN::AliasMember type or is a slice with a IR::BFN::AliasMember object as the underlying base expression.
std::nullopt otherwise.

◆ get_hdr_fields()

void PhvInfo::get_hdr_fields ( cstring name_,
ordered_set< const PHV::Field * > & flds ) const

Get all the fields of header named name_ and store them in set flds

◆ get_slices_in_container() [1/2]

std::vector< PHV::AllocSlice > PhvInfo::get_slices_in_container ( const PHV::Container c) const
Returns
the set of alloc slices assigned to a container c.

◆ get_slices_in_container() [2/2]

std::vector< PHV::AllocSlice > PhvInfo::get_slices_in_container ( const PHV::Container c,
const PHV::AllocContext * ctxt,
const PHV::FieldUse * use ) const
Returns
the set of alloc slices assigned to a container c within a context. The context is one of ParserState, Table/Stage, Deparser. A null context represents the entire pipeline.

◆ getAliasDestination()

const PHV::Field * PhvInfo::getAliasDestination ( const PHV::Field * f) const
inline
Returns
alias destination corresponding to f. Return nullptr if no aliasing relationship exists or if ReinstateAliasSources has not been run.

◆ getAliasMap()

const ordered_map< const PHV::Field *, const PHV::Field * > & PhvInfo::getAliasMap ( ) const
inline
Returns
the aliasMap. This is empty unless ReinstateAliasSources has been run.

◆ getMetadataDepFields()

const ordered_map< tpair, const PHV::FieldSlice * > & PhvInfo::getMetadataDepFields ( ) const
inline
Returns
a reference to metadataDepFields.

◆ getMetadataDeps()

const ordered_map< cstring, ordered_set< cstring > > & PhvInfo::getMetadataDeps ( ) const
inline
Returns
a reference to metadataDeps.

◆ getReverseMetadataDeps() [1/2]

const ordered_map< cstring, ordered_set< cstring > > & PhvInfo::getReverseMetadataDeps ( ) const
inline
Returns
a reference to reverseMetadataDeps.

◆ getReverseMetadataDeps() [2/2]

const ordered_set< cstring > PhvInfo::getReverseMetadataDeps ( const IR::MAU::Table * t) const
inline
Returns
the set of tables which must be placed before table t.

◆ getTempVar()

const IR::TempVar * PhvInfo::getTempVar ( const PHV::Field * f) const
Returns
the TempVar pointer corresponding to f, if the underlying expression for field f is a TempVar.
nullptr otherwise.

◆ getZeroContainers()

const std::set< PHV::Container > & PhvInfo::getZeroContainers ( gress_t gr) const
inline
Returns
the set of deparsed zero containers.

◆ hdr()

const PhvInfo::StructInfo * PhvInfo::hdr ( const cstring & name_) const

Get information about a collection of header or metadata fields, based on the partial or complete name_ of the collection or of a field in the collection.

Parameters
name_Partial or complete name of a field, or a header or metadata collection
Returns
const PhvInfo::StructInfo* Information about collection

◆ insertConstantExtractField()

void PhvInfo::insertConstantExtractField ( PHV::Field * f)
inline

Inserts a new field f into the UnionFind structure that keeps track of fields written in the same parser state using constant extractors.

◆ mergeConstantExtracts()

void PhvInfo::mergeConstantExtracts ( PHV::Field * f,
PHV::Field * g )
inline

Perform a union of sets for fields f and g in the sameStateConstantExtraction UnionFind struct.