1 /* Generate code from machine description to compute values of attributes.
2 Copyright (C) 1991-2014 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 const char *filename
; /* Filename. */
143 int lineno
; /* Line number. */
144 int num_alternatives
; /* Number of alternatives. */
145 int vec_idx
; /* Index of attribute vector in `def'. */
148 /* Once everything has been read in, we store in each attribute value a list
149 of insn codes that have that value. Here is the structure used for the
154 struct insn_ent
*next
; /* Next in chain. */
155 struct insn_def
*def
; /* Instruction definition. */
158 /* Each value of an attribute (either constant or computed) is assigned a
159 structure which is used as the listhead of the insns that have that
164 rtx value
; /* Value of attribute. */
165 struct attr_value
*next
; /* Next attribute value in chain. */
166 struct insn_ent
*first_insn
; /* First insn with this value. */
167 int num_insns
; /* Number of insns with this value. */
168 int has_asm_insn
; /* True if this value used for `asm' insns */
171 /* Structure for each attribute. */
175 char *name
; /* Name of attribute. */
176 const char *enum_name
; /* Enum name for DEFINE_ENUM_NAME. */
177 struct attr_desc
*next
; /* Next attribute. */
178 struct attr_value
*first_value
; /* First value of this attribute. */
179 struct attr_value
*default_val
; /* Default value for this attribute. */
180 int lineno
: 24; /* Line number. */
181 unsigned is_numeric
: 1; /* Values of this attribute are numeric. */
182 unsigned is_const
: 1; /* Attribute value constant for each run. */
183 unsigned is_special
: 1; /* Don't call `write_attr_set'. */
186 /* Structure for each DEFINE_DELAY. */
190 rtx def
; /* DEFINE_DELAY expression. */
191 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
192 int num
; /* Number of DEFINE_DELAY, starting at 1. */
193 int lineno
; /* Line number. */
196 struct attr_value_list
198 struct attr_value
*av
;
200 struct attr_desc
*attr
;
201 struct attr_value_list
*next
;
204 /* Listheads of above structures. */
206 /* This one is indexed by the first character of the attribute name. */
207 #define MAX_ATTRS_INDEX 256
208 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
209 static struct insn_def
*defs
;
210 static struct delay_desc
*delays
;
211 struct attr_value_list
**insn_code_values
;
213 /* Other variables. */
215 static int insn_code_number
;
216 static int insn_index_number
;
217 static int got_define_asm_attributes
;
218 static int must_extract
;
219 static int must_constrain
;
220 static int address_used
;
221 static int length_used
;
222 static int num_delays
;
223 static int have_annul_true
, have_annul_false
;
224 static int num_insn_ents
;
226 /* Stores, for each insn code, the number of constraint alternatives. */
228 static int *insn_n_alternatives
;
230 /* Stores, for each insn code, a bitmap that has bits on for each possible
233 static int *insn_alternatives
;
235 /* Used to simplify expressions. */
237 static rtx true_rtx
, false_rtx
;
239 /* Used to reduce calls to `strcmp' */
241 static const char *alternative_name
;
242 static const char *length_str
;
243 static const char *delay_type_str
;
244 static const char *delay_1_0_str
;
245 static const char *num_delay_slots_str
;
247 /* Simplify an expression. Only call the routine if there is something to
249 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
250 (ATTR_IND_SIMPLIFIED_P (EXP) || ATTR_CURR_SIMPLIFIED_P (EXP) ? (EXP) \
251 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
253 #define DEF_ATTR_STRING(S) (attr_string ((S), strlen (S)))
255 /* Forward declarations of functions used before their definitions, only. */
256 static char *attr_string (const char *, int);
257 static char *attr_printf (unsigned int, const char *, ...)
259 static rtx
make_numeric_value (int);
260 static struct attr_desc
*find_attr (const char **, int);
261 static rtx
mk_attr_alt (int);
262 static char *next_comma_elt (const char **);
263 static rtx
insert_right_side (enum rtx_code
, rtx
, rtx
, int, int);
264 static rtx
copy_boolean (rtx
);
265 static int compares_alternatives_p (rtx
);
266 static void make_internal_attr (const char *, rtx
, int);
267 static void insert_insn_ent (struct attr_value
*, struct insn_ent
*);
268 static void walk_attr_value (rtx
);
269 static int max_attr_value (rtx
, int*);
270 static int min_attr_value (rtx
, int*);
271 static int or_attr_value (rtx
, int*);
272 static rtx
simplify_test_exp (rtx
, int, int);
273 static rtx
simplify_test_exp_in_temp (rtx
, int, int);
274 static rtx
copy_rtx_unchanging (rtx
);
275 static bool attr_alt_subset_p (rtx
, rtx
);
276 static bool attr_alt_subset_of_compl_p (rtx
, rtx
);
277 static void clear_struct_flag (rtx
);
278 static void write_attr_valueq (FILE *, struct attr_desc
*, const char *);
279 static struct attr_value
*find_most_used (struct attr_desc
*);
280 static void write_attr_set (FILE *, struct attr_desc
*, int, rtx
,
281 const char *, const char *, rtx
,
282 int, int, unsigned int);
283 static void write_attr_case (FILE *, struct attr_desc
*,
285 int, const char *, const char *, int, rtx
);
286 static void write_attr_value (FILE *, struct attr_desc
*, rtx
);
287 static void write_upcase (FILE *, const char *);
288 static void write_indent (FILE *, int);
289 static rtx
identity_fn (rtx
);
290 static rtx
zero_fn (rtx
);
291 static rtx
one_fn (rtx
);
292 static rtx
max_fn (rtx
);
293 static rtx
min_fn (rtx
);
295 #define oballoc(T) XOBNEW (hash_obstack, T)
296 #define oballocvec(T, N) XOBNEWVEC (hash_obstack, T, (N))
298 /* This gen* file is unique, in that it writes out multiple files.
300 Before GCC 4.8, insn-attrtab.c was written out containing many large
301 functions and tables. This made insn-attrtab.c _the_ bottle-neck in
302 a parallel build, and even made it impossible to build GCC on machines
303 with relatively small RAM space (PR other/29442). Therefore, the
304 atrribute functions/tables are now written out to three separate
305 files: all "*insn_default_latency" functions go to LATENCY_FILE_NAME,
306 all "*internal_dfa_insn_code" functions go to DFA_FILE_NAME, and the
307 rest goes to ATTR_FILE_NAME. */
309 static const char *attr_file_name
= NULL
;
310 static const char *dfa_file_name
= NULL
;
311 static const char *latency_file_name
= NULL
;
313 static FILE *attr_file
, *dfa_file
, *latency_file
;
315 /* Hash table for sharing RTL and strings. */
317 /* Each hash table slot is a bucket containing a chain of these structures.
318 Strings are given negative hash codes; RTL expressions are given positive
323 struct attr_hash
*next
; /* Next structure in the bucket. */
324 unsigned int hashcode
; /* Hash code of this rtx or string. */
327 char *str
; /* The string (negative hash codes) */
328 rtx rtl
; /* or the RTL recorded here. */
332 /* Now here is the hash table. When recording an RTL, it is added to
333 the slot whose index is the hash code mod the table size. Note
334 that the hash table is used for several kinds of RTL (see attr_rtx)
335 and for strings. While all these live in the same table, they are
336 completely independent, and the hash code is computed differently
339 #define RTL_HASH_SIZE 4093
340 static struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
342 /* Here is how primitive or already-shared RTL's hash
344 #define RTL_HASH(RTL) ((intptr_t) (RTL) & 0777777)
346 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
349 attr_hash_add_rtx (unsigned int hashcode
, rtx rtl
)
353 h
= XOBNEW (hash_obstack
, struct attr_hash
);
354 h
->hashcode
= hashcode
;
356 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
357 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
360 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
363 attr_hash_add_string (unsigned int hashcode
, char *str
)
367 h
= XOBNEW (hash_obstack
, struct attr_hash
);
368 h
->hashcode
= -hashcode
;
370 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
371 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
374 /* Generate an RTL expression, but avoid duplicates.
375 Set the ATTR_PERMANENT_P flag for these permanent objects.
377 In some cases we cannot uniquify; then we return an ordinary
378 impermanent rtx with ATTR_PERMANENT_P clear.
382 rtx attr_rtx (code, [element1, ..., elementn]) */
385 attr_rtx_1 (enum rtx_code code
, va_list p
)
387 rtx rt_val
= NULL_RTX
;/* RTX to return to caller... */
388 unsigned int hashcode
;
390 struct obstack
*old_obstack
= rtl_obstack
;
392 /* For each of several cases, search the hash table for an existing entry.
393 Use that entry if one is found; otherwise create a new RTL and add it
396 if (GET_RTX_CLASS (code
) == RTX_UNARY
)
398 rtx arg0
= va_arg (p
, rtx
);
400 /* A permanent object cannot point to impermanent ones. */
401 if (! ATTR_PERMANENT_P (arg0
))
403 rt_val
= rtx_alloc (code
);
404 XEXP (rt_val
, 0) = arg0
;
408 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
409 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
410 if (h
->hashcode
== hashcode
411 && GET_CODE (h
->u
.rtl
) == code
412 && XEXP (h
->u
.rtl
, 0) == arg0
)
417 rtl_obstack
= hash_obstack
;
418 rt_val
= rtx_alloc (code
);
419 XEXP (rt_val
, 0) = arg0
;
422 else if (GET_RTX_CLASS (code
) == RTX_BIN_ARITH
423 || GET_RTX_CLASS (code
) == RTX_COMM_ARITH
424 || GET_RTX_CLASS (code
) == RTX_COMPARE
425 || GET_RTX_CLASS (code
) == RTX_COMM_COMPARE
)
427 rtx arg0
= va_arg (p
, rtx
);
428 rtx arg1
= va_arg (p
, rtx
);
430 /* A permanent object cannot point to impermanent ones. */
431 if (! ATTR_PERMANENT_P (arg0
) || ! ATTR_PERMANENT_P (arg1
))
433 rt_val
= rtx_alloc (code
);
434 XEXP (rt_val
, 0) = arg0
;
435 XEXP (rt_val
, 1) = arg1
;
439 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
440 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
441 if (h
->hashcode
== hashcode
442 && GET_CODE (h
->u
.rtl
) == code
443 && XEXP (h
->u
.rtl
, 0) == arg0
444 && XEXP (h
->u
.rtl
, 1) == arg1
)
449 rtl_obstack
= hash_obstack
;
450 rt_val
= rtx_alloc (code
);
451 XEXP (rt_val
, 0) = arg0
;
452 XEXP (rt_val
, 1) = arg1
;
455 else if (code
== SYMBOL_REF
456 || (GET_RTX_LENGTH (code
) == 1
457 && GET_RTX_FORMAT (code
)[0] == 's'))
459 char *arg0
= va_arg (p
, char *);
461 arg0
= DEF_ATTR_STRING (arg0
);
463 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
464 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
465 if (h
->hashcode
== hashcode
466 && GET_CODE (h
->u
.rtl
) == code
467 && XSTR (h
->u
.rtl
, 0) == arg0
)
472 rtl_obstack
= hash_obstack
;
473 rt_val
= rtx_alloc (code
);
474 XSTR (rt_val
, 0) = arg0
;
475 if (code
== SYMBOL_REF
)
476 X0EXP (rt_val
, 1) = NULL_RTX
;
479 else if (GET_RTX_LENGTH (code
) == 2
480 && GET_RTX_FORMAT (code
)[0] == 's'
481 && GET_RTX_FORMAT (code
)[1] == 's')
483 char *arg0
= va_arg (p
, char *);
484 char *arg1
= va_arg (p
, char *);
486 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
487 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
488 if (h
->hashcode
== hashcode
489 && GET_CODE (h
->u
.rtl
) == code
490 && XSTR (h
->u
.rtl
, 0) == arg0
491 && XSTR (h
->u
.rtl
, 1) == arg1
)
496 rtl_obstack
= hash_obstack
;
497 rt_val
= rtx_alloc (code
);
498 XSTR (rt_val
, 0) = arg0
;
499 XSTR (rt_val
, 1) = arg1
;
502 else if (code
== CONST_INT
)
504 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
514 int i
; /* Array indices... */
515 const char *fmt
; /* Current rtx's format... */
517 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
519 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
520 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
524 case '0': /* Unused field. */
527 case 'i': /* An integer? */
528 XINT (rt_val
, i
) = va_arg (p
, int);
531 case 'w': /* A wide integer? */
532 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
535 case 's': /* A string? */
536 XSTR (rt_val
, i
) = va_arg (p
, char *);
539 case 'e': /* An expression? */
540 case 'u': /* An insn? Same except when printing. */
541 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
544 case 'E': /* An RTX vector? */
545 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
555 rtl_obstack
= old_obstack
;
556 attr_hash_add_rtx (hashcode
, rt_val
);
557 ATTR_PERMANENT_P (rt_val
) = 1;
562 attr_rtx (enum rtx_code code
, ...)
568 result
= attr_rtx_1 (code
, p
);
573 /* Create a new string printed with the printf line arguments into a space
574 of at most LEN bytes:
576 rtx attr_printf (len, format, [arg1, ..., argn]) */
579 attr_printf (unsigned int len
, const char *fmt
, ...)
586 gcc_assert (len
< sizeof str
); /* Leave room for \0. */
588 vsprintf (str
, fmt
, p
);
591 return DEF_ATTR_STRING (str
);
595 attr_eq (const char *name
, const char *value
)
597 return attr_rtx (EQ_ATTR
, DEF_ATTR_STRING (name
), DEF_ATTR_STRING (value
));
603 return XSTR (make_numeric_value (n
), 0);
606 /* Return a permanent (possibly shared) copy of a string STR (not assumed
607 to be null terminated) with LEN bytes. */
610 attr_string (const char *str
, int len
)
613 unsigned int hashcode
;
617 /* Compute the hash code. */
618 hashcode
= (len
+ 1) * 613U + (unsigned) str
[0];
619 for (i
= 1; i
< len
; i
+= 2)
620 hashcode
= ((hashcode
* 613) + (unsigned) str
[i
]);
621 if ((int) hashcode
< 0)
622 hashcode
= -hashcode
;
624 /* Search the table for the string. */
625 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
626 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
627 && !strncmp (h
->u
.str
, str
, len
))
628 return h
->u
.str
; /* <-- return if found. */
630 /* Not found; create a permanent copy and add it to the hash table. */
631 new_str
= XOBNEWVAR (hash_obstack
, char, len
+ 1);
632 memcpy (new_str
, str
, len
);
634 attr_hash_add_string (hashcode
, new_str
);
635 copy_md_ptr_loc (new_str
, str
);
637 return new_str
; /* Return the new string. */
640 /* Check two rtx's for equality of contents,
641 taking advantage of the fact that if both are hashed
642 then they can't be equal unless they are the same object. */
645 attr_equal_p (rtx x
, rtx y
)
647 return (x
== y
|| (! (ATTR_PERMANENT_P (x
) && ATTR_PERMANENT_P (y
))
648 && rtx_equal_p (x
, y
)));
651 /* Copy an attribute value expression,
652 descending to all depths, but not copying any
653 permanent hashed subexpressions. */
656 attr_copy_rtx (rtx orig
)
661 const char *format_ptr
;
663 /* No need to copy a permanent object. */
664 if (ATTR_PERMANENT_P (orig
))
667 code
= GET_CODE (orig
);
684 copy
= rtx_alloc (code
);
685 PUT_MODE (copy
, GET_MODE (orig
));
686 ATTR_IND_SIMPLIFIED_P (copy
) = ATTR_IND_SIMPLIFIED_P (orig
);
687 ATTR_CURR_SIMPLIFIED_P (copy
) = ATTR_CURR_SIMPLIFIED_P (orig
);
688 ATTR_PERMANENT_P (copy
) = ATTR_PERMANENT_P (orig
);
690 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
692 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
694 switch (*format_ptr
++)
697 XEXP (copy
, i
) = XEXP (orig
, i
);
698 if (XEXP (orig
, i
) != NULL
)
699 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
704 XVEC (copy
, i
) = XVEC (orig
, i
);
705 if (XVEC (orig
, i
) != NULL
)
707 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
708 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
709 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
715 XINT (copy
, i
) = XINT (orig
, i
);
719 XWINT (copy
, i
) = XWINT (orig
, i
);
724 XSTR (copy
, i
) = XSTR (orig
, i
);
734 /* Given a test expression for an attribute, ensure it is validly formed.
735 IS_CONST indicates whether the expression is constant for each compiler
736 run (a constant expression may not test any particular insn).
738 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
739 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
740 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
742 Update the string address in EQ_ATTR expression to be the same used
743 in the attribute (or `alternative_name') to speed up subsequent
744 `find_attr' calls and eliminate most `strcmp' calls.
746 Return the new expression, if any. */
749 check_attr_test (rtx exp
, int is_const
, int lineno
)
751 struct attr_desc
*attr
;
752 struct attr_value
*av
;
753 const char *name_ptr
, *p
;
756 switch (GET_CODE (exp
))
759 /* Handle negation test. */
760 if (XSTR (exp
, 1)[0] == '!')
761 return check_attr_test (attr_rtx (NOT
,
762 attr_eq (XSTR (exp
, 0),
766 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
768 attr
= find_attr (&XSTR (exp
, 0), 0);
771 if (! strcmp (XSTR (exp
, 0), "alternative"))
772 return mk_attr_alt (1 << atoi (XSTR (exp
, 1)));
774 fatal ("unknown attribute `%s' in EQ_ATTR", XSTR (exp
, 0));
777 if (is_const
&& ! attr
->is_const
)
778 fatal ("constant expression uses insn attribute `%s' in EQ_ATTR",
781 /* Copy this just to make it permanent,
782 so expressions using it can be permanent too. */
783 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
785 /* It shouldn't be possible to simplify the value given to a
786 constant attribute, so don't expand this until it's time to
787 write the test expression. */
789 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
791 if (attr
->is_numeric
)
793 for (p
= XSTR (exp
, 1); *p
; p
++)
795 fatal ("attribute `%s' takes only numeric values",
800 for (av
= attr
->first_value
; av
; av
= av
->next
)
801 if (GET_CODE (av
->value
) == CONST_STRING
802 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
806 fatal ("unknown value `%s' for `%s' attribute",
807 XSTR (exp
, 1), XSTR (exp
, 0));
812 if (! strcmp (XSTR (exp
, 0), "alternative"))
816 name_ptr
= XSTR (exp
, 1);
817 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
818 set
|= 1 << atoi (p
);
820 return mk_attr_alt (set
);
824 /* Make an IOR tree of the possible values. */
826 name_ptr
= XSTR (exp
, 1);
827 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
829 newexp
= attr_eq (XSTR (exp
, 0), p
);
830 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
833 return check_attr_test (orexp
, is_const
, lineno
);
842 /* Either TRUE or FALSE. */
850 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
851 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
, lineno
);
855 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
859 exp
= attr_rtx (MATCH_TEST
, XSTR (exp
, 0));
860 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
865 fatal ("RTL operator \"%s\" not valid in constant attribute test",
866 GET_RTX_NAME (GET_CODE (exp
)));
867 /* These cases can't be simplified. */
868 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
871 case LE
: case LT
: case GT
: case GE
:
872 case LEU
: case LTU
: case GTU
: case GEU
:
874 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
875 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
876 exp
= attr_rtx (GET_CODE (exp
),
877 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
878 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
879 /* These cases can't be simplified. */
880 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
886 /* These cases are valid for constant attributes, but can't be
888 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
889 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
893 fatal ("RTL operator \"%s\" not valid in attribute test",
894 GET_RTX_NAME (GET_CODE (exp
)));
900 /* Given an expression, ensure that it is validly formed and that all named
901 attribute values are valid for the given attribute. Issue a fatal error
902 if not. If no attribute is specified, assume a numeric attribute.
904 Return a perhaps modified replacement expression for the value. */
907 check_attr_value (rtx exp
, struct attr_desc
*attr
)
909 struct attr_value
*av
;
913 switch (GET_CODE (exp
))
916 if (attr
&& ! attr
->is_numeric
)
918 error_with_line (attr
->lineno
,
919 "CONST_INT not valid for non-numeric attribute %s",
924 if (INTVAL (exp
) < 0)
926 error_with_line (attr
->lineno
,
927 "negative numeric value specified for attribute %s",
934 if (! strcmp (XSTR (exp
, 0), "*"))
937 if (attr
== 0 || attr
->is_numeric
)
943 error_with_line (attr
? attr
->lineno
: 0,
944 "non-numeric value for numeric attribute %s",
945 attr
? attr
->name
: "internal");
951 for (av
= attr
->first_value
; av
; av
= av
->next
)
952 if (GET_CODE (av
->value
) == CONST_STRING
953 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
957 error_with_line (attr
->lineno
,
958 "unknown value `%s' for `%s' attribute",
959 XSTR (exp
, 0), attr
? attr
->name
: "internal");
963 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
964 attr
? attr
->is_const
: 0,
965 attr
? attr
->lineno
: 0);
966 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
967 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
975 if (attr
&& !attr
->is_numeric
)
977 error_with_line (attr
->lineno
,
978 "invalid operation `%s' for non-numeric"
979 " attribute value", GET_RTX_NAME (GET_CODE (exp
)));
986 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
987 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
996 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1000 if (XVECLEN (exp
, 0) % 2 != 0)
1002 error_with_line (attr
->lineno
,
1003 "first operand of COND must have even length");
1007 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1009 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1010 attr
? attr
->is_const
: 0,
1011 attr
? attr
->lineno
: 0);
1012 XVECEXP (exp
, 0, i
+ 1)
1013 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1016 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1021 struct attr_desc
*attr2
= find_attr (&XSTR (exp
, 0), 0);
1023 error_with_line (attr
? attr
->lineno
: 0,
1024 "unknown attribute `%s' in ATTR",
1026 else if (attr
&& attr
->is_const
&& ! attr2
->is_const
)
1027 error_with_line (attr
->lineno
,
1028 "non-constant attribute `%s' referenced from `%s'",
1029 XSTR (exp
, 0), attr
->name
);
1031 && attr
->is_numeric
!= attr2
->is_numeric
)
1032 error_with_line (attr
->lineno
,
1033 "numeric attribute mismatch calling `%s' from `%s'",
1034 XSTR (exp
, 0), attr
->name
);
1039 /* A constant SYMBOL_REF is valid as a constant attribute test and
1040 is expanded later by make_canonical into a COND. In a non-constant
1041 attribute test, it is left be. */
1042 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1045 error_with_line (attr
? attr
->lineno
: 0,
1046 "invalid operation `%s' for attribute value",
1047 GET_RTX_NAME (GET_CODE (exp
)));
1054 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1055 It becomes a COND with each test being (eq_attr "alternative" "n") */
1058 convert_set_attr_alternative (rtx exp
, struct insn_def
*id
)
1060 int num_alt
= id
->num_alternatives
;
1064 if (XVECLEN (exp
, 1) != num_alt
)
1066 error_with_line (id
->lineno
,
1067 "bad number of entries in SET_ATTR_ALTERNATIVE, was %d expected %d",
1068 XVECLEN (exp
, 1), num_alt
);
1072 /* Make a COND with all tests but the last. Select the last value via the
1074 condexp
= rtx_alloc (COND
);
1075 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1077 for (i
= 0; i
< num_alt
- 1; i
++)
1080 p
= attr_numeral (i
);
1082 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1083 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1086 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1088 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1091 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1092 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1095 convert_set_attr (rtx exp
, struct insn_def
*id
)
1098 const char *name_ptr
;
1102 /* See how many alternative specified. */
1103 n
= n_comma_elts (XSTR (exp
, 1));
1105 return attr_rtx (SET
,
1106 attr_rtx (ATTR
, XSTR (exp
, 0)),
1107 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1109 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1110 XSTR (newexp
, 0) = XSTR (exp
, 0);
1111 XVEC (newexp
, 1) = rtvec_alloc (n
);
1113 /* Process each comma-separated name. */
1114 name_ptr
= XSTR (exp
, 1);
1116 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1117 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1119 return convert_set_attr_alternative (newexp
, id
);
1122 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1123 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1129 struct insn_def
*id
;
1130 struct attr_desc
*attr
;
1134 for (id
= defs
; id
; id
= id
->next
)
1136 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1139 read_md_filename
= id
->filename
;
1140 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1142 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1143 switch (GET_CODE (value
))
1146 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1148 error_with_line (id
->lineno
, "bad attribute set");
1153 case SET_ATTR_ALTERNATIVE
:
1154 value
= convert_set_attr_alternative (value
, id
);
1158 value
= convert_set_attr (value
, id
);
1162 error_with_line (id
->lineno
, "invalid attribute code %s",
1163 GET_RTX_NAME (GET_CODE (value
)));
1166 if (value
== NULL_RTX
)
1169 if ((attr
= find_attr (&XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1171 error_with_line (id
->lineno
, "unknown attribute %s",
1172 XSTR (XEXP (value
, 0), 0));
1176 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1177 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1182 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1183 expressions by converting them into a COND. This removes cases from this
1184 program. Also, replace an attribute value of "*" with the default attribute
1188 make_canonical (struct attr_desc
*attr
, rtx exp
)
1193 switch (GET_CODE (exp
))
1196 exp
= make_numeric_value (INTVAL (exp
));
1200 if (! strcmp (XSTR (exp
, 0), "*"))
1202 if (attr
== 0 || attr
->default_val
== 0)
1203 fatal ("(attr_value \"*\") used in invalid context");
1204 exp
= attr
->default_val
->value
;
1207 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1212 if (!attr
->is_const
|| ATTR_IND_SIMPLIFIED_P (exp
))
1214 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1215 This makes the COND something that won't be considered an arbitrary
1216 expression by walk_attr_value. */
1217 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1218 exp
= check_attr_value (exp
, attr
);
1222 newexp
= rtx_alloc (COND
);
1223 XVEC (newexp
, 0) = rtvec_alloc (2);
1224 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1225 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1227 XEXP (newexp
, 1) = XEXP (exp
, 2);
1230 /* Fall through to COND case since this is now a COND. */
1237 /* First, check for degenerate COND. */
1238 if (XVECLEN (exp
, 0) == 0)
1239 return make_canonical (attr
, XEXP (exp
, 1));
1240 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1242 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1244 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1245 XVECEXP (exp
, 0, i
+ 1)
1246 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1247 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1263 copy_boolean (rtx exp
)
1265 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1266 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1267 copy_boolean (XEXP (exp
, 1)));
1268 if (GET_CODE (exp
) == MATCH_OPERAND
)
1270 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1271 XSTR (exp
, 2) = DEF_ATTR_STRING (XSTR (exp
, 2));
1273 else if (GET_CODE (exp
) == EQ_ATTR
)
1275 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1276 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1282 /* Given a value and an attribute description, return a `struct attr_value *'
1283 that represents that value. This is either an existing structure, if the
1284 value has been previously encountered, or a newly-created structure.
1286 `insn_code' is the code of an insn whose attribute has the specified
1287 value (-2 if not processing an insn). We ensure that all insns for
1288 a given value have the same number of alternatives if the value checks
1291 static struct attr_value
*
1292 get_attr_value (rtx value
, struct attr_desc
*attr
, int insn_code
)
1294 struct attr_value
*av
;
1297 value
= make_canonical (attr
, value
);
1298 if (compares_alternatives_p (value
))
1300 if (insn_code
< 0 || insn_alternatives
== NULL
)
1301 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1303 num_alt
= insn_alternatives
[insn_code
];
1306 for (av
= attr
->first_value
; av
; av
= av
->next
)
1307 if (rtx_equal_p (value
, av
->value
)
1308 && (num_alt
== 0 || av
->first_insn
== NULL
1309 || insn_alternatives
[av
->first_insn
->def
->insn_code
]))
1312 av
= oballoc (struct attr_value
);
1314 av
->next
= attr
->first_value
;
1315 attr
->first_value
= av
;
1316 av
->first_insn
= NULL
;
1318 av
->has_asm_insn
= 0;
1323 /* After all DEFINE_DELAYs have been read in, create internal attributes
1324 to generate the required routines.
1326 First, we compute the number of delay slots for each insn (as a COND of
1327 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1328 delay type is specified, we compute a similar function giving the
1329 DEFINE_DELAY ordinal for each insn.
1331 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1332 tells whether a given insn can be in that delay slot.
1334 Normal attribute filling and optimization expands these to contain the
1335 information needed to handle delay slots. */
1338 expand_delays (void)
1340 struct delay_desc
*delay
;
1346 /* First, generate data for `num_delay_slots' function. */
1348 condexp
= rtx_alloc (COND
);
1349 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1350 XEXP (condexp
, 1) = make_numeric_value (0);
1352 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1354 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1355 XVECEXP (condexp
, 0, i
+ 1)
1356 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1359 make_internal_attr (num_delay_slots_str
, condexp
, ATTR_NONE
);
1361 /* If more than one delay type, do the same for computing the delay type. */
1364 condexp
= rtx_alloc (COND
);
1365 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1366 XEXP (condexp
, 1) = make_numeric_value (0);
1368 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1370 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1371 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1374 make_internal_attr (delay_type_str
, condexp
, ATTR_SPECIAL
);
1377 /* For each delay possibility and delay slot, compute an eligibility
1378 attribute for non-annulled insns and for each type of annulled (annul
1379 if true and annul if false). */
1380 for (delay
= delays
; delay
; delay
= delay
->next
)
1382 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1384 condexp
= XVECEXP (delay
->def
, 1, i
);
1386 condexp
= false_rtx
;
1387 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1388 make_numeric_value (1), make_numeric_value (0));
1390 p
= attr_printf (sizeof "*delay__" + MAX_DIGITS
* 2,
1391 "*delay_%d_%d", delay
->num
, i
/ 3);
1392 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1394 if (have_annul_true
)
1396 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1397 if (condexp
== 0) condexp
= false_rtx
;
1398 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1399 make_numeric_value (1),
1400 make_numeric_value (0));
1401 p
= attr_printf (sizeof "*annul_true__" + MAX_DIGITS
* 2,
1402 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1403 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1406 if (have_annul_false
)
1408 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1409 if (condexp
== 0) condexp
= false_rtx
;
1410 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1411 make_numeric_value (1),
1412 make_numeric_value (0));
1413 p
= attr_printf (sizeof "*annul_false__" + MAX_DIGITS
* 2,
1414 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1415 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1421 /* Once all attributes and insns have been read and checked, we construct for
1422 each attribute value a list of all the insns that have that value for
1426 fill_attr (struct attr_desc
*attr
)
1428 struct attr_value
*av
;
1429 struct insn_ent
*ie
;
1430 struct insn_def
*id
;
1434 /* Don't fill constant attributes. The value is independent of
1435 any particular insn. */
1439 for (id
= defs
; id
; id
= id
->next
)
1441 /* If no value is specified for this insn for this attribute, use the
1444 if (XVEC (id
->def
, id
->vec_idx
))
1445 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1446 if (! strcmp_check (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
1448 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
1451 av
= attr
->default_val
;
1453 av
= get_attr_value (value
, attr
, id
->insn_code
);
1455 ie
= oballoc (struct insn_ent
);
1457 insert_insn_ent (av
, ie
);
1461 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
1462 test that checks relative positions of insns (uses MATCH_DUP or PC).
1463 If so, replace it with what is obtained by passing the expression to
1464 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
1465 recursively on each value (including the default value). Otherwise,
1466 return the value returned by NO_ADDRESS_FN applied to EXP. */
1469 substitute_address (rtx exp
, rtx (*no_address_fn
) (rtx
),
1470 rtx (*address_fn
) (rtx
))
1475 if (GET_CODE (exp
) == COND
)
1477 /* See if any tests use addresses. */
1479 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1480 walk_attr_value (XVECEXP (exp
, 0, i
));
1483 return (*address_fn
) (exp
);
1485 /* Make a new copy of this COND, replacing each element. */
1486 newexp
= rtx_alloc (COND
);
1487 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
1488 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1490 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
1491 XVECEXP (newexp
, 0, i
+ 1)
1492 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
1493 no_address_fn
, address_fn
);
1496 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
1497 no_address_fn
, address_fn
);
1502 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
1505 walk_attr_value (XEXP (exp
, 0));
1507 return (*address_fn
) (exp
);
1509 return attr_rtx (IF_THEN_ELSE
,
1510 substitute_address (XEXP (exp
, 0),
1511 no_address_fn
, address_fn
),
1512 substitute_address (XEXP (exp
, 1),
1513 no_address_fn
, address_fn
),
1514 substitute_address (XEXP (exp
, 2),
1515 no_address_fn
, address_fn
));
1518 return (*no_address_fn
) (exp
);
1521 /* Make new attributes from the `length' attribute. The following are made,
1522 each corresponding to a function called from `shorten_branches' or
1525 *insn_default_length This is the length of the insn to be returned
1526 by `get_attr_length' before `shorten_branches'
1527 has been called. In each case where the length
1528 depends on relative addresses, the largest
1529 possible is used. This routine is also used
1530 to compute the initial size of the insn.
1532 *insn_variable_length_p This returns 1 if the insn's length depends
1533 on relative addresses, zero otherwise.
1535 *insn_current_length This is only called when it is known that the
1536 insn has a variable length and returns the
1537 current length, based on relative addresses.
1541 make_length_attrs (void)
1543 static const char *new_names
[] =
1545 "*insn_default_length",
1547 "*insn_variable_length_p",
1548 "*insn_current_length"
1550 static rtx (*const no_address_fn
[]) (rtx
)
1551 = {identity_fn
,identity_fn
, zero_fn
, zero_fn
};
1552 static rtx (*const address_fn
[]) (rtx
)
1553 = {max_fn
, min_fn
, one_fn
, identity_fn
};
1555 struct attr_desc
*length_attr
, *new_attr
;
1556 struct attr_value
*av
, *new_av
;
1557 struct insn_ent
*ie
, *new_ie
;
1559 /* See if length attribute is defined. If so, it must be numeric. Make
1560 it special so we don't output anything for it. */
1561 length_attr
= find_attr (&length_str
, 0);
1562 if (length_attr
== 0)
1565 if (! length_attr
->is_numeric
)
1566 fatal ("length attribute must be numeric");
1568 length_attr
->is_const
= 0;
1569 length_attr
->is_special
= 1;
1571 /* Make each new attribute, in turn. */
1572 for (i
= 0; i
< ARRAY_SIZE (new_names
); i
++)
1574 make_internal_attr (new_names
[i
],
1575 substitute_address (length_attr
->default_val
->value
,
1576 no_address_fn
[i
], address_fn
[i
]),
1578 new_attr
= find_attr (&new_names
[i
], 0);
1579 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
1580 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1582 new_av
= get_attr_value (substitute_address (av
->value
,
1585 new_attr
, ie
->def
->insn_code
);
1586 new_ie
= oballoc (struct insn_ent
);
1587 new_ie
->def
= ie
->def
;
1588 insert_insn_ent (new_av
, new_ie
);
1593 /* Utility functions called from above routine. */
1596 identity_fn (rtx exp
)
1602 zero_fn (rtx exp ATTRIBUTE_UNUSED
)
1604 return make_numeric_value (0);
1608 one_fn (rtx exp ATTRIBUTE_UNUSED
)
1610 return make_numeric_value (1);
1617 return make_numeric_value (max_attr_value (exp
, &unknown
));
1624 return make_numeric_value (min_attr_value (exp
, &unknown
));
1628 write_length_unit_log (FILE *outf
)
1630 struct attr_desc
*length_attr
= find_attr (&length_str
, 0);
1631 struct attr_value
*av
;
1632 struct insn_ent
*ie
;
1633 unsigned int length_unit_log
, length_or
;
1638 length_or
= or_attr_value (length_attr
->default_val
->value
, &unknown
);
1639 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
1640 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1641 length_or
|= or_attr_value (av
->value
, &unknown
);
1644 if (length_attr
== NULL
|| unknown
)
1645 length_unit_log
= 0;
1648 length_or
= ~length_or
;
1649 for (length_unit_log
= 0; length_or
& 1; length_or
>>= 1)
1652 fprintf (outf
, "EXPORTED_CONST int length_unit_log = %u;\n", length_unit_log
);
1655 /* Compute approximate cost of the expression. Used to decide whether
1656 expression is cheap enough for inline. */
1658 attr_rtx_cost (rtx x
)
1664 code
= GET_CODE (x
);
1677 /* Alternatives don't result into function call. */
1678 if (!strcmp_check (XSTR (x
, 0), alternative_name
))
1685 const char *fmt
= GET_RTX_FORMAT (code
);
1686 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1692 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1693 cost
+= attr_rtx_cost (XVECEXP (x
, i
, j
));
1696 cost
+= attr_rtx_cost (XEXP (x
, i
));
1706 /* Take a COND expression and see if any of the conditions in it can be
1707 simplified. If any are known true or known false for the particular insn
1708 code, the COND can be further simplified.
1710 Also call ourselves on any COND operations that are values of this COND.
1712 We do not modify EXP; rather, we make and return a new rtx. */
1715 simplify_cond (rtx exp
, int insn_code
, int insn_index
)
1718 /* We store the desired contents here,
1719 then build a new expression if they don't match EXP. */
1720 rtx defval
= XEXP (exp
, 1);
1721 rtx new_defval
= XEXP (exp
, 1);
1722 int len
= XVECLEN (exp
, 0);
1723 rtx
*tests
= XNEWVEC (rtx
, len
);
1727 /* This lets us free all storage allocated below, if appropriate. */
1728 obstack_finish (rtl_obstack
);
1730 memcpy (tests
, XVEC (exp
, 0)->elem
, len
* sizeof (rtx
));
1732 /* See if default value needs simplification. */
1733 if (GET_CODE (defval
) == COND
)
1734 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
1736 /* Simplify the subexpressions, and see what tests we can get rid of. */
1738 for (i
= 0; i
< len
; i
+= 2)
1740 rtx newtest
, newval
;
1742 /* Simplify this test. */
1743 newtest
= simplify_test_exp_in_temp (tests
[i
], insn_code
, insn_index
);
1746 newval
= tests
[i
+ 1];
1747 /* See if this value may need simplification. */
1748 if (GET_CODE (newval
) == COND
)
1749 newval
= simplify_cond (newval
, insn_code
, insn_index
);
1751 /* Look for ways to delete or combine this test. */
1752 if (newtest
== true_rtx
)
1754 /* If test is true, make this value the default
1755 and discard this + any following tests. */
1757 defval
= tests
[i
+ 1];
1758 new_defval
= newval
;
1761 else if (newtest
== false_rtx
)
1763 /* If test is false, discard it and its value. */
1764 for (j
= i
; j
< len
- 2; j
++)
1765 tests
[j
] = tests
[j
+ 2];
1770 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
1772 /* If this value and the value for the prev test are the same,
1776 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
1777 insn_code
, insn_index
);
1779 /* Delete this test/value. */
1780 for (j
= i
; j
< len
- 2; j
++)
1781 tests
[j
] = tests
[j
+ 2];
1787 tests
[i
+ 1] = newval
;
1790 /* If the last test in a COND has the same value
1791 as the default value, that test isn't needed. */
1793 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
1796 /* See if we changed anything. */
1797 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
1800 for (i
= 0; i
< len
; i
++)
1801 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
1809 if (GET_CODE (defval
) == COND
)
1810 ret
= simplify_cond (defval
, insn_code
, insn_index
);
1818 rtx newexp
= rtx_alloc (COND
);
1820 XVEC (newexp
, 0) = rtvec_alloc (len
);
1821 memcpy (XVEC (newexp
, 0)->elem
, tests
, len
* sizeof (rtx
));
1822 XEXP (newexp
, 1) = new_defval
;
1829 /* Remove an insn entry from an attribute value. */
1832 remove_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
1834 struct insn_ent
*previe
;
1836 if (av
->first_insn
== ie
)
1837 av
->first_insn
= ie
->next
;
1840 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
1842 previe
->next
= ie
->next
;
1846 if (ie
->def
->insn_code
== -1)
1847 av
->has_asm_insn
= 0;
1852 /* Insert an insn entry in an attribute value list. */
1855 insert_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
1857 ie
->next
= av
->first_insn
;
1858 av
->first_insn
= ie
;
1860 if (ie
->def
->insn_code
== -1)
1861 av
->has_asm_insn
= 1;
1866 /* This is a utility routine to take an expression that is a tree of either
1867 AND or IOR expressions and insert a new term. The new term will be
1868 inserted at the right side of the first node whose code does not match
1869 the root. A new node will be created with the root's code. Its left
1870 side will be the old right side and its right side will be the new
1873 If the `term' is itself a tree, all its leaves will be inserted. */
1876 insert_right_side (enum rtx_code code
, rtx exp
, rtx term
, int insn_code
, int insn_index
)
1880 /* Avoid consing in some special cases. */
1881 if (code
== AND
&& term
== true_rtx
)
1883 if (code
== AND
&& term
== false_rtx
)
1885 if (code
== AND
&& exp
== true_rtx
)
1887 if (code
== AND
&& exp
== false_rtx
)
1889 if (code
== IOR
&& term
== true_rtx
)
1891 if (code
== IOR
&& term
== false_rtx
)
1893 if (code
== IOR
&& exp
== true_rtx
)
1895 if (code
== IOR
&& exp
== false_rtx
)
1897 if (attr_equal_p (exp
, term
))
1900 if (GET_CODE (term
) == code
)
1902 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
1903 insn_code
, insn_index
);
1904 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
1905 insn_code
, insn_index
);
1910 if (GET_CODE (exp
) == code
)
1912 rtx new_rtx
= insert_right_side (code
, XEXP (exp
, 1),
1913 term
, insn_code
, insn_index
);
1914 if (new_rtx
!= XEXP (exp
, 1))
1915 /* Make a copy of this expression and call recursively. */
1916 newexp
= attr_rtx (code
, XEXP (exp
, 0), new_rtx
);
1922 /* Insert the new term. */
1923 newexp
= attr_rtx (code
, exp
, term
);
1926 return simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
1929 /* If we have an expression which AND's a bunch of
1930 (not (eq_attrq "alternative" "n"))
1931 terms, we may have covered all or all but one of the possible alternatives.
1932 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
1934 This routine is passed an expression and either AND or IOR. It returns a
1935 bitmask indicating which alternatives are mentioned within EXP. */
1938 compute_alternative_mask (rtx exp
, enum rtx_code code
)
1941 if (GET_CODE (exp
) == code
)
1942 return compute_alternative_mask (XEXP (exp
, 0), code
)
1943 | compute_alternative_mask (XEXP (exp
, 1), code
);
1945 else if (code
== AND
&& GET_CODE (exp
) == NOT
1946 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
1947 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
1948 string
= XSTR (XEXP (exp
, 0), 1);
1950 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
1951 && XSTR (exp
, 0) == alternative_name
)
1952 string
= XSTR (exp
, 1);
1954 else if (GET_CODE (exp
) == EQ_ATTR_ALT
)
1956 if (code
== AND
&& XINT (exp
, 1))
1957 return XINT (exp
, 0);
1959 if (code
== IOR
&& !XINT (exp
, 1))
1960 return XINT (exp
, 0);
1968 return 1 << (string
[0] - '0');
1969 return 1 << atoi (string
);
1972 /* Given I, a single-bit mask, return RTX to compare the `alternative'
1973 attribute with the value represented by that bit. */
1976 make_alternative_compare (int mask
)
1978 return mk_attr_alt (mask
);
1981 /* If we are processing an (eq_attr "attr" "value") test, we find the value
1982 of "attr" for this insn code. From that value, we can compute a test
1983 showing when the EQ_ATTR will be true. This routine performs that
1984 computation. If a test condition involves an address, we leave the EQ_ATTR
1985 intact because addresses are only valid for the `length' attribute.
1987 EXP is the EQ_ATTR expression and ATTR is the attribute to which
1988 it refers. VALUE is the value of that attribute for the insn
1989 corresponding to INSN_CODE and INSN_INDEX. */
1992 evaluate_eq_attr (rtx exp
, struct attr_desc
*attr
, rtx value
,
1993 int insn_code
, int insn_index
)
2000 while (GET_CODE (value
) == ATTR
)
2002 struct attr_value
*av
= NULL
;
2004 attr
= find_attr (&XSTR (value
, 0), 0);
2006 if (insn_code_values
)
2008 struct attr_value_list
*iv
;
2009 for (iv
= insn_code_values
[insn_code
]; iv
; iv
= iv
->next
)
2010 if (iv
->attr
== attr
)
2018 struct insn_ent
*ie
;
2019 for (av
= attr
->first_value
; av
; av
= av
->next
)
2020 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2021 if (ie
->def
->insn_code
== insn_code
)
2031 switch (GET_CODE (value
))
2034 if (! strcmp_check (XSTR (value
, 0), XSTR (exp
, 1)))
2045 gcc_assert (GET_CODE (exp
) == EQ_ATTR
);
2046 prefix
= attr
->enum_name
? attr
->enum_name
: attr
->name
;
2047 string
= ACONCAT ((prefix
, "_", XSTR (exp
, 1), NULL
));
2048 for (p
= string
; *p
; p
++)
2051 newexp
= attr_rtx (EQ
, value
,
2052 attr_rtx (SYMBOL_REF
,
2053 DEF_ATTR_STRING (string
)));
2058 /* We construct an IOR of all the cases for which the
2059 requested attribute value is present. Since we start with
2060 FALSE, if it is not present, FALSE will be returned.
2062 Each case is the AND of the NOT's of the previous conditions with the
2063 current condition; in the default case the current condition is TRUE.
2065 For each possible COND value, call ourselves recursively.
2067 The extra TRUE and FALSE expressions will be eliminated by another
2068 call to the simplification routine. */
2073 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2075 rtx this_cond
= simplify_test_exp_in_temp (XVECEXP (value
, 0, i
),
2076 insn_code
, insn_index
);
2078 right
= insert_right_side (AND
, andexp
, this_cond
,
2079 insn_code
, insn_index
);
2080 right
= insert_right_side (AND
, right
,
2081 evaluate_eq_attr (exp
, attr
,
2084 insn_code
, insn_index
),
2085 insn_code
, insn_index
);
2086 orexp
= insert_right_side (IOR
, orexp
, right
,
2087 insn_code
, insn_index
);
2089 /* Add this condition into the AND expression. */
2090 newexp
= attr_rtx (NOT
, this_cond
);
2091 andexp
= insert_right_side (AND
, andexp
, newexp
,
2092 insn_code
, insn_index
);
2095 /* Handle the default case. */
2096 right
= insert_right_side (AND
, andexp
,
2097 evaluate_eq_attr (exp
, attr
, XEXP (value
, 1),
2098 insn_code
, insn_index
),
2099 insn_code
, insn_index
);
2100 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2107 /* If uses an address, must return original expression. But set the
2108 ATTR_IND_SIMPLIFIED_P bit so we don't try to simplify it again. */
2111 walk_attr_value (newexp
);
2115 if (! ATTR_IND_SIMPLIFIED_P (exp
))
2116 return copy_rtx_unchanging (exp
);
2123 /* This routine is called when an AND of a term with a tree of AND's is
2124 encountered. If the term or its complement is present in the tree, it
2125 can be replaced with TRUE or FALSE, respectively.
2127 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2128 be true and hence are complementary.
2130 There is one special case: If we see
2131 (and (not (eq_attr "att" "v1"))
2132 (eq_attr "att" "v2"))
2133 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2134 replace the term, not anything in the AND tree. So we pass a pointer to
2138 simplify_and_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
2143 int left_eliminates_term
, right_eliminates_term
;
2145 if (GET_CODE (exp
) == AND
)
2147 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2148 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2149 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2151 newexp
= attr_rtx (AND
, left
, right
);
2153 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2157 else if (GET_CODE (exp
) == IOR
)
2159 /* For the IOR case, we do the same as above, except that we can
2160 only eliminate `term' if both sides of the IOR would do so. */
2162 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2163 left_eliminates_term
= (temp
== true_rtx
);
2166 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2167 right_eliminates_term
= (temp
== true_rtx
);
2169 if (left_eliminates_term
&& right_eliminates_term
)
2172 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2174 newexp
= attr_rtx (IOR
, left
, right
);
2176 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2180 /* Check for simplifications. Do some extra checking here since this
2181 routine is called so many times. */
2186 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
2189 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
2192 else if (GET_CODE (exp
) == EQ_ATTR_ALT
&& GET_CODE (*pterm
) == EQ_ATTR_ALT
)
2194 if (attr_alt_subset_p (*pterm
, exp
))
2197 if (attr_alt_subset_of_compl_p (*pterm
, exp
))
2200 if (attr_alt_subset_p (exp
, *pterm
))
2206 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
2208 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
2211 if (! strcmp_check (XSTR (exp
, 1), XSTR (*pterm
, 1)))
2217 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2218 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
2220 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
2223 if (! strcmp_check (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
2229 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2230 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
2232 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
2235 if (! strcmp_check (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
2241 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
2243 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
2247 else if (GET_CODE (exp
) == NOT
)
2249 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
2253 else if (GET_CODE (*pterm
) == NOT
)
2255 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
2259 else if (attr_equal_p (exp
, *pterm
))
2265 /* Similar to `simplify_and_tree', but for IOR trees. */
2268 simplify_or_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
2273 int left_eliminates_term
, right_eliminates_term
;
2275 if (GET_CODE (exp
) == IOR
)
2277 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2278 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2279 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2281 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2283 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2287 else if (GET_CODE (exp
) == AND
)
2289 /* For the AND case, we do the same as above, except that we can
2290 only eliminate `term' if both sides of the AND would do so. */
2292 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2293 left_eliminates_term
= (temp
== false_rtx
);
2296 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2297 right_eliminates_term
= (temp
== false_rtx
);
2299 if (left_eliminates_term
&& right_eliminates_term
)
2302 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2304 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2306 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2310 if (attr_equal_p (exp
, *pterm
))
2313 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
2316 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
2319 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2320 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2321 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
2324 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2325 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
2326 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
2332 /* Simplify test expression and use temporary obstack in order to avoid
2333 memory bloat. Use ATTR_IND_SIMPLIFIED to avoid unnecessary simplifications
2334 and avoid unnecessary copying if possible. */
2337 simplify_test_exp_in_temp (rtx exp
, int insn_code
, int insn_index
)
2340 struct obstack
*old
;
2341 if (ATTR_IND_SIMPLIFIED_P (exp
))
2344 rtl_obstack
= temp_obstack
;
2345 x
= simplify_test_exp (exp
, insn_code
, insn_index
);
2347 if (x
== exp
|| rtl_obstack
== temp_obstack
)
2349 return attr_copy_rtx (x
);
2352 /* Returns true if S1 is a subset of S2. */
2355 attr_alt_subset_p (rtx s1
, rtx s2
)
2357 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2360 return !(XINT (s1
, 0) &~ XINT (s2
, 0));
2363 return !(XINT (s1
, 0) & XINT (s2
, 0));
2369 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
2376 /* Returns true if S1 is a subset of complement of S2. */
2379 attr_alt_subset_of_compl_p (rtx s1
, rtx s2
)
2381 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2384 return !(XINT (s1
, 0) & XINT (s2
, 0));
2387 return !(XINT (s1
, 0) & ~XINT (s2
, 0));
2390 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
2400 /* Return EQ_ATTR_ALT expression representing intersection of S1 and S2. */
2403 attr_alt_intersection (rtx s1
, rtx s2
)
2405 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
2407 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2410 XINT (result
, 0) = XINT (s1
, 0) & XINT (s2
, 0);
2413 XINT (result
, 0) = XINT (s1
, 0) & ~XINT (s2
, 0);
2416 XINT (result
, 0) = XINT (s2
, 0) & ~XINT (s1
, 0);
2419 XINT (result
, 0) = XINT (s1
, 0) | XINT (s2
, 0);
2424 XINT (result
, 1) = XINT (s1
, 1) & XINT (s2
, 1);
2429 /* Return EQ_ATTR_ALT expression representing union of S1 and S2. */
2432 attr_alt_union (rtx s1
, rtx s2
)
2434 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
2436 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2439 XINT (result
, 0) = XINT (s1
, 0) | XINT (s2
, 0);
2442 XINT (result
, 0) = XINT (s2
, 0) & ~XINT (s1
, 0);
2445 XINT (result
, 0) = XINT (s1
, 0) & ~XINT (s2
, 0);
2448 XINT (result
, 0) = XINT (s1
, 0) & XINT (s2
, 0);
2454 XINT (result
, 1) = XINT (s1
, 1) | XINT (s2
, 1);
2458 /* Return EQ_ATTR_ALT expression representing complement of S. */
2461 attr_alt_complement (rtx s
)
2463 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
2465 XINT (result
, 0) = XINT (s
, 0);
2466 XINT (result
, 1) = 1 - XINT (s
, 1);
2471 /* Return EQ_ATTR_ALT expression representing set containing elements set
2477 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
2479 XINT (result
, 0) = e
;
2480 XINT (result
, 1) = 0;
2485 /* Given an expression, see if it can be simplified for a particular insn
2486 code based on the values of other attributes being tested. This can
2487 eliminate nested get_attr_... calls.
2489 Note that if an endless recursion is specified in the patterns, the
2490 optimization will loop. However, it will do so in precisely the cases where
2491 an infinite recursion loop could occur during compilation. It's better that
2495 simplify_test_exp (rtx exp
, int insn_code
, int insn_index
)
2498 struct attr_desc
*attr
;
2499 struct attr_value
*av
;
2500 struct insn_ent
*ie
;
2501 struct attr_value_list
*iv
;
2504 bool left_alt
, right_alt
;
2506 /* Don't re-simplify something we already simplified. */
2507 if (ATTR_IND_SIMPLIFIED_P (exp
) || ATTR_CURR_SIMPLIFIED_P (exp
))
2510 switch (GET_CODE (exp
))
2513 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2514 if (left
== false_rtx
)
2516 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2517 if (right
== false_rtx
)
2520 if (GET_CODE (left
) == EQ_ATTR_ALT
2521 && GET_CODE (right
) == EQ_ATTR_ALT
)
2523 exp
= attr_alt_intersection (left
, right
);
2524 return simplify_test_exp (exp
, insn_code
, insn_index
);
2527 /* If either side is an IOR and we have (eq_attr "alternative" ..")
2528 present on both sides, apply the distributive law since this will
2529 yield simplifications. */
2530 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
2531 && compute_alternative_mask (left
, IOR
)
2532 && compute_alternative_mask (right
, IOR
))
2534 if (GET_CODE (left
) == IOR
)
2541 newexp
= attr_rtx (IOR
,
2542 attr_rtx (AND
, left
, XEXP (right
, 0)),
2543 attr_rtx (AND
, left
, XEXP (right
, 1)));
2545 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2548 /* Try with the term on both sides. */
2549 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
2550 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2551 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
2553 if (left
== false_rtx
|| right
== false_rtx
)
2555 else if (left
== true_rtx
)
2559 else if (right
== true_rtx
)
2563 /* See if all or all but one of the insn's alternatives are specified
2564 in this tree. Optimize if so. */
2566 if (GET_CODE (left
) == NOT
)
2567 left_alt
= (GET_CODE (XEXP (left
, 0)) == EQ_ATTR
2568 && XSTR (XEXP (left
, 0), 0) == alternative_name
);
2570 left_alt
= (GET_CODE (left
) == EQ_ATTR_ALT
2573 if (GET_CODE (right
) == NOT
)
2574 right_alt
= (GET_CODE (XEXP (right
, 0)) == EQ_ATTR
2575 && XSTR (XEXP (right
, 0), 0) == alternative_name
);
2577 right_alt
= (GET_CODE (right
) == EQ_ATTR_ALT
2578 && XINT (right
, 1));
2581 && (GET_CODE (left
) == AND
2583 || GET_CODE (right
) == AND
2586 i
= compute_alternative_mask (exp
, AND
);
2587 if (i
& ~insn_alternatives
[insn_code
])
2588 fatal ("invalid alternative specified for pattern number %d",
2591 /* If all alternatives are excluded, this is false. */
2592 i
^= insn_alternatives
[insn_code
];
2595 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2597 /* If just one excluded, AND a comparison with that one to the
2598 front of the tree. The others will be eliminated by
2599 optimization. We do not want to do this if the insn has one
2600 alternative and we have tested none of them! */
2601 left
= make_alternative_compare (i
);
2602 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2603 newexp
= attr_rtx (AND
, left
, right
);
2605 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2609 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2611 newexp
= attr_rtx (AND
, left
, right
);
2612 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2617 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2618 if (left
== true_rtx
)
2620 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2621 if (right
== true_rtx
)
2624 if (GET_CODE (left
) == EQ_ATTR_ALT
2625 && GET_CODE (right
) == EQ_ATTR_ALT
)
2627 exp
= attr_alt_union (left
, right
);
2628 return simplify_test_exp (exp
, insn_code
, insn_index
);
2631 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
2632 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2633 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
2635 if (right
== true_rtx
|| left
== true_rtx
)
2637 else if (left
== false_rtx
)
2641 else if (right
== false_rtx
)
2646 /* Test for simple cases where the distributive law is useful. I.e.,
2647 convert (ior (and (x) (y))
2653 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2654 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
2656 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
2658 left
= XEXP (left
, 0);
2660 newexp
= attr_rtx (AND
, left
, right
);
2661 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2665 convert (ior (and (y) (x))
2667 to (and (ior (y) (z))
2669 Note that we want the common term to stay at the end.
2672 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2673 && attr_equal_p (XEXP (left
, 1), XEXP (right
, 1)))
2675 newexp
= attr_rtx (IOR
, XEXP (left
, 0), XEXP (right
, 0));
2678 right
= XEXP (right
, 1);
2679 newexp
= attr_rtx (AND
, left
, right
);
2680 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2683 /* See if all or all but one of the insn's alternatives are specified
2684 in this tree. Optimize if so. */
2686 else if (insn_code
>= 0
2687 && (GET_CODE (left
) == IOR
2688 || (GET_CODE (left
) == EQ_ATTR_ALT
2690 || (GET_CODE (left
) == EQ_ATTR
2691 && XSTR (left
, 0) == alternative_name
)
2692 || GET_CODE (right
) == IOR
2693 || (GET_CODE (right
) == EQ_ATTR_ALT
2694 && !XINT (right
, 1))
2695 || (GET_CODE (right
) == EQ_ATTR
2696 && XSTR (right
, 0) == alternative_name
)))
2698 i
= compute_alternative_mask (exp
, IOR
);
2699 if (i
& ~insn_alternatives
[insn_code
])
2700 fatal ("invalid alternative specified for pattern number %d",
2703 /* If all alternatives are included, this is true. */
2704 i
^= insn_alternatives
[insn_code
];
2707 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2709 /* If just one excluded, IOR a comparison with that one to the
2710 front of the tree. The others will be eliminated by
2711 optimization. We do not want to do this if the insn has one
2712 alternative and we have tested none of them! */
2713 left
= make_alternative_compare (i
);
2714 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2715 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
2717 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2721 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2723 newexp
= attr_rtx (IOR
, left
, right
);
2724 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2729 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
2731 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
2732 insn_code
, insn_index
);
2736 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2737 if (GET_CODE (left
) == NOT
)
2738 return XEXP (left
, 0);
2740 if (left
== false_rtx
)
2742 if (left
== true_rtx
)
2745 if (GET_CODE (left
) == EQ_ATTR_ALT
)
2747 exp
= attr_alt_complement (left
);
2748 return simplify_test_exp (exp
, insn_code
, insn_index
);
2751 /* Try to apply De`Morgan's laws. */
2752 if (GET_CODE (left
) == IOR
)
2754 newexp
= attr_rtx (AND
,
2755 attr_rtx (NOT
, XEXP (left
, 0)),
2756 attr_rtx (NOT
, XEXP (left
, 1)));
2758 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2760 else if (GET_CODE (left
) == AND
)
2762 newexp
= attr_rtx (IOR
,
2763 attr_rtx (NOT
, XEXP (left
, 0)),
2764 attr_rtx (NOT
, XEXP (left
, 1)));
2766 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2768 else if (left
!= XEXP (exp
, 0))
2770 newexp
= attr_rtx (NOT
, left
);
2776 return XINT (exp
, 1) ? true_rtx
: false_rtx
;
2780 if (XSTR (exp
, 0) == alternative_name
)
2782 newexp
= mk_attr_alt (1 << atoi (XSTR (exp
, 1)));
2786 /* Look at the value for this insn code in the specified attribute.
2787 We normally can replace this comparison with the condition that
2788 would give this insn the values being tested for. */
2790 && (attr
= find_attr (&XSTR (exp
, 0), 0)) != NULL
)
2795 if (insn_code_values
)
2797 for (iv
= insn_code_values
[insn_code
]; iv
; iv
= iv
->next
)
2798 if (iv
->attr
== attr
)
2806 for (av
= attr
->first_value
; av
; av
= av
->next
)
2807 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2808 if (ie
->def
->insn_code
== insn_code
)
2815 x
= evaluate_eq_attr (exp
, attr
, av
->value
,
2816 insn_code
, insn_index
);
2817 x
= SIMPLIFY_TEST_EXP (x
, insn_code
, insn_index
);
2818 if (attr_rtx_cost (x
) < 7)
2828 /* We have already simplified this expression. Simplifying it again
2829 won't buy anything unless we weren't given a valid insn code
2830 to process (i.e., we are canonicalizing something.). */
2832 && ! ATTR_IND_SIMPLIFIED_P (newexp
))
2833 return copy_rtx_unchanging (newexp
);
2838 /* Return 1 if any EQ_ATTR subexpression of P refers to ATTR,
2839 otherwise return 0. */
2842 tests_attr_p (rtx p
, struct attr_desc
*attr
)
2847 if (GET_CODE (p
) == EQ_ATTR
)
2849 if (XSTR (p
, 0) != attr
->name
)
2854 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
2855 ie
= GET_RTX_LENGTH (GET_CODE (p
));
2856 for (i
= 0; i
< ie
; i
++)
2861 if (tests_attr_p (XEXP (p
, i
), attr
))
2866 je
= XVECLEN (p
, i
);
2867 for (j
= 0; j
< je
; ++j
)
2868 if (tests_attr_p (XVECEXP (p
, i
, j
), attr
))
2877 /* Calculate a topological sorting of all attributes so that
2878 all attributes only depend on attributes in front of it.
2879 Place the result in *RET (which is a pointer to an array of
2880 attr_desc pointers), and return the size of that array. */
2883 get_attr_order (struct attr_desc
***ret
)
2887 struct attr_desc
*attr
;
2888 struct attr_desc
**all
, **sorted
;
2890 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
2891 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
2893 all
= XNEWVEC (struct attr_desc
*, num
);
2894 sorted
= XNEWVEC (struct attr_desc
*, num
);
2895 handled
= XCNEWVEC (char, num
);
2897 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
2898 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
2902 for (i
= 0; i
< num
; i
++)
2903 if (all
[i
]->is_const
)
2904 handled
[i
] = 1, sorted
[j
++] = all
[i
];
2906 /* We have only few attributes hence we can live with the inner
2907 loop being O(n^2), unlike the normal fast variants of topological
2911 for (i
= 0; i
< num
; i
++)
2914 /* Let's see if I depends on anything interesting. */
2916 for (k
= 0; k
< num
; k
++)
2919 struct attr_value
*av
;
2920 for (av
= all
[i
]->first_value
; av
; av
= av
->next
)
2921 if (av
->num_insns
!= 0)
2922 if (tests_attr_p (av
->value
, all
[k
]))
2926 /* Something in I depends on K. */
2931 /* Nothing in I depended on anything intersting, so
2934 sorted
[j
++] = all
[i
];
2940 for (j
= 0; j
< num
; j
++)
2942 struct attr_desc
*attr2
;
2943 struct attr_value
*av
;
2946 fprintf (stderr
, "%s depends on: ", attr
->name
);
2947 for (i
= 0; i
< MAX_ATTRS_INDEX
; ++i
)
2948 for (attr2
= attrs
[i
]; attr2
; attr2
= attr2
->next
)
2949 if (!attr2
->is_const
)
2950 for (av
= attr
->first_value
; av
; av
= av
->next
)
2951 if (av
->num_insns
!= 0)
2952 if (tests_attr_p (av
->value
, attr2
))
2954 fprintf (stderr
, "%s, ", attr2
->name
);
2957 fprintf (stderr
, "\n");
2965 /* Optimize the attribute lists by seeing if we can determine conditional
2966 values from the known values of other attributes. This will save subroutine
2967 calls during the compilation. */
2970 optimize_attrs (void)
2972 struct attr_desc
*attr
;
2973 struct attr_value
*av
;
2974 struct insn_ent
*ie
;
2977 struct attr_value_list
*ivbuf
;
2978 struct attr_value_list
*iv
;
2979 struct attr_desc
**topsort
;
2982 /* For each insn code, make a list of all the insn_ent's for it,
2983 for all values for all attributes. */
2985 if (num_insn_ents
== 0)
2988 /* Make 2 extra elements, for "code" values -2 and -1. */
2989 insn_code_values
= XCNEWVEC (struct attr_value_list
*, insn_code_number
+ 2);
2991 /* Offset the table address so we can index by -2 or -1. */
2992 insn_code_values
+= 2;
2994 iv
= ivbuf
= XNEWVEC (struct attr_value_list
, num_insn_ents
);
2996 /* Create the chain of insn*attr values such that we see dependend
2997 attributes after their dependencies. As we use a stack via the
2998 next pointers start from the end of the topological order. */
2999 topnum
= get_attr_order (&topsort
);
3000 for (i
= topnum
- 1; i
>= 0; i
--)
3001 for (av
= topsort
[i
]->first_value
; av
; av
= av
->next
)
3002 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3004 iv
->attr
= topsort
[i
];
3007 iv
->next
= insn_code_values
[ie
->def
->insn_code
];
3008 insn_code_values
[ie
->def
->insn_code
] = iv
;
3013 /* Sanity check on num_insn_ents. */
3014 gcc_assert (iv
== ivbuf
+ num_insn_ents
);
3016 /* Process one insn code at a time. */
3017 for (i
= -2; i
< insn_code_number
; i
++)
3019 /* Clear the ATTR_CURR_SIMPLIFIED_P flag everywhere relevant.
3020 We use it to mean "already simplified for this insn". */
3021 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3022 clear_struct_flag (iv
->av
->value
);
3024 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3026 struct obstack
*old
= rtl_obstack
;
3031 if (GET_CODE (av
->value
) != COND
)
3034 rtl_obstack
= temp_obstack
;
3036 while (GET_CODE (newexp
) == COND
)
3038 rtx newexp2
= simplify_cond (newexp
, ie
->def
->insn_code
,
3039 ie
->def
->insn_index
);
3040 if (newexp2
== newexp
)
3046 /* If we created a new value for this instruction, and it's
3047 cheaper than the old value, and overall cheap, use that
3048 one as specific value for the current instruction.
3049 The last test is to avoid exploding the get_attr_ function
3050 sizes for no much gain. */
3051 if (newexp
!= av
->value
3052 && attr_rtx_cost (newexp
) < attr_rtx_cost (av
->value
)
3053 && attr_rtx_cost (newexp
) < 26
3056 newexp
= attr_copy_rtx (newexp
);
3057 remove_insn_ent (av
, ie
);
3058 av
= get_attr_value (newexp
, attr
, ie
->def
->insn_code
);
3060 insert_insn_ent (av
, ie
);
3066 free (insn_code_values
- 2);
3067 insn_code_values
= NULL
;
3070 /* Clear the ATTR_CURR_SIMPLIFIED_P flag in EXP and its subexpressions. */
3073 clear_struct_flag (rtx x
)
3080 ATTR_CURR_SIMPLIFIED_P (x
) = 0;
3081 if (ATTR_IND_SIMPLIFIED_P (x
))
3084 code
= GET_CODE (x
);
3103 /* Compare the elements. If any pair of corresponding elements
3104 fail to match, return 0 for the whole things. */
3106 fmt
= GET_RTX_FORMAT (code
);
3107 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3113 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3114 clear_struct_flag (XVECEXP (x
, i
, j
));
3118 clear_struct_flag (XEXP (x
, i
));
3124 /* Add attribute value NAME to the beginning of ATTR's list. */
3127 add_attr_value (struct attr_desc
*attr
, const char *name
)
3129 struct attr_value
*av
;
3131 av
= oballoc (struct attr_value
);
3132 av
->value
= attr_rtx (CONST_STRING
, name
);
3133 av
->next
= attr
->first_value
;
3134 attr
->first_value
= av
;
3135 av
->first_insn
= NULL
;
3137 av
->has_asm_insn
= 0;
3140 /* Create table entries for DEFINE_ATTR or DEFINE_ENUM_ATTR. */
3143 gen_attr (rtx exp
, int lineno
)
3145 struct enum_type
*et
;
3146 struct enum_value
*ev
;
3147 struct attr_desc
*attr
;
3148 const char *name_ptr
;
3151 /* Make a new attribute structure. Check for duplicate by looking at
3152 attr->default_val, since it is initialized by this routine. */
3153 attr
= find_attr (&XSTR (exp
, 0), 1);
3154 if (attr
->default_val
)
3156 error_with_line (lineno
, "duplicate definition for attribute %s",
3158 message_with_line (attr
->lineno
, "previous definition");
3161 attr
->lineno
= lineno
;
3163 if (GET_CODE (exp
) == DEFINE_ENUM_ATTR
)
3165 attr
->enum_name
= XSTR (exp
, 1);
3166 et
= lookup_enum_type (XSTR (exp
, 1));
3167 if (!et
|| !et
->md_p
)
3168 error_with_line (lineno
, "No define_enum called `%s' defined",
3171 for (ev
= et
->values
; ev
; ev
= ev
->next
)
3172 add_attr_value (attr
, ev
->name
);
3174 else if (*XSTR (exp
, 1) == '\0')
3175 attr
->is_numeric
= 1;
3178 name_ptr
= XSTR (exp
, 1);
3179 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
3180 add_attr_value (attr
, p
);
3183 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
3186 if (attr
->is_numeric
)
3187 error_with_line (lineno
,
3188 "constant attributes may not take numeric values");
3190 /* Get rid of the CONST node. It is allowed only at top-level. */
3191 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
3194 if (! strcmp_check (attr
->name
, length_str
) && ! attr
->is_numeric
)
3195 error_with_line (lineno
, "`length' attribute must take numeric values");
3197 /* Set up the default value. */
3198 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
3199 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
3202 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
3203 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
3204 number of alternatives as this should be checked elsewhere. */
3207 count_alternatives (rtx exp
)
3212 if (GET_CODE (exp
) == MATCH_OPERAND
)
3213 return n_comma_elts (XSTR (exp
, 2));
3215 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3216 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3221 n
= count_alternatives (XEXP (exp
, i
));
3228 if (XVEC (exp
, i
) != NULL
)
3229 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3231 n
= count_alternatives (XVECEXP (exp
, i
, j
));
3240 /* Returns nonzero if the given expression contains an EQ_ATTR with the
3241 `alternative' attribute. */
3244 compares_alternatives_p (rtx exp
)
3249 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
3252 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3253 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3258 if (compares_alternatives_p (XEXP (exp
, i
)))
3263 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3264 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
3272 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
3275 gen_insn (rtx exp
, int lineno
)
3277 struct insn_def
*id
;
3279 id
= oballoc (struct insn_def
);
3283 id
->filename
= read_md_filename
;
3284 id
->lineno
= lineno
;
3286 switch (GET_CODE (exp
))
3289 id
->insn_code
= insn_code_number
;
3290 id
->insn_index
= insn_index_number
;
3291 id
->num_alternatives
= count_alternatives (exp
);
3292 if (id
->num_alternatives
== 0)
3293 id
->num_alternatives
= 1;
3297 case DEFINE_PEEPHOLE
:
3298 id
->insn_code
= insn_code_number
;
3299 id
->insn_index
= insn_index_number
;
3300 id
->num_alternatives
= count_alternatives (exp
);
3301 if (id
->num_alternatives
== 0)
3302 id
->num_alternatives
= 1;
3306 case DEFINE_ASM_ATTRIBUTES
:
3308 id
->insn_index
= -1;
3309 id
->num_alternatives
= 1;
3311 got_define_asm_attributes
= 1;
3319 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
3320 true or annul false is specified, and make a `struct delay_desc'. */
3323 gen_delay (rtx def
, int lineno
)
3325 struct delay_desc
*delay
;
3328 if (XVECLEN (def
, 1) % 3 != 0)
3330 error_with_line (lineno
,
3331 "number of elements in DEFINE_DELAY must"
3332 " be multiple of three");
3336 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
3338 if (XVECEXP (def
, 1, i
+ 1))
3339 have_annul_true
= 1;
3340 if (XVECEXP (def
, 1, i
+ 2))
3341 have_annul_false
= 1;
3344 delay
= oballoc (struct delay_desc
);
3346 delay
->num
= ++num_delays
;
3347 delay
->next
= delays
;
3348 delay
->lineno
= lineno
;
3352 /* Names of attributes that could be possibly cached. */
3353 static const char *cached_attrs
[32];
3354 /* Number of such attributes. */
3355 static int cached_attr_count
;
3356 /* Bitmasks of possibly cached attributes. */
3357 static unsigned int attrs_seen_once
, attrs_seen_more_than_once
;
3358 static unsigned int attrs_to_cache
;
3359 static unsigned int attrs_cached_inside
, attrs_cached_after
;
3361 /* Finds non-const attributes that could be possibly cached.
3362 When create is TRUE, fills in cached_attrs array.
3363 Computes ATTRS_SEEN_ONCE and ATTRS_SEEN_MORE_THAN_ONCE
3367 find_attrs_to_cache (rtx exp
, bool create
)
3371 struct attr_desc
*attr
;
3376 switch (GET_CODE (exp
))
3379 if (GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3380 find_attrs_to_cache (XEXP (exp
, 0), create
);
3384 name
= XSTR (exp
, 0);
3385 if (name
== alternative_name
)
3387 for (i
= 0; i
< cached_attr_count
; i
++)
3388 if (name
== cached_attrs
[i
])
3390 if ((attrs_seen_once
& (1U << i
)) != 0)
3391 attrs_seen_more_than_once
|= (1U << i
);
3393 attrs_seen_once
|= (1U << i
);
3398 attr
= find_attr (&name
, 0);
3402 if (cached_attr_count
== 32)
3404 cached_attrs
[cached_attr_count
] = XSTR (exp
, 0);
3405 attrs_seen_once
|= (1U << cached_attr_count
);
3406 cached_attr_count
++;
3411 find_attrs_to_cache (XEXP (exp
, 0), create
);
3412 find_attrs_to_cache (XEXP (exp
, 1), create
);
3416 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3417 find_attrs_to_cache (XVECEXP (exp
, 0, i
), create
);
3425 /* Given a piece of RTX, print a C expression to test its truth value to OUTF.
3426 We use AND and IOR both for logical and bit-wise operations, so
3427 interpret them as logical unless they are inside a comparison expression. */
3429 /* Interpret AND/IOR as bit-wise operations instead of logical. */
3430 #define FLG_BITWISE 1
3431 /* Set if cached attribute will be known initialized in else block after
3432 this condition. This is true for LHS of toplevel && and || and
3433 even for RHS of ||, but not for RHS of &&. */
3435 /* Set if cached attribute will be known initialized in then block after
3436 this condition. This is true for LHS of toplevel && and || and
3437 even for RHS of &&, but not for RHS of ||. */
3438 #define FLG_INSIDE 4
3439 /* Cleared when an operand of &&. */
3440 #define FLG_OUTSIDE_AND 8
3443 write_test_expr (FILE *outf
, rtx exp
, unsigned int attrs_cached
, int flags
)
3445 int comparison_operator
= 0;
3447 struct attr_desc
*attr
;
3449 /* In order not to worry about operator precedence, surround our part of
3450 the expression with parentheses. */
3452 fprintf (outf
, "(");
3453 code
= GET_CODE (exp
);
3456 /* Binary operators. */
3459 fprintf (outf
, "(unsigned) ");
3465 comparison_operator
= FLG_BITWISE
;
3467 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
3468 case AND
: case IOR
: case XOR
:
3469 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
3470 if ((code
!= AND
&& code
!= IOR
) || (flags
& FLG_BITWISE
))
3472 flags
&= ~(FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
);
3473 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
,
3474 flags
| comparison_operator
);
3479 flags
&= ~FLG_OUTSIDE_AND
;
3480 if (GET_CODE (XEXP (exp
, 0)) == code
3481 || GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3482 || (GET_CODE (XEXP (exp
, 0)) == NOT
3483 && GET_CODE (XEXP (XEXP (exp
, 0), 0)) == EQ_ATTR
))
3485 = write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3487 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3492 fprintf (outf
, " == ");
3495 fprintf (outf
, " != ");
3498 fprintf (outf
, " >= ");
3501 fprintf (outf
, " > ");
3504 fprintf (outf
, " >= (unsigned) ");
3507 fprintf (outf
, " > (unsigned) ");
3510 fprintf (outf
, " <= ");
3513 fprintf (outf
, " < ");
3516 fprintf (outf
, " <= (unsigned) ");
3519 fprintf (outf
, " < (unsigned) ");
3522 fprintf (outf
, " + ");
3525 fprintf (outf
, " - ");
3528 fprintf (outf
, " * ");
3531 fprintf (outf
, " / ");
3534 fprintf (outf
, " %% ");
3537 if (flags
& FLG_BITWISE
)
3538 fprintf (outf
, " & ");
3540 fprintf (outf
, " && ");
3543 if (flags
& FLG_BITWISE
)
3544 fprintf (outf
, " | ");
3546 fprintf (outf
, " || ");
3549 fprintf (outf
, " ^ ");
3552 fprintf (outf
, " << ");
3556 fprintf (outf
, " >> ");
3564 /* For if (something && (cached_x = get_attr_x (insn)) == X)
3565 cached_x is only known to be initialized in then block. */
3566 flags
&= ~FLG_AFTER
;
3568 else if (code
== IOR
)
3570 if (flags
& FLG_OUTSIDE_AND
)
3571 /* For if (something || (cached_x = get_attr_x (insn)) == X)
3572 cached_x is only known to be initialized in else block
3573 and else if conditions. */
3574 flags
&= ~FLG_INSIDE
;
3576 /* For if ((something || (cached_x = get_attr_x (insn)) == X)
3578 cached_x is not know to be initialized anywhere. */
3579 flags
&= ~(FLG_AFTER
| FLG_INSIDE
);
3581 if ((code
== AND
|| code
== IOR
)
3582 && (GET_CODE (XEXP (exp
, 1)) == code
3583 || GET_CODE (XEXP (exp
, 1)) == EQ_ATTR
3584 || (GET_CODE (XEXP (exp
, 1)) == NOT
3585 && GET_CODE (XEXP (XEXP (exp
, 1), 0)) == EQ_ATTR
)))
3587 = write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
, flags
);
3589 write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
,
3590 flags
| comparison_operator
);
3594 /* Special-case (not (eq_attrq "alternative" "x")) */
3595 if (! (flags
& FLG_BITWISE
) && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3597 if (XSTR (XEXP (exp
, 0), 0) == alternative_name
)
3599 fprintf (outf
, "which_alternative != %s",
3600 XSTR (XEXP (exp
, 0), 1));
3604 fprintf (outf
, "! ");
3606 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3610 /* Otherwise, fall through to normal unary operator. */
3612 /* Unary operators. */
3617 if (flags
& FLG_BITWISE
)
3618 fprintf (outf
, "~ ");
3620 fprintf (outf
, "! ");
3623 fprintf (outf
, "abs ");
3626 fprintf (outf
, "-");
3632 flags
&= ~(FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
);
3633 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3638 int set
= XINT (exp
, 0), bit
= 0;
3640 if (flags
& FLG_BITWISE
)
3641 fatal ("EQ_ATTR_ALT not valid inside comparison");
3644 fatal ("Empty EQ_ATTR_ALT should be optimized out");
3646 if (!(set
& (set
- 1)))
3648 if (!(set
& 0xffff))
3671 fprintf (outf
, "which_alternative %s= %d",
3672 XINT (exp
, 1) ? "!" : "=", bit
);
3676 fprintf (outf
, "%s((1 << which_alternative) & %#x)",
3677 XINT (exp
, 1) ? "!" : "", set
);
3682 /* Comparison test of an attribute with a value. Most of these will
3683 have been removed by optimization. Handle "alternative"
3684 specially and give error if EQ_ATTR present inside a comparison. */
3686 if (flags
& FLG_BITWISE
)
3687 fatal ("EQ_ATTR not valid inside comparison");
3689 if (XSTR (exp
, 0) == alternative_name
)
3691 fprintf (outf
, "which_alternative == %s", XSTR (exp
, 1));
3695 attr
= find_attr (&XSTR (exp
, 0), 0);
3698 /* Now is the time to expand the value of a constant attribute. */
3701 write_test_expr (outf
,
3702 evaluate_eq_attr (exp
, attr
,
3703 attr
->default_val
->value
,
3710 for (i
= 0; i
< cached_attr_count
; i
++)
3711 if (attr
->name
== cached_attrs
[i
])
3713 if (i
< cached_attr_count
&& (attrs_cached
& (1U << i
)) != 0)
3714 fprintf (outf
, "cached_%s", attr
->name
);
3715 else if (i
< cached_attr_count
&& (attrs_to_cache
& (1U << i
)) != 0)
3717 fprintf (outf
, "(cached_%s = get_attr_%s (insn))",
3718 attr
->name
, attr
->name
);
3719 if (flags
& FLG_AFTER
)
3720 attrs_cached_after
|= (1U << i
);
3721 if (flags
& FLG_INSIDE
)
3722 attrs_cached_inside
|= (1U << i
);
3723 attrs_cached
|= (1U << i
);
3726 fprintf (outf
, "get_attr_%s (insn)", attr
->name
);
3727 fprintf (outf
, " == ");
3728 write_attr_valueq (outf
, attr
, XSTR (exp
, 1));
3732 /* Comparison test of flags for define_delays. */
3734 if (flags
& FLG_BITWISE
)
3735 fatal ("ATTR_FLAG not valid inside comparison");
3736 fprintf (outf
, "(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
3739 /* See if an operand matches a predicate. */
3741 /* If only a mode is given, just ensure the mode matches the operand.
3742 If neither a mode nor predicate is given, error. */
3743 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
3745 if (GET_MODE (exp
) == VOIDmode
)
3746 fatal ("null MATCH_OPERAND specified as test");
3748 fprintf (outf
, "GET_MODE (operands[%d]) == %smode",
3749 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3752 fprintf (outf
, "%s (operands[%d], %smode)",
3753 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3756 /* Constant integer. */
3758 fprintf (outf
, HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
3762 fprint_c_condition (outf
, XSTR (exp
, 0));
3763 if (flags
& FLG_BITWISE
)
3764 fprintf (outf
, " != 0");
3767 /* A random C expression. */
3769 fprint_c_condition (outf
, XSTR (exp
, 0));
3772 /* The address of the branch target. */
3775 "INSN_ADDRESSES_SET_P () ? INSN_ADDRESSES (INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])) : 0",
3776 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
3780 /* The address of the current insn. We implement this actually as the
3781 address of the current insn for backward branches, but the last
3782 address of the next insn for forward branches, and both with
3783 adjustments that account for the worst-case possible stretching of
3784 intervening alignments between this insn and its destination. */
3785 fprintf (outf
, "insn_current_reference_address (insn)");
3789 fprintf (outf
, "%s", XSTR (exp
, 0));
3793 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, 0);
3794 fprintf (outf
, " ? ");
3795 write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
, FLG_BITWISE
);
3796 fprintf (outf
, " : ");
3797 write_test_expr (outf
, XEXP (exp
, 2), attrs_cached
, FLG_BITWISE
);
3801 fatal ("bad RTX code `%s' in attribute calculation\n",
3802 GET_RTX_NAME (code
));
3805 fprintf (outf
, ")");
3806 return attrs_cached
;
3809 /* Given an attribute value, return the maximum CONST_STRING argument
3810 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
3813 max_attr_value (rtx exp
, int *unknownp
)
3818 switch (GET_CODE (exp
))
3821 current_max
= atoi (XSTR (exp
, 0));
3825 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
3826 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3828 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3829 if (n
> current_max
)
3835 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
3836 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
3837 if (n
> current_max
)
3843 current_max
= INT_MAX
;
3850 /* Given an attribute value, return the minimum CONST_STRING argument
3851 encountered. Set *UNKNOWNP and return 0 if the value is unknown. */
3854 min_attr_value (rtx exp
, int *unknownp
)
3859 switch (GET_CODE (exp
))
3862 current_min
= atoi (XSTR (exp
, 0));
3866 current_min
= min_attr_value (XEXP (exp
, 1), unknownp
);
3867 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3869 n
= min_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3870 if (n
< current_min
)
3876 current_min
= min_attr_value (XEXP (exp
, 1), unknownp
);
3877 n
= min_attr_value (XEXP (exp
, 2), unknownp
);
3878 if (n
< current_min
)
3884 current_min
= INT_MAX
;
3891 /* Given an attribute value, return the result of ORing together all
3892 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
3893 if the numeric value is not known. */
3896 or_attr_value (rtx exp
, int *unknownp
)
3901 switch (GET_CODE (exp
))
3904 current_or
= atoi (XSTR (exp
, 0));
3908 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
3909 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3910 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3914 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
3915 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
3927 /* Scan an attribute value, possibly a conditional, and record what actions
3928 will be required to do any conditional tests in it.
3931 `must_extract' if we need to extract the insn operands
3932 `must_constrain' if we must compute `which_alternative'
3933 `address_used' if an address expression was used
3934 `length_used' if an (eq_attr "length" ...) was used
3938 walk_attr_value (rtx exp
)
3947 code
= GET_CODE (exp
);
3951 if (! ATTR_IND_SIMPLIFIED_P (exp
))
3952 /* Since this is an arbitrary expression, it can look at anything.
3953 However, constant expressions do not depend on any particular
3955 must_extract
= must_constrain
= 1;
3964 must_extract
= must_constrain
= 1;
3968 if (XSTR (exp
, 0) == alternative_name
)
3969 must_extract
= must_constrain
= 1;
3970 else if (strcmp_check (XSTR (exp
, 0), length_str
) == 0)
3990 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
3995 walk_attr_value (XEXP (exp
, i
));
3999 if (XVEC (exp
, i
) != NULL
)
4000 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4001 walk_attr_value (XVECEXP (exp
, i
, j
));
4006 /* Write out a function to obtain the attribute for a given INSN. */
4009 write_attr_get (FILE *outf
, struct attr_desc
*attr
)
4011 struct attr_value
*av
, *common_av
;
4014 /* Find the most used attribute value. Handle that as the `default' of the
4015 switch we will generate. */
4016 common_av
= find_most_used (attr
);
4018 /* Write out start of function, then all values with explicit `case' lines,
4019 then a `default', then the value with the most uses. */
4020 if (attr
->enum_name
)
4021 fprintf (outf
, "enum %s\n", attr
->enum_name
);
4022 else if (!attr
->is_numeric
)
4023 fprintf (outf
, "enum attr_%s\n", attr
->name
);
4025 fprintf (outf
, "int\n");
4027 /* If the attribute name starts with a star, the remainder is the name of
4028 the subroutine to use, instead of `get_attr_...'. */
4029 if (attr
->name
[0] == '*')
4030 fprintf (outf
, "%s (rtx uncast_insn ATTRIBUTE_UNUSED)\n", &attr
->name
[1]);
4031 else if (attr
->is_const
== 0)
4032 fprintf (outf
, "get_attr_%s (rtx uncast_insn ATTRIBUTE_UNUSED)\n", attr
->name
);
4035 fprintf (outf
, "get_attr_%s (void)\n", attr
->name
);
4036 fprintf (outf
, "{\n");
4038 for (av
= attr
->first_value
; av
; av
= av
->next
)
4039 if (av
->num_insns
== 1)
4040 write_attr_set (outf
, attr
, 2, av
->value
, "return", ";",
4041 true_rtx
, av
->first_insn
->def
->insn_code
,
4042 av
->first_insn
->def
->insn_index
, 0);
4043 else if (av
->num_insns
!= 0)
4044 write_attr_set (outf
, attr
, 2, av
->value
, "return", ";",
4045 true_rtx
, -2, 0, 0);
4047 fprintf (outf
, "}\n\n");
4051 fprintf (outf
, "{\n");
4053 if (attr
->name
[0] == '*' || attr
->is_const
== 0)
4054 fprintf (outf
, " rtx_insn *insn = as_a <rtx_insn *> (uncast_insn);\n");
4056 /* Find attributes that are worth caching in the conditions. */
4057 cached_attr_count
= 0;
4058 attrs_seen_more_than_once
= 0;
4059 for (av
= attr
->first_value
; av
; av
= av
->next
)
4061 attrs_seen_once
= 0;
4062 find_attrs_to_cache (av
->value
, true);
4064 /* Remove those that aren't worth caching from the array. */
4065 for (i
= 0, j
= 0; i
< cached_attr_count
; i
++)
4066 if ((attrs_seen_more_than_once
& (1U << i
)) != 0)
4068 const char *name
= cached_attrs
[i
];
4069 struct attr_desc
*cached_attr
;
4071 cached_attrs
[j
] = name
;
4072 cached_attr
= find_attr (&name
, 0);
4073 gcc_assert (cached_attr
&& cached_attr
->is_const
== 0);
4074 if (cached_attr
->enum_name
)
4075 fprintf (outf
, " enum %s", cached_attr
->enum_name
);
4076 else if (!cached_attr
->is_numeric
)
4077 fprintf (outf
, " enum attr_%s", cached_attr
->name
);
4079 fprintf (outf
, " int");
4080 fprintf (outf
, " cached_%s ATTRIBUTE_UNUSED;\n", name
);
4083 cached_attr_count
= j
;
4084 if (cached_attr_count
)
4085 fprintf (outf
, "\n");
4087 fprintf (outf
, " switch (recog_memoized (insn))\n");
4088 fprintf (outf
, " {\n");
4090 for (av
= attr
->first_value
; av
; av
= av
->next
)
4091 if (av
!= common_av
)
4092 write_attr_case (outf
, attr
, av
, 1, "return", ";", 4, true_rtx
);
4094 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4095 fprintf (outf
, " }\n}\n\n");
4096 cached_attr_count
= 0;
4099 /* Given an AND tree of known true terms (because we are inside an `if' with
4100 that as the condition or are in an `else' clause) and an expression,
4101 replace any known true terms with TRUE. Use `simplify_and_tree' to do
4102 the bulk of the work. */
4105 eliminate_known_true (rtx known_true
, rtx exp
, int insn_code
, int insn_index
)
4109 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
4111 if (GET_CODE (known_true
) == AND
)
4113 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
4114 insn_code
, insn_index
);
4115 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
4116 insn_code
, insn_index
);
4121 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
4127 /* Write out a series of tests and assignment statements to perform tests and
4128 sets of an attribute value. We are passed an indentation amount and prefix
4129 and suffix strings to write around each attribute value (e.g., "return"
4133 write_attr_set (FILE *outf
, struct attr_desc
*attr
, int indent
, rtx value
,
4134 const char *prefix
, const char *suffix
, rtx known_true
,
4135 int insn_code
, int insn_index
, unsigned int attrs_cached
)
4137 if (GET_CODE (value
) == COND
)
4139 /* Assume the default value will be the default of the COND unless we
4140 find an always true expression. */
4141 rtx default_val
= XEXP (value
, 1);
4142 rtx our_known_true
= known_true
;
4147 if (cached_attr_count
)
4149 attrs_seen_once
= 0;
4150 attrs_seen_more_than_once
= 0;
4151 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4152 find_attrs_to_cache (XVECEXP (value
, 0, i
), false);
4153 attrs_to_cache
|= attrs_seen_more_than_once
;
4156 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4161 /* Reset our_known_true after some time to not accumulate
4162 too much cruft (slowing down genattrtab). */
4164 our_known_true
= known_true
;
4165 testexp
= eliminate_known_true (our_known_true
,
4166 XVECEXP (value
, 0, i
),
4167 insn_code
, insn_index
);
4168 newexp
= attr_rtx (NOT
, testexp
);
4169 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
4170 insn_code
, insn_index
);
4172 /* If the test expression is always true or if the next `known_true'
4173 expression is always false, this is the last case, so break
4174 out and let this value be the `else' case. */
4175 if (testexp
== true_rtx
|| newexp
== false_rtx
)
4177 default_val
= XVECEXP (value
, 0, i
+ 1);
4181 /* Compute the expression to pass to our recursive call as being
4183 inner_true
= insert_right_side (AND
, our_known_true
,
4184 testexp
, insn_code
, insn_index
);
4186 /* If this is always false, skip it. */
4187 if (inner_true
== false_rtx
)
4190 attrs_cached_inside
= attrs_cached
;
4191 attrs_cached_after
= attrs_cached
;
4192 write_indent (outf
, indent
);
4193 fprintf (outf
, "%sif ", first_if
? "" : "else ");
4195 write_test_expr (outf
, testexp
, attrs_cached
,
4196 (FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
));
4197 attrs_cached
= attrs_cached_after
;
4198 fprintf (outf
, "\n");
4199 write_indent (outf
, indent
+ 2);
4200 fprintf (outf
, "{\n");
4202 write_attr_set (outf
, attr
, indent
+ 4,
4203 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
4204 inner_true
, insn_code
, insn_index
,
4205 attrs_cached_inside
);
4206 write_indent (outf
, indent
+ 2);
4207 fprintf (outf
, "}\n");
4208 our_known_true
= newexp
;
4213 write_indent (outf
, indent
);
4214 fprintf (outf
, "else\n");
4215 write_indent (outf
, indent
+ 2);
4216 fprintf (outf
, "{\n");
4219 write_attr_set (outf
, attr
, first_if
? indent
: indent
+ 4, default_val
,
4220 prefix
, suffix
, our_known_true
, insn_code
, insn_index
,
4225 write_indent (outf
, indent
+ 2);
4226 fprintf (outf
, "}\n");
4231 write_indent (outf
, indent
);
4232 fprintf (outf
, "%s ", prefix
);
4233 write_attr_value (outf
, attr
, value
);
4234 fprintf (outf
, "%s\n", suffix
);
4238 /* Write a series of case statements for every instruction in list IE.
4239 INDENT is the amount of indentation to write before each case. */
4242 write_insn_cases (FILE *outf
, struct insn_ent
*ie
, int indent
)
4244 for (; ie
!= 0; ie
= ie
->next
)
4245 if (ie
->def
->insn_code
!= -1)
4247 write_indent (outf
, indent
);
4248 if (GET_CODE (ie
->def
->def
) == DEFINE_PEEPHOLE
)
4249 fprintf (outf
, "case %d: /* define_peephole, line %d */\n",
4250 ie
->def
->insn_code
, ie
->def
->lineno
);
4252 fprintf (outf
, "case %d: /* %s */\n",
4253 ie
->def
->insn_code
, XSTR (ie
->def
->def
, 0));
4257 /* Write out the computation for one attribute value. */
4260 write_attr_case (FILE *outf
, struct attr_desc
*attr
, struct attr_value
*av
,
4261 int write_case_lines
, const char *prefix
, const char *suffix
,
4262 int indent
, rtx known_true
)
4264 if (av
->num_insns
== 0)
4267 if (av
->has_asm_insn
)
4269 write_indent (outf
, indent
);
4270 fprintf (outf
, "case -1:\n");
4271 write_indent (outf
, indent
+ 2);
4272 fprintf (outf
, "if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
4273 write_indent (outf
, indent
+ 2);
4274 fprintf (outf
, " && asm_noperands (PATTERN (insn)) < 0)\n");
4275 write_indent (outf
, indent
+ 2);
4276 fprintf (outf
, " fatal_insn_not_found (insn);\n");
4279 if (write_case_lines
)
4280 write_insn_cases (outf
, av
->first_insn
, indent
);
4283 write_indent (outf
, indent
);
4284 fprintf (outf
, "default:\n");
4287 /* See what we have to do to output this value. */
4288 must_extract
= must_constrain
= address_used
= 0;
4289 walk_attr_value (av
->value
);
4293 write_indent (outf
, indent
+ 2);
4294 fprintf (outf
, "extract_constrain_insn_cached (insn);\n");
4296 else if (must_extract
)
4298 write_indent (outf
, indent
+ 2);
4299 fprintf (outf
, "extract_insn_cached (insn);\n");
4303 if (av
->num_insns
== 1)
4304 write_attr_set (outf
, attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4305 known_true
, av
->first_insn
->def
->insn_code
,
4306 av
->first_insn
->def
->insn_index
, 0);
4308 write_attr_set (outf
, attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4309 known_true
, -2, 0, 0);
4311 if (strncmp (prefix
, "return", 6))
4313 write_indent (outf
, indent
+ 2);
4314 fprintf (outf
, "break;\n");
4316 fprintf (outf
, "\n");
4319 /* Utilities to write in various forms. */
4322 write_attr_valueq (FILE *outf
, struct attr_desc
*attr
, const char *s
)
4324 if (attr
->is_numeric
)
4328 fprintf (outf
, "%d", num
);
4330 if (num
> 9 || num
< 0)
4331 fprintf (outf
, " /* %#x */", num
);
4335 write_upcase (outf
, attr
->enum_name
? attr
->enum_name
: attr
->name
);
4336 fprintf (outf
, "_");
4337 write_upcase (outf
, s
);
4342 write_attr_value (FILE *outf
, struct attr_desc
*attr
, rtx value
)
4346 switch (GET_CODE (value
))
4349 write_attr_valueq (outf
, attr
, XSTR (value
, 0));
4353 fprintf (outf
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (value
));
4357 fprint_c_condition (outf
, XSTR (value
, 0));
4362 struct attr_desc
*attr2
= find_attr (&XSTR (value
, 0), 0);
4363 if (attr
->enum_name
)
4364 fprintf (outf
, "(enum %s)", attr
->enum_name
);
4365 else if (!attr
->is_numeric
)
4366 fprintf (outf
, "(enum attr_%s)", attr
->name
);
4367 else if (!attr2
->is_numeric
)
4368 fprintf (outf
, "(int)");
4370 fprintf (outf
, "get_attr_%s (%s)", attr2
->name
,
4371 (attr2
->is_const
? "" : "insn"));
4392 write_attr_value (outf
, attr
, XEXP (value
, 0));
4396 write_attr_value (outf
, attr
, XEXP (value
, 1));
4405 write_upcase (FILE *outf
, const char *str
)
4409 /* The argument of TOUPPER should not have side effects. */
4410 fputc (TOUPPER (*str
), outf
);
4416 write_indent (FILE *outf
, int indent
)
4418 for (; indent
> 8; indent
-= 8)
4419 fprintf (outf
, "\t");
4421 for (; indent
; indent
--)
4422 fprintf (outf
, " ");
4425 /* Write a subroutine that is given an insn that requires a delay slot, a
4426 delay slot ordinal, and a candidate insn. It returns nonzero if the
4427 candidate can be placed in the specified delay slot of the insn.
4429 We can write as many as three subroutines. `eligible_for_delay'
4430 handles normal delay slots, `eligible_for_annul_true' indicates that
4431 the specified insn can be annulled if the branch is true, and likewise
4432 for `eligible_for_annul_false'.
4434 KIND is a string distinguishing these three cases ("delay", "annul_true",
4435 or "annul_false"). */
4438 write_eligible_delay (FILE *outf
, const char *kind
)
4440 struct delay_desc
*delay
;
4444 struct attr_desc
*attr
;
4445 struct attr_value
*av
, *common_av
;
4448 /* Compute the maximum number of delay slots required. We use the delay
4449 ordinal times this number plus one, plus the slot number as an index into
4450 the appropriate predicate to test. */
4452 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
4453 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
4454 max_slots
= XVECLEN (delay
->def
, 1) / 3;
4456 /* Write function prelude. */
4458 fprintf (outf
, "int\n");
4459 fprintf (outf
, "eligible_for_%s (rtx_insn *delay_insn ATTRIBUTE_UNUSED, int slot, \n"
4460 " rtx_insn *candidate_insn, int flags ATTRIBUTE_UNUSED)\n",
4462 fprintf (outf
, "{\n");
4463 fprintf (outf
, " rtx_insn *insn;\n");
4464 fprintf (outf
, "\n");
4465 fprintf (outf
, " gcc_assert (slot < %d);\n", max_slots
);
4466 fprintf (outf
, "\n");
4467 /* Allow dbr_schedule to pass labels, etc. This can happen if try_split
4468 converts a compound instruction into a loop. */
4469 fprintf (outf
, " if (!INSN_P (candidate_insn))\n");
4470 fprintf (outf
, " return 0;\n");
4471 fprintf (outf
, "\n");
4473 /* If more than one delay type, find out which type the delay insn is. */
4477 attr
= find_attr (&delay_type_str
, 0);
4479 common_av
= find_most_used (attr
);
4481 fprintf (outf
, " insn = delay_insn;\n");
4482 fprintf (outf
, " switch (recog_memoized (insn))\n");
4483 fprintf (outf
, " {\n");
4485 sprintf (str
, " * %d;\n break;", max_slots
);
4486 for (av
= attr
->first_value
; av
; av
= av
->next
)
4487 if (av
!= common_av
)
4488 write_attr_case (outf
, attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
4490 write_attr_case (outf
, attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
4491 fprintf (outf
, " }\n\n");
4493 /* Ensure matched. Otherwise, shouldn't have been called. */
4494 fprintf (outf
, " gcc_assert (slot >= %d);\n\n", max_slots
);
4497 /* If just one type of delay slot, write simple switch. */
4498 if (num_delays
== 1 && max_slots
== 1)
4500 fprintf (outf
, " insn = candidate_insn;\n");
4501 fprintf (outf
, " switch (recog_memoized (insn))\n");
4502 fprintf (outf
, " {\n");
4504 attr
= find_attr (&delay_1_0_str
, 0);
4506 common_av
= find_most_used (attr
);
4508 for (av
= attr
->first_value
; av
; av
= av
->next
)
4509 if (av
!= common_av
)
4510 write_attr_case (outf
, attr
, av
, 1, "return", ";", 4, true_rtx
);
4512 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4513 fprintf (outf
, " }\n");
4518 /* Write a nested CASE. The first indicates which condition we need to
4519 test, and the inner CASE tests the condition. */
4520 fprintf (outf
, " insn = candidate_insn;\n");
4521 fprintf (outf
, " switch (slot)\n");
4522 fprintf (outf
, " {\n");
4524 for (delay
= delays
; delay
; delay
= delay
->next
)
4525 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
4527 fprintf (outf
, " case %d:\n",
4528 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
4529 fprintf (outf
, " switch (recog_memoized (insn))\n");
4530 fprintf (outf
, "\t{\n");
4532 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
4534 attr
= find_attr (&pstr
, 0);
4536 common_av
= find_most_used (attr
);
4538 for (av
= attr
->first_value
; av
; av
= av
->next
)
4539 if (av
!= common_av
)
4540 write_attr_case (outf
, attr
, av
, 1, "return", ";", 8, true_rtx
);
4542 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 8, true_rtx
);
4543 fprintf (outf
, " }\n");
4546 fprintf (outf
, " default:\n");
4547 fprintf (outf
, " gcc_unreachable ();\n");
4548 fprintf (outf
, " }\n");
4551 fprintf (outf
, "}\n\n");
4554 /* This page contains miscellaneous utility routines. */
4556 /* Given a pointer to a (char *), return a malloc'ed string containing the
4557 next comma-separated element. Advance the pointer to after the string
4558 scanned, or the end-of-string. Return NULL if at end of string. */
4561 next_comma_elt (const char **pstr
)
4565 start
= scan_comma_elt (pstr
);
4570 return attr_string (start
, *pstr
- start
);
4573 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
4574 is nonzero, build a new attribute, if one does not exist. *NAME_P is
4575 replaced by a pointer to a canonical copy of the string. */
4577 static struct attr_desc
*
4578 find_attr (const char **name_p
, int create
)
4580 struct attr_desc
*attr
;
4582 const char *name
= *name_p
;
4584 /* Before we resort to using `strcmp', see if the string address matches
4585 anywhere. In most cases, it should have been canonicalized to do so. */
4586 if (name
== alternative_name
)
4589 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
4590 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4591 if (name
== attr
->name
)
4594 /* Otherwise, do it the slow way. */
4595 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4596 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
4598 *name_p
= attr
->name
;
4605 attr
= oballoc (struct attr_desc
);
4606 attr
->name
= DEF_ATTR_STRING (name
);
4607 attr
->enum_name
= 0;
4608 attr
->first_value
= attr
->default_val
= NULL
;
4609 attr
->is_numeric
= attr
->is_const
= attr
->is_special
= 0;
4610 attr
->next
= attrs
[index
];
4611 attrs
[index
] = attr
;
4613 *name_p
= attr
->name
;
4618 /* Create internal attribute with the given default value. */
4621 make_internal_attr (const char *name
, rtx value
, int special
)
4623 struct attr_desc
*attr
;
4625 attr
= find_attr (&name
, 1);
4626 gcc_assert (!attr
->default_val
);
4628 attr
->is_numeric
= 1;
4630 attr
->is_special
= (special
& ATTR_SPECIAL
) != 0;
4631 attr
->default_val
= get_attr_value (value
, attr
, -2);
4634 /* Find the most used value of an attribute. */
4636 static struct attr_value
*
4637 find_most_used (struct attr_desc
*attr
)
4639 struct attr_value
*av
;
4640 struct attr_value
*most_used
;
4646 for (av
= attr
->first_value
; av
; av
= av
->next
)
4647 if (av
->num_insns
> nuses
)
4648 nuses
= av
->num_insns
, most_used
= av
;
4653 /* Return (attr_value "n") */
4656 make_numeric_value (int n
)
4658 static rtx int_values
[20];
4662 gcc_assert (n
>= 0);
4664 if (n
< 20 && int_values
[n
])
4665 return int_values
[n
];
4667 p
= attr_printf (MAX_DIGITS
, "%d", n
);
4668 exp
= attr_rtx (CONST_STRING
, p
);
4671 int_values
[n
] = exp
;
4677 copy_rtx_unchanging (rtx orig
)
4679 if (ATTR_IND_SIMPLIFIED_P (orig
) || ATTR_CURR_SIMPLIFIED_P (orig
))
4682 ATTR_CURR_SIMPLIFIED_P (orig
) = 1;
4686 /* Determine if an insn has a constant number of delay slots, i.e., the
4687 number of delay slots is not a function of the length of the insn. */
4690 write_const_num_delay_slots (FILE *outf
)
4692 struct attr_desc
*attr
= find_attr (&num_delay_slots_str
, 0);
4693 struct attr_value
*av
;
4697 fprintf (outf
, "int\nconst_num_delay_slots (rtx insn)\n");
4698 fprintf (outf
, "{\n");
4699 fprintf (outf
, " switch (recog_memoized (insn))\n");
4700 fprintf (outf
, " {\n");
4702 for (av
= attr
->first_value
; av
; av
= av
->next
)
4705 walk_attr_value (av
->value
);
4707 write_insn_cases (outf
, av
->first_insn
, 4);
4710 fprintf (outf
, " default:\n");
4711 fprintf (outf
, " return 1;\n");
4712 fprintf (outf
, " }\n}\n\n");
4716 /* Synthetic attributes used by insn-automata.c and the scheduler.
4717 These are primarily concerned with (define_insn_reservation)
4722 struct insn_reserv
*next
;
4725 int default_latency
;
4728 /* Sequence number of this insn. */
4731 /* Whether a (define_bypass) construct names this insn in its
4736 static struct insn_reserv
*all_insn_reservs
= 0;
4737 static struct insn_reserv
**last_insn_reserv_p
= &all_insn_reservs
;
4738 static size_t n_insn_reservs
;
4740 /* Store information from a DEFINE_INSN_RESERVATION for future
4741 attribute generation. */
4743 gen_insn_reserv (rtx def
)
4745 struct insn_reserv
*decl
= oballoc (struct insn_reserv
);
4747 decl
->name
= DEF_ATTR_STRING (XSTR (def
, 0));
4748 decl
->default_latency
= XINT (def
, 1);
4749 decl
->condexp
= check_attr_test (XEXP (def
, 2), 0, 0);
4750 decl
->insn_num
= n_insn_reservs
;
4751 decl
->bypassed
= false;
4754 *last_insn_reserv_p
= decl
;
4755 last_insn_reserv_p
= &decl
->next
;
4759 /* Store information from a DEFINE_BYPASS for future attribute
4760 generation. The only thing we care about is the list of output
4761 insns, which will later be used to tag reservation structures with
4762 a 'bypassed' bit. */
4766 struct bypass_list
*next
;
4767 const char *pattern
;
4770 static struct bypass_list
*all_bypasses
;
4771 static size_t n_bypasses
;
4772 static size_t n_bypassed
;
4775 gen_bypass_1 (const char *s
, size_t len
)
4777 struct bypass_list
*b
;
4782 s
= attr_string (s
, len
);
4783 for (b
= all_bypasses
; b
; b
= b
->next
)
4784 if (s
== b
->pattern
)
4785 return; /* already got that one */
4787 b
= oballoc (struct bypass_list
);
4789 b
->next
= all_bypasses
;
4795 gen_bypass (rtx def
)
4797 const char *p
, *base
;
4799 for (p
= base
= XSTR (def
, 1); *p
; p
++)
4802 gen_bypass_1 (base
, p
- base
);
4805 while (ISSPACE (*p
));
4808 gen_bypass_1 (base
, p
- base
);
4811 /* Find and mark all of the bypassed insns. */
4813 process_bypasses (void)
4815 struct bypass_list
*b
;
4816 struct insn_reserv
*r
;
4820 /* The reservation list is likely to be much longer than the bypass
4822 for (r
= all_insn_reservs
; r
; r
= r
->next
)
4823 for (b
= all_bypasses
; b
; b
= b
->next
)
4824 if (fnmatch (b
->pattern
, r
->name
, 0) == 0)
4832 /* Check that attribute NAME is used in define_insn_reservation condition
4833 EXP. Return true if it is. */
4835 check_tune_attr (const char *name
, rtx exp
)
4837 switch (GET_CODE (exp
))
4840 if (check_tune_attr (name
, XEXP (exp
, 0)))
4842 return check_tune_attr (name
, XEXP (exp
, 1));
4845 return (check_tune_attr (name
, XEXP (exp
, 0))
4846 && check_tune_attr (name
, XEXP (exp
, 1)));
4849 return XSTR (exp
, 0) == name
;
4856 /* Try to find a const attribute (usually cpu or tune) that is used
4857 in all define_insn_reservation conditions. */
4858 static struct attr_desc
*
4859 find_tune_attr (rtx exp
)
4861 struct attr_desc
*attr
;
4863 switch (GET_CODE (exp
))
4867 attr
= find_tune_attr (XEXP (exp
, 0));
4870 return find_tune_attr (XEXP (exp
, 1));
4873 if (XSTR (exp
, 0) == alternative_name
)
4876 attr
= find_attr (&XSTR (exp
, 0), 0);
4879 if (attr
->is_const
&& !attr
->is_special
)
4881 struct insn_reserv
*decl
;
4883 for (decl
= all_insn_reservs
; decl
; decl
= decl
->next
)
4884 if (! check_tune_attr (attr
->name
, decl
->condexp
))
4895 /* Create all of the attributes that describe automaton properties.
4896 Write the DFA and latency function prototypes to the files that
4897 need to have them, and write the init_sched_attrs(). */
4900 make_automaton_attrs (void)
4903 struct insn_reserv
*decl
;
4904 rtx code_exp
, lats_exp
, byps_exp
;
4905 struct attr_desc
*tune_attr
;
4907 if (n_insn_reservs
== 0)
4910 tune_attr
= find_tune_attr (all_insn_reservs
->condexp
);
4911 if (tune_attr
!= NULL
)
4913 rtx
*condexps
= XNEWVEC (rtx
, n_insn_reservs
* 3);
4914 struct attr_value
*val
;
4917 gcc_assert (tune_attr
->is_const
4918 && !tune_attr
->is_special
4919 && !tune_attr
->is_numeric
);
4921 /* Write the prototypes for all DFA functions. */
4922 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4924 if (val
== tune_attr
->default_val
)
4926 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4928 "extern int internal_dfa_insn_code_%s (rtx);\n",
4929 XSTR (val
->value
, 0));
4931 fprintf (dfa_file
, "\n");
4933 /* Write the prototypes for all latency functions. */
4934 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4936 if (val
== tune_attr
->default_val
)
4938 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4939 fprintf (latency_file
,
4940 "extern int insn_default_latency_%s (rtx);\n",
4941 XSTR (val
->value
, 0));
4943 fprintf (latency_file
, "\n");
4945 /* Write the prototypes for all automaton functions. */
4946 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4948 if (val
== tune_attr
->default_val
)
4950 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4952 "extern int internal_dfa_insn_code_%s (rtx);\n"
4953 "extern int insn_default_latency_%s (rtx);\n",
4954 XSTR (val
->value
, 0), XSTR (val
->value
, 0));
4956 fprintf (attr_file
, "\n");
4957 fprintf (attr_file
, "int (*internal_dfa_insn_code) (rtx);\n");
4958 fprintf (attr_file
, "int (*insn_default_latency) (rtx);\n");
4959 fprintf (attr_file
, "\n");
4960 fprintf (attr_file
, "void\n");
4961 fprintf (attr_file
, "init_sched_attrs (void)\n");
4962 fprintf (attr_file
, "{\n");
4964 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4968 rtx test
= attr_rtx (EQ_ATTR
, tune_attr
->name
, XSTR (val
->value
, 0));
4970 if (val
== tune_attr
->default_val
)
4972 for (decl
= all_insn_reservs
, i
= 0;
4978 = simplify_and_tree (decl
->condexp
, &ctest
, -2, 0);
4979 if (condexp
== false_rtx
)
4981 if (condexp
== true_rtx
)
4983 condexps
[i
] = condexp
;
4984 condexps
[i
+ 1] = make_numeric_value (decl
->insn_num
);
4985 condexps
[i
+ 2] = make_numeric_value (decl
->default_latency
);
4989 code_exp
= rtx_alloc (COND
);
4990 lats_exp
= rtx_alloc (COND
);
4993 XVEC (code_exp
, 0) = rtvec_alloc (j
);
4994 XVEC (lats_exp
, 0) = rtvec_alloc (j
);
4998 XEXP (code_exp
, 1) = make_numeric_value (decl
->insn_num
);
4999 XEXP (lats_exp
, 1) = make_numeric_value (decl
->default_latency
);
5003 XEXP (code_exp
, 1) = make_numeric_value (n_insn_reservs
+ 1);
5004 XEXP (lats_exp
, 1) = make_numeric_value (0);
5011 XVECEXP (code_exp
, 0, j
) = condexps
[i
];
5012 XVECEXP (lats_exp
, 0, j
) = condexps
[i
];
5014 XVECEXP (code_exp
, 0, j
+ 1) = condexps
[i
+ 1];
5015 XVECEXP (lats_exp
, 0, j
+ 1) = condexps
[i
+ 2];
5018 name
= XNEWVEC (char,
5019 sizeof ("*internal_dfa_insn_code_")
5020 + strlen (XSTR (val
->value
, 0)));
5021 strcpy (name
, "*internal_dfa_insn_code_");
5022 strcat (name
, XSTR (val
->value
, 0));
5023 make_internal_attr (name
, code_exp
, ATTR_NONE
);
5024 strcpy (name
, "*insn_default_latency_");
5025 strcat (name
, XSTR (val
->value
, 0));
5026 make_internal_attr (name
, lats_exp
, ATTR_NONE
);
5031 fprintf (attr_file
, " if (");
5035 fprintf (attr_file
, " else if (");
5036 write_test_expr (attr_file
, test
, 0, 0);
5037 fprintf (attr_file
, ")\n");
5038 fprintf (attr_file
, " {\n");
5039 fprintf (attr_file
, " internal_dfa_insn_code\n");
5040 fprintf (attr_file
, " = internal_dfa_insn_code_%s;\n",
5041 XSTR (val
->value
, 0));
5042 fprintf (attr_file
, " insn_default_latency\n");
5043 fprintf (attr_file
, " = insn_default_latency_%s;\n",
5044 XSTR (val
->value
, 0));
5045 fprintf (attr_file
, " }\n");
5048 fprintf (attr_file
, " else\n");
5049 fprintf (attr_file
, " gcc_unreachable ();\n");
5050 fprintf (attr_file
, "}\n");
5051 fprintf (attr_file
, "\n");
5053 XDELETEVEC (condexps
);
5057 code_exp
= rtx_alloc (COND
);
5058 lats_exp
= rtx_alloc (COND
);
5060 XVEC (code_exp
, 0) = rtvec_alloc (n_insn_reservs
* 2);
5061 XVEC (lats_exp
, 0) = rtvec_alloc (n_insn_reservs
* 2);
5063 XEXP (code_exp
, 1) = make_numeric_value (n_insn_reservs
+ 1);
5064 XEXP (lats_exp
, 1) = make_numeric_value (0);
5066 for (decl
= all_insn_reservs
, i
= 0;
5068 decl
= decl
->next
, i
+= 2)
5070 XVECEXP (code_exp
, 0, i
) = decl
->condexp
;
5071 XVECEXP (lats_exp
, 0, i
) = decl
->condexp
;
5073 XVECEXP (code_exp
, 0, i
+1) = make_numeric_value (decl
->insn_num
);
5074 XVECEXP (lats_exp
, 0, i
+1)
5075 = make_numeric_value (decl
->default_latency
);
5077 make_internal_attr ("*internal_dfa_insn_code", code_exp
, ATTR_NONE
);
5078 make_internal_attr ("*insn_default_latency", lats_exp
, ATTR_NONE
);
5081 if (n_bypasses
== 0)
5082 byps_exp
= make_numeric_value (0);
5085 process_bypasses ();
5087 byps_exp
= rtx_alloc (COND
);
5088 XVEC (byps_exp
, 0) = rtvec_alloc (n_bypassed
* 2);
5089 XEXP (byps_exp
, 1) = make_numeric_value (0);
5090 for (decl
= all_insn_reservs
, i
= 0;
5095 XVECEXP (byps_exp
, 0, i
) = decl
->condexp
;
5096 XVECEXP (byps_exp
, 0, i
+1) = make_numeric_value (1);
5101 make_internal_attr ("*bypass_p", byps_exp
, ATTR_NONE
);
5105 write_header (FILE *outf
)
5107 fprintf (outf
, "/* Generated automatically by the program `genattrtab'\n"
5108 " from the machine description file `md'. */\n\n");
5110 fprintf (outf
, "#include \"config.h\"\n");
5111 fprintf (outf
, "#include \"system.h\"\n");
5112 fprintf (outf
, "#include \"coretypes.h\"\n");
5113 fprintf (outf
, "#include \"tm.h\"\n");
5114 fprintf (outf
, "#include \"tree.h\"\n");
5115 fprintf (outf
, "#include \"varasm.h\"\n");
5116 fprintf (outf
, "#include \"stor-layout.h\"\n");
5117 fprintf (outf
, "#include \"calls.h\"\n");
5118 fprintf (outf
, "#include \"rtl.h\"\n");
5119 fprintf (outf
, "#include \"insn-attr.h\"\n");
5120 fprintf (outf
, "#include \"tm_p.h\"\n");
5121 fprintf (outf
, "#include \"insn-config.h\"\n");
5122 fprintf (outf
, "#include \"recog.h\"\n");
5123 fprintf (outf
, "#include \"regs.h\"\n");
5124 fprintf (outf
, "#include \"real.h\"\n");
5125 fprintf (outf
, "#include \"output.h\"\n");
5126 fprintf (outf
, "#include \"toplev.h\"\n");
5127 fprintf (outf
, "#include \"flags.h\"\n");
5128 fprintf (outf
, "#include \"function.h\"\n");
5129 fprintf (outf
, "\n");
5130 fprintf (outf
, "#define operands recog_data.operand\n\n");
5134 open_outfile (const char *file_name
)
5137 outf
= fopen (file_name
, "w");
5139 fatal ("cannot open file %s: %s", file_name
, xstrerror (errno
));
5140 write_header (outf
);
5145 handle_arg (const char *arg
)
5150 attr_file_name
= &arg
[2];
5153 dfa_file_name
= &arg
[2];
5156 latency_file_name
= &arg
[2];
5164 main (int argc
, char **argv
)
5167 struct attr_desc
*attr
;
5168 struct insn_def
*id
;
5172 progname
= "genattrtab";
5174 if (!init_rtx_reader_args_cb (argc
, argv
, handle_arg
))
5175 return FATAL_EXIT_CODE
;
5177 attr_file
= open_outfile (attr_file_name
);
5178 dfa_file
= open_outfile (dfa_file_name
);
5179 latency_file
= open_outfile (latency_file_name
);
5181 obstack_init (hash_obstack
);
5182 obstack_init (temp_obstack
);
5184 /* Set up true and false rtx's */
5185 true_rtx
= rtx_alloc (CONST_INT
);
5186 XWINT (true_rtx
, 0) = 1;
5187 false_rtx
= rtx_alloc (CONST_INT
);
5188 XWINT (false_rtx
, 0) = 0;
5189 ATTR_IND_SIMPLIFIED_P (true_rtx
) = ATTR_IND_SIMPLIFIED_P (false_rtx
) = 1;
5190 ATTR_PERMANENT_P (true_rtx
) = ATTR_PERMANENT_P (false_rtx
) = 1;
5192 alternative_name
= DEF_ATTR_STRING ("alternative");
5193 length_str
= DEF_ATTR_STRING ("length");
5194 delay_type_str
= DEF_ATTR_STRING ("*delay_type");
5195 delay_1_0_str
= DEF_ATTR_STRING ("*delay_1_0");
5196 num_delay_slots_str
= DEF_ATTR_STRING ("*num_delay_slots");
5198 /* Read the machine description. */
5204 desc
= read_md_rtx (&lineno
, &insn_code_number
);
5208 switch (GET_CODE (desc
))
5211 case DEFINE_PEEPHOLE
:
5212 case DEFINE_ASM_ATTRIBUTES
:
5213 gen_insn (desc
, lineno
);
5217 case DEFINE_ENUM_ATTR
:
5218 gen_attr (desc
, lineno
);
5222 gen_delay (desc
, lineno
);
5225 case DEFINE_INSN_RESERVATION
:
5226 gen_insn_reserv (desc
);
5236 if (GET_CODE (desc
) != DEFINE_ASM_ATTRIBUTES
)
5237 insn_index_number
++;
5241 return FATAL_EXIT_CODE
;
5245 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
5246 if (! got_define_asm_attributes
)
5248 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
5249 XVEC (tem
, 0) = rtvec_alloc (0);
5253 /* Expand DEFINE_DELAY information into new attribute. */
5257 /* Make `insn_alternatives'. */
5258 insn_alternatives
= oballocvec (int, insn_code_number
);
5259 for (id
= defs
; id
; id
= id
->next
)
5260 if (id
->insn_code
>= 0)
5261 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
5263 /* Make `insn_n_alternatives'. */
5264 insn_n_alternatives
= oballocvec (int, insn_code_number
);
5265 for (id
= defs
; id
; id
= id
->next
)
5266 if (id
->insn_code
>= 0)
5267 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
5269 /* Construct extra attributes for automata. */
5270 make_automaton_attrs ();
5272 /* Prepare to write out attribute subroutines by checking everything stored
5273 away and building the attribute cases. */
5277 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5278 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5279 attr
->default_val
->value
5280 = check_attr_value (attr
->default_val
->value
, attr
);
5283 return FATAL_EXIT_CODE
;
5285 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5286 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5289 /* Construct extra attributes for `length'. */
5290 make_length_attrs ();
5292 /* Perform any possible optimizations to speed up compilation. */
5295 /* Now write out all the `gen_attr_...' routines. Do these before the
5296 special routines so that they get defined before they are used. */
5298 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5299 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5303 #define IS_ATTR_GROUP(X) (!strncmp (attr->name, X, strlen (X)))
5304 if (IS_ATTR_GROUP ("*internal_dfa_insn_code"))
5306 else if (IS_ATTR_GROUP ("*insn_default_latency"))
5307 outf
= latency_file
;
5310 #undef IS_ATTR_GROUP
5312 if (! attr
->is_special
&& ! attr
->is_const
)
5313 write_attr_get (outf
, attr
);
5316 /* Write out delay eligibility information, if DEFINE_DELAY present.
5317 (The function to compute the number of delay slots will be written
5321 write_eligible_delay (attr_file
, "delay");
5322 if (have_annul_true
)
5323 write_eligible_delay (attr_file
, "annul_true");
5324 if (have_annul_false
)
5325 write_eligible_delay (attr_file
, "annul_false");
5328 /* Write out constant delay slot info. */
5329 write_const_num_delay_slots (attr_file
);
5331 write_length_unit_log (attr_file
);
5333 if (fclose (attr_file
) != 0)
5334 fatal ("cannot close file %s: %s", attr_file_name
, xstrerror (errno
));
5335 if (fclose (dfa_file
) != 0)
5336 fatal ("cannot close file %s: %s", dfa_file_name
, xstrerror (errno
));
5337 if (fclose (latency_file
) != 0)
5338 fatal ("cannot close file %s: %s", latency_file_name
, xstrerror (errno
));
5340 return SUCCESS_EXIT_CODE
;