basic-block.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /* Define control flow data structures for the CFG.
  2. Copyright (C) 1987-2019 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_BASIC_BLOCK_H
  16. #define GCC_BASIC_BLOCK_H
  17. #include <profile-count.h>
  18. /* Control flow edge information. */
  19. struct GTY((user)) edge_def {
  20. /* The two blocks at the ends of the edge. */
  21. basic_block src;
  22. basic_block dest;
  23. /* Instructions queued on the edge. */
  24. union edge_def_insns {
  25. gimple_seq g;
  26. rtx_insn *r;
  27. } insns;
  28. /* Auxiliary info specific to a pass. */
  29. PTR aux;
  30. /* Location of any goto implicit in the edge. */
  31. location_t goto_locus;
  32. /* The index number corresponding to this edge in the edge vector
  33. dest->preds. */
  34. unsigned int dest_idx;
  35. int flags; /* see cfg-flags.def */
  36. profile_probability probability;
  37. /* Return count of edge E. */
  38. inline profile_count count () const;
  39. };
  40. /* Masks for edge.flags. */
  41. #define DEF_EDGE_FLAG(NAME,IDX) EDGE_##NAME = 1 << IDX ,
  42. enum cfg_edge_flags {
  43. #include "cfg-flags.def"
  44. LAST_CFG_EDGE_FLAG /* this is only used for EDGE_ALL_FLAGS */
  45. };
  46. #undef DEF_EDGE_FLAG
  47. /* Bit mask for all edge flags. */
  48. #define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1)
  49. /* The following four flags all indicate something special about an edge.
  50. Test the edge flags on EDGE_COMPLEX to detect all forms of "strange"
  51. control flow transfers. */
  52. #define EDGE_COMPLEX \
  53. (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH | EDGE_PRESERVE)
  54. struct GTY(()) rtl_bb_info {
  55. /* The first insn of the block is embedded into bb->il.x. */
  56. /* The last insn of the block. */
  57. rtx_insn *end_;
  58. /* In CFGlayout mode points to insn notes/jumptables to be placed just before
  59. and after the block. */
  60. rtx_insn *header_;
  61. rtx_insn *footer_;
  62. };
  63. struct GTY(()) gimple_bb_info {
  64. /* Sequence of statements in this block. */
  65. gimple_seq seq;
  66. /* PHI nodes for this block. */
  67. gimple_seq phi_nodes;
  68. };
  69. /* A basic block is a sequence of instructions with only one entry and
  70. only one exit. If any one of the instructions are executed, they
  71. will all be executed, and in sequence from first to last.
  72. There may be COND_EXEC instructions in the basic block. The
  73. COND_EXEC *instructions* will be executed -- but if the condition
  74. is false the conditionally executed *expressions* will of course
  75. not be executed. We don't consider the conditionally executed
  76. expression (which might have side-effects) to be in a separate
  77. basic block because the program counter will always be at the same
  78. location after the COND_EXEC instruction, regardless of whether the
  79. condition is true or not.
  80. Basic blocks need not start with a label nor end with a jump insn.
  81. For example, a previous basic block may just "conditionally fall"
  82. into the succeeding basic block, and the last basic block need not
  83. end with a jump insn. Block 0 is a descendant of the entry block.
  84. A basic block beginning with two labels cannot have notes between
  85. the labels.
  86. Data for jump tables are stored in jump_insns that occur in no
  87. basic block even though these insns can follow or precede insns in
  88. basic blocks. */
  89. /* Basic block information indexed by block number. */
  90. struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def {
  91. /* The edges into and out of the block. */
  92. vec<edge, va_gc> *preds;
  93. vec<edge, va_gc> *succs;
  94. /* Auxiliary info specific to a pass. */
  95. PTR GTY ((skip (""))) aux;
  96. /* Innermost loop containing the block. */
  97. struct loop *loop_father;
  98. /* The dominance and postdominance information node. */
  99. struct et_node * GTY ((skip (""))) dom[2];
  100. /* Previous and next blocks in the chain. */
  101. basic_block prev_bb;
  102. basic_block next_bb;
  103. union basic_block_il_dependent {
  104. struct gimple_bb_info GTY ((tag ("0"))) gimple;
  105. struct {
  106. rtx_insn *head_;
  107. struct rtl_bb_info * rtl;
  108. } GTY ((tag ("1"))) x;
  109. } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il;
  110. /* Various flags. See cfg-flags.def. */
  111. int flags;
  112. /* The index of this block. */
  113. int index;
  114. /* Expected number of executions: calculated in profile.c. */
  115. profile_count count;
  116. /* The discriminator for this block. The discriminator distinguishes
  117. among several basic blocks that share a common locus, allowing for
  118. more accurate sample-based profiling. */
  119. int discriminator;
  120. };
  121. /* This ensures that struct gimple_bb_info is smaller than
  122. struct rtl_bb_info, so that inlining the former into basic_block_def
  123. is the better choice. */
  124. typedef int __assert_gimple_bb_smaller_rtl_bb
  125. [(int) sizeof (struct rtl_bb_info)
  126. - (int) sizeof (struct gimple_bb_info)];
  127. #define BB_FREQ_MAX 10000
  128. /* Masks for basic_block.flags. */
  129. #define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
  130. enum cfg_bb_flags
  131. {
  132. #include "cfg-flags.def"
  133. LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */
  134. };
  135. #undef DEF_BASIC_BLOCK_FLAG
  136. /* Bit mask for all basic block flags. */
  137. #define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
  138. /* Bit mask for all basic block flags that must be preserved. These are
  139. the bit masks that are *not* cleared by clear_bb_flags. */
  140. #define BB_FLAGS_TO_PRESERVE \
  141. (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
  142. | BB_HOT_PARTITION | BB_COLD_PARTITION)
  143. /* Dummy bitmask for convenience in the hot/cold partitioning code. */
  144. #define BB_UNPARTITIONED 0
  145. /* Partitions, to be used when partitioning hot and cold basic blocks into
  146. separate sections. */
  147. #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
  148. #define BB_SET_PARTITION(bb, part) do { \
  149. basic_block bb_ = (bb); \
  150. bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
  151. | (part)); \
  152. } while (0)
  153. #define BB_COPY_PARTITION(dstbb, srcbb) \
  154. BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
  155. /* Defines for accessing the fields of the CFG structure for function FN. */
  156. #define ENTRY_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_entry_block_ptr)
  157. #define EXIT_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_exit_block_ptr)
  158. #define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
  159. #define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
  160. #define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
  161. #define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
  162. #define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
  163. #define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
  164. #define BASIC_BLOCK_FOR_FN(FN,N) \
  165. ((*basic_block_info_for_fn (FN))[(N)])
  166. #define SET_BASIC_BLOCK_FOR_FN(FN,N,BB) \
  167. ((*basic_block_info_for_fn (FN))[(N)] = (BB))
  168. /* For iterating over basic blocks. */
  169. #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
  170. for (BB = FROM; BB != TO; BB = BB->DIR)
  171. #define FOR_EACH_BB_FN(BB, FN) \
  172. FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
  173. #define FOR_EACH_BB_REVERSE_FN(BB, FN) \
  174. FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
  175. /* For iterating over insns in basic block. */
  176. #define FOR_BB_INSNS(BB, INSN) \
  177. for ((INSN) = BB_HEAD (BB); \
  178. (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
  179. (INSN) = NEXT_INSN (INSN))
  180. /* For iterating over insns in basic block when we might remove the
  181. current insn. */
  182. #define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
  183. for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \
  184. (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
  185. (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
  186. #define FOR_BB_INSNS_REVERSE(BB, INSN) \
  187. for ((INSN) = BB_END (BB); \
  188. (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
  189. (INSN) = PREV_INSN (INSN))
  190. #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
  191. for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
  192. (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
  193. (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
  194. /* Cycles through _all_ basic blocks, even the fake ones (entry and
  195. exit block). */
  196. #define FOR_ALL_BB_FN(BB, FN) \
  197. for (BB = ENTRY_BLOCK_PTR_FOR_FN (FN); BB; BB = BB->next_bb)
  198. /* Stuff for recording basic block info. */
  199. /* For now, these will be functions (so that they can include checked casts
  200. to rtx_insn. Once the underlying fields are converted from rtx
  201. to rtx_insn, these can be converted back to macros. */
  202. #define BB_HEAD(B) (B)->il.x.head_
  203. #define BB_END(B) (B)->il.x.rtl->end_
  204. #define BB_HEADER(B) (B)->il.x.rtl->header_
  205. #define BB_FOOTER(B) (B)->il.x.rtl->footer_
  206. /* Special block numbers [markers] for entry and exit.
  207. Neither of them is supposed to hold actual statements. */
  208. #define ENTRY_BLOCK (0)
  209. #define EXIT_BLOCK (1)
  210. /* The two blocks that are always in the cfg. */
  211. #define NUM_FIXED_BLOCKS (2)
  212. /* This is the value which indicates no edge is present. */
  213. #define EDGE_INDEX_NO_EDGE -1
  214. /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
  215. if there is no edge between the 2 basic blocks. */
  216. #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
  217. /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
  218. block which is either the pred or succ end of the indexed edge. */
  219. #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
  220. #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
  221. /* INDEX_EDGE returns a pointer to the edge. */
  222. #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
  223. /* Number of edges in the compressed edge list. */
  224. #define NUM_EDGES(el) ((el)->num_edges)
  225. /* BB is assumed to contain conditional jump. Return the fallthru edge. */
  226. #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
  227. ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
  228. /* BB is assumed to contain conditional jump. Return the branch edge. */
  229. #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
  230. ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
  231. /* Return expected execution frequency of the edge E. */
  232. #define EDGE_FREQUENCY(e) e->count ().to_frequency (cfun)
  233. /* Compute a scale factor (or probability) suitable for scaling of
  234. gcov_type values via apply_probability() and apply_scale(). */
  235. #define GCOV_COMPUTE_SCALE(num,den) \
  236. ((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE)
  237. /* Return nonzero if edge is critical. */
  238. #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
  239. && EDGE_COUNT ((e)->dest->preds) >= 2)
  240. #define EDGE_COUNT(ev) vec_safe_length (ev)
  241. #define EDGE_I(ev,i) (*ev)[(i)]
  242. #define EDGE_PRED(bb,i) (*(bb)->preds)[(i)]
  243. #define EDGE_SUCC(bb,i) (*(bb)->succs)[(i)]
  244. /* Returns true if BB has precisely one successor. */
  245. static inline bool
  246. single_succ_p (const_basic_block bb)
  247. {
  248. return EDGE_COUNT (bb->succs) == 1;
  249. }
  250. /* Returns true if BB has precisely one predecessor. */
  251. static inline bool
  252. single_pred_p (const_basic_block bb)
  253. {
  254. return EDGE_COUNT (bb->preds) == 1;
  255. }
  256. /* Returns the single successor edge of basic block BB. Aborts if
  257. BB does not have exactly one successor. */
  258. static inline edge
  259. single_succ_edge (const_basic_block bb)
  260. {
  261. gcc_checking_assert (single_succ_p (bb));
  262. return EDGE_SUCC (bb, 0);
  263. }
  264. /* Returns the single predecessor edge of basic block BB. Aborts
  265. if BB does not have exactly one predecessor. */
  266. static inline edge
  267. single_pred_edge (const_basic_block bb)
  268. {
  269. gcc_checking_assert (single_pred_p (bb));
  270. return EDGE_PRED (bb, 0);
  271. }
  272. /* Returns the single successor block of basic block BB. Aborts
  273. if BB does not have exactly one successor. */
  274. static inline basic_block
  275. single_succ (const_basic_block bb)
  276. {
  277. return single_succ_edge (bb)->dest;
  278. }
  279. /* Returns the single predecessor block of basic block BB. Aborts
  280. if BB does not have exactly one predecessor.*/
  281. static inline basic_block
  282. single_pred (const_basic_block bb)
  283. {
  284. return single_pred_edge (bb)->src;
  285. }
  286. /* Iterator object for edges. */
  287. struct edge_iterator {
  288. unsigned index;
  289. vec<edge, va_gc> **container;
  290. };
  291. static inline vec<edge, va_gc> *
  292. ei_container (edge_iterator i)
  293. {
  294. gcc_checking_assert (i.container);
  295. return *i.container;
  296. }
  297. #define ei_start(iter) ei_start_1 (&(iter))
  298. #define ei_last(iter) ei_last_1 (&(iter))
  299. /* Return an iterator pointing to the start of an edge vector. */
  300. static inline edge_iterator
  301. ei_start_1 (vec<edge, va_gc> **ev)
  302. {
  303. edge_iterator i;
  304. i.index = 0;
  305. i.container = ev;
  306. return i;
  307. }
  308. /* Return an iterator pointing to the last element of an edge
  309. vector. */
  310. static inline edge_iterator
  311. ei_last_1 (vec<edge, va_gc> **ev)
  312. {
  313. edge_iterator i;
  314. i.index = EDGE_COUNT (*ev) - 1;
  315. i.container = ev;
  316. return i;
  317. }
  318. /* Is the iterator `i' at the end of the sequence? */
  319. static inline bool
  320. ei_end_p (edge_iterator i)
  321. {
  322. return (i.index == EDGE_COUNT (ei_container (i)));
  323. }
  324. /* Is the iterator `i' at one position before the end of the
  325. sequence? */
  326. static inline bool
  327. ei_one_before_end_p (edge_iterator i)
  328. {
  329. return (i.index + 1 == EDGE_COUNT (ei_container (i)));
  330. }
  331. /* Advance the iterator to the next element. */
  332. static inline void
  333. ei_next (edge_iterator *i)
  334. {
  335. gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i)));
  336. i->index++;
  337. }
  338. /* Move the iterator to the previous element. */
  339. static inline void
  340. ei_prev (edge_iterator *i)
  341. {
  342. gcc_checking_assert (i->index > 0);
  343. i->index--;
  344. }
  345. /* Return the edge pointed to by the iterator `i'. */
  346. static inline edge
  347. ei_edge (edge_iterator i)
  348. {
  349. return EDGE_I (ei_container (i), i.index);
  350. }
  351. /* Return an edge pointed to by the iterator. Do it safely so that
  352. NULL is returned when the iterator is pointing at the end of the
  353. sequence. */
  354. static inline edge
  355. ei_safe_edge (edge_iterator i)
  356. {
  357. return !ei_end_p (i) ? ei_edge (i) : NULL;
  358. }
  359. /* Return 1 if we should continue to iterate. Return 0 otherwise.
  360. *Edge P is set to the next edge if we are to continue to iterate
  361. and NULL otherwise. */
  362. static inline bool
  363. ei_cond (edge_iterator ei, edge *p)
  364. {
  365. if (!ei_end_p (ei))
  366. {
  367. *p = ei_edge (ei);
  368. return 1;
  369. }
  370. else
  371. {
  372. *p = NULL;
  373. return 0;
  374. }
  375. }
  376. /* This macro serves as a convenient way to iterate each edge in a
  377. vector of predecessor or successor edges. It must not be used when
  378. an element might be removed during the traversal, otherwise
  379. elements will be missed. Instead, use a for-loop like that shown
  380. in the following pseudo-code:
  381. FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
  382. {
  383. IF (e != taken_edge)
  384. remove_edge (e);
  385. ELSE
  386. ei_next (&ei);
  387. }
  388. */
  389. #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
  390. for ((ITER) = ei_start ((EDGE_VEC)); \
  391. ei_cond ((ITER), &(EDGE)); \
  392. ei_next (&(ITER)))
  393. #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
  394. except for edge forwarding */
  395. #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
  396. #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
  397. to care REG_DEAD notes. */
  398. #define CLEANUP_THREADING 8 /* Do jump threading. */
  399. #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
  400. insns. */
  401. #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
  402. #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
  403. #define CLEANUP_NO_PARTITIONING 128 /* Do not try to fix partitions. */
  404. /* Return true if BB is in a transaction. */
  405. static inline bool
  406. bb_in_transaction (basic_block bb)
  407. {
  408. return bb->flags & BB_IN_TRANSACTION;
  409. }
  410. /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
  411. static inline bool
  412. bb_has_eh_pred (basic_block bb)
  413. {
  414. edge e;
  415. edge_iterator ei;
  416. FOR_EACH_EDGE (e, ei, bb->preds)
  417. {
  418. if (e->flags & EDGE_EH)
  419. return true;
  420. }
  421. return false;
  422. }
  423. /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
  424. static inline bool
  425. bb_has_abnormal_pred (basic_block bb)
  426. {
  427. edge e;
  428. edge_iterator ei;
  429. FOR_EACH_EDGE (e, ei, bb->preds)
  430. {
  431. if (e->flags & EDGE_ABNORMAL)
  432. return true;
  433. }
  434. return false;
  435. }
  436. /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
  437. static inline edge
  438. find_fallthru_edge (vec<edge, va_gc> *edges)
  439. {
  440. edge e;
  441. edge_iterator ei;
  442. FOR_EACH_EDGE (e, ei, edges)
  443. if (e->flags & EDGE_FALLTHRU)
  444. break;
  445. return e;
  446. }
  447. /* Check tha probability is sane. */
  448. static inline void
  449. check_probability (int prob)
  450. {
  451. gcc_checking_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
  452. }
  453. /* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE.
  454. Used to combine BB probabilities. */
  455. static inline int
  456. combine_probabilities (int prob1, int prob2)
  457. {
  458. check_probability (prob1);
  459. check_probability (prob2);
  460. return RDIV (prob1 * prob2, REG_BR_PROB_BASE);
  461. }
  462. /* Apply scale factor SCALE on frequency or count FREQ. Use this
  463. interface when potentially scaling up, so that SCALE is not
  464. constrained to be < REG_BR_PROB_BASE. */
  465. static inline gcov_type
  466. apply_scale (gcov_type freq, gcov_type scale)
  467. {
  468. return RDIV (freq * scale, REG_BR_PROB_BASE);
  469. }
  470. /* Apply probability PROB on frequency or count FREQ. */
  471. static inline gcov_type
  472. apply_probability (gcov_type freq, int prob)
  473. {
  474. check_probability (prob);
  475. return apply_scale (freq, prob);
  476. }
  477. /* Return inverse probability for PROB. */
  478. static inline int
  479. inverse_probability (int prob1)
  480. {
  481. check_probability (prob1);
  482. return REG_BR_PROB_BASE - prob1;
  483. }
  484. /* Return true if BB has at least one abnormal outgoing edge. */
  485. static inline bool
  486. has_abnormal_or_eh_outgoing_edge_p (basic_block bb)
  487. {
  488. edge e;
  489. edge_iterator ei;
  490. FOR_EACH_EDGE (e, ei, bb->succs)
  491. if (e->flags & (EDGE_ABNORMAL | EDGE_EH))
  492. return true;
  493. return false;
  494. }
  495. /* Return true when one of the predecessor edges of BB is marked with
  496. EDGE_ABNORMAL_CALL or EDGE_EH. */
  497. static inline bool
  498. has_abnormal_call_or_eh_pred_edge_p (basic_block bb)
  499. {
  500. edge e;
  501. edge_iterator ei;
  502. FOR_EACH_EDGE (e, ei, bb->preds)
  503. if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
  504. return true;
  505. return false;
  506. }
  507. /* Return count of edge E. */
  508. inline profile_count edge_def::count () const
  509. {
  510. return src->count.apply_probability (probability);
  511. }
  512. #endif /* GCC_BASIC_BLOCK_H */