diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/include/llvm/Support/KnownBits.h | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/include/llvm/Support/KnownBits.h')
-rw-r--r-- | contrib/libs/llvm12/include/llvm/Support/KnownBits.h | 286 |
1 files changed, 143 insertions, 143 deletions
diff --git a/contrib/libs/llvm12/include/llvm/Support/KnownBits.h b/contrib/libs/llvm12/include/llvm/Support/KnownBits.h index 9026e8891e..e7eaf0bbbf 100644 --- a/contrib/libs/llvm12/include/llvm/Support/KnownBits.h +++ b/contrib/libs/llvm12/include/llvm/Support/KnownBits.h @@ -22,7 +22,7 @@ #define LLVM_SUPPORT_KNOWNBITS_H #include "llvm/ADT/APInt.h" -#include "llvm/ADT/Optional.h" +#include "llvm/ADT/Optional.h" namespace llvm { @@ -105,9 +105,9 @@ public: /// Returns true if this value is known to be non-negative. bool isNonNegative() const { return Zero.isSignBitSet(); } - /// Returns true if this value is known to be non-zero. - bool isNonZero() const { return !One.isNullValue(); } - + /// Returns true if this value is known to be non-zero. + bool isNonZero() const { return !One.isNullValue(); } + /// Returns true if this value is known to be positive. bool isStrictlyPositive() const { return Zero.isSignBitSet() && !One.isNullValue(); } @@ -121,38 +121,38 @@ public: Zero.setSignBit(); } - /// Return the minimal unsigned value possible given these KnownBits. + /// Return the minimal unsigned value possible given these KnownBits. APInt getMinValue() const { // Assume that all bits that aren't known-ones are zeros. return One; } - /// Return the minimal signed value possible given these KnownBits. - APInt getSignedMinValue() const { - // Assume that all bits that aren't known-ones are zeros. - APInt Min = One; - // Sign bit is unknown. - if (Zero.isSignBitClear()) - Min.setSignBit(); - return Min; - } - - /// Return the maximal unsigned value possible given these KnownBits. + /// Return the minimal signed value possible given these KnownBits. + APInt getSignedMinValue() const { + // Assume that all bits that aren't known-ones are zeros. + APInt Min = One; + // Sign bit is unknown. + if (Zero.isSignBitClear()) + Min.setSignBit(); + return Min; + } + + /// Return the maximal unsigned value possible given these KnownBits. APInt getMaxValue() const { // Assume that all bits that aren't known-zeros are ones. return ~Zero; } - /// Return the maximal signed value possible given these KnownBits. - APInt getSignedMaxValue() const { - // Assume that all bits that aren't known-zeros are ones. - APInt Max = ~Zero; - // Sign bit is unknown. - if (One.isSignBitClear()) - Max.clearSignBit(); - return Max; - } - + /// Return the maximal signed value possible given these KnownBits. + APInt getSignedMaxValue() const { + // Assume that all bits that aren't known-zeros are ones. + APInt Max = ~Zero; + // Sign bit is unknown. + if (One.isSignBitClear()) + Max.clearSignBit(); + return Max; + } + /// Return known bits for a truncation of the value we're tracking. KnownBits trunc(unsigned BitWidth) const { return KnownBits(Zero.trunc(BitWidth), One.trunc(BitWidth)); @@ -197,20 +197,20 @@ public: return *this; } - /// Return known bits for a sign extension or truncation of the value we're - /// tracking. - KnownBits sextOrTrunc(unsigned BitWidth) const { - if (BitWidth > getBitWidth()) - return sext(BitWidth); - if (BitWidth < getBitWidth()) - return trunc(BitWidth); - return *this; - } - - /// Return known bits for a in-register sign extension of the value we're - /// tracking. - KnownBits sextInReg(unsigned SrcBitWidth) const; - + /// Return known bits for a sign extension or truncation of the value we're + /// tracking. + KnownBits sextOrTrunc(unsigned BitWidth) const { + if (BitWidth > getBitWidth()) + return sext(BitWidth); + if (BitWidth < getBitWidth()) + return trunc(BitWidth); + return *this; + } + + /// Return known bits for a in-register sign extension of the value we're + /// tracking. + KnownBits sextInReg(unsigned SrcBitWidth) const; + /// Return a KnownBits with the extracted bits /// [bitPosition,bitPosition+numBits). KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const { @@ -218,10 +218,10 @@ public: One.extractBits(NumBits, BitPosition)); } - /// Return KnownBits based on this, but updated given that the underlying - /// value is known to be greater than or equal to Val. - KnownBits makeGE(const APInt &Val) const; - + /// Return KnownBits based on this, but updated given that the underlying + /// value is known to be greater than or equal to Val. + KnownBits makeGE(const APInt &Val) const; + /// Returns the minimum number of trailing zero bits. unsigned countMinTrailingZeros() const { return Zero.countTrailingOnes(); @@ -282,16 +282,16 @@ public: return getBitWidth() - Zero.countPopulation(); } - /// Create known bits from a known constant. - static KnownBits makeConstant(const APInt &C) { - return KnownBits(~C, C); - } - - /// Compute known bits common to LHS and RHS. - static KnownBits commonBits(const KnownBits &LHS, const KnownBits &RHS) { - return KnownBits(LHS.Zero & RHS.Zero, LHS.One & RHS.One); - } - + /// Create known bits from a known constant. + static KnownBits makeConstant(const APInt &C) { + return KnownBits(~C, C); + } + + /// Compute known bits common to LHS and RHS. + static KnownBits commonBits(const KnownBits &LHS, const KnownBits &RHS) { + return KnownBits(LHS.Zero & RHS.Zero, LHS.One & RHS.One); + } + /// Compute known bits resulting from adding LHS, RHS and a 1-bit Carry. static KnownBits computeForAddCarry( const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry); @@ -300,84 +300,84 @@ public: static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS, KnownBits RHS); - /// Compute known bits resulting from multiplying LHS and RHS. - static KnownBits computeForMul(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for udiv(LHS, RHS). - static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for urem(LHS, RHS). - static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for srem(LHS, RHS). - static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for umax(LHS, RHS). - static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for umin(LHS, RHS). - static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for smax(LHS, RHS). - static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for smin(LHS, RHS). - static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for shl(LHS, RHS). - /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS. - static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for lshr(LHS, RHS). - /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS. - static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS); - - /// Compute known bits for ashr(LHS, RHS). - /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS. - static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_EQ result. - static Optional<bool> eq(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_NE result. - static Optional<bool> ne(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_UGT result. - static Optional<bool> ugt(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_UGE result. - static Optional<bool> uge(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_ULT result. - static Optional<bool> ult(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_ULE result. - static Optional<bool> ule(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_SGT result. - static Optional<bool> sgt(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_SGE result. - static Optional<bool> sge(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_SLT result. - static Optional<bool> slt(const KnownBits &LHS, const KnownBits &RHS); - - /// Determine if these known bits always give the same ICMP_SLE result. - static Optional<bool> sle(const KnownBits &LHS, const KnownBits &RHS); - - /// Insert the bits from a smaller known bits starting at bitPosition. - void insertBits(const KnownBits &SubBits, unsigned BitPosition) { - Zero.insertBits(SubBits.Zero, BitPosition); - One.insertBits(SubBits.One, BitPosition); - } - - /// Return a subset of the known bits from [bitPosition,bitPosition+numBits). - KnownBits extractBits(unsigned NumBits, unsigned BitPosition) { - return KnownBits(Zero.extractBits(NumBits, BitPosition), - One.extractBits(NumBits, BitPosition)); - } - + /// Compute known bits resulting from multiplying LHS and RHS. + static KnownBits computeForMul(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for udiv(LHS, RHS). + static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for urem(LHS, RHS). + static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for srem(LHS, RHS). + static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for umax(LHS, RHS). + static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for umin(LHS, RHS). + static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for smax(LHS, RHS). + static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for smin(LHS, RHS). + static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for shl(LHS, RHS). + /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS. + static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for lshr(LHS, RHS). + /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS. + static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS); + + /// Compute known bits for ashr(LHS, RHS). + /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS. + static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_EQ result. + static Optional<bool> eq(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_NE result. + static Optional<bool> ne(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_UGT result. + static Optional<bool> ugt(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_UGE result. + static Optional<bool> uge(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_ULT result. + static Optional<bool> ult(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_ULE result. + static Optional<bool> ule(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_SGT result. + static Optional<bool> sgt(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_SGE result. + static Optional<bool> sge(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_SLT result. + static Optional<bool> slt(const KnownBits &LHS, const KnownBits &RHS); + + /// Determine if these known bits always give the same ICMP_SLE result. + static Optional<bool> sle(const KnownBits &LHS, const KnownBits &RHS); + + /// Insert the bits from a smaller known bits starting at bitPosition. + void insertBits(const KnownBits &SubBits, unsigned BitPosition) { + Zero.insertBits(SubBits.Zero, BitPosition); + One.insertBits(SubBits.One, BitPosition); + } + + /// Return a subset of the known bits from [bitPosition,bitPosition+numBits). + KnownBits extractBits(unsigned NumBits, unsigned BitPosition) { + return KnownBits(Zero.extractBits(NumBits, BitPosition), + One.extractBits(NumBits, BitPosition)); + } + /// Update known bits based on ANDing with RHS. KnownBits &operator&=(const KnownBits &RHS); @@ -386,17 +386,17 @@ public: /// Update known bits based on XORing with RHS. KnownBits &operator^=(const KnownBits &RHS); - - /// Compute known bits for the absolute value. - KnownBits abs(bool IntMinIsPoison = false) const; - - KnownBits byteSwap() { - return KnownBits(Zero.byteSwap(), One.byteSwap()); - } - - KnownBits reverseBits() { - return KnownBits(Zero.reverseBits(), One.reverseBits()); - } + + /// Compute known bits for the absolute value. + KnownBits abs(bool IntMinIsPoison = false) const; + + KnownBits byteSwap() { + return KnownBits(Zero.byteSwap(), One.byteSwap()); + } + + KnownBits reverseBits() { + return KnownBits(Zero.reverseBits(), One.reverseBits()); + } }; inline KnownBits operator&(KnownBits LHS, const KnownBits &RHS) { |