[llvm] r344145 - [llvm-exegesis][NFC] Pass Instruction instead of bare Opcode
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 10 07:57:33 PDT 2018
Author: gchatelet
Date: Wed Oct 10 07:57:32 2018
New Revision: 344145
URL: http://llvm.org/viewvc/llvm-project?rev=344145&view=rev
Log:
[llvm-exegesis][NFC] Pass Instruction instead of bare Opcode
Modified:
llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp
llvm/trunk/tools/llvm-exegesis/lib/Latency.h
llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.cpp
llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.h
llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp
llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h
llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp
llvm/trunk/tools/llvm-exegesis/lib/Uops.h
llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp
llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp
llvm/trunk/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp
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=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp Wed Oct 10 07:57:32 2018
@@ -57,8 +57,7 @@ LatencySnippetGenerator::generateTwoInst
}
llvm::Expected<CodeTemplate>
-LatencySnippetGenerator::generateCodeTemplate(unsigned Opcode) const {
- const Instruction Instr(State, Opcode);
+LatencySnippetGenerator::generateCodeTemplate(const Instruction &Instr) const {
if (Instr.hasMemoryOperands())
return llvm::make_error<BenchmarkFailure>(
"Infeasible : has memory operands");
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=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.h Wed Oct 10 07:57:32 2018
@@ -27,7 +27,7 @@ public:
~LatencySnippetGenerator() override;
llvm::Expected<CodeTemplate>
- generateCodeTemplate(unsigned Opcode) const override;
+ generateCodeTemplate(const Instruction &Instr) const override;
private:
llvm::Expected<CodeTemplate>
Modified: llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.cpp?rev=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.cpp Wed Oct 10 07:57:32 2018
@@ -88,7 +88,8 @@ const llvm::MCOperandInfo &Operand::getE
}
Instruction::Instruction(const LLVMState &State, unsigned Opcode)
- : Description(&State.getInstrInfo().get(Opcode)) {
+ : Description(&State.getInstrInfo().get(Opcode)),
+ Name(State.getInstrInfo().getName(Opcode)) {
const auto &RATC = State.getRATC();
unsigned OpIndex = 0;
for (; OpIndex < Description->getNumOperands(); ++OpIndex) {
@@ -198,6 +199,7 @@ bool Instruction::hasAliasingRegisters()
void Instruction::dump(const llvm::MCRegisterInfo &RegInfo,
llvm::raw_ostream &Stream) const {
+ Stream << "- " << Name << "\n";
for (const auto &Op : Operands) {
Stream << "- Op" << Op.getIndex();
if (Op.isExplicit())
@@ -227,10 +229,15 @@ void Instruction::dump(const llvm::MCReg
}
for (const auto &Var : Variables) {
Stream << "- Var" << Var.getIndex();
- Stream << " (";
- for (auto OperandIndex : Var.TiedOperands)
+ Stream << " [";
+ bool IsFirst = true;
+ for (auto OperandIndex : Var.TiedOperands) {
+ if (!IsFirst)
+ Stream << ",";
Stream << "Op" << OperandIndex;
- Stream << ")";
+ IsFirst = false;
+ }
+ Stream << "]";
Stream << "\n";
}
if (hasMemoryOperands())
Modified: llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.h?rev=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/MCInstrDescView.h Wed Oct 10 07:57:32 2018
@@ -130,6 +130,7 @@ struct Instruction {
llvm::raw_ostream &Stream) const;
const llvm::MCInstrDesc *Description; // Never nullptr.
+ llvm::StringRef Name; // The name of this instruction.
llvm::SmallVector<Operand, 8> Operands;
llvm::SmallVector<Variable, 4> Variables;
llvm::BitVector ImplDefRegs; // The set of aliased implicit def registers.
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=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.cpp Wed Oct 10 07:57:32 2018
@@ -30,8 +30,8 @@ SnippetGenerator::SnippetGenerator(const
SnippetGenerator::~SnippetGenerator() = default;
llvm::Expected<std::vector<BenchmarkCode>>
-SnippetGenerator::generateConfigurations(unsigned Opcode) const {
- if (auto E = generateCodeTemplate(Opcode)) {
+SnippetGenerator::generateConfigurations(const Instruction &Instr) const {
+ if (auto E = generateCodeTemplate(Instr)) {
CodeTemplate &CT = E.get();
const auto &RATC = State.getRATC();
const llvm::BitVector &ForbiddenRegs =
Modified: llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h?rev=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/SnippetGenerator.h Wed Oct 10 07:57:32 2018
@@ -46,7 +46,7 @@ public:
// Calls generateCodeTemplate and expands it into one or more BenchmarkCode.
llvm::Expected<std::vector<BenchmarkCode>>
- generateConfigurations(unsigned Opcode) const;
+ generateConfigurations(const Instruction &Instr) const;
// Given a snippet, computes which registers the setup code needs to define.
std::vector<RegisterValue> computeRegisterInitialValues(
@@ -66,7 +66,7 @@ protected:
private:
// API to be implemented by subclasses.
virtual llvm::Expected<CodeTemplate>
- generateCodeTemplate(unsigned Opcode) const = 0;
+ generateCodeTemplate(const Instruction &Instr) const = 0;
};
// A global Random Number Generator to randomize configurations.
Modified: llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp?rev=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp Wed Oct 10 07:57:32 2018
@@ -125,13 +125,11 @@ void UopsSnippetGenerator::instantiateMe
}
llvm::Expected<CodeTemplate>
-UopsSnippetGenerator::generateCodeTemplate(unsigned Opcode) const {
- const auto &ET = State.getExegesisTarget();
+UopsSnippetGenerator::generateCodeTemplate(const Instruction &Instr) const {
CodeTemplate CT;
-
const llvm::BitVector *ScratchSpaceAliasedRegs = nullptr;
- const Instruction Instr(State, Opcode);
if (Instr.hasMemoryOperands()) {
+ const auto &ET = State.getExegesisTarget();
CT.ScratchSpacePointerInReg =
ET.getScratchMemoryRegister(State.getTargetMachine().getTargetTriple());
if (CT.ScratchSpacePointerInReg == 0)
Modified: llvm/trunk/tools/llvm-exegesis/lib/Uops.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Uops.h?rev=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Uops.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Uops.h Wed Oct 10 07:57:32 2018
@@ -26,7 +26,7 @@ public:
~UopsSnippetGenerator() override;
llvm::Expected<CodeTemplate>
- generateCodeTemplate(unsigned Opcode) const override;
+ generateCodeTemplate(const Instruction &Instr) const override;
static constexpr const size_t kMinNumDifferentAddresses = 6;
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=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/X86/Target.cpp Wed Oct 10 07:57:32 2018
@@ -26,10 +26,9 @@ template <typename Impl> class X86Snippe
using Impl::Impl;
llvm::Expected<CodeTemplate>
- generateCodeTemplate(unsigned Opcode) const override {
+ generateCodeTemplate(const Instruction &Instr) const override {
// Test whether we can generate a snippet for this instruction.
- const auto &InstrInfo = this->State.getInstrInfo();
- const auto OpcodeName = InstrInfo.getName(Opcode);
+ const auto OpcodeName = Instr.Name;
if (OpcodeName.startswith("POPF") || OpcodeName.startswith("PUSHF") ||
OpcodeName.startswith("ADJCALLSTACK")) {
return llvm::make_error<BenchmarkFailure>(
@@ -38,8 +37,7 @@ template <typename Impl> class X86Snippe
// Handle X87.
const unsigned FPInstClass =
- InstrInfo.get(Opcode).TSFlags & llvm::X86II::FPTypeMask;
- const Instruction Instr(this->State, Opcode);
+ Instr.Description->TSFlags & llvm::X86II::FPTypeMask;
switch (FPInstClass) {
case llvm::X86II::NotFP:
break;
@@ -67,7 +65,7 @@ template <typename Impl> class X86Snippe
}
// Fallback to generic implementation.
- return Impl::Base::generateCodeTemplate(Opcode);
+ return Impl::Base::generateCodeTemplate(Instr);
}
};
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=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp Wed Oct 10 07:57:32 2018
@@ -124,12 +124,8 @@ static unsigned getOpcodeOrDie(const llv
// Generates code snippets for opcode `Opcode`.
static llvm::Expected<std::vector<BenchmarkCode>>
generateSnippets(const LLVMState &State, unsigned Opcode) {
- const std::unique_ptr<SnippetGenerator> Generator =
- State.getExegesisTarget().createSnippetGenerator(BenchmarkMode, State);
- if (!Generator)
- llvm::report_fatal_error("cannot create snippet generator");
-
- const llvm::MCInstrDesc &InstrDesc = State.getInstrInfo().get(Opcode);
+ const Instruction Instr(State, Opcode);
+ const llvm::MCInstrDesc &InstrDesc = *Instr.Description;
// Ignore instructions that we cannot run.
if (InstrDesc.isPseudo())
return llvm::make_error<BenchmarkFailure>("Unsupported opcode: isPseudo");
@@ -140,7 +136,11 @@ generateSnippets(const LLVMState &State,
return llvm::make_error<BenchmarkFailure>(
"Unsupported opcode: isCall/isReturn");
- return Generator->generateConfigurations(Opcode);
+ const std::unique_ptr<SnippetGenerator> Generator =
+ State.getExegesisTarget().createSnippetGenerator(BenchmarkMode, State);
+ if (!Generator)
+ llvm::report_fatal_error("cannot create snippet generator");
+ return Generator->generateConfigurations(Instr);
}
namespace {
Modified: llvm/trunk/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp?rev=344145&r1=344144&r2=344145&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp Wed Oct 10 07:57:32 2018
@@ -59,7 +59,8 @@ protected:
CodeTemplate checkAndGetCodeTemplate(unsigned Opcode) {
randomGenerator().seed(0); // Initialize seed.
- auto CodeTemplateOrError = Generator.generateCodeTemplate(Opcode);
+ const Instruction Instr(State, Opcode);
+ auto CodeTemplateOrError = Generator.generateCodeTemplate(Instr);
EXPECT_FALSE(CodeTemplateOrError.takeError()); // Valid configuration.
return std::move(CodeTemplateOrError.get());
}
@@ -238,7 +239,8 @@ TEST_F(UopsSnippetGeneratorTest, MemoryU
TEST_F(UopsSnippetGeneratorTest, MemoryUse_Movsb) {
// MOVSB writes to scratch memory register.
const unsigned Opcode = llvm::X86::MOVSB;
- auto Error = Generator.generateCodeTemplate(Opcode).takeError();
+ const Instruction Instr(State, Opcode);
+ auto Error = Generator.generateCodeTemplate(Instr).takeError();
EXPECT_TRUE((bool)Error);
llvm::consumeError(std::move(Error));
}
@@ -253,7 +255,7 @@ public:
private:
llvm::Expected<CodeTemplate>
- generateCodeTemplate(unsigned Opcode) const override {
+ generateCodeTemplate(const Instruction &Instr) const override {
return llvm::make_error<llvm::StringError>("not implemented",
llvm::inconvertibleErrorCode());
}
More information about the llvm-commits
mailing list