diff options
author | ebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-04-11 16:15:25 +0000 |
---|---|---|
committer | ebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-04-11 16:15:25 +0000 |
commit | 3303f1bb3df37092b3ec7586b0a9077f62b13309 (patch) | |
tree | 50ecfdf73e14a55579b5dfadb4bcc575c87bafec /gcc/tree.c | |
parent | 19b271a9085026049393a62ce767c86272898e25 (diff) | |
download | gcc-3303f1bb3df37092b3ec7586b0a9077f62b13309.tar.gz |
* stor-layout.c (skip_simple_constant_arithmetic): Move to...
* tree.c (skip_simple_constant_arithmetic): ...here and make public.
(skip_simple_arithmetic): Tidy up.
* tree.h (skip_simple_constant_arithmetic): Declare.
ada/
* gcc-interface/decl.c (elaborate_expression_1): Skip only constant
arithmetics when looking for a read-only variable in the expression.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@197815 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/gcc/tree.c b/gcc/tree.c index ba3dcddaf42..d8f2424a1ef 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -2830,14 +2830,12 @@ save_expr (tree expr) return t; } -/* Look inside EXPR and into any simple arithmetic operations. Return - the innermost non-arithmetic node. */ +/* Look inside EXPR into any simple arithmetic operations. Return the + outermost non-arithmetic or non-invariant node. */ tree skip_simple_arithmetic (tree expr) { - tree inner; - /* We don't care about whether this can be used as an lvalue in this context. */ while (TREE_CODE (expr) == NON_LVALUE_EXPR) @@ -2847,17 +2845,16 @@ skip_simple_arithmetic (tree expr) a constant, it will be more efficient to not make another SAVE_EXPR since it will allow better simplification and GCSE will be able to merge the computations if they actually occur. */ - inner = expr; - while (1) + while (true) { - if (UNARY_CLASS_P (inner)) - inner = TREE_OPERAND (inner, 0); - else if (BINARY_CLASS_P (inner)) + if (UNARY_CLASS_P (expr)) + expr = TREE_OPERAND (expr, 0); + else if (BINARY_CLASS_P (expr)) { - if (tree_invariant_p (TREE_OPERAND (inner, 1))) - inner = TREE_OPERAND (inner, 0); - else if (tree_invariant_p (TREE_OPERAND (inner, 0))) - inner = TREE_OPERAND (inner, 1); + if (tree_invariant_p (TREE_OPERAND (expr, 1))) + expr = TREE_OPERAND (expr, 0); + else if (tree_invariant_p (TREE_OPERAND (expr, 0))) + expr = TREE_OPERAND (expr, 1); else break; } @@ -2865,9 +2862,37 @@ skip_simple_arithmetic (tree expr) break; } - return inner; + return expr; } +/* Look inside EXPR into simple arithmetic operations involving constants. + Return the outermost non-arithmetic or non-constant node. */ + +tree +skip_simple_constant_arithmetic (tree expr) +{ + while (TREE_CODE (expr) == NON_LVALUE_EXPR) + expr = TREE_OPERAND (expr, 0); + + while (true) + { + if (UNARY_CLASS_P (expr)) + expr = TREE_OPERAND (expr, 0); + else if (BINARY_CLASS_P (expr)) + { + if (TREE_CONSTANT (TREE_OPERAND (expr, 1))) + expr = TREE_OPERAND (expr, 0); + else if (TREE_CONSTANT (TREE_OPERAND (expr, 0))) + expr = TREE_OPERAND (expr, 1); + else + break; + } + else + break; + } + + return expr; +} /* Return which tree structure is used by T. */ |