PandA-2024.02
Range.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
43 #ifndef RANGE_HPP
44 #define RANGE_HPP
45 
46 #include "APInt.hpp"
47 #include "bit_lattice.hpp"
48 #include "refcount.hpp"
49 #include "tree_common.hpp"
50 
53 
55 {
61 };
62 
63 class Range
64 {
65  public:
66  using bw_t = APInt::bw_t;
67 
68  private:
77 
78  void normalizeRange(const APInt& lb, const APInt& ub, RangeType rType);
79 
80  public:
81  Range(RangeType type, bw_t bw);
82  Range(RangeType rType, bw_t bw, const APInt& lb, const APInt& ub);
83  virtual ~Range() = default;
84  Range(const Range& other) = default;
85  Range(Range&&) = default;
86  Range& operator=(const Range& other) = default;
87  Range& operator=(Range&&) = default;
88  bw_t getBitWidth() const;
89  const APInt& getLower() const;
90  const APInt& getUpper() const;
91  APInt getSignedMax() const;
92  APInt getSignedMin() const;
93  APInt getUnsignedMax() const;
94  APInt getUnsignedMin() const;
95  APInt getSpan() const;
96  virtual std::deque<bit_lattice> getBitValues(bool isSigned) const;
97  virtual RangeRef getAnti() const;
98 
99  virtual bool isUnknown() const;
100  virtual void setUnknown();
101  bool isRegular() const;
102  bool isAnti() const;
103  virtual bool isEmpty() const;
104  virtual bool isReal() const;
105  bool operator==(const Range& other) const = delete;
106  bool operator!=(const Range& other) const = delete;
107  bool isSameType(const RangeConstRef& other) const;
108  virtual bool isSameRange(const RangeConstRef& other) const;
109  virtual bool isFullSet() const;
110  virtual bool isSingleElement() const;
111  virtual bool isConstant() const;
112  virtual Range* clone() const;
113  virtual void print(std::ostream& OS) const;
114  std::string ToString() const;
115 
116  /* Arithmetic operations */
117  RangeRef add(const RangeConstRef& other) const;
118  RangeRef sat_add(const RangeConstRef& other) const;
119  RangeRef usat_add(const RangeConstRef& other) const;
120  RangeRef sub(const RangeConstRef& other) const;
121  RangeRef sat_sub(const RangeConstRef& other) const;
122  RangeRef usat_sub(const RangeConstRef& other) const;
123  RangeRef mul(const RangeConstRef& other) const;
124  RangeRef udiv(const RangeConstRef& other) const;
125  RangeRef sdiv(const RangeConstRef& other) const;
126  RangeRef urem(const RangeConstRef& other) const;
127  RangeRef srem(const RangeConstRef& other) const;
128  RangeRef shl(const RangeConstRef& other) const;
129  RangeRef shr(const RangeConstRef& other, bool sign) const;
130  virtual RangeRef abs() const;
131  virtual RangeRef negate() const;
132 
133  /* Bitwise operations */
134  RangeRef Not() const;
135  RangeRef And(const RangeConstRef& other) const;
136  RangeRef Or(const RangeConstRef& other) const;
137  RangeRef Xor(const RangeConstRef& other) const;
138 
139  /* Comparators */
140  virtual RangeRef Eq(const RangeConstRef& other, bw_t bw) const;
141  virtual RangeRef Ne(const RangeConstRef& other, bw_t bw) const;
142  RangeRef Ugt(const RangeConstRef& other, bw_t bw) const;
143  RangeRef Uge(const RangeConstRef& other, bw_t bw) const;
144  RangeRef Ult(const RangeConstRef& other, bw_t bw) const;
145  RangeRef Ule(const RangeConstRef& other, bw_t bw) const;
146  RangeRef UMin(const RangeConstRef& other) const;
147  RangeRef UMax(const RangeConstRef& other) const;
148  RangeRef Sgt(const RangeConstRef& other, bw_t bw) const;
149  RangeRef Sge(const RangeConstRef& other, bw_t bw) const;
150  RangeRef Slt(const RangeConstRef& other, bw_t bw) const;
151  RangeRef Sle(const RangeConstRef& other, bw_t bw) const;
152  RangeRef SMin(const RangeConstRef& other) const;
153  RangeRef SMax(const RangeConstRef& other) const;
154 
155  RangeRef sextOrTrunc(bw_t bitwidth) const;
156  RangeRef zextOrTrunc(bw_t bitwidth) const;
157  RangeRef truncate(bw_t bitwidth) const;
158  virtual RangeRef intersectWith(const RangeConstRef& other) const;
159  virtual RangeRef unionWith(const RangeConstRef& other) const;
160 
161  static const bw_t max_digits;
162  static const APInt Min;
163  static const APInt Max;
164  static const APInt MinDelta;
165  static RangeRef makeSatisfyingCmpRegion(kind pred, const RangeConstRef& Other);
166  static bw_t neededBits(const APInt& a, const APInt& b, bool sign);
167  static RangeRef fromBitValues(const std::deque<bit_lattice>& bv, bw_t bitwidth, bool isSigned);
168 };
169 
170 std::ostream& operator<<(std::ostream& OS, const Range& R);
171 
172 class RealRange : public Range
173 {
174  private:
175  RangeRef sign;
176  RangeRef exponent;
177  RangeRef significand;
178 
179  public:
180  RealRange(const Range& s, const Range& e, const Range& f);
181  RealRange(const RangeConstRef& s, const RangeConstRef& e, const RangeConstRef& f);
182  explicit RealRange(const RangeConstRef& vc);
183  ~RealRange() override = default;
184  RealRange(const RealRange& other) = default;
185  RealRange(RealRange&&) = default;
186  RealRange& operator=(const RealRange& other) = default;
187  RealRange& operator=(RealRange&&) = default;
188  RangeRef getRange() const;
189 
190  RangeRef getSign() const;
191  RangeRef getExponent() const;
192  RangeRef getSignificand() const;
193  std::deque<bit_lattice> getBitValues(bool) const override;
194  RangeRef getAnti() const override;
195  void setSign(const RangeConstRef& s);
196  void setExponent(const RangeConstRef& e);
197  void setSignificand(const RangeConstRef& f);
198  bool isSameRange(const RangeConstRef& other) const override;
199  bool isFullSet() const override;
200  bool isUnknown() const override;
201  void setUnknown() override;
202  bool isSingleElement() const override;
203  bool isConstant() const override;
204  bool isEmpty() const override;
205  bool isReal() const override;
206  Range* clone() const override;
207  void print(std::ostream& OS) const override;
208 
209  RangeRef abs() const override;
210  RangeRef negate() const override;
211 
212  RangeRef Eq(const RangeConstRef& other, bw_t bw) const override;
213  RangeRef Ne(const RangeConstRef& other, bw_t bw) const override;
214 
215  RangeRef intersectWith(const RangeConstRef& other) const override;
216  RangeRef unionWith(const RangeConstRef& other) const override;
217  RangeRef toFloat64() const;
218  RangeRef toFloat32() const;
219 
220  static refcount<RealRange> fromBitValues(const std::deque<bit_lattice>& bv);
221 };
222 
223 #endif
virtual bool isSameRange(const RangeConstRef &other) const
Definition: Range.cpp:612
Definition: Range.hpp:56
RangeRef zextOrTrunc(bw_t bitwidth) const
Definition: Range.cpp:2209
RangeRef srem(const RangeConstRef &other) const
Definition: Range.cpp:1229
APInt l
The lower bound of the range.
Definition: Range.hpp:70
virtual void print(std::ostream &OS) const
Definition: Range.cpp:2464
virtual bool isConstant() const
Definition: Range.cpp:636
APInt getSignedMin() const
Definition: Range.cpp:521
RangeRef significand
Definition: Range.hpp:177
RangeRef Ugt(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1770
RangeRef usat_add(const RangeConstRef &other) const
Definition: Range.cpp:770
virtual ~Range()=default
APInt getSignedMax() const
Definition: Range.cpp:509
#define R
Definition: mips.c:40
RangeRef Sgt(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1874
virtual bool isFullSet() const
Definition: Range.cpp:617
RangeRef SMax(const RangeConstRef &other) const
Definition: Range.cpp:1998
virtual RangeRef negate() const
Definition: Range.cpp:2108
std::string ToString() const
Definition: Range.cpp:2516
const APInt & getUpper() const
Definition: Range.cpp:502
bool isSameType(const RangeConstRef &other) const
Definition: Range.cpp:607
RangeRef shl(const RangeConstRef &other) const
Definition: Range.cpp:1266
APInt::bw_t bw_t
Definition: Range.hpp:66
static const APInt MinDelta
Definition: Range.hpp:164
RangeRef add(const RangeConstRef &other) const
Definition: Range.cpp:652
Definition: Range.hpp:63
APInt u
The upper bound of the range.
Definition: Range.hpp:72
RangeRef sign
Definition: Range.hpp:175
RangeRef Xor(const RangeConstRef &other) const
Definition: Range.cpp:1658
CONSTREF_FORWARD_DECL(Range)
RangeRef Ult(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1822
static const APInt Max
Definition: Range.hpp:163
std::ostream & operator<<(std::ostream &OS, const Range &R)
Definition: Range.cpp:2523
APInt getSpan() const
Definition: Range.cpp:557
bool isRegular() const
Definition: Range.cpp:587
RangeRef Not() const
Definition: Range.cpp:1685
RangeRef exponent
Definition: Range.hpp:176
RangeRef And(const RangeConstRef &other) const
Definition: Range.cpp:1635
virtual bool isUnknown() const
Definition: Range.cpp:577
virtual RangeRef abs() const
Definition: Range.cpp:2058
This C++ header file contains common macros for the tree structure.
static RangeRef makeSatisfyingCmpRegion(kind pred, const RangeConstRef &Other)
Definition: Range.cpp:2529
virtual bool isSingleElement() const
Definition: Range.cpp:627
RangeRef udiv(const RangeConstRef &other) const
Definition: Range.cpp:1057
void normalizeRange(const APInt &lb, const APInt &ub, RangeType rType)
Definition: Range.cpp:93
RangeRef sub(const RangeConstRef &other) const
Definition: Range.cpp:819
static const bw_t max_digits
Definition: Range.hpp:161
bw_t getBitWidth() const
Definition: Range.cpp:490
kind
APInt getUnsignedMin() const
Definition: Range.cpp:546
virtual void setUnknown()
Definition: Range.cpp:582
RangeRef mul(const RangeConstRef &other) const
Definition: Range.cpp:1013
RangeRef Sge(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1900
bool operator==(const Range &other) const =delete
uint16_t bw_t
Definition: APInt.hpp:59
RangeRef Or(const RangeConstRef &other) const
Definition: Range.cpp:1612
bw_t bw
the range bit-width
Definition: Range.hpp:74
bool operator!=(const Range &other) const =delete
virtual RangeRef intersectWith(const RangeConstRef &other) const
Definition: Range.cpp:2242
RangeType type
the range type
Definition: Range.hpp:76
Template definition of refcount.
RangeRef truncate(bw_t bitwidth) const
Definition: Range.cpp:2125
Definition: APInt.hpp:53
RangeRef sextOrTrunc(bw_t bitwidth) const
Definition: Range.cpp:2181
bool isAnti() const
Definition: Range.cpp:592
REF_FORWARD_DECL(Range)
RangeRef UMin(const RangeConstRef &other) const
Definition: Range.cpp:2018
RangeRef shr(const RangeConstRef &other, bool sign) const
Definition: Range.cpp:1319
virtual RangeRef Eq(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1699
RangeRef Uge(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1796
RangeRef SMin(const RangeConstRef &other) const
Definition: Range.cpp:1978
Range(RangeType type, bw_t bw)
Definition: Range.cpp:77
Definition: Range.hpp:60
APInt getUnsignedMax() const
Definition: Range.cpp:533
virtual RangeRef unionWith(const RangeConstRef &other) const
Definition: Range.cpp:2356
RangeRef Slt(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1926
static bw_t neededBits(const APInt &a, const APInt &b, bool sign)
Definition: Range.cpp:360
RangeRef UMax(const RangeConstRef &other) const
Definition: Range.cpp:2038
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
RangeRef usat_sub(const RangeConstRef &other) const
Definition: Range.cpp:954
RangeRef urem(const RangeConstRef &other) const
Definition: Range.cpp:1177
const APInt & getLower() const
Definition: Range.cpp:495
RangeRef Ule(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1848
RangeRef sat_sub(const RangeConstRef &other) const
Definition: Range.cpp:889
RangeRef Sle(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1952
virtual bool isEmpty() const
Definition: Range.cpp:597
Definition: Range.hpp:59
static const APInt Min
Definition: Range.hpp:162
uint32_t sign
RangeType
Definition: Range.hpp:54
virtual RangeRef Ne(const RangeConstRef &other, bw_t bw) const
Definition: Range.cpp:1735
static RangeRef fromBitValues(const std::deque< bit_lattice > &bv, bw_t bitwidth, bool isSigned)
Definition: Range.cpp:365
virtual bool isReal() const
Definition: Range.cpp:602
virtual RangeRef getAnti() const
Definition: Range.cpp:464
Range & operator=(const Range &other)=default
RangeRef sdiv(const RangeConstRef &other) const
Definition: Range.cpp:1091
virtual Range * clone() const
Definition: Range.cpp:88
virtual std::deque< bit_lattice > getBitValues(bool isSigned) const
Definition: Range.cpp:420
RangeRef sat_add(const RangeConstRef &other) const
Definition: Range.cpp:701

Generated on Mon Feb 12 2024 13:02:52 for PandA-2024.02 by doxygen 1.8.13