target.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /* Data structure definitions for a generic GCC target.
  2. Copyright (C) 2001-2020 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the
  5. Free Software Foundation; either version 3, or (at your option) any
  6. later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; see the file COPYING3. If not see
  13. <http://www.gnu.org/licenses/>.
  14. In other words, you are welcome to use, share and improve this program.
  15. You are forbidden to forbid anyone else to use, share and improve
  16. what you give them. Help stamp out software-hoarding! */
  17. /* This file contains a data structure that describes a GCC target.
  18. At present it is incomplete, but in future it should grow to
  19. contain most or all target machine and target O/S specific
  20. information.
  21. This structure has its initializer declared in target-def.h in the
  22. form of large macro TARGET_INITIALIZER that expands to many smaller
  23. macros.
  24. The smaller macros each initialize one component of the structure,
  25. and each has a default. Each target should have a file that
  26. includes target.h and target-def.h, and overrides any inappropriate
  27. defaults by undefining the relevant macro and defining a suitable
  28. replacement. That file should then contain the definition of
  29. "targetm" like so:
  30. struct gcc_target targetm = TARGET_INITIALIZER;
  31. Doing things this way allows us to bring together everything that
  32. defines a GCC target. By supplying a default that is appropriate
  33. to most targets, we can easily add new items without needing to
  34. edit dozens of target configuration files. It should also allow us
  35. to gradually reduce the amount of conditional compilation that is
  36. scattered throughout GCC. */
  37. #ifndef GCC_TARGET_H
  38. #define GCC_TARGET_H
  39. #include "insn-codes.h"
  40. #include "tm.h"
  41. #include "hard-reg-set.h"
  42. #if CHECKING_P
  43. struct cumulative_args_t { void *magic; void *p; };
  44. #else /* !CHECKING_P */
  45. /* When using a GCC build compiler, we could use
  46. __attribute__((transparent_union)) to get cumulative_args_t function
  47. arguments passed like scalars where the ABI would mandate a less
  48. efficient way of argument passing otherwise. However, that would come
  49. at the cost of less type-safe !CHECKING_P compilation. */
  50. union cumulative_args_t { void *p; };
  51. #endif /* !CHECKING_P */
  52. /* Types used by the record_gcc_switches() target function. */
  53. enum print_switch_type
  54. {
  55. SWITCH_TYPE_PASSED, /* A switch passed on the command line. */
  56. SWITCH_TYPE_ENABLED, /* An option that is currently enabled. */
  57. SWITCH_TYPE_DESCRIPTIVE, /* Descriptive text, not a switch or option. */
  58. SWITCH_TYPE_LINE_START, /* Please emit any necessary text at the start of a line. */
  59. SWITCH_TYPE_LINE_END /* Please emit a line terminator. */
  60. };
  61. /* Types of memory operation understood by the "by_pieces" infrastructure.
  62. Used by the TARGET_USE_BY_PIECES_INFRASTRUCTURE_P target hook and
  63. internally by the functions in expr.c. */
  64. enum by_pieces_operation
  65. {
  66. CLEAR_BY_PIECES,
  67. MOVE_BY_PIECES,
  68. SET_BY_PIECES,
  69. STORE_BY_PIECES,
  70. COMPARE_BY_PIECES
  71. };
  72. extern unsigned HOST_WIDE_INT by_pieces_ninsns (unsigned HOST_WIDE_INT,
  73. unsigned int,
  74. unsigned int,
  75. by_pieces_operation);
  76. typedef int (* print_switch_fn_type) (print_switch_type, const char *);
  77. /* An example implementation for ELF targets. Defined in varasm.c */
  78. extern int elf_record_gcc_switches (print_switch_type type, const char *);
  79. /* Some places still assume that all pointer or address modes are the
  80. standard Pmode and ptr_mode. These optimizations become invalid if
  81. the target actually supports multiple different modes. For now,
  82. we disable such optimizations on such targets, using this function. */
  83. extern bool target_default_pointer_address_modes_p (void);
  84. /* For hooks which use the MOVE_RATIO macro, this gives the legacy default
  85. behavior. */
  86. extern unsigned int get_move_ratio (bool);
  87. struct stdarg_info;
  88. struct spec_info_def;
  89. struct hard_reg_set_container;
  90. struct cgraph_node;
  91. struct cgraph_simd_clone;
  92. /* The struct used by the secondary_reload target hook. */
  93. struct secondary_reload_info
  94. {
  95. /* icode is actually an enum insn_code, but we don't want to force every
  96. file that includes target.h to include optabs.h . */
  97. int icode;
  98. int extra_cost; /* Cost for using (a) scratch register(s) to be taken
  99. into account by copy_cost. */
  100. /* The next two members are for the use of the backward
  101. compatibility hook. */
  102. struct secondary_reload_info *prev_sri;
  103. int t_icode; /* Actually an enum insn_code - see above. */
  104. };
  105. /* This is defined in sched-int.h . */
  106. struct _dep;
  107. /* This is defined in ddg.h . */
  108. struct ddg;
  109. /* This is defined in cfgloop.h . */
  110. class loop;
  111. /* This is defined in ifcvt.h. */
  112. struct noce_if_info;
  113. /* This is defined in tree-ssa-alias.h. */
  114. class ao_ref;
  115. /* This is defined in tree-vectorizer.h. */
  116. class _stmt_vec_info;
  117. /* This is defined in calls.h. */
  118. class function_arg_info;
  119. /* This is defined in function-abi.h. */
  120. class predefined_function_abi;
  121. /* These are defined in tree-vect-stmts.c. */
  122. extern tree stmt_vectype (class _stmt_vec_info *);
  123. extern bool stmt_in_inner_loop_p (class _stmt_vec_info *);
  124. /* Assembler instructions for creating various kinds of integer object. */
  125. struct asm_int_op
  126. {
  127. const char *hi;
  128. const char *psi;
  129. const char *si;
  130. const char *pdi;
  131. const char *di;
  132. const char *pti;
  133. const char *ti;
  134. };
  135. /* Types of costs for vectorizer cost model. */
  136. enum vect_cost_for_stmt
  137. {
  138. scalar_stmt,
  139. scalar_load,
  140. scalar_store,
  141. vector_stmt,
  142. vector_load,
  143. vector_gather_load,
  144. unaligned_load,
  145. unaligned_store,
  146. vector_store,
  147. vector_scatter_store,
  148. vec_to_scalar,
  149. scalar_to_vec,
  150. cond_branch_not_taken,
  151. cond_branch_taken,
  152. vec_perm,
  153. vec_promote_demote,
  154. vec_construct
  155. };
  156. /* Separate locations for which the vectorizer cost model should
  157. track costs. */
  158. enum vect_cost_model_location {
  159. vect_prologue = 0,
  160. vect_body = 1,
  161. vect_epilogue = 2
  162. };
  163. class vec_perm_indices;
  164. /* The type to use for lists of vector sizes. */
  165. typedef vec<machine_mode> vector_modes;
  166. /* Same, but can be used to construct local lists that are
  167. automatically freed. */
  168. typedef auto_vec<machine_mode, 8> auto_vector_modes;
  169. /* First argument of targetm.omp.device_kind_arch_isa. */
  170. enum omp_device_kind_arch_isa {
  171. omp_device_kind,
  172. omp_device_arch,
  173. omp_device_isa
  174. };
  175. /* Flags returned by TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES:
  176. VECT_COMPARE_COSTS
  177. Tells the loop vectorizer to try all the provided modes and
  178. pick the one with the lowest cost. By default the vectorizer
  179. will choose the first mode that works. */
  180. const unsigned int VECT_COMPARE_COSTS = 1U << 0;
  181. /* The contexts in which the use of a type T can be checked by
  182. TARGET_VERIFY_TYPE_CONTEXT. */
  183. enum type_context_kind {
  184. /* Directly measuring the size of T. */
  185. TCTX_SIZEOF,
  186. /* Directly measuring the alignment of T. */
  187. TCTX_ALIGNOF,
  188. /* Creating objects of type T with static storage duration. */
  189. TCTX_STATIC_STORAGE,
  190. /* Creating objects of type T with thread-local storage duration. */
  191. TCTX_THREAD_STORAGE,
  192. /* Creating a field of type T. */
  193. TCTX_FIELD,
  194. /* Creating an array with elements of type T. */
  195. TCTX_ARRAY_ELEMENT,
  196. /* Adding to or subtracting from a pointer to T, or computing the
  197. difference between two pointers when one of them is a pointer to T. */
  198. TCTX_POINTER_ARITH,
  199. /* Dynamically allocating objects of type T. */
  200. TCTX_ALLOCATION,
  201. /* Dynamically deallocating objects of type T. */
  202. TCTX_DEALLOCATION,
  203. /* Throwing or catching an object of type T. */
  204. TCTX_EXCEPTIONS,
  205. /* Capturing objects of type T by value in a closure. */
  206. TCTX_CAPTURE_BY_COPY
  207. };
  208. extern bool verify_type_context (location_t, type_context_kind, const_tree,
  209. bool = false);
  210. /* The target structure. This holds all the backend hooks. */
  211. #define DEFHOOKPOD(NAME, DOC, TYPE, INIT) TYPE NAME;
  212. #define DEFHOOK(NAME, DOC, TYPE, PARAMS, INIT) TYPE (* NAME) PARAMS;
  213. #define DEFHOOK_UNDOC DEFHOOK
  214. #define HOOKSTRUCT(FRAGMENT) FRAGMENT
  215. #include "target.def"
  216. extern struct gcc_target targetm;
  217. /* Return an estimate of the runtime value of X, for use in things
  218. like cost calculations or profiling frequencies. Note that this
  219. function should never be used in situations where the actual
  220. runtime value is needed for correctness, since the function only
  221. provides a rough guess. */
  222. static inline HOST_WIDE_INT
  223. estimated_poly_value (poly_int64 x)
  224. {
  225. if (NUM_POLY_INT_COEFFS == 1)
  226. return x.coeffs[0];
  227. else
  228. return targetm.estimated_poly_value (x);
  229. }
  230. #ifdef GCC_TM_H
  231. #ifndef CUMULATIVE_ARGS_MAGIC
  232. #define CUMULATIVE_ARGS_MAGIC ((void *) &targetm.calls)
  233. #endif
  234. static inline CUMULATIVE_ARGS *
  235. get_cumulative_args (cumulative_args_t arg)
  236. {
  237. #if CHECKING_P
  238. gcc_assert (arg.magic == CUMULATIVE_ARGS_MAGIC);
  239. #endif /* CHECKING_P */
  240. return (CUMULATIVE_ARGS *) arg.p;
  241. }
  242. static inline cumulative_args_t
  243. pack_cumulative_args (CUMULATIVE_ARGS *arg)
  244. {
  245. cumulative_args_t ret;
  246. #if CHECKING_P
  247. ret.magic = CUMULATIVE_ARGS_MAGIC;
  248. #endif /* CHECKING_P */
  249. ret.p = (void *) arg;
  250. return ret;
  251. }
  252. #endif /* GCC_TM_H */
  253. #endif /* GCC_TARGET_H */