1 //===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the methods in the TargetOptions.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MachineFrameInfo.h"
15 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/CodeGen/TargetFrameLowering.h"
17 #include "llvm/CodeGen/TargetSubtargetInfo.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/Target/TargetOptions.h"
23 /// DisableFramePointerElim - This returns true if frame pointer elimination
24 /// optimization should be disabled for the given machine function.
25 bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
26 // Check to see if the target want to forcably keep frame pointer.
27 if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))
30 const Function &F = MF.getFunction();
32 // TODO: Remove support for old `fp elim` function attributes after fully
33 // migrate to use "frame-pointer"
34 if (!F.hasFnAttribute("frame-pointer")) {
35 // Check to see if we should eliminate all frame pointers.
36 if (F.getFnAttribute("no-frame-pointer-elim").getValueAsString() == "true")
39 // Check to see if we should eliminate non-leaf frame pointers.
40 if (F.hasFnAttribute("no-frame-pointer-elim-non-leaf"))
41 return MF.getFrameInfo().hasCalls();
46 StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
50 return MF.getFrameInfo().hasCalls();
53 llvm_unreachable("unknown frame pointer flag");
56 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
57 /// that the rounding mode of the FPU can change from its default.
58 bool TargetOptions::HonorSignDependentRoundingFPMath() const {
59 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;