1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00
llvm-mirror/include/llvm-c
Andres Freund 7602e1153a Add PerfJITEventListener for perf profiling support.
This new JIT event listener supports generating profiling data for
the linux 'perf' profiling tool, allowing it to generate function and
instruction level profiles.

Currently this functionality is not enabled by default, but must be
enabled with LLVM_USE_PERF=yes.  Given that the listener has no
dependencies, it might be sensible to enable by default once the
initial issues have been shaken out.

I followed existing precedent in registering the listener by default
in lli. Should there be a decision to enable this by default on linux,
that should probably be changed.

Please note that until https://reviews.llvm.org/D47343 is resolved,
using this functionality with mcjit rather than orcjit will not
reliably work.

Disregarding the previous comment, here's an example:

$ cat /tmp/expensive_loop.c

bool stupid_isprime(uint64_t num)
{
        if (num == 2)
                return true;
        if (num < 1 || num % 2 == 0)
                return false;
        for(uint64_t i = 3; i < num / 2; i+= 2) {
                if (num % i == 0)
                        return false;
        }
        return true;
}

int main(int argc, char **argv)
{
        int numprimes = 0;

        for (uint64_t num = argc; num < 100000; num++)
        {
                if (stupid_isprime(num))
                        numprimes++;
        }

        return numprimes;
}

$ clang -ggdb -S -c -emit-llvm /tmp/expensive_loop.c -o
/tmp/expensive_loop.ll

$ perf record -o perf.data -g -k 1 ./bin/lli -jit-kind=mcjit /tmp/expensive_loop.ll 1

$ perf inject --jit -i perf.data -o perf.jit.data

$ perf report -i perf.jit.data
-   92.59%  lli      jitted-5881-2.so                   [.] stupid_isprime
     stupid_isprime
     main
     llvm::MCJIT::runFunction
     llvm::ExecutionEngine::runFunctionAsMain
     main
     __libc_start_main
     0x4bf6258d4c544155
+    0.85%  lli      ld-2.27.so                         [.] do_lookup_x

And line-level annotations also work:
       │              for(uint64_t i = 3; i < num / 2; i+= 2) {
       │1 30:   movq   $0x3,-0x18(%rbp)
  0.03 │1 38:   mov    -0x18(%rbp),%rax
  0.03 │        mov    -0x10(%rbp),%rcx
       │        shr    $0x1,%rcx
  3.63 │     ┌──cmp    %rcx,%rax
       │     ├──jae    6f
       │     │                if (num % i == 0)
  0.03 │     │  mov    -0x10(%rbp),%rax
       │     │  xor    %edx,%edx
 89.00 │     │  divq   -0x18(%rbp)
       │     │  cmp    $0x0,%rdx
  0.22 │     │↓ jne    5f
       │     │                        return false;
       │     │  movb   $0x0,-0x1(%rbp)
       │     │↓ jmp    73
       │     │        }
  3.22 │1 5f:│↓ jmp    61
       │     │        for(uint64_t i = 3; i < num / 2; i+= 2) {

Subscribers: mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D44892

llvm-svn: 337789
2018-07-24 00:54:06 +00:00
..
Transforms [UnrollAndJam] New Unroll and Jam pass 2018-07-01 12:47:30 +00:00
Analysis.h Reorganize the C API headers to improve build times. 2015-12-18 01:46:52 +00:00
BitReader.h Deprecate a few C APIs. 2015-12-18 23:46:42 +00:00
BitWriter.h Reorganize the C API headers to improve build times. 2015-12-18 01:46:52 +00:00
Comdat.h [LLVM-C] [bindings/go] Add C and Golang bindings for COMDAT 2018-03-14 18:33:53 +00:00
Core.h [LLVM-C] Improve Bindings For Aliases 2018-05-20 23:49:08 +00:00
DataTypes.h Assume existence of inttypes.h and stdint.h in DataTypes.h. 2018-04-02 13:22:26 +00:00
DebugInfo.h [DebugInfo] Add a new DI flag to record if a C++ record is a trivial type 2018-07-21 05:42:13 +00:00
Disassembler.h Split Disassembler.h in two to fix dependencies 2018-03-29 00:29:44 +00:00
DisassemblerTypes.h Split Disassembler.h in two to fix dependencies 2018-03-29 00:29:44 +00:00
ErrorHandling.h Make some headers self-contained, remove unused includes that violate layering. 2016-01-27 16:05:37 +00:00
ExecutionEngine.h Add PerfJITEventListener for perf profiling support. 2018-07-24 00:54:06 +00:00
Initialization.h [AggressiveInstCombine] Add aggressive inst combiner to the LLVM C API. 2018-04-24 00:39:29 +00:00
IRReader.h Reorganize the C API headers to improve build times. 2015-12-18 01:46:52 +00:00
Linker.h Delete the deprecated LLVMLinkModules. 2016-02-12 15:28:45 +00:00
LinkTimeOptimizer.h
lto.h Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
module.modulemap
Object.h Reorganize the C API headers to improve build times. 2015-12-18 01:46:52 +00:00
OrcBindings.h [ORC][C-API] Expose LLVMOrc{Unr,R}egisterJITEventListener(). 2018-05-24 21:32:52 +00:00
Support.h Reapply Support layering fixes. 2018-03-21 17:31:49 +00:00
Target.h Move LLVMCreateTargetData and LLVMDisposeTargetData together. NFC 2016-02-17 22:41:09 +00:00
TargetMachine.h [LLVM-C] Add target triple normalization to the C API. 2018-07-17 10:57:39 +00:00
Types.h [ORC][C-API] Expose LLVMOrc{Unr,R}egisterJITEventListener(). 2018-05-24 21:32:52 +00:00