TargetOptionsImpl.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "llvm/CodeGen/MachineFrameInfo.h"
  13. #include "llvm/CodeGen/MachineFunction.h"
  14. #include "llvm/CodeGen/TargetFrameLowering.h"
  15. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  16. #include "llvm/IR/Function.h"
  17. #include "llvm/IR/Module.h"
  18. #include "llvm/Target/TargetOptions.h"
  19. using namespace llvm;
  20. /// DisableFramePointerElim - This returns true if frame pointer elimination
  21. /// optimization should be disabled for the given machine function.
  22. bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
  23. // Check to see if the target want to forcably keep frame pointer.
  24. if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))
  25. return true;
  26. const Function &F = MF.getFunction();
  27. // TODO: Remove support for old `fp elim` function attributes after fully
  28. // migrate to use "frame-pointer"
  29. if (!F.hasFnAttribute("frame-pointer")) {
  30. // Check to see if we should eliminate all frame pointers.
  31. if (F.getFnAttribute("no-frame-pointer-elim").getValueAsString() == "true")
  32. return true;
  33. // Check to see if we should eliminate non-leaf frame pointers.
  34. if (F.hasFnAttribute("no-frame-pointer-elim-non-leaf"))
  35. return MF.getFrameInfo().hasCalls();
  36. return false;
  37. }
  38. StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
  39. if (FP == "all")
  40. return true;
  41. if (FP == "non-leaf")
  42. return MF.getFrameInfo().hasCalls();
  43. if (FP == "none")
  44. return false;
  45. llvm_unreachable("unknown frame pointer flag");
  46. }
  47. /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
  48. /// that the rounding mode of the FPU can change from its default.
  49. bool TargetOptions::HonorSignDependentRoundingFPMath() const {
  50. return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
  51. }