llvm.org GIT mirror llvm / 0746b2b
ADT: Use LLVM_NODISCARD instead of LLVM_ATTRIBUTE_UNUSED_RESULT for APInt Instead of annotating (most of) the APInt API, we can just annotate the type directly. This is less code and it will warn in more cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284297 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 4 years ago
2 changed file(s) with 42 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
7373 /// * In general, the class tries to follow the style of computation that LLVM
7474 /// uses in its IR. This simplifies its use for LLVM.
7575 ///
76 class APInt {
76 class LLVM_NODISCARD APInt {
7777 unsigned BitWidth; ///< The number of bits in this APInt.
7878
7979 /// This union is used to store the integer value. When the
776776 return APInt(getBitWidth(), VAL & RHS.VAL);
777777 return AndSlowCase(RHS);
778778 }
779 APInt LLVM_ATTRIBUTE_UNUSED_RESULT And(const APInt &RHS) const {
780 return this->operator&(RHS);
781 }
779 APInt And(const APInt &RHS) const { return this->operator&(RHS); }
782780
783781 /// \brief Bitwise OR operator.
784782 ///
798796 /// calling operator|.
799797 ///
800798 /// \returns An APInt value representing the bitwise OR of *this and RHS.
801 APInt LLVM_ATTRIBUTE_UNUSED_RESULT Or(const APInt &RHS) const {
802 return this->operator|(RHS);
803 }
799 APInt Or(const APInt &RHS) const { return this->operator|(RHS); }
804800
805801 /// \brief Bitwise XOR operator.
806802 ///
820816 /// through the usage of operator^.
821817 ///
822818 /// \returns An APInt value representing the bitwise XOR of *this and RHS.
823 APInt LLVM_ATTRIBUTE_UNUSED_RESULT Xor(const APInt &RHS) const {
824 return this->operator^(RHS);
825 }
819 APInt Xor(const APInt &RHS) const { return this->operator^(RHS); }
826820
827821 /// \brief Multiplication operator.
828822 ///
842836 /// \brief Arithmetic right-shift function.
843837 ///
844838 /// Arithmetic right-shift this APInt by shiftAmt.
845 APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const;
839 APInt ashr(unsigned shiftAmt) const;
846840
847841 /// \brief Logical right-shift function.
848842 ///
849843 /// Logical right-shift this APInt by shiftAmt.
850 APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const;
844 APInt lshr(unsigned shiftAmt) const;
851845
852846 /// \brief Left-shift function.
853847 ///
854848 /// Left-shift this APInt by shiftAmt.
855 APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(unsigned shiftAmt) const {
849 APInt shl(unsigned shiftAmt) const {
856850 assert(shiftAmt <= BitWidth && "Invalid shift amount");
857851 if (isSingleWord()) {
858852 if (shiftAmt >= BitWidth)
863857 }
864858
865859 /// \brief Rotate left by rotateAmt.
866 APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotl(unsigned rotateAmt) const;
860 APInt rotl(unsigned rotateAmt) const;
867861
868862 /// \brief Rotate right by rotateAmt.
869 APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotr(unsigned rotateAmt) const;
863 APInt rotr(unsigned rotateAmt) const;
870864
871865 /// \brief Arithmetic right-shift function.
872866 ///
873867 /// Arithmetic right-shift this APInt by shiftAmt.
874 APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(const APInt &shiftAmt) const;
868 APInt ashr(const APInt &shiftAmt) const;
875869
876870 /// \brief Logical right-shift function.
877871 ///
878872 /// Logical right-shift this APInt by shiftAmt.
879 APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(const APInt &shiftAmt) const;
873 APInt lshr(const APInt &shiftAmt) const;
880874
881875 /// \brief Left-shift function.
882876 ///
883877 /// Left-shift this APInt by shiftAmt.
884 APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(const APInt &shiftAmt) const;
878 APInt shl(const APInt &shiftAmt) const;
885879
886880 /// \brief Rotate left by rotateAmt.
887 APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotl(const APInt &rotateAmt) const;
881 APInt rotl(const APInt &rotateAmt) const;
888882
889883 /// \brief Rotate right by rotateAmt.
890 APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotr(const APInt &rotateAmt) const;
884 APInt rotr(const APInt &rotateAmt) const;
891885
892886 /// \brief Unsigned division operation.
893887 ///
895889 /// RHS are treated as unsigned quantities for purposes of this division.
896890 ///
897891 /// \returns a new APInt value containing the division result
898 APInt LLVM_ATTRIBUTE_UNUSED_RESULT udiv(const APInt &RHS) const;
892 APInt udiv(const APInt &RHS) const;
899893
900894 /// \brief Signed division function for APInt.
901895 ///
902896 /// Signed divide this APInt by APInt RHS.
903 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sdiv(const APInt &RHS) const;
897 APInt sdiv(const APInt &RHS) const;
904898
905899 /// \brief Unsigned remainder operation.
906900 ///
911905 /// is *this.
912906 ///
913907 /// \returns a new APInt value containing the remainder result
914 APInt LLVM_ATTRIBUTE_UNUSED_RESULT urem(const APInt &RHS) const;
908 APInt urem(const APInt &RHS) const;
915909
916910 /// \brief Function for signed remainder operation.
917911 ///
918912 /// Signed remainder operation on APInt.
919 APInt LLVM_ATTRIBUTE_UNUSED_RESULT srem(const APInt &RHS) const;
913 APInt srem(const APInt &RHS) const;
920914
921915 /// \brief Dual division/remainder interface.
922916 ///
11591153 ///
11601154 /// Truncate the APInt to a specified width. It is an error to specify a width
11611155 /// that is greater than or equal to the current width.
1162 APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const;
1156 APInt trunc(unsigned width) const;
11631157
11641158 /// \brief Sign extend to a new width.
11651159 ///
11671161 /// bit is set, the fill on the left will be done with 1 bits, otherwise zero.
11681162 /// It is an error to specify a width that is less than or equal to the
11691163 /// current width.
1170 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sext(unsigned width) const;
1164 APInt sext(unsigned width) const;
11711165
11721166 /// \brief Zero extend to a new width.
11731167 ///
11741168 /// This operation zero extends the APInt to a new width. The high order bits
11751169 /// are filled with 0 bits. It is an error to specify a width that is less
11761170 /// than or equal to the current width.
1177 APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const;
1171 APInt zext(unsigned width) const;
11781172
11791173 /// \brief Sign extend or truncate to width
11801174 ///
11811175 /// Make this APInt have the bit width given by \p width. The value is sign
11821176 /// extended, truncated, or left alone to make it that width.
1183 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sextOrTrunc(unsigned width) const;
1177 APInt sextOrTrunc(unsigned width) const;
11841178
11851179 /// \brief Zero extend or truncate to width
11861180 ///
11871181 /// Make this APInt have the bit width given by \p width. The value is zero
11881182 /// extended, truncated, or left alone to make it that width.
1189 APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const;
1183 APInt zextOrTrunc(unsigned width) const;
11901184
11911185 /// \brief Sign extend or truncate to width
11921186 ///
11931187 /// Make this APInt have the bit width given by \p width. The value is sign
11941188 /// extended, or left alone to make it that width.
1195 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sextOrSelf(unsigned width) const;
1189 APInt sextOrSelf(unsigned width) const;
11961190
11971191 /// \brief Zero extend or truncate to width
11981192 ///
11991193 /// Make this APInt have the bit width given by \p width. The value is zero
12001194 /// extended, or left alone to make it that width.
1201 APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrSelf(unsigned width) const;
1195 APInt zextOrSelf(unsigned width) const;
12021196
12031197 /// @}
12041198 /// \name Bit Manipulation Operators
14351429 std::string toString(unsigned Radix, bool Signed) const;
14361430
14371431 /// \returns a byte-swapped representation of this APInt Value.
1438 APInt LLVM_ATTRIBUTE_UNUSED_RESULT byteSwap() const;
1432 APInt byteSwap() const;
14391433
14401434 /// \returns the value with the bit representation reversed of this APInt
14411435 /// Value.
1442 APInt LLVM_ATTRIBUTE_UNUSED_RESULT reverseBits() const;
1436 APInt reverseBits() const;
14431437
14441438 /// \brief Converts this APInt to a double value.
14451439 double roundToDouble(bool isSigned) const;
14821476 ///
14831477 /// The conversion does not do a translation from double to integer, it just
14841478 /// re-interprets the bits of the double.
1485 static APInt LLVM_ATTRIBUTE_UNUSED_RESULT doubleToBits(double V) {
1479 static APInt doubleToBits(double V) {
14861480 union {
14871481 uint64_t I;
14881482 double D;
14951489 ///
14961490 /// The conversion does not do a translation from float to integer, it just
14971491 /// re-interprets the bits of the float.
1498 static APInt LLVM_ATTRIBUTE_UNUSED_RESULT floatToBits(float V) {
1492 static APInt floatToBits(float V) {
14991493 union {
15001494 unsigned I;
15011495 float F;
15561550 }
15571551
15581552 /// \brief Compute the square root
1559 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sqrt() const;
1553 APInt sqrt() const;
15601554
15611555 /// \brief Get the absolute value;
15621556 ///
15631557 /// If *this is < 0 then return -(*this), otherwise *this;
1564 APInt LLVM_ATTRIBUTE_UNUSED_RESULT abs() const {
1558 APInt abs() const {
15651559 if (isNegative())
15661560 return -(*this);
15671561 return *this;
1818
1919 namespace llvm {
2020
21 class APSInt : public APInt {
21 class LLVM_NODISCARD APSInt : public APInt {
2222 bool IsUnsigned;
2323
2424 public:
7777 return isSigned() ? getSExtValue() : getZExtValue();
7878 }
7979
80 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(uint32_t width) const {
80 APSInt trunc(uint32_t width) const {
8181 return APSInt(APInt::trunc(width), IsUnsigned);
8282 }
8383
84 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extend(uint32_t width) const {
84 APSInt extend(uint32_t width) const {
8585 if (IsUnsigned)
8686 return APSInt(zext(width), IsUnsigned);
8787 else
8888 return APSInt(sext(width), IsUnsigned);
8989 }
9090
91 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extOrTrunc(uint32_t width) const {
92 if (IsUnsigned)
93 return APSInt(zextOrTrunc(width), IsUnsigned);
94 else
95 return APSInt(sextOrTrunc(width), IsUnsigned);
91 APSInt extOrTrunc(uint32_t width) const {
92 if (IsUnsigned)
93 return APSInt(zextOrTrunc(width), IsUnsigned);
94 else
95 return APSInt(sextOrTrunc(width), IsUnsigned);
9696 }
9797
9898 const APSInt &operator%=(const APSInt &RHS) {
234234 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
235235 return APSInt(static_cast(*this) & RHS, IsUnsigned);
236236 }
237 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT And(const APSInt& RHS) const {
238 return this->operator&(RHS);
239 }
237 APSInt And(const APSInt &RHS) const { return this->operator&(RHS); }
240238
241239 APSInt operator|(const APSInt& RHS) const {
242240 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
243241 return APSInt(static_cast(*this) | RHS, IsUnsigned);
244242 }
245 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Or(const APSInt& RHS) const {
246 return this->operator|(RHS);
247 }
243 APSInt Or(const APSInt &RHS) const { return this->operator|(RHS); }
248244
249245 APSInt operator^(const APSInt &RHS) const {
250246 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
251247 return APSInt(static_cast(*this) ^ RHS, IsUnsigned);
252248 }
253 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Xor(const APSInt& RHS) const {
254 return this->operator^(RHS);
255 }
249 APSInt Xor(const APSInt &RHS) const { return this->operator^(RHS); }
256250
257251 APSInt operator*(const APSInt& RHS) const {
258252 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");