xref: /llvm-project/clang/test/CodeGen/memprof.cpp (revision 546ec641b4b1bbbf9e66a53983b635fe85d365e6)
1 // Test if memprof instrumentation and use pass are invoked.
2 //
3 // Instrumentation:
4 // Ensure Pass MemProfilerPass and ModuleMemProfilerPass are invoked.
5 // RUN: %clang_cc1 -O2 -fmemory-profile %s -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=INSTRUMENT
6 // INSTRUMENT: Running pass: MemProfilerPass on main
7 // INSTRUMENT: Running pass: ModuleMemProfilerPass on [module]
8 
9 // Avoid failures on big-endian systems that can't read the raw profile properly
10 // REQUIRES: x86_64-linux
11 
12 // TODO: Use text profile inputs once that is available for memprof.
13 //
14 // To update the inputs below, run Inputs/update_memprof_inputs.sh
15 // RUN: llvm-profdata merge %S/Inputs/memprof.memprofraw --profiled-binary %S/Inputs/memprof.exe -o %t.memprofdata
16 
17 // Profile use:
18 // Ensure Pass PGOInstrumentationUse is invoked with the memprof-only profile.
19 // RUN: %clang_cc1 -O2 -fmemory-profile-use=%t.memprofdata %s -fdebug-pass-manager  -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=USE
20 // USE: Running pass: MemProfUsePass on [module]
21 
foo()22 char *foo() {
23   return new char[10];
24 }
main()25 int main() {
26   char *a = foo();
27   delete[] a;
28   return 0;
29 }
30