[llvm] 186dcd4 - [instrprof][NFC] Refactor out the common logic for getProfileKind.
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 31 15:15:55 PST 2022
Author: Snehasish Kumar
Date: 2022-01-31T15:04:42-08:00
New Revision: 186dcd4aab77f45552252a3b17cd16a6d8b32233
URL: https://github.com/llvm/llvm-project/commit/186dcd4aab77f45552252a3b17cd16a6d8b32233
DIFF: https://github.com/llvm/llvm-project/commit/186dcd4aab77f45552252a3b17cd16a6d8b32233.diff
LOG: [instrprof][NFC] Refactor out the common logic for getProfileKind.
The logic for getProfileKind for RawInstrProfReader and
InstrProfReaderIndex is similar. To avoid duplication, move the logic
from the header to InstrProfReader.cpp and introduce a static method
which implements the common code.
Differential Revision: https://reviews.llvm.org/D118656
Added:
Modified:
llvm/include/llvm/ProfileData/InstrProfReader.h
llvm/lib/ProfileData/InstrProfReader.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h
index cfaec31216bc7..e9dd19a697920 100644
--- a/llvm/include/llvm/ProfileData/InstrProfReader.h
+++ b/llvm/include/llvm/ProfileData/InstrProfReader.h
@@ -310,25 +310,7 @@ class RawInstrProfReader : public InstrProfReader {
}
/// 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 @@ class InstrProfReaderIndex : public InstrProfReaderIndexBase {
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
index d222f32033876..138b1532d778b 100644
--- 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<std::unique_ptr<MemoryBuffer>>
setupMemoryBuffer(const Twine &Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
@@ -297,6 +319,11 @@ Error TextInstrProfReader::readNextRecord(NamedInstrProfRecord &Record) {
return success();
}
+template <class IntPtrT>
+InstrProfKind RawInstrProfReader<IntPtrT>::getProfileKind() const {
+ return getProfileKindFromVersion(Version);
+}
+
template <class IntPtrT>
bool RawInstrProfReader<IntPtrT>::hasFormat(const MemoryBuffer &DataBuffer) {
if (DataBuffer.getBufferSize() < sizeof(uint64_t))
@@ -718,6 +745,11 @@ InstrProfReaderIndex<HashTableImpl>::InstrProfReaderIndex(
RecordIterator = HashTable->data_begin();
}
+template <typename HashTableImpl>
+InstrProfKind InstrProfReaderIndex<HashTableImpl>::getProfileKind() const {
+ return getProfileKindFromVersion(FormatVersion);
+}
+
namespace {
/// A remapper that does not apply any remappings.
class InstrProfReaderNullRemapper : public InstrProfReaderRemapper {
More information about the llvm-commits
mailing list