P4C
The P4 Compiler
|
Public Types | |
using | InjectPoints = safe_vector<std::pair<const IR::Node *, const IR::Node *>> |
using | Path = safe_vector<const IR::Node *> |
using | TablePathways = ordered_map<const IR::MAU::Table *, safe_vector<Path>> |
Public Types inherited from P4::Visitor | |
typedef Visitor_Context | Context |
Public Member Functions | |
const IR::MAU::Table * | find_dominator (const IR::MAU::Table *init) const |
InjectPoints | get_inject_points (const IR::MAU::Table *a, const IR::MAU::Table *b, bool tbls_only=true) const |
void | print_paths (safe_vector< Path > &paths) const |
Public Member Functions inherited from P4::Inspector | |
const IR::Node * | apply_visitor (const IR::Node *, const char *name=0) override |
profile_t | init_apply (const IR::Node *root) override |
virtual void | loop_revisit (const IR::Node *) |
virtual void | postorder (const IR::Node *) |
virtual bool | preorder (const IR::Node *) |
virtual void | revisit (const IR::Node *) |
void | revisit_visited () |
bool | visit_in_progress (const IR::Node *n) const |
void | visitAgain () const override |
void | visitOnce () const override |
Public Member Functions inherited from P4::Visitor | |
virtual bool | check_global (cstring) |
virtual void | clear_globals () |
virtual Visitor * | clone () const |
virtual ControlFlowVisitor * | controlFlowVisitor () |
virtual void | end_apply () |
virtual void | end_apply (const IR::Node *root) |
virtual void | erase_global (cstring) |
template<class T > | |
const T * | findContext () const |
template<class T > | |
const T * | findContext (const Context *&c) const |
template<class T > | |
const T * | findOrigCtxt () const |
template<class T > | |
const T * | findOrigCtxt (const Context *&c) const |
virtual Visitor & | flow_clone () |
virtual void | flow_merge (Visitor &) |
virtual bool | flow_merge_closure (Visitor &) |
virtual void | flow_merge_global_from (cstring) |
virtual void | flow_merge_global_to (cstring) |
const Context * | getChildContext () const |
int | getChildrenVisited () const |
const Context * | getContext () const |
int | getContextDepth () const |
const IR::Node * | getCurrentNode () const |
template<class T > | |
const T * | getCurrentNode () const |
const IR::Node * | getOriginal () const |
template<class T > | |
const T * | getOriginal () const |
template<class T > | |
const T * | getParent () const |
virtual bool | has_flow_joins () const |
profile_t | init_apply (const IR::Node *root, const Context *parent_context) |
bool | isInContext (const IR::Node *n) const |
virtual const char * | name () const |
template<class T > | |
void | parallel_visit (const IR::Vector< T > &v, const char *name, int cidx) |
template<class T > | |
void | parallel_visit (const IR::Vector< T > &v, const char *name=0) |
template<class T > | |
void | parallel_visit (IR::Vector< T > &v, const char *name, int cidx) |
template<class T > | |
void | parallel_visit (IR::Vector< T > &v, const char *name=0) |
void | print_context () const |
const Visitor & | setCalledBy (const Visitor *visitor) |
void | setName (const char *name) |
void | visit (const IR::Node &n, const char *name, int cidx) |
void | visit (const IR::Node &n, const char *name=0) |
void | visit (const IR::Node *&n, const char *name, int cidx) |
void | visit (const IR::Node *&n, const char *name=0) |
void | visit (const IR::Node *const &n, const char *name, int cidx) |
void | visit (const IR::Node *const &n, const char *name=0) |
void | visit (IR::Node &n, const char *name, int cidx) |
void | visit (IR::Node &n, const char *name=0) |
void | visit (IR::Node *&, const char *=0, int=0) |
template<class T , typename = std::enable_if_t<Util::has_SourceInfo_v<T> && !std::is_pointer_v<T>>, class... Args> | |
void | warn (const int kind, const char *format, const T &node, Args &&...args) |
The const ref variant of the above. | |
template<class T , typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args> | |
void | warn (const int kind, const char *format, const T *node, Args &&...args) |
bool | warning_enabled (int warning_kind) const |
Public Attributes | |
TablePathways | table_pathways |
Public Attributes inherited from P4::Visitor | |
const Visitor * | called_by = nullptr |
cstring | internalName |
SplitFlowVisit_base *& | split_link |
SplitFlowVisit_base * | split_link_mem = nullptr |
Additional Inherited Members | |
Static Public Member Functions inherited from P4::Visitor | |
static cstring | demangle (const char *) |
static bool | warning_enabled (const Visitor *visitor, int warning_kind) |
Protected Member Functions inherited from P4::Visitor | |
virtual void | init_join_flows (const IR::Node *) |
virtual bool | join_flows (const IR::Node *) |
virtual void | post_join_flows (const IR::Node *, const IR::Node *) |
void | visit_children (const IR::Node *, std::function< void()> fn) |
Protected Attributes inherited from P4::Visitor | |
bool | dontForwardChildrenBeforePreorder = false |
bool | joinFlows = false |
bool | visitDagOnce = true |
const IR::MAU::Table * ControlPathwaysToTable::find_dominator | ( | const IR::MAU::Table * | init | ) | const |
The purpose of this pass is to determine the dominator of a IR::MAU::Table object within the IR graph. If a table is applied multiple times, in accordance with the rules of the IR, due to the mutually exclusion rules of the tables, a table is only applied once per packet. This means something like the following:
if (condition) { ... match_table.apply(); ... } else { ... match_table.apply(); ... }
In this case, the condition is the dominator. The same can be done for applications of tables in either hitting or missing, or an action_chain:
if (t1.apply().hit) || if (t1.apply().miss) || switch(t1.apply().action_run)
Currently, the use of a table will only be able to know if each apply of a Table is mutually exclusive because it is entirely under some dominating table application, i.e.
switch (t1.apply().action_run) { a1 : { t2.apply(); t3.apply(); default { t3.apply(); } }
Table t3's applies are mutually exclusive, and always has a Table dominator, table t1. The following apply statement for example, is not supported.
if (x == 0) t1.apply(); ... (no change to x) if (x != 0) t1.apply();
In this technical mutual exclusion, the find_dominator would not be able to return a table. At that point, this function might have to change in order to capture this kind of dominator
ControlPathwaysToTable::InjectPoints ControlPathwaysToTable::get_inject_points | ( | const IR::MAU::Table * | a, |
const IR::MAU::Table * | b, | ||
bool | tbls_only = true ) const |
This function walks up all possible control pathways from a table to the top of the pipe. The point in which two pathways differ is the point where next tables have to propagate through in Tofino.
The propagation point is let's say table A and table B are in the same table sequence, i.e.
apply { switch (A.apply().action_run) { ... (let's say C is here) } switch (B.apply().action_run) { ... (let's say D is here) } }
Now due to the limitations of next table in Tofino, when A is placed, everything directly control dependent on A must also be placed before B can be placed. This is in order to pass the next table pointer through the tables. Thus if anything in A's control dominating set has either an ANTI or DATA dependency on anything in B's control dominating set, then A and it's control dependent set must logical be placed before B's.
The goal for this function is when comparing two tables, i.e. C and D, to return to the point where this inherent next table propagation is found.
TablePathways ControlPathwaysToTable::table_pathways |
Maps each table T to a list of possible control paths from T out to the top-level of the pipe.