1 /* Generate code from machine description to compute values of attributes.
2 Copyright (C) 1991 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@nyu.edu)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This program handles insn attributes and the DEFINE_DELAY and
22 DEFINE_FUNCTION_UNIT definitions.
24 It produces a series of functions named `get_attr_...', one for each insn
25 attribute. Each of these is given the rtx for an insn and returns a member
26 of the enum for the attribute.
28 These subroutines have the form of a `switch' on the INSN_CODE (via
29 `recog_memoized'). Each case either returns a constant attribute value
30 or a value that depends on tests on other attributes, the form of
31 operands, or some random C expression (encoded with a SYMBOL_REF
34 If the attribute `alternative', or a random C expression is present,
35 `constrain_operands' is called. If either of these cases of a reference to
36 an operand is found, `insn_extract' is called.
38 The special attribute `length' is also recognized. For this operand,
39 expressions involving the address of an operand or the current insn,
40 (address (pc)), are valid. In this case, an initial pass is made to
41 set all lengths that do not depend on address. Those that do are set to
42 the maximum length. Then each insn that depends on an address is checked
43 and possibly has its length changed. The process repeats until no further
44 changed are made. The resulting lengths are saved for use by
47 A special form of DEFINE_ATTR, where the expression for default value is a
48 CONST expression, indicates an attribute that is constant for a given run
49 of the compiler. The subroutine generated for these attributes has no
50 parameters as it does not depend on any particular insn. Constant
51 attributes are typically used to specify which variety of processor is
54 Internal attributes are defined to handle DEFINE_DELAY and
55 DEFINE_FUNCTION_UNIT. Special routines are output for these cases.
57 This program works by keeping a list of possible values for each attribute.
58 These include the basic attribute choices, default values for attribute, and
59 all derived quantities.
61 As the description file is read, the definition for each insn is saved in a
62 `struct insn_def'. When the file reading is complete, a `struct insn_ent'
63 is created for each insn and chained to the corresponding attribute value,
64 either that specified, or the default.
66 An optimization phase is then run. This simplifies expressions for each
67 insn. EQ_ATTR tests are resolved, whenever possible, to a test that
68 indicates when the attribute has the specified value for the insn. This
69 avoids recursive calls during compilation.
71 The strategy used when processing DEFINE_DELAY and DEFINE_FUNCTION_UNIT
72 definitions is to create arbitrarily complex expressions and have the
73 optimization simplify them.
75 Once optimization is complete, any required routines and definitions
78 An optimization that is not yet implemented is to hoist the constant
79 expressions entirely out of the routines and definitions that are written.
80 A way to do this is to iterate over all possible combinations of values
81 for constant attributes and generate a set of functions for that given
82 combination. An initialization function would be written that evaluates
83 the attributes and installs the corresponding set of routines and
84 definitions (each would be accessed through a pointer).
86 We use the flags in an RTX as follows:
87 `unchanging' (RTX_UNCHANGING_P): This rtx is fully simplified
88 independent of the insn code.
89 `in_struct' (MEM_IN_STRUCT_P): This rtx is fully simplified
90 for the insn code currently being processed (see optimize_attrs).
91 `integrated' (RTX_INTEGRATED_P): This rtx is permanent and unique
93 `volatil' (MEM_VOLATILE_P): During simplify_by_exploding the value of an
94 EQ_ATTR rtx is true if !volatil and false if volatil. */
102 #include "insn-config.h" /* For REGISTER_CONSTRAINTS */
104 static struct obstack obstack
, obstack1
, obstack2
;
105 struct obstack
*rtl_obstack
= &obstack
;
106 struct obstack
*hash_obstack
= &obstack1
;
107 struct obstack
*temp_obstack
= &obstack2
;
109 #define obstack_chunk_alloc xmalloc
110 #define obstack_chunk_free free
112 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
113 char **insn_name_ptr
= 0;
116 extern rtx
read_rtx ();
118 static void fatal ();
121 /* Define structures used to record attributes and values. */
123 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
124 encountered, we store all the relevant information into a
125 `struct insn_def'. This is done to allow attribute definitions to occur
126 anywhere in the file. */
130 int insn_code
; /* Instruction number. */
131 int insn_index
; /* Expression numer in file, for errors. */
132 struct insn_def
*next
; /* Next insn in chain. */
133 rtx def
; /* The DEFINE_... */
134 int num_alternatives
; /* Number of alternatives. */
135 int vec_idx
; /* Index of attribute vector in `def'. */
138 /* Once everything has been read in, we store in each attribute value a list
139 of insn codes that have that value. Here is the structure used for the
144 int insn_code
; /* Instruction number. */
145 int insn_index
; /* Index of definition in file */
146 struct insn_ent
*next
; /* Next in chain. */
149 /* Each value of an attribute (either constant or computed) is assigned a
150 structure which is used as the listhead of the insns that have that
155 rtx value
; /* Value of attribute. */
156 struct attr_value
*next
; /* Next attribute value in chain. */
157 struct insn_ent
*first_insn
; /* First insn with this value. */
158 int num_insns
; /* Number of insns with this value. */
159 int has_asm_insn
; /* True if this value used for `asm' insns */
162 /* Structure for each attribute. */
166 char *name
; /* Name of attribute. */
167 struct attr_desc
*next
; /* Next attribute. */
168 int is_numeric
; /* Values of this attribute are numeric. */
169 int negative_ok
; /* Allow negative numeric values. */
170 int is_const
; /* Attribute value constant for each run. */
171 int is_special
; /* Don't call `write_attr_set'. */
172 struct attr_value
*first_value
; /* First value of this attribute. */
173 struct attr_value
*default_val
; /* Default value for this attribute. */
176 #define NULL_ATTR (struct attr_desc *) NULL
178 /* Structure for each DEFINE_DELAY. */
182 rtx def
; /* DEFINE_DELAY expression. */
183 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
184 int num
; /* Number of DEFINE_DELAY, starting at 1. */
187 /* Record information about each DEFINE_FUNCTION_UNIT. */
189 struct function_unit_op
191 rtx condexp
; /* Expression TRUE for applicable insn. */
192 struct function_unit_op
*next
; /* Next operation for this function unit. */
193 int num
; /* Ordinal for this operation type in unit. */
194 int ready
; /* Cost until data is ready. */
195 rtx busyexp
; /* Expression computing conflict cost. */
198 /* Record information about each function unit mentioned in a
199 DEFINE_FUNCTION_UNIT. */
203 char *name
; /* Function unit name. */
204 struct function_unit
*next
; /* Next function unit. */
205 int num
; /* Ordinal of this unit type. */
206 int multiplicity
; /* Number of units of this type. */
207 int simultaneity
; /* Maximum number of simultaneous insns
208 on this function unit or 0 if unlimited. */
209 rtx condexp
; /* Expression TRUE for insn needing unit. */
210 rtx costexp
; /* Worst-case cost as function of insn. */
211 int num_opclasses
; /* Number of different operation types. */
212 struct function_unit_op
*ops
; /* Pointer to first operation type. */
213 int needs_conflict_function
; /* Nonzero if a conflict function required. */
214 rtx default_cost
; /* Conflict cost, if constant. */
215 rtx max_busy_cost
; /* Maximum conflict cost. */
216 int min_busy_delay
; /* Minimum conflict cost. */
217 int max_busy_delay
; /* Maximum conflict cost. */
220 /* Listheads of above structures. */
222 /* This one is indexed by the first character of the attribute name. */
223 #define MAX_ATTRS_INDEX 256
224 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
225 static struct insn_def
*defs
;
226 static struct delay_desc
*delays
;
227 static struct function_unit
*units
;
229 /* Other variables. */
231 static int insn_code_number
;
232 static int insn_index_number
;
233 static int got_define_asm_attributes
;
234 static int must_extract
;
235 static int must_constrain
;
236 static int address_used
;
237 static int num_delays
;
238 static int have_annul_true
, have_annul_false
;
239 static int num_units
;
241 /* Used as operand to `operate_exp': */
243 enum operator {PLUS_OP
, MINUS_OP
, OR_OP
, MAX_OP
};
245 /* Stores, for each insn code, the number of constraint alternatives. */
247 static int *insn_n_alternatives
;
249 /* Stores, for each insn code, a bitmap that has bits on for each possible
252 static int *insn_alternatives
;
254 /* If nonzero, assume that the `alternative' attr has this value.
255 This is the hashed, unique string for the numeral
256 whose value is chosen alternative. */
258 static char *current_alternative_string
;
260 /* Used to simplify expressions. */
262 static rtx true_rtx
, false_rtx
;
264 /* Used to reduce calls to `strcmp' */
266 static char *alternative_name
;
268 /* Simplify an expression. Only call the routine if there is something to
270 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
271 (RTX_UNCHANGING_P (EXP) || MEM_IN_STRUCT_P (EXP) ? (EXP) \
272 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
274 /* Simplify (eq_attr ("alternative") ...)
275 when we are working with a particular alternative. */
276 #define SIMPLIFY_ALTERNATIVE(EXP) \
277 if (current_alternative_string \
278 && GET_CODE ((EXP)) == EQ_ATTR \
279 && XSTR ((EXP), 0) == alternative_name) \
280 (EXP) = (XSTR ((EXP), 1) == current_alternative_string \
281 ? true_rtx : false_rtx);
283 /* These are referenced by rtlanal.c and hence need to be defined somewhere.
284 They won't actually be used. */
286 rtx frame_pointer_rtx
, stack_pointer_rtx
, arg_pointer_rtx
;
288 static rtx
attr_rtx ();
289 static char *attr_printf ();
290 static char *attr_string ();
291 static rtx
check_attr_test ();
292 static rtx
check_attr_value ();
293 static rtx
convert_set_attr_alternative ();
294 static rtx
convert_set_attr ();
295 static void check_defs ();
296 static rtx
convert_const_symbol_ref ();
297 static rtx
make_canonical ();
298 static struct attr_value
*get_attr_value ();
299 static rtx
copy_rtx_unchanging ();
300 static rtx
copy_boolean ();
301 static void expand_delays ();
302 static rtx
operate_exp ();
303 static void expand_units ();
304 static rtx
encode_units_mask ();
305 static void fill_attr ();
306 static rtx
substitute_address ();
307 static void make_length_attrs ();
308 static rtx
identity_fn ();
309 static rtx
zero_fn ();
310 static rtx
one_fn ();
311 static rtx
max_fn ();
312 static rtx
simplify_cond ();
313 static rtx
simplify_by_alternatives ();
314 static rtx
simplify_by_exploding ();
315 static int find_and_mark_used_attributes ();
316 static void unmark_used_attributes ();
317 static int add_values_to_cover ();
318 static int increment_current_value ();
319 static rtx
test_for_current_value ();
320 static rtx
simplify_with_current_value ();
321 static rtx
simplify_with_current_value_aux ();
322 static void remove_insn_ent ();
323 static void insert_insn_ent ();
324 static rtx
insert_right_side ();
325 static rtx
make_alternative_compare ();
326 static int compute_alternative_mask ();
327 static rtx
evaluate_eq_attr ();
328 static rtx
simplify_and_tree ();
329 static rtx
simplify_or_tree ();
330 static rtx
simplify_test_exp ();
331 static void optimize_attrs ();
332 static void gen_attr ();
333 static int count_alternatives ();
334 static int compares_alternatives_p ();
335 static int contained_in_p ();
336 static void gen_insn ();
337 static void gen_delay ();
338 static void gen_unit ();
339 static void write_test_expr ();
340 static int max_attr_value ();
341 static void walk_attr_value ();
342 static void write_attr_get ();
343 static rtx
eliminate_known_true ();
344 static void write_attr_set ();
345 static void write_attr_case ();
346 static void write_attr_value ();
347 static void write_attr_valueq ();
348 static void write_upcase ();
349 static void write_indent ();
350 static void write_eligible_delay ();
351 static void write_function_unit_info ();
352 static int n_comma_elts ();
353 static char *next_comma_elt ();
354 static struct attr_desc
*find_attr ();
355 static void make_internal_attr ();
356 static struct attr_value
*find_most_used ();
357 static rtx
find_single_value ();
358 static rtx
make_numeric_value ();
361 static void fatal ();
363 /* Hash table for sharing RTL and strings. */
365 /* Each hash table slot is a bucket containing a chain of these structures.
366 Strings are given negative hash codes; RTL expressions are given positive
371 struct attr_hash
*next
; /* Next structure in the bucket. */
372 int hashcode
; /* Hash code of this rtx or string. */
375 char *str
; /* The string (negative hash codes) */
376 rtx rtl
; /* or the RTL recorded here. */
380 /* Now here is the hash table. When recording an RTL, it is added to
381 the slot whose index is the hash code mod the table size. Note
382 that the hash table is used for several kinds of RTL (see attr_rtx)
383 and for strings. While all these live in the same table, they are
384 completely independent, and the hash code is computed differently
387 #define RTL_HASH_SIZE 4093
388 struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
390 /* Here is how primitive or already-shared RTL's hash
392 #define RTL_HASH(RTL) ((int) (RTL) & 0777777)
394 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
397 attr_hash_add_rtx (hashcode
, rtl
)
401 register struct attr_hash
*h
;
403 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
404 sizeof (struct attr_hash
));
405 h
->hashcode
= hashcode
;
407 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
408 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
411 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
414 attr_hash_add_string (hashcode
, str
)
418 register struct attr_hash
*h
;
420 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
421 sizeof (struct attr_hash
));
422 h
->hashcode
= -hashcode
;
424 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
425 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
428 /* Generate an RTL expression, but avoid duplicates.
429 Set the RTX_INTEGRATED_P flag for these permanent objects.
431 In some cases we cannot uniquify; then we return an ordinary
432 impermanent rtx with RTX_INTEGRATED_P clear.
434 Args are like gen_rtx, but without the mode:
436 rtx attr_rtx (code, [element1, ..., elementn]) */
445 register int i
; /* Array indices... */
446 register char *fmt
; /* Current rtx's format... */
447 register rtx rt_val
; /* RTX to return to caller... */
449 register struct attr_hash
*h
;
450 struct obstack
*old_obstack
= rtl_obstack
;
453 code
= va_arg (p
, enum rtx_code
);
455 /* For each of several cases, search the hash table for an existing entry.
456 Use that entry if one is found; otherwise create a new RTL and add it
459 if (GET_RTX_CLASS (code
) == '1')
461 rtx arg0
= va_arg (p
, rtx
);
463 /* A permanent object cannot point to impermanent ones. */
464 if (! RTX_INTEGRATED_P (arg0
))
466 rt_val
= rtx_alloc (code
);
467 XEXP (rt_val
, 0) = arg0
;
472 hashcode
= ((int) code
+ RTL_HASH (arg0
));
473 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
474 if (h
->hashcode
== hashcode
475 && GET_CODE (h
->u
.rtl
) == code
476 && XEXP (h
->u
.rtl
, 0) == arg0
)
481 rtl_obstack
= hash_obstack
;
482 rt_val
= rtx_alloc (code
);
483 XEXP (rt_val
, 0) = arg0
;
486 else if (GET_RTX_CLASS (code
) == 'c'
487 || GET_RTX_CLASS (code
) == '2'
488 || GET_RTX_CLASS (code
) == '<')
490 rtx arg0
= va_arg (p
, rtx
);
491 rtx arg1
= va_arg (p
, rtx
);
493 /* A permanent object cannot point to impermanent ones. */
494 if (! RTX_INTEGRATED_P (arg0
) || ! RTX_INTEGRATED_P (arg1
))
496 rt_val
= rtx_alloc (code
);
497 XEXP (rt_val
, 0) = arg0
;
498 XEXP (rt_val
, 1) = arg1
;
503 hashcode
= ((int) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
504 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
505 if (h
->hashcode
== hashcode
506 && GET_CODE (h
->u
.rtl
) == code
507 && XEXP (h
->u
.rtl
, 0) == arg0
508 && XEXP (h
->u
.rtl
, 1) == arg1
)
513 rtl_obstack
= hash_obstack
;
514 rt_val
= rtx_alloc (code
);
515 XEXP (rt_val
, 0) = arg0
;
516 XEXP (rt_val
, 1) = arg1
;
519 else if (GET_RTX_LENGTH (code
) == 1
520 && GET_RTX_FORMAT (code
)[0] == 's')
522 char * arg0
= va_arg (p
, char *);
524 if (code
== SYMBOL_REF
)
525 arg0
= attr_string (arg0
, strlen (arg0
));
527 hashcode
= ((int) code
+ RTL_HASH (arg0
));
528 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
529 if (h
->hashcode
== hashcode
530 && GET_CODE (h
->u
.rtl
) == code
531 && XSTR (h
->u
.rtl
, 0) == arg0
)
536 rtl_obstack
= hash_obstack
;
537 rt_val
= rtx_alloc (code
);
538 XSTR (rt_val
, 0) = arg0
;
541 else if (GET_RTX_LENGTH (code
) == 2
542 && GET_RTX_FORMAT (code
)[0] == 's'
543 && GET_RTX_FORMAT (code
)[1] == 's')
545 char *arg0
= va_arg (p
, char *);
546 char *arg1
= va_arg (p
, char *);
548 hashcode
= ((int) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
549 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
550 if (h
->hashcode
== hashcode
551 && GET_CODE (h
->u
.rtl
) == code
552 && XSTR (h
->u
.rtl
, 0) == arg0
553 && XSTR (h
->u
.rtl
, 1) == arg1
)
558 rtl_obstack
= hash_obstack
;
559 rt_val
= rtx_alloc (code
);
560 XSTR (rt_val
, 0) = arg0
;
561 XSTR (rt_val
, 1) = arg1
;
564 else if (code
== CONST_INT
)
566 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
576 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
578 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
579 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
583 case '0': /* Unused field. */
586 case 'i': /* An integer? */
587 XINT (rt_val
, i
) = va_arg (p
, int);
590 case 'w': /* A wide integer? */
591 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
594 case 's': /* A string? */
595 XSTR (rt_val
, i
) = va_arg (p
, char *);
598 case 'e': /* An expression? */
599 case 'u': /* An insn? Same except when printing. */
600 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
603 case 'E': /* An RTX vector? */
604 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
615 rtl_obstack
= old_obstack
;
617 attr_hash_add_rtx (hashcode
, rt_val
);
618 RTX_INTEGRATED_P (rt_val
) = 1;
626 /* Create a new string printed with the printf line arguments into a space
627 of at most LEN bytes:
629 rtx attr_printf (len, format, [arg1, ..., argn]) */
635 attr_printf (va_alist
)
643 /* Print the string into a temporary location. */
645 len
= va_arg (p
, int);
646 str
= (char *) alloca (len
);
647 fmt
= va_arg (p
, char *);
648 vsprintf (str
, fmt
, p
);
651 return attr_string (str
, strlen (str
));
654 #else /* not HAVE_VPRINTF */
657 attr_printf (len
, fmt
, arg1
, arg2
, arg3
)
660 char *arg1
, *arg2
, *arg3
; /* also int */
664 /* Print the string into a temporary location. */
665 str
= (char *) alloca (len
);
666 sprintf (str
, fmt
, arg1
, arg2
, arg3
);
668 return attr_string (str
, strlen (str
));
670 #endif /* not HAVE_VPRINTF */
673 attr_eq (name
, value
)
676 return attr_rtx (EQ_ATTR
, attr_string (name
, strlen (name
)),
677 attr_string (value
, strlen (value
)));
684 return XSTR (make_numeric_value (n
), 0);
687 /* Return a permanent (possibly shared) copy of a string STR (not assumed
688 to be null terminated) with LEN bytes. */
691 attr_string (str
, len
)
695 register struct attr_hash
*h
;
698 register char *new_str
;
700 /* Compute the hash code. */
701 hashcode
= (len
+ 1) * 613 + (unsigned)str
[0];
702 for (i
= 1; i
<= len
; i
+= 2)
703 hashcode
= ((hashcode
* 613) + (unsigned)str
[i
]);
705 hashcode
= -hashcode
;
707 /* Search the table for the string. */
708 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
709 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
710 && !strncmp (h
->u
.str
, str
, len
))
711 return h
->u
.str
; /* <-- return if found. */
713 /* Not found; create a permanent copy and add it to the hash table. */
714 new_str
= (char *) obstack_alloc (hash_obstack
, len
+ 1);
715 bcopy (str
, new_str
, len
);
717 attr_hash_add_string (hashcode
, new_str
);
719 return new_str
; /* Return the new string. */
722 /* Check two rtx's for equality of contents,
723 taking advantage of the fact that if both are hashed
724 then they can't be equal unless they are the same object. */
730 return (x
== y
|| (! (RTX_INTEGRATED_P (x
) && RTX_INTEGRATED_P (y
))
731 && rtx_equal_p (x
, y
)));
734 /* Copy an attribute value expression,
735 descending to all depths, but not copying any
736 permanent hashed subexpressions. */
744 register RTX_CODE code
;
745 register char *format_ptr
;
747 /* No need to copy a permanent object. */
748 if (RTX_INTEGRATED_P (orig
))
751 code
= GET_CODE (orig
);
766 copy
= rtx_alloc (code
);
767 PUT_MODE (copy
, GET_MODE (orig
));
768 copy
->in_struct
= orig
->in_struct
;
769 copy
->volatil
= orig
->volatil
;
770 copy
->unchanging
= orig
->unchanging
;
771 copy
->integrated
= orig
->integrated
;
773 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
775 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
777 switch (*format_ptr
++)
780 XEXP (copy
, i
) = XEXP (orig
, i
);
781 if (XEXP (orig
, i
) != NULL
)
782 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
787 XVEC (copy
, i
) = XVEC (orig
, i
);
788 if (XVEC (orig
, i
) != NULL
)
790 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
791 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
792 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
798 XINT (copy
, i
) = XINT (orig
, i
);
802 XWINT (copy
, i
) = XWINT (orig
, i
);
807 XSTR (copy
, i
) = XSTR (orig
, i
);
817 /* Given a test expression for an attribute, ensure it is validly formed.
818 IS_CONST indicates whether the expression is constant for each compiler
819 run (a constant expression may not test any particular insn).
821 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
822 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
823 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
825 Update the string address in EQ_ATTR expression to be the same used
826 in the attribute (or `alternative_name') to speed up subsequent
827 `find_attr' calls and eliminate most `strcmp' calls.
829 Return the new expression, if any. */
832 check_attr_test (exp
, is_const
)
836 struct attr_desc
*attr
;
837 struct attr_value
*av
;
841 switch (GET_CODE (exp
))
844 /* Handle negation test. */
845 if (XSTR (exp
, 1)[0] == '!')
846 return check_attr_test (attr_rtx (NOT
,
847 attr_eq (XSTR (exp
, 0),
851 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
853 attr
= find_attr (XSTR (exp
, 0), 0);
856 if (! strcmp (XSTR (exp
, 0), "alternative"))
858 XSTR (exp
, 0) = alternative_name
;
859 /* This can't be simplified any further. */
860 RTX_UNCHANGING_P (exp
) = 1;
864 fatal ("Unknown attribute `%s' in EQ_ATTR", XEXP (exp
, 0));
867 if (is_const
&& ! attr
->is_const
)
868 fatal ("Constant expression uses insn attribute `%s' in EQ_ATTR",
871 /* Copy this just to make it permanent,
872 so expressions using it can be permanent too. */
873 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
875 /* It shouldn't be possible to simplify the value given to a
876 constant attribute, so don't expand this until it's time to
877 write the test expression. */
879 RTX_UNCHANGING_P (exp
) = 1;
881 if (attr
->is_numeric
)
883 for (p
= XSTR (exp
, 1); *p
; p
++)
884 if (*p
< '0' || *p
> '9')
885 fatal ("Attribute `%s' takes only numeric values",
890 for (av
= attr
->first_value
; av
; av
= av
->next
)
891 if (GET_CODE (av
->value
) == CONST_STRING
892 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
896 fatal ("Unknown value `%s' for `%s' attribute",
897 XEXP (exp
, 1), XEXP (exp
, 0));
902 /* Make an IOR tree of the possible values. */
904 name_ptr
= XSTR (exp
, 1);
905 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
907 newexp
= attr_eq (XSTR (exp
, 0), p
);
908 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2);
911 return check_attr_test (orexp
, is_const
);
916 /* Either TRUE or FALSE. */
924 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
);
925 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
);
929 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
);
934 fatal ("RTL operator \"%s\" not valid in constant attribute test",
935 GET_RTX_NAME (MATCH_OPERAND
));
936 /* These cases can't be simplified. */
937 RTX_UNCHANGING_P (exp
) = 1;
940 case LE
: case LT
: case GT
: case GE
:
941 case LEU
: case LTU
: case GTU
: case GEU
:
943 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
944 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
945 exp
= attr_rtx (GET_CODE (exp
),
946 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
947 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
948 /* These cases can't be simplified. */
949 RTX_UNCHANGING_P (exp
) = 1;
955 /* These cases are valid for constant attributes, but can't be
957 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
958 RTX_UNCHANGING_P (exp
) = 1;
962 fatal ("RTL operator \"%s\" not valid in attribute test",
963 GET_RTX_NAME (GET_CODE (exp
)));
969 /* Given an expression, ensure that it is validly formed and that all named
970 attribute values are valid for the given attribute. Issue a fatal error
971 if not. If no attribute is specified, assume a numeric attribute.
973 Return a perhaps modified replacement expression for the value. */
976 check_attr_value (exp
, attr
)
978 struct attr_desc
*attr
;
980 struct attr_value
*av
;
984 switch (GET_CODE (exp
))
987 if (attr
&& ! attr
->is_numeric
)
988 fatal ("CONST_INT not valid for non-numeric `%s' attribute",
991 if (INTVAL (exp
) < 0)
992 fatal ("Negative numeric value specified for `%s' attribute",
998 if (! strcmp (XSTR (exp
, 0), "*"))
1001 if (attr
== 0 || attr
->is_numeric
)
1004 if (attr
&& attr
->negative_ok
&& *p
== '-')
1007 if (*p
> '9' || *p
< '0')
1008 fatal ("Non-numeric value for numeric `%s' attribute",
1009 attr
? attr
->name
: "internal");
1013 for (av
= attr
->first_value
; av
; av
= av
->next
)
1014 if (GET_CODE (av
->value
) == CONST_STRING
1015 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
1019 fatal ("Unknown value `%s' for `%s' attribute",
1020 XSTR (exp
, 0), attr
? attr
->name
: "internal");
1025 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
1026 attr
? attr
->is_const
: 0);
1027 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1028 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
1032 if (XVECLEN (exp
, 0) % 2 != 0)
1033 fatal ("First operand of COND must have even length");
1035 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1037 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1038 attr
? attr
->is_const
: 0);
1039 XVECEXP (exp
, 0, i
+ 1)
1040 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1043 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1047 if (attr
&& attr
->is_const
)
1048 /* A constant SYMBOL_REF is valid as a constant attribute test and
1049 is expanded later by make_canonical into a COND. */
1050 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1051 /* Otherwise, fall through... */
1054 fatal ("Illegal operation `%s' for attribute value",
1055 GET_RTX_NAME (GET_CODE (exp
)));
1061 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1062 It becomes a COND with each test being (eq_attr "alternative "n") */
1065 convert_set_attr_alternative (exp
, num_alt
, insn_code
, insn_index
)
1068 int insn_code
, insn_index
;
1073 if (XVECLEN (exp
, 1) != num_alt
)
1074 fatal ("Bad number of entries in SET_ATTR_ALTERNATIVE for insn %d",
1077 /* Make a COND with all tests but the last. Select the last value via the
1079 condexp
= rtx_alloc (COND
);
1080 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1082 for (i
= 0; i
< num_alt
- 1; i
++)
1085 p
= attr_numeral (i
);
1087 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1089 /* Sharing this EQ_ATTR rtl causes trouble. */
1090 XVECEXP (condexp
, 0, 2 * i
) = rtx_alloc (EQ_ATTR
);
1091 XSTR (XVECEXP (condexp
, 0, 2 * i
), 0) = alternative_name
;
1092 XSTR (XVECEXP (condexp
, 0, 2 * i
), 1) = p
;
1094 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1097 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1099 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1102 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1103 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1106 convert_set_attr (exp
, num_alt
, insn_code
, insn_index
)
1109 int insn_code
, insn_index
;
1116 /* See how many alternative specified. */
1117 n
= n_comma_elts (XSTR (exp
, 1));
1119 return attr_rtx (SET
,
1120 attr_rtx (ATTR
, XSTR (exp
, 0)),
1121 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1123 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1124 XSTR (newexp
, 0) = XSTR (exp
, 0);
1125 XVEC (newexp
, 1) = rtvec_alloc (n
);
1127 /* Process each comma-separated name. */
1128 name_ptr
= XSTR (exp
, 1);
1130 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1131 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1133 return convert_set_attr_alternative (newexp
, num_alt
, insn_code
, insn_index
);
1136 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1137 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1143 struct insn_def
*id
;
1144 struct attr_desc
*attr
;
1148 for (id
= defs
; id
; id
= id
->next
)
1150 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1153 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1155 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1156 switch (GET_CODE (value
))
1159 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1160 fatal ("Bad attribute set in pattern %d", id
->insn_index
);
1163 case SET_ATTR_ALTERNATIVE
:
1164 value
= convert_set_attr_alternative (value
,
1165 id
->num_alternatives
,
1171 value
= convert_set_attr (value
, id
->num_alternatives
,
1172 id
->insn_code
, id
->insn_index
);
1176 fatal ("Invalid attribute code `%s' for pattern %d",
1177 GET_RTX_NAME (GET_CODE (value
)), id
->insn_index
);
1180 if ((attr
= find_attr (XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1181 fatal ("Unknown attribute `%s' for pattern number %d",
1182 XSTR (XEXP (value
, 0), 0), id
->insn_index
);
1184 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1185 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1190 /* Given a constant SYMBOL_REF expression, convert to a COND that
1191 explicitly tests each enumerated value. */
1194 convert_const_symbol_ref (exp
, attr
)
1196 struct attr_desc
*attr
;
1199 struct attr_value
*av
;
1203 for (av
= attr
->first_value
; av
; av
= av
->next
)
1206 /* Make a COND with all tests but the last, and in the original order.
1207 Select the last value via the default. Note that the attr values
1208 are constructed in reverse order. */
1210 condexp
= rtx_alloc (COND
);
1211 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1212 av
= attr
->first_value
;
1213 XEXP (condexp
, 1) = av
->value
;
1215 for (i
= num_alt
- 2; av
= av
->next
, i
>= 0; i
--)
1220 string
= p
= (char *) xmalloc (2
1221 + strlen (attr
->name
)
1222 + strlen (XSTR (av
->value
, 0)));
1223 strcpy (p
, attr
->name
);
1225 strcat (p
, XSTR (av
->value
, 0));
1226 for (; *p
!= '\0'; p
++)
1227 if (*p
>= 'a' && *p
<= 'z')
1230 value
= attr_rtx (SYMBOL_REF
, string
);
1231 RTX_UNCHANGING_P (value
) = 1;
1233 XVECEXP (condexp
, 0, 2 * i
) = attr_rtx (EQ
, exp
, value
);
1235 XVECEXP (condexp
, 0, 2 * i
+ 1) = av
->value
;
1241 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1242 expressions by converting them into a COND. This removes cases from this
1243 program. Also, replace an attribute value of "*" with the default attribute
1247 make_canonical (attr
, exp
)
1248 struct attr_desc
*attr
;
1254 switch (GET_CODE (exp
))
1257 exp
= make_numeric_value (INTVAL (exp
));
1261 if (! strcmp (XSTR (exp
, 0), "*"))
1263 if (attr
== 0 || attr
->default_val
== 0)
1264 fatal ("(attr_value \"*\") used in invalid context.");
1265 exp
= attr
->default_val
->value
;
1271 if (!attr
->is_const
|| RTX_UNCHANGING_P (exp
))
1273 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1274 This makes the COND something that won't be considered an arbitrary
1275 expression by walk_attr_value. */
1276 RTX_UNCHANGING_P (exp
) = 1;
1277 exp
= convert_const_symbol_ref (exp
, attr
);
1278 RTX_UNCHANGING_P (exp
) = 1;
1279 exp
= check_attr_value (exp
, attr
);
1280 /* Goto COND case since this is now a COND. Note that while the
1281 new expression is rescanned, all symbol_ref notes are mared as
1286 newexp
= rtx_alloc (COND
);
1287 XVEC (newexp
, 0) = rtvec_alloc (2);
1288 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1289 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1291 XEXP (newexp
, 1) = XEXP (exp
, 2);
1294 /* Fall through to COND case since this is now a COND. */
1302 /* First, check for degenerate COND. */
1303 if (XVECLEN (exp
, 0) == 0)
1304 return make_canonical (attr
, XEXP (exp
, 1));
1305 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1307 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1309 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1310 XVECEXP (exp
, 0, i
+ 1)
1311 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1312 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1328 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1329 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1330 copy_boolean (XEXP (exp
, 1)));
1334 /* Given a value and an attribute description, return a `struct attr_value *'
1335 that represents that value. This is either an existing structure, if the
1336 value has been previously encountered, or a newly-created structure.
1338 `insn_code' is the code of an insn whose attribute has the specified
1339 value (-2 if not processing an insn). We ensure that all insns for
1340 a given value have the same number of alternatives if the value checks
1343 static struct attr_value
*
1344 get_attr_value (value
, attr
, insn_code
)
1346 struct attr_desc
*attr
;
1349 struct attr_value
*av
;
1352 value
= make_canonical (attr
, value
);
1353 if (compares_alternatives_p (value
))
1355 if (insn_code
< 0 || insn_alternatives
== NULL
)
1356 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1358 num_alt
= insn_alternatives
[insn_code
];
1361 for (av
= attr
->first_value
; av
; av
= av
->next
)
1362 if (rtx_equal_p (value
, av
->value
)
1363 && (num_alt
== 0 || av
->first_insn
== NULL
1364 || insn_alternatives
[av
->first_insn
->insn_code
]))
1367 av
= (struct attr_value
*) xmalloc (sizeof (struct attr_value
));
1369 av
->next
= attr
->first_value
;
1370 attr
->first_value
= av
;
1371 av
->first_insn
= NULL
;
1373 av
->has_asm_insn
= 0;
1378 /* After all DEFINE_DELAYs have been read in, create internal attributes
1379 to generate the required routines.
1381 First, we compute the number of delay slots for each insn (as a COND of
1382 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1383 delay type is specified, we compute a similar function giving the
1384 DEFINE_DELAY ordinal for each insn.
1386 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1387 tells whether a given insn can be in that delay slot.
1389 Normal attribute filling and optimization expands these to contain the
1390 information needed to handle delay slots. */
1395 struct delay_desc
*delay
;
1401 /* First, generate data for `num_delay_slots' function. */
1403 condexp
= rtx_alloc (COND
);
1404 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1405 XEXP (condexp
, 1) = make_numeric_value (0);
1407 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1409 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1410 XVECEXP (condexp
, 0, i
+ 1)
1411 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1414 make_internal_attr ("*num_delay_slots", condexp
, 0);
1416 /* If more than one delay type, do the same for computing the delay type. */
1419 condexp
= rtx_alloc (COND
);
1420 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1421 XEXP (condexp
, 1) = make_numeric_value (0);
1423 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1425 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1426 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1429 make_internal_attr ("*delay_type", condexp
, 1);
1432 /* For each delay possibility and delay slot, compute an eligibility
1433 attribute for non-annulled insns and for each type of annulled (annul
1434 if true and annul if false). */
1435 for (delay
= delays
; delay
; delay
= delay
->next
)
1437 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1439 condexp
= XVECEXP (delay
->def
, 1, i
);
1440 if (condexp
== 0) condexp
= false_rtx
;
1441 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1442 make_numeric_value (1), make_numeric_value (0));
1444 p
= attr_printf (13, "*delay_%d_%d", delay
->num
, i
/ 3);
1445 make_internal_attr (p
, newexp
, 1);
1447 if (have_annul_true
)
1449 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1450 if (condexp
== 0) condexp
= false_rtx
;
1451 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1452 make_numeric_value (1),
1453 make_numeric_value (0));
1454 p
= attr_printf (18, "*annul_true_%d_%d", delay
->num
, i
/ 3);
1455 make_internal_attr (p
, newexp
, 1);
1458 if (have_annul_false
)
1460 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1461 if (condexp
== 0) condexp
= false_rtx
;
1462 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1463 make_numeric_value (1),
1464 make_numeric_value (0));
1465 p
= attr_printf (18, "*annul_false_%d_%d", delay
->num
, i
/ 3);
1466 make_internal_attr (p
, newexp
, 1);
1472 /* This function is given a left and right side expression and an operator.
1473 Each side is a conditional expression, each alternative of which has a
1474 numerical value. The function returns another conditional expression
1475 which, for every possible set of condition values, returns a value that is
1476 the operator applied to the values of the two sides.
1478 Since this is called early, it must also support IF_THEN_ELSE. */
1481 operate_exp (op
, left
, right
)
1485 int left_value
, right_value
;
1489 /* If left is a string, apply operator to it and the right side. */
1490 if (GET_CODE (left
) == CONST_STRING
)
1492 /* If right is also a string, just perform the operation. */
1493 if (GET_CODE (right
) == CONST_STRING
)
1495 left_value
= atoi (XSTR (left
, 0));
1496 right_value
= atoi (XSTR (right
, 0));
1500 i
= left_value
+ right_value
;
1504 i
= left_value
- right_value
;
1508 i
= left_value
| right_value
;
1512 if (left_value
> right_value
)
1522 return make_numeric_value (i
);
1524 else if (GET_CODE (right
) == IF_THEN_ELSE
)
1526 /* Apply recursively to all values within. */
1527 rtx newleft
= operate_exp (op
, left
, XEXP (right
, 1));
1528 rtx newright
= operate_exp (op
, left
, XEXP (right
, 2));
1529 if (rtx_equal_p (newleft
, newright
))
1531 return attr_rtx (IF_THEN_ELSE
, XEXP (right
, 0), newleft
, newright
);
1533 else if (GET_CODE (right
) == COND
)
1538 newexp
= rtx_alloc (COND
);
1539 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (right
, 0));
1540 defval
= XEXP (newexp
, 1) = operate_exp (op
, left
, XEXP (right
, 1));
1542 for (i
= 0; i
< XVECLEN (right
, 0); i
+= 2)
1544 XVECEXP (newexp
, 0, i
) = XVECEXP (right
, 0, i
);
1545 XVECEXP (newexp
, 0, i
+ 1)
1546 = operate_exp (op
, left
, XVECEXP (right
, 0, i
+ 1));
1547 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1552 /* If the resulting cond is trivial (all alternatives
1553 give the same value), optimize it away. */
1556 obstack_free (rtl_obstack
, newexp
);
1557 return operate_exp (op
, left
, XEXP (right
, 1));
1560 /* If the result is the same as the RIGHT operand,
1562 if (rtx_equal_p (newexp
, right
))
1564 obstack_free (rtl_obstack
, newexp
);
1571 fatal ("Badly formed attribute value");
1574 /* Otherwise, do recursion the other way. */
1575 else if (GET_CODE (left
) == IF_THEN_ELSE
)
1577 rtx newleft
= operate_exp (op
, XEXP (left
, 1), right
);
1578 rtx newright
= operate_exp (op
, XEXP (left
, 2), right
);
1579 if (rtx_equal_p (newleft
, newright
))
1581 return attr_rtx (IF_THEN_ELSE
, XEXP (left
, 0), newleft
, newright
);
1583 else if (GET_CODE (left
) == COND
)
1588 newexp
= rtx_alloc (COND
);
1589 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (left
, 0));
1590 defval
= XEXP (newexp
, 1) = operate_exp (op
, XEXP (left
, 1), right
);
1592 for (i
= 0; i
< XVECLEN (left
, 0); i
+= 2)
1594 XVECEXP (newexp
, 0, i
) = XVECEXP (left
, 0, i
);
1595 XVECEXP (newexp
, 0, i
+ 1)
1596 = operate_exp (op
, XVECEXP (left
, 0, i
+ 1), right
);
1597 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1602 /* If the cond is trivial (all alternatives give the same value),
1603 optimize it away. */
1606 obstack_free (rtl_obstack
, newexp
);
1607 return operate_exp (op
, XEXP (left
, 1), right
);
1610 /* If the result is the same as the LEFT operand,
1612 if (rtx_equal_p (newexp
, left
))
1614 obstack_free (rtl_obstack
, newexp
);
1622 fatal ("Badly formed attribute value.");
1627 /* Once all attributes and DEFINE_FUNCTION_UNITs have been read, we
1628 construct a number of attributes.
1630 The first produces a function `function_units_used' which is given an
1631 insn and produces an encoding showing which function units are required
1632 for the execution of that insn. If the value is non-negative, the insn
1633 uses that unit; otherwise, the value is a one's compliment mask of units
1636 The second produces a function `result_ready_cost' which is used to
1637 determine the time that the result of an insn will be ready and hence
1638 a worst-case schedule.
1640 Both of these produce quite complex expressions which are then set as the
1641 default value of internal attributes. Normal attribute simplification
1642 should produce reasonable expressions.
1644 For each unit, a `<name>_unit_ready_cost' function will take an
1645 insn and give the delay until that unit will be ready with the result
1646 and a `<name>_unit_conflict_cost' function is given an insn already
1647 executing on the unit and a candidate to execute and will give the
1648 cost from the time the executing insn started until the candidate
1649 can start (ignore limitations on the number of simultaneous insns). */
1654 struct function_unit
*unit
, **unit_num
;
1655 struct function_unit_op
*op
, **op_array
, ***unit_ops
;
1660 int i
, j
, u
, num
, nvalues
;
1662 /* Validate the expressions we were given for the conditions and busy cost.
1663 Then make attributes for use in the conflict function. */
1664 for (unit
= units
; unit
; unit
= unit
->next
)
1665 for (op
= unit
->ops
; op
; op
= op
->next
)
1667 op
->condexp
= check_attr_test (op
->condexp
, 0);
1668 op
->busyexp
= check_attr_value (make_canonical (NULL_ATTR
,
1671 str
= attr_printf (strlen (unit
->name
) + 11, "*%s_case_%d",
1672 unit
->name
, op
->num
);
1673 make_internal_attr (str
, op
->busyexp
, 1);
1676 /* Compute the mask of function units used. Initially, the unitsmask is
1677 zero. Set up a conditional to compute each unit's contribution. */
1678 unitsmask
= make_numeric_value (0);
1679 newexp
= rtx_alloc (IF_THEN_ELSE
);
1680 XEXP (newexp
, 2) = make_numeric_value (0);
1682 /* Merge each function unit into the unit mask attributes. */
1683 for (unit
= units
; unit
; unit
= unit
->next
)
1685 XEXP (newexp
, 0) = check_attr_test (unit
->condexp
, 0);
1686 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1687 unitsmask
= operate_exp (OR_OP
, unitsmask
, newexp
);
1690 /* Simplify the unit mask expression, encode it, and make an attribute
1691 for the function_units_used function. */
1692 unitsmask
= simplify_by_exploding (unitsmask
);
1693 unitsmask
= encode_units_mask (unitsmask
);
1694 make_internal_attr ("*function_units_used", unitsmask
, 2);
1696 /* Create an array of ops for each unit. Add an extra unit for the
1697 result_ready_cost function that has the ops of all other units. */
1698 unit_ops
= (struct function_unit_op
***)
1699 alloca ((num_units
+ 1) * sizeof (struct function_unit_op
**));
1700 unit_num
= (struct function_unit
**)
1701 alloca ((num_units
+ 1) * sizeof (struct function_unit
*));
1703 unit_num
[num_units
] = unit
= (struct function_unit
*)
1704 alloca (sizeof (struct function_unit
));
1705 unit
->num
= num_units
;
1706 unit
->num_opclasses
= 0;
1708 for (unit
= units
; unit
; unit
= unit
->next
)
1710 unit_num
[num_units
]->num_opclasses
+= unit
->num_opclasses
;
1711 unit_num
[unit
->num
] = unit
;
1712 unit_ops
[unit
->num
] = op_array
= (struct function_unit_op
**)
1713 alloca (unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1715 for (op
= unit
->ops
; op
; op
= op
->next
)
1716 op_array
[op
->num
] = op
;
1719 /* Compose the array of ops for the extra unit. */
1720 unit_ops
[num_units
] = op_array
= (struct function_unit_op
**)
1721 alloca (unit_num
[num_units
]->num_opclasses
1722 * sizeof (struct function_unit_op
*));
1724 for (unit
= units
, i
= 0; unit
; i
+= unit
->num_opclasses
, unit
= unit
->next
)
1725 bcopy (unit_ops
[unit
->num
], &op_array
[i
],
1726 unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1728 /* Compute the ready cost function for each unit by computing the
1729 condition for each non-default value. */
1730 for (u
= 0; u
<= num_units
; u
++)
1736 op_array
= unit_ops
[unit
->num
];
1737 num
= unit
->num_opclasses
;
1739 /* Sort the array of ops into increasing ready cost order. */
1740 for (i
= 0; i
< num
; i
++)
1741 for (j
= num
- 1; j
> i
; j
--)
1742 if (op_array
[j
-1]->ready
< op_array
[j
]->ready
)
1745 op_array
[j
] = op_array
[j
-1];
1749 /* Determine how many distinct non-default ready cost values there
1750 are. We use a default ready cost value of 1. */
1751 nvalues
= 0; value
= 1;
1752 for (i
= num
- 1; i
>= 0; i
--)
1753 if (op_array
[i
]->ready
> value
)
1755 value
= op_array
[i
]->ready
;
1760 readycost
= make_numeric_value (1);
1763 /* Construct the ready cost expression as a COND of each value from
1764 the largest to the smallest. */
1765 readycost
= rtx_alloc (COND
);
1766 XVEC (readycost
, 0) = rtvec_alloc (nvalues
* 2);
1767 XEXP (readycost
, 1) = make_numeric_value (1);
1769 nvalues
= 0; orexp
= false_rtx
; value
= op_array
[0]->ready
;
1770 for (i
= 0; i
< num
; i
++)
1775 else if (op
->ready
== value
)
1776 orexp
= insert_right_side (IOR
, orexp
, op
->condexp
, -2);
1779 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
1780 XVECEXP (readycost
, 0, nvalues
* 2 + 1)
1781 = make_numeric_value (value
);
1784 orexp
= op
->condexp
;
1787 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
1788 XVECEXP (readycost
, 0, nvalues
* 2 + 1) = make_numeric_value (value
);
1791 /* Make an attribute for the ready_cost function. Simplifying
1792 further with simplify_by_exploding doesn't win. */
1794 str
= attr_printf (strlen (unit
->name
) + 20, "*%s_unit_ready_cost",
1797 str
= "*result_ready_cost";
1798 make_internal_attr (str
, readycost
, 0);
1801 /* For each unit that requires a conflict cost function, make an attribute
1802 that maps insns to the operation number. */
1803 for (unit
= units
; unit
; unit
= unit
->next
)
1807 if (unit
->min_busy_delay
== unit
->max_busy_delay
)
1810 caseexp
= rtx_alloc (COND
);
1811 XVEC (caseexp
, 0) = rtvec_alloc ((unit
->num_opclasses
- 1) * 2);
1813 for (op
= unit
->ops
; op
; op
= op
->next
)
1815 /* Make our adjustment to the COND being computed. If we are the
1816 last operation class, place our values into the default of the
1818 if (op
->num
== unit
->num_opclasses
- 1)
1820 XEXP (caseexp
, 1) = make_numeric_value (op
->num
);
1824 XVECEXP (caseexp
, 0, op
->num
* 2) = op
->condexp
;
1825 XVECEXP (caseexp
, 0, op
->num
* 2 + 1)
1826 = make_numeric_value (op
->num
);
1830 /* Simplifying caseexp with simplify_by_exploding doesn't win. */
1831 str
= attr_printf (strlen (unit
->name
) + 8, "*%s_cases", unit
->name
);
1832 make_internal_attr (str
, caseexp
, 1);
1836 /* Translate the CONST_STRING expressions in X to change the encoding of
1837 value. On input, the value is a bitmask with a one bit for each unit
1838 used; on output, the value is the unit number (zero based) if one
1839 and only one unit is used or the one's compliment of the bitmask. */
1842 encode_units_mask (x
)
1847 register enum rtx_code code
;
1850 code
= GET_CODE (x
);
1855 i
= atoi (XSTR (x
, 0));
1857 abort (); /* The sign bit encodes a one's compliment mask. */
1858 else if (i
!= 0 && i
== (i
& -i
))
1859 /* Only one bit is set, so yield that unit number. */
1860 for (j
= 0; (i
>>= 1) != 0; j
++)
1864 return attr_rtx (CONST_STRING
, attr_printf (4, "%d", j
));
1878 /* Compare the elements. If any pair of corresponding elements
1879 fail to match, return 0 for the whole things. */
1881 fmt
= GET_RTX_FORMAT (code
);
1882 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1888 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1889 XVECEXP (x
, i
, j
) = encode_units_mask (XVECEXP (x
, i
, j
));
1893 XEXP (x
, i
) = encode_units_mask (XEXP (x
, i
));
1900 /* Once all attributes and insns have been read and checked, we construct for
1901 each attribute value a list of all the insns that have that value for
1906 struct attr_desc
*attr
;
1908 struct attr_value
*av
;
1909 struct insn_ent
*ie
;
1910 struct insn_def
*id
;
1914 /* Don't fill constant attributes. The value is independent of
1915 any particular insn. */
1919 for (id
= defs
; id
; id
= id
->next
)
1921 /* If no value is specified for this insn for this attribute, use the
1924 if (XVEC (id
->def
, id
->vec_idx
))
1925 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1926 if (! strcmp (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
1928 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
1931 av
= attr
->default_val
;
1933 av
= get_attr_value (value
, attr
, id
->insn_code
);
1935 ie
= (struct insn_ent
*) xmalloc (sizeof (struct insn_ent
));
1936 ie
->insn_code
= id
->insn_code
;
1937 ie
->insn_index
= id
->insn_code
;
1938 insert_insn_ent (av
, ie
);
1942 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
1943 test that checks relative positions of insns (uses MATCH_DUP or PC).
1944 If so, replace it with what is obtained by passing the expression to
1945 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
1946 recursively on each value (including the default value). Otherwise,
1947 return the value returned by NO_ADDRESS_FN applied to EXP. */
1950 substitute_address (exp
, no_address_fn
, address_fn
)
1952 rtx (*no_address_fn
) ();
1953 rtx (*address_fn
) ();
1958 if (GET_CODE (exp
) == COND
)
1960 /* See if any tests use addresses. */
1962 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1963 walk_attr_value (XVECEXP (exp
, 0, i
));
1966 return (*address_fn
) (exp
);
1968 /* Make a new copy of this COND, replacing each element. */
1969 newexp
= rtx_alloc (COND
);
1970 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
1971 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1973 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
1974 XVECEXP (newexp
, 0, i
+ 1)
1975 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
1976 no_address_fn
, address_fn
);
1979 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
1980 no_address_fn
, address_fn
);
1985 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
1988 walk_attr_value (XEXP (exp
, 0));
1990 return (*address_fn
) (exp
);
1992 return attr_rtx (IF_THEN_ELSE
,
1993 substitute_address (XEXP (exp
, 0),
1994 no_address_fn
, address_fn
),
1995 substitute_address (XEXP (exp
, 1),
1996 no_address_fn
, address_fn
),
1997 substitute_address (XEXP (exp
, 2),
1998 no_address_fn
, address_fn
));
2001 return (*no_address_fn
) (exp
);
2004 /* Make new attributes from the `length' attribute. The following are made,
2005 each corresponding to a function called from `shorten_branches' or
2008 *insn_default_length This is the length of the insn to be returned
2009 by `get_attr_length' before `shorten_branches'
2010 has been called. In each case where the length
2011 depends on relative addresses, the largest
2012 possible is used. This routine is also used
2013 to compute the initial size of the insn.
2015 *insn_variable_length_p This returns 1 if the insn's length depends
2016 on relative addresses, zero otherwise.
2018 *insn_current_length This is only called when it is known that the
2019 insn has a variable length and returns the
2020 current length, based on relative addresses.
2024 make_length_attrs ()
2026 static char *new_names
[] = {"*insn_default_length",
2027 "*insn_variable_length_p",
2028 "*insn_current_length"};
2029 static rtx (*no_address_fn
[]) () = {identity_fn
, zero_fn
, zero_fn
};
2030 static rtx (*address_fn
[]) () = {max_fn
, one_fn
, identity_fn
};
2032 struct attr_desc
*length_attr
, *new_attr
;
2033 struct attr_value
*av
, *new_av
;
2034 struct insn_ent
*ie
, *new_ie
;
2036 /* See if length attribute is defined. If so, it must be numeric. Make
2037 it special so we don't output anything for it. */
2038 length_attr
= find_attr ("length", 0);
2039 if (length_attr
== 0)
2042 if (! length_attr
->is_numeric
)
2043 fatal ("length attribute must be numeric.");
2045 length_attr
->is_const
= 0;
2046 length_attr
->is_special
= 1;
2048 /* Make each new attribute, in turn. */
2049 for (i
= 0; i
< sizeof new_names
/ sizeof new_names
[0]; i
++)
2051 make_internal_attr (new_names
[i
],
2052 substitute_address (length_attr
->default_val
->value
,
2053 no_address_fn
[i
], address_fn
[i
]),
2055 new_attr
= find_attr (new_names
[i
], 0);
2056 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2057 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2059 new_av
= get_attr_value (substitute_address (av
->value
,
2062 new_attr
, ie
->insn_code
);
2063 new_ie
= (struct insn_ent
*) xmalloc (sizeof (struct insn_ent
));
2064 new_ie
->insn_code
= ie
->insn_code
;
2065 new_ie
->insn_index
= ie
->insn_index
;
2066 insert_insn_ent (new_av
, new_ie
);
2071 /* Utility functions called from above routine. */
2084 return make_numeric_value (0);
2091 return make_numeric_value (1);
2098 return make_numeric_value (max_attr_value (exp
));
2101 /* Take a COND expression and see if any of the conditions in it can be
2102 simplified. If any are known true or known false for the particular insn
2103 code, the COND can be further simplified.
2105 Also call ourselves on any COND operations that are values of this COND.
2107 We do not modify EXP; rather, we make and return a new rtx. */
2110 simplify_cond (exp
, insn_code
, insn_index
)
2112 int insn_code
, insn_index
;
2115 /* We store the desired contents here,
2116 then build a new expression if they don't match EXP. */
2117 rtx defval
= XEXP (exp
, 1);
2118 rtx new_defval
= XEXP (exp
, 1);
2120 int len
= XVECLEN (exp
, 0);
2121 rtx
*tests
= (rtx
*) alloca (len
* sizeof (rtx
));
2125 /* This lets us free all storage allocated below, if appropriate. */
2126 first_spacer
= (char *) obstack_finish (rtl_obstack
);
2128 bcopy (&XVECEXP (exp
, 0, 0), tests
, len
* sizeof (rtx
));
2130 /* See if default value needs simplification. */
2131 if (GET_CODE (defval
) == COND
)
2132 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
2134 /* Simplify the subexpressions, and see what tests we can get rid of. */
2136 for (i
= 0; i
< len
; i
+= 2)
2138 rtx newtest
, newval
;
2140 /* Simplify this test. */
2141 newtest
= SIMPLIFY_TEST_EXP (tests
[i
], insn_code
, insn_index
);
2144 newval
= tests
[i
+ 1];
2145 /* See if this value may need simplification. */
2146 if (GET_CODE (newval
) == COND
)
2147 newval
= simplify_cond (newval
, insn_code
, insn_index
);
2149 /* Look for ways to delete or combine this test. */
2150 if (newtest
== true_rtx
)
2152 /* If test is true, make this value the default
2153 and discard this + any following tests. */
2155 defval
= tests
[i
+ 1];
2156 new_defval
= newval
;
2159 else if (newtest
== false_rtx
)
2161 /* If test is false, discard it and its value. */
2162 for (j
= i
; j
< len
- 2; j
++)
2163 tests
[j
] = tests
[j
+ 2];
2167 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
2169 /* If this value and the value for the prev test are the same,
2173 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
2174 insn_code
, insn_index
);
2176 /* Delete this test/value. */
2177 for (j
= i
; j
< len
- 2; j
++)
2178 tests
[j
] = tests
[j
+ 2];
2183 tests
[i
+ 1] = newval
;
2186 /* If the last test in a COND has the same value
2187 as the default value, that test isn't needed. */
2189 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
2192 /* See if we changed anything. */
2193 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
2196 for (i
= 0; i
< len
; i
++)
2197 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
2205 obstack_free (rtl_obstack
, first_spacer
);
2206 if (GET_CODE (defval
) == COND
)
2207 return simplify_cond (defval
, insn_code
, insn_index
);
2212 obstack_free (rtl_obstack
, first_spacer
);
2217 rtx newexp
= rtx_alloc (COND
);
2219 XVEC (newexp
, 0) = rtvec_alloc (len
);
2220 bcopy (tests
, &XVECEXP (newexp
, 0, 0), len
* sizeof (rtx
));
2221 XEXP (newexp
, 1) = new_defval
;
2226 /* Remove an insn entry from an attribute value. */
2229 remove_insn_ent (av
, ie
)
2230 struct attr_value
*av
;
2231 struct insn_ent
*ie
;
2233 struct insn_ent
*previe
;
2235 if (av
->first_insn
== ie
)
2236 av
->first_insn
= ie
->next
;
2239 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
2241 previe
->next
= ie
->next
;
2245 if (ie
->insn_code
== -1)
2246 av
->has_asm_insn
= 0;
2249 /* Insert an insn entry in an attribute value list. */
2252 insert_insn_ent (av
, ie
)
2253 struct attr_value
*av
;
2254 struct insn_ent
*ie
;
2256 ie
->next
= av
->first_insn
;
2257 av
->first_insn
= ie
;
2259 if (ie
->insn_code
== -1)
2260 av
->has_asm_insn
= 1;
2263 /* This is a utility routine to take an expression that is a tree of either
2264 AND or IOR expressions and insert a new term. The new term will be
2265 inserted at the right side of the first node whose code does not match
2266 the root. A new node will be created with the root's code. Its left
2267 side will be the old right side and its right side will be the new
2270 If the `term' is itself a tree, all its leaves will be inserted. */
2273 insert_right_side (code
, exp
, term
, insn_code
, insn_index
)
2277 int insn_code
, insn_index
;
2281 /* Avoid consing in some special cases. */
2282 if (code
== AND
&& term
== true_rtx
)
2284 if (code
== AND
&& term
== false_rtx
)
2286 if (code
== AND
&& exp
== true_rtx
)
2288 if (code
== AND
&& exp
== false_rtx
)
2290 if (code
== IOR
&& term
== true_rtx
)
2292 if (code
== IOR
&& term
== false_rtx
)
2294 if (code
== IOR
&& exp
== true_rtx
)
2296 if (code
== IOR
&& exp
== false_rtx
)
2298 if (attr_equal_p (exp
, term
))
2301 if (GET_CODE (term
) == code
)
2303 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
2304 insn_code
, insn_index
);
2305 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
2306 insn_code
, insn_index
);
2311 if (GET_CODE (exp
) == code
)
2313 rtx
new = insert_right_side (code
, XEXP (exp
, 1),
2314 term
, insn_code
, insn_index
);
2315 if (new != XEXP (exp
, 1))
2316 /* Make a copy of this expression and call recursively. */
2317 newexp
= attr_rtx (code
, XEXP (exp
, 0), new);
2323 /* Insert the new term. */
2324 newexp
= attr_rtx (code
, exp
, term
);
2327 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2330 /* If we have an expression which AND's a bunch of
2331 (not (eq_attrq "alternative" "n"))
2332 terms, we may have covered all or all but one of the possible alternatives.
2333 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
2335 This routine is passed an expression and either AND or IOR. It returns a
2336 bitmask indicating which alternatives are present.
2337 ??? What does "present" mean? */
2340 compute_alternative_mask (exp
, code
)
2345 if (GET_CODE (exp
) == code
)
2346 return compute_alternative_mask (XEXP (exp
, 0), code
)
2347 | compute_alternative_mask (XEXP (exp
, 1), code
);
2349 else if (code
== AND
&& GET_CODE (exp
) == NOT
2350 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2351 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
2352 string
= XSTR (XEXP (exp
, 0), 1);
2354 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
2355 && XSTR (exp
, 0) == alternative_name
)
2356 string
= XSTR (exp
, 1);
2362 return 1 << (string
[0] - '0');
2363 return 1 << atoi (string
);
2366 /* Given I, a single-bit mask, return RTX to compare the `alternative'
2367 attribute with the value represented by that bit. */
2370 make_alternative_compare (mask
)
2377 for (i
= 0; (mask
& (1 << i
)) == 0; i
++)
2380 newexp
= attr_rtx (EQ_ATTR
, alternative_name
, attr_numeral (i
));
2381 RTX_UNCHANGING_P (newexp
) = 1;
2386 /* If we are processing an (eq_attr "attr" "value") test, we find the value
2387 of "attr" for this insn code. From that value, we can compute a test
2388 showing when the EQ_ATTR will be true. This routine performs that
2389 computation. If a test condition involves an address, we leave the EQ_ATTR
2390 intact because addresses are only valid for the `length' attribute. */
2392 /* ??? Kenner, document the meanings of the arguments!!! */
2395 evaluate_eq_attr (exp
, value
, insn_code
, insn_index
)
2398 int insn_code
, insn_index
;
2405 if (GET_CODE (value
) == CONST_STRING
)
2407 if (! strcmp (XSTR (value
, 0), XSTR (exp
, 1)))
2412 else if (GET_CODE (value
) == COND
)
2414 /* We construct an IOR of all the cases for which the requested attribute
2415 value is present. Since we start with FALSE, if it is not present,
2416 FALSE will be returned.
2418 Each case is the AND of the NOT's of the previous conditions with the
2419 current condition; in the default case the current condition is TRUE.
2421 For each possible COND value, call ourselves recursively.
2423 The extra TRUE and FALSE expressions will be eliminated by another
2424 call to the simplification routine. */
2429 if (current_alternative_string
)
2430 clear_struct_flag (value
);
2432 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2434 rtx
this = SIMPLIFY_TEST_EXP (XVECEXP (value
, 0, i
),
2435 insn_code
, insn_index
);
2437 SIMPLIFY_ALTERNATIVE (this);
2439 right
= insert_right_side (AND
, andexp
, this,
2440 insn_code
, insn_index
);
2441 right
= insert_right_side (AND
, right
,
2442 evaluate_eq_attr (exp
, XVECEXP (value
, 0, i
+ 1),
2443 insn_code
, insn_index
),
2444 insn_code
, insn_index
);
2445 orexp
= insert_right_side (IOR
, orexp
, right
,
2446 insn_code
, insn_index
);
2448 /* Add this condition into the AND expression. */
2449 newexp
= attr_rtx (NOT
, this);
2450 andexp
= insert_right_side (AND
, andexp
, newexp
,
2451 insn_code
, insn_index
);
2454 /* Handle the default case. */
2455 right
= insert_right_side (AND
, andexp
,
2456 evaluate_eq_attr (exp
, XEXP (value
, 1),
2457 insn_code
, insn_index
),
2458 insn_code
, insn_index
);
2459 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2464 /* If uses an address, must return original expression. But set the
2465 RTX_UNCHANGING_P bit so we don't try to simplify it again. */
2468 walk_attr_value (newexp
);
2472 /* This had `&& current_alternative_string', which seems to be wrong. */
2473 if (! RTX_UNCHANGING_P (exp
))
2474 return copy_rtx_unchanging (exp
);
2481 /* This routine is called when an AND of a term with a tree of AND's is
2482 encountered. If the term or its complement is present in the tree, it
2483 can be replaced with TRUE or FALSE, respectively.
2485 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2486 be true and hence are complementary.
2488 There is one special case: If we see
2489 (and (not (eq_attr "att" "v1"))
2490 (eq_attr "att" "v2"))
2491 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2492 replace the term, not anything in the AND tree. So we pass a pointer to
2496 simplify_and_tree (exp
, pterm
, insn_code
, insn_index
)
2499 int insn_code
, insn_index
;
2504 int left_eliminates_term
, right_eliminates_term
;
2506 if (GET_CODE (exp
) == AND
)
2508 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2509 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2510 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2512 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2514 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2518 else if (GET_CODE (exp
) == IOR
)
2520 /* For the IOR case, we do the same as above, except that we can
2521 only eliminate `term' if both sides of the IOR would do so. */
2523 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2524 left_eliminates_term
= (temp
== true_rtx
);
2527 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2528 right_eliminates_term
= (temp
== true_rtx
);
2530 if (left_eliminates_term
&& right_eliminates_term
)
2533 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2535 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2537 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2541 /* Check for simplifications. Do some extra checking here since this
2542 routine is called so many times. */
2547 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
2550 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
2553 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
2555 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
2558 if (! strcmp (XSTR (exp
, 1), XSTR (*pterm
, 1)))
2564 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2565 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
2567 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
2570 if (! strcmp (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
2576 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2577 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
2579 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
2582 if (! strcmp (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
2588 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
2590 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
2594 else if (GET_CODE (exp
) == NOT
)
2596 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
2600 else if (GET_CODE (*pterm
) == NOT
)
2602 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
2606 else if (attr_equal_p (exp
, *pterm
))
2612 /* Similar to `simplify_and_tree', but for IOR trees. */
2615 simplify_or_tree (exp
, pterm
, insn_code
, insn_index
)
2618 int insn_code
, insn_index
;
2623 int left_eliminates_term
, right_eliminates_term
;
2625 if (GET_CODE (exp
) == IOR
)
2627 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2628 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2629 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2631 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2633 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2637 else if (GET_CODE (exp
) == AND
)
2639 /* For the AND case, we do the same as above, except that we can
2640 only eliminate `term' if both sides of the AND would do so. */
2642 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2643 left_eliminates_term
= (temp
== false_rtx
);
2646 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2647 right_eliminates_term
= (temp
== false_rtx
);
2649 if (left_eliminates_term
&& right_eliminates_term
)
2652 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2654 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2656 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2660 if (attr_equal_p (exp
, *pterm
))
2663 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
2666 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
2669 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2670 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2671 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
2674 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2675 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
2676 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
2682 /* Given an expression, see if it can be simplified for a particular insn
2683 code based on the values of other attributes being tested. This can
2684 eliminate nested get_attr_... calls.
2686 Note that if an endless recursion is specified in the patterns, the
2687 optimization will loop. However, it will do so in precisely the cases where
2688 an infinite recursion loop could occur during compilation. It's better that
2692 simplify_test_exp (exp
, insn_code
, insn_index
)
2694 int insn_code
, insn_index
;
2697 struct attr_desc
*attr
;
2698 struct attr_value
*av
;
2699 struct insn_ent
*ie
;
2702 char *spacer
= (char *) obstack_finish (rtl_obstack
);
2704 static rtx loser
= 0;
2705 static int count
= 0;
2706 static stopcount
= 0;
2711 if (count
== stopcount
)
2714 /* Don't re-simplify something we already simplified. */
2715 if (RTX_UNCHANGING_P (exp
) || MEM_IN_STRUCT_P (exp
))
2718 switch (GET_CODE (exp
))
2721 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2722 SIMPLIFY_ALTERNATIVE (left
);
2723 if (left
== false_rtx
)
2725 obstack_free (rtl_obstack
, spacer
);
2728 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2729 SIMPLIFY_ALTERNATIVE (right
);
2730 if (left
== false_rtx
)
2732 obstack_free (rtl_obstack
, spacer
);
2736 /* If either side is an IOR and we have (eq_attr "alternative" ..")
2737 present on both sides, apply the distributive law since this will
2738 yield simplifications. */
2739 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
2740 && compute_alternative_mask (left
, IOR
)
2741 && compute_alternative_mask (right
, IOR
))
2743 if (GET_CODE (left
) == IOR
)
2750 newexp
= attr_rtx (IOR
,
2751 attr_rtx (AND
, left
, XEXP (right
, 0)),
2752 attr_rtx (AND
, left
, XEXP (right
, 1)));
2754 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2757 /* Try with the term on both sides. */
2758 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
2759 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2760 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
2762 if (left
== false_rtx
|| right
== false_rtx
)
2764 obstack_free (rtl_obstack
, spacer
);
2767 else if (left
== true_rtx
)
2771 else if (right
== true_rtx
)
2775 /* See if all or all but one of the insn's alternatives are specified
2776 in this tree. Optimize if so. */
2778 else if (insn_code
>= 0
2779 && (GET_CODE (left
) == AND
2780 || (GET_CODE (left
) == NOT
2781 && GET_CODE (XEXP (left
, 0)) == EQ_ATTR
2782 && XSTR (XEXP (left
, 0), 0) == alternative_name
)
2783 || GET_CODE (right
) == AND
2784 || (GET_CODE (right
) == NOT
2785 && GET_CODE (XEXP (right
, 0)) == EQ_ATTR
2786 && XSTR (XEXP (right
, 0), 0) == alternative_name
)))
2788 i
= compute_alternative_mask (exp
, AND
);
2789 if (i
& ~insn_alternatives
[insn_code
])
2790 fatal ("Illegal alternative specified for pattern number %d",
2793 /* If all alternatives are excluded, this is false. */
2794 i
^= insn_alternatives
[insn_code
];
2797 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2799 /* If just one excluded, AND a comparison with that one to the
2800 front of the tree. The others will be eliminated by
2801 optimization. We do not want to do this if the insn has one
2802 alternative and we have tested none of them! */
2803 left
= make_alternative_compare (i
);
2804 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2805 newexp
= attr_rtx (AND
, left
, right
);
2807 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2811 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2813 newexp
= attr_rtx (AND
, left
, right
);
2814 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2819 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2820 SIMPLIFY_ALTERNATIVE (left
);
2821 if (left
== true_rtx
)
2823 obstack_free (rtl_obstack
, spacer
);
2826 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2827 SIMPLIFY_ALTERNATIVE (right
);
2828 if (right
== true_rtx
)
2830 obstack_free (rtl_obstack
, spacer
);
2834 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
2835 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2836 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
2838 if (right
== true_rtx
|| left
== true_rtx
)
2840 obstack_free (rtl_obstack
, spacer
);
2843 else if (left
== false_rtx
)
2847 else if (right
== false_rtx
)
2852 /* Test for simple cases where the distributive law is useful. I.e.,
2853 convert (ior (and (x) (y))
2859 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2860 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
2862 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
2864 left
= XEXP (left
, 0);
2866 newexp
= attr_rtx (AND
, left
, right
);
2867 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2870 /* See if all or all but one of the insn's alternatives are specified
2871 in this tree. Optimize if so. */
2873 else if (insn_code
>= 0
2874 && (GET_CODE (left
) == IOR
2875 || (GET_CODE (left
) == EQ_ATTR
2876 && XSTR (left
, 0) == alternative_name
)
2877 || GET_CODE (right
) == IOR
2878 || (GET_CODE (right
) == EQ_ATTR
2879 && XSTR (right
, 0) == alternative_name
)))
2881 i
= compute_alternative_mask (exp
, IOR
);
2882 if (i
& ~insn_alternatives
[insn_code
])
2883 fatal ("Illegal alternative specified for pattern number %d",
2886 /* If all alternatives are included, this is true. */
2887 i
^= insn_alternatives
[insn_code
];
2890 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2892 /* If just one excluded, IOR a comparison with that one to the
2893 front of the tree. The others will be eliminated by
2894 optimization. We do not want to do this if the insn has one
2895 alternative and we have tested none of them! */
2896 left
= make_alternative_compare (i
);
2897 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2898 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
2900 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2904 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2906 newexp
= attr_rtx (IOR
, left
, right
);
2907 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2912 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
2914 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
2915 insn_code
, insn_index
);
2916 SIMPLIFY_ALTERNATIVE (left
);
2920 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2921 SIMPLIFY_ALTERNATIVE (left
);
2922 if (GET_CODE (left
) == NOT
)
2923 return XEXP (left
, 0);
2925 if (left
== false_rtx
)
2927 obstack_free (rtl_obstack
, spacer
);
2930 else if (left
== true_rtx
)
2932 obstack_free (rtl_obstack
, spacer
);
2936 /* Try to apply De`Morgan's laws. */
2937 else if (GET_CODE (left
) == IOR
)
2939 newexp
= attr_rtx (AND
,
2940 attr_rtx (NOT
, XEXP (left
, 0)),
2941 attr_rtx (NOT
, XEXP (left
, 1)));
2943 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2945 else if (GET_CODE (left
) == AND
)
2947 newexp
= attr_rtx (IOR
,
2948 attr_rtx (NOT
, XEXP (left
, 0)),
2949 attr_rtx (NOT
, XEXP (left
, 1)));
2951 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2953 else if (left
!= XEXP (exp
, 0))
2955 newexp
= attr_rtx (NOT
, left
);
2960 if (current_alternative_string
&& XSTR (exp
, 0) == alternative_name
)
2961 return (XSTR (exp
, 1) == current_alternative_string
2962 ? true_rtx
: false_rtx
);
2964 /* Look at the value for this insn code in the specified attribute.
2965 We normally can replace this comparison with the condition that
2966 would give this insn the values being tested for. */
2967 if (XSTR (exp
, 0) != alternative_name
2968 && (attr
= find_attr (XSTR (exp
, 0), 0)) != NULL
)
2969 for (av
= attr
->first_value
; av
; av
= av
->next
)
2970 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2971 if (ie
->insn_code
== insn_code
)
2972 return evaluate_eq_attr (exp
, av
->value
, insn_code
, insn_index
);
2975 /* We have already simplified this expression. Simplifying it again
2976 won't buy anything unless we weren't given a valid insn code
2977 to process (i.e., we are canonicalizing something.). */
2978 if (insn_code
!= -2 /* Seems wrong: && current_alternative_string. */
2979 && ! RTX_UNCHANGING_P (newexp
))
2980 return copy_rtx_unchanging (newexp
);
2988 /* Optimize the attribute lists by seeing if we can determine conditional
2989 values from the known values of other attributes. This will save subroutine
2990 calls during the compilation. */
2995 struct attr_desc
*attr
;
2996 struct attr_value
*av
;
2997 struct insn_ent
*ie
;
2999 int something_changed
= 1;
3001 struct attr_value_list
{ struct attr_value
*av
;
3002 struct insn_ent
*ie
;
3003 struct attr_desc
* attr
;
3004 struct attr_value_list
*next
; };
3005 struct attr_value_list
**insn_code_values
;
3006 struct attr_value_list
*iv
;
3008 /* For each insn code, make a list of all the insn_ent's for it,
3009 for all values for all attributes. */
3011 /* Make 2 extra elements, for "code" values -2 and -1. */
3013 = (struct attr_value_list
**) alloca ((insn_code_number
+ 2)
3014 * sizeof (struct attr_value_list
*));
3015 bzero (insn_code_values
,
3016 (insn_code_number
+ 2) * sizeof (struct attr_value_list
*));
3017 /* Offset the table address so we can index by -2 or -1. */
3018 insn_code_values
+= 2;
3020 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
3021 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
3022 for (av
= attr
->first_value
; av
; av
= av
->next
)
3023 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3025 iv
= ((struct attr_value_list
*)
3026 alloca (sizeof (struct attr_value_list
)));
3030 iv
->next
= insn_code_values
[ie
->insn_code
];
3031 insn_code_values
[ie
->insn_code
] = iv
;
3034 /* Process one insn code at a time. */
3035 for (i
= -2; i
< insn_code_number
; i
++)
3037 /* Clear the MEM_IN_STRUCT_P flag everywhere relevant.
3038 We use it to mean "already simplified for this insn". */
3039 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3040 clear_struct_flag (iv
->av
->value
);
3042 /* Loop until nothing changes for one iteration. */
3043 something_changed
= 1;
3044 while (something_changed
)
3046 something_changed
= 0;
3047 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3049 struct obstack
*old
= rtl_obstack
;
3050 char *spacer
= (char *) obstack_finish (temp_obstack
);
3055 if (GET_CODE (av
->value
) != COND
)
3058 rtl_obstack
= temp_obstack
;
3059 #if 0 /* This was intended as a speed up, but it was slower. */
3060 if (insn_n_alternatives
[ie
->insn_code
] > 6
3061 && count_sub_rtxs (av
->value
, 200) >= 200)
3062 newexp
= simplify_by_alternatives (av
->value
, ie
->insn_code
,
3066 newexp
= simplify_cond (av
->value
, ie
->insn_code
,
3070 if (newexp
!= av
->value
)
3072 newexp
= attr_copy_rtx (newexp
);
3073 remove_insn_ent (av
, ie
);
3074 av
= get_attr_value (newexp
, attr
, ie
->insn_code
);
3076 insert_insn_ent (av
, ie
);
3077 something_changed
= 1;
3079 obstack_free (temp_obstack
, spacer
);
3087 simplify_by_alternatives (exp
, insn_code
, insn_index
)
3089 int insn_code
, insn_index
;
3092 int len
= insn_n_alternatives
[insn_code
];
3093 rtx newexp
= rtx_alloc (COND
);
3097 XVEC (newexp
, 0) = rtvec_alloc (len
* 2);
3099 /* It will not matter what value we use as the default value
3100 of the new COND, since that default will never be used.
3101 Choose something of the right type. */
3102 for (ultimate
= exp
; GET_CODE (ultimate
) == COND
;)
3103 ultimate
= XEXP (ultimate
, 1);
3104 XEXP (newexp
, 1) = ultimate
;
3106 for (i
= 0; i
< insn_n_alternatives
[insn_code
]; i
++)
3108 current_alternative_string
= attr_numeral (i
);
3109 XVECEXP (newexp
, 0, i
* 2) = make_alternative_compare (1 << i
);
3110 XVECEXP (newexp
, 0, i
* 2 + 1)
3111 = simplify_cond (exp
, insn_code
, insn_index
);
3114 current_alternative_string
= 0;
3115 return simplify_cond (newexp
, insn_code
, insn_index
);
3119 /* An expression where all the unknown terms are EQ_ATTR tests can be
3120 rearranged into a COND provided we can enumerate all possible
3121 combinations of the unknown values. The set of combinations become the
3122 tests of the COND; the value of the expression given that combination is
3123 computed and becomes the corresponding value. To do this, we must be
3124 able to enumerate all values for each attribute used in the expression
3125 (currently, we give up if we find a numeric attribute).
3127 If the set of EQ_ATTR tests used in an expression tests the value of N
3128 different attributes, the list of all possible combinations can be made
3129 by walking the N-dimensional attribute space defined by those
3130 attributes. We record each of these as a struct dimension.
3132 The algorithm relies on sharing EQ_ATTR nodes: if two nodes in an
3133 expression are the same, the will also have the same address. We find
3134 all the EQ_ATTR nodes by marking them MEM_VOLATILE_P. This bit later
3135 represents the value of an EQ_ATTR node, so once all nodes are marked,
3136 they are also given an initial value of FALSE.
3138 We then separate the set of EQ_ATTR nodes into dimensions for each
3139 attribute and put them on the VALUES list. Terms are added as needed by
3140 `add_values_to_cover' so that all possible values of the attribute are
3143 Each dimension also has a current value. This is the node that is
3144 currently considered to be TRUE. If this is one of the nodes added by
3145 `add_values_to_cover', all the EQ_ATTR tests in the original expression
3146 will be FALSE. Otherwise, only the CURRENT_VALUE will be true.
3148 NUM_VALUES is simply the length of the VALUES list and is there for
3151 Once the dimensions are created, the algorithm enumerates all possible
3152 values and computes the current value of the given expression. */
3156 struct attr_desc
*attr
; /* Attribute for this dimension. */
3157 rtx values
; /* List of attribute values used. */
3158 rtx current_value
; /* Position in the list for the TRUE value. */
3159 int num_values
; /* Length of the values list. */
3162 /* If EXP is a suitable expression, reorganize it by constructing an
3163 equivalent expression that is a COND with the tests being all combinations
3164 of attribute values and the values being simple constants. */
3167 simplify_by_exploding (exp
)
3170 rtx list
= 0, link
, condexp
, defval
;
3171 struct dimension
*space
;
3172 rtx
*condtest
, *condval
;
3173 int i
, j
, total
, ndim
;
3174 int most_tests
, num_marks
, new_marks
;
3176 /* Locate all the EQ_ATTR expressions. */
3177 if (! find_and_mark_used_attributes (exp
, &list
))
3179 unmark_used_attributes (list
, 0, 0);
3183 /* Create an attribute space from the list of used attributes. For each
3184 dimension in the attribute space, record the attribute, list of values
3185 used, and number of values used. Add members to the list of values to
3186 cover the domain of the attribute. This makes the expanded COND form
3187 order independent. */
3190 for (link
= list
; link
; link
= XEXP (link
, 1))
3192 space
= (struct dimension
*) alloca (ndim
* sizeof (struct dimension
));
3195 for (ndim
= 0; list
; ndim
++)
3197 /* Pull the first attribute value from the list and record that
3198 attribute as another dimension in the attribute space. */
3199 char *name
= XSTR (XEXP (list
, 0), 0);
3202 if ((space
[ndim
].attr
= find_attr (name
, 0)) == 0
3203 || space
[ndim
].attr
->is_numeric
)
3205 unmark_used_attributes (list
, space
, ndim
);
3209 /* Add all remaining attribute values that refer to this attribute. */
3210 space
[ndim
].num_values
= 0;
3211 space
[ndim
].values
= 0;
3213 for (link
= list
; link
; link
= *prev
)
3214 if (! strcmp (XSTR (XEXP (link
, 0), 0), name
))
3216 space
[ndim
].num_values
++;
3217 *prev
= XEXP (link
, 1);
3218 XEXP (link
, 1) = space
[ndim
].values
;
3219 space
[ndim
].values
= link
;
3222 prev
= &XEXP (link
, 1);
3224 /* Add sufficient members to the list of values to make the list
3225 mutually exclusive and record the total size of the attribute
3227 total
*= add_values_to_cover (&space
[ndim
]);
3230 /* Sort the attribute space so that the attributes go from non-constant
3231 to constant and from most values to least values. */
3232 for (i
= 0; i
< ndim
; i
++)
3233 for (j
= ndim
- 1; j
> i
; j
--)
3234 if ((space
[j
-1].attr
->is_const
&& !space
[j
].attr
->is_const
)
3235 || space
[j
-1].num_values
< space
[j
].num_values
)
3237 struct dimension tmp
;
3239 space
[j
] = space
[j
-1];
3243 /* Establish the initial current value. */
3244 for (i
= 0; i
< ndim
; i
++)
3245 space
[i
].current_value
= space
[i
].values
;
3247 condtest
= (rtx
*) alloca (total
* sizeof (rtx
));
3248 condval
= (rtx
*) alloca (total
* sizeof (rtx
));
3250 /* Expand the tests and values by iterating over all values in the
3254 condtest
[i
] = test_for_current_value (space
, ndim
);
3255 condval
[i
] = simplify_with_current_value (exp
, space
, ndim
);
3256 if (! increment_current_value (space
, ndim
))
3262 /* We are now finished with the original expression. */
3263 unmark_used_attributes (0, space
, ndim
);
3265 /* Find the most used constant value and make that the default. */
3267 for (i
= num_marks
= 0; i
< total
; i
++)
3268 if (GET_CODE (condval
[i
]) == CONST_STRING
3269 && ! MEM_VOLATILE_P (condval
[i
]))
3271 /* Mark the unmarked constant value and count how many are marked. */
3272 MEM_VOLATILE_P (condval
[i
]) = 1;
3273 for (j
= new_marks
= 0; j
< total
; j
++)
3274 if (GET_CODE (condval
[j
]) == CONST_STRING
3275 && MEM_VOLATILE_P (condval
[j
]))
3277 if (new_marks
- num_marks
> most_tests
)
3279 most_tests
= new_marks
- num_marks
;
3280 defval
= condval
[i
];
3282 num_marks
= new_marks
;
3284 /* Clear all the marks. */
3285 for (i
= 0; i
< total
; i
++)
3286 MEM_VOLATILE_P (condval
[i
]) = 0;
3288 /* Give up if nothing is constant. */
3292 /* Make a COND with the most common constant value the default. (A more
3293 complex method where tests with the same value were combined didn't
3294 seem to improve things.) */
3295 condexp
= rtx_alloc (COND
);
3296 XVEC (condexp
, 0) = rtvec_alloc ((total
- most_tests
) * 2);
3297 XEXP (condexp
, 1) = defval
;
3298 for (i
= j
= 0; i
< total
; i
++)
3299 if (condval
[i
] != defval
)
3301 XVECEXP (condexp
, 0, 2 * j
) = condtest
[i
];
3302 XVECEXP (condexp
, 0, 2 * j
+ 1) = condval
[i
];
3309 /* Set the MEM_VOLATILE_P flag for all EQ_ATTR expressions in EXP and
3310 verify that EXP can be simplified to a constant term if all the EQ_ATTR
3311 tests have known value. */
3314 find_and_mark_used_attributes (exp
, terms
)
3319 switch (GET_CODE (exp
))
3322 if (! MEM_VOLATILE_P (exp
))
3324 rtx link
= rtx_alloc (EXPR_LIST
);
3325 XEXP (link
, 0) = exp
;
3326 XEXP (link
, 1) = *terms
;
3328 MEM_VOLATILE_P (exp
) = 1;
3334 if (! find_and_mark_used_attributes (XEXP (exp
, 2), terms
))
3338 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
))
3341 if (! find_and_mark_used_attributes (XEXP (exp
, 0), terms
))
3346 for (i
= 0; i
< XVECLEN (exp
, 0); i
++)
3347 if (! find_and_mark_used_attributes (XVECEXP (exp
, 0, i
), terms
))
3349 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
))
3357 /* Clear the MEM_VOLATILE_P flag in all EQ_ATTR expressions on LIST and
3358 in the values of the NDIM-dimensional attribute space SPACE. */
3361 unmark_used_attributes (list
, space
, ndim
)
3363 struct dimension
*space
;
3369 for (i
= 0; i
< ndim
; i
++)
3370 unmark_used_attributes (space
[i
].values
, 0, 0);
3372 for (link
= list
; link
; link
= XEXP (link
, 1))
3374 exp
= XEXP (link
, 0);
3375 if (GET_CODE (exp
) == EQ_ATTR
)
3376 MEM_VOLATILE_P (exp
) = 0;
3380 /* Update the attribute dimension DIM so that all values of the attribute
3381 are tested. Return the updated number of values. */
3384 add_values_to_cover (dim
)
3385 struct dimension
*dim
;
3387 struct attr_value
*av
;
3388 rtx exp
, link
, *prev
;
3391 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3392 if (GET_CODE (av
->value
) == CONST_STRING
)
3395 if (nalt
< dim
->num_values
)
3397 else if (nalt
== dim
->num_values
)
3399 else if (nalt
* 2 < dim
->num_values
* 3)
3401 /* Most all the values of the attribute are used, so add all the unused
3403 prev
= &dim
->values
;
3404 for (link
= dim
->values
; link
; link
= *prev
)
3405 prev
= &XEXP (link
, 1);
3407 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3408 if (GET_CODE (av
->value
) == CONST_STRING
)
3410 exp
= attr_eq (dim
->attr
->name
, XSTR (av
->value
, 0));
3411 if (MEM_VOLATILE_P (exp
))
3414 link
= rtx_alloc (EXPR_LIST
);
3415 XEXP (link
, 0) = exp
;
3418 prev
= &XEXP (link
, 1);
3420 dim
->num_values
= nalt
;
3424 rtx orexp
= false_rtx
;
3426 /* Very few values are used, so compute a mutually exclusive
3427 expression. (We could do this for numeric values if that becomes
3429 prev
= &dim
->values
;
3430 for (link
= dim
->values
; link
; link
= *prev
)
3432 orexp
= insert_right_side (IOR
, orexp
, XEXP (link
, 0), -2);
3433 prev
= &XEXP (link
, 1);
3435 link
= rtx_alloc (EXPR_LIST
);
3436 XEXP (link
, 0) = attr_rtx (NOT
, orexp
);
3441 return dim
->num_values
;
3444 /* Increment the current value for the NDIM-dimensional attribute space SPACE
3445 and return FALSE if the increment overflowed. */
3448 increment_current_value (space
, ndim
)
3449 struct dimension
*space
;
3454 for (i
= ndim
- 1; i
>= 0; i
--)
3456 if ((space
[i
].current_value
= XEXP (space
[i
].current_value
, 1)) == 0)
3457 space
[i
].current_value
= space
[i
].values
;
3464 /* Construct an expression corresponding to the current value for the
3465 NDIM-dimensional attribute space SPACE. */
3468 test_for_current_value (space
, ndim
)
3469 struct dimension
*space
;
3475 for (i
= 0; i
< ndim
; i
++)
3476 exp
= insert_right_side (AND
, exp
, XEXP (space
[i
].current_value
, 0), -2);
3481 /* Given the current value of the NDIM-dimensional attribute space SPACE,
3482 set the corresponding EQ_ATTR expressions to that value and reduce
3483 the expression EXP as much as possible. On input [and output], all
3484 known EQ_ATTR expressions are set to FALSE. */
3487 simplify_with_current_value (exp
, space
, ndim
)
3489 struct dimension
*space
;
3495 /* Mark each current value as TRUE. */
3496 for (i
= 0; i
< ndim
; i
++)
3498 x
= XEXP (space
[i
].current_value
, 0);
3499 if (GET_CODE (x
) == EQ_ATTR
)
3500 MEM_VOLATILE_P (x
) = 0;
3503 exp
= simplify_with_current_value_aux (exp
);
3505 /* Change each current value back to FALSE. */
3506 for (i
= 0; i
< ndim
; i
++)
3508 x
= XEXP (space
[i
].current_value
, 0);
3509 if (GET_CODE (x
) == EQ_ATTR
)
3510 MEM_VOLATILE_P (x
) = 1;
3516 /* Reduce the expression EXP based on the MEM_VOLATILE_P settings of
3517 all EQ_ATTR expressions. */
3520 simplify_with_current_value_aux (exp
)
3526 switch (GET_CODE (exp
))
3529 if (MEM_VOLATILE_P (exp
))
3537 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
3538 if (cond
== true_rtx
)
3539 return simplify_with_current_value_aux (XEXP (exp
, 1));
3540 else if (cond
== false_rtx
)
3541 return simplify_with_current_value_aux (XEXP (exp
, 2));
3543 return attr_rtx (IF_THEN_ELSE
, cond
,
3544 simplify_with_current_value_aux (XEXP (exp
, 1)),
3545 simplify_with_current_value_aux (XEXP (exp
, 2)));
3548 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
3549 if (cond
== true_rtx
)
3551 else if (cond
== false_rtx
)
3552 return simplify_with_current_value_aux (XEXP (exp
, 0));
3554 return attr_rtx (IOR
, cond
,
3555 simplify_with_current_value_aux (XEXP (exp
, 0)));
3558 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
3559 if (cond
== true_rtx
)
3560 return simplify_with_current_value_aux (XEXP (exp
, 0));
3561 else if (cond
== false_rtx
)
3564 return attr_rtx (AND
, cond
,
3565 simplify_with_current_value_aux (XEXP (exp
, 0)));
3568 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
3569 if (cond
== true_rtx
)
3571 else if (cond
== false_rtx
)
3574 return attr_rtx (NOT
, cond
);
3577 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3579 cond
= simplify_with_current_value_aux (XVECEXP (exp
, 0, i
));
3580 if (cond
== true_rtx
)
3581 return simplify_with_current_value_aux (XVECEXP (exp
, 0, i
+ 1));
3582 else if (cond
== false_rtx
)
3585 abort (); /* With all EQ_ATTR's of known value, a case should
3586 have been selected. */
3588 return simplify_with_current_value_aux (XEXP (exp
, 1));
3593 /* Clear the MEM_IN_STRUCT_P flag in EXP and its subexpressions. */
3595 clear_struct_flag (x
)
3600 register enum rtx_code code
;
3603 MEM_IN_STRUCT_P (x
) = 0;
3604 if (RTX_UNCHANGING_P (x
))
3607 code
= GET_CODE (x
);
3623 /* Compare the elements. If any pair of corresponding elements
3624 fail to match, return 0 for the whole things. */
3626 fmt
= GET_RTX_FORMAT (code
);
3627 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3633 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3634 clear_struct_flag (XVECEXP (x
, i
, j
));
3638 clear_struct_flag (XEXP (x
, i
));
3644 /* Return the number of RTX objects making up the expression X.
3645 But if we count more more than MAX objects, stop counting. */
3647 count_sub_rtxs (x
, max
)
3653 register enum rtx_code code
;
3657 code
= GET_CODE (x
);
3673 /* Compare the elements. If any pair of corresponding elements
3674 fail to match, return 0 for the whole things. */
3676 fmt
= GET_RTX_FORMAT (code
);
3677 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3686 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3687 total
+= count_sub_rtxs (XVECEXP (x
, i
, j
), max
);
3691 total
+= count_sub_rtxs (XEXP (x
, i
), max
);
3699 /* Create table entries for DEFINE_ATTR. */
3705 struct attr_desc
*attr
;
3706 struct attr_value
*av
;
3710 /* Make a new attribute structure. Check for duplicate by looking at
3711 attr->default_val, since it is initialized by this routine. */
3712 attr
= find_attr (XSTR (exp
, 0), 1);
3713 if (attr
->default_val
)
3714 fatal ("Duplicate definition for `%s' attribute", attr
->name
);
3716 if (*XSTR (exp
, 1) == '\0')
3717 attr
->is_numeric
= 1;
3720 name_ptr
= XSTR (exp
, 1);
3721 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
3723 av
= (struct attr_value
*) xmalloc (sizeof (struct attr_value
));
3724 av
->value
= attr_rtx (CONST_STRING
, p
);
3725 av
->next
= attr
->first_value
;
3726 attr
->first_value
= av
;
3727 av
->first_insn
= NULL
;
3729 av
->has_asm_insn
= 0;
3733 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
3736 if (attr
->is_numeric
)
3737 fatal ("Constant attributes may not take numeric values");
3738 /* Get rid of the CONST node. It is allowed only at top-level. */
3739 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
3742 if (! strcmp (attr
->name
, "length") && ! attr
->is_numeric
)
3743 fatal ("`length' attribute must take numeric values");
3745 /* Set up the default value. */
3746 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
3747 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
3750 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
3751 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
3752 number of alternatives as this should be checked elsewhere. */
3755 count_alternatives (exp
)
3761 if (GET_CODE (exp
) == MATCH_OPERAND
)
3762 return n_comma_elts (XSTR (exp
, 2));
3764 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3765 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3770 n
= count_alternatives (XEXP (exp
, i
));
3777 if (XVEC (exp
, i
) != NULL
)
3778 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3780 n
= count_alternatives (XVECEXP (exp
, i
, j
));
3789 /* Returns non-zero if the given expression contains an EQ_ATTR with the
3790 `alternative' attribute. */
3793 compares_alternatives_p (exp
)
3799 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
3802 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3803 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3808 if (compares_alternatives_p (XEXP (exp
, i
)))
3813 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3814 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
3822 /* Returns non-zero is INNER is contained in EXP. */
3825 contained_in_p (inner
, exp
)
3832 if (rtx_equal_p (inner
, exp
))
3835 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3836 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3841 if (contained_in_p (inner
, XEXP (exp
, i
)))
3846 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3847 if (contained_in_p (inner
, XVECEXP (exp
, i
, j
)))
3855 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
3861 struct insn_def
*id
;
3863 id
= (struct insn_def
*) xmalloc (sizeof (struct insn_def
));
3868 switch (GET_CODE (exp
))
3871 id
->insn_code
= insn_code_number
++;
3872 id
->insn_index
= insn_index_number
++;
3873 id
->num_alternatives
= count_alternatives (exp
);
3874 if (id
->num_alternatives
== 0)
3875 id
->num_alternatives
= 1;
3879 case DEFINE_PEEPHOLE
:
3880 id
->insn_code
= insn_code_number
++;
3881 id
->insn_index
= insn_index_number
++;
3882 id
->num_alternatives
= count_alternatives (exp
);
3883 if (id
->num_alternatives
== 0)
3884 id
->num_alternatives
= 1;
3888 case DEFINE_ASM_ATTRIBUTES
:
3890 id
->insn_index
= -1;
3891 id
->num_alternatives
= 1;
3893 got_define_asm_attributes
= 1;
3898 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
3899 true or annul false is specified, and make a `struct delay_desc'. */
3905 struct delay_desc
*delay
;
3908 if (XVECLEN (def
, 1) % 3 != 0)
3909 fatal ("Number of elements in DEFINE_DELAY must be multiple of three.");
3911 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
3913 if (XVECEXP (def
, 1, i
+ 1))
3914 have_annul_true
= 1;
3915 if (XVECEXP (def
, 1, i
+ 2))
3916 have_annul_false
= 1;
3919 delay
= (struct delay_desc
*) xmalloc (sizeof (struct delay_desc
));
3921 delay
->num
= ++num_delays
;
3922 delay
->next
= delays
;
3926 /* Process a DEFINE_FUNCTION_UNIT.
3928 This gives information about a function unit contained in the CPU.
3929 We fill in a `struct function_unit_op' and a `struct function_unit'
3930 with information used later by `expand_unit'. */
3936 struct function_unit
*unit
;
3937 struct function_unit_op
*op
;
3939 /* See if we have already seen this function unit. If so, check that
3940 the multiplicity and simultaneity values are the same. If not, make
3941 a structure for this function unit. */
3942 for (unit
= units
; unit
; unit
= unit
->next
)
3943 if (! strcmp (unit
->name
, XSTR (def
, 0)))
3945 if (unit
->multiplicity
!= XINT (def
, 1)
3946 || unit
->simultaneity
!= XINT (def
, 2))
3947 fatal ("Differing specifications given for `%s' function unit.",
3954 unit
= (struct function_unit
*) xmalloc (sizeof (struct function_unit
));
3955 unit
->name
= XSTR (def
, 0);
3956 unit
->multiplicity
= XINT (def
, 1);
3957 unit
->simultaneity
= XINT (def
, 2);
3958 unit
->num
= num_units
++;
3959 unit
->num_opclasses
= 0;
3960 unit
->condexp
= false_rtx
;
3963 unit
->min_busy_delay
= unit
->max_busy_delay
= XINT (def
, 5);
3967 /* Make a new operation class structure entry and initialize it. */
3968 op
= (struct function_unit_op
*) xmalloc (sizeof (struct function_unit_op
));
3969 op
->condexp
= XEXP (def
, 3);
3970 op
->num
= unit
->num_opclasses
++;
3971 op
->ready
= XINT (def
, 4);
3972 op
->next
= unit
->ops
;
3975 /* Set our busy expression based on whether or not an optional conflict
3976 vector was specified. */
3979 /* Compute the IOR of all the specified expressions. */
3980 rtx orexp
= false_rtx
;
3983 for (i
= 0; i
< XVECLEN (def
, 6); i
++)
3984 orexp
= insert_right_side (IOR
, orexp
, XVECEXP (def
, 6, i
), -2);
3986 op
->busyexp
= attr_rtx (IF_THEN_ELSE
, orexp
,
3987 make_numeric_value (XINT (def
, 5)),
3988 make_numeric_value (0));
3989 unit
->min_busy_delay
= MIN (unit
->min_busy_delay
, 0);
3990 unit
->max_busy_delay
= MAX (unit
->max_busy_delay
, XINT (def
, 5));
3994 op
->busyexp
= make_numeric_value (XINT (def
, 5));
3995 unit
->min_busy_delay
= MIN (unit
->min_busy_delay
, XINT (def
, 5));
3996 unit
->max_busy_delay
= MAX (unit
->max_busy_delay
, XINT (def
, 5));
3999 /* Merge our conditional into that of the function unit so we can determine
4000 which insns are used by the function unit. */
4001 unit
->condexp
= insert_right_side (IOR
, unit
->condexp
, op
->condexp
, -2);
4004 /* Given a piece of RTX, print a C expression to test it's truth value.
4005 We use AND and IOR both for logical and bit-wise operations, so
4006 interpret them as logical unless they are inside a comparison expression.
4007 The second operand of this function will be non-zero in that case. */
4010 write_test_expr (exp
, in_comparison
)
4014 int comparison_operator
= 0;
4016 struct attr_desc
*attr
;
4018 /* In order not to worry about operator precedence, surround our part of
4019 the expression with parentheses. */
4022 code
= GET_CODE (exp
);
4025 /* Binary operators. */
4027 case GE
: case GT
: case GEU
: case GTU
:
4028 case LE
: case LT
: case LEU
: case LTU
:
4029 comparison_operator
= 1;
4031 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
4032 case AND
: case IOR
: case XOR
:
4033 case LSHIFT
: case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
4034 write_test_expr (XEXP (exp
, 0), in_comparison
|| comparison_operator
);
4050 printf (" >= (unsigned) ");
4053 printf (" > (unsigned) ");
4062 printf (" <= (unsigned) ");
4065 printf (" < (unsigned) ");
4107 write_test_expr (XEXP (exp
, 1), in_comparison
|| comparison_operator
);
4111 /* Special-case (not (eq_attrq "alternative" "x")) */
4112 if (! in_comparison
&& GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
4113 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
4115 printf ("which_alternative != %s", XSTR (XEXP (exp
, 0), 1));
4119 /* Otherwise, fall through to normal unary operator. */
4121 /* Unary operators. */
4139 write_test_expr (XEXP (exp
, 0), in_comparison
);
4142 /* Comparison test of an attribute with a value. Most of these will
4143 have been removed by optimization. Handle "alternative"
4144 specially and give error if EQ_ATTR present inside a comparison. */
4147 fatal ("EQ_ATTR not valid inside comparison");
4149 if (XSTR (exp
, 0) == alternative_name
)
4151 printf ("which_alternative == %s", XSTR (exp
, 1));
4155 attr
= find_attr (XSTR (exp
, 0), 0);
4156 if (! attr
) abort ();
4158 /* Now is the time to expand the value of a constant attribute. */
4161 write_test_expr (evaluate_eq_attr (exp
, attr
->default_val
->value
,
4167 printf ("get_attr_%s (insn) == ", attr
->name
);
4168 write_attr_valueq (attr
, XSTR (exp
, 1));
4172 /* See if an operand matches a predicate. */
4174 /* If only a mode is given, just ensure the mode matches the operand.
4175 If neither a mode nor predicate is given, error. */
4176 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
4178 if (GET_MODE (exp
) == VOIDmode
)
4179 fatal ("Null MATCH_OPERAND specified as test");
4181 printf ("GET_MODE (operands[%d]) == %smode",
4182 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4185 printf ("%s (operands[%d], %smode)",
4186 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4189 /* Constant integer. */
4191 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
4192 printf ("%d", XWINT (exp
, 0));
4194 printf ("%ld", XWINT (exp
, 0));
4198 /* A random C expression. */
4200 printf ("%s", XSTR (exp
, 0));
4203 /* The address of the branch target. */
4205 printf ("insn_addresses[INSN_UID (JUMP_LABEL (insn))]");
4208 /* The address of the current insn. It would be more consistent with
4209 other usage to make this the address of the NEXT insn, but this gets
4210 too confusing because of the ambiguity regarding the length of the
4213 printf ("insn_current_address");
4217 fatal ("bad RTX code `%s' in attribute calculation\n",
4218 GET_RTX_NAME (code
));
4224 /* Given an attribute value, return the maximum CONST_STRING argument
4225 encountered. It is assumed that they are all numeric. */
4228 max_attr_value (exp
)
4231 int current_max
= 0;
4235 if (GET_CODE (exp
) == CONST_STRING
)
4236 return atoi (XSTR (exp
, 0));
4238 else if (GET_CODE (exp
) == COND
)
4240 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4242 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1));
4243 if (n
> current_max
)
4247 n
= max_attr_value (XEXP (exp
, 1));
4248 if (n
> current_max
)
4258 /* Scan an attribute value, possibly a conditional, and record what actions
4259 will be required to do any conditional tests in it.
4262 `must_extract' if we need to extract the insn operands
4263 `must_constrain' if we must compute `which_alternative'
4264 `address_used' if an address expression was used
4268 walk_attr_value (exp
)
4278 code
= GET_CODE (exp
);
4282 if (! RTX_UNCHANGING_P (exp
))
4283 /* Since this is an arbitrary expression, it can look at anything.
4284 However, constant expressions do not depend on any particular
4286 must_extract
= must_constrain
= 1;
4294 if (XSTR (exp
, 0) == alternative_name
)
4295 must_extract
= must_constrain
= 1;
4304 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
4309 walk_attr_value (XEXP (exp
, i
));
4313 if (XVEC (exp
, i
) != NULL
)
4314 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4315 walk_attr_value (XVECEXP (exp
, i
, j
));
4320 /* Write out a function to obtain the attribute for a given INSN. */
4323 write_attr_get (attr
)
4324 struct attr_desc
*attr
;
4326 struct attr_value
*av
, *common_av
;
4328 /* Find the most used attribute value. Handle that as the `default' of the
4329 switch we will generate. */
4330 common_av
= find_most_used (attr
);
4332 /* Write out start of function, then all values with explicit `case' lines,
4333 then a `default', then the value with the most uses. */
4334 if (attr
->is_numeric
)
4337 printf ("enum attr_%s\n", attr
->name
);
4339 /* If the attribute name starts with a star, the remainder is the name of
4340 the subroutine to use, instead of `get_attr_...'. */
4341 if (attr
->name
[0] == '*')
4342 printf ("%s (insn)\n", &attr
->name
[1]);
4343 else if (attr
->is_const
== 0)
4344 printf ("get_attr_%s (insn)\n", attr
->name
);
4347 printf ("get_attr_%s ()\n", attr
->name
);
4350 for (av
= attr
->first_value
; av
; av
= av
->next
)
4351 if (av
->num_insns
!= 0)
4352 write_attr_set (attr
, 2, av
->value
, "return", ";",
4353 true_rtx
, av
->first_insn
->insn_code
,
4354 av
->first_insn
->insn_index
);
4359 printf (" rtx insn;\n");
4361 printf (" switch (recog_memoized (insn))\n");
4364 for (av
= attr
->first_value
; av
; av
= av
->next
)
4365 if (av
!= common_av
)
4366 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
4368 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4369 printf (" }\n}\n\n");
4372 /* Given an AND tree of known true terms (because we are inside an `if' with
4373 that as the condition or are in an `else' clause) and an expression,
4374 replace any known true terms with TRUE. Use `simplify_and_tree' to do
4375 the bulk of the work. */
4378 eliminate_known_true (known_true
, exp
, insn_code
, insn_index
)
4381 int insn_code
, insn_index
;
4385 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
4387 if (GET_CODE (known_true
) == AND
)
4389 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
4390 insn_code
, insn_index
);
4391 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
4392 insn_code
, insn_index
);
4397 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
4403 /* Write out a series of tests and assignment statements to perform tests and
4404 sets of an attribute value. We are passed an indentation amount and prefix
4405 and suffix strings to write around each attribute value (e.g., "return"
4409 write_attr_set (attr
, indent
, value
, prefix
, suffix
, known_true
,
4410 insn_code
, insn_index
)
4411 struct attr_desc
*attr
;
4417 int insn_code
, insn_index
;
4419 if (GET_CODE (value
) == CONST_STRING
)
4421 write_indent (indent
);
4422 printf ("%s ", prefix
);
4423 write_attr_value (attr
, value
);
4424 printf ("%s\n", suffix
);
4426 else if (GET_CODE (value
) == COND
)
4428 /* Assume the default value will be the default of the COND unless we
4429 find an always true expression. */
4430 rtx default_val
= XEXP (value
, 1);
4431 rtx our_known_true
= known_true
;
4436 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4441 testexp
= eliminate_known_true (our_known_true
,
4442 XVECEXP (value
, 0, i
),
4443 insn_code
, insn_index
);
4444 newexp
= attr_rtx (NOT
, testexp
);
4445 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
4446 insn_code
, insn_index
);
4448 /* If the test expression is always true or if the next `known_true'
4449 expression is always false, this is the last case, so break
4450 out and let this value be the `else' case. */
4451 if (testexp
== true_rtx
|| newexp
== false_rtx
)
4453 default_val
= XVECEXP (value
, 0, i
+ 1);
4457 /* Compute the expression to pass to our recursive call as being
4459 inner_true
= insert_right_side (AND
, our_known_true
,
4460 testexp
, insn_code
, insn_index
);
4462 /* If this is always false, skip it. */
4463 if (inner_true
== false_rtx
)
4466 write_indent (indent
);
4467 printf ("%sif ", first_if
? "" : "else ");
4469 write_test_expr (testexp
, 0);
4471 write_indent (indent
+ 2);
4474 write_attr_set (attr
, indent
+ 4,
4475 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
4476 inner_true
, insn_code
, insn_index
);
4477 write_indent (indent
+ 2);
4479 our_known_true
= newexp
;
4484 write_indent (indent
);
4486 write_indent (indent
+ 2);
4490 write_attr_set (attr
, first_if
? indent
: indent
+ 4, default_val
,
4491 prefix
, suffix
, our_known_true
, insn_code
, insn_index
);
4495 write_indent (indent
+ 2);
4503 /* Write out the computation for one attribute value. */
4506 write_attr_case (attr
, av
, write_case_lines
, prefix
, suffix
, indent
, known_true
)
4507 struct attr_desc
*attr
;
4508 struct attr_value
*av
;
4509 int write_case_lines
;
4510 char *prefix
, *suffix
;
4514 struct insn_ent
*ie
;
4516 if (av
->num_insns
== 0)
4519 if (av
->has_asm_insn
)
4521 write_indent (indent
);
4522 printf ("case -1:\n");
4523 write_indent (indent
+ 2);
4524 printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
4525 write_indent (indent
+ 2);
4526 printf (" && asm_noperands (PATTERN (insn)) < 0)\n");
4527 write_indent (indent
+ 2);
4528 printf (" fatal_insn_not_found (insn);\n");
4531 if (write_case_lines
)
4533 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
4534 if (ie
->insn_code
!= -1)
4536 write_indent (indent
);
4537 printf ("case %d:\n", ie
->insn_code
);
4542 write_indent (indent
);
4543 printf ("default:\n");
4546 /* See what we have to do to handle output this value. */
4547 must_extract
= must_constrain
= address_used
= 0;
4548 walk_attr_value (av
->value
);
4552 write_indent (indent
+ 2);
4553 printf ("insn_extract (insn);\n");
4558 #ifdef REGISTER_CONSTRAINTS
4559 write_indent (indent
+ 2);
4560 printf ("if (! constrain_operands (INSN_CODE (insn), reload_completed))\n");
4561 write_indent (indent
+ 2);
4562 printf (" fatal_insn_not_found (insn);\n");
4566 write_attr_set (attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4567 known_true
, av
->first_insn
->insn_code
,
4568 av
->first_insn
->insn_index
);
4570 if (strncmp (prefix
, "return", 6))
4572 write_indent (indent
+ 2);
4573 printf ("break;\n");
4578 /* Utilities to write names in various forms. */
4581 write_attr_valueq (attr
, s
)
4582 struct attr_desc
*attr
;
4585 if (attr
->is_numeric
)
4589 write_upcase (attr
->name
);
4596 write_attr_value (attr
, value
)
4597 struct attr_desc
*attr
;
4600 if (GET_CODE (value
) != CONST_STRING
)
4603 write_attr_valueq (attr
, XSTR (value
, 0));
4611 if (*str
< 'a' || *str
> 'z')
4612 printf ("%c", *str
++);
4614 printf ("%c", *str
++ - 'a' + 'A');
4618 write_indent (indent
)
4621 for (; indent
> 8; indent
-= 8)
4624 for (; indent
; indent
--)
4628 /* Write a subroutine that is given an insn that requires a delay slot, a
4629 delay slot ordinal, and a candidate insn. It returns non-zero if the
4630 candidate can be placed in the specified delay slot of the insn.
4632 We can write as many as three subroutines. `eligible_for_delay'
4633 handles normal delay slots, `eligible_for_annul_true' indicates that
4634 the specified insn can be annulled if the branch is true, and likewise
4635 for `eligible_for_annul_false'.
4637 KIND is a string distinguishing these three cases ("delay", "annul_true",
4638 or "annul_false"). */
4641 write_eligible_delay (kind
)
4644 struct delay_desc
*delay
;
4647 struct attr_desc
*attr
;
4648 struct attr_value
*av
, *common_av
;
4651 /* Compute the maximum number of delay slots required. We use the delay
4652 ordinal times this number plus one, plus the slot number as an index into
4653 the appropriate predicate to test. */
4655 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
4656 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
4657 max_slots
= XVECLEN (delay
->def
, 1) / 3;
4659 /* Write function prelude. */
4662 printf ("eligible_for_%s (delay_insn, slot, candidate_insn)\n", kind
);
4663 printf (" rtx delay_insn;\n");
4664 printf (" int slot;\n");
4665 printf (" rtx candidate_insn;\n");
4667 printf (" rtx insn;\n");
4669 printf (" if (slot >= %d)\n", max_slots
);
4670 printf (" abort ();\n");
4673 /* If more than one delay type, find out which type the delay insn is. */
4677 attr
= find_attr ("*delay_type", 0);
4678 if (! attr
) abort ();
4679 common_av
= find_most_used (attr
);
4681 printf (" insn = delay_insn;\n");
4682 printf (" switch (recog_memoized (insn))\n");
4685 sprintf (str
, " * %d;\n break;", max_slots
);
4686 for (av
= attr
->first_value
; av
; av
= av
->next
)
4687 if (av
!= common_av
)
4688 write_attr_case (attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
4690 write_attr_case (attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
4693 /* Ensure matched. Otherwise, shouldn't have been called. */
4694 printf (" if (slot < %d)\n", max_slots
);
4695 printf (" abort ();\n\n");
4698 /* If just one type of delay slot, write simple switch. */
4699 if (num_delays
== 1 && max_slots
== 1)
4701 printf (" insn = candidate_insn;\n");
4702 printf (" switch (recog_memoized (insn))\n");
4705 attr
= find_attr ("*delay_1_0", 0);
4706 if (! attr
) abort ();
4707 common_av
= find_most_used (attr
);
4709 for (av
= attr
->first_value
; av
; av
= av
->next
)
4710 if (av
!= common_av
)
4711 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
4713 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4719 /* Write a nested CASE. The first indicates which condition we need to
4720 test, and the inner CASE tests the condition. */
4721 printf (" insn = candidate_insn;\n");
4722 printf (" switch (slot)\n");
4725 for (delay
= delays
; delay
; delay
= delay
->next
)
4726 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
4728 printf (" case %d:\n",
4729 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
4730 printf (" switch (recog_memoized (insn))\n");
4733 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
4734 attr
= find_attr (str
, 0);
4735 if (! attr
) abort ();
4736 common_av
= find_most_used (attr
);
4738 for (av
= attr
->first_value
; av
; av
= av
->next
)
4739 if (av
!= common_av
)
4740 write_attr_case (attr
, av
, 1, "return", ";", 8, true_rtx
);
4742 write_attr_case (attr
, common_av
, 0, "return", ";", 8, true_rtx
);
4746 printf (" default:\n");
4747 printf (" abort ();\n");
4754 /* Write routines to compute conflict cost for function units. Then write a
4755 table describing the available function units. */
4758 write_function_unit_info ()
4760 struct function_unit
*unit
;
4761 struct attr_desc
*case_attr
, *attr
;
4762 struct attr_value
*av
, *common_av
;
4768 /* Write out conflict routines for function units. Don't bother writing
4769 one if there is only one busy value. */
4771 for (unit
= units
; unit
; unit
= unit
->next
)
4773 /* Record the maximum busy cost. */
4774 unit
->max_busy_cost
= make_numeric_value (unit
->max_busy_delay
);
4776 /* If the minimum and maximum conflict costs are the same, there
4777 is only one value, so we don't need a function. */
4778 if (unit
->min_busy_delay
== unit
->max_busy_delay
)
4780 unit
->needs_conflict_function
= 0;
4781 unit
->default_cost
= unit
->max_busy_cost
;
4785 /* The function first computes the case from the candidate insn. */
4786 unit
->needs_conflict_function
= 1;
4787 unit
->default_cost
= make_numeric_value (0);
4789 printf ("static int\n");
4790 printf ("%s_unit_conflict_cost (executing_insn, candidate_insn)\n",
4792 printf (" rtx executing_insn;\n");
4793 printf (" rtx candidate_insn;\n");
4795 printf (" rtx insn;\n");
4796 printf (" int casenum;\n\n");
4797 printf (" insn = candidate_insn;\n");
4798 printf (" switch (recog_memoized (insn))\n");
4801 /* Write the `switch' statement to get the case value. */
4802 str
= (char *) alloca (strlen (unit
->name
) + 10);
4803 sprintf (str
, "*%s_cases", unit
->name
);
4804 case_attr
= find_attr (str
, 0);
4805 if (! case_attr
) abort ();
4806 common_av
= find_most_used (case_attr
);
4808 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
4809 if (av
!= common_av
)
4810 write_attr_case (case_attr
, av
, 1,
4811 "casenum =", ";", 4, unit
->condexp
);
4813 write_attr_case (case_attr
, common_av
, 0,
4814 "casenum =", ";", 4, unit
->condexp
);
4817 /* Now write an outer switch statement on each case. Then write
4818 the tests on the executing function within each. */
4819 printf (" insn = executing_insn;\n");
4820 printf (" switch (casenum)\n");
4823 for (i
= 0; i
< unit
->num_opclasses
; i
++)
4825 /* Ensure using this case. */
4827 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
4829 && contained_in_p (make_numeric_value (i
), av
->value
))
4835 printf (" case %d:\n", i
);
4836 sprintf (str
, "*%s_case_%d", unit
->name
, i
);
4837 attr
= find_attr (str
, 0);
4838 if (! attr
) abort ();
4840 /* If single value, just write it. */
4841 value
= find_single_value (attr
);
4843 write_attr_set (attr
, 6, value
, "return", ";\n", true_rtx
, -2);
4846 common_av
= find_most_used (attr
);
4847 printf (" switch (recog_memoized (insn))\n");
4850 for (av
= attr
->first_value
; av
; av
= av
->next
)
4851 if (av
!= common_av
)
4852 write_attr_case (attr
, av
, 1,
4853 "return", ";", 8, unit
->condexp
);
4855 write_attr_case (attr
, common_av
, 0,
4856 "return", ";", 8, unit
->condexp
);
4861 printf (" }\n}\n\n");
4864 /* Now that all functions have been written, write the table describing
4865 the function units. The name is included for documentation purposes
4868 printf ("struct function_unit_desc function_units[] = {\n");
4870 /* Write out the descriptions in numeric order, but don't force that order
4871 on the list. Doing so increases the runtime of genattrtab.c. */
4872 for (i
= 0; i
< num_units
; i
++)
4874 for (unit
= units
; unit
; unit
= unit
->next
)
4878 printf (" {\"%s\", %d, %d, %d, %s, %s, %s_unit_ready_cost, ",
4879 unit
->name
, 1 << unit
->num
, unit
->multiplicity
,
4880 unit
->simultaneity
, XSTR (unit
->default_cost
, 0),
4881 XSTR (unit
->max_busy_cost
, 0), unit
->name
);
4883 if (unit
->needs_conflict_function
)
4884 printf ("%s_unit_conflict_cost", unit
->name
);
4894 /* This page contains miscellaneous utility routines. */
4896 /* Given a string, return the number of comma-separated elements in it.
4897 Return 0 for the null string. */
4908 for (n
= 1; *s
; s
++)
4915 /* Given a pointer to a (char *), return a malloc'ed string containing the
4916 next comma-separated element. Advance the pointer to after the string
4917 scanned, or the end-of-string. Return NULL if at end of string. */
4920 next_comma_elt (pstr
)
4929 /* Find end of string to compute length. */
4930 for (p
= *pstr
; *p
!= ',' && *p
!= '\0'; p
++)
4933 out_str
= attr_string (*pstr
, p
- *pstr
);
4942 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
4943 is non-zero, build a new attribute, if one does not exist. */
4945 static struct attr_desc
*
4946 find_attr (name
, create
)
4950 struct attr_desc
*attr
;
4953 /* Before we resort to using `strcmp', see if the string address matches
4954 anywhere. In most cases, it should have been canonicalized to do so. */
4955 if (name
== alternative_name
)
4958 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
4959 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4960 if (name
== attr
->name
)
4963 /* Otherwise, do it the slow way. */
4964 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4965 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
4971 attr
= (struct attr_desc
*) xmalloc (sizeof (struct attr_desc
));
4972 attr
->name
= attr_string (name
, strlen (name
));
4973 attr
->first_value
= attr
->default_val
= NULL
;
4974 attr
->is_numeric
= attr
->negative_ok
= attr
->is_const
= attr
->is_special
= 0;
4975 attr
->next
= attrs
[index
];
4976 attrs
[index
] = attr
;
4981 /* Create internal attribute with the given default value. */
4984 make_internal_attr (name
, value
, special
)
4989 struct attr_desc
*attr
;
4991 attr
= find_attr (name
, 1);
4992 if (attr
->default_val
)
4995 attr
->is_numeric
= 1;
4997 attr
->is_special
= (special
& 1) != 0;
4998 attr
->negative_ok
= (special
& 2) != 0;
4999 attr
->default_val
= get_attr_value (value
, attr
, -2);
5002 /* Find the most used value of an attribute. */
5004 static struct attr_value
*
5005 find_most_used (attr
)
5006 struct attr_desc
*attr
;
5008 struct attr_value
*av
;
5009 struct attr_value
*most_used
;
5015 for (av
= attr
->first_value
; av
; av
= av
->next
)
5016 if (av
->num_insns
> nuses
)
5017 nuses
= av
->num_insns
, most_used
= av
;
5022 /* If an attribute only has a single value used, return it. Otherwise
5026 find_single_value (attr
)
5027 struct attr_desc
*attr
;
5029 struct attr_value
*av
;
5032 unique_value
= NULL
;
5033 for (av
= attr
->first_value
; av
; av
= av
->next
)
5039 unique_value
= av
->value
;
5042 return unique_value
;
5045 /* Return (attr_value "n") */
5048 make_numeric_value (n
)
5051 static rtx int_values
[20];
5058 if (n
< 20 && int_values
[n
])
5059 return int_values
[n
];
5061 p
= attr_printf ((n
< 1000 ? 4 : HOST_BITS_PER_INT
* 3 / 10 + 3), "%d", n
);
5062 exp
= attr_rtx (CONST_STRING
, p
);
5065 int_values
[n
] = exp
;
5071 xrealloc (ptr
, size
)
5075 char *result
= (char *) realloc (ptr
, size
);
5077 fatal ("virtual memory exhausted");
5085 register char *val
= (char *) malloc (size
);
5088 fatal ("virtual memory exhausted");
5093 copy_rtx_unchanging (orig
)
5098 register RTX_CODE code
;
5101 if (RTX_UNCHANGING_P (orig
) || MEM_IN_STRUCT_P (orig
))
5104 MEM_IN_STRUCT_P (orig
) = 1;
5108 code
= GET_CODE (orig
);
5118 copy
= rtx_alloc (code
);
5119 PUT_MODE (copy
, GET_MODE (orig
));
5120 RTX_UNCHANGING_P (copy
) = 1;
5122 bcopy (&XEXP (orig
, 0), &XEXP (copy
, 0),
5123 GET_RTX_LENGTH (GET_CODE (copy
)) * sizeof (rtx
));
5132 fprintf (stderr
, "genattrtab: ");
5133 fprintf (stderr
, s
, a1
, a2
);
5134 fprintf (stderr
, "\n");
5135 exit (FATAL_EXIT_CODE
);
5138 /* More 'friendly' abort that prints the line and file.
5139 config.h can #define abort fancy_abort if you like that sort of thing. */
5144 fatal ("Internal gcc abort.");
5155 struct attr_desc
*attr
;
5156 struct insn_def
*id
;
5160 obstack_init (rtl_obstack
);
5161 obstack_init (hash_obstack
);
5162 obstack_init (temp_obstack
);
5165 fatal ("No input file name.");
5167 infile
= fopen (argv
[1], "r");
5171 exit (FATAL_EXIT_CODE
);
5176 /* Set up true and false rtx's */
5177 true_rtx
= rtx_alloc (CONST_INT
);
5178 XWINT (true_rtx
, 0) = 1;
5179 false_rtx
= rtx_alloc (CONST_INT
);
5180 XWINT (false_rtx
, 0) = 0;
5181 RTX_UNCHANGING_P (true_rtx
) = RTX_UNCHANGING_P (false_rtx
) = 1;
5182 RTX_INTEGRATED_P (true_rtx
) = RTX_INTEGRATED_P (false_rtx
) = 1;
5184 alternative_name
= attr_string ("alternative", strlen ("alternative"));
5186 printf ("/* Generated automatically by the program `genattrtab'\n\
5187 from the machine description file `md'. */\n\n");
5189 /* Read the machine description. */
5193 c
= read_skip_spaces (infile
);
5198 desc
= read_rtx (infile
);
5199 if (GET_CODE (desc
) == DEFINE_INSN
5200 || GET_CODE (desc
) == DEFINE_PEEPHOLE
5201 || GET_CODE (desc
) == DEFINE_ASM_ATTRIBUTES
)
5204 else if (GET_CODE (desc
) == DEFINE_EXPAND
)
5205 insn_code_number
++, insn_index_number
++;
5207 else if (GET_CODE (desc
) == DEFINE_SPLIT
)
5208 insn_code_number
++, insn_index_number
++;
5210 else if (GET_CODE (desc
) == DEFINE_ATTR
)
5213 insn_index_number
++;
5216 else if (GET_CODE (desc
) == DEFINE_DELAY
)
5219 insn_index_number
++;
5222 else if (GET_CODE (desc
) == DEFINE_FUNCTION_UNIT
)
5225 insn_index_number
++;
5229 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
5230 if (! got_define_asm_attributes
)
5232 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
5233 XVEC (tem
, 0) = rtvec_alloc (0);
5237 /* Expand DEFINE_DELAY information into new attribute. */
5241 /* Expand DEFINE_FUNCTION_UNIT information into new attributes. */
5245 printf ("#include \"config.h\"\n");
5246 printf ("#include \"rtl.h\"\n");
5247 printf ("#include \"insn-config.h\"\n");
5248 printf ("#include \"recog.h\"\n");
5249 printf ("#include \"regs.h\"\n");
5250 printf ("#include \"real.h\"\n");
5251 printf ("#include \"output.h\"\n");
5252 printf ("#include \"insn-attr.h\"\n");
5254 printf ("#define operands recog_operand\n\n");
5256 /* Make `insn_alternatives'. */
5257 insn_alternatives
= (int *) xmalloc (insn_code_number
* sizeof (int));
5258 for (id
= defs
; id
; id
= id
->next
)
5259 if (id
->insn_code
>= 0)
5260 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
5262 /* Make `insn_n_alternatives'. */
5263 insn_n_alternatives
= (int *) xmalloc (insn_code_number
* sizeof (int));
5264 for (id
= defs
; id
; id
= id
->next
)
5265 if (id
->insn_code
>= 0)
5266 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
5268 /* Prepare to write out attribute subroutines by checking everything stored
5269 away and building the attribute cases. */
5272 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5273 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5275 attr
->default_val
->value
5276 = check_attr_value (attr
->default_val
->value
, attr
);
5280 /* Construct extra attributes for `length'. */
5281 make_length_attrs ();
5283 /* Perform any possible optimizations to speed up compilation. */
5286 /* Now write out all the `gen_attr_...' routines. Do these before the
5287 special routines (specifically before write_function_unit_info), so
5288 that they get defined before they are used. */
5290 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5291 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5293 if (! attr
->is_special
)
5294 write_attr_get (attr
);
5297 /* Write out delay eligibility information, if DEFINE_DELAY present.
5298 (The function to compute the number of delay slots will be written
5302 write_eligible_delay ("delay");
5303 if (have_annul_true
)
5304 write_eligible_delay ("annul_true");
5305 if (have_annul_false
)
5306 write_eligible_delay ("annul_false");
5309 /* Write out information about function units. */
5311 write_function_unit_info ();
5314 exit (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);