<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55528>55528</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [ORC] Perf profiling integration not working in lli
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tetzank
      </td>
    </tr>
</table>

<pre>
    The `perf` profiling integration in `lli` does not work with the ORC jit engine. There are no JitDump files created in ~/.debug/jit/. Hence, `perf report` does not know function addresses and boundaries of jitted code.

The following steps work for MCJIT (--jit-kind=mcjit), but not ORC. LLVM needs to be build with perf support: LLVM_USE_PERF=ON.

Simple C program *pi.c* to test profiling:
```C
#include <stdlib.h>
#include <stdio.h>

static double pi(size_t n){
        double res = 4.0;
        for(size_t i=0,v=3; i<n; ++i,v+=4){
                res -= 4.0 / (v);
                res += 4.0 / (v+2);
        }
        return res;
}

int main(int argc, char *argv[]){
        if(argc != 2){
                puts("requires n as input");
                return -1;
        }
        size_t n = atoi(argv[1]);
        double p = pi(n);
        printf("%lu: %f\n", n, p);
        return 0;
}
```
Convert to LLVM IR:
`$ clang -S -emit-llvm pi.c -o pi.ll`

Profile execution:
```
$ perf record -k 1 lli --jit-kind=mcjit pi.ll 100000000
$ perf inject -j -i perf.data -o perf.data.jitted
$ perf report -i perf.data.jitted
```
Without `--jit-kind=mcjit`, ORC is used by default which does not produce dump files. Therefore, `perf report` does not know about the jitted code.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVdty2zYQ_RrqZYccChR1edCDLdnTZJLGE6fto4cklhJsCGAB0G7y9dkFKduy1bQaisRld3H2dlBb-X39bY-QzPMOXUsf6JxtlVZmB8oE3LkqKGtozDJaKxaRFj0YG-DJugd4UmEPgYx8-bqBexUAzU4ZzIAMO4SK_sbCRxW2_aEDsk3KjcMqoIxmF1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