OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [genemit.c] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* Generate code from machine description to emit insns as rtl.
2
   Copyright (C) 1987, 1988, 1991, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
3
   2003, 2004, 2005, 2007 Free Software Foundation, Inc.
4
 
5
This file is part of GCC.
6
 
7
GCC is free software; you can redistribute it and/or modify it under
8
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 3, or (at your option) any later
10
version.
11
 
12
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15
for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with GCC; see the file COPYING3.  If not see
19
<http://www.gnu.org/licenses/>.  */
20
 
21
 
22
#include "bconfig.h"
23
#include "system.h"
24
#include "coretypes.h"
25
#include "tm.h"
26
#include "rtl.h"
27
#include "errors.h"
28
#include "gensupport.h"
29
 
30
 
31
static int max_opno;
32
static int max_dup_opno;
33
static int max_scratch_opno;
34
static int insn_code_number;
35
static int insn_index_number;
36
 
37
/* Data structure for recording the patterns of insns that have CLOBBERs.
38
   We use this to output a function that adds these CLOBBERs to a
39
   previously-allocated PARALLEL expression.  */
40
 
41
struct clobber_pat
42
{
43
  struct clobber_ent *insns;
44
  rtx pattern;
45
  int first_clobber;
46
  struct clobber_pat *next;
47
  int has_hard_reg;
48
} *clobber_list;
49
 
50
/* Records one insn that uses the clobber list.  */
51
 
52
struct clobber_ent
53
{
54
  int code_number;              /* Counts only insns.  */
55
  struct clobber_ent *next;
56
};
57
 
58
static void max_operand_1               (rtx);
59
static int max_operand_vec              (rtx, int);
60
static void print_code                  (RTX_CODE);
61
static void gen_exp                     (rtx, enum rtx_code, char *);
62
static void gen_insn                    (rtx, int);
63
static void gen_expand                  (rtx);
64
static void gen_split                   (rtx);
65
static void output_add_clobbers         (void);
66
static void output_added_clobbers_hard_reg_p (void);
67
static void gen_rtx_scratch             (rtx, enum rtx_code);
68
static void output_peephole2_scratches  (rtx);
69
 
70
 
71
static void
72
max_operand_1 (rtx x)
73
{
74
  RTX_CODE code;
75
  int i;
76
  int len;
77
  const char *fmt;
78
 
79
  if (x == 0)
80
    return;
81
 
82
  code = GET_CODE (x);
83
 
84
  if (code == MATCH_OPERAND || code == MATCH_OPERATOR
85
      || code == MATCH_PARALLEL)
86
    max_opno = MAX (max_opno, XINT (x, 0));
87
  if (code == MATCH_DUP || code == MATCH_OP_DUP || code == MATCH_PAR_DUP)
88
    max_dup_opno = MAX (max_dup_opno, XINT (x, 0));
89
  if (code == MATCH_SCRATCH)
90
    max_scratch_opno = MAX (max_scratch_opno, XINT (x, 0));
91
 
92
  fmt = GET_RTX_FORMAT (code);
93
  len = GET_RTX_LENGTH (code);
94
  for (i = 0; i < len; i++)
95
    {
96
      if (fmt[i] == 'e' || fmt[i] == 'u')
97
        max_operand_1 (XEXP (x, i));
98
      else if (fmt[i] == 'E')
99
        {
100
          int j;
101
          for (j = 0; j < XVECLEN (x, i); j++)
102
            max_operand_1 (XVECEXP (x, i, j));
103
        }
104
    }
105
}
106
 
107
static int
108
max_operand_vec (rtx insn, int arg)
109
{
110
  int len = XVECLEN (insn, arg);
111
  int i;
112
 
113
  max_opno = -1;
114
  max_dup_opno = -1;
115
  max_scratch_opno = -1;
116
 
117
  for (i = 0; i < len; i++)
118
    max_operand_1 (XVECEXP (insn, arg, i));
119
 
120
  return max_opno + 1;
121
}
122
 
123
static void
124
print_code (RTX_CODE code)
125
{
126
  const char *p1;
127
  for (p1 = GET_RTX_NAME (code); *p1; p1++)
128
    putchar (TOUPPER(*p1));
129
}
130
 
