#include "BenchmarkResult.h"
#include "BenchmarkRunner.h"
+#include "Error.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringMap.h"
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();
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;
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();
}
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();
}
#include "Assembler.h"
#include "BenchmarkRunner.h"
+#include "Error.h"
#include "MCInstrDescView.h"
#include "PerfHelper.h"
#include "llvm/ADT/StringExtras.h"
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>()) {}
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();
}
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:
--- /dev/null
+//===-- 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
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);
}
#define LLVM_TOOLS_LLVM_EXEGESIS_LATENCY_H
#include "BenchmarkRunner.h"
+#include "Error.h"
#include "MCInstrDescView.h"
#include "SnippetGenerator.h"
//===----------------------------------------------------------------------===//
#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"
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());
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(
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)};
}
#include <string>
#include "Assembler.h"
+#include "Error.h"
#include "MCInstrDescView.h"
#include "SnippetGenerator.h"
#include "Target.h"
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();
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;
//===----------------------------------------------------------------------===//
#include "../Target.h"
+#include "../Error.h"
#include "../Latency.h"
#include "../SnippetGenerator.h"
#include "../Uops.h"
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.
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;
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();
}
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
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
#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"
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);