1 /* Generate code from machine description to compute values of attributes.
2 Copyright (C) 1991-2018 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5 This file is part of GCC.
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
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
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/>. */
21 /* This program handles insn attributes and the DEFINE_DELAY and
22 DEFINE_INSN_RESERVATION definitions.
24 It produces a series of functions named `get_attr_...', one for each insn
25 attribute. Each of these is given the rtx for an insn and returns a member
26 of the enum for the attribute.
28 These subroutines have the form of a `switch' on the INSN_CODE (via
29 `recog_memoized'). Each case either returns a constant attribute value
30 or a value that depends on tests on other attributes, the form of
31 operands, or some random C expression (encoded with a SYMBOL_REF
34 If the attribute `alternative', or a random C expression is present,
35 `constrain_operands' is called. If either of these cases of a reference to
36 an operand is found, `extract_insn' is called.
38 The special attribute `length' is also recognized. For this operand,
39 expressions involving the address of an operand or the current insn,
40 (address (pc)), are valid. In this case, an initial pass is made to
41 set all lengths that do not depend on address. Those that do are set to
42 the maximum length. Then each insn that depends on an address is checked
43 and possibly has its length changed. The process repeats until no further
44 changed are made. The resulting lengths are saved for use by
47 A special form of DEFINE_ATTR, where the expression for default value is a
48 CONST expression, indicates an attribute that is constant for a given run
49 of the compiler. The subroutine generated for these attributes has no
50 parameters as it does not depend on any particular insn. Constant
51 attributes are typically used to specify which variety of processor is
54 Internal attributes are defined to handle DEFINE_DELAY and
55 DEFINE_INSN_RESERVATION. Special routines are output for these cases.
57 This program works by keeping a list of possible values for each attribute.
58 These include the basic attribute choices, default values for attribute, and
59 all derived quantities.
61 As the description file is read, the definition for each insn is saved in a
62 `struct insn_def'. When the file reading is complete, a `struct insn_ent'
63 is created for each insn and chained to the corresponding attribute value,
64 either that specified, or the default.
66 An optimization phase is then run. This simplifies expressions for each
67 insn. EQ_ATTR tests are resolved, whenever possible, to a test that
68 indicates when the attribute has the specified value for the insn. This
69 avoids recursive calls during compilation.
71 The strategy used when processing DEFINE_DELAY definitions is to create
72 arbitrarily complex expressions and have the optimization simplify them.
74 Once optimization is complete, any required routines and definitions
77 An optimization that is not yet implemented is to hoist the constant
78 expressions entirely out of the routines and definitions that are written.
79 A way to do this is to iterate over all possible combinations of values
80 for constant attributes and generate a set of functions for that given
81 combination. An initialization function would be written that evaluates
82 the attributes and installs the corresponding set of routines and
83 definitions (each would be accessed through a pointer).
85 We use the flags in an RTX as follows:
86 `unchanging' (ATTR_IND_SIMPLIFIED_P): This rtx is fully simplified
87 independent of the insn code.
88 `in_struct' (ATTR_CURR_SIMPLIFIED_P): This rtx is fully simplified
89 for the insn code currently being processed (see optimize_attrs).
90 `return_val' (ATTR_PERMANENT_P): This rtx is permanent and unique
93 #define ATTR_IND_SIMPLIFIED_P(RTX) (RTX_FLAG ((RTX), unchanging))
94 #define ATTR_CURR_SIMPLIFIED_P(RTX) (RTX_FLAG ((RTX), in_struct))
95 #define ATTR_PERMANENT_P(RTX) (RTX_FLAG ((RTX), return_val))
98 #define strcmp_check(S1, S2) ((S1) == (S2) \
100 : (gcc_assert (strcmp ((S1), (S2))), 1))
102 #define strcmp_check(S1, S2) ((S1) != (S2))
107 #include "coretypes.h"
113 #include "gensupport.h"
118 /* Flags for make_internal_attr's `special' parameter. */
120 #define ATTR_SPECIAL (1 << 0)
122 static struct obstack obstack1
, obstack2
;
123 static struct obstack
*hash_obstack
= &obstack1
;
124 static struct obstack
*temp_obstack
= &obstack2
;
126 /* enough space to reserve for printing out ints */
127 #define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
129 /* Define structures used to record attributes and values. */
131 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
132 encountered, we store all the relevant information into a
133 `struct insn_def'. This is done to allow attribute definitions to occur
134 anywhere in the file. */
138 struct insn_def
*next
; /* Next insn in chain. */
139 rtx def
; /* The DEFINE_... */
140 int insn_code
; /* Instruction number. */
141 int insn_index
; /* Expression number in file, for errors. */
142 file_location loc
; /* Where in the .md files it occurs. */
143 int num_alternatives
; /* Number of alternatives. */
144 int vec_idx
; /* Index of attribute vector in `def'. */
147 /* Once everything has been read in, we store in each attribute value a list
148 of insn codes that have that value. Here is the structure used for the
153 struct insn_ent
*next
; /* Next in chain. */
154 struct insn_def
*def
; /* Instruction definition. */
157 /* Each value of an attribute (either constant or computed) is assigned a
158 structure which is used as the listhead of the insns that have that
163 rtx value
; /* Value of attribute. */
164 struct attr_value
*next
; /* Next attribute value in chain. */
165 struct insn_ent
*first_insn
; /* First insn with this value. */
166 int num_insns
; /* Number of insns with this value. */
167 int has_asm_insn
; /* True if this value used for `asm' insns */
170 /* Structure for each attribute. */
174 char *name
; /* Name of attribute. */
175 const char *enum_name
; /* Enum name for DEFINE_ENUM_NAME. */
176 struct attr_desc
*next
; /* Next attribute. */
177 struct attr_value
*first_value
; /* First value of this attribute. */
178 struct attr_value
*default_val
; /* Default value for this attribute. */
179 file_location loc
; /* Where in the .md files it occurs. */
180 unsigned is_numeric
: 1; /* Values of this attribute are numeric. */
181 unsigned is_const
: 1; /* Attribute value constant for each run. */
182 unsigned is_special
: 1; /* Don't call `write_attr_set'. */
185 /* Structure for each DEFINE_DELAY. */
189 rtx def
; /* DEFINE_DELAY expression. */
190 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
191 file_location loc
; /* Where in the .md files it occurs. */
192 int num
; /* Number of DEFINE_DELAY, starting at 1. */
195 struct attr_value_list
197 struct attr_value
*av
;
199 struct attr_desc
*attr
;
200 struct attr_value_list
*next
;
203 /* Listheads of above structures. */
205 /* This one is indexed by the first character of the attribute name. */
206 #define MAX_ATTRS_INDEX 256
207 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
208 static struct insn_def
*defs
;
209 static struct delay_desc
*delays
;
210 struct attr_value_list
**insn_code_values
;
212 /* Other variables. */
214 static int insn_index_number
;
215 static int got_define_asm_attributes
;
216 static int must_extract
;
217 static int must_constrain
;
218 static int address_used
;
219 static int length_used
;
220 static int num_delays
;
221 static int have_annul_true
, have_annul_false
;
222 static int num_insn_ents
;
224 /* Stores, for each insn code, the number of constraint alternatives. */
226 static int *insn_n_alternatives
;
228 /* Stores, for each insn code, a bitmap that has bits on for each possible
231 static uint64_t *insn_alternatives
;
233 /* Used to simplify expressions. */
235 static rtx true_rtx
, false_rtx
;
237 /* Used to reduce calls to `strcmp' */
239 static const char *alternative_name
;
240 static const char *length_str
;
241 static const char *delay_type_str
;
242 static const char *delay_1_0_str
;
243 static const char *num_delay_slots_str
;
245 /* Simplify an expression. Only call the routine if there is something to
247 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
248 (ATTR_IND_SIMPLIFIED_P (EXP) || ATTR_CURR_SIMPLIFIED_P (EXP) ? (EXP) \
249 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
251 #define DEF_ATTR_STRING(S) (attr_string ((S), strlen (S)))
253 /* Forward declarations of functions used before their definitions, only. */
254 static char *attr_string (const char *, int);
255 static char *attr_printf (unsigned int, const char *, ...)
257 static rtx
make_numeric_value (int);
258 static struct attr_desc
*find_attr (const char **, int);
259 static rtx
mk_attr_alt (uint64_t);
260 static char *next_comma_elt (const char **);
261 static rtx
insert_right_side (enum rtx_code
, rtx
, rtx
, int, int);
262 static rtx
copy_boolean (rtx
);
263 static int compares_alternatives_p (rtx
);
264 static void make_internal_attr (const char *, rtx
, int);
265 static void insert_insn_ent (struct attr_value
*, struct insn_ent
*);
266 static void walk_attr_value (rtx
);
267 static int max_attr_value (rtx
, int*);
268 static int min_attr_value (rtx
, int*);
269 static int or_attr_value (rtx
, int*);
270 static rtx
simplify_test_exp (rtx
, int, int);
271 static rtx
simplify_test_exp_in_temp (rtx
, int, int);
272 static rtx
copy_rtx_unchanging (rtx
);
273 static bool attr_alt_subset_p (rtx
, rtx
);
274 static bool attr_alt_subset_of_compl_p (rtx
, rtx
);
275 static void clear_struct_flag (rtx
);
276 static void write_attr_valueq (FILE *, struct attr_desc
*, const char *);
277 static struct attr_value
*find_most_used (struct attr_desc
*);
278 static void write_attr_set (FILE *, struct attr_desc
*, int, rtx
,
279 const char *, const char *, rtx
,
280 int, int, unsigned int);
281 static void write_attr_case (FILE *, struct attr_desc
*,
283 int, const char *, const char *, int, rtx
);
284 static void write_attr_value (FILE *, struct attr_desc
*, rtx
);
285 static void write_upcase (FILE *, const char *);
286 static void write_indent (FILE *, int);
287 static rtx
identity_fn (rtx
);
288 static rtx
zero_fn (rtx
);
289 static rtx
one_fn (rtx
);
290 static rtx
max_fn (rtx
);
291 static rtx
min_fn (rtx
);
293 #define oballoc(T) XOBNEW (hash_obstack, T)
294 #define oballocvec(T, N) XOBNEWVEC (hash_obstack, T, (N))
296 /* This gen* file is unique, in that it writes out multiple files.
298 Before GCC 4.8, insn-attrtab.c was written out containing many large
299 functions and tables. This made insn-attrtab.c _the_ bottle-neck in
300 a parallel build, and even made it impossible to build GCC on machines
301 with relatively small RAM space (PR other/29442). Therefore, the
302 atrribute functions/tables are now written out to three separate
303 files: all "*insn_default_latency" functions go to LATENCY_FILE_NAME,
304 all "*internal_dfa_insn_code" functions go to DFA_FILE_NAME, and the
305 rest goes to ATTR_FILE_NAME. */
307 static const char *attr_file_name
= NULL
;
308 static const char *dfa_file_name
= NULL
;
309 static const char *latency_file_name
= NULL
;
311 static FILE *attr_file
, *dfa_file
, *latency_file
;
313 /* Hash table for sharing RTL and strings. */
315 /* Each hash table slot is a bucket containing a chain of these structures.
316 Strings are given negative hash codes; RTL expressions are given positive
321 struct attr_hash
*next
; /* Next structure in the bucket. */
322 unsigned int hashcode
; /* Hash code of this rtx or string. */
325 char *str
; /* The string (negative hash codes) */
326 rtx rtl
; /* or the RTL recorded here. */
330 /* Now here is the hash table. When recording an RTL, it is added to
331 the slot whose index is the hash code mod the table size. Note
332 that the hash table is used for several kinds of RTL (see attr_rtx)
333 and for strings. While all these live in the same table, they are
334 completely independent, and the hash code is computed differently
337 #define RTL_HASH_SIZE 4093
338 static struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
340 /* Here is how primitive or already-shared RTL's hash
342 #define RTL_HASH(RTL) ((intptr_t) (RTL) & 0777777)
344 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
347 attr_hash_add_rtx (unsigned int hashcode
, rtx rtl
)
351 h
= XOBNEW (hash_obstack
, struct attr_hash
);
352 h
->hashcode
= hashcode
;
354 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
355 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
358 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
361 attr_hash_add_string (unsigned int hashcode
, char *str
)
365 h
= XOBNEW (hash_obstack
, struct attr_hash
);
366 h
->hashcode
= -hashcode
;
368 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
369 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
372 /* Generate an RTL expression, but avoid duplicates.
373 Set the ATTR_PERMANENT_P flag for these permanent objects.
375 In some cases we cannot uniquify; then we return an ordinary
376 impermanent rtx with ATTR_PERMANENT_P clear.
380 rtx attr_rtx (code, [element1, ..., elementn]) */
383 attr_rtx_1 (enum rtx_code code
, va_list p
)
385 rtx rt_val
= NULL_RTX
;/* RTX to return to caller... */
386 unsigned int hashcode
;
388 struct obstack
*old_obstack
= rtl_obstack
;
391 /* For each of several cases, search the hash table for an existing entry.
392 Use that entry if one is found; otherwise create a new RTL and add it
395 if (GET_RTX_CLASS (code
) == RTX_UNARY
)
397 rtx arg0
= va_arg (p
, rtx
);
399 if (! ATTR_PERMANENT_P (arg0
))
402 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
403 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
404 if (h
->hashcode
== hashcode
405 && GET_CODE (h
->u
.rtl
) == code
406 && XEXP (h
->u
.rtl
, 0) == arg0
)
411 rtl_obstack
= hash_obstack
;
412 rt_val
= rtx_alloc (code
);
413 XEXP (rt_val
, 0) = arg0
;
416 else if (GET_RTX_CLASS (code
) == RTX_BIN_ARITH
417 || GET_RTX_CLASS (code
) == RTX_COMM_ARITH
418 || GET_RTX_CLASS (code
) == RTX_COMPARE
419 || GET_RTX_CLASS (code
) == RTX_COMM_COMPARE
)
421 rtx arg0
= va_arg (p
, rtx
);
422 rtx arg1
= va_arg (p
, rtx
);
424 if (! ATTR_PERMANENT_P (arg0
) || ! ATTR_PERMANENT_P (arg1
))
427 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
428 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
429 if (h
->hashcode
== hashcode
430 && GET_CODE (h
->u
.rtl
) == code
431 && XEXP (h
->u
.rtl
, 0) == arg0
432 && XEXP (h
->u
.rtl
, 1) == arg1
)
434 ATTR_CURR_SIMPLIFIED_P (h
->u
.rtl
) = 0;
440 rtl_obstack
= hash_obstack
;
441 rt_val
= rtx_alloc (code
);
442 XEXP (rt_val
, 0) = arg0
;
443 XEXP (rt_val
, 1) = arg1
;
446 else if (code
== SYMBOL_REF
447 || (GET_RTX_LENGTH (code
) == 1
448 && GET_RTX_FORMAT (code
)[0] == 's'))
450 char *arg0
= va_arg (p
, char *);
452 arg0
= DEF_ATTR_STRING (arg0
);
454 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
455 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
456 if (h
->hashcode
== hashcode
457 && GET_CODE (h
->u
.rtl
) == code
458 && XSTR (h
->u
.rtl
, 0) == arg0
)
463 rtl_obstack
= hash_obstack
;
464 rt_val
= rtx_alloc (code
);
465 XSTR (rt_val
, 0) = arg0
;
466 if (code
== SYMBOL_REF
)
467 X0EXP (rt_val
, 1) = NULL_RTX
;
470 else if (GET_RTX_LENGTH (code
) == 2
471 && GET_RTX_FORMAT (code
)[0] == 's'
472 && GET_RTX_FORMAT (code
)[1] == 's')
474 char *arg0
= va_arg (p
, char *);
475 char *arg1
= va_arg (p
, char *);
477 arg0
= DEF_ATTR_STRING (arg0
);
478 arg1
= DEF_ATTR_STRING (arg1
);
480 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
481 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
482 if (h
->hashcode
== hashcode
483 && GET_CODE (h
->u
.rtl
) == code
484 && XSTR (h
->u
.rtl
, 0) == arg0
485 && XSTR (h
->u
.rtl
, 1) == arg1
)
490 rtl_obstack
= hash_obstack
;
491 rt_val
= rtx_alloc (code
);
492 XSTR (rt_val
, 0) = arg0
;
493 XSTR (rt_val
, 1) = arg1
;
496 else if (GET_RTX_LENGTH (code
) == 2
497 && GET_RTX_FORMAT (code
)[0] == 'i'
498 && GET_RTX_FORMAT (code
)[1] == 'i')
500 int arg0
= va_arg (p
, int);
501 int arg1
= va_arg (p
, int);
503 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
504 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
505 if (h
->hashcode
== hashcode
506 && GET_CODE (h
->u
.rtl
) == code
507 && XINT (h
->u
.rtl
, 0) == arg0
508 && XINT (h
->u
.rtl
, 1) == arg1
)
513 rtl_obstack
= hash_obstack
;
514 rt_val
= rtx_alloc (code
);
515 XINT (rt_val
, 0) = arg0
;
516 XINT (rt_val
, 1) = arg1
;
519 else if (code
== CONST_INT
)
521 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
531 int i
; /* Array indices... */
532 const char *fmt
; /* Current rtx's format... */
534 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
536 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
537 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
541 case '0': /* Unused field. */
544 case 'i': /* An integer? */
545 XINT (rt_val
, i
) = va_arg (p
, int);
548 case 'w': /* A wide integer? */
549 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
552 case 's': /* A string? */
553 XSTR (rt_val
, i
) = va_arg (p
, char *);
556 case 'e': /* An expression? */
557 case 'u': /* An insn? Same except when printing. */
558 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
561 case 'E': /* An RTX vector? */
562 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
566 /* Don't need to handle 'p' for attributes. */
573 rtl_obstack
= old_obstack
;
574 attr_hash_add_rtx (hashcode
, rt_val
);
575 ATTR_PERMANENT_P (rt_val
) = permanent_p
;
580 attr_rtx (enum rtx_code code
, ...)
586 result
= attr_rtx_1 (code
, p
);
591 /* Create a new string printed with the printf line arguments into a space
592 of at most LEN bytes:
594 rtx attr_printf (len, format, [arg1, ..., argn]) */
597 attr_printf (unsigned int len
, const char *fmt
, ...)
604 gcc_assert (len
< sizeof str
); /* Leave room for \0. */
606 vsprintf (str
, fmt
, p
);
609 return DEF_ATTR_STRING (str
);
613 attr_eq (const char *name
, const char *value
)
615 return attr_rtx (EQ_ATTR
, name
, value
);
621 return XSTR (make_numeric_value (n
), 0);
624 /* Return a permanent (possibly shared) copy of a string STR (not assumed
625 to be null terminated) with LEN bytes. */
628 attr_string (const char *str
, int len
)
631 unsigned int hashcode
;
635 /* Compute the hash code. */
636 hashcode
= (len
+ 1) * 613U + (unsigned) str
[0];
637 for (i
= 1; i
< len
; i
+= 2)
638 hashcode
= ((hashcode
* 613) + (unsigned) str
[i
]);
639 if ((int) hashcode
< 0)
640 hashcode
= -hashcode
;
642 /* Search the table for the string. */
643 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
644 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
645 && !strncmp (h
->u
.str
, str
, len
))
646 return h
->u
.str
; /* <-- return if found. */
648 /* Not found; create a permanent copy and add it to the hash table. */
649 new_str
= XOBNEWVAR (hash_obstack
, char, len
+ 1);
650 memcpy (new_str
, str
, len
);
652 attr_hash_add_string (hashcode
, new_str
);
653 rtx_reader_ptr
->copy_md_ptr_loc (new_str
, str
);
655 return new_str
; /* Return the new string. */
658 /* Check two rtx's for equality of contents,
659 taking advantage of the fact that if both are hashed
660 then they can't be equal unless they are the same object. */
663 attr_equal_p (rtx x
, rtx y
)
665 return (x
== y
|| (! (ATTR_PERMANENT_P (x
) && ATTR_PERMANENT_P (y
))
666 && rtx_equal_p (x
, y
)));
669 /* Given a test expression EXP for attribute ATTR, ensure it is validly
670 formed. LOC is the location of the .md construct that contains EXP.
672 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
673 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
674 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
676 Update the string address in EQ_ATTR expression to be the same used
677 in the attribute (or `alternative_name') to speed up subsequent
678 `find_attr' calls and eliminate most `strcmp' calls.
680 Return the new expression, if any. */
683 check_attr_test (file_location loc
, rtx exp
, attr_desc
*attr
)
685 struct attr_value
*av
;
686 const char *name_ptr
, *p
;
689 switch (GET_CODE (exp
))
692 /* Handle negation test. */
693 if (XSTR (exp
, 1)[0] == '!')
694 return check_attr_test (loc
,
696 attr_eq (XSTR (exp
, 0),
700 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
702 attr_desc
*attr2
= find_attr (&XSTR (exp
, 0), 0);
705 if (! strcmp (XSTR (exp
, 0), "alternative"))
706 return mk_attr_alt (((uint64_t) 1) << atoi (XSTR (exp
, 1)));
708 fatal_at (loc
, "unknown attribute `%s' in definition of"
709 " attribute `%s'", XSTR (exp
, 0), attr
->name
);
712 if (attr
->is_const
&& ! attr2
->is_const
)
713 fatal_at (loc
, "constant attribute `%s' cannot test non-constant"
714 " attribute `%s'", attr
->name
, attr2
->name
);
716 /* Copy this just to make it permanent,
717 so expressions using it can be permanent too. */
718 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
720 /* It shouldn't be possible to simplify the value given to a
721 constant attribute, so don't expand this until it's time to
722 write the test expression. */
724 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
726 if (attr2
->is_numeric
)
728 for (p
= XSTR (exp
, 1); *p
; p
++)
730 fatal_at (loc
, "attribute `%s' takes only numeric values",
735 for (av
= attr2
->first_value
; av
; av
= av
->next
)
736 if (GET_CODE (av
->value
) == CONST_STRING
737 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
741 fatal_at (loc
, "unknown value `%s' for attribute `%s'",
742 XSTR (exp
, 1), attr2
->name
);
747 if (! strcmp (XSTR (exp
, 0), "alternative"))
751 name_ptr
= XSTR (exp
, 1);
752 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
753 set
|= ((uint64_t) 1) << atoi (p
);
755 return mk_attr_alt (set
);
759 /* Make an IOR tree of the possible values. */
761 name_ptr
= XSTR (exp
, 1);
762 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
764 newexp
= attr_eq (XSTR (exp
, 0), p
);
765 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
768 return check_attr_test (loc
, orexp
, attr
);
777 /* Either TRUE or FALSE. */
785 XEXP (exp
, 0) = check_attr_test (loc
, XEXP (exp
, 0), attr
);
786 XEXP (exp
, 1) = check_attr_test (loc
, XEXP (exp
, 1), attr
);
790 XEXP (exp
, 0) = check_attr_test (loc
, XEXP (exp
, 0), attr
);
794 exp
= attr_rtx (MATCH_TEST
, XSTR (exp
, 0));
795 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
800 fatal_at (loc
, "invalid operator `%s' in definition of constant"
801 " attribute `%s'", GET_RTX_NAME (GET_CODE (exp
)),
803 /* These cases can't be simplified. */
804 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
807 case LE
: case LT
: case GT
: case GE
:
808 case LEU
: case LTU
: case GTU
: case GEU
:
810 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
811 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
812 exp
= attr_rtx (GET_CODE (exp
),
813 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
814 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
815 /* These cases can't be simplified. */
816 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
822 /* These cases are valid for constant attributes, but can't be
824 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
825 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
830 fatal_at (loc
, "invalid operator `%s' in definition of attribute"
831 " `%s'", GET_RTX_NAME (GET_CODE (exp
)), attr
->name
);
837 /* Given an expression EXP, ensure that it is validly formed and that
838 all named attribute values are valid for ATTR. Issue an error if not.
839 LOC is the location of the .md construct that contains EXP.
841 Return a perhaps modified replacement expression for the value. */
844 check_attr_value (file_location loc
, rtx exp
, struct attr_desc
*attr
)
846 struct attr_value
*av
;
850 switch (GET_CODE (exp
))
853 if (!attr
->is_numeric
)
856 "CONST_INT not valid for non-numeric attribute `%s'",
861 if (INTVAL (exp
) < 0)
864 "negative numeric value specified for attribute `%s'",
871 if (! strcmp (XSTR (exp
, 0), "*"))
874 if (attr
->is_numeric
)
881 "non-numeric value specified for numeric"
882 " attribute `%s'", attr
->name
);
888 for (av
= attr
->first_value
; av
; av
= av
->next
)
889 if (GET_CODE (av
->value
) == CONST_STRING
890 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
894 error_at (loc
, "unknown value `%s' for attribute `%s'",
895 XSTR (exp
, 0), attr
->name
);
899 XEXP (exp
, 0) = check_attr_test (loc
, XEXP (exp
, 0), attr
);
900 XEXP (exp
, 1) = check_attr_value (loc
, XEXP (exp
, 1), attr
);
901 XEXP (exp
, 2) = check_attr_value (loc
, XEXP (exp
, 2), attr
);
909 if (!attr
->is_numeric
)
911 error_at (loc
, "invalid operation `%s' for non-numeric"
912 " attribute `%s'", GET_RTX_NAME (GET_CODE (exp
)),
920 XEXP (exp
, 0) = check_attr_value (loc
, XEXP (exp
, 0), attr
);
921 XEXP (exp
, 1) = check_attr_value (loc
, XEXP (exp
, 1), attr
);
930 XEXP (exp
, 0) = check_attr_value (loc
, XEXP (exp
, 0), attr
);
934 if (XVECLEN (exp
, 0) % 2 != 0)
936 error_at (loc
, "first operand of COND must have even length");
940 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
942 XVECEXP (exp
, 0, i
) = check_attr_test (attr
->loc
,
945 XVECEXP (exp
, 0, i
+ 1)
946 = check_attr_value (loc
, XVECEXP (exp
, 0, i
+ 1), attr
);
949 XEXP (exp
, 1) = check_attr_value (loc
, XEXP (exp
, 1), attr
);
954 struct attr_desc
*attr2
= find_attr (&XSTR (exp
, 0), 0);
956 error_at (loc
, "unknown attribute `%s' in ATTR",
958 else if (attr
->is_const
&& ! attr2
->is_const
)
960 "constant attribute `%s' cannot refer to non-constant"
961 " attribute `%s'", attr
->name
, attr2
->name
);
962 else if (attr
->is_numeric
!= attr2
->is_numeric
)
964 "numeric attribute mismatch calling `%s' from `%s'",
965 attr2
->name
, attr
->name
);
970 /* A constant SYMBOL_REF is valid as a constant attribute test and
971 is expanded later by make_canonical into a COND. In a non-constant
972 attribute test, it is left be. */
973 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
976 error_at (loc
, "invalid operator `%s' in definition of attribute `%s'",
977 GET_RTX_NAME (GET_CODE (exp
)), attr
->name
);
984 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
985 It becomes a COND with each test being (eq_attr "alternative" "n") */
988 convert_set_attr_alternative (rtx exp
, struct insn_def
*id
)
990 int num_alt
= id
->num_alternatives
;
994 if (XVECLEN (exp
, 1) != num_alt
)
996 error_at (id
->loc
, "bad number of entries in SET_ATTR_ALTERNATIVE,"
997 " was %d expected %d", XVECLEN (exp
, 1), num_alt
);
1001 /* Make a COND with all tests but the last. Select the last value via the
1003 condexp
= rtx_alloc (COND
);
1004 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1006 for (i
= 0; i
< num_alt
- 1; i
++)
1009 p
= attr_numeral (i
);
1011 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1012 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1015 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1017 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1020 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1021 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1024 convert_set_attr (rtx exp
, struct insn_def
*id
)
1027 const char *name_ptr
;
1031 /* See how many alternative specified. */
1032 n
= n_comma_elts (XSTR (exp
, 1));
1034 return attr_rtx (SET
,
1035 attr_rtx (ATTR
, XSTR (exp
, 0)),
1036 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1038 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1039 XSTR (newexp
, 0) = XSTR (exp
, 0);
1040 XVEC (newexp
, 1) = rtvec_alloc (n
);
1042 /* Process each comma-separated name. */
1043 name_ptr
= XSTR (exp
, 1);
1045 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1046 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1048 return convert_set_attr_alternative (newexp
, id
);
1051 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1052 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1058 struct insn_def
*id
;
1059 struct attr_desc
*attr
;
1063 for (id
= defs
; id
; id
= id
->next
)
1065 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1068 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1070 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1071 switch (GET_CODE (value
))
1074 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1076 error_at (id
->loc
, "bad attribute set");
1081 case SET_ATTR_ALTERNATIVE
:
1082 value
= convert_set_attr_alternative (value
, id
);
1086 value
= convert_set_attr (value
, id
);
1090 error_at (id
->loc
, "invalid attribute code %s",
1091 GET_RTX_NAME (GET_CODE (value
)));
1094 if (value
== NULL_RTX
)
1097 if ((attr
= find_attr (&XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1099 error_at (id
->loc
, "unknown attribute %s",
1100 XSTR (XEXP (value
, 0), 0));
1104 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1105 XEXP (value
, 1) = check_attr_value (id
->loc
, XEXP (value
, 1), attr
);
1110 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1111 expressions by converting them into a COND. This removes cases from this
1112 program. Also, replace an attribute value of "*" with the default attribute
1113 value. LOC is the location to use for error reporting. */
1116 make_canonical (file_location loc
, struct attr_desc
*attr
, rtx exp
)
1121 switch (GET_CODE (exp
))
1124 exp
= make_numeric_value (INTVAL (exp
));
1128 if (! strcmp (XSTR (exp
, 0), "*"))
1130 if (attr
->default_val
== 0)
1131 fatal_at (loc
, "(attr_value \"*\") used in invalid context");
1132 exp
= attr
->default_val
->value
;
1135 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1140 if (!attr
->is_const
|| ATTR_IND_SIMPLIFIED_P (exp
))
1142 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1143 This makes the COND something that won't be considered an arbitrary
1144 expression by walk_attr_value. */
1145 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1146 exp
= check_attr_value (loc
, exp
, attr
);
1150 newexp
= rtx_alloc (COND
);
1151 XVEC (newexp
, 0) = rtvec_alloc (2);
1152 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1153 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1155 XEXP (newexp
, 1) = XEXP (exp
, 2);
1158 /* Fall through to COND case since this is now a COND. */
1166 /* First, check for degenerate COND. */
1167 if (XVECLEN (exp
, 0) == 0)
1168 return make_canonical (loc
, attr
, XEXP (exp
, 1));
1169 defval
= XEXP (exp
, 1) = make_canonical (loc
, attr
, XEXP (exp
, 1));
1171 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1173 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1174 XVECEXP (exp
, 0, i
+ 1)
1175 = make_canonical (loc
, attr
, XVECEXP (exp
, 0, i
+ 1));
1176 if (! attr_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1192 copy_boolean (rtx exp
)
1194 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1195 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1196 copy_boolean (XEXP (exp
, 1)));
1197 else if (GET_CODE (exp
) == NOT
)
1198 return attr_rtx (NOT
, copy_boolean (XEXP (exp
, 0)));
1199 if (GET_CODE (exp
) == MATCH_OPERAND
)
1201 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1202 XSTR (exp
, 2) = DEF_ATTR_STRING (XSTR (exp
, 2));
1204 else if (GET_CODE (exp
) == EQ_ATTR
)
1206 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1207 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1213 /* Given a value and an attribute description, return a `struct attr_value *'
1214 that represents that value. This is either an existing structure, if the
1215 value has been previously encountered, or a newly-created structure.
1217 `insn_code' is the code of an insn whose attribute has the specified
1218 value (-2 if not processing an insn). We ensure that all insns for
1219 a given value have the same number of alternatives if the value checks
1220 alternatives. LOC is the location to use for error reporting. */
1222 static struct attr_value
*
1223 get_attr_value (file_location loc
, rtx value
, struct attr_desc
*attr
,
1226 struct attr_value
*av
;
1227 uint64_t num_alt
= 0;
1229 value
= make_canonical (loc
, attr
, value
);
1230 if (compares_alternatives_p (value
))
1232 if (insn_code
< 0 || insn_alternatives
== NULL
)
1233 fatal_at (loc
, "(eq_attr \"alternatives\" ...) used in non-insn"
1236 num_alt
= insn_alternatives
[insn_code
];
1239 for (av
= attr
->first_value
; av
; av
= av
->next
)
1240 if (attr_equal_p (value
, av
->value
)
1241 && (num_alt
== 0 || av
->first_insn
== NULL
1242 || insn_alternatives
[av
->first_insn
->def
->insn_code
]))
1245 av
= oballoc (struct attr_value
);
1247 av
->next
= attr
->first_value
;
1248 attr
->first_value
= av
;
1249 av
->first_insn
= NULL
;
1251 av
->has_asm_insn
= 0;
1256 /* After all DEFINE_DELAYs have been read in, create internal attributes
1257 to generate the required routines.
1259 First, we compute the number of delay slots for each insn (as a COND of
1260 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1261 delay type is specified, we compute a similar function giving the
1262 DEFINE_DELAY ordinal for each insn.
1264 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1265 tells whether a given insn can be in that delay slot.
1267 Normal attribute filling and optimization expands these to contain the
1268 information needed to handle delay slots. */
1271 expand_delays (void)
1273 struct delay_desc
*delay
;
1279 /* First, generate data for `num_delay_slots' function. */
1281 condexp
= rtx_alloc (COND
);
1282 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1283 XEXP (condexp
, 1) = make_numeric_value (0);
1285 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1287 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1288 XVECEXP (condexp
, 0, i
+ 1)
1289 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1292 make_internal_attr (num_delay_slots_str
, condexp
, ATTR_NONE
);
1294 /* If more than one delay type, do the same for computing the delay type. */
1297 condexp
= rtx_alloc (COND
);
1298 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1299 XEXP (condexp
, 1) = make_numeric_value (0);
1301 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1303 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1304 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1307 make_internal_attr (delay_type_str
, condexp
, ATTR_SPECIAL
);
1310 /* For each delay possibility and delay slot, compute an eligibility
1311 attribute for non-annulled insns and for each type of annulled (annul
1312 if true and annul if false). */
1313 for (delay
= delays
; delay
; delay
= delay
->next
)
1315 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1317 condexp
= XVECEXP (delay
->def
, 1, i
);
1319 condexp
= false_rtx
;
1320 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1321 make_numeric_value (1), make_numeric_value (0));
1323 p
= attr_printf (sizeof "*delay__" + MAX_DIGITS
* 2,
1324 "*delay_%d_%d", delay
->num
, i
/ 3);
1325 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1327 if (have_annul_true
)
1329 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1330 if (condexp
== 0) condexp
= false_rtx
;
1331 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1332 make_numeric_value (1),
1333 make_numeric_value (0));
1334 p
= attr_printf (sizeof "*annul_true__" + MAX_DIGITS
* 2,
1335 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1336 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1339 if (have_annul_false
)
1341 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1342 if (condexp
== 0) condexp
= false_rtx
;
1343 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1344 make_numeric_value (1),
1345 make_numeric_value (0));
1346 p
= attr_printf (sizeof "*annul_false__" + MAX_DIGITS
* 2,
1347 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1348 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1354 /* Once all attributes and insns have been read and checked, we construct for
1355 each attribute value a list of all the insns that have that value for
1359 fill_attr (struct attr_desc
*attr
)
1361 struct attr_value
*av
;
1362 struct insn_ent
*ie
;
1363 struct insn_def
*id
;
1367 /* Don't fill constant attributes. The value is independent of
1368 any particular insn. */
1372 for (id
= defs
; id
; id
= id
->next
)
1374 /* If no value is specified for this insn for this attribute, use the
1377 if (XVEC (id
->def
, id
->vec_idx
))
1378 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1379 if (! strcmp_check (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
1381 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
1384 av
= attr
->default_val
;
1386 av
= get_attr_value (id
->loc
, value
, attr
, id
->insn_code
);
1388 ie
= oballoc (struct insn_ent
);
1390 insert_insn_ent (av
, ie
);
1394 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
1395 test that checks relative positions of insns (uses MATCH_DUP or PC).
1396 If so, replace it with what is obtained by passing the expression to
1397 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
1398 recursively on each value (including the default value). Otherwise,
1399 return the value returned by NO_ADDRESS_FN applied to EXP. */
1402 substitute_address (rtx exp
, rtx (*no_address_fn
) (rtx
),
1403 rtx (*address_fn
) (rtx
))
1408 if (GET_CODE (exp
) == COND
)
1410 /* See if any tests use addresses. */
1412 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1413 walk_attr_value (XVECEXP (exp
, 0, i
));
1416 return (*address_fn
) (exp
);
1418 /* Make a new copy of this COND, replacing each element. */
1419 newexp
= rtx_alloc (COND
);
1420 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
1421 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1423 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
1424 XVECEXP (newexp
, 0, i
+ 1)
1425 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
1426 no_address_fn
, address_fn
);
1429 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
1430 no_address_fn
, address_fn
);
1435 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
1438 walk_attr_value (XEXP (exp
, 0));
1440 return (*address_fn
) (exp
);
1442 return attr_rtx (IF_THEN_ELSE
,
1443 substitute_address (XEXP (exp
, 0),
1444 no_address_fn
, address_fn
),
1445 substitute_address (XEXP (exp
, 1),
1446 no_address_fn
, address_fn
),
1447 substitute_address (XEXP (exp
, 2),
1448 no_address_fn
, address_fn
));
1451 return (*no_address_fn
) (exp
);
1454 /* Make new attributes from the `length' attribute. The following are made,
1455 each corresponding to a function called from `shorten_branches' or
1458 *insn_default_length This is the length of the insn to be returned
1459 by `get_attr_length' before `shorten_branches'
1460 has been called. In each case where the length
1461 depends on relative addresses, the largest
1462 possible is used. This routine is also used
1463 to compute the initial size of the insn.
1465 *insn_variable_length_p This returns 1 if the insn's length depends
1466 on relative addresses, zero otherwise.
1468 *insn_current_length This is only called when it is known that the
1469 insn has a variable length and returns the
1470 current length, based on relative addresses.
1474 make_length_attrs (void)
1476 static const char *new_names
[] =
1478 "*insn_default_length",
1480 "*insn_variable_length_p",
1481 "*insn_current_length"
1483 static rtx (*const no_address_fn
[]) (rtx
)
1484 = {identity_fn
,identity_fn
, zero_fn
, zero_fn
};
1485 static rtx (*const address_fn
[]) (rtx
)
1486 = {max_fn
, min_fn
, one_fn
, identity_fn
};
1488 struct attr_desc
*length_attr
, *new_attr
;
1489 struct attr_value
*av
, *new_av
;
1490 struct insn_ent
*ie
, *new_ie
;
1492 /* See if length attribute is defined. If so, it must be numeric. Make
1493 it special so we don't output anything for it. */
1494 length_attr
= find_attr (&length_str
, 0);
1495 if (length_attr
== 0)
1498 if (! length_attr
->is_numeric
)
1499 fatal_at (length_attr
->loc
, "length attribute must be numeric");
1501 length_attr
->is_const
= 0;
1502 length_attr
->is_special
= 1;
1504 /* Make each new attribute, in turn. */
1505 for (i
= 0; i
< ARRAY_SIZE (new_names
); i
++)
1507 make_internal_attr (new_names
[i
],
1508 substitute_address (length_attr
->default_val
->value
,
1509 no_address_fn
[i
], address_fn
[i
]),
1511 new_attr
= find_attr (&new_names
[i
], 0);
1512 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
1513 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1515 new_av
= get_attr_value (ie
->def
->loc
,
1516 substitute_address (av
->value
,
1519 new_attr
, ie
->def
->insn_code
);
1520 new_ie
= oballoc (struct insn_ent
);
1521 new_ie
->def
= ie
->def
;
1522 insert_insn_ent (new_av
, new_ie
);
1527 /* Utility functions called from above routine. */
1530 identity_fn (rtx exp
)
1536 zero_fn (rtx exp ATTRIBUTE_UNUSED
)
1538 return make_numeric_value (0);
1542 one_fn (rtx exp ATTRIBUTE_UNUSED
)
1544 return make_numeric_value (1);
1551 return make_numeric_value (max_attr_value (exp
, &unknown
));
1558 return make_numeric_value (min_attr_value (exp
, &unknown
));
1562 write_length_unit_log (FILE *outf
)
1564 struct attr_desc
*length_attr
= find_attr (&length_str
, 0);
1565 struct attr_value
*av
;
1566 struct insn_ent
*ie
;
1567 unsigned int length_unit_log
, length_or
;
1572 length_or
= or_attr_value (length_attr
->default_val
->value
, &unknown
);
1573 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
1574 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1575 length_or
|= or_attr_value (av
->value
, &unknown
);
1578 if (length_attr
== NULL
|| unknown
)
1579 length_unit_log
= 0;
1582 length_or
= ~length_or
;
1583 for (length_unit_log
= 0; length_or
& 1; length_or
>>= 1)
1586 fprintf (outf
, "EXPORTED_CONST int length_unit_log = %u;\n", length_unit_log
);
1589 /* Compute approximate cost of the expression. Used to decide whether
1590 expression is cheap enough for inline. */
1592 attr_rtx_cost (rtx x
)
1598 code
= GET_CODE (x
);
1611 /* Alternatives don't result into function call. */
1612 if (!strcmp_check (XSTR (x
, 0), alternative_name
))
1619 const char *fmt
= GET_RTX_FORMAT (code
);
1620 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1626 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1627 cost
+= attr_rtx_cost (XVECEXP (x
, i
, j
));
1630 cost
+= attr_rtx_cost (XEXP (x
, i
));
1640 /* Take a COND expression and see if any of the conditions in it can be
1641 simplified. If any are known true or known false for the particular insn
1642 code, the COND can be further simplified.
1644 Also call ourselves on any COND operations that are values of this COND.
1646 We do not modify EXP; rather, we make and return a new rtx. */
1649 simplify_cond (rtx exp
, int insn_code
, int insn_index
)
1652 /* We store the desired contents here,
1653 then build a new expression if they don't match EXP. */
1654 rtx defval
= XEXP (exp
, 1);
1655 rtx new_defval
= XEXP (exp
, 1);
1656 int len
= XVECLEN (exp
, 0);
1657 rtx
*tests
= XNEWVEC (rtx
, len
);
1661 /* This lets us free all storage allocated below, if appropriate. */
1662 obstack_finish (rtl_obstack
);
1664 memcpy (tests
, XVEC (exp
, 0)->elem
, len
* sizeof (rtx
));
1666 /* See if default value needs simplification. */
1667 if (GET_CODE (defval
) == COND
)
1668 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
1670 /* Simplify the subexpressions, and see what tests we can get rid of. */
1672 for (i
= 0; i
< len
; i
+= 2)
1674 rtx newtest
, newval
;
1676 /* Simplify this test. */
1677 newtest
= simplify_test_exp_in_temp (tests
[i
], insn_code
, insn_index
);
1680 newval
= tests
[i
+ 1];
1681 /* See if this value may need simplification. */
1682 if (GET_CODE (newval
) == COND
)
1683 newval
= simplify_cond (newval
, insn_code
, insn_index
);
1685 /* Look for ways to delete or combine this test. */
1686 if (newtest
== true_rtx
)
1688 /* If test is true, make this value the default
1689 and discard this + any following tests. */
1691 defval
= tests
[i
+ 1];
1692 new_defval
= newval
;
1695 else if (newtest
== false_rtx
)
1697 /* If test is false, discard it and its value. */
1698 for (j
= i
; j
< len
- 2; j
++)
1699 tests
[j
] = tests
[j
+ 2];
1704 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
1706 /* If this value and the value for the prev test are the same,
1710 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
1711 insn_code
, insn_index
);
1713 /* Delete this test/value. */
1714 for (j
= i
; j
< len
- 2; j
++)
1715 tests
[j
] = tests
[j
+ 2];
1721 tests
[i
+ 1] = newval
;
1724 /* If the last test in a COND has the same value
1725 as the default value, that test isn't needed. */
1727 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
1730 /* See if we changed anything. */
1731 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
1734 for (i
= 0; i
< len
; i
++)
1735 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
1743 if (GET_CODE (defval
) == COND
)
1744 ret
= simplify_cond (defval
, insn_code
, insn_index
);
1752 rtx newexp
= rtx_alloc (COND
);
1754 XVEC (newexp
, 0) = rtvec_alloc (len
);
1755 memcpy (XVEC (newexp
, 0)->elem
, tests
, len
* sizeof (rtx
));
1756 XEXP (newexp
, 1) = new_defval
;
1763 /* Remove an insn entry from an attribute value. */
1766 remove_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
1768 struct insn_ent
*previe
;
1770 if (av
->first_insn
== ie
)
1771 av
->first_insn
= ie
->next
;
1774 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
1776 previe
->next
= ie
->next
;
1780 if (ie
->def
->insn_code
== -1)
1781 av
->has_asm_insn
= 0;
1786 /* Insert an insn entry in an attribute value list. */
1789 insert_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
1791 ie
->next
= av
->first_insn
;
1792 av
->first_insn
= ie
;
1794 if (ie
->def
->insn_code
== -1)
1795 av
->has_asm_insn
= 1;
1800 /* This is a utility routine to take an expression that is a tree of either
1801 AND or IOR expressions and insert a new term. The new term will be
1802 inserted at the right side of the first node whose code does not match
1803 the root. A new node will be created with the root's code. Its left
1804 side will be the old right side and its right side will be the new
1807 If the `term' is itself a tree, all its leaves will be inserted. */
1810 insert_right_side (enum rtx_code code
, rtx exp
, rtx term
, int insn_code
, int insn_index
)
1814 /* Avoid consing in some special cases. */
1815 if (code
== AND
&& term
== true_rtx
)
1817 if (code
== AND
&& term
== false_rtx
)
1819 if (code
== AND
&& exp
== true_rtx
)
1821 if (code
== AND
&& exp
== false_rtx
)
1823 if (code
== IOR
&& term
== true_rtx
)
1825 if (code
== IOR
&& term
== false_rtx
)
1827 if (code
== IOR
&& exp
== true_rtx
)
1829 if (code
== IOR
&& exp
== false_rtx
)
1831 if (attr_equal_p (exp
, term
))
1834 if (GET_CODE (term
) == code
)
1836 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
1837 insn_code
, insn_index
);
1838 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
1839 insn_code
, insn_index
);
1844 if (GET_CODE (exp
) == code
)
1846 rtx new_rtx
= insert_right_side (code
, XEXP (exp
, 1),
1847 term
, insn_code
, insn_index
);
1848 if (new_rtx
!= XEXP (exp
, 1))
1849 /* Make a copy of this expression and call recursively. */
1850 newexp
= attr_rtx (code
, XEXP (exp
, 0), new_rtx
);
1856 /* Insert the new term. */
1857 newexp
= attr_rtx (code
, exp
, term
);
1860 return simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
1863 /* If we have an expression which AND's a bunch of
1864 (not (eq_attrq "alternative" "n"))
1865 terms, we may have covered all or all but one of the possible alternatives.
1866 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
1868 This routine is passed an expression and either AND or IOR. It returns a
1869 bitmask indicating which alternatives are mentioned within EXP. */
1872 compute_alternative_mask (rtx exp
, enum rtx_code code
)
1875 if (GET_CODE (exp
) == code
)
1876 return compute_alternative_mask (XEXP (exp
, 0), code
)
1877 | compute_alternative_mask (XEXP (exp
, 1), code
);
1879 else if (code
== AND
&& GET_CODE (exp
) == NOT
1880 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
1881 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
1882 string
= XSTR (XEXP (exp
, 0), 1);
1884 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
1885 && XSTR (exp
, 0) == alternative_name
)
1886 string
= XSTR (exp
, 1);
1888 else if (GET_CODE (exp
) == EQ_ATTR_ALT
)
1890 if (code
== AND
&& XINT (exp
, 1))
1891 return XINT (exp
, 0);
1893 if (code
== IOR
&& !XINT (exp
, 1))
1894 return XINT (exp
, 0);
1902 return ((uint64_t) 1) << (string
[0] - '0');
1903 return ((uint64_t) 1) << atoi (string
);
1906 /* Given I, a single-bit mask, return RTX to compare the `alternative'
1907 attribute with the value represented by that bit. */
1910 make_alternative_compare (uint64_t mask
)
1912 return mk_attr_alt (mask
);
1915 /* If we are processing an (eq_attr "attr" "value") test, we find the value
1916 of "attr" for this insn code. From that value, we can compute a test
1917 showing when the EQ_ATTR will be true. This routine performs that
1918 computation. If a test condition involves an address, we leave the EQ_ATTR
1919 intact because addresses are only valid for the `length' attribute.
1921 EXP is the EQ_ATTR expression and ATTR is the attribute to which
1922 it refers. VALUE is the value of that attribute for the insn
1923 corresponding to INSN_CODE and INSN_INDEX. */
1926 evaluate_eq_attr (rtx exp
, struct attr_desc
*attr
, rtx value
,
1927 int insn_code
, int insn_index
)
1934 while (GET_CODE (value
) == ATTR
)
1936 struct attr_value
*av
= NULL
;
1938 attr
= find_attr (&XSTR (value
, 0), 0);
1940 if (insn_code_values
)
1942 struct attr_value_list
*iv
;
1943 for (iv
= insn_code_values
[insn_code
]; iv
; iv
= iv
->next
)
1944 if (iv
->attr
== attr
)
1952 struct insn_ent
*ie
;
1953 for (av
= attr
->first_value
; av
; av
= av
->next
)
1954 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1955 if (ie
->def
->insn_code
== insn_code
)
1965 switch (GET_CODE (value
))
1968 if (! strcmp_check (XSTR (value
, 0), XSTR (exp
, 1)))
1979 gcc_assert (GET_CODE (exp
) == EQ_ATTR
);
1980 prefix
= attr
->enum_name
? attr
->enum_name
: attr
->name
;
1981 string
= ACONCAT ((prefix
, "_", XSTR (exp
, 1), NULL
));
1982 for (p
= string
; *p
; p
++)
1985 newexp
= attr_rtx (EQ
, value
,
1986 attr_rtx (SYMBOL_REF
,
1987 DEF_ATTR_STRING (string
)));
1992 /* We construct an IOR of all the cases for which the
1993 requested attribute value is present. Since we start with
1994 FALSE, if it is not present, FALSE will be returned.
1996 Each case is the AND of the NOT's of the previous conditions with the
1997 current condition; in the default case the current condition is TRUE.
1999 For each possible COND value, call ourselves recursively.
2001 The extra TRUE and FALSE expressions will be eliminated by another
2002 call to the simplification routine. */
2007 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2009 rtx this_cond
= simplify_test_exp_in_temp (XVECEXP (value
, 0, i
),
2010 insn_code
, insn_index
);
2012 right
= insert_right_side (AND
, andexp
, this_cond
,
2013 insn_code
, insn_index
);
2014 right
= insert_right_side (AND
, right
,
2015 evaluate_eq_attr (exp
, attr
,
2018 insn_code
, insn_index
),
2019 insn_code
, insn_index
);
2020 orexp
= insert_right_side (IOR
, orexp
, right
,
2021 insn_code
, insn_index
);
2023 /* Add this condition into the AND expression. */
2024 newexp
= attr_rtx (NOT
, this_cond
);
2025 andexp
= insert_right_side (AND
, andexp
, newexp
,
2026 insn_code
, insn_index
);
2029 /* Handle the default case. */
2030 right
= insert_right_side (AND
, andexp
,
2031 evaluate_eq_attr (exp
, attr
, XEXP (value
, 1),
2032 insn_code
, insn_index
),
2033 insn_code
, insn_index
);
2034 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2041 /* If uses an address, must return original expression. But set the
2042 ATTR_IND_SIMPLIFIED_P bit so we don't try to simplify it again. */
2045 walk_attr_value (newexp
);
2049 if (! ATTR_IND_SIMPLIFIED_P (exp
))
2050 return copy_rtx_unchanging (exp
);
2057 /* This routine is called when an AND of a term with a tree of AND's is
2058 encountered. If the term or its complement is present in the tree, it
2059 can be replaced with TRUE or FALSE, respectively.
2061 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2062 be true and hence are complementary.
2064 There is one special case: If we see
2065 (and (not (eq_attr "att" "v1"))
2066 (eq_attr "att" "v2"))
2067 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2068 replace the term, not anything in the AND tree. So we pass a pointer to
2072 simplify_and_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
2077 int left_eliminates_term
, right_eliminates_term
;
2079 if (GET_CODE (exp
) == AND
)
2081 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2082 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2083 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2085 newexp
= attr_rtx (AND
, left
, right
);
2087 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2091 else if (GET_CODE (exp
) == IOR
)
2093 /* For the IOR case, we do the same as above, except that we can
2094 only eliminate `term' if both sides of the IOR would do so. */
2096 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2097 left_eliminates_term
= (temp
== true_rtx
);
2100 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2101 right_eliminates_term
= (temp
== true_rtx
);
2103 if (left_eliminates_term
&& right_eliminates_term
)
2106 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2108 newexp
= attr_rtx (IOR
, left
, right
);
2110 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2114 /* Check for simplifications. Do some extra checking here since this
2115 routine is called so many times. */
2120 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
2123 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
2126 else if (GET_CODE (exp
) == EQ_ATTR_ALT
&& GET_CODE (*pterm
) == EQ_ATTR_ALT
)
2128 if (attr_alt_subset_p (*pterm
, exp
))
2131 if (attr_alt_subset_of_compl_p (*pterm
, exp
))
2134 if (attr_alt_subset_p (exp
, *pterm
))
2140 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
2142 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
2145 if (! strcmp_check (XSTR (exp
, 1), XSTR (*pterm
, 1)))
2151 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2152 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
2154 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
2157 if (! strcmp_check (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
2163 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2164 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
2166 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
2169 if (! strcmp_check (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
2175 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
2177 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
2181 else if (GET_CODE (exp
) == NOT
)
2183 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
2187 else if (GET_CODE (*pterm
) == NOT
)
2189 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
2193 else if (attr_equal_p (exp
, *pterm
))
2199 /* Similar to `simplify_and_tree', but for IOR trees. */
2202 simplify_or_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
2207 int left_eliminates_term
, right_eliminates_term
;
2209 if (GET_CODE (exp
) == IOR
)
2211 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2212 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2213 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2215 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2217 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2221 else if (GET_CODE (exp
) == AND
)
2223 /* For the AND case, we do the same as above, except that we can
2224 only eliminate `term' if both sides of the AND would do so. */
2226 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2227 left_eliminates_term
= (temp
== false_rtx
);
2230 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2231 right_eliminates_term
= (temp
== false_rtx
);
2233 if (left_eliminates_term
&& right_eliminates_term
)
2236 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2238 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2240 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2244 if (attr_equal_p (exp
, *pterm
))
2247 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
2250 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
2253 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2254 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2255 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
2258 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2259 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
2260 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
2266 /* Simplify test expression and use temporary obstack in order to avoid
2267 memory bloat. Use ATTR_IND_SIMPLIFIED to avoid unnecessary simplifications
2268 and avoid unnecessary copying if possible. */
2271 simplify_test_exp_in_temp (rtx exp
, int insn_code
, int insn_index
)
2274 struct obstack
*old
;
2275 if (ATTR_IND_SIMPLIFIED_P (exp
))
2278 rtl_obstack
= temp_obstack
;
2279 x
= simplify_test_exp (exp
, insn_code
, insn_index
);
2284 /* Returns true if S1 is a subset of S2. */
2287 attr_alt_subset_p (rtx s1
, rtx s2
)
2289 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2292 return !(XINT (s1
, 0) &~ XINT (s2
, 0));
2295 return !(XINT (s1
, 0) & XINT (s2
, 0));
2301 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
2308 /* Returns true if S1 is a subset of complement of S2. */
2311 attr_alt_subset_of_compl_p (rtx s1
, rtx s2
)
2313 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2316 return !(XINT (s1
, 0) & XINT (s2
, 0));
2319 return !(XINT (s1
, 0) & ~XINT (s2
, 0));
2322 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
2332 /* Return EQ_ATTR_ALT expression representing intersection of S1 and S2. */
2335 attr_alt_intersection (rtx s1
, rtx s2
)
2339 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2342 result
= XINT (s1
, 0) & XINT (s2
, 0);
2345 result
= XINT (s1
, 0) & ~XINT (s2
, 0);
2348 result
= XINT (s2
, 0) & ~XINT (s1
, 0);
2351 result
= XINT (s1
, 0) | XINT (s2
, 0);
2357 return attr_rtx (EQ_ATTR_ALT
, result
, XINT (s1
, 1) & XINT (s2
, 1));
2360 /* Return EQ_ATTR_ALT expression representing union of S1 and S2. */
2363 attr_alt_union (rtx s1
, rtx s2
)
2367 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2370 result
= XINT (s1
, 0) | XINT (s2
, 0);
2373 result
= XINT (s2
, 0) & ~XINT (s1
, 0);
2376 result
= XINT (s1
, 0) & ~XINT (s2
, 0);
2379 result
= XINT (s1
, 0) & XINT (s2
, 0);
2385 return attr_rtx (EQ_ATTR_ALT
, result
, XINT (s1
, 1) | XINT (s2
, 1));
2388 /* Return EQ_ATTR_ALT expression representing complement of S. */
2391 attr_alt_complement (rtx s
)
2393 return attr_rtx (EQ_ATTR_ALT
, XINT (s
, 0), 1 - XINT (s
, 1));
2396 /* Return EQ_ATTR_ALT expression representing set containing elements set
2400 mk_attr_alt (uint64_t e
)
2402 return attr_rtx (EQ_ATTR_ALT
, (int)e
, 0);
2405 /* Given an expression, see if it can be simplified for a particular insn
2406 code based on the values of other attributes being tested. This can
2407 eliminate nested get_attr_... calls.
2409 Note that if an endless recursion is specified in the patterns, the
2410 optimization will loop. However, it will do so in precisely the cases where
2411 an infinite recursion loop could occur during compilation. It's better that
2415 simplify_test_exp (rtx exp
, int insn_code
, int insn_index
)
2418 struct attr_desc
*attr
;
2419 struct attr_value
*av
;
2420 struct insn_ent
*ie
;
2421 struct attr_value_list
*iv
;
2424 bool left_alt
, right_alt
;
2426 /* Don't re-simplify something we already simplified. */
2427 if (ATTR_IND_SIMPLIFIED_P (exp
) || ATTR_CURR_SIMPLIFIED_P (exp
))
2430 switch (GET_CODE (exp
))
2433 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2434 if (left
== false_rtx
)
2436 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2437 if (right
== false_rtx
)
2440 if (GET_CODE (left
) == EQ_ATTR_ALT
2441 && GET_CODE (right
) == EQ_ATTR_ALT
)
2443 exp
= attr_alt_intersection (left
, right
);
2444 return simplify_test_exp (exp
, insn_code
, insn_index
);
2447 /* If either side is an IOR and we have (eq_attr "alternative" ..")
2448 present on both sides, apply the distributive law since this will
2449 yield simplifications. */
2450 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
2451 && compute_alternative_mask (left
, IOR
)
2452 && compute_alternative_mask (right
, IOR
))
2454 if (GET_CODE (left
) == IOR
)
2455 std::swap (left
, right
);
2457 newexp
= attr_rtx (IOR
,
2458 attr_rtx (AND
, left
, XEXP (right
, 0)),
2459 attr_rtx (AND
, left
, XEXP (right
, 1)));
2461 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2464 /* Try with the term on both sides. */
2465 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
2466 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2467 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
2469 if (left
== false_rtx
|| right
== false_rtx
)
2471 else if (left
== true_rtx
)
2475 else if (right
== true_rtx
)
2479 /* See if all or all but one of the insn's alternatives are specified
2480 in this tree. Optimize if so. */
2482 if (GET_CODE (left
) == NOT
)
2483 left_alt
= (GET_CODE (XEXP (left
, 0)) == EQ_ATTR
2484 && XSTR (XEXP (left
, 0), 0) == alternative_name
);
2486 left_alt
= (GET_CODE (left
) == EQ_ATTR_ALT
2489 if (GET_CODE (right
) == NOT
)
2490 right_alt
= (GET_CODE (XEXP (right
, 0)) == EQ_ATTR
2491 && XSTR (XEXP (right
, 0), 0) == alternative_name
);
2493 right_alt
= (GET_CODE (right
) == EQ_ATTR_ALT
2494 && XINT (right
, 1));
2497 && (GET_CODE (left
) == AND
2499 || GET_CODE (right
) == AND
2502 i
= compute_alternative_mask (exp
, AND
);
2503 if (i
& ~insn_alternatives
[insn_code
])
2504 fatal ("invalid alternative specified for pattern number %d",
2507 /* If all alternatives are excluded, this is false. */
2508 i
^= insn_alternatives
[insn_code
];
2511 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2513 /* If just one excluded, AND a comparison with that one to the
2514 front of the tree. The others will be eliminated by
2515 optimization. We do not want to do this if the insn has one
2516 alternative and we have tested none of them! */
2517 left
= make_alternative_compare (i
);
2518 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2519 newexp
= attr_rtx (AND
, left
, right
);
2521 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2525 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2527 newexp
= attr_rtx (AND
, left
, right
);
2528 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2533 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2534 if (left
== true_rtx
)
2536 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2537 if (right
== true_rtx
)
2540 if (GET_CODE (left
) == EQ_ATTR_ALT
2541 && GET_CODE (right
) == EQ_ATTR_ALT
)
2543 exp
= attr_alt_union (left
, right
);
2544 return simplify_test_exp (exp
, insn_code
, insn_index
);
2547 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
2548 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2549 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
2551 if (right
== true_rtx
|| left
== true_rtx
)
2553 else if (left
== false_rtx
)
2557 else if (right
== false_rtx
)
2562 /* Test for simple cases where the distributive law is useful. I.e.,
2563 convert (ior (and (x) (y))
2569 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2570 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
2572 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
2574 left
= XEXP (left
, 0);
2576 newexp
= attr_rtx (AND
, left
, right
);
2577 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2581 convert (ior (and (y) (x))
2583 to (and (ior (y) (z))
2585 Note that we want the common term to stay at the end.
2588 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2589 && attr_equal_p (XEXP (left
, 1), XEXP (right
, 1)))
2591 newexp
= attr_rtx (IOR
, XEXP (left
, 0), XEXP (right
, 0));
2594 right
= XEXP (right
, 1);
2595 newexp
= attr_rtx (AND
, left
, right
);
2596 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2599 /* See if all or all but one of the insn's alternatives are specified
2600 in this tree. Optimize if so. */
2602 else if (insn_code
>= 0
2603 && (GET_CODE (left
) == IOR
2604 || (GET_CODE (left
) == EQ_ATTR_ALT
2606 || (GET_CODE (left
) == EQ_ATTR
2607 && XSTR (left
, 0) == alternative_name
)
2608 || GET_CODE (right
) == IOR
2609 || (GET_CODE (right
) == EQ_ATTR_ALT
2610 && !XINT (right
, 1))
2611 || (GET_CODE (right
) == EQ_ATTR
2612 && XSTR (right
, 0) == alternative_name
)))
2614 i
= compute_alternative_mask (exp
, IOR
);
2615 if (i
& ~insn_alternatives
[insn_code
])
2616 fatal ("invalid alternative specified for pattern number %d",
2619 /* If all alternatives are included, this is true. */
2620 i
^= insn_alternatives
[insn_code
];
2623 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2625 /* If just one excluded, IOR a comparison with that one to the
2626 front of the tree. The others will be eliminated by
2627 optimization. We do not want to do this if the insn has one
2628 alternative and we have tested none of them! */
2629 left
= make_alternative_compare (i
);
2630 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2631 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
2633 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2637 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2639 newexp
= attr_rtx (IOR
, left
, right
);
2640 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2645 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
2647 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
2648 insn_code
, insn_index
);
2652 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2653 if (GET_CODE (left
) == NOT
)
2654 return XEXP (left
, 0);
2656 if (left
== false_rtx
)
2658 if (left
== true_rtx
)
2661 if (GET_CODE (left
) == EQ_ATTR_ALT
)
2663 exp
= attr_alt_complement (left
);
2664 return simplify_test_exp (exp
, insn_code
, insn_index
);
2667 /* Try to apply De`Morgan's laws. */
2668 if (GET_CODE (left
) == IOR
)
2670 newexp
= attr_rtx (AND
,
2671 attr_rtx (NOT
, XEXP (left
, 0)),
2672 attr_rtx (NOT
, XEXP (left
, 1)));
2674 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2676 else if (GET_CODE (left
) == AND
)
2678 newexp
= attr_rtx (IOR
,
2679 attr_rtx (NOT
, XEXP (left
, 0)),
2680 attr_rtx (NOT
, XEXP (left
, 1)));
2682 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2684 else if (left
!= XEXP (exp
, 0))
2686 newexp
= attr_rtx (NOT
, left
);
2692 return XINT (exp
, 1) ? true_rtx
: false_rtx
;
2696 if (XSTR (exp
, 0) == alternative_name
)
2698 newexp
= mk_attr_alt (((uint64_t) 1) << atoi (XSTR (exp
, 1)));
2702 /* Look at the value for this insn code in the specified attribute.
2703 We normally can replace this comparison with the condition that
2704 would give this insn the values being tested for. */
2706 && (attr
= find_attr (&XSTR (exp
, 0), 0)) != NULL
)
2711 if (insn_code_values
)
2713 for (iv
= insn_code_values
[insn_code
]; iv
; iv
= iv
->next
)
2714 if (iv
->attr
== attr
)
2722 for (av
= attr
->first_value
; av
; av
= av
->next
)
2723 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2724 if (ie
->def
->insn_code
== insn_code
)
2731 x
= evaluate_eq_attr (exp
, attr
, av
->value
,
2732 insn_code
, insn_index
);
2733 x
= SIMPLIFY_TEST_EXP (x
, insn_code
, insn_index
);
2734 if (attr_rtx_cost (x
) < 7)
2744 /* We have already simplified this expression. Simplifying it again
2745 won't buy anything unless we weren't given a valid insn code
2746 to process (i.e., we are canonicalizing something.). */
2748 && ! ATTR_IND_SIMPLIFIED_P (newexp
))
2749 return copy_rtx_unchanging (newexp
);
2754 /* Return 1 if any EQ_ATTR subexpression of P refers to ATTR,
2755 otherwise return 0. */
2758 tests_attr_p (rtx p
, struct attr_desc
*attr
)
2763 if (GET_CODE (p
) == EQ_ATTR
)
2765 if (XSTR (p
, 0) != attr
->name
)
2770 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
2771 ie
= GET_RTX_LENGTH (GET_CODE (p
));
2772 for (i
= 0; i
< ie
; i
++)
2777 if (tests_attr_p (XEXP (p
, i
), attr
))
2782 je
= XVECLEN (p
, i
);
2783 for (j
= 0; j
< je
; ++j
)
2784 if (tests_attr_p (XVECEXP (p
, i
, j
), attr
))
2793 /* Calculate a topological sorting of all attributes so that
2794 all attributes only depend on attributes in front of it.
2795 Place the result in *RET (which is a pointer to an array of
2796 attr_desc pointers), and return the size of that array. */
2799 get_attr_order (struct attr_desc
***ret
)
2803 struct attr_desc
*attr
;
2804 struct attr_desc
**all
, **sorted
;
2806 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
2807 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
2809 all
= XNEWVEC (struct attr_desc
*, num
);
2810 sorted
= XNEWVEC (struct attr_desc
*, num
);
2811 handled
= XCNEWVEC (char, num
);
2813 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
2814 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
2818 for (i
= 0; i
< num
; i
++)
2819 if (all
[i
]->is_const
)
2820 handled
[i
] = 1, sorted
[j
++] = all
[i
];
2822 /* We have only few attributes hence we can live with the inner
2823 loop being O(n^2), unlike the normal fast variants of topological
2827 for (i
= 0; i
< num
; i
++)
2830 /* Let's see if I depends on anything interesting. */
2832 for (k
= 0; k
< num
; k
++)
2835 struct attr_value
*av
;
2836 for (av
= all
[i
]->first_value
; av
; av
= av
->next
)
2837 if (av
->num_insns
!= 0)
2838 if (tests_attr_p (av
->value
, all
[k
]))
2842 /* Something in I depends on K. */
2847 /* Nothing in I depended on anything intersting, so
2850 sorted
[j
++] = all
[i
];
2856 for (j
= 0; j
< num
; j
++)
2858 struct attr_desc
*attr2
;
2859 struct attr_value
*av
;
2862 fprintf (stderr
, "%s depends on: ", attr
->name
);
2863 for (i
= 0; i
< MAX_ATTRS_INDEX
; ++i
)
2864 for (attr2
= attrs
[i
]; attr2
; attr2
= attr2
->next
)
2865 if (!attr2
->is_const
)
2866 for (av
= attr
->first_value
; av
; av
= av
->next
)
2867 if (av
->num_insns
!= 0)
2868 if (tests_attr_p (av
->value
, attr2
))
2870 fprintf (stderr
, "%s, ", attr2
->name
);
2873 fprintf (stderr
, "\n");
2881 /* Optimize the attribute lists by seeing if we can determine conditional
2882 values from the known values of other attributes. This will save subroutine
2883 calls during the compilation. NUM_INSN_CODES is the number of unique
2884 instruction codes. */
2887 optimize_attrs (int num_insn_codes
)
2889 struct attr_desc
*attr
;
2890 struct attr_value
*av
;
2891 struct insn_ent
*ie
;
2894 struct attr_value_list
*ivbuf
;
2895 struct attr_value_list
*iv
;
2896 struct attr_desc
**topsort
;
2899 /* For each insn code, make a list of all the insn_ent's for it,
2900 for all values for all attributes. */
2902 if (num_insn_ents
== 0)
2905 /* Make 2 extra elements, for "code" values -2 and -1. */
2906 insn_code_values
= XCNEWVEC (struct attr_value_list
*, num_insn_codes
+ 2);
2908 /* Offset the table address so we can index by -2 or -1. */
2909 insn_code_values
+= 2;
2911 iv
= ivbuf
= XNEWVEC (struct attr_value_list
, num_insn_ents
);
2913 /* Create the chain of insn*attr values such that we see dependend
2914 attributes after their dependencies. As we use a stack via the
2915 next pointers start from the end of the topological order. */
2916 topnum
= get_attr_order (&topsort
);
2917 for (i
= topnum
- 1; i
>= 0; i
--)
2918 for (av
= topsort
[i
]->first_value
; av
; av
= av
->next
)
2919 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2921 iv
->attr
= topsort
[i
];
2924 iv
->next
= insn_code_values
[ie
->def
->insn_code
];
2925 insn_code_values
[ie
->def
->insn_code
] = iv
;
2930 /* Sanity check on num_insn_ents. */
2931 gcc_assert (iv
== ivbuf
+ num_insn_ents
);
2933 /* Process one insn code at a time. */
2934 for (i
= -2; i
< num_insn_codes
; i
++)
2936 /* Clear the ATTR_CURR_SIMPLIFIED_P flag everywhere relevant.
2937 We use it to mean "already simplified for this insn". */
2938 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
2939 clear_struct_flag (iv
->av
->value
);
2941 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
2943 struct obstack
*old
= rtl_obstack
;
2948 if (GET_CODE (av
->value
) != COND
)
2951 rtl_obstack
= temp_obstack
;
2953 while (GET_CODE (newexp
) == COND
)
2955 rtx newexp2
= simplify_cond (newexp
, ie
->def
->insn_code
,
2956 ie
->def
->insn_index
);
2957 if (newexp2
== newexp
)
2963 /* If we created a new value for this instruction, and it's
2964 cheaper than the old value, and overall cheap, use that
2965 one as specific value for the current instruction.
2966 The last test is to avoid exploding the get_attr_ function
2967 sizes for no much gain. */
2968 if (newexp
!= av
->value
2969 && attr_rtx_cost (newexp
) < attr_rtx_cost (av
->value
)
2970 && attr_rtx_cost (newexp
) < 26
2973 remove_insn_ent (av
, ie
);
2974 av
= get_attr_value (ie
->def
->loc
, newexp
, attr
,
2975 ie
->def
->insn_code
);
2977 insert_insn_ent (av
, ie
);
2983 free (insn_code_values
- 2);
2984 insn_code_values
= NULL
;
2987 /* Clear the ATTR_CURR_SIMPLIFIED_P flag in EXP and its subexpressions. */
2990 clear_struct_flag (rtx x
)
2997 ATTR_CURR_SIMPLIFIED_P (x
) = 0;
2998 if (ATTR_IND_SIMPLIFIED_P (x
))
3001 code
= GET_CODE (x
);
3020 /* Compare the elements. If any pair of corresponding elements
3021 fail to match, return 0 for the whole things. */
3023 fmt
= GET_RTX_FORMAT (code
);
3024 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3030 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3031 clear_struct_flag (XVECEXP (x
, i
, j
));
3035 clear_struct_flag (XEXP (x
, i
));
3041 /* Add attribute value NAME to the beginning of ATTR's list. */
3044 add_attr_value (struct attr_desc
*attr
, const char *name
)
3046 struct attr_value
*av
;
3048 av
= oballoc (struct attr_value
);
3049 av
->value
= attr_rtx (CONST_STRING
, name
);
3050 av
->next
= attr
->first_value
;
3051 attr
->first_value
= av
;
3052 av
->first_insn
= NULL
;
3054 av
->has_asm_insn
= 0;
3057 /* Create table entries for DEFINE_ATTR or DEFINE_ENUM_ATTR. */
3060 gen_attr (md_rtx_info
*info
)
3062 struct enum_type
*et
;
3063 struct enum_value
*ev
;
3064 struct attr_desc
*attr
;
3065 const char *name_ptr
;
3067 rtx def
= info
->def
;
3069 /* Make a new attribute structure. Check for duplicate by looking at
3070 attr->default_val, since it is initialized by this routine. */
3071 attr
= find_attr (&XSTR (def
, 0), 1);
3072 if (attr
->default_val
)
3074 error_at (info
->loc
, "duplicate definition for attribute %s",
3076 message_at (attr
->loc
, "previous definition");
3079 attr
->loc
= info
->loc
;
3081 if (GET_CODE (def
) == DEFINE_ENUM_ATTR
)
3083 attr
->enum_name
= XSTR (def
, 1);
3084 et
= rtx_reader_ptr
->lookup_enum_type (XSTR (def
, 1));
3085 if (!et
|| !et
->md_p
)
3086 error_at (info
->loc
, "No define_enum called `%s' defined",
3089 for (ev
= et
->values
; ev
; ev
= ev
->next
)
3090 add_attr_value (attr
, ev
->name
);
3092 else if (*XSTR (def
, 1) == '\0')
3093 attr
->is_numeric
= 1;
3096 name_ptr
= XSTR (def
, 1);
3097 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
3098 add_attr_value (attr
, p
);
3101 if (GET_CODE (XEXP (def
, 2)) == CONST
)
3104 if (attr
->is_numeric
)
3105 error_at (info
->loc
,
3106 "constant attributes may not take numeric values");
3108 /* Get rid of the CONST node. It is allowed only at top-level. */
3109 XEXP (def
, 2) = XEXP (XEXP (def
, 2), 0);
3112 if (! strcmp_check (attr
->name
, length_str
) && ! attr
->is_numeric
)
3113 error_at (info
->loc
, "`length' attribute must take numeric values");
3115 /* Set up the default value. */
3116 XEXP (def
, 2) = check_attr_value (info
->loc
, XEXP (def
, 2), attr
);
3117 attr
->default_val
= get_attr_value (info
->loc
, XEXP (def
, 2), attr
, -2);
3120 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
3121 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
3122 number of alternatives as this should be checked elsewhere. */
3125 count_alternatives (rtx exp
)
3130 if (GET_CODE (exp
) == MATCH_OPERAND
)
3131 return n_comma_elts (XSTR (exp
, 2));
3133 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3134 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3139 n
= count_alternatives (XEXP (exp
, i
));
3146 if (XVEC (exp
, i
) != NULL
)
3147 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3149 n
= count_alternatives (XVECEXP (exp
, i
, j
));
3158 /* Returns nonzero if the given expression contains an EQ_ATTR with the
3159 `alternative' attribute. */
3162 compares_alternatives_p (rtx exp
)
3167 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
3170 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3171 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3176 if (compares_alternatives_p (XEXP (exp
, i
)))
3181 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3182 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
3190 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
3193 gen_insn (md_rtx_info
*info
)
3195 struct insn_def
*id
;
3196 rtx def
= info
->def
;
3198 id
= oballoc (struct insn_def
);
3202 id
->loc
= info
->loc
;
3204 switch (GET_CODE (def
))
3207 id
->insn_code
= info
->index
;
3208 id
->insn_index
= insn_index_number
;
3209 id
->num_alternatives
= count_alternatives (def
);
3210 if (id
->num_alternatives
== 0)
3211 id
->num_alternatives
= 1;
3215 case DEFINE_PEEPHOLE
:
3216 id
->insn_code
= info
->index
;
3217 id
->insn_index
= insn_index_number
;
3218 id
->num_alternatives
= count_alternatives (def
);
3219 if (id
->num_alternatives
== 0)
3220 id
->num_alternatives
= 1;
3224 case DEFINE_ASM_ATTRIBUTES
:
3226 id
->insn_index
= -1;
3227 id
->num_alternatives
= 1;
3229 got_define_asm_attributes
= 1;
3237 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
3238 true or annul false is specified, and make a `struct delay_desc'. */
3241 gen_delay (md_rtx_info
*info
)
3243 struct delay_desc
*delay
;
3246 rtx def
= info
->def
;
3247 if (XVECLEN (def
, 1) % 3 != 0)
3249 error_at (info
->loc
, "number of elements in DEFINE_DELAY must"
3250 " be multiple of three");
3254 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
3256 if (XVECEXP (def
, 1, i
+ 1))
3257 have_annul_true
= 1;
3258 if (XVECEXP (def
, 1, i
+ 2))
3259 have_annul_false
= 1;
3262 delay
= oballoc (struct delay_desc
);
3264 delay
->num
= ++num_delays
;
3265 delay
->next
= delays
;
3266 delay
->loc
= info
->loc
;
3270 /* Names of attributes that could be possibly cached. */
3271 static const char *cached_attrs
[32];
3272 /* Number of such attributes. */
3273 static int cached_attr_count
;
3274 /* Bitmasks of possibly cached attributes. */
3275 static unsigned int attrs_seen_once
, attrs_seen_more_than_once
;
3276 static unsigned int attrs_to_cache
;
3277 static unsigned int attrs_cached_inside
, attrs_cached_after
;
3279 /* Finds non-const attributes that could be possibly cached.
3280 When create is TRUE, fills in cached_attrs array.
3281 Computes ATTRS_SEEN_ONCE and ATTRS_SEEN_MORE_THAN_ONCE
3285 find_attrs_to_cache (rtx exp
, bool create
)
3289 struct attr_desc
*attr
;
3294 switch (GET_CODE (exp
))
3297 if (GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3298 find_attrs_to_cache (XEXP (exp
, 0), create
);
3302 name
= XSTR (exp
, 0);
3303 if (name
== alternative_name
)
3305 for (i
= 0; i
< cached_attr_count
; i
++)
3306 if (name
== cached_attrs
[i
])
3308 if ((attrs_seen_once
& (1U << i
)) != 0)
3309 attrs_seen_more_than_once
|= (1U << i
);
3311 attrs_seen_once
|= (1U << i
);
3316 attr
= find_attr (&name
, 0);
3320 if (cached_attr_count
== 32)
3322 cached_attrs
[cached_attr_count
] = XSTR (exp
, 0);
3323 attrs_seen_once
|= (1U << cached_attr_count
);
3324 cached_attr_count
++;
3329 find_attrs_to_cache (XEXP (exp
, 0), create
);
3330 find_attrs_to_cache (XEXP (exp
, 1), create
);
3334 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3335 find_attrs_to_cache (XVECEXP (exp
, 0, i
), create
);
3343 /* Given a piece of RTX, print a C expression to test its truth value to OUTF.
3344 We use AND and IOR both for logical and bit-wise operations, so
3345 interpret them as logical unless they are inside a comparison expression.
3347 An outermost pair of parentheses is emitted around this C expression unless
3348 EMIT_PARENS is false. */
3350 /* Interpret AND/IOR as bit-wise operations instead of logical. */
3351 #define FLG_BITWISE 1
3352 /* Set if cached attribute will be known initialized in else block after
3353 this condition. This is true for LHS of toplevel && and || and
3354 even for RHS of ||, but not for RHS of &&. */
3356 /* Set if cached attribute will be known initialized in then block after
3357 this condition. This is true for LHS of toplevel && and || and
3358 even for RHS of &&, but not for RHS of ||. */
3359 #define FLG_INSIDE 4
3360 /* Cleared when an operand of &&. */
3361 #define FLG_OUTSIDE_AND 8
3364 write_test_expr (FILE *outf
, rtx exp
, unsigned int attrs_cached
, int flags
,
3365 bool emit_parens
= true)
3367 int comparison_operator
= 0;
3369 struct attr_desc
*attr
;
3372 fprintf (outf
, "(");
3374 code
= GET_CODE (exp
);
3377 /* Binary operators. */
3380 fprintf (outf
, "(unsigned) ");
3386 comparison_operator
= FLG_BITWISE
;
3389 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
3390 case AND
: case IOR
: case XOR
:
3391 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
3392 if ((code
!= AND
&& code
!= IOR
) || (flags
& FLG_BITWISE
))
3394 flags
&= ~(FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
);
3395 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
,
3396 flags
| comparison_operator
);
3401 flags
&= ~FLG_OUTSIDE_AND
;
3402 if (GET_CODE (XEXP (exp
, 0)) == code
3403 || GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3404 || (GET_CODE (XEXP (exp
, 0)) == NOT
3405 && GET_CODE (XEXP (XEXP (exp
, 0), 0)) == EQ_ATTR
))
3407 = write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3409 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3414 fprintf (outf
, " == ");
3417 fprintf (outf
, " != ");
3420 fprintf (outf
, " >= ");
3423 fprintf (outf
, " > ");
3426 fprintf (outf
, " >= (unsigned) ");
3429 fprintf (outf
, " > (unsigned) ");
3432 fprintf (outf
, " <= ");
3435 fprintf (outf
, " < ");
3438 fprintf (outf
, " <= (unsigned) ");
3441 fprintf (outf
, " < (unsigned) ");
3444 fprintf (outf
, " + ");
3447 fprintf (outf
, " - ");
3450 fprintf (outf
, " * ");
3453 fprintf (outf
, " / ");
3456 fprintf (outf
, " %% ");
3459 if (flags
& FLG_BITWISE
)
3460 fprintf (outf
, " & ");
3462 fprintf (outf
, " && ");
3465 if (flags
& FLG_BITWISE
)
3466 fprintf (outf
, " | ");
3468 fprintf (outf
, " || ");
3471 fprintf (outf
, " ^ ");
3474 fprintf (outf
, " << ");
3478 fprintf (outf
, " >> ");
3486 /* For if (something && (cached_x = get_attr_x (insn)) == X)
3487 cached_x is only known to be initialized in then block. */
3488 flags
&= ~FLG_AFTER
;
3490 else if (code
== IOR
)
3492 if (flags
& FLG_OUTSIDE_AND
)
3493 /* For if (something || (cached_x = get_attr_x (insn)) == X)
3494 cached_x is only known to be initialized in else block
3495 and else if conditions. */
3496 flags
&= ~FLG_INSIDE
;
3498 /* For if ((something || (cached_x = get_attr_x (insn)) == X)
3500 cached_x is not know to be initialized anywhere. */
3501 flags
&= ~(FLG_AFTER
| FLG_INSIDE
);
3503 if ((code
== AND
|| code
== IOR
)
3504 && (GET_CODE (XEXP (exp
, 1)) == code
3505 || GET_CODE (XEXP (exp
, 1)) == EQ_ATTR
3506 || (GET_CODE (XEXP (exp
, 1)) == NOT
3507 && GET_CODE (XEXP (XEXP (exp
, 1), 0)) == EQ_ATTR
)))
3509 bool need_parens
= true;
3511 /* No need to emit parentheses around the right-hand operand if we are
3512 continuing a chain of && or || (or & or |). */
3513 if (GET_CODE (XEXP (exp
, 1)) == code
)
3514 need_parens
= false;
3517 = write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
, flags
,
3521 write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
,
3522 flags
| comparison_operator
);
3526 /* Special-case (not (eq_attrq "alternative" "x")) */
3527 if (! (flags
& FLG_BITWISE
) && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3529 if (XSTR (XEXP (exp
, 0), 0) == alternative_name
)
3531 fprintf (outf
, "which_alternative != %s",
3532 XSTR (XEXP (exp
, 0), 1));
3536 fprintf (outf
, "! ");
3538 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3542 /* Otherwise, fall through to normal unary operator. */
3545 /* Unary operators. */
3550 if (flags
& FLG_BITWISE
)
3551 fprintf (outf
, "~ ");
3553 fprintf (outf
, "! ");
3556 fprintf (outf
, "abs ");
3559 fprintf (outf
, "-");
3565 flags
&= ~(FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
);
3566 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3571 int set
= XINT (exp
, 0), bit
= 0;
3573 if (flags
& FLG_BITWISE
)
3574 fatal ("EQ_ATTR_ALT not valid inside comparison");
3577 fatal ("Empty EQ_ATTR_ALT should be optimized out");
3579 if (!(set
& (set
- 1)))
3581 if (!(set
& 0xffff))
3604 fprintf (outf
, "which_alternative %s= %d",
3605 XINT (exp
, 1) ? "!" : "=", bit
);
3609 fprintf (outf
, "%s((1 << which_alternative) & %#x)",
3610 XINT (exp
, 1) ? "!" : "", set
);
3615 /* Comparison test of an attribute with a value. Most of these will
3616 have been removed by optimization. Handle "alternative"
3617 specially and give error if EQ_ATTR present inside a comparison. */
3619 if (flags
& FLG_BITWISE
)
3620 fatal ("EQ_ATTR not valid inside comparison");
3622 if (XSTR (exp
, 0) == alternative_name
)
3624 fprintf (outf
, "which_alternative == %s", XSTR (exp
, 1));
3628 attr
= find_attr (&XSTR (exp
, 0), 0);
3631 /* Now is the time to expand the value of a constant attribute. */
3634 write_test_expr (outf
,
3635 evaluate_eq_attr (exp
, attr
,
3636 attr
->default_val
->value
,
3643 for (i
= 0; i
< cached_attr_count
; i
++)
3644 if (attr
->name
== cached_attrs
[i
])
3646 if (i
< cached_attr_count
&& (attrs_cached
& (1U << i
)) != 0)
3647 fprintf (outf
, "cached_%s", attr
->name
);
3648 else if (i
< cached_attr_count
&& (attrs_to_cache
& (1U << i
)) != 0)
3650 fprintf (outf
, "(cached_%s = get_attr_%s (insn))",
3651 attr
->name
, attr
->name
);
3652 if (flags
& FLG_AFTER
)
3653 attrs_cached_after
|= (1U << i
);
3654 if (flags
& FLG_INSIDE
)
3655 attrs_cached_inside
|= (1U << i
);
3656 attrs_cached
|= (1U << i
);
3659 fprintf (outf
, "get_attr_%s (insn)", attr
->name
);
3660 fprintf (outf
, " == ");
3661 write_attr_valueq (outf
, attr
, XSTR (exp
, 1));
3665 /* Comparison test of flags for define_delays. */
3667 if (flags
& FLG_BITWISE
)
3668 fatal ("ATTR_FLAG not valid inside comparison");
3669 fprintf (outf
, "(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
3672 /* See if an operand matches a predicate. */
3674 /* If only a mode is given, just ensure the mode matches the operand.
3675 If neither a mode nor predicate is given, error. */
3676 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
3678 if (GET_MODE (exp
) == VOIDmode
)
3679 fatal ("null MATCH_OPERAND specified as test");
3681 fprintf (outf
, "GET_MODE (operands[%d]) == %smode",
3682 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3685 fprintf (outf
, "%s (operands[%d], %smode)",
3686 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3689 /* Constant integer. */
3691 fprintf (outf
, HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
3695 rtx_reader_ptr
->fprint_c_condition (outf
, XSTR (exp
, 0));
3696 if (flags
& FLG_BITWISE
)
3697 fprintf (outf
, " != 0");
3700 /* A random C expression. */
3702 rtx_reader_ptr
->fprint_c_condition (outf
, XSTR (exp
, 0));
3705 /* The address of the branch target. */
3708 "INSN_ADDRESSES_SET_P () ? INSN_ADDRESSES (INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])) : 0",
3709 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
3713 /* The address of the current insn. We implement this actually as the
3714 address of the current insn for backward branches, but the last
3715 address of the next insn for forward branches, and both with
3716 adjustments that account for the worst-case possible stretching of
3717 intervening alignments between this insn and its destination. */
3718 fprintf (outf
, "insn_current_reference_address (insn)");
3722 fprintf (outf
, "%s", XSTR (exp
, 0));
3726 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, 0);
3727 fprintf (outf
, " ? ");
3728 write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
, FLG_BITWISE
);
3729 fprintf (outf
, " : ");
3730 write_test_expr (outf
, XEXP (exp
, 2), attrs_cached
, FLG_BITWISE
);
3734 fatal ("bad RTX code `%s' in attribute calculation\n",
3735 GET_RTX_NAME (code
));
3739 fprintf (outf
, ")");
3741 return attrs_cached
;
3744 /* Given an attribute value, return the maximum CONST_STRING argument
3745 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
3748 max_attr_value (rtx exp
, int *unknownp
)
3753 switch (GET_CODE (exp
))
3756 current_max
= atoi (XSTR (exp
, 0));
3760 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
3761 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3763 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3764 if (n
> current_max
)
3770 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
3771 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
3772 if (n
> current_max
)
3778 current_max
= INT_MAX
;
3785 /* Given an attribute value, return the minimum CONST_STRING argument
3786 encountered. Set *UNKNOWNP and return 0 if the value is unknown. */
3789 min_attr_value (rtx exp
, int *unknownp
)
3794 switch (GET_CODE (exp
))
3797 current_min
= atoi (XSTR (exp
, 0));
3801 current_min
= min_attr_value (XEXP (exp
, 1), unknownp
);
3802 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3804 n
= min_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3805 if (n
< current_min
)
3811 current_min
= min_attr_value (XEXP (exp
, 1), unknownp
);
3812 n
= min_attr_value (XEXP (exp
, 2), unknownp
);
3813 if (n
< current_min
)
3819 current_min
= INT_MAX
;
3826 /* Given an attribute value, return the result of ORing together all
3827 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
3828 if the numeric value is not known. */
3831 or_attr_value (rtx exp
, int *unknownp
)
3836 switch (GET_CODE (exp
))
3839 current_or
= atoi (XSTR (exp
, 0));
3843 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
3844 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3845 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3849 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
3850 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
3862 /* Scan an attribute value, possibly a conditional, and record what actions
3863 will be required to do any conditional tests in it.
3866 `must_extract' if we need to extract the insn operands
3867 `must_constrain' if we must compute `which_alternative'
3868 `address_used' if an address expression was used
3869 `length_used' if an (eq_attr "length" ...) was used
3873 walk_attr_value (rtx exp
)
3882 code
= GET_CODE (exp
);
3886 if (! ATTR_IND_SIMPLIFIED_P (exp
))
3887 /* Since this is an arbitrary expression, it can look at anything.
3888 However, constant expressions do not depend on any particular
3890 must_extract
= must_constrain
= 1;
3899 must_extract
= must_constrain
= 1;
3903 if (XSTR (exp
, 0) == alternative_name
)
3904 must_extract
= must_constrain
= 1;
3905 else if (strcmp_check (XSTR (exp
, 0), length_str
) == 0)
3925 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
3930 walk_attr_value (XEXP (exp
, i
));
3934 if (XVEC (exp
, i
) != NULL
)
3935 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3936 walk_attr_value (XVECEXP (exp
, i
, j
));
3941 /* Write out a function to obtain the attribute for a given INSN. */
3944 write_attr_get (FILE *outf
, struct attr_desc
*attr
)
3946 struct attr_value
*av
, *common_av
;
3949 /* Find the most used attribute value. Handle that as the `default' of the
3950 switch we will generate. */
3951 common_av
= find_most_used (attr
);
3953 /* Write out start of function, then all values with explicit `case' lines,
3954 then a `default', then the value with the most uses. */
3955 if (attr
->enum_name
)
3956 fprintf (outf
, "enum %s\n", attr
->enum_name
);
3957 else if (!attr
->is_numeric
)
3958 fprintf (outf
, "enum attr_%s\n", attr
->name
);
3960 fprintf (outf
, "int\n");
3962 /* If the attribute name starts with a star, the remainder is the name of
3963 the subroutine to use, instead of `get_attr_...'. */
3964 if (attr
->name
[0] == '*')
3965 fprintf (outf
, "%s (rtx_insn *insn ATTRIBUTE_UNUSED)\n", &attr
->name
[1]);
3966 else if (attr
->is_const
== 0)
3967 fprintf (outf
, "get_attr_%s (rtx_insn *insn ATTRIBUTE_UNUSED)\n", attr
->name
);
3970 fprintf (outf
, "get_attr_%s (void)\n", attr
->name
);
3971 fprintf (outf
, "{\n");
3973 for (av
= attr
->first_value
; av
; av
= av
->next
)
3974 if (av
->num_insns
== 1)
3975 write_attr_set (outf
, attr
, 2, av
->value
, "return", ";",
3976 true_rtx
, av
->first_insn
->def
->insn_code
,
3977 av
->first_insn
->def
->insn_index
, 0);
3978 else if (av
->num_insns
!= 0)
3979 write_attr_set (outf
, attr
, 2, av
->value
, "return", ";",
3980 true_rtx
, -2, 0, 0);
3982 fprintf (outf
, "}\n\n");
3986 fprintf (outf
, "{\n");
3988 /* Find attributes that are worth caching in the conditions. */
3989 cached_attr_count
= 0;
3990 attrs_seen_more_than_once
= 0;
3991 for (av
= attr
->first_value
; av
; av
= av
->next
)
3993 attrs_seen_once
= 0;
3994 find_attrs_to_cache (av
->value
, true);
3996 /* Remove those that aren't worth caching from the array. */
3997 for (i
= 0, j
= 0; i
< cached_attr_count
; i
++)
3998 if ((attrs_seen_more_than_once
& (1U << i
)) != 0)
4000 const char *name
= cached_attrs
[i
];
4001 struct attr_desc
*cached_attr
;
4003 cached_attrs
[j
] = name
;
4004 cached_attr
= find_attr (&name
, 0);
4005 gcc_assert (cached_attr
&& cached_attr
->is_const
== 0);
4006 if (cached_attr
->enum_name
)
4007 fprintf (outf
, " enum %s", cached_attr
->enum_name
);
4008 else if (!cached_attr
->is_numeric
)
4009 fprintf (outf
, " enum attr_%s", cached_attr
->name
);
4011 fprintf (outf
, " int");
4012 fprintf (outf
, " cached_%s ATTRIBUTE_UNUSED;\n", name
);
4015 cached_attr_count
= j
;
4016 if (cached_attr_count
)
4017 fprintf (outf
, "\n");
4019 fprintf (outf
, " switch (recog_memoized (insn))\n");
4020 fprintf (outf
, " {\n");
4022 for (av
= attr
->first_value
; av
; av
= av
->next
)
4023 if (av
!= common_av
)
4024 write_attr_case (outf
, attr
, av
, 1, "return", ";", 4, true_rtx
);
4026 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4027 fprintf (outf
, " }\n}\n\n");
4028 cached_attr_count
= 0;
4031 /* Given an AND tree of known true terms (because we are inside an `if' with
4032 that as the condition or are in an `else' clause) and an expression,
4033 replace any known true terms with TRUE. Use `simplify_and_tree' to do
4034 the bulk of the work. */
4037 eliminate_known_true (rtx known_true
, rtx exp
, int insn_code
, int insn_index
)
4041 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
4043 if (GET_CODE (known_true
) == AND
)
4045 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
4046 insn_code
, insn_index
);
4047 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
4048 insn_code
, insn_index
);
4053 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
4059 /* Write out a series of tests and assignment statements to perform tests and
4060 sets of an attribute value. We are passed an indentation amount and prefix
4061 and suffix strings to write around each attribute value (e.g., "return"
4065 write_attr_set (FILE *outf
, struct attr_desc
*attr
, int indent
, rtx value
,
4066 const char *prefix
, const char *suffix
, rtx known_true
,
4067 int insn_code
, int insn_index
, unsigned int attrs_cached
)
4069 if (GET_CODE (value
) == COND
)
4071 /* Assume the default value will be the default of the COND unless we
4072 find an always true expression. */
4073 rtx default_val
= XEXP (value
, 1);
4074 rtx our_known_true
= known_true
;
4079 if (cached_attr_count
)
4081 attrs_seen_once
= 0;
4082 attrs_seen_more_than_once
= 0;
4083 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4084 find_attrs_to_cache (XVECEXP (value
, 0, i
), false);
4085 attrs_to_cache
|= attrs_seen_more_than_once
;
4088 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4093 /* Reset our_known_true after some time to not accumulate
4094 too much cruft (slowing down genattrtab). */
4096 our_known_true
= known_true
;
4097 testexp
= eliminate_known_true (our_known_true
,
4098 XVECEXP (value
, 0, i
),
4099 insn_code
, insn_index
);
4100 newexp
= attr_rtx (NOT
, testexp
);
4101 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
4102 insn_code
, insn_index
);
4104 /* If the test expression is always true or if the next `known_true'
4105 expression is always false, this is the last case, so break
4106 out and let this value be the `else' case. */
4107 if (testexp
== true_rtx
|| newexp
== false_rtx
)
4109 default_val
= XVECEXP (value
, 0, i
+ 1);
4113 /* Compute the expression to pass to our recursive call as being
4115 inner_true
= insert_right_side (AND
, our_known_true
,
4116 testexp
, insn_code
, insn_index
);
4118 /* If this is always false, skip it. */
4119 if (inner_true
== false_rtx
)
4122 attrs_cached_inside
= attrs_cached
;
4123 attrs_cached_after
= attrs_cached
;
4124 write_indent (outf
, indent
);
4125 fprintf (outf
, "%sif ", first_if
? "" : "else ");
4127 write_test_expr (outf
, testexp
, attrs_cached
,
4128 (FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
));
4129 attrs_cached
= attrs_cached_after
;
4130 fprintf (outf
, "\n");
4131 write_indent (outf
, indent
+ 2);
4132 fprintf (outf
, "{\n");
4134 write_attr_set (outf
, attr
, indent
+ 4,
4135 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
4136 inner_true
, insn_code
, insn_index
,
4137 attrs_cached_inside
);
4138 write_indent (outf
, indent
+ 2);
4139 fprintf (outf
, "}\n");
4140 our_known_true
= newexp
;
4145 write_indent (outf
, indent
);
4146 fprintf (outf
, "else\n");
4147 write_indent (outf
, indent
+ 2);
4148 fprintf (outf
, "{\n");
4151 write_attr_set (outf
, attr
, first_if
? indent
: indent
+ 4, default_val
,
4152 prefix
, suffix
, our_known_true
, insn_code
, insn_index
,
4157 write_indent (outf
, indent
+ 2);
4158 fprintf (outf
, "}\n");
4163 write_indent (outf
, indent
);
4164 fprintf (outf
, "%s ", prefix
);
4165 write_attr_value (outf
, attr
, value
);
4166 fprintf (outf
, "%s\n", suffix
);
4170 /* Write a series of case statements for every instruction in list IE.
4171 INDENT is the amount of indentation to write before each case. */
4174 write_insn_cases (FILE *outf
, struct insn_ent
*ie
, int indent
)
4176 for (; ie
!= 0; ie
= ie
->next
)
4177 if (ie
->def
->insn_code
!= -1)
4179 write_indent (outf
, indent
);
4180 if (GET_CODE (ie
->def
->def
) == DEFINE_PEEPHOLE
)
4181 fprintf (outf
, "case %d: /* define_peephole, %s:%d */\n",
4182 ie
->def
->insn_code
, ie
->def
->loc
.filename
,
4183 ie
->def
->loc
.lineno
);
4185 fprintf (outf
, "case %d: /* %s */\n",
4186 ie
->def
->insn_code
, XSTR (ie
->def
->def
, 0));
4190 /* Write out the computation for one attribute value. */
4193 write_attr_case (FILE *outf
, struct attr_desc
*attr
, struct attr_value
*av
,
4194 int write_case_lines
, const char *prefix
, const char *suffix
,
4195 int indent
, rtx known_true
)
4197 if (av
->num_insns
== 0)
4200 if (av
->has_asm_insn
)
4202 write_indent (outf
, indent
);
4203 fprintf (outf
, "case -1:\n");
4204 write_indent (outf
, indent
+ 2);
4205 fprintf (outf
, "if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
4206 write_indent (outf
, indent
+ 2);
4207 fprintf (outf
, " && asm_noperands (PATTERN (insn)) < 0)\n");
4208 write_indent (outf
, indent
+ 2);
4209 fprintf (outf
, " fatal_insn_not_found (insn);\n");
4210 write_indent (outf
, indent
+ 2);
4211 fprintf (outf
, "/* FALLTHRU */\n");
4214 if (write_case_lines
)
4215 write_insn_cases (outf
, av
->first_insn
, indent
);
4218 write_indent (outf
, indent
);
4219 fprintf (outf
, "default:\n");
4222 /* See what we have to do to output this value. */
4223 must_extract
= must_constrain
= address_used
= 0;
4224 walk_attr_value (av
->value
);
4228 write_indent (outf
, indent
+ 2);
4229 fprintf (outf
, "extract_constrain_insn_cached (insn);\n");
4231 else if (must_extract
)
4233 write_indent (outf
, indent
+ 2);
4234 fprintf (outf
, "extract_insn_cached (insn);\n");
4238 if (av
->num_insns
== 1)
4239 write_attr_set (outf
, attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4240 known_true
, av
->first_insn
->def
->insn_code
,
4241 av
->first_insn
->def
->insn_index
, 0);
4243 write_attr_set (outf
, attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4244 known_true
, -2, 0, 0);
4246 if (strncmp (prefix
, "return", 6))
4248 write_indent (outf
, indent
+ 2);
4249 fprintf (outf
, "break;\n");
4251 fprintf (outf
, "\n");
4254 /* Utilities to write in various forms. */
4257 write_attr_valueq (FILE *outf
, struct attr_desc
*attr
, const char *s
)
4259 if (attr
->is_numeric
)
4263 fprintf (outf
, "%d", num
);
4265 if (num
> 9 || num
< 0)
4266 fprintf (outf
, " /* %#x */", num
);
4270 write_upcase (outf
, attr
->enum_name
? attr
->enum_name
: attr
->name
);
4271 fprintf (outf
, "_");
4272 write_upcase (outf
, s
);
4277 write_attr_value (FILE *outf
, struct attr_desc
*attr
, rtx value
)
4281 switch (GET_CODE (value
))
4284 write_attr_valueq (outf
, attr
, XSTR (value
, 0));
4288 fprintf (outf
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (value
));
4292 rtx_reader_ptr
->fprint_c_condition (outf
, XSTR (value
, 0));
4297 struct attr_desc
*attr2
= find_attr (&XSTR (value
, 0), 0);
4298 if (attr
->enum_name
)
4299 fprintf (outf
, "(enum %s)", attr
->enum_name
);
4300 else if (!attr
->is_numeric
)
4301 fprintf (outf
, "(enum attr_%s)", attr
->name
);
4302 else if (!attr2
->is_numeric
)
4303 fprintf (outf
, "(int)");
4305 fprintf (outf
, "get_attr_%s (%s)", attr2
->name
,
4306 (attr2
->is_const
? "" : "insn"));
4327 write_attr_value (outf
, attr
, XEXP (value
, 0));
4331 write_attr_value (outf
, attr
, XEXP (value
, 1));
4340 write_upcase (FILE *outf
, const char *str
)
4344 /* The argument of TOUPPER should not have side effects. */
4345 fputc (TOUPPER (*str
), outf
);
4351 write_indent (FILE *outf
, int indent
)
4353 for (; indent
> 8; indent
-= 8)
4354 fprintf (outf
, "\t");
4356 for (; indent
; indent
--)
4357 fprintf (outf
, " ");
4360 /* If the target does not have annul-true or annul-false delay slots, this
4361 function will create a dummy eligible_for function on OUTF which always
4362 returns false. KIND will be annul_true or annul_false. */
4365 write_dummy_eligible_delay (FILE *outf
, const char *kind
)
4367 /* Write function prelude. */
4369 fprintf (outf
, "int\n");
4370 fprintf (outf
, "eligible_for_%s (rtx_insn *delay_insn ATTRIBUTE_UNUSED,\n"
4371 " int slot ATTRIBUTE_UNUSED,\n"
4372 " rtx_insn *candidate_insn ATTRIBUTE_UNUSED,\n"
4373 " int flags ATTRIBUTE_UNUSED)\n",
4375 fprintf (outf
, "{\n");
4376 fprintf (outf
, " return 0;\n");
4377 fprintf (outf
, "}\n\n");
4380 /* Write a subroutine that is given an insn that requires a delay slot, a
4381 delay slot ordinal, and a candidate insn. It returns nonzero if the
4382 candidate can be placed in the specified delay slot of the insn.
4384 We can write as many as three subroutines. `eligible_for_delay'
4385 handles normal delay slots, `eligible_for_annul_true' indicates that
4386 the specified insn can be annulled if the branch is true, and likewise
4387 for `eligible_for_annul_false'.
4389 KIND is a string distinguishing these three cases ("delay", "annul_true",
4390 or "annul_false"). */
4393 write_eligible_delay (FILE *outf
, const char *kind
)
4395 struct delay_desc
*delay
;
4399 struct attr_desc
*attr
;
4400 struct attr_value
*av
, *common_av
;
4403 /* Compute the maximum number of delay slots required. We use the delay
4404 ordinal times this number plus one, plus the slot number as an index into
4405 the appropriate predicate to test. */
4407 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
4408 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
4409 max_slots
= XVECLEN (delay
->def
, 1) / 3;
4411 /* Write function prelude. */
4413 fprintf (outf
, "int\n");
4414 fprintf (outf
, "eligible_for_%s (rtx_insn *delay_insn ATTRIBUTE_UNUSED, int slot, \n"
4415 " rtx_insn *candidate_insn, int flags ATTRIBUTE_UNUSED)\n",
4417 fprintf (outf
, "{\n");
4418 fprintf (outf
, " rtx_insn *insn ATTRIBUTE_UNUSED;\n");
4419 fprintf (outf
, "\n");
4420 fprintf (outf
, " if (num_delay_slots (delay_insn) == 0)\n");
4421 fprintf (outf
, " return 0;");
4422 fprintf (outf
, "\n");
4423 fprintf (outf
, " gcc_assert (slot < %d);\n", max_slots
);
4424 fprintf (outf
, "\n");
4425 /* Allow dbr_schedule to pass labels, etc. This can happen if try_split
4426 converts a compound instruction into a loop. */
4427 fprintf (outf
, " if (!INSN_P (candidate_insn))\n");
4428 fprintf (outf
, " return 0;\n");
4429 fprintf (outf
, "\n");
4431 /* If more than one delay type, find out which type the delay insn is. */
4435 attr
= find_attr (&delay_type_str
, 0);
4437 common_av
= find_most_used (attr
);
4439 fprintf (outf
, " insn = delay_insn;\n");
4440 fprintf (outf
, " switch (recog_memoized (insn))\n");
4441 fprintf (outf
, " {\n");
4443 sprintf (str
, " * %d;\n break;", max_slots
);
4444 for (av
= attr
->first_value
; av
; av
= av
->next
)
4445 if (av
!= common_av
)
4446 write_attr_case (outf
, attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
4448 write_attr_case (outf
, attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
4449 fprintf (outf
, " }\n\n");
4451 /* Ensure matched. Otherwise, shouldn't have been called. */
4452 fprintf (outf
, " gcc_assert (slot >= %d);\n\n", max_slots
);
4455 /* If just one type of delay slot, write simple switch. */
4456 if (num_delays
== 1 && max_slots
== 1)
4458 fprintf (outf
, " insn = candidate_insn;\n");
4459 fprintf (outf
, " switch (recog_memoized (insn))\n");
4460 fprintf (outf
, " {\n");
4462 attr
= find_attr (&delay_1_0_str
, 0);
4464 common_av
= find_most_used (attr
);
4466 for (av
= attr
->first_value
; av
; av
= av
->next
)
4467 if (av
!= common_av
)
4468 write_attr_case (outf
, attr
, av
, 1, "return", ";", 4, true_rtx
);
4470 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4471 fprintf (outf
, " }\n");
4476 /* Write a nested CASE. The first indicates which condition we need to
4477 test, and the inner CASE tests the condition. */
4478 fprintf (outf
, " insn = candidate_insn;\n");
4479 fprintf (outf
, " switch (slot)\n");
4480 fprintf (outf
, " {\n");
4482 for (delay
= delays
; delay
; delay
= delay
->next
)
4483 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
4485 fprintf (outf
, " case %d:\n",
4486 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
4487 fprintf (outf
, " switch (recog_memoized (insn))\n");
4488 fprintf (outf
, "\t{\n");
4490 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
4492 attr
= find_attr (&pstr
, 0);
4494 common_av
= find_most_used (attr
);
4496 for (av
= attr
->first_value
; av
; av
= av
->next
)
4497 if (av
!= common_av
)
4498 write_attr_case (outf
, attr
, av
, 1, "return", ";", 8, true_rtx
);
4500 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 8, true_rtx
);
4501 fprintf (outf
, " }\n");
4504 fprintf (outf
, " default:\n");
4505 fprintf (outf
, " gcc_unreachable ();\n");
4506 fprintf (outf
, " }\n");
4509 fprintf (outf
, "}\n\n");
4512 /* This page contains miscellaneous utility routines. */
4514 /* Given a pointer to a (char *), return a malloc'ed string containing the
4515 next comma-separated element. Advance the pointer to after the string
4516 scanned, or the end-of-string. Return NULL if at end of string. */
4519 next_comma_elt (const char **pstr
)
4523 start
= scan_comma_elt (pstr
);
4528 return attr_string (start
, *pstr
- start
);
4531 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
4532 is nonzero, build a new attribute, if one does not exist. *NAME_P is
4533 replaced by a pointer to a canonical copy of the string. */
4535 static struct attr_desc
*
4536 find_attr (const char **name_p
, int create
)
4538 struct attr_desc
*attr
;
4540 const char *name
= *name_p
;
4542 /* Before we resort to using `strcmp', see if the string address matches
4543 anywhere. In most cases, it should have been canonicalized to do so. */
4544 if (name
== alternative_name
)
4547 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
4548 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4549 if (name
== attr
->name
)
4552 /* Otherwise, do it the slow way. */
4553 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4554 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
4556 *name_p
= attr
->name
;
4563 attr
= oballoc (struct attr_desc
);
4564 attr
->name
= DEF_ATTR_STRING (name
);
4565 attr
->enum_name
= 0;
4566 attr
->first_value
= attr
->default_val
= NULL
;
4567 attr
->is_numeric
= attr
->is_const
= attr
->is_special
= 0;
4568 attr
->next
= attrs
[index
];
4569 attrs
[index
] = attr
;
4571 *name_p
= attr
->name
;
4576 /* Create internal attribute with the given default value. */
4579 make_internal_attr (const char *name
, rtx value
, int special
)
4581 struct attr_desc
*attr
;
4583 attr
= find_attr (&name
, 1);
4584 gcc_assert (!attr
->default_val
);
4586 attr
->is_numeric
= 1;
4588 attr
->is_special
= (special
& ATTR_SPECIAL
) != 0;
4589 attr
->default_val
= get_attr_value (file_location ("<internal>", 0, 0),
4593 /* Find the most used value of an attribute. */
4595 static struct attr_value
*
4596 find_most_used (struct attr_desc
*attr
)
4598 struct attr_value
*av
;
4599 struct attr_value
*most_used
;
4605 for (av
= attr
->first_value
; av
; av
= av
->next
)
4606 if (av
->num_insns
> nuses
)
4607 nuses
= av
->num_insns
, most_used
= av
;
4612 /* Return (attr_value "n") */
4615 make_numeric_value (int n
)
4617 static rtx int_values
[20];
4621 gcc_assert (n
>= 0);
4623 if (n
< 20 && int_values
[n
])
4624 return int_values
[n
];
4626 p
= attr_printf (MAX_DIGITS
, "%d", n
);
4627 exp
= attr_rtx (CONST_STRING
, p
);
4630 int_values
[n
] = exp
;
4636 copy_rtx_unchanging (rtx orig
)
4638 if (ATTR_IND_SIMPLIFIED_P (orig
) || ATTR_CURR_SIMPLIFIED_P (orig
))
4641 ATTR_CURR_SIMPLIFIED_P (orig
) = 1;
4645 /* Determine if an insn has a constant number of delay slots, i.e., the
4646 number of delay slots is not a function of the length of the insn. */
4649 write_const_num_delay_slots (FILE *outf
)
4651 struct attr_desc
*attr
= find_attr (&num_delay_slots_str
, 0);
4652 struct attr_value
*av
;
4656 fprintf (outf
, "int\nconst_num_delay_slots (rtx_insn *insn)\n");
4657 fprintf (outf
, "{\n");
4658 fprintf (outf
, " switch (recog_memoized (insn))\n");
4659 fprintf (outf
, " {\n");
4661 for (av
= attr
->first_value
; av
; av
= av
->next
)
4664 walk_attr_value (av
->value
);
4666 write_insn_cases (outf
, av
->first_insn
, 4);
4669 fprintf (outf
, " default:\n");
4670 fprintf (outf
, " return 1;\n");
4671 fprintf (outf
, " }\n}\n\n");
4675 /* Synthetic attributes used by insn-automata.c and the scheduler.
4676 These are primarily concerned with (define_insn_reservation)
4681 struct insn_reserv
*next
;
4684 int default_latency
;
4687 /* Sequence number of this insn. */
4690 /* Whether a (define_bypass) construct names this insn in its
4695 static struct insn_reserv
*all_insn_reservs
= 0;
4696 static struct insn_reserv
**last_insn_reserv_p
= &all_insn_reservs
;
4697 static size_t n_insn_reservs
;
4699 /* Store information from a DEFINE_INSN_RESERVATION for future
4700 attribute generation. */
4702 gen_insn_reserv (md_rtx_info
*info
)
4704 struct insn_reserv
*decl
= oballoc (struct insn_reserv
);
4705 rtx def
= info
->def
;
4707 struct attr_desc attr
= { };
4709 attr
.name
= DEF_ATTR_STRING (XSTR (def
, 0));
4710 attr
.loc
= info
->loc
;
4712 decl
->name
= DEF_ATTR_STRING (XSTR (def
, 0));
4713 decl
->default_latency
= XINT (def
, 1);
4714 decl
->condexp
= check_attr_test (info
->loc
, XEXP (def
, 2), &attr
);
4715 decl
->insn_num
= n_insn_reservs
;
4716 decl
->bypassed
= false;
4719 *last_insn_reserv_p
= decl
;
4720 last_insn_reserv_p
= &decl
->next
;
4724 /* Store information from a DEFINE_BYPASS for future attribute
4725 generation. The only thing we care about is the list of output
4726 insns, which will later be used to tag reservation structures with
4727 a 'bypassed' bit. */
4731 struct bypass_list
*next
;
4732 const char *pattern
;
4735 static struct bypass_list
*all_bypasses
;
4736 static size_t n_bypasses
;
4737 static size_t n_bypassed
;
4740 gen_bypass_1 (const char *s
, size_t len
)
4742 struct bypass_list
*b
;
4747 s
= attr_string (s
, len
);
4748 for (b
= all_bypasses
; b
; b
= b
->next
)
4749 if (s
== b
->pattern
)
4750 return; /* already got that one */
4752 b
= oballoc (struct bypass_list
);
4754 b
->next
= all_bypasses
;
4760 gen_bypass (md_rtx_info
*info
)
4762 const char *p
, *base
;
4764 rtx def
= info
->def
;
4765 for (p
= base
= XSTR (def
, 1); *p
; p
++)
4768 gen_bypass_1 (base
, p
- base
);
4771 while (ISSPACE (*p
));
4774 gen_bypass_1 (base
, p
- base
);
4777 /* Find and mark all of the bypassed insns. */
4779 process_bypasses (void)
4781 struct bypass_list
*b
;
4782 struct insn_reserv
*r
;
4786 /* The reservation list is likely to be much longer than the bypass
4788 for (r
= all_insn_reservs
; r
; r
= r
->next
)
4789 for (b
= all_bypasses
; b
; b
= b
->next
)
4790 if (fnmatch (b
->pattern
, r
->name
, 0) == 0)
4798 /* Check that attribute NAME is used in define_insn_reservation condition
4799 EXP. Return true if it is. */
4801 check_tune_attr (const char *name
, rtx exp
)
4803 switch (GET_CODE (exp
))
4806 if (check_tune_attr (name
, XEXP (exp
, 0)))
4808 return check_tune_attr (name
, XEXP (exp
, 1));
4811 return (check_tune_attr (name
, XEXP (exp
, 0))
4812 && check_tune_attr (name
, XEXP (exp
, 1)));
4815 return XSTR (exp
, 0) == name
;
4822 /* Try to find a const attribute (usually cpu or tune) that is used
4823 in all define_insn_reservation conditions. */
4824 static struct attr_desc
*
4825 find_tune_attr (rtx exp
)
4827 struct attr_desc
*attr
;
4829 switch (GET_CODE (exp
))
4833 attr
= find_tune_attr (XEXP (exp
, 0));
4836 return find_tune_attr (XEXP (exp
, 1));
4839 if (XSTR (exp
, 0) == alternative_name
)
4842 attr
= find_attr (&XSTR (exp
, 0), 0);
4845 if (attr
->is_const
&& !attr
->is_special
)
4847 struct insn_reserv
*decl
;
4849 for (decl
= all_insn_reservs
; decl
; decl
= decl
->next
)
4850 if (! check_tune_attr (attr
->name
, decl
->condexp
))
4861 /* Create all of the attributes that describe automaton properties.
4862 Write the DFA and latency function prototypes to the files that
4863 need to have them, and write the init_sched_attrs(). */
4866 make_automaton_attrs (void)
4869 struct insn_reserv
*decl
;
4870 rtx code_exp
, lats_exp
, byps_exp
;
4871 struct attr_desc
*tune_attr
;
4873 if (n_insn_reservs
== 0)
4876 tune_attr
= find_tune_attr (all_insn_reservs
->condexp
);
4877 if (tune_attr
!= NULL
)
4879 rtx
*condexps
= XNEWVEC (rtx
, n_insn_reservs
* 3);
4880 struct attr_value
*val
;
4883 gcc_assert (tune_attr
->is_const
4884 && !tune_attr
->is_special
4885 && !tune_attr
->is_numeric
);
4887 /* Write the prototypes for all DFA functions. */
4888 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4890 if (val
== tune_attr
->default_val
)
4892 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4894 "extern int internal_dfa_insn_code_%s (rtx_insn *);\n",
4895 XSTR (val
->value
, 0));
4897 fprintf (dfa_file
, "\n");
4899 /* Write the prototypes for all latency functions. */
4900 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4902 if (val
== tune_attr
->default_val
)
4904 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4905 fprintf (latency_file
,
4906 "extern int insn_default_latency_%s (rtx_insn *);\n",
4907 XSTR (val
->value
, 0));
4909 fprintf (latency_file
, "\n");
4911 /* Write the prototypes for all automaton functions. */
4912 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4914 if (val
== tune_attr
->default_val
)
4916 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4918 "extern int internal_dfa_insn_code_%s (rtx_insn *);\n"
4919 "extern int insn_default_latency_%s (rtx_insn *);\n",
4920 XSTR (val
->value
, 0), XSTR (val
->value
, 0));
4922 fprintf (attr_file
, "\n");
4923 fprintf (attr_file
, "int (*internal_dfa_insn_code) (rtx_insn *);\n");
4924 fprintf (attr_file
, "int (*insn_default_latency) (rtx_insn *);\n");
4925 fprintf (attr_file
, "\n");
4926 fprintf (attr_file
, "void\n");
4927 fprintf (attr_file
, "init_sched_attrs (void)\n");
4928 fprintf (attr_file
, "{\n");
4930 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4934 rtx test
= attr_eq (tune_attr
->name
, XSTR (val
->value
, 0));
4936 if (val
== tune_attr
->default_val
)
4938 for (decl
= all_insn_reservs
, i
= 0;
4944 = simplify_and_tree (decl
->condexp
, &ctest
, -2, 0);
4945 if (condexp
== false_rtx
)
4947 if (condexp
== true_rtx
)
4949 condexps
[i
] = condexp
;
4950 condexps
[i
+ 1] = make_numeric_value (decl
->insn_num
);
4951 condexps
[i
+ 2] = make_numeric_value (decl
->default_latency
);
4955 code_exp
= rtx_alloc (COND
);
4956 lats_exp
= rtx_alloc (COND
);
4959 XVEC (code_exp
, 0) = rtvec_alloc (j
);
4960 XVEC (lats_exp
, 0) = rtvec_alloc (j
);
4964 XEXP (code_exp
, 1) = make_numeric_value (decl
->insn_num
);
4965 XEXP (lats_exp
, 1) = make_numeric_value (decl
->default_latency
);
4969 XEXP (code_exp
, 1) = make_numeric_value (n_insn_reservs
+ 1);
4970 XEXP (lats_exp
, 1) = make_numeric_value (0);
4977 XVECEXP (code_exp
, 0, j
) = condexps
[i
];
4978 XVECEXP (lats_exp
, 0, j
) = condexps
[i
];
4980 XVECEXP (code_exp
, 0, j
+ 1) = condexps
[i
+ 1];
4981 XVECEXP (lats_exp
, 0, j
+ 1) = condexps
[i
+ 2];
4984 name
= XNEWVEC (char,
4985 sizeof ("*internal_dfa_insn_code_")
4986 + strlen (XSTR (val
->value
, 0)));
4987 strcpy (name
, "*internal_dfa_insn_code_");
4988 strcat (name
, XSTR (val
->value
, 0));
4989 make_internal_attr (name
, code_exp
, ATTR_NONE
);
4990 strcpy (name
, "*insn_default_latency_");
4991 strcat (name
, XSTR (val
->value
, 0));
4992 make_internal_attr (name
, lats_exp
, ATTR_NONE
);
4997 fprintf (attr_file
, " if (");
5001 fprintf (attr_file
, " else if (");
5002 write_test_expr (attr_file
, test
, 0, 0);
5003 fprintf (attr_file
, ")\n");
5004 fprintf (attr_file
, " {\n");
5005 fprintf (attr_file
, " internal_dfa_insn_code\n");
5006 fprintf (attr_file
, " = internal_dfa_insn_code_%s;\n",
5007 XSTR (val
->value
, 0));
5008 fprintf (attr_file
, " insn_default_latency\n");
5009 fprintf (attr_file
, " = insn_default_latency_%s;\n",
5010 XSTR (val
->value
, 0));
5011 fprintf (attr_file
, " }\n");
5014 fprintf (attr_file
, " else\n");
5015 fprintf (attr_file
, " gcc_unreachable ();\n");
5016 fprintf (attr_file
, "}\n");
5017 fprintf (attr_file
, "\n");
5019 XDELETEVEC (condexps
);
5023 code_exp
= rtx_alloc (COND
);
5024 lats_exp
= rtx_alloc (COND
);
5026 XVEC (code_exp
, 0) = rtvec_alloc (n_insn_reservs
* 2);
5027 XVEC (lats_exp
, 0) = rtvec_alloc (n_insn_reservs
* 2);
5029 XEXP (code_exp
, 1) = make_numeric_value (n_insn_reservs
+ 1);
5030 XEXP (lats_exp
, 1) = make_numeric_value (0);
5032 for (decl
= all_insn_reservs
, i
= 0;
5034 decl
= decl
->next
, i
+= 2)
5036 XVECEXP (code_exp
, 0, i
) = decl
->condexp
;
5037 XVECEXP (lats_exp
, 0, i
) = decl
->condexp
;
5039 XVECEXP (code_exp
, 0, i
+1) = make_numeric_value (decl
->insn_num
);
5040 XVECEXP (lats_exp
, 0, i
+1)
5041 = make_numeric_value (decl
->default_latency
);
5043 make_internal_attr ("*internal_dfa_insn_code", code_exp
, ATTR_NONE
);
5044 make_internal_attr ("*insn_default_latency", lats_exp
, ATTR_NONE
);
5047 if (n_bypasses
== 0)
5048 byps_exp
= make_numeric_value (0);
5051 process_bypasses ();
5053 byps_exp
= rtx_alloc (COND
);
5054 XVEC (byps_exp
, 0) = rtvec_alloc (n_bypassed
* 2);
5055 XEXP (byps_exp
, 1) = make_numeric_value (0);
5056 for (decl
= all_insn_reservs
, i
= 0;
5061 XVECEXP (byps_exp
, 0, i
) = decl
->condexp
;
5062 XVECEXP (byps_exp
, 0, i
+1) = make_numeric_value (1);
5067 make_internal_attr ("*bypass_p", byps_exp
, ATTR_NONE
);
5071 write_header (FILE *outf
)
5073 fprintf (outf
, "/* Generated automatically by the program `genattrtab'\n"
5074 " from the machine description file `md'. */\n\n");
5076 fprintf (outf
, "#define IN_TARGET_CODE 1\n");
5077 fprintf (outf
, "#include \"config.h\"\n");
5078 fprintf (outf
, "#include \"system.h\"\n");
5079 fprintf (outf
, "#include \"coretypes.h\"\n");
5080 fprintf (outf
, "#include \"backend.h\"\n");
5081 fprintf (outf
, "#include \"predict.h\"\n");
5082 fprintf (outf
, "#include \"tree.h\"\n");
5083 fprintf (outf
, "#include \"rtl.h\"\n");
5084 fprintf (outf
, "#include \"alias.h\"\n");
5085 fprintf (outf
, "#include \"options.h\"\n");
5086 fprintf (outf
, "#include \"varasm.h\"\n");
5087 fprintf (outf
, "#include \"stor-layout.h\"\n");
5088 fprintf (outf
, "#include \"calls.h\"\n");
5089 fprintf (outf
, "#include \"insn-attr.h\"\n");
5090 fprintf (outf
, "#include \"memmodel.h\"\n");
5091 fprintf (outf
, "#include \"tm_p.h\"\n");
5092 fprintf (outf
, "#include \"insn-config.h\"\n");
5093 fprintf (outf
, "#include \"recog.h\"\n");
5094 fprintf (outf
, "#include \"regs.h\"\n");
5095 fprintf (outf
, "#include \"real.h\"\n");
5096 fprintf (outf
, "#include \"output.h\"\n");
5097 fprintf (outf
, "#include \"toplev.h\"\n");
5098 fprintf (outf
, "#include \"flags.h\"\n");
5099 fprintf (outf
, "#include \"emit-rtl.h\"\n");
5100 fprintf (outf
, "\n");
5101 fprintf (outf
, "#define operands recog_data.operand\n\n");
5105 open_outfile (const char *file_name
)
5108 outf
= fopen (file_name
, "w");
5110 fatal ("cannot open file %s: %s", file_name
, xstrerror (errno
));
5111 write_header (outf
);
5116 handle_arg (const char *arg
)
5121 attr_file_name
= &arg
[2];
5124 dfa_file_name
= &arg
[2];
5127 latency_file_name
= &arg
[2];
5135 main (int argc
, const char **argv
)
5137 struct attr_desc
*attr
;
5138 struct insn_def
*id
;
5141 progname
= "genattrtab";
5143 if (!init_rtx_reader_args_cb (argc
, argv
, handle_arg
))
5144 return FATAL_EXIT_CODE
;
5146 attr_file
= open_outfile (attr_file_name
);
5147 dfa_file
= open_outfile (dfa_file_name
);
5148 latency_file
= open_outfile (latency_file_name
);
5150 obstack_init (hash_obstack
);
5151 obstack_init (temp_obstack
);
5153 /* Set up true and false rtx's */
5154 true_rtx
= rtx_alloc (CONST_INT
);
5155 XWINT (true_rtx
, 0) = 1;
5156 false_rtx
= rtx_alloc (CONST_INT
);
5157 XWINT (false_rtx
, 0) = 0;
5158 ATTR_IND_SIMPLIFIED_P (true_rtx
) = ATTR_IND_SIMPLIFIED_P (false_rtx
) = 1;
5159 ATTR_PERMANENT_P (true_rtx
) = ATTR_PERMANENT_P (false_rtx
) = 1;
5161 alternative_name
= DEF_ATTR_STRING ("alternative");
5162 length_str
= DEF_ATTR_STRING ("length");
5163 delay_type_str
= DEF_ATTR_STRING ("*delay_type");
5164 delay_1_0_str
= DEF_ATTR_STRING ("*delay_1_0");
5165 num_delay_slots_str
= DEF_ATTR_STRING ("*num_delay_slots");
5167 /* Read the machine description. */
5170 while (read_md_rtx (&info
))
5172 switch (GET_CODE (info
.def
))
5175 case DEFINE_PEEPHOLE
:
5176 case DEFINE_ASM_ATTRIBUTES
:
5181 case DEFINE_ENUM_ATTR
:
5189 case DEFINE_INSN_RESERVATION
:
5190 gen_insn_reserv (&info
);
5200 if (GET_CODE (info
.def
) != DEFINE_ASM_ATTRIBUTES
)
5201 insn_index_number
++;
5205 return FATAL_EXIT_CODE
;
5207 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
5208 if (! got_define_asm_attributes
)
5211 info
.def
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
5212 XVEC (info
.def
, 0) = rtvec_alloc (0);
5213 info
.loc
= file_location ("<internal>", 0, 0);
5218 /* Expand DEFINE_DELAY information into new attribute. */
5221 /* Make `insn_alternatives'. */
5222 int num_insn_codes
= get_num_insn_codes ();
5223 insn_alternatives
= oballocvec (uint64_t, num_insn_codes
);
5224 for (id
= defs
; id
; id
= id
->next
)
5225 if (id
->insn_code
>= 0)
5226 insn_alternatives
[id
->insn_code
]
5227 = (((uint64_t) 1) << id
->num_alternatives
) - 1;
5229 /* Make `insn_n_alternatives'. */
5230 insn_n_alternatives
= oballocvec (int, num_insn_codes
);
5231 for (id
= defs
; id
; id
= id
->next
)
5232 if (id
->insn_code
>= 0)
5233 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
5235 /* Construct extra attributes for automata. */
5236 make_automaton_attrs ();
5238 /* Prepare to write out attribute subroutines by checking everything stored
5239 away and building the attribute cases. */
5243 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5244 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5245 attr
->default_val
->value
5246 = check_attr_value (attr
->loc
, attr
->default_val
->value
, attr
);
5249 return FATAL_EXIT_CODE
;
5251 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5252 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5255 /* Construct extra attributes for `length'. */
5256 make_length_attrs ();
5258 /* Perform any possible optimizations to speed up compilation. */
5259 optimize_attrs (num_insn_codes
);
5261 /* Now write out all the `gen_attr_...' routines. Do these before the
5262 special routines so that they get defined before they are used. */
5264 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5265 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5269 #define IS_ATTR_GROUP(X) (!strncmp (attr->name, X, strlen (X)))
5270 if (IS_ATTR_GROUP ("*internal_dfa_insn_code"))
5272 else if (IS_ATTR_GROUP ("*insn_default_latency"))
5273 outf
= latency_file
;
5276 #undef IS_ATTR_GROUP
5278 if (! attr
->is_special
&& ! attr
->is_const
)
5279 write_attr_get (outf
, attr
);
5282 /* Write out delay eligibility information, if DEFINE_DELAY present.
5283 (The function to compute the number of delay slots will be written
5285 write_eligible_delay (attr_file
, "delay");
5286 if (have_annul_true
)
5287 write_eligible_delay (attr_file
, "annul_true");
5289 write_dummy_eligible_delay (attr_file
, "annul_true");
5290 if (have_annul_false
)
5291 write_eligible_delay (attr_file
, "annul_false");
5293 write_dummy_eligible_delay (attr_file
, "annul_false");
5295 /* Write out constant delay slot info. */
5296 write_const_num_delay_slots (attr_file
);
5298 write_length_unit_log (attr_file
);
5300 if (fclose (attr_file
) != 0)
5301 fatal ("cannot close file %s: %s", attr_file_name
, xstrerror (errno
));
5302 if (fclose (dfa_file
) != 0)
5303 fatal ("cannot close file %s: %s", dfa_file_name
, xstrerror (errno
));
5304 if (fclose (latency_file
) != 0)
5305 fatal ("cannot close file %s: %s", latency_file_name
, xstrerror (errno
));
5307 return SUCCESS_EXIT_CODE
;