This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH]: Merge two invariant_in_loop functions
- From: Daniel Berlin <dberlin at dberlin dot org>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 26 Sep 2004 15:24:12 -0400 (EDT)
- Subject: [PATCH]: Merge two invariant_in_loop functions
We basically had the same function in two places, one in
tree-ssa-loop-ivopts.c, and one in lambda-code.c
This rewrites lambda-code.c to use the expr_invariant_in_loop function
from tree-ssa-loop-ivopts.c
2004-09-26 Daniel Berlin <dberlin@dberlin.org>
* tree-ssa-loop-ivopts.c (expr_invariant_in_loop): Make non-static.
* tree-flow.h: Add prototype.
* lambda-code.c (invariant_in_loop_and_outer_loops): Use expr_invariant_in_loop.
Index: lambda-code.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/lambda-code.c,v
retrieving revision 2.11
diff -u -p -r2.11 lambda-code.c
--- lambda-code.c 25 Sep 2004 14:36:37 -0000 2.11
+++ lambda-code.c 26 Sep 2004 19:19:55 -0000
@@ -1165,27 +1165,18 @@ gcc_tree_to_linear_expression (int depth
/* Return true if OP is invariant in LOOP and all outer loops. */
static bool
-invariant_in_loop (struct loop *loop, tree op)
+invariant_in_loop_and_outer_loops (struct loop *loop, tree op)
{
if (is_gimple_min_invariant (op))
return true;
if (loop->depth == 0)
return true;
- if (TREE_CODE (op) == SSA_NAME)
- {
- tree def;
- def = SSA_NAME_DEF_STMT (op);
- if (TREE_CODE (SSA_NAME_VAR (op)) == PARM_DECL
- && IS_EMPTY_STMT (def))
- return true;
- if (IS_EMPTY_STMT (def))
- return false;
- if (loop->outer
- && !invariant_in_loop (loop->outer, op))
- return false;
- return !flow_bb_inside_loop_p (loop, bb_for_stmt (def));
- }
- return false;
+ if (!expr_invariant_in_loop_p (loop, op))
+ return false;
+ if (loop->outer
+ && !invariant_in_loop_and_outer_loops (loop->outer, op))
+ return false;
+ return true;
}
/* Generate a lambda loop from a gcc loop LOOP. Return the new lambda loop,
@@ -1352,10 +1343,10 @@ gcc_loop_to_lambda_loop (struct loop *lo
}
/* One part of the test may be a loop invariant tree. */
if (TREE_CODE (TREE_OPERAND (test, 1)) == SSA_NAME
- && invariant_in_loop (loop, TREE_OPERAND (test, 1)))
+ && invariant_in_loop_and_outer_loops (loop, TREE_OPERAND (test, 1)))
VEC_safe_push (tree, *invariants, TREE_OPERAND (test, 1));
else if (TREE_CODE (TREE_OPERAND (test, 0)) == SSA_NAME
- && invariant_in_loop (loop, TREE_OPERAND (test, 0)))
+ && invariant_in_loop_and_outer_loops (loop, TREE_OPERAND (test, 0)))
VEC_safe_push (tree, *invariants, TREE_OPERAND (test, 0));
/* The non-induction variable part of the test is the upper bound variable.
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-flow.h,v
retrieving revision 2.48
diff -u -p -r2.48 tree-flow.h
--- tree-flow.h 23 Sep 2004 21:00:50 -0000 2.48
+++ tree-flow.h 26 Sep 2004 19:19:55 -0000
@@ -745,6 +745,8 @@ extern void build_ssa_operands (tree, st
/* In tree-loop-linear.c */
extern void linear_transform_loops (struct loops *);
+/* In tree-ssa-loop-ivopts.c */
+extern bool expr_invariant_in_loop_p (struct loop *loop, tree expr);
/* In gimplify.c */
tree force_gimple_operand (tree, tree *, bool, tree);
Index: tree-ssa-loop-ivopts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-ivopts.c,v
retrieving revision 2.13
diff -u -p -r2.13 tree-ssa-loop-ivopts.c
--- tree-ssa-loop-ivopts.c 26 Sep 2004 08:32:40 -0000 2.13
+++ tree-ssa-loop-ivopts.c 26 Sep 2004 19:19:56 -0000
@@ -1168,7 +1168,7 @@ find_interesting_uses_cond (struct ivopt
/* Returns true if expression EXPR is obviously invariant in LOOP,
i.e. if all its operands are defined outside of the LOOP. */
-static bool
+bool
expr_invariant_in_loop_p (struct loop *loop, tree expr)
{
basic_block def_bb;