[llvm] r220394 - Use auto iteration in lib/Transforms/Scalar/SampleProfile.cpp. No functional changes.
David Blaikie
dblaikie at gmail.com
Wed Oct 22 10:19:03 PDT 2014
On Wed, Oct 22, 2014 at 9:51 AM, Diego Novillo <dnovillo at google.com> wrote:
> Author: dnovillo
> Date: Wed Oct 22 11:51:50 2014
> New Revision: 220394
>
> URL: http://llvm.org/viewvc/llvm-project?rev=220394&view=rev
> Log:
> Use auto iteration in lib/Transforms/Scalar/SampleProfile.cpp. No
> functional changes.
>
> Modified:
> llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp?rev=220394&r1=220393&r2=220394&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp Wed Oct 22 11:51:50
> 2014
> @@ -249,8 +249,8 @@ unsigned SampleProfileLoader::getBlockWe
>
> // Otherwise, compute and cache B's weight.
> unsigned Weight = 0;
> - for (BasicBlock::iterator I = B->begin(), E = B->end(); I != E; ++I) {
> - unsigned InstWeight = getInstWeight(*I);
> + for (auto &I : B->getInstList()) {
> + unsigned InstWeight = getInstWeight(I);
> if (InstWeight > Weight)
> Weight = InstWeight;
> }
> @@ -267,7 +267,7 @@ unsigned SampleProfileLoader::getBlockWe
> bool SampleProfileLoader::computeBlockWeights(Function &F) {
> bool Changed = false;
> DEBUG(dbgs() << "Block weights\n");
> - for (Function::iterator B = F.begin(), E = F.end(); B != E; ++B) {
> + for (auto B = F.begin(), E = F.end(); B != E; ++B) {
>
for (auto &B : F) {
> unsigned Weight = getBlockWeight(B);
>
& you could change getBlockWeight to take a (possibly const?) BasicBlock&
instead of a BasicBlock*
> Changed |= (Weight > 0);
> DEBUG(printBlockWeight(dbgs(), B));
>
& similarly here for printBlockWeight (pass by ref instead of pointer)
> @@ -302,9 +302,7 @@ bool SampleProfileLoader::computeBlockWe
> void SampleProfileLoader::findEquivalencesFor(
> BasicBlock *BB1, SmallVector<BasicBlock *, 8> Descendants,
> DominatorTreeBase<BasicBlock> *DomTree) {
> - for (SmallVectorImpl<BasicBlock *>::iterator I = Descendants.begin(),
> - E = Descendants.end();
> - I != E; ++I) {
> + for (auto I = Descendants.begin(), E = Descendants.end(); I != E; ++I) {
> BasicBlock *BB2 = *I;
>
for (auto *BB2 : Descendants) {
> bool IsDomParent = DomTree->dominates(BB2, BB1);
> bool IsInSameLoop = LI->getLoopFor(BB1) == LI->getLoopFor(BB2);
> @@ -340,7 +338,7 @@ void SampleProfileLoader::findEquivalenc
> SmallVector<BasicBlock *, 8> DominatedBBs;
> DEBUG(dbgs() << "\nBlock equivalence classes\n");
> // Find equivalence sets based on dominance and post-dominance
> information.
> - for (Function::iterator B = F.begin(), E = F.end(); B != E; ++B) {
> + for (auto B = F.begin(), E = F.end(); B != E; ++B) {
> BasicBlock *BB1 = B;
for (auto &BB1 : F) {
Or, if there are lots of pointer uses you don't want to add '&' to:
for (auto &B : F) {
auto *BB1 = &B;
>
> // Compute BB1's equivalence class once.
> @@ -388,7 +386,7 @@ void SampleProfileLoader::findEquivalenc
> // each equivalence class has the largest weight, assign that weight
> // to all the blocks in that equivalence class.
> DEBUG(dbgs() << "\nAssign the same weight to all blocks in the same
> class\n");
> - for (Function::iterator B = F.begin(), E = F.end(); B != E; ++B) {
> + for (auto B = F.begin(), E = F.end(); B != E; ++B) {
> BasicBlock *BB = B;
>
Similar to above and the rest of this.
> BasicBlock *EquivBB = EquivalenceClass[BB];
> if (BB != EquivBB)
> @@ -432,7 +430,7 @@ unsigned SampleProfileLoader::visitEdge(
> bool SampleProfileLoader::propagateThroughEdges(Function &F) {
> bool Changed = false;
> DEBUG(dbgs() << "\nPropagation through edges\n");
> - for (Function::iterator BI = F.begin(), EI = F.end(); BI != EI; ++BI) {
> + for (auto BI = F.begin(), EI = F.end(); BI != EI; ++BI) {
> BasicBlock *BB = BI;
>
> // Visit all the predecessor and successor edges to determine
> @@ -447,16 +445,16 @@ bool SampleProfileLoader::propagateThrou
>
> if (i == 0) {
> // First, visit all predecessor edges.
> - for (size_t I = 0; I < Predecessors[BB].size(); I++) {
> - Edge E = std::make_pair(Predecessors[BB][I], BB);
> + for (auto *Pred : Predecessors[BB]) {
> + Edge E = std::make_pair(Pred, BB);
> TotalWeight += visitEdge(E, &NumUnknownEdges, &UnknownEdge);
> if (E.first == E.second)
> SelfReferentialEdge = E;
> }
> } else {
> // On the second round, visit all successor edges.
> - for (size_t I = 0; I < Successors[BB].size(); I++) {
> - Edge E = std::make_pair(BB, Successors[BB][I]);
> + for (auto *Succ : Successors[BB]) {
> + Edge E = std::make_pair(BB, Succ);
> TotalWeight += visitEdge(E, &NumUnknownEdges, &UnknownEdge);
> }
> }
> @@ -534,7 +532,7 @@ bool SampleProfileLoader::propagateThrou
> /// We are interested in unique edges. If a block B1 has multiple
> /// edges to another block B2, we only add a single B1->B2 edge.
> void SampleProfileLoader::buildEdges(Function &F) {
> - for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
> + for (auto I = F.begin(), E = F.end(); I != E; ++I) {
> BasicBlock *B1 = I;
>
> // Add predecessors for B1.
> @@ -596,7 +594,7 @@ void SampleProfileLoader::propagateWeigh
> // edge weights computed during propagation.
> DEBUG(dbgs() << "\nPropagation complete. Setting branch weights\n");
> MDBuilder MDB(F.getContext());
> - for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
> + for (auto I = F.begin(), E = F.end(); I != E; ++I) {
> BasicBlock *B = I;
> TerminatorInst *TI = B->getTerminator();
> if (TI->getNumSuccessors() == 1)
> @@ -638,10 +636,9 @@ void SampleProfileLoader::propagateWeigh
> /// \returns a valid DISubprogram, if found. Otherwise, it returns an
> empty
> /// DISubprogram.
> static const DISubprogram getDISubprogram(Function &F, const LLVMContext
> &Ctx) {
> - for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
> + for (auto I = F.begin(), E = F.end(); I != E; ++I) {
> BasicBlock *B = I;
> - for (BasicBlock::iterator BI = B->begin(), BE = B->end(); BI != BE;
> ++BI) {
> - Instruction &Inst = *BI;
> + for (auto &Inst : B->getInstList()) {
> DebugLoc DLoc = Inst.getDebugLoc();
> if (DLoc.isUnknown())
> continue;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141022/74d98015/attachment.html>
More information about the llvm-commits
mailing list