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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [genattr.c] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
/* Generate attribute information (insn-attr.h) from machine description.
2
   Copyright (C) 1991, 1994, 1996, 1998, 1999, 2000, 2003, 2004
3
   Free Software Foundation, Inc.
4
   Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5
 
6
This file is part of GCC.
7
 
8
GCC is free software; you can redistribute it and/or modify it under
9
the terms of the GNU General Public License as published by the Free
10
Software Foundation; either version 2, or (at your option) any later
11
version.
12
 
13
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14
WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16
for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with GCC; see the file COPYING.  If not, write to the Free
20
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21
02110-1301, USA.  */
22
 
23
 
24
#include "bconfig.h"
25
#include "system.h"
26
#include "coretypes.h"
27
#include "tm.h"
28
#include "rtl.h"
29
#include "errors.h"
30
#include "gensupport.h"
31
 
32
 
33
static void write_upcase (const char *);
34
static void gen_attr (rtx);
35
 
36
static void
37
write_upcase (const char *str)
38
{
39
  for (; *str; str++)
40
    putchar (TOUPPER(*str));
41
}
42
 
43
static void
44
gen_attr (rtx attr)
45
{
46
  const char *p, *tag;
47
  int is_const = GET_CODE (XEXP (attr, 2)) == CONST;
48
 
49
  printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0));
50
 
51
  /* If numeric attribute, don't need to write an enum.  */
52
  p = XSTR (attr, 1);
53
  if (*p == '\0')
54
    printf ("extern int get_attr_%s (%s);\n", XSTR (attr, 0),
55
            (is_const ? "void" : "rtx"));
56
  else
57
    {
58
      printf ("enum attr_%s {", XSTR (attr, 0));
59
 
60
      while ((tag = scan_comma_elt (&p)) != 0)
61
        {
62
          write_upcase (XSTR (attr, 0));
63
          putchar ('_');
64
          while (tag != p)
65
            putchar (TOUPPER (*tag++));
66
          if (*p == ',')
67
            fputs (", ", stdout);
68
        }
69
 
70
      fputs ("};\n", stdout);
71
      printf ("extern enum attr_%s get_attr_%s (%s);\n\n",
72
              XSTR (attr, 0), XSTR (attr, 0), (is_const ? "void" : "rtx"));
73
    }
74
 
75
  /* If `length' attribute, write additional function definitions and define
76
     variables used by `insn_current_length'.  */
77
  if (! strcmp (XSTR (attr, 0), "length"))
78
    {
79
      puts ("\
80
extern void shorten_branches (rtx);\n\
81
extern int insn_default_length (rtx);\n\
82
extern int insn_min_length (rtx);\n\
83
extern int insn_variable_length_p (rtx);\n\
84
extern int insn_current_length (rtx);\n\n\
85
#include \"insn-addr.h\"\n");
86
    }
87
}
88
 
