TargetOptionsImpl.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/IR/Function.h"
  14. #include "llvm/CodeGen/MachineFrameInfo.h"
  15. #include "llvm/CodeGen/MachineFunction.h"
  16. #include "llvm/Target/TargetOptions.h"
  17. using namespace llvm;
  18. /// DisableFramePointerElim - This returns true if frame pointer elimination
  19. /// optimization should be disabled for the given machine function.
  20. bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
  21. // Check to see if we should eliminate non-leaf frame pointers and then
  22. // check to see if we should eliminate all frame pointers.
  23. if (MF.getFunction()->hasFnAttribute("no-frame-pointer-elim-non-leaf") &&
  24. !NoFramePointerElim) {
  25. const MachineFrameInfo *MFI = MF.getFrameInfo();
  26. return MFI->hasCalls();
  27. }
  28. return NoFramePointerElim;
  29. }
  30. /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
  31. /// is specified on the command line. When this flag is off(default), the
  32. /// code generator is not allowed to generate mad (multiply add) if the
  33. /// result is "less precise" than doing those operations individually.
  34. bool TargetOptions::LessPreciseFPMAD() const {
  35. return UnsafeFPMath || LessPreciseFPMADOption;
  36. }
  37. /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
  38. /// that the rounding mode of the FPU can change from its default.
  39. bool TargetOptions::HonorSignDependentRoundingFPMath() const {
  40. return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
  41. }
  42. /// getTrapFunctionName - If this returns a non-empty string, this means isel
  43. /// should lower Intrinsic::trap to a call to the specified function name
  44. /// instead of an ISD::TRAP node.
  45. StringRef TargetOptions::getTrapFunctionName() const {
  46. return TrapFuncName;
  47. }
  48. void llvm::setFunctionAttributes(StringRef CPU, StringRef Features, Module &M) {
  49. for (auto &F : M) {
  50. auto &Ctx = F.getContext();
  51. AttributeSet Attrs = F.getAttributes(), NewAttrs;
  52. if (!CPU.empty())
  53. NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
  54. "target-cpu", CPU);
  55. if (!Features.empty())
  56. NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
  57. "target-features", Features);
  58. // Let NewAttrs override Attrs.
  59. NewAttrs = Attrs.addAttributes(Ctx, AttributeSet::FunctionIndex, NewAttrs);
  60. F.setAttributes(NewAttrs);
  61. }
  62. }