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
100 #include "insn-config.h" /* For REGISTER_CONSTRAINTS */
102 static struct obstack obstack
, obstack1
, obstack2
;
103 struct obstack
*rtl_obstack
= &obstack
;
104 struct obstack
*hash_obstack
= &obstack1
;
105 struct obstack
*temp_obstack
= &obstack2
;
107 #define obstack_chunk_alloc xmalloc
108 #define obstack_chunk_free free
110 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
111 char **insn_name_ptr
= 0;
114 extern rtx
read_rtx ();
116 static void fatal ();
119 /* Define structures used to record attributes and values. */
121 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
122 encountered, we store all the relevant information into a
123 `struct insn_def'. This is done to allow attribute definitions to occur
124 anywhere in the file. */
128 int insn_code
; /* Instruction number. */
129 int insn_index
; /* Expression numer in file, for errors. */
130 struct insn_def
*next
; /* Next insn in chain. */
131 rtx def
; /* The DEFINE_... */
132 int num_alternatives
; /* Number of alternatives. */
133 int vec_idx
; /* Index of attribute vector in `def'. */
136 /* Once everything has been read in, we store in each attribute value a list
137 of insn codes that have that value. Here is the structure used for the
142 int insn_code
; /* Instruction number. */
143 int insn_index
; /* Index of definition in file */
144 struct insn_ent
*next
; /* Next in chain. */
147 /* Each value of an attribute (either constant or computed) is assigned a
148 structure which is used as the listhead of the insns that have that
153 rtx value
; /* Value of attribute. */
154 struct attr_value
*next
; /* Next attribute value in chain. */
155 struct insn_ent
*first_insn
; /* First insn with this value. */
156 int num_insns
; /* Number of insns with this value. */
157 int has_asm_insn
; /* True if this value used for `asm' insns */
160 /* Structure for each attribute. */
164 char *name
; /* Name of attribute. */
165 struct attr_desc
*next
; /* Next attribute. */
166 int is_numeric
; /* Values of this attribute are numeric. */
167 int is_const
; /* Attribute value constant for each run. */
168 int is_special
; /* Don't call `write_attr_set'. */
169 struct attr_value
*first_value
; /* First value of this attribute. */
170 struct attr_value
*default_val
; /* Default value for this attribute. */
173 /* Structure for each DEFINE_DELAY. */
177 rtx def
; /* DEFINE_DELAY expression. */
178 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
179 int num
; /* Number of DEFINE_DELAY, starting at 1. */
182 /* Record information about each DEFINE_FUNCTION_UNIT. */
184 struct function_unit_op
186 rtx condexp
; /* Expression TRUE for applicable insn. */
187 struct function_unit_op
*next
; /* Next operation for this function unit. */
188 int num
; /* Ordinal for this operation type in unit. */
189 int ready
; /* Cost until data is ready. */
190 rtx busyexp
; /* Expression computing conflict cost. */
193 /* Record information about each function unit mentioned in a
194 DEFINE_FUNCTION_UNIT. */
198 char *name
; /* Function unit name. */
199 struct function_unit
*next
; /* Next function unit. */
200 int num
; /* Ordinal of this unit type. */
201 int multiplicity
; /* Number of units of this type. */
202 int simultaneity
; /* Maximum number of simultaneous insns
203 on this function unit or 0 if unlimited. */
204 rtx condexp
; /* Expression TRUE for insn needing unit. */
205 rtx costexp
; /* Worst-case cost as function of insn. */
206 int num_opclasses
; /* Number of different operation types. */
207 struct function_unit_op
*ops
; /* Pointer to first operation type. */
208 int needs_conflict_function
; /* Nonzero if a conflict function required. */
209 rtx default_cost
; /* Conflict cost, if constant. */
212 /* Listheads of above structures. */
214 /* This one is indexed by the first character of the attribute name. */
215 #define MAX_ATTRS_INDEX 256
216 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
217 static struct insn_def
*defs
;
218 static struct delay_desc
*delays
;
219 static struct function_unit
*units
;
221 /* Other variables. */
223 static int insn_code_number
;
224 static int insn_index_number
;
225 static int got_define_asm_attributes
;
226 static int must_extract
;
227 static int must_constrain
;
228 static int address_used
;
229 static int num_delays
;
230 static int have_annul_true
, have_annul_false
;
231 static int num_units
;
233 /* Used as operand to `operate_exp': */
235 enum operator {PLUS_OP
, MINUS_OP
, OR_OP
, MAX_OP
};
237 /* Stores, for each insn code, the number of constraint alternatives. */
239 static int *insn_n_alternatives
;
241 /* Stores, for each insn code, a bitmap that has bits on for each possible
244 static int *insn_alternatives
;
246 /* If nonzero, assume that the `alternative' attr has this value.
247 This is the hashed, unique string for the numeral
248 whose value is chosen alternative. */
250 static char *current_alternative_string
;
252 /* Used to simplify expressions. */
254 static rtx true_rtx
, false_rtx
;
256 /* Used to reduce calls to `strcmp' */
258 static char *alternative_name
;
260 /* Simplify an expression. Only call the routine if there is something to
262 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
263 (RTX_UNCHANGING_P (EXP) || MEM_IN_STRUCT_P (EXP) ? (EXP) \
264 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
266 /* Simplify (eq_attr ("alternative") ...)
267 when we are working with a particular alternative. */
268 #define SIMPLIFY_ALTERNATIVE(EXP) \
269 if (current_alternative_string \
270 && GET_CODE ((EXP)) == EQ_ATTR \
271 && XSTR ((EXP), 0) == alternative_name) \
272 (EXP) = (XSTR ((EXP), 1) == current_alternative_string \
273 ? true_rtx : false_rtx);
275 /* These are referenced by rtlanal.c and hence need to be defined somewhere.
276 They won't actually be used. */
278 rtx frame_pointer_rtx
, stack_pointer_rtx
, arg_pointer_rtx
;
280 static rtx
attr_rtx ();
281 static char *attr_printf ();
282 static char *attr_string ();
283 static rtx
check_attr_test ();
284 static rtx
check_attr_value ();
285 static rtx
convert_set_attr_alternative ();
286 static rtx
convert_set_attr ();
287 static void check_defs ();
288 static rtx
convert_const_symbol_ref ();
289 static rtx
make_canonical ();
290 static struct attr_value
*get_attr_value ();
291 static rtx
copy_rtx_unchanging ();
292 static rtx
copy_boolean ();
293 static void expand_delays ();
294 static rtx
operate_exp ();
295 static void expand_units ();
296 static void fill_attr ();
297 static rtx
substitute_address ();
298 static void make_length_attrs ();
299 static rtx
identity_fn ();
300 static rtx
zero_fn ();
301 static rtx
one_fn ();
302 static rtx
max_fn ();
303 static rtx
simplify_cond ();
304 static rtx
simplify_by_alternatives ();
305 static void remove_insn_ent ();
306 static void insert_insn_ent ();
307 static rtx
insert_right_side ();
308 static rtx
make_alternative_compare ();
309 static int compute_alternative_mask ();
310 static rtx
evaluate_eq_attr ();
311 static rtx
simplify_and_tree ();
312 static rtx
simplify_or_tree ();
313 static rtx
simplify_test_exp ();
314 static void optimize_attrs ();
315 static void gen_attr ();
316 static int count_alternatives ();
317 static int compares_alternatives_p ();
318 static int contained_in_p ();
319 static void gen_insn ();
320 static void gen_delay ();
321 static void gen_unit ();
322 static void write_test_expr ();
323 static int max_attr_value ();
324 static void walk_attr_value ();
325 static void write_attr_get ();
326 static rtx
eliminate_known_true ();
327 static void write_attr_set ();
328 static void write_attr_case ();
329 static void write_attr_value ();
330 static void write_attr_valueq ();
331 static void write_upcase ();
332 static void write_indent ();
333 static void write_eligible_delay ();
334 static void write_function_unit_info ();
335 static int n_comma_elts ();
336 static char *next_comma_elt ();
337 static struct attr_desc
*find_attr ();
338 static void make_internal_attr ();
339 static struct attr_value
*find_most_used ();
340 static rtx
find_single_value ();
341 static rtx
make_numeric_value ();
344 static void fatal ();
346 /* Hash table for sharing RTL and strings. */
348 /* Each hash table slot is a bucket containing a chain of these structures.
349 Strings are given negative hash codes; RTL expressions are given positive
354 struct attr_hash
*next
; /* Next structure in the bucket. */
355 int hashcode
; /* Hash code of this rtx or string. */
358 char *str
; /* The string (negative hash codes) */
359 rtx rtl
; /* or the RTL recorded here. */
363 /* Now here is the hash table. When recording an RTL, it is added to
364 the slot whose index is the hash code mod the table size. Note
365 that the hash table is used for several kinds of RTL (see attr_rtx)
366 and for strings. While all these live in the same table, they are
367 completely independent, and the hash code is computed differently
370 #define RTL_HASH_SIZE 4093
371 struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
373 /* Here is how primitive or already-shared RTL's hash
375 #define RTL_HASH(RTL) ((int) (RTL) & 0777777)
377 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
380 attr_hash_add_rtx (hashcode
, rtl
)
384 register struct attr_hash
*h
;
386 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
387 sizeof (struct attr_hash
));
388 h
->hashcode
= hashcode
;
390 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
391 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
394 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
397 attr_hash_add_string (hashcode
, str
)
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 /* Generate an RTL expression, but avoid duplicates.
412 Set the RTX_INTEGRATED_P flag for these permanent objects.
414 In some cases we cannot uniquify; then we return an ordinary
415 impermanent rtx with RTX_INTEGRATED_P clear.
417 Args are like gen_rtx, but without the mode:
419 rtx attr_rtx (code, [element1, ..., elementn]) */
428 register int i
; /* Array indices... */
429 register char *fmt
; /* Current rtx's format... */
430 register rtx rt_val
; /* RTX to return to caller... */
432 register struct attr_hash
*h
;
433 struct obstack
*old_obstack
= rtl_obstack
;
436 code
= va_arg (p
, enum rtx_code
);
438 /* For each of several cases, search the hash table for an existing entry.
439 Use that entry if one is found; otherwise create a new RTL and add it
442 if (GET_RTX_CLASS (code
) == '1')
444 rtx arg0
= va_arg (p
, rtx
);
446 /* A permanent object cannot point to impermanent ones. */
447 if (! RTX_INTEGRATED_P (arg0
))
449 rt_val
= rtx_alloc (code
);
450 XEXP (rt_val
, 0) = arg0
;
455 hashcode
= ((int) code
+ RTL_HASH (arg0
));
456 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
457 if (h
->hashcode
== hashcode
458 && GET_CODE (h
->u
.rtl
) == code
459 && XEXP (h
->u
.rtl
, 0) == arg0
)
464 rtl_obstack
= hash_obstack
;
465 rt_val
= rtx_alloc (code
);
466 XEXP (rt_val
, 0) = arg0
;
469 else if (GET_RTX_CLASS (code
) == 'c'
470 || GET_RTX_CLASS (code
) == '2'
471 || GET_RTX_CLASS (code
) == '<')
473 rtx arg0
= va_arg (p
, rtx
);
474 rtx arg1
= va_arg (p
, rtx
);
476 /* A permanent object cannot point to impermanent ones. */
477 if (! RTX_INTEGRATED_P (arg0
) || ! RTX_INTEGRATED_P (arg1
))
479 rt_val
= rtx_alloc (code
);
480 XEXP (rt_val
, 0) = arg0
;
481 XEXP (rt_val
, 1) = arg1
;
486 hashcode
= ((int) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
487 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
488 if (h
->hashcode
== hashcode
489 && GET_CODE (h
->u
.rtl
) == code
490 && XEXP (h
->u
.rtl
, 0) == arg0
491 && XEXP (h
->u
.rtl
, 1) == arg1
)
496 rtl_obstack
= hash_obstack
;
497 rt_val
= rtx_alloc (code
);
498 XEXP (rt_val
, 0) = arg0
;
499 XEXP (rt_val
, 1) = arg1
;
502 else if (GET_RTX_LENGTH (code
) == 1
503 && GET_RTX_FORMAT (code
)[0] == 's')
505 char * arg0
= va_arg (p
, char *);
507 if (code
== SYMBOL_REF
)
508 arg0
= attr_string (arg0
, strlen (arg0
));
510 hashcode
= ((int) code
+ RTL_HASH (arg0
));
511 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
512 if (h
->hashcode
== hashcode
513 && GET_CODE (h
->u
.rtl
) == code
514 && XSTR (h
->u
.rtl
, 0) == arg0
)
519 rtl_obstack
= hash_obstack
;
520 rt_val
= rtx_alloc (code
);
521 XSTR (rt_val
, 0) = arg0
;
524 else if (GET_RTX_LENGTH (code
) == 2
525 && GET_RTX_FORMAT (code
)[0] == 's'
526 && GET_RTX_FORMAT (code
)[1] == 's')
528 char *arg0
= va_arg (p
, char *);
529 char *arg1
= va_arg (p
, char *);
531 hashcode
= ((int) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
532 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
533 if (h
->hashcode
== hashcode
534 && GET_CODE (h
->u
.rtl
) == code
535 && XSTR (h
->u
.rtl
, 0) == arg0
536 && XSTR (h
->u
.rtl
, 1) == arg1
)
541 rtl_obstack
= hash_obstack
;
542 rt_val
= rtx_alloc (code
);
543 XSTR (rt_val
, 0) = arg0
;
544 XSTR (rt_val
, 1) = arg1
;
547 else if (code
== CONST_INT
)
549 int arg0
= va_arg (p
, int);
559 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
561 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
562 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
566 case '0': /* Unused field. */
569 case 'i': /* An integer? */
570 XINT (rt_val
, i
) = va_arg (p
, int);
573 case 's': /* A string? */
574 XSTR (rt_val
, i
) = va_arg (p
, char *);
577 case 'e': /* An expression? */
578 case 'u': /* An insn? Same except when printing. */
579 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
582 case 'E': /* An RTX vector? */
583 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
594 rtl_obstack
= old_obstack
;
596 attr_hash_add_rtx (hashcode
, rt_val
);
597 RTX_INTEGRATED_P (rt_val
) = 1;
605 /* Create a new string printed with the printf line arguments into a space
606 of at most LEN bytes:
608 rtx attr_printf (len, format, [arg1, ..., argn]) */
614 attr_printf (va_alist
)
622 /* Print the string into a temporary location. */
624 len
= va_arg (p
, int);
625 str
= (char *) alloca (len
);
626 fmt
= va_arg (p
, char *);
627 vsprintf (str
, fmt
, p
);
630 return attr_string (str
, strlen (str
));
633 #else /* not HAVE_VPRINTF */
636 attr_printf (len
, fmt
, arg1
, arg2
, arg3
)
639 char *arg1
, *arg2
, *arg3
; /* also int */
643 /* Print the string into a temporary location. */
644 str
= (char *) alloca (len
);
645 sprintf (str
, fmt
, arg1
, arg2
, arg3
);
647 return attr_string (str
, strlen (str
));
649 #endif /* not HAVE_VPRINTF */
652 attr_eq (name
, value
)
655 return attr_rtx (EQ_ATTR
, attr_string (name
, strlen (name
)),
656 attr_string (value
, strlen (value
)));
663 return XSTR (make_numeric_value (n
), 0);
666 /* Return a permanent (possibly shared) copy of a string STR (not assumed
667 to be null terminated) with LEN bytes. */
670 attr_string (str
, len
)
674 register struct attr_hash
*h
;
677 register char *new_str
;
679 /* Compute the hash code. */
680 hashcode
= (len
+ 1) * 613 + (unsigned)str
[0];
681 for (i
= 1; i
<= len
; i
+= 2)
682 hashcode
= ((hashcode
* 613) + (unsigned)str
[i
]);
684 hashcode
= -hashcode
;
686 /* Search the table for the string. */
687 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
688 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
689 && !strncmp (h
->u
.str
, str
, len
))
690 return h
->u
.str
; /* <-- return if found. */
692 /* Not found; create a permanent copy and add it to the hash table. */
693 new_str
= (char *) obstack_alloc (hash_obstack
, len
+ 1);
694 bcopy (str
, new_str
, len
);
696 attr_hash_add_string (hashcode
, new_str
);
698 return new_str
; /* Return the new string. */
701 /* Check two rtx's for equality of contents,
702 taking advantage of the fact that if both are hashed
703 then they can't be equal unless they are the same object. */
709 return (x
== y
|| (! (RTX_INTEGRATED_P (x
) && RTX_INTEGRATED_P (y
))
710 && rtx_equal_p (x
, y
)));
713 /* Copy an attribute value expression,
714 descending to all depths, but not copying any
715 permanent hashed subexpressions. */
723 register RTX_CODE code
;
724 register char *format_ptr
;
726 /* No need to copy a permanent object. */
727 if (RTX_INTEGRATED_P (orig
))
730 code
= GET_CODE (orig
);
745 copy
= rtx_alloc (code
);
746 PUT_MODE (copy
, GET_MODE (orig
));
747 copy
->in_struct
= orig
->in_struct
;
748 copy
->volatil
= orig
->volatil
;
749 copy
->unchanging
= orig
->unchanging
;
750 copy
->integrated
= orig
->integrated
;
752 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
754 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
756 switch (*format_ptr
++)
759 XEXP (copy
, i
) = XEXP (orig
, i
);
760 if (XEXP (orig
, i
) != NULL
)
761 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
766 XVEC (copy
, i
) = XVEC (orig
, i
);
767 if (XVEC (orig
, i
) != NULL
)
769 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
770 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
771 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
776 XINT (copy
, i
) = XINT (orig
, i
);
783 /* Given a test expression for an attribute, ensure it is validly formed.
784 IS_CONST indicates whether the expression is constant for each compiler
785 run (a constant expression may not test any particular insn).
787 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
788 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
789 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
791 Update the string address in EQ_ATTR expression to be the same used
792 in the attribute (or `alternative_name') to speed up subsequent
793 `find_attr' calls and eliminate most `strcmp' calls.
795 Return the new expression, if any. */
798 check_attr_test (exp
, is_const
)
802 struct attr_desc
*attr
;
803 struct attr_value
*av
;
807 switch (GET_CODE (exp
))
810 /* Handle negation test. */
811 if (XSTR (exp
, 1)[0] == '!')
812 return check_attr_test (attr_rtx (NOT
,
813 attr_eq (XSTR (exp
, 0),
817 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
819 attr
= find_attr (XSTR (exp
, 0), 0);
822 if (! strcmp (XSTR (exp
, 0), "alternative"))
824 XSTR (exp
, 0) = alternative_name
;
825 /* This can't be simplified any further. */
826 RTX_UNCHANGING_P (exp
) = 1;
830 fatal ("Unknown attribute `%s' in EQ_ATTR", XEXP (exp
, 0));
833 if (is_const
&& ! attr
->is_const
)
834 fatal ("Constant expression uses insn attribute `%s' in EQ_ATTR",
837 /* Copy this just to make it permanent,
838 so expressions using it can be permanent too. */
839 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
841 /* It shouldn't be possible to simplfy the value given to a
842 constant attribute, so don't expand this until it's time to
843 write the test expression. */
845 RTX_UNCHANGING_P (exp
) = 1;
847 if (attr
->is_numeric
)
849 for (p
= XSTR (exp
, 1); *p
; p
++)
850 if (*p
< '0' || *p
> '9')
851 fatal ("Attribute `%s' takes only numeric values",
856 for (av
= attr
->first_value
; av
; av
= av
->next
)
857 if (GET_CODE (av
->value
) == CONST_STRING
858 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
862 fatal ("Unknown value `%s' for `%s' attribute",
863 XEXP (exp
, 1), XEXP (exp
, 0));
868 /* Make an IOR tree of the possible values. */
870 name_ptr
= XSTR (exp
, 1);
871 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
873 newexp
= attr_eq (XSTR (exp
, 0), p
);
874 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2);
877 return check_attr_test (orexp
, is_const
);
882 /* Either TRUE or FALSE. */
890 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
);
891 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
);
895 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
);
900 fatal ("RTL operator \"%s\" not valid in constant attribute test",
901 GET_RTX_NAME (MATCH_OPERAND
));
902 /* These cases can't be simplified. */
903 RTX_UNCHANGING_P (exp
) = 1;
906 case LE
: case LT
: case GT
: case GE
:
907 case LEU
: case LTU
: case GTU
: case GEU
:
909 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
910 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
911 exp
= attr_rtx (GET_CODE (exp
),
912 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
913 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
914 /* These cases can't be simplified. */
915 RTX_UNCHANGING_P (exp
) = 1;
921 /* These cases are valid for constant attributes, but can't be
923 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
924 RTX_UNCHANGING_P (exp
) = 1;
928 fatal ("RTL operator \"%s\" not valid in attribute test",
929 GET_RTX_NAME (GET_CODE (exp
)));
935 /* Given an expression, ensure that it is validly formed and that all named
936 attribute values are valid for the given attribute. Issue a fatal error
937 if not. If no attribute is specified, assume a numeric attribute.
939 Return a perhaps modified replacement expression for the value. */
942 check_attr_value (exp
, attr
)
944 struct attr_desc
*attr
;
946 struct attr_value
*av
;
950 switch (GET_CODE (exp
))
953 if (attr
&& ! attr
->is_numeric
)
954 fatal ("CONST_INT not valid for non-numeric `%s' attribute",
957 if (INTVAL (exp
) < 0)
958 fatal ("Negative numeric value specified for `%s' attribute",
964 if (! strcmp (XSTR (exp
, 0), "*"))
967 if (attr
== 0 || attr
->is_numeric
)
969 for (p
= XSTR (exp
, 0); *p
; p
++)
970 if (*p
> '9' || *p
< '0')
971 fatal ("Non-numeric value for numeric `%s' attribute",
972 attr
? attr
->name
: "internal");
976 for (av
= attr
->first_value
; av
; av
= av
->next
)
977 if (GET_CODE (av
->value
) == CONST_STRING
978 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
982 fatal ("Unknown value `%s' for `%s' attribute",
983 XSTR (exp
, 0), attr
? attr
->name
: "internal");
988 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
989 attr
? attr
->is_const
: 0);
990 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
991 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
995 if (XVECLEN (exp
, 0) % 2 != 0)
996 fatal ("First operand of COND must have even length");
998 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1000 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1001 attr
? attr
->is_const
: 0);
1002 XVECEXP (exp
, 0, i
+ 1)
1003 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1006 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1010 if (attr
&& attr
->is_const
)
1011 /* A constant SYMBOL_REF is valid as a constant attribute test and
1012 is expanded later by make_canonical into a COND. */
1013 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1014 /* Otherwise, fall through... */
1017 fatal ("Illegal operation `%s' for attribute value",
1018 GET_RTX_NAME (GET_CODE (exp
)));
1024 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1025 It becomes a COND with each test being (eq_attr "alternative "n") */
1028 convert_set_attr_alternative (exp
, num_alt
, insn_code
, insn_index
)
1031 int insn_code
, insn_index
;
1037 if (XVECLEN (exp
, 1) != num_alt
)
1038 fatal ("Bad number of entries in SET_ATTR_ALTERNATIVE for insn %d",
1041 /* Make a COND with all tests but the last. Select the last value via the
1043 condexp
= rtx_alloc (COND
);
1044 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1046 for (i
= 0; i
< num_alt
- 1; i
++)
1049 p
= attr_numeral (i
);
1051 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1053 /* Sharing this EQ_ATTR rtl causes trouble. */
1054 XVECEXP (condexp
, 0, 2 * i
) = rtx_alloc (EQ_ATTR
);
1055 XSTR (XVECEXP (condexp
, 0, 2 * i
), 0) = alternative_name
;
1056 XSTR (XVECEXP (condexp
, 0, 2 * i
), 1) = p
;
1058 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1061 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1063 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1066 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1067 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1070 convert_set_attr (exp
, num_alt
, insn_code
, insn_index
)
1073 int insn_code
, insn_index
;
1080 /* See how many alternative specified. */
1081 n
= n_comma_elts (XSTR (exp
, 1));
1083 return attr_rtx (SET
,
1084 attr_rtx (ATTR
, XSTR (exp
, 0)),
1085 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1087 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1088 XSTR (newexp
, 0) = XSTR (exp
, 0);
1089 XVEC (newexp
, 1) = rtvec_alloc (n
);
1091 /* Process each comma-separated name. */
1092 name_ptr
= XSTR (exp
, 1);
1094 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1095 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1097 return convert_set_attr_alternative (newexp
, num_alt
, insn_code
, insn_index
);
1100 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1101 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1107 struct insn_def
*id
;
1108 struct attr_desc
*attr
;
1112 for (id
= defs
; id
; id
= id
->next
)
1114 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1117 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1119 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1120 switch (GET_CODE (value
))
1123 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1124 fatal ("Bad attribute set in pattern %d", id
->insn_index
);
1127 case SET_ATTR_ALTERNATIVE
:
1128 value
= convert_set_attr_alternative (value
,
1129 id
->num_alternatives
,
1135 value
= convert_set_attr (value
, id
->num_alternatives
,
1136 id
->insn_code
, id
->insn_index
);
1140 fatal ("Invalid attribute code `%s' for pattern %d",
1141 GET_RTX_NAME (GET_CODE (value
)), id
->insn_index
);
1144 if ((attr
= find_attr (XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1145 fatal ("Unknown attribute `%s' for pattern number %d",
1146 XSTR (XEXP (value
, 0), 0), id
->insn_index
);
1148 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1149 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1154 /* Given a constant SYMBOL_REF expression, convert to a COND that
1155 explicitly tests each enumerated value. */
1158 convert_const_symbol_ref (exp
, attr
)
1160 struct attr_desc
*attr
;
1163 struct attr_value
*av
;
1167 for (av
= attr
->first_value
; av
; av
= av
->next
)
1170 /* Make a COND with all tests but the last, and in the original order.
1171 Select the last value via the default. Note that the attr values
1172 are constructed in reverse order. */
1174 condexp
= rtx_alloc (COND
);
1175 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1176 av
= attr
->first_value
;
1177 XEXP (condexp
, 1) = av
->value
;
1179 for (i
= num_alt
- 2; av
= av
->next
, i
>= 0; i
--)
1184 string
= p
= (char *) xmalloc (2
1185 + strlen (attr
->name
)
1186 + strlen (XSTR (av
->value
, 0)));
1187 strcpy (p
, attr
->name
);
1189 strcat (p
, XSTR (av
->value
, 0));
1190 for (; *p
!= '\0'; p
++)
1191 if (*p
>= 'a' && *p
<= 'z')
1194 value
= attr_rtx (SYMBOL_REF
, string
);
1195 RTX_UNCHANGING_P (value
) = 1;
1197 XVECEXP (condexp
, 0, 2 * i
) = attr_rtx (EQ
, exp
, value
);
1199 XVECEXP (condexp
, 0, 2 * i
+ 1) = av
->value
;
1205 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1206 expressions by converting them into a COND. This removes cases from this
1207 program. Also, replace an attribute value of "*" with the default attribute
1211 make_canonical (attr
, exp
)
1212 struct attr_desc
*attr
;
1218 switch (GET_CODE (exp
))
1221 exp
= make_numeric_value (INTVAL (exp
));
1225 if (! strcmp (XSTR (exp
, 0), "*"))
1227 if (attr
== 0 || attr
->default_val
== 0)
1228 fatal ("(attr_value \"*\") used in invalid context.");
1229 exp
= attr
->default_val
->value
;
1235 if (!attr
->is_const
|| RTX_UNCHANGING_P (exp
))
1237 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1238 This makes the COND something that won't be considered an arbitrary
1239 expression by walk_attr_value. */
1240 RTX_UNCHANGING_P (exp
) = 1;
1241 exp
= convert_const_symbol_ref (exp
, attr
);
1242 RTX_UNCHANGING_P (exp
) = 1;
1243 exp
= check_attr_value (exp
, attr
);
1244 /* Goto COND case since this is now a COND. Note that while the
1245 new expression is rescanned, all symbol_ref notes are mared as
1250 newexp
= rtx_alloc (COND
);
1251 XVEC (newexp
, 0) = rtvec_alloc (2);
1252 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1253 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1255 XEXP (newexp
, 1) = XEXP (exp
, 2);
1258 /* Fall through to COND case since this is now a COND. */
1266 /* First, check for degenerate COND. */
1267 if (XVECLEN (exp
, 0) == 0)
1268 return make_canonical (attr
, XEXP (exp
, 1));
1269 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1271 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1273 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1274 XVECEXP (exp
, 0, i
+ 1)
1275 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1276 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1292 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1293 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1294 copy_boolean (XEXP (exp
, 1)));
1298 /* Given a value and an attribute description, return a `struct attr_value *'
1299 that represents that value. This is either an existing structure, if the
1300 value has been previously encountered, or a newly-created structure.
1302 `insn_code' is the code of an insn whose attribute has the specified
1303 value (-2 if not processing an insn). We ensure that all insns for
1304 a given value have the same number of alternatives if the value checks
1307 static struct attr_value
*
1308 get_attr_value (value
, attr
, insn_code
)
1310 struct attr_desc
*attr
;
1313 struct attr_value
*av
;
1316 value
= make_canonical (attr
, value
);
1317 if (compares_alternatives_p (value
))
1319 if (insn_code
< 0 || insn_alternatives
== NULL
)
1320 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1322 num_alt
= insn_alternatives
[insn_code
];
1325 for (av
= attr
->first_value
; av
; av
= av
->next
)
1326 if (rtx_equal_p (value
, av
->value
)
1327 && (num_alt
== 0 || av
->first_insn
== NULL
1328 || insn_alternatives
[av
->first_insn
->insn_code
]))
1331 av
= (struct attr_value
*) xmalloc (sizeof (struct attr_value
));
1333 av
->next
= attr
->first_value
;
1334 attr
->first_value
= av
;
1335 av
->first_insn
= NULL
;
1337 av
->has_asm_insn
= 0;
1342 /* After all DEFINE_DELAYs have been read in, create internal attributes
1343 to generate the required routines.
1345 First, we compute the number of delay slots for each insn (as a COND of
1346 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1347 delay type is specified, we compute a similar function giving the
1348 DEFINE_DELAY ordinal for each insn.
1350 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1351 tells whether a given insn can be in that delay slot.
1353 Normal attribute filling and optimization expands these to contain the
1354 information needed to handle delay slots. */
1359 struct delay_desc
*delay
;
1365 /* First, generate data for `num_delay_slots' function. */
1367 condexp
= rtx_alloc (COND
);
1368 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1369 XEXP (condexp
, 1) = make_numeric_value (0);
1371 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1373 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1374 XVECEXP (condexp
, 0, i
+ 1)
1375 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1378 make_internal_attr ("*num_delay_slots", condexp
, 0);
1380 /* If more than one delay type, do the same for computing the delay type. */
1383 condexp
= rtx_alloc (COND
);
1384 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1385 XEXP (condexp
, 1) = make_numeric_value (0);
1387 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1389 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1390 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1393 make_internal_attr ("*delay_type", condexp
, 1);
1396 /* For each delay possibility and delay slot, compute an eligibility
1397 attribute for non-annulled insns and for each type of annulled (annul
1398 if true and annul if false). */
1399 for (delay
= delays
; delay
; delay
= delay
->next
)
1401 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1403 condexp
= XVECEXP (delay
->def
, 1, i
);
1404 if (condexp
== 0) condexp
= false_rtx
;
1405 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1406 make_numeric_value (1), make_numeric_value (0));
1408 p
= attr_printf (13, "*delay_%d_%d", delay
->num
, i
/ 3);
1409 make_internal_attr (p
, newexp
, 1);
1411 if (have_annul_true
)
1413 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1414 if (condexp
== 0) condexp
= false_rtx
;
1415 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1416 make_numeric_value (1),
1417 make_numeric_value (0));
1418 p
= attr_printf (18, "*annul_true_%d_%d", delay
->num
, i
/ 3);
1419 make_internal_attr (p
, newexp
, 1);
1422 if (have_annul_false
)
1424 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1425 if (condexp
== 0) condexp
= false_rtx
;
1426 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1427 make_numeric_value (1),
1428 make_numeric_value (0));
1429 p
= attr_printf (18, "*annul_false_%d_%d", delay
->num
, i
/ 3);
1430 make_internal_attr (p
, newexp
, 1);
1436 /* This function is given a left and right side expression and an operator.
1437 Each side is a conditional expression, each alternative of which has a
1438 numerical value. The function returns another conditional expression
1439 which, for every possible set of condition values, returns a value that is
1440 the operator applied to the values of the two sides.
1442 Since this is called early, it must also support IF_THEN_ELSE. */
1445 operate_exp (op
, left
, right
)
1449 int left_value
, right_value
;
1453 /* If left is a string, apply operator to it and the right side. */
1454 if (GET_CODE (left
) == CONST_STRING
)
1456 /* If right is also a string, just perform the operation. */
1457 if (GET_CODE (right
) == CONST_STRING
)
1459 left_value
= atoi (XSTR (left
, 0));
1460 right_value
= atoi (XSTR (right
, 0));
1464 i
= left_value
+ right_value
;
1468 i
= left_value
- right_value
;
1472 i
= left_value
| right_value
;
1476 if (left_value
> right_value
)
1486 return make_numeric_value (i
);
1488 else if (GET_CODE (right
) == IF_THEN_ELSE
)
1490 /* Apply recursively to all values within. */
1491 rtx newleft
= operate_exp (op
, left
, XEXP (right
, 1));
1492 rtx newright
= operate_exp (op
, left
, XEXP (right
, 2));
1493 if (rtx_equal_p (newleft
, newright
))
1495 return attr_rtx (IF_THEN_ELSE
, XEXP (right
, 0), newleft
, newright
);
1497 else if (GET_CODE (right
) == COND
)
1502 newexp
= rtx_alloc (COND
);
1503 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (right
, 0));
1504 defval
= XEXP (newexp
, 1) = operate_exp (op
, left
, XEXP (right
, 1));
1506 for (i
= 0; i
< XVECLEN (right
, 0); i
+= 2)
1508 XVECEXP (newexp
, 0, i
) = XVECEXP (right
, 0, i
);
1509 XVECEXP (newexp
, 0, i
+ 1)
1510 = operate_exp (op
, left
, XVECEXP (right
, 0, i
+ 1));
1511 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1516 /* If the resulting cond is trivial (all alternatives
1517 give the same value), optimize it away. */
1520 obstack_free (rtl_obstack
, newexp
);
1521 return operate_exp (op
, left
, XEXP (right
, 1));
1524 /* If the result is the same as the RIGHT operand,
1526 if (rtx_equal_p (newexp
, right
))
1528 obstack_free (rtl_obstack
, newexp
);
1535 fatal ("Badly formed attribute value");
1538 /* Otherwise, do recursion the other way. */
1539 else if (GET_CODE (left
) == IF_THEN_ELSE
)
1541 rtx newleft
= operate_exp (op
, XEXP (left
, 1), right
);
1542 rtx newright
= operate_exp (op
, XEXP (left
, 2), right
);
1543 if (rtx_equal_p (newleft
, newright
))
1545 return attr_rtx (IF_THEN_ELSE
, XEXP (left
, 0), newleft
, newright
);
1547 else if (GET_CODE (left
) == COND
)
1552 newexp
= rtx_alloc (COND
);
1553 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (left
, 0));
1554 defval
= XEXP (newexp
, 1) = operate_exp (op
, XEXP (left
, 1), right
);
1556 for (i
= 0; i
< XVECLEN (left
, 0); i
+= 2)
1558 XVECEXP (newexp
, 0, i
) = XVECEXP (left
, 0, i
);
1559 XVECEXP (newexp
, 0, i
+ 1)
1560 = operate_exp (op
, XVECEXP (left
, 0, i
+ 1), right
);
1561 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1566 /* If the cond is trivial (all alternatives give the same value),
1567 optimize it away. */
1570 obstack_free (rtl_obstack
, newexp
);
1571 return operate_exp (op
, XEXP (left
, 1), right
);
1574 /* If the result is the same as the LEFT operand,
1576 if (rtx_equal_p (newexp
, left
))
1578 obstack_free (rtl_obstack
, newexp
);
1586 fatal ("Badly formed attribute value.");
1591 /* Once all attributes and DEFINE_FUNCTION_UNITs have been read, we
1592 construct a number of attributes.
1594 The first produces a function `function_units_used' which is given an
1595 insn and produces a mask showing which function units are required for
1596 the execution of that insn.
1598 The second produces a function `result_ready_cost' which is used to
1599 determine the time that the result of an insn will be ready and hence
1600 a worst-case schedule.
1602 Both of these produce quite complex expressions which are then set as the
1603 default value of internal attributes. Normal attribute simplification
1604 should produce reasonable expressions.
1606 For each unit, a `<name>_unit_ready_cost' function will take an
1607 insn and give the delay until that unit will be ready with the result
1608 and a `<name>_unit_busy_delay' function is given an insn already
1609 executing on the unit and a candidate to execute and will give the
1610 cost from the time the executing insn started until the candidate
1611 can start (ignore limitations on the number of simultaneous insns). */
1616 struct function_unit
*unit
;
1617 struct function_unit_op
*op
;
1623 /* Initially, cost and masks are zero. */
1624 unitsmask
= readycost
= make_numeric_value (0);
1626 /* Set up a conditional for costs and unit mask. */
1627 newexp
= rtx_alloc (IF_THEN_ELSE
);
1628 XEXP (newexp
, 2) = make_numeric_value (0);
1630 /* For each unit, insert its contribution to the above three values. */
1631 for (unit
= units
; unit
; unit
= unit
->next
)
1633 /* An expression that computes the ready cost for this unit. */
1634 rtx readyexp
= rtx_alloc (COND
);
1635 /* An expression that maps insns to operation number for conflicts. */
1636 rtx caseexp
= rtx_alloc (COND
);
1638 XVEC (readyexp
, 0) = rtvec_alloc ((unit
->num_opclasses
- 1) * 2);
1639 XVEC (caseexp
, 0) = rtvec_alloc ((unit
->num_opclasses
- 1) * 2);
1641 for (op
= unit
->ops
; op
; op
= op
->next
)
1643 /* Validate the expressions we were given for the conditions
1644 and busy cost. Then make an attribute for use in the conflict
1646 op
->condexp
= check_attr_test (op
->condexp
, 0);
1647 op
->busyexp
= check_attr_value (op
->busyexp
, 0);
1648 str
= attr_printf (strlen (unit
->name
) + 11, "*%s_case_%d",
1649 unit
->name
, op
->num
);
1650 make_internal_attr (str
, make_canonical (0, op
->busyexp
));
1652 /* Make our adjustment to the two COND's being computed. If we are
1653 the last operation class, place our values into the default of
1655 if (op
->num
== unit
->num_opclasses
- 1)
1657 XEXP (readyexp
, 1) = make_numeric_value (op
->ready
);
1658 XEXP (caseexp
, 1) = make_numeric_value (op
->num
);
1662 XVECEXP (readyexp
, 0, op
->num
* 2) = op
->condexp
;
1663 XVECEXP (readyexp
, 0, op
->num
* 2 + 1)
1664 = make_numeric_value (op
->ready
);
1665 XVECEXP (caseexp
, 0, op
->num
* 2) = op
->condexp
;
1666 XVECEXP (caseexp
, 0, op
->num
* 2 + 1)
1667 = make_numeric_value (op
->num
);
1671 /* Make an attribute for the case number and ready delay. */
1672 str
= attr_printf (strlen (unit
->name
) + 8, "*%s_cases", unit
->name
);
1673 make_internal_attr (str
, caseexp
, 1);
1675 str
= attr_printf (strlen (unit
->name
) + 20, "*%s_unit_ready_cost",
1677 make_internal_attr (str
, readyexp
, 0);
1679 /* Merge this function unit into the ready cost and unit mask
1681 XEXP (newexp
, 0) = check_attr_test (unit
->condexp
, 0);
1682 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1683 unitsmask
= operate_exp (OR_OP
, unitsmask
, newexp
);
1685 XEXP (newexp
, 1) = readyexp
;
1686 readycost
= operate_exp (MAX_OP
, readycost
, newexp
);
1689 make_internal_attr ("*function_units_used", unitsmask
, 0);
1690 make_internal_attr ("*result_ready_cost", readycost
, 0);
1693 /* Once all attributes and insns have been read and checked, we construct for
1694 each attribute value a list of all the insns that have that value for
1699 struct attr_desc
*attr
;
1701 struct attr_value
*av
;
1702 struct insn_ent
*ie
;
1703 struct insn_def
*id
;
1707 /* Don't fill constant attributes. The value is independent of
1708 any particular insn. */
1712 for (id
= defs
; id
; id
= id
->next
)
1714 /* If no value is specified for this insn for this attribute, use the
1717 if (XVEC (id
->def
, id
->vec_idx
))
1718 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1719 if (! strcmp (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
1721 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
1724 av
= attr
->default_val
;
1726 av
= get_attr_value (value
, attr
, id
->insn_code
);
1728 ie
= (struct insn_ent
*) xmalloc (sizeof (struct insn_ent
));
1729 ie
->insn_code
= id
->insn_code
;
1730 ie
->insn_index
= id
->insn_code
;
1731 insert_insn_ent (av
, ie
);
1735 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
1736 test that checks relative positions of insns (uses MATCH_DUP or PC).
1737 If so, replace it with what is obtained by passing the expression to
1738 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
1739 recursively on each value (including the default value). Otherwise,
1740 return the value returned by NO_ADDRESS_FN applied to EXP. */
1743 substitute_address (exp
, no_address_fn
, address_fn
)
1745 rtx (*no_address_fn
) ();
1746 rtx (*address_fn
) ();
1751 if (GET_CODE (exp
) == COND
)
1753 /* See if any tests use addresses. */
1755 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1756 walk_attr_value (XVECEXP (exp
, 0, i
));
1759 return (*address_fn
) (exp
);
1761 /* Make a new copy of this COND, replacing each element. */
1762 newexp
= rtx_alloc (COND
);
1763 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
1764 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1766 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
1767 XVECEXP (newexp
, 0, i
+ 1)
1768 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
1769 no_address_fn
, address_fn
);
1772 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
1773 no_address_fn
, address_fn
);
1778 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
1781 walk_attr_value (XEXP (exp
, 0));
1783 return (*address_fn
) (exp
);
1785 return attr_rtx (IF_THEN_ELSE
,
1786 substitute_address (XEXP (exp
, 0),
1787 no_address_fn
, address_fn
),
1788 substitute_address (XEXP (exp
, 1),
1789 no_address_fn
, address_fn
),
1790 substitute_address (XEXP (exp
, 2),
1791 no_address_fn
, address_fn
));
1794 return (*no_address_fn
) (exp
);
1797 /* Make new attributes from the `length' attribute. The following are made,
1798 each corresponding to a function called from `shorten_branches' or
1801 *insn_default_length This is the length of the insn to be returned
1802 by `get_attr_length' before `shorten_branches'
1803 has been called. In each case where the length
1804 depends on relative addresses, the largest
1805 possible is used. This routine is also used
1806 to compute the initial size of the insn.
1808 *insn_variable_length_p This returns 1 if the insn's length depends
1809 on relative addresses, zero otherwise.
1811 *insn_current_length This is only called when it is known that the
1812 insn has a variable length and returns the
1813 current length, based on relative addresses.
1817 make_length_attrs ()
1819 static char *new_names
[] = {"*insn_default_length",
1820 "*insn_variable_length_p",
1821 "*insn_current_length"};
1822 static rtx (*no_address_fn
[]) () = {identity_fn
, zero_fn
, zero_fn
};
1823 static rtx (*address_fn
[]) () = {max_fn
, one_fn
, identity_fn
};
1825 struct attr_desc
*length_attr
, *new_attr
;
1826 struct attr_value
*av
, *new_av
;
1827 struct insn_ent
*ie
, *new_ie
;
1829 /* See if length attribute is defined. If so, it must be numeric. Make
1830 it special so we don't output anything for it. */
1831 length_attr
= find_attr ("length", 0);
1832 if (length_attr
== 0)
1835 if (! length_attr
->is_numeric
)
1836 fatal ("length attribute must be numeric.");
1838 length_attr
->is_const
= 0;
1839 length_attr
->is_special
= 1;
1841 /* Make each new attribute, in turn. */
1842 for (i
= 0; i
< sizeof new_names
/ sizeof new_names
[0]; i
++)
1844 make_internal_attr (new_names
[i
],
1845 substitute_address (length_attr
->default_val
->value
,
1846 no_address_fn
[i
], address_fn
[i
]),
1848 new_attr
= find_attr (new_names
[i
], 0);
1849 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
1850 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
1852 new_av
= get_attr_value (substitute_address (av
->value
,
1855 new_attr
, ie
->insn_code
);
1856 new_ie
= (struct insn_ent
*) xmalloc (sizeof (struct insn_ent
));
1857 new_ie
->insn_code
= ie
->insn_code
;
1858 new_ie
->insn_index
= ie
->insn_index
;
1859 insert_insn_ent (new_av
, new_ie
);
1864 /* Utility functions called from above routine. */
1877 return make_numeric_value (0);
1884 return make_numeric_value (1);
1891 return make_numeric_value (max_attr_value (exp
));
1894 /* Take a COND expression and see if any of the conditions in it can be
1895 simplified. If any are known true or known false for the particular insn
1896 code, the COND can be further simplified.
1898 Also call ourselves on any COND operations that are values of this COND.
1900 We do not modify EXP; rather, we make and return a new rtx. */
1903 simplify_cond (exp
, insn_code
, insn_index
)
1905 int insn_code
, insn_index
;
1908 /* We store the desired contents here,
1909 then build a new expression if they don't match EXP. */
1910 rtx defval
= XEXP (exp
, 1);
1911 rtx new_defval
= XEXP (exp
, 1);
1913 int len
= XVECLEN (exp
, 0);
1914 rtx
*tests
= (rtx
*) alloca (len
* sizeof (rtx
));
1916 char *spacer
, *first_spacer
;
1918 /* This lets us free all storage allocated below, if appropriate. */
1919 first_spacer
= (char *) obstack_finish (rtl_obstack
);
1921 bcopy (&XVECEXP (exp
, 0, 0), tests
, len
* sizeof (rtx
));
1923 /* See if default value needs simplification. */
1924 if (GET_CODE (defval
) == COND
)
1925 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
1927 /* Simplify the subexpressions, and see what tests we can get rid of. */
1929 for (i
= 0; i
< len
; i
+= 2)
1931 rtx newtest
, newval
;
1933 /* Simplify this test. */
1934 newtest
= SIMPLIFY_TEST_EXP (tests
[i
], insn_code
, insn_index
);
1937 newval
= tests
[i
+ 1];
1938 /* See if this value may need simplification. */
1939 if (GET_CODE (newval
) == COND
)
1940 newval
= simplify_cond (newval
, insn_code
, insn_index
);
1942 /* Look for ways to delete or combine this test. */
1943 if (newtest
== true_rtx
)
1945 /* If test is true, make this value the default
1946 and discard this + any following tests. */
1948 defval
= tests
[i
+ 1];
1949 new_defval
= newval
;
1952 else if (newtest
== false_rtx
)
1954 /* If test is false, discard it and its value. */
1955 for (j
= i
; j
< len
- 2; j
++)
1956 tests
[j
] = tests
[j
+ 2];
1960 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
1962 /* If this value and the value for the prev test are the same,
1966 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
1967 insn_code
, insn_index
);
1969 /* Delete this test/value. */
1970 for (j
= i
; j
< len
- 2; j
++)
1971 tests
[j
] = tests
[j
+ 2];
1976 tests
[i
+ 1] = newval
;
1979 /* If the last test in a COND has the same value
1980 as the default value, that test isn't needed. */
1982 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
1985 /* See if we changed anything. */
1986 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
1989 for (i
= 0; i
< len
; i
++)
1990 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
1998 obstack_free (rtl_obstack
, first_spacer
);
1999 if (GET_CODE (defval
) == COND
)
2000 return simplify_cond (defval
, insn_code
, insn_index
);
2005 obstack_free (rtl_obstack
, first_spacer
);
2010 rtx newexp
= rtx_alloc (COND
);
2012 XVEC (newexp
, 0) = rtvec_alloc (len
);
2013 bcopy (tests
, &XVECEXP (newexp
, 0, 0), len
* sizeof (rtx
));
2014 XEXP (newexp
, 1) = new_defval
;
2019 /* Remove an insn entry from an attribute value. */
2022 remove_insn_ent (av
, ie
)
2023 struct attr_value
*av
;
2024 struct insn_ent
*ie
;
2026 struct insn_ent
*previe
;
2028 if (av
->first_insn
== ie
)
2029 av
->first_insn
= ie
->next
;
2032 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
2034 previe
->next
= ie
->next
;
2038 if (ie
->insn_code
== -1)
2039 av
->has_asm_insn
= 0;
2042 /* Insert an insn entry in an attribute value list. */
2045 insert_insn_ent (av
, ie
)
2046 struct attr_value
*av
;
2047 struct insn_ent
*ie
;
2049 ie
->next
= av
->first_insn
;
2050 av
->first_insn
= ie
;
2052 if (ie
->insn_code
== -1)
2053 av
->has_asm_insn
= 1;
2056 /* This is a utility routine to take an expression that is a tree of either
2057 AND or IOR expressions and insert a new term. The new term will be
2058 inserted at the right side of the first node whose code does not match
2059 the root. A new node will be created with the root's code. Its left
2060 side will be the old right side and its right side will be the new
2063 If the `term' is itself a tree, all its leaves will be inserted. */
2066 insert_right_side (code
, exp
, term
, insn_code
, insn_index
)
2070 int insn_code
, insn_index
;
2074 /* Avoid consing in some special cases. */
2075 if (code
== AND
&& term
== true_rtx
)
2077 if (code
== AND
&& term
== false_rtx
)
2079 if (code
== AND
&& exp
== true_rtx
)
2081 if (code
== AND
&& exp
== false_rtx
)
2083 if (code
== IOR
&& term
== true_rtx
)
2085 if (code
== IOR
&& term
== false_rtx
)
2087 if (code
== IOR
&& exp
== true_rtx
)
2089 if (code
== IOR
&& exp
== false_rtx
)
2091 if (attr_equal_p (exp
, term
))
2094 if (GET_CODE (term
) == code
)
2096 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
2097 insn_code
, insn_index
);
2098 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
2099 insn_code
, insn_index
);
2104 if (GET_CODE (exp
) == code
)
2106 rtx
new = insert_right_side (code
, XEXP (exp
, 1),
2107 term
, insn_code
, insn_index
);
2108 if (new != XEXP (exp
, 1))
2109 /* Make a copy of this expression and call recursively. */
2110 newexp
= attr_rtx (code
, XEXP (exp
, 0), new);
2116 /* Insert the new term. */
2117 newexp
= attr_rtx (code
, exp
, term
);
2120 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2123 /* If we have an expression which AND's a bunch of
2124 (not (eq_attrq "alternative" "n"))
2125 terms, we may have covered all or all but one of the possible alternatives.
2126 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
2128 This routine is passed an expression and either AND or IOR. It returns a
2129 bitmask indicating which alternatives are present.
2130 ??? What does "present" mean? */
2133 compute_alternative_mask (exp
, code
)
2138 if (GET_CODE (exp
) == code
)
2139 return compute_alternative_mask (XEXP (exp
, 0), code
)
2140 | compute_alternative_mask (XEXP (exp
, 1), code
);
2142 else if (code
== AND
&& GET_CODE (exp
) == NOT
2143 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2144 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
2145 string
= XSTR (XEXP (exp
, 0), 1);
2147 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
2148 && XSTR (exp
, 0) == alternative_name
)
2149 string
= XSTR (exp
, 1);
2155 return 1 << (string
[0] - '0');
2156 return 1 << atoi (string
);
2159 /* Given I, a single-bit mask, return RTX to compare the `alternative'
2160 attribute with the value represented by that bit. */
2163 make_alternative_compare (mask
)
2171 for (i
= 0; (mask
& (1 << i
)) == 0; i
++)
2174 newexp
= attr_rtx (EQ_ATTR
, alternative_name
, attr_numeral (i
));
2175 RTX_UNCHANGING_P (newexp
) = 1;
2180 /* If we are processing an (eq_attr "attr" "value") test, we find the value
2181 of "attr" for this insn code. From that value, we can compute a test
2182 showing when the EQ_ATTR will be true. This routine performs that
2183 computation. If a test condition involves an address, we leave the EQ_ATTR
2184 intact because addresses are only valid for the `length' attribute. */
2186 /* ??? Kenner, document the meanings of the arguments!!! */
2189 evaluate_eq_attr (exp
, value
, insn_code
, insn_index
)
2192 int insn_code
, insn_index
;
2199 if (GET_CODE (value
) == CONST_STRING
)
2201 if (! strcmp (XSTR (value
, 0), XSTR (exp
, 1)))
2206 else if (GET_CODE (value
) == COND
)
2208 /* We construct an IOR of all the cases for which the requested attribute
2209 value is present. Since we start with FALSE, if it is not present,
2210 FALSE will be returned.
2212 Each case is the AND of the NOT's of the previous conditions with the
2213 current condition; in the default case the current condition is TRUE.
2215 For each possible COND value, call ourselves recursively.
2217 The extra TRUE and FALSE expressions will be eliminated by another
2218 call to the simplification routine. */
2223 if (current_alternative_string
)
2224 clear_struct_flag (value
);
2226 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2228 rtx
this = SIMPLIFY_TEST_EXP (XVECEXP (value
, 0, i
),
2229 insn_code
, insn_index
);
2231 SIMPLIFY_ALTERNATIVE (this);
2233 right
= insert_right_side (AND
, andexp
, this,
2234 insn_code
, insn_index
);
2235 right
= insert_right_side (AND
, right
,
2236 evaluate_eq_attr (exp
, XVECEXP (value
, 0, i
+ 1),
2237 insn_code
, insn_index
),
2238 insn_code
, insn_index
);
2239 orexp
= insert_right_side (IOR
, orexp
, right
,
2240 insn_code
, insn_index
);
2242 /* Add this condition into the AND expression. */
2243 newexp
= attr_rtx (NOT
, this);
2244 andexp
= insert_right_side (AND
, andexp
, newexp
,
2245 insn_code
, insn_index
);
2248 /* Handle the default case. */
2249 right
= insert_right_side (AND
, andexp
,
2250 evaluate_eq_attr (exp
, XEXP (value
, 1),
2251 insn_code
, insn_index
),
2252 insn_code
, insn_index
);
2253 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2258 /* If uses an address, must return original expression. But set the
2259 RTX_UNCHANGING_P bit so we don't try to simplify it again. */
2262 walk_attr_value (newexp
);
2266 if (! RTX_UNCHANGING_P (exp
) && current_alternative_string
)
2267 return copy_rtx_unchanging (exp
);
2274 /* This routine is called when an AND of a term with a tree of AND's is
2275 encountered. If the term or its complement is present in the tree, it
2276 can be replaced with TRUE or FALSE, respectively.
2278 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2279 be true and hence are complementary.
2281 There is one special case: If we see
2282 (and (not (eq_attr "att" "v1"))
2283 (eq_attr "att" "v2"))
2284 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2285 replace the term, not anything in the AND tree. So we pass a pointer to
2289 simplify_and_tree (exp
, pterm
, insn_code
, insn_index
)
2292 int insn_code
, insn_index
;
2297 int left_eliminates_term
, right_eliminates_term
;
2299 if (GET_CODE (exp
) == AND
)
2301 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2302 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2303 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2305 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2307 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2311 else if (GET_CODE (exp
) == IOR
)
2313 /* For the IOR case, we do the same as above, except that we can
2314 only eliminate `term' if both sides of the IOR would do so. */
2316 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2317 left_eliminates_term
= (temp
== true_rtx
);
2320 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2321 right_eliminates_term
= (temp
== true_rtx
);
2323 if (left_eliminates_term
&& right_eliminates_term
)
2326 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2328 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2330 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2334 /* Check for simplifications. Do some extra checking here since this
2335 routine is called so many times. */
2340 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
2343 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
2346 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
2348 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
2351 if (! strcmp (XSTR (exp
, 1), XSTR (*pterm
, 1)))
2357 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2358 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
2360 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
2363 if (! strcmp (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
2369 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2370 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
2372 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
2375 if (! strcmp (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
2381 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
2383 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
2387 else if (GET_CODE (exp
) == NOT
)
2389 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
2393 else if (GET_CODE (*pterm
) == NOT
)
2395 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
2399 else if (attr_equal_p (exp
, *pterm
))
2405 /* Similar to `simplify_and_tree', but for IOR trees. */
2408 simplify_or_tree (exp
, pterm
, insn_code
, insn_index
)
2411 int insn_code
, insn_index
;
2416 int left_eliminates_term
, right_eliminates_term
;
2418 if (GET_CODE (exp
) == IOR
)
2420 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2421 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2422 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2424 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2426 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2430 else if (GET_CODE (exp
) == AND
)
2432 /* For the AND case, we do the same as above, except that we can
2433 only eliminate `term' if both sides of the AND would do so. */
2435 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2436 left_eliminates_term
= (temp
== false_rtx
);
2439 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2440 right_eliminates_term
= (temp
== false_rtx
);
2442 if (left_eliminates_term
&& right_eliminates_term
)
2445 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2447 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2449 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2453 if (attr_equal_p (exp
, *pterm
))
2456 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
2459 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
2462 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2463 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2464 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
2467 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2468 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
2469 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
2475 /* Given an expression, see if it can be simplified for a particular insn
2476 code based on the values of other attributes being tested. This can
2477 eliminate nested get_attr_... calls.
2479 Note that if an endless recursion is specified in the patterns, the
2480 optimization will loop. However, it will do so in precisely the cases where
2481 an infinite recursion loop could occur during compilation. It's better that
2485 simplify_test_exp (exp
, insn_code
, insn_index
)
2487 int insn_code
, insn_index
;
2490 struct attr_desc
*attr
;
2491 struct attr_value
*av
;
2492 struct insn_ent
*ie
;
2495 char *spacer
= (char *) obstack_finish (rtl_obstack
);
2497 static rtx loser
= 0;
2498 static int count
= 0;
2499 static stopcount
= 0;
2504 if (count
== stopcount
)
2507 /* Don't re-simplify something we already simplified. */
2508 if (RTX_UNCHANGING_P (exp
) || MEM_IN_STRUCT_P (exp
))
2511 switch (GET_CODE (exp
))
2514 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2515 SIMPLIFY_ALTERNATIVE (left
);
2516 if (left
== false_rtx
)
2518 obstack_free (rtl_obstack
, spacer
);
2521 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2522 SIMPLIFY_ALTERNATIVE (right
);
2523 if (left
== false_rtx
)
2525 obstack_free (rtl_obstack
, spacer
);
2529 /* If either side is an IOR and we have (eq_attr "alternative" ..")
2530 present on both sides, apply the distributive law since this will
2531 yield simplifications. */
2532 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
2533 && compute_alternative_mask (left
, IOR
)
2534 && compute_alternative_mask (right
, IOR
))
2536 if (GET_CODE (left
) == IOR
)
2543 newexp
= attr_rtx (IOR
,
2544 attr_rtx (AND
, left
, XEXP (right
, 0)),
2545 attr_rtx (AND
, left
, XEXP (right
, 1)));
2547 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2550 /* Try with the term on both sides. */
2551 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
2552 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2553 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
2555 if (left
== false_rtx
|| right
== false_rtx
)
2557 obstack_free (rtl_obstack
, spacer
);
2560 else if (left
== true_rtx
)
2564 else if (right
== true_rtx
)
2568 /* See if all or all but one of the insn's alternatives are specified
2569 in this tree. Optimize if so. */
2571 else if (insn_code
>= 0
2572 && (GET_CODE (left
) == AND
2573 || (GET_CODE (left
) == NOT
2574 && GET_CODE (XEXP (left
, 0)) == EQ_ATTR
2575 && XSTR (XEXP (left
, 0), 0) == alternative_name
)
2576 || GET_CODE (right
) == AND
2577 || (GET_CODE (right
) == NOT
2578 && GET_CODE (XEXP (right
, 0)) == EQ_ATTR
2579 && XSTR (XEXP (right
, 0), 0) == alternative_name
)))
2581 i
= compute_alternative_mask (exp
, AND
);
2582 if (i
& ~insn_alternatives
[insn_code
])
2583 fatal ("Illegal alternative specified for pattern number %d",
2586 /* If all alternatives are excluded, this is false. */
2587 i
^= insn_alternatives
[insn_code
];
2590 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2592 /* If just one excluded, AND a comparison with that one to the
2593 front of the tree. The others will be eliminated by
2594 optimization. We do not want to do this if the insn has one
2595 alternative and we have tested none of them! */
2596 left
= make_alternative_compare (i
);
2597 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2598 newexp
= attr_rtx (AND
, left
, right
);
2600 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2604 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2606 newexp
= attr_rtx (AND
, left
, right
);
2607 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2612 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2613 SIMPLIFY_ALTERNATIVE (left
);
2614 if (left
== true_rtx
)
2616 obstack_free (rtl_obstack
, spacer
);
2619 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
2620 SIMPLIFY_ALTERNATIVE (right
);
2621 if (right
== true_rtx
)
2623 obstack_free (rtl_obstack
, spacer
);
2627 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
2628 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
2629 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
2631 if (right
== true_rtx
|| left
== true_rtx
)
2633 obstack_free (rtl_obstack
, spacer
);
2636 else if (left
== false_rtx
)
2640 else if (right
== false_rtx
)
2645 /* Test for simple cases where the distributive law is useful. I.e.,
2646 convert (ior (and (x) (y))
2652 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
2653 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
2655 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
2657 left
= XEXP (left
, 0);
2659 newexp
= attr_rtx (AND
, left
, right
);
2660 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2663 /* See if all or all but one of the insn's alternatives are specified
2664 in this tree. Optimize if so. */
2666 else if (insn_code
>= 0
2667 && (GET_CODE (left
) == IOR
2668 || (GET_CODE (left
) == EQ_ATTR
2669 && XSTR (left
, 0) == alternative_name
)
2670 || GET_CODE (right
) == IOR
2671 || (GET_CODE (right
) == EQ_ATTR
2672 && XSTR (right
, 0) == alternative_name
)))
2674 i
= compute_alternative_mask (exp
, IOR
);
2675 if (i
& ~insn_alternatives
[insn_code
])
2676 fatal ("Illegal alternative specified for pattern number %d",
2679 /* If all alternatives are included, this is true. */
2680 i
^= insn_alternatives
[insn_code
];
2683 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
2685 /* If just one excluded, IOR a comparison with that one to the
2686 front of the tree. The others will be eliminated by
2687 optimization. We do not want to do this if the insn has one
2688 alternative and we have tested none of them! */
2689 left
= make_alternative_compare (i
);
2690 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
2691 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
2693 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2697 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2699 newexp
= attr_rtx (IOR
, left
, right
);
2700 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2705 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
2707 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
2708 insn_code
, insn_index
);
2709 SIMPLIFY_ALTERNATIVE (left
);
2713 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
2714 SIMPLIFY_ALTERNATIVE (left
);
2715 if (GET_CODE (left
) == NOT
)
2716 return XEXP (left
, 0);
2718 if (left
== false_rtx
)
2720 obstack_free (rtl_obstack
, spacer
);
2723 else if (left
== true_rtx
)
2725 obstack_free (rtl_obstack
, spacer
);
2729 /* Try to apply De`Morgan's laws. */
2730 else if (GET_CODE (left
) == IOR
)
2732 newexp
= attr_rtx (AND
,
2733 attr_rtx (NOT
, XEXP (left
, 0)),
2734 attr_rtx (NOT
, XEXP (left
, 1)));
2736 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2738 else if (GET_CODE (left
) == AND
)
2740 newexp
= attr_rtx (IOR
,
2741 attr_rtx (NOT
, XEXP (left
, 0)),
2742 attr_rtx (NOT
, XEXP (left
, 1)));
2744 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2746 else if (left
!= XEXP (exp
, 0))
2748 newexp
= attr_rtx (NOT
, left
);
2753 if (current_alternative_string
&& XSTR (exp
, 0) == alternative_name
)
2754 return (XSTR (exp
, 1) == current_alternative_string
2755 ? true_rtx
: false_rtx
);
2757 /* Look at the value for this insn code in the specified attribute.
2758 We normally can replace this comparison with the condition that
2759 would give this insn the values being tested for. */
2760 if (XSTR (exp
, 0) != alternative_name
2761 && (attr
= find_attr (XSTR (exp
, 0), 0)) != NULL
)
2762 for (av
= attr
->first_value
; av
; av
= av
->next
)
2763 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2764 if (ie
->insn_code
== insn_code
)
2765 return evaluate_eq_attr (exp
, av
->value
, insn_code
, insn_index
);
2768 /* We have already simplified this expression. Simplifying it again
2769 won't buy anything unless we weren't given a valid insn code
2770 to process (i.e., we are canonicalizing something.). */
2771 if (insn_code
!= -2 && current_alternative_string
2772 && ! RTX_UNCHANGING_P (newexp
))
2773 return copy_rtx_unchanging (newexp
);
2781 /* Optimize the attribute lists by seeing if we can determine conditional
2782 values from the known values of other attributes. This will save subroutine
2783 calls during the compilation. */
2788 struct attr_desc
*attr
;
2789 struct attr_value
*av
;
2790 struct insn_ent
*ie
, *nextie
;
2792 int something_changed
= 1;
2794 struct attr_value_list
{ struct attr_value
*av
;
2795 struct insn_ent
*ie
;
2796 struct attr_desc
* attr
;
2797 struct attr_value_list
*next
; };
2798 struct attr_value_list
**insn_code_values
;
2799 struct attr_value_list
*iv
;
2801 /* For each insn code, make a list of all the insn_ent's for it,
2802 for all values for all attributes. */
2804 /* Make 2 extra elements, for "code" values -2 and -1. */
2806 = (struct attr_value_list
**) alloca ((insn_code_number
+ 2)
2807 * sizeof (struct attr_value_list
*));
2808 bzero (insn_code_values
,
2809 (insn_code_number
+ 2) * sizeof (struct attr_value_list
*));
2810 /* Offset the table address so we can index by -2 or -1. */
2811 insn_code_values
+= 2;
2813 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
2814 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
2815 for (av
= attr
->first_value
; av
; av
= av
->next
)
2816 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2818 iv
= ((struct attr_value_list
*)
2819 alloca (sizeof (struct attr_value_list
)));
2823 iv
->next
= insn_code_values
[ie
->insn_code
];
2824 insn_code_values
[ie
->insn_code
] = iv
;
2827 /* Process one insn code at a time. */
2828 for (i
= -2; i
< insn_code_number
; i
++)
2830 /* Clear the MEM_IN_STRUCT_P flag everywhere relevant.
2831 We use it to mean "already simplified for this insn". */
2832 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
2833 clear_struct_flag (iv
->av
->value
);
2835 /* Loop until nothing changes for one iteration. */
2836 something_changed
= 1;
2837 while (something_changed
)
2839 something_changed
= 0;
2840 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
2842 struct obstack
*old
= rtl_obstack
;
2843 char *spacer
= (char *) obstack_finish (temp_obstack
);
2848 if (GET_CODE (av
->value
) != COND
)
2851 rtl_obstack
= temp_obstack
;
2852 #if 0 /* This was intended as a speed up, but it was slower. */
2853 if (insn_n_alternatives
[ie
->insn_code
] > 6
2854 && count_sub_rtxs (av
->value
, 200) >= 200)
2855 newexp
= simplify_by_alternatives (av
->value
, ie
->insn_code
,
2859 newexp
= simplify_cond (av
->value
, ie
->insn_code
,
2863 if (newexp
!= av
->value
)
2865 newexp
= attr_copy_rtx (newexp
);
2866 remove_insn_ent (av
, ie
);
2867 av
= get_attr_value (newexp
, attr
, ie
->insn_code
);
2869 insert_insn_ent (av
, ie
);
2870 something_changed
= 1;
2872 obstack_free (temp_obstack
, spacer
);
2879 simplify_by_alternatives (exp
, insn_code
, insn_index
)
2881 int insn_code
, insn_index
;
2884 int len
= insn_n_alternatives
[insn_code
];
2885 rtx newexp
= rtx_alloc (COND
);
2889 XVEC (newexp
, 0) = rtvec_alloc (len
* 2);
2891 /* It will not matter what value we use as the default value
2892 of the new COND, since that default will never be used.
2893 Choose something of the right type. */
2894 for (ultimate
= exp
; GET_CODE (ultimate
) == COND
;)
2895 ultimate
= XEXP (ultimate
, 1);
2896 XEXP (newexp
, 1) = ultimate
;
2898 for (i
= 0; i
< insn_n_alternatives
[insn_code
]; i
++)
2900 current_alternative_string
= attr_numeral (i
);
2901 XVECEXP (newexp
, 0, i
* 2) = make_alternative_compare (1 << i
);
2902 XVECEXP (newexp
, 0, i
* 2 + 1)
2903 = simplify_cond (exp
, insn_code
, insn_index
);
2906 current_alternative_string
= 0;
2907 return simplify_cond (newexp
, insn_code
, insn_index
);
2910 /* Clear the MEM_IN_STRUCT_P flag in EXP and its subexpressions. */
2912 clear_struct_flag (x
)
2917 register enum rtx_code code
;
2920 MEM_IN_STRUCT_P (x
) = 0;
2921 if (RTX_UNCHANGING_P (x
))
2924 code
= GET_CODE (x
);
2940 /* Compare the elements. If any pair of corresponding elements
2941 fail to match, return 0 for the whole things. */
2943 fmt
= GET_RTX_FORMAT (code
);
2944 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2950 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2951 clear_struct_flag (XVECEXP (x
, i
, j
));
2955 clear_struct_flag (XEXP (x
, i
));
2961 /* Return the number of RTX objects making up the expression X.
2962 But if we count more more than MAX objects, stop counting. */
2964 count_sub_rtxs (x
, max
)
2970 register enum rtx_code code
;
2974 code
= GET_CODE (x
);
2990 /* Compare the elements. If any pair of corresponding elements
2991 fail to match, return 0 for the whole things. */
2993 fmt
= GET_RTX_FORMAT (code
);
2994 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3003 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3004 total
+= count_sub_rtxs (XVECEXP (x
, i
, j
), max
);
3008 total
+= count_sub_rtxs (XEXP (x
, i
), max
);
3016 /* Create table entries for DEFINE_ATTR. */
3022 struct attr_desc
*attr
;
3023 struct attr_value
*av
;
3027 /* Make a new attribute structure. Check for duplicate by looking at
3028 attr->default_val, since it is initialized by this routine. */
3029 attr
= find_attr (XSTR (exp
, 0), 1);
3030 if (attr
->default_val
)
3031 fatal ("Duplicate definition for `%s' attribute", attr
->name
);
3033 if (*XSTR (exp
, 1) == '\0')
3034 attr
->is_numeric
= 1;
3037 name_ptr
= XSTR (exp
, 1);
3038 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
3040 av
= (struct attr_value
*) xmalloc (sizeof (struct attr_value
));
3041 av
->value
= attr_rtx (CONST_STRING
, p
);
3042 av
->next
= attr
->first_value
;
3043 attr
->first_value
= av
;
3044 av
->first_insn
= NULL
;
3046 av
->has_asm_insn
= 0;
3050 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
3053 if (attr
->is_numeric
)
3054 fatal ("Constant attributes may not take numeric values");
3055 /* Get rid of the CONST node. It is allowed only at top-level. */
3056 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
3059 if (! strcmp (attr
->name
, "length") && ! attr
->is_numeric
)
3060 fatal ("`length' attribute must take numeric values");
3062 /* Set up the default value. */
3063 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
3064 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
3067 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
3068 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
3069 number of alternatives as this should be checked elsewhere. */
3072 count_alternatives (exp
)
3078 if (GET_CODE (exp
) == MATCH_OPERAND
)
3079 return n_comma_elts (XSTR (exp
, 2));
3081 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3082 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3087 n
= count_alternatives (XEXP (exp
, i
));
3094 if (XVEC (exp
, i
) != NULL
)
3095 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3097 n
= count_alternatives (XVECEXP (exp
, i
, j
));
3106 /* Returns non-zero if the given expression contains an EQ_ATTR with the
3107 `alternative' attribute. */
3110 compares_alternatives_p (exp
)
3116 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
3119 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3120 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3125 if (compares_alternatives_p (XEXP (exp
, i
)))
3130 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3131 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
3139 /* Returns non-zero is INNER is contained in EXP. */
3142 contained_in_p (inner
, exp
)
3149 if (rtx_equal_p (inner
, exp
))
3152 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
3153 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
3158 if (contained_in_p (inner
, XEXP (exp
, i
)))
3163 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3164 if (contained_in_p (inner
, XVECEXP (exp
, i
, j
)))
3172 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
3178 struct insn_def
*id
;
3180 id
= (struct insn_def
*) xmalloc (sizeof (struct insn_def
));
3185 switch (GET_CODE (exp
))
3188 id
->insn_code
= insn_code_number
++;
3189 id
->insn_index
= insn_index_number
++;
3190 id
->num_alternatives
= count_alternatives (exp
);
3191 if (id
->num_alternatives
== 0)
3192 id
->num_alternatives
= 1;
3196 case DEFINE_PEEPHOLE
:
3197 id
->insn_code
= insn_code_number
++;
3198 id
->insn_index
= insn_index_number
++;
3199 id
->num_alternatives
= count_alternatives (exp
);
3200 if (id
->num_alternatives
== 0)
3201 id
->num_alternatives
= 1;
3205 case DEFINE_ASM_ATTRIBUTES
:
3207 id
->insn_index
= -1;
3208 id
->num_alternatives
= 1;
3210 got_define_asm_attributes
= 1;
3215 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
3216 true or annul false is specified, and make a `struct delay_desc'. */
3222 struct delay_desc
*delay
;
3225 if (XVECLEN (def
, 1) % 3 != 0)
3226 fatal ("Number of elements in DEFINE_DELAY must be multiple of three.");
3228 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
3230 if (XVECEXP (def
, 1, i
+ 1))
3231 have_annul_true
= 1;
3232 if (XVECEXP (def
, 1, i
+ 2))
3233 have_annul_false
= 1;
3236 delay
= (struct delay_desc
*) xmalloc (sizeof (struct delay_desc
));
3238 delay
->num
= ++num_delays
;
3239 delay
->next
= delays
;
3243 /* Process a DEFINE_FUNCTION_UNIT.
3245 This gives information about a function unit contained in the CPU.
3246 We fill in a `struct function_unit_op' and a `struct function_unit'
3247 with information used later by `expand_unit'. */
3253 struct function_unit
*unit
;
3254 struct function_unit_op
*op
;
3256 /* See if we have already seen this function unit. If so, check that
3257 the multiplicity and simultaneity values are the same. If not, make
3258 a structure for this function unit. */
3259 for (unit
= units
; unit
; unit
= unit
->next
)
3260 if (! strcmp (unit
->name
, XSTR (def
, 0)))
3262 if (unit
->multiplicity
!= XINT (def
, 1)
3263 || unit
->simultaneity
!= XINT (def
, 2))
3264 fatal ("Differing specifications given for `%s' function unit.",
3271 unit
= (struct function_unit
*) xmalloc (sizeof (struct function_unit
));
3272 unit
->name
= XSTR (def
, 0);
3273 unit
->multiplicity
= XINT (def
, 1);
3274 unit
->simultaneity
= XINT (def
, 2);
3275 unit
->num
= num_units
++;
3276 unit
->num_opclasses
= 0;
3277 unit
->condexp
= false_rtx
;
3283 /* Make a new operation class structure entry and initialize it. */
3284 op
= (struct function_unit_op
*) xmalloc (sizeof (struct function_unit_op
));
3285 op
->condexp
= XEXP (def
, 3);
3286 op
->num
= unit
->num_opclasses
++;
3287 op
->ready
= XINT (def
, 4);
3288 op
->next
= unit
->ops
;
3291 /* Set our busy expression based on whether or not an optional conflict
3292 vector was specified. */
3295 /* Compute the IOR of all the specified expressions. */
3296 rtx orexp
= false_rtx
;
3299 for (i
= 0; i
< XVECLEN (def
, 6); i
++)
3300 orexp
= insert_right_side (IOR
, orexp
, XVECEXP (def
, 6, i
), -2);
3302 op
->busyexp
= attr_rtx (IF_THEN_ELSE
, orexp
,
3303 make_numeric_value (XINT (def
, 5)),
3304 make_numeric_value (0));
3307 op
->busyexp
= make_numeric_value (XINT (def
, 5));
3309 /* Merge our conditional into that of the function unit so we can determine
3310 which insns are used by the function unit. */
3311 unit
->condexp
= insert_right_side (IOR
, unit
->condexp
, op
->condexp
, -2);
3314 /* Given a piece of RTX, print a C expression to test it's truth value.
3315 We use AND and IOR both for logical and bit-wise operations, so
3316 interpret them as logical unless they are inside a comparison expression.
3317 The second operand of this function will be non-zero in that case. */
3320 write_test_expr (exp
, in_comparison
)
3324 int comparison_operator
= 0;
3326 struct attr_desc
*attr
;
3328 /* In order not to worry about operator precedence, surround our part of
3329 the expression with parentheses. */
3332 code
= GET_CODE (exp
);
3335 /* Binary operators. */
3337 case GE
: case GT
: case GEU
: case GTU
:
3338 case LE
: case LT
: case LEU
: case LTU
:
3339 comparison_operator
= 1;
3341 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
3342 case AND
: case IOR
: case XOR
:
3343 case LSHIFT
: case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
3344 write_test_expr (XEXP (exp
, 0), in_comparison
|| comparison_operator
);
3360 printf (" >= (unsigned) ");
3363 printf (" > (unsigned) ");
3372 printf (" <= (unsigned) ");
3375 printf (" < (unsigned) ");
3417 write_test_expr (XEXP (exp
, 1), in_comparison
|| comparison_operator
);
3421 /* Special-case (not (eq_attrq "alternative" "x")) */
3422 if (! in_comparison
&& GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3423 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
3425 printf ("which_alternative != %s", XSTR (XEXP (exp
, 0), 1));
3429 /* Otherwise, fall through to normal unary operator. */
3431 /* Unary operators. */
3449 write_test_expr (XEXP (exp
, 0), in_comparison
);
3452 /* Comparison test of an attribute with a value. Most of these will
3453 have been removed by optimization. Handle "alternative"
3454 specially and give error if EQ_ATTR present inside a comparison. */
3457 fatal ("EQ_ATTR not valid inside comparison");
3459 if (XSTR (exp
, 0) == alternative_name
)
3461 printf ("which_alternative == %s", XSTR (exp
, 1));
3465 attr
= find_attr (XSTR (exp
, 0), 0);
3466 if (! attr
) abort ();
3468 /* Now is the time to expand the value of a constant attribute. */
3471 write_test_expr (evaluate_eq_attr (exp
, attr
->default_val
->value
,
3477 printf ("get_attr_%s (insn) == ", attr
->name
);
3478 write_attr_valueq (attr
, XSTR (exp
, 1));
3482 /* See if an operand matches a predicate. */
3484 /* If only a mode is given, just ensure the mode matches the operand.
3485 If neither a mode nor predicate is given, error. */
3486 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
3488 if (GET_MODE (exp
) == VOIDmode
)
3489 fatal ("Null MATCH_OPERAND specified as test");
3491 printf ("GET_MODE (operands[%d]) == %smode",
3492 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3495 printf ("%s (operands[%d], %smode)",
3496 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
3499 /* Constant integer. */
3501 printf ("%d", XINT (exp
, 0));
3504 /* A random C expression. */
3506 printf ("%s", XSTR (exp
, 0));
3509 /* The address of the branch target. */
3511 printf ("insn_addresses[INSN_UID (JUMP_LABEL (insn))]");
3514 /* The address of the current insn. It would be more consistent with
3515 other usage to make this the address of the NEXT insn, but this gets
3516 too confusing because of the ambiguity regarding the length of the
3519 printf ("insn_current_address");
3523 fatal ("bad RTX code `%s' in attribute calculation\n",
3524 GET_RTX_NAME (code
));
3530 /* Given an attribute value, return the maximum CONST_STRING argument
3531 encountered. It is assumed that they are all numeric. */
3534 max_attr_value (exp
)
3537 int current_max
= 0;
3541 if (GET_CODE (exp
) == CONST_STRING
)
3542 return atoi (XSTR (exp
, 0));
3544 else if (GET_CODE (exp
) == COND
)
3546 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3548 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1));
3549 if (n
> current_max
)
3553 n
= max_attr_value (XEXP (exp
, 1));
3554 if (n
> current_max
)
3564 /* Scan an attribute value, possibly a conditional, and record what actions
3565 will be required to do any conditional tests in it.
3568 `must_extract' if we need to extract the insn operands
3569 `must_constrain' if we must compute `which_alternative'
3570 `address_used' if an address expression was used
3574 walk_attr_value (exp
)
3584 code
= GET_CODE (exp
);
3588 if (! RTX_UNCHANGING_P (exp
))
3589 /* Since this is an arbitrary expression, it can look at anything.
3590 However, constant expressions do not depend on any particular
3592 must_extract
= must_constrain
= 1;
3600 if (XSTR (exp
, 0) == alternative_name
)
3601 must_extract
= must_constrain
= 1;
3610 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
3615 walk_attr_value (XEXP (exp
, i
));
3619 if (XVEC (exp
, i
) != NULL
)
3620 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
3621 walk_attr_value (XVECEXP (exp
, i
, j
));
3626 /* Write out a function to obtain the attribute for a given INSN. */
3629 write_attr_get (attr
)
3630 struct attr_desc
*attr
;
3632 struct attr_value
*av
, *common_av
;
3634 /* Find the most used attribute value. Handle that as the `default' of the
3635 switch we will generate. */
3636 common_av
= find_most_used (attr
);
3638 /* Write out start of function, then all values with explicit `case' lines,
3639 then a `default', then the value with the most uses. */
3640 if (attr
->is_numeric
)
3643 printf ("enum attr_%s\n", attr
->name
);
3645 /* If the attribute name starts with a star, the remainder is the name of
3646 the subroutine to use, instead of `get_attr_...'. */
3647 if (attr
->name
[0] == '*')
3648 printf ("%s (insn)\n", &attr
->name
[1]);
3649 else if (attr
->is_const
== 0)
3650 printf ("get_attr_%s (insn)\n", attr
->name
);
3653 printf ("get_attr_%s ()\n", attr
->name
);
3656 for (av
= attr
->first_value
; av
; av
= av
->next
)
3657 if (av
->num_insns
!= 0)
3658 write_attr_set (attr
, 2, av
->value
, "return", ";",
3659 true_rtx
, av
->first_insn
->insn_code
,
3660 av
->first_insn
->insn_index
);
3665 printf (" rtx insn;\n");
3667 printf (" switch (recog_memoized (insn))\n");
3670 for (av
= attr
->first_value
; av
; av
= av
->next
)
3671 if (av
!= common_av
)
3672 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
3674 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
3675 printf (" }\n}\n\n");
3678 /* Given an AND tree of known true terms (because we are inside an `if' with
3679 that as the condition or are in an `else' clause) and an expression,
3680 replace any known true terms with TRUE. Use `simplify_and_tree' to do
3681 the bulk of the work. */
3684 eliminate_known_true (known_true
, exp
, insn_code
, insn_index
)
3687 int insn_code
, insn_index
;
3691 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
3693 if (GET_CODE (known_true
) == AND
)
3695 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
3696 insn_code
, insn_index
);
3697 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
3698 insn_code
, insn_index
);
3703 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
3709 /* Write out a series of tests and assignment statements to perform tests and
3710 sets of an attribute value. We are passed an indentation amount and prefix
3711 and suffix strings to write around each attribute value (e.g., "return"
3715 write_attr_set (attr
, indent
, value
, prefix
, suffix
, known_true
,
3716 insn_code
, insn_index
)
3717 struct attr_desc
*attr
;
3723 int insn_code
, insn_index
;
3725 if (GET_CODE (value
) == CONST_STRING
)
3727 write_indent (indent
);
3728 printf ("%s ", prefix
);
3729 write_attr_value (attr
, value
);
3730 printf ("%s\n", suffix
);
3732 else if (GET_CODE (value
) == COND
)
3734 /* Assume the default value will be the default of the COND unless we
3735 find an always true expression. */
3736 rtx default_val
= XEXP (value
, 1);
3737 rtx our_known_true
= known_true
;
3742 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
3747 testexp
= eliminate_known_true (our_known_true
,
3748 XVECEXP (value
, 0, i
),
3749 insn_code
, insn_index
);
3750 newexp
= attr_rtx (NOT
, testexp
);
3751 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
3752 insn_code
, insn_index
);
3754 /* If the test expression is always true or if the next `known_true'
3755 expression is always false, this is the last case, so break
3756 out and let this value be the `else' case. */
3757 if (testexp
== true_rtx
|| newexp
== false_rtx
)
3759 default_val
= XVECEXP (value
, 0, i
+ 1);
3763 /* Compute the expression to pass to our recursive call as being
3765 inner_true
= insert_right_side (AND
, our_known_true
,
3766 testexp
, insn_code
, insn_index
);
3768 /* If this is always false, skip it. */
3769 if (inner_true
== false_rtx
)
3772 write_indent (indent
);
3773 printf ("%sif ", first_if
? "" : "else ");
3775 write_test_expr (testexp
, 0);
3777 write_indent (indent
+ 2);
3780 write_attr_set (attr
, indent
+ 4,
3781 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
3782 inner_true
, insn_code
, insn_index
);
3783 write_indent (indent
+ 2);
3785 our_known_true
= newexp
;
3790 write_indent (indent
);
3792 write_indent (indent
+ 2);
3796 write_attr_set (attr
, first_if
? indent
: indent
+ 4, default_val
,
3797 prefix
, suffix
, our_known_true
, insn_code
, insn_index
);
3801 write_indent (indent
+ 2);
3809 /* Write out the computation for one attribute value. */
3812 write_attr_case (attr
, av
, write_case_lines
, prefix
, suffix
, indent
, known_true
)
3813 struct attr_desc
*attr
;
3814 struct attr_value
*av
;
3815 int write_case_lines
;
3816 char *prefix
, *suffix
;
3820 struct insn_ent
*ie
;
3822 if (av
->num_insns
== 0)
3825 if (av
->has_asm_insn
)
3827 write_indent (indent
);
3828 printf ("case -1:\n");
3829 write_indent (indent
+ 2);
3830 printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
3831 write_indent (indent
+ 2);
3832 printf (" && asm_noperands (PATTERN (insn)) < 0)\n");
3833 write_indent (indent
+ 2);
3834 printf (" fatal_insn_not_found (insn);\n");
3837 if (write_case_lines
)
3839 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3840 if (ie
->insn_code
!= -1)
3842 write_indent (indent
);
3843 printf ("case %d:\n", ie
->insn_code
);
3848 write_indent (indent
);
3849 printf ("default:\n");
3852 /* See what we have to do to handle output this value. */
3853 must_extract
= must_constrain
= address_used
= 0;
3854 walk_attr_value (av
->value
);
3858 write_indent (indent
+ 2);
3859 printf ("insn_extract (insn);\n");
3864 #ifdef REGISTER_CONSTRAINTS
3865 write_indent (indent
+ 2);
3866 printf ("if (! constrain_operands (INSN_CODE (insn), reload_completed))\n");
3867 write_indent (indent
+ 2);
3868 printf (" fatal_insn_not_found (insn);\n");
3872 write_attr_set (attr
, indent
+ 2, av
->value
, prefix
, suffix
,
3873 known_true
, av
->first_insn
->insn_code
,
3874 av
->first_insn
->insn_index
);
3876 if (strncmp (prefix
, "return", 6))
3878 write_indent (indent
+ 2);
3879 printf ("break;\n");
3884 /* Utilities to write names in various forms. */
3887 write_attr_valueq (attr
, s
)
3888 struct attr_desc
*attr
;
3891 if (attr
->is_numeric
)
3895 write_upcase (attr
->name
);
3902 write_attr_value (attr
, value
)
3903 struct attr_desc
*attr
;
3906 if (GET_CODE (value
) != CONST_STRING
)
3909 write_attr_valueq (attr
, XSTR (value
, 0));
3917 if (*str
< 'a' || *str
> 'z')
3918 printf ("%c", *str
++);
3920 printf ("%c", *str
++ - 'a' + 'A');
3924 write_indent (indent
)
3927 for (; indent
> 8; indent
-= 8)
3930 for (; indent
; indent
--)
3934 /* Write a subroutine that is given an insn that requires a delay slot, a
3935 delay slot ordinal, and a candidate insn. It returns non-zero if the
3936 candidate can be placed in the specified delay slot of the insn.
3938 We can write as many as three subroutines. `eligible_for_delay'
3939 handles normal delay slots, `eligible_for_annul_true' indicates that
3940 the specified insn can be annulled if the branch is true, and likewise
3941 for `eligible_for_annul_false'.
3943 KIND is a string distinguishing these three cases ("delay", "annul_true",
3944 or "annul_false"). */
3947 write_eligible_delay (kind
)
3950 struct delay_desc
*delay
;
3953 struct attr_desc
*attr
;
3954 struct attr_value
*av
, *common_av
;
3957 /* Compute the maximum number of delay slots required. We use the delay
3958 ordinal times this number plus one, plus the slot number as an index into
3959 the appropriate predicate to test. */
3961 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
3962 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
3963 max_slots
= XVECLEN (delay
->def
, 1) / 3;
3965 /* Write function prelude. */
3968 printf ("eligible_for_%s (delay_insn, slot, candidate_insn)\n", kind
);
3969 printf (" rtx delay_insn;\n");
3970 printf (" int slot;\n");
3971 printf (" rtx candidate_insn;\n");
3973 printf (" rtx insn;\n");
3975 printf (" if (slot >= %d)\n", max_slots
);
3976 printf (" abort ();\n");
3979 /* If more than one delay type, find out which type the delay insn is. */
3983 attr
= find_attr ("*delay_type", 0);
3984 if (! attr
) abort ();
3985 common_av
= find_most_used (attr
);
3987 printf (" insn = delay_insn;\n");
3988 printf (" switch (recog_memoized (insn))\n");
3991 sprintf (str
, " * %d;\n break;", max_slots
);
3992 for (av
= attr
->first_value
; av
; av
= av
->next
)
3993 if (av
!= common_av
)
3994 write_attr_case (attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
3996 write_attr_case (attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
3999 /* Ensure matched. Otherwise, shouldn't have been called. */
4000 printf (" if (slot < %d)\n", max_slots
);
4001 printf (" abort ();\n\n");
4004 /* If just one type of delay slot, write simple switch. */
4005 if (num_delays
== 1 && max_slots
== 1)
4007 printf (" insn = candidate_insn;\n");
4008 printf (" switch (recog_memoized (insn))\n");
4011 attr
= find_attr ("*delay_1_0", 0);
4012 if (! attr
) abort ();
4013 common_av
= find_most_used (attr
);
4015 for (av
= attr
->first_value
; av
; av
= av
->next
)
4016 if (av
!= common_av
)
4017 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
4019 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4025 /* Write a nested CASE. The first indicates which condition we need to
4026 test, and the inner CASE tests the condition. */
4027 printf (" insn = candidate_insn;\n");
4028 printf (" switch (slot)\n");
4031 for (delay
= delays
; delay
; delay
= delay
->next
)
4032 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
4034 printf (" case %d:\n",
4035 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
4036 printf (" switch (recog_memoized (insn))\n");
4039 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
4040 attr
= find_attr (str
, 0);
4041 if (! attr
) abort ();
4042 common_av
= find_most_used (attr
);
4044 for (av
= attr
->first_value
; av
; av
= av
->next
)
4045 if (av
!= common_av
)
4046 write_attr_case (attr
, av
, 1, "return", ";", 8, true_rtx
);
4048 write_attr_case (attr
, common_av
, 0, "return", ";", 8, true_rtx
);
4052 printf (" default:\n");
4053 printf (" abort ();\n");
4060 /* Write routines to compute conflict cost for function units. Then write a
4061 table describing the available function units. */
4064 write_function_unit_info ()
4066 struct function_unit
*unit
;
4067 struct attr_desc
*case_attr
, *attr
;
4068 struct attr_value
*av
, *common_av
;
4074 /* Write out conflict routines for function units. Don't bother writing
4075 one if there is only one busy value. */
4077 for (unit
= units
; unit
; unit
= unit
->next
)
4079 /* See if only one case exists and if there is a constant value for
4080 that case. If so, we don't need a function. */
4081 str
= (char *) alloca (strlen (unit
->name
) + 10);
4082 sprintf (str
, "*%s_cases", unit
->name
);
4083 attr
= find_attr (str
, 0);
4084 if (! attr
) abort ();
4085 value
= find_single_value (attr
);
4086 if (value
&& GET_CODE (value
) == CONST_STRING
)
4088 sprintf (str
, "*%s_case_%s", unit
->name
, XSTR (value
, 0));
4089 attr
= find_attr (str
, 0);
4090 if (! attr
) abort ();
4091 value
= find_single_value (attr
);
4092 if (value
&& GET_CODE (value
) == CONST_STRING
)
4094 unit
->needs_conflict_function
= 0;
4095 unit
->default_cost
= value
;
4100 /* The function first computes the case from the candidate insn. */
4101 unit
->needs_conflict_function
= 1;
4102 unit
->default_cost
= make_numeric_value (0);
4104 printf ("static int\n");
4105 printf ("%s_unit_conflict_cost (executing_insn, candidate_insn)\n",
4107 printf (" rtx executing_insn;\n");
4108 printf (" rtx candidate_insn;\n");
4110 printf (" rtx insn;\n");
4111 printf (" int casenum;\n\n");
4112 printf (" insn = candidate_insn;\n");
4113 printf (" switch (recog_memoized (insn))\n");
4116 /* Write the `switch' statement to get the case value. */
4117 sprintf (str
, "*%s_cases", unit
->name
);
4118 case_attr
= find_attr (str
, 0);
4119 if (! case_attr
) abort ();
4120 common_av
= find_most_used (case_attr
);
4122 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
4123 if (av
!= common_av
)
4124 write_attr_case (case_attr
, av
, 1,
4125 "casenum =", ";", 4, unit
->condexp
);
4127 write_attr_case (case_attr
, common_av
, 0,
4128 "casenum =", ";", 4, unit
->condexp
);
4131 /* Now write an outer switch statement on each case. Then write
4132 the tests on the executing function within each. */
4133 printf (" insn = executing_insn;\n");
4134 printf (" switch (casenum)\n");
4137 for (i
= 0; i
< unit
->num_opclasses
; i
++)
4139 /* Ensure using this case. */
4141 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
4143 && contained_in_p (make_numeric_value (i
), av
->value
))
4149 printf (" case %d:\n", i
);
4150 sprintf (str
, "*%s_case_%d", unit
->name
, i
);
4151 attr
= find_attr (str
, 0);
4152 if (! attr
) abort ();
4154 /* If single value, just write it. */
4155 value
= find_single_value (attr
);
4157 write_attr_set (attr
, 6, value
, "return", ";\n", true_rtx
, -2);
4160 common_av
= find_most_used (attr
);
4161 printf (" switch (recog_memoized (insn))\n");
4164 for (av
= attr
->first_value
; av
; av
= av
->next
)
4165 if (av
!= common_av
)
4166 write_attr_case (attr
, av
, 1,
4167 "return", ";", 8, unit
->condexp
);
4169 write_attr_case (attr
, common_av
, 0,
4170 "return", ";", 8, unit
->condexp
);
4175 printf (" }\n}\n\n");
4178 /* Now that all functions have been written, write the table describing
4179 the function units. The name is included for documentation purposes
4182 printf ("struct function_unit_desc function_units[] = {\n");
4184 for (unit
= units
; unit
; unit
= unit
->next
)
4186 printf (" {\"%s\", %d, %d, %d, %s, %s_unit_ready_cost, ",
4187 unit
->name
, 1 << unit
->num
, unit
->multiplicity
,
4188 unit
->simultaneity
, XSTR (unit
->default_cost
, 0), unit
->name
);
4190 if (unit
->needs_conflict_function
)
4191 printf ("%s_unit_conflict_cost", unit
->name
);
4201 /* This page contains miscellaneous utility routines. */
4203 /* Given a string, return the number of comma-separated elements in it.
4204 Return 0 for the null string. */
4215 for (n
= 1; *s
; s
++)
4222 /* Given a pointer to a (char *), return a malloc'ed string containing the
4223 next comma-separated element. Advance the pointer to after the string
4224 scanned, or the end-of-string. Return NULL if at end of string. */
4227 next_comma_elt (pstr
)
4236 /* Find end of string to compute length. */
4237 for (p
= *pstr
; *p
!= ',' && *p
!= '\0'; p
++)
4240 out_str
= attr_string (*pstr
, p
- *pstr
);
4249 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
4250 is non-zero, build a new attribute, if one does not exist. */
4252 static struct attr_desc
*
4253 find_attr (name
, create
)
4257 struct attr_desc
*attr
;
4260 /* Before we resort to using `strcmp', see if the string address matches
4261 anywhere. In most cases, it should have been canonicalized to do so. */
4262 if (name
== alternative_name
)
4265 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
4266 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4267 if (name
== attr
->name
)
4270 /* Otherwise, do it the slow way. */
4271 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
4272 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
4278 attr
= (struct attr_desc
*) xmalloc (sizeof (struct attr_desc
));
4279 attr
->name
= attr_string (name
, strlen (name
));
4280 attr
->first_value
= attr
->default_val
= NULL
;
4281 attr
->is_numeric
= attr
->is_const
= attr
->is_special
= 0;
4282 attr
->next
= attrs
[index
];
4283 attrs
[index
] = attr
;
4288 /* Create internal attribute with the given default value. */
4291 make_internal_attr (name
, value
, special
)
4296 struct attr_desc
*attr
;
4298 attr
= find_attr (name
, 1);
4299 if (attr
->default_val
)
4302 attr
->is_numeric
= 1;
4304 attr
->is_special
= special
;
4305 attr
->default_val
= get_attr_value (value
, attr
, -2);
4308 /* Find the most used value of an attribute. */
4310 static struct attr_value
*
4311 find_most_used (attr
)
4312 struct attr_desc
*attr
;
4314 struct attr_value
*av
;
4315 struct attr_value
*most_used
;
4321 for (av
= attr
->first_value
; av
; av
= av
->next
)
4322 if (av
->num_insns
> nuses
)
4323 nuses
= av
->num_insns
, most_used
= av
;
4328 /* If an attribute only has a single value used, return it. Otherwise
4332 find_single_value (attr
)
4333 struct attr_desc
*attr
;
4335 struct attr_value
*av
;
4338 unique_value
= NULL
;
4339 for (av
= attr
->first_value
; av
; av
= av
->next
)
4345 unique_value
= av
->value
;
4348 return unique_value
;
4351 /* Return (attr_value "n") */
4354 make_numeric_value (n
)
4357 static rtx int_values
[20];
4364 if (n
< 20 && int_values
[n
])
4365 return int_values
[n
];
4367 p
= attr_printf ((n
< 1000 ? 4 : HOST_BITS_PER_INT
* 3 / 10 + 3), "%d", n
);
4368 exp
= attr_rtx (CONST_STRING
, p
);
4371 int_values
[n
] = exp
;
4377 xrealloc (ptr
, size
)
4381 char *result
= (char *) realloc (ptr
, size
);
4383 fatal ("virtual memory exhausted");
4391 register char *val
= (char *) malloc (size
);
4394 fatal ("virtual memory exhausted");
4399 copy_rtx_unchanging (orig
)
4403 register RTX_CODE code
;
4405 if (RTX_UNCHANGING_P (orig
) || MEM_IN_STRUCT_P (orig
))
4408 MEM_IN_STRUCT_P (orig
) = 1;
4412 code
= GET_CODE (orig
);
4422 copy
= rtx_alloc (code
);
4423 PUT_MODE (copy
, GET_MODE (orig
));
4424 RTX_UNCHANGING_P (copy
) = 1;
4426 bcopy (&XEXP (orig
, 0), &XEXP (copy
, 0),
4427 GET_RTX_LENGTH (GET_CODE (copy
)) * sizeof (rtx
));
4436 fprintf (stderr
, "genattrtab: ");
4437 fprintf (stderr
, s
, a1
, a2
);
4438 fprintf (stderr
, "\n");
4439 exit (FATAL_EXIT_CODE
);
4442 /* More 'friendly' abort that prints the line and file.
4443 config.h can #define abort fancy_abort if you like that sort of thing. */
4448 fatal ("Internal gcc abort.");
4459 struct attr_desc
*attr
;
4460 struct attr_value
*av
;
4461 struct insn_def
*id
;
4465 obstack_init (rtl_obstack
);
4466 obstack_init (hash_obstack
);
4467 obstack_init (temp_obstack
);
4470 fatal ("No input file name.");
4472 infile
= fopen (argv
[1], "r");
4476 exit (FATAL_EXIT_CODE
);
4481 /* Set up true and false rtx's */
4482 true_rtx
= rtx_alloc (CONST_INT
);
4483 XINT (true_rtx
, 0) = 1;
4484 false_rtx
= rtx_alloc (CONST_INT
);
4485 XINT (false_rtx
, 0) = 0;
4486 RTX_UNCHANGING_P (true_rtx
) = RTX_UNCHANGING_P (false_rtx
) = 1;
4487 RTX_INTEGRATED_P (true_rtx
) = RTX_INTEGRATED_P (false_rtx
) = 1;
4489 alternative_name
= attr_string ("alternative", strlen ("alternative"));
4491 printf ("/* Generated automatically by the program `genattrtab'\n\
4492 from the machine description file `md'. */\n\n");
4494 /* Read the machine description. */
4498 c
= read_skip_spaces (infile
);
4503 desc
= read_rtx (infile
);
4504 if (GET_CODE (desc
) == DEFINE_INSN
4505 || GET_CODE (desc
) == DEFINE_PEEPHOLE
4506 || GET_CODE (desc
) == DEFINE_ASM_ATTRIBUTES
)
4509 else if (GET_CODE (desc
) == DEFINE_EXPAND
)
4510 insn_code_number
++, insn_index_number
++;
4512 else if (GET_CODE (desc
) == DEFINE_SPLIT
)
4513 insn_code_number
++, insn_index_number
++;
4515 else if (GET_CODE (desc
) == DEFINE_ATTR
)
4518 insn_index_number
++;
4521 else if (GET_CODE (desc
) == DEFINE_DELAY
)
4524 insn_index_number
++;
4527 else if (GET_CODE (desc
) == DEFINE_FUNCTION_UNIT
)
4530 insn_index_number
++;
4534 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
4535 if (! got_define_asm_attributes
)
4537 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
4538 XVEC (tem
, 0) = rtvec_alloc (0);
4542 /* Expand DEFINE_DELAY information into new attribute. */
4546 /* Expand DEFINE_FUNCTION_UNIT information into new attributes. */
4550 printf ("#include \"config.h\"\n");
4551 printf ("#include \"rtl.h\"\n");
4552 printf ("#include \"insn-config.h\"\n");
4553 printf ("#include \"recog.h\"\n");
4554 printf ("#include \"regs.h\"\n");
4555 printf ("#include \"real.h\"\n");
4556 printf ("#include \"output.h\"\n");
4557 printf ("#include \"insn-attr.h\"\n");
4559 printf ("#define operands recog_operand\n\n");
4561 /* Make `insn_alternatives'. */
4562 insn_alternatives
= (int *) xmalloc (insn_code_number
* sizeof (int));
4563 for (id
= defs
; id
; id
= id
->next
)
4564 if (id
->insn_code
>= 0)
4565 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
4567 /* Make `insn_n_alternatives'. */
4568 insn_n_alternatives
= (int *) xmalloc (insn_code_number
* sizeof (int));
4569 for (id
= defs
; id
; id
= id
->next
)
4570 if (id
->insn_code
>= 0)
4571 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
4573 /* Prepare to write out attribute subroutines by checking everything stored
4574 away and building the attribute cases. */
4577 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
4578 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
4580 attr
->default_val
->value
4581 = check_attr_value (attr
->default_val
->value
, attr
);
4585 /* Construct extra attributes for `length'. */
4586 make_length_attrs ();
4588 /* Perform any possible optimizations to speed up compilation. */
4591 /* Now write out all the `gen_attr_...' routines. Do these before the
4592 special routines (specifically before write_function_unit_info), so
4593 that they get defined before they are used. */
4595 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
4596 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
4598 if (! attr
->is_special
)
4599 write_attr_get (attr
);
4602 /* Write out delay eligibility information, if DEFINE_DELAY present.
4603 (The function to compute the number of delay slots will be written
4607 write_eligible_delay ("delay");
4608 if (have_annul_true
)
4609 write_eligible_delay ("annul_true");
4610 if (have_annul_false
)
4611 write_eligible_delay ("annul_false");
4614 /* Write out information about function units. */
4616 write_function_unit_info ();
4619 exit (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);