131
static void
132
gen_rtx_scratch (rtx x, enum rtx_code subroutine_type)
133
{
134
  if (subroutine_type == DEFINE_PEEPHOLE2)
135
    {
136
      printf ("operand%d", XINT (x, 0));
137
    }
138
  else
139
    {
140
      printf ("gen_rtx_SCRATCH (%smode)", GET_MODE_NAME (GET_MODE (x)));
141
    }
142
}
143
 
144
/* Print a C expression to construct an RTX just like X,
145
   substituting any operand references appearing within.  */
146
 
147
static void
148
gen_exp (rtx x, enum rtx_code subroutine_type, char *used)
149
{
150
  RTX_CODE code;
151
  int i;
152
  int len;
153
  const char *fmt;
154
 
155
  if (x == 0)
156
    {
157
      printf ("NULL_RTX");
158
      return;
159
    }
160
 
161
  code = GET_CODE (x);
162
 
163
  switch (code)
164
    {
165
    case MATCH_OPERAND:
166
    case MATCH_DUP:
167
      if (used)
168
        {
169
          if (used[XINT (x, 0)])
170
            {
171
              printf ("copy_rtx (operand%d)", XINT (x, 0));
172
              return;
173
            }
174
          used[XINT (x, 0)] = 1;
175
        }
176
      printf ("operand%d", XINT (x, 0));
177
      return;
178
 
179
    case MATCH_OP_DUP:
180
      printf ("gen_rtx_fmt_");
181
      for (i = 0; i < XVECLEN (x, 1); i++)
182
        printf ("e");
183
      printf (" (GET_CODE (operand%d), ", XINT (x, 0));
184
      if (GET_MODE (x) == VOIDmode)
185
        printf ("GET_MODE (operand%d)", XINT (x, 0));
186
      else
187
        printf ("%smode", GET_MODE_NAME (GET_MODE (x)));
188
      for (i = 0; i < XVECLEN (x, 1); i++)
189
        {
190
          printf (",\n\t\t");
191
          gen_exp (XVECEXP (x, 1, i), subroutine_type, used);
192
        }
193
      printf (")");
194
      return;
195
 
196
    case MATCH_OPERATOR:
197
      printf ("gen_rtx_fmt_");
198
      for (i = 0; i < XVECLEN (x, 2); i++)
199
        printf ("e");
200
      printf (" (GET_CODE (operand%d)", XINT (x, 0));
201
      printf (", %smode", GET_MODE_NAME (GET_MODE (x)));
202
      for (i = 0; i < XVECLEN (x, 2); i++)
203
        {
204
          printf (",\n\t\t");
205
          gen_exp (XVECEXP (x, 2, i), subroutine_type, used);
206
        }
207
      printf (")");
208
      return;
209
 
210
    case MATCH_PARALLEL:
211
    case MATCH_PAR_DUP:
212
      printf ("operand%d", XINT (x, 0));
213
      return;
214
 
215
    case MATCH_SCRATCH:
216
      gen_rtx_scratch (x, subroutine_type);
217
      return;
218
 
219
    case ADDRESS:
220
      fatal ("ADDRESS expression code used in named instruction pattern");
221
 
222
    case PC:
223
      printf ("pc_rtx");
224
      return;
225
    case CLOBBER:
226
      if (REG_P (XEXP (x, 0)))
227
        {
228
          printf ("gen_hard_reg_clobber (%smode, %i)", GET_MODE_NAME (GET_MODE (XEXP (x, 0))),
229
                                                     REGNO (XEXP (x, 0)));
230
          return;
231
        }
232
      break;
233
 
234
    case CC0:
235
      printf ("cc0_rtx");
236
      return;
237
 
238
    case CONST_INT:
239
      if (INTVAL (x) == 0)
240
        printf ("const0_rtx");
241
      else if (INTVAL (x) == 1)
242
        printf ("const1_rtx");
243
      else if (INTVAL (x) == -1)
244
        printf ("constm1_rtx");
245
      else if (-MAX_SAVED_CONST_INT <= INTVAL (x)
246
          && INTVAL (x) <= MAX_SAVED_CONST_INT)
247
        printf ("const_int_rtx[MAX_SAVED_CONST_INT + (%d)]",
248
                (int) INTVAL (x));
249
      else if (INTVAL (x) == STORE_FLAG_VALUE)
250
        printf ("const_true_rtx");
251
      else
252
        {
253
          printf ("GEN_INT (");
254
          printf (HOST_WIDE_INT_PRINT_DEC_C, INTVAL (x));
255
          printf (")");
256
        }
257
      return;
258
 
259
    case CONST_DOUBLE:
260
      /* These shouldn't be written in MD files.  Instead, the appropriate
261
         routines in varasm.c should be called.  */
262
      gcc_unreachable ();
263
 
264
    default:
265
      break;
266
    }
267
 
268
  printf ("gen_rtx_");
269
  print_code (code);
270
  printf (" (%smode", GET_MODE_NAME (GET_MODE (x)));
271
 
272
  fmt = GET_RTX_FORMAT (code);
273
  len = GET_RTX_LENGTH (code);
274
  for (i = 0; i < len; i++)
275
    {
276
      if (fmt[i] == '0')
277
        break;
278
      printf (",\n\t");
279
      switch (fmt[i])
280
        {
281
        case 'e': case 'u':
282
          gen_exp (XEXP (x, i), subroutine_type, used);
283
          break;
284
 
285
        case 'i':
286
          printf ("%u", XINT (x, i));
287
          break;
288
 
289
        case 's':
290
          printf ("\"%s\"", XSTR (x, i));
291
          break;
292
 
293
        case 'E':
294
          {
295
            int j;
296
            printf ("gen_rtvec (%d", XVECLEN (x, i));
297
            for (j = 0; j < XVECLEN (x, i); j++)
298
              {
299
                printf (",\n\t\t");
300
                gen_exp (XVECEXP (x, i, j), subroutine_type, used);
301
              }
302
            printf (")");
303
            break;
304
          }
305
 
306
        default:
307
          gcc_unreachable ();
308
        }
309
    }
310
  printf (")");
311
}
312
 
