LLVM: include/llvm/ADT/APInt.h Source File

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

Generated on for LLVM by doxygen 1.14.0

AltStyle によって変換されたページ (->オリジナル) /