1 /* Generate code from machine description to compute values of attributes.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012
4 Free Software Foundation, Inc.
5 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* This program handles insn attributes and the DEFINE_DELAY and
24 DEFINE_INSN_RESERVATION definitions.
26 It produces a series of functions named `get_attr_...', one for each insn
27 attribute. Each of these is given the rtx for an insn and returns a member
28 of the enum for the attribute.
30 These subroutines have the form of a `switch' on the INSN_CODE (via
31 `recog_memoized'). Each case either returns a constant attribute value
32 or a value that depends on tests on other attributes, the form of
33 operands, or some random C expression (encoded with a SYMBOL_REF
36 If the attribute `alternative', or a random C expression is present,
37 `constrain_operands' is called. If either of these cases of a reference to
38 an operand is found, `extract_insn' is called.
40 The special attribute `length' is also recognized. For this operand,
41 expressions involving the address of an operand or the current insn,
42 (address (pc)), are valid. In this case, an initial pass is made to
43 set all lengths that do not depend on address. Those that do are set to
44 the maximum length. Then each insn that depends on an address is checked
45 and possibly has its length changed. The process repeats until no further
46 changed are made. The resulting lengths are saved for use by
49 A special form of DEFINE_ATTR, where the expression for default value is a
50 CONST expression, indicates an attribute that is constant for a given run
51 of the compiler. The subroutine generated for these attributes has no
52 parameters as it does not depend on any particular insn. Constant
53 attributes are typically used to specify which variety of processor is
56 Internal attributes are defined to handle DEFINE_DELAY and
57 DEFINE_INSN_RESERVATION. Special routines are output for these cases.
59 This program works by keeping a list of possible values for each attribute.
60 These include the basic attribute choices, default values for attribute, and
61 all derived quantities.
63 As the description file is read, the definition for each insn is saved in a
64 `struct insn_def'. When the file reading is complete, a `struct insn_ent'
65 is created for each insn and chained to the corresponding attribute value,
66 either that specified, or the default.
68 An optimization phase is then run. This simplifies expressions for each
69 insn. EQ_ATTR tests are resolved, whenever possible, to a test that
70 indicates when the attribute has the specified value for the insn. This
71 avoids recursive calls during compilation.
73 The strategy used when processing DEFINE_DELAY definitions is to create
74 arbitrarily complex expressions and have the optimization simplify them.
76 Once optimization is complete, any required routines and definitions
79 An optimization that is not yet implemented is to hoist the constant
80 expressions entirely out of the routines and definitions that are written.
81 A way to do this is to iterate over all possible combinations of values
82 for constant attributes and generate a set of functions for that given
83 combination. An initialization function would be written that evaluates
84 the attributes and installs the corresponding set of routines and
85 definitions (each would be accessed through a pointer).
87 We use the flags in an RTX as follows:
88 `unchanging' (ATTR_IND_SIMPLIFIED_P): This rtx is fully simplified
89 independent of the insn code.
90 `in_struct' (ATTR_CURR_SIMPLIFIED_P): This rtx is fully simplified
91 for the insn code currently being processed (see optimize_attrs).
92 `return_val' (ATTR_PERMANENT_P): This rtx is permanent and unique
95 #define ATTR_IND_SIMPLIFIED_P(RTX) (RTX_FLAG((RTX), unchanging))
96 #define ATTR_CURR_SIMPLIFIED_P(RTX) (RTX_FLAG((RTX), in_struct))
97 #define ATTR_PERMANENT_P(RTX) (RTX_FLAG((RTX), return_val))
100 #define strcmp_check(S1, S2) ((S1) == (S2) \
102 : (gcc_assert (strcmp ((S1), (S2))), 1))
104 #define strcmp_check(S1, S2) ((S1) != (S2))
109 #include "coretypes.h"
115 #include "gensupport.h"
121 /* Flags for make_internal_attr's `special' parameter. */
123 #define ATTR_SPECIAL (1 << 0)
125 static struct obstack obstack1
, obstack2
;
126 static struct obstack
*hash_obstack
= &obstack1
;
127 static struct obstack
*temp_obstack
= &obstack2
;
129 /* enough space to reserve for printing out ints */
130 #define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
132 /* Define structures used to record attributes and values. */
134 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
135 encountered, we store all the relevant information into a
136 `struct insn_def'. This is done to allow attribute definitions to occur
137 anywhere in the file. */
141 struct insn_def
*next
; /* Next insn in chain. */
142 rtx def
; /* The DEFINE_... */
143 int insn_code
; /* Instruction number. */
144 int insn_index
; /* Expression number in file, for errors. */
145 int lineno
; /* Line number. */
146 int num_alternatives
; /* Number of alternatives. */
147 int vec_idx
; /* Index of attribute vector in `def'. */
150 /* Once everything has been read in, we store in each attribute value a list
151 of insn codes that have that value. Here is the structure used for the
156 struct insn_ent
*next
; /* Next in chain. */
157 struct insn_def
*def
; /* Instruction definition. */
160 /* Each value of an attribute (either constant or computed) is assigned a
161 structure which is used as the listhead of the insns that have that
166 rtx value
; /* Value of attribute. */
167 struct attr_value
*next
; /* Next attribute value in chain. */
168 struct insn_ent
*first_insn
; /* First insn with this value. */
169 int num_insns
; /* Number of insns with this value. */
170 int has_asm_insn
; /* True if this value used for `asm' insns */
173 /* Structure for each attribute. */
177 char *name
; /* Name of attribute. */
178 const char *enum_name
; /* Enum name for DEFINE_ENUM_NAME. */
179 struct attr_desc
*next
; /* Next attribute. */
180 struct attr_value
*first_value
; /* First value of this attribute. */
181 struct attr_value
*default_val
; /* Default value for this attribute. */
182 int lineno
: 24; /* Line number. */
183 unsigned is_numeric
: 1; /* Values of this attribute are numeric. */
184 unsigned is_const
: 1; /* Attribute value constant for each run. */
185 unsigned is_special
: 1; /* Don't call `write_attr_set'. */
188 /* Structure for each DEFINE_DELAY. */
192 rtx def
; /* DEFINE_DELAY expression. */
193 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
194 int num
; /* Number of DEFINE_DELAY, starting at 1. */
195 int lineno
; /* Line number. */
198 struct attr_value_list
200 struct attr_value
*av
;
202 struct attr_desc
*attr
;
203 struct attr_value_list
*next
;
206 /* Listheads of above structures. */
208 /* This one is indexed by the first character of the attribute name. */
209 #define MAX_ATTRS_INDEX 256
210 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
211 static struct insn_def
*defs
;
212 static struct delay_desc
*delays
;
213 struct attr_value_list
**insn_code_values
;
215 /* Other variables. */
217 static int insn_code_number
;
218 static int insn_index_number
;
219 static int got_define_asm_attributes
;
220 static int must_extract
;
221 static int must_constrain
;
222 static int address_used
;
223 static int length_used
;
224 static int num_delays
;
225 static int have_annul_true
, have_annul_false
;
226 static int num_insn_ents
;
228 /* Stores, for each insn code, the number of constraint alternatives. */
230 static int *insn_n_alternatives
;
232 /* Stores, for each insn code, a bitmap that has bits on for each possible
235 static int *insn_alternatives
;
237 /* Used to simplify expressions. */
239 static rtx true_rtx
, false_rtx
;
241 /* Used to reduce calls to `strcmp' */
243 static const char *alternative_name
;
244 static const char *length_str
;
245 static const char *delay_type_str
;
246 static const char *delay_1_0_str
;
247 static const char *num_delay_slots_str
;
249 /* Simplify an expression. Only call the routine if there is something to
251 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
252 (ATTR_IND_SIMPLIFIED_P (EXP) || ATTR_CURR_SIMPLIFIED_P (EXP) ? (EXP) \
253 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
255 #define DEF_ATTR_STRING(S) (attr_string ((S), strlen (S)))
257 /* Forward declarations of functions used before their definitions, only. */
258 static char *attr_string (const char *, int);
259 static char *attr_printf (unsigned int, const char *, ...)
261 static rtx
make_numeric_value (int);
262 static struct attr_desc
*find_attr (const char **, int);
263 static rtx
mk_attr_alt (int);
264 static char *next_comma_elt (const char **);
265 static rtx
insert_right_side (enum rtx_code
, rtx
, rtx
, int, int);
266 static rtx
copy_boolean (rtx
);
267 static int compares_alternatives_p (rtx
);
268 static void make_internal_attr (const char *, rtx
, int);
269 static void insert_insn_ent (struct attr_value
*, struct insn_ent
*);
270 static void walk_attr_value (rtx
);
271 static int max_attr_value (rtx
, int*);
272 static int min_attr_value (rtx
, int*);
273 static int or_attr_value (rtx
, int*);
274 static rtx
simplify_test_exp (rtx
, int, int);
275 static rtx
simplify_test_exp_in_temp (rtx
, int, int);
276 static rtx
copy_rtx_unchanging (rtx
);
277 static bool attr_alt_subset_p (rtx
, rtx
);
278 static bool attr_alt_subset_of_compl_p (rtx
, rtx
);
279 static void clear_struct_flag (rtx
);
280 static void write_attr_valueq (FILE *, struct attr_desc
*, const char *);
281 static struct attr_value
*find_most_used (struct attr_desc
*);
282 static void write_attr_set (FILE *, struct attr_desc
*, int, rtx
,
283 const char *, const char *, rtx
,
284 int, int, unsigned int);
285 static void write_attr_case (FILE *, struct attr_desc
*,
287 int, const char *, const char *, int, rtx
);
288 static void write_attr_value (FILE *, struct attr_desc
*, rtx
);
289 static void write_upcase (FILE *, const char *);
290 static void write_indent (FILE *, int);
291 static rtx
identity_fn (rtx
);
292 static rtx
zero_fn (rtx
);
293 static rtx
one_fn (rtx
);
294 static rtx
max_fn (rtx
);
295 static rtx
min_fn (rtx
);
297 #define oballoc(T) XOBNEW (hash_obstack, T)
298 #define oballocvec(T, N) XOBNEWVEC (hash_obstack, T, (N))
300 /* This gen* file is unique, in that it writes out multiple files.
302 Before GCC 4.8, insn-attrtab.c was written out containing many large
303 functions and tables. This made insn-attrtab.c _the_ bottle-neck in
304 a parallel build, and even made it impossible to build GCC on machines
305 with relatively small RAM space (PR other/29442). Therefore, the
306 atrribute functions/tables are now written out to three separate
307 files: all "*insn_default_latency" functions go to LATENCY_FILE_NAME,
308 all "*internal_dfa_insn_code" functions go to DFA_FILE_NAME, and the
309 rest goes to ATTR_FILE_NAME. */
311 static const char *attr_file_name
= NULL
;
312 static const char *dfa_file_name
= NULL
;
313 static const char *latency_file_name
= NULL
;
315 static FILE *attr_file
, *dfa_file
, *latency_file
;
317 /* Hash table for sharing RTL and strings. */
319 /* Each hash table slot is a bucket containing a chain of these structures.
320 Strings are given negative hash codes; RTL expressions are given positive
325 struct attr_hash
*next
; /* Next structure in the bucket. */
326 int hashcode
; /* Hash code of this rtx or string. */
329 char *str
; /* The string (negative hash codes) */
330 rtx rtl
; /* or the RTL recorded here. */
334 /* Now here is the hash table. When recording an RTL, it is added to
335 the slot whose index is the hash code mod the table size. Note
336 that the hash table is used for several kinds of RTL (see attr_rtx)
337 and for strings. While all these live in the same table, they are
338 completely independent, and the hash code is computed differently
341 #define RTL_HASH_SIZE 4093
342 static struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
344 /* Here is how primitive or already-shared RTL's hash
346 #define RTL_HASH(RTL) ((intptr_t) (RTL) & 0777777)
348 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
351 attr_hash_add_rtx (int hashcode
, rtx rtl
)
355 h
= XOBNEW (hash_obstack
, struct attr_hash
);
356 h
->hashcode
= hashcode
;
358 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
359 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
362 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
365 attr_hash_add_string (int hashcode
, char *str
)
369 h
= XOBNEW (hash_obstack
, struct attr_hash
);
370 h
->hashcode
= -hashcode
;
372 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
373 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
376 /* Generate an RTL expression, but avoid duplicates.
377 Set the ATTR_PERMANENT_P flag for these permanent objects.
379 In some cases we cannot uniquify; then we return an ordinary
380 impermanent rtx with ATTR_PERMANENT_P clear.
384 rtx attr_rtx (code, [element1, ..., elementn]) */
387 attr_rtx_1 (enum rtx_code code
, va_list p
)
389 rtx rt_val
= NULL_RTX
;/* RTX to return to caller... */
392 struct obstack
*old_obstack
= rtl_obstack
;
394 /* For each of several cases, search the hash table for an existing entry.
395 Use that entry if one is found; otherwise create a new RTL and add it
398 if (GET_RTX_CLASS (code
) == RTX_UNARY
)
400 rtx arg0
= va_arg (p
, rtx
);
402 /* A permanent object cannot point to impermanent ones. */
403 if (! ATTR_PERMANENT_P (arg0
))
405 rt_val
= rtx_alloc (code
);
406 XEXP (rt_val
, 0) = arg0
;
410 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
411 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
412 if (h
->hashcode
== hashcode
413 && GET_CODE (h
->u
.rtl
) == code
414 && XEXP (h
->u
.rtl
, 0) == arg0
)
419 rtl_obstack
= hash_obstack
;
420 rt_val
= rtx_alloc (code
);
421 XEXP (rt_val
, 0) = arg0
;
424 else if (GET_RTX_CLASS (code
) == RTX_BIN_ARITH
425 || GET_RTX_CLASS (code
) == RTX_COMM_ARITH
426 || GET_RTX_CLASS (code
) == RTX_COMPARE
427 || GET_RTX_CLASS (code
) == RTX_COMM_COMPARE
)
429 rtx arg0
= va_arg (p
, rtx
);
430 rtx arg1
= va_arg (p
, rtx
);
432 /* A permanent object cannot point to impermanent ones. */
433 if (! ATTR_PERMANENT_P (arg0
) || ! ATTR_PERMANENT_P (arg1
))
435 rt_val
= rtx_alloc (code
);
436 XEXP (rt_val
, 0) = arg0
;
437 XEXP (rt_val
, 1) = arg1
;
441 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
442 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
443 if (h
->hashcode
== hashcode
444 && GET_CODE (h
->u
.rtl
) == code
445 && XEXP (h
->u
.rtl
, 0) == arg0
446 && XEXP (h
->u
.rtl
, 1) == arg1
)
451 rtl_obstack
= hash_obstack
;
452 rt_val
= rtx_alloc (code
);
453 XEXP (rt_val
, 0) = arg0
;
454 XEXP (rt_val
, 1) = arg1
;
457 else if (code
== SYMBOL_REF
458 || (GET_RTX_LENGTH (code
) == 1
459 && GET_RTX_FORMAT (code
)[0] == 's'))
461 char *arg0
= va_arg (p
, char *);
463 arg0
= DEF_ATTR_STRING (arg0
);
465 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
466 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
467 if (h
->hashcode
== hashcode
468 && GET_CODE (h
->u
.rtl
) == code
469 && XSTR (h
->u
.rtl
, 0) == arg0
)
474 rtl_obstack
= hash_obstack
;
475 rt_val
= rtx_alloc (code
);
476 XSTR (rt_val
, 0) = arg0
;
477 if (code
== SYMBOL_REF
)
479 X0EXP (rt_val
, 1) = NULL_RTX
;
480 X0EXP (rt_val
, 2) = NULL_RTX
;
484 else if (GET_RTX_LENGTH (code
) == 2
485 && GET_RTX_FORMAT (code
)[0] == 's'
486 && GET_RTX_FORMAT (code
)[1] == 's')
488 char *arg0
= va_arg (p
, char *);
489 char *arg1
= va_arg (p
, char *);
491 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
492 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
493 if (h
->hashcode
== hashcode
494 && GET_CODE (h
->u
.rtl
) == code
495 && XSTR (h
->u
.rtl
, 0) == arg0
496 && XSTR (h
->u
.rtl
, 1) == arg1
)
501 rtl_obstack
= hash_obstack
;
502 rt_val
= rtx_alloc (code
);
503 XSTR (rt_val
, 0) = arg0
;
504 XSTR (rt_val
, 1) = arg1
;
507 else if (code
== CONST_INT
)
509 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
519 int i
; /* Array indices... */
520 const char *fmt
; /* Current rtx's format... */
522 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
524 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
525 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
529 case '0': /* Unused field. */
532 case 'i': /* An integer? */
533 XINT (rt_val
, i
) = va_arg (p
, int);
536 case 'w': /* A wide integer? */
537 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
540 case 's': /* A string? */
541 XSTR (rt_val
, i
) = va_arg (p
, char *);
544 case 'e': /* An expression? */
545 case 'u': /* An insn? Same except when printing. */
546 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
549 case 'E': /* An RTX vector? */
550 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
560 rtl_obstack
= old_obstack
;
561 attr_hash_add_rtx (hashcode
, rt_val
);
562 ATTR_PERMANENT_P (rt_val
) = 1;
567 attr_rtx (enum rtx_code code
, ...)
573 result
= attr_rtx_1 (code
, p
);
578 /* Create a new string printed with the printf line arguments into a space
579 of at most LEN bytes:
581 rtx attr_printf (len, format, [arg1, ..., argn]) */
584 attr_printf (unsigned int len
, const char *fmt
, ...)
591 gcc_assert (len
< sizeof str
); /* Leave room for \0. */
593 vsprintf (str
, fmt
, p
);
596 return DEF_ATTR_STRING (str
);
600 attr_eq (const char *name
, const char *value
)
602 return attr_rtx (EQ_ATTR
, DEF_ATTR_STRING (name
), DEF_ATTR_STRING (value
));
608 return XSTR (make_numeric_value (n
), 0);
611 /* Return a permanent (possibly shared) copy of a string STR (not assumed
612 to be null terminated) with LEN bytes. */
615 attr_string (const char *str
, int len
)
622 /* Compute the hash code. */
623 hashcode
= (len
+ 1) * 613 + (unsigned) str
[0];
624 for (i
= 1; i
< len
; i
+= 2)
625 hashcode
= ((hashcode
* 613) + (unsigned) str
[i
]);
627 hashcode
= -hashcode
;
629 /* Search the table for the string. */
630 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
631 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
632 && !strncmp (h
->u
.str
, str
, len
))
633 return h
->u
.str
; /* <-- return if found. */
635 /* Not found; create a permanent copy and add it to the hash table. */
636 new_str
= XOBNEWVAR (hash_obstack
, char, len
+ 1);
637 memcpy (new_str
, str
, len
);
639 attr_hash_add_string (hashcode
, new_str
);
640 copy_md_ptr_loc (new_str
, str
);
642 return new_str
; /* Return the new string. */
645 /* Check two rtx's for equality of contents,
646 taking advantage of the fact that if both are hashed
647 then they can't be equal unless they are the same object. */
650 attr_equal_p (rtx x
, rtx y
)
652 return (x
== y
|| (! (ATTR_PERMANENT_P (x
) && ATTR_PERMANENT_P (y
))
653 && rtx_equal_p (x
, y
)));
656 /* Copy an attribute value expression,
657 descending to all depths, but not copying any
658 permanent hashed subexpressions. */
661 attr_copy_rtx (rtx orig
)
666 const char *format_ptr
;
668 /* No need to copy a permanent object. */
669 if (ATTR_PERMANENT_P (orig
))
672 code
= GET_CODE (orig
);
689 copy
= rtx_alloc (code
);
690 PUT_MODE (copy
, GET_MODE (orig
));
691 ATTR_IND_SIMPLIFIED_P (copy
) = ATTR_IND_SIMPLIFIED_P (orig
);
692 ATTR_CURR_SIMPLIFIED_P (copy
) = ATTR_CURR_SIMPLIFIED_P (orig
);
693 ATTR_PERMANENT_P (copy
) = ATTR_PERMANENT_P (orig
);
695 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
697 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
699 switch (*format_ptr
++)
702 XEXP (copy
, i
) = XEXP (orig
, i
);
703 if (XEXP (orig
, i
) != NULL
)
704 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
709 XVEC (copy
, i
) = XVEC (orig
, i
);
710 if (XVEC (orig
, i
) != NULL
)
712 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
713 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
714 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
720 XINT (copy
, i
) = XINT (orig
, i
);
724 XWINT (copy
, i
) = XWINT (orig
, i
);
729 XSTR (copy
, i
) = XSTR (orig
, i
);
739 /* Given a test expression for an attribute, ensure it is validly formed.
740 IS_CONST indicates whether the expression is constant for each compiler
741 run (a constant expression may not test any particular insn).
743 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
744 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
745 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
747 Update the string address in EQ_ATTR expression to be the same used
748 in the attribute (or `alternative_name') to speed up subsequent
749 `find_attr' calls and eliminate most `strcmp' calls.
751 Return the new expression, if any. */
754 check_attr_test (rtx exp
, int is_const
, int lineno
)
756 struct attr_desc
*attr
;
757 struct attr_value
*av
;
758 const char *name_ptr
, *p
;
761 switch (GET_CODE (exp
))
764 /* Handle negation test. */
765 if (XSTR (exp
, 1)[0] == '!')
766 return check_attr_test (attr_rtx (NOT
,
767 attr_eq (XSTR (exp
, 0),
771 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
773 attr
= find_attr (&XSTR (exp
, 0), 0);
776 if (! strcmp (XSTR (exp
, 0), "alternative"))
777 return mk_attr_alt (1 << atoi (XSTR (exp
, 1)));
779 fatal ("unknown attribute `%s' in EQ_ATTR", XSTR (exp
, 0));
782 if (is_const
&& ! attr
->is_const
)
783 fatal ("constant expression uses insn attribute `%s' in EQ_ATTR",
786 /* Copy this just to make it permanent,
787 so expressions using it can be permanent too. */
788 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
790 /* It shouldn't be possible to simplify the value given to a
791 constant attribute, so don't expand this until it's time to
792 write the test expression. */
794 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
796 if (attr
->is_numeric
)
798 for (p
= XSTR (exp
, 1); *p
; p
++)
800 fatal ("attribute `%s' takes only numeric values",
805 for (av
= attr
->first_value
; av
; av
= av
->next
)
806 if (GET_CODE (av
->value
) == CONST_STRING
807 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
811 fatal ("unknown value `%s' for `%s' attribute",
812 XSTR (exp
, 1), XSTR (exp
, 0));
817 if (! strcmp (XSTR (exp
, 0), "alternative"))
821 name_ptr
= XSTR (exp
, 1);
822 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
823 set
|= 1 << atoi (p
);
825 return mk_attr_alt (set
);
829 /* Make an IOR tree of the possible values. */
831 name_ptr
= XSTR (exp
, 1);
832 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
834 newexp
= attr_eq (XSTR (exp
, 0), p
);
835 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
838 return check_attr_test (orexp
, is_const
, lineno
);
847 /* Either TRUE or FALSE. */
855 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
856 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
, lineno
);
860 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
864 exp
= attr_rtx (MATCH_TEST
, XSTR (exp
, 0));
865 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
870 fatal ("RTL operator \"%s\" not valid in constant attribute test",
871 GET_RTX_NAME (GET_CODE (exp
)));
872 /* These cases can't be simplified. */
873 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
876 case LE
: case LT
: case GT
: case GE
:
877 case LEU
: case LTU
: case GTU
: case GEU
:
879 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
880 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
881 exp
= attr_rtx (GET_CODE (exp
),
882 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
883 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
884 /* These cases can't be simplified. */
885 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
891 /* These cases are valid for constant attributes, but can't be
893 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
894 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
898 fatal ("RTL operator \"%s\" not valid in attribute test",
899 GET_RTX_NAME (GET_CODE (exp
)));
905 /* Given an expression, ensure that it is validly formed and that all named
906 attribute values are valid for the given attribute. Issue a fatal error
907 if not. If no attribute is specified, assume a numeric attribute.
909 Return a perhaps modified replacement expression for the value. */
912 check_attr_value (rtx exp
, struct attr_desc
*attr
)
914 struct attr_value
*av
;
918 switch (GET_CODE (exp
))
921 if (attr
&& ! attr
->is_numeric
)
923 error_with_line (attr
->lineno
,
924 "CONST_INT not valid for non-numeric attribute %s",
929 if (INTVAL (exp
) < 0)
931 error_with_line (attr
->lineno
,
932 "negative numeric value specified for attribute %s",
939 if (! strcmp (XSTR (exp
, 0), "*"))
942 if (attr
== 0 || attr
->is_numeric
)
948 error_with_line (attr
? attr
->lineno
: 0,
949 "non-numeric value for numeric attribute %s",
950 attr
? attr
->name
: "internal");
956 for (av
= attr
->first_value
; av
; av
= av
->next
)
957 if (GET_CODE (av
->value
) == CONST_STRING
958 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
962 error_with_line (attr
->lineno
,
963 "unknown value `%s' for `%s' attribute",
964 XSTR (exp
, 0), attr
? attr
->name
: "internal");
968 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
969 attr
? attr
->is_const
: 0,
970 attr
? attr
->lineno
: 0);
971 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
972 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
980 if (attr
&& !attr
->is_numeric
)
982 error_with_line (attr
->lineno
,
983 "invalid operation `%s' for non-numeric"
984 " attribute value", GET_RTX_NAME (GET_CODE (exp
)));
991 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
992 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1001 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1005 if (XVECLEN (exp
, 0) % 2 != 0)
1007 error_with_line (attr
->lineno
,
1008 "first operand of COND must have even length");
1012 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1014 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1015 attr
? attr
->is_const
: 0,
1016 attr
? attr
->lineno
: 0);
1017 XVECEXP (exp
, 0, i
+ 1)
1018 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1021 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1026 struct attr_desc
*attr2
= find_attr (&XSTR (exp
, 0), 0);
1028 error_with_line (attr
? attr
->lineno
: 0,
1029 "unknown attribute `%s' in ATTR",
1031 else if (attr
&& attr
->is_const
&& ! attr2
->is_const
)
1032 error_with_line (attr
->lineno
,
1033 "non-constant attribute `%s' referenced from `%s'",
1034 XSTR (exp
, 0), attr
->name
);
1036 && attr
->is_numeric
!= attr2
->is_numeric
)
1037 error_with_line (attr
->lineno
,
1038 "numeric attribute mismatch calling `%s' from `%s'",
1039 XSTR (exp
, 0), attr
->name
);
1044 /* A constant SYMBOL_REF is valid as a constant attribute test and
1045 is expanded later by make_canonical into a COND. In a non-constant
1046 attribute test, it is left be. */
1047 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1050 error_with_line (attr
? attr
->lineno
: 0,
1051 "invalid operation `%s' for attribute value",
1052 GET_RTX_NAME (GET_CODE (exp
)));
1059 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1060 It becomes a COND with each test being (eq_attr "alternative" "n") */
1063 convert_set_attr_alternative (rtx exp
, struct insn_def
*id
)
1065 int num_alt
= id
->num_alternatives
;
1069 if (XVECLEN (exp
, 1) != num_alt
)
1071 error_with_line (id
->lineno
,
1072 "bad number of entries in SET_ATTR_ALTERNATIVE");
1076 /* Make a COND with all tests but the last. Select the last value via the
1078 condexp
= rtx_alloc (COND
);
1079 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1081 for (i
= 0; i
< num_alt
- 1; i
++)
1084 p
= attr_numeral (i
);
1086 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1087 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1090 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1092 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1095 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1096 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1099 convert_set_attr (rtx exp
, struct insn_def
*id
)
1102 const char *name_ptr
;
1106 /* See how many alternative specified. */
1107 n
= n_comma_elts (XSTR (exp
, 1));
1109 return attr_rtx (SET
,
1110 attr_rtx (ATTR
, XSTR (exp
, 0)),
1111 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1113 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1114 XSTR (newexp
, 0) = XSTR (exp
, 0);
1115 XVEC (newexp
, 1) = rtvec_alloc (n
);
1117 /* Process each comma-separated name. */
1118 name_ptr
= XSTR (exp
, 1);
1120 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1121 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1123 return convert_set_attr_alternative (newexp
, id
);
1126 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1127 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1133 struct insn_def
*id
;
1134 struct attr_desc
*attr
;
1138 for (id
= defs
; id
; id
= id
->next
)
1140 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1143 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1145 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1146 switch (GET_CODE (value
))
1149 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1151 error_with_line (id
->lineno
, "bad attribute set");
1156 case SET_ATTR_ALTERNATIVE
:
1157 value
= convert_set_attr_alternative (value
, id
);
1161 value
= convert_set_attr (value
, id
);
1165 error_with_line (id
->lineno
, "invalid attribute code %s",
1166 GET_RTX_NAME (GET_CODE (value
)));
1169 if (value
== NULL_RTX
)
1172 if ((attr
= find_attr (&XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1174 error_with_line (id
->lineno
, "unknown attribute %s",
1175 XSTR (XEXP (value
, 0), 0));
1179 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1180 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1185 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1186 expressions by converting them into a COND. This removes cases from this
1187 program. Also, replace an attribute value of "*" with the default attribute
1191 make_canonical (struct attr_desc
*attr
, rtx exp
)
1196 switch (GET_CODE (exp
))
1199 exp
= make_numeric_value (INTVAL (exp
));
1203 if (! strcmp (XSTR (exp
, 0), "*"))
1205 if (attr
== 0 || attr
->default_val
== 0)
1206 fatal ("(attr_value \"*\") used in invalid context");
1207 exp
= attr
->default_val
->value
;
1210 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1215 if (!attr
->is_const
|| ATTR_IND_SIMPLIFIED_P (exp
))
1217 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1218 This makes the COND something that won't be considered an arbitrary
1219 expression by walk_attr_value. */
1220 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1221 exp
= check_attr_value (exp
, attr
);
1225 newexp
= rtx_alloc (COND
);
1226 XVEC (newexp
, 0) = rtvec_alloc (2);
1227 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1228 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1230 XEXP (newexp
, 1) = XEXP (exp
, 2);
1233 /* Fall through to COND case since this is now a COND. */
1240 /* First, check for degenerate COND. */
1241 if (XVECLEN (exp
, 0) == 0)
1242 return make_canonical (attr
, XEXP (exp
, 1));
1243 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1245 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1247 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1248 XVECEXP (exp
, 0, i
+ 1)
1249 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1250 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1266 copy_boolean (rtx exp
)
1268 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1269 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1270 copy_boolean (XEXP (exp
, 1)));
1271 if (GET_CODE (exp
) == MATCH_OPERAND
)
1273 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1274 XSTR (exp
, 2) = DEF_ATTR_STRING (XSTR (exp
, 2));
1276 else if (GET_CODE (exp
) == EQ_ATTR
)
1278 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1279 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1285 /* Given a value and an attribute description, return a `struct attr_value *'
1286 that represents that value. This is either an existing structure, if the
1287 value has been previously encountered, or a newly-created structure.
1289 `insn_code' is the code of an insn whose attribute has the specified
1290 value (-2 if not processing an insn). We ensure that all insns for
1291 a given value have the same number of alternatives if the value checks
1294 static struct attr_value
*
1295 get_attr_value (rtx value
, struct attr_desc
*attr
, int insn_code
)
1297 struct attr_value
*av
;
1300 value
= make_canonical (attr
, value
);
1301 if (compares_alternatives_p (value
))
1303 if (insn_code
< 0 || insn_alternatives
== NULL
)
1304 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1306 num_alt
= insn_alternatives
[insn_code
];
1309 for (av
= attr
->first_value
; av
; av
= av
->next
)
1310 if (rtx_equal_p (value
, av
->value
)
1311 && (num_alt
== 0 || av
->first_insn
== NULL
1312 || insn_alternatives
[av
->first_insn
->def
->insn_code
]))
1315 av
= oballoc (struct attr_value
);
1317 av
->next
= attr
->first_value
;
1318 attr
->first_value
= av
;
1319 av
->first_insn
= NULL
;
1321 av
->has_asm_insn
= 0;
1326 /* After all DEFINE_DELAYs have been read in, create internal attributes
1327 to generate the required routines.
1329 First, we compute the number of delay slots for each insn (as a COND of
1330 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1331 delay type is specified, we compute a similar function giving the
1332 DEFINE_DELAY ordinal for each insn.
1334 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1335 tells whether a given insn can be in that delay slot.
1337 Normal attribute filling and optimization expands these to contain the
1338 information needed to handle delay slots. */
1341 expand_delays (void)
1343 struct delay_desc
*delay
;
1349 /* First, generate data for `num_delay_slots' function. */
1351 condexp
= rtx_alloc (COND
);
1352 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1353 XEXP (condexp
, 1) = make_numeric_value (0);
1355 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1357 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1358 XVECEXP (condexp
, 0, i
+ 1)
1359 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1362 make_internal_attr (num_delay_slots_str
, condexp
, ATTR_NONE
);
1364 /* If more than one delay type, do the same for computing the delay type. */
1367 condexp
= rtx_alloc (COND
);
1368 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1369 XEXP (condexp
, 1) = make_numeric_value (0);
1371 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1373 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1374 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1377 make_internal_attr (delay_type_str
, condexp
, ATTR_SPECIAL
);
1380 /* For each delay possibility and delay slot, compute an eligibility
1381 attribute for non-annulled insns and for each type of annulled (annul
1382 if true and annul if false). */
1383 for (delay
= delays
; delay
; delay
= delay
->next
)
1385 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1387 condexp
= XVECEXP (delay
->def
, 1, i
);
1389 condexp
= false_rtx
;
1390 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1391 make_numeric_value (1), make_numeric_value (0));
1393 p
= attr_printf (sizeof "*delay__" + MAX_DIGITS
* 2,
1394 "*delay_%d_%d", delay
->num
, i
/ 3);
1395 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1397 if (have_annul_true
)
1399 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1400 if (condexp
== 0) condexp
= false_rtx
;
1401 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1402 make_numeric_value (1),
1403 make_numeric_value (0));
1404 p
= attr_printf (sizeof "*annul_true__" + MAX_DIGITS
* 2,
1405 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1406 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1409 if (have_annul_false
)
1411 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1412 if (condexp
== 0) condexp
= false_rtx
;
1413 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1414 make_numeric_value (1),
1415 make_numeric_value (0));
1416 p
= attr_printf (sizeof "*annul_false__" + MAX_DIGITS
* 2,
1417 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1418 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1424 /* Once all attributes and insns have been read and checked, we construct for
1425 each attribute value a list of all the insns that have that value for
1429 fill_attr (struct attr_desc
*attr
)
1431 struct attr_value
*av
;
1432 struct insn_ent
*ie
;
1433 struct insn_def
*id
;
1437 /* Don't fill constant attributes. The value is independent of
1438 any particular insn. */
1442 for (id
= defs
; id
; id
= id
->next
)
1444 /* If no value is specified for this insn for this attribute, use the
1447 if (XVEC (id
->def
, id
->vec_idx
))
1448 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1449 if (! strcmp_check (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
1451 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
1454 av
= attr
->default_val
;
1456 av
= get_attr_value (value
, attr
, id
->insn_code
);
1458 ie
= oballoc (struct insn_ent
);
1460 insert_insn_ent (av
, ie
);
1464 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
1465 test that checks relative positions of insns (uses MATCH_DUP or PC).
1466 If so, replace it with what is obtained by passing the expression to
1467 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
1468 recursively on each value (including the default value). Otherwise,
1469 return the value returned by NO_ADDRESS_FN applied to EXP. */
1472 substitute_address (rtx exp
, rtx (*no_address_fn
) (rtx
),
1473 rtx (*address_fn
) (rtx
))
1478 if (GET_CODE (exp
) == COND
)
1480 /* See if any tests use addresses. */
1482 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1483 walk_attr_value (XVECEXP (exp
, 0, i
));
1486 return (*address_fn
) (exp
);
1488 /* Make a new copy of this COND, replacing each element. */
1489 newexp
= rtx_alloc (COND
);
1490 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
1491 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1493 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
1494 XVECEXP (newexp
, 0, i
+ 1)
1495 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
1496 no_address_fn
, address_fn
);
1499 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
1500 no_address_fn
, address_fn
);
1505 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
1508 walk_attr_value (XEXP (exp
, 0));
1510 return (*address_fn
) (exp
);
1512 return attr_rtx (IF_THEN_ELSE
,
1513 substitute_address (XEXP (exp
, 0),
1514 no_address_fn
, address_fn
),
1515 substitute_address (XEXP (exp
, 1),
1516 no_address_fn
, address_fn
),
1517 substitute_address (XEXP (exp
, 2),
1518 no_address_fn
, address_fn
));
1521 return (*no_address_fn
) (exp
);
1524 /* Make new attributes from the `length' attribute. The following are made,
1525 each corresponding to a function called from `shorten_branches' or
1528 *insn_default_length This is the length of the insn to be returned
1529 by `get_attr_length' before `shorten_branches'
1530 has been called. In each case where the length
1531 depends on relative addresses, the largest
1532 possible is used. This routine is also used
1533 to compute the initial size of the insn.
1535 *insn_variable_length_p This returns 1 if the insn's length depends
1536 on relative addresses, zero otherwise.
1538 *insn_current_length This is only called when it is known that the
1539 insn has a variable length and returns the
1540 current length, based on relative addresses.
1544 make_length_attrs (void)
1546 static const char *new_names
[] =
1548 "*insn_default_length",
1550 "*insn_variable_length_p",
1551 "*insn_current_length"
1553 static rtx (*const no_address_fn
[]) (rtx
)
1554 = {identity_fn
,identity_fn
, zero_fn
, zero_fn
};
1555 static rtx (*const address_fn
[]) (rtx
)
1556 = {max_fn
, min_fn
, one_fn
, identity_fn
};
1558 struct attr_desc
*length_attr
, *new_attr
;
1559 struct attr_value
*av
, *new_av
;
1560 struct insn_ent
*ie
, *new_ie
;
1562 /* See if length attribute is defined. If so, it must be numeric. Make
1563 it special so we don't output anything for it. */
1564 length_attr
= find_attr (&length_str
, 0);
1565 if (length_attr
== 0)
1568 if (! length_attr
->is_numeric
)
1569 fatal ("length attribute must be numeric");
1571 length_attr
->is_const
= 0;
1572 length_attr
->is_special
= 1;
1574 /* Make each new attribute, in turn. */
1575 for (i
= 0; i
< ARRAY_SIZE (new_names
); i
++)
1577 make_internal_attr (new_names
[i
],
1578 substitute_address (length_attr
->default_val
->value
,
1579 no_address_fn
[i
], address_fn
[i
]),
1581 new_attr
= find_attr (&new_names
[i
], 0);
1582 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
1583 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1585 new_av
= get_attr_value (substitute_address (av
->value
,
1588 new_attr
, ie
->def
->insn_code
);
1589 new_ie
= oballoc (struct insn_ent
);
1590 new_ie
->def
= ie
->def
;
1591 insert_insn_ent (new_av
, new_ie
);
1596 /* Utility functions called from above routine. */
1599 identity_fn (rtx exp
)
1605 zero_fn (rtx exp ATTRIBUTE_UNUSED
)
1607 return make_numeric_value (0);
1611 one_fn (rtx exp ATTRIBUTE_UNUSED
)
1613 return make_numeric_value (1);
1620 return make_numeric_value (max_attr_value (exp
, &unknown
));
1627 return make_numeric_value (min_attr_value (exp
, &unknown
));
1631 write_length_unit_log (FILE *outf
)
1633 struct attr_desc
*length_attr
= find_attr (&length_str
, 0);
1634 struct attr_value
*av
;
1635 struct insn_ent
*ie
;
1636 unsigned int length_unit_log
, length_or
;
1641 length_or
= or_attr_value (length_attr
->default_val
->value
, &unknown
);
1642 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
1643 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1644 length_or
|= or_attr_value (av
->value
, &unknown
);
1647 if (length_attr
== NULL
|| unknown
)
1648 length_unit_log
= 0;
1651 length_or
= ~length_or
;
1652 for (length_unit_log
= 0; length_or
& 1; length_or
>>= 1)
1655 fprintf (outf
, "EXPORTED_CONST int length_unit_log = %u;\n", length_unit_log
);
1658 /* Compute approximate cost of the expression. Used to decide whether
1659 expression is cheap enough for inline. */
1661 attr_rtx_cost (rtx x
)
1667 code
= GET_CODE (x
);
1680 /* Alternatives don't result into function call. */
1681 if (!strcmp_check (XSTR (x
, 0), alternative_name
))
1688 const char *fmt
= GET_RTX_FORMAT (code
);
1689 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1695 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1696 cost
+= attr_rtx_cost (XVECEXP (x
, i
, j
));
1699 cost
+= attr_rtx_cost (XEXP (x
, i
));
1709 /* Take a COND expression and see if any of the conditions in it can be
1710 simplified. If any are known true or known false for the particular insn
1711 code, the COND can be further simplified.
1713 Also call ourselves on any COND operations that are values of this COND.
1715 We do not modify EXP; rather, we make and return a new rtx. */
1718 simplify_cond (rtx exp
, int insn_code
, int insn_index
)
1721 /* We store the desired contents here,
1722 then build a new expression if they don't match EXP. */
1723 rtx defval
= XEXP (exp
, 1);
1724 rtx new_defval
= XEXP (exp
, 1);
1725 int len
= XVECLEN (exp
, 0);
1726 rtx
*tests
= XNEWVEC (rtx
, len
);
1730 /* This lets us free all storage allocated below, if appropriate. */
1731 obstack_finish (rtl_obstack
);
1733 memcpy (tests
, XVEC (exp
, 0)->elem
, len
* sizeof (rtx
));
1735 /* See if default value needs simplification. */
1736 if (GET_CODE (defval
) == COND
)
1737 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
1739 /* Simplify the subexpressions, and see what tests we can get rid of. */
1741 for (i
= 0; i
< len
; i
+= 2)
1743 rtx newtest
, newval
;
1745 /* Simplify this test. */
1746 newtest
= simplify_test_exp_in_temp (tests
[i
], insn_code
, insn_index
);
1749 newval
= tests
[i
+ 1];
1750 /* See if this value may need simplification. */
1751 if (GET_CODE (newval
) == COND
)
1752 newval
= simplify_cond (newval
, insn_code
, insn_index
);
1754 /* Look for ways to delete or combine this test. */
1755 if (newtest
== true_rtx
)
1757 /* If test is true, make this value the default
1758 and discard this + any following tests. */
1760 defval
= tests
[i
+ 1];
1761 new_defval
= newval
;
1764 else if (newtest
== false_rtx
)
1766 /* If test is false, discard it and its value. */
1767 for (j
= i
; j
< len
- 2; j
++)
1768 tests
[j
] = tests
[j
+ 2];
1773 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
1775 /* If this value and the value for the prev test are the same,
1779 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
1780 insn_code
, insn_index
);
1782 /* Delete this test/value. */
1783 for (j
= i
; j
< len
- 2; j
++)
1784 tests
[j
] = tests
[j
+ 2];
1790 tests
[i
+ 1] = newval
;
1793 /* If the last test in a COND has the same value
1794 as the default value, that test isn't needed. */
1796 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
1799 /* See if we changed anything. */
1800 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
1803 for (i
= 0; i
< len
; i
++)
1804 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
1812 if (GET_CODE (defval
) == COND
)
1813 ret
= simplify_cond (defval
, insn_code
, insn_index
);
1821 rtx newexp
= rtx_alloc (COND
);
1823 XVEC (newexp
, 0) = rtvec_alloc (len
);
1824 memcpy (XVEC (newexp
, 0)->elem
, tests
, len
* sizeof (rtx
));
1825 XEXP (newexp
, 1) = new_defval
;
1832 /* Remove an insn entry from an attribute value. */
1835 remove_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
1837 struct insn_ent
*previe
;
1839 if (av
->first_insn
== ie
)
1840 av
->first_insn
= ie
->next
;
1843 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
1845 previe
->next
= ie
->next
;
1849 if (ie
->def
->insn_code
== -1)
1850 av
->has_asm_insn
= 0;
1855 /* Insert an insn entry in an attribute value list. */
1858 insert_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
1860 ie
->next
= av
->first_insn
;
1861 av
->first_insn
= ie
;
1863 if (ie
->def
->insn_code
== -1)
1864 av
->has_asm_insn
= 1;
1869 /* This is a utility routine to take an expression that is a tree of either
1870 AND or IOR expressions and insert a new term. The new term will be
1871 inserted at the right side of the first node whose code does not match
1872 the root. A new node will be created with the root's code. Its left
1873 side will be the old right side and its right side will be the new
1876 If the `term' is itself a tree, all its leaves will be inserted. */
1879 insert_right_side (enum rtx_code code
, rtx exp
, rtx term
, int insn_code
, int insn_index
)
1883 /* Avoid consing in some special cases. */
1884 if (code
== AND
&& term
== true_rtx
)
1886 if (code
== AND
&& term
== false_rtx
)
1888 if (code
== AND
&& exp
== true_rtx
)
1890 if (code
== AND
&& exp
== false_rtx
)
1892 if (code
== IOR
&& term
== true_rtx
)
1894 if (code
== IOR
&& term
== false_rtx
)
1896 if (code
== IOR
&& exp
== true_rtx
)
1898 if (code
== IOR
&& exp
== false_rtx
)
1900 if (attr_equal_p (exp
, term
))
1903 if (GET_CODE (term
) == code
)
1905 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
1906 insn_code
, insn_index
);
1907 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
1908 insn_code
, insn_index
);
1913 if (GET_CODE (exp
) == code
)
1915 rtx new_rtx
= insert_right_side (code
, XEXP (exp
, 1),
1916 term
, insn_code
, insn_index
);
1917 if (new_rtx
!= XEXP (exp
, 1))
1918 /* Make a copy of this expression and call recursively. */
1919 newexp
= attr_rtx (code
, XEXP (exp
, 0), new_rtx
);
1925 /* Insert the new term. */
1926 newexp
= attr_rtx (code
, exp
, term
);
1929 return simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
1932 /* If we have an expression which AND's a bunch of
1933 (not (eq_attrq "alternative" "n"))
1934 terms, we may have covered all or all but one of the possible alternatives.
1935 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
1937 This routine is passed an expression and either AND or IOR. It returns a
1938 bitmask indicating which alternatives are mentioned within EXP. */
1941 compute_alternative_mask (rtx exp
, enum rtx_code code
)
1944 if (GET_CODE (exp
) == code
)
1945 return compute_alternative_mask (XEXP (exp
, 0), code
)
1946 | compute_alternative_mask (XEXP (exp
, 1), code
);
1948 else if (code
== AND
&& GET_CODE (exp
) == NOT
1949 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
1950 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
1951 string
= XSTR (XEXP (exp
, 0), 1);
1953 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
1954 && XSTR (exp
, 0) == alternative_name
)
1955 string
= XSTR (exp
, 1);
1957 else if (GET_CODE (exp
) == EQ_ATTR_ALT
)
1959 if (code
== AND
&& XINT (exp
, 1))
1960 return XINT (exp
, 0);
1962 if (code
== IOR
&& !XINT (exp
, 1))
1963 return XINT (exp
, 0);
1971 return 1 << (string
[0] - '0');
1972 return 1 << atoi (string
);
1975 /* Given I, a single-bit mask, return RTX to compare the `alternative'
1976 attribute with the value represented by that bit. */
1979 make_alternative_compare (int mask
)
1981 return mk_attr_alt (mask
);
1984 /* If we are processing an (eq_attr "attr" "value") test, we find the value
1985 of "attr" for this insn code. From that value, we can compute a test
1986 showing when the EQ_ATTR will be true. This routine performs that
1987 computation. If a test condition involves an address, we leave the EQ_ATTR
1988 intact because addresses are only valid for the `length' attribute.
1990 EXP is the EQ_ATTR expression and ATTR is the attribute to which
1991 it refers. VALUE is the value of that attribute for the insn
1992 corresponding to INSN_CODE and INSN_INDEX. */
1995 evaluate_eq_attr (rtx exp
, struct attr_desc
*attr
, rtx value
,
1996 int insn_code
, int insn_index
)
2003 while (GET_CODE (value
) == ATTR
)
2005 struct attr_value
*av
= NULL
;
2007 attr
= find_attr (&XSTR (value
, 0), 0);
2009 if (insn_code_values
)
2011 struct attr_value_list
*iv
;
2012 for (iv
= insn_code_values
[insn_code
]; iv
; iv
= iv
->next
)
2013 if (iv
->attr
== attr
)
2021 struct insn_ent
*ie
;
2022 for (av
= attr
->first_value
; av
; av
= av
->next
)
2023 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2024 if (ie
->def
->insn_code
== insn_code
)
2034 switch (GET_CODE (value
))
2037 if (! strcmp_check (XSTR (value
, 0), XSTR (exp
, 1)))
2048 gcc_assert (GET_CODE (exp
) == EQ_ATTR
);
2049 prefix
= attr
->enum_name
? attr
->enum_name
: attr
->name
;
2050 string
= ACONCAT ((prefix
, "_", XSTR (exp
, 1), NULL
));
2051 for (p
= string
; *p
; p
++)
2054 newexp
= attr_rtx (EQ
, value
,
2055 attr_rtx (SYMBOL_REF
,
2056 DEF_ATTR_STRING (string
)));
2061 /* We construct an IOR of all the cases for which the
2062 requested attribute value is present. Since we start with
2063 FALSE, if it is not present, FALSE will be returned.
2065 Each case is the AND of the NOT's of the previous conditions with the
2066 current condition; in the default case the current condition is TRUE.
2068 For each possible COND value, call ourselves recursively.
2070 The extra TRUE and FALSE expressions will be eliminated by another
2071 call to the simplification routine. */
2076 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2078 rtx this_cond
= simplify_test_exp_in_temp (XVECEXP (value
, 0, i
),
2079 insn_code
, insn_index
);
2081 right
= insert_right_side (AND
, andexp
, this_cond
,
2082 insn_code
, insn_index
);
2083 right
= insert_right_side (AND
, right
,
2084 evaluate_eq_attr (exp
, attr
,
2087 insn_code
, insn_index
),
2088 insn_code
, insn_index
);
2089 orexp
= insert_right_side (IOR
, orexp
, right
,
2090 insn_code
, insn_index
);
2092 /* Add this condition into the AND expression. */
2093 newexp
= attr_rtx (NOT
, this_cond
);
2094 andexp
= insert_right_side (AND
, andexp
, newexp
,
2095 insn_code
, insn_index
);
2098 /* Handle the default case. */
2099 right
= insert_right_side (AND
, andexp
,
2100 evaluate_eq_attr (exp
, attr
, XEXP (value
, 1),
2101 insn_code
, insn_index
),
2102 insn_code
, insn_index
);
2103 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2110 /* If uses an address, must return original expression. But set the
2111 ATTR_IND_SIMPLIFIED_P bit so we don't try to simplify it again. */
2114 walk_attr_value (newexp
);
2118 if (! ATTR_IND_SIMPLIFIED_P (exp
))
2119 return copy_rtx_unchanging (exp
);
2126 /* This routine is called when an AND of a term with a tree of AND's is
2127 encountered. If the term or its complement is present in the tree, it
2128 can be replaced with TRUE or FALSE, respectively.
2130 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2131 be true and hence are complementary.
2133 There is one special case: If we see
2134 (and (not (eq_attr "att" "v1"))
2135 (eq_attr "att" "v2"))
2136 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2137 replace the term, not anything in the AND tree. So we pass a pointer to
2141 simplify_and_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
2146 int left_eliminates_term
, right_eliminates_term
;
2148 if (GET_CODE (exp
) == AND
)
2150 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2151 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2152 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2154 newexp
= attr_rtx (AND
, left
, right
);
2156 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2160 else if (GET_CODE (exp
) == IOR
)
2162 /* For the IOR case, we do the same as above, except that we can
2163 only eliminate `term' if both sides of the IOR would do so. */
2165 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2166 left_eliminates_term
= (temp
== true_rtx
);
2169 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2170 right_eliminates_term
= (temp
== true_rtx
);
2172 if (left_eliminates_term
&& right_eliminates_term
)
2175 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2177 newexp
= attr_rtx (IOR
, left
, right
);
2179 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2183 /* Check for simplifications. Do some extra checking here since this
2184 routine is called so many times. */
2189 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
2192 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
2195 else if (GET_CODE (exp
) == EQ_ATTR_ALT
&& GET_CODE (*pterm
) == EQ_ATTR_ALT
)
2197 if (attr_alt_subset_p (*pterm
, exp
))
2200 if (attr_alt_subset_of_compl_p (*pterm
, exp
))
2203 if (attr_alt_subset_p (exp
, *pterm
))
2209 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
2211 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
2214 if (! strcmp_check (XSTR (exp
, 1), XSTR (*pterm
, 1)))
2220 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2221 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
2223 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
2226 if (! strcmp_check (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
2232 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2233 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
2235 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
2238 if (! strcmp_check (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
2244 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
2246 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
2250 else if (GET_CODE (exp
) == NOT
)
2252 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
2256 else if (GET_CODE (*pterm
) == NOT
)
2258 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
2262 else if (attr_equal_p (exp
, *pterm
))
2268 /* Similar to `simplify_and_tree', but for IOR trees. */
2271 simplify_or_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
2276 int left_eliminates_term
, right_eliminates_term
;
2278 if (GET_CODE (exp
) == IOR
)
2280 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2281 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2282 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2284 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2286 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2290 else if (GET_CODE (exp
) == AND
)
2292 /* For the AND case, we do the same as above, except that we can
2293 only eliminate `term' if both sides of the AND would do so. */
2295 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2296 left_eliminates_term
= (temp
== false_rtx
);
2299 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2300 right_eliminates_term
= (temp
== false_rtx
);
2302 if (left_eliminates_term
&& right_eliminates_term
)
2305 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2307 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2309 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2313 if (attr_equal_p (exp
, *pterm
))
2316 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
2319 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
2322 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2323 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2324 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
2327 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2328 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
2329 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
2335 /* Simplify test expression and use temporary obstack in order to avoid
2336 memory bloat. Use ATTR_IND_SIMPLIFIED to avoid unnecessary simplifications
2337 and avoid unnecessary copying if possible. */
2340 simplify_test_exp_in_temp (rtx exp
, int insn_code
, int insn_index
)
2343 struct obstack
*old
;
2344 if (ATTR_IND_SIMPLIFIED_P (exp
))
2347 rtl_obstack
= temp_obstack
;
2348 x
= simplify_test_exp (exp
, insn_code
, insn_index
);
2350 if (x
== exp
|| rtl_obstack
== temp_obstack
)
2352 return attr_copy_rtx (x
);
2355 /* Returns true if S1 is a subset of S2. */
2358 attr_alt_subset_p (rtx s1
, rtx s2
)
2360 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2363 return !(XINT (s1
, 0) &~ XINT (s2
, 0));
2366 return !(XINT (s1
, 0) & XINT (s2
, 0));
2372 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
2379 /* Returns true if S1 is a subset of complement of S2. */
2382 attr_alt_subset_of_compl_p (rtx s1
, rtx s2
)
2384 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2387 return !(XINT (s1
, 0) & XINT (s2
, 0));
2390 return !(XINT (s1
, 0) & ~XINT (s2
, 0));
2393 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
2403 /* Return EQ_ATTR_ALT expression representing intersection of S1 and S2. */
2406 attr_alt_intersection (rtx s1
, rtx s2
)
2408 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
2410 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2413 XINT (result
, 0) = XINT (s1
, 0) & XINT (s2
, 0);
2416 XINT (result
, 0) = XINT (s1
, 0) & ~XINT (s2
, 0);
2419 XINT (result
, 0) = XINT (s2
, 0) & ~XINT (s1
, 0);
2422 XINT (result
, 0) = XINT (s1
, 0) | XINT (s2
, 0);
2427 XINT (result
, 1) = XINT (s1
, 1) & XINT (s2
, 1);
2432 /* Return EQ_ATTR_ALT expression representing union of S1 and S2. */
2435 attr_alt_union (rtx s1
, rtx s2
)
2437 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
2439 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
2442 XINT (result
, 0) = XINT (s1
, 0) | XINT (s2
, 0);
2445 XINT (result
, 0) = XINT (s2
, 0) & ~XINT (s1
, 0);
2448 XINT (result
, 0) = XINT (s1
, 0) & ~XINT (s2
, 0);
2451 XINT (result
, 0) = XINT (s1
, 0) & XINT (s2
, 0);
2457 XINT (result
, 1) = XINT (s1
, 1) | XINT (s2
, 1);
2461 /* Return EQ_ATTR_ALT expression representing complement of S. */
2464 attr_alt_complement (rtx s
)
2466 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
2468 XINT (result
, 0) = XINT (s
, 0);
2469 XINT (result
, 1) = 1 - XINT (s
, 1);
2474 /* Return EQ_ATTR_ALT expression representing set containing elements set
2480 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
2482 XINT (result
, 0) = e
;
2483 XINT (result
, 1) = 0;
2488 /* Given an expression, see if it can be simplified for a particular insn
2489 code based on the values of other attributes being tested. This can
2490 eliminate nested get_attr_... calls.
2492 Note that if an endless recursion is specified in the patterns, the
2493 optimization will loop. However, it will do so in precisely the cases where
2494 an infinite recursion loop could occur during compilation. It's better that
2498 simplify_test_exp (rtx exp
, int insn_code
, int insn_index
)
2501 struct attr_desc
*attr
;
2502 struct attr_value
*av
;
2503 struct insn_ent
*ie
;
2504 struct attr_value_list
*iv
;
2507 bool left_alt
, right_alt
;
2509 /* Don't re-simplify something we already simplified. */
2510 if (ATTR_IND_SIMPLIFIED_P (exp
) || ATTR_CURR_SIMPLIFIED_P (exp
))
2513 switch (GET_CODE (exp
))
2516 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2517 if (left
== false_rtx
)
2519 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2520 if (right
== false_rtx
)
2523 if (GET_CODE (left
) == EQ_ATTR_ALT
2524 && GET_CODE (right
) == EQ_ATTR_ALT
)
2526 exp
= attr_alt_intersection (left
, right
);
2527 return simplify_test_exp (exp
, insn_code
, insn_index
);
2530 /* If either side is an IOR and we have (eq_attr "alternative" ..")
2531 present on both sides, apply the distributive law since this will
2532 yield simplifications. */
2533 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
2534 && compute_alternative_mask (left
, IOR
)
2535 && compute_alternative_mask (right
, IOR
))
2537 if (GET_CODE (left
) == IOR
)
2544 newexp
= attr_rtx (IOR
,
2545 attr_rtx (AND
, left
, XEXP (right
, 0)),
2546 attr_rtx (AND
, left
, XEXP (right
, 1)));
2548 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2551 /* Try with the term on both sides. */
2552 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
2553 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2554 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
2556 if (left
== false_rtx
|| right
== false_rtx
)
2558 else if (left
== true_rtx
)
2562 else if (right
== true_rtx
)
2566 /* See if all or all but one of the insn's alternatives are specified
2567 in this tree. Optimize if so. */
2569 if (GET_CODE (left
) == NOT
)
2570 left_alt
= (GET_CODE (XEXP (left
, 0)) == EQ_ATTR
2571 && XSTR (XEXP (left
, 0), 0) == alternative_name
);
2573 left_alt
= (GET_CODE (left
) == EQ_ATTR_ALT
2576 if (GET_CODE (right
) == NOT
)
2577 right_alt
= (GET_CODE (XEXP (right
, 0)) == EQ_ATTR
2578 && XSTR (XEXP (right
, 0), 0) == alternative_name
);
2580 right_alt
= (GET_CODE (right
) == EQ_ATTR_ALT
2581 && XINT (right
, 1));
2584 && (GET_CODE (left
) == AND
2586 || GET_CODE (right
) == AND
2589 i
= compute_alternative_mask (exp
, AND
);
2590 if (i
& ~insn_alternatives
[insn_code
])
2591 fatal ("invalid alternative specified for pattern number %d",
2594 /* If all alternatives are excluded, this is false. */
2595 i
^= insn_alternatives
[insn_code
];
2598 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2600 /* If just one excluded, AND a comparison with that one to the
2601 front of the tree. The others will be eliminated by
2602 optimization. We do not want to do this if the insn has one
2603 alternative and we have tested none of them! */
2604 left
= make_alternative_compare (i
);
2605 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2606 newexp
= attr_rtx (AND
, left
, right
);
2608 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2612 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2614 newexp
= attr_rtx (AND
, left
, right
);
2615 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2620 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2621 if (left
== true_rtx
)
2623 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2624 if (right
== true_rtx
)
2627 if (GET_CODE (left
) == EQ_ATTR_ALT
2628 && GET_CODE (right
) == EQ_ATTR_ALT
)
2630 exp
= attr_alt_union (left
, right
);
2631 return simplify_test_exp (exp
, insn_code
, insn_index
);
2634 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
2635 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2636 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
2638 if (right
== true_rtx
|| left
== true_rtx
)
2640 else if (left
== false_rtx
)
2644 else if (right
== false_rtx
)
2649 /* Test for simple cases where the distributive law is useful. I.e.,
2650 convert (ior (and (x) (y))
2656 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2657 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
2659 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
2661 left
= XEXP (left
, 0);
2663 newexp
= attr_rtx (AND
, left
, right
);
2664 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2668 convert (ior (and (y) (x))
2670 to (and (ior (y) (z))
2672 Note that we want the common term to stay at the end.
2675 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2676 && attr_equal_p (XEXP (left
, 1), XEXP (right
, 1)))
2678 newexp
= attr_rtx (IOR
, XEXP (left
, 0), XEXP (right
, 0));
2681 right
= XEXP (right
, 1);
2682 newexp
= attr_rtx (AND
, left
, right
);
2683 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2686 /* See if all or all but one of the insn's alternatives are specified
2687 in this tree. Optimize if so. */
2689 else if (insn_code
>= 0
2690 && (GET_CODE (left
) == IOR
2691 || (GET_CODE (left
) == EQ_ATTR_ALT
2693 || (GET_CODE (left
) == EQ_ATTR
2694 && XSTR (left
, 0) == alternative_name
)
2695 || GET_CODE (right
) == IOR
2696 || (GET_CODE (right
) == EQ_ATTR_ALT
2697 && !XINT (right
, 1))
2698 || (GET_CODE (right
) == EQ_ATTR
2699 && XSTR (right
, 0) == alternative_name
)))
2701 i
= compute_alternative_mask (exp
, IOR
);
2702 if (i
& ~insn_alternatives
[insn_code
])
2703 fatal ("invalid alternative specified for pattern number %d",
2706 /* If all alternatives are included, this is true. */
2707 i
^= insn_alternatives
[insn_code
];
2710 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2712 /* If just one excluded, IOR a comparison with that one to the
2713 front of the tree. The others will be eliminated by
2714 optimization. We do not want to do this if the insn has one
2715 alternative and we have tested none of them! */
2716 left
= make_alternative_compare (i
);
2717 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2718 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
2720 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2724 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2726 newexp
= attr_rtx (IOR
, left
, right
);
2727 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2732 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
2734 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
2735 insn_code
, insn_index
);
2739 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2740 if (GET_CODE (left
) == NOT
)
2741 return XEXP (left
, 0);
2743 if (left
== false_rtx
)
2745 if (left
== true_rtx
)
2748 if (GET_CODE (left
) == EQ_ATTR_ALT
)
2750 exp
= attr_alt_complement (left
);
2751 return simplify_test_exp (exp
, insn_code
, insn_index
);
2754 /* Try to apply De`Morgan's laws. */
2755 if (GET_CODE (left
) == IOR
)
2757 newexp
= attr_rtx (AND
,
2758 attr_rtx (NOT
, XEXP (left
, 0)),
2759 attr_rtx (NOT
, XEXP (left
, 1)));
2761 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2763 else if (GET_CODE (left
) == AND
)
2765 newexp
= attr_rtx (IOR
,
2766 attr_rtx (NOT
, XEXP (left
, 0)),
2767 attr_rtx (NOT
, XEXP (left
, 1)));
2769 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2771 else if (left
!= XEXP (exp
, 0))
2773 newexp
= attr_rtx (NOT
, left
);
2779 return XINT (exp
, 1) ? true_rtx
: false_rtx
;
2783 if (XSTR (exp
, 0) == alternative_name
)
2785 newexp
= mk_attr_alt (1 << atoi (XSTR (exp
, 1)));
2789 /* Look at the value for this insn code in the specified attribute.
2790 We normally can replace this comparison with the condition that
2791 would give this insn the values being tested for. */
2793 && (attr
= find_attr (&XSTR (exp
, 0), 0)) != NULL
)
2798 if (insn_code_values
)
2800 for (iv
= insn_code_values
[insn_code
]; iv
; iv
= iv
->next
)
2801 if (iv
->attr
== attr
)
2809 for (av
= attr
->first_value
; av
; av
= av
->next
)
2810 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2811 if (ie
->def
->insn_code
== insn_code
)
2818 x
= evaluate_eq_attr (exp
, attr
, av
->value
,
2819 insn_code
, insn_index
);
2820 x
= SIMPLIFY_TEST_EXP (x
, insn_code
, insn_index
);
2821 if (attr_rtx_cost(x
) < 7)
2831 /* We have already simplified this expression. Simplifying it again
2832 won't buy anything unless we weren't given a valid insn code
2833 to process (i.e., we are canonicalizing something.). */
2835 && ! ATTR_IND_SIMPLIFIED_P (newexp
))
2836 return copy_rtx_unchanging (newexp
);
2841 /* Return 1 if any EQ_ATTR subexpression of P refers to ATTR,
2842 otherwise return 0. */
2845 tests_attr_p (rtx p
, struct attr_desc
*attr
)
2850 if (GET_CODE (p
) == EQ_ATTR
)
2852 if (XSTR (p
, 0) != attr
->name
)
2857 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
2858 ie
= GET_RTX_LENGTH (GET_CODE (p
));
2859 for (i
= 0; i
< ie
; i
++)
2864 if (tests_attr_p (XEXP (p
, i
), attr
))
2869 je
= XVECLEN (p
, i
);
2870 for (j
= 0; j
< je
; ++j
)
2871 if (tests_attr_p (XVECEXP (p
, i
, j
), attr
))
2880 /* Calculate a topological sorting of all attributes so that
2881 all attributes only depend on attributes in front of it.
2882 Place the result in *RET (which is a pointer to an array of
2883 attr_desc pointers), and return the size of that array. */
2886 get_attr_order (struct attr_desc
***ret
)
2890 struct attr_desc
*attr
;
2891 struct attr_desc
**all
, **sorted
;
2893 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
2894 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
2896 all
= XNEWVEC (struct attr_desc
*, num
);
2897 sorted
= XNEWVEC (struct attr_desc
*, num
);
2898 handled
= XCNEWVEC (char, num
);
2900 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
2901 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
2905 for (i
= 0; i
< num
; i
++)
2906 if (all
[i
]->is_const
)
2907 handled
[i
] = 1, sorted
[j
++] = all
[i
];
2909 /* We have only few attributes hence we can live with the inner
2910 loop being O(n^2), unlike the normal fast variants of topological
2914 for (i
= 0; i
< num
; i
++)
2917 /* Let's see if I depends on anything interesting. */
2919 for (k
= 0; k
< num
; k
++)
2922 struct attr_value
*av
;
2923 for (av
= all
[i
]->first_value
; av
; av
= av
->next
)
2924 if (av
->num_insns
!= 0)
2925 if (tests_attr_p (av
->value
, all
[k
]))
2929 /* Something in I depends on K. */
2934 /* Nothing in I depended on anything intersting, so
2937 sorted
[j
++] = all
[i
];
2943 for (j
= 0; j
< num
; j
++)
2945 struct attr_desc
*attr2
;
2946 struct attr_value
*av
;
2949 fprintf (stderr
, "%s depends on: ", attr
->name
);
2950 for (i
= 0; i
< MAX_ATTRS_INDEX
; ++i
)
2951 for (attr2
= attrs
[i
]; attr2
; attr2
= attr2
->next
)
2952 if (!attr2
->is_const
)
2953 for (av
= attr
->first_value
; av
; av
= av
->next
)
2954 if (av
->num_insns
!= 0)
2955 if (tests_attr_p (av
->value
, attr2
))
2957 fprintf (stderr
, "%s, ", attr2
->name
);
2960 fprintf (stderr
, "\n");
2968 /* Optimize the attribute lists by seeing if we can determine conditional
2969 values from the known values of other attributes. This will save subroutine
2970 calls during the compilation. */
2973 optimize_attrs (void)
2975 struct attr_desc
*attr
;
2976 struct attr_value
*av
;
2977 struct insn_ent
*ie
;
2980 struct attr_value_list
*ivbuf
;
2981 struct attr_value_list
*iv
;
2982 struct attr_desc
**topsort
;
2985 /* For each insn code, make a list of all the insn_ent's for it,
2986 for all values for all attributes. */
2988 if (num_insn_ents
== 0)
2991 /* Make 2 extra elements, for "code" values -2 and -1. */
2992 insn_code_values
= XCNEWVEC (struct attr_value_list
*, insn_code_number
+ 2);
2994 /* Offset the table address so we can index by -2 or -1. */
2995 insn_code_values
+= 2;
2997 iv
= ivbuf
= XNEWVEC (struct attr_value_list
, num_insn_ents
);
2999 /* Create the chain of insn*attr values such that we see dependend
3000 attributes after their dependencies. As we use a stack via the
3001 next pointers start from the end of the topological order. */
3002 topnum
= get_attr_order (&topsort
);
3003 for (i
= topnum
- 1; i
>= 0; i
--)
3004 for (av
= topsort
[i
]->first_value
; av
; av
= av
->next
)
3005 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3007 iv
->attr
= topsort
[i
];
3010 iv
->next
= insn_code_values
[ie
->def
->insn_code
];
3011 insn_code_values
[ie
->def
->insn_code
] = iv
;
3016 /* Sanity check on num_insn_ents. */
3017 gcc_assert (iv
== ivbuf
+ num_insn_ents
);
3019 /* Process one insn code at a time. */
3020 for (i
= -2; i
< insn_code_number
; i
++)
3022 /* Clear the ATTR_CURR_SIMPLIFIED_P flag everywhere relevant.
3023 We use it to mean "already simplified for this insn". */
3024 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3025 clear_struct_flag (iv
->av
->value
);
3027 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3029 struct obstack
*old
= rtl_obstack
;
3034 if (GET_CODE (av
->value
) != COND
)
3037 rtl_obstack
= temp_obstack
;
3039 while (GET_CODE (newexp
) == COND
)
3041 rtx newexp2
= simplify_cond (newexp
, ie
->def
->insn_code
,
3042 ie
->def
->insn_index
);
3043 if (newexp2
== newexp
)
3049 /* If we created a new value for this instruction, and it's
3050 cheaper than the old value, and overall cheap, use that
3051 one as specific value for the current instruction.
3052 The last test is to avoid exploding the get_attr_ function
3053 sizes for no much gain. */
3054 if (newexp
!= av
->value
3055 && attr_rtx_cost (newexp
) < attr_rtx_cost (av
->value
)
3056 && attr_rtx_cost (newexp
) < 26
3059 newexp
= attr_copy_rtx (newexp
);
3060 remove_insn_ent (av
, ie
);
3061 av
= get_attr_value (newexp
, attr
, ie
->def
->insn_code
);
3063 insert_insn_ent (av
, ie
);
3069 free (insn_code_values
- 2);
3070 insn_code_values
= NULL
;
3073 /* Clear the ATTR_CURR_SIMPLIFIED_P flag in EXP and its subexpressions. */
3076 clear_struct_flag (rtx x
)
3083 ATTR_CURR_SIMPLIFIED_P (x
) = 0;
3084 if (ATTR_IND_SIMPLIFIED_P (x
))
3087 code
= GET_CODE (x
);
3106 /* Compare the elements. If any pair of corresponding elements
3107 fail to match, return 0 for the whole things. */
3109 fmt
= GET_RTX_FORMAT (code
);
3110 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3116 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3117 clear_struct_flag (XVECEXP (x
, i
, j
));
3121 clear_struct_flag (XEXP (x
, i
));
3127 /* Add attribute value NAME to the beginning of ATTR's list. */
3130 add_attr_value (struct attr_desc
*attr
, const char *name
)
3132 struct attr_value
*av
;
3134 av
= oballoc (struct attr_value
);
3135 av
->value
= attr_rtx (CONST_STRING
, name
);
3136 av
->next
= attr
->first_value
;
3137 attr
->first_value
= av
;
3138 av
->first_insn
= NULL
;
3140 av
->has_asm_insn
= 0;
3143 /* Create table entries for DEFINE_ATTR or DEFINE_ENUM_ATTR. */
3146 gen_attr (rtx exp
, int lineno
)
3148 struct enum_type
*et
;
3149 struct enum_value
*ev
;
3150 struct attr_desc
*attr
;
3151 const char *name_ptr
;
3154 /* Make a new attribute structure. Check for duplicate by looking at
3155 attr->default_val, since it is initialized by this routine. */
3156 attr
= find_attr (&XSTR (exp
, 0), 1);
3157 if (attr
->default_val
)
3159 error_with_line (lineno
, "duplicate definition for attribute %s",
3161 message_with_line (attr
->lineno
, "previous definition");
3164 attr
->lineno
= lineno
;
3166 if (GET_CODE (exp
) == DEFINE_ENUM_ATTR
)
3168 attr
->enum_name
= XSTR (exp
, 1);
3169 et
= lookup_enum_type (XSTR (exp
, 1));
3170 if (!et
|| !et
->md_p
)
3171 error_with_line (lineno
, "No define_enum called `%s' defined",
3174 for (ev
= et
->values
; ev
; ev
= ev
->next
)
3175 add_attr_value (attr
, ev
->name
);
3177 else if (*XSTR (exp
, 1) == '\0')
3178 attr
->is_numeric
= 1;
3181 name_ptr
= XSTR (exp
, 1);
3182 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
3183 add_attr_value (attr
, p
);
3186 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
3189 if (attr
->is_numeric
)
3190 error_with_line (lineno
,
3191 "constant attributes may not take numeric values");
3193 /* Get rid of the CONST node. It is allowed only at top-level. */
3194 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
3197 if (! strcmp_check (attr
->name
, length_str
) && ! attr
->is_numeric
)
3198 error_with_line (lineno
, "`length' attribute must take numeric values");
3200 /* Set up the default value. */
3201 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
3202 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
3205 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
3206 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
3207 number of alternatives as this should be checked elsewhere. */
3210 count_alternatives (rtx exp
)
3215 if (GET_CODE (exp
) == MATCH_OPERAND
)
3216 return n_comma_elts (XSTR (exp
, 2));
3218 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3219 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3224 n
= count_alternatives (XEXP (exp
, i
));
3231 if (XVEC (exp
, i
) != NULL
)
3232 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3234 n
= count_alternatives (XVECEXP (exp
, i
, j
));
3243 /* Returns nonzero if the given expression contains an EQ_ATTR with the
3244 `alternative' attribute. */
3247 compares_alternatives_p (rtx exp
)
3252 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
3255 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3256 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3261 if (compares_alternatives_p (XEXP (exp
, i
)))
3266 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3267 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
3275 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
3278 gen_insn (rtx exp
, int lineno
)
3280 struct insn_def
*id
;
3282 id
= oballoc (struct insn_def
);
3286 id
->lineno
= lineno
;
3288 switch (GET_CODE (exp
))
3291 id
->insn_code
= insn_code_number
;
3292 id
->insn_index
= insn_index_number
;
3293 id
->num_alternatives
= count_alternatives (exp
);
3294 if (id
->num_alternatives
== 0)
3295 id
->num_alternatives
= 1;
3299 case DEFINE_PEEPHOLE
:
3300 id
->insn_code
= insn_code_number
;
3301 id
->insn_index
= insn_index_number
;
3302 id
->num_alternatives
= count_alternatives (exp
);
3303 if (id
->num_alternatives
== 0)
3304 id
->num_alternatives
= 1;
3308 case DEFINE_ASM_ATTRIBUTES
:
3310 id
->insn_index
= -1;
3311 id
->num_alternatives
= 1;
3313 got_define_asm_attributes
= 1;
3321 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
3322 true or annul false is specified, and make a `struct delay_desc'. */
3325 gen_delay (rtx def
, int lineno
)
3327 struct delay_desc
*delay
;
3330 if (XVECLEN (def
, 1) % 3 != 0)
3332 error_with_line (lineno
,
3333 "number of elements in DEFINE_DELAY must"
3334 " be multiple of three");
3338 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
3340 if (XVECEXP (def
, 1, i
+ 1))
3341 have_annul_true
= 1;
3342 if (XVECEXP (def
, 1, i
+ 2))
3343 have_annul_false
= 1;
3346 delay
= oballoc (struct delay_desc
);
3348 delay
->num
= ++num_delays
;
3349 delay
->next
= delays
;
3350 delay
->lineno
= lineno
;
3354 /* Names of attributes that could be possibly cached. */
3355 static const char *cached_attrs
[32];
3356 /* Number of such attributes. */
3357 static int cached_attr_count
;
3358 /* Bitmasks of possibly cached attributes. */
3359 static unsigned int attrs_seen_once
, attrs_seen_more_than_once
;
3360 static unsigned int attrs_to_cache
;
3361 static unsigned int attrs_cached_inside
, attrs_cached_after
;
3363 /* Finds non-const attributes that could be possibly cached.
3364 When create is TRUE, fills in cached_attrs array.
3365 Computes ATTRS_SEEN_ONCE and ATTRS_SEEN_MORE_THAN_ONCE
3369 find_attrs_to_cache (rtx exp
, bool create
)
3373 struct attr_desc
*attr
;
3378 switch (GET_CODE (exp
))
3381 if (GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3382 find_attrs_to_cache (XEXP (exp
, 0), create
);
3386 name
= XSTR (exp
, 0);
3387 if (name
== alternative_name
)
3389 for (i
= 0; i
< cached_attr_count
; i
++)
3390 if (name
== cached_attrs
[i
])
3392 if ((attrs_seen_once
& (1U << i
)) != 0)
3393 attrs_seen_more_than_once
|= (1U << i
);
3395 attrs_seen_once
|= (1U << i
);
3400 attr
= find_attr (&name
, 0);
3404 if (cached_attr_count
== 32)
3406 cached_attrs
[cached_attr_count
] = XSTR (exp
, 0);
3407 attrs_seen_once
|= (1U << cached_attr_count
);
3408 cached_attr_count
++;
3413 find_attrs_to_cache (XEXP (exp
, 0), create
);
3414 find_attrs_to_cache (XEXP (exp
, 1), create
);
3418 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3419 find_attrs_to_cache (XVECEXP (exp
, 0, i
), create
);
3427 /* Given a piece of RTX, print a C expression to test its truth value to OUTF.
3428 We use AND and IOR both for logical and bit-wise operations, so
3429 interpret them as logical unless they are inside a comparison expression. */
3431 /* Interpret AND/IOR as bit-wise operations instead of logical. */
3432 #define FLG_BITWISE 1
3433 /* Set if cached attribute will be known initialized in else block after
3434 this condition. This is true for LHS of toplevel && and || and
3435 even for RHS of ||, but not for RHS of &&. */
3437 /* Set if cached attribute will be known initialized in then block after
3438 this condition. This is true for LHS of toplevel && and || and
3439 even for RHS of &&, but not for RHS of ||. */
3440 #define FLG_INSIDE 4
3441 /* Cleared when an operand of &&. */
3442 #define FLG_OUTSIDE_AND 8
3445 write_test_expr (FILE *outf
, rtx exp
, unsigned int attrs_cached
, int flags
)
3447 int comparison_operator
= 0;
3449 struct attr_desc
*attr
;
3451 /* In order not to worry about operator precedence, surround our part of
3452 the expression with parentheses. */
3454 fprintf (outf
, "(");
3455 code
= GET_CODE (exp
);
3458 /* Binary operators. */
3461 fprintf (outf
, "(unsigned) ");
3467 comparison_operator
= FLG_BITWISE
;
3469 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
3470 case AND
: case IOR
: case XOR
:
3471 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
3472 if ((code
!= AND
&& code
!= IOR
) || (flags
& FLG_BITWISE
))
3474 flags
&= ~(FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
);
3475 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
,
3476 flags
| comparison_operator
);
3481 flags
&= ~FLG_OUTSIDE_AND
;
3482 if (GET_CODE (XEXP (exp
, 0)) == code
3483 || GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3484 || (GET_CODE (XEXP (exp
, 0)) == NOT
3485 && GET_CODE (XEXP (XEXP (exp
, 0), 0)) == EQ_ATTR
))
3487 = write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3489 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3494 fprintf (outf
, " == ");
3497 fprintf (outf
, " != ");
3500 fprintf (outf
, " >= ");
3503 fprintf (outf
, " > ");
3506 fprintf (outf
, " >= (unsigned) ");
3509 fprintf (outf
, " > (unsigned) ");
3512 fprintf (outf
, " <= ");
3515 fprintf (outf
, " < ");
3518 fprintf (outf
, " <= (unsigned) ");
3521 fprintf (outf
, " < (unsigned) ");
3524 fprintf (outf
, " + ");
3527 fprintf (outf
, " - ");
3530 fprintf (outf
, " * ");
3533 fprintf (outf
, " / ");
3536 fprintf (outf
, " %% ");
3539 if (flags
& FLG_BITWISE
)
3540 fprintf (outf
, " & ");
3542 fprintf (outf
, " && ");
3545 if (flags
& FLG_BITWISE
)
3546 fprintf (outf
, " | ");
3548 fprintf (outf
, " || ");
3551 fprintf (outf
, " ^ ");
3554 fprintf (outf
, " << ");
3558 fprintf (outf
, " >> ");
3566 /* For if (something && (cached_x = get_attr_x (insn)) == X)
3567 cached_x is only known to be initialized in then block. */
3568 flags
&= ~FLG_AFTER
;
3570 else if (code
== IOR
)
3572 if (flags
& FLG_OUTSIDE_AND
)
3573 /* For if (something || (cached_x = get_attr_x (insn)) == X)
3574 cached_x is only known to be initialized in else block
3575 and else if conditions. */
3576 flags
&= ~FLG_INSIDE
;
3578 /* For if ((something || (cached_x = get_attr_x (insn)) == X)
3580 cached_x is not know to be initialized anywhere. */
3581 flags
&= ~(FLG_AFTER
| FLG_INSIDE
);
3583 if ((code
== AND
|| code
== IOR
)
3584 && (GET_CODE (XEXP (exp
, 1)) == code
3585 || GET_CODE (XEXP (exp
, 1)) == EQ_ATTR
3586 || (GET_CODE (XEXP (exp
, 1)) == NOT
3587 && GET_CODE (XEXP (XEXP (exp
, 1), 0)) == EQ_ATTR
)))
3589 = write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
, flags
);
3591 write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
,
3592 flags
| comparison_operator
);
3596 /* Special-case (not (eq_attrq "alternative" "x")) */
3597 if (! (flags
& FLG_BITWISE
) && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3599 if (XSTR (XEXP (exp
, 0), 0) == alternative_name
)
3601 fprintf (outf
, "which_alternative != %s",
3602 XSTR (XEXP (exp
, 0), 1));
3606 fprintf (outf
, "! ");
3608 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3612 /* Otherwise, fall through to normal unary operator. */
3614 /* Unary operators. */
3619 if (flags
& FLG_BITWISE
)
3620 fprintf (outf
, "~ ");
3622 fprintf (outf
, "! ");
3625 fprintf (outf
, "abs ");
3628 fprintf (outf
, "-");
3634 flags
&= ~(FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
);
3635 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, flags
);
3640 int set
= XINT (exp
, 0), bit
= 0;
3642 if (flags
& FLG_BITWISE
)
3643 fatal ("EQ_ATTR_ALT not valid inside comparison");
3646 fatal ("Empty EQ_ATTR_ALT should be optimized out");
3648 if (!(set
& (set
- 1)))
3650 if (!(set
& 0xffff))
3673 fprintf (outf
, "which_alternative %s= %d",
3674 XINT (exp
, 1) ? "!" : "=", bit
);
3678 fprintf (outf
, "%s((1 << which_alternative) & %#x)",
3679 XINT (exp
, 1) ? "!" : "", set
);
3684 /* Comparison test of an attribute with a value. Most of these will
3685 have been removed by optimization. Handle "alternative"
3686 specially and give error if EQ_ATTR present inside a comparison. */
3688 if (flags
& FLG_BITWISE
)
3689 fatal ("EQ_ATTR not valid inside comparison");
3691 if (XSTR (exp
, 0) == alternative_name
)
3693 fprintf (outf
, "which_alternative == %s", XSTR (exp
, 1));
3697 attr
= find_attr (&XSTR (exp
, 0), 0);
3700 /* Now is the time to expand the value of a constant attribute. */
3703 write_test_expr (outf
,
3704 evaluate_eq_attr (exp
, attr
,
3705 attr
->default_val
->value
,
3712 for (i
= 0; i
< cached_attr_count
; i
++)
3713 if (attr
->name
== cached_attrs
[i
])
3715 if (i
< cached_attr_count
&& (attrs_cached
& (1U << i
)) != 0)
3716 fprintf (outf
, "cached_%s", attr
->name
);
3717 else if (i
< cached_attr_count
&& (attrs_to_cache
& (1U << i
)) != 0)
3719 fprintf (outf
, "(cached_%s = get_attr_%s (insn))",
3720 attr
->name
, attr
->name
);
3721 if (flags
& FLG_AFTER
)
3722 attrs_cached_after
|= (1U << i
);
3723 if (flags
& FLG_INSIDE
)
3724 attrs_cached_inside
|= (1U << i
);
3725 attrs_cached
|= (1U << i
);
3728 fprintf (outf
, "get_attr_%s (insn)", attr
->name
);
3729 fprintf (outf
, " == ");
3730 write_attr_valueq (outf
, attr
, XSTR (exp
, 1));
3734 /* Comparison test of flags for define_delays. */
3736 if (flags
& FLG_BITWISE
)
3737 fatal ("ATTR_FLAG not valid inside comparison");
3738 fprintf (outf
, "(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
3741 /* See if an operand matches a predicate. */
3743 /* If only a mode is given, just ensure the mode matches the operand.
3744 If neither a mode nor predicate is given, error. */
3745 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
3747 if (GET_MODE (exp
) == VOIDmode
)
3748 fatal ("null MATCH_OPERAND specified as test");
3750 fprintf (outf
, "GET_MODE (operands[%d]) == %smode",
3751 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3754 fprintf (outf
, "%s (operands[%d], %smode)",
3755 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3758 /* Constant integer. */
3760 fprintf (outf
, HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
3764 fprint_c_condition (outf
, XSTR (exp
, 0));
3765 if (flags
& FLG_BITWISE
)
3766 fprintf (outf
, " != 0");
3769 /* A random C expression. */
3771 fprint_c_condition (outf
, XSTR (exp
, 0));
3774 /* The address of the branch target. */
3777 "INSN_ADDRESSES_SET_P () ? INSN_ADDRESSES (INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])) : 0",
3778 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
3782 /* The address of the current insn. We implement this actually as the
3783 address of the current insn for backward branches, but the last
3784 address of the next insn for forward branches, and both with
3785 adjustments that account for the worst-case possible stretching of
3786 intervening alignments between this insn and its destination. */
3787 fprintf (outf
, "insn_current_reference_address (insn)");
3791 fprintf (outf
, "%s", XSTR (exp
, 0));
3795 write_test_expr (outf
, XEXP (exp
, 0), attrs_cached
, 0);
3796 fprintf (outf
, " ? ");
3797 write_test_expr (outf
, XEXP (exp
, 1), attrs_cached
, FLG_BITWISE
);
3798 fprintf (outf
, " : ");
3799 write_test_expr (outf
, XEXP (exp
, 2), attrs_cached
, FLG_BITWISE
);
3803 fatal ("bad RTX code `%s' in attribute calculation\n",
3804 GET_RTX_NAME (code
));
3807 fprintf (outf
, ")");
3808 return attrs_cached
;
3811 /* Given an attribute value, return the maximum CONST_STRING argument
3812 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
3815 max_attr_value (rtx exp
, int *unknownp
)
3820 switch (GET_CODE (exp
))
3823 current_max
= atoi (XSTR (exp
, 0));
3827 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
3828 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3830 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3831 if (n
> current_max
)
3837 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
3838 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
3839 if (n
> current_max
)
3845 current_max
= INT_MAX
;
3852 /* Given an attribute value, return the minimum CONST_STRING argument
3853 encountered. Set *UNKNOWNP and return 0 if the value is unknown. */
3856 min_attr_value (rtx exp
, int *unknownp
)
3861 switch (GET_CODE (exp
))
3864 current_min
= atoi (XSTR (exp
, 0));
3868 current_min
= min_attr_value (XEXP (exp
, 1), unknownp
);
3869 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3871 n
= min_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3872 if (n
< current_min
)
3878 current_min
= min_attr_value (XEXP (exp
, 1), unknownp
);
3879 n
= min_attr_value (XEXP (exp
, 2), unknownp
);
3880 if (n
< current_min
)
3886 current_min
= INT_MAX
;
3893 /* Given an attribute value, return the result of ORing together all
3894 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
3895 if the numeric value is not known. */
3898 or_attr_value (rtx exp
, int *unknownp
)
3903 switch (GET_CODE (exp
))
3906 current_or
= atoi (XSTR (exp
, 0));
3910 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
3911 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3912 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
3916 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
3917 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
3929 /* Scan an attribute value, possibly a conditional, and record what actions
3930 will be required to do any conditional tests in it.
3933 `must_extract' if we need to extract the insn operands
3934 `must_constrain' if we must compute `which_alternative'
3935 `address_used' if an address expression was used
3936 `length_used' if an (eq_attr "length" ...) was used
3940 walk_attr_value (rtx exp
)
3949 code
= GET_CODE (exp
);
3953 if (! ATTR_IND_SIMPLIFIED_P (exp
))
3954 /* Since this is an arbitrary expression, it can look at anything.
3955 However, constant expressions do not depend on any particular
3957 must_extract
= must_constrain
= 1;
3966 must_extract
= must_constrain
= 1;
3970 if (XSTR (exp
, 0) == alternative_name
)
3971 must_extract
= must_constrain
= 1;
3972 else if (strcmp_check (XSTR (exp
, 0), length_str
) == 0)
3992 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
3997 walk_attr_value (XEXP (exp
, i
));
4001 if (XVEC (exp
, i
) != NULL
)
4002 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4003 walk_attr_value (XVECEXP (exp
, i
, j
));
4008 /* Write out a function to obtain the attribute for a given INSN. */
4011 write_attr_get (FILE *outf
, struct attr_desc
*attr
)
4013 struct attr_value
*av
, *common_av
;
4016 /* Find the most used attribute value. Handle that as the `default' of the
4017 switch we will generate. */
4018 common_av
= find_most_used (attr
);
4020 /* Write out start of function, then all values with explicit `case' lines,
4021 then a `default', then the value with the most uses. */
4022 if (attr
->enum_name
)
4023 fprintf (outf
, "enum %s\n", attr
->enum_name
);
4024 else if (!attr
->is_numeric
)
4025 fprintf (outf
, "enum attr_%s\n", attr
->name
);
4027 fprintf (outf
, "int\n");
4029 /* If the attribute name starts with a star, the remainder is the name of
4030 the subroutine to use, instead of `get_attr_...'. */
4031 if (attr
->name
[0] == '*')
4032 fprintf (outf
, "%s (rtx insn ATTRIBUTE_UNUSED)\n", &attr
->name
[1]);
4033 else if (attr
->is_const
== 0)
4034 fprintf (outf
, "get_attr_%s (rtx insn ATTRIBUTE_UNUSED)\n", attr
->name
);
4037 fprintf (outf
, "get_attr_%s (void)\n", attr
->name
);
4038 fprintf (outf
, "{\n");
4040 for (av
= attr
->first_value
; av
; av
= av
->next
)
4041 if (av
->num_insns
== 1)
4042 write_attr_set (outf
, attr
, 2, av
->value
, "return", ";",
4043 true_rtx
, av
->first_insn
->def
->insn_code
,
4044 av
->first_insn
->def
->insn_index
, 0);
4045 else if (av
->num_insns
!= 0)
4046 write_attr_set (outf
, attr
, 2, av
->value
, "return", ";",
4047 true_rtx
, -2, 0, 0);
4049 fprintf (outf
, "}\n\n");
4053 fprintf (outf
, "{\n");
4055 /* Find attributes that are worth caching in the conditions. */
4056 cached_attr_count
= 0;
4057 attrs_seen_more_than_once
= 0;
4058 for (av
= attr
->first_value
; av
; av
= av
->next
)
4060 attrs_seen_once
= 0;
4061 find_attrs_to_cache (av
->value
, true);
4063 /* Remove those that aren't worth caching from the array. */
4064 for (i
= 0, j
= 0; i
< cached_attr_count
; i
++)
4065 if ((attrs_seen_more_than_once
& (1U << i
)) != 0)
4067 const char *name
= cached_attrs
[i
];
4068 struct attr_desc
*cached_attr
;
4070 cached_attrs
[j
] = name
;
4071 cached_attr
= find_attr (&name
, 0);
4072 gcc_assert (cached_attr
&& cached_attr
->is_const
== 0);
4073 if (cached_attr
->enum_name
)
4074 fprintf (outf
, " enum %s", cached_attr
->enum_name
);
4075 else if (!cached_attr
->is_numeric
)
4076 fprintf (outf
, " enum attr_%s", cached_attr
->name
);
4078 fprintf (outf
, " int");
4079 fprintf (outf
, " cached_%s ATTRIBUTE_UNUSED;\n", name
);
4082 cached_attr_count
= j
;
4083 if (cached_attr_count
)
4084 fprintf (outf
, "\n");
4086 fprintf (outf
, " switch (recog_memoized (insn))\n");
4087 fprintf (outf
, " {\n");
4089 for (av
= attr
->first_value
; av
; av
= av
->next
)
4090 if (av
!= common_av
)
4091 write_attr_case (outf
, attr
, av
, 1, "return", ";", 4, true_rtx
);
4093 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4094 fprintf (outf
, " }\n}\n\n");
4095 cached_attr_count
= 0;
4098 /* Given an AND tree of known true terms (because we are inside an `if' with
4099 that as the condition or are in an `else' clause) and an expression,
4100 replace any known true terms with TRUE. Use `simplify_and_tree' to do
4101 the bulk of the work. */
4104 eliminate_known_true (rtx known_true
, rtx exp
, int insn_code
, int insn_index
)
4108 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
4110 if (GET_CODE (known_true
) == AND
)
4112 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
4113 insn_code
, insn_index
);
4114 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
4115 insn_code
, insn_index
);
4120 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
4126 /* Write out a series of tests and assignment statements to perform tests and
4127 sets of an attribute value. We are passed an indentation amount and prefix
4128 and suffix strings to write around each attribute value (e.g., "return"
4132 write_attr_set (FILE *outf
, struct attr_desc
*attr
, int indent
, rtx value
,
4133 const char *prefix
, const char *suffix
, rtx known_true
,
4134 int insn_code
, int insn_index
, unsigned int attrs_cached
)
4136 if (GET_CODE (value
) == COND
)
4138 /* Assume the default value will be the default of the COND unless we
4139 find an always true expression. */
4140 rtx default_val
= XEXP (value
, 1);
4141 rtx our_known_true
= known_true
;
4146 if (cached_attr_count
)
4148 attrs_seen_once
= 0;
4149 attrs_seen_more_than_once
= 0;
4150 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4151 find_attrs_to_cache (XVECEXP (value
, 0, i
), false);
4152 attrs_to_cache
|= attrs_seen_more_than_once
;
4155 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4160 /* Reset our_known_true after some time to not accumulate
4161 too much cruft (slowing down genattrtab). */
4163 our_known_true
= known_true
;
4164 testexp
= eliminate_known_true (our_known_true
,
4165 XVECEXP (value
, 0, i
),
4166 insn_code
, insn_index
);
4167 newexp
= attr_rtx (NOT
, testexp
);
4168 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
4169 insn_code
, insn_index
);
4171 /* If the test expression is always true or if the next `known_true'
4172 expression is always false, this is the last case, so break
4173 out and let this value be the `else' case. */
4174 if (testexp
== true_rtx
|| newexp
== false_rtx
)
4176 default_val
= XVECEXP (value
, 0, i
+ 1);
4180 /* Compute the expression to pass to our recursive call as being
4182 inner_true
= insert_right_side (AND
, our_known_true
,
4183 testexp
, insn_code
, insn_index
);
4185 /* If this is always false, skip it. */
4186 if (inner_true
== false_rtx
)
4189 attrs_cached_inside
= attrs_cached
;
4190 attrs_cached_after
= attrs_cached
;
4191 write_indent (outf
, indent
);
4192 fprintf (outf
, "%sif ", first_if
? "" : "else ");
4194 write_test_expr (outf
, testexp
, attrs_cached
,
4195 (FLG_AFTER
| FLG_INSIDE
| FLG_OUTSIDE_AND
));
4196 attrs_cached
= attrs_cached_after
;
4197 fprintf (outf
, "\n");
4198 write_indent (outf
, indent
+ 2);
4199 fprintf (outf
, "{\n");
4201 write_attr_set (outf
, attr
, indent
+ 4,
4202 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
4203 inner_true
, insn_code
, insn_index
,
4204 attrs_cached_inside
);
4205 write_indent (outf
, indent
+ 2);
4206 fprintf (outf
, "}\n");
4207 our_known_true
= newexp
;
4212 write_indent (outf
, indent
);
4213 fprintf (outf
, "else\n");
4214 write_indent (outf
, indent
+ 2);
4215 fprintf (outf
, "{\n");
4218 write_attr_set (outf
, attr
, first_if
? indent
: indent
+ 4, default_val
,
4219 prefix
, suffix
, our_known_true
, insn_code
, insn_index
,
4224 write_indent (outf
, indent
+ 2);
4225 fprintf (outf
, "}\n");
4230 write_indent (outf
, indent
);
4231 fprintf (outf
, "%s ", prefix
);
4232 write_attr_value (outf
, attr
, value
);
4233 fprintf (outf
, "%s\n", suffix
);
4237 /* Write a series of case statements for every instruction in list IE.
4238 INDENT is the amount of indentation to write before each case. */
4241 write_insn_cases (FILE *outf
, struct insn_ent
*ie
, int indent
)
4243 for (; ie
!= 0; ie
= ie
->next
)
4244 if (ie
->def
->insn_code
!= -1)
4246 write_indent (outf
, indent
);
4247 if (GET_CODE (ie
->def
->def
) == DEFINE_PEEPHOLE
)
4248 fprintf (outf
, "case %d: /* define_peephole, line %d */\n",
4249 ie
->def
->insn_code
, ie
->def
->lineno
);
4251 fprintf (outf
, "case %d: /* %s */\n",
4252 ie
->def
->insn_code
, XSTR (ie
->def
->def
, 0));
4256 /* Write out the computation for one attribute value. */
4259 write_attr_case (FILE *outf
, struct attr_desc
*attr
, struct attr_value
*av
,
4260 int write_case_lines
, const char *prefix
, const char *suffix
,
4261 int indent
, rtx known_true
)
4263 if (av
->num_insns
== 0)
4266 if (av
->has_asm_insn
)
4268 write_indent (outf
, indent
);
4269 fprintf (outf
, "case -1:\n");
4270 write_indent (outf
, indent
+ 2);
4271 fprintf (outf
, "if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
4272 write_indent (outf
, indent
+ 2);
4273 fprintf (outf
, " && asm_noperands (PATTERN (insn)) < 0)\n");
4274 write_indent (outf
, indent
+ 2);
4275 fprintf (outf
, " fatal_insn_not_found (insn);\n");
4278 if (write_case_lines
)
4279 write_insn_cases (outf
, av
->first_insn
, indent
);
4282 write_indent (outf
, indent
);
4283 fprintf (outf
, "default:\n");
4286 /* See what we have to do to output this value. */
4287 must_extract
= must_constrain
= address_used
= 0;
4288 walk_attr_value (av
->value
);
4292 write_indent (outf
, indent
+ 2);
4293 fprintf (outf
, "extract_constrain_insn_cached (insn);\n");
4295 else if (must_extract
)
4297 write_indent (outf
, indent
+ 2);
4298 fprintf (outf
, "extract_insn_cached (insn);\n");
4302 if (av
->num_insns
== 1)
4303 write_attr_set (outf
, attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4304 known_true
, av
->first_insn
->def
->insn_code
,
4305 av
->first_insn
->def
->insn_index
, 0);
4307 write_attr_set (outf
, attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4308 known_true
, -2, 0, 0);
4310 if (strncmp (prefix
, "return", 6))
4312 write_indent (outf
, indent
+ 2);
4313 fprintf (outf
, "break;\n");
4315 fprintf (outf
, "\n");
4318 /* Utilities to write in various forms. */
4321 write_attr_valueq (FILE *outf
, struct attr_desc
*attr
, const char *s
)
4323 if (attr
->is_numeric
)
4327 fprintf (outf
, "%d", num
);
4329 if (num
> 9 || num
< 0)
4330 fprintf (outf
, " /* %#x */", num
);
4334 write_upcase (outf
, attr
->enum_name
? attr
->enum_name
: attr
->name
);
4335 fprintf (outf
, "_");
4336 write_upcase (outf
, s
);
4341 write_attr_value (FILE *outf
, struct attr_desc
*attr
, rtx value
)
4345 switch (GET_CODE (value
))
4348 write_attr_valueq (outf
, attr
, XSTR (value
, 0));
4352 fprintf (outf
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (value
));
4356 fprint_c_condition (outf
, XSTR (value
, 0));
4361 struct attr_desc
*attr2
= find_attr (&XSTR (value
, 0), 0);
4362 if (attr
->enum_name
)
4363 fprintf (outf
, "(enum %s)", attr
->enum_name
);
4364 else if (!attr
->is_numeric
)
4365 fprintf (outf
, "(enum attr_%s)", attr
->name
);
4366 else if (!attr2
->is_numeric
)
4367 fprintf (outf
, "(int)");
4369 fprintf (outf
, "get_attr_%s (%s)", attr2
->name
,
4370 (attr2
->is_const
? "" : "insn"));
4391 write_attr_value (outf
, attr
, XEXP (value
, 0));
4395 write_attr_value (outf
, attr
, XEXP (value
, 1));
4404 write_upcase (FILE *outf
, const char *str
)
4408 /* The argument of TOUPPER should not have side effects. */
4409 fputc (TOUPPER(*str
), outf
);
4415 write_indent (FILE *outf
, int indent
)
4417 for (; indent
> 8; indent
-= 8)
4418 fprintf (outf
, "\t");
4420 for (; indent
; indent
--)
4421 fprintf (outf
, " ");
4424 /* Write a subroutine that is given an insn that requires a delay slot, a
4425 delay slot ordinal, and a candidate insn. It returns nonzero if the
4426 candidate can be placed in the specified delay slot of the insn.
4428 We can write as many as three subroutines. `eligible_for_delay'
4429 handles normal delay slots, `eligible_for_annul_true' indicates that
4430 the specified insn can be annulled if the branch is true, and likewise
4431 for `eligible_for_annul_false'.
4433 KIND is a string distinguishing these three cases ("delay", "annul_true",
4434 or "annul_false"). */
4437 write_eligible_delay (FILE *outf
, const char *kind
)
4439 struct delay_desc
*delay
;
4443 struct attr_desc
*attr
;
4444 struct attr_value
*av
, *common_av
;
4447 /* Compute the maximum number of delay slots required. We use the delay
4448 ordinal times this number plus one, plus the slot number as an index into
4449 the appropriate predicate to test. */
4451 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
4452 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
4453 max_slots
= XVECLEN (delay
->def
, 1) / 3;
4455 /* Write function prelude. */
4457 fprintf (outf
, "int\n");
4458 fprintf (outf
, "eligible_for_%s (rtx delay_insn ATTRIBUTE_UNUSED, int slot, \n"
4459 " rtx candidate_insn, int flags ATTRIBUTE_UNUSED)\n",
4461 fprintf (outf
, "{\n");
4462 fprintf (outf
, " rtx insn;\n");
4463 fprintf (outf
, "\n");
4464 fprintf (outf
, " gcc_assert (slot < %d);\n", max_slots
);
4465 fprintf (outf
, "\n");
4466 /* Allow dbr_schedule to pass labels, etc. This can happen if try_split
4467 converts a compound instruction into a loop. */
4468 fprintf (outf
, " if (!INSN_P (candidate_insn))\n");
4469 fprintf (outf
, " return 0;\n");
4470 fprintf (outf
, "\n");
4472 /* If more than one delay type, find out which type the delay insn is. */
4476 attr
= find_attr (&delay_type_str
, 0);
4478 common_av
= find_most_used (attr
);
4480 fprintf (outf
, " insn = delay_insn;\n");
4481 fprintf (outf
, " switch (recog_memoized (insn))\n");
4482 fprintf (outf
, " {\n");
4484 sprintf (str
, " * %d;\n break;", max_slots
);
4485 for (av
= attr
->first_value
; av
; av
= av
->next
)
4486 if (av
!= common_av
)
4487 write_attr_case (outf
, attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
4489 write_attr_case (outf
, attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
4490 fprintf (outf
, " }\n\n");
4492 /* Ensure matched. Otherwise, shouldn't have been called. */
4493 fprintf (outf
, " gcc_assert (slot >= %d);\n\n", max_slots
);
4496 /* If just one type of delay slot, write simple switch. */
4497 if (num_delays
== 1 && max_slots
== 1)
4499 fprintf (outf
, " insn = candidate_insn;\n");
4500 fprintf (outf
, " switch (recog_memoized (insn))\n");
4501 fprintf (outf
, " {\n");
4503 attr
= find_attr (&delay_1_0_str
, 0);
4505 common_av
= find_most_used (attr
);
4507 for (av
= attr
->first_value
; av
; av
= av
->next
)
4508 if (av
!= common_av
)
4509 write_attr_case (outf
, attr
, av
, 1, "return", ";", 4, true_rtx
);
4511 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4512 fprintf (outf
, " }\n");
4517 /* Write a nested CASE. The first indicates which condition we need to
4518 test, and the inner CASE tests the condition. */
4519 fprintf (outf
, " insn = candidate_insn;\n");
4520 fprintf (outf
, " switch (slot)\n");
4521 fprintf (outf
, " {\n");
4523 for (delay
= delays
; delay
; delay
= delay
->next
)
4524 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
4526 fprintf (outf
, " case %d:\n",
4527 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
4528 fprintf (outf
, " switch (recog_memoized (insn))\n");
4529 fprintf (outf
, "\t{\n");
4531 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
4533 attr
= find_attr (&pstr
, 0);
4535 common_av
= find_most_used (attr
);
4537 for (av
= attr
->first_value
; av
; av
= av
->next
)
4538 if (av
!= common_av
)
4539 write_attr_case (outf
, attr
, av
, 1, "return", ";", 8, true_rtx
);
4541 write_attr_case (outf
, attr
, common_av
, 0, "return", ";", 8, true_rtx
);
4542 fprintf (outf
, " }\n");
4545 fprintf (outf
, " default:\n");
4546 fprintf (outf
, " gcc_unreachable ();\n");
4547 fprintf (outf
, " }\n");
4550 fprintf (outf
, "}\n\n");
4553 /* This page contains miscellaneous utility routines. */
4555 /* Given a pointer to a (char *), return a malloc'ed string containing the
4556 next comma-separated element. Advance the pointer to after the string
4557 scanned, or the end-of-string. Return NULL if at end of string. */
4560 next_comma_elt (const char **pstr
)
4564 start
= scan_comma_elt (pstr
);
4569 return attr_string (start
, *pstr
- start
);
4572 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
4573 is nonzero, build a new attribute, if one does not exist. *NAME_P is
4574 replaced by a pointer to a canonical copy of the string. */
4576 static struct attr_desc
*
4577 find_attr (const char **name_p
, int create
)
4579 struct attr_desc
*attr
;
4581 const char *name
= *name_p
;
4583 /* Before we resort to using `strcmp', see if the string address matches
4584 anywhere. In most cases, it should have been canonicalized to do so. */
4585 if (name
== alternative_name
)
4588 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
4589 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4590 if (name
== attr
->name
)
4593 /* Otherwise, do it the slow way. */
4594 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4595 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
4597 *name_p
= attr
->name
;
4604 attr
= oballoc (struct attr_desc
);
4605 attr
->name
= DEF_ATTR_STRING (name
);
4606 attr
->enum_name
= 0;
4607 attr
->first_value
= attr
->default_val
= NULL
;
4608 attr
->is_numeric
= attr
->is_const
= attr
->is_special
= 0;
4609 attr
->next
= attrs
[index
];
4610 attrs
[index
] = attr
;
4612 *name_p
= attr
->name
;
4617 /* Create internal attribute with the given default value. */
4620 make_internal_attr (const char *name
, rtx value
, int special
)
4622 struct attr_desc
*attr
;
4624 attr
= find_attr (&name
, 1);
4625 gcc_assert (!attr
->default_val
);
4627 attr
->is_numeric
= 1;
4629 attr
->is_special
= (special
& ATTR_SPECIAL
) != 0;
4630 attr
->default_val
= get_attr_value (value
, attr
, -2);
4633 /* Find the most used value of an attribute. */
4635 static struct attr_value
*
4636 find_most_used (struct attr_desc
*attr
)
4638 struct attr_value
*av
;
4639 struct attr_value
*most_used
;
4645 for (av
= attr
->first_value
; av
; av
= av
->next
)
4646 if (av
->num_insns
> nuses
)
4647 nuses
= av
->num_insns
, most_used
= av
;
4652 /* Return (attr_value "n") */
4655 make_numeric_value (int n
)
4657 static rtx int_values
[20];
4661 gcc_assert (n
>= 0);
4663 if (n
< 20 && int_values
[n
])
4664 return int_values
[n
];
4666 p
= attr_printf (MAX_DIGITS
, "%d", n
);
4667 exp
= attr_rtx (CONST_STRING
, p
);
4670 int_values
[n
] = exp
;
4676 copy_rtx_unchanging (rtx orig
)
4678 if (ATTR_IND_SIMPLIFIED_P (orig
) || ATTR_CURR_SIMPLIFIED_P (orig
))
4681 ATTR_CURR_SIMPLIFIED_P (orig
) = 1;
4685 /* Determine if an insn has a constant number of delay slots, i.e., the
4686 number of delay slots is not a function of the length of the insn. */
4689 write_const_num_delay_slots (FILE *outf
)
4691 struct attr_desc
*attr
= find_attr (&num_delay_slots_str
, 0);
4692 struct attr_value
*av
;
4696 fprintf (outf
, "int\nconst_num_delay_slots (rtx insn)\n");
4697 fprintf (outf
, "{\n");
4698 fprintf (outf
, " switch (recog_memoized (insn))\n");
4699 fprintf (outf
, " {\n");
4701 for (av
= attr
->first_value
; av
; av
= av
->next
)
4704 walk_attr_value (av
->value
);
4706 write_insn_cases (outf
, av
->first_insn
, 4);
4709 fprintf (outf
, " default:\n");
4710 fprintf (outf
, " return 1;\n");
4711 fprintf (outf
, " }\n}\n\n");
4715 /* Synthetic attributes used by insn-automata.c and the scheduler.
4716 These are primarily concerned with (define_insn_reservation)
4721 struct insn_reserv
*next
;
4724 int default_latency
;
4727 /* Sequence number of this insn. */
4730 /* Whether a (define_bypass) construct names this insn in its
4735 static struct insn_reserv
*all_insn_reservs
= 0;
4736 static struct insn_reserv
**last_insn_reserv_p
= &all_insn_reservs
;
4737 static size_t n_insn_reservs
;
4739 /* Store information from a DEFINE_INSN_RESERVATION for future
4740 attribute generation. */
4742 gen_insn_reserv (rtx def
)
4744 struct insn_reserv
*decl
= oballoc (struct insn_reserv
);
4746 decl
->name
= DEF_ATTR_STRING (XSTR (def
, 0));
4747 decl
->default_latency
= XINT (def
, 1);
4748 decl
->condexp
= check_attr_test (XEXP (def
, 2), 0, 0);
4749 decl
->insn_num
= n_insn_reservs
;
4750 decl
->bypassed
= false;
4753 *last_insn_reserv_p
= decl
;
4754 last_insn_reserv_p
= &decl
->next
;
4758 /* Store information from a DEFINE_BYPASS for future attribute
4759 generation. The only thing we care about is the list of output
4760 insns, which will later be used to tag reservation structures with
4761 a 'bypassed' bit. */
4765 struct bypass_list
*next
;
4766 const char *pattern
;
4769 static struct bypass_list
*all_bypasses
;
4770 static size_t n_bypasses
;
4773 gen_bypass_1 (const char *s
, size_t len
)
4775 struct bypass_list
*b
;
4780 s
= attr_string (s
, len
);
4781 for (b
= all_bypasses
; b
; b
= b
->next
)
4782 if (s
== b
->pattern
)
4783 return; /* already got that one */
4785 b
= oballoc (struct bypass_list
);
4787 b
->next
= all_bypasses
;
4793 gen_bypass (rtx def
)
4795 const char *p
, *base
;
4797 for (p
= base
= XSTR (def
, 1); *p
; p
++)
4800 gen_bypass_1 (base
, p
- base
);
4803 while (ISSPACE (*p
));
4806 gen_bypass_1 (base
, p
- base
);
4809 /* Find and mark all of the bypassed insns. */
4811 process_bypasses (void)
4813 struct bypass_list
*b
;
4814 struct insn_reserv
*r
;
4816 /* The reservation list is likely to be much longer than the bypass
4818 for (r
= all_insn_reservs
; r
; r
= r
->next
)
4819 for (b
= all_bypasses
; b
; b
= b
->next
)
4820 if (fnmatch (b
->pattern
, r
->name
, 0) == 0)
4824 /* Check that attribute NAME is used in define_insn_reservation condition
4825 EXP. Return true if it is. */
4827 check_tune_attr (const char *name
, rtx exp
)
4829 switch (GET_CODE (exp
))
4832 if (check_tune_attr (name
, XEXP (exp
, 0)))
4834 return check_tune_attr (name
, XEXP (exp
, 1));
4837 return (check_tune_attr (name
, XEXP (exp
, 0))
4838 && check_tune_attr (name
, XEXP (exp
, 1)));
4841 return XSTR (exp
, 0) == name
;
4848 /* Try to find a const attribute (usually cpu or tune) that is used
4849 in all define_insn_reservation conditions. */
4850 static struct attr_desc
*
4851 find_tune_attr (rtx exp
)
4853 struct attr_desc
*attr
;
4855 switch (GET_CODE (exp
))
4859 attr
= find_tune_attr (XEXP (exp
, 0));
4862 return find_tune_attr (XEXP (exp
, 1));
4865 if (XSTR (exp
, 0) == alternative_name
)
4868 attr
= find_attr (&XSTR (exp
, 0), 0);
4871 if (attr
->is_const
&& !attr
->is_special
)
4873 struct insn_reserv
*decl
;
4875 for (decl
= all_insn_reservs
; decl
; decl
= decl
->next
)
4876 if (! check_tune_attr (attr
->name
, decl
->condexp
))
4887 /* Create all of the attributes that describe automaton properties.
4888 Write the DFA and latency function prototypes to the files that
4889 need to have them, and write the init_sched_attrs(). */
4892 make_automaton_attrs (void)
4895 struct insn_reserv
*decl
;
4896 rtx code_exp
, lats_exp
, byps_exp
;
4897 struct attr_desc
*tune_attr
;
4899 if (n_insn_reservs
== 0)
4902 tune_attr
= find_tune_attr (all_insn_reservs
->condexp
);
4903 if (tune_attr
!= NULL
)
4905 rtx
*condexps
= XNEWVEC (rtx
, n_insn_reservs
* 3);
4906 struct attr_value
*val
;
4909 gcc_assert (tune_attr
->is_const
4910 && !tune_attr
->is_special
4911 && !tune_attr
->is_numeric
);
4913 /* Write the prototypes for all DFA functions. */
4914 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4916 if (val
== tune_attr
->default_val
)
4918 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4920 "extern int internal_dfa_insn_code_%s (rtx);\n",
4921 XSTR (val
->value
, 0));
4923 fprintf (dfa_file
, "\n");
4925 /* Write the prototypes for all latency functions. */
4926 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4928 if (val
== tune_attr
->default_val
)
4930 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4931 fprintf (latency_file
,
4932 "extern int insn_default_latency_%s (rtx);\n",
4933 XSTR (val
->value
, 0));
4935 fprintf (latency_file
, "\n");
4937 /* Write the prototypes for all automaton functions. */
4938 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4940 if (val
== tune_attr
->default_val
)
4942 gcc_assert (GET_CODE (val
->value
) == CONST_STRING
);
4944 "extern int internal_dfa_insn_code_%s (rtx);\n"
4945 "extern int insn_default_latency_%s (rtx);\n",
4946 XSTR (val
->value
, 0), XSTR (val
->value
, 0));
4948 fprintf (attr_file
, "\n");
4949 fprintf (attr_file
, "int (*internal_dfa_insn_code) (rtx);\n");
4950 fprintf (attr_file
, "int (*insn_default_latency) (rtx);\n");
4951 fprintf (attr_file
, "\n");
4952 fprintf (attr_file
, "void\n");
4953 fprintf (attr_file
, "init_sched_attrs (void)\n");
4954 fprintf (attr_file
, "{\n");
4956 for (val
= tune_attr
->first_value
; val
; val
= val
->next
)
4960 rtx test
= attr_rtx (EQ_ATTR
, tune_attr
->name
, XSTR (val
->value
, 0));
4962 if (val
== tune_attr
->default_val
)
4964 for (decl
= all_insn_reservs
, i
= 0;
4970 = simplify_and_tree (decl
->condexp
, &ctest
, -2, 0);
4971 if (condexp
== false_rtx
)
4973 if (condexp
== true_rtx
)
4975 condexps
[i
] = condexp
;
4976 condexps
[i
+ 1] = make_numeric_value (decl
->insn_num
);
4977 condexps
[i
+ 2] = make_numeric_value (decl
->default_latency
);
4981 code_exp
= rtx_alloc (COND
);
4982 lats_exp
= rtx_alloc (COND
);
4985 XVEC (code_exp
, 0) = rtvec_alloc (j
);
4986 XVEC (lats_exp
, 0) = rtvec_alloc (j
);
4990 XEXP (code_exp
, 1) = make_numeric_value (decl
->insn_num
);
4991 XEXP (lats_exp
, 1) = make_numeric_value (decl
->default_latency
);
4995 XEXP (code_exp
, 1) = make_numeric_value (n_insn_reservs
+ 1);
4996 XEXP (lats_exp
, 1) = make_numeric_value (0);
5003 XVECEXP (code_exp
, 0, j
) = condexps
[i
];
5004 XVECEXP (lats_exp
, 0, j
) = condexps
[i
];
5006 XVECEXP (code_exp
, 0, j
+ 1) = condexps
[i
+ 1];
5007 XVECEXP (lats_exp
, 0, j
+ 1) = condexps
[i
+ 2];
5010 name
= XNEWVEC (char,
5011 sizeof ("*internal_dfa_insn_code_")
5012 + strlen (XSTR (val
->value
, 0)));
5013 strcpy (name
, "*internal_dfa_insn_code_");
5014 strcat (name
, XSTR (val
->value
, 0));
5015 make_internal_attr (name
, code_exp
, ATTR_NONE
);
5016 strcpy (name
, "*insn_default_latency_");
5017 strcat (name
, XSTR (val
->value
, 0));
5018 make_internal_attr (name
, lats_exp
, ATTR_NONE
);
5023 fprintf (attr_file
, " if (");
5027 fprintf (attr_file
, " else if (");
5028 write_test_expr (attr_file
, test
, 0, 0);
5029 fprintf (attr_file
, ")\n");
5030 fprintf (attr_file
, " {\n");
5031 fprintf (attr_file
, " internal_dfa_insn_code\n");
5032 fprintf (attr_file
, " = internal_dfa_insn_code_%s;\n",
5033 XSTR (val
->value
, 0));
5034 fprintf (attr_file
, " insn_default_latency\n");
5035 fprintf (attr_file
, " = insn_default_latency_%s;\n",
5036 XSTR (val
->value
, 0));
5037 fprintf (attr_file
, " }\n");
5040 fprintf (attr_file
, " else\n");
5041 fprintf (attr_file
, " gcc_unreachable ();\n");
5042 fprintf (attr_file
, "}\n");
5043 fprintf (attr_file
, "\n");
5045 XDELETEVEC (condexps
);
5049 code_exp
= rtx_alloc (COND
);
5050 lats_exp
= rtx_alloc (COND
);
5052 XVEC (code_exp
, 0) = rtvec_alloc (n_insn_reservs
* 2);
5053 XVEC (lats_exp
, 0) = rtvec_alloc (n_insn_reservs
* 2);
5055 XEXP (code_exp
, 1) = make_numeric_value (n_insn_reservs
+ 1);
5056 XEXP (lats_exp
, 1) = make_numeric_value (0);
5058 for (decl
= all_insn_reservs
, i
= 0;
5060 decl
= decl
->next
, i
+= 2)
5062 XVECEXP (code_exp
, 0, i
) = decl
->condexp
;
5063 XVECEXP (lats_exp
, 0, i
) = decl
->condexp
;
5065 XVECEXP (code_exp
, 0, i
+1) = make_numeric_value (decl
->insn_num
);
5066 XVECEXP (lats_exp
, 0, i
+1)
5067 = make_numeric_value (decl
->default_latency
);
5069 make_internal_attr ("*internal_dfa_insn_code", code_exp
, ATTR_NONE
);
5070 make_internal_attr ("*insn_default_latency", lats_exp
, ATTR_NONE
);
5073 if (n_bypasses
== 0)
5074 byps_exp
= make_numeric_value (0);
5077 process_bypasses ();
5079 byps_exp
= rtx_alloc (COND
);
5080 XVEC (byps_exp
, 0) = rtvec_alloc (n_bypasses
* 2);
5081 XEXP (byps_exp
, 1) = make_numeric_value (0);
5082 for (decl
= all_insn_reservs
, i
= 0;
5087 XVECEXP (byps_exp
, 0, i
) = decl
->condexp
;
5088 XVECEXP (byps_exp
, 0, i
+1) = make_numeric_value (1);
5093 make_internal_attr ("*bypass_p", byps_exp
, ATTR_NONE
);
5097 write_header (FILE *outf
)
5099 fprintf (outf
, "/* Generated automatically by the program `genattrtab'\n"
5100 " from the machine description file `md'. */\n\n");
5102 fprintf (outf
, "#include \"config.h\"\n");
5103 fprintf (outf
, "#include \"system.h\"\n");
5104 fprintf (outf
, "#include \"coretypes.h\"\n");
5105 fprintf (outf
, "#include \"tm.h\"\n");
5106 fprintf (outf
, "#include \"rtl.h\"\n");
5107 fprintf (outf
, "#include \"insn-attr.h\"\n");
5108 fprintf (outf
, "#include \"tm_p.h\"\n");
5109 fprintf (outf
, "#include \"insn-config.h\"\n");
5110 fprintf (outf
, "#include \"recog.h\"\n");
5111 fprintf (outf
, "#include \"regs.h\"\n");
5112 fprintf (outf
, "#include \"real.h\"\n");
5113 fprintf (outf
, "#include \"output.h\"\n");
5114 fprintf (outf
, "#include \"toplev.h\"\n");
5115 fprintf (outf
, "#include \"flags.h\"\n");
5116 fprintf (outf
, "#include \"function.h\"\n");
5117 fprintf (outf
, "\n");
5118 fprintf (outf
, "#define operands recog_data.operand\n\n");
5122 open_outfile (const char *file_name
)
5125 outf
= fopen (file_name
, "w");
5127 fatal ("cannot open file %s: %s", file_name
, xstrerror (errno
));
5128 write_header (outf
);
5133 handle_arg (const char *arg
)
5138 attr_file_name
= &arg
[2];
5141 dfa_file_name
= &arg
[2];
5144 latency_file_name
= &arg
[2];
5152 main (int argc
, char **argv
)
5155 struct attr_desc
*attr
;
5156 struct insn_def
*id
;
5160 progname
= "genattrtab";
5162 if (!init_rtx_reader_args_cb (argc
, argv
, handle_arg
))
5163 return FATAL_EXIT_CODE
;
5165 attr_file
= open_outfile (attr_file_name
);
5166 dfa_file
= open_outfile (dfa_file_name
);
5167 latency_file
= open_outfile (latency_file_name
);
5169 obstack_init (hash_obstack
);
5170 obstack_init (temp_obstack
);
5172 /* Set up true and false rtx's */
5173 true_rtx
= rtx_alloc (CONST_INT
);
5174 XWINT (true_rtx
, 0) = 1;
5175 false_rtx
= rtx_alloc (CONST_INT
);
5176 XWINT (false_rtx
, 0) = 0;
5177 ATTR_IND_SIMPLIFIED_P (true_rtx
) = ATTR_IND_SIMPLIFIED_P (false_rtx
) = 1;
5178 ATTR_PERMANENT_P (true_rtx
) = ATTR_PERMANENT_P (false_rtx
) = 1;
5180 alternative_name
= DEF_ATTR_STRING ("alternative");
5181 length_str
= DEF_ATTR_STRING ("length");
5182 delay_type_str
= DEF_ATTR_STRING ("*delay_type");
5183 delay_1_0_str
= DEF_ATTR_STRING ("*delay_1_0");
5184 num_delay_slots_str
= DEF_ATTR_STRING ("*num_delay_slots");
5186 /* Read the machine description. */
5192 desc
= read_md_rtx (&lineno
, &insn_code_number
);
5196 switch (GET_CODE (desc
))
5199 case DEFINE_PEEPHOLE
:
5200 case DEFINE_ASM_ATTRIBUTES
:
5201 gen_insn (desc
, lineno
);
5205 case DEFINE_ENUM_ATTR
:
5206 gen_attr (desc
, lineno
);
5210 gen_delay (desc
, lineno
);
5213 case DEFINE_INSN_RESERVATION
:
5214 gen_insn_reserv (desc
);
5224 if (GET_CODE (desc
) != DEFINE_ASM_ATTRIBUTES
)
5225 insn_index_number
++;
5229 return FATAL_EXIT_CODE
;
5233 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
5234 if (! got_define_asm_attributes
)
5236 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
5237 XVEC (tem
, 0) = rtvec_alloc (0);
5241 /* Expand DEFINE_DELAY information into new attribute. */
5245 /* Make `insn_alternatives'. */
5246 insn_alternatives
= oballocvec (int, insn_code_number
);
5247 for (id
= defs
; id
; id
= id
->next
)
5248 if (id
->insn_code
>= 0)
5249 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
5251 /* Make `insn_n_alternatives'. */
5252 insn_n_alternatives
= oballocvec (int, insn_code_number
);
5253 for (id
= defs
; id
; id
= id
->next
)
5254 if (id
->insn_code
>= 0)
5255 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
5257 /* Construct extra attributes for automata. */
5258 make_automaton_attrs ();
5260 /* Prepare to write out attribute subroutines by checking everything stored
5261 away and building the attribute cases. */
5265 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5266 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5267 attr
->default_val
->value
5268 = check_attr_value (attr
->default_val
->value
, attr
);
5271 return FATAL_EXIT_CODE
;
5273 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5274 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5277 /* Construct extra attributes for `length'. */
5278 make_length_attrs ();
5280 /* Perform any possible optimizations to speed up compilation. */
5283 /* Now write out all the `gen_attr_...' routines. Do these before the
5284 special routines so that they get defined before they are used. */
5286 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5287 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5291 #define IS_ATTR_GROUP(X) (!strncmp(attr->name,X,strlen(X)))
5292 if (IS_ATTR_GROUP ("*internal_dfa_insn_code"))
5294 else if (IS_ATTR_GROUP ("*insn_default_latency"))
5295 outf
= latency_file
;
5298 #undef IS_ATTR_GROUP
5300 if (! attr
->is_special
&& ! attr
->is_const
)
5301 write_attr_get (outf
, attr
);
5304 /* Write out delay eligibility information, if DEFINE_DELAY present.
5305 (The function to compute the number of delay slots will be written
5309 write_eligible_delay (attr_file
, "delay");
5310 if (have_annul_true
)
5311 write_eligible_delay (attr_file
, "annul_true");
5312 if (have_annul_false
)
5313 write_eligible_delay (attr_file
, "annul_false");
5316 /* Write out constant delay slot info. */
5317 write_const_num_delay_slots (attr_file
);
5319 write_length_unit_log (attr_file
);
5321 if (fclose (attr_file
) != 0)
5322 fatal ("cannot close file %s: %s", attr_file_name
, xstrerror (errno
));
5323 if (fclose (dfa_file
) != 0)
5324 fatal ("cannot close file %s: %s", dfa_file_name
, xstrerror (errno
));
5325 if (fclose (latency_file
) != 0)
5326 fatal ("cannot close file %s: %s", latency_file_name
, xstrerror (errno
));
5328 return SUCCESS_EXIT_CODE
;