diff options
author | Vedant Kumar <vsk@apple.com> | 2017-04-15 00:09:57 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-04-15 00:09:57 +0000 |
commit | 1a6a2b642bd61910424cb7244f547c02460f18db (patch) | |
tree | 8dceb66e86d3a0cf9ed57913af96d5ba602cb695 /llvm/lib/ProfileData | |
parent | 03df14c6dd2ae36b04d0a085ae9fa69aad8193ab (diff) | |
download | bcm5719-llvm-1a6a2b642bd61910424cb7244f547c02460f18db.tar.gz bcm5719-llvm-1a6a2b642bd61910424cb7244f547c02460f18db.zip |
[ProfileData] Unify getInstrProf*SectionName helpers
This is a version of D32090 that unifies all of the
`getInstrProf*SectionName` helper functions. (Note: the build failures
which D32090 would have addressed were fixed with r300352.)
We should unify these helper functions because they are hard to use in
their current form. E.g we recently introduced more helpers to fix
section naming for COFF files. This scheme doesn't totally succeed at
hiding low-level details about section naming, so we should switch to an
API that is easier to maintain.
This is not an NFC commit because it fixes llvm-cov's testing support
for COFF files (this falls out of the API change naturally). This is an
area where we lack tests -- I will see about adding one as a follow up.
Testing: check-clang, check-profile, check-llvm.
Differential Revision: https://reviews.llvm.org/D32097
llvm-svn: 300381
Diffstat (limited to 'llvm/lib/ProfileData')
-rw-r--r-- | llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 90 |
2 files changed, 21 insertions, 77 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp index dab602afd25..a34f359cd54 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -649,13 +649,15 @@ static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer, : support::endianness::big; // Look for the sections that we are interested in. - bool IsCoff = (dyn_cast<COFFObjectFile>(OF.get()) != nullptr); + auto ObjFormat = OF->getTripleObjectFormat(); auto NamesSection = - lookupSection(*OF, getInstrProfNameSectionNameInObject(IsCoff)); + lookupSection(*OF, getInstrProfSectionName(IPSK_name, ObjFormat, + /*AddSegmentInfo=*/false)); if (auto E = NamesSection.takeError()) return E; auto CoverageSection = - lookupSection(*OF, getInstrProfCoverageSectionNameInObject(IsCoff)); + lookupSection(*OF, getInstrProfSectionName(IPSK_covmap, ObjFormat, + /*AddSegmentInfo=*/false)); if (auto E = CoverageSection.takeError()) return E; diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index a8f5b7f3d0e..64a65ccc11a 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -138,103 +138,45 @@ const std::error_category &llvm::instrprof_category() { namespace { -enum InstrProfSectKind { -#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \ - Prefix) \ - Kind, -#include "llvm/ProfileData/InstrProfData.inc" -}; - -const char *InstrProfSectName[] = { -#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \ - Prefix) \ - SectName, -#include "llvm/ProfileData/InstrProfData.inc" -}; - const char *InstrProfSectNameCommon[] = { -#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \ - Prefix) \ +#define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \ SectNameCommon, #include "llvm/ProfileData/InstrProfData.inc" }; const char *InstrProfSectNameCoff[] = { -#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \ - Prefix) \ +#define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \ SectNameCoff, #include "llvm/ProfileData/InstrProfData.inc" }; const char *InstrProfSectNamePrefix[] = { -#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \ - Prefix) \ +#define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \ Prefix, #include "llvm/ProfileData/InstrProfData.inc" }; -std::string getInstrProfSectionName(bool isCoff, InstrProfSectKind Kind) { - return isCoff ? InstrProfSectNameCoff[Kind] : InstrProfSectNameCommon[Kind]; -} - -std::string getInstrProfSectionName(const Module *M, InstrProfSectKind Kind) { - if (!M) - return InstrProfSectName[Kind]; - - bool AddSegment = Triple(M->getTargetTriple()).isOSBinFormatMachO(); - std::string SectName; - if (Triple(M->getTargetTriple()).isOSBinFormatCOFF()) - SectName = InstrProfSectNameCoff[Kind]; - else - SectName = InstrProfSectNameCommon[Kind]; - - if (AddSegment) { - SectName = InstrProfSectNamePrefix[Kind] + SectName; - if (Kind == IPSK_data) { - SectName += ",regular,live_support"; - } - } - return SectName; -} - } // namespace namespace llvm { -std::string getInstrProfCountersSectionName(const Module *M) { - return getInstrProfSectionName(M, IPSK_cnts); -} - -std::string getInstrProfNameSectionName(const Module *M) { - return getInstrProfSectionName(M, IPSK_name); -} - -std::string getInstrProfNameSectionNameInObject(bool isCoff) { - return getInstrProfSectionName(isCoff, IPSK_name); -} - -std::string getInstrProfDataSectionName(const Module *M) { - return getInstrProfSectionName(M, IPSK_data); -} - -std::string getInstrProfDataSectionNameInObject(bool isCoff) { - return getInstrProfSectionName(isCoff, IPSK_data); -} +std::string getInstrProfSectionName(InstrProfSectKind IPSK, + Triple::ObjectFormatType OF, + bool AddSegmentInfo) { + std::string SectName; -std::string getInstrProfValuesSectionName(const Module *M) { - return getInstrProfSectionName(M, IPSK_vals); -} + if (OF == Triple::MachO && AddSegmentInfo) + SectName = InstrProfSectNamePrefix[IPSK]; -std::string getInstrProfVNodesSectionName(const Module *M) { - return getInstrProfSectionName(M, IPSK_vnodes); -} + if (OF == Triple::COFF) + SectName += InstrProfSectNameCoff[IPSK]; + else + SectName += InstrProfSectNameCommon[IPSK]; -std::string getInstrProfCoverageSectionName(const Module *M) { - return getInstrProfSectionName(M, IPSK_covmap); -} + if (OF == Triple::MachO && IPSK == IPSK_data && AddSegmentInfo) + SectName += ",regular,live_support"; -std::string getInstrProfCoverageSectionNameInObject(bool isCoff) { - return getInstrProfSectionName(isCoff, IPSK_covmap); + return SectName; } void SoftInstrProfErrors::addError(instrprof_error IE) { |