diff options
| author | Rafael Auler <rafaelauler@fb.com> | 2024-02-06 11:18:23 -0800 |
|---|---|---|
| committer | Rafael Auler <rafaelauler@fb.com> | 2024-02-09 19:12:23 -0800 |
| commit | c1781b770d1400b62b3c324157a7895c1b9bdaaa (patch) | |
| tree | 7ad6ba005f52a88f4670d30d28cfe2018a5f7593 /bolt/lib/Rewrite/BinaryPassManager.cpp | |
| parent | 2df42fe0efd92a89ae191a598e2727c7b63de80b (diff) | |
[BOLT][NFC] Refactor logging and error handlingusers/rafaelauler/bolt-logging-pr
Make core BOLT functionality more friendly to being used as a
library instead of in our standalone driver llvm-bolt. To accomplish
this, we augment BinaryContext with journaling streams that are to be
used by most BOLT code whenever something needs to be logged to the
screen. Users of the library can decide if logs should be printed to a
file, no file or to the screen, as before. To illustrate this, this
patch adds a new option --log-file that allows the user to redirect
BOLT logging to a file on disk or completely hide it by using
--log-file=/dev/null. Future BOLT code should now use
BinaryContext::outs() for printing important messages instead of
llvm::outs(). A new test log.test enforces this by verifying that no
strings are print to screen once the --log-file option is used.
We also refactor old error handling code that would directly call
exit(1) inside BOLT libraries whenever a serious problem occurred. To
overcome this, we add a new class BOLTError and auxiliary functions
createFatalBOLTError() and createNonFatalBOLTError() that allows BOLT
libs to bubble up the problem to the caller by using the Error class
as a return type (or Expected). To easily handle problems as before
(by quitting with exit(1)), callers can now use
BinaryContext::logBOLTErrorsAndQuitOnFatal(Error) whenever code needs
to deal with BOLT errors. To test this, we have fatal.s that checks
we are correctly quitting and printing a fatal error to the screen.
Because this is a significant change by itself, not all code was yet
ported. Code from Profiler libs (DataAggregator and friends) still
print errors directly to screen.
Diffstat (limited to 'bolt/lib/Rewrite/BinaryPassManager.cpp')
| -rw-r--r-- | bolt/lib/Rewrite/BinaryPassManager.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/bolt/lib/Rewrite/BinaryPassManager.cpp b/bolt/lib/Rewrite/BinaryPassManager.cpp index 9946608c96d8..489b33fe1c7c 100644 --- a/bolt/lib/Rewrite/BinaryPassManager.cpp +++ b/bolt/lib/Rewrite/BinaryPassManager.cpp @@ -268,7 +268,7 @@ const char BinaryFunctionPassManager::TimerGroupName[] = "passman"; const char BinaryFunctionPassManager::TimerGroupDesc[] = "Binary Function Pass Manager"; -void BinaryFunctionPassManager::runPasses() { +Error BinaryFunctionPassManager::runPasses() { auto &BFs = BC.getBinaryFunctions(); for (size_t PassIdx = 0; PassIdx < Passes.size(); PassIdx++) { const std::pair<const bool, std::unique_ptr<BinaryFunctionPass>> @@ -281,13 +281,20 @@ void BinaryFunctionPassManager::runPasses() { formatv("{0:2}_{1}", PassIdx, Pass->getName()).str(); if (opts::Verbosity > 0) - outs() << "BOLT-INFO: Starting pass: " << Pass->getName() << "\n"; + BC.outs() << "BOLT-INFO: Starting pass: " << Pass->getName() << "\n"; NamedRegionTimer T(Pass->getName(), Pass->getName(), TimerGroupName, TimerGroupDesc, TimeOpts); - callWithDynoStats([this, &Pass] { Pass->runOnFunctions(BC); }, BFs, - Pass->getName(), opts::DynoStatsAll, BC.isAArch64()); + Error E = Error::success(); + callWithDynoStats( + BC.outs(), + [this, &E, &Pass] { + E = joinErrors(std::move(E), Pass->runOnFunctions(BC)); + }, + BFs, Pass->getName(), opts::DynoStatsAll, BC.isAArch64()); + if (E) + return Error(std::move(E)); if (opts::VerifyCFG && !std::accumulate( @@ -296,13 +303,13 @@ void BinaryFunctionPassManager::runPasses() { const std::pair<const uint64_t, BinaryFunction> &It) { return Valid && It.second.validateCFG(); })) { - errs() << "BOLT-ERROR: Invalid CFG detected after pass " - << Pass->getName() << "\n"; - exit(1); + return createFatalBOLTError( + Twine("BOLT-ERROR: Invalid CFG detected after pass ") + + Twine(Pass->getName()) + Twine("\n")); } if (opts::Verbosity > 0) - outs() << "BOLT-INFO: Finished pass: " << Pass->getName() << "\n"; + BC.outs() << "BOLT-INFO: Finished pass: " << Pass->getName() << "\n"; if (!opts::PrintAll && !opts::DumpDotAll && !Pass->printPass()) continue; @@ -315,15 +322,16 @@ void BinaryFunctionPassManager::runPasses() { if (!Pass->shouldPrint(Function)) continue; - Function.print(outs(), Message); + Function.print(BC.outs(), Message); if (opts::DumpDotAll) Function.dumpGraphForPass(PassIdName); } } + return Error::success(); } -void BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) { +Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) { BinaryFunctionPassManager Manager(BC); const DynoStats InitialDynoStats = @@ -516,7 +524,7 @@ void BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) { // in parallel and restore them Manager.registerPass(std::make_unique<CleanMCState>(NeverPrint)); - Manager.runPasses(); + return Manager.runPasses(); } } // namespace bolt |
