	* gensupport (init_rtx_reader_args_cb): Start counting code-generating
	patterns from 1 to free up 0 for CODE_FOR_nothing.
	* gencodes.c (main): Give CODE_FOR_nothing the value 0.  Add
	the LAST_INSN_CODE marker at the end.
	* genoutput.c (nothing): New static struct data.
	(idata): Initialize to &nothing.
	(idata_end): Initialize to &nothing.next.
	(init_insn_for_nothing): New function to create dummy 'nothing' insn.
	(main): Use it.
	* genpeep.c (insn_code_number): Remove global variable.
	(gen_peephole): Take it as an argument instead.
	(main): Take insn_code_number from read_md_rtx.
	* optabs.h: Revert r161809:
	(optab_handlers): Change type of insn_code back to insn_code.
	(optab_handler, widening_optab_handler, set_optab_handler,
	set_widening_optab_handler, convert_optab_handler,
	set_convert_optab_handler, direct_optab_handler,
	set_direct_optab_handler): Remove int casts.
	Revert to treating the insn_code field as "insn_code".

Index: gensupport.c
===================================================================
--- gensupport.c	(revision 189358)
+++ gensupport.c	(working copy)
@@ -38,6 +38,10 @@ int insn_elision = 1;
 static struct obstack obstack;
 struct obstack *rtl_obstack = &obstack;
 
+/* Counter for patterns that generate code: define_insn, define_expand,
+   define_split, define_peephole, and define_peephole2.  See read_md_rtx().
+   Any define_insn_and_splits are already in separate queues so that the
+   insn and the splitter get a unique number also.  */
 static int sequence_num;
 
 static int predicable_default;
@@ -1397,8 +1401,10 @@ init_rtx_reader_args_cb (int argc, char **argv,
   condition_table = htab_create (500, hash_c_test, cmp_c_test, NULL);
   init_predicate_table ();
   obstack_init (rtl_obstack);
-  sequence_num = 0;
 
+  /* Start at 1, to make 0 available for CODE_FOR_nothing.  */
+  sequence_num = 1;
+
   read_md_files (argc, argv, parse_opt, rtx_handle_directive);
 
   /* Process define_cond_exec patterns.  */
@@ -1419,7 +1425,11 @@ init_rtx_reader_args (int argc, char **argv)
   return init_rtx_reader_args_cb (argc, argv, 0);
 }
 
-/* The entry point for reading a single rtx from an md file.  */
+/* The entry point for reading a single rtx from an md file.  Return
+   the rtx, or NULL if the md file has been fully processed.
+   Return the line where the rtx was found in LINENO.
+   Return the number of code generating rtx'en read since the start
+   of the md file in SEQNR.  */
 
 rtx
 read_md_rtx (int *lineno, int *seqnr)
Index: gencodes.c
===================================================================
--- gencodes.c	(revision 189358)
+++ gencodes.c	(working copy)
@@ -68,7 +68,8 @@ main (int argc, char **argv)
 #ifndef GCC_INSN_CODES_H\n\
 #define GCC_INSN_CODES_H\n\
 \n\
-enum insn_code {");
+enum insn_code {\n\
+  CODE_FOR_nothing = 0,\n");
 
   /* Read the machine description.  */
 
@@ -85,7 +86,7 @@ main (int argc, char **argv)
 	gen_insn (desc, insn_code_number);
     }
 
-  puts ("  CODE_FOR_nothing\n\
+  puts ("  LAST_INSN_CODE\n\
 };\n\
 \n\
 #endif /* GCC_INSN_CODES_H */");
Index: genoutput.c
===================================================================
--- genoutput.c	(revision 189358)
+++ genoutput.c	(working copy)
@@ -171,9 +171,16 @@ struct data
   struct operand_data operand[MAX_MAX_OPERANDS];
 };
 
+/* A dummy insn, for CODE_FOR_nothing.  */
+static struct data nothing;
+
 /* This variable points to the first link in the insn chain.  */
+static struct data *idata = &nothing;
 
-static struct data *idata, **idata_end = &idata;
+/* This variable points to the end of the insn chain.  This is where
+   everything relevant from the machien description is appended to.  */
+static struct data **idata_end = &nothing.next;
+
 
 static void output_prologue (void);
 static void output_operand_data (void);
@@ -987,6 +994,14 @@ gen_split (rtx split, int lineno)
   place_operands (d);
 }
 
+static void
+init_insn_for_nothing (void)
+{
+  memset (&nothing, 0, sizeof (nothing));
+  nothing.name = "*placeholder_for_nothing";
+  nothing.filename = "<internal>";
+}
+
 extern int main (int, char **);
 
 int
@@ -996,11 +1011,12 @@ main (int argc, char **argv)
 
   progname = "genoutput";
 
+  init_insn_for_nothing ();
+
   if (!init_rtx_reader_args (argc, argv))
     return (FATAL_EXIT_CODE);
 
   output_prologue ();
-  next_code_number = 0;
   next_index_number = 0;
 
   /* Read the machine description.  */
Index: genpeep.c
===================================================================
--- genpeep.c	(revision 189358)
+++ genpeep.c	(working copy)
@@ -47,18 +47,13 @@ static int max_opno;
 
 static int n_operands;
 
-/* Peephole optimizations get insn codes just like insn patterns.
-   Count them so we know the code of the define_peephole we are handling.  */
-
-static int insn_code_number = 0;
-
-static void gen_peephole (rtx);
+static void gen_peephole (rtx, int);
 static void match_rtx (rtx, struct link *, int);
 static void print_path (struct link *);
 static void print_code (RTX_CODE);
 
 static void
