Skip to content

Commit 19129ea

Browse files
[llvm] Use llvm::size (NFC) (#168675)
Note that llvm::size only works on types that allow std::distance in O(1).
1 parent 30e5f76 commit 19129ea

File tree

13 files changed

+20
-27
lines changed

13 files changed

+20
-27
lines changed

llvm/include/llvm/Bitcode/BitcodeConvenience.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ template <typename ElementTy> class BCRecordCoding<BCArray<ElementTy>> {
265265
for (auto &element : array)
266266
ElementTy::assertValid(element);
267267
#endif
268-
buffer.reserve(buffer.size() + std::distance(array.begin(), array.end()));
268+
buffer.reserve(buffer.size() + llvm::size(array));
269269
llvm::append_range(buffer, array);
270270
Stream.EmitRecordWithAbbrev(code, buffer);
271271
}

llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintInstructionCount.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PrintInstructionCount final : public RegionPass {
1313
public:
1414
PrintInstructionCount() : RegionPass("null") {}
1515
bool runOnRegion(Region &R, const Analyses &A) final {
16-
outs() << "InstructionCount: " << std::distance(R.begin(), R.end()) << "\n";
16+
outs() << "InstructionCount: " << llvm::size(R) << "\n";
1717
return false;
1818
}
1919
};

llvm/lib/CAS/OnDiskCAS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class OnDiskCAS : public BuiltinCAS {
6363

6464
size_t getNumRefs(ObjectHandle Node) const final {
6565
auto RefsRange = DB->getObjectRefs(convertHandle(Node));
66-
return std::distance(RefsRange.begin(), RefsRange.end());
66+
return llvm::size(RefsRange);
6767
}
6868

6969
ObjectRef readRef(ObjectHandle Node, size_t I) const final {

llvm/lib/CAS/OnDiskGraphDB.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,9 +1660,8 @@ Error OnDiskGraphDB::importFullTree(ObjectID PrimaryID,
16601660
if (!Node)
16611661
return;
16621662
auto Refs = UpstreamDB->getObjectRefs(*Node);
1663-
CursorStack.push_back({*Node,
1664-
(size_t)std::distance(Refs.begin(), Refs.end()),
1665-
Refs.begin(), Refs.end()});
1663+
CursorStack.push_back(
1664+
{*Node, (size_t)llvm::size(Refs), Refs.begin(), Refs.end()});
16661665
};
16671666

16681667
enqueueNode(PrimaryID, UpstreamNode);
@@ -1722,7 +1721,7 @@ Error OnDiskGraphDB::importSingleNode(ObjectID PrimaryID,
17221721
auto Data = UpstreamDB->getObjectData(UpstreamNode);
17231722
auto UpstreamRefs = UpstreamDB->getObjectRefs(UpstreamNode);
17241723
SmallVector<ObjectID, 64> Refs;
1725-
Refs.reserve(std::distance(UpstreamRefs.begin(), UpstreamRefs.end()));
1724+
Refs.reserve(llvm::size(UpstreamRefs));
17261725
for (ObjectID UpstreamRef : UpstreamRefs) {
17271726
auto Ref = getReference(UpstreamDB->getDigest(UpstreamRef));
17281727
if (LLVM_UNLIKELY(!Ref))

llvm/lib/ObjectYAML/MinidumpEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class BlobAllocator {
8484
template <typename T, typename RangeType>
8585
std::pair<size_t, MutableArrayRef<T>>
8686
BlobAllocator::allocateNewArray(const iterator_range<RangeType> &Range) {
87-
size_t Num = std::distance(Range.begin(), Range.end());
87+
size_t Num = llvm::size(Range);
8888
MutableArrayRef<T> Array(Temporaries.Allocate<T>(Num), Num);
8989
llvm::uninitialized_copy(Range, Array.begin());
9090
return {allocateArray(Array), Array};

llvm/lib/Support/BalancedPartitioning.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void BalancedPartitioning::bisect(const FunctionNodeRange Nodes,
114114
unsigned RecDepth, unsigned RootBucket,
115115
unsigned Offset,
116116
std::optional<BPThreadPool> &TP) const {
117-
unsigned NumNodes = std::distance(Nodes.begin(), Nodes.end());
117+
unsigned NumNodes = llvm::size(Nodes);
118118
if (NumNodes <= 1 || RecDepth >= Config.SplitDepth) {
119119
// We've reach the lowest level of the recursion tree. Fall back to the
120120
// original order and assign to buckets.
@@ -168,7 +168,7 @@ void BalancedPartitioning::runIterations(const FunctionNodeRange Nodes,
168168
unsigned LeftBucket,
169169
unsigned RightBucket,
170170
std::mt19937 &RNG) const {
171-
unsigned NumNodes = std::distance(Nodes.begin(), Nodes.end());
171+
unsigned NumNodes = llvm::size(Nodes);
172172
DenseMap<BPFunctionNode::UtilityNodeT, unsigned> UtilityNodeIndex;
173173
for (auto &N : Nodes)
174174
for (auto &UN : N.UtilityNodes)
@@ -303,7 +303,7 @@ bool BalancedPartitioning::moveFunctionNode(BPFunctionNode &N,
303303

304304
void BalancedPartitioning::split(const FunctionNodeRange Nodes,
305305
unsigned StartBucket) const {
306-
unsigned NumNodes = std::distance(Nodes.begin(), Nodes.end());
306+
unsigned NumNodes = llvm::size(Nodes);
307307
auto NodesMid = Nodes.begin() + (NumNodes + 1) / 2;
308308

309309
llvm::sort(Nodes, [](auto &L, auto &R) {

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,9 +1266,7 @@ void AArch64AsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
12661266
// Frame address. Currently handles register +- offset only.
12671267
assert(MI->isIndirectDebugValue());
12681268
OS << '[';
1269-
for (unsigned I = 0, E = std::distance(MI->debug_operands().begin(),
1270-
MI->debug_operands().end());
1271-
I < E; ++I) {
1269+
for (unsigned I = 0, E = llvm::size(MI->debug_operands()); I < E; ++I) {
12721270
if (I != 0)
12731271
OS << ", ";
12741272
printOperand(MI, I, OS);

llvm/lib/Target/AMDGPU/GCNRegPressure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ template <typename Range>
455455
DenseMap<MachineInstr*, GCNRPTracker::LiveRegSet>
456456
getLiveRegMap(Range &&R, bool After, LiveIntervals &LIS) {
457457
std::vector<SlotIndex> Indexes;
458-
Indexes.reserve(std::distance(R.begin(), R.end()));
458+
Indexes.reserve(llvm::size(R));
459459
auto &SII = *LIS.getSlotIndexes();
460460
for (MachineInstr *I : R) {
461461
auto SI = SII.getInstructionIndex(*I);

llvm/lib/Target/SPIRV/SPIRVISelLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,7 @@ bool SPIRVTargetLowering::insertLogicalCopyOnResult(
606606
createVirtualRegister(NewResultType, &GR, MRI, *I.getMF());
607607
Register NewTypeReg = GR.getSPIRVTypeID(NewResultType);
608608

609-
assert(std::distance(I.defs().begin(), I.defs().end()) == 1 &&
610-
"Expected only one def");
609+
assert(llvm::size(I.defs()) == 1 && "Expected only one def");
611610
MachineOperand &OldResult = *I.defs().begin();
612611
Register OldResultReg = OldResult.getReg();
613612
MachineOperand &OldType = *I.uses().begin();

llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,7 @@ static void removeImplicitFallthroughs(MachineFunction &MF,
10671067
if (!isImplicitFallthrough(MBB))
10681068
continue;
10691069

1070-
assert(std::distance(MBB.successors().begin(), MBB.successors().end()) ==
1071-
1);
1070+
assert(MBB.succ_size() == 1);
10721071
MIB.setInsertPt(MBB, MBB.end());
10731072
MIB.buildBr(**MBB.successors().begin());
10741073
}

0 commit comments

Comments
 (0)