reload.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  1. /* Search an insn for pseudo regs that must be in hard regs and are not.
  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 subroutines used only from the file reload1.c.
  18. It knows how to scan one insn for operands and values
  19. that need to be copied into registers to make valid code.
  20. It also finds other operands and values which are valid
  21. but for which equivalent values in registers exist and
  22. ought to be used instead.
  23. Before processing the first insn of the function, call `init_reload'.
  24. To scan an insn, call `find_reloads'. This does two things:
  25. 1. sets up tables describing which values must be reloaded
  26. for this insn, and what kind of hard regs they must be reloaded into;
  27. 2. optionally record the locations where those values appear in
  28. the data, so they can be replaced properly later.
  29. This is done only if the second arg to `find_reloads' is nonzero.
  30. The third arg to `find_reloads' specifies the value of `indirect_ok'.
  31. Then you must choose the hard regs to reload those pseudo regs into,
  32. and generate appropriate load insns before this insn and perhaps
  33. also store insns after this insn. Set up the array `reload_reg_rtx'
  34. to contain the REG rtx's for the registers you used. In some
  35. cases `find_reloads' will return a nonzero value in `reload_reg_rtx'
  36. for certain reloads. Then that tells you which register to use,
  37. so you do not need to allocate one. But you still do need to add extra
  38. instructions to copy the value into and out of that register.
  39. Finally you must call `subst_reloads' to substitute the reload reg rtx's
  40. into the locations already recorded.
  41. NOTE SIDE EFFECTS:
  42. find_reloads can alter the operands of the instruction it is called on.
  43. 1. Any uses of VOLATILE are removed, since it no longer matters.
  44. 2. Pseudo-registers that are equivalent to constants are replaced
  45. with those constants if they are not in hard registers.
  46. 3. Two operands of any sort may be interchanged, if they are in a
  47. commutative instruction.
  48. This happens only if find_reloads thinks the instruction will compile
  49. better that way.
  50. In all of these cases, calling find_reloads a second time immediately
  51. after would produce no further change.
  52. */
  53. /* Tell config.h to use the strict definitions of REG_OK_FOR_INDEX_P, etc.
  54. The strict definitions reject pseudo regs. */
  55. #define REG_OK_STRICT
  56. #include "config.h"
  57. #include "rtl.h"
  58. #include "insn-config.h"
  59. #include "recog.h"
  60. #include "reload.h"
  61. #include "regs.h"
  62. #include "hard-reg-set.h"
  63. extern char insn_operand_address_p[][MAX_RECOG_OPERANDS];
  64. /* The variables set up by `find_reloads' are:
  65. n_reloads number of distinct reloads needed; max reload # + 1
  66. tables indexed by reload number
  67. reload_in rtx for value to reload from
  68. reload_out rtx for where to store reload-reg afterward if nec
  69. (often the same as reload_in)
  70. reload_reg_class enum reg_class, saying what regs to reload into
  71. reload_mode enum machine_mode; mode this operand should have
  72. when reloaded.
  73. reload_optional char, nonzero for an optional reload.
  74. Optional reloads are ignored unless the
  75. value is already sitting in a register.
  76. reload_inc int, amount to increment reload_in by
  77. before this insn.
  78. reload_reg_rtx rtx. This is the register to reload into.
  79. If it is zero when `find_reloads' returns,
  80. you must find a suitable register in the class
  81. specified by reload_reg_class, and store here
  82. an rtx for that register with mode from reload_mode.
  83. */
  84. int n_reloads;
  85. rtx reload_in[FIRST_PSEUDO_REGISTER];
  86. rtx reload_out[FIRST_PSEUDO_REGISTER];
  87. enum reg_class reload_reg_class[FIRST_PSEUDO_REGISTER];
  88. enum machine_mode reload_mode[FIRST_PSEUDO_REGISTER];
  89. rtx reload_reg_rtx[FIRST_PSEUDO_REGISTER];
  90. char reload_optional[FIRST_PSEUDO_REGISTER];
  91. int reload_inc[FIRST_PSEUDO_REGISTER];
  92. /* Replacing reloads.
  93. If `replace_reloads' is nonzero, then as each reload is recorded
  94. an entry is made for it in the table `replacements'.
  95. Then later `subst_reloads' can look through that table and
  96. perform all the replacements needed. */
  97. /* Nonzero means record the places to replace. */
  98. static int replace_reloads;
  99. /* Each replacement is recorded with a structure like this. */
  100. struct replacement
  101. {
  102. rtx *where; /* Location to store in */
  103. int what; /* which reload this is for */
  104. enum machine_mode mode; /* mode it must have */
  105. };
  106. static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
  107. /* Number of replacements currently recorded. */
  108. static int n_replacements;
  109. /* The instruction we are doing reloads for;
  110. so we can test whether a register dies in it. */
  111. static rtx this_insn;
  112. /* Nonzero means (MEM (REG n)) is valid even if (REG n) is spilled. */
  113. static int indirect_ok;
  114. /* If hard_regs_live_known is nonzero,
  115. we can tell which hard regs are currently live,
  116. at least enough to succeed in choosing dummy reloads. */
  117. static int hard_regs_live_known;
  118. /* Indexed by hard reg number,
  119. element is nonegative if hard reg has been spilled.
  120. This vector is passed to `find_reloads' as an argument
  121. and is not changed here. */
  122. static short *static_reload_reg_p;
  123. static enum reg_class reg_class_subunion[N_REG_CLASSES][N_REG_CLASSES]
  124. = REG_CLASS_SUBUNION;
  125. static HARD_REG_SET reg_class_contents[] = REG_CLASS_CONTENTS;
  126. static char call_clobbered_regs[] = CALL_USED_REGISTERS;
  127. static rtx find_reloads_toplev ();
  128. static void find_reloads_address ();
  129. static void find_reloads_address_1 ();
  130. static int reg_dead_here_p ();
  131. static int hard_reg_dead_here_p ();
  132. static int hard_reg_set_here_p ();
  133. static int refers_to_regno_p ();
  134. static rtx forget_volatility ();
  135. static rtx subst_reg_equivs ();
  136. rtx find_equiv_reg ();
  137. static int find_inc_amount ();
  138. /* Record one reload that needs to be performed.
  139. IN is an rtx saying where the data are to be found before this instruction.
  140. OUT says where they must be stored after the instruction.
  141. (IN is zero for data not read, and OUT is zero for data not written.)
  142. INLOC and OUTLOC point to the places in the instructions where
  143. IN and OUT were found.
  144. CLASS is a register class required for the reloaded data.
  145. INMODE is the machine mode that the instruction requires
  146. for the reg that replaces IN and OUTMODE is likewise for OUT.
  147. If IN is zero, then OUT's location and mode should be passed as
  148. INLOC and INMODE.
  149. OPTIONAL nonzero means this reload does not need to be performed:
  150. it can be discarded if that is more convenient. */
  151. static int
  152. push_reload (in, out, inloc, outloc, class, inmode, outmode, optional)
  153. register rtx in, out;
  154. rtx *inloc, *outloc;
  155. enum reg_class class;
  156. enum machine_mode inmode, outmode;
  157. int optional;
  158. {
  159. register int i;
  160. enum machine_mode mode = inmode;
  161. if (outloc != 0 && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (mode))
  162. mode = outmode;
  163. /* If IN is a pseudo register everywhere-equivalent to a constant, and
  164. it is not in a hard register, reload straight from the constant,
  165. since we want to get rid of such pseudo registers. */
  166. if (in != 0 && GET_CODE (in) == REG)
  167. {
  168. register int regno = REGNO (in);
  169. if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  170. && reg_equiv_constant[regno] != 0)
  171. in = reg_equiv_constant[regno];
  172. }
  173. /* Likewise for OUT. Of course, OUT will never be equivalent to
  174. an actual constant, but it might be equivalent to a memory location
  175. (in the case of a parameter). */
  176. if (out != 0 && GET_CODE (out) == REG)
  177. {
  178. register int regno = REGNO (out);
  179. if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  180. && reg_equiv_constant[regno] != 0)
  181. out = reg_equiv_constant[regno];
  182. }
  183. if (class == NO_REGS)
  184. abort ();
  185. /* Narrow down the class of register wanted if that is
  186. desirable on this machine for efficiency. */
  187. if (in != 0)
  188. class = PREFERRED_RELOAD_CLASS(in, class);
  189. /* We can use an existing reload if the class is right
  190. and at least one of IN and OUT is a match
  191. and the other is at worst neutral.
  192. (A zero compared against anything is neutral.) */
  193. for (i = 0; i < n_reloads; i++)
  194. if (reload_reg_class[i] == class
  195. && ((in != 0 && reload_in[i] == in
  196. && (out == 0 || reload_out[i] == 0 || reload_out[i] == out))
  197. ||
  198. (out != 0 && reload_out[i] == out
  199. && (in == 0 || reload_in[i] == 0 || reload_in[i] == in))))
  200. break;
  201. if (i == n_reloads)
  202. {
  203. /* We found no existing reload suitable for re-use.
  204. So add an additional reload. */
  205. reload_in[i] = in;
  206. reload_out[i] = out;
  207. reload_reg_class[i] = class;
  208. reload_mode[i] = mode;
  209. reload_reg_rtx[i] = 0;
  210. reload_optional[i] = optional;
  211. reload_inc[i] = 0;
  212. n_reloads++;
  213. }
  214. else
  215. {
  216. /* We are reusing an existing reload,
  217. but we may have additional information for it.
  218. For example, we may now have both IN and OUT
  219. while the old one may have just one of them. */
  220. if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (reload_mode[i]))
  221. reload_mode[i] = mode;
  222. if (in != 0)
  223. reload_in[i] = in;
  224. if (out != 0)
  225. reload_out[i] = out;
  226. reload_optional[i] &= optional;
  227. }
  228. /* If this is an IN/OUT reload in an insn that sets the CC,
  229. it must be for an autoincrement. It doesn't work to store
  230. the incremented value after the insn because that would clobber the CC.
  231. So we must do the increment of the value reloaded from,
  232. increment it, store it back, then decrement again. */
  233. if (out != 0 && GET_CODE (PATTERN (this_insn)) == SET
  234. && SET_DEST (PATTERN (this_insn)) == cc0_rtx)
  235. {
  236. out = 0;
  237. reload_out[i] = 0;
  238. reload_inc[i] = find_inc_amount (PATTERN (this_insn), in);
  239. /* If we did not find a nonzero amount-to-increment-by,
  240. that contradicts the belief that IN is being incremented
  241. in an address in this insn. */
  242. if (reload_inc[i] == 0)
  243. abort ();
  244. }
  245. /* If we will replace IN and OUT with the reload-reg,
  246. record where they are located so that substitution need
  247. not do a tree walk. */
  248. if (replace_reloads)
  249. {
  250. if (inloc != 0)
  251. {
  252. register struct replacement *r = &replacements[n_replacements++];
  253. r->what = i;
  254. r->where = inloc;
  255. r->mode = inmode;
  256. }
  257. if (outloc != 0 && outloc != inloc)
  258. {
  259. register struct replacement *r = &replacements[n_replacements++];
  260. r->what = i;
  261. r->where = outloc;
  262. r->mode = outmode;
  263. }
  264. }
  265. /* If this reload is just being introduced and it has both
  266. an incoming quantity and an outgoing quantity that are
  267. supposed to be made to match, see if either one of the two
  268. can serve as the place to reload into.
  269. If one of them is acceptable, set reload_reg_rtx[i]
  270. to that one. */
  271. if (in != 0 && out != 0 && in != out && reload_reg_rtx[i] == 0)
  272. {
  273. /* See if OUT will do. */
  274. while (GET_CODE (out) == SUBREG)
  275. out = SUBREG_REG (out);
  276. if (GET_CODE (out) == REG)
  277. {
  278. register int regno = REGNO (out);
  279. /* When we consider whether the insn uses OUT,
  280. ignore references within IN. They don't prevent us
  281. from copying IN into OUT, because those refs would
  282. move into the insn that reloads IN.
  283. However, we only ignore IN in its role as this operand.
  284. If the insn uses IN elsewhere and it contains OUT,
  285. that counts. We can't be sure it's the "same" operand
  286. so it might not go through this reload. */
  287. *inloc = const0_rtx;
  288. if (reg_renumber[regno] >= 0)
  289. regno = reg_renumber[regno];
  290. if (regno < FIRST_PSEUDO_REGISTER
  291. && ! refers_to_regno_p (regno, PATTERN (this_insn), outloc)
  292. && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[i]], regno))
  293. {
  294. reload_reg_rtx[i] = out;
  295. /* If the outgoing register already contains the same value
  296. as the incoming one, we can dispense with loading it.
  297. The easiest way to tell the caller that is to give a phony
  298. value for the incoming operand (same as outgoing one). */
  299. if ((GET_CODE (in) == REG || CONSTANT_ADDRESS_P (in))
  300. && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
  301. static_reload_reg_p))
  302. reload_in[i] = out;
  303. }
  304. *inloc = in;
  305. }
  306. while (GET_CODE (in) == SUBREG)
  307. in = SUBREG_REG (in);
  308. /* Consider using IN if OUT was not acceptable
  309. or if OUT dies in this insn (like the quotient in a divmod insn).
  310. We can't use IN unless it is free after this insn,
  311. which means we must know accurately which hard regs are live. */
  312. if (hard_regs_live_known
  313. && GET_CODE (in) == REG
  314. && (reload_reg_rtx[i] == 0
  315. || reg_dead_here_p (REGNO (reload_reg_rtx[i]), this_insn)))
  316. {
  317. register int regno = REGNO (in);
  318. if (reg_dead_here_p (regno, this_insn))
  319. {
  320. if (reg_renumber[regno] >= 0)
  321. regno = reg_renumber[regno];
  322. if (regno < FIRST_PSEUDO_REGISTER
  323. && ! hard_reg_set_here_p (regno, PATTERN (this_insn))
  324. && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[i]], regno))
  325. {
  326. /* If we were going to use OUT as the reload reg
  327. and changed our mind, it means OUT is a dummy that
  328. dies here. So don't bother copying value to it. */
  329. if (reload_reg_rtx[i] == out)
  330. reload_out[i] = 0;
  331. reload_reg_rtx[i] = in;
  332. }
  333. }
  334. }
  335. }
  336. return i;
  337. }
  338. /* Record an additional place we must replace a value
  339. for which we have already recorded a reload.
  340. RELOADNUM is the value returned by push_reload
  341. when the reload was recorded.
  342. This is used in insn patterns that use match_dup. */
  343. static void
  344. push_replacement (loc, reloadnum, mode)
  345. rtx *loc;
  346. int reloadnum;
  347. enum machine_mode mode;
  348. {
  349. if (replace_reloads)
  350. {
  351. register struct replacement *r = &replacements[n_replacements++];
  352. r->what = reloadnum;
  353. r->where = loc;
  354. r->mode = mode;
  355. }
  356. }
  357. /* This page contains subroutines used mainly for determining
  358. whether the IN or an OUT of a reload can serve as the
  359. reload register. */
  360. /* Return 1 if hard reg number REGNO is on INSN's dead list,
  361. either explicitly or in the guise of a pseudo-reg allocated to REGNO. */
  362. static int
  363. hard_reg_dead_here_p (regno, insn)
  364. register int regno;
  365. rtx insn;
  366. {
  367. register rtx link;
  368. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  369. if ((enum reg_note) GET_MODE (link) == REG_DEAD)
  370. {
  371. register int r = REGNO (XEXP (link, 0));
  372. if (reg_renumber[r] >= 0)
  373. r = reg_renumber[r];
  374. if (r == regno)
  375. return 1;
  376. }
  377. return 0;
  378. }
  379. /* Return 1 if hard reg number REGNO is stored in by expression X,
  380. either explicitly or in the guise of a pseudo-reg allocated to REGNO.
  381. X should be the body of an instruction. */
  382. static int
  383. hard_reg_set_here_p (regno, x)
  384. register int regno;
  385. rtx x;
  386. {
  387. if (GET_CODE (x) == SET)
  388. {
  389. register rtx op0 = SET_DEST (x);
  390. if (GET_CODE (op0) == REG)
  391. {
  392. register int r = REGNO (op0);
  393. if (reg_renumber[r] >= 0)
  394. r = reg_renumber[r];
  395. if (r == regno)
  396. return 1;
  397. }
  398. }
  399. else if (GET_CODE (x) == PARALLEL)
  400. {
  401. register int i = XVECLEN (x, 0) - 1;
  402. for (; i >= 0; i--)
  403. if (hard_reg_set_here_p (regno, XVECEXP (x, 0, i)))
  404. return 1;
  405. }
  406. return 0;
  407. }
  408. /* Return nonzero if register number REGNO is explicitly on the
  409. dead-list of INSN. */
  410. static int
  411. reg_dead_here_p (regno, insn)
  412. register int regno;
  413. rtx insn;
  414. {
  415. register rtx link;
  416. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  417. if ((enum reg_note) GET_MODE (link) == REG_DEAD
  418. && REGNO (XEXP (link, 0)) == regno)
  419. return 1;
  420. return 0;
  421. }
  422. /* Return nonzero if hard register REGNO appears
  423. either explicitly or implicitly in X
  424. other than being stored into.
  425. References contained within the substructure at LOC do not count. */
  426. static int
  427. refers_to_regno_p (regno, x, loc)
  428. int regno;
  429. rtx x;
  430. rtx *loc;
  431. {
  432. register int i;
  433. register RTX_CODE code;
  434. register char *fmt;
  435. repeat:
  436. code = GET_CODE (x);
  437. if (code == REG)
  438. {
  439. i = REGNO (x);
  440. if (reg_renumber[i] >= 0)
  441. i = reg_renumber[i];
  442. return i == regno;
  443. }
  444. if (code == SET)
  445. {
  446. if (GET_CODE (SET_DEST (x)) != REG
  447. && refers_to_regno_p (regno, SET_DEST (x), loc))
  448. return 1;
  449. if (loc == &SET_SRC (x))
  450. return 0;
  451. x = SET_SRC (x);
  452. goto repeat;
  453. }
  454. /* X does not match, so try its subexpressions. */
  455. fmt = GET_RTX_FORMAT (code);
  456. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  457. {
  458. if (fmt[i] == 'e' && loc != &XEXP (x, i))
  459. {
  460. if (i == 0)
  461. {
  462. x = XEXP (x, 0);
  463. goto repeat;
  464. }
  465. else
  466. if (refers_to_regno_p (regno, XEXP (x, i), loc))
  467. return 1;
  468. }
  469. else if (fmt[i] == 'E')
  470. {
  471. register int j;
  472. for (j = XVECLEN (x, i) - 1; j >=0; j--)
  473. if (loc != &XVECEXP (x, i, j)
  474. && refers_to_regno_p (regno, XVECEXP (x, i, j), loc))
  475. return 1;
  476. }
  477. }
  478. return 0;
  479. }
  480. /* Like rtx_equal_p except that it considers two REGs as equal
  481. if they renumber to the same value. */
  482. int
  483. rtx_renumbered_equal_p (x, y)
  484. rtx x, y;
  485. {
  486. register int i;
  487. register RTX_CODE code = GET_CODE (x);
  488. register char *fmt;
  489. if (x == y)
  490. return 1;
  491. if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
  492. && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
  493. && GET_CODE (SUBREG_REG (y)) == REG)))
  494. {
  495. register int j;
  496. if (code == SUBREG)
  497. {
  498. i = REGNO (SUBREG_REG (x));
  499. if (reg_renumber[i] >= 0)
  500. i = reg_renumber[i];
  501. i += SUBREG_WORD (x);
  502. }
  503. else
  504. {
  505. i = REGNO (x);
  506. if (reg_renumber[i] >= 0)
  507. i = reg_renumber[i];
  508. }
  509. if (GET_CODE (y) == SUBREG)
  510. {
  511. j = REGNO (SUBREG_REG (y));
  512. if (reg_renumber[j] >= 0)
  513. j = reg_renumber[j];
  514. j += SUBREG_WORD (y);
  515. }
  516. else
  517. {
  518. j = REGNO (y);
  519. if (reg_renumber[j] >= 0)
  520. j = reg_renumber[j];
  521. }
  522. return i == j;
  523. }
  524. if (code != GET_CODE (y))
  525. return 0;
  526. if (code == LABEL_REF)
  527. return XEXP (x, 0) == XEXP (y, 0);
  528. if (code == SYMBOL_REF)
  529. return XSTR (x, 0) == XSTR (y, 0);
  530. /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
  531. if (GET_MODE (x) != GET_MODE (y))
  532. return 0;
  533. /* Compare the elements. If any pair of corresponding elements
  534. fail to match, return 0 for the whole things. */
  535. fmt = GET_RTX_FORMAT (code);
  536. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  537. {
  538. switch (fmt[i])
  539. {
  540. case 'i':
  541. if (XINT (x, i) != XINT (y, i))
  542. return 0;
  543. break;
  544. case 'e':
  545. if (rtx_renumbered_equal_p (XEXP (x, i), XEXP (y, i)) == 0)
  546. return 0;
  547. break;
  548. case '0':
  549. break;
  550. /* It is believed that rtx's at this level will never
  551. contain anything but integers and other rtx's,
  552. except for within LABEL_REFs and SYMBOL_REFs. */
  553. default:
  554. abort ();
  555. }
  556. }
  557. return 1;
  558. }
  559. /* Main entry point of this file: search the body of INSN
  560. for values that need reloading and record them with push_reload.
  561. REPLACE nonzero means record also where the values occur
  562. so that subst_reloads can be used.
  563. IND_OK says that a memory reference is a valid memory address.
  564. LIVE_KNOWN says we have valid information about which hard
  565. regs are live at each point in the program; this is true when
  566. we are called from global_alloc but false when stupid register
  567. allocation has been done.
  568. RELOAD_REG_P if nonzero is a vector indexed by hard reg number
  569. which is nonzero if the reg has been commandeered for reloading into.
  570. It is copied into STATIC_RELOAD_REG_P and referenced from there
  571. by various subroutines. */
  572. void
  573. find_reloads (insn, replace, ind_ok, live_known, reload_reg_p)
  574. rtx insn;
  575. int replace, ind_ok;
  576. int live_known;
  577. short *reload_reg_p;
  578. {
  579. #ifdef REGISTER_CONSTRAINTS
  580. enum reload_modified { RELOAD_NOTHING, RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE };
  581. register int insn_code_number;
  582. register int i;
  583. int noperands;
  584. char *constraints[MAX_RECOG_OPERANDS];
  585. int this_alternative[MAX_RECOG_OPERANDS];
  586. char this_alternative_win[MAX_RECOG_OPERANDS];
  587. int this_alternative_matches[MAX_RECOG_OPERANDS];
  588. int swapped;
  589. int goal_alternative[MAX_RECOG_OPERANDS];
  590. int this_alternative_number;
  591. int goal_alternative_number;
  592. int operand_reloadnum[MAX_RECOG_OPERANDS];
  593. int goal_alternative_matches[MAX_RECOG_OPERANDS];
  594. int goal_alternative_matched[MAX_RECOG_OPERANDS];
  595. char goal_alternative_win[MAX_RECOG_OPERANDS];
  596. int goal_alternative_swapped;
  597. enum reload_modified modified[MAX_RECOG_OPERANDS];
  598. int best;
  599. int commutative;
  600. char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
  601. rtx body = PATTERN (insn);
  602. this_insn = insn;
  603. n_reloads = 0;
  604. n_replacements = 0;
  605. replace_reloads = replace;
  606. indirect_ok = ind_ok;
  607. hard_regs_live_known = live_known;
  608. static_reload_reg_p = reload_reg_p;
  609. if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER
  610. || GET_CODE (body) == ASM_INPUT
  611. || GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
  612. return;
  613. forget_volatility (PATTERN (insn));
  614. insn_code_number = recog_memoized (insn);
  615. noperands = insn_n_operands[insn_code_number];
  616. insn_extract (insn);
  617. if (noperands == 0)
  618. return;
  619. commutative = 0;
  620. bcopy (insn_operand_constraint[insn_code_number],
  621. constraints, sizeof constraints);
  622. /* If we will need to know, later, whether some pair of operands
  623. are the same, we must compare them now and save the result.
  624. Reloading the base and index registers will clobber them
  625. and afterward they will fail to match. */
  626. for (i = 0; i < noperands; i++)
  627. {
  628. register char *p = constraints[i];
  629. register int c;
  630. while (c = *p++)
  631. if (c == '%')
  632. commutative = 1;
  633. else if (c >= '0' && c <= '9')
  634. {
  635. c -= '0';
  636. operands_match[c][i]
  637. = rtx_renumbered_equal_p (recog_operand[c], recog_operand[i]);
  638. if (commutative)
  639. {
  640. if (c == 1 || c == 2)
  641. operands_match[3 - c][i]
  642. = rtx_renumbered_equal_p (recog_operand[3 - c], recog_operand[i]);
  643. if (i == 1 || i == 2)
  644. operands_match[c][3 - i]
  645. = rtx_renumbered_equal_p (recog_operand[c], recog_operand[3 - i]);
  646. /* Note that c is supposed to be less than i.
  647. No need to consider subtracting both c and i from 3
  648. because in that case they are 1 and 2
  649. and the element we want is operands_match[1][2]. */
  650. }
  651. }
  652. }
  653. /* Examine each operand that is a memory reference or memory address
  654. and reload parts of the addresses into index registers.
  655. While we are at it, initialize the array `modified'.
  656. Also here any references to pseudo regs that didn't get hard regs
  657. but are equivalent to constants get replaced in the insn itself
  658. with those constants. Nobody will ever see them again. */
  659. for (i = 0; i < noperands; i++)
  660. {
  661. register RTX_CODE code = GET_CODE (recog_operand[i]);
  662. modified[i] = RELOAD_READ;
  663. if (constraints[i][0] == 'p')
  664. find_reloads_address (VOIDmode,
  665. recog_operand[i], recog_operand_loc[i]);
  666. if (code == MEM)
  667. find_reloads_address (GET_MODE (recog_operand[i]),
  668. XEXP (recog_operand[i], 0),
  669. &XEXP (recog_operand[i], 0));
  670. if (code == SUBREG)
  671. find_reloads_toplev (recog_operand[i]);
  672. if (code == REG)
  673. {
  674. register int regno = REGNO (recog_operand[i]);
  675. if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  676. && reg_equiv_constant[regno] != 0)
  677. recog_operand[i] = *recog_operand_loc[i]
  678. = reg_equiv_constant[regno];
  679. }
  680. }
  681. /* Now see what we need for pseudo-regs that didn't get hard regs
  682. or got the wrong kind of hard reg. For this, we must consider
  683. all the operands together against the register constraints. */
  684. best = MAX_RECOG_OPERANDS + 100;
  685. swapped = 0;
  686. try_swapped:
  687. this_alternative_number = 0;
  688. /* The constraints are made of several alternatives.
  689. Each operand's constraint looks like foo,bar,... with commas
  690. separating the alternatives. The first alternatives for all
  691. operands go together, the second alternatives go together, etc.
  692. First loop over alternatives. */
  693. while (*constraints[0])
  694. {
  695. /* Loop over operands for one constraint alternative. */
  696. /* LOSERS counts those that don't fit this alternative
  697. and would require loading. */
  698. int losers = 0;
  699. /* BAD is set to 1 if it some operand can't fit this alternative
  700. even after reloading. */
  701. int bad = 0;
  702. /* REJECT is a count of how undesirable this alternative says it is
  703. if any reloading is required. If the alternative matches exactly
  704. then REJECT is ignored, but otherwise it gets this much
  705. counted against it in addition to the reloading needed. */
  706. int reject = 0;
  707. for (i = 0; i < noperands; i++)
  708. {
  709. register char *p = constraints[i];
  710. register int win = 0;
  711. int badop = 1;
  712. int c;
  713. register rtx operand = recog_operand[i];
  714. int offset = 0;
  715. int force_reload = 0;
  716. /* If the operand is a SUBREG, extract
  717. the REG or MEM within. */
  718. while (GET_CODE (operand) == SUBREG)
  719. {
  720. offset += SUBREG_WORD (operand);
  721. operand = SUBREG_REG (operand);
  722. if (GET_CODE (operand) == MEM
  723. /*** This is overcautious, as for BYTES_BIG_ENDIAN it is still possible
  724. to avoid setting force_reload if the mode of the subreg
  725. is SImode or bigger. */
  726. #ifndef BYTES_BIG_ENDIAN
  727. && offset != 0
  728. #endif
  729. && !offsetable_address_p (operand))
  730. force_reload = 1;
  731. }
  732. this_alternative[i] = (int) NO_REGS;
  733. this_alternative_win[i] = 0;
  734. this_alternative_matches[i] = -1;
  735. /* Scan this alternative's specs for this operand;
  736. set WIN if the operand fits any letter in this alternative.
  737. Otherwise, clear BADOP if this operand could
  738. fit some letter after reloads. */
  739. while (*p && (c = *p++) != ',')
  740. switch (c)
  741. {
  742. case '=':
  743. modified[i] = RELOAD_WRITE;
  744. break;
  745. case '+':
  746. modified[i] = RELOAD_READ_WRITE;
  747. break;
  748. case '*':
  749. break;
  750. case '%':
  751. commutative = 1;
  752. break;
  753. case '?':
  754. reject++;
  755. break;
  756. case '!':
  757. reject = 100;
  758. break;
  759. case '#':
  760. /* Ignore rest of this alternative as far as
  761. reloading is concerned. */
  762. while (*p && *p != ',') p++;
  763. break;
  764. case '0':
  765. case '1':
  766. case '2':
  767. case '3':
  768. case '4':
  769. c -= '0';
  770. this_alternative_matches[i] = c;
  771. /* We are supposed to match a previous operand.
  772. If we do, we win if that one did.
  773. If we do not, then both of us lose. */
  774. if ((swapped && (c != 1 || i != 2))
  775. /* If we are matching as if operands 1 and 2 were swapped,
  776. also pretend that operands_match had been computed
  777. with them swapped.
  778. But if i is 2 and c is 1, don't exchange them,
  779. because operands_match is valid only on one
  780. side of its diagonal. */
  781. ? (operands_match
  782. [(c == 1 || c == 2) ? 3 - c : c]
  783. [(i == 1 || i == 2) ? 3 - i : i])
  784. : operands_match[c][i])
  785. win = this_alternative_win[c];
  786. else
  787. {
  788. if (this_alternative_win[c])
  789. losers++;
  790. this_alternative_win[c] = 0;
  791. if (this_alternative[c] == (int) NO_REGS)
  792. bad = 1;
  793. }
  794. /* This can be fixed with reloads if the operand
  795. we are supposed to match can be fixed with reloads. */
  796. badop = 0;
  797. break;
  798. case 'p':
  799. /* All necessary reloads for an address_operand
  800. were handled in find_reloads_address. */
  801. this_alternative[i] = (int) ALL_REGS;
  802. win = 1;
  803. break;
  804. case 'm':
  805. if (GET_CODE (operand) == MEM
  806. || (GET_CODE (operand) == REG
  807. && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  808. && reg_renumber[REGNO (operand)] < 0))
  809. win = 1;
  810. if (GET_CODE (operand) == CONST_DOUBLE)
  811. bad = 0;
  812. break;
  813. case '<':
  814. if (GET_CODE (operand) == MEM
  815. && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
  816. || GET_CODE (XEXP (operand, 0)) == POST_DEC))
  817. win = 1;
  818. break;
  819. case '>':
  820. if (GET_CODE (operand) == MEM
  821. && (GET_CODE (XEXP (operand, 0)) == PRE_INC
  822. || GET_CODE (XEXP (operand, 0)) == POST_INC))
  823. win = 1;
  824. break;
  825. /* Memory operand whose address is offsettable. */
  826. case 'o':
  827. if ((GET_CODE (operand) == MEM
  828. && offsetable_address_p (operand))
  829. || (GET_CODE (operand) == REG
  830. && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  831. && reg_renumber[REGNO (operand)] < 0))
  832. win = 1;
  833. if (GET_CODE (operand) == CONST_DOUBLE)
  834. bad = 0;
  835. break;
  836. case 'F':
  837. if (GET_CODE (operand) == CONST_DOUBLE)
  838. win = 1;
  839. break;
  840. case 'G':
  841. case 'H':
  842. if (GET_CODE (operand) == CONST_DOUBLE
  843. && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
  844. win = 1;
  845. break;
  846. case 's':
  847. if (GET_CODE (operand) == CONST_INT)
  848. break;
  849. case 'i':
  850. if (CONSTANT_ADDRESS_P (operand))
  851. win = 1;
  852. break;
  853. case 'I':
  854. case 'J':
  855. case 'K':
  856. case 'L':
  857. case 'M':
  858. if (GET_CODE (operand) == CONST_INT
  859. && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
  860. win = 1;
  861. break;
  862. case 'g':
  863. if (GENERAL_REGS == ALL_REGS
  864. || GET_CODE (operand) != REG
  865. || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
  866. && reg_renumber[REGNO (operand)] < 0))
  867. win = 1;
  868. /* Drop through into 'r' case */
  869. case 'r':
  870. this_alternative[i]
  871. = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
  872. goto reg;
  873. default:
  874. this_alternative[i]
  875. = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
  876. reg:
  877. badop = 0;
  878. if (GET_CODE (operand) == REG
  879. && reg_renumbered_fits_class_p (operand, this_alternative[i], offset))
  880. win = 1;
  881. break;
  882. }
  883. constraints[i] = p;
  884. /* Record which operands fit this alternative. */
  885. if (win && ! force_reload)
  886. this_alternative_win[i] = 1;
  887. else
  888. {
  889. losers++;
  890. if (badop)
  891. bad = 1;
  892. }
  893. }
  894. /* If one set of possibilities, in the register constraints,
  895. accept all the operands, then this insn needs no operand reloads. */
  896. if (losers == 0)
  897. {
  898. /* If we are matching swapped operands for a commutative insn,
  899. then we must really swap the operands to use this alternative.
  900. They are already swapped in recog_operand.
  901. Swap them in the instruction. */
  902. if (swapped)
  903. {
  904. *recog_operand_loc[1] = recog_operand[1];
  905. *recog_operand_loc[2] = recog_operand[2];
  906. }
  907. for (i = 0; i < noperands; i++)
  908. goal_alternative_win[i] = 1;
  909. bcopy (this_alternative, goal_alternative,
  910. sizeof this_alternative);
  911. goal_alternative_number = this_alternative_number;
  912. goto finish;
  913. }
  914. /* REJECT, set by the ! and ? constraint characters
  915. discourages the use of this alternative for a reload goal. */
  916. if (reject > 0)
  917. losers += reject;
  918. /* If this alternative is close enough that reloads could fix it,
  919. record it as the chosen goal for reloading. */
  920. if (! bad && best > losers)
  921. {
  922. bcopy (this_alternative, goal_alternative,
  923. sizeof this_alternative);
  924. bcopy (this_alternative_win, goal_alternative_win,
  925. sizeof this_alternative);
  926. bcopy (this_alternative_matches, goal_alternative_matches,
  927. sizeof this_alternative);
  928. goal_alternative_swapped = swapped;
  929. best = losers;
  930. goal_alternative_number = this_alternative_number;
  931. }
  932. this_alternative_number++;
  933. }
  934. /* If insn is commutative (it's safe to exchange operands 1 and 2)
  935. then we need to try each alternative twice,
  936. the second time matching the operands 1 and 2
  937. as if we had exchanged them.
  938. To do this, really exchange them in recog_operand.
  939. If we have just tried the alternatives the second time,
  940. return recog_operand to normal and drop through. */
  941. if (commutative)
  942. {
  943. swapped = !swapped;
  944. if (swapped)
  945. {
  946. recog_operand[1] = *recog_operand_loc[2];
  947. recog_operand[2] = *recog_operand_loc[1];
  948. bcopy (insn_operand_constraint[insn_code_number],
  949. constraints, sizeof constraints);
  950. goto try_swapped;
  951. }
  952. else
  953. {
  954. recog_operand[1] = *recog_operand_loc[1];
  955. recog_operand[2] = *recog_operand_loc[2];
  956. }
  957. }
  958. /* The operands don't meet the constraints.
  959. goal_alternative describes the alternative
  960. that we could reach by reloading the fewest operands.
  961. Reload so as to fit it. */
  962. if (best == MAX_RECOG_OPERANDS + 100)
  963. abort (); /* No alternative works with reloads?? */
  964. /* If the best alternative is with operands 1 and 2 swapped,
  965. really swap them in the instruction before reporting the reloads. */
  966. if (goal_alternative_swapped)
  967. {
  968. /* We do not alter recog_operand_loc because recog_operand_loc[I]
  969. points to the place where the instruction holds operand I. */
  970. /* Interchange the operands in the instruction. */
  971. *recog_operand_loc[1] = recog_operand[2];
  972. *recog_operand_loc[2] = recog_operand[1];
  973. /* Make recog_operand match the instruction again. */
  974. recog_operand[1] = *recog_operand_loc[1];
  975. recog_operand[2] = *recog_operand_loc[2];
  976. }
  977. /* Right now, for any pair of operands I and J that are required to match,
  978. with I < J,
  979. goal_alternative_matches[J] is I.
  980. Set up goal_alternative_matched as the inverse function:
  981. goal_alternative_matched[I] = J. */
  982. for (i = 0; i < noperands; i++)
  983. goal_alternative_matched[i] = -1;
  984. for (i = 0; i < noperands; i++)
  985. if (! goal_alternative_win[i]
  986. && goal_alternative_matches[i] >= 0)
  987. goal_alternative_matched[goal_alternative_matches[i]] = i;
  988. /* Jump to `finish' from above if all operands are valid already.
  989. In that case,
  990. goal_alternative_win is all 1 and operand_reloadnum is all -1. */
  991. finish:
  992. /* Now record reloads for all the operands that need them. */
  993. for (i = 0; i < noperands; i++)
  994. if (! goal_alternative_win[i])
  995. {
  996. /* Operands that match previous ones have already been handled. */
  997. if (goal_alternative_matches[i] >= 0)
  998. ;
  999. else if (GET_CODE (recog_operand[i]) == CONST_DOUBLE
  1000. && alternative_allows_memconst (insn_operand_constraint[insn_code_number][i], goal_alternative_number))
  1001. *recog_operand_loc[i] = recog_operand[i] = XEXP (recog_operand[i], 2);
  1002. else if (goal_alternative_matched[i] == -1)
  1003. operand_reloadnum[i] =
  1004. push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1005. modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1006. recog_operand_loc[i], 0,
  1007. (enum reg_class) goal_alternative[i],
  1008. insn_operand_mode[insn_code_number][i], 0, 0);
  1009. /* In a matching pair of operands, one must be input only
  1010. and the other must be output only.
  1011. Pass the input operand as IN and the other as OUT. */
  1012. else if (modified[i] == RELOAD_READ
  1013. && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
  1014. operand_reloadnum[goal_alternative_matched[i]]
  1015. = operand_reloadnum[i]
  1016. = push_reload (recog_operand[i],
  1017. recog_operand[goal_alternative_matched[i]],
  1018. recog_operand_loc[i],
  1019. recog_operand_loc[goal_alternative_matched[i]],
  1020. (enum reg_class) goal_alternative[i],
  1021. insn_operand_mode[insn_code_number][i],
  1022. insn_operand_mode[insn_code_number][goal_alternative_matched[i]],
  1023. 0);
  1024. else if (modified[i] == RELOAD_WRITE
  1025. && modified[goal_alternative_matched[i]] == RELOAD_READ)
  1026. operand_reloadnum[goal_alternative_matched[i]]
  1027. = operand_reloadnum[i]
  1028. = push_reload (recog_operand[goal_alternative_matched[i]],
  1029. recog_operand[i],
  1030. recog_operand_loc[goal_alternative_matched[i]],
  1031. recog_operand_loc[i],
  1032. (enum reg_class) goal_alternative[i],
  1033. insn_operand_mode[insn_code_number][goal_alternative_matched[i]],
  1034. insn_operand_mode[insn_code_number][i],
  1035. 0);
  1036. else abort ();
  1037. }
  1038. else
  1039. {
  1040. rtx operand = recog_operand[i];
  1041. /* For each operand that's a pseudo-register
  1042. that didn't get a hard register, make an optional reload.
  1043. This may get done even if the insn needs no reloads otherwise. */
  1044. while (GET_CODE (operand) == SUBREG)
  1045. operand = XEXP (operand, 0);
  1046. if (GET_CODE (operand) == REG
  1047. && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1048. && reg_renumber[REGNO (operand)] < 0
  1049. && (enum reg_class) goal_alternative[i] != NO_REGS)
  1050. operand_reloadnum[i]
  1051. = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1052. modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1053. recog_operand_loc[i], 0,
  1054. (enum reg_class) goal_alternative[i],
  1055. insn_operand_mode[insn_code_number][i],
  1056. 0, 1);
  1057. else
  1058. operand_reloadnum[i] = -1;
  1059. }
  1060. /* If this insn pattern contains any MATCH_DUP's, make sure that
  1061. they will be substituted if the operands they match are substituted.
  1062. Also do now any substitutions we already did on the operands. */
  1063. for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
  1064. {
  1065. *recog_dup_loc[i] = *recog_operand_loc[recog_dup_num[i]];
  1066. if (operand_reloadnum[recog_dup_num[i]] >= 0)
  1067. push_replacement (recog_dup_loc[i], operand_reloadnum[recog_dup_num[i]],
  1068. insn_operand_mode[insn_code_number][i]);
  1069. }
  1070. /* For each reload of a reg into some other class of reg,
  1071. search for an existing equivalent reg (same value now) in the right class.
  1072. We can use it as long as we don't need to change its contents. */
  1073. for (i = 0; i < n_reloads; i++)
  1074. if (reload_reg_rtx[i] == 0
  1075. && reload_in[i] != 0
  1076. && GET_CODE (reload_in[i]) == REG
  1077. && reload_out[i] == 0)
  1078. {
  1079. reload_reg_rtx[i]
  1080. = find_equiv_reg (reload_in[i], insn, reload_reg_class[i], -1,
  1081. static_reload_reg_p);
  1082. /* Prevent generation of insn to load the value
  1083. because the one we found already has the value. */
  1084. if (reload_reg_rtx[i])
  1085. reload_in[i] = reload_reg_rtx[i];
  1086. }
  1087. #else /* no REGISTER_CONSTRAINTS */
  1088. int noperands;
  1089. int insn_code_number;
  1090. register int i;
  1091. rtx body = PATTERN (insn);
  1092. if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER
  1093. || GET_CODE (body) == ASM_INPUT
  1094. || GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
  1095. return;
  1096. n_reloads = 0;
  1097. n_replacements = 0;
  1098. replace_reloads = replace;
  1099. indirect_ok = ind_ok;
  1100. this_insn = insn;
  1101. forget_volatility (body);
  1102. insn_code_number = recog_memoized (insn);
  1103. noperands = insn_n_operands[insn_code_number];
  1104. insn_extract (insn);
  1105. if (noperands == 0)
  1106. return;
  1107. for (i = 0; i < noperands; i++)
  1108. {
  1109. register RTX_CODE code = GET_CODE (recog_operand[i]);
  1110. if (insn_operand_address_p[insn_code_number][i])
  1111. find_reloads_address (VOIDmode,
  1112. recog_operand[i], recog_operand_loc[i]);
  1113. if (code == MEM)
  1114. find_reloads_address (GET_MODE (recog_operand[i]),
  1115. XEXP (recog_operand[i], 0),
  1116. &XEXP (recog_operand[i], 0));
  1117. if (code == SUBREG)
  1118. find_reloads_toplev (recog_operand[i]);
  1119. if (code == REG)
  1120. {
  1121. register int regno = REGNO (recog_operand[i]);
  1122. if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1123. && reg_equiv_constant[regno] != 0)
  1124. recog_operand[i] = *recog_operand_loc[i]
  1125. = reg_equiv_constant[regno];
  1126. }
  1127. }
  1128. #endif /* no REGISTER_CONSTRAINTS */
  1129. }
  1130. /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
  1131. accepts a memory operand with constant address. */
  1132. static int
  1133. alternative_allows_memconst (constraint, altnum)
  1134. char *constraint;
  1135. int altnum;
  1136. {
  1137. register int c;
  1138. /* Skip alternatives before the one requested. */
  1139. while (altnum > 0)
  1140. {
  1141. while (*constraint++ != ',');
  1142. altnum--;
  1143. }
  1144. /* Scan the requested alternative for 'm' or 'o'.
  1145. If one of them is present, this alternative accepts memory constants. */
  1146. while (c == *constraint++ && c != ',' && c != '#')
  1147. if (c == 'm' || c == 'o')
  1148. return 1;
  1149. return 0;
  1150. }
  1151. /* Scan X for memory references and scan the addresses for reloading.
  1152. Also checks for references to "constant" regs that we want to eliminate
  1153. and replaces them with the values they stand for.
  1154. We may alter X descructively if it contains a reference to such.
  1155. If X is just a constant reg, we return the equivalent value
  1156. instead of X. */
  1157. static rtx
  1158. find_reloads_toplev (x)
  1159. rtx x;
  1160. {
  1161. register RTX_CODE code = GET_CODE (x);
  1162. register char *fmt = GET_RTX_FORMAT (code);
  1163. register int i;
  1164. if (code == REG)
  1165. {
  1166. register int regno = REGNO (x);
  1167. if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1168. && reg_equiv_constant[regno] != 0)
  1169. return reg_equiv_constant[regno];
  1170. }
  1171. else if (code == MEM)
  1172. find_reloads_address (GET_MODE (x), XEXP (x, 0), &XEXP (x, 0));
  1173. else
  1174. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1175. {
  1176. if (fmt[i] == 'e')
  1177. XEXP (x, i) = find_reloads_toplev (XEXP (x, i));
  1178. }
  1179. return x;
  1180. }
  1181. /* Note that we take shortcuts assuming that no multi-reg machine mode
  1182. occurs as part of an address. */
  1183. static void
  1184. find_reloads_address (mode, ad, loc)
  1185. enum machine_mode mode;
  1186. rtx ad;
  1187. rtx *loc;
  1188. {
  1189. register int regno;
  1190. if (GET_CODE (ad) == REG)
  1191. {
  1192. regno = REGNO (ad);
  1193. if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1194. && reg_equiv_constant[regno] != 0)
  1195. {
  1196. GO_IF_LEGITIMATE_ADDRESS (mode, reg_equiv_constant[regno], win1);
  1197. }
  1198. if (! (reg_renumber[regno] < 0 ? indirect_ok
  1199. : REGNO_OK_FOR_BASE_P (regno)))
  1200. push_reload (ad, 0, loc, 0, BASE_REG_CLASS, GET_MODE (ad), 0, 0);
  1201. return;
  1202. win1:
  1203. *loc = ad = reg_equiv_constant[regno];
  1204. return;
  1205. }
  1206. GO_IF_LEGITIMATE_ADDRESS (mode, ad, win);
  1207. find_reloads_address_1 (ad, 0, loc);
  1208. return;
  1209. /* The address appears valid, so reloads are not needed.
  1210. But the address may contain an eliminable register we need to eliminate.
  1211. This can happen because a machine with indirect addressing
  1212. may consider a pseudo register by itself a valid address even when
  1213. it has failed to get a hard reg.
  1214. So do a tree-walk to find and eliminate all such regs. */
  1215. win:
  1216. *loc = subst_reg_equivs (ad);
  1217. }
  1218. /* Find all pseudo regs appearing in AD
  1219. that are eliminable in favor of equivalent values
  1220. and do not have hard regs; replace them by their equivalents. */
  1221. static rtx
  1222. subst_reg_equivs (ad)
  1223. rtx ad;
  1224. {
  1225. register int regno;
  1226. register RTX_CODE code = GET_CODE (ad);
  1227. register int i;
  1228. register char *fmt;
  1229. switch (code)
  1230. {
  1231. case CONST_INT:
  1232. case CONST:
  1233. case CONST_DOUBLE:
  1234. case SYMBOL_REF:
  1235. case LABEL_REF:
  1236. case PC:
  1237. case CC0:
  1238. return ad;
  1239. case REG:
  1240. {
  1241. register int regno = REGNO (ad);
  1242. if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1243. && reg_equiv_constant[regno] != 0)
  1244. return reg_equiv_constant[regno];
  1245. }
  1246. return ad;
  1247. }
  1248. fmt = GET_RTX_FORMAT (code);
  1249. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1250. if (fmt[i] == 'e')
  1251. XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i));
  1252. return ad;
  1253. }
  1254. /* Record the pseudo registers we must reload into hard registers
  1255. in a subexpression of a memory address, X.
  1256. CONTEXT = 1 means we are considering regs as index regs,
  1257. = 0 means we are considering them as base regs.
  1258. We return X, whose operands may have been altered,
  1259. or perhaps a RELOAD rtx if X itself was a REG that must be reloaded. */
  1260. /* Note that we take shortcuts assuming that no multi-reg machine mode
  1261. occurs as part of an address.
  1262. Also, this is not fully machine-customizable; it works for machines
  1263. such as vaxes and 68000's and 32000's, but other possible machines
  1264. could have addressing modes that this does not handle right. */
  1265. static void
  1266. find_reloads_address_1 (x, context, loc)
  1267. rtx x;
  1268. int context;
  1269. rtx *loc;
  1270. {
  1271. register RTX_CODE code = GET_CODE (x);
  1272. if (code == PLUS)
  1273. {
  1274. register rtx op0 = XEXP (x, 0);
  1275. register rtx op1 = XEXP (x, 1);
  1276. register RTX_CODE code0 = GET_CODE (op0);
  1277. register RTX_CODE code1 = GET_CODE (op1);
  1278. register int regno;
  1279. if (code0 == MULT || code0 == SIGN_EXTEND || code1 == MEM)
  1280. {
  1281. find_reloads_address_1 (op0, 1, &XEXP (x, 0));
  1282. find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  1283. }
  1284. else if (code1 == MULT || code1 == SIGN_EXTEND || code0 == MEM)
  1285. {
  1286. find_reloads_address_1 (op0, 0, &XEXP (x, 0));
  1287. find_reloads_address_1 (op1, 1, &XEXP (x, 1));
  1288. }
  1289. else if (code0 == CONST_INT || code0 == CONST
  1290. || code0 == SYMBOL_REF || code0 == LABEL_REF)
  1291. {
  1292. find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  1293. }
  1294. else if (code1 == CONST_INT || code1 == CONST
  1295. || code1 == SYMBOL_REF || code1 == LABEL_REF)
  1296. {
  1297. find_reloads_address_1 (op0, 0, &XEXP (x, 0));
  1298. }
  1299. else if (code0 == REG && code1 == REG)
  1300. {
  1301. if (REG_OK_FOR_INDEX_P (op0)
  1302. && REG_OK_FOR_BASE_P (op1))
  1303. return;
  1304. else if (REG_OK_FOR_INDEX_P (op1)
  1305. && REG_OK_FOR_BASE_P (op0))
  1306. return;
  1307. else if (REG_OK_FOR_BASE_P (op1))
  1308. find_reloads_address_1 (op0, 1, &XEXP (x, 0));
  1309. else if (REG_OK_FOR_BASE_P (op0))
  1310. find_reloads_address_1 (op1, 1, &XEXP (x, 1));
  1311. else if (REG_OK_FOR_INDEX_P (op1))
  1312. find_reloads_address_1 (op0, 0, &XEXP (x, 0));
  1313. else if (REG_OK_FOR_INDEX_P (op0))
  1314. find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  1315. else
  1316. {
  1317. find_reloads_address_1 (op0, 1, &XEXP (x, 0));
  1318. find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  1319. }
  1320. }
  1321. else if (code0 == REG)
  1322. {
  1323. find_reloads_address_1 (op0, 1, &XEXP (x, 0));
  1324. find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  1325. }
  1326. else if (code1 == REG)
  1327. {
  1328. find_reloads_address_1 (op1, 1, &XEXP (x, 1));
  1329. find_reloads_address_1 (op0, 0, &XEXP (x, 0));
  1330. }
  1331. }
  1332. else if (code == POST_INC || code == POST_DEC
  1333. || code == PRE_INC || code == PRE_DEC)
  1334. {
  1335. if (GET_CODE (XEXP (x, 0)) == REG)
  1336. {
  1337. register int regno = REGNO (XEXP (x, 0));
  1338. /* ??? Is this a bug?
  1339. I don't see any reason why an argument register
  1340. could not appear in an auto-increment
  1341. and yet fail to get a hard reg. Then this would crash. */
  1342. if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1343. && reg_equiv_constant[regno] != 0)
  1344. abort ();
  1345. if (reg_renumber[regno] >= 0)
  1346. regno = reg_renumber[regno];
  1347. if ((regno >= FIRST_PSEUDO_REGISTER
  1348. || !(context ? REGNO_OK_FOR_INDEX_P (regno)
  1349. : REGNO_OK_FOR_BASE_P (regno))))
  1350. {
  1351. register rtx link;
  1352. int reloadnum
  1353. = push_reload (XEXP (x, 0), XEXP (x, 0),
  1354. &XEXP (x, 0), 0,
  1355. context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  1356. GET_MODE (XEXP (x, 0)), 0, 0);
  1357. for (link = REG_NOTES (this_insn);
  1358. link; link = XEXP (link, 1))
  1359. if ((enum reg_note) GET_MODE (link) == REG_INC
  1360. && REGNO (XEXP (link, 0)) == REGNO (XEXP (x, 0)))
  1361. push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
  1362. }
  1363. return;
  1364. }
  1365. }
  1366. else if (code == REG)
  1367. {
  1368. register int regno = REGNO (x);
  1369. if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1370. && reg_equiv_constant[regno] != 0)
  1371. {
  1372. push_reload (reg_equiv_constant[regno], 0, loc, 0,
  1373. context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  1374. GET_MODE (x), 0, 0);
  1375. return;
  1376. }
  1377. if (reg_renumber[regno] >= 0)
  1378. regno = reg_renumber[regno];
  1379. if ((regno >= FIRST_PSEUDO_REGISTER
  1380. || !(context ? REGNO_OK_FOR_INDEX_P (regno)
  1381. : REGNO_OK_FOR_BASE_P (regno))))
  1382. {
  1383. push_reload (x, 0, loc, 0,
  1384. context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  1385. GET_MODE (x), 0, 0);
  1386. return;
  1387. }
  1388. }
  1389. else
  1390. {
  1391. register char *fmt = GET_RTX_FORMAT (code);
  1392. register int i;
  1393. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1394. {
  1395. if (fmt[i] == 'e')
  1396. find_reloads_address_1 (XEXP (x, i), context, &XEXP (x, i));
  1397. }
  1398. }
  1399. }
  1400. /* Substitute into X the registers into which we have reloaded
  1401. the things that need reloading. The array `replacements'
  1402. says contains the locations of all pointers that must be changed
  1403. and says what to replace them with.
  1404. Return the rtx that X translates into; usually X, but modified. */
  1405. void
  1406. subst_reloads ()
  1407. {
  1408. register int i;
  1409. for (i = 0; i < n_replacements; i++)
  1410. {
  1411. register struct replacement *r = &replacements[i];
  1412. register rtx reloadreg = reload_reg_rtx[r->what];
  1413. if (reloadreg)
  1414. {
  1415. /* Encapsulate RELOADREG so its machine mode matches what
  1416. used to be there. */
  1417. if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
  1418. reloadreg = gen_rtx (SUBREG, r->mode, reloadreg, 0);
  1419. *r->where = reloadreg;
  1420. }
  1421. /* If reload got no reg and isn't optional, something's wrong. */
  1422. else if (! reload_optional[r->what])
  1423. abort ();
  1424. }
  1425. }
  1426. /* Alter X by eliminating all VOLATILE and UNCHANGING expressions.
  1427. Each of them is replaced by its operand.
  1428. Thus, (PLUS (VOLATILE (MEM (REG 5))) (CONST_INT 4))
  1429. becomes (PLUS (MEM (REG 5)) (CONST_INT 4)).
  1430. If X is itself a VOLATILE expression,
  1431. we return the expression that should replace it
  1432. but we do not modify X. */
  1433. static rtx
  1434. forget_volatility (x)
  1435. register rtx x;
  1436. {
  1437. enum rtx_code code = GET_CODE (x);
  1438. register char *fmt;
  1439. register int i;
  1440. register rtx value = 0;
  1441. register rtx tem;
  1442. switch (code)
  1443. {
  1444. case LABEL_REF:
  1445. case SYMBOL_REF:
  1446. case CONST_INT:
  1447. case CONST_DOUBLE:
  1448. case CONST:
  1449. case REG:
  1450. case CC0:
  1451. case PC:
  1452. return x;
  1453. case VOLATILE:
  1454. case UNCHANGING:
  1455. return XEXP (x, 0);
  1456. }
  1457. fmt = GET_RTX_FORMAT (code);
  1458. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1459. {
  1460. if (fmt[i] == 'e')
  1461. XEXP (x, i) = forget_volatility (XEXP (x, i));
  1462. if (fmt[i] == 'E')
  1463. {
  1464. register int j;
  1465. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1466. XVECEXP (x, i, j) = forget_volatility (XVECEXP (x, i, j));
  1467. }
  1468. }
  1469. return x;
  1470. }
  1471. /* Check the insns before INSN to see if there is a suitable register
  1472. containing the same value as GOAL.
  1473. If OTHER is -1, look for a register in class CLASS.
  1474. Otherwise, just see if register number OTHER shares GOAL's value.
  1475. Return an rtx for the register found, or zero if none is found.
  1476. If RELOAD_REG_P is nonzero, it is a vector indexed by hard reg number
  1477. and we reject any hard reg whose element in the vector is 1.
  1478. This function is used by final as well as in the reload pass. */
  1479. rtx
  1480. find_equiv_reg (goal, insn, class, other, reload_reg_p)
  1481. register rtx goal;
  1482. rtx insn;
  1483. enum reg_class class;
  1484. register int other;
  1485. short *reload_reg_p;
  1486. {
  1487. register rtx p = insn;
  1488. rtx valtry, value, where;
  1489. register rtx pat;
  1490. register int regno;
  1491. int valueno;
  1492. if (GET_CODE (goal) == REG)
  1493. regno = REGNO (goal);
  1494. else
  1495. regno = -1;
  1496. /* Scan insns back from INSN, looking for one that copies
  1497. a value into or out of GOAL.
  1498. Stop and give up if we reach a label. */
  1499. while (1)
  1500. {
  1501. p = PREV_INSN (p);
  1502. if (p == 0 || GET_CODE (p) == CODE_LABEL)
  1503. return 0;
  1504. if (GET_CODE (p) == INSN)
  1505. {
  1506. pat = PATTERN (p);
  1507. /* First check for something that sets some reg equal to GOAL. */
  1508. if (GET_CODE (pat) == SET
  1509. && ((regno >= 0
  1510. && GET_CODE (SET_SRC (pat)) == REG
  1511. && REGNO (SET_SRC (pat)) == regno
  1512. && GET_CODE (valtry = SET_DEST (pat)) == REG)
  1513. ||
  1514. (regno >= 0
  1515. && GET_CODE (SET_DEST (pat)) == REG
  1516. && REGNO (SET_DEST (pat)) == regno
  1517. && GET_CODE (valtry = SET_SRC (pat)) == REG)
  1518. ||
  1519. (SET_SRC (pat) == goal
  1520. && GET_CODE (valtry = SET_DEST (pat)) == REG))
  1521. && (other >= 0
  1522. ? REGNO (valtry) == other
  1523. : (valueno = REGNO (valtry),
  1524. reg_renumber[valueno] >= 0 ? valueno = reg_renumber[valueno] : 0,
  1525. valueno < FIRST_PSEUDO_REGISTER &&
  1526. TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  1527. valueno))))
  1528. {
  1529. value = valtry;
  1530. where = p;
  1531. break;
  1532. }
  1533. }
  1534. }
  1535. /* We found a previous insn copying GOAL into a suitable other reg VALUE
  1536. (or copying VALUE into GOAL, if GOAL is also a register).
  1537. Now verify that VALUE is really valid. */
  1538. if (regno >= FIRST_PSEUDO_REGISTER)
  1539. regno = reg_renumber[regno];
  1540. /* VALUENO gets the register number of VALUE;
  1541. for a pseudo reg, it gets the hard reg number that the pseudo has,
  1542. and we give up if the pseudo has no hard reg. */
  1543. valueno = REGNO (value);
  1544. if (valueno >= FIRST_PSEUDO_REGISTER)
  1545. valueno = reg_renumber[valueno];
  1546. if (valueno < 0)
  1547. return 0;
  1548. /* Reject VALUE if it is one of the regs reserved for reloads.
  1549. Reload1 knows how to reuse them anyway, and it would get
  1550. confused if we allocated one without its knowledge. */
  1551. if (reload_reg_p != 0 && reload_reg_p[valueno] >= 0)
  1552. return 0;
  1553. /* Now verify that the values of GOAL and VALUE remain unaltered
  1554. until INSN is reached. */
  1555. p = insn;
  1556. while (1)
  1557. {
  1558. p = PREV_INSN (p);
  1559. if (p == where)
  1560. return value;
  1561. /* Don't trust the conversion past a function call
  1562. if either of the two is in a call-clobbered register. */
  1563. if (GET_CODE (p) == CALL_INSN
  1564. && ((regno >= 0 && call_clobbered_regs[regno])
  1565. || (valueno >= 0 && call_clobbered_regs[valueno])))
  1566. return 0;
  1567. if (GET_CODE (p) == INSN || GET_CODE (p) == JUMP_INSN
  1568. || GET_CODE (p) == CALL_INSN)
  1569. {
  1570. /* If this insn P stores in either REG or VALUE, return 0. */
  1571. pat = PATTERN (p);
  1572. if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
  1573. {
  1574. register rtx dest = SET_DEST (pat);
  1575. while (GET_CODE (dest) == SUBREG
  1576. || GET_CODE (dest) == VOLATILE
  1577. || GET_CODE (dest) == ZERO_EXTRACT
  1578. || GET_CODE (dest) == SIGN_EXTRACT
  1579. || GET_CODE (dest) == STRICT_LOW_PART)
  1580. dest = XEXP (dest, 0);
  1581. if (GET_CODE (dest) == REG)
  1582. {
  1583. register int xregno = REGNO (dest);
  1584. if (reg_renumber[xregno] >= 0)
  1585. xregno = reg_renumber[xregno];
  1586. if (xregno == regno || xregno == valueno)
  1587. return 0;
  1588. }
  1589. }
  1590. else if (GET_CODE (pat) == PARALLEL)
  1591. {
  1592. register int i;
  1593. for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
  1594. {
  1595. register rtx v1 = XVECEXP (pat, 0, i);
  1596. if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
  1597. {
  1598. register rtx dest = SET_DEST (v1);
  1599. while (GET_CODE (dest) == SUBREG
  1600. || GET_CODE (dest) == VOLATILE
  1601. || GET_CODE (dest) == ZERO_EXTRACT
  1602. || GET_CODE (dest) == SIGN_EXTRACT
  1603. || GET_CODE (dest) == STRICT_LOW_PART)
  1604. dest = XEXP (dest, 0);
  1605. if (GET_CODE (dest) == REG)
  1606. {
  1607. register int xregno = REGNO (dest);
  1608. if (reg_renumber[xregno] >= 0)
  1609. xregno = reg_renumber[xregno];
  1610. if (xregno == regno || xregno == valueno)
  1611. return 0;
  1612. }
  1613. }
  1614. }
  1615. }
  1616. /* If this insn auto-increments or auto-decrements
  1617. either regno or valueno, return 0 now. */
  1618. {
  1619. register rtx link;
  1620. for (link = REG_NOTES (p); link; link = XEXP (link, 1))
  1621. if ((enum reg_note) GET_MODE (link) == REG_INC)
  1622. {
  1623. register int incno = REGNO (XEXP (link, 0));
  1624. if (reg_renumber[incno] >= 0)
  1625. incno = reg_renumber[incno];
  1626. if (incno == regno || incno == valueno)
  1627. return 0;
  1628. }
  1629. }
  1630. }
  1631. }
  1632. }
  1633. /* Find a place where INCED appears in an increment or decrement operator
  1634. within X, and return the amount INCED is incremented by
  1635. (negative if decremented). */
  1636. static int
  1637. find_inc_amount (x, inced)
  1638. rtx x, inced;
  1639. {
  1640. register enum rtx_code code = GET_CODE (x);
  1641. register char *fmt;
  1642. register int i;
  1643. if (code == MEM)
  1644. {
  1645. register rtx addr = XEXP (x, 0);
  1646. if ((GET_CODE (addr) == PRE_DEC
  1647. || GET_CODE (addr) == POST_DEC)
  1648. && XEXP (addr, 0) == inced)
  1649. return - GET_MODE_SIZE (GET_MODE (x));
  1650. if ((GET_CODE (addr) == PRE_INC
  1651. || GET_CODE (addr) == POST_INC)
  1652. && XEXP (addr, 0) == inced)
  1653. return GET_MODE_SIZE (GET_MODE (x));
  1654. }
  1655. fmt = GET_RTX_FORMAT (code);
  1656. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1657. {
  1658. if (fmt[i] == 'e')
  1659. {
  1660. register int tem = find_inc_amount (XEXP (x, i), inced);
  1661. if (tem != 0)
  1662. return tem;
  1663. }
  1664. if (fmt[i] == 'E')
  1665. {
  1666. register int j;
  1667. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1668. {
  1669. register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
  1670. if (tem != 0)
  1671. return tem;
  1672. }
  1673. }
  1674. }
  1675. return 0;
  1676. }