reginfo.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. /* Compute different info about registers.
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. /* This file contains regscan pass of the compiler and passes for
  16. dealing with info about modes of pseudo-registers inside
  17. subregisters. It also defines some tables of information about the
  18. hardware registers, function init_reg_sets to initialize the
  19. tables, and other auxiliary functions to deal with info about
  20. registers and their classes. */
  21. #include "config.h"
  22. #include "system.h"
  23. #include "coretypes.h"
  24. #include "tm.h"
  25. #include "hard-reg-set.h"
  26. #include "hash-set.h"
  27. #include "machmode.h"
  28. #include "vec.h"
  29. #include "double-int.h"
  30. #include "input.h"
  31. #include "alias.h"
  32. #include "symtab.h"
  33. #include "wide-int.h"
  34. #include "inchash.h"
  35. #include "tree.h"
  36. #include "rtl.h"
  37. #include "hashtab.h"
  38. #include "function.h"
  39. #include "flags.h"
  40. #include "statistics.h"
  41. #include "real.h"
  42. #include "fixed-value.h"
  43. #include "insn-config.h"
  44. #include "expmed.h"
  45. #include "dojump.h"
  46. #include "explow.h"
  47. #include "calls.h"
  48. #include "emit-rtl.h"
  49. #include "varasm.h"
  50. #include "stmt.h"
  51. #include "expr.h"
  52. #include "tm_p.h"
  53. #include "predict.h"
  54. #include "dominance.h"
  55. #include "cfg.h"
  56. #include "basic-block.h"
  57. #include "regs.h"
  58. #include "addresses.h"
  59. #include "recog.h"
  60. #include "reload.h"
  61. #include "diagnostic-core.h"
  62. #include "output.h"
  63. #include "target.h"
  64. #include "tree-pass.h"
  65. #include "df.h"
  66. #include "ira.h"
  67. /* Maximum register number used in this function, plus one. */
  68. int max_regno;
  69. /* Used to cache the results of simplifiable_subregs. SHAPE is the input
  70. parameter and SIMPLIFIABLE_REGS is the result. */
  71. struct simplifiable_subreg
  72. {
  73. simplifiable_subreg (const subreg_shape &);
  74. subreg_shape shape;
  75. HARD_REG_SET simplifiable_regs;
  76. };
  77. struct simplifiable_subregs_hasher : typed_noop_remove <simplifiable_subreg>
  78. {
  79. typedef simplifiable_subreg value_type;
  80. typedef subreg_shape compare_type;
  81. static inline hashval_t hash (const value_type *);
  82. static inline bool equal (const value_type *, const compare_type *);
  83. };
  84. struct target_hard_regs default_target_hard_regs;
  85. struct target_regs default_target_regs;
  86. #if SWITCHABLE_TARGET
  87. struct target_hard_regs *this_target_hard_regs = &default_target_hard_regs;
  88. struct target_regs *this_target_regs = &default_target_regs;
  89. #endif
  90. /* Data for initializing fixed_regs. */
  91. static const char initial_fixed_regs[] = FIXED_REGISTERS;
  92. /* Data for initializing call_used_regs. */
  93. static const char initial_call_used_regs[] = CALL_USED_REGISTERS;
  94. #ifdef CALL_REALLY_USED_REGISTERS
  95. /* Data for initializing call_really_used_regs. */
  96. static const char initial_call_really_used_regs[] = CALL_REALLY_USED_REGISTERS;
  97. #endif
  98. #ifdef CALL_REALLY_USED_REGISTERS
  99. #define CALL_REALLY_USED_REGNO_P(X) call_really_used_regs[X]
  100. #else
  101. #define CALL_REALLY_USED_REGNO_P(X) call_used_regs[X]
  102. #endif
  103. /* Indexed by hard register number, contains 1 for registers
  104. that are being used for global register decls.
  105. These must be exempt from ordinary flow analysis
  106. and are also considered fixed. */
  107. char global_regs[FIRST_PSEUDO_REGISTER];
  108. /* Declaration for the global register. */
  109. tree global_regs_decl[FIRST_PSEUDO_REGISTER];
  110. /* Same information as REGS_INVALIDATED_BY_CALL but in regset form to be used
  111. in dataflow more conveniently. */
  112. regset regs_invalidated_by_call_regset;
  113. /* Same information as FIXED_REG_SET but in regset form. */
  114. regset fixed_reg_set_regset;
  115. /* The bitmap_obstack is used to hold some static variables that
  116. should not be reset after each function is compiled. */
  117. static bitmap_obstack persistent_obstack;
  118. /* Used to initialize reg_alloc_order. */
  119. #ifdef REG_ALLOC_ORDER
  120. static int initial_reg_alloc_order[FIRST_PSEUDO_REGISTER] = REG_ALLOC_ORDER;
  121. #endif
  122. /* The same information, but as an array of unsigned ints. We copy from
  123. these unsigned ints to the table above. We do this so the tm.h files
  124. do not have to be aware of the wordsize for machines with <= 64 regs.
  125. Note that we hard-code 32 here, not HOST_BITS_PER_INT. */
  126. #define N_REG_INTS \
  127. ((FIRST_PSEUDO_REGISTER + (32 - 1)) / 32)
  128. static const unsigned int_reg_class_contents[N_REG_CLASSES][N_REG_INTS]
  129. = REG_CLASS_CONTENTS;
  130. /* Array containing all of the register names. */
  131. static const char *const initial_reg_names[] = REGISTER_NAMES;
  132. /* Array containing all of the register class names. */
  133. const char * reg_class_names[] = REG_CLASS_NAMES;
  134. /* No more global register variables may be declared; true once
  135. reginfo has been initialized. */
  136. static int no_global_reg_vars = 0;
  137. /* Given a register bitmap, turn on the bits in a HARD_REG_SET that
  138. correspond to the hard registers, if any, set in that map. This
  139. could be done far more efficiently by having all sorts of special-cases
  140. with moving single words, but probably isn't worth the trouble. */
  141. void
  142. reg_set_to_hard_reg_set (HARD_REG_SET *to, const_bitmap from)
  143. {
  144. unsigned i;
  145. bitmap_iterator bi;
  146. EXECUTE_IF_SET_IN_BITMAP (from, 0, i, bi)
  147. {
  148. if (i >= FIRST_PSEUDO_REGISTER)
  149. return;
  150. SET_HARD_REG_BIT (*to, i);
  151. }
  152. }
  153. /* Function called only once per target_globals to initialize the
  154. target_hard_regs structure. Once this is done, various switches
  155. may override. */
  156. void
  157. init_reg_sets (void)
  158. {
  159. int i, j;
  160. /* First copy the register information from the initial int form into
  161. the regsets. */
  162. for (i = 0; i < N_REG_CLASSES; i++)
  163. {
  164. CLEAR_HARD_REG_SET (reg_class_contents[i]);
  165. /* Note that we hard-code 32 here, not HOST_BITS_PER_INT. */
  166. for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  167. if (int_reg_class_contents[i][j / 32]
  168. & ((unsigned) 1 << (j % 32)))
  169. SET_HARD_REG_BIT (reg_class_contents[i], j);
  170. }
  171. /* Sanity check: make sure the target macros FIXED_REGISTERS and
  172. CALL_USED_REGISTERS had the right number of initializers. */
  173. gcc_assert (sizeof fixed_regs == sizeof initial_fixed_regs);
  174. gcc_assert (sizeof call_used_regs == sizeof initial_call_used_regs);
  175. #ifdef CALL_REALLY_USED_REGISTERS
  176. gcc_assert (sizeof call_really_used_regs
  177. == sizeof initial_call_really_used_regs);
  178. #endif
  179. #ifdef REG_ALLOC_ORDER
  180. gcc_assert (sizeof reg_alloc_order == sizeof initial_reg_alloc_order);
  181. #endif
  182. gcc_assert (sizeof reg_names == sizeof initial_reg_names);
  183. memcpy (fixed_regs, initial_fixed_regs, sizeof fixed_regs);
  184. memcpy (call_used_regs, initial_call_used_regs, sizeof call_used_regs);
  185. #ifdef CALL_REALLY_USED_REGISTERS
  186. memcpy (call_really_used_regs, initial_call_really_used_regs,
  187. sizeof call_really_used_regs);
  188. #endif
  189. #ifdef REG_ALLOC_ORDER
  190. memcpy (reg_alloc_order, initial_reg_alloc_order, sizeof reg_alloc_order);
  191. #endif
  192. memcpy (reg_names, initial_reg_names, sizeof reg_names);
  193. SET_HARD_REG_SET (accessible_reg_set);
  194. SET_HARD_REG_SET (operand_reg_set);
  195. }
  196. /* We need to save copies of some of the register information which
  197. can be munged by command-line switches so we can restore it during
  198. subsequent back-end reinitialization. */
  199. static char saved_fixed_regs[FIRST_PSEUDO_REGISTER];
  200. static char saved_call_used_regs[FIRST_PSEUDO_REGISTER];
  201. #ifdef CALL_REALLY_USED_REGISTERS
  202. static char saved_call_really_used_regs[FIRST_PSEUDO_REGISTER];
  203. #endif
  204. static const char *saved_reg_names[FIRST_PSEUDO_REGISTER];
  205. static HARD_REG_SET saved_accessible_reg_set;
  206. static HARD_REG_SET saved_operand_reg_set;
  207. /* Save the register information. */
  208. void
  209. save_register_info (void)
  210. {
  211. /* Sanity check: make sure the target macros FIXED_REGISTERS and
  212. CALL_USED_REGISTERS had the right number of initializers. */
  213. gcc_assert (sizeof fixed_regs == sizeof saved_fixed_regs);
  214. gcc_assert (sizeof call_used_regs == sizeof saved_call_used_regs);
  215. memcpy (saved_fixed_regs, fixed_regs, sizeof fixed_regs);
  216. memcpy (saved_call_used_regs, call_used_regs, sizeof call_used_regs);
  217. /* Likewise for call_really_used_regs. */
  218. #ifdef CALL_REALLY_USED_REGISTERS
  219. gcc_assert (sizeof call_really_used_regs
  220. == sizeof saved_call_really_used_regs);
  221. memcpy (saved_call_really_used_regs, call_really_used_regs,
  222. sizeof call_really_used_regs);
  223. #endif
  224. /* And similarly for reg_names. */
  225. gcc_assert (sizeof reg_names == sizeof saved_reg_names);
  226. memcpy (saved_reg_names, reg_names, sizeof reg_names);
  227. COPY_HARD_REG_SET (saved_accessible_reg_set, accessible_reg_set);
  228. COPY_HARD_REG_SET (saved_operand_reg_set, operand_reg_set);
  229. }
  230. /* Restore the register information. */
  231. static void
  232. restore_register_info (void)
  233. {
  234. memcpy (fixed_regs, saved_fixed_regs, sizeof fixed_regs);
  235. memcpy (call_used_regs, saved_call_used_regs, sizeof call_used_regs);
  236. #ifdef CALL_REALLY_USED_REGISTERS
  237. memcpy (call_really_used_regs, saved_call_really_used_regs,
  238. sizeof call_really_used_regs);
  239. #endif
  240. memcpy (reg_names, saved_reg_names, sizeof reg_names);
  241. COPY_HARD_REG_SET (accessible_reg_set, saved_accessible_reg_set);
  242. COPY_HARD_REG_SET (operand_reg_set, saved_operand_reg_set);
  243. }
  244. /* After switches have been processed, which perhaps alter
  245. `fixed_regs' and `call_used_regs', convert them to HARD_REG_SETs. */
  246. static void
  247. init_reg_sets_1 (void)
  248. {
  249. unsigned int i, j;
  250. unsigned int /* machine_mode */ m;
  251. restore_register_info ();
  252. #ifdef REG_ALLOC_ORDER
  253. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  254. inv_reg_alloc_order[reg_alloc_order[i]] = i;
  255. #endif
  256. /* Let the target tweak things if necessary. */
  257. targetm.conditional_register_usage ();
  258. /* Compute number of hard regs in each class. */
  259. memset (reg_class_size, 0, sizeof reg_class_size);
  260. for (i = 0; i < N_REG_CLASSES; i++)
  261. {
  262. bool any_nonfixed = false;
  263. for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  264. if (TEST_HARD_REG_BIT (reg_class_contents[i], j))
  265. {
  266. reg_class_size[i]++;
  267. if (!fixed_regs[j])
  268. any_nonfixed = true;
  269. }
  270. class_only_fixed_regs[i] = !any_nonfixed;
  271. }
  272. /* Initialize the table of subunions.
  273. reg_class_subunion[I][J] gets the largest-numbered reg-class
  274. that is contained in the union of classes I and J. */
  275. memset (reg_class_subunion, 0, sizeof reg_class_subunion);
  276. for (i = 0; i < N_REG_CLASSES; i++)
  277. {
  278. for (j = 0; j < N_REG_CLASSES; j++)
  279. {
  280. HARD_REG_SET c;
  281. int k;
  282. COPY_HARD_REG_SET (c, reg_class_contents[i]);
  283. IOR_HARD_REG_SET (c, reg_class_contents[j]);
  284. for (k = 0; k < N_REG_CLASSES; k++)
  285. if (hard_reg_set_subset_p (reg_class_contents[k], c)
  286. && !hard_reg_set_subset_p (reg_class_contents[k],
  287. reg_class_contents
  288. [(int) reg_class_subunion[i][j]]))
  289. reg_class_subunion[i][j] = (enum reg_class) k;
  290. }
  291. }
  292. /* Initialize the table of superunions.
  293. reg_class_superunion[I][J] gets the smallest-numbered reg-class
  294. containing the union of classes I and J. */
  295. memset (reg_class_superunion, 0, sizeof reg_class_superunion);
  296. for (i = 0; i < N_REG_CLASSES; i++)
  297. {
  298. for (j = 0; j < N_REG_CLASSES; j++)
  299. {
  300. HARD_REG_SET c;
  301. int k;
  302. COPY_HARD_REG_SET (c, reg_class_contents[i]);
  303. IOR_HARD_REG_SET (c, reg_class_contents[j]);
  304. for (k = 0; k < N_REG_CLASSES; k++)
  305. if (hard_reg_set_subset_p (c, reg_class_contents[k]))
  306. break;
  307. reg_class_superunion[i][j] = (enum reg_class) k;
  308. }
  309. }
  310. /* Initialize the tables of subclasses and superclasses of each reg class.
  311. First clear the whole table, then add the elements as they are found. */
  312. for (i = 0; i < N_REG_CLASSES; i++)
  313. {
  314. for (j = 0; j < N_REG_CLASSES; j++)
  315. reg_class_subclasses[i][j] = LIM_REG_CLASSES;
  316. }
  317. for (i = 0; i < N_REG_CLASSES; i++)
  318. {
  319. if (i == (int) NO_REGS)
  320. continue;
  321. for (j = i + 1; j < N_REG_CLASSES; j++)
  322. if (hard_reg_set_subset_p (reg_class_contents[i],
  323. reg_class_contents[j]))
  324. {
  325. /* Reg class I is a subclass of J.
  326. Add J to the table of superclasses of I. */
  327. enum reg_class *p;
  328. /* Add I to the table of superclasses of J. */
  329. p = &reg_class_subclasses[j][0];
  330. while (*p != LIM_REG_CLASSES) p++;
  331. *p = (enum reg_class) i;
  332. }
  333. }
  334. /* Initialize "constant" tables. */
  335. CLEAR_HARD_REG_SET (fixed_reg_set);
  336. CLEAR_HARD_REG_SET (call_used_reg_set);
  337. CLEAR_HARD_REG_SET (call_fixed_reg_set);
  338. CLEAR_HARD_REG_SET (regs_invalidated_by_call);
  339. if (!regs_invalidated_by_call_regset)
  340. {
  341. bitmap_obstack_initialize (&persistent_obstack);
  342. regs_invalidated_by_call_regset = ALLOC_REG_SET (&persistent_obstack);
  343. }
  344. else
  345. CLEAR_REG_SET (regs_invalidated_by_call_regset);
  346. if (!fixed_reg_set_regset)
  347. fixed_reg_set_regset = ALLOC_REG_SET (&persistent_obstack);
  348. else
  349. CLEAR_REG_SET (fixed_reg_set_regset);
  350. AND_HARD_REG_SET (operand_reg_set, accessible_reg_set);
  351. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  352. {
  353. /* As a special exception, registers whose class is NO_REGS are
  354. not accepted by `register_operand'. The reason for this change
  355. is to allow the representation of special architecture artifacts
  356. (such as a condition code register) without extending the rtl
  357. definitions. Since registers of class NO_REGS cannot be used
  358. as registers in any case where register classes are examined,
  359. it is better to apply this exception in a target-independent way. */
  360. if (REGNO_REG_CLASS (i) == NO_REGS)
  361. CLEAR_HARD_REG_BIT (operand_reg_set, i);
  362. /* If a register is too limited to be treated as a register operand,
  363. then it should never be allocated to a pseudo. */
  364. if (!TEST_HARD_REG_BIT (operand_reg_set, i))
  365. {
  366. fixed_regs[i] = 1;
  367. call_used_regs[i] = 1;
  368. }
  369. /* call_used_regs must include fixed_regs. */
  370. gcc_assert (!fixed_regs[i] || call_used_regs[i]);
  371. #ifdef CALL_REALLY_USED_REGISTERS
  372. /* call_used_regs must include call_really_used_regs. */
  373. gcc_assert (!call_really_used_regs[i] || call_used_regs[i]);
  374. #endif
  375. if (fixed_regs[i])
  376. {
  377. SET_HARD_REG_BIT (fixed_reg_set, i);
  378. SET_REGNO_REG_SET (fixed_reg_set_regset, i);
  379. }
  380. if (call_used_regs[i])
  381. SET_HARD_REG_BIT (call_used_reg_set, i);
  382. /* There are a couple of fixed registers that we know are safe to
  383. exclude from being clobbered by calls:
  384. The frame pointer is always preserved across calls. The arg
  385. pointer is if it is fixed. The stack pointer usually is,
  386. unless TARGET_RETURN_POPS_ARGS, in which case an explicit
  387. CLOBBER will be present. If we are generating PIC code, the
  388. PIC offset table register is preserved across calls, though the
  389. target can override that. */
  390. if (i == STACK_POINTER_REGNUM)
  391. ;
  392. else if (global_regs[i])
  393. {
  394. SET_HARD_REG_BIT (regs_invalidated_by_call, i);
  395. SET_REGNO_REG_SET (regs_invalidated_by_call_regset, i);
  396. }
  397. else if (i == FRAME_POINTER_REGNUM)
  398. ;
  399. #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
  400. else if (i == HARD_FRAME_POINTER_REGNUM)
  401. ;
  402. #endif
  403. #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  404. else if (i == ARG_POINTER_REGNUM && fixed_regs[i])
  405. ;
  406. #endif
  407. else if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
  408. && i == (unsigned) PIC_OFFSET_TABLE_REGNUM && fixed_regs[i])
  409. ;
  410. else if (CALL_REALLY_USED_REGNO_P (i))
  411. {
  412. SET_HARD_REG_BIT (regs_invalidated_by_call, i);
  413. SET_REGNO_REG_SET (regs_invalidated_by_call_regset, i);
  414. }
  415. }
  416. COPY_HARD_REG_SET (call_fixed_reg_set, fixed_reg_set);
  417. /* Preserve global registers if called more than once. */
  418. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  419. {
  420. if (global_regs[i])
  421. {
  422. fixed_regs[i] = call_used_regs[i] = 1;
  423. SET_HARD_REG_BIT (fixed_reg_set, i);
  424. SET_HARD_REG_BIT (call_used_reg_set, i);
  425. SET_HARD_REG_BIT (call_fixed_reg_set, i);
  426. }
  427. }
  428. memset (have_regs_of_mode, 0, sizeof (have_regs_of_mode));
  429. memset (contains_reg_of_mode, 0, sizeof (contains_reg_of_mode));
  430. for (m = 0; m < (unsigned int) MAX_MACHINE_MODE; m++)
  431. {
  432. HARD_REG_SET ok_regs;
  433. CLEAR_HARD_REG_SET (ok_regs);
  434. for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  435. if (!fixed_regs [j] && HARD_REGNO_MODE_OK (j, (machine_mode) m))
  436. SET_HARD_REG_BIT (ok_regs, j);
  437. for (i = 0; i < N_REG_CLASSES; i++)
  438. if ((targetm.class_max_nregs ((reg_class_t) i, (machine_mode) m)
  439. <= reg_class_size[i])
  440. && hard_reg_set_intersect_p (ok_regs, reg_class_contents[i]))
  441. {
  442. contains_reg_of_mode [i][m] = 1;
  443. have_regs_of_mode [m] = 1;
  444. }
  445. }
  446. }
  447. /* Compute the table of register modes.
  448. These values are used to record death information for individual registers
  449. (as opposed to a multi-register mode).
  450. This function might be invoked more than once, if the target has support
  451. for changing register usage conventions on a per-function basis.
  452. */
  453. void
  454. init_reg_modes_target (void)
  455. {
  456. int i, j;
  457. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  458. for (j = 0; j < MAX_MACHINE_MODE; j++)
  459. hard_regno_nregs[i][j] = HARD_REGNO_NREGS (i, (machine_mode)j);
  460. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  461. {
  462. reg_raw_mode[i] = choose_hard_reg_mode (i, 1, false);
  463. /* If we couldn't find a valid mode, just use the previous mode
  464. if it is suitable, otherwise fall back on word_mode. */
  465. if (reg_raw_mode[i] == VOIDmode)
  466. {
  467. if (i > 0 && hard_regno_nregs[i][reg_raw_mode[i - 1]] == 1)
  468. reg_raw_mode[i] = reg_raw_mode[i - 1];
  469. else
  470. reg_raw_mode[i] = word_mode;
  471. }
  472. }
  473. }
  474. /* Finish initializing the register sets and initialize the register modes.
  475. This function might be invoked more than once, if the target has support
  476. for changing register usage conventions on a per-function basis.
  477. */
  478. void
  479. init_regs (void)
  480. {
  481. /* This finishes what was started by init_reg_sets, but couldn't be done
  482. until after register usage was specified. */
  483. init_reg_sets_1 ();
  484. }
  485. /* The same as previous function plus initializing IRA. */
  486. void
  487. reinit_regs (void)
  488. {
  489. init_regs ();
  490. /* caller_save needs to be re-initialized. */
  491. caller_save_initialized_p = false;
  492. if (this_target_rtl->target_specific_initialized)
  493. {
  494. ira_init ();
  495. recog_init ();
  496. }
  497. }
  498. /* Initialize some fake stack-frame MEM references for use in
  499. memory_move_secondary_cost. */
  500. void
  501. init_fake_stack_mems (void)
  502. {
  503. int i;
  504. for (i = 0; i < MAX_MACHINE_MODE; i++)
  505. top_of_stack[i] = gen_rtx_MEM ((machine_mode) i, stack_pointer_rtx);
  506. }
  507. /* Compute cost of moving data from a register of class FROM to one of
  508. TO, using MODE. */
  509. int
  510. register_move_cost (machine_mode mode, reg_class_t from, reg_class_t to)
  511. {
  512. return targetm.register_move_cost (mode, from, to);
  513. }
  514. /* Compute cost of moving registers to/from memory. */
  515. int
  516. memory_move_cost (machine_mode mode, reg_class_t rclass, bool in)
  517. {
  518. return targetm.memory_move_cost (mode, rclass, in);
  519. }
  520. /* Compute extra cost of moving registers to/from memory due to reloads.
  521. Only needed if secondary reloads are required for memory moves. */
  522. int
  523. memory_move_secondary_cost (machine_mode mode, reg_class_t rclass,
  524. bool in)
  525. {
  526. reg_class_t altclass;
  527. int partial_cost = 0;
  528. /* We need a memory reference to feed to SECONDARY... macros. */
  529. /* mem may be unused even if the SECONDARY_ macros are defined. */
  530. rtx mem ATTRIBUTE_UNUSED = top_of_stack[(int) mode];
  531. altclass = secondary_reload_class (in ? 1 : 0, rclass, mode, mem);
  532. if (altclass == NO_REGS)
  533. return 0;
  534. if (in)
  535. partial_cost = register_move_cost (mode, altclass, rclass);
  536. else
  537. partial_cost = register_move_cost (mode, rclass, altclass);
  538. if (rclass == altclass)
  539. /* This isn't simply a copy-to-temporary situation. Can't guess
  540. what it is, so TARGET_MEMORY_MOVE_COST really ought not to be
  541. calling here in that case.
  542. I'm tempted to put in an assert here, but returning this will
  543. probably only give poor estimates, which is what we would've
  544. had before this code anyways. */
  545. return partial_cost;
  546. /* Check if the secondary reload register will also need a
  547. secondary reload. */
  548. return memory_move_secondary_cost (mode, altclass, in) + partial_cost;
  549. }
  550. /* Return a machine mode that is legitimate for hard reg REGNO and large
  551. enough to save nregs. If we can't find one, return VOIDmode.
  552. If CALL_SAVED is true, only consider modes that are call saved. */
  553. machine_mode
  554. choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED,
  555. unsigned int nregs, bool call_saved)
  556. {
  557. unsigned int /* machine_mode */ m;
  558. machine_mode found_mode = VOIDmode, mode;
  559. /* We first look for the largest integer mode that can be validly
  560. held in REGNO. If none, we look for the largest floating-point mode.
  561. If we still didn't find a valid mode, try CCmode. */
  562. for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
  563. mode != VOIDmode;
  564. mode = GET_MODE_WIDER_MODE (mode))
  565. if ((unsigned) hard_regno_nregs[regno][mode] == nregs
  566. && HARD_REGNO_MODE_OK (regno, mode)
  567. && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode))
  568. && GET_MODE_SIZE (mode) > GET_MODE_SIZE (found_mode))
  569. found_mode = mode;
  570. for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
  571. mode != VOIDmode;
  572. mode = GET_MODE_WIDER_MODE (mode))
  573. if ((unsigned) hard_regno_nregs[regno][mode] == nregs
  574. && HARD_REGNO_MODE_OK (regno, mode)
  575. && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode))
  576. && GET_MODE_SIZE (mode) > GET_MODE_SIZE (found_mode))
  577. found_mode = mode;
  578. for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT);
  579. mode != VOIDmode;
  580. mode = GET_MODE_WIDER_MODE (mode))
  581. if ((unsigned) hard_regno_nregs[regno][mode] == nregs
  582. && HARD_REGNO_MODE_OK (regno, mode)
  583. && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode))
  584. && GET_MODE_SIZE (mode) > GET_MODE_SIZE (found_mode))
  585. found_mode = mode;
  586. for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT);
  587. mode != VOIDmode;
  588. mode = GET_MODE_WIDER_MODE (mode))
  589. if ((unsigned) hard_regno_nregs[regno][mode] == nregs
  590. && HARD_REGNO_MODE_OK (regno, mode)
  591. && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode))
  592. && GET_MODE_SIZE (mode) > GET_MODE_SIZE (found_mode))
  593. found_mode = mode;
  594. if (found_mode != VOIDmode)
  595. return found_mode;
  596. /* Iterate over all of the CCmodes. */
  597. for (m = (unsigned int) CCmode; m < (unsigned int) NUM_MACHINE_MODES; ++m)
  598. {
  599. mode = (machine_mode) m;
  600. if ((unsigned) hard_regno_nregs[regno][mode] == nregs
  601. && HARD_REGNO_MODE_OK (regno, mode)
  602. && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
  603. return mode;
  604. }
  605. /* We can't find a mode valid for this register. */
  606. return VOIDmode;
  607. }
  608. /* Specify the usage characteristics of the register named NAME.
  609. It should be a fixed register if FIXED and a
  610. call-used register if CALL_USED. */
  611. void
  612. fix_register (const char *name, int fixed, int call_used)
  613. {
  614. int i;
  615. int reg, nregs;
  616. /* Decode the name and update the primary form of
  617. the register info. */
  618. if ((reg = decode_reg_name_and_count (name, &nregs)) >= 0)
  619. {
  620. gcc_assert (nregs >= 1);
  621. for (i = reg; i < reg + nregs; i++)
  622. {
  623. if ((i == STACK_POINTER_REGNUM
  624. #ifdef HARD_FRAME_POINTER_REGNUM
  625. || i == HARD_FRAME_POINTER_REGNUM
  626. #else
  627. || i == FRAME_POINTER_REGNUM
  628. #endif
  629. )
  630. && (fixed == 0 || call_used == 0))
  631. {
  632. switch (fixed)
  633. {
  634. case 0:
  635. switch (call_used)
  636. {
  637. case 0:
  638. error ("can%'t use %qs as a call-saved register", name);
  639. break;
  640. case 1:
  641. error ("can%'t use %qs as a call-used register", name);
  642. break;
  643. default:
  644. gcc_unreachable ();
  645. }
  646. break;
  647. case 1:
  648. switch (call_used)
  649. {
  650. case 1:
  651. error ("can%'t use %qs as a fixed register", name);
  652. break;
  653. case 0:
  654. default:
  655. gcc_unreachable ();
  656. }
  657. break;
  658. default:
  659. gcc_unreachable ();
  660. }
  661. }
  662. else
  663. {
  664. fixed_regs[i] = fixed;
  665. call_used_regs[i] = call_used;
  666. #ifdef CALL_REALLY_USED_REGISTERS
  667. if (fixed == 0)
  668. call_really_used_regs[i] = call_used;
  669. #endif
  670. }
  671. }
  672. }
  673. else
  674. {
  675. warning (0, "unknown register name: %s", name);
  676. }
  677. }
  678. /* Mark register number I as global. */
  679. void
  680. globalize_reg (tree decl, int i)
  681. {
  682. location_t loc = DECL_SOURCE_LOCATION (decl);
  683. #ifdef STACK_REGS
  684. if (IN_RANGE (i, FIRST_STACK_REG, LAST_STACK_REG))
  685. {
  686. error ("stack register used for global register variable");
  687. return;
  688. }
  689. #endif
  690. if (fixed_regs[i] == 0 && no_global_reg_vars)
  691. error_at (loc, "global register variable follows a function definition");
  692. if (global_regs[i])
  693. {
  694. warning_at (loc, 0,
  695. "register of %qD used for multiple global register variables",
  696. decl);
  697. inform (DECL_SOURCE_LOCATION (global_regs_decl[i]),
  698. "conflicts with %qD", global_regs_decl[i]);
  699. return;
  700. }
  701. if (call_used_regs[i] && ! fixed_regs[i])
  702. warning_at (loc, 0, "call-clobbered register used for global register variable");
  703. global_regs[i] = 1;
  704. global_regs_decl[i] = decl;
  705. /* If we're globalizing the frame pointer, we need to set the
  706. appropriate regs_invalidated_by_call bit, even if it's already
  707. set in fixed_regs. */
  708. if (i != STACK_POINTER_REGNUM)
  709. {
  710. SET_HARD_REG_BIT (regs_invalidated_by_call, i);
  711. SET_REGNO_REG_SET (regs_invalidated_by_call_regset, i);
  712. }
  713. /* If already fixed, nothing else to do. */
  714. if (fixed_regs[i])
  715. return;
  716. fixed_regs[i] = call_used_regs[i] = 1;
  717. #ifdef CALL_REALLY_USED_REGISTERS
  718. call_really_used_regs[i] = 1;
  719. #endif
  720. SET_HARD_REG_BIT (fixed_reg_set, i);
  721. SET_HARD_REG_BIT (call_used_reg_set, i);
  722. SET_HARD_REG_BIT (call_fixed_reg_set, i);
  723. reinit_regs ();
  724. }
  725. /* Structure used to record preferences of given pseudo. */
  726. struct reg_pref
  727. {
  728. /* (enum reg_class) prefclass is the preferred class. May be
  729. NO_REGS if no class is better than memory. */
  730. char prefclass;
  731. /* altclass is a register class that we should use for allocating
  732. pseudo if no register in the preferred class is available.
  733. If no register in this class is available, memory is preferred.
  734. It might appear to be more general to have a bitmask of classes here,
  735. but since it is recommended that there be a class corresponding to the
  736. union of most major pair of classes, that generality is not required. */
  737. char altclass;
  738. /* allocnoclass is a register class that IRA uses for allocating
  739. the pseudo. */
  740. char allocnoclass;
  741. };
  742. /* Record preferences of each pseudo. This is available after RA is
  743. run. */
  744. static struct reg_pref *reg_pref;
  745. /* Current size of reg_info. */
  746. static int reg_info_size;
  747. /* Max_reg_num still last resize_reg_info call. */
  748. static int max_regno_since_last_resize;
  749. /* Return the reg_class in which pseudo reg number REGNO is best allocated.
  750. This function is sometimes called before the info has been computed.
  751. When that happens, just return GENERAL_REGS, which is innocuous. */
  752. enum reg_class
  753. reg_preferred_class (int regno)
  754. {
  755. if (reg_pref == 0)
  756. return GENERAL_REGS;
  757. gcc_assert (regno < reg_info_size);
  758. return (enum reg_class) reg_pref[regno].prefclass;
  759. }
  760. enum reg_class
  761. reg_alternate_class (int regno)
  762. {
  763. if (reg_pref == 0)
  764. return ALL_REGS;
  765. gcc_assert (regno < reg_info_size);
  766. return (enum reg_class) reg_pref[regno].altclass;
  767. }
  768. /* Return the reg_class which is used by IRA for its allocation. */
  769. enum reg_class
  770. reg_allocno_class (int regno)
  771. {
  772. if (reg_pref == 0)
  773. return NO_REGS;
  774. gcc_assert (regno < reg_info_size);
  775. return (enum reg_class) reg_pref[regno].allocnoclass;
  776. }
  777. /* Allocate space for reg info and initilize it. */
  778. static void
  779. allocate_reg_info (void)
  780. {
  781. int i;
  782. max_regno_since_last_resize = max_reg_num ();
  783. reg_info_size = max_regno_since_last_resize * 3 / 2 + 1;
  784. gcc_assert (! reg_pref && ! reg_renumber);
  785. reg_renumber = XNEWVEC (short, reg_info_size);
  786. reg_pref = XCNEWVEC (struct reg_pref, reg_info_size);
  787. memset (reg_renumber, -1, reg_info_size * sizeof (short));
  788. for (i = 0; i < reg_info_size; i++)
  789. {
  790. reg_pref[i].prefclass = GENERAL_REGS;
  791. reg_pref[i].altclass = ALL_REGS;
  792. reg_pref[i].allocnoclass = GENERAL_REGS;
  793. }
  794. }
  795. /* Resize reg info. The new elements will be initialized. Return TRUE
  796. if new pseudos were added since the last call. */
  797. bool
  798. resize_reg_info (void)
  799. {
  800. int old, i;
  801. bool change_p;
  802. if (reg_pref == NULL)
  803. {
  804. allocate_reg_info ();
  805. return true;
  806. }
  807. change_p = max_regno_since_last_resize != max_reg_num ();
  808. max_regno_since_last_resize = max_reg_num ();
  809. if (reg_info_size >= max_reg_num ())
  810. return change_p;
  811. old = reg_info_size;
  812. reg_info_size = max_reg_num () * 3 / 2 + 1;
  813. gcc_assert (reg_pref && reg_renumber);
  814. reg_renumber = XRESIZEVEC (short, reg_renumber, reg_info_size);
  815. reg_pref = XRESIZEVEC (struct reg_pref, reg_pref, reg_info_size);
  816. memset (reg_pref + old, -1,
  817. (reg_info_size - old) * sizeof (struct reg_pref));
  818. memset (reg_renumber + old, -1, (reg_info_size - old) * sizeof (short));
  819. for (i = old; i < reg_info_size; i++)
  820. {
  821. reg_pref[i].prefclass = GENERAL_REGS;
  822. reg_pref[i].altclass = ALL_REGS;
  823. reg_pref[i].allocnoclass = GENERAL_REGS;
  824. }
  825. return true;
  826. }
  827. /* Free up the space allocated by allocate_reg_info. */
  828. void
  829. free_reg_info (void)
  830. {
  831. if (reg_pref)
  832. {
  833. free (reg_pref);
  834. reg_pref = NULL;
  835. }
  836. if (reg_renumber)
  837. {
  838. free (reg_renumber);
  839. reg_renumber = NULL;
  840. }
  841. }
  842. /* Initialize some global data for this pass. */
  843. static unsigned int
  844. reginfo_init (void)
  845. {
  846. if (df)
  847. df_compute_regs_ever_live (true);
  848. /* This prevents dump_reg_info from losing if called
  849. before reginfo is run. */
  850. reg_pref = NULL;
  851. reg_info_size = max_regno_since_last_resize = 0;
  852. /* No more global register variables may be declared. */
  853. no_global_reg_vars = 1;
  854. return 1;
  855. }
  856. namespace {
  857. const pass_data pass_data_reginfo_init =
  858. {
  859. RTL_PASS, /* type */
  860. "reginfo", /* name */
  861. OPTGROUP_NONE, /* optinfo_flags */
  862. TV_NONE, /* tv_id */
  863. 0, /* properties_required */
  864. 0, /* properties_provided */
  865. 0, /* properties_destroyed */
  866. 0, /* todo_flags_start */
  867. 0, /* todo_flags_finish */
  868. };
  869. class pass_reginfo_init : public rtl_opt_pass
  870. {
  871. public:
  872. pass_reginfo_init (gcc::context *ctxt)
  873. : rtl_opt_pass (pass_data_reginfo_init, ctxt)
  874. {}
  875. /* opt_pass methods: */
  876. virtual unsigned int execute (function *) { return reginfo_init (); }
  877. }; // class pass_reginfo_init
  878. } // anon namespace
  879. rtl_opt_pass *
  880. make_pass_reginfo_init (gcc::context *ctxt)
  881. {
  882. return new pass_reginfo_init (ctxt);
  883. }
  884. /* Set up preferred, alternate, and allocno classes for REGNO as
  885. PREFCLASS, ALTCLASS, and ALLOCNOCLASS. */
  886. void
  887. setup_reg_classes (int regno,
  888. enum reg_class prefclass, enum reg_class altclass,
  889. enum reg_class allocnoclass)
  890. {
  891. if (reg_pref == NULL)
  892. return;
  893. gcc_assert (reg_info_size >= max_reg_num ());
  894. reg_pref[regno].prefclass = prefclass;
  895. reg_pref[regno].altclass = altclass;
  896. reg_pref[regno].allocnoclass = allocnoclass;
  897. }
  898. /* This is the `regscan' pass of the compiler, run just before cse and
  899. again just before loop. It finds the first and last use of each
  900. pseudo-register. */
  901. static void reg_scan_mark_refs (rtx, rtx_insn *);
  902. void
  903. reg_scan (rtx_insn *f, unsigned int nregs ATTRIBUTE_UNUSED)
  904. {
  905. rtx_insn *insn;
  906. timevar_push (TV_REG_SCAN);
  907. for (insn = f; insn; insn = NEXT_INSN (insn))
  908. if (INSN_P (insn))
  909. {
  910. reg_scan_mark_refs (PATTERN (insn), insn);
  911. if (REG_NOTES (insn))
  912. reg_scan_mark_refs (REG_NOTES (insn), insn);
  913. }
  914. timevar_pop (TV_REG_SCAN);
  915. }
  916. /* X is the expression to scan. INSN is the insn it appears in.
  917. NOTE_FLAG is nonzero if X is from INSN's notes rather than its body.
  918. We should only record information for REGs with numbers
  919. greater than or equal to MIN_REGNO. */
  920. static void
  921. reg_scan_mark_refs (rtx x, rtx_insn *insn)
  922. {
  923. enum rtx_code code;
  924. rtx dest;
  925. rtx note;
  926. if (!x)
  927. return;
  928. code = GET_CODE (x);
  929. switch (code)
  930. {
  931. case CONST:
  932. CASE_CONST_ANY:
  933. case CC0:
  934. case PC:
  935. case SYMBOL_REF:
  936. case LABEL_REF:
  937. case ADDR_VEC:
  938. case ADDR_DIFF_VEC:
  939. case REG:
  940. return;
  941. case EXPR_LIST:
  942. if (XEXP (x, 0))
  943. reg_scan_mark_refs (XEXP (x, 0), insn);
  944. if (XEXP (x, 1))
  945. reg_scan_mark_refs (XEXP (x, 1), insn);
  946. break;
  947. case INSN_LIST:
  948. case INT_LIST:
  949. if (XEXP (x, 1))
  950. reg_scan_mark_refs (XEXP (x, 1), insn);
  951. break;
  952. case CLOBBER:
  953. if (MEM_P (XEXP (x, 0)))
  954. reg_scan_mark_refs (XEXP (XEXP (x, 0), 0), insn);
  955. break;
  956. case SET:
  957. /* Count a set of the destination if it is a register. */
  958. for (dest = SET_DEST (x);
  959. GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
  960. || GET_CODE (dest) == ZERO_EXTRACT;
  961. dest = XEXP (dest, 0))
  962. ;
  963. /* If this is setting a pseudo from another pseudo or the sum of a
  964. pseudo and a constant integer and the other pseudo is known to be
  965. a pointer, set the destination to be a pointer as well.
  966. Likewise if it is setting the destination from an address or from a
  967. value equivalent to an address or to the sum of an address and
  968. something else.
  969. But don't do any of this if the pseudo corresponds to a user
  970. variable since it should have already been set as a pointer based
  971. on the type. */
  972. if (REG_P (SET_DEST (x))
  973. && REGNO (SET_DEST (x)) >= FIRST_PSEUDO_REGISTER
  974. /* If the destination pseudo is set more than once, then other
  975. sets might not be to a pointer value (consider access to a
  976. union in two threads of control in the presence of global
  977. optimizations). So only set REG_POINTER on the destination
  978. pseudo if this is the only set of that pseudo. */
  979. && DF_REG_DEF_COUNT (REGNO (SET_DEST (x))) == 1
  980. && ! REG_USERVAR_P (SET_DEST (x))
  981. && ! REG_POINTER (SET_DEST (x))
  982. && ((REG_P (SET_SRC (x))
  983. && REG_POINTER (SET_SRC (x)))
  984. || ((GET_CODE (SET_SRC (x)) == PLUS
  985. || GET_CODE (SET_SRC (x)) == LO_SUM)
  986. && CONST_INT_P (XEXP (SET_SRC (x), 1))
  987. && REG_P (XEXP (SET_SRC (x), 0))
  988. && REG_POINTER (XEXP (SET_SRC (x), 0)))
  989. || GET_CODE (SET_SRC (x)) == CONST
  990. || GET_CODE (SET_SRC (x)) == SYMBOL_REF
  991. || GET_CODE (SET_SRC (x)) == LABEL_REF
  992. || (GET_CODE (SET_SRC (x)) == HIGH
  993. && (GET_CODE (XEXP (SET_SRC (x), 0)) == CONST
  994. || GET_CODE (XEXP (SET_SRC (x), 0)) == SYMBOL_REF
  995. || GET_CODE (XEXP (SET_SRC (x), 0)) == LABEL_REF))
  996. || ((GET_CODE (SET_SRC (x)) == PLUS
  997. || GET_CODE (SET_SRC (x)) == LO_SUM)
  998. && (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST
  999. || GET_CODE (XEXP (SET_SRC (x), 1)) == SYMBOL_REF
  1000. || GET_CODE (XEXP (SET_SRC (x), 1)) == LABEL_REF))
  1001. || ((note = find_reg_note (insn, REG_EQUAL, 0)) != 0
  1002. && (GET_CODE (XEXP (note, 0)) == CONST
  1003. || GET_CODE (XEXP (note, 0)) == SYMBOL_REF
  1004. || GET_CODE (XEXP (note, 0)) == LABEL_REF))))
  1005. REG_POINTER (SET_DEST (x)) = 1;
  1006. /* If this is setting a register from a register or from a simple
  1007. conversion of a register, propagate REG_EXPR. */
  1008. if (REG_P (dest) && !REG_ATTRS (dest))
  1009. set_reg_attrs_from_value (dest, SET_SRC (x));
  1010. /* ... fall through ... */
  1011. default:
  1012. {
  1013. const char *fmt = GET_RTX_FORMAT (code);
  1014. int i;
  1015. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1016. {
  1017. if (fmt[i] == 'e')
  1018. reg_scan_mark_refs (XEXP (x, i), insn);
  1019. else if (fmt[i] == 'E' && XVEC (x, i) != 0)
  1020. {
  1021. int j;
  1022. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1023. reg_scan_mark_refs (XVECEXP (x, i, j), insn);
  1024. }
  1025. }
  1026. }
  1027. }
  1028. }
  1029. /* Return nonzero if C1 is a subset of C2, i.e., if every register in C1
  1030. is also in C2. */
  1031. int
  1032. reg_class_subset_p (reg_class_t c1, reg_class_t c2)
  1033. {
  1034. return (c1 == c2
  1035. || c2 == ALL_REGS
  1036. || hard_reg_set_subset_p (reg_class_contents[(int) c1],
  1037. reg_class_contents[(int) c2]));
  1038. }
  1039. /* Return nonzero if there is a register that is in both C1 and C2. */
  1040. int
  1041. reg_classes_intersect_p (reg_class_t c1, reg_class_t c2)
  1042. {
  1043. return (c1 == c2
  1044. || c1 == ALL_REGS
  1045. || c2 == ALL_REGS
  1046. || hard_reg_set_intersect_p (reg_class_contents[(int) c1],
  1047. reg_class_contents[(int) c2]));
  1048. }
  1049. inline hashval_t
  1050. simplifiable_subregs_hasher::hash (const value_type *value)
  1051. {
  1052. return value->shape.unique_id ();
  1053. }
  1054. inline bool
  1055. simplifiable_subregs_hasher::equal (const value_type *value,
  1056. const compare_type *compare)
  1057. {
  1058. return value->shape == *compare;
  1059. }
  1060. inline simplifiable_subreg::simplifiable_subreg (const subreg_shape &shape_in)
  1061. : shape (shape_in)
  1062. {
  1063. CLEAR_HARD_REG_SET (simplifiable_regs);
  1064. }
  1065. /* Return the set of hard registers that are able to form the subreg
  1066. described by SHAPE. */
  1067. const HARD_REG_SET &
  1068. simplifiable_subregs (const subreg_shape &shape)
  1069. {
  1070. if (!this_target_hard_regs->x_simplifiable_subregs)
  1071. this_target_hard_regs->x_simplifiable_subregs
  1072. = new hash_table <simplifiable_subregs_hasher> (30);
  1073. simplifiable_subreg **slot
  1074. = (this_target_hard_regs->x_simplifiable_subregs
  1075. ->find_slot_with_hash (&shape, shape.unique_id (), INSERT));
  1076. if (!*slot)
  1077. {
  1078. simplifiable_subreg *info = new simplifiable_subreg (shape);
  1079. for (unsigned int i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
  1080. if (HARD_REGNO_MODE_OK (i, shape.inner_mode)
  1081. && simplify_subreg_regno (i, shape.inner_mode, shape.offset,
  1082. shape.outer_mode) >= 0)
  1083. SET_HARD_REG_BIT (info->simplifiable_regs, i);
  1084. *slot = info;
  1085. }
  1086. return (*slot)->simplifiable_regs;
  1087. }
  1088. /* Passes for keeping and updating info about modes of registers
  1089. inside subregisters. */
  1090. static HARD_REG_SET **valid_mode_changes;
  1091. static obstack valid_mode_changes_obstack;
  1092. static void
  1093. record_subregs_of_mode (rtx subreg)
  1094. {
  1095. unsigned int regno;
  1096. if (!REG_P (SUBREG_REG (subreg)))
  1097. return;
  1098. regno = REGNO (SUBREG_REG (subreg));
  1099. if (regno < FIRST_PSEUDO_REGISTER)
  1100. return;
  1101. if (valid_mode_changes[regno])
  1102. AND_HARD_REG_SET (*valid_mode_changes[regno],
  1103. simplifiable_subregs (shape_of_subreg (subreg)));
  1104. else
  1105. {
  1106. valid_mode_changes[regno]
  1107. = XOBNEW (&valid_mode_changes_obstack, HARD_REG_SET);
  1108. COPY_HARD_REG_SET (*valid_mode_changes[regno],
  1109. simplifiable_subregs (shape_of_subreg (subreg)));
  1110. }
  1111. }
  1112. /* Call record_subregs_of_mode for all the subregs in X. */
  1113. static void
  1114. find_subregs_of_mode (rtx x)
  1115. {
  1116. enum rtx_code code = GET_CODE (x);
  1117. const char * const fmt = GET_RTX_FORMAT (code);
  1118. int i;
  1119. if (code == SUBREG)
  1120. record_subregs_of_mode (x);
  1121. /* Time for some deep diving. */
  1122. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1123. {
  1124. if (fmt[i] == 'e')
  1125. find_subregs_of_mode (XEXP (x, i));
  1126. else if (fmt[i] == 'E')
  1127. {
  1128. int j;
  1129. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1130. find_subregs_of_mode (XVECEXP (x, i, j));
  1131. }
  1132. }
  1133. }
  1134. void
  1135. init_subregs_of_mode (void)
  1136. {
  1137. basic_block bb;
  1138. rtx_insn *insn;
  1139. gcc_obstack_init (&valid_mode_changes_obstack);
  1140. valid_mode_changes = XCNEWVEC (HARD_REG_SET *, max_reg_num ());
  1141. FOR_EACH_BB_FN (bb, cfun)
  1142. FOR_BB_INSNS (bb, insn)
  1143. if (NONDEBUG_INSN_P (insn))
  1144. find_subregs_of_mode (PATTERN (insn));
  1145. }
  1146. const HARD_REG_SET *
  1147. valid_mode_changes_for_regno (unsigned int regno)
  1148. {
  1149. return valid_mode_changes[regno];
  1150. }
  1151. void
  1152. finish_subregs_of_mode (void)
  1153. {
  1154. XDELETEVEC (valid_mode_changes);
  1155. obstack_free (&valid_mode_changes_obstack, NULL);
  1156. }
  1157. /* Free all data attached to the structure. This isn't a destructor because
  1158. we don't want to run on exit. */
  1159. void
  1160. target_hard_regs::finalize ()
  1161. {
  1162. delete x_simplifiable_subregs;
  1163. }