diff --git a/bolt/src/RewriteInstance.cpp b/bolt/src/RewriteInstance.cpp index 1a115e76ab20..6dffca66d66e 100644 --- a/bolt/src/RewriteInstance.cpp +++ b/bolt/src/RewriteInstance.cpp @@ -70,6 +70,7 @@ #include #include #include +#include #undef DEBUG_TYPE #define DEBUG_TYPE "bolt" @@ -784,8 +785,13 @@ bool RewriteInstance::shouldDisassemble(const BinaryFunction &BF) const { return false; } - // In strict mode we have to account for all functions. - if (!opts::StrictMode && opts::AggregateOnly && !BF.hasProfileAvailable()) + // If we are running in profile conversion mode and there is no profile + // available for the function, we can skip the disassembly. + // However, in strict relocation mode we need to account for all + // functions. Also, when multi-threading is enabled, the profile may not be + // available yet, and we conservatively disassemble the function. + if (opts::AggregateOnly && opts::NoThreads && !opts::StrictMode && + !BF.hasProfileAvailable()) return false; return true; @@ -1053,18 +1059,31 @@ void RewriteInstance::run() { readSpecialSections(); adjustCommandLineOptions(); discoverFileObjects(); - preprocessProfileData(); - if (opts::AggregateOnly && DA.usesBAT()) { - // Skip disassembling if we have a translation table and we running an - // aggregation job. - processProfileData(); - return; - } + + std::thread PreProcessProfileThread([&]() { + outs() << "BOLT-INFO: spawning thread to pre-process profile\n"; + preprocessProfileData(); + }); + + if (opts::NoThreads) + PreProcessProfileThread.join(); + readDebugInfo(); - disassembleFunctions(); + + // Skip disassembling if we have a translation table and we are running an + // aggregation job. + if (!opts::AggregateOnly || !DA.usesBAT()) { + disassembleFunctions(); + } + + if (PreProcessProfileThread.joinable()) + PreProcessProfileThread.join(); + processProfileData(); + if (opts::AggregateOnly) return; + postProcessFunctions(); for (uint64_t Address : NonSimpleFunctions) { auto *BF = BC->getBinaryFunctionAtAddress(Address); @@ -1980,6 +1999,13 @@ void RewriteInstance::adjustCommandLineOptions() { opts::StrictMode = false; } + if (BC->HasRelocations && opts::AggregateOnly && + !opts::StrictMode.getNumOccurrences()) { + outs() << "BOLT-INFO: enabling strict relocation mode for aggregtion " + "purposes\n"; + opts::StrictMode = true; + } + if (BC->isX86() && BC->HasRelocations && opts::AlignMacroOpFusion == MFT_HOT && !DA.started() && BC->DR.getAllFuncsData().empty() &&