P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::DoStrengthReduction Class Referencefinal

#include <strengthReduction.h>

Inheritance diagram for P4::DoStrengthReduction:
[legend]

Public Member Functions

 DoStrengthReduction (bool enableSubConstToAddTransform)
 
const IR::Nodepostorder (IR::Add *expr) override
 
const IR::Nodepostorder (IR::ArrayIndex *expr) override
 
const IR::Nodepostorder (IR::BAnd *expr) override
 
const IR::Nodepostorder (IR::BOr *expr) override
 
const IR::Nodepostorder (IR::BXor *expr) override
 
const IR::Nodepostorder (IR::Cmpl *expr) override
 
const IR::Nodepostorder (IR::Concat *expr) override
 
const IR::Nodepostorder (IR::Div *expr) override
 
const IR::Nodepostorder (IR::Equ *expr) override
 
const IR::Nodepostorder (IR::LAnd *expr) override
 
const IR::Nodepostorder (IR::LNot *expr) override
 
const IR::Nodepostorder (IR::LOr *expr) override
 
const IR::Nodepostorder (IR::Mask *expr) override
 
const IR::Nodepostorder (IR::Mod *expr) override
 
const IR::Nodepostorder (IR::Mul *expr) override
 
const IR::Nodepostorder (IR::Mux *expr) override
 
const IR::Nodepostorder (IR::Neq *expr) override
 
virtual const IR::Nodepostorder (IR::Node *n)
 
const IR::Nodepostorder (IR::Range *expr) override
 
const IR::Nodepostorder (IR::Shl *expr) override
 
const IR::Nodepostorder (IR::Shr *expr) override
 
const IR::Nodepostorder (IR::Slice *expr) override
 
const IR::Nodepostorder (IR::Sub *expr) override
 
const IR::Nodepostorder (IR::UPlus *expr) override
 
const IR::BlockStatement * preorder (IR::BlockStatement *bs) override
 
- Public Member Functions inherited from P4::Transform
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 const IR::Nodepreorder (IR::Node *n)
 
void prune ()
 
virtual void revisit (const IR::Node *, const IR::Node *)
 
void revisit_visited ()
 
bool visit_in_progress (const IR::Node *) 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 Visitorclone () const
 
virtual ControlFlowVisitorcontrolFlowVisitor ()
 
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 Visitorflow_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 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
 
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 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
 

Protected Member Functions

bool hasSideEffects (const IR::Expression *expr) const
 
bool isAllOnes (const IR::Expression *expr) const
 
bool isFalse (const IR::Expression *expr) const
 
bool isOne (const IR::Expression *expr) const
 
int isPowerOf2 (const IR::Expression *expr) const
 
bool isTrue (const IR::Expression *expr) const
 
bool isZero (const IR::Expression *expr) const
 
- Protected Member Functions inherited from P4::Transform
const IR::Nodetransform_child (const IR::Node *child)
 
- 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

bool enableSubConstToAddTransform = true
 
- Protected Attributes inherited from P4::Transform
bool forceClone = false
 
- Protected Attributes inherited from P4::Visitor
bool dontForwardChildrenBeforePreorder = false
 
bool joinFlows = false
 
bool visitDagOnce = true
 

Additional Inherited Members

- Public Types inherited from P4::Visitor
typedef Visitor_Context Context
 
- 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
 

Detailed Description

Implements a pass that replaces expensive arithmetic and boolean operations with cheaper ones – i.e., strength reduction

Specifically, it provides:

  1. A collection of helper methods that determine whether a given expression is 0, 1, true, or false, or a power of 2
  2. A visitor that transforms arithmetic and boolean expressions
Precondition
: None
Postcondition
: Ensure that
  • most arithmetic and boolean expressions are simplified
  • division and modulus by 0

Member Function Documentation

◆ hasSideEffects()

bool P4::DoStrengthReduction::hasSideEffects ( const IR::Expression * expr) const
inlineprotected

Used to determine conservatively if an expression has side-effects. If we had a refMap or a typeMap we could use them here.

◆ isAllOnes()

bool P4::DoStrengthReduction::isAllOnes ( const IR::Expression * expr) const
protected
Returns
true if expr is all ones.

◆ isFalse()

bool P4::DoStrengthReduction::isFalse ( const IR::Expression * expr) const
protected
Returns
true if expr is the constant false.

◆ isOne()

bool P4::DoStrengthReduction::isOne ( const IR::Expression * expr) const
protected
Returns
true if expr is the constant 1.

methods

◆ isPowerOf2()

int P4::DoStrengthReduction::isPowerOf2 ( const IR::Expression * expr) const
protected
Returns
the logarithm (base 2) of expr if it is positive and a power of 2 and -1 otherwise.

◆ isTrue()

bool P4::DoStrengthReduction::isTrue ( const IR::Expression * expr) const
protected
Returns
true if expr is the constant true.

◆ isZero()

bool P4::DoStrengthReduction::isZero ( const IR::Expression * expr) const
protected
Returns
true if expr is the constant 0.

◆ postorder() [1/2]

const IR::Node * P4::DoStrengthReduction::postorder ( IR::Cmpl * expr)
override

Methods

◆ postorder() [2/2]

virtual const IR::Node * P4::Transform::postorder ( IR::Node * n)
inlinevirtual

Reimplemented from P4::Transform.

Member Data Documentation

◆ enableSubConstToAddTransform

bool P4::DoStrengthReduction::enableSubConstToAddTransform = true
protected

Enable the subtract constant to add negative constant transform. Replaces a - constant with a + (-constant).