Skip to content

Commit 95e7843

Browse files
committed
[IRGen] Expose an -Xfrontend flag to disable the LLVM MergeFunctions pass
1 parent 3cc6314 commit 95e7843

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
@@ -371,6 +371,8 @@ class IRGenOptions {
371371
/// Emit names of struct stored properties and enum cases.
372372
unsigned EnableReflectionNames : 1;
373373

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

@@ -568,7 +570,8 @@ class IRGenOptions {
568570
SwiftAsyncFramePointer(SwiftAsyncFramePointerKind::Auto),
569571
HasValueNamesSetting(false), ValueNames(false),
570572
ReflectionMetadata(ReflectionMetadataMode::Runtime),
571-
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),
573+
EnableReflectionNames(true), DisableLLVMMergeFunctions(false),
574+
EnableAnonymousContextMangledNames(false),
572575
ForcePublicLinkage(false), LazyInitializeClassMetadata(false),
573576
LazyInitializeProtocolConformances(false),
574577
IndirectAsyncFunctionPointer(false),

include/swift/Option/FrontendOptions.td

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

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

lib/Frontend/CompilerInvocation.cpp

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

3347+
if (Args.hasArg(OPT_disable_llvm_merge_functions_pass)) {
3348+
Opts.DisableLLVMMergeFunctions = true;
3349+
}
3350+
33473351
if (Args.hasArg(OPT_force_public_linkage)) {
33483352
Opts.ForcePublicLinkage = true;
33493353
}

lib/IRGen/IRGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
260260
PTO.LoopInterleaving = true;
261261
PTO.LoopVectorization = true;
262262
PTO.SLPVectorization = true;
263-
PTO.MergeFunctions = true;
263+
PTO.MergeFunctions = !Opts.DisableLLVMMergeFunctions;
264264
// Splitting trades code size to enhance memory locality, avoid in -Osize.
265265
DoHotColdSplit = Opts.EnableHotColdSplit && !Opts.optimizeForSize();
266266
level = llvm::OptimizationLevel::Os;
@@ -361,7 +361,8 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
361361
allowlistFiles, ignorelistFiles));
362362
});
363363
}
364-
if (RunSwiftSpecificLLVMOptzns) {
364+
365+
if (RunSwiftSpecificLLVMOptzns && !Opts.DisableLLVMMergeFunctions) {
365366
PB.registerOptimizerLastEPCallback(
366367
[&](ModulePassManager &MPM, OptimizationLevel Level) {
367368
if (Level != OptimizationLevel::O0) {

0 commit comments

Comments
 (0)