diff options
author | Clement Courbet <courbet@google.com> | 2018-05-17 10:52:18 +0000 |
---|---|---|
committer | Clement Courbet <courbet@google.com> | 2018-05-17 10:52:18 +0000 |
commit | 0e69e2d74739a119a78d131c29b92c25787ec2f3 (patch) | |
tree | c808110b4a710daf2bed231cc96e1e3af1558294 /llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | |
parent | ceb4933dc1dc4e769ea9e1752a8cb8425de09002 (diff) | |
download | bcm5719-llvm-0e69e2d74739a119a78d131c29b92c25787ec2f3.tar.gz bcm5719-llvm-0e69e2d74739a119a78d131c29b92c25787ec2f3.zip |
reland r332579: [llvm-exegesis] Update to cover latency through another opcode.
Restructuring the code to measure latency and uops.
The end goal is to have this program spawn another process to deal with SIGILL and other malformed programs. It is not yet the case in this redesign, it is still the main program that runs the code (and may crash).
It now uses BitVector instead of Graph for performance reasons.
https://reviews.llvm.org/D46821
(with fixed ARM tests)
Authored by Guillaume Chatelet
llvm-svn: 332592
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp')
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp index a043ea40c27..b1083f4ed0a 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp @@ -61,10 +61,8 @@ LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(exegesis::InstructionBenchmark) namespace exegesis { -namespace { - template <typename ObjectOrList> -ObjectOrList readYamlOrDieCommon(llvm::StringRef Filename) { +static ObjectOrList readYamlOrDieCommon(llvm::StringRef Filename) { std::unique_ptr<llvm::MemoryBuffer> MemBuffer = llvm::cantFail( llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename))); llvm::yaml::Input Yin(*MemBuffer); @@ -73,8 +71,6 @@ ObjectOrList readYamlOrDieCommon(llvm::StringRef Filename) { return Benchmark; } -} // namespace - InstructionBenchmark InstructionBenchmark::readYamlOrDie(llvm::StringRef Filename) { return readYamlOrDieCommon<InstructionBenchmark>(Filename); @@ -85,19 +81,26 @@ InstructionBenchmark::readYamlsOrDie(llvm::StringRef Filename) { return readYamlOrDieCommon<std::vector<InstructionBenchmark>>(Filename); } +void InstructionBenchmark::writeYamlTo(llvm::raw_ostream &S) { + llvm::yaml::Output Yout(S); + Yout << *this; +} + +void InstructionBenchmark::readYamlFrom(llvm::StringRef InputContent) { + llvm::yaml::Input Yin(InputContent); + Yin >> *this; +} + +// FIXME: Change the API to let the caller handle errors. void InstructionBenchmark::writeYamlOrDie(const llvm::StringRef Filename) { if (Filename == "-") { - llvm::yaml::Output Yout(llvm::outs()); - Yout << *this; + writeYamlTo(llvm::outs()); } 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()); + int ResultFD = 0; + llvm::cantFail(llvm::errorCodeToError( + openFileForWrite(Filename, ResultFD, llvm::sys::fs::F_Text))); + llvm::raw_fd_ostream Ostr(ResultFD, true /*shouldClose*/); + writeYamlTo(Ostr); } } |