Index: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp +++ llvm/trunk/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 @@ 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 @@ 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 @@ 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 @@ 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(); } Index: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ llvm/trunk/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: Index: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ llvm/trunk/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 @@ 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(); } Index: llvm/trunk/tools/llvm-exegesis/lib/Error.h =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/Error.h +++ llvm/trunk/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 Index: llvm/trunk/tools/llvm-exegesis/lib/Latency.h =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/Latency.h +++ llvm/trunk/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" Index: llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp +++ llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp @@ -164,7 +164,7 @@ break; } if (Results.empty()) - return llvm::make_error( + return make_error( "No strategy found to make the execution serial"); return std::move(Results); } Index: llvm/trunk/tools/llvm-exegesis/lib/SnippetFile.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/SnippetFile.cpp +++ llvm/trunk/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 @@ 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 @@ 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 @@ 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)}; } Index: llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp +++ llvm/trunk/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 @@ 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 @@ 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; Index: llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp +++ llvm/trunk/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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 Index: llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp +++ llvm/trunk/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 @@ 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);