[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)
This commit is contained in:
Maksim Panchenko 2019-04-26 16:32:28 -07:00
parent 5717b0c427
commit caa0fafa18
3 changed files with 13 additions and 0 deletions

View File

@ -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<std::unique_ptr<DataReader>>
DataReader::readPerfData(StringRef Path, raw_ostream &Diag) {
auto MB = MemoryBuffer::getFileOrSTDIN(Path);

View File

@ -303,6 +303,9 @@ public:
static ErrorOr<std::unique_ptr<DataReader>> 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.
///

View File

@ -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,