cleanup_cfg. Following optimizations are performed:
- Unreachable blocks removal
- - Edge forwarding (edge to the forwarder block is forwarded to it's
+ - Edge forwarding (edge to the forwarder block is forwarded to its
successor. Simplification of the branch instruction is performed by
underlying infrastructure so branch can be converted to simplejump or
eliminated).
#include "tm_p.h"
#include "target.h"
#include "regs.h"
+#include "cfglayout.h"
+#include "expr.h"
/* cleanup_cfg maintains following flags for each basic block. */
static void notice_new_block (basic_block);
static void update_forwarder_flag (basic_block);
static int mentions_nonequal_regs (rtx *, void *);
+static void merge_memattrs (rtx, rtx);
\f
/* Set flags for newly created block. */
return false;
jump_dest_block = jump_block->succ->dest;
+ /* If we are partitioning hot/cold basic blocks, we don't want to
+ mess up unconditional or indirect jumps that cross between hot
+ and cold sections. */
+
+ if (flag_reorder_blocks_and_partition
+ && (jump_block->partition != jump_dest_block->partition
+ || cbranch_jump_edge->crossing_edge))
+ return false;
+
/* The conditional branch must target the block after the
unconditional branch. */
cbranch_dest_block = cbranch_jump_edge->dest;
bool changed = false;
edge e, next, *threaded_edges = NULL;
+ /* If we are partitioning hot/cold basic blocks, we don't want to
+ mess up unconditional or indirect jumps that cross between hot
+ and cold sections. */
+
+ if (flag_reorder_blocks_and_partition
+ && find_reg_note (BB_END (b), REG_CROSSING_JUMP, NULL_RTX))
+ return false;
+
for (e = b->succ; e; e = next)
{
basic_block target, first;
{
rtx barrier;
+ /* If we are partitioning hot/cold basic blocks, we don't want to
+ mess up unconditional or indirect jumps that cross between hot
+ and cold sections. */
+
+ if (flag_reorder_blocks_and_partition
+ && (a->partition != b->partition
+ || find_reg_note (BB_END (a), REG_CROSSING_JUMP, NULL_RTX)))
+ return;
+
barrier = next_nonnote_insn (BB_END (a));
if (GET_CODE (barrier) != BARRIER)
abort ();
rtx barrier, real_b_end;
rtx label, table;
+ /* If we are partitioning hot/cold basic blocks, we don't want to
+ mess up unconditional or indirect jumps that cross between hot
+ and cold sections. */
+
+ if (flag_reorder_blocks_and_partition
+ && (find_reg_note (BB_END (a), REG_CROSSING_JUMP, NULL_RTX)
+ || a->partition != b->partition))
+ return;
+
real_b_end = BB_END (b);
/* If there is a jump table following block B temporarily add the jump table
&& tail_recursion_label_p (BB_HEAD (c)))
return NULL;
+ /* If we are partitioning hot/cold basic blocks, we don't want to
+ mess up unconditional or indirect jumps that cross between hot
+ and cold sections. */
+
+ if (flag_reorder_blocks_and_partition
+ && (find_reg_note (BB_END (b), REG_CROSSING_JUMP, NULL_RTX)
+ || find_reg_note (BB_END (c), REG_CROSSING_JUMP, NULL_RTX)
+ || b->partition != c->partition))
+ return NULL;
+
+
+
/* If B has a fallthru edge to C, no need to move anything. */
if (e->flags & EDGE_FALLTHRU)
{
}
\f
+/* Removes the memory attributes of MEM expression
+ if they are not equal. */
+
+void
+merge_memattrs (rtx x, rtx y)
+{
+ int i;
+ int j;
+ enum rtx_code code;
+ const char *fmt;
+
+ if (x == y)
+ return;
+ if (x == 0 || y == 0)
+ return;
+
+ code = GET_CODE (x);
+
+ if (code != GET_CODE (y))
+ return;
+
+ if (GET_MODE (x) != GET_MODE (y))
+ return;
+
+ if (code == MEM && MEM_ATTRS (x) != MEM_ATTRS (y))
+ {
+ if (! MEM_ATTRS (x))
+ MEM_ATTRS (y) = 0;
+ else if (! MEM_ATTRS (y))
+ MEM_ATTRS (x) = 0;
+ else
+ {
+ if (MEM_ALIAS_SET (x) != MEM_ALIAS_SET (y))
+ {
+ set_mem_alias_set (x, 0);
+ set_mem_alias_set (y, 0);
+ }
+
+ if (! mem_expr_equal_p (MEM_EXPR (x), MEM_EXPR (y)))
+ {
+ set_mem_expr (x, 0);
+ set_mem_expr (y, 0);
+ set_mem_offset (x, 0);
+ set_mem_offset (y, 0);
+ }
+ else if (MEM_OFFSET (x) != MEM_OFFSET (y))
+ {
+ set_mem_offset (x, 0);
+ set_mem_offset (y, 0);
+ }
+
+ set_mem_size (x, MAX (MEM_SIZE (x), MEM_SIZE (y)));
+ set_mem_size (y, MEM_SIZE (x));
+
+ set_mem_align (x, MIN (MEM_ALIGN (x), MEM_ALIGN (y)));
+ set_mem_align (y, MEM_ALIGN (x));
+ }
+ }
+
+ fmt = GET_RTX_FORMAT (code);
+ for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
+ {
+ switch (fmt[i])
+ {
+ case 'E':
+ /* Two vectors must have the same length. */
+ if (XVECLEN (x, i) != XVECLEN (y, i))
+ return;
+
+ for (j = 0; j < XVECLEN (x, i); j++)
+ merge_memattrs (XVECEXP (x, i, j), XVECEXP (y, i, j));
+
+ break;
+
+ case 'e':
+ merge_memattrs (XEXP (x, i), XEXP (y, i));
+ }
+ }
+ return;
+}
+
+
/* Return true if I1 and I2 are equivalent and thus can be crossjumped. */
static bool
if (!insns_match_p (mode, i1, i2))
break;
+ merge_memattrs (i1, i2);
+
/* Don't begin a cross-jump with a NOTE insn. */
if (INSN_P (i1))
{
rtx newpos1, newpos2;
edge s;
+ /* If we have partitioned hot/cold basic blocks, it is a bad idea
+ to try this optimization. */
+
+ if (flag_reorder_blocks_and_partition && no_new_pseudos)
+ return false;
+
/* Search backward through forwarder blocks. We don't need to worry
about multiple entry or chained forwarders, as they will be optimized
away. We do this to look past the unconditional jump following a
if (!bb->pred || !bb->pred->pred_next)
return false;
+ /* If we are partitioning hot/cold basic blocks, we don't want to
+ mess up unconditional or indirect jumps that cross between hot
+ and cold sections. */
+
+ if (flag_reorder_blocks_and_partition
+ && (bb->pred->src->partition != bb->pred->pred_next->src->partition
+ || bb->pred->crossing_edge))
+ return false;
+
/* It is always cheapest to redirect a block that ends in a branch to
a block that falls through into BB, as that adds no branches to the
program. We'll try that combination first. */
if (mode & (CLEANUP_UPDATE_LIFE | CLEANUP_CROSSJUMP | CLEANUP_THREADING))
clear_bb_flags ();
- if (! (* targetm.cannot_modify_jumps_p) ())
+ if (! targetm.cannot_modify_jumps_p ())
{
first_pass = true;
/* Attempt to merge blocks as made possible by edge removal. If
&& ! b->succ->succ_next
&& b->succ->dest != EXIT_BLOCK_PTR
&& onlyjump_p (BB_END (b))
+ && !find_reg_note (BB_END (b), REG_CROSSING_JUMP, NULL_RTX)
&& try_redirect_by_replacing_jump (b->succ, b->succ->dest,
(mode & CLEANUP_CFGLAYOUT) != 0))
{