regrename.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884
  1. /* Register renaming for the GNU compiler.
  2. Copyright (C) 2000-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
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  11. License 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. #include "config.h"
  16. #include "system.h"
  17. #include "coretypes.h"
  18. #include "tm.h"
  19. #include "rtl-error.h"
  20. #include "tm_p.h"
  21. #include "insn-config.h"
  22. #include "regs.h"
  23. #include "addresses.h"
  24. #include "hard-reg-set.h"
  25. #include "predict.h"
  26. #include "vec.h"
  27. #include "hashtab.h"
  28. #include "hash-set.h"
  29. #include "machmode.h"
  30. #include "input.h"
  31. #include "function.h"
  32. #include "dominance.h"
  33. #include "cfg.h"
  34. #include "cfganal.h"
  35. #include "basic-block.h"
  36. #include "reload.h"
  37. #include "output.h"
  38. #include "recog.h"
  39. #include "flags.h"
  40. #include "obstack.h"
  41. #include "tree-pass.h"
  42. #include "df.h"
  43. #include "target.h"
  44. #include "emit-rtl.h"
  45. #include "regrename.h"
  46. /* This file implements the RTL register renaming pass of the compiler. It is
  47. a semi-local pass whose goal is to maximize the usage of the register file
  48. of the processor by substituting registers for others in the solution given
  49. by the register allocator. The algorithm is as follows:
  50. 1. Local def/use chains are built: within each basic block, chains are
  51. opened and closed; if a chain isn't closed at the end of the block,
  52. it is dropped. We pre-open chains if we have already examined a
  53. predecessor block and found chains live at the end which match
  54. live registers at the start of the new block.
  55. 2. We try to combine the local chains across basic block boundaries by
  56. comparing chains that were open at the start or end of a block to
  57. those in successor/predecessor blocks.
  58. 3. For each chain, the set of possible renaming registers is computed.
  59. This takes into account the renaming of previously processed chains.
  60. Optionally, a preferred class is computed for the renaming register.
  61. 4. The best renaming register is computed for the chain in the above set,
  62. using a round-robin allocation. If a preferred class exists, then the
  63. round-robin allocation is done within the class first, if possible.
  64. The round-robin allocation of renaming registers itself is global.
  65. 5. If a renaming register has been found, it is substituted in the chain.
  66. Targets can parameterize the pass by specifying a preferred class for the
  67. renaming register for a given (super)class of registers to be renamed. */
  68. #if HOST_BITS_PER_WIDE_INT <= MAX_RECOG_OPERANDS
  69. #error "Use a different bitmap implementation for untracked_operands."
  70. #endif
  71. enum scan_actions
  72. {
  73. terminate_write,
  74. terminate_dead,
  75. mark_all_read,
  76. mark_read,
  77. mark_write,
  78. /* mark_access is for marking the destination regs in
  79. REG_FRAME_RELATED_EXPR notes (as if they were read) so that the
  80. note is updated properly. */
  81. mark_access
  82. };
  83. static const char * const scan_actions_name[] =
  84. {
  85. "terminate_write",
  86. "terminate_dead",
  87. "mark_all_read",
  88. "mark_read",
  89. "mark_write",
  90. "mark_access"
  91. };
  92. /* TICK and THIS_TICK are used to record the last time we saw each
  93. register. */
  94. static int tick[FIRST_PSEUDO_REGISTER];
  95. static int this_tick = 0;
  96. static struct obstack rename_obstack;
  97. /* If nonnull, the code calling into the register renamer requested
  98. information about insn operands, and we store it here. */
  99. vec<insn_rr_info> insn_rr;
  100. static void scan_rtx (rtx_insn *, rtx *, enum reg_class, enum scan_actions,
  101. enum op_type);
  102. static bool build_def_use (basic_block);
  103. /* The id to be given to the next opened chain. */
  104. static unsigned current_id;
  105. /* A mapping of unique id numbers to chains. */
  106. static vec<du_head_p> id_to_chain;
  107. /* List of currently open chains. */
  108. static struct du_head *open_chains;
  109. /* Bitmap of open chains. The bits set always match the list found in
  110. open_chains. */
  111. static bitmap_head open_chains_set;
  112. /* Record the registers being tracked in open_chains. */
  113. static HARD_REG_SET live_in_chains;
  114. /* Record the registers that are live but not tracked. The intersection
  115. between this and live_in_chains is empty. */
  116. static HARD_REG_SET live_hard_regs;
  117. /* Set while scanning RTL if INSN_RR is nonnull, i.e. if the current analysis
  118. is for a caller that requires operand data. Used in
  119. record_operand_use. */
  120. static operand_rr_info *cur_operand;
  121. /* Return the chain corresponding to id number ID. Take into account that
  122. chains may have been merged. */
  123. du_head_p
  124. regrename_chain_from_id (unsigned int id)
  125. {
  126. du_head_p first_chain = id_to_chain[id];
  127. du_head_p chain = first_chain;
  128. while (chain->id != id)
  129. {
  130. id = chain->id;
  131. chain = id_to_chain[id];
  132. }
  133. first_chain->id = id;
  134. return chain;
  135. }
  136. /* Dump all def/use chains, starting at id FROM. */
  137. static void
  138. dump_def_use_chain (int from)
  139. {
  140. du_head_p head;
  141. int i;
  142. FOR_EACH_VEC_ELT_FROM (id_to_chain, i, head, from)
  143. {
  144. struct du_chain *this_du = head->first;
  145. fprintf (dump_file, "Register %s (%d):",
  146. reg_names[head->regno], head->nregs);
  147. while (this_du)
  148. {
  149. fprintf (dump_file, " %d [%s]", INSN_UID (this_du->insn),
  150. reg_class_names[this_du->cl]);
  151. this_du = this_du->next_use;
  152. }
  153. fprintf (dump_file, "\n");
  154. head = head->next_chain;
  155. }
  156. }
  157. static void
  158. free_chain_data (void)
  159. {
  160. int i;
  161. du_head_p ptr;
  162. for (i = 0; id_to_chain.iterate (i, &ptr); i++)
  163. bitmap_clear (&ptr->conflicts);
  164. id_to_chain.release ();
  165. }
  166. /* Walk all chains starting with CHAINS and record that they conflict with
  167. another chain whose id is ID. */
  168. static void
  169. mark_conflict (struct du_head *chains, unsigned id)
  170. {
  171. while (chains)
  172. {
  173. bitmap_set_bit (&chains->conflicts, id);
  174. chains = chains->next_chain;
  175. }
  176. }
  177. /* Examine cur_operand, and if it is nonnull, record information about the
  178. use THIS_DU which is part of the chain HEAD. */
  179. static void
  180. record_operand_use (struct du_head *head, struct du_chain *this_du)
  181. {
  182. if (cur_operand == NULL)
  183. return;
  184. gcc_assert (cur_operand->n_chains < MAX_REGS_PER_ADDRESS);
  185. cur_operand->heads[cur_operand->n_chains] = head;
  186. cur_operand->chains[cur_operand->n_chains++] = this_du;
  187. }
  188. /* Create a new chain for THIS_NREGS registers starting at THIS_REGNO,
  189. and record its occurrence in *LOC, which is being written to in INSN.
  190. This access requires a register of class CL. */
  191. static du_head_p
  192. create_new_chain (unsigned this_regno, unsigned this_nregs, rtx *loc,
  193. rtx_insn *insn, enum reg_class cl)
  194. {
  195. struct du_head *head = XOBNEW (&rename_obstack, struct du_head);
  196. struct du_chain *this_du;
  197. int nregs;
  198. head->next_chain = open_chains;
  199. head->regno = this_regno;
  200. head->nregs = this_nregs;
  201. head->need_caller_save_reg = 0;
  202. head->cannot_rename = 0;
  203. id_to_chain.safe_push (head);
  204. head->id = current_id++;
  205. bitmap_initialize (&head->conflicts, &bitmap_default_obstack);
  206. bitmap_copy (&head->conflicts, &open_chains_set);
  207. mark_conflict (open_chains, head->id);
  208. /* Since we're tracking this as a chain now, remove it from the
  209. list of conflicting live hard registers and track it in
  210. live_in_chains instead. */
  211. nregs = head->nregs;
  212. while (nregs-- > 0)
  213. {
  214. SET_HARD_REG_BIT (live_in_chains, head->regno + nregs);
  215. CLEAR_HARD_REG_BIT (live_hard_regs, head->regno + nregs);
  216. }
  217. COPY_HARD_REG_SET (head->hard_conflicts, live_hard_regs);
  218. bitmap_set_bit (&open_chains_set, head->id);
  219. open_chains = head;
  220. if (dump_file)
  221. {
  222. fprintf (dump_file, "Creating chain %s (%d)",
  223. reg_names[head->regno], head->id);
  224. if (insn != NULL_RTX)
  225. fprintf (dump_file, " at insn %d", INSN_UID (insn));
  226. fprintf (dump_file, "\n");
  227. }
  228. if (insn == NULL_RTX)
  229. {
  230. head->first = head->last = NULL;
  231. return head;
  232. }
  233. this_du = XOBNEW (&rename_obstack, struct du_chain);
  234. head->first = head->last = this_du;
  235. this_du->next_use = 0;
  236. this_du->loc = loc;
  237. this_du->insn = insn;
  238. this_du->cl = cl;
  239. record_operand_use (head, this_du);
  240. return head;
  241. }
  242. /* For a def-use chain HEAD, find which registers overlap its lifetime and
  243. set the corresponding bits in *PSET. */
  244. static void
  245. merge_overlapping_regs (HARD_REG_SET *pset, struct du_head *head)
  246. {
  247. bitmap_iterator bi;
  248. unsigned i;
  249. IOR_HARD_REG_SET (*pset, head->hard_conflicts);
  250. EXECUTE_IF_SET_IN_BITMAP (&head->conflicts, 0, i, bi)
  251. {
  252. du_head_p other = regrename_chain_from_id (i);
  253. unsigned j = other->nregs;
  254. gcc_assert (other != head);
  255. while (j-- > 0)
  256. SET_HARD_REG_BIT (*pset, other->regno + j);
  257. }
  258. }
  259. /* Check if NEW_REG can be the candidate register to rename for
  260. REG in THIS_HEAD chain. THIS_UNAVAILABLE is a set of unavailable hard
  261. registers. */
  262. static bool
  263. check_new_reg_p (int reg ATTRIBUTE_UNUSED, int new_reg,
  264. struct du_head *this_head, HARD_REG_SET this_unavailable)
  265. {
  266. machine_mode mode = GET_MODE (*this_head->first->loc);
  267. int nregs = hard_regno_nregs[new_reg][mode];
  268. int i;
  269. struct du_chain *tmp;
  270. for (i = nregs - 1; i >= 0; --i)
  271. if (TEST_HARD_REG_BIT (this_unavailable, new_reg + i)
  272. || fixed_regs[new_reg + i]
  273. || global_regs[new_reg + i]
  274. /* Can't use regs which aren't saved by the prologue. */
  275. || (! df_regs_ever_live_p (new_reg + i)
  276. && ! call_used_regs[new_reg + i])
  277. #ifdef LEAF_REGISTERS
  278. /* We can't use a non-leaf register if we're in a
  279. leaf function. */
  280. || (crtl->is_leaf
  281. && !LEAF_REGISTERS[new_reg + i])
  282. #endif
  283. #ifdef HARD_REGNO_RENAME_OK
  284. || ! HARD_REGNO_RENAME_OK (reg + i, new_reg + i)
  285. #endif
  286. )
  287. return false;
  288. /* See whether it accepts all modes that occur in
  289. definition and uses. */
  290. for (tmp = this_head->first; tmp; tmp = tmp->next_use)
  291. if ((! HARD_REGNO_MODE_OK (new_reg, GET_MODE (*tmp->loc))
  292. && ! DEBUG_INSN_P (tmp->insn))
  293. || (this_head->need_caller_save_reg
  294. && ! (HARD_REGNO_CALL_PART_CLOBBERED
  295. (reg, GET_MODE (*tmp->loc)))
  296. && (HARD_REGNO_CALL_PART_CLOBBERED
  297. (new_reg, GET_MODE (*tmp->loc)))))
  298. return false;
  299. return true;
  300. }
  301. /* For the chain THIS_HEAD, compute and return the best register to
  302. rename to. SUPER_CLASS is the superunion of register classes in
  303. the chain. UNAVAILABLE is a set of registers that cannot be used.
  304. OLD_REG is the register currently used for the chain. BEST_RENAME
  305. controls whether the register chosen must be better than the
  306. current one or just respect the given constraint. */
  307. int
  308. find_rename_reg (du_head_p this_head, enum reg_class super_class,
  309. HARD_REG_SET *unavailable, int old_reg, bool best_rename)
  310. {
  311. bool has_preferred_class;
  312. enum reg_class preferred_class;
  313. int pass;
  314. int best_new_reg = old_reg;
  315. /* Further narrow the set of registers we can use for renaming.
  316. If the chain needs a call-saved register, mark the call-used
  317. registers as unavailable. */
  318. if (this_head->need_caller_save_reg)
  319. IOR_HARD_REG_SET (*unavailable, call_used_reg_set);
  320. /* Mark registers that overlap this chain's lifetime as unavailable. */
  321. merge_overlapping_regs (unavailable, this_head);
  322. /* Compute preferred rename class of super union of all the classes
  323. in the chain. */
  324. preferred_class
  325. = (enum reg_class) targetm.preferred_rename_class (super_class);
  326. /* If PREFERRED_CLASS is not NO_REGS, we iterate in the first pass
  327. over registers that belong to PREFERRED_CLASS and try to find the
  328. best register within the class. If that failed, we iterate in
  329. the second pass over registers that don't belong to the class.
  330. If PREFERRED_CLASS is NO_REGS, we iterate over all registers in
  331. ascending order without any preference. */
  332. has_preferred_class = (preferred_class != NO_REGS);
  333. for (pass = (has_preferred_class ? 0 : 1); pass < 2; pass++)
  334. {
  335. int new_reg;
  336. for (new_reg = 0; new_reg < FIRST_PSEUDO_REGISTER; new_reg++)
  337. {
  338. if (has_preferred_class
  339. && (pass == 0)
  340. != TEST_HARD_REG_BIT (reg_class_contents[preferred_class],
  341. new_reg))
  342. continue;
  343. if (!check_new_reg_p (old_reg, new_reg, this_head, *unavailable))
  344. continue;
  345. if (!best_rename)
  346. return new_reg;
  347. /* In the first pass, we force the renaming of registers that
  348. don't belong to PREFERRED_CLASS to registers that do, even
  349. though the latters were used not very long ago. */
  350. if ((pass == 0
  351. && !TEST_HARD_REG_BIT (reg_class_contents[preferred_class],
  352. best_new_reg))
  353. || tick[best_new_reg] > tick[new_reg])
  354. best_new_reg = new_reg;
  355. }
  356. if (pass == 0 && best_new_reg != old_reg)
  357. break;
  358. }
  359. return best_new_reg;
  360. }
  361. /* Perform register renaming on the current function. */
  362. static void
  363. rename_chains (void)
  364. {
  365. HARD_REG_SET unavailable;
  366. du_head_p this_head;
  367. int i;
  368. memset (tick, 0, sizeof tick);
  369. CLEAR_HARD_REG_SET (unavailable);
  370. /* Don't clobber traceback for noreturn functions. */
  371. if (frame_pointer_needed)
  372. {
  373. add_to_hard_reg_set (&unavailable, Pmode, FRAME_POINTER_REGNUM);
  374. #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
  375. add_to_hard_reg_set (&unavailable, Pmode, HARD_FRAME_POINTER_REGNUM);
  376. #endif
  377. }
  378. FOR_EACH_VEC_ELT (id_to_chain, i, this_head)
  379. {
  380. int best_new_reg;
  381. int n_uses;
  382. struct du_chain *tmp;
  383. HARD_REG_SET this_unavailable;
  384. int reg = this_head->regno;
  385. enum reg_class super_class = NO_REGS;
  386. if (this_head->cannot_rename)
  387. continue;
  388. if (fixed_regs[reg] || global_regs[reg]
  389. #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
  390. || (frame_pointer_needed && reg == HARD_FRAME_POINTER_REGNUM)
  391. #else
  392. || (frame_pointer_needed && reg == FRAME_POINTER_REGNUM)
  393. #endif
  394. )
  395. continue;
  396. COPY_HARD_REG_SET (this_unavailable, unavailable);
  397. /* Iterate over elements in the chain in order to:
  398. 1. Count number of uses, and narrow the set of registers we can
  399. use for renaming.
  400. 2. Compute the superunion of register classes in this chain. */
  401. n_uses = 0;
  402. super_class = NO_REGS;
  403. for (tmp = this_head->first; tmp; tmp = tmp->next_use)
  404. {
  405. if (DEBUG_INSN_P (tmp->insn))
  406. continue;
  407. n_uses++;
  408. IOR_COMPL_HARD_REG_SET (this_unavailable,
  409. reg_class_contents[tmp->cl]);
  410. super_class
  411. = reg_class_superunion[(int) super_class][(int) tmp->cl];
  412. }
  413. if (n_uses < 2)
  414. continue;
  415. best_new_reg = find_rename_reg (this_head, super_class,
  416. &this_unavailable, reg, true);
  417. if (dump_file)
  418. {
  419. fprintf (dump_file, "Register %s in insn %d",
  420. reg_names[reg], INSN_UID (this_head->first->insn));
  421. if (this_head->need_caller_save_reg)
  422. fprintf (dump_file, " crosses a call");
  423. }
  424. if (best_new_reg == reg)
  425. {
  426. tick[reg] = ++this_tick;
  427. if (dump_file)
  428. fprintf (dump_file, "; no available better choice\n");
  429. continue;
  430. }
  431. if (dump_file)
  432. fprintf (dump_file, ", renamed as %s\n", reg_names[best_new_reg]);
  433. regrename_do_replace (this_head, best_new_reg);
  434. tick[best_new_reg] = ++this_tick;
  435. df_set_regs_ever_live (best_new_reg, true);
  436. }
  437. }
  438. /* A structure to record information for each hard register at the start of
  439. a basic block. */
  440. struct incoming_reg_info {
  441. /* Holds the number of registers used in the chain that gave us information
  442. about this register. Zero means no information known yet, while a
  443. negative value is used for something that is part of, but not the first
  444. register in a multi-register value. */
  445. int nregs;
  446. /* Set to true if we have accesses that conflict in the number of registers
  447. used. */
  448. bool unusable;
  449. };
  450. /* A structure recording information about each basic block. It is saved
  451. and restored around basic block boundaries.
  452. A pointer to such a structure is stored in each basic block's aux field
  453. during regrename_analyze, except for blocks we know can't be optimized
  454. (such as entry and exit blocks). */
  455. struct bb_rename_info
  456. {
  457. /* The basic block corresponding to this structure. */
  458. basic_block bb;
  459. /* Copies of the global information. */
  460. bitmap_head open_chains_set;
  461. bitmap_head incoming_open_chains_set;
  462. struct incoming_reg_info incoming[FIRST_PSEUDO_REGISTER];
  463. };
  464. /* Initialize a rename_info structure P for basic block BB, which starts a new
  465. scan. */
  466. static void
  467. init_rename_info (struct bb_rename_info *p, basic_block bb)
  468. {
  469. int i;
  470. df_ref def;
  471. HARD_REG_SET start_chains_set;
  472. p->bb = bb;
  473. bitmap_initialize (&p->open_chains_set, &bitmap_default_obstack);
  474. bitmap_initialize (&p->incoming_open_chains_set, &bitmap_default_obstack);
  475. open_chains = NULL;
  476. bitmap_clear (&open_chains_set);
  477. CLEAR_HARD_REG_SET (live_in_chains);
  478. REG_SET_TO_HARD_REG_SET (live_hard_regs, df_get_live_in (bb));
  479. FOR_EACH_ARTIFICIAL_DEF (def, bb->index)
  480. if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
  481. SET_HARD_REG_BIT (live_hard_regs, DF_REF_REGNO (def));
  482. /* Open chains based on information from (at least one) predecessor
  483. block. This gives us a chance later on to combine chains across
  484. basic block boundaries. Inconsistencies (in access sizes) will
  485. be caught normally and dealt with conservatively by disabling the
  486. chain for renaming, and there is no risk of losing optimization
  487. opportunities by opening chains either: if we did not open the
  488. chains, we'd have to track the live register as a hard reg, and
  489. we'd be unable to rename it in any case. */
  490. CLEAR_HARD_REG_SET (start_chains_set);
  491. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  492. {
  493. struct incoming_reg_info *iri = p->incoming + i;
  494. if (iri->nregs > 0 && !iri->unusable
  495. && range_in_hard_reg_set_p (live_hard_regs, i, iri->nregs))
  496. {
  497. SET_HARD_REG_BIT (start_chains_set, i);
  498. remove_range_from_hard_reg_set (&live_hard_regs, i, iri->nregs);
  499. }
  500. }
  501. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  502. {
  503. struct incoming_reg_info *iri = p->incoming + i;
  504. if (TEST_HARD_REG_BIT (start_chains_set, i))
  505. {
  506. du_head_p chain;
  507. if (dump_file)
  508. fprintf (dump_file, "opening incoming chain\n");
  509. chain = create_new_chain (i, iri->nregs, NULL, NULL, NO_REGS);
  510. bitmap_set_bit (&p->incoming_open_chains_set, chain->id);
  511. }
  512. }
  513. }
  514. /* Record in RI that the block corresponding to it has an incoming
  515. live value, described by CHAIN. */
  516. static void
  517. set_incoming_from_chain (struct bb_rename_info *ri, du_head_p chain)
  518. {
  519. int i;
  520. int incoming_nregs = ri->incoming[chain->regno].nregs;
  521. int nregs;
  522. /* If we've recorded the same information before, everything is fine. */
  523. if (incoming_nregs == chain->nregs)
  524. {
  525. if (dump_file)
  526. fprintf (dump_file, "reg %d/%d already recorded\n",
  527. chain->regno, chain->nregs);
  528. return;
  529. }
  530. /* If we have no information for any of the involved registers, update
  531. the incoming array. */
  532. nregs = chain->nregs;
  533. while (nregs-- > 0)
  534. if (ri->incoming[chain->regno + nregs].nregs != 0
  535. || ri->incoming[chain->regno + nregs].unusable)
  536. break;
  537. if (nregs < 0)
  538. {
  539. nregs = chain->nregs;
  540. ri->incoming[chain->regno].nregs = nregs;
  541. while (nregs-- > 1)
  542. ri->incoming[chain->regno + nregs].nregs = -nregs;
  543. if (dump_file)
  544. fprintf (dump_file, "recorded reg %d/%d\n",
  545. chain->regno, chain->nregs);
  546. return;
  547. }
  548. /* There must be some kind of conflict. Prevent both the old and
  549. new ranges from being used. */
  550. if (incoming_nregs < 0)
  551. ri->incoming[chain->regno + incoming_nregs].unusable = true;
  552. for (i = 0; i < chain->nregs; i++)
  553. ri->incoming[chain->regno + i].unusable = true;
  554. }
  555. /* Merge the two chains C1 and C2 so that all conflict information is
  556. recorded and C1, and the id of C2 is changed to that of C1. */
  557. static void
  558. merge_chains (du_head_p c1, du_head_p c2)
  559. {
  560. if (c1 == c2)
  561. return;
  562. if (c2->first != NULL)
  563. {
  564. if (c1->first == NULL)
  565. c1->first = c2->first;
  566. else
  567. c1->last->next_use = c2->first;
  568. c1->last = c2->last;
  569. }
  570. c2->first = c2->last = NULL;
  571. c2->id = c1->id;
  572. IOR_HARD_REG_SET (c1->hard_conflicts, c2->hard_conflicts);
  573. bitmap_ior_into (&c1->conflicts, &c2->conflicts);
  574. c1->need_caller_save_reg |= c2->need_caller_save_reg;
  575. c1->cannot_rename |= c2->cannot_rename;
  576. }
  577. /* Analyze the current function and build chains for renaming. */
  578. void
  579. regrename_analyze (bitmap bb_mask)
  580. {
  581. struct bb_rename_info *rename_info;
  582. int i;
  583. basic_block bb;
  584. int n_bbs;
  585. int *inverse_postorder;
  586. inverse_postorder = XNEWVEC (int, last_basic_block_for_fn (cfun));
  587. n_bbs = pre_and_rev_post_order_compute (NULL, inverse_postorder, false);
  588. /* Gather some information about the blocks in this function. */
  589. rename_info = XCNEWVEC (struct bb_rename_info, n_basic_blocks_for_fn (cfun));
  590. i = 0;
  591. FOR_EACH_BB_FN (bb, cfun)
  592. {
  593. struct bb_rename_info *ri = rename_info + i;
  594. ri->bb = bb;
  595. if (bb_mask != NULL && !bitmap_bit_p (bb_mask, bb->index))
  596. bb->aux = NULL;
  597. else
  598. bb->aux = ri;
  599. i++;
  600. }
  601. current_id = 0;
  602. id_to_chain.create (0);
  603. bitmap_initialize (&open_chains_set, &bitmap_default_obstack);
  604. /* The order in which we visit blocks ensures that whenever
  605. possible, we only process a block after at least one of its
  606. predecessors, which provides a "seeding" effect to make the logic
  607. in set_incoming_from_chain and init_rename_info useful. */
  608. for (i = 0; i < n_bbs; i++)
  609. {
  610. basic_block bb1 = BASIC_BLOCK_FOR_FN (cfun, inverse_postorder[i]);
  611. struct bb_rename_info *this_info;
  612. bool success;
  613. edge e;
  614. edge_iterator ei;
  615. int old_length = id_to_chain.length ();
  616. this_info = (struct bb_rename_info *) bb1->aux;
  617. if (this_info == NULL)
  618. continue;
  619. if (dump_file)
  620. fprintf (dump_file, "\nprocessing block %d:\n", bb1->index);
  621. init_rename_info (this_info, bb1);
  622. success = build_def_use (bb1);
  623. if (!success)
  624. {
  625. if (dump_file)
  626. fprintf (dump_file, "failed\n");
  627. bb1->aux = NULL;
  628. id_to_chain.truncate (old_length);
  629. current_id = old_length;
  630. bitmap_clear (&this_info->incoming_open_chains_set);
  631. open_chains = NULL;
  632. if (insn_rr.exists ())
  633. {
  634. rtx_insn *insn;
  635. FOR_BB_INSNS (bb1, insn)
  636. {
  637. insn_rr_info *p = &insn_rr[INSN_UID (insn)];
  638. p->op_info = NULL;
  639. }
  640. }
  641. continue;
  642. }
  643. if (dump_file)
  644. dump_def_use_chain (old_length);
  645. bitmap_copy (&this_info->open_chains_set, &open_chains_set);
  646. /* Add successor blocks to the worklist if necessary, and record
  647. data about our own open chains at the end of this block, which
  648. will be used to pre-open chains when processing the successors. */
  649. FOR_EACH_EDGE (e, ei, bb1->succs)
  650. {
  651. struct bb_rename_info *dest_ri;
  652. struct du_head *chain;
  653. if (dump_file)
  654. fprintf (dump_file, "successor block %d\n", e->dest->index);
  655. if (e->flags & (EDGE_EH | EDGE_ABNORMAL))
  656. continue;
  657. dest_ri = (struct bb_rename_info *)e->dest->aux;
  658. if (dest_ri == NULL)
  659. continue;
  660. for (chain = open_chains; chain; chain = chain->next_chain)
  661. set_incoming_from_chain (dest_ri, chain);
  662. }
  663. }
  664. free (inverse_postorder);
  665. /* Now, combine the chains data we have gathered across basic block
  666. boundaries.
  667. For every basic block, there may be chains open at the start, or at the
  668. end. Rather than exclude them from renaming, we look for open chains
  669. with matching registers at the other side of the CFG edge.
  670. For a given chain using register R, open at the start of block B, we
  671. must find an open chain using R on the other side of every edge leading
  672. to B, if the register is live across this edge. In the code below,
  673. N_PREDS_USED counts the number of edges where the register is live, and
  674. N_PREDS_JOINED counts those where we found an appropriate chain for
  675. joining.
  676. We perform the analysis for both incoming and outgoing edges, but we
  677. only need to merge once (in the second part, after verifying outgoing
  678. edges). */
  679. FOR_EACH_BB_FN (bb, cfun)
  680. {
  681. struct bb_rename_info *bb_ri = (struct bb_rename_info *) bb->aux;
  682. unsigned j;
  683. bitmap_iterator bi;
  684. if (bb_ri == NULL)
  685. continue;
  686. if (dump_file)
  687. fprintf (dump_file, "processing bb %d in edges\n", bb->index);
  688. EXECUTE_IF_SET_IN_BITMAP (&bb_ri->incoming_open_chains_set, 0, j, bi)
  689. {
  690. edge e;
  691. edge_iterator ei;
  692. struct du_head *chain = regrename_chain_from_id (j);
  693. int n_preds_used = 0, n_preds_joined = 0;
  694. FOR_EACH_EDGE (e, ei, bb->preds)
  695. {
  696. struct bb_rename_info *src_ri;
  697. unsigned k;
  698. bitmap_iterator bi2;
  699. HARD_REG_SET live;
  700. bool success = false;
  701. REG_SET_TO_HARD_REG_SET (live, df_get_live_out (e->src));
  702. if (!range_overlaps_hard_reg_set_p (live, chain->regno,
  703. chain->nregs))
  704. continue;
  705. n_preds_used++;
  706. if (e->flags & (EDGE_EH | EDGE_ABNORMAL))
  707. continue;
  708. src_ri = (struct bb_rename_info *)e->src->aux;
  709. if (src_ri == NULL)
  710. continue;
  711. EXECUTE_IF_SET_IN_BITMAP (&src_ri->open_chains_set,
  712. 0, k, bi2)
  713. {
  714. struct du_head *outgoing_chain = regrename_chain_from_id (k);
  715. if (outgoing_chain->regno == chain->regno
  716. && outgoing_chain->nregs == chain->nregs)
  717. {
  718. n_preds_joined++;
  719. success = true;
  720. break;
  721. }
  722. }
  723. if (!success && dump_file)
  724. fprintf (dump_file, "failure to match with pred block %d\n",
  725. e->src->index);
  726. }
  727. if (n_preds_joined < n_preds_used)
  728. {
  729. if (dump_file)
  730. fprintf (dump_file, "cannot rename chain %d\n", j);
  731. chain->cannot_rename = 1;
  732. }
  733. }
  734. }
  735. FOR_EACH_BB_FN (bb, cfun)
  736. {
  737. struct bb_rename_info *bb_ri = (struct bb_rename_info *) bb->aux;
  738. unsigned j;
  739. bitmap_iterator bi;
  740. if (bb_ri == NULL)
  741. continue;
  742. if (dump_file)
  743. fprintf (dump_file, "processing bb %d out edges\n", bb->index);
  744. EXECUTE_IF_SET_IN_BITMAP (&bb_ri->open_chains_set, 0, j, bi)
  745. {
  746. edge e;
  747. edge_iterator ei;
  748. struct du_head *chain = regrename_chain_from_id (j);
  749. int n_succs_used = 0, n_succs_joined = 0;
  750. FOR_EACH_EDGE (e, ei, bb->succs)
  751. {
  752. bool printed = false;
  753. struct bb_rename_info *dest_ri;
  754. unsigned k;
  755. bitmap_iterator bi2;
  756. HARD_REG_SET live;
  757. REG_SET_TO_HARD_REG_SET (live, df_get_live_in (e->dest));
  758. if (!range_overlaps_hard_reg_set_p (live, chain->regno,
  759. chain->nregs))
  760. continue;
  761. n_succs_used++;
  762. dest_ri = (struct bb_rename_info *)e->dest->aux;
  763. if (dest_ri == NULL)
  764. continue;
  765. EXECUTE_IF_SET_IN_BITMAP (&dest_ri->incoming_open_chains_set,
  766. 0, k, bi2)
  767. {
  768. struct du_head *incoming_chain = regrename_chain_from_id (k);
  769. if (incoming_chain->regno == chain->regno
  770. && incoming_chain->nregs == chain->nregs)
  771. {
  772. if (dump_file)
  773. {
  774. if (!printed)
  775. fprintf (dump_file,
  776. "merging blocks for edge %d -> %d\n",
  777. e->src->index, e->dest->index);
  778. printed = true;
  779. fprintf (dump_file,
  780. " merging chains %d (->%d) and %d (->%d) [%s]\n",
  781. k, incoming_chain->id, j, chain->id,
  782. reg_names[incoming_chain->regno]);
  783. }
  784. merge_chains (chain, incoming_chain);
  785. n_succs_joined++;
  786. break;
  787. }
  788. }
  789. }
  790. if (n_succs_joined < n_succs_used)
  791. {
  792. if (dump_file)
  793. fprintf (dump_file, "cannot rename chain %d\n",
  794. j);
  795. chain->cannot_rename = 1;
  796. }
  797. }
  798. }
  799. free (rename_info);
  800. FOR_EACH_BB_FN (bb, cfun)
  801. bb->aux = NULL;
  802. }
  803. void
  804. regrename_do_replace (struct du_head *head, int reg)
  805. {
  806. struct du_chain *chain;
  807. unsigned int base_regno = head->regno;
  808. machine_mode mode;
  809. for (chain = head->first; chain; chain = chain->next_use)
  810. {
  811. unsigned int regno = ORIGINAL_REGNO (*chain->loc);
  812. struct reg_attrs *attr = REG_ATTRS (*chain->loc);
  813. int reg_ptr = REG_POINTER (*chain->loc);
  814. if (DEBUG_INSN_P (chain->insn) && REGNO (*chain->loc) != base_regno)
  815. INSN_VAR_LOCATION_LOC (chain->insn) = gen_rtx_UNKNOWN_VAR_LOC ();
  816. else
  817. {
  818. *chain->loc = gen_raw_REG (GET_MODE (*chain->loc), reg);
  819. if (regno >= FIRST_PSEUDO_REGISTER)
  820. ORIGINAL_REGNO (*chain->loc) = regno;
  821. REG_ATTRS (*chain->loc) = attr;
  822. REG_POINTER (*chain->loc) = reg_ptr;
  823. }
  824. df_insn_rescan (chain->insn);
  825. }
  826. mode = GET_MODE (*head->first->loc);
  827. head->regno = reg;
  828. head->nregs = hard_regno_nregs[reg][mode];
  829. }
  830. /* True if we found a register with a size mismatch, which means that we
  831. can't track its lifetime accurately. If so, we abort the current block
  832. without renaming. */
  833. static bool fail_current_block;
  834. /* Return true if OP is a reg for which all bits are set in PSET, false
  835. if all bits are clear.
  836. In other cases, set fail_current_block and return false. */
  837. static bool
  838. verify_reg_in_set (rtx op, HARD_REG_SET *pset)
  839. {
  840. unsigned regno, nregs;
  841. bool all_live, all_dead;
  842. if (!REG_P (op))
  843. return false;
  844. regno = REGNO (op);
  845. nregs = hard_regno_nregs[regno][GET_MODE (op)];
  846. all_live = all_dead = true;
  847. while (nregs-- > 0)
  848. if (TEST_HARD_REG_BIT (*pset, regno + nregs))
  849. all_dead = false;
  850. else
  851. all_live = false;
  852. if (!all_dead && !all_live)
  853. {
  854. fail_current_block = true;
  855. return false;
  856. }
  857. return all_live;
  858. }
  859. /* Return true if OP is a reg that is being tracked already in some form.
  860. May set fail_current_block if it sees an unhandled case of overlap. */
  861. static bool
  862. verify_reg_tracked (rtx op)
  863. {
  864. return (verify_reg_in_set (op, &live_hard_regs)
  865. || verify_reg_in_set (op, &live_in_chains));
  866. }
  867. /* Called through note_stores. DATA points to a rtx_code, either SET or
  868. CLOBBER, which tells us which kind of rtx to look at. If we have a
  869. match, record the set register in live_hard_regs and in the hard_conflicts
  870. bitmap of open chains. */
  871. static void
  872. note_sets_clobbers (rtx x, const_rtx set, void *data)
  873. {
  874. enum rtx_code code = *(enum rtx_code *)data;
  875. struct du_head *chain;
  876. if (GET_CODE (x) == SUBREG)
  877. x = SUBREG_REG (x);
  878. if (!REG_P (x) || GET_CODE (set) != code)
  879. return;
  880. /* There must not be pseudos at this point. */
  881. gcc_assert (HARD_REGISTER_P (x));
  882. add_to_hard_reg_set (&live_hard_regs, GET_MODE (x), REGNO (x));
  883. for (chain = open_chains; chain; chain = chain->next_chain)
  884. add_to_hard_reg_set (&chain->hard_conflicts, GET_MODE (x), REGNO (x));
  885. }
  886. static void
  887. scan_rtx_reg (rtx_insn *insn, rtx *loc, enum reg_class cl, enum scan_actions action,
  888. enum op_type type)
  889. {
  890. struct du_head **p;
  891. rtx x = *loc;
  892. machine_mode mode = GET_MODE (x);
  893. unsigned this_regno = REGNO (x);
  894. int this_nregs = hard_regno_nregs[this_regno][mode];
  895. if (action == mark_write)
  896. {
  897. if (type == OP_OUT)
  898. create_new_chain (this_regno, this_nregs, loc, insn, cl);
  899. return;
  900. }
  901. if ((type == OP_OUT) != (action == terminate_write || action == mark_access))
  902. return;
  903. for (p = &open_chains; *p;)
  904. {
  905. struct du_head *head = *p;
  906. struct du_head *next = head->next_chain;
  907. int exact_match = (head->regno == this_regno
  908. && head->nregs == this_nregs);
  909. int superset = (this_regno <= head->regno
  910. && this_regno + this_nregs >= head->regno + head->nregs);
  911. int subset = (this_regno >= head->regno
  912. && this_regno + this_nregs <= head->regno + head->nregs);
  913. if (!bitmap_bit_p (&open_chains_set, head->id)
  914. || head->regno + head->nregs <= this_regno
  915. || this_regno + this_nregs <= head->regno)
  916. {
  917. p = &head->next_chain;
  918. continue;
  919. }
  920. if (action == mark_read || action == mark_access)
  921. {
  922. /* ??? Class NO_REGS can happen if the md file makes use of
  923. EXTRA_CONSTRAINTS to match registers. Which is arguably
  924. wrong, but there we are. */
  925. if (cl == NO_REGS || (!exact_match && !DEBUG_INSN_P (insn)))
  926. {
  927. if (dump_file)
  928. fprintf (dump_file,
  929. "Cannot rename chain %s (%d) at insn %d (%s)\n",
  930. reg_names[head->regno], head->id, INSN_UID (insn),
  931. scan_actions_name[(int) action]);
  932. head->cannot_rename = 1;
  933. if (superset)
  934. {
  935. unsigned nregs = this_nregs;
  936. head->regno = this_regno;
  937. head->nregs = this_nregs;
  938. while (nregs-- > 0)
  939. SET_HARD_REG_BIT (live_in_chains, head->regno + nregs);
  940. if (dump_file)
  941. fprintf (dump_file,
  942. "Widening register in chain %s (%d) at insn %d\n",
  943. reg_names[head->regno], head->id, INSN_UID (insn));
  944. }
  945. else if (!subset)
  946. {
  947. fail_current_block = true;
  948. if (dump_file)
  949. fprintf (dump_file,
  950. "Failing basic block due to unhandled overlap\n");
  951. }
  952. }
  953. else
  954. {
  955. struct du_chain *this_du;
  956. this_du = XOBNEW (&rename_obstack, struct du_chain);
  957. this_du->next_use = 0;
  958. this_du->loc = loc;
  959. this_du->insn = insn;
  960. this_du->cl = cl;
  961. if (head->first == NULL)
  962. head->first = this_du;
  963. else
  964. head->last->next_use = this_du;
  965. record_operand_use (head, this_du);
  966. head->last = this_du;
  967. }
  968. /* Avoid adding the same location in a DEBUG_INSN multiple times,
  969. which could happen with non-exact overlap. */
  970. if (DEBUG_INSN_P (insn))
  971. return;
  972. /* Otherwise, find any other chains that do not match exactly;
  973. ensure they all get marked unrenamable. */
  974. p = &head->next_chain;
  975. continue;
  976. }
  977. /* Whether the terminated chain can be used for renaming
  978. depends on the action and this being an exact match.
  979. In either case, we remove this element from open_chains. */
  980. if ((action == terminate_dead || action == terminate_write)
  981. && (superset || subset))
  982. {
  983. unsigned nregs;
  984. if (subset && !superset)
  985. head->cannot_rename = 1;
  986. bitmap_clear_bit (&open_chains_set, head->id);
  987. nregs = head->nregs;
  988. while (nregs-- > 0)
  989. {
  990. CLEAR_HARD_REG_BIT (live_in_chains, head->regno + nregs);
  991. if (subset && !superset
  992. && (head->regno + nregs < this_regno
  993. || head->regno + nregs >= this_regno + this_nregs))
  994. SET_HARD_REG_BIT (live_hard_regs, head->regno + nregs);
  995. }
  996. *p = next;
  997. if (dump_file)
  998. fprintf (dump_file,
  999. "Closing chain %s (%d) at insn %d (%s%s)\n",
  1000. reg_names[head->regno], head->id, INSN_UID (insn),
  1001. scan_actions_name[(int) action],
  1002. superset ? ", superset" : subset ? ", subset" : "");
  1003. }
  1004. else if (action == terminate_dead || action == terminate_write)
  1005. {
  1006. /* In this case, tracking liveness gets too hard. Fail the
  1007. entire basic block. */
  1008. if (dump_file)
  1009. fprintf (dump_file,
  1010. "Failing basic block due to unhandled overlap\n");
  1011. fail_current_block = true;
  1012. return;
  1013. }
  1014. else
  1015. {
  1016. head->cannot_rename = 1;
  1017. if (dump_file)
  1018. fprintf (dump_file,
  1019. "Cannot rename chain %s (%d) at insn %d (%s)\n",
  1020. reg_names[head->regno], head->id, INSN_UID (insn),
  1021. scan_actions_name[(int) action]);
  1022. p = &head->next_chain;
  1023. }
  1024. }
  1025. }
  1026. /* Adapted from find_reloads_address_1. CL is INDEX_REG_CLASS or
  1027. BASE_REG_CLASS depending on how the register is being considered. */
  1028. static void
  1029. scan_rtx_address (rtx_insn *insn, rtx *loc, enum reg_class cl,
  1030. enum scan_actions action, machine_mode mode,
  1031. addr_space_t as)
  1032. {
  1033. rtx x = *loc;
  1034. RTX_CODE code = GET_CODE (x);
  1035. const char *fmt;
  1036. int i, j;
  1037. if (action == mark_write || action == mark_access)
  1038. return;
  1039. switch (code)
  1040. {
  1041. case PLUS:
  1042. {
  1043. rtx orig_op0 = XEXP (x, 0);
  1044. rtx orig_op1 = XEXP (x, 1);
  1045. RTX_CODE code0 = GET_CODE (orig_op0);
  1046. RTX_CODE code1 = GET_CODE (orig_op1);
  1047. rtx op0 = orig_op0;
  1048. rtx op1 = orig_op1;
  1049. rtx *locI = NULL;
  1050. rtx *locB = NULL;
  1051. enum rtx_code index_code = SCRATCH;
  1052. if (GET_CODE (op0) == SUBREG)
  1053. {
  1054. op0 = SUBREG_REG (op0);
  1055. code0 = GET_CODE (op0);
  1056. }
  1057. if (GET_CODE (op1) == SUBREG)
  1058. {
  1059. op1 = SUBREG_REG (op1);
  1060. code1 = GET_CODE (op1);
  1061. }
  1062. if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
  1063. || code0 == ZERO_EXTEND || code1 == MEM)
  1064. {
  1065. locI = &XEXP (x, 0);
  1066. locB = &XEXP (x, 1);
  1067. index_code = GET_CODE (*locI);
  1068. }
  1069. else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
  1070. || code1 == ZERO_EXTEND || code0 == MEM)
  1071. {
  1072. locI = &XEXP (x, 1);
  1073. locB = &XEXP (x, 0);
  1074. index_code = GET_CODE (*locI);
  1075. }
  1076. else if (code0 == CONST_INT || code0 == CONST
  1077. || code0 == SYMBOL_REF || code0 == LABEL_REF)
  1078. {
  1079. locB = &XEXP (x, 1);
  1080. index_code = GET_CODE (XEXP (x, 0));
  1081. }
  1082. else if (code1 == CONST_INT || code1 == CONST
  1083. || code1 == SYMBOL_REF || code1 == LABEL_REF)
  1084. {
  1085. locB = &XEXP (x, 0);
  1086. index_code = GET_CODE (XEXP (x, 1));
  1087. }
  1088. else if (code0 == REG && code1 == REG)
  1089. {
  1090. int index_op;
  1091. unsigned regno0 = REGNO (op0), regno1 = REGNO (op1);
  1092. if (REGNO_OK_FOR_INDEX_P (regno1)
  1093. && regno_ok_for_base_p (regno0, mode, as, PLUS, REG))
  1094. index_op = 1;
  1095. else if (REGNO_OK_FOR_INDEX_P (regno0)
  1096. && regno_ok_for_base_p (regno1, mode, as, PLUS, REG))
  1097. index_op = 0;
  1098. else if (regno_ok_for_base_p (regno0, mode, as, PLUS, REG)
  1099. || REGNO_OK_FOR_INDEX_P (regno1))
  1100. index_op = 1;
  1101. else if (regno_ok_for_base_p (regno1, mode, as, PLUS, REG))
  1102. index_op = 0;
  1103. else
  1104. index_op = 1;
  1105. locI = &XEXP (x, index_op);
  1106. locB = &XEXP (x, !index_op);
  1107. index_code = GET_CODE (*locI);
  1108. }
  1109. else if (code0 == REG)
  1110. {
  1111. locI = &XEXP (x, 0);
  1112. locB = &XEXP (x, 1);
  1113. index_code = GET_CODE (*locI);
  1114. }
  1115. else if (code1 == REG)
  1116. {
  1117. locI = &XEXP (x, 1);
  1118. locB = &XEXP (x, 0);
  1119. index_code = GET_CODE (*locI);
  1120. }
  1121. if (locI)
  1122. scan_rtx_address (insn, locI, INDEX_REG_CLASS, action, mode, as);
  1123. if (locB)
  1124. scan_rtx_address (insn, locB,
  1125. base_reg_class (mode, as, PLUS, index_code),
  1126. action, mode, as);
  1127. return;
  1128. }
  1129. case POST_INC:
  1130. case POST_DEC:
  1131. case POST_MODIFY:
  1132. case PRE_INC:
  1133. case PRE_DEC:
  1134. case PRE_MODIFY:
  1135. #ifndef AUTO_INC_DEC
  1136. /* If the target doesn't claim to handle autoinc, this must be
  1137. something special, like a stack push. Kill this chain. */
  1138. action = mark_all_read;
  1139. #endif
  1140. break;
  1141. case MEM:
  1142. scan_rtx_address (insn, &XEXP (x, 0),
  1143. base_reg_class (GET_MODE (x), MEM_ADDR_SPACE (x),
  1144. MEM, SCRATCH),
  1145. action, GET_MODE (x), MEM_ADDR_SPACE (x));
  1146. return;
  1147. case REG:
  1148. scan_rtx_reg (insn, loc, cl, action, OP_IN);
  1149. return;
  1150. default:
  1151. break;
  1152. }
  1153. fmt = GET_RTX_FORMAT (code);
  1154. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1155. {
  1156. if (fmt[i] == 'e')
  1157. scan_rtx_address (insn, &XEXP (x, i), cl, action, mode, as);
  1158. else if (fmt[i] == 'E')
  1159. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1160. scan_rtx_address (insn, &XVECEXP (x, i, j), cl, action, mode, as);
  1161. }
  1162. }
  1163. static void
  1164. scan_rtx (rtx_insn *insn, rtx *loc, enum reg_class cl, enum scan_actions action,
  1165. enum op_type type)
  1166. {
  1167. const char *fmt;
  1168. rtx x = *loc;
  1169. enum rtx_code code = GET_CODE (x);
  1170. int i, j;
  1171. code = GET_CODE (x);
  1172. switch (code)
  1173. {
  1174. case CONST:
  1175. CASE_CONST_ANY:
  1176. case SYMBOL_REF:
  1177. case LABEL_REF:
  1178. case CC0:
  1179. case PC:
  1180. return;
  1181. case REG:
  1182. scan_rtx_reg (insn, loc, cl, action, type);
  1183. return;
  1184. case MEM:
  1185. scan_rtx_address (insn, &XEXP (x, 0),
  1186. base_reg_class (GET_MODE (x), MEM_ADDR_SPACE (x),
  1187. MEM, SCRATCH),
  1188. action, GET_MODE (x), MEM_ADDR_SPACE (x));
  1189. return;
  1190. case SET:
  1191. scan_rtx (insn, &SET_SRC (x), cl, action, OP_IN);
  1192. scan_rtx (insn, &SET_DEST (x), cl, action,
  1193. (GET_CODE (PATTERN (insn)) == COND_EXEC
  1194. && verify_reg_tracked (SET_DEST (x))) ? OP_INOUT : OP_OUT);
  1195. return;
  1196. case STRICT_LOW_PART:
  1197. scan_rtx (insn, &XEXP (x, 0), cl, action,
  1198. verify_reg_tracked (XEXP (x, 0)) ? OP_INOUT : OP_OUT);
  1199. return;
  1200. case ZERO_EXTRACT:
  1201. case SIGN_EXTRACT:
  1202. scan_rtx (insn, &XEXP (x, 0), cl, action,
  1203. (type == OP_IN ? OP_IN :
  1204. verify_reg_tracked (XEXP (x, 0)) ? OP_INOUT : OP_OUT));
  1205. scan_rtx (insn, &XEXP (x, 1), cl, action, OP_IN);
  1206. scan_rtx (insn, &XEXP (x, 2), cl, action, OP_IN);
  1207. return;
  1208. case POST_INC:
  1209. case PRE_INC:
  1210. case POST_DEC:
  1211. case PRE_DEC:
  1212. case POST_MODIFY:
  1213. case PRE_MODIFY:
  1214. /* Should only happen inside MEM. */
  1215. gcc_unreachable ();
  1216. case CLOBBER:
  1217. scan_rtx (insn, &SET_DEST (x), cl, action,
  1218. (GET_CODE (PATTERN (insn)) == COND_EXEC
  1219. && verify_reg_tracked (SET_DEST (x))) ? OP_INOUT : OP_OUT);
  1220. return;
  1221. case EXPR_LIST:
  1222. scan_rtx (insn, &XEXP (x, 0), cl, action, type);
  1223. if (XEXP (x, 1))
  1224. scan_rtx (insn, &XEXP (x, 1), cl, action, type);
  1225. return;
  1226. default:
  1227. break;
  1228. }
  1229. fmt = GET_RTX_FORMAT (code);
  1230. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1231. {
  1232. if (fmt[i] == 'e')
  1233. scan_rtx (insn, &XEXP (x, i), cl, action, type);
  1234. else if (fmt[i] == 'E')
  1235. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1236. scan_rtx (insn, &XVECEXP (x, i, j), cl, action, type);
  1237. }
  1238. }
  1239. /* Hide operands of the current insn (of which there are N_OPS) by
  1240. substituting cc0 for them.
  1241. Previous values are stored in the OLD_OPERANDS and OLD_DUPS.
  1242. For every bit set in DO_NOT_HIDE, we leave the operand alone.
  1243. If INOUT_AND_EC_ONLY is set, we only do this for OP_INOUT type operands
  1244. and earlyclobbers. */
  1245. static void
  1246. hide_operands (int n_ops, rtx *old_operands, rtx *old_dups,
  1247. unsigned HOST_WIDE_INT do_not_hide, bool inout_and_ec_only)
  1248. {
  1249. int i;
  1250. const operand_alternative *op_alt = which_op_alt ();
  1251. for (i = 0; i < n_ops; i++)
  1252. {
  1253. old_operands[i] = recog_data.operand[i];
  1254. /* Don't squash match_operator or match_parallel here, since
  1255. we don't know that all of the contained registers are
  1256. reachable by proper operands. */
  1257. if (recog_data.constraints[i][0] == '\0')
  1258. continue;
  1259. if (do_not_hide & (1 << i))
  1260. continue;
  1261. if (!inout_and_ec_only || recog_data.operand_type[i] == OP_INOUT
  1262. || op_alt[i].earlyclobber)
  1263. *recog_data.operand_loc[i] = cc0_rtx;
  1264. }
  1265. for (i = 0; i < recog_data.n_dups; i++)
  1266. {
  1267. int opn = recog_data.dup_num[i];
  1268. old_dups[i] = *recog_data.dup_loc[i];
  1269. if (do_not_hide & (1 << opn))
  1270. continue;
  1271. if (!inout_and_ec_only || recog_data.operand_type[opn] == OP_INOUT
  1272. || op_alt[opn].earlyclobber)
  1273. *recog_data.dup_loc[i] = cc0_rtx;
  1274. }
  1275. }
  1276. /* Undo the substitution performed by hide_operands. INSN is the insn we
  1277. are processing; the arguments are the same as in hide_operands. */
  1278. static void
  1279. restore_operands (rtx_insn *insn, int n_ops, rtx *old_operands, rtx *old_dups)
  1280. {
  1281. int i;
  1282. for (i = 0; i < recog_data.n_dups; i++)
  1283. *recog_data.dup_loc[i] = old_dups[i];
  1284. for (i = 0; i < n_ops; i++)
  1285. *recog_data.operand_loc[i] = old_operands[i];
  1286. if (recog_data.n_dups)
  1287. df_insn_rescan (insn);
  1288. }
  1289. /* For each output operand of INSN, call scan_rtx to create a new
  1290. open chain. Do this only for normal or earlyclobber outputs,
  1291. depending on EARLYCLOBBER. If INSN_INFO is nonnull, use it to
  1292. record information about the operands in the insn. */
  1293. static void
  1294. record_out_operands (rtx_insn *insn, bool earlyclobber, insn_rr_info *insn_info)
  1295. {
  1296. int n_ops = recog_data.n_operands;
  1297. const operand_alternative *op_alt = which_op_alt ();
  1298. int i;
  1299. for (i = 0; i < n_ops + recog_data.n_dups; i++)
  1300. {
  1301. int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
  1302. rtx *loc = (i < n_ops
  1303. ? recog_data.operand_loc[opn]
  1304. : recog_data.dup_loc[i - n_ops]);
  1305. rtx op = *loc;
  1306. enum reg_class cl = alternative_class (op_alt, opn);
  1307. struct du_head *prev_open;
  1308. if (recog_data.operand_type[opn] != OP_OUT
  1309. || op_alt[opn].earlyclobber != earlyclobber)
  1310. continue;
  1311. if (insn_info)
  1312. cur_operand = insn_info->op_info + i;
  1313. prev_open = open_chains;
  1314. scan_rtx (insn, loc, cl, mark_write, OP_OUT);
  1315. /* ??? Many targets have output constraints on the SET_DEST
  1316. of a call insn, which is stupid, since these are certainly
  1317. ABI defined hard registers. For these, and for asm operands
  1318. that originally referenced hard registers, we must record that
  1319. the chain cannot be renamed. */
  1320. if (CALL_P (insn)
  1321. || (asm_noperands (PATTERN (insn)) > 0
  1322. && REG_P (op)
  1323. && REGNO (op) == ORIGINAL_REGNO (op)))
  1324. {
  1325. if (prev_open != open_chains)
  1326. open_chains->cannot_rename = 1;
  1327. }
  1328. }
  1329. cur_operand = NULL;
  1330. }
  1331. /* Build def/use chain. */
  1332. static bool
  1333. build_def_use (basic_block bb)
  1334. {
  1335. rtx_insn *insn;
  1336. unsigned HOST_WIDE_INT untracked_operands;
  1337. fail_current_block = false;
  1338. for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
  1339. {
  1340. if (NONDEBUG_INSN_P (insn))
  1341. {
  1342. int n_ops;
  1343. rtx note;
  1344. rtx old_operands[MAX_RECOG_OPERANDS];
  1345. rtx old_dups[MAX_DUP_OPERANDS];
  1346. int i;
  1347. int predicated;
  1348. enum rtx_code set_code = SET;
  1349. enum rtx_code clobber_code = CLOBBER;
  1350. insn_rr_info *insn_info = NULL;
  1351. /* Process the insn, determining its effect on the def-use
  1352. chains and live hard registers. We perform the following
  1353. steps with the register references in the insn, simulating
  1354. its effect:
  1355. (1) Deal with earlyclobber operands and CLOBBERs of non-operands
  1356. by creating chains and marking hard regs live.
  1357. (2) Any read outside an operand causes any chain it overlaps
  1358. with to be marked unrenamable.
  1359. (3) Any read inside an operand is added if there's already
  1360. an open chain for it.
  1361. (4) For any REG_DEAD note we find, close open chains that
  1362. overlap it.
  1363. (5) For any non-earlyclobber write we find, close open chains
  1364. that overlap it.
  1365. (6) For any non-earlyclobber write we find in an operand, make
  1366. a new chain or mark the hard register as live.
  1367. (7) For any REG_UNUSED, close any chains we just opened.
  1368. We cannot deal with situations where we track a reg in one mode
  1369. and see a reference in another mode; these will cause the chain
  1370. to be marked unrenamable or even cause us to abort the entire
  1371. basic block. */
  1372. extract_constrain_insn (insn);
  1373. preprocess_constraints (insn);
  1374. const operand_alternative *op_alt = which_op_alt ();
  1375. n_ops = recog_data.n_operands;
  1376. untracked_operands = 0;
  1377. if (insn_rr.exists ())
  1378. {
  1379. insn_info = &insn_rr[INSN_UID (insn)];
  1380. insn_info->op_info = XOBNEWVEC (&rename_obstack, operand_rr_info,
  1381. recog_data.n_operands);
  1382. memset (insn_info->op_info, 0,
  1383. sizeof (operand_rr_info) * recog_data.n_operands);
  1384. }
  1385. /* Simplify the code below by promoting OP_OUT to OP_INOUT in
  1386. predicated instructions, but only for register operands
  1387. that are already tracked, so that we can create a chain
  1388. when the first SET makes a register live. */
  1389. predicated = GET_CODE (PATTERN (insn)) == COND_EXEC;
  1390. for (i = 0; i < n_ops; ++i)
  1391. {
  1392. rtx op = recog_data.operand[i];
  1393. int matches = op_alt[i].matches;
  1394. if (matches >= 0 || op_alt[i].matched >= 0
  1395. || (predicated && recog_data.operand_type[i] == OP_OUT))
  1396. {
  1397. recog_data.operand_type[i] = OP_INOUT;
  1398. /* A special case to deal with instruction patterns that
  1399. have matching operands with different modes. If we're
  1400. not already tracking such a reg, we won't start here,
  1401. and we must instead make sure to make the operand visible
  1402. to the machinery that tracks hard registers. */
  1403. if (matches >= 0
  1404. && (GET_MODE_SIZE (recog_data.operand_mode[i])
  1405. != GET_MODE_SIZE (recog_data.operand_mode[matches]))
  1406. && !verify_reg_in_set (op, &live_in_chains))
  1407. {
  1408. untracked_operands |= 1 << i;
  1409. untracked_operands |= 1 << matches;
  1410. }
  1411. }
  1412. /* If there's an in-out operand with a register that is not
  1413. being tracked at all yet, open a chain. */
  1414. if (recog_data.operand_type[i] == OP_INOUT
  1415. && !(untracked_operands & (1 << i))
  1416. && REG_P (op)
  1417. && !verify_reg_tracked (op))
  1418. {
  1419. machine_mode mode = GET_MODE (op);
  1420. unsigned this_regno = REGNO (op);
  1421. unsigned this_nregs = hard_regno_nregs[this_regno][mode];
  1422. create_new_chain (this_regno, this_nregs, NULL, NULL,
  1423. NO_REGS);
  1424. }
  1425. }
  1426. if (fail_current_block)
  1427. break;
  1428. /* Step 1a: Mark hard registers that are clobbered in this insn,
  1429. outside an operand, as live. */
  1430. hide_operands (n_ops, old_operands, old_dups, untracked_operands,
  1431. false);
  1432. note_stores (PATTERN (insn), note_sets_clobbers, &clobber_code);
  1433. restore_operands (insn, n_ops, old_operands, old_dups);
  1434. /* Step 1b: Begin new chains for earlyclobbered writes inside
  1435. operands. */
  1436. record_out_operands (insn, true, insn_info);
  1437. /* Step 2: Mark chains for which we have reads outside operands
  1438. as unrenamable.
  1439. We do this by munging all operands into CC0, and closing
  1440. everything remaining. */
  1441. hide_operands (n_ops, old_operands, old_dups, untracked_operands,
  1442. false);
  1443. scan_rtx (insn, &PATTERN (insn), NO_REGS, mark_all_read, OP_IN);
  1444. restore_operands (insn, n_ops, old_operands, old_dups);
  1445. /* Step 2B: Can't rename function call argument registers. */
  1446. if (CALL_P (insn) && CALL_INSN_FUNCTION_USAGE (insn))
  1447. scan_rtx (insn, &CALL_INSN_FUNCTION_USAGE (insn),
  1448. NO_REGS, mark_all_read, OP_IN);
  1449. /* Step 2C: Can't rename asm operands that were originally
  1450. hard registers. */
  1451. if (asm_noperands (PATTERN (insn)) > 0)
  1452. for (i = 0; i < n_ops; i++)
  1453. {
  1454. rtx *loc = recog_data.operand_loc[i];
  1455. rtx op = *loc;
  1456. if (REG_P (op)
  1457. && REGNO (op) == ORIGINAL_REGNO (op)
  1458. && (recog_data.operand_type[i] == OP_IN
  1459. || recog_data.operand_type[i] == OP_INOUT))
  1460. scan_rtx (insn, loc, NO_REGS, mark_all_read, OP_IN);
  1461. }
  1462. /* Step 3: Append to chains for reads inside operands. */
  1463. for (i = 0; i < n_ops + recog_data.n_dups; i++)
  1464. {
  1465. int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
  1466. rtx *loc = (i < n_ops
  1467. ? recog_data.operand_loc[opn]
  1468. : recog_data.dup_loc[i - n_ops]);
  1469. enum reg_class cl = alternative_class (op_alt, opn);
  1470. enum op_type type = recog_data.operand_type[opn];
  1471. /* Don't scan match_operand here, since we've no reg class
  1472. information to pass down. Any operands that we could
  1473. substitute in will be represented elsewhere. */
  1474. if (recog_data.constraints[opn][0] == '\0'
  1475. || untracked_operands & (1 << opn))
  1476. continue;
  1477. if (insn_info)
  1478. cur_operand = i == opn ? insn_info->op_info + i : NULL;
  1479. if (op_alt[opn].is_address)
  1480. scan_rtx_address (insn, loc, cl, mark_read,
  1481. VOIDmode, ADDR_SPACE_GENERIC);
  1482. else
  1483. scan_rtx (insn, loc, cl, mark_read, type);
  1484. }
  1485. cur_operand = NULL;
  1486. /* Step 3B: Record updates for regs in REG_INC notes, and
  1487. source regs in REG_FRAME_RELATED_EXPR notes. */
  1488. for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  1489. if (REG_NOTE_KIND (note) == REG_INC
  1490. || REG_NOTE_KIND (note) == REG_FRAME_RELATED_EXPR)
  1491. scan_rtx (insn, &XEXP (note, 0), ALL_REGS, mark_read,
  1492. OP_INOUT);
  1493. /* Step 4: Close chains for registers that die here, unless
  1494. the register is mentioned in a REG_UNUSED note. In that
  1495. case we keep the chain open until step #7 below to ensure
  1496. it conflicts with other output operands of this insn.
  1497. See PR 52573. Arguably the insn should not have both
  1498. notes; it has proven difficult to fix that without
  1499. other undesirable side effects. */
  1500. for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  1501. if (REG_NOTE_KIND (note) == REG_DEAD
  1502. && !find_regno_note (insn, REG_UNUSED, REGNO (XEXP (note, 0))))
  1503. {
  1504. remove_from_hard_reg_set (&live_hard_regs,
  1505. GET_MODE (XEXP (note, 0)),
  1506. REGNO (XEXP (note, 0)));
  1507. scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
  1508. OP_IN);
  1509. }
  1510. /* Step 4B: If this is a call, any chain live at this point
  1511. requires a caller-saved reg. */
  1512. if (CALL_P (insn))
  1513. {
  1514. struct du_head *p;
  1515. for (p = open_chains; p; p = p->next_chain)
  1516. p->need_caller_save_reg = 1;
  1517. }
  1518. /* Step 5: Close open chains that overlap writes. Similar to
  1519. step 2, we hide in-out operands, since we do not want to
  1520. close these chains. We also hide earlyclobber operands,
  1521. since we've opened chains for them in step 1, and earlier
  1522. chains they would overlap with must have been closed at
  1523. the previous insn at the latest, as such operands cannot
  1524. possibly overlap with any input operands. */
  1525. hide_operands (n_ops, old_operands, old_dups, untracked_operands,
  1526. true);
  1527. scan_rtx (insn, &PATTERN (insn), NO_REGS, terminate_write, OP_IN);
  1528. restore_operands (insn, n_ops, old_operands, old_dups);
  1529. /* Step 6a: Mark hard registers that are set in this insn,
  1530. outside an operand, as live. */
  1531. hide_operands (n_ops, old_operands, old_dups, untracked_operands,
  1532. false);
  1533. note_stores (PATTERN (insn), note_sets_clobbers, &set_code);
  1534. restore_operands (insn, n_ops, old_operands, old_dups);
  1535. /* Step 6b: Begin new chains for writes inside operands. */
  1536. record_out_operands (insn, false, insn_info);
  1537. /* Step 6c: Record destination regs in REG_FRAME_RELATED_EXPR
  1538. notes for update. */
  1539. for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  1540. if (REG_NOTE_KIND (note) == REG_FRAME_RELATED_EXPR)
  1541. scan_rtx (insn, &XEXP (note, 0), ALL_REGS, mark_access,
  1542. OP_INOUT);
  1543. /* Step 7: Close chains for registers that were never
  1544. really used here. */
  1545. for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  1546. if (REG_NOTE_KIND (note) == REG_UNUSED)
  1547. {
  1548. remove_from_hard_reg_set (&live_hard_regs,
  1549. GET_MODE (XEXP (note, 0)),
  1550. REGNO (XEXP (note, 0)));
  1551. scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
  1552. OP_IN);
  1553. }
  1554. }
  1555. else if (DEBUG_INSN_P (insn)
  1556. && !VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn)))
  1557. {
  1558. scan_rtx (insn, &INSN_VAR_LOCATION_LOC (insn),
  1559. ALL_REGS, mark_read, OP_IN);
  1560. }
  1561. if (insn == BB_END (bb))
  1562. break;
  1563. }
  1564. if (fail_current_block)
  1565. return false;
  1566. return true;
  1567. }
  1568. /* Initialize the register renamer. If INSN_INFO is true, ensure that
  1569. insn_rr is nonnull. */
  1570. void
  1571. regrename_init (bool insn_info)
  1572. {
  1573. gcc_obstack_init (&rename_obstack);
  1574. insn_rr.create (0);
  1575. if (insn_info)
  1576. insn_rr.safe_grow_cleared (get_max_uid ());
  1577. }
  1578. /* Free all global data used by the register renamer. */
  1579. void
  1580. regrename_finish (void)
  1581. {
  1582. insn_rr.release ();
  1583. free_chain_data ();
  1584. obstack_free (&rename_obstack, NULL);
  1585. }
  1586. /* Perform register renaming on the current function. */
  1587. static unsigned int
  1588. regrename_optimize (void)
  1589. {
  1590. df_set_flags (DF_LR_RUN_DCE);
  1591. df_note_add_problem ();
  1592. df_analyze ();
  1593. df_set_flags (DF_DEFER_INSN_RESCAN);
  1594. regrename_init (false);
  1595. regrename_analyze (NULL);
  1596. rename_chains ();
  1597. regrename_finish ();
  1598. return 0;
  1599. }
  1600. namespace {
  1601. const pass_data pass_data_regrename =
  1602. {
  1603. RTL_PASS, /* type */
  1604. "rnreg", /* name */
  1605. OPTGROUP_NONE, /* optinfo_flags */
  1606. TV_RENAME_REGISTERS, /* tv_id */
  1607. 0, /* properties_required */
  1608. 0, /* properties_provided */
  1609. 0, /* properties_destroyed */
  1610. 0, /* todo_flags_start */
  1611. TODO_df_finish, /* todo_flags_finish */
  1612. };
  1613. class pass_regrename : public rtl_opt_pass
  1614. {
  1615. public:
  1616. pass_regrename (gcc::context *ctxt)
  1617. : rtl_opt_pass (pass_data_regrename, ctxt)
  1618. {}
  1619. /* opt_pass methods: */
  1620. virtual bool gate (function *)
  1621. {
  1622. return (optimize > 0 && (flag_rename_registers));
  1623. }
  1624. virtual unsigned int execute (function *) { return regrename_optimize (); }
  1625. }; // class pass_regrename
  1626. } // anon namespace
  1627. rtl_opt_pass *
  1628. make_pass_regrename (gcc::context *ctxt)
  1629. {
  1630. return new pass_regrename (ctxt);
  1631. }