PageRenderTime 75ms CodeModel.GetById 28ms RepoModel.GetById 2ms app.codeStats 1ms

/mingw-w64-v2.0.999/gcc/src/gcc/df-core.c

#
C | 2286 lines | 1357 code | 326 blank | 603 comment | 189 complexity | 614ee616c7371163a9ed9ddbe72c3b30 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, LGPL-3.0, Unlicense, GPL-2.0, LGPL-2.0, BSD-3-Clause, GPL-3.0
  1. /* Allocation for dataflow support routines.
  2. Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
  3. 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
  4. Originally contributed by Michael P. Hayes
  5. (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
  6. Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
  7. and Kenneth Zadeck (zadeck@naturalbridge.com).
  8. This file is part of GCC.
  9. GCC is free software; you can redistribute it and/or modify it under
  10. the terms of the GNU General Public License as published by the Free
  11. Software Foundation; either version 3, or (at your option) any later
  12. version.
  13. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  14. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with GCC; see the file COPYING3. If not see
  19. <http://www.gnu.org/licenses/>. */
  20. /*
  21. OVERVIEW:
  22. The files in this collection (df*.c,df.h) provide a general framework
  23. for solving dataflow problems. The global dataflow is performed using
  24. a good implementation of iterative dataflow analysis.
  25. The file df-problems.c provides problem instance for the most common
  26. dataflow problems: reaching defs, upward exposed uses, live variables,
  27. uninitialized variables, def-use chains, and use-def chains. However,
  28. the interface allows other dataflow problems to be defined as well.
  29. Dataflow analysis is available in most of the rtl backend (the parts
  30. between pass_df_initialize and pass_df_finish). It is quite likely
  31. that these boundaries will be expanded in the future. The only
  32. requirement is that there be a correct control flow graph.
  33. There are three variations of the live variable problem that are
  34. available whenever dataflow is available. The LR problem finds the
  35. areas that can reach a use of a variable, the UR problems finds the
  36. areas that can be reached from a definition of a variable. The LIVE
  37. problem finds the intersection of these two areas.
  38. There are several optional problems. These can be enabled when they
  39. are needed and disabled when they are not needed.
  40. Dataflow problems are generally solved in three layers. The bottom
  41. layer is called scanning where a data structure is built for each rtl
  42. insn that describes the set of defs and uses of that insn. Scanning
  43. is generally kept up to date, i.e. as the insns changes, the scanned
  44. version of that insn changes also. There are various mechanisms for
  45. making this happen and are described in the INCREMENTAL SCANNING
  46. section.
  47. In the middle layer, basic blocks are scanned to produce transfer
  48. functions which describe the effects of that block on the global
  49. dataflow solution. The transfer functions are only rebuilt if the
  50. some instruction within the block has changed.
  51. The top layer is the dataflow solution itself. The dataflow solution
  52. is computed by using an efficient iterative solver and the transfer
  53. functions. The dataflow solution must be recomputed whenever the
  54. control changes or if one of the transfer function changes.
  55. USAGE:
  56. Here is an example of using the dataflow routines.
  57. df_[chain,live,note,rd]_add_problem (flags);
  58. df_set_blocks (blocks);
  59. df_analyze ();
  60. df_dump (stderr);
  61. df_finish_pass (false);
  62. DF_[chain,live,note,rd]_ADD_PROBLEM adds a problem, defined by an
  63. instance to struct df_problem, to the set of problems solved in this
  64. instance of df. All calls to add a problem for a given instance of df
  65. must occur before the first call to DF_ANALYZE.
  66. Problems can be dependent on other problems. For instance, solving
  67. def-use or use-def chains is dependent on solving reaching
  68. definitions. As long as these dependencies are listed in the problem
  69. definition, the order of adding the problems is not material.
  70. Otherwise, the problems will be solved in the order of calls to
  71. df_add_problem. Note that it is not necessary to have a problem. In
  72. that case, df will just be used to do the scanning.
  73. DF_SET_BLOCKS is an optional call used to define a region of the
  74. function on which the analysis will be performed. The normal case is
  75. to analyze the entire function and no call to df_set_blocks is made.
  76. DF_SET_BLOCKS only effects the blocks that are effected when computing
  77. the transfer functions and final solution. The insn level information
  78. is always kept up to date.
  79. When a subset is given, the analysis behaves as if the function only
  80. contains those blocks and any edges that occur directly between the
  81. blocks in the set. Care should be taken to call df_set_blocks right
  82. before the call to analyze in order to eliminate the possibility that
  83. optimizations that reorder blocks invalidate the bitvector.
  84. DF_ANALYZE causes all of the defined problems to be (re)solved. When
  85. DF_ANALYZE is completes, the IN and OUT sets for each basic block
  86. contain the computer information. The DF_*_BB_INFO macros can be used
  87. to access these bitvectors. All deferred rescannings are down before
  88. the transfer functions are recomputed.
  89. DF_DUMP can then be called to dump the information produce to some
  90. file. This calls DF_DUMP_START, to print the information that is not
  91. basic block specific, and then calls DF_DUMP_TOP and DF_DUMP_BOTTOM
  92. for each block to print the basic specific information. These parts
  93. can all be called separately as part of a larger dump function.
  94. DF_FINISH_PASS causes df_remove_problem to be called on all of the
  95. optional problems. It also causes any insns whose scanning has been
  96. deferred to be rescanned as well as clears all of the changeable flags.
  97. Setting the pass manager TODO_df_finish flag causes this function to
  98. be run. However, the pass manager will call df_finish_pass AFTER the
  99. pass dumping has been done, so if you want to see the results of the
  100. optional problems in the pass dumps, use the TODO flag rather than
  101. calling the function yourself.
  102. INCREMENTAL SCANNING
  103. There are four ways of doing the incremental scanning:
  104. 1) Immediate rescanning - Calls to df_insn_rescan, df_notes_rescan,
  105. df_bb_delete, df_insn_change_bb have been added to most of
  106. the low level service functions that maintain the cfg and change
  107. rtl. Calling and of these routines many cause some number of insns
  108. to be rescanned.
  109. For most modern rtl passes, this is certainly the easiest way to
  110. manage rescanning the insns. This technique also has the advantage
  111. that the scanning information is always correct and can be relied
  112. upon even after changes have been made to the instructions. This
  113. technique is contra indicated in several cases:
  114. a) If def-use chains OR use-def chains (but not both) are built,
  115. using this is SIMPLY WRONG. The problem is that when a ref is
  116. deleted that is the target of an edge, there is not enough
  117. information to efficiently find the source of the edge and
  118. delete the edge. This leaves a dangling reference that may
  119. cause problems.
  120. b) If def-use chains AND use-def chains are built, this may
  121. produce unexpected results. The problem is that the incremental
  122. scanning of an insn does not know how to repair the chains that
  123. point into an insn when the insn changes. So the incremental
  124. scanning just deletes the chains that enter and exit the insn
  125. being changed. The dangling reference issue in (a) is not a
  126. problem here, but if the pass is depending on the chains being
  127. maintained after insns have been modified, this technique will
  128. not do the correct thing.
  129. c) If the pass modifies insns several times, this incremental
  130. updating may be expensive.
  131. d) If the pass modifies all of the insns, as does register
  132. allocation, it is simply better to rescan the entire function.
  133. 2) Deferred rescanning - Calls to df_insn_rescan, df_notes_rescan, and
  134. df_insn_delete do not immediately change the insn but instead make
  135. a note that the insn needs to be rescanned. The next call to
  136. df_analyze, df_finish_pass, or df_process_deferred_rescans will
  137. cause all of the pending rescans to be processed.
  138. This is the technique of choice if either 1a, 1b, or 1c are issues
  139. in the pass. In the case of 1a or 1b, a call to df_finish_pass
  140. (either manually or via TODO_df_finish) should be made before the
  141. next call to df_analyze or df_process_deferred_rescans.
  142. This mode is also used by a few passes that still rely on note_uses,
  143. note_stores and for_each_rtx instead of using the DF data. This
  144. can be said to fall under case 1c.
  145. To enable this mode, call df_set_flags (DF_DEFER_INSN_RESCAN).
  146. (This mode can be cleared by calling df_clear_flags
  147. (DF_DEFER_INSN_RESCAN) but this does not cause the deferred insns to
  148. be rescanned.
  149. 3) Total rescanning - In this mode the rescanning is disabled.
  150. Only when insns are deleted is the df information associated with
  151. it also deleted. At the end of the pass, a call must be made to
  152. df_insn_rescan_all. This method is used by the register allocator
  153. since it generally changes each insn multiple times (once for each ref)
  154. and does not need to make use of the updated scanning information.
  155. 4) Do it yourself - In this mechanism, the pass updates the insns
  156. itself using the low level df primitives. Currently no pass does
  157. this, but it has the advantage that it is quite efficient given
  158. that the pass generally has exact knowledge of what it is changing.
  159. DATA STRUCTURES
  160. Scanning produces a `struct df_ref' data structure (ref) is allocated
  161. for every register reference (def or use) and this records the insn
  162. and bb the ref is found within. The refs are linked together in
  163. chains of uses and defs for each insn and for each register. Each ref
  164. also has a chain field that links all the use refs for a def or all
  165. the def refs for a use. This is used to create use-def or def-use
  166. chains.
  167. Different optimizations have different needs. Ultimately, only
  168. register allocation and schedulers should be using the bitmaps
  169. produced for the live register and uninitialized register problems.
  170. The rest of the backend should be upgraded to using and maintaining
  171. the linked information such as def use or use def chains.
  172. PHILOSOPHY:
  173. While incremental bitmaps are not worthwhile to maintain, incremental
  174. chains may be perfectly reasonable. The fastest way to build chains
  175. from scratch or after significant modifications is to build reaching
  176. definitions (RD) and build the chains from this.
  177. However, general algorithms for maintaining use-def or def-use chains
  178. are not practical. The amount of work to recompute the chain any
  179. chain after an arbitrary change is large. However, with a modest
  180. amount of work it is generally possible to have the application that
  181. uses the chains keep them up to date. The high level knowledge of
  182. what is really happening is essential to crafting efficient
  183. incremental algorithms.
  184. As for the bit vector problems, there is no interface to give a set of
  185. blocks over with to resolve the iteration. In general, restarting a
  186. dataflow iteration is difficult and expensive. Again, the best way to
  187. keep the dataflow information up to data (if this is really what is
  188. needed) it to formulate a problem specific solution.
  189. There are fine grained calls for creating and deleting references from
  190. instructions in df-scan.c. However, these are not currently connected
  191. to the engine that resolves the dataflow equations.
  192. DATA STRUCTURES:
  193. The basic object is a DF_REF (reference) and this may either be a
  194. DEF (definition) or a USE of a register.
  195. These are linked into a variety of lists; namely reg-def, reg-use,
  196. insn-def, insn-use, def-use, and use-def lists. For example, the
  197. reg-def lists contain all the locations that define a given register
  198. while the insn-use lists contain all the locations that use a
  199. register.
  200. Note that the reg-def and reg-use chains are generally short for
  201. pseudos and long for the hard registers.
  202. ACCESSING INSNS:
  203. 1) The df insn information is kept in an array of DF_INSN_INFO objects.
  204. The array is indexed by insn uid, and every DF_REF points to the
  205. DF_INSN_INFO object of the insn that contains the reference.
  206. 2) Each insn has three sets of refs, which are linked into one of three
  207. lists: The insn's defs list (accessed by the DF_INSN_INFO_DEFS,
  208. DF_INSN_DEFS, or DF_INSN_UID_DEFS macros), the insn's uses list
  209. (accessed by the DF_INSN_INFO_USES, DF_INSN_USES, or
  210. DF_INSN_UID_USES macros) or the insn's eq_uses list (accessed by the
  211. DF_INSN_INFO_EQ_USES, DF_INSN_EQ_USES or DF_INSN_UID_EQ_USES macros).
  212. The latter list are the list of references in REG_EQUAL or REG_EQUIV
  213. notes. These macros produce a ref (or NULL), the rest of the list
  214. can be obtained by traversal of the NEXT_REF field (accessed by the
  215. DF_REF_NEXT_REF macro.) There is no significance to the ordering of
  216. the uses or refs in an instruction.
  217. 3) Each insn has a logical uid field (LUID) which is stored in the
  218. DF_INSN_INFO object for the insn. The LUID field is accessed by
  219. the DF_INSN_INFO_LUID, DF_INSN_LUID, and DF_INSN_UID_LUID macros.
  220. When properly set, the LUID is an integer that numbers each insn in
  221. the basic block, in order from the start of the block.
  222. The numbers are only correct after a call to df_analyze. They will
  223. rot after insns are added deleted or moved round.
  224. ACCESSING REFS:
  225. There are 4 ways to obtain access to refs:
  226. 1) References are divided into two categories, REAL and ARTIFICIAL.
  227. REAL refs are associated with instructions.
  228. ARTIFICIAL refs are associated with basic blocks. The heads of
  229. these lists can be accessed by calling df_get_artificial_defs or
  230. df_get_artificial_uses for the particular basic block.
  231. Artificial defs and uses occur both at the beginning and ends of blocks.
  232. For blocks that area at the destination of eh edges, the
  233. artificial uses and defs occur at the beginning. The defs relate
  234. to the registers specified in EH_RETURN_DATA_REGNO and the uses
  235. relate to the registers specified in ED_USES. Logically these
  236. defs and uses should really occur along the eh edge, but there is
  237. no convenient way to do this. Artificial edges that occur at the
  238. beginning of the block have the DF_REF_AT_TOP flag set.
  239. Artificial uses occur at the end of all blocks. These arise from
  240. the hard registers that are always live, such as the stack
  241. register and are put there to keep the code from forgetting about
  242. them.
  243. Artificial defs occur at the end of the entry block. These arise
  244. from registers that are live at entry to the function.
  245. 2) There are three types of refs: defs, uses and eq_uses. (Eq_uses are
  246. uses that appear inside a REG_EQUAL or REG_EQUIV note.)
  247. All of the eq_uses, uses and defs associated with each pseudo or
  248. hard register may be linked in a bidirectional chain. These are
  249. called reg-use or reg_def chains. If the changeable flag
  250. DF_EQ_NOTES is set when the chains are built, the eq_uses will be
  251. treated like uses. If it is not set they are ignored.
  252. The first use, eq_use or def for a register can be obtained using
  253. the DF_REG_USE_CHAIN, DF_REG_EQ_USE_CHAIN or DF_REG_DEF_CHAIN
  254. macros. Subsequent uses for the same regno can be obtained by
  255. following the next_reg field of the ref. The number of elements in
  256. each of the chains can be found by using the DF_REG_USE_COUNT,
  257. DF_REG_EQ_USE_COUNT or DF_REG_DEF_COUNT macros.
  258. In previous versions of this code, these chains were ordered. It
  259. has not been practical to continue this practice.
  260. 3) If def-use or use-def chains are built, these can be traversed to
  261. get to other refs. If the flag DF_EQ_NOTES has been set, the chains
  262. include the eq_uses. Otherwise these are ignored when building the
  263. chains.
  264. 4) An array of all of the uses (and an array of all of the defs) can
  265. be built. These arrays are indexed by the value in the id
  266. structure. These arrays are only lazily kept up to date, and that
  267. process can be expensive. To have these arrays built, call
  268. df_reorganize_defs or df_reorganize_uses. If the flag DF_EQ_NOTES
  269. has been set the array will contain the eq_uses. Otherwise these
  270. are ignored when building the array and assigning the ids. Note
  271. that the values in the id field of a ref may change across calls to
  272. df_analyze or df_reorganize_defs or df_reorganize_uses.
  273. If the only use of this array is to find all of the refs, it is
  274. better to traverse all of the registers and then traverse all of
  275. reg-use or reg-def chains.
  276. NOTES:
  277. Embedded addressing side-effects, such as POST_INC or PRE_INC, generate
  278. both a use and a def. These are both marked read/write to show that they
  279. are dependent. For example, (set (reg 40) (mem (post_inc (reg 42))))
  280. will generate a use of reg 42 followed by a def of reg 42 (both marked
  281. read/write). Similarly, (set (reg 40) (mem (pre_dec (reg 41))))
  282. generates a use of reg 41 then a def of reg 41 (both marked read/write),
  283. even though reg 41 is decremented before it is used for the memory
  284. address in this second example.
  285. A set to a REG inside a ZERO_EXTRACT, or a set to a non-paradoxical SUBREG
  286. for which the number of word_mode units covered by the outer mode is
  287. smaller than that covered by the inner mode, invokes a read-modify-write
  288. operation. We generate both a use and a def and again mark them
  289. read/write.
  290. Paradoxical subreg writes do not leave a trace of the old content, so they
  291. are write-only operations.
  292. */
  293. #include "config.h"
  294. #include "system.h"
  295. #include "coretypes.h"
  296. #include "tm.h"
  297. #include "rtl.h"
  298. #include "tm_p.h"
  299. #include "insn-config.h"
  300. #include "recog.h"
  301. #include "function.h"
  302. #include "regs.h"
  303. #include "alloc-pool.h"
  304. #include "flags.h"
  305. #include "hard-reg-set.h"
  306. #include "basic-block.h"
  307. #include "sbitmap.h"
  308. #include "bitmap.h"
  309. #include "df.h"
  310. #include "tree-pass.h"
  311. #include "params.h"
  312. static void *df_get_bb_info (struct dataflow *, unsigned int);
  313. static void df_set_bb_info (struct dataflow *, unsigned int, void *);
  314. static void df_clear_bb_info (struct dataflow *, unsigned int);
  315. #ifdef DF_DEBUG_CFG
  316. static void df_set_clean_cfg (void);
  317. #endif
  318. /* The obstack on which regsets are allocated. */
  319. struct bitmap_obstack reg_obstack;
  320. /* An obstack for bitmap not related to specific dataflow problems.
  321. This obstack should e.g. be used for bitmaps with a short life time
  322. such as temporary bitmaps. */
  323. bitmap_obstack df_bitmap_obstack;
  324. /*----------------------------------------------------------------------------
  325. Functions to create, destroy and manipulate an instance of df.
  326. ----------------------------------------------------------------------------*/
  327. struct df_d *df;
  328. /* Add PROBLEM (and any dependent problems) to the DF instance. */
  329. void
  330. df_add_problem (struct df_problem *problem)
  331. {
  332. struct dataflow *dflow;
  333. int i;
  334. /* First try to add the dependent problem. */
  335. if (problem->dependent_problem)
  336. df_add_problem (problem->dependent_problem);
  337. /* Check to see if this problem has already been defined. If it
  338. has, just return that instance, if not, add it to the end of the
  339. vector. */
  340. dflow = df->problems_by_index[problem->id];
  341. if (dflow)
  342. return;
  343. /* Make a new one and add it to the end. */
  344. dflow = XCNEW (struct dataflow);
  345. dflow->problem = problem;
  346. dflow->computed = false;
  347. dflow->solutions_dirty = true;
  348. df->problems_by_index[dflow->problem->id] = dflow;
  349. /* Keep the defined problems ordered by index. This solves the
  350. problem that RI will use the information from UREC if UREC has
  351. been defined, or from LIVE if LIVE is defined and otherwise LR.
  352. However for this to work, the computation of RI must be pushed
  353. after which ever of those problems is defined, but we do not
  354. require any of those except for LR to have actually been
  355. defined. */
  356. df->num_problems_defined++;
  357. for (i = df->num_problems_defined - 2; i >= 0; i--)
  358. {
  359. if (problem->id < df->problems_in_order[i]->problem->id)
  360. df->problems_in_order[i+1] = df->problems_in_order[i];
  361. else
  362. {
  363. df->problems_in_order[i+1] = dflow;
  364. return;
  365. }
  366. }
  367. df->problems_in_order[0] = dflow;
  368. }
  369. /* Set the MASK flags in the DFLOW problem. The old flags are
  370. returned. If a flag is not allowed to be changed this will fail if
  371. checking is enabled. */
  372. int
  373. df_set_flags (int changeable_flags)
  374. {
  375. int old_flags = df->changeable_flags;
  376. df->changeable_flags |= changeable_flags;
  377. return old_flags;
  378. }
  379. /* Clear the MASK flags in the DFLOW problem. The old flags are
  380. returned. If a flag is not allowed to be changed this will fail if
  381. checking is enabled. */
  382. int
  383. df_clear_flags (int changeable_flags)
  384. {
  385. int old_flags = df->changeable_flags;
  386. df->changeable_flags &= ~changeable_flags;
  387. return old_flags;
  388. }
  389. /* Set the blocks that are to be considered for analysis. If this is
  390. not called or is called with null, the entire function in
  391. analyzed. */
  392. void
  393. df_set_blocks (bitmap blocks)
  394. {
  395. if (blocks)
  396. {
  397. if (dump_file)
  398. bitmap_print (dump_file, blocks, "setting blocks to analyze ", "\n");
  399. if (df->blocks_to_analyze)
  400. {
  401. /* This block is called to change the focus from one subset
  402. to another. */
  403. int p;
  404. bitmap_head diff;
  405. bitmap_initialize (&diff, &df_bitmap_obstack);
  406. bitmap_and_compl (&diff, df->blocks_to_analyze, blocks);
  407. for (p = 0; p < df->num_problems_defined; p++)
  408. {
  409. struct dataflow *dflow = df->problems_in_order[p];
  410. if (dflow->optional_p && dflow->problem->reset_fun)
  411. dflow->problem->reset_fun (df->blocks_to_analyze);
  412. else if (dflow->problem->free_blocks_on_set_blocks)
  413. {
  414. bitmap_iterator bi;
  415. unsigned int bb_index;
  416. EXECUTE_IF_SET_IN_BITMAP (&diff, 0, bb_index, bi)
  417. {
  418. basic_block bb = BASIC_BLOCK (bb_index);
  419. if (bb)
  420. {
  421. void *bb_info = df_get_bb_info (dflow, bb_index);
  422. dflow->problem->free_bb_fun (bb, bb_info);
  423. df_clear_bb_info (dflow, bb_index);
  424. }
  425. }
  426. }
  427. }
  428. bitmap_clear (&diff);
  429. }
  430. else
  431. {
  432. /* This block of code is executed to change the focus from
  433. the entire function to a subset. */
  434. bitmap_head blocks_to_reset;
  435. bool initialized = false;
  436. int p;
  437. for (p = 0; p < df->num_problems_defined; p++)
  438. {
  439. struct dataflow *dflow = df->problems_in_order[p];
  440. if (dflow->optional_p && dflow->problem->reset_fun)
  441. {
  442. if (!initialized)
  443. {
  444. basic_block bb;
  445. bitmap_initialize (&blocks_to_reset, &df_bitmap_obstack);
  446. FOR_ALL_BB(bb)
  447. {
  448. bitmap_set_bit (&blocks_to_reset, bb->index);
  449. }
  450. }
  451. dflow->problem->reset_fun (&blocks_to_reset);
  452. }
  453. }
  454. if (initialized)
  455. bitmap_clear (&blocks_to_reset);
  456. df->blocks_to_analyze = BITMAP_ALLOC (&df_bitmap_obstack);
  457. }
  458. bitmap_copy (df->blocks_to_analyze, blocks);
  459. df->analyze_subset = true;
  460. }
  461. else
  462. {
  463. /* This block is executed to reset the focus to the entire
  464. function. */
  465. if (dump_file)
  466. fprintf (dump_file, "clearing blocks_to_analyze\n");
  467. if (df->blocks_to_analyze)
  468. {
  469. BITMAP_FREE (df->blocks_to_analyze);
  470. df->blocks_to_analyze = NULL;
  471. }
  472. df->analyze_subset = false;
  473. }
  474. /* Setting the blocks causes the refs to be unorganized since only
  475. the refs in the blocks are seen. */
  476. df_maybe_reorganize_def_refs (DF_REF_ORDER_NO_TABLE);
  477. df_maybe_reorganize_use_refs (DF_REF_ORDER_NO_TABLE);
  478. df_mark_solutions_dirty ();
  479. }
  480. /* Delete a DFLOW problem (and any problems that depend on this
  481. problem). */
  482. void
  483. df_remove_problem (struct dataflow *dflow)
  484. {
  485. struct df_problem *problem;
  486. int i;
  487. if (!dflow)
  488. return;
  489. problem = dflow->problem;
  490. gcc_assert (problem->remove_problem_fun);
  491. /* Delete any problems that depended on this problem first. */
  492. for (i = 0; i < df->num_problems_defined; i++)
  493. if (df->problems_in_order[i]->problem->dependent_problem == problem)
  494. df_remove_problem (df->problems_in_order[i]);
  495. /* Now remove this problem. */
  496. for (i = 0; i < df->num_problems_defined; i++)
  497. if (df->problems_in_order[i] == dflow)
  498. {
  499. int j;
  500. for (j = i + 1; j < df->num_problems_defined; j++)
  501. df->problems_in_order[j-1] = df->problems_in_order[j];
  502. df->problems_in_order[j-1] = NULL;
  503. df->num_problems_defined--;
  504. break;
  505. }
  506. (problem->remove_problem_fun) ();
  507. df->problems_by_index[problem->id] = NULL;
  508. }
  509. /* Remove all of the problems that are not permanent. Scanning, LR
  510. and (at -O2 or higher) LIVE are permanent, the rest are removable.
  511. Also clear all of the changeable_flags. */
  512. void
  513. df_finish_pass (bool verify ATTRIBUTE_UNUSED)
  514. {
  515. int i;
  516. int removed = 0;
  517. #ifdef ENABLE_DF_CHECKING
  518. int saved_flags;
  519. #endif
  520. if (!df)
  521. return;
  522. df_maybe_reorganize_def_refs (DF_REF_ORDER_NO_TABLE);
  523. df_maybe_reorganize_use_refs (DF_REF_ORDER_NO_TABLE);
  524. #ifdef ENABLE_DF_CHECKING
  525. saved_flags = df->changeable_flags;
  526. #endif
  527. for (i = 0; i < df->num_problems_defined; i++)
  528. {
  529. struct dataflow *dflow = df->problems_in_order[i];
  530. struct df_problem *problem = dflow->problem;
  531. if (dflow->optional_p)
  532. {
  533. gcc_assert (problem->remove_problem_fun);
  534. (problem->remove_problem_fun) ();
  535. df->problems_in_order[i] = NULL;
  536. df->problems_by_index[problem->id] = NULL;
  537. removed++;
  538. }
  539. }
  540. df->num_problems_defined -= removed;
  541. /* Clear all of the flags. */
  542. df->changeable_flags = 0;
  543. df_process_deferred_rescans ();
  544. /* Set the focus back to the whole function. */
  545. if (df->blocks_to_analyze)
  546. {
  547. BITMAP_FREE (df->blocks_to_analyze);
  548. df->blocks_to_analyze = NULL;
  549. df_mark_solutions_dirty ();
  550. df->analyze_subset = false;
  551. }
  552. #ifdef ENABLE_DF_CHECKING
  553. /* Verification will fail in DF_NO_INSN_RESCAN. */
  554. if (!(saved_flags & DF_NO_INSN_RESCAN))
  555. {
  556. df_lr_verify_transfer_functions ();
  557. if (df_live)
  558. df_live_verify_transfer_functions ();
  559. }
  560. #ifdef DF_DEBUG_CFG
  561. df_set_clean_cfg ();
  562. #endif
  563. #endif
  564. #ifdef ENABLE_CHECKING
  565. if (verify)
  566. df->changeable_flags |= DF_VERIFY_SCHEDULED;
  567. #endif
  568. }
  569. /* Set up the dataflow instance for the entire back end. */
  570. static unsigned int
  571. rest_of_handle_df_initialize (void)
  572. {
  573. gcc_assert (!df);
  574. df = XCNEW (struct df_d);
  575. df->changeable_flags = 0;
  576. bitmap_obstack_initialize (&df_bitmap_obstack);
  577. /* Set this to a conservative value. Stack_ptr_mod will compute it
  578. correctly later. */
  579. crtl->sp_is_unchanging = 0;
  580. df_scan_add_problem ();
  581. df_scan_alloc (NULL);
  582. /* These three problems are permanent. */
  583. df_lr_add_problem ();
  584. if (optimize > 1)
  585. df_live_add_problem ();
  586. df->postorder = XNEWVEC (int, last_basic_block);
  587. df->postorder_inverted = XNEWVEC (int, last_basic_block);
  588. df->n_blocks = post_order_compute (df->postorder, true, true);
  589. df->n_blocks_inverted = inverted_post_order_compute (df->postorder_inverted);
  590. gcc_assert (df->n_blocks == df->n_blocks_inverted);
  591. df->hard_regs_live_count = XNEWVEC (unsigned int, FIRST_PSEUDO_REGISTER);
  592. memset (df->hard_regs_live_count, 0,
  593. sizeof (unsigned int) * FIRST_PSEUDO_REGISTER);
  594. df_hard_reg_init ();
  595. /* After reload, some ports add certain bits to regs_ever_live so
  596. this cannot be reset. */
  597. df_compute_regs_ever_live (true);
  598. df_scan_blocks ();
  599. df_compute_regs_ever_live (false);
  600. return 0;
  601. }
  602. static bool
  603. gate_opt (void)
  604. {
  605. return optimize > 0;
  606. }
  607. struct rtl_opt_pass pass_df_initialize_opt =
  608. {
  609. {
  610. RTL_PASS,
  611. "dfinit", /* name */
  612. gate_opt, /* gate */
  613. rest_of_handle_df_initialize, /* execute */
  614. NULL, /* sub */
  615. NULL, /* next */
  616. 0, /* static_pass_number */
  617. TV_DF_SCAN, /* tv_id */
  618. 0, /* properties_required */
  619. 0, /* properties_provided */
  620. 0, /* properties_destroyed */
  621. 0, /* todo_flags_start */
  622. 0 /* todo_flags_finish */
  623. }
  624. };
  625. static bool
  626. gate_no_opt (void)
  627. {
  628. return optimize == 0;
  629. }
  630. struct rtl_opt_pass pass_df_initialize_no_opt =
  631. {
  632. {
  633. RTL_PASS,
  634. "no-opt dfinit", /* name */
  635. gate_no_opt, /* gate */
  636. rest_of_handle_df_initialize, /* execute */
  637. NULL, /* sub */
  638. NULL, /* next */
  639. 0, /* static_pass_number */
  640. TV_DF_SCAN, /* tv_id */
  641. 0, /* properties_required */
  642. 0, /* properties_provided */
  643. 0, /* properties_destroyed */
  644. 0, /* todo_flags_start */
  645. 0 /* todo_flags_finish */
  646. }
  647. };
  648. /* Free all the dataflow info and the DF structure. This should be
  649. called from the df_finish macro which also NULLs the parm. */
  650. static unsigned int
  651. rest_of_handle_df_finish (void)
  652. {
  653. int i;
  654. gcc_assert (df);
  655. for (i = 0; i < df->num_problems_defined; i++)
  656. {
  657. struct dataflow *dflow = df->problems_in_order[i];
  658. dflow->problem->free_fun ();
  659. }
  660. free (df->postorder);
  661. free (df->postorder_inverted);
  662. free (df->hard_regs_live_count);
  663. free (df);
  664. df = NULL;
  665. bitmap_obstack_release (&df_bitmap_obstack);
  666. return 0;
  667. }
  668. struct rtl_opt_pass pass_df_finish =
  669. {
  670. {
  671. RTL_PASS,
  672. "dfinish", /* name */
  673. NULL, /* gate */
  674. rest_of_handle_df_finish, /* execute */
  675. NULL, /* sub */
  676. NULL, /* next */
  677. 0, /* static_pass_number */
  678. TV_NONE, /* tv_id */
  679. 0, /* properties_required */
  680. 0, /* properties_provided */
  681. 0, /* properties_destroyed */
  682. 0, /* todo_flags_start */
  683. 0 /* todo_flags_finish */
  684. }
  685. };
  686. /*----------------------------------------------------------------------------
  687. The general data flow analysis engine.
  688. ----------------------------------------------------------------------------*/
  689. /* Return time BB when it was visited for last time. */
  690. #define BB_LAST_CHANGE_AGE(bb) ((ptrdiff_t)(bb)->aux)
  691. /* Helper function for df_worklist_dataflow.
  692. Propagate the dataflow forward.
  693. Given a BB_INDEX, do the dataflow propagation
  694. and set bits on for successors in PENDING
  695. if the out set of the dataflow has changed.
  696. AGE specify time when BB was visited last time.
  697. AGE of 0 means we are visiting for first time and need to
  698. compute transfer function to initialize datastructures.
  699. Otherwise we re-do transfer function only if something change
  700. while computing confluence functions.
  701. We need to compute confluence only of basic block that are younger
  702. then last visit of the BB.
  703. Return true if BB info has changed. This is always the case
  704. in the first visit. */
  705. static bool
  706. df_worklist_propagate_forward (struct dataflow *dataflow,
  707. unsigned bb_index,
  708. unsigned *bbindex_to_postorder,
  709. bitmap pending,
  710. sbitmap considered,
  711. ptrdiff_t age)
  712. {
  713. edge e;
  714. edge_iterator ei;
  715. basic_block bb = BASIC_BLOCK (bb_index);
  716. bool changed = !age;
  717. /* Calculate <conf_op> of incoming edges. */
  718. if (EDGE_COUNT (bb->preds) > 0)
  719. FOR_EACH_EDGE (e, ei, bb->preds)
  720. {
  721. if (age <= BB_LAST_CHANGE_AGE (e->src)
  722. && TEST_BIT (considered, e->src->index))
  723. changed |= dataflow->problem->con_fun_n (e);
  724. }
  725. else if (dataflow->problem->con_fun_0)
  726. dataflow->problem->con_fun_0 (bb);
  727. if (changed
  728. && dataflow->problem->trans_fun (bb_index))
  729. {
  730. /* The out set of this block has changed.
  731. Propagate to the outgoing blocks. */
  732. FOR_EACH_EDGE (e, ei, bb->succs)
  733. {
  734. unsigned ob_index = e->dest->index;
  735. if (TEST_BIT (considered, ob_index))
  736. bitmap_set_bit (pending, bbindex_to_postorder[ob_index]);
  737. }
  738. return true;
  739. }
  740. return false;
  741. }
  742. /* Helper function for df_worklist_dataflow.
  743. Propagate the dataflow backward. */
  744. static bool
  745. df_worklist_propagate_backward (struct dataflow *dataflow,
  746. unsigned bb_index,
  747. unsigned *bbindex_to_postorder,
  748. bitmap pending,
  749. sbitmap considered,
  750. ptrdiff_t age)
  751. {
  752. edge e;
  753. edge_iterator ei;
  754. basic_block bb = BASIC_BLOCK (bb_index);
  755. bool changed = !age;
  756. /* Calculate <conf_op> of incoming edges. */
  757. if (EDGE_COUNT (bb->succs) > 0)
  758. FOR_EACH_EDGE (e, ei, bb->succs)
  759. {
  760. if (age <= BB_LAST_CHANGE_AGE (e->dest)
  761. && TEST_BIT (considered, e->dest->index))
  762. changed |= dataflow->problem->con_fun_n (e);
  763. }
  764. else if (dataflow->problem->con_fun_0)
  765. dataflow->problem->con_fun_0 (bb);
  766. if (changed
  767. && dataflow->problem->trans_fun (bb_index))
  768. {
  769. /* The out set of this block has changed.
  770. Propagate to the outgoing blocks. */
  771. FOR_EACH_EDGE (e, ei, bb->preds)
  772. {
  773. unsigned ob_index = e->src->index;
  774. if (TEST_BIT (considered, ob_index))
  775. bitmap_set_bit (pending, bbindex_to_postorder[ob_index]);
  776. }
  777. return true;
  778. }
  779. return false;
  780. }
  781. /* Main dataflow solver loop.
  782. DATAFLOW is problem we are solving, PENDING is worklist of basic blocks we
  783. need to visit.
  784. BLOCK_IN_POSTORDER is array of size N_BLOCKS specifying postorder in BBs and
  785. BBINDEX_TO_POSTORDER is array mapping back BB->index to postorder possition.
  786. PENDING will be freed.
  787. The worklists are bitmaps indexed by postorder positions.
  788. The function implements standard algorithm for dataflow solving with two
  789. worklists (we are processing WORKLIST and storing new BBs to visit in
  790. PENDING).
  791. As an optimization we maintain ages when BB was changed (stored in bb->aux)
  792. and when it was last visited (stored in last_visit_age). This avoids need
  793. to re-do confluence function for edges to basic blocks whose source
  794. did not change since destination was visited last time. */
  795. static void
  796. df_worklist_dataflow_doublequeue (struct dataflow *dataflow,
  797. bitmap pending,
  798. sbitmap considered,
  799. int *blocks_in_postorder,
  800. unsigned *bbindex_to_postorder,
  801. int n_blocks)
  802. {
  803. enum df_flow_dir dir = dataflow->problem->dir;
  804. int dcount = 0;
  805. bitmap worklist = BITMAP_ALLOC (&df_bitmap_obstack);
  806. int age = 0;
  807. bool changed;
  808. VEC(int, heap) *last_visit_age = NULL;
  809. int prev_age;
  810. basic_block bb;
  811. int i;
  812. VEC_safe_grow_cleared (int, heap, last_visit_age, n_blocks);
  813. /* Double-queueing. Worklist is for the current iteration,
  814. and pending is for the next. */
  815. while (!bitmap_empty_p (pending))
  816. {
  817. bitmap_iterator bi;
  818. unsigned int index;
  819. /* Swap pending and worklist. */
  820. bitmap temp = worklist;
  821. worklist = pending;
  822. pending = temp;
  823. EXECUTE_IF_SET_IN_BITMAP (worklist, 0, index, bi)
  824. {
  825. unsigned bb_index;
  826. dcount++;
  827. bitmap_clear_bit (pending, index);
  828. bb_index = blocks_in_postorder[index];
  829. bb = BASIC_BLOCK (bb_index);
  830. prev_age = VEC_index (int, last_visit_age, index);
  831. if (dir == DF_FORWARD)
  832. changed = df_worklist_propagate_forward (dataflow, bb_index,
  833. bbindex_to_postorder,
  834. pending, considered,
  835. prev_age);
  836. else
  837. changed = df_worklist_propagate_backward (dataflow, bb_index,
  838. bbindex_to_postorder,
  839. pending, considered,
  840. prev_age);
  841. VEC_replace (int, last_visit_age, index, ++age);
  842. if (changed)
  843. bb->aux = (void *)(ptrdiff_t)age;
  844. }
  845. bitmap_clear (worklist);
  846. }
  847. for (i = 0; i < n_blocks; i++)
  848. BASIC_BLOCK (blocks_in_postorder[i])->aux = NULL;
  849. BITMAP_FREE (worklist);
  850. BITMAP_FREE (pending);
  851. VEC_free (int, heap, last_visit_age);
  852. /* Dump statistics. */
  853. if (dump_file)
  854. fprintf (dump_file, "df_worklist_dataflow_doublequeue:"
  855. "n_basic_blocks %d n_edges %d"
  856. " count %d (%5.2g)\n",
  857. n_basic_blocks, n_edges,
  858. dcount, dcount / (float)n_basic_blocks);
  859. }
  860. /* Worklist-based dataflow solver. It uses sbitmap as a worklist,
  861. with "n"-th bit representing the n-th block in the reverse-postorder order.
  862. The solver is a double-queue algorithm similar to the "double stack" solver
  863. from Cooper, Harvey and Kennedy, "Iterative data-flow analysis, Revisited".
  864. The only significant difference is that the worklist in this implementation
  865. is always sorted in RPO of the CFG visiting direction. */
  866. void
  867. df_worklist_dataflow (struct dataflow *dataflow,
  868. bitmap blocks_to_consider,
  869. int *blocks_in_postorder,
  870. int n_blocks)
  871. {
  872. bitmap pending = BITMAP_ALLOC (&df_bitmap_obstack);
  873. sbitmap considered = sbitmap_alloc (last_basic_block);
  874. bitmap_iterator bi;
  875. unsigned int *bbindex_to_postorder;
  876. int i;
  877. unsigned int index;
  878. enum df_flow_dir dir = dataflow->problem->dir;
  879. gcc_assert (dir != DF_NONE);
  880. /* BBINDEX_TO_POSTORDER maps the bb->index to the reverse postorder. */
  881. bbindex_to_postorder =
  882. (unsigned int *)xmalloc (last_basic_block * sizeof (unsigned int));
  883. /* Initialize the array to an out-of-bound value. */
  884. for (i = 0; i < last_basic_block; i++)
  885. bbindex_to_postorder[i] = last_basic_block;
  886. /* Initialize the considered map. */
  887. sbitmap_zero (considered);
  888. EXECUTE_IF_SET_IN_BITMAP (blocks_to_consider, 0, index, bi)
  889. {
  890. SET_BIT (considered, index);
  891. }
  892. /* Initialize the mapping of block index to postorder. */
  893. for (i = 0; i < n_blocks; i++)
  894. {
  895. bbindex_to_postorder[blocks_in_postorder[i]] = i;
  896. /* Add all blocks to the worklist. */
  897. bitmap_set_bit (pending, i);
  898. }
  899. /* Initialize the problem. */
  900. if (dataflow->problem->init_fun)
  901. dataflow->problem->init_fun (blocks_to_consider);
  902. /* Solve it. */
  903. df_worklist_dataflow_doublequeue (dataflow, pending, considered,
  904. blocks_in_postorder,
  905. bbindex_to_postorder,
  906. n_blocks);
  907. sbitmap_free (considered);
  908. free (bbindex_to_postorder);
  909. }
  910. /* Remove the entries not in BLOCKS from the LIST of length LEN, preserving
  911. the order of the remaining entries. Returns the length of the resulting
  912. list. */
  913. static unsigned
  914. df_prune_to_subcfg (int list[], unsigned len, bitmap blocks)
  915. {
  916. unsigned act, last;
  917. for (act = 0, last = 0; act < len; act++)
  918. if (bitmap_bit_p (blocks, list[act]))
  919. list[last++] = list[act];
  920. return last;
  921. }
  922. /* Execute dataflow analysis on a single dataflow problem.
  923. BLOCKS_TO_CONSIDER are the blocks whose solution can either be
  924. examined or will be computed. For calls from DF_ANALYZE, this is
  925. the set of blocks that has been passed to DF_SET_BLOCKS.
  926. */
  927. void
  928. df_analyze_problem (struct dataflow *dflow,
  929. bitmap blocks_to_consider,
  930. int *postorder, int n_blocks)
  931. {
  932. timevar_push (dflow->problem->tv_id);
  933. /* (Re)Allocate the datastructures necessary to solve the problem. */
  934. if (dflow->problem->alloc_fun)
  935. dflow->problem->alloc_fun (blocks_to_consider);
  936. #ifdef ENABLE_DF_CHECKING
  937. if (dflow->problem->verify_start_fun)
  938. dflow->problem->verify_start_fun ();
  939. #endif
  940. /* Set up the problem and compute the local information. */
  941. if (dflow->problem->local_compute_fun)
  942. dflow->problem->local_compute_fun (blocks_to_consider);
  943. /* Solve the equations. */
  944. if (dflow->problem->dataflow_fun)
  945. dflow->problem->dataflow_fun (dflow, blocks_to_consider,
  946. postorder, n_blocks);
  947. /* Massage the solution. */
  948. if (dflow->problem->finalize_fun)
  949. dflow->problem->finalize_fun (blocks_to_consider);
  950. #ifdef ENABLE_DF_CHECKING
  951. if (dflow->problem->verify_end_fun)
  952. dflow->problem->verify_end_fun ();
  953. #endif
  954. timevar_pop (dflow->problem->tv_id);
  955. dflow->computed = true;
  956. }
  957. /* Analyze dataflow info for the basic blocks specified by the bitmap
  958. BLOCKS, or for the whole CFG if BLOCKS is zero. */
  959. void
  960. df_analyze (void)
  961. {
  962. bitmap current_all_blocks = BITMAP_ALLOC (&df_bitmap_obstack);
  963. bool everything;
  964. int i;
  965. free (df->postorder);
  966. free (df->postorder_inverted);
  967. df->postorder = XNEWVEC (int, last_basic_block);
  968. df->postorder_inverted = XNEWVEC (int, last_basic_block);
  969. df->n_blocks = post_order_compute (df->postorder, true, true);
  970. df->n_blocks_inverted = inverted_post_order_compute (df->postorder_inverted);
  971. /* These should be the same. */
  972. gcc_assert (df->n_blocks == df->n_blocks_inverted);
  973. /* We need to do this before the df_verify_all because this is
  974. not kept incrementally up to date. */
  975. df_compute_regs_ever_live (false);
  976. df_process_deferred_rescans ();
  977. if (dump_file)
  978. fprintf (dump_file, "df_analyze called\n");
  979. #ifndef ENABLE_DF_CHECKING
  980. if (df->changeable_flags & DF_VERIFY_SCHEDULED)
  981. #endif
  982. df_verify ();
  983. for (i = 0; i < df->n_blocks; i++)
  984. bitmap_set_bit (current_all_blocks, df->postorder[i]);
  985. #ifdef ENABLE_CHECKING
  986. /* Verify that POSTORDER_INVERTED only contains blocks reachable from
  987. the ENTRY block. */
  988. for (i = 0; i < df->n_blocks_inverted; i++)
  989. gcc_assert (bitmap_bit_p (current_all_blocks, df->postorder_inverted[i]));
  990. #endif
  991. /* Make sure that we have pruned any unreachable blocks from these
  992. sets. */
  993. if (df->analyze_subset)
  994. {
  995. everything = false;
  996. bitmap_and_into (df->blocks_to_analyze, current_all_blocks);
  997. df->n_blocks = df_prune_to_subcfg (df->postorder,
  998. df->n_blocks, df->blocks_to_analyze);
  999. df->n_blocks_inverted = df_prune_to_subcfg (df->postorder_inverted,
  1000. df->n_blocks_inverted,
  1001. df->blocks_to_analyze);
  1002. BITMAP_FREE (current_all_blocks);
  1003. }
  1004. else
  1005. {
  1006. everything = true;
  1007. df->blocks_to_analyze = current_all_blocks;
  1008. current_all_blocks = NULL;
  1009. }
  1010. /* Skip over the DF_SCAN problem. */
  1011. for (i = 1; i < df->num_problems_defined; i++)
  1012. {
  1013. struct dataflow *dflow = df->problems_in_order[i];
  1014. if (dflow->solutions_dirty)
  1015. {
  1016. if (dflow->problem->dir == DF_FORWARD)
  1017. df_analyze_problem (dflow,
  1018. df->blocks_to_analyze,
  1019. df->postorder_inverted,
  1020. df->n_blocks_inverted);
  1021. else
  1022. df_analyze_problem (dflow,
  1023. df->blocks_to_analyze,
  1024. df->postorder,
  1025. df->n_blocks);
  1026. }
  1027. }
  1028. if (everything)
  1029. {
  1030. BITMAP_FREE (df->blocks_to_analyze);
  1031. df->blocks_to_analyze = NULL;
  1032. }
  1033. #ifdef DF_DEBUG_CFG
  1034. df_set_clean_cfg ();
  1035. #endif
  1036. }
  1037. /* Return the number of basic blocks from the last call to df_analyze. */
  1038. int
  1039. df_get_n_blocks (enum df_flow_dir dir)
  1040. {
  1041. gcc_assert (dir != DF_NONE);
  1042. if (dir == DF_FORWARD)
  1043. {
  1044. gcc_assert (df->postorder_inverted);
  1045. return df->n_blocks_inverted;
  1046. }
  1047. gcc_assert (df->postorder);
  1048. return df->n_blocks;
  1049. }
  1050. /* Return a pointer to the array of basic blocks in the reverse postorder.
  1051. Depending on the direction of the dataflow problem,
  1052. it returns either the usual reverse postorder array
  1053. or the reverse postorder of inverted traversal. */
  1054. int *
  1055. df_get_postorder (enum df_flow_dir dir)
  1056. {
  1057. gcc_assert (dir != DF_NONE);
  1058. if (dir == DF_FORWARD)
  1059. {
  1060. gcc_assert (df->postorder_inverted);
  1061. return df->postorder_inverted;
  1062. }
  1063. gcc_assert (df->postorder);
  1064. return df->postorder;
  1065. }
  1066. static struct df_problem user_problem;
  1067. static struct dataflow user_dflow;
  1068. /* Interface for calling iterative dataflow with user defined
  1069. confluence and transfer functions. All that is necessary is to
  1070. supply DIR, a direction, CONF_FUN_0, a confluence function for
  1071. blocks with no logical preds (or NULL), CONF_FUN_N, the normal
  1072. confluence function, TRANS_FUN, the basic block transfer function,
  1073. and BLOCKS, the set of blocks to examine, POSTORDER the blocks in
  1074. postorder, and N_BLOCKS, the number of blocks in POSTORDER. */
  1075. void
  1076. df_simple_dataflow (enum df_flow_dir dir,
  1077. df_init_function init_fun,
  1078. df_confluence_function_0 con_fun_0,
  1079. df_confluence_function_n con_fun_n,
  1080. df_transfer_function trans_fun,
  1081. bitmap blocks, int * postorder, int n_blocks)
  1082. {
  1083. memset (&user_problem, 0, sizeof (struct df_problem));
  1084. user_problem.dir = dir;
  1085. user_problem.init_fun = init_fun;
  1086. user_problem.con_fun_0 = con_fun_0;
  1087. user_problem.con_fun_n = con_fun_n;
  1088. user_problem.trans_fun = trans_fun;
  1089. user_dflow.problem = &user_problem;
  1090. df_worklist_dataflow (&user_dflow, blocks, postorder, n_blocks);
  1091. }
  1092. /*----------------------------------------------------------------------------
  1093. Functions to support limited incremental change.
  1094. ----------------------------------------------------------------------------*/
  1095. /* Get basic block info. */
  1096. static void *
  1097. df_get_bb_info (struct dataflow *dflow, unsigned int index)
  1098. {
  1099. if (dflow->block_info == NULL)
  1100. return NULL;
  1101. if (index >= dflow->block_info_size)
  1102. return NULL;
  1103. return (void *)((char *)dflow->block_info
  1104. + index * dflow->problem->block_info_elt_size);
  1105. }
  1106. /* Set basic block info. */
  1107. static void
  1108. df_set_bb_info (struct dataflow *dflow, unsigned int index,
  1109. void *bb_info)
  1110. {
  1111. gcc_assert (dflow->block_info);
  1112. memcpy ((char *)dflow->block_info
  1113. + index * dflow->problem->block_info_elt_size,
  1114. bb_info, dflow->problem->block_info_elt_size);
  1115. }
  1116. /* Clear basic block info. */
  1117. static void
  1118. df_clear_bb_info (struct dataflow *dflow, unsigned int index)
  1119. {
  1120. gcc_assert (dflow->block_info);
  1121. gcc_assert (dflow->block_info_size > index);
  1122. memset ((char *)dflow->block_info
  1123. + index * dflow->problem->block_info_elt_size,
  1124. 0, dflow->problem->block_info_elt_size);
  1125. }
  1126. /* Mark the solutions as being out of date. */
  1127. void
  1128. df_mark_solutions_dirty (void)
  1129. {
  1130. if (df)
  1131. {
  1132. int p;
  1133. for (p = 1; p < df->num_problems_defined; p++)
  1134. df->problems_in_order[p]->solutions_dirty = true;
  1135. }
  1136. }
  1137. /* Return true if BB needs it's transfer functions recomputed. */
  1138. bool
  1139. df_get_bb_dirty (basic_block bb)
  1140. {
  1141. return bitmap_bit_p ((df_live
  1142. ? df_live : df_lr)->out_of_date_transfer_functions,
  1143. bb->index);
  1144. }
  1145. /* Mark BB as needing it's transfer functions as being out of
  1146. date. */
  1147. void
  1148. df_set_bb_dirty (basic_block bb)
  1149. {
  1150. bb->flags |= BB_MODIFIED;
  1151. if (df)
  1152. {
  1153. int p;
  1154. for (p = 1; p < df->num_problems_defined; p++)
  1155. {
  1156. struct dataflow *dflow = df->problems_in_order[p];
  1157. if (dflow->out_of_date_transfer_functions)
  1158. bitmap_set_bit (dflow->out_of_date_transfer_functions, bb->index);
  1159. }
  1160. df_mark_solutions_dirty ();
  1161. }
  1162. }
  1163. /* Grow the bb_info array. */
  1164. void
  1165. df_grow_bb_info (struct dataflow *dflow)
  1166. {
  1167. unsigned int new_size = last_basic_block + 1;
  1168. if (dflow->block_info_size < new_size)
  1169. {
  1170. new_size += new_size / 4;
  1171. dflow->block_info
  1172. = (void *)XRESIZEVEC (char, (char *)dflow->block_info,
  1173. new_size
  1174. * dflow->problem->block_info_elt_size);
  1175. memset ((char *)dflow->block_info
  1176. + dflow->block_info_size
  1177. * dflow->problem->block_info_elt_size,
  1178. 0,
  1179. (new_size - dflow->block_info_size)
  1180. * dflow->problem->block_info_elt_size);
  1181. dflow->block_info_size = new_size;
  1182. }
  1183. }
  1184. /* Clear the dirty bits. This is called from places that delete
  1185. blocks. */
  1186. static void
  1187. df_clear_bb_dirty (basic_block bb)
  1188. {
  1189. int p;
  1190. for (p = 1; p < df->num_problems_defined; p++)
  1191. {
  1192. struct dataflow *dflow = df->problems_in_order[p];
  1193. if (dflow->out_of_date_transfer_functions)
  1194. bitmap_clear_bit (dflow->out_of_date_transfer_functions, bb->index);
  1195. }
  1196. }
  1197. /* Called from the rtl_compact_blocks to reorganize the problems basic
  1198. block info. */
  1199. void
  1200. df_compact_blocks (void)
  1201. {
  1202. int i, p;
  1203. basic_block bb;
  1204. void *problem_temps;
  1205. bitmap_head tmp;
  1206. bitmap_initialize (&tmp, &df_bitmap_obstack);
  1207. for (p = 0; p < df->num_problems_defined; p++)
  1208. {
  1209. struct dataflow *dflow = df->problems_in_order[p];
  1210. /* Need to reorganize the out_of_date_transfer_functions for the
  1211. dflow problem. */
  1212. if (dflow->out_of_date_transfer_functions)
  1213. {
  1214. bitmap_copy (&tmp, dflow->out_of_date_transfer_functions);
  1215. bitmap_clear (dflow->out_of_date_transfer_functions);
  1216. if (bitmap_bit_p (&tmp, ENTRY_BLOCK))
  1217. bitmap_set_bit (dflow->out_of_date_transfer_functions, ENTRY_BLOCK);
  1218. if (bitmap_bit_p (&tmp, EXIT_BLOCK))
  1219. bitmap_set_bit (dflow->out_of_date_transfer_functions, EXIT_BLOCK);
  1220. i = NUM_FIXED_BLOCKS;
  1221. FOR_EACH_BB (bb)
  1222. {
  1223. if (bitmap_bit_p (&tmp, bb->index))
  1224. bitmap_set_bit (dflow->out_of_date_transfer_functions, i);
  1225. i++;
  1226. }
  1227. }
  1228. /* Now shuffle the block info for the problem. */
  1229. if (dflow->problem->free_bb_fun)
  1230. {
  1231. int size = last_basic_block * dflow->problem->block_info_elt_size;
  1232. problem_temps = XNEWVAR (char, size);
  1233. df_grow_bb_info (dflow);
  1234. memcpy (problem_temps, dflow->block_info, size);
  1235. /* Copy the bb info from the problem tmps to the proper
  1236. place in the block_info vector. Null out the copied
  1237. item. The entry and exit blocks never move. */
  1238. i = NUM_FIXED_BLOCKS;
  1239. FOR_EACH_BB (bb)
  1240. {
  1241. df_set_bb_info (dflow, i,
  1242. (char *)problem_temps
  1243. + bb->index * dflow->problem->block_info_elt_size);
  1244. i++;
  1245. }
  1246. memset ((char *)dflow->block_info
  1247. + i * dflow->problem->block_info_elt_size, 0,
  1248. (last_basic_block - i)
  1249. * dflow->problem->block_info_elt_size);
  1250. free (problem_temps);
  1251. }
  1252. }
  1253. /* Shuffle the bits in the basic_block indexed arrays. */
  1254. if (df->blocks_to_analyze)
  1255. {
  1256. if (bitmap_bit_p (&tmp, ENTRY_BLOCK))
  1257. bitmap_set_bit (df->blocks_to_analyze, ENTRY_BLOCK);
  1258. if (bitmap_bit_p (&tmp, EXIT_BLOCK))
  1259. bitmap_set_bit (df->blocks_to_analyze, EXIT_BLOCK);
  1260. bitmap_copy (&tmp, df->blocks_to_analyze);
  1261. bitmap_clear (df->blocks_to_analyze);
  1262. i = NUM_FIXED_BLOCKS;
  1263. FOR_EACH_BB (bb)
  1264. {
  1265. if (bitmap_bit_p (&tmp, bb->index))
  1266. bitmap_set_bit (df->blocks_to_analyze, i);
  1267. i++;
  1268. }
  1269. }
  1270. bitmap_clear (&tmp);
  1271. i = NUM_FIXED_BLOCKS;
  1272. FOR_EACH_BB (bb)
  1273. {
  1274. SET_BASIC_BLOCK (i, bb);
  1275. bb->index = i;
  1276. i++;
  1277. }
  1278. gcc_assert (i == n_basic_blocks);
  1279. for (; i < last_basic_block; i++)
  1280. SET_BASIC_BLOCK (i, NULL);
  1281. #ifdef DF_DEBUG_CFG
  1282. if (!df_lr->solutions_dirty)
  1283. df_set_clean_cfg ();
  1284. #endif
  1285. }
  1286. /* Shove NEW_BLOCK in at OLD_INDEX. Called from ifcvt to hack a
  1287. block. There is no excuse for people to do this kind of thing. */
  1288. void
  1289. df_bb_replace (int old_index, basic_block new_block)
  1290. {
  1291. int new_block_index = new_block->index;
  1292. int p;
  1293. if (dump_file)
  1294. fprintf (dump_file, "shoving block %d into %d\n", new_block_index, old_index);
  1295. gcc_assert (df);
  1296. gcc_assert (BASIC_BLOCK (old_index) == NULL);
  1297. for (p = 0; p < df->num_problems_defined; p++)
  1298. {
  1299. struct dataflow *dflow = df->problems_in_order[p];
  1300. if (dflow->block_info)
  1301. {
  1302. df_grow_bb_info (dflow);
  1303. df_set_bb_info (dflow, old_index,
  1304. df_get_bb_info (dflow, new_block_index));
  1305. }
  1306. }
  1307. df_clear_bb_dirty (new_block);
  1308. SET_BASIC_BLOCK (old_index, new_block);
  1309. new_block->index = old_index;
  1310. df_set_bb_dirty (BASIC_BLOCK (old_index));
  1311. SET_BASIC_BLOCK (new_block_index, NULL);
  1312. }
  1313. /* Free all of the per basic block dataflow from all of the problems.
  1314. This is typically called before a basic block is deleted and the
  1315. problem will be reanalyzed. */
  1316. void
  1317. df_bb_delete (int bb_index)
  1318. {
  1319. basic_block bb = BASIC_BLOCK (bb_index);
  1320. int i;
  1321. if (!df)
  1322. return;
  1323. for (i = 0; i < df->num_problems_defined; i++)
  1324. {
  1325. struct dataflow *dflow = df->problems_in_order[i];
  1326. if (dflow->problem->free_bb_fun)
  1327. {
  1328. void *bb_info = df_get_bb_info (dflow, bb_index);
  1329. if (bb_info)
  1330. {
  1331. dflow->problem->free_bb_fun (bb, bb_info);
  1332. df_clear_bb_info (dflow, bb_index);
  1333. }
  1334. }
  1335. }
  1336. df_clear_bb_dirty (bb);
  1337. df_mark_solutions_dirty ();
  1338. }
  1339. /* Verify that there is a place for everything and everything is in
  1340. its place. This is too expensive to run after every pass in the
  1341. mainline. However this is an excellent debugging tool if the
  1342. dataflow information is not being updated properly. You can just
  1343. sprinkle calls in until you find the place that is changing an
  1344. underlying structure without calling the proper updating
  1345. routine. */
  1346. void
  1347. df_verify (void)
  1348. {
  1349. df_scan_verify ();
  1350. #ifdef ENABLE_DF_CHECKING
  1351. df_lr_verify_transfer_functions ();
  1352. if (df_live)
  1353. df_live_verify_transfer_functions ();
  1354. #endif
  1355. }
  1356. #ifdef DF_DEBUG_CFG
  1357. /* Compute an array of ints that describes the cfg. This can be used
  1358. to discover places where the cfg is modified by the appropriate
  1359. calls have not been made to the keep df informed. The internals of
  1360. this are unexciting, the key is that two instances of this can be
  1361. compared to see if any changes have been made to the cfg. */
  1362. static int *
  1363. df_compute_cfg_image (void)
  1364. {
  1365. basic_block bb;
  1366. int size = 2 + (2 * n_basic_blocks);
  1367. int i;
  1368. int * map;
  1369. FOR_ALL_BB (bb)
  1370. {
  1371. size += EDGE_COUNT (bb->succs);
  1372. }
  1373. map = XNEWVEC (int, size);
  1374. map[0] = size;
  1375. i = 1;
  1376. FOR_ALL_BB (bb)
  1377. {
  1378. edge_iterator ei;
  1379. edge e;
  1380. map[i++] = bb->index;
  1381. FOR_EACH_EDGE (e, ei, bb->succs)
  1382. map[i++] = e->dest->index;
  1383. map[i++] = -1;
  1384. }
  1385. map[i] = -1;
  1386. return map;
  1387. }
  1388. static int *saved_cfg = NULL;
  1389. /* This function compares the saved version of the cfg with the
  1390. current cfg and aborts if the two are identical. The function
  1391. silently returns if the cfg has been marked as dirty or the two are
  1392. the same. */
  1393. void
  1394. df_check_cfg_clean (void)
  1395. {
  1396. int *new_map;
  1397. if (!df)
  1398. return;
  1399. if (df_lr->solutions_dirty)
  1400. return;
  1401. if (saved_cfg == NULL)
  1402. return;
  1403. new_map = df_compute_cfg_image ();
  1404. gcc_assert (memcmp (saved_cfg, new_map, saved_cfg[0] * sizeof (int)) == 0);
  1405. free (new_map);
  1406. }
  1407. /* This function builds a cfg fingerprint and squirrels it away in
  1408. saved_cfg. */
  1409. static void
  1410. df_set_clean_cfg (void)
  1411. {
  1412. free (saved_cfg);
  1413. saved_cfg = df_compute_cfg_image ();
  1414. }
  1415. #endif /* DF_DEBUG_CFG */
  1416. /*----------------------------------------------------------------------------
  1417. PUBLIC INTERFACES TO QUERY INFORMATION.
  1418. ----------------------------------------------------------------------------*/
  1419. /* Return first def of REGNO within BB. */
  1420. df_ref
  1421. df_bb_regno_first_def_find (basic_block bb, unsigned int regno)
  1422. {
  1423. rtx insn;
  1424. df_ref *def_rec;
  1425. unsigned int uid;
  1426. FOR_BB_INSNS (bb, insn)
  1427. {
  1428. if (!INSN_P (insn))
  1429. continue;
  1430. uid = INSN_UID (insn);
  1431. for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
  1432. {
  1433. df_ref def = *def_rec;
  1434. if (DF_REF_REGNO (def) == regno)
  1435. return def;
  1436. }
  1437. }
  1438. return NULL;
  1439. }
  1440. /* Return last def of REGNO within BB. */
  1441. df_ref
  1442. df_bb_regno_last_def_find (basic_block bb, unsigned int regno)
  1443. {
  1444. rtx insn;
  1445. df_ref *def_rec;
  1446. unsigned int uid;
  1447. FOR_BB_INSNS_REVERSE (bb, insn)
  1448. {
  1449. if (!INSN_P (insn))
  1450. continue;
  1451. uid = INSN_UID (insn);
  1452. for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
  1453. {
  1454. df_ref def = *def_rec;
  1455. if (DF_REF_REGNO (def) == regno)
  1456. return def;
  1457. }
  1458. }
  1459. return NULL;
  1460. }
  1461. /* Finds the reference corresponding to the definition of REG in INSN.
  1462. DF is the dataflow object. */
  1463. df_ref
  1464. df_find_def (rtx insn, rtx reg)
  1465. {
  1466. unsigned int uid;
  1467. df_ref *def_rec;
  1468. if (GET_CODE (reg) == SUBREG)
  1469. reg = SUBREG_REG (reg);
  1470. gcc_assert (REG_P (reg));
  1471. uid = INSN_UID (insn);
  1472. for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
  1473. {
  1474. df_ref def = *def_rec;
  1475. if (rtx_equal_p (DF_REF_REAL_REG (def), reg))
  1476. return def;
  1477. }
  1478. return NULL;
  1479. }
  1480. /* Return true if REG is defined in INSN, zero otherwise. */
  1481. bool
  1482. df_reg_defined (rtx insn, rtx reg)
  1483. {
  1484. return df_find_def (insn, reg) != NULL;
  1485. }
  1486. /* Finds the reference corresponding to the use of REG in INSN.
  1487. DF is the dataflow object. */
  1488. df_ref
  1489. df_find_use (rtx insn, rtx reg)
  1490. {
  1491. unsigned int uid;
  1492. df_ref *use_rec;
  1493. if (GET_CODE (reg) == SUBREG)
  1494. reg = SUBREG_REG (reg);
  1495. gcc_assert (REG_P (reg));
  1496. uid = INSN_UID (insn);
  1497. for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
  1498. {
  1499. df_ref use = *use_rec;
  1500. if (rtx_equal_p (DF_REF_REAL_REG (use), reg))
  1501. return use;
  1502. }
  1503. if (df->changeable_flags & DF_EQ_NOTES)
  1504. for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
  1505. {
  1506. df_ref use = *use_rec;
  1507. if (rtx_equal_p (DF_REF_REAL_REG (use), reg))
  1508. return use;
  1509. }
  1510. return NULL;
  1511. }
  1512. /* Return true if REG is referenced in INSN, zero otherwise. */
  1513. bool
  1514. df_reg_used (rtx insn, rtx reg)
  1515. {
  1516. return df_find_use (insn, reg) != NULL;
  1517. }
  1518. /*----------------------------------------------------------------------------
  1519. Debugging and printing functions.
  1520. ----------------------------------------------------------------------------*/
  1521. /* Write information about registers and basic blocks into FILE.
  1522. This is part of making a debugging dump. */
  1523. void
  1524. dump_regset (regset r, FILE *outf)
  1525. {
  1526. unsigned i;
  1527. reg_set_iterator rsi;
  1528. if (r == NULL)
  1529. {
  1530. fputs (" (nil)", outf);
  1531. return;
  1532. }
  1533. EXECUTE_IF_SET_IN_REG_SET (r, 0, i, rsi)
  1534. {
  1535. fprintf (outf, " %d", i);
  1536. if (i < FIRST_PSEUDO_REGISTER)
  1537. fprintf (outf, " [%s]",
  1538. reg_names[i]);
  1539. }
  1540. }
  1541. /* Print a human-readable representation of R on the standard error
  1542. stream. This function is designed to be used from within the
  1543. debugger. */
  1544. extern void debug_regset (regset);
  1545. DEBUG_FUNCTION void
  1546. debug_regset (regset r)
  1547. {
  1548. dump_regset (r, stderr);
  1549. putc ('\n', stderr);
  1550. }
  1551. /* Write information about registers and basic blocks into FILE.
  1552. This is part of making a debugging dump. */
  1553. void
  1554. df_print_regset (FILE *file, bitmap r)
  1555. {
  1556. unsigned int i;
  1557. bitmap_iterator bi;
  1558. if (r == NULL)
  1559. fputs (" (nil)", file);
  1560. else
  1561. {
  1562. EXECUTE_IF_SET_IN_BITMAP (r, 0, i, bi)
  1563. {
  1564. fprintf (file, " %d", i);
  1565. if (i < FIRST_PSEUDO_REGISTER)
  1566. fprintf (file, " [%s]", reg_names[i]);
  1567. }
  1568. }
  1569. fprintf (file, "\n");
  1570. }
  1571. /* Write information about registers and basic blocks into FILE. The
  1572. bitmap is in the form used by df_byte_lr. This is part of making a
  1573. debugging dump. */
  1574. void
  1575. df_print_word_regset (FILE *file, bitmap r)
  1576. {
  1577. unsigned int max_reg = max_reg_num ();
  1578. if (r == NULL)
  1579. fputs (" (nil)", file);
  1580. else
  1581. {
  1582. unsigned int i;
  1583. for (i = FIRST_PSEUDO_REGISTER; i < max_reg; i++)
  1584. {
  1585. bool found = (bitmap_bit_p (r, 2 * i)
  1586. || bitmap_bit_p (r, 2 * i + 1));
  1587. if (found)
  1588. {
  1589. int word;
  1590. const char * sep = "";
  1591. fprintf (file, " %d", i);
  1592. fprintf (file, "(");
  1593. for (word = 0; word < 2; word++)
  1594. if (bitmap_bit_p (r, 2 * i + word))
  1595. {
  1596. fprintf (file, "%s%d", sep, word);
  1597. sep = ", ";
  1598. }
  1599. fprintf (file, ")");
  1600. }
  1601. }
  1602. }
  1603. fprintf (file, "\n");
  1604. }
  1605. /* Dump dataflow info. */
  1606. void
  1607. df_dump (FILE *file)
  1608. {
  1609. basic_block bb;
  1610. df_dump_start (file);
  1611. FOR_ALL_BB (bb)
  1612. {
  1613. df_print_bb_index (bb, file);
  1614. df_dump_top (bb, file);
  1615. df_dump_bottom (bb, file);
  1616. }
  1617. fprintf (file, "\n");
  1618. }
  1619. /* Dump dataflow info for df->blocks_to_analyze. */
  1620. void
  1621. df_dump_region (FILE *file)
  1622. {
  1623. if (df->blocks_to_analyze)
  1624. {
  1625. bitmap_iterator bi;
  1626. unsigned int bb_index;
  1627. fprintf (file, "\n\nstarting region dump\n");
  1628. df_dump_start (file);
  1629. EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
  1630. {
  1631. basic_block bb = BASIC_BLOCK (bb_index);
  1632. df_print_bb_index (bb, file);
  1633. df_dump_top (bb, file);
  1634. df_dump_bottom (bb, file);
  1635. }
  1636. fprintf (file, "\n");
  1637. }
  1638. else
  1639. df_dump (file);
  1640. }
  1641. /* Dump the introductory information for each problem defined. */
  1642. void
  1643. df_dump_start (FILE *file)
  1644. {
  1645. int i;
  1646. if (!df || !file)
  1647. return;
  1648. fprintf (file, "\n\n%s\n", current_function_name ());
  1649. fprintf (file, "\nDataflow summary:\n");
  1650. if (df->blocks_to_analyze)
  1651. fprintf (file, "def_info->table_size = %d, use_info->table_size = %d\n",
  1652. DF_DEFS_TABLE_SIZE (), DF_USES_TABLE_SIZE ());
  1653. for (i = 0; i < df->num_problems_defined; i++)
  1654. {
  1655. struct dataflow *dflow = df->problems_in_order[i];
  1656. if (dflow->computed)
  1657. {
  1658. df_dump_problem_function fun = dflow->problem->dump_start_fun;
  1659. if (fun)
  1660. fun(file);
  1661. }
  1662. }
  1663. }
  1664. /* Dump the top of the block information for BB. */
  1665. void
  1666. df_dump_top (basic_block bb, FILE *file)
  1667. {
  1668. int i;
  1669. if (!df || !file)
  1670. return;
  1671. for (i = 0; i < df->num_problems_defined; i++)
  1672. {
  1673. struct dataflow *dflow = df->problems_in_order[i];
  1674. if (dflow->computed)
  1675. {
  1676. df_dump_bb_problem_function bbfun = dflow->problem->dump_top_fun;
  1677. if (bbfun)
  1678. bbfun (bb, file);
  1679. }
  1680. }
  1681. }
  1682. /* Dump the bottom of the block information for BB. */
  1683. void
  1684. df_dump_bottom (basic_block bb, FILE *file)
  1685. {
  1686. int i;
  1687. if (!df || !file)
  1688. return;
  1689. for (i = 0; i < df->num_problems_defined; i++)
  1690. {
  1691. struct dataflow *dflow = df->problems_in_order[i];
  1692. if (dflow->computed)
  1693. {
  1694. df_dump_bb_problem_function bbfun = dflow->problem->dump_bottom_fun;
  1695. if (bbfun)
  1696. bbfun (bb, file);
  1697. }
  1698. }
  1699. }
  1700. static void
  1701. df_ref_dump (df_ref ref, FILE *file)
  1702. {
  1703. fprintf (file, "%c%d(%d)",
  1704. DF_REF_REG_DEF_P (ref)
  1705. ? 'd'
  1706. : (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
  1707. DF_REF_ID (ref),
  1708. DF_REF_REGNO (ref));
  1709. }
  1710. void
  1711. df_refs_chain_dump (df_ref *ref_rec, bool follow_chain, FILE *file)
  1712. {
  1713. fprintf (file, "{ ");
  1714. while (*ref_rec)
  1715. {
  1716. df_ref ref = *ref_rec;
  1717. df_ref_dump (ref, file);
  1718. if (follow_chain)
  1719. df_chain_dump (DF_REF_CHAIN (ref), file);
  1720. ref_rec++;
  1721. }
  1722. fprintf (file, "}");
  1723. }
  1724. /* Dump either a ref-def or reg-use chain. */
  1725. void
  1726. df_regs_chain_dump (df_ref ref, FILE *file)
  1727. {
  1728. fprintf (file, "{ ");
  1729. while (ref)
  1730. {
  1731. df_ref_dump (ref, file);
  1732. ref = DF_REF_NEXT_REG (ref);
  1733. }
  1734. fprintf (file, "}");
  1735. }
  1736. static void
  1737. df_mws_dump (struct df_mw_hardreg **mws, FILE *file)
  1738. {
  1739. while (*mws)
  1740. {
  1741. fprintf (file, "mw %c r[%d..%d]\n",
  1742. (DF_MWS_REG_DEF_P (*mws)) ? 'd' : 'u',
  1743. (*mws)->start_regno, (*mws)->end_regno);
  1744. mws++;
  1745. }
  1746. }
  1747. static void
  1748. df_insn_uid_debug (unsigned int uid,
  1749. bool follow_chain, FILE *file)
  1750. {
  1751. fprintf (file, "insn %d luid %d",
  1752. uid, DF_INSN_UID_LUID (uid));
  1753. if (DF_INSN_UID_DEFS (uid))
  1754. {
  1755. fprintf (file, " defs ");
  1756. df_refs_chain_dump (DF_INSN_UID_DEFS (uid), follow_chain, file);
  1757. }
  1758. if (DF_INSN_UID_USES (uid))
  1759. {
  1760. fprintf (file, " uses ");
  1761. df_refs_chain_dump (DF_INSN_UID_USES (uid), follow_chain, file);
  1762. }
  1763. if (DF_INSN_UID_EQ_USES (uid))
  1764. {
  1765. fprintf (file, " eq uses ");
  1766. df_refs_chain_dump (DF_INSN_UID_EQ_USES (uid), follow_chain, file);
  1767. }
  1768. if (DF_INSN_UID_MWS (uid))
  1769. {
  1770. fprintf (file, " mws ");
  1771. df_mws_dump (DF_INSN_UID_MWS (uid), file);
  1772. }
  1773. fprintf (file, "\n");
  1774. }
  1775. DEBUG_FUNCTION void
  1776. df_insn_debug (rtx insn, bool follow_chain, FILE *file)
  1777. {
  1778. df_insn_uid_debug (INSN_UID (insn), follow_chain, file);
  1779. }
  1780. DEBUG_FUNCTION void
  1781. df_insn_debug_regno (rtx insn, FILE *file)
  1782. {
  1783. struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
  1784. fprintf (file, "insn %d bb %d luid %d defs ",
  1785. INSN_UID (insn), BLOCK_FOR_INSN (insn)->index,
  1786. DF_INSN_INFO_LUID (insn_info));
  1787. df_refs_chain_dump (DF_INSN_INFO_DEFS (insn_info), false, file);
  1788. fprintf (file, " uses ");
  1789. df_refs_chain_dump (DF_INSN_INFO_USES (insn_info), false, file);
  1790. fprintf (file, " eq_uses ");
  1791. df_refs_chain_dump (DF_INSN_INFO_EQ_USES (insn_info), false, file);
  1792. fprintf (file, "\n");
  1793. }
  1794. DEBUG_FUNCTION void
  1795. df_regno_debug (unsigned int regno, FILE *file)
  1796. {
  1797. fprintf (file, "reg %d defs ", regno);
  1798. df_regs_chain_dump (DF_REG_DEF_CHAIN (regno), file);
  1799. fprintf (file, " uses ");
  1800. df_regs_chain_dump (DF_REG_USE_CHAIN (regno), file);
  1801. fprintf (file, " eq_uses ");
  1802. df_regs_chain_dump (DF_REG_EQ_USE_CHAIN (regno), file);
  1803. fprintf (file, "\n");
  1804. }
  1805. DEBUG_FUNCTION void
  1806. df_ref_debug (df_ref ref, FILE *file)
  1807. {
  1808. fprintf (file, "%c%d ",
  1809. DF_REF_REG_DEF_P (ref) ? 'd' : 'u',
  1810. DF_REF_ID (ref));
  1811. fprintf (file, "reg %d bb %d insn %d flag %#x type %#x ",
  1812. DF_REF_REGNO (ref),
  1813. DF_REF_BBNO (ref),
  1814. DF_REF_IS_ARTIFICIAL (ref) ? -1 : DF_REF_INSN_UID (ref),
  1815. DF_REF_FLAGS (ref),
  1816. DF_REF_TYPE (ref));
  1817. if (DF_REF_LOC (ref))
  1818. {
  1819. if (flag_dump_noaddr)
  1820. fprintf (file, "loc #(#) chain ");
  1821. else
  1822. fprintf (file, "loc %p(%p) chain ", (void *)DF_REF_LOC (ref),
  1823. (void *)*DF_REF_LOC (ref));
  1824. }
  1825. else
  1826. fprintf (file, "chain ");
  1827. df_chain_dump (DF_REF_CHAIN (ref), file);
  1828. fprintf (file, "\n");
  1829. }
  1830. /* Functions for debugging from GDB. */
  1831. DEBUG_FUNCTION void
  1832. debug_df_insn (rtx insn)
  1833. {
  1834. df_insn_debug (insn, true, stderr);
  1835. debug_rtx (insn);
  1836. }
  1837. DEBUG_FUNCTION void
  1838. debug_df_reg (rtx reg)
  1839. {
  1840. df_regno_debug (REGNO (reg), stderr);
  1841. }
  1842. DEBUG_FUNCTION void
  1843. debug_df_regno (unsigned int regno)
  1844. {
  1845. df_regno_debug (regno, stderr);
  1846. }
  1847. DEBUG_FUNCTION void
  1848. debug_df_ref (df_ref ref)
  1849. {
  1850. df_ref_debug (ref, stderr);
  1851. }
  1852. DEBUG_FUNCTION void
  1853. debug_df_defno (unsigned int defno)
  1854. {
  1855. df_ref_debug (DF_DEFS_GET (defno), stderr);
  1856. }
  1857. DEBUG_FUNCTION void
  1858. debug_df_useno (unsigned int defno)
  1859. {
  1860. df_ref_debug (DF_USES_GET (defno), stderr);
  1861. }
  1862. DEBUG_FUNCTION void
  1863. debug_df_chain (struct df_link *link)
  1864. {
  1865. df_chain_dump (link, stderr);
  1866. fputc ('\n', stderr);
  1867. }