00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "hconfig.h"
00024 #include "system.h"
00025 #include "rtl.h"
00026 #include "errors.h"
00027 #include "gensupport.h"
00028
00029
00030
00031
00032 struct range
00033 {
00034 int min;
00035 int max;
00036 };
00037
00038
00039
00040
00041 struct function_unit
00042 {
00043 char *name;
00044 struct function_unit *next;
00045 int multiplicity;
00046 int simultaneity;
00047
00048 struct range ready_cost;
00049 struct range issue_delay;
00050 };
00051
00052 static void extend_range PARAMS ((struct range *, int, int));
00053 static void init_range PARAMS ((struct range *));
00054 static void write_upcase PARAMS ((const char *));
00055 static void gen_attr PARAMS ((rtx));
00056 static void write_units PARAMS ((int, struct range *, struct range *,
00057 struct range *, struct range *,
00058 struct range *));
00059 static void
00060 extend_range (range, min, max)
00061 struct range *range;
00062 int min;
00063 int max;
00064 {
00065 if (range->min > min) range->min = min;
00066 if (range->max < max) range->max = max;
00067 }
00068
00069 static void
00070 init_range (range)
00071 struct range *range;
00072 {
00073 range->min = 100000;
00074 range->max = -1;
00075 }
00076
00077 static void
00078 write_upcase (str)
00079 const char *str;
00080 {
00081 for (; *str; str++)
00082 putchar (TOUPPER(*str));
00083 }
00084
00085 static void
00086 gen_attr (attr)
00087 rtx attr;
00088 {
00089 const char *p, *tag;
00090 int is_const = GET_CODE (XEXP (attr, 2)) == CONST;
00091
00092 printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0));
00093
00094
00095 p = XSTR (attr, 1);
00096 if (*p == '\0')
00097 printf ("extern int get_attr_%s PARAMS ((%s));\n", XSTR (attr, 0),
00098 (is_const ? "void" : "rtx"));
00099 else
00100 {
00101 printf ("enum attr_%s {", XSTR (attr, 0));
00102
00103 while ((tag = scan_comma_elt (&p)) != 0)
00104 {
00105 write_upcase (XSTR (attr, 0));
00106 putchar ('_');
00107 while (tag != p)
00108 putchar (TOUPPER (*tag++));
00109 if (*p == ',')
00110 fputs (", ", stdout);
00111 }
00112
00113 fputs ("};\n", stdout);
00114 printf ("extern enum attr_%s get_attr_%s PARAMS ((%s));\n\n",
00115 XSTR (attr, 0), XSTR (attr, 0), (is_const ? "void" : "rtx"));
00116 }
00117
00118
00119
00120 if (! strcmp (XSTR (attr, 0), "length"))
00121 {
00122 puts ("\
00123 extern void shorten_branches PARAMS ((rtx));\n\
00124 extern int insn_default_length PARAMS ((rtx));\n\
00125 extern int insn_variable_length_p PARAMS ((rtx));\n\
00126 extern int insn_current_length PARAMS ((rtx));\n\n\
00127 #include \"insn-addr.h\"\n");
00128 }
00129 }
00130
00131 static void
00132 write_units (num_units, multiplicity, simultaneity,
00133 ready_cost, issue_delay, blockage)
00134 int num_units;
00135 struct range *multiplicity;
00136 struct range *simultaneity;
00137 struct range *ready_cost;
00138 struct range *issue_delay;
00139 struct range *blockage;
00140 {
00141 int i, q_size;
00142
00143 printf ("#define INSN_SCHEDULING\n\n");
00144 printf ("extern int result_ready_cost PARAMS ((rtx));\n");
00145 printf ("extern int function_units_used PARAMS ((rtx));\n\n");
00146 printf ("extern const struct function_unit_desc\n");
00147 printf ("{\n");
00148 printf (" const char *const name;\n");
00149 printf (" const int bitmask;\n");
00150 printf (" const int multiplicity;\n");
00151 printf (" const int simultaneity;\n");
00152 printf (" const int default_cost;\n");
00153 printf (" const int max_issue_delay;\n");
00154 printf (" int (*const ready_cost_function) PARAMS ((rtx));\n");
00155 printf (" int (*const conflict_cost_function) PARAMS ((rtx, rtx));\n");
00156 printf (" const int max_blockage;\n");
00157 printf (" unsigned int (*const blockage_range_function) PARAMS ((rtx));\n");
00158 printf (" int (*const blockage_function) PARAMS ((rtx, rtx));\n");
00159 printf ("} function_units[];\n\n");
00160 printf ("#define FUNCTION_UNITS_SIZE %d\n", num_units);
00161 printf ("#define MIN_MULTIPLICITY %d\n", multiplicity->min);
00162 printf ("#define MAX_MULTIPLICITY %d\n", multiplicity->max);
00163 printf ("#define MIN_SIMULTANEITY %d\n", simultaneity->min);
00164 printf ("#define MAX_SIMULTANEITY %d\n", simultaneity->max);
00165 printf ("#define MIN_READY_COST %d\n", ready_cost->min);
00166 printf ("#define MAX_READY_COST %d\n", ready_cost->max);
00167 printf ("#define MIN_ISSUE_DELAY %d\n", issue_delay->min);
00168 printf ("#define MAX_ISSUE_DELAY %d\n", issue_delay->max);
00169 printf ("#define MIN_BLOCKAGE %d\n", blockage->min);
00170 printf ("#define MAX_BLOCKAGE %d\n", blockage->max);
00171 for (i = 0; (1 << i) < blockage->max; i++)
00172 ;
00173 printf ("#define BLOCKAGE_BITS %d\n", i + 1);
00174
00175
00176
00177 i = MAX (blockage->max, ready_cost->max);
00178 for (q_size = 1; q_size <= i; q_size <<= 1)
00179 ;
00180 printf ("#define INSN_QUEUE_SIZE %d\n", q_size);
00181 }
00182
00183 extern int main PARAMS ((int, char **));
00184
00185 int
00186 main (argc, argv)
00187 int argc;
00188 char **argv;
00189 {
00190 rtx desc;
00191 int have_delay = 0;
00192 int have_annul_true = 0;
00193 int have_annul_false = 0;
00194 int num_insn_reservations = 0;
00195 int num_units = 0;
00196 struct range all_simultaneity, all_multiplicity;
00197 struct range all_ready_cost, all_issue_delay, all_blockage;
00198 struct function_unit *units = 0, *unit;
00199 int i;
00200
00201 init_range (&all_multiplicity);
00202 init_range (&all_simultaneity);
00203 init_range (&all_ready_cost);
00204 init_range (&all_issue_delay);
00205 init_range (&all_blockage);
00206
00207 progname = "genattr";
00208
00209 if (argc <= 1)
00210 fatal ("no input file name");
00211
00212 if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
00213 return (FATAL_EXIT_CODE);
00214
00215 puts ("/* Generated automatically by the program `genattr'");
00216 puts (" from the machine description file `md'. */\n");
00217 puts ("#ifndef GCC_INSN_ATTR_H");
00218 puts ("#define GCC_INSN_ATTR_H\n");
00219
00220
00221
00222
00223 puts ("#define HAVE_ATTR_alternative");
00224 puts ("#define get_attr_alternative(insn) which_alternative");
00225
00226
00227
00228 while (1)
00229 {
00230 int line_no, insn_code_number;
00231
00232 desc = read_md_rtx (&line_no, &insn_code_number);
00233 if (desc == NULL)
00234 break;
00235
00236 if (GET_CODE (desc) == DEFINE_ATTR)
00237 gen_attr (desc);
00238
00239 else if (GET_CODE (desc) == DEFINE_DELAY)
00240 {
00241 if (! have_delay)
00242 {
00243 printf ("#define DELAY_SLOTS\n");
00244 printf ("extern int num_delay_slots PARAMS ((rtx));\n");
00245 printf ("extern int eligible_for_delay PARAMS ((rtx, int, rtx, int));\n\n");
00246 printf ("extern int const_num_delay_slots PARAMS ((rtx));\n\n");
00247 have_delay = 1;
00248 }
00249
00250 for (i = 0; i < XVECLEN (desc, 1); i += 3)
00251 {
00252 if (XVECEXP (desc, 1, i + 1) && ! have_annul_true)
00253 {
00254 printf ("#define ANNUL_IFTRUE_SLOTS\n");
00255 printf ("extern int eligible_for_annul_true PARAMS ((rtx, int, rtx, int));\n");
00256 have_annul_true = 1;
00257 }
00258
00259 if (XVECEXP (desc, 1, i + 2) && ! have_annul_false)
00260 {
00261 printf ("#define ANNUL_IFFALSE_SLOTS\n");
00262 printf ("extern int eligible_for_annul_false PARAMS ((rtx, int, rtx, int));\n");
00263 have_annul_false = 1;
00264 }
00265 }
00266 }
00267
00268 else if (GET_CODE (desc) == DEFINE_FUNCTION_UNIT)
00269 {
00270 const char *name = XSTR (desc, 0);
00271 int multiplicity = XINT (desc, 1);
00272 int simultaneity = XINT (desc, 2);
00273 int ready_cost = MAX (XINT (desc, 4), 1);
00274 int issue_delay = MAX (XINT (desc, 5), 1);
00275 int issueexp_p = (XVEC (desc, 6) != 0);
00276
00277 for (unit = units; unit; unit = unit->next)
00278 if (strcmp (unit->name, name) == 0)
00279 break;
00280
00281 if (unit == 0)
00282 {
00283 unit = (struct function_unit *)
00284 xmalloc (sizeof (struct function_unit));
00285 unit->name = xstrdup (name);
00286 unit->multiplicity = multiplicity;
00287 unit->simultaneity = simultaneity;
00288 unit->ready_cost.min = unit->ready_cost.max = ready_cost;
00289 unit->issue_delay.min = unit->issue_delay.max = issue_delay;
00290 unit->next = units;
00291 units = unit;
00292 num_units++;
00293
00294 extend_range (&all_multiplicity, multiplicity, multiplicity);
00295 extend_range (&all_simultaneity, simultaneity, simultaneity);
00296 }
00297 else if (unit->multiplicity != multiplicity
00298 || unit->simultaneity != simultaneity)
00299 fatal ("Differing specifications given for `%s' function unit",
00300 unit->name);
00301
00302 extend_range (&unit->ready_cost, ready_cost, ready_cost);
00303 extend_range (&unit->issue_delay,
00304 issueexp_p ? 1 : issue_delay, issue_delay);
00305 extend_range (&all_ready_cost,
00306 unit->ready_cost.min, unit->ready_cost.max);
00307 extend_range (&all_issue_delay,
00308 unit->issue_delay.min, unit->issue_delay.max);
00309 }
00310 else if (GET_CODE (desc) == DEFINE_INSN_RESERVATION)
00311 num_insn_reservations++;
00312 }
00313
00314 if (num_units > 0 || num_insn_reservations > 0)
00315 {
00316 if (num_units > 0)
00317 printf ("#define TRADITIONAL_PIPELINE_INTERFACE 1\n");
00318
00319 if (num_insn_reservations > 0)
00320 printf ("#define DFA_PIPELINE_INTERFACE 1\n");
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 for (unit = units; unit; unit = unit->next)
00335 {
00336 struct range blockage;
00337
00338 blockage = unit->issue_delay;
00339 blockage.max = MAX (unit->ready_cost.max
00340 - (unit->ready_cost.min - 1),
00341 blockage.max);
00342 blockage.min = MAX (1, blockage.min);
00343
00344 if (unit->simultaneity != 0)
00345 {
00346 int fill_time = ((unit->simultaneity - 1)
00347 * unit->issue_delay.min);
00348 blockage.min = MAX (unit->ready_cost.min - fill_time,
00349 blockage.min);
00350 blockage.max = MAX (unit->ready_cost.max - fill_time,
00351 blockage.max);
00352 }
00353 extend_range (&all_blockage, blockage.min, blockage.max);
00354 }
00355
00356 write_units (num_units, &all_multiplicity, &all_simultaneity,
00357 &all_ready_cost, &all_issue_delay, &all_blockage);
00358
00359
00360
00361 printf ("\n/* DFA based pipeline interface. */");
00362 printf ("\n#ifndef AUTOMATON_STATE_ALTS\n");
00363 printf ("#define AUTOMATON_STATE_ALTS 0\n");
00364 printf ("#endif\n\n");
00365 printf ("#ifndef CPU_UNITS_QUERY\n");
00366 printf ("#define CPU_UNITS_QUERY 0\n");
00367 printf ("#endif\n\n");
00368
00369 printf ("extern int max_dfa_issue_rate;\n\n");
00370 printf ("/* The following macro value is calculated from the\n");
00371 printf (" automaton based pipeline description and is equal to\n");
00372 printf (" maximal number of all insns described in constructions\n");
00373 printf (" `define_insn_reservation' which can be issued on the\n");
00374 printf (" same processor cycle. */\n");
00375 printf ("#define MAX_DFA_ISSUE_RATE max_dfa_issue_rate\n\n");
00376 printf ("/* Insn latency time defined in define_insn_reservation. */\n");
00377 printf ("extern int insn_default_latency PARAMS ((rtx));\n\n");
00378 printf ("/* Return nonzero if there is a bypass for given insn\n");
00379 printf (" which is a data producer. */\n");
00380 printf ("extern int bypass_p PARAMS ((rtx));\n\n");
00381 printf ("/* Insn latency time on data consumed by the 2nd insn.\n");
00382 printf (" Use the function if bypass_p returns nonzero for\n");
00383 printf (" the 1st insn. */\n");
00384 printf ("extern int insn_latency PARAMS ((rtx, rtx));\n\n");
00385 printf ("/* The following function returns number of alternative\n");
00386 printf (" reservations of given insn. It may be used for better\n");
00387 printf (" insns scheduling heuristics. */\n");
00388 printf ("extern int insn_alts PARAMS ((rtx));\n\n");
00389 printf ("/* Maximal possible number of insns waiting results being\n");
00390 printf (" produced by insns whose execution is not finished. */\n");
00391 printf ("extern int max_insn_queue_index;\n\n");
00392 printf ("/* Pointer to data describing current state of DFA. */\n");
00393 printf ("typedef void *state_t;\n\n");
00394 printf ("/* Size of the data in bytes. */\n");
00395 printf ("extern int state_size PARAMS ((void));\n\n");
00396 printf ("/* Initiate given DFA state, i.e. Set up the state\n");
00397 printf (" as all functional units were not reserved. */\n");
00398 printf ("extern void state_reset PARAMS ((state_t));\n");
00399 printf ("/* The following function returns negative value if given\n");
00400 printf (" insn can be issued in processor state described by given\n");
00401 printf (" DFA state. In this case, the DFA state is changed to\n");
00402 printf (" reflect the current and future reservations by given\n");
00403 printf (" insn. Otherwise the function returns minimal time\n");
00404 printf (" delay to issue the insn. This delay may be zero\n");
00405 printf (" for superscalar or VLIW processors. If the second\n");
00406 printf (" parameter is NULL the function changes given DFA state\n");
00407 printf (" as new processor cycle started. */\n");
00408 printf ("extern int state_transition PARAMS ((state_t, rtx));\n");
00409 printf ("\n#if AUTOMATON_STATE_ALTS\n");
00410 printf ("/* The following function returns number of possible\n");
00411 printf (" alternative reservations of given insn in given\n");
00412 printf (" DFA state. It may be used for better insns scheduling\n");
00413 printf (" heuristics. By default the function is defined if\n");
00414 printf (" macro AUTOMATON_STATE_ALTS is defined because its\n");
00415 printf (" implementation may require much memory. */\n");
00416 printf ("extern int state_alts PARAMS ((state_t, rtx));\n");
00417 printf ("#endif\n\n");
00418 printf ("extern int min_issue_delay PARAMS ((state_t, rtx));\n");
00419 printf ("/* The following function returns nonzero if no one insn\n");
00420 printf (" can be issued in current DFA state. */\n");
00421 printf ("extern int state_dead_lock_p PARAMS ((state_t));\n");
00422 printf ("/* The function returns minimal delay of issue of the 2nd\n");
00423 printf (" insn after issuing the 1st insn in given DFA state.\n");
00424 printf (" The 1st insn should be issued in given state (i.e.\n");
00425 printf (" state_transition should return negative value for\n");
00426 printf (" the insn and the state). Data dependencies between\n");
00427 printf (" the insns are ignored by the function. */\n");
00428 printf
00429 ("extern int min_insn_conflict_delay PARAMS ((state_t, rtx, rtx));\n");
00430 printf ("/* The following function outputs reservations for given\n");
00431 printf (" insn as they are described in the corresponding\n");
00432 printf (" define_insn_reservation. */\n");
00433 printf ("extern void print_reservation PARAMS ((FILE *, rtx));\n");
00434 printf ("\n#if CPU_UNITS_QUERY\n");
00435 printf ("/* The following function returns code of functional unit\n");
00436 printf (" with given name (see define_cpu_unit). */\n");
00437 printf ("extern int get_cpu_unit_code PARAMS ((const char *));\n");
00438 printf ("/* The following function returns nonzero if functional\n");
00439 printf (" unit with given code is currently reserved in given\n");
00440 printf (" DFA state. */\n");
00441 printf ("extern int cpu_unit_reservation_p PARAMS ((state_t, int));\n");
00442 printf ("#endif\n\n");
00443 printf ("/* Initiate and finish work with DFA. They should be\n");
00444 printf (" called as the first and the last interface\n");
00445 printf (" functions. */\n");
00446 printf ("extern void dfa_start PARAMS ((void));\n");
00447 printf ("extern void dfa_finish PARAMS ((void));\n");
00448 }
00449 else
00450 {
00451
00452
00453 printf ("typedef void *state_t;\n\n");
00454 }
00455
00456
00457
00458
00459
00460 printf("\n#define ATTR_FLAG_forward\t0x1\n");
00461 printf("#define ATTR_FLAG_backward\t0x2\n");
00462 printf("#define ATTR_FLAG_likely\t0x4\n");
00463 printf("#define ATTR_FLAG_very_likely\t0x8\n");
00464 printf("#define ATTR_FLAG_unlikely\t0x10\n");
00465 printf("#define ATTR_FLAG_very_unlikely\t0x20\n");
00466
00467 puts("\n#endif /* GCC_INSN_ATTR_H */");
00468
00469 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
00470 return FATAL_EXIT_CODE;
00471
00472 return SUCCESS_EXIT_CODE;
00473 }
00474
00475
00476 const char *
00477 get_insn_name (code)
00478 int code ATTRIBUTE_UNUSED;
00479 {
00480 return NULL;
00481 }