Nick Lewycky | 028700f | 2011-12-15 22:58:58 +0000 | [diff] [blame] | 1 | //===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==// |
Nick Lewycky | b3ffe10 | 2011-12-10 22:34:41 +0000 | [diff] [blame] | 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 | |
Nick Lewycky | b3ffe10 | 2011-12-10 22:34:41 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | 974a445 | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineFunction.h" |
David Blaikie | e3a9b4c | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/TargetFrameLowering.h" |
| 17 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Chandler Carruth | e3e43d9 | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Function.h" |
| 19 | #include "llvm/IR/Module.h" |
Nick Lewycky | b3ffe10 | 2011-12-10 22:34:41 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetOptions.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 { |
Francis Visoiu Mistrih | 08223c3 | 2019-01-14 10:55:55 +0000 | [diff] [blame] | 26 | // Check to see if the target want to forcably keep frame pointer. |
| 27 | if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF)) |
Akira Hatanaka | 0146120 | 2015-05-23 01:14:08 +0000 | [diff] [blame] | 28 | return true; |
Nick Lewycky | b3ffe10 | 2011-12-10 22:34:41 +0000 | [diff] [blame] | 29 | |
Francis Visoiu Mistrih | 08223c3 | 2019-01-14 10:55:55 +0000 | [diff] [blame] | 30 | const Function &F = MF.getFunction(); |
Akira Hatanaka | 0146120 | 2015-05-23 01:14:08 +0000 | [diff] [blame] | 31 | |
Francis Visoiu Mistrih | 08223c3 | 2019-01-14 10:55:55 +0000 | [diff] [blame] | 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") |
| 37 | return true; |
| 38 | |
| 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(); |
| 42 | |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString(); |
| 47 | if (FP == "all") |
| 48 | return true; |
| 49 | if (FP == "non-leaf") |
| 50 | return MF.getFrameInfo().hasCalls(); |
| 51 | if (FP == "none") |
| 52 | return false; |
| 53 | llvm_unreachable("unknown frame pointer flag"); |
Nick Lewycky | b3ffe10 | 2011-12-10 22:34:41 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Nick Lewycky | b3ffe10 | 2011-12-10 22:34:41 +0000 | [diff] [blame] | 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; |
| 60 | } |