Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 1 | ; RUN: opt -passes="function(ee-instrument),cgscc(inline),function(post-inline-ee-instrument)" -S < %s | FileCheck %s |
| 2 | |
| 3 | ; Running the passes twice should not result in more instrumentation. |
| 4 | ; RUN: opt -passes="function(ee-instrument),function(ee-instrument),cgscc(inline),function(post-inline-ee-instrument),function(post-inline-ee-instrument)" -S < %s | FileCheck %s |
| 5 | |
| 6 | target datalayout = "E-m:e-i64:64-n32:64" |
| 7 | target triple = "powerpc64-bgq-linux" |
| 8 | |
| 9 | define void @leaf_function() #0 { |
| 10 | entry: |
| 11 | ret void |
| 12 | |
| 13 | ; CHECK-LABEL: define void @leaf_function() |
| 14 | ; CHECK: entry: |
| 15 | ; CHECK-NEXT: call void @mcount() |
| 16 | ; CHECK-NEXT: %0 = call i8* @llvm.returnaddress(i32 0) |
| 17 | ; CHECK-NEXT: call void @__cyg_profile_func_enter(i8* bitcast (void ()* @leaf_function to i8*), i8* %0) |
| 18 | ; CHECK-NEXT: %1 = call i8* @llvm.returnaddress(i32 0) |
| 19 | ; CHECK-NEXT: call void @__cyg_profile_func_exit(i8* bitcast (void ()* @leaf_function to i8*), i8* %1) |
| 20 | ; CHECK-NEXT: ret void |
| 21 | } |
| 22 | |
| 23 | |
| 24 | define void @root_function() #0 { |
| 25 | entry: |
| 26 | call void @leaf_function() |
| 27 | ret void |
| 28 | |
| 29 | ; CHECK-LABEL: define void @root_function() |
| 30 | ; CHECK: entry: |
| 31 | ; CHECK-NEXT: call void @mcount() |
| 32 | |
| 33 | ; CHECK-NEXT %0 = call i8* @llvm.returnaddress(i32 0) |
| 34 | ; CHECK-NEXT call void @__cyg_profile_func_enter(i8* bitcast (void ()* @root_function to i8*), i8* %0) |
| 35 | |
| 36 | ; Entry and exit calls, inlined from @leaf_function() |
| 37 | ; CHECK-NEXT %1 = call i8* @llvm.returnaddress(i32 0) |
| 38 | ; CHECK-NEXT call void @__cyg_profile_func_enter(i8* bitcast (void ()* @leaf_function to i8*), i8* %1) |
| 39 | ; CHECK-NEXT %2 = call i8* @llvm.returnaddress(i32 0) |
| 40 | ; CHECK-NEXT call void @__cyg_profile_func_exit(i8* bitcast (void ()* @leaf_function to i8*), i8* %2) |
| 41 | ; CHECK-NEXT %3 = call i8* @llvm.returnaddress(i32 0) |
| 42 | |
| 43 | ; CHECK-NEXT call void @__cyg_profile_func_exit(i8* bitcast (void ()* @root_function to i8*), i8* %3) |
| 44 | ; CHECK-NEXT ret void |
| 45 | } |
| 46 | |
| 47 | |
| 48 | |
| 49 | ; The mcount function has many different names. |
| 50 | |
| 51 | define void @f1() #1 { entry: ret void } |
| 52 | ; CHECK-LABEL: define void @f1 |
| 53 | ; CHECK: call void @.mcount |
| 54 | |
| 55 | define void @f2() #2 { entry: ret void } |
| 56 | ; CHECK-LABEL: define void @f2 |
| 57 | ; CHECK: call void @"\01__gnu_mcount_nc" |
| 58 | |
| 59 | define void @f3() #3 { entry: ret void } |
| 60 | ; CHECK-LABEL: define void @f3 |
| 61 | ; CHECK: call void @"\01_mcount" |
| 62 | |
| 63 | define void @f4() #4 { entry: ret void } |
| 64 | ; CHECK-LABEL: define void @f4 |
| 65 | ; CHECK: call void @"\01mcount" |
| 66 | |
| 67 | define void @f5() #5 { entry: ret void } |
| 68 | ; CHECK-LABEL: define void @f5 |
| 69 | ; CHECK: call void @__mcount |
| 70 | |
| 71 | define void @f6() #6 { entry: ret void } |
| 72 | ; CHECK-LABEL: define void @f6 |
| 73 | ; CHECK: call void @_mcount |
| 74 | |
| 75 | define void @f7() #7 { entry: ret void } |
| 76 | ; CHECK-LABEL: define void @f7 |
| 77 | ; CHECK: call void @__cyg_profile_func_enter_bare |
| 78 | |
| 79 | |
| 80 | ; Treat musttail calls as terminators; inserting between the musttail call and |
| 81 | ; ret is not allowed. |
| 82 | declare i32* @tailcallee() |
| 83 | define i32* @tailcaller() #8 { |
| 84 | %1 = musttail call i32* @tailcallee() |
| 85 | ret i32* %1 |
| 86 | ; CHECK-LABEL: define i32* @tailcaller |
| 87 | ; CHECK: call void @__cyg_profile_func_exit |
| 88 | ; CHECK: musttail call i32* @tailcallee |
| 89 | ; CHECK: ret |
| 90 | } |
| 91 | define i8* @tailcaller2() #8 { |
| 92 | %1 = musttail call i32* @tailcallee() |
| 93 | %2 = bitcast i32* %1 to i8* |
| 94 | ret i8* %2 |
| 95 | ; CHECK-LABEL: define i8* @tailcaller2 |
| 96 | ; CHECK: call void @__cyg_profile_func_exit |
| 97 | ; CHECK: musttail call i32* @tailcallee |
| 98 | ; CHECK: bitcast |
| 99 | ; CHECK: ret |
| 100 | } |
| 101 | |
| 102 | ; The attributes are "consumed" when the instrumentation is inserted. |
| 103 | ; CHECK: attributes |
| 104 | ; CHECK-NOT: instrument-function |
| 105 | |
| 106 | attributes #0 = { "instrument-function-entry-inlined"="mcount" "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" } |
| 107 | attributes #1 = { "instrument-function-entry-inlined"=".mcount" } |
| 108 | attributes #2 = { "instrument-function-entry-inlined"="\01__gnu_mcount_nc" } |
| 109 | attributes #3 = { "instrument-function-entry-inlined"="\01_mcount" } |
| 110 | attributes #4 = { "instrument-function-entry-inlined"="\01mcount" } |
| 111 | attributes #5 = { "instrument-function-entry-inlined"="__mcount" } |
| 112 | attributes #6 = { "instrument-function-entry-inlined"="_mcount" } |
| 113 | attributes #7 = { "instrument-function-entry-inlined"="__cyg_profile_func_enter_bare" } |
| 114 | attributes #8 = { "instrument-function-exit"="__cyg_profile_func_exit" } |