313
/* Generate the `gen_...' function for a DEFINE_INSN.  */
314
 
315
static void
316
gen_insn (rtx insn, int lineno)
317
{
318
  int operands;
319
  int i;
320
 
321
  /* See if the pattern for this insn ends with a group of CLOBBERs of (hard)
322
     registers or MATCH_SCRATCHes.  If so, store away the information for
323
     later.  */
324
 
325
  if (XVEC (insn, 1))
326
    {
327
      int has_hard_reg = 0;
328
 
329
      for (i = XVECLEN (insn, 1) - 1; i > 0; i--)
330
        {
331
          if (GET_CODE (XVECEXP (insn, 1, i)) != CLOBBER)
332
            break;
333
 
334
          if (REG_P (XEXP (XVECEXP (insn, 1, i), 0)))
335
            has_hard_reg = 1;
336
          else if (GET_CODE (XEXP (XVECEXP (insn, 1, i), 0)) != MATCH_SCRATCH)
337
            break;
338
        }
339
 
340
      if (i != XVECLEN (insn, 1) - 1)
341
        {
342
          struct clobber_pat *p;
343
          struct clobber_ent *link = XNEW (struct clobber_ent);
344
          int j;
345
 
346
          link->code_number = insn_code_number;
347
 
348
          /* See if any previous CLOBBER_LIST entry is the same as this
349
             one.  */
350
 
351
          for (p = clobber_list; p; p = p->next)
352
            {
353
              if (p->first_clobber != i + 1
354
                  || XVECLEN (p->pattern, 1) != XVECLEN (insn, 1))
355
                continue;
356
 
357
              for (j = i + 1; j < XVECLEN (insn, 1); j++)
358
                {
359
                  rtx old = XEXP (XVECEXP (p->pattern, 1, j), 0);
360
                  rtx new = XEXP (XVECEXP (insn, 1, j), 0);
361
 
362
                  /* OLD and NEW are the same if both are to be a SCRATCH
363
                     of the same mode,
364
                     or if both are registers of the same mode and number.  */
365
                  if (! (GET_MODE (old) == GET_MODE (new)
366
                         && ((GET_CODE (old) == MATCH_SCRATCH
367
                              && GET_CODE (new) == MATCH_SCRATCH)
368
                             || (REG_P (old) && REG_P (new)
369
                                 && REGNO (old) == REGNO (new)))))
370
                    break;
371
                }
372
 
373
              if (j == XVECLEN (insn, 1))
374
                break;
375
            }
376
 
377
          if (p == 0)
378
            {
379
              p = XNEW (struct clobber_pat);
380
 
381
              p->insns = 0;
382
              p->pattern = insn;
383
              p->first_clobber = i + 1;
384
              p->next = clobber_list;
385
              p->has_hard_reg = has_hard_reg;
386
              clobber_list = p;
387
            }
388
 
389
          link->next = p->insns;
390
          p->insns = link;
391
        }
392
    }
393
 
394
  /* Don't mention instructions whose names are the null string
395
     or begin with '*'.  They are in the machine description just
396
     to be recognized.  */
397
  if (XSTR (insn, 0)[0] == 0 || XSTR (insn, 0)[0] == '*')
398
    return;
399
 
400
  printf ("/* %s:%d */\n", read_rtx_filename, lineno);
401
 
402
  /* Find out how many operands this function has.  */
403
  operands = max_operand_vec (insn, 1);
404
  if (max_dup_opno >= operands)
405
    fatal ("match_dup operand number has no match_operand");
406
 
407
  /* Output the function name and argument declarations.  */
408
  printf ("rtx\ngen_%s (", XSTR (insn, 0));
409
  if (operands)
410
    for (i = 0; i < operands; i++)
411
      if (i)
412
        printf (",\n\trtx operand%d ATTRIBUTE_UNUSED", i);
413
      else
414
        printf ("rtx operand%d ATTRIBUTE_UNUSED", i);
415
  else
416
    printf ("void");
417
  printf (")\n");
418
  printf ("{\n");
419
 
420
  /* Output code to construct and return the rtl for the instruction body.  */
421
 
422
  if (XVECLEN (insn, 1) == 1)
423
    {
424
      printf ("  return ");
425
      gen_exp (XVECEXP (insn, 1, 0), DEFINE_INSN, NULL);
426
      printf (";\n}\n\n");
427
    }
428
  else
429
    {
430
      printf ("  return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (%d",
431
              XVECLEN (insn, 1));
432
 
433
      for (i = 0; i < XVECLEN (insn, 1); i++)
434
        {
435
          printf (",\n\t\t");
436
          gen_exp (XVECEXP (insn, 1, i), DEFINE_INSN, NULL);
437
        }
438
      printf ("));\n}\n\n");
439
    }
440
}
441
 
