Skip to content

Commit 55e2cd1

Browse files
Use llvm::count{lr}_{zero,one} (NFC)
1 parent a536d3e commit 55e2cd1

Some content is hidden

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

51 files changed

+92
-97
lines changed

clang-tools-extra/clangd/SourceCode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static bool iterateCodepoints(llvm::StringRef U8, const Callback &CB) {
7272
continue;
7373
}
7474
// This convenient property of UTF-8 holds for all non-ASCII characters.
75-
size_t UTF8Length = llvm::countLeadingOnes(C);
75+
size_t UTF8Length = llvm::countl_one(C);
7676
// 0xxx is ASCII, handled above. 10xxx is a trailing byte, invalid here.
7777
// 11111xxx is not valid UTF-8 at all, maybe some ISO-8859-*.
7878
if (LLVM_UNLIKELY(UTF8Length < 2 || UTF8Length > 4)) {

clang/include/clang/Basic/TargetBuiltins.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ namespace clang {
243243
};
244244

245245
SVETypeFlags(uint64_t F) : Flags(F) {
246-
EltTypeShift = llvm::countTrailingZeros(EltTypeMask);
247-
MemEltTypeShift = llvm::countTrailingZeros(MemEltTypeMask);
248-
MergeTypeShift = llvm::countTrailingZeros(MergeTypeMask);
249-
SplatOperandMaskShift = llvm::countTrailingZeros(SplatOperandMask);
246+
EltTypeShift = llvm::countr_zero(EltTypeMask);
247+
MemEltTypeShift = llvm::countr_zero(MemEltTypeMask);
248+
MergeTypeShift = llvm::countr_zero(MergeTypeMask);
249+
SplatOperandMaskShift = llvm::countr_zero(SplatOperandMask);
250250
}
251251

252252
EltType getEltType() const {

clang/include/clang/CodeGen/CGFunctionInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ class CGFunctionInfo final
742742
/// Set the maximum vector width in the arguments.
743743
void setMaxVectorWidth(unsigned Width) {
744744
assert(llvm::isPowerOf2_32(Width) && "Expected power of 2 vector");
745-
MaxVectorWidth = llvm::countTrailingZeros(Width) + 1;
745+
MaxVectorWidth = llvm::countr_zero(Width) + 1;
746746
}
747747

748748
void Profile(llvm::FoldingSetNodeID &ID) {

clang/lib/AST/Interp/Integral.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ template <unsigned Bits, bool Signed> class Integral final {
127127
return Compare(V, RHS.V);
128128
}
129129

130-
unsigned countLeadingZeros() const {
131-
return llvm::countLeadingZeros<ReprT>(V);
132-
}
130+
unsigned countLeadingZeros() const { return llvm::countl_zero<ReprT>(V); }
133131

134132
Integral truncate(unsigned TruncBits) const {
135133
if (TruncBits >= Bits)

clang/lib/Basic/SourceManager.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,7 @@ LineOffsetMapping LineOffsetMapping::get(llvm::MemoryBufferRef Buffer,
13021302
// in [\n, \r + 1 [
13031303

13041304
// Scan for the next newline - it's very likely there's one.
1305-
unsigned N =
1306-
llvm::countTrailingZeros(Mask) - 7; // -7 because 0x80 is the marker
1305+
unsigned N = llvm::countr_zero(Mask) - 7; // -7 because 0x80 is the marker
13071306
Word >>= N;
13081307
Buf += N / 8 + 1;
13091308
unsigned char Byte = Word;

clang/lib/Lex/Lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,7 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr,
27852785
// Adjust the pointer to point directly after the first slash. It's
27862786
// not necessary to set C here, it will be overwritten at the end of
27872787
// the outer loop.
2788-
CurPtr += llvm::countTrailingZeros<unsigned>(cmp) + 1;
2788+
CurPtr += llvm::countr_zero<unsigned>(cmp) + 1;
27892789
goto FoundSlash;
27902790
}
27912791
CurPtr += 16;

clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class PaddingChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
273273
SmallVector<const FieldDecl *, 20> OptimalFieldsOrder;
274274
while (!Fields.empty()) {
275275
unsigned TrailingZeros =
276-
llvm::countTrailingZeros((unsigned long long)NewOffset.getQuantity());
276+
llvm::countr_zero((unsigned long long)NewOffset.getQuantity());
277277
// If NewOffset is zero, then countTrailingZeros will be 64. Shifting
278278
// 64 will overflow our unsigned long long. Shifting 63 will turn
279279
// our long long (and CharUnits internal type) negative. So shift 62.

clang/utils/TableGen/SveEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class SVEEmitter {
298298
auto It = FlagTypes.find(MaskName);
299299
if (It != FlagTypes.end()) {
300300
uint64_t Mask = It->getValue();
301-
unsigned Shift = llvm::countTrailingZeros(Mask);
301+
unsigned Shift = llvm::countr_zero(Mask);
302302
return (V << Shift) & Mask;
303303
}
304304
llvm_unreachable("Unsupported flag");

lld/ELF/Arch/ARM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static std::pair<uint32_t, uint32_t> getRemAndLZForGroup(unsigned group,
432432
uint32_t val) {
433433
uint32_t rem, lz;
434434
do {
435-
lz = llvm::countLeadingZeros(val) & ~1;
435+
lz = llvm::countl_zero(val) & ~1;
436436
rem = val;
437437
if (lz == 32) // implies rem == 0
438438
break;

lld/ELF/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ static uint64_t getAlignment(ArrayRef<typename ELFT::Shdr> sections,
13171317
const typename ELFT::Sym &sym) {
13181318
uint64_t ret = UINT64_MAX;
13191319
if (sym.st_value)
1320-
ret = 1ULL << countTrailingZeros((uint64_t)sym.st_value);
1320+
ret = 1ULL << llvm::countr_zero((uint64_t)sym.st_value);
13211321
if (0 < sym.st_shndx && sym.st_shndx < sections.size())
13221322
ret = std::min<uint64_t>(ret, sections[sym.st_shndx].sh_addralign);
13231323
return (ret > UINT32_MAX) ? 0 : ret;

lld/ELF/SyntheticSections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2782,7 +2782,7 @@ createSymbols(
27822782
// A sharded map to uniquify symbols by name.
27832783
auto map =
27842784
std::make_unique<DenseMap<CachedHashStringRef, size_t>[]>(numShards);
2785-
size_t shift = 32 - countTrailingZeros(numShards);
2785+
size_t shift = 32 - llvm::countr_zero(numShards);
27862786

27872787
// Instantiate GdbSymbols while uniqufying them by name.
27882788
auto symbols = std::make_unique<SmallVector<GdbSymbol, 0>[]>(numShards);

lld/ELF/SyntheticSections.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ class MergeNoTailSection final : public MergeSyntheticSection {
970970
// hash collisions.
971971
size_t getShardId(uint32_t hash) {
972972
assert((hash >> 31) == 0);
973-
return hash >> (31 - llvm::countTrailingZeros(numShards));
973+
return hash >> (31 - llvm::countr_zero(numShards));
974974
}
975975

976976
// Section size

lld/ELF/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ template <class ELFT> void Writer<ELFT>::setReservedSymbolSections() {
11111111
static int getRankProximity(OutputSection *a, SectionCommand *b) {
11121112
auto *osd = dyn_cast<OutputDesc>(b);
11131113
return (osd && osd->osec.hasInputSections)
1114-
? countLeadingZeros(a->sortRank ^ osd->osec.sortRank)
1114+
? llvm::countl_zero(a->sortRank ^ osd->osec.sortRank)
11151115
: -1;
11161116
}
11171117

lld/MachO/SyntheticSections.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ void CStringSection::finalizeContents() {
16411641
// See comment above DeduplicatedCStringSection for how alignment is
16421642
// handled.
16431643
uint32_t pieceAlign = 1
1644-
<< countTrailingZeros(isec->align | piece.inSecOff);
1644+
<< llvm::countr_zero(isec->align | piece.inSecOff);
16451645
offset = alignTo(offset, pieceAlign);
16461646
piece.outSecOff = offset;
16471647
isec->isFinal = true;
@@ -1698,7 +1698,7 @@ void DeduplicatedCStringSection::finalizeContents() {
16981698
continue;
16991699
auto s = isec->getCachedHashStringRef(i);
17001700
assert(isec->align != 0);
1701-
uint8_t trailingZeros = countTrailingZeros(isec->align | piece.inSecOff);
1701+
uint8_t trailingZeros = llvm::countr_zero(isec->align | piece.inSecOff);
17021702
auto it = stringOffsetMap.insert(
17031703
std::make_pair(s, StringOffset(trailingZeros)));
17041704
if (!it.second && it.first->second.trailingZeros < trailingZeros)

lld/MachO/UnwindInfoSection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void UnwindInfoSectionImpl::encodePersonalities() {
405405
personalityIndex = personalities.size();
406406
}
407407
cu.encoding |=
408-
personalityIndex << countTrailingZeros(
408+
personalityIndex << llvm::countr_zero(
409409
static_cast<compact_unwind_encoding_t>(UNWIND_PERSONALITY_MASK));
410410
}
411411
if (personalities.size() > 3)

lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ static std::optional<RegisterInfo> GetARMDWARFRegisterInfo(unsigned reg_num) {
605605
// Valid return values are {1, 2, 3, 4}, with 0 signifying an error condition.
606606
static uint32_t CountITSize(uint32_t ITMask) {
607607
// First count the trailing zeros of the IT mask.
608-
uint32_t TZ = llvm::countTrailingZeros(ITMask);
608+
uint32_t TZ = llvm::countr_zero(ITMask);
609609
if (TZ > 3) {
610610
return 0;
611611
}

lldb/source/Symbol/CompactUnwindInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ FLAGS_ANONYMOUS_ENUM(){
155155
#endif
156156

157157
#define EXTRACT_BITS(value, mask) \
158-
((value >> llvm::countTrailingZeros(static_cast<uint32_t>(mask))) & \
158+
((value >> llvm::countr_zero(static_cast<uint32_t>(mask))) & \
159159
(((1 << llvm::popcount(static_cast<uint32_t>(mask)))) - 1))
160160

161161
// constructor

llvm/include/llvm/ADT/APInt.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ class [[nodiscard]] APInt {
15521552
unsigned countLeadingZeros() const {
15531553
if (isSingleWord()) {
15541554
unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth;
1555-
return llvm::countLeadingZeros(U.VAL) - unusedBits;
1555+
return llvm::countl_zero(U.VAL) - unusedBits;
15561556
}
15571557
return countLeadingZerosSlowCase();
15581558
}
@@ -1569,7 +1569,7 @@ class [[nodiscard]] APInt {
15691569
if (isSingleWord()) {
15701570
if (LLVM_UNLIKELY(BitWidth == 0))
15711571
return 0;
1572-
return llvm::countLeadingOnes(U.VAL << (APINT_BITS_PER_WORD - BitWidth));
1572+
return llvm::countl_one(U.VAL << (APINT_BITS_PER_WORD - BitWidth));
15731573
}
15741574
return countLeadingOnesSlowCase();
15751575
}
@@ -1590,7 +1590,7 @@ class [[nodiscard]] APInt {
15901590
/// zeros from the least significant bit to the first one bit.
15911591
unsigned countTrailingZeros() const {
15921592
if (isSingleWord()) {
1593-
unsigned TrailingZeros = llvm::countTrailingZeros(U.VAL);
1593+
unsigned TrailingZeros = llvm::countr_zero(U.VAL);
15941594
return (TrailingZeros > BitWidth ? BitWidth : TrailingZeros);
15951595
}
15961596
return countTrailingZerosSlowCase();
@@ -1606,7 +1606,7 @@ class [[nodiscard]] APInt {
16061606
/// of ones from the least significant bit to the first zero bit.
16071607
unsigned countTrailingOnes() const {
16081608
if (isSingleWord())
1609-
return llvm::countTrailingOnes(U.VAL);
1609+
return llvm::countr_one(U.VAL);
16101610
return countTrailingOnesSlowCase();
16111611
}
16121612

llvm/include/llvm/ADT/BitVector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class BitVector {
213213
Copy &= maskTrailingOnes<BitWord>(LastBit + 1);
214214
}
215215
if (Copy != 0)
216-
return i * BITWORD_SIZE + countTrailingZeros(Copy);
216+
return i * BITWORD_SIZE + llvm::countr_zero(Copy);
217217
}
218218
return -1;
219219
}
@@ -243,7 +243,7 @@ class BitVector {
243243
}
244244

245245
if (Copy != 0)
246-
return (CurrentWord + 1) * BITWORD_SIZE - countLeadingZeros(Copy) - 1;
246+
return (CurrentWord + 1) * BITWORD_SIZE - llvm::countl_zero(Copy) - 1;
247247
}
248248

249249
return -1;
@@ -281,7 +281,7 @@ class BitVector {
281281

282282
if (Copy != ~BitWord(0)) {
283283
unsigned Result =
284-
(CurrentWord + 1) * BITWORD_SIZE - countLeadingOnes(Copy) - 1;
284+
(CurrentWord + 1) * BITWORD_SIZE - llvm::countl_one(Copy) - 1;
285285
return Result < Size ? Result : -1;
286286
}
287287
}
@@ -763,7 +763,7 @@ class BitVector {
763763
}
764764

765765
int next_unset_in_word(int WordIndex, BitWord Word) const {
766-
unsigned Result = WordIndex * BITWORD_SIZE + countTrailingOnes(Word);
766+
unsigned Result = WordIndex * BITWORD_SIZE + llvm::countr_one(Word);
767767
return Result < size() ? Result : -1;
768768
}
769769

llvm/include/llvm/ADT/SmallBitVector.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class SmallBitVector {
232232
uintptr_t Bits = getSmallBits();
233233
if (Bits == 0)
234234
return -1;
235-
return countTrailingZeros(Bits);
235+
return llvm::countr_zero(Bits);
236236
}
237237
return getPointer()->find_first();
238238
}
@@ -242,7 +242,7 @@ class SmallBitVector {
242242
uintptr_t Bits = getSmallBits();
243243
if (Bits == 0)
244244
return -1;
245-
return NumBaseBits - countLeadingZeros(Bits) - 1;
245+
return NumBaseBits - llvm::countl_zero(Bits) - 1;
246246
}
247247
return getPointer()->find_last();
248248
}
@@ -254,7 +254,7 @@ class SmallBitVector {
254254
return -1;
255255

256256
uintptr_t Bits = getSmallBits();
257-
return countTrailingOnes(Bits);
257+
return llvm::countr_one(Bits);
258258
}
259259
return getPointer()->find_first_unset();
260260
}
@@ -267,7 +267,7 @@ class SmallBitVector {
267267
uintptr_t Bits = getSmallBits();
268268
// Set unused bits.
269269
Bits |= ~uintptr_t(0) << getSmallSize();
270-
return NumBaseBits - countLeadingOnes(Bits) - 1;
270+
return NumBaseBits - llvm::countl_one(Bits) - 1;
271271
}
272272
return getPointer()->find_last_unset();
273273
}
@@ -281,7 +281,7 @@ class SmallBitVector {
281281
Bits &= ~uintptr_t(0) << (Prev + 1);
282282
if (Bits == 0 || Prev + 1 >= getSmallSize())
283283
return -1;
284-
return countTrailingZeros(Bits);
284+
return llvm::countr_zero(Bits);
285285
}
286286
return getPointer()->find_next(Prev);
287287
}
@@ -298,7 +298,7 @@ class SmallBitVector {
298298

299299
if (Bits == ~uintptr_t(0) || Prev + 1 >= getSmallSize())
300300
return -1;
301-
return countTrailingOnes(Bits);
301+
return llvm::countr_one(Bits);
302302
}
303303
return getPointer()->find_next_unset(Prev);
304304
}
@@ -316,7 +316,7 @@ class SmallBitVector {
316316
if (Bits == 0)
317317
return -1;
318318

319-
return NumBaseBits - countLeadingZeros(Bits) - 1;
319+
return NumBaseBits - llvm::countl_zero(Bits) - 1;
320320
}
321321
return getPointer()->find_prev(PriorTo);
322322
}

llvm/include/llvm/ADT/SparseBitVector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
128128
int find_first() const {
129129
for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i)
130130
if (Bits[i] != 0)
131-
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
131+
return i * BITWORD_SIZE + llvm::countr_zero(Bits[i]);
132132
llvm_unreachable("Illegal empty element");
133133
}
134134

@@ -138,7 +138,7 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
138138
unsigned Idx = BITWORDS_PER_ELEMENT - I - 1;
139139
if (Bits[Idx] != 0)
140140
return Idx * BITWORD_SIZE + BITWORD_SIZE -
141-
countLeadingZeros(Bits[Idx]) - 1;
141+
llvm::countl_zero(Bits[Idx]) - 1;
142142
}
143143
llvm_unreachable("Illegal empty element");
144144
}
@@ -159,12 +159,12 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
159159
Copy &= ~0UL << BitPos;
160160

161161
if (Copy != 0)
162-
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
162+
return WordPos * BITWORD_SIZE + llvm::countr_zero(Copy);
163163

164164
// Check subsequent words.
165165
for (unsigned i = WordPos+1; i < BITWORDS_PER_ELEMENT; ++i)
166166
if (Bits[i] != 0)
167-
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
167+
return i * BITWORD_SIZE + llvm::countr_zero(Bits[i]);
168168
return -1;
169169
}
170170

llvm/include/llvm/CodeGen/ExecutionDomainFix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct DomainValue {
102102

103103
/// First domain available.
104104
unsigned getFirstDomain() const {
105-
return countTrailingZeros(AvailableDomains);
105+
return llvm::countr_zero(AvailableDomains);
106106
}
107107

108108
/// Clear this DomainValue and point to next which has all its data.

llvm/include/llvm/CodeGen/TargetRegisterInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ class BitMaskClassIterator {
12551255
// Otherwise look for the first bit set from the right
12561256
// (representation of the class ID is big endian).
12571257
// See getSubClassMask for more details on the representation.
1258-
unsigned Offset = countTrailingZeros(CurrentChunk);
1258+
unsigned Offset = llvm::countr_zero(CurrentChunk);
12591259
// Add the Offset to the adjusted base number of this chunk: Idx.
12601260
// This is the ID of the register class.
12611261
ID = Idx + Offset;

llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Block : public Addressable {
163163
assert(AlignmentOffset <= MaxAlignmentOffset &&
164164
"Alignment offset exceeds maximum");
165165
ContentMutable = false;
166-
P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
166+
P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
167167
this->AlignmentOffset = AlignmentOffset;
168168
}
169169

@@ -180,7 +180,7 @@ class Block : public Addressable {
180180
assert(AlignmentOffset <= MaxAlignmentOffset &&
181181
"Alignment offset exceeds maximum");
182182
ContentMutable = false;
183-
P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
183+
P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
184184
this->AlignmentOffset = AlignmentOffset;
185185
}
186186

@@ -199,7 +199,7 @@ class Block : public Addressable {
199199
assert(AlignmentOffset <= MaxAlignmentOffset &&
200200
"Alignment offset exceeds maximum");
201201
ContentMutable = true;
202-
P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
202+
P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
203203
this->AlignmentOffset = AlignmentOffset;
204204
}
205205

@@ -289,7 +289,7 @@ class Block : public Addressable {
289289
/// Set the alignment for this content.
290290
void setAlignment(uint64_t Alignment) {
291291
assert(isPowerOf2_64(Alignment) && "Alignment must be a power of two");
292-
P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
292+
P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
293293
}
294294

295295
/// Get the alignment offset for this content.

0 commit comments

Comments
 (0)