TargetOptionsImpl.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //===-- TargetOptionsImpl.cpp - Options that apply to all targets ----------==//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the methods in the TargetOptions.
  11. //
  12. //===----------------------------------------------------------------------===//
  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;
  21. /// DisableFramePointerElim - This returns true if frame pointer elimination
  22. /// optimization should be disabled for the given machine function.
  23. bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
  24. // Check to see if the target want to forcably keep frame pointer.
  25. if (MF.getSubtarget().getFrameLowering()->keepFramePointer(MF))
  26. return true;
  27. const Function &F = MF.getFunction();
  28. // TODO: Remove support for old `fp elim` function attributes after fully
  29. // migrate to use "frame-pointer"
  30. if (!F.hasFnAttribute("frame-pointer")) {
  31. // Check to see if we should eliminate all frame pointers.
  32. if (F.getFnAttribute("no-frame-pointer-elim").getValueAsString() == "true")
  33. return true;
  34. // Check to see if we should eliminate non-leaf frame pointers.
  35. if (F.hasFnAttribute("no-frame-pointer-elim-non-leaf"))
  36. return MF.getFrameInfo().hasCalls();
  37. return false;
  38. }
  39. StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString();
  40. if (FP == "all")
  41. return true;
  42. if (FP == "non-leaf")
  43. return MF.getFrameInfo().hasCalls();
  44. if (FP == "none")
  45. return false;
  46. llvm_unreachable("unknown frame pointer flag");
  47. }
  48. /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
  49. /// that the rounding mode of the FPU can change from its default.
  50. bool TargetOptions::HonorSignDependentRoundingFPMath() const {
  51. return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
  52. }