442
/* Generate the `gen_...' function for a DEFINE_EXPAND.  */
443
 
444
static void
445
gen_expand (rtx expand)
446
{
447
  int operands;
448
  int i;
449
 
450
  if (strlen (XSTR (expand, 0)) == 0)
451
    fatal ("define_expand lacks a name");
452
  if (XVEC (expand, 1) == 0)
453
    fatal ("define_expand for %s lacks a pattern", XSTR (expand, 0));
454
 
455
  /* Find out how many operands this function has.  */
456
  operands = max_operand_vec (expand, 1);
457
 
458
  /* Output the function name and argument declarations.  */
459
  printf ("rtx\ngen_%s (", XSTR (expand, 0));
460
  if (operands)
461
    for (i = 0; i < operands; i++)
462
      if (i)
463
        printf (",\n\trtx operand%d", i);
464
      else
465
        printf ("rtx operand%d", i);
466
  else
467
    printf ("void");
468
  printf (")\n");
469
  printf ("{\n");
470
 
471
  /* If we don't have any C code to write, only one insn is being written,
472
     and no MATCH_DUPs are present, we can just return the desired insn
473
     like we do for a DEFINE_INSN.  This saves memory.  */
474
  if ((XSTR (expand, 3) == 0 || *XSTR (expand, 3) == '\0')
475
      && operands > max_dup_opno
476
      && XVECLEN (expand, 1) == 1)
477
    {
478
      printf ("  return ");
479
      gen_exp (XVECEXP (expand, 1, 0), DEFINE_EXPAND, NULL);
480
      printf (";\n}\n\n");
481
      return;
482
    }
483
 
484
  /* For each operand referred to only with MATCH_DUPs,
485
     make a local variable.  */
486
  for (i = operands; i <= max_dup_opno; i++)
487
    printf ("  rtx operand%d;\n", i);
488
  for (; i <= max_scratch_opno; i++)
489
    printf ("  rtx operand%d ATTRIBUTE_UNUSED;\n", i);
490
  printf ("  rtx _val = 0;\n");
491
  printf ("  start_sequence ();\n");
492
 
493
  /* The fourth operand of DEFINE_EXPAND is some code to be executed
494
     before the actual construction.
495
     This code expects to refer to `operands'
496
     just as the output-code in a DEFINE_INSN does,
497
     but here `operands' is an automatic array.
498
     So copy the operand values there before executing it.  */
499
  if (XSTR (expand, 3) && *XSTR (expand, 3))
500
    {
501
      printf ("  {\n");
502
      if (operands > 0 || max_dup_opno >= 0 || max_scratch_opno >= 0)
503
        printf ("    rtx operands[%d];\n",
504
            MAX (operands, MAX (max_scratch_opno, max_dup_opno) + 1));
505
      /* Output code to copy the arguments into `operands'.  */
506
      for (i = 0; i < operands; i++)
507
        printf ("    operands[%d] = operand%d;\n", i, i);
508
 
509
      /* Output the special code to be executed before the sequence
510
         is generated.  */
511
      print_rtx_ptr_loc (XSTR (expand, 3));
512
      printf ("%s\n", XSTR (expand, 3));
513
 
514
      /* Output code to copy the arguments back out of `operands'
515
         (unless we aren't going to use them at all).  */
516
      if (XVEC (expand, 1) != 0)
517
        {
518
          for (i = 0; i < operands; i++)
519
            printf ("    operand%d = operands[%d];\n", i, i);
520
          for (; i <= max_dup_opno; i++)
521
            printf ("    operand%d = operands[%d];\n", i, i);
522
          for (; i <= max_scratch_opno; i++)
523
            printf ("    operand%d = operands[%d];\n", i, i);
524
        }
525
      printf ("  }\n");
526
    }
527
 
528
  /* Output code to construct the rtl for the instruction bodies.
529
     Use emit_insn to add them to the sequence being accumulated.
530
     But don't do this if the user's code has set `no_more' nonzero.  */
531
 
532
  for (i = 0; i < XVECLEN (expand, 1); i++)
533
    {
534
      rtx next = XVECEXP (expand, 1, i);
535
      if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC)
536
          || (GET_CODE (next) == PARALLEL
537
              && ((GET_CODE (XVECEXP (next, 0, 0)) == SET
538
                   && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC)
539
                  || GET_CODE (XVECEXP (next, 0, 0)) == RETURN))
540
          || GET_CODE (next) == RETURN)
