P4C
The P4 Compiler
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Table Class Referenceabstract
Inheritance diagram for Table:
[legend]

Classes

class  Actions
 
struct  Call
 
class  Format
 
struct  Layout
 
class  NextTables
 
struct  p4_param
 
struct  Ref
 
class  Type
 

Public Types

typedef std::map< std::string, std::string > default_action_params
 
typedef std::vector< p4_paramp4_params
 
enum  table_type_t {
  OTHER = 0 , TERNARY_INDIRECT , GATEWAY , ACTION ,
  SELECTION , COUNTER , METER , IDLETIME ,
  STATEFUL , HASH_ACTION , EXACT , TERNARY ,
  PHASE0 , ATCAM , PROXY_HASH
}
 

Public Member Functions

virtual Callaction_call ()
 
std::string action_profile () const
 
virtual void add_field_to_pack_format (json::vector &field_list, unsigned basebit, std::string name, const Table::Format::Field &field, const Table::Actions::Action *act) const
 
bool add_json_node_to_table (json::map &tbl, const char *name, bool append=false) const
 
void add_match_key_cfg (json::map &tbl) const
 
json::mapadd_pack_format (json::map &stage_tbl, int memword, int words, int entries=-1) const
 
json::mapadd_pack_format (json::map &stage_tbl, Table::Format *format, bool pad_zeros=true, bool print_fields=true, Table::Actions::Action *act=nullptr) const
 
virtual void add_reference_table (json::vector &table_refs, const Table::Call &c) const
 
virtual void add_result_physical_buses (json::map &stage_tbl) const
 
virtual json::mapadd_stage_tbl_cfg (json::map &tbl, const char *type, int size) const
 
void add_zero_padding_fields (Table::Format *format, Table::Actions::Action *act=nullptr, unsigned format_width=64) const
 
virtual int address_shift () const
 
virtual bool adr_mux_select_stats ()
 
void allocate_physical_ids (unsigned usable=~0U)
 
virtual void apply_to_field (const std::string &n, std::function< void(Format::Field *)> fn)
 
void canon_field_list (json::vector &field_list) const
 
void check_next ()
 
void check_next (const Ref &next)
 
void check_next (NextTables &next)
 
bool choose_logical_id (const slist< Table * > *work=nullptr)
 
virtual int color_shiftcount (Table::Call &call, int group, int tcam_shift) const
 
virtual void common_tbl_cfg (json::map &tbl) const
 
virtual bitvec compute_reachable_tables ()
 
virtual unsigned determine_shiftcount (Table::Call &call, int group, unsigned word, int tcam_shift) const
 
virtual std::vector< int > determine_spare_bank_memory_units () const
 
virtual void determine_word_and_result_bus ()
 
virtual int direct_shiftcount () const
 
virtual Format::Fieldfind_address_field (const AttachedTable *) const
 
virtual std::string find_field (Format::Field *field)
 
virtual int find_field_lineno (Format::Field *field)
 
virtual HashDistributionfind_hash_dist (int unit)
 
virtual int find_on_actionbus (const ActionBusSource &src, int lo, int hi, int size, int pos=-1)
 
int find_on_actionbus (const char *n, int lo, int hi, int size, int *len=0)
 
virtual int find_on_actionbus (const char *n, TableOutputModifier mod, int lo, int hi, int size, int *len=0)
 
int find_on_actionbus (const std::string &n, int lo, int hi, int size, int *len=0)
 
int find_on_actionbus (const std::string &n, TableOutputModifier mod, int lo, int hi, int size, int *len=0)
 
int find_on_ixbar (Phv::Slice sl, InputXbar::Group group, InputXbar::Group *found=nullptr)
 
int find_on_ixbar (Phv::Slice sl, int group)
 
const p4_paramfind_p4_param (std::string s, std::string t="", int start_bit=-1, int width=-1) const
 
const p4_paramfind_p4_param_type (std::string &s) const
 
const std::vector< const p4_param * > find_p4_params (std::string s, std::string t="", int start_bit=-1, int width=-1) const
 
std::map< Table *, std::set< Actions::Action * > > find_pred_in_stage (int stageno, const std::set< Actions::Action * > &acts=std::set< Actions::Action * >())
 
