1dff0c46cSDimitry Andric //===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==// 2dff0c46cSDimitry Andric // 3dff0c46cSDimitry Andric // The LLVM Compiler Infrastructure 4dff0c46cSDimitry Andric // 5dff0c46cSDimitry Andric // This file is distributed under the University of Illinois Open Source 6dff0c46cSDimitry Andric // License. See LICENSE.TXT for details. 7dff0c46cSDimitry Andric // 8dff0c46cSDimitry Andric //===----------------------------------------------------------------------===// 9dff0c46cSDimitry Andric // 10dff0c46cSDimitry Andric // This file implements the methods in the TargetOptions. 11dff0c46cSDimitry Andric // 12dff0c46cSDimitry Andric //===----------------------------------------------------------------------===// 13dff0c46cSDimitry Andric 14dff0c46cSDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h" 1591bc56edSDimitry Andric #include "llvm/CodeGen/MachineFunction.h" 162cab237bSDimitry Andric #include "llvm/CodeGen/TargetFrameLowering.h" 172cab237bSDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h" 18db17bf38SDimitry Andric #include "llvm/IR/Function.h" 19db17bf38SDimitry Andric #include "llvm/IR/Module.h" 20dff0c46cSDimitry Andric #include "llvm/Target/TargetOptions.h" 21dff0c46cSDimitry Andric using namespace llvm; 22dff0c46cSDimitry Andric 23dff0c46cSDimitry Andric /// DisableFramePointerElim - This returns true if frame pointer elimination 24dff0c46cSDimitry Andric /// optimization should be disabled for the given machine function. DisableFramePointerElim(const MachineFunction & MF) const25dff0c46cSDimitry Andricbool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const { 26*b5893f02SDimitry Andric // Check to see if the target want to forcably keep frame pointer. 27*b5893f02SDimitry Andric if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF)) 28*b5893f02SDimitry Andric return true; 29*b5893f02SDimitry Andric 30*b5893f02SDimitry Andric const Function &F = MF.getFunction(); 31*b5893f02SDimitry Andric 32*b5893f02SDimitry Andric // TODO: Remove support for old `fp elim` function attributes after fully 33*b5893f02SDimitry Andric // migrate to use "frame-pointer" 34*b5893f02SDimitry Andric if (!F.hasFnAttribute("frame-pointer")) { 35ff0cc061SDimitry Andric // Check to see if we should eliminate all frame pointers. 36*b5893f02SDimitry Andric if (F.getFnAttribute("no-frame-pointer-elim").getValueAsString() == "true") 37ff0cc061SDimitry Andric return true; 38dff0c46cSDimitry Andric 39ff0cc061SDimitry Andric // Check to see if we should eliminate non-leaf frame pointers. 40*b5893f02SDimitry Andric if (F.hasFnAttribute("no-frame-pointer-elim-non-leaf")) 41d88c1a5aSDimitry Andric return MF.getFrameInfo().hasCalls(); 42ff0cc061SDimitry Andric 43ff0cc061SDimitry Andric return false; 44dff0c46cSDimitry Andric } 45dff0c46cSDimitry Andric 46*b5893f02SDimitry Andric StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString(); 47*b5893f02SDimitry Andric if (FP == "all") 48*b5893f02SDimitry Andric return true; 49*b5893f02SDimitry Andric if (FP == "non-leaf") 50*b5893f02SDimitry Andric return MF.getFrameInfo().hasCalls(); 51*b5893f02SDimitry Andric if (FP == "none") 52*b5893f02SDimitry Andric return false; 53*b5893f02SDimitry Andric llvm_unreachable("unknown frame pointer flag"); 54*b5893f02SDimitry Andric } 55*b5893f02SDimitry Andric 56dff0c46cSDimitry Andric /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume 57dff0c46cSDimitry Andric /// that the rounding mode of the FPU can change from its default. HonorSignDependentRoundingFPMath() const58dff0c46cSDimitry Andricbool TargetOptions::HonorSignDependentRoundingFPMath() const { 59dff0c46cSDimitry Andric return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; 60dff0c46cSDimitry Andric } 61