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"
20using namespace llvm;
21
22/// DisableFramePointerElim - This returns true if frame pointer elimination
23/// optimization should be disabled for the given machine function.
24bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
25 const Function &F = MF.getFunction();
26
27 Attribute FPAttr = F.getFnAttribute(Kind: "frame-pointer");
28 if (!FPAttr.isValid())
29 return false;
30 StringRef FP = FPAttr.getValueAsString();
31 if (FP == "all")
32 return true;
33 if (FP == "non-leaf")
34 return MF.getFrameInfo().hasCalls();
35 if (FP == "none" || FP == "reserved")
36 return false;
37 llvm_unreachable("unknown frame pointer flag");
38}
39
40bool TargetOptions::FramePointerIsReserved(const MachineFunction &MF) const {
41 const Function &F = MF.getFunction();
42 Attribute FPAttr = F.getFnAttribute(Kind: "frame-pointer");
43 if (!FPAttr.isValid())
44 return false;
45
46 return StringSwitch<bool>(FPAttr.getValueAsString())
47 .Cases(S0: "all", S1: "non-leaf", S2: "reserved", Value: true)
48 .Case(S: "none", Value: 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.
53bool 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.
62bool TargetOptions::ShouldEmitDebugEntryValues() const {
63 return (SupportsDebugEntryValues && DebuggerTuning != DebuggerKind::SCE) ||
64 EnableDebugEntryValues;
65}
66