ira-int.h 54 KB

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