Skip to content

Commit fd156f2

Browse files
committed
More APInt API updates
Updating more APInt and bit-manipulation API changes.
1 parent 309aed4 commit fd156f2

File tree

10 files changed

+17
-15
lines changed

10 files changed

+17
-15
lines changed

lib/IRGen/GenType.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ FixedTypeInfo::storeSpareBitExtraInhabitant(IRGenFunction &IGF,
934934
occupiedIndex = index;
935935
spareIndex = spareBitBias;
936936
} else {
937-
auto occupiedBitMask = APInt::getAllOnesValue(occupiedBitCount);
937+
auto occupiedBitMask = APInt::getAllOnes(occupiedBitCount);
938938
occupiedBitMask = occupiedBitMask.zext(32);
939939
auto occupiedBitMaskValue = llvm::ConstantInt::get(C, occupiedBitMask);
940940
occupiedIndex = IGF.Builder.CreateAnd(index, occupiedBitMaskValue);

lib/IRGen/StructLayout.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void StructLayoutBuilder::addFixedSizeElement(ElementLayout &elt) {
335335

336336
// The padding can be used as spare bits by enum layout.
337337
auto numBits = Size(paddingRequired).getValueInBits();
338-
auto mask = llvm::APInt::getAllOnesValue(numBits);
338+
auto mask = llvm::APInt::getAllOnes(numBits);
339339
CurSpareBits.push_back(SpareBitVector::fromAPInt(mask));
340340
}
341341
}

