2002-08-11 Diego Novillo * tree-dfa.c (find_refs_in_expr): Use the given ref_type for some unary expressions. (create_ref): Insert ghost definitions at the beginning of the basic block. (find_expr_in_tree): Ignore IDENTIFIER_NODE. * tree-flow.h (treeref_common): Move the id field to the end of the structure. (IS_GHOST_DEF): Redefine to return non zero for definitions without an associated expression in basic block 0. * tree-ssa-ccp.c (tree_ssa_ccp): Use last_basic_block to allocate executable_blocks. (visit_expression): Set the lattice value for ghost definitions to VARYING. (examine_flow_edges): Update comments. * tree-ssa.c (tree_build_ssa): Create ghost definitions in basic block 0. (insert_phi_terms): Don't ignore ghost definitions. Index: tree-dfa.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v retrieving revision 1.1.4.3 diff -d -u -p -r1.1.4.3 tree-dfa.c --- tree-dfa.c 7 Aug 2002 16:02:58 -0000 1.1.4.3 +++ tree-dfa.c 11 Aug 2002 17:53:53 -0000 @@ -294,7 +294,7 @@ find_refs_in_expr (expr, ref_type, bb, p case NOP_EXPR: case REALPART_EXPR: case REFERENCE_EXPR: - find_refs_in_expr (TREE_OPERAND (expr, 0), VARUSE, bb, parent_stmt, + find_refs_in_expr (TREE_OPERAND (expr, 0), ref_type, bb, parent_stmt, expr); break; @@ -639,12 +650,11 @@ create_ref (sym, ref_type, bb, parent_st Make sure that PHI terms are added at the beginning of the list, otherwise FUD chaining will fail to link local uses to the PHI term in this basic block. */ - if (ref_type == VARPHI || ref_type == EXPRPHI) + if (ref_type == VARPHI || ref_type == EXPRPHI || IS_GHOST_DEF (ref)) add_ref_to_list_begin (get_bb_ann (bb)->refs, ref); else add_ref_to_list_end (get_bb_ann (bb)->refs, ref); - return ref; } @@ -2219,6 +2253,7 @@ find_expr_in_tree (t, expr) case REAL_CST: case RESULT_DECL: case STRING_CST: + case IDENTIFIER_NODE: return NULL; case TREE_LIST: Index: tree-flow.h =================================================================== RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v retrieving revision 1.1.4.5 diff -d -u -p -r1.1.4.5 tree-flow.h --- tree-flow.h 7 Aug 2002 16:02:58 -0000 1.1.4.5 +++ tree-flow.h 11 Aug 2002 17:53:53 -0000 @@ -35,9 +35,6 @@ union varref_def; /* Common features of every variable reference. */ struct treeref_common { - /* Reference ID. Unique within a single function. */ - unsigned int id; - /* Base symbol. */ tree sym; @@ -52,6 +49,9 @@ struct treeref_common /* Reference type. */ enum treeref_type type; + + /* Reference ID. Unique within a single function. */ + unsigned int id; }; @@ -230,9 +230,18 @@ typedef union varref_def *varref; #define EXPRREF_SAVE(r) (r)->ecommon.save #define EXPRREF_RELOAD(r) (r)->ecommon.reload -/* Return nonzero if R is a ghost definition. */ -#define IS_GHOST_DEF(R) \ - (R && VARREF_TYPE (R) == VARDEF && VARREF_BB (R) == ENTRY_BLOCK_PTR) +/* Return nonzero if R is a ghost definition. Ghost definitions are + artificially created in the first basic block of the program. They + provide a convenient way of checking if a variable is used without being + assigned a value first. Their presence is not required, but they save + the code from having to consider special cases like nil PHI node + arguments. */ +#define IS_GHOST_DEF(R) \ + (R \ + && VARREF_TYPE (R) == VARDEF \ + && VARREF_EXPR (R) == NULL_TREE \ + && VARREF_STMT (R) == NULL_TREE \ + && VARREF_BB (R)->index == 0) /* Return nonzero if R is an artificial definition (currently, a PHI term or a ghost definition). */ @@ -262,9 +271,6 @@ struct tree_ann_def int flags; }; -#define TF_FOLD 1 /* Expression tree should be folded. */ - - typedef struct tree_ann_def *tree_ann; #define TREE_ANN(NODE) ((tree_ann)((NODE)->common.aux)) @@ -273,6 +279,9 @@ typedef struct tree_ann_def *tree_ann; #define TREE_REFS(NODE) TREE_ANN (NODE)->refs #define TREE_COMPOUND_STMT(NODE) TREE_ANN (NODE)->compound_stmt #define TREE_FLAGS(NODE) TREE_ANN (NODE)->flags + +/* Tree flags. */ +#define TF_FOLD 1 /* Expression tree should be folded. */ /* Block annotations stored in basic_block.aux. */ Index: tree-ssa-ccp.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v retrieving revision 1.1.2.3 diff -d -u -p -r1.1.2.3 tree-ssa-ccp.c --- tree-ssa-ccp.c 7 Aug 2002 16:02:58 -0000 1.1.2.3 +++ tree-ssa-ccp.c 11 Aug 2002 17:53:53 -0000 @@ -170,7 +173,7 @@ tree_ssa_ccp (fndecl) fraction of entries. See if we can get away with less than half. */ VARRAY_GENERIC_PTR_INIT (ssa_edges, next_varref_id / 2, "ssa_edges"); - executable_blocks = sbitmap_alloc (n_basic_blocks); + executable_blocks = sbitmap_alloc (last_basic_block); sbitmap_zero (executable_blocks); executable_edges = sbitmap_alloc (NUM_EDGES (edges)); @@ -380,9 +383,19 @@ visit_expression (ref) { tree expr; #if defined CHECKING /* PHI references should be dealt with by visit_phi_node. */ if (VARREF_TYPE (ref) == VARPHI) abort (); #endif + + /* Special case for ghost definitions. Set their lattice value to + VARYING. */ + if (IS_GHOST_DEF (ref)) + { + values[SSA_NAME (ref)].lattice_val = VARYING; + return; + } expr = VARREF_EXPR (ref); @@ -554,7 +572,7 @@ examine_flow_edges (void) FOR_EACH_REF (ref, tmp, blockrefs) { - /* Simulate each insn within the block. */ + /* Simulate each reference within the block. */ if (VARREF_TYPE (ref) != VARPHI) visit_expression (ref); } Index: tree-ssa.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v retrieving revision 1.1.4.6 diff -d -u -p -r1.1.4.6 tree-ssa.c --- tree-ssa.c 7 Aug 2002 16:02:59 -0000 1.1.4.6 +++ tree-ssa.c 11 Aug 2002 17:53:53 -0000 @@ -89,7 +89,8 @@ tree_build_ssa () with no statement or expression (to distinguish them from actual definitions). */ for (i = 0; i < NREF_SYMBOLS; i++) - create_ref (REF_SYMBOL (i), VARDEF, ENTRY_BLOCK_PTR, NULL, NULL); + create_ref (REF_SYMBOL (i), VARDEF, ENTRY_BLOCK_PTR->succ->dest, NULL, + NULL); /* Insert the PHI terms and build FUD chains. */ insert_phi_terms (dfs); @@ -160,16 +161,17 @@ insert_phi_terms (dfs) struct ref_list_node *tmp; varref ref; #if defined CHECKING /* Symbols in referenced_symbols must have at least 1 reference. */ if (TREE_REFS (sym)->first == NULL) abort (); #endif FOR_EACH_REF (ref, tmp, TREE_REFS (sym)) { basic_block bb = VARREF_BB (ref); - /* Ignore ghost definitions in ENTRY_BLOCK_PTR. */ - if (VARREF_TYPE (ref) != VARDEF || IS_GHOST_DEF (ref)) + if (VARREF_TYPE (ref) != VARDEF) continue; VARRAY_PUSH_BB (work_stack, bb);