diff mbox

read-md.c: Move various state to within class rtx_reader

Message ID 1476468970-12787-1-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm Oct. 14, 2016, 6:16 p.m. UTC
On Wed, 2016-10-12 at 22:57 +0100, Richard Sandiford wrote:
> Sorry, haven't had time to read the full series yet, but:
> 
> David Malcolm <dmalcolm@redhat.com> writes:
> > On Wed, 2016-10-05 at 17:51 +0200, Bernd Schmidt wrote:
> > > On 10/05/2016 06:14 PM, David Malcolm wrote:
> > > > The selftests for the RTL frontend require supporting multiple
> > > > reader instances being alive one after another in-process, so
> > > > this lack of cleanup would become a leak.
> > > 
> > > > +  /* Initialize global data.  */
> > > > +  obstack_init (&string_obstack);
> > > > +  ptr_locs = htab_create (161, leading_ptr_hash,
> > > > leading_ptr_eq_p,
> > > > 0);
> > > > +  obstack_init (&ptr_loc_obstack);
> > > > +  joined_conditions = htab_create (161, leading_ptr_hash,
> > > > leading_ptr_eq_p, 0);
> > > > +  obstack_init (&joined_conditions_obstack);
> > > > +  md_constants = htab_create (31, leading_string_hash,
> > > > +			      leading_string_eq_p, (htab_del)
> > > > 0);
> > > > +  enum_types = htab_create (31, leading_string_hash,
> > > > +			    leading_string_eq_p, (htab_del)
> > > > 0);
> > > > +
> > > > +  /* Unlock the stdio streams.  */
> > > > +  unlock_std_streams ();
> > > 
> > > Hmm, but these are global statics. Shouldn't they first be moved
> > > to
> > > become class members?
> > 
> > [CCing Richard Sandiford]
> > 
> > I tried to move these into class rtx_reader, but doing so rapidly
> > became quite invasive, with many of functions in the gen* tools
> > becoming methods.
> 
> Is that just to avoid introducing explicit references to the global
> rtx_reader object in the gen* tools?  If so, then TBH adding those
> references sound better to me than tying generator-specific functions
> to the rtx reader (not least because most of them do more than just
> read rtl).
> 
> > Arguably that would be a good thing, but there are a couple of
> > issues:
> > 
> > (a) some of these functions take "vec" arguments; moving them from
> > static functions to being class methods requires that vec.h has
> > been
> > included when the relevant class decl is parsed.
> 
> I don't think including vec.h more often should be a blocker though.
> :-)
> 
> > (b) rtx_reader turns into a bug dumping ground of methods, for the
> > union of all of the various gen* tools.
> > 
> > One way to alleviate these issues would be to do the split of
> > rtx_reader into base_rtx_reader vs rtx_reader from patch 9 of the
> > kit:
> >   https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00273.html
> > and perhaps to split out part of read-md.h into a new read-rtl.h.
> > 
> > Before I reorganize the patches, does this approach sound
> > reasonable?
> > 
> > Alternatively, a less invasive approach is to have an accessor for
> > these fields, so that things using them can get at them via the
> > rtx_reader_ptr singleton e.g.:
> > 
> > void
> > grow_string_obstack (char ch)
> > {
> >    obstack_1grow (rtx_reader_ptr->get_string_obstack (), ch);
> > }
> > 
> > and similar.
> 
> I think it's OK for the generators to refer rtx_reader_ptr directly.
> Obviously that makes the patches more invasive, but hopefully the
> extra changes are mechanical.
> 
> Thanks,
> Richard

Thanks.

Here's an updated version of the patch.

As before:

Various global data items relating to reading .md files are
currently initialized in rtx_reader::read_md_files, and are
not cleaned up.

The selftests for the RTL frontend require supporting multiple
reader instances being alive one after another in-process, so
this lack of cleanup would become a leak.

What's new:

In this version of the patch, I've moved the global variables to
be fields of class rtx_reader, moving their setup to the constructor.
The patch adds matching cleanups to the destructor, along with a
cleanup of m_base_dir.

Doing so requires updating the various users of these fields.
Where it seemed appropriate, I made the functions be methods
of rtx_reader.  In other cases, I updated them to access the fields
via rtx_reader_ptr.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

Comparing md5sums of BUILD/gcc/insn-*.[hc] before/after shows them to be
unchanged by the patch.

OK for trunk?