541
        printf ("  emit_jump_insn (");
542
      else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL)
543
               || GET_CODE (next) == CALL
544
               || (GET_CODE (next) == PARALLEL
545
                   && GET_CODE (XVECEXP (next, 0, 0)) == SET
546
                   && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL)
547
               || (GET_CODE (next) == PARALLEL
548
                   && GET_CODE (XVECEXP (next, 0, 0)) == CALL))
549
        printf ("  emit_call_insn (");
550
      else if (LABEL_P (next))
551
        printf ("  emit_label (");
552
      else if (GET_CODE (next) == MATCH_OPERAND
553
               || GET_CODE (next) == MATCH_DUP
554
               || GET_CODE (next) == MATCH_OPERATOR
555
               || GET_CODE (next) == MATCH_OP_DUP
556
               || GET_CODE (next) == MATCH_PARALLEL
557
               || GET_CODE (next) == MATCH_PAR_DUP
558
               || GET_CODE (next) == PARALLEL)
559
        printf ("  emit (");
560
      else
561
        printf ("  emit_insn (");
562
      gen_exp (next, DEFINE_EXPAND, NULL);
563
      printf (");\n");
564
      if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC
565
          && GET_CODE (SET_SRC (next)) == LABEL_REF)
566
        printf ("  emit_barrier ();");
567
    }
568
 
569
  /* Call `get_insns' to extract the list of all the
570
     insns emitted within this gen_... function.  */
571
 
572
  printf ("  _val = get_insns ();\n");
573
  printf ("  end_sequence ();\n");
574
  printf ("  return _val;\n}\n\n");
575
}
576
 
577
/* Like gen_expand, but generates insns resulting from splitting SPLIT.  */
578
 
