[llvm] [NFCI][LLVM] Adopt `ArrayRef::consume_front()` in a few places (PR #146793)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 3 19:55:51 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-vectorizers
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/146793.diff
5 Files Affected:
- (modified) llvm/include/llvm/DebugInfo/CodeView/SymbolRecord.h (+4-8)
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+7-12)
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (+2-2)
- (modified) llvm/lib/CodeGen/MachinePostDominators.cpp (+2-2)
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+6-6)
``````````diff
diff --git a/llvm/include/llvm/DebugInfo/CodeView/SymbolRecord.h b/llvm/include/llvm/DebugInfo/CodeView/SymbolRecord.h
index f5f6fe69430cc..c2897891544af 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/SymbolRecord.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/SymbolRecord.h
@@ -240,8 +240,7 @@ struct BinaryAnnotationIterator
if (Annotations.empty())
return -1;
- uint8_t FirstByte = Annotations.front();
- Annotations = Annotations.drop_front();
+ uint8_t FirstByte = Annotations.consume_front();
if ((FirstByte & 0x80) == 0x00)
return FirstByte;
@@ -249,8 +248,7 @@ struct BinaryAnnotationIterator
if (Annotations.empty())
return -1;
- uint8_t SecondByte = Annotations.front();
- Annotations = Annotations.drop_front();
+ uint8_t SecondByte = Annotations.consume_front();
if ((FirstByte & 0xC0) == 0x80)
return ((FirstByte & 0x3F) << 8) | SecondByte;
@@ -258,14 +256,12 @@ struct BinaryAnnotationIterator
if (Annotations.empty())
return -1;
- uint8_t ThirdByte = Annotations.front();
- Annotations = Annotations.drop_front();
+ uint8_t ThirdByte = Annotations.consume_front();
if (Annotations.empty())
return -1;
- uint8_t FourthByte = Annotations.front();
- Annotations = Annotations.drop_front();
+ uint8_t FourthByte = Annotations.consume_front();
if ((FirstByte & 0xE0) == 0xC0)
return ((FirstByte & 0x1F) << 24) | (SecondByte << 16) |
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index de7bf9b7f4d79..13cec5424a372 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -7513,11 +7513,9 @@ std::vector<FunctionSummary::ParamAccess>
ModuleSummaryIndexBitcodeReader::parseParamAccesses(ArrayRef<uint64_t> Record) {
auto ReadRange = [&]() {
APInt Lower(FunctionSummary::ParamAccess::RangeWidth,
- BitcodeReader::decodeSignRotatedValue(Record.front()));
- Record = Record.drop_front();
+ BitcodeReader::decodeSignRotatedValue(Record.consume_front()));
APInt Upper(FunctionSummary::ParamAccess::RangeWidth,
- BitcodeReader::decodeSignRotatedValue(Record.front()));
- Record = Record.drop_front();
+ BitcodeReader::decodeSignRotatedValue(Record.consume_front()));
ConstantRange Range{Lower, Upper};
assert(!Range.isFullSet());
assert(!Range.isUpperSignWrapped());
@@ -7528,16 +7526,13 @@ ModuleSummaryIndexBitcodeReader::parseParamAccesses(ArrayRef<uint64_t> Record) {
while (!Record.empty()) {
PendingParamAccesses.emplace_back();
FunctionSummary::ParamAccess &ParamAccess = PendingParamAccesses.back();
- ParamAccess.ParamNo = Record.front();
- Record = Record.drop_front();
+ ParamAccess.ParamNo = Record.consume_front();
ParamAccess.Use = ReadRange();
- ParamAccess.Calls.resize(Record.front());
- Record = Record.drop_front();
+ ParamAccess.Calls.resize(Record.consume_front());
for (auto &Call : ParamAccess.Calls) {
- Call.ParamNo = Record.front();
- Record = Record.drop_front();
- Call.Callee = std::get<0>(getValueInfoFromValueId(Record.front()));
- Record = Record.drop_front();
+ Call.ParamNo = Record.consume_front();
+ Call.Callee =
+ std::get<0>(getValueInfoFromValueId(Record.consume_front()));
Call.Offsets = ReadRange();
}
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 5e1b313b4d2fa..d37a22f321cef 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -2085,8 +2085,8 @@ TypeIndex CodeViewDebug::lowerTypeFunction(const DISubroutineType *Ty) {
ArrayRef<TypeIndex> ArgTypeIndices = {};
if (!ReturnAndArgTypeIndices.empty()) {
auto ReturnAndArgTypesRef = ArrayRef(ReturnAndArgTypeIndices);
- ReturnTypeIndex = ReturnAndArgTypesRef.front();
- ArgTypeIndices = ReturnAndArgTypesRef.drop_front();
+ ReturnTypeIndex = ReturnAndArgTypesRef.consume_front();
+ ArgTypeIndices = ReturnAndArgTypesRef;
}
ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices);
diff --git a/llvm/lib/CodeGen/MachinePostDominators.cpp b/llvm/lib/CodeGen/MachinePostDominators.cpp
index 1cb7e465881a2..d6b5ee0e46d74 100644
--- a/llvm/lib/CodeGen/MachinePostDominators.cpp
+++ b/llvm/lib/CodeGen/MachinePostDominators.cpp
@@ -99,8 +99,8 @@ MachineBasicBlock *MachinePostDominatorTree::findNearestCommonDominator(
ArrayRef<MachineBasicBlock *> Blocks) const {
assert(!Blocks.empty());
- MachineBasicBlock *NCD = Blocks.front();
- for (MachineBasicBlock *BB : Blocks.drop_front()) {
+ MachineBasicBlock *NCD = Blocks.consume_front();
+ for (MachineBasicBlock *BB : Blocks) {
NCD = Base::findNearestCommonDominator(NCD, BB);
// Stop when the root is reached.
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 0941bf61953f1..bb09083bbc73b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -1511,8 +1511,8 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
/// \returns true if all of the values in \p VL have the same type or false
/// otherwise.
static bool allSameType(ArrayRef<Value *> VL) {
- Type *Ty = VL.front()->getType();
- return all_of(VL.drop_front(), [&](Value *V) { return V->getType() == Ty; });
+ Type *Ty = VL.consume_front()->getType();
+ return all_of(VL, [&](Value *V) { return V->getType() == Ty; });
}
/// \returns True if in-tree use also needs extract. This refers to
@@ -5567,8 +5567,8 @@ static bool arePointersCompatible(Value *Ptr1, Value *Ptr2,
/// Calculates minimal alignment as a common alignment.
template <typename T>
static Align computeCommonAlignment(ArrayRef<Value *> VL) {
- Align CommonAlignment = cast<T>(VL.front())->getAlign();
- for (Value *V : VL.drop_front())
+ Align CommonAlignment = cast<T>(VL.consume_front())->getAlign();
+ for (Value *V : VL)
CommonAlignment = std::min(CommonAlignment, cast<T>(V)->getAlign());
return CommonAlignment;
}
@@ -9483,8 +9483,8 @@ class PHIHandler {
ArrayRef<unsigned> IncomingValues = P.second;
if (IncomingValues.size() <= 1)
continue;
- unsigned BasicI = IncomingValues.front();
- for (unsigned I : IncomingValues.drop_front()) {
+ unsigned BasicI = IncomingValues.consume_front();
+ for (unsigned I : IncomingValues) {
assert(all_of(enumerate(Operands[I]),
[&](const auto &Data) {
return !Data.value() ||
``````````
</details>
https://github.com/llvm/llvm-project/pull/146793
More information about the llvm-commits
mailing list