gcc/ChangeLog:
	* genattrtab.c (gen_attr): Use rtx_reader_ptr for lookup_enum_type
	call.
	* genconstants.c: Include "statistics.h" and "vec.h".
	(main): Update for conversion of traverse_enum_types to a method.
	* genenums.c: Include "statistics.h" and "vec.h".
	(main): Update for conversion of traverse_enum_types to a method.
	* genmddeps.c: Include "statistics.h" and "vec.h".
	* gensupport.c (gen_mnemonic_setattr): Update for move of
	string_obstack to a field of rtx_reader.
	(mnemonic_htab_callback): Likewise.
	(gen_mnemonic_attr): Likewise.
	* read-md.c: Include "statistics.h" and "vec.h".
	(string_obstack): Convert this global to field "m_string_obstack"
	of class rtx_reader.
	(ptr_locs): Likewise, as "m_ptr_locs".
	(ptr_loc_obstack): Likewise, as "m_ptr_loc_obstack".
	(joined_conditions): Likewise, as "m_joined_conditions".
	(joined_conditions_obstack): Likewise, as "m_joined_conditions_obstack".
	(md_constants): Likewise, as "m_md_constants".
	(enum_types): Likewise, as "m_enum_types".
	(set_md_ptr_loc): Convert from function to...
	(rtx_reader::set_md_ptr_loc): ...this method.
	(get_md_ptr_loc): Convert from function to...
	(rtx_reader::get_md_ptr_loc): ...this method.
	(copy_md_ptr_loc): Use rtx_reader_ptr when calling methods.
	(fprint_md_ptr_loc): Likewise.
	(join_c_conditions): Convert from function to...
	(rtx_reader::join_c_conditions): ...this method.
	(join_c_conditions): Reinstate, with a new function calling the
	above method.
	(fprint_c_condition): Convert from function to...
	(rtx_reader::fprint_c_condition): ...this method.
	(fprint_c_condition): Reinstate, with a new function calling the
	above method.
	(read_name): Convert from function to...
	(rtx_reader::read_name): ...this method.
	(read_escape): Convert from function to...
	(rtx_reader::read_escape): ...this method.
	(read_quoted_string): Convert from function to...
	(rtx_reader::read_quoted_string): ...this method.
	(read_braced_string): Convert from function to...
	(rtx_reader::read_braced_string): ...this method.
	(read_string): Convert from function to...
	(rtx_reader::read_string): ...this method.
	(read_skip_construct): Convert from function to...
	(rtx_reader::read_skip_construct): ...this method.
	(handle_constants): Convert from function to...
	(rtx_reader::handle_constants): ...this method.
	(traverse_md_constants): Use rtx_reader_ptr when calling methods.
	(handle_enum): Convert from function to...
	(rtx_reader::handle_enum): ...this method.
	(lookup_enum_type): Convert from function to...
	(rtx_reader::lookup_enum_type): ...this method.
	(traverse_enum_types): Convert from function to...
	(rtx_reader::traverse_enum_types): ...this method.
	(rtx_reader::rtx_reader): Move initializations
	of various former global data from rtx_reader::read_md_files to
	here, as fields, along with the call to unlock_std_streams.
	(rtx_reader::~rtx_reader): Clean up m_base_dir, and clean up
	the new fields.
	(rtx_reader::read_md_files): Move initializations of various
	global data from here to the ctor.
	* read-md.h (read_name): Convert global decl to...
	(rtx_reader::read_name): ...this new method decl.
	(rtx_reader::read_escape): New method decl.
	(read_quoted_string): Convert global decl to...
	(rtx_reader::read_quoted_string): ...this new method decl.
	(rtx_reader::read_braced_string): New method decl.
	(read_string): Convert global decl to...
	(rtx_reader::read_string): ...this new method decl.
	(rtx_reader::read_skip_construct): New method decl.
	(rtx_reader::set_md_ptr_loc): New method decl.
	(rtx_reader::get_md_ptr_loc): New method decl.
	(rtx_reader::lookup_enum_type): New method decl.
	(rtx_reader::traverse_enum_types): New method decl.
	(rtx_reader::handle_constants): New method decl.
	(rtx_reader::handle_enum): New method decl.
	(rtx_reader::join_c_conditions): New method decl.
	(rtx_reader::fprint_c_condition): New method decl.
	(rtx_reader::apply_iterator_to_string): New method decl.
	(rtx_reader::copy_rtx_for_iterators): New method decl.
	(rtx_reader::read_conditions): New method decl.
	(rtx_reader::record_potential_iterator_use): New method decl.
	(rtx_reader::read_mapping): New method decl.
	(rtx_reader::read_rtx): New method decl.
	(rtx_reader::read_rtx_code): New method decl.
	(rtx_reader::read_rtx_operand): New method decl.
	(rtx_reader::read_nested_rtx): New method decl.
	(rtx_reader::read_rtx_variadic): New method decl.
	(rtx_reader::get_string_obstack): New method.
	(rtx_reader::get_md_constants): New method.
	(string_obstack): Convert global decl to...
	(rtx_reader::m_string_obstack): ...this new field.
	(rtx_reader::m_ptr_locs): New field.
	(rtx_reader::m_ptr_loc_obstack): New field.
	(rtx_reader::m_joined_conditions): New field.
	(rtx_reader::m_joined_conditions_obstack): New field.
	(rtx_reader::m_md_constants): New field.
	(rtx_reader::m_enum_types): New field.
	(fprint_md_ptr_loc): Delete global decl.
	* read-rtl.c (apply_iterator_to_string): Convert to...
	(rtx_reader::apply_iterator_to_string): ...this method.
	(copy_rtx_for_iterators): Convert to...
	(rtx_reader::copy_rtx_for_iterators): ...this method.
	(apply_iterators): Use rtx_reader_ptr for copy_rtx_for_iterators
	call.
	(read_conditions): Convert to...
	(rtx_reader::read_conditions): ...this method.
	(record_potential_iterator_use): Convert to...
	(rtx_reader::record_potential_iterator_use): ...this method.
	(read_mapping): Convert to...
	(rtx_reader::read_mapping): ...this method.
	(read_subst_mapping): Use rtx_reader_ptr for read_string call.
	(read_rtx): Convert to...
	(rtx_reader::read_rtx): ...this method.
	(read_rtx_code): Convert to...
	(rtx_reader::read_rtx_code): ...this method.
	(read_rtx_operand): Convert from function to...
	(rtx_reader::read_rtx_operand): ...this method.  Update for move
	of string_obstack to a field.
	(read_nested_rtx): Convert from function to..
	(rtx_reader::read_nested_rtx): ...this method.
	(read_rtx_variadic): Convert from function to..
	(rtx_reader::read_rtx_variadic): ...this method.
---
 gcc/genattrtab.c   |   2 +-
 gcc/genconstants.c |   4 +-
 gcc/genenums.c     |   4 +-
 gcc/genmddeps.c    |   2 +
 gcc/gensupport.c   |  28 ++++---
 gcc/read-md.c      | 209 ++++++++++++++++++++++++++++-------------------------
 gcc/read-md.h      |  66 +++++++++++++++--
 gcc/read-rtl.c     |  72 +++++++++---------
 8 files changed, 230 insertions(+), 157 deletions(-)

Comments

Bernd Schmidt Oct. 17, 2016, 11:05 a.m. UTC | #1
On 10/14/2016 08:16 PM, David Malcolm wrote:

> In this version of the patch, I've moved the global variables to
> be fields of class rtx_reader, moving their setup to the constructor.
> The patch adds matching cleanups to the destructor, along with a
> cleanup of m_base_dir.
>
> Doing so requires updating the various users of these fields.
> Where it seemed appropriate, I made the functions be methods
> of rtx_reader.  In other cases, I updated them to access the fields
> via rtx_reader_ptr.
>
> Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

Well, at least the actual patch doesn't look as scary as the ChangeLog.

There are things one could discuss, like maybe gensupport should just 
have its own string obstack. But on the whole I think this is 
reasonable, so OK.


