P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::ComputeDefUse Class Reference

Compute defuse info within P4Parser and P4Control blocks in the midend. More...

#include <def_use.h>

Inheritance diagram for P4::ComputeDefUse:
[legend]

Classes

struct  loc_t
 
class  SetupJoinPoints
 

Public Types

typedef hvec_set< const loc_t * > locset_t
 
- Public Types inherited from P4::Visitor
typedef Visitor_Context Context
 

Public Member Functions

void clear ()
 
const locset_tgetDefs (const IR::Node *n) const
 
const locset_tgetUses (const IR::Node *n) const
 
- Public Member Functions inherited from P4::Inspector
const IR::Nodeapply_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 void end_apply (const IR::Node *root)
 
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 bool flow_merge_closure (Visitor &)
 
const ContextgetChildContext () const
 
int getChildrenVisited () const
 
const ContextgetContext () const
 
int getContextDepth () const
 
const IR::NodegetCurrentNode () const
 
template<class T >
const T * getCurrentNode () const
 
const IR::NodegetOriginal () const
 
template<class T >
const T * getOriginal () const
 
template<class T >
const T * getParent () 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 VisitorsetCalledBy (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 Member Functions inherited from P4::ControlFlowVisitor
bool check_global (cstring key) override
 
void clear_globals () override
 
ControlFlowVisitorcontrolFlowVisitor () override
 
void erase_global (cstring key) override
 
ControlFlowVisitorflow_clone () override
 
const flow_join_info_tflow_join_status (const IR::Node *n) const
 
void flow_merge_global_from (cstring key) override
 
void flow_merge_global_to (cstring key) override
 
bool has_flow_joins () const override
 
bool isUnreachable ()
 
bool operator!= (const ControlFlowVisitor &v) const
 
void restore_global (std::pair< cstring, ControlFlowVisitor * > saved)
 
std::pair< cstring, ControlFlowVisitor * > save_global (cstring key)
 
void setUnreachable ()
 
- Public Member Functions inherited from P4::P4WriteContext
bool isRead (bool root_value=false)
 
bool isWrite (bool root_value=false)
 
- Public Member Functions inherited from P4::ResolutionContext
const IR::IDeclarationgetDeclaration (const IR::Path *path, bool notNull=false) const
 
const IR::IDeclarationgetDeclaration (const IR::This *, bool notNull=false) const
 
auto getDeclarations (const IR::INamespace *ns) const
 Returns the set of decls that exist in the given namespace.
 
auto getDeclsByName (const IR::INamespace *ns, cstring name) const
 Returns the set of decls with the given name that exist in the given namespace.
 
std::vector< const IR::IDeclaration * > resolve (const IR::ID &name, ResolutionType type) const
 Resolve references for name, restricted to type declarations.
 
virtual const IR::IDeclarationresolvePath (const IR::Path *path, bool isType) const
 
const IR::Type * resolveType (const IR::Type *type) const
 Resolve a refrence to a type type.
 
const IR::IDeclarationresolveUnique (const IR::ID &name, ResolutionType type, const IR::INamespace *=nullptr) const
 Resolve reference for name, restricted to type declarations, and expect one result.
 
- Public Member Functions inherited from P4::DeclarationLookup

Friends

std::ostream & operator<< (std::ostream &out, const ComputeDefUse &cdu)
 
std::ostream & operator<< (std::ostream &out, const defuse_t &du)
 
std::ostream & operator<< (std::ostream &out, const loc_t &loc)
 

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)
 
- Public Attributes inherited from P4::Visitor
const Visitorcalled_by = nullptr
 
cstring internalName
 
SplitFlowVisit_base *& split_link
 
SplitFlowVisit_basesplit_link_mem = nullptr
 
- Protected Types inherited from P4::ControlFlowVisitor
typedef std::map< const IR::Node *, flow_join_info_tflow_join_points_t
 
- Protected Member Functions inherited from P4::Visitor
void visit_children (const IR::Node *, std::function< void()> fn)
 
- Protected Member Functions inherited from P4::ControlFlowVisitor
void init_join_flows (const IR::Node *root) override
 
bool join_flows (const IR::Node *n) override
 
void post_join_flows (const IR::Node *, const IR::Node *) override
 
- Protected Member Functions inherited from P4::ResolutionContext
 ResolutionContext (bool ao)
 
std::vector< const IR::IDeclaration * > lookup (const IR::INamespace *ns, const IR::ID &name, ResolutionType type) const
 
std::vector< const IR::IDeclaration * > lookupMatchKind (const IR::ID &name) const
 
const IR::Vector< IR::Argument > * methodArguments (cstring name) const
 We are resolving a method call. Find the arguments from the context.
 
- Protected Attributes inherited from P4::Visitor
bool dontForwardChildrenBeforePreorder = false
 
bool joinFlows = false
 
bool visitDagOnce = true
 
- Protected Attributes inherited from P4::ControlFlowVisitor
bool BackwardsCompatibleBroken = false
 
flow_join_points_t * flow_join_points = 0
 
bool unreachable = false
 
- Protected Attributes inherited from P4::ResolutionContext
bool anyOrder = false
 

Detailed Description

Compute defuse info within P4Parser and P4Control blocks in the midend.

This pass finds all uses and definitions of field/slice values in all controls and parsers in the program and stores maps of which defs reach which uses. After the pass runs, getDefs(use) will return all the definitions in the program that reach the argument use while getUses(def) will return all the uses of the given def. The returned values are sets of ComputeUseDef::loc_t objects which contain both the node that is def or use as well as the context path from the root of the IR to that node – actions that are used by mulitple tables or parser states reachable via multiple paths may have mulitple entries as a result

Precondition
Currently the code does not consider calls between controls or parsers, as it is expected to run after inlining when all such calls have been flattened. It could be extended to deal with the before inlining case.