brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.3 KiB · 604b4fd Raw
240 lines · plain
1; The static-data-splitter processes data from @cold_func first,2; @unprofiled_func secondly, and @hot_func after the two functions above.3; Tests that data hotness is based on aggregated module-wide profile4; information. This way linker-mergable data is emitted once per module.5 6target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"7target triple = "x86_64-unknown-linux-gnu"8 9; The three RUN commands set `-relocation-model=pic` so `hot_relro_array` and10; `cold_relro_array` are placed in the .data.rel.ro-prefixed section.11 12; This RUN command sets `-data-sections=true -unique-section-names=true` so data13; sections are uniqufied by numbers.14; RUN: llc -mtriple=x86_64-unknown-linux-gnu -relocation-model=pic \15; RUN:     -partition-static-data-sections=true \16; RUN:     -data-sections=true -unique-section-names=true \17; RUN:     %s -o - 2>&1 | FileCheck %s --check-prefixes=SYM,COMMON --dump-input=always18 19; This RUN command sets `-data-sections=true -unique-section-names=false` so20; data sections are uniqufied by variable names.21; RUN: llc -mtriple=x86_64-unknown-linux-gnu -relocation-model=pic \22; RUN:     -partition-static-data-sections=true \23; RUN:     -data-sections=true  -unique-section-names=false \24; RUN:     %s -o - 2>&1 | FileCheck %s --check-prefixes=UNIQ,COMMON --dump-input=always25 26; This RUN command sets `-data-sections=false -unique-section-names=false`.27; RUN: llc -mtriple=x86_64-unknown-linux-gnu -relocation-model=pic \28; RUN:     -partition-static-data-sections=true \29; RUN:     -data-sections=false -unique-section-names=false  \30; RUN:     %s -o - 2>&1 | FileCheck %s --check-prefixes=AGG,COMMON --dump-input=always31 32; For @.str and @.str.133; COMMON:      .type .L.str,@object34; SYM-NEXT:    .section .rodata.str1.1.hot.35; UNIQ-NEXT:   .section	.rodata.str1.1.hot.,"aMS",@progbits,136; AGG-NEXT:    .section	.rodata.str1.1.hot37; COMMON-NEXT: .L.str:38; COMMON-NEXT:    "hot\t"39; COMMON:      .L.str.1:40; COMMON-NEXT:    "%d\t%d\t%d\n"41 42; For @hot_relro_array43; COMMON:      .type hot_relro_array,@object44; SYM-NEXT:    .section	.data.rel.ro.hot.hot_relro_array45; UNIQ-NEXT:   .section	.data.rel.ro.hot.,"aw",@progbits,unique,146; AGG-NEXT:    .section	.data.rel.ro.hot.,"aw",@progbits47 48; For @hot_data, which is accessed by {cold_func, unprofiled_func, hot_func}.49; COMMON:      .type hot_data,@object50; SYM-NEXT:    .section	.data.hot.hot_data,"aw",@progbits51; UNIQ-NEXT:   .section	.data.hot.,"aw",@progbits,unique,252; AGG-NEXT:    .section	.data.hot.,"aw",@progbits53 54; For @hot_bss, which is accessed by {unprofiled_func, hot_func}.55; COMMON:      .type hot_bss,@object56; SYM-NEXT:    .section	.bss.hot.hot_bss,"aw",@nobits57; UNIQ-NEXT:   .section	.bss.hot.,"aw",@nobits,unique,358; AGG-NEXT:    .section .bss.hot.,"aw",@nobits59 60; For @.str.261; COMMON:      .type .L.str.2,@object62; SYM-NEXT:    .section	.rodata.str1.1.unlikely.,"aMS",@progbits,163; UNIQ-NEXT:   .section	.rodata.str1.1.unlikely.,"aMS",@progbits,164; AGG-NEXT:    .section	.rodata.str1.1.unlikely.,"aMS",@progbits,165; COMMON-NEXT: .L.str.2:66; COMMON-NEXT:    "cold%d\t%d\t%d\n"67 68; For @cold_bss69; COMMON:      .type cold_bss,@object70; SYM-NEXT:    .section	.bss.unlikely.cold_bss,"aw",@nobits71; UNIQ-NEXT:   .section	.bss.unlikely.,"aw",@nobits,unique,472; AGG-NEXT:    .section	.bss.unlikely.,"aw",@nobits73 74; For @cold_data75; COMMON:      .type cold_data,@object76; SYM-NEXT:    .section	.data.unlikely.cold_data,"aw",@progbits77; UNIQ-NEXT:   .section	.data.unlikely.,"aw",@progbits,unique,578; AGG-NEXT:    .section	.data.unlikely.,"aw",@progbits79 80; For @cold_data_custom_foo_section81; It has an explicit section 'foo' and shouldn't have hot or unlikely suffix.82; COMMON:      .type cold_data_custom_foo_section,@object83; SYM-NEXT:    .section foo,"aw",@progbits84; UNIQ-NEXT:   .section foo,"aw",@progbits85; AGG-NEXT:    .section foo,"aw",@progbits86 87; For @cold_relro_array88; COMMON:      .type cold_relro_array,@object89; SYM-NEXT:    .section	.data.rel.ro.unlikely.cold_relro_array,"aw",@progbits90; UNIQ-NEXT:   .section	.data.rel.ro.unlikely.,"aw",@progbits,unique,691; AGG-NEXT:    .section	.data.rel.ro.unlikely.,"aw",@progbits92 93; Currently static-data-splitter only analyzes access from code.94; @bss2 and @data3 are indirectly accessed by code through @hot_relro_array95; and @cold_relro_array. A follow-up item is to analyze indirect access via data96; and prune the unlikely list.97; For @bss298; COMMON:      .type bss2,@object99; SYM-NEXT:    .section	.bss.unlikely.bss2,"aw",@nobits100; UNIQ-NEXT:   .section	.bss.unlikely.,"aw",@nobits,unique,7101; AGG-NEXT:    .section	.bss.unlikely.,"aw",@nobits102 103; For @data3104; COMMON:      .type data3,@object105; SYM-NEXT:    .section	.data.unlikely.data3,"aw",@progbits106; UNIQ-NEXT:   .section	.data.unlikely.,"aw",@progbits,unique,8107; AGG-NEXT:    .section	.data.unlikely.,"aw",@progbits108 109;; The `.section` directive is omitted for .data with -unique-section-names=false.110; See MCSectionELF::shouldOmitSectionDirective for the implementation details.111 112; For @data_with_unknown_hotness113; SYM: 	       .type	.Ldata_with_unknown_hotness,@object          # @data_with_unknown_hotness114; SYM:         .section .data..Ldata_with_unknown_hotness,"aw",@progbits115; UNIQ:        .section  .data,"aw",@progbits,unique,9116 117; AGG:         .data118; COMMON:      .Ldata_with_unknown_hotness:119 120; For variables that are not eligible for section prefix annotation121; COMMON:      .type hot_data_custom_bar_section,@object122; SYM-NEXT:    .section bar,"aw",@progbits123; SYM:         hot_data_custom_bar_section124; UNIQ:        .section bar,"aw",@progbits125; AGG:         .section bar,"aw",@progbits126 127; SYM:      .section .data.llvm.fake_var,"aw"128; UNIQ:     .section .data,"aw"129; AGG:      .data130 131;; No section for linker declaration132; COMMON-NOT:  qux133 134@.str = private unnamed_addr constant [5 x i8] c"hot\09\00", align 1135@.str.1 = private unnamed_addr constant [10 x i8] c"%d\09%d\09%d\0A\00", align 1136@hot_relro_array = internal constant [2 x ptr] [ptr @bss2, ptr @data3]137@hot_data = internal global i32 5138@hot_bss = internal global i32 0139@.str.2 = private unnamed_addr constant [14 x i8] c"cold%d\09%d\09%d\0A\00", align 1140@cold_bss = internal global i32 0141@cold_data = internal global i32 4142@cold_data_custom_foo_section = internal global i32 100, section "foo"143@cold_relro_array = internal constant [2 x ptr] [ptr @data3, ptr @bss2]144@bss2 = internal global i32 0145@data3 = internal global i32 3146@data_with_unknown_hotness = private global i32 5147@hot_data_custom_bar_section = internal global i32 101 #0148@llvm.fake_var = internal global i32 123149@qux = external global i64150 151define void @cold_func(i32 %0) !prof !15 {152  %2 = load i32, ptr @cold_bss153  %3 = load i32, ptr @cold_data154  %4 = srem i32 %0, 2155  %5 = sext i32 %4 to i64156  %6 = getelementptr inbounds [2 x ptr], ptr @cold_relro_array, i64 0, i64 %5157  %7 = load ptr, ptr %6158  %8 = load i32, ptr %7159  %9 = load i32, ptr @data_with_unknown_hotness160  %11 = load i32, ptr @hot_data161  %12 = load i32, ptr @cold_data_custom_foo_section162  %13 = call i32 (...) @func_taking_arbitrary_param(ptr @.str.2, i32 %2, i32 %3, i32 %8, i32 %9, i32 %11, i32 %12)163  ret void164}165 166define i32 @unprofiled_func() {167  %a = load i32, ptr @data_with_unknown_hotness168  %b = load i32, ptr @hot_data169  %c = load i32, ptr @hot_bss170  %ret = call i32 (...) @func_taking_arbitrary_param(i32 %a, i32 %b, i32 %c)171  ret i32 %ret172}173 174define void @hot_func(i32 %0) !prof !14 {175  %2 = call i32 (...) @func_taking_arbitrary_param(ptr @.str)176  %3 = srem i32 %0, 2177  %4 = sext i32 %3 to i64178  %5 = getelementptr inbounds [2 x ptr], ptr @hot_relro_array, i64 0, i64 %4179  %6 = load ptr, ptr %5180  %7 = load i32, ptr %6181  %8 = load i32, ptr @hot_data182  %9 = load i32, ptr @hot_bss183  %10 = load i32, ptr @hot_data_custom_bar_section184  %11 = call i32 (...) @func_taking_arbitrary_param(ptr @.str.1, i32 %7, i32 %8, i32 %9, i32 %10)185  ret void186}187 188define i32 @main(i32 %0, ptr %1) !prof !15 {189  br label %11190 1915:                                                ; preds = %11192  %6 = call i32 @rand()193  store i32 %6, ptr @cold_bss194  store i32 %6, ptr @cold_data195  store i32 %6, ptr @bss2196  store i32 %6, ptr @data3197  call void @cold_func(i32 %6)198  ret i32 0199 20011:                                               ; preds = %11, %2201  %12 = phi i32 [ 0, %2 ], [ %19, %11 ]202  %13 = call i32 @rand()203  %14 = srem i32 %13, 2204  %15 = sext i32 %14 to i64205  %16 = getelementptr inbounds [2 x ptr], ptr @hot_relro_array, i64 0, i64 %15206  %17 = load ptr, ptr %16207  store i32 %13, ptr %17208  store i32 %13, ptr @hot_data209  %18 = add i32 %13, 1210  store i32 %18, ptr @hot_bss211  call void @hot_func(i32 %12)212  %19 = add i32 %12, 1213  %20 = icmp eq i32 %19, 100000214  br i1 %20, label %5, label %11, !prof !16215}216 217declare i32 @rand()218declare i32 @func_taking_arbitrary_param(...)219 220attributes #0 = {"data-section"="bar"}221 222!llvm.module.flags = !{!1}223 224!1 = !{i32 1, !"ProfileSummary", !2}225!2 = !{!3, !4, !5, !6, !7, !8, !9, !10}226!3 = !{!"ProfileFormat", !"InstrProf"}227!4 = !{!"TotalCount", i64 1460183}228!5 = !{!"MaxCount", i64 849024}229!6 = !{!"MaxInternalCount", i64 32769}230!7 = !{!"MaxFunctionCount", i64 849024}231!8 = !{!"NumCounts", i64 23627}232!9 = !{!"NumFunctions", i64 3271}233!10 = !{!"DetailedSummary", !11}234!11 = !{!12, !13}235!12 = !{i32 990000, i64 166, i32 73}236!13 = !{i32 999999, i64 3, i32 1443}237!14 = !{!"function_entry_count", i64 100000}238!15 = !{!"function_entry_count", i64 1}239!16 = !{!"branch_weights", i32 1, i32 99999}240