Bernd
Richard Sandiford Oct. 17, 2016, 11:37 a.m. UTC | #2
David Malcolm <dmalcolm@redhat.com> writes:
> @@ -2388,8 +2389,10 @@ gen_mnemonic_setattr (htab_t mnemonic_htab, rtx insn)
>  static int
>  mnemonic_htab_callback (void **slot, void *info ATTRIBUTE_UNUSED)
>  {
> -  obstack_grow (&string_obstack, (char*)*slot, strlen ((char*)*slot));
> -  obstack_1grow (&string_obstack, ',');
> +  struct obstack *string_obstack = rtx_reader_ptr->get_string_obstack ();
> +
> +  obstack_grow (string_obstack, (char*)*slot, strlen ((char*)*slot));
> +  obstack_1grow (string_obstack, ',');

The old code was missing a space after the cast.  Might be good to
add it while you're there.

> @@ -2470,8 +2474,8 @@ gen_mnemonic_attr (void)
>    htab_traverse (mnemonic_htab, mnemonic_htab_callback, NULL);
>  
>    /* Replace the last ',' with the zero end character.  */
> -  *((char *)obstack_next_free (&string_obstack) - 1) = '\0';
> -  XSTR (mnemonic_attr, 1) = XOBFINISH (&string_obstack, char *);
> +  *((char *)obstack_next_free (string_obstack) - 1) = '\0';
> +  XSTR (mnemonic_attr, 1) = XOBFINISH (string_obstack, char *);

Same here.

> @@ -129,9 +105,9 @@ get_md_ptr_loc (const void *ptr)
>  void
>  copy_md_ptr_loc (const void *new_ptr, const void *old_ptr)
>  {
> -  const struct ptr_loc *loc = get_md_ptr_loc (old_ptr);
> +  const struct ptr_loc *loc = rtx_reader_ptr->get_md_ptr_loc (old_ptr);
>    if (loc != 0)
> -    set_md_ptr_loc (new_ptr, loc->filename, loc->lineno);
> +    rtx_reader_ptr->set_md_ptr_loc (new_ptr, loc->filename, loc->lineno);
>  }

I suppose it's bikeshedding, but since you need access to an rtx_reader
to get and set the locations, it feels like the rtx_reader should be
a parameter here too.

> @@ -140,7 +116,7 @@ copy_md_ptr_loc (const void *new_ptr, const void *old_ptr)
>  void
>  fprint_md_ptr_loc (FILE *outf, const void *ptr)
>  {
> -  const struct ptr_loc *loc = get_md_ptr_loc (ptr);
> +  const struct ptr_loc *loc = rtx_reader_ptr->get_md_ptr_loc (ptr);
>    if (loc != 0)
>      fprintf (outf, "#line %d \"%s\"\n", loc->lineno, loc->filename);
>  }

Same here.

> +/* As rtx_reader::join_c_conditions above, but call it on the singleton
> +   rtx_reader instance.  */
> +
> +const char *
> +join_c_conditions (const char *cond1, const char *cond2)
> +{
> +  return rtx_reader_ptr->join_c_conditions (cond1, cond2);
> +}
> +

I think it'd be better to have the callers use the rtx_reader_ptr
explicitly.

In general I think it'd be better if the read-md.h interface itself
didn't rely on there being a singleton, other than providing the
rtx_reader_ptr variable.  It would then be easy to allow non-singleton
uses in future, without having to update gen* calls a second time.

> @@ -204,6 +189,15 @@ fprint_c_condition (FILE *outf, const char *cond)
>      }
>  }
>  
> +/* As rtx_reader::fprint_c_condition above, but call it on the singleton
> +   rtx_reader instance.  */
> +
> +void
> +fprint_c_condition (FILE *outf, const char *cond)
> +{
> +  rtx_reader_ptr->fprint_c_condition (outf, cond);
> +}
> +
>  /* Special fprint_c_condition for writing to STDOUT.  */
>  
>  void

Another instance of the above.

> @@ -808,7 +802,7 @@ handle_constants (void)
>  void
>  traverse_md_constants (htab_trav callback, void *info)
>  {
> -  htab_traverse (md_constants, callback, info);
> +  htab_traverse (rtx_reader_ptr->get_md_constants (), callback, info);
>  }

Here too.

I assume you didn't turn the functions above into member functions
because they aren't primitives.  OTOH it might seem inconsistent
to have things like traverse_enum_types as member functions but
traverse_md_constants not.

Thanks,
Richard
diff mbox

Patch

diff --git a/gcc/genattrtab.c b/gcc/genattrtab.c
index dbcdcfc..5a844f4 100644
--- a/gcc/genattrtab.c
+++ b/gcc/genattrtab.c
@@ -3157,7 +3157,7 @@  gen_attr (md_rtx_info *info)
   if (GET_CODE (def) == DEFINE_ENUM_ATTR)
     {
       attr->enum_name = XSTR (def, 1);
-      et = lookup_enum_type (XSTR (def, 1));
+      et = rtx_reader_ptr->lookup_enum_type (XSTR (def, 1));
       if (!et || !et->md_p)
 	error_at (info->loc, "No define_enum called `%s' defined",
 		  attr->name);
diff --git a/gcc/genconstants.c b/gcc/genconstants.c
index e8be5b6..a018889 100644
--- a/gcc/genconstants.c
+++ b/gcc/genconstants.c
@@ -28,6 +28,8 @@  along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "errors.h"
+#include "statistics.h"
+#include "vec.h"
 #include "read-md.h"
 
 /* Called via traverse_md_constants; emit a #define for
@@ -92,7 +94,7 @@  main (int argc, const char **argv)
   puts ("#define GCC_INSN_CONSTANTS_H\n");
 
   traverse_md_constants (print_md_constant, 0);
-  traverse_enum_types (print_enum_type, 0);
+  reader.traverse_enum_types (print_enum_type, 0);
 
   puts ("\n#endif /* GCC_INSN_CONSTANTS_H */");
 
diff --git a/gcc/genenums.c b/gcc/genenums.c
index 8af8d9a..2dc98ce 100644
--- a/gcc/genenums.c
+++ b/gcc/genenums.c
@@ -21,6 +21,8 @@  along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "errors.h"
+#include "statistics.h"
+#include "vec.h"
 #include "read-md.h"
 
 /* Called via traverse_enum_types.  Emit an enum definition for
@@ -59,7 +61,7 @@  main (int argc, const char **argv)
   puts ("#include \"system.h\"\n");
   puts ("#include \"insn-constants.h\"\n");
 
-  traverse_enum_types (print_enum_type, 0);
+  reader.traverse_enum_types (print_enum_type, 0);
 
   if (ferror (stdout) || fflush (stdout) || fclose (stdout))
     return FATAL_EXIT_CODE;
diff --git a/gcc/genmddeps.c b/gcc/genmddeps.c
index e3d229d..f97020f 100644
--- a/gcc/genmddeps.c
+++ b/gcc/genmddeps.c
@@ -19,6 +19,8 @@ 
 #include "system.h"
 #include "coretypes.h"
 #include "errors.h"
+#include "statistics.h"
+#include "vec.h"
 #include "read-md.h"
 
 
diff --git a/gcc/gensupport.c b/gcc/gensupport.c
index cb74aea..6ef6c11 100644
--- a/gcc/gensupport.c
+++ b/gcc/gensupport.c
@@ -2299,6 +2299,7 @@  gen_mnemonic_setattr (htab_t mnemonic_htab, rtx insn)
   rtx set_attr;
   char *attr_name;
   rtvec new_vec;
+  struct obstack *string_obstack = rtx_reader_ptr->get_string_obstack ();
 
   template_code = XTMPL (insn, 3);
 
@@ -2324,13 +2325,13 @@  gen_mnemonic_setattr (htab_t mnemonic_htab, rtx insn)
 	  sp = ep + 1;
 
       if (i > 0)
-	obstack_1grow (&string_obstack, ',');
+	obstack_1grow (string_obstack, ',');
 
       while (cp < sp && ((*cp >= '0' && *cp <= '9')
 			 || (*cp >= 'a' && *cp <= 'z')))
 
 	{
-	  obstack_1grow (&string_obstack, *cp);
+	  obstack_1grow (string_obstack, *cp);
 	  cp++;
 	  size++;
 	}
@@ -2341,7 +2342,7 @@  gen_mnemonic_setattr (htab_t mnemonic_htab, rtx insn)
 	    {
 	      /* Don't set a value if there are more than one
 		 instruction in the string.  */
-	      obstack_blank_fast (&string_obstack, -size);
+	      obstack_blank_fast (string_obstack, -size);
 	      size = 0;
 
 	      cp = sp;
@@ -2350,22 +2351,22 @@  gen_mnemonic_setattr (htab_t mnemonic_htab, rtx insn)
 	  cp++;
 	}
       if (size == 0)
