From: Xinliang David Li Date: Mon, 1 Aug 2016 20:25:06 +0000 (+0000) Subject: [Profile] IR profiling minor cleanup /nfc X-Git-Tag: llvmorg-4.0.0-rc1~13637 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d119761bbecdc0043429360b2a58dd86c38282e3;p=platform%2Fupstream%2Fllvm.git [Profile] IR profiling minor cleanup /nfc Differential Revision: http://reviews.llvm.org/D22995 llvm-svn: 277379 --- diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 9b95a25..99154d8 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -299,6 +299,16 @@ public: if (CreateGlobalVar) FuncNameVar = createPGOFuncNameVar(F, FuncName); } + + // Return the number of profile counters needed for the function. + unsigned getNumCounters() { + unsigned NumCounters = 0; + for (auto &E : this->MST.AllEdges) { + if (!E->InMST && !E->Removed) + NumCounters++; + } + return NumCounters; + } }; // Compute Hash value for the CFG: the lower 32 bits are CRC32 of the index @@ -442,13 +452,10 @@ BasicBlock *FuncPGOInstrumentation::getInstrBB(Edge *E) { static void instrumentOneFunc( Function &F, Module *M, BranchProbabilityInfo *BPI, BlockFrequencyInfo *BFI, std::unordered_multimap &ComdatMembers) { - unsigned NumCounters = 0; FuncPGOInstrumentation FuncInfo(F, ComdatMembers, true, BPI, BFI); - for (auto &E : FuncInfo.MST.AllEdges) { - if (!E->InMST && !E->Removed) - NumCounters++; - } + unsigned NumCounters = FuncInfo.getNumCounters(); + uint32_t I = 0; Type *I8PtrTy = Type::getInt8PtrTy(M->getContext()); for (auto &E : FuncInfo.MST.AllEdges) { @@ -465,6 +472,7 @@ static void instrumentOneFunc( Builder.getInt64(FuncInfo.FunctionHash), Builder.getInt32(NumCounters), Builder.getInt32(I++)}); } + assert(I == NumCounters); if (DisableValueProfiling) return; @@ -638,6 +646,7 @@ private: void PGOUseFunc::setInstrumentedCounts( const std::vector &CountFromProfile) { + assert(FuncInfo.getNumCounters() == CountFromProfile.size()); // Use a worklist as we will update the vector during the iteration. std::vector WorkList; for (auto &E : FuncInfo.MST.AllEdges) @@ -667,6 +676,7 @@ void PGOUseFunc::setInstrumentedCounts( NewEdge1.InMST = true; getBBInfo(InstrBB).setBBInfoCount(CountValue); } + assert(I == CountFromProfile.size()); } // Set the count value for the unknown edge. There should be one and only one