cfgloop.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /* Natural loop functions
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef GCC_CFGLOOP_H
  16. #define GCC_CFGLOOP_H
  17. #include "double-int.h"
  18. #include "wide-int.h"
  19. #include "bitmap.h"
  20. #include "sbitmap.h"
  21. #include "hashtab.h"
  22. #include "hash-set.h"
  23. #include "vec.h"
  24. #include "machmode.h"
  25. #include "tm.h"
  26. #include "hard-reg-set.h"
  27. #include "input.h"
  28. #include "function.h"
  29. #include "cfgloopmanip.h"
  30. /* Structure to hold decision about unrolling/peeling. */
  31. enum lpt_dec
  32. {
  33. LPT_NONE,
  34. LPT_UNROLL_CONSTANT,
  35. LPT_UNROLL_RUNTIME,
  36. LPT_UNROLL_STUPID
  37. };
  38. struct GTY (()) lpt_decision {
  39. enum lpt_dec decision;
  40. unsigned times;
  41. };
  42. /* The type of extend applied to an IV. */
  43. enum iv_extend_code
  44. {
  45. IV_SIGN_EXTEND,
  46. IV_ZERO_EXTEND,
  47. IV_UNKNOWN_EXTEND
  48. };
  49. /* The structure describing a bound on number of iterations of a loop. */
  50. struct GTY ((chain_next ("%h.next"))) nb_iter_bound {
  51. /* The statement STMT is executed at most ... */
  52. gimple stmt;
  53. /* ... BOUND + 1 times (BOUND must be an unsigned constant).
  54. The + 1 is added for the following reasons:
  55. a) 0 would otherwise be unused, while we would need to care more about
  56. overflows (as MAX + 1 is sometimes produced as the estimate on number
  57. of executions of STMT).
  58. b) it is consistent with the result of number_of_iterations_exit. */
  59. widest_int bound;
  60. /* True if the statement will cause the loop to be leaved the (at most)
  61. BOUND + 1-st time it is executed, that is, all the statements after it
  62. are executed at most BOUND times. */
  63. bool is_exit;
  64. /* The next bound in the list. */
  65. struct nb_iter_bound *next;
  66. };
  67. /* Description of the loop exit. */
  68. struct GTY ((for_user)) loop_exit {
  69. /* The exit edge. */
  70. edge e;
  71. /* Previous and next exit in the list of the exits of the loop. */
  72. struct loop_exit *prev;
  73. struct loop_exit *next;
  74. /* Next element in the list of loops from that E exits. */
  75. struct loop_exit *next_e;
  76. };
  77. struct loop_exit_hasher : ggc_hasher<loop_exit *>
  78. {
  79. typedef edge compare_type;
  80. static hashval_t hash (loop_exit *);
  81. static bool equal (loop_exit *, edge);
  82. static void remove (loop_exit *);
  83. };
  84. typedef struct loop *loop_p;
  85. /* An integer estimation of the number of iterations. Estimate_state
  86. describes what is the state of the estimation. */
  87. enum loop_estimation
  88. {
  89. /* Estimate was not computed yet. */
  90. EST_NOT_COMPUTED,
  91. /* Estimate is ready. */
  92. EST_AVAILABLE,
  93. EST_LAST
  94. };
  95. /* Structure to hold information for each natural loop. */
  96. struct GTY ((chain_next ("%h.next"))) loop {
  97. /* Index into loops array. */
  98. int num;
  99. /* Number of loop insns. */
  100. unsigned ninsns;
  101. /* Basic block of loop header. */
  102. basic_block header;
  103. /* Basic block of loop latch. */
  104. basic_block latch;
  105. /* For loop unrolling/peeling decision. */
  106. struct lpt_decision lpt_decision;
  107. /* Average number of executed insns per iteration. */
  108. unsigned av_ninsns;
  109. /* Number of blocks contained within the loop. */
  110. unsigned num_nodes;
  111. /* Superloops of the loop, starting with the outermost loop. */
  112. vec<loop_p, va_gc> *superloops;
  113. /* The first inner (child) loop or NULL if innermost loop. */
  114. struct loop *inner;
  115. /* Link to the next (sibling) loop. */
  116. struct loop *next;
  117. /* Auxiliary info specific to a pass. */
  118. PTR GTY ((skip (""))) aux;
  119. /* The number of times the latch of the loop is executed. This can be an
  120. INTEGER_CST, or a symbolic expression representing the number of
  121. iterations like "N - 1", or a COND_EXPR containing the runtime
  122. conditions under which the number of iterations is non zero.
  123. Don't access this field directly: number_of_latch_executions
  124. computes and caches the computed information in this field. */
  125. tree nb_iterations;
  126. /* An integer guaranteed to be greater or equal to nb_iterations. Only
  127. valid if any_upper_bound is true. */
  128. widest_int nb_iterations_upper_bound;
  129. /* An integer giving an estimate on nb_iterations. Unlike
  130. nb_iterations_upper_bound, there is no guarantee that it is at least
  131. nb_iterations. */
  132. widest_int nb_iterations_estimate;
  133. bool any_upper_bound;
  134. bool any_estimate;
  135. /* True if the loop can be parallel. */
  136. bool can_be_parallel;
  137. /* True if -Waggressive-loop-optimizations warned about this loop
  138. already. */
  139. bool warned_aggressive_loop_optimizations;
  140. /* An integer estimation of the number of iterations. Estimate_state
  141. describes what is the state of the estimation. */
  142. enum loop_estimation estimate_state;
  143. /* If > 0, an integer, where the user asserted that for any
  144. I in [ 0, nb_iterations ) and for any J in
  145. [ I, min ( I + safelen, nb_iterations ) ), the Ith and Jth iterations
  146. of the loop can be safely evaluated concurrently. */
  147. int safelen;
  148. /* True if this loop should never be vectorized. */
  149. bool dont_vectorize;
  150. /* True if we should try harder to vectorize this loop. */
  151. bool force_vectorize;
  152. /* For SIMD loops, this is a unique identifier of the loop, referenced
  153. by IFN_GOMP_SIMD_VF, IFN_GOMP_SIMD_LANE and IFN_GOMP_SIMD_LAST_LANE
  154. builtins. */
  155. tree simduid;
  156. /* Upper bound on number of iterations of a loop. */
  157. struct nb_iter_bound *bounds;
  158. /* Head of the cyclic list of the exits of the loop. */
  159. struct loop_exit *exits;
  160. /* Number of iteration analysis data for RTL. */
  161. struct niter_desc *simple_loop_desc;
  162. /* For sanity checking during loop fixup we record here the former
  163. loop header for loops marked for removal. Note that this prevents
  164. the basic-block from being collected but its index can still be
  165. reused. */
  166. basic_block former_header;
  167. };
  168. /* Flags for state of loop structure. */
  169. enum
  170. {
  171. LOOPS_HAVE_PREHEADERS = 1,
  172. LOOPS_HAVE_SIMPLE_LATCHES = 2,
  173. LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS = 4,
  174. LOOPS_HAVE_RECORDED_EXITS = 8,
  175. LOOPS_MAY_HAVE_MULTIPLE_LATCHES = 16,
  176. LOOP_CLOSED_SSA = 32,
  177. LOOPS_NEED_FIXUP = 64,
  178. LOOPS_HAVE_FALLTHRU_PREHEADERS = 128
  179. };
  180. #define LOOPS_NORMAL (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES \
  181. | LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS)
  182. #define AVOID_CFG_MODIFICATIONS (LOOPS_MAY_HAVE_MULTIPLE_LATCHES)
  183. /* Structure to hold CFG information about natural loops within a function. */
  184. struct GTY (()) loops {
  185. /* State of loops. */
  186. int state;
  187. /* Array of the loops. */
  188. vec<loop_p, va_gc> *larray;
  189. /* Maps edges to the list of their descriptions as loop exits. Edges
  190. whose sources or destinations have loop_father == NULL (which may
  191. happen during the cfg manipulations) should not appear in EXITS. */
  192. hash_table<loop_exit_hasher> *GTY(()) exits;
  193. /* Pointer to root of loop hierarchy tree. */
  194. struct loop *tree_root;
  195. };
  196. /* Loop recognition. */
  197. bool bb_loop_header_p (basic_block);
  198. void init_loops_structure (struct function *, struct loops *, unsigned);
  199. extern struct loops *flow_loops_find (struct loops *);
  200. extern void disambiguate_loops_with_multiple_latches (void);
  201. extern void flow_loops_free (struct loops *);
  202. extern void flow_loops_dump (FILE *,
  203. void (*)(const struct loop *, FILE *, int), int);
  204. extern void flow_loop_dump (const struct loop *, FILE *,
  205. void (*)(const struct loop *, FILE *, int), int);
  206. struct loop *alloc_loop (void);
  207. extern void flow_loop_free (struct loop *);
  208. int flow_loop_nodes_find (basic_block, struct loop *);
  209. unsigned fix_loop_structure (bitmap changed_bbs);
  210. bool mark_irreducible_loops (void);
  211. void release_recorded_exits (void);
  212. void record_loop_exits (void);
  213. void rescan_loop_exit (edge, bool, bool);
  214. /* Loop data structure manipulation/querying. */
  215. extern void flow_loop_tree_node_add (struct loop *, struct loop *);
  216. extern void flow_loop_tree_node_remove (struct loop *);
  217. extern bool flow_loop_nested_p (const struct loop *, const struct loop *);
  218. extern bool flow_bb_inside_loop_p (const struct loop *, const_basic_block);
  219. extern struct loop * find_common_loop (struct loop *, struct loop *);
  220. struct loop *superloop_at_depth (struct loop *, unsigned);
  221. struct eni_weights_d;
  222. extern int num_loop_insns (const struct loop *);
  223. extern int average_num_loop_insns (const struct loop *);
  224. extern unsigned get_loop_level (const struct loop *);
  225. extern bool loop_exit_edge_p (const struct loop *, const_edge);
  226. extern bool loop_exits_to_bb_p (struct loop *, basic_block);
  227. extern bool loop_exits_from_bb_p (struct loop *, basic_block);
  228. extern void mark_loop_exit_edges (void);
  229. extern location_t get_loop_location (struct loop *loop);
  230. /* Loops & cfg manipulation. */
  231. extern basic_block *get_loop_body (const struct loop *);
  232. extern unsigned get_loop_body_with_size (const struct loop *, basic_block *,
  233. unsigned);
  234. extern basic_block *get_loop_body_in_dom_order (const struct loop *);
  235. extern basic_block *get_loop_body_in_bfs_order (const struct loop *);
  236. extern basic_block *get_loop_body_in_custom_order (const struct loop *,
  237. int (*) (const void *, const void *));
  238. extern vec<edge> get_loop_exit_edges (const struct loop *);
  239. extern edge single_exit (const struct loop *);
  240. extern edge single_likely_exit (struct loop *loop);
  241. extern unsigned num_loop_branches (const struct loop *);
  242. extern edge loop_preheader_edge (const struct loop *);
  243. extern edge loop_latch_edge (const struct loop *);
  244. extern void add_bb_to_loop (basic_block, struct loop *);
  245. extern void remove_bb_from_loops (basic_block);
  246. extern void cancel_loop_tree (struct loop *);
  247. extern void delete_loop (struct loop *);
  248. extern void verify_loop_structure (void);
  249. /* Loop analysis. */
  250. extern bool just_once_each_iteration_p (const struct loop *, const_basic_block);
  251. gcov_type expected_loop_iterations_unbounded (const struct loop *);
  252. extern unsigned expected_loop_iterations (const struct loop *);
  253. extern rtx doloop_condition_get (rtx);
  254. void mark_loop_for_removal (loop_p);
  255. /* Induction variable analysis. */
  256. /* The description of induction variable. The things are a bit complicated
  257. due to need to handle subregs and extends. The value of the object described
  258. by it can be obtained as follows (all computations are done in extend_mode):
  259. Value in i-th iteration is
  260. delta + mult * extend_{extend_mode} (subreg_{mode} (base + i * step)).
  261. If first_special is true, the value in the first iteration is
  262. delta + mult * base
  263. If extend = UNKNOWN, first_special must be false, delta 0, mult 1 and value is
  264. subreg_{mode} (base + i * step)
  265. The get_iv_value function can be used to obtain these expressions.
  266. ??? Add a third mode field that would specify the mode in that inner
  267. computation is done, which would enable it to be different from the
  268. outer one? */
  269. struct rtx_iv
  270. {
  271. /* Its base and step (mode of base and step is supposed to be extend_mode,
  272. see the description above). */
  273. rtx base, step;
  274. /* The type of extend applied to it (IV_SIGN_EXTEND, IV_ZERO_EXTEND,
  275. or IV_UNKNOWN_EXTEND). */
  276. enum iv_extend_code extend;
  277. /* Operations applied in the extended mode. */
  278. rtx delta, mult;
  279. /* The mode it is extended to. */
  280. machine_mode extend_mode;
  281. /* The mode the variable iterates in. */
  282. machine_mode mode;
  283. /* Whether the first iteration needs to be handled specially. */
  284. unsigned first_special : 1;
  285. };
  286. /* The description of an exit from the loop and of the number of iterations
  287. till we take the exit. */
  288. struct GTY(()) niter_desc
  289. {
  290. /* The edge out of the loop. */
  291. edge out_edge;
  292. /* The other edge leading from the condition. */
  293. edge in_edge;
  294. /* True if we are able to say anything about number of iterations of the
  295. loop. */
  296. bool simple_p;
  297. /* True if the loop iterates the constant number of times. */
  298. bool const_iter;
  299. /* Number of iterations if constant. */
  300. uint64_t niter;
  301. /* Assumptions under that the rest of the information is valid. */
  302. rtx assumptions;
  303. /* Assumptions under that the loop ends before reaching the latch,
  304. even if value of niter_expr says otherwise. */
  305. rtx noloop_assumptions;
  306. /* Condition under that the loop is infinite. */
  307. rtx infinite;
  308. /* Whether the comparison is signed. */
  309. bool signed_p;
  310. /* The mode in that niter_expr should be computed. */
  311. machine_mode mode;
  312. /* The number of iterations of the loop. */
  313. rtx niter_expr;
  314. };
  315. extern void iv_analysis_loop_init (struct loop *);
  316. extern bool iv_analyze (rtx_insn *, rtx, struct rtx_iv *);
  317. extern bool iv_analyze_result (rtx_insn *, rtx, struct rtx_iv *);
  318. extern bool iv_analyze_expr (rtx_insn *, rtx, machine_mode,
  319. struct rtx_iv *);
  320. extern rtx get_iv_value (struct rtx_iv *, rtx);
  321. extern bool biv_p (rtx_insn *, rtx);
  322. extern void find_simple_exit (struct loop *, struct niter_desc *);
  323. extern void iv_analysis_done (void);
  324. extern struct niter_desc *get_simple_loop_desc (struct loop *loop);
  325. extern void free_simple_loop_desc (struct loop *loop);
  326. static inline struct niter_desc *
  327. simple_loop_desc (struct loop *loop)
  328. {
  329. return loop->simple_loop_desc;
  330. }
  331. /* Accessors for the loop structures. */
  332. /* Returns the loop with index NUM from FNs loop tree. */
  333. static inline struct loop *
  334. get_loop (struct function *fn, unsigned num)
  335. {
  336. return (*loops_for_fn (fn)->larray)[num];
  337. }
  338. /* Returns the number of superloops of LOOP. */
  339. static inline unsigned
  340. loop_depth (const struct loop *loop)
  341. {
  342. return vec_safe_length (loop->superloops);
  343. }
  344. /* Returns the immediate superloop of LOOP, or NULL if LOOP is the outermost
  345. loop. */
  346. static inline struct loop *
  347. loop_outer (const struct loop *loop)
  348. {
  349. unsigned n = vec_safe_length (loop->superloops);
  350. if (n == 0)
  351. return NULL;
  352. return (*loop->superloops)[n - 1];
  353. }
  354. /* Returns true if LOOP has at least one exit edge. */
  355. static inline bool
  356. loop_has_exit_edges (const struct loop *loop)
  357. {
  358. return loop->exits->next->e != NULL;
  359. }
  360. /* Returns the list of loops in FN. */
  361. inline vec<loop_p, va_gc> *
  362. get_loops (struct function *fn)
  363. {
  364. struct loops *loops = loops_for_fn (fn);
  365. if (!loops)
  366. return NULL;
  367. return loops->larray;
  368. }
  369. /* Returns the number of loops in FN (including the removed
  370. ones and the fake loop that forms the root of the loop tree). */
  371. static inline unsigned
  372. number_of_loops (struct function *fn)
  373. {
  374. struct loops *loops = loops_for_fn (fn);
  375. if (!loops)
  376. return 0;
  377. return vec_safe_length (loops->larray);
  378. }
  379. /* Returns true if state of the loops satisfies all properties
  380. described by FLAGS. */
  381. static inline bool
  382. loops_state_satisfies_p (unsigned flags)
  383. {
  384. return (current_loops->state & flags) == flags;
  385. }
  386. /* Sets FLAGS to the loops state. */
  387. static inline void
  388. loops_state_set (unsigned flags)
  389. {
  390. current_loops->state |= flags;
  391. }
  392. /* Clears FLAGS from the loops state. */
  393. static inline void
  394. loops_state_clear (unsigned flags)
  395. {
  396. if (!current_loops)
  397. return;
  398. current_loops->state &= ~flags;
  399. }
  400. /* Loop iterators. */
  401. /* Flags for loop iteration. */
  402. enum li_flags
  403. {
  404. LI_INCLUDE_ROOT = 1, /* Include the fake root of the loop tree. */
  405. LI_FROM_INNERMOST = 2, /* Iterate over the loops in the reverse order,
  406. starting from innermost ones. */
  407. LI_ONLY_INNERMOST = 4 /* Iterate only over innermost loops. */
  408. };
  409. /* The iterator for loops. */
  410. struct loop_iterator
  411. {
  412. loop_iterator (loop_p *loop, unsigned flags);
  413. ~loop_iterator ();
  414. inline loop_p next ();
  415. /* The list of loops to visit. */
  416. vec<int> to_visit;
  417. /* The index of the actual loop. */
  418. unsigned idx;
  419. };
  420. inline loop_p
  421. loop_iterator::next ()
  422. {
  423. int anum;
  424. while (this->to_visit.iterate (this->idx, &anum))
  425. {
  426. this->idx++;
  427. loop_p loop = get_loop (cfun, anum);
  428. if (loop)
  429. return loop;
  430. }
  431. return NULL;
  432. }
  433. inline
  434. loop_iterator::loop_iterator (loop_p *loop, unsigned flags)
  435. {
  436. struct loop *aloop;
  437. unsigned i;
  438. int mn;
  439. this->idx = 0;
  440. if (!current_loops)
  441. {
  442. this->to_visit.create (0);
  443. *loop = NULL;
  444. return;
  445. }
  446. this->to_visit.create (number_of_loops (cfun));
  447. mn = (flags & LI_INCLUDE_ROOT) ? 0 : 1;
  448. if (flags & LI_ONLY_INNERMOST)
  449. {
  450. for (i = 0; vec_safe_iterate (current_loops->larray, i, &aloop); i++)
  451. if (aloop != NULL
  452. && aloop->inner == NULL
  453. && aloop->num >= mn)
  454. this->to_visit.quick_push (aloop->num);
  455. }
  456. else if (flags & LI_FROM_INNERMOST)
  457. {
  458. /* Push the loops to LI->TO_VISIT in postorder. */
  459. for (aloop = current_loops->tree_root;
  460. aloop->inner != NULL;
  461. aloop = aloop->inner)
  462. continue;
  463. while (1)
  464. {
  465. if (aloop->num >= mn)
  466. this->to_visit.quick_push (aloop->num);
  467. if (aloop->next)
  468. {
  469. for (aloop = aloop->next;
  470. aloop->inner != NULL;
  471. aloop = aloop->inner)
  472. continue;
  473. }
  474. else if (!loop_outer (aloop))
  475. break;
  476. else
  477. aloop = loop_outer (aloop);
  478. }
  479. }
  480. else
  481. {
  482. /* Push the loops to LI->TO_VISIT in preorder. */
  483. aloop = current_loops->tree_root;
  484. while (1)
  485. {
  486. if (aloop->num >= mn)
  487. this->to_visit.quick_push (aloop->num);
  488. if (aloop->inner != NULL)
  489. aloop = aloop->inner;
  490. else
  491. {
  492. while (aloop != NULL && aloop->next == NULL)
  493. aloop = loop_outer (aloop);
  494. if (aloop == NULL)
  495. break;
  496. aloop = aloop->next;
  497. }
  498. }
  499. }
  500. *loop = this->next ();
  501. }
  502. inline
  503. loop_iterator::~loop_iterator ()
  504. {
  505. this->to_visit.release ();
  506. }
  507. #define FOR_EACH_LOOP(LOOP, FLAGS) \
  508. for (loop_iterator li(&(LOOP), FLAGS); \
  509. (LOOP); \
  510. (LOOP) = li.next ())
  511. /* The properties of the target. */
  512. struct target_cfgloop {
  513. /* Number of available registers. */
  514. unsigned x_target_avail_regs;
  515. /* Number of available registers that are call-clobbered. */
  516. unsigned x_target_clobbered_regs;
  517. /* Number of registers reserved for temporary expressions. */
  518. unsigned x_target_res_regs;
  519. /* The cost for register when there still is some reserve, but we are
  520. approaching the number of available registers. */
  521. unsigned x_target_reg_cost[2];
  522. /* The cost for register when we need to spill. */
  523. unsigned x_target_spill_cost[2];
  524. };
  525. extern struct target_cfgloop default_target_cfgloop;
  526. #if SWITCHABLE_TARGET
  527. extern struct target_cfgloop *this_target_cfgloop;
  528. #else
  529. #define this_target_cfgloop (&default_target_cfgloop)
  530. #endif
  531. #define target_avail_regs \
  532. (this_target_cfgloop->x_target_avail_regs)
  533. #define target_clobbered_regs \
  534. (this_target_cfgloop->x_target_clobbered_regs)
  535. #define target_res_regs \
  536. (this_target_cfgloop->x_target_res_regs)
  537. #define target_reg_cost \
  538. (this_target_cfgloop->x_target_reg_cost)
  539. #define target_spill_cost \
  540. (this_target_cfgloop->x_target_spill_cost)
  541. /* Register pressure estimation for induction variable optimizations & loop
  542. invariant motion. */
  543. extern unsigned estimate_reg_pressure_cost (unsigned, unsigned, bool, bool);
  544. extern void init_set_costs (void);
  545. /* Loop optimizer initialization. */
  546. extern void loop_optimizer_init (unsigned);
  547. extern void loop_optimizer_finalize (void);
  548. /* Optimization passes. */
  549. enum
  550. {
  551. UAP_UNROLL = 1, /* Enables unrolling of loops if it seems profitable. */
  552. UAP_UNROLL_ALL = 2 /* Enables unrolling of all loops. */
  553. };
  554. extern void doloop_optimize_loops (void);
  555. extern void move_loop_invariants (void);
  556. extern vec<basic_block> get_loop_hot_path (const struct loop *loop);
  557. /* Returns the outermost loop of the loop nest that contains LOOP.*/
  558. static inline struct loop *
  559. loop_outermost (struct loop *loop)
  560. {
  561. unsigned n = vec_safe_length (loop->superloops);
  562. if (n <= 1)
  563. return loop;
  564. return (*loop->superloops)[1];
  565. }
  566. extern void record_niter_bound (struct loop *, const widest_int &, bool, bool);
  567. extern HOST_WIDE_INT get_estimated_loop_iterations_int (struct loop *);
  568. extern HOST_WIDE_INT get_max_loop_iterations_int (struct loop *);
  569. extern bool get_estimated_loop_iterations (struct loop *loop, widest_int *nit);
  570. extern bool get_max_loop_iterations (struct loop *loop, widest_int *nit);
  571. extern int bb_loop_depth (const_basic_block);
  572. /* Converts VAL to widest_int. */
  573. static inline widest_int
  574. gcov_type_to_wide_int (gcov_type val)
  575. {
  576. HOST_WIDE_INT a[2];
  577. a[0] = (unsigned HOST_WIDE_INT) val;
  578. /* If HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_WIDEST_INT, avoid shifting by
  579. the size of type. */
  580. val >>= HOST_BITS_PER_WIDE_INT - 1;
  581. val >>= 1;
  582. a[1] = (unsigned HOST_WIDE_INT) val;
  583. return widest_int::from_array (a, 2);
  584. }
  585. #endif /* GCC_CFGLOOP_H */