This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] Make tsi insert iterators handle chains of COMPOUND_EXPRs
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Cc: amacleod at redhat dot com, law at redhat dot com
- Date: Thu, 28 Aug 2003 21:53:23 +0200
- Subject: [tree-ssa] Make tsi insert iterators handle chains of COMPOUND_EXPRs
Hello,
this patch improves tsi_link_before and tsi_link_after so that if
the statement you link in is right-recursive chain of COMPOUND_EXPRs,
rationalize_compound_expr does not have to be called.
This enables to remove creation of BIND_EXPR from replace_stmt.
Zdenek
* tree-iterator.h (enum tsi_iterator_update): Add TSI_CHAIN_END.
* tree.c (tsi_link_before, tsi_link_after): Handle insertion of
COMPOUND_EXPR chains.
Index: tree-iterator.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-iterator.h,v
retrieving revision 1.1.2.7
diff -c -3 -p -r1.1.2.7 tree-iterator.h
*** tree-iterator.h 15 Jul 2003 03:13:40 -0000 1.1.2.7
--- tree-iterator.h 28 Aug 2003 19:46:28 -0000
*************** typedef tree tree_stmt_anchor;
*** 149,155 ****
enum tsi_iterator_update
{
TSI_NEW_STMT,
! TSI_SAME_STMT
};
void tsi_link_before (tree_stmt_iterator *, tree, enum tsi_iterator_update);
--- 149,156 ----
enum tsi_iterator_update
{
TSI_NEW_STMT,
! TSI_SAME_STMT,
! TSI_CHAIN_END
};
void tsi_link_before (tree_stmt_iterator *, tree, enum tsi_iterator_update);
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.263.2.48
diff -c -3 -p -r1.263.2.48 tree.c
*** tree.c 21 Aug 2003 07:44:57 -0000 1.263.2.48
--- tree.c 28 Aug 2003 19:46:32 -0000
*************** build_empty_stmt (void)
*** 5113,5132 ****
void
tsi_link_before (tree_stmt_iterator *i, tree t, enum tsi_iterator_update mode)
{
! tree ce;
/* Build a new CE which points to the current node. */
! ce = build (COMPOUND_EXPR, void_type_node, t, *(i->tp));
/* Make the parent pointer point to this new node. At this point, the
iterator will be pointing to the new node we just inserted. */
! *(i->tp) = ce;
/* Update the iterator to points to the address of the next ptr in our new
node, which is the current stmt again. */
if (mode == TSI_SAME_STMT)
! i->tp = &(TREE_OPERAND (*(i->tp), 1));
!
}
/* Links a stmt after the current stmt. */
--- 5113,5138 ----
void
tsi_link_before (tree_stmt_iterator *i, tree t, enum tsi_iterator_update mode)
{
! tree *last;
!
! for (last = &t;
! TREE_CODE (*last) == COMPOUND_EXPR;
! last = &TREE_OPERAND (*last, 1))
! continue;
/* Build a new CE which points to the current node. */
! *last = build (COMPOUND_EXPR, void_type_node, *last, *(i->tp));
/* Make the parent pointer point to this new node. At this point, the
iterator will be pointing to the new node we just inserted. */
! *(i->tp) = t;
/* Update the iterator to points to the address of the next ptr in our new
node, which is the current stmt again. */
if (mode == TSI_SAME_STMT)
! i->tp = &(TREE_OPERAND (*last, 1));
! else if (mode == TSI_NEW_STMT)
! i->tp = last != &t ? last : i->tp;
}
/* Links a stmt after the current stmt. */
*************** tsi_link_after (tree_stmt_iterator *i, t
*** 5136,5141 ****
--- 5142,5148 ----
{
tree ce;
tree next;
+ tree *last;
/* If this node isnt a COMPUND_EXPR, we need to insert a CE node. */
if (TREE_CODE (*(i->tp)) != COMPOUND_EXPR)
*************** tsi_link_after (tree_stmt_iterator *i, t
*** 5150,5172 ****
/* Change new iterator to point to the new stmt. */
if (mode == TSI_NEW_STMT)
i->tp = &(TREE_OPERAND (ce, 1));
}
else
{
! next = TREE_OPERAND (*(i->tp), 1);
! /* Create a new node with the same 'next' link as the current one. */
! ce = build (COMPOUND_EXPR, void_type_node, t, next);
! /* Make the current one's 'next' link point to our new stmt. */
! TREE_OPERAND (*(i->tp), 1) = ce;
/* Update the iterator to the new stmt. */
if (mode == TSI_NEW_STMT)
i->tp = &(TREE_OPERAND (*(i->tp), 1));
}
-
-
}
/* Remove a stmt from the tree list. The iterator is updated to point to
--- 5157,5185 ----
/* Change new iterator to point to the new stmt. */
if (mode == TSI_NEW_STMT)
i->tp = &(TREE_OPERAND (ce, 1));
+ else if (mode == TSI_CHAIN_END)
+ while (TREE_CODE (*i->tp) == COMPOUND_EXPR)
+ i->tp = &(TREE_OPERAND (*i->tp, 1));
}
else
{
! for (last = &t;
! TREE_CODE (*last) == COMPOUND_EXPR;
! last = &TREE_OPERAND (*last, 1))
! continue;
! next = TREE_OPERAND (*(i->tp), 1);
! /* Create a new node with the same 'next' link as the current one. */
! *last = build (COMPOUND_EXPR, void_type_node, *last, next);
! TREE_OPERAND (*(i->tp), 1) = t;
/* Update the iterator to the new stmt. */
if (mode == TSI_NEW_STMT)
i->tp = &(TREE_OPERAND (*(i->tp), 1));
+ else if (mode == TSI_CHAIN_END)
+ i->tp = last != &t ? last : &(TREE_OPERAND (*(i->tp), 1));
}
}
/* Remove a stmt from the tree list. The iterator is updated to point to