[Alignment][NFC] Remove dependency on GlobalObject::setAlignment(unsigned)
[llvm-core.git] / lib / CodeGen / TargetOptionsImpl.cpp
blob039748d817caad60021755aac9ccd64c5f8fb504
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.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/CodeGen/MachineFrameInfo.h"
14 #include "llvm/CodeGen/MachineFunction.h"
15 #include "llvm/CodeGen/TargetFrameLowering.h"
16 #include "llvm/CodeGen/TargetSubtargetInfo.h"
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/Target/TargetOptions.h"
20 using namespace llvm;
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 forcably keep frame pointer.
26 if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))
27 return true;
29 const Function &F = MF.getFunction();
31 // 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;
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();
42 return false;
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");
55 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
56 /// that the rounding mode of the FPU can change from its default.
57 bool TargetOptions::HonorSignDependentRoundingFPMath() const {
58 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;