[llvm] ea3175c - [Transforms/Instrumentation] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 5 21:02:55 PST 2021
Author: Kazu Hirata
Date: 2021-02-05T21:02:08-08:00
New Revision: ea3175c15b607ce097a80552989673b66016ec30
URL: https://github.com/llvm/llvm-project/commit/ea3175c15b607ce097a80552989673b66016ec30
DIFF: https://github.com/llvm/llvm-project/commit/ea3175c15b607ce097a80552989673b66016ec30.diff
LOG: [Transforms/Instrumentation] Use range-based for loops (NFC)
Added:
Modified:
llvm/lib/Transforms/Instrumentation/CFGMST.h
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/CFGMST.h b/llvm/lib/Transforms/Instrumentation/CFGMST.h
index 6580b6d7d73e..2abe8d12de3c 100644
--- a/llvm/lib/Transforms/Instrumentation/CFGMST.h
+++ b/llvm/lib/Transforms/Instrumentation/CFGMST.h
@@ -122,10 +122,10 @@ template <class Edge, class BBInfo> class CFGMST {
static const uint32_t CriticalEdgeMultiplier = 1000;
- for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
- Instruction *TI = BB->getTerminator();
+ for (BasicBlock &BB : F) {
+ Instruction *TI = BB.getTerminator();
uint64_t BBWeight =
- (BFI != nullptr ? BFI->getBlockFreq(&*BB).getFrequency() : 2);
+ (BFI != nullptr ? BFI->getBlockFreq(&BB).getFrequency() : 2);
uint64_t Weight = 2;
if (int successors = TI->getNumSuccessors()) {
for (int i = 0; i != successors; ++i) {
@@ -139,16 +139,16 @@ template <class Edge, class BBInfo> class CFGMST {
scaleFactor = UINT64_MAX;
}
if (BPI != nullptr)
- Weight = BPI->getEdgeProbability(&*BB, TargetBB).scale(scaleFactor);
+ Weight = BPI->getEdgeProbability(&BB, TargetBB).scale(scaleFactor);
if (Weight == 0)
Weight++;
- auto *E = &addEdge(&*BB, TargetBB, Weight);
+ auto *E = &addEdge(&BB, TargetBB, Weight);
E->IsCritical = Critical;
- LLVM_DEBUG(dbgs() << " Edge: from " << BB->getName() << " to "
+ LLVM_DEBUG(dbgs() << " Edge: from " << BB.getName() << " to "
<< TargetBB->getName() << " w=" << Weight << "\n");
// Keep track of entry/exit edges:
- if (&*BB == Entry) {
+ if (&BB == Entry) {
if (Weight > MaxEntryOutWeight) {
MaxEntryOutWeight = Weight;
EntryOutgoing = E;
@@ -165,12 +165,12 @@ template <class Edge, class BBInfo> class CFGMST {
}
} else {
ExitBlockFound = true;
- Edge *ExitO = &addEdge(&*BB, nullptr, BBWeight);
+ Edge *ExitO = &addEdge(&BB, nullptr, BBWeight);
if (BBWeight > MaxExitOutWeight) {
MaxExitOutWeight = BBWeight;
ExitOutgoing = ExitO;
}
- LLVM_DEBUG(dbgs() << " Edge: from " << BB->getName() << " to fake exit"
+ LLVM_DEBUG(dbgs() << " Edge: from " << BB.getName() << " to fake exit"
<< " w = " << BBWeight << "\n");
}
}
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 7a6874584d59..f484ff0a98c8 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -2188,8 +2188,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
if (!MS.TrackOrigins) return;
IRBuilder<> IRB(&I);
OriginCombiner OC(this, IRB);
- for (Instruction::op_iterator OI = I.op_begin(); OI != I.op_end(); ++OI)
- OC.Add(OI->get());
+ for (Use &Op : I.operands())
+ OC.Add(Op.get());
OC.Done(&I);
}
@@ -2239,8 +2239,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
void handleShadowOr(Instruction &I) {
IRBuilder<> IRB(&I);
ShadowAndOriginCombiner SC(this, IRB);
- for (Instruction::op_iterator OI = I.op_begin(); OI != I.op_end(); ++OI)
- SC.Add(OI->get());
+ for (Use &Op : I.operands())
+ SC.Add(Op.get());
SC.Done(&I);
}
@@ -4049,8 +4049,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
NumRetOutputs = 1;
}
InlineAsm::ConstraintInfoVector Constraints = IA->ParseConstraints();
- for (size_t i = 0, n = Constraints.size(); i < n; i++) {
- InlineAsm::ConstraintInfo Info = Constraints[i];
+ for (const InlineAsm::ConstraintInfo &Info : Constraints) {
switch (Info.Type) {
case InlineAsm::isOutput:
NumOutputs++;
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 46e5b75a611e..25ddf2043ba6 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1465,8 +1465,8 @@ void PGOUseFunc::setBranchWeights() {
}
static bool isIndirectBrTarget(BasicBlock *BB) {
- for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
- if (isa<IndirectBrInst>((*PI)->getTerminator()))
+ for (BasicBlock *Pred : predecessors(BB)) {
+ if (isa<IndirectBrInst>(Pred->getTerminator()))
return true;
}
return false;
@@ -2124,14 +2124,13 @@ template <> struct DOTGraphTraits<PGOUseFunc *> : DefaultDOTGraphTraits {
if (!PGOInstrSelect)
return Result;
- for (auto BI = Node->begin(); BI != Node->end(); ++BI) {
- auto *I = &*BI;
- if (!isa<SelectInst>(I))
+ for (const Instruction &I : *Node) {
+ if (!isa<SelectInst>(&I))
continue;
// Display scaled counts for SELECT instruction:
OS << "SELECT : { T = ";
uint64_t TC, FC;
- bool HasProf = I->extractProfMetadata(TC, FC);
+ bool HasProf = I.extractProfMetadata(TC, FC);
if (!HasProf)
OS << "Unknown, F = Unknown }\\l";
else
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 2d4b07939463..b4b34450ecf2 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -833,10 +833,10 @@ void ModuleSanitizerCoverage::InjectTraceForGep(
Function &, ArrayRef<GetElementPtrInst *> GepTraceTargets) {
for (auto GEP : GepTraceTargets) {
IRBuilder<> IRB(GEP);
- for (auto I = GEP->idx_begin(); I != GEP->idx_end(); ++I)
- if (!isa<ConstantInt>(*I) && (*I)->getType()->isIntegerTy())
+ for (Use &Idx : GEP->indices())
+ if (!isa<ConstantInt>(Idx) && Idx->getType()->isIntegerTy())
IRB.CreateCall(SanCovTraceGepFunction,
- {IRB.CreateIntCast(*I, IntptrTy, true)});
+ {IRB.CreateIntCast(Idx, IntptrTy, true)});
}
}
More information about the llvm-commits
mailing list