Re: tuples: initial infrastructure

2007-04-23 Thread Aldy Hernandez

> > I figured
> > it'd be better than doing GS_SEQP_FIRST(&non_pointer), but I can if you
> > prefer.
> 
> I think I would, though without the "P".

Ok, everything fixed, except I haven't added the sequence iterators yet.

I am committing the patch below to the gimple-tuples-branch.

Thanks again.

* gimple-ir.c: New file.
* gimple-ir.h: New file.
* gsstruct.def: New file.
* gs.def: New file.
* gengtype.c (open_base_files): Add gimple-ir.h.
* tree-gimple.h: Include gimple-ir.h.
Add sequence to gimplify_expr and gimplify_body prototypes.
* gimplify.c: Include gimple-ir.h.
(gimplify_and_add): Adjust for gimple IR.
(gimplify_return_expr): Same.
(gimplify_stmt): Add seq_p argument.
(gimplify_expr): Add seq_p sequence and adjust accordingly.
(gimplify_body): Same.
* coretypes.h: Add gimple_statement_d and gimple definitions.
* Makefile.in (GIMPLE_IR_H): New.
(TREE_GIMPLE_H): Add gimple-ir.h.
(OBJS-common): Add gimple-ir.o.
(gimplify.o): Add GIMPLE_IR_H.
(gimple-ir.o): New.
(build/gencheck.o): Add gs.def.

