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, 2003 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))
104 #define strcmp_check(S1, S2) ((S1) == (S2) \
106 : (strcmp ((S1), (S2)) \
110 #define strcmp_check(S1, S2) ((S1) != (S2))
115 #include "coretypes.h"
119 #include "gensupport.h"
121 #ifdef HAVE_SYS_RESOURCE_H
122 # include <sys/resource.h>
125 /* We must include obstack.h after <sys/time.h>, to avoid lossage with
126 /usr/include/sys/stdtypes.h on Sun OS 4.x. */
130 #include "genattrtab.h"
132 static struct obstack obstack1
, obstack2
;
133 struct obstack
*hash_obstack
= &obstack1
;
134 struct obstack
*temp_obstack
= &obstack2
;
136 /* enough space to reserve for printing out ints */
137 #define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
139 /* Define structures used to record attributes and values. */
141 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
142 encountered, we store all the relevant information into a
143 `struct insn_def'. This is done to allow attribute definitions to occur
144 anywhere in the file. */
148 struct insn_def
*next
; /* Next insn in chain. */
149 rtx def
; /* The DEFINE_... */
150 int insn_code
; /* Instruction number. */
151 int insn_index
; /* Expression numer in file, for errors. */
152 int lineno
; /* Line number. */
153 int num_alternatives
; /* Number of alternatives. */
154 int vec_idx
; /* Index of attribute vector in `def'. */
157 /* Once everything has been read in, we store in each attribute value a list
158 of insn codes that have that value. Here is the structure used for the
163 struct insn_ent
*next
; /* Next in chain. */
164 int insn_code
; /* Instruction number. */
165 int insn_index
; /* Index of definition in file */
166 int lineno
; /* Line number. */
169 /* Each value of an attribute (either constant or computed) is assigned a
170 structure which is used as the listhead of the insns that have that
175 rtx value
; /* Value of attribute. */
176 struct attr_value
*next
; /* Next attribute value in chain. */
177 struct insn_ent
*first_insn
; /* First insn with this value. */
178 int num_insns
; /* Number of insns with this value. */
179 int has_asm_insn
; /* True if this value used for `asm' insns */
182 /* Structure for each attribute. */
186 char *name
; /* Name of attribute. */
187 struct attr_desc
*next
; /* Next attribute. */
188 struct attr_value
*first_value
; /* First value of this attribute. */
189 struct attr_value
*default_val
; /* Default value for this attribute. */
190 int lineno
: 24; /* Line number. */
191 unsigned is_numeric
: 1; /* Values of this attribute are numeric. */
192 unsigned negative_ok
: 1; /* Allow negative numeric values. */
193 unsigned unsigned_p
: 1; /* Make the output function unsigned int. */
194 unsigned is_const
: 1; /* Attribute value constant for each run. */
195 unsigned is_special
: 1; /* Don't call `write_attr_set'. */
196 unsigned func_units_p
: 1; /* This is the function_units attribute. */
197 unsigned blockage_p
: 1; /* This is the blockage range function. */
198 unsigned static_p
: 1; /* Make the output function static. */
201 #define NULL_ATTR (struct attr_desc *) NULL
203 /* A range of values. */
211 /* Structure for each DEFINE_DELAY. */
215 rtx def
; /* DEFINE_DELAY expression. */
216 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
217 int num
; /* Number of DEFINE_DELAY, starting at 1. */
218 int lineno
; /* Line number. */
221 /* Record information about each DEFINE_FUNCTION_UNIT. */
223 struct function_unit_op
225 rtx condexp
; /* Expression TRUE for applicable insn. */
226 struct function_unit_op
*next
; /* Next operation for this function unit. */
227 int num
; /* Ordinal for this operation type in unit. */
228 int ready
; /* Cost until data is ready. */
229 int issue_delay
; /* Cost until unit can accept another insn. */
230 rtx conflict_exp
; /* Expression TRUE for insns incurring issue delay. */
231 rtx issue_exp
; /* Expression computing issue delay. */
232 int lineno
; /* Line number. */
235 /* Record information about each function unit mentioned in a
236 DEFINE_FUNCTION_UNIT. */
240 const char *name
; /* Function unit name. */
241 struct function_unit
*next
; /* Next function unit. */
242 int num
; /* Ordinal of this unit type. */
243 int multiplicity
; /* Number of units of this type. */
244 int simultaneity
; /* Maximum number of simultaneous insns
245 on this function unit or 0 if unlimited. */
246 rtx condexp
; /* Expression TRUE for insn needing unit. */
247 int num_opclasses
; /* Number of different operation types. */
248 struct function_unit_op
*ops
; /* Pointer to first operation type. */
249 int needs_conflict_function
; /* Nonzero if a conflict function required. */
250 int needs_blockage_function
; /* Nonzero if a blockage function required. */
251 int needs_range_function
; /* Nonzero if blockage range function needed. */
252 rtx default_cost
; /* Conflict cost, if constant. */
253 struct range issue_delay
; /* Range of issue delay values. */
254 int max_blockage
; /* Maximum time an insn blocks the unit. */
255 int first_lineno
; /* First seen line number. */
258 /* Listheads of above structures. */
260 /* This one is indexed by the first character of the attribute name. */
261 #define MAX_ATTRS_INDEX 256
262 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
263 static struct insn_def
*defs
;
264 static struct delay_desc
*delays
;
265 static struct function_unit
*units
;
267 /* An expression where all the unknown terms are EQ_ATTR tests can be
268 rearranged into a COND provided we can enumerate all possible
269 combinations of the unknown values. The set of combinations become the
270 tests of the COND; the value of the expression given that combination is
271 computed and becomes the corresponding value. To do this, we must be
272 able to enumerate all values for each attribute used in the expression
273 (currently, we give up if we find a numeric attribute).
275 If the set of EQ_ATTR tests used in an expression tests the value of N
276 different attributes, the list of all possible combinations can be made
277 by walking the N-dimensional attribute space defined by those
278 attributes. We record each of these as a struct dimension.
280 The algorithm relies on sharing EQ_ATTR nodes: if two nodes in an
281 expression are the same, the will also have the same address. We find
282 all the EQ_ATTR nodes by marking them ATTR_EQ_ATTR_P. This bit later
283 represents the value of an EQ_ATTR node, so once all nodes are marked,
284 they are also given an initial value of FALSE.
286 We then separate the set of EQ_ATTR nodes into dimensions for each
287 attribute and put them on the VALUES list. Terms are added as needed by
288 `add_values_to_cover' so that all possible values of the attribute are
291 Each dimension also has a current value. This is the node that is
292 currently considered to be TRUE. If this is one of the nodes added by
293 `add_values_to_cover', all the EQ_ATTR tests in the original expression
294 will be FALSE. Otherwise, only the CURRENT_VALUE will be true.
296 NUM_VALUES is simply the length of the VALUES list and is there for
299 Once the dimensions are created, the algorithm enumerates all possible
300 values and computes the current value of the given expression. */
304 struct attr_desc
*attr
; /* Attribute for this dimension. */
305 rtx values
; /* List of attribute values used. */
306 rtx current_value
; /* Position in the list for the TRUE value. */
307 int num_values
; /* Length of the values list. */
310 /* Other variables. */
312 static int insn_code_number
;
313 static int insn_index_number
;
314 static int got_define_asm_attributes
;
315 static int must_extract
;
316 static int must_constrain
;
317 static int address_used
;
318 static int length_used
;
319 static int num_delays
;
320 static int have_annul_true
, have_annul_false
;
321 static int num_units
, num_unit_opclasses
;
322 static int num_insn_ents
;
326 /* Used as operand to `operate_exp': */
328 enum operator {PLUS_OP
, MINUS_OP
, POS_MINUS_OP
, EQ_OP
, OR_OP
, ORX_OP
, MAX_OP
, MIN_OP
, RANGE_OP
};
330 /* Stores, for each insn code, the number of constraint alternatives. */
332 static int *insn_n_alternatives
;
334 /* Stores, for each insn code, a bitmap that has bits on for each possible
337 static int *insn_alternatives
;
339 /* If nonzero, assume that the `alternative' attr has this value.
340 This is the hashed, unique string for the numeral
341 whose value is chosen alternative. */
343 static const char *current_alternative_string
;
345 /* Used to simplify expressions. */
347 static rtx true_rtx
, false_rtx
;
349 /* Used to reduce calls to `strcmp' */
351 static char *alternative_name
;
352 static const char *length_str
;
353 static const char *delay_type_str
;
354 static const char *delay_1_0_str
;
355 static const char *num_delay_slots_str
;
357 /* Indicate that REG_DEAD notes are valid if dead_or_set_p is ever
360 int reload_completed
= 0;
362 /* Some machines test `optimize' in macros called from rtlanal.c, so we need
363 to define it here. */
367 /* Simplify an expression. Only call the routine if there is something to
369 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
370 (ATTR_IND_SIMPLIFIED_P (EXP) || ATTR_CURR_SIMPLIFIED_P (EXP) ? (EXP) \
371 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
373 /* Simplify (eq_attr ("alternative") ...)
374 when we are working with a particular alternative. */
375 #define SIMPLIFY_ALTERNATIVE(EXP) \
376 if (current_alternative_string \
377 && GET_CODE ((EXP)) == EQ_ATTR \
378 && XSTR ((EXP), 0) == alternative_name) \
379 (EXP) = (XSTR ((EXP), 1) == current_alternative_string \
380 ? true_rtx : false_rtx);
382 #define DEF_ATTR_STRING(S) (attr_string ((S), strlen (S)))
384 /* These are referenced by rtlanal.c and hence need to be defined somewhere.
385 They won't actually be used. */
387 rtx global_rtl
[GR_MAX
];
388 rtx pic_offset_table_rtx
;
390 static void attr_hash_add_rtx (int, rtx
);
391 static void attr_hash_add_string (int, char *);
392 static rtx
attr_rtx (enum rtx_code
, ...);
393 static rtx
attr_rtx_1 (enum rtx_code
, va_list);
394 static char *attr_string (const char *, int);
395 static rtx
check_attr_value (rtx
, struct attr_desc
*);
396 static rtx
convert_set_attr_alternative (rtx
, struct insn_def
*);
397 static rtx
convert_set_attr (rtx
, struct insn_def
*);
398 static void check_defs (void);
399 static rtx
make_canonical (struct attr_desc
*, rtx
);
400 static struct attr_value
*get_attr_value (rtx
, struct attr_desc
*, int);
401 static rtx
copy_rtx_unchanging (rtx
);
402 static rtx
copy_boolean (rtx
);
403 static void expand_delays (void);
404 static rtx
operate_exp (enum operator, rtx
, rtx
);
405 static void expand_units (void);
406 static rtx
simplify_knowing (rtx
, rtx
);
407 static rtx
encode_units_mask (rtx
);
408 static void fill_attr (struct attr_desc
*);
409 static rtx
substitute_address (rtx
, rtx (*) (rtx
), rtx (*) (rtx
));
410 static void make_length_attrs (void);
411 static rtx
identity_fn (rtx
);
412 static rtx
zero_fn (rtx
);
413 static rtx
one_fn (rtx
);
414 static rtx
max_fn (rtx
);
415 static void write_length_unit_log (void);
416 static rtx
simplify_cond (rtx
, int, int);
417 static rtx
simplify_by_exploding (rtx
);
418 static int find_and_mark_used_attributes (rtx
, rtx
*, int *);
419 static void unmark_used_attributes (rtx
, struct dimension
*, int);
420 static int add_values_to_cover (struct dimension
*);
421 static int increment_current_value (struct dimension
*, int);
422 static rtx
test_for_current_value (struct dimension
*, int);
423 static rtx
simplify_with_current_value (rtx
, struct dimension
*, int);
424 static rtx
simplify_with_current_value_aux (rtx
);
425 static void clear_struct_flag (rtx
);
426 static void remove_insn_ent (struct attr_value
*, struct insn_ent
*);
427 static void insert_insn_ent (struct attr_value
*, struct insn_ent
*);
428 static rtx
insert_right_side (enum rtx_code
, rtx
, rtx
, int, int);
429 static rtx
make_alternative_compare (int);
430 static int compute_alternative_mask (rtx
, enum rtx_code
);
431 static rtx
evaluate_eq_attr (rtx
, rtx
, int, int);
432 static rtx
simplify_and_tree (rtx
, rtx
*, int, int);
433 static rtx
simplify_or_tree (rtx
, rtx
*, int, int);
434 static rtx
simplify_test_exp (rtx
, int, int);
435 static rtx
simplify_test_exp_in_temp (rtx
, int, int);
436 static void optimize_attrs (void);
437 static void gen_attr (rtx
, int);
438 static int count_alternatives (rtx
);
439 static int compares_alternatives_p (rtx
);
440 static int contained_in_p (rtx
, rtx
);
441 static void gen_insn (rtx
, int);
442 static void gen_delay (rtx
, int);
443 static void gen_unit (rtx
, int);
444 static void write_test_expr (rtx
, int);
445 static int max_attr_value (rtx
, int*);
446 static int or_attr_value (rtx
, int*);
447 static void walk_attr_value (rtx
);
448 static void write_attr_get (struct attr_desc
*);
449 static rtx
eliminate_known_true (rtx
, rtx
, int, int);
450 static void write_attr_set (struct attr_desc
*, int, rtx
,
451 const char *, const char *, rtx
,
453 static void write_attr_case (struct attr_desc
*, struct attr_value
*,
454 int, const char *, const char *, int, rtx
);
455 static void write_unit_name (const char *, int, const char *);
456 static void write_attr_valueq (struct attr_desc
*, const char *);
457 static void write_attr_value (struct attr_desc
*, rtx
);
458 static void write_upcase (const char *);
459 static void write_indent (int);
460 static void write_eligible_delay (const char *);
461 static void write_function_unit_info (void);
462 static void write_complex_function (struct function_unit
*, const char *,
464 static int write_expr_attr_cache (rtx
, struct attr_desc
*);
465 static void write_toplevel_expr (rtx
);
466 static void write_const_num_delay_slots (void);
467 static char *next_comma_elt (const char **);
468 static struct attr_desc
*find_attr (const char **, int);
469 static struct attr_value
*find_most_used (struct attr_desc
*);
470 static rtx
find_single_value (struct attr_desc
*);
471 static void extend_range (struct range
*, int, int);
472 static rtx
attr_eq (const char *, const char *);
473 static const char *attr_numeral (int);
474 static int attr_equal_p (rtx
, rtx
);
475 static rtx
attr_copy_rtx (rtx
);
476 static int attr_rtx_cost (rtx
);
477 static bool attr_alt_subset_p (rtx
, rtx
);
478 static bool attr_alt_subset_of_compl_p (rtx
, rtx
);
479 static rtx
attr_alt_intersection (rtx
, rtx
);
480 static rtx
attr_alt_union (rtx
, rtx
);
481 static rtx
attr_alt_complement (rtx
);
482 static bool attr_alt_bit_p (rtx
, int);
483 static rtx
mk_attr_alt (int);
485 #define oballoc(size) obstack_alloc (hash_obstack, size)
487 /* Hash table for sharing RTL and strings. */
489 /* Each hash table slot is a bucket containing a chain of these structures.
490 Strings are given negative hash codes; RTL expressions are given positive
495 struct attr_hash
*next
; /* Next structure in the bucket. */
496 int hashcode
; /* Hash code of this rtx or string. */
499 char *str
; /* The string (negative hash codes) */
500 rtx rtl
; /* or the RTL recorded here. */
504 /* Now here is the hash table. When recording an RTL, it is added to
505 the slot whose index is the hash code mod the table size. Note
506 that the hash table is used for several kinds of RTL (see attr_rtx)
507 and for strings. While all these live in the same table, they are
508 completely independent, and the hash code is computed differently
511 #define RTL_HASH_SIZE 4093
512 struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
514 /* Here is how primitive or already-shared RTL's hash
516 #define RTL_HASH(RTL) ((long) (RTL) & 0777777)
518 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
521 attr_hash_add_rtx (int hashcode
, rtx rtl
)
525 h
= obstack_alloc (hash_obstack
, sizeof (struct attr_hash
));
526 h
->hashcode
= hashcode
;
528 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
529 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
532 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
535 attr_hash_add_string (int hashcode
, char *str
)
539 h
= obstack_alloc (hash_obstack
, sizeof (struct attr_hash
));
540 h
->hashcode
= -hashcode
;
542 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
543 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
546 /* Generate an RTL expression, but avoid duplicates.
547 Set the ATTR_PERMANENT_P flag for these permanent objects.
549 In some cases we cannot uniquify; then we return an ordinary
550 impermanent rtx with ATTR_PERMANENT_P clear.
552 Args are like gen_rtx, but without the mode:
554 rtx attr_rtx (code, [element1, ..., elementn]) */
557 attr_rtx_1 (enum rtx_code code
, va_list p
)
559 rtx rt_val
= NULL_RTX
;/* RTX to return to caller... */
562 struct obstack
*old_obstack
= rtl_obstack
;
564 /* For each of several cases, search the hash table for an existing entry.
565 Use that entry if one is found; otherwise create a new RTL and add it
568 if (GET_RTX_CLASS (code
) == '1')
570 rtx arg0
= va_arg (p
, rtx
);
572 /* A permanent object cannot point to impermanent ones. */
573 if (! ATTR_PERMANENT_P (arg0
))
575 rt_val
= rtx_alloc (code
);
576 XEXP (rt_val
, 0) = arg0
;
580 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
581 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
582 if (h
->hashcode
== hashcode
583 && GET_CODE (h
->u
.rtl
) == code
584 && XEXP (h
->u
.rtl
, 0) == arg0
)
589 rtl_obstack
= hash_obstack
;
590 rt_val
= rtx_alloc (code
);
591 XEXP (rt_val
, 0) = arg0
;
594 else if (GET_RTX_CLASS (code
) == 'c'
595 || GET_RTX_CLASS (code
) == '2'
596 || GET_RTX_CLASS (code
) == '<')
598 rtx arg0
= va_arg (p
, rtx
);
599 rtx arg1
= va_arg (p
, rtx
);
601 /* A permanent object cannot point to impermanent ones. */
602 if (! ATTR_PERMANENT_P (arg0
) || ! ATTR_PERMANENT_P (arg1
))
604 rt_val
= rtx_alloc (code
);
605 XEXP (rt_val
, 0) = arg0
;
606 XEXP (rt_val
, 1) = arg1
;
610 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
611 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
612 if (h
->hashcode
== hashcode
613 && GET_CODE (h
->u
.rtl
) == code
614 && XEXP (h
->u
.rtl
, 0) == arg0
615 && XEXP (h
->u
.rtl
, 1) == arg1
)
620 rtl_obstack
= hash_obstack
;
621 rt_val
= rtx_alloc (code
);
622 XEXP (rt_val
, 0) = arg0
;
623 XEXP (rt_val
, 1) = arg1
;
626 else if (GET_RTX_LENGTH (code
) == 1
627 && GET_RTX_FORMAT (code
)[0] == 's')
629 char *arg0
= va_arg (p
, char *);
631 arg0
= DEF_ATTR_STRING (arg0
);
633 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
634 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
635 if (h
->hashcode
== hashcode
636 && GET_CODE (h
->u
.rtl
) == code
637 && XSTR (h
->u
.rtl
, 0) == arg0
)
642 rtl_obstack
= hash_obstack
;
643 rt_val
= rtx_alloc (code
);
644 XSTR (rt_val
, 0) = arg0
;
647 else if (GET_RTX_LENGTH (code
) == 2
648 && GET_RTX_FORMAT (code
)[0] == 's'
649 && GET_RTX_FORMAT (code
)[1] == 's')
651 char *arg0
= va_arg (p
, char *);
652 char *arg1
= va_arg (p
, char *);
654 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
655 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
656 if (h
->hashcode
== hashcode
657 && GET_CODE (h
->u
.rtl
) == code
658 && XSTR (h
->u
.rtl
, 0) == arg0
659 && XSTR (h
->u
.rtl
, 1) == arg1
)
664 rtl_obstack
= hash_obstack
;
665 rt_val
= rtx_alloc (code
);
666 XSTR (rt_val
, 0) = arg0
;
667 XSTR (rt_val
, 1) = arg1
;
670 else if (code
== CONST_INT
)
672 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
682 int i
; /* Array indices... */
683 const char *fmt
; /* Current rtx's format... */
685 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
687 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
688 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
692 case '0': /* Unused field. */
695 case 'i': /* An integer? */
696 XINT (rt_val
, i
) = va_arg (p
, int);
699 case 'w': /* A wide integer? */
700 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
703 case 's': /* A string? */
704 XSTR (rt_val
, i
) = va_arg (p
, char *);
707 case 'e': /* An expression? */
708 case 'u': /* An insn? Same except when printing. */
709 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
712 case 'E': /* An RTX vector? */
713 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
723 rtl_obstack
= old_obstack
;
724 attr_hash_add_rtx (hashcode
, rt_val
);
725 ATTR_PERMANENT_P (rt_val
) = 1;
730 attr_rtx (enum rtx_code code
, ...)
736 result
= attr_rtx_1 (code
, p
);
741 /* Create a new string printed with the printf line arguments into a space
742 of at most LEN bytes:
744 rtx attr_printf (len, format, [arg1, ..., argn]) */
747 attr_printf (unsigned int len
, const char *fmt
, ...)
754 if (len
> sizeof str
- 1) /* Leave room for \0. */
757 vsprintf (str
, fmt
, p
);
760 return DEF_ATTR_STRING (str
);
764 attr_eq (const char *name
, const char *value
)
766 return attr_rtx (EQ_ATTR
, DEF_ATTR_STRING (name
), DEF_ATTR_STRING (value
));
772 return XSTR (make_numeric_value (n
), 0);
775 /* Return a permanent (possibly shared) copy of a string STR (not assumed
776 to be null terminated) with LEN bytes. */
779 attr_string (const char *str
, int 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
= 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. */
813 attr_equal_p (rtx x
, rtx y
)
815 return (x
== y
|| (! (ATTR_PERMANENT_P (x
) && ATTR_PERMANENT_P (y
))
816 && rtx_equal_p (x
, y
)));
819 /* Copy an attribute value expression,
820 descending to all depths, but not copying any
821 permanent hashed subexpressions. */
824 attr_copy_rtx (rtx orig
)
829 const char *format_ptr
;
831 /* No need to copy a permanent object. */
832 if (ATTR_PERMANENT_P (orig
))
835 code
= GET_CODE (orig
);
854 copy
= rtx_alloc (code
);
855 PUT_MODE (copy
, GET_MODE (orig
));
856 ATTR_IND_SIMPLIFIED_P (copy
) = ATTR_IND_SIMPLIFIED_P (orig
);
857 ATTR_CURR_SIMPLIFIED_P (copy
) = ATTR_CURR_SIMPLIFIED_P (orig
);
858 ATTR_PERMANENT_P (copy
) = ATTR_PERMANENT_P (orig
);
859 ATTR_EQ_ATTR_P (copy
) = ATTR_EQ_ATTR_P (orig
);
861 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
863 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
865 switch (*format_ptr
++)
868 XEXP (copy
, i
) = XEXP (orig
, i
);
869 if (XEXP (orig
, i
) != NULL
)
870 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
875 XVEC (copy
, i
) = XVEC (orig
, i
);
876 if (XVEC (orig
, i
) != NULL
)
878 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
879 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
880 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
886 XINT (copy
, i
) = XINT (orig
, i
);
890 XWINT (copy
, i
) = XWINT (orig
, i
);
895 XSTR (copy
, i
) = XSTR (orig
, i
);
905 /* Given a test expression for an attribute, ensure it is validly formed.
906 IS_CONST indicates whether the expression is constant for each compiler
907 run (a constant expression may not test any particular insn).
909 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
910 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
911 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
913 Update the string address in EQ_ATTR expression to be the same used
914 in the attribute (or `alternative_name') to speed up subsequent
915 `find_attr' calls and eliminate most `strcmp' calls.
917 Return the new expression, if any. */
920 check_attr_test (rtx exp
, int is_const
, int lineno
)
922 struct attr_desc
*attr
;
923 struct attr_value
*av
;
924 const char *name_ptr
, *p
;
927 switch (GET_CODE (exp
))
930 /* Handle negation test. */
931 if (XSTR (exp
, 1)[0] == '!')
932 return check_attr_test (attr_rtx (NOT
,
933 attr_eq (XSTR (exp
, 0),
937 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
939 attr
= find_attr (&XSTR (exp
, 0), 0);
942 if (! strcmp (XSTR (exp
, 0), "alternative"))
943 return mk_attr_alt (1 << atoi (XSTR (exp
, 1)));
945 fatal ("unknown attribute `%s' in EQ_ATTR", XSTR (exp
, 0));
948 if (is_const
&& ! attr
->is_const
)
949 fatal ("constant expression uses insn attribute `%s' in EQ_ATTR",
952 /* Copy this just to make it permanent,
953 so expressions using it can be permanent too. */
954 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
956 /* It shouldn't be possible to simplify the value given to a
957 constant attribute, so don't expand this until it's time to
958 write the test expression. */
960 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
962 if (attr
->is_numeric
)
964 for (p
= XSTR (exp
, 1); *p
; p
++)
966 fatal ("attribute `%s' takes only numeric values",
971 for (av
= attr
->first_value
; av
; av
= av
->next
)
972 if (GET_CODE (av
->value
) == CONST_STRING
973 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
977 fatal ("unknown value `%s' for `%s' attribute",
978 XSTR (exp
, 1), XSTR (exp
, 0));
983 if (! strcmp (XSTR (exp
, 0), "alternative"))
987 name_ptr
= XSTR (exp
, 1);
988 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
989 set
|= 1 << atoi (p
);
991 return mk_attr_alt (set
);
995 /* Make an IOR tree of the possible values. */
997 name_ptr
= XSTR (exp
, 1);
998 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1000 newexp
= attr_eq (XSTR (exp
, 0), p
);
1001 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
1004 return check_attr_test (orexp
, is_const
, lineno
);
1013 /* Either TRUE or FALSE. */
1021 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
1022 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
, lineno
);
1026 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
1032 fatal ("RTL operator \"%s\" not valid in constant attribute test",
1033 GET_RTX_NAME (GET_CODE (exp
)));
1034 /* These cases can't be simplified. */
1035 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1038 case LE
: case LT
: case GT
: case GE
:
1039 case LEU
: case LTU
: case GTU
: case GEU
:
1041 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
1042 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
1043 exp
= attr_rtx (GET_CODE (exp
),
1044 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
1045 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
1046 /* These cases can't be simplified. */
1047 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1053 /* These cases are valid for constant attributes, but can't be
1055 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1056 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1060 fatal ("RTL operator \"%s\" not valid in attribute test",
1061 GET_RTX_NAME (GET_CODE (exp
)));
1067 /* Given an expression, ensure that it is validly formed and that all named
1068 attribute values are valid for the given attribute. Issue a fatal error
1069 if not. If no attribute is specified, assume a numeric attribute.
1071 Return a perhaps modified replacement expression for the value. */
1074 check_attr_value (rtx exp
, struct attr_desc
*attr
)
1076 struct attr_value
*av
;
1080 switch (GET_CODE (exp
))
1083 if (attr
&& ! attr
->is_numeric
)
1085 message_with_line (attr
->lineno
,
1086 "CONST_INT not valid for non-numeric attribute %s",
1092 if (INTVAL (exp
) < 0 && ! attr
->negative_ok
)
1094 message_with_line (attr
->lineno
,
1095 "negative numeric value specified for attribute %s",
1103 if (! strcmp (XSTR (exp
, 0), "*"))
1106 if (attr
== 0 || attr
->is_numeric
)
1109 if (attr
&& attr
->negative_ok
&& *p
== '-')
1114 message_with_line (attr
? attr
->lineno
: 0,
1115 "non-numeric value for numeric attribute %s",
1116 attr
? attr
->name
: "internal");
1123 for (av
= attr
->first_value
; av
; av
= av
->next
)
1124 if (GET_CODE (av
->value
) == CONST_STRING
1125 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
1130 message_with_line (attr
->lineno
,
1131 "unknown value `%s' for `%s' attribute",
1132 XSTR (exp
, 0), attr
? attr
->name
: "internal");
1138 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
1139 attr
? attr
->is_const
: 0,
1140 attr
? attr
->lineno
: 0);
1141 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1142 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
1150 if (attr
&& !attr
->is_numeric
)
1152 message_with_line (attr
->lineno
,
1153 "invalid operation `%s' for non-numeric attribute value",
1154 GET_RTX_NAME (GET_CODE (exp
)));
1162 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1163 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1171 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1175 if (XVECLEN (exp
, 0) % 2 != 0)
1177 message_with_line (attr
->lineno
,
1178 "first operand of COND must have even length");
1183 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1185 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1186 attr
? attr
->is_const
: 0,
1187 attr
? attr
->lineno
: 0);
1188 XVECEXP (exp
, 0, i
+ 1)
1189 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1192 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1197 struct attr_desc
*attr2
= find_attr (&XSTR (exp
, 0), 0);
1200 message_with_line (attr
? attr
->lineno
: 0,
1201 "unknown attribute `%s' in ATTR",
1205 else if (attr
&& attr
->is_const
&& ! attr2
->is_const
)
1207 message_with_line (attr
->lineno
,
1208 "non-constant attribute `%s' referenced from `%s'",
1209 XSTR (exp
, 0), attr
->name
);
1213 && (attr
->is_numeric
!= attr2
->is_numeric
1214 || (! attr
->negative_ok
&& attr2
->negative_ok
)))
1216 message_with_line (attr
->lineno
,
1217 "numeric attribute mismatch calling `%s' from `%s'",
1218 XSTR (exp
, 0), attr
->name
);
1225 /* A constant SYMBOL_REF is valid as a constant attribute test and
1226 is expanded later by make_canonical into a COND. In a non-constant
1227 attribute test, it is left be. */
1228 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1231 message_with_line (attr
? attr
->lineno
: 0,
1232 "invalid operation `%s' for attribute value",
1233 GET_RTX_NAME (GET_CODE (exp
)));
1241 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1242 It becomes a COND with each test being (eq_attr "alternative "n") */
1245 convert_set_attr_alternative (rtx exp
, struct insn_def
*id
)
1247 int num_alt
= id
->num_alternatives
;
1251 if (XVECLEN (exp
, 1) != num_alt
)
1253 message_with_line (id
->lineno
,
1254 "bad number of entries in SET_ATTR_ALTERNATIVE");
1259 /* Make a COND with all tests but the last. Select the last value via the
1261 condexp
= rtx_alloc (COND
);
1262 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1264 for (i
= 0; i
< num_alt
- 1; i
++)
1267 p
= attr_numeral (i
);
1269 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1270 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1273 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1275 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1278 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1279 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1282 convert_set_attr (rtx exp
, struct insn_def
*id
)
1285 const char *name_ptr
;
1289 /* See how many alternative specified. */
1290 n
= n_comma_elts (XSTR (exp
, 1));
1292 return attr_rtx (SET
,
1293 attr_rtx (ATTR
, XSTR (exp
, 0)),
1294 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1296 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1297 XSTR (newexp
, 0) = XSTR (exp
, 0);
1298 XVEC (newexp
, 1) = rtvec_alloc (n
);
1300 /* Process each comma-separated name. */
1301 name_ptr
= XSTR (exp
, 1);
1303 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1304 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1306 return convert_set_attr_alternative (newexp
, id
);
1309 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1310 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1316 struct insn_def
*id
;
1317 struct attr_desc
*attr
;
1321 for (id
= defs
; id
; id
= id
->next
)
1323 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1326 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1328 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1329 switch (GET_CODE (value
))
1332 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1334 message_with_line (id
->lineno
, "bad attribute set");
1340 case SET_ATTR_ALTERNATIVE
:
1341 value
= convert_set_attr_alternative (value
, id
);
1345 value
= convert_set_attr (value
, id
);
1349 message_with_line (id
->lineno
, "invalid attribute code %s",
1350 GET_RTX_NAME (GET_CODE (value
)));
1354 if (value
== NULL_RTX
)
1357 if ((attr
= find_attr (&XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1359 message_with_line (id
->lineno
, "unknown attribute %s",
1360 XSTR (XEXP (value
, 0), 0));
1365 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1366 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1371 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1372 expressions by converting them into a COND. This removes cases from this
1373 program. Also, replace an attribute value of "*" with the default attribute
1377 make_canonical (struct attr_desc
*attr
, rtx exp
)
1382 switch (GET_CODE (exp
))
1385 exp
= make_numeric_value (INTVAL (exp
));
1389 if (! strcmp (XSTR (exp
, 0), "*"))
1391 if (attr
== 0 || attr
->default_val
== 0)
1392 fatal ("(attr_value \"*\") used in invalid context");
1393 exp
= attr
->default_val
->value
;
1396 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1401 if (!attr
->is_const
|| ATTR_IND_SIMPLIFIED_P (exp
))
1403 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1404 This makes the COND something that won't be considered an arbitrary
1405 expression by walk_attr_value. */
1406 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1407 exp
= check_attr_value (exp
, attr
);
1411 newexp
= rtx_alloc (COND
);
1412 XVEC (newexp
, 0) = rtvec_alloc (2);
1413 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1414 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1416 XEXP (newexp
, 1) = XEXP (exp
, 2);
1419 /* Fall through to COND case since this is now a COND. */
1426 /* First, check for degenerate COND. */
1427 if (XVECLEN (exp
, 0) == 0)
1428 return make_canonical (attr
, XEXP (exp
, 1));
1429 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1431 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1433 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1434 XVECEXP (exp
, 0, i
+ 1)
1435 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1436 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1452 copy_boolean (rtx exp
)
1454 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1455 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1456 copy_boolean (XEXP (exp
, 1)));
1457 if (GET_CODE (exp
) == MATCH_OPERAND
)
1459 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1460 XSTR (exp
, 2) = DEF_ATTR_STRING (XSTR (exp
, 2));
1462 else if (GET_CODE (exp
) == EQ_ATTR
)
1464 XSTR (exp
, 0) = DEF_ATTR_STRING (XSTR (exp
, 0));
1465 XSTR (exp
, 1) = DEF_ATTR_STRING (XSTR (exp
, 1));
1471 /* Given a value and an attribute description, return a `struct attr_value *'
1472 that represents that value. This is either an existing structure, if the
1473 value has been previously encountered, or a newly-created structure.
1475 `insn_code' is the code of an insn whose attribute has the specified
1476 value (-2 if not processing an insn). We ensure that all insns for
1477 a given value have the same number of alternatives if the value checks
1480 static struct attr_value
*
1481 get_attr_value (rtx value
, struct attr_desc
*attr
, int insn_code
)
1483 struct attr_value
*av
;
1486 value
= make_canonical (attr
, value
);
1487 if (compares_alternatives_p (value
))
1489 if (insn_code
< 0 || insn_alternatives
== NULL
)
1490 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1492 num_alt
= insn_alternatives
[insn_code
];
1495 for (av
= attr
->first_value
; av
; av
= av
->next
)
1496 if (rtx_equal_p (value
, av
->value
)
1497 && (num_alt
== 0 || av
->first_insn
== NULL
1498 || insn_alternatives
[av
->first_insn
->insn_code
]))
1501 av
= oballoc (sizeof (struct attr_value
));
1503 av
->next
= attr
->first_value
;
1504 attr
->first_value
= av
;
1505 av
->first_insn
= NULL
;
1507 av
->has_asm_insn
= 0;
1512 /* After all DEFINE_DELAYs have been read in, create internal attributes
1513 to generate the required routines.
1515 First, we compute the number of delay slots for each insn (as a COND of
1516 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1517 delay type is specified, we compute a similar function giving the
1518 DEFINE_DELAY ordinal for each insn.
1520 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1521 tells whether a given insn can be in that delay slot.
1523 Normal attribute filling and optimization expands these to contain the
1524 information needed to handle delay slots. */
1527 expand_delays (void)
1529 struct delay_desc
*delay
;
1535 /* First, generate data for `num_delay_slots' function. */
1537 condexp
= rtx_alloc (COND
);
1538 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1539 XEXP (condexp
, 1) = make_numeric_value (0);
1541 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1543 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1544 XVECEXP (condexp
, 0, i
+ 1)
1545 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1548 make_internal_attr (num_delay_slots_str
, condexp
, ATTR_NONE
);
1550 /* If more than one delay type, do the same for computing the delay type. */
1553 condexp
= rtx_alloc (COND
);
1554 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1555 XEXP (condexp
, 1) = make_numeric_value (0);
1557 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1559 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1560 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1563 make_internal_attr (delay_type_str
, condexp
, ATTR_SPECIAL
);
1566 /* For each delay possibility and delay slot, compute an eligibility
1567 attribute for non-annulled insns and for each type of annulled (annul
1568 if true and annul if false). */
1569 for (delay
= delays
; delay
; delay
= delay
->next
)
1571 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1573 condexp
= XVECEXP (delay
->def
, 1, i
);
1575 condexp
= false_rtx
;
1576 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1577 make_numeric_value (1), make_numeric_value (0));
1579 p
= attr_printf (sizeof "*delay__" + MAX_DIGITS
* 2,
1580 "*delay_%d_%d", delay
->num
, i
/ 3);
1581 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1583 if (have_annul_true
)
1585 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1586 if (condexp
== 0) condexp
= false_rtx
;
1587 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1588 make_numeric_value (1),
1589 make_numeric_value (0));
1590 p
= attr_printf (sizeof "*annul_true__" + MAX_DIGITS
* 2,
1591 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1592 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1595 if (have_annul_false
)
1597 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1598 if (condexp
== 0) condexp
= false_rtx
;
1599 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1600 make_numeric_value (1),
1601 make_numeric_value (0));
1602 p
= attr_printf (sizeof "*annul_false__" + MAX_DIGITS
* 2,
1603 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1604 make_internal_attr (p
, newexp
, ATTR_SPECIAL
);
1610 /* This function is given a left and right side expression and an operator.
1611 Each side is a conditional expression, each alternative of which has a
1612 numerical value. The function returns another conditional expression
1613 which, for every possible set of condition values, returns a value that is
1614 the operator applied to the values of the two sides.
1616 Since this is called early, it must also support IF_THEN_ELSE. */
1619 operate_exp (enum operator op
, rtx left
, rtx right
)
1621 int left_value
, right_value
;
1625 /* If left is a string, apply operator to it and the right side. */
1626 if (GET_CODE (left
) == CONST_STRING
)
1628 /* If right is also a string, just perform the operation. */
1629 if (GET_CODE (right
) == CONST_STRING
)
1631 left_value
= atoi (XSTR (left
, 0));
1632 right_value
= atoi (XSTR (right
, 0));
1636 i
= left_value
+ right_value
;
1640 i
= left_value
- right_value
;
1643 case POS_MINUS_OP
: /* The positive part of LEFT - RIGHT. */
1644 if (left_value
> right_value
)
1645 i
= left_value
- right_value
;
1652 i
= left_value
| right_value
;
1656 i
= left_value
== right_value
;
1660 i
= (left_value
<< (HOST_BITS_PER_INT
/ 2)) | right_value
;
1664 if (left_value
> right_value
)
1671 if (left_value
< right_value
)
1681 if (i
== left_value
)
1683 if (i
== right_value
)
1685 return make_numeric_value (i
);
1687 else if (GET_CODE (right
) == IF_THEN_ELSE
)
1689 /* Apply recursively to all values within. */
1690 rtx newleft
= operate_exp (op
, left
, XEXP (right
, 1));
1691 rtx newright
= operate_exp (op
, left
, XEXP (right
, 2));
1692 if (rtx_equal_p (newleft
, newright
))
1694 return attr_rtx (IF_THEN_ELSE
, XEXP (right
, 0), newleft
, newright
);
1696 else if (GET_CODE (right
) == COND
)
1701 newexp
= rtx_alloc (COND
);
1702 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (right
, 0));
1703 defval
= XEXP (newexp
, 1) = operate_exp (op
, left
, XEXP (right
, 1));
1705 for (i
= 0; i
< XVECLEN (right
, 0); i
+= 2)
1707 XVECEXP (newexp
, 0, i
) = XVECEXP (right
, 0, i
);
1708 XVECEXP (newexp
, 0, i
+ 1)
1709 = operate_exp (op
, left
, XVECEXP (right
, 0, i
+ 1));
1710 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1715 /* If the resulting cond is trivial (all alternatives
1716 give the same value), optimize it away. */
1718 return operate_exp (op
, left
, XEXP (right
, 1));
1723 fatal ("badly formed attribute value");
1726 /* A hack to prevent expand_units from completely blowing up: ORX_OP does
1727 not associate through IF_THEN_ELSE. */
1728 else if (op
== ORX_OP
&& GET_CODE (right
) == IF_THEN_ELSE
)
1730 return attr_rtx (IOR
, left
, right
);
1733 /* Otherwise, do recursion the other way. */
1734 else if (GET_CODE (left
) == IF_THEN_ELSE
)
1736 rtx newleft
= operate_exp (op
, XEXP (left
, 1), right
);
1737 rtx newright
= operate_exp (op
, XEXP (left
, 2), right
);
1738 if (rtx_equal_p (newleft
, newright
))
1740 return attr_rtx (IF_THEN_ELSE
, XEXP (left
, 0), newleft
, newright
);
1742 else if (GET_CODE (left
) == COND
)
1747 newexp
= rtx_alloc (COND
);
1748 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (left
, 0));
1749 defval
= XEXP (newexp
, 1) = operate_exp (op
, XEXP (left
, 1), right
);
1751 for (i
= 0; i
< XVECLEN (left
, 0); i
+= 2)
1753 XVECEXP (newexp
, 0, i
) = XVECEXP (left
, 0, i
);
1754 XVECEXP (newexp
, 0, i
+ 1)
1755 = operate_exp (op
, XVECEXP (left
, 0, i
+ 1), right
);
1756 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1761 /* If the cond is trivial (all alternatives give the same value),
1762 optimize it away. */
1764 return operate_exp (op
, XEXP (left
, 1), right
);
1766 /* If the result is the same as the LEFT operand,
1768 if (rtx_equal_p (newexp
, left
))
1775 fatal ("badly formed attribute value");
1780 /* Once all attributes and DEFINE_FUNCTION_UNITs have been read, we
1781 construct a number of attributes.
1783 The first produces a function `function_units_used' which is given an
1784 insn and produces an encoding showing which function units are required
1785 for the execution of that insn. If the value is non-negative, the insn
1786 uses that unit; otherwise, the value is a one's complement mask of units
1789 The second produces a function `result_ready_cost' which is used to
1790 determine the time that the result of an insn will be ready and hence
1791 a worst-case schedule.
1793 Both of these produce quite complex expressions which are then set as the
1794 default value of internal attributes. Normal attribute simplification
1795 should produce reasonable expressions.
1797 For each unit, a `<name>_unit_ready_cost' function will take an
1798 insn and give the delay until that unit will be ready with the result
1799 and a `<name>_unit_conflict_cost' function is given an insn already
1800 executing on the unit and a candidate to execute and will give the
1801 cost from the time the executing insn started until the candidate
1802 can start (ignore limitations on the number of simultaneous insns).
1804 For each unit, a `<name>_unit_blockage' function is given an insn
1805 already executing on the unit and a candidate to execute and will
1806 give the delay incurred due to function unit conflicts. The range of
1807 blockage cost values for a given executing insn is given by the
1808 `<name>_unit_blockage_range' function. These values are encoded in
1809 an int where the upper half gives the minimum value and the lower
1810 half gives the maximum value. */
1815 struct function_unit
*unit
, **unit_num
;
1816 struct function_unit_op
*op
, **op_array
, ***unit_ops
;
1821 int i
, j
, u
, num
, nvalues
;
1823 /* Rebuild the condition for the unit to share the RTL expressions.
1824 Sharing is required by simplify_by_exploding. Build the issue delay
1825 expressions. Validate the expressions we were given for the conditions
1826 and conflict vector. Then make attributes for use in the conflict
1829 for (unit
= units
; unit
; unit
= unit
->next
)
1831 unit
->condexp
= check_attr_test (unit
->condexp
, 0, unit
->first_lineno
);
1833 for (op
= unit
->ops
; op
; op
= op
->next
)
1835 rtx issue_delay
= make_numeric_value (op
->issue_delay
);
1836 rtx issue_exp
= issue_delay
;
1838 /* Build, validate, and simplify the issue delay expression. */
1839 if (op
->conflict_exp
!= true_rtx
)
1840 issue_exp
= attr_rtx (IF_THEN_ELSE
, op
->conflict_exp
,
1841 issue_exp
, make_numeric_value (0));
1842 issue_exp
= check_attr_value (make_canonical (NULL_ATTR
,
1845 issue_exp
= simplify_knowing (issue_exp
, unit
->condexp
);
1846 op
->issue_exp
= issue_exp
;
1848 /* Make an attribute for use in the conflict function if needed. */
1849 unit
->needs_conflict_function
= (unit
->issue_delay
.min
1850 != unit
->issue_delay
.max
);
1851 if (unit
->needs_conflict_function
)
1853 str
= attr_printf ((strlen (unit
->name
) + sizeof "*_cost_"
1855 "*%s_cost_%d", unit
->name
, op
->num
);
1856 make_internal_attr (str
, issue_exp
, ATTR_SPECIAL
);
1859 /* Validate the condition. */
1860 op
->condexp
= check_attr_test (op
->condexp
, 0, op
->lineno
);
1864 /* Compute the mask of function units used. Initially, the unitsmask is
1865 zero. Set up a conditional to compute each unit's contribution. */
1866 unitsmask
= make_numeric_value (0);
1867 newexp
= rtx_alloc (IF_THEN_ELSE
);
1868 XEXP (newexp
, 2) = make_numeric_value (0);
1870 /* If we have just a few units, we may be all right expanding the whole
1871 thing. But the expansion is 2**N in space on the number of opclasses,
1872 so we can't do this for very long -- Alpha and MIPS in particular have
1873 problems with this. So in that situation, we fall back on an alternate
1874 implementation method. */
1875 #define NUM_UNITOP_CUTOFF 20
1877 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1879 /* Merge each function unit into the unit mask attributes. */
1880 for (unit
= units
; unit
; unit
= unit
->next
)
1882 XEXP (newexp
, 0) = unit
->condexp
;
1883 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1884 unitsmask
= operate_exp (OR_OP
, unitsmask
, newexp
);
1889 /* Merge each function unit into the unit mask attributes. */
1890 for (unit
= units
; unit
; unit
= unit
->next
)
1892 XEXP (newexp
, 0) = unit
->condexp
;
1893 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1894 unitsmask
= operate_exp (ORX_OP
, unitsmask
, attr_copy_rtx (newexp
));
1898 /* Simplify the unit mask expression, encode it, and make an attribute
1899 for the function_units_used function. */
1900 unitsmask
= simplify_by_exploding (unitsmask
);
1902 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1903 unitsmask
= encode_units_mask (unitsmask
);
1906 /* We can no longer encode unitsmask at compile time, so emit code to
1907 calculate it at runtime. Rather, put a marker for where we'd do
1908 the code, and actually output it in write_attr_get(). */
1909 unitsmask
= attr_rtx (FFS
, unitsmask
);
1912 make_internal_attr ("*function_units_used", unitsmask
,
1913 (ATTR_NEGATIVE_OK
| ATTR_FUNC_UNITS
));
1915 /* Create an array of ops for each unit. Add an extra unit for the
1916 result_ready_cost function that has the ops of all other units. */
1917 unit_ops
= xmalloc ((num_units
+ 1) * sizeof (struct function_unit_op
**));
1918 unit_num
= xmalloc ((num_units
+ 1) * sizeof (struct function_unit
*));
1920 unit_num
[num_units
] = unit
= xmalloc (sizeof (struct function_unit
));
1921 unit
->num
= num_units
;
1922 unit
->num_opclasses
= 0;
1924 for (unit
= units
; unit
; unit
= unit
->next
)
1926 unit_num
[num_units
]->num_opclasses
+= unit
->num_opclasses
;
1927 unit_num
[unit
->num
] = unit
;
1928 unit_ops
[unit
->num
] = op_array
=
1929 xmalloc (unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1931 for (op
= unit
->ops
; op
; op
= op
->next
)
1932 op_array
[op
->num
] = op
;
1935 /* Compose the array of ops for the extra unit. */
1936 unit_ops
[num_units
] = op_array
=
1937 xmalloc (unit_num
[num_units
]->num_opclasses
1938 * sizeof (struct function_unit_op
*));
1940 for (unit
= units
, i
= 0; unit
; i
+= unit
->num_opclasses
, unit
= unit
->next
)
1941 memcpy (&op_array
[i
], unit_ops
[unit
->num
],
1942 unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1944 /* Compute the ready cost function for each unit by computing the
1945 condition for each non-default value. */
1946 for (u
= 0; u
<= num_units
; u
++)
1952 op_array
= unit_ops
[unit
->num
];
1953 num
= unit
->num_opclasses
;
1955 /* Sort the array of ops into increasing ready cost order. */
1956 for (i
= 0; i
< num
; i
++)
1957 for (j
= num
- 1; j
> i
; j
--)
1958 if (op_array
[j
- 1]->ready
< op_array
[j
]->ready
)
1961 op_array
[j
] = op_array
[j
- 1];
1962 op_array
[j
- 1] = op
;
1965 /* Determine how many distinct non-default ready cost values there
1966 are. We use a default ready cost value of 1. */
1967 nvalues
= 0; value
= 1;
1968 for (i
= num
- 1; i
>= 0; i
--)
1969 if (op_array
[i
]->ready
> value
)
1971 value
= op_array
[i
]->ready
;
1976 readycost
= make_numeric_value (1);
1979 /* Construct the ready cost expression as a COND of each value from
1980 the largest to the smallest. */
1981 readycost
= rtx_alloc (COND
);
1982 XVEC (readycost
, 0) = rtvec_alloc (nvalues
* 2);
1983 XEXP (readycost
, 1) = make_numeric_value (1);
1987 value
= op_array
[0]->ready
;
1988 for (i
= 0; i
< num
; i
++)
1993 else if (op
->ready
== value
)
1994 orexp
= insert_right_side (IOR
, orexp
, op
->condexp
, -2, -2);
1997 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
1998 XVECEXP (readycost
, 0, nvalues
* 2 + 1)
1999 = make_numeric_value (value
);
2002 orexp
= op
->condexp
;
2005 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
2006 XVECEXP (readycost
, 0, nvalues
* 2 + 1) = make_numeric_value (value
);
2011 rtx max_blockage
= 0, min_blockage
= 0;
2013 /* Simplify the readycost expression by only considering insns
2014 that use the unit. */
2015 readycost
= simplify_knowing (readycost
, unit
->condexp
);
2017 /* Determine the blockage cost the executing insn (E) given
2018 the candidate insn (C). This is the maximum of the issue
2019 delay, the pipeline delay, and the simultaneity constraint.
2020 Each function_unit_op represents the characteristics of the
2021 candidate insn, so in the expressions below, C is a known
2022 term and E is an unknown term.
2024 We compute the blockage cost for each E for every possible C.
2025 Thus OP represents E, and READYCOST is a list of values for
2028 The issue delay function for C is op->issue_exp and is used to
2029 write the `<name>_unit_conflict_cost' function. Symbolically
2030 this is "ISSUE-DELAY (E,C)".
2032 The pipeline delay results form the FIFO constraint on the
2033 function unit and is "READY-COST (E) + 1 - READY-COST (C)".
2035 The simultaneity constraint is based on how long it takes to
2036 fill the unit given the minimum issue delay. FILL-TIME is the
2037 constant "MIN (ISSUE-DELAY (*,*)) * (SIMULTANEITY - 1)", and
2038 the simultaneity constraint is "READY-COST (E) - FILL-TIME"
2039 if SIMULTANEITY is nonzero and zero otherwise.
2041 Thus, BLOCKAGE (E,C) when SIMULTANEITY is zero is
2043 MAX (ISSUE-DELAY (E,C),
2044 READY-COST (E) - (READY-COST (C) - 1))
2048 MAX (ISSUE-DELAY (E,C),
2049 READY-COST (E) - (READY-COST (C) - 1),
2050 READY-COST (E) - FILL-TIME)
2052 The `<name>_unit_blockage' function is computed by determining
2053 this value for each candidate insn. As these values are
2054 computed, we also compute the upper and lower bounds for
2055 BLOCKAGE (E,*). These are combined to form the function
2056 `<name>_unit_blockage_range'. Finally, the maximum blockage
2057 cost, MAX (BLOCKAGE (*,*)), is computed. */
2059 for (op
= unit
->ops
; op
; op
= op
->next
)
2061 rtx blockage
= op
->issue_exp
;
2062 blockage
= simplify_knowing (blockage
, unit
->condexp
);
2064 /* Add this op's contribution to MAX (BLOCKAGE (E,*)) and
2065 MIN (BLOCKAGE (E,*)). */
2066 if (max_blockage
== 0)
2067 max_blockage
= min_blockage
= blockage
;
2071 = simplify_knowing (operate_exp (MAX_OP
, max_blockage
,
2075 = simplify_knowing (operate_exp (MIN_OP
, min_blockage
,
2080 /* Make an attribute for use in the blockage function. */
2081 str
= attr_printf ((strlen (unit
->name
) + sizeof "*_block_"
2083 "*%s_block_%d", unit
->name
, op
->num
);
2084 make_internal_attr (str
, blockage
, ATTR_SPECIAL
);
2087 /* Record MAX (BLOCKAGE (*,*)). */
2090 unit
->max_blockage
= max_attr_value (max_blockage
, &unknown
);
2093 /* See if the upper and lower bounds of BLOCKAGE (E,*) are the
2094 same. If so, the blockage function carries no additional
2095 information and is not written. */
2096 newexp
= operate_exp (EQ_OP
, max_blockage
, min_blockage
);
2097 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2098 unit
->needs_blockage_function
2099 = (GET_CODE (newexp
) != CONST_STRING
2100 || atoi (XSTR (newexp
, 0)) != 1);
2102 /* If the all values of BLOCKAGE (E,C) have the same value,
2103 neither blockage function is written. */
2104 unit
->needs_range_function
2105 = (unit
->needs_blockage_function
2106 || GET_CODE (max_blockage
) != CONST_STRING
);
2108 if (unit
->needs_range_function
)
2110 /* Compute the blockage range function and make an attribute
2111 for writing its value. */
2112 newexp
= operate_exp (RANGE_OP
, min_blockage
, max_blockage
);
2113 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2115 str
= attr_printf ((strlen (unit
->name
)
2116 + sizeof "*_unit_blockage_range"),
2117 "*%s_unit_blockage_range", unit
->name
);
2118 make_internal_attr (str
, newexp
, (ATTR_STATIC
|ATTR_BLOCKAGE
|ATTR_UNSIGNED
));
2121 str
= attr_printf (strlen (unit
->name
) + sizeof "*_unit_ready_cost",
2122 "*%s_unit_ready_cost", unit
->name
);
2123 make_internal_attr (str
, readycost
, ATTR_STATIC
);
2127 /* Make an attribute for the ready_cost function. Simplifying
2128 further with simplify_by_exploding doesn't win. */
2129 str
= "*result_ready_cost";
2130 make_internal_attr (str
, readycost
, ATTR_NONE
);
2134 /* For each unit that requires a conflict cost function, make an attribute
2135 that maps insns to the operation number. */
2136 for (unit
= units
; unit
; unit
= unit
->next
)
2140 if (! unit
->needs_conflict_function
2141 && ! unit
->needs_blockage_function
)
2144 caseexp
= rtx_alloc (COND
);
2145 XVEC (caseexp
, 0) = rtvec_alloc ((unit
->num_opclasses
- 1) * 2);
2147 for (op
= unit
->ops
; op
; op
= op
->next
)
2149 /* Make our adjustment to the COND being computed. If we are the
2150 last operation class, place our values into the default of the
2152 if (op
->num
== unit
->num_opclasses
- 1)
2154 XEXP (caseexp
, 1) = make_numeric_value (op
->num
);
2158 XVECEXP (caseexp
, 0, op
->num
* 2) = op
->condexp
;
2159 XVECEXP (caseexp
, 0, op
->num
* 2 + 1)
2160 = make_numeric_value (op
->num
);
2164 /* Simplifying caseexp with simplify_by_exploding doesn't win. */
2165 str
= attr_printf (strlen (unit
->name
) + sizeof "*_cases",
2166 "*%s_cases", unit
->name
);
2167 make_internal_attr (str
, caseexp
, ATTR_SPECIAL
);
2171 /* Simplify EXP given KNOWN_TRUE. */
2174 simplify_knowing (rtx exp
, rtx known_true
)
2176 if (GET_CODE (exp
) != CONST_STRING
)
2178 int unknown
= 0, max
;
2179 max
= max_attr_value (exp
, &unknown
);
2182 exp
= attr_rtx (IF_THEN_ELSE
, known_true
, exp
,
2183 make_numeric_value (max
));
2184 exp
= simplify_by_exploding (exp
);
2190 /* Translate the CONST_STRING expressions in X to change the encoding of
2191 value. On input, the value is a bitmask with a one bit for each unit
2192 used; on output, the value is the unit number (zero based) if one
2193 and only one unit is used or the one's complement of the bitmask. */
2196 encode_units_mask (rtx x
)
2203 code
= GET_CODE (x
);
2208 i
= atoi (XSTR (x
, 0));
2210 /* The sign bit encodes a one's complement mask. */
2212 else if (i
!= 0 && i
== (i
& -i
))
2213 /* Only one bit is set, so yield that unit number. */
2214 for (j
= 0; (i
>>= 1) != 0; j
++)
2218 return attr_rtx (CONST_STRING
, attr_printf (MAX_DIGITS
, "%d", j
));
2237 /* Compare the elements. If any pair of corresponding elements
2238 fail to match, return 0 for the whole things. */
2240 fmt
= GET_RTX_FORMAT (code
);
2241 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2247 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2248 XVECEXP (x
, i
, j
) = encode_units_mask (XVECEXP (x
, i
, j
));
2252 XEXP (x
, i
) = encode_units_mask (XEXP (x
, i
));
2259 /* Once all attributes and insns have been read and checked, we construct for
2260 each attribute value a list of all the insns that have that value for
2264 fill_attr (struct attr_desc
*attr
)
2266 struct attr_value
*av
;
2267 struct insn_ent
*ie
;
2268 struct insn_def
*id
;
2272 /* Don't fill constant attributes. The value is independent of
2273 any particular insn. */
2277 for (id
= defs
; id
; id
= id
->next
)
2279 /* If no value is specified for this insn for this attribute, use the
2282 if (XVEC (id
->def
, id
->vec_idx
))
2283 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
2284 if (! strcmp_check (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
2286 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
2289 av
= attr
->default_val
;
2291 av
= get_attr_value (value
, attr
, id
->insn_code
);
2293 ie
= oballoc (sizeof (struct insn_ent
));
2294 ie
->insn_code
= id
->insn_code
;
2295 ie
->insn_index
= id
->insn_code
;
2296 insert_insn_ent (av
, ie
);
2300 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
2301 test that checks relative positions of insns (uses MATCH_DUP or PC).
2302 If so, replace it with what is obtained by passing the expression to
2303 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
2304 recursively on each value (including the default value). Otherwise,
2305 return the value returned by NO_ADDRESS_FN applied to EXP. */
2308 substitute_address (rtx exp
, rtx (*no_address_fn
) (rtx
),
2309 rtx (*address_fn
) (rtx
))
2314 if (GET_CODE (exp
) == COND
)
2316 /* See if any tests use addresses. */
2318 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2319 walk_attr_value (XVECEXP (exp
, 0, i
));
2322 return (*address_fn
) (exp
);
2324 /* Make a new copy of this COND, replacing each element. */
2325 newexp
= rtx_alloc (COND
);
2326 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
2327 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2329 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
2330 XVECEXP (newexp
, 0, i
+ 1)
2331 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
2332 no_address_fn
, address_fn
);
2335 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
2336 no_address_fn
, address_fn
);
2341 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
2344 walk_attr_value (XEXP (exp
, 0));
2346 return (*address_fn
) (exp
);
2348 return attr_rtx (IF_THEN_ELSE
,
2349 substitute_address (XEXP (exp
, 0),
2350 no_address_fn
, address_fn
),
2351 substitute_address (XEXP (exp
, 1),
2352 no_address_fn
, address_fn
),
2353 substitute_address (XEXP (exp
, 2),
2354 no_address_fn
, address_fn
));
2357 return (*no_address_fn
) (exp
);
2360 /* Make new attributes from the `length' attribute. The following are made,
2361 each corresponding to a function called from `shorten_branches' or
2364 *insn_default_length This is the length of the insn to be returned
2365 by `get_attr_length' before `shorten_branches'
2366 has been called. In each case where the length
2367 depends on relative addresses, the largest
2368 possible is used. This routine is also used
2369 to compute the initial size of the insn.
2371 *insn_variable_length_p This returns 1 if the insn's length depends
2372 on relative addresses, zero otherwise.
2374 *insn_current_length This is only called when it is known that the
2375 insn has a variable length and returns the
2376 current length, based on relative addresses.
2380 make_length_attrs (void)
2382 static const char *new_names
[] =
2384 "*insn_default_length",
2385 "*insn_variable_length_p",
2386 "*insn_current_length"
2388 static rtx (*const no_address_fn
[]) (rtx
) = {identity_fn
, zero_fn
, zero_fn
};
2389 static rtx (*const address_fn
[]) (rtx
) = {max_fn
, one_fn
, identity_fn
};
2391 struct attr_desc
*length_attr
, *new_attr
;
2392 struct attr_value
*av
, *new_av
;
2393 struct insn_ent
*ie
, *new_ie
;
2395 /* See if length attribute is defined. If so, it must be numeric. Make
2396 it special so we don't output anything for it. */
2397 length_attr
= find_attr (&length_str
, 0);
2398 if (length_attr
== 0)
2401 if (! length_attr
->is_numeric
)
2402 fatal ("length attribute must be numeric");
2404 length_attr
->is_const
= 0;
2405 length_attr
->is_special
= 1;
2407 /* Make each new attribute, in turn. */
2408 for (i
= 0; i
< ARRAY_SIZE (new_names
); i
++)
2410 make_internal_attr (new_names
[i
],
2411 substitute_address (length_attr
->default_val
->value
,
2412 no_address_fn
[i
], address_fn
[i
]),
2414 new_attr
= find_attr (&new_names
[i
], 0);
2415 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2416 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2418 new_av
= get_attr_value (substitute_address (av
->value
,
2421 new_attr
, ie
->insn_code
);
2422 new_ie
= oballoc (sizeof (struct insn_ent
));
2423 new_ie
->insn_code
= ie
->insn_code
;
2424 new_ie
->insn_index
= ie
->insn_index
;
2425 insert_insn_ent (new_av
, new_ie
);
2430 /* Utility functions called from above routine. */
2433 identity_fn (rtx exp
)
2439 zero_fn (rtx exp ATTRIBUTE_UNUSED
)
2441 return make_numeric_value (0);
2445 one_fn (rtx exp ATTRIBUTE_UNUSED
)
2447 return make_numeric_value (1);
2454 return make_numeric_value (max_attr_value (exp
, &unknown
));
2458 write_length_unit_log (void)
2460 struct attr_desc
*length_attr
= find_attr (&length_str
, 0);
2461 struct attr_value
*av
;
2462 struct insn_ent
*ie
;
2463 unsigned int length_unit_log
, length_or
;
2466 if (length_attr
== 0)
2468 length_or
= or_attr_value (length_attr
->default_val
->value
, &unknown
);
2469 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2470 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2471 length_or
|= or_attr_value (av
->value
, &unknown
);
2474 length_unit_log
= 0;
2477 length_or
= ~length_or
;
2478 for (length_unit_log
= 0; length_or
& 1; length_or
>>= 1)
2481 printf ("int length_unit_log = %u;\n", length_unit_log
);
2484 /* Take a COND expression and see if any of the conditions in it can be
2485 simplified. If any are known true or known false for the particular insn
2486 code, the COND can be further simplified.
2488 Also call ourselves on any COND operations that are values of this COND.
2490 We do not modify EXP; rather, we make and return a new rtx. */
2493 simplify_cond (rtx exp
, int insn_code
, int insn_index
)
2496 /* We store the desired contents here,
2497 then build a new expression if they don't match EXP. */
2498 rtx defval
= XEXP (exp
, 1);
2499 rtx new_defval
= XEXP (exp
, 1);
2500 int len
= XVECLEN (exp
, 0);
2501 rtx
*tests
= xmalloc (len
* sizeof (rtx
));
2505 /* This lets us free all storage allocated below, if appropriate. */
2506 obstack_finish (rtl_obstack
);
2508 memcpy (tests
, XVEC (exp
, 0)->elem
, len
* sizeof (rtx
));
2510 /* See if default value needs simplification. */
2511 if (GET_CODE (defval
) == COND
)
2512 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
2514 /* Simplify the subexpressions, and see what tests we can get rid of. */
2516 for (i
= 0; i
< len
; i
+= 2)
2518 rtx newtest
, newval
;
2520 /* Simplify this test. */
2521 newtest
= simplify_test_exp_in_temp (tests
[i
], insn_code
, insn_index
);
2524 newval
= tests
[i
+ 1];
2525 /* See if this value may need simplification. */
2526 if (GET_CODE (newval
) == COND
)
2527 newval
= simplify_cond (newval
, insn_code
, insn_index
);
2529 /* Look for ways to delete or combine this test. */
2530 if (newtest
== true_rtx
)
2532 /* If test is true, make this value the default
2533 and discard this + any following tests. */
2535 defval
= tests
[i
+ 1];
2536 new_defval
= newval
;
2539 else if (newtest
== false_rtx
)
2541 /* If test is false, discard it and its value. */
2542 for (j
= i
; j
< len
- 2; j
++)
2543 tests
[j
] = tests
[j
+ 2];
2548 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
2550 /* If this value and the value for the prev test are the same,
2554 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
2555 insn_code
, insn_index
);
2557 /* Delete this test/value. */
2558 for (j
= i
; j
< len
- 2; j
++)
2559 tests
[j
] = tests
[j
+ 2];
2565 tests
[i
+ 1] = newval
;
2568 /* If the last test in a COND has the same value
2569 as the default value, that test isn't needed. */
2571 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
2574 /* See if we changed anything. */
2575 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
2578 for (i
= 0; i
< len
; i
++)
2579 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
2587 if (GET_CODE (defval
) == COND
)
2588 ret
= simplify_cond (defval
, insn_code
, insn_index
);
2596 rtx newexp
= rtx_alloc (COND
);
2598 XVEC (newexp
, 0) = rtvec_alloc (len
);
2599 memcpy (XVEC (newexp
, 0)->elem
, tests
, len
* sizeof (rtx
));
2600 XEXP (newexp
, 1) = new_defval
;
2607 /* Remove an insn entry from an attribute value. */
2610 remove_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
2612 struct insn_ent
*previe
;
2614 if (av
->first_insn
== ie
)
2615 av
->first_insn
= ie
->next
;
2618 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
2620 previe
->next
= ie
->next
;
2624 if (ie
->insn_code
== -1)
2625 av
->has_asm_insn
= 0;
2630 /* Insert an insn entry in an attribute value list. */
2633 insert_insn_ent (struct attr_value
*av
, struct insn_ent
*ie
)
2635 ie
->next
= av
->first_insn
;
2636 av
->first_insn
= ie
;
2638 if (ie
->insn_code
== -1)
2639 av
->has_asm_insn
= 1;
2644 /* This is a utility routine to take an expression that is a tree of either
2645 AND or IOR expressions and insert a new term. The new term will be
2646 inserted at the right side of the first node whose code does not match
2647 the root. A new node will be created with the root's code. Its left
2648 side will be the old right side and its right side will be the new
2651 If the `term' is itself a tree, all its leaves will be inserted. */
2654 insert_right_side (enum rtx_code code
, rtx exp
, rtx term
, int insn_code
, int insn_index
)
2658 /* Avoid consing in some special cases. */
2659 if (code
== AND
&& term
== true_rtx
)
2661 if (code
== AND
&& term
== false_rtx
)
2663 if (code
== AND
&& exp
== true_rtx
)
2665 if (code
== AND
&& exp
== false_rtx
)
2667 if (code
== IOR
&& term
== true_rtx
)
2669 if (code
== IOR
&& term
== false_rtx
)
2671 if (code
== IOR
&& exp
== true_rtx
)
2673 if (code
== IOR
&& exp
== false_rtx
)
2675 if (attr_equal_p (exp
, term
))
2678 if (GET_CODE (term
) == code
)
2680 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
2681 insn_code
, insn_index
);
2682 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
2683 insn_code
, insn_index
);
2688 if (GET_CODE (exp
) == code
)
2690 rtx
new = insert_right_side (code
, XEXP (exp
, 1),
2691 term
, insn_code
, insn_index
);
2692 if (new != XEXP (exp
, 1))
2693 /* Make a copy of this expression and call recursively. */
2694 newexp
= attr_rtx (code
, XEXP (exp
, 0), new);
2700 /* Insert the new term. */
2701 newexp
= attr_rtx (code
, exp
, term
);
2704 return simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2707 /* If we have an expression which AND's a bunch of
2708 (not (eq_attrq "alternative" "n"))
2709 terms, we may have covered all or all but one of the possible alternatives.
2710 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
2712 This routine is passed an expression and either AND or IOR. It returns a
2713 bitmask indicating which alternatives are mentioned within EXP. */
2716 compute_alternative_mask (rtx exp
, enum rtx_code code
)
2719 if (GET_CODE (exp
) == code
)
2720 return compute_alternative_mask (XEXP (exp
, 0), code
)
2721 | compute_alternative_mask (XEXP (exp
, 1), code
);
2723 else if (code
== AND
&& GET_CODE (exp
) == NOT
2724 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2725 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
2726 string
= XSTR (XEXP (exp
, 0), 1);
2728 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
2729 && XSTR (exp
, 0) == alternative_name
)
2730 string
= XSTR (exp
, 1);
2732 else if (GET_CODE (exp
) == EQ_ATTR_ALT
)
2734 if (code
== AND
&& XINT (exp
, 1))
2735 return XINT (exp
, 0);
2737 if (code
== IOR
&& !XINT (exp
, 1))
2738 return XINT (exp
, 0);
2746 return 1 << (string
[0] - '0');
2747 return 1 << atoi (string
);
2750 /* Given I, a single-bit mask, return RTX to compare the `alternative'
2751 attribute with the value represented by that bit. */
2754 make_alternative_compare (int mask
)
2756 return mk_attr_alt (mask
);
2759 /* If we are processing an (eq_attr "attr" "value") test, we find the value
2760 of "attr" for this insn code. From that value, we can compute a test
2761 showing when the EQ_ATTR will be true. This routine performs that
2762 computation. If a test condition involves an address, we leave the EQ_ATTR
2763 intact because addresses are only valid for the `length' attribute.
2765 EXP is the EQ_ATTR expression and VALUE is the value of that attribute
2766 for the insn corresponding to INSN_CODE and INSN_INDEX. */
2769 evaluate_eq_attr (rtx exp
, rtx value
, int insn_code
, int insn_index
)
2776 if (GET_CODE (value
) == CONST_STRING
)
2778 if (! strcmp_check (XSTR (value
, 0), XSTR (exp
, 1)))
2783 else if (GET_CODE (value
) == SYMBOL_REF
)
2788 if (GET_CODE (exp
) != EQ_ATTR
)
2791 if (strlen (XSTR (exp
, 0)) + strlen (XSTR (exp
, 1)) + 2 > 256)
2794 strcpy (string
, XSTR (exp
, 0));
2795 strcat (string
, "_");
2796 strcat (string
, XSTR (exp
, 1));
2797 for (p
= string
; *p
; p
++)
2800 newexp
= attr_rtx (EQ
, value
,
2801 attr_rtx (SYMBOL_REF
,
2802 DEF_ATTR_STRING (string
)));
2804 else if (GET_CODE (value
) == COND
)
2806 /* We construct an IOR of all the cases for which the requested attribute
2807 value is present. Since we start with FALSE, if it is not present,
2808 FALSE will be returned.
2810 Each case is the AND of the NOT's of the previous conditions with the
2811 current condition; in the default case the current condition is TRUE.
2813 For each possible COND value, call ourselves recursively.
2815 The extra TRUE and FALSE expressions will be eliminated by another
2816 call to the simplification routine. */
2821 if (current_alternative_string
)
2822 clear_struct_flag (value
);
2824 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2826 rtx
this = simplify_test_exp_in_temp (XVECEXP (value
, 0, i
),
2827 insn_code
, insn_index
);
2829 SIMPLIFY_ALTERNATIVE (this);
2831 right
= insert_right_side (AND
, andexp
, this,
2832 insn_code
, insn_index
);
2833 right
= insert_right_side (AND
, right
,
2834 evaluate_eq_attr (exp
,
2837 insn_code
, insn_index
),
2838 insn_code
, insn_index
);
2839 orexp
= insert_right_side (IOR
, orexp
, right
,
2840 insn_code
, insn_index
);
2842 /* Add this condition into the AND expression. */
2843 newexp
= attr_rtx (NOT
, this);
2844 andexp
= insert_right_side (AND
, andexp
, newexp
,
2845 insn_code
, insn_index
);
2848 /* Handle the default case. */
2849 right
= insert_right_side (AND
, andexp
,
2850 evaluate_eq_attr (exp
, XEXP (value
, 1),
2851 insn_code
, insn_index
),
2852 insn_code
, insn_index
);
2853 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2858 /* If uses an address, must return original expression. But set the
2859 ATTR_IND_SIMPLIFIED_P bit so we don't try to simplify it again. */
2862 walk_attr_value (newexp
);
2866 /* This had `&& current_alternative_string', which seems to be wrong. */
2867 if (! ATTR_IND_SIMPLIFIED_P (exp
))
2868 return copy_rtx_unchanging (exp
);
2875 /* This routine is called when an AND of a term with a tree of AND's is
2876 encountered. If the term or its complement is present in the tree, it
2877 can be replaced with TRUE or FALSE, respectively.
2879 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2880 be true and hence are complementary.
2882 There is one special case: If we see
2883 (and (not (eq_attr "att" "v1"))
2884 (eq_attr "att" "v2"))
2885 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2886 replace the term, not anything in the AND tree. So we pass a pointer to
2890 simplify_and_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
2895 int left_eliminates_term
, right_eliminates_term
;
2897 if (GET_CODE (exp
) == AND
)
2899 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2900 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2901 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2903 newexp
= attr_rtx (AND
, left
, right
);
2905 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2909 else if (GET_CODE (exp
) == IOR
)
2911 /* For the IOR case, we do the same as above, except that we can
2912 only eliminate `term' if both sides of the IOR would do so. */
2914 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2915 left_eliminates_term
= (temp
== true_rtx
);
2918 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2919 right_eliminates_term
= (temp
== true_rtx
);
2921 if (left_eliminates_term
&& right_eliminates_term
)
2924 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2926 newexp
= attr_rtx (IOR
, left
, right
);
2928 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2932 /* Check for simplifications. Do some extra checking here since this
2933 routine is called so many times. */
2938 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
2941 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
2944 else if (GET_CODE (exp
) == EQ_ATTR_ALT
&& GET_CODE (*pterm
) == EQ_ATTR_ALT
)
2946 if (attr_alt_subset_p (*pterm
, exp
))
2949 if (attr_alt_subset_of_compl_p (*pterm
, exp
))
2952 if (attr_alt_subset_p (exp
, *pterm
))
2958 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
2960 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
2963 if (! strcmp_check (XSTR (exp
, 1), XSTR (*pterm
, 1)))
2969 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
2970 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
2972 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
2975 if (! strcmp_check (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
2981 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
2982 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
2984 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
2987 if (! strcmp_check (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
2993 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
2995 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
2999 else if (GET_CODE (exp
) == NOT
)
3001 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
3005 else if (GET_CODE (*pterm
) == NOT
)
3007 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
3011 else if (attr_equal_p (exp
, *pterm
))
3017 /* Similar to `simplify_and_tree', but for IOR trees. */
3020 simplify_or_tree (rtx exp
, rtx
*pterm
, int insn_code
, int insn_index
)
3025 int left_eliminates_term
, right_eliminates_term
;
3027 if (GET_CODE (exp
) == IOR
)
3029 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
3030 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
3031 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3033 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3035 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3039 else if (GET_CODE (exp
) == AND
)
3041 /* For the AND case, we do the same as above, except that we can
3042 only eliminate `term' if both sides of the AND would do so. */
3044 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
3045 left_eliminates_term
= (temp
== false_rtx
);
3048 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
3049 right_eliminates_term
= (temp
== false_rtx
);
3051 if (left_eliminates_term
&& right_eliminates_term
)
3054 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3056 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3058 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3062 if (attr_equal_p (exp
, *pterm
))
3065 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
3068 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
3071 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
3072 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3073 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
3076 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
3077 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
3078 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
3084 /* Compute approximate cost of the expression. Used to decide whether
3085 expression is cheap enough for inline. */
3087 attr_rtx_cost (rtx x
)
3093 code
= GET_CODE (x
);
3106 /* Alternatives don't result into function call. */
3107 if (!strcmp_check (XSTR (x
, 0), alternative_name
))
3114 const char *fmt
= GET_RTX_FORMAT (code
);
3115 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3121 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3122 cost
+= attr_rtx_cost (XVECEXP (x
, i
, j
));
3125 cost
+= attr_rtx_cost (XEXP (x
, i
));
3135 /* Simplify test expression and use temporary obstack in order to avoid
3136 memory bloat. Use ATTR_IND_SIMPLIFIED to avoid unnecessary simplifications
3137 and avoid unnecessary copying if possible. */
3140 simplify_test_exp_in_temp (rtx exp
, int insn_code
, int insn_index
)
3143 struct obstack
*old
;
3144 if (ATTR_IND_SIMPLIFIED_P (exp
))
3147 rtl_obstack
= temp_obstack
;
3148 x
= simplify_test_exp (exp
, insn_code
, insn_index
);
3150 if (x
== exp
|| rtl_obstack
== temp_obstack
)
3152 return attr_copy_rtx (x
);
3155 /* Returns true if S1 is a subset of S2. */
3158 attr_alt_subset_p (rtx s1
, rtx s2
)
3160 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
3163 return !(XINT (s1
, 0) &~ XINT (s2
, 0));
3166 return !(XINT (s1
, 0) & XINT (s2
, 0));
3172 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
3179 /* Returns true if S1 is a subset of complement of S2. */
3181 static bool attr_alt_subset_of_compl_p (rtx s1
, rtx s2
)
3183 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
3186 return !(XINT (s1
, 0) & XINT (s2
, 0));
3189 return !(XINT (s1
, 0) & ~XINT (s2
, 0));
3192 return !(XINT (s2
, 0) &~ XINT (s1
, 0));
3202 /* Return EQ_ATTR_ALT expression representing intersection of S1 and S2. */
3205 attr_alt_intersection (rtx s1
, rtx s2
)
3207 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
3209 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
3212 XINT (result
, 0) = XINT (s1
, 0) & XINT (s2
, 0);
3215 XINT (result
, 0) = XINT (s1
, 0) & ~XINT (s2
, 0);
3218 XINT (result
, 0) = XINT (s2
, 0) & ~XINT (s1
, 0);
3221 XINT (result
, 0) = XINT (s1
, 0) | XINT (s2
, 0);
3226 XINT (result
, 1) = XINT (s1
, 1) & XINT (s2
, 1);
3231 /* Return EQ_ATTR_ALT expression representing union of S1 and S2. */
3234 attr_alt_union (rtx s1
, rtx s2
)
3236 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
3238 switch ((XINT (s1
, 1) << 1) | XINT (s2
, 1))
3241 XINT (result
, 0) = XINT (s1
, 0) | XINT (s2
, 0);
3244 XINT (result
, 0) = XINT (s2
, 0) & ~XINT (s1
, 0);
3247 XINT (result
, 0) = XINT (s1
, 0) & ~XINT (s2
, 0);
3250 XINT (result
, 0) = XINT (s1
, 0) & XINT (s2
, 0);
3256 XINT (result
, 1) = XINT (s1
, 1) | XINT (s2
, 1);
3260 /* Return EQ_ATTR_ALT expression representing complement of S. */
3263 attr_alt_complement (rtx s
)
3265 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
3267 XINT (result
, 0) = XINT (s
, 0);
3268 XINT (result
, 1) = 1 - XINT (s
, 1);
3273 /* Tests whether a bit B belongs to the set represented by S. */
3276 attr_alt_bit_p (rtx s
, int b
)
3278 return XINT (s
, 1) ^ ((XINT (s
, 0) >> b
) & 1);
3281 /* Return EQ_ATTR_ALT expression representing set containing elements set
3287 rtx result
= rtx_alloc (EQ_ATTR_ALT
);
3289 XINT (result
, 0) = e
;
3290 XINT (result
, 1) = 0;
3295 /* Given an expression, see if it can be simplified for a particular insn
3296 code based on the values of other attributes being tested. This can
3297 eliminate nested get_attr_... calls.
3299 Note that if an endless recursion is specified in the patterns, the
3300 optimization will loop. However, it will do so in precisely the cases where
3301 an infinite recursion loop could occur during compilation. It's better that
3305 simplify_test_exp (rtx exp
, int insn_code
, int insn_index
)
3308 struct attr_desc
*attr
;
3309 struct attr_value
*av
;
3310 struct insn_ent
*ie
;
3313 bool left_alt
, right_alt
;
3315 /* Don't re-simplify something we already simplified. */
3316 if (ATTR_IND_SIMPLIFIED_P (exp
) || ATTR_CURR_SIMPLIFIED_P (exp
))
3319 switch (GET_CODE (exp
))
3322 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3323 SIMPLIFY_ALTERNATIVE (left
);
3324 if (left
== false_rtx
)
3326 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3327 SIMPLIFY_ALTERNATIVE (right
);
3328 if (left
== false_rtx
)
3331 if (GET_CODE (left
) == EQ_ATTR_ALT
3332 && GET_CODE (right
) == EQ_ATTR_ALT
)
3334 exp
= attr_alt_intersection (left
, right
);
3335 return simplify_test_exp (exp
, insn_code
, insn_index
);
3338 /* If either side is an IOR and we have (eq_attr "alternative" ..")
3339 present on both sides, apply the distributive law since this will
3340 yield simplifications. */
3341 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
3342 && compute_alternative_mask (left
, IOR
)
3343 && compute_alternative_mask (right
, IOR
))
3345 if (GET_CODE (left
) == IOR
)
3352 newexp
= attr_rtx (IOR
,
3353 attr_rtx (AND
, left
, XEXP (right
, 0)),
3354 attr_rtx (AND
, left
, XEXP (right
, 1)));
3356 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3359 /* Try with the term on both sides. */
3360 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
3361 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3362 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
3364 if (left
== false_rtx
|| right
== false_rtx
)
3366 else if (left
== true_rtx
)
3370 else if (right
== true_rtx
)
3374 /* See if all or all but one of the insn's alternatives are specified
3375 in this tree. Optimize if so. */
3377 if (GET_CODE (left
) == NOT
)
3378 left_alt
= (GET_CODE (XEXP (left
, 0)) == EQ_ATTR
3379 && XSTR (XEXP (left
, 0), 0) == alternative_name
);
3381 left_alt
= (GET_CODE (left
) == EQ_ATTR_ALT
3384 if (GET_CODE (right
) == NOT
)
3385 right_alt
= (GET_CODE (XEXP (right
, 0)) == EQ_ATTR
3386 && XSTR (XEXP (right
, 0), 0) == alternative_name
);
3388 right_alt
= (GET_CODE (right
) == EQ_ATTR_ALT
3389 && XINT (right
, 1));
3392 && (GET_CODE (left
) == AND
3394 || GET_CODE (right
) == AND
3397 i
= compute_alternative_mask (exp
, AND
);
3398 if (i
& ~insn_alternatives
[insn_code
])
3399 fatal ("invalid alternative specified for pattern number %d",
3402 /* If all alternatives are excluded, this is false. */
3403 i
^= insn_alternatives
[insn_code
];
3406 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3408 /* If just one excluded, AND a comparison with that one to the
3409 front of the tree. The others will be eliminated by
3410 optimization. We do not want to do this if the insn has one
3411 alternative and we have tested none of them! */
3412 left
= make_alternative_compare (i
);
3413 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3414 newexp
= attr_rtx (AND
, left
, right
);
3416 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3420 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3422 newexp
= attr_rtx (AND
, left
, right
);
3423 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3428 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3429 SIMPLIFY_ALTERNATIVE (left
);
3430 if (left
== true_rtx
)
3432 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3433 SIMPLIFY_ALTERNATIVE (right
);
3434 if (right
== true_rtx
)
3437 if (GET_CODE (left
) == EQ_ATTR_ALT
3438 && GET_CODE (right
) == EQ_ATTR_ALT
)
3440 exp
= attr_alt_union (left
, right
);
3441 return simplify_test_exp (exp
, insn_code
, insn_index
);
3444 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
3445 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3446 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
3448 if (right
== true_rtx
|| left
== true_rtx
)
3450 else if (left
== false_rtx
)
3454 else if (right
== false_rtx
)
3459 /* Test for simple cases where the distributive law is useful. I.e.,
3460 convert (ior (and (x) (y))
3466 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
3467 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
3469 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
3471 left
= XEXP (left
, 0);
3473 newexp
= attr_rtx (AND
, left
, right
);
3474 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3477 /* See if all or all but one of the insn's alternatives are specified
3478 in this tree. Optimize if so. */
3480 else if (insn_code
>= 0
3481 && (GET_CODE (left
) == IOR
3482 || (GET_CODE (left
) == EQ_ATTR_ALT
3484 || (GET_CODE (left
) == EQ_ATTR
3485 && XSTR (left
, 0) == alternative_name
)
3486 || GET_CODE (right
) == IOR
3487 || (GET_CODE (right
) == EQ_ATTR_ALT
3488 && !XINT (right
, 1))
3489 || (GET_CODE (right
) == EQ_ATTR
3490 && XSTR (right
, 0) == alternative_name
)))
3492 i
= compute_alternative_mask (exp
, IOR
);
3493 if (i
& ~insn_alternatives
[insn_code
])
3494 fatal ("invalid alternative specified for pattern number %d",
3497 /* If all alternatives are included, this is true. */
3498 i
^= insn_alternatives
[insn_code
];
3501 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3503 /* If just one excluded, IOR a comparison with that one to the
3504 front of the tree. The others will be eliminated by
3505 optimization. We do not want to do this if the insn has one
3506 alternative and we have tested none of them! */
3507 left
= make_alternative_compare (i
);
3508 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3509 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
3511 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3515 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3517 newexp
= attr_rtx (IOR
, left
, right
);
3518 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3523 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
3525 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
3526 insn_code
, insn_index
);
3527 SIMPLIFY_ALTERNATIVE (left
);
3531 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3532 SIMPLIFY_ALTERNATIVE (left
);
3533 if (GET_CODE (left
) == NOT
)
3534 return XEXP (left
, 0);
3536 if (left
== false_rtx
)
3538 if (left
== true_rtx
)
3541 if (GET_CODE (left
) == EQ_ATTR_ALT
)
3543 exp
= attr_alt_complement (left
);
3544 return simplify_test_exp (exp
, insn_code
, insn_index
);
3547 /* Try to apply De`Morgan's laws. */
3548 if (GET_CODE (left
) == IOR
)
3550 newexp
= attr_rtx (AND
,
3551 attr_rtx (NOT
, XEXP (left
, 0)),
3552 attr_rtx (NOT
, XEXP (left
, 1)));
3554 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3556 else if (GET_CODE (left
) == AND
)
3558 newexp
= attr_rtx (IOR
,
3559 attr_rtx (NOT
, XEXP (left
, 0)),
3560 attr_rtx (NOT
, XEXP (left
, 1)));
3562 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3564 else if (left
!= XEXP (exp
, 0))
3566 newexp
= attr_rtx (NOT
, left
);
3571 if (current_alternative_string
)
3572 return attr_alt_bit_p (exp
, atoi (current_alternative_string
)) ? true_rtx
: false_rtx
;
3575 return XINT (exp
, 1) ? true_rtx
: false_rtx
;
3579 if (current_alternative_string
&& XSTR (exp
, 0) == alternative_name
)
3580 return (XSTR (exp
, 1) == current_alternative_string
3581 ? true_rtx
: false_rtx
);
3583 if (XSTR (exp
, 0) == alternative_name
)
3585 newexp
= mk_attr_alt (1 << atoi (XSTR (exp
, 1)));
3589 /* Look at the value for this insn code in the specified attribute.
3590 We normally can replace this comparison with the condition that
3591 would give this insn the values being tested for. */
3592 if (XSTR (exp
, 0) != alternative_name
3593 && (attr
= find_attr (&XSTR (exp
, 0), 0)) != NULL
)
3594 for (av
= attr
->first_value
; av
; av
= av
->next
)
3595 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3596 if (ie
->insn_code
== insn_code
)
3599 x
= evaluate_eq_attr (exp
, av
->value
, insn_code
, insn_index
);
3600 x
= SIMPLIFY_TEST_EXP (x
, insn_code
, insn_index
);
3601 if (attr_rtx_cost(x
) < 20)
3610 /* We have already simplified this expression. Simplifying it again
3611 won't buy anything unless we weren't given a valid insn code
3612 to process (i.e., we are canonicalizing something.). */
3613 if (insn_code
!= -2 /* Seems wrong: && current_alternative_string. */
3614 && ! ATTR_IND_SIMPLIFIED_P (newexp
))
3615 return copy_rtx_unchanging (newexp
);
3620 /* Optimize the attribute lists by seeing if we can determine conditional
3621 values from the known values of other attributes. This will save subroutine
3622 calls during the compilation. */
3625 optimize_attrs (void)
3627 struct attr_desc
*attr
;
3628 struct attr_value
*av
;
3629 struct insn_ent
*ie
;
3632 struct attr_value_list
3634 struct attr_value
*av
;
3635 struct insn_ent
*ie
;
3636 struct attr_desc
*attr
;
3637 struct attr_value_list
*next
;
3639 struct attr_value_list
**insn_code_values
;
3640 struct attr_value_list
*ivbuf
;
3641 struct attr_value_list
*iv
;
3643 /* For each insn code, make a list of all the insn_ent's for it,
3644 for all values for all attributes. */
3646 if (num_insn_ents
== 0)
3649 /* Make 2 extra elements, for "code" values -2 and -1. */
3650 insn_code_values
= xcalloc ((insn_code_number
+ 2),
3651 sizeof (struct attr_value_list
*));
3653 /* Offset the table address so we can index by -2 or -1. */
3654 insn_code_values
+= 2;
3656 iv
= ivbuf
= xmalloc (num_insn_ents
* sizeof (struct attr_value_list
));
3658 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
3659 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
3660 for (av
= attr
->first_value
; av
; av
= av
->next
)
3661 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3666 iv
->next
= insn_code_values
[ie
->insn_code
];
3667 insn_code_values
[ie
->insn_code
] = iv
;
3671 /* Sanity check on num_insn_ents. */
3672 if (iv
!= ivbuf
+ num_insn_ents
)
3675 /* Process one insn code at a time. */
3676 for (i
= -2; i
< insn_code_number
; i
++)
3678 /* Clear the ATTR_CURR_SIMPLIFIED_P flag everywhere relevant.
3679 We use it to mean "already simplified for this insn". */
3680 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3681 clear_struct_flag (iv
->av
->value
);
3683 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3685 struct obstack
*old
= rtl_obstack
;
3690 if (GET_CODE (av
->value
) != COND
)
3693 rtl_obstack
= temp_obstack
;
3695 while (GET_CODE (newexp
) == COND
)
3697 rtx newexp2
= simplify_cond (newexp
, ie
->insn_code
,
3699 if (newexp2
== newexp
)
3705 if (newexp
!= av
->value
)
3707 newexp
= attr_copy_rtx (newexp
);
3708 remove_insn_ent (av
, ie
);
3709 av
= get_attr_value (newexp
, attr
, ie
->insn_code
);
3711 insert_insn_ent (av
, ie
);
3717 free (insn_code_values
- 2);
3720 /* If EXP is a suitable expression, reorganize it by constructing an
3721 equivalent expression that is a COND with the tests being all combinations
3722 of attribute values and the values being simple constants. */
3725 simplify_by_exploding (rtx exp
)
3727 rtx list
= 0, link
, condexp
, defval
= NULL_RTX
;
3728 struct dimension
*space
;
3729 rtx
*condtest
, *condval
;
3730 int i
, j
, total
, ndim
= 0;
3731 int most_tests
, num_marks
, new_marks
;
3734 /* Locate all the EQ_ATTR expressions. */
3735 if (! find_and_mark_used_attributes (exp
, &list
, &ndim
) || ndim
== 0)
3737 unmark_used_attributes (list
, 0, 0);
3741 /* Create an attribute space from the list of used attributes. For each
3742 dimension in the attribute space, record the attribute, list of values
3743 used, and number of values used. Add members to the list of values to
3744 cover the domain of the attribute. This makes the expanded COND form
3745 order independent. */
3747 space
= xmalloc (ndim
* sizeof (struct dimension
));
3750 for (ndim
= 0; list
; ndim
++)
3752 /* Pull the first attribute value from the list and record that
3753 attribute as another dimension in the attribute space. */
3754 const char *name
= XSTR (XEXP (list
, 0), 0);
3757 space
[ndim
].attr
= find_attr (&name
, 0);
3758 XSTR (XEXP (list
, 0), 0) = name
;
3760 if (space
[ndim
].attr
== 0
3761 || space
[ndim
].attr
->is_numeric
)
3763 unmark_used_attributes (list
, space
, ndim
);
3767 /* Add all remaining attribute values that refer to this attribute. */
3768 space
[ndim
].num_values
= 0;
3769 space
[ndim
].values
= 0;
3771 for (link
= list
; link
; link
= *prev
)
3772 if (! strcmp_check (XSTR (XEXP (link
, 0), 0), name
))
3774 space
[ndim
].num_values
++;
3775 *prev
= XEXP (link
, 1);
3776 XEXP (link
, 1) = space
[ndim
].values
;
3777 space
[ndim
].values
= link
;
3780 prev
= &XEXP (link
, 1);
3782 /* Add sufficient members to the list of values to make the list
3783 mutually exclusive and record the total size of the attribute
3785 total
*= add_values_to_cover (&space
[ndim
]);
3788 /* Sort the attribute space so that the attributes go from non-constant
3789 to constant and from most values to least values. */
3790 for (i
= 0; i
< ndim
; i
++)
3791 for (j
= ndim
- 1; j
> i
; j
--)
3792 if ((space
[j
-1].attr
->is_const
&& !space
[j
].attr
->is_const
)
3793 || space
[j
-1].num_values
< space
[j
].num_values
)
3795 struct dimension tmp
;
3797 space
[j
] = space
[j
- 1];
3801 /* Establish the initial current value. */
3802 for (i
= 0; i
< ndim
; i
++)
3803 space
[i
].current_value
= space
[i
].values
;
3805 condtest
= xmalloc (total
* sizeof (rtx
));
3806 condval
= xmalloc (total
* sizeof (rtx
));
3808 /* Expand the tests and values by iterating over all values in the
3812 condtest
[i
] = test_for_current_value (space
, ndim
);
3813 condval
[i
] = simplify_with_current_value (exp
, space
, ndim
);
3814 if (! increment_current_value (space
, ndim
))
3820 /* We are now finished with the original expression. */
3821 unmark_used_attributes (0, space
, ndim
);
3824 /* Find the most used constant value and make that the default. */
3826 for (i
= num_marks
= 0; i
< total
; i
++)
3827 if (GET_CODE (condval
[i
]) == CONST_STRING
3828 && ! ATTR_EQ_ATTR_P (condval
[i
]))
3830 /* Mark the unmarked constant value and count how many are marked. */
3831 ATTR_EQ_ATTR_P (condval
[i
]) = 1;
3832 for (j
= new_marks
= 0; j
< total
; j
++)
3833 if (GET_CODE (condval
[j
]) == CONST_STRING
3834 && ATTR_EQ_ATTR_P (condval
[j
]))
3836 if (new_marks
- num_marks
> most_tests
)
3838 most_tests
= new_marks
- num_marks
;
3839 defval
= condval
[i
];
3841 num_marks
= new_marks
;
3843 /* Clear all the marks. */
3844 for (i
= 0; i
< total
; i
++)
3845 ATTR_EQ_ATTR_P (condval
[i
]) = 0;
3847 /* Give up if nothing is constant. */
3851 /* If all values are the default, use that. */
3852 else if (total
== most_tests
)
3855 /* Make a COND with the most common constant value the default. (A more
3856 complex method where tests with the same value were combined didn't
3857 seem to improve things.) */
3860 condexp
= rtx_alloc (COND
);
3861 XVEC (condexp
, 0) = rtvec_alloc ((total
- most_tests
) * 2);
3862 XEXP (condexp
, 1) = defval
;
3863 for (i
= j
= 0; i
< total
; i
++)
3864 if (condval
[i
] != defval
)
3866 XVECEXP (condexp
, 0, 2 * j
) = condtest
[i
];
3867 XVECEXP (condexp
, 0, 2 * j
+ 1) = condval
[i
];
3877 /* Set the ATTR_EQ_ATTR_P flag for all EQ_ATTR expressions in EXP and
3878 verify that EXP can be simplified to a constant term if all the EQ_ATTR
3879 tests have known value. */
3882 find_and_mark_used_attributes (rtx exp
, rtx
*terms
, int *nterms
)
3886 switch (GET_CODE (exp
))
3889 if (! ATTR_EQ_ATTR_P (exp
))
3891 rtx link
= rtx_alloc (EXPR_LIST
);
3892 XEXP (link
, 0) = exp
;
3893 XEXP (link
, 1) = *terms
;
3896 ATTR_EQ_ATTR_P (exp
) = 1;
3905 if (! find_and_mark_used_attributes (XEXP (exp
, 2), terms
, nterms
))
3909 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3912 if (! find_and_mark_used_attributes (XEXP (exp
, 0), terms
, nterms
))
3917 for (i
= 0; i
< XVECLEN (exp
, 0); i
++)
3918 if (! find_and_mark_used_attributes (XVECEXP (exp
, 0, i
), terms
, nterms
))
3920 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3929 /* Clear the ATTR_EQ_ATTR_P flag in all EQ_ATTR expressions on LIST and
3930 in the values of the NDIM-dimensional attribute space SPACE. */
3933 unmark_used_attributes (rtx list
, struct dimension
*space
, int ndim
)
3938 for (i
= 0; i
< ndim
; i
++)
3939 unmark_used_attributes (space
[i
].values
, 0, 0);
3941 for (link
= list
; link
; link
= XEXP (link
, 1))
3943 exp
= XEXP (link
, 0);
3944 if (GET_CODE (exp
) == EQ_ATTR
)
3945 ATTR_EQ_ATTR_P (exp
) = 0;
3949 /* Update the attribute dimension DIM so that all values of the attribute
3950 are tested. Return the updated number of values. */
3953 add_values_to_cover (struct dimension
*dim
)
3955 struct attr_value
*av
;
3956 rtx exp
, link
, *prev
;
3959 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3960 if (GET_CODE (av
->value
) == CONST_STRING
)
3963 if (nalt
< dim
->num_values
)
3965 else if (nalt
== dim
->num_values
)
3968 else if (nalt
* 2 < dim
->num_values
* 3)
3970 /* Most all the values of the attribute are used, so add all the unused
3972 prev
= &dim
->values
;
3973 for (link
= dim
->values
; link
; link
= *prev
)
3974 prev
= &XEXP (link
, 1);
3976 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3977 if (GET_CODE (av
->value
) == CONST_STRING
)
3979 exp
= attr_eq (dim
->attr
->name
, XSTR (av
->value
, 0));
3980 if (ATTR_EQ_ATTR_P (exp
))
3983 link
= rtx_alloc (EXPR_LIST
);
3984 XEXP (link
, 0) = exp
;
3987 prev
= &XEXP (link
, 1);
3989 dim
->num_values
= nalt
;
3993 rtx orexp
= false_rtx
;
3995 /* Very few values are used, so compute a mutually exclusive
3996 expression. (We could do this for numeric values if that becomes
3998 prev
= &dim
->values
;
3999 for (link
= dim
->values
; link
; link
= *prev
)
4001 orexp
= insert_right_side (IOR
, orexp
, XEXP (link
, 0), -2, -2);
4002 prev
= &XEXP (link
, 1);
4004 link
= rtx_alloc (EXPR_LIST
);
4005 XEXP (link
, 0) = attr_rtx (NOT
, orexp
);
4010 return dim
->num_values
;
4013 /* Increment the current value for the NDIM-dimensional attribute space SPACE
4014 and return FALSE if the increment overflowed. */
4017 increment_current_value (struct dimension
*space
, int ndim
)
4021 for (i
= ndim
- 1; i
>= 0; i
--)
4023 if ((space
[i
].current_value
= XEXP (space
[i
].current_value
, 1)) == 0)
4024 space
[i
].current_value
= space
[i
].values
;
4031 /* Construct an expression corresponding to the current value for the
4032 NDIM-dimensional attribute space SPACE. */
4035 test_for_current_value (struct dimension
*space
, int ndim
)
4040 for (i
= 0; i
< ndim
; i
++)
4041 exp
= insert_right_side (AND
, exp
, XEXP (space
[i
].current_value
, 0),
4047 /* Given the current value of the NDIM-dimensional attribute space SPACE,
4048 set the corresponding EQ_ATTR expressions to that value and reduce
4049 the expression EXP as much as possible. On input [and output], all
4050 known EQ_ATTR expressions are set to FALSE. */
4053 simplify_with_current_value (rtx exp
, struct dimension
*space
, int ndim
)
4058 /* Mark each current value as TRUE. */
4059 for (i
= 0; i
< ndim
; i
++)
4061 x
= XEXP (space
[i
].current_value
, 0);
4062 if (GET_CODE (x
) == EQ_ATTR
)
4063 ATTR_EQ_ATTR_P (x
) = 0;
4066 exp
= simplify_with_current_value_aux (exp
);
4068 /* Change each current value back to FALSE. */
4069 for (i
= 0; i
< ndim
; i
++)
4071 x
= XEXP (space
[i
].current_value
, 0);
4072 if (GET_CODE (x
) == EQ_ATTR
)
4073 ATTR_EQ_ATTR_P (x
) = 1;
4079 /* Reduce the expression EXP based on the ATTR_EQ_ATTR_P settings of
4080 all EQ_ATTR expressions. */
4083 simplify_with_current_value_aux (rtx exp
)
4088 switch (GET_CODE (exp
))
4091 if (ATTR_EQ_ATTR_P (exp
))
4100 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
4101 if (cond
== true_rtx
)
4102 return simplify_with_current_value_aux (XEXP (exp
, 1));
4103 else if (cond
== false_rtx
)
4104 return simplify_with_current_value_aux (XEXP (exp
, 2));
4106 return attr_rtx (IF_THEN_ELSE
, cond
,
4107 simplify_with_current_value_aux (XEXP (exp
, 1)),
4108 simplify_with_current_value_aux (XEXP (exp
, 2)));
4111 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
4112 if (cond
== true_rtx
)
4114 else if (cond
== false_rtx
)
4115 return simplify_with_current_value_aux (XEXP (exp
, 0));
4117 return attr_rtx (IOR
, cond
,
4118 simplify_with_current_value_aux (XEXP (exp
, 0)));
4121 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
4122 if (cond
== true_rtx
)
4123 return simplify_with_current_value_aux (XEXP (exp
, 0));
4124 else if (cond
== false_rtx
)
4127 return attr_rtx (AND
, cond
,
4128 simplify_with_current_value_aux (XEXP (exp
, 0)));
4131 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
4132 if (cond
== true_rtx
)
4134 else if (cond
== false_rtx
)
4137 return attr_rtx (NOT
, cond
);
4140 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4142 cond
= simplify_with_current_value_aux (XVECEXP (exp
, 0, i
));
4143 if (cond
== true_rtx
)
4144 return simplify_with_current_value_aux (XVECEXP (exp
, 0, i
+ 1));
4145 else if (cond
== false_rtx
)
4148 abort (); /* With all EQ_ATTR's of known value, a case should
4149 have been selected. */
4151 return simplify_with_current_value_aux (XEXP (exp
, 1));
4158 /* Clear the ATTR_CURR_SIMPLIFIED_P flag in EXP and its subexpressions. */
4161 clear_struct_flag (rtx x
)
4168 ATTR_CURR_SIMPLIFIED_P (x
) = 0;
4169 if (ATTR_IND_SIMPLIFIED_P (x
))
4172 code
= GET_CODE (x
);
4193 /* Compare the elements. If any pair of corresponding elements
4194 fail to match, return 0 for the whole things. */
4196 fmt
= GET_RTX_FORMAT (code
);
4197 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4203 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4204 clear_struct_flag (XVECEXP (x
, i
, j
));
4208 clear_struct_flag (XEXP (x
, i
));
4214 /* Create table entries for DEFINE_ATTR. */
4217 gen_attr (rtx exp
, int lineno
)
4219 struct attr_desc
*attr
;
4220 struct attr_value
*av
;
4221 const char *name_ptr
;
4224 /* Make a new attribute structure. Check for duplicate by looking at
4225 attr->default_val, since it is initialized by this routine. */
4226 attr
= find_attr (&XSTR (exp
, 0), 1);
4227 if (attr
->default_val
)
4229 message_with_line (lineno
, "duplicate definition for attribute %s",
4231 message_with_line (attr
->lineno
, "previous definition");
4235 attr
->lineno
= lineno
;
4237 if (*XSTR (exp
, 1) == '\0')
4238 attr
->is_numeric
= 1;
4241 name_ptr
= XSTR (exp
, 1);
4242 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
4244 av
= oballoc (sizeof (struct attr_value
));
4245 av
->value
= attr_rtx (CONST_STRING
, p
);
4246 av
->next
= attr
->first_value
;
4247 attr
->first_value
= av
;
4248 av
->first_insn
= NULL
;
4250 av
->has_asm_insn
= 0;
4254 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
4257 if (attr
->is_numeric
)
4259 message_with_line (lineno
,
4260 "constant attributes may not take numeric values");
4264 /* Get rid of the CONST node. It is allowed only at top-level. */
4265 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
4268 if (! strcmp_check (attr
->name
, length_str
) && ! attr
->is_numeric
)
4270 message_with_line (lineno
,
4271 "`length' attribute must take numeric values");
4275 /* Set up the default value. */
4276 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
4277 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
4280 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
4281 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
4282 number of alternatives as this should be checked elsewhere. */
4285 count_alternatives (rtx exp
)
4290 if (GET_CODE (exp
) == MATCH_OPERAND
)
4291 return n_comma_elts (XSTR (exp
, 2));
4293 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4294 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4299 n
= count_alternatives (XEXP (exp
, i
));
4306 if (XVEC (exp
, i
) != NULL
)
4307 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4309 n
= count_alternatives (XVECEXP (exp
, i
, j
));
4318 /* Returns nonzero if the given expression contains an EQ_ATTR with the
4319 `alternative' attribute. */
4322 compares_alternatives_p (rtx exp
)
4327 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
4330 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4331 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4336 if (compares_alternatives_p (XEXP (exp
, i
)))
4341 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4342 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
4350 /* Returns nonzero is INNER is contained in EXP. */
4353 contained_in_p (rtx inner
, rtx exp
)
4358 if (rtx_equal_p (inner
, exp
))
4361 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4362 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4367 if (contained_in_p (inner
, XEXP (exp
, i
)))
4372 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4373 if (contained_in_p (inner
, XVECEXP (exp
, i
, j
)))
4381 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
4384 gen_insn (rtx exp
, int lineno
)
4386 struct insn_def
*id
;
4388 id
= oballoc (sizeof (struct insn_def
));
4392 id
->lineno
= lineno
;
4394 switch (GET_CODE (exp
))
4397 id
->insn_code
= insn_code_number
;
4398 id
->insn_index
= insn_index_number
;
4399 id
->num_alternatives
= count_alternatives (exp
);
4400 if (id
->num_alternatives
== 0)
4401 id
->num_alternatives
= 1;
4405 case DEFINE_PEEPHOLE
:
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_ASM_ATTRIBUTES
:
4416 id
->insn_index
= -1;
4417 id
->num_alternatives
= 1;
4419 got_define_asm_attributes
= 1;
4427 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
4428 true or annul false is specified, and make a `struct delay_desc'. */
4431 gen_delay (rtx def
, int lineno
)
4433 struct delay_desc
*delay
;
4436 if (XVECLEN (def
, 1) % 3 != 0)
4438 message_with_line (lineno
,
4439 "number of elements in DEFINE_DELAY must be multiple of three");
4444 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
4446 if (XVECEXP (def
, 1, i
+ 1))
4447 have_annul_true
= 1;
4448 if (XVECEXP (def
, 1, i
+ 2))
4449 have_annul_false
= 1;
4452 delay
= oballoc (sizeof (struct delay_desc
));
4454 delay
->num
= ++num_delays
;
4455 delay
->next
= delays
;
4456 delay
->lineno
= lineno
;
4460 /* Process a DEFINE_FUNCTION_UNIT.
4462 This gives information about a function unit contained in the CPU.
4463 We fill in a `struct function_unit_op' and a `struct function_unit'
4464 with information used later by `expand_unit'. */
4467 gen_unit (rtx def
, int lineno
)
4469 struct function_unit
*unit
;
4470 struct function_unit_op
*op
;
4471 const char *name
= XSTR (def
, 0);
4472 int multiplicity
= XINT (def
, 1);
4473 int simultaneity
= XINT (def
, 2);
4474 rtx condexp
= XEXP (def
, 3);
4475 int ready_cost
= MAX (XINT (def
, 4), 1);
4476 int issue_delay
= MAX (XINT (def
, 5), 1);
4478 /* See if we have already seen this function unit. If so, check that
4479 the multiplicity and simultaneity values are the same. If not, make
4480 a structure for this function unit. */
4481 for (unit
= units
; unit
; unit
= unit
->next
)
4482 if (! strcmp (unit
->name
, name
))
4484 if (unit
->multiplicity
!= multiplicity
4485 || unit
->simultaneity
!= simultaneity
)
4487 message_with_line (lineno
,
4488 "differing specifications given for function unit %s",
4490 message_with_line (unit
->first_lineno
, "previous definition");
4499 unit
= oballoc (sizeof (struct function_unit
));
4501 unit
->multiplicity
= multiplicity
;
4502 unit
->simultaneity
= simultaneity
;
4503 unit
->issue_delay
.min
= unit
->issue_delay
.max
= issue_delay
;
4504 unit
->num
= num_units
++;
4505 unit
->num_opclasses
= 0;
4506 unit
->condexp
= false_rtx
;
4509 unit
->first_lineno
= lineno
;
4513 XSTR (def
, 0) = unit
->name
;
4515 /* Make a new operation class structure entry and initialize it. */
4516 op
= oballoc (sizeof (struct function_unit_op
));
4517 op
->condexp
= condexp
;
4518 op
->num
= unit
->num_opclasses
++;
4519 op
->ready
= ready_cost
;
4520 op
->issue_delay
= issue_delay
;
4521 op
->next
= unit
->ops
;
4522 op
->lineno
= lineno
;
4524 num_unit_opclasses
++;
4526 /* Set our issue expression based on whether or not an optional conflict
4527 vector was specified. */
4530 /* Compute the IOR of all the specified expressions. */
4531 rtx orexp
= false_rtx
;
4534 for (i
= 0; i
< XVECLEN (def
, 6); i
++)
4535 orexp
= insert_right_side (IOR
, orexp
, XVECEXP (def
, 6, i
), -2, -2);
4537 op
->conflict_exp
= orexp
;
4538 extend_range (&unit
->issue_delay
, 1, issue_delay
);
4542 op
->conflict_exp
= true_rtx
;
4543 extend_range (&unit
->issue_delay
, issue_delay
, issue_delay
);
4546 /* Merge our conditional into that of the function unit so we can determine
4547 which insns are used by the function unit. */
4548 unit
->condexp
= insert_right_side (IOR
, unit
->condexp
, op
->condexp
, -2, -2);
4551 /* Given a piece of RTX, print a C expression to test its truth value.
4552 We use AND and IOR both for logical and bit-wise operations, so
4553 interpret them as logical unless they are inside a comparison expression.
4554 The first bit of FLAGS will be nonzero in that case.
4556 Set the second bit of FLAGS to make references to attribute values use
4557 a cached local variable instead of calling a function. */
4560 write_test_expr (rtx exp
, int flags
)
4562 int comparison_operator
= 0;
4564 struct attr_desc
*attr
;
4566 /* In order not to worry about operator precedence, surround our part of
4567 the expression with parentheses. */
4570 code
= GET_CODE (exp
);
4573 /* Binary operators. */
4575 case GE
: case GT
: case GEU
: case GTU
:
4576 case LE
: case LT
: case LEU
: case LTU
:
4577 comparison_operator
= 1;
4579 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
4580 case AND
: case IOR
: case XOR
:
4581 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
4582 write_test_expr (XEXP (exp
, 0), flags
| comparison_operator
);
4598 printf (" >= (unsigned) ");
4601 printf (" > (unsigned) ");
4610 printf (" <= (unsigned) ");
4613 printf (" < (unsigned) ");
4656 write_test_expr (XEXP (exp
, 1), flags
| comparison_operator
);
4660 /* Special-case (not (eq_attrq "alternative" "x")) */
4661 if (! (flags
& 1) && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
4662 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
4664 printf ("which_alternative != %s", XSTR (XEXP (exp
, 0), 1));
4668 /* Otherwise, fall through to normal unary operator. */
4670 /* Unary operators. */
4690 write_test_expr (XEXP (exp
, 0), flags
);
4695 int set
= XINT (exp
, 0), bit
= 0;
4698 fatal ("EQ_ATTR_ALT not valid inside comparison");
4701 fatal ("Empty EQ_ATTR_ALT should be optimized out");
4703 if (!(set
& (set
- 1)))
4705 if (!(set
& 0xffff))
4728 printf ("which_alternative %s= %d",
4729 XINT (exp
, 1) ? "!" : "=", bit
);
4733 printf ("%s((1 << which_alternative) & 0x%x)",
4734 XINT (exp
, 1) ? "!" : "", set
);
4739 /* Comparison test of an attribute with a value. Most of these will
4740 have been removed by optimization. Handle "alternative"
4741 specially and give error if EQ_ATTR present inside a comparison. */
4744 fatal ("EQ_ATTR not valid inside comparison");
4746 if (XSTR (exp
, 0) == alternative_name
)
4748 printf ("which_alternative == %s", XSTR (exp
, 1));
4752 attr
= find_attr (&XSTR (exp
, 0), 0);
4756 /* Now is the time to expand the value of a constant attribute. */
4759 write_test_expr (evaluate_eq_attr (exp
, attr
->default_val
->value
,
4766 printf ("attr_%s", attr
->name
);
4768 printf ("get_attr_%s (insn)", attr
->name
);
4770 write_attr_valueq (attr
, XSTR (exp
, 1));
4774 /* Comparison test of flags for define_delays. */
4777 fatal ("ATTR_FLAG not valid inside comparison");
4778 printf ("(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
4781 /* See if an operand matches a predicate. */
4783 /* If only a mode is given, just ensure the mode matches the operand.
4784 If neither a mode nor predicate is given, error. */
4785 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
4787 if (GET_MODE (exp
) == VOIDmode
)
4788 fatal ("null MATCH_OPERAND specified as test");
4790 printf ("GET_MODE (operands[%d]) == %smode",
4791 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4794 printf ("%s (operands[%d], %smode)",
4795 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4799 printf ("%s (insn)", XSTR (exp
, 0));
4802 /* Constant integer. */
4804 printf (HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
4807 /* A random C expression. */
4809 printf ("%s", XSTR (exp
, 0));
4812 /* The address of the branch target. */
4814 printf ("INSN_ADDRESSES_SET_P () ? INSN_ADDRESSES (INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])) : 0",
4815 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
4819 /* The address of the current insn. We implement this actually as the
4820 address of the current insn for backward branches, but the last
4821 address of the next insn for forward branches, and both with
4822 adjustments that account for the worst-case possible stretching of
4823 intervening alignments between this insn and its destination. */
4824 printf ("insn_current_reference_address (insn)");
4828 printf ("%s", XSTR (exp
, 0));
4832 write_test_expr (XEXP (exp
, 0), flags
& 2);
4834 write_test_expr (XEXP (exp
, 1), flags
| 1);
4836 write_test_expr (XEXP (exp
, 2), flags
| 1);
4840 fatal ("bad RTX code `%s' in attribute calculation\n",
4841 GET_RTX_NAME (code
));
4847 /* Given an attribute value, return the maximum CONST_STRING argument
4848 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
4851 max_attr_value (rtx exp
, int *unknownp
)
4856 switch (GET_CODE (exp
))
4859 current_max
= atoi (XSTR (exp
, 0));
4863 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4864 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4866 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4867 if (n
> current_max
)
4873 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4874 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
4875 if (n
> current_max
)
4881 current_max
= INT_MAX
;
4888 /* Given an attribute value, return the result of ORing together all
4889 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
4890 if the numeric value is not known. */
4893 or_attr_value (rtx exp
, int *unknownp
)
4898 switch (GET_CODE (exp
))
4901 current_or
= atoi (XSTR (exp
, 0));
4905 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4906 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4907 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4911 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4912 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
4924 /* Scan an attribute value, possibly a conditional, and record what actions
4925 will be required to do any conditional tests in it.
4928 `must_extract' if we need to extract the insn operands
4929 `must_constrain' if we must compute `which_alternative'
4930 `address_used' if an address expression was used
4931 `length_used' if an (eq_attr "length" ...) was used
4935 walk_attr_value (rtx exp
)
4944 code
= GET_CODE (exp
);
4948 if (! ATTR_IND_SIMPLIFIED_P (exp
))
4949 /* Since this is an arbitrary expression, it can look at anything.
4950 However, constant expressions do not depend on any particular
4952 must_extract
= must_constrain
= 1;
4960 must_extract
= must_constrain
= 1;
4964 if (XSTR (exp
, 0) == alternative_name
)
4965 must_extract
= must_constrain
= 1;
4966 else if (strcmp_check (XSTR (exp
, 0), length_str
) == 0)
4986 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
4991 walk_attr_value (XEXP (exp
, i
));
4995 if (XVEC (exp
, i
) != NULL
)
4996 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4997 walk_attr_value (XVECEXP (exp
, i
, j
));
5002 /* Write out a function to obtain the attribute for a given INSN. */
5005 write_attr_get (struct attr_desc
*attr
)
5007 struct attr_value
*av
, *common_av
;
5009 /* Find the most used attribute value. Handle that as the `default' of the
5010 switch we will generate. */
5011 common_av
= find_most_used (attr
);
5013 /* Write out start of function, then all values with explicit `case' lines,
5014 then a `default', then the value with the most uses. */
5017 if (!attr
->is_numeric
)
5018 printf ("enum attr_%s\n", attr
->name
);
5019 else if (attr
->unsigned_p
)
5020 printf ("unsigned int\n");
5024 /* If the attribute name starts with a star, the remainder is the name of
5025 the subroutine to use, instead of `get_attr_...'. */
5026 if (attr
->name
[0] == '*')
5027 printf ("%s (rtx insn ATTRIBUTE_UNUSED)\n", &attr
->name
[1]);
5028 else if (attr
->is_const
== 0)
5029 printf ("get_attr_%s (rtx insn ATTRIBUTE_UNUSED)\n", attr
->name
);
5032 printf ("get_attr_%s (void)\n", attr
->name
);
5035 for (av
= attr
->first_value
; av
; av
= av
->next
)
5036 if (av
->num_insns
!= 0)
5037 write_attr_set (attr
, 2, av
->value
, "return", ";",
5038 true_rtx
, av
->first_insn
->insn_code
,
5039 av
->first_insn
->insn_index
);
5047 if (GET_CODE (common_av
->value
) == FFS
)
5049 rtx p
= XEXP (common_av
->value
, 0);
5051 /* No need to emit code to abort if the insn is unrecognized; the
5052 other get_attr_foo functions will do that when we call them. */
5054 write_toplevel_expr (p
);
5056 printf ("\n if (accum && accum == (accum & -accum))\n");
5058 printf (" int i;\n");
5059 printf (" for (i = 0; accum >>= 1; ++i) continue;\n");
5060 printf (" accum = i;\n");
5061 printf (" }\n else\n");
5062 printf (" accum = ~accum;\n");
5063 printf (" return accum;\n}\n\n");
5067 printf (" switch (recog_memoized (insn))\n");
5070 for (av
= attr
->first_value
; av
; av
= av
->next
)
5071 if (av
!= common_av
)
5072 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5074 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5075 printf (" }\n}\n\n");
5079 /* Given an AND tree of known true terms (because we are inside an `if' with
5080 that as the condition or are in an `else' clause) and an expression,
5081 replace any known true terms with TRUE. Use `simplify_and_tree' to do
5082 the bulk of the work. */
5085 eliminate_known_true (rtx known_true
, rtx exp
, int insn_code
, int insn_index
)
5089 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
5091 if (GET_CODE (known_true
) == AND
)
5093 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
5094 insn_code
, insn_index
);
5095 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
5096 insn_code
, insn_index
);
5101 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
5107 /* Write out a series of tests and assignment statements to perform tests and
5108 sets of an attribute value. We are passed an indentation amount and prefix
5109 and suffix strings to write around each attribute value (e.g., "return"
5113 write_attr_set (struct attr_desc
*attr
, int indent
, rtx value
,
5114 const char *prefix
, const char *suffix
, rtx known_true
,
5115 int insn_code
, int insn_index
)
5117 if (GET_CODE (value
) == COND
)
5119 /* Assume the default value will be the default of the COND unless we
5120 find an always true expression. */
5121 rtx default_val
= XEXP (value
, 1);
5122 rtx our_known_true
= known_true
;
5127 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
5132 testexp
= eliminate_known_true (our_known_true
,
5133 XVECEXP (value
, 0, i
),
5134 insn_code
, insn_index
);
5135 newexp
= attr_rtx (NOT
, testexp
);
5136 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
5137 insn_code
, insn_index
);
5139 /* If the test expression is always true or if the next `known_true'
5140 expression is always false, this is the last case, so break
5141 out and let this value be the `else' case. */
5142 if (testexp
== true_rtx
|| newexp
== false_rtx
)
5144 default_val
= XVECEXP (value
, 0, i
+ 1);
5148 /* Compute the expression to pass to our recursive call as being
5150 inner_true
= insert_right_side (AND
, our_known_true
,
5151 testexp
, insn_code
, insn_index
);
5153 /* If this is always false, skip it. */
5154 if (inner_true
== false_rtx
)
5157 write_indent (indent
);
5158 printf ("%sif ", first_if
? "" : "else ");
5160 write_test_expr (testexp
, 0);
5162 write_indent (indent
+ 2);
5165 write_attr_set (attr
, indent
+ 4,
5166 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
5167 inner_true
, insn_code
, insn_index
);
5168 write_indent (indent
+ 2);
5170 our_known_true
= newexp
;
5175 write_indent (indent
);
5177 write_indent (indent
+ 2);
5181 write_attr_set (attr
, first_if
? indent
: indent
+ 4, default_val
,
5182 prefix
, suffix
, our_known_true
, insn_code
, insn_index
);
5186 write_indent (indent
+ 2);
5192 write_indent (indent
);
5193 printf ("%s ", prefix
);
5194 write_attr_value (attr
, value
);
5195 printf ("%s\n", suffix
);
5199 /* Write out the computation for one attribute value. */
5202 write_attr_case (struct attr_desc
*attr
, struct attr_value
*av
,
5203 int write_case_lines
, const char *prefix
, const char *suffix
,
5204 int indent
, rtx known_true
)
5206 struct insn_ent
*ie
;
5208 if (av
->num_insns
== 0)
5211 if (av
->has_asm_insn
)
5213 write_indent (indent
);
5214 printf ("case -1:\n");
5215 write_indent (indent
+ 2);
5216 printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
5217 write_indent (indent
+ 2);
5218 printf (" && asm_noperands (PATTERN (insn)) < 0)\n");
5219 write_indent (indent
+ 2);
5220 printf (" fatal_insn_not_found (insn);\n");
5223 if (write_case_lines
)
5225 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5226 if (ie
->insn_code
!= -1)
5228 write_indent (indent
);
5229 printf ("case %d:\n", ie
->insn_code
);
5234 write_indent (indent
);
5235 printf ("default:\n");
5238 /* See what we have to do to output this value. */
5239 must_extract
= must_constrain
= address_used
= 0;
5240 walk_attr_value (av
->value
);
5244 write_indent (indent
+ 2);
5245 printf ("extract_constrain_insn_cached (insn);\n");
5247 else if (must_extract
)
5249 write_indent (indent
+ 2);
5250 printf ("extract_insn_cached (insn);\n");
5253 write_attr_set (attr
, indent
+ 2, av
->value
, prefix
, suffix
,
5254 known_true
, av
->first_insn
->insn_code
,
5255 av
->first_insn
->insn_index
);
5257 if (strncmp (prefix
, "return", 6))
5259 write_indent (indent
+ 2);
5260 printf ("break;\n");
5265 /* Search for uses of non-const attributes and write code to cache them. */
5268 write_expr_attr_cache (rtx p
, struct attr_desc
*attr
)
5273 if (GET_CODE (p
) == EQ_ATTR
)
5275 if (XSTR (p
, 0) != attr
->name
)
5278 if (!attr
->is_numeric
)
5279 printf (" enum attr_%s ", attr
->name
);
5280 else if (attr
->unsigned_p
)
5281 printf (" unsigned int ");
5285 printf ("attr_%s = get_attr_%s (insn);\n", attr
->name
, attr
->name
);
5289 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
5290 ie
= GET_RTX_LENGTH (GET_CODE (p
));
5291 for (i
= 0; i
< ie
; i
++)
5296 if (write_expr_attr_cache (XEXP (p
, i
), attr
))
5301 je
= XVECLEN (p
, i
);
5302 for (j
= 0; j
< je
; ++j
)
5303 if (write_expr_attr_cache (XVECEXP (p
, i
, j
), attr
))
5312 /* Evaluate an expression at top level. A front end to write_test_expr,
5313 in which we cache attribute values and break up excessively large
5314 expressions to cater to older compilers. */
5317 write_toplevel_expr (rtx 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 (const char *prefix
, int num
, const char *suffix
)
5351 struct function_unit
*unit
;
5353 for (unit
= units
; unit
; unit
= unit
->next
)
5354 if (unit
->num
== num
)
5356 printf ("%s%s%s", prefix
, unit
->name
, suffix
);
5360 printf ("%s<unknown>%s", prefix
, suffix
);
5364 write_attr_valueq (struct attr_desc
*attr
, const char *s
)
5366 if (attr
->is_numeric
)
5372 /* Make the blockage range values and function units used values easier
5374 if (attr
->func_units_p
)
5377 printf (" /* units: none */");
5379 write_unit_name (" /* units: ", num
, " */");
5383 const char *sep
= " /* units: ";
5384 for (i
= 0, num
= ~num
; num
; i
++, num
>>= 1)
5387 write_unit_name (sep
, i
, (num
== 1) ? " */" : "");
5393 else if (attr
->blockage_p
)
5394 printf (" /* min %d, max %d */", num
>> (HOST_BITS_PER_INT
/ 2),
5395 num
& ((1 << (HOST_BITS_PER_INT
/ 2)) - 1));
5397 else if (num
> 9 || num
< 0)
5398 printf (" /* 0x%x */", num
);
5402 write_upcase (attr
->name
);
5409 write_attr_value (struct attr_desc
*attr
, rtx value
)
5413 switch (GET_CODE (value
))
5416 write_attr_valueq (attr
, XSTR (value
, 0));
5420 printf (HOST_WIDE_INT_PRINT_DEC
, INTVAL (value
));
5424 fputs (XSTR (value
, 0), stdout
);
5429 struct attr_desc
*attr2
= find_attr (&XSTR (value
, 0), 0);
5430 printf ("get_attr_%s (%s)", attr2
->name
,
5431 (attr2
->is_const
? "" : "insn"));
5452 write_attr_value (attr
, XEXP (value
, 0));
5456 write_attr_value (attr
, XEXP (value
, 1));
5465 write_upcase (const char *str
)
5469 /* The argument of TOUPPER should not have side effects. */
5470 putchar (TOUPPER(*str
));
5476 write_indent (int indent
)
5478 for (; indent
> 8; indent
-= 8)
5481 for (; indent
; indent
--)
5485 /* Write a subroutine that is given an insn that requires a delay slot, a
5486 delay slot ordinal, and a candidate insn. It returns nonzero if the
5487 candidate can be placed in the specified delay slot of the insn.
5489 We can write as many as three subroutines. `eligible_for_delay'
5490 handles normal delay slots, `eligible_for_annul_true' indicates that
5491 the specified insn can be annulled if the branch is true, and likewise
5492 for `eligible_for_annul_false'.
5494 KIND is a string distinguishing these three cases ("delay", "annul_true",
5495 or "annul_false"). */
5498 write_eligible_delay (const char *kind
)
5500 struct delay_desc
*delay
;
5504 struct attr_desc
*attr
;
5505 struct attr_value
*av
, *common_av
;
5508 /* Compute the maximum number of delay slots required. We use the delay
5509 ordinal times this number plus one, plus the slot number as an index into
5510 the appropriate predicate to test. */
5512 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
5513 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
5514 max_slots
= XVECLEN (delay
->def
, 1) / 3;
5516 /* Write function prelude. */
5519 printf ("eligible_for_%s (rtx delay_insn ATTRIBUTE_UNUSED, int slot, rtx candidate_insn, int flags ATTRIBUTE_UNUSED)\n",
5522 printf (" rtx insn;\n");
5524 printf (" if (slot >= %d)\n", max_slots
);
5525 printf (" abort ();\n");
5528 /* If more than one delay type, find out which type the delay insn is. */
5532 attr
= find_attr (&delay_type_str
, 0);
5535 common_av
= find_most_used (attr
);
5537 printf (" insn = delay_insn;\n");
5538 printf (" switch (recog_memoized (insn))\n");
5541 sprintf (str
, " * %d;\n break;", max_slots
);
5542 for (av
= attr
->first_value
; av
; av
= av
->next
)
5543 if (av
!= common_av
)
5544 write_attr_case (attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
5546 write_attr_case (attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
5549 /* Ensure matched. Otherwise, shouldn't have been called. */
5550 printf (" if (slot < %d)\n", max_slots
);
5551 printf (" abort ();\n\n");
5554 /* If just one type of delay slot, write simple switch. */
5555 if (num_delays
== 1 && max_slots
== 1)
5557 printf (" insn = candidate_insn;\n");
5558 printf (" switch (recog_memoized (insn))\n");
5561 attr
= find_attr (&delay_1_0_str
, 0);
5564 common_av
= find_most_used (attr
);
5566 for (av
= attr
->first_value
; av
; av
= av
->next
)
5567 if (av
!= common_av
)
5568 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5570 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5576 /* Write a nested CASE. The first indicates which condition we need to
5577 test, and the inner CASE tests the condition. */
5578 printf (" insn = candidate_insn;\n");
5579 printf (" switch (slot)\n");
5582 for (delay
= delays
; delay
; delay
= delay
->next
)
5583 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
5585 printf (" case %d:\n",
5586 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
5587 printf (" switch (recog_memoized (insn))\n");
5590 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
5592 attr
= find_attr (&pstr
, 0);
5595 common_av
= find_most_used (attr
);
5597 for (av
= attr
->first_value
; av
; av
= av
->next
)
5598 if (av
!= common_av
)
5599 write_attr_case (attr
, av
, 1, "return", ";", 8, true_rtx
);
5601 write_attr_case (attr
, common_av
, 0, "return", ";", 8, true_rtx
);
5605 printf (" default:\n");
5606 printf (" abort ();\n");
5613 /* Write routines to compute conflict cost for function units. Then write a
5614 table describing the available function units. */
5617 write_function_unit_info (void)
5619 struct function_unit
*unit
;
5622 /* Write out conflict routines for function units. Don't bother writing
5623 one if there is only one issue delay value. */
5625 for (unit
= units
; unit
; unit
= unit
->next
)
5627 if (unit
->needs_blockage_function
)
5628 write_complex_function (unit
, "blockage", "block");
5630 /* If the minimum and maximum conflict costs are the same, there
5631 is only one value, so we don't need a function. */
5632 if (! unit
->needs_conflict_function
)
5634 unit
->default_cost
= make_numeric_value (unit
->issue_delay
.max
);
5638 /* The function first computes the case from the candidate insn. */
5639 unit
->default_cost
= make_numeric_value (0);
5640 write_complex_function (unit
, "conflict_cost", "cost");
5643 /* Now that all functions have been written, write the table describing
5644 the function units. The name is included for documentation purposes
5647 printf ("const struct function_unit_desc function_units[] = {\n");
5649 /* Write out the descriptions in numeric order, but don't force that order
5650 on the list. Doing so increases the runtime of genattrtab.c. */
5651 for (i
= 0; i
< num_units
; i
++)
5653 for (unit
= units
; unit
; unit
= unit
->next
)
5657 printf (" {\"%s\", %d, %d, %d, %s, %d, %s_unit_ready_cost, ",
5658 unit
->name
, 1 << unit
->num
, unit
->multiplicity
,
5659 unit
->simultaneity
, XSTR (unit
->default_cost
, 0),
5660 unit
->issue_delay
.max
, unit
->name
);
5662 if (unit
->needs_conflict_function
)
5663 printf ("%s_unit_conflict_cost, ", unit
->name
);
5667 printf ("%d, ", unit
->max_blockage
);
5669 if (unit
->needs_range_function
)
5670 printf ("%s_unit_blockage_range, ", unit
->name
);
5674 if (unit
->needs_blockage_function
)
5675 printf ("%s_unit_blockage", unit
->name
);
5683 printf ("{\"dummy\", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* a dummy element */");
5688 write_complex_function (struct function_unit
*unit
,
5690 const char *connection
)
5692 struct attr_desc
*case_attr
, *attr
;
5693 struct attr_value
*av
, *common_av
;
5700 printf ("static int\n");
5701 printf ("%s_unit_%s (rtx executing_insn, rtx candidate_insn)\n",
5704 printf (" rtx insn;\n");
5705 printf (" int casenum;\n\n");
5706 printf (" insn = executing_insn;\n");
5707 printf (" switch (recog_memoized (insn))\n");
5710 /* Write the `switch' statement to get the case value. */
5711 if (strlen (unit
->name
) + sizeof "*_cases" > 256)
5713 sprintf (str
, "*%s_cases", unit
->name
);
5715 case_attr
= find_attr (&pstr
, 0);
5718 common_av
= find_most_used (case_attr
);
5720 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5721 if (av
!= common_av
)
5722 write_attr_case (case_attr
, av
, 1,
5723 "casenum =", ";", 4, unit
->condexp
);
5725 write_attr_case (case_attr
, common_av
, 0,
5726 "casenum =", ";", 4, unit
->condexp
);
5729 /* Now write an outer switch statement on each case. Then write
5730 the tests on the executing function within each. */
5731 printf (" insn = candidate_insn;\n");
5732 printf (" switch (casenum)\n");
5735 for (i
= 0; i
< unit
->num_opclasses
; i
++)
5737 /* Ensure using this case. */
5739 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5741 && contained_in_p (make_numeric_value (i
), av
->value
))
5747 printf (" case %d:\n", i
);
5748 sprintf (str
, "*%s_%s_%d", unit
->name
, connection
, i
);
5750 attr
= find_attr (&pstr
, 0);
5754 /* If single value, just write it. */
5755 value
= find_single_value (attr
);
5757 write_attr_set (attr
, 6, value
, "return", ";\n", true_rtx
, -2, -2);
5760 common_av
= find_most_used (attr
);
5761 printf (" switch (recog_memoized (insn))\n");
5764 for (av
= attr
->first_value
; av
; av
= av
->next
)
5765 if (av
!= common_av
)
5766 write_attr_case (attr
, av
, 1,
5767 "return", ";", 8, unit
->condexp
);
5769 write_attr_case (attr
, common_av
, 0,
5770 "return", ";", 8, unit
->condexp
);
5775 /* This default case should not be needed, but gcc's analysis is not
5776 good enough to realize that the default case is not needed for the
5777 second switch statement. */
5778 printf (" default:\n abort ();\n");
5779 printf (" }\n}\n\n");
5782 /* This page contains miscellaneous utility routines. */
5784 /* Given a pointer to a (char *), return a malloc'ed string containing the
5785 next comma-separated element. Advance the pointer to after the string
5786 scanned, or the end-of-string. Return NULL if at end of string. */
5789 next_comma_elt (const char **pstr
)
5793 start
= scan_comma_elt (pstr
);
5798 return attr_string (start
, *pstr
- start
);
5801 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
5802 is nonzero, build a new attribute, if one does not exist. *NAME_P is
5803 replaced by a pointer to a canonical copy of the string. */
5805 static struct attr_desc
*
5806 find_attr (const char **name_p
, int create
)
5808 struct attr_desc
*attr
;
5810 const char *name
= *name_p
;
5812 /* Before we resort to using `strcmp', see if the string address matches
5813 anywhere. In most cases, it should have been canonicalized to do so. */
5814 if (name
== alternative_name
)
5817 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
5818 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5819 if (name
== attr
->name
)
5822 /* Otherwise, do it the slow way. */
5823 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5824 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
5826 *name_p
= attr
->name
;
5833 attr
= oballoc (sizeof (struct attr_desc
));
5834 attr
->name
= DEF_ATTR_STRING (name
);
5835 attr
->first_value
= attr
->default_val
= NULL
;
5836 attr
->is_numeric
= attr
->negative_ok
= attr
->is_const
= attr
->is_special
= 0;
5837 attr
->unsigned_p
= attr
->func_units_p
= attr
->blockage_p
= attr
->static_p
= 0;
5838 attr
->next
= attrs
[index
];
5839 attrs
[index
] = attr
;
5841 *name_p
= attr
->name
;
5846 /* Create internal attribute with the given default value. */
5849 make_internal_attr (const char *name
, rtx value
, int special
)
5851 struct attr_desc
*attr
;
5853 attr
= find_attr (&name
, 1);
5854 if (attr
->default_val
)
5857 attr
->is_numeric
= 1;
5859 attr
->is_special
= (special
& ATTR_SPECIAL
) != 0;
5860 attr
->negative_ok
= (special
& ATTR_NEGATIVE_OK
) != 0;
5861 attr
->unsigned_p
= (special
& ATTR_UNSIGNED
) != 0;
5862 attr
->func_units_p
= (special
& ATTR_FUNC_UNITS
) != 0;
5863 attr
->blockage_p
= (special
& ATTR_BLOCKAGE
) != 0;
5864 attr
->static_p
= (special
& ATTR_STATIC
) != 0;
5865 attr
->default_val
= get_attr_value (value
, attr
, -2);
5868 /* Find the most used value of an attribute. */
5870 static struct attr_value
*
5871 find_most_used (struct attr_desc
*attr
)
5873 struct attr_value
*av
;
5874 struct attr_value
*most_used
;
5880 for (av
= attr
->first_value
; av
; av
= av
->next
)
5881 if (av
->num_insns
> nuses
)
5882 nuses
= av
->num_insns
, most_used
= av
;
5887 /* If an attribute only has a single value used, return it. Otherwise
5891 find_single_value (struct attr_desc
*attr
)
5893 struct attr_value
*av
;
5896 unique_value
= NULL
;
5897 for (av
= attr
->first_value
; av
; av
= av
->next
)
5903 unique_value
= av
->value
;
5906 return unique_value
;
5909 /* Return (attr_value "n") */
5912 make_numeric_value (int n
)
5914 static rtx int_values
[20];
5921 if (n
< 20 && int_values
[n
])
5922 return int_values
[n
];
5924 p
= attr_printf (MAX_DIGITS
, "%d", n
);
5925 exp
= attr_rtx (CONST_STRING
, p
);
5928 int_values
[n
] = exp
;
5934 extend_range (struct range
*range
, int min
, int max
)
5936 if (range
->min
> min
)
5938 if (range
->max
< max
)
5943 copy_rtx_unchanging (rtx orig
)
5945 if (ATTR_IND_SIMPLIFIED_P (orig
) || ATTR_CURR_SIMPLIFIED_P (orig
))
5948 ATTR_CURR_SIMPLIFIED_P (orig
) = 1;
5952 /* Determine if an insn has a constant number of delay slots, i.e., the
5953 number of delay slots is not a function of the length of the insn. */
5956 write_const_num_delay_slots (void)
5958 struct attr_desc
*attr
= find_attr (&num_delay_slots_str
, 0);
5959 struct attr_value
*av
;
5960 struct insn_ent
*ie
;
5964 printf ("int\nconst_num_delay_slots (rtx insn)\n");
5966 printf (" switch (recog_memoized (insn))\n");
5969 for (av
= attr
->first_value
; av
; av
= av
->next
)
5972 walk_attr_value (av
->value
);
5975 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5976 if (ie
->insn_code
!= -1)
5977 printf (" case %d:\n", ie
->insn_code
);
5978 printf (" return 0;\n");
5982 printf (" default:\n");
5983 printf (" return 1;\n");
5984 printf (" }\n}\n\n");
5989 main (int argc
, char **argv
)
5992 struct attr_desc
*attr
;
5993 struct insn_def
*id
;
5997 progname
= "genattrtab";
6000 fatal ("no input file name");
6002 if (init_md_reader_args (argc
, argv
) != SUCCESS_EXIT_CODE
)
6003 return (FATAL_EXIT_CODE
);
6005 obstack_init (hash_obstack
);
6006 obstack_init (temp_obstack
);
6008 /* Set up true and false rtx's */
6009 true_rtx
= rtx_alloc (CONST_INT
);
6010 XWINT (true_rtx
, 0) = 1;
6011 false_rtx
= rtx_alloc (CONST_INT
);
6012 XWINT (false_rtx
, 0) = 0;
6013 ATTR_IND_SIMPLIFIED_P (true_rtx
) = ATTR_IND_SIMPLIFIED_P (false_rtx
) = 1;
6014 ATTR_PERMANENT_P (true_rtx
) = ATTR_PERMANENT_P (false_rtx
) = 1;
6016 alternative_name
= DEF_ATTR_STRING ("alternative");
6017 length_str
= DEF_ATTR_STRING ("length");
6018 delay_type_str
= DEF_ATTR_STRING ("*delay_type");
6019 delay_1_0_str
= DEF_ATTR_STRING ("*delay_1_0");
6020 num_delay_slots_str
= DEF_ATTR_STRING ("*num_delay_slots");
6022 printf ("/* Generated automatically by the program `genattrtab'\n\
6023 from the machine description file `md'. */\n\n");
6025 /* Read the machine description. */
6027 initiate_automaton_gen (argc
, argv
);
6032 desc
= read_md_rtx (&lineno
, &insn_code_number
);
6036 switch (GET_CODE (desc
))
6039 case DEFINE_PEEPHOLE
:
6040 case DEFINE_ASM_ATTRIBUTES
:
6041 gen_insn (desc
, lineno
);
6045 gen_attr (desc
, lineno
);
6049 gen_delay (desc
, lineno
);
6052 case DEFINE_FUNCTION_UNIT
:
6053 gen_unit (desc
, lineno
);
6056 case DEFINE_CPU_UNIT
:
6057 gen_cpu_unit (desc
);
6060 case DEFINE_QUERY_CPU_UNIT
:
6061 gen_query_cpu_unit (desc
);
6069 gen_excl_set (desc
);
6073 gen_presence_set (desc
);
6076 case FINAL_PRESENCE_SET
:
6077 gen_final_presence_set (desc
);
6081 gen_absence_set (desc
);
6084 case FINAL_ABSENCE_SET
:
6085 gen_final_absence_set (desc
);
6088 case DEFINE_AUTOMATON
:
6089 gen_automaton (desc
);
6092 case AUTOMATA_OPTION
:
6093 gen_automata_option (desc
);
6096 case DEFINE_RESERVATION
:
6100 case DEFINE_INSN_RESERVATION
:
6101 gen_insn_reserv (desc
);
6107 if (GET_CODE (desc
) != DEFINE_ASM_ATTRIBUTES
)
6108 insn_index_number
++;
6112 return FATAL_EXIT_CODE
;
6116 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
6117 if (! got_define_asm_attributes
)
6119 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
6120 XVEC (tem
, 0) = rtvec_alloc (0);
6124 /* Expand DEFINE_DELAY information into new attribute. */
6128 if (num_units
|| num_dfa_decls
)
6130 /* Expand DEFINE_FUNCTION_UNIT information into new attributes. */
6132 /* Build DFA, output some functions and expand DFA information
6133 into new attributes. */
6137 printf ("#include \"config.h\"\n");
6138 printf ("#include \"system.h\"\n");
6139 printf ("#include \"coretypes.h\"\n");
6140 printf ("#include \"tm.h\"\n");
6141 printf ("#include \"rtl.h\"\n");
6142 printf ("#include \"tm_p.h\"\n");
6143 printf ("#include \"insn-config.h\"\n");
6144 printf ("#include \"recog.h\"\n");
6145 printf ("#include \"regs.h\"\n");
6146 printf ("#include \"real.h\"\n");
6147 printf ("#include \"output.h\"\n");
6148 printf ("#include \"insn-attr.h\"\n");
6149 printf ("#include \"toplev.h\"\n");
6150 printf ("#include \"flags.h\"\n");
6151 printf ("#include \"function.h\"\n");
6153 printf ("#define operands recog_data.operand\n\n");
6155 /* Make `insn_alternatives'. */
6156 insn_alternatives
= oballoc (insn_code_number
* sizeof (int));
6157 for (id
= defs
; id
; id
= id
->next
)
6158 if (id
->insn_code
>= 0)
6159 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
6161 /* Make `insn_n_alternatives'. */
6162 insn_n_alternatives
= oballoc (insn_code_number
* sizeof (int));
6163 for (id
= defs
; id
; id
= id
->next
)
6164 if (id
->insn_code
>= 0)
6165 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
6167 /* Prepare to write out attribute subroutines by checking everything stored
6168 away and building the attribute cases. */
6172 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6173 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6174 attr
->default_val
->value
6175 = check_attr_value (attr
->default_val
->value
, attr
);
6178 return FATAL_EXIT_CODE
;
6180 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6181 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6184 /* Construct extra attributes for `length'. */
6185 make_length_attrs ();
6187 /* Perform any possible optimizations to speed up compilation. */
6190 /* Now write out all the `gen_attr_...' routines. Do these before the
6191 special routines (specifically before write_function_unit_info), so
6192 that they get defined before they are used. */
6194 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6195 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6197 if (! attr
->is_special
&& ! attr
->is_const
)
6202 = (attr
->name
[0] == '*'
6203 && strcmp (&attr
->name
[1], INSN_ALTS_FUNC_NAME
) == 0);
6205 printf ("\n#if AUTOMATON_ALTS\n");
6206 write_attr_get (attr
);
6208 printf ("#endif\n\n");
6212 /* Write out delay eligibility information, if DEFINE_DELAY present.
6213 (The function to compute the number of delay slots will be written
6217 write_eligible_delay ("delay");
6218 if (have_annul_true
)
6219 write_eligible_delay ("annul_true");
6220 if (have_annul_false
)
6221 write_eligible_delay ("annul_false");
6224 if (num_units
|| num_dfa_decls
)
6226 /* Write out information about function units. */
6227 write_function_unit_info ();
6228 /* Output code for pipeline hazards recognition based on DFA
6229 (deterministic finite state automata. */
6233 /* Write out constant delay slot info. */
6234 write_const_num_delay_slots ();
6236 write_length_unit_log ();
6239 return (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);
6242 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
6244 get_insn_name (int code ATTRIBUTE_UNUSED
)