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