This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH]: Minor tweek: scope reduction part 1
- From: d binderman <dcb314 at hotmail dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 1 Dec 2009 10:45:10 +0000
- Subject: [PATCH]: Minor tweek: scope reduction part 1
Hello there,
I have just been experimenting with the most excellent tool cppcheck
(http://sourceforge.net/projects/cppcheck/) on the gcc source code.
It has a flag called --style which can be used to detect places where
the scope of local variables can be safely reduced.
In the case of gcc, this probably doesn't affect the run time speed or
behaviour of the code, but it does simplify the code for human readers
and reduces the chances of future errors.
I experimented with only source code files gcc/{a,b}*.c
The changes seemed to bootstrap and test ok to me.
2009-12-01? David Binderman <dcb314@hotmail.com>
??????? * gcc/tree-flow-inline.h (op_iter_next_use): Reduce scope of use_p.
??????? * gcc/tree-flow-inline.h (op_iter_next_def): Reduce scope of def_p.
??????? * gcc/tree-flow-inline.h (delink_stmt_imm_use): Reduce scope of iter and use_p.
??????? * gcc/alias.c (nonoverlapping_memrefs_p): Reduce scope of tem.
??????? * gcc/bb-reorder.c (insert_section_boundary_note): Reduce scope of first_partition.
??????? * gcc/bt-load.c (compute_defs_uses_and_gen): Reduce scope of i.
??????? * gcc/bt-load.c (choose_btr): Reduce scope of i.
??????? * gcc/builtins.c (apply_args_size): Reduce scope of align.
??????? * gcc/builtins.c (apply_result_size): Reduce scope of align and regno.
??????? * gcc/builtins.c (expand_builtin_signbit): Reduce scope of hi, lo and word.
??????? * gcc/builtins.c (fold_builtin_call_array): Reduce scope of i.
Regards
David Binderman
_________________________________________________________________
Have more than one Hotmail account? Link them together to easily access both
http://clk.atdmt.com/UKM/go/186394591/direct/01/
--- gcc/tree-flow-inline.h.sav 2009-12-01 10:00:01.000000000 +0000
+++ gcc/tree-flow-inline.h 2009-12-01 09:11:29.000000000 +0000
@@ -681,13 +681,12 @@
static inline use_operand_p
op_iter_next_use (ssa_op_iter *ptr)
{
- use_operand_p use_p;
#ifdef ENABLE_CHECKING
gcc_assert (ptr->iter_type == ssa_op_iter_use);
#endif
if (ptr->uses)
{
- use_p = USE_OP_PTR (ptr->uses);
+ use_operand_p use_p = USE_OP_PTR (ptr->uses);
ptr->uses = ptr->uses->next;
return use_p;
}
@@ -703,13 +702,12 @@
static inline def_operand_p
op_iter_next_def (ssa_op_iter *ptr)
{
- def_operand_p def_p;
#ifdef ENABLE_CHECKING
gcc_assert (ptr->iter_type == ssa_op_iter_def);
#endif
if (ptr->defs)
{
- def_p = DEF_OP_PTR (ptr->defs);
+ def_operand_p def_p = DEF_OP_PTR (ptr->defs);
ptr->defs = ptr->defs->next;
return def_p;
}
@@ -905,12 +903,14 @@
static inline void
delink_stmt_imm_use (gimple stmt)
{
- ssa_op_iter iter;
- use_operand_p use_p;
-
if (ssa_operands_active ())
+ {
+ ssa_op_iter iter;
+ use_operand_p use_p;
+
FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
delink_imm_use (use_p);
+ }
}
--- gcc/alias.c.sav 2009-12-01 09:11:37.000000000 +0000
+++ gcc/alias.c 2009-12-01 09:12:22.000000000 +0000
@@ -2132,7 +2132,7 @@
rtx rtlx, rtly;
rtx basex, basey;
rtx moffsetx, moffsety;
- HOST_WIDE_INT offsetx = 0, offsety = 0, sizex, sizey, tem;
+ HOST_WIDE_INT offsetx = 0, offsety = 0, sizex, sizey;
/* Unless both have exprs, we can't tell anything. */
if (exprx == 0 || expry == 0)
@@ -2277,6 +2277,8 @@
/* Put the values of the memref with the lower offset in X's values. */
if (offsetx > offsety)
{
+ HOST_WIDE_INT tem;
+
tem = offsetx, offsetx = offsety, offsety = tem;
tem = sizex, sizex = sizey, sizey = tem;
}
--- gcc/bb-reorder.c.sav 2009-12-01 09:17:51.000000000 +0000
+++ gcc/bb-reorder.c 2009-12-01 09:18:16.000000000 +0000
@@ -1951,9 +1951,11 @@
{
basic_block bb;
rtx new_note;
- int first_partition = 0;
if (flag_reorder_blocks_and_partition)
+ {
+ int first_partition = 0;
+
FOR_EACH_BB (bb)
{
if (!first_partition)
@@ -1968,6 +1970,7 @@
break;
}
}
+ }
}
/* Duplicate the blocks containing computed gotos. This basically unfactors
--- gcc/bt-load.c.sav 2009-12-01 09:18:46.000000000 +0000
+++ gcc/bt-load.c 2009-12-01 09:19:28.000000000 +0000
@@ -553,10 +553,11 @@
HARD_REG_SET *clobbered = &call_used_reg_set;
HARD_REG_SET call_saved;
rtx pat = PATTERN (insn);
- int i;
/* Check for sibcall. */
if (GET_CODE (pat) == PARALLEL)
+ {
+ int i;
for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
if (GET_CODE (XVECEXP (pat, 0, i)) == RETURN)
{
@@ -564,6 +565,7 @@
call_used_reg_set);
clobbered = &call_saved;
}
+ }
for (regno = first_btr; regno <= last_btr; regno++)
if (TEST_HARD_REG_BIT (*clobbered, regno))
@@ -983,9 +985,11 @@
static int
choose_btr (HARD_REG_SET used_btrs)
{
- int i;
if (!hard_reg_set_subset_p (all_btrs, used_btrs))
+ {
+ int i;
+
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
{
#ifdef REG_ALLOC_ORDER
@@ -997,6 +1001,7 @@
&& !TEST_HARD_REG_BIT (used_btrs, regno))
return regno;
}
+ }
return -1;
}
--- gcc/builtins.c.sav 2009-12-01 09:20:11.000000000 +0000
+++ gcc/builtins.c 2009-12-01 09:23:33.000000000 +0000
@@ -1263,7 +1263,6 @@
apply_args_size (void)
{
static int size = -1;
- int align;
unsigned int regno;
enum machine_mode mode;
@@ -1281,6 +1280,8 @@
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
if (FUNCTION_ARG_REGNO_P (regno))
{
+ int align;
+
mode = reg_raw_mode[regno];
gcc_assert (mode != VOIDmode);
@@ -1306,17 +1307,20 @@
apply_result_size (void)
{
static int size = -1;
- int align, regno;
enum machine_mode mode;
/* The values computed by this function never change. */
if (size < 0)
{
+ int regno;
+
size = 0;
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
if (FUNCTION_VALUE_REGNO_P (regno))
{
+ int align;
+
mode = reg_raw_mode[regno];
gcc_assert (mode != VOIDmode);
@@ -5160,9 +5164,8 @@
{
const struct real_format *fmt;
enum machine_mode fmode, imode, rmode;
- HOST_WIDE_INT hi, lo;
tree arg;
- int word, bitpos;
+ int bitpos;
enum insn_code icode;
rtx temp;
location_t loc = EXPR_LOCATION (exp);
@@ -5212,7 +5215,9 @@
temp = gen_lowpart (imode, temp);
}
else
- {
+ {
+ int word;
+
imode = word_mode;
/* Handle targets with different FP word orders. */
if (FLOAT_WORDS_BIG_ENDIAN)
@@ -5234,6 +5239,8 @@
if (bitpos < GET_MODE_BITSIZE (rmode))
{
+ HOST_WIDE_INT hi, lo;
+
if (bitpos < HOST_BITS_PER_WIDE_INT)
{
hi = 0;
@@ -10596,7 +10603,6 @@
tree *argarray)
{
tree ret = NULL_TREE;
- int i;
tree exp;
if (TREE_CODE (fn) == ADDR_EXPR)
@@ -10620,6 +10626,7 @@
return build_call_array_loc (loc, type, fn, n, argarray);
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
{
+ int i;
tree arglist = NULL_TREE;
for (i = n - 1; i >= 0; i--)
arglist = tree_cons (NULL_TREE, argarray[i], arglist);