Add option to disable leaf frame pointer elimination

This commit is contained in:
Arnold Schwaighofer
2020-05-21 07:52:00 -07:00
parent e155f03e0d
commit 109813ffe5
6 changed files with 27 additions and 1 deletions

View File

@@ -191,6 +191,7 @@ public:
unsigned DisableLLVMSLPVectorizer : 1;
/// Disable frame pointer elimination?
unsigned DisableFPElimLeaf : 1;
unsigned DisableFPElim : 1;
/// Special codegen for playgrounds.
@@ -319,6 +320,7 @@ public:
DisableClangModuleSkeletonCUs(false), UseJIT(false),
DisableLLVMOptzns(false),
DisableSwiftSpecificLLVMOptzns(false), DisableLLVMSLPVectorizer(false),
DisableFPElimLeaf(false),
DisableFPElim(true), Playground(false), EmitStackPromotionChecks(false),
FunctionSections(false), PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None),
HasValueNamesSetting(false), ValueNames(false),

View File

@@ -1010,6 +1010,10 @@ def enable_private_imports : Flag<["-"], "enable-private-imports">,
Flags<[FrontendOption, NoInteractiveOption, HelpHidden]>,
HelpText<"Allows this module's internal and private API to be accessed">;
def disable_leaf_frame_pointer_elim : Flag<["-"], "no-omit-leaf-frame-pointer">,
Flags<[FrontendOption, NoInteractiveOption, HelpHidden]>,
HelpText<"Don't omit the frame pointer for leaf functions">;
def sanitize_EQ : CommaJoined<["-"], "sanitize=">,
Flags<[FrontendOption, NoInteractiveOption]>, MetaVarName<"<check>">,
HelpText<"Turn on runtime checks for erroneous behavior.">;

View File

@@ -287,6 +287,8 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
arguments.push_back("-enable-anonymous-context-mangled-names");
}
inputArgs.AddLastArg(arguments, options::OPT_disable_leaf_frame_pointer_elim);
// Pass through any subsystem flags.
inputArgs.AddAllArgs(arguments, options::OPT_Xllvm);
inputArgs.AddAllArgs(arguments, options::OPT_Xcc);

View File

@@ -1511,6 +1511,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
getRuntimeCompatVersion();
}
if (Args.hasArg(OPT_disable_leaf_frame_pointer_elim))
Opts.DisableFPElimLeaf = true;
return false;
}

View File

@@ -988,7 +988,8 @@ bool swift::irgen::shouldRemoveTargetFeature(StringRef feature) {
void IRGenModule::setHasFramePointer(llvm::AttrBuilder &Attrs,
bool HasFramePointer) {
Attrs.addAttribute("frame-pointer", HasFramePointer ? "non-leaf" : "none");
auto UseFramePointer = IRGen.Opts.DisableFPElimLeaf ? "all" : "non-leaf";
Attrs.addAttribute("frame-pointer", HasFramePointer ? UseFramePointer : "none");
}
void IRGenModule::setHasFramePointer(llvm::Function *F,

View File

@@ -1,4 +1,5 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CHECK
// RUN: %target-swift-frontend -primary-file %s -emit-ir -no-omit-leaf-frame-pointer| %FileCheck %s --check-prefix=CHECK-ALL
// RUN: %target-swift-frontend -primary-file %s -S | %FileCheck %s --check-prefix=CHECKASM --check-prefix=CHECKASM-%target-os-%target-cpu
sil_stage canonical
@@ -30,6 +31,19 @@ entry(%i : $Int32):
// CHECK: attributes [[ATTR]] = {{{.*}}"frame-pointer"="non-leaf"
// CHECK-ALL: define{{.*}} swiftcc i32 @leaf_function_no_frame_pointer(i32 %0) [[ATTR:#.*]] {
// CHECK-ALL: entry:
// CHECK-ALL: ret i32 %0
// CHECK-ALL: }
// CHECK-ALL: define{{.*}} swiftcc i32 @non_leaf_function_with_frame_pointer(i32 %0) [[ATTR]] {
// CHECK-ALL: entry:
// CHECK-ALL: %1 = call swiftcc i32 @leaf_function_no_frame_pointer(i32 %0)
// CHECK-ALL: ret i32 %1
// CHECK-ALL: }
// CHECK-ALL: attributes [[ATTR]] = {{{.*}}"frame-pointer"="all"
// Silence other os-archs.
// CHECKASM: {{.*}}