diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index 3c38b98f7ba44..32f32734767a6 100644 --- a/include/swift/AST/IRGenOptions.h +++ b/include/swift/AST/IRGenOptions.h @@ -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; @@ -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), diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td index cc597a0c83955..ab2a7832d8d54 100644 --- a/include/swift/Option/FrontendOptions.td +++ b/include/swift/Option/FrontendOptions.td @@ -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.">; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 59c54398e17ba..04c30fd64c755 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -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; } diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index 882a5d79ed7a4..388328b950338 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -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; @@ -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) {