154 lines · plain
1; REQUIRES: asserts2; asserts are required for -debug-only=<pass-name>3 4; RUN: rm -rf %t && split-file %s %t && cd %t5 6;; Read text profiles and merge them into indexed profiles.7; RUN: llvm-profdata merge --memprof-version=4 memprof.yaml -o memprof.profdata8; RUN: llvm-profdata merge --memprof-version=4 memprof-no-dap.yaml -o memprof-no-dap.profdata9 10;; Run optimizer pass on an IR module without IR functions, and test that global11;; variables in the module could be annotated (i.e., no early return),12; RUN: opt -passes='memprof-use<profile-filename=memprof.profdata>' -memprof-annotate-static-data-prefix \13; RUN: -debug-only=memprof -stats -S funcless-module.ll -o - 2>&1 | FileCheck %s --check-prefixes=LOG,IR,STAT14 15;; Run optimizer pass on the IR, and check the section prefix.16; RUN: opt -passes='memprof-use<profile-filename=memprof.profdata>' -memprof-annotate-static-data-prefix \17; RUN: -debug-only=memprof -stats -S input.ll -o - 2>&1 | FileCheck %s --check-prefixes=LOG,IR,STAT18 19;; Run memprof without providing memprof data. Test that IR has module flag20;; `EnableDataAccessProf` as 0.21; RUN: opt -passes='memprof-use<profile-filename=memprof-no-dap.profdata>' -memprof-annotate-static-data-prefix \22; RUN: -debug-only=memprof -stats -S input.ll -o - 2>&1 | FileCheck %s --check-prefix=FLAG23 24;; Run memprof without explicitly setting -memprof-annotate-static-data-prefix.25;; The output text IR shouldn't have `section_prefix` or EnableDataAccessProf module flag.26; RUN: opt -passes='memprof-use<profile-filename=memprof.profdata>' \27; RUN: -debug-only=memprof -stats -S input.ll -o - | FileCheck %s --check-prefix=FLAGLESS --implicit-check-not="section_prefix"28 29; LOG: Skip annotating string literal .str30; LOG: Global variable var1 is annotated as hot31; LOG: Global variable var2.llvm.125 is annotated as hot32; LOG: Global variable bar is not annotated33; LOG: Global variable foo is annotated as unlikely34; LOG: Skip annotation for var3 due to explicit section name.35; LOG: Skip annotation for var4 due to explicit section name.36; LOG: Skip annotation for llvm.fake_var due to name starts with `llvm.`.37; LOG: Skip annotation for qux due to linker declaration.38 39;; String literals are not annotated.40; IR: @.str = unnamed_addr constant [5 x i8] c"abcde"41; IR-NOT: section_prefix42; IR: @var1 = global i32 123, !section_prefix !043 44;; @var.llvm.125 will be canonicalized to @var2 for profile look-up.45; IR-NEXT: @var2.llvm.125 = global i64 0, !section_prefix !046 47;; @bar is not seen in hot symbol or known symbol set, so it won't get a section48;; prefix. Test this by testing that there is no section_prefix between @bar and49;; @foo.50; IR-NEXT: @bar = global i16 351; IR-NOT: !section_prefix52 53;; @foo is unlikely.54; IR-NEXT: @foo = global i8 2, !section_prefix !155 56; IR-NEXT: @var3 = constant [2 x i32] [i32 12345, i32 6789], section "sec1"57; IR-NEXT: @var4 = constant [1 x i64] [i64 98765] #058 59; IR: @llvm.fake_var = global i32 12360; IR-NOT: !section_prefix61; IR: @qux = external global i6462; IR-NOT: !section_prefix63 64; IR: attributes #0 = { "rodata-section"="sec2" }65 66; IR: !0 = !{!"section_prefix", !"hot"}67; IR-NEXT: !1 = !{!"section_prefix", !"unlikely"}68; IR-NEXT: !2 = !{i32 2, !"EnableDataAccessProf", i32 1}69 70; FLAG: !{i32 2, !"EnableDataAccessProf", i32 0}71; FLAGLESS-NOT: EnableDataAccessProf72 73; STAT: 1 memprof - Number of global vars annotated with 'unlikely' section prefix.74; STAT: 2 memprof - Number of global vars with user-specified section (not annotated).75; STAT: 2 memprof - Number of global vars annotated with 'hot' section prefix.76; STAT: 1 memprof - Number of global vars with unknown hotness (no section prefix).77 78;--- memprof.yaml79---80DataAccessProfiles:81 SampledRecords:82 - Symbol: var183 AccessCount: 100084 - Symbol: var285 AccessCount: 586 - Hash: 10101087 AccessCount: 14588 KnownColdSymbols:89 - foo90 KnownColdStrHashes: [ 999, 1001 ]91...92;--- memprof-no-dap.yaml93---94# A memprof file with without data access profiles. The heap records are simplified95# to pass profile parsing and don't need to match the IR.96HeapProfileRecords:97 - GUID: 0xdeadbeef1234567898 AllocSites:99 - Callstack:100 - { Function: 0x1111111111111111, LineOffset: 11, Column: 10, IsInlineFrame: true }101 MemInfoBlock:102 AllocCount: 111103 TotalSize: 222104 TotalLifetime: 333105 TotalLifetimeAccessDensity: 444106 CallSites:107 - Frames:108 - { Function: 0x5555555555555555, LineOffset: 55, Column: 50, IsInlineFrame: true }109...110;--- input.ll111 112target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"113target triple = "x86_64-unknown-linux-gnu"114 115@.str = unnamed_addr constant [5 x i8] c"abcde"116@var1 = global i32 123117@var2.llvm.125 = global i64 0 118@bar = global i16 3119@foo = global i8 2120@var3 = constant [2 x i32][i32 12345, i32 6789], section "sec1"121@var4 = constant [1 x i64][i64 98765] #0122@llvm.fake_var = global i32 123123@qux = external global i64124 125define i32 @func() {126 %a = load i32, ptr @var1127 %b = load i32, ptr @var2.llvm.125128 %c = load i32, ptr @llvm.fake_var129 %ret = call i32 (...) @func_taking_arbitrary_param(i32 %a, i32 %b, i32 %c)130 ret i32 %ret131}132 133declare i32 @func_taking_arbitrary_param(...)134 135attributes #0 = { "rodata-section"="sec2" }136 137;--- funcless-module.ll138 139target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"140target triple = "x86_64-unknown-linux-gnu"141 142@.str = unnamed_addr constant [5 x i8] c"abcde"143@var1 = global i32 123144@var2.llvm.125 = global i64 0145@bar = global i16 3146@foo = global i8 2147@var3 = constant [2 x i32][i32 12345, i32 6789], section "sec1"148@var4 = constant [1 x i64][i64 98765] #0149@llvm.fake_var = global i32 123150@qux = external global i64151 152 153attributes #0 = { "rodata-section"="sec2" }154