blob: 3c133fb8594ec7b421e6422770913d36fab1aeec [file] [log] [blame]
Nick Lewycky028700f2011-12-15 22:58:58 +00001//===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==//
Nick Lewyckyb3ffe102011-12-10 22:34:41 +00002//
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 Lewyckyb3ffe102011-12-10 22:34:41 +000014#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruth974a4452014-01-07 11:48:04 +000015#include "llvm/CodeGen/MachineFunction.h"
David Blaikiee3a9b4c2017-11-17 01:07:10 +000016#include "llvm/CodeGen/TargetFrameLowering.h"
17#include "llvm/CodeGen/TargetSubtargetInfo.h"
Chandler Carruthe3e43d92017-06-06 11:49:48 +000018#include "llvm/IR/Function.h"
19#include "llvm/IR/Module.h"
Nick Lewyckyb3ffe102011-12-10 22:34:41 +000020#include "llvm/Target/TargetOptions.h"
21using namespace llvm;
22
23/// DisableFramePointerElim - This returns true if frame pointer elimination
24/// optimization should be disabled for the given machine function.
25bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
Francis Visoiu Mistrih08223c32019-01-14 10:55:55 +000026 // Check to see if the target want to forcably keep frame pointer.
27 if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))
Akira Hatanaka01461202015-05-23 01:14:08 +000028 return true;
Nick Lewyckyb3ffe102011-12-10 22:34:41 +000029
Francis Visoiu Mistrih08223c32019-01-14 10:55:55 +000030 const Function &F = MF.getFunction();
Akira Hatanaka01461202015-05-23 01:14:08 +000031
Francis Visoiu Mistrih08223c32019-01-14 10:55:55 +000032 // 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 Lewyckyb3ffe102011-12-10 22:34:41 +000054}
55
Nick Lewyckyb3ffe102011-12-10 22:34:41 +000056/// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
57/// that the rounding mode of the FPU can change from its default.
58bool TargetOptions::HonorSignDependentRoundingFPMath() const {
59 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
60}