[PGO]: Eliminate calls to __llvm_profile_register_function for Linux.
authorXinliang David Li <davidxl@google.com>
Tue, 13 Oct 2015 18:39:48 +0000 (18:39 +0000)
committerXinliang David Li <davidxl@google.com>
Tue, 13 Oct 2015 18:39:48 +0000 (18:39 +0000)
On Linux, the profile runtime can use __start_SECTNAME and __stop_SECTNAME
symbols defined by the linker to locate the start and end location of
a named section (with C name). This eliminates the need for instrumented
binary to call __llvm_profile_register_function during start-up time.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250199 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/InstrProfiling.cpp
test/Instrumentation/InstrProfiling/platform.ll

index b038d684db21681896594265bb314b22487142b2..a92e7f8297b52ee47b5633f3fb724188834dfd61 100644 (file)
@@ -257,6 +257,9 @@ void InstrProfiling::emitRegistration() {
   if (Triple(M->getTargetTriple()).isOSDarwin())
     return;
 
   if (Triple(M->getTargetTriple()).isOSDarwin())
     return;
 
+  // Use linker script magic to get data/cnts/name start/end.
+  if (Triple(M->getTargetTriple()).isOSLinux()) return;
+
   // Construct the function.
   auto *VoidTy = Type::getVoidTy(M->getContext());
   auto *VoidPtrTy = Type::getInt8PtrTy(M->getContext());
   // Construct the function.
   auto *VoidTy = Type::getVoidTy(M->getContext());
   auto *VoidPtrTy = Type::getInt8PtrTy(M->getContext());
index 5f16cba91d91a86348e837d25d61987522a7f138..cc380d54bd59478e0ace9f640773d3af1bd9cb45 100644 (file)
@@ -1,7 +1,8 @@
 ;; Checks for platform specific section names and initialization code.
 
 ; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s -check-prefix=MACHO
 ;; Checks for platform specific section names and initialization code.
 
 ; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s -check-prefix=MACHO
-; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s -check-prefix=ELF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s -check-prefix=LINUX
+; RUN: opt < %s -mtriple=x86_64-unknown-freebsd -instrprof -S | FileCheck %s -check-prefix=BSD
 
 @__llvm_profile_name_foo = hidden constant [3 x i8] c"foo"
 ; MACHO: @__llvm_profile_name_foo = hidden constant [3 x i8] c"foo", section "__DATA,__llvm_prf_names", align 1
 
 @__llvm_profile_name_foo = hidden constant [3 x i8] c"foo"
 ; MACHO: @__llvm_profile_name_foo = hidden constant [3 x i8] c"foo", section "__DATA,__llvm_prf_names", align 1
@@ -11,7 +12,8 @@
 ; ELF: @__llvm_profile_counters_foo = hidden global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8
 
 ; MACHO: @__llvm_profile_data_foo = hidden constant {{.*}}, section "__DATA,__llvm_prf_data", align 8
 ; ELF: @__llvm_profile_counters_foo = hidden global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8
 
 ; MACHO: @__llvm_profile_data_foo = hidden constant {{.*}}, section "__DATA,__llvm_prf_data", align 8
-; ELF: @__llvm_profile_data_foo = hidden constant {{.*}}, section "__llvm_prf_data", align 8
+; LINUX: @__llvm_profile_data_foo = hidden constant {{.*}}, section "__llvm_prf_data", align 8
+; BSD: @__llvm_profile_data_foo = hidden constant {{.*}}, section "__llvm_prf_data", align 8
 define void @foo() {
   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i64 0, i32 1, i32 0)
   ret void
 define void @foo() {
   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i64 0, i32 1, i32 0)
   ret void
@@ -23,7 +25,8 @@ declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
 ;; symbols by their sections.
 
 ; MACHO-NOT: define internal void @__llvm_profile_register_functions
 ;; symbols by their sections.
 
 ; MACHO-NOT: define internal void @__llvm_profile_register_functions
-; ELF: define internal void @__llvm_profile_register_functions
+; LINUX-NOT: define internal void @__llvm_profile_register_functions
+; BSD: define internal void @__llvm_profile_register_functions
 
 ; MACHO-NOT: define internal void @__llvm_profile_init
 
 ; MACHO-NOT: define internal void @__llvm_profile_init
-; ELF: define internal void @__llvm_profile_init
+; BSD: define internal void @__llvm_profile_init