diff options
| author | Sean Silva <chisophugis@gmail.com> | 2016-05-28 03:56:25 +0000 |
|---|---|---|
| committer | Sean Silva <chisophugis@gmail.com> | 2016-05-28 03:56:25 +0000 |
| commit | 9dd4b5c51da161161c1091bc30d969a21c759765 (patch) | |
| tree | f2688531057bd3e1e827d2fd7d2700a7cefd8db5 | |
| parent | 7884633c5b0660fb613af2e8fcfb03e9f9e54af6 (diff) | |
| download | bcm5719-llvm-9dd4b5c51da161161c1091bc30d969a21c759765.tar.gz bcm5719-llvm-9dd4b5c51da161161c1091bc30d969a21c759765.zip | |
Revert r271089 and r271090.
It was triggering an msan bot.
Revert "[IRPGO] Set the function entry count metadata."
This reverts commit r271090.
Revert "[IRPGO] Centralize the function attribute inliner hint logic. NFC."
This reverts commit r271089.
llvm-svn: 271091
| -rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 73 | ||||
| -rw-r--r-- | llvm/test/Transforms/PGOProfile/branch1.ll | 3 |
2 files changed, 43 insertions, 33 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 4c4784e2394..9b7eb1e4bf5 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -458,7 +458,8 @@ class PGOUseFunc { public: PGOUseFunc(Function &Func, Module *Modu, BranchProbabilityInfo *BPI = nullptr, BlockFrequencyInfo *BFI = nullptr) - : F(Func), M(Modu), FuncInfo(Func, false, BPI, BFI) {} + : F(Func), M(Modu), FuncInfo(Func, false, BPI, BFI), + FreqAttr(FFA_Normal) {} // Read counts for the instrumented BB from profile. bool readCounters(IndexedInstrProfReader *PGOReader); @@ -472,14 +473,14 @@ public: // Annotate the indirect call sites. void annotateIndirectCallSites(); - // Return the profile record for this function; - InstrProfRecord &getProfileRecord() { return ProfileRecord; } + // The hotness of the function from the profile count. + enum FuncFreqAttr { FFA_Normal, FFA_Cold, FFA_Hot }; - // The entry count of this function. - uint64_t EntryCount; + // Return the function hotness from the profile. + FuncFreqAttr getFuncFreqAttr() const { return FreqAttr; } - // The maximum count value of any BB in this function. - uint64_t MaxBBCount; + // Return the profile record for this function; + InstrProfRecord &getProfileRecord() { return ProfileRecord; } private: Function &F; @@ -492,9 +493,16 @@ 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); @@ -504,6 +512,22 @@ 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 @@ -603,6 +627,7 @@ bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader) { getBBInfo(nullptr).UnknownCountInEdge = 2; setInstrumentedCounts(CountFromProfile); + ProgramMaxCount = PGOReader->getMaximumFunctionCount(); return true; } @@ -666,14 +691,16 @@ void PGOUseFunc::populateCounters() { } DEBUG(dbgs() << "Populate counts in " << NumPasses << " passes.\n"); - - EntryCount = getBBInfo(&*F.begin()).CountValue; - MaxBBCount = 0; + // Assert every BB has a valid counter. + uint64_t FuncEntryCount = getBBInfo(&*F.begin()).CountValue; + uint64_t FuncMaxCount = FuncEntryCount; for (auto &BB : F) { - // Assert every BB has a valid counter. assert(getBBInfo(&BB).CountValid && "BB count is not valid"); - MaxBBCount = std::max(MaxBBCount, getBBInfo(&BB).CountValue); + uint64_t Count = getBBInfo(&BB).CountValue; + if (Count > FuncMaxCount) + FuncMaxCount = Count; } + markFunctionAttributes(FuncEntryCount, FuncMaxCount); DEBUG(FuncInfo.dumpInfo("after reading profile.")); } @@ -861,8 +888,6 @@ 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; @@ -870,28 +895,16 @@ static bool annotateAllFunctions( auto *BFI = LookupBFI(F); PGOUseFunc Func(F, &M, BPI, BFI); setPGOCountOnFunc(Func, PGOReader.get()); - F.setEntryCount(Func.EntryCount); if (!Func.getProfileRecord().Counts.empty()) Builder.addRecord(Func.getProfileRecord()); - - 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)) + PGOUseFunc::FuncFreqAttr FreqAttr = Func.getFuncFreqAttr(); + if (FreqAttr == PGOUseFunc::FFA_Cold) ColdFunctions.push_back(&F); + else if (FreqAttr == PGOUseFunc::FFA_Hot) + HotFunctions.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() diff --git a/llvm/test/Transforms/PGOProfile/branch1.ll b/llvm/test/Transforms/PGOProfile/branch1.ll index b2c7bcc2c19..380a293ca0e 100644 --- a/llvm/test/Transforms/PGOProfile/branch1.ll +++ b/llvm/test/Transforms/PGOProfile/branch1.ll @@ -21,8 +21,6 @@ target triple = "x86_64-unknown-linux-gnu" ; GEN: @__profn_test_br_1 = private constant [9 x i8] c"test_br_1" define i32 @test_br_1(i32 %i) { -; USE-LABEL: @test_br_1 -; USE-SAME: !prof ![[FUNC_ENTRY_COUNT:[0-9]+]] entry: ; GEN: entry: ; GEN-NOT: llvm.instrprof.increment @@ -46,4 +44,3 @@ if.end: } ; USE-DAG: {{![0-9]+}} = !{i32 1, !"ProfileSummary", {{![0-9]+}}} ; USE-DAG: {{![0-9]+}} = !{!"DetailedSummary", {{![0-9]+}}} -; USE-DAG: ![[FUNC_ENTRY_COUNT]] = !{!"function_entry_count", i64 3} |