-	obstack_1grow (&string_obstack, '*');
+	obstack_1grow (string_obstack, '*');
       else
 	add_mnemonic_string (mnemonic_htab,
-			     (char *) obstack_next_free (&string_obstack) - size,
+			     (char *) obstack_next_free (string_obstack) - size,
 			     size);
       i++;
     }
 
   /* An insn definition might emit an empty string.  */
-  if (obstack_object_size (&string_obstack) == 0)
+  if (obstack_object_size (string_obstack) == 0)
     return;
 
-  obstack_1grow (&string_obstack, '\0');
+  obstack_1grow (string_obstack, '\0');
 
   set_attr = rtx_alloc (SET_ATTR);
-  XSTR (set_attr, 1) = XOBFINISH (&string_obstack, char *);
+  XSTR (set_attr, 1) = XOBFINISH (string_obstack, char *);
   attr_name = XNEWVAR (char, strlen (MNEMONIC_ATTR_NAME) + 1);
   strcpy (attr_name, MNEMONIC_ATTR_NAME);
   XSTR (set_attr, 0) = attr_name;
@@ -2388,8 +2389,10 @@  gen_mnemonic_setattr (htab_t mnemonic_htab, rtx insn)
 static int
 mnemonic_htab_callback (void **slot, void *info ATTRIBUTE_UNUSED)
 {
-  obstack_grow (&string_obstack, (char*)*slot, strlen ((char*)*slot));
-  obstack_1grow (&string_obstack, ',');
+  struct obstack *string_obstack = rtx_reader_ptr->get_string_obstack ();
+
+  obstack_grow (string_obstack, (char*)*slot, strlen ((char*)*slot));
+  obstack_1grow (string_obstack, ',');
   return 1;
 }
 
@@ -2407,6 +2410,7 @@  gen_mnemonic_attr (void)
   htab_t mnemonic_htab;
   const char *str, *p;
   int i;
+  struct obstack *string_obstack = rtx_reader_ptr->get_string_obstack ();
 
   if (have_error)
     return;
@@ -2470,8 +2474,8 @@  gen_mnemonic_attr (void)
   htab_traverse (mnemonic_htab, mnemonic_htab_callback, NULL);
 
   /* Replace the last ',' with the zero end character.  */
-  *((char *)obstack_next_free (&string_obstack) - 1) = '\0';
-  XSTR (mnemonic_attr, 1) = XOBFINISH (&string_obstack, char *);
+  *((char *)obstack_next_free (string_obstack) - 1) = '\0';
+  XSTR (mnemonic_attr, 1) = XOBFINISH (string_obstack, char *);
 }
 
 /* Check if there are DEFINE_ATTRs with the same name.  */
diff --git a/gcc/read-md.c b/gcc/read-md.c
index e158be5..a4da3d3 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -21,6 +21,8 @@  along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "errors.h"
+#include "statistics.h"
+#include "vec.h"
 #include "read-md.h"
 
 /* Associates PTR (which can be a string, etc.) with the file location
@@ -31,25 +33,6 @@  struct ptr_loc {
   int lineno;
 };
 
-/* Obstack used for allocating MD strings.  */
-struct obstack string_obstack;
-
-/* A table of ptr_locs, hashed on the PTR field.  */
-static htab_t ptr_locs;
-
-/* An obstack for the above.  Plain xmalloc is a bit heavyweight for a
-   small structure like ptr_loc.  */
-static struct obstack ptr_loc_obstack;
-
-/* A hash table of triples (A, B, C), where each of A, B and C is a condition
-   and A is equivalent to "B && C".  This is used to keep track of the source
-   of conditions that are made up of separate MD strings (such as the split
-   condition of a define_insn_and_split).  */
-static htab_t joined_conditions;
-
-/* An obstack for allocating joined_conditions entries.  */
-static struct obstack joined_conditions_obstack;
-
 /* This callback will be invoked whenever an md include directive is
    processed.  To be used for creation of the dependency file.  */
 void (*include_callback) (const char *);
@@ -58,13 +41,6 @@  void (*include_callback) (const char *);
 
 rtx_reader *rtx_reader_ptr;
 
-/* A table of md_constant structures, hashed by name.  Null if no
-   constant expansion should occur.  */
-static htab_t md_constants;
-
-/* A table of enum_type structures, hashed by name.  */
-static htab_t enum_types;
-
 /* Given an object that starts with a char * name field, return a hash
    code for its name.  */
 
@@ -102,26 +78,26 @@  leading_ptr_eq_p (const void *def1, const void *def2)
 
 /* Associate PTR with the file position given by FILENAME and LINENO.  */
 
