PPCMCTargetDesc.h 7.4 KB

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