[llvm] r373209 - [llvm-exegesis][NFC] Move BenchmarkFailure to own file.

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 06:53:50 PDT 2019


Author: courbet
Date: Mon Sep 30 06:53:50 2019
New Revision: 373209

URL: http://llvm.org/viewvc/llvm-project?rev=373209&view=rev
Log:
[llvm-exegesis][NFC] Move BenchmarkFailure to own file.

Summary: And rename to exegesis::Failure, as it's used everytwhere.

Reviewers: gchatelet

Subscribers: tschuett, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D68217

Added:
    llvm/trunk/tools/llvm-exegesis/lib/Error.h
Modified:
    llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
    llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
    llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h
    llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp
    llvm/trunk/tools/llvm-exegesis/lib/Latency.h
    llvm/trunk/tools/llvm-exegesis/lib/SnippetFile.cpp
    llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp
    llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp
    llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp

Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp?rev=373209&r1=373208&r2=373209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp Mon Sep 30 06:53:50 2019
@@ -8,6 +8,7 @@
 
 #include "BenchmarkResult.h"
 #include "BenchmarkRunner.h"
+#include "Error.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringMap.h"
@@ -343,7 +344,7 @@ InstructionBenchmark::readYaml(const LLV
     if (Yin.setCurrentDocument())
       llvm::yaml::yamlize(Yin, Benchmark, /*unused*/ true, Context);
     if (!Context.getLastError().empty())
-      return llvm::make_error<BenchmarkFailure>(Context.getLastError());
+      return make_error<Failure>(Context.getLastError());
     return Benchmark;
   } else {
     return ExpectedMemoryBuffer.takeError();
@@ -364,7 +365,7 @@ InstructionBenchmark::readYamls(const LL
       if (Yin.error())
         return llvm::errorCodeToError(Yin.error());
       if (!Context.getLastError().empty())
-        return llvm::make_error<BenchmarkFailure>(Context.getLastError());
+        return make_error<Failure>(Context.getLastError());
       Yin.nextDocument();
     }
     return Benchmarks;
@@ -381,7 +382,7 @@ llvm::Error InstructionBenchmark::writeY
   Yout.beginDocuments();
   llvm::yaml::yamlize(Yout, *this, /*unused*/ true, Context);
   if (!Context.getLastError().empty())
-    return llvm::make_error<BenchmarkFailure>(Context.getLastError());
+    return make_error<Failure>(Context.getLastError());
   Yout.endDocuments();
   return Error::success();
 }
@@ -393,7 +394,7 @@ llvm::Error InstructionBenchmark::readYa
   if (Yin.setCurrentDocument())
     llvm::yaml::yamlize(Yin, *this, /*unused*/ true, Context);
   if (!Context.getLastError().empty())
-    return llvm::make_error<BenchmarkFailure>(Context.getLastError());
+    return make_error<Failure>(Context.getLastError());
   return Error::success();
 }
 

Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp?rev=373209&r1=373208&r2=373209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp Mon Sep 30 06:53:50 2019
@@ -11,6 +11,7 @@
 
 #include "Assembler.h"
 #include "BenchmarkRunner.h"
+#include "Error.h"
 #include "MCInstrDescView.h"
 #include "PerfHelper.h"
 #include "llvm/ADT/StringExtras.h"