-static void
-set_md_ptr_loc (const void *ptr, const char *filename, int lineno)
+void
+rtx_reader::set_md_ptr_loc (const void *ptr, const char *filename, int lineno)
 {
   struct ptr_loc *loc;
 
-  loc = (struct ptr_loc *) obstack_alloc (&ptr_loc_obstack,
+  loc = (struct ptr_loc *) obstack_alloc (&m_ptr_loc_obstack,
 					  sizeof (struct ptr_loc));
   loc->ptr = ptr;
   loc->filename = filename;
   loc->lineno = lineno;
-  *htab_find_slot (ptr_locs, loc, INSERT) = loc;
+  *htab_find_slot (m_ptr_locs, loc, INSERT) = loc;
 }
 
 /* Return the position associated with pointer PTR.  Return null if no
    position was set.  */
 
-static const struct ptr_loc *
-get_md_ptr_loc (const void *ptr)
+const struct ptr_loc *
+rtx_reader::get_md_ptr_loc (const void *ptr)
 {
-  return (const struct ptr_loc *) htab_find (ptr_locs, &ptr);
+  return (const struct ptr_loc *) htab_find (m_ptr_locs, &ptr);
 }
 
 /* Associate NEW_PTR with the same file position as OLD_PTR.  */
@@ -129,9 +105,9 @@  get_md_ptr_loc (const void *ptr)
 void
 copy_md_ptr_loc (const void *new_ptr, const void *old_ptr)
 {
-  const struct ptr_loc *loc = get_md_ptr_loc (old_ptr);
+  const struct ptr_loc *loc = rtx_reader_ptr->get_md_ptr_loc (old_ptr);
   if (loc != 0)
-    set_md_ptr_loc (new_ptr, loc->filename, loc->lineno);
+    rtx_reader_ptr->set_md_ptr_loc (new_ptr, loc->filename, loc->lineno);
 }
 
 /* If PTR is associated with a known file position, print a #line
@@ -140,7 +116,7 @@  copy_md_ptr_loc (const void *new_ptr, const void *old_ptr)
 void
 fprint_md_ptr_loc (FILE *outf, const void *ptr)
 {
-  const struct ptr_loc *loc = get_md_ptr_loc (ptr);
+  const struct ptr_loc *loc = rtx_reader_ptr->get_md_ptr_loc (ptr);
   if (loc != 0)
     fprintf (outf, "#line %d \"%s\"\n", loc->lineno, loc->filename);
 }
@@ -156,7 +132,7 @@  print_md_ptr_loc (const void *ptr)
    may be null or empty.  */
 
 const char *
-join_c_conditions (const char *cond1, const char *cond2)
+rtx_reader::join_c_conditions (const char *cond1, const char *cond2)
 {
   char *result;
   const void **entry;
@@ -171,23 +147,32 @@  join_c_conditions (const char *cond1, const char *cond2)
     return cond1;
 
   result = concat ("(", cond1, ") && (", cond2, ")", NULL);
-  obstack_ptr_grow (&joined_conditions_obstack, result);
-  obstack_ptr_grow (&joined_conditions_obstack, cond1);
-  obstack_ptr_grow (&joined_conditions_obstack, cond2);
-  entry = XOBFINISH (&joined_conditions_obstack, const void **);
-  *htab_find_slot (joined_conditions, entry, INSERT) = entry;
+  obstack_ptr_grow (&m_joined_conditions_obstack, result);
+  obstack_ptr_grow (&m_joined_conditions_obstack, cond1);
+  obstack_ptr_grow (&m_joined_conditions_obstack, cond2);
+  entry = XOBFINISH (&m_joined_conditions_obstack, const void **);
+  *htab_find_slot (m_joined_conditions, entry, INSERT) = entry;
   return result;
 }
 
+/* As rtx_reader::join_c_conditions above, but call it on the singleton
+   rtx_reader instance.  */
+
+const char *
+join_c_conditions (const char *cond1, const char *cond2)
+{
+  return rtx_reader_ptr->join_c_conditions (cond1, cond2);
+}
+
 /* Print condition COND to OUTF, wrapped in brackets.  If COND was created
    by join_c_conditions, recursively invoke this function for the original
    conditions and join the result with "&&".  Otherwise print a #line
    directive for COND if its original file position is known.  */
 
 void
-fprint_c_condition (FILE *outf, const char *cond)
+rtx_reader::fprint_c_condition (FILE *outf, const char *cond)
 {
-  const char **halves = (const char **) htab_find (joined_conditions, &cond);
+  const char **halves = (const char **) htab_find (m_joined_conditions, &cond);
   if (halves != 0)
     {
       fprintf (outf, "(");
@@ -204,6 +189,15 @@  fprint_c_condition (FILE *outf, const char *cond)
     }
 }
 
+/* As rtx_reader::fprint_c_condition above, but call it on the singleton
+   rtx_reader instance.  */
+
+void
+fprint_c_condition (FILE *outf, const char *cond)
+{
+  rtx_reader_ptr->fprint_c_condition (outf, cond);
+}
+
 /* Special fprint_c_condition for writing to STDOUT.  */
 
 void
@@ -414,7 +408,7 @@  rtx_reader::unread_char (int ch)
    punctuation chars of rtx printed syntax.  */
 
 void
-read_name (struct md_name *name)
+rtx_reader::read_name (struct md_name *name)
 {
   int c;
   size_t i;
@@ -458,7 +452,7 @@  read_name (struct md_name *name)
   name->buffer[i] = 0;
   name->string = name->buffer;
 
-  if (md_constants)
+  if (m_md_constants)
     {
       /* Do constant expansion.  */
       struct md_constant *def;
@@ -468,7 +462,7 @@  read_name (struct md_name *name)
 	  struct md_constant tmp_def;
 
 	  tmp_def.name = name->string;
-	  def = (struct md_constant *) htab_find (md_constants, &tmp_def);
+	  def = (struct md_constant *) htab_find (m_md_constants, &tmp_def);
 	  if (def)
 	    name->string = def->value;
 	}
@@ -479,8 +473,8 @@  read_name (struct md_name *name)
 /* Subroutine of the string readers.  Handles backslash escapes.
    Caller has read the backslash, but not placed it into the obstack.  */
 
-static void
-read_escape (void)
+void
+rtx_reader::read_escape ()
 {
   int c = read_char ();
 
@@ -508,32 +502,32 @@  read_escape (void)
     case 'a': case 'b': case 'f': case 'n': case 'r': case 't': case 'v':
     case '0': case '1': case '2': case '3': case '4': case '5': case '6':
     case '7': case 'x':
-      obstack_1grow (&string_obstack, '\\');
+      obstack_1grow (&m_string_obstack, '\\');
       break;
 
       /* \; makes stuff for a C string constant containing
 	 newline and tab.  */
     case ';':
-      obstack_grow (&string_obstack, "\\n\\t", 4);
+      obstack_grow (&m_string_obstack, "\\n\\t", 4);
       return;
 
       /* pass anything else through, but issue a warning.  */
     default:
       fprintf (stderr, "%s:%d: warning: unrecognized escape \\%c\n",
-	       rtx_reader_ptr->get_filename (), rtx_reader_ptr->get_lineno (),
+	       get_filename (), get_lineno (),
 	       c);
-      obstack_1grow (&string_obstack, '\\');
+      obstack_1grow (&m_string_obstack, '\\');
       break;
     }
 
-  obstack_1grow (&string_obstack, c);
+  obstack_1grow (&m_string_obstack, c);
 }
 
 /* Read a double-quoted string onto the obstack.  Caller has scanned
    the leading quote.  */
 
 char *
-read_quoted_string (void)
+rtx_reader::read_quoted_string ()
 {
   int c;
 
@@ -548,25 +542,25 @@  read_quoted_string (void)
       else if (c == '"' || c == EOF)
 	break;
 
-      obstack_1grow (&string_obstack, c);
+      obstack_1grow (&m_string_obstack, c);
     }
 
-  obstack_1grow (&string_obstack, 0);
-  return XOBFINISH (&string_obstack, char *);
+  obstack_1grow (&m_string_obstack, 0);
+  return XOBFINISH (&m_string_obstack, char *);
 }
 
 /* Read a braced string (a la Tcl) onto the string obstack.  Caller
    has scanned the leading brace.  Note that unlike quoted strings,
    the outermost braces _are_ included in the string constant.  */
 
