1 //===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the methods in the TargetOptions. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/IR/Function.h" 15 #include "llvm/IR/Module.h" 16 #include "llvm/CodeGen/MachineFrameInfo.h" 17 #include "llvm/CodeGen/MachineFunction.h" 18 #include "llvm/Target/TargetFrameLowering.h" 19 #include "llvm/Target/TargetOptions.h" 20 #include "llvm/Target/TargetSubtargetInfo.h" 21 using namespace llvm; 22 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 we should eliminate all frame pointers. 27 if (MF.getSubtarget().getFrameLowering()->noFramePointerElim(MF)) 28 return true; 29 30 // Check to see if we should eliminate non-leaf frame pointers. 31 if (MF.getFunction()->hasFnAttribute("no-frame-pointer-elim-non-leaf")) 32 return MF.getFrameInfo()->hasCalls(); 33 34 return false; 35 } 36 37 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option 38 /// is specified on the command line. When this flag is off(default), the 39 /// code generator is not allowed to generate mad (multiply add) if the 40 /// result is "less precise" than doing those operations individually. 41 bool TargetOptions::LessPreciseFPMAD() const { 42 return UnsafeFPMath || LessPreciseFPMADOption; 43 } 44 45 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume 46 /// that the rounding mode of the FPU can change from its default. 47 bool TargetOptions::HonorSignDependentRoundingFPMath() const { 48 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; 49 } 50 51 /// getTrapFunctionName - If this returns a non-empty string, this means isel 52 /// should lower Intrinsic::trap to a call to the specified function name 53 /// instead of an ISD::TRAP node. 54 StringRef TargetOptions::getTrapFunctionName() const { 55 return TrapFuncName; 56 } 57 58 59 void llvm::setFunctionAttributes(StringRef CPU, StringRef Features, 60 const TargetOptions &Options, Module &M, 61 bool AlwaysRecordAttrs) { 62 for (auto &F : M) { 63 auto &Ctx = F.getContext(); 64 AttributeSet Attrs = F.getAttributes(), NewAttrs; 65 66 if (!CPU.empty()) 67 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex, 68 "target-cpu", CPU); 69 70 if (!Features.empty()) 71 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex, 72 "target-features", Features); 73 74 if (Options.NoFramePointerElimOverride || AlwaysRecordAttrs) 75 NewAttrs = NewAttrs.addAttribute( 76 Ctx, AttributeSet::FunctionIndex, "no-frame-pointer-elim", 77 Options.NoFramePointerElim ? "true" : "false"); 78 79 // Let NewAttrs override Attrs. 80 NewAttrs = Attrs.addAttributes(Ctx, AttributeSet::FunctionIndex, NewAttrs); 81 F.setAttributes(NewAttrs); 82 } 83 } 84