@@ -24,9 +25,6 @@
 namespace llvm {
 namespace exegesis {
 
-BenchmarkFailure::BenchmarkFailure(const llvm::Twine &S)
-    : llvm::StringError(S, llvm::inconvertibleErrorCode()) {}
-
 BenchmarkRunner::BenchmarkRunner(const LLVMState &State,
                                  InstructionBenchmark::ModeE Mode)
     : State(State), Mode(Mode), Scratch(std::make_unique<ScratchSpace>()) {}
@@ -71,8 +69,7 @@ private:
         llvm::CrashRecoveryContext::Disable();
         // FIXME: Better diagnosis.
         if (Crashed)
-          return llvm::make_error<BenchmarkFailure>(
-              "snippet crashed while running");
+          return make_error<Failure>("snippet crashed while running");
       }
       CounterValue += Counter.read();
     }

Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h?rev=373209&r1=373208&r2=373209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h Mon Sep 30 06:53:50 2019
@@ -30,13 +30,6 @@
 namespace llvm {
 namespace exegesis {
 
-// A class representing failures that happened during Benchmark, they are used
-// to report informations to the user.
-class BenchmarkFailure : public llvm::StringError {
-public:
-  BenchmarkFailure(const llvm::Twine &S);
-};
-
 // Common code for all benchmark modes.
 class BenchmarkRunner {
 public:

Added: llvm/trunk/tools/llvm-exegesis/lib/Error.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Error.h?rev=373209&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Error.h (added)
+++ llvm/trunk/tools/llvm-exegesis/lib/Error.h Mon Sep 30 06:53:50 2019
@@ -0,0 +1,28 @@
+//===-- Error.h -------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H
+#define LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H
+
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Error.h"
+
+namespace llvm {
+namespace exegesis {
+
+// A class representing failures that happened within llvm-exegesis, they are
+// used to report informations to the user.
+class Failure : public StringError {
+public:
+  Failure(const Twine &S) : StringError(S, inconvertibleErrorCode()) {}
+};
+
+} // namespace exegesis
+} // namespace llvm
+
+#endif

Modified: llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp?rev=373209&r1=373208&r2=373209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp Mon Sep 30 06:53:50 2019
@@ -164,7 +164,7 @@ LatencySnippetGenerator::generateCodeTem
       break;
   }
   if (Results.empty())
-    return llvm::make_error<BenchmarkFailure>(
+    return make_error<Failure>(
         "No strategy found to make the execution serial");
   return std::move(Results);
 }

Modified: llvm/trunk/tools/llvm-exegesis/lib/Latency.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Latency.h?rev=373209&r1=373208&r2=373209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.h Mon Sep 30 06:53:50 2019
@@ -15,6 +15,7 @@
 #define LLVM_TOOLS_LLVM_EXEGESIS_LATENCY_H
 
 #include "BenchmarkRunner.h"
+#include "Error.h"
 #include "MCInstrDescView.h"
 #include "SnippetGenerator.h"
 

Modified: llvm/trunk/tools/llvm-exegesis/lib/SnippetFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/SnippetFile.cpp?rev=373209&r1=373208&r2=373209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/SnippetFile.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/SnippetFile.cpp Mon Sep 30 06:53:50 2019
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "SnippetFile.h"
-#include "BenchmarkRunner.h" // FIXME: Pull BenchmarkFailure out of there.
+#include "Error.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/MC/MCParser/MCAsmParser.h"
@@ -121,8 +121,8 @@ Expected<std::vector<BenchmarkCode>> rea
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
       MemoryBuffer::getFileOrSTDIN(Filename);
   if (std::error_code EC = BufferPtr.getError()) {
-    return make_error<BenchmarkFailure>("cannot read snippet: " + Filename +
-                                        ": " + EC.message());
+    return make_error<Failure>("cannot read snippet: " + Filename + ": " +
+                               EC.message());
   }
   SourceMgr SM;
   SM.AddNewSourceBuffer(std::move(BufferPtr.get()), SMLoc());
@@ -138,7 +138,7 @@ Expected<std::vector<BenchmarkCode>> rea
   const std::unique_ptr<MCAsmParser> AsmParser(
       createMCAsmParser(SM, Context, Streamer, *TM.getMCAsmInfo()));
   if (!AsmParser)
-    return make_error<BenchmarkFailure>("cannot create asm parser");
+    return make_error<Failure>("cannot create asm parser");
   AsmParser->getLexer().setCommentConsumer(&Streamer);
 
   const std::unique_ptr<MCTargetAsmParser> TargetAsmParser(
@@ -147,16 +147,15 @@ Expected<std::vector<BenchmarkCode>> rea
                                        MCTargetOptions()));
 
   if (!TargetAsmParser)
-    return make_error<BenchmarkFailure>("cannot create target asm parser");
+    return make_error<Failure>("cannot create target asm parser");
   AsmParser->setTargetParser(*TargetAsmParser);
 
   if (AsmParser->Run(false))
-    return make_error<BenchmarkFailure>("cannot parse asm file");
+    return make_error<Failure>("cannot parse asm file");
   if (Streamer.numInvalidComments())
-    return make_error<BenchmarkFailure>(
-        Twine("found ")
-            .concat(Twine(Streamer.numInvalidComments()))
-            .concat(" invalid LLVM-EXEGESIS comments"));
+    return make_error<Failure>(Twine("found ")
+                                   .concat(Twine(Streamer.numInvalidComments()))
+                                   .concat(" invalid LLVM-EXEGESIS comments"));
   return std::vector<BenchmarkCode>{std::move(Result)};
 }
 