-static char *
-read_braced_string (void)
+char *
+rtx_reader::read_braced_string ()
 {
   int c;
   int brace_depth = 1;  /* caller-processed */
-  unsigned long starting_read_md_lineno = rtx_reader_ptr->get_lineno ();
+  unsigned long starting_read_md_lineno = get_lineno ();
 
-  obstack_1grow (&string_obstack, '{');
+  obstack_1grow (&m_string_obstack, '{');
   while (brace_depth)
     {
       c = read_char (); /* Read the string  */
@@ -585,11 +579,11 @@  read_braced_string (void)
 	  ("missing closing } for opening brace on line %lu",
 	   starting_read_md_lineno);
 
-      obstack_1grow (&string_obstack, c);
+      obstack_1grow (&m_string_obstack, c);
     }
 
-  obstack_1grow (&string_obstack, 0);
-  return XOBFINISH (&string_obstack, char *);
+  obstack_1grow (&m_string_obstack, 0);
+  return XOBFINISH (&m_string_obstack, char *);
 }
 
 /* Read some kind of string constant.  This is the high-level routine
@@ -597,7 +591,7 @@  read_braced_string (void)
    and dispatch to the appropriate string constant reader.  */
 
 char *
-read_string (int star_if_braced)
+rtx_reader::read_string (int star_if_braced)
 {
   char *stringbuf;
   int saw_paren = 0;
@@ -610,13 +604,13 @@  read_string (int star_if_braced)
       c = read_skip_spaces ();
     }
 
-  old_lineno = rtx_reader_ptr->get_lineno ();
+  old_lineno = get_lineno ();
   if (c == '"')
     stringbuf = read_quoted_string ();
   else if (c == '{')
     {
       if (star_if_braced)
-	obstack_1grow (&string_obstack, '*');
+	obstack_1grow (&m_string_obstack, '*');
       stringbuf = read_braced_string ();
     }
   else
@@ -625,15 +619,15 @@  read_string (int star_if_braced)
   if (saw_paren)
     require_char_ws (')');
 
-  set_md_ptr_loc (stringbuf, rtx_reader_ptr->get_filename (), old_lineno);
+  set_md_ptr_loc (stringbuf, get_filename (), old_lineno);
   return stringbuf;
 }
 
 /* Skip the rest of a construct that started at line LINENO and that
    is currently nested by DEPTH levels of parentheses.  */
 
