Skip to content

Commit 735f467

Browse files
committed
[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
1 parent 6355234 commit 735f467

File tree

84 files changed

+405
-420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+405
-420
lines changed

clang/lib/AST/ExprConstant.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2675,7 +2675,7 @@ static bool EvalAndBitcastToAPInt(EvalInfo &Info, const Expr *E,
26752675
QualType EltTy = VecTy->castAs<VectorType>()->getElementType();
26762676
unsigned EltSize = Info.Ctx.getTypeSize(EltTy);
26772677
bool BigEndian = Info.Ctx.getTargetInfo().isBigEndian();
2678-
Res = llvm::APInt::getNullValue(VecSize);
2678+
Res = llvm::APInt::getZero(VecSize);
26792679
for (unsigned i = 0; i < SVal.getVectorLength(); i++) {
26802680
APValue &Elt = SVal.getVectorElt(i);
26812681
llvm::APInt EltAsInt;

clang/lib/CodeGen/CGExpr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ static bool getRangeForType(CodeGenFunction &CGF, QualType Ty,
16421642
} else {
16431643
assert(NumPositiveBits <= Bitwidth);
16441644
End = llvm::APInt(Bitwidth, 1) << NumPositiveBits;
1645-
Min = llvm::APInt(Bitwidth, 0);
1645+
Min = llvm::APInt::getZero(Bitwidth);
16461646
}
16471647
}
16481648
return true;

clang/lib/Sema/SemaExprCXX.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -2247,8 +2247,7 @@ Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
22472247
}
22482248

22492249
IntegerLiteral AllocationSizeLiteral(
2250-
Context,
2251-
AllocationSize.getValueOr(llvm::APInt::getNullValue(SizeTyWidth)),
2250+
Context, AllocationSize.getValueOr(llvm::APInt::getZero(SizeTyWidth)),
22522251
SizeTy, SourceLocation());
22532252
// Otherwise, if we failed to constant-fold the allocation size, we'll
22542253
// just give up and pass-in something opaque, that isn't a null pointer.
@@ -2593,10 +2592,9 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
25932592
// FIXME: Should the Sema create the expression and embed it in the syntax
25942593
// tree? Or should the consumer just recalculate the value?
25952594
// FIXME: Using a dummy value will interact poorly with attribute enable_if.
2596-
IntegerLiteral Size(Context, llvm::APInt::getNullValue(
2597-
Context.getTargetInfo().getPointerWidth(0)),
2598-
Context.getSizeType(),
2599-
SourceLocation());
2595+
IntegerLiteral Size(
2596+
Context, llvm::APInt::getZero(Context.getTargetInfo().getPointerWidth(0)),
2597+
Context.getSizeType(), SourceLocation());
26002598
AllocArgs.push_back(&Size);
26012599

26022600
QualType AlignValT = Context.VoidTy;

clang/lib/Sema/SemaOpenMP.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -17153,7 +17153,7 @@ static bool actOnOMPReductionKindClause(
1715317153
} else if (Type->isScalarType()) {
1715417154
uint64_t Size = Context.getTypeSize(Type);
1715517155
QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0);
17156-
llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size);
17156+
llvm::APInt InitValue = llvm::APInt::getAllOnes(Size);
1715717157
Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc);
1715817158
}
1715917159
if (Init && OrigType->isAnyComplexType()) {
@@ -18361,7 +18361,7 @@ Sema::ActOnOpenMPDependClause(Expr *DepModifier, OpenMPDependClauseKind DepKind,
1836118361
Expr::EvalResult Result;
1836218362
if (Length && !Length->isValueDependent() &&
1836318363
Length->EvaluateAsInt(Result, Context) &&
18364-
Result.Val.getInt().isNullValue()) {
18364+
Result.Val.getInt().isZero()) {
1836518365
Diag(ELoc,
1836618366
diag::err_omp_depend_zero_length_array_section_not_allowed)
1836718367
<< SimpleExpr->getSourceRange();
@@ -18754,7 +18754,7 @@ class MapBaseChecker final : public StmtVisitor<MapBaseChecker, bool> {
1875418754
Expr::EvalResult Result;
1875518755
if (!AE->getIdx()->isValueDependent() &&
1875618756
AE->getIdx()->EvaluateAsInt(Result, SemaRef.getASTContext()) &&
18757-
!Result.Val.getInt().isNullValue()) {
18757+
!Result.Val.getInt().isZero()) {
1875818758
SemaRef.Diag(AE->getIdx()->getExprLoc(),
1875918759
diag::err_omp_invalid_map_this_expr);
1876018760
SemaRef.Diag(AE->getIdx()->getExprLoc(),
@@ -18842,7 +18842,7 @@ class MapBaseChecker final : public StmtVisitor<MapBaseChecker, bool> {
1884218842
if (OASE->getLowerBound() && !OASE->getLowerBound()->isValueDependent() &&
1884318843
OASE->getLowerBound()->EvaluateAsInt(ResultL,
1884418844
SemaRef.getASTContext()) &&
18845-
!ResultL.Val.getInt().isNullValue()) {
18845+
!ResultL.Val.getInt().isZero()) {
1884618846
SemaRef.Diag(OASE->getLowerBound()->getExprLoc(),
1884718847
diag::err_omp_invalid_map_this_expr);
1884818848
SemaRef.Diag(OASE->getLowerBound()->getExprLoc(),

clang/lib/StaticAnalyzer/Core/MemRegion.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ DefinedOrUnknownSVal MemRegionManager::getStaticSize(const MemRegion *MR,
789789

790790
if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
791791
const llvm::APInt &Size = CAT->getSize();
792-
if (Size.isNullValue())
792+
if (Size.isZero())
793793
return true;
794794

795795
const AnalyzerOptions &Opts = SVB.getAnalyzerOptions();

lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2946,9 +2946,9 @@ bool EmulateInstructionMIPS::Emulate_MSA_Branch_V(llvm::MCInst &insn,
29462946
bool bnz) {
29472947
bool success = false;
29482948
int32_t target = 0;
2949-
llvm::APInt wr_val = llvm::APInt::getNullValue(128);
2949+
llvm::APInt wr_val = llvm::APInt::getZero(128);
29502950
llvm::APInt fail_value = llvm::APInt::getMaxValue(128);
2951-
llvm::APInt zero_value = llvm::APInt::getNullValue(128);
2951+
llvm::APInt zero_value = llvm::APInt::getZero(128);
29522952
RegisterValue reg_value;
29532953

29542954
uint32_t wt = m_reg_info->getEncodingValue(insn.getOperand(0).getReg());

lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2258,9 +2258,9 @@ bool EmulateInstructionMIPS64::Emulate_MSA_Branch_V(llvm::MCInst &insn,
22582258
bool bnz) {
22592259
bool success = false;
22602260
int64_t target = 0;
2261-
llvm::APInt wr_val = llvm::APInt::getNullValue(128);
2261+
llvm::APInt wr_val = llvm::APInt::getZero(128);
22622262
llvm::APInt fail_value = llvm::APInt::getMaxValue(128);
2263-
llvm::APInt zero_value = llvm::APInt::getNullValue(128);
2263+
llvm::APInt zero_value = llvm::APInt::getZero(128);
22642264
RegisterValue reg_value;
22652265

22662266
uint32_t wt = m_reg_info->getEncodingValue(insn.getOperand(0).getReg());

lldb/source/Utility/Scalar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ Status Scalar::SetValueFromData(const DataExtractor &data,
714714
return Status("insufficient data");
715715
m_type = e_int;
716716
m_integer =
717-
APSInt(APInt::getNullValue(8 * byte_size), encoding == eEncodingUint);
717+
APSInt(APInt::getZero(8 * byte_size), encoding == eEncodingUint);
718718
if (data.GetByteOrder() == endian::InlHostByteOrder()) {
719719
llvm::LoadIntFromMemory(m_integer, data.GetDataStart(), byte_size);
720720
} else {

llvm/include/llvm/ADT/APInt.h

+27-21
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,11 @@ class LLVM_NODISCARD APInt {
173173
/// \name Value Generators
174174
/// @{
175175

176-
/// Get the '0' value.
177-
///
178-
/// \returns the '0' value for an APInt of the specified bit-width.
179-
static APInt getNullValue(unsigned numBits) { return APInt(numBits, 0); }
176+
/// Get the '0' value for the specified bit-width.
177+
static APInt getZero(unsigned numBits) { return APInt(numBits, 0); }
178+
179+
/// NOTE: This is soft-deprecated. Please use `getZero()` instead.
180+
static APInt getNullValue(unsigned numBits) { return getZero(numBits); }
180181

181182
/// Gets maximum unsigned value of APInt for specific bit width.
182183
static APInt getMaxValue(unsigned numBits) {
@@ -208,13 +209,14 @@ class LLVM_NODISCARD APInt {
208209
return getSignedMinValue(BitWidth);
209210
}
210211

211-
/// Get the all-ones value.
212-
///
213-
/// \returns the all-ones value for an APInt of the specified bit-width.
214-
static APInt getAllOnesValue(unsigned numBits) {
212+
/// Return an APInt of a specified width with all bits set.
213+
static APInt getAllOnes(unsigned numBits) {
215214
return APInt(numBits, WORDTYPE_MAX, true);
216215
}
217216

217+
/// NOTE: This is soft-deprecated. Please use `getAllOnes()` instead.
218+
static APInt getAllOnesValue(unsigned numBits) { return getAllOnes(numBits); }
219+
218220
/// Return an APInt with exactly one bit set in the result.
219221
static APInt getOneBitSet(unsigned numBits, unsigned BitNo) {
220222
APInt Res(numBits, 0);
@@ -340,42 +342,46 @@ class LLVM_NODISCARD APInt {
340342
/// that 0 is not a positive value.
341343
///
342344
/// \returns true if this APInt is positive.
343-
bool isStrictlyPositive() const { return isNonNegative() && !isNullValue(); }
345+
bool isStrictlyPositive() const { return isNonNegative() && !isZero(); }
344346

345347
/// Determine if this APInt Value is non-positive (<= 0).
346348
///
347349
/// \returns true if this APInt is non-positive.
348350
bool isNonPositive() const { return !isStrictlyPositive(); }
349351

350-
/// Determine if all bits are set
351-
///
352-
/// This checks to see if the value has all bits of the APInt are set or not.
353-
bool isAllOnesValue() const {
352+
/// Determine if all bits are set.
353+
bool isAllOnes() const {
354354
if (isSingleWord())
355355
return U.VAL == WORDTYPE_MAX >> (APINT_BITS_PER_WORD - BitWidth);
356356
return countTrailingOnesSlowCase() == BitWidth;
357357
}
358358

359-
/// Determine if all bits are clear
360-
///
361-
/// This checks to see if the value has all bits of the APInt are clear or
362-
/// not.
363-
bool isNullValue() const { return !*this; }
359+
/// NOTE: This is soft-deprecated. Please use `isAllOnes()` instead.
360+
bool isAllOnesValue() const { return isAllOnes(); }
361+
362+
/// Determine if this value is zero, i.e. all bits are clear.
363+
bool isZero() const { return !*this; }
364+
365+
/// NOTE: This is soft-deprecated. Please use `isZero()` instead.
366+
bool isNullValue() const { return isZero(); }
364367

365368
/// Determine if this is a value of 1.
366369
///
367370
/// This checks to see if the value of this APInt is one.
368-
bool isOneValue() const {
371+
bool isOne() const {
369372
if (isSingleWord())
370373
return U.VAL == 1;
371374
return countLeadingZerosSlowCase() == BitWidth - 1;
372375
}
373376

377+
/// NOTE: This is soft-deprecated. Please use `isOne()` instead.
378+
bool isOneValue() const { return isOne(); }
379+
374380
/// Determine if this is the largest unsigned value.
375381
///
376382
/// This checks to see if the value of this APInt is the maximum unsigned
377383
/// value for the APInt's bit width.
378-
bool isMaxValue() const { return isAllOnesValue(); }
384+
bool isMaxValue() const { return isAllOnes(); }
379385

380386
/// Determine if this is the largest signed value.
381387
///
@@ -391,7 +397,7 @@ class LLVM_NODISCARD APInt {
391397
///
392398
/// This checks to see if the value of this APInt is the minimum unsigned
393399
/// value for the APInt's bit width.
394-
bool isMinValue() const { return isNullValue(); }
400+
bool isMinValue() const { return isZero(); }
395401

396402
/// Determine if this is the smallest signed value.
397403
///

llvm/include/llvm/ADT/APSInt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class LLVM_NODISCARD APSInt : public APInt {
5858
/// that 0 is not a positive value.
5959
///
6060
/// \returns true if this APSInt is positive.
61-
bool isStrictlyPositive() const { return isNonNegative() && !isNullValue(); }
61+
bool isStrictlyPositive() const { return isNonNegative() && !isZero(); }
6262

6363
APSInt &operator=(APInt RHS) {
6464
// Retain our current sign.

llvm/include/llvm/CodeGen/BasicTTIImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
697697
bool Extract) {
698698
auto *Ty = cast<FixedVectorType>(InTy);
699699

700-
APInt DemandedElts = APInt::getAllOnesValue(Ty->getNumElements());
700+
APInt DemandedElts = APInt::getAllOnes(Ty->getNumElements());
701701
return thisT()->getScalarizationOverhead(Ty, DemandedElts, Insert, Extract);
702702
}
703703

llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class LegalizationArtifactCombiner {
127127
return false;
128128
LLVM_DEBUG(dbgs() << ".. Combine MI: " << MI;);
129129
LLT SrcTy = MRI.getType(SrcReg);
130-
APInt MaskVal = APInt::getAllOnesValue(SrcTy.getScalarSizeInBits());
130+
APInt MaskVal = APInt::getAllOnes(SrcTy.getScalarSizeInBits());
131131
auto Mask = Builder.buildConstant(
132132
DstTy, MaskVal.zext(DstTy.getScalarSizeInBits()));
133133
if (SextSrc && (DstTy != MRI.getType(SextSrc)))

llvm/include/llvm/CodeGen/SelectionDAG.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ class SelectionDAG {
621621

622622
SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget = false,
623623
bool IsOpaque = false) {
624-
return getConstant(APInt::getAllOnesValue(VT.getScalarSizeInBits()), DL,
625-
VT, IsTarget, IsOpaque);
624+
return getConstant(APInt::getAllOnes(VT.getScalarSizeInBits()), DL, VT,
625+
IsTarget, IsOpaque);
626626
}
627627

628628
SDValue getConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT,

llvm/include/llvm/IR/Constants.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ class ConstantInt final : public ConstantData {
191191
/// This is just a convenience method to make client code smaller for a
192192
/// common code. It also correctly performs the comparison without the
193193
/// potential for an assertion from getZExtValue().
194-
bool isZero() const { return Val.isNullValue(); }
194+
bool isZero() const { return Val.isZero(); }
195195

196196
/// This is just a convenience method to make client code smaller for a
197197
/// common case. It also correctly performs the comparison without the
198198
/// potential for an assertion from getZExtValue().
199199
/// Determine if the value is one.
200-
bool isOne() const { return Val.isOneValue(); }
200+
bool isOne() const { return Val.isOne(); }
201201

202202
/// This function will return true iff every bit in this constant is set
203203
/// to true.

llvm/include/llvm/IR/PatternMatch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ inline cst_pred_ty<is_one> m_One() {
515515
}
516516

517517
struct is_zero_int {
518-
bool isValue(const APInt &C) { return C.isNullValue(); }
518+
bool isValue(const APInt &C) { return C.isZero(); }
519519
};
520520
/// Match an integer 0 or a vector with all elements equal to 0.
521521
/// For vectors, this includes constants with undefined elements.

llvm/include/llvm/Support/KnownBits.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct KnownBits {
6060
}
6161

6262
/// Returns true if we don't know any bits.
63-
bool isUnknown() const { return Zero.isNullValue() && One.isNullValue(); }
63+
bool isUnknown() const { return Zero.isZero() && One.isZero(); }
6464

6565
/// Resets the known state of all bits.
6666
void resetAll() {
@@ -99,10 +99,12 @@ struct KnownBits {
9999
bool isNonNegative() const { return Zero.isSignBitSet(); }
100100

101101
/// Returns true if this value is known to be non-zero.
102-
bool isNonZero() const { return !One.isNullValue(); }
102+
bool isNonZero() const { return !One.isZero(); }
103103

104104
/// Returns true if this value is known to be positive.
105-
bool isStrictlyPositive() const { return Zero.isSignBitSet() && !One.isNullValue(); }
105+
bool isStrictlyPositive() const {
106+
return Zero.isSignBitSet() && !One.isZero();
107+
}
106108

107109
/// Make this value negative.
108110
void makeNegative() {

llvm/include/llvm/Transforms/InstCombine/InstCombiner.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,16 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
165165
switch (Pred) {
166166
case ICmpInst::ICMP_SLT: // True if LHS s< 0
167167
TrueIfSigned = true;
168-
return RHS.isNullValue();
168+
return RHS.isZero();
169169
case ICmpInst::ICMP_SLE: // True if LHS s<= -1
170170
TrueIfSigned = true;
171-
return RHS.isAllOnesValue();
171+
return RHS.isAllOnes();
172172
case ICmpInst::ICMP_SGT: // True if LHS s> -1
173173
TrueIfSigned = false;
174-
return RHS.isAllOnesValue();
174+
return RHS.isAllOnes();
175175
case ICmpInst::ICMP_SGE: // True if LHS s>= 0
176176
TrueIfSigned = false;
177-
return RHS.isNullValue();
177+
return RHS.isZero();
178178
case ICmpInst::ICMP_UGT:
179179
// True if LHS u> RHS and RHS == sign-bit-mask - 1
180180
TrueIfSigned = true;

llvm/lib/Analysis/DemandedBits.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void DemandedBits::performAnalysis() {
362362
if (Instruction *J = dyn_cast<Instruction>(OI)) {
363363
Type *T = J->getType();
364364
if (T->isIntOrIntVectorTy())
365-
AliveBits[J] = APInt::getAllOnesValue(T->getScalarSizeInBits());
365+
AliveBits[J] = APInt::getAllOnes(T->getScalarSizeInBits());
366366
else
367367
Visited.insert(J);
368368
Worklist.insert(J);
@@ -407,7 +407,7 @@ void DemandedBits::performAnalysis() {
407407
Type *T = OI->getType();
408408
if (T->isIntOrIntVectorTy()) {
409409
unsigned BitWidth = T->getScalarSizeInBits();
410-
APInt AB = APInt::getAllOnesValue(BitWidth);
410+
APInt AB = APInt::getAllOnes(BitWidth);
411411
if (InputIsKnownDead) {
412412
AB = APInt(BitWidth, 0);
413413
} else {
@@ -417,7 +417,7 @@ void DemandedBits::performAnalysis() {
417417
Known, Known2, KnownBitsComputed);
418418

419419
// Keep track of uses which have no demanded bits.
420-
if (AB.isNullValue())
420+
if (AB.isZero())
421421
DeadUses.insert(&OI);
422422
else
423423
DeadUses.erase(&OI);
@@ -448,8 +448,7 @@ APInt DemandedBits::getDemandedBits(Instruction *I) {
448448
return Found->second;
449449

450450
const DataLayout &DL = I->getModule()->getDataLayout();
451-
return APInt::getAllOnesValue(
452-
DL.getTypeSizeInBits(I->getType()->getScalarType()));
451+
return APInt::getAllOnes(DL.getTypeSizeInBits(I->getType()->getScalarType()));
453452
}
454453

455454
APInt DemandedBits::getDemandedBits(Use *U) {
@@ -461,15 +460,15 @@ APInt DemandedBits::getDemandedBits(Use *U) {
461460
// We only track integer uses, everything else produces a mask with all bits
462461
// set
463462
if (!T->isIntOrIntVectorTy())
464-
return APInt::getAllOnesValue(BitWidth);
463+
return APInt::getAllOnes(BitWidth);
465464

466465
if (isUseDead(U))
467466
return APInt(BitWidth, 0);
468467

469468
performAnalysis();
470469

471470
APInt AOut = getDemandedBits(UserI);
472-
APInt AB = APInt::getAllOnesValue(BitWidth);
471+
APInt AB = APInt::getAllOnes(BitWidth);
473472
KnownBits Known, Known2;
474473
bool KnownBitsComputed = false;
475474

@@ -504,7 +503,7 @@ bool DemandedBits::isUseDead(Use *U) {
504503
// is dead. These uses might not be explicitly present in the DeadUses map.
505504
if (UserI->getType()->isIntOrIntVectorTy()) {
506505
auto Found = AliveBits.find(UserI);
507-
if (Found != AliveBits.end() && Found->second.isNullValue())
506+
if (Found != AliveBits.end() && Found->second.isZero())
508507
return true;
509508
}
510509

0 commit comments

Comments
 (0)