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 | // Check to see if the target want to forcibly keep frame pointer. |
26 | if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF)) |
27 | return true; |
28 | |
29 | const Function &F = MF.getFunction(); |
30 | |
31 | if (!F.hasFnAttribute(Kind: "frame-pointer")) |
32 | return false; |
33 | StringRef FP = F.getFnAttribute(Kind: "frame-pointer").getValueAsString(); |
34 | if (FP == "all") |
35 | return true; |
36 | if (FP == "non-leaf") |
37 | return MF.getFrameInfo().hasCalls(); |
38 | if (FP == "none"|| FP == "reserved") |
39 | return false; |
40 | llvm_unreachable("unknown frame pointer flag"); |
41 | } |
42 | |
43 | bool TargetOptions::FramePointerIsReserved(const MachineFunction &MF) const { |
44 | // Check to see if the target want to forcibly keep frame pointer. |
45 | if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF)) |
46 | return true; |
47 | |
48 | const Function &F = MF.getFunction(); |
49 | |
50 | if (!F.hasFnAttribute(Kind: "frame-pointer")) |
51 | return false; |
52 | |
53 | StringRef FP = F.getFnAttribute(Kind: "frame-pointer").getValueAsString(); |
54 | return StringSwitch<bool>(FP) |
55 | .Cases(S0: "all", S1: "non-leaf", S2: "reserved", Value: true) |
56 | .Case(S: "none", Value: false); |
57 | } |
58 | |
59 | /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume |
60 | /// that the rounding mode of the FPU can change from its default. |
61 | bool TargetOptions::HonorSignDependentRoundingFPMath() const { |
62 | return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; |
63 | } |
64 | |
65 | /// NOTE: There are targets that still do not support the debug entry values |
66 | /// production and that is being controlled with the SupportsDebugEntryValues. |
67 | /// In addition, SCE debugger does not have the feature implemented, so prefer |
68 | /// not to emit the debug entry values in that case. |
69 | /// The EnableDebugEntryValues can be used for the testing purposes. |
70 | bool TargetOptions::ShouldEmitDebugEntryValues() const { |
71 | return (SupportsDebugEntryValues && DebuggerTuning != DebuggerKind::SCE) || |
72 | EnableDebugEntryValues; |
73 | } |
74 |