xref: /llvm-project/llvm/lib/CodeGen/TargetOptionsImpl.cpp (revision 4a2bd78f5b0d0661c23dff9c4b93a393a49dbf9a)
1 //===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the methods in the TargetOptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/ADT/StringSwitch.h"
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/Target/TargetOptions.h"
20 using namespace llvm;
21 
22 /// DisableFramePointerElim - This returns true if frame pointer elimination
23 /// optimization should be disabled for the given machine function.
24 bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
25   const Function &F = MF.getFunction();
26 
27   if (!F.hasFnAttribute("frame-pointer"))
28     return false;
29   StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
30   if (FP == "all")
31     return true;
32   if (FP == "non-leaf")
33     return MF.getFrameInfo().hasCalls();
34   if (FP == "none" || FP == "reserved")
35     return false;
36   llvm_unreachable("unknown frame pointer flag");
37 }
38 
39 bool TargetOptions::FramePointerIsReserved(const MachineFunction &MF) const {
40   const Function &F = MF.getFunction();
41 
42   if (!F.hasFnAttribute("frame-pointer"))
43     return false;
44 
45   StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
46   return StringSwitch<bool>(FP)
47       .Cases("all", "non-leaf", "reserved", true)
48       .Case("none", false);
49 }
50 
51 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
52 /// that the rounding mode of the FPU can change from its default.
53 bool TargetOptions::HonorSignDependentRoundingFPMath() const {
54   return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
55 }
56 
57 /// NOTE: There are targets that still do not support the debug entry values
58 /// production and that is being controlled with the SupportsDebugEntryValues.
59 /// In addition, SCE debugger does not have the feature implemented, so prefer
60 /// not to emit the debug entry values in that case.
61 /// The EnableDebugEntryValues can be used for the testing purposes.
62 bool TargetOptions::ShouldEmitDebugEntryValues() const {
63   return (SupportsDebugEntryValues && DebuggerTuning != DebuggerKind::SCE) ||
64          EnableDebugEntryValues;
65 }
66