Skip to content

[IRGen] Expose an -Xfrontend flag to disable the LLVM MergeFunctions pass #79546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/swift/AST/IRGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ class IRGenOptions {
/// Emit names of struct stored properties and enum cases.
unsigned EnableReflectionNames : 1;

unsigned DisableLLVMMergeFunctions : 1;

/// Emit mangled names of anonymous context descriptors.
unsigned EnableAnonymousContextMangledNames : 1;

Expand Down Expand Up @@ -574,7 +576,8 @@ class IRGenOptions {
SwiftAsyncFramePointer(SwiftAsyncFramePointerKind::Auto),
HasValueNamesSetting(false), ValueNames(false),
ReflectionMetadata(ReflectionMetadataMode::Runtime),
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),
EnableReflectionNames(true), DisableLLVMMergeFunctions(false),
EnableAnonymousContextMangledNames(false),
ForcePublicLinkage(false), LazyInitializeClassMetadata(false),
LazyInitializeProtocolConformances(false),
IndirectAsyncFunctionPointer(false),
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ def disable_reflection_names : Flag<["-"], "disable-reflection-names">,
HelpText<"Disable emission of names of stored properties and enum cases in"
"reflection metadata">;

def disable_llvm_merge_functions_pass : Flag<["-"], "disable-llvm-merge-functions-pass">,
HelpText<"Disable the MergeFunctionPass LLVM IR pass">;

def function_sections: Flag<["-"], "function-sections">,
Flags<[FrontendOption, NoInteractiveOption]>,
HelpText<"Emit functions to separate sections.">;
Expand Down
4 changes: 4 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3406,6 +3406,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
Opts.EnableReflectionNames = false;
}

if (Args.hasArg(OPT_disable_llvm_merge_functions_pass)) {
Opts.DisableLLVMMergeFunctions = true;
}

if (Args.hasArg(OPT_force_public_linkage)) {
Opts.ForcePublicLinkage = true;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
PTO.LoopInterleaving = true;
PTO.LoopVectorization = true;
PTO.SLPVectorization = true;
PTO.MergeFunctions = true;
PTO.MergeFunctions = !Opts.DisableLLVMMergeFunctions;
// Splitting trades code size to enhance memory locality, avoid in -Osize.
DoHotColdSplit = Opts.EnableHotColdSplit && !Opts.optimizeForSize();
level = llvm::OptimizationLevel::Os;
Expand Down Expand Up @@ -388,7 +388,8 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
allowlistFiles, ignorelistFiles));
});
}
if (RunSwiftSpecificLLVMOptzns) {

if (RunSwiftSpecificLLVMOptzns && !Opts.DisableLLVMMergeFunctions) {
PB.registerOptimizerLastEPCallback(
[&](ModulePassManager &MPM, OptimizationLevel Level) {
if (Level != OptimizationLevel::O0) {
Expand Down