ira-int.h 54 KB

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