riscv.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- riscv.h - Generic JITLink riscv edge kinds, utilities -*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Generic utilities for graphs representing riscv objects.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_EXECUTIONENGINE_JITLINK_RISCV_H
  18. #define LLVM_EXECUTIONENGINE_JITLINK_RISCV_H
  19. #include "llvm/ExecutionEngine/JITLink/JITLink.h"
  20. namespace llvm {
  21. namespace jitlink {
  22. namespace riscv {
  23. /// Represents riscv fixups. Ordered in the same way as the relocations in
  24. /// include/llvm/BinaryFormat/ELFRelocs/RISCV.def.
  25. enum EdgeKind_riscv : Edge::Kind {
  26. // TODO: Capture and replace to generic fixups
  27. /// A plain 32-bit pointer value relocation
  28. ///
  29. /// Fixup expression:
  30. /// Fixup <= Target + Addend : uint32
  31. ///
  32. R_RISCV_32 = Edge::FirstRelocation,
  33. /// A plain 64-bit pointer value relocation
  34. ///
  35. /// Fixup expression:
  36. /// Fixup <- Target + Addend : uint32
  37. ///
  38. R_RISCV_64,
  39. /// PC-relative branch pointer value relocation
  40. ///
  41. /// Fixup expression:
  42. /// Fixup <- (Target - Fixup + Addend)
  43. ///
  44. R_RISCV_BRANCH,
  45. /// High 20 bits of PC-relative jump pointer value relocation
  46. ///
  47. /// Fixup expression:
  48. /// Fixup <- Target - Fixup + Addend
  49. ///
  50. R_RISCV_JAL,
  51. /// PC relative call
  52. ///
  53. /// Fixup expression:
  54. /// Fixup <- (Target - Fixup + Addend)
  55. R_RISCV_CALL,
  56. /// PC relative call by PLT
  57. ///
  58. /// Fixup expression:
  59. /// Fixup <- (Target - Fixup + Addend)
  60. R_RISCV_CALL_PLT,
  61. /// PC relative GOT offset
  62. ///
  63. /// Fixup expression:
  64. /// Fixup <- (GOT - Fixup + Addend) >> 12
  65. R_RISCV_GOT_HI20,
  66. /// High 20 bits of PC relative relocation
  67. ///
  68. /// Fixup expression:
  69. /// Fixup <- (Target - Fixup + Addend + 0x800) >> 12
  70. R_RISCV_PCREL_HI20,
  71. /// Low 12 bits of PC relative relocation, used by I type instruction format
  72. ///
  73. /// Fixup expression:
  74. /// Fixup <- (Target - Fixup + Addend) & 0xFFF
  75. R_RISCV_PCREL_LO12_I,
  76. /// Low 12 bits of PC relative relocation, used by S type instruction format
  77. ///
  78. /// Fixup expression:
  79. /// Fixup <- (Target - Fixup + Addend) & 0xFFF
  80. R_RISCV_PCREL_LO12_S,
  81. /// High 20 bits of 32-bit pointer value relocation
  82. ///
  83. /// Fixup expression
  84. /// Fixup <- (Target + Addend + 0x800) >> 12
  85. R_RISCV_HI20,
  86. /// Low 12 bits of 32-bit pointer value relocation
  87. ///
  88. /// Fixup expression
  89. /// Fixup <- (Target + Addend) & 0xFFF
  90. R_RISCV_LO12_I,
  91. /// Low 12 bits of 32-bit pointer value relocation, used by S type instruction
  92. /// format
  93. ///
  94. /// Fixup expression
  95. /// Fixup <- (Target + Addend) & 0xFFF
  96. R_RISCV_LO12_S,
  97. /// 8 bits label addition
  98. ///
  99. /// Fixup expression
  100. /// Fixup <- (Target - *{1}Fixup + Addend)
  101. R_RISCV_ADD8,
  102. /// 16 bits label addition
  103. ///
  104. /// Fixup expression
  105. /// Fixup <- (Target - *{2}Fixup + Addend)
  106. R_RISCV_ADD16,
  107. /// 32 bits label addition
  108. ///
  109. /// Fixup expression:
  110. /// Fixup <- (Target - *{4}Fixup + Addend)
  111. R_RISCV_ADD32,
  112. /// 64 bits label addition
  113. ///
  114. /// Fixup expression:
  115. /// Fixup <- (Target - *{8}Fixup + Addend)
  116. R_RISCV_ADD64,
  117. /// 8 bits label subtraction
  118. ///
  119. /// Fixup expression
  120. /// Fixup <- (Target - *{1}Fixup - Addend)
  121. R_RISCV_SUB8,
  122. /// 16 bits label subtraction
  123. ///
  124. /// Fixup expression
  125. /// Fixup <- (Target - *{2}Fixup - Addend)
  126. R_RISCV_SUB16,
  127. /// 32 bits label subtraction
  128. ///
  129. /// Fixup expression
  130. /// Fixup <- (Target - *{4}Fixup - Addend)
  131. R_RISCV_SUB32,
  132. /// 64 bits label subtraction
  133. ///
  134. /// Fixup expression
  135. /// Fixup <- (Target - *{8}Fixup - Addend)
  136. R_RISCV_SUB64,
  137. /// 8-bit PC-relative branch offset
  138. ///
  139. /// Fixup expression:
  140. /// Fixup <- (Target - Fixup + Addend)
  141. R_RISCV_RVC_BRANCH,
  142. /// 11-bit PC-relative jump offset
  143. ///
  144. /// Fixup expression:
  145. /// Fixup <- (Target - Fixup + Addend)
  146. R_RISCV_RVC_JUMP,
  147. /// 6 bits label subtraction
  148. ///
  149. /// Fixup expression
  150. /// Fixup <- (Target - *{1}Fixup - Addend)
  151. R_RISCV_SUB6,
  152. /// Local label assignment
  153. ///
  154. /// Fixup expression:
  155. /// Fixup <- (Target + Addend)
  156. R_RISCV_SET6,
  157. /// Local label assignment
  158. ///
  159. /// Fixup expression:
  160. /// Fixup <- (Target + Addend)
  161. R_RISCV_SET8,
  162. /// Local label assignment
  163. ///
  164. /// Fixup expression:
  165. /// Fixup <- (Target + Addend)
  166. R_RISCV_SET16,
  167. /// Local label assignment
  168. ///
  169. /// Fixup expression:
  170. /// Fixup <- (Target + Addend)
  171. R_RISCV_SET32,
  172. /// 32 bits PC relative relocation
  173. ///
  174. /// Fixup expression:
  175. /// Fixup <- (Target - Fixup + Addend)
  176. R_RISCV_32_PCREL,
  177. };
  178. /// Returns a string name for the given riscv edge. For debugging purposes
  179. /// only
  180. const char *getEdgeKindName(Edge::Kind K);
  181. } // namespace riscv
  182. } // namespace jitlink
  183. } // namespace llvm
  184. #endif
  185. #ifdef __GNUC__
  186. #pragma GCC diagnostic pop
  187. #endif