summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2018-06-07 07:51:16 +0000
committerGuillaume Chatelet <gchatelet@google.com>2018-06-07 07:51:16 +0000
commit8c91d4cb04ab565d7c0d62c52a9f485a398830e8 (patch)
tree8d6954b4669a6ab95cc0f9efc92fe6ce5b422e88 /llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
parent30c5e4ad35101f88b50bab66bd57ffc66f8a7664 (diff)
downloadbcm5719-llvm-8c91d4cb04ab565d7c0d62c52a9f485a398830e8.tar.gz
bcm5719-llvm-8c91d4cb04ab565d7c0d62c52a9f485a398830e8.zip
[llvm-exegesis] Improve error reporting.
Summary: BenchmarkResult IO functions now return an Error or Expected so caller can deal take proper action. Reviewers: courbet Subscribers: tschuett, llvm-commits Differential Revision: https://reviews.llvm.org/D47868 llvm-svn: 334167
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp')
-rw-r--r--llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp52
1 files changed, 30 insertions, 22 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index aac93abcbe8..9fe7a846353 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -210,27 +210,32 @@ unsigned BenchmarkResultContext::getInstrOpcode(llvm::StringRef Name) const {
}
template <typename ObjectOrList>
-static ObjectOrList readYamlOrDieCommon(const BenchmarkResultContext &Context,
- llvm::StringRef Filename) {
- std::unique_ptr<llvm::MemoryBuffer> MemBuffer = llvm::cantFail(
- llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename)));
- llvm::yaml::Input Yin(*MemBuffer, getUntypedContext(Context));
- ObjectOrList Benchmark;
- Yin >> Benchmark;
- return Benchmark;
+static llvm::Expected<ObjectOrList>
+readYamlCommon(const BenchmarkResultContext &Context,
+ llvm::StringRef Filename) {
+ if (auto ExpectedMemoryBuffer =
+ llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename))) {
+ std::unique_ptr<llvm::MemoryBuffer> MemoryBuffer =
+ std::move(ExpectedMemoryBuffer.get());
+ llvm::yaml::Input Yin(*MemoryBuffer, getUntypedContext(Context));
+ ObjectOrList Benchmark;
+ Yin >> Benchmark;
+ return Benchmark;
+ } else {
+ return ExpectedMemoryBuffer.takeError();
+ }
}
-InstructionBenchmark
-InstructionBenchmark::readYamlOrDie(const BenchmarkResultContext &Context,
- llvm::StringRef Filename) {
- return readYamlOrDieCommon<InstructionBenchmark>(Context, Filename);
+llvm::Expected<InstructionBenchmark>
+InstructionBenchmark::readYaml(const BenchmarkResultContext &Context,
+ llvm::StringRef Filename) {
+ return readYamlCommon<InstructionBenchmark>(Context, Filename);
}
-std::vector<InstructionBenchmark>
-InstructionBenchmark::readYamlsOrDie(const BenchmarkResultContext &Context,
- llvm::StringRef Filename) {
- return readYamlOrDieCommon<std::vector<InstructionBenchmark>>(Context,
- Filename);
+llvm::Expected<std::vector<InstructionBenchmark>>
+InstructionBenchmark::readYamls(const BenchmarkResultContext &Context,
+ llvm::StringRef Filename) {
+ return readYamlCommon<std::vector<InstructionBenchmark>>(Context, Filename);
}
void InstructionBenchmark::writeYamlTo(const BenchmarkResultContext &Context,
@@ -245,18 +250,21 @@ void InstructionBenchmark::readYamlFrom(const BenchmarkResultContext &Context,
Yin >> *this;
}
-// FIXME: Change the API to let the caller handle errors.
-void InstructionBenchmark::writeYamlOrDie(const BenchmarkResultContext &Context,
- const llvm::StringRef Filename) {
+llvm::Error
+InstructionBenchmark::writeYaml(const BenchmarkResultContext &Context,
+ const llvm::StringRef Filename) {
if (Filename == "-") {
writeYamlTo(Context, llvm::outs());
} else {
int ResultFD = 0;
- llvm::cantFail(llvm::errorCodeToError(
- openFileForWrite(Filename, ResultFD, llvm::sys::fs::F_Text)));
+ if (auto E = llvm::errorCodeToError(
+ openFileForWrite(Filename, ResultFD, llvm::sys::fs::F_Text))) {
+ return E;
+ }
llvm::raw_fd_ostream Ostr(ResultFD, true /*shouldClose*/);
writeYamlTo(Context, Ostr);
}
+ return llvm::Error::success();
}
void BenchmarkMeasureStats::push(const BenchmarkMeasure &BM) {
OpenPOWER on IntegriCloud