summaryrefslogtreecommitdiff
path: root/bolt/lib/Passes/SplitFunctions.cpp
diff options
context:
space:
mode:
authorRafael Auler <rafaelauler@fb.com>2024-02-06 11:18:23 -0800
committerRafael Auler <rafaelauler@fb.com>2024-02-09 19:12:23 -0800
commitc1781b770d1400b62b3c324157a7895c1b9bdaaa (patch)
tree7ad6ba005f52a88f4670d30d28cfe2018a5f7593 /bolt/lib/Passes/SplitFunctions.cpp
parent2df42fe0efd92a89ae191a598e2727c7b63de80b (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/Passes/SplitFunctions.cpp')
-rw-r--r--bolt/lib/Passes/SplitFunctions.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/bolt/lib/Passes/SplitFunctions.cpp b/bolt/lib/Passes/SplitFunctions.cpp
index 5de075973004..cdbb2a15f667 100644
--- a/bolt/lib/Passes/SplitFunctions.cpp
+++ b/bolt/lib/Passes/SplitFunctions.cpp
@@ -712,15 +712,15 @@ bool SplitFunctions::shouldOptimize(const BinaryFunction &BF) const {
return BinaryFunctionPass::shouldOptimize(BF);
}
-void SplitFunctions::runOnFunctions(BinaryContext &BC) {
+Error SplitFunctions::runOnFunctions(BinaryContext &BC) {
if (!opts::SplitFunctions)
- return;
+ return Error::success();
// If split strategy is not CDSplit, then a second run of the pass is not
// needed after function reordering.
if (BC.HasFinalizedFunctionOrder &&
opts::SplitStrategy != SplitFunctionsStrategy::CDSplit)
- return;
+ return Error::success();
std::unique_ptr<SplitStrategy> Strategy;
bool ForceSequential = false;
@@ -766,10 +766,12 @@ void SplitFunctions::runOnFunctions(BinaryContext &BC) {
"SplitFunctions", ForceSequential);
if (SplitBytesHot + SplitBytesCold > 0)
- outs() << "BOLT-INFO: splitting separates " << SplitBytesHot
- << " hot bytes from " << SplitBytesCold << " cold bytes "
- << format("(%.2lf%% of split functions is hot).\n",
- 100.0 * SplitBytesHot / (SplitBytesHot + SplitBytesCold));
+ BC.outs() << "BOLT-INFO: splitting separates " << SplitBytesHot
+ << " hot bytes from " << SplitBytesCold << " cold bytes "
+ << format("(%.2lf%% of split functions is hot).\n",
+ 100.0 * SplitBytesHot /
+ (SplitBytesHot + SplitBytesCold));
+ return Error::success();
}
void SplitFunctions::splitFunction(BinaryFunction &BF, SplitStrategy &S) {
@@ -899,9 +901,9 @@ void SplitFunctions::splitFunction(BinaryFunction &BF, SplitStrategy &S) {
if (alignTo(OriginalHotSize, opts::SplitAlignThreshold) <=
alignTo(HotSize, opts::SplitAlignThreshold) + opts::SplitThreshold) {
if (opts::Verbosity >= 2) {
- outs() << "BOLT-INFO: Reversing splitting of function "
- << formatv("{0}:\n {1:x}, {2:x} -> {3:x}\n", BF, HotSize,
- ColdSize, OriginalHotSize);
+ BC.outs() << "BOLT-INFO: Reversing splitting of function "
+ << formatv("{0}:\n {1:x}, {2:x} -> {3:x}\n", BF, HotSize,
+ ColdSize, OriginalHotSize);
}
// Reverse the action of createEHTrampolines(). The trampolines will be