diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2013-04-11 16:15:25 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2013-04-11 16:15:25 +0000 |
commit | 966b587e0b513fa8075beaf9ab184ed74686ee97 (patch) | |
tree | 50ecfdf73e14a55579b5dfadb4bcc575c87bafec /gcc/tree.c | |
parent | 76545796c5181baef9511af159178aef8d93de7c (diff) | |
download | gcc-966b587e0b513fa8075beaf9ab184ed74686ee97.zip gcc-966b587e0b513fa8075beaf9ab184ed74686ee97.tar.gz gcc-966b587e0b513fa8075beaf9ab184ed74686ee97.tar.bz2 |
stor-layout.c (skip_simple_constant_arithmetic): Move to...
* 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.
From-SVN: r197815
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 53 |
1 files changed, 39 insertions, 14 deletions
@@ -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. */ |