Add a counter-function insertion pass
authorHal Finkel <hfinkel@anl.gov>
Thu, 1 Sep 2016 09:42:39 +0000 (09:42 +0000)
committerHal Finkel <hfinkel@anl.gov>
Thu, 1 Sep 2016 09:42:39 +0000 (09:42 +0000)
commit40d7f5c27740f2f03e3d6731772aae073a927c7c
tree7114e24238df2b020f3b8d09acd847d94a334ae6
parent1ab16f8c2ddbaa1595002efe129c689e6ef8e75f
Add a counter-function insertion pass

As discussed in https://reviews.llvm.org/D22666, our current mechanism to
support -pg profiling, where we insert calls to mcount(), or some similar
function, is fundamentally broken. We insert these calls in the frontend, which
means they get duplicated when inlining, and so the accumulated execution
counts for the inlined-into functions are wrong.

Because we don't want the presence of these functions to affect optimizaton,
they should be inserted in the backend. Here's a pass which would do just that.
The knowledge of the name of the counting function lives in the frontend, so
we're passing it here as a function attribute. Clang will be updated to use
this mechanism.

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

llvm-svn: 280347
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/CountingFunctionInserter.cpp [new file with mode: 0644]
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/test/CodeGen/PowerPC/mcount-insertion.ll [new file with mode: 0644]
llvm/test/Transforms/CountingFunctionInserter/mcount.ll [new file with mode: 0644]
llvm/tools/llc/llc.cpp
llvm/tools/opt/opt.cpp