ARMTargetMachine.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //===-- ARMTargetMachine.h - Define TargetMachine for ARM -------*- C++ -*-===//
  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 declares the ARM specific subclass of TargetMachine.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_ARM_ARMTARGETMACHINE_H
  13. #define LLVM_LIB_TARGET_ARM_ARMTARGETMACHINE_H
  14. #include "ARMSubtarget.h"
  15. #include "llvm/ADT/StringMap.h"
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/Analysis/TargetTransformInfo.h"
  18. #include "llvm/Support/CodeGen.h"
  19. #include "llvm/Target/TargetMachine.h"
  20. #include <memory>
  21. #include <optional>
  22. namespace llvm {
  23. class ARMBaseTargetMachine : public LLVMTargetMachine {
  24. public:
  25. enum ARMABI {
  26. ARM_ABI_UNKNOWN,
  27. ARM_ABI_APCS,
  28. ARM_ABI_AAPCS, // ARM EABI
  29. ARM_ABI_AAPCS16
  30. } TargetABI;
  31. protected:
  32. std::unique_ptr<TargetLoweringObjectFile> TLOF;
  33. bool isLittle;
  34. mutable StringMap<std::unique_ptr<ARMSubtarget>> SubtargetMap;
  35. public:
  36. ARMBaseTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
  37. StringRef FS, const TargetOptions &Options,
  38. std::optional<Reloc::Model> RM,
  39. std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
  40. bool isLittle);
  41. ~ARMBaseTargetMachine() override;
  42. const ARMSubtarget *getSubtargetImpl(const Function &F) const override;
  43. // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget,
  44. // subtargets are per-function entities based on the target-specific
  45. // attributes of each function.
  46. const ARMSubtarget *getSubtargetImpl() const = delete;
  47. bool isLittleEndian() const { return isLittle; }
  48. TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
  49. // Pass Pipeline Configuration
  50. TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
  51. TargetLoweringObjectFile *getObjFileLowering() const override {
  52. return TLOF.get();
  53. }
  54. bool isTargetHardFloat() const {
  55. return TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
  56. TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
  57. TargetTriple.getEnvironment() == Triple::EABIHF ||
  58. (TargetTriple.isOSBinFormatMachO() &&
  59. TargetTriple.getSubArch() == Triple::ARMSubArch_v7em) ||
  60. TargetTriple.isOSWindows() ||
  61. TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16;
  62. }
  63. bool targetSchedulesPostRAScheduling() const override { return true; };
  64. MachineFunctionInfo *
  65. createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
  66. const TargetSubtargetInfo *STI) const override;
  67. /// Returns true if a cast between SrcAS and DestAS is a noop.
  68. bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override {
  69. // Addrspacecasts are always noops.
  70. return true;
  71. }
  72. };
  73. /// ARM/Thumb little endian target machine.
  74. ///
  75. class ARMLETargetMachine : public ARMBaseTargetMachine {
  76. public:
  77. ARMLETargetMachine(const Target &T, const Triple &TT, StringRef CPU,
  78. StringRef FS, const TargetOptions &Options,
  79. std::optional<Reloc::Model> RM,
  80. std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
  81. bool JIT);
  82. };
  83. /// ARM/Thumb big endian target machine.
  84. ///
  85. class ARMBETargetMachine : public ARMBaseTargetMachine {
  86. public:
  87. ARMBETargetMachine(const Target &T, const Triple &TT, StringRef CPU,
  88. StringRef FS, const TargetOptions &Options,
  89. std::optional<Reloc::Model> RM,
  90. std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
  91. bool JIT);
  92. };
  93. } // end namespace llvm
  94. #endif // LLVM_LIB_TARGET_ARM_ARMTARGETMACHINE_H