PPCMCTargetDesc.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //===-- PPCMCTargetDesc.h - PowerPC Target Descriptions ---------*- 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 provides PowerPC specific target descriptions.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H
  13. #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H
  14. // GCC #defines PPC on Linux but we use it as our namespace name
  15. #undef PPC
  16. #include "llvm/MC/MCRegisterInfo.h"
  17. #include "llvm/Support/MathExtras.h"
  18. #include <cstdint>
  19. #include <memory>
  20. namespace llvm {
  21. class MCAsmBackend;
  22. class MCCodeEmitter;
  23. class MCContext;
  24. class MCInstrInfo;
  25. class MCObjectTargetWriter;
  26. class MCRegisterInfo;
  27. class MCSubtargetInfo;
  28. class MCTargetOptions;
  29. class Target;
  30. MCCodeEmitter *createPPCMCCodeEmitter(const MCInstrInfo &MCII,
  31. MCContext &Ctx);
  32. MCAsmBackend *createPPCAsmBackend(const Target &T, const MCSubtargetInfo &STI,
  33. const MCRegisterInfo &MRI,
  34. const MCTargetOptions &Options);
  35. /// Construct an PPC ELF object writer.
  36. std::unique_ptr<MCObjectTargetWriter> createPPCELFObjectWriter(bool Is64Bit,
  37. uint8_t OSABI);
  38. /// Construct a PPC Mach-O object writer.
  39. std::unique_ptr<MCObjectTargetWriter>
  40. createPPCMachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype);
  41. /// Construct a PPC XCOFF object writer.
  42. std::unique_ptr<MCObjectTargetWriter> createPPCXCOFFObjectWriter(bool Is64Bit);
  43. /// Returns true iff Val consists of one contiguous run of 1s with any number of
  44. /// 0s on either side. The 1s are allowed to wrap from LSB to MSB, so
  45. /// 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is not,
  46. /// since all 1s are not contiguous.
  47. static inline bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) {
  48. if (!Val)
  49. return false;
  50. if (isShiftedMask_32(Val)) {
  51. // look for the first non-zero bit
  52. MB = countLeadingZeros(Val);
  53. // look for the first zero bit after the run of ones
  54. ME = countLeadingZeros((Val - 1) ^ Val);
  55. return true;
  56. } else {
  57. Val = ~Val; // invert mask
  58. if (isShiftedMask_32(Val)) {
  59. // effectively look for the first zero bit
  60. ME = countLeadingZeros(Val) - 1;
  61. // effectively look for the first one bit after the run of zeros
  62. MB = countLeadingZeros((Val - 1) ^ Val) + 1;
  63. return true;
  64. }
  65. }
  66. // no run present
  67. return false;
  68. }
  69. static inline bool isRunOfOnes64(uint64_t Val, unsigned &MB, unsigned &ME) {
  70. if (!Val)
  71. return false;
  72. if (isShiftedMask_64(Val)) {
  73. // look for the first non-zero bit
  74. MB = countLeadingZeros(Val);
  75. // look for the first zero bit after the run of ones
  76. ME = countLeadingZeros((Val - 1) ^ Val);
  77. return true;
  78. } else {
  79. Val = ~Val; // invert mask
  80. if (isShiftedMask_64(Val)) {
  81. // effectively look for the first zero bit
  82. ME = countLeadingZeros(Val) - 1;
  83. // effectively look for the first one bit after the run of zeros
  84. MB = countLeadingZeros((Val - 1) ^ Val) + 1;
  85. return true;
  86. }
  87. }
  88. // no run present
  89. return false;
  90. }
  91. } // end namespace llvm
  92. // Generated files will use "namespace PPC". To avoid symbol clash,
  93. // undefine PPC here. PPC may be predefined on some hosts.
  94. #undef PPC
  95. // Defines symbolic names for PowerPC registers. This defines a mapping from
  96. // register name to register number.
  97. //
  98. #define GET_REGINFO_ENUM
  99. #include "PPCGenRegisterInfo.inc"
  100. // Defines symbolic names for the PowerPC instructions.
  101. //
  102. #define GET_INSTRINFO_ENUM
  103. #define GET_INSTRINFO_SCHED_ENUM
  104. #define GET_INSTRINFO_MC_HELPER_DECLS
  105. #include "PPCGenInstrInfo.inc"
  106. #define GET_SUBTARGETINFO_ENUM
  107. #include "PPCGenSubtargetInfo.inc"
  108. #define PPC_REGS0_7(X) \
  109. { \
  110. X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7 \
  111. }
  112. #define PPC_REGS0_31(X) \
  113. { \
  114. X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \
  115. X##12, X##13, X##14, X##15, X##16, X##17, X##18, X##19, X##20, X##21, \
  116. X##22, X##23, X##24, X##25, X##26, X##27, X##28, X##29, X##30, X##31 \
  117. }
  118. #define PPC_REGS0_63(X) \
  119. { \
  120. X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \
  121. X##12, X##13, X##14, X##15, X##16, X##17, X##18, X##19, X##20, X##21, \
  122. X##22, X##23, X##24, X##25, X##26, X##27, X##28, X##29, X##30, X##31, \
  123. X##32, X##33, X##34, X##35, X##36, X##37, X##38, X##39, X##40, X##41, \
  124. X##42, X##43, X##44, X##45, X##46, X##47, X##48, X##49, X##50, X##51, \
  125. X##52, X##53, X##54, X##55, X##56, X##57, X##58, X##59, X##60, X##61, \
  126. X##62, X##63 \
  127. }
  128. #define PPC_REGS_NO0_31(Z, X) \
  129. { \
  130. Z, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \
  131. X##12, X##13, X##14, X##15, X##16, X##17, X##18, X##19, X##20, X##21, \
  132. X##22, X##23, X##24, X##25, X##26, X##27, X##28, X##29, X##30, X##31 \
  133. }
  134. #define PPC_REGS_LO_HI(LO, HI) \
  135. { \
  136. LO##0, LO##1, LO##2, LO##3, LO##4, LO##5, LO##6, LO##7, LO##8, LO##9, \
  137. LO##10, LO##11, LO##12, LO##13, LO##14, LO##15, LO##16, LO##17, \
  138. LO##18, LO##19, LO##20, LO##21, LO##22, LO##23, LO##24, LO##25, \
  139. LO##26, LO##27, LO##28, LO##29, LO##30, LO##31, HI##0, HI##1, HI##2, \
  140. HI##3, HI##4, HI##5, HI##6, HI##7, HI##8, HI##9, HI##10, HI##11, \
  141. HI##12, HI##13, HI##14, HI##15, HI##16, HI##17, HI##18, HI##19, \
  142. HI##20, HI##21, HI##22, HI##23, HI##24, HI##25, HI##26, HI##27, \
  143. HI##28, HI##29, HI##30, HI##31 \
  144. }
  145. #define PPC_REGS0_7(X) \
  146. { \
  147. X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7 \
  148. }
  149. #define PPC_REGS0_3(X) \
  150. { \
  151. X##0, X##1, X##2, X##3 \
  152. }
  153. using llvm::MCPhysReg;
  154. #define DEFINE_PPC_REGCLASSES \
  155. static const MCPhysReg RRegs[32] = PPC_REGS0_31(PPC::R); \
  156. static const MCPhysReg XRegs[32] = PPC_REGS0_31(PPC::X); \
  157. static const MCPhysReg FRegs[32] = PPC_REGS0_31(PPC::F); \
  158. static const MCPhysReg VSRpRegs[32] = PPC_REGS0_31(PPC::VSRp); \
  159. static const MCPhysReg SPERegs[32] = PPC_REGS0_31(PPC::S); \
  160. static const MCPhysReg VFRegs[32] = PPC_REGS0_31(PPC::VF); \
  161. static const MCPhysReg VRegs[32] = PPC_REGS0_31(PPC::V); \
  162. static const MCPhysReg RRegsNoR0[32] = \
  163. PPC_REGS_NO0_31(PPC::ZERO, PPC::R); \
  164. static const MCPhysReg XRegsNoX0[32] = \
  165. PPC_REGS_NO0_31(PPC::ZERO8, PPC::X); \
  166. static const MCPhysReg VSRegs[64] = \
  167. PPC_REGS_LO_HI(PPC::VSL, PPC::V); \
  168. static const MCPhysReg VSFRegs[64] = \
  169. PPC_REGS_LO_HI(PPC::F, PPC::VF); \
  170. static const MCPhysReg VSSRegs[64] = \
  171. PPC_REGS_LO_HI(PPC::F, PPC::VF); \
  172. static const MCPhysReg CRBITRegs[32] = { \
  173. PPC::CR0LT, PPC::CR0GT, PPC::CR0EQ, PPC::CR0UN, \
  174. PPC::CR1LT, PPC::CR1GT, PPC::CR1EQ, PPC::CR1UN, \
  175. PPC::CR2LT, PPC::CR2GT, PPC::CR2EQ, PPC::CR2UN, \
  176. PPC::CR3LT, PPC::CR3GT, PPC::CR3EQ, PPC::CR3UN, \
  177. PPC::CR4LT, PPC::CR4GT, PPC::CR4EQ, PPC::CR4UN, \
  178. PPC::CR5LT, PPC::CR5GT, PPC::CR5EQ, PPC::CR5UN, \
  179. PPC::CR6LT, PPC::CR6GT, PPC::CR6EQ, PPC::CR6UN, \
  180. PPC::CR7LT, PPC::CR7GT, PPC::CR7EQ, PPC::CR7UN}; \
  181. static const MCPhysReg CRRegs[8] = PPC_REGS0_7(PPC::CR); \
  182. static const MCPhysReg ACCRegs[8] = PPC_REGS0_7(PPC::ACC); \
  183. static const MCPhysReg WACCRegs[8] = PPC_REGS0_7(PPC::WACC); \
  184. static const MCPhysReg WACC_HIRegs[8] = PPC_REGS0_7(PPC::WACC_HI); \
  185. static const MCPhysReg DMRROWpRegs[32] = PPC_REGS0_31(PPC::DMRROWp); \
  186. static const MCPhysReg DMRROWRegs[64] = PPC_REGS0_63(PPC::DMRROW); \
  187. static const MCPhysReg DMRRegs[8] = PPC_REGS0_7(PPC::DMR); \
  188. static const MCPhysReg DMRpRegs[4] = PPC_REGS0_3(PPC::DMRp);
  189. #endif // LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H