Improve documentation.
[oota-llvm.git] / include / llvm / ADT / APInt.h
1 //===-- llvm/Support/APInt.h - For Arbitrary Precision Integer -*- C++ -*--===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Sheng Zhou and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements a class to represent arbitrary precision integral
11 // constant values.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_APINT_H
16 #define LLVM_APINT_H
17
18 #include "llvm/Support/DataTypes.h"
19 #include <cassert>
20 #include <string>
21
22 namespace llvm {
23
24 /// Forward declaration.
25 class APInt;
26 namespace APIntOps {
27   APInt udiv(const APInt& LHS, const APInt& RHS);
28   APInt urem(const APInt& LHS, const APInt& RHS);
29 }
30
31 //===----------------------------------------------------------------------===//
32 //                              APInt Class
33 //===----------------------------------------------------------------------===//
34
35 /// APInt - This class represents arbitrary precision constant integral values.
36 /// It is a functional replacement for common case unsigned integer type like 
37 /// "unsigned", "unsigned long" or "uint64_t", but also allows non-byte-width 
38 /// integer sizes and large integer value types such as 3-bits, 15-bits, or more
39 /// than 64-bits of precision. APInt provides a variety of arithmetic operators 
40 /// and methods to manipulate integer values of any bit-width. It supports both
41 /// the typical integer arithmetic and comparison operations as well as bitwise
42 /// manipulation.
43 ///
44 /// The class has several invariants worth noting:
45 ///   * All bit, byte, and word positions are zero-based.
46 ///   * Once the bit width is set, it doesn't change except by the Truncate, 
47 ///     SignExtend, or ZeroExtend operations.
48 ///   * All binary operators must be on APInt instances of the same bit width.
49 ///     Attempting to use these operators on instances with different bit 
50 ///     widths will yield an assertion.
51 ///   * The value is stored canonically as an unsigned value. For operations
52 ///     where it makes a difference, there are both signed and unsigned variants
53 ///     of the operation. For example, sdiv and udiv. However, because the bit
54 ///     widths must be the same, operations such as Mul and Add produce the same
55 ///     results regardless of whether the values are interpreted as signed or
56 ///     not.
57 ///   * In general, the class tries to follow the style of computation that LLVM
58 ///     uses in its IR. This simplifies its use for LLVM.
59 ///
60 /// @brief Class for arbitrary precision integers.
61 class APInt {
62 public:
63   uint32_t BitWidth;      ///< The number of bits in this APInt.
64
65   /// This union is used to store the integer value. When the
66   /// integer bit-width <= 64, it uses VAL; 
67   /// otherwise it uses the pVal.
68   union {
69     uint64_t VAL;    ///< Used to store the <= 64 bits integer value.
70     uint64_t *pVal;  ///< Used to store the >64 bits integer value.
71   };
72
73   /// This enum is just used to hold a constant we needed for APInt.
74   enum {
75     APINT_BITS_PER_WORD = sizeof(uint64_t) * 8,
76     APINT_WORD_SIZE = sizeof(uint64_t)
77   };
78
79   /// Here one word's bitwidth equals to that of uint64_t.
80   /// @returns the number of words to hold the integer value of this APInt.
81   /// @brief Get the number of words.
82   inline uint32_t getNumWords() const {
83     return (BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
84   }
85
86   /// @returns true if the number of bits <= 64, false otherwise.
87   /// @brief Determine if this APInt just has one word to store value.
88   inline bool isSingleWord() const { 
89     return BitWidth <= APINT_BITS_PER_WORD; 
90   }
91
92   /// @returns the word position for the specified bit position.
93   static inline uint32_t whichWord(uint32_t bitPosition) { 
94     return bitPosition / APINT_BITS_PER_WORD; 
95   }
96
97   /// @returns the bit position in a word for the specified bit position 
98   /// in APInt.
99   static inline uint32_t whichBit(uint32_t bitPosition) { 
100     return bitPosition % APINT_BITS_PER_WORD; 
101   }
102
103   /// @returns a uint64_t type integer with just bit position at
104   /// "whichBit(bitPosition)" setting, others zero.
105   static inline uint64_t maskBit(uint32_t bitPosition) { 
106     return (static_cast<uint64_t>(1)) << whichBit(bitPosition); 
107   }
108
109   /// This method is used internally to clear the to "N" bits that are not used
110   /// by the APInt. This is needed after the most significant word is assigned 
111   /// a value to ensure that those bits are zero'd out.
112   /// @brief Clear high order bits
113   inline void clearUnusedBits() {
114     if (isSingleWord())
115       VAL &= ~uint64_t(0ULL) >> (APINT_BITS_PER_WORD - BitWidth);
116     else
117       pVal[getNumWords() - 1] &= ~uint64_t(0ULL) >> 
118         (APINT_BITS_PER_WORD - (whichBit(BitWidth - 1) + 1));
119   }
120
121   /// @returns the corresponding word for the specified bit position.
122   /// @brief Get the word corresponding to a bit position
123   inline uint64_t getWord(uint32_t bitPosition) const { 
124     return isSingleWord() ? VAL : pVal[whichWord(bitPosition)]; 
125   }
126
127   /// This is used by the constructors that take string arguments.
128   /// @brief Converts a char array into an APInt
129   void fromString(uint32_t numBits, const char *StrStart, uint32_t slen, 
130                   uint8_t radix);
131
132   /// This is used by the toString method to divide by the radix. It simply
133   /// provides a more convenient form of divide for internal use.
134   /// @brief An internal division function for dividing APInts.
135   static void divide(const APInt LHS, uint32_t lhsWords, 
136                      const APInt &RHS, uint32_t rhsWords,
137                      APInt *Quotient, APInt *Remainder);
138
139 #ifndef NDEBUG
140   /// @brief debug method
141   void dump() const;
142 #endif
143
144 public:
145   /// @brief Create a new APInt of numBits width, initialized as val.
146   APInt(uint32_t numBits, uint64_t val);
147
148   /// Note that numWords can be smaller or larger than the corresponding bit
149   /// width but any extraneous bits will be dropped.
150   /// @brief Create a new APInt of numBits width, initialized as bigVal[].
151   APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[]);
152
153   /// @brief Create a new APInt by translating the string represented 
154   /// integer value.
155   APInt(uint32_t numBits, const std::string& Val, uint8_t radix);
156
157   /// @brief Create a new APInt by translating the char array represented
158   /// integer value.
159   APInt(uint32_t numBits, const char StrStart[], uint32_t slen, uint8_t radix);
160
161   /// @brief Copy Constructor.
162   APInt(const APInt& API);
163
164   /// @brief Destructor.
165   ~APInt();
166
167   /// @brief Copy assignment operator. 
168   APInt& operator=(const APInt& RHS);
169
170   /// Assigns an integer value to the APInt.
171   /// @brief Assignment operator. 
172   APInt& operator=(uint64_t RHS);
173
174   /// Increments the APInt by one.
175   /// @brief Postfix increment operator.
176   inline const APInt operator++(int) {
177     APInt API(*this);
178     ++(*this);
179     return API;
180   }
181
182   /// Increments the APInt by one.
183   /// @brief Prefix increment operator.
184   APInt& operator++();
185
186   /// Decrements the APInt by one.
187   /// @brief Postfix decrement operator. 
188   inline const APInt operator--(int) {
189     APInt API(*this);
190     --(*this);
191     return API;
192   }
193
194   /// Decrements the APInt by one.
195   /// @brief Prefix decrement operator. 
196   APInt& operator--();
197
198   /// Performs bitwise AND operation on this APInt and the given APInt& RHS, 
199   /// assigns the result to this APInt.
200   /// @brief Bitwise AND assignment operator. 
201   APInt& operator&=(const APInt& RHS);
202
203   /// Performs bitwise OR operation on this APInt and the given APInt& RHS, 
204   /// assigns the result to this APInt.
205   /// @brief Bitwise OR assignment operator. 
206   APInt& operator|=(const APInt& RHS);
207
208   /// Performs bitwise XOR operation on this APInt and the given APInt& RHS, 
209   /// assigns the result to this APInt.
210   /// @brief Bitwise XOR assignment operator. 
211   APInt& operator^=(const APInt& RHS);
212
213   /// Performs a bitwise complement operation on this APInt.
214   /// @brief Bitwise complement operator. 
215   APInt operator~() const;
216
217   /// Multiplies this APInt by the  given APInt& RHS and 
218   /// assigns the result to this APInt.
219   /// @brief Multiplication assignment operator. 
220   APInt& operator*=(const APInt& RHS);
221
222   /// Adds this APInt by the given APInt& RHS and 
223   /// assigns the result to this APInt.
224   /// @brief Addition assignment operator. 
225   APInt& operator+=(const APInt& RHS);
226
227   /// Subtracts this APInt by the given APInt &RHS and 
228   /// assigns the result to this APInt.
229   /// @brief Subtraction assignment operator. 
230   APInt& operator-=(const APInt& RHS);
231
232   /// Performs bitwise AND operation on this APInt and 
233   /// the given APInt& RHS.
234   /// @brief Bitwise AND operator. 
235   APInt operator&(const APInt& RHS) const;
236
237   /// Performs bitwise OR operation on this APInt and the given APInt& RHS.
238   /// @brief Bitwise OR operator. 
239   APInt operator|(const APInt& RHS) const;
240
241   /// Performs bitwise XOR operation on this APInt and the given APInt& RHS.
242   /// @brief Bitwise XOR operator. 
243   APInt operator^(const APInt& RHS) const;
244
245   /// Performs logical negation operation on this APInt.
246   /// @brief Logical negation operator. 
247   bool operator !() const;
248
249   /// Multiplies this APInt by the given APInt& RHS.
250   /// @brief Multiplication operator. 
251   APInt operator*(const APInt& RHS) const;
252
253   /// Adds this APInt by the given APInt& RHS.
254   /// @brief Addition operator. 
255   APInt operator+(const APInt& RHS) const;
256
257   /// Subtracts this APInt by the given APInt& RHS
258   /// @brief Subtraction operator. 
259   APInt operator-(const APInt& RHS) const;
260
261   /// @brief Unary negation operator
262   inline APInt operator-() const {
263     return APInt(BitWidth, 0) - (*this);
264   }
265
266   /// @brief Array-indexing support.
267   bool operator[](uint32_t bitPosition) const;
268
269   /// Compare this APInt with the given APInt& RHS 
270   /// for the validity of the equality relationship.
271   /// @brief Equality operator. 
272   bool operator==(const APInt& RHS) const;
273
274   /// Compare this APInt with the given uint64_t value
275   /// for the validity of the equality relationship.
276   /// @brief Equality operator.
277   bool operator==(uint64_t Val) const;
278
279   /// Compare this APInt with the given APInt& RHS 
280   /// for the validity of the inequality relationship.
281   /// @brief Inequality operator. 
282   inline bool operator!=(const APInt& RHS) const {
283     return !((*this) == RHS);
284   }
285
286   /// Compare this APInt with the given uint64_t value 
287   /// for the validity of the inequality relationship.
288   /// @brief Inequality operator. 
289   inline bool operator!=(uint64_t Val) const {
290     return !((*this) == Val);
291   }
292   
293   /// @brief Equality comparison
294   bool eq(const APInt &RHS) const {
295     return (*this) == RHS; 
296   }
297
298   /// @brief Inequality comparison
299   bool ne(const APInt &RHS) const {
300     return !((*this) == RHS);
301   }
302
303   /// @brief Unsigned less than comparison
304   bool ult(const APInt& RHS) const;
305
306   /// @brief Signed less than comparison
307   bool slt(const APInt& RHS) const;
308
309   /// @brief Unsigned less or equal comparison
310   bool ule(const APInt& RHS) const {
311     return ult(RHS) || eq(RHS);
312   }
313
314   /// @brief Signed less or equal comparison
315   bool sle(const APInt& RHS) const {
316     return slt(RHS) || eq(RHS);
317   }
318
319   /// @brief Unsigned greather than comparison
320   bool ugt(const APInt& RHS) const {
321     return !ult(RHS) && !eq(RHS);
322   }
323
324   /// @brief Signed greather than comparison
325   bool sgt(const APInt& RHS) const {
326     return !slt(RHS) && !eq(RHS);
327   }
328
329   /// @brief Unsigned greater or equal comparison
330   bool uge(const APInt& RHS) const {
331     return !ult(RHS);
332   }
333
334   /// @brief Signed greather or equal comparison
335   bool sge(const APInt& RHS) const {
336     return !slt(RHS);
337   }
338
339   /// Arithmetic right-shift this APInt by shiftAmt.
340   /// @brief Arithmetic right-shift function.
341   APInt ashr(uint32_t shiftAmt) const;
342
343   /// Logical right-shift this APInt by shiftAmt.
344   /// @brief Logical right-shift function.
345   APInt lshr(uint32_t shiftAmt) const;
346
347   /// Left-shift this APInt by shiftAmt.
348   /// @brief Left-shift function.
349   APInt shl(uint32_t shiftAmt) const;
350
351   /// Signed divide this APInt by APInt RHS.
352   /// @brief Signed division function for APInt.
353   inline APInt sdiv(const APInt& RHS) const {
354     bool isNegativeLHS = (*this)[BitWidth - 1];
355     bool isNegativeRHS = RHS[RHS.BitWidth - 1];
356     APInt Result = APIntOps::udiv(
357         isNegativeLHS ? -(*this) : (*this), isNegativeRHS ? -RHS : RHS);
358     return isNegativeLHS != isNegativeRHS ? -Result : Result;
359   }
360
361   /// Unsigned divide this APInt by APInt RHS.
362   /// @brief Unsigned division function for APInt.
363   APInt udiv(const APInt& RHS) const;
364
365   /// Signed remainder operation on APInt.
366   /// @brief Function for signed remainder operation.
367   inline APInt srem(const APInt& RHS) const {
368     bool isNegativeLHS = (*this)[BitWidth - 1];
369     bool isNegativeRHS = RHS[RHS.BitWidth - 1];
370     APInt Result = APIntOps::urem(
371         isNegativeLHS ? -(*this) : (*this), isNegativeRHS ? -RHS : RHS);
372     return isNegativeLHS ? -Result : Result;
373   }
374
375   /// Unsigned remainder operation on APInt.
376   /// @brief Function for unsigned remainder operation.
377   APInt urem(const APInt& RHS) const;
378
379   /// Truncate the APInt to a specified width. It is an error to specify a width
380   /// that is greater than or equal to the current width. 
381   /// @brief Truncate to new width.
382   void trunc(uint32_t width);
383
384   /// This operation sign extends the APInt to a new width. If the high order
385   /// bit is set, the fill on the left will be done with 1 bits, otherwise zero.
386   /// It is an error to specify a width that is less than or equal to the 
387   /// current width.
388   /// @brief Sign extend to a new width.
389   void sext(uint32_t width);
390
391   /// This operation zero extends the APInt to a new width. Thie high order bits
392   /// are filled with 0 bits.  It is an error to specify a width that is less 
393   /// than or equal to the current width.
394   /// @brief Zero extend to a new width.
395   void zext(uint32_t width);
396
397   /// @brief Set every bit to 1.
398   APInt& set();
399
400   /// Set the given bit to 1 whose position is given as "bitPosition".
401   /// @brief Set a given bit to 1.
402   APInt& set(uint32_t bitPosition);
403
404   /// @brief Set every bit to 0.
405   APInt& clear();
406
407   /// Set the given bit to 0 whose position is given as "bitPosition".
408   /// @brief Set a given bit to 0.
409   APInt& clear(uint32_t bitPosition);
410
411   /// @brief Toggle every bit to its opposite value.
412   APInt& flip();
413
414   /// Toggle a given bit to its opposite value whose position is given 
415   /// as "bitPosition".
416   /// @brief Toggles a given bit to its opposite value.
417   APInt& flip(uint32_t bitPosition);
418
419   /// This function returns the number of active bits which is defined as the
420   /// bit width minus the number of leading zeros. This is used in several
421   /// computations to see how "wide" the value is.
422   /// @brief Compute the number of active bits in the value
423   inline uint32_t getActiveBits() const {
424     return BitWidth - countLeadingZeros();
425   }
426
427   /// @returns a uint64_t value from this APInt. If this APInt contains a single
428   /// word, just returns VAL, otherwise pVal[0].
429   inline uint64_t getValue(bool isSigned = false) const {
430     if (isSingleWord())
431       return isSigned ? int64_t(VAL << (64 - BitWidth)) >> 
432                                        (64 - BitWidth) : VAL;
433     uint32_t n = getActiveBits();
434     if (n <= 64)
435       return pVal[0];
436     assert(0 && "This APInt's bitwidth > 64");
437   }
438
439   /// @returns the largest value for an APInt of the specified bit-width and 
440   /// if isSign == true, it should be largest signed value, otherwise largest
441   /// unsigned value.
442   /// @brief Gets max value of the APInt with bitwidth <= 64.
443   static APInt getMaxValue(uint32_t numBits, bool isSign);
444
445   /// @returns the smallest value for an APInt of the given bit-width and
446   /// if isSign == true, it should be smallest signed value, otherwise zero.
447   /// @brief Gets min value of the APInt with bitwidth <= 64.
448   static APInt getMinValue(uint32_t numBits, bool isSign);
449
450   /// @returns the all-ones value for an APInt of the specified bit-width.
451   /// @brief Get the all-ones value.
452   static APInt getAllOnesValue(uint32_t numBits);
453
454   /// @returns the '0' value for an APInt of the specified bit-width.
455   /// @brief Get the '0' value.
456   static APInt getNullValue(uint32_t numBits);
457
458   /// This converts the APInt to a boolean valy as a test against zero.
459   /// @brief Boolean conversion function. 
460   inline bool getBoolValue() const {
461     return countLeadingZeros() != BitWidth;
462   }
463
464   /// @returns a character interpretation of the APInt.
465   std::string toString(uint8_t radix = 10, bool wantSigned = true) const;
466
467   /// Get an APInt with the same BitWidth as this APInt, just zero mask
468   /// the low bits and right shift to the least significant bit.
469   /// @returns the high "numBits" bits of this APInt.
470   APInt getHiBits(uint32_t numBits) const;
471
472   /// Get an APInt with the same BitWidth as this APInt, just zero mask
473   /// the high bits.
474   /// @returns the low "numBits" bits of this APInt.
475   APInt getLoBits(uint32_t numBits) const;
476
477   /// @returns true if the argument APInt value is a power of two > 0.
478   bool isPowerOf2() const; 
479
480   /// @returns the number of zeros from the most significant bit to the first
481   /// one bits.
482   uint32_t countLeadingZeros() const;
483
484   /// @returns the number of zeros from the least significant bit to the first
485   /// one bit.
486   uint32_t countTrailingZeros() const;
487
488   /// @returns the number of set bits.
489   uint32_t countPopulation() const; 
490
491   /// @returns the total number of bits.
492   inline uint32_t getBitWidth() const { 
493     return BitWidth; 
494   }
495
496   /// @brief Check if this APInt has a N-bits integer value.
497   inline bool isIntN(uint32_t N) const {
498     assert(N && "N == 0 ???");
499     if (isSingleWord()) {
500       return VAL == (VAL & (~0ULL >> (64 - N)));
501     } else {
502       APInt Tmp(N, getNumWords(), pVal);
503       return Tmp == (*this);
504     }
505   }
506
507   /// @returns a byte-swapped representation of this APInt Value.
508   APInt byteSwap() const;
509
510   /// @returns the floor log base 2 of this APInt.
511   inline uint32_t logBase2() const {
512     return getNumWords() * APINT_BITS_PER_WORD - 1 - countLeadingZeros();
513   }
514
515   /// @brief Converts this APInt to a double value.
516   double roundToDouble(bool isSigned = false) const;
517
518 };
519
520 namespace APIntOps {
521
522 /// @brief Check if the specified APInt has a N-bits integer value.
523 inline bool isIntN(uint32_t N, const APInt& APIVal) {
524   return APIVal.isIntN(N);
525 }
526
527 /// @returns true if the argument APInt value is a sequence of ones
528 /// starting at the least significant bit with the remainder zero.
529 inline const bool isMask(uint32_t numBits, const APInt& APIVal) {
530   return APIVal.getBoolValue() && ((APIVal + APInt(numBits,1)) & APIVal) == 0;
531 }
532
533 /// @returns true if the argument APInt value contains a sequence of ones
534 /// with the remainder zero.
535 inline const bool isShiftedMask(uint32_t numBits, const APInt& APIVal) {
536   return isMask(numBits, (APIVal - APInt(numBits,1)) | APIVal);
537 }
538
539 /// @returns a byte-swapped representation of the specified APInt Value.
540 inline APInt byteSwap(const APInt& APIVal) {
541   return APIVal.byteSwap();
542 }
543
544 /// @returns the floor log base 2 of the specified APInt value.
545 inline uint32_t logBase2(const APInt& APIVal) {
546   return APIVal.logBase2(); 
547 }
548
549 /// @returns the greatest common divisor of the two values 
550 /// using Euclid's algorithm.
551 APInt GreatestCommonDivisor(const APInt& API1, const APInt& API2);
552
553 /// @brief Converts the given APInt to a double value.
554 inline double RoundAPIntToDouble(const APInt& APIVal, bool isSigned = false) {
555   return APIVal.roundToDouble(isSigned);
556 }
557
558 /// @brief Converts the given APInt to a float vlalue.
559 inline float RoundAPIntToFloat(const APInt& APIVal) {
560   return float(RoundAPIntToDouble(APIVal));
561 }
562
563 /// @brief Converts the given double value into a APInt.
564 APInt RoundDoubleToAPInt(double Double);
565
566 /// @brief Converts the given float value into a APInt.
567 inline APInt RoundFloatToAPInt(float Float) {
568   return RoundDoubleToAPInt(double(Float));
569 }
570
571 /// Arithmetic right-shift the APInt by shiftAmt.
572 /// @brief Arithmetic right-shift function.
573 inline APInt ashr(const APInt& LHS, uint32_t shiftAmt) {
574   return LHS.ashr(shiftAmt);
575 }
576
577 /// Logical right-shift the APInt by shiftAmt.
578 /// @brief Logical right-shift function.
579 inline APInt lshr(const APInt& LHS, uint32_t shiftAmt) {
580   return LHS.lshr(shiftAmt);
581 }
582
583 /// Left-shift the APInt by shiftAmt.
584 /// @brief Left-shift function.
585 inline APInt shl(const APInt& LHS, uint32_t shiftAmt) {
586   return LHS.shl(shiftAmt);
587 }
588
589 /// Signed divide APInt LHS by APInt RHS.
590 /// @brief Signed division function for APInt.
591 inline APInt sdiv(const APInt& LHS, const APInt& RHS) {
592   return LHS.sdiv(RHS);
593 }
594
595 /// Unsigned divide APInt LHS by APInt RHS.
596 /// @brief Unsigned division function for APInt.
597 inline APInt udiv(const APInt& LHS, const APInt& RHS) {
598   return LHS.udiv(RHS);
599 }
600
601 /// Signed remainder operation on APInt.
602 /// @brief Function for signed remainder operation.
603 inline APInt srem(const APInt& LHS, const APInt& RHS) {
604   return LHS.srem(RHS);
605 }
606
607 /// Unsigned remainder operation on APInt.
608 /// @brief Function for unsigned remainder operation.
609 inline APInt urem(const APInt& LHS, const APInt& RHS) {
610   return LHS.urem(RHS);
611 }
612
613 /// Performs multiplication on APInt values.
614 /// @brief Function for multiplication operation.
615 inline APInt mul(const APInt& LHS, const APInt& RHS) {
616   return LHS * RHS;
617 }
618
619 /// Performs addition on APInt values.
620 /// @brief Function for addition operation.
621 inline APInt add(const APInt& LHS, const APInt& RHS) {
622   return LHS + RHS;
623 }
624
625 /// Performs subtraction on APInt values.
626 /// @brief Function for subtraction operation.
627 inline APInt sub(const APInt& LHS, const APInt& RHS) {
628   return LHS - RHS;
629 }
630
631 /// Performs bitwise AND operation on APInt LHS and 
632 /// APInt RHS.
633 /// @brief Bitwise AND function for APInt.
634 inline APInt And(const APInt& LHS, const APInt& RHS) {
635   return LHS & RHS;
636 }
637
638 /// Performs bitwise OR operation on APInt LHS and APInt RHS.
639 /// @brief Bitwise OR function for APInt. 
640 inline APInt Or(const APInt& LHS, const APInt& RHS) {
641   return LHS | RHS;
642 }
643
644 /// Performs bitwise XOR operation on APInt.
645 /// @brief Bitwise XOR function for APInt.
646 inline APInt Xor(const APInt& LHS, const APInt& RHS) {
647   return LHS ^ RHS;
648
649
650 /// Performs a bitwise complement operation on APInt.
651 /// @brief Bitwise complement function. 
652 inline APInt Not(const APInt& APIVal) {
653   return ~APIVal;
654 }
655
656 } // End of APIntOps namespace
657
658 } // End of llvm namespace
659
660 #endif