From: Clement Courbet Date: Mon, 30 Sep 2019 13:53:50 +0000 (+0000) Subject: [llvm-exegesis][NFC] Move BenchmarkFailure to own file. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8cb6812d21092a71ce0ab8a2ee678a82abb7e9a;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373209 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/tools/llvm-exegesis/lib/BenchmarkResult.cpp index 685f31a2b7d..790e253709c 100644 --- a/tools/llvm-exegesis/lib/BenchmarkResult.cpp +++ b/tools/llvm-exegesis/lib/BenchmarkResult.cpp @@ -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 LLVMState &State, if (Yin.setCurrentDocument()) llvm::yaml::yamlize(Yin, Benchmark, /*unused*/ true, Context); if (!Context.getLastError().empty()) - return llvm::make_error(Context.getLastError()); + return make_error(Context.getLastError()); return Benchmark; } else { return ExpectedMemoryBuffer.takeError(); @@ -364,7 +365,7 @@ InstructionBenchmark::readYamls(const LLVMState &State, if (Yin.error()) return llvm::errorCodeToError(Yin.error()); if (!Context.getLastError().empty()) - return llvm::make_error(Context.getLastError()); + return make_error(Context.getLastError()); Yin.nextDocument(); } return Benchmarks; @@ -381,7 +382,7 @@ llvm::Error InstructionBenchmark::writeYamlTo(const LLVMState &State, Yout.beginDocuments(); llvm::yaml::yamlize(Yout, *this, /*unused*/ true, Context); if (!Context.getLastError().empty()) - return llvm::make_error(Context.getLastError()); + return make_error(Context.getLastError()); Yout.endDocuments(); return Error::success(); } @@ -393,7 +394,7 @@ llvm::Error InstructionBenchmark::readYamlFrom(const LLVMState &State, if (Yin.setCurrentDocument()) llvm::yaml::yamlize(Yin, *this, /*unused*/ true, Context); if (!Context.getLastError().empty()) - return llvm::make_error(Context.getLastError()); + return make_error(Context.getLastError()); return Error::success(); } diff --git a/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index a08983817ad..4b541f4d829 100644 --- a/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -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()) {} @@ -71,8 +69,7 @@ private: llvm::CrashRecoveryContext::Disable(); // FIXME: Better diagnosis. if (Crashed) - return llvm::make_error( - "snippet crashed while running"); + return make_error("snippet crashed while running"); } CounterValue += Counter.read(); } diff --git a/tools/llvm-exegesis/lib/BenchmarkRunner.h b/tools/llvm-exegesis/lib/BenchmarkRunner.h index 13227a7bfb3..2f6ea0f5b5a 100644 --- a/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ b/tools/llvm-exegesis/lib/BenchmarkRunner.h @@ -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: diff --git a/tools/llvm-exegesis/lib/Error.h b/tools/llvm-exegesis/lib/Error.h new file mode 100644 index 00000000000..720cc6829f3 --- /dev/null +++ b/tools/llvm-exegesis/lib/Error.h @@ -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 diff --git a/tools/llvm-exegesis/lib/Latency.cpp b/tools/llvm-exegesis/lib/Latency.cpp index 112d3acb5c8..87c895e4ab6 100644 --- a/tools/llvm-exegesis/lib/Latency.cpp +++ b/tools/llvm-exegesis/lib/Latency.cpp @@ -164,7 +164,7 @@ LatencySnippetGenerator::generateCodeTemplates( break; } if (Results.empty()) - return llvm::make_error( + return make_error( "No strategy found to make the execution serial"); return std::move(Results); } diff --git a/tools/llvm-exegesis/lib/Latency.h b/tools/llvm-exegesis/lib/Latency.h index 9ffe2d75eeb..503f91daf89 100644 --- a/tools/llvm-exegesis/lib/Latency.h +++ b/tools/llvm-exegesis/lib/Latency.h @@ -15,6 +15,7 @@ #define LLVM_TOOLS_LLVM_EXEGESIS_LATENCY_H #include "BenchmarkRunner.h" +#include "Error.h" #include "MCInstrDescView.h" #include "SnippetGenerator.h" diff --git a/tools/llvm-exegesis/lib/SnippetFile.cpp b/tools/llvm-exegesis/lib/SnippetFile.cpp index 112ac45b478..f5666ecab95 100644 --- a/tools/llvm-exegesis/lib/SnippetFile.cpp +++ b/tools/llvm-exegesis/lib/SnippetFile.cpp @@ -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> readSnippets(const LLVMState &State, ErrorOr> BufferPtr = MemoryBuffer::getFileOrSTDIN(Filename); if (std::error_code EC = BufferPtr.getError()) { - return make_error("cannot read snippet: " + Filename + - ": " + EC.message()); + return make_error("cannot read snippet: " + Filename + ": " + + EC.message()); } SourceMgr SM; SM.AddNewSourceBuffer(std::move(BufferPtr.get()), SMLoc()); @@ -138,7 +138,7 @@ Expected> readSnippets(const LLVMState &State, const std::unique_ptr AsmParser( createMCAsmParser(SM, Context, Streamer, *TM.getMCAsmInfo())); if (!AsmParser) - return make_error("cannot create asm parser"); + return make_error("cannot create asm parser"); AsmParser->getLexer().setCommentConsumer(&Streamer); const std::unique_ptr TargetAsmParser( @@ -147,16 +147,15 @@ Expected> readSnippets(const LLVMState &State, MCTargetOptions())); if (!TargetAsmParser) - return make_error("cannot create target asm parser"); + return make_error("cannot create target asm parser"); AsmParser->setTargetParser(*TargetAsmParser); if (AsmParser->Run(false)) - return make_error("cannot parse asm file"); + return make_error("cannot parse asm file"); if (Streamer.numInvalidComments()) - return make_error( - Twine("found ") - .concat(Twine(Streamer.numInvalidComments())) - .concat(" invalid LLVM-EXEGESIS comments")); + return make_error(Twine("found ") + .concat(Twine(Streamer.numInvalidComments())) + .concat(" invalid LLVM-EXEGESIS comments")); return std::vector{std::move(Result)}; } diff --git a/tools/llvm-exegesis/lib/SnippetGenerator.cpp b/tools/llvm-exegesis/lib/SnippetGenerator.cpp index 21fbe583636..267ab131633 100644 --- a/tools/llvm-exegesis/lib/SnippetGenerator.cpp +++ b/tools/llvm-exegesis/lib/SnippetGenerator.cpp @@ -10,6 +10,7 @@ #include #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( + return make_error( "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( + return make_error( "Infeasible : memory instruction uses scratch memory register"); } ForbiddenRegs |= ScratchRegAliases; diff --git a/tools/llvm-exegesis/lib/X86/Target.cpp b/tools/llvm-exegesis/lib/X86/Target.cpp index ca86ebcf2a2..bf008e8bbc7 100644 --- a/tools/llvm-exegesis/lib/X86/Target.cpp +++ b/tools/llvm-exegesis/lib/X86/Target.cpp @@ -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 Instruction &Instr) { 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( + return (Instr.Description->Opcode == X86::POP16r || + Instr.Description->Opcode == X86::POP32r || + Instr.Description->Opcode == X86::PUSH16r || + Instr.Description->Opcode == X86::PUSH32r) + ? make_error( "unsupported opcode: unsupported memory access") : Error::success(); // These access memory and are handled. @@ -140,19 +143,17 @@ static Error isInvalidMemoryInstr(const Instruction &Instr) { case X86II::RawFrmSrc: case X86II::RawFrmDst: case X86II::RawFrmDstSrc: - return make_error( - "unsupported opcode: non uniform memory access"); + return make_error("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( - "unsupported opcode: pseudo instruction"); + return llvm::make_error("unsupported opcode: pseudo instruction"); if (OpcodeName.startswith("POPF") || OpcodeName.startswith("PUSHF") || OpcodeName.startswith("ADJCALLSTACK")) - return llvm::make_error( + return llvm::make_error( "unsupported opcode: Push/Pop/AdjCallStack"); if (llvm::Error Error = isInvalidMemoryInstr(Instr)) return Error; @@ -160,14 +161,14 @@ static llvm::Error IsInvalidOpcode(const Instruction &Instr) { for (const Operand &Op : Instr.Operands) if (Op.isExplicit() && Op.getExplicitOperandInfo().OperandType == llvm::MCOI::OPERAND_PCREL) - return llvm::make_error( + return llvm::make_error( "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( + return llvm::make_error( "unsupported second-form X87 instruction"); return llvm::Error::success(); } @@ -202,7 +203,7 @@ X86LatencySnippetGenerator::generateCodeTemplates( case llvm::X86II::SpecialFP: case llvm::X86II::CompareFP: case llvm::X86II::CondMovFP: - return llvm::make_error("Unsupported x87 Instruction"); + return llvm::make_error("Unsupported x87 Instruction"); case llvm::X86II::OneArgFPRW: case llvm::X86II::TwoArgFP: // These are instructions like @@ -239,7 +240,7 @@ X86UopsSnippetGenerator::generateCodeTemplates( case llvm::X86II::ZeroArgFP: case llvm::X86II::OneArgFP: case llvm::X86II::SpecialFP: - return llvm::make_error("Unsupported x87 Instruction"); + return llvm::make_error("Unsupported x87 Instruction"); case llvm::X86II::OneArgFPRW: case llvm::X86II::TwoArgFP: // These are instructions like diff --git a/tools/llvm-exegesis/llvm-exegesis.cpp b/tools/llvm-exegesis/llvm-exegesis.cpp index 501f6217fd0..616b7c96232 100644 --- a/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/tools/llvm-exegesis/llvm-exegesis.cpp @@ -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, unsigned Opcode, const llvm::MCInstrDesc &InstrDesc = *Instr.Description; // Ignore instructions that we cannot run. if (InstrDesc.isPseudo()) - return llvm::make_error("Unsupported opcode: isPseudo"); + return make_error("Unsupported opcode: isPseudo"); if (InstrDesc.isBranch() || InstrDesc.isIndirectBranch()) - return llvm::make_error( - "Unsupported opcode: isBranch/isIndirectBranch"); + return make_error("Unsupported opcode: isBranch/isIndirectBranch"); if (InstrDesc.isCall() || InstrDesc.isReturn()) - return llvm::make_error( - "Unsupported opcode: isCall/isReturn"); + return make_error("Unsupported opcode: isCall/isReturn"); const std::unique_ptr Generator = State.getExegesisTarget().createSnippetGenerator(BenchmarkMode, State);