1 /* Generate code from machine description to compute values of attributes.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* This program handles insn attributes and the DEFINE_DELAY and
24 DEFINE_FUNCTION_UNIT definitions.
26 It produces a series of functions named `get_attr_...', one for each insn
27 attribute. Each of these is given the rtx for an insn and returns a member
28 of the enum for the attribute.
30 These subroutines have the form of a `switch' on the INSN_CODE (via
31 `recog_memoized'). Each case either returns a constant attribute value
32 or a value that depends on tests on other attributes, the form of
33 operands, or some random C expression (encoded with a SYMBOL_REF
36 If the attribute `alternative', or a random C expression is present,
37 `constrain_operands' is called. If either of these cases of a reference to
38 an operand is found, `extract_insn' is called.
40 The special attribute `length' is also recognized. For this operand,
41 expressions involving the address of an operand or the current insn,
42 (address (pc)), are valid. In this case, an initial pass is made to
43 set all lengths that do not depend on address. Those that do are set to
44 the maximum length. Then each insn that depends on an address is checked
45 and possibly has its length changed. The process repeats until no further
46 changed are made. The resulting lengths are saved for use by
49 A special form of DEFINE_ATTR, where the expression for default value is a
50 CONST expression, indicates an attribute that is constant for a given run
51 of the compiler. The subroutine generated for these attributes has no
52 parameters as it does not depend on any particular insn. Constant
53 attributes are typically used to specify which variety of processor is
56 Internal attributes are defined to handle DEFINE_DELAY and
57 DEFINE_FUNCTION_UNIT. Special routines are output for these cases.
59 This program works by keeping a list of possible values for each attribute.
60 These include the basic attribute choices, default values for attribute, and
61 all derived quantities.
63 As the description file is read, the definition for each insn is saved in a
64 `struct insn_def'. When the file reading is complete, a `struct insn_ent'
65 is created for each insn and chained to the corresponding attribute value,
66 either that specified, or the default.
68 An optimization phase is then run. This simplifies expressions for each
69 insn. EQ_ATTR tests are resolved, whenever possible, to a test that
70 indicates when the attribute has the specified value for the insn. This
71 avoids recursive calls during compilation.
73 The strategy used when processing DEFINE_DELAY and DEFINE_FUNCTION_UNIT
74 definitions is to create arbitrarily complex expressions and have the
75 optimization simplify them.
77 Once optimization is complete, any required routines and definitions
80 An optimization that is not yet implemented is to hoist the constant
81 expressions entirely out of the routines and definitions that are written.
82 A way to do this is to iterate over all possible combinations of values
83 for constant attributes and generate a set of functions for that given
84 combination. An initialization function would be written that evaluates
85 the attributes and installs the corresponding set of routines and
86 definitions (each would be accessed through a pointer).
88 We use the flags in an RTX as follows:
89 `unchanging' (RTX_UNCHANGING_P): This rtx is fully simplified
90 independent of the insn code.
91 `in_struct' (MEM_IN_STRUCT_P): This rtx is fully simplified
92 for the insn code currently being processed (see optimize_attrs).
93 `integrated' (RTX_INTEGRATED_P): This rtx is permanent and unique
95 `volatil' (MEM_VOLATILE_P): During simplify_by_exploding the value of an
96 EQ_ATTR rtx is true if !volatil and false if volatil. */
104 #ifdef HAVE_SYS_RESOURCE_H
105 # include <sys/resource.h>
108 /* We must include obstack.h after <sys/time.h>, to avoid lossage with
109 /usr/include/sys/stdtypes.h on Sun OS 4.x. */
113 static struct obstack obstack
, obstack1
, obstack2
;
114 struct obstack
*rtl_obstack
= &obstack
;
115 struct obstack
*hash_obstack
= &obstack1
;
116 struct obstack
*temp_obstack
= &obstack2
;
118 #define obstack_chunk_alloc xmalloc
119 #define obstack_chunk_free free
121 /* enough space to reserve for printing out ints */
122 #define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
124 /* Define structures used to record attributes and values. */
126 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
127 encountered, we store all the relevant information into a
128 `struct insn_def'. This is done to allow attribute definitions to occur
129 anywhere in the file. */
133 int insn_code
; /* Instruction number. */
134 int insn_index
; /* Expression numer in file, for errors. */
135 struct insn_def
*next
; /* Next insn in chain. */
136 rtx def
; /* The DEFINE_... */
137 int num_alternatives
; /* Number of alternatives. */
138 int vec_idx
; /* Index of attribute vector in `def'. */
141 /* Once everything has been read in, we store in each attribute value a list
142 of insn codes that have that value. Here is the structure used for the
147 int insn_code
; /* Instruction number. */
148 int insn_index
; /* Index of definition in file */
149 struct insn_ent
*next
; /* Next in chain. */
152 /* Each value of an attribute (either constant or computed) is assigned a
153 structure which is used as the listhead of the insns that have that
158 rtx value
; /* Value of attribute. */
159 struct attr_value
*next
; /* Next attribute value in chain. */
160 struct insn_ent
*first_insn
; /* First insn with this value. */
161 int num_insns
; /* Number of insns with this value. */
162 int has_asm_insn
; /* True if this value used for `asm' insns */
165 /* Structure for each attribute. */
169 char *name
; /* Name of attribute. */
170 struct attr_desc
*next
; /* Next attribute. */
171 unsigned is_numeric
: 1; /* Values of this attribute are numeric. */
172 unsigned negative_ok
: 1; /* Allow negative numeric values. */
173 unsigned unsigned_p
: 1; /* Make the output function unsigned int. */
174 unsigned is_const
: 1; /* Attribute value constant for each run. */
175 unsigned is_special
: 1; /* Don't call `write_attr_set'. */
176 unsigned func_units_p
: 1; /* this is the function_units attribute */
177 unsigned blockage_p
: 1; /* this is the blockage range function */
178 struct attr_value
*first_value
; /* First value of this attribute. */
179 struct attr_value
*default_val
; /* Default value for this attribute. */
182 #define NULL_ATTR (struct attr_desc *) NULL
184 /* A range of values. */
192 /* Structure for each DEFINE_DELAY. */
196 rtx def
; /* DEFINE_DELAY expression. */
197 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
198 int num
; /* Number of DEFINE_DELAY, starting at 1. */
201 /* Record information about each DEFINE_FUNCTION_UNIT. */
203 struct function_unit_op
205 rtx condexp
; /* Expression TRUE for applicable insn. */
206 struct function_unit_op
*next
; /* Next operation for this function unit. */
207 int num
; /* Ordinal for this operation type in unit. */
208 int ready
; /* Cost until data is ready. */
209 int issue_delay
; /* Cost until unit can accept another insn. */
210 rtx conflict_exp
; /* Expression TRUE for insns incurring issue delay. */
211 rtx issue_exp
; /* Expression computing issue delay. */
214 /* Record information about each function unit mentioned in a
215 DEFINE_FUNCTION_UNIT. */
219 const char *name
; /* Function unit name. */
220 struct function_unit
*next
; /* Next function unit. */
221 int num
; /* Ordinal of this unit type. */
222 int multiplicity
; /* Number of units of this type. */
223 int simultaneity
; /* Maximum number of simultaneous insns
224 on this function unit or 0 if unlimited. */
225 rtx condexp
; /* Expression TRUE for insn needing unit. */
226 int num_opclasses
; /* Number of different operation types. */
227 struct function_unit_op
*ops
; /* Pointer to first operation type. */
228 int needs_conflict_function
; /* Nonzero if a conflict function required. */
229 int needs_blockage_function
; /* Nonzero if a blockage function required. */
230 int needs_range_function
; /* Nonzero if blockage range function needed.*/
231 rtx default_cost
; /* Conflict cost, if constant. */
232 struct range issue_delay
; /* Range of issue delay values. */
233 int max_blockage
; /* Maximum time an insn blocks the unit. */
236 /* Listheads of above structures. */
238 /* This one is indexed by the first character of the attribute name. */
239 #define MAX_ATTRS_INDEX 256
240 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
241 static struct insn_def
*defs
;
242 static struct delay_desc
*delays
;
243 static struct function_unit
*units
;
245 /* An expression where all the unknown terms are EQ_ATTR tests can be
246 rearranged into a COND provided we can enumerate all possible
247 combinations of the unknown values. The set of combinations become the
248 tests of the COND; the value of the expression given that combination is
249 computed and becomes the corresponding value. To do this, we must be
250 able to enumerate all values for each attribute used in the expression
251 (currently, we give up if we find a numeric attribute).
253 If the set of EQ_ATTR tests used in an expression tests the value of N
254 different attributes, the list of all possible combinations can be made
255 by walking the N-dimensional attribute space defined by those
256 attributes. We record each of these as a struct dimension.
258 The algorithm relies on sharing EQ_ATTR nodes: if two nodes in an
259 expression are the same, the will also have the same address. We find
260 all the EQ_ATTR nodes by marking them MEM_VOLATILE_P. This bit later
261 represents the value of an EQ_ATTR node, so once all nodes are marked,
262 they are also given an initial value of FALSE.
264 We then separate the set of EQ_ATTR nodes into dimensions for each
265 attribute and put them on the VALUES list. Terms are added as needed by
266 `add_values_to_cover' so that all possible values of the attribute are
269 Each dimension also has a current value. This is the node that is
270 currently considered to be TRUE. If this is one of the nodes added by
271 `add_values_to_cover', all the EQ_ATTR tests in the original expression
272 will be FALSE. Otherwise, only the CURRENT_VALUE will be true.
274 NUM_VALUES is simply the length of the VALUES list and is there for
277 Once the dimensions are created, the algorithm enumerates all possible
278 values and computes the current value of the given expression. */
282 struct attr_desc
*attr
; /* Attribute for this dimension. */
283 rtx values
; /* List of attribute values used. */
284 rtx current_value
; /* Position in the list for the TRUE value. */
285 int num_values
; /* Length of the values list. */
288 /* Other variables. */
290 static int insn_code_number
;
291 static int insn_index_number
;
292 static int got_define_asm_attributes
;
293 static int must_extract
;
294 static int must_constrain
;
295 static int address_used
;
296 static int length_used
;
297 static int num_delays
;
298 static int have_annul_true
, have_annul_false
;
299 static int num_units
, num_unit_opclasses
;
300 static int num_insn_ents
;
302 /* Used as operand to `operate_exp': */
304 enum operator {PLUS_OP
, MINUS_OP
, POS_MINUS_OP
, EQ_OP
, OR_OP
, ORX_OP
, MAX_OP
, MIN_OP
, RANGE_OP
};
306 /* Stores, for each insn code, the number of constraint alternatives. */
308 static int *insn_n_alternatives
;
310 /* Stores, for each insn code, a bitmap that has bits on for each possible
313 static int *insn_alternatives
;
315 /* If nonzero, assume that the `alternative' attr has this value.
316 This is the hashed, unique string for the numeral
317 whose value is chosen alternative. */
319 static const char *current_alternative_string
;
321 /* Used to simplify expressions. */
323 static rtx true_rtx
, false_rtx
;
325 /* Used to reduce calls to `strcmp' */
327 static char *alternative_name
;
329 /* Indicate that REG_DEAD notes are valid if dead_or_set_p is ever
332 int reload_completed
= 0;
334 /* Some machines test `optimize' in macros called from rtlanal.c, so we need
335 to define it here. */
339 /* Simplify an expression. Only call the routine if there is something to
341 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
342 (RTX_UNCHANGING_P (EXP) || MEM_IN_STRUCT_P (EXP) ? (EXP) \
343 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
345 /* Simplify (eq_attr ("alternative") ...)
346 when we are working with a particular alternative. */
347 #define SIMPLIFY_ALTERNATIVE(EXP) \
348 if (current_alternative_string \
349 && GET_CODE ((EXP)) == EQ_ATTR \
350 && XSTR ((EXP), 0) == alternative_name) \
351 (EXP) = (XSTR ((EXP), 1) == current_alternative_string \
352 ? true_rtx : false_rtx);
354 /* These are referenced by rtlanal.c and hence need to be defined somewhere.
355 They won't actually be used. */
357 rtx global_rtl
[GR_MAX
];
358 rtx pic_offset_table_rtx
;
360 static void attr_hash_add_rtx
PARAMS ((int, rtx
));
361 static void attr_hash_add_string
PARAMS ((int, char *));
362 static rtx attr_rtx
PARAMS ((enum rtx_code
, ...));
363 static char *attr_printf
PARAMS ((int, const char *, ...))
365 static char *attr_string
PARAMS ((const char *, int));
366 static rtx check_attr_test
PARAMS ((rtx
, int));
367 static rtx check_attr_value
PARAMS ((rtx
, struct attr_desc
*));
368 static rtx convert_set_attr_alternative
PARAMS ((rtx
, int, int));
369 static rtx convert_set_attr
PARAMS ((rtx
, int, int));
370 static void check_defs
PARAMS ((void));
372 static rtx convert_const_symbol_ref
PARAMS ((rtx
, struct attr_desc
*));
374 static rtx make_canonical
PARAMS ((struct attr_desc
*, rtx
));
375 static struct attr_value
*get_attr_value
PARAMS ((rtx
, struct attr_desc
*, int));
376 static rtx copy_rtx_unchanging
PARAMS ((rtx
));
377 static rtx copy_boolean
PARAMS ((rtx
));
378 static void expand_delays
PARAMS ((void));
379 static rtx operate_exp
PARAMS ((enum operator, rtx
, rtx
));
380 static void expand_units
PARAMS ((void));
381 static rtx simplify_knowing
PARAMS ((rtx
, rtx
));
382 static rtx encode_units_mask
PARAMS ((rtx
));
383 static void fill_attr
PARAMS ((struct attr_desc
*));
384 /* dpx2 compiler chokes if we specify the arg types of the args. */
385 static rtx substitute_address
PARAMS ((rtx
, rtx (*) (rtx
), rtx (*) (rtx
)));
386 static void make_length_attrs
PARAMS ((void));
387 static rtx identity_fn
PARAMS ((rtx
));
388 static rtx zero_fn
PARAMS ((rtx
));
389 static rtx one_fn
PARAMS ((rtx
));
390 static rtx max_fn
PARAMS ((rtx
));
391 static void write_length_unit_log
PARAMS ((void));
392 static rtx simplify_cond
PARAMS ((rtx
, int, int));
394 static rtx simplify_by_alternatives
PARAMS ((rtx
, int, int));
396 static rtx simplify_by_exploding
PARAMS ((rtx
));
397 static int find_and_mark_used_attributes
PARAMS ((rtx
, rtx
*, int *));
398 static void unmark_used_attributes
PARAMS ((rtx
, struct dimension
*, int));
399 static int add_values_to_cover
PARAMS ((struct dimension
*));
400 static int increment_current_value
PARAMS ((struct dimension
*, int));
401 static rtx test_for_current_value
PARAMS ((struct dimension
*, int));
402 static rtx simplify_with_current_value
PARAMS ((rtx
, struct dimension
*, int));
403 static rtx simplify_with_current_value_aux
PARAMS ((rtx
));
404 static void clear_struct_flag
PARAMS ((rtx
));
405 static int count_sub_rtxs
PARAMS ((rtx
, int));
406 static void remove_insn_ent
PARAMS ((struct attr_value
*, struct insn_ent
*));
407 static void insert_insn_ent
PARAMS ((struct attr_value
*, struct insn_ent
*));
408 static rtx insert_right_side
PARAMS ((enum rtx_code
, rtx
, rtx
, int, int));
409 static rtx make_alternative_compare
PARAMS ((int));
410 static int compute_alternative_mask
PARAMS ((rtx
, enum rtx_code
));
411 static rtx evaluate_eq_attr
PARAMS ((rtx
, rtx
, int, int));
412 static rtx simplify_and_tree
PARAMS ((rtx
, rtx
*, int, int));
413 static rtx simplify_or_tree
PARAMS ((rtx
, rtx
*, int, int));
414 static rtx simplify_test_exp
PARAMS ((rtx
, int, int));
415 static void optimize_attrs
PARAMS ((void));
416 static void gen_attr
PARAMS ((rtx
));
417 static int count_alternatives
PARAMS ((rtx
));
418 static int compares_alternatives_p
PARAMS ((rtx
));
419 static int contained_in_p
PARAMS ((rtx
, rtx
));
420 static void gen_insn
PARAMS ((rtx
));
421 static void gen_delay
PARAMS ((rtx
));
422 static void gen_unit
PARAMS ((rtx
));
423 static void write_test_expr
PARAMS ((rtx
, int));
424 static int max_attr_value
PARAMS ((rtx
, int*));
425 static int or_attr_value
PARAMS ((rtx
, int*));
426 static void walk_attr_value
PARAMS ((rtx
));
427 static void write_attr_get
PARAMS ((struct attr_desc
*));
428 static rtx eliminate_known_true
PARAMS ((rtx
, rtx
, int, int));
429 static void write_attr_set
PARAMS ((struct attr_desc
*, int, rtx
,
430 const char *, const char *, rtx
,
432 static void write_attr_case
PARAMS ((struct attr_desc
*, struct attr_value
*,
433 int, const char *, const char *, int, rtx
));
434 static void write_unit_name
PARAMS ((const char *, int, const char *));
435 static void write_attr_valueq
PARAMS ((struct attr_desc
*, const char *));
436 static void write_attr_value
PARAMS ((struct attr_desc
*, rtx
));
437 static void write_upcase
PARAMS ((const char *));
438 static void write_indent
PARAMS ((int));
439 static void write_eligible_delay
PARAMS ((const char *));
440 static void write_function_unit_info
PARAMS ((void));
441 static void write_complex_function
PARAMS ((struct function_unit
*, const char *,
443 static int write_expr_attr_cache
PARAMS ((rtx
, struct attr_desc
*));
444 static void write_toplevel_expr
PARAMS ((rtx
));
445 static void write_const_num_delay_slots
PARAMS ((void));
446 static int n_comma_elts
PARAMS ((const char *));
447 static char *next_comma_elt
PARAMS ((const char **));
448 static struct attr_desc
*find_attr
PARAMS ((const char *, int));
449 static void make_internal_attr
PARAMS ((const char *, rtx
, int));
450 static struct attr_value
*find_most_used
PARAMS ((struct attr_desc
*));
451 static rtx find_single_value
PARAMS ((struct attr_desc
*));
452 static rtx make_numeric_value
PARAMS ((int));
453 static void extend_range
PARAMS ((struct range
*, int, int));
454 static rtx attr_eq
PARAMS ((const char *, const char *));
455 static const char *attr_numeral
PARAMS ((int));
456 static int attr_equal_p
PARAMS ((rtx
, rtx
));
457 static rtx attr_copy_rtx
PARAMS ((rtx
));
459 #define oballoc(size) obstack_alloc (hash_obstack, size)
462 /* Hash table for sharing RTL and strings. */
464 /* Each hash table slot is a bucket containing a chain of these structures.
465 Strings are given negative hash codes; RTL expressions are given positive
470 struct attr_hash
*next
; /* Next structure in the bucket. */
471 int hashcode
; /* Hash code of this rtx or string. */
474 char *str
; /* The string (negative hash codes) */
475 rtx rtl
; /* or the RTL recorded here. */
479 /* Now here is the hash table. When recording an RTL, it is added to
480 the slot whose index is the hash code mod the table size. Note
481 that the hash table is used for several kinds of RTL (see attr_rtx)
482 and for strings. While all these live in the same table, they are
483 completely independent, and the hash code is computed differently
486 #define RTL_HASH_SIZE 4093
487 struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
489 /* Here is how primitive or already-shared RTL's hash
491 #define RTL_HASH(RTL) ((long) (RTL) & 0777777)
493 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
496 attr_hash_add_rtx (hashcode
, rtl
)
500 register struct attr_hash
*h
;
502 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
503 sizeof (struct attr_hash
));
504 h
->hashcode
= hashcode
;
506 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
507 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
510 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
513 attr_hash_add_string (hashcode
, str
)
517 register struct attr_hash
*h
;
519 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
520 sizeof (struct attr_hash
));
521 h
->hashcode
= -hashcode
;
523 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
524 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
527 /* Generate an RTL expression, but avoid duplicates.
528 Set the RTX_INTEGRATED_P flag for these permanent objects.
530 In some cases we cannot uniquify; then we return an ordinary
531 impermanent rtx with RTX_INTEGRATED_P clear.
533 Args are like gen_rtx, but without the mode:
535 rtx attr_rtx (code, [element1, ..., elementn]) */
539 attr_rtx
VPARAMS ((enum rtx_code code
, ...))
541 #ifndef ANSI_PROTOTYPES
545 register int i
; /* Array indices... */
546 register const char *fmt
; /* Current rtx's format... */
547 register rtx rt_val
= NULL_RTX
;/* RTX to return to caller... */
549 register struct attr_hash
*h
;
550 struct obstack
*old_obstack
= rtl_obstack
;
554 #ifndef ANSI_PROTOTYPES
555 code
= va_arg (p
, enum rtx_code
);
558 /* For each of several cases, search the hash table for an existing entry.
559 Use that entry if one is found; otherwise create a new RTL and add it
562 if (GET_RTX_CLASS (code
) == '1')
564 rtx arg0
= va_arg (p
, rtx
);
566 /* A permanent object cannot point to impermanent ones. */
567 if (! RTX_INTEGRATED_P (arg0
))
569 rt_val
= rtx_alloc (code
);
570 XEXP (rt_val
, 0) = arg0
;
575 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
576 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
577 if (h
->hashcode
== hashcode
578 && GET_CODE (h
->u
.rtl
) == code
579 && XEXP (h
->u
.rtl
, 0) == arg0
)
584 rtl_obstack
= hash_obstack
;
585 rt_val
= rtx_alloc (code
);
586 XEXP (rt_val
, 0) = arg0
;
589 else if (GET_RTX_CLASS (code
) == 'c'
590 || GET_RTX_CLASS (code
) == '2'
591 || GET_RTX_CLASS (code
) == '<')
593 rtx arg0
= va_arg (p
, rtx
);
594 rtx arg1
= va_arg (p
, rtx
);
596 /* A permanent object cannot point to impermanent ones. */
597 if (! RTX_INTEGRATED_P (arg0
) || ! RTX_INTEGRATED_P (arg1
))
599 rt_val
= rtx_alloc (code
);
600 XEXP (rt_val
, 0) = arg0
;
601 XEXP (rt_val
, 1) = arg1
;
606 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
607 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
608 if (h
->hashcode
== hashcode
609 && GET_CODE (h
->u
.rtl
) == code
610 && XEXP (h
->u
.rtl
, 0) == arg0
611 && XEXP (h
->u
.rtl
, 1) == arg1
)
616 rtl_obstack
= hash_obstack
;
617 rt_val
= rtx_alloc (code
);
618 XEXP (rt_val
, 0) = arg0
;
619 XEXP (rt_val
, 1) = arg1
;
622 else if (GET_RTX_LENGTH (code
) == 1
623 && GET_RTX_FORMAT (code
)[0] == 's')
625 char * arg0
= va_arg (p
, char *);
627 if (code
== SYMBOL_REF
)
628 arg0
= attr_string (arg0
, strlen (arg0
));
630 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
631 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
632 if (h
->hashcode
== hashcode
633 && GET_CODE (h
->u
.rtl
) == code
634 && XSTR (h
->u
.rtl
, 0) == arg0
)
639 rtl_obstack
= hash_obstack
;
640 rt_val
= rtx_alloc (code
);
641 XSTR (rt_val
, 0) = arg0
;
644 else if (GET_RTX_LENGTH (code
) == 2
645 && GET_RTX_FORMAT (code
)[0] == 's'
646 && GET_RTX_FORMAT (code
)[1] == 's')
648 char *arg0
= va_arg (p
, char *);
649 char *arg1
= va_arg (p
, char *);
651 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
652 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
653 if (h
->hashcode
== hashcode
654 && GET_CODE (h
->u
.rtl
) == code
655 && XSTR (h
->u
.rtl
, 0) == arg0
656 && XSTR (h
->u
.rtl
, 1) == arg1
)
661 rtl_obstack
= hash_obstack
;
662 rt_val
= rtx_alloc (code
);
663 XSTR (rt_val
, 0) = arg0
;
664 XSTR (rt_val
, 1) = arg1
;
667 else if (code
== CONST_INT
)
669 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
685 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
687 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
688 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
692 case '0': /* Unused field. */
695 case 'i': /* An integer? */
696 XINT (rt_val
, i
) = va_arg (p
, int);
699 case 'w': /* A wide integer? */
700 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
703 case 's': /* A string? */
704 XSTR (rt_val
, i
) = va_arg (p
, char *);
707 case 'e': /* An expression? */
708 case 'u': /* An insn? Same except when printing. */
709 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
712 case 'E': /* An RTX vector? */
713 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
724 rtl_obstack
= old_obstack
;
726 attr_hash_add_rtx (hashcode
, rt_val
);
727 RTX_INTEGRATED_P (rt_val
) = 1;
735 /* Create a new string printed with the printf line arguments into a space
736 of at most LEN bytes:
738 rtx attr_printf (len, format, [arg1, ..., argn]) */
742 attr_printf
VPARAMS ((register int len
, const char *fmt
, ...))
744 #ifndef ANSI_PROTOTYPES
753 #ifndef ANSI_PROTOTYPES
754 len
= va_arg (p
, int);
755 fmt
= va_arg (p
, const char *);
758 /* Print the string into a temporary location. */
759 str
= (char *) alloca (len
);
760 vsprintf (str
, fmt
, p
);
763 return attr_string (str
, strlen (str
));
767 attr_eq (name
, value
)
768 const char *name
, *value
;
770 return attr_rtx (EQ_ATTR
, attr_string (name
, strlen (name
)),
771 attr_string (value
, strlen (value
)));
778 return XSTR (make_numeric_value (n
), 0);
781 /* Return a permanent (possibly shared) copy of a string STR (not assumed
782 to be null terminated) with LEN bytes. */
785 attr_string (str
, len
)
789 register struct attr_hash
*h
;
792 register char *new_str
;
794 /* Compute the hash code. */
795 hashcode
= (len
+ 1) * 613 + (unsigned)str
[0];
796 for (i
= 1; i
<= len
; i
+= 2)
797 hashcode
= ((hashcode
* 613) + (unsigned)str
[i
]);
799 hashcode
= -hashcode
;
801 /* Search the table for the string. */
802 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
803 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
804 && !strncmp (h
->u
.str
, str
, len
))
805 return h
->u
.str
; /* <-- return if found. */
807 /* Not found; create a permanent copy and add it to the hash table. */
808 new_str
= (char *) obstack_alloc (hash_obstack
, len
+ 1);
809 bcopy (str
, new_str
, len
);
811 attr_hash_add_string (hashcode
, new_str
);
813 return new_str
; /* Return the new string. */
816 /* Check two rtx's for equality of contents,
817 taking advantage of the fact that if both are hashed
818 then they can't be equal unless they are the same object. */
824 return (x
== y
|| (! (RTX_INTEGRATED_P (x
) && RTX_INTEGRATED_P (y
))
825 && rtx_equal_p (x
, y
)));
828 /* Copy an attribute value expression,
829 descending to all depths, but not copying any
830 permanent hashed subexpressions. */
838 register RTX_CODE code
;
839 register const char *format_ptr
;
841 /* No need to copy a permanent object. */
842 if (RTX_INTEGRATED_P (orig
))
845 code
= GET_CODE (orig
);
863 copy
= rtx_alloc (code
);
864 PUT_MODE (copy
, GET_MODE (orig
));
865 copy
->in_struct
= orig
->in_struct
;
866 copy
->volatil
= orig
->volatil
;
867 copy
->unchanging
= orig
->unchanging
;
868 copy
->integrated
= orig
->integrated
;
870 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
872 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
874 switch (*format_ptr
++)
877 XEXP (copy
, i
) = XEXP (orig
, i
);
878 if (XEXP (orig
, i
) != NULL
)
879 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
884 XVEC (copy
, i
) = XVEC (orig
, i
);
885 if (XVEC (orig
, i
) != NULL
)
887 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
888 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
889 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
895 XINT (copy
, i
) = XINT (orig
, i
);
899 XWINT (copy
, i
) = XWINT (orig
, i
);
904 XSTR (copy
, i
) = XSTR (orig
, i
);
914 /* Given a test expression for an attribute, ensure it is validly formed.
915 IS_CONST indicates whether the expression is constant for each compiler
916 run (a constant expression may not test any particular insn).
918 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
919 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
920 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
922 Update the string address in EQ_ATTR expression to be the same used
923 in the attribute (or `alternative_name') to speed up subsequent
924 `find_attr' calls and eliminate most `strcmp' calls.
926 Return the new expression, if any. */
929 check_attr_test (exp
, is_const
)
933 struct attr_desc
*attr
;
934 struct attr_value
*av
;
935 const char *name_ptr
, *p
;
938 switch (GET_CODE (exp
))
941 /* Handle negation test. */
942 if (XSTR (exp
, 1)[0] == '!')
943 return check_attr_test (attr_rtx (NOT
,
944 attr_eq (XSTR (exp
, 0),
948 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
950 attr
= find_attr (XSTR (exp
, 0), 0);
953 if (! strcmp (XSTR (exp
, 0), "alternative"))
955 XSTR (exp
, 0) = alternative_name
;
956 /* This can't be simplified any further. */
957 RTX_UNCHANGING_P (exp
) = 1;
961 fatal ("Unknown attribute `%s' in EQ_ATTR", XSTR (exp
, 0));
964 if (is_const
&& ! attr
->is_const
)
965 fatal ("Constant expression uses insn attribute `%s' in EQ_ATTR",
968 /* Copy this just to make it permanent,
969 so expressions using it can be permanent too. */
970 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
972 /* It shouldn't be possible to simplify the value given to a
973 constant attribute, so don't expand this until it's time to
974 write the test expression. */
976 RTX_UNCHANGING_P (exp
) = 1;
978 if (attr
->is_numeric
)
980 for (p
= XSTR (exp
, 1); *p
; p
++)
981 if (*p
< '0' || *p
> '9')
982 fatal ("Attribute `%s' takes only numeric values",
987 for (av
= attr
->first_value
; av
; av
= av
->next
)
988 if (GET_CODE (av
->value
) == CONST_STRING
989 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
993 fatal ("Unknown value `%s' for `%s' attribute",
994 XSTR (exp
, 1), XSTR (exp
, 0));
999 /* Make an IOR tree of the possible values. */
1001 name_ptr
= XSTR (exp
, 1);
1002 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1004 newexp
= attr_eq (XSTR (exp
, 0), p
);
1005 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
1008 return check_attr_test (orexp
, is_const
);
1016 /* Either TRUE or FALSE. */
1024 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
);
1025 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
);
1029 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
);
1035 fatal ("RTL operator \"%s\" not valid in constant attribute test",
1036 GET_RTX_NAME (GET_CODE (exp
)));
1037 /* These cases can't be simplified. */
1038 RTX_UNCHANGING_P (exp
) = 1;
1041 case LE
: case LT
: case GT
: case GE
:
1042 case LEU
: case LTU
: case GTU
: case GEU
:
1044 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
1045 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
1046 exp
= attr_rtx (GET_CODE (exp
),
1047 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
1048 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
1049 /* These cases can't be simplified. */
1050 RTX_UNCHANGING_P (exp
) = 1;
1056 /* These cases are valid for constant attributes, but can't be
1058 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1059 RTX_UNCHANGING_P (exp
) = 1;
1063 fatal ("RTL operator \"%s\" not valid in attribute test",
1064 GET_RTX_NAME (GET_CODE (exp
)));
1070 /* Given an expression, ensure that it is validly formed and that all named
1071 attribute values are valid for the given attribute. Issue a fatal error
1072 if not. If no attribute is specified, assume a numeric attribute.
1074 Return a perhaps modified replacement expression for the value. */
1077 check_attr_value (exp
, attr
)
1079 struct attr_desc
*attr
;
1081 struct attr_value
*av
;
1085 switch (GET_CODE (exp
))
1088 if (attr
&& ! attr
->is_numeric
)
1089 fatal ("CONST_INT not valid for non-numeric `%s' attribute",
1092 if (INTVAL (exp
) < 0 && ! attr
->negative_ok
)
1093 fatal ("Negative numeric value specified for `%s' attribute",
1099 if (! strcmp (XSTR (exp
, 0), "*"))
1102 if (attr
== 0 || attr
->is_numeric
)
1105 if (attr
&& attr
->negative_ok
&& *p
== '-')
1108 if (*p
> '9' || *p
< '0')
1109 fatal ("Non-numeric value for numeric `%s' attribute",
1110 attr
? attr
->name
: "internal");
1114 for (av
= attr
->first_value
; av
; av
= av
->next
)
1115 if (GET_CODE (av
->value
) == CONST_STRING
1116 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
1120 fatal ("Unknown value `%s' for `%s' attribute",
1121 XSTR (exp
, 0), attr
? attr
->name
: "internal");
1126 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
1127 attr
? attr
->is_const
: 0);
1128 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1129 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
1137 if (attr
&& !attr
->is_numeric
)
1138 fatal ("Invalid operation `%s' for non-numeric attribute value",
1139 GET_RTX_NAME (GET_CODE (exp
)));
1144 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1145 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1149 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1153 if (XVECLEN (exp
, 0) % 2 != 0)
1154 fatal ("First operand of COND must have even length");
1156 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1158 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1159 attr
? attr
->is_const
: 0);
1160 XVECEXP (exp
, 0, i
+ 1)
1161 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1164 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1169 struct attr_desc
*attr2
= find_attr (XSTR (exp
, 0), 0);
1171 fatal ("Unknown attribute `%s' in ATTR", XSTR (exp
, 0));
1172 else if ((attr
&& attr
->is_const
) && ! attr2
->is_const
)
1173 fatal ("Non-constant attribute `%s' referenced from `%s'",
1174 XSTR (exp
, 0), attr
->name
);
1176 && (attr
->is_numeric
!= attr2
->is_numeric
1177 || (! attr
->negative_ok
&& attr2
->negative_ok
)))
1178 fatal ("Numeric attribute mismatch calling `%s' from `%s'",
1179 XSTR (exp
, 0), attr
->name
);
1184 /* A constant SYMBOL_REF is valid as a constant attribute test and
1185 is expanded later by make_canonical into a COND. In a non-constant
1186 attribute test, it is left be. */
1187 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1190 fatal ("Invalid operation `%s' for attribute value",
1191 GET_RTX_NAME (GET_CODE (exp
)));
1197 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1198 It becomes a COND with each test being (eq_attr "alternative "n") */
1201 convert_set_attr_alternative (exp
, num_alt
, insn_index
)
1209 if (XVECLEN (exp
, 1) != num_alt
)
1210 fatal ("Bad number of entries in SET_ATTR_ALTERNATIVE for insn %d",
1213 /* Make a COND with all tests but the last. Select the last value via the
1215 condexp
= rtx_alloc (COND
);
1216 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1218 for (i
= 0; i
< num_alt
- 1; i
++)
1221 p
= attr_numeral (i
);
1223 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1225 /* Sharing this EQ_ATTR rtl causes trouble. */
1226 XVECEXP (condexp
, 0, 2 * i
) = rtx_alloc (EQ_ATTR
);
1227 XSTR (XVECEXP (condexp
, 0, 2 * i
), 0) = alternative_name
;
1228 XSTR (XVECEXP (condexp
, 0, 2 * i
), 1) = p
;
1230 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1233 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1235 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1238 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1239 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1242 convert_set_attr (exp
, num_alt
, insn_index
)
1248 const char *name_ptr
;
1252 /* See how many alternative specified. */
1253 n
= n_comma_elts (XSTR (exp
, 1));
1255 return attr_rtx (SET
,
1256 attr_rtx (ATTR
, XSTR (exp
, 0)),
1257 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1259 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1260 XSTR (newexp
, 0) = XSTR (exp
, 0);
1261 XVEC (newexp
, 1) = rtvec_alloc (n
);
1263 /* Process each comma-separated name. */
1264 name_ptr
= XSTR (exp
, 1);
1266 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1267 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1269 return convert_set_attr_alternative (newexp
, num_alt
, insn_index
);
1272 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1273 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1279 struct insn_def
*id
;
1280 struct attr_desc
*attr
;
1284 for (id
= defs
; id
; id
= id
->next
)
1286 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1289 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1291 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1292 switch (GET_CODE (value
))
1295 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1296 fatal ("Bad attribute set in pattern %d", id
->insn_index
);
1299 case SET_ATTR_ALTERNATIVE
:
1300 value
= convert_set_attr_alternative (value
,
1301 id
->num_alternatives
,
1306 value
= convert_set_attr (value
, id
->num_alternatives
,
1311 fatal ("Invalid attribute code `%s' for pattern %d",
1312 GET_RTX_NAME (GET_CODE (value
)), id
->insn_index
);
1315 if ((attr
= find_attr (XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1316 fatal ("Unknown attribute `%s' for pattern number %d",
1317 XSTR (XEXP (value
, 0), 0), id
->insn_index
);
1319 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1320 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1326 /* Given a constant SYMBOL_REF expression, convert to a COND that
1327 explicitly tests each enumerated value. */
1330 convert_const_symbol_ref (exp
, attr
)
1332 struct attr_desc
*attr
;
1335 struct attr_value
*av
;
1339 for (av
= attr
->first_value
; av
; av
= av
->next
)
1342 /* Make a COND with all tests but the last, and in the original order.
1343 Select the last value via the default. Note that the attr values
1344 are constructed in reverse order. */
1346 condexp
= rtx_alloc (COND
);
1347 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1348 av
= attr
->first_value
;
1349 XEXP (condexp
, 1) = av
->value
;
1351 for (i
= num_alt
- 2; av
= av
->next
, i
>= 0; i
--)
1356 string
= p
= (char *) oballoc (2
1357 + strlen (attr
->name
)
1358 + strlen (XSTR (av
->value
, 0)));
1359 strcpy (p
, attr
->name
);
1361 strcat (p
, XSTR (av
->value
, 0));
1362 for (; *p
!= '\0'; p
++)
1365 value
= attr_rtx (SYMBOL_REF
, string
);
1366 RTX_UNCHANGING_P (value
) = 1;
1368 XVECEXP (condexp
, 0, 2 * i
) = attr_rtx (EQ
, exp
, value
);
1370 XVECEXP (condexp
, 0, 2 * i
+ 1) = av
->value
;
1377 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1378 expressions by converting them into a COND. This removes cases from this
1379 program. Also, replace an attribute value of "*" with the default attribute
1383 make_canonical (attr
, exp
)
1384 struct attr_desc
*attr
;
1390 switch (GET_CODE (exp
))
1393 exp
= make_numeric_value (INTVAL (exp
));
1397 if (! strcmp (XSTR (exp
, 0), "*"))
1399 if (attr
== 0 || attr
->default_val
== 0)
1400 fatal ("(attr_value \"*\") used in invalid context.");
1401 exp
= attr
->default_val
->value
;
1407 if (!attr
->is_const
|| RTX_UNCHANGING_P (exp
))
1409 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1410 This makes the COND something that won't be considered an arbitrary
1411 expression by walk_attr_value. */
1412 RTX_UNCHANGING_P (exp
) = 1;
1414 /* ??? Why do we do this? With attribute values { A B C D E }, this
1415 tends to generate (!(x==A) && !(x==B) && !(x==C) && !(x==D)) rather
1417 exp
= convert_const_symbol_ref (exp
, attr
);
1418 RTX_UNCHANGING_P (exp
) = 1;
1419 exp
= check_attr_value (exp
, attr
);
1420 /* Goto COND case since this is now a COND. Note that while the
1421 new expression is rescanned, all symbol_ref notes are marked as
1425 exp
= check_attr_value (exp
, attr
);
1430 newexp
= rtx_alloc (COND
);
1431 XVEC (newexp
, 0) = rtvec_alloc (2);
1432 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1433 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1435 XEXP (newexp
, 1) = XEXP (exp
, 2);
1438 /* Fall through to COND case since this is now a COND. */
1445 /* First, check for degenerate COND. */
1446 if (XVECLEN (exp
, 0) == 0)
1447 return make_canonical (attr
, XEXP (exp
, 1));
1448 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1450 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1452 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1453 XVECEXP (exp
, 0, i
+ 1)
1454 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1455 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1474 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1475 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1476 copy_boolean (XEXP (exp
, 1)));
1480 /* Given a value and an attribute description, return a `struct attr_value *'
1481 that represents that value. This is either an existing structure, if the
1482 value has been previously encountered, or a newly-created structure.
1484 `insn_code' is the code of an insn whose attribute has the specified
1485 value (-2 if not processing an insn). We ensure that all insns for
1486 a given value have the same number of alternatives if the value checks
1489 static struct attr_value
*
1490 get_attr_value (value
, attr
, insn_code
)
1492 struct attr_desc
*attr
;
1495 struct attr_value
*av
;
1498 value
= make_canonical (attr
, value
);
1499 if (compares_alternatives_p (value
))
1501 if (insn_code
< 0 || insn_alternatives
== NULL
)
1502 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1504 num_alt
= insn_alternatives
[insn_code
];
1507 for (av
= attr
->first_value
; av
; av
= av
->next
)
1508 if (rtx_equal_p (value
, av
->value
)
1509 && (num_alt
== 0 || av
->first_insn
== NULL
1510 || insn_alternatives
[av
->first_insn
->insn_code
]))
1513 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
1515 av
->next
= attr
->first_value
;
1516 attr
->first_value
= av
;
1517 av
->first_insn
= NULL
;
1519 av
->has_asm_insn
= 0;
1524 /* After all DEFINE_DELAYs have been read in, create internal attributes
1525 to generate the required routines.
1527 First, we compute the number of delay slots for each insn (as a COND of
1528 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1529 delay type is specified, we compute a similar function giving the
1530 DEFINE_DELAY ordinal for each insn.
1532 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1533 tells whether a given insn can be in that delay slot.
1535 Normal attribute filling and optimization expands these to contain the
1536 information needed to handle delay slots. */
1541 struct delay_desc
*delay
;
1547 /* First, generate data for `num_delay_slots' function. */
1549 condexp
= rtx_alloc (COND
);
1550 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1551 XEXP (condexp
, 1) = make_numeric_value (0);
1553 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1555 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1556 XVECEXP (condexp
, 0, i
+ 1)
1557 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1560 make_internal_attr ("*num_delay_slots", condexp
, 0);
1562 /* If more than one delay type, do the same for computing the delay type. */
1565 condexp
= rtx_alloc (COND
);
1566 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1567 XEXP (condexp
, 1) = make_numeric_value (0);
1569 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1571 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1572 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1575 make_internal_attr ("*delay_type", condexp
, 1);
1578 /* For each delay possibility and delay slot, compute an eligibility
1579 attribute for non-annulled insns and for each type of annulled (annul
1580 if true and annul if false). */
1581 for (delay
= delays
; delay
; delay
= delay
->next
)
1583 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1585 condexp
= XVECEXP (delay
->def
, 1, i
);
1586 if (condexp
== 0) condexp
= false_rtx
;
1587 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1588 make_numeric_value (1), make_numeric_value (0));
1590 p
= attr_printf (sizeof ("*delay__") + MAX_DIGITS
*2, "*delay_%d_%d",
1592 make_internal_attr (p
, newexp
, 1);
1594 if (have_annul_true
)
1596 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1597 if (condexp
== 0) condexp
= false_rtx
;
1598 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1599 make_numeric_value (1),
1600 make_numeric_value (0));
1601 p
= attr_printf (sizeof ("*annul_true__") + MAX_DIGITS
*2,
1602 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1603 make_internal_attr (p
, newexp
, 1);
1606 if (have_annul_false
)
1608 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1609 if (condexp
== 0) condexp
= false_rtx
;
1610 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1611 make_numeric_value (1),
1612 make_numeric_value (0));
1613 p
= attr_printf (sizeof ("*annul_false__") + MAX_DIGITS
*2,
1614 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1615 make_internal_attr (p
, newexp
, 1);
1621 /* This function is given a left and right side expression and an operator.
1622 Each side is a conditional expression, each alternative of which has a
1623 numerical value. The function returns another conditional expression
1624 which, for every possible set of condition values, returns a value that is
1625 the operator applied to the values of the two sides.
1627 Since this is called early, it must also support IF_THEN_ELSE. */
1630 operate_exp (op
, left
, right
)
1634 int left_value
, right_value
;
1638 /* If left is a string, apply operator to it and the right side. */
1639 if (GET_CODE (left
) == CONST_STRING
)
1641 /* If right is also a string, just perform the operation. */
1642 if (GET_CODE (right
) == CONST_STRING
)
1644 left_value
= atoi (XSTR (left
, 0));
1645 right_value
= atoi (XSTR (right
, 0));
1649 i
= left_value
+ right_value
;
1653 i
= left_value
- right_value
;
1656 case POS_MINUS_OP
: /* The positive part of LEFT - RIGHT. */
1657 if (left_value
> right_value
)
1658 i
= left_value
- right_value
;
1665 i
= left_value
| right_value
;
1669 i
= left_value
== right_value
;
1673 i
= (left_value
<< (HOST_BITS_PER_INT
/ 2)) | right_value
;
1677 if (left_value
> right_value
)
1684 if (left_value
< right_value
)
1694 if (i
== left_value
)
1696 if (i
== right_value
)
1698 return make_numeric_value (i
);
1700 else if (GET_CODE (right
) == IF_THEN_ELSE
)
1702 /* Apply recursively to all values within. */
1703 rtx newleft
= operate_exp (op
, left
, XEXP (right
, 1));
1704 rtx newright
= operate_exp (op
, left
, XEXP (right
, 2));
1705 if (rtx_equal_p (newleft
, newright
))
1707 return attr_rtx (IF_THEN_ELSE
, XEXP (right
, 0), newleft
, newright
);
1709 else if (GET_CODE (right
) == COND
)
1714 newexp
= rtx_alloc (COND
);
1715 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (right
, 0));
1716 defval
= XEXP (newexp
, 1) = operate_exp (op
, left
, XEXP (right
, 1));
1718 for (i
= 0; i
< XVECLEN (right
, 0); i
+= 2)
1720 XVECEXP (newexp
, 0, i
) = XVECEXP (right
, 0, i
);
1721 XVECEXP (newexp
, 0, i
+ 1)
1722 = operate_exp (op
, left
, XVECEXP (right
, 0, i
+ 1));
1723 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1728 /* If the resulting cond is trivial (all alternatives
1729 give the same value), optimize it away. */
1733 obstack_free (rtl_obstack
, newexp
);
1734 return operate_exp (op
, left
, XEXP (right
, 1));
1737 /* If the result is the same as the RIGHT operand,
1739 if (rtx_equal_p (newexp
, right
))
1742 obstack_free (rtl_obstack
, newexp
);
1749 fatal ("Badly formed attribute value");
1752 /* A hack to prevent expand_units from completely blowing up: ORX_OP does
1753 not associate through IF_THEN_ELSE. */
1754 else if (op
== ORX_OP
&& GET_CODE (right
) == IF_THEN_ELSE
)
1756 return attr_rtx (IOR
, left
, right
);
1759 /* Otherwise, do recursion the other way. */
1760 else if (GET_CODE (left
) == IF_THEN_ELSE
)
1762 rtx newleft
= operate_exp (op
, XEXP (left
, 1), right
);
1763 rtx newright
= operate_exp (op
, XEXP (left
, 2), right
);
1764 if (rtx_equal_p (newleft
, newright
))
1766 return attr_rtx (IF_THEN_ELSE
, XEXP (left
, 0), newleft
, newright
);
1768 else if (GET_CODE (left
) == COND
)
1773 newexp
= rtx_alloc (COND
);
1774 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (left
, 0));
1775 defval
= XEXP (newexp
, 1) = operate_exp (op
, XEXP (left
, 1), right
);
1777 for (i
= 0; i
< XVECLEN (left
, 0); i
+= 2)
1779 XVECEXP (newexp
, 0, i
) = XVECEXP (left
, 0, i
);
1780 XVECEXP (newexp
, 0, i
+ 1)
1781 = operate_exp (op
, XVECEXP (left
, 0, i
+ 1), right
);
1782 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1787 /* If the cond is trivial (all alternatives give the same value),
1788 optimize it away. */
1792 obstack_free (rtl_obstack
, newexp
);
1793 return operate_exp (op
, XEXP (left
, 1), right
);
1796 /* If the result is the same as the LEFT operand,
1798 if (rtx_equal_p (newexp
, left
))
1801 obstack_free (rtl_obstack
, newexp
);
1809 fatal ("Badly formed attribute value.");
1814 /* Once all attributes and DEFINE_FUNCTION_UNITs have been read, we
1815 construct a number of attributes.
1817 The first produces a function `function_units_used' which is given an
1818 insn and produces an encoding showing which function units are required
1819 for the execution of that insn. If the value is non-negative, the insn
1820 uses that unit; otherwise, the value is a one's compliment mask of units
1823 The second produces a function `result_ready_cost' which is used to
1824 determine the time that the result of an insn will be ready and hence
1825 a worst-case schedule.
1827 Both of these produce quite complex expressions which are then set as the
1828 default value of internal attributes. Normal attribute simplification
1829 should produce reasonable expressions.
1831 For each unit, a `<name>_unit_ready_cost' function will take an
1832 insn and give the delay until that unit will be ready with the result
1833 and a `<name>_unit_conflict_cost' function is given an insn already
1834 executing on the unit and a candidate to execute and will give the
1835 cost from the time the executing insn started until the candidate
1836 can start (ignore limitations on the number of simultaneous insns).
1838 For each unit, a `<name>_unit_blockage' function is given an insn
1839 already executing on the unit and a candidate to execute and will
1840 give the delay incurred due to function unit conflicts. The range of
1841 blockage cost values for a given executing insn is given by the
1842 `<name>_unit_blockage_range' function. These values are encoded in
1843 an int where the upper half gives the minimum value and the lower
1844 half gives the maximum value. */
1849 struct function_unit
*unit
, **unit_num
;
1850 struct function_unit_op
*op
, **op_array
, ***unit_ops
;
1855 int i
, j
, u
, num
, nvalues
;
1857 /* Rebuild the condition for the unit to share the RTL expressions.
1858 Sharing is required by simplify_by_exploding. Build the issue delay
1859 expressions. Validate the expressions we were given for the conditions
1860 and conflict vector. Then make attributes for use in the conflict
1863 for (unit
= units
; unit
; unit
= unit
->next
)
1865 unit
->condexp
= check_attr_test (unit
->condexp
, 0);
1867 for (op
= unit
->ops
; op
; op
= op
->next
)
1869 rtx issue_delay
= make_numeric_value (op
->issue_delay
);
1870 rtx issue_exp
= issue_delay
;
1872 /* Build, validate, and simplify the issue delay expression. */
1873 if (op
->conflict_exp
!= true_rtx
)
1874 issue_exp
= attr_rtx (IF_THEN_ELSE
, op
->conflict_exp
,
1875 issue_exp
, make_numeric_value (0));
1876 issue_exp
= check_attr_value (make_canonical (NULL_ATTR
,
1879 issue_exp
= simplify_knowing (issue_exp
, unit
->condexp
);
1880 op
->issue_exp
= issue_exp
;
1882 /* Make an attribute for use in the conflict function if needed. */
1883 unit
->needs_conflict_function
= (unit
->issue_delay
.min
1884 != unit
->issue_delay
.max
);
1885 if (unit
->needs_conflict_function
)
1887 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_cost_") + MAX_DIGITS
,
1888 "*%s_cost_%d", unit
->name
, op
->num
);
1889 make_internal_attr (str
, issue_exp
, 1);
1892 /* Validate the condition. */
1893 op
->condexp
= check_attr_test (op
->condexp
, 0);
1897 /* Compute the mask of function units used. Initially, the unitsmask is
1898 zero. Set up a conditional to compute each unit's contribution. */
1899 unitsmask
= make_numeric_value (0);
1900 newexp
= rtx_alloc (IF_THEN_ELSE
);
1901 XEXP (newexp
, 2) = make_numeric_value (0);
1903 /* If we have just a few units, we may be all right expanding the whole
1904 thing. But the expansion is 2**N in space on the number of opclasses,
1905 so we can't do this for very long -- Alpha and MIPS in particular have
1906 problems with this. So in that situation, we fall back on an alternate
1907 implementation method. */
1908 #define NUM_UNITOP_CUTOFF 20
1910 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1912 /* Merge each function unit into the unit mask attributes. */
1913 for (unit
= units
; unit
; unit
= unit
->next
)
1915 XEXP (newexp
, 0) = unit
->condexp
;
1916 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1917 unitsmask
= operate_exp (OR_OP
, unitsmask
, newexp
);
1922 /* Merge each function unit into the unit mask attributes. */
1923 for (unit
= units
; unit
; unit
= unit
->next
)
1925 XEXP (newexp
, 0) = unit
->condexp
;
1926 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1927 unitsmask
= operate_exp (ORX_OP
, unitsmask
, attr_copy_rtx (newexp
));
1931 /* Simplify the unit mask expression, encode it, and make an attribute
1932 for the function_units_used function. */
1933 unitsmask
= simplify_by_exploding (unitsmask
);
1935 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1936 unitsmask
= encode_units_mask (unitsmask
);
1939 /* We can no longer encode unitsmask at compile time, so emit code to
1940 calculate it at runtime. Rather, put a marker for where we'd do
1941 the code, and actually output it in write_attr_get(). */
1942 unitsmask
= attr_rtx (FFS
, unitsmask
);
1945 make_internal_attr ("*function_units_used", unitsmask
, 10);
1947 /* Create an array of ops for each unit. Add an extra unit for the
1948 result_ready_cost function that has the ops of all other units. */
1949 unit_ops
= (struct function_unit_op
***)
1950 alloca ((num_units
+ 1) * sizeof (struct function_unit_op
**));
1951 unit_num
= (struct function_unit
**)
1952 alloca ((num_units
+ 1) * sizeof (struct function_unit
*));
1954 unit_num
[num_units
] = unit
= (struct function_unit
*)
1955 alloca (sizeof (struct function_unit
));
1956 unit
->num
= num_units
;
1957 unit
->num_opclasses
= 0;
1959 for (unit
= units
; unit
; unit
= unit
->next
)
1961 unit_num
[num_units
]->num_opclasses
+= unit
->num_opclasses
;
1962 unit_num
[unit
->num
] = unit
;
1963 unit_ops
[unit
->num
] = op_array
= (struct function_unit_op
**)
1964 alloca (unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1966 for (op
= unit
->ops
; op
; op
= op
->next
)
1967 op_array
[op
->num
] = op
;
1970 /* Compose the array of ops for the extra unit. */
1971 unit_ops
[num_units
] = op_array
= (struct function_unit_op
**)
1972 alloca (unit_num
[num_units
]->num_opclasses
1973 * sizeof (struct function_unit_op
*));
1975 for (unit
= units
, i
= 0; unit
; i
+= unit
->num_opclasses
, unit
= unit
->next
)
1976 bcopy ((char *) unit_ops
[unit
->num
], (char *) &op_array
[i
],
1977 unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1979 /* Compute the ready cost function for each unit by computing the
1980 condition for each non-default value. */
1981 for (u
= 0; u
<= num_units
; u
++)
1987 op_array
= unit_ops
[unit
->num
];
1988 num
= unit
->num_opclasses
;
1990 /* Sort the array of ops into increasing ready cost order. */
1991 for (i
= 0; i
< num
; i
++)
1992 for (j
= num
- 1; j
> i
; j
--)
1993 if (op_array
[j
-1]->ready
< op_array
[j
]->ready
)
1996 op_array
[j
] = op_array
[j
-1];
2000 /* Determine how many distinct non-default ready cost values there
2001 are. We use a default ready cost value of 1. */
2002 nvalues
= 0; value
= 1;
2003 for (i
= num
- 1; i
>= 0; i
--)
2004 if (op_array
[i
]->ready
> value
)
2006 value
= op_array
[i
]->ready
;
2011 readycost
= make_numeric_value (1);
2014 /* Construct the ready cost expression as a COND of each value from
2015 the largest to the smallest. */
2016 readycost
= rtx_alloc (COND
);
2017 XVEC (readycost
, 0) = rtvec_alloc (nvalues
* 2);
2018 XEXP (readycost
, 1) = make_numeric_value (1);
2020 nvalues
= 0; orexp
= false_rtx
; value
= op_array
[0]->ready
;
2021 for (i
= 0; i
< num
; i
++)
2026 else if (op
->ready
== value
)
2027 orexp
= insert_right_side (IOR
, orexp
, op
->condexp
, -2, -2);
2030 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
2031 XVECEXP (readycost
, 0, nvalues
* 2 + 1)
2032 = make_numeric_value (value
);
2035 orexp
= op
->condexp
;
2038 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
2039 XVECEXP (readycost
, 0, nvalues
* 2 + 1) = make_numeric_value (value
);
2044 rtx max_blockage
= 0, min_blockage
= 0;
2046 /* Simplify the readycost expression by only considering insns
2047 that use the unit. */
2048 readycost
= simplify_knowing (readycost
, unit
->condexp
);
2050 /* Determine the blockage cost the executing insn (E) given
2051 the candidate insn (C). This is the maximum of the issue
2052 delay, the pipeline delay, and the simultaneity constraint.
2053 Each function_unit_op represents the characteristics of the
2054 candidate insn, so in the expressions below, C is a known
2055 term and E is an unknown term.
2057 We compute the blockage cost for each E for every possible C.
2058 Thus OP represents E, and READYCOST is a list of values for
2061 The issue delay function for C is op->issue_exp and is used to
2062 write the `<name>_unit_conflict_cost' function. Symbolicly
2063 this is "ISSUE-DELAY (E,C)".
2065 The pipeline delay results form the FIFO constraint on the
2066 function unit and is "READY-COST (E) + 1 - READY-COST (C)".
2068 The simultaneity constraint is based on how long it takes to
2069 fill the unit given the minimum issue delay. FILL-TIME is the
2070 constant "MIN (ISSUE-DELAY (*,*)) * (SIMULTANEITY - 1)", and
2071 the simultaneity constraint is "READY-COST (E) - FILL-TIME"
2072 if SIMULTANEITY is non-zero and zero otherwise.
2074 Thus, BLOCKAGE (E,C) when SIMULTANEITY is zero is
2076 MAX (ISSUE-DELAY (E,C),
2077 READY-COST (E) - (READY-COST (C) - 1))
2081 MAX (ISSUE-DELAY (E,C),
2082 READY-COST (E) - (READY-COST (C) - 1),
2083 READY-COST (E) - FILL-TIME)
2085 The `<name>_unit_blockage' function is computed by determining
2086 this value for each candidate insn. As these values are
2087 computed, we also compute the upper and lower bounds for
2088 BLOCKAGE (E,*). These are combined to form the function
2089 `<name>_unit_blockage_range'. Finally, the maximum blockage
2090 cost, MAX (BLOCKAGE (*,*)), is computed. */
2092 for (op
= unit
->ops
; op
; op
= op
->next
)
2094 rtx blockage
= op
->issue_exp
;
2095 blockage
= simplify_knowing (blockage
, unit
->condexp
);
2097 /* Add this op's contribution to MAX (BLOCKAGE (E,*)) and
2098 MIN (BLOCKAGE (E,*)). */
2099 if (max_blockage
== 0)
2100 max_blockage
= min_blockage
= blockage
;
2104 = simplify_knowing (operate_exp (MAX_OP
, max_blockage
,
2108 = simplify_knowing (operate_exp (MIN_OP
, min_blockage
,
2113 /* Make an attribute for use in the blockage function. */
2114 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_block_") + MAX_DIGITS
,
2115 "*%s_block_%d", unit
->name
, op
->num
);
2116 make_internal_attr (str
, blockage
, 1);
2119 /* Record MAX (BLOCKAGE (*,*)). */
2122 unit
->max_blockage
= max_attr_value (max_blockage
, &unknown
);
2125 /* See if the upper and lower bounds of BLOCKAGE (E,*) are the
2126 same. If so, the blockage function carries no additional
2127 information and is not written. */
2128 newexp
= operate_exp (EQ_OP
, max_blockage
, min_blockage
);
2129 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2130 unit
->needs_blockage_function
2131 = (GET_CODE (newexp
) != CONST_STRING
2132 || atoi (XSTR (newexp
, 0)) != 1);
2134 /* If the all values of BLOCKAGE (E,C) have the same value,
2135 neither blockage function is written. */
2136 unit
->needs_range_function
2137 = (unit
->needs_blockage_function
2138 || GET_CODE (max_blockage
) != CONST_STRING
);
2140 if (unit
->needs_range_function
)
2142 /* Compute the blockage range function and make an attribute
2143 for writing its value. */
2144 newexp
= operate_exp (RANGE_OP
, min_blockage
, max_blockage
);
2145 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2147 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_unit_blockage_range"),
2148 "*%s_unit_blockage_range", unit
->name
);
2149 make_internal_attr (str
, newexp
, 20);
2152 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_unit_ready_cost"),
2153 "*%s_unit_ready_cost", unit
->name
);
2156 str
= "*result_ready_cost";
2158 /* Make an attribute for the ready_cost function. Simplifying
2159 further with simplify_by_exploding doesn't win. */
2160 make_internal_attr (str
, readycost
, 0);
2163 /* For each unit that requires a conflict cost function, make an attribute
2164 that maps insns to the operation number. */
2165 for (unit
= units
; unit
; unit
= unit
->next
)
2169 if (! unit
->needs_conflict_function
2170 && ! unit
->needs_blockage_function
)
2173 caseexp
= rtx_alloc (COND
);
2174 XVEC (caseexp
, 0) = rtvec_alloc ((unit
->num_opclasses
- 1) * 2);
2176 for (op
= unit
->ops
; op
; op
= op
->next
)
2178 /* Make our adjustment to the COND being computed. If we are the
2179 last operation class, place our values into the default of the
2181 if (op
->num
== unit
->num_opclasses
- 1)
2183 XEXP (caseexp
, 1) = make_numeric_value (op
->num
);
2187 XVECEXP (caseexp
, 0, op
->num
* 2) = op
->condexp
;
2188 XVECEXP (caseexp
, 0, op
->num
* 2 + 1)
2189 = make_numeric_value (op
->num
);
2193 /* Simplifying caseexp with simplify_by_exploding doesn't win. */
2194 str
= attr_printf (strlen (unit
->name
) + sizeof ("*_cases"),
2195 "*%s_cases", unit
->name
);
2196 make_internal_attr (str
, caseexp
, 1);
2200 /* Simplify EXP given KNOWN_TRUE. */
2203 simplify_knowing (exp
, known_true
)
2204 rtx exp
, known_true
;
2206 if (GET_CODE (exp
) != CONST_STRING
)
2208 int unknown
= 0, max
;
2209 max
= max_attr_value (exp
, &unknown
);
2212 exp
= attr_rtx (IF_THEN_ELSE
, known_true
, exp
,
2213 make_numeric_value (max
));
2214 exp
= simplify_by_exploding (exp
);
2220 /* Translate the CONST_STRING expressions in X to change the encoding of
2221 value. On input, the value is a bitmask with a one bit for each unit
2222 used; on output, the value is the unit number (zero based) if one
2223 and only one unit is used or the one's compliment of the bitmask. */
2226 encode_units_mask (x
)
2231 register enum rtx_code code
;
2232 register const char *fmt
;
2234 code
= GET_CODE (x
);
2239 i
= atoi (XSTR (x
, 0));
2241 abort (); /* The sign bit encodes a one's compliment mask. */
2242 else if (i
!= 0 && i
== (i
& -i
))
2243 /* Only one bit is set, so yield that unit number. */
2244 for (j
= 0; (i
>>= 1) != 0; j
++)
2248 return attr_rtx (CONST_STRING
, attr_printf (MAX_DIGITS
, "%d", j
));
2265 /* Compare the elements. If any pair of corresponding elements
2266 fail to match, return 0 for the whole things. */
2268 fmt
= GET_RTX_FORMAT (code
);
2269 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2275 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2276 XVECEXP (x
, i
, j
) = encode_units_mask (XVECEXP (x
, i
, j
));
2280 XEXP (x
, i
) = encode_units_mask (XEXP (x
, i
));
2287 /* Once all attributes and insns have been read and checked, we construct for
2288 each attribute value a list of all the insns that have that value for
2293 struct attr_desc
*attr
;
2295 struct attr_value
*av
;
2296 struct insn_ent
*ie
;
2297 struct insn_def
*id
;
2301 /* Don't fill constant attributes. The value is independent of
2302 any particular insn. */
2306 for (id
= defs
; id
; id
= id
->next
)
2308 /* If no value is specified for this insn for this attribute, use the
2311 if (XVEC (id
->def
, id
->vec_idx
))
2312 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
2313 if (! strcmp (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
2315 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
2318 av
= attr
->default_val
;
2320 av
= get_attr_value (value
, attr
, id
->insn_code
);
2322 ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2323 ie
->insn_code
= id
->insn_code
;
2324 ie
->insn_index
= id
->insn_code
;
2325 insert_insn_ent (av
, ie
);
2329 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
2330 test that checks relative positions of insns (uses MATCH_DUP or PC).
2331 If so, replace it with what is obtained by passing the expression to
2332 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
2333 recursively on each value (including the default value). Otherwise,
2334 return the value returned by NO_ADDRESS_FN applied to EXP. */
2337 substitute_address (exp
, no_address_fn
, address_fn
)
2339 rtx (*no_address_fn
) PARAMS ((rtx
));
2340 rtx (*address_fn
) PARAMS ((rtx
));
2345 if (GET_CODE (exp
) == COND
)
2347 /* See if any tests use addresses. */
2349 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2350 walk_attr_value (XVECEXP (exp
, 0, i
));
2353 return (*address_fn
) (exp
);
2355 /* Make a new copy of this COND, replacing each element. */
2356 newexp
= rtx_alloc (COND
);
2357 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
2358 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2360 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
2361 XVECEXP (newexp
, 0, i
+ 1)
2362 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
2363 no_address_fn
, address_fn
);
2366 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
2367 no_address_fn
, address_fn
);
2372 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
2375 walk_attr_value (XEXP (exp
, 0));
2377 return (*address_fn
) (exp
);
2379 return attr_rtx (IF_THEN_ELSE
,
2380 substitute_address (XEXP (exp
, 0),
2381 no_address_fn
, address_fn
),
2382 substitute_address (XEXP (exp
, 1),
2383 no_address_fn
, address_fn
),
2384 substitute_address (XEXP (exp
, 2),
2385 no_address_fn
, address_fn
));
2388 return (*no_address_fn
) (exp
);
2391 /* Make new attributes from the `length' attribute. The following are made,
2392 each corresponding to a function called from `shorten_branches' or
2395 *insn_default_length This is the length of the insn to be returned
2396 by `get_attr_length' before `shorten_branches'
2397 has been called. In each case where the length
2398 depends on relative addresses, the largest
2399 possible is used. This routine is also used
2400 to compute the initial size of the insn.
2402 *insn_variable_length_p This returns 1 if the insn's length depends
2403 on relative addresses, zero otherwise.
2405 *insn_current_length This is only called when it is known that the
2406 insn has a variable length and returns the
2407 current length, based on relative addresses.
2411 make_length_attrs ()
2413 static const char *new_names
[] = {"*insn_default_length",
2414 "*insn_variable_length_p",
2415 "*insn_current_length"};
2416 static rtx (*no_address_fn
[]) PARAMS ((rtx
)) = {identity_fn
, zero_fn
, zero_fn
};
2417 static rtx (*address_fn
[]) PARAMS ((rtx
)) = {max_fn
, one_fn
, identity_fn
};
2419 struct attr_desc
*length_attr
, *new_attr
;
2420 struct attr_value
*av
, *new_av
;
2421 struct insn_ent
*ie
, *new_ie
;
2423 /* See if length attribute is defined. If so, it must be numeric. Make
2424 it special so we don't output anything for it. */
2425 length_attr
= find_attr ("length", 0);
2426 if (length_attr
== 0)
2429 if (! length_attr
->is_numeric
)
2430 fatal ("length attribute must be numeric.");
2432 length_attr
->is_const
= 0;
2433 length_attr
->is_special
= 1;
2435 /* Make each new attribute, in turn. */
2436 for (i
= 0; i
< sizeof new_names
/ sizeof new_names
[0]; i
++)
2438 make_internal_attr (new_names
[i
],
2439 substitute_address (length_attr
->default_val
->value
,
2440 no_address_fn
[i
], address_fn
[i
]),
2442 new_attr
= find_attr (new_names
[i
], 0);
2443 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2444 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2446 new_av
= get_attr_value (substitute_address (av
->value
,
2449 new_attr
, ie
->insn_code
);
2450 new_ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2451 new_ie
->insn_code
= ie
->insn_code
;
2452 new_ie
->insn_index
= ie
->insn_index
;
2453 insert_insn_ent (new_av
, new_ie
);
2458 /* Utility functions called from above routine. */
2469 rtx exp ATTRIBUTE_UNUSED
;
2471 return make_numeric_value (0);
2476 rtx exp ATTRIBUTE_UNUSED
;
2478 return make_numeric_value (1);
2486 return make_numeric_value (max_attr_value (exp
, &unknown
));
2490 write_length_unit_log ()
2492 struct attr_desc
*length_attr
= find_attr ("length", 0);
2493 struct attr_value
*av
;
2494 struct insn_ent
*ie
;
2495 unsigned int length_unit_log
, length_or
;
2498 if (length_attr
== 0)
2500 length_or
= or_attr_value (length_attr
->default_val
->value
, &unknown
);
2501 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2502 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2503 length_or
|= or_attr_value (av
->value
, &unknown
);
2506 length_unit_log
= 0;
2509 length_or
= ~length_or
;
2510 for (length_unit_log
= 0; length_or
& 1; length_or
>>= 1)
2513 printf ("int length_unit_log = %u;\n", length_unit_log
);
2516 /* Take a COND expression and see if any of the conditions in it can be
2517 simplified. If any are known true or known false for the particular insn
2518 code, the COND can be further simplified.
2520 Also call ourselves on any COND operations that are values of this COND.
2522 We do not modify EXP; rather, we make and return a new rtx. */
2525 simplify_cond (exp
, insn_code
, insn_index
)
2527 int insn_code
, insn_index
;
2530 /* We store the desired contents here,
2531 then build a new expression if they don't match EXP. */
2532 rtx defval
= XEXP (exp
, 1);
2533 rtx new_defval
= XEXP (exp
, 1);
2534 int len
= XVECLEN (exp
, 0);
2535 rtx
*tests
= (rtx
*) alloca (len
* sizeof (rtx
));
2539 /* This lets us free all storage allocated below, if appropriate. */
2540 first_spacer
= (char *) obstack_finish (rtl_obstack
);
2542 bcopy ((char *) XVEC (exp
, 0)->elem
, (char *) tests
, len
* sizeof (rtx
));
2544 /* See if default value needs simplification. */
2545 if (GET_CODE (defval
) == COND
)
2546 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
2548 /* Simplify the subexpressions, and see what tests we can get rid of. */
2550 for (i
= 0; i
< len
; i
+= 2)
2552 rtx newtest
, newval
;
2554 /* Simplify this test. */
2555 newtest
= SIMPLIFY_TEST_EXP (tests
[i
], insn_code
, insn_index
);
2558 newval
= tests
[i
+ 1];
2559 /* See if this value may need simplification. */
2560 if (GET_CODE (newval
) == COND
)
2561 newval
= simplify_cond (newval
, insn_code
, insn_index
);
2563 /* Look for ways to delete or combine this test. */
2564 if (newtest
== true_rtx
)
2566 /* If test is true, make this value the default
2567 and discard this + any following tests. */
2569 defval
= tests
[i
+ 1];
2570 new_defval
= newval
;
2573 else if (newtest
== false_rtx
)
2575 /* If test is false, discard it and its value. */
2576 for (j
= i
; j
< len
- 2; j
++)
2577 tests
[j
] = tests
[j
+ 2];
2581 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
2583 /* If this value and the value for the prev test are the same,
2587 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
2588 insn_code
, insn_index
);
2590 /* Delete this test/value. */
2591 for (j
= i
; j
< len
- 2; j
++)
2592 tests
[j
] = tests
[j
+ 2];
2597 tests
[i
+ 1] = newval
;
2600 /* If the last test in a COND has the same value
2601 as the default value, that test isn't needed. */
2603 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
2606 /* See if we changed anything. */
2607 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
2610 for (i
= 0; i
< len
; i
++)
2611 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
2620 obstack_free (rtl_obstack
, first_spacer
);
2621 if (GET_CODE (defval
) == COND
)
2622 return simplify_cond (defval
, insn_code
, insn_index
);
2628 obstack_free (rtl_obstack
, first_spacer
);
2633 rtx newexp
= rtx_alloc (COND
);
2635 XVEC (newexp
, 0) = rtvec_alloc (len
);
2636 bcopy ((char *) tests
, (char *) XVEC (newexp
, 0)->elem
,
2637 len
* sizeof (rtx
));
2638 XEXP (newexp
, 1) = new_defval
;
2643 /* Remove an insn entry from an attribute value. */
2646 remove_insn_ent (av
, ie
)
2647 struct attr_value
*av
;
2648 struct insn_ent
*ie
;
2650 struct insn_ent
*previe
;
2652 if (av
->first_insn
== ie
)
2653 av
->first_insn
= ie
->next
;
2656 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
2658 previe
->next
= ie
->next
;
2662 if (ie
->insn_code
== -1)
2663 av
->has_asm_insn
= 0;
2668 /* Insert an insn entry in an attribute value list. */
2671 insert_insn_ent (av
, ie
)
2672 struct attr_value
*av
;
2673 struct insn_ent
*ie
;
2675 ie
->next
= av
->first_insn
;
2676 av
->first_insn
= ie
;
2678 if (ie
->insn_code
== -1)
2679 av
->has_asm_insn
= 1;
2684 /* This is a utility routine to take an expression that is a tree of either
2685 AND or IOR expressions and insert a new term. The new term will be
2686 inserted at the right side of the first node whose code does not match
2687 the root. A new node will be created with the root's code. Its left
2688 side will be the old right side and its right side will be the new
2691 If the `term' is itself a tree, all its leaves will be inserted. */
2694 insert_right_side (code
, exp
, term
, insn_code
, insn_index
)
2698 int insn_code
, insn_index
;
2702 /* Avoid consing in some special cases. */
2703 if (code
== AND
&& term
== true_rtx
)
2705 if (code
== AND
&& term
== false_rtx
)
2707 if (code
== AND
&& exp
== true_rtx
)
2709 if (code
== AND
&& exp
== false_rtx
)
2711 if (code
== IOR
&& term
== true_rtx
)
2713 if (code
== IOR
&& term
== false_rtx
)
2715 if (code
== IOR
&& exp
== true_rtx
)
2717 if (code
== IOR
&& exp
== false_rtx
)
2719 if (attr_equal_p (exp
, term
))
2722 if (GET_CODE (term
) == code
)
2724 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
2725 insn_code
, insn_index
);
2726 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
2727 insn_code
, insn_index
);
2732 if (GET_CODE (exp
) == code
)
2734 rtx
new = insert_right_side (code
, XEXP (exp
, 1),
2735 term
, insn_code
, insn_index
);
2736 if (new != XEXP (exp
, 1))
2737 /* Make a copy of this expression and call recursively. */
2738 newexp
= attr_rtx (code
, XEXP (exp
, 0), new);
2744 /* Insert the new term. */
2745 newexp
= attr_rtx (code
, exp
, term
);
2748 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2751 /* If we have an expression which AND's a bunch of
2752 (not (eq_attrq "alternative" "n"))
2753 terms, we may have covered all or all but one of the possible alternatives.
2754 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
2756 This routine is passed an expression and either AND or IOR. It returns a
2757 bitmask indicating which alternatives are mentioned within EXP. */
2760 compute_alternative_mask (exp
, code
)
2765 if (GET_CODE (exp
) == code
)
2766 return compute_alternative_mask (XEXP (exp
, 0), code
)
2767 | compute_alternative_mask (XEXP (exp
, 1), code
);
2769 else if (code
== AND
&& GET_CODE (exp
) == NOT
2770 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2771 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
2772 string
= XSTR (XEXP (exp
, 0), 1);
2774 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
2775 && XSTR (exp
, 0) == alternative_name
)
2776 string
= XSTR (exp
, 1);
2782 return 1 << (string
[0] - '0');
2783 return 1 << atoi (string
);
2786 /* Given I, a single-bit mask, return RTX to compare the `alternative'
2787 attribute with the value represented by that bit. */
2790 make_alternative_compare (mask
)
2797 for (i
= 0; (mask
& (1 << i
)) == 0; i
++)
2800 newexp
= attr_rtx (EQ_ATTR
, alternative_name
, attr_numeral (i
));
2801 RTX_UNCHANGING_P (newexp
) = 1;
2806 /* If we are processing an (eq_attr "attr" "value") test, we find the value
2807 of "attr" for this insn code. From that value, we can compute a test
2808 showing when the EQ_ATTR will be true. This routine performs that
2809 computation. If a test condition involves an address, we leave the EQ_ATTR
2810 intact because addresses are only valid for the `length' attribute.
2812 EXP is the EQ_ATTR expression and VALUE is the value of that attribute
2813 for the insn corresponding to INSN_CODE and INSN_INDEX. */
2816 evaluate_eq_attr (exp
, value
, insn_code
, insn_index
)
2819 int insn_code
, insn_index
;
2826 if (GET_CODE (value
) == CONST_STRING
)
2828 if (! strcmp (XSTR (value
, 0), XSTR (exp
, 1)))
2833 else if (GET_CODE (value
) == SYMBOL_REF
)
2837 if (GET_CODE (exp
) != EQ_ATTR
)
2840 string
= (char *) alloca (2 + strlen (XSTR (exp
, 0))
2841 + strlen (XSTR (exp
, 1)));
2842 strcpy (string
, XSTR (exp
, 0));
2843 strcat (string
, "_");
2844 strcat (string
, XSTR (exp
, 1));
2845 for (p
= string
; *p
; p
++)
2848 newexp
= attr_rtx (EQ
, value
,
2849 attr_rtx (SYMBOL_REF
,
2850 attr_string(string
, strlen(string
))));
2852 else if (GET_CODE (value
) == COND
)
2854 /* We construct an IOR of all the cases for which the requested attribute
2855 value is present. Since we start with FALSE, if it is not present,
2856 FALSE will be returned.
2858 Each case is the AND of the NOT's of the previous conditions with the
2859 current condition; in the default case the current condition is TRUE.
2861 For each possible COND value, call ourselves recursively.
2863 The extra TRUE and FALSE expressions will be eliminated by another
2864 call to the simplification routine. */
2869 if (current_alternative_string
)
2870 clear_struct_flag (value
);
2872 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2874 rtx
this = SIMPLIFY_TEST_EXP (XVECEXP (value
, 0, i
),
2875 insn_code
, insn_index
);
2877 SIMPLIFY_ALTERNATIVE (this);
2879 right
= insert_right_side (AND
, andexp
, this,
2880 insn_code
, insn_index
);
2881 right
= insert_right_side (AND
, right
,
2882 evaluate_eq_attr (exp
,
2885 insn_code
, insn_index
),
2886 insn_code
, insn_index
);
2887 orexp
= insert_right_side (IOR
, orexp
, right
,
2888 insn_code
, insn_index
);
2890 /* Add this condition into the AND expression. */
2891 newexp
= attr_rtx (NOT
, this);
2892 andexp
= insert_right_side (AND
, andexp
, newexp
,
2893 insn_code
, insn_index
);
2896 /* Handle the default case. */
2897 right
= insert_right_side (AND
, andexp
,
2898 evaluate_eq_attr (exp
, XEXP (value
, 1),
2899 insn_code
, insn_index
),
2900 insn_code
, insn_index
);
2901 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2906 /* If uses an address, must return original expression. But set the
2907 RTX_UNCHANGING_P bit so we don't try to simplify it again. */
2910 walk_attr_value (newexp
);
2914 /* This had `&& current_alternative_string', which seems to be wrong. */
2915 if (! RTX_UNCHANGING_P (exp
))
2916 return copy_rtx_unchanging (exp
);
2923 /* This routine is called when an AND of a term with a tree of AND's is
2924 encountered. If the term or its complement is present in the tree, it
2925 can be replaced with TRUE or FALSE, respectively.
2927 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2928 be true and hence are complementary.
2930 There is one special case: If we see
2931 (and (not (eq_attr "att" "v1"))
2932 (eq_attr "att" "v2"))
2933 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2934 replace the term, not anything in the AND tree. So we pass a pointer to
2938 simplify_and_tree (exp
, pterm
, insn_code
, insn_index
)
2941 int insn_code
, insn_index
;
2946 int left_eliminates_term
, right_eliminates_term
;
2948 if (GET_CODE (exp
) == AND
)
2950 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2951 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2952 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2954 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2956 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2960 else if (GET_CODE (exp
) == IOR
)
2962 /* For the IOR case, we do the same as above, except that we can
2963 only eliminate `term' if both sides of the IOR would do so. */
2965 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2966 left_eliminates_term
= (temp
== true_rtx
);
2969 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2970 right_eliminates_term
= (temp
== true_rtx
);
2972 if (left_eliminates_term
&& right_eliminates_term
)
2975 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2977 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2979 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
2983 /* Check for simplifications. Do some extra checking here since this
2984 routine is called so many times. */
2989 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
2992 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
2995 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
2997 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
3000 if (! strcmp (XSTR (exp
, 1), XSTR (*pterm
, 1)))
3006 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
3007 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3009 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
3012 if (! strcmp (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
3018 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
3019 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
3021 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
3024 if (! strcmp (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
3030 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
3032 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
3036 else if (GET_CODE (exp
) == NOT
)
3038 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
3042 else if (GET_CODE (*pterm
) == NOT
)
3044 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
3048 else if (attr_equal_p (exp
, *pterm
))
3054 /* Similar to `simplify_and_tree', but for IOR trees. */
3057 simplify_or_tree (exp
, pterm
, insn_code
, insn_index
)
3060 int insn_code
, insn_index
;
3065 int left_eliminates_term
, right_eliminates_term
;
3067 if (GET_CODE (exp
) == IOR
)
3069 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
3070 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
3071 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3073 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3075 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3079 else if (GET_CODE (exp
) == AND
)
3081 /* For the AND case, we do the same as above, except that we can
3082 only eliminate `term' if both sides of the AND would do so. */
3084 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
3085 left_eliminates_term
= (temp
== false_rtx
);
3088 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
3089 right_eliminates_term
= (temp
== false_rtx
);
3091 if (left_eliminates_term
&& right_eliminates_term
)
3094 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3096 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3098 exp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3102 if (attr_equal_p (exp
, *pterm
))
3105 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
3108 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
3111 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
3112 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3113 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
3116 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
3117 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
3118 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
3124 /* Given an expression, see if it can be simplified for a particular insn
3125 code based on the values of other attributes being tested. This can
3126 eliminate nested get_attr_... calls.
3128 Note that if an endless recursion is specified in the patterns, the
3129 optimization will loop. However, it will do so in precisely the cases where
3130 an infinite recursion loop could occur during compilation. It's better that
3134 simplify_test_exp (exp
, insn_code
, insn_index
)
3136 int insn_code
, insn_index
;
3139 struct attr_desc
*attr
;
3140 struct attr_value
*av
;
3141 struct insn_ent
*ie
;
3144 char *spacer
= (char *) obstack_finish (rtl_obstack
);
3146 /* Don't re-simplify something we already simplified. */
3147 if (RTX_UNCHANGING_P (exp
) || MEM_IN_STRUCT_P (exp
))
3150 switch (GET_CODE (exp
))
3153 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3154 SIMPLIFY_ALTERNATIVE (left
);
3155 if (left
== false_rtx
)
3158 obstack_free (rtl_obstack
, spacer
);
3161 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3162 SIMPLIFY_ALTERNATIVE (right
);
3163 if (left
== false_rtx
)
3166 obstack_free (rtl_obstack
, spacer
);
3170 /* If either side is an IOR and we have (eq_attr "alternative" ..")
3171 present on both sides, apply the distributive law since this will
3172 yield simplifications. */
3173 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
3174 && compute_alternative_mask (left
, IOR
)
3175 && compute_alternative_mask (right
, IOR
))
3177 if (GET_CODE (left
) == IOR
)
3184 newexp
= attr_rtx (IOR
,
3185 attr_rtx (AND
, left
, XEXP (right
, 0)),
3186 attr_rtx (AND
, left
, XEXP (right
, 1)));
3188 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3191 /* Try with the term on both sides. */
3192 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
3193 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3194 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
3196 if (left
== false_rtx
|| right
== false_rtx
)
3199 obstack_free (rtl_obstack
, spacer
);
3202 else if (left
== true_rtx
)
3206 else if (right
== true_rtx
)
3210 /* See if all or all but one of the insn's alternatives are specified
3211 in this tree. Optimize if so. */
3213 else if (insn_code
>= 0
3214 && (GET_CODE (left
) == AND
3215 || (GET_CODE (left
) == NOT
3216 && GET_CODE (XEXP (left
, 0)) == EQ_ATTR
3217 && XSTR (XEXP (left
, 0), 0) == alternative_name
)
3218 || GET_CODE (right
) == AND
3219 || (GET_CODE (right
) == NOT
3220 && GET_CODE (XEXP (right
, 0)) == EQ_ATTR
3221 && XSTR (XEXP (right
, 0), 0) == alternative_name
)))
3223 i
= compute_alternative_mask (exp
, AND
);
3224 if (i
& ~insn_alternatives
[insn_code
])
3225 fatal ("Invalid alternative specified for pattern number %d",
3228 /* If all alternatives are excluded, this is false. */
3229 i
^= insn_alternatives
[insn_code
];
3232 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3234 /* If just one excluded, AND a comparison with that one to the
3235 front of the tree. The others will be eliminated by
3236 optimization. We do not want to do this if the insn has one
3237 alternative and we have tested none of them! */
3238 left
= make_alternative_compare (i
);
3239 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3240 newexp
= attr_rtx (AND
, left
, right
);
3242 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3246 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3248 newexp
= attr_rtx (AND
, left
, right
);
3249 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3254 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3255 SIMPLIFY_ALTERNATIVE (left
);
3256 if (left
== true_rtx
)
3259 obstack_free (rtl_obstack
, spacer
);
3262 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3263 SIMPLIFY_ALTERNATIVE (right
);
3264 if (right
== true_rtx
)
3267 obstack_free (rtl_obstack
, spacer
);
3271 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
3272 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3273 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
3275 if (right
== true_rtx
|| left
== true_rtx
)
3278 obstack_free (rtl_obstack
, spacer
);
3281 else if (left
== false_rtx
)
3285 else if (right
== false_rtx
)
3290 /* Test for simple cases where the distributive law is useful. I.e.,
3291 convert (ior (and (x) (y))
3297 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
3298 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
3300 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
3302 left
= XEXP (left
, 0);
3304 newexp
= attr_rtx (AND
, left
, right
);
3305 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3308 /* See if all or all but one of the insn's alternatives are specified
3309 in this tree. Optimize if so. */
3311 else if (insn_code
>= 0
3312 && (GET_CODE (left
) == IOR
3313 || (GET_CODE (left
) == EQ_ATTR
3314 && XSTR (left
, 0) == alternative_name
)
3315 || GET_CODE (right
) == IOR
3316 || (GET_CODE (right
) == EQ_ATTR
3317 && XSTR (right
, 0) == alternative_name
)))
3319 i
= compute_alternative_mask (exp
, IOR
);
3320 if (i
& ~insn_alternatives
[insn_code
])
3321 fatal ("Invalid alternative specified for pattern number %d",
3324 /* If all alternatives are included, this is true. */
3325 i
^= insn_alternatives
[insn_code
];
3328 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3330 /* If just one excluded, IOR a comparison with that one to the
3331 front of the tree. The others will be eliminated by
3332 optimization. We do not want to do this if the insn has one
3333 alternative and we have tested none of them! */
3334 left
= make_alternative_compare (i
);
3335 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3336 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
3338 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3342 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3344 newexp
= attr_rtx (IOR
, left
, right
);
3345 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3350 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
3352 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
3353 insn_code
, insn_index
);
3354 SIMPLIFY_ALTERNATIVE (left
);
3358 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3359 SIMPLIFY_ALTERNATIVE (left
);
3360 if (GET_CODE (left
) == NOT
)
3361 return XEXP (left
, 0);
3363 if (left
== false_rtx
)
3366 obstack_free (rtl_obstack
, spacer
);
3369 else if (left
== true_rtx
)
3372 obstack_free (rtl_obstack
, spacer
);
3376 /* Try to apply De`Morgan's laws. */
3377 else if (GET_CODE (left
) == IOR
)
3379 newexp
= attr_rtx (AND
,
3380 attr_rtx (NOT
, XEXP (left
, 0)),
3381 attr_rtx (NOT
, XEXP (left
, 1)));
3383 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3385 else if (GET_CODE (left
) == AND
)
3387 newexp
= attr_rtx (IOR
,
3388 attr_rtx (NOT
, XEXP (left
, 0)),
3389 attr_rtx (NOT
, XEXP (left
, 1)));
3391 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3393 else if (left
!= XEXP (exp
, 0))
3395 newexp
= attr_rtx (NOT
, left
);
3400 if (current_alternative_string
&& XSTR (exp
, 0) == alternative_name
)
3401 return (XSTR (exp
, 1) == current_alternative_string
3402 ? true_rtx
: false_rtx
);
3404 /* Look at the value for this insn code in the specified attribute.
3405 We normally can replace this comparison with the condition that
3406 would give this insn the values being tested for. */
3407 if (XSTR (exp
, 0) != alternative_name
3408 && (attr
= find_attr (XSTR (exp
, 0), 0)) != NULL
)
3409 for (av
= attr
->first_value
; av
; av
= av
->next
)
3410 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3411 if (ie
->insn_code
== insn_code
)
3412 return evaluate_eq_attr (exp
, av
->value
, insn_code
, insn_index
);
3419 /* We have already simplified this expression. Simplifying it again
3420 won't buy anything unless we weren't given a valid insn code
3421 to process (i.e., we are canonicalizing something.). */
3422 if (insn_code
!= -2 /* Seems wrong: && current_alternative_string. */
3423 && ! RTX_UNCHANGING_P (newexp
))
3424 return copy_rtx_unchanging (newexp
);
3429 /* Optimize the attribute lists by seeing if we can determine conditional
3430 values from the known values of other attributes. This will save subroutine
3431 calls during the compilation. */
3436 struct attr_desc
*attr
;
3437 struct attr_value
*av
;
3438 struct insn_ent
*ie
;
3440 int something_changed
= 1;
3442 struct attr_value_list
{ struct attr_value
*av
;
3443 struct insn_ent
*ie
;
3444 struct attr_desc
* attr
;
3445 struct attr_value_list
*next
; };
3446 struct attr_value_list
**insn_code_values
;
3447 struct attr_value_list
*ivbuf
;
3448 struct attr_value_list
*iv
;
3450 /* For each insn code, make a list of all the insn_ent's for it,
3451 for all values for all attributes. */
3453 if (num_insn_ents
== 0)
3456 /* Make 2 extra elements, for "code" values -2 and -1. */
3458 = (struct attr_value_list
**) alloca ((insn_code_number
+ 2)
3459 * sizeof (struct attr_value_list
*));
3460 bzero ((char *) insn_code_values
,
3461 (insn_code_number
+ 2) * sizeof (struct attr_value_list
*));
3463 /* Offset the table address so we can index by -2 or -1. */
3464 insn_code_values
+= 2;
3466 /* Allocate the attr_value_list structures using xmalloc rather than
3467 alloca, because using alloca can overflow the maximum permitted
3468 stack limit on SPARC Lynx. */
3469 iv
= ivbuf
= ((struct attr_value_list
*)
3470 xmalloc (num_insn_ents
* sizeof (struct attr_value_list
)));
3472 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
3473 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
3474 for (av
= attr
->first_value
; av
; av
= av
->next
)
3475 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3480 iv
->next
= insn_code_values
[ie
->insn_code
];
3481 insn_code_values
[ie
->insn_code
] = iv
;
3485 /* Sanity check on num_insn_ents. */
3486 if (iv
!= ivbuf
+ num_insn_ents
)
3489 /* Process one insn code at a time. */
3490 for (i
= -2; i
< insn_code_number
; i
++)
3492 /* Clear the MEM_IN_STRUCT_P flag everywhere relevant.
3493 We use it to mean "already simplified for this insn". */
3494 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3495 clear_struct_flag (iv
->av
->value
);
3497 /* Loop until nothing changes for one iteration. */
3498 something_changed
= 1;
3499 while (something_changed
)
3501 something_changed
= 0;
3502 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3504 struct obstack
*old
= rtl_obstack
;
3505 char *spacer
= (char *) obstack_finish (temp_obstack
);
3510 if (GET_CODE (av
->value
) != COND
)
3513 rtl_obstack
= temp_obstack
;
3514 #if 0 /* This was intended as a speed up, but it was slower. */
3515 if (insn_n_alternatives
[ie
->insn_code
] > 6
3516 && count_sub_rtxs (av
->value
, 200) >= 200)
3517 newexp
= simplify_by_alternatives (av
->value
, ie
->insn_code
,
3521 newexp
= simplify_cond (av
->value
, ie
->insn_code
,
3525 if (newexp
!= av
->value
)
3527 newexp
= attr_copy_rtx (newexp
);
3528 remove_insn_ent (av
, ie
);
3529 av
= get_attr_value (newexp
, attr
, ie
->insn_code
);
3531 insert_insn_ent (av
, ie
);
3532 something_changed
= 1;
3535 obstack_free (temp_obstack
, spacer
);
3545 simplify_by_alternatives (exp
, insn_code
, insn_index
)
3547 int insn_code
, insn_index
;
3550 int len
= insn_n_alternatives
[insn_code
];
3551 rtx newexp
= rtx_alloc (COND
);
3555 XVEC (newexp
, 0) = rtvec_alloc (len
* 2);
3557 /* It will not matter what value we use as the default value
3558 of the new COND, since that default will never be used.
3559 Choose something of the right type. */
3560 for (ultimate
= exp
; GET_CODE (ultimate
) == COND
;)
3561 ultimate
= XEXP (ultimate
, 1);
3562 XEXP (newexp
, 1) = ultimate
;
3564 for (i
= 0; i
< insn_n_alternatives
[insn_code
]; i
++)
3566 current_alternative_string
= attr_numeral (i
);
3567 XVECEXP (newexp
, 0, i
* 2) = make_alternative_compare (1 << i
);
3568 XVECEXP (newexp
, 0, i
* 2 + 1)
3569 = simplify_cond (exp
, insn_code
, insn_index
);
3572 current_alternative_string
= 0;
3573 return simplify_cond (newexp
, insn_code
, insn_index
);
3577 /* If EXP is a suitable expression, reorganize it by constructing an
3578 equivalent expression that is a COND with the tests being all combinations
3579 of attribute values and the values being simple constants. */
3582 simplify_by_exploding (exp
)
3585 rtx list
= 0, link
, condexp
, defval
= NULL_RTX
;
3586 struct dimension
*space
;
3587 rtx
*condtest
, *condval
;
3588 int i
, j
, total
, ndim
= 0;
3589 int most_tests
, num_marks
, new_marks
;
3591 /* Locate all the EQ_ATTR expressions. */
3592 if (! find_and_mark_used_attributes (exp
, &list
, &ndim
) || ndim
== 0)
3594 unmark_used_attributes (list
, 0, 0);
3598 /* Create an attribute space from the list of used attributes. For each
3599 dimension in the attribute space, record the attribute, list of values
3600 used, and number of values used. Add members to the list of values to
3601 cover the domain of the attribute. This makes the expanded COND form
3602 order independent. */
3604 space
= (struct dimension
*) alloca (ndim
* sizeof (struct dimension
));
3607 for (ndim
= 0; list
; ndim
++)
3609 /* Pull the first attribute value from the list and record that
3610 attribute as another dimension in the attribute space. */
3611 const char *name
= XSTR (XEXP (list
, 0), 0);
3614 if ((space
[ndim
].attr
= find_attr (name
, 0)) == 0
3615 || space
[ndim
].attr
->is_numeric
)
3617 unmark_used_attributes (list
, space
, ndim
);
3621 /* Add all remaining attribute values that refer to this attribute. */
3622 space
[ndim
].num_values
= 0;
3623 space
[ndim
].values
= 0;
3625 for (link
= list
; link
; link
= *prev
)
3626 if (! strcmp (XSTR (XEXP (link
, 0), 0), name
))
3628 space
[ndim
].num_values
++;
3629 *prev
= XEXP (link
, 1);
3630 XEXP (link
, 1) = space
[ndim
].values
;
3631 space
[ndim
].values
= link
;
3634 prev
= &XEXP (link
, 1);
3636 /* Add sufficient members to the list of values to make the list
3637 mutually exclusive and record the total size of the attribute
3639 total
*= add_values_to_cover (&space
[ndim
]);
3642 /* Sort the attribute space so that the attributes go from non-constant
3643 to constant and from most values to least values. */
3644 for (i
= 0; i
< ndim
; i
++)
3645 for (j
= ndim
- 1; j
> i
; j
--)
3646 if ((space
[j
-1].attr
->is_const
&& !space
[j
].attr
->is_const
)
3647 || space
[j
-1].num_values
< space
[j
].num_values
)
3649 struct dimension tmp
;
3651 space
[j
] = space
[j
-1];
3655 /* Establish the initial current value. */
3656 for (i
= 0; i
< ndim
; i
++)
3657 space
[i
].current_value
= space
[i
].values
;
3659 condtest
= (rtx
*) alloca (total
* sizeof (rtx
));
3660 condval
= (rtx
*) alloca (total
* sizeof (rtx
));
3662 /* Expand the tests and values by iterating over all values in the
3666 condtest
[i
] = test_for_current_value (space
, ndim
);
3667 condval
[i
] = simplify_with_current_value (exp
, space
, ndim
);
3668 if (! increment_current_value (space
, ndim
))
3674 /* We are now finished with the original expression. */
3675 unmark_used_attributes (0, space
, ndim
);
3677 /* Find the most used constant value and make that the default. */
3679 for (i
= num_marks
= 0; i
< total
; i
++)
3680 if (GET_CODE (condval
[i
]) == CONST_STRING
3681 && ! MEM_VOLATILE_P (condval
[i
]))
3683 /* Mark the unmarked constant value and count how many are marked. */
3684 MEM_VOLATILE_P (condval
[i
]) = 1;
3685 for (j
= new_marks
= 0; j
< total
; j
++)
3686 if (GET_CODE (condval
[j
]) == CONST_STRING
3687 && MEM_VOLATILE_P (condval
[j
]))
3689 if (new_marks
- num_marks
> most_tests
)
3691 most_tests
= new_marks
- num_marks
;
3692 defval
= condval
[i
];
3694 num_marks
= new_marks
;
3696 /* Clear all the marks. */
3697 for (i
= 0; i
< total
; i
++)
3698 MEM_VOLATILE_P (condval
[i
]) = 0;
3700 /* Give up if nothing is constant. */
3704 /* If all values are the default, use that. */
3705 if (total
== most_tests
)
3708 /* Make a COND with the most common constant value the default. (A more
3709 complex method where tests with the same value were combined didn't
3710 seem to improve things.) */
3711 condexp
= rtx_alloc (COND
);
3712 XVEC (condexp
, 0) = rtvec_alloc ((total
- most_tests
) * 2);
3713 XEXP (condexp
, 1) = defval
;
3714 for (i
= j
= 0; i
< total
; i
++)
3715 if (condval
[i
] != defval
)
3717 XVECEXP (condexp
, 0, 2 * j
) = condtest
[i
];
3718 XVECEXP (condexp
, 0, 2 * j
+ 1) = condval
[i
];
3725 /* Set the MEM_VOLATILE_P flag for all EQ_ATTR expressions in EXP and
3726 verify that EXP can be simplified to a constant term if all the EQ_ATTR
3727 tests have known value. */
3730 find_and_mark_used_attributes (exp
, terms
, nterms
)
3736 switch (GET_CODE (exp
))
3739 if (! MEM_VOLATILE_P (exp
))
3741 rtx link
= rtx_alloc (EXPR_LIST
);
3742 XEXP (link
, 0) = exp
;
3743 XEXP (link
, 1) = *terms
;
3746 MEM_VOLATILE_P (exp
) = 1;
3755 if (! find_and_mark_used_attributes (XEXP (exp
, 2), terms
, nterms
))
3759 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3762 if (! find_and_mark_used_attributes (XEXP (exp
, 0), terms
, nterms
))
3767 for (i
= 0; i
< XVECLEN (exp
, 0); i
++)
3768 if (! find_and_mark_used_attributes (XVECEXP (exp
, 0, i
), terms
, nterms
))
3770 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3779 /* Clear the MEM_VOLATILE_P flag in all EQ_ATTR expressions on LIST and
3780 in the values of the NDIM-dimensional attribute space SPACE. */
3783 unmark_used_attributes (list
, space
, ndim
)
3785 struct dimension
*space
;
3791 for (i
= 0; i
< ndim
; i
++)
3792 unmark_used_attributes (space
[i
].values
, 0, 0);
3794 for (link
= list
; link
; link
= XEXP (link
, 1))
3796 exp
= XEXP (link
, 0);
3797 if (GET_CODE (exp
) == EQ_ATTR
)
3798 MEM_VOLATILE_P (exp
) = 0;
3802 /* Update the attribute dimension DIM so that all values of the attribute
3803 are tested. Return the updated number of values. */
3806 add_values_to_cover (dim
)
3807 struct dimension
*dim
;
3809 struct attr_value
*av
;
3810 rtx exp
, link
, *prev
;
3813 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3814 if (GET_CODE (av
->value
) == CONST_STRING
)
3817 if (nalt
< dim
->num_values
)
3819 else if (nalt
== dim
->num_values
)
3821 else if (nalt
* 2 < dim
->num_values
* 3)
3823 /* Most all the values of the attribute are used, so add all the unused
3825 prev
= &dim
->values
;
3826 for (link
= dim
->values
; link
; link
= *prev
)
3827 prev
= &XEXP (link
, 1);
3829 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3830 if (GET_CODE (av
->value
) == CONST_STRING
)
3832 exp
= attr_eq (dim
->attr
->name
, XSTR (av
->value
, 0));
3833 if (MEM_VOLATILE_P (exp
))
3836 link
= rtx_alloc (EXPR_LIST
);
3837 XEXP (link
, 0) = exp
;
3840 prev
= &XEXP (link
, 1);
3842 dim
->num_values
= nalt
;
3846 rtx orexp
= false_rtx
;
3848 /* Very few values are used, so compute a mutually exclusive
3849 expression. (We could do this for numeric values if that becomes
3851 prev
= &dim
->values
;
3852 for (link
= dim
->values
; link
; link
= *prev
)
3854 orexp
= insert_right_side (IOR
, orexp
, XEXP (link
, 0), -2, -2);
3855 prev
= &XEXP (link
, 1);
3857 link
= rtx_alloc (EXPR_LIST
);
3858 XEXP (link
, 0) = attr_rtx (NOT
, orexp
);
3863 return dim
->num_values
;
3866 /* Increment the current value for the NDIM-dimensional attribute space SPACE
3867 and return FALSE if the increment overflowed. */
3870 increment_current_value (space
, ndim
)
3871 struct dimension
*space
;
3876 for (i
= ndim
- 1; i
>= 0; i
--)
3878 if ((space
[i
].current_value
= XEXP (space
[i
].current_value
, 1)) == 0)
3879 space
[i
].current_value
= space
[i
].values
;
3886 /* Construct an expression corresponding to the current value for the
3887 NDIM-dimensional attribute space SPACE. */
3890 test_for_current_value (space
, ndim
)
3891 struct dimension
*space
;
3897 for (i
= 0; i
< ndim
; i
++)
3898 exp
= insert_right_side (AND
, exp
, XEXP (space
[i
].current_value
, 0),
3904 /* Given the current value of the NDIM-dimensional attribute space SPACE,
3905 set the corresponding EQ_ATTR expressions to that value and reduce
3906 the expression EXP as much as possible. On input [and output], all
3907 known EQ_ATTR expressions are set to FALSE. */
3910 simplify_with_current_value (exp
, space
, ndim
)
3912 struct dimension
*space
;
3918 /* Mark each current value as TRUE. */
3919 for (i
= 0; i
< ndim
; i
++)
3921 x
= XEXP (space
[i
].current_value
, 0);
3922 if (GET_CODE (x
) == EQ_ATTR
)
3923 MEM_VOLATILE_P (x
) = 0;
3926 exp
= simplify_with_current_value_aux (exp
);
3928 /* Change each current value back to FALSE. */
3929 for (i
= 0; i
< ndim
; i
++)
3931 x
= XEXP (space
[i
].current_value
, 0);
3932 if (GET_CODE (x
) == EQ_ATTR
)
3933 MEM_VOLATILE_P (x
) = 1;
3939 /* Reduce the expression EXP based on the MEM_VOLATILE_P settings of
3940 all EQ_ATTR expressions. */
3943 simplify_with_current_value_aux (exp
)
3949 switch (GET_CODE (exp
))
3952 if (MEM_VOLATILE_P (exp
))
3961 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
3962 if (cond
== true_rtx
)
3963 return simplify_with_current_value_aux (XEXP (exp
, 1));
3964 else if (cond
== false_rtx
)
3965 return simplify_with_current_value_aux (XEXP (exp
, 2));
3967 return attr_rtx (IF_THEN_ELSE
, cond
,
3968 simplify_with_current_value_aux (XEXP (exp
, 1)),
3969 simplify_with_current_value_aux (XEXP (exp
, 2)));
3972 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
3973 if (cond
== true_rtx
)
3975 else if (cond
== false_rtx
)
3976 return simplify_with_current_value_aux (XEXP (exp
, 0));
3978 return attr_rtx (IOR
, cond
,
3979 simplify_with_current_value_aux (XEXP (exp
, 0)));
3982 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
3983 if (cond
== true_rtx
)
3984 return simplify_with_current_value_aux (XEXP (exp
, 0));
3985 else if (cond
== false_rtx
)
3988 return attr_rtx (AND
, cond
,
3989 simplify_with_current_value_aux (XEXP (exp
, 0)));
3992 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
3993 if (cond
== true_rtx
)
3995 else if (cond
== false_rtx
)
3998 return attr_rtx (NOT
, cond
);
4001 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4003 cond
= simplify_with_current_value_aux (XVECEXP (exp
, 0, i
));
4004 if (cond
== true_rtx
)
4005 return simplify_with_current_value_aux (XVECEXP (exp
, 0, i
+ 1));
4006 else if (cond
== false_rtx
)
4009 abort (); /* With all EQ_ATTR's of known value, a case should
4010 have been selected. */
4012 return simplify_with_current_value_aux (XEXP (exp
, 1));
4019 /* Clear the MEM_IN_STRUCT_P flag in EXP and its subexpressions. */
4022 clear_struct_flag (x
)
4027 register enum rtx_code code
;
4028 register const char *fmt
;
4030 MEM_IN_STRUCT_P (x
) = 0;
4031 if (RTX_UNCHANGING_P (x
))
4034 code
= GET_CODE (x
);
4054 /* Compare the elements. If any pair of corresponding elements
4055 fail to match, return 0 for the whole things. */
4057 fmt
= GET_RTX_FORMAT (code
);
4058 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4064 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4065 clear_struct_flag (XVECEXP (x
, i
, j
));
4069 clear_struct_flag (XEXP (x
, i
));
4075 /* Return the number of RTX objects making up the expression X.
4076 But if we count more than MAX objects, stop counting. */
4079 count_sub_rtxs (x
, max
)
4085 register enum rtx_code code
;
4086 register const char *fmt
;
4089 code
= GET_CODE (x
);
4109 /* Compare the elements. If any pair of corresponding elements
4110 fail to match, return 0 for the whole things. */
4112 fmt
= GET_RTX_FORMAT (code
);
4113 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4122 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4123 total
+= count_sub_rtxs (XVECEXP (x
, i
, j
), max
);
4127 total
+= count_sub_rtxs (XEXP (x
, i
), max
);
4135 /* Create table entries for DEFINE_ATTR. */
4141 struct attr_desc
*attr
;
4142 struct attr_value
*av
;
4143 const char *name_ptr
;
4146 /* Make a new attribute structure. Check for duplicate by looking at
4147 attr->default_val, since it is initialized by this routine. */
4148 attr
= find_attr (XSTR (exp
, 0), 1);
4149 if (attr
->default_val
)
4150 fatal ("Duplicate definition for `%s' attribute", attr
->name
);
4152 if (*XSTR (exp
, 1) == '\0')
4153 attr
->is_numeric
= 1;
4156 name_ptr
= XSTR (exp
, 1);
4157 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
4159 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
4160 av
->value
= attr_rtx (CONST_STRING
, p
);
4161 av
->next
= attr
->first_value
;
4162 attr
->first_value
= av
;
4163 av
->first_insn
= NULL
;
4165 av
->has_asm_insn
= 0;
4169 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
4172 if (attr
->is_numeric
)
4173 fatal ("Constant attributes may not take numeric values");
4174 /* Get rid of the CONST node. It is allowed only at top-level. */
4175 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
4178 if (! strcmp (attr
->name
, "length") && ! attr
->is_numeric
)
4179 fatal ("`length' attribute must take numeric values");
4181 /* Set up the default value. */
4182 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
4183 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
4186 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
4187 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
4188 number of alternatives as this should be checked elsewhere. */
4191 count_alternatives (exp
)
4197 if (GET_CODE (exp
) == MATCH_OPERAND
)
4198 return n_comma_elts (XSTR (exp
, 2));
4200 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4201 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4206 n
= count_alternatives (XEXP (exp
, i
));
4213 if (XVEC (exp
, i
) != NULL
)
4214 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4216 n
= count_alternatives (XVECEXP (exp
, i
, j
));
4225 /* Returns non-zero if the given expression contains an EQ_ATTR with the
4226 `alternative' attribute. */
4229 compares_alternatives_p (exp
)
4235 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
4238 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4239 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4244 if (compares_alternatives_p (XEXP (exp
, i
)))
4249 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4250 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
4258 /* Returns non-zero is INNER is contained in EXP. */
4261 contained_in_p (inner
, exp
)
4268 if (rtx_equal_p (inner
, exp
))
4271 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4272 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4277 if (contained_in_p (inner
, XEXP (exp
, i
)))
4282 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4283 if (contained_in_p (inner
, XVECEXP (exp
, i
, j
)))
4291 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
4297 struct insn_def
*id
;
4299 id
= (struct insn_def
*) oballoc (sizeof (struct insn_def
));
4304 switch (GET_CODE (exp
))
4307 id
->insn_code
= insn_code_number
++;
4308 id
->insn_index
= insn_index_number
++;
4309 id
->num_alternatives
= count_alternatives (exp
);
4310 if (id
->num_alternatives
== 0)
4311 id
->num_alternatives
= 1;
4315 case DEFINE_PEEPHOLE
:
4316 id
->insn_code
= insn_code_number
++;
4317 id
->insn_index
= insn_index_number
++;
4318 id
->num_alternatives
= count_alternatives (exp
);
4319 if (id
->num_alternatives
== 0)
4320 id
->num_alternatives
= 1;
4324 case DEFINE_ASM_ATTRIBUTES
:
4326 id
->insn_index
= -1;
4327 id
->num_alternatives
= 1;
4329 got_define_asm_attributes
= 1;
4337 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
4338 true or annul false is specified, and make a `struct delay_desc'. */
4344 struct delay_desc
*delay
;
4347 if (XVECLEN (def
, 1) % 3 != 0)
4348 fatal ("Number of elements in DEFINE_DELAY must be multiple of three.");
4350 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
4352 if (XVECEXP (def
, 1, i
+ 1))
4353 have_annul_true
= 1;
4354 if (XVECEXP (def
, 1, i
+ 2))
4355 have_annul_false
= 1;
4358 delay
= (struct delay_desc
*) oballoc (sizeof (struct delay_desc
));
4360 delay
->num
= ++num_delays
;
4361 delay
->next
= delays
;
4365 /* Process a DEFINE_FUNCTION_UNIT.
4367 This gives information about a function unit contained in the CPU.
4368 We fill in a `struct function_unit_op' and a `struct function_unit'
4369 with information used later by `expand_unit'. */
4375 struct function_unit
*unit
;
4376 struct function_unit_op
*op
;
4377 const char *name
= XSTR (def
, 0);
4378 int multiplicity
= XINT (def
, 1);
4379 int simultaneity
= XINT (def
, 2);
4380 rtx condexp
= XEXP (def
, 3);
4381 int ready_cost
= MAX (XINT (def
, 4), 1);
4382 int issue_delay
= MAX (XINT (def
, 5), 1);
4384 /* See if we have already seen this function unit. If so, check that
4385 the multiplicity and simultaneity values are the same. If not, make
4386 a structure for this function unit. */
4387 for (unit
= units
; unit
; unit
= unit
->next
)
4388 if (! strcmp (unit
->name
, name
))
4390 if (unit
->multiplicity
!= multiplicity
4391 || unit
->simultaneity
!= simultaneity
)
4392 fatal ("Differing specifications given for `%s' function unit.",
4399 unit
= (struct function_unit
*) oballoc (sizeof (struct function_unit
));
4401 unit
->multiplicity
= multiplicity
;
4402 unit
->simultaneity
= simultaneity
;
4403 unit
->issue_delay
.min
= unit
->issue_delay
.max
= issue_delay
;
4404 unit
->num
= num_units
++;
4405 unit
->num_opclasses
= 0;
4406 unit
->condexp
= false_rtx
;
4412 /* Make a new operation class structure entry and initialize it. */
4413 op
= (struct function_unit_op
*) oballoc (sizeof (struct function_unit_op
));
4414 op
->condexp
= condexp
;
4415 op
->num
= unit
->num_opclasses
++;
4416 op
->ready
= ready_cost
;
4417 op
->issue_delay
= issue_delay
;
4418 op
->next
= unit
->ops
;
4420 num_unit_opclasses
++;
4422 /* Set our issue expression based on whether or not an optional conflict
4423 vector was specified. */
4426 /* Compute the IOR of all the specified expressions. */
4427 rtx orexp
= false_rtx
;
4430 for (i
= 0; i
< XVECLEN (def
, 6); i
++)
4431 orexp
= insert_right_side (IOR
, orexp
, XVECEXP (def
, 6, i
), -2, -2);
4433 op
->conflict_exp
= orexp
;
4434 extend_range (&unit
->issue_delay
, 1, issue_delay
);
4438 op
->conflict_exp
= true_rtx
;
4439 extend_range (&unit
->issue_delay
, issue_delay
, issue_delay
);
4442 /* Merge our conditional into that of the function unit so we can determine
4443 which insns are used by the function unit. */
4444 unit
->condexp
= insert_right_side (IOR
, unit
->condexp
, op
->condexp
, -2, -2);
4447 /* Given a piece of RTX, print a C expression to test its truth value.
4448 We use AND and IOR both for logical and bit-wise operations, so
4449 interpret them as logical unless they are inside a comparison expression.
4450 The first bit of FLAGS will be non-zero in that case.
4452 Set the second bit of FLAGS to make references to attribute values use
4453 a cached local variable instead of calling a function. */
4456 write_test_expr (exp
, flags
)
4460 int comparison_operator
= 0;
4462 struct attr_desc
*attr
;
4464 /* In order not to worry about operator precedence, surround our part of
4465 the expression with parentheses. */
4468 code
= GET_CODE (exp
);
4471 /* Binary operators. */
4473 case GE
: case GT
: case GEU
: case GTU
:
4474 case LE
: case LT
: case LEU
: case LTU
:
4475 comparison_operator
= 1;
4477 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
4478 case AND
: case IOR
: case XOR
:
4479 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
4480 write_test_expr (XEXP (exp
, 0), flags
| comparison_operator
);
4496 printf (" >= (unsigned) ");
4499 printf (" > (unsigned) ");
4508 printf (" <= (unsigned) ");
4511 printf (" < (unsigned) ");
4554 write_test_expr (XEXP (exp
, 1), flags
| comparison_operator
);
4558 /* Special-case (not (eq_attrq "alternative" "x")) */
4559 if (! (flags
& 1) && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
4560 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
4562 printf ("which_alternative != %s", XSTR (XEXP (exp
, 0), 1));
4566 /* Otherwise, fall through to normal unary operator. */
4568 /* Unary operators. */
4588 write_test_expr (XEXP (exp
, 0), flags
);
4591 /* Comparison test of an attribute with a value. Most of these will
4592 have been removed by optimization. Handle "alternative"
4593 specially and give error if EQ_ATTR present inside a comparison. */
4596 fatal ("EQ_ATTR not valid inside comparison");
4598 if (XSTR (exp
, 0) == alternative_name
)
4600 printf ("which_alternative == %s", XSTR (exp
, 1));
4604 attr
= find_attr (XSTR (exp
, 0), 0);
4605 if (! attr
) abort ();
4607 /* Now is the time to expand the value of a constant attribute. */
4610 write_test_expr (evaluate_eq_attr (exp
, attr
->default_val
->value
,
4617 printf ("attr_%s", attr
->name
);
4619 printf ("get_attr_%s (insn)", attr
->name
);
4621 write_attr_valueq (attr
, XSTR (exp
, 1));
4625 /* Comparison test of flags for define_delays. */
4628 fatal ("ATTR_FLAG not valid inside comparison");
4629 printf ("(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
4632 /* See if an operand matches a predicate. */
4634 /* If only a mode is given, just ensure the mode matches the operand.
4635 If neither a mode nor predicate is given, error. */
4636 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
4638 if (GET_MODE (exp
) == VOIDmode
)
4639 fatal ("Null MATCH_OPERAND specified as test");
4641 printf ("GET_MODE (operands[%d]) == %smode",
4642 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4645 printf ("%s (operands[%d], %smode)",
4646 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4650 printf ("%s (insn)", XSTR (exp
, 0));
4653 /* Constant integer. */
4655 printf (HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
4658 /* A random C expression. */
4660 printf ("%s", XSTR (exp
, 0));
4663 /* The address of the branch target. */
4665 printf ("insn_addresses[INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])]",
4666 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
4670 /* The address of the current insn. We implement this actually as the
4671 address of the current insn for backward branches, but the last
4672 address of the next insn for forward branches, and both with
4673 adjustments that account for the worst-case possible stretching of
4674 intervening alignments between this insn and its destination. */
4675 printf("insn_current_reference_address (insn)");
4679 printf ("%s", XSTR (exp
, 0));
4683 write_test_expr (XEXP (exp
, 0), flags
& 2);
4685 write_test_expr (XEXP (exp
, 1), flags
| 1);
4687 write_test_expr (XEXP (exp
, 2), flags
| 1);
4691 fatal ("bad RTX code `%s' in attribute calculation\n",
4692 GET_RTX_NAME (code
));
4698 /* Given an attribute value, return the maximum CONST_STRING argument
4699 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
4702 max_attr_value (exp
, unknownp
)
4709 switch (GET_CODE (exp
))
4712 current_max
= atoi (XSTR (exp
, 0));
4716 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4717 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4719 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4720 if (n
> current_max
)
4726 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4727 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
4728 if (n
> current_max
)
4734 current_max
= INT_MAX
;
4741 /* Given an attribute value, return the result of ORing together all
4742 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
4743 if the numeric value is not known. */
4746 or_attr_value (exp
, unknownp
)
4753 switch (GET_CODE (exp
))
4756 current_or
= atoi (XSTR (exp
, 0));
4760 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4761 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4762 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4766 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4767 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
4779 /* Scan an attribute value, possibly a conditional, and record what actions
4780 will be required to do any conditional tests in it.
4783 `must_extract' if we need to extract the insn operands
4784 `must_constrain' if we must compute `which_alternative'
4785 `address_used' if an address expression was used
4786 `length_used' if an (eq_attr "length" ...) was used
4790 walk_attr_value (exp
)
4794 register const char *fmt
;
4800 code
= GET_CODE (exp
);
4804 if (! RTX_UNCHANGING_P (exp
))
4805 /* Since this is an arbitrary expression, it can look at anything.
4806 However, constant expressions do not depend on any particular
4808 must_extract
= must_constrain
= 1;
4816 if (XSTR (exp
, 0) == alternative_name
)
4817 must_extract
= must_constrain
= 1;
4818 else if (strcmp (XSTR (exp
, 0), "length") == 0)
4838 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
4843 walk_attr_value (XEXP (exp
, i
));
4847 if (XVEC (exp
, i
) != NULL
)
4848 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4849 walk_attr_value (XVECEXP (exp
, i
, j
));
4854 /* Write out a function to obtain the attribute for a given INSN. */
4857 write_attr_get (attr
)
4858 struct attr_desc
*attr
;
4860 struct attr_value
*av
, *common_av
;
4862 /* Find the most used attribute value. Handle that as the `default' of the
4863 switch we will generate. */
4864 common_av
= find_most_used (attr
);
4866 /* Write out prototype of function. */
4867 if (!attr
->is_numeric
)
4868 printf ("extern enum attr_%s ", attr
->name
);
4869 else if (attr
->unsigned_p
)
4870 printf ("extern unsigned int ");
4872 printf ("extern int ");
4873 /* If the attribute name starts with a star, the remainder is the name of
4874 the subroutine to use, instead of `get_attr_...'. */
4875 if (attr
->name
[0] == '*')
4876 printf ("%s PARAMS ((rtx));\n", &attr
->name
[1]);
4878 printf ("get_attr_%s PARAMS ((%s));\n", attr
->name
,
4879 (attr
->is_const
? "void" : "rtx"));
4881 /* Write out start of function, then all values with explicit `case' lines,
4882 then a `default', then the value with the most uses. */
4883 if (!attr
->is_numeric
)
4884 printf ("enum attr_%s\n", attr
->name
);
4885 else if (attr
->unsigned_p
)
4886 printf ("unsigned int\n");
4890 /* If the attribute name starts with a star, the remainder is the name of
4891 the subroutine to use, instead of `get_attr_...'. */
4892 if (attr
->name
[0] == '*')
4893 printf ("%s (insn)\n", &attr
->name
[1]);
4894 else if (attr
->is_const
== 0)
4895 printf ("get_attr_%s (insn)\n", attr
->name
);
4898 printf ("get_attr_%s ()\n", attr
->name
);
4901 for (av
= attr
->first_value
; av
; av
= av
->next
)
4902 if (av
->num_insns
!= 0)
4903 write_attr_set (attr
, 2, av
->value
, "return", ";",
4904 true_rtx
, av
->first_insn
->insn_code
,
4905 av
->first_insn
->insn_index
);
4911 printf (" rtx insn;\n");
4914 if (GET_CODE (common_av
->value
) == FFS
)
4916 rtx p
= XEXP (common_av
->value
, 0);
4918 /* No need to emit code to abort if the insn is unrecognized; the
4919 other get_attr_foo functions will do that when we call them. */
4921 write_toplevel_expr (p
);
4923 printf ("\n if (accum && accum == (accum & -accum))\n");
4925 printf (" int i;\n");
4926 printf (" for (i = 0; accum >>= 1; ++i) continue;\n");
4927 printf (" accum = i;\n");
4928 printf (" }\n else\n");
4929 printf (" accum = ~accum;\n");
4930 printf (" return accum;\n}\n\n");
4934 printf (" switch (recog_memoized (insn))\n");
4937 for (av
= attr
->first_value
; av
; av
= av
->next
)
4938 if (av
!= common_av
)
4939 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
4941 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
4942 printf (" }\n}\n\n");
4946 /* Given an AND tree of known true terms (because we are inside an `if' with
4947 that as the condition or are in an `else' clause) and an expression,
4948 replace any known true terms with TRUE. Use `simplify_and_tree' to do
4949 the bulk of the work. */
4952 eliminate_known_true (known_true
, exp
, insn_code
, insn_index
)
4955 int insn_code
, insn_index
;
4959 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
4961 if (GET_CODE (known_true
) == AND
)
4963 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
4964 insn_code
, insn_index
);
4965 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
4966 insn_code
, insn_index
);
4971 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
4977 /* Write out a series of tests and assignment statements to perform tests and
4978 sets of an attribute value. We are passed an indentation amount and prefix
4979 and suffix strings to write around each attribute value (e.g., "return"
4983 write_attr_set (attr
, indent
, value
, prefix
, suffix
, known_true
,
4984 insn_code
, insn_index
)
4985 struct attr_desc
*attr
;
4991 int insn_code
, insn_index
;
4993 if (GET_CODE (value
) == COND
)
4995 /* Assume the default value will be the default of the COND unless we
4996 find an always true expression. */
4997 rtx default_val
= XEXP (value
, 1);
4998 rtx our_known_true
= known_true
;
5003 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
5008 testexp
= eliminate_known_true (our_known_true
,
5009 XVECEXP (value
, 0, i
),
5010 insn_code
, insn_index
);
5011 newexp
= attr_rtx (NOT
, testexp
);
5012 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
5013 insn_code
, insn_index
);
5015 /* If the test expression is always true or if the next `known_true'
5016 expression is always false, this is the last case, so break
5017 out and let this value be the `else' case. */
5018 if (testexp
== true_rtx
|| newexp
== false_rtx
)
5020 default_val
= XVECEXP (value
, 0, i
+ 1);
5024 /* Compute the expression to pass to our recursive call as being
5026 inner_true
= insert_right_side (AND
, our_known_true
,
5027 testexp
, insn_code
, insn_index
);
5029 /* If this is always false, skip it. */
5030 if (inner_true
== false_rtx
)
5033 write_indent (indent
);
5034 printf ("%sif ", first_if
? "" : "else ");
5036 write_test_expr (testexp
, 0);
5038 write_indent (indent
+ 2);
5041 write_attr_set (attr
, indent
+ 4,
5042 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
5043 inner_true
, insn_code
, insn_index
);
5044 write_indent (indent
+ 2);
5046 our_known_true
= newexp
;
5051 write_indent (indent
);
5053 write_indent (indent
+ 2);
5057 write_attr_set (attr
, first_if
? indent
: indent
+ 4, default_val
,
5058 prefix
, suffix
, our_known_true
, insn_code
, insn_index
);
5062 write_indent (indent
+ 2);
5068 write_indent (indent
);
5069 printf ("%s ", prefix
);
5070 write_attr_value (attr
, value
);
5071 printf ("%s\n", suffix
);
5075 /* Write out the computation for one attribute value. */
5078 write_attr_case (attr
, av
, write_case_lines
, prefix
, suffix
, indent
,
5080 struct attr_desc
*attr
;
5081 struct attr_value
*av
;
5082 int write_case_lines
;
5083 const char *prefix
, *suffix
;
5087 struct insn_ent
*ie
;
5089 if (av
->num_insns
== 0)
5092 if (av
->has_asm_insn
)
5094 write_indent (indent
);
5095 printf ("case -1:\n");
5096 write_indent (indent
+ 2);
5097 printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
5098 write_indent (indent
+ 2);
5099 printf (" && asm_noperands (PATTERN (insn)) < 0)\n");
5100 write_indent (indent
+ 2);
5101 printf (" fatal_insn_not_found (insn);\n");
5104 if (write_case_lines
)
5106 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5107 if (ie
->insn_code
!= -1)
5109 write_indent (indent
);
5110 printf ("case %d:\n", ie
->insn_code
);
5115 write_indent (indent
);
5116 printf ("default:\n");
5119 /* See what we have to do to output this value. */
5120 must_extract
= must_constrain
= address_used
= 0;
5121 walk_attr_value (av
->value
);
5125 write_indent (indent
+ 2);
5126 printf ("extract_insn (insn);\n");
5131 write_indent (indent
+ 2);
5132 printf ("if (! constrain_operands (reload_completed))\n");
5133 write_indent (indent
+ 2);
5134 printf (" fatal_insn_not_found (insn);\n");
5137 write_attr_set (attr
, indent
+ 2, av
->value
, prefix
, suffix
,
5138 known_true
, av
->first_insn
->insn_code
,
5139 av
->first_insn
->insn_index
);
5141 if (strncmp (prefix
, "return", 6))
5143 write_indent (indent
+ 2);
5144 printf ("break;\n");
5149 /* Search for uses of non-const attributes and write code to cache them. */
5152 write_expr_attr_cache (p
, attr
)
5154 struct attr_desc
*attr
;
5159 if (GET_CODE (p
) == EQ_ATTR
)
5161 if (XSTR (p
, 0) != attr
->name
)
5164 if (!attr
->is_numeric
)
5165 printf (" register enum attr_%s ", attr
->name
);
5166 else if (attr
->unsigned_p
)
5167 printf (" register unsigned int ");
5169 printf (" register int ");
5171 printf ("attr_%s = get_attr_%s (insn);\n", attr
->name
, attr
->name
);
5175 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
5176 ie
= GET_RTX_LENGTH (GET_CODE (p
));
5177 for (i
= 0; i
< ie
; i
++)
5182 if (write_expr_attr_cache (XEXP (p
, i
), attr
))
5187 je
= XVECLEN (p
, i
);
5188 for (j
= 0; j
< je
; ++j
)
5189 if (write_expr_attr_cache (XVECEXP (p
, i
, j
), attr
))
5198 /* Evaluate an expression at top level. A front end to write_test_expr,
5199 in which we cache attribute values and break up excessively large
5200 expressions to cater to older compilers. */
5203 write_toplevel_expr (p
)
5206 struct attr_desc
*attr
;
5209 for (i
= 0; i
< MAX_ATTRS_INDEX
; ++i
)
5210 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5211 if (!attr
->is_const
)
5212 write_expr_attr_cache (p
, attr
);
5214 printf(" register unsigned long accum = 0;\n\n");
5216 while (GET_CODE (p
) == IOR
)
5219 if (GET_CODE (XEXP (p
, 0)) == IOR
)
5220 e
= XEXP (p
, 1), p
= XEXP (p
, 0);
5222 e
= XEXP (p
, 0), p
= XEXP (p
, 1);
5224 printf (" accum |= ");
5225 write_test_expr (e
, 3);
5228 printf (" accum |= ");
5229 write_test_expr (p
, 3);
5233 /* Utilities to write names in various forms. */
5236 write_unit_name (prefix
, num
, suffix
)
5241 struct function_unit
*unit
;
5243 for (unit
= units
; unit
; unit
= unit
->next
)
5244 if (unit
->num
== num
)
5246 printf ("%s%s%s", prefix
, unit
->name
, suffix
);
5250 printf ("%s<unknown>%s", prefix
, suffix
);
5254 write_attr_valueq (attr
, s
)
5255 struct attr_desc
*attr
;
5258 if (attr
->is_numeric
)
5264 /* Make the blockage range values and function units used values easier
5266 if (attr
->func_units_p
)
5269 printf (" /* units: none */");
5271 write_unit_name (" /* units: ", num
, " */");
5275 const char *sep
= " /* units: ";
5276 for (i
= 0, num
= ~num
; num
; i
++, num
>>= 1)
5279 write_unit_name (sep
, i
, (num
== 1) ? " */" : "");
5285 else if (attr
->blockage_p
)
5286 printf (" /* min %d, max %d */", num
>> (HOST_BITS_PER_INT
/ 2),
5287 num
& ((1 << (HOST_BITS_PER_INT
/ 2)) - 1));
5289 else if (num
> 9 || num
< 0)
5290 printf (" /* 0x%x */", num
);
5294 write_upcase (attr
->name
);
5301 write_attr_value (attr
, value
)
5302 struct attr_desc
*attr
;
5307 switch (GET_CODE (value
))
5310 write_attr_valueq (attr
, XSTR (value
, 0));
5314 fputs (XSTR (value
, 0), stdout
);
5319 struct attr_desc
*attr2
= find_attr (XSTR (value
, 0), 0);
5320 printf ("get_attr_%s (%s)", attr2
->name
,
5321 (attr2
->is_const
? "" : "insn"));
5342 write_attr_value (attr
, XEXP (value
, 0));
5346 write_attr_value (attr
, XEXP (value
, 1));
5360 /* The argument of TOUPPER should not have side effects. */
5361 putchar (TOUPPER(*str
));
5367 write_indent (indent
)
5370 for (; indent
> 8; indent
-= 8)
5373 for (; indent
; indent
--)
5377 /* Write a subroutine that is given an insn that requires a delay slot, a
5378 delay slot ordinal, and a candidate insn. It returns non-zero if the
5379 candidate can be placed in the specified delay slot of the insn.
5381 We can write as many as three subroutines. `eligible_for_delay'
5382 handles normal delay slots, `eligible_for_annul_true' indicates that
5383 the specified insn can be annulled if the branch is true, and likewise
5384 for `eligible_for_annul_false'.
5386 KIND is a string distinguishing these three cases ("delay", "annul_true",
5387 or "annul_false"). */
5390 write_eligible_delay (kind
)
5393 struct delay_desc
*delay
;
5396 struct attr_desc
*attr
;
5397 struct attr_value
*av
, *common_av
;
5400 /* Compute the maximum number of delay slots required. We use the delay
5401 ordinal times this number plus one, plus the slot number as an index into
5402 the appropriate predicate to test. */
5404 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
5405 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
5406 max_slots
= XVECLEN (delay
->def
, 1) / 3;
5408 /* Write function prelude. */
5411 printf ("eligible_for_%s (delay_insn, slot, candidate_insn, flags)\n",
5413 printf (" rtx delay_insn;\n");
5414 printf (" int slot;\n");
5415 printf (" rtx candidate_insn;\n");
5416 printf (" int flags ATTRIBUTE_UNUSED;\n");
5418 printf (" rtx insn;\n");
5420 printf (" if (slot >= %d)\n", max_slots
);
5421 printf (" abort ();\n");
5424 /* If more than one delay type, find out which type the delay insn is. */
5428 attr
= find_attr ("*delay_type", 0);
5429 if (! attr
) abort ();
5430 common_av
= find_most_used (attr
);
5432 printf (" insn = delay_insn;\n");
5433 printf (" switch (recog_memoized (insn))\n");
5436 sprintf (str
, " * %d;\n break;", max_slots
);
5437 for (av
= attr
->first_value
; av
; av
= av
->next
)
5438 if (av
!= common_av
)
5439 write_attr_case (attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
5441 write_attr_case (attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
5444 /* Ensure matched. Otherwise, shouldn't have been called. */
5445 printf (" if (slot < %d)\n", max_slots
);
5446 printf (" abort ();\n\n");
5449 /* If just one type of delay slot, write simple switch. */
5450 if (num_delays
== 1 && max_slots
== 1)
5452 printf (" insn = candidate_insn;\n");
5453 printf (" switch (recog_memoized (insn))\n");
5456 attr
= find_attr ("*delay_1_0", 0);
5457 if (! attr
) abort ();
5458 common_av
= find_most_used (attr
);
5460 for (av
= attr
->first_value
; av
; av
= av
->next
)
5461 if (av
!= common_av
)
5462 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5464 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5470 /* Write a nested CASE. The first indicates which condition we need to
5471 test, and the inner CASE tests the condition. */
5472 printf (" insn = candidate_insn;\n");
5473 printf (" switch (slot)\n");
5476 for (delay
= delays
; delay
; delay
= delay
->next
)
5477 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
5479 printf (" case %d:\n",
5480 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
5481 printf (" switch (recog_memoized (insn))\n");
5484 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
5485 attr
= find_attr (str
, 0);
5486 if (! attr
) abort ();
5487 common_av
= find_most_used (attr
);
5489 for (av
= attr
->first_value
; av
; av
= av
->next
)
5490 if (av
!= common_av
)
5491 write_attr_case (attr
, av
, 1, "return", ";", 8, true_rtx
);
5493 write_attr_case (attr
, common_av
, 0, "return", ";", 8, true_rtx
);
5497 printf (" default:\n");
5498 printf (" abort ();\n");
5505 /* Write routines to compute conflict cost for function units. Then write a
5506 table describing the available function units. */
5509 write_function_unit_info ()
5511 struct function_unit
*unit
;
5514 /* Write out conflict routines for function units. Don't bother writing
5515 one if there is only one issue delay value. */
5517 for (unit
= units
; unit
; unit
= unit
->next
)
5519 if (unit
->needs_blockage_function
)
5520 write_complex_function (unit
, "blockage", "block");
5522 /* If the minimum and maximum conflict costs are the same, there
5523 is only one value, so we don't need a function. */
5524 if (! unit
->needs_conflict_function
)
5526 unit
->default_cost
= make_numeric_value (unit
->issue_delay
.max
);
5530 /* The function first computes the case from the candidate insn. */
5531 unit
->default_cost
= make_numeric_value (0);
5532 write_complex_function (unit
, "conflict_cost", "cost");
5535 /* Now that all functions have been written, write the table describing
5536 the function units. The name is included for documentation purposes
5539 printf ("struct function_unit_desc function_units[] = {\n");
5541 /* Write out the descriptions in numeric order, but don't force that order
5542 on the list. Doing so increases the runtime of genattrtab.c. */
5543 for (i
= 0; i
< num_units
; i
++)
5545 for (unit
= units
; unit
; unit
= unit
->next
)
5549 printf (" {\"%s\", %d, %d, %d, %s, %d, %s_unit_ready_cost, ",
5550 unit
->name
, 1 << unit
->num
, unit
->multiplicity
,
5551 unit
->simultaneity
, XSTR (unit
->default_cost
, 0),
5552 unit
->issue_delay
.max
, unit
->name
);
5554 if (unit
->needs_conflict_function
)
5555 printf ("%s_unit_conflict_cost, ", unit
->name
);
5559 printf ("%d, ", unit
->max_blockage
);
5561 if (unit
->needs_range_function
)
5562 printf ("%s_unit_blockage_range, ", unit
->name
);
5566 if (unit
->needs_blockage_function
)
5567 printf ("%s_unit_blockage", unit
->name
);
5578 write_complex_function (unit
, name
, connection
)
5579 struct function_unit
*unit
;
5580 const char *name
, *connection
;
5582 struct attr_desc
*case_attr
, *attr
;
5583 struct attr_value
*av
, *common_av
;
5589 printf ("static int %s_unit_%s PARAMS ((rtx, rtx));\n", unit
->name
, name
);
5590 printf ("static int\n");
5591 printf ("%s_unit_%s (executing_insn, candidate_insn)\n",
5593 printf (" rtx executing_insn;\n");
5594 printf (" rtx candidate_insn;\n");
5596 printf (" rtx insn;\n");
5597 printf (" int casenum;\n\n");
5598 printf (" insn = executing_insn;\n");
5599 printf (" switch (recog_memoized (insn))\n");
5602 /* Write the `switch' statement to get the case value. */
5603 str
= (char *) alloca (strlen (unit
->name
) + strlen (name
) + strlen (connection
) + 10);
5604 sprintf (str
, "*%s_cases", unit
->name
);
5605 case_attr
= find_attr (str
, 0);
5606 if (! case_attr
) abort ();
5607 common_av
= find_most_used (case_attr
);
5609 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5610 if (av
!= common_av
)
5611 write_attr_case (case_attr
, av
, 1,
5612 "casenum =", ";", 4, unit
->condexp
);
5614 write_attr_case (case_attr
, common_av
, 0,
5615 "casenum =", ";", 4, unit
->condexp
);
5618 /* Now write an outer switch statement on each case. Then write
5619 the tests on the executing function within each. */
5620 printf (" insn = candidate_insn;\n");
5621 printf (" switch (casenum)\n");
5624 for (i
= 0; i
< unit
->num_opclasses
; i
++)
5626 /* Ensure using this case. */
5628 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5630 && contained_in_p (make_numeric_value (i
), av
->value
))
5636 printf (" case %d:\n", i
);
5637 sprintf (str
, "*%s_%s_%d", unit
->name
, connection
, i
);
5638 attr
= find_attr (str
, 0);
5639 if (! attr
) abort ();
5641 /* If single value, just write it. */
5642 value
= find_single_value (attr
);
5644 write_attr_set (attr
, 6, value
, "return", ";\n", true_rtx
, -2, -2);
5647 common_av
= find_most_used (attr
);
5648 printf (" switch (recog_memoized (insn))\n");
5651 for (av
= attr
->first_value
; av
; av
= av
->next
)
5652 if (av
!= common_av
)
5653 write_attr_case (attr
, av
, 1,
5654 "return", ";", 8, unit
->condexp
);
5656 write_attr_case (attr
, common_av
, 0,
5657 "return", ";", 8, unit
->condexp
);
5662 /* This default case should not be needed, but gcc's analysis is not
5663 good enough to realize that the default case is not needed for the
5664 second switch statement. */
5665 printf (" default:\n abort ();\n");
5666 printf (" }\n}\n\n");
5669 /* This page contains miscellaneous utility routines. */
5671 /* Given a string, return the number of comma-separated elements in it.
5672 Return 0 for the null string. */
5683 for (n
= 1; *s
; s
++)
5690 /* Given a pointer to a (char *), return a malloc'ed string containing the
5691 next comma-separated element. Advance the pointer to after the string
5692 scanned, or the end-of-string. Return NULL if at end of string. */
5695 next_comma_elt (pstr
)
5704 /* Find end of string to compute length. */
5705 for (p
= *pstr
; *p
!= ',' && *p
!= '\0'; p
++)
5708 out_str
= attr_string (*pstr
, p
- *pstr
);
5717 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
5718 is non-zero, build a new attribute, if one does not exist. */
5720 static struct attr_desc
*
5721 find_attr (name
, create
)
5725 struct attr_desc
*attr
;
5728 /* Before we resort to using `strcmp', see if the string address matches
5729 anywhere. In most cases, it should have been canonicalized to do so. */
5730 if (name
== alternative_name
)
5733 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
5734 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5735 if (name
== attr
->name
)
5738 /* Otherwise, do it the slow way. */
5739 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5740 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
5746 attr
= (struct attr_desc
*) oballoc (sizeof (struct attr_desc
));
5747 attr
->name
= attr_string (name
, strlen (name
));
5748 attr
->first_value
= attr
->default_val
= NULL
;
5749 attr
->is_numeric
= attr
->negative_ok
= attr
->is_const
= attr
->is_special
= 0;
5750 attr
->next
= attrs
[index
];
5751 attrs
[index
] = attr
;
5756 /* Create internal attribute with the given default value. */
5759 make_internal_attr (name
, value
, special
)
5764 struct attr_desc
*attr
;
5766 attr
= find_attr (name
, 1);
5767 if (attr
->default_val
)
5770 attr
->is_numeric
= 1;
5772 attr
->is_special
= (special
& 1) != 0;
5773 attr
->negative_ok
= (special
& 2) != 0;
5774 attr
->unsigned_p
= (special
& 4) != 0;
5775 attr
->func_units_p
= (special
& 8) != 0;
5776 attr
->blockage_p
= (special
& 16) != 0;
5777 attr
->default_val
= get_attr_value (value
, attr
, -2);
5780 /* Find the most used value of an attribute. */
5782 static struct attr_value
*
5783 find_most_used (attr
)
5784 struct attr_desc
*attr
;
5786 struct attr_value
*av
;
5787 struct attr_value
*most_used
;
5793 for (av
= attr
->first_value
; av
; av
= av
->next
)
5794 if (av
->num_insns
> nuses
)
5795 nuses
= av
->num_insns
, most_used
= av
;
5800 /* If an attribute only has a single value used, return it. Otherwise
5804 find_single_value (attr
)
5805 struct attr_desc
*attr
;
5807 struct attr_value
*av
;
5810 unique_value
= NULL
;
5811 for (av
= attr
->first_value
; av
; av
= av
->next
)
5817 unique_value
= av
->value
;
5820 return unique_value
;
5823 /* Return (attr_value "n") */
5826 make_numeric_value (n
)
5829 static rtx int_values
[20];
5836 if (n
< 20 && int_values
[n
])
5837 return int_values
[n
];
5839 p
= attr_printf (MAX_DIGITS
, "%d", n
);
5840 exp
= attr_rtx (CONST_STRING
, p
);
5843 int_values
[n
] = exp
;
5849 extend_range (range
, min
, max
)
5850 struct range
*range
;
5854 if (range
->min
> min
) range
->min
= min
;
5855 if (range
->max
< max
) range
->max
= max
;
5859 xrealloc (old
, size
)
5865 ptr
= (PTR
) realloc (old
, size
);
5867 ptr
= (PTR
) malloc (size
);
5869 fatal ("virtual memory exhausted");
5877 register PTR val
= (PTR
) malloc (size
);
5880 fatal ("virtual memory exhausted");
5885 copy_rtx_unchanging (orig
)
5890 register RTX_CODE code
;
5893 if (RTX_UNCHANGING_P (orig
) || MEM_IN_STRUCT_P (orig
))
5896 MEM_IN_STRUCT_P (orig
) = 1;
5900 code
= GET_CODE (orig
);
5913 copy
= rtx_alloc (code
);
5914 PUT_MODE (copy
, GET_MODE (orig
));
5915 RTX_UNCHANGING_P (copy
) = 1;
5917 bcopy ((char *) &XEXP (orig
, 0), (char *) &XEXP (copy
, 0),
5918 GET_RTX_LENGTH (GET_CODE (copy
)) * sizeof (rtx
));
5923 /* Determine if an insn has a constant number of delay slots, i.e., the
5924 number of delay slots is not a function of the length of the insn. */
5927 write_const_num_delay_slots ()
5929 struct attr_desc
*attr
= find_attr ("*num_delay_slots", 0);
5930 struct attr_value
*av
;
5931 struct insn_ent
*ie
;
5935 printf ("int\nconst_num_delay_slots (insn)\n");
5936 printf (" rtx insn;\n");
5938 printf (" switch (recog_memoized (insn))\n");
5941 for (av
= attr
->first_value
; av
; av
= av
->next
)
5944 walk_attr_value (av
->value
);
5947 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5948 if (ie
->insn_code
!= -1)
5949 printf (" case %d:\n", ie
->insn_code
);
5950 printf (" return 0;\n");
5954 printf (" default:\n");
5955 printf (" return 1;\n");
5956 printf (" }\n}\n\n");
5961 extern int main
PARAMS ((int, char **));
5971 struct attr_desc
*attr
;
5972 struct insn_def
*id
;
5976 progname
= "genattrtab";
5978 #if defined (RLIMIT_STACK) && defined (HAVE_GETRLIMIT) && defined (HAVE_SETRLIMIT)
5979 /* Get rid of any avoidable limit on stack size. */
5983 /* Set the stack limit huge so that alloca does not fail. */
5984 getrlimit (RLIMIT_STACK
, &rlim
);
5985 rlim
.rlim_cur
= rlim
.rlim_max
;
5986 setrlimit (RLIMIT_STACK
, &rlim
);
5990 progname
= "genattrtab";
5991 obstack_init (rtl_obstack
);
5992 obstack_init (hash_obstack
);
5993 obstack_init (temp_obstack
);
5996 fatal ("No input file name.");
5998 infile
= fopen (argv
[1], "r");
6002 return (FATAL_EXIT_CODE
);
6004 read_rtx_filename
= argv
[1];
6006 /* Set up true and false rtx's */
6007 true_rtx
= rtx_alloc (CONST_INT
);
6008 XWINT (true_rtx
, 0) = 1;
6009 false_rtx
= rtx_alloc (CONST_INT
);
6010 XWINT (false_rtx
, 0) = 0;
6011 RTX_UNCHANGING_P (true_rtx
) = RTX_UNCHANGING_P (false_rtx
) = 1;
6012 RTX_INTEGRATED_P (true_rtx
) = RTX_INTEGRATED_P (false_rtx
) = 1;
6014 alternative_name
= attr_string ("alternative", strlen ("alternative"));
6016 printf ("/* Generated automatically by the program `genattrtab'\n\
6017 from the machine description file `md'. */\n\n");
6019 /* Read the machine description. */
6023 c
= read_skip_spaces (infile
);
6028 desc
= read_rtx (infile
);
6029 if (GET_CODE (desc
) == DEFINE_INSN
6030 || GET_CODE (desc
) == DEFINE_PEEPHOLE
6031 || GET_CODE (desc
) == DEFINE_ASM_ATTRIBUTES
)
6034 else if (GET_CODE (desc
) == DEFINE_EXPAND
)
6035 insn_code_number
++, insn_index_number
++;
6037 else if (GET_CODE (desc
) == DEFINE_SPLIT
)
6038 insn_code_number
++, insn_index_number
++;
6040 else if (GET_CODE (desc
) == DEFINE_PEEPHOLE2
)
6041 insn_code_number
++, insn_index_number
++;
6043 else if (GET_CODE (desc
) == DEFINE_ATTR
)
6046 insn_index_number
++;
6049 else if (GET_CODE (desc
) == DEFINE_DELAY
)
6052 insn_index_number
++;
6055 else if (GET_CODE (desc
) == DEFINE_FUNCTION_UNIT
)
6058 insn_index_number
++;
6062 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
6063 if (! got_define_asm_attributes
)
6065 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
6066 XVEC (tem
, 0) = rtvec_alloc (0);
6070 /* Expand DEFINE_DELAY information into new attribute. */
6074 /* Expand DEFINE_FUNCTION_UNIT information into new attributes. */
6078 printf ("#include \"config.h\"\n");
6079 printf ("#include \"system.h\"\n");
6080 printf ("#include \"rtl.h\"\n");
6081 printf ("#include \"tm_p.h\"\n");
6082 printf ("#include \"insn-config.h\"\n");
6083 printf ("#include \"recog.h\"\n");
6084 printf ("#include \"regs.h\"\n");
6085 printf ("#include \"real.h\"\n");
6086 printf ("#include \"output.h\"\n");
6087 printf ("#include \"insn-attr.h\"\n");
6088 printf ("#include \"toplev.h\"\n");
6090 printf ("#define operands recog_data.operand\n\n");
6092 /* Make `insn_alternatives'. */
6093 insn_alternatives
= (int *) oballoc (insn_code_number
* sizeof (int));
6094 for (id
= defs
; id
; id
= id
->next
)
6095 if (id
->insn_code
>= 0)
6096 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
6098 /* Make `insn_n_alternatives'. */
6099 insn_n_alternatives
= (int *) oballoc (insn_code_number
* sizeof (int));
6100 for (id
= defs
; id
; id
= id
->next
)
6101 if (id
->insn_code
>= 0)
6102 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
6104 /* Prepare to write out attribute subroutines by checking everything stored
6105 away and building the attribute cases. */
6108 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6109 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6111 attr
->default_val
->value
6112 = check_attr_value (attr
->default_val
->value
, attr
);
6116 /* Construct extra attributes for `length'. */
6117 make_length_attrs ();
6119 /* Perform any possible optimizations to speed up compilation. */
6122 /* Now write out all the `gen_attr_...' routines. Do these before the
6123 special routines (specifically before write_function_unit_info), so
6124 that they get defined before they are used. */
6126 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6127 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6129 if (! attr
->is_special
&& ! attr
->is_const
)
6130 write_attr_get (attr
);
6133 /* Write out delay eligibility information, if DEFINE_DELAY present.
6134 (The function to compute the number of delay slots will be written
6138 write_eligible_delay ("delay");
6139 if (have_annul_true
)
6140 write_eligible_delay ("annul_true");
6141 if (have_annul_false
)
6142 write_eligible_delay ("annul_false");
6145 /* Write out information about function units. */
6147 write_function_unit_info ();
6149 /* Write out constant delay slot info */
6150 write_const_num_delay_slots ();
6152 write_length_unit_log ();
6155 return (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);
6158 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
6160 get_insn_name (code
)
6161 int code ATTRIBUTE_UNUSED
;