Skip to content

Commit c6af243

Browse files
committed
Replace Count{Leading,Trailing}Zeros_{32,64} with count{Leading,Trailing}Zeros.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182680 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 54c7482 commit c6af243

40 files changed

+104
-104
lines changed

include/llvm/ADT/APInt.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,18 +1399,18 @@ class APInt {
13991399
/// equivalent of the string given by \p str.
14001400
static unsigned getBitsNeeded(StringRef str, uint8_t radix);
14011401

1402-
/// \brief Count the number of zeros from the msb to the first one bit.
1402+
/// \brief The APInt version of the countLeadingZeros functions in
1403+
/// MathExtras.h.
14031404
///
1404-
/// This function is an APInt version of the countLeadingZeros_{32,64}
1405-
/// functions in MathExtras.h. It counts the number of zeros from the most
1406-
/// significant bit to the first one bit.
1405+
/// It counts the number of zeros from the most significant bit to the first
1406+
/// one bit.
14071407
///
14081408
/// \returns BitWidth if the value is zero, otherwise returns the number of
1409-
/// zeros from the most significant bit to the first one bits.
1409+
/// zeros from the most significant bit to the first one bits.
14101410
unsigned countLeadingZeros() const {
14111411
if (isSingleWord()) {
14121412
unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth;
1413-
return CountLeadingZeros_64(VAL) - unusedBits;
1413+
return llvm::countLeadingZeros(VAL) - unusedBits;
14141414
}
14151415
return countLeadingZerosSlowCase();
14161416
}

include/llvm/ADT/BitVector.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ class BitVector {
153153
for (unsigned i = 0; i < NumBitWords(size()); ++i)
154154
if (Bits[i] != 0) {
155155
if (sizeof(BitWord) == 4)
156-
return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
156+
return i * BITWORD_SIZE + countTrailingZeros((uint32_t)Bits[i]);
157157
if (sizeof(BitWord) == 8)
158-
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
158+
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
159159
llvm_unreachable("Unsupported!");
160160
}
161161
return -1;
@@ -176,19 +176,19 @@ class BitVector {
176176

177177
if (Copy != 0) {
178178
if (sizeof(BitWord) == 4)
179-
return WordPos * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Copy);
179+
return WordPos * BITWORD_SIZE + countTrailingZeros((uint32_t)Copy);
180180
if (sizeof(BitWord) == 8)
181-
return WordPos * BITWORD_SIZE + CountTrailingZeros_64(Copy);
181+
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
182182
llvm_unreachable("Unsupported!");
183183
}
184184

185185
// Check subsequent words.
186186
for (unsigned i = WordPos+1; i < NumBitWords(size()); ++i)
187187
if (Bits[i] != 0) {
188188
if (sizeof(BitWord) == 4)
189-
return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
189+
return i * BITWORD_SIZE + countTrailingZeros((uint32_t)Bits[i]);
190190
if (sizeof(BitWord) == 8)
191-
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
191+
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
192192
llvm_unreachable("Unsupported!");
193193
}
194194
return -1;

include/llvm/ADT/SmallBitVector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ class SmallBitVector {
216216
if (Bits == 0)
217217
return -1;
218218
if (NumBaseBits == 32)
219-
return CountTrailingZeros_32(Bits);
219+
return countTrailingZeros(Bits);
220220
if (NumBaseBits == 64)
221-
return CountTrailingZeros_64(Bits);
221+
return countTrailingZeros(Bits);
222222
llvm_unreachable("Unsupported!");
223223
}
224224
return getPointer()->find_first();
@@ -234,9 +234,9 @@ class SmallBitVector {
234234
if (Bits == 0 || Prev + 1 >= getSmallSize())
235235
return -1;
236236
if (NumBaseBits == 32)
237-
return CountTrailingZeros_32(Bits);
237+
return countTrailingZeros(Bits);
238238
if (NumBaseBits == 64)
239-
return CountTrailingZeros_64(Bits);
239+
return countTrailingZeros(Bits);
240240
llvm_unreachable("Unsupported!");
241241
}
242242
return getPointer()->find_next(Prev);

include/llvm/ADT/SparseBitVector.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ struct SparseBitVectorElement
137137
for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i)
138138
if (Bits[i] != 0) {
139139
if (sizeof(BitWord) == 4)
140-
return i * BITWORD_SIZE + CountTrailingZeros_32(Bits[i]);
140+
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
141141
if (sizeof(BitWord) == 8)
142-
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
142+
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
143143
llvm_unreachable("Unsupported!");
144144
}
145145
llvm_unreachable("Illegal empty element");
@@ -162,19 +162,19 @@ struct SparseBitVectorElement
162162

163163
if (Copy != 0) {
164164
if (sizeof(BitWord) == 4)
165-
return WordPos * BITWORD_SIZE + CountTrailingZeros_32(Copy);
165+
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
166166
if (sizeof(BitWord) == 8)
167-
return WordPos * BITWORD_SIZE + CountTrailingZeros_64(Copy);
167+
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
168168
llvm_unreachable("Unsupported!");
169169
}
170170

171171
// Check subsequent words.
172172
for (unsigned i = WordPos+1; i < BITWORDS_PER_ELEMENT; ++i)
173173
if (Bits[i] != 0) {
174174
if (sizeof(BitWord) == 4)
175-
return i * BITWORD_SIZE + CountTrailingZeros_32(Bits[i]);
175+
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
176176
if (sizeof(BitWord) == 8)
177-
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
177+
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
178178
llvm_unreachable("Unsupported!");
179179
}
180180
return -1;

include/llvm/Support/MathExtras.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ inline unsigned CountTrailingZeros_64(uint64_t Value) {
517517
/// zero bit (64 bit edition.)
518518
/// Returns 64 if the word is all ones.
519519
inline unsigned CountTrailingOnes_64(uint64_t Value) {
520-
return CountTrailingZeros_64(~Value);
520+
return countTrailingZeros(~Value);
521521
}
522522

523523
/// CountPopulation_32 - this function counts the number of set bits in a value.
@@ -550,26 +550,26 @@ inline unsigned CountPopulation_64(uint64_t Value) {
550550
/// -1 if the value is zero. (32 bit edition.)
551551
/// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2
552552
inline unsigned Log2_32(uint32_t Value) {
553-
return 31 - CountLeadingZeros_32(Value);
553+
return 31 - countLeadingZeros(Value);
554554
}
555555

556556
/// Log2_64 - This function returns the floor log base 2 of the specified value,
557557
/// -1 if the value is zero. (64 bit edition.)
558558
inline unsigned Log2_64(uint64_t Value) {
559-
return 63 - CountLeadingZeros_64(Value);
559+
return 63 - countLeadingZeros(Value);
560560
}
561561

562562
/// Log2_32_Ceil - This function returns the ceil log base 2 of the specified
563563
/// value, 32 if the value is zero. (32 bit edition).
564564
/// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3
565565
inline unsigned Log2_32_Ceil(uint32_t Value) {
566-
return 32-CountLeadingZeros_32(Value-1);
566+
return 32 - countLeadingZeros(Value - 1);
567567
}
568568

569569
/// Log2_64_Ceil - This function returns the ceil log base 2 of the specified
570570
/// value, 64 if the value is zero. (64 bit edition.)
571571
inline unsigned Log2_64_Ceil(uint64_t Value) {
572-
return 64-CountLeadingZeros_64(Value-1);
572+
return 64 - countLeadingZeros(Value - 1);
573573
}
574574

575575
/// GreatestCommonDivisor64 - Return the greatest common divisor of the two

lib/Analysis/ValueTracking.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void llvm::ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne,
290290
}
291291
if (Align > 0)
292292
KnownZero = APInt::getLowBitsSet(BitWidth,
293-
CountTrailingZeros_32(Align));
293+
countTrailingZeros(Align));
294294
else
295295
KnownZero.clearAllBits();
296296
KnownOne.clearAllBits();
@@ -321,7 +321,7 @@ void llvm::ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne,
321321
}
322322

