[InstrProf] Temporal Profiling
authorEllis Hoag <ellis.sparky.hoag@gmail.com>
Tue, 11 Apr 2023 14:58:47 +0000 (07:58 -0700)
committerEllis Hoag <ellis.sparky.hoag@gmail.com>
Tue, 11 Apr 2023 15:30:52 +0000 (08:30 -0700)
commit244be0b0de198fbe8a0861bb8f75509f610b57a4
tree9182f8398c1bb41b9fb290fce766baeba4ea8386
parentd288411c8aef1820366d477aa8f90ed6a52d70ee
[InstrProf] Temporal Profiling

As described in [0], this extends IRPGO to support //Temporal Profiling//.

When `-pgo-temporal-instrumentation` is used we add the `llvm.instrprof.timestamp()` intrinsic to the entry of functions which in turn gets lowered to a call to the compiler-rt function `INSTR_PROF_PROFILE_SET_TIMESTAMP()`. A new field in the `llvm_prf_cnts` section stores each function's timestamp. Then in `llvm-profdata merge` we convert these function timestamps into a //trace// and add it to the indexed profile.

Since these traces could significantly increase the profile size, we've added `-max-temporal-profile-trace-length` and `-temporal-profile-trace-reservoir-size` to limit the length of a trace and the number of traces in a profile, respectively.

In a future diff we plan to use these traces to construct an optimized function order to reduce the number of page faults during startup.

Special thanks to Julian Mestre for helping with reservoir sampling.

[0] https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068

Reviewed By: snehasish

Differential Revision: https://reviews.llvm.org/D147287
25 files changed:
compiler-rt/include/profile/InstrProfData.inc
compiler-rt/lib/profile/InstrProfiling.c
compiler-rt/test/profile/instrprof-timestamp.c [new file with mode: 0644]
llvm/docs/LangRef.rst
llvm/include/llvm/IR/IntrinsicInst.h
llvm/include/llvm/IR/Intrinsics.td
llvm/include/llvm/ProfileData/InstrProf.h
llvm/include/llvm/ProfileData/InstrProfData.inc
llvm/include/llvm/ProfileData/InstrProfReader.h
llvm/include/llvm/ProfileData/InstrProfWriter.h
llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/ProfileData/InstrProfReader.cpp
llvm/lib/ProfileData/InstrProfWriter.cpp
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Instrumentation/InstrProfiling/timestamp-coverage.ll [new file with mode: 0644]
llvm/test/Instrumentation/InstrProfiling/timestamp.ll [new file with mode: 0644]
llvm/test/Transforms/PGOProfile/timestamp.ll [new file with mode: 0644]
llvm/test/tools/llvm-profdata/merge-traces.proftext [new file with mode: 0644]
llvm/test/tools/llvm-profdata/read-traces.proftext [new file with mode: 0644]
llvm/test/tools/llvm-profdata/trace-limit.proftext [new file with mode: 0644]
llvm/tools/llvm-profdata/llvm-profdata.cpp
llvm/unittests/ProfileData/InstrProfTest.cpp