summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2018-05-17 07:38:21 +0000
committerClement Courbet <courbet@google.com>2018-05-17 07:38:21 +0000
commitee110fb735651d63252f70104d39c5a0376ee20d (patch)
tree56191aacb80508141d669128159f56b5afef5879 /llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
parentf4b09a3a30875842ea4f8e8fce22936a2a29164e (diff)
downloadbcm5719-llvm-ee110fb735651d63252f70104d39c5a0376ee20d.tar.gz
bcm5719-llvm-ee110fb735651d63252f70104d39c5a0376ee20d.zip
[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 Authored by Guillaume Chatelet llvm-svn: 332579
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp')
-rw-r--r--llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp33
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);
}
}
OpenPOWER on IntegriCloud