[llvm] eb1905d - opt: Don't exit when we can't create a TargetMachine

Alex Richardson via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 4 14:17:43 PDT 2023


Author: Alex Richardson
Date: 2023-10-04T14:17:09-07:00
New Revision: eb1905d2b6928be4b0258f021d145432ab7d292e

URL: https://github.com/llvm/llvm-project/commit/eb1905d2b6928be4b0258f021d145432ab7d292e
DIFF: https://github.com/llvm/llvm-project/commit/eb1905d2b6928be4b0258f021d145432ab7d292e.diff

LOG: opt: Don't exit when we can't create a TargetMachine

This more closly matches the previous behaviour that silently ignored the
failure. We now print a warning instead of exiting.
Fixes: a8f8613dec435cfb78bf202c392f2acf150a5937

Added: 
    

Modified: 
    llvm/tools/opt/opt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index a578bea7d62172c..ed9c10d971218f1 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -392,7 +392,6 @@ static bool shouldForceLegacyPM() {
 //
 int main(int argc, char **argv) {
   InitLLVM X(argc, argv);
-  ExitOnError ExitOnErr(std::string(argv[0]) + ": error: ");
 
   // Enable debug stream buffering.
   EnableDebugBuffering = true;
@@ -598,8 +597,15 @@ int main(int argc, char **argv) {
   if (ModuleTriple.getArch()) {
     CPUStr = codegen::getCPUStr();
     FeaturesStr = codegen::getFeaturesStr();
-    TM = ExitOnErr(codegen::createTargetMachineForTriple(ModuleTriple.str(),
-                                                         GetCodeGenOptLevel()));
+    Expected<std::unique_ptr<TargetMachine>> ExpectedTM =
+        codegen::createTargetMachineForTriple(ModuleTriple.str(),
+                                              GetCodeGenOptLevel());
+    if (auto E = ExpectedTM.takeError()) {
+      errs() << argv[0] << ": WARNING: failed to create target machine for '"
+             << ModuleTriple.str() << "': " << toString(std::move(E)) << "\n";
+    } else {
+      TM = std::move(*ExpectedTM);
+    }
   } else if (ModuleTriple.getArchName() != "unknown" &&
              ModuleTriple.getArchName() != "") {
     errs() << argv[0] << ": unrecognized architecture '"


        


More information about the llvm-commits mailing list