1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00

[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

llvm-svn: 373209
This commit is contained in:
Clement Courbet 2019-09-30 13:53:50 +00:00
parent e4601bbf20
commit 2790dd8d16
10 changed files with 66 additions and 46 deletions

View File

@ -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<BenchmarkFailure>(Context.getLastError());
return make_error<Failure>(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<BenchmarkFailure>(Context.getLastError());
return make_error<Failure>(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<BenchmarkFailure>(Context.getLastError());
return make_error<Failure>(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<BenchmarkFailure>(Context.getLastError());
return make_error<Failure>(Context.getLastError());
return Error::success();
}

View File

@ -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();
}

View File

@ -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:

View File

@ -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

View File

@ -164,7 +164,7 @@ LatencySnippetGenerator::generateCodeTemplates(
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);
}

View File

@ -15,6 +15,7 @@
#define LLVM_TOOLS_LLVM_EXEGESIS_LATENCY_H
#include "BenchmarkRunner.h"
#include "Error.h"
#include "MCInstrDescView.h"
#include "SnippetGenerator.h"

View File

@ -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>> readSnippets(const LLVMState &State,
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>> readSnippets(const LLVMState &State,
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>> readSnippets(const LLVMState &State,
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)};
}

View File

@ -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;

View File

@ -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<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 Instruction &Instr) {
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 Instruction &Instr) {
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::generateCodeTemplates(
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::generateCodeTemplates(
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

View File

@ -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<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);