This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[graphite] Some cleanups for the tree CFG checker
- From: "Sebastian Pop" <sebastian dot pop at inria dot fr>
- To: gcc-patches at gcc dot gnu dot org, "Nic Volanschi" <nic dot volanschi at free dot fr>
- Date: Mon, 12 Mar 2007 16:24:23 +0100
- Subject: [graphite] Some cleanups for the tree CFG checker
Hi,
Here is a patch for transforming all the varrays to VECs in the
cfg checker. The graphite-branch bootstraps with the patch on
i686-linux, and passes the testsuite. However, for the moment
the testsuite does not contain any test that stresses the checker,
so I tested the patch with some simple examples that I will
include in the testsuite.
Sebastian
Index: gcc/tree-pretty-print.c
===================================================================
--- gcc/tree-pretty-print.c (revision 121080)
+++ gcc/tree-pretty-print.c (working copy)
@@ -3033,15 +3033,17 @@ dump_generic_bb_buff (pretty_printer *bu
that constitute its printed form. Tree chunks may be: characters,
strings, and sub-trees. */
-varray_type
+VEC (tree_chunk, heap) *
lazy_dump_generic_node (tree node, int flags, bool is_stmt)
{
pretty_printer *pp = &buffer;
- varray_type res;
- VARRAY_GENERIC_PTR_NOGC_INIT (pp->buffer->varray, 10, "tree pp list");
+ VEC (tree_chunk, heap) *res;
+
+ pp->buffer->chunks = VEC_alloc (tree_chunk, heap, 10);
dump_generic_node_aux (pp, node, 0, flags, is_stmt);
- res = pp->buffer->varray;
- pp->buffer->varray = NULL;
+ res = pp->buffer->chunks;
+ pp->buffer->chunks = NULL;
+
return res;
}
@@ -3051,9 +3053,10 @@ lazy_dump_generic_node (tree node, int f
void
lazy_print_generic_expr (FILE *file, tree t, int flags)
{
- varray_type va;
+ VEC (tree_chunk, heap) *chunks;
+
maybe_init_pretty_print (file);
fprintf (file, "<%s>=", tree_name(t));
- va = lazy_dump_generic_node (t, flags, false);
- pp_write_list (va, file);
+ chunks = lazy_dump_generic_node (t, flags, false);
+ pp_write_list (chunks, file);
}
Index: gcc/diagnostic.h
===================================================================
--- gcc/diagnostic.h (revision 121080)
+++ gcc/diagnostic.h (working copy)
@@ -216,7 +216,7 @@ extern void print_generic_stmt_indented
extern void print_generic_expr (FILE *, tree, int);
extern void print_generic_decl (FILE *, tree, int);
-extern varray_type lazy_dump_generic_node (tree, int, bool);
+extern VEC (tree_chunk, heap) *lazy_dump_generic_node (tree, int, bool);
extern void lazy_print_generic_expr (FILE *file, tree t, int flags);
extern void debug_generic_expr (tree);
Index: gcc/pretty-print.c
===================================================================
--- gcc/pretty-print.c (revision 121080)
+++ gcc/pretty-print.c (working copy)
@@ -25,6 +25,8 @@ Software Foundation, 51 Franklin Street,
#include "system.h"
#include "coretypes.h"
#include "intl.h"
+#include "tree.h"
+#include "vec.h"
#include "pretty-print.h"
#include "tree.h"
#include "diagnostic.h"
@@ -92,7 +94,7 @@ pp_clear_state (pretty_printer *pp)
pp->emitted_prefix = false;
pp_indentation (pp) = 0;
if (pp_lazy_mode (pp))
- pp_free_list (pp->buffer->varray);
+ pp_free_list (pp->buffer->chunks);
}
/* Flush the formatted text of PRETTY-PRINTER onto the attached stream. */
@@ -109,8 +111,8 @@ static void
pp_write_list_to_stream (pretty_printer *pp)
{
FILE *f = pp->buffer->stream;
- varray_type va = pp->buffer->varray;
- pp_write_list (va, f);
+ VEC (tree_chunk, heap) *chunks = pp->buffer->chunks;
+ pp_write_list (chunks, f);
}
/* Wrap a text delimited by START and END into PRETTY-PRINTER. */
@@ -232,7 +234,7 @@ pp_base_format (pretty_printer *pp, text
pp_wrapping_mode_t old_wrapping_mode;
bool any_unnumbered = false, any_numbered = false;
const char **formatters[PP_NL_ARGMAX];
- varray_type save_varray;
+ VEC (tree_chunk, heap) *saved_chunks;
/* Allocate a new chunk structure. */
new_chunk_array = XOBNEW (&buffer->chunk_obstack, struct chunk_info);
@@ -386,8 +388,8 @@ pp_base_format (pretty_printer *pp, text
buffer->obstack = &buffer->chunk_obstack;
old_wrapping_mode = pp_set_verbatim_wrapping (pp);
/* and also disable lazy printing while using the chunk_obstack */
- save_varray = buffer->varray;
- buffer->varray = NULL;
+ saved_chunks = buffer->chunks;
+ buffer->chunks = NULL;
/* Second phase. Replace each formatter with the formatted text it
@@ -569,8 +571,8 @@ pp_base_format (pretty_printer *pp, text
buffer->line_length = 0;
pp_wrapping_mode (pp) = old_wrapping_mode;
pp_clear_state (pp);
- /* and also revert lazy mode to its previous state */
- buffer->varray = save_varray;
+ /* And also revert lazy mode to its previous state */
+ buffer->chunks = saved_chunks;
}
/* Format of a message pointed to by TEXT. */
@@ -710,7 +712,7 @@ pp_construct (pretty_printer *pp, const
obstack_init (&pp->buffer->formatted_obstack);
pp->buffer->obstack = &pp->buffer->formatted_obstack;
pp->buffer->stream = stderr;
- pp->buffer->varray = NULL;
+ pp->buffer->chunks = NULL;
pp_line_cutoff (pp) = maximum_length;
pp_prefixing_rule (pp) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
pp_set_prefix (pp, prefix);
@@ -852,15 +854,15 @@ pp_base_string (pretty_printer *pp, cons
bool
pp_lazy_mode (const pretty_printer *pp)
{
- return (pp->buffer->varray != NULL);
+ return (pp->buffer->chunks != NULL);
}
/* Tree chunk constructor. */
-tree_chunk *
+tree_chunk
new_tree_chunk (void)
{
- tree_chunk *chunk = xmalloc (sizeof (tree_chunk));
+ tree_chunk chunk = xmalloc (sizeof (struct tree_chunk_s));
chunk->t = NULL;
chunk->s = NULL;
chunk->c = '\0';
@@ -872,9 +874,10 @@ new_tree_chunk (void)
void
pp_add_tree (pretty_printer *pp, tree t)
{
- tree_chunk *chunk = new_tree_chunk ();
+ tree_chunk chunk = new_tree_chunk ();
+
chunk->t = t;
- VARRAY_PUSH_GENERIC_PTR_NOGC (pp->buffer->varray, chunk);
+ VEC_safe_push (tree_chunk, heap, pp->buffer->chunks, chunk);
}
/* Add a string chunk to the lazy list. */
@@ -882,12 +885,13 @@ pp_add_tree (pretty_printer *pp, tree t)
void
pp_add_string (pretty_printer *pp, const char *start, int len)
{
- tree_chunk *chunk = new_tree_chunk ();
+ tree_chunk chunk = new_tree_chunk ();
char *str = xmalloc (len + 1);
+
strncpy (str, start, len);
str[len] = '\0';
chunk->s = str;
- VARRAY_PUSH_GENERIC_PTR_NOGC (pp->buffer->varray, chunk);
+ VEC_safe_push (tree_chunk, heap, pp->buffer->chunks, chunk);
}
/* Add a character chunk to the lazy list. */
@@ -895,53 +899,56 @@ pp_add_string (pretty_printer *pp, const
void
pp_add_char (pretty_printer *pp, char c)
{
- tree_chunk *chunk = new_tree_chunk ();
+ tree_chunk chunk = new_tree_chunk ();
+
chunk->c = c;
- VARRAY_PUSH_GENERIC_PTR_NOGC (pp->buffer->varray, chunk);
+ VEC_safe_push (tree_chunk, heap, pp->buffer->chunks, chunk);
}
/* Write the lazy list to a file. */
void
-pp_write_list (varray_type va, FILE *f)
+pp_write_list (VEC (tree_chunk, heap) *chunks, FILE *f)
{
unsigned int i;
- tree_chunk *chunk;
+ tree_chunk chunk;
fprintf (f, "[ ");
- for(i = 0; i < VARRAY_ACTIVE_SIZE (va); i++)
+
+ for (i = 0; VEC_iterate (tree_chunk, chunks, i, chunk); i++)
{
- chunk = VARRAY_GENERIC_PTR_NOGC (va, i);
if (chunk->t)
fprintf (f, "<%s>", tree_name (chunk->t));
+
else if (chunk->s)
fprintf (f, "\"%s\"", chunk->s);
+
else
- /* One-character chunk. */
fprintf (f, "'%c'", chunk->c);
+
fprintf (f, " ");
- } /* for */
+ }
+
fprintf (f, "]");
}
/* Lazy list destructor. */
void
-pp_free_list (varray_type va)
+pp_free_list (VEC (tree_chunk, heap) *chunks)
{
unsigned int i;
- tree_chunk *chunk;
- for(i = 0; i < VARRAY_ACTIVE_SIZE (va); i++)
+ tree_chunk chunk;
+
+ for (i = 0; VEC_iterate (tree_chunk, chunks, i, chunk); i++)
{
- chunk = VARRAY_GENERIC_PTR_NOGC (va, i);
- if (chunk->t)
- /* don't free chunk->t, as it hasn't been allocated by us! */
- ;
- else if (chunk->s)
+ if (chunk->s)
free (chunk->s);
+
free (chunk);
}
- VARRAY_FREE (va);
+
+ VEC_free (tree_chunk, heap, chunks);
}
/* Print out a whitespace if needed. */
Index: gcc/pretty-print.h
===================================================================
--- gcc/pretty-print.h (revision 121080)
+++ gcc/pretty-print.h (working copy)
@@ -24,7 +24,6 @@ Software Foundation, 51 Franklin Street,
#include "obstack.h"
#include "input.h"
-#include "varray.h"
/* Maximum number of format string arguments. */
#define PP_NL_ARGMAX 30
@@ -70,6 +69,19 @@ struct chunk_info
const char *args[PP_NL_ARGMAX * 2];
};
+/* Structure containing a piece of a tree's textual representation */
+typedef struct tree_chunk_s {
+ /* Reference to a subtree. */
+ tree t;
+ /* A token. */
+ char *s;
+ /* A token of only one char is not stored in a malloc-ed string. */
+ char c;
+} *tree_chunk;
+
+DEF_VEC_P (tree_chunk);
+DEF_VEC_ALLOC_P (tree_chunk, heap);
+
/* The output buffer datatype. This is best seen as an abstract datatype
whose fields should not be accessed directly by clients. */
typedef struct
@@ -88,16 +100,13 @@ typedef struct
/* Stack of chunk arrays. These come from the chunk_obstack. */
struct chunk_info *cur_chunk_array;
- /* The varray where the text is built up. If null, the textual
+ /* A buffer where the text is built up. If null, the textual
representation of a tree is built as a plain string in the
- obstack above.
-
- If varray is not null, we're in "lazy mode", i.e instead of
- recursively building the textual representation of a tree as a
- plain string, we build a list of token strings and of "lazy"
- references to subtrees.
- */
- varray_type varray;
+ obstack above. If CHUNKS is not null, we're in "lazy mode", i.e.
+ instead of recursively building the textual representation of a
+ tree as a plain string, we build a list of token strings and of
+ "lazy" references to subtrees. */
+ VEC (tree_chunk, heap) *chunks;
/* Where to output formatted text. */
FILE *stream;
@@ -335,24 +344,13 @@ extern void pp_base_string (pretty_print
extern void pp_write_text_to_stream (pretty_printer *pp);
extern void pp_base_maybe_space (pretty_printer *);
-/* Structure containing a piece of a tree's textual representation */
-typedef struct {
- /* Reference to a substree. */
- tree t;
- /* A token. */
- char *s;
- /* A token of only one char is not stored in a malloc-ed string. */
- char c;
-} tree_chunk;
-
-extern tree_chunk *new_tree_chunk (void);
-
-extern bool pp_lazy_mode (const pretty_printer *pp);
-extern void pp_add_tree (pretty_printer *pp, tree t);
-extern void pp_add_string (pretty_printer *pp, const char *start, int len);
-extern void pp_add_char (pretty_printer *pp, char c);
-extern void pp_free_list (varray_type va);
-extern void pp_write_list (varray_type va, FILE *f);
+extern tree_chunk new_tree_chunk (void);
+extern bool pp_lazy_mode (const pretty_printer *);
+extern void pp_add_tree (pretty_printer *, tree);
+extern void pp_add_string (pretty_printer *, const char *, int);
+extern void pp_add_char (pretty_printer *, char);
+extern void pp_free_list (VEC (tree_chunk, heap) *);
+extern void pp_write_list (VEC (tree_chunk, heap) *, FILE *);
/* Switch into verbatim mode and return the old mode. */
static inline pp_wrapping_mode_t
Index: gcc/tree-match.c
===================================================================
--- gcc/tree-match.c (revision 121080)
+++ gcc/tree-match.c (working copy)
@@ -124,9 +124,11 @@ static bool tree_equal_mod_tmps (tree, t
static bool
tree_equal (tree t1, tree t2, cfg_node ctx_node1, cfg_node ctx_node2)
{
- varray_type va1, va2;
- tree_chunk *chunk1, *chunk2;
+ VEC (tree_chunk, heap) *chunks1;
+ VEC (tree_chunk, heap) *chunks2;
+ tree_chunk chunk1, chunk2;
int len1, len2, i;
+ bool res = false;
if ((!t1 || !t2))
return (t1 == t2);
@@ -134,8 +136,8 @@ tree_equal (tree t1, tree t2, cfg_node c
if (t1 == t2)
return true;
- va1 = lazy_dump_generic_node (t1, 0, false);
- va2 = lazy_dump_generic_node (t2, 0, false);
+ chunks1 = lazy_dump_generic_node (t1, 0, false);
+ chunks2 = lazy_dump_generic_node (t2, 0, false);
PP_TRACE (TRACE_MATCH_STEPS, {
fprintf (stderr, "tree cmp:\n");
@@ -145,52 +147,32 @@ tree_equal (tree t1, tree t2, cfg_node c
fprintf (stderr, "---\n");
});
- len1 = VARRAY_ACTIVE_SIZE (va1);
- len2 = VARRAY_ACTIVE_SIZE (va2);
+ len1 = VEC_length (tree_chunk, chunks1);
+ len2 = VEC_length (tree_chunk, chunks2);
if (len1 != len2)
- {
- pp_free_list (va1);
- pp_free_list (va2);
- return 0;
- }
+ goto mismatch;
- for (i = 0; i < len1; i++)
+ for (i = 0; VEC_iterate (tree_chunk, chunks1, i, chunk1); i++)
{
- chunk1 = VARRAY_GENERIC_PTR_NOGC (va1, i);
- chunk2 = VARRAY_GENERIC_PTR_NOGC (va2, i);
-
- if ((chunk1->t || chunk2->t)
- && (!(chunk1->t && chunk2->t)
- || !tree_equal_mod_tmps (chunk1->t, chunk2->t,
- ctx_node1, ctx_node2)))
- {
- pp_free_list (va1);
- pp_free_list (va2);
- return 0;
- }
-
- else if ((chunk1->s || chunk2->s)
- && (!(chunk1->s && chunk2->s)
- || strcmp (chunk1->s, chunk2->s)))
- {
- pp_free_list (va1);
- pp_free_list (va2);
- return 0;
- }
+ chunk2 = VEC_index (tree_chunk, chunks2, i);
- else if (chunk1->c != chunk2->c)
- {
- /* one-character chunk */
- pp_free_list (va1);
- pp_free_list (va2);
- return 0;
- }
+ if (((chunk1->t || chunk2->t)
+ && (!(chunk1->t && chunk2->t)
+ || !tree_equal_mod_tmps (chunk1->t, chunk2->t,
+ ctx_node1, ctx_node2)))
+ || ((chunk1->s || chunk2->s)
+ && (!(chunk1->s && chunk2->s)
+ || strcmp (chunk1->s, chunk2->s)))
+ || (chunk1->c != chunk2->c))
+ goto mismatch;
}
- pp_free_list (va1);
- pp_free_list (va2);
- return 1;
+ res = true;
+ mismatch:
+ pp_free_list (chunks1);
+ pp_free_list (chunks2);
+ return res;
}
/* Check if two trees are equal, modulo casts and substitutions of
@@ -220,7 +202,7 @@ static char tree_1st_char (tree);
/* Get the first character of (the printed form of) a tree chunk */
static char
-chunk_1st_char (tree_chunk *chunk)
+chunk_1st_char (tree_chunk chunk)
{
if (chunk->t)
return tree_1st_char (chunk->t);
@@ -234,15 +216,14 @@ chunk_1st_char (tree_chunk *chunk)
/* Search the first chunk of a lazy list not consisting of whitespace */
-static tree_chunk *
-chunks_lookahead (varray_type va, unsigned int i)
+static tree_chunk
+chunks_lookahead (VEC (tree_chunk, heap) *chunks, unsigned int i)
{
- tree_chunk *chunk;
+ tree_chunk chunk;
- do {
- chunk = VARRAY_GENERIC_PTR_NOGC (va, i);
- i++;
- } while (chunk->c && chunk->c == ' ' && i <= VARRAY_ACTIVE_SIZE (va));
+ for (; VEC_iterate (tree_chunk, chunks, i, chunk); i++)
+ if (chunk->c == 0 || chunk->c != ' ')
+ break;
return chunk;
}
@@ -252,16 +233,17 @@ chunks_lookahead (varray_type va, unsign
static char
tree_1st_char (tree t)
{
- varray_type va;
- tree_chunk *chunk;
+ VEC (tree_chunk, heap) *chunks;
+ tree_chunk chunk;
/* Don't hung on unnamed vars, etc. Cannot dump these nodes. */
if (TREE_CODE (t) == VAR_DECL || TREE_CODE_CLASS (TREE_CODE (t)) == 'x')
return '\0';
- va = lazy_dump_generic_node (t, 0, false);
- chunk = chunks_lookahead (va, 0);
- pp_free_list (va);
+ chunks = lazy_dump_generic_node (t, 0, false);
+ chunk = chunks_lookahead (chunks, 0);
+ pp_free_list (chunks);
+
return chunk_1st_char (chunk);
}
@@ -295,22 +277,20 @@ static bool match_tree_pattinfo (tree, p
a pattern. */
static bool
-match_chunks_pattinfo (varray_type va, patt_info *patt, const char *delim,
- cfg_node ctx_node)
+match_chunks_pattinfo (VEC (tree_chunk, heap) *chunks, patt_info *patt,
+ const char *delim, cfg_node ctx_node)
{
unsigned int i;
- tree_chunk *chunk;
+ tree_chunk chunk;
- for (i = 0; i < VARRAY_ACTIVE_SIZE (va); i++)
+ for (i = 0; VEC_iterate (tree_chunk, chunks, i, chunk); i++)
{
- chunk = VARRAY_GENERIC_PTR_NOGC (va, i);
-
if (chunk->t)
{
/* Compute delimiter for t. */
- char next_char = (i + 1 == VARRAY_ACTIVE_SIZE (va) ?
+ char next_char = (i + 1 == VEC_length (tree_chunk, chunks) ?
*delim :
- chunk_1st_char (chunks_lookahead (va, i + 1)));
+ chunk_1st_char (chunks_lookahead (chunks, i + 1)));
PP_TRACE (TRACE_MATCH_STEPS,
fprintf (stderr, "tree delimited by %c", next_char));
@@ -411,7 +391,6 @@ static bool
match_tree_pattinfo (tree t, patt_info *patt, const char *delim,
cfg_node ctx_node)
{
- varray_type va;
tree *pt;
hole *ph = NULL;
bool res;
@@ -480,9 +459,12 @@ match_tree_pattinfo (tree t, patt_info *
}
else
{
- /* can't swallow a whole tree, must recurse on it */
+ /* Can't swallow a whole tree, must recurse on it. */
+ VEC (tree_chunk, heap) *chunks;
+
PP_TRACE (TRACE_MATCH_STEPS, fprintf (stderr, "check chunks vs patt"));
- /* check an eventual pattern-only '(' to be skipped */
+
+ /* Check an eventual pattern-only '(' to be skipped. */
if (patt->format_spec[0] == '\\' && patt->format_spec[1] == '(')
{
PP_TRACE (TRACE_MATCH_STEPS, fprintf (stderr, "[skip lpar]"));
@@ -490,7 +472,7 @@ match_tree_pattinfo (tree t, patt_info *
}
/* On a tmpvar or a cast, there is no point to recurse directly (they
- cannot be in the pattern), so substitute it before */
+ cannot be in the pattern), so substitute it before. */
while ((val = substitute_tmp_var (t, ctx_node, false)) != NULL
|| (val = substitute_cast_expr (t)) != NULL)
{
@@ -499,9 +481,9 @@ match_tree_pattinfo (tree t, patt_info *
}
maybe_init_pretty_print (stdout);
- va = lazy_dump_generic_node (t, 0, false);
- res = match_chunks_pattinfo (va, patt, delim, ctx_node);
- pp_free_list (va);
+ chunks = lazy_dump_generic_node (t, 0, false);
+ res = match_chunks_pattinfo (chunks, patt, delim, ctx_node);
+ pp_free_list (chunks);
PP_TRACE (TRACE_MATCH_STEPS, fprintf (stderr, "%s chunks vs patt",
(res? "succeed": "fail")));
@@ -585,7 +567,7 @@ save_global_holes (void)
/* Restore the values of all global variables from a buffer */
void
-restore_global_holes (hole *saved)
+restore_global_holes (hole_p saved)
{
memcpy (global_holes, saved, sizeof (global_holes));
free (saved);
Index: gcc/tree-match.h
===================================================================
--- gcc/tree-match.h (revision 121080)
+++ gcc/tree-match.h (working copy)
@@ -27,6 +27,9 @@ Software Foundation, 51 Franklin Street,
/* At the statement level, a node in the CFG has the following type: */
typedef struct tree_statement_list_node *cfg_node;
+DEF_VEC_P (cfg_node);
+DEF_VEC_ALLOC_P (cfg_node, heap);
+
/* Accessor for a CFG node */
static inline tree
cfg_node_stmt (cfg_node node)
@@ -116,6 +119,11 @@ typedef struct hole_s {
cfg_node ctx;
} hole;
+typedef hole *hole_p;
+
+DEF_VEC_P (hole_p);
+DEF_VEC_ALLOC_P (hole_p, heap);
+
/* Named local holes are noted by a single lowercase letter */
#define LOCAL_MAX 26
/* Named global holes are noted by a single capital letter */
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in (revision 121080)
+++ gcc/Makefile.in (working copy)
@@ -2598,7 +2598,7 @@ params.o : params.c $(CONFIG_H) $(SYSTEM
pointer-set.o: pointer-set.c pointer-set.h $(CONFIG_H) $(SYSTEM_H)
hooks.o: hooks.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(HOOKS_H)
pretty-print.o: $(CONFIG_H) $(SYSTEM_H) coretypes.h intl.h $(PRETTY_PRINT_H) \
- $(TREE_H)
+ $(TREE_H) vec.h
errors.o : errors.c $(CONFIG_H) $(SYSTEM_H) errors.h $(BCONFIG_H)
$(out_object_file): $(out_file) $(CONFIG_H) coretypes.h $(TM_H) $(TREE_H) \
Index: gcc/ChangeLog.graphite
===================================================================
--- gcc/ChangeLog.graphite (revision 121080)
+++ gcc/ChangeLog.graphite (working copy)
@@ -1,3 +1,27 @@
+2007-03-12 Sebastian Pop <sebastian.pop@inria.fr>
+
+ * tree-pretty-print.c (dump_generic_bb_buff, lazy_dump_generic_node):
+ Use VECs instead of varrays.
+ * diagnostic.h (lazy_dump_generic_node): Update declaration.
+ * Makefile.in (pretty-print.o): Depend on vec.h.
+ * pretty-print.c: Include tree.h and vec.h.
+ (pp_clear_state, pp_write_list_to_stream, pp_base_format,
+ pp_base_format, pp_construct, pp_base_string, pp_lazy_mode,
+ new_tree_chunk, pp_add_tree, pp_add_string, pp_add_char, pp_write_list,
+ pp_free_list): Use VECs instead of varrays.
+ * pretty-print.h: Do not include varray.h.
+ (struct tree_chunk_s): Declaration moved before its use.
+ (output_buffer): Rename varray field to chunks.
+ * tree-match.c (tree_equal, chunk_1st_char, chunks_lookahead,
+ tree_1st_char, match_chunks_pattinfo, match_tree_pattinfo,
+ save_global_holes): Use VECs instead of varrays.
+ * tree-match.h: Declare VECs of cfg_node, and hole_p.
+ * tree-check.c (scan_cfg_stmts, push_node, print_matching_stmt): Removed.
+ (tree_check_instance, push_global_holes_if_new, tree_check,
+ execute_tree_check): Use VECs instead of varrays.
+ (gate_tree_check): Don't execute the CFG check when basic_block_info
+ is not available.
+
2007-01-12 Sebastian Pop <sebastian.pop@inria.fr>
* Merge from mainline (r115016:120733).
Index: gcc/tree-check.c
===================================================================
--- gcc/tree-check.c (revision 121080)
+++ gcc/tree-check.c (working copy)
@@ -41,6 +41,7 @@ Software Foundation, 51 Franklin Street,
#include "toplev.h"
#include "tree-match.h"
+
/* Raise a warning upon detecting a satisfied condate. The concept of
condate (control & data property to be checked) is described in
tree-match.h. */
@@ -65,45 +66,6 @@ tree_check_warning (const char *condname
fprintf (stderr, ".\n");
input_location = saved_location;
}
-
-/* Type of a callback for scan_cfg_stmts. */
-typedef void (*scan_cfg_stmts_fn)(cfg_node node, void *);
-
-/* Scan all statements in the CFG, and for every statement (matching
- the patern, if non-null), execute the callback. */
-
-static void
-scan_cfg_stmts (pattern patt, scan_cfg_stmts_fn callback, void *data)
-{
- basic_block bb;
-
- if (!basic_block_info)
- {
- fprintf (stderr, "no BBs available!\n");
- return;
- }
-
- FOR_EACH_BB (bb)
- {
- block_stmt_iterator bsi;
- tree stmt;
-
- for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
- {
- stmt = bsi_stmt (bsi);
-
- PP_TRACE (TRACE_MATCH, {
- lazy_print_generic_expr (stderr, stmt, 0);
- fprintf (stderr, "= ");
- print_generic_expr (stderr, stmt, 0);
- fprintf (stderr, "\n");
- });
-
- if (!patt || tree_match_disj (stmt, patt, bsi_cfg_node (bsi)))
- (*callback) (bsi_cfg_node (bsi), data);
- }
- }
-}
/* Initialization function for the tree-check pass. */
@@ -113,26 +75,6 @@ tree_check_init (void)
reset_global_holes ();
}
-/* scan_cfg_stmts callback used in tree_check_instance. */
-
-static void
-push_node (cfg_node node, void *data)
-{
- varray_type va = (varray_type) data;
- tree stmt = cfg_node_stmt (node);
-
- VARRAY_PUSH_GENERIC_PTR_NOGC (va, node);
-
- if (stmt)
- TREE_VISITED (stmt) = 1;
-
- PP_TRACE (TRACE_CHECK_STEPS, {
- fprintf (stderr, "found src stmt:");
- print_generic_expr (stderr, stmt, 0);
- fprintf (stderr, "\n");
- });
-}
-
/* Visit a CFG node. Used in tree_check_instance. */
static bool
@@ -172,40 +114,75 @@ check_node (cfg_node node, condate cond)
static void
tree_check_instance (condate cond)
{
- varray_type stack;
-
+ VEC (cfg_node, heap) *stack = VEC_alloc (cfg_node, heap, 100);
+ basic_block bb;
+ cfg_node node;
+ tree stmt;
+
PP_TRACE (TRACE_CHECK, {
fprintf (stderr, "checking condate instance:\n");
print_global_holes ();
- })
- /* Allocate stack for back-tracking up CFG. */
- VARRAY_GENERIC_PTR_NOGC_INIT (stack, 100, "TreeCheckStmtStack");
+ });
/* Push from nodes on the stack. */
PP_TRACE (TRACE_CHECK, fprintf (stderr, "searching src pat %s\n",
cond->from->format_spec));
- scan_cfg_stmts (cond->from, push_node, stack);
+
+ FOR_EACH_BB (bb)
+ {
+ block_stmt_iterator bsi;
+ tree stmt;
+
+ for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+ {
+ stmt = bsi_stmt (bsi);
+ pattern patt = cond->from;
+
+ PP_TRACE (TRACE_MATCH, {
+ lazy_print_generic_expr (stderr, stmt, 0);
+ fprintf (stderr, "= ");
+ print_generic_expr (stderr, stmt, 0);
+ fprintf (stderr, "\n");
+ });
+
+ if (!patt || tree_match_disj (stmt, patt, bsi_cfg_node (bsi)))
+ {
+ node = bsi_cfg_node (bsi);
+ stmt = cfg_node_stmt (node);
+
+ VEC_safe_push (cfg_node, heap, stack, node);
+
+ if (stmt)
+ TREE_VISITED (stmt) = 1;
+
+ PP_TRACE (TRACE_CHECK_STEPS, {
+ fprintf (stderr, "found src stmt:");
+ print_generic_expr (stderr, stmt, 0);
+ fprintf (stderr, "\n");
+ });
+ }
+ }
+ }
+
PP_TRACE (TRACE_CHECK, fprintf (stderr, "%d src stmts found\n",
- (unsigned) VARRAY_ACTIVE_SIZE (stack)));
+ (unsigned) VEC_length (cfg_node, stack)));
/* Perform depth-first search. */
- while (VARRAY_ACTIVE_SIZE (stack))
+ while (VEC_length (cfg_node, stack) != 0)
{
- cfg_node node;
- tree stmt;
cfg_node succ_node;
bool push_it;
- node = VARRAY_TOP_GENERIC_PTR_NOGC (stack);
- VARRAY_POP (stack);
+ node = VEC_pop (cfg_node, stack);
stmt = cfg_node_stmt (node);
+
if (node->next == NULL)
{
edge e;
edge_iterator ei;
- basic_block bb;
-
+
bb = bb_for_stmt (stmt);
+
FOR_EACH_EDGE (e, ei, bb->succs)
{
if (e->dest == EXIT_BLOCK_PTR)
@@ -235,7 +212,7 @@ tree_check_instance (condate cond)
push_it = check_node (succ_node, cond);
if (push_it)
- VARRAY_PUSH_GENERIC_PTR_NOGC (stack, succ_node);
+ VEC_safe_push (cfg_node, heap, stack, succ_node);
}
}
else
@@ -244,31 +221,31 @@ tree_check_instance (condate cond)
push_it = check_node (succ_node, cond);
if (push_it)
- VARRAY_PUSH_GENERIC_PTR_NOGC (stack, succ_node);
+ VEC_safe_push (cfg_node, heap, stack, succ_node);
}
- } /* while DFS */
- VARRAY_FREE (stack);
+ }
+
+ VEC_free (cfg_node, heap, stack);
}
-/* scan_cfg_stmts() callback used in tree_check() to collect condate
- instances. An instance is new if the combination of global hole
- values has not been seen yet. */
+/* Collect new condate instances. An instance is new if the
+ combination of global hole values has not been seen yet. */
-static void
-push_global_holes_if_new (cfg_node node ATTRIBUTE_UNUSED, void *data)
+static void
+push_global_holes_if_new (VEC (hole_p, heap) *stack)
{
- varray_type va = (varray_type) data;
unsigned int i;
+ hole_p h;
/* Check if these global holes were already seen. */
- for (i=0; i < VARRAY_ACTIVE_SIZE (va); i++)
- if (eq_global_holes (global_holes, VARRAY_GENERIC_PTR_NOGC (va, i)))
+ for (i = 0; VEC_iterate (hole_p, stack, i, h); i++)
+ if (eq_global_holes (global_holes, h))
{
reset_global_holes ();
- return;
+ return;
}
- VARRAY_PUSH_GENERIC_PTR_NOGC (va, save_global_holes ());
+ VEC_safe_push (hole_p, heap, stack, save_global_holes ());
reset_global_holes ();
}
@@ -277,28 +254,50 @@ push_global_holes_if_new (cfg_node node
static void
tree_check (condate cond)
{
- varray_type holes_stack;
-
/* Allocate stack for collecting condate instances. */
- VARRAY_GENERIC_PTR_NOGC_INIT (holes_stack, 10, "TreeCheckHolesStack");
-
+ VEC (hole_p, heap) *stack = VEC_alloc (hole_p, heap, 10);
+ pattern patt = cond->from;
+ basic_block bb;
+
PP_TRACE (TRACE_CHECK,
fprintf (stderr, "searching src pat %s\n",
- cond->from->format_spec));
- scan_cfg_stmts (cond->from, push_global_holes_if_new, holes_stack);
+ patt->format_spec));
+
+ FOR_EACH_BB (bb)
+ {
+ block_stmt_iterator bsi;
+ tree stmt;
+
+ for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+ {
+ stmt = bsi_stmt (bsi);
+
+ PP_TRACE (TRACE_MATCH, {
+ lazy_print_generic_expr (stderr, stmt, 0);
+ fprintf (stderr, "= ");
+ print_generic_expr (stderr, stmt, 0);
+ fprintf (stderr, "\n");
+ });
+
+ if (!patt || tree_match_disj (stmt, patt, bsi_cfg_node (bsi)))
+ push_global_holes_if_new (stack);
+ }
+ }
+
PP_TRACE (TRACE_CHECK, fprintf (stderr, "%d condate instances found\n",
- (unsigned) VARRAY_ACTIVE_SIZE (holes_stack)));
+ VEC_length (hole_p, stack)));
- while (VARRAY_ACTIVE_SIZE (holes_stack))
+ while (VEC_length (hole_p, stack))
{
- restore_global_holes (VARRAY_TOP_GENERIC_PTR_NOGC (holes_stack));
- VARRAY_POP (holes_stack);
+ hole_p h = VEC_pop (hole_p, stack);
+
+ restore_global_holes (h);
tree_check_instance (cond);
PP_TRACE (TRACE_CHECK, fprintf (stderr, "recounting stmts\n"));
tree_check_init (); /* clear visited flag */
}
- VARRAY_FREE (holes_stack);
+ VEC_free (hole_p, heap, stack);
}
/* Read from a file a string delimted by double quotes. */
@@ -459,17 +458,6 @@ parse_tree_check_file_once (void)
return 0;
}
-/* scan_cfg_stmts callback used in execute_tree_check. */
-
-static void
-print_matching_stmt (cfg_node node ATTRIBUTE_UNUSED,
- void *data ATTRIBUTE_UNUSED)
-{
- tree stmt = cfg_node_stmt (node);
- tree_check_warning (tree_check_string, stmt, OPT_ftree_check_);
- reset_global_holes ();
-}
-
/* Main function of the tree-check pass. Triggered either by
-ftree-check or -ftree-checks. */
@@ -498,10 +486,37 @@ execute_tree_check (void)
else
{
/* tree_check_string != NULL */
- pattern patt;
+ basic_block bb;
+ pattern patt = mkpat (tree_check_string);
+
reset_global_holes ();
- patt = mkpat (tree_check_string);
- scan_cfg_stmts (patt, print_matching_stmt, NULL);
+
+ FOR_EACH_BB (bb)
+ {
+ block_stmt_iterator bsi;
+ tree stmt;
+
+ for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+ {
+ stmt = bsi_stmt (bsi);
+
+ PP_TRACE (TRACE_MATCH, {
+ lazy_print_generic_expr (stderr, stmt, 0);
+ fprintf (stderr, "= ");
+ print_generic_expr (stderr, stmt, 0);
+ fprintf (stderr, "\n");
+ });
+
+ if (!patt || tree_match_disj (stmt, patt, bsi_cfg_node (bsi)))
+ {
+ tree_check_warning (tree_check_string,
+ cfg_node_stmt (bsi_cfg_node (bsi)),
+ OPT_ftree_check_);
+ reset_global_holes ();
+ }
+ }
+ }
+
rmpat (patt);
}
@@ -512,7 +527,8 @@ execute_tree_check (void)
static bool
gate_tree_check (void)
{
- return (tree_check_file != 0 || tree_check_string != 0);
+ return ((tree_check_file != 0 || tree_check_string != 0)
+ && basic_block_info != 0);
}
struct tree_opt_pass pass_check =