89
int
90
main (int argc, char **argv)
91
{
92
  rtx desc;
93
  int have_delay = 0;
94
  int have_annul_true = 0;
95
  int have_annul_false = 0;
96
  int num_insn_reservations = 0;
97
  int i;
98
 
99
  progname = "genattr";
100
 
101
  if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
102
    return (FATAL_EXIT_CODE);
103
 
104
  puts ("/* Generated automatically by the program `genattr'");
105
  puts ("   from the machine description file `md'.  */\n");
106
  puts ("#ifndef GCC_INSN_ATTR_H");
107
  puts ("#define GCC_INSN_ATTR_H\n");
108
 
109
  /* For compatibility, define the attribute `alternative', which is just
110
     a reference to the variable `which_alternative'.  */
111
 
112
  puts ("#define HAVE_ATTR_alternative");
113
  puts ("#define get_attr_alternative(insn) which_alternative");
114
 
115
  /* Read the machine description.  */
116
 
117
  while (1)
118
    {
119
      int line_no, insn_code_number;
120
 
121
      desc = read_md_rtx (&line_no, &insn_code_number);
122
      if (desc == NULL)
123
        break;
124
 
125
      if (GET_CODE (desc) == DEFINE_ATTR)
126
        gen_attr (desc);
127
 
128
      else if (GET_CODE (desc) == DEFINE_DELAY)
129
        {
130
          if (! have_delay)
131
            {
132
              printf ("#define DELAY_SLOTS\n");
133
              printf ("extern int num_delay_slots (rtx);\n");
134
              printf ("extern int eligible_for_delay (rtx, int, rtx, int);\n\n");
135
              printf ("extern int const_num_delay_slots (rtx);\n\n");
136
              have_delay = 1;
137
            }
138
 
139
          for (i = 0; i < XVECLEN (desc, 1); i += 3)
140
            {
141
              if (XVECEXP (desc, 1, i + 1) && ! have_annul_true)
142
                {
143
                  printf ("#define ANNUL_IFTRUE_SLOTS\n");
144
                  printf ("extern int eligible_for_annul_true (rtx, int, rtx, int);\n");
145
                  have_annul_true = 1;
146
                }
147
 
148
              if (XVECEXP (desc, 1, i + 2) && ! have_annul_false)
149
                {
150
                  printf ("#define ANNUL_IFFALSE_SLOTS\n");
151
                  printf ("extern int eligible_for_annul_false (rtx, int, rtx, int);\n");
152
                  have_annul_false = 1;
153
                }
154
            }
155
        }
156
 
157
      else if (GET_CODE (desc) == DEFINE_INSN_RESERVATION)
158
        num_insn_reservations++;
159
    }
160
 
161
  if (num_insn_reservations > 0)
162
    {
163
      /* Output interface for pipeline hazards recognition based on
164
         DFA (deterministic finite state automata.  */
165
      printf ("\n#define INSN_SCHEDULING\n");
166
      printf ("\n/* DFA based pipeline interface.  */");
167
      printf ("\n#ifndef AUTOMATON_ALTS\n");
168
      printf ("#define AUTOMATON_ALTS 0\n");
169
      printf ("#endif\n\n");
170
      printf ("\n#ifndef AUTOMATON_STATE_ALTS\n");
171
      printf ("#define AUTOMATON_STATE_ALTS 0\n");
172
      printf ("#endif\n\n");
173
      printf ("#ifndef CPU_UNITS_QUERY\n");
174
      printf ("#define CPU_UNITS_QUERY 0\n");
175
      printf ("#endif\n\n");
176
      /* Interface itself: */
177
      printf ("extern int max_dfa_issue_rate;\n\n");
178
      printf ("/* The following macro value is calculated from the\n");
179
      printf ("   automaton based pipeline description and is equal to\n");
180
      printf ("   maximal number of all insns described in constructions\n");
181
      printf ("   `define_insn_reservation' which can be issued on the\n");
182
      printf ("   same processor cycle. */\n");
183
      printf ("#define MAX_DFA_ISSUE_RATE max_dfa_issue_rate\n\n");
184
      printf ("/* Insn latency time defined in define_insn_reservation. */\n");
185
      printf ("extern int insn_default_latency (rtx);\n\n");
186
      printf ("/* Return nonzero if there is a bypass for given insn\n");
187
      printf ("   which is a data producer.  */\n");
188
      printf ("extern int bypass_p (rtx);\n\n");
189
      printf ("/* Insn latency time on data consumed by the 2nd insn.\n");
190
      printf ("   Use the function if bypass_p returns nonzero for\n");
191
      printf ("   the 1st insn. */\n");
192
      printf ("extern int insn_latency (rtx, rtx);\n\n");
193
      printf ("\n#if AUTOMATON_ALTS\n");
194
      printf ("/* The following function returns number of alternative\n");
195
      printf ("   reservations of given insn.  It may be used for better\n");
196
      printf ("   insns scheduling heuristics. */\n");
197
      printf ("extern int insn_alts (rtx);\n\n");
198
      printf ("#endif\n\n");
199
      printf ("/* Maximal possible number of insns waiting results being\n");
200
      printf ("   produced by insns whose execution is not finished. */\n");
201
      printf ("extern int max_insn_queue_index;\n\n");
202
      printf ("/* Pointer to data describing current state of DFA.  */\n");
203
      printf ("typedef void *state_t;\n\n");
204
      printf ("/* Size of the data in bytes.  */\n");
205
      printf ("extern int state_size (void);\n\n");
206
      printf ("/* Initiate given DFA state, i.e. Set up the state\n");
207
      printf ("   as all functional units were not reserved.  */\n");
208
      printf ("extern void state_reset (state_t);\n");
209
      printf ("/* The following function returns negative value if given\n");
210
      printf ("   insn can be issued in processor state described by given\n");
211
      printf ("   DFA state.  In this case, the DFA state is changed to\n");
212
      printf ("   reflect the current and future reservations by given\n");
213
      printf ("   insn.  Otherwise the function returns minimal time\n");
214
      printf ("   delay to issue the insn.  This delay may be zero\n");
215
      printf ("   for superscalar or VLIW processors.  If the second\n");
216
      printf ("   parameter is NULL the function changes given DFA state\n");
217
      printf ("   as new processor cycle started.  */\n");
218
      printf ("extern int state_transition (state_t, rtx);\n");
219
      printf ("\n#if AUTOMATON_STATE_ALTS\n");
220
      printf ("/* The following function returns number of possible\n");
221
      printf ("   alternative reservations of given insn in given\n");
222
      printf ("   DFA state.  It may be used for better insns scheduling\n");
223
      printf ("   heuristics.  By default the function is defined if\n");
224
      printf ("   macro AUTOMATON_STATE_ALTS is defined because its\n");
225
      printf ("   implementation may require much memory.  */\n");
226
      printf ("extern int state_alts (state_t, rtx);\n");
227
      printf ("#endif\n\n");
228
      printf ("extern int min_issue_delay (state_t, rtx);\n");
229
      printf ("/* The following function returns nonzero if no one insn\n");
230
      printf ("   can be issued in current DFA state. */\n");
231
      printf ("extern int state_dead_lock_p (state_t);\n");
232
      printf ("/* The function returns minimal delay of issue of the 2nd\n");
233
      printf ("   insn after issuing the 1st insn in given DFA state.\n");
234
      printf ("   The 1st insn should be issued in given state (i.e.\n");
235
      printf ("    state_transition should return negative value for\n");
236
      printf ("    the insn and the state).  Data dependencies between\n");
237
      printf ("    the insns are ignored by the function.  */\n");
238
      printf
239
        ("extern int min_insn_conflict_delay (state_t, rtx, rtx);\n");
240
      printf ("/* The following function outputs reservations for given\n");
241
      printf ("   insn as they are described in the corresponding\n");
242
      printf ("   define_insn_reservation.  */\n");
243
      printf ("extern void print_reservation (FILE *, rtx);\n");
244
      printf ("\n#if CPU_UNITS_QUERY\n");
245
      printf ("/* The following function returns code of functional unit\n");
246
      printf ("   with given name (see define_cpu_unit). */\n");
247
      printf ("extern int get_cpu_unit_code (const char *);\n");
248
      printf ("/* The following function returns nonzero if functional\n");
249
      printf ("   unit with given code is currently reserved in given\n");
250
      printf ("   DFA state.  */\n");
251
      printf ("extern int cpu_unit_reservation_p (state_t, int);\n");
252
      printf ("#endif\n\n");
253
      printf ("/* Clean insn code cache.  It should be called if there\n");
254
      printf ("   is a chance that condition value in a\n");
255
      printf ("   define_insn_reservation will be changed after\n");
256
      printf ("   last call of dfa_start.  */\n");
257
      printf ("extern void dfa_clean_insn_cache (void);\n\n");
258
      printf ("/* Initiate and finish work with DFA.  They should be\n");
259
      printf ("   called as the first and the last interface\n");
260
      printf ("   functions.  */\n");
261
      printf ("extern void dfa_start (void);\n");
262
      printf ("extern void dfa_finish (void);\n");
263
    }
264
  else
265
    {
266
      /* Otherwise we do no scheduling, but we need these typedefs
267
         in order to avoid uglifying other code with more ifdefs.  */
268
      printf ("typedef void *state_t;\n\n");
269
    }
270
 
271
  /* Output flag masks for use by reorg.
272
 
273
     Flags are used to hold branch direction and prediction information
274
     for use by eligible_for_...  */
275
  printf("\n#define ATTR_FLAG_forward\t0x1\n");
276
  printf("#define ATTR_FLAG_backward\t0x2\n");
277
  printf("#define ATTR_FLAG_likely\t0x4\n");
278
  printf("#define ATTR_FLAG_very_likely\t0x8\n");
279
  printf("#define ATTR_FLAG_unlikely\t0x10\n");
280
  printf("#define ATTR_FLAG_very_unlikely\t0x20\n");
281
 
282
  puts("\n#endif /* GCC_INSN_ATTR_H */");
283
 
284
  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
285
    return FATAL_EXIT_CODE;
286
 
287
  return SUCCESS_EXIT_CODE;
288
}
289
 
290
/* Define this so we can link with print-rtl.o to get debug_rtx function.  */
291
const char *
292
get_insn_name (int code ATTRIBUTE_UNUSED)
293
{
294
  return NULL;
295
}

powered by: WebSVN 2.1.0

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