163faed5bSDimitry Andric //===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==// 263faed5bSDimitry Andric // 3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 663faed5bSDimitry Andric // 763faed5bSDimitry Andric //===----------------------------------------------------------------------===// 863faed5bSDimitry Andric // 963faed5bSDimitry Andric // This file implements the methods in the TargetOptions. 1063faed5bSDimitry Andric // 1163faed5bSDimitry Andric //===----------------------------------------------------------------------===// 1263faed5bSDimitry Andric 13ac9a064cSDimitry Andric #include "llvm/ADT/StringSwitch.h" 1463faed5bSDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h" 155ca98fd9SDimitry Andric #include "llvm/CodeGen/MachineFunction.h" 16044eb2f6SDimitry Andric #include "llvm/CodeGen/TargetFrameLowering.h" 17044eb2f6SDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h" 187ab83427SDimitry Andric #include "llvm/IR/Function.h" 1963faed5bSDimitry Andric #include "llvm/Target/TargetOptions.h" 2063faed5bSDimitry Andric using namespace llvm; 2163faed5bSDimitry Andric 2263faed5bSDimitry Andric /// DisableFramePointerElim - This returns true if frame pointer elimination 2363faed5bSDimitry Andric /// optimization should be disabled for the given machine function. DisableFramePointerElim(const MachineFunction & MF) const2463faed5bSDimitry Andricbool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const { 25ac9a064cSDimitry Andric // Check to see if the target want to forcibly keep frame pointer. 26d8e91e46SDimitry Andric if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF)) 27d8e91e46SDimitry Andric return true; 28d8e91e46SDimitry Andric 29d8e91e46SDimitry Andric const Function &F = MF.getFunction(); 30d8e91e46SDimitry Andric 31706b4fc4SDimitry Andric if (!F.hasFnAttribute("frame-pointer")) 325a5ac124SDimitry Andric return false; 33d8e91e46SDimitry Andric StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString(); 34d8e91e46SDimitry Andric if (FP == "all") 35d8e91e46SDimitry Andric return true; 36d8e91e46SDimitry Andric if (FP == "non-leaf") 37d8e91e46SDimitry Andric return MF.getFrameInfo().hasCalls(); 38ac9a064cSDimitry Andric if (FP == "none" || FP == "reserved") 39d8e91e46SDimitry Andric return false; 40d8e91e46SDimitry Andric llvm_unreachable("unknown frame pointer flag"); 41d8e91e46SDimitry Andric } 42d8e91e46SDimitry Andric FramePointerIsReserved(const MachineFunction & MF) const43ac9a064cSDimitry Andricbool TargetOptions::FramePointerIsReserved(const MachineFunction &MF) const { 44ac9a064cSDimitry Andric // Check to see if the target want to forcibly keep frame pointer. 45ac9a064cSDimitry Andric if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF)) 46ac9a064cSDimitry Andric return true; 47ac9a064cSDimitry Andric 48ac9a064cSDimitry Andric const Function &F = MF.getFunction(); 49ac9a064cSDimitry Andric 50ac9a064cSDimitry Andric if (!F.hasFnAttribute("frame-pointer")) 51ac9a064cSDimitry Andric return false; 52ac9a064cSDimitry Andric 53ac9a064cSDimitry Andric StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString(); 54ac9a064cSDimitry Andric return StringSwitch<bool>(FP) 55ac9a064cSDimitry Andric .Cases("all", "non-leaf", "reserved", true) 56ac9a064cSDimitry Andric .Case("none", false); 57ac9a064cSDimitry Andric } 58ac9a064cSDimitry Andric 5963faed5bSDimitry Andric /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume 6063faed5bSDimitry Andric /// that the rounding mode of the FPU can change from its default. HonorSignDependentRoundingFPMath() const6163faed5bSDimitry Andricbool TargetOptions::HonorSignDependentRoundingFPMath() const { 6263faed5bSDimitry Andric return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; 6363faed5bSDimitry Andric } 64cfca06d7SDimitry Andric 65cfca06d7SDimitry Andric /// NOTE: There are targets that still do not support the debug entry values 66b60736ecSDimitry Andric /// production and that is being controlled with the SupportsDebugEntryValues. 67b60736ecSDimitry Andric /// In addition, SCE debugger does not have the feature implemented, so prefer 68b60736ecSDimitry Andric /// not to emit the debug entry values in that case. 69b60736ecSDimitry Andric /// The EnableDebugEntryValues can be used for the testing purposes. ShouldEmitDebugEntryValues() const70cfca06d7SDimitry Andricbool TargetOptions::ShouldEmitDebugEntryValues() const { 71b60736ecSDimitry Andric return (SupportsDebugEntryValues && DebuggerTuning != DebuggerKind::SCE) || 72b60736ecSDimitry Andric EnableDebugEntryValues; 73cfca06d7SDimitry Andric } 74