From f245ae5a4a78d5a02b3b9e2dae819077a56d81e7 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 25 Jul 2013 00:34:29 +0000 Subject: [PATCH] Replace the "NoFramePointerElimNonLeaf" target option with a function attribute. There's no need to specify a flag to omit frame pointer elimination on non-leaf nodes...(Honestly, I can't parse that option out.) Use the function attribute stuff instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187093 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/CommandFlags.h | 5 -- include/llvm/Target/TargetOptions.h | 8 +-- lib/CodeGen/TargetOptionsImpl.cpp | 4 ++ lib/IR/Attributes.cpp | 4 ++ lib/Target/TargetMachine.cpp | 1 - test/CodeGen/X86/fp-elim.ll | 74 ++++++++++++-------- test/CodeGen/X86/leaf-fp-elim.ll | 4 +- test/DebugInfo/2010-05-03-DisableFramePtr.ll | 4 +- tools/llc/llc.cpp | 1 - tools/lto/LTOModule.cpp | 6 -- tools/opt/opt.cpp | 1 - 11 files changed, 59 insertions(+), 53 deletions(-) diff --git a/include/llvm/CodeGen/CommandFlags.h b/include/llvm/CodeGen/CommandFlags.h index fd1d67bdcd1..22bea34d78d 100644 --- a/include/llvm/CodeGen/CommandFlags.h +++ b/include/llvm/CodeGen/CommandFlags.h @@ -109,11 +109,6 @@ DisableFPElim("disable-fp-elim", cl::desc("Disable frame pointer elimination optimization"), cl::init(false)); -cl::opt -DisableFPElimNonLeaf("disable-non-leaf-fp-elim", - cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"), - cl::init(false)); - cl::opt EnableUnsafeFPMath("enable-unsafe-fp-math", cl::desc("Enable optimizations that may decrease FP precision"), diff --git a/include/llvm/Target/TargetOptions.h b/include/llvm/Target/TargetOptions.h index 04b20801066..feba3408f8a 100644 --- a/include/llvm/Target/TargetOptions.h +++ b/include/llvm/Target/TargetOptions.h @@ -42,7 +42,7 @@ namespace llvm { public: TargetOptions() : PrintMachineCode(false), NoFramePointerElim(false), - NoFramePointerElimNonLeaf(false), LessPreciseFPMADOption(false), + LessPreciseFPMADOption(false), UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false), HonorSignDependentRoundingFPMathOption(false), UseSoftFloat(false), NoZerosInBSS(false), @@ -64,12 +64,6 @@ namespace llvm { /// elimination optimization, this option should disable it. unsigned NoFramePointerElim : 1; - /// NoFramePointerElimNonLeaf - This flag is enabled when the - /// -disable-non-leaf-fp-elim is specified on the command line. If the - /// target supports the frame pointer elimination optimization, this option - /// should disable it for non-leaf functions. - unsigned NoFramePointerElimNonLeaf : 1; - /// DisableFramePointerElim - This returns true if frame pointer elimination /// optimization should be disabled for the given machine function. bool DisableFramePointerElim(const MachineFunction &MF) const; diff --git a/lib/CodeGen/TargetOptionsImpl.cpp b/lib/CodeGen/TargetOptionsImpl.cpp index b5d4160f939..7a39a4c2737 100644 --- a/lib/CodeGen/TargetOptionsImpl.cpp +++ b/lib/CodeGen/TargetOptionsImpl.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/IR/Function.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/Target/TargetOptions.h" @@ -21,6 +22,9 @@ using namespace llvm; bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const { // Check to see if we should eliminate non-leaf frame pointers and then // check to see if we should eliminate all frame pointers. + bool NoFramePointerElimNonLeaf = + MF.getFunction()->getFnAttribute("no-frame-pointer-elim-non-leaf") + .getValueAsString() == "true"; if (NoFramePointerElimNonLeaf && !NoFramePointerElim) { const MachineFrameInfo *MFI = MF.getFrameInfo(); return MFI->hasCalls(); diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index c8e2f6be5c0..48743fae692 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -104,24 +104,28 @@ bool Attribute::isStringAttribute() const { } Attribute::AttrKind Attribute::getKindAsEnum() const { + if (!pImpl) return None; assert((isEnumAttribute() || isAlignAttribute()) && "Invalid attribute type to get the kind as an enum!"); return pImpl ? pImpl->getKindAsEnum() : None; } uint64_t Attribute::getValueAsInt() const { + if (!pImpl) return 0; assert(isAlignAttribute() && "Expected the attribute to be an alignment attribute!"); return pImpl ? pImpl->getValueAsInt() : 0; } StringRef Attribute::getKindAsString() const { + if (!pImpl) return StringRef(); assert(isStringAttribute() && "Invalid attribute type to get the kind as a string!"); return pImpl ? pImpl->getKindAsString() : StringRef(); } StringRef Attribute::getValueAsString() const { + if (!pImpl) return StringRef(); assert(isStringAttribute() && "Invalid attribute type to get the value as a string!"); return pImpl ? pImpl->getValueAsString() : StringRef(); diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp index e7282519d59..df4a03c9e8b 100644 --- a/lib/Target/TargetMachine.cpp +++ b/lib/Target/TargetMachine.cpp @@ -78,7 +78,6 @@ void TargetMachine::resetTargetOptions(const MachineFunction *MF) const { } while (0) RESET_OPTION(NoFramePointerElim, "no-frame-pointer-elim"); - RESET_OPTION(NoFramePointerElimNonLeaf, "no-frame-pointer-elim-non-leaf"); RESET_OPTION(LessPreciseFPMADOption, "less-precise-fpmad"); RESET_OPTION(UnsafeFPMath, "unsafe-fp-math"); RESET_OPTION(NoInfsFPMath, "no-infs-fp-math"); diff --git a/test/CodeGen/X86/fp-elim.ll b/test/CodeGen/X86/fp-elim.ll index d43ee36143b..583388cc713 100644 --- a/test/CodeGen/X86/fp-elim.ll +++ b/test/CodeGen/X86/fp-elim.ll @@ -1,42 +1,60 @@ ; RUN: llc < %s -march=x86 -asm-verbose=false | FileCheck %s -check-prefix=FP-ELIM ; RUN: llc < %s -march=x86 -asm-verbose=false -disable-fp-elim | FileCheck %s -check-prefix=NO-ELIM -; RUN: llc < %s -march=x86 -asm-verbose=false -disable-non-leaf-fp-elim | FileCheck %s -check-prefix=NON-LEAF ; Implement -momit-leaf-frame-pointer ; rdar://7886181 -define i32 @t1() nounwind readnone { +define i32 @t1() "no-frame-pointer-elim-non-leaf"="false" nounwind readnone { entry: -; FP-ELIM-LABEL: t1: -; FP-ELIM-NEXT: movl -; FP-ELIM-NEXT: ret - -; NO-ELIM-LABEL: t1: -; NO-ELIM-NEXT: pushl %ebp -; NO-ELIM: popl %ebp -; NO-ELIM-NEXT: ret - -; NON-LEAF-LABEL: t1: -; NON-LEAF-NEXT: movl -; NON-LEAF-NEXT: ret +; FP-ELIM-LABEL: t1: +; FP-ELIM-NEXT: movl +; FP-ELIM-NEXT: ret + +; NO-ELIM-LABEL: t1: +; NO-ELIM-NEXT: pushl %ebp +; NO-ELIM: popl %ebp +; NO-ELIM-NEXT: ret ret i32 10 } -define void @t2() nounwind { +define void @t2() "no-frame-pointer-elim-non-leaf"="false" nounwind { entry: -; FP-ELIM-LABEL: t2: -; FP-ELIM-NOT: pushl %ebp -; FP-ELIM: ret - -; NO-ELIM-LABEL: t2: -; NO-ELIM-NEXT: pushl %ebp -; NO-ELIM: popl %ebp -; NO-ELIM-NEXT: ret - -; NON-LEAF-LABEL: t2: -; NON-LEAF-NEXT: pushl %ebp -; NON-LEAF: popl %ebp -; NON-LEAF-NEXT: ret +; FP-ELIM-LABEL: t2: +; FP-ELIM-NOT: pushl %ebp +; FP-ELIM: ret + +; NO-ELIM-LABEL: t2: +; NO-ELIM-NEXT: pushl %ebp +; NO-ELIM: popl %ebp +; NO-ELIM-NEXT: ret + tail call void @foo(i32 0) nounwind + ret void +} + +define i32 @t3() "no-frame-pointer-elim-non-leaf"="true" nounwind readnone { +entry: +; FP-ELIM-LABEL: t3: +; FP-ELIM-NEXT: movl +; FP-ELIM-NEXT: ret + +; NO-ELIM-LABEL: t3: +; NO-ELIM-NEXT: pushl %ebp +; NO-ELIM: popl %ebp +; NO-ELIM-NEXT: ret + ret i32 10 +} + +define void @t4() "no-frame-pointer-elim-non-leaf"="true" nounwind { +entry: +; FP-ELIM-LABEL: t4: +; FP-ELIM-NEXT: pushl %ebp +; FP-ELIM: popl %ebp +; FP-ELIM-NEXT: ret + +; NO-ELIM-LABEL: t4: +; NO-ELIM-NEXT: pushl %ebp +; NO-ELIM: popl %ebp +; NO-ELIM-NEXT: ret tail call void @foo(i32 0) nounwind ret void } diff --git a/test/CodeGen/X86/leaf-fp-elim.ll b/test/CodeGen/X86/leaf-fp-elim.ll index 607dc72e2fa..7eebf8d2924 100644 --- a/test/CodeGen/X86/leaf-fp-elim.ll +++ b/test/CodeGen/X86/leaf-fp-elim.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -disable-non-leaf-fp-elim -relocation-model=pic -mtriple=x86_64-apple-darwin | FileCheck %s +; RUN: llc < %s -relocation-model=pic -mtriple=x86_64-apple-darwin | FileCheck %s ; target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-apple-darwin11.0" @@ -6,7 +6,7 @@ target triple = "x86_64-apple-darwin11.0" @msg = internal global i8* null ; [#uses=1] @.str = private constant [2 x i8] c"x\00", align 1 ; <[2 x i8]*> [#uses=1] -define void @test(i8* %p) nounwind optsize ssp { +define void @test(i8* %p) "no-frame-pointer-elim-non-leaf"="true" nounwind optsize ssp { ; No stack frame, please. ; CHECK: _test diff --git a/test/DebugInfo/2010-05-03-DisableFramePtr.ll b/test/DebugInfo/2010-05-03-DisableFramePtr.ll index ec734f65cc3..7e07067f42f 100644 --- a/test/DebugInfo/2010-05-03-DisableFramePtr.ll +++ b/test/DebugInfo/2010-05-03-DisableFramePtr.ll @@ -1,8 +1,8 @@ -; RUN: llc -o /dev/null -disable-non-leaf-fp-elim < %s +; RUN: llc -o /dev/null < %s ; Radar 7937664 %struct.AppleEvent = type opaque -define void @DisposeDMNotificationUPP(void (%struct.AppleEvent*)* %userUPP) nounwind ssp { +define void @DisposeDMNotificationUPP(void (%struct.AppleEvent*)* %userUPP) "no-frame-pointer-elim-non-leaf"="true" nounwind ssp { entry: %userUPP_addr = alloca void (%struct.AppleEvent*)* ; [#uses=1] %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index b62f41aec8a..c66106b5947 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -262,7 +262,6 @@ static int compileModule(char **argv, LLVMContext &Context) { TargetOptions Options; Options.LessPreciseFPMADOption = EnableFPMAD; Options.NoFramePointerElim = DisableFPElim; - Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf; Options.AllowFPOpFusion = FuseFPOps; Options.UnsafeFPMath = EnableUnsafeFPMath; Options.NoInfsFPMath = EnableNoInfsFPMath; diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 6626eaac47a..7aeadc3da43 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -49,11 +49,6 @@ DisableFPElim("disable-fp-elim", cl::desc("Disable frame pointer elimination optimization"), cl::init(false)); -static cl::opt -DisableFPElimNonLeaf("disable-non-leaf-fp-elim", - cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"), - cl::init(false)); - static cl::opt EnableUnsafeFPMath("enable-unsafe-fp-math", cl::desc("Enable optimizations that may decrease FP precision"), @@ -236,7 +231,6 @@ LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length, void LTOModule::getTargetOptions(TargetOptions &Options) { Options.LessPreciseFPMADOption = EnableFPMAD; Options.NoFramePointerElim = DisableFPElim; - Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf; Options.AllowFPOpFusion = FuseFPOps; Options.UnsafeFPMath = EnableUnsafeFPMath; Options.NoInfsFPMath = EnableNoInfsFPMath; diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 23acefafbee..68fca83c96a 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -491,7 +491,6 @@ static TargetOptions GetTargetOptions() { TargetOptions Options; Options.LessPreciseFPMADOption = EnableFPMAD; Options.NoFramePointerElim = DisableFPElim; - Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf; Options.AllowFPOpFusion = FuseFPOps; Options.UnsafeFPMath = EnableUnsafeFPMath; Options.NoInfsFPMath = EnableNoInfsFPMath; -- 2.34.1