323323
if (Align)
324-
KnownZero = APInt::getLowBitsSet(BitWidth, CountTrailingZeros_32(Align));
324+
KnownZero = APInt::getLowBitsSet(BitWidth, countTrailingZeros(Align));
325325
return;
326326
}
327327

@@ -613,7 +613,7 @@ void llvm::ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne,
613613
Align = TD->getABITypeAlignment(AI->getType()->getElementType());
614614

615615
if (Align > 0)
616-
KnownZero = APInt::getLowBitsSet(BitWidth, CountTrailingZeros_32(Align));
616+
KnownZero = APInt::getLowBitsSet(BitWidth, countTrailingZeros(Align));
617617
break;
618618
}
619619
case Instruction::GetElementPtr: {
@@ -633,8 +633,8 @@ void llvm::ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne,
633633
const StructLayout *SL = TD->getStructLayout(STy);
634634
unsigned Idx = cast<ConstantInt>(Index)->getZExtValue();
635635
uint64_t Offset = SL->getElementOffset(Idx);
636-
TrailZ = std::min(TrailZ,
637-
CountTrailingZeros_64(Offset));
636+
TrailZ = std::min<unsigned>(TrailZ,
637+
countTrailingZeros(Offset));
638638
} else {
639639
// Handle array index arithmetic.
640640
Type *IndexedTy = GTI.getIndexedType();
@@ -644,7 +644,7 @@ void llvm::ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne,
644644
LocalKnownZero = LocalKnownOne = APInt(GEPOpiBits, 0);
645645
ComputeMaskedBits(Index, LocalKnownZero, LocalKnownOne, TD, Depth+1);
646646
TrailZ = std::min(TrailZ,
647-
unsigned(CountTrailingZeros_64(TypeSize) +
647+
unsigned(countTrailingZeros(TypeSize) +
648648
LocalKnownZero.countTrailingOnes()));
649649
}
650650
}

