1 /* Generate code from machine description to compute values of attributes.
2 Copyright (C) 1991-2017 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
);
572 rtl_obstack
= old_obstack
;
573 attr_hash_add_rtx (hashcode
, rt_val
);
574 ATTR_PERMANENT_P (rt_val
) = permanent_p
;
579 attr_rtx (enum rtx_code code
, ...)
585 result
= attr_rtx_1 (code
, p
);
590 /* Create a new string printed with the printf line arguments into a space
591 of at most LEN bytes:
593 rtx attr_printf (len, format, [arg1, ..., argn]) */
596 attr_printf (unsigned int len
, const char *fmt
, ...)
603 gcc_assert (len
< sizeof str
); /* Leave room for \0. */
605 vsprintf (str
, fmt
, p
);
608 return DEF_ATTR_STRING (str
);
612 attr_eq (const char *name
, const char *value
)
614 return attr_rtx (EQ_ATTR
, name
, value
);
620 return XSTR (make_numeric_value (n
), 0);
623 /* Return a permanent (possibly shared) copy of a string STR (not assumed
624 to be null terminated) with LEN bytes. */
627 attr_string (const char *str
, int len
)
630 unsigned int hashcode
;
634 /* Compute the hash code. */
635 hashcode
= (len
+ 1) * 613U + (unsigned) str
[0];
636 for (i
= 1; i
< len
; i
+= 2)
637 hashcode
= ((hashcode
* 613) + (unsigned) str
[i
]);
638 if ((int) hashcode
< 0)
639 hashcode
= -hashcode
;
641 /* Search the table for the string. */
642 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
643 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
644 && !strncmp (h
->u
.str
, str
, len
))
645 return h
->u
.str
; /* <-- return if found. */
647 /* Not found; create a permanent copy and add it to the hash table. */
648 new_str
= XOBNEWVAR (hash_obstack
, char, len
+ 1);
649 memcpy (new_str
, str
, len
);
651 attr_hash_add_string (hashcode
, new_str
);
652 rtx_reader_ptr
->copy_md_ptr_loc (new_str
, str
);
654 return new_str
; /* Return the new string. */
657 /* Check two rtx's for equality of contents,
658 taking advantage of the fact that if both are hashed
659 then they can't be equal unless they are the same object. */
662 attr_equal_p (rtx x
, rtx y
)
664 return (x
== y
|| (! (ATTR_PERMANENT_P (x
) && ATTR_PERMANENT_P (y
))
665 && rtx_equal_p (x
, y
)));
668 /* Given a test expression EXP for attribute ATTR, ensure it is validly
669 formed. LOC is the location of the .md construct that contains EXP.
671 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
672 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
673 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
675 Update the string address in EQ_ATTR expression to be the same used
676 in the attribute (or `alternative_name') to speed up subsequent
677 `find_attr' calls and eliminate most `strcmp' calls.
679 Return the new expression, if any. */
682 check_attr_test (file_location loc
, rtx exp
, attr_desc
*attr
)
684 struct attr_value
*av
;
685 const char *name_ptr
, *p
;
688 switch (GET_CODE (exp
))
691 /* Handle negation test. */
692 if (XSTR (exp
, 1)[0] == '!')
693 return check_attr_test (loc
,
695 attr_eq (XSTR (exp
, 0),
699 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
701 attr_desc
*attr2
= find_attr (&XSTR (exp
, 0), 0);
704 if (! strcmp (XSTR (exp
, 0), "alternative"))
705 return mk_attr_alt (((uint64_t) 1) << atoi (XSTR (exp
, 1)));
707 fatal_at (loc
, "unknown attribute `%s' in definition of"
708 " attribute `%s'", XSTR (exp
, 0), attr
->name
);
711 if (attr
->is_const
&& ! attr2
->is_const
)
712 fatal_at (loc
, "constant attribute `%s' cannot test non-constant"
713 " attribute `%s'", attr
->name
, attr2
->name
);
715 /* Copy this just to make it permanent,
716 so expressions using it can be permanent too. */
717 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
719 /* It shouldn't be possible to simplify the value given to a
720 constant attribute, so don't expand this until it's time to
721 write the test expression. */
723 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
725 if (attr2
->is_numeric
)
727 for (p
= XSTR (exp
, 1); *p
; p
++)
729 fatal_at (loc
, "attribute `%s' takes only numeric values",
734 for (av
= attr2
->first_value
; av
; av
= av
->next
)
735 if (GET_CODE (av
->value
) == CONST_STRING
736 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
740 fatal_at (loc
, "unknown value `%s' for attribute `%s'",
741 XSTR (exp
, 1), attr2
->name
);
746 if (! strcmp (XSTR (exp
, 0), "alternative"))
750 name_ptr
= XSTR (exp
, 1);
751 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
752 set
|= ((uint64_t) 1) << atoi (p
);
754 return mk_attr_alt (set
);
758 /* Make an IOR tree of the possible values. */
760 name_ptr
= XSTR (exp
, 1);
761 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
763 newexp
= attr_eq (XSTR (exp
, 0), p
);
764 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
767 return check_attr_test (loc
, orexp
, attr
);
776 /* Either TRUE or FALSE. */
784 XEXP (exp
, 0) = check_attr_test (loc
, XEXP (exp
, 0), attr
);
785 XEXP (exp
, 1) = check_attr_test (loc
, XEXP (exp
, 1), attr
);
789 XEXP (exp
, 0) = check_attr_test (loc
, XEXP (exp
, 0), attr
);
793 exp
= attr_rtx (MATCH_TEST
, XSTR (exp
, 0));
794 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
799 fatal_at (loc
, "invalid operator `%s' in definition of constant"
800 " attribute `%s'", GET_RTX_NAME (GET_CODE (exp
)),
802 /* These cases can't be simplified. */
803 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
806 case LE
: case LT
: case GT
: case GE
:
807 case LEU
: case LTU
: case GTU
: case GEU
:
809 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
810 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
811 exp
= attr_rtx (GET_CODE (exp
),
812 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
813 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
814 /* These cases can't be simplified. */
815 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
821 /* These cases are valid for constant attributes, but can't be
823 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
824 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
829 fatal_at (loc
, "invalid operator `%s' in definition of attribute"
830 " `%s'", GET_RTX_NAME (GET_CODE (exp
)), attr
->name
);
836 /* Given an expression EXP, ensure that it is validly formed and that
837 all named attribute values are valid for ATTR. Issue an error if not.
838 LOC is the location of the .md construct that contains EXP.
840 Return a perhaps modified replacement expression for the value. */
843 check_attr_value (file_location loc
, rtx exp
, struct attr_desc
*attr
)
845 struct attr_value
*av
;
849 switch (GET_CODE (exp
))
852 if (!attr
->is_numeric
)
855 "CONST_INT not valid for non-numeric attribute `%s'",
860 if (INTVAL (exp
) < 0)
863 "negative numeric value specified for attribute `%s'",
870 if (! strcmp (XSTR (exp
, 0), "*"))
873 if (attr
->is_numeric
)
880 "non-numeric value specified for numeric"
881 " attribute `%s'", attr
->name
);
887 for (av
= attr
->first_value
; av
; av
= av
->next
)
888 if (GET_CODE (av
->value
) == CONST_STRING
889 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
893 error_at (loc
, "unknown value `%s' for attribute `%s'",
894 XSTR (exp
, 0), attr
->name
);
898 XEXP (exp
, 0) = check_attr_test (loc
, XEXP (exp
, 0), attr
);
899 XEXP (exp
, 1) = check_attr_value (loc
, XEXP (exp
, 1), attr
);
900 XEXP (exp
, 2) = check_attr_value (loc
, XEXP (exp
, 2), attr
);
908 if (!attr
->is_numeric
)
910 error_at (loc
, "invalid operation `%s' for non-numeric"
911 " attribute `%s'", GET_RTX_NAME (GET_CODE (exp
)),
919 XEXP (exp
, 0) = check_attr_value (loc
, XEXP (exp
, 0), attr
);
920 XEXP (exp
, 1) = check_attr_value (loc
, XEXP (exp
, 1), attr
);
929 XEXP (exp
, 0) = check_attr_value (loc
, XEXP (exp
, 0), attr
);
933 if (XVECLEN (exp
, 0) % 2 != 0)
935 error_at (loc
, "first operand of COND must have even length");
939 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
941 XVECEXP (exp
, 0, i
) = check_attr_test (attr
->loc
,
944 XVECEXP (exp
, 0, i
+ 1)
945 = check_attr_value (loc
, XVECEXP (exp
, 0, i
+ 1), attr
);
948 XEXP (exp
, 1) = check_attr_value (loc
, XEXP (exp
, 1), attr
);
953 struct attr_desc
*attr2
= find_attr (&XSTR (exp
, 0), 0);
955 error_at (loc
, "unknown attribute `%s' in ATTR",
957 else if (attr
->is_const
&& ! attr2
->is_const
)
959 "constant attribute `%s' cannot refer to non-constant"
960 " attribute `%s'", attr
->name
, attr2
->name
);
961 else if (attr
->is_numeric
!= attr2
->is_numeric
)
963 "numeric attribute mismatch calling `%s' from `%s'",
964 attr2
->name
, attr
->name
);
969 /* A constant SYMBOL_REF is valid as a constant attribute test and
970 is expanded later by make_canonical into a COND. In a non-constant
971 attribute test, it is left be. */
972 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
975 error_at (loc
, "invalid operator `%s' in definition of attribute `%s'",
976 GET_RTX_NAME (GET_CODE (exp
)), attr
->name
);
983 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
984 It becomes a COND with each test being (eq_attr "alternative" "n") */
987 convert_set_attr_alternative (rtx exp
, struct insn_def
*id
)
989 int num_alt
= id
->num_alternatives
;
993 if (XVECLEN (exp
, 1) != num_alt
)
995 error_at (id
->loc
, "bad number of entries in SET_ATTR_ALTERNATIVE,"
996 " was %d expected %d", XVECLEN (exp
, 1), num_alt
);
1000 /* Make a COND with all tests but the last. Select the last value via the
1002 condexp
= rtx_alloc (COND
);
1003 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1005 for (i
= 0; i
< num_alt
- 1; i
++)
1008 p
= attr_numeral (i
);
1010 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1011 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1014 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1016 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1019 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1020 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1023 convert_set_attr (rtx exp
, struct insn_def
*id
)
1026 const char *name_ptr
;
1030 /* See how many alternative specified. */
1031 n
= n_comma_elts (XSTR (exp
, 1));
1033 return attr_rtx (SET
,
1034 attr_rtx (ATTR
, XSTR (exp
, 0)),
1035 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1037 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1038 XSTR (newexp
, 0) = XSTR (exp
, 0);
1039 XVEC (newexp
, 1) = rtvec_alloc (n
);
1041 /* Process each comma-separated name. */
1042 name_ptr
= XSTR (exp
, 1);
1044 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1045 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1047 return convert_set_attr_alternative (newexp
, id
);
1050 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1051 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1057 struct insn_def
*id
;
1058 struct attr_desc
*attr
;
1062 for (id
= defs
; id
; id
= id
->next
)
1064 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1067 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1069 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1070 switch (GET_CODE (value
))
1073 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1075 error_at (id
->loc
, "bad attribute set");
1080 case SET_ATTR_ALTERNATIVE
:
1081 value
= convert_set_attr_alternative (value
, id
);
1085 value
= convert_set_attr (value
, id
);
1089 error_at (id
->loc
, "invalid attribute code %s",
1090 GET_RTX_NAME (GET_CODE (value
)));
1093 if (value
== NULL_RTX
)
1096 if ((attr
= find_attr (&XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1098 error_at (id
->loc
, "unknown attribute %s",
1099 XSTR (XEXP (value
, 0), 0));
1103 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1104 XEXP (value
, 1) = check_attr_value (id
->loc
, XEXP (value
, 1), attr
);
1109 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1110 expressions by converting them into a COND. This removes cases from this
1111 program. Also, replace an attribute value of "*" with the default attribute
1112 value. LOC is the location to use for error reporting. */
1115 make_canonical (file_location loc
, struct attr_desc
*attr
, rtx exp
)
1120 switch (GET_CODE (exp
))
1123 exp
= make_numeric_value (INTVAL (exp
));
1127 if (! strcmp (XSTR (exp
, 0), "*"))
1129 if (attr
->default_val
== 0)
1130 fatal_at (loc
, "(attr_value \"*\") used in invalid context");
1131 exp
= attr
->default_val
->value
;
1134 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1139 if (!attr
->is_const
|| ATTR_IND_SIMPLIFIED_P (exp
))
1141 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1142 This makes the COND something that won't be considered an arbitrary
1143 expression by walk_attr_value. */
1144 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1145 exp
= check_attr_value (loc
, exp
, attr
);
1149 newexp
= rtx_alloc (COND
);
1150 XVEC (newexp
, 0) = rtvec_alloc (2);
1151 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1152 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1154 XEXP (newexp
, 1) = XEXP (exp
, 2);
1157 /* Fall through to COND case since this is now a COND. */
1165 /* First, check for degenerate COND. */
1166 if (XVECLEN (exp
, 0) == 0)
1167 return make_canonical (loc
, attr
, XEXP (exp
, 1));
1168 defval
= XEXP (exp
, 1) = make_canonical (loc
, attr
, XEXP (exp
, 1));
1170 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1172 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1173 XVECEXP (exp
, 0, i
+ 1)
1174 = make_canonical (loc
, attr
, XVECEXP (exp
, 0, i
+ 1));
1175 if (! attr_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1191 copy_boolean (rtx exp
)
1193 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1194 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1195 copy_boolean (XEXP (exp
, 1)));
1196 else if (GET_CODE (exp
) == NOT
)
1197 return attr_rtx (NOT
, copy_boolean (XEXP (exp
, 0)));
1198 if (GET_CODE (exp
) == MATCH_OPERAND
)
1200 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1201 XSTR (exp
, 2) = DEF_ATTR_STRING (XSTR (exp
, 2));
1203 else if (GET_CODE (exp
) == EQ_ATTR
)
1205 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1206 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1212 /* Given a value and an attribute description, return a `struct attr_value *'
1213 that represents that value. This is either an existing structure, if the
1214 value has been previously encountered, or a newly-created structure.
1216 `insn_code' is the code of an insn whose attribute has the specified
1217 value (-2 if not processing an insn). We ensure that all insns for
1218 a given value have the same number of alternatives if the value checks
1219 alternatives. LOC is the location to use for error reporting. */
1221 static struct attr_value
*
1222 get_attr_value (file_location loc
, rtx value
, struct attr_desc
*attr
,
1225 struct attr_value
*av
;
1226 uint64_t num_alt
= 0;
1228 value
= make_canonical (loc
, attr
, value
);
1229 if (compares_alternatives_p (value
))
1231 if (insn_code
< 0 || insn_alternatives
== NULL
)
1232 fatal_at (loc
, "(eq_attr \"alternatives\" ...) used in non-insn"
1235 num_alt
= insn_alternatives
[insn_code
];
1238 for (av
= attr
->first_value
; av
; av
= av
->next
)
1239 if (attr_equal_p (value
, av
->value
)
1240 && (num_alt
== 0 || av
->first_insn
== NULL
1241 || insn_alternatives
[av
->first_insn
->def
->insn_code
]))
1244 av
= oballoc (struct attr_value
);
1246 av
->next
= attr
->first_value
;
1247 attr
->first_value
= av
;
1248 av
->first_insn
= NULL
;
1250 av
->has_asm_insn
= 0;
1255 /* After all DEFINE_DELAYs have been read in, create internal attributes
1256 to generate the required routines.
1258 First, we compute the number of delay slots for each insn (as a COND of
1259 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1260 delay type is specified, we compute a similar function giving the
1261 DEFINE_DELAY ordinal for each insn.
1263 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1264 tells whether a given insn can be in that delay slot.
1266 Normal attribute filling and optimization expands these to contain the
1267 information needed to handle delay slots. */
1270 expand_delays (void)
1272 struct delay_desc
*delay
;
1278 /* First, generate data for `num_delay_slots' function. */
1280 condexp
= rtx_alloc (COND
);
1281 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1282 XEXP (condexp
, 1) = make_numeric_value (0);
1284 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1286 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1287 XVECEXP (condexp
, 0, i
+ 1)
1288 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1291 make_internal_attr (num_delay_slots_str
, condexp
, ATTR_NONE
);
1293 /* If more than one delay type, do the same for computing the delay type. */
1296 condexp
= rtx_alloc (COND
);
1297 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1298 XEXP (condexp
, 1) = make_numeric_value (0);
1300 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1302 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1303 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1306 make_internal_attr (delay_type_str
, condexp
, ATTR_SPECIAL
);
1309 /* For each delay possibility and delay slot, compute an eligibility
1310 attribute for non-annulled insns and for each type of annulled (annul
1311 if true and annul if false). */
1312 for (delay
= delays
; delay
; delay
= delay
->next
)
1314 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1316 condexp
= XVECEXP (delay
->def
, 1, i
);
1318 condexp
= false_rtx
;
1319 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1320 make_numeric_value (1), make_numeric_value (0));
1322 p
= attr_printf (sizeof "*delay__" + MAX_DIGITS
* 2,
1323 "*delay_%d_%d", delay
->num
, i
/ 3);
1324 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1326 if (have_annul_true
)
1328 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1329 if (condexp
== 0) condexp
= false_rtx
;
1330 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1331 make_numeric_value (1),
1332 make_numeric_value (0));
1333 p
= attr_printf (sizeof "*annul_true__" + MAX_DIGITS
* 2,
1334 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1335 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1338 if (have_annul_false
)
1340 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1341 if (condexp
== 0) condexp
= false_rtx
;
1342 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1343 make_numeric_value (1),
1344 make_numeric_value (0));
1345 p
= attr_printf (sizeof "*annul_false__" + MAX_DIGITS
* 2,
1346 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1347 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1353 /* Once all attributes and insns have been read and checked, we construct for
1354 each attribute value a list of all the insns that have that value for
1358 fill_attr (struct attr_desc
*attr
)
1360 struct attr_value
*av
;
1361 struct insn_ent
*ie
;
1362 struct insn_def
*id
;
1366 /* Don't fill constant attributes. The value is independent of
1367 any particular insn. */
1371 for (id
= defs
; id
; id
= id
->next
)
1373 /* If no value is specified for this insn for this attribute, use the
1376 if (XVEC (id
->def
, id
->vec_idx
))
1377 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1378 if (! strcmp_check (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
1380 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
1383 av
= attr
->default_val
;
1385 av
= get_attr_value (id
->loc
, value
, attr
, id
->insn_code
);
1387 ie
= oballoc (struct insn_ent
);
1389 insert_insn_ent (av
, ie
);
1393 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
1394 test that checks relative positions of insns (uses MATCH_DUP or PC).
1395 If so, replace it with what is obtained by passing the expression to
1396 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
1397 recursively on each value (including the default value). Otherwise,
1398 return the value returned by NO_ADDRESS_FN applied to EXP. */
1401 substitute_address (rtx exp
, rtx (*no_address_fn
) (rtx
),
1402 rtx (*address_fn
) (rtx
))
1407 if (GET_CODE (exp
) == COND
)
1409 /* See if any tests use addresses. */
1411 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1412 walk_attr_value (XVECEXP (exp
, 0, i
));
1415 return (*address_fn
) (exp
);
1417 /* Make a new copy of this COND, replacing each element. */
1418 newexp
= rtx_alloc (COND
);
1419 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
1420 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1422 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
1423 XVECEXP (newexp
, 0, i
+ 1)
1424 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
1425 no_address_fn
, address_fn
);
1428 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
1429 no_address_fn
, address_fn
);
1434 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
1437 walk_attr_value (XEXP (exp
, 0));
1439 return (*address_fn
) (exp
);
1441 return attr_rtx (IF_THEN_ELSE
,
1442 substitute_address (XEXP (exp
, 0),
1443 no_address_fn
, address_fn
),
1444 substitute_address (XEXP (exp
, 1),
1445 no_address_fn
, address_fn
),
1446 substitute_address (XEXP (exp
, 2),
1447 no_address_fn
, address_fn
));
1450 return (*no_address_fn
) (exp
);
1453 /* Make new attributes from the `length' attribute. The following are made,
1454 each corresponding to a function called from `shorten_branches' or
1457 *insn_default_length This is the length of the insn to be returned
1458 by `get_attr_length' before `shorten_branches'
1459 has been called. In each case where the length
1460 depends on relative addresses, the largest
1461 possible is used. This routine is also used
1462 to compute the initial size of the insn.
1464 *insn_variable_length_p This returns 1 if the insn's length depends
1465 on relative addresses, zero otherwise.
1467 *insn_current_length This is only called when it is known that the
1468 insn has a variable length and returns the
1469 current length, based on relative addresses.
1473 make_length_attrs (void)
1475 static const char *new_names
[] =
1477 "*insn_default_length",
1479 "*insn_variable_length_p",
1480 "*insn_current_length"
1482 static rtx (*const no_address_fn
[]) (rtx
)
1483 = {identity_fn
,identity_fn
, zero_fn
, zero_fn
};
1484 static rtx (*const address_fn
[]) (rtx
)
1485 = {max_fn
, min_fn
, one_fn
, identity_fn
};
1487 struct attr_desc
*length_attr
, *new_attr
;
1488 struct attr_value
*av
, *new_av
;
1489 struct insn_ent
*ie
, *new_ie
;
1491 /* See if length attribute is defined. If so, it must be numeric. Make
1492 it special so we don't output anything for it. */
1493 length_attr
= find_attr (&length_str
, 0);
1494 if (length_attr
== 0)
1497 if (! length_attr
->is_numeric
)
1498 fatal_at (length_attr
->loc
, "length attribute must be numeric");
1500 length_attr
->is_const
= 0;
1501 length_attr
->is_special
= 1;
1503 /* Make each new attribute, in turn. */
1504 for (i
= 0; i
< ARRAY_SIZE (new_names
); i
++)
1506 make_internal_attr (new_names
[i
],
1507 substitute_address (length_attr
->default_val
->value
,
1508 no_address_fn
[i
], address_fn
[i
]),
1510 new_attr
= find_attr (&new_names
[i
], 0);
1511 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
1512 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1514 new_av
= get_attr_value (ie
->def
->loc
,
1515 substitute_address (av
->value
,
1518 new_attr
, ie
->def
->insn_code
);
1519 new_ie
= oballoc (struct insn_ent
);
1520 new_ie
->def
= ie
->def
;
1521 insert_insn_ent (new_av
, new_ie
);
1526 /* Utility functions called from above routine. */
1529 identity_fn (rtx exp
)
1535 zero_fn (rtx exp ATTRIBUTE_UNUSED
)
1537 return make_numeric_value (0);
1541 one_fn (rtx exp ATTRIBUTE_UNUSED
)
1543 return make_numeric_value (1);
1550 return make_numeric_value (max_attr_value (exp
, &unknown
));
1557 return make_numeric_value (min_attr_value (exp
, &unknown
));
1561 write_length_unit_log (FILE *outf
)
1563 struct attr_desc
*length_attr
= find_attr (&length_str
, 0);
1564 struct attr_value
*av
;
1565 struct insn_ent
*ie
;
1566 unsigned int length_unit_log
, length_or
;
1571 length_or
= or_attr_value (length_attr
->default_val
->value
, &unknown
);
1572 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
1573 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1574 length_or
|= or_attr_value (av
->value
, &unknown
);
1577 if (length_attr
== NULL
|| unknown
)
1578 length_unit_log
= 0;
1581 length_or
= ~length_or
;
1582 for (length_unit_log
= 0; length_or
& 1; length_or
>>= 1)
1585 fprintf (outf
, "EXPORTED_CONST int length_unit_log = %u;\n", length_unit_log
);
1588 /* Compute approximate cost of the expression. Used to decide whether
1589 expression is cheap enough for inline. */
1591 attr_rtx_cost (rtx x
)
1597 code
= GET_CODE (x
);
1610 /* Alternatives don't result into function call. */
1611 if (!strcmp_check (XSTR (x
, 0), alternative_name
))
1618 const char *fmt
= GET_RTX_FORMAT (code
);
1619 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1625 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1626 cost
+= attr_rtx_cost (XVECEXP (x
, i
, j
));
1629 cost
+= attr_rtx_cost (XEXP (x
, i
));
1639 /* Take a COND expression and see if any of the conditions in it can be
1640 simplified. If any are known true or known false for the particular insn
1641 code, the COND can be further simplified.
1643 Also call ourselves on any COND operations that are values of this COND.
1645 We do not modify EXP; rather, we make and return a new rtx. */
1648 simplify_cond (rtx exp
, int insn_code
, int insn_index
)
1651 /* We store the desired contents here,
1652 then build a new expression if they don't match EXP. */
1653 rtx defval
= XEXP (exp
, 1);
1654 rtx new_defval
= XEXP (exp
, 1);
1655 int len
= XVECLEN (exp
, 0);
1656 rtx
*tests
= XNEWVEC (rtx
, len
);
1660 /* This lets us free all storage allocated below, if appropriate. */
1661 obstack_finish (rtl_obstack
);
1663 memcpy (tests
, XVEC (exp
, 0)->elem
, len
* sizeof (rtx
));
1665 /* See if default value needs simplification. */
1666 if (GET_CODE (defval
) == COND
)
1667 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
1669 /* Simplify the subexpressions, and see what tests we can get rid of. */
1671 for (i
= 0; i
< len
; i
+= 2)
1673 rtx newtest
, newval
;
1675 /* Simplify this test. */
1676 newtest
= simplify_test_exp_in_temp (tests
[i
], insn_code
, insn_index
);
1679 newval
= tests
[i
+ 1];
1680 /* See if this value may need simplification. */
1681 if (GET_CODE (newval
) == COND
)
1682 newval
= simplify_cond (newval
, insn_code
, insn_index
);
1684 /* Look for ways to delete or combine this test. */
1685 if (newtest
== true_rtx
)
1687 /* If test is true, make this value the default
1688 and discard this + any following tests. */
1690 defval
= tests
[i
+ 1];
1691 new_defval
= newval
;
1694 else if (newtest
== false_rtx
)
1696 /* If test is false, discard it and its value. */
1697 for (j
= i
; j
< len
- 2; j
++)
1698 tests
[j
] = tests
[j
+ 2];
1703 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
1705 /* If this value and the value for the prev test are the same,
1709 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
1710 insn_code
, insn_index
);
1712 /* Delete this test/value. */
1713 for (j
= i
; j
< len
- 2; j
++)
1714 tests
[j
] = tests
[j
+ 2];
1720 tests
[i
+ 1] = newval
;
1723 /* If the last test in a COND has the same value
1724 as the default value, that test isn't needed. */
1726 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
1729 /* See if we changed anything. */
1730 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
1733 for (i
= 0; i
< len
; i
++)
1734 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
1742 if (GET_CODE (defval
) == COND
)
1743 ret
= simplify_cond (defval
, insn_code
, insn_index
);
1751 rtx newexp
= rtx_alloc (COND
);
1753 XVEC (newexp
, 0) = rtvec_alloc (len
);
1754 memcpy (XVEC (newexp
, 0)->elem
, tests
, len
* sizeof (rtx
));
1755 XEXP (newexp
, 1) = new_defval
;
1762 /* Remove an insn entry from an attribute value. */
1765 remove_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
1767 struct insn_ent
*previe
;
1769 if (av
->first_insn
== ie
)
1770 av
->first_insn
= ie
->next
;
1773 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
1775 previe
->next
= ie
->next
;
1779 if (ie
->def
->insn_code
== -1)
1780 av
->has_asm_insn
= 0;
1785 /* Insert an insn entry in an attribute value list. */
1788 insert_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
1790 ie
->next
= av
->first_insn
;
1791 av
->first_insn
= ie
;
1793 if (ie
->def
->insn_code
== -1)
1794 av
->has_asm_insn
= 1;
1799 /* This is a utility routine to take an expression that is a tree of either
1800 AND or IOR expressions and insert a new term. The new term will be
1801 inserted at the right side of the first node whose code does not match
1802 the root. A new node will be created with the root's code. Its left
1803 side will be the old right side and its right side will be the new
1806 If the `term' is itself a tree, all its leaves will be inserted. */
1809 insert_right_side (enum rtx_code code
, rtx exp
, rtx term
, int insn_code
, int insn_index
)
1813 /* Avoid consing in some special cases. */
1814 if (code
== AND
&& term
== true_rtx
)
1816 if (code
== AND
&& term
== false_rtx
)
1818 if (code
== AND
&& exp
== true_rtx
)
1820 if (code
== AND
&& exp
== false_rtx
)
1822 if (code
== IOR
&& term
== true_rtx
)
1824 if (code
== IOR
&& term
== false_rtx
)
1826 if (code
== IOR
&& exp
== true_rtx
)
1828 if (code
== IOR
&& exp
== false_rtx
)
1830 if (attr_equal_p (exp
, term
))
1833 if (GET_CODE (term
) == code
)
1835 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
1836 insn_code
, insn_index
);
1837 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
1838 insn_code
, insn_index
);
1843 if (GET_CODE (exp
) == code
)
1845 rtx new_rtx
= insert_right_side (code
, XEXP (exp
, 1),
1846 term
, insn_code
, insn_index
);
1847 if (new_rtx
!= XEXP (exp
, 1))
1848 /* Make a copy of this expression and call recursively. */
1849 newexp
= attr_rtx (code
, XEXP (exp
, 0), new_rtx
);
1855 /* Insert the new term. */
1856 newexp
= attr_rtx (code
, exp
, term
);
1859 return simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
1862 /* If we have an expression which AND's a bunch of
1863 (not (eq_attrq "alternative" "n"))
1864 terms, we may have covered all or all but one of the possible alternatives.
1865 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
1867 This routine is passed an expression and either AND or IOR. It returns a
1868 bitmask indicating which alternatives are mentioned within EXP. */
1871 compute_alternative_mask (rtx exp
, enum rtx_code code
)
1874 if (GET_CODE (exp
) == code
)
1875 return compute_alternative_mask (XEXP (exp
, 0), code
)
1876 | compute_alternative_mask (XEXP (exp
, 1), code
);
1878 else if (code
== AND
&& GET_CODE (exp
) == NOT
1879 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
1880 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
1881 string
= XSTR (XEXP (exp
, 0), 1);
1883 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
1884 && XSTR (exp
, 0) == alternative_name
)
1885 string
= XSTR (exp
, 1);
1887 else if (GET_CODE (exp
) == EQ_ATTR_ALT
)
1889 if (code
== AND
&& XINT (exp
, 1))
1890 return XINT (exp
, 0);
1892 if (code
== IOR
&& !XINT (exp
, 1))
1893 return XINT (exp
, 0);
1901 return ((uint64_t) 1) << (string
[0] - '0');
1902 return ((uint64_t) 1) << atoi (string
);
1905 /* Given I, a single-bit mask, return RTX to compare the `alternative'
1906 attribute with the value represented by that bit. */
1909 make_alternative_compare (uint64_t mask
)
1911 return mk_attr_alt (mask
);
1914 /* If we are processing an (eq_attr "attr" "value") test, we find the value
1915 of "attr" for this insn code. From that value, we can compute a test
1916 showing when the EQ_ATTR will be true. This routine performs that
1917 computation. If a test condition involves an address, we leave the EQ_ATTR
1918 intact because addresses are only valid for the `length' attribute.
1920 EXP is the EQ_ATTR expression and ATTR is the attribute to which
1921 it refers. VALUE is the value of that attribute for the insn
1922 corresponding to INSN_CODE and INSN_INDEX. */
1925 evaluate_eq_attr (rtx exp
, struct attr_desc
*attr
, rtx value
,
1926 int insn_code
, int insn_index
)
1933 while (GET_CODE (value
) == ATTR
)
1935 struct attr_value
*av
= NULL
;
1937 attr
= find_attr (&XSTR (value
, 0), 0);
1939 if (insn_code_values
)
1941 struct attr_value_list
*iv
;
1942 for (iv
= insn_code_values
[insn_code
]; iv
; iv
= iv
->next
)
1943 if (iv
->attr
== attr
)
1951 struct insn_ent
*ie
;
1952 for (av
= attr
->first_value
; av
; av
= av
->next
)
1953 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1954 if (ie
->def
->insn_code
== insn_code
)
1964 switch (GET_CODE (value
))
1967 if (! strcmp_check (XSTR (value
, 0), XSTR (exp
, 1)))
1978 gcc_assert (GET_CODE (exp
) == EQ_ATTR
);
1979 prefix
= attr
->enum_name
? attr
->enum_name
: attr
->name
;
1980 string
= ACONCAT ((prefix
, "_", XSTR (exp
, 1), NULL
));
1981 for (p
= string
; *p
; p
++)
1984 newexp
= attr_rtx (EQ
, value
,
1985 attr_rtx (SYMBOL_REF
,
1986 DEF_ATTR_STRING (string
)));
1991 /* We construct an IOR of all the cases for which the
1992 requested attribute value is present. Since we start with
1993 FALSE, if it is not present, FALSE will be returned.
1995 Each case is the AND of the NOT's of the previous conditions with the
1996 current condition; in the default case the current condition is TRUE.
1998 For each possible COND value, call ourselves recursively.
2000 The extra TRUE and FALSE expressions will be eliminated by another
2001 call to the simplification routine. */
2006 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2008 rtx this_cond
= simplify_test_exp_in_temp (XVECEXP (value
, 0, i
),
2009 insn_code
, insn_index
);
2011 right
= insert_right_side (AND
, andexp
, this_cond
,
2012 insn_code
, insn_index
);
2013 right
= insert_right_side (AND
, right
,
2014 evaluate_eq_attr (exp
, attr
,
2017 insn_code
, insn_index
),
2018 insn_code
, insn_index
);
2019 orexp
= insert_right_side (IOR
, orexp
, right
,
2020 insn_code
, insn_index
);
2022 /* Add this condition into the AND expression. */
2023 newexp
= attr_rtx (NOT
, this_cond
);
2024 andexp
= insert_right_side (AND
, andexp
, newexp
,
2025 insn_code
, insn_index
);
2028 /* Handle the default case. */
2029 right
= insert_right_side (AND
, andexp
,
2030 evaluate_eq_attr (exp
, attr
, XEXP (value
, 1),
2031 insn_code
, insn_index
),
2032 insn_code
, insn_index
);
2033 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2040 /* If uses an address, must return original expression. But set the
2041 ATTR_IND_SIMPLIFIED_P bit so we don't try to simplify it again. */
2044 walk_attr_value (newexp
);
2048 if (! ATTR_IND_SIMPLIFIED_P (exp
))
2049 return copy_rtx_unchanging (exp
);
2056 /* This routine is called when an AND of a term with a tree of AND's is
2057 encountered. If the term or its complement is present in the tree, it
2058 can be replaced with TRUE or FALSE, respectively.
2060 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2061 be true and hence are complementary.
2063 There is one special case: If we see
2064 (and (not (eq_attr "att" "v1"))
2065 (eq_attr "att" "v2"))
2066 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2067 replace the term, not anything in the AND tree. So we pass a pointer to
2071 simplify_and_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
2076 int left_eliminates_term
, right_eliminates_term
;
2078 if (GET_CODE (exp
) == AND
)
2080 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2081 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2082 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2084 newexp
= attr_rtx (AND
, left
, right
);
2086 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2090 else if (GET_CODE (exp
) == IOR
)
2092 /* For the IOR case, we do the same as above, except that we can
2093 only eliminate `term' if both sides of the IOR would do so. */
2095 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2096 left_eliminates_term
= (temp
== true_rtx
);
2099 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2100 right_eliminates_term
= (temp
== true_rtx
);
2102 if (left_eliminates_term
&& right_eliminates_term
)
2105 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2107 newexp
= attr_rtx (IOR
, left
, right
);
2109 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2113 /* Check for simplifications. Do some extra checking here since this
2114 routine is called so many times. */
2119 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
2122 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
2125 else if (GET_CODE (exp
) == EQ_ATTR_ALT
&& GET_CODE (*pterm
) == EQ_ATTR_ALT
)
2127 if (attr_alt_subset_p (*pterm
, exp
))
2130 if (attr_alt_subset_of_compl_p (*pterm
, exp
))
2133 if (attr_alt_subset_p (exp
, *pterm
))
2139 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
2141 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
2144 if (! strcmp_check (XSTR (exp
, 1), XSTR (*pterm
, 1)))
2150 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2151 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
2153 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
2156 if (! strcmp_check (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
2162 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2163 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
2165 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
2168 if (! strcmp_check (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
2174 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
2176 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
2180 else if (GET_CODE (exp
) == NOT
)
2182 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
2186 else if (GET_CODE (*pterm
) == NOT
)
2188 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
2192 else if (attr_equal_p (exp
, *pterm
))
2198 /* Similar to `simplify_and_tree', but for IOR trees. */
2201 simplify_or_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
2206 int left_eliminates_term
, right_eliminates_term
;
2208 if (GET_CODE (exp
) == IOR
)
2210 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2211 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2212 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2214 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2216 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2220 else if (GET_CODE (exp
) == AND
)
2222 /* For the AND case, we do the same as above, except that we can
2223 only eliminate `term' if both sides of the AND would do so. */
2225 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2226 left_eliminates_term
= (temp
== false_rtx
);
2229 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2230 right_eliminates_term
= (temp
== false_rtx
);
2232 if (left_eliminates_term
&& right_eliminates_term
)
2235 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2237 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2239 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2243 if (attr_equal_p (exp
, *pterm
))
2246 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
2249 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
2252 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2253 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2254 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
2257 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2258 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
2259 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
2265 /* Simplify test expression and use temporary obstack in order to avoid
2266 memory bloat. Use ATTR_IND_SIMPLIFIED to avoid unnecessary simplifications
2267 and avoid unnecessary copying if possible. */
2270 simplify_test_exp_in_temp (rtx exp
, int insn_code
, int insn_index
)
2273 struct obstack
*old
;
2274 if (ATTR_IND_SIMPLIFIED_P (exp
))
2277 rtl_obstack
= temp_obstack
;
2278 x
= simplify_test_exp (exp
, insn_code
, insn_index
);
2283 /* Returns true if S1 is a subset of S2. */
2286 attr_alt_subset_p (rtx s1
, rtx s2
)
2288 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2291 return !(XINT (s1
, 0) &~ XINT (s2
, 0));
2294 return !(XINT (s1
, 0) & XINT (s2
, 0));
2300 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
2307 /* Returns true if S1 is a subset of complement of S2. */
2310 attr_alt_subset_of_compl_p (rtx s1
, rtx s2
)
2312 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2315 return !(XINT (s1
, 0) & XINT (s2
, 0));
2318 return !(XINT (s1
, 0) & ~XINT (s2
, 0));
2321 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
2331 /* Return EQ_ATTR_ALT expression representing intersection of S1 and S2. */
2334 attr_alt_intersection (rtx s1
, rtx s2
)
2338 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2341 result
= XINT (s1
, 0) & XINT (s2
, 0);
2344 result
= XINT (s1
, 0) & ~XINT (s2
, 0);
2347 result
= XINT (s2
, 0) & ~XINT (s1
, 0);
2350 result
= XINT (s1
, 0) | XINT (s2
, 0);
2356 return attr_rtx (EQ_ATTR_ALT
, result
, XINT (s1
, 1) & XINT (s2
, 1));
2359 /* Return EQ_ATTR_ALT expression representing union of S1 and S2. */
2362 attr_alt_union (rtx s1
, rtx s2
)
2366 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2369 result
= XINT (s1
, 0) | XINT (s2
, 0);
2372 result
= XINT (s2
, 0) & ~XINT (s1
, 0);
2375 result
= XINT (s1
, 0) & ~XINT (s2
, 0);
2378 result
= XINT (s1
, 0) & XINT (s2
, 0);
2384 return attr_rtx (EQ_ATTR_ALT
, result
, XINT (s1
, 1) | XINT (s2
, 1));
2387 /* Return EQ_ATTR_ALT expression representing complement of S. */
2390 attr_alt_complement (rtx s
)
2392 return attr_rtx (EQ_ATTR_ALT
, XINT (s
, 0), 1 - XINT (s
, 1));
2395 /* Return EQ_ATTR_ALT expression representing set containing elements set
2399 mk_attr_alt (uint64_t e
)
2401 return attr_rtx (EQ_ATTR_ALT
, (int)e
, 0);
2404 /* Given an expression, see if it can be simplified for a particular insn
2405 code based on the values of other attributes being tested. This can
2406 eliminate nested get_attr_... calls.
2408 Note that if an endless recursion is specified in the patterns, the
2409 optimization will loop. However, it will do so in precisely the cases where
2410 an infinite recursion loop could occur during compilation. It's better that
2414 simplify_test_exp (rtx exp
, int insn_code
, int insn_index
)
2417 struct attr_desc
*attr
;
2418 struct attr_value
*av
;
2419 struct insn_ent
*ie
;
2420 struct attr_value_list
*iv
;
2423 bool left_alt
, right_alt
;
2425 /* Don't re-simplify something we already simplified. */
2426 if (ATTR_IND_SIMPLIFIED_P (exp
) || ATTR_CURR_SIMPLIFIED_P (exp
))
2429 switch (GET_CODE (exp
))
2432 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2433 if (left
== false_rtx
)
2435 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2436 if (right
== false_rtx
)
2439 if (GET_CODE (left
) == EQ_ATTR_ALT
2440 && GET_CODE (right
) == EQ_ATTR_ALT
)
2442 exp
= attr_alt_intersection (left
, right
);
2443 return simplify_test_exp (exp
, insn_code
, insn_index
);
2446 /* If either side is an IOR and we have (eq_attr "alternative" ..")
2447 present on both sides, apply the distributive law since this will
2448 yield simplifications. */
2449 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
2450 && compute_alternative_mask (left
, IOR
)
2451 && compute_alternative_mask (right
, IOR
))
2453 if (GET_CODE (left
) == IOR
)
2454 std::swap (left
, right
);
2456 newexp
= attr_rtx (IOR
,
2457 attr_rtx (AND
, left
, XEXP (right
, 0)),
2458 attr_rtx (AND
, left
, XEXP (right
, 1)));
2460 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2463 /* Try with the term on both sides. */
2464 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
2465 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2466 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
2468 if (left
== false_rtx
|| right
== false_rtx
)
2470 else if (left
== true_rtx
)
2474 else if (right
== true_rtx
)
2478 /* See if all or all but one of the insn's alternatives are specified
2479 in this tree. Optimize if so. */
2481 if (GET_CODE (left
) == NOT
)
2482 left_alt
= (GET_CODE (XEXP (left
, 0)) == EQ_ATTR
2483 && XSTR (XEXP (left
, 0), 0) == alternative_name
);
2485 left_alt
= (GET_CODE (left
) == EQ_ATTR_ALT
2488 if (GET_CODE (right
) == NOT
)
2489 right_alt
= (GET_CODE (XEXP (right
, 0)) == EQ_ATTR
2490 && XSTR (XEXP (right
, 0), 0) == alternative_name
);
2492 right_alt
= (GET_CODE (right
) == EQ_ATTR_ALT
2493 && XINT (right
, 1));
2496 && (GET_CODE (left
) == AND
2498 || GET_CODE (right
) == AND
2501 i
= compute_alternative_mask (exp
, AND
);
2502 if (i
& ~insn_alternatives
[insn_code
])
2503 fatal ("invalid alternative specified for pattern number %d",
2506 /* If all alternatives are excluded, this is false. */
2507 i
^= insn_alternatives
[insn_code
];
2510 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2512 /* If just one excluded, AND a comparison with that one to the
2513 front of the tree. The others will be eliminated by
2514 optimization. We do not want to do this if the insn has one
2515 alternative and we have tested none of them! */
2516 left
= make_alternative_compare (i
);
2517 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2518 newexp
= attr_rtx (AND
, left
, right
);
2520 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2524 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2526 newexp
= attr_rtx (AND
, left
, right
);
2527 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2532 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2533 if (left
== true_rtx
)
2535 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2536 if (right
== true_rtx
)
2539 if (GET_CODE (left
) == EQ_ATTR_ALT
2540 && GET_CODE (right
) == EQ_ATTR_ALT
)
2542 exp
= attr_alt_union (left
, right
);
2543 return simplify_test_exp (exp
, insn_code
, insn_index
);
2546 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
2547 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2548 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
2550 if (right
== true_rtx
|| left
== true_rtx
)
2552 else if (left
== false_rtx
)
2556 else if (right
== false_rtx
)
2561 /* Test for simple cases where the distributive law is useful. I.e.,
2562 convert (ior (and (x) (y))
2568 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2569 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
2571 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
2573 left
= XEXP (left
, 0);
2575 newexp
= attr_rtx (AND
, left
, right
);
2576 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2580 convert (ior (and (y) (x))
2582 to (and (ior (y) (z))
2584 Note that we want the common term to stay at the end.
2587 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2588 && attr_equal_p (XEXP (left
, 1), XEXP (right
, 1)))
2590 newexp
= attr_rtx (IOR
, XEXP (left
, 0), XEXP (right
, 0));
2593 right
= XEXP (right
, 1);
2594 newexp
= attr_rtx (AND
, left
, right
);
2595 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2598 /* See if all or all but one of the insn's alternatives are specified
2599 in this tree. Optimize if so. */
2601 else if (insn_code
>= 0
2602 && (GET_CODE (left
) == IOR
2603 || (GET_CODE (left
) == EQ_ATTR_ALT
2605 || (GET_CODE (left
) == EQ_ATTR
2606 && XSTR (left
, 0) == alternative_name
)
2607 || GET_CODE (right
) == IOR
2608 || (GET_CODE (right
) == EQ_ATTR_ALT
2609 && !XINT (right
, 1))
2610 || (GET_CODE (right
) == EQ_ATTR
2611 && XSTR (right
, 0) == alternative_name
)))
2613 i
= compute_alternative_mask (exp
, IOR
);
2614 if (i
& ~insn_alternatives
[insn_code
])
2615 fatal ("invalid alternative specified for pattern number %d",
2618 /* If all alternatives are included, this is true. */
2619 i
^= insn_alternatives
[insn_code
];
2622 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2624 /* If just one excluded, IOR a comparison with that one to the
2625 front of the tree. The others will be eliminated by
2626 optimization. We do not want to do this if the insn has one
2627 alternative and we have tested none of them! */
2628 left
= make_alternative_compare (i
);
2629 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2630 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
2632 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2636 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2638 newexp
= attr_rtx (IOR
, left
, right
);
2639 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2644 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
2646 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
2647 insn_code
, insn_index
);
2651 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2652 if (GET_CODE (left
) == NOT
)
2653 return XEXP (left
, 0);
2655 if (left
== false_rtx
)
2657 if (left
== true_rtx
)
2660 if (GET_CODE (left
) == EQ_ATTR_ALT
)
2662 exp
= attr_alt_complement (left
);
2663 return simplify_test_exp (exp
, insn_code
, insn_index
);
2666 /* Try to apply De`Morgan's laws. */
2667 if (GET_CODE (left
) == IOR
)
2669 newexp
= attr_rtx (AND
,
2670 attr_rtx (NOT
, XEXP (left
, 0)),
2671 attr_rtx (NOT
, XEXP (left
, 1)));
2673 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2675 else if (GET_CODE (left
) == AND
)
2677 newexp
= attr_rtx (IOR
,
2678 attr_rtx (NOT
, XEXP (left
, 0)),
2679 attr_rtx (NOT
, XEXP (left
, 1)));
2681 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2683 else if (left
!= XEXP (exp
, 0))
2685 newexp
= attr_rtx (NOT
, left
);
2691 return XINT (exp
, 1) ? true_rtx
: false_rtx
;
2695 if (XSTR (exp
, 0) == alternative_name
)
2697 newexp
= mk_attr_alt (((uint64_t) 1) << atoi (XSTR (exp
, 1)));
2701 /* Look at the value for this insn code in the specified attribute.
2702 We normally can replace this comparison with the condition that
2703 would give this insn the values being tested for. */
2705 && (attr
= find_attr (&XSTR (exp
, 0), 0)) != NULL
)
2710 if (insn_code_values
)
2712 for (iv
= insn_code_values
[insn_code
]; iv
; iv
= iv
->next
)
2713 if (iv
->attr
== attr
)
2721 for (av
= attr
->first_value
; av
; av
= av
->next
)
2722 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2723 if (ie
->def
->insn_code
== insn_code
)
2730 x
= evaluate_eq_attr (exp
, attr
, av
->value
,
2731 insn_code
, insn_index
);
2732 x
= SIMPLIFY_TEST_EXP (x
, insn_code
, insn_index
);
2733 if (attr_rtx_cost (x
) < 7)
2743 /* We have already simplified this expression. Simplifying it again
2744 won't buy anything unless we weren't given a valid insn code
2745 to process (i.e., we are canonicalizing something.). */
2747 && ! ATTR_IND_SIMPLIFIED_P (newexp
))
2748 return copy_rtx_unchanging (newexp
);
2753 /* Return 1 if any EQ_ATTR subexpression of P refers to ATTR,
2754 otherwise return 0. */
2757 tests_attr_p (rtx p
, struct attr_desc
*attr
)
2762 if (GET_CODE (p
) == EQ_ATTR
)
2764 if (XSTR (p
, 0) != attr
->name
)
2769 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
2770 ie
= GET_RTX_LENGTH (GET_CODE (p
));
2771 for (i
= 0; i
< ie
; i
++)
2776 if (tests_attr_p (XEXP (p
, i
), attr
))
2781 je
= XVECLEN (p
, i
);
2782 for (j
= 0; j
< je
; ++j
)
2783 if (tests_attr_p (XVECEXP (p
, i
, j
), attr
))
2792 /* Calculate a topological sorting of all attributes so that
2793 all attributes only depend on attributes in front of it.
2794 Place the result in *RET (which is a pointer to an array of
2795 attr_desc pointers), and return the size of that array. */
2798 get_attr_order (struct attr_desc
***ret
)
2802 struct attr_desc
*attr
;
2803 struct attr_desc
**all
, **sorted
;
2805 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
2806 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
2808 all
= XNEWVEC (struct attr_desc
*, num
);
2809 sorted
= XNEWVEC (struct attr_desc
*, num
);
2810 handled
= XCNEWVEC (char, num
);
2812 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
2813 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
2817 for (i
= 0; i
< num
; i
++)
2818 if (all
[i
]->is_const
)
2819 handled
[i
] = 1, sorted
[j
++] = all
[i
];
2821 /* We have only few attributes hence we can live with the inner
2822 loop being O(n^2), unlike the normal fast variants of topological
2826 for (i
= 0; i
< num
; i
++)
2829 /* Let's see if I depends on anything interesting. */
2831 for (k
= 0; k
< num
; k
++)
2834 struct attr_value
*av
;
2835 for (av
= all
[i
]->first_value
; av
; av
= av
->next
)
2836 if (av
->num_insns
!= 0)
2837 if (tests_attr_p (av
->value
, all
[k
]))
2841 /* Something in I depends on K. */
2846 /* Nothing in I depended on anything intersting, so
2849 sorted
[j
++] = all
[i
];
2855 for (j
= 0; j
< num
; j
++)
2857 struct attr_desc
*attr2
;
2858 struct attr_value
*av
;
2861 fprintf (stderr
, "%s depends on: ", attr
->name
);
2862 for (i
= 0; i
< MAX_ATTRS_INDEX
; ++i
)
2863 for (attr2
= attrs
[i
]; attr2
; attr2
= attr2
->next
)
2864 if (!attr2
->is_const
)
2865 for (av
= attr
->first_value
; av
; av
= av
->next
)
2866 if (av
->num_insns
!= 0)
2867 if (tests_attr_p (av
->value
, attr2
))
2869 fprintf (stderr
, "%s, ", attr2
->name
);
2872 fprintf (stderr
, "\n");
2880 /* Optimize the attribute lists by seeing if we can determine conditional
2881 values from the known values of other attributes. This will save subroutine
2882 calls during the compilation. NUM_INSN_CODES is the number of unique
2883 instruction codes. */
2886 optimize_attrs (int num_insn_codes
)
2888 struct attr_desc
*attr
;
2889 struct attr_value
*av
;
2890 struct insn_ent
*ie
;
2893 struct attr_value_list
*ivbuf
;
2894 struct attr_value_list
*iv
;
2895 struct attr_desc
**topsort
;
2898 /* For each insn code, make a list of all the insn_ent's for it,
2899 for all values for all attributes. */
2901 if (num_insn_ents
== 0)
2904 /* Make 2 extra elements, for "code" values -2 and -1. */
2905 insn_code_values
= XCNEWVEC (struct attr_value_list
*, num_insn_codes
+ 2);
2907 /* Offset the table address so we can index by -2 or -1. */
2908 insn_code_values
+= 2;
2910 iv
= ivbuf
= XNEWVEC (struct attr_value_list
, num_insn_ents
);
2912 /* Create the chain of insn*attr values such that we see dependend
2913 attributes after their dependencies. As we use a stack via the
2914 next pointers start from the end of the topological order. */
2915 topnum
= get_attr_order (&topsort
);
2916 for (i
= topnum
- 1; i
>= 0; i
--)
2917 for (av
= topsort
[i
]->first_value
; av
; av
= av
->next
)
2918 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2920 iv
->attr
= topsort
[i
];
2923 iv
->next
= insn_code_values
[ie
->def
->insn_code
];
2924 insn_code_values
[ie
->def
->insn_code
] = iv
;
2929 /* Sanity check on num_insn_ents. */
2930 gcc_assert (iv
== ivbuf
+ num_insn_ents
);
2932 /* Process one insn code at a time. */
2933 for (i
= -2; i
< num_insn_codes
; i
++)
2935 /* Clear the ATTR_CURR_SIMPLIFIED_P flag everywhere relevant.
2936 We use it to mean "already simplified for this insn". */
2937 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
2938 clear_struct_flag (iv
->av
->value
);
2940 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
2942 struct obstack
*old
= rtl_obstack
;
2947 if (GET_CODE (av
->value
) != COND
)
2950 rtl_obstack
= temp_obstack
;
2952 while (GET_CODE (newexp
) == COND
)
2954 rtx newexp2
= simplify_cond (newexp
, ie
->def
->insn_code
,
2955 ie
->def
->insn_index
);
2956 if (newexp2
== newexp
)
2962 /* If we created a new value for this instruction, and it's
2963 cheaper than the old value, and overall cheap, use that
2964 one as specific value for the current instruction.
2965 The last test is to avoid exploding the get_attr_ function
2966 sizes for no much gain. */
2967 if (newexp
!= av
->value
2968 && attr_rtx_cost (newexp
) < attr_rtx_cost (av
->value
)
2969 && attr_rtx_cost (newexp
) < 26
2972 remove_insn_ent (av
, ie
);
2973 av
= get_attr_value (ie
->def
->loc
, newexp
, attr
,
2974 ie
->def
->insn_code
);
2976 insert_insn_ent (av
, ie
);
2982 free (insn_code_values
- 2);
2983 insn_code_values
= NULL
;
2986 /* Clear the ATTR_CURR_SIMPLIFIED_P flag in EXP and its subexpressions. */
2989 clear_struct_flag (rtx x
)
2996 ATTR_CURR_SIMPLIFIED_P (x
) = 0;
2997 if (ATTR_IND_SIMPLIFIED_P (x
))
3000 code
= GET_CODE (x
);
3019 /* Compare the elements. If any pair of corresponding elements
3020 fail to match, return 0 for the whole things. */
3022 fmt
= GET_RTX_FORMAT (code
);
3023 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3029 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3030 clear_struct_flag (XVECEXP (x
, i
, j
));
3034 clear_struct_flag (XEXP (x
, i
));
3040 /* Add attribute value NAME to the beginning of ATTR's list. */
3043 add_attr_value (struct attr_desc
*attr
, const char *name
)
3045 struct attr_value
*av
;
3047 av
= oballoc (struct attr_value
);
3048 av
->value
= attr_rtx (CONST_STRING
, name
);
3049 av
->next
= attr
->first_value
;
3050 attr
->first_value
= av
;
3051 av
->first_insn
= NULL
;
3053 av
->has_asm_insn
= 0;
3056 /* Create table entries for DEFINE_ATTR or DEFINE_ENUM_ATTR. */
3059 gen_attr (md_rtx_info
*info
)
3061 struct enum_type
*et
;
3062 struct enum_value
*ev
;
3063 struct attr_desc
*attr
;
3064 const char *name_ptr
;
3066 rtx def
= info
->def
;
3068 /* Make a new attribute structure. Check for duplicate by looking at
3069 attr->default_val, since it is initialized by this routine. */
3070 attr
= find_attr (&XSTR (def
, 0), 1);
3071 if (attr
->default_val
)
3073 error_at (info
->loc
, "duplicate definition for attribute %s",
3075 message_at (attr
->loc
, "previous definition");
3078 attr
->loc
= info
->loc
;
3080 if (GET_CODE (def
) == DEFINE_ENUM_ATTR
)
3082 attr
->enum_name
= XSTR (def
, 1);
3083 et
= rtx_reader_ptr
->lookup_enum_type (XSTR (def
, 1));
3084 if (!et
|| !et
->md_p
)
3085 error_at (info
->loc
, "No define_enum called `%s' defined",
3088 for (ev
= et
->values
; ev
; ev
= ev
->next
)
3089 add_attr_value (attr
, ev
->name
);
3091 else if (*XSTR (def
, 1) == '\0')
3092 attr
->is_numeric
= 1;
3095 name_ptr
= XSTR (def
, 1);
3096 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
3097 add_attr_value (attr
, p
);
3100 if (GET_CODE (XEXP (def
, 2)) == CONST
)
3103 if (attr
->is_numeric
)
3104 error_at (info
->loc
,
3105 "constant attributes may not take numeric values");
3107 /* Get rid of the CONST node. It is allowed only at top-level. */
3108 XEXP (def
, 2) = XEXP (XEXP (def
, 2), 0);
3111 if (! strcmp_check (attr
->name
, length_str
) && ! attr
->is_numeric
)
3112 error_at (info
->loc
, "`length' attribute must take numeric values");
3114 /* Set up the default value. */
3115 XEXP (def
, 2) = check_attr_value (info
->loc
, XEXP (def
, 2), attr
);
3116 attr
->default_val
= get_attr_value (info
->loc
, XEXP (def
, 2), attr
, -2);
3119 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
3120 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
3121 number of alternatives as this should be checked elsewhere. */
3124 count_alternatives (rtx exp
)
3129 if (GET_CODE (exp
) == MATCH_OPERAND
)
3130 return n_comma_elts (XSTR (exp
, 2));
3132 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3133 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3138 n
= count_alternatives (XEXP (exp
, i
));
3145 if (XVEC (exp
, i
) != NULL
)
3146 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3148 n
= count_alternatives (XVECEXP (exp
, i
, j
));
3157 /* Returns nonzero if the given expression contains an EQ_ATTR with the
3158 `alternative' attribute. */
3161 compares_alternatives_p (rtx exp
)
3166 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
3169 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3170 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3175 if (compares_alternatives_p (XEXP (exp
, i
)))
3180 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3181 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
3189 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
3192 gen_insn (md_rtx_info
*info
)
3194 struct insn_def
*id
;
3195 rtx def
= info
->def
;
3197 id
= oballoc (struct insn_def
);
3201 id
->loc
= info
->loc
;
3203 switch (GET_CODE (def
))
3206 id
->insn_code
= info
->index
;
3207 id
->insn_index
= insn_index_number
;
3208 id
->num_alternatives
= count_alternatives (def
);
3209 if (id
->num_alternatives
== 0)
3210 id
->num_alternatives
= 1;
3214 case DEFINE_PEEPHOLE
:
3215 id
->insn_code
= info
->index
;
3216 id
->insn_index
= insn_index_number
;
3217 id
->num_alternatives
= count_alternatives (def
);
3218 if (id
->num_alternatives
== 0)
3219 id
->num_alternatives
= 1;
3223 case DEFINE_ASM_ATTRIBUTES
:
3225 id
->insn_index
= -1;
3226 id
->num_alternatives
= 1;
3228 got_define_asm_attributes
= 1;
3236 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
3237 true or annul false is specified, and make a `struct delay_desc'. */
3240 gen_delay (md_rtx_info
*info
)
3242 struct delay_desc
*delay
;
3245 rtx def
= info
->def
;
3246 if (XVECLEN (def
, 1) % 3 != 0)
3248 error_at (info
->loc
, "number of elements in DEFINE_DELAY must"
3249 " be multiple of three");
3253 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
3255 if (XVECEXP (def
, 1, i
+ 1))
3256 have_annul_true
= 1;
3257 if (XVECEXP (def
, 1, i
+ 2))
3258 have_annul_false
= 1;
3261 delay
= oballoc (struct delay_desc
);
3263 delay
->num
= ++num_delays
;
3264 delay
->next
= delays
;
3265 delay
->loc
= info
->loc
;
3269 /* Names of attributes that could be possibly cached. */
3270 static const char *cached_attrs
[32];
3271 /* Number of such attributes. */
3272 static int cached_attr_count
;
3273 /* Bitmasks of possibly cached attributes. */
3274 static unsigned int attrs_seen_once
, attrs_seen_more_than_once
;
3275 static unsigned int attrs_to_cache
;
3276 static unsigned int attrs_cached_inside
, attrs_cached_after
;
3278 /* Finds non-const attributes that could be possibly cached.
3279 When create is TRUE, fills in cached_attrs array.
3280 Computes ATTRS_SEEN_ONCE and ATTRS_SEEN_MORE_THAN_ONCE
3284 find_attrs_to_cache (rtx exp
, bool create
)
3288 struct attr_desc
*attr
;
3293 switch (GET_CODE (exp
))
3296 if (GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3297 find_attrs_to_cache (XEXP (exp
, 0), create
);
3301 name
= XSTR (exp
, 0);
3302 if (name
== alternative_name
)
3304 for (i
= 0; i
< cached_attr_count
; i
++)
3305 if (name
== cached_attrs
[i
])
3307 if ((attrs_seen_once
& (1U << i
)) != 0)
3308 attrs_seen_more_than_once
|= (1U << i
);
3310 attrs_seen_once
|= (1U << i
);
3315 attr
= find_attr (&name
, 0);
3319 if (cached_attr_count
== 32)
3321 cached_attrs
[cached_attr_count
] = XSTR (exp
, 0);
3322 attrs_seen_once
|= (1U << cached_attr_count
);
3323 cached_attr_count
++;
3328 find_attrs_to_cache (XEXP (exp
, 0), create
);
3329 find_attrs_to_cache (XEXP (exp
, 1), create
);
3333 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3334 find_attrs_to_cache (XVECEXP (exp
, 0, i
), create
);
3342 /* Given a piece of RTX, print a C expression to test its truth value to OUTF.
3343 We use AND and IOR both for logical and bit-wise operations, so
3344 interpret them as logical unless they are inside a comparison expression.
3346 An outermost pair of parentheses is emitted around this C expression unless
3347 EMIT_PARENS is false. */
3349 /* Interpret AND/IOR as bit-wise operations instead of logical. */
3350 #define FLG_BITWISE 1
3351 /* Set if cached attribute will be known initialized in else block after
3352 this condition. This is true for LHS of toplevel && and || and
3353 even for RHS of ||, but not for RHS of &&. */
3355 /* Set if cached attribute will be known initialized in then block after
3356 this condition. This is true for LHS of toplevel && and || and
3357 even for RHS of &&, but not for RHS of ||. */
3358 #define FLG_INSIDE 4
3359 /* Cleared when an operand of &&. */
3360 #define FLG_OUTSIDE_AND 8
3363 write_test_expr (FILE *outf
, rtx exp
, unsigned int attrs_cached
, int flags
,
3364 bool emit_parens
= true)
3366 int comparison_operator
= 0;
3368 struct attr_desc
*attr
;
3371 fprintf (outf
, "(");
3373 code
= GET_CODE (exp
);
3376 /* Binary operators. */
3379 fprintf (outf
, "(unsigned) ");
3385 comparison_operator
= FLG_BITWISE
;
3388 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
3389 case AND
: case IOR
: case XOR
:
3390 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
3391 if ((code
!= AND
&& code
!= IOR
) || (flags
& FLG_BITWISE
))
3393 flags
&= ~(FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
);
3394 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
,
3395 flags
| comparison_operator
);
3400 flags
&= ~FLG_OUTSIDE_AND
;
3401 if (GET_CODE (XEXP (exp
, 0)) == code
3402 || GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3403 || (GET_CODE (XEXP (exp
, 0)) == NOT
3404 && GET_CODE (XEXP (XEXP (exp
, 0), 0)) == EQ_ATTR
))
3406 = write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3408 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3413 fprintf (outf
, " == ");
3416 fprintf (outf
, " != ");
3419 fprintf (outf
, " >= ");
3422 fprintf (outf
, " > ");
3425 fprintf (outf
, " >= (unsigned) ");
3428 fprintf (outf
, " > (unsigned) ");
3431 fprintf (outf
, " <= ");
3434 fprintf (outf
, " < ");
3437 fprintf (outf
, " <= (unsigned) ");
3440 fprintf (outf
, " < (unsigned) ");
3443 fprintf (outf
, " + ");
3446 fprintf (outf
, " - ");
3449 fprintf (outf
, " * ");
3452 fprintf (outf
, " / ");
3455 fprintf (outf
, " %% ");
3458 if (flags
& FLG_BITWISE
)
3459 fprintf (outf
, " & ");
3461 fprintf (outf
, " && ");
3464 if (flags
& FLG_BITWISE
)
3465 fprintf (outf
, " | ");
3467 fprintf (outf
, " || ");
3470 fprintf (outf
, " ^ ");
3473 fprintf (outf
, " << ");
3477 fprintf (outf
, " >> ");
3485 /* For if (something && (cached_x = get_attr_x (insn)) == X)
3486 cached_x is only known to be initialized in then block. */
3487 flags
&= ~FLG_AFTER
;
3489 else if (code
== IOR
)
3491 if (flags
& FLG_OUTSIDE_AND
)
3492 /* For if (something || (cached_x = get_attr_x (insn)) == X)
3493 cached_x is only known to be initialized in else block
3494 and else if conditions. */
3495 flags
&= ~FLG_INSIDE
;
3497 /* For if ((something || (cached_x = get_attr_x (insn)) == X)
3499 cached_x is not know to be initialized anywhere. */
3500 flags
&= ~(FLG_AFTER
| FLG_INSIDE
);
3502 if ((code
== AND
|| code
== IOR
)
3503 && (GET_CODE (XEXP (exp
, 1)) == code
3504 || GET_CODE (XEXP (exp
, 1)) == EQ_ATTR
3505 || (GET_CODE (XEXP (exp
, 1)) == NOT
3506 && GET_CODE (XEXP (XEXP (exp
, 1), 0)) == EQ_ATTR
)))
3508 bool need_parens
= true;
3510 /* No need to emit parentheses around the right-hand operand if we are
3511 continuing a chain of && or || (or & or |). */
3512 if (GET_CODE (XEXP (exp
, 1)) == code
)
3513 need_parens
= false;
3516 = write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
, flags
,
3520 write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
,
3521 flags
| comparison_operator
);
3525 /* Special-case (not (eq_attrq "alternative" "x")) */
3526 if (! (flags
& FLG_BITWISE
) && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3528 if (XSTR (XEXP (exp
, 0), 0) == alternative_name
)
3530 fprintf (outf
, "which_alternative != %s",
3531 XSTR (XEXP (exp
, 0), 1));
3535 fprintf (outf
, "! ");
3537 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3541 /* Otherwise, fall through to normal unary operator. */
3544 /* Unary operators. */
3549 if (flags
& FLG_BITWISE
)
3550 fprintf (outf
, "~ ");
3552 fprintf (outf
, "! ");
3555 fprintf (outf
, "abs ");
3558 fprintf (outf
, "-");
3564 flags
&= ~(FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
);
3565 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3570 int set
= XINT (exp
, 0), bit
= 0;
3572 if (flags
& FLG_BITWISE
)
3573 fatal ("EQ_ATTR_ALT not valid inside comparison");
3576 fatal ("Empty EQ_ATTR_ALT should be optimized out");
3578 if (!(set
& (set
- 1)))
3580 if (!(set
& 0xffff))
3603 fprintf (outf
, "which_alternative %s= %d",
3604 XINT (exp
, 1) ? "!" : "=", bit
);
3608 fprintf (outf
, "%s((1 << which_alternative) & %#x)",
3609 XINT (exp
, 1) ? "!" : "", set
);
3614 /* Comparison test of an attribute with a value. Most of these will
3615 have been removed by optimization. Handle "alternative"
3616 specially and give error if EQ_ATTR present inside a comparison. */
3618 if (flags
& FLG_BITWISE
)
3619 fatal ("EQ_ATTR not valid inside comparison");
3621 if (XSTR (exp
, 0) == alternative_name
)
3623 fprintf (outf
, "which_alternative == %s", XSTR (exp
, 1));
3627 attr
= find_attr (&XSTR (exp
, 0), 0);
3630 /* Now is the time to expand the value of a constant attribute. */
3633 write_test_expr (outf
,
3634 evaluate_eq_attr (exp
, attr
,
3635 attr
->default_val
->value
,
3642 for (i
= 0; i
< cached_attr_count
; i
++)
3643 if (attr
->name
== cached_attrs
[i
])
3645 if (i
< cached_attr_count
&& (attrs_cached
& (1U << i
)) != 0)
3646 fprintf (outf
, "cached_%s", attr
->name
);
3647 else if (i
< cached_attr_count
&& (attrs_to_cache
& (1U << i
)) != 0)
3649 fprintf (outf
, "(cached_%s = get_attr_%s (insn))",
3650 attr
->name
, attr
->name
);
3651 if (flags
& FLG_AFTER
)
3652 attrs_cached_after
|= (1U << i
);
3653 if (flags
& FLG_INSIDE
)
3654 attrs_cached_inside
|= (1U << i
);
3655 attrs_cached
|= (1U << i
);
3658 fprintf (outf
, "get_attr_%s (insn)", attr
->name
);
3659 fprintf (outf
, " == ");
3660 write_attr_valueq (outf
, attr
, XSTR (exp
, 1));
3664 /* Comparison test of flags for define_delays. */
3666 if (flags
& FLG_BITWISE
)
3667 fatal ("ATTR_FLAG not valid inside comparison");
3668 fprintf (outf
, "(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
3671 /* See if an operand matches a predicate. */
3673 /* If only a mode is given, just ensure the mode matches the operand.
3674 If neither a mode nor predicate is given, error. */
3675 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
3677 if (GET_MODE (exp
) == VOIDmode
)
3678 fatal ("null MATCH_OPERAND specified as test");
3680 fprintf (outf
, "GET_MODE (operands[%d]) == %smode",
3681 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3684 fprintf (outf
, "%s (operands[%d], %smode)",
3685 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3688 /* Constant integer. */
3690 fprintf (outf
, HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
3694 rtx_reader_ptr
->fprint_c_condition (outf
, XSTR (exp
, 0));
3695 if (flags
& FLG_BITWISE
)
3696 fprintf (outf
, " != 0");
3699 /* A random C expression. */
3701 rtx_reader_ptr
->fprint_c_condition (outf
, XSTR (exp
, 0));
3704 /* The address of the branch target. */
3707 "INSN_ADDRESSES_SET_P () ? INSN_ADDRESSES (INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])) : 0",
3708 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
3712 /* The address of the current insn. We implement this actually as the
3713 address of the current insn for backward branches, but the last
3714 address of the next insn for forward branches, and both with
3715 adjustments that account for the worst-case possible stretching of
3716 intervening alignments between this insn and its destination. */
3717 fprintf (outf
, "insn_current_reference_address (insn)");
3721 fprintf (outf
, "%s", XSTR (exp
, 0));
3725 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, 0);
3726 fprintf (outf
, " ? ");
3727 write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
, FLG_BITWISE
);
3728 fprintf (outf
, " : ");
3729 write_test_expr (outf
, XEXP (exp
, 2), attrs_cached
, FLG_BITWISE
);
3733 fatal ("bad RTX code `%s' in attribute calculation\n",
3734 GET_RTX_NAME (code
));
3738 fprintf (outf
, ")");
3740 return attrs_cached
;
3743 /* Given an attribute value, return the maximum CONST_STRING argument
3744 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
3747 max_attr_value (rtx exp
, int *unknownp
)
3752 switch (GET_CODE (exp
))
3755 current_max
= atoi (XSTR (exp
, 0));
3759 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
3760 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3762 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3763 if (n
> current_max
)
3769 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
3770 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
3771 if (n
> current_max
)
3777 current_max
= INT_MAX
;
3784 /* Given an attribute value, return the minimum CONST_STRING argument
3785 encountered. Set *UNKNOWNP and return 0 if the value is unknown. */
3788 min_attr_value (rtx exp
, int *unknownp
)
3793 switch (GET_CODE (exp
))
3796 current_min
= atoi (XSTR (exp
, 0));
3800 current_min
= min_attr_value (XEXP (exp
, 1), unknownp
);
3801 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3803 n
= min_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3804 if (n
< current_min
)
3810 current_min
= min_attr_value (XEXP (exp
, 1), unknownp
);
3811 n
= min_attr_value (XEXP (exp
, 2), unknownp
);
3812 if (n
< current_min
)
3818 current_min
= INT_MAX
;
3825 /* Given an attribute value, return the result of ORing together all
3826 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
3827 if the numeric value is not known. */
3830 or_attr_value (rtx exp
, int *unknownp
)
3835 switch (GET_CODE (exp
))
3838 current_or
= atoi (XSTR (exp
, 0));
3842 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
3843 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3844 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3848 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
3849 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
3861 /* Scan an attribute value, possibly a conditional, and record what actions
3862 will be required to do any conditional tests in it.
3865 `must_extract' if we need to extract the insn operands
3866 `must_constrain' if we must compute `which_alternative'
3867 `address_used' if an address expression was used
3868 `length_used' if an (eq_attr "length" ...) was used
3872 walk_attr_value (rtx exp
)
3881 code
= GET_CODE (exp
);
3885 if (! ATTR_IND_SIMPLIFIED_P (exp
))
3886 /* Since this is an arbitrary expression, it can look at anything.
3887 However, constant expressions do not depend on any particular
3889 must_extract
= must_constrain
= 1;
3898 must_extract
= must_constrain
= 1;
3902 if (XSTR (exp
, 0) == alternative_name
)
3903 must_extract
= must_constrain
= 1;
3904 else if (strcmp_check (XSTR (exp
, 0), length_str
) == 0)
3924 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
3929 walk_attr_value (XEXP (exp
, i
));
3933 if (XVEC (exp
, i
) != NULL
)
3934 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3935 walk_attr_value (XVECEXP (exp
, i
, j
));
3940 /* Write out a function to obtain the attribute for a given INSN. */
3943 write_attr_get (FILE *outf
, struct attr_desc
*attr
)
3945 struct attr_value
*av
, *common_av
;
3948 /* Find the most used attribute value. Handle that as the `default' of the
3949 switch we will generate. */
3950 common_av
= find_most_used (attr
);
3952 /* Write out start of function, then all values with explicit `case' lines,
3953 then a `default', then the value with the most uses. */
3954 if (attr
->enum_name
)
3955 fprintf (outf
, "enum %s\n", attr
->enum_name
);
3956 else if (!attr
->is_numeric
)
3957 fprintf (outf
, "enum attr_%s\n", attr
->name
);
3959 fprintf (outf
, "int\n");
3961 /* If the attribute name starts with a star, the remainder is the name of
3962 the subroutine to use, instead of `get_attr_...'. */
3963 if (attr
->name
[0] == '*')
3964 fprintf (outf
, "%s (rtx_insn *insn ATTRIBUTE_UNUSED)\n", &attr
->name
[1]);
3965 else if (attr
->is_const
== 0)
3966 fprintf (outf
, "get_attr_%s (rtx_insn *insn ATTRIBUTE_UNUSED)\n", attr
->name
);
3969 fprintf (outf
, "get_attr_%s (void)\n", attr
->name
);
3970 fprintf (outf
, "{\n");
3972 for (av
= attr
->first_value
; av
; av
= av
->next
)
3973 if (av
->num_insns
== 1)
3974 write_attr_set (outf
, attr
, 2, av
->value
, "return", ";",
3975 true_rtx
, av
->first_insn
->def
->insn_code
,
3976 av
->first_insn
->def
->insn_index
, 0);
3977 else if (av
->num_insns
!= 0)
3978 write_attr_set (outf
, attr
, 2, av
->value
, "return", ";",
3979 true_rtx
, -2, 0, 0);
3981 fprintf (outf
, "}\n\n");
3985 fprintf (outf
, "{\n");
3987 /* Find attributes that are worth caching in the conditions. */
3988 cached_attr_count
= 0;
3989 attrs_seen_more_than_once
= 0;
3990 for (av
= attr
->first_value
; av
; av
= av
->next
)
3992 attrs_seen_once
= 0;
3993 find_attrs_to_cache (av
->value
, true);
3995 /* Remove those that aren't worth caching from the array. */
3996 for (i
= 0, j
= 0; i
< cached_attr_count
; i
++)
3997 if ((attrs_seen_more_than_once
& (1U << i
)) != 0)
3999 const char *name
= cached_attrs
[i
];
4000 struct attr_desc
*cached_attr
;
4002 cached_attrs
[j
] = name
;
4003 cached_attr
= find_attr (&name
, 0);
4004 gcc_assert (cached_attr
&& cached_attr
->is_const
== 0);
4005 if (cached_attr
->enum_name
)
4006 fprintf (outf
, " enum %s", cached_attr
->enum_name
);
4007 else if (!cached_attr
->is_numeric
)
4008 fprintf (outf
, " enum attr_%s", cached_attr
->name
);
4010 fprintf (outf
, " int");
4011 fprintf (outf
, " cached_%s ATTRIBUTE_UNUSED;\n", name
);
4014 cached_attr_count
= j
;
4015 if (cached_attr_count
)
4016 fprintf (outf
, "\n");
4018 fprintf (outf
, " switch (recog_memoized (insn))\n");
4019 fprintf (outf
, " {\n");
4021 for (av
= attr
->first_value
; av
; av
= av
->next
)
4022 if (av
!= common_av
)
4023 write_attr_case (outf
, attr
, av
, 1, "return", ";", 4, true_rtx
);
4025 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4026 fprintf (outf
, " }\n}\n\n");
4027 cached_attr_count
= 0;
4030 /* Given an AND tree of known true terms (because we are inside an `if' with
4031 that as the condition or are in an `else' clause) and an expression,
4032 replace any known true terms with TRUE. Use `simplify_and_tree' to do
4033 the bulk of the work. */
4036 eliminate_known_true (rtx known_true
, rtx exp
, int insn_code
, int insn_index
)
4040 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
4042 if (GET_CODE (known_true
) == AND
)
4044 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
4045 insn_code
, insn_index
);
4046 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
4047 insn_code
, insn_index
);
4052 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
4058 /* Write out a series of tests and assignment statements to perform tests and
4059 sets of an attribute value. We are passed an indentation amount and prefix
4060 and suffix strings to write around each attribute value (e.g., "return"
4064 write_attr_set (FILE *outf
, struct attr_desc
*attr
, int indent
, rtx value
,
4065 const char *prefix
, const char *suffix
, rtx known_true
,
4066 int insn_code
, int insn_index
, unsigned int attrs_cached
)
4068 if (GET_CODE (value
) == COND
)
4070 /* Assume the default value will be the default of the COND unless we
4071 find an always true expression. */
4072 rtx default_val
= XEXP (value
, 1);
4073 rtx our_known_true
= known_true
;
4078 if (cached_attr_count
)
4080 attrs_seen_once
= 0;
4081 attrs_seen_more_than_once
= 0;
4082 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4083 find_attrs_to_cache (XVECEXP (value
, 0, i
), false);
4084 attrs_to_cache
|= attrs_seen_more_than_once
;
4087 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4092 /* Reset our_known_true after some time to not accumulate
4093 too much cruft (slowing down genattrtab). */
4095 our_known_true
= known_true
;
4096 testexp
= eliminate_known_true (our_known_true
,
4097 XVECEXP (value
, 0, i
),
4098 insn_code
, insn_index
);
4099 newexp
= attr_rtx (NOT
, testexp
);
4100 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
4101 insn_code
, insn_index
);
4103 /* If the test expression is always true or if the next `known_true'
4104 expression is always false, this is the last case, so break
4105 out and let this value be the `else' case. */
4106 if (testexp
== true_rtx
|| newexp
== false_rtx
)
4108 default_val
= XVECEXP (value
, 0, i
+ 1);
4112 /* Compute the expression to pass to our recursive call as being
4114 inner_true
= insert_right_side (AND
, our_known_true
,
4115 testexp
, insn_code
, insn_index
);
4117 /* If this is always false, skip it. */
4118 if (inner_true
== false_rtx
)
4121 attrs_cached_inside
= attrs_cached
;
4122 attrs_cached_after
= attrs_cached
;
4123 write_indent (outf
, indent
);
4124 fprintf (outf
, "%sif ", first_if
? "" : "else ");
4126 write_test_expr (outf
, testexp
, attrs_cached
,
4127 (FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
));
4128 attrs_cached
= attrs_cached_after
;
4129 fprintf (outf
, "\n");
4130 write_indent (outf
, indent
+ 2);
4131 fprintf (outf
, "{\n");
4133 write_attr_set (outf
, attr
, indent
+ 4,
4134 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
4135 inner_true
, insn_code
, insn_index
,
4136 attrs_cached_inside
);
4137 write_indent (outf
, indent
+ 2);
4138 fprintf (outf
, "}\n");
4139 our_known_true
= newexp
;
4144 write_indent (outf
, indent
);
4145 fprintf (outf
, "else\n");
4146 write_indent (outf
, indent
+ 2);
4147 fprintf (outf
, "{\n");
4150 write_attr_set (outf
, attr
, first_if
? indent
: indent
+ 4, default_val
,
4151 prefix
, suffix
, our_known_true
, insn_code
, insn_index
,
4156 write_indent (outf
, indent
+ 2);
4157 fprintf (outf
, "}\n");
4162 write_indent (outf
, indent
);
4163 fprintf (outf
, "%s ", prefix
);
4164 write_attr_value (outf
, attr
, value
);
4165 fprintf (outf
, "%s\n", suffix
);
4169 /* Write a series of case statements for every instruction in list IE.
4170 INDENT is the amount of indentation to write before each case. */
4173 write_insn_cases (FILE *outf
, struct insn_ent
*ie
, int indent
)
4175 for (; ie
!= 0; ie
= ie
->next
)
4176 if (ie
->def
->insn_code
!= -1)
4178 write_indent (outf
, indent
);
4179 if (GET_CODE (ie
->def
->def
) == DEFINE_PEEPHOLE
)
4180 fprintf (outf
, "case %d: /* define_peephole, %s:%d */\n",
4181 ie
->def
->insn_code
, ie
->def
->loc
.filename
,
4182 ie
->def
->loc
.lineno
);
4184 fprintf (outf
, "case %d: /* %s */\n",
4185 ie
->def
->insn_code
, XSTR (ie
->def
->def
, 0));
4189 /* Write out the computation for one attribute value. */
4192 write_attr_case (FILE *outf
, struct attr_desc
*attr
, struct attr_value
*av
,
4193 int write_case_lines
, const char *prefix
, const char *suffix
,
4194 int indent
, rtx known_true
)
4196 if (av
->num_insns
== 0)
4199 if (av
->has_asm_insn
)
4201 write_indent (outf
, indent
);
4202 fprintf (outf
, "case -1:\n");
4203 write_indent (outf
, indent
+ 2);
4204 fprintf (outf
, "if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
4205 write_indent (outf
, indent
+ 2);
4206 fprintf (outf
, " && asm_noperands (PATTERN (insn)) < 0)\n");
4207 write_indent (outf
, indent
+ 2);
4208 fprintf (outf
, " fatal_insn_not_found (insn);\n");
4209 write_indent (outf
, indent
+ 2);
4210 fprintf (outf
, "/* FALLTHRU */\n");
4213 if (write_case_lines
)
4214 write_insn_cases (outf
, av
->first_insn
, indent
);
4217 write_indent (outf
, indent
);
4218 fprintf (outf
, "default:\n");
4221 /* See what we have to do to output this value. */
4222 must_extract
= must_constrain
= address_used
= 0;
4223 walk_attr_value (av
->value
);
4227 write_indent (outf
, indent
+ 2);
4228 fprintf (outf
, "extract_constrain_insn_cached (insn);\n");
4230 else if (must_extract
)
4232 write_indent (outf
, indent
+ 2);
4233 fprintf (outf
, "extract_insn_cached (insn);\n");
4237 if (av
->num_insns
== 1)
4238 write_attr_set (outf
, attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4239 known_true
, av
->first_insn
->def
->insn_code
,
4240 av
->first_insn
->def
->insn_index
, 0);
4242 write_attr_set (outf
, attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4243 known_true
, -2, 0, 0);
4245 if (strncmp (prefix
, "return", 6))
4247 write_indent (outf
, indent
+ 2);
4248 fprintf (outf
, "break;\n");
4250 fprintf (outf
, "\n");
4253 /* Utilities to write in various forms. */
4256 write_attr_valueq (FILE *outf
, struct attr_desc
*attr
, const char *s
)
4258 if (attr
->is_numeric
)
4262 fprintf (outf
, "%d", num
);
4264 if (num
> 9 || num
< 0)
4265 fprintf (outf
, " /* %#x */", num
);
4269 write_upcase (outf
, attr
->enum_name
? attr
->enum_name
: attr
->name
);
4270 fprintf (outf
, "_");
4271 write_upcase (outf
, s
);
4276 write_attr_value (FILE *outf
, struct attr_desc
*attr
, rtx value
)
4280 switch (GET_CODE (value
))
4283 write_attr_valueq (outf
, attr
, XSTR (value
, 0));
4287 fprintf (outf
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (value
));
4291 rtx_reader_ptr
->fprint_c_condition (outf
, XSTR (value
, 0));
4296 struct attr_desc
*attr2
= find_attr (&XSTR (value
, 0), 0);
4297 if (attr
->enum_name
)
4298 fprintf (outf
, "(enum %s)", attr
->enum_name
);
4299 else if (!attr
->is_numeric
)
4300 fprintf (outf
, "(enum attr_%s)", attr
->name
);
4301 else if (!attr2
->is_numeric
)
4302 fprintf (outf
, "(int)");
4304 fprintf (outf
, "get_attr_%s (%s)", attr2
->name
,
4305 (attr2
->is_const
? "" : "insn"));
4326 write_attr_value (outf
, attr
, XEXP (value
, 0));
4330 write_attr_value (outf
, attr
, XEXP (value
, 1));
4339 write_upcase (FILE *outf
, const char *str
)
4343 /* The argument of TOUPPER should not have side effects. */
4344 fputc (TOUPPER (*str
), outf
);
4350 write_indent (FILE *outf
, int indent
)
4352 for (; indent
> 8; indent
-= 8)
4353 fprintf (outf
, "\t");
4355 for (; indent
; indent
--)
4356 fprintf (outf
, " ");
4359 /* If the target does not have annul-true or annul-false delay slots, this
4360 function will create a dummy eligible_for function on OUTF which always
4361 returns false. KIND will be annul_true or annul_false. */
4364 write_dummy_eligible_delay (FILE *outf
, const char *kind
)
4366 /* Write function prelude. */
4368 fprintf (outf
, "int\n");
4369 fprintf (outf
, "eligible_for_%s (rtx_insn *delay_insn ATTRIBUTE_UNUSED,\n"
4370 " int slot ATTRIBUTE_UNUSED,\n"
4371 " rtx_insn *candidate_insn ATTRIBUTE_UNUSED,\n"
4372 " int flags ATTRIBUTE_UNUSED)\n",
4374 fprintf (outf
, "{\n");
4375 fprintf (outf
, " return 0;\n");
4376 fprintf (outf
, "}\n\n");
4379 /* Write a subroutine that is given an insn that requires a delay slot, a
4380 delay slot ordinal, and a candidate insn. It returns nonzero if the
4381 candidate can be placed in the specified delay slot of the insn.
4383 We can write as many as three subroutines. `eligible_for_delay'
4384 handles normal delay slots, `eligible_for_annul_true' indicates that
4385 the specified insn can be annulled if the branch is true, and likewise
4386 for `eligible_for_annul_false'.
4388 KIND is a string distinguishing these three cases ("delay", "annul_true",
4389 or "annul_false"). */
4392 write_eligible_delay (FILE *outf
, const char *kind
)
4394 struct delay_desc
*delay
;
4398 struct attr_desc
*attr
;
4399 struct attr_value
*av
, *common_av
;
4402 /* Compute the maximum number of delay slots required. We use the delay
4403 ordinal times this number plus one, plus the slot number as an index into
4404 the appropriate predicate to test. */
4406 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
4407 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
4408 max_slots
= XVECLEN (delay
->def
, 1) / 3;
4410 /* Write function prelude. */
4412 fprintf (outf
, "int\n");
4413 fprintf (outf
, "eligible_for_%s (rtx_insn *delay_insn ATTRIBUTE_UNUSED, int slot, \n"
4414 " rtx_insn *candidate_insn, int flags ATTRIBUTE_UNUSED)\n",
4416 fprintf (outf
, "{\n");
4417 fprintf (outf
, " rtx_insn *insn ATTRIBUTE_UNUSED;\n");
4418 fprintf (outf
, "\n");
4419 fprintf (outf
, " if (num_delay_slots (delay_insn) == 0)\n");
4420 fprintf (outf
, " return 0;");
4421 fprintf (outf
, "\n");
4422 fprintf (outf
, " gcc_assert (slot < %d);\n", max_slots
);
4423 fprintf (outf
, "\n");
4424 /* Allow dbr_schedule to pass labels, etc. This can happen if try_split
4425 converts a compound instruction into a loop. */
4426 fprintf (outf
, " if (!INSN_P (candidate_insn))\n");
4427 fprintf (outf
, " return 0;\n");
4428 fprintf (outf
, "\n");
4430 /* If more than one delay type, find out which type the delay insn is. */
4434 attr
= find_attr (&delay_type_str
, 0);
4436 common_av
= find_most_used (attr
);
4438 fprintf (outf
, " insn = delay_insn;\n");
4439 fprintf (outf
, " switch (recog_memoized (insn))\n");
4440 fprintf (outf
, " {\n");
4442 sprintf (str
, " * %d;\n break;", max_slots
);
4443 for (av
= attr
->first_value
; av
; av
= av
->next
)
4444 if (av
!= common_av
)
4445 write_attr_case (outf
, attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
4447 write_attr_case (outf
, attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
4448 fprintf (outf
, " }\n\n");
4450 /* Ensure matched. Otherwise, shouldn't have been called. */
4451 fprintf (outf
, " gcc_assert (slot >= %d);\n\n", max_slots
);
4454 /* If just one type of delay slot, write simple switch. */
4455 if (num_delays
== 1 && max_slots
== 1)
4457 fprintf (outf
, " insn = candidate_insn;\n");
4458 fprintf (outf
, " switch (recog_memoized (insn))\n");
4459 fprintf (outf
, " {\n");
4461 attr
= find_attr (&delay_1_0_str
, 0);
4463 common_av
= find_most_used (attr
);
4465 for (av
= attr
->first_value
; av
; av
= av
->next
)
4466 if (av
!= common_av
)
4467 write_attr_case (outf
, attr
, av
, 1, "return", ";", 4, true_rtx
);
4469 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4470 fprintf (outf
, " }\n");
4475 /* Write a nested CASE. The first indicates which condition we need to
4476 test, and the inner CASE tests the condition. */
4477 fprintf (outf
, " insn = candidate_insn;\n");
4478 fprintf (outf
, " switch (slot)\n");
4479 fprintf (outf
, " {\n");
4481 for (delay
= delays
; delay
; delay
= delay
->next
)
4482 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
4484 fprintf (outf
, " case %d:\n",
4485 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
4486 fprintf (outf
, " switch (recog_memoized (insn))\n");
4487 fprintf (outf
, "\t{\n");
4489 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
4491 attr
= find_attr (&pstr
, 0);
4493 common_av
= find_most_used (attr
);
4495 for (av
= attr
->first_value
; av
; av
= av
->next
)
4496 if (av
!= common_av
)
4497 write_attr_case (outf
, attr
, av
, 1, "return", ";", 8, true_rtx
);
4499 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 8, true_rtx
);
4500 fprintf (outf
, " }\n");
4503 fprintf (outf
, " default:\n");
4504 fprintf (outf
, " gcc_unreachable ();\n");
4505 fprintf (outf
, " }\n");
4508 fprintf (outf
, "}\n\n");
4511 /* This page contains miscellaneous utility routines. */
4513 /* Given a pointer to a (char *), return a malloc'ed string containing the
4514 next comma-separated element. Advance the pointer to after the string
4515 scanned, or the end-of-string. Return NULL if at end of string. */
4518 next_comma_elt (const char **pstr
)
4522 start
= scan_comma_elt (pstr
);
4527 return attr_string (start
, *pstr
- start
);
4530 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
4531 is nonzero, build a new attribute, if one does not exist. *NAME_P is
4532 replaced by a pointer to a canonical copy of the string. */
4534 static struct attr_desc
*
4535 find_attr (const char **name_p
, int create
)
4537 struct attr_desc
*attr
;
4539 const char *name
= *name_p
;
4541 /* Before we resort to using `strcmp', see if the string address matches
4542 anywhere. In most cases, it should have been canonicalized to do so. */
4543 if (name
== alternative_name
)
4546 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
4547 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4548 if (name
== attr
->name
)
4551 /* Otherwise, do it the slow way. */
4552 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4553 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
4555 *name_p
= attr
->name
;
4562 attr
= oballoc (struct attr_desc
);
4563 attr
->name
= DEF_ATTR_STRING (name
);
4564 attr
->enum_name
= 0;
4565 attr
->first_value
= attr
->default_val
= NULL
;
4566 attr
->is_numeric
= attr
->is_const
= attr
->is_special
= 0;
4567 attr
->next
= attrs
[index
];
4568 attrs
[index
] = attr
;
4570 *name_p
= attr
->name
;
4575 /* Create internal attribute with the given default value. */
4578 make_internal_attr (const char *name
, rtx value
, int special
)
4580 struct attr_desc
*attr
;
4582 attr
= find_attr (&name
, 1);
4583 gcc_assert (!attr
->default_val
);
4585 attr
->is_numeric
= 1;
4587 attr
->is_special
= (special
& ATTR_SPECIAL
) != 0;
4588 attr
->default_val
= get_attr_value (file_location ("<internal>", 0, 0),
4592 /* Find the most used value of an attribute. */
4594 static struct attr_value
*
4595 find_most_used (struct attr_desc
*attr
)
4597 struct attr_value
*av
;
4598 struct attr_value
*most_used
;
4604 for (av
= attr
->first_value
; av
; av
= av
->next
)
4605 if (av
->num_insns
> nuses
)
4606 nuses
= av
->num_insns
, most_used
= av
;
4611 /* Return (attr_value "n") */
4614 make_numeric_value (int n
)
4616 static rtx int_values
[20];
4620 gcc_assert (n
>= 0);
4622 if (n
< 20 && int_values
[n
])
4623 return int_values
[n
];
4625 p
= attr_printf (MAX_DIGITS
, "%d", n
);
4626 exp
= attr_rtx (CONST_STRING
, p
);
4629 int_values
[n
] = exp
;
4635 copy_rtx_unchanging (rtx orig
)
4637 if (ATTR_IND_SIMPLIFIED_P (orig
) || ATTR_CURR_SIMPLIFIED_P (orig
))
4640 ATTR_CURR_SIMPLIFIED_P (orig
) = 1;
4644 /* Determine if an insn has a constant number of delay slots, i.e., the
4645 number of delay slots is not a function of the length of the insn. */
4648 write_const_num_delay_slots (FILE *outf
)
4650 struct attr_desc
*attr
= find_attr (&num_delay_slots_str
, 0);
4651 struct attr_value
*av
;
4655 fprintf (outf
, "int\nconst_num_delay_slots (rtx_insn *insn)\n");
4656 fprintf (outf
, "{\n");
4657 fprintf (outf
, " switch (recog_memoized (insn))\n");
4658 fprintf (outf
, " {\n");
4660 for (av
= attr
->first_value
; av
; av
= av
->next
)
4663 walk_attr_value (av
->value
);
4665 write_insn_cases (outf
, av
->first_insn
, 4);
4668 fprintf (outf
, " default:\n");
4669 fprintf (outf
, " return 1;\n");
4670 fprintf (outf
, " }\n}\n\n");
4674 /* Synthetic attributes used by insn-automata.c and the scheduler.
4675 These are primarily concerned with (define_insn_reservation)
4680 struct insn_reserv
*next
;
4683 int default_latency
;
4686 /* Sequence number of this insn. */
4689 /* Whether a (define_bypass) construct names this insn in its
4694 static struct insn_reserv
*all_insn_reservs
= 0;
4695 static struct insn_reserv
**last_insn_reserv_p
= &all_insn_reservs
;
4696 static size_t n_insn_reservs
;
4698 /* Store information from a DEFINE_INSN_RESERVATION for future
4699 attribute generation. */
4701 gen_insn_reserv (md_rtx_info
*info
)
4703 struct insn_reserv
*decl
= oballoc (struct insn_reserv
);
4704 rtx def
= info
->def
;
4706 struct attr_desc attr
= { };
4708 attr
.name
= DEF_ATTR_STRING (XSTR (def
, 0));
4709 attr
.loc
= info
->loc
;
4711 decl
->name
= DEF_ATTR_STRING (XSTR (def
, 0));
4712 decl
->default_latency
= XINT (def
, 1);
4713 decl
->condexp
= check_attr_test (info
->loc
, XEXP (def
, 2), &attr
);
4714 decl
->insn_num
= n_insn_reservs
;
4715 decl
->bypassed
= false;
4718 *last_insn_reserv_p
= decl
;
4719 last_insn_reserv_p
= &decl
->next
;
4723 /* Store information from a DEFINE_BYPASS for future attribute
4724 generation. The only thing we care about is the list of output
4725 insns, which will later be used to tag reservation structures with
4726 a 'bypassed' bit. */
4730 struct bypass_list
*next
;
4731 const char *pattern
;
4734 static struct bypass_list
*all_bypasses
;
4735 static size_t n_bypasses
;
4736 static size_t n_bypassed
;
4739 gen_bypass_1 (const char *s
, size_t len
)
4741 struct bypass_list
*b
;
4746 s
= attr_string (s
, len
);
4747 for (b
= all_bypasses
; b
; b
= b
->next
)
4748 if (s
== b
->pattern
)
4749 return; /* already got that one */
4751 b
= oballoc (struct bypass_list
);
4753 b
->next
= all_bypasses
;
4759 gen_bypass (md_rtx_info
*info
)
4761 const char *p
, *base
;
4763 rtx def
= info
->def
;
4764 for (p
= base
= XSTR (def
, 1); *p
; p
++)
4767 gen_bypass_1 (base
, p
- base
);
4770 while (ISSPACE (*p
));
4773 gen_bypass_1 (base
, p
- base
);
4776 /* Find and mark all of the bypassed insns. */
4778 process_bypasses (void)
4780 struct bypass_list
*b
;
4781 struct insn_reserv
*r
;
4785 /* The reservation list is likely to be much longer than the bypass
4787 for (r
= all_insn_reservs
; r
; r
= r
->next
)
4788 for (b
= all_bypasses
; b
; b
= b
->next
)
4789 if (fnmatch (b
->pattern
, r
->name
, 0) == 0)
4797 /* Check that attribute NAME is used in define_insn_reservation condition
4798 EXP. Return true if it is. */
4800 check_tune_attr (const char *name
, rtx exp
)
4802 switch (GET_CODE (exp
))
4805 if (check_tune_attr (name
, XEXP (exp
, 0)))
4807 return check_tune_attr (name
, XEXP (exp
, 1));
4810 return (check_tune_attr (name
, XEXP (exp
, 0))
4811 && check_tune_attr (name
, XEXP (exp
, 1)));
4814 return XSTR (exp
, 0) == name
;
4821 /* Try to find a const attribute (usually cpu or tune) that is used
4822 in all define_insn_reservation conditions. */
4823 static struct attr_desc
*
4824 find_tune_attr (rtx exp
)
4826 struct attr_desc
*attr
;
4828 switch (GET_CODE (exp
))
4832 attr
= find_tune_attr (XEXP (exp
, 0));
4835 return find_tune_attr (XEXP (exp
, 1));
4838 if (XSTR (exp
, 0) == alternative_name
)
4841 attr
= find_attr (&XSTR (exp
, 0), 0);
4844 if (attr
->is_const
&& !attr
->is_special
)
4846 struct insn_reserv
*decl
;
4848 for (decl
= all_insn_reservs
; decl
; decl
= decl
->next
)
4849 if (! check_tune_attr (attr
->name
, decl
->condexp
))
4860 /* Create all of the attributes that describe automaton properties.
4861 Write the DFA and latency function prototypes to the files that
4862 need to have them, and write the init_sched_attrs(). */
4865 make_automaton_attrs (void)
4868 struct insn_reserv
*decl
;
4869 rtx code_exp
, lats_exp
, byps_exp
;
4870 struct attr_desc
*tune_attr
;
4872 if (n_insn_reservs
== 0)
4875 tune_attr
= find_tune_attr (all_insn_reservs
->condexp
);
4876 if (tune_attr
!= NULL
)
4878 rtx
*condexps
= XNEWVEC (rtx
, n_insn_reservs
* 3);
4879 struct attr_value
*val
;
4882 gcc_assert (tune_attr
->is_const
4883 && !tune_attr
->is_special
4884 && !tune_attr
->is_numeric
);
4886 /* Write the prototypes for all DFA functions. */
4887 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4889 if (val
== tune_attr
->default_val
)
4891 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4893 "extern int internal_dfa_insn_code_%s (rtx_insn *);\n",
4894 XSTR (val
->value
, 0));
4896 fprintf (dfa_file
, "\n");
4898 /* Write the prototypes for all latency functions. */
4899 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4901 if (val
== tune_attr
->default_val
)
4903 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4904 fprintf (latency_file
,
4905 "extern int insn_default_latency_%s (rtx_insn *);\n",
4906 XSTR (val
->value
, 0));
4908 fprintf (latency_file
, "\n");
4910 /* Write the prototypes for all automaton functions. */
4911 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4913 if (val
== tune_attr
->default_val
)
4915 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4917 "extern int internal_dfa_insn_code_%s (rtx_insn *);\n"
4918 "extern int insn_default_latency_%s (rtx_insn *);\n",
4919 XSTR (val
->value
, 0), XSTR (val
->value
, 0));
4921 fprintf (attr_file
, "\n");
4922 fprintf (attr_file
, "int (*internal_dfa_insn_code) (rtx_insn *);\n");
4923 fprintf (attr_file
, "int (*insn_default_latency) (rtx_insn *);\n");
4924 fprintf (attr_file
, "\n");
4925 fprintf (attr_file
, "void\n");
4926 fprintf (attr_file
, "init_sched_attrs (void)\n");
4927 fprintf (attr_file
, "{\n");
4929 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4933 rtx test
= attr_eq (tune_attr
->name
, XSTR (val
->value
, 0));
4935 if (val
== tune_attr
->default_val
)
4937 for (decl
= all_insn_reservs
, i
= 0;
4943 = simplify_and_tree (decl
->condexp
, &ctest
, -2, 0);
4944 if (condexp
== false_rtx
)
4946 if (condexp
== true_rtx
)
4948 condexps
[i
] = condexp
;
4949 condexps
[i
+ 1] = make_numeric_value (decl
->insn_num
);
4950 condexps
[i
+ 2] = make_numeric_value (decl
->default_latency
);
4954 code_exp
= rtx_alloc (COND
);
4955 lats_exp
= rtx_alloc (COND
);
4958 XVEC (code_exp
, 0) = rtvec_alloc (j
);
4959 XVEC (lats_exp
, 0) = rtvec_alloc (j
);
4963 XEXP (code_exp
, 1) = make_numeric_value (decl
->insn_num
);
4964 XEXP (lats_exp
, 1) = make_numeric_value (decl
->default_latency
);
4968 XEXP (code_exp
, 1) = make_numeric_value (n_insn_reservs
+ 1);
4969 XEXP (lats_exp
, 1) = make_numeric_value (0);
4976 XVECEXP (code_exp
, 0, j
) = condexps
[i
];
4977 XVECEXP (lats_exp
, 0, j
) = condexps
[i
];
4979 XVECEXP (code_exp
, 0, j
+ 1) = condexps
[i
+ 1];
4980 XVECEXP (lats_exp
, 0, j
+ 1) = condexps
[i
+ 2];
4983 name
= XNEWVEC (char,
4984 sizeof ("*internal_dfa_insn_code_")
4985 + strlen (XSTR (val
->value
, 0)));
4986 strcpy (name
, "*internal_dfa_insn_code_");
4987 strcat (name
, XSTR (val
->value
, 0));
4988 make_internal_attr (name
, code_exp
, ATTR_NONE
);
4989 strcpy (name
, "*insn_default_latency_");
4990 strcat (name
, XSTR (val
->value
, 0));
4991 make_internal_attr (name
, lats_exp
, ATTR_NONE
);
4996 fprintf (attr_file
, " if (");
5000 fprintf (attr_file
, " else if (");
5001 write_test_expr (attr_file
, test
, 0, 0);
5002 fprintf (attr_file
, ")\n");
5003 fprintf (attr_file
, " {\n");
5004 fprintf (attr_file
, " internal_dfa_insn_code\n");
5005 fprintf (attr_file
, " = internal_dfa_insn_code_%s;\n",
5006 XSTR (val
->value
, 0));
5007 fprintf (attr_file
, " insn_default_latency\n");
5008 fprintf (attr_file
, " = insn_default_latency_%s;\n",
5009 XSTR (val
->value
, 0));
5010 fprintf (attr_file
, " }\n");
5013 fprintf (attr_file
, " else\n");
5014 fprintf (attr_file
, " gcc_unreachable ();\n");
5015 fprintf (attr_file
, "}\n");
5016 fprintf (attr_file
, "\n");
5018 XDELETEVEC (condexps
);
5022 code_exp
= rtx_alloc (COND
);
5023 lats_exp
= rtx_alloc (COND
);
5025 XVEC (code_exp
, 0) = rtvec_alloc (n_insn_reservs
* 2);
5026 XVEC (lats_exp
, 0) = rtvec_alloc (n_insn_reservs
* 2);
5028 XEXP (code_exp
, 1) = make_numeric_value (n_insn_reservs
+ 1);
5029 XEXP (lats_exp
, 1) = make_numeric_value (0);
5031 for (decl
= all_insn_reservs
, i
= 0;
5033 decl
= decl
->next
, i
+= 2)
5035 XVECEXP (code_exp
, 0, i
) = decl
->condexp
;
5036 XVECEXP (lats_exp
, 0, i
) = decl
->condexp
;
5038 XVECEXP (code_exp
, 0, i
+1) = make_numeric_value (decl
->insn_num
);
5039 XVECEXP (lats_exp
, 0, i
+1)
5040 = make_numeric_value (decl
->default_latency
);
5042 make_internal_attr ("*internal_dfa_insn_code", code_exp
, ATTR_NONE
);
5043 make_internal_attr ("*insn_default_latency", lats_exp
, ATTR_NONE
);
5046 if (n_bypasses
== 0)
5047 byps_exp
= make_numeric_value (0);
5050 process_bypasses ();
5052 byps_exp
= rtx_alloc (COND
);
5053 XVEC (byps_exp
, 0) = rtvec_alloc (n_bypassed
* 2);
5054 XEXP (byps_exp
, 1) = make_numeric_value (0);
5055 for (decl
= all_insn_reservs
, i
= 0;
5060 XVECEXP (byps_exp
, 0, i
) = decl
->condexp
;
5061 XVECEXP (byps_exp
, 0, i
+1) = make_numeric_value (1);
5066 make_internal_attr ("*bypass_p", byps_exp
, ATTR_NONE
);
5070 write_header (FILE *outf
)
5072 fprintf (outf
, "/* Generated automatically by the program `genattrtab'\n"
5073 " from the machine description file `md'. */\n\n");
5075 fprintf (outf
, "#include \"config.h\"\n");
5076 fprintf (outf
, "#include \"system.h\"\n");
5077 fprintf (outf
, "#include \"coretypes.h\"\n");
5078 fprintf (outf
, "#include \"backend.h\"\n");
5079 fprintf (outf
, "#include \"predict.h\"\n");
5080 fprintf (outf
, "#include \"tree.h\"\n");
5081 fprintf (outf
, "#include \"rtl.h\"\n");
5082 fprintf (outf
, "#include \"alias.h\"\n");
5083 fprintf (outf
, "#include \"options.h\"\n");
5084 fprintf (outf
, "#include \"varasm.h\"\n");
5085 fprintf (outf
, "#include \"stor-layout.h\"\n");
5086 fprintf (outf
, "#include \"calls.h\"\n");
5087 fprintf (outf
, "#include \"insn-attr.h\"\n");
5088 fprintf (outf
, "#include \"memmodel.h\"\n");
5089 fprintf (outf
, "#include \"tm_p.h\"\n");
5090 fprintf (outf
, "#include \"insn-config.h\"\n");
5091 fprintf (outf
, "#include \"recog.h\"\n");
5092 fprintf (outf
, "#include \"regs.h\"\n");
5093 fprintf (outf
, "#include \"real.h\"\n");
5094 fprintf (outf
, "#include \"output.h\"\n");
5095 fprintf (outf
, "#include \"toplev.h\"\n");
5096 fprintf (outf
, "#include \"flags.h\"\n");
5097 fprintf (outf
, "#include \"emit-rtl.h\"\n");
5098 fprintf (outf
, "\n");
5099 fprintf (outf
, "#define operands recog_data.operand\n\n");
5103 open_outfile (const char *file_name
)
5106 outf
= fopen (file_name
, "w");
5108 fatal ("cannot open file %s: %s", file_name
, xstrerror (errno
));
5109 write_header (outf
);
5114 handle_arg (const char *arg
)
5119 attr_file_name
= &arg
[2];
5122 dfa_file_name
= &arg
[2];
5125 latency_file_name
= &arg
[2];
5133 main (int argc
, const char **argv
)
5135 struct attr_desc
*attr
;
5136 struct insn_def
*id
;
5139 progname
= "genattrtab";
5141 if (!init_rtx_reader_args_cb (argc
, argv
, handle_arg
))
5142 return FATAL_EXIT_CODE
;
5144 attr_file
= open_outfile (attr_file_name
);
5145 dfa_file
= open_outfile (dfa_file_name
);
5146 latency_file
= open_outfile (latency_file_name
);
5148 obstack_init (hash_obstack
);
5149 obstack_init (temp_obstack
);
5151 /* Set up true and false rtx's */
5152 true_rtx
= rtx_alloc (CONST_INT
);
5153 XWINT (true_rtx
, 0) = 1;
5154 false_rtx
= rtx_alloc (CONST_INT
);
5155 XWINT (false_rtx
, 0) = 0;
5156 ATTR_IND_SIMPLIFIED_P (true_rtx
) = ATTR_IND_SIMPLIFIED_P (false_rtx
) = 1;
5157 ATTR_PERMANENT_P (true_rtx
) = ATTR_PERMANENT_P (false_rtx
) = 1;
5159 alternative_name
= DEF_ATTR_STRING ("alternative");
5160 length_str
= DEF_ATTR_STRING ("length");
5161 delay_type_str
= DEF_ATTR_STRING ("*delay_type");
5162 delay_1_0_str
= DEF_ATTR_STRING ("*delay_1_0");
5163 num_delay_slots_str
= DEF_ATTR_STRING ("*num_delay_slots");
5165 /* Read the machine description. */
5168 while (read_md_rtx (&info
))
5170 switch (GET_CODE (info
.def
))
5173 case DEFINE_PEEPHOLE
:
5174 case DEFINE_ASM_ATTRIBUTES
:
5179 case DEFINE_ENUM_ATTR
:
5187 case DEFINE_INSN_RESERVATION
:
5188 gen_insn_reserv (&info
);
5198 if (GET_CODE (info
.def
) != DEFINE_ASM_ATTRIBUTES
)
5199 insn_index_number
++;
5203 return FATAL_EXIT_CODE
;
5205 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
5206 if (! got_define_asm_attributes
)
5209 info
.def
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
5210 XVEC (info
.def
, 0) = rtvec_alloc (0);
5211 info
.loc
= file_location ("<internal>", 0, 0);
5216 /* Expand DEFINE_DELAY information into new attribute. */
5219 /* Make `insn_alternatives'. */
5220 int num_insn_codes
= get_num_insn_codes ();
5221 insn_alternatives
= oballocvec (uint64_t, num_insn_codes
);
5222 for (id
= defs
; id
; id
= id
->next
)
5223 if (id
->insn_code
>= 0)
5224 insn_alternatives
[id
->insn_code
]
5225 = (((uint64_t) 1) << id
->num_alternatives
) - 1;
5227 /* Make `insn_n_alternatives'. */
5228 insn_n_alternatives
= oballocvec (int, num_insn_codes
);
5229 for (id
= defs
; id
; id
= id
->next
)
5230 if (id
->insn_code
>= 0)
5231 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
5233 /* Construct extra attributes for automata. */
5234 make_automaton_attrs ();
5236 /* Prepare to write out attribute subroutines by checking everything stored
5237 away and building the attribute cases. */
5241 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5242 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5243 attr
->default_val
->value
5244 = check_attr_value (attr
->loc
, attr
->default_val
->value
, attr
);
5247 return FATAL_EXIT_CODE
;
5249 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5250 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5253 /* Construct extra attributes for `length'. */
5254 make_length_attrs ();
5256 /* Perform any possible optimizations to speed up compilation. */
5257 optimize_attrs (num_insn_codes
);
5259 /* Now write out all the `gen_attr_...' routines. Do these before the
5260 special routines so that they get defined before they are used. */
5262 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5263 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5267 #define IS_ATTR_GROUP(X) (!strncmp (attr->name, X, strlen (X)))
5268 if (IS_ATTR_GROUP ("*internal_dfa_insn_code"))
5270 else if (IS_ATTR_GROUP ("*insn_default_latency"))
5271 outf
= latency_file
;
5274 #undef IS_ATTR_GROUP
5276 if (! attr
->is_special
&& ! attr
->is_const
)
5277 write_attr_get (outf
, attr
);
5280 /* Write out delay eligibility information, if DEFINE_DELAY present.
5281 (The function to compute the number of delay slots will be written
5283 write_eligible_delay (attr_file
, "delay");
5284 if (have_annul_true
)
5285 write_eligible_delay (attr_file
, "annul_true");
5287 write_dummy_eligible_delay (attr_file
, "annul_true");
5288 if (have_annul_false
)
5289 write_eligible_delay (attr_file
, "annul_false");
5291 write_dummy_eligible_delay (attr_file
, "annul_false");
5293 /* Write out constant delay slot info. */
5294 write_const_num_delay_slots (attr_file
);
5296 write_length_unit_log (attr_file
);
5298 if (fclose (attr_file
) != 0)
5299 fatal ("cannot close file %s: %s", attr_file_name
, xstrerror (errno
));
5300 if (fclose (dfa_file
) != 0)
5301 fatal ("cannot close file %s: %s", dfa_file_name
, xstrerror (errno
));
5302 if (fclose (latency_file
) != 0)
5303 fatal ("cannot close file %s: %s", latency_file_name
, xstrerror (errno
));
5305 return SUCCESS_EXIT_CODE
;