Index: gimple-ir.c
===
--- gimple-ir.c (revision 0)
+++ gimple-ir.c (revision 0)
@@ -0,0 +1,154 @@
+/* Gimple IR support functions.
+
+   Copyright 2007 Free Software Foundation, Inc.
+   Contributed by Aldy Hernandez <[EMAIL PROTECTED]>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tree.h"
+#include "ggc.h"
+#include "errors.h"
+#include "tree-gimple.h"
+#include "gimple-ir.h"
+
+#define DEFGSCODE(SYM, NAME)   NAME,
+static const char *gs_code_name[] = {
+#include "gs.def"
+};
+#undef DEFGSCODE
+
+/* Gimple tuple constructors.  */
+
+/* Construct a GS_RETURN statement.  */
+
+gimple
+gs_build_return (bool result_decl_p, tree retval)
+{
+  gimple p = ggc_alloc_cleared (sizeof (struct gimple_statement_return));
+
+  GS_CODE (p) = GS_RETURN;
+  GS_SUBCODE_FLAGS (p) = (int) result_decl_p;
+  GS_RETURN_OPERAND_RETVAL (p) = retval;
+  return p;
+}
+
+/* Return which gimple structure is used by T.  The enums here are defined
+   in gsstruct.def.  */
+
+enum gimple_statement_structure_enum
+gimple_statement_structure (gimple gs)
+{
+  unsigned int code = GS_CODE (gs);
+  unsigned int subcode = GS_SUBCODE_FLAGS (gs);
+
+  switch (code)
+{
+case GS_ASSIGN:
+  {
+   enum tree_code_class class = TREE_CODE_CLASS (subcode);
+
+   if (class == tcc_binary
+   || class == tcc_comparison)
+ return GSS_ASSIGN_BINARY;
+   else 
+ {
+   /* There can be 3 types of unary operations:
+
+SYM =<== GSS_ASSIGN_UNARY_REG
+SYM = SSA_NAME <== GSS_ASSIGN_UNARY_REG
+SYM = SYM2 <== GSS_ASSIGN_UNARY_MEM
+SYM = UNARY_OP SYM2<== GSS_ASSIGN_UNARY_MEM
+   */
+   if (class == tcc_constant || subcode == SSA_NAME)
+ return GSS_ASSIGN_UNARY_REG;
+
+   /* Must be class == tcc_unary.  */
+   return GSS_ASSIGN_UNARY_MEM;
+ }
+  }
+case GS_ASM:   return GSS_ASM;
+case GS_BIND:  return GSS_BIND;
+case GS_CALL:  return GSS_CALL;
+case GS_CATCH: return GSS_CATCH;
+case GS_COND:  return GSS_COND;
+case GS_EH_FILTER: return GSS_EH_FILTER;
+case GS_GOTO:  return GSS_GOTO;
+case GS_LABEL: return GSS_LABEL;
+case GS_NOP:   return GSS_BASE;
+case GS_PHI:   return GSS_PHI;
+case GS_RESX:  return GSS_RESX;
+case GS_RETURN:return GSS_RETURN;
+case GS_SWITCH:return GSS_SWITCH;
+case GS_TRY:   return GSS_TRY;
+case GS_OMP_CRITICAL:  return GSS_OMP_CRITICAL;
+case GS_OMP_FOR:   return GSS_OMP_FOR;
+case GS_OMP_CONTINUE:
+case GS_OMP_MASTER:
+case GS_OMP_ORDERED:
+case GS_OMP_RETURN:
+case GS_OMP_SECTION:
+   return GSS_OMP;
+case GS_OMP_PARALLEL:  return GSS_OMP_PARALLEL;
+case GS_OMP_SECTIONS:  return GSS_

Re: tuples: initial infrastructure

2007-04-23 Thread Richard Henderson
On Mon, Apr 23, 2007 at 04:30:40PM -0400, Aldy Hernandez wrote:
> I figured
> it'd be better than doing GS_SEQP_FIRST(&non_pointer), but I can if you
> prefer.

I think I would, though without the "P".


r~


Re: tuples: initial infrastructure

2007-04-23 Thread Aldy Hernandez
> > +/* A sequences of gimple statements.  */
> > +#define GS_SEQP_FIRST(S)   (S)->first
> > +#define GS_SEQP_LAST(S)(S)->last
> > +#define GS_SEQ_FIRST(S)(S).first
> > +#define GS_SEQ_LAST(S) (S).last
> 
> Why do you have both of these?

Most places in the gimplifier we will send sequences as pointers, but
for saving state (see gimplify_and_add), we use local variables.  I figured
it'd be better than doing GS_SEQP_FIRST(&non_pointer), but I can if you
prefer.

> Otherwise it looks ok.  I figure you'll want to build a set of
> iterators and such for gs_sequences, like for tree-iterator.[ch].

Yee haw!  Thanks so much for reviewing this.

I'll commit to the branch and start the long haul.

Aldy


Re: tuples: initial infrastructure

2007-04-23 Thread Richard Henderson
On Fri, Apr 20, 2007 at 01:07:14PM -0400, Aldy Hernandez wrote:
> + /* There can be 3 types of unary operations:
> +
> +  SYM =<== GSS_ASSIGN_UNARY_REG
> +  SYM = SYM2 <== GSS_ASSIGN_UNARY_MEM

Um, ssa_name = ssa_name isn't  a memory 

> +/* A sequences of gimple statements.  */
> +#define GS_SEQP_FIRST(S) (S)->first
> +#define GS_SEQP_LAST(S)  (S)->last
> +#define GS_SEQ_FIRST(S)  (S).first
> +#define GS_SEQ_LAST(S)   (S).last

Why do you have both of these?

Otherwise it looks ok.  I figure you'll want to build a set of
iterators and such for gs_sequences, like for tree-iterator.[ch].


r~


tuples: initial infrastructure

2007-04-20 Thread Aldy Hernandez
Hi folks.

I have some preliminary code laying out the tuples infrastructure as has
been documented in the tuples design document.

I'd like to get this out for public review sooner than later, to make sure
I'm not taking any wrong approaches, and folks know where things are.  I'll
be reviving the gimple-tuples-branch again, and starting to offload things
there.

The current plan is to disable the passes that haven't been converted,
start with the gimplifier and out-of-ssa, then work towards the middle.
I'm currently working on the gimplifier.  I also suspect we'll have to write
a tuples back to trees pass for the rtl expander, while the expander is
converted.

Richard, Diego, could y'all take a look at this?

A few points...

I have currently converted gimplify_return_expr() in the gimplifier to give
an idea of how I envision things happening.  Trees are converted into a
sequence, similar to the way we expand rtl, and the current {pre,post}_q's
become sequences that get passed around.  Sequences are just a structure
with a first and last gimple statement (see struct gs_sequence).

At rth's suggestion, all tuple fields `body' are no sequences, instead
of trees.

I am a little uncomfortable with gimple_statement_structure() where it comes
to determining what subcode to use for GS_ASSIGN.  Richard had pointed out
that it was too convoluted.  I simplified things a bit, but it seems the
underlying problem may be that we may be overloading GS_ASSIGN too much.
I don't know.  Suggestions welcome.

This is just a general idea to make sure we're on the same page, or at least
the same chapter.

Aldy

Index: gengtype.c
===
--- gengtype.c  (revision 123746)
+++ gengtype.c  (working copy)
@@ -1534,7 +1534,7 @@ open_base_files (void)
   "hard-reg-set.h", "basic-block.h", "cselib.h", "insn-addr.h",
   "optabs.h", "libfuncs.h", "debug.h", "ggc.h", "cgraph.h",
   "tree-flow.h", "reload.h", "cpp-id-data.h", "tree-chrec.h",
-  "cfglayout.h", "except.h", "output.h", NULL
+  "cfglayout.h", "except.h", "output.h", "gimple-ir.h", NULL
 };
 const char *const *ifp;
 outf_p gtype_desc_c;
Index: tree-gimple.h
===
--- tree-gimple.h   (revision 123746)
+++ tree-gimple.h   (working copy)
@@ -24,6 +24,7 @@ Boston, MA 02110-1301, USA.  */
 
 
 #include "tree-iterator.h"
+#include "gimple-ir.h"
 
 extern tree create_tmp_var_raw (tree, const char *);
 extern tree create_tmp_var_name (const char *);
@@ -110,13 +111,13 @@ enum gimplify_status {
   GS_ALL_DONE  = 1 /* The expression is fully gimplified.  */
 };
 
-extern enum gimplify_status gimplify_expr (tree *, tree *, tree *,
+extern enum gimplify_status gimplify_expr (tree *, gs_seq, tree *, tree *,
   bool (*) (tree), fallback_t);
 extern void gimplify_type_sizes (tree, tree *);
 extern void gimplify_one_sizepos (tree *, tree *);
 extern void gimplify_stmt (tree *);
 extern void gimplify_to_stmt_list (tree *);
-extern void gimplify_body (tree *, tree, bool);
+extern void gimplify_body (tree *, gs_seq, tree, bool);
 extern void push_gimplify_context (void);
 extern void pop_gimplify_context (tree);
 extern void gimplify_and_add (tree, tree *);
Index: gsstruct.def
===
--- gsstruct.def(revision 0)
+++ gsstruct.def(revision 0)
@@ -0,0 +1,55 @@
+/* This file contains the definitions for the gimple IR structure
+   enumeration used in GCC.
+
+   Copyright (C) 2007 Free Software Foundation, Inc.
+   Contributed by Aldy Hernandez <[EMAIL PROTECTED]>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (GSS_at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
+
+/* The format of this file is
+   DEFGSSTRUCT(GSS_enumeration value, printable name).
+   Each enum value should correspond with a single member of the union
+   gimple_statement_d.
+   */
+
+DEFGSSTRUCT(GSS_BASE, "base")
+DEFGSSTRUCT(GSS_WITH_OPS, "with_ops")
+DEFGSSTRUCT(GSS_WITH_MEM_OPS, "with_mem_ops")
+DEFGSSTRUCT(GSS_OMP, "omp")
+
+DEFGSSTRUCT(GSS_BIND, "bind")
+DEFGSSTRUCT(GSS_CATCH, "catch")
+DEFGSSTRUCT(GSS_EH_FILTER, "eh_filter")
+DEFGSSTRUCT(GSS_LABEL, "label")
+DEFGSSTRUCT(GSS_PHI, "phi")
+DEFGSSTRUCT(GSS_RESX, "resx")
+DEFGSSTRUCT(GSS_TRY, "try")
+DEFG