Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -59,12 +59,12 @@ #include "llvm/IR/Module.h" #include "llvm/IR/ProfileSummary.h" #include "llvm/ProfileData/InstrProfReader.h" +#include "llvm/ProfileData/SampleProf.h" #include "llvm/Support/CRC.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/MD5.h" #include "llvm/Support/TimeProfiler.h" #include "llvm/Support/X86TargetParser.h" @@ -206,22 +206,7 @@ Path = Entry.second + Path.substr(Entry.first.size()); break; } - llvm::MD5 Md5; - Md5.update(Path); - llvm::MD5::MD5Result R; - Md5.final(R); - SmallString<32> Str; - llvm::MD5::stringifyResult(R, Str); - // Convert MD5hash to Decimal. Demangler suffixes can either contain - // numbers or characters but not both. - llvm::APInt IntHash(128, Str.str(), 16); - // Prepend "__uniq" before the hash for tools like profilers to understand - // that this symbol is of internal linkage type. The "__uniq" is the - // pre-determined prefix that is used to tell tools that this symbol was - // created with -funique-internal-linakge-symbols and the tools can strip or - // keep the prefix as needed. - ModuleNameHash = (Twine(".__uniq.") + - Twine(toString(IntHash, /* Radix = */ 10, /* Signed = */false))).str(); + ModuleNameHash = llvm::getUniqueInternalLinkagePostfix(Path); } } Index: llvm/include/llvm/ProfileData/SampleProf.h =================================================================== --- llvm/include/llvm/ProfileData/SampleProf.h +++ llvm/include/llvm/ProfileData/SampleProf.h @@ -16,6 +16,7 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/Function.h" @@ -1331,6 +1332,26 @@ return LHS == RHS; } }; + +// Prepend "__uniq" before the hash for tools like profilers to understand +// that this symbol is of internal linkage type. The "__uniq" is the +// pre-determined prefix that is used to tell tools that this symbol was +// created with -funique-internal-linakge-symbols and the tools can strip or +// keep the prefix as needed. +inline std::string getUniqueInternalLinkagePostfix(const StringRef &FName) { + llvm::MD5 Md5; + Md5.update(FName); + llvm::MD5::MD5Result R; + Md5.final(R); + SmallString<32> Str; + llvm::MD5::stringifyResult(R, Str); + // Convert MD5hash to Decimal. Demangler suffixes can either contain + // numbers or characters but not both. + llvm::APInt IntHash(128, Str.str(), 16); + return toString(IntHash, /* Radix = */ 10, /* Signed = */ false) + .insert(0, FunctionSamples::UniqSuffix); +}; + } // end namespace llvm #endif // LLVM_PROFILEDATA_SAMPLEPROF_H Index: llvm/lib/ProfileData/ProfileSummaryBuilder.cpp =================================================================== --- llvm/lib/ProfileData/ProfileSummaryBuilder.cpp +++ llvm/lib/ProfileData/ProfileSummaryBuilder.cpp @@ -223,7 +223,7 @@ NumFunctions++; // Skip invalid count. - if (Count == (uint64_t)-1) + if (Count == (uint64_t)-1 || Count == (uint64_t)-2) return; addCount(Count); @@ -233,7 +233,7 @@ void InstrProfSummaryBuilder::addInternalCount(uint64_t Count) { // Skip invalid count. - if (Count == (uint64_t)-1) + if (Count == (uint64_t)-1 || Count == (uint64_t)-2) return; addCount(Count); Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -1019,7 +1019,7 @@ // Read counts for the instrumented BB from profile. bool readCounters(IndexedInstrProfReader *PGOReader, bool &AllZeros, - bool &AllMinusOnes); + int &AllMinus); // Populate the counts for all BBs. void populateCounters(); @@ -1225,7 +1225,7 @@ // instrumented BB and the edges. This function also updates ProgramMaxCount. // Return true if the profile are successfully read, and false on errors. bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader, bool &AllZeros, - bool &AllMinusOnes) { + int &AllMinus) { auto &Ctx = M->getContext(); uint64_t MismatchedFuncSum = 0; Expected Result = PGOReader->getInstrProfRecord( @@ -1274,15 +1274,27 @@ IsCS ? NumOfCSPGOFunc++ : NumOfPGOFunc++; LLVM_DEBUG(dbgs() << CountFromProfile.size() << " counts\n"); - AllMinusOnes = (CountFromProfile.size() > 0); uint64_t ValueSum = 0; + bool AllMinusOne = true; + bool AllMinusTwo = true; for (unsigned I = 0, S = CountFromProfile.size(); I < S; I++) { LLVM_DEBUG(dbgs() << " " << I << ": " << CountFromProfile[I] << "\n"); ValueSum += CountFromProfile[I]; if (CountFromProfile[I] != (uint64_t)-1) - AllMinusOnes = false; - } + AllMinusOne = false; + if (CountFromProfile[I] != (uint64_t)-2) + AllMinusTwo = false; + } + if (AllMinusOne) + AllMinus = -1; + else if (AllMinusTwo) + AllMinus = -2; + else + AllMinus = 0; AllZeros = (ValueSum == 0); + // LLVM_DEBUG(dbgs() << "AllMinus = " << AllMinus << " AllZeros = " << + // AllZeros << "\n"); + (dbgs() << "AllMinus = " << AllMinus << " AllZeros = " << AllZeros << "\n"); LLVM_DEBUG(dbgs() << "SUM = " << ValueSum << "\n"); @@ -1818,13 +1830,13 @@ SplitIndirectBrCriticalEdges(F, /*IgnoreBlocksWithoutPHI=*/false, BPI, BFI); PGOUseFunc Func(F, &M, TLI, ComdatMembers, BPI, BFI, PSI, IsCS, InstrumentFuncEntry); - // When AllMinusOnes is true, it means the profile for the function - // is unrepresentative and this function is actually hot. Set the + // When AllMinus is not zero, it means the profile for the function + // is unrepresentative and this function is actually hot / warm. Set the // entry count of the function to be multiple times of hot threshold // and drop all its internal counters. - bool AllMinusOnes = false; + int AllMinus = 0; bool AllZeros = false; - if (!Func.readCounters(PGOReader.get(), AllZeros, AllMinusOnes)) + if (!Func.readCounters(PGOReader.get(), AllZeros, AllMinus)) continue; if (AllZeros) { F.setEntryCount(ProfileCount(0, Function::PCT_Real)); @@ -1833,12 +1845,16 @@ continue; } const unsigned MultiplyFactor = 3; - if (AllMinusOnes) { - uint64_t HotThreshold = PSI->getHotCountThreshold(); - if (HotThreshold) + if (AllMinus == -1 || AllMinus == -2) { + uint64_t Threshold = AllMinus == -1 ? PSI->getHotCountThreshold() + : PSI->getColdCountThreshold(); + dbgs() << "hihihi hi " << Threshold << " to " + << Threshold * MultiplyFactor << "\n"; + if (Threshold) F.setEntryCount( - ProfileCount(HotThreshold * MultiplyFactor, Function::PCT_Real)); - HotFunctions.push_back(&F); + ProfileCount(Threshold * MultiplyFactor, Function::PCT_Real)); + if (AllMinus == -1) + HotFunctions.push_back(&F); continue; } Func.populateCounters(); Index: llvm/test/Transforms/PGOProfile/Inputs/sample-profile-warm.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/sample-profile-warm.proftext @@ -0,0 +1,12 @@ +test_simple_for:40:40 + 1: 10 + 2: 10 + 3: 10 + 4: 10 + +moo:1000:1000 + 1: 2000 + 2: 2000 + 3: 2000 + 4: 2000 + 5: 2000 Index: llvm/test/Transforms/PGOProfile/Inputs/suppl-profile.proftext =================================================================== --- llvm/test/Transforms/PGOProfile/Inputs/suppl-profile.proftext +++ llvm/test/Transforms/PGOProfile/Inputs/suppl-profile.proftext @@ -13,3 +13,12 @@ 270 180 760 + +boo +2582734 +4 +100 +27 +10 +70 + Index: llvm/test/Transforms/PGOProfile/suppl-profile.ll =================================================================== --- llvm/test/Transforms/PGOProfile/suppl-profile.ll +++ llvm/test/Transforms/PGOProfile/suppl-profile.ll @@ -1,18 +1,27 @@ ; Supplement instr profile suppl-profile.proftext with sample profile ; sample-profile.proftext. +; For hot functions: ; RUN: llvm-profdata merge -instr -suppl-min-size-threshold=0 \ -; RUN: -supplement-instr-with-sample=%p/Inputs/sample-profile.proftext \ +; RUN: -supplement-instr-with-sample=%p/Inputs/sample-profile-hot.proftext \ ; RUN: %S/Inputs/suppl-profile.proftext -o %t.profdata -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s +; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=HOT +; For warm functions: +; RUN: llvm-profdata merge -instr -suppl-min-size-threshold=0 \ +; RUN: -supplement-instr-with-sample=%p/Inputs/sample-profile-warm.proftext \ +; RUN: %S/Inputs/suppl-profile.proftext -o %t1.profdata +; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t1.profdata -S | FileCheck %s --check-prefix=WARM target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" ; Check test_simple_for has a non-zero entry count and doesn't have any other ; prof metadata. -; CHECK: @test_simple_for(i32 %n) {{.*}} !prof ![[ENTRY_COUNT:[0-9]+]] -; CHECK-NOT: !prof ! -; CHECK: ![[ENTRY_COUNT]] = !{!"function_entry_count", i64 540} +; HOT: @test_simple_for(i32 %n) {{.*}} !prof ![[ENTRY_COUNT:[0-9]+]] +; HOT-NOT: !prof ! +; HOT: ![[ENTRY_COUNT]] = !{!"function_entry_count", i64 81} +; WARM: @test_simple_for(i32 %n) !prof ![[ENTRY_COUNT:[0-9]+]] +; WARM-NOT: !prof ! +; WARM: ![[ENTRY_COUNT]] = !{!"function_entry_count", i64 30} define i32 @test_simple_for(i32 %n) { entry: br label %for.cond Index: llvm/test/tools/llvm-profdata/Inputs/FUnique.afdotext =================================================================== --- /dev/null +++ llvm/test/tools/llvm-profdata/Inputs/FUnique.afdotext @@ -0,0 +1,17 @@ +_ZL3foom.__uniq.276699478366846449772231447066107882794:14064855:0 + 0: 0 + 2.1: 0 + 2.2: 290944 + 2.3073: 290944 + 3: 290944 + 4: 256 bar:256 + 5: 304048 bar:307919 + 7: 0 +_Z3barmi:6447198:308175 + 1: 302866 + 2: 5551 + 3: 296598 + 3.13824: 5551 + 3.2952803840: 296598 + 4: 5551 + 4.4160749568: 296598 Index: llvm/test/tools/llvm-profdata/Inputs/FUnique.proftext =================================================================== --- /dev/null +++ llvm/test/tools/llvm-profdata/Inputs/FUnique.proftext @@ -0,0 +1,30 @@ +# IR level Instrumentation Flag +:ir +_Z3barmi +# Func Hash: +784007056844089447 +# Num Counters: +2 +# Counter Values: +0 +0 + +main +# Func Hash: +784007059655560962 +# Num Counters: +2 +# Counter Values: +1 +0 + +test.c:_ZL3foom.__uniq.276699478366846449772231447066107882794 +# Func Hash: +1124680652115249575 +# Num Counters: +3 +# Counter Values: +0 +0 +0 + Index: llvm/test/tools/llvm-profdata/Inputs/NoFUnique.afdotext =================================================================== --- /dev/null +++ llvm/test/tools/llvm-profdata/Inputs/NoFUnique.afdotext @@ -0,0 +1,17 @@ +_ZL3foom:14064855:0 + 0: 0 + 2.1: 0 + 2.2: 290944 + 2.3073: 290944 + 3: 290944 + 4: 256 bar:256 + 5: 304048 bar:307919 + 7: 0 +_Z3barmi:6447198:308175 + 1: 302866 + 2: 5551 + 3: 296598 + 3.13824: 5551 + 3.2952803840: 296598 + 4: 5551 + 4.4160749568: 296598 Index: llvm/test/tools/llvm-profdata/Inputs/NoFUnique.proftext =================================================================== --- /dev/null +++ llvm/test/tools/llvm-profdata/Inputs/NoFUnique.proftext @@ -0,0 +1,30 @@ +# IR level Instrumentation Flag +:ir +_Z3barmi +# Func Hash: +784007056844089447 +# Num Counters: +2 +# Counter Values: +0 +0 + +main +# Func Hash: +784007059655560962 +# Num Counters: +2 +# Counter Values: +1 +0 + +test.c:_ZL3foom +# Func Hash: +1124680652115249575 +# Num Counters: +3 +# Counter Values: +0 +0 +0 + Index: llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext =================================================================== --- /dev/null +++ llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext @@ -0,0 +1,18 @@ +:ir +foo +7 +1 +0 + +goo +5 +3 +0 +0 +0 + +moo +9 +1 +0 + Index: llvm/test/tools/llvm-profdata/suppl-instr-with-sample-static-func.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-profdata/suppl-instr-with-sample-static-func.test @@ -0,0 +1,15 @@ +Some basic tests for supplementing instrumentation profile with sample profile for static funcs. + +RUN: llvm-profdata merge -supplement-instr-with-sample=%p/Inputs/NoFUnique.afdotext -suppl-min-size-threshold=2 %p/Inputs/NoFUnique.proftext -o %t1 +RUN: llvm-profdata show -function=foo -counts %t1 | FileCheck %s + +RUN: llvm-profdata merge -supplement-instr-with-sample=%p/Inputs/FUnique.afdotext -suppl-min-size-threshold=2 %p/Inputs/FUnique.proftext -o %t2 +RUN: llvm-profdata show -function=foo -counts %t2 | FileCheck %s + +RUN: llvm-profdata merge -supplement-instr-with-sample=%p/Inputs/NoFUnique.afdotext -suppl-min-size-threshold=2 %p/Inputs/FUnique.proftext -o %t3 +RUN: llvm-profdata show -function=foo -counts %t3 | FileCheck %s + +RUN: llvm-profdata merge -supplement-instr-with-sample=%p/Inputs/FUnique.afdotext -suppl-min-size-threshold=2 %p/Inputs/NoFUnique.proftext -o %t4 +RUN: llvm-profdata show -function=foo -counts %t4 | FileCheck %s + +CHECK: Block counts: [18446744073709551615, 18446744073709551615, 18446744073709551615] Index: llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test =================================================================== --- llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test +++ llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test @@ -64,21 +64,21 @@ RUN: llvm-profdata merge \ RUN: -supplement-instr-with-sample=%p/Inputs/mix_sample.proftext \ RUN: -suppl-min-size-threshold=2 -zero-counter-threshold=0.7 \ -RUN: -instr-prof-cold-threshold=30 %p/Inputs/mix_instr.proftext -o %t +RUN: -instr-prof-cold-threshold=30 %p/Inputs/mix_instr_small.proftext -o %t RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=MIX4 MIX4: foo: MIX4-NEXT: Hash: 0x0000000000000007 -MIX4-NEXT: Counters: 5 -MIX4-NEXT: Block counts: [12, 13, 0, 0, 0] +MIX4-NEXT: Counters: 1 +MIX4-NEXT: Block counts: [0] MIX4: goo: MIX4-NEXT: Hash: 0x0000000000000005 MIX4-NEXT: Counters: 3 MIX4-NEXT: Block counts: [18446744073709551615, 18446744073709551615, 18446744073709551615] MIX4: moo: MIX4-NEXT: Hash: 0x0000000000000009 -MIX4-NEXT: Counters: 4 -MIX4-NEXT: Block counts: [3000, 1000, 2000, 500] +MIX4-NEXT: Counters: 1 +MIX4-NEXT: Block counts: [0] Test profile summary won't be affected by -1 counter. RUN: llvm-profdata merge \ Index: llvm/tools/llvm-profdata/llvm-profdata.cpp =================================================================== --- llvm/tools/llvm-profdata/llvm-profdata.cpp +++ llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -31,6 +31,7 @@ #include "llvm/Support/Format.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/InitLLVM.h" +#include "llvm/Support/MD5.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/ThreadPool.h" @@ -461,6 +462,7 @@ /// The profile entry for a function in instrumentation profile. struct InstrProfileEntry { uint64_t MaxCount = 0; + uint64_t NumEdgeCounters = 0; float ZeroCounterRatio = 0.0; InstrProfRecord *ProfRecord; InstrProfileEntry(InstrProfRecord *Record); @@ -476,33 +478,42 @@ ZeroCntNum += !Record->Counts[I]; } ZeroCounterRatio = (float)ZeroCntNum / CntNum; + NumEdgeCounters = CntNum; } -/// Either set all the counters in the instr profile entry \p IFE to -1 -/// in order to drop the profile or scale up the counters in \p IFP to -/// be above hot threshold. We use the ratio of zero counters in the -/// profile of a function to decide the profile is helpful or harmful -/// for performance, and to choose whether to scale up or drop it. -static void updateInstrProfileEntry(InstrProfileEntry &IFE, +/// Either set all the counters in the instr profile entry \p IFE to +/// -1 / -2 /in order to drop the profile or scale up the +/// counters in \p IFP to be above hot / cold threshold. We use +/// the ratio of zero counters in the profile of a function to +/// decide the profile is helpful or harmful for performance, +/// and to choose whether to scale up or drop it. +static void updateInstrProfileEntry(InstrProfileEntry &IFE, bool SetToHot, uint64_t HotInstrThreshold, + uint64_t ColdInstrThreshold, float ZeroCounterThreshold) { InstrProfRecord *ProfRecord = IFE.ProfRecord; if (!IFE.MaxCount || IFE.ZeroCounterRatio > ZeroCounterThreshold) { // If all or most of the counters of the function are zero, the // profile is unaccountable and shuld be dropped. Reset all the - // counters to be -1 and PGO profile-use will drop the profile. - // All counters being -1 also implies that the function is hot so + // counters to be -1 / -2 and PGO profile-use will drop the profile. + // All counters being -1 implies that the function is hot so // PGO profile-use will also set the entry count metadata to be // above hot threshold. + // All counters being -2 implies that the function is warm so + // PGO profile-use will also set the entry count metadata to be + // above cold threshold. for (size_t I = 0; I < ProfRecord->Counts.size(); ++I) - ProfRecord->Counts[I] = -1; + ProfRecord->Counts[I] = (SetToHot ? -1 : -2); return; } // Scale up the MaxCount to be multiple times above hot threshold. const unsigned MultiplyFactor = 3; - uint64_t Numerator = HotInstrThreshold * MultiplyFactor; + uint64_t Threshold = (SetToHot ? HotInstrThreshold : ColdInstrThreshold); + uint64_t Numerator = Threshold * MultiplyFactor; uint64_t Denominator = IFE.MaxCount; + if (Numerator <= Denominator) + return; ProfRecord->scale(Numerator, Denominator, [&](instrprof_error E) { warn(toString(make_error(E))); }); @@ -539,7 +550,73 @@ unsigned InstrProfColdThreshold) { // Function to its entry in instr profile. StringMap InstrProfileMap; + StringMap StaticFuncMap; InstrProfSummaryBuilder IPBuilder(ProfileSummaryBuilder::DefaultCutoffs); + + auto checkSampleProfileHasFUnique = [&Reader]() { + for (const auto &PD : Reader->getProfiles()) { + auto &FContext = PD.first; + if (FContext.toString().find(FunctionSamples::UniqSuffix) != + std::string::npos) { + return true; + } + } + return false; + }; + + bool SampleProfileHasFUnique = checkSampleProfileHasFUnique(); + + auto buildStaticFuncMap = [&StaticFuncMap, + SampleProfileHasFUnique](const StringRef &Name) { + std::string Prefixes[] = {".cpp:", "cc:", ".c:", ".hpp:", ".h:"}; + size_t PrefixPos = StringRef::npos; + for (auto &Prefix : Prefixes) { + PrefixPos = Name.find_insensitive(Prefix); + if (PrefixPos == StringRef::npos) + continue; + PrefixPos += Prefix.size(); + break; + } + + if (PrefixPos == StringRef::npos) { + return; + } + + StringRef NewName = Name.drop_front(PrefixPos); + StringRef FName = Name.substr(0, PrefixPos - 1); + if (NewName.size() == 0) { + return; + } + + // This name should have a static linkage. + size_t PostfixPos = NewName.find(FunctionSamples::UniqSuffix); + bool ProfileHasFUnique = (PostfixPos != StringRef::npos); + + if (SampleProfileHasFUnique) { + // If profile also uses funqiue, nothing to do here. + // Otherwise, we need to build the map. + if (!ProfileHasFUnique) { + std::string NStr = + NewName.str() + getUniqueInternalLinkagePostfix(FName); + NewName = StringRef(NStr); + StaticFuncMap[NewName] = Name; + return; + } + } else { + // If profile does not use -funique-internal-linakge-symbols, nothing to + // do here. Otherwise, we need to trim. + if (ProfileHasFUnique) { + NewName = NewName.substr(0, PostfixPos); + } + } + + if (StaticFuncMap.find(NewName) == StaticFuncMap.end()) { + StaticFuncMap[NewName] = Name; + } else { + StaticFuncMap[NewName] = "---"; + } + }; + for (auto &PD : WC->Writer.getProfileData()) { // Populate IPBuilder. for (const auto &PDV : PD.getValue()) { @@ -553,13 +630,20 @@ // Initialize InstrProfileMap. InstrProfRecord *R = &PD.getValue().begin()->second; - InstrProfileMap[PD.getKey()] = InstrProfileEntry(R); + StringRef FullName = PD.getKey(); + InstrProfileMap[FullName] = InstrProfileEntry(R); + buildStaticFuncMap(FullName); } ProfileSummary InstrPS = *IPBuilder.getSummary(); ProfileSummary SamplePS = Reader->getSummary(); // Compute cold thresholds for instr profile and sample profile. + uint64_t HotSampleThreshold = + ProfileSummaryBuilder::getEntryForPercentile( + SamplePS.getDetailedSummary(), + ProfileSummaryBuilder::DefaultCutoffs[HotPercentileIdx]) + .MinCount; uint64_t ColdSampleThreshold = ProfileSummaryBuilder::getEntryForPercentile( SamplePS.getDetailedSummary(), @@ -584,12 +668,29 @@ auto &FContext = PD.first; const sampleprof::FunctionSamples &FS = PD.second; auto It = InstrProfileMap.find(FContext.toString()); - if (FS.getHeadSamples() > ColdSampleThreshold && - It != InstrProfileMap.end() && + if (It == InstrProfileMap.end()) { + auto NewName = StaticFuncMap.find(FContext.toString()); + if (NewName != StaticFuncMap.end()) { + It = InstrProfileMap.find(NewName->second.str()); + if (NewName->second == "---") { + WithColor::warning() + << "Static function " << FContext.toString() + << " has multiple promoted names, cannot adjust profile.\n"; + } + } + } + + uint64_t SampleMaxCount = FS.getMaxCountInside(); + if (SampleMaxCount < ColdSampleThreshold) + continue; + + if (It != InstrProfileMap.end() && It->second.MaxCount <= ColdInstrThreshold && - FS.getBodySamples().size() >= SupplMinSizeThreshold) { - updateInstrProfileEntry(It->second, HotInstrThreshold, - ZeroCounterThreshold); + It->second.NumEdgeCounters >= SupplMinSizeThreshold) { + bool SetToHot = SampleMaxCount >= HotSampleThreshold; + printf("set to hot is %d\n", SetToHot); + updateInstrProfileEntry(It->second, SetToHot, HotInstrThreshold, + ColdInstrThreshold, ZeroCounterThreshold); } } }