Skip to content

Commit c771208

Browse files
committed
[InstrProfiling] Don't generate __llvm_profile_runtime_user
This is no longer needed, we can add __llvm_profile_runtime directly to llvm.compiler.used or llvm.used to achieve the same effect. Differential Revision: https://reviews.llvm.org/D98325
1 parent 5af991d commit c771208

File tree

4 files changed

+5
-33
lines changed

4 files changed

+5
-33
lines changed

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ inline StringRef getInstrProfRuntimeHookVarName() {
149149
return INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_RUNTIME_VAR);
150150
}
151151

152-
/// Return the name of the compiler generated function that references the
153-
/// runtime hook variable. The function is a weak global.
154-
inline StringRef getInstrProfRuntimeHookVarUseFuncName() {
155-
return "__llvm_profile_runtime_user";
156-
}
157-
158152
inline StringRef getInstrProfCounterBiasVarName() {
159153
return "__llvm_profile_counter_bias";
160154
}

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,23 +1073,8 @@ bool InstrProfiling::emitRuntimeHook() {
10731073
new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
10741074
nullptr, getInstrProfRuntimeHookVarName());
10751075

1076-
// Make a function that uses it.
1077-
auto *User = Function::Create(FunctionType::get(Int32Ty, false),
1078-
GlobalValue::LinkOnceODRLinkage,
1079-
getInstrProfRuntimeHookVarUseFuncName(), M);
1080-
User->addFnAttr(Attribute::NoInline);
1081-
if (Options.NoRedZone)
1082-
User->addFnAttr(Attribute::NoRedZone);
1083-
User->setVisibility(GlobalValue::HiddenVisibility);
1084-
if (TT.supportsCOMDAT())
1085-
User->setComdat(M->getOrInsertComdat(User->getName()));
1086-
1087-
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", User));
1088-
auto *Load = IRB.CreateLoad(Int32Ty, Var);
1089-
IRB.CreateRet(Load);
1090-
10911076
// Mark the user variable as used so that it isn't stripped out.
1092-
CompilerUsedVars.push_back(User);
1077+
CompilerUsedVars.push_back(Var);
10931078
return true;
10941079
}
10951080

llvm/test/Instrumentation/InstrProfiling/linkage.ll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,3 @@ define available_externally void @foo_extern() {
8181
}
8282

8383
declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
84-
85-
; MACHO: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() {{.*}} {
86-
; MACHO: %[[REG:.*]] = load i32, i32* @__llvm_profile_runtime
87-
; MACHO: ret i32 %[[REG]]
88-
; MACHO: }
89-
; COFF: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() {{.*}} comdat {
90-
; ELF-NOT: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() {{.*}} {
91-
; ELF-NOT: %[[REG:.*]] = load i32, i32* @__llvm_profile_runtime

llvm/test/Instrumentation/InstrProfiling/profiling.ll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ define void @baz() {
5454

5555
declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
5656

57-
; ELF: @llvm.compiler.used = appending global {{.*}} @__llvm_profile_runtime_user {{.*}} @__profd_foo {{.*}} @__profd_bar {{.*}} @__profd_baz
58-
; MACHO: @llvm.used = appending global {{.*}} @__llvm_profile_runtime_user {{.*}} @__profd_foo {{.*}} @__profd_bar {{.*}} @__profd_baz
59-
; WIN: @llvm.used = appending global {{.*}} @__llvm_profile_runtime_user {{.*}} @__profd_foo {{.*}} @__profd_bar {{.*}} @__profd_baz
57+
; ELF: @llvm.compiler.used = appending global {{.*}} @__llvm_profile_runtime {{.*}} @__profd_foo {{.*}} @__profd_bar {{.*}} @__profd_baz
58+
; MACHO: @llvm.used = appending global {{.*}} @__llvm_profile_runtime {{.*}} @__profd_foo {{.*}} @__profd_bar {{.*}} @__profd_baz
59+
; WIN: @llvm.used = appending global {{.*}} @__llvm_profile_runtime {{.*}} @__profd_foo {{.*}} @__profd_bar {{.*}} @__profd_baz
6060

6161
; ELF_GENERIC: define internal void @__llvm_profile_register_functions() unnamed_addr {
62+
; ELF_GENERIC-NEXT: call void @__llvm_profile_register_function(i8* bitcast (i32* @__llvm_profile_runtime to i8*))
6263
; ELF_GENERIC-NEXT: call void @__llvm_profile_register_function(i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_foo to i8*))
6364
; ELF_GENERIC-NEXT: call void @__llvm_profile_register_function(i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_bar to i8*))
6465
; ELF_GENERIC-NEXT: call void @__llvm_profile_register_function(i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_baz to i8*))

0 commit comments

Comments
 (0)