OSDN Git Service

* java/io/DataInput.java: Merge with Classpath.
[pf3gnuchains/gcc-fork.git] / gcc / gensupport.c
1 /* Support routines for the various generation passes.
2    Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3
4    This file is part of GCC.
5
6    GCC is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GCC is distributed in the hope that it will be useful, but WITHOUT
12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
14    License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GCC; see the file COPYING.  If not, write to the Free
18    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19    02111-1307, USA.  */
20
21 #include "hconfig.h"
22 #include "system.h"
23 #include "rtl.h"
24 #include "obstack.h"
25 #include "errors.h"
26 #include "gensupport.h"
27
28
29 static struct obstack obstack;
30 struct obstack *rtl_obstack = &obstack;
31
32 #define obstack_chunk_alloc xmalloc
33 #define obstack_chunk_free free
34
35 static int sequence_num;
36 static int errors;
37
38 static int predicable_default;
39 static const char *predicable_true;
40 static const char *predicable_false;
41
42 /* We initially queue all patterns, process the define_insn and
43    define_cond_exec patterns, then return them one at a time.  */
44
45 struct queue_elem
46 {
47   rtx data;
48   int lineno;
49   struct queue_elem *next;
50 };
51
52 static struct queue_elem *define_attr_queue;
53 static struct queue_elem **define_attr_tail = &define_attr_queue;
54 static struct queue_elem *define_insn_queue;
55 static struct queue_elem **define_insn_tail = &define_insn_queue;
56 static struct queue_elem *define_cond_exec_queue;
57 static struct queue_elem **define_cond_exec_tail = &define_cond_exec_queue;
58 static struct queue_elem *other_queue;
59 static struct queue_elem **other_tail = &other_queue;
60
61 static void queue_pattern PARAMS ((rtx, struct queue_elem ***, int));
62 static void remove_constraints PARAMS ((rtx));
63 static void process_rtx PARAMS ((rtx, int));
64
65 static int is_predicable PARAMS ((struct queue_elem *));
66 static void identify_predicable_attribute PARAMS ((void));
67 static int n_alternatives PARAMS ((const char *));
68 static void collect_insn_data PARAMS ((rtx, int *, int *));
69 static rtx alter_predicate_for_insn PARAMS ((rtx, int, int, int));
70 static const char *alter_test_for_insn PARAMS ((struct queue_elem *,
71                                                 struct queue_elem *));
72 static char *shift_output_template PARAMS ((char *, const char *, int));
73 static const char *alter_output_for_insn PARAMS ((struct queue_elem *,
74                                                   struct queue_elem *,
75                                                   int, int));
76 static void process_one_cond_exec PARAMS ((struct queue_elem *));
77 static void process_define_cond_exec PARAMS ((void));
78 \f
79 void
80 message_with_line VPARAMS ((int lineno, const char *msg, ...))
81 {
82   VA_OPEN (ap, msg);
83   VA_FIXEDARG (ap, int, lineno);
84   VA_FIXEDARG (ap, const char *, msg);
85
86   fprintf (stderr, "%s:%d: ", read_rtx_filename, lineno);
87   vfprintf (stderr, msg, ap);
88   fputc ('\n', stderr);
89
90   VA_CLOSE (ap);
91 }
92 \f
93 /* Queue PATTERN on LIST_TAIL.  */
94
95 static void
96 queue_pattern (pattern, list_tail, lineno)
97      rtx pattern;
98      struct queue_elem ***list_tail;
99      int lineno;
100 {
101   struct queue_elem *e = (struct queue_elem *) xmalloc (sizeof (*e));
102   e->data = pattern;
103   e->lineno = lineno;
104   e->next = NULL;
105   **list_tail = e;
106   *list_tail = &e->next;
107 }
108
109 /* Recursively remove constraints from an rtx.  */
110
111 static void
112 remove_constraints (part)
113      rtx part;
114 {
115   register int i, j;
116   register const char *format_ptr;
117
118   if (part == 0)
119     return;
120
121   if (GET_CODE (part) == MATCH_OPERAND)
122     XSTR (part, 2) = "";
123   else if (GET_CODE (part) == MATCH_SCRATCH)
124     XSTR (part, 1) = "";
125
126   format_ptr = GET_RTX_FORMAT (GET_CODE (part));
127
128   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
129     switch (*format_ptr++)
130       {
131       case 'e':
132       case 'u':
133         remove_constraints (XEXP (part, i));
134         break;
135       case 'E':
136         if (XVEC (part, i) != NULL)
137           for (j = 0; j < XVECLEN (part, i); j++)
138             remove_constraints (XVECEXP (part, i, j));
139         break;
140       }
141 }
142
143 /* Process a top level rtx in some way, queueing as appropriate.  */
144
145 static void
146 process_rtx (desc, lineno)
147      rtx desc;
148      int lineno;
149 {
150   switch (GET_CODE (desc))
151     {
152     case DEFINE_INSN:
153       queue_pattern (desc, &define_insn_tail, lineno);
154       break;
155
156     case DEFINE_COND_EXEC:
157       queue_pattern (desc, &define_cond_exec_tail, lineno);
158       break;
159
160     case DEFINE_ATTR:
161       queue_pattern (desc, &define_attr_tail, lineno);
162       break;
163
164     case DEFINE_INSN_AND_SPLIT:
165       {
166         const char *split_cond;
167         rtx split;
168         rtvec attr;
169         int i;
170
171         /* Create a split with values from the insn_and_split.  */
172         split = rtx_alloc (DEFINE_SPLIT);
173
174         i = XVECLEN (desc, 1);
175         XVEC (split, 0) = rtvec_alloc (i);
176         while (--i >= 0)
177           {
178             XVECEXP (split, 0, i) = copy_rtx (XVECEXP (desc, 1, i));
179             remove_constraints (XVECEXP (split, 0, i));
180           }
181
182         /* If the split condition starts with "&&", append it to the
183            insn condition to create the new split condition.  */
184         split_cond = XSTR (desc, 4);
185         if (split_cond[0] == '&' && split_cond[1] == '&')
186           {
187             const char *insn_cond = XSTR (desc, 2);
188             size_t insn_cond_len = strlen (insn_cond);
189             size_t split_cond_len = strlen (split_cond);
190             char *combined;
191
192             combined = (char *) xmalloc (insn_cond_len + split_cond_len + 1);
193             memcpy (combined, insn_cond, insn_cond_len);
194             memcpy (combined + insn_cond_len, split_cond, split_cond_len + 1);
195
196             split_cond = combined;
197           }
198         XSTR (split, 1) = split_cond;
199         XVEC (split, 2) = XVEC (desc, 5);
200         XSTR (split, 3) = XSTR (desc, 6);
201
202         /* Fix up the DEFINE_INSN.  */
203         attr = XVEC (desc, 7);
204         PUT_CODE (desc, DEFINE_INSN);
205         XVEC (desc, 4) = attr;
206
207         /* Queue them.  */
208         queue_pattern (desc, &define_insn_tail, lineno);
209         queue_pattern (split, &other_tail, lineno);
210         break;
211       }
212
213     default:
214       queue_pattern (desc, &other_tail, lineno);
215       break;
216     }
217 }
218 \f
219 /* Return true if attribute PREDICABLE is true for ELEM, which holds
220    a DEFINE_INSN.  */
221
222 static int
223 is_predicable (elem)
224      struct queue_elem *elem;
225 {
226   rtvec vec = XVEC (elem->data, 4);
227   const char *value;
228   int i;
229
230   if (! vec)
231     return predicable_default;
232
233   for (i = GET_NUM_ELEM (vec) - 1; i >= 0; --i)
234     {
235       rtx sub = RTVEC_ELT (vec, i);
236       switch (GET_CODE (sub))
237         {
238         case SET_ATTR:
239           if (strcmp (XSTR (sub, 0), "predicable") == 0)
240             {
241               value = XSTR (sub, 1);
242               goto found;
243             }
244           break;
245
246         case SET_ATTR_ALTERNATIVE:
247           if (strcmp (XSTR (sub, 0), "predicable") == 0)
248             {
249               message_with_line (elem->lineno,
250                                  "multiple alternatives for `predicable'");
251               errors = 1;
252               return 0;
253             }
254           break;
255
256         case SET:
257           if (GET_CODE (SET_DEST (sub)) != ATTR
258               || strcmp (XSTR (SET_DEST (sub), 0), "predicable") != 0)
259             break;
260           sub = SET_SRC (sub);
261           if (GET_CODE (sub) == CONST_STRING)
262             {
263               value = XSTR (sub, 0);
264               goto found;
265             }
266
267           /* ??? It would be possible to handle this if we really tried.
268              It's not easy though, and I'm not going to bother until it
269              really proves necessary.  */
270           message_with_line (elem->lineno,
271                              "non-constant value for `predicable'");
272           errors = 1;
273           return 0;
274
275         default:
276           abort ();
277         }
278     }
279
280   return predicable_default;
281
282  found:
283   /* Verify that predicability does not vary on the alternative.  */
284   /* ??? It should be possible to handle this by simply eliminating
285      the non-predicable alternatives from the insn.  FRV would like
286      to do this.  Delay this until we've got the basics solid.  */
287   if (strchr (value, ',') != NULL)
288     {
289       message_with_line (elem->lineno,
290                          "multiple alternatives for `predicable'");
291       errors = 1;
292       return 0;
293     }
294
295   /* Find out which value we're looking at.  */
296   if (strcmp (value, predicable_true) == 0)
297     return 1;
298   if (strcmp (value, predicable_false) == 0)
299     return 0;
300
301   message_with_line (elem->lineno,
302                      "Unknown value `%s' for `predicable' attribute",
303                      value);
304   errors = 1;
305   return 0;
306 }
307
308 /* Examine the attribute "predicable"; discover its boolean values
309    and its default.  */
310
311 static void
312 identify_predicable_attribute ()
313 {
314   struct queue_elem *elem;
315   char *p_true, *p_false;
316   const char *value;
317   size_t len;
318
319   /* Look for the DEFINE_ATTR for `predicable', which must exist.  */
320   for (elem = define_attr_queue; elem ; elem = elem->next)
321     if (strcmp (XSTR (elem->data, 0), "predicable") == 0)
322       goto found;
323
324   message_with_line (define_cond_exec_queue->lineno,
325                      "Attribute `predicable' not defined");
326   errors = 1;
327   return;
328
329  found:
330   value = XSTR (elem->data, 1);
331   len = strlen (value);
332   p_false = (char *) xmalloc (len + 1);
333   memcpy (p_false, value, len + 1);
334
335   p_true = strchr (p_false, ',');
336   if (p_true == NULL || strchr (++p_true, ',') != NULL)
337     {
338       message_with_line (elem->lineno,
339                          "Attribute `predicable' is not a boolean");
340       errors = 1;
341       return;
342     }
343   p_true[-1] = '\0';
344
345   predicable_true = p_true;
346   predicable_false = p_false;
347
348   switch (GET_CODE (XEXP (elem->data, 2)))
349     {
350     case CONST_STRING:
351       value = XSTR (XEXP (elem->data, 2), 0);
352       break;
353
354     case CONST:
355       message_with_line (elem->lineno,
356                          "Attribute `predicable' cannot be const");
357       errors = 1;
358       return;
359
360     default:
361       message_with_line (elem->lineno,
362                          "Attribute `predicable' must have a constant default");
363       errors = 1;
364       return;
365     }
366
367   if (strcmp (value, p_true) == 0)
368     predicable_default = 1;
369   else if (strcmp (value, p_false) == 0)
370     predicable_default = 0;
371   else
372     {
373       message_with_line (elem->lineno,
374                          "Unknown value `%s' for `predicable' attribute",
375                          value);
376       errors = 1;
377     }
378 }
379
380 /* Return the number of alternatives in constraint S.  */
381
382 static int
383 n_alternatives (s)
384      const char *s;
385 {
386   int n = 1;
387
388   if (s)
389     while (*s)
390       n += (*s++ == ',');
391
392   return n;
393 }
394
395 /* Determine how many alternatives there are in INSN, and how many
396    operands.  */
397
398 static void
399 collect_insn_data (pattern, palt, pmax)
400      rtx pattern;
401      int *palt, *pmax;
402 {
403   const char *fmt;
404   enum rtx_code code;
405   int i, j, len;
406
407   code = GET_CODE (pattern);
408   switch (code)
409     {
410     case MATCH_OPERAND:
411       i = n_alternatives (XSTR (pattern, 2));
412       *palt = (i > *palt ? i : *palt);
413       /* FALLTHRU */
414
415     case MATCH_OPERATOR:
416     case MATCH_SCRATCH:
417     case MATCH_PARALLEL:
418     case MATCH_INSN:
419       i = XINT (pattern, 0);
420       if (i > *pmax)
421         *pmax = i;
422       break;
423
424     default:
425       break;
426     }
427
428   fmt = GET_RTX_FORMAT (code);
429   len = GET_RTX_LENGTH (code);
430   for (i = 0; i < len; i++)
431     {
432       switch (fmt[i])
433         {
434         case 'e': case 'u':
435           collect_insn_data (XEXP (pattern, i), palt, pmax);
436           break;
437
438         case 'V':
439           if (XVEC (pattern, i) == NULL)
440             break;
441           /* FALLTHRU */
442         case 'E':
443           for (j = XVECLEN (pattern, i) - 1; j >= 0; --j)
444             collect_insn_data (XVECEXP (pattern, i, j), palt, pmax);
445           break;
446
447         case 'i': case 'w': case '0': case 's': case 'S': case 'T':
448           break;
449
450         default:
451           abort ();
452         }
453     }
454 }
455
456 static rtx
457 alter_predicate_for_insn (pattern, alt, max_op, lineno)
458      rtx pattern;
459      int alt, max_op, lineno;
460 {
461   const char *fmt;
462   enum rtx_code code;
463   int i, j, len;
464
465   code = GET_CODE (pattern);
466   switch (code)
467     {
468     case MATCH_OPERAND:
469       {
470         const char *c = XSTR (pattern, 2);
471
472         if (n_alternatives (c) != 1)
473           {
474             message_with_line (lineno,
475                                "Too many alternatives for operand %d",
476                                XINT (pattern, 0));
477             errors = 1;
478             return NULL;
479           }
480
481         /* Replicate C as needed to fill out ALT alternatives.  */
482         if (c && *c && alt > 1)
483           {
484             size_t c_len = strlen (c);
485             size_t len = alt * (c_len + 1);
486             char *new_c = (char *) xmalloc (len);
487
488             memcpy (new_c, c, c_len);
489             for (i = 1; i < alt; ++i)
490               {
491                 new_c[i * (c_len + 1) - 1] = ',';
492                 memcpy (&new_c[i * (c_len + 1)], c, c_len);
493               }
494             new_c[len - 1] = '\0';
495             XSTR (pattern, 2) = new_c;
496           }
497       }
498       /* FALLTHRU */
499
500     case MATCH_OPERATOR:
501     case MATCH_SCRATCH:
502     case MATCH_PARALLEL:
503     case MATCH_INSN:
504       XINT (pattern, 0) += max_op;
505       break;
506
507     default:
508       break;
509     }
510
511   fmt = GET_RTX_FORMAT (code);
512   len = GET_RTX_LENGTH (code);
513   for (i = 0; i < len; i++)
514     {
515       rtx r;
516
517       switch (fmt[i])
518         {
519         case 'e': case 'u':
520           r = alter_predicate_for_insn (XEXP (pattern, i), alt,
521                                         max_op, lineno);
522           if (r == NULL)
523             return r;
524           break;
525
526         case 'E':
527           for (j = XVECLEN (pattern, i) - 1; j >= 0; --j)
528             {
529               r = alter_predicate_for_insn (XVECEXP (pattern, i, j),
530                                             alt, max_op, lineno);
531               if (r == NULL)
532                 return r;
533             }
534           break;
535
536         case 'i': case 'w': case '0': case 's':
537           break;
538
539         default:
540           abort ();
541         }
542     }
543
544   return pattern;
545 }
546
547 static const char *
548 alter_test_for_insn (ce_elem, insn_elem)
549      struct queue_elem *ce_elem, *insn_elem;
550 {
551   const char *ce_test, *insn_test;
552   char *new_test;
553   size_t len, ce_len, insn_len;
554
555   ce_test = XSTR (ce_elem->data, 1);
556   insn_test = XSTR (insn_elem->data, 2);
557   if (!ce_test || *ce_test == '\0')
558     return insn_test;
559   if (!insn_test || *insn_test == '\0')
560     return ce_test;
561
562   ce_len = strlen (ce_test);
563   insn_len = strlen (insn_test);
564   len = 1 + ce_len + 1 + 4 + 1 + insn_len + 1 + 1;
565   new_test = (char *) xmalloc (len);
566
567   sprintf (new_test, "(%s) && (%s)", ce_test, insn_test);
568
569   return new_test;
570 }
571
572 /* Adjust all of the operand numbers in OLD to match the shift they'll
573    get from an operand displacement of DISP.  Return a pointer after the
574    adjusted string.  */
575
576 static char *
577 shift_output_template (new, old, disp)
578      char *new;
579      const char *old;
580      int disp;
581 {
582   while (*old)
583     {
584       char c = *old++;
585       *new++ = c;
586       if (c == '%')
587         {
588           c = *old++;
589           if (ISDIGIT ((unsigned char) c))
590             c += disp;
591           else if (ISUPPER ((unsigned char) c)
592                    || ISLOWER ((unsigned char) c))
593             {
594               *new++ = c;
595               c = *old++ + disp;
596             }
597           *new++ = c;
598         }
599     }
600
601   return new;
602 }
603
604 static const char *
605 alter_output_for_insn (ce_elem, insn_elem, alt, max_op)
606      struct queue_elem *ce_elem, *insn_elem;
607      int alt, max_op;
608 {
609   const char *ce_out, *insn_out;
610   char *new, *p;
611   size_t len, ce_len, insn_len;
612
613   /* ??? Could coordinate with genoutput to not duplicate code here.  */
614
615   ce_out = XSTR (ce_elem->data, 2);
616   insn_out = XTMPL (insn_elem->data, 3);
617   if (!ce_out || *ce_out == '\0')
618     return insn_out;
619
620   ce_len = strlen (ce_out);
621   insn_len = strlen (insn_out);
622
623   if (*insn_out == '*')
624     /* You must take care of the predicate yourself.  */
625     return insn_out;
626
627   if (*insn_out == '@')
628     {
629       len = (ce_len + 1) * alt + insn_len + 1;
630       p = new = xmalloc (len);
631
632       do
633         {
634           do
635             *p++ = *insn_out++;
636           while (ISSPACE ((unsigned char) *insn_out));
637
638           if (*insn_out != '#')
639             {
640               p = shift_output_template (p, ce_out, max_op);
641               *p++ = ' ';
642             }
643
644           do
645             *p++ = *insn_out++;
646           while (*insn_out && *insn_out != '\n');
647         }
648       while (*insn_out);
649       *p = '\0';
650     }
651   else
652     {
653       len = ce_len + 1 + insn_len + 1;
654       new = xmalloc (len);
655
656       p = shift_output_template (new, ce_out, max_op);
657       *p++ = ' ';
658       memcpy (p, insn_out, insn_len + 1);
659     }
660
661   return new;
662 }
663
664 /* Replicate insns as appropriate for the given DEFINE_COND_EXEC.  */
665
666 static void
667 process_one_cond_exec (ce_elem)
668      struct queue_elem *ce_elem;
669 {
670   struct queue_elem *insn_elem;
671   for (insn_elem = define_insn_queue; insn_elem ; insn_elem = insn_elem->next)
672     {
673       int alternatives, max_operand;
674       rtx pred, insn, pattern;
675
676       if (! is_predicable (insn_elem))
677         continue;
678
679       alternatives = 1;
680       max_operand = -1;
681       collect_insn_data (insn_elem->data, &alternatives, &max_operand);
682       max_operand += 1;
683
684       if (XVECLEN (ce_elem->data, 0) != 1)
685         {
686           message_with_line (ce_elem->lineno,
687                              "too many patterns in predicate");
688           errors = 1;
689           return;
690         }
691
692       pred = copy_rtx (XVECEXP (ce_elem->data, 0, 0));
693       pred = alter_predicate_for_insn (pred, alternatives, max_operand,
694                                        ce_elem->lineno);
695       if (pred == NULL)
696         return;
697
698       /* Construct a new pattern for the new insn.  */
699       insn = copy_rtx (insn_elem->data);
700       XSTR (insn, 0) = "";
701       pattern = rtx_alloc (COND_EXEC);
702       XEXP (pattern, 0) = pred;
703       if (XVECLEN (insn, 1) == 1)
704         {
705           XEXP (pattern, 1) = XVECEXP (insn, 1, 0);
706           XVECEXP (insn, 1, 0) = pattern;
707           PUT_NUM_ELEM (XVEC (insn, 1), 1);
708         }
709       else
710         {
711           XEXP (pattern, 1) = rtx_alloc (PARALLEL);
712           XVEC (XEXP (pattern, 1), 0) = XVEC (insn, 1);
713           XVEC (insn, 1) = rtvec_alloc (1);
714           XVECEXP (insn, 1, 0) = pattern;
715         }
716
717       XSTR (insn, 2) = alter_test_for_insn (ce_elem, insn_elem);
718       XTMPL (insn, 3) = alter_output_for_insn (ce_elem, insn_elem,
719                                               alternatives, max_operand);
720
721       /* ??? Set `predicable' to false.  Not crucial since it's really
722          only used here, and we won't reprocess this new pattern.  */
723
724       /* Put the new pattern on the `other' list so that it
725          (a) is not reprocessed by other define_cond_exec patterns
726          (b) appears after all normal define_insn patterns.
727
728          ??? B is debatable.  If one has normal insns that match
729          cond_exec patterns, they will be preferred over these
730          generated patterns.  Whether this matters in practice, or if
731          it's a good thing, or whether we should thread these new
732          patterns into the define_insn chain just after their generator
733          is something we'll have to experiment with.  */
734
735       queue_pattern (insn, &other_tail, insn_elem->lineno);
736     }
737 }
738
739 /* If we have any DEFINE_COND_EXEC patterns, expand the DEFINE_INSN
740    patterns appropriately.  */
741
742 static void
743 process_define_cond_exec ()
744 {
745   struct queue_elem *elem;
746
747   identify_predicable_attribute ();
748   if (errors)
749     return;
750
751   for (elem = define_cond_exec_queue; elem ; elem = elem->next)
752     process_one_cond_exec (elem);
753 }
754 \f
755 /* The entry point for initializing the reader.  */
756
757 int
758 init_md_reader (filename)
759      const char *filename;
760 {
761   FILE *input_file;
762   int c;
763
764   read_rtx_filename = filename;
765   input_file = fopen (filename, "r");
766   if (input_file == 0)
767     {
768       perror (filename);
769       return FATAL_EXIT_CODE;
770     }
771
772   obstack_init (rtl_obstack);
773   errors = 0;
774   sequence_num = 0;
775
776   /* Read the entire file.  */
777   while (1)
778     {
779       rtx desc;
780       int lineno;
781
782       c = read_skip_spaces (input_file);
783       if (c == EOF)
784         break;
785
786       ungetc (c, input_file);
787       lineno = read_rtx_lineno;
788       desc = read_rtx (input_file);
789       process_rtx (desc, lineno);
790     }
791   fclose (input_file);
792
793   /* Process define_cond_exec patterns.  */
794   if (define_cond_exec_queue != NULL)
795     process_define_cond_exec ();
796
797   return errors ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;
798 }
799
800 /* The entry point for reading a single rtx from an md file.  */
801
802 rtx
803 read_md_rtx (lineno, seqnr)
804      int *lineno;
805      int *seqnr;
806 {
807   struct queue_elem **queue, *elem;
808   rtx desc;
809
810   /* Read all patterns from a given queue before moving on to the next.  */
811   if (define_attr_queue != NULL)
812     queue = &define_attr_queue;
813   else if (define_insn_queue != NULL)
814     queue = &define_insn_queue;
815   else if (other_queue != NULL)
816     queue = &other_queue;
817   else
818     return NULL_RTX;
819
820   elem = *queue;
821   *queue = elem->next;
822   desc = elem->data;
823   *lineno = elem->lineno;
824   *seqnr = sequence_num;
825
826   free (elem);
827
828   switch (GET_CODE (desc))
829     {
830     case DEFINE_INSN:
831     case DEFINE_EXPAND:
832     case DEFINE_SPLIT:
833     case DEFINE_PEEPHOLE:
834     case DEFINE_PEEPHOLE2:
835       sequence_num++;
836       break;
837
838     default:
839       break;
840     }
841
842   return desc;
843 }
844
845 /* Until we can use the versions in libiberty.  */
846 char *
847 xstrdup (input)
848   const char *input;
849 {
850   register size_t len = strlen (input) + 1;
851   register char *output = xmalloc (len);
852   memcpy (output, input, len);
853   return output;
854 }
855
856 PTR
857 xcalloc (nelem, elsize)
858   size_t nelem, elsize;
859 {
860   PTR newmem;
861
862   if (nelem == 0 || elsize == 0)
863     nelem = elsize = 1;
864
865   newmem = really_call_calloc (nelem, elsize);
866   if (!newmem)
867     fatal ("virtual memory exhausted");
868   return (newmem);
869 }
870
871 PTR
872 xrealloc (old, size)
873   PTR old;
874   size_t size;
875 {
876   register PTR ptr;
877   if (old)
878     ptr = (PTR) really_call_realloc (old, size);
879   else
880     ptr = (PTR) really_call_malloc (size);
881   if (!ptr)
882     fatal ("virtual memory exhausted");
883   return ptr;
884 }
885
886 PTR
887 xmalloc (size)
888   size_t size;
889 {
890   register PTR val = (PTR) really_call_malloc (size);
891
892   if (val == 0)
893     fatal ("virtual memory exhausted");
894   return val;
895 }