Skip to content

Commit

Permalink
Revert "[PGO] Generate __llvm_profile_raw_version only when instrumen…
Browse files Browse the repository at this point in the history
…ted"

This reverts commit 5d5ead1.
  • Loading branch information
samolisov committed May 31, 2024
1 parent 37019cf commit e6a918e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
20 changes: 7 additions & 13 deletions llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,9 @@ static GlobalVariable *createIRLevelProfileFlagVar(Module &M, bool IsCS) {
ProfileVersion |= VARIANT_MASK_BYTE_COVERAGE;
if (PGOTemporalInstrumentation)
ProfileVersion |= VARIANT_MASK_TEMPORAL_PROF;
assert(!M.global_empty() &&
"If a module was instrumented, there must be defined global variables "
"at least for the counters.");
auto *InsertionPoint = &*M.global_begin();
auto *IRLevelVersionVariable = new GlobalVariable(
auto IRLevelVersionVariable = new GlobalVariable(
M, IntTy64, true, GlobalValue::WeakAnyLinkage,
Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName,
InsertionPoint);
Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
IRLevelVersionVariable->setVisibility(GlobalValue::HiddenVisibility);
Triple TT(M.getTargetTriple());
if (TT.supportsCOMDAT()) {
Expand Down Expand Up @@ -1834,6 +1829,11 @@ static bool InstrumentAllFunctions(
Module &M, function_ref<TargetLibraryInfo &(Function &)> LookupTLI,
function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
function_ref<BlockFrequencyInfo *(Function &)> LookupBFI, bool IsCS) {
// For the context-sensitve instrumentation, we should have a separated pass
// (before LTO/ThinLTO linking) to create these variables.
if (!IsCS && !PGOCtxProfLoweringPass::isContextualIRPGOEnabled())
createIRLevelProfileFlagVar(M, /*IsCS=*/false);

Triple TT(M.getTargetTriple());
LLVMContext &Ctx = M.getContext();
if (!TT.isOSBinFormatELF() && EnableVTableValueProfiling)
Expand All @@ -1855,15 +1855,9 @@ static bool InstrumentAllFunctions(
instrumentOneFunc(F, &M, TLI, BPI, BFI, ComdatMembers, IsCS);
AnythingInstrumented = true;
}

if (!AnythingInstrumented)
return false;

// For the context-sensitve instrumentation, we should have a separated pass
// (before LTO/ThinLTO linking) to create these variables.
if (!IsCS && !PGOCtxProfLoweringPass::isContextualIRPGOEnabled())
createIRLevelProfileFlagVar(M, /*IsCS=*/false);

return true;
}

Expand Down
7 changes: 6 additions & 1 deletion llvm/test/Transforms/PGOProfile/declarations_only.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --implicit-check-not='__llvm_profile_raw_version'
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-COMDAT

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; GEN-COMDAT: $__llvm_profile_raw_version = comdat any
; GEN-COMDAT: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
; GEN-NOT: @__profn_test_1 = private constant [6 x i8] c"test_1"
; GEN-NOT: @__profn_test_2 = private constant [6 x i8] c"test_2"

declare i32 @test_1(i32 %i)

declare i32 @test_2(i32 %i)
5 changes: 4 additions & 1 deletion llvm/test/Transforms/PGOProfile/global_variables_only.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --implicit-check-not='__llvm_profile_raw_version'
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN-COMDAT

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; GEN-COMDAT: $__llvm_profile_raw_version = comdat any
; GEN-COMDAT: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat

@var = internal unnamed_addr global [35 x ptr] zeroinitializer, align 16
15 changes: 0 additions & 15 deletions llvm/test/Transforms/PGOProfile/no_global_variables.ll

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ TEST_P(PGOInstrumentationGenIgnoreTest, NotInstrumented) {

const auto *IRInstrVar =
M->getNamedGlobal(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
EXPECT_THAT(IRInstrVar, IsNull());
EXPECT_THAT(IRInstrVar, NotNull());
EXPECT_FALSE(IRInstrVar->isDeclaration());
}

} // end anonymous namespace

0 comments on commit e6a918e

Please sign in to comment.