summaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/ProfileData')
-rw-r--r--llvm/lib/ProfileData/InstrProf.cpp26
-rw-r--r--llvm/lib/ProfileData/InstrProfReader.cpp62
-rw-r--r--llvm/lib/ProfileData/InstrProfWriter.cpp31
3 files changed, 64 insertions, 55 deletions
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 051655e1fed6..07d467305ae5 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -1181,32 +1181,6 @@ bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken) {
return true;
}
-// Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime
-// aware this is an ir_level profile so it can set the version flag.
-GlobalVariable *createIRLevelProfileFlagVar(Module &M, bool IsCS,
- bool InstrEntryBBEnabled,
- bool DebugInfoCorrelate) {
- const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
- Type *IntTy64 = Type::getInt64Ty(M.getContext());
- uint64_t ProfileVersion = (INSTR_PROF_RAW_VERSION | VARIANT_MASK_IR_PROF);
- if (IsCS)
- ProfileVersion |= VARIANT_MASK_CSIR_PROF;
- if (InstrEntryBBEnabled)
- ProfileVersion |= VARIANT_MASK_INSTR_ENTRY;
- if (DebugInfoCorrelate)
- ProfileVersion |= VARIANT_MASK_DBG_CORRELATE;
- auto IRLevelVersionVariable = new GlobalVariable(
- M, IntTy64, true, GlobalValue::WeakAnyLinkage,
- Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
- IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility);
- Triple TT(M.getTargetTriple());
- if (TT.supportsCOMDAT()) {
- IRLevelVersionVariable->setLinkage(GlobalValue::ExternalLinkage);
- IRLevelVersionVariable->setComdat(M.getOrInsertComdat(VarName));
- }
- return IRLevelVersionVariable;
-}
-
// Create the variable for the profile file name.
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput) {
if (InstrProfileOutput.empty())
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 861ff61df510..138b1532d778 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 =
@@ -154,30 +176,24 @@ bool TextInstrProfReader::hasFormat(const MemoryBuffer &Buffer) {
// with a leading ':' will be reported an error format.
Error TextInstrProfReader::readHeader() {
Symtab.reset(new InstrProfSymtab());
- bool IsIRInstr = false;
- bool IsEntryFirst = false;
- bool IsCS = false;
while (Line->startswith(":")) {
StringRef Str = Line->substr(1);
if (Str.equals_insensitive("ir"))
- IsIRInstr = true;
+ ProfileKind |= InstrProfKind::IR;
else if (Str.equals_insensitive("fe"))
- IsIRInstr = false;
+ ProfileKind |= InstrProfKind::FE;
else if (Str.equals_insensitive("csir")) {
- IsIRInstr = true;
- IsCS = true;
+ ProfileKind |= InstrProfKind::IR;
+ ProfileKind |= InstrProfKind::CS;
} else if (Str.equals_insensitive("entry_first"))
- IsEntryFirst = true;
+ ProfileKind |= InstrProfKind::BB;
else if (Str.equals_insensitive("not_entry_first"))
- IsEntryFirst = false;
+ ProfileKind &= ~InstrProfKind::BB;
else
return error(instrprof_error::bad_header);
++Line;
}
- IsIRLevelProfile = IsIRInstr;
- InstrEntryBBEnabled = IsEntryFirst;
- HasCSIRLevelProfile = IsCS;
return success();
}
@@ -304,6 +320,11 @@ Error TextInstrProfReader::readNextRecord(NamedInstrProfRecord &Record) {
}
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))
return false;
@@ -485,9 +506,15 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(
Record.Counts.clear();
Record.Counts.reserve(NumCounters);
for (uint32_t I = 0; I < NumCounters; I++) {
- const auto *CounterValue = reinterpret_cast<const uint64_t *>(
- CountersStart + CounterBaseOffset + I * getCounterTypeSize());
- Record.Counts.push_back(swap(*CounterValue));
+ const char *Ptr =
+ CountersStart + CounterBaseOffset + I * getCounterTypeSize();
+ if (hasSingleByteCoverage()) {
+ // A value of zero signifies the block is covered.
+ Record.Counts.push_back(*Ptr == 0 ? 1 : 0);
+ } else {
+ const auto *CounterValue = reinterpret_cast<const uint64_t *>(Ptr);
+ Record.Counts.push_back(swap(*CounterValue));
+ }
}
return success();
@@ -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 {
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 6628eea80640..8ded1c0426e5 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -166,9 +166,8 @@ public:
} // end namespace llvm
-InstrProfWriter::InstrProfWriter(bool Sparse, bool InstrEntryBBEnabled)
- : Sparse(Sparse), InstrEntryBBEnabled(InstrEntryBBEnabled),
- InfoObj(new InstrProfRecordWriterTrait()) {}
+InstrProfWriter::InstrProfWriter(bool Sparse)
+ : Sparse(Sparse), InfoObj(new InstrProfRecordWriterTrait()) {}
InstrProfWriter::~InstrProfWriter() { delete InfoObj; }
@@ -303,14 +302,16 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
IndexedInstrProf::Header Header;
Header.Magic = IndexedInstrProf::Magic;
Header.Version = IndexedInstrProf::ProfVersion::CurrentVersion;
- if (ProfileKind == PF_IRLevel)
- Header.Version |= VARIANT_MASK_IR_PROF;
- if (ProfileKind == PF_IRLevelWithCS) {
+ if (static_cast<bool>(ProfileKind & InstrProfKind::IR))
Header.Version |= VARIANT_MASK_IR_PROF;
+ if (static_cast<bool>(ProfileKind & InstrProfKind::CS))
Header.Version |= VARIANT_MASK_CSIR_PROF;
- }
- if (InstrEntryBBEnabled)
+ if (static_cast<bool>(ProfileKind & InstrProfKind::BB))
Header.Version |= VARIANT_MASK_INSTR_ENTRY;
+ if (static_cast<bool>(ProfileKind & InstrProfKind::SingleByteCoverage))
+ Header.Version |= VARIANT_MASK_BYTE_COVERAGE;
+ if (static_cast<bool>(ProfileKind & InstrProfKind::FunctionEntryOnly))
+ Header.Version |= VARIANT_MASK_FUNCTION_ENTRY_ONLY;
Header.Unused = 0;
Header.HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
@@ -337,7 +338,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
OS.write(0);
uint64_t CSSummaryOffset = 0;
uint64_t CSSummarySize = 0;
- if (ProfileKind == PF_IRLevelWithCS) {
+ if (static_cast<bool>(ProfileKind & InstrProfKind::CS)) {
CSSummaryOffset = OS.tell();
CSSummarySize = SummarySize / sizeof(uint64_t);
for (unsigned I = 0; I < CSSummarySize; I++)
@@ -358,7 +359,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
// For Context Sensitive summary.
std::unique_ptr<IndexedInstrProf::Summary> TheCSSummary = nullptr;
- if (ProfileKind == PF_IRLevelWithCS) {
+ if (static_cast<bool>(ProfileKind & InstrProfKind::CS)) {
TheCSSummary = IndexedInstrProf::allocSummary(SummarySize);
std::unique_ptr<ProfileSummary> CSPS = CSISB.getSummary();
setSummary(TheCSSummary.get(), *CSPS);
@@ -470,11 +471,13 @@ void InstrProfWriter::writeRecordInText(StringRef Name, uint64_t Hash,
}
Error InstrProfWriter::writeText(raw_fd_ostream &OS) {
- if (ProfileKind == PF_IRLevel)
- OS << "# IR level Instrumentation Flag\n:ir\n";
- else if (ProfileKind == PF_IRLevelWithCS)
+ // Check CS first since it implies an IR level profile.
+ if (static_cast<bool>(ProfileKind & InstrProfKind::CS))
OS << "# CSIR level Instrumentation Flag\n:csir\n";
- if (InstrEntryBBEnabled)
+ else if (static_cast<bool>(ProfileKind & InstrProfKind::IR))
+ OS << "# IR level Instrumentation Flag\n:ir\n";
+
+ if (static_cast<bool>(ProfileKind & InstrProfKind::BB))
OS << "# Always instrument the function entry block\n:entry_first\n";
InstrProfSymtab Symtab;