1; RUN: opt < %s -codegenprepare -S | FileCheck %s 2; RUN: llc < %s | FileCheck --check-prefix=ASM1 %s 3; RUN: llc < %s -function-sections | FileCheck --check-prefix=ASM2 %s 4 5target triple = "x86_64-pc-linux-gnu" 6 7; This tests that hot/cold functions get correct section prefix assigned 8 9; CHECK: hot_func1{{.*}}!section_prefix ![[HOT_ID:[0-9]+]] 10; ASM1: .section .text.hot.,"ax",@progbits 11; ASM2: .section .text.hot.hot_func1,"ax",@progbits 12; The entry is hot 13define void @hot_func1() !prof !15 { 14 ret void 15} 16 17; CHECK: hot_func2{{.*}}!section_prefix ![[HOT_ID:[0-9]+]] 18; Entry is cold but inner block is hot 19define void @hot_func2(i32 %n) !prof !16 { 20entry: 21 %n.addr = alloca i32, align 4 22 %i = alloca i32, align 4 23 store i32 %n, i32* %n.addr, align 4 24 store i32 0, i32* %i, align 4 25 br label %for.cond 26 27for.cond: 28 %0 = load i32, i32* %i, align 4 29 %1 = load i32, i32* %n.addr, align 4 30 %cmp = icmp slt i32 %0, %1 31 br i1 %cmp, label %for.body, label %for.end, !prof !19 32 33for.body: 34 %2 = load i32, i32* %i, align 4 35 %inc = add nsw i32 %2, 1 36 store i32 %inc, i32* %i, align 4 37 br label %for.cond 38 39for.end: 40 ret void 41} 42 43; For instrumentation based PGO, we should only look at block counts, 44; not call site VP metadata (which can exist on value profiled memcpy, 45; or possibly left behind after static analysis based devirtualization). 46; CHECK: cold_func1{{.*}}!section_prefix ![[COLD_ID:[0-9]+]] 47; ASM1: .section .text.unlikely.,"ax",@progbits 48; ASM2: .section .text.unlikely.cold_func1,"ax",@progbits 49define void @cold_func1() !prof !16 { 50 call void @hot_func1(), !prof !17 51 call void @hot_func1(), !prof !17 52 ret void 53} 54 55; CHECK: cold_func2{{.*}}!section_prefix ![[COLD_ID]] 56define void @cold_func2() !prof !16 { 57 call void @hot_func1(), !prof !17 58 call void @hot_func1(), !prof !18 59 call void @hot_func1(), !prof !18 60 ret void 61} 62 63; CHECK: cold_func3{{.*}}!section_prefix ![[COLD_ID]] 64define void @cold_func3() !prof !16 { 65 call void @hot_func1(), !prof !18 66 ret void 67} 68 69; CHECK: ![[HOT_ID]] = !{!"function_section_prefix", !"hot"} 70; CHECK: ![[COLD_ID]] = !{!"function_section_prefix", !"unlikely"} 71!llvm.module.flags = !{!1} 72!1 = !{i32 1, !"ProfileSummary", !2} 73!2 = !{!3, !4, !5, !6, !7, !8, !9, !10} 74!3 = !{!"ProfileFormat", !"InstrProf"} 75!4 = !{!"TotalCount", i64 10000} 76!5 = !{!"MaxCount", i64 1000} 77!6 = !{!"MaxInternalCount", i64 1} 78!7 = !{!"MaxFunctionCount", i64 1000} 79!8 = !{!"NumCounts", i64 3} 80!9 = !{!"NumFunctions", i64 3} 81!10 = !{!"DetailedSummary", !11} 82!11 = !{!12, !13, !14} 83!12 = !{i32 10000, i64 100, i32 1} 84!13 = !{i32 999000, i64 100, i32 1} 85!14 = !{i32 999999, i64 1, i32 2} 86!15 = !{!"function_entry_count", i64 1000} 87!16 = !{!"function_entry_count", i64 1} 88!17 = !{!"branch_weights", i32 80} 89!18 = !{!"branch_weights", i32 1} 90!19 = !{!"branch_weights", i32 1000, i32 1} 91