riscv.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. /// Represets riscv fixups
  24. enum EdgeKind_riscv : Edge::Kind {
  25. // TODO: Capture and replace to generic fixups
  26. /// A plain 32-bit pointer value relocation
  27. ///
  28. /// Fixup expression:
  29. /// Fixup <= Target + Addend : uint32
  30. ///
  31. R_RISCV_32 = Edge::FirstRelocation,
  32. /// A plain 64-bit pointer value relocation
  33. ///
  34. /// Fixup expression:
  35. /// Fixup <- Target + Addend : uint32
  36. ///
  37. R_RISCV_64,
  38. /// Low 12 bits of PC-relative branch pointer value relocation
  39. ///
  40. /// Fixup expression:
  41. /// Fixup <- (Target - Fixup + Addend) & 0xFFF
  42. ///
  43. R_RISCV_BRANCH,
  44. /// High 20 bits of 32-bit pointer value relocation
  45. ///
  46. /// Fixup expression
  47. /// Fixup <- (Target + Addend + 0x800) >> 12
  48. R_RISCV_HI20,
  49. /// Low 12 bits of 32-bit pointer value relocation
  50. ///
  51. /// Fixup expression
  52. /// Fixup <- (Target + Addend) & 0xFFF
  53. R_RISCV_LO12_I,
  54. /// High 20 bits of PC relative relocation
  55. ///
  56. /// Fixup expression:
  57. /// Fixup <- (Target - Fixup + Addend + 0x800) >> 12
  58. R_RISCV_PCREL_HI20,
  59. /// Low 12 bits of PC relative relocation, used by I type instruction format
  60. ///
  61. /// Fixup expression:
  62. /// Fixup <- (Target - Fixup + Addend) & 0xFFF
  63. R_RISCV_PCREL_LO12_I,
  64. /// Low 12 bits of PC relative relocation, used by S type instruction format
  65. ///
  66. /// Fixup expression:
  67. /// Fixup <- (Target - Fixup + Addend) & 0xFFF
  68. R_RISCV_PCREL_LO12_S,
  69. /// PC relative call
  70. ///
  71. /// Fixup expression:
  72. /// Fixup <- (Target - Fixup + Addend)
  73. R_RISCV_CALL,
  74. /// 32 bits PC relative relocation
  75. ///
  76. /// Fixup expression:
  77. /// Fixup <- (Target - Fixup + Addend)
  78. R_RISCV_32_PCREL,
  79. /// PC relative GOT offset
  80. ///
  81. /// Fixup expression:
  82. /// Fixup <- (GOT - Fixup + Addend) >> 12
  83. R_RISCV_GOT_HI20,
  84. /// PC relative call by PLT
  85. ///
  86. /// Fixup expression:
  87. /// Fixup <- (Target - Fixup + Addend)
  88. R_RISCV_CALL_PLT,
  89. /// 64 bits label addition
  90. ///
  91. /// Fixup expression:
  92. /// Fixup <- (Target - *{8}Fixup + Addend)
  93. R_RISCV_ADD64,
  94. /// 32 bits label addition
  95. ///
  96. /// Fixup expression:
  97. /// Fixup <- (Target - *{4}Fixup + Addend)
  98. R_RISCV_ADD32,
  99. /// 16 bits label addition
  100. ///
  101. /// Fixup expression
  102. /// Fixup <- (Target - *{2}Fixup + Addend)
  103. R_RISCV_ADD16,
  104. /// 8 bits label addition
  105. ///
  106. /// Fixup expression
  107. /// Fixup <- (Target - *{1}Fixup + Addend)
  108. R_RISCV_ADD8,
  109. /// 64 bits label subtraction
  110. ///
  111. /// Fixup expression
  112. /// Fixup <- (Target - *{8}Fixup - Addend)
  113. R_RISCV_SUB64,
  114. /// 32 bits label subtraction
  115. ///
  116. /// Fixup expression
  117. /// Fixup <- (Target - *{4}Fixup - Addend)
  118. R_RISCV_SUB32,
  119. /// 16 bits label subtraction
  120. ///
  121. /// Fixup expression
  122. /// Fixup <- (Target - *{2}Fixup - Addend)
  123. R_RISCV_SUB16,
  124. /// 8 bits label subtraction
  125. ///
  126. /// Fixup expression
  127. /// Fixup <- (Target - *{1}Fixup - Addend)
  128. R_RISCV_SUB8,
  129. /// Local label assignment
  130. ///
  131. /// Fixup expression:
  132. /// Fixup <- (Target + Addend)
  133. R_RISCV_SET6,
  134. /// Local label assignment
  135. ///
  136. /// Fixup expression:
  137. /// Fixup <- (Target + Addend)
  138. R_RISCV_SET8,
  139. /// Local label assignment
  140. ///
  141. /// Fixup expression:
  142. /// Fixup <- (Target + Addend)
  143. R_RISCV_SET16,
  144. /// Local label assignment
  145. ///
  146. /// Fixup expression:
  147. /// Fixup <- (Target + Addend)
  148. R_RISCV_SET32,
  149. };
  150. /// Returns a string name for the given riscv edge. For debugging purposes
  151. /// only
  152. const char *getEdgeKindName(Edge::Kind K);
  153. } // namespace riscv
  154. } // namespace jitlink
  155. } // namespace llvm
  156. #endif
  157. #ifdef __GNUC__
  158. #pragma GCC diagnostic pop
  159. #endif