File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed
lib/Transforms/Instrumentation
test/Transforms/PGOProfile Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -1014,9 +1014,17 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfInstBase *Inc) {
1014
1014
};
1015
1015
auto *DataTy = StructType::get (Ctx, makeArrayRef (DataTypes));
1016
1016
1017
- Constant *FunctionAddr = shouldRecordFunctionAddr (Fn)
1018
- ? ConstantExpr::getBitCast (Fn, Int8PtrTy)
1019
- : ConstantPointerNull::get (Int8PtrTy);
1017
+ Constant *FunctionAddr;
1018
+ if (shouldRecordFunctionAddr (Fn)) {
1019
+ // When possible use a private alias to avoid relocations
1020
+ Constant *Addr = !Fn->isDeclarationForLinker ()
1021
+ ? static_cast <Constant *>(GlobalAlias::create (
1022
+ GlobalValue::PrivateLinkage, Fn->getName (), Fn))
1023
+ : Fn;
1024
+ FunctionAddr = ConstantExpr::getBitCast (Addr, Int8PtrTy);
1025
+ } else {
1026
+ FunctionAddr = ConstantPointerNull::get (Int8PtrTy);
1027
+ }
1020
1028
1021
1029
Constant *Int16ArrayVals[IPVK_Last + 1 ];
1022
1030
for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
Original file line number Diff line number Diff line change
1
+ ; RUN: opt -S -passes=pgo-instr-gen,instrprof < %s | FileCheck %s
2
+
3
+ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4
+ target triple = "x86_64-unknown-linux-gnu"
5
+
6
+ ; Test that we use private aliases to reference function addresses inside profile data
7
+
8
+ ; CHECK: @__profd_foo = private global {{.*}}, ptr @foo.1,
9
+ ; CHECK-NOT: @__profd_foo = private global {{.*}}, ptr @foo,
10
+ ; CHECK: @foo.1 = private alias i32 (i32), ptr @foo
11
+
12
+ define i32 @foo (i32 %0 ) {
13
+ ; CHECK-LABEL: @foo(
14
+ ; CHECK-NEXT: entry:
15
+ ; CHECK-NEXT: [[PGOCOUNT:%.*]] = load i64, ptr @__profc_foo, align 8
16
+ ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[PGOCOUNT]], 1
17
+ ; CHECK-NEXT: store i64 [[TMP1]], ptr @__profc_foo, align 8
18
+ ; CHECK-NEXT: ret i32 0
19
+ ;
20
+ entry:
21
+ ret i32 0
22
+ }
23
+
You can’t perform that action at this time.
0 commit comments