Skip to content

Commit 11922d2

Browse files
Merge pull request #79546 from kubamracek/expose-flag-to-disable-merge-functions
[IRGen] Expose an -Xfrontend flag to disable the LLVM MergeFunctions pass
2 parents b577a13 + 119d6e2 commit 11922d2

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ class IRGenOptions {
372372
/// Emit names of struct stored properties and enum cases.
373373
unsigned EnableReflectionNames : 1;
374374

375+
unsigned DisableLLVMMergeFunctions : 1;
376+
375377
/// Emit mangled names of anonymous context descriptors.
376378
unsigned EnableAnonymousContextMangledNames : 1;
377379

@@ -577,7 +579,8 @@ class IRGenOptions {
577579
SwiftAsyncFramePointer(SwiftAsyncFramePointerKind::Auto),
578580
HasValueNamesSetting(false), ValueNames(false),
579581
ReflectionMetadata(ReflectionMetadataMode::Runtime),
580-
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),
582+
EnableReflectionNames(true), DisableLLVMMergeFunctions(false),
583+
EnableAnonymousContextMangledNames(false),
581584
ForcePublicLinkage(false), LazyInitializeClassMetadata(false),
582585
LazyInitializeProtocolConformances(false),
583586
IndirectAsyncFunctionPointer(false),

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ def disable_reflection_names : Flag<["-"], "disable-reflection-names">,
615615
HelpText<"Disable emission of names of stored properties and enum cases in"
616616
"reflection metadata">;
617617

618+
def disable_llvm_merge_functions_pass : Flag<["-"], "disable-llvm-merge-functions-pass">,
619+
HelpText<"Disable the MergeFunctionPass LLVM IR pass">;
620+
618621
def function_sections: Flag<["-"], "function-sections">,
619622
Flags<[FrontendOption, NoInteractiveOption]>,
620623
HelpText<"Emit functions to separate sections.">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,6 +3406,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
34063406
Opts.EnableReflectionNames = false;
34073407
}
34083408

3409+
if (Args.hasArg(OPT_disable_llvm_merge_functions_pass)) {
3410+
Opts.DisableLLVMMergeFunctions = true;
3411+
}
3412+
34093413
if (Args.hasArg(OPT_force_public_linkage)) {
34103414
Opts.ForcePublicLinkage = true;
34113415
}

lib/IRGen/IRGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
275275
PTO.LoopInterleaving = true;
276276
PTO.LoopVectorization = true;
277277
PTO.SLPVectorization = true;
278-
PTO.MergeFunctions = true;
278+
PTO.MergeFunctions = !Opts.DisableLLVMMergeFunctions;
279279
// Splitting trades code size to enhance memory locality, avoid in -Osize.
280280
DoHotColdSplit = Opts.EnableHotColdSplit && !Opts.optimizeForSize();
281281
level = llvm::OptimizationLevel::Os;
@@ -388,7 +388,8 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
388388
allowlistFiles, ignorelistFiles));
389389
});
390390
}
391-
if (RunSwiftSpecificLLVMOptzns) {
391+
392+
if (RunSwiftSpecificLLVMOptzns && !Opts.DisableLLVMMergeFunctions) {
392393
PB.registerOptimizerLastEPCallback(
393394
[&](ModulePassManager &MPM, OptimizationLevel Level) {
394395
if (Level != OptimizationLevel::O0) {

0 commit comments

Comments
 (0)