579
static void
580
gen_split (rtx split)
581
{
582
  int i;
583
  int operands;
584
  const char *const name =
585
    ((GET_CODE (split) == DEFINE_PEEPHOLE2) ? "peephole2" : "split");
586
  const char *unused;
587
  char *used;
588
 
589
  if (XVEC (split, 0) == 0)
590
    fatal ("define_%s (definition %d) lacks a pattern", name,
591
           insn_index_number);
592
  else if (XVEC (split, 2) == 0)
593
    fatal ("define_%s (definition %d) lacks a replacement pattern", name,
594
           insn_index_number);
595
 
596
  /* Find out how many operands this function has.  */
597
 
598
  max_operand_vec (split, 2);
599
  operands = MAX (max_opno, MAX (max_dup_opno, max_scratch_opno)) + 1;
600
  unused = (operands == 0 ? " ATTRIBUTE_UNUSED" : "");
601
  used = XCNEWVEC (char, operands);
602
 
603
  /* Output the prototype, function name and argument declarations.  */
604
  if (GET_CODE (split) == DEFINE_PEEPHOLE2)
605
    {
606
      printf ("extern rtx gen_%s_%d (rtx, rtx *);\n",
607
              name, insn_code_number);
608
      printf ("rtx\ngen_%s_%d (rtx curr_insn ATTRIBUTE_UNUSED, rtx *operands%s)\n",
609
              name, insn_code_number, unused);
610
    }
611
  else
612
    {
613
      printf ("extern rtx gen_split_%d (rtx, rtx *);\n", insn_code_number);
614
      printf ("rtx\ngen_split_%d (rtx curr_insn ATTRIBUTE_UNUSED, rtx *operands%s)\n",
615
              insn_code_number, unused);
616
    }
617
  printf ("{\n");
618
 
619
  /* Declare all local variables.  */
620
  for (i = 0; i < operands; i++)
621
    printf ("  rtx operand%d;\n", i);
622
  printf ("  rtx _val = 0;\n");
623
 
624
  if (GET_CODE (split) == DEFINE_PEEPHOLE2)
625
    output_peephole2_scratches (split);
626
 
627
  printf ("  start_sequence ();\n");
628
 
629
  /* The fourth operand of DEFINE_SPLIT is some code to be executed
630
     before the actual construction.  */
631
 
632
  if (XSTR (split, 3))
633
    {
634
      print_rtx_ptr_loc (XSTR (split, 3));
635
      printf ("%s\n", XSTR (split, 3));
636
    }
637
 
638
  /* Output code to copy the arguments back out of `operands'  */
639
  for (i = 0; i < operands; i++)
640
    printf ("  operand%d = operands[%d];\n", i, i);
641
 
642
  /* Output code to construct the rtl for the instruction bodies.
643
     Use emit_insn to add them to the sequence being accumulated.
644
     But don't do this if the user's code has set `no_more' nonzero.  */
645
 
646
  for (i = 0; i < XVECLEN (split, 2); i++)
647
    {
648
      rtx next = XVECEXP (split, 2, i);
649
      if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC)
650
          || (GET_CODE (next) == PARALLEL
651
              && GET_CODE (XVECEXP (next, 0, 0)) == SET
652
              && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC)
653
          || GET_CODE (next) == RETURN)
654
        printf ("  emit_jump_insn (");
655
      else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL)
656
               || GET_CODE (next) == CALL
657
               || (GET_CODE (next) == PARALLEL
658
                   && GET_CODE (XVECEXP (next, 0, 0)) == SET
659
                   && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL)
660
               || (GET_CODE (next) == PARALLEL
661
                   && GET_CODE (XVECEXP (next, 0, 0)) == CALL))
662
        printf ("  emit_call_insn (");
663
      else if (LABEL_P (next))
664
        printf ("  emit_label (");
665
      else if (GET_CODE (next) == MATCH_OPERAND
666
               || GET_CODE (next) == MATCH_OPERATOR
667
               || GET_CODE (next) == MATCH_PARALLEL
668
               || GET_CODE (next) == MATCH_OP_DUP
669
               || GET_CODE (next) == MATCH_DUP
670
               || GET_CODE (next) == PARALLEL)
671
        printf ("  emit (");
672
      else
673
        printf ("  emit_insn (");
