diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h --- a/llvm/include/llvm/ProfileData/InstrProfReader.h +++ b/llvm/include/llvm/ProfileData/InstrProfReader.h @@ -310,25 +310,7 @@ } /// Returns a BitsetEnum describing the attributes of the raw instr profile. - InstrProfKind getProfileKind() const override { - InstrProfKind ProfileKind = InstrProfKind::Unknown; - if (Version & VARIANT_MASK_IR_PROF) { - ProfileKind |= InstrProfKind::IR; - } - if (Version & VARIANT_MASK_CSIR_PROF) { - ProfileKind |= InstrProfKind::CS; - } - if (Version & VARIANT_MASK_INSTR_ENTRY) { - ProfileKind |= InstrProfKind::BB; - } - if (Version & VARIANT_MASK_BYTE_COVERAGE) { - ProfileKind |= InstrProfKind::SingleByteCoverage; - } - if (Version & VARIANT_MASK_FUNCTION_ENTRY_ONLY) { - ProfileKind |= InstrProfKind::FunctionEntryOnly; - } - return ProfileKind; - } + InstrProfKind getProfileKind() const override; InstrProfSymtab &getSymtab() override { assert(Symtab.get()); @@ -532,25 +514,7 @@ return (FormatVersion & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0; } - InstrProfKind getProfileKind() const override { - InstrProfKind ProfileKind = InstrProfKind::Unknown; - if (FormatVersion & VARIANT_MASK_IR_PROF) { - ProfileKind |= InstrProfKind::IR; - } - if (FormatVersion & VARIANT_MASK_CSIR_PROF) { - ProfileKind |= InstrProfKind::CS; - } - if (FormatVersion & VARIANT_MASK_INSTR_ENTRY) { - ProfileKind |= InstrProfKind::BB; - } - if (FormatVersion & VARIANT_MASK_BYTE_COVERAGE) { - ProfileKind |= InstrProfKind::SingleByteCoverage; - } - if (FormatVersion & VARIANT_MASK_FUNCTION_ENTRY_ONLY) { - ProfileKind |= InstrProfKind::FunctionEntryOnly; - } - return ProfileKind; - } + InstrProfKind getProfileKind() const override; Error populateSymtab(InstrProfSymtab &Symtab) override { return Symtab.create(HashTable->keys()); diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp --- a/llvm/lib/ProfileData/InstrProfReader.cpp +++ b/llvm/lib/ProfileData/InstrProfReader.cpp @@ -38,6 +38,28 @@ using namespace llvm; +// Extracts the variant information from the top 8 bits in the version and +// returns an enum specifying the variants present. +static InstrProfKind getProfileKindFromVersion(uint64_t Version) { + InstrProfKind ProfileKind = InstrProfKind::Unknown; + if (Version & VARIANT_MASK_IR_PROF) { + ProfileKind |= InstrProfKind::IR; + } + if (Version & VARIANT_MASK_CSIR_PROF) { + ProfileKind |= InstrProfKind::CS; + } + if (Version & VARIANT_MASK_INSTR_ENTRY) { + ProfileKind |= InstrProfKind::BB; + } + if (Version & VARIANT_MASK_BYTE_COVERAGE) { + ProfileKind |= InstrProfKind::SingleByteCoverage; + } + if (Version & VARIANT_MASK_FUNCTION_ENTRY_ONLY) { + ProfileKind |= InstrProfKind::FunctionEntryOnly; + } + return ProfileKind; +} + static Expected> setupMemoryBuffer(const Twine &Path) { ErrorOr> BufferOrErr = @@ -297,6 +319,11 @@ return success(); } +template +InstrProfKind RawInstrProfReader::getProfileKind() const { + return getProfileKindFromVersion(Version); +} + template bool RawInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) { if (DataBuffer.getBufferSize() < sizeof(uint64_t)) @@ -718,6 +745,11 @@ RecordIterator = HashTable->data_begin(); } +template +InstrProfKind InstrProfReaderIndex::getProfileKind() const { + return getProfileKindFromVersion(FormatVersion); +} + namespace { /// A remapper that does not apply any remappings. class InstrProfReaderNullRemapper : public InstrProfReaderRemapper {