Use llvm::count{lr}_{zero,one} (NFC)
This commit is contained in:
parent
a536d3e40e
commit
55e2cd1609
@ -72,7 +72,7 @@ static bool iterateCodepoints(llvm::StringRef U8, const Callback &CB) {
|
||||
continue;
|
||||
}
|
||||
// This convenient property of UTF-8 holds for all non-ASCII characters.
|
||||
size_t UTF8Length = llvm::countLeadingOnes(C);
|
||||
size_t UTF8Length = llvm::countl_one(C);
|
||||
// 0xxx is ASCII, handled above. 10xxx is a trailing byte, invalid here.
|
||||
// 11111xxx is not valid UTF-8 at all, maybe some ISO-8859-*.
|
||||
if (LLVM_UNLIKELY(UTF8Length < 2 || UTF8Length > 4)) {
|
||||
|
||||
@ -243,10 +243,10 @@ namespace clang {
|
||||
};
|
||||
|
||||
SVETypeFlags(uint64_t F) : Flags(F) {
|
||||
EltTypeShift = llvm::countTrailingZeros(EltTypeMask);
|
||||
MemEltTypeShift = llvm::countTrailingZeros(MemEltTypeMask);
|
||||
MergeTypeShift = llvm::countTrailingZeros(MergeTypeMask);
|
||||
SplatOperandMaskShift = llvm::countTrailingZeros(SplatOperandMask);
|
||||
EltTypeShift = llvm::countr_zero(EltTypeMask);
|
||||
MemEltTypeShift = llvm::countr_zero(MemEltTypeMask);
|
||||
MergeTypeShift = llvm::countr_zero(MergeTypeMask);
|
||||
SplatOperandMaskShift = llvm::countr_zero(SplatOperandMask);
|
||||
}
|
||||
|
||||
EltType getEltType() const {
|
||||
|
||||
@ -742,7 +742,7 @@ public:
|
||||
/// Set the maximum vector width in the arguments.
|
||||
void setMaxVectorWidth(unsigned Width) {
|
||||
assert(llvm::isPowerOf2_32(Width) && "Expected power of 2 vector");
|
||||
MaxVectorWidth = llvm::countTrailingZeros(Width) + 1;
|
||||
MaxVectorWidth = llvm::countr_zero(Width) + 1;
|
||||
}
|
||||
|
||||
void Profile(llvm::FoldingSetNodeID &ID) {
|
||||
|
||||
@ -127,9 +127,7 @@ public:
|
||||
return Compare(V, RHS.V);
|
||||
}
|
||||
|
||||
unsigned countLeadingZeros() const {
|
||||
return llvm::countLeadingZeros<ReprT>(V);
|
||||
}
|
||||
unsigned countLeadingZeros() const { return llvm::countl_zero<ReprT>(V); }
|
||||
|
||||
Integral truncate(unsigned TruncBits) const {
|
||||
if (TruncBits >= Bits)
|
||||
|
||||
@ -1302,8 +1302,7 @@ LineOffsetMapping LineOffsetMapping::get(llvm::MemoryBufferRef Buffer,
|
||||
// in [\n, \r + 1 [
|
||||
|
||||
// Scan for the next newline - it's very likely there's one.
|
||||
unsigned N =
|
||||
llvm::countTrailingZeros(Mask) - 7; // -7 because 0x80 is the marker
|
||||
unsigned N = llvm::countr_zero(Mask) - 7; // -7 because 0x80 is the marker
|
||||
Word >>= N;
|
||||
Buf += N / 8 + 1;
|
||||
unsigned char Byte = Word;
|
||||
|
||||
@ -2785,7 +2785,7 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr,
|
||||
// Adjust the pointer to point directly after the first slash. It's
|
||||
// not necessary to set C here, it will be overwritten at the end of
|
||||
// the outer loop.
|
||||
CurPtr += llvm::countTrailingZeros<unsigned>(cmp) + 1;
|
||||
CurPtr += llvm::countr_zero<unsigned>(cmp) + 1;
|
||||
goto FoundSlash;
|
||||
}
|
||||
CurPtr += 16;
|
||||
|
||||
@ -273,7 +273,7 @@ public:
|
||||
SmallVector<const FieldDecl *, 20> OptimalFieldsOrder;
|
||||
while (!Fields.empty()) {
|
||||
unsigned TrailingZeros =
|
||||
llvm::countTrailingZeros((unsigned long long)NewOffset.getQuantity());
|
||||
llvm::countr_zero((unsigned long long)NewOffset.getQuantity());
|
||||
// If NewOffset is zero, then countTrailingZeros will be 64. Shifting
|
||||
// 64 will overflow our unsigned long long. Shifting 63 will turn
|
||||
// our long long (and CharUnits internal type) negative. So shift 62.
|
||||
|
||||
@ -298,7 +298,7 @@ public:
|
||||
auto It = FlagTypes.find(MaskName);
|
||||
if (It != FlagTypes.end()) {
|
||||
uint64_t Mask = It->getValue();
|
||||
unsigned Shift = llvm::countTrailingZeros(Mask);
|
||||
unsigned Shift = llvm::countr_zero(Mask);
|
||||
return (V << Shift) & Mask;
|
||||
}
|
||||
llvm_unreachable("Unsupported flag");
|
||||
|
||||
@ -432,7 +432,7 @@ static std::pair<uint32_t, uint32_t> getRemAndLZForGroup(unsigned group,
|
||||
uint32_t val) {
|
||||
uint32_t rem, lz;
|
||||
do {
|
||||
lz = llvm::countLeadingZeros(val) & ~1;
|
||||
lz = llvm::countl_zero(val) & ~1;
|
||||
rem = val;
|
||||
if (lz == 32) // implies rem == 0
|
||||
break;
|
||||
|
||||
@ -1317,7 +1317,7 @@ static uint64_t getAlignment(ArrayRef<typename ELFT::Shdr> sections,
|
||||
const typename ELFT::Sym &sym) {
|
||||
uint64_t ret = UINT64_MAX;
|
||||
if (sym.st_value)
|
||||
ret = 1ULL << countTrailingZeros((uint64_t)sym.st_value);
|
||||
ret = 1ULL << llvm::countr_zero((uint64_t)sym.st_value);
|
||||
if (0 < sym.st_shndx && sym.st_shndx < sections.size())
|
||||
ret = std::min<uint64_t>(ret, sections[sym.st_shndx].sh_addralign);
|
||||
return (ret > UINT32_MAX) ? 0 : ret;
|
||||
|
||||
@ -2782,7 +2782,7 @@ createSymbols(
|
||||
// A sharded map to uniquify symbols by name.
|
||||
auto map =
|
||||
std::make_unique<DenseMap<CachedHashStringRef, size_t>[]>(numShards);
|
||||
size_t shift = 32 - countTrailingZeros(numShards);
|
||||
size_t shift = 32 - llvm::countr_zero(numShards);
|
||||
|
||||
// Instantiate GdbSymbols while uniqufying them by name.
|
||||
auto symbols = std::make_unique<SmallVector<GdbSymbol, 0>[]>(numShards);
|
||||
|
||||
@ -970,7 +970,7 @@ private:
|
||||
// hash collisions.
|
||||
size_t getShardId(uint32_t hash) {
|
||||
assert((hash >> 31) == 0);
|
||||
return hash >> (31 - llvm::countTrailingZeros(numShards));
|
||||
return hash >> (31 - llvm::countr_zero(numShards));
|
||||
}
|
||||
|
||||
// Section size
|
||||
|
||||
@ -1111,7 +1111,7 @@ template <class ELFT> void Writer<ELFT>::setReservedSymbolSections() {
|
||||
static int getRankProximity(OutputSection *a, SectionCommand *b) {
|
||||
auto *osd = dyn_cast<OutputDesc>(b);
|
||||
return (osd && osd->osec.hasInputSections)
|
||||
? countLeadingZeros(a->sortRank ^ osd->osec.sortRank)
|
||||
? llvm::countl_zero(a->sortRank ^ osd->osec.sortRank)
|
||||
: -1;
|
||||
}
|
||||
|
||||
|
||||
@ -1641,7 +1641,7 @@ void CStringSection::finalizeContents() {
|
||||
// See comment above DeduplicatedCStringSection for how alignment is
|
||||
// handled.
|
||||
uint32_t pieceAlign = 1
|
||||
<< countTrailingZeros(isec->align | piece.inSecOff);
|
||||
<< llvm::countr_zero(isec->align | piece.inSecOff);
|
||||
offset = alignTo(offset, pieceAlign);
|
||||
piece.outSecOff = offset;
|
||||
isec->isFinal = true;
|
||||
@ -1698,7 +1698,7 @@ void DeduplicatedCStringSection::finalizeContents() {
|
||||
continue;
|
||||
auto s = isec->getCachedHashStringRef(i);
|
||||
assert(isec->align != 0);
|
||||
uint8_t trailingZeros = countTrailingZeros(isec->align | piece.inSecOff);
|
||||
uint8_t trailingZeros = llvm::countr_zero(isec->align | piece.inSecOff);
|
||||
auto it = stringOffsetMap.insert(
|
||||
std::make_pair(s, StringOffset(trailingZeros)));
|
||||
if (!it.second && it.first->second.trailingZeros < trailingZeros)
|
||||
|
||||
@ -405,7 +405,7 @@ void UnwindInfoSectionImpl::encodePersonalities() {
|
||||
personalityIndex = personalities.size();
|
||||
}
|
||||
cu.encoding |=
|
||||
personalityIndex << countTrailingZeros(
|
||||
personalityIndex << llvm::countr_zero(
|
||||
static_cast<compact_unwind_encoding_t>(UNWIND_PERSONALITY_MASK));
|
||||
}
|
||||
if (personalities.size() > 3)
|
||||
|
||||
@ -605,7 +605,7 @@ static std::optional<RegisterInfo> GetARMDWARFRegisterInfo(unsigned reg_num) {
|
||||
// Valid return values are {1, 2, 3, 4}, with 0 signifying an error condition.
|
||||
static uint32_t CountITSize(uint32_t ITMask) {
|
||||
// First count the trailing zeros of the IT mask.
|
||||
uint32_t TZ = llvm::countTrailingZeros(ITMask);
|
||||
uint32_t TZ = llvm::countr_zero(ITMask);
|
||||
if (TZ > 3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ FLAGS_ANONYMOUS_ENUM(){
|
||||
#endif
|
||||
|
||||
#define EXTRACT_BITS(value, mask) \
|
||||
((value >> llvm::countTrailingZeros(static_cast<uint32_t>(mask))) & \
|
||||
((value >> llvm::countr_zero(static_cast<uint32_t>(mask))) & \
|
||||
(((1 << llvm::popcount(static_cast<uint32_t>(mask)))) - 1))
|
||||
|
||||
// constructor
|
||||
|
||||
@ -1552,7 +1552,7 @@ public:
|
||||
unsigned countLeadingZeros() const {
|
||||
if (isSingleWord()) {
|
||||
unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth;
|
||||
return llvm::countLeadingZeros(U.VAL) - unusedBits;
|
||||
return llvm::countl_zero(U.VAL) - unusedBits;
|
||||
}
|
||||
return countLeadingZerosSlowCase();
|
||||
}
|
||||
@ -1569,7 +1569,7 @@ public:
|
||||
if (isSingleWord()) {
|
||||
if (LLVM_UNLIKELY(BitWidth == 0))
|
||||
return 0;
|
||||
return llvm::countLeadingOnes(U.VAL << (APINT_BITS_PER_WORD - BitWidth));
|
||||
return llvm::countl_one(U.VAL << (APINT_BITS_PER_WORD - BitWidth));
|
||||
}
|
||||
return countLeadingOnesSlowCase();
|
||||
}
|
||||
@ -1590,7 +1590,7 @@ public:
|
||||
/// zeros from the least significant bit to the first one bit.
|
||||
unsigned countTrailingZeros() const {
|
||||
if (isSingleWord()) {
|
||||
unsigned TrailingZeros = llvm::countTrailingZeros(U.VAL);
|
||||
unsigned TrailingZeros = llvm::countr_zero(U.VAL);
|
||||
return (TrailingZeros > BitWidth ? BitWidth : TrailingZeros);
|
||||
}
|
||||
return countTrailingZerosSlowCase();
|
||||
@ -1606,7 +1606,7 @@ public:
|
||||
/// of ones from the least significant bit to the first zero bit.
|
||||
unsigned countTrailingOnes() const {
|
||||
if (isSingleWord())
|
||||
return llvm::countTrailingOnes(U.VAL);
|
||||
return llvm::countr_one(U.VAL);
|
||||
return countTrailingOnesSlowCase();
|
||||
}
|
||||
|
||||
|
||||
@ -213,7 +213,7 @@ public:
|
||||
Copy &= maskTrailingOnes<BitWord>(LastBit + 1);
|
||||
}
|
||||
if (Copy != 0)
|
||||
return i * BITWORD_SIZE + countTrailingZeros(Copy);
|
||||
return i * BITWORD_SIZE + llvm::countr_zero(Copy);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -243,7 +243,7 @@ public:
|
||||
}
|
||||
|
||||
if (Copy != 0)
|
||||
return (CurrentWord + 1) * BITWORD_SIZE - countLeadingZeros(Copy) - 1;
|
||||
return (CurrentWord + 1) * BITWORD_SIZE - llvm::countl_zero(Copy) - 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -281,7 +281,7 @@ public:
|
||||
|
||||
if (Copy != ~BitWord(0)) {
|
||||
unsigned Result =
|
||||
(CurrentWord + 1) * BITWORD_SIZE - countLeadingOnes(Copy) - 1;
|
||||
(CurrentWord + 1) * BITWORD_SIZE - llvm::countl_one(Copy) - 1;
|
||||
return Result < Size ? Result : -1;
|
||||
}
|
||||
}
|
||||
@ -763,7 +763,7 @@ private:
|
||||
}
|
||||
|
||||
int next_unset_in_word(int WordIndex, BitWord Word) const {
|
||||
unsigned Result = WordIndex * BITWORD_SIZE + countTrailingOnes(Word);
|
||||
unsigned Result = WordIndex * BITWORD_SIZE + llvm::countr_one(Word);
|
||||
return Result < size() ? Result : -1;
|
||||
}
|
||||
|
||||
|
||||
@ -232,7 +232,7 @@ public:
|
||||
uintptr_t Bits = getSmallBits();
|
||||
if (Bits == 0)
|
||||
return -1;
|
||||
return countTrailingZeros(Bits);
|
||||
return llvm::countr_zero(Bits);
|
||||
}
|
||||
return getPointer()->find_first();
|
||||
}
|
||||
@ -242,7 +242,7 @@ public:
|
||||
uintptr_t Bits = getSmallBits();
|
||||
if (Bits == 0)
|
||||
return -1;
|
||||
return NumBaseBits - countLeadingZeros(Bits) - 1;
|
||||
return NumBaseBits - llvm::countl_zero(Bits) - 1;
|
||||
}
|
||||
return getPointer()->find_last();
|
||||
}
|
||||
@ -254,7 +254,7 @@ public:
|
||||
return -1;
|
||||
|
||||
uintptr_t Bits = getSmallBits();
|
||||
return countTrailingOnes(Bits);
|
||||
return llvm::countr_one(Bits);
|
||||
}
|
||||
return getPointer()->find_first_unset();
|
||||
}
|
||||
@ -267,7 +267,7 @@ public:
|
||||
uintptr_t Bits = getSmallBits();
|
||||
// Set unused bits.
|
||||
Bits |= ~uintptr_t(0) << getSmallSize();
|
||||
return NumBaseBits - countLeadingOnes(Bits) - 1;
|
||||
return NumBaseBits - llvm::countl_one(Bits) - 1;
|
||||
}
|
||||
return getPointer()->find_last_unset();
|
||||
}
|
||||
@ -281,7 +281,7 @@ public:
|
||||
Bits &= ~uintptr_t(0) << (Prev + 1);
|
||||
if (Bits == 0 || Prev + 1 >= getSmallSize())
|
||||
return -1;
|
||||
return countTrailingZeros(Bits);
|
||||
return llvm::countr_zero(Bits);
|
||||
}
|
||||
return getPointer()->find_next(Prev);
|
||||
}
|
||||
@ -298,7 +298,7 @@ public:
|
||||
|
||||
if (Bits == ~uintptr_t(0) || Prev + 1 >= getSmallSize())
|
||||
return -1;
|
||||
return countTrailingOnes(Bits);
|
||||
return llvm::countr_one(Bits);
|
||||
}
|
||||
return getPointer()->find_next_unset(Prev);
|
||||
}
|
||||
@ -316,7 +316,7 @@ public:
|
||||
if (Bits == 0)
|
||||
return -1;
|
||||
|
||||
return NumBaseBits - countLeadingZeros(Bits) - 1;
|
||||
return NumBaseBits - llvm::countl_zero(Bits) - 1;
|
||||
}
|
||||
return getPointer()->find_prev(PriorTo);
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ public:
|
||||
int find_first() const {
|
||||
for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i)
|
||||
if (Bits[i] != 0)
|
||||
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
|
||||
return i * BITWORD_SIZE + llvm::countr_zero(Bits[i]);
|
||||
llvm_unreachable("Illegal empty element");
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ public:
|
||||
unsigned Idx = BITWORDS_PER_ELEMENT - I - 1;
|
||||
if (Bits[Idx] != 0)
|
||||
return Idx * BITWORD_SIZE + BITWORD_SIZE -
|
||||
countLeadingZeros(Bits[Idx]) - 1;
|
||||
llvm::countl_zero(Bits[Idx]) - 1;
|
||||
}
|
||||
llvm_unreachable("Illegal empty element");
|
||||
}
|
||||
@ -159,12 +159,12 @@ public:
|
||||
Copy &= ~0UL << BitPos;
|
||||
|
||||
if (Copy != 0)
|
||||
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
|
||||
return WordPos * BITWORD_SIZE + llvm::countr_zero(Copy);
|
||||
|
||||
// Check subsequent words.
|
||||
for (unsigned i = WordPos+1; i < BITWORDS_PER_ELEMENT; ++i)
|
||||
if (Bits[i] != 0)
|
||||
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
|
||||
return i * BITWORD_SIZE + llvm::countr_zero(Bits[i]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ struct DomainValue {
|
||||
|
||||
/// First domain available.
|
||||
unsigned getFirstDomain() const {
|
||||
return countTrailingZeros(AvailableDomains);
|
||||
return llvm::countr_zero(AvailableDomains);
|
||||
}
|
||||
|
||||
/// Clear this DomainValue and point to next which has all its data.
|
||||
|
||||
@ -1255,7 +1255,7 @@ class BitMaskClassIterator {
|
||||
// Otherwise look for the first bit set from the right
|
||||
// (representation of the class ID is big endian).
|
||||
// See getSubClassMask for more details on the representation.
|
||||
unsigned Offset = countTrailingZeros(CurrentChunk);
|
||||
unsigned Offset = llvm::countr_zero(CurrentChunk);
|
||||
// Add the Offset to the adjusted base number of this chunk: Idx.
|
||||
// This is the ID of the register class.
|
||||
ID = Idx + Offset;
|
||||
|
||||
@ -163,7 +163,7 @@ private:
|
||||
assert(AlignmentOffset <= MaxAlignmentOffset &&
|
||||
"Alignment offset exceeds maximum");
|
||||
ContentMutable = false;
|
||||
P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
|
||||
P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
|
||||
this->AlignmentOffset = AlignmentOffset;
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ private:
|
||||
assert(AlignmentOffset <= MaxAlignmentOffset &&
|
||||
"Alignment offset exceeds maximum");
|
||||
ContentMutable = false;
|
||||
P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
|
||||
P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
|
||||
this->AlignmentOffset = AlignmentOffset;
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ private:
|
||||
assert(AlignmentOffset <= MaxAlignmentOffset &&
|
||||
"Alignment offset exceeds maximum");
|
||||
ContentMutable = true;
|
||||
P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
|
||||
P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
|
||||
this->AlignmentOffset = AlignmentOffset;
|
||||
}
|
||||
|
||||
@ -289,7 +289,7 @@ public:
|
||||
/// Set the alignment for this content.
|
||||
void setAlignment(uint64_t Alignment) {
|
||||
assert(isPowerOf2_64(Alignment) && "Alignment must be a power of two");
|
||||
P2Align = Alignment ? countTrailingZeros(Alignment) : 0;
|
||||
P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
|
||||
}
|
||||
|
||||
/// Get the alignment offset for this content.
|
||||
|
||||
@ -85,7 +85,7 @@ inline std::pair<DigitsT, int16_t> getAdjusted(uint64_t Digits,
|
||||
return std::make_pair(Digits, Scale);
|
||||
|
||||
// Shift right and round.
|
||||
int Shift = 64 - Width - countLeadingZeros(Digits);
|
||||
int Shift = 64 - Width - llvm::countl_zero(Digits);
|
||||
return getRounded<DigitsT>(Digits >> Shift, Scale + Shift,
|
||||
Digits & (UINT64_C(1) << (Shift - 1)));
|
||||
}
|
||||
@ -305,7 +305,7 @@ int16_t matchScales(DigitsT &LDigits, int16_t &LScale, DigitsT &RDigits,
|
||||
}
|
||||
|
||||
// Shift LDigits left as much as possible, then shift RDigits right.
|
||||
int32_t ShiftL = std::min<int32_t>(countLeadingZeros(LDigits), ScaleDiff);
|
||||
int32_t ShiftL = std::min<int32_t>(llvm::countl_zero(LDigits), ScaleDiff);
|
||||
assert(ShiftL < getWidth<DigitsT>() && "can't shift more than width");
|
||||
|
||||
int32_t ShiftR = ScaleDiff - ShiftL;
|
||||
@ -426,8 +426,8 @@ public:
|
||||
unsigned Precision);
|
||||
static std::string toString(uint64_t D, int16_t E, int Width,
|
||||
unsigned Precision);
|
||||
static int countLeadingZeros32(uint32_t N) { return countLeadingZeros(N); }
|
||||
static int countLeadingZeros64(uint64_t N) { return countLeadingZeros(N); }
|
||||
static int countLeadingZeros32(uint32_t N) { return llvm::countl_zero(N); }
|
||||
static int countLeadingZeros64(uint64_t N) { return llvm::countl_zero(N); }
|
||||
static uint64_t getHalf(uint64_t N) { return (N >> 1) + (N & 1); }
|
||||
|
||||
static std::pair<uint64_t, bool> splitSigned(int64_t N) {
|
||||
|
||||
@ -256,7 +256,7 @@ void Distribution::normalize() {
|
||||
if (DidOverflow)
|
||||
Shift = 33;
|
||||
else if (Total > UINT32_MAX)
|
||||
Shift = 33 - countLeadingZeros(Total);
|
||||
Shift = 33 - llvm::countl_zero(Total);
|
||||
|
||||
// Early exit if nothing needs to be scaled.
|
||||
if (!Shift) {
|
||||
|
||||
@ -1376,7 +1376,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
|
||||
if (IndexTypeSize.isScalable()) {
|
||||
// For scalable types the only thing we know about sizeof is
|
||||
// that this is a multiple of the minimum size.
|
||||
ScalingFactor.Zero.setLowBits(countTrailingZeros(TypeSizeInBytes));
|
||||
ScalingFactor.Zero.setLowBits(llvm::countr_zero(TypeSizeInBytes));
|
||||
} else if (IndexBits.isConstant()) {
|
||||
APInt IndexConst = IndexBits.getConstant();
|
||||
APInt ScalingFactor(IndexBitWidth, TypeSizeInBytes);
|
||||
|
||||
@ -771,7 +771,7 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
|
||||
LeaderDemandedBits |= DBits[M];
|
||||
|
||||
uint64_t MinBW = (sizeof(LeaderDemandedBits) * 8) -
|
||||
llvm::countLeadingZeros(LeaderDemandedBits);
|
||||
llvm::countl_zero(LeaderDemandedBits);
|
||||
// Round up to a power of 2
|
||||
if (!isPowerOf2_64((uint64_t)MinBW))
|
||||
MinBW = NextPowerOf2(MinBW);
|
||||
|
||||
@ -318,7 +318,7 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
|
||||
|
||||
// If the collapsed operands force a single domain, propagate the collapse.
|
||||
if (isPowerOf2_32(available)) {
|
||||
unsigned domain = countTrailingZeros(available);
|
||||
unsigned domain = llvm::countr_zero(available);
|
||||
TII->setExecutionDomain(*mi, domain);
|
||||
visitHardInstr(mi, domain);
|
||||
return;
|
||||
|
||||
@ -4496,7 +4496,7 @@ bool CombinerHelper::matchBitfieldExtractFromShrAnd(
|
||||
|
||||
// Calculate start position and width of the extract.
|
||||
const int64_t Pos = ShrAmt;
|
||||
const int64_t Width = countTrailingOnes(UMask) - ShrAmt;
|
||||
const int64_t Width = llvm::countr_one(UMask) - ShrAmt;
|
||||
|
||||
// It's preferable to keep the shift, rather than form G_SBFX.
|
||||
// TODO: remove the G_AND via demanded bits analysis.
|
||||
|
||||
@ -1074,14 +1074,14 @@ void IRTranslator::emitBitTestCase(SwitchCG::BitTestBlock &BB,
|
||||
// Testing for a single bit; just compare the shift count with what it
|
||||
// would need to be to shift a 1 bit in that position.
|
||||
auto MaskTrailingZeros =
|
||||
MIB.buildConstant(SwitchTy, countTrailingZeros(B.Mask));
|
||||
MIB.buildConstant(SwitchTy, llvm::countr_zero(B.Mask));
|
||||
Cmp =
|
||||
MIB.buildICmp(ICmpInst::ICMP_EQ, LLT::scalar(1), Reg, MaskTrailingZeros)
|
||||
.getReg(0);
|
||||
} else if (PopCount == BB.Range) {
|
||||
// There is only one zero bit in the range, test for it directly.
|
||||
auto MaskTrailingOnes =
|
||||
MIB.buildConstant(SwitchTy, countTrailingOnes(B.Mask));
|
||||
MIB.buildConstant(SwitchTy, llvm::countr_one(B.Mask));
|
||||
Cmp = MIB.buildICmp(CmpInst::ICMP_NE, LLT::scalar(1), Reg, MaskTrailingOnes)
|
||||
.getReg(0);
|
||||
} else {
|
||||
|
||||
@ -18125,14 +18125,14 @@ CheckForMaskedLoad(SDValue V, SDValue Ptr, SDValue Chain) {
|
||||
// 0 and the bits being kept are 1. Use getSExtValue so that leading bits
|
||||
// follow the sign bit for uniformity.
|
||||
uint64_t NotMask = ~cast<ConstantSDNode>(V->getOperand(1))->getSExtValue();
|
||||
unsigned NotMaskLZ = countLeadingZeros(NotMask);
|
||||
unsigned NotMaskLZ = llvm::countl_zero(NotMask);
|
||||
if (NotMaskLZ & 7) return Result; // Must be multiple of a byte.
|
||||
unsigned NotMaskTZ = countTrailingZeros(NotMask);
|
||||
unsigned NotMaskTZ = llvm::countr_zero(NotMask);
|
||||
if (NotMaskTZ & 7) return Result; // Must be multiple of a byte.
|
||||
if (NotMaskLZ == 64) return Result; // All zero mask.
|
||||
|
||||
// See if we have a continuous run of bits. If so, we have 0*1+0*
|
||||
if (countTrailingOnes(NotMask >> NotMaskTZ) + NotMaskTZ + NotMaskLZ != 64)
|
||||
if (llvm::countr_one(NotMask >> NotMaskTZ) + NotMaskTZ + NotMaskLZ != 64)
|
||||
return Result;
|
||||
|
||||
// Adjust NotMaskLZ down to be from the actual size of the int instead of i64.
|
||||
|
||||
@ -2901,14 +2901,13 @@ void SelectionDAGBuilder::visitBitTestCase(BitTestBlock &BB,
|
||||
// would need to be to shift a 1 bit in that position.
|
||||
Cmp = DAG.getSetCC(
|
||||
dl, TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT),
|
||||
ShiftOp, DAG.getConstant(countTrailingZeros(B.Mask), dl, VT),
|
||||
ShiftOp, DAG.getConstant(llvm::countr_zero(B.Mask), dl, VT),
|
||||
ISD::SETEQ);
|
||||
} else if (PopCount == BB.Range) {
|
||||
// There is only one zero bit in the range, test for it directly.
|
||||
Cmp = DAG.getSetCC(
|
||||
dl, TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT),
|
||||
ShiftOp, DAG.getConstant(countTrailingOnes(B.Mask), dl, VT),
|
||||
ISD::SETNE);
|
||||
ShiftOp, DAG.getConstant(llvm::countr_one(B.Mask), dl, VT), ISD::SETNE);
|
||||
} else {
|
||||
// Make desired shift
|
||||
SDValue SwitchVal = DAG.getNode(ISD::SHL, dl, VT,
|
||||
|
||||
@ -281,7 +281,7 @@ const TargetRegisterClass *firstCommonClass(const uint32_t *A,
|
||||
const TargetRegisterInfo *TRI) {
|
||||
for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; I += 32)
|
||||
if (unsigned Common = *A++ & *B++)
|
||||
return TRI->getRegClass(I + countTrailingZeros(Common));
|
||||
return TRI->getRegClass(I + llvm::countr_zero(Common));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ using namespace object;
|
||||
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) {
|
||||
OS << " (";
|
||||
do {
|
||||
uint64_t Shift = countTrailingZeros(Val);
|
||||
uint64_t Shift = llvm::countr_zero(Val);
|
||||
assert(Shift < 64 && "undefined behavior");
|
||||
uint64_t Bit = 1ULL << Shift;
|
||||
auto PropName = ApplePropertyString(Bit);
|
||||
|
||||
@ -73,7 +73,7 @@ ObjectFile::createELFObjectFile(MemoryBufferRef Obj, bool InitContent) {
|
||||
std::pair<unsigned char, unsigned char> Ident =
|
||||
getElfArchType(Obj.getBuffer());
|
||||
std::size_t MaxAlignment =
|
||||
1ULL << countTrailingZeros(
|
||||
1ULL << llvm::countr_zero(
|
||||
reinterpret_cast<uintptr_t>(Obj.getBufferStart()));
|
||||
|
||||
if (MaxAlignment < 2)
|
||||
|
||||
@ -54,8 +54,8 @@ static uint32_t calculateFileAlignment(const MachOObjectFile &O) {
|
||||
}
|
||||
} else {
|
||||
P2CurrentAlignment =
|
||||
countTrailingZeros(Is64Bit ? O.getSegment64LoadCommand(LC).vmaddr
|
||||
: O.getSegmentLoadCommand(LC).vmaddr);
|
||||
llvm::countr_zero(Is64Bit ? O.getSegment64LoadCommand(LC).vmaddr
|
||||
: O.getSegmentLoadCommand(LC).vmaddr);
|
||||
}
|
||||
P2MinAlignment = std::min(P2MinAlignment, P2CurrentAlignment);
|
||||
}
|
||||
|
||||
@ -626,7 +626,7 @@ unsigned APInt::countLeadingZerosSlowCase() const {
|
||||
if (V == 0)
|
||||
Count += APINT_BITS_PER_WORD;
|
||||
else {
|
||||
Count += llvm::countLeadingZeros(V);
|
||||
Count += llvm::countl_zero(V);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -646,13 +646,13 @@ unsigned APInt::countLeadingOnesSlowCase() const {
|
||||
shift = APINT_BITS_PER_WORD - highWordBits;
|
||||
}
|
||||
int i = getNumWords() - 1;
|
||||
unsigned Count = llvm::countLeadingOnes(U.pVal[i] << shift);
|
||||
unsigned Count = llvm::countl_one(U.pVal[i] << shift);
|
||||
if (Count == highWordBits) {
|
||||
for (i--; i >= 0; --i) {
|
||||
if (U.pVal[i] == WORDTYPE_MAX)
|
||||
Count += APINT_BITS_PER_WORD;
|
||||
else {
|
||||
Count += llvm::countLeadingOnes(U.pVal[i]);
|
||||
Count += llvm::countl_one(U.pVal[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -666,7 +666,7 @@ unsigned APInt::countTrailingZerosSlowCase() const {
|
||||
for (; i < getNumWords() && U.pVal[i] == 0; ++i)
|
||||
Count += APINT_BITS_PER_WORD;
|
||||
if (i < getNumWords())
|
||||
Count += llvm::countTrailingZeros(U.pVal[i]);
|
||||
Count += llvm::countr_zero(U.pVal[i]);
|
||||
return std::min(Count, BitWidth);
|
||||
}
|
||||
|
||||
@ -676,7 +676,7 @@ unsigned APInt::countTrailingOnesSlowCase() const {
|
||||
for (; i < getNumWords() && U.pVal[i] == WORDTYPE_MAX; ++i)
|
||||
Count += APINT_BITS_PER_WORD;
|
||||
if (i < getNumWords())
|
||||
Count += llvm::countTrailingOnes(U.pVal[i]);
|
||||
Count += llvm::countr_one(U.pVal[i]);
|
||||
assert(Count <= BitWidth);
|
||||
return Count;
|
||||
}
|
||||
@ -1318,7 +1318,7 @@ static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t* r,
|
||||
// and v so that its high bits are shifted to the top of v's range without
|
||||
// overflow. Note that this can require an extra word in u so that u must
|
||||
// be of length m+n+1.
|
||||
unsigned shift = countLeadingZeros(v[n-1]);
|
||||
unsigned shift = llvm::countl_zero(v[n - 1]);
|
||||
uint32_t v_carry = 0;
|
||||
uint32_t u_carry = 0;
|
||||
if (shift) {
|
||||
|
||||
@ -44,7 +44,7 @@ std::pair<uint64_t, int16_t> ScaledNumbers::multiply64(uint64_t LHS,
|
||||
return std::make_pair(Lower, 0);
|
||||
|
||||
// Shift as little as possible to maximize precision.
|
||||
unsigned LeadingZeros = countLeadingZeros(Upper);
|
||||
unsigned LeadingZeros = llvm::countl_zero(Upper);
|
||||
int Shift = 64 - LeadingZeros;
|
||||
if (LeadingZeros)
|
||||
Upper = Upper << LeadingZeros | Lower >> Shift;
|
||||
@ -62,7 +62,7 @@ std::pair<uint32_t, int16_t> ScaledNumbers::divide32(uint32_t Dividend,
|
||||
// Use 64-bit math and canonicalize the dividend to gain precision.
|
||||
uint64_t Dividend64 = Dividend;
|
||||
int Shift = 0;
|
||||
if (int Zeros = countLeadingZeros(Dividend64)) {
|
||||
if (int Zeros = llvm::countl_zero(Dividend64)) {
|
||||
Shift -= Zeros;
|
||||
Dividend64 <<= Zeros;
|
||||
}
|
||||
@ -84,7 +84,7 @@ std::pair<uint64_t, int16_t> ScaledNumbers::divide64(uint64_t Dividend,
|
||||
|
||||
// Minimize size of divisor.
|
||||
int Shift = 0;
|
||||
if (int Zeros = countTrailingZeros(Divisor)) {
|
||||
if (int Zeros = llvm::countr_zero(Divisor)) {
|
||||
Shift -= Zeros;
|
||||
Divisor >>= Zeros;
|
||||
}
|
||||
@ -94,7 +94,7 @@ std::pair<uint64_t, int16_t> ScaledNumbers::divide64(uint64_t Dividend,
|
||||
return std::make_pair(Dividend, Shift);
|
||||
|
||||
// Maximize size of dividend.
|
||||
if (int Zeros = countLeadingZeros(Dividend)) {
|
||||
if (int Zeros = llvm::countl_zero(Dividend)) {
|
||||
Shift -= Zeros;
|
||||
Dividend <<= Zeros;
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ BitSetInfo BitSetBuilder::build() {
|
||||
|
||||
BSI.AlignLog2 = 0;
|
||||
if (Mask != 0)
|
||||
BSI.AlignLog2 = countTrailingZeros(Mask);
|
||||
BSI.AlignLog2 = llvm::countr_zero(Mask);
|
||||
|
||||
// Build the compressed bitset while normalizing the offsets against the
|
||||
// computed alignment.
|
||||
|
||||
@ -259,7 +259,7 @@ wholeprogramdevirt::findLowestOffset(ArrayRef<VirtualCallTarget> Targets,
|
||||
if (I < B.size())
|
||||
BitsUsed |= B[I];
|
||||
if (BitsUsed != 0xff)
|
||||
return (MinByte + I) * 8 + countTrailingZeros(uint8_t(~BitsUsed));
|
||||
return (MinByte + I) * 8 + llvm::countr_zero(uint8_t(~BitsUsed));
|
||||
}
|
||||
} else {
|
||||
// Find a free (Size/8) byte region in each member of Used.
|
||||
|
||||
@ -295,10 +295,10 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
|
||||
// We need to erase the highest countTrailingZeros(ElementSize) bits of Idx.
|
||||
unsigned ElementSize =
|
||||
DL.getTypeAllocSize(Init->getType()->getArrayElementType());
|
||||
auto MaskIdx = [&](Value* Idx){
|
||||
if (!GEP->isInBounds() && countTrailingZeros(ElementSize) != 0) {
|
||||
auto MaskIdx = [&](Value *Idx) {
|
||||
if (!GEP->isInBounds() && llvm::countr_zero(ElementSize) != 0) {
|
||||
Value *Mask = ConstantInt::get(Idx->getType(), -1);
|
||||
Mask = Builder.CreateLShr(Mask, countTrailingZeros(ElementSize));
|
||||
Mask = Builder.CreateLShr(Mask, llvm::countr_zero(ElementSize));
|
||||
Idx = Builder.CreateAnd(Idx, Mask);
|
||||
}
|
||||
return Idx;
|
||||
|
||||
@ -1177,7 +1177,7 @@ PreservedAnalyses AddressSanitizerPass::run(Module &M,
|
||||
}
|
||||
|
||||
static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
|
||||
size_t Res = countTrailingZeros(TypeSize / 8);
|
||||
size_t Res = llvm::countr_zero(TypeSize / 8);
|
||||
assert(Res < kNumberOfAccessSizes);
|
||||
return Res;
|
||||
}
|
||||
|
||||
@ -788,7 +788,7 @@ static unsigned getPointerOperandIndex(Instruction *I) {
|
||||
}
|
||||
|
||||
static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
|
||||
size_t Res = countTrailingZeros(TypeSize / 8);
|
||||
size_t Res = llvm::countr_zero(TypeSize / 8);
|
||||
assert(Res < kNumberOfAccessSizes);
|
||||
return Res;
|
||||
}
|
||||
|
||||
@ -822,7 +822,7 @@ int ThreadSanitizer::getMemoryAccessFuncIndex(Type *OrigTy, Value *Addr,
|
||||
// Ignore all unusual sizes.
|
||||
return -1;
|
||||
}
|
||||
size_t Idx = countTrailingZeros(TypeSize / 8);
|
||||
size_t Idx = llvm::countr_zero(TypeSize / 8);
|
||||
assert(Idx < kNumberOfAccessSizes);
|
||||
return Idx;
|
||||
}
|
||||
|
||||
@ -4380,7 +4380,7 @@ void LSRInstance::GenerateCrossUseConstantOffsets() {
|
||||
.abs()
|
||||
.slt(std::abs(NewF.BaseOffset)) &&
|
||||
(C->getAPInt() + NewF.BaseOffset).countTrailingZeros() >=
|
||||
countTrailingZeros<uint64_t>(NewF.BaseOffset))
|
||||
(unsigned)llvm::countr_zero<uint64_t>(NewF.BaseOffset))
|
||||
goto skip_formula;
|
||||
|
||||
// Ok, looks good.
|
||||
|
||||
@ -1086,7 +1086,7 @@ static void GetBranchWeights(Instruction *TI,
|
||||
static void FitWeights(MutableArrayRef<uint64_t> Weights) {
|
||||
uint64_t Max = *std::max_element(Weights.begin(), Weights.end());
|
||||
if (Max > UINT_MAX) {
|
||||
unsigned Offset = 32 - countLeadingZeros(Max);
|
||||
unsigned Offset = 32 - llvm::countl_zero(Max);
|
||||
for (uint64_t &I : Weights)
|
||||
I >>= Offset;
|
||||
}
|
||||
@ -6694,7 +6694,7 @@ static bool ReduceSwitchRange(SwitchInst *SI, IRBuilder<> &Builder,
|
||||
// less than 64.
|
||||
unsigned Shift = 64;
|
||||
for (auto &V : Values)
|
||||
Shift = std::min(Shift, countTrailingZeros((uint64_t)V));
|
||||
Shift = std::min(Shift, (unsigned)llvm::countr_zero((uint64_t)V));
|
||||
assert(Shift < 64);
|
||||
if (Shift > 0)
|
||||
for (auto &V : Values)
|
||||
|
||||
@ -69,7 +69,7 @@ void PressureTracker::handleInstructionIssuedEvent(
|
||||
for (const ResourceUse &Use : Event.UsedResources) {
|
||||
const ResourceRef &RR = Use.first;
|
||||
unsigned Index = ProcResID2ResourceUsersIndex[RR.first];
|
||||
Index += countTrailingZeros(RR.second);
|
||||
Index += llvm::countr_zero(RR.second);
|
||||
ResourceUsers[Index] = std::make_pair(IID, Use.second.getNumerator());
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ void ResourcePressureView::onEvent(const HWInstructionEvent &Event) {
|
||||
const ResourceRef &RR = Use.first;
|
||||
assert(Resource2VecIndex.find(RR.first) != Resource2VecIndex.end());
|
||||
unsigned R2VIndex = Resource2VecIndex[RR.first];
|
||||
R2VIndex += countTrailingZeros(RR.second);
|
||||
R2VIndex += llvm::countr_zero(RR.second);
|
||||
ResourceUsage[R2VIndex + NumResourceUnits * SourceIdx] += Use.second;
|
||||
ResourceUsage[R2VIndex + NumResourceUnits * Source.size()] += Use.second;
|
||||
}
|
||||
|
||||
@ -274,8 +274,7 @@ static void printProgramHeaders(const ELFFile<ELFT> &Obj, StringRef FileName) {
|
||||
outs() << "off " << format(Fmt, (uint64_t)Phdr.p_offset) << "vaddr "
|
||||
<< format(Fmt, (uint64_t)Phdr.p_vaddr) << "paddr "
|
||||
<< format(Fmt, (uint64_t)Phdr.p_paddr)
|
||||
<< format("align 2**%u\n",
|
||||
countTrailingZeros<uint64_t>(Phdr.p_align))
|
||||
<< format("align 2**%u\n", llvm::countr_zero<uint64_t>(Phdr.p_align))
|
||||
<< " filesz " << format(Fmt, (uint64_t)Phdr.p_filesz)
|
||||
<< "memsz " << format(Fmt, (uint64_t)Phdr.p_memsz) << "flags "
|
||||
<< ((Phdr.p_flags & ELF::PF_R) ? "r" : "-")
|
||||
|
||||
@ -281,7 +281,7 @@ private:
|
||||
// here because we only care about the first byte, and so that be actually
|
||||
// get ctz intrinsic calls when possible (the `uint8_t` overload uses a loop
|
||||
// implementation).
|
||||
uint32_t numBytes = llvm::countTrailingZeros<uint32_t>(result);
|
||||
uint32_t numBytes = llvm::countr_zero<uint32_t>(result);
|
||||
assert(numBytes > 0 && numBytes <= 7 &&
|
||||
"unexpected number of trailing zeros in varint encoding");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user