#include "cfgloop.h"
#include "tree-pass.h"
#include "print-rtl.h"
+#include "rtl-iter.h"
+#include "gimplify.h"
/* Disable warnings about missing quoting in GCC diagnostics. */
#if __GNUC__ >= 10
}
rtx_insn *
-duplicate_insn_chain (rtx_insn *from, rtx_insn *to)
+duplicate_insn_chain (rtx_insn *from, rtx_insn *to,
+ class loop *loop, copy_bb_data *id)
{
rtx_insn *insn, *next, *copy;
rtx_note *last;
&& ANY_RETURN_P (JUMP_LABEL (insn)))
JUMP_LABEL (copy) = JUMP_LABEL (insn);
maybe_copy_prologue_epilogue_insn (insn, copy);
+ /* If requested remap dependence info of cliques brought in
+ via inlining. */
+ if (id)
+ {
+ subrtx_iterator::array_type array;
+ FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
+ if (MEM_P (*iter) && MEM_EXPR (*iter))
+ {
+ tree op = MEM_EXPR (*iter);
+ if (TREE_CODE (op) == WITH_SIZE_EXPR)
+ op = TREE_OPERAND (op, 0);
+ while (handled_component_p (op))
+ op = TREE_OPERAND (op, 0);
+ if ((TREE_CODE (op) == MEM_REF
+ || TREE_CODE (op) == TARGET_MEM_REF)
+ && MR_DEPENDENCE_CLIQUE (op) > 1
+ && (!loop
+ || (MR_DEPENDENCE_CLIQUE (op)
+ != loop->owned_clique)))
+ {
+ if (!id->dependence_map)
+ id->dependence_map = new hash_map<dependence_hash,
+ unsigned short>;
+ bool existed;
+ unsigned short &newc = id->dependence_map->get_or_insert
+ (MR_DEPENDENCE_CLIQUE (op), &existed);
+ if (!existed)
+ {
+ gcc_assert
+ (MR_DEPENDENCE_CLIQUE (op) <= cfun->last_clique);
+ newc = ++cfun->last_clique;
+ }
+ /* We cannot adjust MR_DEPENDENCE_CLIQUE in-place
+ since MEM_EXPR is shared so make a copy and
+ walk to the subtree again. */
+ tree new_expr = unshare_expr (MEM_EXPR (*iter));
+ if (TREE_CODE (new_expr) == WITH_SIZE_EXPR)
+ new_expr = TREE_OPERAND (new_expr, 0);
+ while (handled_component_p (new_expr))
+ new_expr = TREE_OPERAND (new_expr, 0);
+ MR_DEPENDENCE_CLIQUE (new_expr) = newc;
+ set_mem_expr (const_cast <rtx> (*iter), new_expr);
+ }
+ }
+ }
break;
case JUMP_TABLE_DATA:
/* Create a duplicate of the basic block BB. */
static basic_block
-cfg_layout_duplicate_bb (basic_block bb, copy_bb_data *)
+cfg_layout_duplicate_bb (basic_block bb, copy_bb_data *id)
{
rtx_insn *insn;
basic_block new_bb;
- insn = duplicate_insn_chain (BB_HEAD (bb), BB_END (bb));
+ class loop *loop = (id && current_loops) ? bb->loop_father : NULL;
+
+ insn = duplicate_insn_chain (BB_HEAD (bb), BB_END (bb), loop, id);
new_bb = create_basic_block (insn,
insn ? get_last_insn () : NULL,
EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb);
insn = BB_HEADER (bb);
while (NEXT_INSN (insn))
insn = NEXT_INSN (insn);
- insn = duplicate_insn_chain (BB_HEADER (bb), insn);
+ insn = duplicate_insn_chain (BB_HEADER (bb), insn, loop, id);
if (insn)
BB_HEADER (new_bb) = unlink_insn_chain (insn, get_last_insn ());
}
insn = BB_FOOTER (bb);
while (NEXT_INSN (insn))
insn = NEXT_INSN (insn);
- insn = duplicate_insn_chain (BB_FOOTER (bb), insn);
+ insn = duplicate_insn_chain (BB_FOOTER (bb), insn, loop, id);
if (insn)
BB_FOOTER (new_bb) = unlink_insn_chain (insn, get_last_insn ());
}
static void
duplicate_insns_of_cycles (partial_schedule_ptr ps, int from_stage,
- int to_stage, rtx count_reg)
+ int to_stage, rtx count_reg, class loop *loop)
{
int row;
ps_insn_ptr ps_ij;
+ copy_bb_data id;
for (row = 0; row < ps->ii; row++)
for (ps_ij = ps->rows[row]; ps_ij; ps_ij = ps_ij->next_in_row)
if (from_stage <= last_u && to_stage >= first_u)
{
if (u < ps->g->num_nodes)
- duplicate_insn_chain (ps_first_note (ps, u), u_insn);
+ duplicate_insn_chain (ps_first_note (ps, u), u_insn,
+ loop, &id);
else
emit_insn (copy_rtx (PATTERN (u_insn)));
}
}
for (i = 0; i < last_stage; i++)
- duplicate_insns_of_cycles (ps, 0, i, count_reg);
+ duplicate_insns_of_cycles (ps, 0, i, count_reg, loop);
/* Put the prolog on the entry edge. */
e = loop_preheader_edge (loop);
start_sequence ();
for (i = 0; i < last_stage; i++)
- duplicate_insns_of_cycles (ps, i + 1, last_stage, count_reg);
+ duplicate_insns_of_cycles (ps, i + 1, last_stage, count_reg, loop);
/* Put the epilogue on the exit edge. */
gcc_assert (single_exit (loop));