From b6817999384e5ae125eb477c003c040d51770c96 Mon Sep 17 00:00:00 2001 From: Snehasish Kumar Date: Thu, 17 Feb 2022 14:44:49 -0800 Subject: [PATCH] [instrprof] Rename the profile kind types to be more descriptive. Based on the discussion in D115393, I've updated the names to be more descriptive. Reviewed By: ellis, MaskRay Differential Revision: https://reviews.llvm.org/D120092 --- llvm/include/llvm/ProfileData/InstrProf.h | 21 ++++++++++++++------- llvm/include/llvm/ProfileData/InstrProfReader.h | 7 ++++--- llvm/include/llvm/ProfileData/InstrProfWriter.h | 8 +++++--- llvm/lib/ProfileData/InstrProfReader.cpp | 18 +++++++++--------- llvm/lib/ProfileData/InstrProfWriter.cpp | 18 ++++++++++-------- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h index 9f7a671..401d278 100644 --- a/llvm/include/llvm/ProfileData/InstrProf.h +++ b/llvm/include/llvm/ProfileData/InstrProf.h @@ -281,13 +281,20 @@ bool needsComdatForCounter(const Function &F, const Module &M); /// An enum describing the attributes of an instrumented profile. enum class InstrProfKind { Unknown = 0x0, - FE = 0x1, // A frontend clang profile, incompatible with other attrs. - IR = 0x2, // An IR-level profile (default when -fprofile-generate is used). - BB = 0x4, // A profile with entry basic block instrumentation. - CS = 0x8, // A context sensitive IR-level profile. - SingleByteCoverage = 0x10, // Use single byte probes for coverage. - FunctionEntryOnly = 0x20, // Only instrument the function entry basic block. - MemProf = 0x40, // A memory profile collected using -fprofile=memory. + // A frontend clang profile, incompatible with other attrs. + FrontendInstrumentation = 0x1, + // An IR-level profile (default when -fprofile-generate is used). + IRInstrumentation = 0x2, + // A profile with entry basic block instrumentation. + FunctionEntryInstrumentation = 0x4, + // A context sensitive IR-level profile. + ContextSensitive = 0x8, + // Use single byte probes for coverage. + SingleByteCoverage = 0x10, + // Only instrument the function entry basic block. + FunctionEntryOnly = 0x20, + // A memory profile collected using -fprofile=memory. + MemProf = 0x40, LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/MemProf) }; diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h index 7a18d5a..7a01ef5 100644 --- a/llvm/include/llvm/ProfileData/InstrProfReader.h +++ b/llvm/include/llvm/ProfileData/InstrProfReader.h @@ -213,15 +213,16 @@ public: static bool hasFormat(const MemoryBuffer &Buffer); bool isIRLevelProfile() const override { - return static_cast(ProfileKind & InstrProfKind::IR); + return static_cast(ProfileKind & InstrProfKind::IRInstrumentation); } bool hasCSIRLevelProfile() const override { - return static_cast(ProfileKind & InstrProfKind::CS); + return static_cast(ProfileKind & InstrProfKind::ContextSensitive); } bool instrEntryBBEnabled() const override { - return static_cast(ProfileKind & InstrProfKind::BB); + return static_cast(ProfileKind & + InstrProfKind::FunctionEntryInstrumentation); } bool hasSingleByteCoverage() const override { diff --git a/llvm/include/llvm/ProfileData/InstrProfWriter.h b/llvm/include/llvm/ProfileData/InstrProfWriter.h index bb180ac..fb60826 100644 --- a/llvm/include/llvm/ProfileData/InstrProfWriter.h +++ b/llvm/include/llvm/ProfileData/InstrProfWriter.h @@ -106,11 +106,13 @@ public: // Check if the profiles are in-compatible. Clang frontend profiles can't be // merged with other profile types. - if (static_cast((ProfileKind & InstrProfKind::FE) ^ - (Other & InstrProfKind::FE))) { + if (static_cast( + (ProfileKind & InstrProfKind::FrontendInstrumentation) ^ + (Other & InstrProfKind::FrontendInstrumentation))) { return make_error(instrprof_error::unsupported_version); } - if (testIncompatible(InstrProfKind::FunctionEntryOnly, InstrProfKind::BB)) { + if (testIncompatible(InstrProfKind::FunctionEntryOnly, + InstrProfKind::FunctionEntryInstrumentation)) { return make_error( instrprof_error::unsupported_version, "cannot merge FunctionEntryOnly profiles and BB profiles together"); diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp index f79169c..67f6158 100644 --- a/llvm/lib/ProfileData/InstrProfReader.cpp +++ b/llvm/lib/ProfileData/InstrProfReader.cpp @@ -45,13 +45,13 @@ using namespace llvm; static InstrProfKind getProfileKindFromVersion(uint64_t Version) { InstrProfKind ProfileKind = InstrProfKind::Unknown; if (Version & VARIANT_MASK_IR_PROF) { - ProfileKind |= InstrProfKind::IR; + ProfileKind |= InstrProfKind::IRInstrumentation; } if (Version & VARIANT_MASK_CSIR_PROF) { - ProfileKind |= InstrProfKind::CS; + ProfileKind |= InstrProfKind::ContextSensitive; } if (Version & VARIANT_MASK_INSTR_ENTRY) { - ProfileKind |= InstrProfKind::BB; + ProfileKind |= InstrProfKind::FunctionEntryInstrumentation; } if (Version & VARIANT_MASK_BYTE_COVERAGE) { ProfileKind |= InstrProfKind::SingleByteCoverage; @@ -177,16 +177,16 @@ Error TextInstrProfReader::readHeader() { while (Line->startswith(":")) { StringRef Str = Line->substr(1); if (Str.equals_insensitive("ir")) - ProfileKind |= InstrProfKind::IR; + ProfileKind |= InstrProfKind::IRInstrumentation; else if (Str.equals_insensitive("fe")) - ProfileKind |= InstrProfKind::FE; + ProfileKind |= InstrProfKind::FrontendInstrumentation; else if (Str.equals_insensitive("csir")) { - ProfileKind |= InstrProfKind::IR; - ProfileKind |= InstrProfKind::CS; + ProfileKind |= InstrProfKind::IRInstrumentation; + ProfileKind |= InstrProfKind::ContextSensitive; } else if (Str.equals_insensitive("entry_first")) - ProfileKind |= InstrProfKind::BB; + ProfileKind |= InstrProfKind::FunctionEntryInstrumentation; else if (Str.equals_insensitive("not_entry_first")) - ProfileKind &= ~InstrProfKind::BB; + ProfileKind &= ~InstrProfKind::FunctionEntryInstrumentation; else return error(instrprof_error::bad_header); ++Line; diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index 4c974f4..2771b3a 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -336,11 +336,12 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) { IndexedInstrProf::Header Header; Header.Magic = IndexedInstrProf::Magic; Header.Version = IndexedInstrProf::ProfVersion::CurrentVersion; - if (static_cast(ProfileKind & InstrProfKind::IR)) + if (static_cast(ProfileKind & InstrProfKind::IRInstrumentation)) Header.Version |= VARIANT_MASK_IR_PROF; - if (static_cast(ProfileKind & InstrProfKind::CS)) + if (static_cast(ProfileKind & InstrProfKind::ContextSensitive)) Header.Version |= VARIANT_MASK_CSIR_PROF; - if (static_cast(ProfileKind & InstrProfKind::BB)) + if (static_cast(ProfileKind & + InstrProfKind::FunctionEntryInstrumentation)) Header.Version |= VARIANT_MASK_INSTR_ENTRY; if (static_cast(ProfileKind & InstrProfKind::SingleByteCoverage)) Header.Version |= VARIANT_MASK_BYTE_COVERAGE; @@ -381,7 +382,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) { OS.write(0); uint64_t CSSummaryOffset = 0; uint64_t CSSummarySize = 0; - if (static_cast(ProfileKind & InstrProfKind::CS)) { + if (static_cast(ProfileKind & InstrProfKind::ContextSensitive)) { CSSummaryOffset = OS.tell(); CSSummarySize = SummarySize / sizeof(uint64_t); for (unsigned I = 0; I < CSSummarySize; I++) @@ -438,7 +439,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) { // For Context Sensitive summary. std::unique_ptr TheCSSummary = nullptr; - if (static_cast(ProfileKind & InstrProfKind::CS)) { + if (static_cast(ProfileKind & InstrProfKind::ContextSensitive)) { TheCSSummary = IndexedInstrProf::allocSummary(SummarySize); std::unique_ptr CSPS = CSISB.getSummary(); setSummary(TheCSSummary.get(), *CSPS); @@ -553,12 +554,13 @@ void InstrProfWriter::writeRecordInText(StringRef Name, uint64_t Hash, Error InstrProfWriter::writeText(raw_fd_ostream &OS) { // Check CS first since it implies an IR level profile. - if (static_cast(ProfileKind & InstrProfKind::CS)) + if (static_cast(ProfileKind & InstrProfKind::ContextSensitive)) OS << "# CSIR level Instrumentation Flag\n:csir\n"; - else if (static_cast(ProfileKind & InstrProfKind::IR)) + else if (static_cast(ProfileKind & InstrProfKind::IRInstrumentation)) OS << "# IR level Instrumentation Flag\n:ir\n"; - if (static_cast(ProfileKind & InstrProfKind::BB)) + if (static_cast(ProfileKind & + InstrProfKind::FunctionEntryInstrumentation)) OS << "# Always instrument the function entry block\n:entry_first\n"; InstrProfSymtab Symtab; -- 2.7.4