[llvm] r342982 - [llvm-exegesis] Serializes registers initial values.
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 25 08:15:55 PDT 2018
Author: gchatelet
Date: Tue Sep 25 08:15:54 2018
New Revision: 342982
URL: http://llvm.org/viewvc/llvm-project?rev=342982&view=rev
Log:
[llvm-exegesis] Serializes registers initial values.
Summary: Adds the registers initial values to the YAML output of llvm-exegesis.
Reviewers: courbet
Subscribers: tschuett, llvm-commits
Differential Revision: https://reviews.llvm.org/D52460
Modified:
llvm/trunk/test/tools/llvm-exegesis/X86/latency-by-opcode-name.s
llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h
llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/trunk/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp
Modified: llvm/trunk/test/tools/llvm-exegesis/X86/latency-by-opcode-name.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-exegesis/X86/latency-by-opcode-name.s?rev=342982&r1=342981&r2=342982&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-exegesis/X86/latency-by-opcode-name.s (original)
+++ llvm/trunk/test/tools/llvm-exegesis/X86/latency-by-opcode-name.s Tue Sep 25 08:15:54 2018
@@ -1,8 +1,11 @@
# RUN: llvm-exegesis -mode=latency -opcode-name=ADD32rr | FileCheck %s
CHECK: ---
-CHECK-NEXT: mode: latency
+CHECK-NEXT: mode: latency
CHECK-NEXT: key:
CHECK-NEXT: instructions:
CHECK-NEXT: ADD32rr
+CHECK-NEXT: config: ''
+CHECK-NEXT: register_initial_values:
+CHECK-DAG: - '[[REG1:[A-Z0-9]+]]=0x0'
CHECK-LAST: ...
Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp?rev=342982&r1=342981&r2=342982&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp Tue Sep 25 08:15:54 2018
@@ -54,6 +54,24 @@ struct YamlContext {
std::string &getLastError() { return ErrorStream.str(); }
+ llvm::raw_string_ostream &getErrorStream() { return ErrorStream; }
+
+ llvm::StringRef getRegName(unsigned RegNo) {
+ const llvm::StringRef RegName = State->getRegInfo().getName(RegNo);
+ if (RegName.empty())
+ ErrorStream << "No register with enum value" << RegNo;
+ return RegName;
+ }
+
+ unsigned getRegNo(llvm::StringRef RegName) {
+ const llvm::MCRegisterInfo &RegInfo = State->getRegInfo();
+ for (unsigned E = RegInfo.getNumRegs(), I = 0; I < E; ++I)
+ if (RegInfo.getName(I) == RegName)
+ return I;
+ ErrorStream << "No register with name " << RegName;
+ return 0;
+ }
+
private:
void serializeMCOperand(const llvm::MCOperand &MCOperand,
llvm::raw_ostream &OS) {
@@ -83,13 +101,6 @@ private:
return {};
}
- llvm::StringRef getRegName(unsigned RegNo) {
- const llvm::StringRef RegName = State->getRegInfo().getName(RegNo);
- if (RegName.empty())
- ErrorStream << "No register with enum value" << RegNo;
- return RegName;
- }
-
llvm::StringRef getInstrName(unsigned InstrNo) {
const llvm::StringRef InstrName = State->getInstrInfo().getName(InstrNo);
if (InstrName.empty())
@@ -97,15 +108,6 @@ private:
return InstrName;
}
- unsigned getRegNo(llvm::StringRef RegName) {
- const llvm::MCRegisterInfo &RegInfo = State->getRegInfo();
- for (unsigned E = RegInfo.getNumRegs(), I = 0; I < E; ++I)
- if (RegInfo.getName(I) == RegName)
- return I;
- ErrorStream << "No register with name " << RegName;
- return 0;
- }
-
unsigned getInstrOpcode(llvm::StringRef InstrName) {
const llvm::MCInstrInfo &InstrInfo = State->getInstrInfo();
for (unsigned E = InstrInfo.getNumOpcodes(), I = 0; I < E; ++I)
@@ -124,6 +126,10 @@ private:
namespace llvm {
namespace yaml {
+static YamlContext &getTypedContext(void *Ctx) {
+ return *reinterpret_cast<YamlContext *>(Ctx);
+}
+
// std::vector<llvm::MCInst> will be rendered as a list.
template <> struct SequenceElementTraits<llvm::MCInst> {
static const bool flow = false;
@@ -133,15 +139,17 @@ template <> struct ScalarTraits<llvm::MC
static void output(const llvm::MCInst &Value, void *Ctx,
llvm::raw_ostream &Out) {
- reinterpret_cast<YamlContext *>(Ctx)->serializeMCInst(Value, Out);
+ getTypedContext(Ctx).serializeMCInst(Value, Out);
}
static StringRef input(StringRef Scalar, void *Ctx, llvm::MCInst &Value) {
- YamlContext &Context = *reinterpret_cast<YamlContext *>(Ctx);
+ YamlContext &Context = getTypedContext(Ctx);
Context.deserializeMCInst(Scalar, Value);
return Context.getLastError();
}
+ // By default strings are quoted only when necessary.
+ // We force the use of single quotes for uniformity.
static QuotingType mustQuote(StringRef) { return QuotingType::Single; }
static const bool flow = true;
@@ -173,6 +181,44 @@ struct ScalarEnumerationTraits<exegesis:
}
};
+// std::vector<exegesis::RegisterValue> will be rendered as a list.
+template <> struct SequenceElementTraits<exegesis::RegisterValue> {
+ static const bool flow = false;
+};
+
+template <> struct ScalarTraits<exegesis::RegisterValue> {
+ static constexpr const unsigned kRadix = 16;
+ static constexpr const bool kSigned = false;
+
+ static void output(const exegesis::RegisterValue &RV, void *Ctx,
+ llvm::raw_ostream &Out) {
+ YamlContext &Context = getTypedContext(Ctx);
+ Out << Context.getRegName(RV.Register) << "=0x"
+ << RV.Value.toString(kRadix, kSigned);
+ }
+
+ static StringRef input(StringRef String, void *Ctx,
+ exegesis::RegisterValue &RV) {
+ llvm::SmallVector<llvm::StringRef, 2> Pieces;
+ String.split(Pieces, "=0x", /* MaxSplit */ -1,
+ /* KeepEmpty */ false);
+ YamlContext &Context = getTypedContext(Ctx);
+ if (Pieces.size() == 2) {
+ RV.Register = Context.getRegNo(Pieces[0]);
+ const unsigned BitsNeeded = llvm::APInt::getBitsNeeded(Pieces[1], kRadix);
+ RV.Value = llvm::APInt(BitsNeeded, Pieces[1], kRadix);
+ } else {
+ Context.getErrorStream()
+ << "Unknown initial register value: '" << String << "'";
+ }
+ return Context.getLastError();
+ }
+
+ static QuotingType mustQuote(StringRef) { return QuotingType::Single; }
+
+ static const bool flow = true;
+};
+
template <>
struct MappingContextTraits<exegesis::InstructionBenchmarkKey, YamlContext> {
static void mapping(IO &Io, exegesis::InstructionBenchmarkKey &Obj,
@@ -180,13 +226,13 @@ struct MappingContextTraits<exegesis::In
Io.setContext(&Context);
Io.mapRequired("instructions", Obj.Instructions);
Io.mapOptional("config", Obj.Config);
+ Io.mapRequired("register_initial_values", Obj.RegisterInitialValues);
}
};
template <>
struct MappingContextTraits<exegesis::InstructionBenchmark, YamlContext> {
- class NormalizedBinary {
- public:
+ struct NormalizedBinary {
NormalizedBinary(IO &io) {}
NormalizedBinary(IO &, std::vector<uint8_t> &Data) : Binary(Data) {}
std::vector<uint8_t> denormalize(IO &) {
Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h?rev=342982&r1=342981&r2=342982&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h Tue Sep 25 08:15:54 2018
@@ -16,6 +16,7 @@
#ifndef LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H
#define LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H
+#include "BenchmarkCode.h"
#include "LlvmState.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
@@ -32,6 +33,8 @@ namespace exegesis {
struct InstructionBenchmarkKey {
// The LLVM opcode name.
std::vector<llvm::MCInst> Instructions;
+ // The initial values of the registers.
+ std::vector<RegisterValue> RegisterInitialValues;
// An opaque configuration, that can be used to separate several benchmarks of
// the same instruction under different configurations.
std::string Config;
Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp?rev=342982&r1=342981&r2=342982&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp Tue Sep 25 08:15:54 2018
@@ -57,6 +57,7 @@ BenchmarkRunner::runConfiguration(const
const std::vector<llvm::MCInst> &Instructions = BC.Instructions;
InstrBenchmark.Key.Instructions = Instructions;
+ InstrBenchmark.Key.RegisterInitialValues = BC.RegisterInitialValues;
// Assemble at least kMinInstructionsForSnippet instructions by repeating the
// snippet for debug/analysis. This is so that the user clearly understands
Modified: llvm/trunk/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp?rev=342982&r1=342981&r2=342982&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp Tue Sep 25 08:15:54 2018
@@ -68,6 +68,9 @@ TEST(BenchmarkResultTest, WriteToAndRead
.addImm(123)
.addFPImm(0.5));
ToDisk.Key.Config = "config";
+ ToDisk.Key.RegisterInitialValues = {
+ RegisterValue{llvm::X86::AL, llvm::APInt(8, "-1", 10)},
+ RegisterValue{llvm::X86::AH, llvm::APInt(8, "123", 10)}};
ToDisk.Mode = InstructionBenchmark::Latency;
ToDisk.CpuName = "cpu_name";
ToDisk.LLVMTriple = "llvm_triple";
More information about the llvm-commits
mailing list