Index: lib/Transforms/IPO/SampleProfile.cpp =================================================================== --- lib/Transforms/IPO/SampleProfile.cpp +++ lib/Transforms/IPO/SampleProfile.cpp @@ -218,6 +218,7 @@ const FunctionSamples *findCalleeFunctionSamples(const Instruction &I) const; std::vector findIndirectCallFunctionSamples(const Instruction &I, uint64_t &Sum) const; + mutable DenseMap DILocation2SampleMap; const FunctionSamples *findFunctionSamples(const Instruction &I) const; bool inlineCallInstruction(Instruction *I); bool inlineHotFunctions(Function &F, @@ -719,12 +720,14 @@ /// \returns the FunctionSamples pointer to the inlined instance. const FunctionSamples * SampleProfileLoader::findFunctionSamples(const Instruction &Inst) const { - SmallVector, 10> S; const DILocation *DIL = Inst.getDebugLoc(); if (!DIL) return Samples; - return Samples->findFunctionSamples(DIL); + auto it = DILocation2SampleMap.try_emplace(DIL,nullptr); + if (it.second) + it.first->second = Samples->findFunctionSamples(DIL); + return it.first->second; } bool SampleProfileLoader::inlineCallInstruction(Instruction *I) {