674
      gen_exp (next, GET_CODE (split), used);
675
      printf (");\n");
676
      if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC
677
          && GET_CODE (SET_SRC (next)) == LABEL_REF)
678
        printf ("  emit_barrier ();");
679
    }
680
 
681
  /* Call `get_insns' to make a list of all the
682
     insns emitted within this gen_... function.  */
683
 
684
  printf ("  _val = get_insns ();\n");
685
  printf ("  end_sequence ();\n");
686
  printf ("  return _val;\n}\n\n");
687
 
688
  free (used);
689
}
690
 
691
/* Write a function, `add_clobbers', that is given a PARALLEL of sufficient
692
   size for the insn and an INSN_CODE, and inserts the required CLOBBERs at
693
   the end of the vector.  */
694
 
695
static void
696
output_add_clobbers (void)
697
{
698
  struct clobber_pat *clobber;
699
  struct clobber_ent *ent;
700
  int i;
701
 
702
  printf ("\n\nvoid\nadd_clobbers (rtx pattern ATTRIBUTE_UNUSED, int insn_code_number)\n");
703
  printf ("{\n");
704
  printf ("  switch (insn_code_number)\n");
705
  printf ("    {\n");
706
 
707
  for (clobber = clobber_list; clobber; clobber = clobber->next)
708
    {
709
      for (ent = clobber->insns; ent; ent = ent->next)
710
        printf ("    case %d:\n", ent->code_number);
711
 
712
      for (i = clobber->first_clobber; i < XVECLEN (clobber->pattern, 1); i++)
713
        {
714
          printf ("      XVECEXP (pattern, 0, %d) = ", i);
715
          gen_exp (XVECEXP (clobber->pattern, 1, i),
716
                   GET_CODE (clobber->pattern), NULL);
717
          printf (";\n");
718
        }
719
 
720
      printf ("      break;\n\n");
721
    }
722
 
723
  printf ("    default:\n");
724
  printf ("      gcc_unreachable ();\n");
725
  printf ("    }\n");
726
  printf ("}\n");
727
}
728
 
729
/* Write a function, `added_clobbers_hard_reg_p' that is given an insn_code
730
   number that will have clobbers added (as indicated by `recog') and returns
731
   1 if those include a clobber of a hard reg or 0 if all of them just clobber
732
   SCRATCH.  */
733
 
734
static void
735
output_added_clobbers_hard_reg_p (void)
736
{
737
  struct clobber_pat *clobber;
738
  struct clobber_ent *ent;
739
  int clobber_p, used;
740
 
741
  printf ("\n\nint\nadded_clobbers_hard_reg_p (int insn_code_number)\n");
742
  printf ("{\n");
743
  printf ("  switch (insn_code_number)\n");
744
  printf ("    {\n");
745
 
746
  for (clobber_p = 0; clobber_p <= 1; clobber_p++)
747
    {
748
      used = 0;
749
      for (clobber = clobber_list; clobber; clobber = clobber->next)
750
        if (clobber->has_hard_reg == clobber_p)
751
          for (ent = clobber->insns; ent; ent = ent->next)
752
            {
753
              printf ("    case %d:\n", ent->code_number);
754
              used++;
755
            }
756
 
757
      if (used)
758
        printf ("      return %d;\n\n", clobber_p);
759
    }
760
 
761
  printf ("    default:\n");
762
  printf ("      gcc_unreachable ();\n");
763
  printf ("    }\n");
764
  printf ("}\n");
765
}
766
 
767
/* Generate code to invoke find_free_register () as needed for the
768
   scratch registers used by the peephole2 pattern in SPLIT.  */
769
 
