Restore "[MemProf] Context disambiguation cloning pass [patch 1a/3]"
authorTeresa Johnson <tejohnson@google.com>
Wed, 22 Mar 2023 17:01:45 +0000 (10:01 -0700)
committerTeresa Johnson <tejohnson@google.com>
Wed, 22 Mar 2023 17:16:06 +0000 (10:16 -0700)
commit700cd99061edeeba7b657e32acca940225fa25ae
tree2a1327fe95a930920d46abaae2d21dfddf109810
parenta67e989cd2a730ea778102f2a0d965daed0182bd
Restore "[MemProf] Context disambiguation cloning pass [patch 1a/3]"

This restores commit d6ad4f01c3dafcab335bca66dac6e36d9eac8421, which was
reverted in commit 883dbb9c86be87593a58ef10b070b3a0564c7fee, along with
a fix for gcc 12.2 build errors in the original commit.

Support for building, printing, and displaying CallsiteContextGraph
which represents the MemProf metadata contexts. Uses CRTP to enable
support for both IR (regular LTO) and summary (ThinLTO). This patch
includes the support for building it in regular LTO mode (from
memprof and callsite metadata), and the next patch will add the
handling for building it from ThinLTO summaries.

Also includes support for dumping the graph to text and to dot files.

Follow-on patches will contain the support for cloning on the graph and
in the IR.

The graph represents the call contexts in all memprof metadata on
allocation calls, with nodes for the allocations themselves, as well as
for the calls in each context. The graph is initially built from the
allocation memprof metadata (or summary) MIBs. It is then updated to
match calls with callsite metadata onto the nodes, updating it to
reflect any inlining performed on those calls.

Each MIB (representing an allocation's call context with allocation
behavior) is assigned a unique context id during the graph build. The
edges and nodes in the graph are decorated with the context ids they
carry. This is used to correctly update the graph when cloning is
performed so that we can uniquify the context for a single (possibly
cloned) allocation.

Differential Revision: https://reviews.llvm.org/D140908
14 files changed:
llvm/include/llvm/Transforms/IPO/MemProfContextDisambiguation.h [new file with mode: 0644]
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/IPO/CMakeLists.txt
llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp [new file with mode: 0644]
llvm/test/ThinLTO/X86/memprof-summary.ll [deleted file]
llvm/test/Transforms/MemProfContextDisambiguation/basic.ll [new file with mode: 0644]
llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids.ll [new file with mode: 0644]
llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll [new file with mode: 0644]
llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll [new file with mode: 0644]
llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll [new file with mode: 0644]
llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll [new file with mode: 0644]
llvm/test/Transforms/MemProfContextDisambiguation/pass-pipeline.ll [new file with mode: 0644]