P4C
The P4 Compiler
Loading...
Searching...
No Matches
InferWriteMode Struct Reference
Inheritance diagram for InferWriteMode:
[legend]

Classes

struct  CounterExample
 

Public Member Functions

 InferWriteMode (const PhvInfo &ph, const CollectParserInfo &pi, const MapFieldToParserStates &fs)
 
bool can_absorb (const IR::BFN::ParserPrimitive *prev_p, const IR::BFN::ParserPrimitive *curr_p)
 
ordered_set< const IR::BFN::ParserPrimitive * > exclude_zero_inits (const ordered_set< const IR::BFN::ParserPrimitive * > &writes)
 
ordered_set< const IR::BFN::ParserPrimitive * > find_inits (const ordered_set< const IR::BFN::ParserPrimitive * > &writes)
 
void infer_write_mode (const PHV::Field *dest, const ordered_set< const IR::BFN::ParserPrimitive * > &prim_writes)
 
profile_t init_apply (const IR::Node *root) override
 
CounterExampleis_bitwise_or (const PHV::Field *dest, const ordered_set< const IR::BFN::ParserPrimitive * > &writes, bool strict=false)
 
CounterExampleis_clear_on_write (const ordered_set< const IR::BFN::ParserPrimitive * > &writes)
 
bool is_postdominated_by_extract (const IR::BFN::ParserPrimitive *write, const ordered_set< const IR::BFN::ParserPrimitive * > &writes)
 
bool is_zero_extract (const IR::BFN::ParserPrimitive *p)
 
ordered_set< const IR::BFN::ParserPrimitive * > mark_and_exclude_dead_writes (const ordered_set< const IR::BFN::ParserPrimitive * > &writes)
 
void mark_write_mode (IR::BFN::ParserWriteMode mode, const PHV::Field *dest, const ordered_set< const IR::BFN::ParserPrimitive * > &writes)
 
IR::Node * preorder (IR::BFN::Extract *extract) override
 
IR::Node * preorder (IR::BFN::ParserChecksumWritePrimitive *checksum_write) override
 
void print (CounterExample *example)
 
void validate_checksum_residual_deposits (const PHV::Field *field, const ordered_set< const IR::BFN::ParserPrimitive * > &writes)
 

Public Attributes

ordered_set< const IR::BFN::ParserPrimitive * > dead_writes
 
const MapFieldToParserStatesfield_to_states
 
const CollectParserInfoparser_info
 
const PhvInfophv
 
const ParserQuery pq
 
std::map< const IR::BFN::ParserPrimitive *, IR::BFN::ParserWriteMode > write_to_write_mode
 
ordered_set< const IR::BFN::ParserPrimitive * > zero_inits
 

Member Function Documentation

◆ can_absorb()

bool InferWriteMode::can_absorb ( const IR::BFN::ParserPrimitive * prev_p,
const IR::BFN::ParserPrimitive * curr_p )
inline

Check if the current write curr_p is safe to be applied BITWISE_OR on the prev_p write. This can be done if we can guarantee that no bit will need to be set to 0.

  • if both prev_p and curr_p are constants and their bitwise or is same as curr_p
  • if curr_p is a constant and sets all bits in the left-hand-side of the assignment to 1
  • if prev_p is constant 0

◆ is_bitwise_or()

CounterExample * InferWriteMode::is_bitwise_or ( const PHV::Field * dest,
const ordered_set< const IR::BFN::ParserPrimitive * > & writes,
bool strict = false )
inline

strict indicates that all ovewrites should be treated as "always overwrites". This specifically means that they will always cause error even on Tofino 1.

◆ is_postdominated_by_extract()

bool InferWriteMode::is_postdominated_by_extract ( const IR::BFN::ParserPrimitive * write,
const ordered_set< const IR::BFN::ParserPrimitive * > & writes )
inline

Determines whether extract write is postdominated by extract of the same field (from writes). Essentially we want to check 2 separate things:

  1. A state/extract is postdominated by extracts of a same field as is (without loopbacks) Example: A->B ->C if A, B, C extract the same field x then is_postdominated_by_extract = true if A, B extract the same field x, but C does not then is_postdominated_by_extract = false
  2. There is a loopback in which the same field is always extracted (loop start is postdominate by extracts within that loop). In this case we also have to take into account the fact that the "loop from" state needs to be dominated by the set, otherwise the loop might make sense when we reach this state without extracting the field and then take the loopback once. Example: A->B->D->A (loopback from D to A) ->C-> if B, C extract the same field x then is_postdominated_by_extract = true if A or D extract the field x then is_postdominated_by_extract = true if A, D does not extract x and only one of B, C extract the field x then is_postdominated_by_extract = false

This is mainly used to detect the cases where we allow unsafe rewrites on Tofino 1

◆ validate_checksum_residual_deposits()

void InferWriteMode::validate_checksum_residual_deposits ( const PHV::Field * field,
const ordered_set< const IR::BFN::ParserPrimitive * > & writes )
inline

Check for all pairs of checksum residual deposits that can conflict with each other. This can be a problem as these instructions have affect at the end of the parser, after they were called in some previous state.