lib/IRGen/TypeLayout.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2242,13 +2242,13 @@ bool EnumTypeLayoutEntry::buildSinglePayloadRefCountString(
22422242
auto tzCount = mask.countTrailingZeros();
22432243
auto shiftedMask = mask.lshr(tzCount);
22442244
auto toCount = shiftedMask.countTrailingOnes();
2245-
if (mask.countPopulation() > 64 || toCount != mask.countPopulation() ||
2245+
if (mask.popcount() > 64 || toCount != mask.popcount() ||
22462246
(tzCount % toCount != 0)) {
22472247
// We currently don't handle cases with non-contiguous or > 64 bits of
22482248
// extra inhabitants
22492249
isSimple = false;
22502250
} else {
2251-
xiBitCount = std::min(64u, mask.countPopulation());
2251+
xiBitCount = std::min(64u, mask.popcount());
22522252
xiBitOffset = mask.countTrailingZeros();
22532253
zeroTagValue = lowValue.extractBitsAsZExtValue(xiBitCount, xiBitOffset);
22542254
}

lib/Parse/Lexer.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ADT/SmallString.h"
2626
#include "llvm/ADT/StringSwitch.h"
2727
#include "llvm/ADT/Twine.h"
28+
#include "llvm/ADT/bit.h"
2829
#include "llvm/Support/Compiler.h"
2930
#include "llvm/Support/MathExtras.h"
3031
#include "llvm/Support/MemoryBuffer.h"
@@ -60,7 +61,7 @@ using clang::isWhitespace;
6061
static bool EncodeToUTF8(unsigned CharValue,
6162
SmallVectorImpl<char> &Result) {
6263
// Number of bits in the value, ignoring leading zeros.
63-
unsigned NumBits = 32-llvm::countLeadingZeros(CharValue);
64+
unsigned NumBits = 32-llvm::countl_zero(CharValue);
6465

6566
// Handle the leading byte, based on the number of bits in the value.
6667
unsigned NumTrailingBytes;
@@ -100,7 +101,7 @@ static bool EncodeToUTF8(unsigned CharValue,
100101

101102
/// CLO8 - Return the number of leading ones in the specified 8-bit value.
102103
static unsigned CLO8(unsigned char C) {
103-
return llvm::countLeadingOnes(uint32_t(C) << 24);
104+
return llvm::countl_zero(uint32_t(C) << 24);
104105
}
105106

106107
/// isStartOfUTF8Character - Return true if this isn't a UTF8 continuation
@@ -162,7 +163,7 @@ uint32_t swift::validateUTF8CharacterAndAdvance(const char *&Ptr,
162163
// If we got here, we read the appropriate number of accumulated bytes.
163164
// Verify that the encoding was actually minimal.
164165
// Number of bits in the value, ignoring leading zeros.
165-
unsigned NumBits = 32-llvm::countLeadingZeros(CharValue);
166+
unsigned NumBits = 32-llvm::countl_zero(CharValue);
166167

167168
if (NumBits <= 5+6)
168169
return EncodedBytes == 2 ? CharValue : ~0U;

lib/SIL/IR/SILInstructions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc,
10681068
"IntegerLiteralInst APInt value's bit width doesn't match type");
10691069
} else {
10701070
assert(Ty.is<BuiltinIntegerLiteralType>());
1071-
assert(Value.getBitWidth() == Value.getMinSignedBits());
1071+
assert(Value.getBitWidth() == Value.getSignificantBits());
10721072
}
10731073
#endif
10741074

@@ -1085,7 +1085,7 @@ static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value) {
10851085
// Otherwise, build using the size of the type and then truncate to the
10861086
// minimum width necessary.
10871087
APInt result(8 * sizeof(value), value, /*signed*/ true);
1088-
result = result.trunc(result.getMinSignedBits());
1088+
result = result.trunc(result.getSignificantBits());
10891089
return result;
10901090
}
10911091

lib/SILOptimizer/Mandatory/DataflowDiagnostics.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static void diagnosePoundAssert(const SILInstruction *I,
180180
APInt intValue = value.getIntegerValue();
181181
assert(intValue.getBitWidth() == 1 &&
182182
"sema prevents non-int1 #assert condition");
183-
if (intValue.isNullValue()) {
183+
if (intValue.isZero()) {
184184
auto *message = cast<StringLiteralInst>(builtinInst->getArguments()[1]);
185185
StringRef messageValue = message->getValue();
186186
if (messageValue.empty())

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2723,7 +2723,7 @@ static void updateControlVariable(SILLocation Loc,
27232723

27242724
// If the mask is all ones, do a simple store, otherwise do a
27252725
// load/or/store sequence to mask in the bits.
2726-
if (!Bitmask.isAllOnesValue()) {
2726+
if (!Bitmask.isAllOnes()) {
27272727
SILValue Tmp =
27282728
B.createLoad(Loc, ControlVariable, LoadOwnershipQualifier::Trivial);
27292729
if (!OrFn.get())

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static bool onlyStoresToTailObjects(BuiltinInst *destroyArray,
301301
AllocRefInstBase *allocRef) {
302302
// Get the number of destroyed elements.
303303
auto *literal = dyn_cast<IntegerLiteralInst>(destroyArray->getArguments()[2]);
304-
if (!literal || literal->getValue().getMinSignedBits() > 32)
304+
if (!literal || literal->getValue().getSignificantBits() > 32)
305305
return false;
306306
int numDestroyed = literal->getValue().getSExtValue();
307307

lib/SILOptimizer/Utils/ConstExpr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ ConstExprFunctionState::computeConstantValueBuiltin(BuiltinInst *inst) {
768768

769769
// Return a statically diagnosed overflow if the operation is supposed to
770770
// trap on overflow.
771-
if (overflowed && !operand2.getIntegerValue().isNullValue())
771+
if (overflowed && !operand2.getIntegerValue().isZero())
772772
return getUnknown(evaluator, SILValue(inst), UnknownReason::Overflow);
773773

774774
auto &allocator = evaluator.getAllocator();

lib/Serialization/ModuleFileSharedCore.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/LinkLibrary.h"
1818
#include "swift/AST/Module.h"
1919
#include "swift/Serialization/Validation.h"
20+
#include "llvm/ADT/bit.h"
2021
#include "llvm/Bitstream/BitstreamReader.h"
2122

2223
namespace llvm {
@@ -124,7 +125,7 @@ class ModuleFileSharedCore {
124125
const unsigned IsScoped : 1;
125126

126127
static unsigned rawControlFromKind(ImportFilterKind importKind) {
127-
return llvm::countTrailingZeros(static_cast<unsigned>(importKind));
128+
return llvm::countr_zero(static_cast<unsigned>(importKind));
128129
}
129130
ImportFilterKind getImportControl() const {
130131
return static_cast<ImportFilterKind>(1 << RawImportControl);
@@ -137,7 +138,7 @@ class ModuleFileSharedCore {
137138
RawImportControl(rawControlFromKind(importControl)),
138139
IsHeader(isHeader),
139140
IsScoped(isScoped) {
140-
assert(llvm::countPopulation(static_cast<unsigned>(importControl)) == 1 &&
141+
assert(llvm::popcount(static_cast<unsigned>(importControl)) == 1 &&
141142
"must be a particular filter option, not a bitset");
142143
assert(getImportControl() == importControl && "not enough bits");
143144
}

0 commit comments

Comments
 (0)