[llvm] 6ce03ff - Revert "[IR] Use range-based for loops (NFC)"
Shubham Sandeep Rastogi via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 15:33:42 PST 2024
Author: Shubham Sandeep Rastogi
Date: 2024-02-05T15:33:21-08:00
New Revision: 6ce03ff3fef8fb6fa9afe8eb22c6d98bced26d48
URL: https://github.com/llvm/llvm-project/commit/6ce03ff3fef8fb6fa9afe8eb22c6d98bced26d48
DIFF: https://github.com/llvm/llvm-project/commit/6ce03ff3fef8fb6fa9afe8eb22c6d98bced26d48.diff
LOG: Revert "[IR] Use range-based for loops (NFC)"
This reverts commit e8512786fedbfa6ddba70ceddc29d7122173ba5e.
This revert is done because llvm::drop_begin over an empty ArrayRef
doesn't return an empty range, and therefore can lead to an invalid
address returned instead.
See discussion in https://github.com/llvm/llvm-project/pull/80737 for
more context.
Added:
Modified:
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/ProfDataUtils.cpp
llvm/lib/IR/Verifier.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 35a98767a8be3..7b56c471a745e 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -1309,8 +1309,8 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) {
++mdnNext;
// Recursively add any MDNodes referenced by operands.
- for (const MDOperand &MDO : N->operands())
- if (const MDNode *Op = dyn_cast_or_null<MDNode>(MDO))
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
+ if (const MDNode *Op = dyn_cast_or_null<MDNode>(N->getOperand(i)))
CreateMetadataSlot(Op);
}
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 19d80eb9aec0b..b90bbe71ac189 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5209,8 +5209,8 @@ static Metadata *upgradeLoopArgument(Metadata *MD) {
SmallVector<Metadata *, 8> Ops;
Ops.reserve(T->getNumOperands());
Ops.push_back(upgradeLoopTag(T->getContext(), OldTag->getString()));
- for (const MDOperand &MDO : llvm::drop_begin(T->operands()))
- Ops.push_back(MDO);
+ for (unsigned I = 1, E = T->getNumOperands(); I != E; ++I)
+ Ops.push_back(T->getOperand(I));
return MDTuple::get(T->getContext(), Ops);
}
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 2cf88292b14ed..d8c1b0d534f61 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -400,8 +400,8 @@ static MDNode *updateLoopMetadataDebugLocationsImpl(
// Save space for the self-referential LoopID.
SmallVector<Metadata *, 4> MDs = {nullptr};
- for (const MDOperand &MDO : llvm::drop_begin(OrigLoopID->operands())) {
- Metadata *MD = MDO;
+ for (unsigned i = 1; i < OrigLoopID->getNumOperands(); ++i) {
+ Metadata *MD = OrigLoopID->getOperand(i);
if (!MD)
MDs.push_back(nullptr);
else if (Metadata *NewMD = Updater(MD))
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index d3e2ae0dede45..22e2455462bf4 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -1976,9 +1976,10 @@ DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const {
if (MDNode *MD = getMetadata(LLVMContext::MD_prof))
if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0)))
if (MDS->getString().equals("function_entry_count"))
- for (const MDOperand &MDO : llvm::drop_begin(MD->operands(), 2))
- R.insert(
- mdconst::extract<ConstantInt>(MDO)->getValue().getZExtValue());
+ for (unsigned i = 2; i < MD->getNumOperands(); i++)
+ R.insert(mdconst::extract<ConstantInt>(MD->getOperand(i))
+ ->getValue()
+ .getZExtValue());
return R;
}
diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp
index dcb057c1b25fd..b1a10d0ce5a52 100644
--- a/llvm/lib/IR/ProfDataUtils.cpp
+++ b/llvm/lib/IR/ProfDataUtils.cpp
@@ -162,8 +162,8 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
return false;
if (ProfDataName->getString().equals("branch_weights")) {
- for (const MDOperand &MDO : llvm::drop_begin(ProfileData->operands())) {
- auto *V = mdconst::dyn_extract<ConstantInt>(MDO);
+ for (unsigned Idx = 1; Idx < ProfileData->getNumOperands(); Idx++) {
+ auto *V = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(Idx));
assert(V && "Malformed branch_weight in MD_prof node");
TotalVal += V->getValue().getZExtValue();
}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 8d992c232ca7c..b04d39c700a8f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2913,8 +2913,8 @@ void Verifier::visitFunction(const Function &F) {
VisitDebugLoc(I, I.getDebugLoc().getAsMDNode());
// The llvm.loop annotations also contain two DILocations.
if (auto MD = I.getMetadata(LLVMContext::MD_loop))
- for (const MDOperand &MDO : llvm::drop_begin(MD->operands()))
- VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MDO));
+ for (unsigned i = 1; i < MD->getNumOperands(); ++i)
+ VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MD->getOperand(i)));
if (BrokenDebugInfo)
return;
}
@@ -4713,7 +4713,8 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
Check(MD->getNumOperands() == 1 + ExpectedNumOperands,
"Wrong number of operands", MD);
}
- for (const MDOperand &MDO : llvm::drop_begin(MD->operands())) {
+ for (unsigned i = 1; i < MD->getNumOperands(); ++i) {
+ auto &MDO = MD->getOperand(i);
Check(MDO, "second operand should not be null", MD);
Check(mdconst::dyn_extract<ConstantInt>(MDO),
"!prof brunch_weights operand is not a const int");
More information about the llvm-commits
mailing list