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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221120 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Diego Novillo
2014-11-03 00:51:45 +00:00
parent b6c9c729dd
commit 2b6bd7aaf5
8 changed files with 65 additions and 51 deletions

View File

@ -737,12 +737,13 @@ INITIALIZE_PASS_END(SampleProfileLoader, "sample-profile",
"Sample Profile loader", false, false)
bool SampleProfileLoader::doInitialization(Module &M) {
if (std::error_code EC =
SampleProfileReader::create(Filename, Reader, M.getContext())) {
auto ReaderOrErr = SampleProfileReader::create(Filename, M.getContext());
if (std::error_code EC = ReaderOrErr.getError()) {
std::string Msg = "Could not open profile: " + EC.message();
M.getContext().diagnose(DiagnosticInfoSampleProfile(Filename.data(), Msg));
return false;
}
Reader = std::move(ReaderOrErr.get());
ProfileIsValid = (Reader->read() == sampleprof_error::success);
return true;
}