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, 2004 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 `return_val' (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), return_val))
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.
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
) == RTX_UNARY
)
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
) == RTX_BIN_ARITH
595 || GET_RTX_CLASS (code
) == RTX_COMM_ARITH
596 || GET_RTX_CLASS (code
) == RTX_COMPARE
597 || GET_RTX_CLASS (code
) == RTX_COMM_COMPARE
)
599 rtx arg0
= va_arg (p
, rtx
);
600 rtx arg1
= va_arg (p
, rtx
);
602 /* A permanent object cannot point to impermanent ones. */
603 if (! ATTR_PERMANENT_P (arg0
) || ! ATTR_PERMANENT_P (arg1
))
605 rt_val
= rtx_alloc (code
);
606 XEXP (rt_val
, 0) = arg0
;
607 XEXP (rt_val
, 1) = arg1
;
611 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
612 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
613 if (h
->hashcode
== hashcode
614 && GET_CODE (h
->u
.rtl
) == code
615 && XEXP (h
->u
.rtl
, 0) == arg0
616 && XEXP (h
->u
.rtl
, 1) == arg1
)
621 rtl_obstack
= hash_obstack
;
622 rt_val
= rtx_alloc (code
);
623 XEXP (rt_val
, 0) = arg0
;
624 XEXP (rt_val
, 1) = arg1
;
627 else if (GET_RTX_LENGTH (code
) == 1
628 && GET_RTX_FORMAT (code
)[0] == 's')
630 char *arg0
= va_arg (p
, char *);
632 arg0
= DEF_ATTR_STRING (arg0
);
634 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
635 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
636 if (h
->hashcode
== hashcode
637 && GET_CODE (h
->u
.rtl
) == code
638 && XSTR (h
->u
.rtl
, 0) == arg0
)
643 rtl_obstack
= hash_obstack
;
644 rt_val
= rtx_alloc (code
);
645 XSTR (rt_val
, 0) = arg0
;
648 else if (GET_RTX_LENGTH (code
) == 2
649 && GET_RTX_FORMAT (code
)[0] == 's'
650 && GET_RTX_FORMAT (code
)[1] == 's')
652 char *arg0
= va_arg (p
, char *);
653 char *arg1
= va_arg (p
, char *);
655 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
656 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
657 if (h
->hashcode
== hashcode
658 && GET_CODE (h
->u
.rtl
) == code
659 && XSTR (h
->u
.rtl
, 0) == arg0
660 && XSTR (h
->u
.rtl
, 1) == arg1
)
665 rtl_obstack
= hash_obstack
;
666 rt_val
= rtx_alloc (code
);
667 XSTR (rt_val
, 0) = arg0
;
668 XSTR (rt_val
, 1) = arg1
;
671 else if (code
== CONST_INT
)
673 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
683 int i
; /* Array indices... */
684 const char *fmt
; /* Current rtx's format... */
686 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
688 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
689 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
693 case '0': /* Unused field. */
696 case 'i': /* An integer? */
697 XINT (rt_val
, i
) = va_arg (p
, int);
700 case 'w': /* A wide integer? */
701 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
704 case 's': /* A string? */
705 XSTR (rt_val
, i
) = va_arg (p
, char *);
708 case 'e': /* An expression? */
709 case 'u': /* An insn? Same except when printing. */
710 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
713 case 'E': /* An RTX vector? */
714 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
724 rtl_obstack
= old_obstack
;
725 attr_hash_add_rtx (hashcode
, rt_val
);
726 ATTR_PERMANENT_P (rt_val
) = 1;
731 attr_rtx (enum rtx_code code
, ...)
737 result
= attr_rtx_1 (code
, p
);
742 /* Create a new string printed with the printf line arguments into a space
743 of at most LEN bytes:
745 rtx attr_printf (len, format, [arg1, ..., argn]) */
748 attr_printf (unsigned int len
, const char *fmt
, ...)
755 if (len
> sizeof str
- 1) /* Leave room for \0. */
758 vsprintf (str
, fmt
, p
);
761 return DEF_ATTR_STRING (str
);
765 attr_eq (const char *name
, const char *value
)
767 return attr_rtx (EQ_ATTR
, DEF_ATTR_STRING (name
), DEF_ATTR_STRING (value
));
773 return XSTR (make_numeric_value (n
), 0);
776 /* Return a permanent (possibly shared) copy of a string STR (not assumed
777 to be null terminated) with LEN bytes. */
780 attr_string (const char *str
, int len
)
787 /* Compute the hash code. */
788 hashcode
= (len
+ 1) * 613 + (unsigned) str
[0];
789 for (i
= 1; i
<= len
; i
+= 2)
790 hashcode
= ((hashcode
* 613) + (unsigned) str
[i
]);
792 hashcode
= -hashcode
;
794 /* Search the table for the string. */
795 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
796 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
797 && !strncmp (h
->u
.str
, str
, len
))
798 return h
->u
.str
; /* <-- return if found. */
800 /* Not found; create a permanent copy and add it to the hash table. */
801 new_str
= obstack_alloc (hash_obstack
, len
+ 1);
802 memcpy (new_str
, str
, len
);
804 attr_hash_add_string (hashcode
, new_str
);
806 return new_str
; /* Return the new string. */
809 /* Check two rtx's for equality of contents,
810 taking advantage of the fact that if both are hashed
811 then they can't be equal unless they are the same object. */
814 attr_equal_p (rtx x
, rtx y
)
816 return (x
== y
|| (! (ATTR_PERMANENT_P (x
) && ATTR_PERMANENT_P (y
))
817 && rtx_equal_p (x
, y
)));
820 /* Copy an attribute value expression,
821 descending to all depths, but not copying any
822 permanent hashed subexpressions. */
825 attr_copy_rtx (rtx orig
)
830 const char *format_ptr
;
832 /* No need to copy a permanent object. */
833 if (ATTR_PERMANENT_P (orig
))
836 code
= GET_CODE (orig
);
855 copy
= rtx_alloc (code
);
856 PUT_MODE (copy
, GET_MODE (orig
));
857 ATTR_IND_SIMPLIFIED_P (copy
) = ATTR_IND_SIMPLIFIED_P (orig
);
858 ATTR_CURR_SIMPLIFIED_P (copy
) = ATTR_CURR_SIMPLIFIED_P (orig
);
859 ATTR_PERMANENT_P (copy
) = ATTR_PERMANENT_P (orig
);
860 ATTR_EQ_ATTR_P (copy
) = ATTR_EQ_ATTR_P (orig
);
862 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
864 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
866 switch (*format_ptr
++)
869 XEXP (copy
, i
) = XEXP (orig
, i
);
870 if (XEXP (orig
, i
) != NULL
)
871 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
876 XVEC (copy
, i
) = XVEC (orig
, i
);
877 if (XVEC (orig
, i
) != NULL
)
879 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
880 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
881 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
887 XINT (copy
, i
) = XINT (orig
, i
);
891 XWINT (copy
, i
) = XWINT (orig
, i
);
896 XSTR (copy
, i
) = XSTR (orig
, i
);
906 /* Given a test expression for an attribute, ensure it is validly formed.
907 IS_CONST indicates whether the expression is constant for each compiler
908 run (a constant expression may not test any particular insn).
910 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
911 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
912 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
914 Update the string address in EQ_ATTR expression to be the same used
915 in the attribute (or `alternative_name') to speed up subsequent
916 `find_attr' calls and eliminate most `strcmp' calls.
918 Return the new expression, if any. */
921 check_attr_test (rtx exp
, int is_const
, int lineno
)
923 struct attr_desc
*attr
;
924 struct attr_value
*av
;
925 const char *name_ptr
, *p
;
928 switch (GET_CODE (exp
))
931 /* Handle negation test. */
932 if (XSTR (exp
, 1)[0] == '!')
933 return check_attr_test (attr_rtx (NOT
,
934 attr_eq (XSTR (exp
, 0),
938 else if (n_comma_elts (XSTR (exp
, 1)) == 1)
940 attr
= find_attr (&XSTR (exp
, 0), 0);
943 if (! strcmp (XSTR (exp
, 0), "alternative"))
944 return mk_attr_alt (1 << atoi (XSTR (exp
, 1)));
946 fatal ("unknown attribute `%s' in EQ_ATTR", XSTR (exp
, 0));
949 if (is_const
&& ! attr
->is_const
)
950 fatal ("constant expression uses insn attribute `%s' in EQ_ATTR",
953 /* Copy this just to make it permanent,
954 so expressions using it can be permanent too. */
955 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
957 /* It shouldn't be possible to simplify the value given to a
958 constant attribute, so don't expand this until it's time to
959 write the test expression. */
961 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
963 if (attr
->is_numeric
)
965 for (p
= XSTR (exp
, 1); *p
; p
++)
967 fatal ("attribute `%s' takes only numeric values",
972 for (av
= attr
->first_value
; av
; av
= av
->next
)
973 if (GET_CODE (av
->value
) == CONST_STRING
974 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
978 fatal ("unknown value `%s' for `%s' attribute",
979 XSTR (exp
, 1), XSTR (exp
, 0));
984 if (! strcmp (XSTR (exp
, 0), "alternative"))
988 name_ptr
= XSTR (exp
, 1);
989 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
990 set
|= 1 << atoi (p
);
992 return mk_attr_alt (set
);
996 /* Make an IOR tree of the possible values. */
998 name_ptr
= XSTR (exp
, 1);
999 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1001 newexp
= attr_eq (XSTR (exp
, 0), p
);
1002 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
1005 return check_attr_test (orexp
, is_const
, lineno
);
1014 /* Either TRUE or FALSE. */
1022 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
1023 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
, lineno
);
1027 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
)));
4798 /* Constant integer. */
4800 printf (HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
4803 /* A random C expression. */
4805 printf ("%s", XSTR (exp
, 0));
4808 /* The address of the branch target. */
4810 printf ("INSN_ADDRESSES_SET_P () ? INSN_ADDRESSES (INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])) : 0",
4811 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
4815 /* The address of the current insn. We implement this actually as the
4816 address of the current insn for backward branches, but the last
4817 address of the next insn for forward branches, and both with
4818 adjustments that account for the worst-case possible stretching of
4819 intervening alignments between this insn and its destination. */
4820 printf ("insn_current_reference_address (insn)");
4824 printf ("%s", XSTR (exp
, 0));
4828 write_test_expr (XEXP (exp
, 0), flags
& 2);
4830 write_test_expr (XEXP (exp
, 1), flags
| 1);
4832 write_test_expr (XEXP (exp
, 2), flags
| 1);
4836 fatal ("bad RTX code `%s' in attribute calculation\n",
4837 GET_RTX_NAME (code
));
4843 /* Given an attribute value, return the maximum CONST_STRING argument
4844 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
4847 max_attr_value (rtx exp
, int *unknownp
)
4852 switch (GET_CODE (exp
))
4855 current_max
= atoi (XSTR (exp
, 0));
4859 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4860 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4862 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4863 if (n
> current_max
)
4869 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4870 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
4871 if (n
> current_max
)
4877 current_max
= INT_MAX
;
4884 /* Given an attribute value, return the result of ORing together all
4885 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
4886 if the numeric value is not known. */
4889 or_attr_value (rtx exp
, int *unknownp
)
4894 switch (GET_CODE (exp
))
4897 current_or
= atoi (XSTR (exp
, 0));
4901 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4902 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4903 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4907 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4908 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
4920 /* Scan an attribute value, possibly a conditional, and record what actions
4921 will be required to do any conditional tests in it.
4924 `must_extract' if we need to extract the insn operands
4925 `must_constrain' if we must compute `which_alternative'
4926 `address_used' if an address expression was used
4927 `length_used' if an (eq_attr "length" ...) was used
4931 walk_attr_value (rtx exp
)
4940 code
= GET_CODE (exp
);
4944 if (! ATTR_IND_SIMPLIFIED_P (exp
))
4945 /* Since this is an arbitrary expression, it can look at anything.
4946 However, constant expressions do not depend on any particular
4948 must_extract
= must_constrain
= 1;
4956 must_extract
= must_constrain
= 1;
4960 if (XSTR (exp
, 0) == alternative_name
)
4961 must_extract
= must_constrain
= 1;
4962 else if (strcmp_check (XSTR (exp
, 0), length_str
) == 0)
4982 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
4987 walk_attr_value (XEXP (exp
, i
));
4991 if (XVEC (exp
, i
) != NULL
)
4992 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4993 walk_attr_value (XVECEXP (exp
, i
, j
));
4998 /* Write out a function to obtain the attribute for a given INSN. */
5001 write_attr_get (struct attr_desc
*attr
)
5003 struct attr_value
*av
, *common_av
;
5005 /* Find the most used attribute value. Handle that as the `default' of the
5006 switch we will generate. */
5007 common_av
= find_most_used (attr
);
5009 /* Write out start of function, then all values with explicit `case' lines,
5010 then a `default', then the value with the most uses. */
5013 if (!attr
->is_numeric
)
5014 printf ("enum attr_%s\n", attr
->name
);
5015 else if (attr
->unsigned_p
)
5016 printf ("unsigned int\n");
5020 /* If the attribute name starts with a star, the remainder is the name of
5021 the subroutine to use, instead of `get_attr_...'. */
5022 if (attr
->name
[0] == '*')
5023 printf ("%s (rtx insn ATTRIBUTE_UNUSED)\n", &attr
->name
[1]);
5024 else if (attr
->is_const
== 0)
5025 printf ("get_attr_%s (rtx insn ATTRIBUTE_UNUSED)\n", attr
->name
);
5028 printf ("get_attr_%s (void)\n", attr
->name
);
5031 for (av
= attr
->first_value
; av
; av
= av
->next
)
5032 if (av
->num_insns
!= 0)
5033 write_attr_set (attr
, 2, av
->value
, "return", ";",
5034 true_rtx
, av
->first_insn
->insn_code
,
5035 av
->first_insn
->insn_index
);
5043 if (GET_CODE (common_av
->value
) == FFS
)
5045 rtx p
= XEXP (common_av
->value
, 0);
5047 /* No need to emit code to abort if the insn is unrecognized; the
5048 other get_attr_foo functions will do that when we call them. */
5050 write_toplevel_expr (p
);
5052 printf ("\n if (accum && accum == (accum & -accum))\n");
5054 printf (" int i;\n");
5055 printf (" for (i = 0; accum >>= 1; ++i) continue;\n");
5056 printf (" accum = i;\n");
5057 printf (" }\n else\n");
5058 printf (" accum = ~accum;\n");
5059 printf (" return accum;\n}\n\n");
5063 printf (" switch (recog_memoized (insn))\n");
5066 for (av
= attr
->first_value
; av
; av
= av
->next
)
5067 if (av
!= common_av
)
5068 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5070 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5071 printf (" }\n}\n\n");
5075 /* Given an AND tree of known true terms (because we are inside an `if' with
5076 that as the condition or are in an `else' clause) and an expression,
5077 replace any known true terms with TRUE. Use `simplify_and_tree' to do
5078 the bulk of the work. */
5081 eliminate_known_true (rtx known_true
, rtx exp
, int insn_code
, int insn_index
)
5085 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
5087 if (GET_CODE (known_true
) == AND
)
5089 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
5090 insn_code
, insn_index
);
5091 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
5092 insn_code
, insn_index
);
5097 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
5103 /* Write out a series of tests and assignment statements to perform tests and
5104 sets of an attribute value. We are passed an indentation amount and prefix
5105 and suffix strings to write around each attribute value (e.g., "return"
5109 write_attr_set (struct attr_desc
*attr
, int indent
, rtx value
,
5110 const char *prefix
, const char *suffix
, rtx known_true
,
5111 int insn_code
, int insn_index
)
5113 if (GET_CODE (value
) == COND
)
5115 /* Assume the default value will be the default of the COND unless we
5116 find an always true expression. */
5117 rtx default_val
= XEXP (value
, 1);
5118 rtx our_known_true
= known_true
;
5123 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
5128 testexp
= eliminate_known_true (our_known_true
,
5129 XVECEXP (value
, 0, i
),
5130 insn_code
, insn_index
);
5131 newexp
= attr_rtx (NOT
, testexp
);
5132 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
5133 insn_code
, insn_index
);
5135 /* If the test expression is always true or if the next `known_true'
5136 expression is always false, this is the last case, so break
5137 out and let this value be the `else' case. */
5138 if (testexp
== true_rtx
|| newexp
== false_rtx
)
5140 default_val
= XVECEXP (value
, 0, i
+ 1);
5144 /* Compute the expression to pass to our recursive call as being
5146 inner_true
= insert_right_side (AND
, our_known_true
,
5147 testexp
, insn_code
, insn_index
);
5149 /* If this is always false, skip it. */
5150 if (inner_true
== false_rtx
)
5153 write_indent (indent
);
5154 printf ("%sif ", first_if
? "" : "else ");
5156 write_test_expr (testexp
, 0);
5158 write_indent (indent
+ 2);
5161 write_attr_set (attr
, indent
+ 4,
5162 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
5163 inner_true
, insn_code
, insn_index
);
5164 write_indent (indent
+ 2);
5166 our_known_true
= newexp
;
5171 write_indent (indent
);
5173 write_indent (indent
+ 2);
5177 write_attr_set (attr
, first_if
? indent
: indent
+ 4, default_val
,
5178 prefix
, suffix
, our_known_true
, insn_code
, insn_index
);
5182 write_indent (indent
+ 2);
5188 write_indent (indent
);
5189 printf ("%s ", prefix
);
5190 write_attr_value (attr
, value
);
5191 printf ("%s\n", suffix
);
5195 /* Write out the computation for one attribute value. */
5198 write_attr_case (struct attr_desc
*attr
, struct attr_value
*av
,
5199 int write_case_lines
, const char *prefix
, const char *suffix
,
5200 int indent
, rtx known_true
)
5202 struct insn_ent
*ie
;
5204 if (av
->num_insns
== 0)
5207 if (av
->has_asm_insn
)
5209 write_indent (indent
);
5210 printf ("case -1:\n");
5211 write_indent (indent
+ 2);
5212 printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
5213 write_indent (indent
+ 2);
5214 printf (" && asm_noperands (PATTERN (insn)) < 0)\n");
5215 write_indent (indent
+ 2);
5216 printf (" fatal_insn_not_found (insn);\n");
5219 if (write_case_lines
)
5221 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5222 if (ie
->insn_code
!= -1)
5224 write_indent (indent
);
5225 printf ("case %d:\n", ie
->insn_code
);
5230 write_indent (indent
);
5231 printf ("default:\n");
5234 /* See what we have to do to output this value. */
5235 must_extract
= must_constrain
= address_used
= 0;
5236 walk_attr_value (av
->value
);
5240 write_indent (indent
+ 2);
5241 printf ("extract_constrain_insn_cached (insn);\n");
5243 else if (must_extract
)
5245 write_indent (indent
+ 2);
5246 printf ("extract_insn_cached (insn);\n");
5249 write_attr_set (attr
, indent
+ 2, av
->value
, prefix
, suffix
,
5250 known_true
, av
->first_insn
->insn_code
,
5251 av
->first_insn
->insn_index
);
5253 if (strncmp (prefix
, "return", 6))
5255 write_indent (indent
+ 2);
5256 printf ("break;\n");
5261 /* Search for uses of non-const attributes and write code to cache them. */
5264 write_expr_attr_cache (rtx p
, struct attr_desc
*attr
)
5269 if (GET_CODE (p
) == EQ_ATTR
)
5271 if (XSTR (p
, 0) != attr
->name
)
5274 if (!attr
->is_numeric
)
5275 printf (" enum attr_%s ", attr
->name
);
5276 else if (attr
->unsigned_p
)
5277 printf (" unsigned int ");
5281 printf ("attr_%s = get_attr_%s (insn);\n", attr
->name
, attr
->name
);
5285 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
5286 ie
= GET_RTX_LENGTH (GET_CODE (p
));
5287 for (i
= 0; i
< ie
; i
++)
5292 if (write_expr_attr_cache (XEXP (p
, i
), attr
))
5297 je
= XVECLEN (p
, i
);
5298 for (j
= 0; j
< je
; ++j
)
5299 if (write_expr_attr_cache (XVECEXP (p
, i
, j
), attr
))
5308 /* Evaluate an expression at top level. A front end to write_test_expr,
5309 in which we cache attribute values and break up excessively large
5310 expressions to cater to older compilers. */
5313 write_toplevel_expr (rtx p
)
5315 struct attr_desc
*attr
;
5318 for (i
= 0; i
< MAX_ATTRS_INDEX
; ++i
)
5319 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
5320 if (!attr
->is_const
)
5321 write_expr_attr_cache (p
, attr
);
5323 printf (" unsigned long accum = 0;\n\n");
5325 while (GET_CODE (p
) == IOR
)
5328 if (GET_CODE (XEXP (p
, 0)) == IOR
)
5329 e
= XEXP (p
, 1), p
= XEXP (p
, 0);
5331 e
= XEXP (p
, 0), p
= XEXP (p
, 1);
5333 printf (" accum |= ");
5334 write_test_expr (e
, 3);
5337 printf (" accum |= ");
5338 write_test_expr (p
, 3);
5342 /* Utilities to write names in various forms. */
5345 write_unit_name (const char *prefix
, int num
, const char *suffix
)
5347 struct function_unit
*unit
;
5349 for (unit
= units
; unit
; unit
= unit
->next
)
5350 if (unit
->num
== num
)
5352 printf ("%s%s%s", prefix
, unit
->name
, suffix
);
5356 printf ("%s<unknown>%s", prefix
, suffix
);
5360 write_attr_valueq (struct attr_desc
*attr
, const char *s
)
5362 if (attr
->is_numeric
)
5368 /* Make the blockage range values and function units used values easier
5370 if (attr
->func_units_p
)
5373 printf (" /* units: none */");
5375 write_unit_name (" /* units: ", num
, " */");
5379 const char *sep
= " /* units: ";
5380 for (i
= 0, num
= ~num
; num
; i
++, num
>>= 1)
5383 write_unit_name (sep
, i
, (num
== 1) ? " */" : "");
5389 else if (attr
->blockage_p
)
5390 printf (" /* min %d, max %d */", num
>> (HOST_BITS_PER_INT
/ 2),
5391 num
& ((1 << (HOST_BITS_PER_INT
/ 2)) - 1));
5393 else if (num
> 9 || num
< 0)
5394 printf (" /* 0x%x */", num
);
5398 write_upcase (attr
->name
);
5405 write_attr_value (struct attr_desc
*attr
, rtx value
)
5409 switch (GET_CODE (value
))
5412 write_attr_valueq (attr
, XSTR (value
, 0));
5416 printf (HOST_WIDE_INT_PRINT_DEC
, INTVAL (value
));
5420 fputs (XSTR (value
, 0), stdout
);
5425 struct attr_desc
*attr2
= find_attr (&XSTR (value
, 0), 0);
5426 printf ("get_attr_%s (%s)", attr2
->name
,
5427 (attr2
->is_const
? "" : "insn"));
5448 write_attr_value (attr
, XEXP (value
, 0));
5452 write_attr_value (attr
, XEXP (value
, 1));
5461 write_upcase (const char *str
)
5465 /* The argument of TOUPPER should not have side effects. */
5466 putchar (TOUPPER(*str
));
5472 write_indent (int indent
)
5474 for (; indent
> 8; indent
-= 8)
5477 for (; indent
; indent
--)
5481 /* Write a subroutine that is given an insn that requires a delay slot, a
5482 delay slot ordinal, and a candidate insn. It returns nonzero if the
5483 candidate can be placed in the specified delay slot of the insn.
5485 We can write as many as three subroutines. `eligible_for_delay'
5486 handles normal delay slots, `eligible_for_annul_true' indicates that
5487 the specified insn can be annulled if the branch is true, and likewise
5488 for `eligible_for_annul_false'.
5490 KIND is a string distinguishing these three cases ("delay", "annul_true",
5491 or "annul_false"). */
5494 write_eligible_delay (const char *kind
)
5496 struct delay_desc
*delay
;
5500 struct attr_desc
*attr
;
5501 struct attr_value
*av
, *common_av
;
5504 /* Compute the maximum number of delay slots required. We use the delay
5505 ordinal times this number plus one, plus the slot number as an index into
5506 the appropriate predicate to test. */
5508 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
5509 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
5510 max_slots
= XVECLEN (delay
->def
, 1) / 3;
5512 /* Write function prelude. */
5515 printf ("eligible_for_%s (rtx delay_insn ATTRIBUTE_UNUSED, int slot, rtx candidate_insn, int flags ATTRIBUTE_UNUSED)\n",
5518 printf (" rtx insn;\n");
5520 printf (" if (slot >= %d)\n", max_slots
);
5521 printf (" abort ();\n");
5524 /* If more than one delay type, find out which type the delay insn is. */
5528 attr
= find_attr (&delay_type_str
, 0);
5531 common_av
= find_most_used (attr
);
5533 printf (" insn = delay_insn;\n");
5534 printf (" switch (recog_memoized (insn))\n");
5537 sprintf (str
, " * %d;\n break;", max_slots
);
5538 for (av
= attr
->first_value
; av
; av
= av
->next
)
5539 if (av
!= common_av
)
5540 write_attr_case (attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
5542 write_attr_case (attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
5545 /* Ensure matched. Otherwise, shouldn't have been called. */
5546 printf (" if (slot < %d)\n", max_slots
);
5547 printf (" abort ();\n\n");
5550 /* If just one type of delay slot, write simple switch. */
5551 if (num_delays
== 1 && max_slots
== 1)
5553 printf (" insn = candidate_insn;\n");
5554 printf (" switch (recog_memoized (insn))\n");
5557 attr
= find_attr (&delay_1_0_str
, 0);
5560 common_av
= find_most_used (attr
);
5562 for (av
= attr
->first_value
; av
; av
= av
->next
)
5563 if (av
!= common_av
)
5564 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5566 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5572 /* Write a nested CASE. The first indicates which condition we need to
5573 test, and the inner CASE tests the condition. */
5574 printf (" insn = candidate_insn;\n");
5575 printf (" switch (slot)\n");
5578 for (delay
= delays
; delay
; delay
= delay
->next
)
5579 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
5581 printf (" case %d:\n",
5582 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
5583 printf (" switch (recog_memoized (insn))\n");
5586 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
5588 attr
= find_attr (&pstr
, 0);
5591 common_av
= find_most_used (attr
);
5593 for (av
= attr
->first_value
; av
; av
= av
->next
)
5594 if (av
!= common_av
)
5595 write_attr_case (attr
, av
, 1, "return", ";", 8, true_rtx
);
5597 write_attr_case (attr
, common_av
, 0, "return", ";", 8, true_rtx
);
5601 printf (" default:\n");
5602 printf (" abort ();\n");
5609 /* Write routines to compute conflict cost for function units. Then write a
5610 table describing the available function units. */
5613 write_function_unit_info (void)
5615 struct function_unit
*unit
;
5618 /* Write out conflict routines for function units. Don't bother writing
5619 one if there is only one issue delay value. */
5621 for (unit
= units
; unit
; unit
= unit
->next
)
5623 if (unit
->needs_blockage_function
)
5624 write_complex_function (unit
, "blockage", "block");
5626 /* If the minimum and maximum conflict costs are the same, there
5627 is only one value, so we don't need a function. */
5628 if (! unit
->needs_conflict_function
)
5630 unit
->default_cost
= make_numeric_value (unit
->issue_delay
.max
);
5634 /* The function first computes the case from the candidate insn. */
5635 unit
->default_cost
= make_numeric_value (0);
5636 write_complex_function (unit
, "conflict_cost", "cost");
5639 /* Now that all functions have been written, write the table describing
5640 the function units. The name is included for documentation purposes
5643 printf ("const struct function_unit_desc function_units[] = {\n");
5645 /* Write out the descriptions in numeric order, but don't force that order
5646 on the list. Doing so increases the runtime of genattrtab.c. */
5647 for (i
= 0; i
< num_units
; i
++)
5649 for (unit
= units
; unit
; unit
= unit
->next
)
5653 printf (" {\"%s\", %d, %d, %d, %s, %d, %s_unit_ready_cost, ",
5654 unit
->name
, 1 << unit
->num
, unit
->multiplicity
,
5655 unit
->simultaneity
, XSTR (unit
->default_cost
, 0),
5656 unit
->issue_delay
.max
, unit
->name
);
5658 if (unit
->needs_conflict_function
)
5659 printf ("%s_unit_conflict_cost, ", unit
->name
);
5663 printf ("%d, ", unit
->max_blockage
);
5665 if (unit
->needs_range_function
)
5666 printf ("%s_unit_blockage_range, ", unit
->name
);
5670 if (unit
->needs_blockage_function
)
5671 printf ("%s_unit_blockage", unit
->name
);
5679 printf ("{\"dummy\", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* a dummy element */");
5684 write_complex_function (struct function_unit
*unit
,
5686 const char *connection
)
5688 struct attr_desc
*case_attr
, *attr
;
5689 struct attr_value
*av
, *common_av
;
5696 printf ("static int\n");
5697 printf ("%s_unit_%s (rtx executing_insn, rtx candidate_insn)\n",
5700 printf (" rtx insn;\n");
5701 printf (" int casenum;\n\n");
5702 printf (" insn = executing_insn;\n");
5703 printf (" switch (recog_memoized (insn))\n");
5706 /* Write the `switch' statement to get the case value. */
5707 if (strlen (unit
->name
) + sizeof "*_cases" > 256)
5709 sprintf (str
, "*%s_cases", unit
->name
);
5711 case_attr
= find_attr (&pstr
, 0);
5714 common_av
= find_most_used (case_attr
);
5716 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5717 if (av
!= common_av
)
5718 write_attr_case (case_attr
, av
, 1,
5719 "casenum =", ";", 4, unit
->condexp
);
5721 write_attr_case (case_attr
, common_av
, 0,
5722 "casenum =", ";", 4, unit
->condexp
);
5725 /* Now write an outer switch statement on each case. Then write
5726 the tests on the executing function within each. */
5727 printf (" insn = candidate_insn;\n");
5728 printf (" switch (casenum)\n");
5731 for (i
= 0; i
< unit
->num_opclasses
; i
++)
5733 /* Ensure using this case. */
5735 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5737 && contained_in_p (make_numeric_value (i
), av
->value
))
5743 printf (" case %d:\n", i
);
5744 sprintf (str
, "*%s_%s_%d", unit
->name
, connection
, i
);
5746 attr
= find_attr (&pstr
, 0);
5750 /* If single value, just write it. */
5751 value
= find_single_value (attr
);
5753 write_attr_set (attr
, 6, value
, "return", ";\n", true_rtx
, -2, -2);
5756 common_av
= find_most_used (attr
);
5757 printf (" switch (recog_memoized (insn))\n");
5760 for (av
= attr
->first_value
; av
; av
= av
->next
)
5761 if (av
!= common_av
)
5762 write_attr_case (attr
, av
, 1,
5763 "return", ";", 8, unit
->condexp
);
5765 write_attr_case (attr
, common_av
, 0,
5766 "return", ";", 8, unit
->condexp
);
5771 /* This default case should not be needed, but gcc's analysis is not
5772 good enough to realize that the default case is not needed for the
5773 second switch statement. */
5774 printf (" default:\n abort ();\n");
5775 printf (" }\n}\n\n");
5778 /* This page contains miscellaneous utility routines. */
5780 /* Given a pointer to a (char *), return a malloc'ed string containing the
5781 next comma-separated element. Advance the pointer to after the string
5782 scanned, or the end-of-string. Return NULL if at end of string. */
5785 next_comma_elt (const char **pstr
)
5789 start
= scan_comma_elt (pstr
);
5794 return attr_string (start
, *pstr
- start
);
5797 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
5798 is nonzero, build a new attribute, if one does not exist. *NAME_P is
5799 replaced by a pointer to a canonical copy of the string. */
5801 static struct attr_desc
*
5802 find_attr (const char **name_p
, int create
)
5804 struct attr_desc
*attr
;
5806 const char *name
= *name_p
;
5808 /* Before we resort to using `strcmp', see if the string address matches
5809 anywhere. In most cases, it should have been canonicalized to do so. */
5810 if (name
== alternative_name
)
5813 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
5814 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5815 if (name
== attr
->name
)
5818 /* Otherwise, do it the slow way. */
5819 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5820 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
5822 *name_p
= attr
->name
;
5829 attr
= oballoc (sizeof (struct attr_desc
));
5830 attr
->name
= DEF_ATTR_STRING (name
);
5831 attr
->first_value
= attr
->default_val
= NULL
;
5832 attr
->is_numeric
= attr
->negative_ok
= attr
->is_const
= attr
->is_special
= 0;
5833 attr
->unsigned_p
= attr
->func_units_p
= attr
->blockage_p
= attr
->static_p
= 0;
5834 attr
->next
= attrs
[index
];
5835 attrs
[index
] = attr
;
5837 *name_p
= attr
->name
;
5842 /* Create internal attribute with the given default value. */
5845 make_internal_attr (const char *name
, rtx value
, int special
)
5847 struct attr_desc
*attr
;
5849 attr
= find_attr (&name
, 1);
5850 if (attr
->default_val
)
5853 attr
->is_numeric
= 1;
5855 attr
->is_special
= (special
& ATTR_SPECIAL
) != 0;
5856 attr
->negative_ok
= (special
& ATTR_NEGATIVE_OK
) != 0;
5857 attr
->unsigned_p
= (special
& ATTR_UNSIGNED
) != 0;
5858 attr
->func_units_p
= (special
& ATTR_FUNC_UNITS
) != 0;
5859 attr
->blockage_p
= (special
& ATTR_BLOCKAGE
) != 0;
5860 attr
->static_p
= (special
& ATTR_STATIC
) != 0;
5861 attr
->default_val
= get_attr_value (value
, attr
, -2);
5864 /* Find the most used value of an attribute. */
5866 static struct attr_value
*
5867 find_most_used (struct attr_desc
*attr
)
5869 struct attr_value
*av
;
5870 struct attr_value
*most_used
;
5876 for (av
= attr
->first_value
; av
; av
= av
->next
)
5877 if (av
->num_insns
> nuses
)
5878 nuses
= av
->num_insns
, most_used
= av
;
5883 /* If an attribute only has a single value used, return it. Otherwise
5887 find_single_value (struct attr_desc
*attr
)
5889 struct attr_value
*av
;
5892 unique_value
= NULL
;
5893 for (av
= attr
->first_value
; av
; av
= av
->next
)
5899 unique_value
= av
->value
;
5902 return unique_value
;
5905 /* Return (attr_value "n") */
5908 make_numeric_value (int n
)
5910 static rtx int_values
[20];
5917 if (n
< 20 && int_values
[n
])
5918 return int_values
[n
];
5920 p
= attr_printf (MAX_DIGITS
, "%d", n
);
5921 exp
= attr_rtx (CONST_STRING
, p
);
5924 int_values
[n
] = exp
;
5930 extend_range (struct range
*range
, int min
, int max
)
5932 if (range
->min
> min
)
5934 if (range
->max
< max
)
5939 copy_rtx_unchanging (rtx orig
)
5941 if (ATTR_IND_SIMPLIFIED_P (orig
) || ATTR_CURR_SIMPLIFIED_P (orig
))
5944 ATTR_CURR_SIMPLIFIED_P (orig
) = 1;
5948 /* Determine if an insn has a constant number of delay slots, i.e., the
5949 number of delay slots is not a function of the length of the insn. */
5952 write_const_num_delay_slots (void)
5954 struct attr_desc
*attr
= find_attr (&num_delay_slots_str
, 0);
5955 struct attr_value
*av
;
5956 struct insn_ent
*ie
;
5960 printf ("int\nconst_num_delay_slots (rtx insn)\n");
5962 printf (" switch (recog_memoized (insn))\n");
5965 for (av
= attr
->first_value
; av
; av
= av
->next
)
5968 walk_attr_value (av
->value
);
5971 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5972 if (ie
->insn_code
!= -1)
5973 printf (" case %d:\n", ie
->insn_code
);
5974 printf (" return 0;\n");
5978 printf (" default:\n");
5979 printf (" return 1;\n");
5980 printf (" }\n}\n\n");
5985 main (int argc
, char **argv
)
5988 struct attr_desc
*attr
;
5989 struct insn_def
*id
;
5993 progname
= "genattrtab";
5996 fatal ("no input file name");
5998 if (init_md_reader_args (argc
, argv
) != SUCCESS_EXIT_CODE
)
5999 return (FATAL_EXIT_CODE
);
6001 obstack_init (hash_obstack
);
6002 obstack_init (temp_obstack
);
6004 /* Set up true and false rtx's */
6005 true_rtx
= rtx_alloc (CONST_INT
);
6006 XWINT (true_rtx
, 0) = 1;
6007 false_rtx
= rtx_alloc (CONST_INT
);
6008 XWINT (false_rtx
, 0) = 0;
6009 ATTR_IND_SIMPLIFIED_P (true_rtx
) = ATTR_IND_SIMPLIFIED_P (false_rtx
) = 1;
6010 ATTR_PERMANENT_P (true_rtx
) = ATTR_PERMANENT_P (false_rtx
) = 1;
6012 alternative_name
= DEF_ATTR_STRING ("alternative");
6013 length_str
= DEF_ATTR_STRING ("length");
6014 delay_type_str
= DEF_ATTR_STRING ("*delay_type");
6015 delay_1_0_str
= DEF_ATTR_STRING ("*delay_1_0");
6016 num_delay_slots_str
= DEF_ATTR_STRING ("*num_delay_slots");
6018 printf ("/* Generated automatically by the program `genattrtab'\n\
6019 from the machine description file `md'. */\n\n");
6021 /* Read the machine description. */
6023 initiate_automaton_gen (argc
, argv
);
6028 desc
= read_md_rtx (&lineno
, &insn_code_number
);
6032 switch (GET_CODE (desc
))
6035 case DEFINE_PEEPHOLE
:
6036 case DEFINE_ASM_ATTRIBUTES
:
6037 gen_insn (desc
, lineno
);
6041 gen_attr (desc
, lineno
);
6045 gen_delay (desc
, lineno
);
6048 case DEFINE_FUNCTION_UNIT
:
6049 gen_unit (desc
, lineno
);
6052 case DEFINE_CPU_UNIT
:
6053 gen_cpu_unit (desc
);
6056 case DEFINE_QUERY_CPU_UNIT
:
6057 gen_query_cpu_unit (desc
);
6065 gen_excl_set (desc
);
6069 gen_presence_set (desc
);
6072 case FINAL_PRESENCE_SET
:
6073 gen_final_presence_set (desc
);
6077 gen_absence_set (desc
);
6080 case FINAL_ABSENCE_SET
:
6081 gen_final_absence_set (desc
);
6084 case DEFINE_AUTOMATON
:
6085 gen_automaton (desc
);
6088 case AUTOMATA_OPTION
:
6089 gen_automata_option (desc
);
6092 case DEFINE_RESERVATION
:
6096 case DEFINE_INSN_RESERVATION
:
6097 gen_insn_reserv (desc
);
6103 if (GET_CODE (desc
) != DEFINE_ASM_ATTRIBUTES
)
6104 insn_index_number
++;
6108 return FATAL_EXIT_CODE
;
6112 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
6113 if (! got_define_asm_attributes
)
6115 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
6116 XVEC (tem
, 0) = rtvec_alloc (0);
6120 /* Expand DEFINE_DELAY information into new attribute. */
6124 if (num_units
|| num_dfa_decls
)
6126 /* Expand DEFINE_FUNCTION_UNIT information into new attributes. */
6128 /* Build DFA, output some functions and expand DFA information
6129 into new attributes. */
6133 printf ("#include \"config.h\"\n");
6134 printf ("#include \"system.h\"\n");
6135 printf ("#include \"coretypes.h\"\n");
6136 printf ("#include \"tm.h\"\n");
6137 printf ("#include \"rtl.h\"\n");
6138 printf ("#include \"tm_p.h\"\n");
6139 printf ("#include \"insn-config.h\"\n");
6140 printf ("#include \"recog.h\"\n");
6141 printf ("#include \"regs.h\"\n");
6142 printf ("#include \"real.h\"\n");
6143 printf ("#include \"output.h\"\n");
6144 printf ("#include \"insn-attr.h\"\n");
6145 printf ("#include \"toplev.h\"\n");
6146 printf ("#include \"flags.h\"\n");
6147 printf ("#include \"function.h\"\n");
6149 printf ("#define operands recog_data.operand\n\n");
6151 /* Make `insn_alternatives'. */
6152 insn_alternatives
= oballoc (insn_code_number
* sizeof (int));
6153 for (id
= defs
; id
; id
= id
->next
)
6154 if (id
->insn_code
>= 0)
6155 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
6157 /* Make `insn_n_alternatives'. */
6158 insn_n_alternatives
= oballoc (insn_code_number
* sizeof (int));
6159 for (id
= defs
; id
; id
= id
->next
)
6160 if (id
->insn_code
>= 0)
6161 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
6163 /* Prepare to write out attribute subroutines by checking everything stored
6164 away and building the attribute cases. */
6168 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6169 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6170 attr
->default_val
->value
6171 = check_attr_value (attr
->default_val
->value
, attr
);
6174 return FATAL_EXIT_CODE
;
6176 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6177 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6180 /* Construct extra attributes for `length'. */
6181 make_length_attrs ();
6183 /* Perform any possible optimizations to speed up compilation. */
6186 /* Now write out all the `gen_attr_...' routines. Do these before the
6187 special routines (specifically before write_function_unit_info), so
6188 that they get defined before they are used. */
6190 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6191 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6193 if (! attr
->is_special
&& ! attr
->is_const
)
6198 = (attr
->name
[0] == '*'
6199 && strcmp (&attr
->name
[1], INSN_ALTS_FUNC_NAME
) == 0);
6201 printf ("\n#if AUTOMATON_ALTS\n");
6202 write_attr_get (attr
);
6204 printf ("#endif\n\n");
6208 /* Write out delay eligibility information, if DEFINE_DELAY present.
6209 (The function to compute the number of delay slots will be written
6213 write_eligible_delay ("delay");
6214 if (have_annul_true
)
6215 write_eligible_delay ("annul_true");
6216 if (have_annul_false
)
6217 write_eligible_delay ("annul_false");
6220 if (num_units
|| num_dfa_decls
)
6222 /* Write out information about function units. */
6223 write_function_unit_info ();
6224 /* Output code for pipeline hazards recognition based on DFA
6225 (deterministic finite state automata. */
6229 /* Write out constant delay slot info. */
6230 write_const_num_delay_slots ();
6232 write_length_unit_log ();
6235 return (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);
6238 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
6240 get_insn_name (int code ATTRIBUTE_UNUSED
)