diff options
author | Sean Silva <chisophugis@gmail.com> | 2016-05-28 03:02:50 +0000 |
---|---|---|
committer | Sean Silva <chisophugis@gmail.com> | 2016-05-28 03:02:50 +0000 |
commit | 2a73019f3e031ccb474849f46fce7d8beb47d340 (patch) | |
tree | c69e227762fd1a855638441fcdc5a728192c9363 /llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | |
parent | 07d75185401a29ed640ec956947aad1bd34d6e63 (diff) | |
download | bcm5719-llvm-2a73019f3e031ccb474849f46fce7d8beb47d340.tar.gz bcm5719-llvm-2a73019f3e031ccb474849f46fce7d8beb47d340.zip |
[IRPGO] Centralize the function attribute inliner hint logic. NFC.
This keeps the logic in the same function.
llvm-svn: 271089
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 72 |
1 files changed, 29 insertions, 43 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 9b7eb1e4bf5..6f994eb2c7a 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -458,8 +458,7 @@ class PGOUseFunc { public: PGOUseFunc(Function &Func, Module *Modu, BranchProbabilityInfo *BPI = nullptr, BlockFrequencyInfo *BFI = nullptr) - : F(Func), M(Modu), FuncInfo(Func, false, BPI, BFI), - FreqAttr(FFA_Normal) {} + : F(Func), M(Modu), FuncInfo(Func, false, BPI, BFI) {} // Read counts for the instrumented BB from profile. bool readCounters(IndexedInstrProfReader *PGOReader); @@ -473,15 +472,15 @@ public: // Annotate the indirect call sites. void annotateIndirectCallSites(); - // The hotness of the function from the profile count. - enum FuncFreqAttr { FFA_Normal, FFA_Cold, FFA_Hot }; - - // Return the function hotness from the profile. - FuncFreqAttr getFuncFreqAttr() const { return FreqAttr; } - // Return the profile record for this function; InstrProfRecord &getProfileRecord() { return ProfileRecord; } + // The entry count of this function. + uint64_t EntryCount; + + // The maximum count value of any BB in this function. + uint64_t MaxBBCount; + private: Function &F; Module *M; @@ -493,16 +492,9 @@ private: return FuncInfo.getBBInfo(BB); } - // The maximum count value in the profile. This is only used in PGO use - // compilation. - uint64_t ProgramMaxCount; - // ProfileRecord for this function. InstrProfRecord ProfileRecord; - // Function hotness info derived from profile. - FuncFreqAttr FreqAttr; - // Find the Instrumented BB and set the value. void setInstrumentedCounts(const std::vector<uint64_t> &CountFromProfile); @@ -512,22 +504,6 @@ private: // Return FuncName string; const std::string getFuncName() const { return FuncInfo.FuncName; } - - // Set the hot/cold inline hints based on the count values. - // FIXME: This function should be removed once the functionality in - // the inliner is implemented. - void markFunctionAttributes(uint64_t EntryCount, uint64_t MaxCount) { - if (ProgramMaxCount == 0) - return; - // Threshold of the hot functions. - const BranchProbability HotFunctionThreshold(1, 100); - // Threshold of the cold functions. - const BranchProbability ColdFunctionThreshold(2, 10000); - if (EntryCount >= HotFunctionThreshold.scale(ProgramMaxCount)) - FreqAttr = FFA_Hot; - else if (MaxCount <= ColdFunctionThreshold.scale(ProgramMaxCount)) - FreqAttr = FFA_Cold; - } }; // Visit all the edges and assign the count value for the instrumented @@ -627,7 +603,6 @@ bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader) { getBBInfo(nullptr).UnknownCountInEdge = 2; setInstrumentedCounts(CountFromProfile); - ProgramMaxCount = PGOReader->getMaximumFunctionCount(); return true; } @@ -691,16 +666,14 @@ void PGOUseFunc::populateCounters() { } DEBUG(dbgs() << "Populate counts in " << NumPasses << " passes.\n"); - // Assert every BB has a valid counter. - uint64_t FuncEntryCount = getBBInfo(&*F.begin()).CountValue; - uint64_t FuncMaxCount = FuncEntryCount; + + EntryCount = getBBInfo(&*F.begin()).CountValue; + MaxBBCount = 0; for (auto &BB : F) { + // Assert every BB has a valid counter. assert(getBBInfo(&BB).CountValid && "BB count is not valid"); - uint64_t Count = getBBInfo(&BB).CountValue; - if (Count > FuncMaxCount) - FuncMaxCount = Count; + MaxBBCount = std::max(MaxBBCount, getBBInfo(&BB).CountValue); } - markFunctionAttributes(FuncEntryCount, FuncMaxCount); DEBUG(FuncInfo.dumpInfo("after reading profile.")); } @@ -888,6 +861,8 @@ static bool annotateAllFunctions( std::vector<Function *> HotFunctions; std::vector<Function *> ColdFunctions; InstrProfSummaryBuilder Builder(ProfileSummaryBuilder::DefaultCutoffs); + uint64_t ProgramMaxCount = PGOReader->getMaximumFunctionCount(); + bool HasProgramMaxCount = ProgramMaxCount != 0; for (auto &F : M) { if (F.isDeclaration()) continue; @@ -897,14 +872,25 @@ static bool annotateAllFunctions( setPGOCountOnFunc(Func, PGOReader.get()); if (!Func.getProfileRecord().Counts.empty()) Builder.addRecord(Func.getProfileRecord()); - PGOUseFunc::FuncFreqAttr FreqAttr = Func.getFuncFreqAttr(); - if (FreqAttr == PGOUseFunc::FFA_Cold) - ColdFunctions.push_back(&F); - else if (FreqAttr == PGOUseFunc::FFA_Hot) + + if (!HasProgramMaxCount) + continue; + // Set the hot/cold inline hints based on the count values. + // FIXME: This should be removed once the functionality in + // the inliner is implemented. + const BranchProbability HotFunctionThreshold(1, 100); + const BranchProbability ColdFunctionThreshold(2, 10000); + if (Func.EntryCount >= HotFunctionThreshold.scale(ProgramMaxCount)) HotFunctions.push_back(&F); + else if (Func.MaxBBCount <= ColdFunctionThreshold.scale(ProgramMaxCount)) + ColdFunctions.push_back(&F); } M.setProfileSummary(Builder.getSummary()->getMD(M.getContext())); + // Set function hotness attribute from the profile. + // We have to apply these attributes at the end because their presence + // can affect the BranchProbabilityInfo of any callers, resulting in an + // inconsistent MST between prof-gen and prof-use. for (auto &F : HotFunctions) { F->addFnAttr(llvm::Attribute::InlineHint); DEBUG(dbgs() << "Set inline attribute to function: " << F->getName() |