Modified: llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp?rev=373209&r1=373208&r2=373209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp Mon Sep 30 06:53:50 2019
@@ -10,6 +10,7 @@
 #include <string>
 
 #include "Assembler.h"
+#include "Error.h"
 #include "MCInstrDescView.h"
 #include "SnippetGenerator.h"
 #include "Target.h"
@@ -48,7 +49,7 @@ SnippetGenerator::generateConfigurations
     unsigned ScratchSpacePointerInReg =
         ET.getScratchMemoryRegister(State.getTargetMachine().getTargetTriple());
     if (ScratchSpacePointerInReg == 0)
-      return llvm::make_error<BenchmarkFailure>(
+      return make_error<Failure>(
           "Infeasible : target does not support memory instructions");
     const auto &ScratchRegAliases =
         State.getRATC().getRegister(ScratchSpacePointerInReg).aliasedBits();
@@ -57,7 +58,7 @@ SnippetGenerator::generateConfigurations
     for (const auto &Op : Instr.Operands) {
       if (Op.isDef() && Op.isImplicitReg() &&
           ScratchRegAliases.test(Op.getImplicitReg()))
-        return llvm::make_error<BenchmarkFailure>(
+        return make_error<Failure>(
             "Infeasible : memory instruction uses scratch memory register");
     }
     ForbiddenRegs |= ScratchRegAliases;

Modified: llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp?rev=373209&r1=373208&r2=373209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp Mon Sep 30 06:53:50 2019
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 #include "../Target.h"
 
+#include "../Error.h"
 #include "../Latency.h"
 #include "../SnippetGenerator.h"
 #include "../Uops.h"
@@ -112,9 +113,11 @@ static Error isInvalidMemoryInstr(const
   case X86II::RawFrmImm8:
     return Error::success();
   case X86II::AddRegFrm:
-    return (Instr.Description->Opcode == X86::POP16r || Instr.Description->Opcode == X86::POP32r ||
-            Instr.Description->Opcode == X86::PUSH16r || Instr.Description->Opcode == X86::PUSH32r)
-               ? make_error<BenchmarkFailure>(
+    return (Instr.Description->Opcode == X86::POP16r ||
+            Instr.Description->Opcode == X86::POP32r ||
+            Instr.Description->Opcode == X86::PUSH16r ||
+            Instr.Description->Opcode == X86::PUSH32r)
+               ? make_error<Failure>(
                      "unsupported opcode: unsupported memory access")
                : Error::success();
   // These access memory and are handled.
@@ -140,19 +143,17 @@ static Error isInvalidMemoryInstr(const
   case X86II::RawFrmSrc:
   case X86II::RawFrmDst:
   case X86II::RawFrmDstSrc:
-    return make_error<BenchmarkFailure>(
-        "unsupported opcode: non uniform memory access");
+    return make_error<Failure>("unsupported opcode: non uniform memory access");
   }
 }
 
 static llvm::Error IsInvalidOpcode(const Instruction &Instr) {
   const auto OpcodeName = Instr.Name;
   if ((Instr.Description->TSFlags & X86II::FormMask) == X86II::Pseudo)
-    return llvm::make_error<BenchmarkFailure>(
-        "unsupported opcode: pseudo instruction");
+    return llvm::make_error<Failure>("unsupported opcode: pseudo instruction");
   if (OpcodeName.startswith("POPF") || OpcodeName.startswith("PUSHF") ||
       OpcodeName.startswith("ADJCALLSTACK"))
-    return llvm::make_error<BenchmarkFailure>(
+    return llvm::make_error<Failure>(
         "unsupported opcode: Push/Pop/AdjCallStack");
   if (llvm::Error Error = isInvalidMemoryInstr(Instr))
     return Error;
@@ -160,14 +161,14 @@ static llvm::Error IsInvalidOpcode(const
   for (const Operand &Op : Instr.Operands)
     if (Op.isExplicit() &&
         Op.getExplicitOperandInfo().OperandType == llvm::MCOI::OPERAND_PCREL)
-      return llvm::make_error<BenchmarkFailure>(
+      return llvm::make_error<Failure>(
           "unsupported opcode: PC relative operand");
   // We do not handle second-form X87 instructions. We only handle first-form
   // ones (_Fp), see comment in X86InstrFPStack.td.
   for (const Operand &Op : Instr.Operands)
     if (Op.isReg() && Op.isExplicit() &&
         Op.getExplicitOperandInfo().RegClass == llvm::X86::RSTRegClassID)
-      return llvm::make_error<BenchmarkFailure>(
+      return llvm::make_error<Failure>(
           "unsupported second-form X87 instruction");
   return llvm::Error::success();
 }
@@ -202,7 +203,7 @@ X86LatencySnippetGenerator::generateCode
   case llvm::X86II::SpecialFP:
   case llvm::X86II::CompareFP:
   case llvm::X86II::CondMovFP:
-    return llvm::make_error<BenchmarkFailure>("Unsupported x87 Instruction");
+    return llvm::make_error<Failure>("Unsupported x87 Instruction");
   case llvm::X86II::OneArgFPRW:
   case llvm::X86II::TwoArgFP:
     // These are instructions like
@@ -239,7 +240,7 @@ X86UopsSnippetGenerator::generateCodeTem
   case llvm::X86II::ZeroArgFP:
   case llvm::X86II::OneArgFP:
   case llvm::X86II::SpecialFP:
-    return llvm::make_error<BenchmarkFailure>("Unsupported x87 Instruction");
+    return llvm::make_error<Failure>("Unsupported x87 Instruction");
   case llvm::X86II::OneArgFPRW:
   case llvm::X86II::TwoArgFP:
     // These are instructions like

Modified: llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp?rev=373209&r1=373208&r2=373209&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp Mon Sep 30 06:53:50 2019
@@ -15,6 +15,7 @@
 #include "lib/BenchmarkResult.h"
 #include "lib/BenchmarkRunner.h"
 #include "lib/Clustering.h"
+#include "lib/Error.h"
 #include "lib/LlvmState.h"
 #include "lib/PerfHelper.h"
 #include "lib/SnippetFile.h"
@@ -207,13 +208,11 @@ generateSnippets(const LLVMState &State,
   const llvm::MCInstrDesc &InstrDesc = *Instr.Description;
   // Ignore instructions that we cannot run.
   if (InstrDesc.isPseudo())
-    return llvm::make_error<BenchmarkFailure>("Unsupported opcode: isPseudo");
+    return make_error<Failure>("Unsupported opcode: isPseudo");
   if (InstrDesc.isBranch() || InstrDesc.isIndirectBranch())
-    return llvm::make_error<BenchmarkFailure>(
-        "Unsupported opcode: isBranch/isIndirectBranch");
+    return make_error<Failure>("Unsupported opcode: isBranch/isIndirectBranch");
   if (InstrDesc.isCall() || InstrDesc.isReturn())
-    return llvm::make_error<BenchmarkFailure>(
-        "Unsupported opcode: isCall/isReturn");
+    return make_error<Failure>("Unsupported opcode: isCall/isReturn");
 
   const std::unique_ptr<SnippetGenerator> Generator =
       State.getExegesisTarget().createSnippetGenerator(BenchmarkMode, State);




More information about the llvm-commits mailing list