[llvm-branch-commits] [llvm] [BOLT] Propagate BOLTErrors from Core, RewriteInstance, and passes (2/2) (PR #81523)

Amir Ayupov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 12 14:38:35 PST 2024


https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/81523

>From 17ab8e592a01d4402e88de21c8f66742134b64f3 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 12 Feb 2024 12:42:25 -0800
Subject: [PATCH 1/2] Fix build

Created using spr 1.3.4
---
 bolt/lib/Rewrite/MachORewriteInstance.cpp |  4 ++--
 bolt/lib/Rewrite/RewriteInstance.cpp      | 11 ++++++-----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/bolt/lib/Rewrite/MachORewriteInstance.cpp b/bolt/lib/Rewrite/MachORewriteInstance.cpp
index 8be8257f15c1ce..c2a6c1f88ab070 100644
--- a/bolt/lib/Rewrite/MachORewriteInstance.cpp
+++ b/bolt/lib/Rewrite/MachORewriteInstance.cpp
@@ -337,7 +337,7 @@ void MachORewriteInstance::disassembleFunctions() {
     BinaryFunction &Function = BFI.second;
     if (!Function.isSimple())
       continue;
-    Function.disassemble();
+    cantFail(Function.disassemble());
     if (opts::PrintDisasm)
       Function.print(outs(), "after disassembly");
   }
@@ -387,7 +387,7 @@ void MachORewriteInstance::runOptimizationPasses() {
   Manager.registerPass(
       std::make_unique<FinalizeFunctions>(opts::PrintFinalized));
 
-  Manager.runPasses();
+  cantFail(Manager.runPasses());
 }
 
 void MachORewriteInstance::mapInstrumentationSection(
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index cc994c213482d4..06aed246de0cf2 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1283,7 +1283,7 @@ void RewriteInstance::discoverFileObjects() {
                                                    /*UseMaxSize*/ true);
         if (BF) {
           assert(Rel.isRelative() && "Expected relative relocation for island");
-          BF->markIslandDynamicRelocationAtAddress(RelAddress);
+          cantFail(BF->markIslandDynamicRelocationAtAddress(RelAddress));
         }
       }
     }
@@ -2859,8 +2859,9 @@ void RewriteInstance::selectFunctionsToProcess() {
   StringSet<> ReorderFunctionsUserSet;
   StringSet<> ReorderFunctionsLTOCommonSet;
   if (opts::ReorderFunctions == ReorderFunctions::RT_USER) {
-    for (const std::string &Function :
-         ReorderFunctions::readFunctionOrderFile()) {
+    std::vector<std::string> FunctionNames;
+    cantFail(ReorderFunctions::readFunctionOrderFile(FunctionNames));
+    for (const std::string &Function : FunctionNames) {
       ReorderFunctionsUserSet.insert(Function);
       if (std::optional<StringRef> LTOCommonName = getLTOCommonName(Function))
         ReorderFunctionsLTOCommonSet.insert(*LTOCommonName);
@@ -3207,7 +3208,7 @@ void RewriteInstance::disassembleFunctions() {
       check_error(LSDASection.getError(), "failed to get LSDA section");
       ArrayRef<uint8_t> LSDAData = ArrayRef<uint8_t>(
           LSDASection->getData(), LSDASection->getContents().size());
-      Function.parseLSDA(LSDAData, LSDASection->getAddress());
+      cantFail(Function.parseLSDA(LSDAData, LSDASection->getAddress()));
     }
   }
 }
@@ -3298,7 +3299,7 @@ void RewriteInstance::postProcessFunctions() {
 void RewriteInstance::runOptimizationPasses() {
   NamedRegionTimer T("runOptimizationPasses", "run optimization passes",
                      TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
-  BinaryFunctionPassManager::runAllPasses(*BC);
+  cantFail(BinaryFunctionPassManager::runAllPasses(*BC));
 }
 
 void RewriteInstance::preregisterSections() {

>From cb5a6939b09a88e1f1442d8ea761a04b2fcad332 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 12 Feb 2024 13:52:48 -0800
Subject: [PATCH 2/2] Handle BOLTErrors in runOptimizationPasses

Created using spr 1.3.4
---
 bolt/lib/Rewrite/RewriteInstance.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 06aed246de0cf2..829568cefff01f 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -3299,7 +3299,11 @@ void RewriteInstance::postProcessFunctions() {
 void RewriteInstance::runOptimizationPasses() {
   NamedRegionTimer T("runOptimizationPasses", "run optimization passes",
                      TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
-  cantFail(BinaryFunctionPassManager::runAllPasses(*BC));
+  handleAllErrors(BinaryFunctionPassManager::runAllPasses(*BC),
+                  [](const BOLTError &E) {
+                    E.log(errs());
+                    exit(1);
+                  });
 }
 
 void RewriteInstance::preregisterSections() {



More information about the llvm-branch-commits mailing list