-gen_peephole (rtx peep)
+gen_peephole (rtx peep, int insn_code_number)
 {
   int ninsns = XVECLEN (peep, 0);
   int i;
@@ -392,24 +387,15 @@ from the machine description file `md'.  */\n\n");
 
   while (1)
     {
-      int line_no, rtx_number = 0;
+      int line_no;
+      int insn_code_number;
 
-      desc = read_md_rtx (&line_no, &rtx_number);
+      desc = read_md_rtx (&line_no, &insn_code_number);
       if (desc == NULL)
 	break;
 
-       if (GET_CODE (desc) == DEFINE_PEEPHOLE)
-	{
-	  gen_peephole (desc);
-	  insn_code_number++;
-	}
-      if (GET_CODE (desc) == DEFINE_INSN
-	  || GET_CODE (desc) == DEFINE_EXPAND
-	  || GET_CODE (desc) == DEFINE_SPLIT
-	  || GET_CODE (desc) == DEFINE_PEEPHOLE2)
-	{
-	  insn_code_number++;
-	}
+      if (GET_CODE (desc) == DEFINE_PEEPHOLE)
+	gen_peephole (desc, insn_code_number);
     }
 
   printf ("  return 0;\n}\n\n");
Index: optabs.h
===================================================================
--- optabs.h	(revision 189358)
+++ optabs.h	(working copy)
@@ -29,6 +29,10 @@ along with GCC; see the file COPYING3.  If not see
 
    For example, add_optab applies to addition.
 
+   The insn_code slot is the enum insn_code that says how to
+   generate an insn for this operation on a particular machine mode.
+   It is CODE_FOR_nothing if there is no such insn on the target machine.
+
    The `lib_call' slot is the name of the library function that
    can be used to perform the operation.
 
@@ -36,10 +40,7 @@ along with GCC; see the file COPYING3.  If not see
 
 struct optab_handlers
 {
-  /* I - CODE_FOR_nothing, where I is either the insn code of the
-     associated insn generator or CODE_FOR_nothing if there is no such
-     insn on the target machine.  */
-  int insn_code;
+  enum insn_code insn_code;
 };
 
 struct widening_optab_handlers
@@ -1011,8 +1012,7 @@ extern rtx expand_vec_perm (enum machine_mode, rtx
 static inline enum insn_code
 optab_handler (optab op, enum machine_mode mode)
 {
-  return (enum insn_code) (op->handlers[(int) mode].insn_code
-			   + (int) CODE_FOR_nothing);
+  return op->handlers[(int) mode].insn_code;
 }
 
 /* Like optab_handler, but for widening_operations that have a TO_MODE and
@@ -1026,8 +1026,7 @@ widening_optab_handler (optab op, enum machine_mod
     return optab_handler (op, to_mode);
 
   if (op->widening)
-    return (enum insn_code) (op->widening->handlers[(int) to_mode][(int) from_mode].insn_code
-			     + (int) CODE_FOR_nothing);
+    return op->widening->handlers[(int) to_mode][(int) from_mode].insn_code;
 
   return CODE_FOR_nothing;
 }
@@ -1037,7 +1036,7 @@ widening_optab_handler (optab op, enum machine_mod
 static inline void
 set_optab_handler (optab op, enum machine_mode mode, enum insn_code code)
 {
-  op->handlers[(int) mode].insn_code = (int) code - (int) CODE_FOR_nothing;
+  op->handlers[(int) mode].insn_code = code;
 }
 
 /* Like set_optab_handler, but for widening operations that have a TO_MODE
@@ -1055,8 +1054,7 @@ set_widening_optab_handler (optab op, enum machine
 	op->widening = (struct widening_optab_handlers *)
 	      xcalloc (1, sizeof (struct widening_optab_handlers));
 
-      op->widening->handlers[(int) to_mode][(int) from_mode].insn_code
-	  = (int) code - (int) CODE_FOR_nothing;
+      op->widening->handlers[(int) to_mode][(int) from_mode].insn_code = code;
     }
 }
 
@@ -1068,9 +1066,7 @@ static inline enum insn_code
 convert_optab_handler (convert_optab op, enum machine_mode to_mode,
 		       enum machine_mode from_mode)
 {
-  return ((enum insn_code)
-	  (op->handlers[(int) to_mode][(int) from_mode].insn_code
-	   + (int) CODE_FOR_nothing));
+  return op->handlers[(int) to_mode][(int) from_mode].insn_code;
 }
 
 /* Record that insn CODE should be used to perform conversion OP
@@ -1080,8 +1076,7 @@ static inline void
 set_convert_optab_handler (convert_optab op, enum machine_mode to_mode,
 			   enum machine_mode from_mode, enum insn_code code)
 {
-  op->handlers[(int) to_mode][(int) from_mode].insn_code
-    = (int) code - (int) CODE_FOR_nothing;
+  op->handlers[(int) to_mode][(int) from_mode].insn_code = code;
 }
 
 /* Return the insn used to implement mode MODE of OP, or CODE_FOR_nothing
@@ -1090,8 +1085,7 @@ set_convert_optab_handler (convert_optab op, enum
 static inline enum insn_code
 direct_optab_handler (direct_optab op, enum machine_mode mode)
 {
-  return (enum insn_code) (op->handlers[(int) mode].insn_code
-			   + (int) CODE_FOR_nothing);
+  return op->handlers[(int) mode].insn_code;
 }
 
 /* Record that insn CODE should be used to implement mode MODE of OP.  */
@@ -1100,7 +1094,7 @@ static inline void
 set_direct_optab_handler (direct_optab op, enum machine_mode mode,
 			  enum insn_code code)
 {
-  op->handlers[(int) mode].insn_code = (int) code - (int) CODE_FOR_nothing;
+  op->handlers[(int) mode].insn_code = code;
 }
 
 /* Return true if UNOPTAB is for a trapping-on-overflow operation.  */
