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