vect_mark_slp_stmts_relevant (node, visited);
}
+/* Copy the SLP subtree rooted at NODE. */
+
+static slp_tree
+slp_copy_subtree (slp_tree node, hash_map<slp_tree, slp_tree> &map)
+{
+ unsigned i;
+
+ bool existed_p;
+ slp_tree © = map.get_or_insert (node, &existed_p);
+ if (existed_p)
+ return copy;
+
+ copy = XNEW (_slp_tree);
+ memcpy (copy, node, sizeof (_slp_tree));
+ if (SLP_TREE_SCALAR_STMTS (node).exists ())
+ {
+ SLP_TREE_SCALAR_STMTS (copy) = SLP_TREE_SCALAR_STMTS (node).copy ();
+ stmt_vec_info stmt_info;
+ FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info)
+ STMT_VINFO_NUM_SLP_USES (stmt_info)++;
+ }
+ if (SLP_TREE_SCALAR_OPS (node).exists ())
+ SLP_TREE_SCALAR_OPS (copy) = SLP_TREE_SCALAR_OPS (node).copy ();
+ if (SLP_TREE_LOAD_PERMUTATION (node).exists ())
+ SLP_TREE_LOAD_PERMUTATION (copy) = SLP_TREE_LOAD_PERMUTATION (node).copy ();
+ if (SLP_TREE_CHILDREN (node).exists ())
+ SLP_TREE_CHILDREN (copy) = SLP_TREE_CHILDREN (node).copy ();
+ gcc_assert (!SLP_TREE_VEC_STMTS (node).exists ());
+ copy->refcnt = 0;
+
+ slp_tree child;
+ FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (copy), i, child)
+ {
+ SLP_TREE_CHILDREN (copy)[i] = slp_copy_subtree (child, map);
+ SLP_TREE_CHILDREN (copy)[i]->refcnt++;
+ }
+ return copy;
+}
/* Rearrange the statements of NODE according to PERMUTATION. */
statements in the nodes is not important unless they are memory
accesses, we can rearrange the statements in all the nodes
according to the order of the loads. */
+
+ /* We have to unshare the SLP tree we modify. */
+ hash_map<slp_tree, slp_tree> map;
+ slp_tree unshared = slp_copy_subtree (SLP_INSTANCE_TREE (slp_instn), map);
+ vect_free_slp_tree (SLP_INSTANCE_TREE (slp_instn), false);
+ unshared->refcnt++;
+ SLP_INSTANCE_TREE (slp_instn) = unshared;
+ FOR_EACH_VEC_ELT (SLP_INSTANCE_LOADS (slp_instn), i, node)
+ SLP_INSTANCE_LOADS (slp_instn)[i] = *map.get (node);
+ node = SLP_INSTANCE_LOADS (slp_instn)[0];
+
+ /* Do the actual re-arrangement. */
hash_set<slp_tree> visited;
vect_slp_rearrange_stmts (SLP_INSTANCE_TREE (slp_instn), group_size,
node->load_permutation, visited);