1// This is a regression test for supplementary profiles. 2 3// What the test does: 4// - Generate raw profiles from an executable and convert it to indexed profiles. 5// - Merge indexed profiles with supplementary sample-pgo profiles 6// - Check that the block counters for function foo is scaled up. 7 8// REQUIRES: lld-available 9 10// Building the instrumented binary will fail because lld doesn't support 11// big-endian ELF for PPC (aka ABI 1). 12// ld.lld: error: /lib/../lib64/Scrt1.o: ABI version 1 is not supported 13// UNSUPPORTED: ppc && host-byteorder-big-endian 14 15// This compiler-rt test aims to have test coverage for the IRPGO name format 16// of local-linkage functions during raw profile generation. The C++ functions 17// are simple with little optimization space so test outputs are more stable. 18// On the other hand, LLVM tests (like tools/llvm-profdata/suppl-instr-with-sample-static-func.test 19// or other suppl* test under tools/llvm-profdata dir) are more suitable for 20// more sophisticated cases (e.g., pseudo hot functions or profiles with discriminiators, etc). 21 22// RUN: rm -rf %t && split-file %s %t && cd %t 23 24// Use clangxx_pgogen for IR level instrumentation for C++. 25// The test case is constructed such that `-funique-internal-linkage-names` is 26// not used in instrPGO but used in static function names in SamplePGO. 27// RUN: %clangxx_pgogen -fuse-ld=lld -O2 main.cpp -o main 28// RUN: env LLVM_PROFILE_FILE=main.profraw %run ./main 29// RUN: llvm-profdata merge main.profraw -o main.profdata 30 31// The function counters are not scaled up. 32// RUN: llvm-profdata show -all-functions -counts main.profdata | FileCheck %s --check-prefix=INSTR 33 34// The instrPGO profile counter of function foo should be scaled up. Note the 35// scaling factor of a function is computed based on instrPGO profiles and 36// invariant to samplePGO profile counters. 37// RUN: llvm-profdata merge -supplement-instr-with-sample=sampleprof.proftext \ 38// RUN: -suppl-min-size-threshold=0 -instr-prof-cold-threshold=1 \ 39// RUN: main.profdata -o merge.profdata 40// RUN: llvm-profdata show -all-functions -counts merge.profdata | FileCheck %s --check-prefix=SUPPL 41 42// INSTR: Counters: 43// INSTR: main: 44// INSTR: Counters: 1 45// INSTR: Block counts: [1] 46// INSTR: _Z3barv: 47// INSTR: Counters: 1 48// INSTR: Block counts: [2] 49// INSTR: main.cpp;_ZL3foov: 50// INSTR: Counters: 1 51// INSTR: Block counts: [1] 52 53// INSTR: Functions shown: 3 54// INSTR: Total functions: 3 55 56// SUPPL: Counters: 57// SUPPL: main: 58// SUPPL: Counters: 1 59// SUPPL: Block counts: [1] 60// SUPPL: _Z3barv: 61// SUPPL: Counters: 1 62// SUPPL: Block counts: [2] 63// SUPPL: main.cpp;_ZL3foov: 64// SUPPL: Counters: 1 65// SUPPL: Block counts: [3] 66 67//--- main.cpp 68 69// mark foo and bar as noinline so preinliner won't inlined them into main 70// before the instrumentation pass. 71__attribute__((noinline)) static void foo() { 72} 73 74__attribute__((noinline)) void bar() { 75} 76 77int main() { 78 foo(); 79 bar(); 80 bar(); 81 return 0; 82} 83 84//--- sampleprof.proftext 85_ZL3foov.__uniq.23343505234642233139497840575431302970:5:5 86 1: 5 87