basic-block.h 19 KB

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