17#ifndef P4_STRENGTHREDUCTION_H_
18#define P4_STRENGTHREDUCTION_H_
20#include "frontends/common/resolveReferences/referenceMap.h"
21#include "frontends/p4/sideEffects.h"
22#include "frontends/p4/typeChecking/typeChecker.h"
23#include "frontends/p4/typeMap.h"
28using namespace literals;
54 bool isOne(
const IR::Expression *expr)
const;
56 bool isZero(
const IR::Expression *expr)
const;
58 bool isTrue(
const IR::Expression *expr)
const;
60 bool isFalse(
const IR::Expression *expr)
const;
62 bool isAllOnes(
const IR::Expression *expr)
const;
65 int isPowerOf2(
const IR::Expression *expr)
const;
77 setName(
"StrengthReduction");
83 DoStrengthReduction();
86 using Transform::postorder;
88 const IR::Node *
postorder(IR::Cmpl *expr)
override;
89 const IR::Node *
postorder(IR::BAnd *expr)
override;
90 const IR::Node *
postorder(IR::BOr *expr)
override;
91 const IR::Node *
postorder(IR::Equ *expr)
override;
92 const IR::Node *
postorder(IR::Neq *expr)
override;
93 const IR::Node *
postorder(IR::BXor *expr)
override;
94 const IR::Node *
postorder(IR::LAnd *expr)
override;
95 const IR::Node *
postorder(IR::LOr *expr)
override;
96 const IR::Node *
postorder(IR::LNot *expr)
override;
97 const IR::Node *
postorder(IR::Sub *expr)
override;
98 const IR::Node *
postorder(IR::Add *expr)
override;
99 const IR::Node *
postorder(IR::UPlus *expr)
override;
100 const IR::Node *
postorder(IR::Shl *expr)
override;
101 const IR::Node *
postorder(IR::Shr *expr)
override;
102 const IR::Node *
postorder(IR::Mul *expr)
override;
103 const IR::Node *
postorder(IR::Div *expr)
override;
104 const IR::Node *
postorder(IR::Mod *expr)
override;
105 const IR::Node *
postorder(IR::Mux *expr)
override;
106 const IR::Node *
postorder(IR::Slice *expr)
override;
107 const IR::Node *
postorder(IR::PlusSlice *expr)
override;
108 const IR::Node *
postorder(IR::Mask *expr)
override;
109 const IR::Node *
postorder(IR::Range *expr)
override;
110 const IR::Node *
postorder(IR::Concat *expr)
override;
111 const IR::Node *
postorder(IR::ArrayIndex *expr)
override;
113 const IR::BlockStatement *preorder(IR::BlockStatement *bs)
override {
116 if (bs->hasAnnotation(IR::Annotation::disableOptimizationAnnotation)) prune();
124 bool enableSubConstToAddTransform =
true) {
125 if (typeMap !=
nullptr) {
126 if (!typeChecking) typeChecking =
new TypeChecking(
nullptr, typeMap,
true);
127 passes.push_back(typeChecking);
Definition strengthReduction.h:47
const IR::Node * postorder(IR::Cmpl *expr) override
Definition strengthReduction.cpp:71
bool isZero(const IR::Expression *expr) const
Definition strengthReduction.cpp:29
bool isFalse(const IR::Expression *expr) const
Definition strengthReduction.cpp:44
bool isAllOnes(const IR::Expression *expr) const
Definition strengthReduction.cpp:60
bool isTrue(const IR::Expression *expr) const
Definition strengthReduction.cpp:38
bool isOne(const IR::Expression *expr) const
Definition strengthReduction.cpp:23
bool hasSideEffects(const IR::Expression *expr) const
Definition strengthReduction.h:70
int isPowerOf2(const IR::Expression *expr) const
Definition strengthReduction.cpp:50
bool enableSubConstToAddTransform
Definition strengthReduction.h:51
Definition ir/pass_manager.h:40
static bool check(const IR::Expression *expression, const Visitor *calledBy, DeclarationLookup *refMap, TypeMap *typeMap, const Visitor::Context *ctxt=nullptr)
Definition sideEffects.h:106
Definition strengthReduction.h:121
Definition typeChecker.h:55
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24