From caa0fafa18e4e6a468e9ee585e4d714c1f6cb0b3 Mon Sep 17 00:00:00 2001 From: Maksim Panchenko Date: Fri, 26 Apr 2019 16:32:28 -0700 Subject: [PATCH] [BOLT] Fix profile reading in non-reloc mode Summary: In non-relocation mode we may execute multiple re-write passes either because we need to split large functions or update debug information for large functions (in this context large functions are functions that do not fit into the original function boundaries after optimizations). When we execute another pass, we reset RewriteInstance and run most of the steps such as disassembly and profile matching for the 2nd or 3rd time. However, when we match a profile, we check `Used` flag, and don't use the profile for the 2nd time. Since we didn't reset the flag while resetting the rest of the states, we ignored profile for all functions. Resetting the flag in-between rewrite passes solves the problem. (cherry picked from FBD15110959) --- bolt/src/DataReader.cpp | 9 +++++++++ bolt/src/DataReader.h | 3 +++ bolt/src/RewriteInstance.cpp | 1 + 3 files changed, 13 insertions(+) diff --git a/bolt/src/DataReader.cpp b/bolt/src/DataReader.cpp index 65f67c3bce7d..c84773467a99 100644 --- a/bolt/src/DataReader.cpp +++ b/bolt/src/DataReader.cpp @@ -251,6 +251,15 @@ void FuncMemData::update(const Location &Offset, const Location &Addr) { ++Data[Iter->second].Count; } +void DataReader::reset() { + for (auto &Pair : getAllFuncsBranchData()) { + Pair.second.Used = false; + } + for (auto &Pair : getAllFuncsMemData()) { + Pair.second.Used = false; + } +} + ErrorOr> DataReader::readPerfData(StringRef Path, raw_ostream &Diag) { auto MB = MemoryBuffer::getFileOrSTDIN(Path); diff --git a/bolt/src/DataReader.h b/bolt/src/DataReader.h index 50b901b9f5b5..342db39c12d6 100644 --- a/bolt/src/DataReader.h +++ b/bolt/src/DataReader.h @@ -303,6 +303,9 @@ public: static ErrorOr> readPerfData(StringRef Path, raw_ostream &Diag); + /// Mark all profile objects unused. + void reset(); + /// Parses the input bolt data file into internal data structures. We expect /// the file format to follow the syntax below. /// diff --git a/bolt/src/RewriteInstance.cpp b/bolt/src/RewriteInstance.cpp index 0c3a51d28e32..8c2fbad93c03 100644 --- a/bolt/src/RewriteInstance.cpp +++ b/bolt/src/RewriteInstance.cpp @@ -725,6 +725,7 @@ RewriteInstance::~RewriteInstance() {} void RewriteInstance::reset() { FileSymRefs.clear(); auto &DR = BC->DR; + DR.reset(); BC = createBinaryContext( InputFile, DR, DWARFContext::create(*InputFile, nullptr,