diff options
author | Chris Lattner <clattner@nondot.org> | 2021-09-08 22:13:13 -0700 |
---|---|---|
committer | Chris Lattner <clattner@nondot.org> | 2021-09-09 09:50:24 -0700 |
commit | 735f46715d90fd0ff48dd44d1007302640ab4d11 (patch) | |
tree | b6e83d6168f4c6e7b3427791fe17581f210015ec /llvm/lib/IR/ConstantRange.cpp | |
parent | 6355234660551e7562e2ace512ccaefacbbb9065 (diff) | |
download | llvm-735f46715d90fd0ff48dd44d1007302640ab4d11.zip llvm-735f46715d90fd0ff48dd44d1007302640ab4d11.tar.gz llvm-735f46715d90fd0ff48dd44d1007302640ab4d11.tar.bz2 |
[APInt] Normalize naming on keep constructors / predicate methods.
This renames the primary methods for creating a zero value to `getZero`
instead of `getNullValue` and renames predicates like `isAllOnesValue`
to simply `isAllOnes`. This achieves two things:
1) This starts standardizing predicates across the LLVM codebase,
following (in this case) ConstantInt. The word "Value" doesn't
convey anything of merit, and is missing in some of the other things.
2) Calling an integer "null" doesn't make any sense. The original sin
here is mine and I've regretted it for years. This moves us to calling
it "zero" instead, which is correct!
APInt is widely used and I don't think anyone is keen to take massive source
breakage on anything so core, at least not all in one go. As such, this
doesn't actually delete any entrypoints, it "soft deprecates" them with a
comment.
Included in this patch are changes to a bunch of the codebase, but there are
more. We should normalize SelectionDAG and other APIs as well, which would
make the API change more mechanical.
Differential Revision: https://reviews.llvm.org/D109483
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index 0649776..6f47cd0c 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -110,7 +110,7 @@ ConstantRange ConstantRange::makeAllowedICmpRegion(CmpInst::Predicate Pred, APInt UMin(CR.getUnsignedMin()); if (UMin.isMaxValue()) return getEmpty(W); - return ConstantRange(std::move(UMin) + 1, APInt::getNullValue(W)); + return ConstantRange(std::move(UMin) + 1, APInt::getZero(W)); } case CmpInst::ICMP_SGT: { APInt SMin(CR.getSignedMin()); @@ -119,7 +119,7 @@ ConstantRange ConstantRange::makeAllowedICmpRegion(CmpInst::Predicate Pred, return ConstantRange(std::move(SMin) + 1, APInt::getSignedMinValue(W)); } case CmpInst::ICMP_UGE: - return getNonEmpty(CR.getUnsignedMin(), APInt::getNullValue(W)); + return getNonEmpty(CR.getUnsignedMin(), APInt::getZero(W)); case CmpInst::ICMP_SGE: return getNonEmpty(CR.getSignedMin(), APInt::getSignedMinValue(W)); } @@ -248,8 +248,7 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, case Instruction::Add: { if (Unsigned) - return getNonEmpty(APInt::getNullValue(BitWidth), - -Other.getUnsignedMax()); + return getNonEmpty(APInt::getZero(BitWidth), -Other.getUnsignedMax()); APInt SignedMinVal = APInt::getSignedMinValue(BitWidth); APInt SMin = Other.getSignedMin(), SMax = Other.getSignedMax(); @@ -291,7 +290,7 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, // to be at most bitwidth-1, which results in most conservative range. APInt ShAmtUMax = ShAmt.getUnsignedMax(); if (Unsigned) - return getNonEmpty(APInt::getNullValue(BitWidth), + return getNonEmpty(APInt::getZero(BitWidth), APInt::getMaxValue(BitWidth).lshr(ShAmtUMax) + 1); return getNonEmpty(APInt::getSignedMinValue(BitWidth).ashr(ShAmtUMax), APInt::getSignedMaxValue(BitWidth).ashr(ShAmtUMax) + 1); @@ -316,7 +315,7 @@ bool ConstantRange::isEmptySet() const { } bool ConstantRange::isWrappedSet() const { - return Lower.ugt(Upper) && !Upper.isNullValue(); + return Lower.ugt(Upper) && !Upper.isZero(); } bool ConstantRange::isUpperWrapped() const { @@ -595,7 +594,7 @@ ConstantRange ConstantRange::unionWith(const ConstantRange &CR, APInt L = CR.Lower.ult(Lower) ? CR.Lower : Lower; APInt U = (CR.Upper - 1).ugt(Upper - 1) ? CR.Upper : Upper; - if (L.isNullValue() && U.isNullValue()) + if (L.isZero() && U.isZero()) return getFull(); return ConstantRange(std::move(L), std::move(U)); @@ -1113,13 +1112,13 @@ ConstantRange::umin(const ConstantRange &Other) const { ConstantRange ConstantRange::udiv(const ConstantRange &RHS) const { - if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax().isNullValue()) + if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax().isZero()) return getEmpty(); APInt Lower = getUnsignedMin().udiv(RHS.getUnsignedMax()); APInt RHS_umin = RHS.getUnsignedMin(); - if (RHS_umin.isNullValue()) { + if (RHS_umin.isZero()) { // We want the lowest value in RHS excluding zero. Usually that would be 1 // except for a range in the form of [X, 1) in which case it would be X. if (RHS.getUpper() == 1) @@ -1136,7 +1135,7 @@ ConstantRange ConstantRange::sdiv(const ConstantRange &RHS) const { // We split up the LHS and RHS into positive and negative components // and then also compute the positive and negative components of the result // separately by combining division results with the appropriate signs. - APInt Zero = APInt::getNullValue(getBitWidth()); + APInt Zero = APInt::getZero(getBitWidth()); APInt SignedMin = APInt::getSignedMinValue(getBitWidth()); ConstantRange PosFilter(APInt(getBitWidth(), 1), SignedMin); ConstantRange NegFilter(SignedMin, Zero); @@ -1159,7 +1158,7 @@ ConstantRange ConstantRange::sdiv(const ConstantRange &RHS) const { // (For APInts the operation is well-defined and yields SignedMin.) We // handle this by dropping either SignedMin from the LHS or -1 from the RHS. APInt Lo = (NegL.Upper - 1).sdiv(NegR.Lower); - if (NegL.Lower.isMinSignedValue() && NegR.Upper.isNullValue()) { + if (NegL.Lower.isMinSignedValue() && NegR.Upper.isZero()) { // Remove -1 from the LHS. Skip if it's the only element, as this would // leave us with an empty set. if (!NegR.Lower.isAllOnesValue()) { @@ -1218,12 +1217,12 @@ ConstantRange ConstantRange::sdiv(const ConstantRange &RHS) const { } ConstantRange ConstantRange::urem(const ConstantRange &RHS) const { - if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax().isNullValue()) + if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax().isZero()) return getEmpty(); if (const APInt *RHSInt = RHS.getSingleElement()) { // UREM by null is UB. - if (RHSInt->isNullValue()) + if (RHSInt->isZero()) return getEmpty(); // Use APInt's implementation of UREM for single element ranges. if (const APInt *LHSInt = getSingleElement()) @@ -1236,7 +1235,7 @@ ConstantRange ConstantRange::urem(const ConstantRange &RHS) const { // L % R is <= L and < R. APInt Upper = APIntOps::umin(getUnsignedMax(), RHS.getUnsignedMax() - 1) + 1; - return getNonEmpty(APInt::getNullValue(getBitWidth()), std::move(Upper)); + return getNonEmpty(APInt::getZero(getBitWidth()), std::move(Upper)); } ConstantRange ConstantRange::srem(const ConstantRange &RHS) const { @@ -1245,7 +1244,7 @@ ConstantRange ConstantRange::srem(const ConstantRange &RHS) const { if (const APInt *RHSInt = RHS.getSingleElement()) { // SREM by null is UB. - if (RHSInt->isNullValue()) + if (RHSInt->isZero()) return getEmpty(); // Use APInt's implementation of SREM for single element ranges. if (const APInt *LHSInt = getSingleElement()) @@ -1257,10 +1256,10 @@ ConstantRange ConstantRange::srem(const ConstantRange &RHS) const { APInt MaxAbsRHS = AbsRHS.getUnsignedMax(); // Modulus by zero is UB. - if (MaxAbsRHS.isNullValue()) + if (MaxAbsRHS.isZero()) return getEmpty(); - if (MinAbsRHS.isNullValue()) + if (MinAbsRHS.isZero()) ++MinAbsRHS; APInt MinLHS = getSignedMin(), MaxLHS = getSignedMax(); @@ -1272,7 +1271,7 @@ ConstantRange ConstantRange::srem(const ConstantRange &RHS) const { // L % R is <= L and < R. APInt Upper = APIntOps::umin(MaxLHS, MaxAbsRHS - 1) + 1; - return ConstantRange(APInt::getNullValue(getBitWidth()), std::move(Upper)); + return ConstantRange(APInt::getZero(getBitWidth()), std::move(Upper)); } // Same basic logic as above, but the result is negative. @@ -1291,7 +1290,7 @@ ConstantRange ConstantRange::srem(const ConstantRange &RHS) const { } ConstantRange ConstantRange::binaryNot() const { - return ConstantRange(APInt::getAllOnesValue(getBitWidth())).sub(*this); + return ConstantRange(APInt::getAllOnes(getBitWidth())).sub(*this); } ConstantRange @@ -1306,7 +1305,7 @@ ConstantRange::binaryAnd(const ConstantRange &Other) const { // TODO: replace this with something less conservative APInt umin = APIntOps::umin(Other.getUnsignedMax(), getUnsignedMax()); - return getNonEmpty(APInt::getNullValue(getBitWidth()), std::move(umin) + 1); + return getNonEmpty(APInt::getZero(getBitWidth()), std::move(umin) + 1); } ConstantRange @@ -1321,7 +1320,7 @@ ConstantRange::binaryOr(const ConstantRange &Other) const { // TODO: replace this with something less conservative APInt umax = APIntOps::umax(getUnsignedMin(), Other.getUnsignedMin()); - return getNonEmpty(std::move(umax), APInt::getNullValue(getBitWidth())); + return getNonEmpty(std::move(umax), APInt::getZero(getBitWidth())); } ConstantRange ConstantRange::binaryXor(const ConstantRange &Other) const { @@ -1352,7 +1351,7 @@ ConstantRange::shl(const ConstantRange &Other) const { // If we are shifting by maximum amount of // zero return return the original range. - if (Other_umax.isNullValue()) + if (Other_umax.isZero()) return *this; // there's overflow! if (Other_umax.ugt(max.countLeadingZeros())) @@ -1535,7 +1534,7 @@ ConstantRange ConstantRange::abs(bool IntMinIsPoison) const { APInt Lo; // Check whether the range crosses zero. if (Upper.isStrictlyPositive() || !Lower.isStrictlyPositive()) - Lo = APInt::getNullValue(getBitWidth()); + Lo = APInt::getZero(getBitWidth()); else Lo = APIntOps::umin(Lower, -Upper + 1); @@ -1565,7 +1564,7 @@ ConstantRange ConstantRange::abs(bool IntMinIsPoison) const { return ConstantRange(-SMax, -SMin + 1); // Range crosses zero. - return ConstantRange(APInt::getNullValue(getBitWidth()), + return ConstantRange(APInt::getZero(getBitWidth()), APIntOps::umax(-SMin, SMax) + 1); } |