ira-int.h 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542
  1. /* Integrated Register Allocator (IRA) intercommunication header file.
  2. Copyright (C) 2006-2020 Free Software Foundation, Inc.
  3. Contributed by Vladimir Makarov <vmakarov@redhat.com>.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_IRA_INT_H
  17. #define GCC_IRA_INT_H
  18. #include "recog.h"
  19. #include "function-abi.h"
  20. /* To provide consistency in naming, all IRA external variables,
  21. functions, common typedefs start with prefix ira_. */
  22. #if CHECKING_P
  23. #define ENABLE_IRA_CHECKING
  24. #endif
  25. #ifdef ENABLE_IRA_CHECKING
  26. #define ira_assert(c) gcc_assert (c)
  27. #else
  28. /* Always define and include C, so that warnings for empty body in an
  29. 'if' statement and unused variable do not occur. */
  30. #define ira_assert(c) ((void)(0 && (c)))
  31. #endif
  32. /* Compute register frequency from edge frequency FREQ. It is
  33. analogous to REG_FREQ_FROM_BB. When optimizing for size, or
  34. profile driven feedback is available and the function is never
  35. executed, frequency is always equivalent. Otherwise rescale the
  36. edge frequency. */
  37. #define REG_FREQ_FROM_EDGE_FREQ(freq) \
  38. (optimize_function_for_size_p (cfun) \
  39. ? REG_FREQ_MAX : (freq * REG_FREQ_MAX / BB_FREQ_MAX) \
  40. ? (freq * REG_FREQ_MAX / BB_FREQ_MAX) : 1)
  41. /* A modified value of flag `-fira-verbose' used internally. */
  42. extern int internal_flag_ira_verbose;
  43. /* Dump file of the allocator if it is not NULL. */
  44. extern FILE *ira_dump_file;
  45. /* Typedefs for pointers to allocno live range, allocno, and copy of
  46. allocnos. */
  47. typedef struct live_range *live_range_t;
  48. typedef struct ira_allocno *ira_allocno_t;
  49. typedef struct ira_allocno_pref *ira_pref_t;
  50. typedef struct ira_allocno_copy *ira_copy_t;
  51. typedef struct ira_object *ira_object_t;
  52. /* Definition of vector of allocnos and copies. */
  53. /* Typedef for pointer to the subsequent structure. */
  54. typedef struct ira_loop_tree_node *ira_loop_tree_node_t;
  55. typedef unsigned short move_table[N_REG_CLASSES];
  56. /* In general case, IRA is a regional allocator. The regions are
  57. nested and form a tree. Currently regions are natural loops. The
  58. following structure describes loop tree node (representing basic
  59. block or loop). We need such tree because the loop tree from
  60. cfgloop.h is not convenient for the optimization: basic blocks are
  61. not a part of the tree from cfgloop.h. We also use the nodes for
  62. storing additional information about basic blocks/loops for the
  63. register allocation purposes. */
  64. struct ira_loop_tree_node
  65. {
  66. /* The node represents basic block if children == NULL. */
  67. basic_block bb; /* NULL for loop. */
  68. /* NULL for BB or for loop tree root if we did not build CFG loop tree. */
  69. class loop *loop;
  70. /* NEXT/SUBLOOP_NEXT is the next node/loop-node of the same parent.
  71. SUBLOOP_NEXT is always NULL for BBs. */
  72. ira_loop_tree_node_t subloop_next, next;
  73. /* CHILDREN/SUBLOOPS is the first node/loop-node immediately inside
  74. the node. They are NULL for BBs. */
  75. ira_loop_tree_node_t subloops, children;
  76. /* The node immediately containing given node. */
  77. ira_loop_tree_node_t parent;
  78. /* Loop level in range [0, ira_loop_tree_height). */
  79. int level;
  80. /* All the following members are defined only for nodes representing
  81. loops. */
  82. /* The loop number from CFG loop tree. The root number is 0. */
  83. int loop_num;
  84. /* True if the loop was marked for removal from the register
  85. allocation. */
  86. bool to_remove_p;
  87. /* Allocnos in the loop corresponding to their regnos. If it is
  88. NULL the loop does not form a separate register allocation region
  89. (e.g. because it has abnormal enter/exit edges and we cannot put
  90. code for register shuffling on the edges if a different
  91. allocation is used for a pseudo-register on different sides of
  92. the edges). Caps are not in the map (remember we can have more
  93. one cap with the same regno in a region). */
  94. ira_allocno_t *regno_allocno_map;
  95. /* True if there is an entry to given loop not from its parent (or
  96. grandparent) basic block. For example, it is possible for two
  97. adjacent loops inside another loop. */
  98. bool entered_from_non_parent_p;
  99. /* Maximal register pressure inside loop for given register class
  100. (defined only for the pressure classes). */
  101. int reg_pressure[N_REG_CLASSES];
  102. /* Numbers of allocnos referred or living in the loop node (except
  103. for its subloops). */
  104. bitmap all_allocnos;
  105. /* Numbers of allocnos living at the loop borders. */
  106. bitmap border_allocnos;
  107. /* Regnos of pseudos modified in the loop node (including its
  108. subloops). */
  109. bitmap modified_regnos;
  110. /* Numbers of copies referred in the corresponding loop. */
  111. bitmap local_copies;
  112. };
  113. /* The root of the loop tree corresponding to the all function. */
  114. extern ira_loop_tree_node_t ira_loop_tree_root;
  115. /* Height of the loop tree. */
  116. extern int ira_loop_tree_height;
  117. /* All nodes representing basic blocks are referred through the
  118. following array. We cannot use basic block member `aux' for this
  119. because it is used for insertion of insns on edges. */
  120. extern ira_loop_tree_node_t ira_bb_nodes;
  121. /* Two access macros to the nodes representing basic blocks. */
  122. #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
  123. #define IRA_BB_NODE_BY_INDEX(index) __extension__ \
  124. (({ ira_loop_tree_node_t _node = (&ira_bb_nodes[index]); \
  125. if (_node->children != NULL || _node->loop != NULL || _node->bb == NULL)\
  126. { \
  127. fprintf (stderr, \
  128. "\n%s: %d: error in %s: it is not a block node\n", \
  129. __FILE__, __LINE__, __FUNCTION__); \
  130. gcc_unreachable (); \
  131. } \
  132. _node; }))
  133. #else
  134. #define IRA_BB_NODE_BY_INDEX(index) (&ira_bb_nodes[index])
  135. #endif
  136. #define IRA_BB_NODE(bb) IRA_BB_NODE_BY_INDEX ((bb)->index)
  137. /* All nodes representing loops are referred through the following
  138. array. */
  139. extern ira_loop_tree_node_t ira_loop_nodes;
  140. /* Two access macros to the nodes representing loops. */
  141. #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
  142. #define IRA_LOOP_NODE_BY_INDEX(index) __extension__ \
  143. (({ ira_loop_tree_node_t const _node = (&ira_loop_nodes[index]); \
  144. if (_node->children == NULL || _node->bb != NULL \
  145. || (_node->loop == NULL && current_loops != NULL)) \
  146. { \
  147. fprintf (stderr, \
  148. "\n%s: %d: error in %s: it is not a loop node\n", \
  149. __FILE__, __LINE__, __FUNCTION__); \
  150. gcc_unreachable (); \
  151. } \
  152. _node; }))
  153. #else
  154. #define IRA_LOOP_NODE_BY_INDEX(index) (&ira_loop_nodes[index])
  155. #endif
  156. #define IRA_LOOP_NODE(loop) IRA_LOOP_NODE_BY_INDEX ((loop)->num)
  157. /* The structure describes program points where a given allocno lives.
  158. If the live ranges of two allocnos are intersected, the allocnos
  159. are in conflict. */
  160. struct live_range
  161. {
  162. /* Object whose live range is described by given structure. */
  163. ira_object_t object;
  164. /* Program point range. */
  165. int start, finish;
  166. /* Next structure describing program points where the allocno
  167. lives. */
  168. live_range_t next;
  169. /* Pointer to structures with the same start/finish. */
  170. live_range_t start_next, finish_next;
  171. };
  172. /* Program points are enumerated by numbers from range
  173. 0..IRA_MAX_POINT-1. There are approximately two times more program
  174. points than insns. Program points are places in the program where
  175. liveness info can be changed. In most general case (there are more
  176. complicated cases too) some program points correspond to places
  177. where input operand dies and other ones correspond to places where
  178. output operands are born. */
  179. extern int ira_max_point;
  180. /* Arrays of size IRA_MAX_POINT mapping a program point to the allocno
  181. live ranges with given start/finish point. */
  182. extern live_range_t *ira_start_point_ranges, *ira_finish_point_ranges;
  183. /* A structure representing conflict information for an allocno
  184. (or one of its subwords). */
  185. struct ira_object
  186. {
  187. /* The allocno associated with this record. */
  188. ira_allocno_t allocno;
  189. /* Vector of accumulated conflicting conflict_redords with NULL end
  190. marker (if OBJECT_CONFLICT_VEC_P is true) or conflict bit vector
  191. otherwise. */
  192. void *conflicts_array;
  193. /* Pointer to structures describing at what program point the
  194. object lives. We always maintain the list in such way that *the
  195. ranges in the list are not intersected and ordered by decreasing
  196. their program points*. */
  197. live_range_t live_ranges;
  198. /* The subword within ALLOCNO which is represented by this object.
  199. Zero means the lowest-order subword (or the entire allocno in case
  200. it is not being tracked in subwords). */
  201. int subword;
  202. /* Allocated size of the conflicts array. */
  203. unsigned int conflicts_array_size;
  204. /* A unique number for every instance of this structure, which is used
  205. to represent it in conflict bit vectors. */
  206. int id;
  207. /* Before building conflicts, MIN and MAX are initialized to
  208. correspondingly minimal and maximal points of the accumulated
  209. live ranges. Afterwards, they hold the minimal and maximal ids
  210. of other ira_objects that this one can conflict with. */
  211. int min, max;
  212. /* Initial and accumulated hard registers conflicting with this
  213. object and as a consequences cannot be assigned to the allocno.
  214. All non-allocatable hard regs and hard regs of register classes
  215. different from given allocno one are included in the sets. */
  216. HARD_REG_SET conflict_hard_regs, total_conflict_hard_regs;
  217. /* Number of accumulated conflicts in the vector of conflicting
  218. objects. */
  219. int num_accumulated_conflicts;
  220. /* TRUE if conflicts are represented by a vector of pointers to
  221. ira_object structures. Otherwise, we use a bit vector indexed
  222. by conflict ID numbers. */
  223. unsigned int conflict_vec_p : 1;
  224. };
  225. /* A structure representing an allocno (allocation entity). Allocno
  226. represents a pseudo-register in an allocation region. If
  227. pseudo-register does not live in a region but it lives in the
  228. nested regions, it is represented in the region by special allocno
  229. called *cap*. There may be more one cap representing the same
  230. pseudo-register in region. It means that the corresponding
  231. pseudo-register lives in more one non-intersected subregion. */
  232. struct ira_allocno
  233. {
  234. /* The allocno order number starting with 0. Each allocno has an
  235. unique number and the number is never changed for the
  236. allocno. */
  237. int num;
  238. /* Regno for allocno or cap. */
  239. int regno;
  240. /* Mode of the allocno which is the mode of the corresponding
  241. pseudo-register. */
  242. ENUM_BITFIELD (machine_mode) mode : 8;
  243. /* Widest mode of the allocno which in at least one case could be
  244. for paradoxical subregs where wmode > mode. */
  245. ENUM_BITFIELD (machine_mode) wmode : 8;
  246. /* Register class which should be used for allocation for given
  247. allocno. NO_REGS means that we should use memory. */
  248. ENUM_BITFIELD (reg_class) aclass : 16;
  249. /* A bitmask of the ABIs used by calls that occur while the allocno
  250. is live. */
  251. unsigned int crossed_calls_abis : NUM_ABI_IDS;
  252. /* During the reload, value TRUE means that we should not reassign a
  253. hard register to the allocno got memory earlier. It is set up
  254. when we removed memory-memory move insn before each iteration of
  255. the reload. */
  256. unsigned int dont_reassign_p : 1;
  257. #ifdef STACK_REGS
  258. /* Set to TRUE if allocno can't be assigned to the stack hard
  259. register correspondingly in this region and area including the
  260. region and all its subregions recursively. */
  261. unsigned int no_stack_reg_p : 1, total_no_stack_reg_p : 1;
  262. #endif
  263. /* TRUE value means that there is no sense to spill the allocno
  264. during coloring because the spill will result in additional
  265. reloads in reload pass. */
  266. unsigned int bad_spill_p : 1;
  267. /* TRUE if a hard register or memory has been assigned to the
  268. allocno. */
  269. unsigned int assigned_p : 1;
  270. /* TRUE if conflicts for given allocno are represented by vector of
  271. pointers to the conflicting allocnos. Otherwise, we use a bit
  272. vector where a bit with given index represents allocno with the
  273. same number. */
  274. unsigned int conflict_vec_p : 1;
  275. /* Hard register assigned to given allocno. Negative value means
  276. that memory was allocated to the allocno. During the reload,
  277. spilled allocno has value equal to the corresponding stack slot
  278. number (0, ...) - 2. Value -1 is used for allocnos spilled by the
  279. reload (at this point pseudo-register has only one allocno) which
  280. did not get stack slot yet. */
  281. signed int hard_regno : 16;
  282. /* Allocnos with the same regno are linked by the following member.
  283. Allocnos corresponding to inner loops are first in the list (it
  284. corresponds to depth-first traverse of the loops). */
  285. ira_allocno_t next_regno_allocno;
  286. /* There may be different allocnos with the same regno in different
  287. regions. Allocnos are bound to the corresponding loop tree node.
  288. Pseudo-register may have only one regular allocno with given loop
  289. tree node but more than one cap (see comments above). */
  290. ira_loop_tree_node_t loop_tree_node;
  291. /* Accumulated usage references of the allocno. Here and below,
  292. word 'accumulated' means info for given region and all nested
  293. subregions. In this case, 'accumulated' means sum of references
  294. of the corresponding pseudo-register in this region and in all
  295. nested subregions recursively. */
  296. int nrefs;
  297. /* Accumulated frequency of usage of the allocno. */
  298. int freq;
  299. /* Minimal accumulated and updated costs of usage register of the
  300. allocno class. */
  301. int class_cost, updated_class_cost;
  302. /* Minimal accumulated, and updated costs of memory for the allocno.
  303. At the allocation start, the original and updated costs are
  304. equal. The updated cost may be changed after finishing
  305. allocation in a region and starting allocation in a subregion.
  306. The change reflects the cost of spill/restore code on the
  307. subregion border if we assign memory to the pseudo in the
  308. subregion. */
  309. int memory_cost, updated_memory_cost;
  310. /* Accumulated number of points where the allocno lives and there is
  311. excess pressure for its class. Excess pressure for a register
  312. class at some point means that there are more allocnos of given
  313. register class living at the point than number of hard-registers
  314. of the class available for the allocation. */
  315. int excess_pressure_points_num;
  316. /* Allocno hard reg preferences. */
  317. ira_pref_t allocno_prefs;
  318. /* Copies to other non-conflicting allocnos. The copies can
  319. represent move insn or potential move insn usually because of two
  320. operand insn constraints. */
  321. ira_copy_t allocno_copies;
  322. /* It is a allocno (cap) representing given allocno on upper loop tree
  323. level. */
  324. ira_allocno_t cap;
  325. /* It is a link to allocno (cap) on lower loop level represented by
  326. given cap. Null if given allocno is not a cap. */
  327. ira_allocno_t cap_member;
  328. /* The number of objects tracked in the following array. */
  329. int num_objects;
  330. /* An array of structures describing conflict information and live
  331. ranges for each object associated with the allocno. There may be
  332. more than one such object in cases where the allocno represents a
  333. multi-word register. */
  334. ira_object_t objects[2];
  335. /* Accumulated frequency of calls which given allocno
  336. intersects. */
  337. int call_freq;
  338. /* Accumulated number of the intersected calls. */
  339. int calls_crossed_num;
  340. /* The number of calls across which it is live, but which should not
  341. affect register preferences. */
  342. int cheap_calls_crossed_num;
  343. /* Registers clobbered by intersected calls. */
  344. HARD_REG_SET crossed_calls_clobbered_regs;
  345. /* Array of usage costs (accumulated and the one updated during
  346. coloring) for each hard register of the allocno class. The
  347. member value can be NULL if all costs are the same and equal to
  348. CLASS_COST. For example, the costs of two different hard
  349. registers can be different if one hard register is callee-saved
  350. and another one is callee-used and the allocno lives through
  351. calls. Another example can be case when for some insn the
  352. corresponding pseudo-register value should be put in specific
  353. register class (e.g. AREG for x86) which is a strict subset of
  354. the allocno class (GENERAL_REGS for x86). We have updated costs
  355. to reflect the situation when the usage cost of a hard register
  356. is decreased because the allocno is connected to another allocno
  357. by a copy and the another allocno has been assigned to the hard
  358. register. */
  359. int *hard_reg_costs, *updated_hard_reg_costs;
  360. /* Array of decreasing costs (accumulated and the one updated during
  361. coloring) for allocnos conflicting with given allocno for hard
  362. regno of the allocno class. The member value can be NULL if all
  363. costs are the same. These costs are used to reflect preferences
  364. of other allocnos not assigned yet during assigning to given
  365. allocno. */
  366. int *conflict_hard_reg_costs, *updated_conflict_hard_reg_costs;
  367. /* Different additional data. It is used to decrease size of
  368. allocno data footprint. */
  369. void *add_data;
  370. };
  371. /* All members of the allocno structures should be accessed only
  372. through the following macros. */
  373. #define ALLOCNO_NUM(A) ((A)->num)
  374. #define ALLOCNO_REGNO(A) ((A)->regno)
  375. #define ALLOCNO_REG(A) ((A)->reg)
  376. #define ALLOCNO_NEXT_REGNO_ALLOCNO(A) ((A)->next_regno_allocno)
  377. #define ALLOCNO_LOOP_TREE_NODE(A) ((A)->loop_tree_node)
  378. #define ALLOCNO_CAP(A) ((A)->cap)
  379. #define ALLOCNO_CAP_MEMBER(A) ((A)->cap_member)
  380. #define ALLOCNO_NREFS(A) ((A)->nrefs)
  381. #define ALLOCNO_FREQ(A) ((A)->freq)
  382. #define ALLOCNO_HARD_REGNO(A) ((A)->hard_regno)
  383. #define ALLOCNO_CALL_FREQ(A) ((A)->call_freq)
  384. #define ALLOCNO_CALLS_CROSSED_NUM(A) ((A)->calls_crossed_num)
  385. #define ALLOCNO_CHEAP_CALLS_CROSSED_NUM(A) ((A)->cheap_calls_crossed_num)
  386. #define ALLOCNO_CROSSED_CALLS_ABIS(A) ((A)->crossed_calls_abis)
  387. #define ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS(A) \
  388. ((A)->crossed_calls_clobbered_regs)
  389. #define ALLOCNO_MEM_OPTIMIZED_DEST(A) ((A)->mem_optimized_dest)
  390. #define ALLOCNO_MEM_OPTIMIZED_DEST_P(A) ((A)->mem_optimized_dest_p)
  391. #define ALLOCNO_SOMEWHERE_RENAMED_P(A) ((A)->somewhere_renamed_p)
  392. #define ALLOCNO_CHILD_RENAMED_P(A) ((A)->child_renamed_p)
  393. #define ALLOCNO_DONT_REASSIGN_P(A) ((A)->dont_reassign_p)
  394. #ifdef STACK_REGS
  395. #define ALLOCNO_NO_STACK_REG_P(A) ((A)->no_stack_reg_p)
  396. #define ALLOCNO_TOTAL_NO_STACK_REG_P(A) ((A)->total_no_stack_reg_p)
  397. #endif
  398. #define ALLOCNO_BAD_SPILL_P(A) ((A)->bad_spill_p)
  399. #define ALLOCNO_ASSIGNED_P(A) ((A)->assigned_p)
  400. #define ALLOCNO_MODE(A) ((A)->mode)
  401. #define ALLOCNO_WMODE(A) ((A)->wmode)
  402. #define ALLOCNO_PREFS(A) ((A)->allocno_prefs)
  403. #define ALLOCNO_COPIES(A) ((A)->allocno_copies)
  404. #define ALLOCNO_HARD_REG_COSTS(A) ((A)->hard_reg_costs)
  405. #define ALLOCNO_UPDATED_HARD_REG_COSTS(A) ((A)->updated_hard_reg_costs)
  406. #define ALLOCNO_CONFLICT_HARD_REG_COSTS(A) \
  407. ((A)->conflict_hard_reg_costs)
  408. #define ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS(A) \
  409. ((A)->updated_conflict_hard_reg_costs)
  410. #define ALLOCNO_CLASS(A) ((A)->aclass)
  411. #define ALLOCNO_CLASS_COST(A) ((A)->class_cost)
  412. #define ALLOCNO_UPDATED_CLASS_COST(A) ((A)->updated_class_cost)
  413. #define ALLOCNO_MEMORY_COST(A) ((A)->memory_cost)
  414. #define ALLOCNO_UPDATED_MEMORY_COST(A) ((A)->updated_memory_cost)
  415. #define ALLOCNO_EXCESS_PRESSURE_POINTS_NUM(A) \
  416. ((A)->excess_pressure_points_num)
  417. #define ALLOCNO_OBJECT(A,N) ((A)->objects[N])
  418. #define ALLOCNO_NUM_OBJECTS(A) ((A)->num_objects)
  419. #define ALLOCNO_ADD_DATA(A) ((A)->add_data)
  420. /* Typedef for pointer to the subsequent structure. */
  421. typedef struct ira_emit_data *ira_emit_data_t;
  422. /* Allocno bound data used for emit pseudo live range split insns and
  423. to flattening IR. */
  424. struct ira_emit_data
  425. {
  426. /* TRUE if the allocno assigned to memory was a destination of
  427. removed move (see ira-emit.c) at loop exit because the value of
  428. the corresponding pseudo-register is not changed inside the
  429. loop. */
  430. unsigned int mem_optimized_dest_p : 1;
  431. /* TRUE if the corresponding pseudo-register has disjoint live
  432. ranges and the other allocnos of the pseudo-register except this
  433. one changed REG. */
  434. unsigned int somewhere_renamed_p : 1;
  435. /* TRUE if allocno with the same REGNO in a subregion has been
  436. renamed, in other words, got a new pseudo-register. */
  437. unsigned int child_renamed_p : 1;
  438. /* Final rtx representation of the allocno. */
  439. rtx reg;
  440. /* Non NULL if we remove restoring value from given allocno to
  441. MEM_OPTIMIZED_DEST at loop exit (see ira-emit.c) because the
  442. allocno value is not changed inside the loop. */
  443. ira_allocno_t mem_optimized_dest;
  444. };
  445. #define ALLOCNO_EMIT_DATA(a) ((ira_emit_data_t) ALLOCNO_ADD_DATA (a))
  446. /* Data used to emit live range split insns and to flattening IR. */
  447. extern ira_emit_data_t ira_allocno_emit_data;
  448. /* Abbreviation for frequent emit data access. */
  449. static inline rtx
  450. allocno_emit_reg (ira_allocno_t a)
  451. {
  452. return ALLOCNO_EMIT_DATA (a)->reg;
  453. }
  454. #define OBJECT_ALLOCNO(O) ((O)->allocno)
  455. #define OBJECT_SUBWORD(O) ((O)->subword)
  456. #define OBJECT_CONFLICT_ARRAY(O) ((O)->conflicts_array)
  457. #define OBJECT_CONFLICT_VEC(O) ((ira_object_t *)(O)->conflicts_array)
  458. #define OBJECT_CONFLICT_BITVEC(O) ((IRA_INT_TYPE *)(O)->conflicts_array)
  459. #define OBJECT_CONFLICT_ARRAY_SIZE(O) ((O)->conflicts_array_size)
  460. #define OBJECT_CONFLICT_VEC_P(O) ((O)->conflict_vec_p)
  461. #define OBJECT_NUM_CONFLICTS(O) ((O)->num_accumulated_conflicts)
  462. #define OBJECT_CONFLICT_HARD_REGS(O) ((O)->conflict_hard_regs)
  463. #define OBJECT_TOTAL_CONFLICT_HARD_REGS(O) ((O)->total_conflict_hard_regs)
  464. #define OBJECT_MIN(O) ((O)->min)
  465. #define OBJECT_MAX(O) ((O)->max)
  466. #define OBJECT_CONFLICT_ID(O) ((O)->id)
  467. #define OBJECT_LIVE_RANGES(O) ((O)->live_ranges)
  468. /* Map regno -> allocnos with given regno (see comments for
  469. allocno member `next_regno_allocno'). */
  470. extern ira_allocno_t *ira_regno_allocno_map;
  471. /* Array of references to all allocnos. The order number of the
  472. allocno corresponds to the index in the array. Removed allocnos
  473. have NULL element value. */
  474. extern ira_allocno_t *ira_allocnos;
  475. /* The size of the previous array. */
  476. extern int ira_allocnos_num;
  477. /* Map a conflict id to its corresponding ira_object structure. */
  478. extern ira_object_t *ira_object_id_map;
  479. /* The size of the previous array. */
  480. extern int ira_objects_num;
  481. /* The following structure represents a hard register preference of
  482. allocno. The preference represent move insns or potential move
  483. insns usually because of two operand insn constraints. One move
  484. operand is a hard register. */
  485. struct ira_allocno_pref
  486. {
  487. /* The unique order number of the preference node starting with 0. */
  488. int num;
  489. /* Preferred hard register. */
  490. int hard_regno;
  491. /* Accumulated execution frequency of insns from which the
  492. preference created. */
  493. int freq;
  494. /* Given allocno. */
  495. ira_allocno_t allocno;
  496. /* All preferences with the same allocno are linked by the following
  497. member. */
  498. ira_pref_t next_pref;
  499. };
  500. /* Array of references to all allocno preferences. The order number
  501. of the preference corresponds to the index in the array. */
  502. extern ira_pref_t *ira_prefs;
  503. /* Size of the previous array. */
  504. extern int ira_prefs_num;
  505. /* The following structure represents a copy of two allocnos. The
  506. copies represent move insns or potential move insns usually because
  507. of two operand insn constraints. To remove register shuffle, we
  508. also create copies between allocno which is output of an insn and
  509. allocno becoming dead in the insn. */
  510. struct ira_allocno_copy
  511. {
  512. /* The unique order number of the copy node starting with 0. */
  513. int num;
  514. /* Allocnos connected by the copy. The first allocno should have
  515. smaller order number than the second one. */
  516. ira_allocno_t first, second;
  517. /* Execution frequency of the copy. */
  518. int freq;
  519. bool constraint_p;
  520. /* It is a move insn which is an origin of the copy. The member
  521. value for the copy representing two operand insn constraints or
  522. for the copy created to remove register shuffle is NULL. In last
  523. case the copy frequency is smaller than the corresponding insn
  524. execution frequency. */
  525. rtx_insn *insn;
  526. /* All copies with the same allocno as FIRST are linked by the two
  527. following members. */
  528. ira_copy_t prev_first_allocno_copy, next_first_allocno_copy;
  529. /* All copies with the same allocno as SECOND are linked by the two
  530. following members. */
  531. ira_copy_t prev_second_allocno_copy, next_second_allocno_copy;
  532. /* Region from which given copy is originated. */
  533. ira_loop_tree_node_t loop_tree_node;
  534. };
  535. /* Array of references to all copies. The order number of the copy
  536. corresponds to the index in the array. Removed copies have NULL
  537. element value. */
  538. extern ira_copy_t *ira_copies;
  539. /* Size of the previous array. */
  540. extern int ira_copies_num;
  541. /* The following structure describes a stack slot used for spilled
  542. pseudo-registers. */
  543. class ira_spilled_reg_stack_slot
  544. {
  545. public:
  546. /* pseudo-registers assigned to the stack slot. */
  547. bitmap_head spilled_regs;
  548. /* RTL representation of the stack slot. */
  549. rtx mem;
  550. /* Size of the stack slot. */
  551. poly_uint64_pod width;
  552. };
  553. /* The number of elements in the following array. */
  554. extern int ira_spilled_reg_stack_slots_num;
  555. /* The following array contains info about spilled pseudo-registers
  556. stack slots used in current function so far. */
  557. extern class ira_spilled_reg_stack_slot *ira_spilled_reg_stack_slots;
  558. /* Correspondingly overall cost of the allocation, cost of the
  559. allocnos assigned to hard-registers, cost of the allocnos assigned
  560. to memory, cost of loads, stores and register move insns generated
  561. for pseudo-register live range splitting (see ira-emit.c). */
  562. extern int64_t ira_overall_cost;
  563. extern int64_t ira_reg_cost, ira_mem_cost;
  564. extern int64_t ira_load_cost, ira_store_cost, ira_shuffle_cost;
  565. extern int ira_move_loops_num, ira_additional_jumps_num;
  566. /* This page contains a bitset implementation called 'min/max sets' used to
  567. record conflicts in IRA.
  568. They are named min/maxs set since we keep track of a minimum and a maximum
  569. bit number for each set representing the bounds of valid elements. Otherwise,
  570. the implementation resembles sbitmaps in that we store an array of integers
  571. whose bits directly represent the members of the set. */
  572. /* The type used as elements in the array, and the number of bits in
  573. this type. */
  574. #define IRA_INT_BITS HOST_BITS_PER_WIDE_INT
  575. #define IRA_INT_TYPE HOST_WIDE_INT
  576. /* Set, clear or test bit number I in R, a bit vector of elements with
  577. minimal index and maximal index equal correspondingly to MIN and
  578. MAX. */
  579. #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
  580. #define SET_MINMAX_SET_BIT(R, I, MIN, MAX) __extension__ \
  581. (({ int _min = (MIN), _max = (MAX), _i = (I); \
  582. if (_i < _min || _i > _max) \
  583. { \
  584. fprintf (stderr, \
  585. "\n%s: %d: error in %s: %d not in range [%d,%d]\n", \
  586. __FILE__, __LINE__, __FUNCTION__, _i, _min, _max); \
  587. gcc_unreachable (); \
  588. } \
  589. ((R)[(unsigned) (_i - _min) / IRA_INT_BITS] \
  590. |= ((IRA_INT_TYPE) 1 << ((unsigned) (_i - _min) % IRA_INT_BITS))); }))
  591. #define CLEAR_MINMAX_SET_BIT(R, I, MIN, MAX) __extension__ \
  592. (({ int _min = (MIN), _max = (MAX), _i = (I); \
  593. if (_i < _min || _i > _max) \
  594. { \
  595. fprintf (stderr, \
  596. "\n%s: %d: error in %s: %d not in range [%d,%d]\n", \
  597. __FILE__, __LINE__, __FUNCTION__, _i, _min, _max); \
  598. gcc_unreachable (); \
  599. } \
  600. ((R)[(unsigned) (_i - _min) / IRA_INT_BITS] \
  601. &= ~((IRA_INT_TYPE) 1 << ((unsigned) (_i - _min) % IRA_INT_BITS))); }))
  602. #define TEST_MINMAX_SET_BIT(R, I, MIN, MAX) __extension__ \
  603. (({ int _min = (MIN), _max = (MAX), _i = (I); \
  604. if (_i < _min || _i > _max) \
  605. { \
  606. fprintf (stderr, \
  607. "\n%s: %d: error in %s: %d not in range [%d,%d]\n", \
  608. __FILE__, __LINE__, __FUNCTION__, _i, _min, _max); \
  609. gcc_unreachable (); \
  610. } \
  611. ((R)[(unsigned) (_i - _min) / IRA_INT_BITS] \
  612. & ((IRA_INT_TYPE) 1 << ((unsigned) (_i - _min) % IRA_INT_BITS))); }))
  613. #else
  614. #define SET_MINMAX_SET_BIT(R, I, MIN, MAX) \
  615. ((R)[(unsigned) ((I) - (MIN)) / IRA_INT_BITS] \
  616. |= ((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
  617. #define CLEAR_MINMAX_SET_BIT(R, I, MIN, MAX) \
  618. ((R)[(unsigned) ((I) - (MIN)) / IRA_INT_BITS] \
  619. &= ~((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
  620. #define TEST_MINMAX_SET_BIT(R, I, MIN, MAX) \
  621. ((R)[(unsigned) ((I) - (MIN)) / IRA_INT_BITS] \
  622. & ((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
  623. #endif
  624. /* The iterator for min/max sets. */
  625. struct minmax_set_iterator {
  626. /* Array containing the bit vector. */
  627. IRA_INT_TYPE *vec;
  628. /* The number of the current element in the vector. */
  629. unsigned int word_num;
  630. /* The number of bits in the bit vector. */
  631. unsigned int nel;
  632. /* The current bit index of the bit vector. */
  633. unsigned int bit_num;
  634. /* Index corresponding to the 1st bit of the bit vector. */
  635. int start_val;
  636. /* The word of the bit vector currently visited. */
  637. unsigned IRA_INT_TYPE word;
  638. };
  639. /* Initialize the iterator I for bit vector VEC containing minimal and
  640. maximal values MIN and MAX. */
  641. static inline void
  642. minmax_set_iter_init (minmax_set_iterator *i, IRA_INT_TYPE *vec, int min,
  643. int max)
  644. {
  645. i->vec = vec;
  646. i->word_num = 0;
  647. i->nel = max < min ? 0 : max - min + 1;
  648. i->start_val = min;
  649. i->bit_num = 0;
  650. i->word = i->nel == 0 ? 0 : vec[0];
  651. }
  652. /* Return TRUE if we have more allocnos to visit, in which case *N is
  653. set to the number of the element to be visited. Otherwise, return
  654. FALSE. */
  655. static inline bool
  656. minmax_set_iter_cond (minmax_set_iterator *i, int *n)
  657. {
  658. /* Skip words that are zeros. */
  659. for (; i->word == 0; i->word = i->vec[i->word_num])
  660. {
  661. i->word_num++;
  662. i->bit_num = i->word_num * IRA_INT_BITS;
  663. /* If we have reached the end, break. */
  664. if (i->bit_num >= i->nel)
  665. return false;
  666. }
  667. /* Skip bits that are zero. */
  668. for (; (i->word & 1) == 0; i->word >>= 1)
  669. i->bit_num++;
  670. *n = (int) i->bit_num + i->start_val;
  671. return true;
  672. }
  673. /* Advance to the next element in the set. */
  674. static inline void
  675. minmax_set_iter_next (minmax_set_iterator *i)
  676. {
  677. i->word >>= 1;
  678. i->bit_num++;
  679. }
  680. /* Loop over all elements of a min/max set given by bit vector VEC and
  681. their minimal and maximal values MIN and MAX. In each iteration, N
  682. is set to the number of next allocno. ITER is an instance of
  683. minmax_set_iterator used to iterate over the set. */
  684. #define FOR_EACH_BIT_IN_MINMAX_SET(VEC, MIN, MAX, N, ITER) \
  685. for (minmax_set_iter_init (&(ITER), (VEC), (MIN), (MAX)); \
  686. minmax_set_iter_cond (&(ITER), &(N)); \
  687. minmax_set_iter_next (&(ITER)))
  688. class target_ira_int {
  689. public:
  690. ~target_ira_int ();
  691. void free_ira_costs ();
  692. void free_register_move_costs ();
  693. /* Initialized once. It is a maximal possible size of the allocated
  694. struct costs. */
  695. size_t x_max_struct_costs_size;
  696. /* Allocated and initialized once, and used to initialize cost values
  697. for each insn. */
  698. struct costs *x_init_cost;
  699. /* Allocated once, and used for temporary purposes. */
  700. struct costs *x_temp_costs;
  701. /* Allocated once, and used for the cost calculation. */
  702. struct costs *x_op_costs[MAX_RECOG_OPERANDS];
  703. struct costs *x_this_op_costs[MAX_RECOG_OPERANDS];
  704. /* Hard registers that cannot be used for the register allocator for
  705. all functions of the current compilation unit. */
  706. HARD_REG_SET x_no_unit_alloc_regs;
  707. /* Map: hard regs X modes -> set of hard registers for storing value
  708. of given mode starting with given hard register. */
  709. HARD_REG_SET (x_ira_reg_mode_hard_regset
  710. [FIRST_PSEUDO_REGISTER][NUM_MACHINE_MODES]);
  711. /* Maximum cost of moving from a register in one class to a register
  712. in another class. Based on TARGET_REGISTER_MOVE_COST. */
  713. move_table *x_ira_register_move_cost[MAX_MACHINE_MODE];
  714. /* Similar, but here we don't have to move if the first index is a
  715. subset of the second so in that case the cost is zero. */
  716. move_table *x_ira_may_move_in_cost[MAX_MACHINE_MODE];
  717. /* Similar, but here we don't have to move if the first index is a
  718. superset of the second so in that case the cost is zero. */
  719. move_table *x_ira_may_move_out_cost[MAX_MACHINE_MODE];
  720. /* Keep track of the last mode we initialized move costs for. */
  721. int x_last_mode_for_init_move_cost;
  722. /* Array analog of the macro MEMORY_MOVE_COST but they contain maximal
  723. cost not minimal. */
  724. short int x_ira_max_memory_move_cost[MAX_MACHINE_MODE][N_REG_CLASSES][2];
  725. /* Map class->true if class is a possible allocno class, false
  726. otherwise. */
  727. bool x_ira_reg_allocno_class_p[N_REG_CLASSES];
  728. /* Map class->true if class is a pressure class, false otherwise. */
  729. bool x_ira_reg_pressure_class_p[N_REG_CLASSES];
  730. /* Array of the number of hard registers of given class which are
  731. available for allocation. The order is defined by the hard
  732. register numbers. */
  733. short x_ira_non_ordered_class_hard_regs[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
  734. /* Index (in ira_class_hard_regs; for given register class and hard
  735. register (in general case a hard register can belong to several
  736. register classes;. The index is negative for hard registers
  737. unavailable for the allocation. */
  738. short x_ira_class_hard_reg_index[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
  739. /* Index [CL][M] contains R if R appears somewhere in a register of the form:
  740. (reg:M R'), R' not in x_ira_prohibited_class_mode_regs[CL][M]
  741. For example, if:
  742. - (reg:M 2) is valid and occupies two registers;
  743. - register 2 belongs to CL; and
  744. - register 3 belongs to the same pressure class as CL
  745. then (reg:M 2) contributes to [CL][M] and registers 2 and 3 will be
  746. in the set. */
  747. HARD_REG_SET x_ira_useful_class_mode_regs[N_REG_CLASSES][NUM_MACHINE_MODES];
  748. /* The value is number of elements in the subsequent array. */
  749. int x_ira_important_classes_num;
  750. /* The array containing all non-empty classes. Such classes is
  751. important for calculation of the hard register usage costs. */
  752. enum reg_class x_ira_important_classes[N_REG_CLASSES];
  753. /* The array containing indexes of important classes in the previous
  754. array. The array elements are defined only for important
  755. classes. */
  756. int x_ira_important_class_nums[N_REG_CLASSES];
  757. /* Map class->true if class is an uniform class, false otherwise. */
  758. bool x_ira_uniform_class_p[N_REG_CLASSES];
  759. /* The biggest important class inside of intersection of the two
  760. classes (that is calculated taking only hard registers available
  761. for allocation into account;. If the both classes contain no hard
  762. registers available for allocation, the value is calculated with
  763. taking all hard-registers including fixed ones into account. */
  764. enum reg_class x_ira_reg_class_intersect[N_REG_CLASSES][N_REG_CLASSES];
  765. /* Classes with end marker LIM_REG_CLASSES which are intersected with
  766. given class (the first index). That includes given class itself.
  767. This is calculated taking only hard registers available for
  768. allocation into account. */
  769. enum reg_class x_ira_reg_class_super_classes[N_REG_CLASSES][N_REG_CLASSES];
  770. /* The biggest (smallest) important class inside of (covering) union
  771. of the two classes (that is calculated taking only hard registers
  772. available for allocation into account). If the both classes
  773. contain no hard registers available for allocation, the value is
  774. calculated with taking all hard-registers including fixed ones
  775. into account. In other words, the value is the corresponding
  776. reg_class_subunion (reg_class_superunion) value. */
  777. enum reg_class x_ira_reg_class_subunion[N_REG_CLASSES][N_REG_CLASSES];
  778. enum reg_class x_ira_reg_class_superunion[N_REG_CLASSES][N_REG_CLASSES];
  779. /* For each reg class, table listing all the classes contained in it
  780. (excluding the class itself. Non-allocatable registers are
  781. excluded from the consideration). */
  782. enum reg_class x_alloc_reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
  783. /* Array whose values are hard regset of hard registers for which
  784. move of the hard register in given mode into itself is
  785. prohibited. */
  786. HARD_REG_SET x_ira_prohibited_mode_move_regs[NUM_MACHINE_MODES];
  787. /* Flag of that the above array has been initialized. */
  788. bool x_ira_prohibited_mode_move_regs_initialized_p;
  789. };
  790. extern class target_ira_int default_target_ira_int;
  791. #if SWITCHABLE_TARGET
  792. extern class target_ira_int *this_target_ira_int;
  793. #else
  794. #define this_target_ira_int (&default_target_ira_int)
  795. #endif
  796. #define ira_reg_mode_hard_regset \
  797. (this_target_ira_int->x_ira_reg_mode_hard_regset)
  798. #define ira_register_move_cost \
  799. (this_target_ira_int->x_ira_register_move_cost)
  800. #define ira_max_memory_move_cost \
  801. (this_target_ira_int->x_ira_max_memory_move_cost)
  802. #define ira_may_move_in_cost \
  803. (this_target_ira_int->x_ira_may_move_in_cost)
  804. #define ira_may_move_out_cost \
  805. (this_target_ira_int->x_ira_may_move_out_cost)
  806. #define ira_reg_allocno_class_p \
  807. (this_target_ira_int->x_ira_reg_allocno_class_p)
  808. #define ira_reg_pressure_class_p \
  809. (this_target_ira_int->x_ira_reg_pressure_class_p)
  810. #define ira_non_ordered_class_hard_regs \
  811. (this_target_ira_int->x_ira_non_ordered_class_hard_regs)
  812. #define ira_class_hard_reg_index \
  813. (this_target_ira_int->x_ira_class_hard_reg_index)
  814. #define ira_useful_class_mode_regs \
  815. (this_target_ira_int->x_ira_useful_class_mode_regs)
  816. #define ira_important_classes_num \
  817. (this_target_ira_int->x_ira_important_classes_num)
  818. #define ira_important_classes \
  819. (this_target_ira_int->x_ira_important_classes)
  820. #define ira_important_class_nums \
  821. (this_target_ira_int->x_ira_important_class_nums)
  822. #define ira_uniform_class_p \
  823. (this_target_ira_int->x_ira_uniform_class_p)
  824. #define ira_reg_class_intersect \
  825. (this_target_ira_int->x_ira_reg_class_intersect)
  826. #define ira_reg_class_super_classes \
  827. (this_target_ira_int->x_ira_reg_class_super_classes)
  828. #define ira_reg_class_subunion \
  829. (this_target_ira_int->x_ira_reg_class_subunion)
  830. #define ira_reg_class_superunion \
  831. (this_target_ira_int->x_ira_reg_class_superunion)
  832. #define ira_prohibited_mode_move_regs \
  833. (this_target_ira_int->x_ira_prohibited_mode_move_regs)
  834. /* ira.c: */
  835. extern void *ira_allocate (size_t);
  836. extern void ira_free (void *addr);
  837. extern bitmap ira_allocate_bitmap (void);
  838. extern void ira_free_bitmap (bitmap);
  839. extern void ira_print_disposition (FILE *);
  840. extern void ira_debug_disposition (void);
  841. extern void ira_debug_allocno_classes (void);
  842. extern void ira_init_register_move_cost (machine_mode);
  843. extern alternative_mask ira_setup_alts (rtx_insn *);
  844. extern int ira_get_dup_out_num (int, alternative_mask);
  845. /* ira-build.c */
  846. /* The current loop tree node and its regno allocno map. */
  847. extern ira_loop_tree_node_t ira_curr_loop_tree_node;
  848. extern ira_allocno_t *ira_curr_regno_allocno_map;
  849. extern void ira_debug_pref (ira_pref_t);
  850. extern void ira_debug_prefs (void);
  851. extern void ira_debug_allocno_prefs (ira_allocno_t);
  852. extern void ira_debug_copy (ira_copy_t);
  853. extern void debug (ira_allocno_copy &ref);
  854. extern void debug (ira_allocno_copy *ptr);
  855. extern void ira_debug_copies (void);
  856. extern void ira_debug_allocno_copies (ira_allocno_t);
  857. extern void debug (ira_allocno &ref);
  858. extern void debug (ira_allocno *ptr);
  859. extern void ira_traverse_loop_tree (bool, ira_loop_tree_node_t,
  860. void (*) (ira_loop_tree_node_t),
  861. void (*) (ira_loop_tree_node_t));
  862. extern ira_allocno_t ira_parent_allocno (ira_allocno_t);
  863. extern ira_allocno_t ira_parent_or_cap_allocno (ira_allocno_t);
  864. extern ira_allocno_t ira_create_allocno (int, bool, ira_loop_tree_node_t);
  865. extern void ira_create_allocno_objects (ira_allocno_t);
  866. extern void ira_set_allocno_class (ira_allocno_t, enum reg_class);
  867. extern bool ira_conflict_vector_profitable_p (ira_object_t, int);
  868. extern void ira_allocate_conflict_vec (ira_object_t, int);
  869. extern void ira_allocate_object_conflicts (ira_object_t, int);
  870. extern void ior_hard_reg_conflicts (ira_allocno_t, const_hard_reg_set);
  871. extern void ira_print_expanded_allocno (ira_allocno_t);
  872. extern void ira_add_live_range_to_object (ira_object_t, int, int);
  873. extern live_range_t ira_create_live_range (ira_object_t, int, int,
  874. live_range_t);
  875. extern live_range_t ira_copy_live_range_list (live_range_t);
  876. extern live_range_t ira_merge_live_ranges (live_range_t, live_range_t);
  877. extern bool ira_live_ranges_intersect_p (live_range_t, live_range_t);
  878. extern void ira_finish_live_range (live_range_t);
  879. extern void ira_finish_live_range_list (live_range_t);
  880. extern void ira_free_allocno_updated_costs (ira_allocno_t);
  881. extern ira_pref_t ira_create_pref (ira_allocno_t, int, int);
  882. extern void ira_add_allocno_pref (ira_allocno_t, int, int);
  883. extern void ira_remove_pref (ira_pref_t);
  884. extern void ira_remove_allocno_prefs (ira_allocno_t);
  885. extern ira_copy_t ira_create_copy (ira_allocno_t, ira_allocno_t,
  886. int, bool, rtx_insn *,
  887. ira_loop_tree_node_t);
  888. extern ira_copy_t ira_add_allocno_copy (ira_allocno_t, ira_allocno_t, int,
  889. bool, rtx_insn *,
  890. ira_loop_tree_node_t);
  891. extern int *ira_allocate_cost_vector (reg_class_t);
  892. extern void ira_free_cost_vector (int *, reg_class_t);
  893. extern void ira_flattening (int, int);
  894. extern bool ira_build (void);
  895. extern void ira_destroy (void);
  896. /* ira-costs.c */
  897. extern void ira_init_costs_once (void);
  898. extern void ira_init_costs (void);
  899. extern void ira_costs (void);
  900. extern void ira_tune_allocno_costs (void);
  901. /* ira-lives.c */
  902. extern void ira_rebuild_start_finish_chains (void);
  903. extern void ira_print_live_range_list (FILE *, live_range_t);
  904. extern void debug (live_range &ref);
  905. extern void debug (live_range *ptr);
  906. extern void ira_debug_live_range_list (live_range_t);
  907. extern void ira_debug_allocno_live_ranges (ira_allocno_t);
  908. extern void ira_debug_live_ranges (void);
  909. extern void ira_create_allocno_live_ranges (void);
  910. extern void ira_compress_allocno_live_ranges (void);
  911. extern void ira_finish_allocno_live_ranges (void);
  912. extern void ira_implicitly_set_insn_hard_regs (HARD_REG_SET *,
  913. alternative_mask);
  914. /* ira-conflicts.c */
  915. extern void ira_debug_conflicts (bool);
  916. extern void ira_build_conflicts (void);
  917. /* ira-color.c */
  918. extern void ira_debug_hard_regs_forest (void);
  919. extern int ira_loop_edge_freq (ira_loop_tree_node_t, int, bool);
  920. extern void ira_reassign_conflict_allocnos (int);
  921. extern void ira_initiate_assign (void);
  922. extern void ira_finish_assign (void);
  923. extern void ira_color (void);
  924. /* ira-emit.c */
  925. extern void ira_initiate_emit_data (void);
  926. extern void ira_finish_emit_data (void);
  927. extern void ira_emit (bool);
  928. /* Return true if equivalence of pseudo REGNO is not a lvalue. */
  929. static inline bool
  930. ira_equiv_no_lvalue_p (int regno)
  931. {
  932. if (regno >= ira_reg_equiv_len)
  933. return false;
  934. return (ira_reg_equiv[regno].constant != NULL_RTX
  935. || ira_reg_equiv[regno].invariant != NULL_RTX
  936. || (ira_reg_equiv[regno].memory != NULL_RTX
  937. && MEM_READONLY_P (ira_reg_equiv[regno].memory)));
  938. }
  939. /* Initialize register costs for MODE if necessary. */
  940. static inline void
  941. ira_init_register_move_cost_if_necessary (machine_mode mode)
  942. {
  943. if (ira_register_move_cost[mode] == NULL)
  944. ira_init_register_move_cost (mode);
  945. }
  946. /* The iterator for all allocnos. */
  947. struct ira_allocno_iterator {
  948. /* The number of the current element in IRA_ALLOCNOS. */
  949. int n;
  950. };
  951. /* Initialize the iterator I. */
  952. static inline void
  953. ira_allocno_iter_init (ira_allocno_iterator *i)
  954. {
  955. i->n = 0;
  956. }
  957. /* Return TRUE if we have more allocnos to visit, in which case *A is
  958. set to the allocno to be visited. Otherwise, return FALSE. */
  959. static inline bool
  960. ira_allocno_iter_cond (ira_allocno_iterator *i, ira_allocno_t *a)
  961. {
  962. int n;
  963. for (n = i->n; n < ira_allocnos_num; n++)
  964. if (ira_allocnos[n] != NULL)
  965. {
  966. *a = ira_allocnos[n];
  967. i->n = n + 1;
  968. return true;
  969. }
  970. return false;
  971. }
  972. /* Loop over all allocnos. In each iteration, A is set to the next
  973. allocno. ITER is an instance of ira_allocno_iterator used to iterate
  974. the allocnos. */
  975. #define FOR_EACH_ALLOCNO(A, ITER) \
  976. for (ira_allocno_iter_init (&(ITER)); \
  977. ira_allocno_iter_cond (&(ITER), &(A));)
  978. /* The iterator for all objects. */
  979. struct ira_object_iterator {
  980. /* The number of the current element in ira_object_id_map. */
  981. int n;
  982. };
  983. /* Initialize the iterator I. */
  984. static inline void
  985. ira_object_iter_init (ira_object_iterator *i)
  986. {
  987. i->n = 0;
  988. }
  989. /* Return TRUE if we have more objects to visit, in which case *OBJ is
  990. set to the object to be visited. Otherwise, return FALSE. */
  991. static inline bool
  992. ira_object_iter_cond (ira_object_iterator *i, ira_object_t *obj)
  993. {
  994. int n;
  995. for (n = i->n; n < ira_objects_num; n++)
  996. if (ira_object_id_map[n] != NULL)
  997. {
  998. *obj = ira_object_id_map[n];
  999. i->n = n + 1;
  1000. return true;
  1001. }
  1002. return false;
  1003. }
  1004. /* Loop over all objects. In each iteration, OBJ is set to the next
  1005. object. ITER is an instance of ira_object_iterator used to iterate
  1006. the objects. */
  1007. #define FOR_EACH_OBJECT(OBJ, ITER) \
  1008. for (ira_object_iter_init (&(ITER)); \
  1009. ira_object_iter_cond (&(ITER), &(OBJ));)
  1010. /* The iterator for objects associated with an allocno. */
  1011. struct ira_allocno_object_iterator {
  1012. /* The number of the element the allocno's object array. */
  1013. int n;
  1014. };
  1015. /* Initialize the iterator I. */
  1016. static inline void
  1017. ira_allocno_object_iter_init (ira_allocno_object_iterator *i)
  1018. {
  1019. i->n = 0;
  1020. }
  1021. /* Return TRUE if we have more objects to visit in allocno A, in which
  1022. case *O is set to the object to be visited. Otherwise, return
  1023. FALSE. */
  1024. static inline bool
  1025. ira_allocno_object_iter_cond (ira_allocno_object_iterator *i, ira_allocno_t a,
  1026. ira_object_t *o)
  1027. {
  1028. int n = i->n++;
  1029. if (n < ALLOCNO_NUM_OBJECTS (a))
  1030. {
  1031. *o = ALLOCNO_OBJECT (a, n);
  1032. return true;
  1033. }
  1034. return false;
  1035. }
  1036. /* Loop over all objects associated with allocno A. In each
  1037. iteration, O is set to the next object. ITER is an instance of
  1038. ira_allocno_object_iterator used to iterate the conflicts. */
  1039. #define FOR_EACH_ALLOCNO_OBJECT(A, O, ITER) \
  1040. for (ira_allocno_object_iter_init (&(ITER)); \
  1041. ira_allocno_object_iter_cond (&(ITER), (A), &(O));)
  1042. /* The iterator for prefs. */
  1043. struct ira_pref_iterator {
  1044. /* The number of the current element in IRA_PREFS. */
  1045. int n;
  1046. };
  1047. /* Initialize the iterator I. */
  1048. static inline void
  1049. ira_pref_iter_init (ira_pref_iterator *i)
  1050. {
  1051. i->n = 0;
  1052. }
  1053. /* Return TRUE if we have more prefs to visit, in which case *PREF is
  1054. set to the pref to be visited. Otherwise, return FALSE. */
  1055. static inline bool
  1056. ira_pref_iter_cond (ira_pref_iterator *i, ira_pref_t *pref)
  1057. {
  1058. int n;
  1059. for (n = i->n; n < ira_prefs_num; n++)
  1060. if (ira_prefs[n] != NULL)
  1061. {
  1062. *pref = ira_prefs[n];
  1063. i->n = n + 1;
  1064. return true;
  1065. }
  1066. return false;
  1067. }
  1068. /* Loop over all prefs. In each iteration, P is set to the next
  1069. pref. ITER is an instance of ira_pref_iterator used to iterate
  1070. the prefs. */
  1071. #define FOR_EACH_PREF(P, ITER) \
  1072. for (ira_pref_iter_init (&(ITER)); \
  1073. ira_pref_iter_cond (&(ITER), &(P));)
  1074. /* The iterator for copies. */
  1075. struct ira_copy_iterator {
  1076. /* The number of the current element in IRA_COPIES. */
  1077. int n;
  1078. };
  1079. /* Initialize the iterator I. */
  1080. static inline void
  1081. ira_copy_iter_init (ira_copy_iterator *i)
  1082. {
  1083. i->n = 0;
  1084. }
  1085. /* Return TRUE if we have more copies to visit, in which case *CP is
  1086. set to the copy to be visited. Otherwise, return FALSE. */
  1087. static inline bool
  1088. ira_copy_iter_cond (ira_copy_iterator *i, ira_copy_t *cp)
  1089. {
  1090. int n;
  1091. for (n = i->n; n < ira_copies_num; n++)
  1092. if (ira_copies[n] != NULL)
  1093. {
  1094. *cp = ira_copies[n];
  1095. i->n = n + 1;
  1096. return true;
  1097. }
  1098. return false;
  1099. }
  1100. /* Loop over all copies. In each iteration, C is set to the next
  1101. copy. ITER is an instance of ira_copy_iterator used to iterate
  1102. the copies. */
  1103. #define FOR_EACH_COPY(C, ITER) \
  1104. for (ira_copy_iter_init (&(ITER)); \
  1105. ira_copy_iter_cond (&(ITER), &(C));)
  1106. /* The iterator for object conflicts. */
  1107. struct ira_object_conflict_iterator {
  1108. /* TRUE if the conflicts are represented by vector of allocnos. */
  1109. bool conflict_vec_p;
  1110. /* The conflict vector or conflict bit vector. */
  1111. void *vec;
  1112. /* The number of the current element in the vector (of type
  1113. ira_object_t or IRA_INT_TYPE). */
  1114. unsigned int word_num;
  1115. /* The bit vector size. It is defined only if
  1116. OBJECT_CONFLICT_VEC_P is FALSE. */
  1117. unsigned int size;
  1118. /* The current bit index of bit vector. It is defined only if
  1119. OBJECT_CONFLICT_VEC_P is FALSE. */
  1120. unsigned int bit_num;
  1121. /* The object id corresponding to the 1st bit of the bit vector. It
  1122. is defined only if OBJECT_CONFLICT_VEC_P is FALSE. */
  1123. int base_conflict_id;
  1124. /* The word of bit vector currently visited. It is defined only if
  1125. OBJECT_CONFLICT_VEC_P is FALSE. */
  1126. unsigned IRA_INT_TYPE word;
  1127. };
  1128. /* Initialize the iterator I with ALLOCNO conflicts. */
  1129. static inline void
  1130. ira_object_conflict_iter_init (ira_object_conflict_iterator *i,
  1131. ira_object_t obj)
  1132. {
  1133. i->conflict_vec_p = OBJECT_CONFLICT_VEC_P (obj);
  1134. i->vec = OBJECT_CONFLICT_ARRAY (obj);
  1135. i->word_num = 0;
  1136. if (i->conflict_vec_p)
  1137. i->size = i->bit_num = i->base_conflict_id = i->word = 0;
  1138. else
  1139. {
  1140. if (OBJECT_MIN (obj) > OBJECT_MAX (obj))
  1141. i->size = 0;
  1142. else
  1143. i->size = ((OBJECT_MAX (obj) - OBJECT_MIN (obj)
  1144. + IRA_INT_BITS)
  1145. / IRA_INT_BITS) * sizeof (IRA_INT_TYPE);
  1146. i->bit_num = 0;
  1147. i->base_conflict_id = OBJECT_MIN (obj);
  1148. i->word = (i->size == 0 ? 0 : ((IRA_INT_TYPE *) i->vec)[0]);
  1149. }
  1150. }
  1151. /* Return TRUE if we have more conflicting allocnos to visit, in which
  1152. case *A is set to the allocno to be visited. Otherwise, return
  1153. FALSE. */
  1154. static inline bool
  1155. ira_object_conflict_iter_cond (ira_object_conflict_iterator *i,
  1156. ira_object_t *pobj)
  1157. {
  1158. ira_object_t obj;
  1159. if (i->conflict_vec_p)
  1160. {
  1161. obj = ((ira_object_t *) i->vec)[i->word_num++];
  1162. if (obj == NULL)
  1163. return false;
  1164. }
  1165. else
  1166. {
  1167. unsigned IRA_INT_TYPE word = i->word;
  1168. unsigned int bit_num = i->bit_num;
  1169. /* Skip words that are zeros. */
  1170. for (; word == 0; word = ((IRA_INT_TYPE *) i->vec)[i->word_num])
  1171. {
  1172. i->word_num++;
  1173. /* If we have reached the end, break. */
  1174. if (i->word_num * sizeof (IRA_INT_TYPE) >= i->size)
  1175. return false;
  1176. bit_num = i->word_num * IRA_INT_BITS;
  1177. }
  1178. /* Skip bits that are zero. */
  1179. for (; (word & 1) == 0; word >>= 1)
  1180. bit_num++;
  1181. obj = ira_object_id_map[bit_num + i->base_conflict_id];
  1182. i->bit_num = bit_num + 1;
  1183. i->word = word >> 1;
  1184. }
  1185. *pobj = obj;
  1186. return true;
  1187. }
  1188. /* Loop over all objects conflicting with OBJ. In each iteration,
  1189. CONF is set to the next conflicting object. ITER is an instance
  1190. of ira_object_conflict_iterator used to iterate the conflicts. */
  1191. #define FOR_EACH_OBJECT_CONFLICT(OBJ, CONF, ITER) \
  1192. for (ira_object_conflict_iter_init (&(ITER), (OBJ)); \
  1193. ira_object_conflict_iter_cond (&(ITER), &(CONF));)
  1194. /* The function returns TRUE if at least one hard register from ones
  1195. starting with HARD_REGNO and containing value of MODE are in set
  1196. HARD_REGSET. */
  1197. static inline bool
  1198. ira_hard_reg_set_intersection_p (int hard_regno, machine_mode mode,
  1199. HARD_REG_SET hard_regset)
  1200. {
  1201. int i;
  1202. gcc_assert (hard_regno >= 0);
  1203. for (i = hard_regno_nregs (hard_regno, mode) - 1; i >= 0; i--)
  1204. if (TEST_HARD_REG_BIT (hard_regset, hard_regno + i))
  1205. return true;
  1206. return false;
  1207. }
  1208. /* Return number of hard registers in hard register SET. */
  1209. static inline int
  1210. hard_reg_set_size (HARD_REG_SET set)
  1211. {
  1212. int i, size;
  1213. for (size = i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1214. if (TEST_HARD_REG_BIT (set, i))
  1215. size++;
  1216. return size;
  1217. }
  1218. /* The function returns TRUE if hard registers starting with
  1219. HARD_REGNO and containing value of MODE are fully in set
  1220. HARD_REGSET. */
  1221. static inline bool
  1222. ira_hard_reg_in_set_p (int hard_regno, machine_mode mode,
  1223. HARD_REG_SET hard_regset)
  1224. {
  1225. int i;
  1226. ira_assert (hard_regno >= 0);
  1227. for (i = hard_regno_nregs (hard_regno, mode) - 1; i >= 0; i--)
  1228. if (!TEST_HARD_REG_BIT (hard_regset, hard_regno + i))
  1229. return false;
  1230. return true;
  1231. }
  1232. /* To save memory we use a lazy approach for allocation and
  1233. initialization of the cost vectors. We do this only when it is
  1234. really necessary. */
  1235. /* Allocate cost vector *VEC for hard registers of ACLASS and
  1236. initialize the elements by VAL if it is necessary */
  1237. static inline void
  1238. ira_allocate_and_set_costs (int **vec, reg_class_t aclass, int val)
  1239. {
  1240. int i, *reg_costs;
  1241. int len;
  1242. if (*vec != NULL)
  1243. return;
  1244. *vec = reg_costs = ira_allocate_cost_vector (aclass);
  1245. len = ira_class_hard_regs_num[(int) aclass];
  1246. for (i = 0; i < len; i++)
  1247. reg_costs[i] = val;
  1248. }
  1249. /* Allocate cost vector *VEC for hard registers of ACLASS and copy
  1250. values of vector SRC into the vector if it is necessary */
  1251. static inline void
  1252. ira_allocate_and_copy_costs (int **vec, enum reg_class aclass, int *src)
  1253. {
  1254. int len;
  1255. if (*vec != NULL || src == NULL)
  1256. return;
  1257. *vec = ira_allocate_cost_vector (aclass);
  1258. len = ira_class_hard_regs_num[aclass];
  1259. memcpy (*vec, src, sizeof (int) * len);
  1260. }
  1261. /* Allocate cost vector *VEC for hard registers of ACLASS and add
  1262. values of vector SRC into the vector if it is necessary */
  1263. static inline void
  1264. ira_allocate_and_accumulate_costs (int **vec, enum reg_class aclass, int *src)
  1265. {
  1266. int i, len;
  1267. if (src == NULL)
  1268. return;
  1269. len = ira_class_hard_regs_num[aclass];
  1270. if (*vec == NULL)
  1271. {
  1272. *vec = ira_allocate_cost_vector (aclass);
  1273. memset (*vec, 0, sizeof (int) * len);
  1274. }
  1275. for (i = 0; i < len; i++)
  1276. (*vec)[i] += src[i];
  1277. }
  1278. /* Allocate cost vector *VEC for hard registers of ACLASS and copy
  1279. values of vector SRC into the vector or initialize it by VAL (if
  1280. SRC is null). */
  1281. static inline void
  1282. ira_allocate_and_set_or_copy_costs (int **vec, enum reg_class aclass,
  1283. int val, int *src)
  1284. {
  1285. int i, *reg_costs;
  1286. int len;
  1287. if (*vec != NULL)
  1288. return;
  1289. *vec = reg_costs = ira_allocate_cost_vector (aclass);
  1290. len = ira_class_hard_regs_num[aclass];
  1291. if (src != NULL)
  1292. memcpy (reg_costs, src, sizeof (int) * len);
  1293. else
  1294. {
  1295. for (i = 0; i < len; i++)
  1296. reg_costs[i] = val;
  1297. }
  1298. }
  1299. extern rtx ira_create_new_reg (rtx);
  1300. extern int first_moveable_pseudo, last_moveable_pseudo;
  1301. /* Return the set of registers that would need a caller save if allocno A
  1302. overlapped them. */
  1303. inline HARD_REG_SET
  1304. ira_need_caller_save_regs (ira_allocno_t a)
  1305. {
  1306. return call_clobbers_in_region (ALLOCNO_CROSSED_CALLS_ABIS (a),
  1307. ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a),
  1308. ALLOCNO_MODE (a));
  1309. }
  1310. /* Return true if we would need to save allocno A around a call if we
  1311. assigned hard register REGNO. */
  1312. inline bool
  1313. ira_need_caller_save_p (ira_allocno_t a, unsigned int regno)
  1314. {
  1315. if (ALLOCNO_CALLS_CROSSED_NUM (a) == 0)
  1316. return false;
  1317. return call_clobbered_in_region_p (ALLOCNO_CROSSED_CALLS_ABIS (a),
  1318. ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a),
  1319. ALLOCNO_MODE (a), regno);
  1320. }
  1321. #endif /* GCC_IRA_INT_H */