void for_all_next (std::function< void(const Ref &)> fn)
 
 FOR_ALL_REGISTER_SETS (TARGET_OVERLOAD, virtual void write_action_regs,(mau_regs &, const Actions::Action *), {}) FOR_ALL_REGISTER_SETS(TARGET_OVERLOAD
 
virtual std::unique_ptr< json::mapgen_memory_resource_allocation_tbl_cfg (const char *type, const std::vector< Layout > &layout, bool skip_spare_bank=false) const
 
virtual const Callget_action () const
 
virtual Actionsget_actions () const
 
virtual AttachedTablesget_attached ()
 
virtual const AttachedTablesget_attached () const
 
virtual std::vector< Callget_calls () const
 
void get_cjson_source (const std::string &field_name, std::string &source, int &start_bit) const
 
virtual std::string get_default_action ()
 
virtual unsigned get_default_action_handle () const
 
virtual default_action_params * get_default_action_parameters ()
 
virtual Formatget_format () const
 
int get_format_field_size (std::string s) const
 
virtual const GatewayTable * get_gateway () const
 
virtual const std::vector< NextTables > & get_hit_next () const
 
virtual MatchTable * get_match_table ()
 
virtual const MatchTable * get_match_table () const
 
virtual std::set< MatchTable * > get_match_tables ()
 
virtual MeterTable * get_meter () const
 
virtual Format::Fieldget_meter_address_param (MatchTable *) const
 
virtual Format::Fieldget_meter_type_param (MatchTable *) const
 
virtual const NextTablesget_miss_next () const
 
virtual Format::Fieldget_per_flow_enable_param (MatchTable *) const
 
virtual SelectionTable * get_selector () const
 
virtual StatefulTable * get_stateful () const
 
virtual int get_tcam_id () const
 
unsigned handle () const
 
virtual int hit_next_size () const
 
virtual int home_row () const
 
std::string how_referenced () const
 
virtual int indirect_shiftcount () const
 
template<typename T>
void init_json_node (json::map &tbl, const char *name) const
 
virtual Callinstruction_call ()
 
virtual int instruction_set ()
 
virtual bool is_always_run () const
 
virtual bool is_attached (const Table *) const
 
virtual bool is_directly_referenced (const Table::Call &c) const
 
virtual int json_memunit (const MemUnit &u) const
 
unsigned layout_get_vpn (const MemUnit &m) const
 
unsigned layout_size () const
 
void layout_vpn_bounds (int &min, int &max, bool spare=false) const
 
std::string loc () const
 
virtual Format::Fieldlookup_field (const std::string &n, const std::string &act="") const
 
virtual void merge_context_json (json::map &tbl, json::map &stage_tbl) const
 
const char * name () const
 
virtual void need_on_actionbus (const ActionBusSource &src, int lo, int hi, int size)
 
virtual void need_on_actionbus (Table *att, TableOutputModifier mod, int lo, int hi, int size)
 
virtual bool needs_handle () const
 
virtual bool needs_next () const
 
void output_field_to_pack_format (json::vector &field_list, unsigned basebit, std::string name, std::string source, unsigned start_bit, const Table::Format::Field &field, unsigned value=0) const
 
const char * p4_name () const
 
unsigned p4_size () const
 
virtual void pass0 ()
 
virtual void pass1 ()
 
virtual void pass2 ()=0
 
virtual void pass3 ()=0
 
virtual int ram_word_width () const
 
bitvec reachable_tables ()
 
virtual bool run_at_eop ()
 
virtual void set_address_used ()
 
virtual void set_color_used ()
 
virtual table_type_t set_match_table (MatchTable *m, bool indirect)
 
virtual void set_output_used ()
 
virtual void set_pred ()
 
virtual void set_stateful (StatefulTable *s)
 
virtual int stm_vbus_column () const
 
int table_id () const
 
virtual table_type_t table_type () const
 
template<class T>
T * to ()
 
template<class T>
const T * to () const
 
virtual int unitram_type ()
 
virtual bool uses_colormaprams () const
 
virtual bool validate_call (Table::Call &call, MatchTable *self, size_t required_args, int hash_dist_type, Table::Call &first_call)
 
bool validate_instruction (Table::Call &call) const
 
template<class REGS>
void write_mapram_regs (REGS &regs, int row, int col, int vpn, int type)
 

Static Public Member Functions

static bool allow_bus_sharing (Table *t1, Table *t2)
 

Public Attributes

Call action
 
std::unique_ptr< ActionBusaction_bus
 
int action_enable = -1
 
std::unique_ptr< Actionsactions
 
virtual void mau_regs int int virtual FOR_ALL_REGISTER_SETS(TARGET_OVERLOAD, virtual void write_merge_regs,(mau_regs &, MatchTable *match, int type, int bus, const std::vector< Call::Arg > &args), { assert(0);}) virtual void gen_tbl_cfg(json json::map base_tbl_cfg )(json::vector &out, const char *type, int size) const { assert(0)
 
virtual void mau_regs int int bus
 
std::unique_ptr< json::mapcontext_json
 
std::string default_action
 
unsigned default_action_handle = 0
 
int default_action_lineno = -1
 
default_action_params default_action_parameters
 
bool default_only_action = false
 
std::vector< DynamicIXbardynamic_config
 
bool enable_action_data_enable = false
 
bool enable_action_instruction_enable = false
 
std::vector< NextTablesextra_next_lut
 
std::unique_ptr< Formatformat
 
gress_t gress
 
std::vector< HashDistributionhash_dist
 
std::vector< NextTableshit_next
 
std::vector< std::unique_ptr< InputXbar > > input_xbar
 
Call instruction
 
std::vector< Layoutlayout
 
int lineno = -1
 
int logical_id = -1
 
std::map< int, NextTableslong_branch
 
int long_branch_input = -1
 
NextTables miss_next
 
std::string name_
 
unsigned next_table_adr_mask = 0U
 
bool no_vpns = false
 
p4_params p4_params_list
 
P4Tablep4_table = 0
 
bitvec physical_ids
 
std::map< Table *, std::set< Actions::Action * > > pred
 
bitvec reachable_tables_
 
Stagestage = 0
 
virtual void mau_regs int type
 
int uid
 
virtual void write_merge_regs
 

Static Public Attributes

static std::map< std::string, Table * > * all
 
static std::vector< Table * > * by_uid
 

Protected Member Functions

 Table (const Table &)=delete
 
 Table (int line, std::string &&n, gress_t gr, Stage *s, int lid=-1)
 
 Table (Table &&)=delete
 
void alloc_busses (BFN::Alloc2Dbase< Table * > &bus_use, Layout::bus_type_t bus_type)
 
void alloc_global_bus (Layout &, Layout::bus_type_t, int, int, int, int)
 
virtual void alloc_global_busses ()
 
void alloc_global_srams ()
 
void alloc_global_tcams ()
 
void alloc_id (const char *idname, int &id, int &next_id, int max_id, bool order, BFN::Alloc1Dbase< Table * > &use)
 
void alloc_maprams ()
 
void alloc_rams (bool logical, BFN::Alloc2Dbase< Table * > &use, BFN::Alloc2Dbase< Table * > *bus_use=0, Layout::bus_type_t bus_type=Layout::SEARCH_BUS)
 
virtual void alloc_vpns ()
 
virtual void common_init_setup (const VECTOR(pair_t) &, bool, P4Table::type)
 
virtual bool common_setup (pair_t &, const VECTOR(pair_t) &, P4Table::type)
 
virtual Layout::bus_type_t default_bus_type () const
 
virtual int get_start_vpn ()
 
void need_bus (int lineno, BFN::Alloc1Dbase< Table * > &use, int idx, const char *name)
 
virtual void setup (VECTOR(pair_t) &data)=0
 
void setup_actions (value_t &)
 
void setup_context_json (value_t &)
 
void setup_layout (std::vector< Layout > &, const VECTOR(pair_t) &data, const char *subname="")
 
int setup_layout_attrib (std::vector< Layout > &, const value_t &data, const char *what, int Layout::*attr)
 
int setup_layout_bus_attrib (std::vector< Layout > &, const value_t &data, const char *what, Layout::bus_type_t type)
 
void setup_logical_id ()
 
void setup_maprams (value_t &)
 
void setup_vpns (std::vector< Layout > &, VECTOR(value_t) *, bool allow_holes=false)
 
virtual void vpn_params (int &width, int &depth, int &period, const char *&period_name) const
 

Static Protected Member Functions

static bool allow_ram_sharing (const Table *t1, const Table *t2)
 

Friends

std::ostream & operator<< (std::ostream &out, const p4_param &p)
 

Member Function Documentation

◆ add_field_to_pack_format()

void Table::add_field_to_pack_format ( json::vector & field_list,
unsigned basebit,
std::string name,
const Table::Format::Field & field,
const Table::Actions::Action * act ) const
virtual

Adds a field into the format of either a match or action table. Honestly, this is used for both action data tables and match tables, and this should be split up into two separate functions, as the corner casing for these different cases can be quite different and lead to some significant confusion

◆ add_pack_format()

json::map & Table::add_pack_format ( json::map & stage_tbl,
Table::Format * format,
bool pad_zeros = true,
bool print_fields = true,
Table::Actions::Action * act = nullptr ) const

Entry number has to be unique for all tables. However, for ATCAM tables specifically, the entry with the highest priority starts at entry number 0. The priority decreases as the entry number increases.

This is actually reversed in the hardware. The compiler format entries are in priority order in the hardware, and have been validated in validate_format. Thus, the context JSON is reversed.

◆ add_reference_table()

void Table::add_reference_table ( json::vector & table_refs,
const Table::Call & c ) const
virtual

One can no longer use whether the table is directly or indirectly addressed on whether a table is referenced that way. This is due to the corner case on hash action tables For a hash action table, an attached table that was previously directly addressed is now addressed by hash. However, for the driver, the driver must know which tables used to be directly addressed vs. an attached table that is addressed by a hash based index.

Thus, for those corner cases, a how_referenced in the p4 tag of the attached table is currently provided. Really for an attached table in hardware, it has no sense of how the table is addressed, as it only receives an address, so if somehow two tables, where one was direct while another was indirect (which is theoretically supportable if a hash action direct counter is shared), would break this parameter.

However, for the moment, there are no realistic attached table not either directly or indirectly referenced

If we need to change this, this was the delineation for how this was determined in match tables:

In the call for both of these examples, the address field is a hash_dist object, as this is necessary for the set up of the address. This call, unlike every other type table, cannot be the place where the address is determined.

Instead, the attached calls in the action is how the assembler can delineate whether the reference table is direct or indirect. If the address argument is $DIRECT, then the direct table has been converted to a hash, however if the argument is $hash_dist, then the original call was from a hash-based index, and is indirect

◆ allow_bus_sharing()

bool Table::allow_bus_sharing ( Table * t1,
Table * t2 )
static

check two tables to see if they can share action bus Two ATCAM tables or their action tables can occur in the same stage and share bytes on the action bus which is valid as they are always mutually exclusive

◆ allow_ram_sharing()

bool Table::allow_ram_sharing ( const Table * t1,
const Table * t2 )
staticprotected

check two tables to see if they can share ram. FIXME – for now we just allow a STATEFUL and a SELECTION to share – we should FIXME – check to make sure they're mutually exclusive and use the memory in FIXME – a compatible way

◆ get_cjson_source()

void Table::get_cjson_source ( const std::string & field_name,
std::string & source,
int & start_bit ) const

Determines both the start bit and the source name in the context JSON node for a particular field. Do not like string matching, and this should potentially be determined by looking through a list of fields, but this will work in the short term

◆ validate_instruction()

bool Table::validate_instruction ( Table::Call & call) const

Guarantees that the instruction call provided to the table has valid entries, and that if multiple choices are required, the compiler can make that choices.

The instruction address is a two piece address. The first argument is the address bits location. The second argument is a per flow enable bit location. These are both required. Additionally, the keyword $DEFAULT means that that particular portion of the address comes from the default register.

FIXME – this code is a messy hack – various target-specific special cases. Should try to figure out a better way to organize this.