summaryrefslogtreecommitdiff
path: root/tools/llvm-profdata
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2016-05-14 05:26:26 +0000
committerChandler Carruth <chandlerc@gmail.com>2016-05-14 05:26:26 +0000
commit2e531af53a61ec306d137b0da83744bc68a36662 (patch)
tree75fc4a59fd49d60bdd54fa7173f08bfe2f9abcb2 /tools/llvm-profdata
parentb01d46ba1cdbe2a03b80efbdbbcf75f8b29cc7a1 (diff)
Revert "Retry "[ProfileData] (llvm) Use Error in InstrProf and Coverage, NFC""
This reverts commit r269491. It triggers warnings with Clang, breaking builds for -Werror users including several build bots. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269547 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-profdata')
-rw-r--r--tools/llvm-profdata/llvm-profdata.cpp68
1 files changed, 27 insertions, 41 deletions
diff --git a/tools/llvm-profdata/llvm-profdata.cpp b/tools/llvm-profdata/llvm-profdata.cpp
index d45e6afa5a5..5cdf962e885 100644
--- a/tools/llvm-profdata/llvm-profdata.cpp
+++ b/tools/llvm-profdata/llvm-profdata.cpp
@@ -47,50 +47,38 @@ static void exitWithError(const Twine &Message, StringRef Whence = "",
::exit(1);
}
-static void exitWithError(Error E, StringRef Whence = "") {
- if (E.isA<InstrProfError>()) {
- handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
- instrprof_error instrError = IPE.get();
- StringRef Hint = "";
- if (instrError == instrprof_error::unrecognized_format) {
- // Hint for common error of forgetting -sample for sample profiles.
- Hint = "Perhaps you forgot to use the -sample option?";
- }
- exitWithError(IPE.message(), Whence, Hint);
- });
+static void exitWithErrorCode(const std::error_code &Error,
+ StringRef Whence = "") {
+ if (Error.category() == instrprof_category()) {
+ instrprof_error instrError = static_cast<instrprof_error>(Error.value());
+ if (instrError == instrprof_error::unrecognized_format) {
+ // Hint for common error of forgetting -sample for sample profiles.
+ exitWithError(Error.message(), Whence,
+ "Perhaps you forgot to use the -sample option?");
+ }
}
-
- exitWithError(toString(std::move(E)), Whence);
-}
-
-static void exitWithErrorCode(std::error_code EC, StringRef Whence = "") {
- exitWithError(EC.message(), Whence);
+ exitWithError(Error.message(), Whence);
}
namespace {
enum ProfileKinds { instr, sample };
}
-static void handleMergeWriterError(Error E, StringRef WhenceFile = "",
+static void handleMergeWriterError(std::error_code &Error,
+ StringRef WhenceFile = "",
StringRef WhenceFunction = "",
bool ShowHint = true) {
if (!WhenceFile.empty())
errs() << WhenceFile << ": ";
if (!WhenceFunction.empty())
errs() << WhenceFunction << ": ";
-
- auto IPE = instrprof_error::success;
- E = handleErrors(std::move(E),
- [&IPE](std::unique_ptr<InstrProfError> E) -> Error {
- IPE = E->get();
- return Error(std::move(E));
- });
- errs() << toString(std::move(E)) << "\n";
+ errs() << Error.message() << "\n";
if (ShowHint) {
StringRef Hint = "";
- if (IPE != instrprof_error::success) {
- switch (IPE) {
+ if (Error.category() == instrprof_category()) {
+ instrprof_error instrError = static_cast<instrprof_error>(Error.value());
+ switch (instrError) {
case instrprof_error::hash_mismatch:
case instrprof_error::count_mismatch:
case instrprof_error::value_site_count_mismatch:
@@ -132,11 +120,11 @@ static void mergeInstrProfile(const WeightedFileVector &Inputs,
exitWithErrorCode(EC, OutputFilename);
InstrProfWriter Writer(OutputSparse);
- SmallSet<instrprof_error, 4> WriterErrorCodes;
+ SmallSet<std::error_code, 4> WriterErrorCodes;
for (const auto &Input : Inputs) {
auto ReaderOrErr = InstrProfReader::create(Input.Filename);
- if (Error E = ReaderOrErr.takeError())
- exitWithError(std::move(E), Input.Filename);
+ if (std::error_code ec = ReaderOrErr.getError())
+ exitWithErrorCode(ec, Input.Filename);
auto Reader = std::move(ReaderOrErr.get());
bool IsIRProfile = Reader->isIRLevelProfile();
@@ -144,16 +132,14 @@ static void mergeInstrProfile(const WeightedFileVector &Inputs,
exitWithError("Merge IR generated profile with Clang generated profile.");
for (auto &I : *Reader) {
- if (Error E = Writer.addRecord(std::move(I), Input.Weight)) {
+ if (std::error_code EC = Writer.addRecord(std::move(I), Input.Weight)) {
// Only show hint the first time an error occurs.
- instrprof_error IPE = InstrProfError::take(std::move(E));
- bool firstTime = WriterErrorCodes.insert(IPE).second;
- handleMergeWriterError(make_error<InstrProfError>(IPE), Input.Filename,
- I.Name, firstTime);
+ bool firstTime = WriterErrorCodes.insert(EC).second;
+ handleMergeWriterError(EC, Input.Filename, I.Name, firstTime);
}
}
if (Reader->hasError())
- exitWithError(Reader->getError(), Input.Filename);
+ exitWithErrorCode(Reader->getError(), Input.Filename);
}
if (OutputFormat == PF_Text)
Writer.writeText(Output);
@@ -201,7 +187,7 @@ static void mergeSampleProfile(const WeightedFileVector &Inputs,
sampleprof_error Result = ProfileMap[FName].merge(Samples, Input.Weight);
if (Result != sampleprof_error::success) {
std::error_code EC = make_error_code(Result);
- handleMergeWriterError(errorCodeToError(EC), Input.Filename, FName);
+ handleMergeWriterError(EC, Input.Filename, FName);
}
}
}
@@ -282,8 +268,8 @@ static int showInstrProfile(std::string Filename, bool ShowCounts,
Cutoffs = {800000, 900000, 950000, 990000, 999000, 999900, 999990};
}
InstrProfSummary PS(Cutoffs);
- if (Error E = ReaderOrErr.takeError())
- exitWithError(std::move(E), Filename);
+ if (std::error_code EC = ReaderOrErr.getError())
+ exitWithErrorCode(EC, Filename);
auto Reader = std::move(ReaderOrErr.get());
bool IsIRInstr = Reader->isIRLevelProfile();
@@ -349,7 +335,7 @@ static int showInstrProfile(std::string Filename, bool ShowCounts,
}
if (Reader->hasError())
- exitWithError(Reader->getError(), Filename);
+ exitWithErrorCode(Reader->getError(), Filename);
if (ShowCounts && TextFormat)
return 0;