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.
34 lines
1.9 KiB
TableGen
34 lines
1.9 KiB
TableGen
include "llvm/Option/OptParser.td"
|
|
|
|
class F<string letter, string help> : Flag<["-"], letter>, HelpText<help>;
|
|
class FF<string name, string help> : Flag<["--"], name>, HelpText<help>;
|
|
|
|
// General options
|
|
def generic_group : OptionGroup<"Genric Options">, HelpText<"Generic Options">;
|
|
def help : FF<"help", "Display this help">, Group<generic_group>;
|
|
def : F<"h", "Alias for --help">, Alias<help>, Group<generic_group>;
|
|
def version : FF<"version", "Display the LLVM version">, Group<generic_group>;
|
|
def : F<"v", "Alias for --version">, Alias<version>, Group<generic_group>;
|
|
|
|
// Action options
|
|
def action_group : OptionGroup<"Action">, HelpText<"Action (required)">;
|
|
def show : FF<"show", "Show summary of the (indexed) codegen data file.">,
|
|
Group<action_group>;
|
|
def : F<"s", "Alias for --show">, Alias<show>, Group<action_group>;
|
|
def convert : FF<"convert", "Convert the (indexed) codegen data file in either text or binary format.">,
|
|
Group<action_group>;
|
|
def : F<"c", "Alias for --convert">, Alias<convert>, Group<action_group>;
|
|
def merge : FF<"merge", "Take binary files having raw codegen data in custom sections, and merge them into an indexed codegen data file.">,
|
|
Group<action_group>;
|
|
def : F<"m", "Alias for --merge">, Alias<merge>, Group<action_group>;
|
|
|
|
// Additional options
|
|
def cgdata_version : FF<"cgdata-version", "Display the cgdata version">;
|
|
def skip_trim : FF<"skip-trim", "Skip trimming content when merging the cgdata">;
|
|
def output : Option<["--"], "output", KIND_SEPARATE>,
|
|
HelpText<"Specify the name for the output file to be created">, MetaVarName<"<file>">;
|
|
def : JoinedOrSeparate<["-"], "o">, Alias<output>, MetaVarName<"<file>">, HelpText<"Alias for --output">;
|
|
def format : Option<["--"], "format", KIND_SEPARATE>,
|
|
HelpText<"Specify the output format (text or binary)">, MetaVarName<"<value>">;
|
|
def : JoinedOrSeparate<["-"], "f">, Alias<format>, HelpText<"Alias for --format">;
|