Skip to content

Commit eea002a

Browse files
committed
[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
1 parent de0c2d7 commit eea002a

File tree

3 files changed

+30
-45
lines changed

3 files changed

+30
-45
lines changed

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,13 +1168,6 @@ struct Header {
11681168
void getMemOPSizeRangeFromOption(StringRef Str, int64_t &RangeStart,
11691169
int64_t &RangeLast);
11701170

1171-
// Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime
1172-
// aware this is an ir_level profile so it can set the version flag.
1173-
GlobalVariable *createIRLevelProfileFlagVar(Module &M, bool IsCS,
1174-
bool InstrEntryBBEnabled,
1175-
bool DebugInfoCorrelate,
1176-
bool PGOFunctionEntryCoverage);
1177-
11781171
// Create the variable for the profile file name.
11791172
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput);
11801173

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,36 +1181,6 @@ bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken) {
11811181
return true;
11821182
}
11831183

1184-
// Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime
1185-
// aware this is an ir_level profile so it can set the version flag.
1186-
GlobalVariable *createIRLevelProfileFlagVar(Module &M, bool IsCS,
1187-
bool InstrEntryBBEnabled,
1188-
bool DebugInfoCorrelate,
1189-
bool PGOFunctionEntryCoverage) {
1190-
const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
1191-
Type *IntTy64 = Type::getInt64Ty(M.getContext());
1192-
uint64_t ProfileVersion = (INSTR_PROF_RAW_VERSION | VARIANT_MASK_IR_PROF);
1193-
if (IsCS)
1194-
ProfileVersion |= VARIANT_MASK_CSIR_PROF;
1195-
if (InstrEntryBBEnabled)
1196-
ProfileVersion |= VARIANT_MASK_INSTR_ENTRY;
1197-
if (DebugInfoCorrelate)
1198-
ProfileVersion |= VARIANT_MASK_DBG_CORRELATE;
1199-
if (PGOFunctionEntryCoverage)
1200-
ProfileVersion |=
1201-
VARIANT_MASK_BYTE_COVERAGE | VARIANT_MASK_FUNCTION_ENTRY_ONLY;
1202-
auto IRLevelVersionVariable = new GlobalVariable(
1203-
M, IntTy64, true, GlobalValue::WeakAnyLinkage,
1204-
Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
1205-
IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility);
1206-
Triple TT(M.getTargetTriple());
1207-
if (TT.supportsCOMDAT()) {
1208-
IRLevelVersionVariable->setLinkage(GlobalValue::ExternalLinkage);
1209-
IRLevelVersionVariable->setComdat(M.getOrInsertComdat(VarName));
1210-
}
1211-
return IRLevelVersionVariable;
1212-
}
1213-
12141184
// Create the variable for the profile file name.
12151185
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput) {
12161186
if (InstrProfileOutput.empty())

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,33 @@ static const char *ValueProfKindDescr[] = {
342342
#include "llvm/ProfileData/InstrProfData.inc"
343343
};
344344

345+
// Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime
346+
// aware this is an ir_level profile so it can set the version flag.
347+
static GlobalVariable *createIRLevelProfileFlagVar(Module &M, bool IsCS) {
348+
const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
349+
Type *IntTy64 = Type::getInt64Ty(M.getContext());
350+
uint64_t ProfileVersion = (INSTR_PROF_RAW_VERSION | VARIANT_MASK_IR_PROF);
351+
if (IsCS)
352+
ProfileVersion |= VARIANT_MASK_CSIR_PROF;
353+
if (PGOInstrumentEntry)
354+
ProfileVersion |= VARIANT_MASK_INSTR_ENTRY;
355+
if (DebugInfoCorrelate)
356+
ProfileVersion |= VARIANT_MASK_DBG_CORRELATE;
357+
if (PGOFunctionEntryCoverage)
358+
ProfileVersion |=
359+
VARIANT_MASK_BYTE_COVERAGE | VARIANT_MASK_FUNCTION_ENTRY_ONLY;
360+
auto IRLevelVersionVariable = new GlobalVariable(
361+
M, IntTy64, true, GlobalValue::WeakAnyLinkage,
362+
Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
363+
IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility);
364+
Triple TT(M.getTargetTriple());
365+
if (TT.supportsCOMDAT()) {
366+
IRLevelVersionVariable->setLinkage(GlobalValue::ExternalLinkage);
367+
IRLevelVersionVariable->setComdat(M.getOrInsertComdat(VarName));
368+
}
369+
return IRLevelVersionVariable;
370+
}
371+
345372
namespace {
346373

347374
/// The select instruction visitor plays three roles specified
@@ -474,9 +501,7 @@ class PGOInstrumentationGenCreateVarLegacyPass : public ModulePass {
474501
createProfileFileNameVar(M, InstrProfileOutput);
475502
// The variable in a comdat may be discarded by LTO. Ensure the
476503
// declaration will be retained.
477-
appendToCompilerUsed(M, createIRLevelProfileFlagVar(
478-
M, /*IsCS=*/true, PGOInstrumentEntry,
479-
DebugInfoCorrelate, PGOFunctionEntryCoverage));
504+
appendToCompilerUsed(M, createIRLevelProfileFlagVar(M, /*IsCS=*/true));
480505
return false;
481506
}
482507
std::string InstrProfileOutput;
@@ -1646,8 +1671,7 @@ static bool InstrumentAllFunctions(
16461671
// For the context-sensitve instrumentation, we should have a separated pass
16471672
// (before LTO/ThinLTO linking) to create these variables.
16481673
if (!IsCS)
1649-
createIRLevelProfileFlagVar(M, /*IsCS=*/false, PGOInstrumentEntry,
1650-
DebugInfoCorrelate, PGOFunctionEntryCoverage);
1674+
createIRLevelProfileFlagVar(M, /*IsCS=*/false);
16511675
std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
16521676
collectComdatMembers(M, ComdatMembers);
16531677

@@ -1669,9 +1693,7 @@ PGOInstrumentationGenCreateVar::run(Module &M, ModuleAnalysisManager &AM) {
16691693
createProfileFileNameVar(M, CSInstrName);
16701694
// The variable in a comdat may be discarded by LTO. Ensure the declaration
16711695
// will be retained.
1672-
appendToCompilerUsed(M, createIRLevelProfileFlagVar(
1673-
M, /*IsCS=*/true, PGOInstrumentEntry,
1674-
DebugInfoCorrelate, PGOFunctionEntryCoverage));
1696+
appendToCompilerUsed(M, createIRLevelProfileFlagVar(M, /*IsCS=*/true));
16751697
return PreservedAnalyses::all();
16761698
}
16771699

0 commit comments

Comments
 (0)