llvm-project/llvm/test/Transforms/PGOProfile/profdata_priv_alias.ll
Paul Kirth f2916becc5 Reland [pgo] Avoid introducing relocations by using private alias
In many cases, we can use an alias to avoid a symbolic relocations,
instead of using the public, interposable symbol. When the instrumented
function is in a COMDAT, we can use a hidden alias, and still avoid
references to discarded sections.

Previous versions of this patch allowed the compiler to name the
generated alias, but that would only be valid when the functions were
local. Since the alias may be used across TUs we use a more
deterministic naming convention, and add a ".local" suffix to the alias
name just as we do for relative vtables aliases.

https://reviews.llvm.org/rG20894a478da224bdd69c91a22a5175b28bc08ed9
removed an incorrect assertion on Mach-O which caused assertion failures in LLD.

We prevent duplicate symbols under ThinLTO + PGO + CFI by disabling
alias generation when the target function has MD_type metadata used in
CFI.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D137982
2023-01-25 22:19:19 +00:00

85 lines
3.4 KiB
LLVM

; RUN: opt -S -passes=pgo-instr-gen,instrprof < %s | FileCheck %s
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"
;; Test that we use private aliases to reference function addresses inside profile data
; CHECK: @__profd_foo = private global {{.*}} ptr @foo.local
; CHECK-NOT: @__profd_foo = private global {{.*}} ptr @foo
; CHECK: @__profd_weak = private global {{.*}} ptr @weak.local
; CHECK: @__profd_linkonce = private global {{.*}} ptr @linkonce.local
; CHECK: @__profd_weakodr = private global {{.*}} ptr @weakodr.local
; CHECK: @__profd_linkonceodr = private global {{.*}} ptr @linkonceodr.local
; available_externally shouldn't have an alias, so make sure it doesn't appear here
; CHECK: @__profc_available_externally.[[HASH:[#0-9]+]]
; CHECK-NOT: @__profd_available_externally.[[HASH]] = {{.*}}ptr @available_externally.[[HASH]].local
;; Ensure when not instrumenting a non-comdat function, then if we generate an
;; alias, then it is private. We check comdat versions in comdat.ll
; CHECK: @foo.local = private alias i32 (i32), ptr @foo
; CHECK: @weak.local = private alias void (), ptr @weak
; CHECK: @linkonce.local = private alias void (), ptr @linkonce
; CHECK: @weakodr.local = private alias void (), ptr @weakodr
; CHECK: @linkonceodr.local = private alias void (), ptr @linkonceodr
;; We should never generate an alias for available_externally functions
; CHECK-NOT: @available_externally{{.*}} = private alias void (), ptr @available_externally
define i32 @foo(i32 %0) {
; CHECK-LABEL: @foo(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[PGOCOUNT:%.*]] = load i64, ptr @__profc_foo, align 8
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[PGOCOUNT]], 1
; CHECK-NEXT: store i64 [[TMP1]], ptr @__profc_foo, align 8
; CHECK-NEXT: ret i32 0
entry:
ret i32 0
}
define weak void @weak() {
; CHECK-LABEL: @weak(
; CHECK-NEXT: [[PGOCOUNT:%.*]] = load i64, ptr @__profc_weak, align 8
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[PGOCOUNT]], 1
; CHECK-NEXT: store i64 [[TMP1]], ptr @__profc_weak, align 8
; CHECK-NEXT: ret void
ret void
}
define linkonce void @linkonce() {
; CHECK-LABEL: @linkonce(
; CHECK-NEXT: [[PGOCOUNT:%.*]] = load i64, ptr @__profc_linkonce, align 8
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[PGOCOUNT]], 1
; CHECK-NEXT: store i64 [[TMP1]], ptr @__profc_linkonce, align 8
; CHECK-NEXT: ret void
ret void
}
define weak_odr void @weakodr() {
; CHECK-LABEL: @weakodr(
; CHECK-NEXT: [[PGOCOUNT:%.*]] = load i64, ptr @__profc_weakodr, align 8
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[PGOCOUNT]], 1
; CHECK-NEXT: store i64 [[TMP1]], ptr @__profc_weakodr, align 8
; CHECK-NEXT: ret void
ret void
}
define linkonce_odr void @linkonceodr() {
; CHECK-LABEL: @linkonceodr(
; CHECK-NEXT: [[PGOCOUNT:%.*]] = load i64, ptr @__profc_linkonceodr, align 8
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[PGOCOUNT]], 1
; CHECK-NEXT: store i64 [[TMP1]], ptr @__profc_linkonceodr, align 8
; CHECK-NEXT: ret void
ret void
}
define available_externally void @available_externally(){
; CHECK-LABEL: @available_externally(
; CHECK-NEXT: [[PGOCOUNT:%.*]] = load i64, ptr @__profc_available_externally.[[HASH]], align 8
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[PGOCOUNT]], 1
; CHECK-NEXT: store i64 [[TMP1]], ptr @__profc_available_externally.[[HASH]], align 8
; CHECK-NEXT: ret void
ret void
}