sched-vis.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. /* Printing of RTL in "slim", mnemonic like form.
  2. Copyright (C) 1992-2015 Free Software Foundation, Inc.
  3. Contributed by Michael Tiemann (tiemann@cygnus.com) Enhanced by,
  4. and currently maintained by, Jim Wilson (wilson@cygnus.com)
  5. This file is part of GCC.
  6. GCC is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation; either version 3, or (at your option) any later
  9. version.
  10. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GCC; see the file COPYING3. If not see
  16. <http://www.gnu.org/licenses/>. */
  17. /* Historically this form of RTL dumping was introduced along with
  18. the Haifa instruction scheduling pass, hence the name of this file.
  19. But there is nothing in this file left that is scheduler-specific. */
  20. #include "config.h"
  21. #include "system.h"
  22. #include "coretypes.h"
  23. #include "tm.h"
  24. #include "rtl.h"
  25. #include "hash-set.h"
  26. #include "machmode.h"
  27. #include "vec.h"
  28. #include "double-int.h"
  29. #include "input.h"
  30. #include "alias.h"
  31. #include "symtab.h"
  32. #include "wide-int.h"
  33. #include "inchash.h"
  34. #include "tree.h" /* FIXME: To dump INSN_VAR_LOCATION_DECL. */
  35. #include "predict.h"
  36. #include "vec.h"
  37. #include "hashtab.h"
  38. #include "hash-set.h"
  39. #include "machmode.h"
  40. #include "hard-reg-set.h"
  41. #include "input.h"
  42. #include "function.h"
  43. #include "dominance.h"
  44. #include "cfg.h"
  45. #include "basic-block.h"
  46. #include "dumpfile.h" /* for the TDF_* flags */
  47. #include "pretty-print.h"
  48. /* The functions in this file try to print RTL in a form resembling assembler
  49. mnemonics. Because this form is more concise than the "traditional" form
  50. of RTL printing in Lisp-style, the form printed by this file is called
  51. "slim". RTL dumps in slim format can be obtained by appending the "-slim"
  52. option to -fdump-rtl-<pass>. Control flow graph output as a DOT file is
  53. always printed in slim form.
  54. The normal interface to the functionality provided in this pretty-printer
  55. is through the dump_*_slim functions to print to a stream, or via the
  56. print_*_slim functions to print into a user's pretty-printer.
  57. It is also possible to obtain a string for a single pattern as a string
  58. pointer, via str_pattern_slim, but this usage is discouraged. */
  59. /* For insns we print patterns, and for some patterns we print insns... */
  60. static void print_insn_with_notes (pretty_printer *, const_rtx);
  61. /* This recognizes rtx'en classified as expressions. These are always
  62. represent some action on values or results of other expression, that
  63. may be stored in objects representing values. */
  64. static void
  65. print_exp (pretty_printer *pp, const_rtx x, int verbose)
  66. {
  67. const char *st[4];
  68. const char *fun;
  69. rtx op[4];
  70. int i;
  71. fun = (char *) 0;
  72. for (i = 0; i < 4; i++)
  73. {
  74. st[i] = (char *) 0;
  75. op[i] = NULL_RTX;
  76. }
  77. switch (GET_CODE (x))
  78. {
  79. case PLUS:
  80. op[0] = XEXP (x, 0);
  81. if (CONST_INT_P (XEXP (x, 1))
  82. && INTVAL (XEXP (x, 1)) < 0)
  83. {
  84. st[1] = "-";
  85. op[1] = GEN_INT (-INTVAL (XEXP (x, 1)));
  86. }
  87. else
  88. {
  89. st[1] = "+";
  90. op[1] = XEXP (x, 1);
  91. }
  92. break;
  93. case LO_SUM:
  94. op[0] = XEXP (x, 0);
  95. st[1] = "+low(";
  96. op[1] = XEXP (x, 1);
  97. st[2] = ")";
  98. break;
  99. case MINUS:
  100. op[0] = XEXP (x, 0);
  101. st[1] = "-";
  102. op[1] = XEXP (x, 1);
  103. break;
  104. case COMPARE:
  105. fun = "cmp";
  106. op[0] = XEXP (x, 0);
  107. op[1] = XEXP (x, 1);
  108. break;
  109. case NEG:
  110. st[0] = "-";
  111. op[0] = XEXP (x, 0);
  112. break;
  113. case FMA:
  114. st[0] = "{";
  115. op[0] = XEXP (x, 0);
  116. st[1] = "*";
  117. op[1] = XEXP (x, 1);
  118. st[2] = "+";
  119. op[2] = XEXP (x, 2);
  120. st[3] = "}";
  121. break;
  122. case MULT:
  123. op[0] = XEXP (x, 0);
  124. st[1] = "*";
  125. op[1] = XEXP (x, 1);
  126. break;
  127. case DIV:
  128. op[0] = XEXP (x, 0);
  129. st[1] = "/";
  130. op[1] = XEXP (x, 1);
  131. break;
  132. case UDIV:
  133. fun = "udiv";
  134. op[0] = XEXP (x, 0);
  135. op[1] = XEXP (x, 1);
  136. break;
  137. case MOD:
  138. op[0] = XEXP (x, 0);
  139. st[1] = "%";
  140. op[1] = XEXP (x, 1);
  141. break;
  142. case UMOD:
  143. fun = "umod";
  144. op[0] = XEXP (x, 0);
  145. op[1] = XEXP (x, 1);
  146. break;
  147. case SMIN:
  148. fun = "smin";
  149. op[0] = XEXP (x, 0);
  150. op[1] = XEXP (x, 1);
  151. break;
  152. case SMAX:
  153. fun = "smax";
  154. op[0] = XEXP (x, 0);
  155. op[1] = XEXP (x, 1);
  156. break;
  157. case UMIN:
  158. fun = "umin";
  159. op[0] = XEXP (x, 0);
  160. op[1] = XEXP (x, 1);
  161. break;
  162. case UMAX:
  163. fun = "umax";
  164. op[0] = XEXP (x, 0);
  165. op[1] = XEXP (x, 1);
  166. break;
  167. case NOT:
  168. st[0] = "!";
  169. op[0] = XEXP (x, 0);
  170. break;
  171. case AND:
  172. op[0] = XEXP (x, 0);
  173. st[1] = "&";
  174. op[1] = XEXP (x, 1);
  175. break;
  176. case IOR:
  177. op[0] = XEXP (x, 0);
  178. st[1] = "|";
  179. op[1] = XEXP (x, 1);
  180. break;
  181. case XOR:
  182. op[0] = XEXP (x, 0);
  183. st[1] = "^";
  184. op[1] = XEXP (x, 1);
  185. break;
  186. case ASHIFT:
  187. op[0] = XEXP (x, 0);
  188. st[1] = "<<";
  189. op[1] = XEXP (x, 1);
  190. break;
  191. case LSHIFTRT:
  192. op[0] = XEXP (x, 0);
  193. st[1] = " 0>>";
  194. op[1] = XEXP (x, 1);
  195. break;
  196. case ASHIFTRT:
  197. op[0] = XEXP (x, 0);
  198. st[1] = ">>";
  199. op[1] = XEXP (x, 1);
  200. break;
  201. case ROTATE:
  202. op[0] = XEXP (x, 0);
  203. st[1] = "<-<";
  204. op[1] = XEXP (x, 1);
  205. break;
  206. case ROTATERT:
  207. op[0] = XEXP (x, 0);
  208. st[1] = ">->";
  209. op[1] = XEXP (x, 1);
  210. break;
  211. case NE:
  212. op[0] = XEXP (x, 0);
  213. st[1] = "!=";
  214. op[1] = XEXP (x, 1);
  215. break;
  216. case EQ:
  217. op[0] = XEXP (x, 0);
  218. st[1] = "==";
  219. op[1] = XEXP (x, 1);
  220. break;
  221. case GE:
  222. op[0] = XEXP (x, 0);
  223. st[1] = ">=";
  224. op[1] = XEXP (x, 1);
  225. break;
  226. case GT:
  227. op[0] = XEXP (x, 0);
  228. st[1] = ">";
  229. op[1] = XEXP (x, 1);
  230. break;
  231. case LE:
  232. op[0] = XEXP (x, 0);
  233. st[1] = "<=";
  234. op[1] = XEXP (x, 1);
  235. break;
  236. case LT:
  237. op[0] = XEXP (x, 0);
  238. st[1] = "<";
  239. op[1] = XEXP (x, 1);
  240. break;
  241. case SIGN_EXTRACT:
  242. fun = (verbose) ? "sign_extract" : "sxt";
  243. op[0] = XEXP (x, 0);
  244. op[1] = XEXP (x, 1);
  245. op[2] = XEXP (x, 2);
  246. break;
  247. case ZERO_EXTRACT:
  248. fun = (verbose) ? "zero_extract" : "zxt";
  249. op[0] = XEXP (x, 0);
  250. op[1] = XEXP (x, 1);
  251. op[2] = XEXP (x, 2);
  252. break;
  253. case SIGN_EXTEND:
  254. fun = (verbose) ? "sign_extend" : "sxn";
  255. op[0] = XEXP (x, 0);
  256. break;
  257. case ZERO_EXTEND:
  258. fun = (verbose) ? "zero_extend" : "zxn";
  259. op[0] = XEXP (x, 0);
  260. break;
  261. case FLOAT_EXTEND:
  262. fun = (verbose) ? "float_extend" : "fxn";
  263. op[0] = XEXP (x, 0);
  264. break;
  265. case TRUNCATE:
  266. fun = (verbose) ? "trunc" : "trn";
  267. op[0] = XEXP (x, 0);
  268. break;
  269. case FLOAT_TRUNCATE:
  270. fun = (verbose) ? "float_trunc" : "ftr";
  271. op[0] = XEXP (x, 0);
  272. break;
  273. case FLOAT:
  274. fun = (verbose) ? "float" : "flt";
  275. op[0] = XEXP (x, 0);
  276. break;
  277. case UNSIGNED_FLOAT:
  278. fun = (verbose) ? "uns_float" : "ufl";
  279. op[0] = XEXP (x, 0);
  280. break;
  281. case FIX:
  282. fun = "fix";
  283. op[0] = XEXP (x, 0);
  284. break;
  285. case UNSIGNED_FIX:
  286. fun = (verbose) ? "uns_fix" : "ufx";
  287. op[0] = XEXP (x, 0);
  288. break;
  289. case PRE_DEC:
  290. st[0] = "--";
  291. op[0] = XEXP (x, 0);
  292. break;
  293. case PRE_INC:
  294. st[0] = "++";
  295. op[0] = XEXP (x, 0);
  296. break;
  297. case POST_DEC:
  298. op[0] = XEXP (x, 0);
  299. st[1] = "--";
  300. break;
  301. case POST_INC:
  302. op[0] = XEXP (x, 0);
  303. st[1] = "++";
  304. break;
  305. case PRE_MODIFY:
  306. st[0] = "pre ";
  307. op[0] = XEXP (XEXP (x, 1), 0);
  308. st[1] = "+=";
  309. op[1] = XEXP (XEXP (x, 1), 1);
  310. break;
  311. case POST_MODIFY:
  312. st[0] = "post ";
  313. op[0] = XEXP (XEXP (x, 1), 0);
  314. st[1] = "+=";
  315. op[1] = XEXP (XEXP (x, 1), 1);
  316. break;
  317. case CALL:
  318. st[0] = "call ";
  319. op[0] = XEXP (x, 0);
  320. if (verbose)
  321. {
  322. st[1] = " argc:";
  323. op[1] = XEXP (x, 1);
  324. }
  325. break;
  326. case IF_THEN_ELSE:
  327. st[0] = "{(";
  328. op[0] = XEXP (x, 0);
  329. st[1] = ")?";
  330. op[1] = XEXP (x, 1);
  331. st[2] = ":";
  332. op[2] = XEXP (x, 2);
  333. st[3] = "}";
  334. break;
  335. case TRAP_IF:
  336. fun = "trap_if";
  337. op[0] = TRAP_CONDITION (x);
  338. break;
  339. case PREFETCH:
  340. fun = "prefetch";
  341. op[0] = XEXP (x, 0);
  342. op[1] = XEXP (x, 1);
  343. op[2] = XEXP (x, 2);
  344. break;
  345. case UNSPEC:
  346. case UNSPEC_VOLATILE:
  347. {
  348. pp_string (pp, "unspec");
  349. if (GET_CODE (x) == UNSPEC_VOLATILE)
  350. pp_string (pp, "/v");
  351. pp_left_bracket (pp);
  352. for (i = 0; i < XVECLEN (x, 0); i++)
  353. {
  354. if (i != 0)
  355. pp_comma (pp);
  356. print_pattern (pp, XVECEXP (x, 0, i), verbose);
  357. }
  358. pp_string (pp, "] ");
  359. pp_decimal_int (pp, XINT (x, 1));
  360. }
  361. break;
  362. default:
  363. {
  364. /* Most unhandled codes can be printed as pseudo-functions. */
  365. if (GET_RTX_CLASS (GET_CODE (x)) == RTX_UNARY)
  366. {
  367. fun = GET_RTX_NAME (GET_CODE (x));
  368. op[0] = XEXP (x, 0);
  369. }
  370. else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_COMPARE
  371. || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_COMPARE
  372. || GET_RTX_CLASS (GET_CODE (x)) == RTX_BIN_ARITH
  373. || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_ARITH)
  374. {
  375. fun = GET_RTX_NAME (GET_CODE (x));
  376. op[0] = XEXP (x, 0);
  377. op[1] = XEXP (x, 1);
  378. }
  379. else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_TERNARY)
  380. {
  381. fun = GET_RTX_NAME (GET_CODE (x));
  382. op[0] = XEXP (x, 0);
  383. op[1] = XEXP (x, 1);
  384. op[2] = XEXP (x, 2);
  385. }
  386. else
  387. /* Give up, just print the RTX name. */
  388. st[0] = GET_RTX_NAME (GET_CODE (x));
  389. }
  390. break;
  391. }
  392. /* Print this as a function? */
  393. if (fun)
  394. {
  395. pp_string (pp, fun);
  396. pp_left_paren (pp);
  397. }
  398. for (i = 0; i < 4; i++)
  399. {
  400. if (st[i])
  401. pp_string (pp, st[i]);
  402. if (op[i])
  403. {
  404. if (fun && i != 0)
  405. pp_comma (pp);
  406. print_value (pp, op[i], verbose);
  407. }
  408. }
  409. if (fun)
  410. pp_right_paren (pp);
  411. } /* print_exp */
  412. /* Prints rtxes, I customarily classified as values. They're constants,
  413. registers, labels, symbols and memory accesses. */
  414. void
  415. print_value (pretty_printer *pp, const_rtx x, int verbose)
  416. {
  417. char tmp[1024];
  418. if (!x)
  419. {
  420. pp_string (pp, "(nil)");
  421. return;
  422. }
  423. switch (GET_CODE (x))
  424. {
  425. case CONST_INT:
  426. pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX,
  427. (unsigned HOST_WIDE_INT) INTVAL (x));
  428. break;
  429. case CONST_WIDE_INT:
  430. {
  431. const char *sep = "<";
  432. int i;
  433. for (i = CONST_WIDE_INT_NUNITS (x) - 1; i >= 0; i--)
  434. {
  435. pp_string (pp, sep);
  436. sep = ",";
  437. sprintf (tmp, HOST_WIDE_INT_PRINT_HEX,
  438. (unsigned HOST_WIDE_INT) CONST_WIDE_INT_ELT (x, i));
  439. pp_string (pp, tmp);
  440. }
  441. pp_greater (pp);
  442. }
  443. break;
  444. case CONST_DOUBLE:
  445. if (FLOAT_MODE_P (GET_MODE (x)))
  446. {
  447. real_to_decimal (tmp, CONST_DOUBLE_REAL_VALUE (x),
  448. sizeof (tmp), 0, 1);
  449. pp_string (pp, tmp);
  450. }
  451. else
  452. pp_printf (pp, "<%wx,%wx>",
  453. (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x),
  454. (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x));
  455. break;
  456. case CONST_FIXED:
  457. fixed_to_decimal (tmp, CONST_FIXED_VALUE (x), sizeof (tmp));
  458. pp_string (pp, tmp);
  459. break;
  460. case CONST_STRING:
  461. pp_printf (pp, "\"%s\"", XSTR (x, 0));
  462. break;
  463. case SYMBOL_REF:
  464. pp_printf (pp, "`%s'", XSTR (x, 0));
  465. break;
  466. case LABEL_REF:
  467. pp_printf (pp, "L%d", INSN_UID (LABEL_REF_LABEL (x)));
  468. break;
  469. case CONST:
  470. case HIGH:
  471. case STRICT_LOW_PART:
  472. pp_printf (pp, "%s(", GET_RTX_NAME (GET_CODE (x)));
  473. print_value (pp, XEXP (x, 0), verbose);
  474. pp_right_paren (pp);
  475. break;
  476. case REG:
  477. if (REGNO (x) < FIRST_PSEUDO_REGISTER)
  478. {
  479. if (ISDIGIT (reg_names[REGNO (x)][0]))
  480. pp_modulo (pp);
  481. pp_string (pp, reg_names[REGNO (x)]);
  482. }
  483. else
  484. pp_printf (pp, "r%d", REGNO (x));
  485. if (verbose)
  486. pp_printf (pp, ":%s", GET_MODE_NAME (GET_MODE (x)));
  487. break;
  488. case SUBREG:
  489. print_value (pp, SUBREG_REG (x), verbose);
  490. pp_printf (pp, "#%d", SUBREG_BYTE (x));
  491. break;
  492. case SCRATCH:
  493. case CC0:
  494. case PC:
  495. pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
  496. break;
  497. case MEM:
  498. pp_left_bracket (pp);
  499. print_value (pp, XEXP (x, 0), verbose);
  500. pp_right_bracket (pp);
  501. break;
  502. case DEBUG_EXPR:
  503. pp_printf (pp, "D#%i", DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x)));
  504. break;
  505. default:
  506. print_exp (pp, x, verbose);
  507. break;
  508. }
  509. } /* print_value */
  510. /* The next step in insn detalization, its pattern recognition. */
  511. void
  512. print_pattern (pretty_printer *pp, const_rtx x, int verbose)
  513. {
  514. if (! x)
  515. {
  516. pp_string (pp, "(nil)");
  517. return;
  518. }
  519. switch (GET_CODE (x))
  520. {
  521. case SET:
  522. print_value (pp, SET_DEST (x), verbose);
  523. pp_equal (pp);
  524. print_value (pp, SET_SRC (x), verbose);
  525. break;
  526. case RETURN:
  527. case SIMPLE_RETURN:
  528. case EH_RETURN:
  529. pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
  530. break;
  531. case CALL:
  532. print_exp (pp, x, verbose);
  533. break;
  534. case CLOBBER:
  535. case USE:
  536. pp_printf (pp, "%s ", GET_RTX_NAME (GET_CODE (x)));
  537. print_value (pp, XEXP (x, 0), verbose);
  538. break;
  539. case VAR_LOCATION:
  540. pp_string (pp, "loc ");
  541. print_value (pp, PAT_VAR_LOCATION_LOC (x), verbose);
  542. break;
  543. case COND_EXEC:
  544. pp_left_paren (pp);
  545. if (GET_CODE (COND_EXEC_TEST (x)) == NE
  546. && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
  547. print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
  548. else if (GET_CODE (COND_EXEC_TEST (x)) == EQ
  549. && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
  550. {
  551. pp_exclamation (pp);
  552. print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
  553. }
  554. else
  555. print_value (pp, COND_EXEC_TEST (x), verbose);
  556. pp_string (pp, ") ");
  557. print_pattern (pp, COND_EXEC_CODE (x), verbose);
  558. break;
  559. case PARALLEL:
  560. {
  561. int i;
  562. pp_left_brace (pp);
  563. for (i = 0; i < XVECLEN (x, 0); i++)
  564. {
  565. print_pattern (pp, XVECEXP (x, 0, i), verbose);
  566. pp_semicolon (pp);
  567. }
  568. pp_right_brace (pp);
  569. }
  570. break;
  571. case SEQUENCE:
  572. {
  573. const rtx_sequence *seq = as_a <const rtx_sequence *> (x);
  574. pp_string (pp, "sequence{");
  575. if (INSN_P (seq->element (0)))
  576. {
  577. /* Print the sequence insns indented. */
  578. const char * save_print_rtx_head = print_rtx_head;
  579. char indented_print_rtx_head[32];
  580. pp_newline (pp);
  581. gcc_assert (strlen (print_rtx_head) < sizeof (indented_print_rtx_head) - 4);
  582. snprintf (indented_print_rtx_head,
  583. sizeof (indented_print_rtx_head),
  584. "%s ", print_rtx_head);
  585. print_rtx_head = indented_print_rtx_head;
  586. for (int i = 0; i < seq->len (); i++)
  587. print_insn_with_notes (pp, seq->insn (i));
  588. pp_printf (pp, "%s ", save_print_rtx_head);
  589. print_rtx_head = save_print_rtx_head;
  590. }
  591. else
  592. {
  593. for (int i = 0; i < seq->len (); i++)
  594. {
  595. print_pattern (pp, seq->element (i), verbose);
  596. pp_semicolon (pp);
  597. }
  598. }
  599. pp_right_brace (pp);
  600. }
  601. break;
  602. case ASM_INPUT:
  603. pp_printf (pp, "asm {%s}", XSTR (x, 0));
  604. break;
  605. case ADDR_VEC:
  606. for (int i = 0; i < XVECLEN (x, 0); i++)
  607. {
  608. print_value (pp, XVECEXP (x, 0, i), verbose);
  609. pp_semicolon (pp);
  610. }
  611. break;
  612. case ADDR_DIFF_VEC:
  613. for (int i = 0; i < XVECLEN (x, 1); i++)
  614. {
  615. print_value (pp, XVECEXP (x, 1, i), verbose);
  616. pp_semicolon (pp);
  617. }
  618. break;
  619. case TRAP_IF:
  620. pp_string (pp, "trap_if ");
  621. print_value (pp, TRAP_CONDITION (x), verbose);
  622. break;
  623. case UNSPEC:
  624. case UNSPEC_VOLATILE:
  625. /* Fallthru -- leave UNSPECs to print_exp. */
  626. default:
  627. print_value (pp, x, verbose);
  628. }
  629. } /* print_pattern */
  630. /* This is the main function in slim rtl visualization mechanism.
  631. X is an insn, to be printed into PP.
  632. This function tries to print it properly in human-readable form,
  633. resembling assembler mnemonics (instead of the older Lisp-style
  634. form).
  635. If VERBOSE is TRUE, insns are printed with more complete (but
  636. longer) pattern names and with extra information, and prefixed
  637. with their INSN_UIDs. */
  638. void
  639. print_insn (pretty_printer *pp, const_rtx x, int verbose)
  640. {
  641. if (verbose)
  642. {
  643. /* Blech, pretty-print can't print integers with a specified width. */
  644. char uid_prefix[32];
  645. snprintf (uid_prefix, sizeof uid_prefix, " %4d: ", INSN_UID (x));
  646. pp_string (pp, uid_prefix);
  647. }
  648. switch (GET_CODE (x))
  649. {
  650. case INSN:
  651. print_pattern (pp, PATTERN (x), verbose);
  652. break;
  653. case DEBUG_INSN:
  654. {
  655. const char *name = "?";
  656. if (DECL_P (INSN_VAR_LOCATION_DECL (x)))
  657. {
  658. tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (x));
  659. char idbuf[32];
  660. if (id)
  661. name = IDENTIFIER_POINTER (id);
  662. else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x))
  663. == DEBUG_EXPR_DECL)
  664. {
  665. sprintf (idbuf, "D#%i",
  666. DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (x)));
  667. name = idbuf;
  668. }
  669. else
  670. {
  671. sprintf (idbuf, "D.%i",
  672. DECL_UID (INSN_VAR_LOCATION_DECL (x)));
  673. name = idbuf;
  674. }
  675. }
  676. pp_printf (pp, "debug %s => ", name);
  677. if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (x)))
  678. pp_string (pp, "optimized away");
  679. else
  680. print_pattern (pp, INSN_VAR_LOCATION_LOC (x), verbose);
  681. }
  682. break;
  683. case JUMP_INSN:
  684. print_pattern (pp, PATTERN (x), verbose);
  685. break;
  686. case CALL_INSN:
  687. if (GET_CODE (PATTERN (x)) == PARALLEL)
  688. print_pattern (pp, XVECEXP (PATTERN (x), 0, 0), verbose);
  689. else
  690. print_pattern (pp, PATTERN (x), verbose);
  691. break;
  692. case CODE_LABEL:
  693. pp_printf (pp, "L%d:", INSN_UID (x));
  694. break;
  695. case JUMP_TABLE_DATA:
  696. pp_string (pp, "jump_table_data{\n");
  697. print_pattern (pp, PATTERN (x), verbose);
  698. pp_right_brace (pp);
  699. break;
  700. case BARRIER:
  701. pp_string (pp, "barrier");
  702. break;
  703. case NOTE:
  704. {
  705. pp_string (pp, GET_NOTE_INSN_NAME (NOTE_KIND (x)));
  706. switch (NOTE_KIND (x))
  707. {
  708. case NOTE_INSN_EH_REGION_BEG:
  709. case NOTE_INSN_EH_REGION_END:
  710. pp_printf (pp, " %d", NOTE_EH_HANDLER (x));
  711. break;
  712. case NOTE_INSN_BLOCK_BEG:
  713. case NOTE_INSN_BLOCK_END:
  714. pp_printf (pp, " %d", BLOCK_NUMBER (NOTE_BLOCK (x)));
  715. break;
  716. case NOTE_INSN_BASIC_BLOCK:
  717. pp_printf (pp, " %d", NOTE_BASIC_BLOCK (x)->index);
  718. break;
  719. case NOTE_INSN_DELETED_LABEL:
  720. case NOTE_INSN_DELETED_DEBUG_LABEL:
  721. {
  722. const char *label = NOTE_DELETED_LABEL_NAME (x);
  723. if (label == NULL)
  724. label = "";
  725. pp_printf (pp, " (\"%s\")", label);
  726. }
  727. break;
  728. case NOTE_INSN_VAR_LOCATION:
  729. case NOTE_INSN_CALL_ARG_LOCATION:
  730. pp_left_brace (pp);
  731. print_pattern (pp, NOTE_VAR_LOCATION (x), verbose);
  732. pp_right_brace (pp);
  733. break;
  734. default:
  735. break;
  736. }
  737. break;
  738. }
  739. default:
  740. gcc_unreachable ();
  741. }
  742. } /* print_insn */
  743. /* Pretty-print a slim dump of X (an insn) to PP, including any register
  744. note attached to the instruction. */
  745. static void
  746. print_insn_with_notes (pretty_printer *pp, const_rtx x)
  747. {
  748. pp_string (pp, print_rtx_head);
  749. print_insn (pp, x, 1);
  750. pp_newline (pp);
  751. if (INSN_P (x) && REG_NOTES (x))
  752. for (rtx note = REG_NOTES (x); note; note = XEXP (note, 1))
  753. {
  754. pp_printf (pp, "%s %s ", print_rtx_head,
  755. GET_REG_NOTE_NAME (REG_NOTE_KIND (note)));
  756. if (GET_CODE (note) == INT_LIST)
  757. pp_printf (pp, "%d", XINT (note, 0));
  758. else
  759. print_pattern (pp, XEXP (note, 0), 1);
  760. pp_newline (pp);
  761. }
  762. }
  763. /* Print X, an RTL value node, to file F in slim format. Include
  764. additional information if VERBOSE is nonzero.
  765. Value nodes are constants, registers, labels, symbols and
  766. memory. */
  767. void
  768. dump_value_slim (FILE *f, const_rtx x, int verbose)
  769. {
  770. pretty_printer rtl_slim_pp;
  771. rtl_slim_pp.buffer->stream = f;
  772. print_value (&rtl_slim_pp, x, verbose);
  773. pp_flush (&rtl_slim_pp);
  774. }
  775. /* Emit a slim dump of X (an insn) to the file F, including any register
  776. note attached to the instruction. */
  777. void
  778. dump_insn_slim (FILE *f, const_rtx x)
  779. {
  780. pretty_printer rtl_slim_pp;
  781. rtl_slim_pp.buffer->stream = f;
  782. print_insn_with_notes (&rtl_slim_pp, x);
  783. pp_flush (&rtl_slim_pp);
  784. }
  785. /* Same as above, but stop at LAST or when COUNT == 0.
  786. If COUNT < 0 it will stop only at LAST or NULL rtx. */
  787. void
  788. dump_rtl_slim (FILE *f, const rtx_insn *first, const rtx_insn *last,
  789. int count, int flags ATTRIBUTE_UNUSED)
  790. {
  791. const rtx_insn *insn, *tail;
  792. pretty_printer rtl_slim_pp;
  793. rtl_slim_pp.buffer->stream = f;
  794. tail = last ? NEXT_INSN (last) : NULL;
  795. for (insn = first;
  796. (insn != NULL) && (insn != tail) && (count != 0);
  797. insn = NEXT_INSN (insn))
  798. {
  799. print_insn_with_notes (&rtl_slim_pp, insn);
  800. if (count > 0)
  801. count--;
  802. }
  803. pp_flush (&rtl_slim_pp);
  804. }
  805. /* Dumps basic block BB to pretty-printer PP in slim form and without and
  806. no indentation, for use as a label of a DOT graph record-node. */
  807. void
  808. rtl_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
  809. {
  810. rtx_insn *insn;
  811. bool first = true;
  812. /* TODO: inter-bb stuff. */
  813. FOR_BB_INSNS (bb, insn)
  814. {
  815. if (! first)
  816. {
  817. pp_bar (pp);
  818. pp_write_text_to_stream (pp);
  819. }
  820. first = false;
  821. print_insn_with_notes (pp, insn);
  822. pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
  823. }
  824. }
  825. /* Pretty-print pattern X of some insn in non-verbose mode.
  826. Return a string pointer to the pretty-printer buffer.
  827. This function is only exported exists only to accommodate some older users
  828. of the slim RTL pretty printers. Please do not use it for new code. */
  829. const char *
  830. str_pattern_slim (const_rtx x)
  831. {
  832. pretty_printer rtl_slim_pp;
  833. print_pattern (&rtl_slim_pp, x, 0);
  834. return ggc_strdup (pp_formatted_text (&rtl_slim_pp));
  835. }
  836. /* Emit a slim dump of X (an insn) to stderr. */
  837. extern void debug_insn_slim (const_rtx);
  838. DEBUG_FUNCTION void
  839. debug_insn_slim (const_rtx x)
  840. {
  841. dump_insn_slim (stderr, x);
  842. }
  843. /* Same as above, but using dump_rtl_slim. */
  844. extern void debug_rtl_slim (FILE *, const rtx_insn *, const rtx_insn *,
  845. int, int);
  846. DEBUG_FUNCTION void
  847. debug_rtl_slim (const rtx_insn *first, const rtx_insn *last, int count,
  848. int flags)
  849. {
  850. dump_rtl_slim (stderr, first, last, count, flags);
  851. }
  852. extern void debug_bb_slim (basic_block);
  853. DEBUG_FUNCTION void
  854. debug_bb_slim (basic_block bb)
  855. {
  856. dump_bb (stderr, bb, 0, TDF_SLIM | TDF_BLOCKS);
  857. }
  858. extern void debug_bb_n_slim (int);
  859. DEBUG_FUNCTION void
  860. debug_bb_n_slim (int n)
  861. {
  862. basic_block bb = BASIC_BLOCK_FOR_FN (cfun, n);
  863. debug_bb_slim (bb);
  864. }