770
static void
771
output_peephole2_scratches (rtx split)
772
{
773
  int i;
774
  int insn_nr = 0;
775
 
776
  printf ("  HARD_REG_SET _regs_allocated;\n");
777
  printf ("  CLEAR_HARD_REG_SET (_regs_allocated);\n");
778
 
779
  for (i = 0; i < XVECLEN (split, 0); i++)
780
    {
781
      rtx elt = XVECEXP (split, 0, i);
782
      if (GET_CODE (elt) == MATCH_SCRATCH)
783
        {
784
          int last_insn_nr = insn_nr;
785
          int cur_insn_nr = insn_nr;
786
          int j;
787
          for (j = i + 1; j < XVECLEN (split, 0); j++)
788
            if (GET_CODE (XVECEXP (split, 0, j)) == MATCH_DUP)
789
              {
790
                if (XINT (XVECEXP (split, 0, j), 0) == XINT (elt, 0))
791
                  last_insn_nr = cur_insn_nr;
792
              }
793
            else if (GET_CODE (XVECEXP (split, 0, j)) != MATCH_SCRATCH)
794
              cur_insn_nr++;
795
 
796
          printf ("  if ((operands[%d] = peep2_find_free_register (%d, %d, \"%s\", %smode, &_regs_allocated)) == NULL_RTX)\n\
797
    return NULL;\n",
798
                  XINT (elt, 0),
799
                  insn_nr, last_insn_nr,
800
                  XSTR (elt, 1),
801
                  GET_MODE_NAME (GET_MODE (elt)));
802
 
803
        }
804
      else if (GET_CODE (elt) != MATCH_DUP)
805
        insn_nr++;
806
    }
807
}
808
 
809
int
810
main (int argc, char **argv)
811
{
812
  rtx desc;
813
 
814
  progname = "genemit";
815
 
816
  if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
817
    return (FATAL_EXIT_CODE);
818
 
819
  /* Assign sequential codes to all entries in the machine description
820
     in parallel with the tables in insn-output.c.  */
821
 
822
  insn_code_number = 0;
823
  insn_index_number = 0;
824
 
825
  printf ("/* Generated automatically by the program `genemit'\n\
826
from the machine description file `md'.  */\n\n");
827
 
828
  printf ("#include \"config.h\"\n");
829
  printf ("#include \"system.h\"\n");
830
  printf ("#include \"coretypes.h\"\n");
831
  printf ("#include \"tm.h\"\n");
832
  printf ("#include \"rtl.h\"\n");
833
  printf ("#include \"tm_p.h\"\n");
834
  printf ("#include \"function.h\"\n");
835
  printf ("#include \"expr.h\"\n");
836
  printf ("#include \"optabs.h\"\n");
837
  printf ("#include \"real.h\"\n");
838
  printf ("#include \"flags.h\"\n");
839
  printf ("#include \"output.h\"\n");
840
  printf ("#include \"insn-config.h\"\n");
841
  printf ("#include \"hard-reg-set.h\"\n");
842
  printf ("#include \"recog.h\"\n");
843
  printf ("#include \"resource.h\"\n");
844
  printf ("#include \"reload.h\"\n");
845
  printf ("#include \"toplev.h\"\n");
846
  printf ("#include \"tm-constrs.h\"\n");
847
  printf ("#include \"ggc.h\"\n\n");
848
  printf ("#include \"basic-block.h\"\n\n");
849
  printf ("#define FAIL return (end_sequence (), _val)\n");
850
  printf ("#define DONE return (_val = get_insns (), end_sequence (), _val)\n\n");
851
 
852
  /* Read the machine description.  */
853
 
854
  while (1)
855
    {
856
      int line_no;
857
 
858
      desc = read_md_rtx (&line_no, &insn_code_number);
859
      if (desc == NULL)
860
        break;
861
 
862
      switch (GET_CODE (desc))
863
        {
864
        case DEFINE_INSN:
865
          gen_insn (desc, line_no);
866
          break;
867
 
868
        case DEFINE_EXPAND:
869
          printf ("/* %s:%d */\n", read_rtx_filename, line_no);
870
          gen_expand (desc);
871
          break;
872
 
873
        case DEFINE_SPLIT:
874
          printf ("/* %s:%d */\n", read_rtx_filename, line_no);
875
          gen_split (desc);
876
          break;
877
 
878
        case DEFINE_PEEPHOLE2:
879
          printf ("/* %s:%d */\n", read_rtx_filename, line_no);
880
          gen_split (desc);
881
          break;
882
 
883
        default:
884
          break;
885
        }
886
      ++insn_index_number;
887
    }
888
 
889
  /* Write out the routines to add CLOBBERs to a pattern and say whether they
890
     clobber a hard reg.  */
891
  output_add_clobbers ();
892
  output_added_clobbers_hard_reg_p ();
893
 
894
  fflush (stdout);
895
  return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
896
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.