diff options
author | Clement Courbet <courbet@google.com> | 2018-04-04 08:13:32 +0000 |
---|---|---|
committer | Clement Courbet <courbet@google.com> | 2018-04-04 08:13:32 +0000 |
commit | 7287b2c1ec669791df8b1c704e2457338f6bee47 (patch) | |
tree | 43bc8f285b995f2f9bae92ce122bf0425c55a718 /llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | |
parent | 4f98e0bc030dacf65af981968a8f4f8234f5f32f (diff) | |
download | bcm5719-llvm-7287b2c1ec669791df8b1c704e2457338f6bee47.tar.gz bcm5719-llvm-7287b2c1ec669791df8b1c704e2457338f6bee47.zip |
Add llvm-exegesis tool.
Summary:
[llvm-exegesis][RFC] Automatic Measurement of Instruction Latency/Uops
This is the code corresponding to the RFC "llvm-exegesis Automatic Measurement of Instruction Latency/Uops".
The RFC is available on the LLVM mailing lists as well as the following document
for easier reading:
https://docs.google.com/document/d/1QidaJMJUyQdRrFKD66vE1_N55whe0coQ3h1GpFzz27M/edit?usp=sharing
Subscribers: mgorny, gchatelet, orwant, llvm-commits
Differential Revision: https://reviews.llvm.org/D44519
llvm-svn: 329156
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp')
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp new file mode 100644 index 00000000000..e9b8d29aaec --- /dev/null +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp @@ -0,0 +1,85 @@ +//===-- BenchmarkResult.cpp -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "BenchmarkResult.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/FileOutputBuffer.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" + +// Defining YAML traits for IO. +namespace llvm { +namespace yaml { + +// std::vector<exegesis::Measure> will be rendered as a list. +template <> struct SequenceElementTraits<exegesis::BenchmarkMeasure> { + static const bool flow = false; +}; + +// exegesis::Measure is rendererd as a flow instead of a list. +// e.g. { "key": "the key", "value": 0123 } +template <> struct MappingTraits<exegesis::BenchmarkMeasure> { + static void mapping(IO &Io, exegesis::BenchmarkMeasure &Obj) { + Io.mapRequired("key", Obj.Key); + Io.mapRequired("value", Obj.Value); + Io.mapOptional("debug_string", Obj.DebugString); + } + static const bool flow = true; +}; + +template <> struct MappingTraits<exegesis::AsmTemplate> { + static void mapping(IO &Io, exegesis::AsmTemplate &Obj) { + Io.mapRequired("name", Obj.Name); + } +}; + +template <> struct MappingTraits<exegesis::InstructionBenchmark> { + static void mapping(IO &Io, exegesis::InstructionBenchmark &Obj) { + Io.mapRequired("asm_template", Obj.AsmTmpl); + Io.mapRequired("cpu_name", Obj.CpuName); + Io.mapRequired("llvm_triple", Obj.LLVMTriple); + Io.mapRequired("num_repetitions", Obj.NumRepetitions); + Io.mapRequired("measurements", Obj.Measurements); + Io.mapRequired("error", Obj.Error); + } +}; + +} // namespace yaml +} // namespace llvm + +namespace exegesis { + +InstructionBenchmark +InstructionBenchmark::readYamlOrDie(llvm::StringRef Filename) { + std::unique_ptr<llvm::MemoryBuffer> MemBuffer = llvm::cantFail( + llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename))); + llvm::yaml::Input Yin(*MemBuffer); + InstructionBenchmark Benchmark; + Yin >> Benchmark; + return Benchmark; +} + +void InstructionBenchmark::writeYamlOrDie(const llvm::StringRef Filename) { + if (Filename == "-") { + llvm::yaml::Output Yout(llvm::outs()); + Yout << *this; + } else { + llvm::SmallString<1024> Buffer; + llvm::raw_svector_ostream Ostr(Buffer); + llvm::yaml::Output Yout(Ostr); + Yout << *this; + std::unique_ptr<llvm::FileOutputBuffer> File = + llvm::cantFail(llvm::FileOutputBuffer::create(Filename, Buffer.size())); + memcpy(File->getBufferStart(), Buffer.data(), Buffer.size()); + llvm::cantFail(File->commit()); + } +} + +} // namespace exegesis |