87 lines · plain
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 profiles6// - Check that the block counters for function foo is scaled up.7 8// REQUIRES: lld-available9 10// Building the instrumented binary will fail because lld doesn't support11// big-endian ELF for PPC (aka ABI 1).12// ld.lld: error: /lib/../lib64/Scrt1.o: ABI version 1 is not supported13// UNSUPPORTED: ppc && host-byteorder-big-endian14 15// This compiler-rt test aims to have test coverage for the IRPGO name format16// of local-linkage functions during raw profile generation. The C++ functions17// 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.test19// or other suppl* test under tools/llvm-profdata dir) are more suitable for20// more sophisticated cases (e.g., pseudo hot functions or profiles with discriminiators, etc).21 22// RUN: rm -rf %t && split-file %s %t && cd %t23 24// Use clangxx_pgogen for IR level instrumentation for C++.25// The test case is constructed such that `-funique-internal-linkage-names` is26// not used in instrPGO but used in static function names in SamplePGO.27// RUN: %clangxx_pgogen -fuse-ld=lld -O2 main.cpp -o main28// RUN: env LLVM_PROFILE_FILE=main.profraw %run ./main29// RUN: llvm-profdata merge main.profraw -o main.profdata30 31// The function counters are not scaled up.32// RUN: llvm-profdata show -all-functions -counts main.profdata | FileCheck %s --check-prefix=INSTR33 34// The instrPGO profile counter of function foo should be scaled up. Note the35// scaling factor of a function is computed based on instrPGO profiles and36// 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.profdata40// RUN: llvm-profdata show -all-functions -counts merge.profdata | FileCheck %s --check-prefix=SUPPL41 42// INSTR: Counters:43// INSTR: main:44// INSTR: Counters: 145// INSTR: Block counts: [1]46// INSTR: _Z3barv:47// INSTR: Counters: 148// INSTR: Block counts: [2]49// INSTR: main.cpp;_ZL3foov:50// INSTR: Counters: 151// INSTR: Block counts: [1]52 53// INSTR: Functions shown: 354// INSTR: Total functions: 355 56// SUPPL: Counters:57// SUPPL: main:58// SUPPL: Counters: 159// SUPPL: Block counts: [1]60// SUPPL: _Z3barv:61// SUPPL: Counters: 162// SUPPL: Block counts: [2]63// SUPPL: main.cpp;_ZL3foov:64// SUPPL: Counters: 165// SUPPL: Block counts: [3]66 67//--- main.cpp68 69// mark foo and bar as noinline so preinliner won't inlined them into main70// 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.proftext85_ZL3foov.__uniq.23343505234642233139497840575431302970:5:586 1: 587