diff options
author | Justin Bogner <mail@justinbogner.com> | 2015-05-07 00:31:58 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2015-05-07 00:31:58 +0000 |
commit | 5a5c381ba9d10366070804633f1c007f415890bb (patch) | |
tree | b498e1a5eb91a953d69befd4f56771b4146f8ca0 /llvm/lib/ProfileData/CoverageMappingReader.cpp | |
parent | 7a738dd94c3209e3fdfdb768d8cf977cef5d9547 (diff) | |
download | bcm5719-llvm-5a5c381ba9d10366070804633f1c007f415890bb.tar.gz bcm5719-llvm-5a5c381ba9d10366070804633f1c007f415890bb.zip |
InstrProf: Simplify looking up sections for coverage data
llvm-svn: 236685
Diffstat (limited to 'llvm/lib/ProfileData/CoverageMappingReader.cpp')
-rw-r--r-- | llvm/lib/ProfileData/CoverageMappingReader.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/llvm/lib/ProfileData/CoverageMappingReader.cpp b/llvm/lib/ProfileData/CoverageMappingReader.cpp index eb77f775ca6..cf6cd58f953 100644 --- a/llvm/lib/ProfileData/CoverageMappingReader.cpp +++ b/llvm/lib/ProfileData/CoverageMappingReader.cpp @@ -427,6 +427,17 @@ static std::error_code loadTestingFormat(StringRef Data, return std::error_code(); } +static ErrorOr<SectionRef> lookupSection(ObjectFile &OF, StringRef Name) { + StringRef FoundName; + for (const auto &Section : OF.sections()) { + if (auto EC = Section.getName(FoundName)) + return EC; + if (FoundName == Name) + return Section; + } + return coveragemap_error::no_data_found; +} + static std::error_code loadBinaryFormat(MemoryBufferRef ObjectBuffer, SectionData &ProfileNames, StringRef &CoverageMapping, @@ -461,27 +472,17 @@ static std::error_code loadBinaryFormat(MemoryBufferRef ObjectBuffer, : support::endianness::big; // Look for the sections that we are interested in. - int FoundSectionCount = 0; - SectionRef NamesSection, CoverageSection; - for (const auto &Section : OF->sections()) { - StringRef Name; - if (auto Err = Section.getName(Name)) - return Err; - if (Name == "__llvm_prf_names") { - NamesSection = Section; - } else if (Name == "__llvm_covmap") { - CoverageSection = Section; - } else - continue; - ++FoundSectionCount; - } - if (FoundSectionCount != 2) - return coveragemap_error::no_data_found; + auto NamesSection = lookupSection(*OF, "__llvm_prf_names"); + if (auto EC = NamesSection.getError()) + return EC; + auto CoverageSection = lookupSection(*OF, "__llvm_covmap"); + if (auto EC = CoverageSection.getError()) + return EC; // Get the contents of the given sections. - if (std::error_code EC = CoverageSection.getContents(CoverageMapping)) + if (std::error_code EC = CoverageSection->getContents(CoverageMapping)) return EC; - if (std::error_code EC = ProfileNames.load(NamesSection)) + if (std::error_code EC = ProfileNames.load(*NamesSection)) return EC; return std::error_code(); |