regclass.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. /* Compute register class preferences for pseudo-registers.
  2. Copyright (C) 1987 Free Software Foundation, Inc.
  3. This file is part of GNU CC.
  4. GNU CC is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the GNU CC General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. GNU CC, but only under the conditions described in the
  12. GNU CC General Public License. A copy of this license is
  13. supposed to have been given to you along with GNU CC so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. /* This file contains two passes of the compiler: reg_scan and reg_class.
  18. It also defines some tables of information about the hardware registers
  19. and a function init_reg_sets to initialize the tables. */
  20. #include "config.h"
  21. #include "rtl.h"
  22. #include "hard-reg-set.h"
  23. #include "flags.h"
  24. #include "regs.h"
  25. #include "insn-config.h"
  26. #include "recog.h"
  27. #define max(A,B) ((A) > (B) ? (A) : (B))
  28. #define min(A,B) ((A) < (B) ? (A) : (B))
  29. /* Register tables used by many passes. */
  30. /* Indexed by hard register number, contains 1 for registers
  31. that are fixed use (stack pointer, pc, frame pointer, etc.).
  32. These are the registers that cannot be used to allocate
  33. a pseudo reg whose life does not cross calls. */
  34. char fixed_regs[FIRST_PSEUDO_REGISTER];
  35. /* Same info as a HARD_REG_SET. */
  36. HARD_REG_SET fixed_reg_set;
  37. /* Data for initializing the above. */
  38. static char initial_fixed_regs[] = FIXED_REGISTERS;
  39. /* Indexed by hard register number, contains 1 for registers
  40. that are fixed use or are clobbered by function calls.
  41. These are the registers that cannot be used to allocate
  42. a pseudo reg whose life crosses calls. */
  43. char call_used_regs[FIRST_PSEUDO_REGISTER];
  44. /* Same info as a HARD_REG_SET. */
  45. HARD_REG_SET call_used_reg_set;
  46. /* Data for initializing the above. */
  47. static char initial_call_used_regs[] = CALL_USED_REGISTERS;
  48. /* For each reg class, a HARD_REG_SET saying which registers are in it. */
  49. HARD_REG_SET reg_class_contents[] = REG_CLASS_CONTENTS;
  50. /* For each reg class, table listing all the containing classes. */
  51. enum reg_class reg_class_superclasses[N_REG_CLASSES][N_REG_CLASSES];
  52. /* For each reg class, table listing all the classes contained in it. */
  53. enum reg_class reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
  54. /* For each pair of reg classes,
  55. a largest reg class contained in their union. */
  56. enum reg_class reg_class_subunion[N_REG_CLASSES][N_REG_CLASSES];
  57. /* Function called only once to initialize the tables above. */
  58. void
  59. init_reg_sets ()
  60. {
  61. register int i, j;
  62. bcopy (initial_fixed_regs, fixed_regs, sizeof fixed_regs);
  63. bcopy (initial_call_used_regs, call_used_regs, sizeof call_used_regs);
  64. /* This macro allows the fixed or call-used registers
  65. to depend on target flags. */
  66. #ifdef CONDITIONAL_REGISTER_USAGE
  67. CONDITIONAL_REGISTER_USAGE
  68. #endif
  69. /* Initialize "constant" tables. */
  70. CLEAR_HARD_REG_SET (fixed_reg_set);
  71. CLEAR_HARD_REG_SET (call_used_reg_set);
  72. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  73. {
  74. if (fixed_regs[i])
  75. SET_HARD_REG_BIT (fixed_reg_set, i);
  76. if (call_used_regs[i])
  77. SET_HARD_REG_BIT (call_used_reg_set, i);
  78. }
  79. /* Initialize the table of subunions.
  80. reg_class_subunion[I][J] gets the largest-numbered reg-class
  81. that is contained in the union of classes I and J. */
  82. for (i = 0; i < N_REG_CLASSES; i++)
  83. {
  84. for (j = 0; j < N_REG_CLASSES; j++)
  85. {
  86. #ifdef HARD_REG_SET
  87. register /* Declare it register if it's a scalar. */
  88. #endif
  89. HARD_REG_SET c;
  90. register int k;
  91. COPY_HARD_REG_SET (c, reg_class_contents[i]);
  92. IOR_HARD_REG_SET (c, reg_class_contents[j]);
  93. for (k = 0; k < N_REG_CLASSES; k++)
  94. {
  95. GO_IF_HARD_REG_SUBSET (reg_class_contents[k], c,
  96. subclass1);
  97. continue;
  98. subclass1:
  99. reg_class_subunion[i][j] = (enum reg_class) k;
  100. }
  101. }
  102. }
  103. /* Initialize the tables of subclasses and superclasses of each reg class.
  104. First clear the whole table, then add the elements as they are found. */
  105. for (i = 0; i < N_REG_CLASSES; i++)
  106. {
  107. for (j = 0; j < N_REG_CLASSES; j++)
  108. {
  109. reg_class_superclasses[i][j] = LIM_REG_CLASSES;
  110. reg_class_subclasses[i][j] = LIM_REG_CLASSES;
  111. }
  112. }
  113. for (i = 0; i < N_REG_CLASSES; i++)
  114. {
  115. if (i == (int) NO_REGS)
  116. continue;
  117. for (j = i + 1; j < N_REG_CLASSES; j++)
  118. {
  119. enum reg_class *p;
  120. GO_IF_HARD_REG_SUBSET (reg_class_contents[i], reg_class_contents[j],
  121. subclass);
  122. continue;
  123. subclass:
  124. /* Reg class I is a subclass of J.
  125. Add J to the table of superclasses of I. */
  126. p = &reg_class_superclasses[i][0];
  127. while (*p != LIM_REG_CLASSES) p++;
  128. *p = (enum reg_class) j;
  129. /* Add I to the table of superclasses of J. */
  130. p = &reg_class_subclasses[j][0];
  131. while (*p != LIM_REG_CLASSES) p++;
  132. *p = (enum reg_class) i;
  133. }
  134. }
  135. }
  136. /* Specify the usage characteristics of the register named NAME.
  137. It should be a fixed register if FIXED and a
  138. call-used register if CALL_USED. */
  139. void
  140. fix_register (name, fixed, call_used)
  141. char *name;
  142. int fixed, call_used;
  143. {
  144. static char *reg_names[] = REGISTER_NAMES;
  145. int i;
  146. /* Decode the name and update the primary form of
  147. the register info. */
  148. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  149. if (!strcmp (reg_names[i], name))
  150. {
  151. fixed_regs[i] = fixed;
  152. call_used_regs[i] = call_used;
  153. break;
  154. }
  155. if (i == FIRST_PSEUDO_REGISTER)
  156. {
  157. warning ("unknown register name: %s", name);
  158. return;
  159. }
  160. /* Reinitialize the HARD_REG_SETs that have the same info. */
  161. CLEAR_HARD_REG_SET (fixed_reg_set);
  162. CLEAR_HARD_REG_SET (call_used_reg_set);
  163. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  164. {
  165. if (fixed_regs[i])
  166. SET_HARD_REG_BIT (fixed_reg_set, i);
  167. if (call_used_regs[i])
  168. SET_HARD_REG_BIT (call_used_reg_set, i);
  169. }
  170. }
  171. /* Now the data and code for the `regclass' pass, which happens
  172. just before local-alloc. */
  173. /* savings[R].savings[CL] is twice the amount saved by putting register R
  174. in class CL. This data is used within `regclass' and freed
  175. when it is finished. */
  176. struct savings
  177. {
  178. short savings[N_REG_CLASSES];
  179. short memcost;
  180. };
  181. static struct savings *savings;
  182. /* (enum reg_class) prefclass[R] is the preferred class for pseudo number R.
  183. This is available after `regclass' is run. */
  184. static char *prefclass;
  185. /* preferred_or_nothing[R] is nonzero if we should put pseudo number R
  186. in memory if we can't get its perferred class.
  187. This is available after `regclass' is run. */
  188. static char *preferred_or_nothing;
  189. void reg_class_record ();
  190. void record_address_regs ();
  191. /* Return the reg_class in which pseudo reg number REGNO is best allocated.
  192. This function is sometimes called before the info has been computed.
  193. When that happens, just return GENERAL_REGS, which is innocuous. */
  194. enum reg_class
  195. reg_preferred_class (regno)
  196. int regno;
  197. {
  198. if (prefclass == 0)
  199. return GENERAL_REGS;
  200. return (enum reg_class) prefclass[regno];
  201. }
  202. int
  203. reg_preferred_or_nothing (regno)
  204. {
  205. if (prefclass == 0)
  206. return 0;
  207. return preferred_or_nothing[regno];
  208. }
  209. /* This prevents dump_flow_info from losing if called
  210. before regclass is run. */
  211. int
  212. regclass_init ()
  213. {
  214. prefclass = 0;
  215. }
  216. /* This is a pass of the compiler that scans all instructions
  217. and calculates the preferred class for each pseudo-register.
  218. This information can be accessed later by calling `reg_preferred_class'.
  219. This pass comes just before local register allocation. */
  220. void
  221. regclass (f, nregs)
  222. rtx f;
  223. int nregs;
  224. {
  225. #ifdef REGISTER_CONSTRAINTS
  226. register rtx insn;
  227. register int i;
  228. init_recog ();
  229. /* Zero out our accumulation of the cost of each class for each reg. */
  230. savings = (struct savings *) alloca (nregs * sizeof (struct savings));
  231. bzero (savings, nregs * sizeof (struct savings));
  232. /* Scan the instructions and record each time it would
  233. save code to put a certain register in a certain class. */
  234. for (insn = f; insn; insn = NEXT_INSN (insn))
  235. if ((GET_CODE (insn) == INSN
  236. && GET_CODE (PATTERN (insn)) != USE
  237. && GET_CODE (PATTERN (insn)) != CLOBBER
  238. && GET_CODE (PATTERN (insn)) != ASM_INPUT)
  239. || (GET_CODE (insn) == JUMP_INSN
  240. && GET_CODE (PATTERN (insn)) != ADDR_VEC
  241. && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
  242. || GET_CODE (insn) == CALL_INSN)
  243. {
  244. if (GET_CODE (insn) == INSN && asm_noperands (PATTERN (insn)) > 0)
  245. {
  246. int noperands = asm_noperands (PATTERN (insn));
  247. rtx *operands = (rtx *) oballoc (noperands * sizeof (rtx));
  248. char **constraints
  249. = (char **) oballoc (noperands * sizeof (char *));
  250. decode_asm_operands (PATTERN (insn), operands, 0, constraints, 0);
  251. for (i = noperands - 1; i >= 0; i--)
  252. reg_class_record (operands[i],
  253. &constraints[i]);
  254. obfree (operands);
  255. }
  256. else
  257. {
  258. int insn_code_number = recog_memoized (insn);
  259. insn_extract (insn);
  260. for (i = insn_n_operands[insn_code_number] - 1; i >= 0; i--)
  261. reg_class_record (recog_operand[i],
  262. &insn_operand_constraint[insn_code_number][i]);
  263. /* Improve handling of two-address insns such as
  264. (set X (ashift CONST Y)) where CONST must be made to match X.
  265. Change it into two insns: (set X CONST) (set X (ashift X Y)).
  266. If we left this for reloading, it would probably get three insns
  267. because X and Y might go in the same place.
  268. This prevents X and Y from receiving the same hard reg. */
  269. if (optimize
  270. && insn_n_operands[insn_code_number] >= 3
  271. && insn_operand_constraint[insn_code_number][1][0] == '0'
  272. && insn_operand_constraint[insn_code_number][1][1] == 0
  273. && CONSTANT_P (recog_operand[1])
  274. && ! rtx_equal_p (recog_operand[0], recog_operand[1])
  275. && ! rtx_equal_p (recog_operand[0], recog_operand[2])
  276. && GET_CODE (recog_operand[0]) == REG)
  277. {
  278. emit_insn_before (gen_move_insn (recog_operand[0], recog_operand[1]),
  279. insn);
  280. /* This makes one more setting of new insns's destination. */
  281. reg_n_sets[REGNO (recog_operand[0])]++;
  282. *recog_operand_loc[1] = recog_operand[0];
  283. for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
  284. if (recog_dup_num[i] == 1)
  285. *recog_dup_loc[i] = recog_operand[0];
  286. }
  287. }
  288. }
  289. /* Now for each register look at how desirable each class is
  290. and find which class is preferred. Store that in `prefclass[REGNO]'. */
  291. prefclass = (char *) oballoc (nregs);
  292. preferred_or_nothing = (char *) oballoc (nregs);
  293. for (i = FIRST_PSEUDO_REGISTER; i < nregs; i++)
  294. {
  295. register int best_savings = 0;
  296. enum reg_class best = ALL_REGS;
  297. /* This is an enum reg_class, but we call it an int
  298. to save lots of casts. */
  299. register int class;
  300. register struct savings *p = &savings[i];
  301. for (class = (int) ALL_REGS - 1; class > 0; class--)
  302. {
  303. if (p->savings[class] > best_savings)
  304. {
  305. best_savings = p->savings[class];
  306. best = (enum reg_class) class;
  307. }
  308. else if (p->savings[class] == best_savings)
  309. {
  310. best = reg_class_subunion[(int)best][class];
  311. }
  312. }
  313. #if 0
  314. /* Note that best_savings is twice number of places something
  315. is saved. */
  316. if ((best_savings - p->savings[(int) GENERAL_REGS]) * 5 < reg_n_refs[i])
  317. prefclass[i] = (char) GENERAL_REGS;
  318. else
  319. prefclass[i] = (char) best;
  320. #else
  321. prefclass[i] = (char) best;
  322. #endif
  323. /* reg_n_refs + p->memcost measures the cost of putting in memory.
  324. If a GENERAL_REG is no better, don't even try for one. */
  325. if (reg_n_refs != 0)
  326. preferred_or_nothing[i]
  327. = ((best_savings - p->savings[(int) GENERAL_REGS]) / 2
  328. >= reg_n_refs[i] + p->memcost);
  329. }
  330. #endif /* REGISTER_CONSTRAINTS */
  331. }
  332. #ifdef REGISTER_CONSTRAINTS
  333. /* Scan an operand OP to which the constraint *CONSTRAINT_LOC should apply
  334. and record the preferred register classes from the constraint for OP
  335. if OP is a register. If OP is a memory reference, record suitable
  336. preferences for registers used in the address.
  337. We can deduce both the insn code number and which operand in the insn
  338. this is supposed to be from the position of CONSTRAINT_LOC
  339. in the table of constraints. */
  340. void
  341. reg_class_record (op, constraint_loc)
  342. rtx op;
  343. char **constraint_loc;
  344. {
  345. char *constraint = *constraint_loc;
  346. register char *p;
  347. register enum reg_class class = NO_REGS;
  348. char *next = 0;
  349. int insn_code = (constraint_loc - insn_operand_constraint[0]) / MAX_RECOG_OPERANDS;
  350. int memok = 0;
  351. int double_cost = 0;
  352. while (1)
  353. {
  354. if (GET_CODE (op) == SUBREG)
  355. op = SUBREG_REG (op);
  356. else break;
  357. }
  358. /* Memory reference: scan the address. */
  359. if (GET_CODE (op) == MEM)
  360. record_address_regs (XEXP (op, 0), 2, 0);
  361. if (GET_CODE (op) != REG)
  362. {
  363. /* If the constraint says the operand is supposed to BE an address,
  364. scan it as one. */
  365. if (constraint != 0 && constraint[0] == 'p')
  366. record_address_regs (op, 2, 0);
  367. return;
  368. }
  369. /* Operand is a register: examine the constraint for specified classes. */
  370. for (p = constraint; *p || next; p++)
  371. {
  372. if (*p == 0)
  373. {
  374. p = next;
  375. next = 0;
  376. }
  377. switch (*p)
  378. {
  379. case '=':
  380. case '?':
  381. case '#':
  382. case '!':
  383. case '%':
  384. case 'F':
  385. case 'G':
  386. case 'H':
  387. case 'i':
  388. case 'n':
  389. case 's':
  390. case 'p':
  391. case ',':
  392. break;
  393. case '+':
  394. /* An input-output operand is twice as costly if it loses. */
  395. double_cost = 1;
  396. break;
  397. case 'm':
  398. case 'o':
  399. memok = 1;
  400. break;
  401. /* * means ignore following letter
  402. when choosing register preferences. */
  403. case '*':
  404. p++;
  405. break;
  406. case 'g':
  407. case 'r':
  408. class
  409. = reg_class_subunion[(int) class][(int) GENERAL_REGS];
  410. break;
  411. case '0':
  412. case '1':
  413. case '2':
  414. case '3':
  415. case '4':
  416. /* If constraint says "match another operand",
  417. use that operand's constraint to choose preferences. */
  418. next = insn_operand_constraint[insn_code][*p - '0'];
  419. break;
  420. default:
  421. class
  422. = reg_class_subunion[(int) class][(int) REG_CLASS_FROM_LETTER (*p)];
  423. }
  424. }
  425. {
  426. register int i;
  427. register struct savings *pp;
  428. register enum reg_class class1;
  429. int cost = 2 * (1 + double_cost);
  430. pp = &savings[REGNO (op)];
  431. /* Increment the savings for this reg
  432. for each class contained in the one the constraint asks for. */
  433. if (class != NO_REGS && class != ALL_REGS)
  434. {
  435. pp->savings[(int) class] += cost;
  436. for (i = 0; ; i++)
  437. {
  438. class1 = reg_class_subclasses[(int)class][i];
  439. if (class1 == LIM_REG_CLASSES)
  440. break;
  441. pp->savings[(int) class1] += cost;
  442. }
  443. }
  444. if (! memok)
  445. pp->memcost += 1 + 2 * double_cost;
  446. }
  447. }
  448. /* Record the pseudo registers we must reload into hard registers
  449. in a subexpression of a memory address, X.
  450. BCOST is the cost if X is a register and it fails to be in BASE_REG_CLASS.
  451. ICOST is the cost if it fails to be in INDEX_REG_CLASS. */
  452. void
  453. record_address_regs (x, bcost, icost)
  454. rtx x;
  455. int bcost, icost;
  456. {
  457. register RTX_CODE code = GET_CODE (x);
  458. switch (code)
  459. {
  460. case CONST_INT:
  461. case CONST:
  462. case CC0:
  463. case PC:
  464. case SYMBOL_REF:
  465. case LABEL_REF:
  466. return;
  467. case PLUS:
  468. /* When we have an address that is a sum,
  469. we must determine whether registers are "base" or "index" regs.
  470. If there is a sum of two registers, we must choose one to be
  471. the "base". Luckily, we can use the REGNO_POINTER_FLAG
  472. to make a good choice most of the time. */
  473. {
  474. register RTX_CODE code0 = GET_CODE (XEXP (x, 0));
  475. register RTX_CODE code1 = GET_CODE (XEXP (x, 1));
  476. int icost0 = 0;
  477. int icost1 = 0;
  478. int suppress1 = 0;
  479. int suppress0 = 0;
  480. if (code0 == MULT || code1 == MEM)
  481. icost0 = 2;
  482. else if (code1 == MULT || code0 == MEM)
  483. icost1 = 2;
  484. else if (code0 == CONST_INT)
  485. suppress0 = 1;
  486. else if (code1 == CONST_INT)
  487. suppress1 = 1;
  488. else if (code0 == REG && code1 == REG)
  489. {
  490. if (REGNO_POINTER_FLAG (REGNO (XEXP (x, 0))))
  491. icost1 = 2;
  492. else if (REGNO_POINTER_FLAG (REGNO (XEXP (x, 1))))
  493. icost0 = 2;
  494. else
  495. icost0 = icost1 = 1;
  496. }
  497. else if (code0 == REG)
  498. {
  499. if (code1 == PLUS
  500. && ! REGNO_POINTER_FLAG (REGNO (XEXP (x, 0))))
  501. icost0 = 2;
  502. else
  503. REGNO_POINTER_FLAG (REGNO (XEXP (x, 0))) = 1;
  504. }
  505. else if (code1 == REG)
  506. {
  507. if (code0 == PLUS
  508. && ! REGNO_POINTER_FLAG (REGNO (XEXP (x, 1))))
  509. icost1 = 2;
  510. else
  511. REGNO_POINTER_FLAG (REGNO (XEXP (x, 1))) = 1;
  512. }
  513. /* ICOST0 determines whether we are treating operand 0
  514. as a base register or as an index register.
  515. SUPPRESS0 nonzero means it isn't a register at all.
  516. ICOST1 and SUPPRESS1 are likewise for operand 1. */
  517. if (! suppress0)
  518. record_address_regs (XEXP (x, 0), 2 - icost0, icost0);
  519. if (! suppress1)
  520. record_address_regs (XEXP (x, 1), 2 - icost1, icost1);
  521. }
  522. break;
  523. case POST_INC:
  524. case PRE_INC:
  525. case POST_DEC:
  526. case PRE_DEC:
  527. /* Double the importance of a pseudo register that is incremented
  528. or decremented, since it would take two extra insns
  529. if it ends up in the wrong place. */
  530. record_address_regs (XEXP (x, 0), 2 * bcost, 2 * icost);
  531. break;
  532. case REG:
  533. {
  534. register struct savings *pp;
  535. register enum reg_class class, class1;
  536. pp = &savings[REGNO (x)];
  537. /* We have an address (or part of one) that is just one register. */
  538. /* Record BCOST worth of savings for classes contained
  539. in BASE_REG_CLASS. */
  540. class = BASE_REG_CLASS;
  541. if (class != NO_REGS && class != ALL_REGS)
  542. {
  543. register int i;
  544. pp->savings[(int) class] += bcost;
  545. for (i = 0; ; i++)
  546. {
  547. class1 = reg_class_subclasses[(int)class][i];
  548. if (class1 == LIM_REG_CLASSES)
  549. break;
  550. pp->savings[(int) class1] += bcost;
  551. }
  552. }
  553. /* Record ICOST worth of savings for classes contained
  554. in INDEX_REG_CLASS. */
  555. class = INDEX_REG_CLASS;
  556. if (icost != 0 && class != NO_REGS && class != ALL_REGS)
  557. {
  558. register int i;
  559. pp->savings[(int) class] += icost;
  560. for (i = 0; ; i++)
  561. {
  562. class1 = reg_class_subclasses[(int)class][i];
  563. if (class1 == LIM_REG_CLASSES)
  564. break;
  565. pp->savings[(int) class1] += icost;
  566. }
  567. }
  568. }
  569. break;
  570. default:
  571. {
  572. register char *fmt = GET_RTX_FORMAT (code);
  573. register int i;
  574. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  575. if (fmt[i] == 'e')
  576. record_address_regs (XEXP (x, i), bcost, icost);
  577. }
  578. }
  579. }
  580. #endif /* REGISTER_CONSTRAINTS */
  581. /* This is the `regscan' pass of the compiler, run just before cse
  582. and again just before loop.
  583. It finds the first and last use of each pseudo-register
  584. and records them in the vectors regno_first_uid, regno_last_uid.
  585. REPEAT is nonzero the second time this is called. */
  586. /* Indexed by pseudo register number, gives uid of first insn using the reg
  587. (as of the time reg_scan is called). */
  588. short *regno_first_uid;
  589. /* Indexed by pseudo register number, gives uid of last insn using the reg
  590. (as of the time reg_scan is called). */
  591. short *regno_last_uid;
  592. void reg_scan_mark_refs ();
  593. void
  594. reg_scan (f, nregs, repeat)
  595. rtx f;
  596. int nregs;
  597. int repeat;
  598. {
  599. register rtx insn;
  600. if (!repeat)
  601. regno_first_uid = (short *) oballoc (nregs * sizeof (short));
  602. bzero (regno_first_uid, nregs * sizeof (short));
  603. if (!repeat)
  604. regno_last_uid = (short *) oballoc (nregs * sizeof (short));
  605. bzero (regno_last_uid, nregs * sizeof (short));
  606. for (insn = f; insn; insn = NEXT_INSN (insn))
  607. if (GET_CODE (insn) == INSN
  608. || GET_CODE (insn) == CALL_INSN
  609. || GET_CODE (insn) == JUMP_INSN)
  610. reg_scan_mark_refs (PATTERN (insn), INSN_UID (insn));
  611. }
  612. void
  613. reg_scan_mark_refs (x, uid)
  614. rtx x;
  615. int uid;
  616. {
  617. register RTX_CODE code = GET_CODE (x);
  618. switch (code)
  619. {
  620. case CONST_INT:
  621. case CONST:
  622. case CONST_DOUBLE:
  623. case CC0:
  624. case PC:
  625. case SYMBOL_REF:
  626. case LABEL_REF:
  627. return;
  628. case REG:
  629. {
  630. register int regno = REGNO (x);
  631. regno_last_uid[regno] = uid;
  632. if (regno_first_uid[regno] == 0)
  633. regno_first_uid[regno] = uid;
  634. }
  635. break;
  636. default:
  637. {
  638. register char *fmt = GET_RTX_FORMAT (code);
  639. register int i;
  640. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  641. {
  642. if (fmt[i] == 'e')
  643. reg_scan_mark_refs (XEXP (x, i), uid);
  644. else if (fmt[i] == 'E')
  645. {
  646. register int j;
  647. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  648. reg_scan_mark_refs (XVECEXP (x, i, j), uid);
  649. }
  650. }
  651. }
  652. }
  653. }