diff options
author | Diego Novillo <dnovillo@google.com> | 2014-11-03 00:51:45 +0000 |
---|---|---|
committer | Diego Novillo <dnovillo@google.com> | 2014-11-03 00:51:45 +0000 |
commit | fcd556074c03ab47fe809e1f94fc78a3b3fe94dd (patch) | |
tree | 0a20112f562c2a7dd6c9c11b0eebde6cedecd04c /llvm/tools/llvm-profdata/llvm-profdata.cpp | |
parent | 4cd1d4ecb1a89d6201c24df5f48dd4c5366747fe (diff) | |
download | bcm5719-llvm-fcd556074c03ab47fe809e1f94fc78a3b3fe94dd.tar.gz bcm5719-llvm-fcd556074c03ab47fe809e1f94fc78a3b3fe94dd.zip |
Use ErrorOr for the ::create factory on instrumented and sample profilers.
Summary:
As discussed in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20141027/242445.html,
the creation of reader and writer instances is better done using
ErrorOr. There are no functional changes, but several callers needed to
be adjusted.
Reviewers: bogner
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D6076
llvm-svn: 221120
Diffstat (limited to 'llvm/tools/llvm-profdata/llvm-profdata.cpp')
-rw-r--r-- | llvm/tools/llvm-profdata/llvm-profdata.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 22acedc569a..e97779968d4 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -49,10 +49,11 @@ void mergeInstrProfile(cl::list<std::string> Inputs, StringRef OutputFilename) { InstrProfWriter Writer; for (const auto &Filename : Inputs) { - std::unique_ptr<InstrProfReader> Reader; - if (std::error_code ec = InstrProfReader::create(Filename, Reader)) + auto ReaderOrErr = InstrProfReader::create(Filename); + if (std::error_code ec = ReaderOrErr.getError()) exitWithError(ec.message(), Filename); + auto Reader = std::move(ReaderOrErr.get()); for (const auto &I : *Reader) if (std::error_code EC = Writer.addFunctionCounts(I.Name, I.Hash, I.Counts)) @@ -66,18 +67,19 @@ void mergeInstrProfile(cl::list<std::string> Inputs, StringRef OutputFilename) { void mergeSampleProfile(cl::list<std::string> Inputs, StringRef OutputFilename, sampleprof::SampleProfileFormat OutputFormat) { using namespace sampleprof; - std::unique_ptr<SampleProfileWriter> Writer; - if (std::error_code EC = SampleProfileWriter::create(OutputFilename.data(), - Writer, OutputFormat)) + auto WriterOrErr = SampleProfileWriter::create(OutputFilename, OutputFormat); + if (std::error_code EC = WriterOrErr.getError()) exitWithError(EC.message(), OutputFilename); + auto Writer = std::move(WriterOrErr.get()); StringMap<FunctionSamples> ProfileMap; for (const auto &Filename : Inputs) { - std::unique_ptr<SampleProfileReader> Reader; - if (std::error_code EC = - SampleProfileReader::create(Filename, Reader, getGlobalContext())) + auto ReaderOrErr = + SampleProfileReader::create(Filename, getGlobalContext()); + if (std::error_code EC = ReaderOrErr.getError()) exitWithError(EC.message(), Filename); + auto Reader = std::move(ReaderOrErr.get()); if (std::error_code EC = Reader->read()) exitWithError(EC.message(), Filename); @@ -129,10 +131,11 @@ int merge_main(int argc, const char *argv[]) { int showInstrProfile(std::string Filename, bool ShowCounts, bool ShowAllFunctions, std::string ShowFunction, raw_fd_ostream &OS) { - std::unique_ptr<InstrProfReader> Reader; - if (std::error_code EC = InstrProfReader::create(Filename, Reader)) + auto ReaderOrErr = InstrProfReader::create(Filename); + if (std::error_code EC = ReaderOrErr.getError()) exitWithError(EC.message(), Filename); + auto Reader = std::move(ReaderOrErr.get()); uint64_t MaxFunctionCount = 0, MaxBlockCount = 0; size_t ShownFunctions = 0, TotalFunctions = 0; for (const auto &Func : *Reader) { @@ -182,11 +185,11 @@ int showSampleProfile(std::string Filename, bool ShowCounts, bool ShowAllFunctions, std::string ShowFunction, raw_fd_ostream &OS) { using namespace sampleprof; - std::unique_ptr<SampleProfileReader> Reader; - if (std::error_code EC = - SampleProfileReader::create(Filename, Reader, getGlobalContext())) + auto ReaderOrErr = SampleProfileReader::create(Filename, getGlobalContext()); + if (std::error_code EC = ReaderOrErr.getError()) exitWithError(EC.message(), Filename); + auto Reader = std::move(ReaderOrErr.get()); Reader->read(); if (ShowAllFunctions || ShowFunction.empty()) Reader->dump(OS); |