[llvm] r236685 - InstrProf: Simplify looking up sections for coverage data
Justin Bogner
mail at justinbogner.com
Wed May 6 17:31:58 PDT 2015
Author: bogner
Date: Wed May 6 19:31:58 2015
New Revision: 236685
URL: http://llvm.org/viewvc/llvm-project?rev=236685&view=rev
Log:
InstrProf: Simplify looking up sections for coverage data
Modified:
llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp
Modified: llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp?rev=236685&r1=236684&r2=236685&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp Wed May 6 19:31:58 2015
@@ -427,6 +427,17 @@ static std::error_code loadTestingFormat
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(
: 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();
More information about the llvm-commits
mailing list