blob: 039748d817caad60021755aac9ccd64c5f8fb504 [file] [log] [blame]
Nick Lewyckyc9e935c2011-12-15 22:58:58 +00001//===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==//
Nick Lewyckyb9cda972011-12-10 22:34:41 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Nick Lewyckyb9cda972011-12-10 22:34:41 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the methods in the TargetOptions.
10//
11//===----------------------------------------------------------------------===//
12
Nick Lewyckyb9cda972011-12-10 22:34:41 +000013#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000014#include "llvm/CodeGen/MachineFunction.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000015#include "llvm/CodeGen/TargetFrameLowering.h"
16#include "llvm/CodeGen/TargetSubtargetInfo.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000017#include "llvm/IR/Function.h"
18#include "llvm/IR/Module.h"
Nick Lewyckyb9cda972011-12-10 22:34:41 +000019#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 {
Francis Visoiu Mistrihb7cef812019-01-14 10:55:55 +000025 // Check to see if the target want to forcably keep frame pointer.
26 if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))
Akira Hatanakaddf76aa2015-05-23 01:14:08 +000027 return true;
Nick Lewyckyb9cda972011-12-10 22:34:41 +000028
Francis Visoiu Mistrihb7cef812019-01-14 10:55:55 +000029 const Function &F = MF.getFunction();
Akira Hatanakaddf76aa2015-05-23 01:14:08 +000030
Francis Visoiu Mistrihb7cef812019-01-14 10:55:55 +000031 // TODO: Remove support for old `fp elim` function attributes after fully
32 // migrate to use "frame-pointer"
33 if (!F.hasFnAttribute("frame-pointer")) {
34 // Check to see if we should eliminate all frame pointers.
35 if (F.getFnAttribute("no-frame-pointer-elim").getValueAsString() == "true")
36 return true;
37
38 // Check to see if we should eliminate non-leaf frame pointers.
39 if (F.hasFnAttribute("no-frame-pointer-elim-non-leaf"))
40 return MF.getFrameInfo().hasCalls();
41
42 return false;
43 }
44
45 StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
46 if (FP == "all")
47 return true;
48 if (FP == "non-leaf")
49 return MF.getFrameInfo().hasCalls();
50 if (FP == "none")
51 return false;
52 llvm_unreachable("unknown frame pointer flag");
Nick Lewyckyb9cda972011-12-10 22:34:41 +000053}
54
Nick Lewyckyb9cda972011-12-10 22:34:41 +000055/// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
56/// that the rounding mode of the FPU can change from its default.
57bool TargetOptions::HonorSignDependentRoundingFPMath() const {
58 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
59}