1 /* Generate code from machine description to compute values of attributes.
2 Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This program handles insn attributes and the DEFINE_DELAY and
22 DEFINE_FUNCTION_UNIT definitions.
24 It produces a series of functions named `get_attr_...', one for each insn
25 attribute. Each of these is given the rtx for an insn and returns a member
26 of the enum for the attribute.
28 These subroutines have the form of a `switch' on the INSN_CODE (via
29 `recog_memoized'). Each case either returns a constant attribute value
30 or a value that depends on tests on other attributes, the form of
31 operands, or some random C expression (encoded with a SYMBOL_REF
34 If the attribute `alternative', or a random C expression is present,
35 `constrain_operands' is called. If either of these cases of a reference to
36 an operand is found, `insn_extract' is called.
38 The special attribute `length' is also recognized. For this operand,
39 expressions involving the address of an operand or the current insn,
40 (address (pc)), are valid. In this case, an initial pass is made to
41 set all lengths that do not depend on address. Those that do are set to
42 the maximum length. Then each insn that depends on an address is checked
43 and possibly has its length changed. The process repeats until no further
44 changed are made. The resulting lengths are saved for use by
47 A special form of DEFINE_ATTR, where the expression for default value is a
48 CONST expression, indicates an attribute that is constant for a given run
49 of the compiler. The subroutine generated for these attributes has no
50 parameters as it does not depend on any particular insn. Constant
51 attributes are typically used to specify which variety of processor is
54 Internal attributes are defined to handle DEFINE_DELAY and
55 DEFINE_FUNCTION_UNIT. Special routines are output for these cases.
57 This program works by keeping a list of possible values for each attribute.
58 These include the basic attribute choices, default values for attribute, and
59 all derived quantities.
61 As the description file is read, the definition for each insn is saved in a
62 `struct insn_def'. When the file reading is complete, a `struct insn_ent'
63 is created for each insn and chained to the corresponding attribute value,
64 either that specified, or the default.
66 An optimization phase is then run. This simplifies expressions for each
67 insn. EQ_ATTR tests are resolved, whenever possible, to a test that
68 indicates when the attribute has the specified value for the insn. This
69 avoids recursive calls during compilation.
71 The strategy used when processing DEFINE_DELAY and DEFINE_FUNCTION_UNIT
72 definitions is to create arbitrarily complex expressions and have the
73 optimization simplify them.
75 Once optimization is complete, any required routines and definitions
78 An optimization that is not yet implemented is to hoist the constant
79 expressions entirely out of the routines and definitions that are written.
80 A way to do this is to iterate over all possible combinations of values
81 for constant attributes and generate a set of functions for that given
82 combination. An initialization function would be written that evaluates
83 the attributes and installs the corresponding set of routines and
84 definitions (each would be accessed through a pointer).
86 We use the flags in an RTX as follows:
87 `unchanging' (RTX_UNCHANGING_P): This rtx is fully simplified
88 independent of the insn code.
89 `in_struct' (MEM_IN_STRUCT_P): This rtx is fully simplified
90 for the insn code currently being processed (see optimize_attrs).
91 `integrated' (RTX_INTEGRATED_P): This rtx is permanent and unique
93 `volatil' (MEM_VOLATILE_P): During simplify_by_exploding the value of an
94 EQ_ATTR rtx is true if !volatil and false if volatil. */
98 /* varargs must always be included after *config.h. */
105 #include "insn-config.h" /* For REGISTER_CONSTRAINTS */
110 #include <sys/time.h>
111 #include <sys/resource.h>
115 /* We must include obstack.h after <sys/time.h>, to avoid lossage with
116 /usr/include/sys/stdtypes.h on Sun OS 4.x. */
119 static struct obstack obstack
, obstack1
, obstack2
;
120 struct obstack
*rtl_obstack
= &obstack
;
121 struct obstack
*hash_obstack
= &obstack1
;
122 struct obstack
*temp_obstack
= &obstack2
;
124 #define obstack_chunk_alloc xmalloc
125 #define obstack_chunk_free free
127 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
128 char **insn_name_ptr
= 0;
131 extern rtx
read_rtx ();
133 static void fatal ();
136 /* enough space to reserve for printing out ints */
137 #define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
139 /* Define structures used to record attributes and values. */
141 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
142 encountered, we store all the relevant information into a
143 `struct insn_def'. This is done to allow attribute definitions to occur
144 anywhere in the file. */
148 int insn_code
; /* Instruction number. */
149 int insn_index
; /* Expression numer in file, for errors. */
150 struct insn_def
*next
; /* Next insn in chain. */
151 rtx def
; /* The DEFINE_... */
152 int num_alternatives
; /* Number of alternatives. */
153 int vec_idx
; /* Index of attribute vector in `def'. */
156 /* Once everything has been read in, we store in each attribute value a list
157 of insn codes that have that value. Here is the structure used for the
162 int insn_code
; /* Instruction number. */
163 int insn_index
; /* Index of definition in file */
164 struct insn_ent
*next
; /* Next in chain. */
167 /* Each value of an attribute (either constant or computed) is assigned a
168 structure which is used as the listhead of the insns that have that
173 rtx value
; /* Value of attribute. */
174 struct attr_value
*next
; /* Next attribute value in chain. */
175 struct insn_ent
*first_insn
; /* First insn with this value. */
176 int num_insns
; /* Number of insns with this value. */
177 int has_asm_insn
; /* True if this value used for `asm' insns */
180 /* Structure for each attribute. */
184 char *name
; /* Name of attribute. */
185 struct attr_desc
*next
; /* Next attribute. */
186 int is_numeric
; /* Values of this attribute are numeric. */
187 int negative_ok
; /* Allow negative numeric values. */
188 int unsigned_p
; /* Make the output function unsigned int. */
189 int is_const
; /* Attribute value constant for each run. */
190 int is_special
; /* Don't call `write_attr_set'. */
191 struct attr_value
*first_value
; /* First value of this attribute. */
192 struct attr_value
*default_val
; /* Default value for this attribute. */
195 #define NULL_ATTR (struct attr_desc *) NULL
197 /* A range of values. */
205 /* Structure for each DEFINE_DELAY. */
209 rtx def
; /* DEFINE_DELAY expression. */
210 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
211 int num
; /* Number of DEFINE_DELAY, starting at 1. */
214 /* Record information about each DEFINE_FUNCTION_UNIT. */
216 struct function_unit_op
218 rtx condexp
; /* Expression TRUE for applicable insn. */
219 struct function_unit_op
*next
; /* Next operation for this function unit. */
220 int num
; /* Ordinal for this operation type in unit. */
221 int ready
; /* Cost until data is ready. */
222 int issue_delay
; /* Cost until unit can accept another insn. */
223 rtx conflict_exp
; /* Expression TRUE for insns incurring issue delay. */
224 rtx issue_exp
; /* Expression computing issue delay. */
227 /* Record information about each function unit mentioned in a
228 DEFINE_FUNCTION_UNIT. */
232 char *name
; /* Function unit name. */
233 struct function_unit
*next
; /* Next function unit. */
234 int num
; /* Ordinal of this unit type. */
235 int multiplicity
; /* Number of units of this type. */
236 int simultaneity
; /* Maximum number of simultaneous insns
237 on this function unit or 0 if unlimited. */
238 rtx condexp
; /* Expression TRUE for insn needing unit. */
239 int num_opclasses
; /* Number of different operation types. */
240 struct function_unit_op
*ops
; /* Pointer to first operation type. */
241 int needs_conflict_function
; /* Nonzero if a conflict function required. */
242 int needs_blockage_function
; /* Nonzero if a blockage function required. */
243 int needs_range_function
; /* Nonzero if blockage range function needed.*/
244 rtx default_cost
; /* Conflict cost, if constant. */
245 struct range issue_delay
; /* Range of issue delay values. */
246 int max_blockage
; /* Maximum time an insn blocks the unit. */
249 /* Listheads of above structures. */
251 /* This one is indexed by the first character of the attribute name. */
252 #define MAX_ATTRS_INDEX 256
253 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
254 static struct insn_def
*defs
;
255 static struct delay_desc
*delays
;
256 static struct function_unit
*units
;
258 /* An expression where all the unknown terms are EQ_ATTR tests can be
259 rearranged into a COND provided we can enumerate all possible
260 combinations of the unknown values. The set of combinations become the
261 tests of the COND; the value of the expression given that combination is
262 computed and becomes the corresponding value. To do this, we must be
263 able to enumerate all values for each attribute used in the expression
264 (currently, we give up if we find a numeric attribute).
266 If the set of EQ_ATTR tests used in an expression tests the value of N
267 different attributes, the list of all possible combinations can be made
268 by walking the N-dimensional attribute space defined by those
269 attributes. We record each of these as a struct dimension.
271 The algorithm relies on sharing EQ_ATTR nodes: if two nodes in an
272 expression are the same, the will also have the same address. We find
273 all the EQ_ATTR nodes by marking them MEM_VOLATILE_P. This bit later
274 represents the value of an EQ_ATTR node, so once all nodes are marked,
275 they are also given an initial value of FALSE.
277 We then separate the set of EQ_ATTR nodes into dimensions for each
278 attribute and put them on the VALUES list. Terms are added as needed by
279 `add_values_to_cover' so that all possible values of the attribute are
282 Each dimension also has a current value. This is the node that is
283 currently considered to be TRUE. If this is one of the nodes added by
284 `add_values_to_cover', all the EQ_ATTR tests in the original expression
285 will be FALSE. Otherwise, only the CURRENT_VALUE will be true.
287 NUM_VALUES is simply the length of the VALUES list and is there for
290 Once the dimensions are created, the algorithm enumerates all possible
291 values and computes the current value of the given expression. */
295 struct attr_desc
*attr
; /* Attribute for this dimension. */
296 rtx values
; /* List of attribute values used. */
297 rtx current_value
; /* Position in the list for the TRUE value. */
298 int num_values
; /* Length of the values list. */
301 /* Other variables. */
303 static int insn_code_number
;
304 static int insn_index_number
;
305 static int got_define_asm_attributes
;
306 static int must_extract
;
307 static int must_constrain
;
308 static int address_used
;
309 static int length_used
;
310 static int num_delays
;
311 static int have_annul_true
, have_annul_false
;
312 static int num_units
;
314 /* Used as operand to `operate_exp': */
316 enum operator {PLUS_OP
, MINUS_OP
, POS_MINUS_OP
, EQ_OP
, OR_OP
, MAX_OP
, MIN_OP
, RANGE_OP
};
318 /* Stores, for each insn code, the number of constraint alternatives. */
320 static int *insn_n_alternatives
;
322 /* Stores, for each insn code, a bitmap that has bits on for each possible
325 static int *insn_alternatives
;
327 /* If nonzero, assume that the `alternative' attr has this value.
328 This is the hashed, unique string for the numeral
329 whose value is chosen alternative. */
331 static char *current_alternative_string
;
333 /* Used to simplify expressions. */
335 static rtx true_rtx
, false_rtx
;
337 /* Used to reduce calls to `strcmp' */
339 static char *alternative_name
;
341 /* Simplify an expression. Only call the routine if there is something to
343 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
344 (RTX_UNCHANGING_P (EXP) || MEM_IN_STRUCT_P (EXP) ? (EXP) \
345 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
347 /* Simplify (eq_attr ("alternative") ...)
348 when we are working with a particular alternative. */
349 #define SIMPLIFY_ALTERNATIVE(EXP) \
350 if (current_alternative_string \
351 && GET_CODE ((EXP)) == EQ_ATTR \
352 && XSTR ((EXP), 0) == alternative_name) \
353 (EXP) = (XSTR ((EXP), 1) == current_alternative_string \
354 ? true_rtx : false_rtx);
356 /* These are referenced by rtlanal.c and hence need to be defined somewhere.
357 They won't actually be used. */
359 rtx frame_pointer_rtx
, hard_frame_pointer_rtx
, stack_pointer_rtx
;
362 static rtx attr_rtx
PVPROTO((enum rtx_code
, ...));
364 static char *attr_printf
PVPROTO((int, char *, ...));
366 static char *attr_printf ();
369 static char *attr_string
PROTO((char *, int));
370 static rtx check_attr_test
PROTO((rtx
, int));
371 static rtx check_attr_value
PROTO((rtx
, struct attr_desc
*));
372 static rtx convert_set_attr_alternative
PROTO((rtx
, int, int, int));
373 static rtx convert_set_attr
PROTO((rtx
, int, int, int));
374 static void check_defs
PROTO((void));
375 static rtx convert_const_symbol_ref
PROTO((rtx
, struct attr_desc
*));
376 static rtx make_canonical
PROTO((struct attr_desc
*, rtx
));
377 static struct attr_value
*get_attr_value
PROTO((rtx
, struct attr_desc
*, int));
378 static rtx copy_rtx_unchanging
PROTO((rtx
));
379 static rtx copy_boolean
PROTO((rtx
));
380 static void expand_delays
PROTO((void));
381 static rtx operate_exp
PROTO((enum operator, rtx
, rtx
));
382 static void expand_units
PROTO((void));
383 static rtx simplify_knowing
PROTO((rtx
, rtx
));
384 static rtx encode_units_mask
PROTO((rtx
));
385 static void fill_attr
PROTO((struct attr_desc
*));
386 /* dpx2 compiler chokes if we specify the arg types of the args. */
387 static rtx substitute_address
PROTO((rtx
, rtx (*) (), rtx (*) ()));
388 static void make_length_attrs
PROTO((void));
389 static rtx identity_fn
PROTO((rtx
));
390 static rtx zero_fn
PROTO((rtx
));
391 static rtx one_fn
PROTO((rtx
));
392 static rtx max_fn
PROTO((rtx
));
393 static rtx simplify_cond
PROTO((rtx
, int, int));
394 static rtx simplify_by_alternatives
PROTO((rtx
, int, int));
395 static rtx simplify_by_exploding
PROTO((rtx
));
396 static int find_and_mark_used_attributes
PROTO((rtx
, rtx
*, int *));
397 static void unmark_used_attributes
PROTO((rtx
, struct dimension
*, int));
398 static int add_values_to_cover
PROTO((struct dimension
*));
399 static int increment_current_value
PROTO((struct dimension
*, int));
400 static rtx test_for_current_value
PROTO((struct dimension
*, int));
401 static rtx simplify_with_current_value
PROTO((rtx
, struct dimension
*, int));
402 static rtx simplify_with_current_value_aux
PROTO((rtx
));
403 static void clear_struct_flag
PROTO((rtx
));
404 static int count_sub_rtxs
PROTO((rtx
, int));
405 static void remove_insn_ent
PROTO((struct attr_value
*, struct insn_ent
*));
406 static void insert_insn_ent
PROTO((struct attr_value
*, struct insn_ent
*));
407 static rtx insert_right_side
PROTO((enum rtx_code
, rtx
, rtx
, int, int));
408 static rtx make_alternative_compare
PROTO((int));
409 static int compute_alternative_mask
PROTO((rtx
, enum rtx_code
));
410 static rtx evaluate_eq_attr
PROTO((rtx
, rtx
, int, int));
411 static rtx simplify_and_tree
PROTO((rtx
, rtx
*, int, int));
412 static rtx simplify_or_tree
PROTO((rtx
, rtx
*, int, int));
413 static rtx simplify_test_exp
PROTO((rtx
, int, int));
414 static void optimize_attrs
PROTO((void));
415 static void gen_attr
PROTO((rtx
));
416 static int count_alternatives
PROTO((rtx
));
417 static int compares_alternatives_p
PROTO((rtx
));
418 static int contained_in_p
PROTO((rtx
, rtx
));
419 static void gen_insn
PROTO((rtx
));
420 static void gen_delay
PROTO((rtx
));
421 static void gen_unit
PROTO((rtx
));
422 static void write_test_expr
PROTO((rtx
, int));
423 static int max_attr_value
PROTO((rtx
));
424 static void walk_attr_value
PROTO((rtx
));
425 static void write_attr_get
PROTO((struct attr_desc
*));
426 static rtx eliminate_known_true
PROTO((rtx
, rtx
, int, int));
427 static void write_attr_set
PROTO((struct attr_desc
*, int, rtx
, char *,
428 char *, rtx
, int, int));
429 static void write_attr_case
PROTO((struct attr_desc
*, struct attr_value
*,
430 int, char *, char *, int, rtx
));
431 static void write_attr_valueq
PROTO((struct attr_desc
*, char *));
432 static void write_attr_value
PROTO((struct attr_desc
*, rtx
));
433 static void write_upcase
PROTO((char *));
434 static void write_indent
PROTO((int));
435 static void write_eligible_delay
PROTO((char *));
436 static void write_function_unit_info
PROTO((void));
437 static void write_complex_function
PROTO((struct function_unit
*, char *,
439 static int n_comma_elts
PROTO((char *));
440 static char *next_comma_elt
PROTO((char **));
441 static struct attr_desc
*find_attr
PROTO((char *, int));
442 static void make_internal_attr
PROTO((char *, rtx
, int));
443 static struct attr_value
*find_most_used
PROTO((struct attr_desc
*));
444 static rtx find_single_value
PROTO((struct attr_desc
*));
445 static rtx make_numeric_value
PROTO((int));
446 static void extend_range
PROTO((struct range
*, int, int));
447 char *xrealloc
PROTO((char *, unsigned));
448 char *xmalloc
PROTO((unsigned));
450 #define oballoc(size) obstack_alloc (hash_obstack, size)
453 /* Hash table for sharing RTL and strings. */
455 /* Each hash table slot is a bucket containing a chain of these structures.
456 Strings are given negative hash codes; RTL expressions are given positive
461 struct attr_hash
*next
; /* Next structure in the bucket. */
462 int hashcode
; /* Hash code of this rtx or string. */
465 char *str
; /* The string (negative hash codes) */
466 rtx rtl
; /* or the RTL recorded here. */
470 /* Now here is the hash table. When recording an RTL, it is added to
471 the slot whose index is the hash code mod the table size. Note
472 that the hash table is used for several kinds of RTL (see attr_rtx)
473 and for strings. While all these live in the same table, they are
474 completely independent, and the hash code is computed differently
477 #define RTL_HASH_SIZE 4093
478 struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
480 /* Here is how primitive or already-shared RTL's hash
482 #define RTL_HASH(RTL) ((HOST_WIDE_INT) (RTL) & 0777777)
484 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
487 attr_hash_add_rtx (hashcode
, rtl
)
491 register struct attr_hash
*h
;
493 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
494 sizeof (struct attr_hash
));
495 h
->hashcode
= hashcode
;
497 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
498 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
501 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
504 attr_hash_add_string (hashcode
, str
)
508 register struct attr_hash
*h
;
510 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
511 sizeof (struct attr_hash
));
512 h
->hashcode
= -hashcode
;
514 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
515 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
518 /* Generate an RTL expression, but avoid duplicates.
519 Set the RTX_INTEGRATED_P flag for these permanent objects.
521 In some cases we cannot uniquify; then we return an ordinary
522 impermanent rtx with RTX_INTEGRATED_P clear.
524 Args are like gen_rtx, but without the mode:
526 rtx attr_rtx (code, [element1, ..., elementn]) */
530 attr_rtx
VPROTO((enum rtx_code code
, ...))
536 register int i
; /* Array indices... */
537 register char *fmt
; /* Current rtx's format... */
538 register rtx rt_val
; /* RTX to return to caller... */
540 register struct attr_hash
*h
;
541 struct obstack
*old_obstack
= rtl_obstack
;
546 code
= va_arg (p
, enum rtx_code
);
549 /* For each of several cases, search the hash table for an existing entry.
550 Use that entry if one is found; otherwise create a new RTL and add it
553 if (GET_RTX_CLASS (code
) == '1')
555 rtx arg0
= va_arg (p
, rtx
);
557 /* A permanent object cannot point to impermanent ones. */
558 if (! RTX_INTEGRATED_P (arg0
))
560 rt_val
= rtx_alloc (code
);
561 XEXP (rt_val
, 0) = arg0
;
566 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
567 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
568 if (h
->hashcode
== hashcode
569 && GET_CODE (h
->u
.rtl
) == code
570 && XEXP (h
->u
.rtl
, 0) == arg0
)
575 rtl_obstack
= hash_obstack
;
576 rt_val
= rtx_alloc (code
);
577 XEXP (rt_val
, 0) = arg0
;
580 else if (GET_RTX_CLASS (code
) == 'c'
581 || GET_RTX_CLASS (code
) == '2'
582 || GET_RTX_CLASS (code
) == '<')
584 rtx arg0
= va_arg (p
, rtx
);
585 rtx arg1
= va_arg (p
, rtx
);
587 /* A permanent object cannot point to impermanent ones. */
588 if (! RTX_INTEGRATED_P (arg0
) || ! RTX_INTEGRATED_P (arg1
))
590 rt_val
= rtx_alloc (code
);
591 XEXP (rt_val
, 0) = arg0
;
592 XEXP (rt_val
, 1) = arg1
;
597 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
598 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
599 if (h
->hashcode
== hashcode
600 && GET_CODE (h
->u
.rtl
) == code
601 && XEXP (h
->u
.rtl
, 0) == arg0
602 && XEXP (h
->u
.rtl
, 1) == arg1
)
607 rtl_obstack
= hash_obstack
;
608 rt_val
= rtx_alloc (code
);
609 XEXP (rt_val
, 0) = arg0
;
610 XEXP (rt_val
, 1) = arg1
;
613 else if (GET_RTX_LENGTH (code
) == 1
614 && GET_RTX_FORMAT (code
)[0] == 's')
616 char * arg0
= va_arg (p
, char *);
618 if (code
== SYMBOL_REF
)
619 arg0
= attr_string (arg0
, strlen (arg0
));
621 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
622 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
623 if (h
->hashcode
== hashcode
624 && GET_CODE (h
->u
.rtl
) == code
625 && XSTR (h
->u
.rtl
, 0) == arg0
)
630 rtl_obstack
= hash_obstack
;
631 rt_val
= rtx_alloc (code
);
632 XSTR (rt_val
, 0) = arg0
;
635 else if (GET_RTX_LENGTH (code
) == 2
636 && GET_RTX_FORMAT (code
)[0] == 's'
637 && GET_RTX_FORMAT (code
)[1] == 's')
639 char *arg0
= va_arg (p
, char *);
640 char *arg1
= va_arg (p
, char *);
642 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
643 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
644 if (h
->hashcode
== hashcode
645 && GET_CODE (h
->u
.rtl
) == code
646 && XSTR (h
->u
.rtl
, 0) == arg0
647 && XSTR (h
->u
.rtl
, 1) == arg1
)
652 rtl_obstack
= hash_obstack
;
653 rt_val
= rtx_alloc (code
);
654 XSTR (rt_val
, 0) = arg0
;
655 XSTR (rt_val
, 1) = arg1
;
658 else if (code
== CONST_INT
)
660 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
670 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
672 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
673 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
677 case '0': /* Unused field. */
680 case 'i': /* An integer? */
681 XINT (rt_val
, i
) = va_arg (p
, int);
684 case 'w': /* A wide integer? */
685 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
688 case 's': /* A string? */
689 XSTR (rt_val
, i
) = va_arg (p
, char *);
692 case 'e': /* An expression? */
693 case 'u': /* An insn? Same except when printing. */
694 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
697 case 'E': /* An RTX vector? */
698 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
709 rtl_obstack
= old_obstack
;
711 attr_hash_add_rtx (hashcode
, rt_val
);
712 RTX_INTEGRATED_P (rt_val
) = 1;
720 /* Create a new string printed with the printf line arguments into a space
721 of at most LEN bytes:
723 rtx attr_printf (len, format, [arg1, ..., argn]) */
729 attr_printf
VPROTO((register int len
, char *fmt
, ...))
741 len
= va_arg (p
, int);
742 fmt
= va_arg (p
, char*);
745 /* Print the string into a temporary location. */
746 str
= (char *) alloca (len
);
747 vsprintf (str
, fmt
, p
);
750 return attr_string (str
, strlen (str
));
753 #else /* not HAVE_VPRINTF */
756 attr_printf (len
, fmt
, arg1
, arg2
, arg3
)
759 char *arg1
, *arg2
, *arg3
; /* also int */
763 /* Print the string into a temporary location. */
764 str
= (char *) alloca (len
);
765 sprintf (str
, fmt
, arg1
, arg2
, arg3
);
767 return attr_string (str
, strlen (str
));
769 #endif /* not HAVE_VPRINTF */
772 attr_eq (name
, value
)
775 return attr_rtx (EQ_ATTR
, attr_string (name
, strlen (name
)),
776 attr_string (value
, strlen (value
)));
783 return XSTR (make_numeric_value (n
), 0);
786 /* Return a permanent (possibly shared) copy of a string STR (not assumed
787 to be null terminated) with LEN bytes. */
790 attr_string (str
, len
)
794 register struct attr_hash
*h
;
797 register char *new_str
;
799 /* Compute the hash code. */
800 hashcode
= (len
+ 1) * 613 + (unsigned)str
[0];
801 for (i
= 1; i
<= len
; i
+= 2)
802 hashcode
= ((hashcode
* 613) + (unsigned)str
[i
]);
804 hashcode
= -hashcode
;
806 /* Search the table for the string. */
807 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
808 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
809 && !strncmp (h
->u
.str
, str
, len
))
810 return h
->u
.str
; /* <-- return if found. */
812 /* Not found; create a permanent copy and add it to the hash table. */
813 new_str
= (char *) obstack_alloc (hash_obstack
, len
+ 1);
814 bcopy (str
, new_str
, len
);
816 attr_hash_add_string (hashcode
, new_str
);
818 return new_str
; /* Return the new string. */
821 /* Check two rtx's for equality of contents,
822 taking advantage of the fact that if both are hashed
823 then they can't be equal unless they are the same object. */
829 return (x
== y
|| (! (RTX_INTEGRATED_P (x
) && RTX_INTEGRATED_P (y
))
830 && rtx_equal_p (x
, y
)));
833 /* Copy an attribute value expression,
834 descending to all depths, but not copying any
835 permanent hashed subexpressions. */
843 register RTX_CODE code
;
844 register char *format_ptr
;
846 /* No need to copy a permanent object. */
847 if (RTX_INTEGRATED_P (orig
))
850 code
= GET_CODE (orig
);
865 copy
= rtx_alloc (code
);
866 PUT_MODE (copy
, GET_MODE (orig
));
867 copy
->in_struct
= orig
->in_struct
;
868 copy
->volatil
= orig
->volatil
;
869 copy
->unchanging
= orig
->unchanging
;
870 copy
->integrated
= orig
->integrated
;
872 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
874 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
876 switch (*format_ptr
++)
879 XEXP (copy
, i
) = XEXP (orig
, i
);
880 if (XEXP (orig
, i
) != NULL
)
881 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
886 XVEC (copy
, i
) = XVEC (orig
, i
);
887 if (XVEC (orig
, i
) != NULL
)
889 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
890 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
891 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
897 XINT (copy
, i
) = XINT (orig
, i
);
901 XWINT (copy
, i
) = XWINT (orig
, i
);
906 XSTR (copy
, i
) = XSTR (orig
, i
);
916 /* Given a test expression for an attribute, ensure it is validly formed.
917 IS_CONST indicates whether the expression is constant for each compiler
918 run (a constant expression may not test any particular insn).
920 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
921 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
922 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
924 Update the string address in EQ_ATTR expression to be the same used
925 in the attribute (or `alternative_name') to speed up subsequent
926 `find_attr' calls and eliminate most `strcmp' calls.
928 Return the new expression, if any. */
931 check_attr_test (exp
, is_const
)
935 struct attr_desc
*attr
;
936 struct attr_value
*av
;
940 switch (GET_CODE (exp
))
943 /* Handle negation test. */
944 if (XSTR (exp
, 1)[0] == '!')
945 return check_attr_test (attr_rtx (NOT
,
946 attr_eq (XSTR (exp
, 0),
950 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
952 attr
= find_attr (XSTR (exp
, 0), 0);
955 if (! strcmp (XSTR (exp
, 0), "alternative"))
957 XSTR (exp
, 0) = alternative_name
;
958 /* This can't be simplified any further. */
959 RTX_UNCHANGING_P (exp
) = 1;
963 fatal ("Unknown attribute `%s' in EQ_ATTR", XEXP (exp
, 0));
966 if (is_const
&& ! attr
->is_const
)
967 fatal ("Constant expression uses insn attribute `%s' in EQ_ATTR",
970 /* Copy this just to make it permanent,
971 so expressions using it can be permanent too. */
972 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
974 /* It shouldn't be possible to simplify the value given to a
975 constant attribute, so don't expand this until it's time to
976 write the test expression. */
978 RTX_UNCHANGING_P (exp
) = 1;
980 if (attr
->is_numeric
)
982 for (p
= XSTR (exp
, 1); *p
; p
++)
983 if (*p
< '0' || *p
> '9')
984 fatal ("Attribute `%s' takes only numeric values",
989 for (av
= attr
->first_value
; av
; av
= av
->next
)
990 if (GET_CODE (av
->value
) == CONST_STRING
991 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
995 fatal ("Unknown value `%s' for `%s' attribute",
996 XEXP (exp
, 1), XEXP (exp
, 0));
1001 /* Make an IOR tree of the possible values. */
1003 name_ptr
= XSTR (exp
, 1);
1004 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1006 newexp
= attr_eq (XSTR (exp
, 0), p
);
1007 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
1010 return check_attr_test (orexp
, is_const
);
1018 /* Either TRUE or FALSE. */
1026 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
);
1027 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
);
1031 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
);
1036 fatal ("RTL operator \"%s\" not valid in constant attribute test",
1037 GET_RTX_NAME (MATCH_OPERAND
));
1038 /* These cases can't be simplified. */
1039 RTX_UNCHANGING_P (exp
) = 1;
1042 case LE
: case LT
: case GT
: case GE
:
1043 case LEU
: case LTU
: case GTU
: case GEU
:
1045 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
1046 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
1047 exp
= attr_rtx (GET_CODE (exp
),
1048 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
1049 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
1050 /* These cases can't be simplified. */
1051 RTX_UNCHANGING_P (exp
) = 1;
1057 /* These cases are valid for constant attributes, but can't be
1059 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1060 RTX_UNCHANGING_P (exp
) = 1;
1064 fatal ("RTL operator \"%s\" not valid in attribute test",
1065 GET_RTX_NAME (GET_CODE (exp
)));
1071 /* Given an expression, ensure that it is validly formed and that all named
1072 attribute values are valid for the given attribute. Issue a fatal error
1073 if not. If no attribute is specified, assume a numeric attribute.
1075 Return a perhaps modified replacement expression for the value. */
1078 check_attr_value (exp
, attr
)
1080 struct attr_desc
*attr
;
1082 struct attr_value
*av
;
1086 switch (GET_CODE (exp
))
1089 if (attr
&& ! attr
->is_numeric
)
1090 fatal ("CONST_INT not valid for non-numeric `%s' attribute",
1093 if (INTVAL (exp
) < 0)
1094 fatal ("Negative numeric value specified for `%s' attribute",
1100 if (! strcmp (XSTR (exp
, 0), "*"))
1103 if (attr
== 0 || attr
->is_numeric
)
1106 if (attr
&& attr
->negative_ok
&& *p
== '-')
1109 if (*p
> '9' || *p
< '0')
1110 fatal ("Non-numeric value for numeric `%s' attribute",
1111 attr
? attr
->name
: "internal");
1115 for (av
= attr
->first_value
; av
; av
= av
->next
)
1116 if (GET_CODE (av
->value
) == CONST_STRING
1117 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
1121 fatal ("Unknown value `%s' for `%s' attribute",
1122 XSTR (exp
, 0), attr
? attr
->name
: "internal");
1127 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
1128 attr
? attr
->is_const
: 0);
1129 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1130 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
1134 if (XVECLEN (exp
, 0) % 2 != 0)
1135 fatal ("First operand of COND must have even length");
1137 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1139 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1140 attr
? attr
->is_const
: 0);
1141 XVECEXP (exp
, 0, i
+ 1)
1142 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1145 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1149 if (attr
&& attr
->is_const
)
1150 /* A constant SYMBOL_REF is valid as a constant attribute test and
1151 is expanded later by make_canonical into a COND. */
1152 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1153 /* Otherwise, fall through... */
1156 fatal ("Illegal operation `%s' for attribute value",
1157 GET_RTX_NAME (GET_CODE (exp
)));
1163 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1164 It becomes a COND with each test being (eq_attr "alternative "n") */
1167 convert_set_attr_alternative (exp
, num_alt
, insn_code
, insn_index
)
1170 int insn_code
, insn_index
;
1175 if (XVECLEN (exp
, 1) != num_alt
)
1176 fatal ("Bad number of entries in SET_ATTR_ALTERNATIVE for insn %d",
1179 /* Make a COND with all tests but the last. Select the last value via the
1181 condexp
= rtx_alloc (COND
);
1182 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1184 for (i
= 0; i
< num_alt
- 1; i
++)
1187 p
= attr_numeral (i
);
1189 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1191 /* Sharing this EQ_ATTR rtl causes trouble. */
1192 XVECEXP (condexp
, 0, 2 * i
) = rtx_alloc (EQ_ATTR
);
1193 XSTR (XVECEXP (condexp
, 0, 2 * i
), 0) = alternative_name
;
1194 XSTR (XVECEXP (condexp
, 0, 2 * i
), 1) = p
;
1196 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1199 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1201 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1204 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1205 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1208 convert_set_attr (exp
, num_alt
, insn_code
, insn_index
)
1211 int insn_code
, insn_index
;
1218 /* See how many alternative specified. */
1219 n
= n_comma_elts (XSTR (exp
, 1));
1221 return attr_rtx (SET
,
1222 attr_rtx (ATTR
, XSTR (exp
, 0)),
1223 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1225 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1226 XSTR (newexp
, 0) = XSTR (exp
, 0);
1227 XVEC (newexp
, 1) = rtvec_alloc (n
);
1229 /* Process each comma-separated name. */
1230 name_ptr
= XSTR (exp
, 1);
1232 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1233 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1235 return convert_set_attr_alternative (newexp
, num_alt
, insn_code
, insn_index
);
1238 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1239 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1245 struct insn_def
*id
;
1246 struct attr_desc
*attr
;
1250 for (id
= defs
; id
; id
= id
->next
)
1252 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1255 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1257 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1258 switch (GET_CODE (value
))
1261 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1262 fatal ("Bad attribute set in pattern %d", id
->insn_index
);
1265 case SET_ATTR_ALTERNATIVE
:
1266 value
= convert_set_attr_alternative (value
,
1267 id
->num_alternatives
,
1273 value
= convert_set_attr (value
, id
->num_alternatives
,
1274 id
->insn_code
, id
->insn_index
);
1278 fatal ("Invalid attribute code `%s' for pattern %d",
1279 GET_RTX_NAME (GET_CODE (value
)), id
->insn_index
);
1282 if ((attr
= find_attr (XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1283 fatal ("Unknown attribute `%s' for pattern number %d",
1284 XSTR (XEXP (value
, 0), 0), id
->insn_index
);
1286 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1287 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1292 /* Given a constant SYMBOL_REF expression, convert to a COND that
1293 explicitly tests each enumerated value. */
1296 convert_const_symbol_ref (exp
, attr
)
1298 struct attr_desc
*attr
;
1301 struct attr_value
*av
;
1305 for (av
= attr
->first_value
; av
; av
= av
->next
)
1308 /* Make a COND with all tests but the last, and in the original order.
1309 Select the last value via the default. Note that the attr values
1310 are constructed in reverse order. */
1312 condexp
= rtx_alloc (COND
);
1313 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1314 av
= attr
->first_value
;
1315 XEXP (condexp
, 1) = av
->value
;
1317 for (i
= num_alt
- 2; av
= av
->next
, i
>= 0; i
--)
1322 string
= p
= (char *) oballoc (2
1323 + strlen (attr
->name
)
1324 + strlen (XSTR (av
->value
, 0)));
1325 strcpy (p
, attr
->name
);
1327 strcat (p
, XSTR (av
->value
, 0));
1328 for (; *p
!= '\0'; p
++)
1329 if (*p
>= 'a' && *p
<= 'z')
1332 value
= attr_rtx (SYMBOL_REF
, string
);
1333 RTX_UNCHANGING_P (value
) = 1;
1335 XVECEXP (condexp
, 0, 2 * i
) = attr_rtx (EQ
, exp
, value
);
1337 XVECEXP (condexp
, 0, 2 * i
+ 1) = av
->value
;
1343 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1344 expressions by converting them into a COND. This removes cases from this
1345 program. Also, replace an attribute value of "*" with the default attribute
1349 make_canonical (attr
, exp
)
1350 struct attr_desc
*attr
;
1356 switch (GET_CODE (exp
))
1359 exp
= make_numeric_value (INTVAL (exp
));
1363 if (! strcmp (XSTR (exp
, 0), "*"))
1365 if (attr
== 0 || attr
->default_val
== 0)
1366 fatal ("(attr_value \"*\") used in invalid context.");
1367 exp
= attr
->default_val
->value
;
1373 if (!attr
->is_const
|| RTX_UNCHANGING_P (exp
))
1375 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1376 This makes the COND something that won't be considered an arbitrary
1377 expression by walk_attr_value. */
1378 RTX_UNCHANGING_P (exp
) = 1;
1379 exp
= convert_const_symbol_ref (exp
, attr
);
1380 RTX_UNCHANGING_P (exp
) = 1;
1381 exp
= check_attr_value (exp
, attr
);
1382 /* Goto COND case since this is now a COND. Note that while the
1383 new expression is rescanned, all symbol_ref notes are mared as
1388 newexp
= rtx_alloc (COND
);
1389 XVEC (newexp
, 0) = rtvec_alloc (2);
1390 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1391 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1393 XEXP (newexp
, 1) = XEXP (exp
, 2);
1396 /* Fall through to COND case since this is now a COND. */
1404 /* First, check for degenerate COND. */
1405 if (XVECLEN (exp
, 0) == 0)
1406 return make_canonical (attr
, XEXP (exp
, 1));
1407 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1409 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1411 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1412 XVECEXP (exp
, 0, i
+ 1)
1413 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1414 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1430 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1431 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1432 copy_boolean (XEXP (exp
, 1)));
1436 /* Given a value and an attribute description, return a `struct attr_value *'
1437 that represents that value. This is either an existing structure, if the
1438 value has been previously encountered, or a newly-created structure.
1440 `insn_code' is the code of an insn whose attribute has the specified
1441 value (-2 if not processing an insn). We ensure that all insns for
1442 a given value have the same number of alternatives if the value checks
1445 static struct attr_value
*
1446 get_attr_value (value
, attr
, insn_code
)
1448 struct attr_desc
*attr
;
1451 struct attr_value
*av
;
1454 value
= make_canonical (attr
, value
);
1455 if (compares_alternatives_p (value
))
1457 if (insn_code
< 0 || insn_alternatives
== NULL
)
1458 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1460 num_alt
= insn_alternatives
[insn_code
];
1463 for (av
= attr
->first_value
; av
; av
= av
->next
)
1464 if (rtx_equal_p (value
, av
->value
)
1465 && (num_alt
== 0 || av
->first_insn
== NULL
1466 || insn_alternatives
[av
->first_insn
->insn_code
]))
1469 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
1471 av
->next
= attr
->first_value
;
1472 attr
->first_value
= av
;
1473 av
->first_insn
= NULL
;
1475 av
->has_asm_insn
= 0;
1480 /* After all DEFINE_DELAYs have been read in, create internal attributes
1481 to generate the required routines.
1483 First, we compute the number of delay slots for each insn (as a COND of
1484 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1485 delay type is specified, we compute a similar function giving the
1486 DEFINE_DELAY ordinal for each insn.
1488 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1489 tells whether a given insn can be in that delay slot.
1491 Normal attribute filling and optimization expands these to contain the
1492 information needed to handle delay slots. */
1497 struct delay_desc
*delay
;
1503 /* First, generate data for `num_delay_slots' function. */
1505 condexp
= rtx_alloc (COND
);
1506 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1507 XEXP (condexp
, 1) = make_numeric_value (0);
1509 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1511 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1512 XVECEXP (condexp
, 0, i
+ 1)
1513 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1516 make_internal_attr ("*num_delay_slots", condexp
, 0);
1518 /* If more than one delay type, do the same for computing the delay type. */
1521 condexp
= rtx_alloc (COND
);
1522 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1523 XEXP (condexp
, 1) = make_numeric_value (0);
1525 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1527 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1528 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1531 make_internal_attr ("*delay_type", condexp
, 1);
1534 /* For each delay possibility and delay slot, compute an eligibility
1535 attribute for non-annulled insns and for each type of annulled (annul
1536 if true and annul if false). */
1537 for (delay
= delays
; delay
; delay
= delay
->next
)
1539 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1541 condexp
= XVECEXP (delay
->def
, 1, i
);
1542 if (condexp
== 0) condexp
= false_rtx
;
1543 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1544 make_numeric_value (1), make_numeric_value (0));
1546 p
= attr_printf (sizeof ("*delay__") + MAX_DIGITS
*2, "*delay_%d_%d",
1548 make_internal_attr (p
, newexp
, 1);
1550 if (have_annul_true
)
1552 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1553 if (condexp
== 0) condexp
= false_rtx
;
1554 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1555 make_numeric_value (1),
1556 make_numeric_value (0));
1557 p
= attr_printf (sizeof ("*annul_true__") + MAX_DIGITS
*2,
1558 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1559 make_internal_attr (p
, newexp
, 1);
1562 if (have_annul_false
)
1564 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1565 if (condexp
== 0) condexp
= false_rtx
;
1566 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1567 make_numeric_value (1),
1568 make_numeric_value (0));
1569 p
= attr_printf (sizeof ("*annul_false__") + MAX_DIGITS
*2,
1570 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1571 make_internal_attr (p
, newexp
, 1);
1577 /* This function is given a left and right side expression and an operator.
1578 Each side is a conditional expression, each alternative of which has a
1579 numerical value. The function returns another conditional expression
1580 which, for every possible set of condition values, returns a value that is
1581 the operator applied to the values of the two sides.
1583 Since this is called early, it must also support IF_THEN_ELSE. */
1586 operate_exp (op
, left
, right
)
1590 int left_value
, right_value
;
1594 /* If left is a string, apply operator to it and the right side. */
1595 if (GET_CODE (left
) == CONST_STRING
)
1597 /* If right is also a string, just perform the operation. */
1598 if (GET_CODE (right
) == CONST_STRING
)
1600 left_value
= atoi (XSTR (left
, 0));
1601 right_value
= atoi (XSTR (right
, 0));
1605 i
= left_value
+ right_value
;
1609 i
= left_value
- right_value
;
1612 case POS_MINUS_OP
: /* The positive part of LEFT - RIGHT. */
1613 if (left_value
> right_value
)
1614 i
= left_value
- right_value
;
1620 i
= left_value
| right_value
;
1624 i
= left_value
== right_value
;
1628 i
= (left_value
<< (HOST_BITS_PER_INT
/ 2)) | right_value
;
1632 if (left_value
> right_value
)
1639 if (left_value
< right_value
)
1649 return make_numeric_value (i
);
1651 else if (GET_CODE (right
) == IF_THEN_ELSE
)
1653 /* Apply recursively to all values within. */
1654 rtx newleft
= operate_exp (op
, left
, XEXP (right
, 1));
1655 rtx newright
= operate_exp (op
, left
, XEXP (right
, 2));
1656 if (rtx_equal_p (newleft
, newright
))
1658 return attr_rtx (IF_THEN_ELSE
, XEXP (right
, 0), newleft
, newright
);
1660 else if (GET_CODE (right
) == COND
)
1665 newexp
= rtx_alloc (COND
);
1666 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (right
, 0));
1667 defval
= XEXP (newexp
, 1) = operate_exp (op
, left
, XEXP (right
, 1));
1669 for (i
= 0; i
< XVECLEN (right
, 0); i
+= 2)
1671 XVECEXP (newexp
, 0, i
) = XVECEXP (right
, 0, i
);
1672 XVECEXP (newexp
, 0, i
+ 1)
1673 = operate_exp (op
, left
, XVECEXP (right
, 0, i
+ 1));
1674 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1679 /* If the resulting cond is trivial (all alternatives
1680 give the same value), optimize it away. */
1683 obstack_free (rtl_obstack
, newexp
);
1684 return operate_exp (op
, left
, XEXP (right
, 1));
1687 /* If the result is the same as the RIGHT operand,
1689 if (rtx_equal_p (newexp
, right
))
1691 obstack_free (rtl_obstack
, newexp
);
1698 fatal ("Badly formed attribute value");
1701 /* Otherwise, do recursion the other way. */
1702 else if (GET_CODE (left
) == IF_THEN_ELSE
)
1704 rtx newleft
= operate_exp (op
, XEXP (left
, 1), right
);
1705 rtx newright
= operate_exp (op
, XEXP (left
, 2), right
);
1706 if (rtx_equal_p (newleft
, newright
))
1708 return attr_rtx (IF_THEN_ELSE
, XEXP (left
, 0), newleft
, newright
);
1710 else if (GET_CODE (left
) == COND
)
1715 newexp
= rtx_alloc (COND
);
1716 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (left
, 0));
1717 defval
= XEXP (newexp
, 1) = operate_exp (op
, XEXP (left
, 1), right
);
1719 for (i
= 0; i
< XVECLEN (left
, 0); i
+= 2)
1721 XVECEXP (newexp
, 0, i
) = XVECEXP (left
, 0, i
);
1722 XVECEXP (newexp
, 0, i
+ 1)
1723 = operate_exp (op
, XVECEXP (left
, 0, i
+ 1), right
);
1724 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1729 /* If the cond is trivial (all alternatives give the same value),
1730 optimize it away. */
1733 obstack_free (rtl_obstack
, newexp
);
1734 return operate_exp (op
, XEXP (left
, 1), right
);
1737 /* If the result is the same as the LEFT operand,
1739 if (rtx_equal_p (newexp
, left
))
1741 obstack_free (rtl_obstack
, newexp
);
1749 fatal ("Badly formed attribute value.");
1754 /* Once all attributes and DEFINE_FUNCTION_UNITs have been read, we
1755 construct a number of attributes.
1757 The first produces a function `function_units_used' which is given an
1758 insn and produces an encoding showing which function units are required
1759 for the execution of that insn. If the value is non-negative, the insn
1760 uses that unit; otherwise, the value is a one's compliment mask of units
1763 The second produces a function `result_ready_cost' which is used to
1764 determine the time that the result of an insn will be ready and hence
1765 a worst-case schedule.
1767 Both of these produce quite complex expressions which are then set as the
1768 default value of internal attributes. Normal attribute simplification
1769 should produce reasonable expressions.
1771 For each unit, a `<name>_unit_ready_cost' function will take an
1772 insn and give the delay until that unit will be ready with the result
1773 and a `<name>_unit_conflict_cost' function is given an insn already
1774 executing on the unit and a candidate to execute and will give the
1775 cost from the time the executing insn started until the candidate
1776 can start (ignore limitations on the number of simultaneous insns).
1778 For each unit, a `<name>_unit_blockage' function is given an insn
1779 already executing on the unit and a candidate to execute and will
1780 give the delay incurred due to function unit conflicts. The range of
1781 blockage cost values for a given executing insn is given by the
1782 `<name>_unit_blockage_range' function. These values are encoded in
1783 an int where the upper half gives the minimum value and the lower
1784 half gives the maximum value. */
1789 struct function_unit
*unit
, **unit_num
;
1790 struct function_unit_op
*op
, **op_array
, ***unit_ops
;
1795 int i
, j
, u
, num
, nvalues
;
1797 /* Rebuild the condition for the unit to share the RTL expressions.
1798 Sharing is required by simplify_by_exploding. Build the issue delay
1799 expressions. Validate the expressions we were given for the conditions
1800 and conflict vector. Then make attributes for use in the conflict
1803 for (unit
= units
; unit
; unit
= unit
->next
)
1805 unit
->condexp
= check_attr_test (unit
->condexp
, 0);
1807 for (op
= unit
->ops
; op
; op
= op
->next
)
1809 rtx issue_delay
= make_numeric_value (op
->issue_delay
);
1810 rtx issue_exp
= issue_delay
;
1812 /* Build, validate, and simplify the issue delay expression. */
1813 if (op
->conflict_exp
!= true_rtx
)
1814 issue_exp
= attr_rtx (IF_THEN_ELSE
, op
->conflict_exp
,
1815 issue_exp
, make_numeric_value (0));
1816 issue_exp
= check_attr_value (make_canonical (NULL_ATTR
,
1819 issue_exp
= simplify_knowing (issue_exp
, unit
->condexp
);
1820 op
->issue_exp
= issue_exp
;
1822 /* Make an attribute for use in the conflict function if needed. */
1823 unit
->needs_conflict_function
= (unit
->issue_delay
.min
1824 != unit
->issue_delay
.max
);
1825 if (unit
->needs_conflict_function
)
1827 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_cost_") + MAX_DIGITS
,
1828 "*%s_cost_%d", unit
->name
, op
->num
);
1829 make_internal_attr (str
, issue_exp
, 1);
1832 /* Validate the condition. */
1833 op
->condexp
= check_attr_test (op
->condexp
, 0);
1837 /* Compute the mask of function units used. Initially, the unitsmask is
1838 zero. Set up a conditional to compute each unit's contribution. */
1839 unitsmask
= make_numeric_value (0);
1840 newexp
= rtx_alloc (IF_THEN_ELSE
);
1841 XEXP (newexp
, 2) = make_numeric_value (0);
1843 /* Merge each function unit into the unit mask attributes. */
1844 for (unit
= units
; unit
; unit
= unit
->next
)
1846 XEXP (newexp
, 0) = unit
->condexp
;
1847 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1848 unitsmask
= operate_exp (OR_OP
, unitsmask
, newexp
);
1851 /* Simplify the unit mask expression, encode it, and make an attribute
1852 for the function_units_used function. */
1853 unitsmask
= simplify_by_exploding (unitsmask
);
1854 unitsmask
= encode_units_mask (unitsmask
);
1855 make_internal_attr ("*function_units_used", unitsmask
, 2);
1857 /* Create an array of ops for each unit. Add an extra unit for the
1858 result_ready_cost function that has the ops of all other units. */
1859 unit_ops
= (struct function_unit_op
***)
1860 alloca ((num_units
+ 1) * sizeof (struct function_unit_op
**));
1861 unit_num
= (struct function_unit
**)
1862 alloca ((num_units
+ 1) * sizeof (struct function_unit
*));
1864 unit_num
[num_units
] = unit
= (struct function_unit
*)
1865 alloca (sizeof (struct function_unit
));
1866 unit
->num
= num_units
;
1867 unit
->num_opclasses
= 0;
1869 for (unit
= units
; unit
; unit
= unit
->next
)
1871 unit_num
[num_units
]->num_opclasses
+= unit
->num_opclasses
;
1872 unit_num
[unit
->num
] = unit
;
1873 unit_ops
[unit
->num
] = op_array
= (struct function_unit_op
**)
1874 alloca (unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1876 for (op
= unit
->ops
; op
; op
= op
->next
)
1877 op_array
[op
->num
] = op
;
1880 /* Compose the array of ops for the extra unit. */
1881 unit_ops
[num_units
] = op_array
= (struct function_unit_op
**)
1882 alloca (unit_num
[num_units
]->num_opclasses
1883 * sizeof (struct function_unit_op
*));
1885 for (unit
= units
, i
= 0; unit
; i
+= unit
->num_opclasses
, unit
= unit
->next
)
1886 bcopy (unit_ops
[unit
->num
], &op_array
[i
],
1887 unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1889 /* Compute the ready cost function for each unit by computing the
1890 condition for each non-default value. */
1891 for (u
= 0; u
<= num_units
; u
++)
1897 op_array
= unit_ops
[unit
->num
];
1898 num
= unit
->num_opclasses
;
1900 /* Sort the array of ops into increasing ready cost order. */
1901 for (i
= 0; i
< num
; i
++)
1902 for (j
= num
- 1; j
> i
; j
--)
1903 if (op_array
[j
-1]->ready
< op_array
[j
]->ready
)
1906 op_array
[j
] = op_array
[j
-1];
1910 /* Determine how many distinct non-default ready cost values there
1911 are. We use a default ready cost value of 1. */
1912 nvalues
= 0; value
= 1;
1913 for (i
= num
- 1; i
>= 0; i
--)
1914 if (op_array
[i
]->ready
> value
)
1916 value
= op_array
[i
]->ready
;
1921 readycost
= make_numeric_value (1);
1924 /* Construct the ready cost expression as a COND of each value from
1925 the largest to the smallest. */
1926 readycost
= rtx_alloc (COND
);
1927 XVEC (readycost
, 0) = rtvec_alloc (nvalues
* 2);
1928 XEXP (readycost
, 1) = make_numeric_value (1);
1930 nvalues
= 0; orexp
= false_rtx
; value
= op_array
[0]->ready
;
1931 for (i
= 0; i
< num
; i
++)
1936 else if (op
->ready
== value
)
1937 orexp
= insert_right_side (IOR
, orexp
, op
->condexp
, -2, -2);
1940 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
1941 XVECEXP (readycost
, 0, nvalues
* 2 + 1)
1942 = make_numeric_value (value
);
1945 orexp
= op
->condexp
;
1948 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
1949 XVECEXP (readycost
, 0, nvalues
* 2 + 1) = make_numeric_value (value
);
1954 rtx max_blockage
= 0, min_blockage
= 0;
1956 /* Simplify the readycost expression by only considering insns
1957 that use the unit. */
1958 readycost
= simplify_knowing (readycost
, unit
->condexp
);
1960 /* Determine the blockage cost the executing insn (E) given
1961 the candidate insn (C). This is the maximum of the issue
1962 delay, the pipeline delay, and the simultaneity constraint.
1963 Each function_unit_op represents the characteristics of the
1964 candidate insn, so in the expressions below, C is a known
1965 term and E is an unknown term.
1967 We compute the blockage cost for each E for every possible C.
1968 Thus OP represents E, and READYCOST is a list of values for
1971 The issue delay function for C is op->issue_exp and is used to
1972 write the `<name>_unit_conflict_cost' function. Symbolicly
1973 this is "ISSUE-DELAY (E,C)".
1975 The pipeline delay results form the FIFO constraint on the
1976 function unit and is "READY-COST (E) + 1 - READY-COST (C)".
1978 The simultaneity constraint is based on how long it takes to
1979 fill the unit given the minimum issue delay. FILL-TIME is the
1980 constant "MIN (ISSUE-DELAY (*,*)) * (SIMULTANEITY - 1)", and
1981 the simultaneity constraint is "READY-COST (E) - FILL-TIME"
1982 if SIMULTANEITY is non-zero and zero otherwise.
1984 Thus, BLOCKAGE (E,C) when SIMULTANEITY is zero is
1986 MAX (ISSUE-DELAY (E,C),
1987 READY-COST (E) - (READY-COST (C) - 1))
1991 MAX (ISSUE-DELAY (E,C),
1992 READY-COST (E) - (READY-COST (C) - 1),
1993 READY-COST (E) - FILL-TIME)
1995 The `<name>_unit_blockage' function is computed by determining
1996 this value for each candidate insn. As these values are
1997 computed, we also compute the upper and lower bounds for
1998 BLOCKAGE (E,*). These are combined to form the function
1999 `<name>_unit_blockage_range'. Finally, the maximum blockage
2000 cost, MAX (BLOCKAGE (*,*)), is computed. */
2002 for (op
= unit
->ops
; op
; op
= op
->next
)
2004 rtx blockage
= operate_exp (POS_MINUS_OP
, readycost
,
2005 make_numeric_value (1));
2007 if (unit
->simultaneity
!= 0)
2009 rtx filltime
= make_numeric_value ((unit
->simultaneity
- 1)
2010 * unit
->issue_delay
.min
);
2011 blockage
= operate_exp (MIN_OP
, blockage
, filltime
);
2014 blockage
= operate_exp (POS_MINUS_OP
,
2015 make_numeric_value (op
->ready
),
2018 blockage
= operate_exp (MAX_OP
, blockage
, op
->issue_exp
);
2019 blockage
= simplify_knowing (blockage
, unit
->condexp
);
2021 /* Add this op's contribution to MAX (BLOCKAGE (E,*)) and
2022 MIN (BLOCKAGE (E,*)). */
2023 if (max_blockage
== 0)
2024 max_blockage
= min_blockage
= blockage
;
2028 = simplify_knowing (operate_exp (MAX_OP
, max_blockage
,
2032 = simplify_knowing (operate_exp (MIN_OP
, min_blockage
,
2037 /* Make an attribute for use in the blockage function. */
2038 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_block_") + MAX_DIGITS
,
2039 "*%s_block_%d", unit
->name
, op
->num
);
2040 make_internal_attr (str
, blockage
, 1);
2043 /* Record MAX (BLOCKAGE (*,*)). */
2044 unit
->max_blockage
= max_attr_value (max_blockage
);
2046 /* See if the upper and lower bounds of BLOCKAGE (E,*) are the
2047 same. If so, the blockage function carries no additional
2048 information and is not written. */
2049 newexp
= operate_exp (EQ_OP
, max_blockage
, min_blockage
);
2050 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2051 unit
->needs_blockage_function
2052 = (GET_CODE (newexp
) != CONST_STRING
2053 || atoi (XSTR (newexp
, 0)) != 1);
2055 /* If the all values of BLOCKAGE (E,C) have the same value,
2056 neither blockage function is written. */
2057 unit
->needs_range_function
2058 = (unit
->needs_blockage_function
2059 || GET_CODE (max_blockage
) != CONST_STRING
);
2061 if (unit
->needs_range_function
)
2063 /* Compute the blockage range function and make an attribute
2064 for writing it's value. */
2065 newexp
= operate_exp (RANGE_OP
, min_blockage
, max_blockage
);
2066 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2068 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_unit_blockage_range"),
2069 "*%s_unit_blockage_range", unit
->name
);
2070 make_internal_attr (str
, newexp
, 4);
2073 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_unit_ready_cost"),
2074 "*%s_unit_ready_cost", unit
->name
);
2077 str
= "*result_ready_cost";
2079 /* Make an attribute for the ready_cost function. Simplifying
2080 further with simplify_by_exploding doesn't win. */
2081 make_internal_attr (str
, readycost
, 0);
2084 /* For each unit that requires a conflict cost function, make an attribute
2085 that maps insns to the operation number. */
2086 for (unit
= units
; unit
; unit
= unit
->next
)
2090 if (! unit
->needs_conflict_function
2091 && ! unit
->needs_blockage_function
)
2094 caseexp
= rtx_alloc (COND
);
2095 XVEC (caseexp
, 0) = rtvec_alloc ((unit
->num_opclasses
- 1) * 2);
2097 for (op
= unit
->ops
; op
; op
= op
->next
)
2099 /* Make our adjustment to the COND being computed. If we are the
2100 last operation class, place our values into the default of the
2102 if (op
->num
== unit
->num_opclasses
- 1)
2104 XEXP (caseexp
, 1) = make_numeric_value (op
->num
);
2108 XVECEXP (caseexp
, 0, op
->num
* 2) = op
->condexp
;
2109 XVECEXP (caseexp
, 0, op
->num
* 2 + 1)
2110 = make_numeric_value (op
->num
);
2114 /* Simplifying caseexp with simplify_by_exploding doesn't win. */
2115 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_cases"),
2116 "*%s_cases", unit
->name
);
2117 make_internal_attr (str
, caseexp
, 1);
2121 /* Simplify EXP given KNOWN_TRUE. */
2124 simplify_knowing (exp
, known_true
)
2125 rtx exp
, known_true
;
2127 if (GET_CODE (exp
) != CONST_STRING
)
2129 exp
= attr_rtx (IF_THEN_ELSE
, known_true
, exp
,
2130 make_numeric_value (max_attr_value (exp
)));
2131 exp
= simplify_by_exploding (exp
);
2136 /* Translate the CONST_STRING expressions in X to change the encoding of
2137 value. On input, the value is a bitmask with a one bit for each unit
2138 used; on output, the value is the unit number (zero based) if one
2139 and only one unit is used or the one's compliment of the bitmask. */
2142 encode_units_mask (x
)
2147 register enum rtx_code code
;
2150 code
= GET_CODE (x
);
2155 i
= atoi (XSTR (x
, 0));
2157 abort (); /* The sign bit encodes a one's compliment mask. */
2158 else if (i
!= 0 && i
== (i
& -i
))
2159 /* Only one bit is set, so yield that unit number. */
2160 for (j
= 0; (i
>>= 1) != 0; j
++)
2164 return attr_rtx (CONST_STRING
, attr_printf (MAX_DIGITS
, "%d", j
));
2178 /* Compare the elements. If any pair of corresponding elements
2179 fail to match, return 0 for the whole things. */
2181 fmt
= GET_RTX_FORMAT (code
);
2182 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2188 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2189 XVECEXP (x
, i
, j
) = encode_units_mask (XVECEXP (x
, i
, j
));
2193 XEXP (x
, i
) = encode_units_mask (XEXP (x
, i
));
2200 /* Once all attributes and insns have been read and checked, we construct for
2201 each attribute value a list of all the insns that have that value for
2206 struct attr_desc
*attr
;
2208 struct attr_value
*av
;
2209 struct insn_ent
*ie
;
2210 struct insn_def
*id
;
2214 /* Don't fill constant attributes. The value is independent of
2215 any particular insn. */
2219 for (id
= defs
; id
; id
= id
->next
)
2221 /* If no value is specified for this insn for this attribute, use the
2224 if (XVEC (id
->def
, id
->vec_idx
))
2225 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
2226 if (! strcmp (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
2228 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
2231 av
= attr
->default_val
;
2233 av
= get_attr_value (value
, attr
, id
->insn_code
);
2235 ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2236 ie
->insn_code
= id
->insn_code
;
2237 ie
->insn_index
= id
->insn_code
;
2238 insert_insn_ent (av
, ie
);
2242 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
2243 test that checks relative positions of insns (uses MATCH_DUP or PC).
2244 If so, replace it with what is obtained by passing the expression to
2245 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
2246 recursively on each value (including the default value). Otherwise,
2247 return the value returned by NO_ADDRESS_FN applied to EXP. */
2250 substitute_address (exp
, no_address_fn
, address_fn
)
2252 rtx (*no_address_fn
) ();
2253 rtx (*address_fn
) ();
2258 if (GET_CODE (exp
) == COND
)
2260 /* See if any tests use addresses. */
2262 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2263 walk_attr_value (XVECEXP (exp
, 0, i
));
2266 return (*address_fn
) (exp
);
2268 /* Make a new copy of this COND, replacing each element. */
2269 newexp
= rtx_alloc (COND
);
2270 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
2271 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2273 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
2274 XVECEXP (newexp
, 0, i
+ 1)
2275 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
2276 no_address_fn
, address_fn
);
2279 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
2280 no_address_fn
, address_fn
);
2285 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
2288 walk_attr_value (XEXP (exp
, 0));
2290 return (*address_fn
) (exp
);
2292 return attr_rtx (IF_THEN_ELSE
,
2293 substitute_address (XEXP (exp
, 0),
2294 no_address_fn
, address_fn
),
2295 substitute_address (XEXP (exp
, 1),
2296 no_address_fn
, address_fn
),
2297 substitute_address (XEXP (exp
, 2),
2298 no_address_fn
, address_fn
));
2301 return (*no_address_fn
) (exp
);
2304 /* Make new attributes from the `length' attribute. The following are made,
2305 each corresponding to a function called from `shorten_branches' or
2308 *insn_default_length This is the length of the insn to be returned
2309 by `get_attr_length' before `shorten_branches'
2310 has been called. In each case where the length
2311 depends on relative addresses, the largest
2312 possible is used. This routine is also used
2313 to compute the initial size of the insn.
2315 *insn_variable_length_p This returns 1 if the insn's length depends
2316 on relative addresses, zero otherwise.
2318 *insn_current_length This is only called when it is known that the
2319 insn has a variable length and returns the
2320 current length, based on relative addresses.
2324 make_length_attrs ()
2326 static char *new_names
[] = {"*insn_default_length",
2327 "*insn_variable_length_p",
2328 "*insn_current_length"};
2329 static rtx (*no_address_fn
[]) PROTO((rtx
)) = {identity_fn
, zero_fn
, zero_fn
};
2330 static rtx (*address_fn
[]) PROTO((rtx
)) = {max_fn
, one_fn
, identity_fn
};
2332 struct attr_desc
*length_attr
, *new_attr
;
2333 struct attr_value
*av
, *new_av
;
2334 struct insn_ent
*ie
, *new_ie
;
2336 /* See if length attribute is defined. If so, it must be numeric. Make
2337 it special so we don't output anything for it. */
2338 length_attr
= find_attr ("length", 0);
2339 if (length_attr
== 0)
2342 if (! length_attr
->is_numeric
)
2343 fatal ("length attribute must be numeric.");
2345 length_attr
->is_const
= 0;
2346 length_attr
->is_special
= 1;
2348 /* Make each new attribute, in turn. */
2349 for (i
= 0; i
< sizeof new_names
/ sizeof new_names
[0]; i
++)
2351 make_internal_attr (new_names
[i
],
2352 substitute_address (length_attr
->default_val
->value
,
2353 no_address_fn
[i
], address_fn
[i
]),
2355 new_attr
= find_attr (new_names
[i
], 0);
2356 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2357 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2359 new_av
= get_attr_value (substitute_address (av
->value
,
2362 new_attr
, ie
->insn_code
);
2363 new_ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2364 new_ie
->insn_code
= ie
->insn_code
;
2365 new_ie
->insn_index
= ie
->insn_index
;
2366 insert_insn_ent (new_av
, new_ie
);
2371 /* Utility functions called from above routine. */
2384 return make_numeric_value (0);
2391 return make_numeric_value (1);
2398 return make_numeric_value (max_attr_value (exp
));
2401 /* Take a COND expression and see if any of the conditions in it can be
2402 simplified. If any are known true or known false for the particular insn
2403 code, the COND can be further simplified.
2405 Also call ourselves on any COND operations that are values of this COND.
2407 We do not modify EXP; rather, we make and return a new rtx. */
2410 simplify_cond (exp
, insn_code
, insn_index
)
2412 int insn_code
, insn_index
;
2415 /* We store the desired contents here,
2416 then build a new expression if they don't match EXP. */
2417 rtx defval
= XEXP (exp
, 1);
2418 rtx new_defval
= XEXP (exp
, 1);
2420 int len
= XVECLEN (exp
, 0);
2421 rtx
*tests
= (rtx
*) alloca (len
* sizeof (rtx
));
2425 /* This lets us free all storage allocated below, if appropriate. */
2426 first_spacer
= (char *) obstack_finish (rtl_obstack
);
2428 bcopy (&XVECEXP (exp
, 0, 0), tests
, len
* sizeof (rtx
));
2430 /* See if default value needs simplification. */
2431 if (GET_CODE (defval
) == COND
)
2432 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
2434 /* Simplify the subexpressions, and see what tests we can get rid of. */
2436 for (i
= 0; i
< len
; i
+= 2)
2438 rtx newtest
, newval
;
2440 /* Simplify this test. */
2441 newtest
= SIMPLIFY_TEST_EXP (tests
[i
], insn_code
, insn_index
);
2444 newval
= tests
[i
+ 1];
2445 /* See if this value may need simplification. */
2446 if (GET_CODE (newval
) == COND
)
2447 newval
= simplify_cond (newval
, insn_code
, insn_index
);
2449 /* Look for ways to delete or combine this test. */
2450 if (newtest
== true_rtx
)
2452 /* If test is true, make this value the default
2453 and discard this + any following tests. */
2455 defval
= tests
[i
+ 1];
2456 new_defval
= newval
;
2459 else if (newtest
== false_rtx
)
2461 /* If test is false, discard it and its value. */
2462 for (j
= i
; j
< len
- 2; j
++)
2463 tests
[j
] = tests
[j
+ 2];
2467 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
2469 /* If this value and the value for the prev test are the same,
2473 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
2474 insn_code
, insn_index
);
2476 /* Delete this test/value. */
2477 for (j
= i
; j
< len
- 2; j
++)
2478 tests
[j
] = tests
[j
+ 2];
2483 tests
[i
+ 1] = newval
;
2486 /* If the last test in a COND has the same value
2487 as the default value, that test isn't needed. */
2489 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
2492 /* See if we changed anything. */
2493 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
2496 for (i
= 0; i
< len
; i
++)
2497 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
2505 obstack_free (rtl_obstack
, first_spacer
);
2506 if (GET_CODE (defval
) == COND
)
2507 return simplify_cond (defval
, insn_code
, insn_index
);
2512 obstack_free (rtl_obstack
, first_spacer
);
2517 rtx newexp
= rtx_alloc (COND
);
2519 XVEC (newexp
, 0) = rtvec_alloc (len
);
2520 bcopy (tests
, &XVECEXP (newexp
, 0, 0), len
* sizeof (rtx
));
2521 XEXP (newexp
, 1) = new_defval
;
2526 /* Remove an insn entry from an attribute value. */
2529 remove_insn_ent (av
, ie
)
2530 struct attr_value
*av
;
2531 struct insn_ent
*ie
;
2533 struct insn_ent
*previe
;
2535 if (av
->first_insn
== ie
)
2536 av
->first_insn
= ie
->next
;
2539 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
2541 previe
->next
= ie
->next
;
2545 if (ie
->insn_code
== -1)
2546 av
->has_asm_insn
= 0;
2549 /* Insert an insn entry in an attribute value list. */
2552 insert_insn_ent (av
, ie
)
2553 struct attr_value
*av
;
2554 struct insn_ent
*ie
;
2556 ie
->next
= av
->first_insn
;
2557 av
->first_insn
= ie
;
2559 if (ie
->insn_code
== -1)
2560 av
->has_asm_insn
= 1;
2563 /* This is a utility routine to take an expression that is a tree of either
2564 AND or IOR expressions and insert a new term. The new term will be
2565 inserted at the right side of the first node whose code does not match
2566 the root. A new node will be created with the root's code. Its left
2567 side will be the old right side and its right side will be the new
2570 If the `term' is itself a tree, all its leaves will be inserted. */
2573 insert_right_side (code
, exp
, term
, insn_code
, insn_index
)
2577 int insn_code
, insn_index
;
2581 /* Avoid consing in some special cases. */
2582 if (code
== AND
&& term
== true_rtx
)
2584 if (code
== AND
&& term
== false_rtx
)
2586 if (code
== AND
&& exp
== true_rtx
)
2588 if (code
== AND
&& exp
== false_rtx
)
2590 if (code
== IOR
&& term
== true_rtx
)
2592 if (code
== IOR
&& term
== false_rtx
)
2594 if (code
== IOR
&& exp
== true_rtx
)
2596 if (code
== IOR
&& exp
== false_rtx
)
2598 if (attr_equal_p (exp
, term
))
2601 if (GET_CODE (term
) == code
)
2603 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
2604 insn_code
, insn_index
);
2605 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
2606 insn_code
, insn_index
);
2611 if (GET_CODE (exp
) == code
)
2613 rtx
new = insert_right_side (code
, XEXP (exp
, 1),
2614 term
, insn_code
, insn_index
);
2615 if (new != XEXP (exp
, 1))
2616 /* Make a copy of this expression and call recursively. */
2617 newexp
= attr_rtx (code
, XEXP (exp
, 0), new);
2623 /* Insert the new term. */
2624 newexp
= attr_rtx (code
, exp
, term
);
2627 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2630 /* If we have an expression which AND's a bunch of
2631 (not (eq_attrq "alternative" "n"))
2632 terms, we may have covered all or all but one of the possible alternatives.
2633 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
2635 This routine is passed an expression and either AND or IOR. It returns a
2636 bitmask indicating which alternatives are mentioned within EXP. */
2639 compute_alternative_mask (exp
, code
)
2644 if (GET_CODE (exp
) == code
)
2645 return compute_alternative_mask (XEXP (exp
, 0), code
)
2646 | compute_alternative_mask (XEXP (exp
, 1), code
);
2648 else if (code
== AND
&& GET_CODE (exp
) == NOT
2649 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2650 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
2651 string
= XSTR (XEXP (exp
, 0), 1);
2653 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
2654 && XSTR (exp
, 0) == alternative_name
)
2655 string
= XSTR (exp
, 1);
2661 return 1 << (string
[0] - '0');
2662 return 1 << atoi (string
);
2665 /* Given I, a single-bit mask, return RTX to compare the `alternative'
2666 attribute with the value represented by that bit. */
2669 make_alternative_compare (mask
)
2676 for (i
= 0; (mask
& (1 << i
)) == 0; i
++)
2679 newexp
= attr_rtx (EQ_ATTR
, alternative_name
, attr_numeral (i
));
2680 RTX_UNCHANGING_P (newexp
) = 1;
2685 /* If we are processing an (eq_attr "attr" "value") test, we find the value
2686 of "attr" for this insn code. From that value, we can compute a test
2687 showing when the EQ_ATTR will be true. This routine performs that
2688 computation. If a test condition involves an address, we leave the EQ_ATTR
2689 intact because addresses are only valid for the `length' attribute.
2691 EXP is the EQ_ATTR expression and VALUE is the value of that attribute
2692 for the insn corresponding to INSN_CODE and INSN_INDEX. */
2695 evaluate_eq_attr (exp
, value
, insn_code
, insn_index
)
2698 int insn_code
, insn_index
;
2705 if (GET_CODE (value
) == CONST_STRING
)
2707 if (! strcmp (XSTR (value
, 0), XSTR (exp
, 1)))
2712 else if (GET_CODE (value
) == COND
)
2714 /* We construct an IOR of all the cases for which the requested attribute
2715 value is present. Since we start with FALSE, if it is not present,
2716 FALSE will be returned.
2718 Each case is the AND of the NOT's of the previous conditions with the
2719 current condition; in the default case the current condition is TRUE.
2721 For each possible COND value, call ourselves recursively.
2723 The extra TRUE and FALSE expressions will be eliminated by another
2724 call to the simplification routine. */
2729 if (current_alternative_string
)
2730 clear_struct_flag (value
);
2732 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2734 rtx
this = SIMPLIFY_TEST_EXP (XVECEXP (value
, 0, i
),
2735 insn_code
, insn_index
);
2737 SIMPLIFY_ALTERNATIVE (this);
2739 right
= insert_right_side (AND
, andexp
, this,
2740 insn_code
, insn_index
);
2741 right
= insert_right_side (AND
, right
,
2742 evaluate_eq_attr (exp
,
2745 insn_code
, insn_index
),
2746 insn_code
, insn_index
);
2747 orexp
= insert_right_side (IOR
, orexp
, right
,
2748 insn_code
, insn_index
);
2750 /* Add this condition into the AND expression. */
2751 newexp
= attr_rtx (NOT
, this);
2752 andexp
= insert_right_side (AND
, andexp
, newexp
,
2753 insn_code
, insn_index
);
2756 /* Handle the default case. */
2757 right
= insert_right_side (AND
, andexp
,
2758 evaluate_eq_attr (exp
, XEXP (value
, 1),
2759 insn_code
, insn_index
),
2760 insn_code
, insn_index
);
2761 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2766 /* If uses an address, must return original expression. But set the
2767 RTX_UNCHANGING_P bit so we don't try to simplify it again. */
2770 walk_attr_value (newexp
);
2774 /* This had `&& current_alternative_string', which seems to be wrong. */
2775 if (! RTX_UNCHANGING_P (exp
))
2776 return copy_rtx_unchanging (exp
);
2783 /* This routine is called when an AND of a term with a tree of AND's is
2784 encountered. If the term or its complement is present in the tree, it
2785 can be replaced with TRUE or FALSE, respectively.
2787 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2788 be true and hence are complementary.
2790 There is one special case: If we see
2791 (and (not (eq_attr "att" "v1"))
2792 (eq_attr "att" "v2"))
2793 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2794 replace the term, not anything in the AND tree. So we pass a pointer to
2798 simplify_and_tree (exp
, pterm
, insn_code
, insn_index
)
2801 int insn_code
, insn_index
;
2806 int left_eliminates_term
, right_eliminates_term
;
2808 if (GET_CODE (exp
) == AND
)
2810 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2811 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2812 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2814 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2816 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2820 else if (GET_CODE (exp
) == IOR
)
2822 /* For the IOR case, we do the same as above, except that we can
2823 only eliminate `term' if both sides of the IOR would do so. */
2825 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2826 left_eliminates_term
= (temp
== true_rtx
);
2829 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2830 right_eliminates_term
= (temp
== true_rtx
);
2832 if (left_eliminates_term
&& right_eliminates_term
)
2835 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2837 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2839 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2843 /* Check for simplifications. Do some extra checking here since this
2844 routine is called so many times. */
2849 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
2852 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
2855 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
2857 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
2860 if (! strcmp (XSTR (exp
, 1), XSTR (*pterm
, 1)))
2866 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2867 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
2869 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
2872 if (! strcmp (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
2878 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2879 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
2881 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
2884 if (! strcmp (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
2890 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
2892 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
2896 else if (GET_CODE (exp
) == NOT
)
2898 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
2902 else if (GET_CODE (*pterm
) == NOT
)
2904 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
2908 else if (attr_equal_p (exp
, *pterm
))
2914 /* Similar to `simplify_and_tree', but for IOR trees. */
2917 simplify_or_tree (exp
, pterm
, insn_code
, insn_index
)
2920 int insn_code
, insn_index
;
2925 int left_eliminates_term
, right_eliminates_term
;
2927 if (GET_CODE (exp
) == IOR
)
2929 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2930 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2931 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2933 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2935 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2939 else if (GET_CODE (exp
) == AND
)
2941 /* For the AND case, we do the same as above, except that we can
2942 only eliminate `term' if both sides of the AND would do so. */
2944 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2945 left_eliminates_term
= (temp
== false_rtx
);
2948 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2949 right_eliminates_term
= (temp
== false_rtx
);
2951 if (left_eliminates_term
&& right_eliminates_term
)
2954 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2956 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2958 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2962 if (attr_equal_p (exp
, *pterm
))
2965 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
2968 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
2971 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2972 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2973 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
2976 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2977 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
2978 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
2984 /* Given an expression, see if it can be simplified for a particular insn
2985 code based on the values of other attributes being tested. This can
2986 eliminate nested get_attr_... calls.
2988 Note that if an endless recursion is specified in the patterns, the
2989 optimization will loop. However, it will do so in precisely the cases where
2990 an infinite recursion loop could occur during compilation. It's better that
2994 simplify_test_exp (exp
, insn_code
, insn_index
)
2996 int insn_code
, insn_index
;
2999 struct attr_desc
*attr
;
3000 struct attr_value
*av
;
3001 struct insn_ent
*ie
;
3004 char *spacer
= (char *) obstack_finish (rtl_obstack
);
3006 /* Don't re-simplify something we already simplified. */
3007 if (RTX_UNCHANGING_P (exp
) || MEM_IN_STRUCT_P (exp
))
3010 switch (GET_CODE (exp
))
3013 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3014 SIMPLIFY_ALTERNATIVE (left
);
3015 if (left
== false_rtx
)
3017 obstack_free (rtl_obstack
, spacer
);
3020 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3021 SIMPLIFY_ALTERNATIVE (right
);
3022 if (left
== false_rtx
)
3024 obstack_free (rtl_obstack
, spacer
);
3028 /* If either side is an IOR and we have (eq_attr "alternative" ..")
3029 present on both sides, apply the distributive law since this will
3030 yield simplifications. */
3031 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
3032 && compute_alternative_mask (left
, IOR
)
3033 && compute_alternative_mask (right
, IOR
))
3035 if (GET_CODE (left
) == IOR
)
3042 newexp
= attr_rtx (IOR
,
3043 attr_rtx (AND
, left
, XEXP (right
, 0)),
3044 attr_rtx (AND
, left
, XEXP (right
, 1)));
3046 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3049 /* Try with the term on both sides. */
3050 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
3051 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3052 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
3054 if (left
== false_rtx
|| right
== false_rtx
)
3056 obstack_free (rtl_obstack
, spacer
);
3059 else if (left
== true_rtx
)
3063 else if (right
== true_rtx
)
3067 /* See if all or all but one of the insn's alternatives are specified
3068 in this tree. Optimize if so. */
3070 else if (insn_code
>= 0
3071 && (GET_CODE (left
) == AND
3072 || (GET_CODE (left
) == NOT
3073 && GET_CODE (XEXP (left
, 0)) == EQ_ATTR
3074 && XSTR (XEXP (left
, 0), 0) == alternative_name
)
3075 || GET_CODE (right
) == AND
3076 || (GET_CODE (right
) == NOT
3077 && GET_CODE (XEXP (right
, 0)) == EQ_ATTR
3078 && XSTR (XEXP (right
, 0), 0) == alternative_name
)))
3080 i
= compute_alternative_mask (exp
, AND
);
3081 if (i
& ~insn_alternatives
[insn_code
])
3082 fatal ("Illegal alternative specified for pattern number %d",
3085 /* If all alternatives are excluded, this is false. */
3086 i
^= insn_alternatives
[insn_code
];
3089 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3091 /* If just one excluded, AND a comparison with that one to the
3092 front of the tree. The others will be eliminated by
3093 optimization. We do not want to do this if the insn has one
3094 alternative and we have tested none of them! */
3095 left
= make_alternative_compare (i
);
3096 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3097 newexp
= attr_rtx (AND
, left
, right
);
3099 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3103 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3105 newexp
= attr_rtx (AND
, left
, right
);
3106 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3111 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3112 SIMPLIFY_ALTERNATIVE (left
);
3113 if (left
== true_rtx
)
3115 obstack_free (rtl_obstack
, spacer
);
3118 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3119 SIMPLIFY_ALTERNATIVE (right
);
3120 if (right
== true_rtx
)
3122 obstack_free (rtl_obstack
, spacer
);
3126 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
3127 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3128 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
3130 if (right
== true_rtx
|| left
== true_rtx
)
3132 obstack_free (rtl_obstack
, spacer
);
3135 else if (left
== false_rtx
)
3139 else if (right
== false_rtx
)
3144 /* Test for simple cases where the distributive law is useful. I.e.,
3145 convert (ior (and (x) (y))
3151 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
3152 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
3154 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
3156 left
= XEXP (left
, 0);
3158 newexp
= attr_rtx (AND
, left
, right
);
3159 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3162 /* See if all or all but one of the insn's alternatives are specified
3163 in this tree. Optimize if so. */
3165 else if (insn_code
>= 0
3166 && (GET_CODE (left
) == IOR
3167 || (GET_CODE (left
) == EQ_ATTR
3168 && XSTR (left
, 0) == alternative_name
)
3169 || GET_CODE (right
) == IOR
3170 || (GET_CODE (right
) == EQ_ATTR
3171 && XSTR (right
, 0) == alternative_name
)))
3173 i
= compute_alternative_mask (exp
, IOR
);
3174 if (i
& ~insn_alternatives
[insn_code
])
3175 fatal ("Illegal alternative specified for pattern number %d",
3178 /* If all alternatives are included, this is true. */
3179 i
^= insn_alternatives
[insn_code
];
3182 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3184 /* If just one excluded, IOR a comparison with that one to the
3185 front of the tree. The others will be eliminated by
3186 optimization. We do not want to do this if the insn has one
3187 alternative and we have tested none of them! */
3188 left
= make_alternative_compare (i
);
3189 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3190 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
3192 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3196 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3198 newexp
= attr_rtx (IOR
, left
, right
);
3199 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3204 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
3206 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
3207 insn_code
, insn_index
);
3208 SIMPLIFY_ALTERNATIVE (left
);
3212 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3213 SIMPLIFY_ALTERNATIVE (left
);
3214 if (GET_CODE (left
) == NOT
)
3215 return XEXP (left
, 0);
3217 if (left
== false_rtx
)
3219 obstack_free (rtl_obstack
, spacer
);
3222 else if (left
== true_rtx
)
3224 obstack_free (rtl_obstack
, spacer
);
3228 /* Try to apply De`Morgan's laws. */
3229 else if (GET_CODE (left
) == IOR
)
3231 newexp
= attr_rtx (AND
,
3232 attr_rtx (NOT
, XEXP (left
, 0)),
3233 attr_rtx (NOT
, XEXP (left
, 1)));
3235 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3237 else if (GET_CODE (left
) == AND
)
3239 newexp
= attr_rtx (IOR
,
3240 attr_rtx (NOT
, XEXP (left
, 0)),
3241 attr_rtx (NOT
, XEXP (left
, 1)));
3243 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3245 else if (left
!= XEXP (exp
, 0))
3247 newexp
= attr_rtx (NOT
, left
);
3252 if (current_alternative_string
&& XSTR (exp
, 0) == alternative_name
)
3253 return (XSTR (exp
, 1) == current_alternative_string
3254 ? true_rtx
: false_rtx
);
3256 /* Look at the value for this insn code in the specified attribute.
3257 We normally can replace this comparison with the condition that
3258 would give this insn the values being tested for. */
3259 if (XSTR (exp
, 0) != alternative_name
3260 && (attr
= find_attr (XSTR (exp
, 0), 0)) != NULL
)
3261 for (av
= attr
->first_value
; av
; av
= av
->next
)
3262 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3263 if (ie
->insn_code
== insn_code
)
3264 return evaluate_eq_attr (exp
, av
->value
, insn_code
, insn_index
);
3267 /* We have already simplified this expression. Simplifying it again
3268 won't buy anything unless we weren't given a valid insn code
3269 to process (i.e., we are canonicalizing something.). */
3270 if (insn_code
!= -2 /* Seems wrong: && current_alternative_string. */
3271 && ! RTX_UNCHANGING_P (newexp
))
3272 return copy_rtx_unchanging (newexp
);
3277 /* Optimize the attribute lists by seeing if we can determine conditional
3278 values from the known values of other attributes. This will save subroutine
3279 calls during the compilation. */
3284 struct attr_desc
*attr
;
3285 struct attr_value
*av
;
3286 struct insn_ent
*ie
;
3288 int something_changed
= 1;
3290 struct attr_value_list
{ struct attr_value
*av
;
3291 struct insn_ent
*ie
;
3292 struct attr_desc
* attr
;
3293 struct attr_value_list
*next
; };
3294 struct attr_value_list
**insn_code_values
;
3295 struct attr_value_list
*iv
;
3297 /* For each insn code, make a list of all the insn_ent's for it,
3298 for all values for all attributes. */
3300 /* Make 2 extra elements, for "code" values -2 and -1. */
3302 = (struct attr_value_list
**) alloca ((insn_code_number
+ 2)
3303 * sizeof (struct attr_value_list
*));
3304 bzero (insn_code_values
,
3305 (insn_code_number
+ 2) * sizeof (struct attr_value_list
*));
3306 /* Offset the table address so we can index by -2 or -1. */
3307 insn_code_values
+= 2;
3309 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
3310 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
3311 for (av
= attr
->first_value
; av
; av
= av
->next
)
3312 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3314 iv
= ((struct attr_value_list
*)
3315 alloca (sizeof (struct attr_value_list
)));
3319 iv
->next
= insn_code_values
[ie
->insn_code
];
3320 insn_code_values
[ie
->insn_code
] = iv
;
3323 /* Process one insn code at a time. */
3324 for (i
= -2; i
< insn_code_number
; i
++)
3326 /* Clear the MEM_IN_STRUCT_P flag everywhere relevant.
3327 We use it to mean "already simplified for this insn". */
3328 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3329 clear_struct_flag (iv
->av
->value
);
3331 /* Loop until nothing changes for one iteration. */
3332 something_changed
= 1;
3333 while (something_changed
)
3335 something_changed
= 0;
3336 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3338 struct obstack
*old
= rtl_obstack
;
3339 char *spacer
= (char *) obstack_finish (temp_obstack
);
3344 if (GET_CODE (av
->value
) != COND
)
3347 rtl_obstack
= temp_obstack
;
3348 #if 0 /* This was intended as a speed up, but it was slower. */
3349 if (insn_n_alternatives
[ie
->insn_code
] > 6
3350 && count_sub_rtxs (av
->value
, 200) >= 200)
3351 newexp
= simplify_by_alternatives (av
->value
, ie
->insn_code
,
3355 newexp
= simplify_cond (av
->value
, ie
->insn_code
,
3359 if (newexp
!= av
->value
)
3361 newexp
= attr_copy_rtx (newexp
);
3362 remove_insn_ent (av
, ie
);
3363 av
= get_attr_value (newexp
, attr
, ie
->insn_code
);
3365 insert_insn_ent (av
, ie
);
3366 something_changed
= 1;
3368 obstack_free (temp_obstack
, spacer
);
3376 simplify_by_alternatives (exp
, insn_code
, insn_index
)
3378 int insn_code
, insn_index
;
3381 int len
= insn_n_alternatives
[insn_code
];
3382 rtx newexp
= rtx_alloc (COND
);
3386 XVEC (newexp
, 0) = rtvec_alloc (len
* 2);
3388 /* It will not matter what value we use as the default value
3389 of the new COND, since that default will never be used.
3390 Choose something of the right type. */
3391 for (ultimate
= exp
; GET_CODE (ultimate
) == COND
;)
3392 ultimate
= XEXP (ultimate
, 1);
3393 XEXP (newexp
, 1) = ultimate
;
3395 for (i
= 0; i
< insn_n_alternatives
[insn_code
]; i
++)
3397 current_alternative_string
= attr_numeral (i
);
3398 XVECEXP (newexp
, 0, i
* 2) = make_alternative_compare (1 << i
);
3399 XVECEXP (newexp
, 0, i
* 2 + 1)
3400 = simplify_cond (exp
, insn_code
, insn_index
);
3403 current_alternative_string
= 0;
3404 return simplify_cond (newexp
, insn_code
, insn_index
);
3408 /* If EXP is a suitable expression, reorganize it by constructing an
3409 equivalent expression that is a COND with the tests being all combinations
3410 of attribute values and the values being simple constants. */
3413 simplify_by_exploding (exp
)
3416 rtx list
= 0, link
, condexp
, defval
;
3417 struct dimension
*space
;
3418 rtx
*condtest
, *condval
;
3419 int i
, j
, total
, ndim
= 0;
3420 int most_tests
, num_marks
, new_marks
;
3422 /* Locate all the EQ_ATTR expressions. */
3423 if (! find_and_mark_used_attributes (exp
, &list
, &ndim
) || ndim
== 0)
3425 unmark_used_attributes (list
, 0, 0);
3429 /* Create an attribute space from the list of used attributes. For each
3430 dimension in the attribute space, record the attribute, list of values
3431 used, and number of values used. Add members to the list of values to
3432 cover the domain of the attribute. This makes the expanded COND form
3433 order independent. */
3435 space
= (struct dimension
*) alloca (ndim
* sizeof (struct dimension
));
3438 for (ndim
= 0; list
; ndim
++)
3440 /* Pull the first attribute value from the list and record that
3441 attribute as another dimension in the attribute space. */
3442 char *name
= XSTR (XEXP (list
, 0), 0);
3445 if ((space
[ndim
].attr
= find_attr (name
, 0)) == 0
3446 || space
[ndim
].attr
->is_numeric
)
3448 unmark_used_attributes (list
, space
, ndim
);
3452 /* Add all remaining attribute values that refer to this attribute. */
3453 space
[ndim
].num_values
= 0;
3454 space
[ndim
].values
= 0;
3456 for (link
= list
; link
; link
= *prev
)
3457 if (! strcmp (XSTR (XEXP (link
, 0), 0), name
))
3459 space
[ndim
].num_values
++;
3460 *prev
= XEXP (link
, 1);
3461 XEXP (link
, 1) = space
[ndim
].values
;
3462 space
[ndim
].values
= link
;
3465 prev
= &XEXP (link
, 1);
3467 /* Add sufficient members to the list of values to make the list
3468 mutually exclusive and record the total size of the attribute
3470 total
*= add_values_to_cover (&space
[ndim
]);
3473 /* Sort the attribute space so that the attributes go from non-constant
3474 to constant and from most values to least values. */
3475 for (i
= 0; i
< ndim
; i
++)
3476 for (j
= ndim
- 1; j
> i
; j
--)
3477 if ((space
[j
-1].attr
->is_const
&& !space
[j
].attr
->is_const
)
3478 || space
[j
-1].num_values
< space
[j
].num_values
)
3480 struct dimension tmp
;
3482 space
[j
] = space
[j
-1];
3486 /* Establish the initial current value. */
3487 for (i
= 0; i
< ndim
; i
++)
3488 space
[i
].current_value
= space
[i
].values
;
3490 condtest
= (rtx
*) alloca (total
* sizeof (rtx
));
3491 condval
= (rtx
*) alloca (total
* sizeof (rtx
));
3493 /* Expand the tests and values by iterating over all values in the
3497 condtest
[i
] = test_for_current_value (space
, ndim
);
3498 condval
[i
] = simplify_with_current_value (exp
, space
, ndim
);
3499 if (! increment_current_value (space
, ndim
))
3505 /* We are now finished with the original expression. */
3506 unmark_used_attributes (0, space
, ndim
);
3508 /* Find the most used constant value and make that the default. */
3510 for (i
= num_marks
= 0; i
< total
; i
++)
3511 if (GET_CODE (condval
[i
]) == CONST_STRING
3512 && ! MEM_VOLATILE_P (condval
[i
]))
3514 /* Mark the unmarked constant value and count how many are marked. */
3515 MEM_VOLATILE_P (condval
[i
]) = 1;
3516 for (j
= new_marks
= 0; j
< total
; j
++)
3517 if (GET_CODE (condval
[j
]) == CONST_STRING
3518 && MEM_VOLATILE_P (condval
[j
]))
3520 if (new_marks
- num_marks
> most_tests
)
3522 most_tests
= new_marks
- num_marks
;
3523 defval
= condval
[i
];
3525 num_marks
= new_marks
;
3527 /* Clear all the marks. */
3528 for (i
= 0; i
< total
; i
++)
3529 MEM_VOLATILE_P (condval
[i
]) = 0;
3531 /* Give up if nothing is constant. */
3535 /* If all values are the default, use that. */
3536 if (total
== most_tests
)
3539 /* Make a COND with the most common constant value the default. (A more
3540 complex method where tests with the same value were combined didn't
3541 seem to improve things.) */
3542 condexp
= rtx_alloc (COND
);
3543 XVEC (condexp
, 0) = rtvec_alloc ((total
- most_tests
) * 2);
3544 XEXP (condexp
, 1) = defval
;
3545 for (i
= j
= 0; i
< total
; i
++)
3546 if (condval
[i
] != defval
)
3548 XVECEXP (condexp
, 0, 2 * j
) = condtest
[i
];
3549 XVECEXP (condexp
, 0, 2 * j
+ 1) = condval
[i
];
3556 /* Set the MEM_VOLATILE_P flag for all EQ_ATTR expressions in EXP and
3557 verify that EXP can be simplified to a constant term if all the EQ_ATTR
3558 tests have known value. */
3561 find_and_mark_used_attributes (exp
, terms
, nterms
)
3567 switch (GET_CODE (exp
))
3570 if (! MEM_VOLATILE_P (exp
))
3572 rtx link
= rtx_alloc (EXPR_LIST
);
3573 XEXP (link
, 0) = exp
;
3574 XEXP (link
, 1) = *terms
;
3577 MEM_VOLATILE_P (exp
) = 1;
3583 if (! find_and_mark_used_attributes (XEXP (exp
, 2), terms
, nterms
))
3587 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3590 if (! find_and_mark_used_attributes (XEXP (exp
, 0), terms
, nterms
))
3595 for (i
= 0; i
< XVECLEN (exp
, 0); i
++)
3596 if (! find_and_mark_used_attributes (XVECEXP (exp
, 0, i
), terms
, nterms
))
3598 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3606 /* Clear the MEM_VOLATILE_P flag in all EQ_ATTR expressions on LIST and
3607 in the values of the NDIM-dimensional attribute space SPACE. */
3610 unmark_used_attributes (list
, space
, ndim
)
3612 struct dimension
*space
;
3618 for (i
= 0; i
< ndim
; i
++)
3619 unmark_used_attributes (space
[i
].values
, 0, 0);
3621 for (link
= list
; link
; link
= XEXP (link
, 1))
3623 exp
= XEXP (link
, 0);
3624 if (GET_CODE (exp
) == EQ_ATTR
)
3625 MEM_VOLATILE_P (exp
) = 0;
3629 /* Update the attribute dimension DIM so that all values of the attribute
3630 are tested. Return the updated number of values. */
3633 add_values_to_cover (dim
)
3634 struct dimension
*dim
;
3636 struct attr_value
*av
;
3637 rtx exp
, link
, *prev
;
3640 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3641 if (GET_CODE (av
->value
) == CONST_STRING
)
3644 if (nalt
< dim
->num_values
)
3646 else if (nalt
== dim
->num_values
)
3648 else if (nalt
* 2 < dim
->num_values
* 3)
3650 /* Most all the values of the attribute are used, so add all the unused
3652 prev
= &dim
->values
;
3653 for (link
= dim
->values
; link
; link
= *prev
)
3654 prev
= &XEXP (link
, 1);
3656 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3657 if (GET_CODE (av
->value
) == CONST_STRING
)
3659 exp
= attr_eq (dim
->attr
->name
, XSTR (av
->value
, 0));
3660 if (MEM_VOLATILE_P (exp
))
3663 link
= rtx_alloc (EXPR_LIST
);
3664 XEXP (link
, 0) = exp
;
3667 prev
= &XEXP (link
, 1);
3669 dim
->num_values
= nalt
;
3673 rtx orexp
= false_rtx
;
3675 /* Very few values are used, so compute a mutually exclusive
3676 expression. (We could do this for numeric values if that becomes
3678 prev
= &dim
->values
;
3679 for (link
= dim
->values
; link
; link
= *prev
)
3681 orexp
= insert_right_side (IOR
, orexp
, XEXP (link
, 0), -2, -2);
3682 prev
= &XEXP (link
, 1);
3684 link
= rtx_alloc (EXPR_LIST
);
3685 XEXP (link
, 0) = attr_rtx (NOT
, orexp
);
3690 return dim
->num_values
;
3693 /* Increment the current value for the NDIM-dimensional attribute space SPACE
3694 and return FALSE if the increment overflowed. */
3697 increment_current_value (space
, ndim
)
3698 struct dimension
*space
;
3703 for (i
= ndim
- 1; i
>= 0; i
--)
3705 if ((space
[i
].current_value
= XEXP (space
[i
].current_value
, 1)) == 0)
3706 space
[i
].current_value
= space
[i
].values
;
3713 /* Construct an expression corresponding to the current value for the
3714 NDIM-dimensional attribute space SPACE. */
3717 test_for_current_value (space
, ndim
)
3718 struct dimension
*space
;
3724 for (i
= 0; i
< ndim
; i
++)
3725 exp
= insert_right_side (AND
, exp
, XEXP (space
[i
].current_value
, 0),
3731 /* Given the current value of the NDIM-dimensional attribute space SPACE,
3732 set the corresponding EQ_ATTR expressions to that value and reduce
3733 the expression EXP as much as possible. On input [and output], all
3734 known EQ_ATTR expressions are set to FALSE. */
3737 simplify_with_current_value (exp
, space
, ndim
)
3739 struct dimension
*space
;
3745 /* Mark each current value as TRUE. */
3746 for (i
= 0; i
< ndim
; i
++)
3748 x
= XEXP (space
[i
].current_value
, 0);
3749 if (GET_CODE (x
) == EQ_ATTR
)
3750 MEM_VOLATILE_P (x
) = 0;
3753 exp
= simplify_with_current_value_aux (exp
);
3755 /* Change each current value back to FALSE. */
3756 for (i
= 0; i
< ndim
; i
++)
3758 x
= XEXP (space
[i
].current_value
, 0);
3759 if (GET_CODE (x
) == EQ_ATTR
)
3760 MEM_VOLATILE_P (x
) = 1;
3766 /* Reduce the expression EXP based on the MEM_VOLATILE_P settings of
3767 all EQ_ATTR expressions. */
3770 simplify_with_current_value_aux (exp
)
3776 switch (GET_CODE (exp
))
3779 if (MEM_VOLATILE_P (exp
))
3787 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
3788 if (cond
== true_rtx
)
3789 return simplify_with_current_value_aux (XEXP (exp
, 1));
3790 else if (cond
== false_rtx
)
3791 return simplify_with_current_value_aux (XEXP (exp
, 2));
3793 return attr_rtx (IF_THEN_ELSE
, cond
,
3794 simplify_with_current_value_aux (XEXP (exp
, 1)),
3795 simplify_with_current_value_aux (XEXP (exp
, 2)));
3798 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
3799 if (cond
== true_rtx
)
3801 else if (cond
== false_rtx
)
3802 return simplify_with_current_value_aux (XEXP (exp
, 0));
3804 return attr_rtx (IOR
, cond
,
3805 simplify_with_current_value_aux (XEXP (exp
, 0)));
3808 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
3809 if (cond
== true_rtx
)
3810 return simplify_with_current_value_aux (XEXP (exp
, 0));
3811 else if (cond
== false_rtx
)
3814 return attr_rtx (AND
, cond
,
3815 simplify_with_current_value_aux (XEXP (exp
, 0)));
3818 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
3819 if (cond
== true_rtx
)
3821 else if (cond
== false_rtx
)
3824 return attr_rtx (NOT
, cond
);
3827 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
3829 cond
= simplify_with_current_value_aux (XVECEXP (exp
, 0, i
));
3830 if (cond
== true_rtx
)
3831 return simplify_with_current_value_aux (XVECEXP (exp
, 0, i
+ 1));
3832 else if (cond
== false_rtx
)
3835 abort (); /* With all EQ_ATTR's of known value, a case should
3836 have been selected. */
3838 return simplify_with_current_value_aux (XEXP (exp
, 1));
3843 /* Clear the MEM_IN_STRUCT_P flag in EXP and its subexpressions. */
3846 clear_struct_flag (x
)
3851 register enum rtx_code code
;
3854 MEM_IN_STRUCT_P (x
) = 0;
3855 if (RTX_UNCHANGING_P (x
))
3858 code
= GET_CODE (x
);
3875 /* Compare the elements. If any pair of corresponding elements
3876 fail to match, return 0 for the whole things. */
3878 fmt
= GET_RTX_FORMAT (code
);
3879 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3885 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3886 clear_struct_flag (XVECEXP (x
, i
, j
));
3890 clear_struct_flag (XEXP (x
, i
));
3896 /* Return the number of RTX objects making up the expression X.
3897 But if we count more more than MAX objects, stop counting. */
3900 count_sub_rtxs (x
, max
)
3906 register enum rtx_code code
;
3910 code
= GET_CODE (x
);
3927 /* Compare the elements. If any pair of corresponding elements
3928 fail to match, return 0 for the whole things. */
3930 fmt
= GET_RTX_FORMAT (code
);
3931 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3940 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3941 total
+= count_sub_rtxs (XVECEXP (x
, i
, j
), max
);
3945 total
+= count_sub_rtxs (XEXP (x
, i
), max
);
3953 /* Create table entries for DEFINE_ATTR. */
3959 struct attr_desc
*attr
;
3960 struct attr_value
*av
;
3964 /* Make a new attribute structure. Check for duplicate by looking at
3965 attr->default_val, since it is initialized by this routine. */
3966 attr
= find_attr (XSTR (exp
, 0), 1);
3967 if (attr
->default_val
)
3968 fatal ("Duplicate definition for `%s' attribute", attr
->name
);
3970 if (*XSTR (exp
, 1) == '\0')
3971 attr
->is_numeric
= 1;
3974 name_ptr
= XSTR (exp
, 1);
3975 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
3977 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
3978 av
->value
= attr_rtx (CONST_STRING
, p
);
3979 av
->next
= attr
->first_value
;
3980 attr
->first_value
= av
;
3981 av
->first_insn
= NULL
;
3983 av
->has_asm_insn
= 0;
3987 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
3990 if (attr
->is_numeric
)
3991 fatal ("Constant attributes may not take numeric values");
3992 /* Get rid of the CONST node. It is allowed only at top-level. */
3993 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
3996 if (! strcmp (attr
->name
, "length") && ! attr
->is_numeric
)
3997 fatal ("`length' attribute must take numeric values");
3999 /* Set up the default value. */
4000 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
4001 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
4004 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
4005 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
4006 number of alternatives as this should be checked elsewhere. */
4009 count_alternatives (exp
)
4015 if (GET_CODE (exp
) == MATCH_OPERAND
)
4016 return n_comma_elts (XSTR (exp
, 2));
4018 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4019 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4024 n
= count_alternatives (XEXP (exp
, i
));
4031 if (XVEC (exp
, i
) != NULL
)
4032 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4034 n
= count_alternatives (XVECEXP (exp
, i
, j
));
4043 /* Returns non-zero if the given expression contains an EQ_ATTR with the
4044 `alternative' attribute. */
4047 compares_alternatives_p (exp
)
4053 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
4056 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4057 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4062 if (compares_alternatives_p (XEXP (exp
, i
)))
4067 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4068 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
4076 /* Returns non-zero is INNER is contained in EXP. */
4079 contained_in_p (inner
, exp
)
4086 if (rtx_equal_p (inner
, exp
))
4089 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4090 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4095 if (contained_in_p (inner
, XEXP (exp
, i
)))
4100 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4101 if (contained_in_p (inner
, XVECEXP (exp
, i
, j
)))
4109 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
4115 struct insn_def
*id
;
4117 id
= (struct insn_def
*) oballoc (sizeof (struct insn_def
));
4122 switch (GET_CODE (exp
))
4125 id
->insn_code
= insn_code_number
++;
4126 id
->insn_index
= insn_index_number
++;
4127 id
->num_alternatives
= count_alternatives (exp
);
4128 if (id
->num_alternatives
== 0)
4129 id
->num_alternatives
= 1;
4133 case DEFINE_PEEPHOLE
:
4134 id
->insn_code
= insn_code_number
++;
4135 id
->insn_index
= insn_index_number
++;
4136 id
->num_alternatives
= count_alternatives (exp
);
4137 if (id
->num_alternatives
== 0)
4138 id
->num_alternatives
= 1;
4142 case DEFINE_ASM_ATTRIBUTES
:
4144 id
->insn_index
= -1;
4145 id
->num_alternatives
= 1;
4147 got_define_asm_attributes
= 1;
4152 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
4153 true or annul false is specified, and make a `struct delay_desc'. */
4159 struct delay_desc
*delay
;
4162 if (XVECLEN (def
, 1) % 3 != 0)
4163 fatal ("Number of elements in DEFINE_DELAY must be multiple of three.");
4165 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
4167 if (XVECEXP (def
, 1, i
+ 1))
4168 have_annul_true
= 1;
4169 if (XVECEXP (def
, 1, i
+ 2))
4170 have_annul_false
= 1;
4173 delay
= (struct delay_desc
*) oballoc (sizeof (struct delay_desc
));
4175 delay
->num
= ++num_delays
;
4176 delay
->next
= delays
;
4180 /* Process a DEFINE_FUNCTION_UNIT.
4182 This gives information about a function unit contained in the CPU.
4183 We fill in a `struct function_unit_op' and a `struct function_unit'
4184 with information used later by `expand_unit'. */
4190 struct function_unit
*unit
;
4191 struct function_unit_op
*op
;
4192 char *name
= XSTR (def
, 0);
4193 int multiplicity
= XINT (def
, 1);
4194 int simultaneity
= XINT (def
, 2);
4195 rtx condexp
= XEXP (def
, 3);
4196 int ready_cost
= MAX (XINT (def
, 4), 1);
4197 int issue_delay
= MAX (XINT (def
, 5), 1);
4199 /* See if we have already seen this function unit. If so, check that
4200 the multiplicity and simultaneity values are the same. If not, make
4201 a structure for this function unit. */
4202 for (unit
= units
; unit
; unit
= unit
->next
)
4203 if (! strcmp (unit
->name
, name
))
4205 if (unit
->multiplicity
!= multiplicity
4206 || unit
->simultaneity
!= simultaneity
)
4207 fatal ("Differing specifications given for `%s' function unit.",
4214 unit
= (struct function_unit
*) oballoc (sizeof (struct function_unit
));
4216 unit
->multiplicity
= multiplicity
;
4217 unit
->simultaneity
= simultaneity
;
4218 unit
->issue_delay
.min
= unit
->issue_delay
.max
= issue_delay
;
4219 unit
->num
= num_units
++;
4220 unit
->num_opclasses
= 0;
4221 unit
->condexp
= false_rtx
;
4227 /* Make a new operation class structure entry and initialize it. */
4228 op
= (struct function_unit_op
*) oballoc (sizeof (struct function_unit_op
));
4229 op
->condexp
= condexp
;
4230 op
->num
= unit
->num_opclasses
++;
4231 op
->ready
= ready_cost
;
4232 op
->issue_delay
= issue_delay
;
4233 op
->next
= unit
->ops
;
4236 /* Set our issue expression based on whether or not an optional conflict
4237 vector was specified. */
4240 /* Compute the IOR of all the specified expressions. */
4241 rtx orexp
= false_rtx
;
4244 for (i
= 0; i
< XVECLEN (def
, 6); i
++)
4245 orexp
= insert_right_side (IOR
, orexp
, XVECEXP (def
, 6, i
), -2, -2);
4247 op
->conflict_exp
= orexp
;
4248 extend_range (&unit
->issue_delay
, 1, issue_delay
);
4252 op
->conflict_exp
= true_rtx
;
4253 extend_range (&unit
->issue_delay
, issue_delay
, issue_delay
);
4256 /* Merge our conditional into that of the function unit so we can determine
4257 which insns are used by the function unit. */
4258 unit
->condexp
= insert_right_side (IOR
, unit
->condexp
, op
->condexp
, -2, -2);
4261 /* Given a piece of RTX, print a C expression to test it's truth value.
4262 We use AND and IOR both for logical and bit-wise operations, so
4263 interpret them as logical unless they are inside a comparison expression.
4264 The second operand of this function will be non-zero in that case. */
4267 write_test_expr (exp
, in_comparison
)
4271 int comparison_operator
= 0;
4273 struct attr_desc
*attr
;
4275 /* In order not to worry about operator precedence, surround our part of
4276 the expression with parentheses. */
4279 code
= GET_CODE (exp
);
4282 /* Binary operators. */
4284 case GE
: case GT
: case GEU
: case GTU
:
4285 case LE
: case LT
: case LEU
: case LTU
:
4286 comparison_operator
= 1;
4288 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
4289 case AND
: case IOR
: case XOR
:
4290 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
4291 write_test_expr (XEXP (exp
, 0), in_comparison
|| comparison_operator
);
4307 printf (" >= (unsigned) ");
4310 printf (" > (unsigned) ");
4319 printf (" <= (unsigned) ");
4322 printf (" < (unsigned) ");
4363 write_test_expr (XEXP (exp
, 1), in_comparison
|| comparison_operator
);
4367 /* Special-case (not (eq_attrq "alternative" "x")) */
4368 if (! in_comparison
&& GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
4369 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
4371 printf ("which_alternative != %s", XSTR (XEXP (exp
, 0), 1));
4375 /* Otherwise, fall through to normal unary operator. */
4377 /* Unary operators. */
4395 write_test_expr (XEXP (exp
, 0), in_comparison
);
4398 /* Comparison test of an attribute with a value. Most of these will
4399 have been removed by optimization. Handle "alternative"
4400 specially and give error if EQ_ATTR present inside a comparison. */
4403 fatal ("EQ_ATTR not valid inside comparison");
4405 if (XSTR (exp
, 0) == alternative_name
)
4407 printf ("which_alternative == %s", XSTR (exp
, 1));
4411 attr
= find_attr (XSTR (exp
, 0), 0);
4412 if (! attr
) abort ();
4414 /* Now is the time to expand the value of a constant attribute. */
4417 write_test_expr (evaluate_eq_attr (exp
, attr
->default_val
->value
,
4423 printf ("get_attr_%s (insn) == ", attr
->name
);
4424 write_attr_valueq (attr
, XSTR (exp
, 1));
4428 /* Comparison test of flags for define_delays. */
4431 fatal ("ATTR_FLAG not valid inside comparison");
4432 printf ("(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
4435 /* See if an operand matches a predicate. */
4437 /* If only a mode is given, just ensure the mode matches the operand.
4438 If neither a mode nor predicate is given, error. */
4439 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
4441 if (GET_MODE (exp
) == VOIDmode
)
4442 fatal ("Null MATCH_OPERAND specified as test");
4444 printf ("GET_MODE (operands[%d]) == %smode",
4445 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4448 printf ("%s (operands[%d], %smode)",
4449 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4452 /* Constant integer. */
4454 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
4455 printf ("%d", XWINT (exp
, 0));
4457 printf ("%ld", XWINT (exp
, 0));
4461 /* A random C expression. */
4463 printf ("%s", XSTR (exp
, 0));
4466 /* The address of the branch target. */
4468 printf ("insn_addresses[INSN_UID (JUMP_LABEL (insn))]");
4471 /* The address of the current insn. It would be more consistent with
4472 other usage to make this the address of the NEXT insn, but this gets
4473 too confusing because of the ambiguity regarding the length of the
4476 printf ("insn_current_address");
4480 fatal ("bad RTX code `%s' in attribute calculation\n",
4481 GET_RTX_NAME (code
));
4487 /* Given an attribute value, return the maximum CONST_STRING argument
4488 encountered. It is assumed that they are all numeric. */
4491 max_attr_value (exp
)
4494 int current_max
= 0;
4498 if (GET_CODE (exp
) == CONST_STRING
)
4499 return atoi (XSTR (exp
, 0));
4501 else if (GET_CODE (exp
) == COND
)
4503 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4505 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1));
4506 if (n
> current_max
)
4510 n
= max_attr_value (XEXP (exp
, 1));
4511 if (n
> current_max
)
4515 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
4517 current_max
= max_attr_value (XEXP (exp
, 1));
4518 n
= max_attr_value (XEXP (exp
, 2));
4519 if (n
> current_max
)
4529 /* Scan an attribute value, possibly a conditional, and record what actions
4530 will be required to do any conditional tests in it.
4533 `must_extract' if we need to extract the insn operands
4534 `must_constrain' if we must compute `which_alternative'
4535 `address_used' if an address expression was used
4536 `length_used' if an (eq_attr "length" ...) was used
4540 walk_attr_value (exp
)
4550 code
= GET_CODE (exp
);
4554 if (! RTX_UNCHANGING_P (exp
))
4555 /* Since this is an arbitrary expression, it can look at anything.
4556 However, constant expressions do not depend on any particular
4558 must_extract
= must_constrain
= 1;
4566 if (XSTR (exp
, 0) == alternative_name
)
4567 must_extract
= must_constrain
= 1;
4568 else if (strcmp (XSTR (exp
, 0), "length") == 0)
4581 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
4586 walk_attr_value (XEXP (exp
, i
));
4590 if (XVEC (exp
, i
) != NULL
)
4591 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4592 walk_attr_value (XVECEXP (exp
, i
, j
));
4597 /* Write out a function to obtain the attribute for a given INSN. */
4600 write_attr_get (attr
)
4601 struct attr_desc
*attr
;
4603 struct attr_value
*av
, *common_av
;
4605 /* Find the most used attribute value. Handle that as the `default' of the
4606 switch we will generate. */
4607 common_av
= find_most_used (attr
);
4609 /* Write out start of function, then all values with explicit `case' lines,
4610 then a `default', then the value with the most uses. */
4611 if (!attr
->is_numeric
)
4612 printf ("enum attr_%s\n", attr
->name
);
4613 else if (attr
->unsigned_p
)
4614 printf ("unsigned int\n");
4618 /* If the attribute name starts with a star, the remainder is the name of
4619 the subroutine to use, instead of `get_attr_...'. */
4620 if (attr
->name
[0] == '*')
4621 printf ("%s (insn)\n", &attr
->name
[1]);
4622 else if (attr
->is_const
== 0)
4623 printf ("get_attr_%s (insn)\n", attr
->name
);
4626 printf ("get_attr_%s ()\n", attr
->name
);
4629 for (av
= attr
->first_value
; av
; av
= av
->next
)
4630 if (av
->num_insns
!= 0)
4631 write_attr_set (attr
, 2, av
->value
, "return", ";",
4632 true_rtx
, av
->first_insn
->insn_code
,
4633 av
->first_insn
->insn_index
);
4638 printf (" rtx insn;\n");
4640 printf (" switch (recog_memoized (insn))\n");
4643 for (av
= attr
->first_value
; av
; av
= av
->next
)
4644 if (av
!= common_av
)
4645 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
4647 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4648 printf (" }\n}\n\n");
4651 /* Given an AND tree of known true terms (because we are inside an `if' with
4652 that as the condition or are in an `else' clause) and an expression,
4653 replace any known true terms with TRUE. Use `simplify_and_tree' to do
4654 the bulk of the work. */
4657 eliminate_known_true (known_true
, exp
, insn_code
, insn_index
)
4660 int insn_code
, insn_index
;
4664 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
4666 if (GET_CODE (known_true
) == AND
)
4668 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
4669 insn_code
, insn_index
);
4670 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
4671 insn_code
, insn_index
);
4676 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
4682 /* Write out a series of tests and assignment statements to perform tests and
4683 sets of an attribute value. We are passed an indentation amount and prefix
4684 and suffix strings to write around each attribute value (e.g., "return"
4688 write_attr_set (attr
, indent
, value
, prefix
, suffix
, known_true
,
4689 insn_code
, insn_index
)
4690 struct attr_desc
*attr
;
4696 int insn_code
, insn_index
;
4698 if (GET_CODE (value
) == CONST_STRING
)
4700 write_indent (indent
);
4701 printf ("%s ", prefix
);
4702 write_attr_value (attr
, value
);
4703 printf ("%s\n", suffix
);
4705 else if (GET_CODE (value
) == COND
)
4707 /* Assume the default value will be the default of the COND unless we
4708 find an always true expression. */
4709 rtx default_val
= XEXP (value
, 1);
4710 rtx our_known_true
= known_true
;
4715 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
4720 testexp
= eliminate_known_true (our_known_true
,
4721 XVECEXP (value
, 0, i
),
4722 insn_code
, insn_index
);
4723 newexp
= attr_rtx (NOT
, testexp
);
4724 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
4725 insn_code
, insn_index
);
4727 /* If the test expression is always true or if the next `known_true'
4728 expression is always false, this is the last case, so break
4729 out and let this value be the `else' case. */
4730 if (testexp
== true_rtx
|| newexp
== false_rtx
)
4732 default_val
= XVECEXP (value
, 0, i
+ 1);
4736 /* Compute the expression to pass to our recursive call as being
4738 inner_true
= insert_right_side (AND
, our_known_true
,
4739 testexp
, insn_code
, insn_index
);
4741 /* If this is always false, skip it. */
4742 if (inner_true
== false_rtx
)
4745 write_indent (indent
);
4746 printf ("%sif ", first_if
? "" : "else ");
4748 write_test_expr (testexp
, 0);
4750 write_indent (indent
+ 2);
4753 write_attr_set (attr
, indent
+ 4,
4754 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
4755 inner_true
, insn_code
, insn_index
);
4756 write_indent (indent
+ 2);
4758 our_known_true
= newexp
;
4763 write_indent (indent
);
4765 write_indent (indent
+ 2);
4769 write_attr_set (attr
, first_if
? indent
: indent
+ 4, default_val
,
4770 prefix
, suffix
, our_known_true
, insn_code
, insn_index
);
4774 write_indent (indent
+ 2);
4782 /* Write out the computation for one attribute value. */
4785 write_attr_case (attr
, av
, write_case_lines
, prefix
, suffix
, indent
,
4787 struct attr_desc
*attr
;
4788 struct attr_value
*av
;
4789 int write_case_lines
;
4790 char *prefix
, *suffix
;
4794 struct insn_ent
*ie
;
4796 if (av
->num_insns
== 0)
4799 if (av
->has_asm_insn
)
4801 write_indent (indent
);
4802 printf ("case -1:\n");
4803 write_indent (indent
+ 2);
4804 printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
4805 write_indent (indent
+ 2);
4806 printf (" && asm_noperands (PATTERN (insn)) < 0)\n");
4807 write_indent (indent
+ 2);
4808 printf (" fatal_insn_not_found (insn);\n");
4811 if (write_case_lines
)
4813 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
4814 if (ie
->insn_code
!= -1)
4816 write_indent (indent
);
4817 printf ("case %d:\n", ie
->insn_code
);
4822 write_indent (indent
);
4823 printf ("default:\n");
4826 /* See what we have to do to output this value. */
4827 must_extract
= must_constrain
= address_used
= 0;
4828 walk_attr_value (av
->value
);
4832 write_indent (indent
+ 2);
4833 printf ("insn_extract (insn);\n");
4838 #ifdef REGISTER_CONSTRAINTS
4839 write_indent (indent
+ 2);
4840 printf ("if (! constrain_operands (INSN_CODE (insn), reload_completed))\n");
4841 write_indent (indent
+ 2);
4842 printf (" fatal_insn_not_found (insn);\n");
4846 write_attr_set (attr
, indent
+ 2, av
->value
, prefix
, suffix
,
4847 known_true
, av
->first_insn
->insn_code
,
4848 av
->first_insn
->insn_index
);
4850 if (strncmp (prefix
, "return", 6))
4852 write_indent (indent
+ 2);
4853 printf ("break;\n");
4858 /* Utilities to write names in various forms. */
4861 write_attr_valueq (attr
, s
)
4862 struct attr_desc
*attr
;
4865 if (attr
->is_numeric
)
4868 /* Make the blockage range values easier to read. */
4870 printf (" /* 0x%x */", atoi (s
));
4874 write_upcase (attr
->name
);
4881 write_attr_value (attr
, value
)
4882 struct attr_desc
*attr
;
4885 if (GET_CODE (value
) != CONST_STRING
)
4888 write_attr_valueq (attr
, XSTR (value
, 0));
4896 if (*str
< 'a' || *str
> 'z')
4897 printf ("%c", *str
++);
4899 printf ("%c", *str
++ - 'a' + 'A');
4903 write_indent (indent
)
4906 for (; indent
> 8; indent
-= 8)
4909 for (; indent
; indent
--)
4913 /* Write a subroutine that is given an insn that requires a delay slot, a
4914 delay slot ordinal, and a candidate insn. It returns non-zero if the
4915 candidate can be placed in the specified delay slot of the insn.
4917 We can write as many as three subroutines. `eligible_for_delay'
4918 handles normal delay slots, `eligible_for_annul_true' indicates that
4919 the specified insn can be annulled if the branch is true, and likewise
4920 for `eligible_for_annul_false'.
4922 KIND is a string distinguishing these three cases ("delay", "annul_true",
4923 or "annul_false"). */
4926 write_eligible_delay (kind
)
4929 struct delay_desc
*delay
;
4932 struct attr_desc
*attr
;
4933 struct attr_value
*av
, *common_av
;
4936 /* Compute the maximum number of delay slots required. We use the delay
4937 ordinal times this number plus one, plus the slot number as an index into
4938 the appropriate predicate to test. */
4940 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
4941 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
4942 max_slots
= XVECLEN (delay
->def
, 1) / 3;
4944 /* Write function prelude. */
4947 printf ("eligible_for_%s (delay_insn, slot, candidate_insn, flags)\n",
4949 printf (" rtx delay_insn;\n");
4950 printf (" int slot;\n");
4951 printf (" rtx candidate_insn;\n");
4952 printf (" int flags;\n");
4954 printf (" rtx insn;\n");
4956 printf (" if (slot >= %d)\n", max_slots
);
4957 printf (" abort ();\n");
4960 /* If more than one delay type, find out which type the delay insn is. */
4964 attr
= find_attr ("*delay_type", 0);
4965 if (! attr
) abort ();
4966 common_av
= find_most_used (attr
);
4968 printf (" insn = delay_insn;\n");
4969 printf (" switch (recog_memoized (insn))\n");
4972 sprintf (str
, " * %d;\n break;", max_slots
);
4973 for (av
= attr
->first_value
; av
; av
= av
->next
)
4974 if (av
!= common_av
)
4975 write_attr_case (attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
4977 write_attr_case (attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
4980 /* Ensure matched. Otherwise, shouldn't have been called. */
4981 printf (" if (slot < %d)\n", max_slots
);
4982 printf (" abort ();\n\n");
4985 /* If just one type of delay slot, write simple switch. */
4986 if (num_delays
== 1 && max_slots
== 1)
4988 printf (" insn = candidate_insn;\n");
4989 printf (" switch (recog_memoized (insn))\n");
4992 attr
= find_attr ("*delay_1_0", 0);
4993 if (! attr
) abort ();
4994 common_av
= find_most_used (attr
);
4996 for (av
= attr
->first_value
; av
; av
= av
->next
)
4997 if (av
!= common_av
)
4998 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5000 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5006 /* Write a nested CASE. The first indicates which condition we need to
5007 test, and the inner CASE tests the condition. */
5008 printf (" insn = candidate_insn;\n");
5009 printf (" switch (slot)\n");
5012 for (delay
= delays
; delay
; delay
= delay
->next
)
5013 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
5015 printf (" case %d:\n",
5016 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
5017 printf (" switch (recog_memoized (insn))\n");
5020 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
5021 attr
= find_attr (str
, 0);
5022 if (! attr
) abort ();
5023 common_av
= find_most_used (attr
);
5025 for (av
= attr
->first_value
; av
; av
= av
->next
)
5026 if (av
!= common_av
)
5027 write_attr_case (attr
, av
, 1, "return", ";", 8, true_rtx
);
5029 write_attr_case (attr
, common_av
, 0, "return", ";", 8, true_rtx
);
5033 printf (" default:\n");
5034 printf (" abort ();\n");
5041 /* Write routines to compute conflict cost for function units. Then write a
5042 table describing the available function units. */
5045 write_function_unit_info ()
5047 struct function_unit
*unit
;
5050 /* Write out conflict routines for function units. Don't bother writing
5051 one if there is only one issue delay value. */
5053 for (unit
= units
; unit
; unit
= unit
->next
)
5055 if (unit
->needs_blockage_function
)
5056 write_complex_function (unit
, "blockage", "block");
5058 /* If the minimum and maximum conflict costs are the same, there
5059 is only one value, so we don't need a function. */
5060 if (! unit
->needs_conflict_function
)
5062 unit
->default_cost
= make_numeric_value (unit
->issue_delay
.max
);
5066 /* The function first computes the case from the candidate insn. */
5067 unit
->default_cost
= make_numeric_value (0);
5068 write_complex_function (unit
, "conflict_cost", "cost");
5071 /* Now that all functions have been written, write the table describing
5072 the function units. The name is included for documentation purposes
5075 printf ("struct function_unit_desc function_units[] = {\n");
5077 /* Write out the descriptions in numeric order, but don't force that order
5078 on the list. Doing so increases the runtime of genattrtab.c. */
5079 for (i
= 0; i
< num_units
; i
++)
5081 for (unit
= units
; unit
; unit
= unit
->next
)
5085 printf (" {\"%s\", %d, %d, %d, %s, %d, %s_unit_ready_cost, ",
5086 unit
->name
, 1 << unit
->num
, unit
->multiplicity
,
5087 unit
->simultaneity
, XSTR (unit
->default_cost
, 0),
5088 unit
->issue_delay
.max
, unit
->name
);
5090 if (unit
->needs_conflict_function
)
5091 printf ("%s_unit_conflict_cost, ", unit
->name
);
5095 printf ("%d, ", unit
->max_blockage
);
5097 if (unit
->needs_range_function
)
5098 printf ("%s_unit_blockage_range, ", unit
->name
);
5102 if (unit
->needs_blockage_function
)
5103 printf ("%s_unit_blockage", unit
->name
);
5114 write_complex_function (unit
, name
, connection
)
5115 struct function_unit
*unit
;
5116 char *name
, *connection
;
5118 struct attr_desc
*case_attr
, *attr
;
5119 struct attr_value
*av
, *common_av
;
5125 printf ("static int\n");
5126 printf ("%s_unit_%s (executing_insn, candidate_insn)\n",
5128 printf (" rtx executing_insn;\n");
5129 printf (" rtx candidate_insn;\n");
5131 printf (" rtx insn;\n");
5132 printf (" int casenum;\n\n");
5133 printf (" insn = executing_insn;\n");
5134 printf (" switch (recog_memoized (insn))\n");
5137 /* Write the `switch' statement to get the case value. */
5138 str
= (char *) alloca (strlen (unit
->name
) + strlen (name
) + strlen (connection
) + 10);
5139 sprintf (str
, "*%s_cases", unit
->name
);
5140 case_attr
= find_attr (str
, 0);
5141 if (! case_attr
) abort ();
5142 common_av
= find_most_used (case_attr
);
5144 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5145 if (av
!= common_av
)
5146 write_attr_case (case_attr
, av
, 1,
5147 "casenum =", ";", 4, unit
->condexp
);
5149 write_attr_case (case_attr
, common_av
, 0,
5150 "casenum =", ";", 4, unit
->condexp
);
5153 /* Now write an outer switch statement on each case. Then write
5154 the tests on the executing function within each. */
5155 printf (" insn = candidate_insn;\n");
5156 printf (" switch (casenum)\n");
5159 for (i
= 0; i
< unit
->num_opclasses
; i
++)
5161 /* Ensure using this case. */
5163 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5165 && contained_in_p (make_numeric_value (i
), av
->value
))
5171 printf (" case %d:\n", i
);
5172 sprintf (str
, "*%s_%s_%d", unit
->name
, connection
, i
);
5173 attr
= find_attr (str
, 0);
5174 if (! attr
) abort ();
5176 /* If single value, just write it. */
5177 value
= find_single_value (attr
);
5179 write_attr_set (attr
, 6, value
, "return", ";\n", true_rtx
, -2, -2);
5182 common_av
= find_most_used (attr
);
5183 printf (" switch (recog_memoized (insn))\n");
5186 for (av
= attr
->first_value
; av
; av
= av
->next
)
5187 if (av
!= common_av
)
5188 write_attr_case (attr
, av
, 1,
5189 "return", ";", 8, unit
->condexp
);
5191 write_attr_case (attr
, common_av
, 0,
5192 "return", ";", 8, unit
->condexp
);
5197 printf (" }\n}\n\n");
5200 /* This page contains miscellaneous utility routines. */
5202 /* Given a string, return the number of comma-separated elements in it.
5203 Return 0 for the null string. */
5214 for (n
= 1; *s
; s
++)
5221 /* Given a pointer to a (char *), return a malloc'ed string containing the
5222 next comma-separated element. Advance the pointer to after the string
5223 scanned, or the end-of-string. Return NULL if at end of string. */
5226 next_comma_elt (pstr
)
5235 /* Find end of string to compute length. */
5236 for (p
= *pstr
; *p
!= ',' && *p
!= '\0'; p
++)
5239 out_str
= attr_string (*pstr
, p
- *pstr
);
5248 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
5249 is non-zero, build a new attribute, if one does not exist. */
5251 static struct attr_desc
*
5252 find_attr (name
, create
)
5256 struct attr_desc
*attr
;
5259 /* Before we resort to using `strcmp', see if the string address matches
5260 anywhere. In most cases, it should have been canonicalized to do so. */
5261 if (name
== alternative_name
)
5264 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
5265 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5266 if (name
== attr
->name
)
5269 /* Otherwise, do it the slow way. */
5270 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5271 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
5277 attr
= (struct attr_desc
*) oballoc (sizeof (struct attr_desc
));
5278 attr
->name
= attr_string (name
, strlen (name
));
5279 attr
->first_value
= attr
->default_val
= NULL
;
5280 attr
->is_numeric
= attr
->negative_ok
= attr
->is_const
= attr
->is_special
= 0;
5281 attr
->next
= attrs
[index
];
5282 attrs
[index
] = attr
;
5287 /* Create internal attribute with the given default value. */
5290 make_internal_attr (name
, value
, special
)
5295 struct attr_desc
*attr
;
5297 attr
= find_attr (name
, 1);
5298 if (attr
->default_val
)
5301 attr
->is_numeric
= 1;
5303 attr
->is_special
= (special
& 1) != 0;
5304 attr
->negative_ok
= (special
& 2) != 0;
5305 attr
->unsigned_p
= (special
& 4) != 0;
5306 attr
->default_val
= get_attr_value (value
, attr
, -2);
5309 /* Find the most used value of an attribute. */
5311 static struct attr_value
*
5312 find_most_used (attr
)
5313 struct attr_desc
*attr
;
5315 struct attr_value
*av
;
5316 struct attr_value
*most_used
;
5322 for (av
= attr
->first_value
; av
; av
= av
->next
)
5323 if (av
->num_insns
> nuses
)
5324 nuses
= av
->num_insns
, most_used
= av
;
5329 /* If an attribute only has a single value used, return it. Otherwise
5333 find_single_value (attr
)
5334 struct attr_desc
*attr
;
5336 struct attr_value
*av
;
5339 unique_value
= NULL
;
5340 for (av
= attr
->first_value
; av
; av
= av
->next
)
5346 unique_value
= av
->value
;
5349 return unique_value
;
5352 /* Return (attr_value "n") */
5355 make_numeric_value (n
)
5358 static rtx int_values
[20];
5365 if (n
< 20 && int_values
[n
])
5366 return int_values
[n
];
5368 p
= attr_printf (MAX_DIGITS
, "%d", n
);
5369 exp
= attr_rtx (CONST_STRING
, p
);
5372 int_values
[n
] = exp
;
5378 extend_range (range
, min
, max
)
5379 struct range
*range
;
5383 if (range
->min
> min
) range
->min
= min
;
5384 if (range
->max
< max
) range
->max
= max
;
5388 xrealloc (ptr
, size
)
5392 char *result
= (char *) realloc (ptr
, size
);
5394 fatal ("virtual memory exhausted");
5402 register char *val
= (char *) malloc (size
);
5405 fatal ("virtual memory exhausted");
5410 copy_rtx_unchanging (orig
)
5415 register RTX_CODE code
;
5418 if (RTX_UNCHANGING_P (orig
) || MEM_IN_STRUCT_P (orig
))
5421 MEM_IN_STRUCT_P (orig
) = 1;
5425 code
= GET_CODE (orig
);
5435 copy
= rtx_alloc (code
);
5436 PUT_MODE (copy
, GET_MODE (orig
));
5437 RTX_UNCHANGING_P (copy
) = 1;
5439 bcopy (&XEXP (orig
, 0), &XEXP (copy
, 0),
5440 GET_RTX_LENGTH (GET_CODE (copy
)) * sizeof (rtx
));
5449 fprintf (stderr
, "genattrtab: ");
5450 fprintf (stderr
, s
, a1
, a2
);
5451 fprintf (stderr
, "\n");
5452 exit (FATAL_EXIT_CODE
);
5455 /* More 'friendly' abort that prints the line and file.
5456 config.h can #define abort fancy_abort if you like that sort of thing. */
5461 fatal ("Internal gcc abort.");
5464 /* Determine if an insn has a constant number of delay slots, i.e., the
5465 number of delay slots is not a function of the length of the insn. */
5468 write_const_num_delay_slots ()
5470 struct attr_desc
*attr
= find_attr ("*num_delay_slots", 0);
5471 struct attr_value
*av
;
5472 struct insn_ent
*ie
;
5477 printf ("int\nconst_num_delay_slots (insn)\n");
5478 printf (" rtx insn;\n");
5480 printf (" switch (recog_memoized (insn))\n");
5483 for (av
= attr
->first_value
; av
; av
= av
->next
)
5486 walk_attr_value (av
->value
);
5489 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5490 if (ie
->insn_code
!= -1)
5491 printf (" case %d:\n", ie
->insn_code
);
5492 printf (" return 0;\n");
5496 printf (" default:\n");
5497 printf (" return 1;\n");
5511 struct attr_desc
*attr
;
5512 struct insn_def
*id
;
5517 /* Get rid of any avoidable limit on stack size. */
5521 /* Set the stack limit huge so that alloca does not fail. */
5522 getrlimit (RLIMIT_STACK
, &rlim
);
5523 rlim
.rlim_cur
= rlim
.rlim_max
;
5524 setrlimit (RLIMIT_STACK
, &rlim
);
5526 #endif /* RLIMIT_STACK defined */
5528 obstack_init (rtl_obstack
);
5529 obstack_init (hash_obstack
);
5530 obstack_init (temp_obstack
);
5533 fatal ("No input file name.");
5535 infile
= fopen (argv
[1], "r");
5539 exit (FATAL_EXIT_CODE
);
5544 /* Set up true and false rtx's */
5545 true_rtx
= rtx_alloc (CONST_INT
);
5546 XWINT (true_rtx
, 0) = 1;
5547 false_rtx
= rtx_alloc (CONST_INT
);
5548 XWINT (false_rtx
, 0) = 0;
5549 RTX_UNCHANGING_P (true_rtx
) = RTX_UNCHANGING_P (false_rtx
) = 1;
5550 RTX_INTEGRATED_P (true_rtx
) = RTX_INTEGRATED_P (false_rtx
) = 1;
5552 alternative_name
= attr_string ("alternative", strlen ("alternative"));
5554 printf ("/* Generated automatically by the program `genattrtab'\n\
5555 from the machine description file `md'. */\n\n");
5557 /* Read the machine description. */
5561 c
= read_skip_spaces (infile
);
5566 desc
= read_rtx (infile
);
5567 if (GET_CODE (desc
) == DEFINE_INSN
5568 || GET_CODE (desc
) == DEFINE_PEEPHOLE
5569 || GET_CODE (desc
) == DEFINE_ASM_ATTRIBUTES
)
5572 else if (GET_CODE (desc
) == DEFINE_EXPAND
)
5573 insn_code_number
++, insn_index_number
++;
5575 else if (GET_CODE (desc
) == DEFINE_SPLIT
)
5576 insn_code_number
++, insn_index_number
++;
5578 else if (GET_CODE (desc
) == DEFINE_ATTR
)
5581 insn_index_number
++;
5584 else if (GET_CODE (desc
) == DEFINE_DELAY
)
5587 insn_index_number
++;
5590 else if (GET_CODE (desc
) == DEFINE_FUNCTION_UNIT
)
5593 insn_index_number
++;
5597 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
5598 if (! got_define_asm_attributes
)
5600 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
5601 XVEC (tem
, 0) = rtvec_alloc (0);
5605 /* Expand DEFINE_DELAY information into new attribute. */
5609 /* Expand DEFINE_FUNCTION_UNIT information into new attributes. */
5613 printf ("#include \"config.h\"\n");
5614 printf ("#include \"rtl.h\"\n");
5615 printf ("#include \"insn-config.h\"\n");
5616 printf ("#include \"recog.h\"\n");
5617 printf ("#include \"regs.h\"\n");
5618 printf ("#include \"real.h\"\n");
5619 printf ("#include \"output.h\"\n");
5620 printf ("#include \"insn-attr.h\"\n");
5622 printf ("#define operands recog_operand\n\n");
5624 /* Make `insn_alternatives'. */
5625 insn_alternatives
= (int *) oballoc (insn_code_number
* sizeof (int));
5626 for (id
= defs
; id
; id
= id
->next
)
5627 if (id
->insn_code
>= 0)
5628 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
5630 /* Make `insn_n_alternatives'. */
5631 insn_n_alternatives
= (int *) oballoc (insn_code_number
* sizeof (int));
5632 for (id
= defs
; id
; id
= id
->next
)
5633 if (id
->insn_code
>= 0)
5634 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
5636 /* Prepare to write out attribute subroutines by checking everything stored
5637 away and building the attribute cases. */
5640 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5641 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5643 attr
->default_val
->value
5644 = check_attr_value (attr
->default_val
->value
, attr
);
5648 /* Construct extra attributes for `length'. */
5649 make_length_attrs ();
5651 /* Perform any possible optimizations to speed up compilation. */
5654 /* Now write out all the `gen_attr_...' routines. Do these before the
5655 special routines (specifically before write_function_unit_info), so
5656 that they get defined before they are used. */
5658 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
5659 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5661 if (! attr
->is_special
)
5662 write_attr_get (attr
);
5665 /* Write out delay eligibility information, if DEFINE_DELAY present.
5666 (The function to compute the number of delay slots will be written
5670 write_eligible_delay ("delay");
5671 if (have_annul_true
)
5672 write_eligible_delay ("annul_true");
5673 if (have_annul_false
)
5674 write_eligible_delay ("annul_false");
5677 /* Write out information about function units. */
5679 write_function_unit_info ();
5681 /* Write out constant delay slot info */
5682 write_const_num_delay_slots ();
5685 exit (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);