xref: /freebsd-src/contrib/llvm-project/llvm/lib/CodeGen/TargetOptionsImpl.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements the methods in the TargetOptions.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
13*0fca6ea1SDimitry Andric #include "llvm/ADT/StringSwitch.h"
140b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h"
150b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
160b57cec5SDimitry Andric #include "llvm/CodeGen/TargetFrameLowering.h"
170b57cec5SDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h"
180b57cec5SDimitry Andric #include "llvm/IR/Function.h"
190b57cec5SDimitry Andric #include "llvm/Target/TargetOptions.h"
200b57cec5SDimitry Andric using namespace llvm;
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric /// DisableFramePointerElim - This returns true if frame pointer elimination
230b57cec5SDimitry Andric /// optimization should be disabled for the given machine function.
240b57cec5SDimitry Andric bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
25*0fca6ea1SDimitry Andric   // Check to see if the target want to forcibly keep frame pointer.
260b57cec5SDimitry Andric   if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))
270b57cec5SDimitry Andric     return true;
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric   const Function &F = MF.getFunction();
300b57cec5SDimitry Andric 
31480093f4SDimitry Andric   if (!F.hasFnAttribute("frame-pointer"))
320b57cec5SDimitry Andric     return false;
330b57cec5SDimitry Andric   StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
340b57cec5SDimitry Andric   if (FP == "all")
350b57cec5SDimitry Andric     return true;
360b57cec5SDimitry Andric   if (FP == "non-leaf")
370b57cec5SDimitry Andric     return MF.getFrameInfo().hasCalls();
38*0fca6ea1SDimitry Andric   if (FP == "none" || FP == "reserved")
390b57cec5SDimitry Andric     return false;
400b57cec5SDimitry Andric   llvm_unreachable("unknown frame pointer flag");
410b57cec5SDimitry Andric }
420b57cec5SDimitry Andric 
43*0fca6ea1SDimitry Andric bool TargetOptions::FramePointerIsReserved(const MachineFunction &MF) const {
44*0fca6ea1SDimitry Andric   // Check to see if the target want to forcibly keep frame pointer.
45*0fca6ea1SDimitry Andric   if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))
46*0fca6ea1SDimitry Andric     return true;
47*0fca6ea1SDimitry Andric 
48*0fca6ea1SDimitry Andric   const Function &F = MF.getFunction();
49*0fca6ea1SDimitry Andric 
50*0fca6ea1SDimitry Andric   if (!F.hasFnAttribute("frame-pointer"))
51*0fca6ea1SDimitry Andric     return false;
52*0fca6ea1SDimitry Andric 
53*0fca6ea1SDimitry Andric   StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
54*0fca6ea1SDimitry Andric   return StringSwitch<bool>(FP)
55*0fca6ea1SDimitry Andric       .Cases("all", "non-leaf", "reserved", true)
56*0fca6ea1SDimitry Andric       .Case("none", false);
57*0fca6ea1SDimitry Andric }
58*0fca6ea1SDimitry Andric 
590b57cec5SDimitry Andric /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
600b57cec5SDimitry Andric /// that the rounding mode of the FPU can change from its default.
610b57cec5SDimitry Andric bool TargetOptions::HonorSignDependentRoundingFPMath() const {
620b57cec5SDimitry Andric   return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
630b57cec5SDimitry Andric }
645ffd83dbSDimitry Andric 
655ffd83dbSDimitry Andric /// NOTE: There are targets that still do not support the debug entry values
66e8d8bef9SDimitry Andric /// production and that is being controlled with the SupportsDebugEntryValues.
67e8d8bef9SDimitry Andric /// In addition, SCE debugger does not have the feature implemented, so prefer
68e8d8bef9SDimitry Andric /// not to emit the debug entry values in that case.
69e8d8bef9SDimitry Andric /// The EnableDebugEntryValues can be used for the testing purposes.
705ffd83dbSDimitry Andric bool TargetOptions::ShouldEmitDebugEntryValues() const {
71e8d8bef9SDimitry Andric   return (SupportsDebugEntryValues && DebuggerTuning != DebuggerKind::SCE) ||
72e8d8bef9SDimitry Andric          EnableDebugEntryValues;
735ffd83dbSDimitry Andric }
74