LLVM 23.0.0git
APInt.h
Go to the documentation of this file.
1//===-- llvm/ADT/APInt.h - For Arbitrary Precision Integer -----*- C++ -*--===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements a class to represent arbitrary precision
11/// integral constant values and operations on them.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_ADT_APINT_H
16#define LLVM_ADT_APINT_H
17
21#include <cassert>
22#include <climits>
23#include <cstring>
24#include <optional>
25#include <utility>
26
27namespace llvm {
29class StringRef;
30class hash_code;
31class raw_ostream;
32struct Align;
33class DynamicAPInt;
34
35template <typename T> class SmallVectorImpl;
36template <typename T> class ArrayRef;
37template <typename T, typename Enable> struct DenseMapInfo;
38
39class APInt;
40
41inline APInt operator-(APInt);
42
43//===----------------------------------------------------------------------===//
44// APInt Class
45//===----------------------------------------------------------------------===//
46
47/// Class for arbitrary precision integers.
48///
49/// APInt is a functional replacement for common case unsigned integer type like
50/// "unsigned", "unsigned long" or "uint64_t", but also allows non-byte-width
51/// integer sizes and large integer value types such as 3-bits, 15-bits, or more
52/// than 64-bits of precision. APInt provides a variety of arithmetic operators
53/// and methods to manipulate integer values of any bit-width. It supports both
54/// the typical integer arithmetic and comparison operations as well as bitwise
55/// manipulation.
56///
57/// The class has several invariants worth noting:
58/// * All bit, byte, and word positions are zero-based.
59/// * Once the bit width is set, it doesn't change except by the Truncate,
60/// SignExtend, or ZeroExtend operations.
61/// * All binary operators must be on APInt instances of the same bit width.
62/// Attempting to use these operators on instances with different bit
63/// widths will yield an assertion.
64/// * The value is stored canonically as an unsigned value. For operations
65/// where it makes a difference, there are both signed and unsigned variants
66/// of the operation. For example, sdiv and udiv. However, because the bit
67/// widths must be the same, operations such as Mul and Add produce the same
68/// results regardless of whether the values are interpreted as signed or
69/// not.
70/// * In general, the class tries to follow the style of computation that LLVM
71/// uses in its IR. This simplifies its use for LLVM.
72/// * APInt supports zero-bit-width values, but operations that require bits
73/// are not defined on it (e.g. you cannot ask for the sign of a zero-bit
74/// integer). This means that operations like zero extension and logical
75/// shifts are defined, but sign extension and ashr is not. Zero bit values
76/// compare and hash equal to themselves, and countLeadingZeros returns 0.
77///
78class [[nodiscard]] APInt {
79public:
81
82 /// Byte size of a word.
83 static constexpr unsigned APINT_WORD_SIZE = sizeof(WordType);
84
85 /// Bits in a word.
86 static constexpr unsigned APINT_BITS_PER_WORD = APINT_WORD_SIZE * CHAR_BIT;
87
88 enum class Rounding {
92 };
93
94 static constexpr WordType WORDTYPE_MAX = ~WordType(0);
95
96 /// \name Constructors
97 /// @{
98
99 /// Create a new APInt of numBits width, initialized as val.
100 ///
101 /// If isSigned is true then val is treated as if it were a signed value
102 /// (i.e. as an int64_t) and the appropriate sign extension to the bit width
103 /// will be done. Otherwise, no sign extension occurs (high order bits beyond
104 /// the range of val are zero filled).
105 ///
106 /// \param numBits the bit width of the constructed APInt
107 /// \param val the initial value of the APInt
108 /// \param isSigned how to treat signedness of val
109 /// \param implicitTrunc allow implicit truncation of non-zero/sign bits of
110 /// val beyond the range of numBits
111 APInt(unsigned numBits, uint64_t val, bool isSigned = false,
112 bool implicitTrunc = false)
113 : BitWidth(numBits) {
114 if (!implicitTrunc) {
115 if (isSigned) {
116 if (BitWidth == 0) {
117 assert((val == 0 || val == uint64_t(-1)) &&
118 "Value must be 0 or -1 for signed 0-bit APInt");
119 } else {
120 assert(llvm::isIntN(BitWidth, val) &&
121 "Value is not an N-bit signed value");
122 }
123 } else {
124 if (BitWidth == 0) {
125 assert(val == 0 && "Value must be zero for unsigned 0-bit APInt");
126 } else {
127 assert(llvm::isUIntN(BitWidth, val) &&
128 "Value is not an N-bit unsigned value");
129 }
130 }
131 }
132 if (isSingleWord()) {
133 U.VAL = val;
134 if (implicitTrunc || isSigned)
136 } else {
137 initSlowCase(val, isSigned);
138 }
139 }
140
141 /// Construct an APInt of numBits width, initialized as bigVal[].
142 ///
143 /// Note that bigVal.size() can be smaller or larger than the corresponding
144 /// bit width but any extraneous bits will be dropped.
145 ///
146 /// \param numBits the bit width of the constructed APInt
147 /// \param bigVal a sequence of words to form the initial value of the APInt
148 LLVM_ABI APInt(unsigned numBits, ArrayRef<uint64_t> bigVal);
149
150 /// Equivalent to APInt(numBits, ArrayRef<uint64_t>(bigVal, numWords)), but
151 /// deprecated because this constructor is prone to ambiguity with the
152 /// APInt(unsigned, uint64_t, bool) constructor.
153 ///
154 /// Once all uses of this constructor are migrated to other constructors,
155 /// consider marking this overload ""= delete" to prevent calls from being
156 /// incorrectly bound to the APInt(unsigned, uint64_t, bool) constructor.
157 [[deprecated("Use other constructors of APInt")]]
158 LLVM_ABI APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]);
159
160 /// Construct an APInt from a string representation.
161 ///
162 /// This constructor interprets the string \p str in the given radix. The
163 /// interpretation stops when the first character that is not suitable for the
164 /// radix is encountered, or the end of the string. Acceptable radix values
165 /// are 2, 8, 10, 16, and 36. It is an error for the value implied by the
166 /// string to require more bits than numBits.
167 ///
168 /// \param numBits the bit width of the constructed APInt
169 /// \param str the string to be interpreted
170 /// \param radix the radix to use for the conversion
171 LLVM_ABI APInt(unsigned numBits, StringRef str, uint8_t radix);
172
173 /// Default constructor that creates an APInt with a 1-bit zero value.
174 explicit APInt() { U.VAL = 0; }
175
176 /// Copy Constructor.
177 APInt(const APInt &that) : BitWidth(that.BitWidth) {
178 if (isSingleWord())
179 U.VAL = that.U.VAL;
180 else
181 initSlowCase(that);
182 }
183
184 /// Move Constructor.
185 APInt(APInt &&that) : BitWidth(that.BitWidth) {
186 memcpy(&U, &that.U, sizeof(U));
187 that.BitWidth = 0;
188 }
189
190 /// Destructor.
192 if (needsCleanup())
193 delete[] U.pVal;
194 }
195
196 /// @}
197 /// \name Value Generators
198 /// @{
199
200 /// Get the '0' value for the specified bit-width.
201 static APInt getZero(unsigned numBits) { return APInt(numBits, 0); }
202
203 /// Return an APInt zero bits wide.
204 static APInt getZeroWidth() { return getZero(0); }
205
206 /// Gets maximum unsigned value of APInt for specific bit width.
207 static APInt getMaxValue(unsigned numBits) { return getAllOnes(numBits); }
208
209 /// Gets maximum signed value of APInt for a specific bit width.
210 static APInt getSignedMaxValue(unsigned numBits) {
211 APInt API = getAllOnes(numBits);
212 API.clearBit(numBits - 1);
213 return API;
214 }
215
216 /// Gets minimum unsigned value of APInt for a specific bit width.
217 static APInt getMinValue(unsigned numBits) { return APInt(numBits, 0); }
218
219 /// Gets minimum signed value of APInt for a specific bit width.
220 static APInt getSignedMinValue(unsigned numBits) {
221 APInt API(numBits, 0);
222 API.setBit(numBits - 1);
223 return API;
224 }
225
226 /// Get the SignMask for a specific bit width.
227 ///
228 /// This is just a wrapper function of getSignedMinValue(), and it helps code
229 /// readability when we want to get a SignMask.
230 static APInt getSignMask(unsigned BitWidth) {
231 return getSignedMinValue(BitWidth);
232 }
233
234 /// Return an APInt of a specified width with all bits set.
235 static APInt getAllOnes(unsigned numBits) {
236 return APInt(numBits, WORDTYPE_MAX, true);
237 }
238
239 /// Return an APInt with exactly one bit set in the result.
240 static APInt getOneBitSet(unsigned numBits, unsigned BitNo) {
241 APInt Res(numBits, 0);
242 Res.setBit(BitNo);
243 return Res;
244 }
245
246 /// Get a value with a block of bits set.
247 ///
248 /// Constructs an APInt value that has a contiguous range of bits set. The
249 /// bits from loBit (inclusive) to hiBit (exclusive) will be set. All other
250 /// bits will be zero. For example, with parameters(32, 0, 16) you would get
251 /// 0x0000FFFF. Please call getBitsSetWithWrap if \p loBit may be greater than
252 /// \p hiBit.
253 ///
254 /// \param numBits the intended bit width of the result
255 /// \param loBit the index of the lowest bit set.
256 /// \param hiBit the index of the highest bit set.
257 ///
258 /// \returns An APInt value with the requested bits set.
259 static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit) {
260 APInt Res(numBits, 0);
261 Res.setBits(loBit, hiBit);
262 return Res;
263 }
264
265 /// Wrap version of getBitsSet.
266 /// If \p hiBit is bigger than \p loBit, this is same with getBitsSet.
267 /// If \p hiBit is not bigger than \p loBit, the set bits "wrap". For example,
268 /// with parameters (32, 28, 4), you would get 0xF000000F.
269 /// If \p hiBit is equal to \p loBit, you would get a result with all bits
270 /// set.
271 static APInt getBitsSetWithWrap(unsigned numBits, unsigned loBit,
272 unsigned hiBit) {
273 APInt Res(numBits, 0);
274 Res.setBitsWithWrap(loBit, hiBit);
275 return Res;
276 }
277
278 /// Constructs an APInt value that has a contiguous range of bits set. The
279 /// bits from loBit (inclusive) to numBits (exclusive) will be set. All other
280 /// bits will be zero. For example, with parameters(32, 12) you would get
281 /// 0xFFFFF000.
282 ///
283 /// \param numBits the intended bit width of the result
284 /// \param loBit the index of the lowest bit to set.
285 ///
286 /// \returns An APInt value with the requested bits set.
287 static APInt getBitsSetFrom(unsigned numBits, unsigned loBit) {
288 APInt Res(numBits, 0);
289 Res.setBitsFrom(loBit);
290 return Res;
291 }
292
293 /// Constructs an APInt value that has the top hiBitsSet bits set.
294 ///
295 /// \param numBits the bitwidth of the result
296 /// \param hiBitsSet the number of high-order bits set in the result.
297 static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet) {
298 APInt Res(numBits, 0);
299 Res.setHighBits(hiBitsSet);
300 return Res;
301 }
302
303 /// Constructs an APInt value that has the bottom loBitsSet bits set.
304 ///
305 /// \param numBits the bitwidth of the result
306 /// \param loBitsSet the number of low-order bits set in the result.
307 static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet) {
308 APInt Res(numBits, 0);
309 Res.setLowBits(loBitsSet);
310 return Res;
311 }
312
313 /// Return a value containing V broadcasted over NewLen bits.
314 LLVM_ABI static APInt getSplat(unsigned NewLen, const APInt &V);
315
316 /// @}
317 /// \name Value Tests
318 /// @{
319
320 /// Determine if this APInt just has one word to store value.
321 ///
322 /// \returns true if the number of bits <= 64, false otherwise.
323 bool isSingleWord() const { return BitWidth <= APINT_BITS_PER_WORD; }
324
325 /// Determine sign of this APInt.
326 ///
327 /// This tests the high bit of this APInt to determine if it is set.
328 ///
329 /// \returns true if this APInt is negative, false otherwise
330 bool isNegative() const { return (*this)[BitWidth - 1]; }
331
332 /// Determine if this APInt Value is non-negative (>= 0)
333 ///
334 /// This tests the high bit of the APInt to determine if it is unset.
335 bool isNonNegative() const { return !isNegative(); }
336
337 /// Determine if sign bit of this APInt is set.
338 ///
339 /// This tests the high bit of this APInt to determine if it is set.
340 ///
341 /// \returns true if this APInt has its sign bit set, false otherwise.
342 bool isSignBitSet() const { return (*this)[BitWidth - 1]; }
343
344 /// Determine if sign bit of this APInt is clear.
345 ///
346 /// This tests the high bit of this APInt to determine if it is clear.
347 ///
348 /// \returns true if this APInt has its sign bit clear, false otherwise.
349 bool isSignBitClear() const { return !isSignBitSet(); }
350
351 /// Determine if this APInt Value is positive.
352 ///
353 /// This tests if the value of this APInt is positive (> 0). Note
354 /// that 0 is not a positive value.
355 ///
356 /// \returns true if this APInt is positive.
357 bool isStrictlyPositive() const { return isNonNegative() && !isZero(); }
358
359 /// Determine if this APInt Value is non-positive (<= 0).
360 ///
361 /// \returns true if this APInt is non-positive.
362 bool isNonPositive() const { return !isStrictlyPositive(); }
363
364 /// Determine if this APInt Value only has the specified bit set.
365 ///
366 /// \returns true if this APInt only has the specified bit set.
367 bool isOneBitSet(unsigned BitNo) const {
368 return (*this)[BitNo] && popcount() == 1;
369 }
370
371 /// Determine if all bits are set. This is true for zero-width values.
372 bool isAllOnes() const {
373 if (BitWidth == 0)
374 return true;
375 if (isSingleWord())
376 return U.VAL == WORDTYPE_MAX >> (APINT_BITS_PER_WORD - BitWidth);
377 return countTrailingOnesSlowCase() == BitWidth;
378 }
379
380 /// Determine if this value is zero, i.e. all bits are clear.
381 bool isZero() const {
382 if (isSingleWord())
383 return U.VAL == 0;
384 return countLeadingZerosSlowCase() == BitWidth;
385 }
386
387 /// Determine if this is a value of 1.
388 ///
389 /// This checks to see if the value of this APInt is one.
390 bool isOne() const {
391 if (isSingleWord())
392 return U.VAL == 1;
393 return countLeadingZerosSlowCase() == BitWidth - 1;
394 }
395
396 /// Determine if this is the largest unsigned value.
397 ///
398 /// This checks to see if the value of this APInt is the maximum unsigned
399 /// value for the APInt's bit width.
400 bool isMaxValue() const { return isAllOnes(); }
401
402 /// Determine if this is the largest signed value.
403 ///
404 /// This checks to see if the value of this APInt is the maximum signed
405 /// value for the APInt's bit width.
406 bool isMaxSignedValue() const {
407 if (isSingleWord()) {
408 assert(BitWidth && "zero width values not allowed");
409 return U.VAL == ((WordType(1) << (BitWidth - 1)) - 1);
410 }
411 return !isNegative() && countTrailingOnesSlowCase() == BitWidth - 1;
412 }
413
414 /// Determine if this is the smallest unsigned value.
415 ///
416 /// This checks to see if the value of this APInt is the minimum unsigned
417 /// value for the APInt's bit width.
418 bool isMinValue() const { return isZero(); }
419
420 /// Determine if this is the smallest signed value.
421 ///
422 /// This checks to see if the value of this APInt is the minimum signed
423 /// value for the APInt's bit width.
424 bool isMinSignedValue() const {
425 if (isSingleWord()) {
426 assert(BitWidth && "zero width values not allowed");
427 return U.VAL == (WordType(1) << (BitWidth - 1));
428 }
429 return isNegative() && countTrailingZerosSlowCase() == BitWidth - 1;
430 }
431
432 /// Check if this APInt has an N-bits unsigned integer value.
433 bool isIntN(unsigned N) const { return getActiveBits() <= N; }
434
435 /// Check if this APInt has an N-bits signed integer value.
436 bool isSignedIntN(unsigned N) const { return getSignificantBits() <= N; }
437
438 /// Check if this APInt's value is a power of two greater than zero.
439 ///
440 /// \returns true if the argument APInt value is a power of two > 0.
441 bool isPowerOf2() const {
442 if (isSingleWord()) {
443 assert(BitWidth && "zero width values not allowed");
444 return isPowerOf2_64(U.VAL);
445 }
446 return countPopulationSlowCase() == 1;
447 }
448
449 /// Check if this APInt's negated value is a power of two greater than zero.
450 bool isNegatedPowerOf2() const {
451 assert(BitWidth && "zero width values not allowed");
452 if (isNonNegative())
453 return false;
454 // NegatedPowerOf2 - shifted mask in the top bits.
455 unsigned LO = countl_one();
456 unsigned TZ = countr_zero();
457 return (LO + TZ) == BitWidth;
458 }
459
460 /// Checks if this APInt -interpreted as an address- is aligned to the
461 /// provided value.
462 LLVM_ABI bool isAligned(Align A) const;
463
464 /// Check if the APInt's value is returned by getSignMask.
465 ///
466 /// \returns true if this is the value returned by getSignMask.
467 bool isSignMask() const { return isMinSignedValue(); }
468
469 /// Convert APInt to a boolean value.
470 ///
471 /// This converts the APInt to a boolean value as a test against zero.
472 bool getBoolValue() const { return !isZero(); }
473
474 /// If this value is smaller than the specified limit, return it, otherwise
475 /// return the limit value. This causes the value to saturate to the limit.
477 return ugt(Limit) ? Limit : getZExtValue();
478 }
479
480 /// Check if the APInt consists of a repeated bit pattern.
481 ///
482 /// e.g. 0x01010101 satisfies isSplat(8).
483 /// \param SplatSizeInBits The size of the pattern in bits. Must divide bit
484 /// width without remainder.
485 LLVM_ABI bool isSplat(unsigned SplatSizeInBits) const;
486
487 /// \returns true if this APInt value is a sequence of \param numBits ones
488 /// starting at the least significant bit with the remainder zero.
489 bool isMask(unsigned numBits) const {
490 assert(numBits != 0 && "numBits must be non-zero");
491 assert(numBits <= BitWidth && "numBits out of range");
492 if (isSingleWord())
493 return U.VAL == (WORDTYPE_MAX >> (APINT_BITS_PER_WORD - numBits));
494 unsigned Ones = countTrailingOnesSlowCase();
495 return (numBits == Ones) &&
496 ((Ones + countLeadingZerosSlowCase()) == BitWidth);
497 }
498
499 /// \returns true if this APInt is a non-empty sequence of ones starting at
500 /// the least significant bit with the remainder zero.
501 /// Ex. isMask(0x0000FFFFU) == true.
502 bool isMask() const {
503 if (isSingleWord())
504 return isMask_64(U.VAL);
505 unsigned Ones = countTrailingOnesSlowCase();
506 return (Ones > 0) && ((Ones + countLeadingZerosSlowCase()) == BitWidth);
507 }
508
509 /// Return true if this APInt value contains a non-empty sequence of ones with
510 /// the remainder zero.
511 bool isShiftedMask() const {
512 if (isSingleWord())
513 return isShiftedMask_64(U.VAL);
514 unsigned Ones = countPopulationSlowCase();
515 unsigned LeadZ = countLeadingZerosSlowCase();
516 return (Ones + LeadZ + countTrailingZerosSlowCase()) == BitWidth;
517 }
518
519 /// Return true if this APInt value contains a non-empty sequence of ones with
520 /// the remainder zero. If true, \p MaskIdx will specify the index of the
521 /// lowest set bit and \p MaskLen is updated to specify the length of the
522 /// mask, else neither are updated.
523 bool isShiftedMask(unsigned &MaskIdx, unsigned &MaskLen) const {
524 if (isSingleWord())
525 return isShiftedMask_64(U.VAL, MaskIdx, MaskLen);
526 unsigned Ones = countPopulationSlowCase();
527 unsigned LeadZ = countLeadingZerosSlowCase();
528 unsigned TrailZ = countTrailingZerosSlowCase();
529 if ((Ones + LeadZ + TrailZ) != BitWidth)
530 return false;
531 MaskLen = Ones;
532 MaskIdx = TrailZ;
533 return true;
534 }
535
536 /// Compute an APInt containing numBits highbits from this APInt.
537 ///
538 /// Get an APInt with the same BitWidth as this APInt, just zero mask the low
539 /// bits and right shift to the least significant bit.
540 ///
541 /// \returns the high "numBits" bits of this APInt.
542 LLVM_ABI APInt getHiBits(unsigned numBits) const;
543
544 /// Compute an APInt containing numBits lowbits from this APInt.
545 ///
546 /// Get an APInt with the same BitWidth as this APInt, just zero mask the high
547 /// bits.
548 ///
549 /// \returns the low "numBits" bits of this APInt.
550 LLVM_ABI APInt getLoBits(unsigned numBits) const;
551
552 /// Determine if two APInts have the same value, after zero-extending or
553 /// sign-extending (if \p SignedCompare) one of them (if needed!) to ensure
554 /// that the bit-widths match.
555 static bool isSameValue(const APInt &I1, const APInt &I2,
556 bool SignedCompare = false) {
557 if (I1.getBitWidth() == I2.getBitWidth())
558 return I1 == I2;
559
560 auto ZExtOrSExt = [SignedCompare](const APInt &I, unsigned BitWidth) {
561 return SignedCompare ? I.sext(BitWidth) : I.zext(BitWidth);
562 };
563
564 if (I1.getBitWidth() > I2.getBitWidth())
565 return I1 == ZExtOrSExt(I2, I1.getBitWidth());
566
567 return ZExtOrSExt(I1, I2.getBitWidth()) == I2;
568 }
569
570 /// Overload to compute a hash_code for an APInt value.
571 LLVM_ABI friend hash_code hash_value(const APInt &Arg);
572
573 /// This function returns a pointer to the internal storage of the APInt.
574 /// This is useful for writing out the APInt in binary form without any
575 /// conversions.
576 const uint64_t *getRawData() const {
577 if (isSingleWord())
578 return &U.VAL;
579 return &U.pVal[0];
580 }
581
582 /// @}
583 /// \name Unary Operators
584 /// @{
585
586 /// Postfix increment operator. Increment *this by 1.
587 ///
588 /// \returns a new APInt value representing the original value of *this.
590 APInt API(*this);
591 ++(*this);
592 return API;
593 }
594
595 /// Prefix increment operator.
596 ///
597 /// \returns *this incremented by one
598 LLVM_ABI APInt &operator++();
599
600 /// Postfix decrement operator. Decrement *this by 1.
601 ///
602 /// \returns a new APInt value representing the original value of *this.
604 APInt API(*this);
605 --(*this);
606 return API;
607 }
608
609 /// Prefix decrement operator.
610 ///
611 /// \returns *this decremented by one.
612 LLVM_ABI APInt &operator--();
613
614 /// Logical negation operation on this APInt returns true if zero, like normal
615 /// integers.
616 bool operator!() const { return isZero(); }
617
618 /// @}
619 /// \name Assignment Operators
620 /// @{
621
622 /// Copy assignment operator.
623 ///
624 /// \returns *this after assignment of RHS.
626 // The common case (both source or dest being inline) doesn't require
627 // allocation or deallocation.
628 if (isSingleWord() && RHS.isSingleWord()) {
629 U.VAL = RHS.U.VAL;
630 BitWidth = RHS.BitWidth;
631 return *this;
632 }
633
634 assignSlowCase(RHS);
635 return *this;
636 }
637
638 /// Move assignment operator.
640#ifdef EXPENSIVE_CHECKS
641 // Some std::shuffle implementations still do self-assignment.
642 if (this == &that)
643 return *this;
644#endif
645 assert(this != &that && "Self-move not supported");
646 if (!isSingleWord())
647 delete[] U.pVal;
648
649 // Use memcpy so that type based alias analysis sees both VAL and pVal
650 // as modified.
651 memcpy(&U, &that.U, sizeof(U));
652
653 BitWidth = that.BitWidth;
654 that.BitWidth = 0;
655 return *this;
656 }
657
658 /// Assignment operator.
659 ///
660 /// The RHS value is assigned to *this. If the significant bits in RHS exceed
661 /// the bit width, the excess bits are truncated. If the bit width is larger
662 /// than 64, the value is zero filled in the unspecified high order bits.
663 ///
664 /// \returns *this after assignment of RHS value.
666 if (isSingleWord()) {
667 U.VAL = RHS;
668 return clearUnusedBits();
669 }
670 U.pVal[0] = RHS;
671 memset(U.pVal + 1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
672 return *this;
673 }
674
675 /// Bitwise AND assignment operator.
676 ///
677 /// Performs a bitwise AND operation on this APInt and RHS. The result is
678 /// assigned to *this.
679 ///
680 /// \returns *this after ANDing with RHS.
682 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
683 if (isSingleWord())
684 U.VAL &= RHS.U.VAL;
685 else
686 andAssignSlowCase(RHS);
687 return *this;
688 }
689
690 /// Bitwise AND assignment operator.
691 ///
692 /// Performs a bitwise AND operation on this APInt and RHS. RHS is
693 /// logically zero-extended or truncated to match the bit-width of
694 /// the LHS.
696 if (isSingleWord()) {
697 U.VAL &= RHS;
698 return *this;
699 }
700 U.pVal[0] &= RHS;
701 memset(U.pVal + 1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
702 return *this;
703 }
704
705 /// Bitwise OR assignment operator.
706 ///
707 /// Performs a bitwise OR operation on this APInt and RHS. The result is
708 /// assigned *this;
709 ///
710 /// \returns *this after ORing with RHS.
712 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
713 if (isSingleWord())
714 U.VAL |= RHS.U.VAL;
715 else
716 orAssignSlowCase(RHS);
717 return *this;
718 }
719
720 /// Bitwise OR assignment operator.
721 ///
722 /// Performs a bitwise OR operation on this APInt and RHS. RHS is
723 /// logically zero-extended or truncated to match the bit-width of
724 /// the LHS.
726 if (isSingleWord()) {
727 U.VAL |= RHS;
728 return clearUnusedBits();
729 }
730 U.pVal[0] |= RHS;
731 return *this;
732 }
733
734 /// Bitwise XOR assignment operator.
735 ///
736 /// Performs a bitwise XOR operation on this APInt and RHS. The result is
737 /// assigned to *this.
738 ///
739 /// \returns *this after XORing with RHS.
741 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
742 if (isSingleWord())
743 U.VAL ^= RHS.U.VAL;
744 else
745 xorAssignSlowCase(RHS);
746 return *this;
747 }
748
749 /// Bitwise XOR assignment operator.
750 ///
751 /// Performs a bitwise XOR operation on this APInt and RHS. RHS is
752 /// logically zero-extended or truncated to match the bit-width of
753 /// the LHS.
755 if (isSingleWord()) {
756 U.VAL ^= RHS;
757 return clearUnusedBits();
758 }
759 U.pVal[0] ^= RHS;
760 return *this;
761 }
762
763 /// Multiplication assignment operator.
764 ///
765 /// Multiplies this APInt by RHS and assigns the result to *this.
766 ///
767 /// \returns *this
770
771 /// Addition assignment operator.
772 ///
773 /// Adds RHS to *this and assigns the result to *this.
774 ///
775 /// \returns *this
778
779 /// Subtraction assignment operator.
780 ///
781 /// Subtracts RHS from *this and assigns the result to *this.
782 ///
783 /// \returns *this
786
787 /// Left-shift assignment function.
788 ///
789 /// Shifts *this left by shiftAmt and assigns the result to *this.
790 ///
791 /// \returns *this after shifting left by ShiftAmt
792 APInt &operator<<=(unsigned ShiftAmt) {
793 assert(ShiftAmt <= BitWidth && "Invalid shift amount");
794 if (isSingleWord()) {
795 if (ShiftAmt == BitWidth)
796 U.VAL = 0;
797 else
798 U.VAL <<= ShiftAmt;
799 return clearUnusedBits();
800 }
801 shlSlowCase(ShiftAmt);
802 return *this;
803 }
804
805 /// Left-shift assignment function.
806 ///
807 /// Shifts *this left by shiftAmt and assigns the result to *this.
808 ///
809 /// \returns *this after shifting left by ShiftAmt
810 LLVM_ABI APInt &operator<<=(const APInt &ShiftAmt);
811
812 /// @}
813 /// \name Binary Operators
814 /// @{
815
816 /// Multiplication operator.
817 ///
818 /// Multiplies this APInt by RHS and returns the result.
819 LLVM_ABI APInt operator*(const APInt &RHS) const;
820
821 /// Left logical shift operator.
822 ///
823 /// Shifts this APInt left by \p Bits and returns the result.
824 APInt operator<<(unsigned Bits) const { return shl(Bits); }
825
826 /// Left logical shift operator.
827 ///
828 /// Shifts this APInt left by \p Bits and returns the result.
829 APInt operator<<(const APInt &Bits) const { return shl(Bits); }
830
831 /// Arithmetic right-shift function.
832 ///
833 /// Arithmetic right-shift this APInt by shiftAmt.
834 APInt ashr(unsigned ShiftAmt) const {
835 APInt R(*this);
836 R.ashrInPlace(ShiftAmt);
837 return R;
838 }
839
840 /// Arithmetic right-shift this APInt by ShiftAmt in place.
841 void ashrInPlace(unsigned ShiftAmt) {
842 assert(ShiftAmt <= BitWidth && "Invalid shift amount");
843 if (isSingleWord()) {
844 int64_t SExtVAL = SignExtend64(U.VAL, BitWidth);
845 if (ShiftAmt == BitWidth)
846 U.VAL = SExtVAL >> (APINT_BITS_PER_WORD - 1); // Fill with sign bit.
847 else
848 U.VAL = SExtVAL >> ShiftAmt;
850 return;
851 }
852 ashrSlowCase(ShiftAmt);
853 }
854
855 /// Logical right-shift function.
856 ///
857 /// Logical right-shift this APInt by shiftAmt.
858 APInt lshr(unsigned shiftAmt) const {
859 APInt R(*this);
860 R.lshrInPlace(shiftAmt);
861 return R;
862 }
863
864 /// Logical right-shift this APInt by ShiftAmt in place.
865 void lshrInPlace(unsigned ShiftAmt) {
866 assert(ShiftAmt <= BitWidth && "Invalid shift amount");
867 if (isSingleWord()) {
868 if (ShiftAmt == BitWidth)
869 U.VAL = 0;
870 else
871 U.VAL >>= ShiftAmt;
872 return;
873 }
874 lshrSlowCase(ShiftAmt);
875 }
876
877 /// Left-shift function.
878 ///
879 /// Left-shift this APInt by shiftAmt.
880 APInt shl(unsigned shiftAmt) const {
881 APInt R(*this);
882 R <<= shiftAmt;
883 return R;
884 }
885
886 /// relative logical shift right
887 APInt relativeLShr(int RelativeShift) const {
888 return RelativeShift > 0 ? lshr(RelativeShift) : shl(-RelativeShift);
889 }
890
891 /// relative logical shift left
892 APInt relativeLShl(int RelativeShift) const {
893 return relativeLShr(-RelativeShift);
894 }
895
896 /// relative arithmetic shift right
897 APInt relativeAShr(int RelativeShift) const {
898 return RelativeShift > 0 ? ashr(RelativeShift) : shl(-RelativeShift);
899 }
900
901 /// relative arithmetic shift left
902 APInt relativeAShl(int RelativeShift) const {
903 return relativeAShr(-RelativeShift);
904 }
905
906 /// Rotate left by rotateAmt.
907 LLVM_ABI APInt rotl(unsigned rotateAmt) const;
908
909 /// Rotate right by rotateAmt.
910 LLVM_ABI APInt rotr(unsigned rotateAmt) const;
911
912 /// Arithmetic right-shift function.
913 ///
914 /// Arithmetic right-shift this APInt by shiftAmt.
915 APInt ashr(const APInt &ShiftAmt) const {
916 APInt R(*this);
917 R.ashrInPlace(ShiftAmt);
918 return R;
919 }
920
921 /// Arithmetic right-shift this APInt by shiftAmt in place.
922 LLVM_ABI void ashrInPlace(const APInt &shiftAmt);
923
924 /// Logical right-shift function.
925 ///
926 /// Logical right-shift this APInt by shiftAmt.
927 APInt lshr(const APInt &ShiftAmt) const {
928 APInt R(*this);
929 R.lshrInPlace(ShiftAmt);
930 return R;
931 }
932
933 /// Logical right-shift this APInt by ShiftAmt in place.
934 LLVM_ABI void lshrInPlace(const APInt &ShiftAmt);
935
936 /// Left-shift function.
937 ///
938 /// Left-shift this APInt by shiftAmt.
939 APInt shl(const APInt &ShiftAmt) const {
940 APInt R(*this);
941 R <<= ShiftAmt;
942 return R;
943 }
944
945 /// Rotate left by rotateAmt.
946 LLVM_ABI APInt rotl(const APInt &rotateAmt) const;
947
948 /// Rotate right by rotateAmt.
949 LLVM_ABI APInt rotr(const APInt &rotateAmt) const;
950
951 /// Concatenate the bits from "NewLSB" onto the bottom of *this. This is
952 /// equivalent to:
953 /// (this->zext(NewWidth) << NewLSB.getBitWidth()) | NewLSB.zext(NewWidth)
954 APInt concat(const APInt &NewLSB) const {
955 /// If the result will be small, then both the merged values are small.
956 unsigned NewWidth = getBitWidth() + NewLSB.getBitWidth();
957 if (NewWidth <= APINT_BITS_PER_WORD)
958 return APInt(NewWidth, (U.VAL << NewLSB.getBitWidth()) | NewLSB.U.VAL);
959 return concatSlowCase(NewLSB);
960 }
961
962 /// Unsigned division operation.
963 ///
964 /// Perform an unsigned divide operation on this APInt by RHS. Both this and
965 /// RHS are treated as unsigned quantities for purposes of this division.
966 ///
967 /// \returns a new APInt value containing the division result, rounded towards
968 /// zero.
969 LLVM_ABI APInt udiv(const APInt &RHS) const;
970 LLVM_ABI APInt udiv(uint64_t RHS) const;
971
972 /// Signed division function for APInt.
973 ///
974 /// Signed divide this APInt by APInt RHS.
975 ///
976 /// The result is rounded towards zero.
977 LLVM_ABI APInt sdiv(const APInt &RHS) const;
978 LLVM_ABI APInt sdiv(int64_t RHS) const;
979
980 /// Unsigned remainder operation.
981 ///
982 /// Perform an unsigned remainder operation on this APInt with RHS being the
983 /// divisor. Both this and RHS are treated as unsigned quantities for purposes
984 /// of this operation.
985 ///
986 /// \returns a new APInt value containing the remainder result
987 LLVM_ABI APInt urem(const APInt &RHS) const;
988 LLVM_ABI uint64_t urem(uint64_t RHS) const;
989
990 /// Function for signed remainder operation.
991 ///
992 /// Signed remainder operation on APInt.
993 ///
994 /// Note that this is a true remainder operation and not a modulo operation
995 /// because the sign follows the sign of the dividend which is *this.
996 LLVM_ABI APInt srem(const APInt &RHS) const;
997 LLVM_ABI int64_t srem(int64_t RHS) const;
998
999 /// Dual division/remainder interface.
1000 ///
1001 /// Sometimes it is convenient to divide two APInt values and obtain both the
1002 /// quotient and remainder. This function does both operations in the same
1003 /// computation making it a little more efficient. The pair of input arguments
1004 /// may overlap with the pair of output arguments. It is safe to call
1005 /// udivrem(X, Y, X, Y), for example.
1006 LLVM_ABI static void udivrem(const APInt &LHS, const APInt &RHS,
1007 APInt &Quotient, APInt &Remainder);
1008 LLVM_ABI static void udivrem(const APInt &LHS, uint64_t RHS, APInt &Quotient,
1009 uint64_t &Remainder);
1010
1011 LLVM_ABI static void sdivrem(const APInt &LHS, const APInt &RHS,
1012 APInt &Quotient, APInt &Remainder);
1013 LLVM_ABI static void sdivrem(const APInt &LHS, int64_t RHS, APInt &Quotient,
1014 int64_t &Remainder);
1015
1016 // Operations that return overflow indicators.
1017 LLVM_ABI APInt sadd_ov(const APInt &RHS, bool &Overflow) const;
1018 LLVM_ABI APInt uadd_ov(const APInt &RHS, bool &Overflow) const;
1019 LLVM_ABI APInt ssub_ov(const APInt &RHS, bool &Overflow) const;
1020 LLVM_ABI APInt usub_ov(const APInt &RHS, bool &Overflow) const;
1021 LLVM_ABI APInt sdiv_ov(const APInt &RHS, bool &Overflow) const;
1022 LLVM_ABI APInt smul_ov(const APInt &RHS, bool &Overflow) const;
1023 LLVM_ABI APInt umul_ov(const APInt &RHS, bool &Overflow) const;
1024 LLVM_ABI APInt sshl_ov(const APInt &Amt, bool &Overflow) const;
1025 LLVM_ABI APInt sshl_ov(unsigned Amt, bool &Overflow) const;
1026 LLVM_ABI APInt ushl_ov(const APInt &Amt, bool &Overflow) const;
1027 LLVM_ABI APInt ushl_ov(unsigned Amt, bool &Overflow) const;
1028
1029 /// Signed integer floor division operation.
1030 ///
1031 /// Rounds towards negative infinity, i.e. 5 / -2 = -3. Iff minimum value
1032 /// divided by -1 set Overflow to true.
1033 LLVM_ABI APInt sfloordiv_ov(const APInt &RHS, bool &Overflow) const;
1034
1035 // Operations that saturate
1036 LLVM_ABI APInt sadd_sat(const APInt &RHS) const;
1037 LLVM_ABI APInt uadd_sat(const APInt &RHS) const;
1038 LLVM_ABI APInt ssub_sat(const APInt &RHS) const;
1039 LLVM_ABI APInt usub_sat(const APInt &RHS) const;
1040 LLVM_ABI APInt smul_sat(const APInt &RHS) const;
1041 LLVM_ABI APInt umul_sat(const APInt &RHS) const;
1042 LLVM_ABI APInt sshl_sat(const APInt &RHS) const;
1043 LLVM_ABI APInt sshl_sat(unsigned RHS) const;
1044 LLVM_ABI APInt ushl_sat(const APInt &RHS) const;
1045 LLVM_ABI APInt ushl_sat(unsigned RHS) const;
1046
1047 /// Array-indexing support.
1048 ///
1049 /// \returns the bit value at bitPosition
1050 bool operator[](unsigned bitPosition) const {
1051 assert(bitPosition < getBitWidth() && "Bit position out of bounds!");
1052 return (maskBit(bitPosition) & getWord(bitPosition)) != 0;
1053 }
1054
1055 /// @}
1056 /// \name Comparison Operators
1057 /// @{
1058
1059 /// Equality operator.
1060 ///
1061 /// Compares this APInt with RHS for the validity of the equality
1062 /// relationship.
1063 bool operator==(const APInt &RHS) const {
1064 assert(BitWidth == RHS.BitWidth && "Comparison requires equal bit widths");
1065 if (isSingleWord())
1066 return U.VAL == RHS.U.VAL;
1067 return equalSlowCase(RHS);
1068 }
1069
1070 /// Equality operator.
1071 ///
1072 /// Compares this APInt with a uint64_t for the validity of the equality
1073 /// relationship.
1074 ///
1075 /// \returns true if *this == Val
1076 bool operator==(uint64_t Val) const {
1077 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() == Val;
1078 }
1079
1080 /// Equality comparison.
1081 ///
1082 /// Compares this APInt with RHS for the validity of the equality
1083 /// relationship.
1084 ///
1085 /// \returns true if *this == Val
1086 bool eq(const APInt &RHS) const { return (*this) == RHS; }
1087
1088 /// Inequality operator.
1089 ///
1090 /// Compares this APInt with RHS for the validity of the inequality
1091 /// relationship.
1092 ///
1093 /// \returns true if *this != Val
1094 bool operator!=(const APInt &RHS) const { return !((*this) == RHS); }
1095
1096 /// Inequality operator.
1097 ///
1098 /// Compares this APInt with a uint64_t for the validity of the inequality
1099 /// relationship.
1100 ///
1101 /// \returns true if *this != Val
1102 bool operator!=(uint64_t Val) const { return !((*this) == Val); }
1103
1104 /// Inequality comparison
1105 ///
1106 /// Compares this APInt with RHS for the validity of the inequality
1107 /// relationship.
1108 ///
1109 /// \returns true if *this != Val
1110 bool ne(const APInt &RHS) const { return !((*this) == RHS); }
1111
1112 /// Unsigned less than comparison
1113 ///
1114 /// Regards both *this and RHS as unsigned quantities and compares them for
1115 /// the validity of the less-than relationship.
1116 ///
1117 /// \returns true if *this < RHS when both are considered unsigned.
1118 bool ult(const APInt &RHS) const { return compare(RHS) < 0; }
1119
1120 /// Unsigned less than comparison
1121 ///
1122 /// Regards both *this as an unsigned quantity and compares it with RHS for
1123 /// the validity of the less-than relationship.
1124 ///
1125 /// \returns true if *this < RHS when considered unsigned.
1126 bool ult(uint64_t RHS) const {
1127 // Only need to check active bits if not a single word.
1128 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() < RHS;
1129 }
1130
1131 /// Signed less than comparison
1132 ///
1133 /// Regards both *this and RHS as signed quantities and compares them for
1134 /// validity of the less-than relationship.
1135 ///
1136 /// \returns true if *this < RHS when both are considered signed.
1137 bool slt(const APInt &RHS) const { return compareSigned(RHS) < 0; }
1138
1139 /// Signed less than comparison
1140 ///
1141 /// Regards both *this as a signed quantity and compares it with RHS for
1142 /// the validity of the less-than relationship.
1143 ///
1144 /// \returns true if *this < RHS when considered signed.
1145 bool slt(int64_t RHS) const {
1146 return (!isSingleWord() && getSignificantBits() > 64)
1147 ? isNegative()
1148 : getSExtValue() < RHS;
1149 }
1150
1151 /// Unsigned less or equal comparison
1152 ///
1153 /// Regards both *this and RHS as unsigned quantities and compares them for
1154 /// validity of the less-or-equal relationship.
1155 ///
1156 /// \returns true if *this <= RHS when both are considered unsigned.
1157 bool ule(const APInt &RHS) const { return compare(RHS) <= 0; }
1158
1159 /// Unsigned less or equal comparison
1160 ///
1161 /// Regards both *this as an unsigned quantity and compares it with RHS for
1162 /// the validity of the less-or-equal relationship.
1163 ///
1164 /// \returns true if *this <= RHS when considered unsigned.
1165 bool ule(uint64_t RHS) const { return !ugt(RHS); }
1166
1167 /// Signed less or equal comparison
1168 ///
1169 /// Regards both *this and RHS as signed quantities and compares them for
1170 /// validity of the less-or-equal relationship.
1171 ///
1172 /// \returns true if *this <= RHS when both are considered signed.
1173 bool sle(const APInt &RHS) const { return compareSigned(RHS) <= 0; }
1174
1175 /// Signed less or equal comparison
1176 ///
1177 /// Regards both *this as a signed quantity and compares it with RHS for the
1178 /// validity of the less-or-equal relationship.
1179 ///
1180 /// \returns true if *this <= RHS when considered signed.
1181 bool sle(uint64_t RHS) const { return !sgt(RHS); }
1182
1183 /// Unsigned greater than comparison
1184 ///
1185 /// Regards both *this and RHS as unsigned quantities and compares them for
1186 /// the validity of the greater-than relationship.
1187 ///
1188 /// \returns true if *this > RHS when both are considered unsigned.
1189 bool ugt(const APInt &RHS) const { return !ule(RHS); }
1190
1191 /// Unsigned greater than comparison
1192 ///
1193 /// Regards both *this as an unsigned quantity and compares it with RHS for
1194 /// the validity of the greater-than relationship.
1195 ///
1196 /// \returns true if *this > RHS when considered unsigned.
1197 bool ugt(uint64_t RHS) const {
1198 // Only need to check active bits if not a single word.
1199 return (!isSingleWord() && getActiveBits() > 64) || getZExtValue() > RHS;
1200 }
1201
1202 /// Signed greater than comparison
1203 ///
1204 /// Regards both *this and RHS as signed quantities and compares them for the
1205 /// validity of the greater-than relationship.
1206 ///
1207 /// \returns true if *this > RHS when both are considered signed.
1208 bool sgt(const APInt &RHS) const { return !sle(RHS); }
1209
1210 /// Signed greater than comparison
1211 ///
1212 /// Regards both *this as a signed quantity and compares it with RHS for
1213 /// the validity of the greater-than relationship.
1214 ///
1215 /// \returns true if *this > RHS when considered signed.
1216 bool sgt(int64_t RHS) const {
1217 return (!isSingleWord() && getSignificantBits() > 64)
1218 ? !isNegative()
1219 : getSExtValue() > RHS;
1220 }
1221
1222 /// Unsigned greater or equal comparison
1223 ///
1224 /// Regards both *this and RHS as unsigned quantities and compares them for
1225 /// validity of the greater-or-equal relationship.
1226 ///
1227 /// \returns true if *this >= RHS when both are considered unsigned.
1228 bool uge(const APInt &RHS) const { return !ult(RHS); }
1229
1230 /// Unsigned greater or equal comparison
1231 ///
1232 /// Regards both *this as an unsigned quantity and compares it with RHS for
1233 /// the validity of the greater-or-equal relationship.
1234 ///
1235 /// \returns true if *this >= RHS when considered unsigned.
1236 bool uge(uint64_t RHS) const { return !ult(RHS); }
1237
1238 /// Signed greater or equal comparison
1239 ///
1240 /// Regards both *this and RHS as signed quantities and compares them for
1241 /// validity of the greater-or-equal relationship.
1242 ///
1243 /// \returns true if *this >= RHS when both are considered signed.
1244 bool sge(const APInt &RHS) const { return !slt(RHS); }
1245
1246 /// Signed greater or equal comparison
1247 ///
1248 /// Regards both *this as a signed quantity and compares it with RHS for
1249 /// the validity of the greater-or-equal relationship.
1250 ///
1251 /// \returns true if *this >= RHS when considered signed.
1252 bool sge(int64_t RHS) const { return !slt(RHS); }
1253
1254 /// This operation tests if there are any pairs of corresponding bits
1255 /// between this APInt and RHS that are both set.
1256 bool intersects(const APInt &RHS) const {
1257 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
1258 if (isSingleWord())
1259 return (U.VAL & RHS.U.VAL) != 0;
1260 return intersectsSlowCase(RHS);
1261 }
1262
1263 /// This operation checks that all bits set in this APInt are also set in RHS.
1264 bool isSubsetOf(const APInt &RHS) const {
1265 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
1266 if (isSingleWord())
1267 return (U.VAL & ~RHS.U.VAL) == 0;
1268 return isSubsetOfSlowCase(RHS);
1269 }
1270
1271 /// @}
1272 /// \name Resizing Operators
1273 /// @{
1274
1275 /// Truncate to new width.
1276 ///
1277 /// Truncate the APInt to a specified width. It is an error to specify a width
1278 /// that is greater than the current width.
1279 LLVM_ABI APInt trunc(unsigned width) const;
1280
1281 /// Truncate to new width with unsigned saturation.
1282 ///
1283 /// If the APInt, treated as unsigned integer, can be losslessly truncated to
1284 /// the new bitwidth, then return truncated APInt. Else, return max value.
1285 LLVM_ABI APInt truncUSat(unsigned width) const;
1286
1287 /// Truncate to new width with signed saturation to signed result.
1288 ///
1289 /// If this APInt, treated as signed integer, can be losslessly truncated to
1290 /// the new bitwidth, then return truncated APInt. Else, return either
1291 /// signed min value if the APInt was negative, or signed max value.
1292 LLVM_ABI APInt truncSSat(unsigned width) const;
1293
1294 /// Truncate to new width with signed saturation to unsigned result.
1295 ///
1296 /// If this APInt, treated as signed integer, can be losslessly truncated to
1297 /// the new bitwidth, then return truncated APInt. Else, return either
1298 /// zero if the APInt was negative, or unsigned max value.
1299 /// If \p width matches the current bit width then no changes are made.
1300 LLVM_ABI APInt truncSSatU(unsigned width) const;
1301
1302 /// Sign extend to a new width.
1303 ///
1304 /// This operation sign extends the APInt to a new width. If the high order
1305 /// bit is set, the fill on the left will be done with 1 bits, otherwise zero.
1306 /// It is an error to specify a width that is less than the
1307 /// current width.
1308 LLVM_ABI APInt sext(unsigned width) const;
1309
1310 /// Zero extend to a new width.
1311 ///
1312 /// This operation zero extends the APInt to a new width. The high order bits
1313 /// are filled with 0 bits. It is an error to specify a width that is less
1314 /// than the current width.
1315 LLVM_ABI APInt zext(unsigned width) const;
1316
1317 /// Sign extend or truncate to width
1318 ///
1319 /// Make this APInt have the bit width given by \p width. The value is sign
1320 /// extended, truncated, or left alone to make it that width.
1321 LLVM_ABI APInt sextOrTrunc(unsigned width) const;
1322
1323 /// Zero extend or truncate to width
1324 ///
1325 /// Make this APInt have the bit width given by \p width. The value is zero
1326 /// extended, truncated, or left alone to make it that width.
1327 LLVM_ABI APInt zextOrTrunc(unsigned width) const;
1328
1329 /// @}
1330 /// \name Bit Manipulation Operators
1331 /// @{
1332
1333 /// Set every bit to 1.
1334 void setAllBits() {
1335 if (isSingleWord())
1336 U.VAL = WORDTYPE_MAX;
1337 else
1338 // Set all the bits in all the words.
1339 memset(U.pVal, -1, getNumWords() * APINT_WORD_SIZE);
1340 // Clear the unused ones
1342 }
1343
1344 /// Set the given bit to 1 whose position is given as "bitPosition".
1345 void setBit(unsigned BitPosition) {
1346 assert(BitPosition < BitWidth && "BitPosition out of range");
1347 WordType Mask = maskBit(BitPosition);
1348 if (isSingleWord())
1349 U.VAL |= Mask;
1350 else
1351 U.pVal[whichWord(BitPosition)] |= Mask;
1352 }
1353
1354 /// Set the sign bit to 1.
1355 void setSignBit() { setBit(BitWidth - 1); }
1356
1357 /// Set a given bit to a given value.
1358 void setBitVal(unsigned BitPosition, bool BitValue) {
1359 if (BitValue)
1360 setBit(BitPosition);
1361 else
1362 clearBit(BitPosition);
1363 }
1364
1365 /// Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
1366 /// This function handles "wrap" case when \p loBit >= \p hiBit, and calls
1367 /// setBits when \p loBit < \p hiBit.
1368 /// For \p loBit == \p hiBit wrap case, set every bit to 1.
1369 void setBitsWithWrap(unsigned loBit, unsigned hiBit) {
1370 assert(hiBit <= BitWidth && "hiBit out of range");
1371 assert(loBit <= BitWidth && "loBit out of range");
1372 if (loBit < hiBit) {
1373 setBits(loBit, hiBit);
1374 return;
1375 }
1376 setLowBits(hiBit);
1377 setHighBits(BitWidth - loBit);
1378 }
1379
1380 /// Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
1381 /// This function handles case when \p loBit <= \p hiBit.
1382 void setBits(unsigned loBit, unsigned hiBit) {
1383 assert(hiBit <= BitWidth && "hiBit out of range");
1384 assert(loBit <= hiBit && "loBit greater than hiBit");
1385 if (loBit == hiBit)
1386 return;
1387 if (hiBit <= APINT_BITS_PER_WORD) {
1388 uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit));
1389 mask <<= loBit;
1390 if (isSingleWord())
1391 U.VAL |= mask;
1392 else
1393 U.pVal[0] |= mask;
1394 } else {
1395 setBitsSlowCase(loBit, hiBit);
1396 }
1397 }
1398
1399 /// Set the top bits starting from loBit.
1400 void setBitsFrom(unsigned loBit) { return setBits(loBit, BitWidth); }
1401
1402 /// Set the bottom loBits bits.
1403 void setLowBits(unsigned loBits) { return setBits(0, loBits); }
1404
1405 /// Set the top hiBits bits.
1406 void setHighBits(unsigned hiBits) {
1407 return setBits(BitWidth - hiBits, BitWidth);
1408 }
1409
1410 /// Set every bit to 0.
1412 if (isSingleWord())
1413 U.VAL = 0;
1414 else
1415 memset(U.pVal, 0, getNumWords() * APINT_WORD_SIZE);
1416 }
1417
1418 /// Set a given bit to 0.
1419 ///
1420 /// Set the given bit to 0 whose position is given as "bitPosition".
1421 void clearBit(unsigned BitPosition) {
1422 assert(BitPosition < BitWidth && "BitPosition out of range");
1423 WordType Mask = ~maskBit(BitPosition);
1424 if (isSingleWord())
1425 U.VAL &= Mask;
1426 else
1427 U.pVal[whichWord(BitPosition)] &= Mask;
1428 }
1429
1430 /// Clear the bits from LoBit (inclusive) to HiBit (exclusive) to 0.
1431 /// This function handles case when \p LoBit <= \p HiBit.
1432 void clearBits(unsigned LoBit, unsigned HiBit) {
1433 assert(HiBit <= BitWidth && "HiBit out of range");
1434 assert(LoBit <= HiBit && "LoBit greater than HiBit");
1435 if (LoBit == HiBit)
1436 return;
1437 if (HiBit <= APINT_BITS_PER_WORD) {
1438 uint64_t Mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - (HiBit - LoBit));
1439 Mask = ~(Mask << LoBit);
1440 if (isSingleWord())
1441 U.VAL &= Mask;
1442 else
1443 U.pVal[0] &= Mask;
1444 } else {
1445 clearBitsSlowCase(LoBit, HiBit);
1446 }
1447 }
1448
1449 /// Set bottom loBits bits to 0.
1450 void clearLowBits(unsigned loBits) {
1451 assert(loBits <= BitWidth && "More bits than bitwidth");
1452 APInt Keep = getHighBitsSet(BitWidth, BitWidth - loBits);
1453 *this &= Keep;
1454 }
1455
1456 /// Set top hiBits bits to 0.
1457 void clearHighBits(unsigned hiBits) {
1458 assert(hiBits <= BitWidth && "More bits than bitwidth");
1459 APInt Keep = getLowBitsSet(BitWidth, BitWidth - hiBits);
1460 *this &= Keep;
1461 }
1462
1463 /// Set the sign bit to 0.
1464 void clearSignBit() { clearBit(BitWidth - 1); }
1465
1466 /// Toggle every bit to its opposite value.
1468 if (isSingleWord()) {
1469 U.VAL ^= WORDTYPE_MAX;
1471 } else {
1472 flipAllBitsSlowCase();
1473 }
1474 }
1475
1476 /// Toggles a given bit to its opposite value.
1477 ///
1478 /// Toggle a given bit to its opposite value whose position is given
1479 /// as "bitPosition".
1480 LLVM_ABI void flipBit(unsigned bitPosition);
1481
1482 /// Negate this APInt in place.
1483 void negate() {
1484 flipAllBits();
1485 ++(*this);
1486 }
1487
1488 /// Insert the bits from a smaller APInt starting at bitPosition.
1489 LLVM_ABI void insertBits(const APInt &SubBits, unsigned bitPosition);
1490 LLVM_ABI void insertBits(uint64_t SubBits, unsigned bitPosition,
1491 unsigned numBits);
1492
1493 /// Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
1494 LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const;
1495 LLVM_ABI uint64_t extractBitsAsZExtValue(unsigned numBits,
1496 unsigned bitPosition) const;
1497
1498 /// @}
1499 /// \name Value Characterization Functions
1500 /// @{
1501
1502 /// Return the number of bits in the APInt.
1503 unsigned getBitWidth() const { return BitWidth; }
1504
1505 /// Get the number of words.
1506 ///
1507 /// Here one word's bitwidth equals to that of uint64_t.
1508 ///
1509 /// \returns the number of words to hold the integer value of this APInt.
1510 unsigned getNumWords() const { return getNumWords(BitWidth); }
1511
1512 /// Get the number of words.
1513 ///
1514 /// *NOTE* Here one word's bitwidth equals to that of uint64_t.
1515 ///
1516 /// \returns the number of words to hold the integer value with a given bit
1517 /// width.
1518 static unsigned getNumWords(unsigned BitWidth) {
1519 return ((uint64_t)BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
1520 }
1521
1522 /// Compute the number of active bits in the value
1523 ///
1524 /// This function returns the number of active bits which is defined as the
1525 /// bit width minus the number of leading zeros. This is used in several
1526 /// computations to see how "wide" the value is.
1527 unsigned getActiveBits() const { return BitWidth - countl_zero(); }
1528
1529 /// Compute the number of active words in the value of this APInt.
1530 ///
1531 /// This is used in conjunction with getActiveData to extract the raw value of
1532 /// the APInt.
1533 unsigned getActiveWords() const {
1534 unsigned numActiveBits = getActiveBits();
1535 return numActiveBits ? whichWord(numActiveBits - 1) + 1 : 1;
1536 }
1537
1538 /// Get the minimum bit size for this signed APInt
1539 ///
1540 /// Computes the minimum bit width for this APInt while considering it to be a
1541 /// signed (and probably negative) value. If the value is not negative, this
1542 /// function returns the same value as getActiveBits()+1. Otherwise, it
1543 /// returns the smallest bit width that will retain the negative value. For
1544 /// example, -1 can be written as 0b1 or 0xFFFFFFFFFF. 0b1 is shorter and so
1545 /// for -1, this function will always return 1.
1546 unsigned getSignificantBits() const {
1547 return BitWidth - getNumSignBits() + 1;
1548 }
1549
1550 /// Get zero extended value
1551 ///
1552 /// This method attempts to return the value of this APInt as a zero extended
1553 /// uint64_t. The bitwidth must be <= 64 or the value must fit within a
1554 /// uint64_t. Otherwise an assertion will result.
1556 if (isSingleWord())
1557 return U.VAL;
1558 assert(getActiveBits() <= 64 && "Too many bits for uint64_t");
1559 return U.pVal[0];
1560 }
1561
1562 /// Get zero extended value if possible
1563 ///
1564 /// This method attempts to return the value of this APInt as a zero extended
1565 /// uint64_t. The bitwidth must be <= 64 or the value must fit within a
1566 /// uint64_t. Otherwise no value is returned.
1567 std::optional<uint64_t> tryZExtValue() const {
1568 return (getActiveBits() <= 64) ? std::optional<uint64_t>(getZExtValue())
1569 : std::nullopt;
1570 };
1571
1572 /// Get sign extended value
1573 ///
1574 /// This method attempts to return the value of this APInt as a sign extended
1575 /// int64_t. The bit width must be <= 64 or the value must fit within an
1576 /// int64_t. Otherwise an assertion will result.
1577 int64_t getSExtValue() const {
1578 if (isSingleWord())
1579 return SignExtend64(U.VAL, BitWidth);
1580 assert(getSignificantBits() <= 64 && "Too many bits for int64_t");
1581 return int64_t(U.pVal[0]);
1582 }
1583
1584 /// Get sign extended value if possible
1585 ///
1586 /// This method attempts to return the value of this APInt as a sign extended
1587 /// int64_t. The bitwidth must be <= 64 or the value must fit within an
1588 /// int64_t. Otherwise no value is returned.
1589 std::optional<int64_t> trySExtValue() const {
1590 return (getSignificantBits() <= 64) ? std::optional<int64_t>(getSExtValue())
1591 : std::nullopt;
1592 };
1593
1594 /// Get bits required for string value.
1595 ///
1596 /// This method determines how many bits are required to hold the APInt
1597 /// equivalent of the string given by \p str.
1598 LLVM_ABI static unsigned getBitsNeeded(StringRef str, uint8_t radix);
1599
1600 /// Get the bits that are sufficient to represent the string value. This may
1601 /// over estimate the amount of bits required, but it does not require
1602 /// parsing the value in the string.
1603 LLVM_ABI static unsigned getSufficientBitsNeeded(StringRef Str,
1604 uint8_t Radix);
1605
1606 /// The APInt version of std::countl_zero.
1607 ///
1608 /// It counts the number of zeros from the most significant bit to the first
1609 /// one bit.
1610 ///
1611 /// \returns BitWidth if the value is zero, otherwise returns the number of
1612 /// zeros from the most significant bit to the first one bits.
1613 unsigned countl_zero() const {
1614 if (isSingleWord()) {
1615 unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth;
1616 return llvm::countl_zero(U.VAL) - unusedBits;
1617 }
1618 return countLeadingZerosSlowCase();
1619 }
1620
1621 unsigned countLeadingZeros() const { return countl_zero(); }
1622
1623 /// Count the number of leading one bits.
1624 ///
1625 /// This function is an APInt version of std::countl_one. It counts the number
1626 /// of ones from the most significant bit to the first zero bit.
1627 ///
1628 /// \returns 0 if the high order bit is not set, otherwise returns the number
1629 /// of 1 bits from the most significant to the least
1630 unsigned countl_one() const {
1631 if (isSingleWord()) {
1632 if (LLVM_UNLIKELY(BitWidth == 0))
1633 return 0;
1634 return llvm::countl_one(U.VAL << (APINT_BITS_PER_WORD - BitWidth));
1635 }
1636 return countLeadingOnesSlowCase();
1637 }
1638
1639 unsigned countLeadingOnes() const { return countl_one(); }
1640
1641 /// Computes the number of leading bits of this APInt that are equal to its
1642 /// sign bit.
1643 unsigned getNumSignBits() const {
1644 return isNegative() ? countl_one() : countl_zero();
1645 }
1646
1647 /// Count the number of trailing zero bits.
1648 ///
1649 /// This function is an APInt version of std::countr_zero. It counts the
1650 /// number of zeros from the least significant bit to the first set bit.
1651 ///
1652 /// \returns BitWidth if the value is zero, otherwise returns the number of
1653 /// zeros from the least significant bit to the first one bit.
1654 unsigned countr_zero() const {
1655 if (isSingleWord()) {
1656 unsigned TrailingZeros = llvm::countr_zero(U.VAL);
1657 return (TrailingZeros > BitWidth ? BitWidth : TrailingZeros);
1658 }
1659 return countTrailingZerosSlowCase();
1660 }
1661
1662 unsigned countTrailingZeros() const { return countr_zero(); }
1663
1664 /// Count the number of trailing one bits.
1665 ///
1666 /// This function is an APInt version of std::countr_one. It counts the number
1667 /// of ones from the least significant bit to the first zero bit.
1668 ///
1669 /// \returns BitWidth if the value is all ones, otherwise returns the number
1670 /// of ones from the least significant bit to the first zero bit.
1671 unsigned countr_one() const {
1672 if (isSingleWord())
1673 return llvm::countr_one(U.VAL);
1674 return countTrailingOnesSlowCase();
1675 }
1676
1677 unsigned countTrailingOnes() const { return countr_one(); }
1678
1679 /// Count the number of bits set.
1680 ///
1681 /// This function is an APInt version of std::popcount. It counts the number
1682 /// of 1 bits in the APInt value.
1683 ///
1684 /// \returns 0 if the value is zero, otherwise returns the number of set bits.
1685 unsigned popcount() const {
1686 if (isSingleWord())
1687 return llvm::popcount(U.VAL);
1688 return countPopulationSlowCase();
1689 }
1690
1691 /// @}
1692 /// \name Conversion Functions
1693 /// @{
1694 LLVM_ABI void print(raw_ostream &OS, bool isSigned) const;
1695
1696 /// Converts an APInt to a string and append it to Str. Str is commonly a
1697 /// SmallString. If Radix > 10, UpperCase determine the case of letter
1698 /// digits.
1699 LLVM_ABI void toString(SmallVectorImpl<char> &Str, unsigned Radix,
1700 bool Signed, bool formatAsCLiteral = false,
1701 bool UpperCase = true,
1702 bool InsertSeparators = false) const;
1703
1704 /// Considers the APInt to be unsigned and converts it into a string in the
1705 /// radix given. The radix can be 2, 8, 10 16, or 36.
1706 void toStringUnsigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
1707 toString(Str, Radix, false, false);
1708 }
1709
1710 /// Considers the APInt to be signed and converts it into a string in the
1711 /// radix given. The radix can be 2, 8, 10, 16, or 36.
1712 void toStringSigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
1713 toString(Str, Radix, true, false);
1714 }
1715
1716 /// \returns a byte-swapped representation of this APInt Value.
1717 LLVM_ABI APInt byteSwap() const;
1718
1719 /// \returns the value with the bit representation reversed of this APInt
1720 /// Value.
1721 LLVM_ABI APInt reverseBits() const;
1722
1723 /// Converts this APInt to a double value.
1724 LLVM_ABI double roundToDouble(bool isSigned) const;
1725
1726 /// Converts this unsigned APInt to a double value.
1727 double roundToDouble() const { return roundToDouble(false); }
1728
1729 /// Converts this signed APInt to a double value.
1730 double signedRoundToDouble() const { return roundToDouble(true); }
1731
1732 /// Converts APInt bits to a double
1733 ///
1734 /// The conversion does not do a translation from integer to double, it just
1735 /// re-interprets the bits as a double. Note that it is valid to do this on
1736 /// any bit width. Exactly 64 bits will be translated.
1737 double bitsToDouble() const { return llvm::bit_cast<double>(getWord(0)); }
1738
1739#ifdef HAS_IEE754_FLOAT128
1740 float128 bitsToQuad() const {
1741 __uint128_t ul = ((__uint128_t)U.pVal[1] << 64) + U.pVal[0];
1742 return llvm::bit_cast<float128>(ul);
1743 }
1744#endif
1745
1746 /// Converts APInt bits to a float
1747 ///
1748 /// The conversion does not do a translation from integer to float, it just
1749 /// re-interprets the bits as a float. Note that it is valid to do this on
1750 /// any bit width. Exactly 32 bits will be translated.
1751 float bitsToFloat() const {
1752 return llvm::bit_cast<float>(static_cast<uint32_t>(getWord(0)));
1753 }
1754
1755 /// Converts a double to APInt bits.
1756 ///
1757 /// The conversion does not do a translation from double to integer, it just
1758 /// re-interprets the bits of the double.
1759 static APInt doubleToBits(double V) {
1760 return APInt(sizeof(double) * CHAR_BIT, llvm::bit_cast<uint64_t>(V));
1761 }
1762
1763 /// Converts a float to APInt bits.
1764 ///
1765 /// The conversion does not do a translation from float to integer, it just
1766 /// re-interprets the bits of the float.
1767 static APInt floatToBits(float V) {
1768 return APInt(sizeof(float) * CHAR_BIT, llvm::bit_cast<uint32_t>(V));
1769 }
1770
1771 /// @}
1772 /// \name Mathematics Operations
1773 /// @{
1774
1775 /// \returns the floor log base 2 of this APInt.
1776 unsigned logBase2() const { return getActiveBits() - 1; }
1777
1778 /// \returns the ceil log base 2 of this APInt.
1779 unsigned ceilLogBase2() const {
1780 APInt temp(*this);
1781 --temp;
1782 return temp.getActiveBits();
1783 }
1784
1785 /// \returns the nearest log base 2 of this APInt. Ties round up.
1786 ///
1787 /// NOTE: When we have a BitWidth of 1, we define:
1788 ///
1789 /// log2(0) = UINT32_MAX
1790 /// log2(1) = 0
1791 ///
1792 /// to get around any mathematical concerns resulting from
1793 /// referencing 2 in a space where 2 does no exist.
1794 LLVM_ABI unsigned nearestLogBase2() const;
1795
1796 /// \returns the log base 2 of this APInt if its an exact power of two, -1
1797 /// otherwise
1798 int32_t exactLogBase2() const {
1799 if (!isPowerOf2())
1800 return -1;
1801 return logBase2();
1802 }
1803
1804 /// Compute the square root.
1805 LLVM_ABI APInt sqrt() const;
1806
1807 /// Get the absolute value. If *this is < 0 then return -(*this), otherwise
1808 /// *this. Note that the "most negative" signed number (e.g. -128 for 8 bit
1809 /// wide APInt) is unchanged due to how negation works.
1810 APInt abs() const {
1811 if (isNegative())
1812 return -(*this);
1813 return *this;
1814 }
1815
1816 /// \returns the multiplicative inverse of an odd APInt modulo 2^BitWidth.
1817 LLVM_ABI APInt multiplicativeInverse() const;
1818
1819 /// @}
1820 /// \name Building-block Operations for APInt and APFloat
1821 /// @{
1822
1823 // These building block operations operate on a representation of arbitrary
1824 // precision, two's-complement, bignum integer values. They should be
1825 // sufficient to implement APInt and APFloat bignum requirements. Inputs are
1826 // generally a pointer to the base of an array of integer parts, representing
1827 // an unsigned bignum, and a count of how many parts there are.
1828
1829 /// Sets the least significant part of a bignum to the input value, and zeroes
1830 /// out higher parts.
1831 LLVM_ABI static void tcSet(WordType *, WordType, unsigned);
1832
1833 /// Assign one bignum to another.
1834 LLVM_ABI static void tcAssign(WordType *, const WordType *, unsigned);
1835
1836 /// Returns true if a bignum is zero, false otherwise.
1837 LLVM_ABI static bool tcIsZero(const WordType *, unsigned);
1838
1839 /// Extract the given bit of a bignum; returns 0 or 1. Zero-based.
1840 LLVM_ABI static int tcExtractBit(const WordType *, unsigned bit);
1841
1842 /// Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to
1843 /// DST, of dstCOUNT parts, such that the bit srcLSB becomes the least
1844 /// significant bit of DST. All high bits above srcBITS in DST are
1845 /// zero-filled.
1846 LLVM_ABI static void tcExtract(WordType *, unsigned dstCount,
1847 const WordType *, unsigned srcBits,
1848 unsigned srcLSB);
1849
1850 /// Set the given bit of a bignum. Zero-based.
1851 LLVM_ABI static void tcSetBit(WordType *, unsigned bit);
1852
1853 /// Clear the given bit of a bignum. Zero-based.
1854 LLVM_ABI static void tcClearBit(WordType *, unsigned bit);
1855
1856 /// Returns the bit number of the least or most significant set bit of a
1857 /// number. If the input number has no bits set -1U is returned.
1858 LLVM_ABI static unsigned tcLSB(const WordType *, unsigned n);
1859 LLVM_ABI static unsigned tcMSB(const WordType *parts, unsigned n);
1860
1861 /// Negate a bignum in-place.
1862 LLVM_ABI static void tcNegate(WordType *, unsigned);
1863
1864 /// DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
1865 LLVM_ABI static WordType tcAdd(WordType *, const WordType *, WordType carry,
1866 unsigned);
1867 /// DST += RHS. Returns the carry flag.
1868 LLVM_ABI static WordType tcAddPart(WordType *, WordType, unsigned);
1869
1870 /// DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
1871 LLVM_ABI static WordType tcSubtract(WordType *, const WordType *,
1872 WordType carry, unsigned);
1873 /// DST -= RHS. Returns the carry flag.
1874 LLVM_ABI static WordType tcSubtractPart(WordType *, WordType, unsigned);
1875
1876 /// DST += SRC * MULTIPLIER + PART if add is true
1877 /// DST = SRC * MULTIPLIER + PART if add is false
1878 ///
1879 /// Requires 0 <= DSTPARTS <= SRCPARTS + 1. If DST overlaps SRC they must
1880 /// start at the same point, i.e. DST == SRC.
1881 ///
1882 /// If DSTPARTS == SRC_PARTS + 1 no overflow occurs and zero is returned.
1883 /// Otherwise DST is filled with the least significant DSTPARTS parts of the
1884 /// result, and if all of the omitted higher parts were zero return zero,
1885 /// otherwise overflow occurred and return one.
1886 LLVM_ABI static int tcMultiplyPart(WordType *dst, const WordType *src,
1887 WordType multiplier, WordType carry,
1888 unsigned srcParts, unsigned dstParts,
1889 bool add);
1890
1891 /// DST = LHS * RHS, where DST has the same width as the operands and is
1892 /// filled with the least significant parts of the result. Returns one if
1893 /// overflow occurred, otherwise zero. DST must be disjoint from both
1894 /// operands.
1895 LLVM_ABI static int tcMultiply(WordType *, const WordType *, const WordType *,
1896 unsigned);
1897
1898 /// DST = LHS * RHS, where DST has width the sum of the widths of the
1899 /// operands. No overflow occurs. DST must be disjoint from both operands.
1900 LLVM_ABI static void tcFullMultiply(WordType *, const WordType *,
1901 const WordType *, unsigned, unsigned);
1902
1903 /// If RHS is zero LHS and REMAINDER are left unchanged, return one.
1904 /// Otherwise set LHS to LHS / RHS with the fractional part discarded, set
1905 /// REMAINDER to the remainder, return zero. i.e.
1906 ///
1907 /// OLD_LHS = RHS * LHS + REMAINDER
1908 ///
1909 /// SCRATCH is a bignum of the same size as the operands and result for use by
1910 /// the routine; its contents need not be initialized and are destroyed. LHS,
1911 /// REMAINDER and SCRATCH must be distinct.
1912 LLVM_ABI static int tcDivide(WordType *lhs, const WordType *rhs,
1913 WordType *remainder, WordType *scratch,
1914 unsigned parts);
1915
1916 /// Shift a bignum left Count bits. Shifted in bits are zero. There are no
1917 /// restrictions on Count.
1918 LLVM_ABI static void tcShiftLeft(WordType *, unsigned Words, unsigned Count);
1919
1920 /// Shift a bignum right Count bits. Shifted in bits are zero. There are no
1921 /// restrictions on Count.
1922 LLVM_ABI static void tcShiftRight(WordType *, unsigned Words, unsigned Count);
1923
1924 /// Comparison (unsigned) of two bignums.
1925 LLVM_ABI static int tcCompare(const WordType *, const WordType *, unsigned);
1926
1927 /// Increment a bignum in-place. Return the carry flag.
1928 static WordType tcIncrement(WordType *dst, unsigned parts) {
1929 return tcAddPart(dst, 1, parts);
1930 }
1931
1932 /// Decrement a bignum in-place. Return the borrow flag.
1933 static WordType tcDecrement(WordType *dst, unsigned parts) {
1934 return tcSubtractPart(dst, 1, parts);
1935 }
1936
1937 /// Used to insert APInt objects, or objects that contain APInt objects, into
1938 /// FoldingSets.
1939 LLVM_ABI void Profile(FoldingSetNodeID &id) const;
1940
1941#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1942 /// debug method
1943 LLVM_DUMP_METHOD void dump() const;
1944#endif
1945
1946 /// Returns whether this instance allocated memory.
1947 bool needsCleanup() const { return !isSingleWord(); }
1948
1949private:
1950 /// This union is used to store the integer value. When the
1951 /// integer bit-width <= 64, it uses VAL, otherwise it uses pVal.
1952 union {
1953 uint64_t VAL; ///< Used to store the <= 64 bits integer value.
1954 uint64_t *pVal; ///< Used to store the >64 bits integer value.
1955 } U;
1956
1957 unsigned BitWidth = 1; ///< The number of bits in this APInt.
1958
1959 friend struct DenseMapInfo<APInt, void>;
1960 friend class APSInt;
1961
1962 // Make DynamicAPInt a friend so it can access BitWidth directly.
1963 friend DynamicAPInt;
1964
1965 /// This constructor is used only internally for speed of construction of
1966 /// temporaries. It is unsafe since it takes ownership of the pointer, so it
1967 /// is not public.
1968 APInt(uint64_t *val, unsigned bits) : BitWidth(bits) { U.pVal = val; }
1969
1970 /// Determine which word a bit is in.
1971 ///
1972 /// \returns the word position for the specified bit position.
1973 static unsigned whichWord(unsigned bitPosition) {
1974 return bitPosition / APINT_BITS_PER_WORD;
1975 }
1976
1977 /// Determine which bit in a word the specified bit position is in.
1978 static unsigned whichBit(unsigned bitPosition) {
1979 return bitPosition % APINT_BITS_PER_WORD;
1980 }
1981
1982 /// Get a single bit mask.
1983 ///
1984 /// \returns a uint64_t with only bit at "whichBit(bitPosition)" set
1985 /// This method generates and returns a uint64_t (word) mask for a single
1986 /// bit at a specific bit position. This is used to mask the bit in the
1987 /// corresponding word.
1988 static uint64_t maskBit(unsigned bitPosition) {
1989 return 1ULL << whichBit(bitPosition);
1990 }
1991
1992 /// Clear unused high order bits
1993 ///
1994 /// This method is used internally to clear the top "N" bits in the high order
1995 /// word that are not used by the APInt. This is needed after the most
1996 /// significant word is assigned a value to ensure that those bits are
1997 /// zero'd out.
1998 APInt &clearUnusedBits() {
1999 // Compute how many bits are used in the final word.
2000 unsigned WordBits = ((BitWidth - 1) % APINT_BITS_PER_WORD) + 1;
2001
2002 // Mask out the high bits.
2003 uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - WordBits);
2004 if (LLVM_UNLIKELY(BitWidth == 0))
2005 mask = 0;
2006
2007 if (isSingleWord())
2008 U.VAL &= mask;
2009 else
2010 U.pVal[getNumWords() - 1] &= mask;
2011 return *this;
2012 }
2013
2014 /// Get the word corresponding to a bit position
2015 /// \returns the corresponding word for the specified bit position.
2016 uint64_t getWord(unsigned bitPosition) const {
2017 return isSingleWord() ? U.VAL : U.pVal[whichWord(bitPosition)];
2018 }
2019
2020 /// Utility method to change the bit width of this APInt to new bit width,
2021 /// allocating and/or deallocating as necessary. There is no guarantee on the
2022 /// value of any bits upon return. Caller should populate the bits after.
2023 void reallocate(unsigned NewBitWidth);
2024
2025 /// Convert a char array into an APInt
2026 ///
2027 /// \param radix 2, 8, 10, 16, or 36
2028 /// Converts a string into a number. The string must be non-empty
2029 /// and well-formed as a number of the given base. The bit-width
2030 /// must be sufficient to hold the result.
2031 ///
2032 /// This is used by the constructors that take string arguments.
2033 ///
2034 /// StringRef::getAsInteger is superficially similar but (1) does
2035 /// not assume that the string is well-formed and (2) grows the
2036 /// result to hold the input.
2037 void fromString(unsigned numBits, StringRef str, uint8_t radix);
2038
2039 /// An internal division function for dividing APInts.
2040 ///
2041 /// This is used by the toString method to divide by the radix. It simply
2042 /// provides a more convenient form of divide for internal use since KnuthDiv
2043 /// has specific constraints on its inputs. If those constraints are not met
2044 /// then it provides a simpler form of divide.
2045 static void divide(const WordType *LHS, unsigned lhsWords,
2046 const WordType *RHS, unsigned rhsWords, WordType *Quotient,
2047 WordType *Remainder);
2048
2049 /// out-of-line slow case for inline constructor
2050 LLVM_ABI void initSlowCase(uint64_t val, bool isSigned);
2051
2052 /// shared code between two array constructors
2053 void initFromArray(ArrayRef<uint64_t> array);
2054
2055 /// out-of-line slow case for inline copy constructor
2056 LLVM_ABI void initSlowCase(const APInt &that);
2057
2058 /// out-of-line slow case for shl
2059 LLVM_ABI void shlSlowCase(unsigned ShiftAmt);
2060
2061 /// out-of-line slow case for lshr.
2062 LLVM_ABI void lshrSlowCase(unsigned ShiftAmt);
2063
2064 /// out-of-line slow case for ashr.
2065 LLVM_ABI void ashrSlowCase(unsigned ShiftAmt);
2066
2067 /// out-of-line slow case for operator=
2068 LLVM_ABI void assignSlowCase(const APInt &RHS);
2069
2070 /// out-of-line slow case for operator==
2071 LLVM_ABI bool equalSlowCase(const APInt &RHS) const LLVM_READONLY;
2072
2073 /// out-of-line slow case for countLeadingZeros
2074 LLVM_ABI unsigned countLeadingZerosSlowCase() const LLVM_READONLY;
2075
2076 /// out-of-line slow case for countLeadingOnes.
2077 LLVM_ABI unsigned countLeadingOnesSlowCase() const LLVM_READONLY;
2078
2079 /// out-of-line slow case for countTrailingZeros.
2080 LLVM_ABI unsigned countTrailingZerosSlowCase() const LLVM_READONLY;
2081
2082 /// out-of-line slow case for countTrailingOnes
2083 LLVM_ABI unsigned countTrailingOnesSlowCase() const LLVM_READONLY;
2084
2085 /// out-of-line slow case for countPopulation
2086 LLVM_ABI unsigned countPopulationSlowCase() const LLVM_READONLY;
2087
2088 /// out-of-line slow case for intersects.
2089 LLVM_ABI bool intersectsSlowCase(const APInt &RHS) const LLVM_READONLY;
2090
2091 /// out-of-line slow case for isSubsetOf.
2092 LLVM_ABI bool isSubsetOfSlowCase(const APInt &RHS) const LLVM_READONLY;
2093
2094 /// out-of-line slow case for setBits.
2095 LLVM_ABI void setBitsSlowCase(unsigned loBit, unsigned hiBit);
2096
2097 /// out-of-line slow case for clearBits.
2098 LLVM_ABI void clearBitsSlowCase(unsigned LoBit, unsigned HiBit);
2099
2100 /// out-of-line slow case for flipAllBits.
2101 LLVM_ABI void flipAllBitsSlowCase();
2102
2103 /// out-of-line slow case for concat.
2104 LLVM_ABI APInt concatSlowCase(const APInt &NewLSB) const;
2105
2106 /// out-of-line slow case for operator&=.
2107 LLVM_ABI void andAssignSlowCase(const APInt &RHS);
2108
2109 /// out-of-line slow case for operator|=.
2110 LLVM_ABI void orAssignSlowCase(const APInt &RHS);
2111
2112 /// out-of-line slow case for operator^=.
2113 LLVM_ABI void xorAssignSlowCase(const APInt &RHS);
2114
2115 /// Unsigned comparison. Returns -1, 0, or 1 if this APInt is less than, equal
2116 /// to, or greater than RHS.
2117 LLVM_ABI int compare(const APInt &RHS) const LLVM_READONLY;
2118
2119 /// Signed comparison. Returns -1, 0, or 1 if this APInt is less than, equal
2120 /// to, or greater than RHS.
2121 LLVM_ABI int compareSigned(const APInt &RHS) const LLVM_READONLY;
2122
2123 /// @}
2124};
2125
2126inline bool operator==(uint64_t V1, const APInt &V2) { return V2 == V1; }
2127
2128inline bool operator!=(uint64_t V1, const APInt &V2) { return V2 != V1; }
2129
2130/// Unary bitwise complement operator.
2131///
2132/// \returns an APInt that is the bitwise complement of \p v.
2134 v.flipAllBits();
2135 return v;
2136}
2137
2138inline APInt operator&(APInt a, const APInt &b) {
2139 a &= b;
2140 return a;
2141}
2142
2143inline APInt operator&(const APInt &a, APInt &&b) {
2144 b &= a;
2145 return std::move(b);
2146}
2147
2149 a &= RHS;
2150 return a;
2151}
2152
2154 b &= LHS;
2155 return b;
2156}
2157
2158inline APInt operator|(APInt a, const APInt &b) {
2159 a |= b;
2160 return a;
2161}
2162
2163inline APInt operator|(const APInt &a, APInt &&b) {
2164 b |= a;
2165 return std::move(b);
2166}
2167
2169 a |= RHS;
2170 return a;
2171}
2172
2174 b |= LHS;
2175 return b;
2176}
2177
2178inline APInt operator^(APInt a, const APInt &b) {
2179 a ^= b;
2180 return a;
2181}
2182
2183inline APInt operator^(const APInt &a, APInt &&b) {
2184 b ^= a;
2185 return std::move(b);
2186}
2187
2189 a ^= RHS;
2190 return a;
2191}
2192
2194 b ^= LHS;
2195 return b;
2196}
2197
2199 I.print(OS, true);
2200 return OS;
2201}
2202
2204 v.negate();
2205 return v;
2206}
2207
2208inline APInt operator+(APInt a, const APInt &b) {
2209 a += b;
2210 return a;
2211}
2212
2213inline APInt operator+(const APInt &a, APInt &&b) {
2214 b += a;
2215 return std::move(b);
2216}
2217
2219 a += RHS;
2220 return a;
2221}
2222
2224 b += LHS;
2225 return b;
2226}
2227
2228inline APInt operator-(APInt a, const APInt &b) {
2229 a -= b;
2230 return a;
2231}
2232
2233inline APInt operator-(const APInt &a, APInt &&b) {
2234 b.negate();
2235 b += a;
2236 return std::move(b);
2237}
2238
2240 a -= RHS;
2241 return a;
2242}
2243
2245 b.negate();
2246 b += LHS;
2247 return b;
2248}
2249
2251 a *= RHS;
2252 return a;
2253}
2254
2256 b *= LHS;
2257 return b;
2258}
2259
2260namespace APIntOps {
2261
2262/// Determine the smaller of two APInts considered to be signed.
2263inline const APInt &smin(const APInt &A, const APInt &B) {
2264 return A.slt(B) ? A : B;
2265}
2266
2267/// Determine the larger of two APInts considered to be signed.
2268inline const APInt &smax(const APInt &A, const APInt &B) {
2269 return A.sgt(B) ? A : B;
2270}
2271
2272/// Determine the smaller of two APInts considered to be unsigned.
2273inline const APInt &umin(const APInt &A, const APInt &B) {
2274 return A.ult(B) ? A : B;
2275}
2276
2277/// Determine the larger of two APInts considered to be unsigned.
2278inline const APInt &umax(const APInt &A, const APInt &B) {
2279 return A.ugt(B) ? A : B;
2280}
2281
2282/// Determine the absolute difference of two APInts considered to be signed.
2283inline APInt abds(const APInt &A, const APInt &B) {
2284 return A.sge(B) ? (A - B) : (B - A);
2285}
2286
2287/// Determine the absolute difference of two APInts considered to be unsigned.
2288inline APInt abdu(const APInt &A, const APInt &B) {
2289 return A.uge(B) ? (A - B) : (B - A);
2290}
2291
2292/// Compute the floor of the signed average of C1 and C2
2293LLVM_ABI APInt avgFloorS(const APInt &C1, const APInt &C2);
2294
2295/// Compute the floor of the unsigned average of C1 and C2
2296LLVM_ABI APInt avgFloorU(const APInt &C1, const APInt &C2);
2297
2298/// Compute the ceil of the signed average of C1 and C2
2299LLVM_ABI APInt avgCeilS(const APInt &C1, const APInt &C2);
2300
2301/// Compute the ceil of the unsigned average of C1 and C2
2302LLVM_ABI APInt avgCeilU(const APInt &C1, const APInt &C2);
2303
2304/// Performs (2*N)-bit multiplication on sign-extended operands.
2305/// Returns the high N bits of the multiplication result.
2306LLVM_ABI APInt mulhs(const APInt &C1, const APInt &C2);
2307
2308/// Performs (2*N)-bit multiplication on zero-extended operands.
2309/// Returns the high N bits of the multiplication result.
2310LLVM_ABI APInt mulhu(const APInt &C1, const APInt &C2);
2311
2312/// Performs (2*N)-bit multiplication on sign-extended operands.
2313LLVM_ABI APInt mulsExtended(const APInt &C1, const APInt &C2);
2314
2315/// Performs (2*N)-bit multiplication on zero-extended operands.
2316LLVM_ABI APInt muluExtended(const APInt &C1, const APInt &C2);
2317
2318/// Compute X^N for N>=0.
2319/// 0^0 is supported and returns 1.
2320LLVM_ABI APInt pow(const APInt &X, int64_t N);
2321
2322/// Compute GCD of two unsigned APInt values.
2323///
2324/// This function returns the greatest common divisor of the two APInt values
2325/// using Stein's algorithm.
2326///
2327/// \returns the greatest common divisor of A and B.
2328LLVM_ABI APInt GreatestCommonDivisor(APInt A, APInt B);
2329
2330/// Converts the given APInt to a double value.
2331///
2332/// Treats the APInt as an unsigned value for conversion purposes.
2333inline double RoundAPIntToDouble(const APInt &APIVal) {
2334 return APIVal.roundToDouble();
2335}
2336
2337/// Converts the given APInt to a double value.
2338///
2339/// Treats the APInt as a signed value for conversion purposes.
2340inline double RoundSignedAPIntToDouble(const APInt &APIVal) {
2341 return APIVal.signedRoundToDouble();
2342}
2343
2344/// Converts the given APInt to a float value.
2345inline float RoundAPIntToFloat(const APInt &APIVal) {
2346 return float(RoundAPIntToDouble(APIVal));
2347}
2348
2349/// Converts the given APInt to a float value.
2350///
2351/// Treats the APInt as a signed value for conversion purposes.
2352inline float RoundSignedAPIntToFloat(const APInt &APIVal) {
2353 return float(APIVal.signedRoundToDouble());
2354}
2355
2356/// Converts the given double value into a APInt.
2357///
2358/// This function convert a double value to an APInt value.
2359LLVM_ABI APInt RoundDoubleToAPInt(double Double, unsigned width);
2360
2361/// Converts a float value into a APInt.
2362///
2363/// Converts a float value into an APInt value.
2364inline APInt RoundFloatToAPInt(float Float, unsigned width) {
2365 return RoundDoubleToAPInt(double(Float), width);
2366}
2367
2368/// Return A unsign-divided by B, rounded by the given rounding mode.
2369LLVM_ABI APInt RoundingUDiv(const APInt &A, const APInt &B, APInt::Rounding RM);
2370
2371/// Return A sign-divided by B, rounded by the given rounding mode.
2372LLVM_ABI APInt RoundingSDiv(const APInt &A, const APInt &B, APInt::Rounding RM);
2373
2374/// Let q(n) = An^2 + Bn + C, and BW = bit width of the value range
2375/// (e.g. 32 for i32).
2376/// This function finds the smallest number n, such that
2377/// (a) n >= 0 and q(n) = 0, or
2378/// (b) n >= 1 and q(n-1) and q(n), when evaluated in the set of all
2379/// integers, belong to two different intervals [Rk, Rk+R),
2380/// where R = 2^BW, and k is an integer.
2381/// The idea here is to find when q(n) "overflows" 2^BW, while at the
2382/// same time "allowing" subtraction. In unsigned modulo arithmetic a
2383/// subtraction (treated as addition of negated numbers) would always
2384/// count as an overflow, but here we want to allow values to decrease
2385/// and increase as long as they are within the same interval.
2386/// Specifically, adding of two negative numbers should not cause an
2387/// overflow (as long as the magnitude does not exceed the bit width).
2388/// On the other hand, given a positive number, adding a negative
2389/// number to it can give a negative result, which would cause the
2390/// value to go from [-2^BW, 0) to [0, 2^BW). In that sense, zero is
2391/// treated as a special case of an overflow.
2392///
2393/// This function returns std::nullopt if after finding k that minimizes the
2394/// positive solution to q(n) = kR, both solutions are contained between
2395/// two consecutive integers.
2396///
2397/// There are cases where q(n) > T, and q(n+1) < T (assuming evaluation
2398/// in arithmetic modulo 2^BW, and treating the values as signed) by the
2399/// virtue of *signed* overflow. This function will *not* find such an n,
2400/// however it may find a value of n satisfying the inequalities due to
2401/// an *unsigned* overflow (if the values are treated as unsigned).
2402/// To find a solution for a signed overflow, treat it as a problem of
2403/// finding an unsigned overflow with a range with of BW-1.
2404///
2405/// The returned value may have a different bit width from the input
2406/// coefficients.
2407LLVM_ABI std::optional<APInt>
2408SolveQuadraticEquationWrap(APInt A, APInt B, APInt C, unsigned RangeWidth);
2409
2410/// Compare two values, and if they are different, return the position of the
2411/// most significant bit that is different in the values.
2412LLVM_ABI std::optional<unsigned> GetMostSignificantDifferentBit(const APInt &A,
2413 const APInt &B);
2414
2415/// Splat/Merge neighboring bits to widen/narrow the bitmask represented
2416/// by \param A to \param NewBitWidth bits.
2417///
2418/// MatchAnyBits: (Default)
2419/// e.g. ScaleBitMask(0b0101, 8) -> 0b00110011
2420/// e.g. ScaleBitMask(0b00011011, 4) -> 0b0111
2421///
2422/// MatchAllBits:
2423/// e.g. ScaleBitMask(0b0101, 8) -> 0b00110011
2424/// e.g. ScaleBitMask(0b00011011, 4) -> 0b0001
2425/// A.getBitwidth() or NewBitWidth must be a whole multiples of the other.
2426LLVM_ABI APInt ScaleBitMask(const APInt &A, unsigned NewBitWidth,
2427 bool MatchAllBits = false);
2428
2429/// Perform a funnel shift left.
2430///
2431/// Concatenate Hi and Lo (Hi is the most significant bits of the wide value),
2432/// the combined value is shifted left by Shift (modulo the bit width of the
2433/// original arguments), and the most significant bits are extracted to produce
2434/// a result that is the same size as the original arguments.
2435///
2436/// Examples:
2437/// (1) fshl(i8 255, i8 0, i8 15) = 128 (0b10000000)
2438/// (2) fshl(i8 15, i8 15, i8 11) = 120 (0b01111000)
2439/// (3) fshl(i8 0, i8 255, i8 8) = 0 (0b00000000)
2440/// (4) fshl(i8 255, i8 0, i8 15) = fshl(i8 255, i8 0, i8 7) // 15 % 8
2441LLVM_ABI APInt fshl(const APInt &Hi, const APInt &Lo, const APInt &Shift);
2442
2443/// Perform a funnel shift right.
2444///
2445/// Concatenate Hi and Lo (Hi is the most significant bits of the wide value),
2446/// the combined value is shifted right by Shift (modulo the bit width of the
2447/// original arguments), and the least significant bits are extracted to produce
2448/// a result that is the same size as the original arguments.
2449///
2450/// Examples:
2451/// (1) fshr(i8 255, i8 0, i8 15) = 254 (0b11111110)
2452/// (2) fshr(i8 15, i8 15, i8 11) = 225 (0b11100001)
2453/// (3) fshr(i8 0, i8 255, i8 8) = 255 (0b11111111)
2454/// (4) fshr(i8 255, i8 0, i8 9) = fshr(i8 255, i8 0, i8 1) // 9 % 8
2455LLVM_ABI APInt fshr(const APInt &Hi, const APInt &Lo, const APInt &Shift);
2456
2457/// Perform a carry-less multiply, also known as XOR multiplication, and return
2458/// low-bits. All arguments and result have the same bitwidth.
2459///
2460/// Examples:
2461/// (1) clmul(i4 1, i4 2) = 2
2462/// (2) clmul(i4 5, i4 6) = 14
2463/// (3) clmul(i4 -4, i4 2) = -8
2464/// (4) clmul(i4 -4, i4 -5) = 4
2465LLVM_ABI APInt clmul(const APInt &LHS, const APInt &RHS);
2466
2467/// Perform a reversed carry-less multiply.
2468///
2469/// clmulr(a, b) = bitreverse(clmul(bitreverse(a), bitreverse(b)))
2470LLVM_ABI APInt clmulr(const APInt &LHS, const APInt &RHS);
2471
2472/// Perform a carry-less multiply, and return high-bits. All arguments and
2473/// result have the same bitwidth.
2474///
2475/// clmulh(a, b) = clmulr(a, b) >> 1
2476LLVM_ABI APInt clmulh(const APInt &LHS, const APInt &RHS);
2477
2478} // namespace APIntOps
2479
2480// See friend declaration above. This additional declaration is required in
2481// order to compile LLVM with IBM xlC compiler.
2482LLVM_ABI hash_code hash_value(const APInt &Arg);
2483
2484/// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
2485/// with the integer held in IntVal.
2486LLVM_ABI void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst,
2487 unsigned StoreBytes);
2488
2489/// LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting
2490/// from Src into IntVal, which is assumed to be wide enough and to hold zero.
2491LLVM_ABI void LoadIntFromMemory(APInt &IntVal, const uint8_t *Src,
2492 unsigned LoadBytes);
2493
2494/// Provide DenseMapInfo for APInt.
2495template <> struct DenseMapInfo<APInt, void> {
2496 static inline APInt getEmptyKey() {
2497 APInt V(nullptr, 0);
2498 V.U.VAL = ~0ULL;
2499 return V;
2500 }
2501
2502 static inline APInt getTombstoneKey() {
2503 APInt V(nullptr, 0);
2504 V.U.VAL = ~1ULL;
2505 return V;
2506 }
2507
2508 LLVM_ABI static unsigned getHashValue(const APInt &Key);
2509
2510 static bool isEqual(const APInt &LHS, const APInt &RHS) {
2511 return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
2512 }
2513};
2514
2515} // namespace llvm
2516
2517#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
always inline
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static constexpr unsigned long long mask(BlockVerifier::State S)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
raw_ostream & operator<<(raw_ostream &OS, const binary_le_impl< value_type > &BLE)
#define LLVM_UNLIKELY(EXPR)
Definition Compiler.h:336
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
#define LLVM_READONLY
Definition Compiler.h:322
static KnownBits extractBits(unsigned BitWidth, const KnownBits &SrcOpKnown, const KnownBits &OffsetKnown, const KnownBits &WidthKnown)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Definition Lint.cpp:539
static bool isAligned(const Value *Base, Align Alignment, const DataLayout &DL)
Definition Loads.cpp:30
static bool isSplat(Value *V)
Return true if V is a splat of a value (which is used when multiplying a matrix with a scalar).
#define I(x, y, z)
Definition MD5.cpp:57
static const char * toString(MIToken::TokenKind TokenKind)
Definition MIParser.cpp:625
Load MIR Sample Profile
const uint64_t BitWidth
static uint64_t clearUnusedBits(uint64_t Val, unsigned Size)
static uint64_t umul_ov(uint64_t i, uint64_t j, bool &Overflow)
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
std::optional< uint64_t > tryZExtValue() const
Get zero extended value if possible.
Definition APInt.h:1567
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition APInt.h:235
bool slt(int64_t RHS) const
Signed less than comparison.
Definition APInt.h:1145
void clearBit(unsigned BitPosition)
Set a given bit to 0.
Definition APInt.h:1421
APInt relativeLShr(int RelativeShift) const
relative logical shift right
Definition APInt.h:887
bool isNegatedPowerOf2() const
Check if this APInt's negated value is a power of two greater than zero.
Definition APInt.h:450
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
Definition APInt.h:230
bool isMinSignedValue() const
Determine if this is the smallest signed value.
Definition APInt.h:424
APInt operator--(int)
Postfix decrement operator.
Definition APInt.h:603
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1555
uint64_t * pVal
Used to store the >64 bits integer value.
Definition APInt.h:1954
friend class APSInt
Definition APInt.h:1960
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
Definition APInt.h:1406
unsigned popcount() const
Count the number of bits set.
Definition APInt.h:1685
~APInt()
Destructor.
Definition APInt.h:191
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
Definition APInt.h:1400
APInt operator<<(const APInt &Bits) const
Left logical shift operator.
Definition APInt.h:829
bool isMask() const
Definition APInt.h:502
APInt operator<<(unsigned Bits) const
Left logical shift operator.
Definition APInt.h:824
unsigned getActiveBits() const
Compute the number of active bits in the value.
Definition APInt.h:1527
bool sgt(int64_t RHS) const
Signed greater than comparison.
Definition APInt.h:1216
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition APInt.h:207
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
Definition APInt.h:1345
bool operator[](unsigned bitPosition) const
Array-indexing support.
Definition APInt.h:1050
bool operator!=(const APInt &RHS) const
Inequality operator.
Definition APInt.h:1094
void toStringUnsigned(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be unsigned and converts it into a string in the radix given.
Definition APInt.h:1706
APInt & operator&=(const APInt &RHS)
Bitwise AND assignment operator.
Definition APInt.h:681
APInt abs() const
Get the absolute value.
Definition APInt.h:1810
unsigned ceilLogBase2() const
Definition APInt.h:1779
unsigned countLeadingOnes() const
Definition APInt.h:1639
APInt relativeLShl(int RelativeShift) const
relative logical shift left
Definition APInt.h:892
APInt & operator=(const APInt &RHS)
Copy assignment operator.
Definition APInt.h:625
bool sgt(const APInt &RHS) const
Signed greater than comparison.
Definition APInt.h:1208
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Definition APInt.h:372
APInt(unsigned numBits, uint64_t val, bool isSigned=false, bool implicitTrunc=false)
Create a new APInt of numBits width, initialized as val.
Definition APInt.h:111
APInt & operator^=(uint64_t RHS)
Bitwise XOR assignment operator.
Definition APInt.h:754
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
Definition APInt.h:1189
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
Definition APInt.h:259
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition APInt.h:381
APInt & operator|=(uint64_t RHS)
Bitwise OR assignment operator.
Definition APInt.h:725
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
Definition APInt.h:467
static APInt floatToBits(float V)
Converts a float to APInt bits.
Definition APInt.h:1767
uint64_t WordType
Definition APInt.h:80
void setSignBit()
Set the sign bit to 1.
Definition APInt.h:1355
static constexpr unsigned APINT_WORD_SIZE
Byte size of a word.
Definition APInt.h:83
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1503
bool sle(uint64_t RHS) const
Signed less or equal comparison.
Definition APInt.h:1181
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Definition APInt.h:1118
bool uge(uint64_t RHS) const
Unsigned greater or equal comparison.
Definition APInt.h:1236
bool operator!() const
Logical negation operation on this APInt returns true if zero, like normal integers.
Definition APInt.h:616
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition APInt.h:210
APInt & operator=(uint64_t RHS)
Assignment operator.
Definition APInt.h:665
APInt relativeAShr(int RelativeShift) const
relative arithmetic shift right
Definition APInt.h:897
APInt(const APInt &that)
Copy Constructor.
Definition APInt.h:177
APInt & operator|=(const APInt &RHS)
Bitwise OR assignment operator.
Definition APInt.h:711
bool isSingleWord() const
Determine if this APInt just has one word to store value.
Definition APInt.h:323
bool operator==(uint64_t Val) const
Equality operator.
Definition APInt.h:1076
APInt operator++(int)
Postfix increment operator.
Definition APInt.h:589
unsigned getNumWords() const
Get the number of words.
Definition APInt.h:1510
bool isMinValue() const
Determine if this is the smallest unsigned value.
Definition APInt.h:418
APInt ashr(const APInt &ShiftAmt) const
Arithmetic right-shift function.
Definition APInt.h:915
APInt()
Default constructor that creates an APInt with a 1-bit zero value.
Definition APInt.h:174
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition APInt.h:217
APInt(APInt &&that)
Move Constructor.
Definition APInt.h:185
bool isNegative() const
Determine sign of this APInt.
Definition APInt.h:330
APInt concat(const APInt &NewLSB) const
Concatenate the bits from "NewLSB" onto the bottom of *this.
Definition APInt.h:954
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
Definition APInt.h:1256
bool eq(const APInt &RHS) const
Equality comparison.
Definition APInt.h:1086
int32_t exactLogBase2() const
Definition APInt.h:1798
APInt & operator<<=(unsigned ShiftAmt)
Left-shift assignment function.
Definition APInt.h:792
double roundToDouble() const
Converts this unsigned APInt to a double value.
Definition APInt.h:1727
void clearAllBits()
Set every bit to 0.
Definition APInt.h:1411
APInt relativeAShl(int RelativeShift) const
relative arithmetic shift left
Definition APInt.h:902
void ashrInPlace(unsigned ShiftAmt)
Arithmetic right-shift this APInt by ShiftAmt in place.
Definition APInt.h:841
bool sle(const APInt &RHS) const
Signed less or equal comparison.
Definition APInt.h:1173
void negate()
Negate this APInt in place.
Definition APInt.h:1483
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
Definition APInt.h:1933
unsigned countr_zero() const
Count the number of trailing zero bits.
Definition APInt.h:1654
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
Definition APInt.h:436
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
Definition APInt.h:1643
bool isOneBitSet(unsigned BitNo) const
Determine if this APInt Value only has the specified bit set.
Definition APInt.h:367
unsigned countl_zero() const
The APInt version of std::countl_zero.
Definition APInt.h:1613
bool operator==(const APInt &RHS) const
Equality operator.
Definition APInt.h:1063
APInt shl(const APInt &ShiftAmt) const
Left-shift function.
Definition APInt.h:939
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition APInt.h:220
LLVM_ABI friend hash_code hash_value(const APInt &Arg)
Overload to compute a hash_code for an APInt value.
bool isShiftedMask(unsigned &MaskIdx, unsigned &MaskLen) const
Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
Definition APInt.h:523
static constexpr WordType WORDTYPE_MAX
Definition APInt.h:94
static LLVM_ABI WordType tcSubtractPart(WordType *, WordType, unsigned)
DST -= RHS. Returns the carry flag.
Definition APInt.cpp:2513
void setBitsWithWrap(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
Definition APInt.h:1369
APInt lshr(const APInt &ShiftAmt) const
Logical right-shift function.
Definition APInt.h:927
bool isNonPositive() const
Determine if this APInt Value is non-positive (<= 0).
Definition APInt.h:362
unsigned countTrailingZeros() const
Definition APInt.h:1662
unsigned getSignificantBits() const
Get the minimum bit size for this signed APInt.
Definition APInt.h:1546
unsigned countLeadingZeros() const
Definition APInt.h:1621
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
Definition APInt.h:357
void flipAllBits()
Toggle every bit to its opposite value.
Definition APInt.h:1467
static unsigned getNumWords(unsigned BitWidth)
Get the number of words.
Definition APInt.h:1518
static bool isSameValue(const APInt &I1, const APInt &I2, bool SignedCompare=false)
Determine if two APInts have the same value, after zero-extending or sign-extending (if SignedCompare...
Definition APInt.h:555
bool needsCleanup() const
Returns whether this instance allocated memory.
Definition APInt.h:1947
unsigned countl_one() const
Count the number of leading one bits.
Definition APInt.h:1630
void clearLowBits(unsigned loBits)
Set bottom loBits bits to 0.
Definition APInt.h:1450
unsigned logBase2() const
Definition APInt.h:1776
static APInt getZeroWidth()
Return an APInt zero bits wide.
Definition APInt.h:204
double signedRoundToDouble() const
Converts this signed APInt to a double value.
Definition APInt.h:1730
bool isShiftedMask() const
Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
Definition APInt.h:511
float bitsToFloat() const
Converts APInt bits to a float.
Definition APInt.h:1751
static constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
Definition APInt.h:86
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
Definition APInt.h:476
bool ule(uint64_t RHS) const
Unsigned less or equal comparison.
Definition APInt.h:1165
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
Definition APInt.h:834
void setAllBits()
Set every bit to 1.
Definition APInt.h:1334
uint64_t VAL
Used to store the <= 64 bits integer value.
Definition APInt.h:1953
bool ugt(uint64_t RHS) const
Unsigned greater than comparison.
Definition APInt.h:1197
bool sge(int64_t RHS) const
Signed greater or equal comparison.
Definition APInt.h:1252
bool getBoolValue() const
Convert APInt to a boolean value.
Definition APInt.h:472
static APInt doubleToBits(double V)
Converts a double to APInt bits.
Definition APInt.h:1759
bool isMask(unsigned numBits) const
Definition APInt.h:489
APInt & operator=(APInt &&that)
Move assignment operator.
Definition APInt.h:639
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
Definition APInt.h:1928
APInt & operator^=(const APInt &RHS)
Bitwise XOR assignment operator.
Definition APInt.h:740
bool isMaxSignedValue() const
Determine if this is the largest signed value.
Definition APInt.h:406
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Definition APInt.h:335
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
Definition APInt.h:1157
void setBits(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
Definition APInt.h:1382
APInt shl(unsigned shiftAmt) const
Left-shift function.
Definition APInt.h:880
double bitsToDouble() const
Converts APInt bits to a double.
Definition APInt.h:1737
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
Definition APInt.h:1264
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
Definition APInt.h:441
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
Definition APInt.h:1533
bool ne(const APInt &RHS) const
Inequality comparison.
Definition APInt.h:1110
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
Definition APInt.h:307
void clearBits(unsigned LoBit, unsigned HiBit)
Clear the bits from LoBit (inclusive) to HiBit (exclusive) to 0.
Definition APInt.h:1432
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
Definition APInt.h:342
static LLVM_ABI WordType tcAddPart(WordType *, WordType, unsigned)
DST += RHS. Returns the carry flag.
Definition APInt.cpp:2475
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition APInt.h:576
bool slt(const APInt &RHS) const
Signed less than comparison.
Definition APInt.h:1137
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
Definition APInt.h:297
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:201
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
Definition APInt.h:1403
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
Definition APInt.h:433
unsigned countTrailingOnes() const
Definition APInt.h:1677
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
Definition APInt.h:1244
std::optional< int64_t > trySExtValue() const
Get sign extended value if possible.
Definition APInt.h:1589
APInt & operator&=(uint64_t RHS)
Bitwise AND assignment operator.
Definition APInt.h:695
LLVM_ABI double roundToDouble(bool isSigned) const
Converts this APInt to a double value.
Definition APInt.cpp:880
bool isOne() const
Determine if this is a value of 1.
Definition APInt.h:390
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
Definition APInt.h:287
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition APInt.h:240
void clearHighBits(unsigned hiBits)
Set top hiBits bits to 0.
Definition APInt.h:1457
int64_t getSExtValue() const
Get sign extended value.
Definition APInt.h:1577
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
Definition APInt.h:865
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Definition APInt.h:858
unsigned countr_one() const
Count the number of trailing one bits.
Definition APInt.h:1671
static APInt getBitsSetWithWrap(unsigned numBits, unsigned loBit, unsigned hiBit)
Wrap version of getBitsSet.
Definition APInt.h:271
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
Definition APInt.h:349
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Definition APInt.h:1228
void setBitVal(unsigned BitPosition, bool BitValue)
Set a given bit to a given value.
Definition APInt.h:1358
void clearSignBit()
Set the sign bit to 0.
Definition APInt.h:1464
bool isMaxValue() const
Determine if this is the largest unsigned value.
Definition APInt.h:400
void toStringSigned(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be signed and converts it into a string in the radix given.
Definition APInt.h:1712
bool ult(uint64_t RHS) const
Unsigned less than comparison.
Definition APInt.h:1126
bool operator!=(uint64_t Val) const
Inequality operator.
Definition APInt.h:1102
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class provides support for dynamic arbitrary-precision arithmetic.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:209
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.
Definition StringRef.h:55
An opaque object representing a hash code.
Definition Hashing.h:76
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define UINT64_MAX
Definition DataTypes.h:77
LLVM_ABI std::error_code fromString(StringRef String, Metadata &HSAMetadata)
Converts String to HSAMetadata.
float RoundAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float value.
Definition APInt.h:2345
double RoundAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
Definition APInt.h:2333
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
Definition APInt.h:2263
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
Definition APInt.h:2268
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
Definition APInt.h:2273
APInt RoundFloatToAPInt(float Float, unsigned width)
Converts a float value into a APInt.
Definition APInt.h:2364
LLVM_ABI APInt RoundDoubleToAPInt(double Double, unsigned width)
Converts the given double value into a APInt.
Definition APInt.cpp:841
APInt abds(const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be signed.
Definition APInt.h:2283
double RoundSignedAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
Definition APInt.h:2340
APInt abdu(const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be unsigned.
Definition APInt.h:2288
float RoundSignedAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float value.
Definition APInt.h:2352
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
Definition APInt.h:2278
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
constexpr T rotr(T V, int R)
Definition bit.h:382
APInt operator&(APInt a, const APInt &b)
Definition APInt.h:2138
APInt operator*(APInt a, uint64_t RHS)
Definition APInt.h:2250
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
Definition bit.h:293
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2128
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator+=(DynamicAPInt &A, int64_t B)
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition MathExtras.h:243
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator-=(DynamicAPInt &A, int64_t B)
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition MathExtras.h:284
APInt operator~(APInt v)
Unary bitwise complement operator.
Definition APInt.h:2133
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
Definition bit.h:154
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:202
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
Definition MathExtras.h:273
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator*=(DynamicAPInt &A, int64_t B)
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
Definition bit.h:236
APInt operator^(APInt a, const APInt &b)
Definition APInt.h:2178
constexpr bool isMask_64(uint64_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
Definition MathExtras.h:261
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
int countl_one(T Value)
Count the number of ones from the most significant bit to the first zero bit.
Definition bit.h:280
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
To bit_cast(const From &from) noexcept
Definition bit.h:90
APInt operator-(APInt)
Definition APInt.h:2203
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition MathExtras.h:248
constexpr T reverseBits(T Val)
Reverse the bits in Val.
Definition MathExtras.h:118
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Definition MathExtras.h:572
APInt operator+(APInt a, const APInt &b)
Definition APInt.h:2208
APInt operator|(APInt a, const APInt &b)
Definition APInt.h:2158
constexpr T rotl(T V, int R)
Definition bit.h:369
@ Keep
No function return thunk.
Definition CodeGen.h:162
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static bool isEqual(const APInt &LHS, const APInt &RHS)
Definition APInt.h:2510
static LLVM_ABI unsigned getHashValue(const APInt &Key)
An information struct used to provide DenseMap with the various necessary components for a given valu...