1//===-- llvm/ADT/APInt.h - For Arbitrary Precision Integer -----*- C++ -*--===//
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
7//===----------------------------------------------------------------------===//
10/// This file implements a class to represent arbitrary precision
11/// integral constant values and operations on them.
13//===----------------------------------------------------------------------===//
15#ifndef LLVM_ADT_APINT_H
16#define LLVM_ADT_APINT_H
37template <
typename T,
typename Enable>
struct DenseMapInfo;
43//===----------------------------------------------------------------------===//
45//===----------------------------------------------------------------------===//
47/// Class for arbitrary precision integers.
49/// APInt is a functional replacement for common case unsigned integer type like
50/// "unsigned", "unsigned long" or "uint64_t", but also allows non-byte-width
51/// integer sizes and large integer value types such as 3-bits, 15-bits, or more
52/// than 64-bits of precision. APInt provides a variety of arithmetic operators
53/// and methods to manipulate integer values of any bit-width. It supports both
54/// the typical integer arithmetic and comparison operations as well as bitwise
57/// The class has several invariants worth noting:
58/// * All bit, byte, and word positions are zero-based.
59/// * Once the bit width is set, it doesn't change except by the Truncate,
60/// SignExtend, or ZeroExtend operations.
61/// * All binary operators must be on APInt instances of the same bit width.
62/// Attempting to use these operators on instances with different bit
63/// widths will yield an assertion.
64/// * The value is stored canonically as an unsigned value. For operations
65/// where it makes a difference, there are both signed and unsigned variants
66/// of the operation. For example, sdiv and udiv. However, because the bit
67/// widths must be the same, operations such as Mul and Add produce the same
68/// results regardless of whether the values are interpreted as signed or
70/// * In general, the class tries to follow the style of computation that LLVM
71/// uses in its IR. This simplifies its use for LLVM.
72/// * APInt supports zero-bit-width values, but operations that require bits
73/// are not defined on it (e.g. you cannot ask for the sign of a zero-bit
74/// integer). This means that operations like zero extension and logical
75/// shifts are defined, but sign extension and ashr is not. Zero bit values
76/// compare and hash equal to themselves, and countLeadingZeros returns 0.
82 /// Byte size of a word.
96 /// \name Constructors
99 /// Create a new APInt of numBits width, initialized as val.
101 /// If isSigned is true then val is treated as if it were a signed value
102 /// (i.e. as an int64_t) and the appropriate sign extension to the bit width
103 /// will be done. Otherwise, no sign extension occurs (high order bits beyond
104 /// the range of val are zero filled).
106 /// \param numBits the bit width of the constructed APInt
107 /// \param val the initial value of the APInt
108 /// \param isSigned how to treat signedness of val
109 /// \param implicitTrunc allow implicit truncation of non-zero/sign bits of
110 /// val beyond the range of numBits
112 bool implicitTrunc =
false)
113 : BitWidth(numBits) {
114 if (!implicitTrunc) {
118 "Value must be 0 or -1 for signed 0-bit APInt");
121 "Value is not an N-bit signed value");
125 assert(val == 0 &&
"Value must be zero for unsigned 0-bit APInt");
128 "Value is not an N-bit unsigned value");
141 /// Construct an APInt of numBits width, initialized as bigVal[].
143 /// Note that bigVal.size() can be smaller or larger than the corresponding
144 /// bit width but any extraneous bits will be dropped.
146 /// \param numBits the bit width of the constructed APInt
147 /// \param bigVal a sequence of words to form the initial value of the APInt
150 /// Equivalent to APInt(numBits, ArrayRef<uint64_t>(bigVal, numWords)), but
151 /// deprecated because this constructor is prone to ambiguity with the
152 /// APInt(unsigned, uint64_t, bool) constructor.
154 /// Once all uses of this constructor are migrated to other constructors,
155 /// consider marking this overload ""= delete" to prevent calls from being
156 /// incorrectly bound to the APInt(unsigned, uint64_t, bool) constructor.
157 [[deprecated(
"Use other constructors of APInt")]]
160 /// Construct an APInt from a string representation.
162 /// This constructor interprets the string \p str in the given radix. The
163 /// interpretation stops when the first character that is not suitable for the
164 /// radix is encountered, or the end of the string. Acceptable radix values
165 /// are 2, 8, 10, 16, and 36. It is an error for the value implied by the
166 /// string to require more bits than numBits.
168 /// \param numBits the bit width of the constructed APInt
169 /// \param str the string to be interpreted
170 /// \param radix the radix to use for the conversion
173 /// Default constructor that creates an APInt with a 1-bit zero value.
176 /// Copy Constructor.
184 /// Move Constructor.
186 memcpy(&U, &that.U,
sizeof(U));
197 /// \name Value Generators
200 /// Get the '0' value for the specified bit-width.
203 /// Return an APInt zero bits wide.
206 /// Gets maximum unsigned value of APInt for specific bit width.
209 /// Gets maximum signed value of APInt for a specific bit width.
216 /// Gets minimum unsigned value of APInt for a specific bit width.
219 /// Gets minimum signed value of APInt for a specific bit width.
221 APInt API(numBits, 0);
226 /// Get the SignMask for a specific bit width.
228 /// This is just a wrapper function of getSignedMinValue(), and it helps code
229 /// readability when we want to get a SignMask.
234 /// Return an APInt of a specified width with all bits set.
239 /// Return an APInt with exactly one bit set in the result.
241 APInt Res(numBits, 0);
246 /// Get a value with a block of bits set.
248 /// Constructs an APInt value that has a contiguous range of bits set. The
249 /// bits from loBit (inclusive) to hiBit (exclusive) will be set. All other
250 /// bits will be zero. For example, with parameters(32, 0, 16) you would get
251 /// 0x0000FFFF. Please call getBitsSetWithWrap if \p loBit may be greater than
254 /// \param numBits the intended bit width of the result
255 /// \param loBit the index of the lowest bit set.
256 /// \param hiBit the index of the highest bit set.
258 /// \returns An APInt value with the requested bits set.
260 APInt Res(numBits, 0);
265 /// Wrap version of getBitsSet.
266 /// If \p hiBit is bigger than \p loBit, this is same with getBitsSet.
267 /// If \p hiBit is not bigger than \p loBit, the set bits "wrap". For example,
268 /// with parameters (32, 28, 4), you would get 0xF000000F.
269 /// If \p hiBit is equal to \p loBit, you would get a result with all bits
273 APInt Res(numBits, 0);
278 /// Constructs an APInt value that has a contiguous range of bits set. The
279 /// bits from loBit (inclusive) to numBits (exclusive) will be set. All other
280 /// bits will be zero. For example, with parameters(32, 12) you would get
283 /// \param numBits the intended bit width of the result
284 /// \param loBit the index of the lowest bit to set.
286 /// \returns An APInt value with the requested bits set.
288 APInt Res(numBits, 0);
293 /// Constructs an APInt value that has the top hiBitsSet bits set.
295 /// \param numBits the bitwidth of the result
296 /// \param hiBitsSet the number of high-order bits set in the result.
298 APInt Res(numBits, 0);
303 /// Constructs an APInt value that has the bottom loBitsSet bits set.
305 /// \param numBits the bitwidth of the result
306 /// \param loBitsSet the number of low-order bits set in the result.
308 APInt Res(numBits, 0);
313 /// Return a value containing V broadcasted over NewLen bits.
317 /// \name Value Tests
320 /// Determine if this APInt just has one word to store value.
322 /// \returns true if the number of bits <= 64, false otherwise.
325 /// Determine sign of this APInt.
327 /// This tests the high bit of this APInt to determine if it is set.
329 /// \returns true if this APInt is negative, false otherwise
332 /// Determine if this APInt Value is non-negative (>= 0)
334 /// This tests the high bit of the APInt to determine if it is unset.
337 /// Determine if sign bit of this APInt is set.
339 /// This tests the high bit of this APInt to determine if it is set.
341 /// \returns true if this APInt has its sign bit set, false otherwise.
344 /// Determine if sign bit of this APInt is clear.
346 /// This tests the high bit of this APInt to determine if it is clear.
348 /// \returns true if this APInt has its sign bit clear, false otherwise.
351 /// Determine if this APInt Value is positive.
353 /// This tests if the value of this APInt is positive (> 0). Note
354 /// that 0 is not a positive value.
356 /// \returns true if this APInt is positive.
359 /// Determine if this APInt Value is non-positive (<= 0).
361 /// \returns true if this APInt is non-positive.
364 /// Determine if this APInt Value only has the specified bit set.
366 /// \returns true if this APInt only has the specified bit set.
368 return (*
this)[BitNo] &&
popcount() == 1;
371 /// Determine if all bits are set. This is true for zero-width values.
377 return countTrailingOnesSlowCase() == BitWidth;
380 /// Determine if this value is zero, i.e. all bits are clear.
384 return countLeadingZerosSlowCase() == BitWidth;
387 /// Determine if this is a value of 1.
389 /// This checks to see if the value of this APInt is one.
393 return countLeadingZerosSlowCase() == BitWidth - 1;
396 /// Determine if this is the largest unsigned value.
398 /// This checks to see if the value of this APInt is the maximum unsigned
399 /// value for the APInt's bit width.
402 /// Determine if this is the largest signed value.
404 /// This checks to see if the value of this APInt is the maximum signed
405 /// value for the APInt's bit width.
408 assert(BitWidth &&
"zero width values not allowed");
409 return U.VAL == ((
WordType(1) << (BitWidth - 1)) - 1);
411 return !
isNegative() && countTrailingOnesSlowCase() == BitWidth - 1;
414 /// Determine if this is the smallest unsigned value.
416 /// This checks to see if the value of this APInt is the minimum unsigned
417 /// value for the APInt's bit width.
420 /// Determine if this is the smallest signed value.
422 /// This checks to see if the value of this APInt is the minimum signed
423 /// value for the APInt's bit width.
426 assert(BitWidth &&
"zero width values not allowed");
427 return U.VAL == (
WordType(1) << (BitWidth - 1));
429 return isNegative() && countTrailingZerosSlowCase() == BitWidth - 1;
432 /// Check if this APInt has an N-bits unsigned integer value.
435 /// Check if this APInt has an N-bits signed integer value.
438 /// Check if this APInt's value is a power of two greater than zero.
440 /// \returns true if the argument APInt value is a power of two > 0.
443 assert(BitWidth &&
"zero width values not allowed");
446 return countPopulationSlowCase() == 1;
449 /// Check if this APInt's negated value is a power of two greater than zero.
451 assert(BitWidth &&
"zero width values not allowed");
454 // NegatedPowerOf2 - shifted mask in the top bits.
457 return (LO + TZ) == BitWidth;
460 /// Checks if this APInt -interpreted as an address- is aligned to the
464 /// Check if the APInt's value is returned by getSignMask.
466 /// \returns true if this is the value returned by getSignMask.
469 /// Convert APInt to a boolean value.
471 /// This converts the APInt to a boolean value as a test against zero.
474 /// If this value is smaller than the specified limit, return it, otherwise
475 /// return the limit value. This causes the value to saturate to the limit.
480 /// Check if the APInt consists of a repeated bit pattern.
482 /// e.g. 0x01010101 satisfies isSplat(8).
483 /// \param SplatSizeInBits The size of the pattern in bits. Must divide bit
484 /// width without remainder.
487 /// \returns true if this APInt value is a sequence of \param numBits ones
488 /// starting at the least significant bit with the remainder zero.
490 assert(numBits != 0 &&
"numBits must be non-zero");
491 assert(numBits <= BitWidth &&
"numBits out of range");
494 unsigned Ones = countTrailingOnesSlowCase();
495 return (numBits == Ones) &&
496 ((Ones + countLeadingZerosSlowCase()) == BitWidth);
499 /// \returns true if this APInt is a non-empty sequence of ones starting at
500 /// the least significant bit with the remainder zero.
501 /// Ex. isMask(0x0000FFFFU) == true.
505 unsigned Ones = countTrailingOnesSlowCase();
506 return (Ones > 0) && ((Ones + countLeadingZerosSlowCase()) == BitWidth);
509 /// Return true if this APInt value contains a non-empty sequence of ones with
510 /// the remainder zero.
514 unsigned Ones = countPopulationSlowCase();
515 unsigned LeadZ = countLeadingZerosSlowCase();
516 return (Ones + LeadZ + countTrailingZerosSlowCase()) == BitWidth;
519 /// Return true if this APInt value contains a non-empty sequence of ones with
520 /// the remainder zero. If true, \p MaskIdx will specify the index of the
521 /// lowest set bit and \p MaskLen is updated to specify the length of the
522 /// mask, else neither are updated.
526 unsigned Ones = countPopulationSlowCase();
527 unsigned LeadZ = countLeadingZerosSlowCase();
528 unsigned TrailZ = countTrailingZerosSlowCase();
529 if ((Ones + LeadZ + TrailZ) != BitWidth)
536 /// Compute an APInt containing numBits highbits from this APInt.
538 /// Get an APInt with the same BitWidth as this APInt, just zero mask the low
539 /// bits and right shift to the least significant bit.
541 /// \returns the high "numBits" bits of this APInt.
544 /// Compute an APInt containing numBits lowbits from this APInt.
546 /// Get an APInt with the same BitWidth as this APInt, just zero mask the high
549 /// \returns the low "numBits" bits of this APInt.
552 /// Determine if two APInts have the same value, after zero-extending
553 /// one of them (if needed!) to ensure that the bit-widths match.
559 return I1 == I2.
zext(I1.getBitWidth());
564 /// Overload to compute a hash_code for an APInt value.
567 /// This function returns a pointer to the internal storage of the APInt.
568 /// This is useful for writing out the APInt in binary form without any
577 /// \name Unary Operators
580 /// Postfix increment operator. Increment *this by 1.
582 /// \returns a new APInt value representing the original value of *this.
589 /// Prefix increment operator.
591 /// \returns *this incremented by one
594 /// Postfix decrement operator. Decrement *this by 1.
596 /// \returns a new APInt value representing the original value of *this.
603 /// Prefix decrement operator.
605 /// \returns *this decremented by one.
608 /// Logical negation operation on this APInt returns true if zero, like normal
613 /// \name Assignment Operators
616 /// Copy assignment operator.
618 /// \returns *this after assignment of RHS.
620 // The common case (both source or dest being inline) doesn't require
621 // allocation or deallocation.
624 BitWidth =
RHS.BitWidth;
632 /// Move assignment operator.
634#ifdef EXPENSIVE_CHECKS
635 // Some std::shuffle implementations still do self-assignment.
639 assert(
this != &that &&
"Self-move not supported");
643 // Use memcpy so that type based alias analysis sees both VAL and pVal
645 memcpy(&U, &that.U,
sizeof(U));
647 BitWidth = that.BitWidth;
652 /// Assignment operator.
654 /// The RHS value is assigned to *this. If the significant bits in RHS exceed
655 /// the bit width, the excess bits are truncated. If the bit width is larger
656 /// than 64, the value is zero filled in the unspecified high order bits.
658 /// \returns *this after assignment of RHS value.
669 /// Bitwise AND assignment operator.
671 /// Performs a bitwise AND operation on this APInt and RHS. The result is
672 /// assigned to *this.
674 /// \returns *this after ANDing with RHS.
676 assert(BitWidth ==
RHS.BitWidth &&
"Bit widths must be the same");
680 andAssignSlowCase(
RHS);
684 /// Bitwise AND assignment operator.
686 /// Performs a bitwise AND operation on this APInt and RHS. RHS is
687 /// logically zero-extended or truncated to match the bit-width of
699 /// Bitwise OR assignment operator.
701 /// Performs a bitwise OR operation on this APInt and RHS. The result is
704 /// \returns *this after ORing with RHS.
706 assert(BitWidth ==
RHS.BitWidth &&
"Bit widths must be the same");
710 orAssignSlowCase(
RHS);
714 /// Bitwise OR assignment operator.
716 /// Performs a bitwise OR operation on this APInt and RHS. RHS is
717 /// logically zero-extended or truncated to match the bit-width of
728 /// Bitwise XOR assignment operator.
730 /// Performs a bitwise XOR operation on this APInt and RHS. The result is
731 /// assigned to *this.
733 /// \returns *this after XORing with RHS.
735 assert(BitWidth ==
RHS.BitWidth &&
"Bit widths must be the same");
739 xorAssignSlowCase(
RHS);
743 /// Bitwise XOR assignment operator.
745 /// Performs a bitwise XOR operation on this APInt and RHS. RHS is
746 /// logically zero-extended or truncated to match the bit-width of
757 /// Multiplication assignment operator.
759 /// Multiplies this APInt by RHS and assigns the result to *this.
765 /// Addition assignment operator.
767 /// Adds RHS to *this and assigns the result to *this.
773 /// Subtraction assignment operator.
775 /// Subtracts RHS from *this and assigns the result to *this.
781 /// Left-shift assignment function.
783 /// Shifts *this left by shiftAmt and assigns the result to *this.
785 /// \returns *this after shifting left by ShiftAmt
787 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
789 if (ShiftAmt == BitWidth)
795 shlSlowCase(ShiftAmt);
799 /// Left-shift assignment function.
801 /// Shifts *this left by shiftAmt and assigns the result to *this.
803 /// \returns *this after shifting left by ShiftAmt
807 /// \name Binary Operators
810 /// Multiplication operator.
812 /// Multiplies this APInt by RHS and returns the result.
815 /// Left logical shift operator.
817 /// Shifts this APInt left by \p Bits and returns the result.
820 /// Left logical shift operator.
822 /// Shifts this APInt left by \p Bits and returns the result.
825 /// Arithmetic right-shift function.
827 /// Arithmetic right-shift this APInt by shiftAmt.
830 R.ashrInPlace(ShiftAmt);
834 /// Arithmetic right-shift this APInt by ShiftAmt in place.
836 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
839 if (ShiftAmt == BitWidth)
842 U.VAL = SExtVAL >> ShiftAmt;
846 ashrSlowCase(ShiftAmt);
849 /// Logical right-shift function.
851 /// Logical right-shift this APInt by shiftAmt.
854 R.lshrInPlace(shiftAmt);
858 /// Logical right-shift this APInt by ShiftAmt in place.
860 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
862 if (ShiftAmt == BitWidth)
868 lshrSlowCase(ShiftAmt);
871 /// Left-shift function.
873 /// Left-shift this APInt by shiftAmt.
880 /// relative logical shift right
882 return RelativeShift > 0 ?
lshr(RelativeShift) :
shl(-RelativeShift);
885 /// relative logical shift left
890 /// relative arithmetic shift right
892 return RelativeShift > 0 ?
ashr(RelativeShift) :
shl(-RelativeShift);
895 /// relative arithmetic shift left
900 /// Rotate left by rotateAmt.
903 /// Rotate right by rotateAmt.
906 /// Arithmetic right-shift function.
908 /// Arithmetic right-shift this APInt by shiftAmt.
911 R.ashrInPlace(ShiftAmt);
915 /// Arithmetic right-shift this APInt by shiftAmt in place.
918 /// Logical right-shift function.
920 /// Logical right-shift this APInt by shiftAmt.
923 R.lshrInPlace(ShiftAmt);
927 /// Logical right-shift this APInt by ShiftAmt in place.
930 /// Left-shift function.
932 /// Left-shift this APInt by shiftAmt.
939 /// Rotate left by rotateAmt.
942 /// Rotate right by rotateAmt.
945 /// Concatenate the bits from "NewLSB" onto the bottom of *this. This is
947 /// (this->zext(NewWidth) << NewLSB.getBitWidth()) | NewLSB.zext(NewWidth)
949 /// If the result will be small, then both the merged values are small.
953 return concatSlowCase(NewLSB);
956 /// Unsigned division operation.
958 /// Perform an unsigned divide operation on this APInt by RHS. Both this and
959 /// RHS are treated as unsigned quantities for purposes of this division.
961 /// \returns a new APInt value containing the division result, rounded towards
966 /// Signed division function for APInt.
968 /// Signed divide this APInt by APInt RHS.
970 /// The result is rounded towards zero.
974 /// Unsigned remainder operation.
976 /// Perform an unsigned remainder operation on this APInt with RHS being the
977 /// divisor. Both this and RHS are treated as unsigned quantities for purposes
978 /// of this operation.
980 /// \returns a new APInt value containing the remainder result
984 /// Function for signed remainder operation.
986 /// Signed remainder operation on APInt.
988 /// Note that this is a true remainder operation and not a modulo operation
989 /// because the sign follows the sign of the dividend which is *this.
993 /// Dual division/remainder interface.
995 /// Sometimes it is convenient to divide two APInt values and obtain both the
996 /// quotient and remainder. This function does both operations in the same
997 /// computation making it a little more efficient. The pair of input arguments
998 /// may overlap with the pair of output arguments. It is safe to call
999 /// udivrem(X, Y, X, Y), for example.
1008 int64_t &Remainder);
1010 // Operations that return overflow indicators.
1023 /// Signed integer floor division operation.
1025 /// Rounds towards negative infinity, i.e. 5 / -2 = -3. Iff minimum value
1026 /// divided by -1 set Overflow to true.
1029 // Operations that saturate
1041 /// Array-indexing support.
1043 /// \returns the bit value at bitPosition
1046 return (maskBit(bitPosition) & getWord(bitPosition)) != 0;
1050 /// \name Comparison Operators
1053 /// Equality operator.
1055 /// Compares this APInt with RHS for the validity of the equality
1058 assert(BitWidth ==
RHS.BitWidth &&
"Comparison requires equal bit widths");
1060 return U.VAL ==
RHS.U.VAL;
1061 return equalSlowCase(
RHS);
1064 /// Equality operator.
1066 /// Compares this APInt with a uint64_t for the validity of the equality
1069 /// \returns true if *this == Val
1074 /// Equality comparison.
1076 /// Compares this APInt with RHS for the validity of the equality
1079 /// \returns true if *this == Val
1082 /// Inequality operator.
1084 /// Compares this APInt with RHS for the validity of the inequality
1087 /// \returns true if *this != Val
1090 /// Inequality operator.
1092 /// Compares this APInt with a uint64_t for the validity of the inequality
1095 /// \returns true if *this != Val
1098 /// Inequality comparison
1100 /// Compares this APInt with RHS for the validity of the inequality
1103 /// \returns true if *this != Val
1106 /// Unsigned less than comparison
1108 /// Regards both *this and RHS as unsigned quantities and compares them for
1109 /// the validity of the less-than relationship.
1111 /// \returns true if *this < RHS when both are considered unsigned.
1114 /// Unsigned less than comparison
1116 /// Regards both *this as an unsigned quantity and compares it with RHS for
1117 /// the validity of the less-than relationship.
1119 /// \returns true if *this < RHS when considered unsigned.
1121 // Only need to check active bits if not a single word.
1125 /// Signed less than comparison
1127 /// Regards both *this and RHS as signed quantities and compares them for
1128 /// validity of the less-than relationship.
1130 /// \returns true if *this < RHS when both are considered signed.
1133 /// Signed less than comparison
1135 /// Regards both *this as a signed quantity and compares it with RHS for
1136 /// the validity of the less-than relationship.
1138 /// \returns true if *this < RHS when considered signed.
1145 /// Unsigned less or equal comparison
1147 /// Regards both *this and RHS as unsigned quantities and compares them for
1148 /// validity of the less-or-equal relationship.
1150 /// \returns true if *this <= RHS when both are considered unsigned.
1153 /// Unsigned less or equal comparison
1155 /// Regards both *this as an unsigned quantity and compares it with RHS for
1156 /// the validity of the less-or-equal relationship.
1158 /// \returns true if *this <= RHS when considered unsigned.
1161 /// Signed less or equal comparison
1163 /// Regards both *this and RHS as signed quantities and compares them for
1164 /// validity of the less-or-equal relationship.
1166 /// \returns true if *this <= RHS when both are considered signed.
1169 /// Signed less or equal comparison
1171 /// Regards both *this as a signed quantity and compares it with RHS for the
1172 /// validity of the less-or-equal relationship.
1174 /// \returns true if *this <= RHS when considered signed.
1177 /// Unsigned greater than comparison
1179 /// Regards both *this and RHS as unsigned quantities and compares them for
1180 /// the validity of the greater-than relationship.
1182 /// \returns true if *this > RHS when both are considered unsigned.
1185 /// Unsigned greater than comparison
1187 /// Regards both *this as an unsigned quantity and compares it with RHS for
1188 /// the validity of the greater-than relationship.
1190 /// \returns true if *this > RHS when considered unsigned.
1192 // Only need to check active bits if not a single word.
1196 /// Signed greater than comparison
1198 /// Regards both *this and RHS as signed quantities and compares them for the
1199 /// validity of the greater-than relationship.
1201 /// \returns true if *this > RHS when both are considered signed.
1204 /// Signed greater than comparison
1206 /// Regards both *this as a signed quantity and compares it with RHS for
1207 /// the validity of the greater-than relationship.
1209 /// \returns true if *this > RHS when considered signed.
1216 /// Unsigned greater or equal comparison
1218 /// Regards both *this and RHS as unsigned quantities and compares them for
1219 /// validity of the greater-or-equal relationship.
1221 /// \returns true if *this >= RHS when both are considered unsigned.
1224 /// Unsigned greater or equal comparison
1226 /// Regards both *this as an unsigned quantity and compares it with RHS for
1227 /// the validity of the greater-or-equal relationship.
1229 /// \returns true if *this >= RHS when considered unsigned.
1232 /// Signed greater or equal comparison
1234 /// Regards both *this and RHS as signed quantities and compares them for
1235 /// validity of the greater-or-equal relationship.
1237 /// \returns true if *this >= RHS when both are considered signed.
1240 /// Signed greater or equal comparison
1242 /// Regards both *this as a signed quantity and compares it with RHS for
1243 /// the validity of the greater-or-equal relationship.
1245 /// \returns true if *this >= RHS when considered signed.
1248 /// This operation tests if there are any pairs of corresponding bits
1249 /// between this APInt and RHS that are both set.
1251 assert(BitWidth ==
RHS.BitWidth &&
"Bit widths must be the same");
1253 return (U.VAL &
RHS.U.VAL) != 0;
1254 return intersectsSlowCase(
RHS);
1257 /// This operation checks that all bits set in this APInt are also set in RHS.
1259 assert(BitWidth ==
RHS.BitWidth &&
"Bit widths must be the same");
1261 return (U.VAL & ~
RHS.U.VAL) == 0;
1262 return isSubsetOfSlowCase(
RHS);
1266 /// \name Resizing Operators
1269 /// Truncate to new width.
1271 /// Truncate the APInt to a specified width. It is an error to specify a width
1272 /// that is greater than the current width.
1275 /// Truncate to new width with unsigned saturation.
1277 /// If the APInt, treated as unsigned integer, can be losslessly truncated to
1278 /// the new bitwidth, then return truncated APInt. Else, return max value.
1281 /// Truncate to new width with signed saturation.
1283 /// If this APInt, treated as signed integer, can be losslessly truncated to
1284 /// the new bitwidth, then return truncated APInt. Else, return either
1285 /// signed min value if the APInt was negative, or signed max value.
1288 /// Sign extend to a new width.
1290 /// This operation sign extends the APInt to a new width. If the high order
1291 /// bit is set, the fill on the left will be done with 1 bits, otherwise zero.
1292 /// It is an error to specify a width that is less than the
1296 /// Zero extend to a new width.
1298 /// This operation zero extends the APInt to a new width. The high order bits
1299 /// are filled with 0 bits. It is an error to specify a width that is less
1300 /// than the current width.
1303 /// Sign extend or truncate to width
1305 /// Make this APInt have the bit width given by \p width. The value is sign
1306 /// extended, truncated, or left alone to make it that width.
1309 /// Zero extend or truncate to width
1311 /// Make this APInt have the bit width given by \p width. The value is zero
1312 /// extended, truncated, or left alone to make it that width.
1316 /// \name Bit Manipulation Operators
1319 /// Set every bit to 1.
1324 // Set all the bits in all the words.
1326 // Clear the unused ones
1330 /// Set the given bit to 1 whose position is given as "bitPosition".
1332 assert(BitPosition < BitWidth &&
"BitPosition out of range");
1333 WordType Mask = maskBit(BitPosition);
1337 U.pVal[whichWord(BitPosition)] |= Mask;
1340 /// Set the sign bit to 1.
1343 /// Set a given bit to a given value.
1351 /// Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
1352 /// This function handles "wrap" case when \p loBit >= \p hiBit, and calls
1353 /// setBits when \p loBit < \p hiBit.
1354 /// For \p loBit == \p hiBit wrap case, set every bit to 1.
1356 assert(hiBit <= BitWidth &&
"hiBit out of range");
1357 assert(loBit <= BitWidth &&
"loBit out of range");
1358 if (loBit < hiBit) {
1366 /// Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
1367 /// This function handles case when \p loBit <= \p hiBit.
1369 assert(hiBit <= BitWidth &&
"hiBit out of range");
1370 assert(loBit <= hiBit &&
"loBit greater than hiBit");
1381 setBitsSlowCase(loBit, hiBit);
1385 /// Set the top bits starting from loBit.
1388 /// Set the bottom loBits bits.
1391 /// Set the top hiBits bits.
1393 return setBits(BitWidth - hiBits, BitWidth);
1396 /// Set every bit to 0.
1404 /// Set a given bit to 0.
1406 /// Set the given bit to 0 whose position is given as "bitPosition".
1408 assert(BitPosition < BitWidth &&
"BitPosition out of range");
1409 WordType Mask = ~maskBit(BitPosition);
1413 U.pVal[whichWord(BitPosition)] &= Mask;
1416 /// Clear the bits from LoBit (inclusive) to HiBit (exclusive) to 0.
1417 /// This function handles case when \p LoBit <= \p HiBit.
1419 assert(HiBit <= BitWidth &&
"HiBit out of range");
1420 assert(LoBit <= HiBit &&
"LoBit greater than HiBit");
1425 Mask = ~(Mask << LoBit);
1431 clearBitsSlowCase(LoBit, HiBit);
1435 /// Set bottom loBits bits to 0.
1437 assert(loBits <= BitWidth &&
"More bits than bitwidth");
1442 /// Set top hiBits bits to 0.
1444 assert(hiBits <= BitWidth &&
"More bits than bitwidth");
1449 /// Set the sign bit to 0.
1452 /// Toggle every bit to its opposite value.
1458 flipAllBitsSlowCase();
1462 /// Toggles a given bit to its opposite value.
1464 /// Toggle a given bit to its opposite value whose position is given
1465 /// as "bitPosition".
1466 LLVM_ABI void flipBit(
unsigned bitPosition);
1468 /// Negate this APInt in place.
1474 /// Insert the bits from a smaller APInt starting at bitPosition.
1475 LLVM_ABI void insertBits(
const APInt &SubBits,
unsigned bitPosition);
1479 /// Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
1482 unsigned bitPosition)
const;
1485 /// \name Value Characterization Functions
1488 /// Return the number of bits in the APInt.
1491 /// Get the number of words.
1493 /// Here one word's bitwidth equals to that of uint64_t.
1495 /// \returns the number of words to hold the integer value of this APInt.
1498 /// Get the number of words.
1500 /// *NOTE* Here one word's bitwidth equals to that of uint64_t.
1502 /// \returns the number of words to hold the integer value with a given bit
1508 /// Compute the number of active bits in the value
1510 /// This function returns the number of active bits which is defined as the
1511 /// bit width minus the number of leading zeros. This is used in several
1512 /// computations to see how "wide" the value is.
1515 /// Compute the number of active words in the value of this APInt.
1517 /// This is used in conjunction with getActiveData to extract the raw value of
1521 return numActiveBits ? whichWord(numActiveBits - 1) + 1 : 1;
1524 /// Get the minimum bit size for this signed APInt
1526 /// Computes the minimum bit width for this APInt while considering it to be a
1527 /// signed (and probably negative) value. If the value is not negative, this
1528 /// function returns the same value as getActiveBits()+1. Otherwise, it
1529 /// returns the smallest bit width that will retain the negative value. For
1530 /// example, -1 can be written as 0b1 or 0xFFFFFFFFFF. 0b1 is shorter and so
1531 /// for -1, this function will always return 1.
1536 /// Get zero extended value
1538 /// This method attempts to return the value of this APInt as a zero extended
1539 /// uint64_t. The bitwidth must be <= 64 or the value must fit within a
1540 /// uint64_t. Otherwise an assertion will result.
1548 /// Get zero extended value if possible
1550 /// This method attempts to return the value of this APInt as a zero extended
1551 /// uint64_t. The bitwidth must be <= 64 or the value must fit within a
1552 /// uint64_t. Otherwise no value is returned.
1558 /// Get sign extended value
1560 /// This method attempts to return the value of this APInt as a sign extended
1561 /// int64_t. The bit width must be <= 64 or the value must fit within an
1562 /// int64_t. Otherwise an assertion will result.
1567 return int64_t(U.pVal[0]);
1570 /// Get sign extended value if possible
1572 /// This method attempts to return the value of this APInt as a sign extended
1573 /// int64_t. The bitwidth must be <= 64 or the value must fit within an
1574 /// int64_t. Otherwise no value is returned.
1580 /// Get bits required for string value.
1582 /// This method determines how many bits are required to hold the APInt
1583 /// equivalent of the string given by \p str.
1586 /// Get the bits that are sufficient to represent the string value. This may
1587 /// over estimate the amount of bits required, but it does not require
1588 /// parsing the value in the string.
1592 /// The APInt version of std::countl_zero.
1594 /// It counts the number of zeros from the most significant bit to the first
1597 /// \returns BitWidth if the value is zero, otherwise returns the number of
1598 /// zeros from the most significant bit to the first one bits.
1604 return countLeadingZerosSlowCase();
1609 /// Count the number of leading one bits.
1611 /// This function is an APInt version of std::countl_one. It counts the number
1612 /// of ones from the most significant bit to the first zero bit.
1614 /// \returns 0 if the high order bit is not set, otherwise returns the number
1615 /// of 1 bits from the most significant to the least
1622 return countLeadingOnesSlowCase();
1627 /// Computes the number of leading bits of this APInt that are equal to its
1633 /// Count the number of trailing zero bits.
1635 /// This function is an APInt version of std::countr_zero. It counts the
1636 /// number of zeros from the least significant bit to the first set bit.
1638 /// \returns BitWidth if the value is zero, otherwise returns the number of
1639 /// zeros from the least significant bit to the first one bit.
1643 return (TrailingZeros > BitWidth ? BitWidth : TrailingZeros);
1645 return countTrailingZerosSlowCase();
1650 /// Count the number of trailing one bits.
1652 /// This function is an APInt version of std::countr_one. It counts the number
1653 /// of ones from the least significant bit to the first zero bit.
1655 /// \returns BitWidth if the value is all ones, otherwise returns the number
1656 /// of ones from the least significant bit to the first zero bit.
1660 return countTrailingOnesSlowCase();
1665 /// Count the number of bits set.
1667 /// This function is an APInt version of std::popcount. It counts the number
1668 /// of 1 bits in the APInt value.
1670 /// \returns 0 if the value is zero, otherwise returns the number of set bits.
1674 return countPopulationSlowCase();
1678 /// \name Conversion Functions
1682 /// Converts an APInt to a string and append it to Str. Str is commonly a
1683 /// SmallString. If Radix > 10, UpperCase determine the case of letter
1686 bool Signed,
bool formatAsCLiteral =
false,
1687 bool UpperCase =
true,
1688 bool InsertSeparators =
false)
const;
1690 /// Considers the APInt to be unsigned and converts it into a string in the
1691 /// radix given. The radix can be 2, 8, 10 16, or 36.
1693 toString(Str, Radix,
false,
false);
1696 /// Considers the APInt to be signed and converts it into a string in the
1697 /// radix given. The radix can be 2, 8, 10, 16, or 36.
1702 /// \returns a byte-swapped representation of this APInt Value.
1705 /// \returns the value with the bit representation reversed of this APInt
1709 /// Converts this APInt to a double value.
1712 /// Converts this unsigned APInt to a double value.
1715 /// Converts this signed APInt to a double value.
1718 /// Converts APInt bits to a double
1720 /// The conversion does not do a translation from integer to double, it just
1721 /// re-interprets the bits as a double. Note that it is valid to do this on
1722 /// any bit width. Exactly 64 bits will be translated.
1725#ifdef HAS_IEE754_FLOAT128
1726 float128 bitsToQuad()
const {
1727 __uint128_t ul = ((__uint128_t)U.pVal[1] << 64) + U.pVal[0];
1732 /// Converts APInt bits to a float
1734 /// The conversion does not do a translation from integer to float, it just
1735 /// re-interprets the bits as a float. Note that it is valid to do this on
1736 /// any bit width. Exactly 32 bits will be translated.
1741 /// Converts a double to APInt bits.
1743 /// The conversion does not do a translation from double to integer, it just
1744 /// re-interprets the bits of the double.
1749 /// Converts a float to APInt bits.
1751 /// The conversion does not do a translation from float to integer, it just
1752 /// re-interprets the bits of the float.
1758 /// \name Mathematics Operations
1761 /// \returns the floor log base 2 of this APInt.
1764 /// \returns the ceil log base 2 of this APInt.
1771 /// \returns the nearest log base 2 of this APInt. Ties round up.
1773 /// NOTE: When we have a BitWidth of 1, we define:
1775 /// log2(0) = UINT32_MAX
1778 /// to get around any mathematical concerns resulting from
1779 /// referencing 2 in a space where 2 does no exist.
1780 LLVM_ABI unsigned nearestLogBase2()
const;
1782 /// \returns the log base 2 of this APInt if its an exact power of two, -1
1790 /// Compute the square root.
1793 /// Get the absolute value. If *this is < 0 then return -(*this), otherwise
1794 /// *this. Note that the "most negative" signed number (e.g. -128 for 8 bit
1795 /// wide APInt) is unchanged due to how negation works.
1802 /// \returns the multiplicative inverse of an odd APInt modulo 2^BitWidth.
1806 /// \name Building-block Operations for APInt and APFloat
1809 // These building block operations operate on a representation of arbitrary
1810 // precision, two's-complement, bignum integer values. They should be
1811 // sufficient to implement APInt and APFloat bignum requirements. Inputs are
1812 // generally a pointer to the base of an array of integer parts, representing
1813 // an unsigned bignum, and a count of how many parts there are.
1815 /// Sets the least significant part of a bignum to the input value, and zeroes
1816 /// out higher parts.
1817 LLVM_ABI static void tcSet(WordType *, WordType,
unsigned);
1819 /// Assign one bignum to another.
1820 LLVM_ABI static void tcAssign(WordType *,
const WordType *,
unsigned);
1822 /// Returns true if a bignum is zero, false otherwise.
1823 LLVM_ABI static bool tcIsZero(
const WordType *,
unsigned);
1825 /// Extract the given bit of a bignum; returns 0 or 1. Zero-based.
1826 LLVM_ABI static int tcExtractBit(
const WordType *,
unsigned bit);
1828 /// Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to
1829 /// DST, of dstCOUNT parts, such that the bit srcLSB becomes the least
1830 /// significant bit of DST. All high bits above srcBITS in DST are
1832 LLVM_ABI static void tcExtract(WordType *,
unsigned dstCount,
1833 const WordType *,
unsigned srcBits,
1836 /// Set the given bit of a bignum. Zero-based.
1837 LLVM_ABI static void tcSetBit(WordType *,
unsigned bit);
1839 /// Clear the given bit of a bignum. Zero-based.
1840 LLVM_ABI static void tcClearBit(WordType *,
unsigned bit);
1842 /// Returns the bit number of the least or most significant set bit of a
1843 /// number. If the input number has no bits set -1U is returned.
1844 LLVM_ABI static unsigned tcLSB(
const WordType *,
unsigned n);
1845 LLVM_ABI static unsigned tcMSB(
const WordType *parts,
unsigned n);
1847 /// Negate a bignum in-place.
1848 LLVM_ABI static void tcNegate(WordType *,
unsigned);
1850 /// DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
1851 LLVM_ABI static WordType tcAdd(WordType *,
const WordType *, WordType carry,
1853 /// DST += RHS. Returns the carry flag.
1854 LLVM_ABI static WordType tcAddPart(WordType *, WordType,
unsigned);
1856 /// DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
1857 LLVM_ABI static WordType tcSubtract(WordType *,
const WordType *,
1858 WordType carry,
unsigned);
1859 /// DST -= RHS. Returns the carry flag.
1860 LLVM_ABI static WordType tcSubtractPart(WordType *, WordType,
unsigned);
1862 /// DST += SRC * MULTIPLIER + PART if add is true
1863 /// DST = SRC * MULTIPLIER + PART if add is false
1865 /// Requires 0 <= DSTPARTS <= SRCPARTS + 1. If DST overlaps SRC they must
1866 /// start at the same point, i.e. DST == SRC.
1868 /// If DSTPARTS == SRC_PARTS + 1 no overflow occurs and zero is returned.
1869 /// Otherwise DST is filled with the least significant DSTPARTS parts of the
1870 /// result, and if all of the omitted higher parts were zero return zero,
1871 /// otherwise overflow occurred and return one.
1872 LLVM_ABI static int tcMultiplyPart(WordType *dst,
const WordType *src,
1873 WordType multiplier, WordType carry,
1874 unsigned srcParts,
unsigned dstParts,
1877 /// DST = LHS * RHS, where DST has the same width as the operands and is
1878 /// filled with the least significant parts of the result. Returns one if
1879 /// overflow occurred, otherwise zero. DST must be disjoint from both
1881 LLVM_ABI static int tcMultiply(WordType *,
const WordType *,
const WordType *,
1884 /// DST = LHS * RHS, where DST has width the sum of the widths of the
1885 /// operands. No overflow occurs. DST must be disjoint from both operands.
1886 LLVM_ABI static void tcFullMultiply(WordType *,
const WordType *,
1887 const WordType *,
unsigned,
unsigned);
1889 /// If RHS is zero LHS and REMAINDER are left unchanged, return one.
1890 /// Otherwise set LHS to LHS / RHS with the fractional part discarded, set
1891 /// REMAINDER to the remainder, return zero. i.e.
1893 /// OLD_LHS = RHS * LHS + REMAINDER
1895 /// SCRATCH is a bignum of the same size as the operands and result for use by
1896 /// the routine; its contents need not be initialized and are destroyed. LHS,
1897 /// REMAINDER and SCRATCH must be distinct.
1898 LLVM_ABI static int tcDivide(WordType *lhs,
const WordType *rhs,
1899 WordType *remainder, WordType *scratch,
1902 /// Shift a bignum left Count bits. Shifted in bits are zero. There are no
1903 /// restrictions on Count.
1904 LLVM_ABI static void tcShiftLeft(WordType *,
unsigned Words,
unsigned Count);
1906 /// Shift a bignum right Count bits. Shifted in bits are zero. There are no
1907 /// restrictions on Count.
1908 LLVM_ABI static void tcShiftRight(WordType *,
unsigned Words,
unsigned Count);
1910 /// Comparison (unsigned) of two bignums.
1911 LLVM_ABI static int tcCompare(
const WordType *,
const WordType *,
unsigned);
1913 /// Increment a bignum in-place. Return the carry flag.
1918 /// Decrement a bignum in-place. Return the borrow flag.
1923 /// Used to insert APInt objects, or objects that contain APInt objects, into
1927#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1932 /// Returns whether this instance allocated memory.
1936 /// This union is used to store the integer value. When the
1937 /// integer bit-width <= 64, it uses VAL, otherwise it uses pVal.
1943 unsigned BitWidth = 1;
///< The number of bits in this APInt.
1948 // Make DynamicAPInt a friend so it can access BitWidth directly.
1949 friend DynamicAPInt;
1951 /// This constructor is used only internally for speed of construction of
1952 /// temporaries. It is unsafe since it takes ownership of the pointer, so it
1954 APInt(
uint64_t *val,
unsigned bits) : BitWidth(bits) { U.pVal = val; }
1956 /// Determine which word a bit is in.
1958 /// \returns the word position for the specified bit position.
1959 static unsigned whichWord(
unsigned bitPosition) {
1960 return bitPosition / APINT_BITS_PER_WORD;
1963 /// Determine which bit in a word the specified bit position is in.
1964 static unsigned whichBit(
unsigned bitPosition) {
1965 return bitPosition % APINT_BITS_PER_WORD;
1968 /// Get a single bit mask.
1970 /// \returns a uint64_t with only bit at "whichBit(bitPosition)" set
1971 /// This method generates and returns a uint64_t (word) mask for a single
1972 /// bit at a specific bit position. This is used to mask the bit in the
1973 /// corresponding word.
1974 static uint64_t maskBit(
unsigned bitPosition) {
1975 return 1ULL << whichBit(bitPosition);
1978 /// Clear unused high order bits
1980 /// This method is used internally to clear the top "N" bits in the high order
1981 /// word that are not used by the APInt. This is needed after the most
1982 /// significant word is assigned a value to ensure that those bits are
1985 // Compute how many bits are used in the final word.
1986 unsigned WordBits = ((
BitWidth - 1) % APINT_BITS_PER_WORD) + 1;
1988 // Mask out the high bits.
1989 uint64_t
mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - WordBits);
1996 U.pVal[getNumWords() - 1] &=
mask;
2000 /// Get the word corresponding to a bit position
2001 /// \returns the corresponding word for the specified bit position.
2002 uint64_t getWord(
unsigned bitPosition)
const {
2003 return isSingleWord() ?
U.VAL :
U.pVal[whichWord(bitPosition)];
2006 /// Utility method to change the bit width of this APInt to new bit width,
2007 /// allocating and/or deallocating as necessary. There is no guarantee on the
2008 /// value of any bits upon return. Caller should populate the bits after.
2009 void reallocate(
unsigned NewBitWidth);
2011 /// Convert a char array into an APInt
2013 /// \param radix 2, 8, 10, 16, or 36
2014 /// Converts a string into a number. The string must be non-empty
2015 /// and well-formed as a number of the given base. The bit-width
2016 /// must be sufficient to hold the result.
2018 /// This is used by the constructors that take string arguments.
2020 /// StringRef::getAsInteger is superficially similar but (1) does
2021 /// not assume that the string is well-formed and (2) grows the
2022 /// result to hold the input.
2023 void fromString(
unsigned numBits, StringRef str, uint8_t radix);
2025 /// An internal division function for dividing APInts.
2027 /// This is used by the toString method to divide by the radix. It simply
2028 /// provides a more convenient form of divide for internal use since KnuthDiv
2029 /// has specific constraints on its inputs. If those constraints are not met
2030 /// then it provides a simpler form of divide.
2031 static void divide(
const WordType *
LHS,
unsigned lhsWords,
2032 const WordType *
RHS,
unsigned rhsWords, WordType *Quotient,
2033 WordType *Remainder);
2035 /// out-of-line slow case for inline constructor
2038 /// shared code between two array constructors
2039 void initFromArray(ArrayRef<uint64_t> array);
2041 /// out-of-line slow case for inline copy constructor
2042 LLVM_ABI void initSlowCase(
const APInt &that);
2044 /// out-of-line slow case for shl
2045 LLVM_ABI void shlSlowCase(
unsigned ShiftAmt);
2047 /// out-of-line slow case for lshr.
2048 LLVM_ABI void lshrSlowCase(
unsigned ShiftAmt);
2050 /// out-of-line slow case for ashr.
2051 LLVM_ABI void ashrSlowCase(
unsigned ShiftAmt);
2053 /// out-of-line slow case for operator=
2056 /// out-of-line slow case for operator==
2059 /// out-of-line slow case for countLeadingZeros
2062 /// out-of-line slow case for countLeadingOnes.
2065 /// out-of-line slow case for countTrailingZeros.
2068 /// out-of-line slow case for countTrailingOnes
2071 /// out-of-line slow case for countPopulation
2074 /// out-of-line slow case for intersects.
2077 /// out-of-line slow case for isSubsetOf.
2080 /// out-of-line slow case for setBits.
2081 LLVM_ABI void setBitsSlowCase(
unsigned loBit,
unsigned hiBit);
2083 /// out-of-line slow case for clearBits.
2084 LLVM_ABI void clearBitsSlowCase(
unsigned LoBit,
unsigned HiBit);
2086 /// out-of-line slow case for flipAllBits.
2087 LLVM_ABI void flipAllBitsSlowCase();
2089 /// out-of-line slow case for concat.
2092 /// out-of-line slow case for operator&=.
2095 /// out-of-line slow case for operator|=.
2098 /// out-of-line slow case for operator^=.
2101 /// Unsigned comparison. Returns -1, 0, or 1 if this APInt is less than, equal
2102 /// to, or greater than RHS.
2105 /// Signed comparison. Returns -1, 0, or 1 if this APInt is less than, equal
2106 /// to, or greater than RHS.
2116/// Unary bitwise complement operator.
2118/// \returns an APInt that is the bitwise complement of \p v.
2131 return std::move(b);
2151 return std::move(b);
2171 return std::move(b);
2201 return std::move(b);
2222 return std::move(b);
2248/// Determine the smaller of two APInts considered to be signed.
2250 return A.slt(
B) ?
A :
B;
2253/// Determine the larger of two APInts considered to be signed.
2255 return A.sgt(
B) ?
A :
B;
2258/// Determine the smaller of two APInts considered to be unsigned.
2260 return A.ult(
B) ?
A :
B;
2263/// Determine the larger of two APInts considered to be unsigned.
2265 return A.ugt(
B) ?
A :
B;
2268/// Determine the absolute difference of two APInts considered to be signed.
2270 return A.sge(
B) ? (
A -
B) : (
B -
A);
2273/// Determine the absolute difference of two APInts considered to be unsigned.
2275 return A.uge(
B) ? (
A -
B) : (
B -
A);
2278/// Compute the floor of the signed average of C1 and C2
2281/// Compute the floor of the unsigned average of C1 and C2
2284/// Compute the ceil of the signed average of C1 and C2
2287/// Compute the ceil of the unsigned average of C1 and C2
2290/// Performs (2*N)-bit multiplication on sign-extended operands.
2291/// Returns the high N bits of the multiplication result.
2294/// Performs (2*N)-bit multiplication on zero-extended operands.
2295/// Returns the high N bits of the multiplication result.
2298/// Performs (2*N)-bit multiplication on sign-extended operands.
2301/// Performs (2*N)-bit multiplication on zero-extended operands.
2304/// Compute X^N for N>=0.
2305/// 0^0 is supported and returns 1.
2308/// Compute GCD of two unsigned APInt values.
2310/// This function returns the greatest common divisor of the two APInt values
2311/// using Stein's algorithm.
2313/// \returns the greatest common divisor of A and B.
2316/// Converts the given APInt to a double value.
2318/// Treats the APInt as an unsigned value for conversion purposes.
2323/// Converts the given APInt to a double value.
2325/// Treats the APInt as a signed value for conversion purposes.
2330/// Converts the given APInt to a float value.
2335/// Converts the given APInt to a float value.
2337/// Treats the APInt as a signed value for conversion purposes.
2342/// Converts the given double value into a APInt.
2344/// This function convert a double value to an APInt value.
2345LLVM_ABI APInt RoundDoubleToAPInt(
double Double,
unsigned width);
2347/// Converts a float value into a APInt.
2349/// Converts a float value into an APInt value.
2354/// Return A unsign-divided by B, rounded by the given rounding mode.
2357/// Return A sign-divided by B, rounded by the given rounding mode.
2360/// Let q(n) = An^2 + Bn + C, and BW = bit width of the value range
2361/// (e.g. 32 for i32).
2362/// This function finds the smallest number n, such that
2363/// (a) n >= 0 and q(n) = 0, or
2364/// (b) n >= 1 and q(n-1) and q(n), when evaluated in the set of all
2365/// integers, belong to two different intervals [Rk, Rk+R),
2366/// where R = 2^BW, and k is an integer.
2367/// The idea here is to find when q(n) "overflows" 2^BW, while at the
2368/// same time "allowing" subtraction. In unsigned modulo arithmetic a
2369/// subtraction (treated as addition of negated numbers) would always
2370/// count as an overflow, but here we want to allow values to decrease
2371/// and increase as long as they are within the same interval.
2372/// Specifically, adding of two negative numbers should not cause an
2373/// overflow (as long as the magnitude does not exceed the bit width).
2374/// On the other hand, given a positive number, adding a negative
2375/// number to it can give a negative result, which would cause the
2376/// value to go from [-2^BW, 0) to [0, 2^BW). In that sense, zero is
2377/// treated as a special case of an overflow.
2379/// This function returns std::nullopt if after finding k that minimizes the
2380/// positive solution to q(n) = kR, both solutions are contained between
2381/// two consecutive integers.
2383/// There are cases where q(n) > T, and q(n+1) < T (assuming evaluation
2384/// in arithmetic modulo 2^BW, and treating the values as signed) by the
2385/// virtue of *signed* overflow. This function will *not* find such an n,
2386/// however it may find a value of n satisfying the inequalities due to
2387/// an *unsigned* overflow (if the values are treated as unsigned).
2388/// To find a solution for a signed overflow, treat it as a problem of
2389/// finding an unsigned overflow with a range with of BW-1.
2391/// The returned value may have a different bit width from the input
2396/// Compare two values, and if they are different, return the position of the
2397/// most significant bit that is different in the values.
2398LLVM_ABI std::optional<unsigned> GetMostSignificantDifferentBit(
const APInt &
A,
2401/// Splat/Merge neighboring bits to widen/narrow the bitmask represented
2402/// by \param A to \param NewBitWidth bits.
2404/// MatchAnyBits: (Default)
2405/// e.g. ScaleBitMask(0b0101, 8) -> 0b00110011
2406/// e.g. ScaleBitMask(0b00011011, 4) -> 0b0111
2409/// e.g. ScaleBitMask(0b0101, 8) -> 0b00110011
2410/// e.g. ScaleBitMask(0b00011011, 4) -> 0b0001
2411/// A.getBitwidth() or NewBitWidth must be a whole multiples of the other.
2413 bool MatchAllBits =
false);
2415/// Perform a funnel shift left.
2417/// Concatenate Hi and Lo (Hi is the most significant bits of the wide value),
2418/// the combined value is shifted left by Shift (modulo the bit width of the
2419/// original arguments), and the most significant bits are extracted to produce
2420/// a result that is the same size as the original arguments.
2423/// (1) fshl(i8 255, i8 0, i8 15) = 128 (0b10000000)
2424/// (2) fshl(i8 15, i8 15, i8 11) = 120 (0b01111000)
2425/// (3) fshl(i8 0, i8 255, i8 8) = 0 (0b00000000)
2426/// (4) fshl(i8 255, i8 0, i8 15) = fshl(i8 255, i8 0, i8 7) // 15 % 8
2429/// Perform a funnel shift right.
2431/// Concatenate Hi and Lo (Hi is the most significant bits of the wide value),
2432/// the combined value is shifted right by Shift (modulo the bit width of the
2433/// original arguments), and the least significant bits are extracted to produce
2434/// a result that is the same size as the original arguments.
2437/// (1) fshr(i8 255, i8 0, i8 15) = 254 (0b11111110)
2438/// (2) fshr(i8 15, i8 15, i8 11) = 225 (0b11100001)
2439/// (3) fshr(i8 0, i8 255, i8 8) = 255 (0b11111111)
2440/// (4) fshr(i8 255, i8 0, i8 9) = fshr(i8 255, i8 0, i8 1) // 9 % 8
2443}
// namespace APIntOps
2445// See friend declaration above. This additional declaration is required in
2446// order to compile LLVM with IBM xlC compiler.
2447LLVM_ABI hash_code hash_value(
const APInt &Arg);
2449/// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
2450/// with the integer held in IntVal.
2452 unsigned StoreBytes);
2454/// LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting
2455/// from Src into IntVal, which is assumed to be wide enough and to hold zero.
2457 unsigned LoadBytes);
2459/// Provide DenseMapInfo for APInt.
2462 APInt V(
nullptr, 0);
2468 APInt V(
nullptr, 0);
2476 return LHS.getBitWidth() ==
RHS.getBitWidth() &&
LHS ==
RHS;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static constexpr unsigned long long mask(BlockVerifier::State S)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
raw_ostream & operator<<(raw_ostream &OS, const binary_le_impl< value_type > &BLE)
#define LLVM_UNLIKELY(EXPR)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static bool isSigned(unsigned int Opcode)
static KnownBits extractBits(unsigned BitWidth, const KnownBits &SrcOpKnown, const KnownBits &OffsetKnown, const KnownBits &WidthKnown)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
static bool isAligned(const Value *Base, Align Alignment, const DataLayout &DL)
static bool isSplat(Value *V)
Return true if V is a splat of a value (which is used when multiplying a matrix with a scalar).
static const char * toString(MIToken::TokenKind TokenKind)
static uint64_t clearUnusedBits(uint64_t Val, unsigned Size)
static uint64_t umul_ov(uint64_t i, uint64_t j, bool &Overflow)
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Class for arbitrary precision integers.
std::optional< uint64_t > tryZExtValue() const
Get zero extended value if possible.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
bool slt(int64_t RHS) const
Signed less than comparison.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
APInt relativeLShr(int RelativeShift) const
relative logical shift right
bool isNegatedPowerOf2() const
Check if this APInt's negated value is a power of two greater than zero.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
APInt operator--(int)
Postfix decrement operator.
uint64_t getZExtValue() const
Get zero extended value.
uint64_t * pVal
Used to store the >64 bits integer value.
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
unsigned popcount() const
Count the number of bits set.
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
APInt operator<<(const APInt &Bits) const
Left logical shift operator.
APInt operator<<(unsigned Bits) const
Left logical shift operator.
unsigned getActiveBits() const
Compute the number of active bits in the value.
bool sgt(int64_t RHS) const
Signed greater than comparison.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
bool operator[](unsigned bitPosition) const
Array-indexing support.
bool operator!=(const APInt &RHS) const
Inequality operator.
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.
APInt & operator&=(const APInt &RHS)
Bitwise AND assignment operator.
APInt abs() const
Get the absolute value.
unsigned ceilLogBase2() const
unsigned countLeadingOnes() const
APInt relativeLShl(int RelativeShift) const
relative logical shift left
APInt & operator=(const APInt &RHS)
Copy assignment operator.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
APInt(unsigned numBits, uint64_t val, bool isSigned=false, bool implicitTrunc=false)
Create a new APInt of numBits width, initialized as val.
APInt & operator^=(uint64_t RHS)
Bitwise XOR assignment operator.
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
APInt & operator|=(uint64_t RHS)
Bitwise OR assignment operator.
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
static APInt floatToBits(float V)
Converts a float to APInt bits.
void setSignBit()
Set the sign bit to 1.
static constexpr unsigned APINT_WORD_SIZE
Byte size of a word.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool sle(uint64_t RHS) const
Signed less or equal comparison.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
bool uge(uint64_t RHS) const
Unsigned greater or equal comparison.
bool operator!() const
Logical negation operation on this APInt returns true if zero, like normal integers.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
APInt & operator=(uint64_t RHS)
Assignment operator.
APInt relativeAShr(int RelativeShift) const
relative arithmetic shift right
APInt(const APInt &that)
Copy Constructor.
APInt & operator|=(const APInt &RHS)
Bitwise OR assignment operator.
bool isSingleWord() const
Determine if this APInt just has one word to store value.
bool operator==(uint64_t Val) const
Equality operator.
APInt operator++(int)
Postfix increment operator.
unsigned getNumWords() const
Get the number of words.
bool isMinValue() const
Determine if this is the smallest unsigned value.
APInt ashr(const APInt &ShiftAmt) const
Arithmetic right-shift function.
APInt()
Default constructor that creates an APInt with a 1-bit zero value.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
APInt(APInt &&that)
Move Constructor.
bool isNegative() const
Determine sign of this APInt.
APInt concat(const APInt &NewLSB) const
Concatenate the bits from "NewLSB" onto the bottom of *this.
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
bool eq(const APInt &RHS) const
Equality comparison.
int32_t exactLogBase2() const
APInt & operator<<=(unsigned ShiftAmt)
Left-shift assignment function.
double roundToDouble() const
Converts this unsigned APInt to a double value.
void clearAllBits()
Set every bit to 0.
APInt relativeAShl(int RelativeShift) const
relative arithmetic shift left
void ashrInPlace(unsigned ShiftAmt)
Arithmetic right-shift this APInt by ShiftAmt in place.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
void negate()
Negate this APInt in place.
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
unsigned countr_zero() const
Count the number of trailing zero bits.
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
bool isOneBitSet(unsigned BitNo) const
Determine if this APInt Value only has the specified bit set.
unsigned countl_zero() const
The APInt version of std::countl_zero.
bool operator==(const APInt &RHS) const
Equality operator.
APInt shl(const APInt &ShiftAmt) const
Left-shift function.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
LLVM_ABI friend hash_code hash_value(const APInt &Arg)
Overload to compute a hash_code for an APInt value.
bool isShiftedMask(unsigned &MaskIdx, unsigned &MaskLen) const
Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
static constexpr WordType WORDTYPE_MAX
static LLVM_ABI WordType tcSubtractPart(WordType *, WordType, unsigned)
DST -= RHS. Returns the carry flag.
void setBitsWithWrap(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
APInt lshr(const APInt &ShiftAmt) const
Logical right-shift function.
bool isNonPositive() const
Determine if this APInt Value is non-positive (<= 0).
unsigned countTrailingZeros() const
unsigned getSignificantBits() const
Get the minimum bit size for this signed APInt.
unsigned countLeadingZeros() const
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
void flipAllBits()
Toggle every bit to its opposite value.
static unsigned getNumWords(unsigned BitWidth)
Get the number of words.
bool needsCleanup() const
Returns whether this instance allocated memory.
unsigned countl_one() const
Count the number of leading one bits.
void clearLowBits(unsigned loBits)
Set bottom loBits bits to 0.
unsigned logBase2() const
static APInt getZeroWidth()
Return an APInt zero bits wide.
double signedRoundToDouble() const
Converts this signed APInt to a double value.
bool isShiftedMask() const
Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
float bitsToFloat() const
Converts APInt bits to a float.
static constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
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.
bool ule(uint64_t RHS) const
Unsigned less or equal comparison.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
void setAllBits()
Set every bit to 1.
uint64_t VAL
Used to store the <= 64 bits integer value.
bool ugt(uint64_t RHS) const
Unsigned greater than comparison.
bool sge(int64_t RHS) const
Signed greater or equal comparison.
bool getBoolValue() const
Convert APInt to a boolean value.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
bool isMask(unsigned numBits) const
APInt & operator=(APInt &&that)
Move assignment operator.
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
APInt & operator^=(const APInt &RHS)
Bitwise XOR assignment operator.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
void setBits(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
APInt shl(unsigned shiftAmt) const
Left-shift function.
double bitsToDouble() const
Converts APInt bits to a double.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
bool ne(const APInt &RHS) const
Inequality comparison.
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!...
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
void clearBits(unsigned LoBit, unsigned HiBit)
Clear the bits from LoBit (inclusive) to HiBit (exclusive) to 0.
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
static LLVM_ABI WordType tcAddPart(WordType *, WordType, unsigned)
DST += RHS. Returns the carry flag.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
bool slt(const APInt &RHS) const
Signed less than comparison.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
unsigned countTrailingOnes() const
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
std::optional< int64_t > trySExtValue() const
Get sign extended value if possible.
APInt & operator&=(uint64_t RHS)
Bitwise AND assignment operator.
LLVM_ABI double roundToDouble(bool isSigned) const
Converts this APInt to a double value.
bool isOne() const
Determine if this is a value of 1.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
void clearHighBits(unsigned hiBits)
Set top hiBits bits to 0.
int64_t getSExtValue() const
Get sign extended value.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
unsigned countr_one() const
Count the number of trailing one bits.
static APInt getBitsSetWithWrap(unsigned numBits, unsigned loBit, unsigned hiBit)
Wrap version of getBitsSet.
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
void setBitVal(unsigned BitPosition, bool BitValue)
Set a given bit to a given value.
void clearSignBit()
Set the sign bit to 0.
bool isMaxValue() const
Determine if this is the largest unsigned value.
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.
bool ult(uint64_t RHS) const
Unsigned less than comparison.
bool operator!=(uint64_t Val) const
Inequality operator.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class provides support for dynamic arbitrary-precision arithmetic.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
An opaque object representing a hash code.
This class implements an extremely fast bulk output stream that can only output to a stream.
LLVM_ABI std::error_code fromString(StringRef String, Metadata &HSAMetadata)
Converts String to HSAMetadata.
float RoundAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float value.
double RoundAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
APInt RoundFloatToAPInt(float Float, unsigned width)
Converts a float value into a APInt.
LLVM_ABI APInt RoundDoubleToAPInt(double Double, unsigned width)
Converts the given double value into a APInt.
APInt abds(const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be signed.
double RoundSignedAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
APInt abdu(const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be unsigned.
float RoundSignedAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float value.
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
constexpr T rotr(T V, int R)
APInt operator&(APInt a, const APInt &b)
APInt operator*(APInt a, uint64_t RHS)
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
bool operator!=(uint64_t V1, const APInt &V2)
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator+=(DynamicAPInt &A, int64_t B)
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator-=(DynamicAPInt &A, int64_t B)
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
APInt operator~(APInt v)
Unary bitwise complement operator.
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
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...
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator*=(DynamicAPInt &A, int64_t B)
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
APInt operator^(APInt a, const APInt &b)
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...
FunctionAddr VTableAddr Count
int countl_one(T Value)
Count the number of ones from the most significant bit to the first zero bit.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
To bit_cast(const From &from) noexcept
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
constexpr T reverseBits(T Val)
Reverse the bits in Val.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
APInt operator+(APInt a, const APInt &b)
APInt operator|(APInt a, const APInt &b)
constexpr T rotl(T V, int R)
@ Keep
No function return thunk.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static APInt getEmptyKey()
static APInt getTombstoneKey()
static bool isEqual(const APInt &LHS, const APInt &RHS)
static LLVM_ABI unsigned getHashValue(const APInt &Key)
An information struct used to provide DenseMap with the various necessary components for a given valu...