summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/ProfileData/Coverage/CoverageMapping.cpp86
-rw-r--r--llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp230
-rw-r--r--llvm/lib/ProfileData/InstrProf.cpp133
-rw-r--r--llvm/lib/ProfileData/InstrProfReader.cpp175
-rw-r--r--llvm/lib/ProfileData/InstrProfWriter.cpp5
-rw-r--r--llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp4
-rw-r--r--llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp43
7 files changed, 325 insertions, 351 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 7133697bb87..9fdd37081c9 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -143,30 +143,28 @@ void CounterMappingContext::dump(const Counter &C,
}
if (CounterValues.empty())
return;
- Expected<int64_t> Value = evaluate(C);
- if (auto E = Value.takeError()) {
- llvm::consumeError(std::move(E));
+ ErrorOr<int64_t> Value = evaluate(C);
+ if (!Value)
return;
- }
OS << '[' << *Value << ']';
}
-Expected<int64_t> CounterMappingContext::evaluate(const Counter &C) const {
+ErrorOr<int64_t> CounterMappingContext::evaluate(const Counter &C) const {
switch (C.getKind()) {
case Counter::Zero:
return 0;
case Counter::CounterValueReference:
if (C.getCounterID() >= CounterValues.size())
- return errorCodeToError(errc::argument_out_of_domain);
+ return make_error_code(errc::argument_out_of_domain);
return CounterValues[C.getCounterID()];
case Counter::Expression: {
if (C.getExpressionID() >= Expressions.size())
- return errorCodeToError(errc::argument_out_of_domain);
+ return make_error_code(errc::argument_out_of_domain);
const auto &E = Expressions[C.getExpressionID()];
- Expected<int64_t> LHS = evaluate(E.LHS);
+ ErrorOr<int64_t> LHS = evaluate(E.LHS);
if (!LHS)
return LHS;
- Expected<int64_t> RHS = evaluate(E.RHS);
+ ErrorOr<int64_t> RHS = evaluate(E.RHS);
if (!RHS)
return RHS;
return E.Kind == CounterExpression::Subtract ? *LHS - *RHS : *LHS + *RHS;
@@ -183,7 +181,7 @@ void FunctionRecordIterator::skipOtherFiles() {
*this = FunctionRecordIterator();
}
-Expected<std::unique_ptr<CoverageMapping>>
+ErrorOr<std::unique_ptr<CoverageMapping>>
CoverageMapping::load(CoverageMappingReader &CoverageReader,
IndexedInstrProfReader &ProfileReader) {
auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
@@ -193,14 +191,13 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader,
CounterMappingContext Ctx(Record.Expressions);
Counts.clear();
- if (Error E = ProfileReader.getFunctionCounts(
+ if (std::error_code EC = ProfileReader.getFunctionCounts(
Record.FunctionName, Record.FunctionHash, Counts)) {
- instrprof_error IPE = InstrProfError::take(std::move(E));
- if (IPE == instrprof_error::hash_mismatch) {
+ if (EC == instrprof_error::hash_mismatch) {
Coverage->MismatchedFunctionCount++;
continue;
- } else if (IPE != instrprof_error::unknown_function)
- return make_error<InstrProfError>(IPE);
+ } else if (EC != instrprof_error::unknown_function)
+ return EC;
Counts.assign(Record.MappingRegions.size(), 0);
}
Ctx.setCounts(Counts);
@@ -215,11 +212,9 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader,
getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
FunctionRecord Function(OrigFuncName, Record.Filenames);
for (const auto &Region : Record.MappingRegions) {
- Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
- if (auto E = ExecutionCount.takeError()) {
- llvm::consumeError(std::move(E));
+ ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
+ if (!ExecutionCount)
break;
- }
Function.pushRegion(Region, *ExecutionCount);
}
if (Function.CountedRegions.size() != Record.MappingRegions.size()) {
@@ -233,20 +228,20 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader,
return std::move(Coverage);
}
-Expected<std::unique_ptr<CoverageMapping>>
+ErrorOr<std::unique_ptr<CoverageMapping>>
CoverageMapping::load(StringRef ObjectFilename, StringRef ProfileFilename,
StringRef Arch) {
auto CounterMappingBuff = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
if (std::error_code EC = CounterMappingBuff.getError())
- return errorCodeToError(EC);
+ return EC;
auto CoverageReaderOrErr =
BinaryCoverageReader::create(CounterMappingBuff.get(), Arch);
- if (Error E = CoverageReaderOrErr.takeError())
- return std::move(E);
+ if (std::error_code EC = CoverageReaderOrErr.getError())
+ return EC;
auto CoverageReader = std::move(CoverageReaderOrErr.get());
auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename);
- if (Error E = ProfileReaderOrErr.takeError())
- return std::move(E);
+ if (auto EC = ProfileReaderOrErr.getError())
+ return EC;
auto ProfileReader = std::move(ProfileReaderOrErr.get());
return load(*CoverageReader, *ProfileReader);
}
@@ -538,34 +533,27 @@ CoverageMapping::getCoverageForExpansion(const ExpansionRecord &Expansion) {
}
namespace {
-std::string getCoverageMapErrString(coveragemap_error Err) {
- switch (Err) {
- case coveragemap_error::success:
- return "Success";
- case coveragemap_error::eof:
- return "End of File";
- case coveragemap_error::no_data_found:
- return "No coverage data found";
- case coveragemap_error::unsupported_version:
- return "Unsupported coverage format version";
- case coveragemap_error::truncated:
- return "Truncated coverage data";
- case coveragemap_error::malformed:
- return "Malformed coverage data";
- }
- llvm_unreachable("A value of coveragemap_error has no message.");
-}
-
class CoverageMappingErrorCategoryType : public std::error_category {
const char *name() const LLVM_NOEXCEPT override { return "llvm.coveragemap"; }
std::string message(int IE) const override {
- return getCoverageMapErrString(static_cast<coveragemap_error>(IE));
+ auto E = static_cast<coveragemap_error>(IE);
+ switch (E) {
+ case coveragemap_error::success:
+ return "Success";
+ case coveragemap_error::eof:
+ return "End of File";
+ case coveragemap_error::no_data_found:
+ return "No coverage data found";
+ case coveragemap_error::unsupported_version:
+ return "Unsupported coverage format version";
+ case coveragemap_error::truncated:
+ return "Truncated coverage data";
+ case coveragemap_error::malformed:
+ return "Malformed coverage data";
+ }
+ llvm_unreachable("A value of coveragemap_error has no message.");
}
};
-} // end anonymous namespace
-
-std::string CoverageMapError::message() const {
- return getCoverageMapErrString(Err);
}
static ManagedStatic<CoverageMappingErrorCategoryType> ErrorCategory;
@@ -573,5 +561,3 @@ static ManagedStatic<CoverageMappingErrorCategoryType> ErrorCategory;
const std::error_category &llvm::coverage::coveragemap_category() {
return *ErrorCategory;
}
-
-template <> char ProfErrorInfoBase<coveragemap_error>::ID = 0;
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 999460dd5a8..9f27de91bc5 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -31,54 +31,49 @@ using namespace object;
void CoverageMappingIterator::increment() {
// Check if all the records were read or if an error occurred while reading
// the next record.
- if (auto E = Reader->readNextRecord(Record)) {
- handleAllErrors(std::move(E), [&](const CoverageMapError &CME) {
- if (CME.get() == coveragemap_error::eof)
- *this = CoverageMappingIterator();
- else
- llvm_unreachable("Unexpected error in coverage mapping iterator");
- });
- }
+ if (Reader->readNextRecord(Record))
+ *this = CoverageMappingIterator();
}
-Error RawCoverageReader::readULEB128(uint64_t &Result) {
+std::error_code RawCoverageReader::readULEB128(uint64_t &Result) {
if (Data.size() < 1)
- return make_error<CoverageMapError>(coveragemap_error::truncated);
+ return coveragemap_error::truncated;
unsigned N = 0;
Result = decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);
if (N > Data.size())
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
Data = Data.substr(N);
- return Error::success();
+ return std::error_code();
}
-Error RawCoverageReader::readIntMax(uint64_t &Result, uint64_t MaxPlus1) {
+std::error_code RawCoverageReader::readIntMax(uint64_t &Result,
+ uint64_t MaxPlus1) {
if (auto Err = readULEB128(Result))
return Err;
if (Result >= MaxPlus1)
- return make_error<CoverageMapError>(coveragemap_error::malformed);
- return Error::success();
+ return coveragemap_error::malformed;
+ return std::error_code();
}
-Error RawCoverageReader::readSize(uint64_t &Result) {
+std::error_code RawCoverageReader::readSize(uint64_t &Result) {
if (auto Err = readULEB128(Result))
return Err;
// Sanity check the number.
if (Result > Data.size())
- return make_error<CoverageMapError>(coveragemap_error::malformed);
- return Error::success();
+ return coveragemap_error::malformed;
+ return std::error_code();
}
-Error RawCoverageReader::readString(StringRef &Result) {
+std::error_code RawCoverageReader::readString(StringRef &Result) {
uint64_t Length;
if (auto Err = readSize(Length))
return Err;
Result = Data.substr(0, Length);
Data = Data.substr(Length);
- return Error::success();
+ return std::error_code();
}
-Error RawCoverageFilenamesReader::read() {
+std::error_code RawCoverageFilenamesReader::read() {
uint64_t NumFilenames;
if (auto Err = readSize(NumFilenames))
return Err;
@@ -88,18 +83,19 @@ Error RawCoverageFilenamesReader::read() {
return Err;
Filenames.push_back(Filename);
}
- return Error::success();
+ return std::error_code();
}
-Error RawCoverageMappingReader::decodeCounter(unsigned Value, Counter &C) {
+std::error_code RawCoverageMappingReader::decodeCounter(unsigned Value,
+ Counter &C) {
auto Tag = Value & Counter::EncodingTagMask;
switch (Tag) {
case Counter::Zero:
C = Counter::getZero();
- return Error::success();
+ return std::error_code();
case Counter::CounterValueReference:
C = Counter::getCounter(Value >> Counter::EncodingTagBits);
- return Error::success();
+ return std::error_code();
default:
break;
}
@@ -109,25 +105,25 @@ Error RawCoverageMappingReader::decodeCounter(unsigned Value, Counter &C) {
case CounterExpression::Add: {
auto ID = Value >> Counter::EncodingTagBits;
if (ID >= Expressions.size())
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
Expressions[ID].Kind = CounterExpression::ExprKind(Tag);
C = Counter::getExpression(ID);
break;
}
default:
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
}
- return Error::success();
+ return std::error_code();
}
-Error RawCoverageMappingReader::readCounter(Counter &C) {
+std::error_code RawCoverageMappingReader::readCounter(Counter &C) {
uint64_t EncodedCounter;
if (auto Err =
readIntMax(EncodedCounter, std::numeric_limits<unsigned>::max()))
return Err;
if (auto Err = decodeCounter(EncodedCounter, C))
return Err;
- return Error::success();
+ return std::error_code();
}
static const unsigned EncodingExpansionRegionBit = 1
@@ -136,7 +132,7 @@ static const unsigned EncodingExpansionRegionBit = 1
/// \brief Read the sub-array of regions for the given inferred file id.
/// \param NumFileIDs the number of file ids that are defined for this
/// function.
-Error RawCoverageMappingReader::readMappingRegionsSubArray(
+std::error_code RawCoverageMappingReader::readMappingRegionsSubArray(
std::vector<CounterMappingRegion> &MappingRegions, unsigned InferredFileID,
size_t NumFileIDs) {
uint64_t NumRegions;
@@ -164,7 +160,7 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray(
ExpandedFileID = EncodedCounterAndRegion >>
Counter::EncodingCounterTagAndExpansionRegionTagBits;
if (ExpandedFileID >= NumFileIDs)
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
} else {
switch (EncodedCounterAndRegion >>
Counter::EncodingCounterTagAndExpansionRegionTagBits) {
@@ -175,7 +171,7 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray(
Kind = CounterMappingRegion::SkippedRegion;
break;
default:
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
}
}
}
@@ -188,7 +184,7 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray(
if (auto Err = readULEB128(ColumnStart))
return Err;
if (ColumnStart > std::numeric_limits<unsigned>::max())
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
if (auto Err = readIntMax(NumLines, std::numeric_limits<unsigned>::max()))
return Err;
if (auto Err = readIntMax(ColumnEnd, std::numeric_limits<unsigned>::max()))
@@ -222,10 +218,10 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray(
C, InferredFileID, ExpandedFileID, LineStart, ColumnStart,
LineStart + NumLines, ColumnEnd, Kind));
}
- return Error::success();
+ return std::error_code();
}
-Error RawCoverageMappingReader::read() {
+std::error_code RawCoverageMappingReader::read() {
// Read the virtual file mapping.
llvm::SmallVector<unsigned, 8> VirtualFileMapping;
@@ -291,14 +287,14 @@ Error RawCoverageMappingReader::read() {
}
}
- return Error::success();
+ return std::error_code();
}
-Error InstrProfSymtab::create(SectionRef &Section) {
- if (auto EC = Section.getContents(Data))
- return errorCodeToError(EC);
+std::error_code InstrProfSymtab::create(SectionRef &Section) {
+ if (auto Err = Section.getContents(Data))
+ return Err;
Address = Section.getAddress();
- return Error::success();
+ return std::error_code();
}
StringRef InstrProfSymtab::getFuncName(uint64_t Pointer, size_t Size) {
@@ -316,10 +312,11 @@ struct CovMapFuncRecordReader {
// a module. \p Buf is a reference to the buffer pointer pointing
// to the \c CovHeader of coverage mapping data associated with
// the module.
- virtual Error readFunctionRecords(const char *&Buf, const char *End) = 0;
+ virtual std::error_code readFunctionRecords(const char *&Buf,
+ const char *End) = 0;
virtual ~CovMapFuncRecordReader() {}
template <class IntPtrT, support::endianness Endian>
- static Expected<std::unique_ptr<CovMapFuncRecordReader>>
+ static ErrorOr<std::unique_ptr<CovMapFuncRecordReader>>
get(coverage::CovMapVersion Version, InstrProfSymtab &P,
std::vector<BinaryCoverageReader::ProfileMappingRecord> &R,
std::vector<StringRef> &F);
@@ -347,10 +344,11 @@ public:
: ProfileNames(P), Filenames(F), Records(R) {}
~VersionedCovMapFuncRecordReader() override {}
- Error readFunctionRecords(const char *&Buf, const char *End) override {
+ std::error_code readFunctionRecords(const char *&Buf,
+ const char *End) override {
using namespace support;
if (Buf + sizeof(CovMapHeader) > End)
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
auto CovHeader = reinterpret_cast<const coverage::CovMapHeader *>(Buf);
uint32_t NRecords = CovHeader->getNRecords<Endian>();
uint32_t FilenamesSize = CovHeader->getFilenamesSize<Endian>();
@@ -365,7 +363,7 @@ public:
// Get the filenames.
if (Buf + FilenamesSize > End)
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
size_t FilenamesBegin = Filenames.size();
RawCoverageFilenamesReader Reader(StringRef(Buf, FilenamesSize), Filenames);
if (auto Err = Reader.read())
@@ -378,7 +376,7 @@ public:
const char *CovEnd = Buf;
if (Buf > End)
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
// Each coverage map has an alignment of 8, so we need to adjust alignment
// before reading the next map.
Buf += alignmentAdjustment(Buf, 8);
@@ -391,7 +389,7 @@ public:
// Now use that to read the coverage data.
if (CovBuf + DataSize > CovEnd)
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
auto Mapping = StringRef(CovBuf, DataSize);
CovBuf += DataSize;
@@ -405,20 +403,21 @@ public:
}
StringRef FuncName;
- if (Error E = CFR->template getFuncName<Endian>(ProfileNames, FuncName))
- return E;
+ if (std::error_code EC =
+ CFR->template getFuncName<Endian>(ProfileNames, FuncName))
+ return EC;
Records.push_back(BinaryCoverageReader::ProfileMappingRecord(
Version, FuncName, FuncHash, Mapping, FilenamesBegin,
Filenames.size() - FilenamesBegin));
CFR++;
}
- return Error::success();
+ return std::error_code();
}
};
} // end anonymous namespace
template <class IntPtrT, support::endianness Endian>
-Expected<std::unique_ptr<CovMapFuncRecordReader>> CovMapFuncRecordReader::get(
+ErrorOr<std::unique_ptr<CovMapFuncRecordReader>> CovMapFuncRecordReader::get(
coverage::CovMapVersion Version, InstrProfSymtab &P,
std::vector<BinaryCoverageReader::ProfileMappingRecord> &R,
std::vector<StringRef> &F) {
@@ -429,8 +428,8 @@ Expected<std::unique_ptr<CovMapFuncRecordReader>> CovMapFuncRecordReader::get(
CovMapVersion::Version1, IntPtrT, Endian>>(P, R, F);
case CovMapVersion::Version2:
// Decompress the name data.
- if (Error E = P.create(P.getNameData()))
- return std::move(E);
+ if (auto EC = P.create(P.getNameData()))
+ return EC;
return llvm::make_unique<VersionedCovMapFuncRecordReader<
CovMapVersion::Version2, IntPtrT, Endian>>(P, R, F);
}
@@ -438,7 +437,7 @@ Expected<std::unique_ptr<CovMapFuncRecordReader>> CovMapFuncRecordReader::get(
}
template <typename T, support::endianness Endian>
-static Error readCoverageMappingData(
+static std::error_code readCoverageMappingData(
InstrProfSymtab &ProfileNames, StringRef Data,
std::vector<BinaryCoverageReader::ProfileMappingRecord> &Records,
std::vector<StringRef> &Filenames) {
@@ -448,90 +447,89 @@ static Error readCoverageMappingData(
reinterpret_cast<const coverage::CovMapHeader *>(Data.data());
CovMapVersion Version = (CovMapVersion)CovHeader->getVersion<Endian>();
if (Version > coverage::CovMapVersion::CurrentVersion)
- return make_error<CoverageMapError>(coveragemap_error::unsupported_version);
- Expected<std::unique_ptr<CovMapFuncRecordReader>> ReaderExpected =
+ return coveragemap_error::unsupported_version;
+ ErrorOr<std::unique_ptr<CovMapFuncRecordReader>> ReaderErrorOr =
CovMapFuncRecordReader::get<T, Endian>(Version, ProfileNames, Records,
Filenames);
- if (Error E = ReaderExpected.takeError())
- return E;
- auto Reader = std::move(ReaderExpected.get());
+ if (auto EC = ReaderErrorOr.getError())
+ return EC;
+ auto Reader = std::move(ReaderErrorOr.get());
for (const char *Buf = Data.data(), *End = Buf + Data.size(); Buf < End;) {
- if (Error E = Reader->readFunctionRecords(Buf, End))
- return E;
+ if (std::error_code EC = Reader->readFunctionRecords(Buf, End))
+ return EC;
}
- return Error::success();
+ return std::error_code();
}
static const char *TestingFormatMagic = "llvmcovmtestdata";
-static Error loadTestingFormat(StringRef Data, InstrProfSymtab &ProfileNames,
- StringRef &CoverageMapping,
- uint8_t &BytesInAddress,
- support::endianness &Endian) {
+static std::error_code loadTestingFormat(StringRef Data,
+ InstrProfSymtab &ProfileNames,
+ StringRef &CoverageMapping,
+ uint8_t &BytesInAddress,
+ support::endianness &Endian) {
BytesInAddress = 8;
Endian = support::endianness::little;
Data = Data.substr(StringRef(TestingFormatMagic).size());
if (Data.size() < 1)
- return make_error<CoverageMapError>(coveragemap_error::truncated);
+ return coveragemap_error::truncated;
unsigned N = 0;
auto ProfileNamesSize =
decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);
if (N > Data.size())
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
Data = Data.substr(N);
if (Data.size() < 1)
- return make_error<CoverageMapError>(coveragemap_error::truncated);
+ return coveragemap_error::truncated;
N = 0;
uint64_t Address =
decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);
if (N > Data.size())
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
Data = Data.substr(N);
if (Data.size() < ProfileNamesSize)
- return make_error<CoverageMapError>(coveragemap_error::malformed);
- if (Error E = ProfileNames.create(Data.substr(0, ProfileNamesSize), Address))
- return E;
+ return coveragemap_error::malformed;
+ ProfileNames.create(Data.substr(0, ProfileNamesSize), Address);
CoverageMapping = Data.substr(ProfileNamesSize);
- return Error::success();
+ return std::error_code();
}
-static Expected<SectionRef> lookupSection(ObjectFile &OF, StringRef Name) {
+static ErrorOr<SectionRef> lookupSection(ObjectFile &OF, StringRef Name) {
StringRef FoundName;
for (const auto &Section : OF.sections()) {
if (auto EC = Section.getName(FoundName))
- return errorCodeToError(EC);
+ return EC;
if (FoundName == Name)
return Section;
}
- return make_error<CoverageMapError>(coveragemap_error::no_data_found);
+ return coveragemap_error::no_data_found;
}
-static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer,
- InstrProfSymtab &ProfileNames,
- StringRef &CoverageMapping,
- uint8_t &BytesInAddress,
- support::endianness &Endian, StringRef Arch) {
+static std::error_code
+loadBinaryFormat(MemoryBufferRef ObjectBuffer, InstrProfSymtab &ProfileNames,
+ StringRef &CoverageMapping, uint8_t &BytesInAddress,
+ support::endianness &Endian, StringRef Arch) {
auto BinOrErr = object::createBinary(ObjectBuffer);
if (!BinOrErr)
- return BinOrErr.takeError();
+ return errorToErrorCode(BinOrErr.takeError());
auto Bin = std::move(BinOrErr.get());
std::unique_ptr<ObjectFile> OF;
if (auto *Universal = dyn_cast<object::MachOUniversalBinary>(Bin.get())) {
// If we have a universal binary, try to look up the object for the
// appropriate architecture.
auto ObjectFileOrErr = Universal->getObjectForArch(Arch);
- if (auto EC = ObjectFileOrErr.getError())
- return errorCodeToError(EC);
+ if (std::error_code EC = ObjectFileOrErr.getError())
+ return EC;
OF = std::move(ObjectFileOrErr.get());
} else if (isa<object::ObjectFile>(Bin.get())) {
// For any other object file, upcast and take ownership.
OF.reset(cast<object::ObjectFile>(Bin.release()));
// If we've asked for a particular arch, make sure they match.
if (!Arch.empty() && OF->getArch() != Triple(Arch).getArch())
- return errorCodeToError(object_error::arch_not_found);
+ return object_error::arch_not_found;
} else
// We can only handle object files.
- return make_error<CoverageMapError>(coveragemap_error::malformed);
+ return coveragemap_error::malformed;
// The coverage uses native pointer sizes for the object it's written in.
BytesInAddress = OF->getBytesInAddress();
@@ -540,23 +538,23 @@ static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer,
// Look for the sections that we are interested in.
auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName(false));
- if (auto E = NamesSection.takeError())
- return E;
+ if (auto EC = NamesSection.getError())
+ return EC;
auto CoverageSection =
lookupSection(*OF, getInstrProfCoverageSectionName(false));
- if (auto E = CoverageSection.takeError())
- return E;
+ if (auto EC = CoverageSection.getError())
+ return EC;
// Get the contents of the given sections.
- if (auto EC = CoverageSection->getContents(CoverageMapping))
- return errorCodeToError(EC);
- if (Error E = ProfileNames.create(*NamesSection))
- return E;
+ if (std::error_code EC = CoverageSection->getContents(CoverageMapping))
+ return EC;
+ if (std::error_code EC = ProfileNames.create(*NamesSection))
+ return EC;
- return Error::success();
+ return std::error_code();
}
-Expected<std::unique_ptr<BinaryCoverageReader>>
+ErrorOr<std::unique_ptr<BinaryCoverageReader>>
BinaryCoverageReader::create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
StringRef Arch) {
std::unique_ptr<BinaryCoverageReader> Reader(new BinaryCoverageReader());
@@ -564,44 +562,44 @@ BinaryCoverageReader::create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
StringRef Coverage;
uint8_t BytesInAddress;
support::endianness Endian;
- Error E;
- consumeError(std::move(E));
+ std::error_code EC;
if (ObjectBuffer->getBuffer().startswith(TestingFormatMagic))
// This is a special format used for testing.
- E = loadTestingFormat(ObjectBuffer->getBuffer(), Reader->ProfileNames,
- Coverage, BytesInAddress, Endian);
+ EC = loadTestingFormat(ObjectBuffer->getBuffer(), Reader->ProfileNames,
+ Coverage, BytesInAddress, Endian);
else
- E = loadBinaryFormat(ObjectBuffer->getMemBufferRef(), Reader->ProfileNames,
- Coverage, BytesInAddress, Endian, Arch);
- if (E)
- return std::move(E);
+ EC = loadBinaryFormat(ObjectBuffer->getMemBufferRef(), Reader->ProfileNames,
+ Coverage, BytesInAddress, Endian, Arch);
+ if (EC)
+ return EC;
if (BytesInAddress == 4 && Endian == support::endianness::little)
- E = readCoverageMappingData<uint32_t, support::endianness::little>(
+ EC = readCoverageMappingData<uint32_t, support::endianness::little>(
Reader->ProfileNames, Coverage, Reader->MappingRecords,
Reader->Filenames);
else if (BytesInAddress == 4 && Endian == support::endianness::big)
- E = readCoverageMappingData<uint32_t, support::endianness::big>(
+ EC = readCoverageMappingData<uint32_t, support::endianness::big>(
Reader->ProfileNames, Coverage, Reader->MappingRecords,
Reader->Filenames);
else if (BytesInAddress == 8 && Endian == support::endianness::little)
- E = readCoverageMappingData<uint64_t, support::endianness::little>(
+ EC = readCoverageMappingData<uint64_t, support::endianness::little>(
Reader->ProfileNames, Coverage, Reader->MappingRecords,
Reader->Filenames);
else if (BytesInAddress == 8 && Endian == support::endianness::big)
- E = readCoverageMappingData<uint64_t, support::endianness::big>(
+ EC = readCoverageMappingData<uint64_t, support::endianness::big>(
Reader->ProfileNames, Coverage, Reader->MappingRecords,
Reader->Filenames);
else
- return make_error<CoverageMapError>(coveragemap_error::malformed);
- if (E)
- return std::move(E);
+ return coveragemap_error::malformed;
+ if (EC)
+ return EC;
return std::move(Reader);
}
-Error BinaryCoverageReader::readNextRecord(CoverageMappingRecord &Record) {
+std::error_code
+BinaryCoverageReader::readNextRecord(CoverageMappingRecord &Record) {
if (CurrentRecord >= MappingRecords.size())
- return make_error<CoverageMapError>(coveragemap_error::eof);
+ return coveragemap_error::eof;
FunctionsFilenames.clear();
Expressions.clear();
@@ -621,5 +619,5 @@ Error BinaryCoverageReader::readNextRecord(CoverageMappingRecord &Record) {
Record.MappingRegions = MappingRegions;
++CurrentRecord;
- return Error::success();
+ return std::error_code();
}
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 7042a5825cd..bcb31993d20 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -27,50 +27,47 @@
using namespace llvm;
namespace {
-std::string getInstrProfErrString(instrprof_error Err) {
- switch (Err) {
- case instrprof_error::success:
- return "Success";
- case instrprof_error::eof:
- return "End of File";
- case instrprof_error::unrecognized_format:
- return "Unrecognized instrumentation profile encoding format";
- case instrprof_error::bad_magic:
- return "Invalid instrumentation profile data (bad magic)";
- case instrprof_error::bad_header:
- return "Invalid instrumentation profile data (file header is corrupt)";
- case instrprof_error::unsupported_version:
- return "Unsupported instrumentation profile format version";
- case instrprof_error::unsupported_hash_type:
- return "Unsupported instrumentation profile hash type";
- case instrprof_error::too_large:
- return "Too much profile data";
- case instrprof_error::truncated:
- return "Truncated profile data";
- case instrprof_error::malformed:
- return "Malformed instrumentation profile data";
- case instrprof_error::unknown_function:
- return "No profile data available for function";
- case instrprof_error::hash_mismatch:
- return "Function control flow change detected (hash mismatch)";
- case instrprof_error::count_mismatch:
- return "Function basic block count change detected (counter mismatch)";
- case instrprof_error::counter_overflow:
- return "Counter overflow";
- case instrprof_error::value_site_count_mismatch:
- return "Function value site count change detected (counter mismatch)";
- case instrprof_error::compress_failed:
- return "Failed to compress data (zlib)";
- case instrprof_error::uncompress_failed:
- return "Failed to uncompress data (zlib)";
- }
- llvm_unreachable("A value of instrprof_error has no message.");
-}
-
class InstrProfErrorCategoryType : public std::error_category {
const char *name() const LLVM_NOEXCEPT override { return "llvm.instrprof"; }
std::string message(int IE) const override {
- return getInstrProfErrString(static_cast<instrprof_error>(IE));
+ instrprof_error E = static_cast<instrprof_error>(IE);
+ switch (E) {
+ case instrprof_error::success:
+ return "Success";
+ case instrprof_error::eof:
+ return "End of File";
+ case instrprof_error::unrecognized_format:
+ return "Unrecognized instrumentation profile encoding format";
+ case instrprof_error::bad_magic:
+ return "Invalid instrumentation profile data (bad magic)";
+ case instrprof_error::bad_header:
+ return "Invalid instrumentation profile data (file header is corrupt)";
+ case instrprof_error::unsupported_version:
+ return "Unsupported instrumentation profile format version";
+ case instrprof_error::unsupported_hash_type:
+ return "Unsupported instrumentation profile hash type";
+ case instrprof_error::too_large:
+ return "Too much profile data";
+ case instrprof_error::truncated:
+ return "Truncated profile data";
+ case instrprof_error::malformed:
+ return "Malformed instrumentation profile data";
+ case instrprof_error::unknown_function:
+ return "No profile data available for function";
+ case instrprof_error::hash_mismatch:
+ return "Function control flow change detected (hash mismatch)";
+ case instrprof_error::count_mismatch:
+ return "Function basic block count change detected (counter mismatch)";
+ case instrprof_error::counter_overflow:
+ return "Counter overflow";
+ case instrprof_error::value_site_count_mismatch:
+ return "Function value site count change detected (counter mismatch)";
+ case instrprof_error::compress_failed:
+ return "Failed to compress data (zlib)";
+ case instrprof_error::uncompress_failed:
+ return "Failed to uncompress data (zlib)";
+ }
+ llvm_unreachable("A value of instrprof_error has no message.");
}
};
} // end anonymous namespace
@@ -108,12 +105,6 @@ void SoftInstrProfErrors::addError(instrprof_error IE) {
}
}
-std::string InstrProfError::message() const {
- return getInstrProfErrString(Err);
-}
-
-template <> char ProfErrorInfoBase<instrprof_error>::ID = 0;
-
std::string getPGOFuncName(StringRef RawFuncName,
GlobalValue::LinkageTypes Linkage,
StringRef FileName,
@@ -223,8 +214,9 @@ void InstrProfSymtab::create(Module &M, bool InLTO) {
finalizeSymtab();
}
-Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
- bool doCompression, std::string &Result) {
+std::error_code
+collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
+ bool doCompression, std::string &Result) {
assert(NameStrs.size() && "No name data to emit");
uint8_t Header[16], *P = Header;
@@ -246,12 +238,11 @@ Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
unsigned HeaderLen = P - &Header[0];
Result.append(HeaderStr, HeaderLen);
Result += InputStr;
- return Error::success();
+ return make_error_code(instrprof_error::success);
};
- if (!doCompression) {
+ if (!doCompression)
return WriteStringToResult(0, UncompressedNameStrings);
- }
SmallVector<char, 128> CompressedNameStrings;
zlib::Status Success =
@@ -259,7 +250,7 @@ Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
zlib::BestSizeCompression);
if (Success != zlib::StatusOK)
- return make_error<InstrProfError>(instrprof_error::compress_failed);
+ return make_error_code(instrprof_error::compress_failed);
return WriteStringToResult(
CompressedNameStrings.size(),
@@ -273,8 +264,9 @@ StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar) {
return NameStr;
}
-Error collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,
- std::string &Result, bool doCompression) {
+std::error_code
+collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,
+ std::string &Result, bool doCompression) {
std::vector<std::string> NameStrs;
for (auto *NameVar : NameVars) {
NameStrs.push_back(getPGOFuncNameVarInitializer(NameVar));
@@ -283,7 +275,8 @@ Error collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,
NameStrs, zlib::isAvailable() && doCompression, Result);
}
-Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
+std::error_code readPGOFuncNameStrings(StringRef NameStrings,
+ InstrProfSymtab &Symtab) {
const uint8_t *P = reinterpret_cast<const uint8_t *>(NameStrings.data());
const uint8_t *EndP = reinterpret_cast<const uint8_t *>(NameStrings.data() +
NameStrings.size());
@@ -301,7 +294,7 @@ Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
CompressedSize);
if (zlib::uncompress(CompressedNameStrings, UncompressedNameStrings,
UncompressedSize) != zlib::StatusOK)
- return make_error<InstrProfError>(instrprof_error::uncompress_failed);
+ return make_error_code(instrprof_error::uncompress_failed);
P += CompressedSize;
NameStrings = StringRef(UncompressedNameStrings.data(),
UncompressedNameStrings.size());
@@ -320,7 +313,7 @@ Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
P++;
}
Symtab.finalizeSymtab();
- return Error::success();
+ return make_error_code(instrprof_error::success);
}
void InstrProfValueSiteRecord::merge(SoftInstrProfErrors &SIPE,
@@ -584,45 +577,45 @@ static std::unique_ptr<ValueProfData> allocValueProfData(uint32_t TotalSize) {
ValueProfData());
}
-Error ValueProfData::checkIntegrity() {
+instrprof_error ValueProfData::checkIntegrity() {
if (NumValueKinds > IPVK_Last + 1)
- return make_error<InstrProfError>(instrprof_error::malformed);
+ return instrprof_error::malformed;
// Total size needs to be mulltiple of quadword size.
if (TotalSize % sizeof(uint64_t))
- return make_error<InstrProfError>(instrprof_error::malformed);
+ return instrprof_error::malformed;
ValueProfRecord *VR = getFirstValueProfRecord(this);
for (uint32_t K = 0; K < this->NumValueKinds; K++) {
if (VR->Kind > IPVK_Last)
- return make_error<InstrProfError>(instrprof_error::malformed);
+ return instrprof_error::malformed;
VR = getValueProfRecordNext(VR);
if ((char *)VR - (char *)this > (ptrdiff_t)TotalSize)
- return make_error<InstrProfError>(instrprof_error::malformed);
+ return instrprof_error::malformed;
}
- return Error::success();
+ return instrprof_error::success;
}
-Expected<std::unique_ptr<ValueProfData>>
+ErrorOr<std::unique_ptr<ValueProfData>>
ValueProfData::getValueProfData(const unsigned char *D,
const unsigned char *const BufferEnd,
support::endianness Endianness) {
using namespace support;
if (D + sizeof(ValueProfData) > BufferEnd)
- return make_error<InstrProfError>(instrprof_error::truncated);
+ return instrprof_error::truncated;
const unsigned char *Header = D;
uint32_t TotalSize = swapToHostOrder<uint32_t>(Header, Endianness);
if (D + TotalSize > BufferEnd)
- return make_error<InstrProfError>(instrprof_error::too_large);
+ return instrprof_error::too_large;
std::unique_ptr<ValueProfData> VPD = allocValueProfData(TotalSize);
memcpy(VPD.get(), D, TotalSize);
// Byte swap.
VPD->swapBytesToHost(Endianness);
- Error E = VPD->checkIntegrity();
- if (E)
- return std::move(E);
+ instrprof_error EC = VPD->checkIntegrity();
+ if (EC != instrprof_error::success)
+ return EC;
return std::move(VPD);
}
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 2678ac28561..0828bb2c3fc 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -18,33 +18,33 @@
using namespace llvm;
-static Expected<std::unique_ptr<MemoryBuffer>>
+static ErrorOr<std::unique_ptr<MemoryBuffer>>
setupMemoryBuffer(std::string Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFileOrSTDIN(Path);
if (std::error_code EC = BufferOrErr.getError())
- return errorCodeToError(EC);
+ return EC;
return std::move(BufferOrErr.get());
}
-static Error initializeReader(InstrProfReader &Reader) {
+static std::error_code initializeReader(InstrProfReader &Reader) {
return Reader.readHeader();
}
-Expected<std::unique_ptr<InstrProfReader>>
+ErrorOr<std::unique_ptr<InstrProfReader>>
InstrProfReader::create(std::string Path) {
// Set up the buffer to read.
auto BufferOrError = setupMemoryBuffer(Path);
- if (Error E = BufferOrError.takeError())
- return std::move(E);
+ if (std::error_code EC = BufferOrError.getError())
+ return EC;
return InstrProfReader::create(std::move(BufferOrError.get()));
}
-Expected<std::unique_ptr<InstrProfReader>>
+ErrorOr<std::unique_ptr<InstrProfReader>>
InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
// Sanity check the buffer.
if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
- return make_error<InstrProfError>(instrprof_error::too_large);
+ return instrprof_error::too_large;
std::unique_ptr<InstrProfReader> Result;
// Create the reader.
@@ -57,49 +57,46 @@ InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
else if (TextInstrProfReader::hasFormat(*Buffer))
Result.reset(new TextInstrProfReader(std::move(Buffer)));
else
- return make_error<InstrProfError>(instrprof_error::unrecognized_format);
+ return instrprof_error::unrecognized_format;
// Initialize the reader and return the result.
- if (Error E = initializeReader(*Result))
- return std::move(E);
+ if (std::error_code EC = initializeReader(*Result))
+ return EC;
return std::move(Result);
}
-Expected<std::unique_ptr<IndexedInstrProfReader>>
+ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
IndexedInstrProfReader::create(std::string Path) {
// Set up the buffer to read.
auto BufferOrError = setupMemoryBuffer(Path);
- if (Error E = BufferOrError.takeError())
- return std::move(E);
+ if (std::error_code EC = BufferOrError.getError())
+ return EC;
return IndexedInstrProfReader::create(std::move(BufferOrError.get()));
}
-Expected<std::unique_ptr<IndexedInstrProfReader>>
+ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
IndexedInstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
// Sanity check the buffer.
if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
- return make_error<InstrProfError>(instrprof_error::too_large);
+ return instrprof_error::too_large;
// Create the reader.
if (!IndexedInstrProfReader::hasFormat(*Buffer))
- return make_error<InstrProfError>(instrprof_error::bad_magic);
+ return instrprof_error::bad_magic;
auto Result = llvm::make_unique<IndexedInstrProfReader>(std::move(Buffer));
// Initialize the reader and return the result.
- if (Error E = initializeReader(*Result))
- return std::move(E);
+ if (std::error_code EC = initializeReader(*Result))
+ return EC;
return std::move(Result);
}
void InstrProfIterator::Increment() {
- if (auto E = Reader->readNextRecord(Record)) {
- // Handle errors in the reader.
- InstrProfError::take(std::move(E));
+ if (Reader->readNextRecord(Record))
*this = InstrProfIterator();
- }
}
bool TextInstrProfReader::hasFormat(const MemoryBuffer &Buffer) {
@@ -115,7 +112,7 @@ bool TextInstrProfReader::hasFormat(const MemoryBuffer &Buffer) {
// Read the profile variant flag from the header: ":FE" means this is a FE
// generated profile. ":IR" means this is an IR level profile. Other strings
// with a leading ':' will be reported an error format.
-Error TextInstrProfReader::readHeader() {
+std::error_code TextInstrProfReader::readHeader() {
Symtab.reset(new InstrProfSymtab());
bool IsIRInstr = false;
if (!Line->startswith(":")) {
@@ -128,14 +125,14 @@ Error TextInstrProfReader::readHeader() {
else if (Str.equals_lower("fe"))
IsIRInstr = false;
else
- return error(instrprof_error::bad_header);
+ return instrprof_error::bad_header;
++Line;
IsIRLevelProfile = IsIRInstr;
return success();
}
-Error
+std::error_code
TextInstrProfReader::readValueProfileData(InstrProfRecord &Record) {
#define CHECK_LINE_END(Line) \
@@ -199,7 +196,7 @@ TextInstrProfReader::readValueProfileData(InstrProfRecord &Record) {
#undef VP_READ_ADVANCE
}
-Error TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {
+std::error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {
// Skip empty lines and comments.
while (!Line.is_at_end() && (Line->empty() || Line->startswith("#")))
++Line;
@@ -241,8 +238,8 @@ Error TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {
}
// Check if value profile data exists and read it if so.
- if (Error E = readValueProfileData(Record))
- return E;
+ if (std::error_code EC = readValueProfileData(Record))
+ return EC;
// This is needed to avoid two pass parsing because llvm-profdata
// does dumping while reading.
@@ -261,7 +258,7 @@ bool RawInstrProfReader<IntPtrT>::hasFormat(const MemoryBuffer &DataBuffer) {
}
template <class IntPtrT>
-Error RawInstrProfReader<IntPtrT>::readHeader() {
+std::error_code RawInstrProfReader<IntPtrT>::readHeader() {
if (!hasFormat(*DataBuffer))
return error(instrprof_error::bad_magic);
if (DataBuffer->getBufferSize() < sizeof(RawInstrProf::Header))
@@ -273,25 +270,26 @@ Error RawInstrProfReader<IntPtrT>::readHeader() {
}
template <class IntPtrT>
-Error RawInstrProfReader<IntPtrT>::readNextHeader(const char *CurrentPos) {
+std::error_code
+RawInstrProfReader<IntPtrT>::readNextHeader(const char *CurrentPos) {
const char *End = DataBuffer->getBufferEnd();
// Skip zero padding between profiles.
while (CurrentPos != End && *CurrentPos == 0)
++CurrentPos;
// If there's nothing left, we're done.
if (CurrentPos == End)
- return make_error<InstrProfError>(instrprof_error::eof);
+ return instrprof_error::eof;
// If there isn't enough space for another header, this is probably just
// garbage at the end of the file.
if (CurrentPos + sizeof(RawInstrProf::Header) > End)
- return make_error<InstrProfError>(instrprof_error::malformed);
+ return instrprof_error::malformed;
// The writer ensures each profile is padded to start at an aligned address.
if (reinterpret_cast<size_t>(CurrentPos) % alignOf<uint64_t>())
- return make_error<InstrProfError>(instrprof_error::malformed);
+ return instrprof_error::malformed;
// The magic should have the same byte order as in the previous header.
uint64_t Magic = *reinterpret_cast<const uint64_t *>(CurrentPos);
if (Magic != swap(RawInstrProf::getMagic<IntPtrT>()))
- return make_error<InstrProfError>(instrprof_error::bad_magic);
+ return instrprof_error::bad_magic;
// There's another profile to read, so we need to process the header.
auto *Header = reinterpret_cast<const RawInstrProf::Header *>(CurrentPos);
@@ -299,9 +297,11 @@ Error RawInstrProfReader<IntPtrT>::readNextHeader(const char *CurrentPos) {
}
template <class IntPtrT>
-Error RawInstrProfReader<IntPtrT>::createSymtab(InstrProfSymtab &Symtab) {
- if (Error E = Symtab.create(StringRef(NamesStart, NamesSize)))
- return error(std::move(E));
+std::error_code
+RawInstrProfReader<IntPtrT>::createSymtab(InstrProfSymtab &Symtab) {
+ std::error_code EC = Symtab.create(StringRef(NamesStart, NamesSize));
+ if (EC)
+ return EC;
for (const RawInstrProf::ProfileData<IntPtrT> *I = Data; I != DataEnd; ++I) {
const IntPtrT FPtr = swap(I->FunctionPointer);
if (!FPtr)
@@ -313,8 +313,8 @@ Error RawInstrProfReader<IntPtrT>::createSymtab(InstrProfSymtab &Symtab) {
}
template <class IntPtrT>
-Error RawInstrProfReader<IntPtrT>::readHeader(
- const RawInstrProf::Header &Header) {
+std::error_code
+RawInstrProfReader<IntPtrT>::readHeader(const RawInstrProf::Header &Header) {
Version = swap(Header.Version);
if (GET_VERSION(Version) != RawInstrProf::Version)
return error(instrprof_error::unsupported_version);
@@ -346,27 +346,28 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
ValueDataStart = reinterpret_cast<const uint8_t *>(Start + ValueDataOffset);
std::unique_ptr<InstrProfSymtab> NewSymtab = make_unique<InstrProfSymtab>();
- if (Error E = createSymtab(*NewSymtab.get()))
- return E;
+ if (auto EC = createSymtab(*NewSymtab.get()))
+ return EC;
Symtab = std::move(NewSymtab);
return success();
}
template <class IntPtrT>
-Error RawInstrProfReader<IntPtrT>::readName(InstrProfRecord &Record) {
+std::error_code RawInstrProfReader<IntPtrT>::readName(InstrProfRecord &Record) {
Record.Name = getName(Data->NameRef);
return success();
}
template <class IntPtrT>
-Error RawInstrProfReader<IntPtrT>::readFuncHash(InstrProfRecord &Record) {
+std::error_code RawInstrProfReader<IntPtrT>::readFuncHash(
+ InstrProfRecord &Record) {
Record.Hash = swap(Data->FuncHash);
return success();
}
template <class IntPtrT>
-Error RawInstrProfReader<IntPtrT>::readRawCounts(
+std::error_code RawInstrProfReader<IntPtrT>::readRawCounts(
InstrProfRecord &Record) {
uint32_t NumCounters = swap(Data->NumCounters);
IntPtrT CounterPtr = Data->CounterPtr;
@@ -393,8 +394,8 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(
}
template <class IntPtrT>
-Error RawInstrProfReader<IntPtrT>::readValueProfilingData(
- InstrProfRecord &Record) {
+std::error_code
+RawInstrProfReader<IntPtrT>::readValueProfilingData(InstrProfRecord &Record) {
Record.clearValueData();
CurValueDataSize = 0;
@@ -406,13 +407,13 @@ Error RawInstrProfReader<IntPtrT>::readValueProfilingData(
if (!NumValueKinds)
return success();
- Expected<std::unique_ptr<ValueProfData>> VDataPtrOrErr =
+ ErrorOr<std::unique_ptr<ValueProfData>> VDataPtrOrErr =
ValueProfData::getValueProfData(
ValueDataStart, (const unsigned char *)DataBuffer->getBufferEnd(),
getDataEndianness());
- if (Error E = VDataPtrOrErr.takeError())
- return E;
+ if (VDataPtrOrErr.getError())
+ return VDataPtrOrErr.getError();
// Note that besides deserialization, this also performs the conversion for
// indirect call targets. The function pointers from the raw profile are
@@ -423,27 +424,28 @@ Error RawInstrProfReader<IntPtrT>::readValueProfilingData(
}
template <class IntPtrT>
-Error RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) {
+std::error_code
+RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) {
if (atEnd())
// At this point, ValueDataStart field points to the next header.
- if (Error E = readNextHeader(getNextHeaderPos()))
- return E;
+ if (std::error_code EC = readNextHeader(getNextHeaderPos()))
+ return EC;
// Read name ad set it in Record.
- if (Error E = readName(Record))
- return E;
+ if (std::error_code EC = readName(Record))
+ return EC;
// Read FuncHash and set it in Record.
- if (Error E = readFuncHash(Record))
- return E;
+ if (std::error_code EC = readFuncHash(Record))
+ return EC;
// Read raw counts and set Record.
- if (Error E = readRawCounts(Record))
- return E;
+ if (std::error_code EC = readRawCounts(Record))
+ return EC;
// Read value data and set Record.
- if (Error E = readValueProfilingData(Record))
- return E;
+ if (std::error_code EC = readValueProfilingData(Record))
+ return EC;
// Iterate.
advanceData();
@@ -465,10 +467,10 @@ typedef InstrProfLookupTrait::offset_type offset_type;
bool InstrProfLookupTrait::readValueProfilingData(
const unsigned char *&D, const unsigned char *const End) {
- Expected<std::unique_ptr<ValueProfData>> VDataPtrOrErr =
+ ErrorOr<std::unique_ptr<ValueProfData>> VDataPtrOrErr =
ValueProfData::getValueProfData(D, End, ValueProfDataEndianness);
- if (VDataPtrOrErr.takeError())
+ if (VDataPtrOrErr.getError())
return false;
VDataPtrOrErr.get()->deserializeTo(DataBuffer.back(), nullptr);
@@ -524,31 +526,31 @@ data_type InstrProfLookupTrait::ReadData(StringRef K, const unsigned char *D,
}
template <typename HashTableImpl>
-Error InstrProfReaderIndex<HashTableImpl>::getRecords(
+std::error_code InstrProfReaderIndex<HashTableImpl>::getRecords(
StringRef FuncName, ArrayRef<InstrProfRecord> &Data) {
auto Iter = HashTable->find(FuncName);
if (Iter == HashTable->end())
- return make_error<InstrProfError>(instrprof_error::unknown_function);
+ return instrprof_error::unknown_function;
Data = (*Iter);
if (Data.empty())
- return make_error<InstrProfError>(instrprof_error::malformed);
+ return instrprof_error::malformed;
- return Error::success();
+ return instrprof_error::success;
}
template <typename HashTableImpl>
-Error InstrProfReaderIndex<HashTableImpl>::getRecords(
+std::error_code InstrProfReaderIndex<HashTableImpl>::getRecords(
ArrayRef<InstrProfRecord> &Data) {
if (atEnd())
- return make_error<InstrProfError>(instrprof_error::eof);
+ return instrprof_error::eof;
Data = *RecordIterator;
if (Data.empty())
- return make_error<InstrProfError>(instrprof_error::malformed);
+ return instrprof_error::malformed;
- return Error::success();
+ return instrprof_error::success;
}
template <typename HashTableImpl>
@@ -607,7 +609,7 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version,
}
}
-Error IndexedInstrProfReader::readHeader() {
+std::error_code IndexedInstrProfReader::readHeader() {
const unsigned char *Start =
(const unsigned char *)DataBuffer->getBufferStart();
const unsigned char *Cur = Start;
@@ -659,13 +661,13 @@ InstrProfSymtab &IndexedInstrProfReader::getSymtab() {
return *Symtab.get();
}
-Expected<InstrProfRecord>
+ErrorOr<InstrProfRecord>
IndexedInstrProfReader::getInstrProfRecord(StringRef FuncName,
uint64_t FuncHash) {
ArrayRef<InstrProfRecord> Data;
- Error Err = Index->getRecords(FuncName, Data);
- if (Err)
- return std::move(Err);
+ std::error_code EC = Index->getRecords(FuncName, Data);
+ if (EC != instrprof_error::success)
+ return EC;
// Found it. Look for counters with the right hash.
for (unsigned I = 0, E = Data.size(); I < E; ++I) {
// Check for a match and fill the vector if there is one.
@@ -676,25 +678,26 @@ IndexedInstrProfReader::getInstrProfRecord(StringRef FuncName,
return error(instrprof_error::hash_mismatch);
}
-Error IndexedInstrProfReader::getFunctionCounts(StringRef FuncName,
- uint64_t FuncHash,
- std::vector<uint64_t> &Counts) {
- Expected<InstrProfRecord> Record = getInstrProfRecord(FuncName, FuncHash);
- if (Error E = Record.takeError())
- return error(std::move(E));
+std::error_code
+IndexedInstrProfReader::getFunctionCounts(StringRef FuncName, uint64_t FuncHash,
+ std::vector<uint64_t> &Counts) {
+ ErrorOr<InstrProfRecord> Record = getInstrProfRecord(FuncName, FuncHash);
+ if (std::error_code EC = Record.getError())
+ return EC;
Counts = Record.get().Counts;
return success();
}
-Error IndexedInstrProfReader::readNextRecord(InstrProfRecord &Record) {
+std::error_code IndexedInstrProfReader::readNextRecord(
+ InstrProfRecord &Record) {
static unsigned RecordIndex = 0;
ArrayRef<InstrProfRecord> Data;
- Error E = Index->getRecords(Data);
- if (E)
- return error(std::move(E));
+ std::error_code EC = Index->getRecords(Data);
+ if (EC != instrprof_error::success)
+ return error(EC);
Record = Data[RecordIndex++];
if (RecordIndex >= Data.size()) {
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 9b01dac313b..d6caca2a7a9 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -156,7 +156,8 @@ void InstrProfWriter::setOutputSparse(bool Sparse) {
this->Sparse = Sparse;
}
-Error InstrProfWriter::addRecord(InstrProfRecord &&I, uint64_t Weight) {
+std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I,
+ uint64_t Weight) {
auto &ProfileDataMap = FunctionData[I.Name];
bool NewFunc;
@@ -179,7 +180,7 @@ Error InstrProfWriter::addRecord(InstrProfRecord &&I, uint64_t Weight) {
Dest.sortValueData();
- return Dest.takeError();
+ return Dest.getError();
}
bool InstrProfWriter::shouldEncodeData(const ProfilingData &PD) {
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 11369d6f70d..930001fd684 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -374,9 +374,9 @@ void InstrProfiling::emitNameData() {
return;
std::string CompressedNameStr;
- if (Error E = collectPGOFuncNameStrings(ReferencedNames, CompressedNameStr,
+ if (auto EC = collectPGOFuncNameStrings(ReferencedNames, CompressedNameStr,
DoNameCompression)) {
- llvm::report_fatal_error(toString(std::move(E)), false);
+ llvm::report_fatal_error(EC.message(), false);
}
auto &Ctx = M->getContext();
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 835f75edcd2..379f7c5ebed 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -582,28 +582,23 @@ void PGOUseFunc::setEdgeCount(DirectEdges &Edges, uint64_t Value) {
// Return true if the profile are successfully read, and false on errors.
bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader) {
auto &Ctx = M->getContext();
- Expected<InstrProfRecord> Result =
+ ErrorOr<InstrProfRecord> Result =
PGOReader->getInstrProfRecord(FuncInfo.FuncName, FuncInfo.FunctionHash);
- if (Error E = Result.takeError()) {
- handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
- auto Err = IPE.get();
- bool SkipWarning = false;
- if (Err == instrprof_error::unknown_function) {
- NumOfPGOMissing++;
- SkipWarning = NoPGOWarnMissing;
- } else if (Err == instrprof_error::hash_mismatch ||
- Err == instrprof_error::malformed) {
- NumOfPGOMismatch++;
- SkipWarning = NoPGOWarnMismatch;
- }
-
- if (SkipWarning)
- return;
+ if (std::error_code EC = Result.getError()) {
+ if (EC == instrprof_error::unknown_function) {
+ NumOfPGOMissing++;
+ if (NoPGOWarnMissing)
+ return false;
+ } else if (EC == instrprof_error::hash_mismatch ||
+ EC == llvm::instrprof_error::malformed) {
+ NumOfPGOMismatch++;
+ if (NoPGOWarnMismatch)
+ return false;
+ }
- std::string Msg = IPE.message() + std::string(" ") + F.getName().str();
- Ctx.diagnose(
- DiagnosticInfoPGOProfile(M->getName().data(), Msg, DS_Warning));
- });
+ std::string Msg = EC.message() + std::string(" ") + F.getName().str();
+ Ctx.diagnose(
+ DiagnosticInfoPGOProfile(M->getName().data(), Msg, DS_Warning));
return false;
}
ProfileRecord = std::move(Result.get());
@@ -859,11 +854,9 @@ static bool annotateAllFunctions(
auto &Ctx = M.getContext();
// Read the counter array from file.
auto ReaderOrErr = IndexedInstrProfReader::create(ProfileFileName);
- if (Error E = ReaderOrErr.takeError()) {
- handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) {
- Ctx.diagnose(
- DiagnosticInfoPGOProfile(ProfileFileName.data(), EI.message()));
- });
+ if (std::error_code EC = ReaderOrErr.getError()) {
+ Ctx.diagnose(
+ DiagnosticInfoPGOProfile(ProfileFileName.data(), EC.message()));
return false;
}
OpenPOWER on IntegriCloud