lib/CodeGen/ExecutionDepsFix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct DomainValue {
9191

9292
// First domain available.
9393
unsigned getFirstDomain() const {
94-
return CountTrailingZeros_32(AvailableDomains);
94+
return countTrailingZeros(AvailableDomains);
9595
}
9696

9797
DomainValue() : Refs(0) { clear(); }
@@ -564,7 +564,7 @@ void ExeDepsFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
564564

565565
// If the collapsed operands force a single domain, propagate the collapse.
566566
if (isPowerOf2_32(available)) {
567-
unsigned domain = CountTrailingZeros_32(available);
567+
unsigned domain = countTrailingZeros(available);
568568
TII->setExecutionDomain(mi, domain);
569569
visitHardInstr(mi, domain);
570570
return;

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7509,9 +7509,9 @@ CheckForMaskedLoad(SDValue V, SDValue Ptr, SDValue Chain) {
75097509
// 0 and the bits being kept are 1. Use getSExtValue so that leading bits
75107510
// follow the sign bit for uniformity.
75117511
uint64_t NotMask = ~cast<ConstantSDNode>(V->getOperand(1))->getSExtValue();
7512-
unsigned NotMaskLZ = CountLeadingZeros_64(NotMask);
7512+
unsigned NotMaskLZ = countLeadingZeros(NotMask);
75137513
if (NotMaskLZ & 7) return Result; // Must be multiple of a byte.
7514-
unsigned NotMaskTZ = CountTrailingZeros_64(NotMask);
7514+
unsigned NotMaskTZ = countTrailingZeros(NotMask);
75157515
if (NotMaskTZ & 7) return Result; // Must be multiple of a byte.
75167516
if (NotMaskLZ == 64) return Result; // All zero mask.
75177517

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ void SelectionDAGBuilder::visitBitTestCase(BitTestBlock &BB,
18161816
Cmp = DAG.getSetCC(getCurDebugLoc(),
18171817
TLI.getSetCCResultType(*DAG.getContext(), VT),
18181818
ShiftOp,
1819-
DAG.getConstant(CountTrailingZeros_64(B.Mask), VT),
1819+
DAG.getConstant(countTrailingZeros(B.Mask), VT),
18201820
ISD::SETEQ);
18211821
} else if (PopCount == BB.Range) {
18221822
// There is only one zero bit in the range, test for it directly.

lib/CodeGen/TargetRegisterInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ TargetRegisterInfo::getAllocatableClass(const TargetRegisterClass *RC) const {
8585
Base < BaseE; Base += 32) {
8686
unsigned Idx = Base;
8787
for (unsigned Mask = *SubClass++; Mask; Mask >>= 1) {
88-
unsigned Offset = CountTrailingZeros_32(Mask);
88+
unsigned Offset = countTrailingZeros(Mask);
8989
const TargetRegisterClass *SubRC = getRegClass(Idx + Offset);
9090
if (SubRC->isAllocatable())
9191
return SubRC;
@@ -155,7 +155,7 @@ const TargetRegisterClass *firstCommonClass(const uint32_t *A,
155155
const TargetRegisterInfo *TRI) {
156156
for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; I += 32)
157157
if (unsigned Common = *A++ & *B++)
158-
return TRI->getRegClass(I + CountTrailingZeros_32(Common));
158+
return TRI->getRegClass(I + countTrailingZeros(Common));
159159
return 0;
160160
}
161161

lib/Object/ELFObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ObjectFile *ObjectFile::createELFObjectFile(MemoryBuffer *Object) {
2424
error_code ec;
2525

2626
std::size_t MaxAlignment =
27-
1ULL << CountTrailingZeros_64(uintptr_t(Object->getBufferStart()));
27+
1ULL << countTrailingZeros(uintptr_t(Object->getBufferStart()));
2828

2929
if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB)
3030
#if !LLVM_IS_UNALIGNED_ACCESS_FAST

lib/Support/APInt.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,14 +692,14 @@ unsigned APInt::countLeadingZerosSlowCase() const {
692692
unsigned i = getNumWords();
693693
integerPart MSW = pVal[i-1] & MSWMask;
694694
if (MSW)
695-
return CountLeadingZeros_64(MSW) - (APINT_BITS_PER_WORD - BitsInMSW);
695+
return llvm::countLeadingZeros(MSW) - (APINT_BITS_PER_WORD - BitsInMSW);
696696

697697
unsigned Count = BitsInMSW;
698698
for (--i; i > 0u; --i) {
699699
if (pVal[i-1] == 0)
700700
Count += APINT_BITS_PER_WORD;
701701
else {
702-
Count += CountLeadingZeros_64(pVal[i-1]);
702+
Count += llvm::countLeadingZeros(pVal[i-1]);
703703
break;
704704
}
705705
}
@@ -735,13 +735,13 @@ unsigned APInt::countLeadingOnes() const {
735735

736736
unsigned APInt::countTrailingZeros() const {
737737
if (isSingleWord())
738-
return std::min(unsigned(CountTrailingZeros_64(VAL)), BitWidth);
738+
return std::min(unsigned(llvm::countTrailingZeros(VAL)), BitWidth);
739739
unsigned Count = 0;
740740
unsigned i = 0;
741741
for (; i < getNumWords() && pVal[i] == 0; ++i)
742742
Count += APINT_BITS_PER_WORD;
743743
if (i < getNumWords())
744-
Count += CountTrailingZeros_64(pVal[i]);
744+
Count += llvm::countTrailingZeros(pVal[i]);
745745
return std::min(Count, BitWidth);
746746
}
747747

@@ -1512,7 +1512,7 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
15121512
// and v so that its high bits are shifted to the top of v's range without
15131513
// overflow. Note that this can require an extra word in u so that u must
15141514
// be of length m+n+1.
1515-
unsigned shift = CountLeadingZeros_32(v[n-1]);
1515+
unsigned shift = countLeadingZeros(v[n-1]);
15161516
unsigned v_carry = 0;
15171517
unsigned u_carry = 0;
15181518
if (shift) {

lib/Target/AArch64/AArch64BranchFixupPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace {
8787
// If the block size isn't a multiple of the known bits, assume the
8888
// worst case padding.
8989
if (Size & ((1u << Bits) - 1))
90-
Bits = CountTrailingZeros_32(Size);
90+
Bits = countTrailingZeros(Size);
9191
return Bits;
9292
}
9393

lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ static int32_t getLSBForBFI(SelectionDAG &DAG, DebugLoc DL, EVT VT,
24642464
// cases (e.g. bitfield to bitfield copy) may still need a real shift before
24652465
// the BFI.
24662466

2467-
uint64_t LSB = CountTrailingZeros_64(Mask);
2467+
uint64_t LSB = countTrailingZeros(Mask);
24682468
int64_t ShiftRightRequired = LSB;
24692469
if (MaskedVal.getOpcode() == ISD::SHL &&
24702470
isa<ConstantSDNode>(MaskedVal.getOperand(1))) {

lib/Target/AArch64/Utils/AArch64BaseInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ bool A64Imms::isLogicalImm(unsigned RegWidth, uint64_t Imm, uint32_t &Bits) {
972972
// Now we have to work out the amount of rotation needed. The first part of
973973
// this calculation is actually independent of RepeatWidth, but the complex
974974
// case will depend on it.
975-
Rotation = CountTrailingZeros_64(Imm);
975+
Rotation = countTrailingZeros(Imm);
976976
if (Rotation == 0) {
977977
// There were no leading zeros, which means it's either in place or there
978978
// are 1s at each end (e.g. 0x8003 needs rotating).

lib/Target/ARM/ARMCodeEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,8 +1044,8 @@ void ARMCodeEmitter::emitDataProcessingInstruction(const MachineInstr &MI,
10441044
return;
10451045
} else if ((MCID.Opcode == ARM::BFC) || (MCID.Opcode == ARM::BFI)) {
10461046
uint32_t v = ~MI.getOperand(2).getImm();
1047-
int32_t lsb = CountTrailingZeros_32(v);
1048-
int32_t msb = (32 - CountLeadingZeros_32(v)) - 1;
1047+
int32_t lsb = countTrailingZeros(v);
1048+
int32_t msb = (32 - countLeadingZeros(v)) - 1;
10491049
// Instr{20-16} = msb, Instr{11-7} = lsb
10501050
Binary |= (msb & 0x1F) << 16;
10511051
Binary |= (lsb & 0x1F) << 7;

lib/Target/ARM/ARMConstantIslandPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ namespace {
128128
// If the block size isn't a multiple of the known bits, assume the
129129
// worst case padding.
130130
if (Size & ((1u << Bits) - 1))
131-
Bits = CountTrailingZeros_32(Size);
131+
Bits = countTrailingZeros(Size);
132132
return Bits;
133133
}
134134

lib/Target/ARM/ARMISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void ARMDAGToDAGISel::PreprocessISelDAG() {
364364
continue;
365365

366366
// Check if the AND mask is an immediate of the form: 000.....1111111100
367-
unsigned TZ = CountTrailingZeros_32(And_imm);
367+
unsigned TZ = countTrailingZeros(And_imm);
368368
if (TZ != 1 && TZ != 2)
369369
// Be conservative here. Shifter operands aren't always free. e.g. On
370370
// Swift, left shifter operand of 1 / 2 for free but others are not.

0 commit comments

Comments
 (0)