1 /* Generate code from machine description to compute values of attributes.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2002 Free Software Foundation, Inc.
4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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' (ATTR_IND_SIMPLIFIED_P): This rtx is fully simplified
90 independent of the insn code.
91 `in_struct' (ATTR_CURR_SIMPLIFIED_P): This rtx is fully simplified
92 for the insn code currently being processed (see optimize_attrs).
93 `integrated' (ATTR_PERMANENT_P): This rtx is permanent and unique
95 `volatil' (ATTR_EQ_ATTR_P): During simplify_by_exploding the value of an
96 EQ_ATTR rtx is true if !volatil and false if volatil. */
98 #define ATTR_IND_SIMPLIFIED_P(RTX) (RTX_FLAG((RTX), unchanging))
99 #define ATTR_CURR_SIMPLIFIED_P(RTX) (RTX_FLAG((RTX), in_struct))
100 #define ATTR_PERMANENT_P(RTX) (RTX_FLAG((RTX), integrated))
101 #define ATTR_EQ_ATTR_P(RTX) (RTX_FLAG((RTX), volatil))
105 #include "coretypes.h"
109 #include "gensupport.h"
111 #ifdef HAVE_SYS_RESOURCE_H
112 # include <sys/resource.h>
115 /* We must include obstack.h after <sys/time.h>, to avoid lossage with
116 /usr/include/sys/stdtypes.h on Sun OS 4.x. */
120 #include "genattrtab.h"
122 static struct obstack obstack1
, obstack2
;
123 struct obstack
*hash_obstack
= &obstack1
;
124 struct obstack
*temp_obstack
= &obstack2
;
126 /* enough space to reserve for printing out ints */
127 #define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
129 /* Define structures used to record attributes and values. */
131 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
132 encountered, we store all the relevant information into a
133 `struct insn_def'. This is done to allow attribute definitions to occur
134 anywhere in the file. */
138 struct insn_def
*next
; /* Next insn in chain. */
139 rtx def
; /* The DEFINE_... */
140 int insn_code
; /* Instruction number. */
141 int insn_index
; /* Expression numer in file, for errors. */
142 int lineno
; /* Line number. */
143 int num_alternatives
; /* Number of alternatives. */
144 int vec_idx
; /* Index of attribute vector in `def'. */
147 /* Once everything has been read in, we store in each attribute value a list
148 of insn codes that have that value. Here is the structure used for the
153 struct insn_ent
*next
; /* Next in chain. */
154 int insn_code
; /* Instruction number. */
155 int insn_index
; /* Index of definition in file */
156 int lineno
; /* Line number. */
159 /* Each value of an attribute (either constant or computed) is assigned a
160 structure which is used as the listhead of the insns that have that
165 rtx value
; /* Value of attribute. */
166 struct attr_value
*next
; /* Next attribute value in chain. */
167 struct insn_ent
*first_insn
; /* First insn with this value. */
168 int num_insns
; /* Number of insns with this value. */
169 int has_asm_insn
; /* True if this value used for `asm' insns */
172 /* Structure for each attribute. */
176 char *name
; /* Name of attribute. */
177 struct attr_desc
*next
; /* Next attribute. */
178 unsigned is_numeric
: 1; /* Values of this attribute are numeric. */
179 unsigned negative_ok
: 1; /* Allow negative numeric values. */
180 unsigned unsigned_p
: 1; /* Make the output function unsigned int. */
181 unsigned is_const
: 1; /* Attribute value constant for each run. */
182 unsigned is_special
: 1; /* Don't call `write_attr_set'. */
183 unsigned func_units_p
: 1; /* this is the function_units attribute */
184 unsigned blockage_p
: 1; /* this is the blockage range function */
185 struct attr_value
*first_value
; /* First value of this attribute. */
186 struct attr_value
*default_val
; /* Default value for this attribute. */
187 int lineno
; /* Line number. */
190 #define NULL_ATTR (struct attr_desc *) NULL
192 /* A range of values. */
200 /* Structure for each DEFINE_DELAY. */
204 rtx def
; /* DEFINE_DELAY expression. */
205 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
206 int num
; /* Number of DEFINE_DELAY, starting at 1. */
207 int lineno
; /* Line number. */
210 /* Record information about each DEFINE_FUNCTION_UNIT. */
212 struct function_unit_op
214 rtx condexp
; /* Expression TRUE for applicable insn. */
215 struct function_unit_op
*next
; /* Next operation for this function unit. */
216 int num
; /* Ordinal for this operation type in unit. */
217 int ready
; /* Cost until data is ready. */
218 int issue_delay
; /* Cost until unit can accept another insn. */
219 rtx conflict_exp
; /* Expression TRUE for insns incurring issue delay. */
220 rtx issue_exp
; /* Expression computing issue delay. */
221 int lineno
; /* Line number. */
224 /* Record information about each function unit mentioned in a
225 DEFINE_FUNCTION_UNIT. */
229 const char *name
; /* Function unit name. */
230 struct function_unit
*next
; /* Next function unit. */
231 int num
; /* Ordinal of this unit type. */
232 int multiplicity
; /* Number of units of this type. */
233 int simultaneity
; /* Maximum number of simultaneous insns
234 on this function unit or 0 if unlimited. */
235 rtx condexp
; /* Expression TRUE for insn needing unit. */
236 int num_opclasses
; /* Number of different operation types. */
237 struct function_unit_op
*ops
; /* Pointer to first operation type. */
238 int needs_conflict_function
; /* Nonzero if a conflict function required. */
239 int needs_blockage_function
; /* Nonzero if a blockage function required. */
240 int needs_range_function
; /* Nonzero if blockage range function needed. */
241 rtx default_cost
; /* Conflict cost, if constant. */
242 struct range issue_delay
; /* Range of issue delay values. */
243 int max_blockage
; /* Maximum time an insn blocks the unit. */
244 int first_lineno
; /* First seen line number. */
247 /* Listheads of above structures. */
249 /* This one is indexed by the first character of the attribute name. */
250 #define MAX_ATTRS_INDEX 256
251 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
252 static struct insn_def
*defs
;
253 static struct delay_desc
*delays
;
254 static struct function_unit
*units
;
256 /* An expression where all the unknown terms are EQ_ATTR tests can be
257 rearranged into a COND provided we can enumerate all possible
258 combinations of the unknown values. The set of combinations become the
259 tests of the COND; the value of the expression given that combination is
260 computed and becomes the corresponding value. To do this, we must be
261 able to enumerate all values for each attribute used in the expression
262 (currently, we give up if we find a numeric attribute).
264 If the set of EQ_ATTR tests used in an expression tests the value of N
265 different attributes, the list of all possible combinations can be made
266 by walking the N-dimensional attribute space defined by those
267 attributes. We record each of these as a struct dimension.
269 The algorithm relies on sharing EQ_ATTR nodes: if two nodes in an
270 expression are the same, the will also have the same address. We find
271 all the EQ_ATTR nodes by marking them ATTR_EQ_ATTR_P. This bit later
272 represents the value of an EQ_ATTR node, so once all nodes are marked,
273 they are also given an initial value of FALSE.
275 We then separate the set of EQ_ATTR nodes into dimensions for each
276 attribute and put them on the VALUES list. Terms are added as needed by
277 `add_values_to_cover' so that all possible values of the attribute are
280 Each dimension also has a current value. This is the node that is
281 currently considered to be TRUE. If this is one of the nodes added by
282 `add_values_to_cover', all the EQ_ATTR tests in the original expression
283 will be FALSE. Otherwise, only the CURRENT_VALUE will be true.
285 NUM_VALUES is simply the length of the VALUES list and is there for
288 Once the dimensions are created, the algorithm enumerates all possible
289 values and computes the current value of the given expression. */
293 struct attr_desc
*attr
; /* Attribute for this dimension. */
294 rtx values
; /* List of attribute values used. */
295 rtx current_value
; /* Position in the list for the TRUE value. */
296 int num_values
; /* Length of the values list. */
299 /* Other variables. */
301 static int insn_code_number
;
302 static int insn_index_number
;
303 static int got_define_asm_attributes
;
304 static int must_extract
;
305 static int must_constrain
;
306 static int address_used
;
307 static int length_used
;
308 static int num_delays
;
309 static int have_annul_true
, have_annul_false
;
310 static int num_units
, num_unit_opclasses
;
311 static int num_insn_ents
;
315 /* Used as operand to `operate_exp': */
317 enum operator {PLUS_OP
, MINUS_OP
, POS_MINUS_OP
, EQ_OP
, OR_OP
, ORX_OP
, MAX_OP
, MIN_OP
, RANGE_OP
};
319 /* Stores, for each insn code, the number of constraint alternatives. */
321 static int *insn_n_alternatives
;
323 /* Stores, for each insn code, a bitmap that has bits on for each possible
326 static int *insn_alternatives
;
328 /* If nonzero, assume that the `alternative' attr has this value.
329 This is the hashed, unique string for the numeral
330 whose value is chosen alternative. */
332 static const char *current_alternative_string
;
334 /* Used to simplify expressions. */
336 static rtx true_rtx
, false_rtx
;
338 /* Used to reduce calls to `strcmp' */
340 static char *alternative_name
;
342 /* Indicate that REG_DEAD notes are valid if dead_or_set_p is ever
345 int reload_completed
= 0;
347 /* Some machines test `optimize' in macros called from rtlanal.c, so we need
348 to define it here. */
352 /* Simplify an expression. Only call the routine if there is something to
354 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
355 (ATTR_IND_SIMPLIFIED_P (EXP) || ATTR_CURR_SIMPLIFIED_P (EXP) ? (EXP) \
356 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
358 /* Simplify (eq_attr ("alternative") ...)
359 when we are working with a particular alternative. */
360 #define SIMPLIFY_ALTERNATIVE(EXP) \
361 if (current_alternative_string \
362 && GET_CODE ((EXP)) == EQ_ATTR \
363 && XSTR ((EXP), 0) == alternative_name) \
364 (EXP) = (XSTR ((EXP), 1) == current_alternative_string \
365 ? true_rtx : false_rtx);
367 /* These are referenced by rtlanal.c and hence need to be defined somewhere.
368 They won't actually be used. */
370 rtx global_rtl
[GR_MAX
];
371 rtx pic_offset_table_rtx
;
373 static void attr_hash_add_rtx
PARAMS ((int, rtx
));
374 static void attr_hash_add_string
PARAMS ((int, char *));
375 static rtx attr_rtx
PARAMS ((enum rtx_code
, ...));
376 static rtx attr_rtx_1
PARAMS ((enum rtx_code
, va_list));
377 static char *attr_string
PARAMS ((const char *, int));
378 static rtx check_attr_value
PARAMS ((rtx
, struct attr_desc
*));
379 static rtx convert_set_attr_alternative
PARAMS ((rtx
, struct insn_def
*));
380 static rtx convert_set_attr
PARAMS ((rtx
, struct insn_def
*));
381 static void check_defs
PARAMS ((void));
383 static rtx convert_const_symbol_ref
PARAMS ((rtx
, struct attr_desc
*));
385 static rtx make_canonical
PARAMS ((struct attr_desc
*, rtx
));
386 static struct attr_value
*get_attr_value
PARAMS ((rtx
, struct attr_desc
*, int));
387 static rtx copy_rtx_unchanging
PARAMS ((rtx
));
388 static rtx copy_boolean
PARAMS ((rtx
));
389 static void expand_delays
PARAMS ((void));
390 static rtx operate_exp
PARAMS ((enum operator, rtx
, rtx
));
391 static void expand_units
PARAMS ((void));
392 static rtx simplify_knowing
PARAMS ((rtx
, rtx
));
393 static rtx encode_units_mask
PARAMS ((rtx
));
394 static void fill_attr
PARAMS ((struct attr_desc
*));
395 static rtx substitute_address
PARAMS ((rtx
, rtx (*) (rtx
), rtx (*) (rtx
)));
396 static void make_length_attrs
PARAMS ((void));
397 static rtx identity_fn
PARAMS ((rtx
));
398 static rtx zero_fn
PARAMS ((rtx
));
399 static rtx one_fn
PARAMS ((rtx
));
400 static rtx max_fn
PARAMS ((rtx
));
401 static void write_length_unit_log
PARAMS ((void));
402 static rtx simplify_cond
PARAMS ((rtx
, int, int));
404 static rtx simplify_by_alternatives
PARAMS ((rtx
, int, int));
406 static rtx simplify_by_exploding
PARAMS ((rtx
));
407 static int find_and_mark_used_attributes
PARAMS ((rtx
, rtx
*, int *));
408 static void unmark_used_attributes
PARAMS ((rtx
, struct dimension
*, int));
409 static int add_values_to_cover
PARAMS ((struct dimension
*));
410 static int increment_current_value
PARAMS ((struct dimension
*, int));
411 static rtx test_for_current_value
PARAMS ((struct dimension
*, int));
412 static rtx simplify_with_current_value
PARAMS ((rtx
, struct dimension
*, int));
413 static rtx simplify_with_current_value_aux
PARAMS ((rtx
));
414 static void clear_struct_flag
PARAMS ((rtx
));
415 static int count_sub_rtxs
PARAMS ((rtx
, int));
416 static void remove_insn_ent
PARAMS ((struct attr_value
*, struct insn_ent
*));
417 static void insert_insn_ent
PARAMS ((struct attr_value
*, struct insn_ent
*));
418 static rtx insert_right_side
PARAMS ((enum rtx_code
, rtx
, rtx
, int, int));
419 static rtx make_alternative_compare
PARAMS ((int));
420 static int compute_alternative_mask
PARAMS ((rtx
, enum rtx_code
));
421 static rtx evaluate_eq_attr
PARAMS ((rtx
, rtx
, int, int));
422 static rtx simplify_and_tree
PARAMS ((rtx
, rtx
*, int, int));
423 static rtx simplify_or_tree
PARAMS ((rtx
, rtx
*, int, int));
424 static rtx simplify_test_exp
PARAMS ((rtx
, int, int));
425 static rtx simplify_test_exp_in_temp
PARAMS ((rtx
, int, int));
426 static void optimize_attrs
PARAMS ((void));
427 static void gen_attr
PARAMS ((rtx
, int));
428 static int count_alternatives
PARAMS ((rtx
));
429 static int compares_alternatives_p
PARAMS ((rtx
));
430 static int contained_in_p
PARAMS ((rtx
, rtx
));
431 static void gen_insn
PARAMS ((rtx
, int));
432 static void gen_delay
PARAMS ((rtx
, int));
433 static void gen_unit
PARAMS ((rtx
, int));
434 static void write_test_expr
PARAMS ((rtx
, int));
435 static int max_attr_value
PARAMS ((rtx
, int*));
436 static int or_attr_value
PARAMS ((rtx
, int*));
437 static void walk_attr_value
PARAMS ((rtx
));
438 static void write_attr_get
PARAMS ((struct attr_desc
*));
439 static rtx eliminate_known_true
PARAMS ((rtx
, rtx
, int, int));
440 static void write_attr_set
PARAMS ((struct attr_desc
*, int, rtx
,
441 const char *, const char *, rtx
,
443 static void write_attr_case
PARAMS ((struct attr_desc
*, struct attr_value
*,
444 int, const char *, const char *, int, rtx
));
445 static void write_unit_name
PARAMS ((const char *, int, const char *));
446 static void write_attr_valueq
PARAMS ((struct attr_desc
*, const char *));
447 static void write_attr_value
PARAMS ((struct attr_desc
*, rtx
));
448 static void write_upcase
PARAMS ((const char *));
449 static void write_indent
PARAMS ((int));
450 static void write_eligible_delay
PARAMS ((const char *));
451 static void write_function_unit_info
PARAMS ((void));
452 static void write_complex_function
PARAMS ((struct function_unit
*, const char *,
454 static int write_expr_attr_cache
PARAMS ((rtx
, struct attr_desc
*));
455 static void write_toplevel_expr
PARAMS ((rtx
));
456 static void write_const_num_delay_slots
PARAMS ((void));
457 static char *next_comma_elt
PARAMS ((const char **));
458 static struct attr_desc
*find_attr
PARAMS ((const char *, int));
459 static struct attr_value
*find_most_used
PARAMS ((struct attr_desc
*));
460 static rtx find_single_value
PARAMS ((struct attr_desc
*));
461 static void extend_range
PARAMS ((struct range
*, int, int));
462 static rtx attr_eq
PARAMS ((const char *, const char *));
463 static const char *attr_numeral
PARAMS ((int));
464 static int attr_equal_p
PARAMS ((rtx
, rtx
));
465 static rtx attr_copy_rtx
PARAMS ((rtx
));
466 static int attr_rtx_cost
PARAMS ((rtx
));
468 #define oballoc(size) obstack_alloc (hash_obstack, size)
470 /* Hash table for sharing RTL and strings. */
472 /* Each hash table slot is a bucket containing a chain of these structures.
473 Strings are given negative hash codes; RTL expressions are given positive
478 struct attr_hash
*next
; /* Next structure in the bucket. */
479 int hashcode
; /* Hash code of this rtx or string. */
482 char *str
; /* The string (negative hash codes) */
483 rtx rtl
; /* or the RTL recorded here. */
487 /* Now here is the hash table. When recording an RTL, it is added to
488 the slot whose index is the hash code mod the table size. Note
489 that the hash table is used for several kinds of RTL (see attr_rtx)
490 and for strings. While all these live in the same table, they are
491 completely independent, and the hash code is computed differently
494 #define RTL_HASH_SIZE 4093
495 struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
497 /* Here is how primitive or already-shared RTL's hash
499 #define RTL_HASH(RTL) ((long) (RTL) & 0777777)
501 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
504 attr_hash_add_rtx (hashcode
, rtl
)
510 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
511 sizeof (struct attr_hash
));
512 h
->hashcode
= hashcode
;
514 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
515 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
518 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
521 attr_hash_add_string (hashcode
, str
)
527 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
528 sizeof (struct attr_hash
));
529 h
->hashcode
= -hashcode
;
531 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
532 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
535 /* Generate an RTL expression, but avoid duplicates.
536 Set the ATTR_PERMANENT_P flag for these permanent objects.
538 In some cases we cannot uniquify; then we return an ordinary
539 impermanent rtx with ATTR_PERMANENT_P clear.
541 Args are like gen_rtx, but without the mode:
543 rtx attr_rtx (code, [element1, ..., elementn]) */
550 rtx rt_val
= NULL_RTX
;/* RTX to return to caller... */
553 struct obstack
*old_obstack
= rtl_obstack
;
555 /* For each of several cases, search the hash table for an existing entry.
556 Use that entry if one is found; otherwise create a new RTL and add it
559 if (GET_RTX_CLASS (code
) == '1')
561 rtx arg0
= va_arg (p
, rtx
);
563 /* A permanent object cannot point to impermanent ones. */
564 if (! ATTR_PERMANENT_P (arg0
))
566 rt_val
= rtx_alloc (code
);
567 XEXP (rt_val
, 0) = arg0
;
571 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
572 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
573 if (h
->hashcode
== hashcode
574 && GET_CODE (h
->u
.rtl
) == code
575 && XEXP (h
->u
.rtl
, 0) == arg0
)
580 rtl_obstack
= hash_obstack
;
581 rt_val
= rtx_alloc (code
);
582 XEXP (rt_val
, 0) = arg0
;
585 else if (GET_RTX_CLASS (code
) == 'c'
586 || GET_RTX_CLASS (code
) == '2'
587 || GET_RTX_CLASS (code
) == '<')
589 rtx arg0
= va_arg (p
, rtx
);
590 rtx arg1
= va_arg (p
, rtx
);
592 /* A permanent object cannot point to impermanent ones. */
593 if (! ATTR_PERMANENT_P (arg0
) || ! ATTR_PERMANENT_P (arg1
))
595 rt_val
= rtx_alloc (code
);
596 XEXP (rt_val
, 0) = arg0
;
597 XEXP (rt_val
, 1) = arg1
;
601 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
602 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
603 if (h
->hashcode
== hashcode
604 && GET_CODE (h
->u
.rtl
) == code
605 && XEXP (h
->u
.rtl
, 0) == arg0
606 && XEXP (h
->u
.rtl
, 1) == arg1
)
611 rtl_obstack
= hash_obstack
;
612 rt_val
= rtx_alloc (code
);
613 XEXP (rt_val
, 0) = arg0
;
614 XEXP (rt_val
, 1) = arg1
;
617 else if (GET_RTX_LENGTH (code
) == 1
618 && GET_RTX_FORMAT (code
)[0] == 's')
620 char *arg0
= va_arg (p
, char *);
622 if (code
== SYMBOL_REF
)
623 arg0
= attr_string (arg0
, strlen (arg0
));
625 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
626 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
627 if (h
->hashcode
== hashcode
628 && GET_CODE (h
->u
.rtl
) == code
629 && XSTR (h
->u
.rtl
, 0) == arg0
)
634 rtl_obstack
= hash_obstack
;
635 rt_val
= rtx_alloc (code
);
636 XSTR (rt_val
, 0) = arg0
;
639 else if (GET_RTX_LENGTH (code
) == 2
640 && GET_RTX_FORMAT (code
)[0] == 's'
641 && GET_RTX_FORMAT (code
)[1] == 's')
643 char *arg0
= va_arg (p
, char *);
644 char *arg1
= va_arg (p
, char *);
646 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
647 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
648 if (h
->hashcode
== hashcode
649 && GET_CODE (h
->u
.rtl
) == code
650 && XSTR (h
->u
.rtl
, 0) == arg0
651 && XSTR (h
->u
.rtl
, 1) == arg1
)
656 rtl_obstack
= hash_obstack
;
657 rt_val
= rtx_alloc (code
);
658 XSTR (rt_val
, 0) = arg0
;
659 XSTR (rt_val
, 1) = arg1
;
662 else if (code
== CONST_INT
)
664 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
674 int i
; /* Array indices... */
675 const char *fmt
; /* Current rtx's format... */
677 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
679 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
680 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
684 case '0': /* Unused field. */
687 case 'i': /* An integer? */
688 XINT (rt_val
, i
) = va_arg (p
, int);
691 case 'w': /* A wide integer? */
692 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
695 case 's': /* A string? */
696 XSTR (rt_val
, i
) = va_arg (p
, char *);
699 case 'e': /* An expression? */
700 case 'u': /* An insn? Same except when printing. */
701 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
704 case 'E': /* An RTX vector? */
705 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
715 rtl_obstack
= old_obstack
;
716 attr_hash_add_rtx (hashcode
, rt_val
);
717 ATTR_PERMANENT_P (rt_val
) = 1;
722 attr_rtx
VPARAMS ((enum rtx_code code
, ...))
727 VA_FIXEDARG (p
, enum rtx_code
, code
);
728 result
= attr_rtx_1 (code
, p
);
733 /* Create a new string printed with the printf line arguments into a space
734 of at most LEN bytes:
736 rtx attr_printf (len, format, [arg1, ..., argn]) */
739 attr_printf
VPARAMS ((unsigned int len
, const char *fmt
, ...))
744 VA_FIXEDARG (p
, unsigned int, len
);
745 VA_FIXEDARG (p
, const char *, fmt
);
747 if (len
> sizeof str
- 1) /* Leave room for \0. */
750 vsprintf (str
, fmt
, p
);
753 return attr_string (str
, strlen (str
));
757 attr_eq (name
, value
)
758 const char *name
, *value
;
760 return attr_rtx (EQ_ATTR
, attr_string (name
, strlen (name
)),
761 attr_string (value
, strlen (value
)));
768 return XSTR (make_numeric_value (n
), 0);
771 /* Return a permanent (possibly shared) copy of a string STR (not assumed
772 to be null terminated) with LEN bytes. */
775 attr_string (str
, len
)
784 /* Compute the hash code. */
785 hashcode
= (len
+ 1) * 613 + (unsigned) str
[0];
786 for (i
= 1; i
<= len
; i
+= 2)
787 hashcode
= ((hashcode
* 613) + (unsigned) str
[i
]);
789 hashcode
= -hashcode
;
791 /* Search the table for the string. */
792 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
793 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
794 && !strncmp (h
->u
.str
, str
, len
))
795 return h
->u
.str
; /* <-- return if found. */
797 /* Not found; create a permanent copy and add it to the hash table. */
798 new_str
= (char *) obstack_alloc (hash_obstack
, len
+ 1);
799 memcpy (new_str
, str
, len
);
801 attr_hash_add_string (hashcode
, new_str
);
803 return new_str
; /* Return the new string. */
806 /* Check two rtx's for equality of contents,
807 taking advantage of the fact that if both are hashed
808 then they can't be equal unless they are the same object. */
814 return (x
== y
|| (! (ATTR_PERMANENT_P (x
) && ATTR_PERMANENT_P (y
))
815 && rtx_equal_p (x
, y
)));
818 /* Copy an attribute value expression,
819 descending to all depths, but not copying any
820 permanent hashed subexpressions. */
829 const char *format_ptr
;
831 /* No need to copy a permanent object. */
832 if (ATTR_PERMANENT_P (orig
))
835 code
= GET_CODE (orig
);
854 copy
= rtx_alloc (code
);
855 PUT_MODE (copy
, GET_MODE (orig
));
856 ATTR_IND_SIMPLIFIED_P (copy
) = ATTR_IND_SIMPLIFIED_P (orig
);
857 ATTR_CURR_SIMPLIFIED_P (copy
) = ATTR_CURR_SIMPLIFIED_P (orig
);
858 ATTR_PERMANENT_P (copy
) = ATTR_PERMANENT_P (orig
);
859 ATTR_EQ_ATTR_P (copy
) = ATTR_EQ_ATTR_P (orig
);
861 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
863 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
865 switch (*format_ptr
++)
868 XEXP (copy
, i
) = XEXP (orig
, i
);
869 if (XEXP (orig
, i
) != NULL
)
870 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
875 XVEC (copy
, i
) = XVEC (orig
, i
);
876 if (XVEC (orig
, i
) != NULL
)
878 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
879 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
880 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
886 XINT (copy
, i
) = XINT (orig
, i
);
890 XWINT (copy
, i
) = XWINT (orig
, i
);
895 XSTR (copy
, i
) = XSTR (orig
, i
);
905 /* Given a test expression for an attribute, ensure it is validly formed.
906 IS_CONST indicates whether the expression is constant for each compiler
907 run (a constant expression may not test any particular insn).
909 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
910 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
911 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
913 Update the string address in EQ_ATTR expression to be the same used
914 in the attribute (or `alternative_name') to speed up subsequent
915 `find_attr' calls and eliminate most `strcmp' calls.
917 Return the new expression, if any. */
920 check_attr_test (exp
, is_const
, lineno
)
925 struct attr_desc
*attr
;
926 struct attr_value
*av
;
927 const char *name_ptr
, *p
;
930 switch (GET_CODE (exp
))
933 /* Handle negation test. */
934 if (XSTR (exp
, 1)[0] == '!')
935 return check_attr_test (attr_rtx (NOT
,
936 attr_eq (XSTR (exp
, 0),
940 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
942 attr
= find_attr (XSTR (exp
, 0), 0);
945 if (! strcmp (XSTR (exp
, 0), "alternative"))
947 XSTR (exp
, 0) = alternative_name
;
948 /* This can't be simplified any further. */
949 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
953 fatal ("unknown attribute `%s' in EQ_ATTR", XSTR (exp
, 0));
956 if (is_const
&& ! attr
->is_const
)
957 fatal ("constant expression uses insn attribute `%s' in EQ_ATTR",
960 /* Copy this just to make it permanent,
961 so expressions using it can be permanent too. */
962 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
964 /* It shouldn't be possible to simplify the value given to a
965 constant attribute, so don't expand this until it's time to
966 write the test expression. */
968 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
970 if (attr
->is_numeric
)
972 for (p
= XSTR (exp
, 1); *p
; p
++)
974 fatal ("attribute `%s' takes only numeric values",
979 for (av
= attr
->first_value
; av
; av
= av
->next
)
980 if (GET_CODE (av
->value
) == CONST_STRING
981 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
985 fatal ("unknown value `%s' for `%s' attribute",
986 XSTR (exp
, 1), XSTR (exp
, 0));
991 /* Make an IOR tree of the possible values. */
993 name_ptr
= XSTR (exp
, 1);
994 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
996 newexp
= attr_eq (XSTR (exp
, 0), p
);
997 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
1000 return check_attr_test (orexp
, is_const
, lineno
);
1008 /* Either TRUE or FALSE. */
1016 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
1017 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
, lineno
);
1021 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
1027 fatal ("RTL operator \"%s\" not valid in constant attribute test",
1028 GET_RTX_NAME (GET_CODE (exp
)));
1029 /* These cases can't be simplified. */
1030 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1033 case LE
: case LT
: case GT
: case GE
:
1034 case LEU
: case LTU
: case GTU
: case GEU
:
1036 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
1037 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
1038 exp
= attr_rtx (GET_CODE (exp
),
1039 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
1040 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
1041 /* These cases can't be simplified. */
1042 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1048 /* These cases are valid for constant attributes, but can't be
1050 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1051 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1055 fatal ("RTL operator \"%s\" not valid in attribute test",
1056 GET_RTX_NAME (GET_CODE (exp
)));
1062 /* Given an expression, ensure that it is validly formed and that all named
1063 attribute values are valid for the given attribute. Issue a fatal error
1064 if not. If no attribute is specified, assume a numeric attribute.
1066 Return a perhaps modified replacement expression for the value. */
1069 check_attr_value (exp
, attr
)
1071 struct attr_desc
*attr
;
1073 struct attr_value
*av
;
1077 switch (GET_CODE (exp
))
1080 if (attr
&& ! attr
->is_numeric
)
1082 message_with_line (attr
->lineno
,
1083 "CONST_INT not valid for non-numeric attribute %s",
1089 if (INTVAL (exp
) < 0 && ! attr
->negative_ok
)
1091 message_with_line (attr
->lineno
,
1092 "negative numeric value specified for attribute %s",
1100 if (! strcmp (XSTR (exp
, 0), "*"))
1103 if (attr
== 0 || attr
->is_numeric
)
1106 if (attr
&& attr
->negative_ok
&& *p
== '-')
1111 message_with_line (attr
? attr
->lineno
: 0,
1112 "non-numeric value for numeric attribute %s",
1113 attr
? attr
->name
: "internal");
1120 for (av
= attr
->first_value
; av
; av
= av
->next
)
1121 if (GET_CODE (av
->value
) == CONST_STRING
1122 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
1127 message_with_line (attr
->lineno
,
1128 "unknown value `%s' for `%s' attribute",
1129 XSTR (exp
, 0), attr
? attr
->name
: "internal");
1135 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
1136 attr
? attr
->is_const
: 0,
1137 attr
? attr
->lineno
: 0);
1138 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1139 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
1147 if (attr
&& !attr
->is_numeric
)
1149 message_with_line (attr
->lineno
,
1150 "invalid operation `%s' for non-numeric attribute value",
1151 GET_RTX_NAME (GET_CODE (exp
)));
1159 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1160 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1164 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1168 if (XVECLEN (exp
, 0) % 2 != 0)
1170 message_with_line (attr
->lineno
,
1171 "first operand of COND must have even length");
1176 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1178 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1179 attr
? attr
->is_const
: 0,
1180 attr
? attr
->lineno
: 0);
1181 XVECEXP (exp
, 0, i
+ 1)
1182 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1185 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1190 struct attr_desc
*attr2
= find_attr (XSTR (exp
, 0), 0);
1193 message_with_line (attr
? attr
->lineno
: 0,
1194 "unknown attribute `%s' in ATTR",
1198 else if (attr
&& attr
->is_const
&& ! attr2
->is_const
)
1200 message_with_line (attr
->lineno
,
1201 "non-constant attribute `%s' referenced from `%s'",
1202 XSTR (exp
, 0), attr
->name
);
1206 && (attr
->is_numeric
!= attr2
->is_numeric
1207 || (! attr
->negative_ok
&& attr2
->negative_ok
)))
1209 message_with_line (attr
->lineno
,
1210 "numeric attribute mismatch calling `%s' from `%s'",
1211 XSTR (exp
, 0), attr
->name
);
1218 /* A constant SYMBOL_REF is valid as a constant attribute test and
1219 is expanded later by make_canonical into a COND. In a non-constant
1220 attribute test, it is left be. */
1221 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1224 message_with_line (attr
? attr
->lineno
: 0,
1225 "invalid operation `%s' for attribute value",
1226 GET_RTX_NAME (GET_CODE (exp
)));
1234 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1235 It becomes a COND with each test being (eq_attr "alternative "n") */
1238 convert_set_attr_alternative (exp
, id
)
1240 struct insn_def
*id
;
1242 int num_alt
= id
->num_alternatives
;
1246 if (XVECLEN (exp
, 1) != num_alt
)
1248 message_with_line (id
->lineno
,
1249 "bad number of entries in SET_ATTR_ALTERNATIVE");
1254 /* Make a COND with all tests but the last. Select the last value via the
1256 condexp
= rtx_alloc (COND
);
1257 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1259 for (i
= 0; i
< num_alt
- 1; i
++)
1262 p
= attr_numeral (i
);
1264 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1265 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1268 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1270 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1273 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1274 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1277 convert_set_attr (exp
, id
)
1279 struct insn_def
*id
;
1282 const char *name_ptr
;
1286 /* See how many alternative specified. */
1287 n
= n_comma_elts (XSTR (exp
, 1));
1289 return attr_rtx (SET
,
1290 attr_rtx (ATTR
, XSTR (exp
, 0)),
1291 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1293 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1294 XSTR (newexp
, 0) = XSTR (exp
, 0);
1295 XVEC (newexp
, 1) = rtvec_alloc (n
);
1297 /* Process each comma-separated name. */
1298 name_ptr
= XSTR (exp
, 1);
1300 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1301 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1303 return convert_set_attr_alternative (newexp
, id
);
1306 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1307 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1313 struct insn_def
*id
;
1314 struct attr_desc
*attr
;
1318 for (id
= defs
; id
; id
= id
->next
)
1320 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1323 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1325 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1326 switch (GET_CODE (value
))
1329 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1331 message_with_line (id
->lineno
, "bad attribute set");
1337 case SET_ATTR_ALTERNATIVE
:
1338 value
= convert_set_attr_alternative (value
, id
);
1342 value
= convert_set_attr (value
, id
);
1346 message_with_line (id
->lineno
, "invalid attribute code %s",
1347 GET_RTX_NAME (GET_CODE (value
)));
1351 if (value
== NULL_RTX
)
1354 if ((attr
= find_attr (XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1356 message_with_line (id
->lineno
, "unknown attribute %s",
1357 XSTR (XEXP (value
, 0), 0));
1362 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1363 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1369 /* Given a constant SYMBOL_REF expression, convert to a COND that
1370 explicitly tests each enumerated value. */
1373 convert_const_symbol_ref (exp
, attr
)
1375 struct attr_desc
*attr
;
1378 struct attr_value
*av
;
1382 for (av
= attr
->first_value
; av
; av
= av
->next
)
1385 /* Make a COND with all tests but the last, and in the original order.
1386 Select the last value via the default. Note that the attr values
1387 are constructed in reverse order. */
1389 condexp
= rtx_alloc (COND
);
1390 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1391 av
= attr
->first_value
;
1392 XEXP (condexp
, 1) = av
->value
;
1394 for (i
= num_alt
- 2; av
= av
->next
, i
>= 0; i
--)
1399 string
= p
= (char *) oballoc (2
1400 + strlen (attr
->name
)
1401 + strlen (XSTR (av
->value
, 0)));
1402 strcpy (p
, attr
->name
);
1404 strcat (p
, XSTR (av
->value
, 0));
1405 for (; *p
!= '\0'; p
++)
1408 value
= attr_rtx (SYMBOL_REF
, string
);
1409 ATTR_IND_SIMPLIFIED_P (value
) = 1;
1411 XVECEXP (condexp
, 0, 2 * i
) = attr_rtx (EQ
, exp
, value
);
1413 XVECEXP (condexp
, 0, 2 * i
+ 1) = av
->value
;
1420 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1421 expressions by converting them into a COND. This removes cases from this
1422 program. Also, replace an attribute value of "*" with the default attribute
1426 make_canonical (attr
, exp
)
1427 struct attr_desc
*attr
;
1433 switch (GET_CODE (exp
))
1436 exp
= make_numeric_value (INTVAL (exp
));
1440 if (! strcmp (XSTR (exp
, 0), "*"))
1442 if (attr
== 0 || attr
->default_val
== 0)
1443 fatal ("(attr_value \"*\") used in invalid context");
1444 exp
= attr
->default_val
->value
;
1450 if (!attr
->is_const
|| ATTR_IND_SIMPLIFIED_P (exp
))
1452 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1453 This makes the COND something that won't be considered an arbitrary
1454 expression by walk_attr_value. */
1455 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1457 /* ??? Why do we do this? With attribute values { A B C D E }, this
1458 tends to generate (!(x==A) && !(x==B) && !(x==C) && !(x==D)) rather
1460 exp
= convert_const_symbol_ref (exp
, attr
);
1461 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1462 exp
= check_attr_value (exp
, attr
);
1463 /* Goto COND case since this is now a COND. Note that while the
1464 new expression is rescanned, all symbol_ref notes are marked as
1468 exp
= check_attr_value (exp
, attr
);
1473 newexp
= rtx_alloc (COND
);
1474 XVEC (newexp
, 0) = rtvec_alloc (2);
1475 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1476 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1478 XEXP (newexp
, 1) = XEXP (exp
, 2);
1481 /* Fall through to COND case since this is now a COND. */
1488 /* First, check for degenerate COND. */
1489 if (XVECLEN (exp
, 0) == 0)
1490 return make_canonical (attr
, XEXP (exp
, 1));
1491 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1493 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1495 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1496 XVECEXP (exp
, 0, i
+ 1)
1497 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1498 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1517 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1518 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1519 copy_boolean (XEXP (exp
, 1)));
1523 /* Given a value and an attribute description, return a `struct attr_value *'
1524 that represents that value. This is either an existing structure, if the
1525 value has been previously encountered, or a newly-created structure.
1527 `insn_code' is the code of an insn whose attribute has the specified
1528 value (-2 if not processing an insn). We ensure that all insns for
1529 a given value have the same number of alternatives if the value checks
1532 static struct attr_value
*
1533 get_attr_value (value
, attr
, insn_code
)
1535 struct attr_desc
*attr
;
1538 struct attr_value
*av
;
1541 value
= make_canonical (attr
, value
);
1542 if (compares_alternatives_p (value
))
1544 if (insn_code
< 0 || insn_alternatives
== NULL
)
1545 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1547 num_alt
= insn_alternatives
[insn_code
];
1550 for (av
= attr
->first_value
; av
; av
= av
->next
)
1551 if (rtx_equal_p (value
, av
->value
)
1552 && (num_alt
== 0 || av
->first_insn
== NULL
1553 || insn_alternatives
[av
->first_insn
->insn_code
]))
1556 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
1558 av
->next
= attr
->first_value
;
1559 attr
->first_value
= av
;
1560 av
->first_insn
= NULL
;
1562 av
->has_asm_insn
= 0;
1567 /* After all DEFINE_DELAYs have been read in, create internal attributes
1568 to generate the required routines.
1570 First, we compute the number of delay slots for each insn (as a COND of
1571 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1572 delay type is specified, we compute a similar function giving the
1573 DEFINE_DELAY ordinal for each insn.
1575 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1576 tells whether a given insn can be in that delay slot.
1578 Normal attribute filling and optimization expands these to contain the
1579 information needed to handle delay slots. */
1584 struct delay_desc
*delay
;
1590 /* First, generate data for `num_delay_slots' function. */
1592 condexp
= rtx_alloc (COND
);
1593 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1594 XEXP (condexp
, 1) = make_numeric_value (0);
1596 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1598 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1599 XVECEXP (condexp
, 0, i
+ 1)
1600 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1603 make_internal_attr ("*num_delay_slots", condexp
, 0);
1605 /* If more than one delay type, do the same for computing the delay type. */
1608 condexp
= rtx_alloc (COND
);
1609 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1610 XEXP (condexp
, 1) = make_numeric_value (0);
1612 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1614 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1615 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1618 make_internal_attr ("*delay_type", condexp
, 1);
1621 /* For each delay possibility and delay slot, compute an eligibility
1622 attribute for non-annulled insns and for each type of annulled (annul
1623 if true and annul if false). */
1624 for (delay
= delays
; delay
; delay
= delay
->next
)
1626 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1628 condexp
= XVECEXP (delay
->def
, 1, i
);
1630 condexp
= false_rtx
;
1631 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1632 make_numeric_value (1), make_numeric_value (0));
1634 p
= attr_printf (sizeof "*delay__" + MAX_DIGITS
* 2,
1635 "*delay_%d_%d", delay
->num
, i
/ 3);
1636 make_internal_attr (p
, newexp
, 1);
1638 if (have_annul_true
)
1640 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1641 if (condexp
== 0) condexp
= false_rtx
;
1642 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1643 make_numeric_value (1),
1644 make_numeric_value (0));
1645 p
= attr_printf (sizeof "*annul_true__" + MAX_DIGITS
* 2,
1646 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1647 make_internal_attr (p
, newexp
, 1);
1650 if (have_annul_false
)
1652 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1653 if (condexp
== 0) condexp
= false_rtx
;
1654 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1655 make_numeric_value (1),
1656 make_numeric_value (0));
1657 p
= attr_printf (sizeof "*annul_false__" + MAX_DIGITS
* 2,
1658 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1659 make_internal_attr (p
, newexp
, 1);
1665 /* This function is given a left and right side expression and an operator.
1666 Each side is a conditional expression, each alternative of which has a
1667 numerical value. The function returns another conditional expression
1668 which, for every possible set of condition values, returns a value that is
1669 the operator applied to the values of the two sides.
1671 Since this is called early, it must also support IF_THEN_ELSE. */
1674 operate_exp (op
, left
, right
)
1678 int left_value
, right_value
;
1682 /* If left is a string, apply operator to it and the right side. */
1683 if (GET_CODE (left
) == CONST_STRING
)
1685 /* If right is also a string, just perform the operation. */
1686 if (GET_CODE (right
) == CONST_STRING
)
1688 left_value
= atoi (XSTR (left
, 0));
1689 right_value
= atoi (XSTR (right
, 0));
1693 i
= left_value
+ right_value
;
1697 i
= left_value
- right_value
;
1700 case POS_MINUS_OP
: /* The positive part of LEFT - RIGHT. */
1701 if (left_value
> right_value
)
1702 i
= left_value
- right_value
;
1709 i
= left_value
| right_value
;
1713 i
= left_value
== right_value
;
1717 i
= (left_value
<< (HOST_BITS_PER_INT
/ 2)) | right_value
;
1721 if (left_value
> right_value
)
1728 if (left_value
< right_value
)
1738 if (i
== left_value
)
1740 if (i
== right_value
)
1742 return make_numeric_value (i
);
1744 else if (GET_CODE (right
) == IF_THEN_ELSE
)
1746 /* Apply recursively to all values within. */
1747 rtx newleft
= operate_exp (op
, left
, XEXP (right
, 1));
1748 rtx newright
= operate_exp (op
, left
, XEXP (right
, 2));
1749 if (rtx_equal_p (newleft
, newright
))
1751 return attr_rtx (IF_THEN_ELSE
, XEXP (right
, 0), newleft
, newright
);
1753 else if (GET_CODE (right
) == COND
)
1758 newexp
= rtx_alloc (COND
);
1759 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (right
, 0));
1760 defval
= XEXP (newexp
, 1) = operate_exp (op
, left
, XEXP (right
, 1));
1762 for (i
= 0; i
< XVECLEN (right
, 0); i
+= 2)
1764 XVECEXP (newexp
, 0, i
) = XVECEXP (right
, 0, i
);
1765 XVECEXP (newexp
, 0, i
+ 1)
1766 = operate_exp (op
, left
, XVECEXP (right
, 0, i
+ 1));
1767 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1772 /* If the resulting cond is trivial (all alternatives
1773 give the same value), optimize it away. */
1775 return operate_exp (op
, left
, XEXP (right
, 1));
1780 fatal ("badly formed attribute value");
1783 /* A hack to prevent expand_units from completely blowing up: ORX_OP does
1784 not associate through IF_THEN_ELSE. */
1785 else if (op
== ORX_OP
&& GET_CODE (right
) == IF_THEN_ELSE
)
1787 return attr_rtx (IOR
, left
, right
);
1790 /* Otherwise, do recursion the other way. */
1791 else if (GET_CODE (left
) == IF_THEN_ELSE
)
1793 rtx newleft
= operate_exp (op
, XEXP (left
, 1), right
);
1794 rtx newright
= operate_exp (op
, XEXP (left
, 2), right
);
1795 if (rtx_equal_p (newleft
, newright
))
1797 return attr_rtx (IF_THEN_ELSE
, XEXP (left
, 0), newleft
, newright
);
1799 else if (GET_CODE (left
) == COND
)
1804 newexp
= rtx_alloc (COND
);
1805 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (left
, 0));
1806 defval
= XEXP (newexp
, 1) = operate_exp (op
, XEXP (left
, 1), right
);
1808 for (i
= 0; i
< XVECLEN (left
, 0); i
+= 2)
1810 XVECEXP (newexp
, 0, i
) = XVECEXP (left
, 0, i
);
1811 XVECEXP (newexp
, 0, i
+ 1)
1812 = operate_exp (op
, XVECEXP (left
, 0, i
+ 1), right
);
1813 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1818 /* If the cond is trivial (all alternatives give the same value),
1819 optimize it away. */
1821 return operate_exp (op
, XEXP (left
, 1), right
);
1823 /* If the result is the same as the LEFT operand,
1825 if (rtx_equal_p (newexp
, left
))
1832 fatal ("badly formed attribute value");
1837 /* Once all attributes and DEFINE_FUNCTION_UNITs have been read, we
1838 construct a number of attributes.
1840 The first produces a function `function_units_used' which is given an
1841 insn and produces an encoding showing which function units are required
1842 for the execution of that insn. If the value is non-negative, the insn
1843 uses that unit; otherwise, the value is a one's complement mask of units
1846 The second produces a function `result_ready_cost' which is used to
1847 determine the time that the result of an insn will be ready and hence
1848 a worst-case schedule.
1850 Both of these produce quite complex expressions which are then set as the
1851 default value of internal attributes. Normal attribute simplification
1852 should produce reasonable expressions.
1854 For each unit, a `<name>_unit_ready_cost' function will take an
1855 insn and give the delay until that unit will be ready with the result
1856 and a `<name>_unit_conflict_cost' function is given an insn already
1857 executing on the unit and a candidate to execute and will give the
1858 cost from the time the executing insn started until the candidate
1859 can start (ignore limitations on the number of simultaneous insns).
1861 For each unit, a `<name>_unit_blockage' function is given an insn
1862 already executing on the unit and a candidate to execute and will
1863 give the delay incurred due to function unit conflicts. The range of
1864 blockage cost values for a given executing insn is given by the
1865 `<name>_unit_blockage_range' function. These values are encoded in
1866 an int where the upper half gives the minimum value and the lower
1867 half gives the maximum value. */
1872 struct function_unit
*unit
, **unit_num
;
1873 struct function_unit_op
*op
, **op_array
, ***unit_ops
;
1878 int i
, j
, u
, num
, nvalues
;
1880 /* Rebuild the condition for the unit to share the RTL expressions.
1881 Sharing is required by simplify_by_exploding. Build the issue delay
1882 expressions. Validate the expressions we were given for the conditions
1883 and conflict vector. Then make attributes for use in the conflict
1886 for (unit
= units
; unit
; unit
= unit
->next
)
1888 unit
->condexp
= check_attr_test (unit
->condexp
, 0, unit
->first_lineno
);
1890 for (op
= unit
->ops
; op
; op
= op
->next
)
1892 rtx issue_delay
= make_numeric_value (op
->issue_delay
);
1893 rtx issue_exp
= issue_delay
;
1895 /* Build, validate, and simplify the issue delay expression. */
1896 if (op
->conflict_exp
!= true_rtx
)
1897 issue_exp
= attr_rtx (IF_THEN_ELSE
, op
->conflict_exp
,
1898 issue_exp
, make_numeric_value (0));
1899 issue_exp
= check_attr_value (make_canonical (NULL_ATTR
,
1902 issue_exp
= simplify_knowing (issue_exp
, unit
->condexp
);
1903 op
->issue_exp
= issue_exp
;
1905 /* Make an attribute for use in the conflict function if needed. */
1906 unit
->needs_conflict_function
= (unit
->issue_delay
.min
1907 != unit
->issue_delay
.max
);
1908 if (unit
->needs_conflict_function
)
1910 str
= attr_printf ((strlen (unit
->name
) + sizeof "*_cost_"
1912 "*%s_cost_%d", unit
->name
, op
->num
);
1913 make_internal_attr (str
, issue_exp
, 1);
1916 /* Validate the condition. */
1917 op
->condexp
= check_attr_test (op
->condexp
, 0, op
->lineno
);
1921 /* Compute the mask of function units used. Initially, the unitsmask is
1922 zero. Set up a conditional to compute each unit's contribution. */
1923 unitsmask
= make_numeric_value (0);
1924 newexp
= rtx_alloc (IF_THEN_ELSE
);
1925 XEXP (newexp
, 2) = make_numeric_value (0);
1927 /* If we have just a few units, we may be all right expanding the whole
1928 thing. But the expansion is 2**N in space on the number of opclasses,
1929 so we can't do this for very long -- Alpha and MIPS in particular have
1930 problems with this. So in that situation, we fall back on an alternate
1931 implementation method. */
1932 #define NUM_UNITOP_CUTOFF 20
1934 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1936 /* Merge each function unit into the unit mask attributes. */
1937 for (unit
= units
; unit
; unit
= unit
->next
)
1939 XEXP (newexp
, 0) = unit
->condexp
;
1940 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1941 unitsmask
= operate_exp (OR_OP
, unitsmask
, newexp
);
1946 /* Merge each function unit into the unit mask attributes. */
1947 for (unit
= units
; unit
; unit
= unit
->next
)
1949 XEXP (newexp
, 0) = unit
->condexp
;
1950 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1951 unitsmask
= operate_exp (ORX_OP
, unitsmask
, attr_copy_rtx (newexp
));
1955 /* Simplify the unit mask expression, encode it, and make an attribute
1956 for the function_units_used function. */
1957 unitsmask
= simplify_by_exploding (unitsmask
);
1959 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1960 unitsmask
= encode_units_mask (unitsmask
);
1963 /* We can no longer encode unitsmask at compile time, so emit code to
1964 calculate it at runtime. Rather, put a marker for where we'd do
1965 the code, and actually output it in write_attr_get(). */
1966 unitsmask
= attr_rtx (FFS
, unitsmask
);
1969 make_internal_attr ("*function_units_used", unitsmask
, 10);
1971 /* Create an array of ops for each unit. Add an extra unit for the
1972 result_ready_cost function that has the ops of all other units. */
1973 unit_ops
= (struct function_unit_op
***)
1974 xmalloc ((num_units
+ 1) * sizeof (struct function_unit_op
**));
1975 unit_num
= (struct function_unit
**)
1976 xmalloc ((num_units
+ 1) * sizeof (struct function_unit
*));
1978 unit_num
[num_units
] = unit
= (struct function_unit
*)
1979 xmalloc (sizeof (struct function_unit
));
1980 unit
->num
= num_units
;
1981 unit
->num_opclasses
= 0;
1983 for (unit
= units
; unit
; unit
= unit
->next
)
1985 unit_num
[num_units
]->num_opclasses
+= unit
->num_opclasses
;
1986 unit_num
[unit
->num
] = unit
;
1987 unit_ops
[unit
->num
] = op_array
= (struct function_unit_op
**)
1988 xmalloc (unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1990 for (op
= unit
->ops
; op
; op
= op
->next
)
1991 op_array
[op
->num
] = op
;
1994 /* Compose the array of ops for the extra unit. */
1995 unit_ops
[num_units
] = op_array
= (struct function_unit_op
**)
1996 xmalloc (unit_num
[num_units
]->num_opclasses
1997 * sizeof (struct function_unit_op
*));
1999 for (unit
= units
, i
= 0; unit
; i
+= unit
->num_opclasses
, unit
= unit
->next
)
2000 memcpy (&op_array
[i
], unit_ops
[unit
->num
],
2001 unit
->num_opclasses
* sizeof (struct function_unit_op
*));
2003 /* Compute the ready cost function for each unit by computing the
2004 condition for each non-default value. */
2005 for (u
= 0; u
<= num_units
; u
++)
2011 op_array
= unit_ops
[unit
->num
];
2012 num
= unit
->num_opclasses
;
2014 /* Sort the array of ops into increasing ready cost order. */
2015 for (i
= 0; i
< num
; i
++)
2016 for (j
= num
- 1; j
> i
; j
--)
2017 if (op_array
[j
- 1]->ready
< op_array
[j
]->ready
)
2020 op_array
[j
] = op_array
[j
- 1];
2021 op_array
[j
- 1] = op
;
2024 /* Determine how many distinct non-default ready cost values there
2025 are. We use a default ready cost value of 1. */
2026 nvalues
= 0; value
= 1;
2027 for (i
= num
- 1; i
>= 0; i
--)
2028 if (op_array
[i
]->ready
> value
)
2030 value
= op_array
[i
]->ready
;
2035 readycost
= make_numeric_value (1);
2038 /* Construct the ready cost expression as a COND of each value from
2039 the largest to the smallest. */
2040 readycost
= rtx_alloc (COND
);
2041 XVEC (readycost
, 0) = rtvec_alloc (nvalues
* 2);
2042 XEXP (readycost
, 1) = make_numeric_value (1);
2046 value
= op_array
[0]->ready
;
2047 for (i
= 0; i
< num
; i
++)
2052 else if (op
->ready
== value
)
2053 orexp
= insert_right_side (IOR
, orexp
, op
->condexp
, -2, -2);
2056 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
2057 XVECEXP (readycost
, 0, nvalues
* 2 + 1)
2058 = make_numeric_value (value
);
2061 orexp
= op
->condexp
;
2064 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
2065 XVECEXP (readycost
, 0, nvalues
* 2 + 1) = make_numeric_value (value
);
2070 rtx max_blockage
= 0, min_blockage
= 0;
2072 /* Simplify the readycost expression by only considering insns
2073 that use the unit. */
2074 readycost
= simplify_knowing (readycost
, unit
->condexp
);
2076 /* Determine the blockage cost the executing insn (E) given
2077 the candidate insn (C). This is the maximum of the issue
2078 delay, the pipeline delay, and the simultaneity constraint.
2079 Each function_unit_op represents the characteristics of the
2080 candidate insn, so in the expressions below, C is a known
2081 term and E is an unknown term.
2083 We compute the blockage cost for each E for every possible C.
2084 Thus OP represents E, and READYCOST is a list of values for
2087 The issue delay function for C is op->issue_exp and is used to
2088 write the `<name>_unit_conflict_cost' function. Symbolicly
2089 this is "ISSUE-DELAY (E,C)".
2091 The pipeline delay results form the FIFO constraint on the
2092 function unit and is "READY-COST (E) + 1 - READY-COST (C)".
2094 The simultaneity constraint is based on how long it takes to
2095 fill the unit given the minimum issue delay. FILL-TIME is the
2096 constant "MIN (ISSUE-DELAY (*,*)) * (SIMULTANEITY - 1)", and
2097 the simultaneity constraint is "READY-COST (E) - FILL-TIME"
2098 if SIMULTANEITY is nonzero and zero otherwise.
2100 Thus, BLOCKAGE (E,C) when SIMULTANEITY is zero is
2102 MAX (ISSUE-DELAY (E,C),
2103 READY-COST (E) - (READY-COST (C) - 1))
2107 MAX (ISSUE-DELAY (E,C),
2108 READY-COST (E) - (READY-COST (C) - 1),
2109 READY-COST (E) - FILL-TIME)
2111 The `<name>_unit_blockage' function is computed by determining
2112 this value for each candidate insn. As these values are
2113 computed, we also compute the upper and lower bounds for
2114 BLOCKAGE (E,*). These are combined to form the function
2115 `<name>_unit_blockage_range'. Finally, the maximum blockage
2116 cost, MAX (BLOCKAGE (*,*)), is computed. */
2118 for (op
= unit
->ops
; op
; op
= op
->next
)
2120 rtx blockage
= op
->issue_exp
;
2121 blockage
= simplify_knowing (blockage
, unit
->condexp
);
2123 /* Add this op's contribution to MAX (BLOCKAGE (E,*)) and
2124 MIN (BLOCKAGE (E,*)). */
2125 if (max_blockage
== 0)
2126 max_blockage
= min_blockage
= blockage
;
2130 = simplify_knowing (operate_exp (MAX_OP
, max_blockage
,
2134 = simplify_knowing (operate_exp (MIN_OP
, min_blockage
,
2139 /* Make an attribute for use in the blockage function. */
2140 str
= attr_printf ((strlen (unit
->name
) + sizeof "*_block_"
2142 "*%s_block_%d", unit
->name
, op
->num
);
2143 make_internal_attr (str
, blockage
, 1);
2146 /* Record MAX (BLOCKAGE (*,*)). */
2149 unit
->max_blockage
= max_attr_value (max_blockage
, &unknown
);
2152 /* See if the upper and lower bounds of BLOCKAGE (E,*) are the
2153 same. If so, the blockage function carries no additional
2154 information and is not written. */
2155 newexp
= operate_exp (EQ_OP
, max_blockage
, min_blockage
);
2156 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2157 unit
->needs_blockage_function
2158 = (GET_CODE (newexp
) != CONST_STRING
2159 || atoi (XSTR (newexp
, 0)) != 1);
2161 /* If the all values of BLOCKAGE (E,C) have the same value,
2162 neither blockage function is written. */
2163 unit
->needs_range_function
2164 = (unit
->needs_blockage_function
2165 || GET_CODE (max_blockage
) != CONST_STRING
);
2167 if (unit
->needs_range_function
)
2169 /* Compute the blockage range function and make an attribute
2170 for writing its value. */
2171 newexp
= operate_exp (RANGE_OP
, min_blockage
, max_blockage
);
2172 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2174 str
= attr_printf ((strlen (unit
->name
)
2175 + sizeof "*_unit_blockage_range"),
2176 "*%s_unit_blockage_range", unit
->name
);
2177 make_internal_attr (str
, newexp
, 20);
2180 str
= attr_printf (strlen (unit
->name
) + sizeof "*_unit_ready_cost",
2181 "*%s_unit_ready_cost", unit
->name
);
2184 str
= "*result_ready_cost";
2186 /* Make an attribute for the ready_cost function. Simplifying
2187 further with simplify_by_exploding doesn't win. */
2188 make_internal_attr (str
, readycost
, 0);
2191 /* For each unit that requires a conflict cost function, make an attribute
2192 that maps insns to the operation number. */
2193 for (unit
= units
; unit
; unit
= unit
->next
)
2197 if (! unit
->needs_conflict_function
2198 && ! unit
->needs_blockage_function
)
2201 caseexp
= rtx_alloc (COND
);
2202 XVEC (caseexp
, 0) = rtvec_alloc ((unit
->num_opclasses
- 1) * 2);
2204 for (op
= unit
->ops
; op
; op
= op
->next
)
2206 /* Make our adjustment to the COND being computed. If we are the
2207 last operation class, place our values into the default of the
2209 if (op
->num
== unit
->num_opclasses
- 1)
2211 XEXP (caseexp
, 1) = make_numeric_value (op
->num
);
2215 XVECEXP (caseexp
, 0, op
->num
* 2) = op
->condexp
;
2216 XVECEXP (caseexp
, 0, op
->num
* 2 + 1)
2217 = make_numeric_value (op
->num
);
2221 /* Simplifying caseexp with simplify_by_exploding doesn't win. */
2222 str
= attr_printf (strlen (unit
->name
) + sizeof "*_cases",
2223 "*%s_cases", unit
->name
);
2224 make_internal_attr (str
, caseexp
, 1);
2228 /* Simplify EXP given KNOWN_TRUE. */
2231 simplify_knowing (exp
, known_true
)
2232 rtx exp
, known_true
;
2234 if (GET_CODE (exp
) != CONST_STRING
)
2236 int unknown
= 0, max
;
2237 max
= max_attr_value (exp
, &unknown
);
2240 exp
= attr_rtx (IF_THEN_ELSE
, known_true
, exp
,
2241 make_numeric_value (max
));
2242 exp
= simplify_by_exploding (exp
);
2248 /* Translate the CONST_STRING expressions in X to change the encoding of
2249 value. On input, the value is a bitmask with a one bit for each unit
2250 used; on output, the value is the unit number (zero based) if one
2251 and only one unit is used or the one's complement of the bitmask. */
2254 encode_units_mask (x
)
2262 code
= GET_CODE (x
);
2267 i
= atoi (XSTR (x
, 0));
2269 /* The sign bit encodes a one's complement mask. */
2271 else if (i
!= 0 && i
== (i
& -i
))
2272 /* Only one bit is set, so yield that unit number. */
2273 for (j
= 0; (i
>>= 1) != 0; j
++)
2277 return attr_rtx (CONST_STRING
, attr_printf (MAX_DIGITS
, "%d", j
));
2295 /* Compare the elements. If any pair of corresponding elements
2296 fail to match, return 0 for the whole things. */
2298 fmt
= GET_RTX_FORMAT (code
);
2299 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2305 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2306 XVECEXP (x
, i
, j
) = encode_units_mask (XVECEXP (x
, i
, j
));
2310 XEXP (x
, i
) = encode_units_mask (XEXP (x
, i
));
2317 /* Once all attributes and insns have been read and checked, we construct for
2318 each attribute value a list of all the insns that have that value for
2323 struct attr_desc
*attr
;
2325 struct attr_value
*av
;
2326 struct insn_ent
*ie
;
2327 struct insn_def
*id
;
2331 /* Don't fill constant attributes. The value is independent of
2332 any particular insn. */
2336 for (id
= defs
; id
; id
= id
->next
)
2338 /* If no value is specified for this insn for this attribute, use the
2341 if (XVEC (id
->def
, id
->vec_idx
))
2342 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
2343 if (! strcmp (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
2345 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
2348 av
= attr
->default_val
;
2350 av
= get_attr_value (value
, attr
, id
->insn_code
);
2352 ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2353 ie
->insn_code
= id
->insn_code
;
2354 ie
->insn_index
= id
->insn_code
;
2355 insert_insn_ent (av
, ie
);
2359 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
2360 test that checks relative positions of insns (uses MATCH_DUP or PC).
2361 If so, replace it with what is obtained by passing the expression to
2362 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
2363 recursively on each value (including the default value). Otherwise,
2364 return the value returned by NO_ADDRESS_FN applied to EXP. */
2367 substitute_address (exp
, no_address_fn
, address_fn
)
2369 rtx (*no_address_fn
) PARAMS ((rtx
));
2370 rtx (*address_fn
) PARAMS ((rtx
));
2375 if (GET_CODE (exp
) == COND
)
2377 /* See if any tests use addresses. */
2379 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2380 walk_attr_value (XVECEXP (exp
, 0, i
));
2383 return (*address_fn
) (exp
);
2385 /* Make a new copy of this COND, replacing each element. */
2386 newexp
= rtx_alloc (COND
);
2387 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
2388 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2390 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
2391 XVECEXP (newexp
, 0, i
+ 1)
2392 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
2393 no_address_fn
, address_fn
);
2396 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
2397 no_address_fn
, address_fn
);
2402 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
2405 walk_attr_value (XEXP (exp
, 0));
2407 return (*address_fn
) (exp
);
2409 return attr_rtx (IF_THEN_ELSE
,
2410 substitute_address (XEXP (exp
, 0),
2411 no_address_fn
, address_fn
),
2412 substitute_address (XEXP (exp
, 1),
2413 no_address_fn
, address_fn
),
2414 substitute_address (XEXP (exp
, 2),
2415 no_address_fn
, address_fn
));
2418 return (*no_address_fn
) (exp
);
2421 /* Make new attributes from the `length' attribute. The following are made,
2422 each corresponding to a function called from `shorten_branches' or
2425 *insn_default_length This is the length of the insn to be returned
2426 by `get_attr_length' before `shorten_branches'
2427 has been called. In each case where the length
2428 depends on relative addresses, the largest
2429 possible is used. This routine is also used
2430 to compute the initial size of the insn.
2432 *insn_variable_length_p This returns 1 if the insn's length depends
2433 on relative addresses, zero otherwise.
2435 *insn_current_length This is only called when it is known that the
2436 insn has a variable length and returns the
2437 current length, based on relative addresses.
2441 make_length_attrs ()
2443 static const char *const new_names
[] = {"*insn_default_length",
2444 "*insn_variable_length_p",
2445 "*insn_current_length"};
2446 static rtx (*const no_address_fn
[]) PARAMS ((rtx
)) = {identity_fn
, zero_fn
, zero_fn
};
2447 static rtx (*const address_fn
[]) PARAMS ((rtx
)) = {max_fn
, one_fn
, identity_fn
};
2449 struct attr_desc
*length_attr
, *new_attr
;
2450 struct attr_value
*av
, *new_av
;
2451 struct insn_ent
*ie
, *new_ie
;
2453 /* See if length attribute is defined. If so, it must be numeric. Make
2454 it special so we don't output anything for it. */
2455 length_attr
= find_attr ("length", 0);
2456 if (length_attr
== 0)
2459 if (! length_attr
->is_numeric
)
2460 fatal ("length attribute must be numeric");
2462 length_attr
->is_const
= 0;
2463 length_attr
->is_special
= 1;
2465 /* Make each new attribute, in turn. */
2466 for (i
= 0; i
< ARRAY_SIZE (new_names
); i
++)
2468 make_internal_attr (new_names
[i
],
2469 substitute_address (length_attr
->default_val
->value
,
2470 no_address_fn
[i
], address_fn
[i
]),
2472 new_attr
= find_attr (new_names
[i
], 0);
2473 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2474 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2476 new_av
= get_attr_value (substitute_address (av
->value
,
2479 new_attr
, ie
->insn_code
);
2480 new_ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2481 new_ie
->insn_code
= ie
->insn_code
;
2482 new_ie
->insn_index
= ie
->insn_index
;
2483 insert_insn_ent (new_av
, new_ie
);
2488 /* Utility functions called from above routine. */
2499 rtx exp ATTRIBUTE_UNUSED
;
2501 return make_numeric_value (0);
2506 rtx exp ATTRIBUTE_UNUSED
;
2508 return make_numeric_value (1);
2516 return make_numeric_value (max_attr_value (exp
, &unknown
));
2520 write_length_unit_log ()
2522 struct attr_desc
*length_attr
= find_attr ("length", 0);
2523 struct attr_value
*av
;
2524 struct insn_ent
*ie
;
2525 unsigned int length_unit_log
, length_or
;
2528 if (length_attr
== 0)
2530 length_or
= or_attr_value (length_attr
->default_val
->value
, &unknown
);
2531 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2532 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2533 length_or
|= or_attr_value (av
->value
, &unknown
);
2536 length_unit_log
= 0;
2539 length_or
= ~length_or
;
2540 for (length_unit_log
= 0; length_or
& 1; length_or
>>= 1)
2543 printf ("int length_unit_log = %u;\n", length_unit_log
);
2546 /* Take a COND expression and see if any of the conditions in it can be
2547 simplified. If any are known true or known false for the particular insn
2548 code, the COND can be further simplified.
2550 Also call ourselves on any COND operations that are values of this COND.
2552 We do not modify EXP; rather, we make and return a new rtx. */
2555 simplify_cond (exp
, insn_code
, insn_index
)
2557 int insn_code
, insn_index
;
2560 /* We store the desired contents here,
2561 then build a new expression if they don't match EXP. */
2562 rtx defval
= XEXP (exp
, 1);
2563 rtx new_defval
= XEXP (exp
, 1);
2564 int len
= XVECLEN (exp
, 0);
2565 rtx
*tests
= (rtx
*) xmalloc (len
* sizeof (rtx
));
2569 /* This lets us free all storage allocated below, if appropriate. */
2570 obstack_finish (rtl_obstack
);
2572 memcpy (tests
, XVEC (exp
, 0)->elem
, len
* sizeof (rtx
));
2574 /* See if default value needs simplification. */
2575 if (GET_CODE (defval
) == COND
)
2576 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
2578 /* Simplify the subexpressions, and see what tests we can get rid of. */
2580 for (i
= 0; i
< len
; i
+= 2)
2582 rtx newtest
, newval
;
2584 /* Simplify this test. */
2585 newtest
= simplify_test_exp_in_temp (tests
[i
], insn_code
, insn_index
);
2588 newval
= tests
[i
+ 1];
2589 /* See if this value may need simplification. */
2590 if (GET_CODE (newval
) == COND
)
2591 newval
= simplify_cond (newval
, insn_code
, insn_index
);
2593 /* Look for ways to delete or combine this test. */
2594 if (newtest
== true_rtx
)
2596 /* If test is true, make this value the default
2597 and discard this + any following tests. */
2599 defval
= tests
[i
+ 1];
2600 new_defval
= newval
;
2603 else if (newtest
== false_rtx
)
2605 /* If test is false, discard it and its value. */
2606 for (j
= i
; j
< len
- 2; j
++)
2607 tests
[j
] = tests
[j
+ 2];
2611 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
2613 /* If this value and the value for the prev test are the same,
2617 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
2618 insn_code
, insn_index
);
2620 /* Delete this test/value. */
2621 for (j
= i
; j
< len
- 2; j
++)
2622 tests
[j
] = tests
[j
+ 2];
2627 tests
[i
+ 1] = newval
;
2630 /* If the last test in a COND has the same value
2631 as the default value, that test isn't needed. */
2633 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
2636 /* See if we changed anything. */
2637 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
2640 for (i
= 0; i
< len
; i
++)
2641 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
2649 if (GET_CODE (defval
) == COND
)
2650 ret
= simplify_cond (defval
, insn_code
, insn_index
);
2658 rtx newexp
= rtx_alloc (COND
);
2660 XVEC (newexp
, 0) = rtvec_alloc (len
);
2661 memcpy (XVEC (newexp
, 0)->elem
, tests
, len
* sizeof (rtx
));
2662 XEXP (newexp
, 1) = new_defval
;
2669 /* Remove an insn entry from an attribute value. */
2672 remove_insn_ent (av
, ie
)
2673 struct attr_value
*av
;
2674 struct insn_ent
*ie
;
2676 struct insn_ent
*previe
;
2678 if (av
->first_insn
== ie
)
2679 av
->first_insn
= ie
->next
;
2682 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
2684 previe
->next
= ie
->next
;
2688 if (ie
->insn_code
== -1)
2689 av
->has_asm_insn
= 0;
2694 /* Insert an insn entry in an attribute value list. */
2697 insert_insn_ent (av
, ie
)
2698 struct attr_value
*av
;
2699 struct insn_ent
*ie
;
2701 ie
->next
= av
->first_insn
;
2702 av
->first_insn
= ie
;
2704 if (ie
->insn_code
== -1)
2705 av
->has_asm_insn
= 1;
2710 /* This is a utility routine to take an expression that is a tree of either
2711 AND or IOR expressions and insert a new term. The new term will be
2712 inserted at the right side of the first node whose code does not match
2713 the root. A new node will be created with the root's code. Its left
2714 side will be the old right side and its right side will be the new
2717 If the `term' is itself a tree, all its leaves will be inserted. */
2720 insert_right_side (code
, exp
, term
, insn_code
, insn_index
)
2724 int insn_code
, insn_index
;
2728 /* Avoid consing in some special cases. */
2729 if (code
== AND
&& term
== true_rtx
)
2731 if (code
== AND
&& term
== false_rtx
)
2733 if (code
== AND
&& exp
== true_rtx
)
2735 if (code
== AND
&& exp
== false_rtx
)
2737 if (code
== IOR
&& term
== true_rtx
)
2739 if (code
== IOR
&& term
== false_rtx
)
2741 if (code
== IOR
&& exp
== true_rtx
)
2743 if (code
== IOR
&& exp
== false_rtx
)
2745 if (attr_equal_p (exp
, term
))
2748 if (GET_CODE (term
) == code
)
2750 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
2751 insn_code
, insn_index
);
2752 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
2753 insn_code
, insn_index
);
2758 if (GET_CODE (exp
) == code
)
2760 rtx
new = insert_right_side (code
, XEXP (exp
, 1),
2761 term
, insn_code
, insn_index
);
2762 if (new != XEXP (exp
, 1))
2763 /* Make a copy of this expression and call recursively. */
2764 newexp
= attr_rtx (code
, XEXP (exp
, 0), new);
2770 /* Insert the new term. */
2771 newexp
= attr_rtx (code
, exp
, term
);
2774 return simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2777 /* If we have an expression which AND's a bunch of
2778 (not (eq_attrq "alternative" "n"))
2779 terms, we may have covered all or all but one of the possible alternatives.
2780 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
2782 This routine is passed an expression and either AND or IOR. It returns a
2783 bitmask indicating which alternatives are mentioned within EXP. */
2786 compute_alternative_mask (exp
, code
)
2791 if (GET_CODE (exp
) == code
)
2792 return compute_alternative_mask (XEXP (exp
, 0), code
)
2793 | compute_alternative_mask (XEXP (exp
, 1), code
);
2795 else if (code
== AND
&& GET_CODE (exp
) == NOT
2796 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2797 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
2798 string
= XSTR (XEXP (exp
, 0), 1);
2800 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
2801 && XSTR (exp
, 0) == alternative_name
)
2802 string
= XSTR (exp
, 1);
2808 return 1 << (string
[0] - '0');
2809 return 1 << atoi (string
);
2812 /* Given I, a single-bit mask, return RTX to compare the `alternative'
2813 attribute with the value represented by that bit. */
2816 make_alternative_compare (mask
)
2823 for (i
= 0; (mask
& (1 << i
)) == 0; i
++)
2826 newexp
= attr_rtx (EQ_ATTR
, alternative_name
, attr_numeral (i
));
2827 ATTR_IND_SIMPLIFIED_P (newexp
) = 1;
2832 /* If we are processing an (eq_attr "attr" "value") test, we find the value
2833 of "attr" for this insn code. From that value, we can compute a test
2834 showing when the EQ_ATTR will be true. This routine performs that
2835 computation. If a test condition involves an address, we leave the EQ_ATTR
2836 intact because addresses are only valid for the `length' attribute.
2838 EXP is the EQ_ATTR expression and VALUE is the value of that attribute
2839 for the insn corresponding to INSN_CODE and INSN_INDEX. */
2842 evaluate_eq_attr (exp
, value
, insn_code
, insn_index
)
2845 int insn_code
, insn_index
;
2852 if (GET_CODE (value
) == CONST_STRING
)
2854 if (! strcmp (XSTR (value
, 0), XSTR (exp
, 1)))
2859 else if (GET_CODE (value
) == SYMBOL_REF
)
2864 if (GET_CODE (exp
) != EQ_ATTR
)
2867 if (strlen (XSTR (exp
, 0)) + strlen (XSTR (exp
, 1)) + 2 > 256)
2870 strcpy (string
, XSTR (exp
, 0));
2871 strcat (string
, "_");
2872 strcat (string
, XSTR (exp
, 1));
2873 for (p
= string
; *p
; p
++)
2876 newexp
= attr_rtx (EQ
, value
,
2877 attr_rtx (SYMBOL_REF
,
2878 attr_string (string
, strlen (string
))));
2880 else if (GET_CODE (value
) == COND
)
2882 /* We construct an IOR of all the cases for which the requested attribute
2883 value is present. Since we start with FALSE, if it is not present,
2884 FALSE will be returned.
2886 Each case is the AND of the NOT's of the previous conditions with the
2887 current condition; in the default case the current condition is TRUE.
2889 For each possible COND value, call ourselves recursively.
2891 The extra TRUE and FALSE expressions will be eliminated by another
2892 call to the simplification routine. */
2897 if (current_alternative_string
)
2898 clear_struct_flag (value
);
2900 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2902 rtx
this = simplify_test_exp_in_temp (XVECEXP (value
, 0, i
),
2903 insn_code
, insn_index
);
2905 SIMPLIFY_ALTERNATIVE (this);
2907 right
= insert_right_side (AND
, andexp
, this,
2908 insn_code
, insn_index
);
2909 right
= insert_right_side (AND
, right
,
2910 evaluate_eq_attr (exp
,
2913 insn_code
, insn_index
),
2914 insn_code
, insn_index
);
2915 orexp
= insert_right_side (IOR
, orexp
, right
,
2916 insn_code
, insn_index
);
2918 /* Add this condition into the AND expression. */
2919 newexp
= attr_rtx (NOT
, this);
2920 andexp
= insert_right_side (AND
, andexp
, newexp
,
2921 insn_code
, insn_index
);
2924 /* Handle the default case. */
2925 right
= insert_right_side (AND
, andexp
,
2926 evaluate_eq_attr (exp
, XEXP (value
, 1),
2927 insn_code
, insn_index
),
2928 insn_code
, insn_index
);
2929 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2934 /* If uses an address, must return original expression. But set the
2935 ATTR_IND_SIMPLIFIED_P bit so we don't try to simplify it again. */
2938 walk_attr_value (newexp
);
2942 /* This had `&& current_alternative_string', which seems to be wrong. */
2943 if (! ATTR_IND_SIMPLIFIED_P (exp
))
2944 return copy_rtx_unchanging (exp
);
2951 /* This routine is called when an AND of a term with a tree of AND's is
2952 encountered. If the term or its complement is present in the tree, it
2953 can be replaced with TRUE or FALSE, respectively.
2955 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2956 be true and hence are complementary.
2958 There is one special case: If we see
2959 (and (not (eq_attr "att" "v1"))
2960 (eq_attr "att" "v2"))
2961 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2962 replace the term, not anything in the AND tree. So we pass a pointer to
2966 simplify_and_tree (exp
, pterm
, insn_code
, insn_index
)
2969 int insn_code
, insn_index
;
2974 int left_eliminates_term
, right_eliminates_term
;
2976 if (GET_CODE (exp
) == AND
)
2978 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2979 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2980 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2982 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2984 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2988 else if (GET_CODE (exp
) == IOR
)
2990 /* For the IOR case, we do the same as above, except that we can
2991 only eliminate `term' if both sides of the IOR would do so. */
2993 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2994 left_eliminates_term
= (temp
== true_rtx
);
2997 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2998 right_eliminates_term
= (temp
== true_rtx
);
3000 if (left_eliminates_term
&& right_eliminates_term
)
3003 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3005 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3007 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3011 /* Check for simplifications. Do some extra checking here since this
3012 routine is called so many times. */
3017 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
3020 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
3023 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
3025 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
3028 if (! strcmp (XSTR (exp
, 1), XSTR (*pterm
, 1)))
3034 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
3035 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3037 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
3040 if (! strcmp (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
3046 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
3047 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
3049 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
3052 if (! strcmp (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
3058 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
3060 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
3064 else if (GET_CODE (exp
) == NOT
)
3066 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
3070 else if (GET_CODE (*pterm
) == NOT
)
3072 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
3076 else if (attr_equal_p (exp
, *pterm
))
3082 /* Similar to `simplify_and_tree', but for IOR trees. */
3085 simplify_or_tree (exp
, pterm
, insn_code
, insn_index
)
3088 int insn_code
, insn_index
;
3093 int left_eliminates_term
, right_eliminates_term
;
3095 if (GET_CODE (exp
) == IOR
)
3097 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
3098 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
3099 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3101 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3103 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3107 else if (GET_CODE (exp
) == AND
)
3109 /* For the AND case, we do the same as above, except that we can
3110 only eliminate `term' if both sides of the AND would do so. */
3112 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
3113 left_eliminates_term
= (temp
== false_rtx
);
3116 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
3117 right_eliminates_term
= (temp
== false_rtx
);
3119 if (left_eliminates_term
&& right_eliminates_term
)
3122 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3124 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3126 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3130 if (attr_equal_p (exp
, *pterm
))
3133 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
3136 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
3139 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
3140 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3141 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
3144 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
3145 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
3146 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
3151 /* Compute approximate cost of the expression. Used to decide whether
3152 expression is cheap enough for inline. */
3161 code
= GET_CODE (x
);
3170 /* Alternatives don't result into function call. */
3171 if (!strcmp (XSTR (x
, 0), "alternative"))
3178 const char *fmt
= GET_RTX_FORMAT (code
);
3179 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3185 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3186 cost
+= attr_rtx_cost (XVECEXP (x
, i
, j
));
3189 cost
+= attr_rtx_cost (XEXP (x
, i
));
3200 /* Simplify test expression and use temporary obstack in order to avoid
3201 memory bloat. Use ATTR_IND_SIMPLIFIED to avoid unnecesary simplifications
3202 and avoid unnecesary copying if possible. */
3205 simplify_test_exp_in_temp (exp
, insn_code
, insn_index
)
3207 int insn_code
, insn_index
;
3210 struct obstack
*old
;
3211 if (ATTR_IND_SIMPLIFIED_P (exp
))
3214 rtl_obstack
= temp_obstack
;
3215 x
= simplify_test_exp (exp
, insn_code
, insn_index
);
3217 if (x
== exp
|| rtl_obstack
== temp_obstack
)
3219 return attr_copy_rtx (x
);
3222 /* Given an expression, see if it can be simplified for a particular insn
3223 code based on the values of other attributes being tested. This can
3224 eliminate nested get_attr_... calls.
3226 Note that if an endless recursion is specified in the patterns, the
3227 optimization will loop. However, it will do so in precisely the cases where
3228 an infinite recursion loop could occur during compilation. It's better that
3232 simplify_test_exp (exp
, insn_code
, insn_index
)
3234 int insn_code
, insn_index
;
3237 struct attr_desc
*attr
;
3238 struct attr_value
*av
;
3239 struct insn_ent
*ie
;
3243 /* Don't re-simplify something we already simplified. */
3244 if (ATTR_IND_SIMPLIFIED_P (exp
) || ATTR_CURR_SIMPLIFIED_P (exp
))
3247 switch (GET_CODE (exp
))
3250 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3251 SIMPLIFY_ALTERNATIVE (left
);
3252 if (left
== false_rtx
)
3254 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3255 SIMPLIFY_ALTERNATIVE (right
);
3256 if (left
== false_rtx
)
3259 /* If either side is an IOR and we have (eq_attr "alternative" ..")
3260 present on both sides, apply the distributive law since this will
3261 yield simplifications. */
3262 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
3263 && compute_alternative_mask (left
, IOR
)
3264 && compute_alternative_mask (right
, IOR
))
3266 if (GET_CODE (left
) == IOR
)
3273 newexp
= attr_rtx (IOR
,
3274 attr_rtx (AND
, left
, XEXP (right
, 0)),
3275 attr_rtx (AND
, left
, XEXP (right
, 1)));
3277 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3280 /* Try with the term on both sides. */
3281 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
3282 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3283 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
3285 if (left
== false_rtx
|| right
== false_rtx
)
3287 else if (left
== true_rtx
)
3291 else if (right
== true_rtx
)
3295 /* See if all or all but one of the insn's alternatives are specified
3296 in this tree. Optimize if so. */
3298 else if (insn_code
>= 0
3299 && (GET_CODE (left
) == AND
3300 || (GET_CODE (left
) == NOT
3301 && GET_CODE (XEXP (left
, 0)) == EQ_ATTR
3302 && XSTR (XEXP (left
, 0), 0) == alternative_name
)
3303 || GET_CODE (right
) == AND
3304 || (GET_CODE (right
) == NOT
3305 && GET_CODE (XEXP (right
, 0)) == EQ_ATTR
3306 && XSTR (XEXP (right
, 0), 0) == alternative_name
)))
3308 i
= compute_alternative_mask (exp
, AND
);
3309 if (i
& ~insn_alternatives
[insn_code
])
3310 fatal ("invalid alternative specified for pattern number %d",
3313 /* If all alternatives are excluded, this is false. */
3314 i
^= insn_alternatives
[insn_code
];
3317 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3319 /* If just one excluded, AND a comparison with that one to the
3320 front of the tree. The others will be eliminated by
3321 optimization. We do not want to do this if the insn has one
3322 alternative and we have tested none of them! */
3323 left
= make_alternative_compare (i
);
3324 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3325 newexp
= attr_rtx (AND
, left
, right
);
3327 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3331 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3333 newexp
= attr_rtx (AND
, left
, right
);
3334 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3339 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3340 SIMPLIFY_ALTERNATIVE (left
);
3341 if (left
== true_rtx
)
3343 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3344 SIMPLIFY_ALTERNATIVE (right
);
3345 if (right
== true_rtx
)
3348 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
3349 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3350 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
3352 if (right
== true_rtx
|| left
== true_rtx
)
3354 else if (left
== false_rtx
)
3358 else if (right
== false_rtx
)
3363 /* Test for simple cases where the distributive law is useful. I.e.,
3364 convert (ior (and (x) (y))
3370 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
3371 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
3373 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
3375 left
= XEXP (left
, 0);
3377 newexp
= attr_rtx (AND
, left
, right
);
3378 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3381 /* See if all or all but one of the insn's alternatives are specified
3382 in this tree. Optimize if so. */
3384 else if (insn_code
>= 0
3385 && (GET_CODE (left
) == IOR
3386 || (GET_CODE (left
) == EQ_ATTR
3387 && XSTR (left
, 0) == alternative_name
)
3388 || GET_CODE (right
) == IOR
3389 || (GET_CODE (right
) == EQ_ATTR
3390 && XSTR (right
, 0) == alternative_name
)))
3392 i
= compute_alternative_mask (exp
, IOR
);
3393 if (i
& ~insn_alternatives
[insn_code
])
3394 fatal ("invalid alternative specified for pattern number %d",
3397 /* If all alternatives are included, this is true. */
3398 i
^= insn_alternatives
[insn_code
];
3401 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3403 /* If just one excluded, IOR a comparison with that one to the
3404 front of the tree. The others will be eliminated by
3405 optimization. We do not want to do this if the insn has one
3406 alternative and we have tested none of them! */
3407 left
= make_alternative_compare (i
);
3408 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3409 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
3411 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3415 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3417 newexp
= attr_rtx (IOR
, left
, right
);
3418 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3423 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
3425 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
3426 insn_code
, insn_index
);
3427 SIMPLIFY_ALTERNATIVE (left
);
3431 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3432 SIMPLIFY_ALTERNATIVE (left
);
3433 if (GET_CODE (left
) == NOT
)
3434 return XEXP (left
, 0);
3436 if (left
== false_rtx
)
3438 else if (left
== true_rtx
)
3441 /* Try to apply De`Morgan's laws. */
3442 else if (GET_CODE (left
) == IOR
)
3444 newexp
= attr_rtx (AND
,
3445 attr_rtx (NOT
, XEXP (left
, 0)),
3446 attr_rtx (NOT
, XEXP (left
, 1)));
3448 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3450 else if (GET_CODE (left
) == AND
)
3452 newexp
= attr_rtx (IOR
,
3453 attr_rtx (NOT
, XEXP (left
, 0)),
3454 attr_rtx (NOT
, XEXP (left
, 1)));
3456 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3458 else if (left
!= XEXP (exp
, 0))
3460 newexp
= attr_rtx (NOT
, left
);
3465 if (current_alternative_string
&& XSTR (exp
, 0) == alternative_name
)
3466 return (XSTR (exp
, 1) == current_alternative_string
3467 ? true_rtx
: false_rtx
);
3469 /* Look at the value for this insn code in the specified attribute.
3470 We normally can replace this comparison with the condition that
3471 would give this insn the values being tested for. */
3472 if (XSTR (exp
, 0) != alternative_name
3473 && (attr
= find_attr (XSTR (exp
, 0), 0)) != NULL
)
3474 for (av
= attr
->first_value
; av
; av
= av
->next
)
3475 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3476 if (ie
->insn_code
== insn_code
)
3479 x
= evaluate_eq_attr (exp
, av
->value
, insn_code
, insn_index
);
3480 x
= SIMPLIFY_TEST_EXP (x
, insn_code
, insn_index
);
3481 if (attr_rtx_cost(x
) < 20)
3490 /* We have already simplified this expression. Simplifying it again
3491 won't buy anything unless we weren't given a valid insn code
3492 to process (i.e., we are canonicalizing something.). */
3493 if (insn_code
!= -2 /* Seems wrong: && current_alternative_string. */
3494 && ! ATTR_IND_SIMPLIFIED_P (newexp
))
3495 return copy_rtx_unchanging (newexp
);
3500 /* Optimize the attribute lists by seeing if we can determine conditional
3501 values from the known values of other attributes. This will save subroutine
3502 calls during the compilation. */
3507 struct attr_desc
*attr
;
3508 struct attr_value
*av
;
3509 struct insn_ent
*ie
;
3512 struct attr_value_list
3514 struct attr_value
*av
;
3515 struct insn_ent
*ie
;
3516 struct attr_desc
*attr
;
3517 struct attr_value_list
*next
;
3519 struct attr_value_list
**insn_code_values
;
3520 struct attr_value_list
*ivbuf
;
3521 struct attr_value_list
*iv
;
3523 /* For each insn code, make a list of all the insn_ent's for it,
3524 for all values for all attributes. */
3526 if (num_insn_ents
== 0)
3529 /* Make 2 extra elements, for "code" values -2 and -1. */
3531 = (struct attr_value_list
**) xmalloc ((insn_code_number
+ 2)
3532 * sizeof (struct attr_value_list
*));
3533 memset ((char *) insn_code_values
, 0,
3534 (insn_code_number
+ 2) * sizeof (struct attr_value_list
*));
3536 /* Offset the table address so we can index by -2 or -1. */
3537 insn_code_values
+= 2;
3539 iv
= ivbuf
= ((struct attr_value_list
*)
3540 xmalloc (num_insn_ents
* sizeof (struct attr_value_list
)));
3542 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
3543 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
3544 for (av
= attr
->first_value
; av
; av
= av
->next
)
3545 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3550 iv
->next
= insn_code_values
[ie
->insn_code
];
3551 insn_code_values
[ie
->insn_code
] = iv
;
3555 /* Sanity check on num_insn_ents. */
3556 if (iv
!= ivbuf
+ num_insn_ents
)
3559 /* Process one insn code at a time. */
3560 for (i
= -2; i
< insn_code_number
; i
++)
3562 /* Clear the ATTR_CURR_SIMPLIFIED_P flag everywhere relevant.
3563 We use it to mean "already simplified for this insn". */
3564 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3565 clear_struct_flag (iv
->av
->value
);
3567 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3569 struct obstack
*old
= rtl_obstack
;
3574 if (GET_CODE (av
->value
) != COND
)
3577 rtl_obstack
= temp_obstack
;
3578 #if 0 /* This was intended as a speed up, but it was slower. */
3579 if (insn_n_alternatives
[ie
->insn_code
] > 6
3580 && count_sub_rtxs (av
->value
, 200) >= 200)
3581 newexp
= simplify_by_alternatives (av
->value
, ie
->insn_code
,
3586 while (GET_CODE (newexp
) == COND
)
3588 rtx newexp2
= simplify_cond (newexp
, ie
->insn_code
,
3590 if (newexp2
== newexp
)
3596 if (newexp
!= av
->value
)
3598 newexp
= attr_copy_rtx (newexp
);
3599 remove_insn_ent (av
, ie
);
3600 av
= get_attr_value (newexp
, attr
, ie
->insn_code
);
3602 insert_insn_ent (av
, ie
);
3608 free (insn_code_values
- 2);
3613 simplify_by_alternatives (exp
, insn_code
, insn_index
)
3615 int insn_code
, insn_index
;
3618 int len
= insn_n_alternatives
[insn_code
];
3619 rtx newexp
= rtx_alloc (COND
);
3622 XVEC (newexp
, 0) = rtvec_alloc (len
* 2);
3624 /* It will not matter what value we use as the default value
3625 of the new COND, since that default will never be used.
3626 Choose something of the right type. */
3627 for (ultimate
= exp
; GET_CODE (ultimate
) == COND
;)
3628 ultimate
= XEXP (ultimate
, 1);
3629 XEXP (newexp
, 1) = ultimate
;
3631 for (i
= 0; i
< insn_n_alternatives
[insn_code
]; i
++)
3633 current_alternative_string
= attr_numeral (i
);
3634 XVECEXP (newexp
, 0, i
* 2) = make_alternative_compare (1 << i
);
3635 XVECEXP (newexp
, 0, i
* 2 + 1)
3636 = simplify_cond (exp
, insn_code
, insn_index
);
3639 current_alternative_string
= 0;
3640 return simplify_cond (newexp
, insn_code
, insn_index
);
3644 /* If EXP is a suitable expression, reorganize it by constructing an
3645 equivalent expression that is a COND with the tests being all combinations
3646 of attribute values and the values being simple constants. */
3649 simplify_by_exploding (exp
)
3652 rtx list
= 0, link
, condexp
, defval
= NULL_RTX
;
3653 struct dimension
*space
;
3654 rtx
*condtest
, *condval
;
3655 int i
, j
, total
, ndim
= 0;
3656 int most_tests
, num_marks
, new_marks
;
3659 /* Locate all the EQ_ATTR expressions. */
3660 if (! find_and_mark_used_attributes (exp
, &list
, &ndim
) || ndim
== 0)
3662 unmark_used_attributes (list
, 0, 0);
3666 /* Create an attribute space from the list of used attributes. For each
3667 dimension in the attribute space, record the attribute, list of values
3668 used, and number of values used. Add members to the list of values to
3669 cover the domain of the attribute. This makes the expanded COND form
3670 order independent. */
3672 space
= (struct dimension
*) xmalloc (ndim
* sizeof (struct dimension
));
3675 for (ndim
= 0; list
; ndim
++)
3677 /* Pull the first attribute value from the list and record that
3678 attribute as another dimension in the attribute space. */
3679 const char *name
= XSTR (XEXP (list
, 0), 0);
3682 if ((space
[ndim
].attr
= find_attr (name
, 0)) == 0
3683 || space
[ndim
].attr
->is_numeric
)
3685 unmark_used_attributes (list
, space
, ndim
);
3689 /* Add all remaining attribute values that refer to this attribute. */
3690 space
[ndim
].num_values
= 0;
3691 space
[ndim
].values
= 0;
3693 for (link
= list
; link
; link
= *prev
)
3694 if (! strcmp (XSTR (XEXP (link
, 0), 0), name
))
3696 space
[ndim
].num_values
++;
3697 *prev
= XEXP (link
, 1);
3698 XEXP (link
, 1) = space
[ndim
].values
;
3699 space
[ndim
].values
= link
;
3702 prev
= &XEXP (link
, 1);
3704 /* Add sufficient members to the list of values to make the list
3705 mutually exclusive and record the total size of the attribute
3707 total
*= add_values_to_cover (&space
[ndim
]);
3710 /* Sort the attribute space so that the attributes go from non-constant
3711 to constant and from most values to least values. */
3712 for (i
= 0; i
< ndim
; i
++)
3713 for (j
= ndim
- 1; j
> i
; j
--)
3714 if ((space
[j
-1].attr
->is_const
&& !space
[j
].attr
->is_const
)
3715 || space
[j
-1].num_values
< space
[j
].num_values
)
3717 struct dimension tmp
;
3719 space
[j
] = space
[j
- 1];
3723 /* Establish the initial current value. */
3724 for (i
= 0; i
< ndim
; i
++)
3725 space
[i
].current_value
= space
[i
].values
;
3727 condtest
= (rtx
*) xmalloc (total
* sizeof (rtx
));
3728 condval
= (rtx
*) xmalloc (total
* sizeof (rtx
));
3730 /* Expand the tests and values by iterating over all values in the
3734 condtest
[i
] = test_for_current_value (space
, ndim
);
3735 condval
[i
] = simplify_with_current_value (exp
, space
, ndim
);
3736 if (! increment_current_value (space
, ndim
))
3742 /* We are now finished with the original expression. */
3743 unmark_used_attributes (0, space
, ndim
);
3746 /* Find the most used constant value and make that the default. */
3748 for (i
= num_marks
= 0; i
< total
; i
++)
3749 if (GET_CODE (condval
[i
]) == CONST_STRING
3750 && ! ATTR_EQ_ATTR_P (condval
[i
]))
3752 /* Mark the unmarked constant value and count how many are marked. */
3753 ATTR_EQ_ATTR_P (condval
[i
]) = 1;
3754 for (j
= new_marks
= 0; j
< total
; j
++)
3755 if (GET_CODE (condval
[j
]) == CONST_STRING
3756 && ATTR_EQ_ATTR_P (condval
[j
]))
3758 if (new_marks
- num_marks
> most_tests
)
3760 most_tests
= new_marks
- num_marks
;
3761 defval
= condval
[i
];
3763 num_marks
= new_marks
;
3765 /* Clear all the marks. */
3766 for (i
= 0; i
< total
; i
++)
3767 ATTR_EQ_ATTR_P (condval
[i
]) = 0;
3769 /* Give up if nothing is constant. */
3773 /* If all values are the default, use that. */
3774 else if (total
== most_tests
)
3777 /* Make a COND with the most common constant value the default. (A more
3778 complex method where tests with the same value were combined didn't
3779 seem to improve things.) */
3782 condexp
= rtx_alloc (COND
);
3783 XVEC (condexp
, 0) = rtvec_alloc ((total
- most_tests
) * 2);
3784 XEXP (condexp
, 1) = defval
;
3785 for (i
= j
= 0; i
< total
; i
++)
3786 if (condval
[i
] != defval
)
3788 XVECEXP (condexp
, 0, 2 * j
) = condtest
[i
];
3789 XVECEXP (condexp
, 0, 2 * j
+ 1) = condval
[i
];
3799 /* Set the ATTR_EQ_ATTR_P flag for all EQ_ATTR expressions in EXP and
3800 verify that EXP can be simplified to a constant term if all the EQ_ATTR
3801 tests have known value. */
3804 find_and_mark_used_attributes (exp
, terms
, nterms
)
3810 switch (GET_CODE (exp
))
3813 if (! ATTR_EQ_ATTR_P (exp
))
3815 rtx link
= rtx_alloc (EXPR_LIST
);
3816 XEXP (link
, 0) = exp
;
3817 XEXP (link
, 1) = *terms
;
3820 ATTR_EQ_ATTR_P (exp
) = 1;
3829 if (! find_and_mark_used_attributes (XEXP (exp
, 2), terms
, nterms
))
3833 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3836 if (! find_and_mark_used_attributes (XEXP (exp
, 0), terms
, nterms
))
3841 for (i
= 0; i
< XVECLEN (exp
, 0); i
++)
3842 if (! find_and_mark_used_attributes (XVECEXP (exp
, 0, i
), terms
, nterms
))
3844 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3853 /* Clear the ATTR_EQ_ATTR_P flag in all EQ_ATTR expressions on LIST and
3854 in the values of the NDIM-dimensional attribute space SPACE. */
3857 unmark_used_attributes (list
, space
, ndim
)
3859 struct dimension
*space
;
3865 for (i
= 0; i
< ndim
; i
++)
3866 unmark_used_attributes (space
[i
].values
, 0, 0);
3868 for (link
= list
; link
; link
= XEXP (link
, 1))
3870 exp
= XEXP (link
, 0);
3871 if (GET_CODE (exp
) == EQ_ATTR
)
3872 ATTR_EQ_ATTR_P (exp
) = 0;
3876 /* Update the attribute dimension DIM so that all values of the attribute
3877 are tested. Return the updated number of values. */
3880 add_values_to_cover (dim
)
3881 struct dimension
*dim
;
3883 struct attr_value
*av
;
3884 rtx exp
, link
, *prev
;
3887 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3888 if (GET_CODE (av
->value
) == CONST_STRING
)
3891 if (nalt
< dim
->num_values
)
3893 else if (nalt
== dim
->num_values
)
3896 else if (nalt
* 2 < dim
->num_values
* 3)
3898 /* Most all the values of the attribute are used, so add all the unused
3900 prev
= &dim
->values
;
3901 for (link
= dim
->values
; link
; link
= *prev
)
3902 prev
= &XEXP (link
, 1);
3904 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3905 if (GET_CODE (av
->value
) == CONST_STRING
)
3907 exp
= attr_eq (dim
->attr
->name
, XSTR (av
->value
, 0));
3908 if (ATTR_EQ_ATTR_P (exp
))
3911 link
= rtx_alloc (EXPR_LIST
);
3912 XEXP (link
, 0) = exp
;
3915 prev
= &XEXP (link
, 1);
3917 dim
->num_values
= nalt
;
3921 rtx orexp
= false_rtx
;
3923 /* Very few values are used, so compute a mutually exclusive
3924 expression. (We could do this for numeric values if that becomes
3926 prev
= &dim
->values
;
3927 for (link
= dim
->values
; link
; link
= *prev
)
3929 orexp
= insert_right_side (IOR
, orexp
, XEXP (link
, 0), -2, -2);
3930 prev
= &XEXP (link
, 1);
3932 link
= rtx_alloc (EXPR_LIST
);
3933 XEXP (link
, 0) = attr_rtx (NOT
, orexp
);
3938 return dim
->num_values
;
3941 /* Increment the current value for the NDIM-dimensional attribute space SPACE
3942 and return FALSE if the increment overflowed. */
3945 increment_current_value (space
, ndim
)
3946 struct dimension
*space
;
3951 for (i
= ndim
- 1; i
>= 0; i
--)
3953 if ((space
[i
].current_value
= XEXP (space
[i
].current_value
, 1)) == 0)
3954 space
[i
].current_value
= space
[i
].values
;
3961 /* Construct an expression corresponding to the current value for the
3962 NDIM-dimensional attribute space SPACE. */
3965 test_for_current_value (space
, ndim
)
3966 struct dimension
*space
;
3972 for (i
= 0; i
< ndim
; i
++)
3973 exp
= insert_right_side (AND
, exp
, XEXP (space
[i
].current_value
, 0),
3979 /* Given the current value of the NDIM-dimensional attribute space SPACE,
3980 set the corresponding EQ_ATTR expressions to that value and reduce
3981 the expression EXP as much as possible. On input [and output], all
3982 known EQ_ATTR expressions are set to FALSE. */
3985 simplify_with_current_value (exp
, space
, ndim
)
3987 struct dimension
*space
;
3993 /* Mark each current value as TRUE. */
3994 for (i
= 0; i
< ndim
; i
++)
3996 x
= XEXP (space
[i
].current_value
, 0);
3997 if (GET_CODE (x
) == EQ_ATTR
)
3998 ATTR_EQ_ATTR_P (x
) = 0;
4001 exp
= simplify_with_current_value_aux (exp
);
4003 /* Change each current value back to FALSE. */
4004 for (i
= 0; i
< ndim
; i
++)
4006 x
= XEXP (space
[i
].current_value
, 0);
4007 if (GET_CODE (x
) == EQ_ATTR
)
4008 ATTR_EQ_ATTR_P (x
) = 1;
4014 /* Reduce the expression EXP based on the ATTR_EQ_ATTR_P settings of
4015 all EQ_ATTR expressions. */
4018 simplify_with_current_value_aux (exp
)
4024 switch (GET_CODE (exp
))
4027 if (ATTR_EQ_ATTR_P (exp
))
4036 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
4037 if (cond
== true_rtx
)
4038 return simplify_with_current_value_aux (XEXP (exp
, 1));
4039 else if (cond
== false_rtx
)
4040 return simplify_with_current_value_aux (XEXP (exp
, 2));
4042 return attr_rtx (IF_THEN_ELSE
, cond
,
4043 simplify_with_current_value_aux (XEXP (exp
, 1)),
4044 simplify_with_current_value_aux (XEXP (exp
, 2)));
4047 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
4048 if (cond
== true_rtx
)
4050 else if (cond
== false_rtx
)
4051 return simplify_with_current_value_aux (XEXP (exp
, 0));
4053 return attr_rtx (IOR
, cond
,
4054 simplify_with_current_value_aux (XEXP (exp
, 0)));
4057 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
4058 if (cond
== true_rtx
)
4059 return simplify_with_current_value_aux (XEXP (exp
, 0));
4060 else if (cond
== false_rtx
)
4063 return attr_rtx (AND
, cond
,
4064 simplify_with_current_value_aux (XEXP (exp
, 0)));
4067 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
4068 if (cond
== true_rtx
)
4070 else if (cond
== false_rtx
)
4073 return attr_rtx (NOT
, cond
);
4076 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4078 cond
= simplify_with_current_value_aux (XVECEXP (exp
, 0, i
));
4079 if (cond
== true_rtx
)
4080 return simplify_with_current_value_aux (XVECEXP (exp
, 0, i
+ 1));
4081 else if (cond
== false_rtx
)
4084 abort (); /* With all EQ_ATTR's of known value, a case should
4085 have been selected. */
4087 return simplify_with_current_value_aux (XEXP (exp
, 1));
4094 /* Clear the ATTR_CURR_SIMPLIFIED_P flag in EXP and its subexpressions. */
4097 clear_struct_flag (x
)
4105 ATTR_CURR_SIMPLIFIED_P (x
) = 0;
4106 if (ATTR_IND_SIMPLIFIED_P (x
))
4109 code
= GET_CODE (x
);
4130 /* Compare the elements. If any pair of corresponding elements
4131 fail to match, return 0 for the whole things. */
4133 fmt
= GET_RTX_FORMAT (code
);
4134 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4140 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4141 clear_struct_flag (XVECEXP (x
, i
, j
));
4145 clear_struct_flag (XEXP (x
, i
));
4151 /* Return the number of RTX objects making up the expression X.
4152 But if we count more than MAX objects, stop counting. */
4155 count_sub_rtxs (x
, max
)
4165 code
= GET_CODE (x
);
4186 /* Compare the elements. If any pair of corresponding elements
4187 fail to match, return 0 for the whole things. */
4189 fmt
= GET_RTX_FORMAT (code
);
4190 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4199 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4200 total
+= count_sub_rtxs (XVECEXP (x
, i
, j
), max
);
4204 total
+= count_sub_rtxs (XEXP (x
, i
), max
);
4212 /* Create table entries for DEFINE_ATTR. */
4215 gen_attr (exp
, lineno
)
4219 struct attr_desc
*attr
;
4220 struct attr_value
*av
;
4221 const char *name_ptr
;
4224 /* Make a new attribute structure. Check for duplicate by looking at
4225 attr->default_val, since it is initialized by this routine. */
4226 attr
= find_attr (XSTR (exp
, 0), 1);
4227 if (attr
->default_val
)
4229 message_with_line (lineno
, "duplicate definition for attribute %s",
4231 message_with_line (attr
->lineno
, "previous definition");
4235 attr
->lineno
= lineno
;
4237 if (*XSTR (exp
, 1) == '\0')
4238 attr
->is_numeric
= 1;
4241 name_ptr
= XSTR (exp
, 1);
4242 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
4244 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
4245 av
->value
= attr_rtx (CONST_STRING
, p
);
4246 av
->next
= attr
->first_value
;
4247 attr
->first_value
= av
;
4248 av
->first_insn
= NULL
;
4250 av
->has_asm_insn
= 0;
4254 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
4257 if (attr
->is_numeric
)
4259 message_with_line (lineno
,
4260 "constant attributes may not take numeric values");
4264 /* Get rid of the CONST node. It is allowed only at top-level. */
4265 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
4268 if (! strcmp (attr
->name
, "length") && ! attr
->is_numeric
)
4270 message_with_line (lineno
,
4271 "`length' attribute must take numeric values");
4275 /* Set up the default value. */
4276 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
4277 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
4280 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
4281 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
4282 number of alternatives as this should be checked elsewhere. */
4285 count_alternatives (exp
)
4291 if (GET_CODE (exp
) == MATCH_OPERAND
)
4292 return n_comma_elts (XSTR (exp
, 2));
4294 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4295 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4300 n
= count_alternatives (XEXP (exp
, i
));
4307 if (XVEC (exp
, i
) != NULL
)
4308 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4310 n
= count_alternatives (XVECEXP (exp
, i
, j
));
4319 /* Returns nonzero if the given expression contains an EQ_ATTR with the
4320 `alternative' attribute. */
4323 compares_alternatives_p (exp
)
4329 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
4332 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4333 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4338 if (compares_alternatives_p (XEXP (exp
, i
)))
4343 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4344 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
4352 /* Returns nonzero is INNER is contained in EXP. */
4355 contained_in_p (inner
, exp
)
4362 if (rtx_equal_p (inner
, exp
))
4365 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4366 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4371 if (contained_in_p (inner
, XEXP (exp
, i
)))
4376 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4377 if (contained_in_p (inner
, XVECEXP (exp
, i
, j
)))
4385 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
4388 gen_insn (exp
, lineno
)
4392 struct insn_def
*id
;
4394 id
= (struct insn_def
*) oballoc (sizeof (struct insn_def
));
4398 id
->lineno
= lineno
;
4400 switch (GET_CODE (exp
))
4403 id
->insn_code
= insn_code_number
;
4404 id
->insn_index
= insn_index_number
;
4405 id
->num_alternatives
= count_alternatives (exp
);
4406 if (id
->num_alternatives
== 0)
4407 id
->num_alternatives
= 1;
4411 case DEFINE_PEEPHOLE
:
4412 id
->insn_code
= insn_code_number
;
4413 id
->insn_index
= insn_index_number
;
4414 id
->num_alternatives
= count_alternatives (exp
);
4415 if (id
->num_alternatives
== 0)
4416 id
->num_alternatives
= 1;
4420 case DEFINE_ASM_ATTRIBUTES
:
4422 id
->insn_index
= -1;
4423 id
->num_alternatives
= 1;
4425 got_define_asm_attributes
= 1;
4433 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
4434 true or annul false is specified, and make a `struct delay_desc'. */
4437 gen_delay (def
, lineno
)
4441 struct delay_desc
*delay
;
4444 if (XVECLEN (def
, 1) % 3 != 0)
4446 message_with_line (lineno
,
4447 "number of elements in DEFINE_DELAY must be multiple of three");
4452 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
4454 if (XVECEXP (def
, 1, i
+ 1))
4455 have_annul_true
= 1;
4456 if (XVECEXP (def
, 1, i
+ 2))
4457 have_annul_false
= 1;
4460 delay
= (struct delay_desc
*) oballoc (sizeof (struct delay_desc
));
4462 delay
->num
= ++num_delays
;
4463 delay
->next
= delays
;
4464 delay
->lineno
= lineno
;
4468 /* Process a DEFINE_FUNCTION_UNIT.
4470 This gives information about a function unit contained in the CPU.
4471 We fill in a `struct function_unit_op' and a `struct function_unit'
4472 with information used later by `expand_unit'. */
4475 gen_unit (def
, lineno
)
4479 struct function_unit
*unit
;
4480 struct function_unit_op
*op
;
4481 const char *name
= XSTR (def
, 0);
4482 int multiplicity
= XINT (def
, 1);
4483 int simultaneity
= XINT (def
, 2);
4484 rtx condexp
= XEXP (def
, 3);
4485 int ready_cost
= MAX (XINT (def
, 4), 1);
4486 int issue_delay
= MAX (XINT (def
, 5), 1);
4488 /* See if we have already seen this function unit. If so, check that
4489 the multiplicity and simultaneity values are the same. If not, make
4490 a structure for this function unit. */
4491 for (unit
= units
; unit
; unit
= unit
->next
)
4492 if (! strcmp (unit
->name
, name
))
4494 if (unit
->multiplicity
!= multiplicity
4495 || unit
->simultaneity
!= simultaneity
)
4497 message_with_line (lineno
,
4498 "differing specifications given for function unit %s",
4500 message_with_line (unit
->first_lineno
, "previous definition");
4509 unit
= (struct function_unit
*) oballoc (sizeof (struct function_unit
));
4511 unit
->multiplicity
= multiplicity
;
4512 unit
->simultaneity
= simultaneity
;
4513 unit
->issue_delay
.min
= unit
->issue_delay
.max
= issue_delay
;
4514 unit
->num
= num_units
++;
4515 unit
->num_opclasses
= 0;
4516 unit
->condexp
= false_rtx
;
4519 unit
->first_lineno
= lineno
;
4523 /* Make a new operation class structure entry and initialize it. */
4524 op
= (struct function_unit_op
*) oballoc (sizeof (struct function_unit_op
));
4525 op
->condexp
= condexp
;
4526 op
->num
= unit
->num_opclasses
++;
4527 op
->ready
= ready_cost
;
4528 op
->issue_delay
= issue_delay
;
4529 op
->next
= unit
->ops
;
4530 op
->lineno
= lineno
;
4532 num_unit_opclasses
++;
4534 /* Set our issue expression based on whether or not an optional conflict
4535 vector was specified. */
4538 /* Compute the IOR of all the specified expressions. */
4539 rtx orexp
= false_rtx
;
4542 for (i
= 0; i
< XVECLEN (def
, 6); i
++)
4543 orexp
= insert_right_side (IOR
, orexp
, XVECEXP (def
, 6, i
), -2, -2);
4545 op
->conflict_exp
= orexp
;
4546 extend_range (&unit
->issue_delay
, 1, issue_delay
);
4550 op
->conflict_exp
= true_rtx
;
4551 extend_range (&unit
->issue_delay
, issue_delay
, issue_delay
);
4554 /* Merge our conditional into that of the function unit so we can determine
4555 which insns are used by the function unit. */
4556 unit
->condexp
= insert_right_side (IOR
, unit
->condexp
, op
->condexp
, -2, -2);
4559 /* Given a piece of RTX, print a C expression to test its truth value.
4560 We use AND and IOR both for logical and bit-wise operations, so
4561 interpret them as logical unless they are inside a comparison expression.
4562 The first bit of FLAGS will be nonzero in that case.
4564 Set the second bit of FLAGS to make references to attribute values use
4565 a cached local variable instead of calling a function. */
4568 write_test_expr (exp
, flags
)
4572 int comparison_operator
= 0;
4574 struct attr_desc
*attr
;
4576 /* In order not to worry about operator precedence, surround our part of
4577 the expression with parentheses. */
4580 code
= GET_CODE (exp
);
4583 /* Binary operators. */
4585 case GE
: case GT
: case GEU
: case GTU
:
4586 case LE
: case LT
: case LEU
: case LTU
:
4587 comparison_operator
= 1;
4589 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
4590 case AND
: case IOR
: case XOR
:
4591 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
4592 write_test_expr (XEXP (exp
, 0), flags
| comparison_operator
);
4608 printf (" >= (unsigned) ");
4611 printf (" > (unsigned) ");
4620 printf (" <= (unsigned) ");
4623 printf (" < (unsigned) ");
4666 write_test_expr (XEXP (exp
, 1), flags
| comparison_operator
);
4670 /* Special-case (not (eq_attrq "alternative" "x")) */
4671 if (! (flags
& 1) && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
4672 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
4674 printf ("which_alternative != %s", XSTR (XEXP (exp
, 0), 1));
4678 /* Otherwise, fall through to normal unary operator. */
4680 /* Unary operators. */
4700 write_test_expr (XEXP (exp
, 0), flags
);
4703 /* Comparison test of an attribute with a value. Most of these will
4704 have been removed by optimization. Handle "alternative"
4705 specially and give error if EQ_ATTR present inside a comparison. */
4708 fatal ("EQ_ATTR not valid inside comparison");
4710 if (XSTR (exp
, 0) == alternative_name
)
4712 printf ("which_alternative == %s", XSTR (exp
, 1));
4716 attr
= find_attr (XSTR (exp
, 0), 0);
4720 /* Now is the time to expand the value of a constant attribute. */
4723 write_test_expr (evaluate_eq_attr (exp
, attr
->default_val
->value
,
4730 printf ("attr_%s", attr
->name
);
4732 printf ("get_attr_%s (insn)", attr
->name
);
4734 write_attr_valueq (attr
, XSTR (exp
, 1));
4738 /* Comparison test of flags for define_delays. */
4741 fatal ("ATTR_FLAG not valid inside comparison");
4742 printf ("(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
4745 /* See if an operand matches a predicate. */
4747 /* If only a mode is given, just ensure the mode matches the operand.
4748 If neither a mode nor predicate is given, error. */
4749 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
4751 if (GET_MODE (exp
) == VOIDmode
)
4752 fatal ("null MATCH_OPERAND specified as test");
4754 printf ("GET_MODE (operands[%d]) == %smode",
4755 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4758 printf ("%s (operands[%d], %smode)",
4759 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4763 printf ("%s (insn)", XSTR (exp
, 0));
4766 /* Constant integer. */
4768 printf (HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
4771 /* A random C expression. */
4773 printf ("%s", XSTR (exp
, 0));
4776 /* The address of the branch target. */
4778 printf ("INSN_ADDRESSES_SET_P () ? INSN_ADDRESSES (INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])) : 0",
4779 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
4783 /* The address of the current insn. We implement this actually as the
4784 address of the current insn for backward branches, but the last
4785 address of the next insn for forward branches, and both with
4786 adjustments that account for the worst-case possible stretching of
4787 intervening alignments between this insn and its destination. */
4788 printf ("insn_current_reference_address (insn)");
4792 printf ("%s", XSTR (exp
, 0));
4796 write_test_expr (XEXP (exp
, 0), flags
& 2);
4798 write_test_expr (XEXP (exp
, 1), flags
| 1);
4800 write_test_expr (XEXP (exp
, 2), flags
| 1);
4804 fatal ("bad RTX code `%s' in attribute calculation\n",
4805 GET_RTX_NAME (code
));
4811 /* Given an attribute value, return the maximum CONST_STRING argument
4812 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
4815 max_attr_value (exp
, unknownp
)
4822 switch (GET_CODE (exp
))
4825 current_max
= atoi (XSTR (exp
, 0));
4829 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4830 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4832 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4833 if (n
> current_max
)
4839 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4840 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
4841 if (n
> current_max
)
4847 current_max
= INT_MAX
;
4854 /* Given an attribute value, return the result of ORing together all
4855 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
4856 if the numeric value is not known. */
4859 or_attr_value (exp
, unknownp
)
4866 switch (GET_CODE (exp
))
4869 current_or
= atoi (XSTR (exp
, 0));
4873 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4874 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4875 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4879 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4880 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
4892 /* Scan an attribute value, possibly a conditional, and record what actions
4893 will be required to do any conditional tests in it.
4896 `must_extract' if we need to extract the insn operands
4897 `must_constrain' if we must compute `which_alternative'
4898 `address_used' if an address expression was used
4899 `length_used' if an (eq_attr "length" ...) was used
4903 walk_attr_value (exp
)
4913 code
= GET_CODE (exp
);
4917 if (! ATTR_IND_SIMPLIFIED_P (exp
))
4918 /* Since this is an arbitrary expression, it can look at anything.
4919 However, constant expressions do not depend on any particular
4921 must_extract
= must_constrain
= 1;
4929 if (XSTR (exp
, 0) == alternative_name
)
4930 must_extract
= must_constrain
= 1;
4931 else if (strcmp (XSTR (exp
, 0), "length") == 0)
4951 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
4956 walk_attr_value (XEXP (exp
, i
));
4960 if (XVEC (exp
, i
) != NULL
)
4961 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4962 walk_attr_value (XVECEXP (exp
, i
, j
));
4967 /* Write out a function to obtain the attribute for a given INSN. */
4970 write_attr_get (attr
)
4971 struct attr_desc
*attr
;
4973 struct attr_value
*av
, *common_av
;
4975 /* Find the most used attribute value. Handle that as the `default' of the
4976 switch we will generate. */
4977 common_av
= find_most_used (attr
);
4979 /* Write out prototype of function. */
4980 if (!attr
->is_numeric
)
4981 printf ("extern enum attr_%s ", attr
->name
);
4982 else if (attr
->unsigned_p
)
4983 printf ("extern unsigned int ");
4985 printf ("extern int ");
4986 /* If the attribute name starts with a star, the remainder is the name of
4987 the subroutine to use, instead of `get_attr_...'. */
4988 if (attr
->name
[0] == '*')
4989 printf ("%s PARAMS ((rtx));\n", &attr
->name
[1]);
4991 printf ("get_attr_%s PARAMS ((%s));\n", attr
->name
,
4992 (attr
->is_const
? "void" : "rtx"));
4994 /* Write out start of function, then all values with explicit `case' lines,
4995 then a `default', then the value with the most uses. */
4996 if (!attr
->is_numeric
)
4997 printf ("enum attr_%s\n", attr
->name
);
4998 else if (attr
->unsigned_p
)
4999 printf ("unsigned int\n");
5003 /* If the attribute name starts with a star, the remainder is the name of
5004 the subroutine to use, instead of `get_attr_...'. */
5005 if (attr
->name
[0] == '*')
5006 printf ("%s (insn)\n", &attr
->name
[1]);
5007 else if (attr
->is_const
== 0)
5008 printf ("get_attr_%s (insn)\n", attr
->name
);
5011 printf ("get_attr_%s ()\n", attr
->name
);
5014 for (av
= attr
->first_value
; av
; av
= av
->next
)
5015 if (av
->num_insns
!= 0)
5016 write_attr_set (attr
, 2, av
->value
, "return", ";",
5017 true_rtx
, av
->first_insn
->insn_code
,
5018 av
->first_insn
->insn_index
);
5024 printf (" rtx insn;\n");
5027 if (GET_CODE (common_av
->value
) == FFS
)
5029 rtx p
= XEXP (common_av
->value
, 0);
5031 /* No need to emit code to abort if the insn is unrecognized; the
5032 other get_attr_foo functions will do that when we call them. */
5034 write_toplevel_expr (p
);
5036 printf ("\n if (accum && accum == (accum & -accum))\n");
5038 printf (" int i;\n");
5039 printf (" for (i = 0; accum >>= 1; ++i) continue;\n");
5040 printf (" accum = i;\n");
5041 printf (" }\n else\n");
5042 printf (" accum = ~accum;\n");
5043 printf (" return accum;\n}\n\n");
5047 printf (" switch (recog_memoized (insn))\n");
5050 for (av
= attr
->first_value
; av
; av
= av
->next
)
5051 if (av
!= common_av
)
5052 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5054 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5055 printf (" }\n}\n\n");
5059 /* Given an AND tree of known true terms (because we are inside an `if' with
5060 that as the condition or are in an `else' clause) and an expression,
5061 replace any known true terms with TRUE. Use `simplify_and_tree' to do
5062 the bulk of the work. */
5065 eliminate_known_true (known_true
, exp
, insn_code
, insn_index
)
5068 int insn_code
, insn_index
;
5072 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
5074 if (GET_CODE (known_true
) == AND
)
5076 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
5077 insn_code
, insn_index
);
5078 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
5079 insn_code
, insn_index
);
5084 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
5090 /* Write out a series of tests and assignment statements to perform tests and
5091 sets of an attribute value. We are passed an indentation amount and prefix
5092 and suffix strings to write around each attribute value (e.g., "return"
5096 write_attr_set (attr
, indent
, value
, prefix
, suffix
, known_true
,
5097 insn_code
, insn_index
)
5098 struct attr_desc
*attr
;
5104 int insn_code
, insn_index
;
5106 if (GET_CODE (value
) == COND
)
5108 /* Assume the default value will be the default of the COND unless we
5109 find an always true expression. */
5110 rtx default_val
= XEXP (value
, 1);
5111 rtx our_known_true
= known_true
;
5116 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
5121 testexp
= eliminate_known_true (our_known_true
,
5122 XVECEXP (value
, 0, i
),
5123 insn_code
, insn_index
);
5124 newexp
= attr_rtx (NOT
, testexp
);
5125 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
5126 insn_code
, insn_index
);
5128 /* If the test expression is always true or if the next `known_true'
5129 expression is always false, this is the last case, so break
5130 out and let this value be the `else' case. */
5131 if (testexp
== true_rtx
|| newexp
== false_rtx
)
5133 default_val
= XVECEXP (value
, 0, i
+ 1);
5137 /* Compute the expression to pass to our recursive call as being
5139 inner_true
= insert_right_side (AND
, our_known_true
,
5140 testexp
, insn_code
, insn_index
);
5142 /* If this is always false, skip it. */
5143 if (inner_true
== false_rtx
)
5146 write_indent (indent
);
5147 printf ("%sif ", first_if
? "" : "else ");
5149 write_test_expr (testexp
, 0);
5151 write_indent (indent
+ 2);
5154 write_attr_set (attr
, indent
+ 4,
5155 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
5156 inner_true
, insn_code
, insn_index
);
5157 write_indent (indent
+ 2);
5159 our_known_true
= newexp
;
5164 write_indent (indent
);
5166 write_indent (indent
+ 2);
5170 write_attr_set (attr
, first_if
? indent
: indent
+ 4, default_val
,
5171 prefix
, suffix
, our_known_true
, insn_code
, insn_index
);
5175 write_indent (indent
+ 2);
5181 write_indent (indent
);
5182 printf ("%s ", prefix
);
5183 write_attr_value (attr
, value
);
5184 printf ("%s\n", suffix
);
5188 /* Write out the computation for one attribute value. */
5191 write_attr_case (attr
, av
, write_case_lines
, prefix
, suffix
, indent
,
5193 struct attr_desc
*attr
;
5194 struct attr_value
*av
;
5195 int write_case_lines
;
5196 const char *prefix
, *suffix
;
5200 struct insn_ent
*ie
;
5202 if (av
->num_insns
== 0)
5205 if (av
->has_asm_insn
)
5207 write_indent (indent
);
5208 printf ("case -1:\n");
5209 write_indent (indent
+ 2);
5210 printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
5211 write_indent (indent
+ 2);
5212 printf (" && asm_noperands (PATTERN (insn)) < 0)\n");
5213 write_indent (indent
+ 2);
5214 printf (" fatal_insn_not_found (insn);\n");
5217 if (write_case_lines
)
5219 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5220 if (ie
->insn_code
!= -1)
5222 write_indent (indent
);
5223 printf ("case %d:\n", ie
->insn_code
);
5228 write_indent (indent
);
5229 printf ("default:\n");
5232 /* See what we have to do to output this value. */
5233 must_extract
= must_constrain
= address_used
= 0;
5234 walk_attr_value (av
->value
);
5238 write_indent (indent
+ 2);
5239 printf ("extract_constrain_insn_cached (insn);\n");
5241 else if (must_extract
)
5243 write_indent (indent
+ 2);
5244 printf ("extract_insn_cached (insn);\n");
5247 write_attr_set (attr
, indent
+ 2, av
->value
, prefix
, suffix
,
5248 known_true
, av
->first_insn
->insn_code
,
5249 av
->first_insn
->insn_index
);
5251 if (strncmp (prefix
, "return", 6))
5253 write_indent (indent
+ 2);
5254 printf ("break;\n");
5259 /* Search for uses of non-const attributes and write code to cache them. */
5262 write_expr_attr_cache (p
, attr
)
5264 struct attr_desc
*attr
;
5269 if (GET_CODE (p
) == EQ_ATTR
)
5271 if (XSTR (p
, 0) != attr
->name
)
5274 if (!attr
->is_numeric
)
5275 printf (" enum attr_%s ", attr
->name
);
5276 else if (attr
->unsigned_p
)
5277 printf (" unsigned int ");
5281 printf ("attr_%s = get_attr_%s (insn);\n", attr
->name
, attr
->name
);
5285 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
5286 ie
= GET_RTX_LENGTH (GET_CODE (p
));
5287 for (i
= 0; i
< ie
; i
++)
5292 if (write_expr_attr_cache (XEXP (p
, i
), attr
))
5297 je
= XVECLEN (p
, i
);
5298 for (j
= 0; j
< je
; ++j
)
5299 if (write_expr_attr_cache (XVECEXP (p
, i
, j
), attr
))
5308 /* Evaluate an expression at top level. A front end to write_test_expr,
5309 in which we cache attribute values and break up excessively large
5310 expressions to cater to older compilers. */
5313 write_toplevel_expr (p
)
5316 struct attr_desc
*attr
;
5319 for (i
= 0; i
< MAX_ATTRS_INDEX
; ++i
)
5320 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5321 if (!attr
->is_const
)
5322 write_expr_attr_cache (p
, attr
);
5324 printf (" unsigned long accum = 0;\n\n");
5326 while (GET_CODE (p
) == IOR
)
5329 if (GET_CODE (XEXP (p
, 0)) == IOR
)
5330 e
= XEXP (p
, 1), p
= XEXP (p
, 0);
5332 e
= XEXP (p
, 0), p
= XEXP (p
, 1);
5334 printf (" accum |= ");
5335 write_test_expr (e
, 3);
5338 printf (" accum |= ");
5339 write_test_expr (p
, 3);
5343 /* Utilities to write names in various forms. */
5346 write_unit_name (prefix
, num
, suffix
)
5351 struct function_unit
*unit
;
5353 for (unit
= units
; unit
; unit
= unit
->next
)
5354 if (unit
->num
== num
)
5356 printf ("%s%s%s", prefix
, unit
->name
, suffix
);
5360 printf ("%s<unknown>%s", prefix
, suffix
);
5364 write_attr_valueq (attr
, s
)
5365 struct attr_desc
*attr
;
5368 if (attr
->is_numeric
)
5374 /* Make the blockage range values and function units used values easier
5376 if (attr
->func_units_p
)
5379 printf (" /* units: none */");
5381 write_unit_name (" /* units: ", num
, " */");
5385 const char *sep
= " /* units: ";
5386 for (i
= 0, num
= ~num
; num
; i
++, num
>>= 1)
5389 write_unit_name (sep
, i
, (num
== 1) ? " */" : "");
5395 else if (attr
->blockage_p
)
5396 printf (" /* min %d, max %d */", num
>> (HOST_BITS_PER_INT
/ 2),
5397 num
& ((1 << (HOST_BITS_PER_INT
/ 2)) - 1));
5399 else if (num
> 9 || num
< 0)
5400 printf (" /* 0x%x */", num
);
5404 write_upcase (attr
->name
);
5411 write_attr_value (attr
, value
)
5412 struct attr_desc
*attr
;
5417 switch (GET_CODE (value
))
5420 write_attr_valueq (attr
, XSTR (value
, 0));
5424 printf (HOST_WIDE_INT_PRINT_DEC
, INTVAL (value
));
5428 fputs (XSTR (value
, 0), stdout
);
5433 struct attr_desc
*attr2
= find_attr (XSTR (value
, 0), 0);
5434 printf ("get_attr_%s (%s)", attr2
->name
,
5435 (attr2
->is_const
? "" : "insn"));
5456 write_attr_value (attr
, XEXP (value
, 0));
5460 write_attr_value (attr
, XEXP (value
, 1));
5474 /* The argument of TOUPPER should not have side effects. */
5475 putchar (TOUPPER(*str
));
5481 write_indent (indent
)
5484 for (; indent
> 8; indent
-= 8)
5487 for (; indent
; indent
--)
5491 /* Write a subroutine that is given an insn that requires a delay slot, a
5492 delay slot ordinal, and a candidate insn. It returns nonzero if the
5493 candidate can be placed in the specified delay slot of the insn.
5495 We can write as many as three subroutines. `eligible_for_delay'
5496 handles normal delay slots, `eligible_for_annul_true' indicates that
5497 the specified insn can be annulled if the branch is true, and likewise
5498 for `eligible_for_annul_false'.
5500 KIND is a string distinguishing these three cases ("delay", "annul_true",
5501 or "annul_false"). */
5504 write_eligible_delay (kind
)
5507 struct delay_desc
*delay
;
5510 struct attr_desc
*attr
;
5511 struct attr_value
*av
, *common_av
;
5514 /* Compute the maximum number of delay slots required. We use the delay
5515 ordinal times this number plus one, plus the slot number as an index into
5516 the appropriate predicate to test. */
5518 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
5519 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
5520 max_slots
= XVECLEN (delay
->def
, 1) / 3;
5522 /* Write function prelude. */
5525 printf ("eligible_for_%s (delay_insn, slot, candidate_insn, flags)\n",
5527 printf (" rtx delay_insn ATTRIBUTE_UNUSED;\n");
5528 printf (" int slot;\n");
5529 printf (" rtx candidate_insn;\n");
5530 printf (" int flags ATTRIBUTE_UNUSED;\n");
5532 printf (" rtx insn;\n");
5534 printf (" if (slot >= %d)\n", max_slots
);
5535 printf (" abort ();\n");
5538 /* If more than one delay type, find out which type the delay insn is. */
5542 attr
= find_attr ("*delay_type", 0);
5545 common_av
= find_most_used (attr
);
5547 printf (" insn = delay_insn;\n");
5548 printf (" switch (recog_memoized (insn))\n");
5551 sprintf (str
, " * %d;\n break;", max_slots
);
5552 for (av
= attr
->first_value
; av
; av
= av
->next
)
5553 if (av
!= common_av
)
5554 write_attr_case (attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
5556 write_attr_case (attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
5559 /* Ensure matched. Otherwise, shouldn't have been called. */
5560 printf (" if (slot < %d)\n", max_slots
);
5561 printf (" abort ();\n\n");
5564 /* If just one type of delay slot, write simple switch. */
5565 if (num_delays
== 1 && max_slots
== 1)
5567 printf (" insn = candidate_insn;\n");
5568 printf (" switch (recog_memoized (insn))\n");
5571 attr
= find_attr ("*delay_1_0", 0);
5574 common_av
= find_most_used (attr
);
5576 for (av
= attr
->first_value
; av
; av
= av
->next
)
5577 if (av
!= common_av
)
5578 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5580 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5586 /* Write a nested CASE. The first indicates which condition we need to
5587 test, and the inner CASE tests the condition. */
5588 printf (" insn = candidate_insn;\n");
5589 printf (" switch (slot)\n");
5592 for (delay
= delays
; delay
; delay
= delay
->next
)
5593 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
5595 printf (" case %d:\n",
5596 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
5597 printf (" switch (recog_memoized (insn))\n");
5600 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
5601 attr
= find_attr (str
, 0);
5604 common_av
= find_most_used (attr
);
5606 for (av
= attr
->first_value
; av
; av
= av
->next
)
5607 if (av
!= common_av
)
5608 write_attr_case (attr
, av
, 1, "return", ";", 8, true_rtx
);
5610 write_attr_case (attr
, common_av
, 0, "return", ";", 8, true_rtx
);
5614 printf (" default:\n");
5615 printf (" abort ();\n");
5622 /* Write routines to compute conflict cost for function units. Then write a
5623 table describing the available function units. */
5626 write_function_unit_info ()
5628 struct function_unit
*unit
;
5631 /* Write out conflict routines for function units. Don't bother writing
5632 one if there is only one issue delay value. */
5634 for (unit
= units
; unit
; unit
= unit
->next
)
5636 if (unit
->needs_blockage_function
)
5637 write_complex_function (unit
, "blockage", "block");
5639 /* If the minimum and maximum conflict costs are the same, there
5640 is only one value, so we don't need a function. */
5641 if (! unit
->needs_conflict_function
)
5643 unit
->default_cost
= make_numeric_value (unit
->issue_delay
.max
);
5647 /* The function first computes the case from the candidate insn. */
5648 unit
->default_cost
= make_numeric_value (0);
5649 write_complex_function (unit
, "conflict_cost", "cost");
5652 /* Now that all functions have been written, write the table describing
5653 the function units. The name is included for documentation purposes
5656 printf ("const struct function_unit_desc function_units[] = {\n");
5658 /* Write out the descriptions in numeric order, but don't force that order
5659 on the list. Doing so increases the runtime of genattrtab.c. */
5660 for (i
= 0; i
< num_units
; i
++)
5662 for (unit
= units
; unit
; unit
= unit
->next
)
5666 printf (" {\"%s\", %d, %d, %d, %s, %d, %s_unit_ready_cost, ",
5667 unit
->name
, 1 << unit
->num
, unit
->multiplicity
,
5668 unit
->simultaneity
, XSTR (unit
->default_cost
, 0),
5669 unit
->issue_delay
.max
, unit
->name
);
5671 if (unit
->needs_conflict_function
)
5672 printf ("%s_unit_conflict_cost, ", unit
->name
);
5676 printf ("%d, ", unit
->max_blockage
);
5678 if (unit
->needs_range_function
)
5679 printf ("%s_unit_blockage_range, ", unit
->name
);
5683 if (unit
->needs_blockage_function
)
5684 printf ("%s_unit_blockage", unit
->name
);
5692 printf ("{\"dummy\", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* a dummy element */");
5697 write_complex_function (unit
, name
, connection
)
5698 struct function_unit
*unit
;
5699 const char *name
, *connection
;
5701 struct attr_desc
*case_attr
, *attr
;
5702 struct attr_value
*av
, *common_av
;
5708 printf ("static int %s_unit_%s PARAMS ((rtx, rtx));\n", unit
->name
, name
);
5709 printf ("static int\n");
5710 printf ("%s_unit_%s (executing_insn, candidate_insn)\n", unit
->name
, name
);
5711 printf (" rtx executing_insn;\n");
5712 printf (" rtx candidate_insn;\n");
5714 printf (" rtx insn;\n");
5715 printf (" int casenum;\n\n");
5716 printf (" insn = executing_insn;\n");
5717 printf (" switch (recog_memoized (insn))\n");
5720 /* Write the `switch' statement to get the case value. */
5721 if (strlen (unit
->name
) + sizeof "*_cases" > 256)
5723 sprintf (str
, "*%s_cases", unit
->name
);
5724 case_attr
= find_attr (str
, 0);
5727 common_av
= find_most_used (case_attr
);
5729 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5730 if (av
!= common_av
)
5731 write_attr_case (case_attr
, av
, 1,
5732 "casenum =", ";", 4, unit
->condexp
);
5734 write_attr_case (case_attr
, common_av
, 0,
5735 "casenum =", ";", 4, unit
->condexp
);
5738 /* Now write an outer switch statement on each case. Then write
5739 the tests on the executing function within each. */
5740 printf (" insn = candidate_insn;\n");
5741 printf (" switch (casenum)\n");
5744 for (i
= 0; i
< unit
->num_opclasses
; i
++)
5746 /* Ensure using this case. */
5748 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5750 && contained_in_p (make_numeric_value (i
), av
->value
))
5756 printf (" case %d:\n", i
);
5757 sprintf (str
, "*%s_%s_%d", unit
->name
, connection
, i
);
5758 attr
= find_attr (str
, 0);
5762 /* If single value, just write it. */
5763 value
= find_single_value (attr
);
5765 write_attr_set (attr
, 6, value
, "return", ";\n", true_rtx
, -2, -2);
5768 common_av
= find_most_used (attr
);
5769 printf (" switch (recog_memoized (insn))\n");
5772 for (av
= attr
->first_value
; av
; av
= av
->next
)
5773 if (av
!= common_av
)
5774 write_attr_case (attr
, av
, 1,
5775 "return", ";", 8, unit
->condexp
);
5777 write_attr_case (attr
, common_av
, 0,
5778 "return", ";", 8, unit
->condexp
);
5783 /* This default case should not be needed, but gcc's analysis is not
5784 good enough to realize that the default case is not needed for the
5785 second switch statement. */
5786 printf (" default:\n abort ();\n");
5787 printf (" }\n}\n\n");
5790 /* This page contains miscellaneous utility routines. */
5792 /* Given a pointer to a (char *), return a malloc'ed string containing the
5793 next comma-separated element. Advance the pointer to after the string
5794 scanned, or the end-of-string. Return NULL if at end of string. */
5797 next_comma_elt (pstr
)
5802 start
= scan_comma_elt (pstr
);
5807 return attr_string (start
, *pstr
- start
);
5810 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
5811 is nonzero, build a new attribute, if one does not exist. */
5813 static struct attr_desc
*
5814 find_attr (name
, create
)
5818 struct attr_desc
*attr
;
5821 /* Before we resort to using `strcmp', see if the string address matches
5822 anywhere. In most cases, it should have been canonicalized to do so. */
5823 if (name
== alternative_name
)
5826 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
5827 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5828 if (name
== attr
->name
)
5831 /* Otherwise, do it the slow way. */
5832 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5833 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
5839 attr
= (struct attr_desc
*) oballoc (sizeof (struct attr_desc
));
5840 attr
->name
= attr_string (name
, strlen (name
));
5841 attr
->first_value
= attr
->default_val
= NULL
;
5842 attr
->is_numeric
= attr
->negative_ok
= attr
->is_const
= attr
->is_special
= 0;
5843 attr
->unsigned_p
= attr
->func_units_p
= attr
->blockage_p
= 0;
5844 attr
->next
= attrs
[index
];
5845 attrs
[index
] = attr
;
5850 /* Create internal attribute with the given default value. */
5853 make_internal_attr (name
, value
, special
)
5858 struct attr_desc
*attr
;
5860 attr
= find_attr (name
, 1);
5861 if (attr
->default_val
)
5864 attr
->is_numeric
= 1;
5866 attr
->is_special
= (special
& 1) != 0;
5867 attr
->negative_ok
= (special
& 2) != 0;
5868 attr
->unsigned_p
= (special
& 4) != 0;
5869 attr
->func_units_p
= (special
& 8) != 0;
5870 attr
->blockage_p
= (special
& 16) != 0;
5871 attr
->default_val
= get_attr_value (value
, attr
, -2);
5874 /* Find the most used value of an attribute. */
5876 static struct attr_value
*
5877 find_most_used (attr
)
5878 struct attr_desc
*attr
;
5880 struct attr_value
*av
;
5881 struct attr_value
*most_used
;
5887 for (av
= attr
->first_value
; av
; av
= av
->next
)
5888 if (av
->num_insns
> nuses
)
5889 nuses
= av
->num_insns
, most_used
= av
;
5894 /* If an attribute only has a single value used, return it. Otherwise
5898 find_single_value (attr
)
5899 struct attr_desc
*attr
;
5901 struct attr_value
*av
;
5904 unique_value
= NULL
;
5905 for (av
= attr
->first_value
; av
; av
= av
->next
)
5911 unique_value
= av
->value
;
5914 return unique_value
;
5917 /* Return (attr_value "n") */
5920 make_numeric_value (n
)
5923 static rtx int_values
[20];
5930 if (n
< 20 && int_values
[n
])
5931 return int_values
[n
];
5933 p
= attr_printf (MAX_DIGITS
, "%d", n
);
5934 exp
= attr_rtx (CONST_STRING
, p
);
5937 int_values
[n
] = exp
;
5943 extend_range (range
, min
, max
)
5944 struct range
*range
;
5948 if (range
->min
> min
)
5950 if (range
->max
< max
)
5955 copy_rtx_unchanging (orig
)
5963 if (ATTR_IND_SIMPLIFIED_P (orig
) || ATTR_CURR_SIMPLIFIED_P (orig
))
5966 ATTR_CURR_SIMPLIFIED_P (orig
) = 1;
5970 code
= GET_CODE (orig
);
5983 copy
= rtx_alloc (code
);
5984 PUT_MODE (copy
, GET_MODE (orig
));
5985 ATTR_IND_SIMPLIFIED_P (copy
) = 1;
5987 memcpy (&XEXP (copy
, 0), &XEXP (orig
, 0),
5988 GET_RTX_LENGTH (GET_CODE (copy
)) * sizeof (rtx
));
5993 /* Determine if an insn has a constant number of delay slots, i.e., the
5994 number of delay slots is not a function of the length of the insn. */
5997 write_const_num_delay_slots ()
5999 struct attr_desc
*attr
= find_attr ("*num_delay_slots", 0);
6000 struct attr_value
*av
;
6001 struct insn_ent
*ie
;
6005 printf ("int\nconst_num_delay_slots (insn)\n");
6006 printf (" rtx insn;\n");
6008 printf (" switch (recog_memoized (insn))\n");
6011 for (av
= attr
->first_value
; av
; av
= av
->next
)
6014 walk_attr_value (av
->value
);
6017 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
6018 if (ie
->insn_code
!= -1)
6019 printf (" case %d:\n", ie
->insn_code
);
6020 printf (" return 0;\n");
6024 printf (" default:\n");
6025 printf (" return 1;\n");
6026 printf (" }\n}\n\n");
6030 extern int main
PARAMS ((int, char **));
6038 struct attr_desc
*attr
;
6039 struct insn_def
*id
;
6043 progname
= "genattrtab";
6046 fatal ("no input file name");
6048 if (init_md_reader_args (argc
, argv
) != SUCCESS_EXIT_CODE
)
6049 return (FATAL_EXIT_CODE
);
6051 obstack_init (hash_obstack
);
6052 obstack_init (temp_obstack
);
6054 /* Set up true and false rtx's */
6055 true_rtx
= rtx_alloc (CONST_INT
);
6056 XWINT (true_rtx
, 0) = 1;
6057 false_rtx
= rtx_alloc (CONST_INT
);
6058 XWINT (false_rtx
, 0) = 0;
6059 ATTR_IND_SIMPLIFIED_P (true_rtx
) = ATTR_IND_SIMPLIFIED_P (false_rtx
) = 1;
6060 ATTR_PERMANENT_P (true_rtx
) = ATTR_PERMANENT_P (false_rtx
) = 1;
6062 alternative_name
= attr_string ("alternative", strlen ("alternative"));
6064 printf ("/* Generated automatically by the program `genattrtab'\n\
6065 from the machine description file `md'. */\n\n");
6067 /* Read the machine description. */
6069 initiate_automaton_gen (argc
, argv
);
6074 desc
= read_md_rtx (&lineno
, &insn_code_number
);
6078 switch (GET_CODE (desc
))
6081 case DEFINE_PEEPHOLE
:
6082 case DEFINE_ASM_ATTRIBUTES
:
6083 gen_insn (desc
, lineno
);
6087 gen_attr (desc
, lineno
);
6091 gen_delay (desc
, lineno
);
6094 case DEFINE_FUNCTION_UNIT
:
6095 gen_unit (desc
, lineno
);
6098 case DEFINE_CPU_UNIT
:
6099 gen_cpu_unit (desc
);
6102 case DEFINE_QUERY_CPU_UNIT
:
6103 gen_query_cpu_unit (desc
);
6111 gen_excl_set (desc
);
6115 gen_presence_set (desc
);
6119 gen_absence_set (desc
);
6122 case DEFINE_AUTOMATON
:
6123 gen_automaton (desc
);
6126 case AUTOMATA_OPTION
:
6127 gen_automata_option (desc
);
6130 case DEFINE_RESERVATION
:
6134 case DEFINE_INSN_RESERVATION
:
6135 gen_insn_reserv (desc
);
6141 if (GET_CODE (desc
) != DEFINE_ASM_ATTRIBUTES
)
6142 insn_index_number
++;
6146 return FATAL_EXIT_CODE
;
6150 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
6151 if (! got_define_asm_attributes
)
6153 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
6154 XVEC (tem
, 0) = rtvec_alloc (0);
6158 /* Expand DEFINE_DELAY information into new attribute. */
6162 if (num_units
|| num_dfa_decls
)
6164 /* Expand DEFINE_FUNCTION_UNIT information into new attributes. */
6166 /* Build DFA, output some functions and expand DFA information
6167 into new attributes. */
6171 printf ("#include \"config.h\"\n");
6172 printf ("#include \"system.h\"\n");
6173 printf ("#include \"coretypes.h\"\n");
6174 printf ("#include \"tm.h\"\n");
6175 printf ("#include \"rtl.h\"\n");
6176 printf ("#include \"tm_p.h\"\n");
6177 printf ("#include \"insn-config.h\"\n");
6178 printf ("#include \"recog.h\"\n");
6179 printf ("#include \"regs.h\"\n");
6180 printf ("#include \"real.h\"\n");
6181 printf ("#include \"output.h\"\n");
6182 printf ("#include \"insn-attr.h\"\n");
6183 printf ("#include \"toplev.h\"\n");
6184 printf ("#include \"flags.h\"\n");
6185 printf ("#include \"function.h\"\n");
6187 printf ("#define operands recog_data.operand\n\n");
6189 /* Make `insn_alternatives'. */
6190 insn_alternatives
= (int *) oballoc (insn_code_number
* sizeof (int));
6191 for (id
= defs
; id
; id
= id
->next
)
6192 if (id
->insn_code
>= 0)
6193 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
6195 /* Make `insn_n_alternatives'. */
6196 insn_n_alternatives
= (int *) oballoc (insn_code_number
* sizeof (int));
6197 for (id
= defs
; id
; id
= id
->next
)
6198 if (id
->insn_code
>= 0)
6199 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
6201 /* Prepare to write out attribute subroutines by checking everything stored
6202 away and building the attribute cases. */
6206 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6207 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6208 attr
->default_val
->value
6209 = check_attr_value (attr
->default_val
->value
, attr
);
6212 return FATAL_EXIT_CODE
;
6214 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6215 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6218 /* Construct extra attributes for `length'. */
6219 make_length_attrs ();
6221 /* Perform any possible optimizations to speed up compilation. */
6224 /* Now write out all the `gen_attr_...' routines. Do these before the
6225 special routines (specifically before write_function_unit_info), so
6226 that they get defined before they are used. */
6228 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6229 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6231 if (! attr
->is_special
&& ! attr
->is_const
)
6232 write_attr_get (attr
);
6235 /* Write out delay eligibility information, if DEFINE_DELAY present.
6236 (The function to compute the number of delay slots will be written
6240 write_eligible_delay ("delay");
6241 if (have_annul_true
)
6242 write_eligible_delay ("annul_true");
6243 if (have_annul_false
)
6244 write_eligible_delay ("annul_false");
6247 if (num_units
|| num_dfa_decls
)
6249 /* Write out information about function units. */
6250 write_function_unit_info ();
6251 /* Output code for pipeline hazards recognition based on DFA
6252 (deterministic finite state automata. */
6256 /* Write out constant delay slot info */
6257 write_const_num_delay_slots ();
6259 write_length_unit_log ();
6262 return (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);
6265 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
6267 get_insn_name (code
)
6268 int code ATTRIBUTE_UNUSED
;