1 /* Generate code from machine description to compute values of attributes.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2002 Free Software Foundation, Inc.
4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* This program handles insn attributes and the DEFINE_DELAY and
24 DEFINE_FUNCTION_UNIT definitions.
26 It produces a series of functions named `get_attr_...', one for each insn
27 attribute. Each of these is given the rtx for an insn and returns a member
28 of the enum for the attribute.
30 These subroutines have the form of a `switch' on the INSN_CODE (via
31 `recog_memoized'). Each case either returns a constant attribute value
32 or a value that depends on tests on other attributes, the form of
33 operands, or some random C expression (encoded with a SYMBOL_REF
36 If the attribute `alternative', or a random C expression is present,
37 `constrain_operands' is called. If either of these cases of a reference to
38 an operand is found, `extract_insn' is called.
40 The special attribute `length' is also recognized. For this operand,
41 expressions involving the address of an operand or the current insn,
42 (address (pc)), are valid. In this case, an initial pass is made to
43 set all lengths that do not depend on address. Those that do are set to
44 the maximum length. Then each insn that depends on an address is checked
45 and possibly has its length changed. The process repeats until no further
46 changed are made. The resulting lengths are saved for use by
49 A special form of DEFINE_ATTR, where the expression for default value is a
50 CONST expression, indicates an attribute that is constant for a given run
51 of the compiler. The subroutine generated for these attributes has no
52 parameters as it does not depend on any particular insn. Constant
53 attributes are typically used to specify which variety of processor is
56 Internal attributes are defined to handle DEFINE_DELAY and
57 DEFINE_FUNCTION_UNIT. Special routines are output for these cases.
59 This program works by keeping a list of possible values for each attribute.
60 These include the basic attribute choices, default values for attribute, and
61 all derived quantities.
63 As the description file is read, the definition for each insn is saved in a
64 `struct insn_def'. When the file reading is complete, a `struct insn_ent'
65 is created for each insn and chained to the corresponding attribute value,
66 either that specified, or the default.
68 An optimization phase is then run. This simplifies expressions for each
69 insn. EQ_ATTR tests are resolved, whenever possible, to a test that
70 indicates when the attribute has the specified value for the insn. This
71 avoids recursive calls during compilation.
73 The strategy used when processing DEFINE_DELAY and DEFINE_FUNCTION_UNIT
74 definitions is to create arbitrarily complex expressions and have the
75 optimization simplify them.
77 Once optimization is complete, any required routines and definitions
80 An optimization that is not yet implemented is to hoist the constant
81 expressions entirely out of the routines and definitions that are written.
82 A way to do this is to iterate over all possible combinations of values
83 for constant attributes and generate a set of functions for that given
84 combination. An initialization function would be written that evaluates
85 the attributes and installs the corresponding set of routines and
86 definitions (each would be accessed through a pointer).
88 We use the flags in an RTX as follows:
89 `unchanging' (ATTR_IND_SIMPLIFIED_P): This rtx is fully simplified
90 independent of the insn code.
91 `in_struct' (ATTR_CURR_SIMPLIFIED_P): This rtx is fully simplified
92 for the insn code currently being processed (see optimize_attrs).
93 `integrated' (ATTR_PERMANENT_P): This rtx is permanent and unique
95 `volatil' (ATTR_EQ_ATTR_P): During simplify_by_exploding the value of an
96 EQ_ATTR rtx is true if !volatil and false if volatil. */
98 #define ATTR_IND_SIMPLIFIED_P(RTX) (RTX_FLAG((RTX), unchanging))
99 #define ATTR_CURR_SIMPLIFIED_P(RTX) (RTX_FLAG((RTX), in_struct))
100 #define ATTR_PERMANENT_P(RTX) (RTX_FLAG((RTX), integrated))
101 #define ATTR_EQ_ATTR_P(RTX) (RTX_FLAG((RTX), volatil))
107 #include "gensupport.h"
109 #ifdef HAVE_SYS_RESOURCE_H
110 # include <sys/resource.h>
113 /* We must include obstack.h after <sys/time.h>, to avoid lossage with
114 /usr/include/sys/stdtypes.h on Sun OS 4.x. */
118 #include "genattrtab.h"
120 static struct obstack obstack1
, obstack2
;
121 struct obstack
*hash_obstack
= &obstack1
;
122 struct obstack
*temp_obstack
= &obstack2
;
124 /* enough space to reserve for printing out ints */
125 #define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
127 /* Define structures used to record attributes and values. */
129 /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
130 encountered, we store all the relevant information into a
131 `struct insn_def'. This is done to allow attribute definitions to occur
132 anywhere in the file. */
136 struct insn_def
*next
; /* Next insn in chain. */
137 rtx def
; /* The DEFINE_... */
138 int insn_code
; /* Instruction number. */
139 int insn_index
; /* Expression numer in file, for errors. */
140 int lineno
; /* Line number. */
141 int num_alternatives
; /* Number of alternatives. */
142 int vec_idx
; /* Index of attribute vector in `def'. */
145 /* Once everything has been read in, we store in each attribute value a list
146 of insn codes that have that value. Here is the structure used for the
151 struct insn_ent
*next
; /* Next in chain. */
152 int insn_code
; /* Instruction number. */
153 int insn_index
; /* Index of definition in file */
154 int lineno
; /* Line number. */
157 /* Each value of an attribute (either constant or computed) is assigned a
158 structure which is used as the listhead of the insns that have that
163 rtx value
; /* Value of attribute. */
164 struct attr_value
*next
; /* Next attribute value in chain. */
165 struct insn_ent
*first_insn
; /* First insn with this value. */
166 int num_insns
; /* Number of insns with this value. */
167 int has_asm_insn
; /* True if this value used for `asm' insns */
170 /* Structure for each attribute. */
174 char *name
; /* Name of attribute. */
175 struct attr_desc
*next
; /* Next attribute. */
176 unsigned is_numeric
: 1; /* Values of this attribute are numeric. */
177 unsigned negative_ok
: 1; /* Allow negative numeric values. */
178 unsigned unsigned_p
: 1; /* Make the output function unsigned int. */
179 unsigned is_const
: 1; /* Attribute value constant for each run. */
180 unsigned is_special
: 1; /* Don't call `write_attr_set'. */
181 unsigned func_units_p
: 1; /* this is the function_units attribute */
182 unsigned blockage_p
: 1; /* this is the blockage range function */
183 struct attr_value
*first_value
; /* First value of this attribute. */
184 struct attr_value
*default_val
; /* Default value for this attribute. */
185 int lineno
; /* Line number. */
188 #define NULL_ATTR (struct attr_desc *) NULL
190 /* A range of values. */
198 /* Structure for each DEFINE_DELAY. */
202 rtx def
; /* DEFINE_DELAY expression. */
203 struct delay_desc
*next
; /* Next DEFINE_DELAY. */
204 int num
; /* Number of DEFINE_DELAY, starting at 1. */
205 int lineno
; /* Line number. */
208 /* Record information about each DEFINE_FUNCTION_UNIT. */
210 struct function_unit_op
212 rtx condexp
; /* Expression TRUE for applicable insn. */
213 struct function_unit_op
*next
; /* Next operation for this function unit. */
214 int num
; /* Ordinal for this operation type in unit. */
215 int ready
; /* Cost until data is ready. */
216 int issue_delay
; /* Cost until unit can accept another insn. */
217 rtx conflict_exp
; /* Expression TRUE for insns incurring issue delay. */
218 rtx issue_exp
; /* Expression computing issue delay. */
219 int lineno
; /* Line number. */
222 /* Record information about each function unit mentioned in a
223 DEFINE_FUNCTION_UNIT. */
227 const char *name
; /* Function unit name. */
228 struct function_unit
*next
; /* Next function unit. */
229 int num
; /* Ordinal of this unit type. */
230 int multiplicity
; /* Number of units of this type. */
231 int simultaneity
; /* Maximum number of simultaneous insns
232 on this function unit or 0 if unlimited. */
233 rtx condexp
; /* Expression TRUE for insn needing unit. */
234 int num_opclasses
; /* Number of different operation types. */
235 struct function_unit_op
*ops
; /* Pointer to first operation type. */
236 int needs_conflict_function
; /* Nonzero if a conflict function required. */
237 int needs_blockage_function
; /* Nonzero if a blockage function required. */
238 int needs_range_function
; /* Nonzero if blockage range function needed. */
239 rtx default_cost
; /* Conflict cost, if constant. */
240 struct range issue_delay
; /* Range of issue delay values. */
241 int max_blockage
; /* Maximum time an insn blocks the unit. */
242 int first_lineno
; /* First seen line number. */
245 /* Listheads of above structures. */
247 /* This one is indexed by the first character of the attribute name. */
248 #define MAX_ATTRS_INDEX 256
249 static struct attr_desc
*attrs
[MAX_ATTRS_INDEX
];
250 static struct insn_def
*defs
;
251 static struct delay_desc
*delays
;
252 static struct function_unit
*units
;
254 /* An expression where all the unknown terms are EQ_ATTR tests can be
255 rearranged into a COND provided we can enumerate all possible
256 combinations of the unknown values. The set of combinations become the
257 tests of the COND; the value of the expression given that combination is
258 computed and becomes the corresponding value. To do this, we must be
259 able to enumerate all values for each attribute used in the expression
260 (currently, we give up if we find a numeric attribute).
262 If the set of EQ_ATTR tests used in an expression tests the value of N
263 different attributes, the list of all possible combinations can be made
264 by walking the N-dimensional attribute space defined by those
265 attributes. We record each of these as a struct dimension.
267 The algorithm relies on sharing EQ_ATTR nodes: if two nodes in an
268 expression are the same, the will also have the same address. We find
269 all the EQ_ATTR nodes by marking them ATTR_EQ_ATTR_P. This bit later
270 represents the value of an EQ_ATTR node, so once all nodes are marked,
271 they are also given an initial value of FALSE.
273 We then separate the set of EQ_ATTR nodes into dimensions for each
274 attribute and put them on the VALUES list. Terms are added as needed by
275 `add_values_to_cover' so that all possible values of the attribute are
278 Each dimension also has a current value. This is the node that is
279 currently considered to be TRUE. If this is one of the nodes added by
280 `add_values_to_cover', all the EQ_ATTR tests in the original expression
281 will be FALSE. Otherwise, only the CURRENT_VALUE will be true.
283 NUM_VALUES is simply the length of the VALUES list and is there for
286 Once the dimensions are created, the algorithm enumerates all possible
287 values and computes the current value of the given expression. */
291 struct attr_desc
*attr
; /* Attribute for this dimension. */
292 rtx values
; /* List of attribute values used. */
293 rtx current_value
; /* Position in the list for the TRUE value. */
294 int num_values
; /* Length of the values list. */
297 /* Other variables. */
299 static int insn_code_number
;
300 static int insn_index_number
;
301 static int got_define_asm_attributes
;
302 static int must_extract
;
303 static int must_constrain
;
304 static int address_used
;
305 static int length_used
;
306 static int num_delays
;
307 static int have_annul_true
, have_annul_false
;
308 static int num_units
, num_unit_opclasses
;
309 static int num_insn_ents
;
313 /* Used as operand to `operate_exp': */
315 enum operator {PLUS_OP
, MINUS_OP
, POS_MINUS_OP
, EQ_OP
, OR_OP
, ORX_OP
, MAX_OP
, MIN_OP
, RANGE_OP
};
317 /* Stores, for each insn code, the number of constraint alternatives. */
319 static int *insn_n_alternatives
;
321 /* Stores, for each insn code, a bitmap that has bits on for each possible
324 static int *insn_alternatives
;
326 /* If nonzero, assume that the `alternative' attr has this value.
327 This is the hashed, unique string for the numeral
328 whose value is chosen alternative. */
330 static const char *current_alternative_string
;
332 /* Used to simplify expressions. */
334 static rtx true_rtx
, false_rtx
;
336 /* Used to reduce calls to `strcmp' */
338 static char *alternative_name
;
340 /* Indicate that REG_DEAD notes are valid if dead_or_set_p is ever
343 int reload_completed
= 0;
345 /* Some machines test `optimize' in macros called from rtlanal.c, so we need
346 to define it here. */
350 /* Simplify an expression. Only call the routine if there is something to
352 #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
353 (ATTR_IND_SIMPLIFIED_P (EXP) || ATTR_CURR_SIMPLIFIED_P (EXP) ? (EXP) \
354 : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
356 /* Simplify (eq_attr ("alternative") ...)
357 when we are working with a particular alternative. */
358 #define SIMPLIFY_ALTERNATIVE(EXP) \
359 if (current_alternative_string \
360 && GET_CODE ((EXP)) == EQ_ATTR \
361 && XSTR ((EXP), 0) == alternative_name) \
362 (EXP) = (XSTR ((EXP), 1) == current_alternative_string \
363 ? true_rtx : false_rtx);
365 /* These are referenced by rtlanal.c and hence need to be defined somewhere.
366 They won't actually be used. */
368 rtx global_rtl
[GR_MAX
];
369 rtx pic_offset_table_rtx
;
371 static void attr_hash_add_rtx
PARAMS ((int, rtx
));
372 static void attr_hash_add_string
PARAMS ((int, char *));
373 static rtx attr_rtx
PARAMS ((enum rtx_code
, ...));
374 static rtx attr_rtx_1
PARAMS ((enum rtx_code
, va_list));
375 static char *attr_string
PARAMS ((const char *, int));
376 static rtx check_attr_value
PARAMS ((rtx
, struct attr_desc
*));
377 static rtx convert_set_attr_alternative
PARAMS ((rtx
, struct insn_def
*));
378 static rtx convert_set_attr
PARAMS ((rtx
, struct insn_def
*));
379 static void check_defs
PARAMS ((void));
381 static rtx convert_const_symbol_ref
PARAMS ((rtx
, struct attr_desc
*));
383 static rtx make_canonical
PARAMS ((struct attr_desc
*, rtx
));
384 static struct attr_value
*get_attr_value
PARAMS ((rtx
, struct attr_desc
*, int));
385 static rtx copy_rtx_unchanging
PARAMS ((rtx
));
386 static rtx copy_boolean
PARAMS ((rtx
));
387 static void expand_delays
PARAMS ((void));
388 static rtx operate_exp
PARAMS ((enum operator, rtx
, rtx
));
389 static void expand_units
PARAMS ((void));
390 static rtx simplify_knowing
PARAMS ((rtx
, rtx
));
391 static rtx encode_units_mask
PARAMS ((rtx
));
392 static void fill_attr
PARAMS ((struct attr_desc
*));
393 static rtx substitute_address
PARAMS ((rtx
, rtx (*) (rtx
), rtx (*) (rtx
)));
394 static void make_length_attrs
PARAMS ((void));
395 static rtx identity_fn
PARAMS ((rtx
));
396 static rtx zero_fn
PARAMS ((rtx
));
397 static rtx one_fn
PARAMS ((rtx
));
398 static rtx max_fn
PARAMS ((rtx
));
399 static void write_length_unit_log
PARAMS ((void));
400 static rtx simplify_cond
PARAMS ((rtx
, int, int));
402 static rtx simplify_by_alternatives
PARAMS ((rtx
, int, int));
404 static rtx simplify_by_exploding
PARAMS ((rtx
));
405 static int find_and_mark_used_attributes
PARAMS ((rtx
, rtx
*, int *));
406 static void unmark_used_attributes
PARAMS ((rtx
, struct dimension
*, int));
407 static int add_values_to_cover
PARAMS ((struct dimension
*));
408 static int increment_current_value
PARAMS ((struct dimension
*, int));
409 static rtx test_for_current_value
PARAMS ((struct dimension
*, int));
410 static rtx simplify_with_current_value
PARAMS ((rtx
, struct dimension
*, int));
411 static rtx simplify_with_current_value_aux
PARAMS ((rtx
));
412 static void clear_struct_flag
PARAMS ((rtx
));
413 static int count_sub_rtxs
PARAMS ((rtx
, int));
414 static void remove_insn_ent
PARAMS ((struct attr_value
*, struct insn_ent
*));
415 static void insert_insn_ent
PARAMS ((struct attr_value
*, struct insn_ent
*));
416 static rtx insert_right_side
PARAMS ((enum rtx_code
, rtx
, rtx
, int, int));
417 static rtx make_alternative_compare
PARAMS ((int));
418 static int compute_alternative_mask
PARAMS ((rtx
, enum rtx_code
));
419 static rtx evaluate_eq_attr
PARAMS ((rtx
, rtx
, int, int));
420 static rtx simplify_and_tree
PARAMS ((rtx
, rtx
*, int, int));
421 static rtx simplify_or_tree
PARAMS ((rtx
, rtx
*, int, int));
422 static rtx simplify_test_exp
PARAMS ((rtx
, int, int));
423 static rtx simplify_test_exp_in_temp
PARAMS ((rtx
, int, int));
424 static void optimize_attrs
PARAMS ((void));
425 static void gen_attr
PARAMS ((rtx
, int));
426 static int count_alternatives
PARAMS ((rtx
));
427 static int compares_alternatives_p
PARAMS ((rtx
));
428 static int contained_in_p
PARAMS ((rtx
, rtx
));
429 static void gen_insn
PARAMS ((rtx
, int));
430 static void gen_delay
PARAMS ((rtx
, int));
431 static void gen_unit
PARAMS ((rtx
, int));
432 static void write_test_expr
PARAMS ((rtx
, int));
433 static int max_attr_value
PARAMS ((rtx
, int*));
434 static int or_attr_value
PARAMS ((rtx
, int*));
435 static void walk_attr_value
PARAMS ((rtx
));
436 static void write_attr_get
PARAMS ((struct attr_desc
*));
437 static rtx eliminate_known_true
PARAMS ((rtx
, rtx
, int, int));
438 static void write_attr_set
PARAMS ((struct attr_desc
*, int, rtx
,
439 const char *, const char *, rtx
,
441 static void write_attr_case
PARAMS ((struct attr_desc
*, struct attr_value
*,
442 int, const char *, const char *, int, rtx
));
443 static void write_unit_name
PARAMS ((const char *, int, const char *));
444 static void write_attr_valueq
PARAMS ((struct attr_desc
*, const char *));
445 static void write_attr_value
PARAMS ((struct attr_desc
*, rtx
));
446 static void write_upcase
PARAMS ((const char *));
447 static void write_indent
PARAMS ((int));
448 static void write_eligible_delay
PARAMS ((const char *));
449 static void write_function_unit_info
PARAMS ((void));
450 static void write_complex_function
PARAMS ((struct function_unit
*, const char *,
452 static int write_expr_attr_cache
PARAMS ((rtx
, struct attr_desc
*));
453 static void write_toplevel_expr
PARAMS ((rtx
));
454 static void write_const_num_delay_slots
PARAMS ((void));
455 static char *next_comma_elt
PARAMS ((const char **));
456 static struct attr_desc
*find_attr
PARAMS ((const char *, int));
457 static struct attr_value
*find_most_used
PARAMS ((struct attr_desc
*));
458 static rtx find_single_value
PARAMS ((struct attr_desc
*));
459 static void extend_range
PARAMS ((struct range
*, int, int));
460 static rtx attr_eq
PARAMS ((const char *, const char *));
461 static const char *attr_numeral
PARAMS ((int));
462 static int attr_equal_p
PARAMS ((rtx
, rtx
));
463 static rtx attr_copy_rtx
PARAMS ((rtx
));
464 static int attr_rtx_cost
PARAMS ((rtx
));
466 #define oballoc(size) obstack_alloc (hash_obstack, size)
468 /* Hash table for sharing RTL and strings. */
470 /* Each hash table slot is a bucket containing a chain of these structures.
471 Strings are given negative hash codes; RTL expressions are given positive
476 struct attr_hash
*next
; /* Next structure in the bucket. */
477 int hashcode
; /* Hash code of this rtx or string. */
480 char *str
; /* The string (negative hash codes) */
481 rtx rtl
; /* or the RTL recorded here. */
485 /* Now here is the hash table. When recording an RTL, it is added to
486 the slot whose index is the hash code mod the table size. Note
487 that the hash table is used for several kinds of RTL (see attr_rtx)
488 and for strings. While all these live in the same table, they are
489 completely independent, and the hash code is computed differently
492 #define RTL_HASH_SIZE 4093
493 struct attr_hash
*attr_hash_table
[RTL_HASH_SIZE
];
495 /* Here is how primitive or already-shared RTL's hash
497 #define RTL_HASH(RTL) ((long) (RTL) & 0777777)
499 /* Add an entry to the hash table for RTL with hash code HASHCODE. */
502 attr_hash_add_rtx (hashcode
, rtl
)
508 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
509 sizeof (struct attr_hash
));
510 h
->hashcode
= hashcode
;
512 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
513 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
516 /* Add an entry to the hash table for STRING with hash code HASHCODE. */
519 attr_hash_add_string (hashcode
, str
)
525 h
= (struct attr_hash
*) obstack_alloc (hash_obstack
,
526 sizeof (struct attr_hash
));
527 h
->hashcode
= -hashcode
;
529 h
->next
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
];
530 attr_hash_table
[hashcode
% RTL_HASH_SIZE
] = h
;
533 /* Generate an RTL expression, but avoid duplicates.
534 Set the ATTR_PERMANENT_P flag for these permanent objects.
536 In some cases we cannot uniquify; then we return an ordinary
537 impermanent rtx with ATTR_PERMANENT_P clear.
539 Args are like gen_rtx, but without the mode:
541 rtx attr_rtx (code, [element1, ..., elementn]) */
548 rtx rt_val
= NULL_RTX
;/* RTX to return to caller... */
551 struct obstack
*old_obstack
= rtl_obstack
;
553 /* For each of several cases, search the hash table for an existing entry.
554 Use that entry if one is found; otherwise create a new RTL and add it
557 if (GET_RTX_CLASS (code
) == '1')
559 rtx arg0
= va_arg (p
, rtx
);
561 /* A permanent object cannot point to impermanent ones. */
562 if (! ATTR_PERMANENT_P (arg0
))
564 rt_val
= rtx_alloc (code
);
565 XEXP (rt_val
, 0) = arg0
;
569 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
570 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
571 if (h
->hashcode
== hashcode
572 && GET_CODE (h
->u
.rtl
) == code
573 && XEXP (h
->u
.rtl
, 0) == arg0
)
578 rtl_obstack
= hash_obstack
;
579 rt_val
= rtx_alloc (code
);
580 XEXP (rt_val
, 0) = arg0
;
583 else if (GET_RTX_CLASS (code
) == 'c'
584 || GET_RTX_CLASS (code
) == '2'
585 || GET_RTX_CLASS (code
) == '<')
587 rtx arg0
= va_arg (p
, rtx
);
588 rtx arg1
= va_arg (p
, rtx
);
590 /* A permanent object cannot point to impermanent ones. */
591 if (! ATTR_PERMANENT_P (arg0
) || ! ATTR_PERMANENT_P (arg1
))
593 rt_val
= rtx_alloc (code
);
594 XEXP (rt_val
, 0) = arg0
;
595 XEXP (rt_val
, 1) = arg1
;
599 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
600 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
601 if (h
->hashcode
== hashcode
602 && GET_CODE (h
->u
.rtl
) == code
603 && XEXP (h
->u
.rtl
, 0) == arg0
604 && XEXP (h
->u
.rtl
, 1) == arg1
)
609 rtl_obstack
= hash_obstack
;
610 rt_val
= rtx_alloc (code
);
611 XEXP (rt_val
, 0) = arg0
;
612 XEXP (rt_val
, 1) = arg1
;
615 else if (GET_RTX_LENGTH (code
) == 1
616 && GET_RTX_FORMAT (code
)[0] == 's')
618 char *arg0
= va_arg (p
, char *);
620 if (code
== SYMBOL_REF
)
621 arg0
= attr_string (arg0
, strlen (arg0
));
623 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
));
624 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
625 if (h
->hashcode
== hashcode
626 && GET_CODE (h
->u
.rtl
) == code
627 && XSTR (h
->u
.rtl
, 0) == arg0
)
632 rtl_obstack
= hash_obstack
;
633 rt_val
= rtx_alloc (code
);
634 XSTR (rt_val
, 0) = arg0
;
637 else if (GET_RTX_LENGTH (code
) == 2
638 && GET_RTX_FORMAT (code
)[0] == 's'
639 && GET_RTX_FORMAT (code
)[1] == 's')
641 char *arg0
= va_arg (p
, char *);
642 char *arg1
= va_arg (p
, char *);
644 hashcode
= ((HOST_WIDE_INT
) code
+ RTL_HASH (arg0
) + RTL_HASH (arg1
));
645 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
646 if (h
->hashcode
== hashcode
647 && GET_CODE (h
->u
.rtl
) == code
648 && XSTR (h
->u
.rtl
, 0) == arg0
649 && XSTR (h
->u
.rtl
, 1) == arg1
)
654 rtl_obstack
= hash_obstack
;
655 rt_val
= rtx_alloc (code
);
656 XSTR (rt_val
, 0) = arg0
;
657 XSTR (rt_val
, 1) = arg1
;
660 else if (code
== CONST_INT
)
662 HOST_WIDE_INT arg0
= va_arg (p
, HOST_WIDE_INT
);
672 int i
; /* Array indices... */
673 const char *fmt
; /* Current rtx's format... */
675 rt_val
= rtx_alloc (code
); /* Allocate the storage space. */
677 fmt
= GET_RTX_FORMAT (code
); /* Find the right format... */
678 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
682 case '0': /* Unused field. */
685 case 'i': /* An integer? */
686 XINT (rt_val
, i
) = va_arg (p
, int);
689 case 'w': /* A wide integer? */
690 XWINT (rt_val
, i
) = va_arg (p
, HOST_WIDE_INT
);
693 case 's': /* A string? */
694 XSTR (rt_val
, i
) = va_arg (p
, char *);
697 case 'e': /* An expression? */
698 case 'u': /* An insn? Same except when printing. */
699 XEXP (rt_val
, i
) = va_arg (p
, rtx
);
702 case 'E': /* An RTX vector? */
703 XVEC (rt_val
, i
) = va_arg (p
, rtvec
);
713 rtl_obstack
= old_obstack
;
714 attr_hash_add_rtx (hashcode
, rt_val
);
715 ATTR_PERMANENT_P (rt_val
) = 1;
720 attr_rtx
VPARAMS ((enum rtx_code code
, ...))
725 VA_FIXEDARG (p
, enum rtx_code
, code
);
726 result
= attr_rtx_1 (code
, p
);
731 /* Create a new string printed with the printf line arguments into a space
732 of at most LEN bytes:
734 rtx attr_printf (len, format, [arg1, ..., argn]) */
737 attr_printf
VPARAMS ((unsigned int len
, const char *fmt
, ...))
742 VA_FIXEDARG (p
, unsigned int, len
);
743 VA_FIXEDARG (p
, const char *, fmt
);
745 if (len
> sizeof str
- 1) /* Leave room for \0. */
748 vsprintf (str
, fmt
, p
);
751 return attr_string (str
, strlen (str
));
755 attr_eq (name
, value
)
756 const char *name
, *value
;
758 return attr_rtx (EQ_ATTR
, attr_string (name
, strlen (name
)),
759 attr_string (value
, strlen (value
)));
766 return XSTR (make_numeric_value (n
), 0);
769 /* Return a permanent (possibly shared) copy of a string STR (not assumed
770 to be null terminated) with LEN bytes. */
773 attr_string (str
, len
)
782 /* Compute the hash code. */
783 hashcode
= (len
+ 1) * 613 + (unsigned) str
[0];
784 for (i
= 1; i
<= len
; i
+= 2)
785 hashcode
= ((hashcode
* 613) + (unsigned) str
[i
]);
787 hashcode
= -hashcode
;
789 /* Search the table for the string. */
790 for (h
= attr_hash_table
[hashcode
% RTL_HASH_SIZE
]; h
; h
= h
->next
)
791 if (h
->hashcode
== -hashcode
&& h
->u
.str
[0] == str
[0]
792 && !strncmp (h
->u
.str
, str
, len
))
793 return h
->u
.str
; /* <-- return if found. */
795 /* Not found; create a permanent copy and add it to the hash table. */
796 new_str
= (char *) obstack_alloc (hash_obstack
, len
+ 1);
797 memcpy (new_str
, str
, len
);
799 attr_hash_add_string (hashcode
, new_str
);
801 return new_str
; /* Return the new string. */
804 /* Check two rtx's for equality of contents,
805 taking advantage of the fact that if both are hashed
806 then they can't be equal unless they are the same object. */
812 return (x
== y
|| (! (ATTR_PERMANENT_P (x
) && ATTR_PERMANENT_P (y
))
813 && rtx_equal_p (x
, y
)));
816 /* Copy an attribute value expression,
817 descending to all depths, but not copying any
818 permanent hashed subexpressions. */
827 const char *format_ptr
;
829 /* No need to copy a permanent object. */
830 if (ATTR_PERMANENT_P (orig
))
833 code
= GET_CODE (orig
);
852 copy
= rtx_alloc (code
);
853 PUT_MODE (copy
, GET_MODE (orig
));
854 ATTR_IND_SIMPLIFIED_P (copy
) = ATTR_IND_SIMPLIFIED_P (orig
);
855 ATTR_CURR_SIMPLIFIED_P (copy
) = ATTR_CURR_SIMPLIFIED_P (orig
);
856 ATTR_PERMANENT_P (copy
) = ATTR_PERMANENT_P (orig
);
857 ATTR_EQ_ATTR_P (copy
) = ATTR_EQ_ATTR_P (orig
);
859 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
861 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
863 switch (*format_ptr
++)
866 XEXP (copy
, i
) = XEXP (orig
, i
);
867 if (XEXP (orig
, i
) != NULL
)
868 XEXP (copy
, i
) = attr_copy_rtx (XEXP (orig
, i
));
873 XVEC (copy
, i
) = XVEC (orig
, i
);
874 if (XVEC (orig
, i
) != NULL
)
876 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
877 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
878 XVECEXP (copy
, i
, j
) = attr_copy_rtx (XVECEXP (orig
, i
, j
));
884 XINT (copy
, i
) = XINT (orig
, i
);
888 XWINT (copy
, i
) = XWINT (orig
, i
);
893 XSTR (copy
, i
) = XSTR (orig
, i
);
903 /* Given a test expression for an attribute, ensure it is validly formed.
904 IS_CONST indicates whether the expression is constant for each compiler
905 run (a constant expression may not test any particular insn).
907 Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
908 and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
909 test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
911 Update the string address in EQ_ATTR expression to be the same used
912 in the attribute (or `alternative_name') to speed up subsequent
913 `find_attr' calls and eliminate most `strcmp' calls.
915 Return the new expression, if any. */
918 check_attr_test (exp
, is_const
, 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"))
945 XSTR (exp
, 0) = alternative_name
;
946 /* This can't be simplified any further. */
947 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
951 fatal ("unknown attribute `%s' in EQ_ATTR", XSTR (exp
, 0));
954 if (is_const
&& ! attr
->is_const
)
955 fatal ("constant expression uses insn attribute `%s' in EQ_ATTR",
958 /* Copy this just to make it permanent,
959 so expressions using it can be permanent too. */
960 exp
= attr_eq (XSTR (exp
, 0), XSTR (exp
, 1));
962 /* It shouldn't be possible to simplify the value given to a
963 constant attribute, so don't expand this until it's time to
964 write the test expression. */
966 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
968 if (attr
->is_numeric
)
970 for (p
= XSTR (exp
, 1); *p
; p
++)
972 fatal ("attribute `%s' takes only numeric values",
977 for (av
= attr
->first_value
; av
; av
= av
->next
)
978 if (GET_CODE (av
->value
) == CONST_STRING
979 && ! strcmp (XSTR (exp
, 1), XSTR (av
->value
, 0)))
983 fatal ("unknown value `%s' for `%s' attribute",
984 XSTR (exp
, 1), XSTR (exp
, 0));
989 /* Make an IOR tree of the possible values. */
991 name_ptr
= XSTR (exp
, 1);
992 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
994 newexp
= attr_eq (XSTR (exp
, 0), p
);
995 orexp
= insert_right_side (IOR
, orexp
, newexp
, -2, -2);
998 return check_attr_test (orexp
, is_const
, lineno
);
1006 /* Either TRUE or FALSE. */
1014 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
1015 XEXP (exp
, 1) = check_attr_test (XEXP (exp
, 1), is_const
, lineno
);
1019 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0), is_const
, lineno
);
1025 fatal ("RTL operator \"%s\" not valid in constant attribute test",
1026 GET_RTX_NAME (GET_CODE (exp
)));
1027 /* These cases can't be simplified. */
1028 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1031 case LE
: case LT
: case GT
: case GE
:
1032 case LEU
: case LTU
: case GTU
: case GEU
:
1034 if (GET_CODE (XEXP (exp
, 0)) == SYMBOL_REF
1035 && GET_CODE (XEXP (exp
, 1)) == SYMBOL_REF
)
1036 exp
= attr_rtx (GET_CODE (exp
),
1037 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 0), 0)),
1038 attr_rtx (SYMBOL_REF
, XSTR (XEXP (exp
, 1), 0)));
1039 /* These cases can't be simplified. */
1040 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1046 /* These cases are valid for constant attributes, but can't be
1048 exp
= attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1049 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1053 fatal ("RTL operator \"%s\" not valid in attribute test",
1054 GET_RTX_NAME (GET_CODE (exp
)));
1060 /* Given an expression, ensure that it is validly formed and that all named
1061 attribute values are valid for the given attribute. Issue a fatal error
1062 if not. If no attribute is specified, assume a numeric attribute.
1064 Return a perhaps modified replacement expression for the value. */
1067 check_attr_value (exp
, attr
)
1069 struct attr_desc
*attr
;
1071 struct attr_value
*av
;
1075 switch (GET_CODE (exp
))
1078 if (attr
&& ! attr
->is_numeric
)
1080 message_with_line (attr
->lineno
,
1081 "CONST_INT not valid for non-numeric attribute %s",
1087 if (INTVAL (exp
) < 0 && ! attr
->negative_ok
)
1089 message_with_line (attr
->lineno
,
1090 "negative numeric value specified for attribute %s",
1098 if (! strcmp (XSTR (exp
, 0), "*"))
1101 if (attr
== 0 || attr
->is_numeric
)
1104 if (attr
&& attr
->negative_ok
&& *p
== '-')
1109 message_with_line (attr
? attr
->lineno
: 0,
1110 "non-numeric value for numeric attribute %s",
1111 attr
? attr
->name
: "internal");
1118 for (av
= attr
->first_value
; av
; av
= av
->next
)
1119 if (GET_CODE (av
->value
) == CONST_STRING
1120 && ! strcmp (XSTR (av
->value
, 0), XSTR (exp
, 0)))
1125 message_with_line (attr
->lineno
,
1126 "unknown value `%s' for `%s' attribute",
1127 XSTR (exp
, 0), attr
? attr
->name
: "internal");
1133 XEXP (exp
, 0) = check_attr_test (XEXP (exp
, 0),
1134 attr
? attr
->is_const
: 0,
1135 attr
? attr
->lineno
: 0);
1136 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1137 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
1145 if (attr
&& !attr
->is_numeric
)
1147 message_with_line (attr
->lineno
,
1148 "invalid operation `%s' for non-numeric attribute value",
1149 GET_RTX_NAME (GET_CODE (exp
)));
1157 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1158 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1162 XEXP (exp
, 0) = check_attr_value (XEXP (exp
, 0), attr
);
1166 if (XVECLEN (exp
, 0) % 2 != 0)
1168 message_with_line (attr
->lineno
,
1169 "first operand of COND must have even length");
1174 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1176 XVECEXP (exp
, 0, i
) = check_attr_test (XVECEXP (exp
, 0, i
),
1177 attr
? attr
->is_const
: 0,
1178 attr
? attr
->lineno
: 0);
1179 XVECEXP (exp
, 0, i
+ 1)
1180 = check_attr_value (XVECEXP (exp
, 0, i
+ 1), attr
);
1183 XEXP (exp
, 1) = check_attr_value (XEXP (exp
, 1), attr
);
1188 struct attr_desc
*attr2
= find_attr (XSTR (exp
, 0), 0);
1191 message_with_line (attr
? attr
->lineno
: 0,
1192 "unknown attribute `%s' in ATTR",
1196 else if (attr
&& attr
->is_const
&& ! attr2
->is_const
)
1198 message_with_line (attr
->lineno
,
1199 "non-constant attribute `%s' referenced from `%s'",
1200 XSTR (exp
, 0), attr
->name
);
1204 && (attr
->is_numeric
!= attr2
->is_numeric
1205 || (! attr
->negative_ok
&& attr2
->negative_ok
)))
1207 message_with_line (attr
->lineno
,
1208 "numeric attribute mismatch calling `%s' from `%s'",
1209 XSTR (exp
, 0), attr
->name
);
1216 /* A constant SYMBOL_REF is valid as a constant attribute test and
1217 is expanded later by make_canonical into a COND. In a non-constant
1218 attribute test, it is left be. */
1219 return attr_rtx (SYMBOL_REF
, XSTR (exp
, 0));
1222 message_with_line (attr
? attr
->lineno
: 0,
1223 "invalid operation `%s' for attribute value",
1224 GET_RTX_NAME (GET_CODE (exp
)));
1232 /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
1233 It becomes a COND with each test being (eq_attr "alternative "n") */
1236 convert_set_attr_alternative (exp
, id
)
1238 struct insn_def
*id
;
1240 int num_alt
= id
->num_alternatives
;
1244 if (XVECLEN (exp
, 1) != num_alt
)
1246 message_with_line (id
->lineno
,
1247 "bad number of entries in SET_ATTR_ALTERNATIVE");
1252 /* Make a COND with all tests but the last. Select the last value via the
1254 condexp
= rtx_alloc (COND
);
1255 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1257 for (i
= 0; i
< num_alt
- 1; i
++)
1260 p
= attr_numeral (i
);
1262 XVECEXP (condexp
, 0, 2 * i
) = attr_eq (alternative_name
, p
);
1263 XVECEXP (condexp
, 0, 2 * i
+ 1) = XVECEXP (exp
, 1, i
);
1266 XEXP (condexp
, 1) = XVECEXP (exp
, 1, i
);
1268 return attr_rtx (SET
, attr_rtx (ATTR
, XSTR (exp
, 0)), condexp
);
1271 /* Given a SET_ATTR, convert to the appropriate SET. If a comma-separated
1272 list of values is given, convert to SET_ATTR_ALTERNATIVE first. */
1275 convert_set_attr (exp
, id
)
1277 struct insn_def
*id
;
1280 const char *name_ptr
;
1284 /* See how many alternative specified. */
1285 n
= n_comma_elts (XSTR (exp
, 1));
1287 return attr_rtx (SET
,
1288 attr_rtx (ATTR
, XSTR (exp
, 0)),
1289 attr_rtx (CONST_STRING
, XSTR (exp
, 1)));
1291 newexp
= rtx_alloc (SET_ATTR_ALTERNATIVE
);
1292 XSTR (newexp
, 0) = XSTR (exp
, 0);
1293 XVEC (newexp
, 1) = rtvec_alloc (n
);
1295 /* Process each comma-separated name. */
1296 name_ptr
= XSTR (exp
, 1);
1298 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
1299 XVECEXP (newexp
, 1, n
++) = attr_rtx (CONST_STRING
, p
);
1301 return convert_set_attr_alternative (newexp
, id
);
1304 /* Scan all definitions, checking for validity. Also, convert any SET_ATTR
1305 and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
1311 struct insn_def
*id
;
1312 struct attr_desc
*attr
;
1316 for (id
= defs
; id
; id
= id
->next
)
1318 if (XVEC (id
->def
, id
->vec_idx
) == NULL
)
1321 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
1323 value
= XVECEXP (id
->def
, id
->vec_idx
, i
);
1324 switch (GET_CODE (value
))
1327 if (GET_CODE (XEXP (value
, 0)) != ATTR
)
1329 message_with_line (id
->lineno
, "bad attribute set");
1335 case SET_ATTR_ALTERNATIVE
:
1336 value
= convert_set_attr_alternative (value
, id
);
1340 value
= convert_set_attr (value
, id
);
1344 message_with_line (id
->lineno
, "invalid attribute code %s",
1345 GET_RTX_NAME (GET_CODE (value
)));
1349 if (value
== NULL_RTX
)
1352 if ((attr
= find_attr (XSTR (XEXP (value
, 0), 0), 0)) == NULL
)
1354 message_with_line (id
->lineno
, "unknown attribute %s",
1355 XSTR (XEXP (value
, 0), 0));
1360 XVECEXP (id
->def
, id
->vec_idx
, i
) = value
;
1361 XEXP (value
, 1) = check_attr_value (XEXP (value
, 1), attr
);
1367 /* Given a constant SYMBOL_REF expression, convert to a COND that
1368 explicitly tests each enumerated value. */
1371 convert_const_symbol_ref (exp
, attr
)
1373 struct attr_desc
*attr
;
1376 struct attr_value
*av
;
1380 for (av
= attr
->first_value
; av
; av
= av
->next
)
1383 /* Make a COND with all tests but the last, and in the original order.
1384 Select the last value via the default. Note that the attr values
1385 are constructed in reverse order. */
1387 condexp
= rtx_alloc (COND
);
1388 XVEC (condexp
, 0) = rtvec_alloc ((num_alt
- 1) * 2);
1389 av
= attr
->first_value
;
1390 XEXP (condexp
, 1) = av
->value
;
1392 for (i
= num_alt
- 2; av
= av
->next
, i
>= 0; i
--)
1397 string
= p
= (char *) oballoc (2
1398 + strlen (attr
->name
)
1399 + strlen (XSTR (av
->value
, 0)));
1400 strcpy (p
, attr
->name
);
1402 strcat (p
, XSTR (av
->value
, 0));
1403 for (; *p
!= '\0'; p
++)
1406 value
= attr_rtx (SYMBOL_REF
, string
);
1407 ATTR_IND_SIMPLIFIED_P (value
) = 1;
1409 XVECEXP (condexp
, 0, 2 * i
) = attr_rtx (EQ
, exp
, value
);
1411 XVECEXP (condexp
, 0, 2 * i
+ 1) = av
->value
;
1418 /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
1419 expressions by converting them into a COND. This removes cases from this
1420 program. Also, replace an attribute value of "*" with the default attribute
1424 make_canonical (attr
, exp
)
1425 struct attr_desc
*attr
;
1431 switch (GET_CODE (exp
))
1434 exp
= make_numeric_value (INTVAL (exp
));
1438 if (! strcmp (XSTR (exp
, 0), "*"))
1440 if (attr
== 0 || attr
->default_val
== 0)
1441 fatal ("(attr_value \"*\") used in invalid context");
1442 exp
= attr
->default_val
->value
;
1448 if (!attr
->is_const
|| ATTR_IND_SIMPLIFIED_P (exp
))
1450 /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
1451 This makes the COND something that won't be considered an arbitrary
1452 expression by walk_attr_value. */
1453 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1455 /* ??? Why do we do this? With attribute values { A B C D E }, this
1456 tends to generate (!(x==A) && !(x==B) && !(x==C) && !(x==D)) rather
1458 exp
= convert_const_symbol_ref (exp
, attr
);
1459 ATTR_IND_SIMPLIFIED_P (exp
) = 1;
1460 exp
= check_attr_value (exp
, attr
);
1461 /* Goto COND case since this is now a COND. Note that while the
1462 new expression is rescanned, all symbol_ref notes are marked as
1466 exp
= check_attr_value (exp
, attr
);
1471 newexp
= rtx_alloc (COND
);
1472 XVEC (newexp
, 0) = rtvec_alloc (2);
1473 XVECEXP (newexp
, 0, 0) = XEXP (exp
, 0);
1474 XVECEXP (newexp
, 0, 1) = XEXP (exp
, 1);
1476 XEXP (newexp
, 1) = XEXP (exp
, 2);
1479 /* Fall through to COND case since this is now a COND. */
1486 /* First, check for degenerate COND. */
1487 if (XVECLEN (exp
, 0) == 0)
1488 return make_canonical (attr
, XEXP (exp
, 1));
1489 defval
= XEXP (exp
, 1) = make_canonical (attr
, XEXP (exp
, 1));
1491 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
1493 XVECEXP (exp
, 0, i
) = copy_boolean (XVECEXP (exp
, 0, i
));
1494 XVECEXP (exp
, 0, i
+ 1)
1495 = make_canonical (attr
, XVECEXP (exp
, 0, i
+ 1));
1496 if (! rtx_equal_p (XVECEXP (exp
, 0, i
+ 1), defval
))
1515 if (GET_CODE (exp
) == AND
|| GET_CODE (exp
) == IOR
)
1516 return attr_rtx (GET_CODE (exp
), copy_boolean (XEXP (exp
, 0)),
1517 copy_boolean (XEXP (exp
, 1)));
1521 /* Given a value and an attribute description, return a `struct attr_value *'
1522 that represents that value. This is either an existing structure, if the
1523 value has been previously encountered, or a newly-created structure.
1525 `insn_code' is the code of an insn whose attribute has the specified
1526 value (-2 if not processing an insn). We ensure that all insns for
1527 a given value have the same number of alternatives if the value checks
1530 static struct attr_value
*
1531 get_attr_value (value
, attr
, insn_code
)
1533 struct attr_desc
*attr
;
1536 struct attr_value
*av
;
1539 value
= make_canonical (attr
, value
);
1540 if (compares_alternatives_p (value
))
1542 if (insn_code
< 0 || insn_alternatives
== NULL
)
1543 fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
1545 num_alt
= insn_alternatives
[insn_code
];
1548 for (av
= attr
->first_value
; av
; av
= av
->next
)
1549 if (rtx_equal_p (value
, av
->value
)
1550 && (num_alt
== 0 || av
->first_insn
== NULL
1551 || insn_alternatives
[av
->first_insn
->insn_code
]))
1554 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
1556 av
->next
= attr
->first_value
;
1557 attr
->first_value
= av
;
1558 av
->first_insn
= NULL
;
1560 av
->has_asm_insn
= 0;
1565 /* After all DEFINE_DELAYs have been read in, create internal attributes
1566 to generate the required routines.
1568 First, we compute the number of delay slots for each insn (as a COND of
1569 each of the test expressions in DEFINE_DELAYs). Then, if more than one
1570 delay type is specified, we compute a similar function giving the
1571 DEFINE_DELAY ordinal for each insn.
1573 Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
1574 tells whether a given insn can be in that delay slot.
1576 Normal attribute filling and optimization expands these to contain the
1577 information needed to handle delay slots. */
1582 struct delay_desc
*delay
;
1588 /* First, generate data for `num_delay_slots' function. */
1590 condexp
= rtx_alloc (COND
);
1591 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1592 XEXP (condexp
, 1) = make_numeric_value (0);
1594 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1596 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1597 XVECEXP (condexp
, 0, i
+ 1)
1598 = make_numeric_value (XVECLEN (delay
->def
, 1) / 3);
1601 make_internal_attr ("*num_delay_slots", condexp
, 0);
1603 /* If more than one delay type, do the same for computing the delay type. */
1606 condexp
= rtx_alloc (COND
);
1607 XVEC (condexp
, 0) = rtvec_alloc (num_delays
* 2);
1608 XEXP (condexp
, 1) = make_numeric_value (0);
1610 for (i
= 0, delay
= delays
; delay
; i
+= 2, delay
= delay
->next
)
1612 XVECEXP (condexp
, 0, i
) = XEXP (delay
->def
, 0);
1613 XVECEXP (condexp
, 0, i
+ 1) = make_numeric_value (delay
->num
);
1616 make_internal_attr ("*delay_type", condexp
, 1);
1619 /* For each delay possibility and delay slot, compute an eligibility
1620 attribute for non-annulled insns and for each type of annulled (annul
1621 if true and annul if false). */
1622 for (delay
= delays
; delay
; delay
= delay
->next
)
1624 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
1626 condexp
= XVECEXP (delay
->def
, 1, i
);
1628 condexp
= false_rtx
;
1629 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1630 make_numeric_value (1), make_numeric_value (0));
1632 p
= attr_printf (sizeof "*delay__" + MAX_DIGITS
* 2,
1633 "*delay_%d_%d", delay
->num
, i
/ 3);
1634 make_internal_attr (p
, newexp
, 1);
1636 if (have_annul_true
)
1638 condexp
= XVECEXP (delay
->def
, 1, i
+ 1);
1639 if (condexp
== 0) condexp
= false_rtx
;
1640 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1641 make_numeric_value (1),
1642 make_numeric_value (0));
1643 p
= attr_printf (sizeof "*annul_true__" + MAX_DIGITS
* 2,
1644 "*annul_true_%d_%d", delay
->num
, i
/ 3);
1645 make_internal_attr (p
, newexp
, 1);
1648 if (have_annul_false
)
1650 condexp
= XVECEXP (delay
->def
, 1, i
+ 2);
1651 if (condexp
== 0) condexp
= false_rtx
;
1652 newexp
= attr_rtx (IF_THEN_ELSE
, condexp
,
1653 make_numeric_value (1),
1654 make_numeric_value (0));
1655 p
= attr_printf (sizeof "*annul_false__" + MAX_DIGITS
* 2,
1656 "*annul_false_%d_%d", delay
->num
, i
/ 3);
1657 make_internal_attr (p
, newexp
, 1);
1663 /* This function is given a left and right side expression and an operator.
1664 Each side is a conditional expression, each alternative of which has a
1665 numerical value. The function returns another conditional expression
1666 which, for every possible set of condition values, returns a value that is
1667 the operator applied to the values of the two sides.
1669 Since this is called early, it must also support IF_THEN_ELSE. */
1672 operate_exp (op
, left
, right
)
1676 int left_value
, right_value
;
1680 /* If left is a string, apply operator to it and the right side. */
1681 if (GET_CODE (left
) == CONST_STRING
)
1683 /* If right is also a string, just perform the operation. */
1684 if (GET_CODE (right
) == CONST_STRING
)
1686 left_value
= atoi (XSTR (left
, 0));
1687 right_value
= atoi (XSTR (right
, 0));
1691 i
= left_value
+ right_value
;
1695 i
= left_value
- right_value
;
1698 case POS_MINUS_OP
: /* The positive part of LEFT - RIGHT. */
1699 if (left_value
> right_value
)
1700 i
= left_value
- right_value
;
1707 i
= left_value
| right_value
;
1711 i
= left_value
== right_value
;
1715 i
= (left_value
<< (HOST_BITS_PER_INT
/ 2)) | right_value
;
1719 if (left_value
> right_value
)
1726 if (left_value
< right_value
)
1736 if (i
== left_value
)
1738 if (i
== right_value
)
1740 return make_numeric_value (i
);
1742 else if (GET_CODE (right
) == IF_THEN_ELSE
)
1744 /* Apply recursively to all values within. */
1745 rtx newleft
= operate_exp (op
, left
, XEXP (right
, 1));
1746 rtx newright
= operate_exp (op
, left
, XEXP (right
, 2));
1747 if (rtx_equal_p (newleft
, newright
))
1749 return attr_rtx (IF_THEN_ELSE
, XEXP (right
, 0), newleft
, newright
);
1751 else if (GET_CODE (right
) == COND
)
1756 newexp
= rtx_alloc (COND
);
1757 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (right
, 0));
1758 defval
= XEXP (newexp
, 1) = operate_exp (op
, left
, XEXP (right
, 1));
1760 for (i
= 0; i
< XVECLEN (right
, 0); i
+= 2)
1762 XVECEXP (newexp
, 0, i
) = XVECEXP (right
, 0, i
);
1763 XVECEXP (newexp
, 0, i
+ 1)
1764 = operate_exp (op
, left
, XVECEXP (right
, 0, i
+ 1));
1765 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1770 /* If the resulting cond is trivial (all alternatives
1771 give the same value), optimize it away. */
1773 return operate_exp (op
, left
, XEXP (right
, 1));
1778 fatal ("badly formed attribute value");
1781 /* A hack to prevent expand_units from completely blowing up: ORX_OP does
1782 not associate through IF_THEN_ELSE. */
1783 else if (op
== ORX_OP
&& GET_CODE (right
) == IF_THEN_ELSE
)
1785 return attr_rtx (IOR
, left
, right
);
1788 /* Otherwise, do recursion the other way. */
1789 else if (GET_CODE (left
) == IF_THEN_ELSE
)
1791 rtx newleft
= operate_exp (op
, XEXP (left
, 1), right
);
1792 rtx newright
= operate_exp (op
, XEXP (left
, 2), right
);
1793 if (rtx_equal_p (newleft
, newright
))
1795 return attr_rtx (IF_THEN_ELSE
, XEXP (left
, 0), newleft
, newright
);
1797 else if (GET_CODE (left
) == COND
)
1802 newexp
= rtx_alloc (COND
);
1803 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (left
, 0));
1804 defval
= XEXP (newexp
, 1) = operate_exp (op
, XEXP (left
, 1), right
);
1806 for (i
= 0; i
< XVECLEN (left
, 0); i
+= 2)
1808 XVECEXP (newexp
, 0, i
) = XVECEXP (left
, 0, i
);
1809 XVECEXP (newexp
, 0, i
+ 1)
1810 = operate_exp (op
, XVECEXP (left
, 0, i
+ 1), right
);
1811 if (! rtx_equal_p (XVECEXP (newexp
, 0, i
+ 1),
1816 /* If the cond is trivial (all alternatives give the same value),
1817 optimize it away. */
1819 return operate_exp (op
, XEXP (left
, 1), right
);
1821 /* If the result is the same as the LEFT operand,
1823 if (rtx_equal_p (newexp
, left
))
1830 fatal ("badly formed attribute value");
1835 /* Once all attributes and DEFINE_FUNCTION_UNITs have been read, we
1836 construct a number of attributes.
1838 The first produces a function `function_units_used' which is given an
1839 insn and produces an encoding showing which function units are required
1840 for the execution of that insn. If the value is non-negative, the insn
1841 uses that unit; otherwise, the value is a one's complement mask of units
1844 The second produces a function `result_ready_cost' which is used to
1845 determine the time that the result of an insn will be ready and hence
1846 a worst-case schedule.
1848 Both of these produce quite complex expressions which are then set as the
1849 default value of internal attributes. Normal attribute simplification
1850 should produce reasonable expressions.
1852 For each unit, a `<name>_unit_ready_cost' function will take an
1853 insn and give the delay until that unit will be ready with the result
1854 and a `<name>_unit_conflict_cost' function is given an insn already
1855 executing on the unit and a candidate to execute and will give the
1856 cost from the time the executing insn started until the candidate
1857 can start (ignore limitations on the number of simultaneous insns).
1859 For each unit, a `<name>_unit_blockage' function is given an insn
1860 already executing on the unit and a candidate to execute and will
1861 give the delay incurred due to function unit conflicts. The range of
1862 blockage cost values for a given executing insn is given by the
1863 `<name>_unit_blockage_range' function. These values are encoded in
1864 an int where the upper half gives the minimum value and the lower
1865 half gives the maximum value. */
1870 struct function_unit
*unit
, **unit_num
;
1871 struct function_unit_op
*op
, **op_array
, ***unit_ops
;
1876 int i
, j
, u
, num
, nvalues
;
1878 /* Rebuild the condition for the unit to share the RTL expressions.
1879 Sharing is required by simplify_by_exploding. Build the issue delay
1880 expressions. Validate the expressions we were given for the conditions
1881 and conflict vector. Then make attributes for use in the conflict
1884 for (unit
= units
; unit
; unit
= unit
->next
)
1886 unit
->condexp
= check_attr_test (unit
->condexp
, 0, unit
->first_lineno
);
1888 for (op
= unit
->ops
; op
; op
= op
->next
)
1890 rtx issue_delay
= make_numeric_value (op
->issue_delay
);
1891 rtx issue_exp
= issue_delay
;
1893 /* Build, validate, and simplify the issue delay expression. */
1894 if (op
->conflict_exp
!= true_rtx
)
1895 issue_exp
= attr_rtx (IF_THEN_ELSE
, op
->conflict_exp
,
1896 issue_exp
, make_numeric_value (0));
1897 issue_exp
= check_attr_value (make_canonical (NULL_ATTR
,
1900 issue_exp
= simplify_knowing (issue_exp
, unit
->condexp
);
1901 op
->issue_exp
= issue_exp
;
1903 /* Make an attribute for use in the conflict function if needed. */
1904 unit
->needs_conflict_function
= (unit
->issue_delay
.min
1905 != unit
->issue_delay
.max
);
1906 if (unit
->needs_conflict_function
)
1908 str
= attr_printf ((strlen (unit
->name
) + sizeof "*_cost_"
1910 "*%s_cost_%d", unit
->name
, op
->num
);
1911 make_internal_attr (str
, issue_exp
, 1);
1914 /* Validate the condition. */
1915 op
->condexp
= check_attr_test (op
->condexp
, 0, op
->lineno
);
1919 /* Compute the mask of function units used. Initially, the unitsmask is
1920 zero. Set up a conditional to compute each unit's contribution. */
1921 unitsmask
= make_numeric_value (0);
1922 newexp
= rtx_alloc (IF_THEN_ELSE
);
1923 XEXP (newexp
, 2) = make_numeric_value (0);
1925 /* If we have just a few units, we may be all right expanding the whole
1926 thing. But the expansion is 2**N in space on the number of opclasses,
1927 so we can't do this for very long -- Alpha and MIPS in particular have
1928 problems with this. So in that situation, we fall back on an alternate
1929 implementation method. */
1930 #define NUM_UNITOP_CUTOFF 20
1932 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1934 /* Merge each function unit into the unit mask attributes. */
1935 for (unit
= units
; unit
; unit
= unit
->next
)
1937 XEXP (newexp
, 0) = unit
->condexp
;
1938 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1939 unitsmask
= operate_exp (OR_OP
, unitsmask
, newexp
);
1944 /* Merge each function unit into the unit mask attributes. */
1945 for (unit
= units
; unit
; unit
= unit
->next
)
1947 XEXP (newexp
, 0) = unit
->condexp
;
1948 XEXP (newexp
, 1) = make_numeric_value (1 << unit
->num
);
1949 unitsmask
= operate_exp (ORX_OP
, unitsmask
, attr_copy_rtx (newexp
));
1953 /* Simplify the unit mask expression, encode it, and make an attribute
1954 for the function_units_used function. */
1955 unitsmask
= simplify_by_exploding (unitsmask
);
1957 if (num_unit_opclasses
< NUM_UNITOP_CUTOFF
)
1958 unitsmask
= encode_units_mask (unitsmask
);
1961 /* We can no longer encode unitsmask at compile time, so emit code to
1962 calculate it at runtime. Rather, put a marker for where we'd do
1963 the code, and actually output it in write_attr_get(). */
1964 unitsmask
= attr_rtx (FFS
, unitsmask
);
1967 make_internal_attr ("*function_units_used", unitsmask
, 10);
1969 /* Create an array of ops for each unit. Add an extra unit for the
1970 result_ready_cost function that has the ops of all other units. */
1971 unit_ops
= (struct function_unit_op
***)
1972 xmalloc ((num_units
+ 1) * sizeof (struct function_unit_op
**));
1973 unit_num
= (struct function_unit
**)
1974 xmalloc ((num_units
+ 1) * sizeof (struct function_unit
*));
1976 unit_num
[num_units
] = unit
= (struct function_unit
*)
1977 xmalloc (sizeof (struct function_unit
));
1978 unit
->num
= num_units
;
1979 unit
->num_opclasses
= 0;
1981 for (unit
= units
; unit
; unit
= unit
->next
)
1983 unit_num
[num_units
]->num_opclasses
+= unit
->num_opclasses
;
1984 unit_num
[unit
->num
] = unit
;
1985 unit_ops
[unit
->num
] = op_array
= (struct function_unit_op
**)
1986 xmalloc (unit
->num_opclasses
* sizeof (struct function_unit_op
*));
1988 for (op
= unit
->ops
; op
; op
= op
->next
)
1989 op_array
[op
->num
] = op
;
1992 /* Compose the array of ops for the extra unit. */
1993 unit_ops
[num_units
] = op_array
= (struct function_unit_op
**)
1994 xmalloc (unit_num
[num_units
]->num_opclasses
1995 * sizeof (struct function_unit_op
*));
1997 for (unit
= units
, i
= 0; unit
; i
+= unit
->num_opclasses
, unit
= unit
->next
)
1998 memcpy (&op_array
[i
], unit_ops
[unit
->num
],
1999 unit
->num_opclasses
* sizeof (struct function_unit_op
*));
2001 /* Compute the ready cost function for each unit by computing the
2002 condition for each non-default value. */
2003 for (u
= 0; u
<= num_units
; u
++)
2009 op_array
= unit_ops
[unit
->num
];
2010 num
= unit
->num_opclasses
;
2012 /* Sort the array of ops into increasing ready cost order. */
2013 for (i
= 0; i
< num
; i
++)
2014 for (j
= num
- 1; j
> i
; j
--)
2015 if (op_array
[j
- 1]->ready
< op_array
[j
]->ready
)
2018 op_array
[j
] = op_array
[j
- 1];
2019 op_array
[j
- 1] = op
;
2022 /* Determine how many distinct non-default ready cost values there
2023 are. We use a default ready cost value of 1. */
2024 nvalues
= 0; value
= 1;
2025 for (i
= num
- 1; i
>= 0; i
--)
2026 if (op_array
[i
]->ready
> value
)
2028 value
= op_array
[i
]->ready
;
2033 readycost
= make_numeric_value (1);
2036 /* Construct the ready cost expression as a COND of each value from
2037 the largest to the smallest. */
2038 readycost
= rtx_alloc (COND
);
2039 XVEC (readycost
, 0) = rtvec_alloc (nvalues
* 2);
2040 XEXP (readycost
, 1) = make_numeric_value (1);
2044 value
= op_array
[0]->ready
;
2045 for (i
= 0; i
< num
; i
++)
2050 else if (op
->ready
== value
)
2051 orexp
= insert_right_side (IOR
, orexp
, op
->condexp
, -2, -2);
2054 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
2055 XVECEXP (readycost
, 0, nvalues
* 2 + 1)
2056 = make_numeric_value (value
);
2059 orexp
= op
->condexp
;
2062 XVECEXP (readycost
, 0, nvalues
* 2) = orexp
;
2063 XVECEXP (readycost
, 0, nvalues
* 2 + 1) = make_numeric_value (value
);
2068 rtx max_blockage
= 0, min_blockage
= 0;
2070 /* Simplify the readycost expression by only considering insns
2071 that use the unit. */
2072 readycost
= simplify_knowing (readycost
, unit
->condexp
);
2074 /* Determine the blockage cost the executing insn (E) given
2075 the candidate insn (C). This is the maximum of the issue
2076 delay, the pipeline delay, and the simultaneity constraint.
2077 Each function_unit_op represents the characteristics of the
2078 candidate insn, so in the expressions below, C is a known
2079 term and E is an unknown term.
2081 We compute the blockage cost for each E for every possible C.
2082 Thus OP represents E, and READYCOST is a list of values for
2085 The issue delay function for C is op->issue_exp and is used to
2086 write the `<name>_unit_conflict_cost' function. Symbolicly
2087 this is "ISSUE-DELAY (E,C)".
2089 The pipeline delay results form the FIFO constraint on the
2090 function unit and is "READY-COST (E) + 1 - READY-COST (C)".
2092 The simultaneity constraint is based on how long it takes to
2093 fill the unit given the minimum issue delay. FILL-TIME is the
2094 constant "MIN (ISSUE-DELAY (*,*)) * (SIMULTANEITY - 1)", and
2095 the simultaneity constraint is "READY-COST (E) - FILL-TIME"
2096 if SIMULTANEITY is nonzero and zero otherwise.
2098 Thus, BLOCKAGE (E,C) when SIMULTANEITY is zero is
2100 MAX (ISSUE-DELAY (E,C),
2101 READY-COST (E) - (READY-COST (C) - 1))
2105 MAX (ISSUE-DELAY (E,C),
2106 READY-COST (E) - (READY-COST (C) - 1),
2107 READY-COST (E) - FILL-TIME)
2109 The `<name>_unit_blockage' function is computed by determining
2110 this value for each candidate insn. As these values are
2111 computed, we also compute the upper and lower bounds for
2112 BLOCKAGE (E,*). These are combined to form the function
2113 `<name>_unit_blockage_range'. Finally, the maximum blockage
2114 cost, MAX (BLOCKAGE (*,*)), is computed. */
2116 for (op
= unit
->ops
; op
; op
= op
->next
)
2118 rtx blockage
= op
->issue_exp
;
2119 blockage
= simplify_knowing (blockage
, unit
->condexp
);
2121 /* Add this op's contribution to MAX (BLOCKAGE (E,*)) and
2122 MIN (BLOCKAGE (E,*)). */
2123 if (max_blockage
== 0)
2124 max_blockage
= min_blockage
= blockage
;
2128 = simplify_knowing (operate_exp (MAX_OP
, max_blockage
,
2132 = simplify_knowing (operate_exp (MIN_OP
, min_blockage
,
2137 /* Make an attribute for use in the blockage function. */
2138 str
= attr_printf ((strlen (unit
->name
) + sizeof "*_block_"
2140 "*%s_block_%d", unit
->name
, op
->num
);
2141 make_internal_attr (str
, blockage
, 1);
2144 /* Record MAX (BLOCKAGE (*,*)). */
2147 unit
->max_blockage
= max_attr_value (max_blockage
, &unknown
);
2150 /* See if the upper and lower bounds of BLOCKAGE (E,*) are the
2151 same. If so, the blockage function carries no additional
2152 information and is not written. */
2153 newexp
= operate_exp (EQ_OP
, max_blockage
, min_blockage
);
2154 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2155 unit
->needs_blockage_function
2156 = (GET_CODE (newexp
) != CONST_STRING
2157 || atoi (XSTR (newexp
, 0)) != 1);
2159 /* If the all values of BLOCKAGE (E,C) have the same value,
2160 neither blockage function is written. */
2161 unit
->needs_range_function
2162 = (unit
->needs_blockage_function
2163 || GET_CODE (max_blockage
) != CONST_STRING
);
2165 if (unit
->needs_range_function
)
2167 /* Compute the blockage range function and make an attribute
2168 for writing its value. */
2169 newexp
= operate_exp (RANGE_OP
, min_blockage
, max_blockage
);
2170 newexp
= simplify_knowing (newexp
, unit
->condexp
);
2172 str
= attr_printf ((strlen (unit
->name
)
2173 + sizeof "*_unit_blockage_range"),
2174 "*%s_unit_blockage_range", unit
->name
);
2175 make_internal_attr (str
, newexp
, 20);
2178 str
= attr_printf (strlen (unit
->name
) + sizeof "*_unit_ready_cost",
2179 "*%s_unit_ready_cost", unit
->name
);
2182 str
= "*result_ready_cost";
2184 /* Make an attribute for the ready_cost function. Simplifying
2185 further with simplify_by_exploding doesn't win. */
2186 make_internal_attr (str
, readycost
, 0);
2189 /* For each unit that requires a conflict cost function, make an attribute
2190 that maps insns to the operation number. */
2191 for (unit
= units
; unit
; unit
= unit
->next
)
2195 if (! unit
->needs_conflict_function
2196 && ! unit
->needs_blockage_function
)
2199 caseexp
= rtx_alloc (COND
);
2200 XVEC (caseexp
, 0) = rtvec_alloc ((unit
->num_opclasses
- 1) * 2);
2202 for (op
= unit
->ops
; op
; op
= op
->next
)
2204 /* Make our adjustment to the COND being computed. If we are the
2205 last operation class, place our values into the default of the
2207 if (op
->num
== unit
->num_opclasses
- 1)
2209 XEXP (caseexp
, 1) = make_numeric_value (op
->num
);
2213 XVECEXP (caseexp
, 0, op
->num
* 2) = op
->condexp
;
2214 XVECEXP (caseexp
, 0, op
->num
* 2 + 1)
2215 = make_numeric_value (op
->num
);
2219 /* Simplifying caseexp with simplify_by_exploding doesn't win. */
2220 str
= attr_printf (strlen (unit
->name
) + sizeof "*_cases",
2221 "*%s_cases", unit
->name
);
2222 make_internal_attr (str
, caseexp
, 1);
2226 /* Simplify EXP given KNOWN_TRUE. */
2229 simplify_knowing (exp
, known_true
)
2230 rtx exp
, known_true
;
2232 if (GET_CODE (exp
) != CONST_STRING
)
2234 int unknown
= 0, max
;
2235 max
= max_attr_value (exp
, &unknown
);
2238 exp
= attr_rtx (IF_THEN_ELSE
, known_true
, exp
,
2239 make_numeric_value (max
));
2240 exp
= simplify_by_exploding (exp
);
2246 /* Translate the CONST_STRING expressions in X to change the encoding of
2247 value. On input, the value is a bitmask with a one bit for each unit
2248 used; on output, the value is the unit number (zero based) if one
2249 and only one unit is used or the one's complement of the bitmask. */
2252 encode_units_mask (x
)
2260 code
= GET_CODE (x
);
2265 i
= atoi (XSTR (x
, 0));
2267 /* The sign bit encodes a one's complement mask. */
2269 else if (i
!= 0 && i
== (i
& -i
))
2270 /* Only one bit is set, so yield that unit number. */
2271 for (j
= 0; (i
>>= 1) != 0; j
++)
2275 return attr_rtx (CONST_STRING
, attr_printf (MAX_DIGITS
, "%d", j
));
2293 /* Compare the elements. If any pair of corresponding elements
2294 fail to match, return 0 for the whole things. */
2296 fmt
= GET_RTX_FORMAT (code
);
2297 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2303 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2304 XVECEXP (x
, i
, j
) = encode_units_mask (XVECEXP (x
, i
, j
));
2308 XEXP (x
, i
) = encode_units_mask (XEXP (x
, i
));
2315 /* Once all attributes and insns have been read and checked, we construct for
2316 each attribute value a list of all the insns that have that value for
2321 struct attr_desc
*attr
;
2323 struct attr_value
*av
;
2324 struct insn_ent
*ie
;
2325 struct insn_def
*id
;
2329 /* Don't fill constant attributes. The value is independent of
2330 any particular insn. */
2334 for (id
= defs
; id
; id
= id
->next
)
2336 /* If no value is specified for this insn for this attribute, use the
2339 if (XVEC (id
->def
, id
->vec_idx
))
2340 for (i
= 0; i
< XVECLEN (id
->def
, id
->vec_idx
); i
++)
2341 if (! strcmp (XSTR (XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 0), 0),
2343 value
= XEXP (XVECEXP (id
->def
, id
->vec_idx
, i
), 1);
2346 av
= attr
->default_val
;
2348 av
= get_attr_value (value
, attr
, id
->insn_code
);
2350 ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2351 ie
->insn_code
= id
->insn_code
;
2352 ie
->insn_index
= id
->insn_code
;
2353 insert_insn_ent (av
, ie
);
2357 /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
2358 test that checks relative positions of insns (uses MATCH_DUP or PC).
2359 If so, replace it with what is obtained by passing the expression to
2360 ADDRESS_FN. If not but it is a COND or IF_THEN_ELSE, call this routine
2361 recursively on each value (including the default value). Otherwise,
2362 return the value returned by NO_ADDRESS_FN applied to EXP. */
2365 substitute_address (exp
, no_address_fn
, address_fn
)
2367 rtx (*no_address_fn
) PARAMS ((rtx
));
2368 rtx (*address_fn
) PARAMS ((rtx
));
2373 if (GET_CODE (exp
) == COND
)
2375 /* See if any tests use addresses. */
2377 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2378 walk_attr_value (XVECEXP (exp
, 0, i
));
2381 return (*address_fn
) (exp
);
2383 /* Make a new copy of this COND, replacing each element. */
2384 newexp
= rtx_alloc (COND
);
2385 XVEC (newexp
, 0) = rtvec_alloc (XVECLEN (exp
, 0));
2386 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
2388 XVECEXP (newexp
, 0, i
) = XVECEXP (exp
, 0, i
);
2389 XVECEXP (newexp
, 0, i
+ 1)
2390 = substitute_address (XVECEXP (exp
, 0, i
+ 1),
2391 no_address_fn
, address_fn
);
2394 XEXP (newexp
, 1) = substitute_address (XEXP (exp
, 1),
2395 no_address_fn
, address_fn
);
2400 else if (GET_CODE (exp
) == IF_THEN_ELSE
)
2403 walk_attr_value (XEXP (exp
, 0));
2405 return (*address_fn
) (exp
);
2407 return attr_rtx (IF_THEN_ELSE
,
2408 substitute_address (XEXP (exp
, 0),
2409 no_address_fn
, address_fn
),
2410 substitute_address (XEXP (exp
, 1),
2411 no_address_fn
, address_fn
),
2412 substitute_address (XEXP (exp
, 2),
2413 no_address_fn
, address_fn
));
2416 return (*no_address_fn
) (exp
);
2419 /* Make new attributes from the `length' attribute. The following are made,
2420 each corresponding to a function called from `shorten_branches' or
2423 *insn_default_length This is the length of the insn to be returned
2424 by `get_attr_length' before `shorten_branches'
2425 has been called. In each case where the length
2426 depends on relative addresses, the largest
2427 possible is used. This routine is also used
2428 to compute the initial size of the insn.
2430 *insn_variable_length_p This returns 1 if the insn's length depends
2431 on relative addresses, zero otherwise.
2433 *insn_current_length This is only called when it is known that the
2434 insn has a variable length and returns the
2435 current length, based on relative addresses.
2439 make_length_attrs ()
2441 static const char *const new_names
[] = {"*insn_default_length",
2442 "*insn_variable_length_p",
2443 "*insn_current_length"};
2444 static rtx (*const no_address_fn
[]) PARAMS ((rtx
)) = {identity_fn
, zero_fn
, zero_fn
};
2445 static rtx (*const address_fn
[]) PARAMS ((rtx
)) = {max_fn
, one_fn
, identity_fn
};
2447 struct attr_desc
*length_attr
, *new_attr
;
2448 struct attr_value
*av
, *new_av
;
2449 struct insn_ent
*ie
, *new_ie
;
2451 /* See if length attribute is defined. If so, it must be numeric. Make
2452 it special so we don't output anything for it. */
2453 length_attr
= find_attr ("length", 0);
2454 if (length_attr
== 0)
2457 if (! length_attr
->is_numeric
)
2458 fatal ("length attribute must be numeric");
2460 length_attr
->is_const
= 0;
2461 length_attr
->is_special
= 1;
2463 /* Make each new attribute, in turn. */
2464 for (i
= 0; i
< ARRAY_SIZE (new_names
); i
++)
2466 make_internal_attr (new_names
[i
],
2467 substitute_address (length_attr
->default_val
->value
,
2468 no_address_fn
[i
], address_fn
[i
]),
2470 new_attr
= find_attr (new_names
[i
], 0);
2471 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2472 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2474 new_av
= get_attr_value (substitute_address (av
->value
,
2477 new_attr
, ie
->insn_code
);
2478 new_ie
= (struct insn_ent
*) oballoc (sizeof (struct insn_ent
));
2479 new_ie
->insn_code
= ie
->insn_code
;
2480 new_ie
->insn_index
= ie
->insn_index
;
2481 insert_insn_ent (new_av
, new_ie
);
2486 /* Utility functions called from above routine. */
2497 rtx exp ATTRIBUTE_UNUSED
;
2499 return make_numeric_value (0);
2504 rtx exp ATTRIBUTE_UNUSED
;
2506 return make_numeric_value (1);
2514 return make_numeric_value (max_attr_value (exp
, &unknown
));
2518 write_length_unit_log ()
2520 struct attr_desc
*length_attr
= find_attr ("length", 0);
2521 struct attr_value
*av
;
2522 struct insn_ent
*ie
;
2523 unsigned int length_unit_log
, length_or
;
2526 if (length_attr
== 0)
2528 length_or
= or_attr_value (length_attr
->default_val
->value
, &unknown
);
2529 for (av
= length_attr
->first_value
; av
; av
= av
->next
)
2530 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
2531 length_or
|= or_attr_value (av
->value
, &unknown
);
2534 length_unit_log
= 0;
2537 length_or
= ~length_or
;
2538 for (length_unit_log
= 0; length_or
& 1; length_or
>>= 1)
2541 printf ("int length_unit_log = %u;\n", length_unit_log
);
2544 /* Take a COND expression and see if any of the conditions in it can be
2545 simplified. If any are known true or known false for the particular insn
2546 code, the COND can be further simplified.
2548 Also call ourselves on any COND operations that are values of this COND.
2550 We do not modify EXP; rather, we make and return a new rtx. */
2553 simplify_cond (exp
, insn_code
, insn_index
)
2555 int insn_code
, insn_index
;
2558 /* We store the desired contents here,
2559 then build a new expression if they don't match EXP. */
2560 rtx defval
= XEXP (exp
, 1);
2561 rtx new_defval
= XEXP (exp
, 1);
2562 int len
= XVECLEN (exp
, 0);
2563 rtx
*tests
= (rtx
*) xmalloc (len
* sizeof (rtx
));
2568 /* This lets us free all storage allocated below, if appropriate. */
2569 first_spacer
= (char *) obstack_finish (rtl_obstack
);
2571 memcpy (tests
, XVEC (exp
, 0)->elem
, len
* sizeof (rtx
));
2573 /* See if default value needs simplification. */
2574 if (GET_CODE (defval
) == COND
)
2575 new_defval
= simplify_cond (defval
, insn_code
, insn_index
);
2577 /* Simplify the subexpressions, and see what tests we can get rid of. */
2579 for (i
= 0; i
< len
; i
+= 2)
2581 rtx newtest
, newval
;
2583 /* Simplify this test. */
2584 newtest
= simplify_test_exp_in_temp (tests
[i
], insn_code
, insn_index
);
2587 newval
= tests
[i
+ 1];
2588 /* See if this value may need simplification. */
2589 if (GET_CODE (newval
) == COND
)
2590 newval
= simplify_cond (newval
, insn_code
, insn_index
);
2592 /* Look for ways to delete or combine this test. */
2593 if (newtest
== true_rtx
)
2595 /* If test is true, make this value the default
2596 and discard this + any following tests. */
2598 defval
= tests
[i
+ 1];
2599 new_defval
= newval
;
2602 else if (newtest
== false_rtx
)
2604 /* If test is false, discard it and its value. */
2605 for (j
= i
; j
< len
- 2; j
++)
2606 tests
[j
] = tests
[j
+ 2];
2610 else if (i
> 0 && attr_equal_p (newval
, tests
[i
- 1]))
2612 /* If this value and the value for the prev test are the same,
2616 = insert_right_side (IOR
, tests
[i
- 2], newtest
,
2617 insn_code
, insn_index
);
2619 /* Delete this test/value. */
2620 for (j
= i
; j
< len
- 2; j
++)
2621 tests
[j
] = tests
[j
+ 2];
2626 tests
[i
+ 1] = newval
;
2629 /* If the last test in a COND has the same value
2630 as the default value, that test isn't needed. */
2632 while (len
> 0 && attr_equal_p (tests
[len
- 1], new_defval
))
2635 /* See if we changed anything. */
2636 if (len
!= XVECLEN (exp
, 0) || new_defval
!= XEXP (exp
, 1))
2639 for (i
= 0; i
< len
; i
++)
2640 if (! attr_equal_p (tests
[i
], XVECEXP (exp
, 0, i
)))
2648 if (GET_CODE (defval
) == COND
)
2649 ret
= simplify_cond (defval
, insn_code
, insn_index
);
2657 rtx newexp
= rtx_alloc (COND
);
2659 XVEC (newexp
, 0) = rtvec_alloc (len
);
2660 memcpy (XVEC (newexp
, 0)->elem
, tests
, len
* sizeof (rtx
));
2661 XEXP (newexp
, 1) = new_defval
;
2668 /* Remove an insn entry from an attribute value. */
2671 remove_insn_ent (av
, ie
)
2672 struct attr_value
*av
;
2673 struct insn_ent
*ie
;
2675 struct insn_ent
*previe
;
2677 if (av
->first_insn
== ie
)
2678 av
->first_insn
= ie
->next
;
2681 for (previe
= av
->first_insn
; previe
->next
!= ie
; previe
= previe
->next
)
2683 previe
->next
= ie
->next
;
2687 if (ie
->insn_code
== -1)
2688 av
->has_asm_insn
= 0;
2693 /* Insert an insn entry in an attribute value list. */
2696 insert_insn_ent (av
, ie
)
2697 struct attr_value
*av
;
2698 struct insn_ent
*ie
;
2700 ie
->next
= av
->first_insn
;
2701 av
->first_insn
= ie
;
2703 if (ie
->insn_code
== -1)
2704 av
->has_asm_insn
= 1;
2709 /* This is a utility routine to take an expression that is a tree of either
2710 AND or IOR expressions and insert a new term. The new term will be
2711 inserted at the right side of the first node whose code does not match
2712 the root. A new node will be created with the root's code. Its left
2713 side will be the old right side and its right side will be the new
2716 If the `term' is itself a tree, all its leaves will be inserted. */
2719 insert_right_side (code
, exp
, term
, insn_code
, insn_index
)
2723 int insn_code
, insn_index
;
2727 /* Avoid consing in some special cases. */
2728 if (code
== AND
&& term
== true_rtx
)
2730 if (code
== AND
&& term
== false_rtx
)
2732 if (code
== AND
&& exp
== true_rtx
)
2734 if (code
== AND
&& exp
== false_rtx
)
2736 if (code
== IOR
&& term
== true_rtx
)
2738 if (code
== IOR
&& term
== false_rtx
)
2740 if (code
== IOR
&& exp
== true_rtx
)
2742 if (code
== IOR
&& exp
== false_rtx
)
2744 if (attr_equal_p (exp
, term
))
2747 if (GET_CODE (term
) == code
)
2749 exp
= insert_right_side (code
, exp
, XEXP (term
, 0),
2750 insn_code
, insn_index
);
2751 exp
= insert_right_side (code
, exp
, XEXP (term
, 1),
2752 insn_code
, insn_index
);
2757 if (GET_CODE (exp
) == code
)
2759 rtx
new = insert_right_side (code
, XEXP (exp
, 1),
2760 term
, insn_code
, insn_index
);
2761 if (new != XEXP (exp
, 1))
2762 /* Make a copy of this expression and call recursively. */
2763 newexp
= attr_rtx (code
, XEXP (exp
, 0), new);
2769 /* Insert the new term. */
2770 newexp
= attr_rtx (code
, exp
, term
);
2773 return simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2776 /* If we have an expression which AND's a bunch of
2777 (not (eq_attrq "alternative" "n"))
2778 terms, we may have covered all or all but one of the possible alternatives.
2779 If so, we can optimize. Similarly for IOR's of EQ_ATTR.
2781 This routine is passed an expression and either AND or IOR. It returns a
2782 bitmask indicating which alternatives are mentioned within EXP. */
2785 compute_alternative_mask (exp
, code
)
2790 if (GET_CODE (exp
) == code
)
2791 return compute_alternative_mask (XEXP (exp
, 0), code
)
2792 | compute_alternative_mask (XEXP (exp
, 1), code
);
2794 else if (code
== AND
&& GET_CODE (exp
) == NOT
2795 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
2796 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
2797 string
= XSTR (XEXP (exp
, 0), 1);
2799 else if (code
== IOR
&& GET_CODE (exp
) == EQ_ATTR
2800 && XSTR (exp
, 0) == alternative_name
)
2801 string
= XSTR (exp
, 1);
2807 return 1 << (string
[0] - '0');
2808 return 1 << atoi (string
);
2811 /* Given I, a single-bit mask, return RTX to compare the `alternative'
2812 attribute with the value represented by that bit. */
2815 make_alternative_compare (mask
)
2822 for (i
= 0; (mask
& (1 << i
)) == 0; i
++)
2825 newexp
= attr_rtx (EQ_ATTR
, alternative_name
, attr_numeral (i
));
2826 ATTR_IND_SIMPLIFIED_P (newexp
) = 1;
2831 /* If we are processing an (eq_attr "attr" "value") test, we find the value
2832 of "attr" for this insn code. From that value, we can compute a test
2833 showing when the EQ_ATTR will be true. This routine performs that
2834 computation. If a test condition involves an address, we leave the EQ_ATTR
2835 intact because addresses are only valid for the `length' attribute.
2837 EXP is the EQ_ATTR expression and VALUE is the value of that attribute
2838 for the insn corresponding to INSN_CODE and INSN_INDEX. */
2841 evaluate_eq_attr (exp
, value
, insn_code
, insn_index
)
2844 int insn_code
, insn_index
;
2851 if (GET_CODE (value
) == CONST_STRING
)
2853 if (! strcmp (XSTR (value
, 0), XSTR (exp
, 1)))
2858 else if (GET_CODE (value
) == SYMBOL_REF
)
2863 if (GET_CODE (exp
) != EQ_ATTR
)
2866 if (strlen (XSTR (exp
, 0)) + strlen (XSTR (exp
, 1)) + 2 > 256)
2869 strcpy (string
, XSTR (exp
, 0));
2870 strcat (string
, "_");
2871 strcat (string
, XSTR (exp
, 1));
2872 for (p
= string
; *p
; p
++)
2875 newexp
= attr_rtx (EQ
, value
,
2876 attr_rtx (SYMBOL_REF
,
2877 attr_string (string
, strlen (string
))));
2879 else if (GET_CODE (value
) == COND
)
2881 /* We construct an IOR of all the cases for which the requested attribute
2882 value is present. Since we start with FALSE, if it is not present,
2883 FALSE will be returned.
2885 Each case is the AND of the NOT's of the previous conditions with the
2886 current condition; in the default case the current condition is TRUE.
2888 For each possible COND value, call ourselves recursively.
2890 The extra TRUE and FALSE expressions will be eliminated by another
2891 call to the simplification routine. */
2896 if (current_alternative_string
)
2897 clear_struct_flag (value
);
2899 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
2901 rtx
this = simplify_test_exp_in_temp (XVECEXP (value
, 0, i
),
2902 insn_code
, insn_index
);
2904 SIMPLIFY_ALTERNATIVE (this);
2906 right
= insert_right_side (AND
, andexp
, this,
2907 insn_code
, insn_index
);
2908 right
= insert_right_side (AND
, right
,
2909 evaluate_eq_attr (exp
,
2912 insn_code
, insn_index
),
2913 insn_code
, insn_index
);
2914 orexp
= insert_right_side (IOR
, orexp
, right
,
2915 insn_code
, insn_index
);
2917 /* Add this condition into the AND expression. */
2918 newexp
= attr_rtx (NOT
, this);
2919 andexp
= insert_right_side (AND
, andexp
, newexp
,
2920 insn_code
, insn_index
);
2923 /* Handle the default case. */
2924 right
= insert_right_side (AND
, andexp
,
2925 evaluate_eq_attr (exp
, XEXP (value
, 1),
2926 insn_code
, insn_index
),
2927 insn_code
, insn_index
);
2928 newexp
= insert_right_side (IOR
, orexp
, right
, insn_code
, insn_index
);
2933 /* If uses an address, must return original expression. But set the
2934 ATTR_IND_SIMPLIFIED_P bit so we don't try to simplify it again. */
2937 walk_attr_value (newexp
);
2941 /* This had `&& current_alternative_string', which seems to be wrong. */
2942 if (! ATTR_IND_SIMPLIFIED_P (exp
))
2943 return copy_rtx_unchanging (exp
);
2950 /* This routine is called when an AND of a term with a tree of AND's is
2951 encountered. If the term or its complement is present in the tree, it
2952 can be replaced with TRUE or FALSE, respectively.
2954 Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
2955 be true and hence are complementary.
2957 There is one special case: If we see
2958 (and (not (eq_attr "att" "v1"))
2959 (eq_attr "att" "v2"))
2960 this can be replaced by (eq_attr "att" "v2"). To do this we need to
2961 replace the term, not anything in the AND tree. So we pass a pointer to
2965 simplify_and_tree (exp
, pterm
, insn_code
, insn_index
)
2968 int insn_code
, insn_index
;
2973 int left_eliminates_term
, right_eliminates_term
;
2975 if (GET_CODE (exp
) == AND
)
2977 left
= simplify_and_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
2978 right
= simplify_and_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
2979 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
2981 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
2983 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
2987 else if (GET_CODE (exp
) == IOR
)
2989 /* For the IOR case, we do the same as above, except that we can
2990 only eliminate `term' if both sides of the IOR would do so. */
2992 left
= simplify_and_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
2993 left_eliminates_term
= (temp
== true_rtx
);
2996 right
= simplify_and_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
2997 right_eliminates_term
= (temp
== true_rtx
);
2999 if (left_eliminates_term
&& right_eliminates_term
)
3002 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3004 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3006 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3010 /* Check for simplifications. Do some extra checking here since this
3011 routine is called so many times. */
3016 else if (GET_CODE (exp
) == NOT
&& XEXP (exp
, 0) == *pterm
)
3019 else if (GET_CODE (*pterm
) == NOT
&& exp
== XEXP (*pterm
, 0))
3022 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == EQ_ATTR
)
3024 if (XSTR (exp
, 0) != XSTR (*pterm
, 0))
3027 if (! strcmp (XSTR (exp
, 1), XSTR (*pterm
, 1)))
3033 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
3034 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
)
3036 if (XSTR (*pterm
, 0) != XSTR (XEXP (exp
, 0), 0))
3039 if (! strcmp (XSTR (*pterm
, 1), XSTR (XEXP (exp
, 0), 1)))
3045 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
3046 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
)
3048 if (XSTR (exp
, 0) != XSTR (XEXP (*pterm
, 0), 0))
3051 if (! strcmp (XSTR (exp
, 1), XSTR (XEXP (*pterm
, 0), 1)))
3057 else if (GET_CODE (exp
) == NOT
&& GET_CODE (*pterm
) == NOT
)
3059 if (attr_equal_p (XEXP (exp
, 0), XEXP (*pterm
, 0)))
3063 else if (GET_CODE (exp
) == NOT
)
3065 if (attr_equal_p (XEXP (exp
, 0), *pterm
))
3069 else if (GET_CODE (*pterm
) == NOT
)
3071 if (attr_equal_p (XEXP (*pterm
, 0), exp
))
3075 else if (attr_equal_p (exp
, *pterm
))
3081 /* Similar to `simplify_and_tree', but for IOR trees. */
3084 simplify_or_tree (exp
, pterm
, insn_code
, insn_index
)
3087 int insn_code
, insn_index
;
3092 int left_eliminates_term
, right_eliminates_term
;
3094 if (GET_CODE (exp
) == IOR
)
3096 left
= simplify_or_tree (XEXP (exp
, 0), pterm
, insn_code
, insn_index
);
3097 right
= simplify_or_tree (XEXP (exp
, 1), pterm
, insn_code
, insn_index
);
3098 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3100 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3102 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3106 else if (GET_CODE (exp
) == AND
)
3108 /* For the AND case, we do the same as above, except that we can
3109 only eliminate `term' if both sides of the AND would do so. */
3111 left
= simplify_or_tree (XEXP (exp
, 0), &temp
, insn_code
, insn_index
);
3112 left_eliminates_term
= (temp
== false_rtx
);
3115 right
= simplify_or_tree (XEXP (exp
, 1), &temp
, insn_code
, insn_index
);
3116 right_eliminates_term
= (temp
== false_rtx
);
3118 if (left_eliminates_term
&& right_eliminates_term
)
3121 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3123 newexp
= attr_rtx (GET_CODE (exp
), left
, right
);
3125 exp
= simplify_test_exp_in_temp (newexp
, insn_code
, insn_index
);
3129 if (attr_equal_p (exp
, *pterm
))
3132 else if (GET_CODE (exp
) == NOT
&& attr_equal_p (XEXP (exp
, 0), *pterm
))
3135 else if (GET_CODE (*pterm
) == NOT
&& attr_equal_p (XEXP (*pterm
, 0), exp
))
3138 else if (GET_CODE (*pterm
) == EQ_ATTR
&& GET_CODE (exp
) == NOT
3139 && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
3140 && XSTR (*pterm
, 0) == XSTR (XEXP (exp
, 0), 0))
3143 else if (GET_CODE (exp
) == EQ_ATTR
&& GET_CODE (*pterm
) == NOT
3144 && GET_CODE (XEXP (*pterm
, 0)) == EQ_ATTR
3145 && XSTR (exp
, 0) == XSTR (XEXP (*pterm
, 0), 0))
3150 /* Compute approximate cost of the expression. Used to decide whether
3151 expression is cheap enough for inline. */
3160 code
= GET_CODE (x
);
3169 /* Alternatives don't result into function call. */
3170 if (!strcmp (XSTR (x
, 0), "alternative"))
3177 const char *fmt
= GET_RTX_FORMAT (code
);
3178 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3184 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3185 cost
+= attr_rtx_cost (XVECEXP (x
, i
, j
));
3188 cost
+= attr_rtx_cost (XEXP (x
, i
));
3199 /* Simplify test expression and use temporary obstack in order to avoid
3200 memory bloat. Use ATTR_IND_SIMPLIFIED to avoid unnecesary simplifications
3201 and avoid unnecesary copying if possible. */
3204 simplify_test_exp_in_temp (exp
, insn_code
, insn_index
)
3206 int insn_code
, insn_index
;
3209 struct obstack
*old
;
3210 if (ATTR_IND_SIMPLIFIED_P (exp
))
3213 rtl_obstack
= temp_obstack
;
3214 x
= simplify_test_exp (exp
, insn_code
, insn_index
);
3216 if (x
== exp
|| rtl_obstack
== temp_obstack
)
3218 return attr_copy_rtx (x
);
3221 /* Given an expression, see if it can be simplified for a particular insn
3222 code based on the values of other attributes being tested. This can
3223 eliminate nested get_attr_... calls.
3225 Note that if an endless recursion is specified in the patterns, the
3226 optimization will loop. However, it will do so in precisely the cases where
3227 an infinite recursion loop could occur during compilation. It's better that
3231 simplify_test_exp (exp
, insn_code
, insn_index
)
3233 int insn_code
, insn_index
;
3236 struct attr_desc
*attr
;
3237 struct attr_value
*av
;
3238 struct insn_ent
*ie
;
3242 /* Don't re-simplify something we already simplified. */
3243 if (ATTR_IND_SIMPLIFIED_P (exp
) || ATTR_CURR_SIMPLIFIED_P (exp
))
3246 switch (GET_CODE (exp
))
3249 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3250 SIMPLIFY_ALTERNATIVE (left
);
3251 if (left
== false_rtx
)
3253 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3254 SIMPLIFY_ALTERNATIVE (right
);
3255 if (left
== false_rtx
)
3258 /* If either side is an IOR and we have (eq_attr "alternative" ..")
3259 present on both sides, apply the distributive law since this will
3260 yield simplifications. */
3261 if ((GET_CODE (left
) == IOR
|| GET_CODE (right
) == IOR
)
3262 && compute_alternative_mask (left
, IOR
)
3263 && compute_alternative_mask (right
, IOR
))
3265 if (GET_CODE (left
) == IOR
)
3272 newexp
= attr_rtx (IOR
,
3273 attr_rtx (AND
, left
, XEXP (right
, 0)),
3274 attr_rtx (AND
, left
, XEXP (right
, 1)));
3276 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3279 /* Try with the term on both sides. */
3280 right
= simplify_and_tree (right
, &left
, insn_code
, insn_index
);
3281 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3282 left
= simplify_and_tree (left
, &right
, insn_code
, insn_index
);
3284 if (left
== false_rtx
|| right
== false_rtx
)
3286 else if (left
== true_rtx
)
3290 else if (right
== true_rtx
)
3294 /* See if all or all but one of the insn's alternatives are specified
3295 in this tree. Optimize if so. */
3297 else if (insn_code
>= 0
3298 && (GET_CODE (left
) == AND
3299 || (GET_CODE (left
) == NOT
3300 && GET_CODE (XEXP (left
, 0)) == EQ_ATTR
3301 && XSTR (XEXP (left
, 0), 0) == alternative_name
)
3302 || GET_CODE (right
) == AND
3303 || (GET_CODE (right
) == NOT
3304 && GET_CODE (XEXP (right
, 0)) == EQ_ATTR
3305 && XSTR (XEXP (right
, 0), 0) == alternative_name
)))
3307 i
= compute_alternative_mask (exp
, AND
);
3308 if (i
& ~insn_alternatives
[insn_code
])
3309 fatal ("invalid alternative specified for pattern number %d",
3312 /* If all alternatives are excluded, this is false. */
3313 i
^= insn_alternatives
[insn_code
];
3316 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3318 /* If just one excluded, AND a comparison with that one to the
3319 front of the tree. The others will be eliminated by
3320 optimization. We do not want to do this if the insn has one
3321 alternative and we have tested none of them! */
3322 left
= make_alternative_compare (i
);
3323 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3324 newexp
= attr_rtx (AND
, left
, right
);
3326 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3330 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3332 newexp
= attr_rtx (AND
, left
, right
);
3333 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3338 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3339 SIMPLIFY_ALTERNATIVE (left
);
3340 if (left
== true_rtx
)
3342 right
= SIMPLIFY_TEST_EXP (XEXP (exp
, 1), insn_code
, insn_index
);
3343 SIMPLIFY_ALTERNATIVE (right
);
3344 if (right
== true_rtx
)
3347 right
= simplify_or_tree (right
, &left
, insn_code
, insn_index
);
3348 if (left
== XEXP (exp
, 0) && right
== XEXP (exp
, 1))
3349 left
= simplify_or_tree (left
, &right
, insn_code
, insn_index
);
3351 if (right
== true_rtx
|| left
== true_rtx
)
3353 else if (left
== false_rtx
)
3357 else if (right
== false_rtx
)
3362 /* Test for simple cases where the distributive law is useful. I.e.,
3363 convert (ior (and (x) (y))
3369 else if (GET_CODE (left
) == AND
&& GET_CODE (right
) == AND
3370 && attr_equal_p (XEXP (left
, 0), XEXP (right
, 0)))
3372 newexp
= attr_rtx (IOR
, XEXP (left
, 1), XEXP (right
, 1));
3374 left
= XEXP (left
, 0);
3376 newexp
= attr_rtx (AND
, left
, right
);
3377 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3380 /* See if all or all but one of the insn's alternatives are specified
3381 in this tree. Optimize if so. */
3383 else if (insn_code
>= 0
3384 && (GET_CODE (left
) == IOR
3385 || (GET_CODE (left
) == EQ_ATTR
3386 && XSTR (left
, 0) == alternative_name
)
3387 || GET_CODE (right
) == IOR
3388 || (GET_CODE (right
) == EQ_ATTR
3389 && XSTR (right
, 0) == alternative_name
)))
3391 i
= compute_alternative_mask (exp
, IOR
);
3392 if (i
& ~insn_alternatives
[insn_code
])
3393 fatal ("invalid alternative specified for pattern number %d",
3396 /* If all alternatives are included, this is true. */
3397 i
^= insn_alternatives
[insn_code
];
3400 else if ((i
& (i
- 1)) == 0 && insn_alternatives
[insn_code
] > 1)
3402 /* If just one excluded, IOR a comparison with that one to the
3403 front of the tree. The others will be eliminated by
3404 optimization. We do not want to do this if the insn has one
3405 alternative and we have tested none of them! */
3406 left
= make_alternative_compare (i
);
3407 right
= simplify_and_tree (exp
, &left
, insn_code
, insn_index
);
3408 newexp
= attr_rtx (IOR
, attr_rtx (NOT
, left
), right
);
3410 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3414 if (left
!= XEXP (exp
, 0) || right
!= XEXP (exp
, 1))
3416 newexp
= attr_rtx (IOR
, left
, right
);
3417 return SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3422 if (GET_CODE (XEXP (exp
, 0)) == NOT
)
3424 left
= SIMPLIFY_TEST_EXP (XEXP (XEXP (exp
, 0), 0),
3425 insn_code
, insn_index
);
3426 SIMPLIFY_ALTERNATIVE (left
);
3430 left
= SIMPLIFY_TEST_EXP (XEXP (exp
, 0), insn_code
, insn_index
);
3431 SIMPLIFY_ALTERNATIVE (left
);
3432 if (GET_CODE (left
) == NOT
)
3433 return XEXP (left
, 0);
3435 if (left
== false_rtx
)
3437 else if (left
== true_rtx
)
3440 /* Try to apply De`Morgan's laws. */
3441 else if (GET_CODE (left
) == IOR
)
3443 newexp
= attr_rtx (AND
,
3444 attr_rtx (NOT
, XEXP (left
, 0)),
3445 attr_rtx (NOT
, XEXP (left
, 1)));
3447 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3449 else if (GET_CODE (left
) == AND
)
3451 newexp
= attr_rtx (IOR
,
3452 attr_rtx (NOT
, XEXP (left
, 0)),
3453 attr_rtx (NOT
, XEXP (left
, 1)));
3455 newexp
= SIMPLIFY_TEST_EXP (newexp
, insn_code
, insn_index
);
3457 else if (left
!= XEXP (exp
, 0))
3459 newexp
= attr_rtx (NOT
, left
);
3464 if (current_alternative_string
&& XSTR (exp
, 0) == alternative_name
)
3465 return (XSTR (exp
, 1) == current_alternative_string
3466 ? true_rtx
: false_rtx
);
3468 /* Look at the value for this insn code in the specified attribute.
3469 We normally can replace this comparison with the condition that
3470 would give this insn the values being tested for. */
3471 if (XSTR (exp
, 0) != alternative_name
3472 && (attr
= find_attr (XSTR (exp
, 0), 0)) != NULL
)
3473 for (av
= attr
->first_value
; av
; av
= av
->next
)
3474 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3475 if (ie
->insn_code
== insn_code
)
3478 x
= evaluate_eq_attr (exp
, av
->value
, insn_code
, insn_index
);
3479 x
= SIMPLIFY_TEST_EXP (x
, insn_code
, insn_index
);
3480 if (attr_rtx_cost(x
) < 20)
3489 /* We have already simplified this expression. Simplifying it again
3490 won't buy anything unless we weren't given a valid insn code
3491 to process (i.e., we are canonicalizing something.). */
3492 if (insn_code
!= -2 /* Seems wrong: && current_alternative_string. */
3493 && ! ATTR_IND_SIMPLIFIED_P (newexp
))
3494 return copy_rtx_unchanging (newexp
);
3499 /* Optimize the attribute lists by seeing if we can determine conditional
3500 values from the known values of other attributes. This will save subroutine
3501 calls during the compilation. */
3506 struct attr_desc
*attr
;
3507 struct attr_value
*av
;
3508 struct insn_ent
*ie
;
3511 struct attr_value_list
3513 struct attr_value
*av
;
3514 struct insn_ent
*ie
;
3515 struct attr_desc
*attr
;
3516 struct attr_value_list
*next
;
3518 struct attr_value_list
**insn_code_values
;
3519 struct attr_value_list
*ivbuf
;
3520 struct attr_value_list
*iv
;
3522 /* For each insn code, make a list of all the insn_ent's for it,
3523 for all values for all attributes. */
3525 if (num_insn_ents
== 0)
3528 /* Make 2 extra elements, for "code" values -2 and -1. */
3530 = (struct attr_value_list
**) xmalloc ((insn_code_number
+ 2)
3531 * sizeof (struct attr_value_list
*));
3532 memset ((char *) insn_code_values
, 0,
3533 (insn_code_number
+ 2) * sizeof (struct attr_value_list
*));
3535 /* Offset the table address so we can index by -2 or -1. */
3536 insn_code_values
+= 2;
3538 iv
= ivbuf
= ((struct attr_value_list
*)
3539 xmalloc (num_insn_ents
* sizeof (struct attr_value_list
)));
3541 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
3542 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
3543 for (av
= attr
->first_value
; av
; av
= av
->next
)
3544 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
3549 iv
->next
= insn_code_values
[ie
->insn_code
];
3550 insn_code_values
[ie
->insn_code
] = iv
;
3554 /* Sanity check on num_insn_ents. */
3555 if (iv
!= ivbuf
+ num_insn_ents
)
3558 /* Process one insn code at a time. */
3559 for (i
= -2; i
< insn_code_number
; i
++)
3561 /* Clear the ATTR_CURR_SIMPLIFIED_P flag everywhere relevant.
3562 We use it to mean "already simplified for this insn". */
3563 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3564 clear_struct_flag (iv
->av
->value
);
3566 for (iv
= insn_code_values
[i
]; iv
; iv
= iv
->next
)
3568 struct obstack
*old
= rtl_obstack
;
3573 if (GET_CODE (av
->value
) != COND
)
3576 rtl_obstack
= temp_obstack
;
3577 #if 0 /* This was intended as a speed up, but it was slower. */
3578 if (insn_n_alternatives
[ie
->insn_code
] > 6
3579 && count_sub_rtxs (av
->value
, 200) >= 200)
3580 newexp
= simplify_by_alternatives (av
->value
, ie
->insn_code
,
3585 while (GET_CODE (newexp
) == COND
)
3587 rtx newexp2
= simplify_cond (newexp
, ie
->insn_code
,
3589 if (newexp2
== newexp
)
3595 if (newexp
!= av
->value
)
3597 newexp
= attr_copy_rtx (newexp
);
3598 remove_insn_ent (av
, ie
);
3599 av
= get_attr_value (newexp
, attr
, ie
->insn_code
);
3601 insert_insn_ent (av
, ie
);
3607 free (insn_code_values
- 2);
3612 simplify_by_alternatives (exp
, insn_code
, insn_index
)
3614 int insn_code
, insn_index
;
3617 int len
= insn_n_alternatives
[insn_code
];
3618 rtx newexp
= rtx_alloc (COND
);
3621 XVEC (newexp
, 0) = rtvec_alloc (len
* 2);
3623 /* It will not matter what value we use as the default value
3624 of the new COND, since that default will never be used.
3625 Choose something of the right type. */
3626 for (ultimate
= exp
; GET_CODE (ultimate
) == COND
;)
3627 ultimate
= XEXP (ultimate
, 1);
3628 XEXP (newexp
, 1) = ultimate
;
3630 for (i
= 0; i
< insn_n_alternatives
[insn_code
]; i
++)
3632 current_alternative_string
= attr_numeral (i
);
3633 XVECEXP (newexp
, 0, i
* 2) = make_alternative_compare (1 << i
);
3634 XVECEXP (newexp
, 0, i
* 2 + 1)
3635 = simplify_cond (exp
, insn_code
, insn_index
);
3638 current_alternative_string
= 0;
3639 return simplify_cond (newexp
, insn_code
, insn_index
);
3643 /* If EXP is a suitable expression, reorganize it by constructing an
3644 equivalent expression that is a COND with the tests being all combinations
3645 of attribute values and the values being simple constants. */
3648 simplify_by_exploding (exp
)
3651 rtx list
= 0, link
, condexp
, defval
= NULL_RTX
;
3652 struct dimension
*space
;
3653 rtx
*condtest
, *condval
;
3654 int i
, j
, total
, ndim
= 0;
3655 int most_tests
, num_marks
, new_marks
;
3658 /* Locate all the EQ_ATTR expressions. */
3659 if (! find_and_mark_used_attributes (exp
, &list
, &ndim
) || ndim
== 0)
3661 unmark_used_attributes (list
, 0, 0);
3665 /* Create an attribute space from the list of used attributes. For each
3666 dimension in the attribute space, record the attribute, list of values
3667 used, and number of values used. Add members to the list of values to
3668 cover the domain of the attribute. This makes the expanded COND form
3669 order independent. */
3671 space
= (struct dimension
*) xmalloc (ndim
* sizeof (struct dimension
));
3674 for (ndim
= 0; list
; ndim
++)
3676 /* Pull the first attribute value from the list and record that
3677 attribute as another dimension in the attribute space. */
3678 const char *name
= XSTR (XEXP (list
, 0), 0);
3681 if ((space
[ndim
].attr
= find_attr (name
, 0)) == 0
3682 || space
[ndim
].attr
->is_numeric
)
3684 unmark_used_attributes (list
, space
, ndim
);
3688 /* Add all remaining attribute values that refer to this attribute. */
3689 space
[ndim
].num_values
= 0;
3690 space
[ndim
].values
= 0;
3692 for (link
= list
; link
; link
= *prev
)
3693 if (! strcmp (XSTR (XEXP (link
, 0), 0), name
))
3695 space
[ndim
].num_values
++;
3696 *prev
= XEXP (link
, 1);
3697 XEXP (link
, 1) = space
[ndim
].values
;
3698 space
[ndim
].values
= link
;
3701 prev
= &XEXP (link
, 1);
3703 /* Add sufficient members to the list of values to make the list
3704 mutually exclusive and record the total size of the attribute
3706 total
*= add_values_to_cover (&space
[ndim
]);
3709 /* Sort the attribute space so that the attributes go from non-constant
3710 to constant and from most values to least values. */
3711 for (i
= 0; i
< ndim
; i
++)
3712 for (j
= ndim
- 1; j
> i
; j
--)
3713 if ((space
[j
-1].attr
->is_const
&& !space
[j
].attr
->is_const
)
3714 || space
[j
-1].num_values
< space
[j
].num_values
)
3716 struct dimension tmp
;
3718 space
[j
] = space
[j
- 1];
3722 /* Establish the initial current value. */
3723 for (i
= 0; i
< ndim
; i
++)
3724 space
[i
].current_value
= space
[i
].values
;
3726 condtest
= (rtx
*) xmalloc (total
* sizeof (rtx
));
3727 condval
= (rtx
*) xmalloc (total
* sizeof (rtx
));
3729 /* Expand the tests and values by iterating over all values in the
3733 condtest
[i
] = test_for_current_value (space
, ndim
);
3734 condval
[i
] = simplify_with_current_value (exp
, space
, ndim
);
3735 if (! increment_current_value (space
, ndim
))
3741 /* We are now finished with the original expression. */
3742 unmark_used_attributes (0, space
, ndim
);
3745 /* Find the most used constant value and make that the default. */
3747 for (i
= num_marks
= 0; i
< total
; i
++)
3748 if (GET_CODE (condval
[i
]) == CONST_STRING
3749 && ! ATTR_EQ_ATTR_P (condval
[i
]))
3751 /* Mark the unmarked constant value and count how many are marked. */
3752 ATTR_EQ_ATTR_P (condval
[i
]) = 1;
3753 for (j
= new_marks
= 0; j
< total
; j
++)
3754 if (GET_CODE (condval
[j
]) == CONST_STRING
3755 && ATTR_EQ_ATTR_P (condval
[j
]))
3757 if (new_marks
- num_marks
> most_tests
)
3759 most_tests
= new_marks
- num_marks
;
3760 defval
= condval
[i
];
3762 num_marks
= new_marks
;
3764 /* Clear all the marks. */
3765 for (i
= 0; i
< total
; i
++)
3766 ATTR_EQ_ATTR_P (condval
[i
]) = 0;
3768 /* Give up if nothing is constant. */
3772 /* If all values are the default, use that. */
3773 else if (total
== most_tests
)
3776 /* Make a COND with the most common constant value the default. (A more
3777 complex method where tests with the same value were combined didn't
3778 seem to improve things.) */
3781 condexp
= rtx_alloc (COND
);
3782 XVEC (condexp
, 0) = rtvec_alloc ((total
- most_tests
) * 2);
3783 XEXP (condexp
, 1) = defval
;
3784 for (i
= j
= 0; i
< total
; i
++)
3785 if (condval
[i
] != defval
)
3787 XVECEXP (condexp
, 0, 2 * j
) = condtest
[i
];
3788 XVECEXP (condexp
, 0, 2 * j
+ 1) = condval
[i
];
3798 /* Set the ATTR_EQ_ATTR_P flag for all EQ_ATTR expressions in EXP and
3799 verify that EXP can be simplified to a constant term if all the EQ_ATTR
3800 tests have known value. */
3803 find_and_mark_used_attributes (exp
, terms
, nterms
)
3809 switch (GET_CODE (exp
))
3812 if (! ATTR_EQ_ATTR_P (exp
))
3814 rtx link
= rtx_alloc (EXPR_LIST
);
3815 XEXP (link
, 0) = exp
;
3816 XEXP (link
, 1) = *terms
;
3819 ATTR_EQ_ATTR_P (exp
) = 1;
3828 if (! find_and_mark_used_attributes (XEXP (exp
, 2), terms
, nterms
))
3832 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3835 if (! find_and_mark_used_attributes (XEXP (exp
, 0), terms
, nterms
))
3840 for (i
= 0; i
< XVECLEN (exp
, 0); i
++)
3841 if (! find_and_mark_used_attributes (XVECEXP (exp
, 0, i
), terms
, nterms
))
3843 if (! find_and_mark_used_attributes (XEXP (exp
, 1), terms
, nterms
))
3852 /* Clear the ATTR_EQ_ATTR_P flag in all EQ_ATTR expressions on LIST and
3853 in the values of the NDIM-dimensional attribute space SPACE. */
3856 unmark_used_attributes (list
, space
, ndim
)
3858 struct dimension
*space
;
3864 for (i
= 0; i
< ndim
; i
++)
3865 unmark_used_attributes (space
[i
].values
, 0, 0);
3867 for (link
= list
; link
; link
= XEXP (link
, 1))
3869 exp
= XEXP (link
, 0);
3870 if (GET_CODE (exp
) == EQ_ATTR
)
3871 ATTR_EQ_ATTR_P (exp
) = 0;
3875 /* Update the attribute dimension DIM so that all values of the attribute
3876 are tested. Return the updated number of values. */
3879 add_values_to_cover (dim
)
3880 struct dimension
*dim
;
3882 struct attr_value
*av
;
3883 rtx exp
, link
, *prev
;
3886 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3887 if (GET_CODE (av
->value
) == CONST_STRING
)
3890 if (nalt
< dim
->num_values
)
3892 else if (nalt
== dim
->num_values
)
3895 else if (nalt
* 2 < dim
->num_values
* 3)
3897 /* Most all the values of the attribute are used, so add all the unused
3899 prev
= &dim
->values
;
3900 for (link
= dim
->values
; link
; link
= *prev
)
3901 prev
= &XEXP (link
, 1);
3903 for (av
= dim
->attr
->first_value
; av
; av
= av
->next
)
3904 if (GET_CODE (av
->value
) == CONST_STRING
)
3906 exp
= attr_eq (dim
->attr
->name
, XSTR (av
->value
, 0));
3907 if (ATTR_EQ_ATTR_P (exp
))
3910 link
= rtx_alloc (EXPR_LIST
);
3911 XEXP (link
, 0) = exp
;
3914 prev
= &XEXP (link
, 1);
3916 dim
->num_values
= nalt
;
3920 rtx orexp
= false_rtx
;
3922 /* Very few values are used, so compute a mutually exclusive
3923 expression. (We could do this for numeric values if that becomes
3925 prev
= &dim
->values
;
3926 for (link
= dim
->values
; link
; link
= *prev
)
3928 orexp
= insert_right_side (IOR
, orexp
, XEXP (link
, 0), -2, -2);
3929 prev
= &XEXP (link
, 1);
3931 link
= rtx_alloc (EXPR_LIST
);
3932 XEXP (link
, 0) = attr_rtx (NOT
, orexp
);
3937 return dim
->num_values
;
3940 /* Increment the current value for the NDIM-dimensional attribute space SPACE
3941 and return FALSE if the increment overflowed. */
3944 increment_current_value (space
, ndim
)
3945 struct dimension
*space
;
3950 for (i
= ndim
- 1; i
>= 0; i
--)
3952 if ((space
[i
].current_value
= XEXP (space
[i
].current_value
, 1)) == 0)
3953 space
[i
].current_value
= space
[i
].values
;
3960 /* Construct an expression corresponding to the current value for the
3961 NDIM-dimensional attribute space SPACE. */
3964 test_for_current_value (space
, ndim
)
3965 struct dimension
*space
;
3971 for (i
= 0; i
< ndim
; i
++)
3972 exp
= insert_right_side (AND
, exp
, XEXP (space
[i
].current_value
, 0),
3978 /* Given the current value of the NDIM-dimensional attribute space SPACE,
3979 set the corresponding EQ_ATTR expressions to that value and reduce
3980 the expression EXP as much as possible. On input [and output], all
3981 known EQ_ATTR expressions are set to FALSE. */
3984 simplify_with_current_value (exp
, space
, ndim
)
3986 struct dimension
*space
;
3992 /* Mark each current value as TRUE. */
3993 for (i
= 0; i
< ndim
; i
++)
3995 x
= XEXP (space
[i
].current_value
, 0);
3996 if (GET_CODE (x
) == EQ_ATTR
)
3997 ATTR_EQ_ATTR_P (x
) = 0;
4000 exp
= simplify_with_current_value_aux (exp
);
4002 /* Change each current value back to FALSE. */
4003 for (i
= 0; i
< ndim
; i
++)
4005 x
= XEXP (space
[i
].current_value
, 0);
4006 if (GET_CODE (x
) == EQ_ATTR
)
4007 ATTR_EQ_ATTR_P (x
) = 1;
4013 /* Reduce the expression EXP based on the ATTR_EQ_ATTR_P settings of
4014 all EQ_ATTR expressions. */
4017 simplify_with_current_value_aux (exp
)
4023 switch (GET_CODE (exp
))
4026 if (ATTR_EQ_ATTR_P (exp
))
4035 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
4036 if (cond
== true_rtx
)
4037 return simplify_with_current_value_aux (XEXP (exp
, 1));
4038 else if (cond
== false_rtx
)
4039 return simplify_with_current_value_aux (XEXP (exp
, 2));
4041 return attr_rtx (IF_THEN_ELSE
, cond
,
4042 simplify_with_current_value_aux (XEXP (exp
, 1)),
4043 simplify_with_current_value_aux (XEXP (exp
, 2)));
4046 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
4047 if (cond
== true_rtx
)
4049 else if (cond
== false_rtx
)
4050 return simplify_with_current_value_aux (XEXP (exp
, 0));
4052 return attr_rtx (IOR
, cond
,
4053 simplify_with_current_value_aux (XEXP (exp
, 0)));
4056 cond
= simplify_with_current_value_aux (XEXP (exp
, 1));
4057 if (cond
== true_rtx
)
4058 return simplify_with_current_value_aux (XEXP (exp
, 0));
4059 else if (cond
== false_rtx
)
4062 return attr_rtx (AND
, cond
,
4063 simplify_with_current_value_aux (XEXP (exp
, 0)));
4066 cond
= simplify_with_current_value_aux (XEXP (exp
, 0));
4067 if (cond
== true_rtx
)
4069 else if (cond
== false_rtx
)
4072 return attr_rtx (NOT
, cond
);
4075 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4077 cond
= simplify_with_current_value_aux (XVECEXP (exp
, 0, i
));
4078 if (cond
== true_rtx
)
4079 return simplify_with_current_value_aux (XVECEXP (exp
, 0, i
+ 1));
4080 else if (cond
== false_rtx
)
4083 abort (); /* With all EQ_ATTR's of known value, a case should
4084 have been selected. */
4086 return simplify_with_current_value_aux (XEXP (exp
, 1));
4093 /* Clear the ATTR_CURR_SIMPLIFIED_P flag in EXP and its subexpressions. */
4096 clear_struct_flag (x
)
4104 ATTR_CURR_SIMPLIFIED_P (x
) = 0;
4105 if (ATTR_IND_SIMPLIFIED_P (x
))
4108 code
= GET_CODE (x
);
4129 /* Compare the elements. If any pair of corresponding elements
4130 fail to match, return 0 for the whole things. */
4132 fmt
= GET_RTX_FORMAT (code
);
4133 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4139 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4140 clear_struct_flag (XVECEXP (x
, i
, j
));
4144 clear_struct_flag (XEXP (x
, i
));
4150 /* Return the number of RTX objects making up the expression X.
4151 But if we count more than MAX objects, stop counting. */
4154 count_sub_rtxs (x
, max
)
4164 code
= GET_CODE (x
);
4185 /* Compare the elements. If any pair of corresponding elements
4186 fail to match, return 0 for the whole things. */
4188 fmt
= GET_RTX_FORMAT (code
);
4189 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4198 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4199 total
+= count_sub_rtxs (XVECEXP (x
, i
, j
), max
);
4203 total
+= count_sub_rtxs (XEXP (x
, i
), max
);
4211 /* Create table entries for DEFINE_ATTR. */
4214 gen_attr (exp
, lineno
)
4218 struct attr_desc
*attr
;
4219 struct attr_value
*av
;
4220 const char *name_ptr
;
4223 /* Make a new attribute structure. Check for duplicate by looking at
4224 attr->default_val, since it is initialized by this routine. */
4225 attr
= find_attr (XSTR (exp
, 0), 1);
4226 if (attr
->default_val
)
4228 message_with_line (lineno
, "duplicate definition for attribute %s",
4230 message_with_line (attr
->lineno
, "previous definition");
4234 attr
->lineno
= lineno
;
4236 if (*XSTR (exp
, 1) == '\0')
4237 attr
->is_numeric
= 1;
4240 name_ptr
= XSTR (exp
, 1);
4241 while ((p
= next_comma_elt (&name_ptr
)) != NULL
)
4243 av
= (struct attr_value
*) oballoc (sizeof (struct attr_value
));
4244 av
->value
= attr_rtx (CONST_STRING
, p
);
4245 av
->next
= attr
->first_value
;
4246 attr
->first_value
= av
;
4247 av
->first_insn
= NULL
;
4249 av
->has_asm_insn
= 0;
4253 if (GET_CODE (XEXP (exp
, 2)) == CONST
)
4256 if (attr
->is_numeric
)
4258 message_with_line (lineno
,
4259 "constant attributes may not take numeric values");
4263 /* Get rid of the CONST node. It is allowed only at top-level. */
4264 XEXP (exp
, 2) = XEXP (XEXP (exp
, 2), 0);
4267 if (! strcmp (attr
->name
, "length") && ! attr
->is_numeric
)
4269 message_with_line (lineno
,
4270 "`length' attribute must take numeric values");
4274 /* Set up the default value. */
4275 XEXP (exp
, 2) = check_attr_value (XEXP (exp
, 2), attr
);
4276 attr
->default_val
= get_attr_value (XEXP (exp
, 2), attr
, -2);
4279 /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
4280 alternatives in the constraints. Assume all MATCH_OPERANDs have the same
4281 number of alternatives as this should be checked elsewhere. */
4284 count_alternatives (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 (exp
)
4328 if (GET_CODE (exp
) == EQ_ATTR
&& XSTR (exp
, 0) == alternative_name
)
4331 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4332 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4337 if (compares_alternatives_p (XEXP (exp
, i
)))
4342 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4343 if (compares_alternatives_p (XVECEXP (exp
, i
, j
)))
4351 /* Returns nonzero is INNER is contained in EXP. */
4354 contained_in_p (inner
, exp
)
4361 if (rtx_equal_p (inner
, exp
))
4364 for (i
= 0, fmt
= GET_RTX_FORMAT (GET_CODE (exp
));
4365 i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4370 if (contained_in_p (inner
, XEXP (exp
, i
)))
4375 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4376 if (contained_in_p (inner
, XVECEXP (exp
, i
, j
)))
4384 /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES. */
4387 gen_insn (exp
, lineno
)
4391 struct insn_def
*id
;
4393 id
= (struct insn_def
*) oballoc (sizeof (struct insn_def
));
4397 id
->lineno
= lineno
;
4399 switch (GET_CODE (exp
))
4402 id
->insn_code
= insn_code_number
;
4403 id
->insn_index
= insn_index_number
;
4404 id
->num_alternatives
= count_alternatives (exp
);
4405 if (id
->num_alternatives
== 0)
4406 id
->num_alternatives
= 1;
4410 case DEFINE_PEEPHOLE
:
4411 id
->insn_code
= insn_code_number
;
4412 id
->insn_index
= insn_index_number
;
4413 id
->num_alternatives
= count_alternatives (exp
);
4414 if (id
->num_alternatives
== 0)
4415 id
->num_alternatives
= 1;
4419 case DEFINE_ASM_ATTRIBUTES
:
4421 id
->insn_index
= -1;
4422 id
->num_alternatives
= 1;
4424 got_define_asm_attributes
= 1;
4432 /* Process a DEFINE_DELAY. Validate the vector length, check if annul
4433 true or annul false is specified, and make a `struct delay_desc'. */
4436 gen_delay (def
, lineno
)
4440 struct delay_desc
*delay
;
4443 if (XVECLEN (def
, 1) % 3 != 0)
4445 message_with_line (lineno
,
4446 "number of elements in DEFINE_DELAY must be multiple of three");
4451 for (i
= 0; i
< XVECLEN (def
, 1); i
+= 3)
4453 if (XVECEXP (def
, 1, i
+ 1))
4454 have_annul_true
= 1;
4455 if (XVECEXP (def
, 1, i
+ 2))
4456 have_annul_false
= 1;
4459 delay
= (struct delay_desc
*) oballoc (sizeof (struct delay_desc
));
4461 delay
->num
= ++num_delays
;
4462 delay
->next
= delays
;
4463 delay
->lineno
= lineno
;
4467 /* Process a DEFINE_FUNCTION_UNIT.
4469 This gives information about a function unit contained in the CPU.
4470 We fill in a `struct function_unit_op' and a `struct function_unit'
4471 with information used later by `expand_unit'. */
4474 gen_unit (def
, lineno
)
4478 struct function_unit
*unit
;
4479 struct function_unit_op
*op
;
4480 const char *name
= XSTR (def
, 0);
4481 int multiplicity
= XINT (def
, 1);
4482 int simultaneity
= XINT (def
, 2);
4483 rtx condexp
= XEXP (def
, 3);
4484 int ready_cost
= MAX (XINT (def
, 4), 1);
4485 int issue_delay
= MAX (XINT (def
, 5), 1);
4487 /* See if we have already seen this function unit. If so, check that
4488 the multiplicity and simultaneity values are the same. If not, make
4489 a structure for this function unit. */
4490 for (unit
= units
; unit
; unit
= unit
->next
)
4491 if (! strcmp (unit
->name
, name
))
4493 if (unit
->multiplicity
!= multiplicity
4494 || unit
->simultaneity
!= simultaneity
)
4496 message_with_line (lineno
,
4497 "differing specifications given for function unit %s",
4499 message_with_line (unit
->first_lineno
, "previous definition");
4508 unit
= (struct function_unit
*) oballoc (sizeof (struct function_unit
));
4510 unit
->multiplicity
= multiplicity
;
4511 unit
->simultaneity
= simultaneity
;
4512 unit
->issue_delay
.min
= unit
->issue_delay
.max
= issue_delay
;
4513 unit
->num
= num_units
++;
4514 unit
->num_opclasses
= 0;
4515 unit
->condexp
= false_rtx
;
4518 unit
->first_lineno
= lineno
;
4522 /* Make a new operation class structure entry and initialize it. */
4523 op
= (struct function_unit_op
*) oballoc (sizeof (struct function_unit_op
));
4524 op
->condexp
= condexp
;
4525 op
->num
= unit
->num_opclasses
++;
4526 op
->ready
= ready_cost
;
4527 op
->issue_delay
= issue_delay
;
4528 op
->next
= unit
->ops
;
4529 op
->lineno
= lineno
;
4531 num_unit_opclasses
++;
4533 /* Set our issue expression based on whether or not an optional conflict
4534 vector was specified. */
4537 /* Compute the IOR of all the specified expressions. */
4538 rtx orexp
= false_rtx
;
4541 for (i
= 0; i
< XVECLEN (def
, 6); i
++)
4542 orexp
= insert_right_side (IOR
, orexp
, XVECEXP (def
, 6, i
), -2, -2);
4544 op
->conflict_exp
= orexp
;
4545 extend_range (&unit
->issue_delay
, 1, issue_delay
);
4549 op
->conflict_exp
= true_rtx
;
4550 extend_range (&unit
->issue_delay
, issue_delay
, issue_delay
);
4553 /* Merge our conditional into that of the function unit so we can determine
4554 which insns are used by the function unit. */
4555 unit
->condexp
= insert_right_side (IOR
, unit
->condexp
, op
->condexp
, -2, -2);
4558 /* Given a piece of RTX, print a C expression to test its truth value.
4559 We use AND and IOR both for logical and bit-wise operations, so
4560 interpret them as logical unless they are inside a comparison expression.
4561 The first bit of FLAGS will be nonzero in that case.
4563 Set the second bit of FLAGS to make references to attribute values use
4564 a cached local variable instead of calling a function. */
4567 write_test_expr (exp
, flags
)
4571 int comparison_operator
= 0;
4573 struct attr_desc
*attr
;
4575 /* In order not to worry about operator precedence, surround our part of
4576 the expression with parentheses. */
4579 code
= GET_CODE (exp
);
4582 /* Binary operators. */
4584 case GE
: case GT
: case GEU
: case GTU
:
4585 case LE
: case LT
: case LEU
: case LTU
:
4586 comparison_operator
= 1;
4588 case PLUS
: case MINUS
: case MULT
: case DIV
: case MOD
:
4589 case AND
: case IOR
: case XOR
:
4590 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
4591 write_test_expr (XEXP (exp
, 0), flags
| comparison_operator
);
4607 printf (" >= (unsigned) ");
4610 printf (" > (unsigned) ");
4619 printf (" <= (unsigned) ");
4622 printf (" < (unsigned) ");
4665 write_test_expr (XEXP (exp
, 1), flags
| comparison_operator
);
4669 /* Special-case (not (eq_attrq "alternative" "x")) */
4670 if (! (flags
& 1) && GET_CODE (XEXP (exp
, 0)) == EQ_ATTR
4671 && XSTR (XEXP (exp
, 0), 0) == alternative_name
)
4673 printf ("which_alternative != %s", XSTR (XEXP (exp
, 0), 1));
4677 /* Otherwise, fall through to normal unary operator. */
4679 /* Unary operators. */
4699 write_test_expr (XEXP (exp
, 0), flags
);
4702 /* Comparison test of an attribute with a value. Most of these will
4703 have been removed by optimization. Handle "alternative"
4704 specially and give error if EQ_ATTR present inside a comparison. */
4707 fatal ("EQ_ATTR not valid inside comparison");
4709 if (XSTR (exp
, 0) == alternative_name
)
4711 printf ("which_alternative == %s", XSTR (exp
, 1));
4715 attr
= find_attr (XSTR (exp
, 0), 0);
4719 /* Now is the time to expand the value of a constant attribute. */
4722 write_test_expr (evaluate_eq_attr (exp
, attr
->default_val
->value
,
4729 printf ("attr_%s", attr
->name
);
4731 printf ("get_attr_%s (insn)", attr
->name
);
4733 write_attr_valueq (attr
, XSTR (exp
, 1));
4737 /* Comparison test of flags for define_delays. */
4740 fatal ("ATTR_FLAG not valid inside comparison");
4741 printf ("(flags & ATTR_FLAG_%s) != 0", XSTR (exp
, 0));
4744 /* See if an operand matches a predicate. */
4746 /* If only a mode is given, just ensure the mode matches the operand.
4747 If neither a mode nor predicate is given, error. */
4748 if (XSTR (exp
, 1) == NULL
|| *XSTR (exp
, 1) == '\0')
4750 if (GET_MODE (exp
) == VOIDmode
)
4751 fatal ("null MATCH_OPERAND specified as test");
4753 printf ("GET_MODE (operands[%d]) == %smode",
4754 XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4757 printf ("%s (operands[%d], %smode)",
4758 XSTR (exp
, 1), XINT (exp
, 0), GET_MODE_NAME (GET_MODE (exp
)));
4762 printf ("%s (insn)", XSTR (exp
, 0));
4765 /* Constant integer. */
4767 printf (HOST_WIDE_INT_PRINT_DEC
, XWINT (exp
, 0));
4770 /* A random C expression. */
4772 printf ("%s", XSTR (exp
, 0));
4775 /* The address of the branch target. */
4777 printf ("INSN_ADDRESSES_SET_P () ? INSN_ADDRESSES (INSN_UID (GET_CODE (operands[%d]) == LABEL_REF ? XEXP (operands[%d], 0) : operands[%d])) : 0",
4778 XINT (exp
, 0), XINT (exp
, 0), XINT (exp
, 0));
4782 /* The address of the current insn. We implement this actually as the
4783 address of the current insn for backward branches, but the last
4784 address of the next insn for forward branches, and both with
4785 adjustments that account for the worst-case possible stretching of
4786 intervening alignments between this insn and its destination. */
4787 printf ("insn_current_reference_address (insn)");
4791 printf ("%s", XSTR (exp
, 0));
4795 write_test_expr (XEXP (exp
, 0), flags
& 2);
4797 write_test_expr (XEXP (exp
, 1), flags
| 1);
4799 write_test_expr (XEXP (exp
, 2), flags
| 1);
4803 fatal ("bad RTX code `%s' in attribute calculation\n",
4804 GET_RTX_NAME (code
));
4810 /* Given an attribute value, return the maximum CONST_STRING argument
4811 encountered. Set *UNKNOWNP and return INT_MAX if the value is unknown. */
4814 max_attr_value (exp
, unknownp
)
4821 switch (GET_CODE (exp
))
4824 current_max
= atoi (XSTR (exp
, 0));
4828 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4829 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4831 n
= max_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4832 if (n
> current_max
)
4838 current_max
= max_attr_value (XEXP (exp
, 1), unknownp
);
4839 n
= max_attr_value (XEXP (exp
, 2), unknownp
);
4840 if (n
> current_max
)
4846 current_max
= INT_MAX
;
4853 /* Given an attribute value, return the result of ORing together all
4854 CONST_STRING arguments encountered. Set *UNKNOWNP and return -1
4855 if the numeric value is not known. */
4858 or_attr_value (exp
, unknownp
)
4865 switch (GET_CODE (exp
))
4868 current_or
= atoi (XSTR (exp
, 0));
4872 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4873 for (i
= 0; i
< XVECLEN (exp
, 0); i
+= 2)
4874 current_or
|= or_attr_value (XVECEXP (exp
, 0, i
+ 1), unknownp
);
4878 current_or
= or_attr_value (XEXP (exp
, 1), unknownp
);
4879 current_or
|= or_attr_value (XEXP (exp
, 2), unknownp
);
4891 /* Scan an attribute value, possibly a conditional, and record what actions
4892 will be required to do any conditional tests in it.
4895 `must_extract' if we need to extract the insn operands
4896 `must_constrain' if we must compute `which_alternative'
4897 `address_used' if an address expression was used
4898 `length_used' if an (eq_attr "length" ...) was used
4902 walk_attr_value (exp
)
4912 code
= GET_CODE (exp
);
4916 if (! ATTR_IND_SIMPLIFIED_P (exp
))
4917 /* Since this is an arbitrary expression, it can look at anything.
4918 However, constant expressions do not depend on any particular
4920 must_extract
= must_constrain
= 1;
4928 if (XSTR (exp
, 0) == alternative_name
)
4929 must_extract
= must_constrain
= 1;
4930 else if (strcmp (XSTR (exp
, 0), "length") == 0)
4950 for (i
= 0, fmt
= GET_RTX_FORMAT (code
); i
< GET_RTX_LENGTH (code
); i
++)
4955 walk_attr_value (XEXP (exp
, i
));
4959 if (XVEC (exp
, i
) != NULL
)
4960 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4961 walk_attr_value (XVECEXP (exp
, i
, j
));
4966 /* Write out a function to obtain the attribute for a given INSN. */
4969 write_attr_get (attr
)
4970 struct attr_desc
*attr
;
4972 struct attr_value
*av
, *common_av
;
4974 /* Find the most used attribute value. Handle that as the `default' of the
4975 switch we will generate. */
4976 common_av
= find_most_used (attr
);
4978 /* Write out prototype of function. */
4979 if (!attr
->is_numeric
)
4980 printf ("extern enum attr_%s ", attr
->name
);
4981 else if (attr
->unsigned_p
)
4982 printf ("extern unsigned int ");
4984 printf ("extern int ");
4985 /* If the attribute name starts with a star, the remainder is the name of
4986 the subroutine to use, instead of `get_attr_...'. */
4987 if (attr
->name
[0] == '*')
4988 printf ("%s PARAMS ((rtx));\n", &attr
->name
[1]);
4990 printf ("get_attr_%s PARAMS ((%s));\n", attr
->name
,
4991 (attr
->is_const
? "void" : "rtx"));
4993 /* Write out start of function, then all values with explicit `case' lines,
4994 then a `default', then the value with the most uses. */
4995 if (!attr
->is_numeric
)
4996 printf ("enum attr_%s\n", attr
->name
);
4997 else if (attr
->unsigned_p
)
4998 printf ("unsigned int\n");
5002 /* If the attribute name starts with a star, the remainder is the name of
5003 the subroutine to use, instead of `get_attr_...'. */
5004 if (attr
->name
[0] == '*')
5005 printf ("%s (insn)\n", &attr
->name
[1]);
5006 else if (attr
->is_const
== 0)
5007 printf ("get_attr_%s (insn)\n", attr
->name
);
5010 printf ("get_attr_%s ()\n", attr
->name
);
5013 for (av
= attr
->first_value
; av
; av
= av
->next
)
5014 if (av
->num_insns
!= 0)
5015 write_attr_set (attr
, 2, av
->value
, "return", ";",
5016 true_rtx
, av
->first_insn
->insn_code
,
5017 av
->first_insn
->insn_index
);
5023 printf (" rtx insn;\n");
5026 if (GET_CODE (common_av
->value
) == FFS
)
5028 rtx p
= XEXP (common_av
->value
, 0);
5030 /* No need to emit code to abort if the insn is unrecognized; the
5031 other get_attr_foo functions will do that when we call them. */
5033 write_toplevel_expr (p
);
5035 printf ("\n if (accum && accum == (accum & -accum))\n");
5037 printf (" int i;\n");
5038 printf (" for (i = 0; accum >>= 1; ++i) continue;\n");
5039 printf (" accum = i;\n");
5040 printf (" }\n else\n");
5041 printf (" accum = ~accum;\n");
5042 printf (" return accum;\n}\n\n");
5046 printf (" switch (recog_memoized (insn))\n");
5049 for (av
= attr
->first_value
; av
; av
= av
->next
)
5050 if (av
!= common_av
)
5051 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5053 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5054 printf (" }\n}\n\n");
5058 /* Given an AND tree of known true terms (because we are inside an `if' with
5059 that as the condition or are in an `else' clause) and an expression,
5060 replace any known true terms with TRUE. Use `simplify_and_tree' to do
5061 the bulk of the work. */
5064 eliminate_known_true (known_true
, exp
, insn_code
, insn_index
)
5067 int insn_code
, insn_index
;
5071 known_true
= SIMPLIFY_TEST_EXP (known_true
, insn_code
, insn_index
);
5073 if (GET_CODE (known_true
) == AND
)
5075 exp
= eliminate_known_true (XEXP (known_true
, 0), exp
,
5076 insn_code
, insn_index
);
5077 exp
= eliminate_known_true (XEXP (known_true
, 1), exp
,
5078 insn_code
, insn_index
);
5083 exp
= simplify_and_tree (exp
, &term
, insn_code
, insn_index
);
5089 /* Write out a series of tests and assignment statements to perform tests and
5090 sets of an attribute value. We are passed an indentation amount and prefix
5091 and suffix strings to write around each attribute value (e.g., "return"
5095 write_attr_set (attr
, indent
, value
, prefix
, suffix
, known_true
,
5096 insn_code
, insn_index
)
5097 struct attr_desc
*attr
;
5103 int insn_code
, insn_index
;
5105 if (GET_CODE (value
) == COND
)
5107 /* Assume the default value will be the default of the COND unless we
5108 find an always true expression. */
5109 rtx default_val
= XEXP (value
, 1);
5110 rtx our_known_true
= known_true
;
5115 for (i
= 0; i
< XVECLEN (value
, 0); i
+= 2)
5120 testexp
= eliminate_known_true (our_known_true
,
5121 XVECEXP (value
, 0, i
),
5122 insn_code
, insn_index
);
5123 newexp
= attr_rtx (NOT
, testexp
);
5124 newexp
= insert_right_side (AND
, our_known_true
, newexp
,
5125 insn_code
, insn_index
);
5127 /* If the test expression is always true or if the next `known_true'
5128 expression is always false, this is the last case, so break
5129 out and let this value be the `else' case. */
5130 if (testexp
== true_rtx
|| newexp
== false_rtx
)
5132 default_val
= XVECEXP (value
, 0, i
+ 1);
5136 /* Compute the expression to pass to our recursive call as being
5138 inner_true
= insert_right_side (AND
, our_known_true
,
5139 testexp
, insn_code
, insn_index
);
5141 /* If this is always false, skip it. */
5142 if (inner_true
== false_rtx
)
5145 write_indent (indent
);
5146 printf ("%sif ", first_if
? "" : "else ");
5148 write_test_expr (testexp
, 0);
5150 write_indent (indent
+ 2);
5153 write_attr_set (attr
, indent
+ 4,
5154 XVECEXP (value
, 0, i
+ 1), prefix
, suffix
,
5155 inner_true
, insn_code
, insn_index
);
5156 write_indent (indent
+ 2);
5158 our_known_true
= newexp
;
5163 write_indent (indent
);
5165 write_indent (indent
+ 2);
5169 write_attr_set (attr
, first_if
? indent
: indent
+ 4, default_val
,
5170 prefix
, suffix
, our_known_true
, insn_code
, insn_index
);
5174 write_indent (indent
+ 2);
5180 write_indent (indent
);
5181 printf ("%s ", prefix
);
5182 write_attr_value (attr
, value
);
5183 printf ("%s\n", suffix
);
5187 /* Write out the computation for one attribute value. */
5190 write_attr_case (attr
, av
, write_case_lines
, prefix
, suffix
, indent
,
5192 struct attr_desc
*attr
;
5193 struct attr_value
*av
;
5194 int write_case_lines
;
5195 const char *prefix
, *suffix
;
5199 struct insn_ent
*ie
;
5201 if (av
->num_insns
== 0)
5204 if (av
->has_asm_insn
)
5206 write_indent (indent
);
5207 printf ("case -1:\n");
5208 write_indent (indent
+ 2);
5209 printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
5210 write_indent (indent
+ 2);
5211 printf (" && asm_noperands (PATTERN (insn)) < 0)\n");
5212 write_indent (indent
+ 2);
5213 printf (" fatal_insn_not_found (insn);\n");
5216 if (write_case_lines
)
5218 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
5219 if (ie
->insn_code
!= -1)
5221 write_indent (indent
);
5222 printf ("case %d:\n", ie
->insn_code
);
5227 write_indent (indent
);
5228 printf ("default:\n");
5231 /* See what we have to do to output this value. */
5232 must_extract
= must_constrain
= address_used
= 0;
5233 walk_attr_value (av
->value
);
5237 write_indent (indent
+ 2);
5238 printf ("extract_constrain_insn_cached (insn);\n");
5240 else if (must_extract
)
5242 write_indent (indent
+ 2);
5243 printf ("extract_insn_cached (insn);\n");
5246 write_attr_set (attr
, indent
+ 2, av
->value
, prefix
, suffix
,
5247 known_true
, av
->first_insn
->insn_code
,
5248 av
->first_insn
->insn_index
);
5250 if (strncmp (prefix
, "return", 6))
5252 write_indent (indent
+ 2);
5253 printf ("break;\n");
5258 /* Search for uses of non-const attributes and write code to cache them. */
5261 write_expr_attr_cache (p
, attr
)
5263 struct attr_desc
*attr
;
5268 if (GET_CODE (p
) == EQ_ATTR
)
5270 if (XSTR (p
, 0) != attr
->name
)
5273 if (!attr
->is_numeric
)
5274 printf (" enum attr_%s ", attr
->name
);
5275 else if (attr
->unsigned_p
)
5276 printf (" unsigned int ");
5280 printf ("attr_%s = get_attr_%s (insn);\n", attr
->name
, attr
->name
);
5284 fmt
= GET_RTX_FORMAT (GET_CODE (p
));
5285 ie
= GET_RTX_LENGTH (GET_CODE (p
));
5286 for (i
= 0; i
< ie
; i
++)
5291 if (write_expr_attr_cache (XEXP (p
, i
), attr
))
5296 je
= XVECLEN (p
, i
);
5297 for (j
= 0; j
< je
; ++j
)
5298 if (write_expr_attr_cache (XVECEXP (p
, i
, j
), attr
))
5307 /* Evaluate an expression at top level. A front end to write_test_expr,
5308 in which we cache attribute values and break up excessively large
5309 expressions to cater to older compilers. */
5312 write_toplevel_expr (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 (prefix
, num
, suffix
)
5350 struct function_unit
*unit
;
5352 for (unit
= units
; unit
; unit
= unit
->next
)
5353 if (unit
->num
== num
)
5355 printf ("%s%s%s", prefix
, unit
->name
, suffix
);
5359 printf ("%s<unknown>%s", prefix
, suffix
);
5363 write_attr_valueq (attr
, s
)
5364 struct attr_desc
*attr
;
5367 if (attr
->is_numeric
)
5373 /* Make the blockage range values and function units used values easier
5375 if (attr
->func_units_p
)
5378 printf (" /* units: none */");
5380 write_unit_name (" /* units: ", num
, " */");
5384 const char *sep
= " /* units: ";
5385 for (i
= 0, num
= ~num
; num
; i
++, num
>>= 1)
5388 write_unit_name (sep
, i
, (num
== 1) ? " */" : "");
5394 else if (attr
->blockage_p
)
5395 printf (" /* min %d, max %d */", num
>> (HOST_BITS_PER_INT
/ 2),
5396 num
& ((1 << (HOST_BITS_PER_INT
/ 2)) - 1));
5398 else if (num
> 9 || num
< 0)
5399 printf (" /* 0x%x */", num
);
5403 write_upcase (attr
->name
);
5410 write_attr_value (attr
, value
)
5411 struct attr_desc
*attr
;
5416 switch (GET_CODE (value
))
5419 write_attr_valueq (attr
, XSTR (value
, 0));
5423 printf (HOST_WIDE_INT_PRINT_DEC
, INTVAL (value
));
5427 fputs (XSTR (value
, 0), stdout
);
5432 struct attr_desc
*attr2
= find_attr (XSTR (value
, 0), 0);
5433 printf ("get_attr_%s (%s)", attr2
->name
,
5434 (attr2
->is_const
? "" : "insn"));
5455 write_attr_value (attr
, XEXP (value
, 0));
5459 write_attr_value (attr
, XEXP (value
, 1));
5473 /* The argument of TOUPPER should not have side effects. */
5474 putchar (TOUPPER(*str
));
5480 write_indent (indent
)
5483 for (; indent
> 8; indent
-= 8)
5486 for (; indent
; indent
--)
5490 /* Write a subroutine that is given an insn that requires a delay slot, a
5491 delay slot ordinal, and a candidate insn. It returns nonzero if the
5492 candidate can be placed in the specified delay slot of the insn.
5494 We can write as many as three subroutines. `eligible_for_delay'
5495 handles normal delay slots, `eligible_for_annul_true' indicates that
5496 the specified insn can be annulled if the branch is true, and likewise
5497 for `eligible_for_annul_false'.
5499 KIND is a string distinguishing these three cases ("delay", "annul_true",
5500 or "annul_false"). */
5503 write_eligible_delay (kind
)
5506 struct delay_desc
*delay
;
5509 struct attr_desc
*attr
;
5510 struct attr_value
*av
, *common_av
;
5513 /* Compute the maximum number of delay slots required. We use the delay
5514 ordinal times this number plus one, plus the slot number as an index into
5515 the appropriate predicate to test. */
5517 for (delay
= delays
, max_slots
= 0; delay
; delay
= delay
->next
)
5518 if (XVECLEN (delay
->def
, 1) / 3 > max_slots
)
5519 max_slots
= XVECLEN (delay
->def
, 1) / 3;
5521 /* Write function prelude. */
5524 printf ("eligible_for_%s (delay_insn, slot, candidate_insn, flags)\n",
5526 printf (" rtx delay_insn ATTRIBUTE_UNUSED;\n");
5527 printf (" int slot;\n");
5528 printf (" rtx candidate_insn;\n");
5529 printf (" int flags ATTRIBUTE_UNUSED;\n");
5531 printf (" rtx insn;\n");
5533 printf (" if (slot >= %d)\n", max_slots
);
5534 printf (" abort ();\n");
5537 /* If more than one delay type, find out which type the delay insn is. */
5541 attr
= find_attr ("*delay_type", 0);
5544 common_av
= find_most_used (attr
);
5546 printf (" insn = delay_insn;\n");
5547 printf (" switch (recog_memoized (insn))\n");
5550 sprintf (str
, " * %d;\n break;", max_slots
);
5551 for (av
= attr
->first_value
; av
; av
= av
->next
)
5552 if (av
!= common_av
)
5553 write_attr_case (attr
, av
, 1, "slot +=", str
, 4, true_rtx
);
5555 write_attr_case (attr
, common_av
, 0, "slot +=", str
, 4, true_rtx
);
5558 /* Ensure matched. Otherwise, shouldn't have been called. */
5559 printf (" if (slot < %d)\n", max_slots
);
5560 printf (" abort ();\n\n");
5563 /* If just one type of delay slot, write simple switch. */
5564 if (num_delays
== 1 && max_slots
== 1)
5566 printf (" insn = candidate_insn;\n");
5567 printf (" switch (recog_memoized (insn))\n");
5570 attr
= find_attr ("*delay_1_0", 0);
5573 common_av
= find_most_used (attr
);
5575 for (av
= attr
->first_value
; av
; av
= av
->next
)
5576 if (av
!= common_av
)
5577 write_attr_case (attr
, av
, 1, "return", ";", 4, true_rtx
);
5579 write_attr_case (attr
, common_av
, 0, "return", ";", 4, true_rtx
);
5585 /* Write a nested CASE. The first indicates which condition we need to
5586 test, and the inner CASE tests the condition. */
5587 printf (" insn = candidate_insn;\n");
5588 printf (" switch (slot)\n");
5591 for (delay
= delays
; delay
; delay
= delay
->next
)
5592 for (i
= 0; i
< XVECLEN (delay
->def
, 1); i
+= 3)
5594 printf (" case %d:\n",
5595 (i
/ 3) + (num_delays
== 1 ? 0 : delay
->num
* max_slots
));
5596 printf (" switch (recog_memoized (insn))\n");
5599 sprintf (str
, "*%s_%d_%d", kind
, delay
->num
, i
/ 3);
5600 attr
= find_attr (str
, 0);
5603 common_av
= find_most_used (attr
);
5605 for (av
= attr
->first_value
; av
; av
= av
->next
)
5606 if (av
!= common_av
)
5607 write_attr_case (attr
, av
, 1, "return", ";", 8, true_rtx
);
5609 write_attr_case (attr
, common_av
, 0, "return", ";", 8, true_rtx
);
5613 printf (" default:\n");
5614 printf (" abort ();\n");
5621 /* Write routines to compute conflict cost for function units. Then write a
5622 table describing the available function units. */
5625 write_function_unit_info ()
5627 struct function_unit
*unit
;
5630 /* Write out conflict routines for function units. Don't bother writing
5631 one if there is only one issue delay value. */
5633 for (unit
= units
; unit
; unit
= unit
->next
)
5635 if (unit
->needs_blockage_function
)
5636 write_complex_function (unit
, "blockage", "block");
5638 /* If the minimum and maximum conflict costs are the same, there
5639 is only one value, so we don't need a function. */
5640 if (! unit
->needs_conflict_function
)
5642 unit
->default_cost
= make_numeric_value (unit
->issue_delay
.max
);
5646 /* The function first computes the case from the candidate insn. */
5647 unit
->default_cost
= make_numeric_value (0);
5648 write_complex_function (unit
, "conflict_cost", "cost");
5651 /* Now that all functions have been written, write the table describing
5652 the function units. The name is included for documentation purposes
5655 printf ("const struct function_unit_desc function_units[] = {\n");
5657 /* Write out the descriptions in numeric order, but don't force that order
5658 on the list. Doing so increases the runtime of genattrtab.c. */
5659 for (i
= 0; i
< num_units
; i
++)
5661 for (unit
= units
; unit
; unit
= unit
->next
)
5665 printf (" {\"%s\", %d, %d, %d, %s, %d, %s_unit_ready_cost, ",
5666 unit
->name
, 1 << unit
->num
, unit
->multiplicity
,
5667 unit
->simultaneity
, XSTR (unit
->default_cost
, 0),
5668 unit
->issue_delay
.max
, unit
->name
);
5670 if (unit
->needs_conflict_function
)
5671 printf ("%s_unit_conflict_cost, ", unit
->name
);
5675 printf ("%d, ", unit
->max_blockage
);
5677 if (unit
->needs_range_function
)
5678 printf ("%s_unit_blockage_range, ", unit
->name
);
5682 if (unit
->needs_blockage_function
)
5683 printf ("%s_unit_blockage", unit
->name
);
5691 printf ("{\"dummy\", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* a dummy element */");
5696 write_complex_function (unit
, name
, connection
)
5697 struct function_unit
*unit
;
5698 const char *name
, *connection
;
5700 struct attr_desc
*case_attr
, *attr
;
5701 struct attr_value
*av
, *common_av
;
5707 printf ("static int %s_unit_%s PARAMS ((rtx, rtx));\n", unit
->name
, name
);
5708 printf ("static int\n");
5709 printf ("%s_unit_%s (executing_insn, candidate_insn)\n", unit
->name
, name
);
5710 printf (" rtx executing_insn;\n");
5711 printf (" rtx candidate_insn;\n");
5713 printf (" rtx insn;\n");
5714 printf (" int casenum;\n\n");
5715 printf (" insn = executing_insn;\n");
5716 printf (" switch (recog_memoized (insn))\n");
5719 /* Write the `switch' statement to get the case value. */
5720 if (strlen (unit
->name
) + sizeof "*_cases" > 256)
5722 sprintf (str
, "*%s_cases", unit
->name
);
5723 case_attr
= find_attr (str
, 0);
5726 common_av
= find_most_used (case_attr
);
5728 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5729 if (av
!= common_av
)
5730 write_attr_case (case_attr
, av
, 1,
5731 "casenum =", ";", 4, unit
->condexp
);
5733 write_attr_case (case_attr
, common_av
, 0,
5734 "casenum =", ";", 4, unit
->condexp
);
5737 /* Now write an outer switch statement on each case. Then write
5738 the tests on the executing function within each. */
5739 printf (" insn = candidate_insn;\n");
5740 printf (" switch (casenum)\n");
5743 for (i
= 0; i
< unit
->num_opclasses
; i
++)
5745 /* Ensure using this case. */
5747 for (av
= case_attr
->first_value
; av
; av
= av
->next
)
5749 && contained_in_p (make_numeric_value (i
), av
->value
))
5755 printf (" case %d:\n", i
);
5756 sprintf (str
, "*%s_%s_%d", unit
->name
, connection
, i
);
5757 attr
= find_attr (str
, 0);
5761 /* If single value, just write it. */
5762 value
= find_single_value (attr
);
5764 write_attr_set (attr
, 6, value
, "return", ";\n", true_rtx
, -2, -2);
5767 common_av
= find_most_used (attr
);
5768 printf (" switch (recog_memoized (insn))\n");
5771 for (av
= attr
->first_value
; av
; av
= av
->next
)
5772 if (av
!= common_av
)
5773 write_attr_case (attr
, av
, 1,
5774 "return", ";", 8, unit
->condexp
);
5776 write_attr_case (attr
, common_av
, 0,
5777 "return", ";", 8, unit
->condexp
);
5782 /* This default case should not be needed, but gcc's analysis is not
5783 good enough to realize that the default case is not needed for the
5784 second switch statement. */
5785 printf (" default:\n abort ();\n");
5786 printf (" }\n}\n\n");
5789 /* This page contains miscellaneous utility routines. */
5791 /* Given a pointer to a (char *), return a malloc'ed string containing the
5792 next comma-separated element. Advance the pointer to after the string
5793 scanned, or the end-of-string. Return NULL if at end of string. */
5796 next_comma_elt (pstr
)
5801 start
= scan_comma_elt (pstr
);
5806 return attr_string (start
, *pstr
- start
);
5809 /* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
5810 is nonzero, build a new attribute, if one does not exist. */
5812 static struct attr_desc
*
5813 find_attr (name
, create
)
5817 struct attr_desc
*attr
;
5820 /* Before we resort to using `strcmp', see if the string address matches
5821 anywhere. In most cases, it should have been canonicalized to do so. */
5822 if (name
== alternative_name
)
5825 index
= name
[0] & (MAX_ATTRS_INDEX
- 1);
5826 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5827 if (name
== attr
->name
)
5830 /* Otherwise, do it the slow way. */
5831 for (attr
= attrs
[index
]; attr
; attr
= attr
->next
)
5832 if (name
[0] == attr
->name
[0] && ! strcmp (name
, attr
->name
))
5838 attr
= (struct attr_desc
*) oballoc (sizeof (struct attr_desc
));
5839 attr
->name
= attr_string (name
, strlen (name
));
5840 attr
->first_value
= attr
->default_val
= NULL
;
5841 attr
->is_numeric
= attr
->negative_ok
= attr
->is_const
= attr
->is_special
= 0;
5842 attr
->unsigned_p
= attr
->func_units_p
= attr
->blockage_p
= 0;
5843 attr
->next
= attrs
[index
];
5844 attrs
[index
] = attr
;
5849 /* Create internal attribute with the given default value. */
5852 make_internal_attr (name
, value
, special
)
5857 struct attr_desc
*attr
;
5859 attr
= find_attr (name
, 1);
5860 if (attr
->default_val
)
5863 attr
->is_numeric
= 1;
5865 attr
->is_special
= (special
& 1) != 0;
5866 attr
->negative_ok
= (special
& 2) != 0;
5867 attr
->unsigned_p
= (special
& 4) != 0;
5868 attr
->func_units_p
= (special
& 8) != 0;
5869 attr
->blockage_p
= (special
& 16) != 0;
5870 attr
->default_val
= get_attr_value (value
, attr
, -2);
5873 /* Find the most used value of an attribute. */
5875 static struct attr_value
*
5876 find_most_used (attr
)
5877 struct attr_desc
*attr
;
5879 struct attr_value
*av
;
5880 struct attr_value
*most_used
;
5886 for (av
= attr
->first_value
; av
; av
= av
->next
)
5887 if (av
->num_insns
> nuses
)
5888 nuses
= av
->num_insns
, most_used
= av
;
5893 /* If an attribute only has a single value used, return it. Otherwise
5897 find_single_value (attr
)
5898 struct attr_desc
*attr
;
5900 struct attr_value
*av
;
5903 unique_value
= NULL
;
5904 for (av
= attr
->first_value
; av
; av
= av
->next
)
5910 unique_value
= av
->value
;
5913 return unique_value
;
5916 /* Return (attr_value "n") */
5919 make_numeric_value (n
)
5922 static rtx int_values
[20];
5929 if (n
< 20 && int_values
[n
])
5930 return int_values
[n
];
5932 p
= attr_printf (MAX_DIGITS
, "%d", n
);
5933 exp
= attr_rtx (CONST_STRING
, p
);
5936 int_values
[n
] = exp
;
5942 extend_range (range
, min
, max
)
5943 struct range
*range
;
5947 if (range
->min
> min
)
5949 if (range
->max
< max
)
5954 copy_rtx_unchanging (orig
)
5962 if (ATTR_IND_SIMPLIFIED_P (orig
) || ATTR_CURR_SIMPLIFIED_P (orig
))
5965 ATTR_CURR_SIMPLIFIED_P (orig
) = 1;
5969 code
= GET_CODE (orig
);
5982 copy
= rtx_alloc (code
);
5983 PUT_MODE (copy
, GET_MODE (orig
));
5984 ATTR_IND_SIMPLIFIED_P (copy
) = 1;
5986 memcpy (&XEXP (copy
, 0), &XEXP (orig
, 0),
5987 GET_RTX_LENGTH (GET_CODE (copy
)) * sizeof (rtx
));
5992 /* Determine if an insn has a constant number of delay slots, i.e., the
5993 number of delay slots is not a function of the length of the insn. */
5996 write_const_num_delay_slots ()
5998 struct attr_desc
*attr
= find_attr ("*num_delay_slots", 0);
5999 struct attr_value
*av
;
6000 struct insn_ent
*ie
;
6004 printf ("int\nconst_num_delay_slots (insn)\n");
6005 printf (" rtx insn;\n");
6007 printf (" switch (recog_memoized (insn))\n");
6010 for (av
= attr
->first_value
; av
; av
= av
->next
)
6013 walk_attr_value (av
->value
);
6016 for (ie
= av
->first_insn
; ie
; ie
= ie
->next
)
6017 if (ie
->insn_code
!= -1)
6018 printf (" case %d:\n", ie
->insn_code
);
6019 printf (" return 0;\n");
6023 printf (" default:\n");
6024 printf (" return 1;\n");
6025 printf (" }\n}\n\n");
6029 extern int main
PARAMS ((int, char **));
6037 struct attr_desc
*attr
;
6038 struct insn_def
*id
;
6042 progname
= "genattrtab";
6045 fatal ("no input file name");
6047 if (init_md_reader_args (argc
, argv
) != SUCCESS_EXIT_CODE
)
6048 return (FATAL_EXIT_CODE
);
6050 obstack_init (hash_obstack
);
6051 obstack_init (temp_obstack
);
6053 /* Set up true and false rtx's */
6054 true_rtx
= rtx_alloc (CONST_INT
);
6055 XWINT (true_rtx
, 0) = 1;
6056 false_rtx
= rtx_alloc (CONST_INT
);
6057 XWINT (false_rtx
, 0) = 0;
6058 ATTR_IND_SIMPLIFIED_P (true_rtx
) = ATTR_IND_SIMPLIFIED_P (false_rtx
) = 1;
6059 ATTR_PERMANENT_P (true_rtx
) = ATTR_PERMANENT_P (false_rtx
) = 1;
6061 alternative_name
= attr_string ("alternative", strlen ("alternative"));
6063 printf ("/* Generated automatically by the program `genattrtab'\n\
6064 from the machine description file `md'. */\n\n");
6066 /* Read the machine description. */
6068 initiate_automaton_gen (argc
, argv
);
6073 desc
= read_md_rtx (&lineno
, &insn_code_number
);
6077 switch (GET_CODE (desc
))
6080 case DEFINE_PEEPHOLE
:
6081 case DEFINE_ASM_ATTRIBUTES
:
6082 gen_insn (desc
, lineno
);
6086 gen_attr (desc
, lineno
);
6090 gen_delay (desc
, lineno
);
6093 case DEFINE_FUNCTION_UNIT
:
6094 gen_unit (desc
, lineno
);
6097 case DEFINE_CPU_UNIT
:
6098 gen_cpu_unit (desc
);
6101 case DEFINE_QUERY_CPU_UNIT
:
6102 gen_query_cpu_unit (desc
);
6110 gen_excl_set (desc
);
6114 gen_presence_set (desc
);
6118 gen_absence_set (desc
);
6121 case DEFINE_AUTOMATON
:
6122 gen_automaton (desc
);
6125 case AUTOMATA_OPTION
:
6126 gen_automata_option (desc
);
6129 case DEFINE_RESERVATION
:
6133 case DEFINE_INSN_RESERVATION
:
6134 gen_insn_reserv (desc
);
6140 if (GET_CODE (desc
) != DEFINE_ASM_ATTRIBUTES
)
6141 insn_index_number
++;
6145 return FATAL_EXIT_CODE
;
6149 /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one. */
6150 if (! got_define_asm_attributes
)
6152 tem
= rtx_alloc (DEFINE_ASM_ATTRIBUTES
);
6153 XVEC (tem
, 0) = rtvec_alloc (0);
6157 /* Expand DEFINE_DELAY information into new attribute. */
6161 if (num_units
|| num_dfa_decls
)
6163 /* Expand DEFINE_FUNCTION_UNIT information into new attributes. */
6165 /* Build DFA, output some functions and expand DFA information
6166 into new attributes. */
6170 printf ("#include \"config.h\"\n");
6171 printf ("#include \"system.h\"\n");
6172 printf ("#include \"rtl.h\"\n");
6173 printf ("#include \"tm_p.h\"\n");
6174 printf ("#include \"insn-config.h\"\n");
6175 printf ("#include \"recog.h\"\n");
6176 printf ("#include \"regs.h\"\n");
6177 printf ("#include \"real.h\"\n");
6178 printf ("#include \"output.h\"\n");
6179 printf ("#include \"insn-attr.h\"\n");
6180 printf ("#include \"toplev.h\"\n");
6181 printf ("#include \"flags.h\"\n");
6182 printf ("#include \"function.h\"\n");
6184 printf ("#define operands recog_data.operand\n\n");
6186 /* Make `insn_alternatives'. */
6187 insn_alternatives
= (int *) oballoc (insn_code_number
* sizeof (int));
6188 for (id
= defs
; id
; id
= id
->next
)
6189 if (id
->insn_code
>= 0)
6190 insn_alternatives
[id
->insn_code
] = (1 << id
->num_alternatives
) - 1;
6192 /* Make `insn_n_alternatives'. */
6193 insn_n_alternatives
= (int *) oballoc (insn_code_number
* sizeof (int));
6194 for (id
= defs
; id
; id
= id
->next
)
6195 if (id
->insn_code
>= 0)
6196 insn_n_alternatives
[id
->insn_code
] = id
->num_alternatives
;
6198 /* Prepare to write out attribute subroutines by checking everything stored
6199 away and building the attribute cases. */
6203 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6204 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6205 attr
->default_val
->value
6206 = check_attr_value (attr
->default_val
->value
, attr
);
6209 return FATAL_EXIT_CODE
;
6211 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6212 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6215 /* Construct extra attributes for `length'. */
6216 make_length_attrs ();
6218 /* Perform any possible optimizations to speed up compilation. */
6221 /* Now write out all the `gen_attr_...' routines. Do these before the
6222 special routines (specifically before write_function_unit_info), so
6223 that they get defined before they are used. */
6225 for (i
= 0; i
< MAX_ATTRS_INDEX
; i
++)
6226 for (attr
= attrs
[i
]; attr
; attr
= attr
->next
)
6228 if (! attr
->is_special
&& ! attr
->is_const
)
6229 write_attr_get (attr
);
6232 /* Write out delay eligibility information, if DEFINE_DELAY present.
6233 (The function to compute the number of delay slots will be written
6237 write_eligible_delay ("delay");
6238 if (have_annul_true
)
6239 write_eligible_delay ("annul_true");
6240 if (have_annul_false
)
6241 write_eligible_delay ("annul_false");
6244 if (num_units
|| num_dfa_decls
)
6246 /* Write out information about function units. */
6247 write_function_unit_info ();
6248 /* Output code for pipeline hazards recognition based on DFA
6249 (deterministic finite state automata. */
6253 /* Write out constant delay slot info */
6254 write_const_num_delay_slots ();
6256 write_length_unit_log ();
6259 return (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);
6262 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
6264 get_insn_name (code
)
6265 int code ATTRIBUTE_UNUSED
;