[PATCH] D74113: [llvm-exegesis] Improve error reporting in Target.cpp

Miloš Stojanović via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 6 02:08:36 PST 2020


mstojanovic created this revision.
mstojanovic added reviewers: courbet, gchatelet, petarj.
Herald added a subscriber: tschuett.
Herald added a project: LLVM.

Followup to D74085 <https://reviews.llvm.org/D74085>.
Replace the use of `report_fatal_error()` with returning the error to `llvm-exegesis.cpp` and handling it there.


https://reviews.llvm.org/D74113

Files:
  llvm/tools/llvm-exegesis/lib/Target.cpp
  llvm/tools/llvm-exegesis/lib/Target.h
  llvm/tools/llvm-exegesis/llvm-exegesis.cpp


Index: llvm/tools/llvm-exegesis/llvm-exegesis.cpp
===================================================================
--- llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -263,8 +263,8 @@
 
   const LLVMState State(CpuName);
 
-  const std::unique_ptr<BenchmarkRunner> Runner =
-      State.getExegesisTarget().createBenchmarkRunner(BenchmarkMode, State);
+  const std::unique_ptr<BenchmarkRunner> Runner = ExitOnErr(
+      State.getExegesisTarget().createBenchmarkRunner(BenchmarkMode, State));
   if (!Runner) {
     ExitWithError("cannot create benchmark runner");
   }
Index: llvm/tools/llvm-exegesis/lib/Target.h
===================================================================
--- llvm/tools/llvm-exegesis/lib/Target.h
+++ llvm/tools/llvm-exegesis/lib/Target.h
@@ -132,7 +132,7 @@
                          const LLVMState &State,
                          const SnippetGenerator::Options &Opts) const;
   // Creates a benchmark runner for the given mode.
-  std::unique_ptr<BenchmarkRunner>
+  Expected<std::unique_ptr<BenchmarkRunner>>
   createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
                         const LLVMState &State) const;
 
Index: llvm/tools/llvm-exegesis/lib/Target.cpp
===================================================================
--- llvm/tools/llvm-exegesis/lib/Target.cpp
+++ llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -53,7 +53,7 @@
   return nullptr;
 }
 
-std::unique_ptr<BenchmarkRunner>
+Expected<std::unique_ptr<BenchmarkRunner>>
 ExegesisTarget::createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
                                       const LLVMState &State) const {
   PfmCountersInfo PfmCounters = State.getPfmCounters();
@@ -66,14 +66,16 @@
       const char *ModeName = Mode == InstructionBenchmark::Latency
                                  ? "latency"
                                  : "inverse_throughput";
-      report_fatal_error(Twine("can't run '").concat(ModeName).concat("' mode, "
-                               "sched model does not define a cycle counter."));
+      return make_error<Failure>(
+          Twine("can't run '")
+              .concat(ModeName)
+              .concat("' mode, sched model does not define a cycle counter."));
     }
     return createLatencyBenchmarkRunner(State, Mode);
   case InstructionBenchmark::Uops:
     if (!PfmCounters.UopsCounter && !PfmCounters.IssueCounters)
-      report_fatal_error("can't run 'uops' mode, sched model does not define "
-                         "uops or issue counters.");
+      return make_error<Failure>("can't run 'uops' mode, sched model does not "
+                                 "define uops or issue counters.");
     return createUopsBenchmarkRunner(State);
   }
   return nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74113.242836.patch
Type: text/x-patch
Size: 2787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200206/988329ae/attachment.bin>


More information about the llvm-commits mailing list