final.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /* Convert RTL to assembler code and output it, for GNU compiler.
  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 is the final pass of the compiler.
  18. It looks at the rtl code for a function and outputs assembler code.
  19. Final is responsible for changing pseudo-register references
  20. into hard regs or stack slots. This is done by altering the
  21. REG rtx's for the pseudo regs into either hard regs or MEM rtx's.
  22. SUBREG rtx's must also be altered.
  23. Some optimizations are also done at this level.
  24. Move instructions that were made unnecessary by good register allocation
  25. are detected and omitted from the output.
  26. Instructions to set the condition codes are omitted when it can be
  27. seen that the condition codes already had the desired values.
  28. In some cases it is sufficient if the inherited condition codes
  29. have related values, but this may require the following insn
  30. (the one that tests the condition codes) to be modified.
  31. The code for the function prologue and epilogue are generated
  32. directly as assembler code by the macros FUNCTION_PROLOGUE and
  33. FUNCTION_EPILOGUE. Those instructions never exist as rtl. */
  34. #include <stdio.h>
  35. #include <stab.h>
  36. #include "config.h"
  37. #include "rtl.h"
  38. #include "regs.h"
  39. #include "insn-config.h"
  40. #include "recog.h"
  41. #include "conditions.h"
  42. #define min(A,B) ((A) < (B) ? (A) : (B))
  43. void output_asm_insn ();
  44. static void alter_reg ();
  45. static void alter_subreg ();
  46. static int alter_cond ();
  47. static void output_asm_label ();
  48. static void output_operand ();
  49. static void output_address ();
  50. static void output_addr_reg ();
  51. void output_addr_const ();
  52. static char *reg_name[] = REGISTER_NAMES;
  53. /* File in which assembler code is being written. */
  54. static FILE *outfile;
  55. /* All the symbol-blocks (levels of scoping) in the compilation
  56. are assigned sequence numbers in order of appearance of the
  57. beginnings of the symbol-blocks. Both final and dbxout do this,
  58. and assume that they will both give the same number to each block.
  59. Final uses these sequence numbers to generate assembler label names
  60. LBBnnn and LBEnnn for the beginning and end of the symbol-block.
  61. Dbxout uses the sequence nunbers to generate references to the same labels
  62. from the dbx debugging information. */
  63. static next_block_index;
  64. /* This variable contains machine-dependent flags (defined in tm-...h)
  65. set and examined by output routines
  66. that describe how to interpret the condition codes properly. */
  67. CC_STATUS cc_status;
  68. /* Last source file name mentioned in a NOTE insn. */
  69. static char *lastfile;
  70. /* Indexed by hardware reg number, is 1 if that register is ever
  71. used in the current function.
  72. In life_analysis, or in stupid_life_analysis, this is set
  73. up to record the hard regs used explicitly. Reload adds
  74. in the hard regs used for holding pseudo regs. Final uses
  75. it to generate the code in the function prologue and epilogue
  76. to save and restore registers as needed. */
  77. char regs_ever_live[FIRST_PSEUDO_REGISTER];
  78. /* Element N is nonzero if pseudo-reg N is being allocated in memory.
  79. The value of the element is an rtx (MEM ...) to be used
  80. to replace references to pseudo-reg N.
  81. This is set up at the end of global allocation.
  82. These MEM rtx's all have VOIDmode because we do not know the correct mode.
  83. When they are substituted into the code, they will be given the
  84. correct mode, copied from the (REG...) being replaced. */
  85. rtx *reg_spill_replacement;
  86. /* Initialize data in final at the beginning of a compilation. */
  87. void
  88. init_final (filename)
  89. char *filename;
  90. {
  91. next_block_index = 2;
  92. lastfile = filename;
  93. }
  94. /* Main entry point for final pass: output assembler code from rtl.
  95. FIRST is the first insn of the rtl for the function being compiled.
  96. FILE is the file to write assembler code to.
  97. FNNAME is the name of the function being compiled.
  98. WRITE_SYMBOLS is 1 for gdb symbols, 2 for dbx symbols.
  99. OPTIMIZE is nonzero if we should eliminate redundant
  100. test and compare insns. */
  101. void
  102. final (first, file, fnname, write_symbols, optimize)
  103. rtx first;
  104. FILE *file;
  105. char *fnname;
  106. int write_symbols;
  107. int optimize;
  108. {
  109. register rtx insn;
  110. register int i;
  111. /* Length so far allocated in PENDING_BLOCKS. */
  112. int max_depth = 20;
  113. /* Stack of sequence numbers of symbol-blocks of which we have seen the
  114. beginning but not yet the end. Sequence numbers are assigned at
  115. the beginning; this stack allows us to find the sequence number
  116. of a block that is ending. */
  117. int *pending_blocks = (int *) alloca (max_depth * sizeof (int));
  118. /* Number of elements currently in use in PENDING_BLOCKS. */
  119. int depth = 0;
  120. /* Allocate in the stack frame whatever did not make it into a hard reg. */
  121. reg_spill_replacement = (rtx *) alloca (max_regno * sizeof (rtx));
  122. bzero (reg_spill_replacement, max_regno * sizeof (rtx));
  123. /* Parameter copies that didn't get into hardware registers
  124. should be referenced in the parameter list.
  125. For other registers, allocate a local stack slot. */
  126. for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  127. {
  128. if (reg_renumber[i] < 0 && reg_n_refs[i] > 0)
  129. reg_spill_replacement[i]
  130. = assign_stack_local (VOIDmode, PSEUDO_REGNO_BYTES (i));
  131. alter_reg (regno_reg_rtx[i]);
  132. }
  133. init_recog ();
  134. outfile = file;
  135. /* Tell assembler to switch to text segment. */
  136. fprintf (file, "%s\n", TEXT_SECTION_ASM_OP);
  137. /* Tell assembler to move to target machine's alignment for functions. */
  138. ASM_OUTPUT_ALIGN (file, floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT));
  139. /* Output label for the function. */
  140. fprintf (file, "_%s:\n", fnname);
  141. /* Record beginning of the symbol-block that's the entire function. */
  142. /* Is this incorrect now? */
  143. if (write_symbols == 1)
  144. {
  145. pending_blocks[depth++] = next_block_index;
  146. fprintf (file, "\t.gdbbeg %d\n", next_block_index++);
  147. }
  148. /* Initial line number is supposed to be output
  149. before the function's prologue and label
  150. so that the function's address will not appear to be
  151. in the last statement of the preceding function. */
  152. if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
  153. output_source_line (file, first);
  154. #ifdef FUNCTION_PROLOGUE
  155. /* First output the function prologue: code to set up the stack frame. */
  156. FUNCTION_PROLOGUE (file, get_frame_size ());
  157. #endif
  158. CC_STATUS_INIT;
  159. for (insn = NEXT_INSN (first); insn; insn = NEXT_INSN (insn))
  160. {
  161. switch (GET_CODE (insn))
  162. {
  163. case NOTE:
  164. if (! write_symbols)
  165. break;
  166. if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
  167. abort (); /* Obsolete; shouldn't appear */
  168. if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
  169. || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
  170. break;
  171. if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
  172. break; /* An insn that was "deleted" */
  173. if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  174. {
  175. /* Beginning of a symbol-block. Assign it a sequence number
  176. and push the number onto the stack PENDING_BLOCKS. */
  177. if (depth == max_depth)
  178. {
  179. /* PENDING_BLOCKS is full; make it longer. */
  180. register int *new
  181. = (int *) alloca (2 * max_depth * sizeof (int));
  182. bcopy (pending_blocks, new, max_depth * sizeof (int));
  183. pending_blocks = new;
  184. max_depth <<= 1;
  185. }
  186. pending_blocks[depth++] = next_block_index;
  187. /* Output debugging info about the symbol-block beginning. */
  188. if (write_symbols == 2)
  189. fprintf (file, "LBB%d:\n", next_block_index++);
  190. else
  191. fprintf (file, "\t.gdbbeg %d\n", next_block_index++);
  192. }
  193. else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
  194. {
  195. /* End of a symbol-block. Pop its sequence number off
  196. PENDING_BLOCKS and output debugging info based on that. */
  197. if (write_symbols == 2)
  198. {
  199. if (depth > 0)
  200. fprintf (file, "LBE%d:\n", pending_blocks[--depth]);
  201. }
  202. else
  203. fprintf (file, "\t.gdbend %d\n", pending_blocks[--depth]);
  204. }
  205. else
  206. /* This note is a line-number. */
  207. output_source_line (file, insn);
  208. break;
  209. case BARRIER:
  210. break;
  211. case CODE_LABEL:
  212. fprintf (file, "L%d:\n", CODE_LABEL_NUMBER (insn));
  213. CC_STATUS_INIT;
  214. break;
  215. default:
  216. {
  217. register rtx body = PATTERN (insn);
  218. int insn_code_number;
  219. char *template;
  220. /* An INSN, JUMP_INSN or CALL_INSN.
  221. First check for special kinds. */
  222. if (GET_CODE (body) == USE /* These are just declarations */
  223. || GET_CODE (body) == CLOBBER)
  224. break;
  225. if (GET_CODE (body) == ASM_INPUT)
  226. {
  227. output_asm_insn (XSTR (body, 0), 0);
  228. break;
  229. }
  230. /* Detect insns that are really jump-tables
  231. and output them as such. */
  232. if (GET_CODE (body) == ADDR_VEC)
  233. {
  234. enum machine_mode mode = GET_MODE (body);
  235. char *pseudo = (mode == SImode) ? ".int"
  236. : ((mode == HImode) ? ".word" : (char *) abort ());
  237. register int vlen, idx;
  238. vlen = XVECLEN (body, 0);
  239. for (idx = 0; idx < vlen; idx++)
  240. fprintf (file, "\t%s L%d\n", pseudo,
  241. CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
  242. break;
  243. }
  244. if (GET_CODE (body) == ADDR_DIFF_VEC)
  245. {
  246. enum machine_mode mode = GET_MODE (body);
  247. char *pseudo = (mode == SImode) ? ".int"
  248. : ((mode == HImode) ? ".word" : (char *) abort ());
  249. register int vlen, idx;
  250. vlen = XVECLEN (body, 1);
  251. for (idx = 0; idx < vlen; idx++)
  252. fprintf (file, "\t%s L%d-L%d\n", pseudo,
  253. CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
  254. CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
  255. break;
  256. }
  257. /* We have a real machine instruction as rtl. */
  258. body = PATTERN (insn);
  259. /* Detect and ignore no-op move instructions
  260. resulting from not allocating a parameter in a register. */
  261. if (GET_CODE (body) == SET
  262. && (SET_DEST (body) == SET_SRC (body)
  263. || (GET_CODE (SET_DEST (body)) == MEM
  264. && GET_CODE (SET_SRC (body)) == MEM
  265. && (XEXP (SET_DEST (body), 0)
  266. == XEXP (SET_SRC (body), 0))))
  267. && GET_CODE (SET_DEST (body)) != VOLATILE)
  268. break;
  269. /* Detect and ignore no-op move instructions
  270. resulting from smart or fortuitous register allocation. */
  271. if (GET_CODE (body) == SET)
  272. {
  273. if (GET_CODE (SET_DEST (body)) == SUBREG)
  274. alter_subreg (SET_DEST (body));
  275. if (GET_CODE (SET_SRC (body)) == SUBREG)
  276. alter_subreg (SET_SRC (body));
  277. if (GET_CODE (SET_DEST (body)) == REG
  278. && GET_CODE (SET_SRC (body)) == REG)
  279. {
  280. rtx tem;
  281. if (REGNO (SET_DEST (body))
  282. == REGNO (SET_SRC (body)))
  283. break;
  284. tem = find_equiv_reg (SET_DEST (body), insn, 0,
  285. REGNO (SET_SRC (body)), 0);
  286. if (tem != 0
  287. && GET_MODE (tem) == GET_MODE (SET_DEST (body)))
  288. break;
  289. }
  290. }
  291. /* Check for redundant test and compare instructions
  292. (when the condition codes are already set up as desired).
  293. This is done only when optimizing; if not optimizing,
  294. it should be possible for the user to alter a variable
  295. with the debugger in between statements
  296. and the next statement should reexamine the variable
  297. to compute the condition codes. */
  298. if (optimize
  299. && GET_CODE (body) == SET
  300. && GET_CODE (SET_DEST (body)) == CC0)
  301. {
  302. if (GET_CODE (SET_SRC (body)) == SUBREG)
  303. alter_subreg (SET_SRC (body));
  304. if ((cc_status.value1 != 0
  305. && rtx_equal_p (SET_SRC (body), cc_status.value1))
  306. || (cc_status.value2 != 0
  307. && rtx_equal_p (SET_SRC (body), cc_status.value2)))
  308. break;
  309. }
  310. /* If this is a conditional branch, maybe modify it
  311. if the cc's are in a nonstandard state
  312. so that it accomplishes the same thing that it would
  313. do straightforwardly if the cc's were set up normally. */
  314. if (cc_status.flags != 0
  315. && GET_CODE (insn) == JUMP_INSN
  316. && GET_CODE (body) == SET
  317. && SET_DEST (body) == pc_rtx
  318. && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE)
  319. {
  320. /* This function may alter the contents of its argument
  321. and clear some of the cc_status.flags bits.
  322. It may also return 1 meaning condition now always true
  323. or -1 meaning condition now always false
  324. or 2 meaning condition nontrivial but altered. */
  325. register int result = alter_cond (XEXP (SET_SRC (body), 0));
  326. /* If condition now has fixed value, replace the IF_THEN_ELSE
  327. with its then-operand or its else-operand. */
  328. if (result == 1)
  329. SET_SRC (body) = XEXP (SET_SRC (body), 1);
  330. if (result == -1)
  331. SET_SRC (body) = XEXP (SET_SRC (body), 2);
  332. /* The jump is now either unconditional or a no-op.
  333. If it has become a no-op, don't try to output it.
  334. (It would not be recognized.) */
  335. if (SET_SRC (body) == pc_rtx)
  336. continue;
  337. /* Rerecognize the instruction if it has changed. */
  338. if (result != 0)
  339. INSN_CODE (insn) = -1;
  340. }
  341. /* Make same adjustments to instructions that examine the
  342. condition codes without jumping. */
  343. if (cc_status.flags != 0
  344. && GET_CODE (body) == SET)
  345. switch (GET_CODE (SET_SRC (body)))
  346. {
  347. case GTU:
  348. case GT:
  349. case LTU:
  350. case LT:
  351. case GEU:
  352. case GE:
  353. case LEU:
  354. case LE:
  355. case EQ:
  356. case NE:
  357. {
  358. register int result = alter_cond (SET_SRC (body));
  359. if (result == 1)
  360. SET_SRC (body) = gen_rtx (CONST_INT, VOIDmode, -1);
  361. if (result == -1)
  362. SET_SRC (body) = const0_rtx;
  363. if (result != 0)
  364. INSN_CODE (insn) = -1;
  365. }
  366. }
  367. /* Try to recognize the instruction.
  368. If successful, verify that the operands satisfy the
  369. constraints for the instruction. Crash if they don't,
  370. since `reload' should have changed them so that they do. */
  371. insn_code_number = recog_memoized (insn);
  372. insn_extract (insn);
  373. for (i = 0; i < insn_n_operands[insn_code_number]; i++)
  374. if (GET_CODE (recog_operand[i]) == SUBREG)
  375. alter_subreg (recog_operand[i]);
  376. #ifdef REGISTER_CONSTRAINTS
  377. if (! constrain_operands (insn_code_number))
  378. abort ();
  379. #endif
  380. /* Update `cc_status' for this instruction.
  381. The instruction's output routine may change it further.
  382. This should be a no-op for jump instructions
  383. because their output routines may need to examine `cc_status',
  384. below. That's ok since jump insns don't normally alter
  385. the condition codes. */
  386. NOTICE_UPDATE_CC (body);
  387. /* If the proper template needs to be chosen by some C code,
  388. run that code and get the real template.
  389. In this case the template we were passed
  390. consists of * and a decimal number.
  391. The number is used to select which case is run,
  392. in output_insn_hairy, a machine-generated function
  393. that all the C code for these situations is written into. */
  394. template = insn_template[insn_code_number];
  395. if (template == 0)
  396. template = output_insn_hairy (insn_code_number,
  397. recog_operand, insn);
  398. /* Output assembler code from the template. */
  399. output_asm_insn (template, recog_operand);
  400. }
  401. }
  402. }
  403. #ifdef FUNCTION_EPILOGUE
  404. /* Finally, output the function epilogue:
  405. code to restore the stack frame and return to the caller. */
  406. FUNCTION_EPILOGUE (file, get_frame_size ());
  407. #endif
  408. /* If FUNCTION_EPILOGUE is not defined, then the function body
  409. itself contains return instructions wherever needed. */
  410. }
  411. /* Output debugging info to the assembler file
  412. based on the NOTE insn INSN, assumed to be a line number. */
  413. output_source_line (file, insn)
  414. FILE *file;
  415. rtx insn;
  416. {
  417. register char *filename = NOTE_SOURCE_FILE (insn);
  418. if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
  419. fprintf (file, "\t.stabs \"%s\",%d,0,0,Ltext\n",
  420. filename, N_SOL);
  421. lastfile = filename;
  422. fprintf (file, "\t.stabd %d,0,%d\n",
  423. N_SLINE, NOTE_LINE_NUMBER (insn));
  424. }
  425. /* Replace all pseudo regs in *X with their allocated homes:
  426. either a hard reg found in reg_renumber
  427. or a memory location found in reg_spill_replacement. */
  428. static void
  429. alter_subreg (x)
  430. register rtx x;
  431. {
  432. register rtx y = SUBREG_REG (x);
  433. if (GET_CODE (y) == SUBREG)
  434. alter_subreg (y);
  435. if (GET_CODE (y) == REG)
  436. {
  437. /* If the containing reg really gets a hard reg, so do we. */
  438. PUT_CODE (x, REG);
  439. REGNO (x) = REGNO (y) + SUBREG_WORD (x);
  440. }
  441. else if (GET_CODE (y) == MEM)
  442. {
  443. register int offset = SUBREG_WORD (x) * BITS_PER_WORD;
  444. #ifdef BYTES_BIG_ENDIAN
  445. if (GET_MODE_SIZE (GET_MODE (x)) < UNITS_PER_WORD)
  446. offset -= (GET_MODE_SIZE (GET_MODE (x))
  447. - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
  448. #endif
  449. PUT_CODE (x, MEM);
  450. XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
  451. }
  452. }
  453. static void
  454. alter_reg (reg)
  455. rtx reg;
  456. {
  457. register int regno = REGNO (reg);
  458. if (reg_spill_replacement[regno] != 0)
  459. {
  460. PUT_CODE (reg, MEM);
  461. XEXP (reg, 0) = XEXP (reg_spill_replacement[regno], 0);
  462. }
  463. else
  464. REGNO (reg) = reg_renumber[regno];
  465. return;
  466. }
  467. /* Given BODY, the body of a jump instruction, alter the jump condition
  468. as required by the bits that are set in cc_status.flags.
  469. Not all of the bits there can be handled at this level in all cases.
  470. The bits that are taken care of here are cleared.
  471. The value is normally 0.
  472. In this case, COND itself has usually been altered.
  473. 1 means that the condition has become always true.
  474. -1 means that the condition has become always false. */
  475. static int
  476. alter_cond (cond)
  477. register rtx cond;
  478. {
  479. int value = 0;
  480. if (cc_status.flags & CC_REVERSED)
  481. {
  482. value = 2;
  483. switch (GET_CODE (cond))
  484. {
  485. case LE:
  486. PUT_CODE (cond, GE);
  487. break;
  488. case GE:
  489. PUT_CODE (cond, LE);
  490. break;
  491. case LT:
  492. PUT_CODE (cond, GT);
  493. break;
  494. case GT:
  495. PUT_CODE (cond, LT);
  496. break;
  497. case LEU:
  498. PUT_CODE (cond, GEU);
  499. break;
  500. case GEU:
  501. PUT_CODE (cond, LEU);
  502. break;
  503. case LTU:
  504. PUT_CODE (cond, GTU);
  505. break;
  506. case GTU:
  507. PUT_CODE (cond, LTU);
  508. break;
  509. }
  510. }
  511. if (cond != 0 && cc_status.flags & CC_NOT_POSITIVE)
  512. switch (GET_CODE (cond))
  513. {
  514. case LE:
  515. case LEU:
  516. case GEU:
  517. /* Jump becomes unconditional. */
  518. return 1;
  519. case GT:
  520. case GTU:
  521. case LTU:
  522. /* Jump becomes no-op. */
  523. return -1;
  524. case GE:
  525. PUT_CODE (cond, EQ);
  526. value = 2;
  527. break;
  528. case LT:
  529. PUT_CODE (cond, NE);
  530. value = 2;
  531. break;
  532. }
  533. if (cond != 0 && cc_status.flags & CC_NOT_NEGATIVE)
  534. switch (GET_CODE (cond))
  535. {
  536. case GE:
  537. case GEU:
  538. /* Jump becomes unconditional. */
  539. return 1;
  540. case LT:
  541. case LTU:
  542. /* Jump becomes no-op. */
  543. return -1;
  544. case LE:
  545. case LEU:
  546. PUT_CODE (cond, EQ);
  547. value = 2;
  548. break;
  549. case GT:
  550. case GTU:
  551. PUT_CODE (cond, NE);
  552. value = 2;
  553. break;
  554. }
  555. if (cond != 0 && cc_status.flags & CC_NO_OVERFLOW)
  556. switch (GET_CODE (cond))
  557. {
  558. case GEU:
  559. /* Jump becomes unconditional. */
  560. return 1;
  561. case LEU:
  562. PUT_CODE (cond, EQ);
  563. value = 2;
  564. break;
  565. case GTU:
  566. PUT_CODE (cond, NE);
  567. value = 2;
  568. break;
  569. case LTU:
  570. /* Jump becomes no-op. */
  571. return -1;
  572. }
  573. return value;
  574. }
  575. /* Output of assembler code from a template, and its subroutines. */
  576. /* Output text from TEMPLATE to the assembler output file,
  577. obeying %-directions to substitute operands taken from
  578. the vector OPERANDS.
  579. %N (for N a digit) means print operand N in usual manner.
  580. %lN means require operand N to be a CODE_LABEL or LABEL_REF
  581. and print the label name with no punctuation.
  582. %cN means require operand N to be a constant
  583. and print the constant expression with no punctuation.
  584. %aN means expect operand N to be a memory address
  585. (not a memory reference!) and print a reference
  586. to that address.
  587. %nN means expect operand N to be a constant
  588. and print a constant expression for minus the value
  589. of the operand, with no other punctuation. */
  590. void
  591. output_asm_insn (template, operands)
  592. char *template;
  593. rtx *operands;
  594. {
  595. register char *p;
  596. register int c;
  597. p = template;
  598. putc ('\t', outfile);
  599. while (c = *p++)
  600. {
  601. if (c != '%')
  602. putc (c, outfile);
  603. else
  604. {
  605. if (*p == 'l')
  606. {
  607. c = atoi (++p);
  608. output_asm_label (operands[c]);
  609. }
  610. else if (*p == 'c')
  611. {
  612. c = atoi (++p);
  613. output_addr_const (outfile, operands[c]);
  614. }
  615. else if (*p == 'a')
  616. {
  617. c = atoi (++p);
  618. output_address (operands[c]);
  619. }
  620. else if (*p == 'n')
  621. {
  622. c = atoi (++p);
  623. if (GET_CODE (operands[c]) == CONST_INT)
  624. fprintf (outfile, "%d", - INTVAL (operands[c]));
  625. else
  626. {
  627. putc ('-', outfile);
  628. output_addr_const (operands[c]);
  629. }
  630. }
  631. else
  632. {
  633. c = atoi (p);
  634. output_operand (operands[c]);
  635. }
  636. while ((c = *p) >= '0' && c <= '9') p++;
  637. }
  638. }
  639. putc ('\n', outfile);
  640. }
  641. static void
  642. output_asm_label (x)
  643. rtx x;
  644. {
  645. if (GET_CODE (x) == LABEL_REF)
  646. fprintf (outfile, "L%d", CODE_LABEL_NUMBER (XEXP (x, 0)));
  647. else if (GET_CODE (x) == CODE_LABEL)
  648. fprintf (outfile, "L%d", CODE_LABEL_NUMBER (x));
  649. else
  650. abort ();
  651. }
  652. /* Print operand X using machine-dependent assembler syntax.
  653. The macro PRINT_OPERAND is defined just to control this function. */
  654. static void
  655. output_operand (x)
  656. rtx x;
  657. {
  658. if (GET_CODE (x) == SUBREG)
  659. alter_subreg (x);
  660. PRINT_OPERAND (outfile, x);
  661. }
  662. /* Print a memory reference operand for address X
  663. using machine-dependent assembler syntax.
  664. The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
  665. static void
  666. output_address (x)
  667. rtx x;
  668. {
  669. if (GET_CODE (x) == SUBREG)
  670. alter_subreg (x);
  671. PRINT_OPERAND_ADDRESS (outfile, x);
  672. }
  673. /* Print an integer constant expression in assembler syntax.
  674. Addition and subtraction are the only arithmetic
  675. that may appear in these expressions. */
  676. void
  677. output_addr_const (file, x)
  678. FILE *file;
  679. rtx x;
  680. {
  681. restart:
  682. switch (GET_CODE (x))
  683. {
  684. case SYMBOL_REF:
  685. if (XSTR (x, 0)[0] == '*')
  686. fprintf (file, "%s", XSTR (x, 0) + 1);
  687. else
  688. fprintf (file, "_%s", XSTR (x, 0));
  689. break;
  690. case LABEL_REF:
  691. fprintf (file, "L%d", CODE_LABEL_NUMBER (XEXP (x, 0)));
  692. break;
  693. case CODE_LABEL:
  694. fprintf (file, "L%d", CODE_LABEL_NUMBER (x));
  695. break;
  696. case CONST_INT:
  697. fprintf (file, "%d", INTVAL (x));
  698. break;
  699. case CONST:
  700. x = XEXP (x, 0);
  701. goto restart;
  702. case PLUS:
  703. output_addr_const (file, XEXP (x, 0));
  704. fprintf (file, "+");
  705. output_addr_const (file, XEXP (x, 1));
  706. break;
  707. case MINUS:
  708. output_addr_const (file, XEXP (x, 0));
  709. fprintf (file, "-");
  710. output_addr_const (file, XEXP (x, 1));
  711. break;
  712. default:
  713. abort ();
  714. }
  715. }