diff options
| author | Justin Bogner <mail@justinbogner.com> | 2014-12-08 18:02:35 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2014-12-08 18:02:35 +0000 |
| commit | 61ba2e3996120a08deef823dccd7e8d8cd9c4332 (patch) | |
| tree | 668a13811cf59ae9a9f96442aa0e51cd4153eb9e /llvm/test/Instrumentation | |
| parent | 05917fa60041518d5dc30eb4301fec8483dadb17 (diff) | |
| download | bcm5719-llvm-61ba2e3996120a08deef823dccd7e8d8cd9c4332.tar.gz bcm5719-llvm-61ba2e3996120a08deef823dccd7e8d8cd9c4332.zip | |
InstrProf: An intrinsic and lowering for instrumentation based profiling
Introduce the ``llvm.instrprof_increment`` intrinsic and the
``-instrprof`` pass. These provide the infrastructure for writing
counters for profiling, as in clang's ``-fprofile-instr-generate``.
The implementation of the instrprof pass is ported directly out of the
CodeGenPGO classes in clang, and with the followup in clang that rips
that code out to use these new intrinsics this ends up being NFC.
Doing the instrumentation this way opens some doors in terms of
improving the counter performance. For example, this will make it
simple to experiment with alternate lowering strategies, and allows us
to try handling profiling specially in some optimizations if we want
to.
Finally, this drastically simplifies the frontend and puts all of the
lowering logic in one place.
llvm-svn: 223672
Diffstat (limited to 'llvm/test/Instrumentation')
4 files changed, 93 insertions, 0 deletions
diff --git a/llvm/test/Instrumentation/InstrProfiling/no-counters.ll b/llvm/test/Instrumentation/InstrProfiling/no-counters.ll new file mode 100644 index 00000000000..0716b0d8c6f --- /dev/null +++ b/llvm/test/Instrumentation/InstrProfiling/no-counters.ll @@ -0,0 +1,10 @@ +;; No instrumentation should be emitted if there are no counter increments. + +; RUN: opt < %s -instrprof -S | FileCheck %s +; CHECK-NOT: @__llvm_profile_counters +; CHECK-NOT: @__llvm_profile_data +; CHECK-NOT: @__llvm_profile_runtime + +define void @foo() { + ret void +} diff --git a/llvm/test/Instrumentation/InstrProfiling/noruntime.ll b/llvm/test/Instrumentation/InstrProfiling/noruntime.ll new file mode 100644 index 00000000000..e69445dc350 --- /dev/null +++ b/llvm/test/Instrumentation/InstrProfiling/noruntime.ll @@ -0,0 +1,16 @@ +;; Check that we don't emit the runtime hooks if the user provided them. + +; RUN: opt < %s -instrprof -S | FileCheck %s +; CHECK-NOT: define {{.*}} @__llvm_profile_runtime_user() +; CHECK-NOT: load i32* @__llvm_profile_runtime + +@__llvm_profile_runtime = global i32 0, align 4 + +@__llvm_profile_name_foo = hidden constant [3 x i8] c"foo" + +define void @foo() { + call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i64 0, i32 1, i32 0) + ret void +} + +declare void @llvm.instrprof.increment(i8*, i64, i32, i32) diff --git a/llvm/test/Instrumentation/InstrProfiling/platform.ll b/llvm/test/Instrumentation/InstrProfiling/platform.ll new file mode 100644 index 00000000000..e0327683b7f --- /dev/null +++ b/llvm/test/Instrumentation/InstrProfiling/platform.ll @@ -0,0 +1,29 @@ +;; 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 + +@__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 +; ELF: @__llvm_profile_name_foo = hidden constant [3 x i8] c"foo", section "__llvm_prf_names", align 1 + +; MACHO: @__llvm_profile_counters_foo = hidden global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", 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 +define void @foo() { + call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i64 0, i32 1, i32 0) + ret void +} + +declare void @llvm.instrprof.increment(i8*, i64, i32, i32) + +;; Emit registration functions for platforms that don't find the +;; symbols by their sections. + +; MACHO-NOT: define internal void @__llvm_profile_register_functions +; ELF: define internal void @__llvm_profile_register_functions + +; MACHO-NOT: define internal void @__llvm_profile_init +; ELF: define internal void @__llvm_profile_init diff --git a/llvm/test/Instrumentation/InstrProfiling/profiling.ll b/llvm/test/Instrumentation/InstrProfiling/profiling.ll new file mode 100644 index 00000000000..246bf6b43f9 --- /dev/null +++ b/llvm/test/Instrumentation/InstrProfiling/profiling.ll @@ -0,0 +1,38 @@ +; RUN: opt < %s -instrprof -S | FileCheck %s + +target triple = "x86_64-apple-macosx10.10.0" + +@__llvm_profile_name_foo = hidden constant [3 x i8] c"foo" +; CHECK: @__llvm_profile_name_foo = hidden constant [3 x i8] c"foo", section "__DATA,__llvm_prf_names", align 1 +@__llvm_profile_name_bar = hidden constant [4 x i8] c"bar\00" +; CHECK: @__llvm_profile_name_bar = hidden constant [4 x i8] c"bar\00", section "__DATA,__llvm_prf_names", align 1 +@baz_prof_name = hidden constant [3 x i8] c"baz" +; CHECK: @baz_prof_name = hidden constant [3 x i8] c"baz", section "__DATA,__llvm_prf_names", align 1 + +; CHECK: @__llvm_profile_counters_foo = hidden global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 +; CHECK: @__llvm_profile_data_foo = hidden constant {{.*}}, section "__DATA,__llvm_prf_data", align 8 +define void @foo() { + call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i64 0, i32 1, i32 0) + ret void +} + +; CHECK: @__llvm_profile_counters_bar = hidden global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 +; CHECK: @__llvm_profile_data_bar = hidden constant {{.*}}, section "__DATA,__llvm_prf_data", align 8 +define void @bar() { + call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8]* @__llvm_profile_name_bar, i32 0, i32 0), i64 0, i32 1, i32 0) + ret void +} + +; CHECK: @__llvm_profile_counters_baz = hidden global [3 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 +; CHECK: @__llvm_profile_data_baz = hidden constant {{.*}}, section "__DATA,__llvm_prf_data", align 8 +define void @baz() { + call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8]* @baz_prof_name, i32 0, i32 0), i64 0, i32 3, i32 0) + call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8]* @baz_prof_name, i32 0, i32 0), i64 0, i32 3, i32 1) + call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8]* @baz_prof_name, i32 0, i32 0), i64 0, i32 3, i32 2) + ret void +} + +declare void @llvm.instrprof.increment(i8*, i64, i32, i32) + +; CHECK: @__llvm_profile_runtime = external global i32 +; CHECK: @llvm.used = appending global {{.*}} @__llvm_profile_data_foo {{.*}} @__llvm_profile_data_bar {{.*}} @__llvm_profile_data_baz {{.*}} section "llvm.metadata" |

