33 virtual bool match(
const IR::Node *) = 0;
35 Pattern(Base *p) : pattern(p) {}
38 class MatchExt :
public Base {
42 bool match(
const IR::Node *n)
override {
return (m = n->
to<T>()); }
43 MatchExt(
const T *&m) : m(m) {}
46 class Const :
public Base {
50 bool match(
const IR::Node *n)
override {
51 if (
auto k = n->
to<IR::Constant>())
return k->value == value;
54 Const(big_int v) : value(v) {}
55 Const(
int v) : value(v) {}
58 class Unary :
public Base {
62 bool match(
const IR::Node *n)
override {
63 if (
auto b = n->
to<T>())
return expr->match(b->expr);
66 Unary(Base *e) : expr(e) {}
69 class Binary :
public Base {
74 bool match(
const IR::Node *n)
override {
75 if (
auto b = n->
to<T>()) {
76 if (left->match(b->left) && right->match(b->right))
return true;
77 if (commutative && left->match(b->right) && right->match(b->left))
return true;
81 Binary(Base *l, Base *r,
bool commute =
false) : left(l), right(r), commutative(commute) {}
90 bool match(
const IR::Node *n)
override {
return (m = n->
to<T>()); }
91 Match() : m(
nullptr) {}
92 const T *operator->()
const {
return m; }
93 operator const T *()
const {
return m; }
121 Pattern(
const T *&m) : pattern(new MatchExt<T>(m)) {}
123 Pattern(Match<T> &m) : pattern(&m) {}
124 explicit Pattern(big_int v) : pattern(new Const(v)) {}
125 explicit Pattern(
int v) : pattern(new Const(v)) {}
126 Pattern operator-()
const {
return Pattern(
new Unary<IR::Neg>(pattern)); }
127 Pattern operator~()
const {
return Pattern(
new Unary<IR::Cmpl>(pattern)); }
128 Pattern operator!()
const {
return Pattern(
new Unary<IR::LNot>(pattern)); }
129 Pattern operator*(
const Pattern &r)
const {
130 return Pattern(
new Binary<IR::Mul>(pattern, r.pattern,
true));
132 Pattern operator/(
const Pattern &r)
const {
133 return Pattern(
new Binary<IR::Div>(pattern, r.pattern));
135 Pattern operator%(
const Pattern &r)
const {
136 return Pattern(
new Binary<IR::Mod>(pattern, r.pattern));
138 Pattern operator+(
const Pattern &r)
const {
139 return Pattern(
new Binary<IR::Add>(pattern, r.pattern,
true));
141 Pattern operator-(
const Pattern &r)
const {
142 return Pattern(
new Binary<IR::Sub>(pattern, r.pattern));
144 Pattern operator<<(
const Pattern &r)
const {
145 return Pattern(
new Binary<IR::Shl>(pattern, r.pattern));
147 Pattern operator>>(
const Pattern &r)
const {
148 return Pattern(
new Binary<IR::Shr>(pattern, r.pattern));
150 Pattern operator==(
const Pattern &r)
const {
151 return Pattern(
new Binary<IR::Equ>(pattern, r.pattern,
true));
153 Pattern operator!=(
const Pattern &r)
const {
154 return Pattern(
new Binary<IR::Neq>(pattern, r.pattern,
true));
156 Pattern operator<(
const Pattern &r)
const {
157 return Pattern(
new Binary<IR::Lss>(pattern, r.pattern));
159 Pattern operator<=(
const Pattern &r)
const {
160 return Pattern(
new Binary<IR::Leq>(pattern, r.pattern));
162 Pattern operator>(
const Pattern &r)
const {
163 return Pattern(
new Binary<IR::Grt>(pattern, r.pattern));
165 Pattern operator>=(
const Pattern &r)
const {
166 return Pattern(
new Binary<IR::Geq>(pattern, r.pattern));
168 Pattern Relation(
const Pattern &r)
const {
169 return Pattern(
new Binary<IR::Operation::Relation>(pattern, r.pattern,
true));
171 Pattern operator&(
const Pattern &r)
const {
172 return Pattern(
new Binary<IR::BAnd>(pattern, r.pattern,
true));
174 Pattern operator|(
const Pattern &r)
const {
175 return Pattern(
new Binary<IR::BOr>(pattern, r.pattern,
true));
177 Pattern operator^(
const Pattern &r)
const {
178 return Pattern(
new Binary<IR::BXor>(pattern, r.pattern,
true));
180 Pattern operator&&(
const Pattern &r)
const {
181 return Pattern(
new Binary<IR::LAnd>(pattern, r.pattern));
183 Pattern operator||(
const Pattern &r)
const {
184 return Pattern(
new Binary<IR::LOr>(pattern, r.pattern));
187 bool match(
const IR::Node *n) {
return pattern->match(n); }
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
std::pair< HalfOpenRange< Unit, Order >, HalfOpenRange< Unit, Order > > operator-(HalfOpenRange< Unit, Order > left, HalfOpenRange< Unit, Order > right)
Definition lib/bitrange.h:716