llvminfo.pas 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. {
  2. Copyright (c) 2010, 2013, 2015 by Jonas Maebe
  3. Basic Processor information for LLVM
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. {$i fpcdefs.inc}
  18. Unit llvminfo;
  19. Interface
  20. uses
  21. globtype;
  22. {$j-}
  23. Type
  24. { supported LLVM versions }
  25. tllvmversion =
  26. (llvmver_invalid,
  27. { Xcode versions use snapshots of LLVM and don't correspond to released
  28. versions of llvm (they don't ship with the llvm utilities either, but
  29. they do come with clang, which is what we use as assembler) }
  30. llvmver_7_0,
  31. llvmver_7_1,
  32. llvmver_8_0,
  33. llvmver_xc_11,
  34. llvmver_9_0,
  35. llvmver_xc_11_4,
  36. llvmver_10_0,
  37. llvmver_xc_12,
  38. llvmver_11_0,
  39. llvmver_11_1,
  40. llvmver_xc_12_5,
  41. llvmver_12_0,
  42. llvmver_xc_13,
  43. llvmver_13_0,
  44. llvmver_xc_13_3,
  45. llvmver_xc_14_0,
  46. llvmver_14_0,
  47. llvmver_xc_14_3,
  48. llvmver_15_0,
  49. llvmver_16_0,
  50. llvmver_xc_15,
  51. llvmver_17_0
  52. );
  53. type
  54. tllvmversionflag = (
  55. llvmflag_constrained_fptrunc_fpext, { supports constrained fptrunc and fpext intrinsics }
  56. llvmflag_constrained_fptoi_itofp, { supports constrained fptosi/fptoui/uitofp/sitofp instrinsics }
  57. llvmflag_generic_constrained_si64tofp, { supports sitofp for 64 bit signed integers on all targets }
  58. llvmflag_null_pointer_valid_new, { new syntax for the null pointer valid attribute: null_pointer_is_valid (which indicates access to nil should not be optimized as undefined behaviour) }
  59. llvmflag_array_datalocation, { arrays debug info supports a dataLocation attribute to specify how to obtain the array data based on the array variable }
  60. llvmflag_NoDISPFlags, { no DI sub program flags, but separate fields }
  61. llvmflag_NoDISPFlagMainSubprogram, { MainSubprogram still in DIFlags instead of DISPFlags }
  62. llvmflag_para_attr_type, { parameter attributes such as noalias and byval need to repeat the type }
  63. llvmflag_opaque_ptr_transition, { initial opaque pointer introduction, needs to some elementtype attributes }
  64. llvmflag_opaque_ptr, { only opaque pointers }
  65. llvmflag_sanitizer_attributes, { can use attributes to exclude symbols from sanitizers }
  66. llvmflag_no_freeze, { lacks the freeze opcode to clear undefined/poison values }
  67. llvmflag_old_function_memory_attributes, { old-style memory attributes for functions (not currently generated by FPC) }
  68. llvmflag_no_threadlocal_address { no intrinsic to get threadlocal address }
  69. );
  70. tllvmversionflags = set of tllvmversionflag;
  71. Const
  72. llvmversionstr : array[tllvmversion] of string[14] = (
  73. '',
  74. '7.0',
  75. '7.1',
  76. '8.0',
  77. 'Xcode-11.0',
  78. '9.0',
  79. 'Xcode-11.4',
  80. '10.0',
  81. 'Xcode-12.0',
  82. '11.0',
  83. '11.1',
  84. 'Xcode-12.5',
  85. '12.0',
  86. 'Xcode-13.0',
  87. '13.0',
  88. 'Xcode-13.3',
  89. 'Xcode-14.0',
  90. '14.0',
  91. 'Xcode-14.3',
  92. '15.0',
  93. '16.0',
  94. 'Xcode-15',
  95. '17.0'
  96. );
  97. llvm_debuginfo_metadata_format : array[tllvmversion] of byte = (
  98. 0,
  99. 3,
  100. 3,
  101. 3,
  102. 3,
  103. 3,
  104. 3,
  105. 3,
  106. 3,
  107. 3,
  108. 3,
  109. 3,
  110. 3,
  111. 3,
  112. 3,
  113. 3,
  114. 3,
  115. 3,
  116. 3,
  117. 3,
  118. 3,
  119. 3,
  120. 3
  121. );
  122. llvmversion_properties: array[tllvmversion] of tllvmversionflags =
  123. (
  124. { invalid } [],
  125. { llvmver_7_0 } [llvmflag_NoDISPFlags,llvmflag_no_freeze, llvmflag_old_function_memory_attributes],
  126. { llvmver_7_1 } [llvmflag_NoDISPFlags,llvmflag_no_freeze, llvmflag_old_function_memory_attributes],
  127. { llvmver_8_0 } [llvmflag_NoDISPFlagMainSubprogram,llvmflag_no_freeze, llvmflag_old_function_memory_attributes],
  128. { llvmver_xc_11 } [llvmflag_NoDISPFlagMainSubprogram,llvmflag_no_freeze, llvmflag_old_function_memory_attributes],
  129. { llvmver_9_0 } [llvmflag_constrained_fptrunc_fpext,llvmflag_no_freeze, llvmflag_old_function_memory_attributes],
  130. { llvmver_xc_11_4 } [llvmflag_constrained_fptrunc_fpext,llvmflag_no_freeze, llvmflag_old_function_memory_attributes],
  131. { llvmver_10_0 } [llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp, llvmflag_old_function_memory_attributes],
  132. { llvmver_xc_12_0 } [llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp, llvmflag_old_function_memory_attributes],
  133. { llvmver_11_0 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation, llvmflag_old_function_memory_attributes],
  134. { llvmver_11_1 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation, llvmflag_old_function_memory_attributes],
  135. { llvmver_xc_12_5 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation, llvmflag_old_function_memory_attributes],
  136. { llvmver_12_0 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type, llvmflag_old_function_memory_attributes],
  137. { llvmver_xc_13_0 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type, llvmflag_old_function_memory_attributes],
  138. { llvmver_13_0 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type, llvmflag_old_function_memory_attributes],
  139. { llvmver_xc_13_3 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type, llvmflag_old_function_memory_attributes],
  140. { llvmver_xc_14_0 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type,llvmflag_old_function_memory_attributes],
  141. { llvmver_14_0 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type,llvmflag_opaque_ptr_transition, llvmflag_old_function_memory_attributes],
  142. { llvmver_xc_14_3 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type,llvmflag_opaque_ptr,llvmflag_sanitizer_attributes, llvmflag_old_function_memory_attributes],
  143. { llvmver_15_0 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type,llvmflag_opaque_ptr,llvmflag_sanitizer_attributes, llvmflag_old_function_memory_attributes],
  144. { llvmver_16_0 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type,llvmflag_opaque_ptr,llvmflag_sanitizer_attributes],
  145. { llvmver_xc_15 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type,llvmflag_opaque_ptr,llvmflag_sanitizer_attributes],
  146. { llvmver_17_0 } [llvmflag_null_pointer_valid_new,llvmflag_constrained_fptrunc_fpext,llvmflag_constrained_fptoi_itofp,llvmflag_array_datalocation,llvmflag_para_attr_type,llvmflag_opaque_ptr,llvmflag_sanitizer_attributes]
  147. );
  148. { Supported optimizations, only used for information }
  149. supported_optimizerswitches = genericlevel1optimizerswitches+
  150. genericlevel2optimizerswitches+
  151. genericlevel3optimizerswitches-
  152. { no need to write info about those }
  153. [cs_opt_level1,cs_opt_level2,cs_opt_level3]+
  154. [cs_opt_loopunroll,cs_opt_stackframe,
  155. cs_opt_nodecse,cs_opt_reorder_fields,cs_opt_fastmath];
  156. level1optimizerswitches = genericlevel1optimizerswitches;
  157. level2optimizerswitches = genericlevel2optimizerswitches + level1optimizerswitches + [cs_opt_nodecse,cs_opt_stackframe];
  158. level3optimizerswitches = genericlevel3optimizerswitches + level2optimizerswitches + [];
  159. level4optimizerswitches = genericlevel4optimizerswitches + level3optimizerswitches + [];
  160. function llvmversion2enum(const s: string): tllvmversion;
  161. Implementation
  162. function llvmversion2enum(const s: string): tllvmversion;
  163. begin
  164. for result:=succ(low(llvmversionstr)) to high(llvmversionstr) do
  165. begin
  166. if s=llvmversionstr[result] then
  167. exit;
  168. end;
  169. result:=llvmver_invalid;
  170. end;
  171. end.