LLVM: include/llvm/ADT/APSInt.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_ADT_APSINT_H
16#define LLVM_ADT_APSINT_H
17
20
21namespace llvm {
22
23
25 bool IsUnsigned = false;
26
27public:
28
30
31
34
37
38
39
40
41
42
43
44
46
47
48
49
51
52
53
54
56
57
58
59
60
61
62
64
70
76
77
78 bool isSigned() const { return !IsUnsigned; }
79 bool isUnsigned() const { return IsUnsigned; }
82
83
88
89
97
98
103
106 : std::nullopt;
107 }
108
112
114 if (IsUnsigned)
115 return APSInt(zext(width), IsUnsigned);
116 else
117 return APSInt(sext(width), IsUnsigned);
118 }
119
121 if (IsUnsigned)
123 else
125 }
126
128 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
129 if (IsUnsigned)
131 else
133 return *this;
134 }
136 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
137 if (IsUnsigned)
139 else
141 return *this;
142 }
144 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
146 }
148 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
150 }
151
156 if (IsUnsigned)
158 else
160 return *this;
161 }
166
168 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
170 }
172 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
174 }
176 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
178 }
180 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
182 }
184 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
186 }
188
207
208
209
210
212 return APSInt(static_cast<const APInt &>(*this) << Bits, IsUnsigned);
213 }
215 static_cast<APInt &>(*this) <<= Amt;
216 return *this;
217 }
222
224 ++(static_cast<APInt &>(*this));
225 return *this;
226 }
228 --(static_cast<APInt &>(*this));
229 return *this;
230 }
232 return APSInt(++static_cast<APInt &>(*this), IsUnsigned);
233 }
235 return APSInt(--static_cast<APInt &>(*this), IsUnsigned);
236 }
238 return APSInt(-static_cast<const APInt &>(*this), IsUnsigned);
239 }
241 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
242 static_cast<APInt &>(*this) += RHS;
243 return *this;
244 }
246 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
247 static_cast<APInt &>(*this) -= RHS;
248 return *this;
249 }
251 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
252 static_cast<APInt &>(*this) *= RHS;
253 return *this;
254 }
256 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
257 static_cast<APInt &>(*this) &= RHS;
258 return *this;
259 }
261 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
262 static_cast<APInt &>(*this) |= RHS;
263 return *this;
264 }
266 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
267 static_cast<APInt &>(*this) ^= RHS;
268 return *this;
269 }
270
272 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
273 return APSInt(static_cast<const APInt &>(*this) & RHS, IsUnsigned);
274 }
275
277 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
278 return APSInt(static_cast<const APInt &>(*this) | RHS, IsUnsigned);
279 }
280
282 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
283 return APSInt(static_cast<const APInt &>(*this) ^ RHS, IsUnsigned);
284 }
285
287 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
288 return APSInt(static_cast<const APInt &>(*this) * RHS, IsUnsigned);
289 }
291 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
292 return APSInt(static_cast<const APInt &>(*this) + RHS, IsUnsigned);
293 }
295 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
296 return APSInt(static_cast<const APInt &>(*this) - RHS, IsUnsigned);
297 }
299 return APSInt(~static_cast<const APInt &>(*this), IsUnsigned);
300 }
301
302
303
309
310
311
317
318
319
323
324
326 if (I1.getBitWidth() == I2.getBitWidth() && I1.isSigned() == I2.isSigned())
327 return I1.IsUnsigned ? I1.compare(I2) : I1.compareSigned(I2);
328
329
334
335
336
337 if (I1.isSigned()) {
338 assert(!I2.isSigned() && "Expected signed mismatch");
339 if (I1.isNegative())
340 return -1;
341 } else {
344 return 1;
345 }
346
347 return I1.compare(I2);
348 }
349
352
353
354
356};
357
362inline bool operator<(int64_t V1, const APSInt &V2) { return V2 > V1; }
363inline bool operator>(int64_t V1, const APSInt &V2) { return V2 < V1; }
364
366 I.print(OS, I.isSigned());
367 return OS;
368}
369
370
375
379
383
385 return LHS.getBitWidth() == RHS.getBitWidth() &&
386 LHS.isUnsigned() == RHS.isUnsigned() && LHS == RHS;
387 }
388};
389
390}
391
392#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
static bool isSigned(unsigned int Opcode)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
APInt relativeLShr(int RelativeShift) const
relative logical shift right
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
uint64_t getZExtValue() const
Get zero extended value.
LLVM_ABI APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
APInt relativeLShl(int RelativeShift) const
relative logical shift left
APInt & operator=(const APInt &RHS)
Copy assignment operator.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
APInt(unsigned numBits, uint64_t val, bool isSigned=false, bool implicitTrunc=false)
Create a new APInt of numBits width, initialized as val.
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
LLVM_ABI APInt urem(const APInt &RHS) const
Unsigned remainder operation.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
APInt relativeAShr(int RelativeShift) const
relative arithmetic shift right
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
bool isNegative() const
Determine sign of this APInt.
bool eq(const APInt &RHS) const
Equality comparison.
LLVM_ABI APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
APInt relativeAShl(int RelativeShift) const
relative arithmetic shift left
void ashrInPlace(unsigned ShiftAmt)
Arithmetic right-shift this APInt by ShiftAmt in place.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
LLVM_ABI APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
LLVM_ABI APInt srem(const APInt &RHS) const
Function for signed remainder operation.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
bool slt(const APInt &RHS) const
Signed less than comparison.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
int64_t getSExtValue() const
Get sign extended value.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false) const
Converts an APInt to a string and append it to Str.
An arbitrary precision integer that knows its signedness.
Definition APSInt.h:24
APSInt extOrTrunc(uint32_t width) const
Definition APSInt.h:120
APSInt & operator+=(const APSInt &RHS)
Definition APSInt.h:240
APSInt operator-(const APSInt &RHS) const
Definition APSInt.h:294
APSInt & operator=(APInt RHS)
Definition APSInt.h:65
static APSInt getMinValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the minimum integer value with the given bit width and signedness.
Definition APSInt.h:312
bool operator==(int64_t RHS) const
Definition APSInt.h:189
static APSInt get(int64_t X)
Definition APSInt.h:350
bool operator==(const APSInt &RHS) const
Definition APSInt.h:183
bool isNegative() const
Determine sign of this APSInt.
Definition APSInt.h:50
APSInt operator>>(unsigned Amt) const
Definition APSInt.h:152
APSInt operator^(const APSInt &RHS) const
Definition APSInt.h:281
bool operator!=(int64_t RHS) const
Definition APSInt.h:192
APSInt operator*(const APSInt &RHS) const
Definition APSInt.h:286
APSInt & operator*=(const APSInt &RHS)
Definition APSInt.h:250
APSInt & operator++()
Definition APSInt.h:223
bool operator>(const APSInt &RHS) const
Definition APSInt.h:171
bool operator>(int64_t RHS) const
Definition APSInt.h:204
APSInt(uint32_t BitWidth, bool isUnsigned=true)
Create an APSInt with the specified width, default to unsigned.
Definition APSInt.h:32
APSInt relativeShr(unsigned Amt) const
Definition APSInt.h:162
bool operator<(const APSInt &RHS) const
Definition APSInt.h:167
static int compareValues(const APSInt &I1, const APSInt &I2)
Compare underlying values of two numbers.
Definition APSInt.h:325
int64_t getExtValue() const
Get the correctly-extended int64_t value.
Definition APSInt.h:99
APSInt operator+(const APSInt &RHS) const
Definition APSInt.h:290
const APSInt & operator/=(const APSInt &RHS)
Definition APSInt.h:135
APSInt operator++(int)
Definition APSInt.h:231
bool isRepresentableByInt64() const
If this int is representable using an int64_t.
Definition APSInt.h:90
static APSInt getMaxValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the maximum integer value with the given bit width and signedness.
Definition APSInt.h:304
bool isNonNegative() const
Determine if this APSInt Value is non-negative (>= 0)
Definition APSInt.h:55
static APSInt getUnsigned(uint64_t X)
Definition APSInt.h:351
APSInt operator-() const
Definition APSInt.h:237
bool operator<=(int64_t RHS) const
Definition APSInt.h:195
APSInt operator<<(unsigned Bits) const
Definition APSInt.h:211
APSInt operator&(const APSInt &RHS) const
Definition APSInt.h:271
APSInt operator--(int)
Definition APSInt.h:234
bool isStrictlyPositive() const
Determine if this APSInt Value is positive.
Definition APSInt.h:63
APSInt & operator&=(const APSInt &RHS)
Definition APSInt.h:255
void setIsSigned(bool Val)
Definition APSInt.h:81
bool operator>=(const APSInt &RHS) const
Definition APSInt.h:179
APSInt(APInt I, bool isUnsigned=true)
Definition APSInt.h:35
APSInt operator~() const
Definition APSInt.h:298
APSInt operator%(const APSInt &RHS) const
Definition APSInt.h:143
const APSInt & operator%=(const APSInt &RHS)
Definition APSInt.h:127
APSInt & operator|=(const APSInt &RHS)
Definition APSInt.h:260
APSInt relativeShl(unsigned Amt) const
Definition APSInt.h:218
void toString(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Append this APSInt to the specified SmallString.
Definition APSInt.h:84
bool operator!=(const APSInt &RHS) const
Definition APSInt.h:187
std::optional< int64_t > tryExtValue() const
Definition APSInt.h:104
bool operator<(int64_t RHS) const
Definition APSInt.h:201
bool isUnsigned() const
Definition APSInt.h:79
APSInt()=default
Default constructor that creates an uninitialized APInt.
APSInt & operator>>=(unsigned Amt)
Definition APSInt.h:155
void setIsUnsigned(bool Val)
Definition APSInt.h:80
static bool isSameValue(const APSInt &I1, const APSInt &I2)
Determine if two APSInts have the same value, zero- or sign-extending as needed.
Definition APSInt.h:320
APSInt extend(uint32_t width) const
Definition APSInt.h:113
APSInt & operator-=(const APSInt &RHS)
Definition APSInt.h:245
APSInt operator|(const APSInt &RHS) const
Definition APSInt.h:276
bool operator<=(const APSInt &RHS) const
Definition APSInt.h:175
APSInt operator/(const APSInt &RHS) const
Definition APSInt.h:147
APSInt & operator=(uint64_t RHS)
Definition APSInt.h:71
bool operator>=(int64_t RHS) const
Definition APSInt.h:198
APSInt trunc(uint32_t width) const
Definition APSInt.h:109
APSInt & operator--()
Definition APSInt.h:227
bool isSigned() const
Definition APSInt.h:78
APSInt & operator^=(const APSInt &RHS)
Definition APSInt.h:265
APSInt & operator<<=(unsigned Amt)
Definition APSInt.h:214
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
Definition APSInt.h:362
bool operator!=(uint64_t V1, const APInt &V2)
bool operator>=(int64_t V1, const APSInt &V2)
Definition APSInt.h:361
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
bool operator>(int64_t V1, const APSInt &V2)
Definition APSInt.h:363
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
bool operator<=(int64_t V1, const APSInt &V2)
Definition APSInt.h:360
Implement std::hash so that hash_code can be used in STL containers.
static APSInt getEmptyKey()
Definition APSInt.h:372
static bool isEqual(const APSInt &LHS, const APSInt &RHS)
Definition APSInt.h:384
static APSInt getTombstoneKey()
Definition APSInt.h:376
static unsigned getHashValue(const APSInt &Key)
Definition APSInt.h:380
An information struct used to provide DenseMap with the various necessary components for a given valu...