P4C
The P4 Compiler
Loading...
Searching...
No Matches
CheckWriteModeConsistency Struct Reference

#include <check_parser_multi_write.h>

Inheritance diagram for CheckWriteModeConsistency:
[legend]

Public Member Functions

 CheckWriteModeConsistency (const PhvInfo &p, const MapFieldToParserStates &fs, const CollectParserInfo &pi)
 
bool check_compatability (const PHV::FieldSlice &slice_a, const PHV::FieldSlice &slice_b)
 

Protected Member Functions

bool check (const std::vector< const IR::BFN::Extract * > extracts) const
 Check that the write modes of all extracts are consistent.
 
void check_and_adjust (const std::vector< const IR::BFN::Extract * > extracts)
 Check and adjust the write modes of all extracts to be consistent.
 
void check_post_alloc ()
 Verify/unify parser write mode consistency post PHV allocation.
 
void check_pre_alloc (const ordered_set< const IR::BFN::ParserPrimitive * > &state_writes)
 
profile_t init_apply (const IR::Node *root) override
 
IR::Node * preorder (IR::BFN::Extract *extract) override
 
IR::Node * preorder (IR::BFN::ParserChecksumWritePrimitive *pcw) override
 
template<typename T >
IR::Node * set_write_mode (T *write)
 

Protected Attributes

std::map< std::pair< PHV::FieldSlice, PHV::FieldSlice >, bool > compatability
 
std::map< const IR::BFN::ParserPrimitive *, IR::BFN::ParserWriteMode > extract_to_write_mode
 
const MapFieldToParserStatesfield_to_states
 
const PhvInfophv
 
const ParserQuery pq
 

Detailed Description

Check if fields that share the same byte on the wire have conflicting parser write semantics.

Member Function Documentation

◆ check_and_adjust()

void CheckWriteModeConsistency::check_and_adjust ( const std::vector< const IR::BFN::Extract * > extracts)
protected

Check and adjust the write modes of all extracts to be consistent.

Checks whether the write modes of all extracts are consistent. If not, record the adjustments necessary to make them consistent, or produce an error if they can't be made consistent.

◆ check_compatability()

bool CheckWriteModeConsistency::check_compatability ( const PHV::FieldSlice & slice_a,
const PHV::FieldSlice & slice_b )

Check if the extracts for two slices can be made compatible

◆ check_post_alloc()

void CheckWriteModeConsistency::check_post_alloc ( )
protected

Verify/unify parser write mode consistency post PHV allocation.

Verify that the parser write modes are consistent across fields. If not, then attempt to unify the write modes.

◆ check_pre_alloc()

void CheckWriteModeConsistency::check_pre_alloc ( const ordered_set< const IR::BFN::ParserPrimitive * > & state_writes)
protected

Find all extracts that stard/end in mid byte and add them to a map by the partial byte they create. Ideally, we would check together only fields that actually lead to the same PHV. But this would require doing this analysis only after fields are sliced and PHV allocated. That currently cannot be done as the PHV allocation uses write modes as input. A proper solution might be to integrate this check/modification of write modes to PHV allocation.

Meanwhile, we approximate by looking for generations of extracted bits – we go over the extracts in the order they appear in the state and every time we encounter bit that is not higher than the last already extracted, we start a new generation of extracts. Then we only look for conflicts within the same generation. This should resolve code like pkt.extract(hdrs.a) meta.x = pkt.hdr.a.x that does actually generate two extracts of x to different fields. NOTE: the ranges coming from one P4 extract may not be consecutive due to dead-extract elimination.