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))
107 #include "gensupport.h"
109 #ifdef HAVE_SYS_RESOURCE_H
110 # include <sys/resource.h>
113 /* We must include obstack.h after <sys/time.h>, to avoid lossage with
114 /usr/include/sys/stdtypes.h on Sun OS 4.x. */
118 #include "genattrtab.h"
120 static struct obstack obstack1
, obstack2
;
121 struct obstack
*hash_obstack
= &obstack1
;
122 struct obstack
*temp_obstack
= &obstack2
;
124 #define obstack_chunk_alloc xmalloc
125 #define obstack_chunk_free free
127 /* enough space to reserve for printing out ints */
128 #define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
130 /* Define structures used to record attributes and values. */
132 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
133 encountered, we store all the relevant information into a
134 `struct insn_def'. This is done to allow attribute definitions to occur
135 anywhere in the file. */
139 struct insn_def
*next
; /* Next insn in chain. */
140 rtx def
; /* The DEFINE_... */
141 int insn_code
; /* Instruction number. */
142 int insn_index
; /* Expression numer in file, for errors. */
143 int lineno
; /* Line number. */
144 int num_alternatives
; /* Number of alternatives. */
145 int vec_idx
; /* Index of attribute vector in `def'. */
148 /* Once everything has been read in, we store in each attribute value a list
149 of insn codes that have that value. Here is the structure used for the
154 struct insn_ent
*next
; /* Next in chain. */
155 int insn_code
; /* Instruction number. */
156 int insn_index
; /* Index of definition in file */
157 int lineno
; /* Line number. */
160 /* Each value of an attribute (either constant or computed) is assigned a
161 structure which is used as the listhead of the insns that have that
166 rtx value
; /* Value of attribute. */
167 struct attr_value
*next
; /* Next attribute value in chain. */
168 struct insn_ent
*first_insn
; /* First insn with this value. */
169 int num_insns
; /* Number of insns with this value. */
170 int has_asm_insn
; /* True if this value used for `asm' insns */
173 /* Structure for each attribute. */
177 char *name
; /* Name of attribute. */
178 struct attr_desc
*next
; /* Next attribute. */
179 unsigned is_numeric
: 1; /* Values of this attribute are numeric. */
180 unsigned negative_ok
: 1; /* Allow negative numeric values. */
181 unsigned unsigned_p
: 1; /* Make the output function unsigned int. */
182 unsigned is_const
: 1; /* Attribute value constant for each run. */
183 unsigned is_special
: 1; /* Don't call `write_attr_set'. */
184 unsigned func_units_p
: 1; /* this is the function_units attribute */
185 unsigned blockage_p
: 1; /* this is the blockage range function */
186 struct attr_value
*first_value
; /* First value of this attribute. */
187 struct attr_value
*default_val
; /* Default value for this attribute. */
188 int lineno
; /* Line number. */
191 #define NULL_ATTR (struct attr_desc *) NULL
193 /* A range of values. */
201 /* Structure for each DEFINE_DELAY. */
205 rtx def
; /* DEFINE_DELAY expression. */
206 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
207 int num
; /* Number of DEFINE_DELAY, starting at 1. */
208 int lineno
; /* Line number. */
211 /* Record information about each DEFINE_FUNCTION_UNIT. */
213 struct function_unit_op
215 rtx condexp
; /* Expression TRUE for applicable insn. */
216 struct function_unit_op
*next
; /* Next operation for this function unit. */
217 int num
; /* Ordinal for this operation type in unit. */
218 int ready
; /* Cost until data is ready. */
219 int issue_delay
; /* Cost until unit can accept another insn. */
220 rtx conflict_exp
; /* Expression TRUE for insns incurring issue delay. */
221 rtx issue_exp
; /* Expression computing issue delay. */
222 int lineno
; /* Line number. */
225 /* Record information about each function unit mentioned in a
226 DEFINE_FUNCTION_UNIT. */
230 const char *name
; /* Function unit name. */
231 struct function_unit
*next
; /* Next function unit. */
232 int num
; /* Ordinal of this unit type. */
233 int multiplicity
; /* Number of units of this type. */
234 int simultaneity
; /* Maximum number of simultaneous insns
235 on this function unit or 0 if unlimited. */
236 rtx condexp
; /* Expression TRUE for insn needing unit. */
237 int num_opclasses
; /* Number of different operation types. */
238 struct function_unit_op
*ops
; /* Pointer to first operation type. */
239 int needs_conflict_function
; /* Nonzero if a conflict function required. */
240 int needs_blockage_function
; /* Nonzero if a blockage function required. */
241 int needs_range_function
; /* Nonzero if blockage range function needed. */
242 rtx default_cost
; /* Conflict cost, if constant. */
243 struct range issue_delay
; /* Range of issue delay values. */
244 int max_blockage
; /* Maximum time an insn blocks the unit. */
245 int first_lineno
; /* First seen line number. */
248 /* Listheads of above structures. */
250 /* This one is indexed by the first character of the attribute name. */
251 #define MAX_ATTRS_INDEX 256
252 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
253 static struct insn_def
*defs
;
254 static struct delay_desc
*delays
;
255 static struct function_unit
*units
;
257 /* An expression where all the unknown terms are EQ_ATTR tests can be
258 rearranged into a COND provided we can enumerate all possible
259 combinations of the unknown values. The set of combinations become the
260 tests of the COND; the value of the expression given that combination is
261 computed and becomes the corresponding value. To do this, we must be
262 able to enumerate all values for each attribute used in the expression
263 (currently, we give up if we find a numeric attribute).
265 If the set of EQ_ATTR tests used in an expression tests the value of N
266 different attributes, the list of all possible combinations can be made
267 by walking the N-dimensional attribute space defined by those
268 attributes. We record each of these as a struct dimension.
270 The algorithm relies on sharing EQ_ATTR nodes: if two nodes in an
271 expression are the same, the will also have the same address. We find
272 all the EQ_ATTR nodes by marking them ATTR_EQ_ATTR_P. This bit later
273 represents the value of an EQ_ATTR node, so once all nodes are marked,
274 they are also given an initial value of FALSE.
276 We then separate the set of EQ_ATTR nodes into dimensions for each
277 attribute and put them on the VALUES list. Terms are added as needed by
278 `add_values_to_cover' so that all possible values of the attribute are
281 Each dimension also has a current value. This is the node that is
282 currently considered to be TRUE. If this is one of the nodes added by
283 `add_values_to_cover', all the EQ_ATTR tests in the original expression
284 will be FALSE. Otherwise, only the CURRENT_VALUE will be true.
286 NUM_VALUES is simply the length of the VALUES list and is there for
289 Once the dimensions are created, the algorithm enumerates all possible
290 values and computes the current value of the given expression. */
294 struct attr_desc
*attr
; /* Attribute for this dimension. */
295 rtx values
; /* List of attribute values used. */
296 rtx current_value
; /* Position in the list for the TRUE value. */
297 int num_values
; /* Length of the values list. */
300 /* Other variables. */
302 static int insn_code_number
;
303 static int insn_index_number
;
304 static int got_define_asm_attributes
;
305 static int must_extract
;
306 static int must_constrain
;
307 static int address_used
;
308 static int length_used
;
309 static int num_delays
;
310 static int have_annul_true
, have_annul_false
;
311 static int num_units
, num_unit_opclasses
;
312 static int num_insn_ents
;
316 /* Used as operand to `operate_exp': */
318 enum operator {PLUS_OP
, MINUS_OP
, POS_MINUS_OP
, EQ_OP
, OR_OP
, ORX_OP
, MAX_OP
, MIN_OP
, RANGE_OP
};
320 /* Stores, for each insn code, the number of constraint alternatives. */
322 static int *insn_n_alternatives
;
324 /* Stores, for each insn code, a bitmap that has bits on for each possible
327 static int *insn_alternatives
;
329 /* If nonzero, assume that the `alternative' attr has this value.
330 This is the hashed, unique string for the numeral
331 whose value is chosen alternative. */
333 static const char *current_alternative_string
;
335 /* Used to simplify expressions. */
337 static rtx true_rtx
, false_rtx
;
339 /* Used to reduce calls to `strcmp' */
341 static char *alternative_name
;
343 /* Indicate that REG_DEAD notes are valid if dead_or_set_p is ever
346 int reload_completed
= 0;
348 /* Some machines test `optimize' in macros called from rtlanal.c, so we need
349 to define it here. */
353 /* Simplify an expression. Only call the routine if there is something to
355 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
356 (ATTR_IND_SIMPLIFIED_P (EXP) || ATTR_CURR_SIMPLIFIED_P (EXP) ? (EXP) \
357 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
359 /* Simplify (eq_attr ("alternative") ...)
360 when we are working with a particular alternative. */
361 #define SIMPLIFY_ALTERNATIVE(EXP) \
362 if (current_alternative_string \
363 && GET_CODE ((EXP)) == EQ_ATTR \
364 && XSTR ((EXP), 0) == alternative_name) \
365 (EXP) = (XSTR ((EXP), 1) == current_alternative_string \
366 ? true_rtx : false_rtx);
368 /* These are referenced by rtlanal.c and hence need to be defined somewhere.
369 They won't actually be used. */
371 rtx global_rtl
[GR_MAX
];
372 rtx pic_offset_table_rtx
;
374 static void attr_hash_add_rtx
PARAMS ((int, rtx
));
375 static void attr_hash_add_string
PARAMS ((int, char *));
376 static rtx attr_rtx
PARAMS ((enum rtx_code
, ...));
377 static rtx attr_rtx_1
PARAMS ((enum rtx_code
, va_list));
378 static char *attr_string
PARAMS ((const char *, int));
379 static rtx check_attr_value
PARAMS ((rtx
, struct attr_desc
*));
380 static rtx convert_set_attr_alternative
PARAMS ((rtx
, struct insn_def
*));
381 static rtx convert_set_attr
PARAMS ((rtx
, struct insn_def
*));
382 static void check_defs
PARAMS ((void));
384 static rtx convert_const_symbol_ref
PARAMS ((rtx
, struct attr_desc
*));
386 static rtx make_canonical
PARAMS ((struct attr_desc
*, rtx
));
387 static struct attr_value
*get_attr_value
PARAMS ((rtx
, struct attr_desc
*, int));
388 static rtx copy_rtx_unchanging
PARAMS ((rtx
));
389 static rtx copy_boolean
PARAMS ((rtx
));
390 static void expand_delays
PARAMS ((void));
391 static rtx operate_exp
PARAMS ((enum operator, rtx
, rtx
));
392 static void expand_units
PARAMS ((void));
393 static rtx simplify_knowing
PARAMS ((rtx
, rtx
));
394 static rtx encode_units_mask
PARAMS ((rtx
));
395 static void fill_attr
PARAMS ((struct attr_desc
*));
396 /* dpx2 compiler chokes if we specify the arg types of the args. */
397 static rtx substitute_address
PARAMS ((rtx
, rtx (*) (rtx
), rtx (*) (rtx
)));
398 static void make_length_attrs
PARAMS ((void));
399 static rtx identity_fn
PARAMS ((rtx
));
400 static rtx zero_fn
PARAMS ((rtx
));
401 static rtx one_fn
PARAMS ((rtx
));
402 static rtx max_fn
PARAMS ((rtx
));
403 static void write_length_unit_log
PARAMS ((void));
404 static rtx simplify_cond
PARAMS ((rtx
, int, int));
406 static rtx simplify_by_alternatives
PARAMS ((rtx
, int, int));
408 static rtx simplify_by_exploding
PARAMS ((rtx
));
409 static int find_and_mark_used_attributes
PARAMS ((rtx
, rtx
*, int *));
410 static void unmark_used_attributes
PARAMS ((rtx
, struct dimension
*, int));
411 static int add_values_to_cover
PARAMS ((struct dimension
*));
412 static int increment_current_value
PARAMS ((struct dimension
*, int));
413 static rtx test_for_current_value
PARAMS ((struct dimension
*, int));
414 static rtx simplify_with_current_value
PARAMS ((rtx
, struct dimension
*, int));
415 static rtx simplify_with_current_value_aux
PARAMS ((rtx
));
416 static void clear_struct_flag
PARAMS ((rtx
));
417 static int count_sub_rtxs
PARAMS ((rtx
, int));
418 static void remove_insn_ent
PARAMS ((struct attr_value
*, struct insn_ent
*));
419 static void insert_insn_ent
PARAMS ((struct attr_value
*, struct insn_ent
*));
420 static rtx insert_right_side
PARAMS ((enum rtx_code
, rtx
, rtx
, int, int));
421 static rtx make_alternative_compare
PARAMS ((int));
422 static int compute_alternative_mask
PARAMS ((rtx
, enum rtx_code
));
423 static rtx evaluate_eq_attr
PARAMS ((rtx
, rtx
, int, int));
424 static rtx simplify_and_tree
PARAMS ((rtx
, rtx
*, int, int));
425 static rtx simplify_or_tree
PARAMS ((rtx
, rtx
*, int, int));
426 static rtx simplify_test_exp
PARAMS ((rtx
, int, int));
427 static rtx simplify_test_exp_in_temp
PARAMS ((rtx
, int, int));
428 static void optimize_attrs
PARAMS ((void));
429 static void gen_attr
PARAMS ((rtx
, int));
430 static int count_alternatives
PARAMS ((rtx
));
431 static int compares_alternatives_p
PARAMS ((rtx
));
432 static int contained_in_p
PARAMS ((rtx
, rtx
));
433 static void gen_insn
PARAMS ((rtx
, int));
434 static void gen_delay
PARAMS ((rtx
, int));
435 static void gen_unit
PARAMS ((rtx
, int));
436 static void write_test_expr
PARAMS ((rtx
, int));
437 static int max_attr_value
PARAMS ((rtx
, int*));
438 static int or_attr_value
PARAMS ((rtx
, int*));
439 static void walk_attr_value
PARAMS ((rtx
));
440 static void write_attr_get
PARAMS ((struct attr_desc
*));
441 static rtx eliminate_known_true
PARAMS ((rtx
, rtx
, int, int));
442 static void write_attr_set
PARAMS ((struct attr_desc
*, int, rtx
,
443 const char *, const char *, rtx
,
445 static void write_attr_case
PARAMS ((struct attr_desc
*, struct attr_value
*,
446 int, const char *, const char *, int, rtx
));
447 static void write_unit_name
PARAMS ((const char *, int, const char *));
448 static void write_attr_valueq
PARAMS ((struct attr_desc
*, const char *));
449 static void write_attr_value
PARAMS ((struct attr_desc
*, rtx
));
450 static void write_upcase
PARAMS ((const char *));
451 static void write_indent
PARAMS ((int));
452 static void write_eligible_delay
PARAMS ((const char *));
453 static void write_function_unit_info
PARAMS ((void));
454 static void write_complex_function
PARAMS ((struct function_unit
*, const char *,
456 static int write_expr_attr_cache
PARAMS ((rtx
, struct attr_desc
*));
457 static void write_toplevel_expr
PARAMS ((rtx
));
458 static void write_const_num_delay_slots
PARAMS ((void));
459 static char *next_comma_elt
PARAMS ((const char **));
460 static struct attr_desc
*find_attr
PARAMS ((const char *, int));
461 static struct attr_value
*find_most_used
PARAMS ((struct attr_desc
*));
462 static rtx find_single_value
PARAMS ((struct attr_desc
*));
463 static void extend_range
PARAMS ((struct range
*, int, int));
464 static rtx attr_eq
PARAMS ((const char *, const char *));
465 static const char *attr_numeral
PARAMS ((int));
466 static int attr_equal_p
PARAMS ((rtx
, rtx
));
467 static rtx attr_copy_rtx
PARAMS ((rtx
));
468 static int attr_rtx_cost
PARAMS ((rtx
));
470 #define oballoc(size) obstack_alloc (hash_obstack, size)
472 /* Hash table for sharing RTL and strings. */
474 /* Each hash table slot is a bucket containing a chain of these structures.
475 Strings are given negative hash codes; RTL expressions are given positive
480 struct attr_hash
*next
; /* Next structure in the bucket. */
481 int hashcode
; /* Hash code of this rtx or string. */
484 char *str
; /* The string (negative hash codes) */
485 rtx rtl
; /* or the RTL recorded here. */
489 /* Now here is the hash table. When recording an RTL, it is added to
490 the slot whose index is the hash code mod the table size. Note
491 that the hash table is used for several kinds of RTL (see attr_rtx)
492 and for strings. While all these live in the same table, they are
493 completely independent, and the hash code is computed differently
496 #define RTL_HASH_SIZE 4093
497 struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
499 /* Here is how primitive or already-shared RTL's hash
501 #define RTL_HASH(RTL) ((long) (RTL) & 0777777)
503 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
506 attr_hash_add_rtx (hashcode
, rtl
)
512 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
513 sizeof (struct attr_hash
));
514 h
->hashcode
= hashcode
;
516 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
517 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
520 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
523 attr_hash_add_string (hashcode
, str
)
529 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
530 sizeof (struct attr_hash
));
531 h
->hashcode
= -hashcode
;
533 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
534 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
537 /* Generate an RTL expression, but avoid duplicates.
538 Set the ATTR_PERMANENT_P flag for these permanent objects.
540 In some cases we cannot uniquify; then we return an ordinary
541 impermanent rtx with ATTR_PERMANENT_P clear.
543 Args are like gen_rtx, but without the mode:
545 rtx attr_rtx (code, [element1, ..., elementn]) */
552 rtx rt_val
= NULL_RTX
;/* RTX to return to caller... */
555 struct obstack
*old_obstack
= rtl_obstack
;
557 /* For each of several cases, search the hash table for an existing entry.
558 Use that entry if one is found; otherwise create a new RTL and add it
561 if (GET_RTX_CLASS (code
) == '1')
563 rtx arg0
= va_arg (p
, rtx
);
565 /* A permanent object cannot point to impermanent ones. */
566 if (! ATTR_PERMANENT_P (arg0
))
568 rt_val
= rtx_alloc (code
);
569 XEXP (rt_val
, 0) = arg0
;
573 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
574 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
575 if (h
->hashcode
== hashcode
576 && GET_CODE (h
->u
.rtl
) == code
577 && XEXP (h
->u
.rtl
, 0) == arg0
)
582 rtl_obstack
= hash_obstack
;
583 rt_val
= rtx_alloc (code
);
584 XEXP (rt_val
, 0) = arg0
;
587 else if (GET_RTX_CLASS (code
) == 'c'
588 || GET_RTX_CLASS (code
) == '2'
589 || GET_RTX_CLASS (code
) == '<')
591 rtx arg0
= va_arg (p
, rtx
);
592 rtx arg1
= va_arg (p
, rtx
);
594 /* A permanent object cannot point to impermanent ones. */
595 if (! ATTR_PERMANENT_P (arg0
) || ! ATTR_PERMANENT_P (arg1
))
597 rt_val
= rtx_alloc (code
);
598 XEXP (rt_val
, 0) = arg0
;
599 XEXP (rt_val
, 1) = arg1
;
603 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
604 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
605 if (h
->hashcode
== hashcode
606 && GET_CODE (h
->u
.rtl
) == code
607 && XEXP (h
->u
.rtl
, 0) == arg0
608 && XEXP (h
->u
.rtl
, 1) == arg1
)
613 rtl_obstack
= hash_obstack
;
614 rt_val
= rtx_alloc (code
);
615 XEXP (rt_val
, 0) = arg0
;
616 XEXP (rt_val
, 1) = arg1
;
619 else if (GET_RTX_LENGTH (code
) == 1
620 && GET_RTX_FORMAT (code
)[0] == 's')
622 char *arg0
= va_arg (p
, char *);
624 if (code
== SYMBOL_REF
)
625 arg0
= attr_string (arg0
, strlen (arg0
));
627 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
628 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
629 if (h
->hashcode
== hashcode
630 && GET_CODE (h
->u
.rtl
) == code
631 && XSTR (h
->u
.rtl
, 0) == arg0
)
636 rtl_obstack
= hash_obstack
;
637 rt_val
= rtx_alloc (code
);
638 XSTR (rt_val
, 0) = arg0
;
641 else if (GET_RTX_LENGTH (code
) == 2
642 && GET_RTX_FORMAT (code
)[0] == 's'
643 && GET_RTX_FORMAT (code
)[1] == 's')
645 char *arg0
= va_arg (p
, char *);
646 char *arg1
= va_arg (p
, char *);
648 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
649 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
650 if (h
->hashcode
== hashcode
651 && GET_CODE (h
->u
.rtl
) == code
652 && XSTR (h
->u
.rtl
, 0) == arg0
653 && XSTR (h
->u
.rtl
, 1) == arg1
)
658 rtl_obstack
= hash_obstack
;
659 rt_val
= rtx_alloc (code
);
660 XSTR (rt_val
, 0) = arg0
;
661 XSTR (rt_val
, 1) = arg1
;
664 else if (code
== CONST_INT
)
666 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
676 int i
; /* Array indices... */
677 const char *fmt
; /* Current rtx's format... */
679 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
681 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
682 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
686 case '0': /* Unused field. */
689 case 'i': /* An integer? */
690 XINT (rt_val
, i
) = va_arg (p
, int);
693 case 'w': /* A wide integer? */
694 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
697 case 's': /* A string? */
698 XSTR (rt_val
, i
) = va_arg (p
, char *);
701 case 'e': /* An expression? */
702 case 'u': /* An insn? Same except when printing. */
703 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
706 case 'E': /* An RTX vector? */
707 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
717 rtl_obstack
= old_obstack
;
718 attr_hash_add_rtx (hashcode
, rt_val
);
719 ATTR_PERMANENT_P (rt_val
) = 1;
724 attr_rtx
VPARAMS ((enum rtx_code code
, ...))
729 VA_FIXEDARG (p
, enum rtx_code
, code
);
730 result
= attr_rtx_1 (code
, p
);
735 /* Create a new string printed with the printf line arguments into a space
736 of at most LEN bytes:
738 rtx attr_printf (len, format, [arg1, ..., argn]) */
741 attr_printf
VPARAMS ((unsigned int len
, const char *fmt
, ...))
746 VA_FIXEDARG (p
, unsigned int, len
);
747 VA_FIXEDARG (p
, const char *, fmt
);
749 if (len
> sizeof str
- 1) /* Leave room for \0. */
752 vsprintf (str
, fmt
, p
);
755 return attr_string (str
, strlen (str
));
759 attr_eq (name
, value
)
760 const char *name
, *value
;
762 return attr_rtx (EQ_ATTR
, attr_string (name
, strlen (name
)),
763 attr_string (value
, strlen (value
)));
770 return XSTR (make_numeric_value (n
), 0);
773 /* Return a permanent (possibly shared) copy of a string STR (not assumed
774 to be null terminated) with LEN bytes. */
777 attr_string (str
, len
)
786 /* Compute the hash code. */
787 hashcode
= (len
+ 1) * 613 + (unsigned) str
[0];
788 for (i
= 1; i
<= len
; i
+= 2)
789 hashcode
= ((hashcode
* 613) + (unsigned) str
[i
]);
791 hashcode
= -hashcode
;
793 /* Search the table for the string. */
794 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
795 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
796 && !strncmp (h
->u
.str
, str
, len
))
797 return h
->u
.str
; /* <-- return if found. */
799 /* Not found; create a permanent copy and add it to the hash table. */
800 new_str
= (char *) obstack_alloc (hash_obstack
, len
+ 1);
801 memcpy (new_str
, str
, len
);
803 attr_hash_add_string (hashcode
, new_str
);
805 return new_str
; /* Return the new string. */
808 /* Check two rtx's for equality of contents,
809 taking advantage of the fact that if both are hashed
810 then they can't be equal unless they are the same object. */
816 return (x
== y
|| (! (ATTR_PERMANENT_P (x
) && ATTR_PERMANENT_P (y
))
817 && rtx_equal_p (x
, y
)));
820 /* Copy an attribute value expression,
821 descending to all depths, but not copying any
822 permanent hashed subexpressions. */
831 const char *format_ptr
;
833 /* No need to copy a permanent object. */
834 if (ATTR_PERMANENT_P (orig
))
837 code
= GET_CODE (orig
);
856 copy
= rtx_alloc (code
);
857 PUT_MODE (copy
, GET_MODE (orig
));
858 ATTR_IND_SIMPLIFIED_P (copy
) = ATTR_IND_SIMPLIFIED_P (orig
);
859 ATTR_CURR_SIMPLIFIED_P (copy
) = ATTR_CURR_SIMPLIFIED_P (orig
);
860 ATTR_PERMANENT_P (copy
) = ATTR_PERMANENT_P (orig
);
861 ATTR_EQ_ATTR_P (copy
) = ATTR_EQ_ATTR_P (orig
);
863 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
865 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
867 switch (*format_ptr
++)
870 XEXP (copy
, i
) = XEXP (orig
, i
);
871 if (XEXP (orig
, i
) != NULL
)
872 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
877 XVEC (copy
, i
) = XVEC (orig
, i
);
878 if (XVEC (orig
, i
) != NULL
)
880 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
881 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
882 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
888 XINT (copy
, i
) = XINT (orig
, i
);
892 XWINT (copy
, i
) = XWINT (orig
, i
);
897 XSTR (copy
, i
) = XSTR (orig
, i
);
907 /* Given a test expression for an attribute, ensure it is validly formed.
908 IS_CONST indicates whether the expression is constant for each compiler
909 run (a constant expression may not test any particular insn).
911 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
912 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
913 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
915 Update the string address in EQ_ATTR expression to be the same used
916 in the attribute (or `alternative_name') to speed up subsequent
917 `find_attr' calls and eliminate most `strcmp' calls.
919 Return the new expression, if any. */
922 check_attr_test (exp
, is_const
, lineno
)
927 struct attr_desc
*attr
;
928 struct attr_value
*av
;
929 const char *name_ptr
, *p
;
932 switch (GET_CODE (exp
))
935 /* Handle negation test. */
936 if (XSTR (exp
, 1)[0] == '!')
937 return check_attr_test (attr_rtx (NOT
,
938 attr_eq (XSTR (exp
, 0),
942 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
944 attr
= find_attr (XSTR (exp
, 0), 0);
947 if (! strcmp (XSTR (exp
, 0), "alternative"))
949 XSTR (exp
, 0) = alternative_name
;
950 /* This can't be simplified any further. */
951 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
955 fatal ("unknown attribute `%s' in EQ_ATTR", XSTR (exp
, 0));
958 if (is_const
&& ! attr
->is_const
)
959 fatal ("constant expression uses insn attribute `%s' in EQ_ATTR",
962 /* Copy this just to make it permanent,
963 so expressions using it can be permanent too. */
964 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
966 /* It shouldn't be possible to simplify the value given to a
967 constant attribute, so don't expand this until it's time to
968 write the test expression. */
970 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
972 if (attr
->is_numeric
)
974 for (p
= XSTR (exp
, 1); *p
; p
++)
976 fatal ("attribute `%s' takes only numeric values",
981 for (av
= attr
->first_value
; av
; av
= av
->next
)
982 if (GET_CODE (av
->value
) == CONST_STRING
983 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
987 fatal ("unknown value `%s' for `%s' attribute",
988 XSTR (exp
, 1), XSTR (exp
, 0));
993 /* Make an IOR tree of the possible values. */
995 name_ptr
= XSTR (exp
, 1);
996 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
998 newexp
= attr_eq (XSTR (exp
, 0), p
);
999 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
1002 return check_attr_test (orexp
, is_const
, lineno
);
1010 /* Either TRUE or FALSE. */
1018 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
1019 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
, lineno
);
1023 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
1029 fatal ("RTL operator \"%s\" not valid in constant attribute test",
1030 GET_RTX_NAME (GET_CODE (exp
)));
1031 /* These cases can't be simplified. */
1032 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1035 case LE
: case LT
: case GT
: case GE
:
1036 case LEU
: case LTU
: case GTU
: case GEU
:
1038 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
1039 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
1040 exp
= attr_rtx (GET_CODE (exp
),
1041 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
1042 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
1043 /* These cases can't be simplified. */
1044 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1050 /* These cases are valid for constant attributes, but can't be
1052 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1053 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1057 fatal ("RTL operator \"%s\" not valid in attribute test",
1058 GET_RTX_NAME (GET_CODE (exp
)));
1064 /* Given an expression, ensure that it is validly formed and that all named
1065 attribute values are valid for the given attribute. Issue a fatal error
1066 if not. If no attribute is specified, assume a numeric attribute.
1068 Return a perhaps modified replacement expression for the value. */
1071 check_attr_value (exp
, attr
)
1073 struct attr_desc
*attr
;
1075 struct attr_value
*av
;
1079 switch (GET_CODE (exp
))
1082 if (attr
&& ! attr
->is_numeric
)
1084 message_with_line (attr
->lineno
,
1085 "CONST_INT not valid for non-numeric attribute %s",
1091 if (INTVAL (exp
) < 0 && ! attr
->negative_ok
)
1093 message_with_line (attr
->lineno
,
1094 "negative numeric value specified for attribute %s",
1102 if (! strcmp (XSTR (exp
, 0), "*"))
1105 if (attr
== 0 || attr
->is_numeric
)
1108 if (attr
&& attr
->negative_ok
&& *p
== '-')
1113 message_with_line (attr
? attr
->lineno
: 0,
1114 "non-numeric value for numeric attribute %s",
1115 attr
? attr
->name
: "internal");
1122 for (av
= attr
->first_value
; av
; av
= av
->next
)
1123 if (GET_CODE (av
->value
) == CONST_STRING
1124 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
1129 message_with_line (attr
->lineno
,
1130 "unknown value `%s' for `%s' attribute",
1131 XSTR (exp
, 0), attr
? attr
->name
: "internal");
1137 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
1138 attr
? attr
->is_const
: 0,
1139 attr
? attr
->lineno
: 0);
1140 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1141 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
1149 if (attr
&& !attr
->is_numeric
)
1151 message_with_line (attr
->lineno
,
1152 "invalid operation `%s' for non-numeric attribute value",
1153 GET_RTX_NAME (GET_CODE (exp
)));
1161 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1162 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1166 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1170 if (XVECLEN (exp
, 0) % 2 != 0)
1172 message_with_line (attr
->lineno
,
1173 "first operand of COND must have even length");
1178 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1180 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1181 attr
? attr
->is_const
: 0,
1182 attr
? attr
->lineno
: 0);
1183 XVECEXP (exp
, 0, i
+ 1)
1184 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1187 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1192 struct attr_desc
*attr2
= find_attr (XSTR (exp
, 0), 0);
1195 message_with_line (attr
? attr
->lineno
: 0,
1196 "unknown attribute `%s' in ATTR",
1200 else if (attr
&& attr
->is_const
&& ! attr2
->is_const
)
1202 message_with_line (attr
->lineno
,
1203 "non-constant attribute `%s' referenced from `%s'",
1204 XSTR (exp
, 0), attr
->name
);
1208 && (attr
->is_numeric
!= attr2
->is_numeric
1209 || (! attr
->negative_ok
&& attr2
->negative_ok
)))
1211 message_with_line (attr
->lineno
,
1212 "numeric attribute mismatch calling `%s' from `%s'",
1213 XSTR (exp
, 0), attr
->name
);
1220 /* A constant SYMBOL_REF is valid as a constant attribute test and
1221 is expanded later by make_canonical into a COND. In a non-constant
1222 attribute test, it is left be. */
1223 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1226 message_with_line (attr
? attr
->lineno
: 0,
1227 "invalid operation `%s' for attribute value",
1228 GET_RTX_NAME (GET_CODE (exp
)));
1236 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1237 It becomes a COND with each test being (eq_attr "alternative "n") */
1240 convert_set_attr_alternative (exp
, id
)
1242 struct insn_def
*id
;
1244 int num_alt
= id
->num_alternatives
;
1248 if (XVECLEN (exp
, 1) != num_alt
)
1250 message_with_line (id
->lineno
,
1251 "bad number of entries in SET_ATTR_ALTERNATIVE");
1256 /* Make a COND with all tests but the last. Select the last value via the
1258 condexp
= rtx_alloc (COND
);
1259 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1261 for (i
= 0; i
< num_alt
- 1; i
++)
1264 p
= attr_numeral (i
);
1266 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1267 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1270 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1272 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1275 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1276 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1279 convert_set_attr (exp
, id
)
1281 struct insn_def
*id
;
1284 const char *name_ptr
;
1288 /* See how many alternative specified. */
1289 n
= n_comma_elts (XSTR (exp
, 1));
1291 return attr_rtx (SET
,
1292 attr_rtx (ATTR
, XSTR (exp
, 0)),
1293 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1295 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1296 XSTR (newexp
, 0) = XSTR (exp
, 0);
1297 XVEC (newexp
, 1) = rtvec_alloc (n
);
1299 /* Process each comma-separated name. */
1300 name_ptr
= XSTR (exp
, 1);
1302 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1303 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1305 return convert_set_attr_alternative (newexp
, id
);
1308 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1309 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1315 struct insn_def
*id
;
1316 struct attr_desc
*attr
;
1320 for (id
= defs
; id
; id
= id
->next
)
1322 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1325 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1327 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1328 switch (GET_CODE (value
))
1331 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1333 message_with_line (id
->lineno
, "bad attribute set");
1339 case SET_ATTR_ALTERNATIVE
:
1340 value
= convert_set_attr_alternative (value
, id
);
1344 value
= convert_set_attr (value
, id
);
1348 message_with_line (id
->lineno
, "invalid attribute code %s",
1349 GET_RTX_NAME (GET_CODE (value
)));
1353 if (value
== NULL_RTX
)
1356 if ((attr
= find_attr (XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1358 message_with_line (id
->lineno
, "unknown attribute %s",
1359 XSTR (XEXP (value
, 0), 0));
1364 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1365 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1371 /* Given a constant SYMBOL_REF expression, convert to a COND that
1372 explicitly tests each enumerated value. */
1375 convert_const_symbol_ref (exp
, attr
)
1377 struct attr_desc
*attr
;
1380 struct attr_value
*av
;
1384 for (av
= attr
->first_value
; av
; av
= av
->next
)
1387 /* Make a COND with all tests but the last, and in the original order.
1388 Select the last value via the default. Note that the attr values
1389 are constructed in reverse order. */
1391 condexp
= rtx_alloc (COND
);
1392 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1393 av
= attr
->first_value
;
1394 XEXP (condexp
, 1) = av
->value
;
1396 for (i
= num_alt
- 2; av
= av
->next
, i
>= 0; i
--)
1401 string
= p
= (char *) oballoc (2
1402 + strlen (attr
->name
)
1403 + strlen (XSTR (av
->value
, 0)));
1404 strcpy (p
, attr
->name
);
1406 strcat (p
, XSTR (av
->value
, 0));
1407 for (; *p
!= '\0'; p
++)
1410 value
= attr_rtx (SYMBOL_REF
, string
);
1411 ATTR_IND_SIMPLIFIED_P (value
) = 1;
1413 XVECEXP (condexp
, 0, 2 * i
) = attr_rtx (EQ
, exp
, value
);
1415 XVECEXP (condexp
, 0, 2 * i
+ 1) = av
->value
;
1422 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1423 expressions by converting them into a COND. This removes cases from this
1424 program. Also, replace an attribute value of "*" with the default attribute
1428 make_canonical (attr
, exp
)
1429 struct attr_desc
*attr
;
1435 switch (GET_CODE (exp
))
1438 exp
= make_numeric_value (INTVAL (exp
));
1442 if (! strcmp (XSTR (exp
, 0), "*"))
1444 if (attr
== 0 || attr
->default_val
== 0)
1445 fatal ("(attr_value \"*\") used in invalid context");
1446 exp
= attr
->default_val
->value
;
1452 if (!attr
->is_const
|| ATTR_IND_SIMPLIFIED_P (exp
))
1454 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1455 This makes the COND something that won't be considered an arbitrary
1456 expression by walk_attr_value. */
1457 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1459 /* ??? Why do we do this? With attribute values { A B C D E }, this
1460 tends to generate (!(x==A) && !(x==B) && !(x==C) && !(x==D)) rather
1462 exp
= convert_const_symbol_ref (exp
, attr
);
1463 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1464 exp
= check_attr_value (exp
, attr
);
1465 /* Goto COND case since this is now a COND. Note that while the
1466 new expression is rescanned, all symbol_ref notes are marked as
1470 exp
= check_attr_value (exp
, attr
);
1475 newexp
= rtx_alloc (COND
);
1476 XVEC (newexp
, 0) = rtvec_alloc (2);
1477 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1478 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1480 XEXP (newexp
, 1) = XEXP (exp
, 2);
1483 /* Fall through to COND case since this is now a COND. */
1490 /* First, check for degenerate COND. */
1491 if (XVECLEN (exp
, 0) == 0)
1492 return make_canonical (attr
, XEXP (exp
, 1));
1493 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1495 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1497 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1498 XVECEXP (exp
, 0, i
+ 1)
1499 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1500 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1519 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1520 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1521 copy_boolean (XEXP (exp
, 1)));
1525 /* Given a value and an attribute description, return a `struct attr_value *'
1526 that represents that value. This is either an existing structure, if the
1527 value has been previously encountered, or a newly-created structure.
1529 `insn_code' is the code of an insn whose attribute has the specified
1530 value (-2 if not processing an insn). We ensure that all insns for
1531 a given value have the same number of alternatives if the value checks
1534 static struct attr_value
*
1535 get_attr_value (value
, attr
, insn_code
)
1537 struct attr_desc
*attr
;
1540 struct attr_value
*av
;
1543 value
= make_canonical (attr
, value
);
1544 if (compares_alternatives_p (value
))
1546 if (insn_code
< 0 || insn_alternatives
== NULL
)
1547 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1549 num_alt
= insn_alternatives
[insn_code
];
1552 for (av
= attr
->first_value
; av
; av
= av
->next
)
1553 if (rtx_equal_p (value
, av
->value
)
1554 && (num_alt
== 0 || av
->first_insn
== NULL
1555 || insn_alternatives
[av
->first_insn
->insn_code
]))
1558 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
1560 av
->next
= attr
->first_value
;
1561 attr
->first_value
= av
;
1562 av
->first_insn
= NULL
;
1564 av
->has_asm_insn
= 0;
1569 /* After all DEFINE_DELAYs have been read in, create internal attributes
1570 to generate the required routines.
1572 First, we compute the number of delay slots for each insn (as a COND of
1573 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1574 delay type is specified, we compute a similar function giving the
1575 DEFINE_DELAY ordinal for each insn.
1577 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1578 tells whether a given insn can be in that delay slot.
1580 Normal attribute filling and optimization expands these to contain the
1581 information needed to handle delay slots. */
1586 struct delay_desc
*delay
;
1592 /* First, generate data for `num_delay_slots' function. */
1594 condexp
= rtx_alloc (COND
);
1595 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1596 XEXP (condexp
, 1) = make_numeric_value (0);
1598 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1600 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1601 XVECEXP (condexp
, 0, i
+ 1)
1602 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1605 make_internal_attr ("*num_delay_slots", condexp
, 0);
1607 /* If more than one delay type, do the same for computing the delay type. */
1610 condexp
= rtx_alloc (COND
);
1611 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1612 XEXP (condexp
, 1) = make_numeric_value (0);
1614 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1616 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1617 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1620 make_internal_attr ("*delay_type", condexp
, 1);
1623 /* For each delay possibility and delay slot, compute an eligibility
1624 attribute for non-annulled insns and for each type of annulled (annul
1625 if true and annul if false). */
1626 for (delay
= delays
; delay
; delay
= delay
->next
)
1628 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1630 condexp
= XVECEXP (delay
->def
, 1, i
);
1632 condexp
= false_rtx
;
1633 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1634 make_numeric_value (1), make_numeric_value (0));
1636 p
= attr_printf (sizeof "*delay__" + MAX_DIGITS
* 2,
1637 "*delay_%d_%d", delay
->num
, i
/ 3);
1638 make_internal_attr (p
, newexp
, 1);
1640 if (have_annul_true
)
1642 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1643 if (condexp
== 0) condexp
= false_rtx
;
1644 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1645 make_numeric_value (1),
1646 make_numeric_value (0));
1647 p
= attr_printf (sizeof "*annul_true__" + MAX_DIGITS
* 2,
1648 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1649 make_internal_attr (p
, newexp
, 1);
1652 if (have_annul_false
)
1654 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1655 if (condexp
== 0) condexp
= false_rtx
;
1656 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1657 make_numeric_value (1),
1658 make_numeric_value (0));
1659 p
= attr_printf (sizeof "*annul_false__" + MAX_DIGITS
* 2,
1660 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1661 make_internal_attr (p
, newexp
, 1);
1667 /* This function is given a left and right side expression and an operator.
1668 Each side is a conditional expression, each alternative of which has a
1669 numerical value. The function returns another conditional expression
1670 which, for every possible set of condition values, returns a value that is
1671 the operator applied to the values of the two sides.
1673 Since this is called early, it must also support IF_THEN_ELSE. */
1676 operate_exp (op
, left
, right
)
1680 int left_value
, right_value
;
1684 /* If left is a string, apply operator to it and the right side. */
1685 if (GET_CODE (left
) == CONST_STRING
)
1687 /* If right is also a string, just perform the operation. */
1688 if (GET_CODE (right
) == CONST_STRING
)
1690 left_value
= atoi (XSTR (left
, 0));
1691 right_value
= atoi (XSTR (right
, 0));
1695 i
= left_value
+ right_value
;
1699 i
= left_value
- right_value
;
1702 case POS_MINUS_OP
: /* The positive part of LEFT - RIGHT. */
1703 if (left_value
> right_value
)
1704 i
= left_value
- right_value
;
1711 i
= left_value
| right_value
;
1715 i
= left_value
== right_value
;
1719 i
= (left_value
<< (HOST_BITS_PER_INT
/ 2)) | right_value
;
1723 if (left_value
> right_value
)
1730 if (left_value
< right_value
)
1740 if (i
== left_value
)
1742 if (i
== right_value
)
1744 return make_numeric_value (i
);
1746 else if (GET_CODE (right
) == IF_THEN_ELSE
)
1748 /* Apply recursively to all values within. */
1749 rtx newleft
= operate_exp (op
, left
, XEXP (right
, 1));
1750 rtx newright
= operate_exp (op
, left
, XEXP (right
, 2));
1751 if (rtx_equal_p (newleft
, newright
))
1753 return attr_rtx (IF_THEN_ELSE
, XEXP (right
, 0), newleft
, newright
);
1755 else if (GET_CODE (right
) == COND
)
1760 newexp
= rtx_alloc (COND
);
1761 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (right
, 0));
1762 defval
= XEXP (newexp
, 1) = operate_exp (op
, left
, XEXP (right
, 1));
1764 for (i
= 0; i
< XVECLEN (right
, 0); i
+= 2)
1766 XVECEXP (newexp
, 0, i
) = XVECEXP (right
, 0, i
);
1767 XVECEXP (newexp
, 0, i
+ 1)
1768 = operate_exp (op
, left
, XVECEXP (right
, 0, i
+ 1));
1769 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1774 /* If the resulting cond is trivial (all alternatives
1775 give the same value), optimize it away. */
1777 return operate_exp (op
, left
, XEXP (right
, 1));
1782 fatal ("badly formed attribute value");
1785 /* A hack to prevent expand_units from completely blowing up: ORX_OP does
1786 not associate through IF_THEN_ELSE. */
1787 else if (op
== ORX_OP
&& GET_CODE (right
) == IF_THEN_ELSE
)
1789 return attr_rtx (IOR
, left
, right
);
1792 /* Otherwise, do recursion the other way. */
1793 else if (GET_CODE (left
) == IF_THEN_ELSE
)
1795 rtx newleft
= operate_exp (op
, XEXP (left
, 1), right
);
1796 rtx newright
= operate_exp (op
, XEXP (left
, 2), right
);
1797 if (rtx_equal_p (newleft
, newright
))
1799 return attr_rtx (IF_THEN_ELSE
, XEXP (left
, 0), newleft
, newright
);
1801 else if (GET_CODE (left
) == COND
)
1806 newexp
= rtx_alloc (COND
);
1807 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (left
, 0));
1808 defval
= XEXP (newexp
, 1) = operate_exp (op
, XEXP (left
, 1), right
);
1810 for (i
= 0; i
< XVECLEN (left
, 0); i
+= 2)
1812 XVECEXP (newexp
, 0, i
) = XVECEXP (left
, 0, i
);
1813 XVECEXP (newexp
, 0, i
+ 1)
1814 = operate_exp (op
, XVECEXP (left
, 0, i
+ 1), right
);
1815 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1820 /* If the cond is trivial (all alternatives give the same value),
1821 optimize it away. */
1823 return operate_exp (op
, XEXP (left
, 1), right
);
1825 /* If the result is the same as the LEFT operand,
1827 if (rtx_equal_p (newexp
, left
))
1834 fatal ("badly formed attribute value");
1839 /* Once all attributes and DEFINE_FUNCTION_UNITs have been read, we
1840 construct a number of attributes.
1842 The first produces a function `function_units_used' which is given an
1843 insn and produces an encoding showing which function units are required
1844 for the execution of that insn. If the value is non-negative, the insn
1845 uses that unit; otherwise, the value is a one's compliment mask of units
1848 The second produces a function `result_ready_cost' which is used to
1849 determine the time that the result of an insn will be ready and hence
1850 a worst-case schedule.
1852 Both of these produce quite complex expressions which are then set as the
1853 default value of internal attributes. Normal attribute simplification
1854 should produce reasonable expressions.
1856 For each unit, a `<name>_unit_ready_cost' function will take an
1857 insn and give the delay until that unit will be ready with the result
1858 and a `<name>_unit_conflict_cost' function is given an insn already
1859 executing on the unit and a candidate to execute and will give the
1860 cost from the time the executing insn started until the candidate
1861 can start (ignore limitations on the number of simultaneous insns).
1863 For each unit, a `<name>_unit_blockage' function is given an insn
1864 already executing on the unit and a candidate to execute and will
1865 give the delay incurred due to function unit conflicts. The range of
1866 blockage cost values for a given executing insn is given by the
1867 `<name>_unit_blockage_range' function. These values are encoded in
1868 an int where the upper half gives the minimum value and the lower
1869 half gives the maximum value. */
1874 struct function_unit
*unit
, **unit_num
;
1875 struct function_unit_op
*op
, **op_array
, ***unit_ops
;
1880 int i
, j
, u
, num
, nvalues
;
1882 /* Rebuild the condition for the unit to share the RTL expressions.
1883 Sharing is required by simplify_by_exploding. Build the issue delay
1884 expressions. Validate the expressions we were given for the conditions
1885 and conflict vector. Then make attributes for use in the conflict
1888 for (unit
= units
; unit
; unit
= unit
->next
)
1890 unit
->condexp
= check_attr_test (unit
->condexp
, 0, unit
->first_lineno
);
1892 for (op
= unit
->ops
; op
; op
= op
->next
)
1894 rtx issue_delay
= make_numeric_value (op
->issue_delay
);
1895 rtx issue_exp
= issue_delay
;
1897 /* Build, validate, and simplify the issue delay expression. */
1898 if (op
->conflict_exp
!= true_rtx
)
1899 issue_exp
= attr_rtx (IF_THEN_ELSE
, op
->conflict_exp
,
1900 issue_exp
, make_numeric_value (0));
1901 issue_exp
= check_attr_value (make_canonical (NULL_ATTR
,
1904 issue_exp
= simplify_knowing (issue_exp
, unit
->condexp
);
1905 op
->issue_exp
= issue_exp
;
1907 /* Make an attribute for use in the conflict function if needed. */
1908 unit
->needs_conflict_function
= (unit
->issue_delay
.min
1909 != unit
->issue_delay
.max
);
1910 if (unit
->needs_conflict_function
)
1912 str
= attr_printf ((strlen (unit
->name
) + sizeof "*_cost_"
1914 "*%s_cost_%d", unit
->name
, op
->num
);
1915 make_internal_attr (str
, issue_exp
, 1);
1918 /* Validate the condition. */
1919 op
->condexp
= check_attr_test (op
->condexp
, 0, op
->lineno
);
1923 /* Compute the mask of function units used. Initially, the unitsmask is
1924 zero. Set up a conditional to compute each unit's contribution. */
1925 unitsmask
= make_numeric_value (0);
1926 newexp
= rtx_alloc (IF_THEN_ELSE
);
1927 XEXP (newexp
, 2) = make_numeric_value (0);
1929 /* If we have just a few units, we may be all right expanding the whole
1930 thing. But the expansion is 2**N in space on the number of opclasses,
1931 so we can't do this for very long -- Alpha and MIPS in particular have
1932 problems with this. So in that situation, we fall back on an alternate
1933 implementation method. */
1934 #define NUM_UNITOP_CUTOFF 20
1936 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1938 /* Merge each function unit into the unit mask attributes. */
1939 for (unit
= units
; unit
; unit
= unit
->next
)
1941 XEXP (newexp
, 0) = unit
->condexp
;
1942 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1943 unitsmask
= operate_exp (OR_OP
, unitsmask
, newexp
);
1948 /* Merge each function unit into the unit mask attributes. */
1949 for (unit
= units
; unit
; unit
= unit
->next
)
1951 XEXP (newexp
, 0) = unit
->condexp
;
1952 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1953 unitsmask
= operate_exp (ORX_OP
, unitsmask
, attr_copy_rtx (newexp
));
1957 /* Simplify the unit mask expression, encode it, and make an attribute
1958 for the function_units_used function. */
1959 unitsmask
= simplify_by_exploding (unitsmask
);
1961 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1962 unitsmask
= encode_units_mask (unitsmask
);
1965 /* We can no longer encode unitsmask at compile time, so emit code to
1966 calculate it at runtime. Rather, put a marker for where we'd do
1967 the code, and actually output it in write_attr_get(). */
1968 unitsmask
= attr_rtx (FFS
, unitsmask
);
1971 make_internal_attr ("*function_units_used", unitsmask
, 10);
1973 /* Create an array of ops for each unit. Add an extra unit for the
1974 result_ready_cost function that has the ops of all other units. */
1975 unit_ops
= (struct function_unit_op
***)
1976 xmalloc ((num_units
+ 1) * sizeof (struct function_unit_op
**));
1977 unit_num
= (struct function_unit
**)
1978 xmalloc ((num_units
+ 1) * sizeof (struct function_unit
*));
1980 unit_num
[num_units
] = unit
= (struct function_unit
*)
1981 xmalloc (sizeof (struct function_unit
));
1982 unit
->num
= num_units
;
1983 unit
->num_opclasses
= 0;
1985 for (unit
= units
; unit
; unit
= unit
->next
)
1987 unit_num
[num_units
]->num_opclasses
+= unit
->num_opclasses
;
1988 unit_num
[unit
->num
] = unit
;
1989 unit_ops
[unit
->num
] = op_array
= (struct function_unit_op
**)
1990 xmalloc (unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1992 for (op
= unit
->ops
; op
; op
= op
->next
)
1993 op_array
[op
->num
] = op
;
1996 /* Compose the array of ops for the extra unit. */
1997 unit_ops
[num_units
] = op_array
= (struct function_unit_op
**)
1998 xmalloc (unit_num
[num_units
]->num_opclasses
1999 * sizeof (struct function_unit_op
*));
2001 for (unit
= units
, i
= 0; unit
; i
+= unit
->num_opclasses
, unit
= unit
->next
)
2002 memcpy (&op_array
[i
], unit_ops
[unit
->num
],
2003 unit
->num_opclasses
* sizeof (struct function_unit_op
*));
2005 /* Compute the ready cost function for each unit by computing the
2006 condition for each non-default value. */
2007 for (u
= 0; u
<= num_units
; u
++)
2013 op_array
= unit_ops
[unit
->num
];
2014 num
= unit
->num_opclasses
;
2016 /* Sort the array of ops into increasing ready cost order. */
2017 for (i
= 0; i
< num
; i
++)
2018 for (j
= num
- 1; j
> i
; j
--)
2019 if (op_array
[j
- 1]->ready
< op_array
[j
]->ready
)
2022 op_array
[j
] = op_array
[j
- 1];
2023 op_array
[j
- 1] = op
;
2026 /* Determine how many distinct non-default ready cost values there
2027 are. We use a default ready cost value of 1. */
2028 nvalues
= 0; value
= 1;
2029 for (i
= num
- 1; i
>= 0; i
--)
2030 if (op_array
[i
]->ready
> value
)
2032 value
= op_array
[i
]->ready
;
2037 readycost
= make_numeric_value (1);
2040 /* Construct the ready cost expression as a COND of each value from
2041 the largest to the smallest. */
2042 readycost
= rtx_alloc (COND
);
2043 XVEC (readycost
, 0) = rtvec_alloc (nvalues
* 2);
2044 XEXP (readycost
, 1) = make_numeric_value (1);
2048 value
= op_array
[0]->ready
;
2049 for (i
= 0; i
< num
; i
++)
2054 else if (op
->ready
== value
)
2055 orexp
= insert_right_side (IOR
, orexp
, op
->condexp
, -2, -2);
2058 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
2059 XVECEXP (readycost
, 0, nvalues
* 2 + 1)
2060 = make_numeric_value (value
);
2063 orexp
= op
->condexp
;
2066 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
2067 XVECEXP (readycost
, 0, nvalues
* 2 + 1) = make_numeric_value (value
);
2072 rtx max_blockage
= 0, min_blockage
= 0;
2074 /* Simplify the readycost expression by only considering insns
2075 that use the unit. */
2076 readycost
= simplify_knowing (readycost
, unit
->condexp
);
2078 /* Determine the blockage cost the executing insn (E) given
2079 the candidate insn (C). This is the maximum of the issue
2080 delay, the pipeline delay, and the simultaneity constraint.
2081 Each function_unit_op represents the characteristics of the
2082 candidate insn, so in the expressions below, C is a known
2083 term and E is an unknown term.
2085 We compute the blockage cost for each E for every possible C.
2086 Thus OP represents E, and READYCOST is a list of values for
2089 The issue delay function for C is op->issue_exp and is used to
2090 write the `<name>_unit_conflict_cost' function. Symbolicly
2091 this is "ISSUE-DELAY (E,C)".
2093 The pipeline delay results form the FIFO constraint on the
2094 function unit and is "READY-COST (E) + 1 - READY-COST (C)".
2096 The simultaneity constraint is based on how long it takes to
2097 fill the unit given the minimum issue delay. FILL-TIME is the
2098 constant "MIN (ISSUE-DELAY (*,*)) * (SIMULTANEITY - 1)", and
2099 the simultaneity constraint is "READY-COST (E) - FILL-TIME"
2100 if SIMULTANEITY is non-zero and zero otherwise.
2102 Thus, BLOCKAGE (E,C) when SIMULTANEITY is zero is
2104 MAX (ISSUE-DELAY (E,C),
2105 READY-COST (E) - (READY-COST (C) - 1))
2109 MAX (ISSUE-DELAY (E,C),
2110 READY-COST (E) - (READY-COST (C) - 1),
2111 READY-COST (E) - FILL-TIME)
2113 The `<name>_unit_blockage' function is computed by determining
2114 this value for each candidate insn. As these values are
2115 computed, we also compute the upper and lower bounds for
2116 BLOCKAGE (E,*). These are combined to form the function
2117 `<name>_unit_blockage_range'. Finally, the maximum blockage
2118 cost, MAX (BLOCKAGE (*,*)), is computed. */
2120 for (op
= unit
->ops
; op
; op
= op
->next
)
2122 rtx blockage
= op
->issue_exp
;
2123 blockage
= simplify_knowing (blockage
, unit
->condexp
);
2125 /* Add this op's contribution to MAX (BLOCKAGE (E,*)) and
2126 MIN (BLOCKAGE (E,*)). */
2127 if (max_blockage
== 0)
2128 max_blockage
= min_blockage
= blockage
;
2132 = simplify_knowing (operate_exp (MAX_OP
, max_blockage
,
2136 = simplify_knowing (operate_exp (MIN_OP
, min_blockage
,
2141 /* Make an attribute for use in the blockage function. */
2142 str
= attr_printf ((strlen (unit
->name
) + sizeof "*_block_"
2144 "*%s_block_%d", unit
->name
, op
->num
);
2145 make_internal_attr (str
, blockage
, 1);
2148 /* Record MAX (BLOCKAGE (*,*)). */
2151 unit
->max_blockage
= max_attr_value (max_blockage
, &unknown
);
2154 /* See if the upper and lower bounds of BLOCKAGE (E,*) are the
2155 same. If so, the blockage function carries no additional
2156 information and is not written. */
2157 newexp
= operate_exp (EQ_OP
, max_blockage
, min_blockage
);
2158 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2159 unit
->needs_blockage_function
2160 = (GET_CODE (newexp
) != CONST_STRING
2161 || atoi (XSTR (newexp
, 0)) != 1);
2163 /* If the all values of BLOCKAGE (E,C) have the same value,
2164 neither blockage function is written. */
2165 unit
->needs_range_function
2166 = (unit
->needs_blockage_function
2167 || GET_CODE (max_blockage
) != CONST_STRING
);
2169 if (unit
->needs_range_function
)
2171 /* Compute the blockage range function and make an attribute
2172 for writing its value. */
2173 newexp
= operate_exp (RANGE_OP
, min_blockage
, max_blockage
);
2174 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2176 str
= attr_printf ((strlen (unit
->name
)
2177 + sizeof "*_unit_blockage_range"),
2178 "*%s_unit_blockage_range", unit
->name
);
2179 make_internal_attr (str
, newexp
, 20);
2182 str
= attr_printf (strlen (unit
->name
) + sizeof "*_unit_ready_cost",
2183 "*%s_unit_ready_cost", unit
->name
);
2186 str
= "*result_ready_cost";
2188 /* Make an attribute for the ready_cost function. Simplifying
2189 further with simplify_by_exploding doesn't win. */
2190 make_internal_attr (str
, readycost
, 0);
2193 /* For each unit that requires a conflict cost function, make an attribute
2194 that maps insns to the operation number. */
2195 for (unit
= units
; unit
; unit
= unit
->next
)
2199 if (! unit
->needs_conflict_function
2200 && ! unit
->needs_blockage_function
)
2203 caseexp
= rtx_alloc (COND
);
2204 XVEC (caseexp
, 0) = rtvec_alloc ((unit
->num_opclasses
- 1) * 2);
2206 for (op
= unit
->ops
; op
; op
= op
->next
)
2208 /* Make our adjustment to the COND being computed. If we are the
2209 last operation class, place our values into the default of the
2211 if (op
->num
== unit
->num_opclasses
- 1)
2213 XEXP (caseexp
, 1) = make_numeric_value (op
->num
);
2217 XVECEXP (caseexp
, 0, op
->num
* 2) = op
->condexp
;
2218 XVECEXP (caseexp
, 0, op
->num
* 2 + 1)
2219 = make_numeric_value (op
->num
);
2223 /* Simplifying caseexp with simplify_by_exploding doesn't win. */
2224 str
= attr_printf (strlen (unit
->name
) + sizeof "*_cases",
2225 "*%s_cases", unit
->name
);
2226 make_internal_attr (str
, caseexp
, 1);
2230 /* Simplify EXP given KNOWN_TRUE. */
2233 simplify_knowing (exp
, known_true
)
2234 rtx exp
, known_true
;
2236 if (GET_CODE (exp
) != CONST_STRING
)
2238 int unknown
= 0, max
;
2239 max
= max_attr_value (exp
, &unknown
);
2242 exp
= attr_rtx (IF_THEN_ELSE
, known_true
, exp
,
2243 make_numeric_value (max
));
2244 exp
= simplify_by_exploding (exp
);
2250 /* Translate the CONST_STRING expressions in X to change the encoding of
2251 value. On input, the value is a bitmask with a one bit for each unit
2252 used; on output, the value is the unit number (zero based) if one
2253 and only one unit is used or the one's compliment of the bitmask. */
2256 encode_units_mask (x
)
2264 code
= GET_CODE (x
);
2269 i
= atoi (XSTR (x
, 0));
2271 /* The sign bit encodes a one's compliment mask. */
2273 else if (i
!= 0 && i
== (i
& -i
))
2274 /* Only one bit is set, so yield that unit number. */
2275 for (j
= 0; (i
>>= 1) != 0; j
++)
2279 return attr_rtx (CONST_STRING
, attr_printf (MAX_DIGITS
, "%d", j
));
2297 /* Compare the elements. If any pair of corresponding elements
2298 fail to match, return 0 for the whole things. */
2300 fmt
= GET_RTX_FORMAT (code
);
2301 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2307 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2308 XVECEXP (x
, i
, j
) = encode_units_mask (XVECEXP (x
, i
, j
));
2312 XEXP (x
, i
) = encode_units_mask (XEXP (x
, i
));
2319 /* Once all attributes and insns have been read and checked, we construct for
2320 each attribute value a list of all the insns that have that value for
2325 struct attr_desc
*attr
;
2327 struct attr_value
*av
;
2328 struct insn_ent
*ie
;
2329 struct insn_def
*id
;
2333 /* Don't fill constant attributes. The value is independent of
2334 any particular insn. */
2338 for (id
= defs
; id
; id
= id
->next
)
2340 /* If no value is specified for this insn for this attribute, use the
2343 if (XVEC (id
->def
, id
->vec_idx
))
2344 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
2345 if (! strcmp (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
2347 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
2350 av
= attr
->default_val
;
2352 av
= get_attr_value (value
, attr
, id
->insn_code
);
2354 ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2355 ie
->insn_code
= id
->insn_code
;
2356 ie
->insn_index
= id
->insn_code
;
2357 insert_insn_ent (av
, ie
);
2361 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
2362 test that checks relative positions of insns (uses MATCH_DUP or PC).
2363 If so, replace it with what is obtained by passing the expression to
2364 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
2365 recursively on each value (including the default value). Otherwise,
2366 return the value returned by NO_ADDRESS_FN applied to EXP. */
2369 substitute_address (exp
, no_address_fn
, address_fn
)
2371 rtx (*no_address_fn
) PARAMS ((rtx
));
2372 rtx (*address_fn
) PARAMS ((rtx
));
2377 if (GET_CODE (exp
) == COND
)
2379 /* See if any tests use addresses. */
2381 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2382 walk_attr_value (XVECEXP (exp
, 0, i
));
2385 return (*address_fn
) (exp
);
2387 /* Make a new copy of this COND, replacing each element. */
2388 newexp
= rtx_alloc (COND
);
2389 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
2390 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2392 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
2393 XVECEXP (newexp
, 0, i
+ 1)
2394 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
2395 no_address_fn
, address_fn
);
2398 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
2399 no_address_fn
, address_fn
);
2404 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
2407 walk_attr_value (XEXP (exp
, 0));
2409 return (*address_fn
) (exp
);
2411 return attr_rtx (IF_THEN_ELSE
,
2412 substitute_address (XEXP (exp
, 0),
2413 no_address_fn
, address_fn
),
2414 substitute_address (XEXP (exp
, 1),
2415 no_address_fn
, address_fn
),
2416 substitute_address (XEXP (exp
, 2),
2417 no_address_fn
, address_fn
));
2420 return (*no_address_fn
) (exp
);
2423 /* Make new attributes from the `length' attribute. The following are made,
2424 each corresponding to a function called from `shorten_branches' or
2427 *insn_default_length This is the length of the insn to be returned
2428 by `get_attr_length' before `shorten_branches'
2429 has been called. In each case where the length
2430 depends on relative addresses, the largest
2431 possible is used. This routine is also used
2432 to compute the initial size of the insn.
2434 *insn_variable_length_p This returns 1 if the insn's length depends
2435 on relative addresses, zero otherwise.
2437 *insn_current_length This is only called when it is known that the
2438 insn has a variable length and returns the
2439 current length, based on relative addresses.
2443 make_length_attrs ()
2445 static const char *const new_names
[] = {"*insn_default_length",
2446 "*insn_variable_length_p",
2447 "*insn_current_length"};
2448 static rtx (*const no_address_fn
[]) PARAMS ((rtx
)) = {identity_fn
, zero_fn
, zero_fn
};
2449 static rtx (*const address_fn
[]) PARAMS ((rtx
)) = {max_fn
, one_fn
, identity_fn
};
2451 struct attr_desc
*length_attr
, *new_attr
;
2452 struct attr_value
*av
, *new_av
;
2453 struct insn_ent
*ie
, *new_ie
;
2455 /* See if length attribute is defined. If so, it must be numeric. Make
2456 it special so we don't output anything for it. */
2457 length_attr
= find_attr ("length", 0);
2458 if (length_attr
== 0)
2461 if (! length_attr
->is_numeric
)
2462 fatal ("length attribute must be numeric");
2464 length_attr
->is_const
= 0;
2465 length_attr
->is_special
= 1;
2467 /* Make each new attribute, in turn. */
2468 for (i
= 0; i
< ARRAY_SIZE (new_names
); i
++)
2470 make_internal_attr (new_names
[i
],
2471 substitute_address (length_attr
->default_val
->value
,
2472 no_address_fn
[i
], address_fn
[i
]),
2474 new_attr
= find_attr (new_names
[i
], 0);
2475 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2476 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2478 new_av
= get_attr_value (substitute_address (av
->value
,
2481 new_attr
, ie
->insn_code
);
2482 new_ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2483 new_ie
->insn_code
= ie
->insn_code
;
2484 new_ie
->insn_index
= ie
->insn_index
;
2485 insert_insn_ent (new_av
, new_ie
);
2490 /* Utility functions called from above routine. */
2501 rtx exp ATTRIBUTE_UNUSED
;
2503 return make_numeric_value (0);
2508 rtx exp ATTRIBUTE_UNUSED
;
2510 return make_numeric_value (1);
2518 return make_numeric_value (max_attr_value (exp
, &unknown
));
2522 write_length_unit_log ()
2524 struct attr_desc
*length_attr
= find_attr ("length", 0);
2525 struct attr_value
*av
;
2526 struct insn_ent
*ie
;
2527 unsigned int length_unit_log
, length_or
;
2530 if (length_attr
== 0)
2532 length_or
= or_attr_value (length_attr
->default_val
->value
, &unknown
);
2533 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2534 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2535 length_or
|= or_attr_value (av
->value
, &unknown
);
2538 length_unit_log
= 0;
2541 length_or
= ~length_or
;
2542 for (length_unit_log
= 0; length_or
& 1; length_or
>>= 1)
2545 printf ("int length_unit_log = %u;\n", length_unit_log
);
2548 /* Take a COND expression and see if any of the conditions in it can be
2549 simplified. If any are known true or known false for the particular insn
2550 code, the COND can be further simplified.
2552 Also call ourselves on any COND operations that are values of this COND.
2554 We do not modify EXP; rather, we make and return a new rtx. */
2557 simplify_cond (exp
, insn_code
, insn_index
)
2559 int insn_code
, insn_index
;
2562 /* We store the desired contents here,
2563 then build a new expression if they don't match EXP. */
2564 rtx defval
= XEXP (exp
, 1);
2565 rtx new_defval
= XEXP (exp
, 1);
2566 int len
= XVECLEN (exp
, 0);
2567 rtx
*tests
= (rtx
*) xmalloc (len
* sizeof (rtx
));
2572 /* This lets us free all storage allocated below, if appropriate. */
2573 first_spacer
= (char *) obstack_finish (rtl_obstack
);
2575 memcpy (tests
, XVEC (exp
, 0)->elem
, len
* sizeof (rtx
));
2577 /* See if default value needs simplification. */
2578 if (GET_CODE (defval
) == COND
)
2579 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
2581 /* Simplify the subexpressions, and see what tests we can get rid of. */
2583 for (i
= 0; i
< len
; i
+= 2)
2585 rtx newtest
, newval
;
2587 /* Simplify this test. */
2588 newtest
= simplify_test_exp_in_temp (tests
[i
], insn_code
, insn_index
);
2591 newval
= tests
[i
+ 1];
2592 /* See if this value may need simplification. */
2593 if (GET_CODE (newval
) == COND
)
2594 newval
= simplify_cond (newval
, insn_code
, insn_index
);
2596 /* Look for ways to delete or combine this test. */
2597 if (newtest
== true_rtx
)
2599 /* If test is true, make this value the default
2600 and discard this + any following tests. */
2602 defval
= tests
[i
+ 1];
2603 new_defval
= newval
;
2606 else if (newtest
== false_rtx
)
2608 /* If test is false, discard it and its value. */
2609 for (j
= i
; j
< len
- 2; j
++)
2610 tests
[j
] = tests
[j
+ 2];
2614 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
2616 /* If this value and the value for the prev test are the same,
2620 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
2621 insn_code
, insn_index
);
2623 /* Delete this test/value. */
2624 for (j
= i
; j
< len
- 2; j
++)
2625 tests
[j
] = tests
[j
+ 2];
2630 tests
[i
+ 1] = newval
;
2633 /* If the last test in a COND has the same value
2634 as the default value, that test isn't needed. */
2636 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
2639 /* See if we changed anything. */
2640 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
2643 for (i
= 0; i
< len
; i
++)
2644 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
2652 if (GET_CODE (defval
) == COND
)
2653 ret
= simplify_cond (defval
, insn_code
, insn_index
);
2661 rtx newexp
= rtx_alloc (COND
);
2663 XVEC (newexp
, 0) = rtvec_alloc (len
);
2664 memcpy (XVEC (newexp
, 0)->elem
, tests
, len
* sizeof (rtx
));
2665 XEXP (newexp
, 1) = new_defval
;
2672 /* Remove an insn entry from an attribute value. */
2675 remove_insn_ent (av
, ie
)
2676 struct attr_value
*av
;
2677 struct insn_ent
*ie
;
2679 struct insn_ent
*previe
;
2681 if (av
->first_insn
== ie
)
2682 av
->first_insn
= ie
->next
;
2685 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
2687 previe
->next
= ie
->next
;
2691 if (ie
->insn_code
== -1)
2692 av
->has_asm_insn
= 0;
2697 /* Insert an insn entry in an attribute value list. */
2700 insert_insn_ent (av
, ie
)
2701 struct attr_value
*av
;
2702 struct insn_ent
*ie
;
2704 ie
->next
= av
->first_insn
;
2705 av
->first_insn
= ie
;
2707 if (ie
->insn_code
== -1)
2708 av
->has_asm_insn
= 1;
2713 /* This is a utility routine to take an expression that is a tree of either
2714 AND or IOR expressions and insert a new term. The new term will be
2715 inserted at the right side of the first node whose code does not match
2716 the root. A new node will be created with the root's code. Its left
2717 side will be the old right side and its right side will be the new
2720 If the `term' is itself a tree, all its leaves will be inserted. */
2723 insert_right_side (code
, exp
, term
, insn_code
, insn_index
)
2727 int insn_code
, insn_index
;
2731 /* Avoid consing in some special cases. */
2732 if (code
== AND
&& term
== true_rtx
)
2734 if (code
== AND
&& term
== false_rtx
)
2736 if (code
== AND
&& exp
== true_rtx
)
2738 if (code
== AND
&& exp
== false_rtx
)
2740 if (code
== IOR
&& term
== true_rtx
)
2742 if (code
== IOR
&& term
== false_rtx
)
2744 if (code
== IOR
&& exp
== true_rtx
)
2746 if (code
== IOR
&& exp
== false_rtx
)
2748 if (attr_equal_p (exp
, term
))
2751 if (GET_CODE (term
) == code
)
2753 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
2754 insn_code
, insn_index
);
2755 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
2756 insn_code
, insn_index
);
2761 if (GET_CODE (exp
) == code
)
2763 rtx
new = insert_right_side (code
, XEXP (exp
, 1),
2764 term
, insn_code
, insn_index
);
2765 if (new != XEXP (exp
, 1))
2766 /* Make a copy of this expression and call recursively. */
2767 newexp
= attr_rtx (code
, XEXP (exp
, 0), new);
2773 /* Insert the new term. */
2774 newexp
= attr_rtx (code
, exp
, term
);
2777 return simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2780 /* If we have an expression which AND's a bunch of
2781 (not (eq_attrq "alternative" "n"))
2782 terms, we may have covered all or all but one of the possible alternatives.
2783 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
2785 This routine is passed an expression and either AND or IOR. It returns a
2786 bitmask indicating which alternatives are mentioned within EXP. */
2789 compute_alternative_mask (exp
, code
)
2794 if (GET_CODE (exp
) == code
)
2795 return compute_alternative_mask (XEXP (exp
, 0), code
)
2796 | compute_alternative_mask (XEXP (exp
, 1), code
);
2798 else if (code
== AND
&& GET_CODE (exp
) == NOT
2799 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2800 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
2801 string
= XSTR (XEXP (exp
, 0), 1);
2803 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
2804 && XSTR (exp
, 0) == alternative_name
)
2805 string
= XSTR (exp
, 1);
2811 return 1 << (string
[0] - '0');
2812 return 1 << atoi (string
);
2815 /* Given I, a single-bit mask, return RTX to compare the `alternative'
2816 attribute with the value represented by that bit. */
2819 make_alternative_compare (mask
)
2826 for (i
= 0; (mask
& (1 << i
)) == 0; i
++)
2829 newexp
= attr_rtx (EQ_ATTR
, alternative_name
, attr_numeral (i
));
2830 ATTR_IND_SIMPLIFIED_P (newexp
) = 1;
2835 /* If we are processing an (eq_attr "attr" "value") test, we find the value
2836 of "attr" for this insn code. From that value, we can compute a test
2837 showing when the EQ_ATTR will be true. This routine performs that
2838 computation. If a test condition involves an address, we leave the EQ_ATTR
2839 intact because addresses are only valid for the `length' attribute.
2841 EXP is the EQ_ATTR expression and VALUE is the value of that attribute
2842 for the insn corresponding to INSN_CODE and INSN_INDEX. */
2845 evaluate_eq_attr (exp
, value
, insn_code
, insn_index
)
2848 int insn_code
, insn_index
;
2855 if (GET_CODE (value
) == CONST_STRING
)
2857 if (! strcmp (XSTR (value
, 0), XSTR (exp
, 1)))
2862 else if (GET_CODE (value
) == SYMBOL_REF
)
2867 if (GET_CODE (exp
) != EQ_ATTR
)
2870 if (strlen (XSTR (exp
, 0)) + strlen (XSTR (exp
, 1)) + 2 > 256)
2873 strcpy (string
, XSTR (exp
, 0));
2874 strcat (string
, "_");
2875 strcat (string
, XSTR (exp
, 1));
2876 for (p
= string
; *p
; p
++)
2879 newexp
= attr_rtx (EQ
, value
,
2880 attr_rtx (SYMBOL_REF
,
2881 attr_string (string
, strlen (string
))));
2883 else if (GET_CODE (value
) == COND
)
2885 /* We construct an IOR of all the cases for which the requested attribute
2886 value is present. Since we start with FALSE, if it is not present,
2887 FALSE will be returned.
2889 Each case is the AND of the NOT's of the previous conditions with the
2890 current condition; in the default case the current condition is TRUE.
2892 For each possible COND value, call ourselves recursively.
2894 The extra TRUE and FALSE expressions will be eliminated by another
2895 call to the simplification routine. */
2900 if (current_alternative_string
)
2901 clear_struct_flag (value
);
2903 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2905 rtx
this = simplify_test_exp_in_temp (XVECEXP (value
, 0, i
),
2906 insn_code
, insn_index
);
2908 SIMPLIFY_ALTERNATIVE (this);
2910 right
= insert_right_side (AND
, andexp
, this,
2911 insn_code
, insn_index
);
2912 right
= insert_right_side (AND
, right
,
2913 evaluate_eq_attr (exp
,
2916 insn_code
, insn_index
),
2917 insn_code
, insn_index
);
2918 orexp
= insert_right_side (IOR
, orexp
, right
,
2919 insn_code
, insn_index
);
2921 /* Add this condition into the AND expression. */
2922 newexp
= attr_rtx (NOT
, this);
2923 andexp
= insert_right_side (AND
, andexp
, newexp
,
2924 insn_code
, insn_index
);
2927 /* Handle the default case. */
2928 right
= insert_right_side (AND
, andexp
,
2929 evaluate_eq_attr (exp
, XEXP (value
, 1),
2930 insn_code
, insn_index
),
2931 insn_code
, insn_index
);
2932 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2937 /* If uses an address, must return original expression. But set the
2938 ATTR_IND_SIMPLIFIED_P bit so we don't try to simplify it again. */
2941 walk_attr_value (newexp
);
2945 /* This had `&& current_alternative_string', which seems to be wrong. */
2946 if (! ATTR_IND_SIMPLIFIED_P (exp
))
2947 return copy_rtx_unchanging (exp
);
2954 /* This routine is called when an AND of a term with a tree of AND's is
2955 encountered. If the term or its complement is present in the tree, it
2956 can be replaced with TRUE or FALSE, respectively.
2958 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2959 be true and hence are complementary.
2961 There is one special case: If we see
2962 (and (not (eq_attr "att" "v1"))
2963 (eq_attr "att" "v2"))
2964 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2965 replace the term, not anything in the AND tree. So we pass a pointer to
2969 simplify_and_tree (exp
, pterm
, insn_code
, insn_index
)
2972 int insn_code
, insn_index
;
2977 int left_eliminates_term
, right_eliminates_term
;
2979 if (GET_CODE (exp
) == AND
)
2981 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2982 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2983 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2985 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2987 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2991 else if (GET_CODE (exp
) == IOR
)
2993 /* For the IOR case, we do the same as above, except that we can
2994 only eliminate `term' if both sides of the IOR would do so. */
2996 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2997 left_eliminates_term
= (temp
== true_rtx
);
3000 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
3001 right_eliminates_term
= (temp
== true_rtx
);
3003 if (left_eliminates_term
&& right_eliminates_term
)
3006 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3008 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3010 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3014 /* Check for simplifications. Do some extra checking here since this
3015 routine is called so many times. */
3020 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
3023 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
3026 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
3028 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
3031 if (! strcmp (XSTR (exp
, 1), XSTR (*pterm
, 1)))
3037 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
3038 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3040 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
3043 if (! strcmp (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
3049 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
3050 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
3052 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
3055 if (! strcmp (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
3061 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
3063 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
3067 else if (GET_CODE (exp
) == NOT
)
3069 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
3073 else if (GET_CODE (*pterm
) == NOT
)
3075 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
3079 else if (attr_equal_p (exp
, *pterm
))
3085 /* Similar to `simplify_and_tree', but for IOR trees. */
3088 simplify_or_tree (exp
, pterm
, insn_code
, insn_index
)
3091 int insn_code
, insn_index
;
3096 int left_eliminates_term
, right_eliminates_term
;
3098 if (GET_CODE (exp
) == IOR
)
3100 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
3101 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
3102 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3104 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3106 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3110 else if (GET_CODE (exp
) == AND
)
3112 /* For the AND case, we do the same as above, except that we can
3113 only eliminate `term' if both sides of the AND would do so. */
3115 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
3116 left_eliminates_term
= (temp
== false_rtx
);
3119 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
3120 right_eliminates_term
= (temp
== false_rtx
);
3122 if (left_eliminates_term
&& right_eliminates_term
)
3125 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3127 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3129 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3133 if (attr_equal_p (exp
, *pterm
))
3136 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
3139 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
3142 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
3143 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3144 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
3147 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
3148 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
3149 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
3154 /* Compute approximate cost of the expression. Used to decide whether
3155 expression is cheap enough for inline. */
3164 code
= GET_CODE (x
);
3173 /* Alternatives don't result into function call. */
3174 if (!strcmp (XSTR (x
, 0), "alternative"))
3181 const char *fmt
= GET_RTX_FORMAT (code
);
3182 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3188 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3189 cost
+= attr_rtx_cost (XVECEXP (x
, i
, j
));
3192 cost
+= attr_rtx_cost (XEXP (x
, i
));
3203 /* Simplify test expression and use temporary obstack in order to avoid
3204 memory bloat. Use ATTR_IND_SIMPLIFIED to avoid unnecesary simplifications
3205 and avoid unnecesary copying if possible. */
3208 simplify_test_exp_in_temp (exp
, insn_code
, insn_index
)
3210 int insn_code
, insn_index
;
3213 struct obstack
*old
;
3214 if (ATTR_IND_SIMPLIFIED_P (exp
))
3217 rtl_obstack
= temp_obstack
;
3218 x
= simplify_test_exp (exp
, insn_code
, insn_index
);
3220 if (x
== exp
|| rtl_obstack
== temp_obstack
)
3222 return attr_copy_rtx (x
);
3225 /* Given an expression, see if it can be simplified for a particular insn
3226 code based on the values of other attributes being tested. This can
3227 eliminate nested get_attr_... calls.
3229 Note that if an endless recursion is specified in the patterns, the
3230 optimization will loop. However, it will do so in precisely the cases where
3231 an infinite recursion loop could occur during compilation. It's better that
3235 simplify_test_exp (exp
, insn_code
, insn_index
)
3237 int insn_code
, insn_index
;
3240 struct attr_desc
*attr
;
3241 struct attr_value
*av
;
3242 struct insn_ent
*ie
;
3246 /* Don't re-simplify something we already simplified. */
3247 if (ATTR_IND_SIMPLIFIED_P (exp
) || ATTR_CURR_SIMPLIFIED_P (exp
))
3250 switch (GET_CODE (exp
))
3253 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3254 SIMPLIFY_ALTERNATIVE (left
);
3255 if (left
== false_rtx
)
3257 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3258 SIMPLIFY_ALTERNATIVE (right
);
3259 if (left
== false_rtx
)
3262 /* If either side is an IOR and we have (eq_attr "alternative" ..")
3263 present on both sides, apply the distributive law since this will
3264 yield simplifications. */
3265 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
3266 && compute_alternative_mask (left
, IOR
)
3267 && compute_alternative_mask (right
, IOR
))
3269 if (GET_CODE (left
) == IOR
)
3276 newexp
= attr_rtx (IOR
,
3277 attr_rtx (AND
, left
, XEXP (right
, 0)),
3278 attr_rtx (AND
, left
, XEXP (right
, 1)));
3280 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3283 /* Try with the term on both sides. */
3284 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
3285 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3286 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
3288 if (left
== false_rtx
|| right
== false_rtx
)
3290 else if (left
== true_rtx
)
3294 else if (right
== true_rtx
)
3298 /* See if all or all but one of the insn's alternatives are specified
3299 in this tree. Optimize if so. */
3301 else if (insn_code
>= 0
3302 && (GET_CODE (left
) == AND
3303 || (GET_CODE (left
) == NOT
3304 && GET_CODE (XEXP (left
, 0)) == EQ_ATTR
3305 && XSTR (XEXP (left
, 0), 0) == alternative_name
)
3306 || GET_CODE (right
) == AND
3307 || (GET_CODE (right
) == NOT
3308 && GET_CODE (XEXP (right
, 0)) == EQ_ATTR
3309 && XSTR (XEXP (right
, 0), 0) == alternative_name
)))
3311 i
= compute_alternative_mask (exp
, AND
);
3312 if (i
& ~insn_alternatives
[insn_code
])
3313 fatal ("invalid alternative specified for pattern number %d",
3316 /* If all alternatives are excluded, this is false. */
3317 i
^= insn_alternatives
[insn_code
];
3320 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3322 /* If just one excluded, AND a comparison with that one to the
3323 front of the tree. The others will be eliminated by
3324 optimization. We do not want to do this if the insn has one
3325 alternative and we have tested none of them! */
3326 left
= make_alternative_compare (i
);
3327 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3328 newexp
= attr_rtx (AND
, left
, right
);
3330 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3334 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3336 newexp
= attr_rtx (AND
, left
, right
);
3337 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3342 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3343 SIMPLIFY_ALTERNATIVE (left
);
3344 if (left
== true_rtx
)
3346 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3347 SIMPLIFY_ALTERNATIVE (right
);
3348 if (right
== true_rtx
)
3351 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
3352 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3353 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
3355 if (right
== true_rtx
|| left
== true_rtx
)
3357 else if (left
== false_rtx
)
3361 else if (right
== false_rtx
)
3366 /* Test for simple cases where the distributive law is useful. I.e.,
3367 convert (ior (and (x) (y))
3373 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
3374 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
3376 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
3378 left
= XEXP (left
, 0);
3380 newexp
= attr_rtx (AND
, left
, right
);
3381 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3384 /* See if all or all but one of the insn's alternatives are specified
3385 in this tree. Optimize if so. */
3387 else if (insn_code
>= 0
3388 && (GET_CODE (left
) == IOR
3389 || (GET_CODE (left
) == EQ_ATTR
3390 && XSTR (left
, 0) == alternative_name
)
3391 || GET_CODE (right
) == IOR
3392 || (GET_CODE (right
) == EQ_ATTR
3393 && XSTR (right
, 0) == alternative_name
)))
3395 i
= compute_alternative_mask (exp
, IOR
);
3396 if (i
& ~insn_alternatives
[insn_code
])
3397 fatal ("invalid alternative specified for pattern number %d",
3400 /* If all alternatives are included, this is true. */
3401 i
^= insn_alternatives
[insn_code
];
3404 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3406 /* If just one excluded, IOR a comparison with that one to the
3407 front of the tree. The others will be eliminated by
3408 optimization. We do not want to do this if the insn has one
3409 alternative and we have tested none of them! */
3410 left
= make_alternative_compare (i
);
3411 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3412 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
3414 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3418 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3420 newexp
= attr_rtx (IOR
, left
, right
);
3421 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3426 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
3428 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
3429 insn_code
, insn_index
);
3430 SIMPLIFY_ALTERNATIVE (left
);
3434 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3435 SIMPLIFY_ALTERNATIVE (left
);
3436 if (GET_CODE (left
) == NOT
)
3437 return XEXP (left
, 0);
3439 if (left
== false_rtx
)
3441 else if (left
== true_rtx
)
3444 /* Try to apply De`Morgan's laws. */
3445 else if (GET_CODE (left
) == IOR
)
3447 newexp
= attr_rtx (AND
,
3448 attr_rtx (NOT
, XEXP (left
, 0)),
3449 attr_rtx (NOT
, XEXP (left
, 1)));
3451 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3453 else if (GET_CODE (left
) == AND
)
3455 newexp
= attr_rtx (IOR
,
3456 attr_rtx (NOT
, XEXP (left
, 0)),
3457 attr_rtx (NOT
, XEXP (left
, 1)));
3459 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3461 else if (left
!= XEXP (exp
, 0))
3463 newexp
= attr_rtx (NOT
, left
);
3468 if (current_alternative_string
&& XSTR (exp
, 0) == alternative_name
)
3469 return (XSTR (exp
, 1) == current_alternative_string
3470 ? true_rtx
: false_rtx
);
3472 /* Look at the value for this insn code in the specified attribute.
3473 We normally can replace this comparison with the condition that
3474 would give this insn the values being tested for. */
3475 if (XSTR (exp
, 0) != alternative_name
3476 && (attr
= find_attr (XSTR (exp
, 0), 0)) != NULL
)
3477 for (av
= attr
->first_value
; av
; av
= av
->next
)
3478 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3479 if (ie
->insn_code
== insn_code
)
3482 x
= evaluate_eq_attr (exp
, av
->value
, insn_code
, insn_index
);
3483 x
= SIMPLIFY_TEST_EXP (x
, insn_code
, insn_index
);
3484 if (attr_rtx_cost(x
) < 20)
3493 /* We have already simplified this expression. Simplifying it again
3494 won't buy anything unless we weren't given a valid insn code
3495 to process (i.e., we are canonicalizing something.). */
3496 if (insn_code
!= -2 /* Seems wrong: && current_alternative_string. */
3497 && ! ATTR_IND_SIMPLIFIED_P (newexp
))
3498 return copy_rtx_unchanging (newexp
);
3503 /* Optimize the attribute lists by seeing if we can determine conditional
3504 values from the known values of other attributes. This will save subroutine
3505 calls during the compilation. */
3510 struct attr_desc
*attr
;
3511 struct attr_value
*av
;
3512 struct insn_ent
*ie
;
3515 struct attr_value_list
3517 struct attr_value
*av
;
3518 struct insn_ent
*ie
;
3519 struct attr_desc
*attr
;
3520 struct attr_value_list
*next
;
3522 struct attr_value_list
**insn_code_values
;
3523 struct attr_value_list
*ivbuf
;
3524 struct attr_value_list
*iv
;
3526 /* For each insn code, make a list of all the insn_ent's for it,
3527 for all values for all attributes. */
3529 if (num_insn_ents
== 0)
3532 /* Make 2 extra elements, for "code" values -2 and -1. */
3534 = (struct attr_value_list
**) xmalloc ((insn_code_number
+ 2)
3535 * sizeof (struct attr_value_list
*));
3536 memset ((char *) insn_code_values
, 0,
3537 (insn_code_number
+ 2) * sizeof (struct attr_value_list
*));
3539 /* Offset the table address so we can index by -2 or -1. */
3540 insn_code_values
+= 2;
3542 iv
= ivbuf
= ((struct attr_value_list
*)
3543 xmalloc (num_insn_ents
* sizeof (struct attr_value_list
)));
3545 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
3546 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
3547 for (av
= attr
->first_value
; av
; av
= av
->next
)
3548 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3553 iv
->next
= insn_code_values
[ie
->insn_code
];
3554 insn_code_values
[ie
->insn_code
] = iv
;
3558 /* Sanity check on num_insn_ents. */
3559 if (iv
!= ivbuf
+ num_insn_ents
)
3562 /* Process one insn code at a time. */
3563 for (i
= -2; i
< insn_code_number
; i
++)
3565 /* Clear the ATTR_CURR_SIMPLIFIED_P flag everywhere relevant.
3566 We use it to mean "already simplified for this insn". */
3567 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3568 clear_struct_flag (iv
->av
->value
);
3570 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3572 struct obstack
*old
= rtl_obstack
;
3577 if (GET_CODE (av
->value
) != COND
)
3580 rtl_obstack
= temp_obstack
;
3581 #if 0 /* This was intended as a speed up, but it was slower. */
3582 if (insn_n_alternatives
[ie
->insn_code
] > 6
3583 && count_sub_rtxs (av
->value
, 200) >= 200)
3584 newexp
= simplify_by_alternatives (av
->value
, ie
->insn_code
,
3589 while (GET_CODE (newexp
) == COND
)
3591 rtx newexp2
= simplify_cond (newexp
, ie
->insn_code
,
3593 if (newexp2
== newexp
)
3599 if (newexp
!= av
->value
)
3601 newexp
= attr_copy_rtx (newexp
);
3602 remove_insn_ent (av
, ie
);
3603 av
= get_attr_value (newexp
, attr
, ie
->insn_code
);
3605 insert_insn_ent (av
, ie
);
3611 free (insn_code_values
- 2);
3616 simplify_by_alternatives (exp
, insn_code
, insn_index
)
3618 int insn_code
, insn_index
;
3621 int len
= insn_n_alternatives
[insn_code
];
3622 rtx newexp
= rtx_alloc (COND
);
3625 XVEC (newexp
, 0) = rtvec_alloc (len
* 2);
3627 /* It will not matter what value we use as the default value
3628 of the new COND, since that default will never be used.
3629 Choose something of the right type. */
3630 for (ultimate
= exp
; GET_CODE (ultimate
) == COND
;)
3631 ultimate
= XEXP (ultimate
, 1);
3632 XEXP (newexp
, 1) = ultimate
;
3634 for (i
= 0; i
< insn_n_alternatives
[insn_code
]; i
++)
3636 current_alternative_string
= attr_numeral (i
);
3637 XVECEXP (newexp
, 0, i
* 2) = make_alternative_compare (1 << i
);
3638 XVECEXP (newexp
, 0, i
* 2 + 1)
3639 = simplify_cond (exp
, insn_code
, insn_index
);
3642 current_alternative_string
= 0;
3643 return simplify_cond (newexp
, insn_code
, insn_index
);
3647 /* If EXP is a suitable expression, reorganize it by constructing an
3648 equivalent expression that is a COND with the tests being all combinations
3649 of attribute values and the values being simple constants. */
3652 simplify_by_exploding (exp
)
3655 rtx list
= 0, link
, condexp
, defval
= NULL_RTX
;
3656 struct dimension
*space
;
3657 rtx
*condtest
, *condval
;
3658 int i
, j
, total
, ndim
= 0;
3659 int most_tests
, num_marks
, new_marks
;
3662 /* Locate all the EQ_ATTR expressions. */
3663 if (! find_and_mark_used_attributes (exp
, &list
, &ndim
) || ndim
== 0)
3665 unmark_used_attributes (list
, 0, 0);
3669 /* Create an attribute space from the list of used attributes. For each
3670 dimension in the attribute space, record the attribute, list of values
3671 used, and number of values used. Add members to the list of values to
3672 cover the domain of the attribute. This makes the expanded COND form
3673 order independent. */
3675 space
= (struct dimension
*) xmalloc (ndim
* sizeof (struct dimension
));
3678 for (ndim
= 0; list
; ndim
++)
3680 /* Pull the first attribute value from the list and record that
3681 attribute as another dimension in the attribute space. */
3682 const char *name
= XSTR (XEXP (list
, 0), 0);
3685 if ((space
[ndim
].attr
= find_attr (name
, 0)) == 0
3686 || space
[ndim
].attr
->is_numeric
)
3688 unmark_used_attributes (list
, space
, ndim
);
3692 /* Add all remaining attribute values that refer to this attribute. */
3693 space
[ndim
].num_values
= 0;
3694 space
[ndim
].values
= 0;
3696 for (link
= list
; link
; link
= *prev
)
3697 if (! strcmp (XSTR (XEXP (link
, 0), 0), name
))
3699 space
[ndim
].num_values
++;
3700 *prev
= XEXP (link
, 1);
3701 XEXP (link
, 1) = space
[ndim
].values
;
3702 space
[ndim
].values
= link
;
3705 prev
= &XEXP (link
, 1);
3707 /* Add sufficient members to the list of values to make the list
3708 mutually exclusive and record the total size of the attribute
3710 total
*= add_values_to_cover (&space
[ndim
]);
3713 /* Sort the attribute space so that the attributes go from non-constant
3714 to constant and from most values to least values. */
3715 for (i
= 0; i
< ndim
; i
++)
3716 for (j
= ndim
- 1; j
> i
; j
--)
3717 if ((space
[j
-1].attr
->is_const
&& !space
[j
].attr
->is_const
)
3718 || space
[j
-1].num_values
< space
[j
].num_values
)
3720 struct dimension tmp
;
3722 space
[j
] = space
[j
- 1];
3726 /* Establish the initial current value. */
3727 for (i
= 0; i
< ndim
; i
++)
3728 space
[i
].current_value
= space
[i
].values
;
3730 condtest
= (rtx
*) xmalloc (total
* sizeof (rtx
));
3731 condval
= (rtx
*) xmalloc (total
* sizeof (rtx
));
3733 /* Expand the tests and values by iterating over all values in the
3737 condtest
[i
] = test_for_current_value (space
, ndim
);
3738 condval
[i
] = simplify_with_current_value (exp
, space
, ndim
);
3739 if (! increment_current_value (space
, ndim
))
3745 /* We are now finished with the original expression. */
3746 unmark_used_attributes (0, space
, ndim
);
3749 /* Find the most used constant value and make that the default. */
3751 for (i
= num_marks
= 0; i
< total
; i
++)
3752 if (GET_CODE (condval
[i
]) == CONST_STRING
3753 && ! ATTR_EQ_ATTR_P (condval
[i
]))
3755 /* Mark the unmarked constant value and count how many are marked. */
3756 ATTR_EQ_ATTR_P (condval
[i
]) = 1;
3757 for (j
= new_marks
= 0; j
< total
; j
++)
3758 if (GET_CODE (condval
[j
]) == CONST_STRING
3759 && ATTR_EQ_ATTR_P (condval
[j
]))
3761 if (new_marks
- num_marks
> most_tests
)
3763 most_tests
= new_marks
- num_marks
;
3764 defval
= condval
[i
];
3766 num_marks
= new_marks
;
3768 /* Clear all the marks. */
3769 for (i
= 0; i
< total
; i
++)
3770 ATTR_EQ_ATTR_P (condval
[i
]) = 0;
3772 /* Give up if nothing is constant. */
3776 /* If all values are the default, use that. */
3777 else if (total
== most_tests
)
3780 /* Make a COND with the most common constant value the default. (A more
3781 complex method where tests with the same value were combined didn't
3782 seem to improve things.) */
3785 condexp
= rtx_alloc (COND
);
3786 XVEC (condexp
, 0) = rtvec_alloc ((total
- most_tests
) * 2);
3787 XEXP (condexp
, 1) = defval
;
3788 for (i
= j
= 0; i
< total
; i
++)
3789 if (condval
[i
] != defval
)
3791 XVECEXP (condexp
, 0, 2 * j
) = condtest
[i
];
3792 XVECEXP (condexp
, 0, 2 * j
+ 1) = condval
[i
];
3802 /* Set the ATTR_EQ_ATTR_P flag for all EQ_ATTR expressions in EXP and
3803 verify that EXP can be simplified to a constant term if all the EQ_ATTR
3804 tests have known value. */
3807 find_and_mark_used_attributes (exp
, terms
, nterms
)
3813 switch (GET_CODE (exp
))
3816 if (! ATTR_EQ_ATTR_P (exp
))
3818 rtx link
= rtx_alloc (EXPR_LIST
);
3819 XEXP (link
, 0) = exp
;
3820 XEXP (link
, 1) = *terms
;
3823 ATTR_EQ_ATTR_P (exp
) = 1;
3832 if (! find_and_mark_used_attributes (XEXP (exp
, 2), terms
, nterms
))
3836 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3839 if (! find_and_mark_used_attributes (XEXP (exp
, 0), terms
, nterms
))
3844 for (i
= 0; i
< XVECLEN (exp
, 0); i
++)
3845 if (! find_and_mark_used_attributes (XVECEXP (exp
, 0, i
), terms
, nterms
))
3847 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3856 /* Clear the ATTR_EQ_ATTR_P flag in all EQ_ATTR expressions on LIST and
3857 in the values of the NDIM-dimensional attribute space SPACE. */
3860 unmark_used_attributes (list
, space
, ndim
)
3862 struct dimension
*space
;
3868 for (i
= 0; i
< ndim
; i
++)
3869 unmark_used_attributes (space
[i
].values
, 0, 0);
3871 for (link
= list
; link
; link
= XEXP (link
, 1))
3873 exp
= XEXP (link
, 0);
3874 if (GET_CODE (exp
) == EQ_ATTR
)
3875 ATTR_EQ_ATTR_P (exp
) = 0;
3879 /* Update the attribute dimension DIM so that all values of the attribute
3880 are tested. Return the updated number of values. */
3883 add_values_to_cover (dim
)
3884 struct dimension
*dim
;
3886 struct attr_value
*av
;
3887 rtx exp
, link
, *prev
;
3890 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3891 if (GET_CODE (av
->value
) == CONST_STRING
)
3894 if (nalt
< dim
->num_values
)
3896 else if (nalt
== dim
->num_values
)
3899 else if (nalt
* 2 < dim
->num_values
* 3)
3901 /* Most all the values of the attribute are used, so add all the unused
3903 prev
= &dim
->values
;
3904 for (link
= dim
->values
; link
; link
= *prev
)
3905 prev
= &XEXP (link
, 1);
3907 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3908 if (GET_CODE (av
->value
) == CONST_STRING
)
3910 exp
= attr_eq (dim
->attr
->name
, XSTR (av
->value
, 0));
3911 if (ATTR_EQ_ATTR_P (exp
))
3914 link
= rtx_alloc (EXPR_LIST
);
3915 XEXP (link
, 0) = exp
;
3918 prev
= &XEXP (link
, 1);
3920 dim
->num_values
= nalt
;
3924 rtx orexp
= false_rtx
;
3926 /* Very few values are used, so compute a mutually exclusive
3927 expression. (We could do this for numeric values if that becomes
3929 prev
= &dim
->values
;
3930 for (link
= dim
->values
; link
; link
= *prev
)
3932 orexp
= insert_right_side (IOR
, orexp
, XEXP (link
, 0), -2, -2);
3933 prev
= &XEXP (link
, 1);
3935 link
= rtx_alloc (EXPR_LIST
);
3936 XEXP (link
, 0) = attr_rtx (NOT
, orexp
);
3941 return dim
->num_values
;
3944 /* Increment the current value for the NDIM-dimensional attribute space SPACE
3945 and return FALSE if the increment overflowed. */
3948 increment_current_value (space
, ndim
)
3949 struct dimension
*space
;
3954 for (i
= ndim
- 1; i
>= 0; i
--)
3956 if ((space
[i
].current_value
= XEXP (space
[i
].current_value
, 1)) == 0)
3957 space
[i
].current_value
= space
[i
].values
;
3964 /* Construct an expression corresponding to the current value for the
3965 NDIM-dimensional attribute space SPACE. */
3968 test_for_current_value (space
, ndim
)
3969 struct dimension
*space
;
3975 for (i
= 0; i
< ndim
; i
++)
3976 exp
= insert_right_side (AND
, exp
, XEXP (space
[i
].current_value
, 0),
3982 /* Given the current value of the NDIM-dimensional attribute space SPACE,
3983 set the corresponding EQ_ATTR expressions to that value and reduce
3984 the expression EXP as much as possible. On input [and output], all
3985 known EQ_ATTR expressions are set to FALSE. */
3988 simplify_with_current_value (exp
, space
, ndim
)
3990 struct dimension
*space
;
3996 /* Mark each current value as TRUE. */
3997 for (i
= 0; i
< ndim
; i
++)
3999 x
= XEXP (space
[i
].current_value
, 0);
4000 if (GET_CODE (x
) == EQ_ATTR
)
4001 ATTR_EQ_ATTR_P (x
) = 0;
4004 exp
= simplify_with_current_value_aux (exp
);
4006 /* Change each current value back to FALSE. */
4007 for (i
= 0; i
< ndim
; i
++)
4009 x
= XEXP (space
[i
].current_value
, 0);
4010 if (GET_CODE (x
) == EQ_ATTR
)
4011 ATTR_EQ_ATTR_P (x
) = 1;
4017 /* Reduce the expression EXP based on the ATTR_EQ_ATTR_P settings of
4018 all EQ_ATTR expressions. */
4021 simplify_with_current_value_aux (exp
)
4027 switch (GET_CODE (exp
))
4030 if (ATTR_EQ_ATTR_P (exp
))
4039 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
4040 if (cond
== true_rtx
)
4041 return simplify_with_current_value_aux (XEXP (exp
, 1));
4042 else if (cond
== false_rtx
)
4043 return simplify_with_current_value_aux (XEXP (exp
, 2));
4045 return attr_rtx (IF_THEN_ELSE
, cond
,
4046 simplify_with_current_value_aux (XEXP (exp
, 1)),
4047 simplify_with_current_value_aux (XEXP (exp
, 2)));
4050 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
4051 if (cond
== true_rtx
)
4053 else if (cond
== false_rtx
)
4054 return simplify_with_current_value_aux (XEXP (exp
, 0));
4056 return attr_rtx (IOR
, cond
,
4057 simplify_with_current_value_aux (XEXP (exp
, 0)));
4060 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
4061 if (cond
== true_rtx
)
4062 return simplify_with_current_value_aux (XEXP (exp
, 0));
4063 else if (cond
== false_rtx
)
4066 return attr_rtx (AND
, cond
,
4067 simplify_with_current_value_aux (XEXP (exp
, 0)));
4070 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
4071 if (cond
== true_rtx
)
4073 else if (cond
== false_rtx
)
4076 return attr_rtx (NOT
, cond
);
4079 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4081 cond
= simplify_with_current_value_aux (XVECEXP (exp
, 0, i
));
4082 if (cond
== true_rtx
)
4083 return simplify_with_current_value_aux (XVECEXP (exp
, 0, i
+ 1));
4084 else if (cond
== false_rtx
)
4087 abort (); /* With all EQ_ATTR's of known value, a case should
4088 have been selected. */
4090 return simplify_with_current_value_aux (XEXP (exp
, 1));
4097 /* Clear the ATTR_CURR_SIMPLIFIED_P flag in EXP and its subexpressions. */
4100 clear_struct_flag (x
)
4108 ATTR_CURR_SIMPLIFIED_P (x
) = 0;
4109 if (ATTR_IND_SIMPLIFIED_P (x
))
4112 code
= GET_CODE (x
);
4133 /* Compare the elements. If any pair of corresponding elements
4134 fail to match, return 0 for the whole things. */
4136 fmt
= GET_RTX_FORMAT (code
);
4137 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4143 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4144 clear_struct_flag (XVECEXP (x
, i
, j
));
4148 clear_struct_flag (XEXP (x
, i
));
4154 /* Return the number of RTX objects making up the expression X.
4155 But if we count more than MAX objects, stop counting. */
4158 count_sub_rtxs (x
, max
)
4168 code
= GET_CODE (x
);
4189 /* Compare the elements. If any pair of corresponding elements
4190 fail to match, return 0 for the whole things. */
4192 fmt
= GET_RTX_FORMAT (code
);
4193 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4202 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4203 total
+= count_sub_rtxs (XVECEXP (x
, i
, j
), max
);
4207 total
+= count_sub_rtxs (XEXP (x
, i
), max
);
4215 /* Create table entries for DEFINE_ATTR. */
4218 gen_attr (exp
, lineno
)
4222 struct attr_desc
*attr
;
4223 struct attr_value
*av
;
4224 const char *name_ptr
;
4227 /* Make a new attribute structure. Check for duplicate by looking at
4228 attr->default_val, since it is initialized by this routine. */
4229 attr
= find_attr (XSTR (exp
, 0), 1);
4230 if (attr
->default_val
)
4232 message_with_line (lineno
, "duplicate definition for attribute %s",
4234 message_with_line (attr
->lineno
, "previous definition");
4238 attr
->lineno
= lineno
;
4240 if (*XSTR (exp
, 1) == '\0')
4241 attr
->is_numeric
= 1;
4244 name_ptr
= XSTR (exp
, 1);
4245 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
4247 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
4248 av
->value
= attr_rtx (CONST_STRING
, p
);
4249 av
->next
= attr
->first_value
;
4250 attr
->first_value
= av
;
4251 av
->first_insn
= NULL
;
4253 av
->has_asm_insn
= 0;
4257 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
4260 if (attr
->is_numeric
)
4262 message_with_line (lineno
,
4263 "constant attributes may not take numeric values");
4267 /* Get rid of the CONST node. It is allowed only at top-level. */
4268 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
4271 if (! strcmp (attr
->name
, "length") && ! attr
->is_numeric
)
4273 message_with_line (lineno
,
4274 "`length' attribute must take numeric values");
4278 /* Set up the default value. */
4279 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
4280 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
4283 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
4284 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
4285 number of alternatives as this should be checked elsewhere. */
4288 count_alternatives (exp
)
4294 if (GET_CODE (exp
) == MATCH_OPERAND
)
4295 return n_comma_elts (XSTR (exp
, 2));
4297 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4298 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4303 n
= count_alternatives (XEXP (exp
, i
));
4310 if (XVEC (exp
, i
) != NULL
)
4311 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4313 n
= count_alternatives (XVECEXP (exp
, i
, j
));
4322 /* Returns non-zero if the given expression contains an EQ_ATTR with the
4323 `alternative' attribute. */
4326 compares_alternatives_p (exp
)
4332 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
4335 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4336 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4341 if (compares_alternatives_p (XEXP (exp
, i
)))
4346 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4347 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
4355 /* Returns non-zero is INNER is contained in EXP. */
4358 contained_in_p (inner
, exp
)
4365 if (rtx_equal_p (inner
, exp
))
4368 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4369 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4374 if (contained_in_p (inner
, XEXP (exp
, i
)))
4379 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4380 if (contained_in_p (inner
, XVECEXP (exp
, i
, j
)))
4388 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
4391 gen_insn (exp
, lineno
)
4395 struct insn_def
*id
;
4397 id
= (struct insn_def
*) oballoc (sizeof (struct insn_def
));
4401 id
->lineno
= lineno
;
4403 switch (GET_CODE (exp
))
4406 id
->insn_code
= insn_code_number
;
4407 id
->insn_index
= insn_index_number
;
4408 id
->num_alternatives
= count_alternatives (exp
);
4409 if (id
->num_alternatives
== 0)
4410 id
->num_alternatives
= 1;
4414 case DEFINE_PEEPHOLE
:
4415 id
->insn_code
= insn_code_number
;
4416 id
->insn_index
= insn_index_number
;
4417 id
->num_alternatives
= count_alternatives (exp
);
4418 if (id
->num_alternatives
== 0)
4419 id
->num_alternatives
= 1;
4423 case DEFINE_ASM_ATTRIBUTES
:
4425 id
->insn_index
= -1;
4426 id
->num_alternatives
= 1;
4428 got_define_asm_attributes
= 1;
4436 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
4437 true or annul false is specified, and make a `struct delay_desc'. */
4440 gen_delay (def
, lineno
)
4444 struct delay_desc
*delay
;
4447 if (XVECLEN (def
, 1) % 3 != 0)
4449 message_with_line (lineno
,
4450 "number of elements in DEFINE_DELAY must be multiple of three");
4455 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
4457 if (XVECEXP (def
, 1, i
+ 1))
4458 have_annul_true
= 1;
4459 if (XVECEXP (def
, 1, i
+ 2))
4460 have_annul_false
= 1;
4463 delay
= (struct delay_desc
*) oballoc (sizeof (struct delay_desc
));
4465 delay
->num
= ++num_delays
;
4466 delay
->next
= delays
;
4467 delay
->lineno
= lineno
;
4471 /* Process a DEFINE_FUNCTION_UNIT.
4473 This gives information about a function unit contained in the CPU.
4474 We fill in a `struct function_unit_op' and a `struct function_unit'
4475 with information used later by `expand_unit'. */
4478 gen_unit (def
, lineno
)
4482 struct function_unit
*unit
;
4483 struct function_unit_op
*op
;
4484 const char *name
= XSTR (def
, 0);
4485 int multiplicity
= XINT (def
, 1);
4486 int simultaneity
= XINT (def
, 2);
4487 rtx condexp
= XEXP (def
, 3);
4488 int ready_cost
= MAX (XINT (def
, 4), 1);
4489 int issue_delay
= MAX (XINT (def
, 5), 1);
4491 /* See if we have already seen this function unit. If so, check that
4492 the multiplicity and simultaneity values are the same. If not, make
4493 a structure for this function unit. */
4494 for (unit
= units
; unit
; unit
= unit
->next
)
4495 if (! strcmp (unit
->name
, name
))
4497 if (unit
->multiplicity
!= multiplicity
4498 || unit
->simultaneity
!= simultaneity
)
4500 message_with_line (lineno
,
4501 "differing specifications given for function unit %s",
4503 message_with_line (unit
->first_lineno
, "previous definition");
4512 unit
= (struct function_unit
*) oballoc (sizeof (struct function_unit
));
4514 unit
->multiplicity
= multiplicity
;
4515 unit
->simultaneity
= simultaneity
;
4516 unit
->issue_delay
.min
= unit
->issue_delay
.max
= issue_delay
;
4517 unit
->num
= num_units
++;
4518 unit
->num_opclasses
= 0;
4519 unit
->condexp
= false_rtx
;
4522 unit
->first_lineno
= lineno
;
4526 /* Make a new operation class structure entry and initialize it. */
4527 op
= (struct function_unit_op
*) oballoc (sizeof (struct function_unit_op
));
4528 op
->condexp
= condexp
;
4529 op
->num
= unit
->num_opclasses
++;
4530 op
->ready
= ready_cost
;
4531 op
->issue_delay
= issue_delay
;
4532 op
->next
= unit
->ops
;
4533 op
->lineno
= lineno
;
4535 num_unit_opclasses
++;
4537 /* Set our issue expression based on whether or not an optional conflict
4538 vector was specified. */
4541 /* Compute the IOR of all the specified expressions. */
4542 rtx orexp
= false_rtx
;
4545 for (i
= 0; i
< XVECLEN (def
, 6); i
++)
4546 orexp
= insert_right_side (IOR
, orexp
, XVECEXP (def
, 6, i
), -2, -2);
4548 op
->conflict_exp
= orexp
;
4549 extend_range (&unit
->issue_delay
, 1, issue_delay
);
4553 op
->conflict_exp
= true_rtx
;
4554 extend_range (&unit
->issue_delay
, issue_delay
, issue_delay
);
4557 /* Merge our conditional into that of the function unit so we can determine
4558 which insns are used by the function unit. */
4559 unit
->condexp
= insert_right_side (IOR
, unit
->condexp
, op
->condexp
, -2, -2);
4562 /* Given a piece of RTX, print a C expression to test its truth value.
4563 We use AND and IOR both for logical and bit-wise operations, so
4564 interpret them as logical unless they are inside a comparison expression.
4565 The first bit of FLAGS will be non-zero in that case.
4567 Set the second bit of FLAGS to make references to attribute values use
4568 a cached local variable instead of calling a function. */
4571 write_test_expr (exp
, flags
)
4575 int comparison_operator
= 0;
4577 struct attr_desc
*attr
;
4579 /* In order not to worry about operator precedence, surround our part of
4580 the expression with parentheses. */
4583 code
= GET_CODE (exp
);
4586 /* Binary operators. */
4588 case GE
: case GT
: case GEU
: case GTU
:
4589 case LE
: case LT
: case LEU
: case LTU
:
4590 comparison_operator
= 1;
4592 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
4593 case AND
: case IOR
: case XOR
:
4594 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
4595 write_test_expr (XEXP (exp
, 0), flags
| comparison_operator
);
4611 printf (" >= (unsigned) ");
4614 printf (" > (unsigned) ");
4623 printf (" <= (unsigned) ");
4626 printf (" < (unsigned) ");
4669 write_test_expr (XEXP (exp
, 1), flags
| comparison_operator
);
4673 /* Special-case (not (eq_attrq "alternative" "x")) */
4674 if (! (flags
& 1) && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
4675 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
4677 printf ("which_alternative != %s", XSTR (XEXP (exp
, 0), 1));
4681 /* Otherwise, fall through to normal unary operator. */
4683 /* Unary operators. */
4703 write_test_expr (XEXP (exp
, 0), flags
);
4706 /* Comparison test of an attribute with a value. Most of these will
4707 have been removed by optimization. Handle "alternative"
4708 specially and give error if EQ_ATTR present inside a comparison. */
4711 fatal ("EQ_ATTR not valid inside comparison");
4713 if (XSTR (exp
, 0) == alternative_name
)
4715 printf ("which_alternative == %s", XSTR (exp
, 1));
4719 attr
= find_attr (XSTR (exp
, 0), 0);
4723 /* Now is the time to expand the value of a constant attribute. */
4726 write_test_expr (evaluate_eq_attr (exp
, attr
->default_val
->value
,
4733 printf ("attr_%s", attr
->name
);
4735 printf ("get_attr_%s (insn)", attr
->name
);
4737 write_attr_valueq (attr
, XSTR (exp
, 1));
4741 /* Comparison test of flags for define_delays. */
4744 fatal ("ATTR_FLAG not valid inside comparison");
4745 printf ("(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
4748 /* See if an operand matches a predicate. */
4750 /* If only a mode is given, just ensure the mode matches the operand.
4751 If neither a mode nor predicate is given, error. */
4752 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
4754 if (GET_MODE (exp
) == VOIDmode
)
4755 fatal ("null MATCH_OPERAND specified as test");
4757 printf ("GET_MODE (operands[%d]) == %smode",
4758 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4761 printf ("%s (operands[%d], %smode)",
4762 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4766 printf ("%s (insn)", XSTR (exp
, 0));
4769 /* Constant integer. */
4771 printf (HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
4774 /* A random C expression. */
4776 printf ("%s", XSTR (exp
, 0));
4779 /* The address of the branch target. */
4781 printf ("INSN_ADDRESSES_SET_P () ? INSN_ADDRESSES (INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])) : 0",
4782 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
4786 /* The address of the current insn. We implement this actually as the
4787 address of the current insn for backward branches, but the last
4788 address of the next insn for forward branches, and both with
4789 adjustments that account for the worst-case possible stretching of
4790 intervening alignments between this insn and its destination. */
4791 printf ("insn_current_reference_address (insn)");
4795 printf ("%s", XSTR (exp
, 0));
4799 write_test_expr (XEXP (exp
, 0), flags
& 2);
4801 write_test_expr (XEXP (exp
, 1), flags
| 1);
4803 write_test_expr (XEXP (exp
, 2), flags
| 1);
4807 fatal ("bad RTX code `%s' in attribute calculation\n",
4808 GET_RTX_NAME (code
));
4814 /* Given an attribute value, return the maximum CONST_STRING argument
4815 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
4818 max_attr_value (exp
, unknownp
)
4825 switch (GET_CODE (exp
))
4828 current_max
= atoi (XSTR (exp
, 0));
4832 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4833 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4835 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4836 if (n
> current_max
)
4842 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4843 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
4844 if (n
> current_max
)
4850 current_max
= INT_MAX
;
4857 /* Given an attribute value, return the result of ORing together all
4858 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
4859 if the numeric value is not known. */
4862 or_attr_value (exp
, unknownp
)
4869 switch (GET_CODE (exp
))
4872 current_or
= atoi (XSTR (exp
, 0));
4876 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4877 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4878 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4882 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4883 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
4895 /* Scan an attribute value, possibly a conditional, and record what actions
4896 will be required to do any conditional tests in it.
4899 `must_extract' if we need to extract the insn operands
4900 `must_constrain' if we must compute `which_alternative'
4901 `address_used' if an address expression was used
4902 `length_used' if an (eq_attr "length" ...) was used
4906 walk_attr_value (exp
)
4916 code
= GET_CODE (exp
);
4920 if (! ATTR_IND_SIMPLIFIED_P (exp
))
4921 /* Since this is an arbitrary expression, it can look at anything.
4922 However, constant expressions do not depend on any particular
4924 must_extract
= must_constrain
= 1;
4932 if (XSTR (exp
, 0) == alternative_name
)
4933 must_extract
= must_constrain
= 1;
4934 else if (strcmp (XSTR (exp
, 0), "length") == 0)
4954 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
4959 walk_attr_value (XEXP (exp
, i
));
4963 if (XVEC (exp
, i
) != NULL
)
4964 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4965 walk_attr_value (XVECEXP (exp
, i
, j
));
4970 /* Write out a function to obtain the attribute for a given INSN. */
4973 write_attr_get (attr
)
4974 struct attr_desc
*attr
;
4976 struct attr_value
*av
, *common_av
;
4978 /* Find the most used attribute value. Handle that as the `default' of the
4979 switch we will generate. */
4980 common_av
= find_most_used (attr
);
4982 /* Write out prototype of function. */
4983 if (!attr
->is_numeric
)
4984 printf ("extern enum attr_%s ", attr
->name
);
4985 else if (attr
->unsigned_p
)
4986 printf ("extern unsigned int ");
4988 printf ("extern int ");
4989 /* If the attribute name starts with a star, the remainder is the name of
4990 the subroutine to use, instead of `get_attr_...'. */
4991 if (attr
->name
[0] == '*')
4992 printf ("%s PARAMS ((rtx));\n", &attr
->name
[1]);
4994 printf ("get_attr_%s PARAMS ((%s));\n", attr
->name
,
4995 (attr
->is_const
? "void" : "rtx"));
4997 /* Write out start of function, then all values with explicit `case' lines,
4998 then a `default', then the value with the most uses. */
4999 if (!attr
->is_numeric
)
5000 printf ("enum attr_%s\n", attr
->name
);
5001 else if (attr
->unsigned_p
)
5002 printf ("unsigned int\n");
5006 /* If the attribute name starts with a star, the remainder is the name of
5007 the subroutine to use, instead of `get_attr_...'. */
5008 if (attr
->name
[0] == '*')
5009 printf ("%s (insn)\n", &attr
->name
[1]);
5010 else if (attr
->is_const
== 0)
5011 printf ("get_attr_%s (insn)\n", attr
->name
);
5014 printf ("get_attr_%s ()\n", attr
->name
);
5017 for (av
= attr
->first_value
; av
; av
= av
->next
)
5018 if (av
->num_insns
!= 0)
5019 write_attr_set (attr
, 2, av
->value
, "return", ";",
5020 true_rtx
, av
->first_insn
->insn_code
,
5021 av
->first_insn
->insn_index
);
5027 printf (" rtx insn;\n");
5030 if (GET_CODE (common_av
->value
) == FFS
)
5032 rtx p
= XEXP (common_av
->value
, 0);
5034 /* No need to emit code to abort if the insn is unrecognized; the
5035 other get_attr_foo functions will do that when we call them. */
5037 write_toplevel_expr (p
);
5039 printf ("\n if (accum && accum == (accum & -accum))\n");
5041 printf (" int i;\n");
5042 printf (" for (i = 0; accum >>= 1; ++i) continue;\n");
5043 printf (" accum = i;\n");
5044 printf (" }\n else\n");
5045 printf (" accum = ~accum;\n");
5046 printf (" return accum;\n}\n\n");
5050 printf (" switch (recog_memoized (insn))\n");
5053 for (av
= attr
->first_value
; av
; av
= av
->next
)
5054 if (av
!= common_av
)
5055 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5057 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5058 printf (" }\n}\n\n");
5062 /* Given an AND tree of known true terms (because we are inside an `if' with
5063 that as the condition or are in an `else' clause) and an expression,
5064 replace any known true terms with TRUE. Use `simplify_and_tree' to do
5065 the bulk of the work. */
5068 eliminate_known_true (known_true
, exp
, insn_code
, insn_index
)
5071 int insn_code
, insn_index
;
5075 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
5077 if (GET_CODE (known_true
) == AND
)
5079 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
5080 insn_code
, insn_index
);
5081 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
5082 insn_code
, insn_index
);
5087 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
5093 /* Write out a series of tests and assignment statements to perform tests and
5094 sets of an attribute value. We are passed an indentation amount and prefix
5095 and suffix strings to write around each attribute value (e.g., "return"
5099 write_attr_set (attr
, indent
, value
, prefix
, suffix
, known_true
,
5100 insn_code
, insn_index
)
5101 struct attr_desc
*attr
;
5107 int insn_code
, insn_index
;
5109 if (GET_CODE (value
) == COND
)
5111 /* Assume the default value will be the default of the COND unless we
5112 find an always true expression. */
5113 rtx default_val
= XEXP (value
, 1);
5114 rtx our_known_true
= known_true
;
5119 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
5124 testexp
= eliminate_known_true (our_known_true
,
5125 XVECEXP (value
, 0, i
),
5126 insn_code
, insn_index
);
5127 newexp
= attr_rtx (NOT
, testexp
);
5128 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
5129 insn_code
, insn_index
);
5131 /* If the test expression is always true or if the next `known_true'
5132 expression is always false, this is the last case, so break
5133 out and let this value be the `else' case. */
5134 if (testexp
== true_rtx
|| newexp
== false_rtx
)
5136 default_val
= XVECEXP (value
, 0, i
+ 1);
5140 /* Compute the expression to pass to our recursive call as being
5142 inner_true
= insert_right_side (AND
, our_known_true
,
5143 testexp
, insn_code
, insn_index
);
5145 /* If this is always false, skip it. */
5146 if (inner_true
== false_rtx
)
5149 write_indent (indent
);
5150 printf ("%sif ", first_if
? "" : "else ");
5152 write_test_expr (testexp
, 0);
5154 write_indent (indent
+ 2);
5157 write_attr_set (attr
, indent
+ 4,
5158 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
5159 inner_true
, insn_code
, insn_index
);
5160 write_indent (indent
+ 2);
5162 our_known_true
= newexp
;
5167 write_indent (indent
);
5169 write_indent (indent
+ 2);
5173 write_attr_set (attr
, first_if
? indent
: indent
+ 4, default_val
,
5174 prefix
, suffix
, our_known_true
, insn_code
, insn_index
);
5178 write_indent (indent
+ 2);
5184 write_indent (indent
);
5185 printf ("%s ", prefix
);
5186 write_attr_value (attr
, value
);
5187 printf ("%s\n", suffix
);
5191 /* Write out the computation for one attribute value. */
5194 write_attr_case (attr
, av
, write_case_lines
, prefix
, suffix
, indent
,
5196 struct attr_desc
*attr
;
5197 struct attr_value
*av
;
5198 int write_case_lines
;
5199 const char *prefix
, *suffix
;
5203 struct insn_ent
*ie
;
5205 if (av
->num_insns
== 0)
5208 if (av
->has_asm_insn
)
5210 write_indent (indent
);
5211 printf ("case -1:\n");
5212 write_indent (indent
+ 2);
5213 printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
5214 write_indent (indent
+ 2);
5215 printf (" && asm_noperands (PATTERN (insn)) < 0)\n");
5216 write_indent (indent
+ 2);
5217 printf (" fatal_insn_not_found (insn);\n");
5220 if (write_case_lines
)
5222 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5223 if (ie
->insn_code
!= -1)
5225 write_indent (indent
);
5226 printf ("case %d:\n", ie
->insn_code
);
5231 write_indent (indent
);
5232 printf ("default:\n");
5235 /* See what we have to do to output this value. */
5236 must_extract
= must_constrain
= address_used
= 0;
5237 walk_attr_value (av
->value
);
5241 write_indent (indent
+ 2);
5242 printf ("extract_constrain_insn_cached (insn);\n");
5244 else if (must_extract
)
5246 write_indent (indent
+ 2);
5247 printf ("extract_insn_cached (insn);\n");
5250 write_attr_set (attr
, indent
+ 2, av
->value
, prefix
, suffix
,
5251 known_true
, av
->first_insn
->insn_code
,
5252 av
->first_insn
->insn_index
);
5254 if (strncmp (prefix
, "return", 6))
5256 write_indent (indent
+ 2);
5257 printf ("break;\n");
5262 /* Search for uses of non-const attributes and write code to cache them. */
5265 write_expr_attr_cache (p
, attr
)
5267 struct attr_desc
*attr
;
5272 if (GET_CODE (p
) == EQ_ATTR
)
5274 if (XSTR (p
, 0) != attr
->name
)
5277 if (!attr
->is_numeric
)
5278 printf (" enum attr_%s ", attr
->name
);
5279 else if (attr
->unsigned_p
)
5280 printf (" unsigned int ");
5284 printf ("attr_%s = get_attr_%s (insn);\n", attr
->name
, attr
->name
);
5288 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
5289 ie
= GET_RTX_LENGTH (GET_CODE (p
));
5290 for (i
= 0; i
< ie
; i
++)
5295 if (write_expr_attr_cache (XEXP (p
, i
), attr
))
5300 je
= XVECLEN (p
, i
);
5301 for (j
= 0; j
< je
; ++j
)
5302 if (write_expr_attr_cache (XVECEXP (p
, i
, j
), attr
))
5311 /* Evaluate an expression at top level. A front end to write_test_expr,
5312 in which we cache attribute values and break up excessively large
5313 expressions to cater to older compilers. */
5316 write_toplevel_expr (p
)
5319 struct attr_desc
*attr
;
5322 for (i
= 0; i
< MAX_ATTRS_INDEX
; ++i
)
5323 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5324 if (!attr
->is_const
)
5325 write_expr_attr_cache (p
, attr
);
5327 printf (" unsigned long accum = 0;\n\n");
5329 while (GET_CODE (p
) == IOR
)
5332 if (GET_CODE (XEXP (p
, 0)) == IOR
)
5333 e
= XEXP (p
, 1), p
= XEXP (p
, 0);
5335 e
= XEXP (p
, 0), p
= XEXP (p
, 1);
5337 printf (" accum |= ");
5338 write_test_expr (e
, 3);
5341 printf (" accum |= ");
5342 write_test_expr (p
, 3);
5346 /* Utilities to write names in various forms. */
5349 write_unit_name (prefix
, num
, suffix
)
5354 struct function_unit
*unit
;
5356 for (unit
= units
; unit
; unit
= unit
->next
)
5357 if (unit
->num
== num
)
5359 printf ("%s%s%s", prefix
, unit
->name
, suffix
);
5363 printf ("%s<unknown>%s", prefix
, suffix
);
5367 write_attr_valueq (attr
, s
)
5368 struct attr_desc
*attr
;
5371 if (attr
->is_numeric
)
5377 /* Make the blockage range values and function units used values easier
5379 if (attr
->func_units_p
)
5382 printf (" /* units: none */");
5384 write_unit_name (" /* units: ", num
, " */");
5388 const char *sep
= " /* units: ";
5389 for (i
= 0, num
= ~num
; num
; i
++, num
>>= 1)
5392 write_unit_name (sep
, i
, (num
== 1) ? " */" : "");
5398 else if (attr
->blockage_p
)
5399 printf (" /* min %d, max %d */", num
>> (HOST_BITS_PER_INT
/ 2),
5400 num
& ((1 << (HOST_BITS_PER_INT
/ 2)) - 1));
5402 else if (num
> 9 || num
< 0)
5403 printf (" /* 0x%x */", num
);
5407 write_upcase (attr
->name
);
5414 write_attr_value (attr
, value
)
5415 struct attr_desc
*attr
;
5420 switch (GET_CODE (value
))
5423 write_attr_valueq (attr
, XSTR (value
, 0));
5427 printf (HOST_WIDE_INT_PRINT_DEC
, INTVAL (value
));
5431 fputs (XSTR (value
, 0), stdout
);
5436 struct attr_desc
*attr2
= find_attr (XSTR (value
, 0), 0);
5437 printf ("get_attr_%s (%s)", attr2
->name
,
5438 (attr2
->is_const
? "" : "insn"));
5459 write_attr_value (attr
, XEXP (value
, 0));
5463 write_attr_value (attr
, XEXP (value
, 1));
5477 /* The argument of TOUPPER should not have side effects. */
5478 putchar (TOUPPER(*str
));
5484 write_indent (indent
)
5487 for (; indent
> 8; indent
-= 8)
5490 for (; indent
; indent
--)
5494 /* Write a subroutine that is given an insn that requires a delay slot, a
5495 delay slot ordinal, and a candidate insn. It returns non-zero if the
5496 candidate can be placed in the specified delay slot of the insn.
5498 We can write as many as three subroutines. `eligible_for_delay'
5499 handles normal delay slots, `eligible_for_annul_true' indicates that
5500 the specified insn can be annulled if the branch is true, and likewise
5501 for `eligible_for_annul_false'.
5503 KIND is a string distinguishing these three cases ("delay", "annul_true",
5504 or "annul_false"). */
5507 write_eligible_delay (kind
)
5510 struct delay_desc
*delay
;
5513 struct attr_desc
*attr
;
5514 struct attr_value
*av
, *common_av
;
5517 /* Compute the maximum number of delay slots required. We use the delay
5518 ordinal times this number plus one, plus the slot number as an index into
5519 the appropriate predicate to test. */
5521 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
5522 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
5523 max_slots
= XVECLEN (delay
->def
, 1) / 3;
5525 /* Write function prelude. */
5528 printf ("eligible_for_%s (delay_insn, slot, candidate_insn, flags)\n",
5530 printf (" rtx delay_insn ATTRIBUTE_UNUSED;\n");
5531 printf (" int slot;\n");
5532 printf (" rtx candidate_insn;\n");
5533 printf (" int flags ATTRIBUTE_UNUSED;\n");
5535 printf (" rtx insn;\n");
5537 printf (" if (slot >= %d)\n", max_slots
);
5538 printf (" abort ();\n");
5541 /* If more than one delay type, find out which type the delay insn is. */
5545 attr
= find_attr ("*delay_type", 0);
5548 common_av
= find_most_used (attr
);
5550 printf (" insn = delay_insn;\n");
5551 printf (" switch (recog_memoized (insn))\n");
5554 sprintf (str
, " * %d;\n break;", max_slots
);
5555 for (av
= attr
->first_value
; av
; av
= av
->next
)
5556 if (av
!= common_av
)
5557 write_attr_case (attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
5559 write_attr_case (attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
5562 /* Ensure matched. Otherwise, shouldn't have been called. */
5563 printf (" if (slot < %d)\n", max_slots
);
5564 printf (" abort ();\n\n");
5567 /* If just one type of delay slot, write simple switch. */
5568 if (num_delays
== 1 && max_slots
== 1)
5570 printf (" insn = candidate_insn;\n");
5571 printf (" switch (recog_memoized (insn))\n");
5574 attr
= find_attr ("*delay_1_0", 0);
5577 common_av
= find_most_used (attr
);
5579 for (av
= attr
->first_value
; av
; av
= av
->next
)
5580 if (av
!= common_av
)
5581 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5583 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5589 /* Write a nested CASE. The first indicates which condition we need to
5590 test, and the inner CASE tests the condition. */
5591 printf (" insn = candidate_insn;\n");
5592 printf (" switch (slot)\n");
5595 for (delay
= delays
; delay
; delay
= delay
->next
)
5596 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
5598 printf (" case %d:\n",
5599 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
5600 printf (" switch (recog_memoized (insn))\n");
5603 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
5604 attr
= find_attr (str
, 0);
5607 common_av
= find_most_used (attr
);
5609 for (av
= attr
->first_value
; av
; av
= av
->next
)
5610 if (av
!= common_av
)
5611 write_attr_case (attr
, av
, 1, "return", ";", 8, true_rtx
);
5613 write_attr_case (attr
, common_av
, 0, "return", ";", 8, true_rtx
);
5617 printf (" default:\n");
5618 printf (" abort ();\n");
5625 /* Write routines to compute conflict cost for function units. Then write a
5626 table describing the available function units. */
5629 write_function_unit_info ()
5631 struct function_unit
*unit
;
5634 /* Write out conflict routines for function units. Don't bother writing
5635 one if there is only one issue delay value. */
5637 for (unit
= units
; unit
; unit
= unit
->next
)
5639 if (unit
->needs_blockage_function
)
5640 write_complex_function (unit
, "blockage", "block");
5642 /* If the minimum and maximum conflict costs are the same, there
5643 is only one value, so we don't need a function. */
5644 if (! unit
->needs_conflict_function
)
5646 unit
->default_cost
= make_numeric_value (unit
->issue_delay
.max
);
5650 /* The function first computes the case from the candidate insn. */
5651 unit
->default_cost
= make_numeric_value (0);
5652 write_complex_function (unit
, "conflict_cost", "cost");
5655 /* Now that all functions have been written, write the table describing
5656 the function units. The name is included for documentation purposes
5659 printf ("const struct function_unit_desc function_units[] = {\n");
5661 /* Write out the descriptions in numeric order, but don't force that order
5662 on the list. Doing so increases the runtime of genattrtab.c. */
5663 for (i
= 0; i
< num_units
; i
++)
5665 for (unit
= units
; unit
; unit
= unit
->next
)
5669 printf (" {\"%s\", %d, %d, %d, %s, %d, %s_unit_ready_cost, ",
5670 unit
->name
, 1 << unit
->num
, unit
->multiplicity
,
5671 unit
->simultaneity
, XSTR (unit
->default_cost
, 0),
5672 unit
->issue_delay
.max
, unit
->name
);
5674 if (unit
->needs_conflict_function
)
5675 printf ("%s_unit_conflict_cost, ", unit
->name
);
5679 printf ("%d, ", unit
->max_blockage
);
5681 if (unit
->needs_range_function
)
5682 printf ("%s_unit_blockage_range, ", unit
->name
);
5686 if (unit
->needs_blockage_function
)
5687 printf ("%s_unit_blockage", unit
->name
);
5695 printf ("{\"dummy\", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* a dummy element */");
5700 write_complex_function (unit
, name
, connection
)
5701 struct function_unit
*unit
;
5702 const char *name
, *connection
;
5704 struct attr_desc
*case_attr
, *attr
;
5705 struct attr_value
*av
, *common_av
;
5711 printf ("static int %s_unit_%s PARAMS ((rtx, rtx));\n", unit
->name
, name
);
5712 printf ("static int\n");
5713 printf ("%s_unit_%s (executing_insn, candidate_insn)\n", unit
->name
, name
);
5714 printf (" rtx executing_insn;\n");
5715 printf (" rtx candidate_insn;\n");
5717 printf (" rtx insn;\n");
5718 printf (" int casenum;\n\n");
5719 printf (" insn = executing_insn;\n");
5720 printf (" switch (recog_memoized (insn))\n");
5723 /* Write the `switch' statement to get the case value. */
5724 if (strlen (unit
->name
) + sizeof "*_cases" > 256)
5726 sprintf (str
, "*%s_cases", unit
->name
);
5727 case_attr
= find_attr (str
, 0);
5730 common_av
= find_most_used (case_attr
);
5732 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5733 if (av
!= common_av
)
5734 write_attr_case (case_attr
, av
, 1,
5735 "casenum =", ";", 4, unit
->condexp
);
5737 write_attr_case (case_attr
, common_av
, 0,
5738 "casenum =", ";", 4, unit
->condexp
);
5741 /* Now write an outer switch statement on each case. Then write
5742 the tests on the executing function within each. */
5743 printf (" insn = candidate_insn;\n");
5744 printf (" switch (casenum)\n");
5747 for (i
= 0; i
< unit
->num_opclasses
; i
++)
5749 /* Ensure using this case. */
5751 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5753 && contained_in_p (make_numeric_value (i
), av
->value
))
5759 printf (" case %d:\n", i
);
5760 sprintf (str
, "*%s_%s_%d", unit
->name
, connection
, i
);
5761 attr
= find_attr (str
, 0);
5765 /* If single value, just write it. */
5766 value
= find_single_value (attr
);
5768 write_attr_set (attr
, 6, value
, "return", ";\n", true_rtx
, -2, -2);
5771 common_av
= find_most_used (attr
);
5772 printf (" switch (recog_memoized (insn))\n");
5775 for (av
= attr
->first_value
; av
; av
= av
->next
)
5776 if (av
!= common_av
)
5777 write_attr_case (attr
, av
, 1,
5778 "return", ";", 8, unit
->condexp
);
5780 write_attr_case (attr
, common_av
, 0,
5781 "return", ";", 8, unit
->condexp
);
5786 /* This default case should not be needed, but gcc's analysis is not
5787 good enough to realize that the default case is not needed for the
5788 second switch statement. */
5789 printf (" default:\n abort ();\n");
5790 printf (" }\n}\n\n");
5793 /* This page contains miscellaneous utility routines. */
5795 /* Given a pointer to a (char *), return a malloc'ed string containing the
5796 next comma-separated element. Advance the pointer to after the string
5797 scanned, or the end-of-string. Return NULL if at end of string. */
5800 next_comma_elt (pstr
)
5805 start
= scan_comma_elt (pstr
);
5810 return attr_string (start
, *pstr
- start
);
5813 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
5814 is non-zero, build a new attribute, if one does not exist. */
5816 static struct attr_desc
*
5817 find_attr (name
, create
)
5821 struct attr_desc
*attr
;
5824 /* Before we resort to using `strcmp', see if the string address matches
5825 anywhere. In most cases, it should have been canonicalized to do so. */
5826 if (name
== alternative_name
)
5829 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
5830 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5831 if (name
== attr
->name
)
5834 /* Otherwise, do it the slow way. */
5835 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5836 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
5842 attr
= (struct attr_desc
*) oballoc (sizeof (struct attr_desc
));
5843 attr
->name
= attr_string (name
, strlen (name
));
5844 attr
->first_value
= attr
->default_val
= NULL
;
5845 attr
->is_numeric
= attr
->negative_ok
= attr
->is_const
= attr
->is_special
= 0;
5846 attr
->unsigned_p
= attr
->func_units_p
= attr
->blockage_p
= 0;
5847 attr
->next
= attrs
[index
];
5848 attrs
[index
] = attr
;
5853 /* Create internal attribute with the given default value. */
5856 make_internal_attr (name
, value
, special
)
5861 struct attr_desc
*attr
;
5863 attr
= find_attr (name
, 1);
5864 if (attr
->default_val
)
5867 attr
->is_numeric
= 1;
5869 attr
->is_special
= (special
& 1) != 0;
5870 attr
->negative_ok
= (special
& 2) != 0;
5871 attr
->unsigned_p
= (special
& 4) != 0;
5872 attr
->func_units_p
= (special
& 8) != 0;
5873 attr
->blockage_p
= (special
& 16) != 0;
5874 attr
->default_val
= get_attr_value (value
, attr
, -2);
5877 /* Find the most used value of an attribute. */
5879 static struct attr_value
*
5880 find_most_used (attr
)
5881 struct attr_desc
*attr
;
5883 struct attr_value
*av
;
5884 struct attr_value
*most_used
;
5890 for (av
= attr
->first_value
; av
; av
= av
->next
)
5891 if (av
->num_insns
> nuses
)
5892 nuses
= av
->num_insns
, most_used
= av
;
5897 /* If an attribute only has a single value used, return it. Otherwise
5901 find_single_value (attr
)
5902 struct attr_desc
*attr
;
5904 struct attr_value
*av
;
5907 unique_value
= NULL
;
5908 for (av
= attr
->first_value
; av
; av
= av
->next
)
5914 unique_value
= av
->value
;
5917 return unique_value
;
5920 /* Return (attr_value "n") */
5923 make_numeric_value (n
)
5926 static rtx int_values
[20];
5933 if (n
< 20 && int_values
[n
])
5934 return int_values
[n
];
5936 p
= attr_printf (MAX_DIGITS
, "%d", n
);
5937 exp
= attr_rtx (CONST_STRING
, p
);
5940 int_values
[n
] = exp
;
5946 extend_range (range
, min
, max
)
5947 struct range
*range
;
5951 if (range
->min
> min
)
5953 if (range
->max
< max
)
5958 copy_rtx_unchanging (orig
)
5966 if (ATTR_IND_SIMPLIFIED_P (orig
) || ATTR_CURR_SIMPLIFIED_P (orig
))
5969 ATTR_CURR_SIMPLIFIED_P (orig
) = 1;
5973 code
= GET_CODE (orig
);
5986 copy
= rtx_alloc (code
);
5987 PUT_MODE (copy
, GET_MODE (orig
));
5988 ATTR_IND_SIMPLIFIED_P (copy
) = 1;
5990 memcpy (&XEXP (copy
, 0), &XEXP (orig
, 0),
5991 GET_RTX_LENGTH (GET_CODE (copy
)) * sizeof (rtx
));
5996 /* Determine if an insn has a constant number of delay slots, i.e., the
5997 number of delay slots is not a function of the length of the insn. */
6000 write_const_num_delay_slots ()
6002 struct attr_desc
*attr
= find_attr ("*num_delay_slots", 0);
6003 struct attr_value
*av
;
6004 struct insn_ent
*ie
;
6008 printf ("int\nconst_num_delay_slots (insn)\n");
6009 printf (" rtx insn;\n");
6011 printf (" switch (recog_memoized (insn))\n");
6014 for (av
= attr
->first_value
; av
; av
= av
->next
)
6017 walk_attr_value (av
->value
);
6020 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
6021 if (ie
->insn_code
!= -1)
6022 printf (" case %d:\n", ie
->insn_code
);
6023 printf (" return 0;\n");
6027 printf (" default:\n");
6028 printf (" return 1;\n");
6029 printf (" }\n}\n\n");
6033 extern int main
PARAMS ((int, char **));
6041 struct attr_desc
*attr
;
6042 struct insn_def
*id
;
6046 progname
= "genattrtab";
6049 fatal ("no input file name");
6051 if (init_md_reader_args (argc
, argv
) != SUCCESS_EXIT_CODE
)
6052 return (FATAL_EXIT_CODE
);
6054 obstack_init (hash_obstack
);
6055 obstack_init (temp_obstack
);
6057 /* Set up true and false rtx's */
6058 true_rtx
= rtx_alloc (CONST_INT
);
6059 XWINT (true_rtx
, 0) = 1;
6060 false_rtx
= rtx_alloc (CONST_INT
);
6061 XWINT (false_rtx
, 0) = 0;
6062 ATTR_IND_SIMPLIFIED_P (true_rtx
) = ATTR_IND_SIMPLIFIED_P (false_rtx
) = 1;
6063 ATTR_PERMANENT_P (true_rtx
) = ATTR_PERMANENT_P (false_rtx
) = 1;
6065 alternative_name
= attr_string ("alternative", strlen ("alternative"));
6067 printf ("/* Generated automatically by the program `genattrtab'\n\
6068 from the machine description file `md'. */\n\n");
6070 /* Read the machine description. */
6072 initiate_automaton_gen (argc
, argv
);
6077 desc
= read_md_rtx (&lineno
, &insn_code_number
);
6081 switch (GET_CODE (desc
))
6084 case DEFINE_PEEPHOLE
:
6085 case DEFINE_ASM_ATTRIBUTES
:
6086 gen_insn (desc
, lineno
);
6090 gen_attr (desc
, lineno
);
6094 gen_delay (desc
, lineno
);
6097 case DEFINE_FUNCTION_UNIT
:
6098 gen_unit (desc
, lineno
);
6101 case DEFINE_CPU_UNIT
:
6102 gen_cpu_unit (desc
);
6105 case DEFINE_QUERY_CPU_UNIT
:
6106 gen_query_cpu_unit (desc
);
6114 gen_excl_set (desc
);
6118 gen_presence_set (desc
);
6122 gen_absence_set (desc
);
6125 case DEFINE_AUTOMATON
:
6126 gen_automaton (desc
);
6129 case AUTOMATA_OPTION
:
6130 gen_automata_option (desc
);
6133 case DEFINE_RESERVATION
:
6137 case DEFINE_INSN_RESERVATION
:
6138 gen_insn_reserv (desc
);
6144 if (GET_CODE (desc
) != DEFINE_ASM_ATTRIBUTES
)
6145 insn_index_number
++;
6149 return FATAL_EXIT_CODE
;
6153 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
6154 if (! got_define_asm_attributes
)
6156 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
6157 XVEC (tem
, 0) = rtvec_alloc (0);
6161 /* Expand DEFINE_DELAY information into new attribute. */
6165 if (num_units
|| num_dfa_decls
)
6167 /* Expand DEFINE_FUNCTION_UNIT information into new attributes. */
6169 /* Build DFA, output some functions and expand DFA information
6170 into new attributes. */
6174 printf ("#include \"config.h\"\n");
6175 printf ("#include \"system.h\"\n");
6176 printf ("#include \"rtl.h\"\n");
6177 printf ("#include \"tm_p.h\"\n");
6178 printf ("#include \"insn-config.h\"\n");
6179 printf ("#include \"recog.h\"\n");
6180 printf ("#include \"regs.h\"\n");
6181 printf ("#include \"real.h\"\n");
6182 printf ("#include \"output.h\"\n");
6183 printf ("#include \"insn-attr.h\"\n");
6184 printf ("#include \"toplev.h\"\n");
6185 printf ("#include \"flags.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
;