aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-cgdata/llvm-cgdata.cpp
diff options
context:
space:
mode:
authorKyungwoo Lee <kyulee@meta.com>2024-11-13 17:34:07 -0800
committerGitHub <noreply@github.com>2024-11-13 17:34:07 -0800
commitd23c5c2d6566fce4380cfa31d438422db19fbce9 (patch)
treea50fe5074a1f87cfb437051b7627093f8a1d7139 /llvm/tools/llvm-cgdata/llvm-cgdata.cpp
parent6e614e11df6a152082b51a1b18332cb8730a4032 (diff)
downloadllvm-d23c5c2d6566fce4380cfa31d438422db19fbce9.zip
llvm-d23c5c2d6566fce4380cfa31d438422db19fbce9.tar.gz
llvm-d23c5c2d6566fce4380cfa31d438422db19fbce9.tar.bz2
[CGData] Global Merge Functions (#112671)
This implements a global function merging pass. Unlike traditional function merging passes that use IR comparators, this pass employs a structurally stable hash to identify similar functions while ignoring certain constant operands. These ignored constants are tracked and encoded into a stable function summary. When merging, instead of explicitly folding similar functions and their call sites, we form a merging instance by supplying different parameters via thunks. The actual size reduction occurs when identically created merging instances are folded by the linker. Currently, this pass is wired to a pre-codegen pass, enabled by the `-enable-global-merge-func` flag. In a local merging mode, the analysis and merging steps occur sequentially within a module: - `analyze`: Collects stable function hashes and tracks locations of ignored constant operands. - `finalize`: Identifies merge candidates with matching hashes and computes the set of parameters that point to different constants. - `merge`: Uses the stable function map to optimistically create a merged function. We can enable a global merging mode similar to the global function outliner (https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753/), which will perform the above steps separately. - `-codegen-data-generate`: During the first round of code generation, we analyze local merging instances and publish their summaries. - Offline using `llvm-cgdata` or at link-time, we can finalize all these merging summaries that are combined to determine parameters. - `-codegen-data-use`: During the second round of code generation, we optimistically create merging instances within each module, and finally, the linker folds identically created merging instances. Depends on #112664 This is a patch for https://discourse.llvm.org/t/rfc-global-function-merging/82608.
Diffstat (limited to 'llvm/tools/llvm-cgdata/llvm-cgdata.cpp')
-rw-r--r--llvm/tools/llvm-cgdata/llvm-cgdata.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/tools/llvm-cgdata/llvm-cgdata.cpp b/llvm/tools/llvm-cgdata/llvm-cgdata.cpp
index 0931cad..d33459b 100644
--- a/llvm/tools/llvm-cgdata/llvm-cgdata.cpp
+++ b/llvm/tools/llvm-cgdata/llvm-cgdata.cpp
@@ -76,6 +76,7 @@ static StringRef ToolName;
static StringRef OutputFilename = "-";
static StringRef Filename;
static bool ShowCGDataVersion;
+static bool SkipTrim;
static CGDataAction Action;
static std::optional<CGDataFormat> OutputFormat;
static std::vector<std::string> InputFilenames;
@@ -214,7 +215,7 @@ static int merge_main(int argc, const char *argv[]) {
if (!Result)
exitWithError("failed to merge codegen data files.");
- GlobalFunctionMapRecord.finalize();
+ GlobalFunctionMapRecord.finalize(SkipTrim);
CodeGenDataWriter Writer;
if (!GlobalOutlineRecord.empty())
@@ -301,6 +302,7 @@ static void parseArgs(int argc, char **argv) {
}
ShowCGDataVersion = Args.hasArg(OPT_cgdata_version);
+ SkipTrim = Args.hasArg(OPT_skip_trim);
if (opt::Arg *A = Args.getLastArg(OPT_format)) {
StringRef OF = A->getValue();