diff options
author | Ellis Hoag <ellis.sparky.hoag@gmail.com> | 2022-01-27 17:40:19 -0800 |
---|---|---|
committer | Ellis Hoag <ellis.sparky.hoag@gmail.com> | 2022-01-28 09:24:26 -0800 |
commit | eea002a9c4712217a0cd0df4529abaaaad6644e2 (patch) | |
tree | a5a1e678c67a8d40d5eb8490933a9cd3f4be19f7 /llvm/lib | |
parent | de0c2d75bf06beebbd0b3084e390629dbb9df2e9 (diff) | |
download | llvm-eea002a9c4712217a0cd0df4529abaaaad6644e2.zip llvm-eea002a9c4712217a0cd0df4529abaaaad6644e2.tar.gz llvm-eea002a9c4712217a0cd0df4529abaaaad6644e2.tar.bz2 |
[InstrProf][NFC] Move function out of InstrProf.h
`createIRLevelProfileFlagVar()` seems to be only used in
`PGOInstrumentation.cpp` so we move it to that file. Then it can also
take advantage of directly using options rather than passing them as
arguments.
Reviewed By: kyulee, phosek
Differential Revision: https://reviews.llvm.org/D118097
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 30 | ||||
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 38 |
2 files changed, 30 insertions, 38 deletions
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index aba9bd7..07d4673 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -1181,36 +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, - bool PGOFunctionEntryCoverage) { - 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; - if (PGOFunctionEntryCoverage) - ProfileVersion |= - VARIANT_MASK_BYTE_COVERAGE | VARIANT_MASK_FUNCTION_ENTRY_ONLY; - 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/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 2c373cf..0902a94 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -342,6 +342,33 @@ static const char *ValueProfKindDescr[] = { #include "llvm/ProfileData/InstrProfData.inc" }; +// 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. +static GlobalVariable *createIRLevelProfileFlagVar(Module &M, bool IsCS) { + 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 (PGOInstrumentEntry) + ProfileVersion |= VARIANT_MASK_INSTR_ENTRY; + if (DebugInfoCorrelate) + ProfileVersion |= VARIANT_MASK_DBG_CORRELATE; + if (PGOFunctionEntryCoverage) + ProfileVersion |= + VARIANT_MASK_BYTE_COVERAGE | VARIANT_MASK_FUNCTION_ENTRY_ONLY; + 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; +} + namespace { /// The select instruction visitor plays three roles specified @@ -474,9 +501,7 @@ private: createProfileFileNameVar(M, InstrProfileOutput); // The variable in a comdat may be discarded by LTO. Ensure the // declaration will be retained. - appendToCompilerUsed(M, createIRLevelProfileFlagVar( - M, /*IsCS=*/true, PGOInstrumentEntry, - DebugInfoCorrelate, PGOFunctionEntryCoverage)); + appendToCompilerUsed(M, createIRLevelProfileFlagVar(M, /*IsCS=*/true)); return false; } std::string InstrProfileOutput; @@ -1646,8 +1671,7 @@ static bool InstrumentAllFunctions( // For the context-sensitve instrumentation, we should have a separated pass // (before LTO/ThinLTO linking) to create these variables. if (!IsCS) - createIRLevelProfileFlagVar(M, /*IsCS=*/false, PGOInstrumentEntry, - DebugInfoCorrelate, PGOFunctionEntryCoverage); + createIRLevelProfileFlagVar(M, /*IsCS=*/false); std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers; collectComdatMembers(M, ComdatMembers); @@ -1669,9 +1693,7 @@ PGOInstrumentationGenCreateVar::run(Module &M, ModuleAnalysisManager &AM) { createProfileFileNameVar(M, CSInstrName); // The variable in a comdat may be discarded by LTO. Ensure the declaration // will be retained. - appendToCompilerUsed(M, createIRLevelProfileFlagVar( - M, /*IsCS=*/true, PGOInstrumentEntry, - DebugInfoCorrelate, PGOFunctionEntryCoverage)); + appendToCompilerUsed(M, createIRLevelProfileFlagVar(M, /*IsCS=*/true)); return PreservedAnalyses::all(); } |