llvm.org GIT mirror llvm / b69143c
Annotate APInt methods where it's not clear whether they are in place with warn_unused_result. Fix ScalarEvolution bugs uncovered by this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194928 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 7 years ago
3 changed file(s) with 47 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
764764 return APInt(getBitWidth(), VAL & RHS.VAL);
765765 return AndSlowCase(RHS);
766766 }
767 APInt And(const APInt &RHS) const { return this->operator&(RHS); }
767 APInt LLVM_ATTRIBUTE_UNUSED_RESULT And(const APInt &RHS) const {
768 return this->operator&(RHS);
769 }
768770
769771 /// \brief Bitwise OR operator.
770772 ///
784786 /// calling operator|.
785787 ///
786788 /// \returns An APInt value representing the bitwise OR of *this and RHS.
787 APInt Or(const APInt &RHS) const { return this->operator|(RHS); }
789 APInt LLVM_ATTRIBUTE_UNUSED_RESULT Or(const APInt &RHS) const {
790 return this->operator|(RHS);
791 }
788792
789793 /// \brief Bitwise XOR operator.
790794 ///
804808 /// through the usage of operator^.
805809 ///
806810 /// \returns An APInt value representing the bitwise XOR of *this and RHS.
807 APInt Xor(const APInt &RHS) const { return this->operator^(RHS); }
811 APInt LLVM_ATTRIBUTE_UNUSED_RESULT Xor(const APInt &RHS) const {
812 return this->operator^(RHS);
813 }
808814
809815 /// \brief Multiplication operator.
810816 ///
836842 /// \brief Arithmetic right-shift function.
837843 ///
838844 /// Arithmetic right-shift this APInt by shiftAmt.
839 APInt ashr(unsigned shiftAmt) const;
845 APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const;
840846
841847 /// \brief Logical right-shift function.
842848 ///
843849 /// Logical right-shift this APInt by shiftAmt.
844 APInt lshr(unsigned shiftAmt) const;
850 APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const;
845851
846852 /// \brief Left-shift function.
847853 ///
848854 /// Left-shift this APInt by shiftAmt.
849 APInt shl(unsigned shiftAmt) const {
855 APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(unsigned shiftAmt) const {
850856 assert(shiftAmt <= BitWidth && "Invalid shift amount");
851857 if (isSingleWord()) {
852858 if (shiftAmt >= BitWidth)
857863 }
858864
859865 /// \brief Rotate left by rotateAmt.
860 APInt rotl(unsigned rotateAmt) const;
866 APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotl(unsigned rotateAmt) const;
861867
862868 /// \brief Rotate right by rotateAmt.
863 APInt rotr(unsigned rotateAmt) const;
869 APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotr(unsigned rotateAmt) const;
864870
865871 /// \brief Arithmetic right-shift function.
866872 ///
867873 /// Arithmetic right-shift this APInt by shiftAmt.
868 APInt ashr(const APInt &shiftAmt) const;
874 APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(const APInt &shiftAmt) const;
869875
870876 /// \brief Logical right-shift function.
871877 ///
872878 /// Logical right-shift this APInt by shiftAmt.
873 APInt lshr(const APInt &shiftAmt) const;
879 APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(const APInt &shiftAmt) const;
874880
875881 /// \brief Left-shift function.
876882 ///
877883 /// Left-shift this APInt by shiftAmt.
878 APInt shl(const APInt &shiftAmt) const;
884 APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(const APInt &shiftAmt) const;
879885
880886 /// \brief Rotate left by rotateAmt.
881 APInt rotl(const APInt &rotateAmt) const;
887 APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotl(const APInt &rotateAmt) const;
882888
883889 /// \brief Rotate right by rotateAmt.
884 APInt rotr(const APInt &rotateAmt) const;
890 APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotr(const APInt &rotateAmt) const;
885891
886892 /// \brief Unsigned division operation.
887893 ///
889895 /// RHS are treated as unsigned quantities for purposes of this division.
890896 ///
891897 /// \returns a new APInt value containing the division result
892 APInt udiv(const APInt &RHS) const;
898 APInt LLVM_ATTRIBUTE_UNUSED_RESULT udiv(const APInt &RHS) const;
893899
894900 /// \brief Signed division function for APInt.
895901 ///
896902 /// Signed divide this APInt by APInt RHS.
897 APInt sdiv(const APInt &RHS) const;
903 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sdiv(const APInt &RHS) const;
898904
899905 /// \brief Unsigned remainder operation.
900906 ///
905911 /// is *this.
906912 ///
907913 /// \returns a new APInt value containing the remainder result
908 APInt urem(const APInt &RHS) const;
914 APInt LLVM_ATTRIBUTE_UNUSED_RESULT urem(const APInt &RHS) const;
909915
910916 /// \brief Function for signed remainder operation.
911917 ///
912918 /// Signed remainder operation on APInt.
913 APInt srem(const APInt &RHS) const;
919 APInt LLVM_ATTRIBUTE_UNUSED_RESULT srem(const APInt &RHS) const;
914920
915921 /// \brief Dual division/remainder interface.
916922 ///
11441150 ///
11451151 /// Truncate the APInt to a specified width. It is an error to specify a width
11461152 /// that is greater than or equal to the current width.
1147 APInt trunc(unsigned width) const;
1153 APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const;
11481154
11491155 /// \brief Sign extend to a new width.
11501156 ///
11521158 /// bit is set, the fill on the left will be done with 1 bits, otherwise zero.
11531159 /// It is an error to specify a width that is less than or equal to the
11541160 /// current width.
1155 APInt sext(unsigned width) const;
1161 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sext(unsigned width) const;
11561162
11571163 /// \brief Zero extend to a new width.
11581164 ///
11591165 /// This operation zero extends the APInt to a new width. The high order bits
11601166 /// are filled with 0 bits. It is an error to specify a width that is less
11611167 /// than or equal to the current width.
1162 APInt zext(unsigned width) const;
1168 APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const;
11631169
11641170 /// \brief Sign extend or truncate to width
11651171 ///
11661172 /// Make this APInt have the bit width given by \p width. The value is sign
11671173 /// extended, truncated, or left alone to make it that width.
1168 APInt sextOrTrunc(unsigned width) const;
1174 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sextOrTrunc(unsigned width) const;
11691175
11701176 /// \brief Zero extend or truncate to width
11711177 ///
11721178 /// Make this APInt have the bit width given by \p width. The value is zero
11731179 /// extended, truncated, or left alone to make it that width.
1174 APInt zextOrTrunc(unsigned width) const;
1180 APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const;
11751181
11761182 /// \brief Sign extend or truncate to width
11771183 ///
11781184 /// Make this APInt have the bit width given by \p width. The value is sign
11791185 /// extended, or left alone to make it that width.
1180 APInt sextOrSelf(unsigned width) const;
1186 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sextOrSelf(unsigned width) const;
11811187
11821188 /// \brief Zero extend or truncate to width
11831189 ///
11841190 /// Make this APInt have the bit width given by \p width. The value is zero
11851191 /// extended, or left alone to make it that width.
1186 APInt zextOrSelf(unsigned width) const;
1192 APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrSelf(unsigned width) const;
11871193
11881194 /// @}
11891195 /// \name Bit Manipulation Operators
14201426 std::string toString(unsigned Radix, bool Signed) const;
14211427
14221428 /// \returns a byte-swapped representation of this APInt Value.
1423 APInt byteSwap() const;
1429 APInt LLVM_ATTRIBUTE_UNUSED_RESULT byteSwap() const;
14241430
14251431 /// \brief Converts this APInt to a double value.
14261432 double roundToDouble(bool isSigned) const;
14631469 ///
14641470 /// The conversion does not do a translation from double to integer, it just
14651471 /// re-interprets the bits of the double.
1466 static APInt doubleToBits(double V) {
1472 static APInt LLVM_ATTRIBUTE_UNUSED_RESULT doubleToBits(double V) {
14671473 union {
14681474 uint64_t I;
14691475 double D;
14761482 ///
14771483 /// The conversion does not do a translation from float to integer, it just
14781484 /// re-interprets the bits of the float.
1479 static APInt floatToBits(float V) {
1485 static APInt LLVM_ATTRIBUTE_UNUSED_RESULT floatToBits(float V) {
14801486 union {
14811487 unsigned I;
14821488 float F;
15061512 }
15071513
15081514 /// \brief Compute the square root
1509 APInt sqrt() const;
1515 APInt LLVM_ATTRIBUTE_UNUSED_RESULT sqrt() const;
15101516
15111517 /// \brief Get the absolute value;
15121518 ///
15131519 /// If *this is < 0 then return -(*this), otherwise *this;
1514 APInt abs() const {
1520 APInt LLVM_ATTRIBUTE_UNUSED_RESULT abs() const {
15151521 if (isNegative())
15161522 return -(*this);
15171523 return *this;
6767 }
6868 using APInt::toString;
6969
70 APSInt trunc(uint32_t width) const {
70 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(uint32_t width) const {
7171 return APSInt(APInt::trunc(width), IsUnsigned);
7272 }
7373
74 APSInt extend(uint32_t width) const {
74 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extend(uint32_t width) const {
7575 if (IsUnsigned)
7676 return APSInt(zext(width), IsUnsigned);
7777 else
7878 return APSInt(sext(width), IsUnsigned);
7979 }
8080
81 APSInt extOrTrunc(uint32_t width) const {
81 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extOrTrunc(uint32_t width) const {
8282 if (IsUnsigned)
8383 return APSInt(zextOrTrunc(width), IsUnsigned);
8484 else
211211 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
212212 return APSInt(static_cast(*this) & RHS, IsUnsigned);
213213 }
214 APSInt And(const APSInt& RHS) const {
214 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT And(const APSInt& RHS) const {
215215 return this->operator&(RHS);
216216 }
217217
219219 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
220220 return APSInt(static_cast(*this) | RHS, IsUnsigned);
221221 }
222 APSInt Or(const APSInt& RHS) const {
222 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Or(const APSInt& RHS) const {
223223 return this->operator|(RHS);
224224 }
225225
228228 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
229229 return APSInt(static_cast(*this) ^ RHS, IsUnsigned);
230230 }
231 APSInt Xor(const APSInt& RHS) const {
231 APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Xor(const APSInt& RHS) const {
232232 return this->operator^(RHS);
233233 }
234234
66836683 uint32_t BBW = B.getBitWidth();
66846684
66856685 if (ABW > BBW)
6686 B.zext(ABW);
6686 B = B.zext(ABW);
66876687 else if (ABW < BBW)
6688 A.zext(BBW);
6688 A = A.zext(BBW);
66896689
66906690 return APIntOps::GreatestCommonDivisor(A, B);
66916691 }
66976697 uint32_t BBW = B.getBitWidth();
66986698
66996699 if (ABW > BBW)
6700 B.sext(ABW);
6700 B = B.sext(ABW);
67016701 else if (ABW < BBW)
6702 A.sext(BBW);
6702 A = A.sext(BBW);
67036703
67046704 return APIntOps::srem(A, B);
67056705 }
67116711 uint32_t BBW = B.getBitWidth();
67126712
67136713 if (ABW > BBW)
6714 B.sext(ABW);
6714 B = B.sext(ABW);
67156715 else if (ABW < BBW)
6716 A.sext(BBW);
6716 A = A.sext(BBW);
67176717
67186718 return APIntOps::sdiv(A, B);
67196719 }