-static void
-read_skip_construct (int depth, file_location loc)
+void
+rtx_reader::read_skip_construct (int depth, file_location loc)
 {
   struct md_name name;
   int c;
@@ -774,8 +768,8 @@  add_constant (htab_t defs, char *name, char *value,
 /* Process a define_constants directive, starting with the optional space
    after the "define_constants".  */
 
-static void
-handle_constants (void)
+void
+rtx_reader::handle_constants ()
 {
   int c;
   htab_t defs;
@@ -783,8 +777,8 @@  handle_constants (void)
   require_char_ws ('[');
 
   /* Disable constant expansion during definition processing.  */
-  defs = md_constants;
-  md_constants = 0;
+  defs = m_md_constants;
+  m_md_constants = 0;
   while ( (c = read_skip_spaces ()) != ']')
     {
       struct md_name name, value;
@@ -798,7 +792,7 @@  handle_constants (void)
 
       require_char_ws (')');
     }
-  md_constants = defs;
+  m_md_constants = defs;
 }
 
 /* For every constant definition, call CALLBACK with two arguments:
@@ -808,7 +802,7 @@  handle_constants (void)
 void
 traverse_md_constants (htab_trav callback, void *info)
 {
-  htab_traverse (md_constants, callback, info);
+  htab_traverse (rtx_reader_ptr->get_md_constants (), callback, info);
 }
 
 /* Return a malloc()ed decimal string that represents number NUMBER.  */
@@ -828,8 +822,8 @@  md_decimal_string (int number)
    number on which the directive started and MD_P is true if the
    directive is a define_enum rather than a define_c_enum.  */
 
-static void
-handle_enum (file_location loc, bool md_p)
+void
+rtx_reader::handle_enum (file_location loc, bool md_p)
 {
   char *enum_name, *value_name;
   struct md_name name;
@@ -839,7 +833,7 @@  handle_enum (file_location loc, bool md_p)
   int c;
 
   enum_name = read_string (false);
-  slot = htab_find_slot (enum_types, &enum_name, INSERT);
+  slot = htab_find_slot (m_enum_types, &enum_name, INSERT);
   if (*slot)
     {
       def = (struct enum_type *) *slot;
@@ -883,7 +877,7 @@  handle_enum (file_location loc, bool md_p)
 	  value_name = xstrdup (name.string);
 	  ev->name = value_name;
 	}
-      ev->def = add_constant (md_constants, value_name,
+      ev->def = add_constant (get_md_constants (), value_name,
 			      md_decimal_string (def->num_values), def);
 
       *def->tail_ptr = ev;
@@ -895,9 +889,9 @@  handle_enum (file_location loc, bool md_p)
 /* Try to find the definition of the given enum.  Return null on failure.  */
 
 struct enum_type *
-lookup_enum_type (const char *name)
+rtx_reader::lookup_enum_type (const char *name)
 {
-  return (struct enum_type *) htab_find (enum_types, &name);
+  return (struct enum_type *) htab_find (m_enum_types, &name);
 }
 
 /* For every enum definition, call CALLBACK with two arguments:
@@ -905,9 +899,9 @@  lookup_enum_type (const char *name)
    returns zero.  */
 
 void
-traverse_enum_types (htab_trav callback, void *info)
+rtx_reader::traverse_enum_types (htab_trav callback, void *info)
 {
-  htab_traverse (enum_types, callback, info);
+  htab_traverse (m_enum_types, callback, info);
 }
 
 
@@ -925,12 +919,43 @@  rtx_reader::rtx_reader ()
 {
   /* Set the global singleton pointer.  */
   rtx_reader_ptr = this;
+
+  obstack_init (&m_string_obstack);
+
+  m_ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
+  obstack_init (&m_ptr_loc_obstack);
+
+  m_joined_conditions = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
+  obstack_init (&m_joined_conditions_obstack);
+
+  m_md_constants = htab_create (31, leading_string_hash,
+				leading_string_eq_p, (htab_del) 0);
+
+  m_enum_types = htab_create (31, leading_string_hash,
+			      leading_string_eq_p, (htab_del) 0);
+
+  /* Unlock the stdio streams.  */
+  unlock_std_streams ();
 }
 
 /* rtx_reader's destructor.  */
 
 rtx_reader::~rtx_reader ()
 {
+  free (m_base_dir);
+
+  htab_delete (m_enum_types);
+
+  htab_delete (m_md_constants);
+
+  obstack_free (&m_joined_conditions_obstack, NULL);
+  htab_delete (m_joined_conditions);
+
+  obstack_free (&m_ptr_loc_obstack, NULL);
+  htab_delete (m_ptr_locs);
+
+  obstack_free (&m_string_obstack, NULL);
+
   /* Clear the global singleton pointer.  */
   rtx_reader_ptr = NULL;
 }
@@ -1105,20 +1130,6 @@  rtx_reader::read_md_files (int argc, const char **argv,
   bool already_read_stdin;
   int num_files;
 
-  /* Initialize global data.  */
-  obstack_init (&string_obstack);
-  ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
-  obstack_init (&ptr_loc_obstack);
-  joined_conditions = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
-  obstack_init (&joined_conditions_obstack);
-  md_constants = htab_create (31, leading_string_hash,
-			      leading_string_eq_p, (htab_del) 0);
-  enum_types = htab_create (31, leading_string_hash,
-			    leading_string_eq_p, (htab_del) 0);
-
-  /* Unlock the stdio streams.  */
-  unlock_std_streams ();
-
   /* First we loop over all the options.  */
   for (i = 1; i < argc; i++)
     if (argv[i][0] == '-')
diff --git a/gcc/read-md.h b/gcc/read-md.h
index a74cc72..a089595 100644
--- a/gcc/read-md.h
+++ b/gcc/read-md.h
@@ -107,14 +107,49 @@  class rtx_reader
 
   file_location get_current_location () const;
 
+  /* Defined in read-md.c.  */
   int read_char (void);
   void unread_char (int ch);
+  void read_name (struct md_name *name);
+  void read_escape ();
+  char *read_quoted_string ();
+  char *read_braced_string ();
+  char *read_string (int star_if_braced);
+  void read_skip_construct (int depth, file_location loc);
+
+  void set_md_ptr_loc (const void *ptr, const char *filename, int lineno);
+  const struct ptr_loc *get_md_ptr_loc (const void *ptr);
+
+  struct enum_type *lookup_enum_type (const char *name);
+  void traverse_enum_types (htab_trav callback, void *info);
+
+  void handle_constants ();
+  void handle_enum (file_location loc, bool md_p);
+
+  const char *join_c_conditions (const char *cond1, const char *cond2);
+  void fprint_c_condition (FILE *outf, const char *cond);
+
+  /* Defined in read-rtl.c.  */
+  const char *apply_iterator_to_string (const char *string);
+  rtx copy_rtx_for_iterators (rtx original);
+  void read_conditions ();
+  void record_potential_iterator_use (struct iterator_group *group,
+				      void *ptr, const char *name);
+  struct mapping *read_mapping (struct iterator_group *group, htab_t table);
+  bool read_rtx (const char *rtx_name, vec<rtx> *rtxen);
+  rtx read_rtx_code (const char *code_name);
+  void read_rtx_operand (rtx return_rtx, int idx);
+  rtx read_nested_rtx ();
+  rtx read_rtx_variadic (rtx form);
 
   const char *get_top_level_filename () const { return m_toplevel_fname; }
   const char *get_filename () const { return m_read_md_filename; }
   int get_lineno () const { return m_read_md_lineno; }
   int get_colno () const { return m_read_md_colno; }
 
+  struct obstack *get_string_obstack () { return &m_string_obstack; }
+  htab_t get_md_constants () { return m_md_constants; }
+
  private:
   /* A singly-linked list of filenames.  */
   struct file_name_list {
@@ -159,6 +194,32 @@  class rtx_reader
 
   /* A pointer to the null terminator of the md include chain.  */
   file_name_list **m_last_dir_md_include_ptr;
+
+  /* Obstack used for allocating MD strings.  */
+  struct obstack m_string_obstack;
+
+  /* A table of ptr_locs, hashed on the PTR field.  */
+  htab_t m_ptr_locs;
+
+  /* An obstack for the above.  Plain xmalloc is a bit heavyweight for a
+     small structure like ptr_loc.  */
+  struct obstack m_ptr_loc_obstack;
+
+  /* A hash table of triples (A, B, C), where each of A, B and C is a condition
+     and A is equivalent to "B && C".  This is used to keep track of the source
+     of conditions that are made up of separate MD strings (such as the split
+     condition of a define_insn_and_split).  */
+  htab_t m_joined_conditions;
+
+  /* An obstack for allocating joined_conditions entries.  */
+  struct obstack m_joined_conditions_obstack;
+
+  /* A table of md_constant structures, hashed by name.  Null if no
+     constant expansion should occur.  */
+  htab_t m_md_constants;
+
+  /* A table of enum_type structures, hashed by name.  */
+  htab_t m_enum_types;
 };
 
 /* Global singleton.  */
@@ -175,7 +236,6 @@  class noop_reader : public rtx_reader
   void handle_unknown_directive (file_location, const char *);
 };
 
-extern struct obstack string_obstack;
 extern void (*include_callback) (const char *);
 
 /* Read the next character from the MD file.  */
@@ -198,7 +258,6 @@  extern hashval_t leading_string_hash (const void *);
 extern int leading_string_eq_p (const void *, const void *);
 extern void copy_md_ptr_loc (const void *, const void *);
 extern void print_md_ptr_loc (const void *);
-extern void fprint_md_ptr_loc (FILE *, const void *);
 extern const char *join_c_conditions (const char *, const char *);
 extern void print_c_condition (const char *);
 extern void fprint_c_condition (FILE *, const char *);
@@ -210,9 +269,6 @@  extern void fatal_with_file_and_line (const char *, ...)
 extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN;
 extern int read_skip_spaces (void);
 extern void require_char_ws (char expected);
-extern void read_name (struct md_name *);
-extern char *read_quoted_string (void);
-extern char *read_string (int);
 extern int n_comma_elts (const char *);
 extern const char *scan_comma_elt (const char **);
 extern void upcase_string (char *);
diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c
index 925ea45..c3c0b93 100644
--- a/gcc/read-rtl.c
+++ b/gcc/read-rtl.c
@@ -106,10 +106,6 @@  htab_t subst_attr_to_iter_map = NULL;
 const char *current_iterator_name;
 
 static void validate_const_int (const char *);
-static rtx read_rtx_code (const char *);
-static void read_rtx_operand (rtx, int);
-static rtx read_nested_rtx (void);
-static rtx read_rtx_variadic (rtx);
 
 /* The mode and code iterator structures.  */
 static struct iterator_group modes, codes, ints, substs;
@@ -329,8 +325,8 @@  map_attr_string (const char *p)
 /* Apply the current iterator values to STRING.  Return the new string
    if any changes were needed, otherwise return STRING itself.  */
 
-static const char *
-apply_iterator_to_string (const char *string)
+const char *
+rtx_reader::apply_iterator_to_string (const char *string)
 {
   char *base, *copy, *p, *start, *end;
   struct map_value *v;
@@ -351,14 +347,14 @@  apply_iterator_to_string (const char *string)
 
       /* Add everything between the last copied byte and the '<',
 	 then add in the attribute value.  */
-      obstack_grow (&string_obstack, base, start - base);
-      obstack_grow (&string_obstack, v->string, strlen (v->string));
+      obstack_grow (&m_string_obstack, base, start - base);
+      obstack_grow (&m_string_obstack, v->string, strlen (v->string));
       base = end + 1;
     }
   if (base != copy)
     {
-      obstack_grow (&string_obstack, base, strlen (base) + 1);
-      copy = XOBFINISH (&string_obstack, char *);
+      obstack_grow (&m_string_obstack, base, strlen (base) + 1);
+      copy = XOBFINISH (&m_string_obstack, char *);
       copy_md_ptr_loc (copy, string);
       return copy;
     }
@@ -368,8 +364,8 @@  apply_iterator_to_string (const char *string)
 /* Return a deep copy of X, substituting the current iterator
    values into any strings.  */
 
-static rtx
-copy_rtx_for_iterators (rtx original)
+rtx
+rtx_reader::copy_rtx_for_iterators (rtx original)
 {
   const char *format_ptr, *p;
   int i, j;
@@ -546,7 +542,7 @@  apply_iterators (rtx original, vec<rtx> *queue)
 	  condition = join_c_conditions (condition, v->string);
 	}
       apply_attribute_uses ();
-      x = copy_rtx_for_iterators (original);
+      x = rtx_reader_ptr->copy_rtx_for_iterators (original);
       add_condition_to_rtx (x, condition);
 
       /* We apply subst iterator after RTL-template is copied, as during
@@ -738,8 +734,8 @@  atoll (const char *p)
    generated by (the program generated by) genconditions.c, and
    slipped in at the beginning of the sequence of MD files read by
    most of the other generators.  */
-static void
-read_conditions (void)
+void
+rtx_reader::read_conditions ()
 {
   int c;
 
@@ -837,9 +833,9 @@  record_attribute_use (struct iterator_group *group, void *ptr,
    for group GROUP.  PTR is the value to pass to GROUP's apply_iterator
    callback.  */
 
-static void
-record_potential_iterator_use (struct iterator_group *group, void *ptr,
-			       const char *name)
+void
+rtx_reader::record_potential_iterator_use (struct iterator_group *group,
+					   void *ptr, const char *name)
 {
   struct mapping *m;
   size_t len;
@@ -849,8 +845,8 @@  record_potential_iterator_use (struct iterator_group *group, void *ptr,
     {
       /* Copy the attribute string into permanent storage, without the
 	 angle brackets around it.  */
-      obstack_grow0 (&string_obstack, name + 1, len - 2);
-      record_attribute_use (group, ptr, XOBFINISH (&string_obstack, char *));
+      obstack_grow0 (&m_string_obstack, name + 1, len - 2);
+      record_attribute_use (group, ptr, XOBFINISH (&m_string_obstack, char *));
     }
   else
     {
@@ -872,8 +868,8 @@  record_potential_iterator_use (struct iterator_group *group, void *ptr,
    Represent the declaration as a "mapping" structure; add it to TABLE
    (which belongs to GROUP) and return it.  */
 
-static struct mapping *
-read_mapping (struct iterator_group *group, htab_t table)
+struct mapping *
+rtx_reader::read_mapping (struct iterator_group *group, htab_t table)
 {
   struct md_name name;
   struct mapping *m;
@@ -974,7 +970,7 @@  read_subst_mapping (htab_t subst_iters_table, htab_t subst_attrs_table,
   int i;
 
   for (i = 0; i < 4; i++)
-    attr_operands[i] = read_string (false);
+    attr_operands[i] = rtx_reader_ptr->read_string (false);
 
   add_define_subst_attr (attr_operands, queue);
 
@@ -1019,7 +1015,7 @@  check_code_iterator (struct mapping *iterator)
    store the list of rtxes as an EXPR_LIST in *X.  */
 
 bool
-read_rtx (const char *rtx_name, vec<rtx> *rtxen)
+rtx_reader::read_rtx (const char *rtx_name, vec<rtx> *rtxen)
 {
   static bool initialized = false;
 
@@ -1087,8 +1083,8 @@  read_rtx (const char *rtx_name, vec<rtx> *rtxen)
    either an rtx code or a code iterator.  Parse the rest of the rtx and
    return it.  */
 
-static rtx
-read_rtx_code (const char *code_name)
+rtx
+rtx_reader::read_rtx_code (const char *code_name)
 {
   RTX_CODE code;
   struct mapping *iterator;
@@ -1200,8 +1196,8 @@  read_rtx_code (const char *code_name)
    based on the corresponding format character within GET_RTX_FORMAT
    for the GET_CODE (RETURN_RTX).  */
 
-static void
-read_rtx_operand (rtx return_rtx, int idx)
+void
+rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
 {
   RTX_CODE code = GET_CODE (return_rtx);
   const char *format_ptr = GET_RTX_FORMAT (code);
@@ -1304,17 +1300,17 @@  read_rtx_operand (rtx return_rtx, int idx)
 		|| GET_CODE (return_rtx) == DEFINE_INSN_AND_SPLIT))
 	  {
 	    char line_name[20];
-	    const char *read_md_filename = rtx_reader_ptr->get_filename ();
+	    const char *read_md_filename = get_filename ();
 	    const char *fn = (read_md_filename ? read_md_filename : "rtx");
 	    const char *slash;
 	    for (slash = fn; *slash; slash ++)
 	      if (*slash == '/' || *slash == '\\' || *slash == ':')
 		fn = slash + 1;
-	    obstack_1grow (&string_obstack, '*');
-	    obstack_grow (&string_obstack, fn, strlen (fn));
-	    sprintf (line_name, ":%d", rtx_reader_ptr->get_lineno ());
-	    obstack_grow (&string_obstack, line_name, strlen (line_name)+1);
-	    stringbuf = XOBFINISH (&string_obstack, char *);
+	    obstack_1grow (&m_string_obstack, '*');
+	    obstack_grow (&m_string_obstack, fn, strlen (fn));
+	    sprintf (line_name, ":%d", get_lineno ());
+	    obstack_grow (&m_string_obstack, line_name, strlen (line_name)+1);
+	    stringbuf = XOBFINISH (&m_string_obstack, char *);
 	  }
 
 	/* Find attr-names in the string.  */
@@ -1402,8 +1398,8 @@  read_rtx_operand (rtx return_rtx, int idx)
 
 /* Read a nested rtx construct from the MD file and return it.  */
 
-static rtx
-read_nested_rtx (void)
+rtx
+rtx_reader::read_nested_rtx ()
 {
   struct md_name name;
   rtx return_rtx;
@@ -1427,8 +1423,8 @@  read_nested_rtx (void)
    When called, FORM is (thing x1 x2), and the file position
    is just past the leading parenthesis of x3.  Only works
    for THINGs which are dyadic expressions, e.g. AND, IOR.  */
-static rtx
-read_rtx_variadic (rtx form)
+rtx
+rtx_reader::read_rtx_variadic (rtx form)
 {
   char c = '(';
   rtx p = form, q;