1 /* Pipeline hazard description translator.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
3 Free Software Foundation, Inc.
5 Written by Vladimir Makarov <vmakarov@redhat.com>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 3, or (at your option) any
14 GCC is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 1. Detecting pipeline structural hazards quickly. T. Proebsting,
26 C. Fraser. Proceedings of ACM SIGPLAN-SIGACT Symposium on
27 Principles of Programming Languages, pages 280--286, 1994.
29 This article is a good start point to understand usage of finite
30 state automata for pipeline hazard recognizers. But I'd
31 recommend the 2nd article for more deep understanding.
33 2. Efficient Instruction Scheduling Using Finite State Automata:
34 V. Bala and N. Rubin, Proceedings of MICRO-28. This is the best
35 article about usage of finite state automata for pipeline hazard
38 The current implementation is different from the 2nd article in the
41 1. New operator `|' (alternative) is permitted in functional unit
42 reservation which can be treated deterministically and
43 non-deterministically.
45 2. Possibility of usage of nondeterministic automata too.
47 3. Possibility to query functional unit reservations for given
50 4. Several constructions to describe impossible reservations
51 (`exclusion_set', `presence_set', `final_presence_set',
52 `absence_set', and `final_absence_set').
54 5. No reverse automata are generated. Trace instruction scheduling
55 requires this. It can be easily added in the future if we
58 6. Union of automaton states are not generated yet. It is planned
59 to be implemented. Such feature is needed to make more accurate
60 interlock insn scheduling to get state describing functional
61 unit reservation in a joint CFG point. */
63 /* This file code processes constructions of machine description file
64 which describes automaton used for recognition of processor pipeline
65 hazards by insn scheduler and can be used for other tasks (such as
68 The translator functions `gen_cpu_unit', `gen_query_cpu_unit',
69 `gen_bypass', `gen_excl_set', `gen_presence_set',
70 `gen_final_presence_set', `gen_absence_set',
71 `gen_final_absence_set', `gen_automaton', `gen_automata_option',
72 `gen_reserv', `gen_insn_reserv' are called from file
73 `genattrtab.c'. They transform RTL constructions describing
74 automata in .md file into internal representation convenient for
77 The translator major function `expand_automata' processes the
78 description internal representation into finite state automaton.
81 o checking correctness of the automaton pipeline description
82 (major function is `check_all_description').
84 o generating automaton (automata) from the description (major
85 function is `make_automaton').
87 o optional transformation of nondeterministic finite state
88 automata into deterministic ones if the alternative operator
89 `|' is treated nondeterministically in the description (major
90 function is NDFA_to_DFA).
92 o optional minimization of the finite state automata by merging
93 equivalent automaton states (major function is `minimize_DFA').
95 o forming tables (some as comb vectors) and attributes
96 representing the automata (functions output_..._table).
98 Function `write_automata' outputs the created finite state
99 automaton as different tables and functions which works with the
100 automata to inquire automaton state and to change its state. These
101 function are used by gcc instruction scheduler and may be some
106 #include "coretypes.h"
111 #include "gensupport.h"
121 /* Positions in machine description file. Now they are not used. But
122 they could be used in the future for better diagnostic messages. */
125 /* The following is element of vector of current (and planned in the
126 future) functional unit reservations. */
127 typedef unsigned HOST_WIDE_INT set_el_t
;
129 /* Reservations of function units are represented by value of the following
131 typedef set_el_t
*reserv_sets_t
;
132 typedef const set_el_t
*const_reserv_sets_t
;
134 /* The following structure describes a ticker. */
137 /* The following member value is time of the ticker creation with
138 taking into account time when the ticker is off. Active time of
139 the ticker is current time minus the value. */
140 int modified_creation_time
;
141 /* The following member value is time (incremented by one) when the
142 ticker was off. Zero value means that now the ticker is on. */
143 int incremented_off_time
;
146 /* The ticker is represented by the following type. */
147 typedef struct ticker ticker_t
;
149 /* The following type describes elements of output vectors. */
150 typedef HOST_WIDE_INT vect_el_t
;
152 /* Forward declaration of structures of internal representation of
153 pipeline description based on NDFA. */
158 struct automaton_decl
;
159 struct unit_pattern_rel_decl
;
161 struct insn_reserv_decl
;
164 struct result_regexp
;
165 struct reserv_regexp
;
166 struct nothing_regexp
;
167 struct sequence_regexp
;
168 struct repeat_regexp
;
174 struct pattern_set_el
;
175 struct pattern_reserv
;
181 struct state_ainsn_table
;
183 /* The following typedefs are for brevity. */
184 typedef struct unit_decl
*unit_decl_t
;
185 typedef const struct unit_decl
*const_unit_decl_t
;
186 typedef struct decl
*decl_t
;
187 typedef const struct decl
*const_decl_t
;
188 typedef struct regexp
*regexp_t
;
189 typedef struct unit_set_el
*unit_set_el_t
;
190 typedef struct pattern_set_el
*pattern_set_el_t
;
191 typedef struct pattern_reserv
*pattern_reserv_t
;
192 typedef struct alt_state
*alt_state_t
;
193 typedef struct state
*state_t
;
194 typedef const struct state
*const_state_t
;
195 typedef struct arc
*arc_t
;
196 typedef struct ainsn
*ainsn_t
;
197 typedef struct automaton
*automaton_t
;
198 typedef struct automata_list_el
*automata_list_el_t
;
199 typedef const struct automata_list_el
*const_automata_list_el_t
;
200 typedef struct state_ainsn_table
*state_ainsn_table_t
;
202 /* Undefined position. */
203 static pos_t no_pos
= 0;
205 /* All IR is stored in the following obstack. */
206 static struct obstack irp
;
209 /* Declare vector types for various data structures: */
211 DEF_VEC_P(alt_state_t
);
212 DEF_VEC_ALLOC_P(alt_state_t
,heap
);
214 DEF_VEC_ALLOC_P(ainsn_t
,heap
);
216 DEF_VEC_ALLOC_P(state_t
,heap
);
218 DEF_VEC_ALLOC_P(decl_t
,heap
);
219 DEF_VEC_P(reserv_sets_t
);
220 DEF_VEC_ALLOC_P(reserv_sets_t
,heap
);
222 DEF_VEC_I(vect_el_t
);
223 DEF_VEC_ALLOC_I(vect_el_t
, heap
);
224 typedef VEC(vect_el_t
,heap
) *vla_hwint_t
;
226 /* Forward declarations of functions used before their definitions, only. */
227 static regexp_t
gen_regexp_sequence (const char *);
228 static void reserv_sets_or (reserv_sets_t
, reserv_sets_t
,
230 static reserv_sets_t
get_excl_set (reserv_sets_t
);
231 static int check_presence_pattern_sets (reserv_sets_t
,
233 static int check_absence_pattern_sets (reserv_sets_t
, reserv_sets_t
,
235 static arc_t
first_out_arc (const_state_t
);
236 static arc_t
next_out_arc (arc_t
);
240 /* Options with the following names can be set up in automata_option
241 construction. Because the strings occur more one time we use the
244 #define NO_MINIMIZATION_OPTION "-no-minimization"
245 #define TIME_OPTION "-time"
246 #define STATS_OPTION "-stats"
247 #define V_OPTION "-v"
248 #define W_OPTION "-w"
249 #define NDFA_OPTION "-ndfa"
250 #define PROGRESS_OPTION "-progress"
252 /* The following flags are set up by function `initiate_automaton_gen'. */
254 /* Make automata with nondeterministic reservation by insns (`-ndfa'). */
255 static int ndfa_flag
;
257 /* Do not make minimization of DFA (`-no-minimization'). */
258 static int no_minimization_flag
;
260 /* Value of this variable is number of automata being generated. The
261 actual number of automata may be less this value if there is not
262 sufficient number of units. This value is defined by argument of
263 option `-split' or by constructions automaton if the value is zero
264 (it is default value of the argument). */
265 static int split_argument
;
267 /* Flag of output time statistics (`-time'). */
268 static int time_flag
;
270 /* Flag of automata statistics (`-stats'). */
271 static int stats_flag
;
273 /* Flag of creation of description file which contains description of
274 result automaton and statistics information (`-v'). */
277 /* Flag of output of a progress bar showing how many states were
278 generated so far for automaton being processed (`-progress'). */
279 static int progress_flag
;
281 /* Flag of generating warning instead of error for non-critical errors
286 /* Output file for pipeline hazard recognizer (PHR) being generated.
287 The value is NULL if the file is not defined. */
288 static FILE *output_file
;
290 /* Description file of PHR. The value is NULL if the file is not
292 static FILE *output_description_file
;
294 /* PHR description file name. */
295 static char *output_description_file_name
;
297 /* Value of the following variable is node representing description
298 being processed. This is start point of IR. */
299 static struct description
*description
;
303 /* This page contains description of IR structure (nodes). */
317 /* This describes define_cpu_unit and define_query_cpu_unit (see file
322 /* NULL if the automaton name is absent. */
323 const char *automaton_name
;
324 /* If the following value is not zero, the cpu unit reservation is
325 described in define_query_cpu_unit. */
328 /* The following fields are defined by checker. */
330 /* The following field value is nonzero if the unit is used in an
334 /* The following field value is order number (0, 1, ...) of given
337 /* The following field value is corresponding declaration of
338 automaton which was given in description. If the field value is
339 NULL then automaton in the unit declaration was absent. */
340 struct automaton_decl
*automaton_decl
;
341 /* The following field value is maximal cycle number (1, ...) on
342 which given unit occurs in insns. Zero value means that given
343 unit is not used in insns. */
344 int max_occ_cycle_num
;
345 /* The following field value is minimal cycle number (0, ...) on
346 which given unit occurs in insns. -1 value means that given
347 unit is not used in insns. */
348 int min_occ_cycle_num
;
349 /* The following list contains units which conflict with given
351 unit_set_el_t excl_list
;
352 /* The following list contains patterns which are required to
353 reservation of given unit. */
354 pattern_set_el_t presence_list
;
355 pattern_set_el_t final_presence_list
;
356 /* The following list contains patterns which should be not present
357 in reservation for given unit. */
358 pattern_set_el_t absence_list
;
359 pattern_set_el_t final_absence_list
;
360 /* The following is used only when `query_p' has nonzero value.
361 This is query number for the unit. */
363 /* The following is the last cycle on which the unit was checked for
364 correct distributions of units to automata in a regexp. */
365 int last_distribution_check_cycle
;
367 /* The following fields are defined by automaton generator. */
369 /* The following field value is number of the automaton to which
370 given unit belongs. */
371 int corresponding_automaton_num
;
372 /* If the following value is not zero, the cpu unit is present in a
373 `exclusion_set' or in right part of a `presence_set',
374 `final_presence_set', `absence_set', and
375 `final_absence_set'define_query_cpu_unit. */
379 /* This describes define_bypass (see file rtl.def). */
383 const char *out_insn_name
;
384 const char *in_insn_name
;
385 const char *bypass_guard_name
;
387 /* The following fields are defined by checker. */
389 /* output and input insns of given bypass. */
390 struct insn_reserv_decl
*out_insn_reserv
;
391 struct insn_reserv_decl
*in_insn_reserv
;
392 /* The next bypass for given output insn. */
393 struct bypass_decl
*next
;
396 /* This describes define_automaton (see file rtl.def). */
397 struct automaton_decl
401 /* The following fields are defined by automaton generator. */
403 /* The following field value is nonzero if the automaton is used in
404 an regexp definition. */
405 char automaton_is_used
;
407 /* The following fields are defined by checker. */
409 /* The following field value is the corresponding automaton. This
410 field is not NULL only if the automaton is present in unit
411 declarations and the automatic partition on automata is not
413 automaton_t corresponding_automaton
;
416 /* This describes exclusion relations: exclusion_set (see file
421 int first_list_length
;
425 /* This describes unit relations: [final_]presence_set or
426 [final_]absence_set (see file rtl.def). */
427 struct unit_pattern_rel_decl
436 /* This describes define_reservation (see file rtl.def). */
442 /* The following fields are defined by checker. */
444 /* The following field value is nonzero if the unit is used in an
447 /* The following field is used to check up cycle in expression
452 /* This describes define_insn_reservation (see file rtl.def). */
453 struct insn_reserv_decl
460 /* The following fields are defined by checker. */
462 /* The following field value is order number (0, 1, ...) of given
465 /* The following field value is list of bypasses in which given insn
467 struct bypass_decl
*bypass_list
;
469 /* The following fields are defined by automaton generator. */
471 /* The following field is the insn regexp transformed that
472 the regexp has not optional regexp, repetition regexp, and an
473 reservation name (i.e. reservation identifiers are changed by the
474 corresponding regexp) and all alternations are the top level
475 of the regexp. The value can be NULL only if it is special
476 insn `cycle advancing'. */
477 regexp_t transformed_regexp
;
478 /* The following field value is list of arcs marked given
479 insn. The field is used in transformation NDFA -> DFA. */
480 arc_t arcs_marked_by_insn
;
481 /* The two following fields are used during minimization of a finite state
483 /* The field value is number of equivalence class of state into
484 which arc marked by given insn enters from a state (fixed during
485 an automaton minimization). */
487 /* The following member value is the list to automata which can be
488 changed by the insn issue. */
489 automata_list_el_t important_automata_list
;
490 /* The following member is used to process insn once for output. */
494 /* This contains a declaration mentioned above. */
497 /* What node in the union? */
502 struct unit_decl unit
;
503 struct bypass_decl bypass
;
504 struct automaton_decl automaton
;
505 struct excl_rel_decl excl
;
506 struct unit_pattern_rel_decl presence
;
507 struct unit_pattern_rel_decl absence
;
508 struct reserv_decl reserv
;
509 struct insn_reserv_decl insn_reserv
;
513 /* The following structures represent parsed reservation strings. */
525 /* Cpu unit in reservation. */
529 unit_decl_t unit_decl
;
532 /* Define_reservation in a reservation. */
536 struct reserv_decl
*reserv_decl
;
539 /* Absence of reservation (represented by string `nothing'). */
540 struct nothing_regexp
542 /* This used to be empty but ISO C doesn't allow that. */
546 /* Representation of reservations separated by ',' (see file
548 struct sequence_regexp
551 regexp_t regexps
[1];
554 /* Representation of construction `repeat' (see file rtl.def). */
561 /* Representation of reservations separated by '+' (see file
566 regexp_t regexps
[1];
569 /* Representation of reservations separated by '|' (see file
574 regexp_t regexps
[1];
577 /* Representation of a reservation string. */
580 /* What node in the union? */
581 enum regexp_mode mode
;
585 struct unit_regexp unit
;
586 struct reserv_regexp reserv
;
587 struct nothing_regexp nothing
;
588 struct sequence_regexp sequence
;
589 struct repeat_regexp repeat
;
590 struct allof_regexp allof
;
591 struct oneof_regexp oneof
;
595 /* Represents description of pipeline hazard description based on
601 /* The following fields are defined by checker. */
603 /* The following fields values are correspondingly number of all
604 units, query units, and insns in the description. */
608 /* The following field value is max length (in cycles) of
609 reservations of insns. The field value is defined only for
611 int max_insn_reserv_cycles
;
613 /* The following fields are defined by automaton generator. */
615 /* The following field value is the first automaton. */
616 automaton_t first_automaton
;
618 /* The following field is created by pipeline hazard parser and
619 contains all declarations. We allocate additional entry for
620 special insn "cycle advancing" which is added by the automaton
626 /* The following nodes are created in automaton checker. */
628 /* The following nodes represent exclusion set for cpu units. Each
629 element is accessed through only one excl_list. */
632 unit_decl_t unit_decl
;
633 unit_set_el_t next_unit_set_el
;
636 /* The following nodes represent presence or absence pattern for cpu
637 units. Each element is accessed through only one presence_list or
639 struct pattern_set_el
641 /* The number of units in unit_decls. */
643 /* The units forming the pattern. */
644 struct unit_decl
**unit_decls
;
645 pattern_set_el_t next_pattern_set_el
;
649 /* The following nodes are created in automaton generator. */
652 /* The following nodes represent presence or absence pattern for cpu
653 units. Each element is accessed through only one element of
654 unit_presence_set_table or unit_absence_set_table. */
655 struct pattern_reserv
657 reserv_sets_t reserv
;
658 pattern_reserv_t next_pattern_reserv
;
661 /* The following node type describes state automaton. The state may
662 be deterministic or non-deterministic. Non-deterministic state has
663 several component states which represent alternative cpu units
664 reservations. The state also is used for describing a
665 deterministic reservation of automaton insn. */
668 /* The following member value is nonzero if there is a transition by
671 /* The following field is list of processor unit reservations on
673 reserv_sets_t reservs
;
674 /* The following field is unique number of given state between other
677 /* The following field value is automaton to which given state
679 automaton_t automaton
;
680 /* The following field value is the first arc output from given
683 unsigned int num_out_arcs
;
684 /* The following field is used to form NDFA. */
685 char it_was_placed_in_stack_for_NDFA_forming
;
686 /* The following field is used to form DFA. */
687 char it_was_placed_in_stack_for_DFA_forming
;
688 /* The following field is used to transform NDFA to DFA and DFA
689 minimization. The field value is not NULL if the state is a
690 compound state. In this case the value of field `unit_sets_list'
691 is NULL. All states in the list are in the hash table. The list
692 is formed through field `next_sorted_alt_state'. We should
693 support only one level of nesting state. */
694 alt_state_t component_states
;
695 /* The following field is used for passing graph of states. */
697 /* The list of states belonging to one equivalence class is formed
698 with the aid of the following field. */
699 state_t next_equiv_class_state
;
700 /* The two following fields are used during minimization of a finite
702 int equiv_class_num_1
, equiv_class_num_2
;
703 /* The following field is used during minimization of a finite state
704 automaton. The field value is state corresponding to equivalence
705 class to which given state belongs. */
706 state_t equiv_class_state
;
707 unsigned int *presence_signature
;
708 /* The following field value is the order number of given state.
709 The states in final DFA is enumerated with the aid of the
712 /* This member is used for passing states for searching minimal
715 /* The following member is used to evaluate min issue delay of insn
717 int min_insn_issue_delay
;
723 /* The following field refers for the state into which given arc
726 /* The following field describes that the insn issue (with cycle
727 advancing for special insn `cycle advancing' and without cycle
728 advancing for others) makes transition from given state to
729 another given state. */
731 /* The following field value is the next arc output from the same
734 /* List of arcs marked given insn is formed with the following
735 field. The field is used in transformation NDFA -> DFA. */
736 arc_t next_arc_marked_by_insn
;
739 /* The following node type describes a deterministic alternative in
740 non-deterministic state which characterizes cpu unit reservations
741 of automaton insn or which is part of NDFA. */
744 /* The following field is a deterministic state which characterizes
745 unit reservations of the instruction. */
747 /* The following field refers to the next state which characterizes
748 unit reservations of the instruction. */
749 alt_state_t next_alt_state
;
750 /* The following field refers to the next state in sorted list. */
751 alt_state_t next_sorted_alt_state
;
754 /* The following node type describes insn of automaton. They are
755 labels of FA arcs. */
758 /* The following field value is the corresponding insn declaration
760 struct insn_reserv_decl
*insn_reserv_decl
;
761 /* The following field value is the next insn declaration for an
764 /* The following field is states which characterize automaton unit
765 reservations of the instruction. The value can be NULL only if it
766 is special insn `cycle advancing'. */
767 alt_state_t alt_states
;
768 /* The following field is sorted list of states which characterize
769 automaton unit reservations of the instruction. The value can be
770 NULL only if it is special insn `cycle advancing'. */
771 alt_state_t sorted_alt_states
;
772 /* The following field refers the next automaton insn with
773 the same reservations. */
774 ainsn_t next_same_reservs_insn
;
775 /* The following field is flag of the first automaton insn with the
776 same reservations in the declaration list. Only arcs marked such
777 insn is present in the automaton. This significantly decreases
778 memory requirements especially when several automata are
780 char first_insn_with_same_reservs
;
781 /* The following member has nonzero value if there is arc from state of
782 the automaton marked by the ainsn. */
784 /* Cyclic list of insns of an equivalence class is formed with the
785 aid of the following field. */
786 ainsn_t next_equiv_class_insn
;
787 /* The following field value is nonzero if the insn declaration is
788 the first insn declaration with given equivalence number. */
789 char first_ainsn_with_given_equivalence_num
;
790 /* The following field is number of class of equivalence of insns.
791 It is necessary because many insns may be equivalent with the
792 point of view of pipeline hazards. */
793 int insn_equiv_class_num
;
794 /* The following member value is TRUE if there is an arc in the
795 automaton marked by the insn into another state. In other
796 words, the insn can change the state of the automaton. */
800 /* The following describes an automaton for PHR. */
803 /* The following field value is the list of insn declarations for
806 /* The following field value is the corresponding automaton
807 declaration. This field is not NULL only if the automatic
808 partition on automata is not used. */
809 struct automaton_decl
*corresponding_automaton_decl
;
810 /* The following field value is the next automaton. */
811 automaton_t next_automaton
;
812 /* The following field is start state of FA. There are not unit
813 reservations in the state. */
815 /* The following field value is number of equivalence classes of
816 insns (see field `insn_equiv_class_num' in
817 `insn_reserv_decl'). */
818 int insn_equiv_classes_num
;
819 /* The following field value is number of states of final DFA. */
820 int achieved_states_num
;
821 /* The following field value is the order number (0, 1, ...) of
823 int automaton_order_num
;
824 /* The following fields contain statistics information about
825 building automaton. */
826 int NDFA_states_num
, DFA_states_num
;
827 /* The following field value is defined only if minimization of DFA
829 int minimal_DFA_states_num
;
830 int NDFA_arcs_num
, DFA_arcs_num
;
831 /* The following field value is defined only if minimization of DFA
833 int minimal_DFA_arcs_num
;
834 /* The following member refers for two table state x ainsn -> int.
835 ??? Above sentence is incomprehensible. */
836 state_ainsn_table_t trans_table
;
837 /* The following member value is maximal value of min issue delay
838 for insns of the automaton. */
840 /* Usually min issue delay is small and we can place several (2, 4,
841 8) elements in one vector element. So the compression factor can
842 be 1 (no compression), 2, 4, 8. */
843 int min_issue_delay_table_compression_factor
;
844 /* Total number of locked states in this automaton. */
848 /* The following is the element of the list of automata. */
849 struct automata_list_el
851 /* The automaton itself. */
852 automaton_t automaton
;
853 /* The next automata set element. */
854 automata_list_el_t next_automata_list_el
;
857 /* The following structure describes a table state X ainsn -> int(>= 0). */
858 struct state_ainsn_table
860 /* Automaton to which given table belongs. */
861 automaton_t automaton
;
862 /* The following tree vectors for comb vector implementation of the
864 vla_hwint_t comb_vect
;
865 vla_hwint_t check_vect
;
866 vla_hwint_t base_vect
;
867 /* This is simple implementation of the table. */
868 vla_hwint_t full_vect
;
869 /* Minimal and maximal values of the previous vectors. */
870 int min_comb_vect_el_value
, max_comb_vect_el_value
;
871 int min_base_vect_el_value
, max_base_vect_el_value
;
874 /* Macros to access members of unions. Use only them for access to
875 union members of declarations and regexps. */
877 #if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
879 #define DECL_UNIT(d) __extension__ \
880 (({ __typeof (d) const _decl = (d); \
881 if (_decl->mode != dm_unit) \
882 decl_mode_check_failed (_decl->mode, "dm_unit", \
883 __FILE__, __LINE__, __FUNCTION__); \
884 &(_decl)->decl.unit; }))
886 #define DECL_BYPASS(d) __extension__ \
887 (({ __typeof (d) const _decl = (d); \
888 if (_decl->mode != dm_bypass) \
889 decl_mode_check_failed (_decl->mode, "dm_bypass", \
890 __FILE__, __LINE__, __FUNCTION__); \
891 &(_decl)->decl.bypass; }))
893 #define DECL_AUTOMATON(d) __extension__ \
894 (({ __typeof (d) const _decl = (d); \
895 if (_decl->mode != dm_automaton) \
896 decl_mode_check_failed (_decl->mode, "dm_automaton", \
897 __FILE__, __LINE__, __FUNCTION__); \
898 &(_decl)->decl.automaton; }))
900 #define DECL_EXCL(d) __extension__ \
901 (({ __typeof (d) const _decl = (d); \
902 if (_decl->mode != dm_excl) \
903 decl_mode_check_failed (_decl->mode, "dm_excl", \
904 __FILE__, __LINE__, __FUNCTION__); \
905 &(_decl)->decl.excl; }))
907 #define DECL_PRESENCE(d) __extension__ \
908 (({ __typeof (d) const _decl = (d); \
909 if (_decl->mode != dm_presence) \
910 decl_mode_check_failed (_decl->mode, "dm_presence", \
911 __FILE__, __LINE__, __FUNCTION__); \
912 &(_decl)->decl.presence; }))
914 #define DECL_ABSENCE(d) __extension__ \
915 (({ __typeof (d) const _decl = (d); \
916 if (_decl->mode != dm_absence) \
917 decl_mode_check_failed (_decl->mode, "dm_absence", \
918 __FILE__, __LINE__, __FUNCTION__); \
919 &(_decl)->decl.absence; }))
921 #define DECL_RESERV(d) __extension__ \
922 (({ __typeof (d) const _decl = (d); \
923 if (_decl->mode != dm_reserv) \
924 decl_mode_check_failed (_decl->mode, "dm_reserv", \
925 __FILE__, __LINE__, __FUNCTION__); \
926 &(_decl)->decl.reserv; }))
928 #define DECL_INSN_RESERV(d) __extension__ \
929 (({ __typeof (d) const _decl = (d); \
930 if (_decl->mode != dm_insn_reserv) \
931 decl_mode_check_failed (_decl->mode, "dm_insn_reserv", \
932 __FILE__, __LINE__, __FUNCTION__); \
933 &(_decl)->decl.insn_reserv; }))
935 static const char *decl_name (enum decl_mode
);
936 static void decl_mode_check_failed (enum decl_mode
, const char *,
937 const char *, int, const char *)
940 /* Return string representation of declaration mode MODE. */
942 decl_name (enum decl_mode mode
)
944 static char str
[100];
948 else if (mode
== dm_bypass
)
950 else if (mode
== dm_automaton
)
951 return "dm_automaton";
952 else if (mode
== dm_excl
)
954 else if (mode
== dm_presence
)
955 return "dm_presence";
956 else if (mode
== dm_absence
)
958 else if (mode
== dm_reserv
)
960 else if (mode
== dm_insn_reserv
)
961 return "dm_insn_reserv";
963 sprintf (str
, "unknown (%d)", (int) mode
);
967 /* The function prints message about unexpected declaration and finish
970 decl_mode_check_failed (enum decl_mode mode
, const char *expected_mode_str
,
971 const char *file
, int line
, const char *func
)
975 "\n%s: %d: error in %s: DECL check: expected decl %s, have %s\n",
976 file
, line
, func
, expected_mode_str
, decl_name (mode
));
981 #define REGEXP_UNIT(r) __extension__ \
982 (({ struct regexp *const _regexp = (r); \
983 if (_regexp->mode != rm_unit) \
984 regexp_mode_check_failed (_regexp->mode, "rm_unit", \
985 __FILE__, __LINE__, __FUNCTION__); \
986 &(_regexp)->regexp.unit; }))
988 #define REGEXP_RESERV(r) __extension__ \
989 (({ struct regexp *const _regexp = (r); \
990 if (_regexp->mode != rm_reserv) \
991 regexp_mode_check_failed (_regexp->mode, "rm_reserv", \
992 __FILE__, __LINE__, __FUNCTION__); \
993 &(_regexp)->regexp.reserv; }))
995 #define REGEXP_SEQUENCE(r) __extension__ \
996 (({ struct regexp *const _regexp = (r); \
997 if (_regexp->mode != rm_sequence) \
998 regexp_mode_check_failed (_regexp->mode, "rm_sequence", \
999 __FILE__, __LINE__, __FUNCTION__); \
1000 &(_regexp)->regexp.sequence; }))
1002 #define REGEXP_REPEAT(r) __extension__ \
1003 (({ struct regexp *const _regexp = (r); \
1004 if (_regexp->mode != rm_repeat) \
1005 regexp_mode_check_failed (_regexp->mode, "rm_repeat", \
1006 __FILE__, __LINE__, __FUNCTION__); \
1007 &(_regexp)->regexp.repeat; }))
1009 #define REGEXP_ALLOF(r) __extension__ \
1010 (({ struct regexp *const _regexp = (r); \
1011 if (_regexp->mode != rm_allof) \
1012 regexp_mode_check_failed (_regexp->mode, "rm_allof", \
1013 __FILE__, __LINE__, __FUNCTION__); \
1014 &(_regexp)->regexp.allof; }))
1016 #define REGEXP_ONEOF(r) __extension__ \
1017 (({ struct regexp *const _regexp = (r); \
1018 if (_regexp->mode != rm_oneof) \
1019 regexp_mode_check_failed (_regexp->mode, "rm_oneof", \
1020 __FILE__, __LINE__, __FUNCTION__); \
1021 &(_regexp)->regexp.oneof; }))
1023 static const char *regexp_name (enum regexp_mode
);
1024 static void regexp_mode_check_failed (enum regexp_mode
, const char *,
1026 const char *) ATTRIBUTE_NORETURN
;
1029 /* Return string representation of regexp mode MODE. */
1031 regexp_name (enum regexp_mode mode
)
1040 return "rm_nothing";
1042 return "rm_sequence";
1054 /* The function prints message about unexpected regexp and finish the
1057 regexp_mode_check_failed (enum regexp_mode mode
,
1058 const char *expected_mode_str
,
1059 const char *file
, int line
, const char *func
)
1063 "\n%s: %d: error in %s: REGEXP check: expected decl %s, have %s\n",
1064 file
, line
, func
, expected_mode_str
, regexp_name (mode
));
1068 #else /* #if defined ENABLE_RTL_CHECKING && (GCC_VERSION >= 2007) */
1070 #define DECL_UNIT(d) (&(d)->decl.unit)
1071 #define DECL_BYPASS(d) (&(d)->decl.bypass)
1072 #define DECL_AUTOMATON(d) (&(d)->decl.automaton)
1073 #define DECL_EXCL(d) (&(d)->decl.excl)
1074 #define DECL_PRESENCE(d) (&(d)->decl.presence)
1075 #define DECL_ABSENCE(d) (&(d)->decl.absence)
1076 #define DECL_RESERV(d) (&(d)->decl.reserv)
1077 #define DECL_INSN_RESERV(d) (&(d)->decl.insn_reserv)
1079 #define REGEXP_UNIT(r) (&(r)->regexp.unit)
1080 #define REGEXP_RESERV(r) (&(r)->regexp.reserv)
1081 #define REGEXP_SEQUENCE(r) (&(r)->regexp.sequence)
1082 #define REGEXP_REPEAT(r) (&(r)->regexp.repeat)
1083 #define REGEXP_ALLOF(r) (&(r)->regexp.allof)
1084 #define REGEXP_ONEOF(r) (&(r)->regexp.oneof)
1086 #endif /* #if defined ENABLE_RTL_CHECKING && (GCC_VERSION >= 2007) */
1088 #define XCREATENODE(T) ((T *) create_node (sizeof (T)))
1089 #define XCREATENODEVEC(T, N) ((T *) create_node (sizeof (T) * (N)))
1090 #define XCREATENODEVAR(T, S) ((T *) create_node ((S)))
1092 #define XCOPYNODE(T, P) ((T *) copy_node ((P), sizeof (T)))
1093 #define XCOPYNODEVEC(T, P, N) ((T *) copy_node ((P), sizeof (T) * (N)))
1094 #define XCOPYNODEVAR(T, P, S) ((T *) copy_node ((P), (S)))
1096 /* Create IR structure (node). */
1098 create_node (size_t size
)
1102 obstack_blank (&irp
, size
);
1103 result
= obstack_base (&irp
);
1104 obstack_finish (&irp
);
1105 /* Default values of members are NULL and zero. */
1106 memset (result
, 0, size
);
1110 /* Copy IR structure (node). */
1112 copy_node (const void *from
, size_t size
)
1114 void *const result
= create_node (size
);
1115 memcpy (result
, from
, size
);
1119 /* The function checks that NAME does not contain quotes (`"'). */
1121 check_name (const char * name
, pos_t pos ATTRIBUTE_UNUSED
)
1125 for (str
= name
; *str
!= '\0'; str
++)
1127 error ("Name `%s' contains quotes", name
);
1131 /* Pointers to all declarations during IR generation are stored in the
1133 static VEC(decl_t
,heap
) *decls
;
1135 /* Given a pointer to a (char *) and a separator, return an alloc'ed
1136 string containing the next separated element, taking parentheses
1137 into account if PAR_FLAG has nonzero value. Advance the pointer to
1138 after the string scanned, or the end-of-string. Return NULL if at
1141 next_sep_el (const char **pstr
, int sep
, int par_flag
)
1148 /* Remove leading whitespaces. */
1149 while (ISSPACE ((int) **pstr
))
1156 for (pars_num
= 0, p
= *pstr
; *p
!= '\0'; p
++)
1158 if (par_flag
&& *p
== '(')
1160 else if (par_flag
&& *p
== ')')
1162 else if (pars_num
== 0 && *p
== sep
)
1164 if (pars_num
== 0 && ISSPACE ((int) *p
))
1168 for (; n_spaces
!= 0; n_spaces
--)
1169 obstack_1grow (&irp
, p
[-n_spaces
]);
1170 obstack_1grow (&irp
, *p
);
1173 obstack_1grow (&irp
, '\0');
1174 out_str
= obstack_base (&irp
);
1175 obstack_finish (&irp
);
1184 /* Given a string and a separator, return the number of separated
1185 elements in it, taking parentheses into account if PAR_FLAG has
1186 nonzero value. Return 0 for the null string, -1 if parentheses is
1189 n_sep_els (const char *s
, int sep
, int par_flag
)
1197 for (pars_num
= 0, n
= 1; *s
; s
++)
1198 if (par_flag
&& *s
== '(')
1200 else if (par_flag
&& *s
== ')')
1202 else if (pars_num
== 0 && *s
== sep
)
1205 return (pars_num
!= 0 ? -1 : n
);
1208 /* Given a string and a separator, return vector of strings which are
1209 elements in the string and number of elements through els_num.
1210 Take parentheses into account if PAREN_P has nonzero value. The
1211 function also inserts the end marker NULL at the end of vector.
1212 Return 0 for the null string, -1 if parentheses are not balanced. */
1214 get_str_vect (const char *str
, int *els_num
, int sep
, int paren_p
)
1221 *els_num
= n_sep_els (str
, sep
, paren_p
);
1224 obstack_blank (&irp
, sizeof (char *) * (*els_num
+ 1));
1225 vect
= (char **) obstack_base (&irp
);
1226 obstack_finish (&irp
);
1228 for (i
= 0; i
< *els_num
; i
++)
1229 vect
[i
] = next_sep_el (pstr
, sep
, paren_p
);
1230 trail
= next_sep_el (pstr
, sep
, paren_p
);
1231 gcc_assert (!trail
);
1236 /* Process a DEFINE_CPU_UNIT.
1238 This gives information about a unit contained in CPU. We fill a
1239 struct unit_decl with information used later by `expand_automata'. */
1241 gen_cpu_unit (rtx def
)
1244 char **str_cpu_units
;
1248 str_cpu_units
= get_str_vect (XSTR (def
, 0), &vect_length
, ',', FALSE
);
1249 if (str_cpu_units
== NULL
)
1250 fatal ("invalid string `%s' in define_cpu_unit", XSTR (def
, 0));
1251 for (i
= 0; i
< vect_length
; i
++)
1253 decl
= XCREATENODE (struct decl
);
1254 decl
->mode
= dm_unit
;
1256 DECL_UNIT (decl
)->name
= check_name (str_cpu_units
[i
], decl
->pos
);
1257 DECL_UNIT (decl
)->automaton_name
= XSTR (def
, 1);
1258 DECL_UNIT (decl
)->query_p
= 0;
1259 DECL_UNIT (decl
)->min_occ_cycle_num
= -1;
1260 DECL_UNIT (decl
)->in_set_p
= 0;
1261 VEC_safe_push (decl_t
,heap
, decls
, decl
);
1265 /* Process a DEFINE_QUERY_CPU_UNIT.
1267 This gives information about a unit contained in CPU. We fill a
1268 struct unit_decl with information used later by `expand_automata'. */
1270 gen_query_cpu_unit (rtx def
)
1273 char **str_cpu_units
;
1277 str_cpu_units
= get_str_vect (XSTR (def
, 0), &vect_length
, ',',
1279 if (str_cpu_units
== NULL
)
1280 fatal ("invalid string `%s' in define_query_cpu_unit", XSTR (def
, 0));
1281 for (i
= 0; i
< vect_length
; i
++)
1283 decl
= XCREATENODE (struct decl
);
1284 decl
->mode
= dm_unit
;
1286 DECL_UNIT (decl
)->name
= check_name (str_cpu_units
[i
], decl
->pos
);
1287 DECL_UNIT (decl
)->automaton_name
= XSTR (def
, 1);
1288 DECL_UNIT (decl
)->query_p
= 1;
1289 VEC_safe_push (decl_t
,heap
, decls
, decl
);
1293 /* Process a DEFINE_BYPASS.
1295 This gives information about a unit contained in the CPU. We fill
1296 in a struct bypass_decl with information used later by
1297 `expand_automata'. */
1299 gen_bypass (rtx def
)
1308 out_insns
= get_str_vect (XSTR (def
, 1), &out_length
, ',', FALSE
);
1309 if (out_insns
== NULL
)
1310 fatal ("invalid string `%s' in define_bypass", XSTR (def
, 1));
1311 in_insns
= get_str_vect (XSTR (def
, 2), &in_length
, ',', FALSE
);
1312 if (in_insns
== NULL
)
1313 fatal ("invalid string `%s' in define_bypass", XSTR (def
, 2));
1314 for (i
= 0; i
< out_length
; i
++)
1315 for (j
= 0; j
< in_length
; j
++)
1317 decl
= XCREATENODE (struct decl
);
1318 decl
->mode
= dm_bypass
;
1320 DECL_BYPASS (decl
)->latency
= XINT (def
, 0);
1321 DECL_BYPASS (decl
)->out_insn_name
= out_insns
[i
];
1322 DECL_BYPASS (decl
)->in_insn_name
= in_insns
[j
];
1323 DECL_BYPASS (decl
)->bypass_guard_name
= XSTR (def
, 3);
1324 VEC_safe_push (decl_t
,heap
, decls
, decl
);
1328 /* Process an EXCLUSION_SET.
1330 This gives information about a cpu unit conflicts. We fill a
1331 struct excl_rel_decl (excl) with information used later by
1332 `expand_automata'. */
1334 gen_excl_set (rtx def
)
1337 char **first_str_cpu_units
;
1338 char **second_str_cpu_units
;
1339 int first_vect_length
;
1344 = get_str_vect (XSTR (def
, 0), &first_vect_length
, ',', FALSE
);
1345 if (first_str_cpu_units
== NULL
)
1346 fatal ("invalid first string `%s' in exclusion_set", XSTR (def
, 0));
1347 second_str_cpu_units
= get_str_vect (XSTR (def
, 1), &length
, ',',
1349 if (second_str_cpu_units
== NULL
)
1350 fatal ("invalid second string `%s' in exclusion_set", XSTR (def
, 1));
1351 length
+= first_vect_length
;
1352 decl
= XCREATENODEVAR (struct decl
, sizeof (struct decl
) + (length
- 1) * sizeof (char *));
1353 decl
->mode
= dm_excl
;
1355 DECL_EXCL (decl
)->all_names_num
= length
;
1356 DECL_EXCL (decl
)->first_list_length
= first_vect_length
;
1357 for (i
= 0; i
< length
; i
++)
1358 if (i
< first_vect_length
)
1359 DECL_EXCL (decl
)->names
[i
] = first_str_cpu_units
[i
];
1361 DECL_EXCL (decl
)->names
[i
]
1362 = second_str_cpu_units
[i
- first_vect_length
];
1363 VEC_safe_push (decl_t
,heap
, decls
, decl
);
1366 /* Process a PRESENCE_SET, a FINAL_PRESENCE_SET, an ABSENCE_SET,
1367 FINAL_ABSENCE_SET (it is depended on PRESENCE_P and FINAL_P).
1369 This gives information about a cpu unit reservation requirements.
1370 We fill a struct unit_pattern_rel_decl with information used later
1371 by `expand_automata'. */
1373 gen_presence_absence_set (rtx def
, int presence_p
, int final_p
)
1376 char **str_cpu_units
;
1377 char **str_pattern_lists
;
1378 char ***str_patterns
;
1379 int cpu_units_length
;
1381 int patterns_length
;
1384 str_cpu_units
= get_str_vect (XSTR (def
, 0), &cpu_units_length
, ',',
1386 if (str_cpu_units
== NULL
)
1389 ? "invalid first string `%s' in final_presence_set"
1390 : "invalid first string `%s' in presence_set")
1392 ? "invalid first string `%s' in final_absence_set"
1393 : "invalid first string `%s' in absence_set")),
1395 str_pattern_lists
= get_str_vect (XSTR (def
, 1),
1396 &patterns_length
, ',', FALSE
);
1397 if (str_pattern_lists
== NULL
)
1400 ? "invalid second string `%s' in final_presence_set"
1401 : "invalid second string `%s' in presence_set")
1403 ? "invalid second string `%s' in final_absence_set"
1404 : "invalid second string `%s' in absence_set")), XSTR (def
, 1));
1405 str_patterns
= XOBNEWVEC (&irp
, char **, patterns_length
);
1406 for (i
= 0; i
< patterns_length
; i
++)
1408 str_patterns
[i
] = get_str_vect (str_pattern_lists
[i
],
1409 &length
, ' ', FALSE
);
1410 gcc_assert (str_patterns
[i
]);
1412 decl
= XCREATENODE (struct decl
);
1416 decl
->mode
= dm_presence
;
1417 DECL_PRESENCE (decl
)->names_num
= cpu_units_length
;
1418 DECL_PRESENCE (decl
)->names
= str_cpu_units
;
1419 DECL_PRESENCE (decl
)->patterns
= str_patterns
;
1420 DECL_PRESENCE (decl
)->patterns_num
= patterns_length
;
1421 DECL_PRESENCE (decl
)->final_p
= final_p
;
1425 decl
->mode
= dm_absence
;
1426 DECL_ABSENCE (decl
)->names_num
= cpu_units_length
;
1427 DECL_ABSENCE (decl
)->names
= str_cpu_units
;
1428 DECL_ABSENCE (decl
)->patterns
= str_patterns
;
1429 DECL_ABSENCE (decl
)->patterns_num
= patterns_length
;
1430 DECL_ABSENCE (decl
)->final_p
= final_p
;
1432 VEC_safe_push (decl_t
,heap
, decls
, decl
);
1435 /* Process a PRESENCE_SET.
1437 This gives information about a cpu unit reservation requirements.
1438 We fill a struct unit_pattern_rel_decl (presence) with information
1439 used later by `expand_automata'. */
1441 gen_presence_set (rtx def
)
1443 gen_presence_absence_set (def
, TRUE
, FALSE
);
1446 /* Process a FINAL_PRESENCE_SET.
1448 This gives information about a cpu unit reservation requirements.
1449 We fill a struct unit_pattern_rel_decl (presence) with information
1450 used later by `expand_automata'. */
1452 gen_final_presence_set (rtx def
)
1454 gen_presence_absence_set (def
, TRUE
, TRUE
);
1457 /* Process an ABSENCE_SET.
1459 This gives information about a cpu unit reservation requirements.
1460 We fill a struct unit_pattern_rel_decl (absence) with information
1461 used later by `expand_automata'. */
1463 gen_absence_set (rtx def
)
1465 gen_presence_absence_set (def
, FALSE
, FALSE
);
1468 /* Process a FINAL_ABSENCE_SET.
1470 This gives information about a cpu unit reservation requirements.
1471 We fill a struct unit_pattern_rel_decl (absence) with information
1472 used later by `expand_automata'. */
1474 gen_final_absence_set (rtx def
)
1476 gen_presence_absence_set (def
, FALSE
, TRUE
);
1479 /* Process a DEFINE_AUTOMATON.
1481 This gives information about a finite state automaton used for
1482 recognizing pipeline hazards. We fill a struct automaton_decl
1483 with information used later by `expand_automata'. */
1485 gen_automaton (rtx def
)
1488 char **str_automata
;
1492 str_automata
= get_str_vect (XSTR (def
, 0), &vect_length
, ',', FALSE
);
1493 if (str_automata
== NULL
)
1494 fatal ("invalid string `%s' in define_automaton", XSTR (def
, 0));
1495 for (i
= 0; i
< vect_length
; i
++)
1497 decl
= XCREATENODE (struct decl
);
1498 decl
->mode
= dm_automaton
;
1500 DECL_AUTOMATON (decl
)->name
= check_name (str_automata
[i
], decl
->pos
);
1501 VEC_safe_push (decl_t
,heap
, decls
, decl
);
1505 /* Process an AUTOMATA_OPTION.
1507 This gives information how to generate finite state automaton used
1508 for recognizing pipeline hazards. */
1510 gen_automata_option (rtx def
)
1512 if (strcmp (XSTR (def
, 0), NO_MINIMIZATION_OPTION
+ 1) == 0)
1513 no_minimization_flag
= 1;
1514 else if (strcmp (XSTR (def
, 0), TIME_OPTION
+ 1) == 0)
1516 else if (strcmp (XSTR (def
, 0), STATS_OPTION
+ 1) == 0)
1518 else if (strcmp (XSTR (def
, 0), V_OPTION
+ 1) == 0)
1520 else if (strcmp (XSTR (def
, 0), W_OPTION
+ 1) == 0)
1522 else if (strcmp (XSTR (def
, 0), NDFA_OPTION
+ 1) == 0)
1524 else if (strcmp (XSTR (def
, 0), PROGRESS_OPTION
+ 1) == 0)
1527 fatal ("invalid option `%s' in automata_option", XSTR (def
, 0));
1530 /* Name in reservation to denote absence reservation. */
1531 #define NOTHING_NAME "nothing"
1533 /* The following string contains original reservation string being
1535 static const char *reserv_str
;
1537 /* Parse an element in STR. */
1539 gen_regexp_el (const char *str
)
1548 if (str
[len
- 1] != ')')
1549 fatal ("garbage after ) in reservation `%s'", reserv_str
);
1550 dstr
= XALLOCAVAR (char, len
- 1);
1551 memcpy (dstr
, str
+ 1, len
- 2);
1552 dstr
[len
-2] = '\0';
1553 regexp
= gen_regexp_sequence (dstr
);
1555 else if (strcmp (str
, NOTHING_NAME
) == 0)
1557 regexp
= XCREATENODE (struct regexp
);
1558 regexp
->mode
= rm_nothing
;
1562 regexp
= XCREATENODE (struct regexp
);
1563 regexp
->mode
= rm_unit
;
1564 REGEXP_UNIT (regexp
)->name
= str
;
1569 /* Parse construction `repeat' in STR. */
1571 gen_regexp_repeat (const char *str
)
1579 repeat_vect
= get_str_vect (str
, &els_num
, '*', TRUE
);
1580 if (repeat_vect
== NULL
)
1581 fatal ("invalid `%s' in reservation `%s'", str
, reserv_str
);
1584 regexp
= gen_regexp_el (repeat_vect
[0]);
1585 for (i
= 1; i
< els_num
; i
++)
1587 repeat
= XCREATENODE (struct regexp
);
1588 repeat
->mode
= rm_repeat
;
1589 REGEXP_REPEAT (repeat
)->regexp
= regexp
;
1590 REGEXP_REPEAT (repeat
)->repeat_num
= atoi (repeat_vect
[i
]);
1591 if (REGEXP_REPEAT (repeat
)->repeat_num
<= 1)
1592 fatal ("repetition `%s' <= 1 in reservation `%s'",
1599 return gen_regexp_el (str
);
1602 /* Parse reservation STR which possibly contains separator '+'. */
1604 gen_regexp_allof (const char *str
)
1611 allof_vect
= get_str_vect (str
, &els_num
, '+', TRUE
);
1612 if (allof_vect
== NULL
)
1613 fatal ("invalid `%s' in reservation `%s'", str
, reserv_str
);
1616 allof
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
1617 + sizeof (regexp_t
) * (els_num
- 1));
1618 allof
->mode
= rm_allof
;
1619 REGEXP_ALLOF (allof
)->regexps_num
= els_num
;
1620 for (i
= 0; i
< els_num
; i
++)
1621 REGEXP_ALLOF (allof
)->regexps
[i
] = gen_regexp_repeat (allof_vect
[i
]);
1625 return gen_regexp_repeat (str
);
1628 /* Parse reservation STR which possibly contains separator '|'. */
1630 gen_regexp_oneof (const char *str
)
1637 oneof_vect
= get_str_vect (str
, &els_num
, '|', TRUE
);
1638 if (oneof_vect
== NULL
)
1639 fatal ("invalid `%s' in reservation `%s'", str
, reserv_str
);
1642 oneof
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
1643 + sizeof (regexp_t
) * (els_num
- 1));
1644 oneof
->mode
= rm_oneof
;
1645 REGEXP_ONEOF (oneof
)->regexps_num
= els_num
;
1646 for (i
= 0; i
< els_num
; i
++)
1647 REGEXP_ONEOF (oneof
)->regexps
[i
] = gen_regexp_allof (oneof_vect
[i
]);
1651 return gen_regexp_allof (str
);
1654 /* Parse reservation STR which possibly contains separator ','. */
1656 gen_regexp_sequence (const char *str
)
1659 char **sequence_vect
;
1663 sequence_vect
= get_str_vect (str
, &els_num
, ',', TRUE
);
1666 sequence
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
1667 + sizeof (regexp_t
) * (els_num
- 1));
1668 sequence
->mode
= rm_sequence
;
1669 REGEXP_SEQUENCE (sequence
)->regexps_num
= els_num
;
1670 for (i
= 0; i
< els_num
; i
++)
1671 REGEXP_SEQUENCE (sequence
)->regexps
[i
]
1672 = gen_regexp_oneof (sequence_vect
[i
]);
1676 return gen_regexp_oneof (str
);
1679 /* Parse construction reservation STR. */
1681 gen_regexp (const char *str
)
1684 return gen_regexp_sequence (str
);;
1687 /* Process a DEFINE_RESERVATION.
1689 This gives information about a reservation of cpu units. We fill
1690 in a struct reserv_decl with information used later by
1691 `expand_automata'. */
1693 gen_reserv (rtx def
)
1697 decl
= XCREATENODE (struct decl
);
1698 decl
->mode
= dm_reserv
;
1700 DECL_RESERV (decl
)->name
= check_name (XSTR (def
, 0), decl
->pos
);
1701 DECL_RESERV (decl
)->regexp
= gen_regexp (XSTR (def
, 1));
1702 VEC_safe_push (decl_t
,heap
, decls
, decl
);
1705 /* Process a DEFINE_INSN_RESERVATION.
1707 This gives information about the reservation of cpu units by an
1708 insn. We fill a struct insn_reserv_decl with information used
1709 later by `expand_automata'. */
1711 gen_insn_reserv (rtx def
)
1715 decl
= XCREATENODE (struct decl
);
1716 decl
->mode
= dm_insn_reserv
;
1718 DECL_INSN_RESERV (decl
)->name
1719 = check_name (XSTR (def
, 0), decl
->pos
);
1720 DECL_INSN_RESERV (decl
)->default_latency
= XINT (def
, 1);
1721 DECL_INSN_RESERV (decl
)->condexp
= XEXP (def
, 2);
1722 DECL_INSN_RESERV (decl
)->regexp
= gen_regexp (XSTR (def
, 3));
1723 VEC_safe_push (decl_t
,heap
, decls
, decl
);
1728 /* The function evaluates hash value (0..UINT_MAX) of string. */
1730 string_hash (const char *string
)
1734 for (result
= i
= 0;*string
++ != '\0'; i
++)
1735 result
+= ((unsigned char) *string
<< (i
% CHAR_BIT
));
1741 /* This page contains abstract data `table of automaton declarations'.
1742 Elements of the table is nodes representing automaton declarations.
1743 Key of the table elements is name of given automaton. Remember
1744 that automaton names have own space. */
1746 /* The function evaluates hash value of an automaton declaration. The
1747 function is used by abstract data `hashtab'. The function returns
1748 hash value (0..UINT_MAX) of given automaton declaration. */
1750 automaton_decl_hash (const void *automaton_decl
)
1752 const_decl_t
const decl
= (const_decl_t
) automaton_decl
;
1754 gcc_assert (decl
->mode
!= dm_automaton
1755 || DECL_AUTOMATON (decl
)->name
);
1756 return string_hash (DECL_AUTOMATON (decl
)->name
);
1759 /* The function tests automaton declarations on equality of their
1760 keys. The function is used by abstract data `hashtab'. The
1761 function returns 1 if the declarations have the same key, 0
1764 automaton_decl_eq_p (const void* automaton_decl_1
,
1765 const void* automaton_decl_2
)
1767 const_decl_t
const decl1
= (const_decl_t
) automaton_decl_1
;
1768 const_decl_t
const decl2
= (const_decl_t
) automaton_decl_2
;
1770 gcc_assert (decl1
->mode
== dm_automaton
1771 && DECL_AUTOMATON (decl1
)->name
1772 && decl2
->mode
== dm_automaton
1773 && DECL_AUTOMATON (decl2
)->name
);
1774 return strcmp (DECL_AUTOMATON (decl1
)->name
,
1775 DECL_AUTOMATON (decl2
)->name
) == 0;
1778 /* The automaton declaration table itself is represented by the
1779 following variable. */
1780 static htab_t automaton_decl_table
;
1782 /* The function inserts automaton declaration into the table. The
1783 function does nothing if an automaton declaration with the same key
1784 exists already in the table. The function returns automaton
1785 declaration node in the table with the same key as given automaton
1786 declaration node. */
1788 insert_automaton_decl (decl_t automaton_decl
)
1792 entry_ptr
= htab_find_slot (automaton_decl_table
, automaton_decl
, 1);
1793 if (*entry_ptr
== NULL
)
1794 *entry_ptr
= (void *) automaton_decl
;
1795 return (decl_t
) *entry_ptr
;
1798 /* The following variable value is node representing automaton
1799 declaration. The node used for searching automaton declaration
1801 static struct decl work_automaton_decl
;
1803 /* The function searches for automaton declaration in the table with
1804 the same key as node representing name of the automaton
1805 declaration. The function returns node found in the table, NULL if
1806 such node does not exist in the table. */
1808 find_automaton_decl (const char *name
)
1812 work_automaton_decl
.mode
= dm_automaton
;
1813 DECL_AUTOMATON (&work_automaton_decl
)->name
= name
;
1814 entry
= htab_find (automaton_decl_table
, &work_automaton_decl
);
1815 return (decl_t
) entry
;
1818 /* The function creates empty automaton declaration table and node
1819 representing automaton declaration and used for searching automaton
1820 declaration with given name. The function must be called only once
1821 before any work with the automaton declaration table. */
1823 initiate_automaton_decl_table (void)
1825 work_automaton_decl
.mode
= dm_automaton
;
1826 automaton_decl_table
= htab_create (10, automaton_decl_hash
,
1827 automaton_decl_eq_p
, (htab_del
) 0);
1830 /* The function deletes the automaton declaration table. Only call of
1831 function `initiate_automaton_decl_table' is possible immediately
1832 after this function call. */
1834 finish_automaton_decl_table (void)
1836 htab_delete (automaton_decl_table
);
1841 /* This page contains abstract data `table of insn declarations'.
1842 Elements of the table is nodes representing insn declarations. Key
1843 of the table elements is name of given insn (in corresponding
1844 define_insn_reservation). Remember that insn names have own
1847 /* The function evaluates hash value of an insn declaration. The
1848 function is used by abstract data `hashtab'. The function returns
1849 hash value (0..UINT_MAX) of given insn declaration. */
1851 insn_decl_hash (const void *insn_decl
)
1853 const_decl_t
const decl
= (const_decl_t
) insn_decl
;
1855 gcc_assert (decl
->mode
== dm_insn_reserv
1856 && DECL_INSN_RESERV (decl
)->name
);
1857 return string_hash (DECL_INSN_RESERV (decl
)->name
);
1860 /* The function tests insn declarations on equality of their keys.
1861 The function is used by abstract data `hashtab'. The function
1862 returns 1 if declarations have the same key, 0 otherwise. */
1864 insn_decl_eq_p (const void *insn_decl_1
, const void *insn_decl_2
)
1866 const_decl_t
const decl1
= (const_decl_t
) insn_decl_1
;
1867 const_decl_t
const decl2
= (const_decl_t
) insn_decl_2
;
1869 gcc_assert (decl1
->mode
== dm_insn_reserv
1870 && DECL_INSN_RESERV (decl1
)->name
1871 && decl2
->mode
== dm_insn_reserv
1872 && DECL_INSN_RESERV (decl2
)->name
);
1873 return strcmp (DECL_INSN_RESERV (decl1
)->name
,
1874 DECL_INSN_RESERV (decl2
)->name
) == 0;
1877 /* The insn declaration table itself is represented by the following
1878 variable. The table does not contain insn reservation
1880 static htab_t insn_decl_table
;
1882 /* The function inserts insn declaration into the table. The function
1883 does nothing if an insn declaration with the same key exists
1884 already in the table. The function returns insn declaration node
1885 in the table with the same key as given insn declaration node. */
1887 insert_insn_decl (decl_t insn_decl
)
1891 entry_ptr
= htab_find_slot (insn_decl_table
, insn_decl
, 1);
1892 if (*entry_ptr
== NULL
)
1893 *entry_ptr
= (void *) insn_decl
;
1894 return (decl_t
) *entry_ptr
;
1897 /* The following variable value is node representing insn reservation
1898 declaration. The node used for searching insn reservation
1899 declaration with given name. */
1900 static struct decl work_insn_decl
;
1902 /* The function searches for insn reservation declaration in the table
1903 with the same key as node representing name of the insn reservation
1904 declaration. The function returns node found in the table, NULL if
1905 such node does not exist in the table. */
1907 find_insn_decl (const char *name
)
1911 work_insn_decl
.mode
= dm_insn_reserv
;
1912 DECL_INSN_RESERV (&work_insn_decl
)->name
= name
;
1913 entry
= htab_find (insn_decl_table
, &work_insn_decl
);
1914 return (decl_t
) entry
;
1917 /* The function creates empty insn declaration table and node
1918 representing insn declaration and used for searching insn
1919 declaration with given name. The function must be called only once
1920 before any work with the insn declaration table. */
1922 initiate_insn_decl_table (void)
1924 work_insn_decl
.mode
= dm_insn_reserv
;
1925 insn_decl_table
= htab_create (10, insn_decl_hash
, insn_decl_eq_p
,
1929 /* The function deletes the insn declaration table. Only call of
1930 function `initiate_insn_decl_table' is possible immediately after
1931 this function call. */
1933 finish_insn_decl_table (void)
1935 htab_delete (insn_decl_table
);
1940 /* This page contains abstract data `table of declarations'. Elements
1941 of the table is nodes representing declarations (of units and
1942 reservations). Key of the table elements is names of given
1945 /* The function evaluates hash value of a declaration. The function
1946 is used by abstract data `hashtab'. The function returns hash
1947 value (0..UINT_MAX) of given declaration. */
1949 decl_hash (const void *decl
)
1951 const_decl_t
const d
= (const_decl_t
) decl
;
1953 gcc_assert ((d
->mode
== dm_unit
&& DECL_UNIT (d
)->name
)
1954 || (d
->mode
== dm_reserv
&& DECL_RESERV (d
)->name
));
1955 return string_hash (d
->mode
== dm_unit
1956 ? DECL_UNIT (d
)->name
: DECL_RESERV (d
)->name
);
1959 /* The function tests declarations on equality of their keys. The
1960 function is used by abstract data 'hashtab'. The function
1961 returns 1 if the declarations have the same key, 0 otherwise. */
1963 decl_eq_p (const void *decl_1
, const void *decl_2
)
1965 const_decl_t
const d1
= (const_decl_t
) decl_1
;
1966 const_decl_t
const d2
= (const_decl_t
) decl_2
;
1968 gcc_assert ((d1
->mode
== dm_unit
&& DECL_UNIT (d1
)->name
)
1969 || (d1
->mode
== dm_reserv
&& DECL_RESERV (d1
)->name
));
1970 gcc_assert ((d2
->mode
== dm_unit
&& DECL_UNIT (d2
)->name
)
1971 || (d2
->mode
== dm_reserv
&& DECL_RESERV (d2
)->name
));
1972 return strcmp ((d1
->mode
== dm_unit
1973 ? DECL_UNIT (d1
)->name
: DECL_RESERV (d1
)->name
),
1974 (d2
->mode
== dm_unit
1975 ? DECL_UNIT (d2
)->name
: DECL_RESERV (d2
)->name
)) == 0;
1978 /* The declaration table itself is represented by the following
1980 static htab_t decl_table
;
1982 /* The function inserts declaration into the table. The function does
1983 nothing if a declaration with the same key exists already in the
1984 table. The function returns declaration node in the table with the
1985 same key as given declaration node. */
1988 insert_decl (decl_t decl
)
1992 entry_ptr
= htab_find_slot (decl_table
, decl
, 1);
1993 if (*entry_ptr
== NULL
)
1994 *entry_ptr
= (void *) decl
;
1995 return (decl_t
) *entry_ptr
;
1998 /* The following variable value is node representing declaration. The
1999 node used for searching declaration with given name. */
2000 static struct decl work_decl
;
2002 /* The function searches for declaration in the table with the same
2003 key as node representing name of the declaration. The function
2004 returns node found in the table, NULL if such node does not exist
2007 find_decl (const char *name
)
2011 work_decl
.mode
= dm_unit
;
2012 DECL_UNIT (&work_decl
)->name
= name
;
2013 entry
= htab_find (decl_table
, &work_decl
);
2014 return (decl_t
) entry
;
2017 /* The function creates empty declaration table and node representing
2018 declaration and used for searching declaration with given name.
2019 The function must be called only once before any work with the
2020 declaration table. */
2022 initiate_decl_table (void)
2024 work_decl
.mode
= dm_unit
;
2025 decl_table
= htab_create (10, decl_hash
, decl_eq_p
, (htab_del
) 0);
2028 /* The function deletes the declaration table. Only call of function
2029 `initiate_declaration_table' is possible immediately after this
2032 finish_decl_table (void)
2034 htab_delete (decl_table
);
2039 /* This page contains checker of pipeline hazard description. */
2041 /* Checking NAMES in an exclusion clause vector and returning formed
2042 unit_set_el_list. */
2043 static unit_set_el_t
2044 process_excls (char **names
, int num
, pos_t excl_pos ATTRIBUTE_UNUSED
)
2046 unit_set_el_t el_list
;
2047 unit_set_el_t last_el
;
2048 unit_set_el_t new_el
;
2049 decl_t decl_in_table
;
2054 for (i
= 0; i
< num
; i
++)
2056 decl_in_table
= find_decl (names
[i
]);
2057 if (decl_in_table
== NULL
)
2058 error ("unit `%s' in exclusion is not declared", names
[i
]);
2059 else if (decl_in_table
->mode
!= dm_unit
)
2060 error ("`%s' in exclusion is not unit", names
[i
]);
2063 new_el
= XCREATENODE (struct unit_set_el
);
2064 new_el
->unit_decl
= DECL_UNIT (decl_in_table
);
2065 new_el
->next_unit_set_el
= NULL
;
2066 if (last_el
== NULL
)
2067 el_list
= last_el
= new_el
;
2070 last_el
->next_unit_set_el
= new_el
;
2071 last_el
= last_el
->next_unit_set_el
;
2078 /* The function adds each element from SOURCE_LIST to the exclusion
2079 list of the each element from DEST_LIST. Checking situation "unit
2080 excludes itself". */
2082 add_excls (unit_set_el_t dest_list
, unit_set_el_t source_list
,
2083 pos_t excl_pos ATTRIBUTE_UNUSED
)
2087 unit_set_el_t curr_el
;
2088 unit_set_el_t prev_el
;
2091 for (dst
= dest_list
; dst
!= NULL
; dst
= dst
->next_unit_set_el
)
2092 for (src
= source_list
; src
!= NULL
; src
= src
->next_unit_set_el
)
2094 if (dst
->unit_decl
== src
->unit_decl
)
2096 error ("unit `%s' excludes itself", src
->unit_decl
->name
);
2099 if (dst
->unit_decl
->automaton_name
!= NULL
2100 && src
->unit_decl
->automaton_name
!= NULL
2101 && strcmp (dst
->unit_decl
->automaton_name
,
2102 src
->unit_decl
->automaton_name
) != 0)
2104 error ("units `%s' and `%s' in exclusion set belong to different automata",
2105 src
->unit_decl
->name
, dst
->unit_decl
->name
);
2108 for (curr_el
= dst
->unit_decl
->excl_list
, prev_el
= NULL
;
2110 prev_el
= curr_el
, curr_el
= curr_el
->next_unit_set_el
)
2111 if (curr_el
->unit_decl
== src
->unit_decl
)
2113 if (curr_el
== NULL
)
2115 /* Element not found - insert. */
2116 copy
= XCOPYNODE (struct unit_set_el
, src
);
2117 copy
->next_unit_set_el
= NULL
;
2118 if (prev_el
== NULL
)
2119 dst
->unit_decl
->excl_list
= copy
;
2121 prev_el
->next_unit_set_el
= copy
;
2126 /* Checking NAMES in presence/absence clause and returning the
2127 formed unit_set_el_list. The function is called only after
2128 processing all exclusion sets. */
2129 static unit_set_el_t
2130 process_presence_absence_names (char **names
, int num
,
2131 pos_t req_pos ATTRIBUTE_UNUSED
,
2132 int presence_p
, int final_p
)
2134 unit_set_el_t el_list
;
2135 unit_set_el_t last_el
;
2136 unit_set_el_t new_el
;
2137 decl_t decl_in_table
;
2142 for (i
= 0; i
< num
; i
++)
2144 decl_in_table
= find_decl (names
[i
]);
2145 if (decl_in_table
== NULL
)
2148 ? "unit `%s' in final presence set is not declared"
2149 : "unit `%s' in presence set is not declared")
2151 ? "unit `%s' in final absence set is not declared"
2152 : "unit `%s' in absence set is not declared")), names
[i
]);
2153 else if (decl_in_table
->mode
!= dm_unit
)
2156 ? "`%s' in final presence set is not unit"
2157 : "`%s' in presence set is not unit")
2159 ? "`%s' in final absence set is not unit"
2160 : "`%s' in absence set is not unit")), names
[i
]);
2163 new_el
= XCREATENODE (struct unit_set_el
);
2164 new_el
->unit_decl
= DECL_UNIT (decl_in_table
);
2165 new_el
->next_unit_set_el
= NULL
;
2166 if (last_el
== NULL
)
2167 el_list
= last_el
= new_el
;
2170 last_el
->next_unit_set_el
= new_el
;
2171 last_el
= last_el
->next_unit_set_el
;
2178 /* Checking NAMES in patterns of a presence/absence clause and
2179 returning the formed pattern_set_el_list. The function is called
2180 only after processing all exclusion sets. */
2181 static pattern_set_el_t
2182 process_presence_absence_patterns (char ***patterns
, int num
,
2183 pos_t req_pos ATTRIBUTE_UNUSED
,
2184 int presence_p
, int final_p
)
2186 pattern_set_el_t el_list
;
2187 pattern_set_el_t last_el
;
2188 pattern_set_el_t new_el
;
2189 decl_t decl_in_table
;
2194 for (i
= 0; i
< num
; i
++)
2196 for (j
= 0; patterns
[i
] [j
] != NULL
; j
++)
2198 new_el
= XCREATENODEVAR (struct pattern_set_el
,
2199 sizeof (struct pattern_set_el
)
2200 + sizeof (struct unit_decl
*) * j
);
2202 = (struct unit_decl
**) ((char *) new_el
2203 + sizeof (struct pattern_set_el
));
2204 new_el
->next_pattern_set_el
= NULL
;
2205 if (last_el
== NULL
)
2206 el_list
= last_el
= new_el
;
2209 last_el
->next_pattern_set_el
= new_el
;
2210 last_el
= last_el
->next_pattern_set_el
;
2212 new_el
->units_num
= 0;
2213 for (j
= 0; patterns
[i
] [j
] != NULL
; j
++)
2215 decl_in_table
= find_decl (patterns
[i
] [j
]);
2216 if (decl_in_table
== NULL
)
2219 ? "unit `%s' in final presence set is not declared"
2220 : "unit `%s' in presence set is not declared")
2222 ? "unit `%s' in final absence set is not declared"
2223 : "unit `%s' in absence set is not declared")),
2225 else if (decl_in_table
->mode
!= dm_unit
)
2228 ? "`%s' in final presence set is not unit"
2229 : "`%s' in presence set is not unit")
2231 ? "`%s' in final absence set is not unit"
2232 : "`%s' in absence set is not unit")),
2236 new_el
->unit_decls
[new_el
->units_num
]
2237 = DECL_UNIT (decl_in_table
);
2238 new_el
->units_num
++;
2245 /* The function adds each element from PATTERN_LIST to presence (if
2246 PRESENCE_P) or absence list of the each element from DEST_LIST.
2247 Checking situations "unit requires own absence", and "unit excludes
2248 and requires presence of ...", "unit requires absence and presence
2249 of ...", "units in (final) presence set belong to different
2250 automata", and "units in (final) absence set belong to different
2251 automata". Remember that we process absence sets only after all
2254 add_presence_absence (unit_set_el_t dest_list
,
2255 pattern_set_el_t pattern_list
,
2256 pos_t req_pos ATTRIBUTE_UNUSED
,
2257 int presence_p
, int final_p
)
2260 pattern_set_el_t pat
;
2261 struct unit_decl
*unit
;
2262 unit_set_el_t curr_excl_el
;
2263 pattern_set_el_t curr_pat_el
;
2264 pattern_set_el_t prev_el
;
2265 pattern_set_el_t copy
;
2269 for (dst
= dest_list
; dst
!= NULL
; dst
= dst
->next_unit_set_el
)
2270 for (pat
= pattern_list
; pat
!= NULL
; pat
= pat
->next_pattern_set_el
)
2272 for (i
= 0; i
< pat
->units_num
; i
++)
2274 unit
= pat
->unit_decls
[i
];
2275 if (dst
->unit_decl
== unit
&& pat
->units_num
== 1 && !presence_p
)
2277 error ("unit `%s' requires own absence", unit
->name
);
2280 if (dst
->unit_decl
->automaton_name
!= NULL
2281 && unit
->automaton_name
!= NULL
2282 && strcmp (dst
->unit_decl
->automaton_name
,
2283 unit
->automaton_name
) != 0)
2287 ? "units `%s' and `%s' in final presence set belong to different automata"
2288 : "units `%s' and `%s' in presence set belong to different automata")
2290 ? "units `%s' and `%s' in final absence set belong to different automata"
2291 : "units `%s' and `%s' in absence set belong to different automata")),
2292 unit
->name
, dst
->unit_decl
->name
);
2297 for (curr_excl_el
= dst
->unit_decl
->excl_list
;
2298 curr_excl_el
!= NULL
;
2299 curr_excl_el
= curr_excl_el
->next_unit_set_el
)
2301 if (unit
== curr_excl_el
->unit_decl
&& pat
->units_num
== 1)
2305 error ("unit `%s' excludes and requires presence of `%s'",
2306 dst
->unit_decl
->name
, unit
->name
);
2311 (0, "unit `%s' excludes and requires presence of `%s'",
2312 dst
->unit_decl
->name
, unit
->name
);
2315 else if (pat
->units_num
== 1)
2316 for (curr_pat_el
= dst
->unit_decl
->presence_list
;
2317 curr_pat_el
!= NULL
;
2318 curr_pat_el
= curr_pat_el
->next_pattern_set_el
)
2319 if (curr_pat_el
->units_num
== 1
2320 && unit
== curr_pat_el
->unit_decls
[0])
2325 ("unit `%s' requires absence and presence of `%s'",
2326 dst
->unit_decl
->name
, unit
->name
);
2331 (0, "unit `%s' requires absence and presence of `%s'",
2332 dst
->unit_decl
->name
, unit
->name
);
2336 for (prev_el
= (presence_p
2338 ? dst
->unit_decl
->final_presence_list
2339 : dst
->unit_decl
->final_presence_list
)
2341 ? dst
->unit_decl
->final_absence_list
2342 : dst
->unit_decl
->absence_list
));
2343 prev_el
!= NULL
&& prev_el
->next_pattern_set_el
!= NULL
;
2344 prev_el
= prev_el
->next_pattern_set_el
)
2346 copy
= XCOPYNODE (struct pattern_set_el
, pat
);
2347 copy
->next_pattern_set_el
= NULL
;
2348 if (prev_el
== NULL
)
2353 dst
->unit_decl
->final_presence_list
= copy
;
2355 dst
->unit_decl
->presence_list
= copy
;
2358 dst
->unit_decl
->final_absence_list
= copy
;
2360 dst
->unit_decl
->absence_list
= copy
;
2363 prev_el
->next_pattern_set_el
= copy
;
2370 /* The function searches for bypass with given IN_INSN_RESERV in given
2372 static struct bypass_decl
*
2373 find_bypass (struct bypass_decl
*bypass_list
,
2374 struct insn_reserv_decl
*in_insn_reserv
)
2376 struct bypass_decl
*bypass
;
2378 for (bypass
= bypass_list
; bypass
!= NULL
; bypass
= bypass
->next
)
2379 if (bypass
->in_insn_reserv
== in_insn_reserv
)
2384 /* The function processes pipeline description declarations, checks
2385 their correctness, and forms exclusion/presence/absence sets. */
2387 process_decls (void)
2390 decl_t automaton_decl
;
2391 decl_t decl_in_table
;
2392 decl_t out_insn_reserv
;
2393 decl_t in_insn_reserv
;
2394 struct bypass_decl
*bypass
;
2395 int automaton_presence
;
2398 /* Checking repeated automata declarations. */
2399 automaton_presence
= 0;
2400 for (i
= 0; i
< description
->decls_num
; i
++)
2402 decl
= description
->decls
[i
];
2403 if (decl
->mode
== dm_automaton
)
2405 automaton_presence
= 1;
2406 decl_in_table
= insert_automaton_decl (decl
);
2407 if (decl_in_table
!= decl
)
2410 error ("repeated declaration of automaton `%s'",
2411 DECL_AUTOMATON (decl
)->name
);
2413 warning (0, "repeated declaration of automaton `%s'",
2414 DECL_AUTOMATON (decl
)->name
);
2418 /* Checking undeclared automata, repeated declarations (except for
2419 automata) and correctness of their attributes (insn latency times
2421 for (i
= 0; i
< description
->decls_num
; i
++)
2423 decl
= description
->decls
[i
];
2424 if (decl
->mode
== dm_insn_reserv
)
2426 if (DECL_INSN_RESERV (decl
)->default_latency
< 0)
2427 error ("define_insn_reservation `%s' has negative latency time",
2428 DECL_INSN_RESERV (decl
)->name
);
2429 DECL_INSN_RESERV (decl
)->insn_num
= description
->insns_num
;
2430 description
->insns_num
++;
2431 decl_in_table
= insert_insn_decl (decl
);
2432 if (decl_in_table
!= decl
)
2433 error ("`%s' is already used as insn reservation name",
2434 DECL_INSN_RESERV (decl
)->name
);
2436 else if (decl
->mode
== dm_bypass
)
2438 if (DECL_BYPASS (decl
)->latency
< 0)
2439 error ("define_bypass `%s - %s' has negative latency time",
2440 DECL_BYPASS (decl
)->out_insn_name
,
2441 DECL_BYPASS (decl
)->in_insn_name
);
2443 else if (decl
->mode
== dm_unit
|| decl
->mode
== dm_reserv
)
2445 if (decl
->mode
== dm_unit
)
2447 DECL_UNIT (decl
)->automaton_decl
= NULL
;
2448 if (DECL_UNIT (decl
)->automaton_name
!= NULL
)
2451 = find_automaton_decl (DECL_UNIT (decl
)->automaton_name
);
2452 if (automaton_decl
== NULL
)
2453 error ("automaton `%s' is not declared",
2454 DECL_UNIT (decl
)->automaton_name
);
2457 DECL_AUTOMATON (automaton_decl
)->automaton_is_used
= 1;
2458 DECL_UNIT (decl
)->automaton_decl
2459 = DECL_AUTOMATON (automaton_decl
);
2462 else if (automaton_presence
)
2463 error ("define_unit `%s' without automaton when one defined",
2464 DECL_UNIT (decl
)->name
);
2465 DECL_UNIT (decl
)->unit_num
= description
->units_num
;
2466 description
->units_num
++;
2467 if (strcmp (DECL_UNIT (decl
)->name
, NOTHING_NAME
) == 0)
2469 error ("`%s' is declared as cpu unit", NOTHING_NAME
);
2472 decl_in_table
= find_decl (DECL_UNIT (decl
)->name
);
2476 if (strcmp (DECL_RESERV (decl
)->name
, NOTHING_NAME
) == 0)
2478 error ("`%s' is declared as cpu reservation", NOTHING_NAME
);
2481 decl_in_table
= find_decl (DECL_RESERV (decl
)->name
);
2483 if (decl_in_table
== NULL
)
2484 decl_in_table
= insert_decl (decl
);
2487 if (decl
->mode
== dm_unit
)
2488 error ("repeated declaration of unit `%s'",
2489 DECL_UNIT (decl
)->name
);
2491 error ("repeated declaration of reservation `%s'",
2492 DECL_RESERV (decl
)->name
);
2496 /* Check bypasses and form list of bypasses for each (output)
2498 for (i
= 0; i
< description
->decls_num
; i
++)
2500 decl
= description
->decls
[i
];
2501 if (decl
->mode
== dm_bypass
)
2503 out_insn_reserv
= find_insn_decl (DECL_BYPASS (decl
)->out_insn_name
);
2504 in_insn_reserv
= find_insn_decl (DECL_BYPASS (decl
)->in_insn_name
);
2505 if (out_insn_reserv
== NULL
)
2506 error ("there is no insn reservation `%s'",
2507 DECL_BYPASS (decl
)->out_insn_name
);
2508 else if (in_insn_reserv
== NULL
)
2509 error ("there is no insn reservation `%s'",
2510 DECL_BYPASS (decl
)->in_insn_name
);
2513 DECL_BYPASS (decl
)->out_insn_reserv
2514 = DECL_INSN_RESERV (out_insn_reserv
);
2515 DECL_BYPASS (decl
)->in_insn_reserv
2516 = DECL_INSN_RESERV (in_insn_reserv
);
2518 = find_bypass (DECL_INSN_RESERV (out_insn_reserv
)->bypass_list
,
2519 DECL_BYPASS (decl
)->in_insn_reserv
);
2522 if (DECL_BYPASS (decl
)->latency
== bypass
->latency
)
2526 ("the same bypass `%s - %s' is already defined",
2527 DECL_BYPASS (decl
)->out_insn_name
,
2528 DECL_BYPASS (decl
)->in_insn_name
);
2531 (0, "the same bypass `%s - %s' is already defined",
2532 DECL_BYPASS (decl
)->out_insn_name
,
2533 DECL_BYPASS (decl
)->in_insn_name
);
2536 error ("bypass `%s - %s' is already defined",
2537 DECL_BYPASS (decl
)->out_insn_name
,
2538 DECL_BYPASS (decl
)->in_insn_name
);
2542 DECL_BYPASS (decl
)->next
2543 = DECL_INSN_RESERV (out_insn_reserv
)->bypass_list
;
2544 DECL_INSN_RESERV (out_insn_reserv
)->bypass_list
2545 = DECL_BYPASS (decl
);
2551 /* Check exclusion set declarations and form exclusion sets. */
2552 for (i
= 0; i
< description
->decls_num
; i
++)
2554 decl
= description
->decls
[i
];
2555 if (decl
->mode
== dm_excl
)
2557 unit_set_el_t unit_set_el_list
;
2558 unit_set_el_t unit_set_el_list_2
;
2561 = process_excls (DECL_EXCL (decl
)->names
,
2562 DECL_EXCL (decl
)->first_list_length
, decl
->pos
);
2564 = process_excls (&DECL_EXCL (decl
)->names
2565 [DECL_EXCL (decl
)->first_list_length
],
2566 DECL_EXCL (decl
)->all_names_num
2567 - DECL_EXCL (decl
)->first_list_length
,
2569 add_excls (unit_set_el_list
, unit_set_el_list_2
, decl
->pos
);
2570 add_excls (unit_set_el_list_2
, unit_set_el_list
, decl
->pos
);
2574 /* Check presence set declarations and form presence sets. */
2575 for (i
= 0; i
< description
->decls_num
; i
++)
2577 decl
= description
->decls
[i
];
2578 if (decl
->mode
== dm_presence
)
2580 unit_set_el_t unit_set_el_list
;
2581 pattern_set_el_t pattern_set_el_list
;
2584 = process_presence_absence_names
2585 (DECL_PRESENCE (decl
)->names
, DECL_PRESENCE (decl
)->names_num
,
2586 decl
->pos
, TRUE
, DECL_PRESENCE (decl
)->final_p
);
2588 = process_presence_absence_patterns
2589 (DECL_PRESENCE (decl
)->patterns
,
2590 DECL_PRESENCE (decl
)->patterns_num
,
2591 decl
->pos
, TRUE
, DECL_PRESENCE (decl
)->final_p
);
2592 add_presence_absence (unit_set_el_list
, pattern_set_el_list
,
2594 DECL_PRESENCE (decl
)->final_p
);
2598 /* Check absence set declarations and form absence sets. */
2599 for (i
= 0; i
< description
->decls_num
; i
++)
2601 decl
= description
->decls
[i
];
2602 if (decl
->mode
== dm_absence
)
2604 unit_set_el_t unit_set_el_list
;
2605 pattern_set_el_t pattern_set_el_list
;
2608 = process_presence_absence_names
2609 (DECL_ABSENCE (decl
)->names
, DECL_ABSENCE (decl
)->names_num
,
2610 decl
->pos
, FALSE
, DECL_ABSENCE (decl
)->final_p
);
2612 = process_presence_absence_patterns
2613 (DECL_ABSENCE (decl
)->patterns
,
2614 DECL_ABSENCE (decl
)->patterns_num
,
2615 decl
->pos
, FALSE
, DECL_ABSENCE (decl
)->final_p
);
2616 add_presence_absence (unit_set_el_list
, pattern_set_el_list
,
2618 DECL_ABSENCE (decl
)->final_p
);
2623 /* The following function checks that declared automaton is used. If
2624 the automaton is not used, the function fixes error/warning. The
2625 following function must be called only after `process_decls'. */
2627 check_automaton_usage (void)
2632 for (i
= 0; i
< description
->decls_num
; i
++)
2634 decl
= description
->decls
[i
];
2635 if (decl
->mode
== dm_automaton
2636 && !DECL_AUTOMATON (decl
)->automaton_is_used
)
2639 error ("automaton `%s' is not used", DECL_AUTOMATON (decl
)->name
);
2641 warning (0, "automaton `%s' is not used",
2642 DECL_AUTOMATON (decl
)->name
);
2647 /* The following recursive function processes all regexp in order to
2648 fix usage of units or reservations and to fix errors of undeclared
2649 name. The function may change unit_regexp onto reserv_regexp.
2650 Remember that reserv_regexp does not exist before the function
2653 process_regexp (regexp_t regexp
)
2655 decl_t decl_in_table
;
2656 regexp_t new_regexp
;
2659 switch (regexp
->mode
)
2662 decl_in_table
= find_decl (REGEXP_UNIT (regexp
)->name
);
2663 if (decl_in_table
== NULL
)
2664 error ("undeclared unit or reservation `%s'",
2665 REGEXP_UNIT (regexp
)->name
);
2667 switch (decl_in_table
->mode
)
2670 DECL_UNIT (decl_in_table
)->unit_is_used
= 1;
2671 REGEXP_UNIT (regexp
)->unit_decl
= DECL_UNIT (decl_in_table
);
2675 DECL_RESERV (decl_in_table
)->reserv_is_used
= 1;
2676 new_regexp
= XCREATENODE (struct regexp
);
2677 new_regexp
->mode
= rm_reserv
;
2678 new_regexp
->pos
= regexp
->pos
;
2679 REGEXP_RESERV (new_regexp
)->name
= REGEXP_UNIT (regexp
)->name
;
2680 REGEXP_RESERV (new_regexp
)->reserv_decl
2681 = DECL_RESERV (decl_in_table
);
2682 regexp
= new_regexp
;
2690 for (i
= 0; i
<REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
2691 REGEXP_SEQUENCE (regexp
)->regexps
[i
]
2692 = process_regexp (REGEXP_SEQUENCE (regexp
)->regexps
[i
]);
2695 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
2696 REGEXP_ALLOF (regexp
)->regexps
[i
]
2697 = process_regexp (REGEXP_ALLOF (regexp
)->regexps
[i
]);
2700 for (i
= 0; i
< REGEXP_ONEOF (regexp
)->regexps_num
; i
++)
2701 REGEXP_ONEOF (regexp
)->regexps
[i
]
2702 = process_regexp (REGEXP_ONEOF (regexp
)->regexps
[i
]);
2705 REGEXP_REPEAT (regexp
)->regexp
2706 = process_regexp (REGEXP_REPEAT (regexp
)->regexp
);
2716 /* The following function processes regexp of define_reservation and
2717 define_insn_reservation with the aid of function
2718 `process_regexp'. */
2720 process_regexp_decls (void)
2725 for (i
= 0; i
< description
->decls_num
; i
++)
2727 decl
= description
->decls
[i
];
2728 if (decl
->mode
== dm_reserv
)
2729 DECL_RESERV (decl
)->regexp
2730 = process_regexp (DECL_RESERV (decl
)->regexp
);
2731 else if (decl
->mode
== dm_insn_reserv
)
2732 DECL_INSN_RESERV (decl
)->regexp
2733 = process_regexp (DECL_INSN_RESERV (decl
)->regexp
);
2737 /* The following function checks that declared unit is used. If the
2738 unit is not used, the function fixes errors/warnings. The
2739 following function must be called only after `process_decls',
2740 `process_regexp_decls'. */
2747 for (i
= 0; i
< description
->decls_num
; i
++)
2749 decl
= description
->decls
[i
];
2750 if (decl
->mode
== dm_unit
&& !DECL_UNIT (decl
)->unit_is_used
)
2753 error ("unit `%s' is not used", DECL_UNIT (decl
)->name
);
2755 warning (0, "unit `%s' is not used", DECL_UNIT (decl
)->name
);
2757 else if (decl
->mode
== dm_reserv
&& !DECL_RESERV (decl
)->reserv_is_used
)
2760 error ("reservation `%s' is not used", DECL_RESERV (decl
)->name
);
2762 warning (0, "reservation `%s' is not used", DECL_RESERV (decl
)->name
);
2767 /* The following variable value is number of reservation being
2768 processed on loop recognition. */
2769 static int curr_loop_pass_num
;
2771 /* The following recursive function returns nonzero value if REGEXP
2772 contains given decl or reservations in given regexp refers for
2775 loop_in_regexp (regexp_t regexp
, decl_t start_decl
)
2781 switch (regexp
->mode
)
2787 if (start_decl
->mode
== dm_reserv
2788 && REGEXP_RESERV (regexp
)->reserv_decl
== DECL_RESERV (start_decl
))
2790 else if (REGEXP_RESERV (regexp
)->reserv_decl
->loop_pass_num
2791 == curr_loop_pass_num
)
2792 /* declaration has been processed. */
2796 REGEXP_RESERV (regexp
)->reserv_decl
->loop_pass_num
2797 = curr_loop_pass_num
;
2798 return loop_in_regexp (REGEXP_RESERV (regexp
)->reserv_decl
->regexp
,
2803 for (i
= 0; i
<REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
2804 if (loop_in_regexp (REGEXP_SEQUENCE (regexp
)->regexps
[i
], start_decl
))
2809 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
2810 if (loop_in_regexp (REGEXP_ALLOF (regexp
)->regexps
[i
], start_decl
))
2815 for (i
= 0; i
< REGEXP_ONEOF (regexp
)->regexps_num
; i
++)
2816 if (loop_in_regexp (REGEXP_ONEOF (regexp
)->regexps
[i
], start_decl
))
2821 return loop_in_regexp (REGEXP_REPEAT (regexp
)->regexp
, start_decl
);
2831 /* The following function fixes errors "cycle in definition ...". The
2832 function uses function `loop_in_regexp' for that. */
2834 check_loops_in_regexps (void)
2839 for (i
= 0; i
< description
->decls_num
; i
++)
2841 decl
= description
->decls
[i
];
2842 if (decl
->mode
== dm_reserv
)
2843 DECL_RESERV (decl
)->loop_pass_num
= 0;
2845 for (i
= 0; i
< description
->decls_num
; i
++)
2847 decl
= description
->decls
[i
];
2848 curr_loop_pass_num
= i
;
2850 if (decl
->mode
== dm_reserv
)
2852 DECL_RESERV (decl
)->loop_pass_num
= curr_loop_pass_num
;
2853 if (loop_in_regexp (DECL_RESERV (decl
)->regexp
, decl
))
2855 gcc_assert (DECL_RESERV (decl
)->regexp
);
2856 error ("cycle in definition of reservation `%s'",
2857 DECL_RESERV (decl
)->name
);
2863 /* The function recursively processes IR of reservation and defines
2864 max and min cycle for reservation of unit. */
2866 process_regexp_cycles (regexp_t regexp
, int max_start_cycle
,
2867 int min_start_cycle
, int *max_finish_cycle
,
2868 int *min_finish_cycle
)
2872 switch (regexp
->mode
)
2875 if (REGEXP_UNIT (regexp
)->unit_decl
->max_occ_cycle_num
< max_start_cycle
)
2876 REGEXP_UNIT (regexp
)->unit_decl
->max_occ_cycle_num
= max_start_cycle
;
2877 if (REGEXP_UNIT (regexp
)->unit_decl
->min_occ_cycle_num
> min_start_cycle
2878 || REGEXP_UNIT (regexp
)->unit_decl
->min_occ_cycle_num
== -1)
2879 REGEXP_UNIT (regexp
)->unit_decl
->min_occ_cycle_num
= min_start_cycle
;
2880 *max_finish_cycle
= max_start_cycle
;
2881 *min_finish_cycle
= min_start_cycle
;
2885 process_regexp_cycles (REGEXP_RESERV (regexp
)->reserv_decl
->regexp
,
2886 max_start_cycle
, min_start_cycle
,
2887 max_finish_cycle
, min_finish_cycle
);
2891 for (i
= 0; i
< REGEXP_REPEAT (regexp
)->repeat_num
; i
++)
2893 process_regexp_cycles (REGEXP_REPEAT (regexp
)->regexp
,
2894 max_start_cycle
, min_start_cycle
,
2895 max_finish_cycle
, min_finish_cycle
);
2896 max_start_cycle
= *max_finish_cycle
+ 1;
2897 min_start_cycle
= *min_finish_cycle
+ 1;
2902 for (i
= 0; i
<REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
2904 process_regexp_cycles (REGEXP_SEQUENCE (regexp
)->regexps
[i
],
2905 max_start_cycle
, min_start_cycle
,
2906 max_finish_cycle
, min_finish_cycle
);
2907 max_start_cycle
= *max_finish_cycle
+ 1;
2908 min_start_cycle
= *min_finish_cycle
+ 1;
2917 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
2919 process_regexp_cycles (REGEXP_ALLOF (regexp
)->regexps
[i
],
2920 max_start_cycle
, min_start_cycle
,
2921 max_finish_cycle
, min_finish_cycle
);
2922 if (max_cycle
< *max_finish_cycle
)
2923 max_cycle
= *max_finish_cycle
;
2924 if (i
== 0 || min_cycle
> *min_finish_cycle
)
2925 min_cycle
= *min_finish_cycle
;
2927 *max_finish_cycle
= max_cycle
;
2928 *min_finish_cycle
= min_cycle
;
2937 for (i
= 0; i
< REGEXP_ONEOF (regexp
)->regexps_num
; i
++)
2939 process_regexp_cycles (REGEXP_ONEOF (regexp
)->regexps
[i
],
2940 max_start_cycle
, min_start_cycle
,
2941 max_finish_cycle
, min_finish_cycle
);
2942 if (max_cycle
< *max_finish_cycle
)
2943 max_cycle
= *max_finish_cycle
;
2944 if (i
== 0 || min_cycle
> *min_finish_cycle
)
2945 min_cycle
= *min_finish_cycle
;
2947 *max_finish_cycle
= max_cycle
;
2948 *min_finish_cycle
= min_cycle
;
2953 *max_finish_cycle
= max_start_cycle
;
2954 *min_finish_cycle
= min_start_cycle
;
2962 /* The following function is called only for correct program. The
2963 function defines max reservation of insns in cycles. */
2965 evaluate_max_reserv_cycles (void)
2967 int max_insn_cycles_num
;
2968 int min_insn_cycles_num
;
2972 description
->max_insn_reserv_cycles
= 0;
2973 for (i
= 0; i
< description
->decls_num
; i
++)
2975 decl
= description
->decls
[i
];
2976 if (decl
->mode
== dm_insn_reserv
)
2978 process_regexp_cycles (DECL_INSN_RESERV (decl
)->regexp
, 0, 0,
2979 &max_insn_cycles_num
, &min_insn_cycles_num
);
2980 if (description
->max_insn_reserv_cycles
< max_insn_cycles_num
)
2981 description
->max_insn_reserv_cycles
= max_insn_cycles_num
;
2984 description
->max_insn_reserv_cycles
++;
2987 /* The following function calls functions for checking all
2990 check_all_description (void)
2993 check_automaton_usage ();
2994 process_regexp_decls ();
2996 check_loops_in_regexps ();
2998 evaluate_max_reserv_cycles ();
3003 /* The page contains abstract data `ticker'. This data is used to
3004 report time of different phases of building automata. It is
3005 possibly to write a description for which automata will be built
3006 during several minutes even on fast machine. */
3008 /* The following function creates ticker and makes it active. */
3010 create_ticker (void)
3014 ticker
.modified_creation_time
= get_run_time ();
3015 ticker
.incremented_off_time
= 0;
3019 /* The following function switches off given ticker. */
3021 ticker_off (ticker_t
*ticker
)
3023 if (ticker
->incremented_off_time
== 0)
3024 ticker
->incremented_off_time
= get_run_time () + 1;
3027 /* The following function switches on given ticker. */
3029 ticker_on (ticker_t
*ticker
)
3031 if (ticker
->incremented_off_time
!= 0)
3033 ticker
->modified_creation_time
3034 += get_run_time () - ticker
->incremented_off_time
+ 1;
3035 ticker
->incremented_off_time
= 0;
3039 /* The following function returns current time in milliseconds since
3040 the moment when given ticker was created. */
3042 active_time (ticker_t ticker
)
3044 if (ticker
.incremented_off_time
!= 0)
3045 return ticker
.incremented_off_time
- 1 - ticker
.modified_creation_time
;
3047 return get_run_time () - ticker
.modified_creation_time
;
3050 /* The following function returns string representation of active time
3051 of given ticker. The result is string representation of seconds
3052 with accuracy of 1/100 second. Only result of the last call of the
3053 function exists. Therefore the following code is not correct
3055 printf ("parser time: %s\ngeneration time: %s\n",
3056 active_time_string (parser_ticker),
3057 active_time_string (generation_ticker));
3059 Correct code has to be the following
3061 printf ("parser time: %s\n", active_time_string (parser_ticker));
3062 printf ("generation time: %s\n",
3063 active_time_string (generation_ticker));
3067 print_active_time (FILE *f
, ticker_t ticker
)
3071 msecs
= active_time (ticker
);
3072 fprintf (f
, "%d.%06d", msecs
/ 1000000, msecs
% 1000000);
3077 /* The following variable value is number of automaton which are
3078 really being created. This value is defined on the base of
3079 argument of option `-split'. If the variable has zero value the
3080 number of automata is defined by the constructions `%automaton'.
3081 This case occurs when option `-split' is absent or has zero
3082 argument. If constructions `define_automaton' is absent only one
3083 automaton is created. */
3084 static int automata_num
;
3086 /* The following variable values are times of
3087 o transformation of regular expressions
3088 o building NDFA (DFA if !ndfa_flag)
3089 o NDFA -> DFA (simply the same automaton if !ndfa_flag)
3091 o building insn equivalence classes
3094 static ticker_t transform_time
;
3095 static ticker_t NDFA_time
;
3096 static ticker_t NDFA_to_DFA_time
;
3097 static ticker_t minimize_time
;
3098 static ticker_t equiv_time
;
3099 static ticker_t automaton_generation_time
;
3100 static ticker_t output_time
;
3102 /* The following variable values are times of
3105 all pipeline hazard translator work */
3106 static ticker_t check_time
;
3107 static ticker_t generation_time
;
3108 static ticker_t all_time
;
3112 /* Pseudo insn decl which denotes advancing cycle. */
3113 static decl_t advance_cycle_insn_decl
;
3115 add_advance_cycle_insn_decl (void)
3117 advance_cycle_insn_decl
= XCREATENODE (struct decl
);
3118 advance_cycle_insn_decl
->mode
= dm_insn_reserv
;
3119 advance_cycle_insn_decl
->pos
= no_pos
;
3120 DECL_INSN_RESERV (advance_cycle_insn_decl
)->regexp
= NULL
;
3121 DECL_INSN_RESERV (advance_cycle_insn_decl
)->name
= "$advance_cycle";
3122 DECL_INSN_RESERV (advance_cycle_insn_decl
)->insn_num
3123 = description
->insns_num
;
3124 description
->decls
[description
->decls_num
] = advance_cycle_insn_decl
;
3125 description
->decls_num
++;
3126 description
->insns_num
++;
3130 /* Abstract data `alternative states' which represents
3131 nondeterministic nature of the description (see comments for
3132 structures alt_state and state). */
3134 /* List of free states. */
3135 static alt_state_t first_free_alt_state
;
3138 /* The following variables is maximal number of allocated nodes
3140 static int allocated_alt_states_num
= 0;
3143 /* The following function returns free node alt_state. It may be new
3144 allocated node or node freed earlier. */
3146 get_free_alt_state (void)
3150 if (first_free_alt_state
!= NULL
)
3152 result
= first_free_alt_state
;
3153 first_free_alt_state
= first_free_alt_state
->next_alt_state
;
3158 allocated_alt_states_num
++;
3160 result
= XCREATENODE (struct alt_state
);
3162 result
->state
= NULL
;
3163 result
->next_alt_state
= NULL
;
3164 result
->next_sorted_alt_state
= NULL
;
3168 /* The function frees node ALT_STATE. */
3170 free_alt_state (alt_state_t alt_state
)
3172 if (alt_state
== NULL
)
3174 alt_state
->next_alt_state
= first_free_alt_state
;
3175 first_free_alt_state
= alt_state
;
3178 /* The function frees list started with node ALT_STATE_LIST. */
3180 free_alt_states (alt_state_t alt_states_list
)
3182 alt_state_t curr_alt_state
;
3183 alt_state_t next_alt_state
;
3185 for (curr_alt_state
= alt_states_list
;
3186 curr_alt_state
!= NULL
;
3187 curr_alt_state
= next_alt_state
)
3189 next_alt_state
= curr_alt_state
->next_alt_state
;
3190 free_alt_state (curr_alt_state
);
3194 /* The function compares unique numbers of alt states. */
3196 alt_state_cmp (const void *alt_state_ptr_1
, const void *alt_state_ptr_2
)
3198 if ((*(const alt_state_t
*) alt_state_ptr_1
)->state
->unique_num
3199 == (*(const alt_state_t
*) alt_state_ptr_2
)->state
->unique_num
)
3201 else if ((*(const alt_state_t
*) alt_state_ptr_1
)->state
->unique_num
3202 < (*(const alt_state_t
*) alt_state_ptr_2
)->state
->unique_num
)
3208 /* The function sorts ALT_STATES_LIST and removes duplicated alt
3209 states from the list. The comparison key is alt state unique
3213 uniq_sort_alt_states (alt_state_t alt_states_list
)
3215 alt_state_t curr_alt_state
;
3216 VEC(alt_state_t
,heap
) *alt_states
;
3218 size_t prev_unique_state_ind
;
3221 if (alt_states_list
== 0)
3223 if (alt_states_list
->next_alt_state
== 0)
3224 return alt_states_list
;
3226 alt_states
= VEC_alloc (alt_state_t
,heap
, 150);
3227 for (curr_alt_state
= alt_states_list
;
3228 curr_alt_state
!= NULL
;
3229 curr_alt_state
= curr_alt_state
->next_alt_state
)
3230 VEC_safe_push (alt_state_t
,heap
, alt_states
, curr_alt_state
);
3232 qsort (VEC_address (alt_state_t
, alt_states
),
3233 VEC_length (alt_state_t
, alt_states
),
3234 sizeof (alt_state_t
), alt_state_cmp
);
3236 prev_unique_state_ind
= 0;
3237 for (i
= 1; i
< VEC_length (alt_state_t
, alt_states
); i
++)
3238 if (VEC_index (alt_state_t
, alt_states
, prev_unique_state_ind
)->state
3239 != VEC_index (alt_state_t
, alt_states
, i
)->state
)
3241 prev_unique_state_ind
++;
3242 VEC_replace (alt_state_t
, alt_states
, prev_unique_state_ind
,
3243 VEC_index (alt_state_t
, alt_states
, i
));
3245 VEC_truncate (alt_state_t
, alt_states
, prev_unique_state_ind
+ 1);
3247 for (i
= 1; i
< VEC_length (alt_state_t
, alt_states
); i
++)
3248 VEC_index (alt_state_t
, alt_states
, i
-1)->next_sorted_alt_state
3249 = VEC_index (alt_state_t
, alt_states
, i
);
3250 VEC_last (alt_state_t
, alt_states
)->next_sorted_alt_state
= 0;
3252 result
= VEC_index (alt_state_t
, alt_states
, 0);
3254 VEC_free (alt_state_t
,heap
, alt_states
);
3258 /* The function checks equality of alt state lists. Remember that the
3259 lists must be already sorted by the previous function. */
3261 alt_states_eq (alt_state_t alt_states_1
, alt_state_t alt_states_2
)
3263 while (alt_states_1
!= NULL
&& alt_states_2
!= NULL
3264 && alt_state_cmp (&alt_states_1
, &alt_states_2
) == 0)
3266 alt_states_1
= alt_states_1
->next_sorted_alt_state
;
3267 alt_states_2
= alt_states_2
->next_sorted_alt_state
;
3269 return alt_states_1
== alt_states_2
;
3272 /* Initialization of the abstract data. */
3274 initiate_alt_states (void)
3276 first_free_alt_state
= NULL
;
3279 /* Finishing work with the abstract data. */
3281 finish_alt_states (void)
3287 /* The page contains macros for work with bits strings. We could use
3288 standard gcc bitmap or sbitmap but it would result in difficulties
3289 of building canadian cross. */
3291 /* Set bit number bitno in the bit string. The macro is not side
3293 #define SET_BIT(bitstring, bitno) \
3294 (((char *) (bitstring)) [(bitno) / CHAR_BIT] |= 1 << (bitno) % CHAR_BIT)
3296 #define CLEAR_BIT(bitstring, bitno) \
3297 (((char *) (bitstring)) [(bitno) / CHAR_BIT] &= ~(1 << (bitno) % CHAR_BIT))
3299 /* Test if bit number bitno in the bitstring is set. The macro is not
3300 side effect proof. */
3301 #define TEST_BIT(bitstring, bitno) \
3302 (((char *) (bitstring)) [(bitno) / CHAR_BIT] >> (bitno) % CHAR_BIT & 1)
3306 /* This page contains abstract data `state'. */
3308 /* Maximal length of reservations in cycles (>= 1). */
3309 static int max_cycles_num
;
3311 /* Number of set elements (see type set_el_t) needed for
3312 representation of one cycle reservation. It is depended on units
3314 static int els_in_cycle_reserv
;
3316 /* Number of set elements (see type set_el_t) needed for
3317 representation of maximal length reservation. Deterministic
3318 reservation is stored as set (bit string) of length equal to the
3319 variable value * number of bits in set_el_t. */
3320 static int els_in_reservs
;
3322 /* Array of pointers to unit declarations. */
3323 static unit_decl_t
*units_array
;
3325 /* Temporary reservation of maximal length. */
3326 static reserv_sets_t temp_reserv
;
3328 /* The state table itself is represented by the following variable. */
3329 static htab_t state_table
;
3331 /* Linked list of free 'state' structures to be recycled. The
3332 next_equiv_class_state pointer is borrowed for a free list. */
3333 static state_t first_free_state
;
3335 static int curr_unique_state_num
;
3338 /* The following variables is maximal number of allocated nodes
3340 static int allocated_states_num
= 0;
3343 /* Allocate new reservation set. */
3344 static reserv_sets_t
3345 alloc_empty_reserv_sets (void)
3347 reserv_sets_t result
;
3349 obstack_blank (&irp
, els_in_reservs
* sizeof (set_el_t
));
3350 result
= (reserv_sets_t
) obstack_base (&irp
);
3351 obstack_finish (&irp
);
3352 memset (result
, 0, els_in_reservs
* sizeof (set_el_t
));
3356 /* Hash value of reservation set. */
3358 reserv_sets_hash_value (reserv_sets_t reservs
)
3360 set_el_t hash_value
;
3363 set_el_t
*reserv_ptr
;
3366 reservs_num
= els_in_reservs
;
3367 reserv_ptr
= reservs
;
3369 while (reservs_num
!= 0)
3372 hash_value
+= ((*reserv_ptr
>> i
)
3373 | (*reserv_ptr
<< (sizeof (set_el_t
) * CHAR_BIT
- i
)));
3375 if (i
== sizeof (set_el_t
) * CHAR_BIT
)
3379 if (sizeof (set_el_t
) <= sizeof (unsigned))
3382 for (i
= sizeof (set_el_t
); i
> 0; i
-= sizeof (unsigned) - 1)
3384 result
+= (unsigned) hash_value
;
3385 hash_value
>>= (sizeof (unsigned) - 1) * CHAR_BIT
;
3390 /* Comparison of given reservation sets. */
3392 reserv_sets_cmp (const_reserv_sets_t reservs_1
, const_reserv_sets_t reservs_2
)
3395 const set_el_t
*reserv_ptr_1
;
3396 const set_el_t
*reserv_ptr_2
;
3398 gcc_assert (reservs_1
&& reservs_2
);
3399 reservs_num
= els_in_reservs
;
3400 reserv_ptr_1
= reservs_1
;
3401 reserv_ptr_2
= reservs_2
;
3402 while (reservs_num
!= 0 && *reserv_ptr_1
== *reserv_ptr_2
)
3408 if (reservs_num
== 0)
3410 else if (*reserv_ptr_1
< *reserv_ptr_2
)
3416 /* The function checks equality of the reservation sets. */
3418 reserv_sets_eq (const_reserv_sets_t reservs_1
, const_reserv_sets_t reservs_2
)
3420 return reserv_sets_cmp (reservs_1
, reservs_2
) == 0;
3423 /* Set up in the reservation set that unit with UNIT_NUM is used on
3426 set_unit_reserv (reserv_sets_t reservs
, int cycle_num
, int unit_num
)
3428 gcc_assert (cycle_num
< max_cycles_num
);
3429 SET_BIT (reservs
, cycle_num
* els_in_cycle_reserv
3430 * sizeof (set_el_t
) * CHAR_BIT
+ unit_num
);
3433 /* Set up in the reservation set RESERVS that unit with UNIT_NUM is
3434 used on CYCLE_NUM. */
3436 test_unit_reserv (reserv_sets_t reservs
, int cycle_num
, int unit_num
)
3438 gcc_assert (cycle_num
< max_cycles_num
);
3439 return TEST_BIT (reservs
, cycle_num
* els_in_cycle_reserv
3440 * sizeof (set_el_t
) * CHAR_BIT
+ unit_num
);
3443 /* The function checks that the reservation sets are intersected,
3444 i.e. there is a unit reservation on a cycle in both reservation
3447 reserv_sets_are_intersected (reserv_sets_t operand_1
,
3448 reserv_sets_t operand_2
)
3452 set_el_t
*cycle_ptr_1
;
3453 set_el_t
*cycle_ptr_2
;
3455 gcc_assert (operand_1
&& operand_2
);
3456 for (el_ptr_1
= operand_1
, el_ptr_2
= operand_2
;
3457 el_ptr_1
< operand_1
+ els_in_reservs
;
3458 el_ptr_1
++, el_ptr_2
++)
3459 if (*el_ptr_1
& *el_ptr_2
)
3461 reserv_sets_or (temp_reserv
, operand_1
, operand_2
);
3462 for (cycle_ptr_1
= operand_1
, cycle_ptr_2
= operand_2
;
3463 cycle_ptr_1
< operand_1
+ els_in_reservs
;
3464 cycle_ptr_1
+= els_in_cycle_reserv
, cycle_ptr_2
+= els_in_cycle_reserv
)
3466 for (el_ptr_1
= cycle_ptr_1
, el_ptr_2
= get_excl_set (cycle_ptr_2
);
3467 el_ptr_1
< cycle_ptr_1
+ els_in_cycle_reserv
;
3468 el_ptr_1
++, el_ptr_2
++)
3469 if (*el_ptr_1
& *el_ptr_2
)
3471 if (!check_presence_pattern_sets (cycle_ptr_1
, cycle_ptr_2
, FALSE
))
3473 if (!check_presence_pattern_sets (temp_reserv
+ (cycle_ptr_2
3477 if (!check_absence_pattern_sets (cycle_ptr_1
, cycle_ptr_2
, FALSE
))
3479 if (!check_absence_pattern_sets (temp_reserv
+ (cycle_ptr_2
- operand_2
),
3486 /* The function sets up RESULT bits by bits of OPERAND shifted on one
3487 cpu cycle. The remaining bits of OPERAND (representing the last
3488 cycle unit reservations) are not changed. */
3490 reserv_sets_shift (reserv_sets_t result
, reserv_sets_t operand
)
3494 gcc_assert (result
&& operand
&& result
!= operand
);
3495 for (i
= els_in_cycle_reserv
; i
< els_in_reservs
; i
++)
3496 result
[i
- els_in_cycle_reserv
] = operand
[i
];
3499 /* OR of the reservation sets. */
3501 reserv_sets_or (reserv_sets_t result
, reserv_sets_t operand_1
,
3502 reserv_sets_t operand_2
)
3506 set_el_t
*result_set_el_ptr
;
3508 gcc_assert (result
&& operand_1
&& operand_2
);
3509 for (el_ptr_1
= operand_1
, el_ptr_2
= operand_2
, result_set_el_ptr
= result
;
3510 el_ptr_1
< operand_1
+ els_in_reservs
;
3511 el_ptr_1
++, el_ptr_2
++, result_set_el_ptr
++)
3512 *result_set_el_ptr
= *el_ptr_1
| *el_ptr_2
;
3515 /* AND of the reservation sets. */
3517 reserv_sets_and (reserv_sets_t result
, reserv_sets_t operand_1
,
3518 reserv_sets_t operand_2
)
3522 set_el_t
*result_set_el_ptr
;
3524 gcc_assert (result
&& operand_1
&& operand_2
);
3525 for (el_ptr_1
= operand_1
, el_ptr_2
= operand_2
, result_set_el_ptr
= result
;
3526 el_ptr_1
< operand_1
+ els_in_reservs
;
3527 el_ptr_1
++, el_ptr_2
++, result_set_el_ptr
++)
3528 *result_set_el_ptr
= *el_ptr_1
& *el_ptr_2
;
3531 /* The function outputs string representation of units reservation on
3532 cycle START_CYCLE in the reservation set. The function uses repeat
3533 construction if REPETITION_NUM > 1. */
3535 output_cycle_reservs (FILE *f
, reserv_sets_t reservs
, int start_cycle
,
3539 int reserved_units_num
;
3541 reserved_units_num
= 0;
3542 for (unit_num
= 0; unit_num
< description
->units_num
; unit_num
++)
3543 if (TEST_BIT (reservs
, start_cycle
* els_in_cycle_reserv
3544 * sizeof (set_el_t
) * CHAR_BIT
+ unit_num
))
3545 reserved_units_num
++;
3546 gcc_assert (repetition_num
> 0);
3547 if (repetition_num
!= 1 && reserved_units_num
> 1)
3549 reserved_units_num
= 0;
3551 unit_num
< description
->units_num
;
3553 if (TEST_BIT (reservs
, start_cycle
* els_in_cycle_reserv
3554 * sizeof (set_el_t
) * CHAR_BIT
+ unit_num
))
3556 if (reserved_units_num
!= 0)
3558 reserved_units_num
++;
3559 fprintf (f
, "%s", units_array
[unit_num
]->name
);
3561 if (reserved_units_num
== 0)
3562 fprintf (f
, NOTHING_NAME
);
3563 gcc_assert (repetition_num
> 0);
3564 if (repetition_num
!= 1 && reserved_units_num
> 1)
3566 if (repetition_num
!= 1)
3567 fprintf (f
, "*%d", repetition_num
);
3570 /* The function outputs string representation of units reservation in
3571 the reservation set. */
3573 output_reserv_sets (FILE *f
, reserv_sets_t reservs
)
3575 int start_cycle
= 0;
3580 for (cycle
= 0; cycle
< max_cycles_num
; cycle
++)
3581 if (repetition_num
== 0)
3584 start_cycle
= cycle
;
3587 ((char *) reservs
+ start_cycle
* els_in_cycle_reserv
3588 * sizeof (set_el_t
),
3589 (char *) reservs
+ cycle
* els_in_cycle_reserv
3590 * sizeof (set_el_t
),
3591 els_in_cycle_reserv
* sizeof (set_el_t
)) == 0)
3595 if (start_cycle
!= 0)
3597 output_cycle_reservs (f
, reservs
, start_cycle
, repetition_num
);
3599 start_cycle
= cycle
;
3601 if (start_cycle
< max_cycles_num
)
3603 if (start_cycle
!= 0)
3605 output_cycle_reservs (f
, reservs
, start_cycle
, repetition_num
);
3609 /* The following function returns free node state for AUTOMATON. It
3610 may be new allocated node or node freed earlier. The function also
3611 allocates reservation set if WITH_RESERVS has nonzero value. */
3613 get_free_state (int with_reservs
, automaton_t automaton
)
3617 gcc_assert (max_cycles_num
> 0 && automaton
);
3618 if (first_free_state
)
3620 result
= first_free_state
;
3621 first_free_state
= result
->next_equiv_class_state
;
3623 result
->next_equiv_class_state
= NULL
;
3624 result
->automaton
= automaton
;
3625 result
->first_out_arc
= NULL
;
3626 result
->it_was_placed_in_stack_for_NDFA_forming
= 0;
3627 result
->it_was_placed_in_stack_for_DFA_forming
= 0;
3628 result
->component_states
= NULL
;
3633 allocated_states_num
++;
3635 result
= XCREATENODE (struct state
);
3636 result
->automaton
= automaton
;
3637 result
->first_out_arc
= NULL
;
3638 result
->unique_num
= curr_unique_state_num
;
3639 curr_unique_state_num
++;
3643 if (result
->reservs
== NULL
)
3644 result
->reservs
= alloc_empty_reserv_sets ();
3646 memset (result
->reservs
, 0, els_in_reservs
* sizeof (set_el_t
));
3651 /* The function frees node STATE. */
3653 free_state (state_t state
)
3655 free_alt_states (state
->component_states
);
3656 state
->next_equiv_class_state
= first_free_state
;
3657 first_free_state
= state
;
3660 /* Hash value of STATE. If STATE represents deterministic state it is
3661 simply hash value of the corresponding reservation set. Otherwise
3662 it is formed from hash values of the component deterministic
3663 states. One more key is order number of state automaton. */
3665 state_hash (const void *state
)
3667 unsigned int hash_value
;
3668 alt_state_t alt_state
;
3670 if (((const_state_t
) state
)->component_states
== NULL
)
3671 hash_value
= reserv_sets_hash_value (((const_state_t
) state
)->reservs
);
3675 for (alt_state
= ((const_state_t
) state
)->component_states
;
3677 alt_state
= alt_state
->next_sorted_alt_state
)
3678 hash_value
= (((hash_value
>> (sizeof (unsigned) - 1) * CHAR_BIT
)
3679 | (hash_value
<< CHAR_BIT
))
3680 + alt_state
->state
->unique_num
);
3682 hash_value
= (((hash_value
>> (sizeof (unsigned) - 1) * CHAR_BIT
)
3683 | (hash_value
<< CHAR_BIT
))
3684 + ((const_state_t
) state
)->automaton
->automaton_order_num
);
3688 /* Return nonzero value if the states are the same. */
3690 state_eq_p (const void *state_1
, const void *state_2
)
3692 alt_state_t alt_state_1
;
3693 alt_state_t alt_state_2
;
3695 if (((const_state_t
) state_1
)->automaton
!= ((const_state_t
) state_2
)->automaton
)
3697 else if (((const_state_t
) state_1
)->component_states
== NULL
3698 && ((const_state_t
) state_2
)->component_states
== NULL
)
3699 return reserv_sets_eq (((const_state_t
) state_1
)->reservs
,
3700 ((const_state_t
) state_2
)->reservs
);
3701 else if (((const_state_t
) state_1
)->component_states
!= NULL
3702 && ((const_state_t
) state_2
)->component_states
!= NULL
)
3704 for (alt_state_1
= ((const_state_t
) state_1
)->component_states
,
3705 alt_state_2
= ((const_state_t
) state_2
)->component_states
;
3706 alt_state_1
!= NULL
&& alt_state_2
!= NULL
;
3707 alt_state_1
= alt_state_1
->next_sorted_alt_state
,
3708 alt_state_2
= alt_state_2
->next_sorted_alt_state
)
3709 /* All state in the list must be already in the hash table.
3710 Also the lists must be sorted. */
3711 if (alt_state_1
->state
!= alt_state_2
->state
)
3713 return alt_state_1
== alt_state_2
;
3719 /* Insert STATE into the state table. */
3721 insert_state (state_t state
)
3725 entry_ptr
= htab_find_slot (state_table
, (void *) state
, 1);
3726 if (*entry_ptr
== NULL
)
3727 *entry_ptr
= (void *) state
;
3728 return (state_t
) *entry_ptr
;
3731 /* Add reservation of unit with UNIT_NUM on cycle CYCLE_NUM to
3732 deterministic STATE. */
3734 set_state_reserv (state_t state
, int cycle_num
, int unit_num
)
3736 set_unit_reserv (state
->reservs
, cycle_num
, unit_num
);
3739 /* Return nonzero value if the deterministic states contains a
3740 reservation of the same cpu unit on the same cpu cycle. */
3742 intersected_state_reservs_p (state_t state1
, state_t state2
)
3744 gcc_assert (state1
->automaton
== state2
->automaton
);
3745 return reserv_sets_are_intersected (state1
->reservs
, state2
->reservs
);
3748 /* Return deterministic state (inserted into the table) which
3749 representing the automaton state which is union of reservations of
3750 the deterministic states masked by RESERVS. */
3752 states_union (state_t state1
, state_t state2
, reserv_sets_t reservs
)
3755 state_t state_in_table
;
3757 gcc_assert (state1
->automaton
== state2
->automaton
);
3758 result
= get_free_state (1, state1
->automaton
);
3759 reserv_sets_or (result
->reservs
, state1
->reservs
, state2
->reservs
);
3760 reserv_sets_and (result
->reservs
, result
->reservs
, reservs
);
3761 state_in_table
= insert_state (result
);
3762 if (result
!= state_in_table
)
3764 free_state (result
);
3765 result
= state_in_table
;
3770 /* Return deterministic state (inserted into the table) which
3771 represent the automaton state is obtained from deterministic STATE
3772 by advancing cpu cycle and masking by RESERVS. */
3774 state_shift (state_t state
, reserv_sets_t reservs
)
3777 state_t state_in_table
;
3779 result
= get_free_state (1, state
->automaton
);
3780 reserv_sets_shift (result
->reservs
, state
->reservs
);
3781 reserv_sets_and (result
->reservs
, result
->reservs
, reservs
);
3782 state_in_table
= insert_state (result
);
3783 if (result
!= state_in_table
)
3785 free_state (result
);
3786 result
= state_in_table
;
3791 /* Initialization of the abstract data. */
3793 initiate_states (void)
3798 if (description
->units_num
)
3799 units_array
= XNEWVEC (unit_decl_t
, description
->units_num
);
3803 for (i
= 0; i
< description
->decls_num
; i
++)
3805 decl
= description
->decls
[i
];
3806 if (decl
->mode
== dm_unit
)
3807 units_array
[DECL_UNIT (decl
)->unit_num
] = DECL_UNIT (decl
);
3809 max_cycles_num
= description
->max_insn_reserv_cycles
;
3811 = ((description
->units_num
+ sizeof (set_el_t
) * CHAR_BIT
- 1)
3812 / (sizeof (set_el_t
) * CHAR_BIT
));
3813 els_in_reservs
= els_in_cycle_reserv
* max_cycles_num
;
3814 curr_unique_state_num
= 0;
3815 initiate_alt_states ();
3816 state_table
= htab_create (1500, state_hash
, state_eq_p
, (htab_del
) 0);
3817 temp_reserv
= alloc_empty_reserv_sets ();
3820 /* Finishing work with the abstract data. */
3822 finish_states (void)
3826 htab_delete (state_table
);
3827 first_free_state
= NULL
;
3828 finish_alt_states ();
3833 /* Abstract data `arcs'. */
3835 /* List of free arcs. */
3836 static arc_t first_free_arc
;
3839 /* The following variables is maximal number of allocated nodes
3841 static int allocated_arcs_num
= 0;
3844 /* The function frees node ARC. */
3846 free_arc (arc_t arc
)
3848 arc
->next_out_arc
= first_free_arc
;
3849 first_free_arc
= arc
;
3852 /* The function removes and frees ARC staring from FROM_STATE. */
3854 remove_arc (state_t from_state
, arc_t arc
)
3860 for (prev_arc
= NULL
, curr_arc
= from_state
->first_out_arc
;
3862 prev_arc
= curr_arc
, curr_arc
= curr_arc
->next_out_arc
)
3863 if (curr_arc
== arc
)
3865 gcc_assert (curr_arc
);
3866 if (prev_arc
== NULL
)
3867 from_state
->first_out_arc
= arc
->next_out_arc
;
3869 prev_arc
->next_out_arc
= arc
->next_out_arc
;
3870 from_state
->num_out_arcs
--;
3874 /* The functions returns arc with given characteristics (or NULL if
3875 the arc does not exist). */
3877 find_arc (state_t from_state
, state_t to_state
, ainsn_t insn
)
3881 for (arc
= first_out_arc (from_state
); arc
!= NULL
; arc
= next_out_arc (arc
))
3882 if (arc
->to_state
== to_state
&& arc
->insn
== insn
)
3887 /* The function adds arc from FROM_STATE to TO_STATE marked by AINSN.
3888 The function returns added arc (or already existing arc). */
3890 add_arc (state_t from_state
, state_t to_state
, ainsn_t ainsn
)
3894 new_arc
= find_arc (from_state
, to_state
, ainsn
);
3895 if (new_arc
!= NULL
)
3897 if (first_free_arc
== NULL
)
3900 allocated_arcs_num
++;
3902 new_arc
= XCREATENODE (struct arc
);
3903 new_arc
->to_state
= NULL
;
3904 new_arc
->insn
= NULL
;
3905 new_arc
->next_out_arc
= NULL
;
3909 new_arc
= first_free_arc
;
3910 first_free_arc
= first_free_arc
->next_out_arc
;
3912 new_arc
->to_state
= to_state
;
3913 new_arc
->insn
= ainsn
;
3914 ainsn
->arc_exists_p
= 1;
3915 new_arc
->next_out_arc
= from_state
->first_out_arc
;
3916 from_state
->first_out_arc
= new_arc
;
3917 from_state
->num_out_arcs
++;
3918 new_arc
->next_arc_marked_by_insn
= NULL
;
3922 /* The function returns the first arc starting from STATE. */
3924 first_out_arc (const_state_t state
)
3926 return state
->first_out_arc
;
3929 /* The function returns next out arc after ARC. */
3931 next_out_arc (arc_t arc
)
3933 return arc
->next_out_arc
;
3936 /* Initialization of the abstract data. */
3938 initiate_arcs (void)
3940 first_free_arc
= NULL
;
3943 /* Finishing work with the abstract data. */
3951 /* Abstract data `automata lists'. */
3953 /* List of free states. */
3954 static automata_list_el_t first_free_automata_list_el
;
3956 /* The list being formed. */
3957 static automata_list_el_t current_automata_list
;
3959 /* Hash table of automata lists. */
3960 static htab_t automata_list_table
;
3962 /* The following function returns free automata list el. It may be
3963 new allocated node or node freed earlier. */
3964 static automata_list_el_t
3965 get_free_automata_list_el (void)
3967 automata_list_el_t result
;
3969 if (first_free_automata_list_el
!= NULL
)
3971 result
= first_free_automata_list_el
;
3972 first_free_automata_list_el
3973 = first_free_automata_list_el
->next_automata_list_el
;
3976 result
= XCREATENODE (struct automata_list_el
);
3977 result
->automaton
= NULL
;
3978 result
->next_automata_list_el
= NULL
;
3982 /* The function frees node AUTOMATA_LIST_EL. */
3984 free_automata_list_el (automata_list_el_t automata_list_el
)
3986 if (automata_list_el
== NULL
)
3988 automata_list_el
->next_automata_list_el
= first_free_automata_list_el
;
3989 first_free_automata_list_el
= automata_list_el
;
3992 /* The function frees list AUTOMATA_LIST. */
3994 free_automata_list (automata_list_el_t automata_list
)
3996 automata_list_el_t curr_automata_list_el
;
3997 automata_list_el_t next_automata_list_el
;
3999 for (curr_automata_list_el
= automata_list
;
4000 curr_automata_list_el
!= NULL
;
4001 curr_automata_list_el
= next_automata_list_el
)
4003 next_automata_list_el
= curr_automata_list_el
->next_automata_list_el
;
4004 free_automata_list_el (curr_automata_list_el
);
4008 /* Hash value of AUTOMATA_LIST. */
4010 automata_list_hash (const void *automata_list
)
4012 unsigned int hash_value
;
4013 const_automata_list_el_t curr_automata_list_el
;
4016 for (curr_automata_list_el
= (const_automata_list_el_t
) automata_list
;
4017 curr_automata_list_el
!= NULL
;
4018 curr_automata_list_el
= curr_automata_list_el
->next_automata_list_el
)
4019 hash_value
= (((hash_value
>> (sizeof (unsigned) - 1) * CHAR_BIT
)
4020 | (hash_value
<< CHAR_BIT
))
4021 + curr_automata_list_el
->automaton
->automaton_order_num
);
4025 /* Return nonzero value if the automata_lists are the same. */
4027 automata_list_eq_p (const void *automata_list_1
, const void *automata_list_2
)
4029 const_automata_list_el_t automata_list_el_1
;
4030 const_automata_list_el_t automata_list_el_2
;
4032 for (automata_list_el_1
= (const_automata_list_el_t
) automata_list_1
,
4033 automata_list_el_2
= (const_automata_list_el_t
) automata_list_2
;
4034 automata_list_el_1
!= NULL
&& automata_list_el_2
!= NULL
;
4035 automata_list_el_1
= automata_list_el_1
->next_automata_list_el
,
4036 automata_list_el_2
= automata_list_el_2
->next_automata_list_el
)
4037 if (automata_list_el_1
->automaton
!= automata_list_el_2
->automaton
)
4039 return automata_list_el_1
== automata_list_el_2
;
4042 /* Initialization of the abstract data. */
4044 initiate_automata_lists (void)
4046 first_free_automata_list_el
= NULL
;
4047 automata_list_table
= htab_create (1500, automata_list_hash
,
4048 automata_list_eq_p
, (htab_del
) 0);
4051 /* The following function starts new automata list and makes it the
4054 automata_list_start (void)
4056 current_automata_list
= NULL
;
4059 /* The following function adds AUTOMATON to the current list. */
4061 automata_list_add (automaton_t automaton
)
4063 automata_list_el_t el
;
4065 el
= get_free_automata_list_el ();
4066 el
->automaton
= automaton
;
4067 el
->next_automata_list_el
= current_automata_list
;
4068 current_automata_list
= el
;
4071 /* The following function finishes forming the current list, inserts
4072 it into the table and returns it. */
4073 static automata_list_el_t
4074 automata_list_finish (void)
4078 if (current_automata_list
== NULL
)
4080 entry_ptr
= htab_find_slot (automata_list_table
,
4081 (void *) current_automata_list
, 1);
4082 if (*entry_ptr
== NULL
)
4083 *entry_ptr
= (void *) current_automata_list
;
4085 free_automata_list (current_automata_list
);
4086 current_automata_list
= NULL
;
4087 return (automata_list_el_t
) *entry_ptr
;
4090 /* Finishing work with the abstract data. */
4092 finish_automata_lists (void)
4094 htab_delete (automata_list_table
);
4099 /* The page contains abstract data for work with exclusion sets (see
4100 exclusion_set in file rtl.def). */
4102 /* The following variable refers to an exclusion set returned by
4103 get_excl_set. This is bit string of length equal to cpu units
4104 number. If exclusion set for given unit contains 1 for a unit,
4105 then simultaneous reservation of the units is prohibited. */
4106 static reserv_sets_t excl_set
;
4108 /* The array contains exclusion sets for each unit. */
4109 static reserv_sets_t
*unit_excl_set_table
;
4111 /* The following function forms the array containing exclusion sets
4114 initiate_excl_sets (void)
4117 reserv_sets_t unit_excl_set
;
4121 obstack_blank (&irp
, els_in_cycle_reserv
* sizeof (set_el_t
));
4122 excl_set
= (reserv_sets_t
) obstack_base (&irp
);
4123 obstack_finish (&irp
);
4124 obstack_blank (&irp
, description
->units_num
* sizeof (reserv_sets_t
));
4125 unit_excl_set_table
= (reserv_sets_t
*) obstack_base (&irp
);
4126 obstack_finish (&irp
);
4127 /* Evaluate unit exclusion sets. */
4128 for (i
= 0; i
< description
->decls_num
; i
++)
4130 decl
= description
->decls
[i
];
4131 if (decl
->mode
== dm_unit
)
4133 obstack_blank (&irp
, els_in_cycle_reserv
* sizeof (set_el_t
));
4134 unit_excl_set
= (reserv_sets_t
) obstack_base (&irp
);
4135 obstack_finish (&irp
);
4136 memset (unit_excl_set
, 0, els_in_cycle_reserv
* sizeof (set_el_t
));
4137 for (el
= DECL_UNIT (decl
)->excl_list
;
4139 el
= el
->next_unit_set_el
)
4141 SET_BIT (unit_excl_set
, el
->unit_decl
->unit_num
);
4142 el
->unit_decl
->in_set_p
= TRUE
;
4144 unit_excl_set_table
[DECL_UNIT (decl
)->unit_num
] = unit_excl_set
;
4149 /* The function sets up and return EXCL_SET which is union of
4150 exclusion sets for each unit in IN_SET. */
4151 static reserv_sets_t
4152 get_excl_set (reserv_sets_t in_set
)
4160 chars_num
= els_in_cycle_reserv
* sizeof (set_el_t
);
4161 memset (excl_set
, 0, chars_num
);
4162 for (excl_char_num
= 0; excl_char_num
< chars_num
; excl_char_num
++)
4163 if (((unsigned char *) in_set
) [excl_char_num
])
4164 for (i
= CHAR_BIT
- 1; i
>= 0; i
--)
4165 if ((((unsigned char *) in_set
) [excl_char_num
] >> i
) & 1)
4167 start_unit_num
= excl_char_num
* CHAR_BIT
+ i
;
4168 if (start_unit_num
>= description
->units_num
)
4170 for (unit_num
= 0; unit_num
< els_in_cycle_reserv
; unit_num
++)
4173 |= unit_excl_set_table
[start_unit_num
] [unit_num
];
4181 /* The page contains abstract data for work with presence/absence
4182 pattern sets (see presence_set/absence_set in file rtl.def). */
4184 /* The following arrays contain correspondingly presence, final
4185 presence, absence, and final absence patterns for each unit. */
4186 static pattern_reserv_t
*unit_presence_set_table
;
4187 static pattern_reserv_t
*unit_final_presence_set_table
;
4188 static pattern_reserv_t
*unit_absence_set_table
;
4189 static pattern_reserv_t
*unit_final_absence_set_table
;
4191 /* The following function forms list of reservation sets for given
4193 static pattern_reserv_t
4194 form_reserv_sets_list (pattern_set_el_t pattern_list
)
4196 pattern_set_el_t el
;
4197 pattern_reserv_t first
, curr
, prev
;
4200 prev
= first
= NULL
;
4201 for (el
= pattern_list
; el
!= NULL
; el
= el
->next_pattern_set_el
)
4203 curr
= XCREATENODE (struct pattern_reserv
);
4204 curr
->reserv
= alloc_empty_reserv_sets ();
4205 curr
->next_pattern_reserv
= NULL
;
4206 for (i
= 0; i
< el
->units_num
; i
++)
4208 SET_BIT (curr
->reserv
, el
->unit_decls
[i
]->unit_num
);
4209 el
->unit_decls
[i
]->in_set_p
= TRUE
;
4212 prev
->next_pattern_reserv
= curr
;
4220 /* The following function forms the array containing presence and
4221 absence pattern sets for each unit. */
4223 initiate_presence_absence_pattern_sets (void)
4228 obstack_blank (&irp
, description
->units_num
* sizeof (pattern_reserv_t
));
4229 unit_presence_set_table
= (pattern_reserv_t
*) obstack_base (&irp
);
4230 obstack_finish (&irp
);
4231 obstack_blank (&irp
, description
->units_num
* sizeof (pattern_reserv_t
));
4232 unit_final_presence_set_table
= (pattern_reserv_t
*) obstack_base (&irp
);
4233 obstack_finish (&irp
);
4234 obstack_blank (&irp
, description
->units_num
* sizeof (pattern_reserv_t
));
4235 unit_absence_set_table
= (pattern_reserv_t
*) obstack_base (&irp
);
4236 obstack_finish (&irp
);
4237 obstack_blank (&irp
, description
->units_num
* sizeof (pattern_reserv_t
));
4238 unit_final_absence_set_table
= (pattern_reserv_t
*) obstack_base (&irp
);
4239 obstack_finish (&irp
);
4240 /* Evaluate unit presence/absence sets. */
4241 for (i
= 0; i
< description
->decls_num
; i
++)
4243 decl
= description
->decls
[i
];
4244 if (decl
->mode
== dm_unit
)
4246 unit_presence_set_table
[DECL_UNIT (decl
)->unit_num
]
4247 = form_reserv_sets_list (DECL_UNIT (decl
)->presence_list
);
4248 unit_final_presence_set_table
[DECL_UNIT (decl
)->unit_num
]
4249 = form_reserv_sets_list (DECL_UNIT (decl
)->final_presence_list
);
4250 unit_absence_set_table
[DECL_UNIT (decl
)->unit_num
]
4251 = form_reserv_sets_list (DECL_UNIT (decl
)->absence_list
);
4252 unit_final_absence_set_table
[DECL_UNIT (decl
)->unit_num
]
4253 = form_reserv_sets_list (DECL_UNIT (decl
)->final_absence_list
);
4258 /* The function checks that CHECKED_SET satisfies all presence pattern
4259 sets for units in ORIGINAL_SET. The function returns TRUE if it
4262 check_presence_pattern_sets (reserv_sets_t checked_set
,
4263 reserv_sets_t original_set
,
4272 pattern_reserv_t pat_reserv
;
4274 chars_num
= els_in_cycle_reserv
* sizeof (set_el_t
);
4275 for (char_num
= 0; char_num
< chars_num
; char_num
++)
4276 if (((unsigned char *) original_set
) [char_num
])
4277 for (i
= CHAR_BIT
- 1; i
>= 0; i
--)
4278 if ((((unsigned char *) original_set
) [char_num
] >> i
) & 1)
4280 start_unit_num
= char_num
* CHAR_BIT
+ i
;
4281 if (start_unit_num
>= description
->units_num
)
4284 && unit_final_presence_set_table
[start_unit_num
] == NULL
)
4286 && unit_presence_set_table
[start_unit_num
] == NULL
))
4289 for (pat_reserv
= (final_p
4290 ? unit_final_presence_set_table
[start_unit_num
]
4291 : unit_presence_set_table
[start_unit_num
]);
4293 pat_reserv
= pat_reserv
->next_pattern_reserv
)
4295 for (unit_num
= 0; unit_num
< els_in_cycle_reserv
; unit_num
++)
4296 if ((checked_set
[unit_num
] & pat_reserv
->reserv
[unit_num
])
4297 != pat_reserv
->reserv
[unit_num
])
4299 presence_p
= presence_p
|| unit_num
>= els_in_cycle_reserv
;
4307 /* The function checks that CHECKED_SET satisfies all absence pattern
4308 sets for units in ORIGINAL_SET. The function returns TRUE if it
4311 check_absence_pattern_sets (reserv_sets_t checked_set
,
4312 reserv_sets_t original_set
,
4320 pattern_reserv_t pat_reserv
;
4322 chars_num
= els_in_cycle_reserv
* sizeof (set_el_t
);
4323 for (char_num
= 0; char_num
< chars_num
; char_num
++)
4324 if (((unsigned char *) original_set
) [char_num
])
4325 for (i
= CHAR_BIT
- 1; i
>= 0; i
--)
4326 if ((((unsigned char *) original_set
) [char_num
] >> i
) & 1)
4328 start_unit_num
= char_num
* CHAR_BIT
+ i
;
4329 if (start_unit_num
>= description
->units_num
)
4331 for (pat_reserv
= (final_p
4332 ? unit_final_absence_set_table
[start_unit_num
]
4333 : unit_absence_set_table
[start_unit_num
]);
4335 pat_reserv
= pat_reserv
->next_pattern_reserv
)
4337 for (unit_num
= 0; unit_num
< els_in_cycle_reserv
; unit_num
++)
4338 if ((checked_set
[unit_num
] & pat_reserv
->reserv
[unit_num
])
4339 != pat_reserv
->reserv
[unit_num
]
4340 && pat_reserv
->reserv
[unit_num
])
4342 if (unit_num
>= els_in_cycle_reserv
)
4351 /* This page contains code for transformation of original reservations
4352 described in .md file. The main goal of transformations is
4353 simplifying reservation and lifting up all `|' on the top of IR
4354 reservation representation. */
4357 /* The following function makes copy of IR representation of
4358 reservation. The function also substitutes all reservations
4359 defined by define_reservation by corresponding value during making
4362 copy_insn_regexp (regexp_t regexp
)
4367 switch (regexp
->mode
)
4370 result
= copy_insn_regexp (REGEXP_RESERV (regexp
)->reserv_decl
->regexp
);
4374 result
= XCOPYNODE (struct regexp
, regexp
);
4378 result
= XCOPYNODE (struct regexp
, regexp
);
4379 REGEXP_REPEAT (result
)->regexp
4380 = copy_insn_regexp (REGEXP_REPEAT (regexp
)->regexp
);
4384 result
= XCOPYNODEVAR (struct regexp
, regexp
,
4385 sizeof (struct regexp
) + sizeof (regexp_t
)
4386 * (REGEXP_SEQUENCE (regexp
)->regexps_num
- 1));
4387 for (i
= 0; i
<REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
4388 REGEXP_SEQUENCE (result
)->regexps
[i
]
4389 = copy_insn_regexp (REGEXP_SEQUENCE (regexp
)->regexps
[i
]);
4393 result
= XCOPYNODEVAR (struct regexp
, regexp
,
4394 sizeof (struct regexp
) + sizeof (regexp_t
)
4395 * (REGEXP_ALLOF (regexp
)->regexps_num
- 1));
4396 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
4397 REGEXP_ALLOF (result
)->regexps
[i
]
4398 = copy_insn_regexp (REGEXP_ALLOF (regexp
)->regexps
[i
]);
4402 result
= XCOPYNODEVAR (struct regexp
, regexp
,
4403 sizeof (struct regexp
) + sizeof (regexp_t
)
4404 * (REGEXP_ONEOF (regexp
)->regexps_num
- 1));
4405 for (i
= 0; i
< REGEXP_ONEOF (regexp
)->regexps_num
; i
++)
4406 REGEXP_ONEOF (result
)->regexps
[i
]
4407 = copy_insn_regexp (REGEXP_ONEOF (regexp
)->regexps
[i
]);
4411 result
= XCOPYNODE (struct regexp
, regexp
);
4420 /* The following variable is set up 1 if a transformation has been
4422 static int regexp_transformed_p
;
4424 /* The function makes transformation
4427 transform_1 (regexp_t regexp
)
4434 if (regexp
->mode
== rm_repeat
)
4436 repeat_num
= REGEXP_REPEAT (regexp
)->repeat_num
;
4437 gcc_assert (repeat_num
> 1);
4438 operand
= REGEXP_REPEAT (regexp
)->regexp
;
4440 regexp
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4441 + sizeof (regexp_t
) * (repeat_num
- 1));
4442 regexp
->mode
= rm_sequence
;
4444 REGEXP_SEQUENCE (regexp
)->regexps_num
= repeat_num
;
4445 for (i
= 0; i
< repeat_num
; i
++)
4446 REGEXP_SEQUENCE (regexp
)->regexps
[i
] = copy_insn_regexp (operand
);
4447 regexp_transformed_p
= 1;
4452 /* The function makes transformations
4453 ...,(A,B,...),C,... -> ...,A,B,...,C,...
4454 ...+(A+B+...)+C+... -> ...+A+B+...+C+...
4455 ...|(A|B|...)|C|... -> ...|A|B|...|C|... */
4457 transform_2 (regexp_t regexp
)
4459 if (regexp
->mode
== rm_sequence
)
4461 regexp_t sequence
= NULL
;
4463 int sequence_index
= 0;
4466 for (i
= 0; i
< REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
4467 if (REGEXP_SEQUENCE (regexp
)->regexps
[i
]->mode
== rm_sequence
)
4470 sequence
= REGEXP_SEQUENCE (regexp
)->regexps
[i
];
4473 if (i
< REGEXP_SEQUENCE (regexp
)->regexps_num
)
4475 gcc_assert (REGEXP_SEQUENCE (sequence
)->regexps_num
> 1
4476 && REGEXP_SEQUENCE (regexp
)->regexps_num
> 1);
4477 result
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4479 * (REGEXP_SEQUENCE (regexp
)->regexps_num
4480 + REGEXP_SEQUENCE (sequence
)->regexps_num
4482 result
->mode
= rm_sequence
;
4483 result
->pos
= regexp
->pos
;
4484 REGEXP_SEQUENCE (result
)->regexps_num
4485 = (REGEXP_SEQUENCE (regexp
)->regexps_num
4486 + REGEXP_SEQUENCE (sequence
)->regexps_num
- 1);
4487 for (i
= 0; i
< REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
4488 if (i
< sequence_index
)
4489 REGEXP_SEQUENCE (result
)->regexps
[i
]
4490 = copy_insn_regexp (REGEXP_SEQUENCE (regexp
)->regexps
[i
]);
4491 else if (i
> sequence_index
)
4492 REGEXP_SEQUENCE (result
)->regexps
4493 [i
+ REGEXP_SEQUENCE (sequence
)->regexps_num
- 1]
4494 = copy_insn_regexp (REGEXP_SEQUENCE (regexp
)->regexps
[i
]);
4496 for (j
= 0; j
< REGEXP_SEQUENCE (sequence
)->regexps_num
; j
++)
4497 REGEXP_SEQUENCE (result
)->regexps
[i
+ j
]
4498 = copy_insn_regexp (REGEXP_SEQUENCE (sequence
)->regexps
[j
]);
4499 regexp_transformed_p
= 1;
4503 else if (regexp
->mode
== rm_allof
)
4505 regexp_t allof
= NULL
;
4507 int allof_index
= 0;
4510 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
4511 if (REGEXP_ALLOF (regexp
)->regexps
[i
]->mode
== rm_allof
)
4514 allof
= REGEXP_ALLOF (regexp
)->regexps
[i
];
4517 if (i
< REGEXP_ALLOF (regexp
)->regexps_num
)
4519 gcc_assert (REGEXP_ALLOF (allof
)->regexps_num
> 1
4520 && REGEXP_ALLOF (regexp
)->regexps_num
> 1);
4521 result
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4523 * (REGEXP_ALLOF (regexp
)->regexps_num
4524 + REGEXP_ALLOF (allof
)->regexps_num
- 2));
4525 result
->mode
= rm_allof
;
4526 result
->pos
= regexp
->pos
;
4527 REGEXP_ALLOF (result
)->regexps_num
4528 = (REGEXP_ALLOF (regexp
)->regexps_num
4529 + REGEXP_ALLOF (allof
)->regexps_num
- 1);
4530 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
4531 if (i
< allof_index
)
4532 REGEXP_ALLOF (result
)->regexps
[i
]
4533 = copy_insn_regexp (REGEXP_ALLOF (regexp
)->regexps
[i
]);
4534 else if (i
> allof_index
)
4535 REGEXP_ALLOF (result
)->regexps
4536 [i
+ REGEXP_ALLOF (allof
)->regexps_num
- 1]
4537 = copy_insn_regexp (REGEXP_ALLOF (regexp
)->regexps
[i
]);
4539 for (j
= 0; j
< REGEXP_ALLOF (allof
)->regexps_num
; j
++)
4540 REGEXP_ALLOF (result
)->regexps
[i
+ j
]
4541 = copy_insn_regexp (REGEXP_ALLOF (allof
)->regexps
[j
]);
4542 regexp_transformed_p
= 1;
4546 else if (regexp
->mode
== rm_oneof
)
4548 regexp_t oneof
= NULL
;
4550 int oneof_index
= 0;
4553 for (i
= 0; i
< REGEXP_ONEOF (regexp
)->regexps_num
; i
++)
4554 if (REGEXP_ONEOF (regexp
)->regexps
[i
]->mode
== rm_oneof
)
4557 oneof
= REGEXP_ONEOF (regexp
)->regexps
[i
];
4560 if (i
< REGEXP_ONEOF (regexp
)->regexps_num
)
4562 gcc_assert (REGEXP_ONEOF (oneof
)->regexps_num
> 1
4563 && REGEXP_ONEOF (regexp
)->regexps_num
> 1);
4564 result
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4566 * (REGEXP_ONEOF (regexp
)->regexps_num
4567 + REGEXP_ONEOF (oneof
)->regexps_num
- 2));
4568 result
->mode
= rm_oneof
;
4569 result
->pos
= regexp
->pos
;
4570 REGEXP_ONEOF (result
)->regexps_num
4571 = (REGEXP_ONEOF (regexp
)->regexps_num
4572 + REGEXP_ONEOF (oneof
)->regexps_num
- 1);
4573 for (i
= 0; i
< REGEXP_ONEOF (regexp
)->regexps_num
; i
++)
4574 if (i
< oneof_index
)
4575 REGEXP_ONEOF (result
)->regexps
[i
]
4576 = copy_insn_regexp (REGEXP_ONEOF (regexp
)->regexps
[i
]);
4577 else if (i
> oneof_index
)
4578 REGEXP_ONEOF (result
)->regexps
4579 [i
+ REGEXP_ONEOF (oneof
)->regexps_num
- 1]
4580 = copy_insn_regexp (REGEXP_ONEOF (regexp
)->regexps
[i
]);
4582 for (j
= 0; j
< REGEXP_ONEOF (oneof
)->regexps_num
; j
++)
4583 REGEXP_ONEOF (result
)->regexps
[i
+ j
]
4584 = copy_insn_regexp (REGEXP_ONEOF (oneof
)->regexps
[j
]);
4585 regexp_transformed_p
= 1;
4592 /* The function makes transformations
4593 ...,A|B|...,C,... -> (...,A,C,...)|(...,B,C,...)|...
4594 ...+(A|B|...)+C+... -> (...+A+C+...)|(...+B+C+...)|...
4595 ...+(A,B,...)+C+... -> (...+A+C+...),B,...
4596 ...+(A,B,...)+(C,D,...) -> (A+C),(B+D),... */
4598 transform_3 (regexp_t regexp
)
4600 if (regexp
->mode
== rm_sequence
)
4602 regexp_t oneof
= NULL
;
4603 int oneof_index
= 0;
4608 for (i
= 0; i
<REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
4609 if (REGEXP_SEQUENCE (regexp
)->regexps
[i
]->mode
== rm_oneof
)
4612 oneof
= REGEXP_SEQUENCE (regexp
)->regexps
[i
];
4615 if (i
< REGEXP_SEQUENCE (regexp
)->regexps_num
)
4617 gcc_assert (REGEXP_ONEOF (oneof
)->regexps_num
> 1
4618 && REGEXP_SEQUENCE (regexp
)->regexps_num
> 1);
4619 result
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4621 * (REGEXP_ONEOF (oneof
)->regexps_num
- 1));
4622 result
->mode
= rm_oneof
;
4623 result
->pos
= regexp
->pos
;
4624 REGEXP_ONEOF (result
)->regexps_num
4625 = REGEXP_ONEOF (oneof
)->regexps_num
;
4626 for (i
= 0; i
< REGEXP_ONEOF (result
)->regexps_num
; i
++)
4629 = XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4631 * (REGEXP_SEQUENCE (regexp
)->regexps_num
- 1));
4632 sequence
->mode
= rm_sequence
;
4633 sequence
->pos
= regexp
->pos
;
4634 REGEXP_SEQUENCE (sequence
)->regexps_num
4635 = REGEXP_SEQUENCE (regexp
)->regexps_num
;
4636 REGEXP_ONEOF (result
)->regexps
[i
] = sequence
;
4637 for (j
= 0; j
< REGEXP_SEQUENCE (sequence
)->regexps_num
; j
++)
4638 if (j
!= oneof_index
)
4639 REGEXP_SEQUENCE (sequence
)->regexps
[j
]
4640 = copy_insn_regexp (REGEXP_SEQUENCE (regexp
)->regexps
[j
]);
4642 REGEXP_SEQUENCE (sequence
)->regexps
[j
]
4643 = copy_insn_regexp (REGEXP_ONEOF (oneof
)->regexps
[i
]);
4645 regexp_transformed_p
= 1;
4649 else if (regexp
->mode
== rm_allof
)
4651 regexp_t oneof
= NULL
;
4653 int oneof_index
= 0;
4654 int max_seq_length
, allof_length
;
4656 regexp_t allof
= NULL
;
4657 regexp_t allof_op
= NULL
;
4660 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
4661 if (REGEXP_ALLOF (regexp
)->regexps
[i
]->mode
== rm_oneof
)
4664 oneof
= REGEXP_ALLOF (regexp
)->regexps
[i
];
4667 if (i
< REGEXP_ALLOF (regexp
)->regexps_num
)
4669 gcc_assert (REGEXP_ONEOF (oneof
)->regexps_num
> 1
4670 && REGEXP_ALLOF (regexp
)->regexps_num
> 1);
4671 result
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4673 * (REGEXP_ONEOF (oneof
)->regexps_num
- 1));
4674 result
->mode
= rm_oneof
;
4675 result
->pos
= regexp
->pos
;
4676 REGEXP_ONEOF (result
)->regexps_num
4677 = REGEXP_ONEOF (oneof
)->regexps_num
;
4678 for (i
= 0; i
< REGEXP_ONEOF (result
)->regexps_num
; i
++)
4681 = XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4683 * (REGEXP_ALLOF (regexp
)->regexps_num
- 1));
4684 allof
->mode
= rm_allof
;
4685 allof
->pos
= regexp
->pos
;
4686 REGEXP_ALLOF (allof
)->regexps_num
4687 = REGEXP_ALLOF (regexp
)->regexps_num
;
4688 REGEXP_ONEOF (result
)->regexps
[i
] = allof
;
4689 for (j
= 0; j
< REGEXP_ALLOF (allof
)->regexps_num
; j
++)
4690 if (j
!= oneof_index
)
4691 REGEXP_ALLOF (allof
)->regexps
[j
]
4692 = copy_insn_regexp (REGEXP_ALLOF (regexp
)->regexps
[j
]);
4694 REGEXP_ALLOF (allof
)->regexps
[j
]
4695 = copy_insn_regexp (REGEXP_ONEOF (oneof
)->regexps
[i
]);
4697 regexp_transformed_p
= 1;
4701 if (regexp
->mode
== rm_allof
)
4702 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
4704 switch (REGEXP_ALLOF (regexp
)->regexps
[i
]->mode
)
4707 seq
= REGEXP_ALLOF (regexp
)->regexps
[i
];
4708 if (max_seq_length
< REGEXP_SEQUENCE (seq
)->regexps_num
)
4709 max_seq_length
= REGEXP_SEQUENCE (seq
)->regexps_num
;
4722 if (max_seq_length
!= 0)
4724 gcc_assert (max_seq_length
!= 1
4725 && REGEXP_ALLOF (regexp
)->regexps_num
> 1);
4726 result
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4727 + sizeof (regexp_t
) * (max_seq_length
- 1));
4728 result
->mode
= rm_sequence
;
4729 result
->pos
= regexp
->pos
;
4730 REGEXP_SEQUENCE (result
)->regexps_num
= max_seq_length
;
4731 for (i
= 0; i
< max_seq_length
; i
++)
4734 for (j
= 0; j
< REGEXP_ALLOF (regexp
)->regexps_num
; j
++)
4735 switch (REGEXP_ALLOF (regexp
)->regexps
[j
]->mode
)
4738 if (i
< (REGEXP_SEQUENCE (REGEXP_ALLOF (regexp
)
4739 ->regexps
[j
])->regexps_num
))
4742 = (REGEXP_SEQUENCE (REGEXP_ALLOF (regexp
)
4752 allof_op
= REGEXP_ALLOF (regexp
)->regexps
[j
];
4760 if (allof_length
== 1)
4761 REGEXP_SEQUENCE (result
)->regexps
[i
] = allof_op
;
4764 allof
= XCREATENODEVAR (struct regexp
, sizeof (struct regexp
)
4766 * (allof_length
- 1));
4767 allof
->mode
= rm_allof
;
4768 allof
->pos
= regexp
->pos
;
4769 REGEXP_ALLOF (allof
)->regexps_num
= allof_length
;
4770 REGEXP_SEQUENCE (result
)->regexps
[i
] = allof
;
4772 for (j
= 0; j
< REGEXP_ALLOF (regexp
)->regexps_num
; j
++)
4773 if (REGEXP_ALLOF (regexp
)->regexps
[j
]->mode
== rm_sequence
4775 (REGEXP_SEQUENCE (REGEXP_ALLOF (regexp
)
4776 ->regexps
[j
])->regexps_num
)))
4778 allof_op
= (REGEXP_SEQUENCE (REGEXP_ALLOF (regexp
)
4781 REGEXP_ALLOF (allof
)->regexps
[allof_length
]
4786 && (REGEXP_ALLOF (regexp
)->regexps
[j
]->mode
4788 || (REGEXP_ALLOF (regexp
)->regexps
[j
]->mode
4791 allof_op
= REGEXP_ALLOF (regexp
)->regexps
[j
];
4792 REGEXP_ALLOF (allof
)->regexps
[allof_length
]
4798 regexp_transformed_p
= 1;
4805 /* The function traverses IR of reservation and applies transformations
4806 implemented by FUNC. */
4808 regexp_transform_func (regexp_t regexp
, regexp_t (*func
) (regexp_t regexp
))
4812 switch (regexp
->mode
)
4815 for (i
= 0; i
< REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
4816 REGEXP_SEQUENCE (regexp
)->regexps
[i
]
4817 = regexp_transform_func (REGEXP_SEQUENCE (regexp
)->regexps
[i
],
4822 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
4823 REGEXP_ALLOF (regexp
)->regexps
[i
]
4824 = regexp_transform_func (REGEXP_ALLOF (regexp
)->regexps
[i
], func
);
4828 for (i
= 0; i
< REGEXP_ONEOF (regexp
)->regexps_num
; i
++)
4829 REGEXP_ONEOF (regexp
)->regexps
[i
]
4830 = regexp_transform_func (REGEXP_ONEOF (regexp
)->regexps
[i
], func
);
4834 REGEXP_REPEAT (regexp
)->regexp
4835 = regexp_transform_func (REGEXP_REPEAT (regexp
)->regexp
, func
);
4845 return (*func
) (regexp
);
4848 /* The function applies all transformations for IR representation of
4849 reservation REGEXP. */
4851 transform_regexp (regexp_t regexp
)
4853 regexp
= regexp_transform_func (regexp
, transform_1
);
4856 regexp_transformed_p
= 0;
4857 regexp
= regexp_transform_func (regexp
, transform_2
);
4858 regexp
= regexp_transform_func (regexp
, transform_3
);
4860 while (regexp_transformed_p
);
4864 /* The function applies all transformations for reservations of all
4865 insn declarations. */
4867 transform_insn_regexps (void)
4872 transform_time
= create_ticker ();
4873 add_advance_cycle_insn_decl ();
4875 fprintf (stderr
, "Reservation transformation...");
4876 for (i
= 0; i
< description
->decls_num
; i
++)
4878 decl
= description
->decls
[i
];
4879 if (decl
->mode
== dm_insn_reserv
&& decl
!= advance_cycle_insn_decl
)
4880 DECL_INSN_RESERV (decl
)->transformed_regexp
4881 = transform_regexp (copy_insn_regexp
4882 (DECL_INSN_RESERV (decl
)->regexp
));
4885 fprintf (stderr
, "done\n");
4886 ticker_off (&transform_time
);
4891 /* The following variable value is TRUE if the first annotated message
4892 about units to automata distribution has been output. */
4893 static int annotation_message_reported_p
;
4895 /* The following structure describes usage of a unit in a reservation. */
4898 unit_decl_t unit_decl
;
4899 /* The following forms a list of units used on the same cycle in the
4900 same alternative. */
4901 struct unit_usage
*next
;
4903 typedef struct unit_usage
*unit_usage_t
;
4905 DEF_VEC_P(unit_usage_t
);
4906 DEF_VEC_ALLOC_P(unit_usage_t
,heap
);
4908 /* Obstack for unit_usage structures. */
4909 static struct obstack unit_usages
;
4911 /* VLA for representation of array of pointers to unit usage
4912 structures. There is an element for each combination of
4913 (alternative number, cycle). Unit usages on given cycle in
4914 alternative with given number are referred through element with
4915 index equals to the cycle * number of all alternatives in the regexp
4916 + the alternative number. */
4917 static VEC(unit_usage_t
,heap
) *cycle_alt_unit_usages
;
4919 /* The following function creates the structure unit_usage for UNIT on
4920 CYCLE in REGEXP alternative with ALT_NUM. The structure is made
4921 accessed through cycle_alt_unit_usages. */
4923 store_alt_unit_usage (regexp_t regexp
, regexp_t unit
, int cycle
,
4927 unit_decl_t unit_decl
;
4928 unit_usage_t unit_usage_ptr
;
4931 gcc_assert (regexp
&& regexp
->mode
== rm_oneof
4932 && alt_num
< REGEXP_ONEOF (regexp
)->regexps_num
);
4933 unit_decl
= REGEXP_UNIT (unit
)->unit_decl
;
4935 length
= (cycle
+ 1) * REGEXP_ONEOF (regexp
)->regexps_num
;
4936 while (VEC_length (unit_usage_t
, cycle_alt_unit_usages
) < length
)
4937 VEC_safe_push (unit_usage_t
,heap
, cycle_alt_unit_usages
, 0);
4939 obstack_blank (&unit_usages
, sizeof (struct unit_usage
));
4940 unit_usage_ptr
= (struct unit_usage
*) obstack_base (&unit_usages
);
4941 obstack_finish (&unit_usages
);
4942 unit_usage_ptr
->unit_decl
= unit_decl
;
4943 index
= cycle
* REGEXP_ONEOF (regexp
)->regexps_num
+ alt_num
;
4944 unit_usage_ptr
->next
= VEC_index (unit_usage_t
, cycle_alt_unit_usages
, index
);
4945 VEC_replace (unit_usage_t
, cycle_alt_unit_usages
, index
, unit_usage_ptr
);
4946 unit_decl
->last_distribution_check_cycle
= -1; /* undefined */
4949 /* The function processes given REGEXP to find units with the wrong
4952 check_regexp_units_distribution (const char *insn_reserv_name
,
4956 regexp_t seq
, allof
, unit
;
4957 struct unit_usage
*unit_usage_ptr
, *other_unit_usage_ptr
;
4959 if (regexp
== NULL
|| regexp
->mode
!= rm_oneof
)
4961 /* Store all unit usages in the regexp: */
4962 obstack_init (&unit_usages
);
4963 cycle_alt_unit_usages
= 0;
4965 for (i
= REGEXP_ONEOF (regexp
)->regexps_num
- 1; i
>= 0; i
--)
4967 seq
= REGEXP_ONEOF (regexp
)->regexps
[i
];
4971 for (j
= 0; j
< REGEXP_SEQUENCE (seq
)->regexps_num
; j
++)
4973 allof
= REGEXP_SEQUENCE (seq
)->regexps
[j
];
4974 switch (allof
->mode
)
4977 for (k
= 0; k
< REGEXP_ALLOF (allof
)->regexps_num
; k
++)
4979 unit
= REGEXP_ALLOF (allof
)->regexps
[k
];
4980 if (unit
->mode
== rm_unit
)
4981 store_alt_unit_usage (regexp
, unit
, j
, i
);
4983 gcc_assert (unit
->mode
== rm_nothing
);
4988 store_alt_unit_usage (regexp
, allof
, j
, i
);
5001 for (k
= 0; k
< REGEXP_ALLOF (seq
)->regexps_num
; k
++)
5003 unit
= REGEXP_ALLOF (seq
)->regexps
[k
];
5007 store_alt_unit_usage (regexp
, unit
, 0, i
);
5020 store_alt_unit_usage (regexp
, seq
, 0, i
);
5030 /* Check distribution: */
5031 for (i
= 0; i
< (int) VEC_length (unit_usage_t
, cycle_alt_unit_usages
); i
++)
5033 cycle
= i
/ REGEXP_ONEOF (regexp
)->regexps_num
;
5034 for (unit_usage_ptr
= VEC_index (unit_usage_t
, cycle_alt_unit_usages
, i
);
5035 unit_usage_ptr
!= NULL
;
5036 unit_usage_ptr
= unit_usage_ptr
->next
)
5037 if (cycle
!= unit_usage_ptr
->unit_decl
->last_distribution_check_cycle
)
5039 unit_usage_ptr
->unit_decl
->last_distribution_check_cycle
= cycle
;
5040 for (k
= cycle
* REGEXP_ONEOF (regexp
)->regexps_num
;
5041 k
< (int) VEC_length (unit_usage_t
, cycle_alt_unit_usages
)
5042 && k
== cycle
* REGEXP_ONEOF (regexp
)->regexps_num
;
5045 for (other_unit_usage_ptr
5046 = VEC_index (unit_usage_t
, cycle_alt_unit_usages
, k
);
5047 other_unit_usage_ptr
!= NULL
;
5048 other_unit_usage_ptr
= other_unit_usage_ptr
->next
)
5049 if (unit_usage_ptr
->unit_decl
->automaton_decl
5050 == other_unit_usage_ptr
->unit_decl
->automaton_decl
)
5052 if (other_unit_usage_ptr
== NULL
5053 && (VEC_index (unit_usage_t
, cycle_alt_unit_usages
, k
)
5057 if (k
< (int) VEC_length (unit_usage_t
, cycle_alt_unit_usages
)
5058 && k
== cycle
* REGEXP_ONEOF (regexp
)->regexps_num
)
5060 if (!annotation_message_reported_p
)
5062 fprintf (stderr
, "\n");
5063 error ("The following units do not satisfy units-automata distribution rule");
5064 error (" (A unit of given unit automaton should be on each reserv. altern.)");
5065 annotation_message_reported_p
= TRUE
;
5067 error ("Unit %s, reserv. %s, cycle %d",
5068 unit_usage_ptr
->unit_decl
->name
, insn_reserv_name
,
5073 VEC_free (unit_usage_t
,heap
, cycle_alt_unit_usages
);
5074 obstack_free (&unit_usages
, NULL
);
5077 /* The function finds units which violates units to automata
5078 distribution rule. If the units exist, report about them. */
5080 check_unit_distributions_to_automata (void)
5086 fprintf (stderr
, "Check unit distributions to automata...");
5087 annotation_message_reported_p
= FALSE
;
5088 for (i
= 0; i
< description
->decls_num
; i
++)
5090 decl
= description
->decls
[i
];
5091 if (decl
->mode
== dm_insn_reserv
)
5092 check_regexp_units_distribution
5093 (DECL_INSN_RESERV (decl
)->name
,
5094 DECL_INSN_RESERV (decl
)->transformed_regexp
);
5097 fprintf (stderr
, "done\n");
5102 /* The page contains code for building alt_states (see comments for
5103 IR) describing all possible insns reservations of an automaton. */
5105 /* Current state being formed for which the current alt_state
5107 static state_t state_being_formed
;
5109 /* Current alt_state being formed. */
5110 static alt_state_t alt_state_being_formed
;
5112 /* This recursive function processes `,' and units in reservation
5113 REGEXP for forming alt_states of AUTOMATON. It is believed that
5114 CURR_CYCLE is start cycle of all reservation REGEXP. */
5116 process_seq_for_forming_states (regexp_t regexp
, automaton_t automaton
,
5124 switch (regexp
->mode
)
5127 if (REGEXP_UNIT (regexp
)->unit_decl
->corresponding_automaton_num
5128 == automaton
->automaton_order_num
)
5129 set_state_reserv (state_being_formed
, curr_cycle
,
5130 REGEXP_UNIT (regexp
)->unit_decl
->unit_num
);
5134 for (i
= 0; i
< REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
5136 = process_seq_for_forming_states
5137 (REGEXP_SEQUENCE (regexp
)->regexps
[i
], automaton
, curr_cycle
) + 1;
5142 int finish_cycle
= 0;
5145 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
5147 cycle
= process_seq_for_forming_states (REGEXP_ALLOF (regexp
)
5149 automaton
, curr_cycle
);
5150 if (finish_cycle
< cycle
)
5151 finish_cycle
= cycle
;
5153 return finish_cycle
;
5164 /* This recursive function finishes forming ALT_STATE of AUTOMATON and
5165 inserts alt_state into the table. */
5167 finish_forming_alt_state (alt_state_t alt_state
,
5168 automaton_t automaton ATTRIBUTE_UNUSED
)
5170 state_t state_in_table
;
5171 state_t corresponding_state
;
5173 corresponding_state
= alt_state
->state
;
5174 state_in_table
= insert_state (corresponding_state
);
5175 if (state_in_table
!= corresponding_state
)
5177 free_state (corresponding_state
);
5178 alt_state
->state
= state_in_table
;
5182 /* The following variable value is current automaton insn for whose
5183 reservation the alt states are created. */
5184 static ainsn_t curr_ainsn
;
5186 /* This recursive function processes `|' in reservation REGEXP for
5187 forming alt_states of AUTOMATON. List of the alt states should
5188 have the same order as in the description. */
5190 process_alts_for_forming_states (regexp_t regexp
, automaton_t automaton
,
5195 if (regexp
->mode
!= rm_oneof
)
5197 alt_state_being_formed
= get_free_alt_state ();
5198 state_being_formed
= get_free_state (1, automaton
);
5199 alt_state_being_formed
->state
= state_being_formed
;
5200 /* We inserts in reverse order but we process alternatives also
5201 in reverse order. So we have the same order of alternative
5202 as in the description. */
5203 alt_state_being_formed
->next_alt_state
= curr_ainsn
->alt_states
;
5204 curr_ainsn
->alt_states
= alt_state_being_formed
;
5205 (void) process_seq_for_forming_states (regexp
, automaton
, 0);
5206 finish_forming_alt_state (alt_state_being_formed
, automaton
);
5210 gcc_assert (!inside_oneof_p
);
5211 /* We processes it in reverse order to get list with the same
5212 order as in the description. See also the previous
5214 for (i
= REGEXP_ONEOF (regexp
)->regexps_num
- 1; i
>= 0; i
--)
5215 process_alts_for_forming_states (REGEXP_ONEOF (regexp
)->regexps
[i
],
5220 /* Create nodes alt_state for all AUTOMATON insns. */
5222 create_alt_states (automaton_t automaton
)
5224 struct insn_reserv_decl
*reserv_decl
;
5226 for (curr_ainsn
= automaton
->ainsn_list
;
5228 curr_ainsn
= curr_ainsn
->next_ainsn
)
5230 reserv_decl
= curr_ainsn
->insn_reserv_decl
;
5231 if (reserv_decl
!= DECL_INSN_RESERV (advance_cycle_insn_decl
))
5233 curr_ainsn
->alt_states
= NULL
;
5234 process_alts_for_forming_states (reserv_decl
->transformed_regexp
,
5236 curr_ainsn
->sorted_alt_states
5237 = uniq_sort_alt_states (curr_ainsn
->alt_states
);
5244 /* The page contains major code for building DFA(s) for fast pipeline
5245 hazards recognition. */
5247 /* The function forms list of ainsns of AUTOMATON with the same
5251 form_ainsn_with_same_reservs (automaton_t automaton
)
5255 VEC(ainsn_t
,heap
) *last_insns
= VEC_alloc (ainsn_t
,heap
, 150);
5257 for (curr_ainsn
= automaton
->ainsn_list
;
5259 curr_ainsn
= curr_ainsn
->next_ainsn
)
5260 if (curr_ainsn
->insn_reserv_decl
5261 == DECL_INSN_RESERV (advance_cycle_insn_decl
))
5263 curr_ainsn
->next_same_reservs_insn
= NULL
;
5264 curr_ainsn
->first_insn_with_same_reservs
= 1;
5268 for (i
= 0; i
< VEC_length (ainsn_t
, last_insns
); i
++)
5270 (curr_ainsn
->sorted_alt_states
,
5271 VEC_index (ainsn_t
, last_insns
, i
)->sorted_alt_states
))
5273 curr_ainsn
->next_same_reservs_insn
= NULL
;
5274 if (i
< VEC_length (ainsn_t
, last_insns
))
5276 curr_ainsn
->first_insn_with_same_reservs
= 0;
5277 VEC_index (ainsn_t
, last_insns
, i
)->next_same_reservs_insn
5279 VEC_replace (ainsn_t
, last_insns
, i
, curr_ainsn
);
5283 VEC_safe_push (ainsn_t
, heap
, last_insns
, curr_ainsn
);
5284 curr_ainsn
->first_insn_with_same_reservs
= 1;
5287 VEC_free (ainsn_t
,heap
, last_insns
);
5290 /* Forming unit reservations which can affect creating the automaton
5291 states achieved from a given state. It permits to build smaller
5292 automata in many cases. We would have the same automata after
5293 the minimization without such optimization, but the automaton
5294 right after the building could be huge. So in other words, usage
5295 of reservs_matter means some minimization during building the
5297 static reserv_sets_t
5298 form_reservs_matter (automaton_t automaton
)
5301 reserv_sets_t reservs_matter
= alloc_empty_reserv_sets();
5303 for (cycle
= 0; cycle
< max_cycles_num
; cycle
++)
5304 for (unit
= 0; unit
< description
->units_num
; unit
++)
5305 if (units_array
[unit
]->automaton_decl
5306 == automaton
->corresponding_automaton_decl
5307 && (cycle
>= units_array
[unit
]->min_occ_cycle_num
5308 /* We can not remove queried unit from reservations. */
5309 || units_array
[unit
]->query_p
5310 /* We can not remove units which are used
5311 `exclusion_set', `presence_set',
5312 `final_presence_set', `absence_set', and
5313 `final_absence_set'. */
5314 || units_array
[unit
]->in_set_p
))
5315 set_unit_reserv (reservs_matter
, cycle
, unit
);
5316 return reservs_matter
;
5319 /* The following function creates all states of nondeterministic AUTOMATON. */
5321 make_automaton (automaton_t automaton
)
5324 struct insn_reserv_decl
*insn_reserv_decl
;
5325 alt_state_t alt_state
;
5327 state_t start_state
;
5329 ainsn_t advance_cycle_ainsn
;
5331 VEC(state_t
,heap
) *state_stack
= VEC_alloc(state_t
,heap
, 150);
5333 reserv_sets_t reservs_matter
= form_reservs_matter (automaton
);
5335 /* Create the start state (empty state). */
5336 start_state
= insert_state (get_free_state (1, automaton
));
5337 automaton
->start_state
= start_state
;
5338 start_state
->it_was_placed_in_stack_for_NDFA_forming
= 1;
5339 VEC_safe_push (state_t
,heap
, state_stack
, start_state
);
5341 while (VEC_length (state_t
, state_stack
) != 0)
5343 state
= VEC_pop (state_t
, state_stack
);
5344 advance_cycle_ainsn
= NULL
;
5345 for (ainsn
= automaton
->ainsn_list
;
5347 ainsn
= ainsn
->next_ainsn
)
5348 if (ainsn
->first_insn_with_same_reservs
)
5350 insn_reserv_decl
= ainsn
->insn_reserv_decl
;
5351 if (insn_reserv_decl
!= DECL_INSN_RESERV (advance_cycle_insn_decl
))
5353 /* We process alt_states in the same order as they are
5354 present in the description. */
5356 for (alt_state
= ainsn
->alt_states
;
5358 alt_state
= alt_state
->next_alt_state
)
5360 state2
= alt_state
->state
;
5361 if (!intersected_state_reservs_p (state
, state2
))
5363 state2
= states_union (state
, state2
, reservs_matter
);
5364 if (!state2
->it_was_placed_in_stack_for_NDFA_forming
)
5366 state2
->it_was_placed_in_stack_for_NDFA_forming
5368 VEC_safe_push (state_t
,heap
, state_stack
, state2
);
5370 if (progress_flag
&& states_n
% 100 == 0)
5371 fprintf (stderr
, ".");
5373 added_arc
= add_arc (state
, state2
, ainsn
);
5378 if (!ndfa_flag
&& added_arc
!= NULL
)
5380 for (alt_state
= ainsn
->alt_states
;
5382 alt_state
= alt_state
->next_alt_state
)
5383 state2
= alt_state
->state
;
5387 advance_cycle_ainsn
= ainsn
;
5389 /* Add transition to advance cycle. */
5390 state2
= state_shift (state
, reservs_matter
);
5391 if (!state2
->it_was_placed_in_stack_for_NDFA_forming
)
5393 state2
->it_was_placed_in_stack_for_NDFA_forming
= 1;
5394 VEC_safe_push (state_t
,heap
, state_stack
, state2
);
5396 if (progress_flag
&& states_n
% 100 == 0)
5397 fprintf (stderr
, ".");
5399 gcc_assert (advance_cycle_ainsn
);
5400 add_arc (state
, state2
, advance_cycle_ainsn
);
5402 VEC_free (state_t
,heap
, state_stack
);
5405 /* Form lists of all arcs of STATE marked by the same ainsn. */
5407 form_arcs_marked_by_insn (state_t state
)
5413 for (i
= 0; i
< description
->decls_num
; i
++)
5415 decl
= description
->decls
[i
];
5416 if (decl
->mode
== dm_insn_reserv
)
5417 DECL_INSN_RESERV (decl
)->arcs_marked_by_insn
= NULL
;
5419 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
5421 gcc_assert (arc
->insn
);
5422 arc
->next_arc_marked_by_insn
5423 = arc
->insn
->insn_reserv_decl
->arcs_marked_by_insn
;
5424 arc
->insn
->insn_reserv_decl
->arcs_marked_by_insn
= arc
;
5428 /* The function creates composed state (see comments for IR) from
5429 ORIGINAL_STATE and list of arcs ARCS_MARKED_BY_INSN marked by the
5430 same insn. If the composed state is not in STATE_STACK yet, it is
5431 pushed into STATE_STACK. */
5434 create_composed_state (state_t original_state
, arc_t arcs_marked_by_insn
,
5435 VEC(state_t
,heap
) **state_stack
)
5438 alt_state_t alt_state
, curr_alt_state
;
5439 alt_state_t new_alt_state
;
5442 state_t state_in_table
;
5444 alt_state_t canonical_alt_states_list
;
5446 int new_state_p
= 0;
5448 if (arcs_marked_by_insn
== NULL
)
5450 if (arcs_marked_by_insn
->next_arc_marked_by_insn
== NULL
)
5451 state
= arcs_marked_by_insn
->to_state
;
5454 gcc_assert (ndfa_flag
);
5455 /* Create composed state. */
5456 state
= get_free_state (0, arcs_marked_by_insn
->to_state
->automaton
);
5457 curr_alt_state
= NULL
;
5458 for (curr_arc
= arcs_marked_by_insn
;
5460 curr_arc
= curr_arc
->next_arc_marked_by_insn
)
5461 if (curr_arc
->to_state
->component_states
== NULL
)
5463 new_alt_state
= get_free_alt_state ();
5464 new_alt_state
->next_alt_state
= curr_alt_state
;
5465 new_alt_state
->state
= curr_arc
->to_state
;
5466 curr_alt_state
= new_alt_state
;
5469 for (alt_state
= curr_arc
->to_state
->component_states
;
5471 alt_state
= alt_state
->next_sorted_alt_state
)
5473 new_alt_state
= get_free_alt_state ();
5474 new_alt_state
->next_alt_state
= curr_alt_state
;
5475 new_alt_state
->state
= alt_state
->state
;
5476 gcc_assert (!alt_state
->state
->component_states
);
5477 curr_alt_state
= new_alt_state
;
5479 /* There are not identical sets in the alt state list. */
5480 canonical_alt_states_list
= uniq_sort_alt_states (curr_alt_state
);
5481 if (canonical_alt_states_list
->next_sorted_alt_state
== NULL
)
5484 state
= canonical_alt_states_list
->state
;
5485 free_state (temp_state
);
5489 state
->component_states
= canonical_alt_states_list
;
5490 state_in_table
= insert_state (state
);
5491 if (state_in_table
!= state
)
5494 (state_in_table
->it_was_placed_in_stack_for_DFA_forming
);
5496 state
= state_in_table
;
5500 gcc_assert (!state
->it_was_placed_in_stack_for_DFA_forming
);
5502 for (curr_alt_state
= state
->component_states
;
5503 curr_alt_state
!= NULL
;
5504 curr_alt_state
= curr_alt_state
->next_sorted_alt_state
)
5505 for (curr_arc
= first_out_arc (curr_alt_state
->state
);
5507 curr_arc
= next_out_arc (curr_arc
))
5508 add_arc (state
, curr_arc
->to_state
, curr_arc
->insn
);
5510 arcs_marked_by_insn
->to_state
= state
;
5511 for (alts_number
= 0,
5512 curr_arc
= arcs_marked_by_insn
->next_arc_marked_by_insn
;
5514 curr_arc
= next_arc
)
5516 next_arc
= curr_arc
->next_arc_marked_by_insn
;
5517 remove_arc (original_state
, curr_arc
);
5522 if (!state
->it_was_placed_in_stack_for_DFA_forming
)
5524 state
->it_was_placed_in_stack_for_DFA_forming
= 1;
5525 VEC_safe_push (state_t
,heap
, *state_stack
, state
);
5530 /* The function transforms nondeterministic AUTOMATON into
5534 NDFA_to_DFA (automaton_t automaton
)
5536 state_t start_state
;
5539 VEC(state_t
,heap
) *state_stack
;
5543 state_stack
= VEC_alloc (state_t
,heap
, 0);
5545 /* Create the start state (empty state). */
5546 start_state
= automaton
->start_state
;
5547 start_state
->it_was_placed_in_stack_for_DFA_forming
= 1;
5548 VEC_safe_push (state_t
,heap
, state_stack
, start_state
);
5550 while (VEC_length (state_t
, state_stack
) != 0)
5552 state
= VEC_pop (state_t
, state_stack
);
5553 form_arcs_marked_by_insn (state
);
5554 for (i
= 0; i
< description
->decls_num
; i
++)
5556 decl
= description
->decls
[i
];
5557 if (decl
->mode
== dm_insn_reserv
5558 && create_composed_state
5559 (state
, DECL_INSN_RESERV (decl
)->arcs_marked_by_insn
,
5563 if (progress_flag
&& states_n
% 100 == 0)
5564 fprintf (stderr
, ".");
5568 VEC_free (state_t
,heap
, state_stack
);
5571 /* The following variable value is current number (1, 2, ...) of passing
5573 static int curr_state_graph_pass_num
;
5575 /* This recursive function passes all states achieved from START_STATE
5576 and applies APPLIED_FUNC to them. */
5578 pass_state_graph (state_t start_state
, void (*applied_func
) (state_t state
))
5582 if (start_state
->pass_num
== curr_state_graph_pass_num
)
5584 start_state
->pass_num
= curr_state_graph_pass_num
;
5585 (*applied_func
) (start_state
);
5586 for (arc
= first_out_arc (start_state
);
5588 arc
= next_out_arc (arc
))
5589 pass_state_graph (arc
->to_state
, applied_func
);
5592 /* This recursive function passes all states of AUTOMATON and applies
5593 APPLIED_FUNC to them. */
5595 pass_states (automaton_t automaton
, void (*applied_func
) (state_t state
))
5597 curr_state_graph_pass_num
++;
5598 pass_state_graph (automaton
->start_state
, applied_func
);
5601 /* The function initializes code for passing of all states. */
5603 initiate_pass_states (void)
5605 curr_state_graph_pass_num
= 0;
5608 /* The following vla is used for storing pointers to all achieved
5610 static VEC(state_t
,heap
) *all_achieved_states
;
5612 /* This function is called by function pass_states to add an achieved
5615 add_achieved_state (state_t state
)
5617 VEC_safe_push (state_t
,heap
, all_achieved_states
, state
);
5620 /* The function sets up equivalence numbers of insns which mark all
5621 out arcs of STATE by equiv_class_num_1 (if ODD_ITERATION_FLAG has
5622 nonzero value) or by equiv_class_num_2 of the destination state.
5623 The function returns number of out arcs of STATE. */
5625 set_out_arc_insns_equiv_num (state_t state
, int odd_iteration_flag
)
5629 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
5631 gcc_assert (!arc
->insn
->insn_reserv_decl
->equiv_class_num
);
5632 arc
->insn
->insn_reserv_decl
->equiv_class_num
5633 = (odd_iteration_flag
5634 ? arc
->to_state
->equiv_class_num_1
5635 : arc
->to_state
->equiv_class_num_2
);
5636 gcc_assert (arc
->insn
->insn_reserv_decl
->equiv_class_num
);
5640 /* The function clears equivalence numbers and alt_states in all insns
5641 which mark all out arcs of STATE. */
5643 clear_arc_insns_equiv_num (state_t state
)
5647 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
5648 arc
->insn
->insn_reserv_decl
->equiv_class_num
= 0;
5652 /* The following function returns TRUE if STATE reserves the unit with
5653 UNIT_NUM on the first cycle. */
5655 first_cycle_unit_presence (state_t state
, int unit_num
)
5657 alt_state_t alt_state
;
5659 if (state
->component_states
== NULL
)
5660 return test_unit_reserv (state
->reservs
, 0, unit_num
);
5663 for (alt_state
= state
->component_states
;
5665 alt_state
= alt_state
->next_sorted_alt_state
)
5666 if (test_unit_reserv (alt_state
->state
->reservs
, 0, unit_num
))
5672 /* This fills in the presence_signature[] member of STATE. */
5674 cache_presence (state_t state
)
5678 sz
= (description
->query_units_num
+ sizeof (int) * CHAR_BIT
- 1)
5679 / (sizeof (int) * CHAR_BIT
);
5681 state
->presence_signature
= XCREATENODEVEC (unsigned int, sz
);
5682 for (i
= 0; i
< description
->units_num
; i
++)
5683 if (units_array
[i
]->query_p
)
5685 int presence1_p
= first_cycle_unit_presence (state
, i
);
5686 state
->presence_signature
[num
/ (sizeof (int) * CHAR_BIT
)]
5687 |= (!!presence1_p
) << (num
% (sizeof (int) * CHAR_BIT
));
5692 /* The function returns nonzero value if STATE is not equivalent to
5693 ANOTHER_STATE from the same current partition on equivalence
5694 classes. Another state has ANOTHER_STATE_OUT_ARCS_NUM number of
5695 output arcs. Iteration of making equivalence partition is defined
5696 by ODD_ITERATION_FLAG. */
5698 state_is_differed (state_t state
, state_t another_state
,
5699 int odd_iteration_flag
)
5702 unsigned int sz
, si
;
5704 gcc_assert (state
->num_out_arcs
== another_state
->num_out_arcs
);
5706 sz
= (description
->query_units_num
+ sizeof (int) * CHAR_BIT
- 1)
5707 / (sizeof (int) * CHAR_BIT
);
5709 for (si
= 0; si
< sz
; si
++)
5710 gcc_assert (state
->presence_signature
[si
]
5711 == another_state
->presence_signature
[si
]);
5713 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
5715 if ((odd_iteration_flag
5716 ? arc
->to_state
->equiv_class_num_1
5717 : arc
->to_state
->equiv_class_num_2
)
5718 != arc
->insn
->insn_reserv_decl
->equiv_class_num
)
5725 /* Compares two states pointed to by STATE_PTR_1 and STATE_PTR_2
5726 and return -1, 0 or 1. This function can be used as predicate for
5727 qsort(). It requires the member presence_signature[] of both
5728 states be filled. */
5730 compare_states_for_equiv (const void *state_ptr_1
,
5731 const void *state_ptr_2
)
5733 const_state_t
const s1
= *(const_state_t
const*)state_ptr_1
;
5734 const_state_t
const s2
= *(const_state_t
const*)state_ptr_2
;
5735 unsigned int sz
, si
;
5736 if (s1
->num_out_arcs
< s2
->num_out_arcs
)
5738 else if (s1
->num_out_arcs
> s2
->num_out_arcs
)
5741 sz
= (description
->query_units_num
+ sizeof (int) * CHAR_BIT
- 1)
5742 / (sizeof (int) * CHAR_BIT
);
5744 for (si
= 0; si
< sz
; si
++)
5745 if (s1
->presence_signature
[si
] < s2
->presence_signature
[si
])
5747 else if (s1
->presence_signature
[si
] > s2
->presence_signature
[si
])
5752 /* The function makes initial partition of STATES on equivalent
5753 classes and saves it into *CLASSES. This function requires the input
5754 to be sorted via compare_states_for_equiv(). */
5756 init_equiv_class (VEC(state_t
,heap
) *states
, VEC (state_t
,heap
) **classes
)
5762 *classes
= VEC_alloc (state_t
,heap
, 150);
5763 for (i
= 0; i
< VEC_length (state_t
, states
); i
++)
5765 state_t state
= VEC_index (state_t
, states
, i
);
5768 if (compare_states_for_equiv (&prev
, &state
) != 0)
5770 VEC_safe_push (state_t
,heap
, *classes
, prev
);
5775 state
->equiv_class_num_1
= class_num
;
5776 state
->next_equiv_class_state
= prev
;
5780 VEC_safe_push (state_t
,heap
, *classes
, prev
);
5784 /* The function copies pointers to equivalent states from vla FROM
5787 copy_equiv_class (VEC(state_t
,heap
) **to
, VEC(state_t
,heap
) *from
)
5789 VEC_free (state_t
,heap
, *to
);
5790 *to
= VEC_copy (state_t
,heap
, from
);
5793 /* The function processes equivalence class given by its first state,
5794 FIRST_STATE, on odd iteration if ODD_ITERATION_FLAG. If there
5795 are not equivalent states, the function partitions the class
5796 removing nonequivalent states and placing them in
5797 *NEXT_ITERATION_CLASSES, increments *NEW_EQUIV_CLASS_NUM_PTR ans
5798 assigns it to the state equivalence number. If the class has been
5799 partitioned, the function returns nonzero value. */
5801 partition_equiv_class (state_t first_state
, int odd_iteration_flag
,
5802 VEC(state_t
,heap
) **next_iteration_classes
,
5803 int *new_equiv_class_num_ptr
)
5805 state_t new_equiv_class
;
5813 while (first_state
!= NULL
)
5815 new_equiv_class
= NULL
;
5816 if (first_state
->next_equiv_class_state
!= NULL
)
5818 /* There are more one states in the class equivalence. */
5819 set_out_arc_insns_equiv_num (first_state
, odd_iteration_flag
);
5820 for (prev_state
= first_state
,
5821 curr_state
= first_state
->next_equiv_class_state
;
5823 curr_state
= next_state
)
5825 next_state
= curr_state
->next_equiv_class_state
;
5826 if (state_is_differed (curr_state
, first_state
,
5827 odd_iteration_flag
))
5829 /* Remove curr state from the class equivalence. */
5830 prev_state
->next_equiv_class_state
= next_state
;
5831 /* Add curr state to the new class equivalence. */
5832 curr_state
->next_equiv_class_state
= new_equiv_class
;
5833 if (new_equiv_class
== NULL
)
5834 (*new_equiv_class_num_ptr
)++;
5835 if (odd_iteration_flag
)
5836 curr_state
->equiv_class_num_2
= *new_equiv_class_num_ptr
;
5838 curr_state
->equiv_class_num_1
= *new_equiv_class_num_ptr
;
5839 new_equiv_class
= curr_state
;
5843 prev_state
= curr_state
;
5845 clear_arc_insns_equiv_num (first_state
);
5847 if (new_equiv_class
!= NULL
)
5848 VEC_safe_push (state_t
,heap
, *next_iteration_classes
, new_equiv_class
);
5849 first_state
= new_equiv_class
;
5854 /* The function finds equivalent states of AUTOMATON. */
5856 evaluate_equiv_classes (automaton_t automaton
,
5857 VEC(state_t
,heap
) **equiv_classes
)
5859 int new_equiv_class_num
;
5860 int odd_iteration_flag
;
5862 VEC (state_t
,heap
) *next_iteration_classes
;
5865 all_achieved_states
= VEC_alloc (state_t
,heap
, 1500);
5866 pass_states (automaton
, add_achieved_state
);
5867 pass_states (automaton
, cache_presence
);
5868 qsort (VEC_address (state_t
, all_achieved_states
),
5869 VEC_length (state_t
, all_achieved_states
),
5870 sizeof (state_t
), compare_states_for_equiv
);
5872 odd_iteration_flag
= 0;
5873 new_equiv_class_num
= init_equiv_class (all_achieved_states
,
5874 &next_iteration_classes
);
5878 odd_iteration_flag
= !odd_iteration_flag
;
5880 copy_equiv_class (equiv_classes
, next_iteration_classes
);
5882 /* Transfer equiv numbers for the next iteration. */
5883 for (i
= 0; i
< VEC_length (state_t
, all_achieved_states
); i
++)
5884 if (odd_iteration_flag
)
5885 VEC_index (state_t
, all_achieved_states
, i
)->equiv_class_num_2
5886 = VEC_index (state_t
, all_achieved_states
, i
)->equiv_class_num_1
;
5888 VEC_index (state_t
, all_achieved_states
, i
)->equiv_class_num_1
5889 = VEC_index (state_t
, all_achieved_states
, i
)->equiv_class_num_2
;
5891 for (i
= 0; i
< VEC_length (state_t
, *equiv_classes
); i
++)
5892 if (partition_equiv_class (VEC_index (state_t
, *equiv_classes
, i
),
5894 &next_iteration_classes
,
5895 &new_equiv_class_num
))
5898 while (!finish_flag
);
5899 VEC_free (state_t
,heap
, next_iteration_classes
);
5900 VEC_free (state_t
,heap
, all_achieved_states
);
5903 /* The function merges equivalent states of AUTOMATON. */
5905 merge_states (automaton_t automaton
, VEC(state_t
,heap
) *equiv_classes
)
5909 state_t first_class_state
;
5910 alt_state_t alt_states
;
5911 alt_state_t alt_state
, new_alt_state
;
5916 /* Create states corresponding to equivalence classes containing two
5918 for (i
= 0; i
< VEC_length (state_t
, equiv_classes
); i
++)
5920 curr_state
= VEC_index (state_t
, equiv_classes
, i
);
5921 if (curr_state
->next_equiv_class_state
!= NULL
)
5923 /* There are more one states in the class equivalence. */
5924 /* Create new compound state. */
5925 new_state
= get_free_state (0, automaton
);
5927 first_class_state
= curr_state
;
5928 for (curr_state
= first_class_state
;
5930 curr_state
= curr_state
->next_equiv_class_state
)
5932 curr_state
->equiv_class_state
= new_state
;
5933 if (curr_state
->component_states
== NULL
)
5935 new_alt_state
= get_free_alt_state ();
5936 new_alt_state
->state
= curr_state
;
5937 new_alt_state
->next_alt_state
= alt_states
;
5938 alt_states
= new_alt_state
;
5941 for (alt_state
= curr_state
->component_states
;
5943 alt_state
= alt_state
->next_sorted_alt_state
)
5945 new_alt_state
= get_free_alt_state ();
5946 new_alt_state
->state
= alt_state
->state
;
5947 new_alt_state
->next_alt_state
= alt_states
;
5948 alt_states
= new_alt_state
;
5951 /* Its is important that alt states were sorted before and
5952 after merging to have the same querying results. */
5953 new_state
->component_states
= uniq_sort_alt_states (alt_states
);
5956 curr_state
->equiv_class_state
= curr_state
;
5959 for (i
= 0; i
< VEC_length (state_t
, equiv_classes
); i
++)
5961 curr_state
= VEC_index (state_t
, equiv_classes
, i
);
5962 if (curr_state
->next_equiv_class_state
!= NULL
)
5964 first_class_state
= curr_state
;
5965 /* Create new arcs output from the state corresponding to
5967 for (curr_arc
= first_out_arc (first_class_state
);
5969 curr_arc
= next_out_arc (curr_arc
))
5970 add_arc (first_class_state
->equiv_class_state
,
5971 curr_arc
->to_state
->equiv_class_state
,
5973 /* Delete output arcs from states of given class equivalence. */
5974 for (curr_state
= first_class_state
;
5976 curr_state
= curr_state
->next_equiv_class_state
)
5978 if (automaton
->start_state
== curr_state
)
5979 automaton
->start_state
= curr_state
->equiv_class_state
;
5980 /* Delete the state and its output arcs. */
5981 for (curr_arc
= first_out_arc (curr_state
);
5983 curr_arc
= next_arc
)
5985 next_arc
= next_out_arc (curr_arc
);
5986 free_arc (curr_arc
);
5992 /* Change `to_state' of arcs output from the state of given
5993 equivalence class. */
5994 for (curr_arc
= first_out_arc (curr_state
);
5996 curr_arc
= next_out_arc (curr_arc
))
5997 curr_arc
->to_state
= curr_arc
->to_state
->equiv_class_state
;
6002 /* The function sets up new_cycle_p for states if there is arc to the
6003 state marked by advance_cycle_insn_decl. */
6005 set_new_cycle_flags (state_t state
)
6009 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
6010 if (arc
->insn
->insn_reserv_decl
6011 == DECL_INSN_RESERV (advance_cycle_insn_decl
))
6012 arc
->to_state
->new_cycle_p
= 1;
6015 /* The top level function for minimization of deterministic
6018 minimize_DFA (automaton_t automaton
)
6020 VEC(state_t
,heap
) *equiv_classes
= 0;
6022 evaluate_equiv_classes (automaton
, &equiv_classes
);
6023 merge_states (automaton
, equiv_classes
);
6024 pass_states (automaton
, set_new_cycle_flags
);
6026 VEC_free (state_t
,heap
, equiv_classes
);
6029 /* Values of two variables are counted number of states and arcs in an
6031 static int curr_counted_states_num
;
6032 static int curr_counted_arcs_num
;
6034 /* The function is called by function `pass_states' to count states
6035 and arcs of an automaton. */
6037 incr_states_and_arcs_nums (state_t state
)
6041 curr_counted_states_num
++;
6042 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
6043 curr_counted_arcs_num
++;
6046 /* The function counts states and arcs of AUTOMATON. */
6048 count_states_and_arcs (automaton_t automaton
, int *states_num
,
6051 curr_counted_states_num
= 0;
6052 curr_counted_arcs_num
= 0;
6053 pass_states (automaton
, incr_states_and_arcs_nums
);
6054 *states_num
= curr_counted_states_num
;
6055 *arcs_num
= curr_counted_arcs_num
;
6058 /* The function builds one DFA AUTOMATON for fast pipeline hazards
6059 recognition after checking and simplifying IR of the
6062 build_automaton (automaton_t automaton
)
6067 ticker_on (&NDFA_time
);
6070 if (automaton
->corresponding_automaton_decl
== NULL
)
6071 fprintf (stderr
, "Create anonymous automaton");
6073 fprintf (stderr
, "Create automaton `%s'",
6074 automaton
->corresponding_automaton_decl
->name
);
6075 fprintf (stderr
, " (1 dot is 100 new states):");
6077 make_automaton (automaton
);
6079 fprintf (stderr
, " done\n");
6080 ticker_off (&NDFA_time
);
6081 count_states_and_arcs (automaton
, &states_num
, &arcs_num
);
6082 automaton
->NDFA_states_num
= states_num
;
6083 automaton
->NDFA_arcs_num
= arcs_num
;
6084 ticker_on (&NDFA_to_DFA_time
);
6087 if (automaton
->corresponding_automaton_decl
== NULL
)
6088 fprintf (stderr
, "Make anonymous DFA");
6090 fprintf (stderr
, "Make DFA `%s'",
6091 automaton
->corresponding_automaton_decl
->name
);
6092 fprintf (stderr
, " (1 dot is 100 new states):");
6094 NDFA_to_DFA (automaton
);
6096 fprintf (stderr
, " done\n");
6097 ticker_off (&NDFA_to_DFA_time
);
6098 count_states_and_arcs (automaton
, &states_num
, &arcs_num
);
6099 automaton
->DFA_states_num
= states_num
;
6100 automaton
->DFA_arcs_num
= arcs_num
;
6101 if (!no_minimization_flag
)
6103 ticker_on (&minimize_time
);
6106 if (automaton
->corresponding_automaton_decl
== NULL
)
6107 fprintf (stderr
, "Minimize anonymous DFA...");
6109 fprintf (stderr
, "Minimize DFA `%s'...",
6110 automaton
->corresponding_automaton_decl
->name
);
6112 minimize_DFA (automaton
);
6114 fprintf (stderr
, "done\n");
6115 ticker_off (&minimize_time
);
6116 count_states_and_arcs (automaton
, &states_num
, &arcs_num
);
6117 automaton
->minimal_DFA_states_num
= states_num
;
6118 automaton
->minimal_DFA_arcs_num
= arcs_num
;
6124 /* The page contains code for enumeration of all states of an automaton. */
6126 /* Variable used for enumeration of all states of an automaton. Its
6127 value is current number of automaton states. */
6128 static int curr_state_order_num
;
6130 /* The function is called by function `pass_states' for enumerating
6133 set_order_state_num (state_t state
)
6135 state
->order_state_num
= curr_state_order_num
;
6136 curr_state_order_num
++;
6139 /* The function enumerates all states of AUTOMATON. */
6141 enumerate_states (automaton_t automaton
)
6143 curr_state_order_num
= 0;
6144 pass_states (automaton
, set_order_state_num
);
6145 automaton
->achieved_states_num
= curr_state_order_num
;
6150 /* The page contains code for finding equivalent automaton insns
6153 /* The function inserts AINSN into cyclic list
6154 CYCLIC_EQUIV_CLASS_INSN_LIST of ainsns. */
6156 insert_ainsn_into_equiv_class (ainsn_t ainsn
,
6157 ainsn_t cyclic_equiv_class_insn_list
)
6159 if (cyclic_equiv_class_insn_list
== NULL
)
6160 ainsn
->next_equiv_class_insn
= ainsn
;
6163 ainsn
->next_equiv_class_insn
6164 = cyclic_equiv_class_insn_list
->next_equiv_class_insn
;
6165 cyclic_equiv_class_insn_list
->next_equiv_class_insn
= ainsn
;
6170 /* The function deletes equiv_class_insn into cyclic list of
6171 equivalent ainsns. */
6173 delete_ainsn_from_equiv_class (ainsn_t equiv_class_insn
)
6175 ainsn_t curr_equiv_class_insn
;
6176 ainsn_t prev_equiv_class_insn
;
6178 prev_equiv_class_insn
= equiv_class_insn
;
6179 for (curr_equiv_class_insn
= equiv_class_insn
->next_equiv_class_insn
;
6180 curr_equiv_class_insn
!= equiv_class_insn
;
6181 curr_equiv_class_insn
= curr_equiv_class_insn
->next_equiv_class_insn
)
6182 prev_equiv_class_insn
= curr_equiv_class_insn
;
6183 if (prev_equiv_class_insn
!= equiv_class_insn
)
6184 prev_equiv_class_insn
->next_equiv_class_insn
6185 = equiv_class_insn
->next_equiv_class_insn
;
6188 /* The function processes AINSN of a state in order to find equivalent
6189 ainsns. INSN_ARCS_ARRAY is table: code of insn -> out arc of the
6192 process_insn_equiv_class (ainsn_t ainsn
, arc_t
*insn_arcs_array
)
6196 ainsn_t cyclic_insn_list
;
6199 gcc_assert (insn_arcs_array
[ainsn
->insn_reserv_decl
->insn_num
]);
6201 /* New class of ainsns which are not equivalent to given ainsn. */
6202 cyclic_insn_list
= NULL
;
6205 next_insn
= curr_insn
->next_equiv_class_insn
;
6206 arc
= insn_arcs_array
[curr_insn
->insn_reserv_decl
->insn_num
];
6208 || (insn_arcs_array
[ainsn
->insn_reserv_decl
->insn_num
]->to_state
6211 delete_ainsn_from_equiv_class (curr_insn
);
6212 cyclic_insn_list
= insert_ainsn_into_equiv_class (curr_insn
,
6215 curr_insn
= next_insn
;
6217 while (curr_insn
!= ainsn
);
6220 /* The function processes STATE in order to find equivalent ainsns. */
6222 process_state_for_insn_equiv_partition (state_t state
)
6225 arc_t
*insn_arcs_array
= XCNEWVEC (arc_t
, description
->insns_num
);
6227 /* Process insns of the arcs. */
6228 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
6229 insn_arcs_array
[arc
->insn
->insn_reserv_decl
->insn_num
] = arc
;
6230 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
6231 process_insn_equiv_class (arc
->insn
, insn_arcs_array
);
6233 free (insn_arcs_array
);
6236 /* The function searches for equivalent ainsns of AUTOMATON. */
6238 set_insn_equiv_classes (automaton_t automaton
)
6243 ainsn_t cyclic_insn_list
;
6244 ainsn_t insn_with_same_reservs
;
6245 int equiv_classes_num
;
6247 /* All insns are included in one equivalence class. */
6248 cyclic_insn_list
= NULL
;
6249 for (ainsn
= automaton
->ainsn_list
; ainsn
!= NULL
; ainsn
= ainsn
->next_ainsn
)
6250 if (ainsn
->first_insn_with_same_reservs
)
6251 cyclic_insn_list
= insert_ainsn_into_equiv_class (ainsn
,
6253 /* Process insns in order to make equivalence partition. */
6254 pass_states (automaton
, process_state_for_insn_equiv_partition
);
6255 /* Enumerate equiv classes. */
6256 for (ainsn
= automaton
->ainsn_list
; ainsn
!= NULL
; ainsn
= ainsn
->next_ainsn
)
6257 /* Set undefined value. */
6258 ainsn
->insn_equiv_class_num
= -1;
6259 equiv_classes_num
= 0;
6260 for (ainsn
= automaton
->ainsn_list
; ainsn
!= NULL
; ainsn
= ainsn
->next_ainsn
)
6261 if (ainsn
->insn_equiv_class_num
< 0)
6264 gcc_assert (first_insn
->first_insn_with_same_reservs
);
6265 first_insn
->first_ainsn_with_given_equivalence_num
= 1;
6266 curr_insn
= first_insn
;
6269 for (insn_with_same_reservs
= curr_insn
;
6270 insn_with_same_reservs
!= NULL
;
6271 insn_with_same_reservs
6272 = insn_with_same_reservs
->next_same_reservs_insn
)
6273 insn_with_same_reservs
->insn_equiv_class_num
= equiv_classes_num
;
6274 curr_insn
= curr_insn
->next_equiv_class_insn
;
6276 while (curr_insn
!= first_insn
);
6277 equiv_classes_num
++;
6279 automaton
->insn_equiv_classes_num
= equiv_classes_num
;
6284 /* This page contains code for creating DFA(s) and calls functions
6288 /* The following value is used to prevent floating point overflow for
6289 estimating an automaton bound. The value should be less DBL_MAX on
6290 the host machine. We use here approximate minimum of maximal
6291 double floating point value required by ANSI C standard. It
6292 will work for non ANSI sun compiler too. */
6294 #define MAX_FLOATING_POINT_VALUE_FOR_AUTOMATON_BOUND 1.0E37
6296 /* The function estimate size of the single DFA used by PHR (pipeline
6297 hazards recognizer). */
6299 estimate_one_automaton_bound (void)
6302 double one_automaton_estimation_bound
;
6306 one_automaton_estimation_bound
= 1.0;
6307 for (i
= 0; i
< description
->decls_num
; i
++)
6309 decl
= description
->decls
[i
];
6310 if (decl
->mode
== dm_unit
)
6312 root_value
= exp (log (DECL_UNIT (decl
)->max_occ_cycle_num
6313 - DECL_UNIT (decl
)->min_occ_cycle_num
+ 1.0)
6315 if (MAX_FLOATING_POINT_VALUE_FOR_AUTOMATON_BOUND
/ root_value
6316 > one_automaton_estimation_bound
)
6317 one_automaton_estimation_bound
*= root_value
;
6320 return one_automaton_estimation_bound
;
6323 /* The function compares unit declarations according to their maximal
6324 cycle in reservations. */
6326 compare_max_occ_cycle_nums (const void *unit_decl_1
,
6327 const void *unit_decl_2
)
6329 if ((DECL_UNIT (*(const_decl_t
const*) unit_decl_1
)->max_occ_cycle_num
)
6330 < (DECL_UNIT (*(const_decl_t
const*) unit_decl_2
)->max_occ_cycle_num
))
6332 else if ((DECL_UNIT (*(const_decl_t
const*) unit_decl_1
)->max_occ_cycle_num
)
6333 == (DECL_UNIT (*(const_decl_t
const*) unit_decl_2
)->max_occ_cycle_num
))
6339 /* The function makes heuristic assigning automata to units. Actually
6340 efficacy of the algorithm has been checked yet??? */
6343 units_to_automata_heuristic_distr (void)
6345 double estimation_bound
;
6349 unit_decl_t
*unit_decls
;
6352 if (description
->units_num
== 0)
6354 estimation_bound
= estimate_one_automaton_bound ();
6355 unit_decls
= XNEWVEC (unit_decl_t
, description
->units_num
);
6357 for (i
= 0, j
= 0; i
< description
->decls_num
; i
++)
6358 if (description
->decls
[i
]->mode
== dm_unit
)
6359 unit_decls
[j
++] = DECL_UNIT (description
->decls
[i
]);
6360 gcc_assert (j
== description
->units_num
);
6362 qsort (unit_decls
, description
->units_num
,
6363 sizeof (unit_decl_t
), compare_max_occ_cycle_nums
);
6366 bound_value
= unit_decls
[0]->max_occ_cycle_num
;
6367 unit_decls
[0]->corresponding_automaton_num
= automaton_num
;
6369 for (i
= 1; i
< description
->units_num
; i
++)
6371 rest_units_num
= description
->units_num
- i
+ 1;
6372 gcc_assert (automata_num
- automaton_num
- 1 <= rest_units_num
);
6373 if (automaton_num
< automata_num
- 1
6374 && ((automata_num
- automaton_num
- 1 == rest_units_num
)
6377 / unit_decls
[i
]->max_occ_cycle_num
))))
6379 bound_value
= unit_decls
[i
]->max_occ_cycle_num
;
6383 bound_value
*= unit_decls
[i
]->max_occ_cycle_num
;
6384 unit_decls
[i
]->corresponding_automaton_num
= automaton_num
;
6386 gcc_assert (automaton_num
== automata_num
- 1);
6390 /* The functions creates automaton insns for each automata. Automaton
6391 insn is simply insn for given automaton which makes reservation
6392 only of units of the automaton. */
6394 create_ainsns (void)
6397 ainsn_t first_ainsn
;
6404 for (i
= 0; i
< description
->decls_num
; i
++)
6406 decl
= description
->decls
[i
];
6407 if (decl
->mode
== dm_insn_reserv
)
6409 curr_ainsn
= XCREATENODE (struct ainsn
);
6410 curr_ainsn
->insn_reserv_decl
= DECL_INSN_RESERV (decl
);
6411 curr_ainsn
->important_p
= FALSE
;
6412 curr_ainsn
->next_ainsn
= NULL
;
6413 if (prev_ainsn
== NULL
)
6414 first_ainsn
= curr_ainsn
;
6416 prev_ainsn
->next_ainsn
= curr_ainsn
;
6417 prev_ainsn
= curr_ainsn
;
6423 /* The function assigns automata to units according to constructions
6424 `define_automaton' in the description. */
6426 units_to_automata_distr (void)
6431 for (i
= 0; i
< description
->decls_num
; i
++)
6433 decl
= description
->decls
[i
];
6434 if (decl
->mode
== dm_unit
)
6436 if (DECL_UNIT (decl
)->automaton_decl
== NULL
6437 || (DECL_UNIT (decl
)->automaton_decl
->corresponding_automaton
6439 /* Distribute to the first automaton. */
6440 DECL_UNIT (decl
)->corresponding_automaton_num
= 0;
6442 DECL_UNIT (decl
)->corresponding_automaton_num
6443 = (DECL_UNIT (decl
)->automaton_decl
6444 ->corresponding_automaton
->automaton_order_num
);
6449 /* The function creates DFA(s) for fast pipeline hazards recognition
6450 after checking and simplifying IR of the description. */
6452 create_automata (void)
6454 automaton_t curr_automaton
;
6455 automaton_t prev_automaton
;
6457 int curr_automaton_num
;
6460 if (automata_num
!= 0)
6462 units_to_automata_heuristic_distr ();
6463 for (prev_automaton
= NULL
, curr_automaton_num
= 0;
6464 curr_automaton_num
< automata_num
;
6465 curr_automaton_num
++, prev_automaton
= curr_automaton
)
6467 curr_automaton
= XCREATENODE (struct automaton
);
6468 curr_automaton
->ainsn_list
= create_ainsns ();
6469 curr_automaton
->corresponding_automaton_decl
= NULL
;
6470 curr_automaton
->next_automaton
= NULL
;
6471 curr_automaton
->automaton_order_num
= curr_automaton_num
;
6472 if (prev_automaton
== NULL
)
6473 description
->first_automaton
= curr_automaton
;
6475 prev_automaton
->next_automaton
= curr_automaton
;
6480 curr_automaton_num
= 0;
6481 prev_automaton
= NULL
;
6482 for (i
= 0; i
< description
->decls_num
; i
++)
6484 decl
= description
->decls
[i
];
6485 if (decl
->mode
== dm_automaton
6486 && DECL_AUTOMATON (decl
)->automaton_is_used
)
6488 curr_automaton
= XCREATENODE (struct automaton
);
6489 curr_automaton
->ainsn_list
= create_ainsns ();
6490 curr_automaton
->corresponding_automaton_decl
6491 = DECL_AUTOMATON (decl
);
6492 curr_automaton
->next_automaton
= NULL
;
6493 DECL_AUTOMATON (decl
)->corresponding_automaton
= curr_automaton
;
6494 curr_automaton
->automaton_order_num
= curr_automaton_num
;
6495 if (prev_automaton
== NULL
)
6496 description
->first_automaton
= curr_automaton
;
6498 prev_automaton
->next_automaton
= curr_automaton
;
6499 curr_automaton_num
++;
6500 prev_automaton
= curr_automaton
;
6503 if (curr_automaton_num
== 0)
6505 curr_automaton
= XCREATENODE (struct automaton
);
6506 curr_automaton
->ainsn_list
= create_ainsns ();
6507 curr_automaton
->corresponding_automaton_decl
= NULL
;
6508 curr_automaton
->next_automaton
= NULL
;
6509 description
->first_automaton
= curr_automaton
;
6511 units_to_automata_distr ();
6513 NDFA_time
= create_ticker ();
6514 ticker_off (&NDFA_time
);
6515 NDFA_to_DFA_time
= create_ticker ();
6516 ticker_off (&NDFA_to_DFA_time
);
6517 minimize_time
= create_ticker ();
6518 ticker_off (&minimize_time
);
6519 equiv_time
= create_ticker ();
6520 ticker_off (&equiv_time
);
6521 for (curr_automaton
= description
->first_automaton
;
6522 curr_automaton
!= NULL
;
6523 curr_automaton
= curr_automaton
->next_automaton
)
6527 if (curr_automaton
->corresponding_automaton_decl
== NULL
)
6528 fprintf (stderr
, "Prepare anonymous automaton creation ... ");
6530 fprintf (stderr
, "Prepare automaton `%s' creation...",
6531 curr_automaton
->corresponding_automaton_decl
->name
);
6533 create_alt_states (curr_automaton
);
6534 form_ainsn_with_same_reservs (curr_automaton
);
6536 fprintf (stderr
, "done\n");
6537 build_automaton (curr_automaton
);
6538 enumerate_states (curr_automaton
);
6539 ticker_on (&equiv_time
);
6540 set_insn_equiv_classes (curr_automaton
);
6541 ticker_off (&equiv_time
);
6547 /* This page contains code for forming string representation of
6548 regexp. The representation is formed on IR obstack. So you should
6549 not work with IR obstack between regexp_representation and
6550 finish_regexp_representation calls. */
6552 /* This recursive function forms string representation of regexp
6553 (without tailing '\0'). */
6555 form_regexp (regexp_t regexp
)
6559 switch (regexp
->mode
)
6561 case rm_unit
: case rm_reserv
:
6563 const char *name
= (regexp
->mode
== rm_unit
6564 ? REGEXP_UNIT (regexp
)->name
6565 : REGEXP_RESERV (regexp
)->name
);
6567 obstack_grow (&irp
, name
, strlen (name
));
6572 for (i
= 0; i
< REGEXP_SEQUENCE (regexp
)->regexps_num
; i
++)
6575 obstack_1grow (&irp
, ',');
6576 form_regexp (REGEXP_SEQUENCE (regexp
)->regexps
[i
]);
6581 obstack_1grow (&irp
, '(');
6582 for (i
= 0; i
< REGEXP_ALLOF (regexp
)->regexps_num
; i
++)
6585 obstack_1grow (&irp
, '+');
6586 if (REGEXP_ALLOF (regexp
)->regexps
[i
]->mode
== rm_sequence
6587 || REGEXP_ALLOF (regexp
)->regexps
[i
]->mode
== rm_oneof
)
6588 obstack_1grow (&irp
, '(');
6589 form_regexp (REGEXP_ALLOF (regexp
)->regexps
[i
]);
6590 if (REGEXP_ALLOF (regexp
)->regexps
[i
]->mode
== rm_sequence
6591 || REGEXP_ALLOF (regexp
)->regexps
[i
]->mode
== rm_oneof
)
6592 obstack_1grow (&irp
, ')');
6594 obstack_1grow (&irp
, ')');
6598 for (i
= 0; i
< REGEXP_ONEOF (regexp
)->regexps_num
; i
++)
6601 obstack_1grow (&irp
, '|');
6602 if (REGEXP_ONEOF (regexp
)->regexps
[i
]->mode
== rm_sequence
)
6603 obstack_1grow (&irp
, '(');
6604 form_regexp (REGEXP_ONEOF (regexp
)->regexps
[i
]);
6605 if (REGEXP_ONEOF (regexp
)->regexps
[i
]->mode
== rm_sequence
)
6606 obstack_1grow (&irp
, ')');
6614 if (REGEXP_REPEAT (regexp
)->regexp
->mode
== rm_sequence
6615 || REGEXP_REPEAT (regexp
)->regexp
->mode
== rm_allof
6616 || REGEXP_REPEAT (regexp
)->regexp
->mode
== rm_oneof
)
6617 obstack_1grow (&irp
, '(');
6618 form_regexp (REGEXP_REPEAT (regexp
)->regexp
);
6619 if (REGEXP_REPEAT (regexp
)->regexp
->mode
== rm_sequence
6620 || REGEXP_REPEAT (regexp
)->regexp
->mode
== rm_allof
6621 || REGEXP_REPEAT (regexp
)->regexp
->mode
== rm_oneof
)
6622 obstack_1grow (&irp
, ')');
6623 sprintf (digits
, "*%d", REGEXP_REPEAT (regexp
)->repeat_num
);
6624 obstack_grow (&irp
, digits
, strlen (digits
));
6629 obstack_grow (&irp
, NOTHING_NAME
, strlen (NOTHING_NAME
));
6637 /* The function returns string representation of REGEXP on IR
6640 regexp_representation (regexp_t regexp
)
6642 form_regexp (regexp
);
6643 obstack_1grow (&irp
, '\0');
6644 return obstack_base (&irp
);
6647 /* The function frees memory allocated for last formed string
6648 representation of regexp. */
6650 finish_regexp_representation (void)
6652 int length
= obstack_object_size (&irp
);
6654 obstack_blank_fast (&irp
, -length
);
6659 /* This page contains code for output PHR (pipeline hazards recognizer). */
6661 /* The function outputs minimal C type which is sufficient for
6662 representation numbers in range min_range_value and
6663 max_range_value. Because host machine and build machine may be
6664 different, we use here minimal values required by ANSI C standard
6665 instead of UCHAR_MAX, SHRT_MAX, SHRT_MIN, etc. This is a good
6669 output_range_type (FILE *f
, long int min_range_value
,
6670 long int max_range_value
)
6672 if (min_range_value
>= 0 && max_range_value
<= 255)
6673 fprintf (f
, "unsigned char");
6674 else if (min_range_value
>= -127 && max_range_value
<= 127)
6675 fprintf (f
, "signed char");
6676 else if (min_range_value
>= 0 && max_range_value
<= 65535)
6677 fprintf (f
, "unsigned short");
6678 else if (min_range_value
>= -32767 && max_range_value
<= 32767)
6679 fprintf (f
, "short");
6684 /* The function outputs all initialization values of VECT. */
6686 output_vect (vla_hwint_t vect
)
6689 size_t vect_length
= VEC_length (vect_el_t
, vect
);
6693 if (vect_length
== 0)
6694 fputs ("0 /* This is dummy el because the vect is empty */", output_file
);
6696 for (i
= 0; i
< vect_length
; i
++)
6698 fprintf (output_file
, "%5ld", (long) VEC_index (vect_el_t
, vect
, i
));
6699 if (els_on_line
== 10)
6702 fputs (",\n", output_file
);
6704 else if (i
< vect_length
-1)
6705 fputs (", ", output_file
);
6710 /* The following is name of the structure which represents DFA(s) for
6712 #define CHIP_NAME "DFA_chip"
6714 /* The following is name of member which represents state of a DFA for
6717 output_chip_member_name (FILE *f
, automaton_t automaton
)
6719 if (automaton
->corresponding_automaton_decl
== NULL
)
6720 fprintf (f
, "automaton_state_%d", automaton
->automaton_order_num
);
6722 fprintf (f
, "%s_automaton_state",
6723 automaton
->corresponding_automaton_decl
->name
);
6726 /* The following is name of temporary variable which stores state of a
6729 output_temp_chip_member_name (FILE *f
, automaton_t automaton
)
6732 output_chip_member_name (f
, automaton
);
6735 /* This is name of macro value which is code of pseudo_insn
6736 representing advancing cpu cycle. Its value is used as internal
6737 code unknown insn. */
6738 #define ADVANCE_CYCLE_VALUE_NAME "DFA__ADVANCE_CYCLE"
6740 /* Output name of translate vector for given automaton. */
6742 output_translate_vect_name (FILE *f
, automaton_t automaton
)
6744 if (automaton
->corresponding_automaton_decl
== NULL
)
6745 fprintf (f
, "translate_%d", automaton
->automaton_order_num
);
6747 fprintf (f
, "%s_translate", automaton
->corresponding_automaton_decl
->name
);
6750 /* Output name for simple transition table representation. */
6752 output_trans_full_vect_name (FILE *f
, automaton_t automaton
)
6754 if (automaton
->corresponding_automaton_decl
== NULL
)
6755 fprintf (f
, "transitions_%d", automaton
->automaton_order_num
);
6757 fprintf (f
, "%s_transitions",
6758 automaton
->corresponding_automaton_decl
->name
);
6761 /* Output name of comb vector of the transition table for given
6764 output_trans_comb_vect_name (FILE *f
, automaton_t automaton
)
6766 if (automaton
->corresponding_automaton_decl
== NULL
)
6767 fprintf (f
, "transitions_%d", automaton
->automaton_order_num
);
6769 fprintf (f
, "%s_transitions",
6770 automaton
->corresponding_automaton_decl
->name
);
6773 /* Output name of check vector of the transition table for given
6776 output_trans_check_vect_name (FILE *f
, automaton_t automaton
)
6778 if (automaton
->corresponding_automaton_decl
== NULL
)
6779 fprintf (f
, "check_%d", automaton
->automaton_order_num
);
6781 fprintf (f
, "%s_check", automaton
->corresponding_automaton_decl
->name
);
6784 /* Output name of base vector of the transition table for given
6787 output_trans_base_vect_name (FILE *f
, automaton_t automaton
)
6789 if (automaton
->corresponding_automaton_decl
== NULL
)
6790 fprintf (f
, "base_%d", automaton
->automaton_order_num
);
6792 fprintf (f
, "%s_base", automaton
->corresponding_automaton_decl
->name
);
6795 /* Output name of simple min issue delay table representation. */
6797 output_min_issue_delay_vect_name (FILE *f
, automaton_t automaton
)
6799 if (automaton
->corresponding_automaton_decl
== NULL
)
6800 fprintf (f
, "min_issue_delay_%d", automaton
->automaton_order_num
);
6802 fprintf (f
, "%s_min_issue_delay",
6803 automaton
->corresponding_automaton_decl
->name
);
6806 /* Output name of deadlock vector for given automaton. */
6808 output_dead_lock_vect_name (FILE *f
, automaton_t automaton
)
6810 if (automaton
->corresponding_automaton_decl
== NULL
)
6811 fprintf (f
, "dead_lock_%d", automaton
->automaton_order_num
);
6813 fprintf (f
, "%s_dead_lock", automaton
->corresponding_automaton_decl
->name
);
6816 /* Output name of reserved units table for AUTOMATON into file F. */
6818 output_reserved_units_table_name (FILE *f
, automaton_t automaton
)
6820 if (automaton
->corresponding_automaton_decl
== NULL
)
6821 fprintf (f
, "reserved_units_%d", automaton
->automaton_order_num
);
6823 fprintf (f
, "%s_reserved_units",
6824 automaton
->corresponding_automaton_decl
->name
);
6827 /* Name of the PHR interface macro. */
6828 #define CPU_UNITS_QUERY_MACRO_NAME "CPU_UNITS_QUERY"
6830 /* Names of an internal functions: */
6831 #define INTERNAL_MIN_ISSUE_DELAY_FUNC_NAME "internal_min_issue_delay"
6833 /* This is external type of DFA(s) state. */
6834 #define STATE_TYPE_NAME "state_t"
6836 #define INTERNAL_TRANSITION_FUNC_NAME "internal_state_transition"
6838 #define INTERNAL_RESET_FUNC_NAME "internal_reset"
6840 #define INTERNAL_DEAD_LOCK_FUNC_NAME "internal_state_dead_lock_p"
6842 #define INTERNAL_INSN_LATENCY_FUNC_NAME "internal_insn_latency"
6844 /* Name of cache of insn dfa codes. */
6845 #define DFA_INSN_CODES_VARIABLE_NAME "dfa_insn_codes"
6847 /* Name of length of cache of insn dfa codes. */
6848 #define DFA_INSN_CODES_LENGTH_VARIABLE_NAME "dfa_insn_codes_length"
6850 /* Names of the PHR interface functions: */
6851 #define SIZE_FUNC_NAME "state_size"
6853 #define TRANSITION_FUNC_NAME "state_transition"
6855 #define MIN_ISSUE_DELAY_FUNC_NAME "min_issue_delay"
6857 #define MIN_INSN_CONFLICT_DELAY_FUNC_NAME "min_insn_conflict_delay"
6859 #define DEAD_LOCK_FUNC_NAME "state_dead_lock_p"
6861 #define RESET_FUNC_NAME "state_reset"
6863 #define INSN_LATENCY_FUNC_NAME "insn_latency"
6865 #define PRINT_RESERVATION_FUNC_NAME "print_reservation"
6867 #define GET_CPU_UNIT_CODE_FUNC_NAME "get_cpu_unit_code"
6869 #define CPU_UNIT_RESERVATION_P_FUNC_NAME "cpu_unit_reservation_p"
6871 #define INSN_HAS_DFA_RESERVATION_P_FUNC_NAME "insn_has_dfa_reservation_p"
6873 #define DFA_CLEAN_INSN_CACHE_FUNC_NAME "dfa_clean_insn_cache"
6875 #define DFA_CLEAR_SINGLE_INSN_CACHE_FUNC_NAME "dfa_clear_single_insn_cache"
6877 #define DFA_START_FUNC_NAME "dfa_start"
6879 #define DFA_FINISH_FUNC_NAME "dfa_finish"
6881 /* Names of parameters of the PHR interface functions. */
6882 #define STATE_NAME "state"
6884 #define INSN_PARAMETER_NAME "insn"
6886 #define INSN2_PARAMETER_NAME "insn2"
6888 #define CHIP_PARAMETER_NAME "chip"
6890 #define FILE_PARAMETER_NAME "f"
6892 #define CPU_UNIT_NAME_PARAMETER_NAME "cpu_unit_name"
6894 #define CPU_CODE_PARAMETER_NAME "cpu_unit_code"
6896 /* Names of the variables whose values are internal insn code of rtx
6898 #define INTERNAL_INSN_CODE_NAME "insn_code"
6900 #define INTERNAL_INSN2_CODE_NAME "insn2_code"
6902 /* Names of temporary variables in some functions. */
6903 #define TEMPORARY_VARIABLE_NAME "temp"
6905 #define I_VARIABLE_NAME "i"
6907 /* Name of result variable in some functions. */
6908 #define RESULT_VARIABLE_NAME "res"
6910 /* Name of function (attribute) to translate insn into internal insn
6912 #define INTERNAL_DFA_INSN_CODE_FUNC_NAME "internal_dfa_insn_code"
6914 /* Name of function (attribute) to translate insn into internal insn
6915 code with caching. */
6916 #define DFA_INSN_CODE_FUNC_NAME "dfa_insn_code"
6918 /* Output C type which is used for representation of codes of states
6921 output_state_member_type (FILE *f
, automaton_t automaton
)
6923 output_range_type (f
, 0, automaton
->achieved_states_num
);
6926 /* Output definition of the structure representing current DFA(s)
6929 output_chip_definitions (void)
6931 automaton_t automaton
;
6933 fprintf (output_file
, "struct %s\n{\n", CHIP_NAME
);
6934 for (automaton
= description
->first_automaton
;
6936 automaton
= automaton
->next_automaton
)
6938 fprintf (output_file
, " ");
6939 output_state_member_type (output_file
, automaton
);
6940 fprintf (output_file
, " ");
6941 output_chip_member_name (output_file
, automaton
);
6942 fprintf (output_file
, ";\n");
6944 fprintf (output_file
, "};\n\n");
6946 fprintf (output_file
, "static struct %s %s;\n\n", CHIP_NAME
, CHIP_NAME
);
6951 /* The function outputs translate vector of internal insn code into
6952 insn equivalence class number. The equivalence class number is
6953 used to access to table and vectors representing DFA(s). */
6955 output_translate_vect (automaton_t automaton
)
6959 vla_hwint_t translate_vect
;
6961 translate_vect
= VEC_alloc (vect_el_t
,heap
, description
->insns_num
);
6963 for (insn_value
= 0; insn_value
< description
->insns_num
; insn_value
++)
6964 /* Undefined value */
6965 VEC_quick_push (vect_el_t
, translate_vect
,
6966 automaton
->insn_equiv_classes_num
);
6968 for (ainsn
= automaton
->ainsn_list
; ainsn
!= NULL
; ainsn
= ainsn
->next_ainsn
)
6969 VEC_replace (vect_el_t
, translate_vect
,
6970 ainsn
->insn_reserv_decl
->insn_num
,
6971 ainsn
->insn_equiv_class_num
);
6973 fprintf (output_file
,
6974 "/* Vector translating external insn codes to internal ones.*/\n");
6975 fprintf (output_file
, "static const ");
6976 output_range_type (output_file
, 0, automaton
->insn_equiv_classes_num
);
6977 fprintf (output_file
, " ");
6978 output_translate_vect_name (output_file
, automaton
);
6979 fprintf (output_file
, "[] ATTRIBUTE_UNUSED = {\n");
6980 output_vect (translate_vect
);
6981 fprintf (output_file
, "};\n\n");
6982 VEC_free (vect_el_t
,heap
, translate_vect
);
6985 /* The value in a table state x ainsn -> something which represents
6987 static int undefined_vect_el_value
;
6989 /* The following function returns nonzero value if the best
6990 representation of the table is comb vector. */
6992 comb_vect_p (state_ainsn_table_t tab
)
6994 return (2 * VEC_length (vect_el_t
, tab
->full_vect
)
6995 > 5 * VEC_length (vect_el_t
, tab
->comb_vect
));
6998 /* The following function creates new table for AUTOMATON. */
6999 static state_ainsn_table_t
7000 create_state_ainsn_table (automaton_t automaton
)
7002 state_ainsn_table_t tab
;
7003 int full_vect_length
;
7006 tab
= XCREATENODE (struct state_ainsn_table
);
7007 tab
->automaton
= automaton
;
7009 tab
->comb_vect
= VEC_alloc (vect_el_t
,heap
, 10000);
7010 tab
->check_vect
= VEC_alloc (vect_el_t
,heap
, 10000);
7013 VEC_safe_grow (vect_el_t
,heap
, tab
->base_vect
,
7014 automaton
->achieved_states_num
);
7016 full_vect_length
= (automaton
->insn_equiv_classes_num
7017 * automaton
->achieved_states_num
);
7018 tab
->full_vect
= VEC_alloc (vect_el_t
,heap
, full_vect_length
);
7019 for (i
= 0; i
< full_vect_length
; i
++)
7020 VEC_quick_push (vect_el_t
, tab
->full_vect
, undefined_vect_el_value
);
7022 tab
->min_base_vect_el_value
= 0;
7023 tab
->max_base_vect_el_value
= 0;
7024 tab
->min_comb_vect_el_value
= 0;
7025 tab
->max_comb_vect_el_value
= 0;
7029 /* The following function outputs the best C representation of the
7030 table TAB of given TABLE_NAME. */
7032 output_state_ainsn_table (state_ainsn_table_t tab
, const char *table_name
,
7033 void (*output_full_vect_name_func
) (FILE *, automaton_t
),
7034 void (*output_comb_vect_name_func
) (FILE *, automaton_t
),
7035 void (*output_check_vect_name_func
) (FILE *, automaton_t
),
7036 void (*output_base_vect_name_func
) (FILE *, automaton_t
))
7038 if (!comb_vect_p (tab
))
7040 fprintf (output_file
, "/* Vector for %s. */\n", table_name
);
7041 fprintf (output_file
, "static const ");
7042 output_range_type (output_file
, tab
->min_comb_vect_el_value
,
7043 tab
->max_comb_vect_el_value
);
7044 fprintf (output_file
, " ");
7045 (*output_full_vect_name_func
) (output_file
, tab
->automaton
);
7046 fprintf (output_file
, "[] ATTRIBUTE_UNUSED = {\n");
7047 output_vect (tab
->full_vect
);
7048 fprintf (output_file
, "};\n\n");
7052 fprintf (output_file
, "/* Comb vector for %s. */\n", table_name
);
7053 fprintf (output_file
, "static const ");
7054 output_range_type (output_file
, tab
->min_comb_vect_el_value
,
7055 tab
->max_comb_vect_el_value
);
7056 fprintf (output_file
, " ");
7057 (*output_comb_vect_name_func
) (output_file
, tab
->automaton
);
7058 fprintf (output_file
, "[] ATTRIBUTE_UNUSED = {\n");
7059 output_vect (tab
->comb_vect
);
7060 fprintf (output_file
, "};\n\n");
7061 fprintf (output_file
, "/* Check vector for %s. */\n", table_name
);
7062 fprintf (output_file
, "static const ");
7063 output_range_type (output_file
, 0, tab
->automaton
->achieved_states_num
);
7064 fprintf (output_file
, " ");
7065 (*output_check_vect_name_func
) (output_file
, tab
->automaton
);
7066 fprintf (output_file
, "[] = {\n");
7067 output_vect (tab
->check_vect
);
7068 fprintf (output_file
, "};\n\n");
7069 fprintf (output_file
, "/* Base vector for %s. */\n", table_name
);
7070 fprintf (output_file
, "static const ");
7071 output_range_type (output_file
, tab
->min_base_vect_el_value
,
7072 tab
->max_base_vect_el_value
);
7073 fprintf (output_file
, " ");
7074 (*output_base_vect_name_func
) (output_file
, tab
->automaton
);
7075 fprintf (output_file
, "[] = {\n");
7076 output_vect (tab
->base_vect
);
7077 fprintf (output_file
, "};\n\n");
7081 /* The following function adds vector VECT to table TAB as its line
7082 with number VECT_NUM. */
7084 add_vect (state_ainsn_table_t tab
, int vect_num
, vla_hwint_t vect
)
7087 size_t real_vect_length
;
7088 int comb_vect_index
;
7089 int comb_vect_els_num
;
7091 int first_unempty_vect_index
;
7092 int additional_els_num
;
7096 unsigned long vect_mask
, comb_vect_mask
;
7098 vect_length
= VEC_length (vect_el_t
, vect
);
7099 gcc_assert (vect_length
);
7100 gcc_assert (VEC_last (vect_el_t
, vect
) != undefined_vect_el_value
);
7101 real_vect_length
= tab
->automaton
->insn_equiv_classes_num
;
7102 /* Form full vector in the table: */
7104 size_t full_base
= tab
->automaton
->insn_equiv_classes_num
* vect_num
;
7105 if (VEC_length (vect_el_t
, tab
->full_vect
) < full_base
+ vect_length
)
7106 VEC_safe_grow (vect_el_t
,heap
, tab
->full_vect
,
7107 full_base
+ vect_length
);
7108 for (i
= 0; i
< vect_length
; i
++)
7109 VEC_replace (vect_el_t
, tab
->full_vect
, full_base
+ i
,
7110 VEC_index (vect_el_t
, vect
, i
));
7112 /* Form comb vector in the table: */
7113 gcc_assert (VEC_length (vect_el_t
, tab
->comb_vect
)
7114 == VEC_length (vect_el_t
, tab
->check_vect
));
7116 comb_vect_els_num
= VEC_length (vect_el_t
, tab
->comb_vect
);
7117 for (first_unempty_vect_index
= 0;
7118 first_unempty_vect_index
< vect_length
;
7119 first_unempty_vect_index
++)
7120 if (VEC_index (vect_el_t
, vect
, first_unempty_vect_index
)
7121 != undefined_vect_el_value
)
7124 /* Search for the place in comb vect for the inserted vect. */
7127 if (vect_length
- first_unempty_vect_index
>= SIZEOF_LONG
* CHAR_BIT
)
7129 for (comb_vect_index
= 0;
7130 comb_vect_index
< comb_vect_els_num
;
7133 for (vect_index
= first_unempty_vect_index
;
7134 vect_index
< vect_length
7135 && vect_index
+ comb_vect_index
< comb_vect_els_num
;
7137 if (VEC_index (vect_el_t
, vect
, vect_index
)
7138 != undefined_vect_el_value
7139 && (VEC_index (vect_el_t
, tab
->comb_vect
,
7140 vect_index
+ comb_vect_index
)
7141 != undefined_vect_el_value
))
7143 if (vect_index
>= vect_length
7144 || vect_index
+ comb_vect_index
>= comb_vect_els_num
)
7152 for (vect_index
= first_unempty_vect_index
;
7153 vect_index
< vect_length
;
7156 vect_mask
= vect_mask
<< 1;
7157 if (VEC_index (vect_el_t
, vect
, vect_index
) != undefined_vect_el_value
)
7161 /* Search for the place in comb vect for the inserted vect. */
7162 comb_vect_index
= 0;
7163 if (comb_vect_els_num
== 0)
7167 for (vect_index
= first_unempty_vect_index
;
7168 vect_index
< vect_length
&& vect_index
< comb_vect_els_num
;
7171 comb_vect_mask
<<= 1;
7172 if (vect_index
+ comb_vect_index
< comb_vect_els_num
7173 && VEC_index (vect_el_t
, tab
->comb_vect
, vect_index
+ comb_vect_index
)
7174 != undefined_vect_el_value
)
7175 comb_vect_mask
|= 1;
7177 if ((vect_mask
& comb_vect_mask
) == 0)
7180 for (comb_vect_index
= 1, i
= vect_length
; i
< comb_vect_els_num
;
7181 comb_vect_index
++, i
++)
7183 comb_vect_mask
= (comb_vect_mask
<< 1) | 1;
7184 comb_vect_mask
^= (VEC_index (vect_el_t
, tab
->comb_vect
, i
)
7185 == undefined_vect_el_value
);
7186 if ((vect_mask
& comb_vect_mask
) == 0)
7189 for ( ; comb_vect_index
< comb_vect_els_num
; comb_vect_index
++)
7191 comb_vect_mask
<<= 1;
7192 if ((vect_mask
& comb_vect_mask
) == 0)
7197 /* Slot was found. */
7198 additional_els_num
= comb_vect_index
+ real_vect_length
- comb_vect_els_num
;
7199 if (additional_els_num
< 0)
7200 additional_els_num
= 0;
7201 /* Expand comb and check vectors. */
7202 vect_el
= undefined_vect_el_value
;
7203 no_state_value
= tab
->automaton
->achieved_states_num
;
7204 while (additional_els_num
> 0)
7206 VEC_safe_push (vect_el_t
,heap
, tab
->comb_vect
, vect_el
);
7207 VEC_safe_push (vect_el_t
,heap
, tab
->check_vect
, no_state_value
);
7208 additional_els_num
--;
7210 gcc_assert (VEC_length (vect_el_t
, tab
->comb_vect
)
7211 >= comb_vect_index
+ real_vect_length
);
7212 /* Fill comb and check vectors. */
7213 for (vect_index
= 0; vect_index
< vect_length
; vect_index
++)
7214 if (VEC_index (vect_el_t
, vect
, vect_index
) != undefined_vect_el_value
)
7216 vect_el_t x
= VEC_index (vect_el_t
, vect
, vect_index
);
7217 gcc_assert (VEC_index (vect_el_t
, tab
->comb_vect
,
7218 comb_vect_index
+ vect_index
)
7219 == undefined_vect_el_value
);
7220 gcc_assert (x
>= 0);
7221 if (tab
->max_comb_vect_el_value
< x
)
7222 tab
->max_comb_vect_el_value
= x
;
7223 if (tab
->min_comb_vect_el_value
> x
)
7224 tab
->min_comb_vect_el_value
= x
;
7225 VEC_replace (vect_el_t
, tab
->comb_vect
,
7226 comb_vect_index
+ vect_index
, x
);
7227 VEC_replace (vect_el_t
, tab
->check_vect
,
7228 comb_vect_index
+ vect_index
, vect_num
);
7230 if (tab
->max_comb_vect_el_value
< undefined_vect_el_value
)
7231 tab
->max_comb_vect_el_value
= undefined_vect_el_value
;
7232 if (tab
->min_comb_vect_el_value
> undefined_vect_el_value
)
7233 tab
->min_comb_vect_el_value
= undefined_vect_el_value
;
7234 if (tab
->max_base_vect_el_value
< comb_vect_index
)
7235 tab
->max_base_vect_el_value
= comb_vect_index
;
7236 if (tab
->min_base_vect_el_value
> comb_vect_index
)
7237 tab
->min_base_vect_el_value
= comb_vect_index
;
7239 VEC_replace (vect_el_t
, tab
->base_vect
, vect_num
, comb_vect_index
);
7242 /* Return number of out arcs of STATE. */
7244 out_state_arcs_num (const_state_t state
)
7250 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
7252 gcc_assert (arc
->insn
);
7253 if (arc
->insn
->first_ainsn_with_given_equivalence_num
)
7259 /* Compare number of possible transitions from the states. */
7261 compare_transition_els_num (const void *state_ptr_1
,
7262 const void *state_ptr_2
)
7264 const int transition_els_num_1
7265 = out_state_arcs_num (*(const_state_t
const*) state_ptr_1
);
7266 const int transition_els_num_2
7267 = out_state_arcs_num (*(const_state_t
const*) state_ptr_2
);
7269 if (transition_els_num_1
< transition_els_num_2
)
7271 else if (transition_els_num_1
== transition_els_num_2
)
7277 /* The function adds element EL_VALUE to vector VECT for a table state
7280 add_vect_el (vla_hwint_t
*vect
, ainsn_t ainsn
, int el_value
)
7282 int equiv_class_num
;
7286 equiv_class_num
= ainsn
->insn_equiv_class_num
;
7287 for (vect_index
= VEC_length (vect_el_t
, *vect
);
7288 vect_index
<= equiv_class_num
;
7290 VEC_safe_push (vect_el_t
,heap
, *vect
, undefined_vect_el_value
);
7291 VEC_replace (vect_el_t
, *vect
, equiv_class_num
, el_value
);
7294 /* This is for forming vector of states of an automaton. */
7295 static VEC(state_t
,heap
) *output_states_vect
;
7297 /* The function is called by function pass_states. The function adds
7298 STATE to `output_states_vect'. */
7300 add_states_vect_el (state_t state
)
7302 VEC_safe_push (state_t
,heap
, output_states_vect
, state
);
7305 /* Form and output vectors (comb, check, base or full vector)
7306 representing transition table of AUTOMATON. */
7308 output_trans_table (automaton_t automaton
)
7312 vla_hwint_t transition_vect
= 0;
7314 undefined_vect_el_value
= automaton
->achieved_states_num
;
7315 automaton
->trans_table
= create_state_ainsn_table (automaton
);
7316 /* Create vect of pointers to states ordered by num of transitions
7317 from the state (state with the maximum num is the first). */
7318 output_states_vect
= 0;
7319 pass_states (automaton
, add_states_vect_el
);
7320 qsort (VEC_address (state_t
, output_states_vect
),
7321 VEC_length (state_t
, output_states_vect
),
7322 sizeof (state_t
), compare_transition_els_num
);
7324 for (i
= 0; i
< VEC_length (state_t
, output_states_vect
); i
++)
7326 VEC_truncate (vect_el_t
, transition_vect
, 0);
7327 for (arc
= first_out_arc (VEC_index (state_t
, output_states_vect
, i
));
7329 arc
= next_out_arc (arc
))
7331 gcc_assert (arc
->insn
);
7332 if (arc
->insn
->first_ainsn_with_given_equivalence_num
)
7333 add_vect_el (&transition_vect
, arc
->insn
,
7334 arc
->to_state
->order_state_num
);
7336 add_vect (automaton
->trans_table
,
7337 VEC_index (state_t
, output_states_vect
, i
)->order_state_num
,
7340 output_state_ainsn_table
7341 (automaton
->trans_table
, "state transitions",
7342 output_trans_full_vect_name
, output_trans_comb_vect_name
,
7343 output_trans_check_vect_name
, output_trans_base_vect_name
);
7345 VEC_free (state_t
,heap
, output_states_vect
);
7346 VEC_free (vect_el_t
,heap
, transition_vect
);
7349 /* The current number of passing states to find minimal issue delay
7350 value for an ainsn and state. */
7351 static int curr_state_pass_num
;
7353 /* This recursive function passes states to find minimal issue delay
7354 value for AINSN. The state being visited is STATE. The function
7355 returns minimal issue delay value for AINSN in STATE or -1 if we
7356 enter into a loop. */
7358 min_issue_delay_pass_states (state_t state
, ainsn_t ainsn
)
7361 int min_insn_issue_delay
, insn_issue_delay
;
7363 if (state
->state_pass_num
== curr_state_pass_num
7364 || state
->min_insn_issue_delay
!= -1)
7365 /* We've entered into a loop or already have the correct value for
7366 given state and ainsn. */
7367 return state
->min_insn_issue_delay
;
7368 state
->state_pass_num
= curr_state_pass_num
;
7369 min_insn_issue_delay
= -1;
7370 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
7371 if (arc
->insn
== ainsn
)
7373 min_insn_issue_delay
= 0;
7378 insn_issue_delay
= min_issue_delay_pass_states (arc
->to_state
, ainsn
);
7379 if (insn_issue_delay
!= -1)
7381 if (arc
->insn
->insn_reserv_decl
7382 == DECL_INSN_RESERV (advance_cycle_insn_decl
))
7384 if (min_insn_issue_delay
== -1
7385 || min_insn_issue_delay
> insn_issue_delay
)
7387 min_insn_issue_delay
= insn_issue_delay
;
7388 if (insn_issue_delay
== 0)
7393 return min_insn_issue_delay
;
7396 /* The function searches minimal issue delay value for AINSN in STATE.
7397 The function can return negative value if we can not issue AINSN. We
7398 will report about it later. */
7400 min_issue_delay (state_t state
, ainsn_t ainsn
)
7402 curr_state_pass_num
++;
7403 state
->min_insn_issue_delay
= min_issue_delay_pass_states (state
, ainsn
);
7404 return state
->min_insn_issue_delay
;
7407 /* The function initiates code for finding minimal issue delay values.
7408 It should be called only once. */
7410 initiate_min_issue_delay_pass_states (void)
7412 curr_state_pass_num
= 0;
7415 /* Form and output vectors representing minimal issue delay table of
7416 AUTOMATON. The table is state x ainsn -> minimal issue delay of
7419 output_min_issue_delay_table (automaton_t automaton
)
7421 vla_hwint_t min_issue_delay_vect
;
7422 vla_hwint_t compressed_min_issue_delay_vect
;
7423 vect_el_t min_delay
;
7425 size_t i
, min_issue_delay_len
;
7426 size_t compressed_min_issue_delay_len
;
7429 /* Create vect of pointers to states ordered by num of transitions
7430 from the state (state with the maximum num is the first). */
7431 output_states_vect
= 0;
7432 pass_states (automaton
, add_states_vect_el
);
7434 min_issue_delay_len
= (VEC_length (state_t
, output_states_vect
)
7435 * automaton
->insn_equiv_classes_num
);
7436 min_issue_delay_vect
= VEC_alloc (vect_el_t
,heap
, min_issue_delay_len
);
7437 for (i
= 0; i
< min_issue_delay_len
; i
++)
7438 VEC_quick_push (vect_el_t
, min_issue_delay_vect
, 0);
7440 automaton
->max_min_delay
= 0;
7441 for (ainsn
= automaton
->ainsn_list
; ainsn
!= NULL
; ainsn
= ainsn
->next_ainsn
)
7442 if (ainsn
->first_ainsn_with_given_equivalence_num
)
7444 for (i
= 0; i
< VEC_length (state_t
, output_states_vect
); i
++)
7445 VEC_index (state_t
, output_states_vect
, i
)->min_insn_issue_delay
= -1;
7446 for (i
= 0; i
< VEC_length (state_t
, output_states_vect
); i
++)
7448 state_t s
= VEC_index (state_t
, output_states_vect
, i
);
7449 min_delay
= min_issue_delay (s
, ainsn
);
7450 if (automaton
->max_min_delay
< min_delay
)
7451 automaton
->max_min_delay
= min_delay
;
7452 VEC_replace (vect_el_t
, min_issue_delay_vect
,
7454 * automaton
->insn_equiv_classes_num
7455 + ainsn
->insn_equiv_class_num
,
7459 fprintf (output_file
, "/* Vector of min issue delay of insns. */\n");
7460 fprintf (output_file
, "static const ");
7461 output_range_type (output_file
, 0, automaton
->max_min_delay
);
7462 fprintf (output_file
, " ");
7463 output_min_issue_delay_vect_name (output_file
, automaton
);
7464 fprintf (output_file
, "[] ATTRIBUTE_UNUSED = {\n");
7465 /* Compress the vector. */
7466 if (automaton
->max_min_delay
< 2)
7468 else if (automaton
->max_min_delay
< 4)
7470 else if (automaton
->max_min_delay
< 16)
7474 automaton
->min_issue_delay_table_compression_factor
= cfactor
;
7476 compressed_min_issue_delay_len
= (min_issue_delay_len
+cfactor
-1) / cfactor
;
7477 compressed_min_issue_delay_vect
7478 = VEC_alloc (vect_el_t
,heap
, compressed_min_issue_delay_len
);
7480 for (i
= 0; i
< compressed_min_issue_delay_len
; i
++)
7481 VEC_quick_push (vect_el_t
, compressed_min_issue_delay_vect
, 0);
7483 for (i
= 0; i
< min_issue_delay_len
; i
++)
7485 size_t ci
= i
/ cfactor
;
7486 vect_el_t x
= VEC_index (vect_el_t
, min_issue_delay_vect
, i
);
7487 vect_el_t cx
= VEC_index (vect_el_t
, compressed_min_issue_delay_vect
, ci
);
7489 cx
|= x
<< (8 - (i
% cfactor
+ 1) * (8 / cfactor
));
7490 VEC_replace (vect_el_t
, compressed_min_issue_delay_vect
, ci
, cx
);
7492 output_vect (compressed_min_issue_delay_vect
);
7493 fprintf (output_file
, "};\n\n");
7494 VEC_free (state_t
,heap
, output_states_vect
);
7495 VEC_free (vect_el_t
,heap
, min_issue_delay_vect
);
7496 VEC_free (vect_el_t
,heap
, compressed_min_issue_delay_vect
);
7499 /* Form and output vector representing the locked states of
7502 output_dead_lock_vect (automaton_t automaton
)
7506 vla_hwint_t dead_lock_vect
= 0;
7508 /* Create vect of pointers to states ordered by num of
7509 transitions from the state (state with the maximum num is the
7511 automaton
->locked_states
= 0;
7512 output_states_vect
= 0;
7513 pass_states (automaton
, add_states_vect_el
);
7515 VEC_safe_grow (vect_el_t
,heap
, dead_lock_vect
,
7516 VEC_length (state_t
, output_states_vect
));
7517 for (i
= 0; i
< VEC_length (state_t
, output_states_vect
); i
++)
7519 state_t s
= VEC_index (state_t
, output_states_vect
, i
);
7520 arc
= first_out_arc (s
);
7522 if (next_out_arc (arc
) == NULL
7523 && (arc
->insn
->insn_reserv_decl
7524 == DECL_INSN_RESERV (advance_cycle_insn_decl
)))
7526 VEC_replace (vect_el_t
, dead_lock_vect
, s
->order_state_num
, 1);
7527 automaton
->locked_states
++;
7530 VEC_replace (vect_el_t
, dead_lock_vect
, s
->order_state_num
, 0);
7532 if (automaton
->locked_states
== 0)
7535 fprintf (output_file
, "/* Vector for locked state flags. */\n");
7536 fprintf (output_file
, "static const ");
7537 output_range_type (output_file
, 0, 1);
7538 fprintf (output_file
, " ");
7539 output_dead_lock_vect_name (output_file
, automaton
);
7540 fprintf (output_file
, "[] = {\n");
7541 output_vect (dead_lock_vect
);
7542 fprintf (output_file
, "};\n\n");
7543 VEC_free (state_t
,heap
, output_states_vect
);
7544 VEC_free (vect_el_t
,heap
, dead_lock_vect
);
7547 /* Form and output vector representing reserved units of the states of
7550 output_reserved_units_table (automaton_t automaton
)
7552 vla_hwint_t reserved_units_table
= 0;
7553 int state_byte_size
;
7554 int reserved_units_size
;
7558 if (description
->query_units_num
== 0)
7561 /* Create vect of pointers to states. */
7562 output_states_vect
= 0;
7563 pass_states (automaton
, add_states_vect_el
);
7564 /* Create vector. */
7565 state_byte_size
= (description
->query_units_num
+ 7) / 8;
7566 reserved_units_size
= (VEC_length (state_t
, output_states_vect
)
7569 reserved_units_table
= VEC_alloc (vect_el_t
,heap
, reserved_units_size
);
7571 for (i
= 0; i
< reserved_units_size
; i
++)
7572 VEC_quick_push (vect_el_t
, reserved_units_table
, 0);
7573 for (n
= 0; n
< VEC_length (state_t
, output_states_vect
); n
++)
7575 state_t s
= VEC_index (state_t
, output_states_vect
, n
);
7576 for (i
= 0; i
< description
->units_num
; i
++)
7577 if (units_array
[i
]->query_p
7578 && first_cycle_unit_presence (s
, i
))
7580 int ri
= (s
->order_state_num
* state_byte_size
7581 + units_array
[i
]->query_num
/ 8);
7582 vect_el_t x
= VEC_index (vect_el_t
, reserved_units_table
, ri
);
7584 x
+= 1 << (units_array
[i
]->query_num
% 8);
7585 VEC_replace (vect_el_t
, reserved_units_table
, ri
, x
);
7588 fprintf (output_file
, "\n#if %s\n", CPU_UNITS_QUERY_MACRO_NAME
);
7589 fprintf (output_file
, "/* Vector for reserved units of states. */\n");
7590 fprintf (output_file
, "static const ");
7591 output_range_type (output_file
, 0, 255);
7592 fprintf (output_file
, " ");
7593 output_reserved_units_table_name (output_file
, automaton
);
7594 fprintf (output_file
, "[] = {\n");
7595 output_vect (reserved_units_table
);
7596 fprintf (output_file
, "};\n#endif /* #if %s */\n\n",
7597 CPU_UNITS_QUERY_MACRO_NAME
);
7599 VEC_free (state_t
,heap
, output_states_vect
);
7600 VEC_free (vect_el_t
,heap
, reserved_units_table
);
7603 /* The function outputs all tables representing DFA(s) used for fast
7604 pipeline hazards recognition. */
7606 output_tables (void)
7608 automaton_t automaton
;
7610 initiate_min_issue_delay_pass_states ();
7611 for (automaton
= description
->first_automaton
;
7613 automaton
= automaton
->next_automaton
)
7615 output_translate_vect (automaton
);
7616 output_trans_table (automaton
);
7617 output_min_issue_delay_table (automaton
);
7618 output_dead_lock_vect (automaton
);
7619 output_reserved_units_table (automaton
);
7621 fprintf (output_file
, "\n#define %s %d\n\n", ADVANCE_CYCLE_VALUE_NAME
,
7622 DECL_INSN_RESERV (advance_cycle_insn_decl
)->insn_num
);
7625 /* The function outputs definition and value of PHR interface variable
7626 `max_insn_queue_index'. Its value is not less than maximal queue
7627 length needed for the insn scheduler. */
7629 output_max_insn_queue_index_def (void)
7631 int i
, max
, latency
;
7634 max
= description
->max_insn_reserv_cycles
;
7635 for (i
= 0; i
< description
->decls_num
; i
++)
7637 decl
= description
->decls
[i
];
7638 if (decl
->mode
== dm_insn_reserv
&& decl
!= advance_cycle_insn_decl
)
7640 latency
= DECL_INSN_RESERV (decl
)->default_latency
;
7644 else if (decl
->mode
== dm_bypass
)
7646 latency
= DECL_BYPASS (decl
)->latency
;
7651 for (i
= 0; (1 << i
) <= max
; i
++)
7653 gcc_assert (i
>= 0);
7654 fprintf (output_file
, "\nconst int max_insn_queue_index = %d;\n\n",
7658 /* The function outputs switch cases for insn reservations using
7659 function *output_automata_list_code. */
7661 output_insn_code_cases (void (*output_automata_list_code
)
7662 (automata_list_el_t
))
7667 for (i
= 0; i
< description
->decls_num
; i
++)
7669 decl
= description
->decls
[i
];
7670 if (decl
->mode
== dm_insn_reserv
)
7671 DECL_INSN_RESERV (decl
)->processed_p
= FALSE
;
7673 for (i
= 0; i
< description
->decls_num
; i
++)
7675 decl
= description
->decls
[i
];
7676 if (decl
->mode
== dm_insn_reserv
7677 && !DECL_INSN_RESERV (decl
)->processed_p
)
7679 for (j
= i
; j
< description
->decls_num
; j
++)
7681 decl2
= description
->decls
[j
];
7682 if (decl2
->mode
== dm_insn_reserv
7683 && (DECL_INSN_RESERV (decl2
)->important_automata_list
7684 == DECL_INSN_RESERV (decl
)->important_automata_list
))
7686 DECL_INSN_RESERV (decl2
)->processed_p
= TRUE
;
7687 fprintf (output_file
, " case %d: /* %s */\n",
7688 DECL_INSN_RESERV (decl2
)->insn_num
,
7689 DECL_INSN_RESERV (decl2
)->name
);
7692 (*output_automata_list_code
)
7693 (DECL_INSN_RESERV (decl
)->important_automata_list
);
7699 /* The function outputs a code for evaluation of a minimal delay of
7700 issue of insns which have reservations in given AUTOMATA_LIST. */
7702 output_automata_list_min_issue_delay_code (automata_list_el_t automata_list
)
7704 automata_list_el_t el
;
7705 automaton_t automaton
;
7707 for (el
= automata_list
; el
!= NULL
; el
= el
->next_automata_list_el
)
7709 automaton
= el
->automaton
;
7710 fprintf (output_file
, "\n %s = ", TEMPORARY_VARIABLE_NAME
);
7711 output_min_issue_delay_vect_name (output_file
, automaton
);
7712 fprintf (output_file
,
7713 (automaton
->min_issue_delay_table_compression_factor
!= 1
7715 output_translate_vect_name (output_file
, automaton
);
7716 fprintf (output_file
, " [%s] + ", INTERNAL_INSN_CODE_NAME
);
7717 fprintf (output_file
, "%s->", CHIP_PARAMETER_NAME
);
7718 output_chip_member_name (output_file
, automaton
);
7719 fprintf (output_file
, " * %d", automaton
->insn_equiv_classes_num
);
7720 if (automaton
->min_issue_delay_table_compression_factor
== 1)
7721 fprintf (output_file
, "];\n");
7724 fprintf (output_file
, ") / %d];\n",
7725 automaton
->min_issue_delay_table_compression_factor
);
7726 fprintf (output_file
, " %s = (%s >> (8 - (",
7727 TEMPORARY_VARIABLE_NAME
, TEMPORARY_VARIABLE_NAME
);
7728 output_translate_vect_name (output_file
, automaton
);
7730 (output_file
, " [%s] %% %d + 1) * %d)) & %d;\n",
7731 INTERNAL_INSN_CODE_NAME
,
7732 automaton
->min_issue_delay_table_compression_factor
,
7733 8 / automaton
->min_issue_delay_table_compression_factor
,
7734 (1 << (8 / automaton
->min_issue_delay_table_compression_factor
))
7737 if (el
== automata_list
)
7738 fprintf (output_file
, " %s = %s;\n",
7739 RESULT_VARIABLE_NAME
, TEMPORARY_VARIABLE_NAME
);
7742 fprintf (output_file
, " if (%s > %s)\n",
7743 TEMPORARY_VARIABLE_NAME
, RESULT_VARIABLE_NAME
);
7744 fprintf (output_file
, " %s = %s;\n",
7745 RESULT_VARIABLE_NAME
, TEMPORARY_VARIABLE_NAME
);
7748 fprintf (output_file
, " break;\n\n");
7751 /* Output function `internal_min_issue_delay'. */
7753 output_internal_min_issue_delay_func (void)
7755 fprintf (output_file
,
7756 "static int\n%s (int %s, struct %s *%s ATTRIBUTE_UNUSED)\n",
7757 INTERNAL_MIN_ISSUE_DELAY_FUNC_NAME
, INTERNAL_INSN_CODE_NAME
,
7758 CHIP_NAME
, CHIP_PARAMETER_NAME
);
7759 fprintf (output_file
, "{\n int %s ATTRIBUTE_UNUSED;\n int %s = -1;\n",
7760 TEMPORARY_VARIABLE_NAME
, RESULT_VARIABLE_NAME
);
7761 fprintf (output_file
, "\n switch (%s)\n {\n", INTERNAL_INSN_CODE_NAME
);
7762 output_insn_code_cases (output_automata_list_min_issue_delay_code
);
7763 fprintf (output_file
,
7764 "\n default:\n %s = -1;\n break;\n }\n",
7765 RESULT_VARIABLE_NAME
);
7766 fprintf (output_file
, " return %s;\n", RESULT_VARIABLE_NAME
);
7767 fprintf (output_file
, "}\n\n");
7770 /* The function outputs a code changing state after issue of insns
7771 which have reservations in given AUTOMATA_LIST. */
7773 output_automata_list_transition_code (automata_list_el_t automata_list
)
7775 automata_list_el_t el
, next_el
;
7777 fprintf (output_file
, " {\n");
7778 if (automata_list
!= NULL
&& automata_list
->next_automata_list_el
!= NULL
)
7779 for (el
= automata_list
;; el
= next_el
)
7781 next_el
= el
->next_automata_list_el
;
7782 if (next_el
== NULL
)
7784 fprintf (output_file
, " ");
7785 output_state_member_type (output_file
, el
->automaton
);
7786 fprintf (output_file
, " ");
7787 output_temp_chip_member_name (output_file
, el
->automaton
);
7788 fprintf (output_file
, ";\n");
7790 for (el
= automata_list
; el
!= NULL
; el
= el
->next_automata_list_el
)
7791 if (comb_vect_p (el
->automaton
->trans_table
))
7793 fprintf (output_file
, "\n %s = ", TEMPORARY_VARIABLE_NAME
);
7794 output_trans_base_vect_name (output_file
, el
->automaton
);
7795 fprintf (output_file
, " [%s->", CHIP_PARAMETER_NAME
);
7796 output_chip_member_name (output_file
, el
->automaton
);
7797 fprintf (output_file
, "] + ");
7798 output_translate_vect_name (output_file
, el
->automaton
);
7799 fprintf (output_file
, " [%s];\n", INTERNAL_INSN_CODE_NAME
);
7800 fprintf (output_file
, " if (");
7801 output_trans_check_vect_name (output_file
, el
->automaton
);
7802 fprintf (output_file
, " [%s] != %s->",
7803 TEMPORARY_VARIABLE_NAME
, CHIP_PARAMETER_NAME
);
7804 output_chip_member_name (output_file
, el
->automaton
);
7805 fprintf (output_file
, ")\n");
7806 fprintf (output_file
, " return %s (%s, %s);\n",
7807 INTERNAL_MIN_ISSUE_DELAY_FUNC_NAME
, INTERNAL_INSN_CODE_NAME
,
7808 CHIP_PARAMETER_NAME
);
7809 fprintf (output_file
, " else\n");
7810 fprintf (output_file
, " ");
7811 if (el
->next_automata_list_el
!= NULL
)
7812 output_temp_chip_member_name (output_file
, el
->automaton
);
7815 fprintf (output_file
, "%s->", CHIP_PARAMETER_NAME
);
7816 output_chip_member_name (output_file
, el
->automaton
);
7818 fprintf (output_file
, " = ");
7819 output_trans_comb_vect_name (output_file
, el
->automaton
);
7820 fprintf (output_file
, " [%s];\n", TEMPORARY_VARIABLE_NAME
);
7824 fprintf (output_file
, "\n %s = ", TEMPORARY_VARIABLE_NAME
);
7825 output_trans_full_vect_name (output_file
, el
->automaton
);
7826 fprintf (output_file
, " [");
7827 output_translate_vect_name (output_file
, el
->automaton
);
7828 fprintf (output_file
, " [%s] + ", INTERNAL_INSN_CODE_NAME
);
7829 fprintf (output_file
, "%s->", CHIP_PARAMETER_NAME
);
7830 output_chip_member_name (output_file
, el
->automaton
);
7831 fprintf (output_file
, " * %d];\n",
7832 el
->automaton
->insn_equiv_classes_num
);
7833 fprintf (output_file
, " if (%s >= %d)\n",
7834 TEMPORARY_VARIABLE_NAME
, el
->automaton
->achieved_states_num
);
7835 fprintf (output_file
, " return %s (%s, %s);\n",
7836 INTERNAL_MIN_ISSUE_DELAY_FUNC_NAME
, INTERNAL_INSN_CODE_NAME
,
7837 CHIP_PARAMETER_NAME
);
7838 fprintf (output_file
, " else\n ");
7839 if (el
->next_automata_list_el
!= NULL
)
7840 output_temp_chip_member_name (output_file
, el
->automaton
);
7843 fprintf (output_file
, "%s->", CHIP_PARAMETER_NAME
);
7844 output_chip_member_name (output_file
, el
->automaton
);
7846 fprintf (output_file
, " = %s;\n", TEMPORARY_VARIABLE_NAME
);
7848 if (automata_list
!= NULL
&& automata_list
->next_automata_list_el
!= NULL
)
7849 for (el
= automata_list
;; el
= next_el
)
7851 next_el
= el
->next_automata_list_el
;
7852 if (next_el
== NULL
)
7854 fprintf (output_file
, " %s->", CHIP_PARAMETER_NAME
);
7855 output_chip_member_name (output_file
, el
->automaton
);
7856 fprintf (output_file
, " = ");
7857 output_temp_chip_member_name (output_file
, el
->automaton
);
7858 fprintf (output_file
, ";\n");
7860 fprintf (output_file
, " return -1;\n");
7861 fprintf (output_file
, " }\n");
7864 /* Output function `internal_state_transition'. */
7866 output_internal_trans_func (void)
7868 fprintf (output_file
,
7869 "static int\n%s (int %s, struct %s *%s ATTRIBUTE_UNUSED)\n",
7870 INTERNAL_TRANSITION_FUNC_NAME
, INTERNAL_INSN_CODE_NAME
,
7871 CHIP_NAME
, CHIP_PARAMETER_NAME
);
7872 fprintf (output_file
, "{\n int %s ATTRIBUTE_UNUSED;\n", TEMPORARY_VARIABLE_NAME
);
7873 fprintf (output_file
, "\n switch (%s)\n {\n", INTERNAL_INSN_CODE_NAME
);
7874 output_insn_code_cases (output_automata_list_transition_code
);
7875 fprintf (output_file
, "\n default:\n return -1;\n }\n");
7876 fprintf (output_file
, "}\n\n");
7883 insn_code = dfa_insn_code (insn);
7884 if (insn_code > DFA__ADVANCE_CYCLE)
7888 insn_code = DFA__ADVANCE_CYCLE;
7890 where insn denotes INSN_NAME, insn_code denotes INSN_CODE_NAME, and
7891 code denotes CODE. */
7893 output_internal_insn_code_evaluation (const char *insn_name
,
7894 const char *insn_code_name
,
7897 fprintf (output_file
, "\n if (%s != 0)\n {\n", insn_name
);
7898 fprintf (output_file
, " %s = %s (%s);\n", insn_code_name
,
7899 DFA_INSN_CODE_FUNC_NAME
, insn_name
);
7900 fprintf (output_file
, " if (%s > %s)\n return %d;\n",
7901 insn_code_name
, ADVANCE_CYCLE_VALUE_NAME
, code
);
7902 fprintf (output_file
, " }\n else\n %s = %s;\n\n",
7903 insn_code_name
, ADVANCE_CYCLE_VALUE_NAME
);
7907 /* This function outputs `dfa_insn_code' and its helper function
7908 `dfa_insn_code_enlarge'. */
7910 output_dfa_insn_code_func (void)
7912 /* Emacs c-mode gets really confused if there's a { or } in column 0
7913 inside a string, so don't do that. */
7914 fprintf (output_file
, "\
7916 dfa_insn_code_enlarge (int uid)\n\
7920 %s = XRESIZEVEC (int, %s,\n\
7922 for (; i < %s; i++)\n\
7923 %s[i] = -1;\n}\n\n",
7924 DFA_INSN_CODES_LENGTH_VARIABLE_NAME
,
7925 DFA_INSN_CODES_LENGTH_VARIABLE_NAME
,
7926 DFA_INSN_CODES_VARIABLE_NAME
, DFA_INSN_CODES_VARIABLE_NAME
,
7927 DFA_INSN_CODES_LENGTH_VARIABLE_NAME
,
7928 DFA_INSN_CODES_LENGTH_VARIABLE_NAME
,
7929 DFA_INSN_CODES_VARIABLE_NAME
);
7930 fprintf (output_file
, "\
7931 static inline int\n%s (rtx %s)\n\
7933 int uid = INSN_UID (%s);\n\
7935 DFA_INSN_CODE_FUNC_NAME
, INSN_PARAMETER_NAME
,
7936 INSN_PARAMETER_NAME
, INTERNAL_INSN_CODE_NAME
);
7938 fprintf (output_file
,
7939 " if (uid >= %s)\n dfa_insn_code_enlarge (uid);\n\n",
7940 DFA_INSN_CODES_LENGTH_VARIABLE_NAME
);
7941 fprintf (output_file
, " %s = %s[uid];\n",
7942 INTERNAL_INSN_CODE_NAME
, DFA_INSN_CODES_VARIABLE_NAME
);
7943 fprintf (output_file
, "\
7949 INTERNAL_INSN_CODE_NAME
,
7950 INTERNAL_INSN_CODE_NAME
,
7951 INTERNAL_DFA_INSN_CODE_FUNC_NAME
, INSN_PARAMETER_NAME
,
7952 DFA_INSN_CODES_VARIABLE_NAME
, INTERNAL_INSN_CODE_NAME
);
7953 fprintf (output_file
, " return %s;\n}\n\n", INTERNAL_INSN_CODE_NAME
);
7956 /* The function outputs PHR interface function `state_transition'. */
7958 output_trans_func (void)
7960 fprintf (output_file
, "int\n%s (%s %s, rtx %s)\n",
7961 TRANSITION_FUNC_NAME
, STATE_TYPE_NAME
, STATE_NAME
,
7962 INSN_PARAMETER_NAME
);
7963 fprintf (output_file
, "{\n int %s;\n", INTERNAL_INSN_CODE_NAME
);
7964 output_internal_insn_code_evaluation (INSN_PARAMETER_NAME
,
7965 INTERNAL_INSN_CODE_NAME
, -1);
7966 fprintf (output_file
, " return %s (%s, (struct %s *) %s);\n}\n\n",
7967 INTERNAL_TRANSITION_FUNC_NAME
, INTERNAL_INSN_CODE_NAME
, CHIP_NAME
, STATE_NAME
);
7970 /* Output function `min_issue_delay'. */
7972 output_min_issue_delay_func (void)
7974 fprintf (output_file
, "int\n%s (%s %s, rtx %s)\n",
7975 MIN_ISSUE_DELAY_FUNC_NAME
, STATE_TYPE_NAME
, STATE_NAME
,
7976 INSN_PARAMETER_NAME
);
7977 fprintf (output_file
, "{\n int %s;\n", INTERNAL_INSN_CODE_NAME
);
7978 fprintf (output_file
, "\n if (%s != 0)\n {\n", INSN_PARAMETER_NAME
);
7979 fprintf (output_file
, " %s = %s (%s);\n", INTERNAL_INSN_CODE_NAME
,
7980 DFA_INSN_CODE_FUNC_NAME
, INSN_PARAMETER_NAME
);
7981 fprintf (output_file
, " if (%s > %s)\n return 0;\n",
7982 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
);
7983 fprintf (output_file
, " }\n else\n %s = %s;\n",
7984 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
);
7985 fprintf (output_file
, "\n return %s (%s, (struct %s *) %s);\n",
7986 INTERNAL_MIN_ISSUE_DELAY_FUNC_NAME
, INTERNAL_INSN_CODE_NAME
,
7987 CHIP_NAME
, STATE_NAME
);
7988 fprintf (output_file
, "}\n\n");
7991 /* Output function `internal_dead_lock'. */
7993 output_internal_dead_lock_func (void)
7995 automaton_t automaton
;
7997 fprintf (output_file
, "static int\n%s (struct %s *ARG_UNUSED (%s))\n",
7998 INTERNAL_DEAD_LOCK_FUNC_NAME
, CHIP_NAME
, CHIP_PARAMETER_NAME
);
7999 fprintf (output_file
, "{\n");
8000 for (automaton
= description
->first_automaton
;
8002 automaton
= automaton
->next_automaton
)
8003 if (automaton
->locked_states
)
8005 fprintf (output_file
, " if (");
8006 output_dead_lock_vect_name (output_file
, automaton
);
8007 fprintf (output_file
, " [%s->", CHIP_PARAMETER_NAME
);
8008 output_chip_member_name (output_file
, automaton
);
8009 fprintf (output_file
, "])\n return 1/* TRUE */;\n");
8011 fprintf (output_file
, " return 0/* FALSE */;\n}\n\n");
8014 /* The function outputs PHR interface function `state_dead_lock_p'. */
8016 output_dead_lock_func (void)
8018 fprintf (output_file
, "int\n%s (%s %s)\n",
8019 DEAD_LOCK_FUNC_NAME
, STATE_TYPE_NAME
, STATE_NAME
);
8020 fprintf (output_file
, "{\n return %s ((struct %s *) %s);\n}\n\n",
8021 INTERNAL_DEAD_LOCK_FUNC_NAME
, CHIP_NAME
, STATE_NAME
);
8024 /* Output function `internal_reset'. */
8026 output_internal_reset_func (void)
8028 fprintf (output_file
, "static inline void\n%s (struct %s *%s)\n",
8029 INTERNAL_RESET_FUNC_NAME
, CHIP_NAME
, CHIP_PARAMETER_NAME
);
8030 fprintf (output_file
, "{\n memset (%s, 0, sizeof (struct %s));\n}\n\n",
8031 CHIP_PARAMETER_NAME
, CHIP_NAME
);
8034 /* The function outputs PHR interface function `state_size'. */
8036 output_size_func (void)
8038 fprintf (output_file
, "int\n%s (void)\n", SIZE_FUNC_NAME
);
8039 fprintf (output_file
, "{\n return sizeof (struct %s);\n}\n\n", CHIP_NAME
);
8042 /* The function outputs PHR interface function `state_reset'. */
8044 output_reset_func (void)
8046 fprintf (output_file
, "void\n%s (%s %s)\n",
8047 RESET_FUNC_NAME
, STATE_TYPE_NAME
, STATE_NAME
);
8048 fprintf (output_file
, "{\n %s ((struct %s *) %s);\n}\n\n", INTERNAL_RESET_FUNC_NAME
,
8049 CHIP_NAME
, STATE_NAME
);
8052 /* Output function `min_insn_conflict_delay'. */
8054 output_min_insn_conflict_delay_func (void)
8056 fprintf (output_file
,
8057 "int\n%s (%s %s, rtx %s, rtx %s)\n",
8058 MIN_INSN_CONFLICT_DELAY_FUNC_NAME
, STATE_TYPE_NAME
,
8059 STATE_NAME
, INSN_PARAMETER_NAME
, INSN2_PARAMETER_NAME
);
8060 fprintf (output_file
, "{\n struct %s %s;\n int %s, %s, transition;\n",
8061 CHIP_NAME
, CHIP_NAME
, INTERNAL_INSN_CODE_NAME
,
8062 INTERNAL_INSN2_CODE_NAME
);
8063 output_internal_insn_code_evaluation (INSN_PARAMETER_NAME
,
8064 INTERNAL_INSN_CODE_NAME
, 0);
8065 output_internal_insn_code_evaluation (INSN2_PARAMETER_NAME
,
8066 INTERNAL_INSN2_CODE_NAME
, 0);
8067 fprintf (output_file
, " memcpy (&%s, %s, sizeof (%s));\n",
8068 CHIP_NAME
, STATE_NAME
, CHIP_NAME
);
8069 fprintf (output_file
, " %s (&%s);\n", INTERNAL_RESET_FUNC_NAME
, CHIP_NAME
);
8070 fprintf (output_file
, " transition = %s (%s, &%s);\n",
8071 INTERNAL_TRANSITION_FUNC_NAME
, INTERNAL_INSN_CODE_NAME
, CHIP_NAME
);
8072 fprintf (output_file
, " gcc_assert (transition <= 0);\n");
8073 fprintf (output_file
, " return %s (%s, &%s);\n",
8074 INTERNAL_MIN_ISSUE_DELAY_FUNC_NAME
, INTERNAL_INSN2_CODE_NAME
,
8076 fprintf (output_file
, "}\n\n");
8079 /* Output the array holding default latency values. These are used in
8080 insn_latency and maximal_insn_latency function implementations. */
8082 output_default_latencies (void)
8086 const char *tabletype
= "unsigned char";
8088 /* Find the smallest integer type that can hold all the default
8090 for (i
= 0; i
< description
->decls_num
; i
++)
8091 if (description
->decls
[i
]->mode
== dm_insn_reserv
)
8093 decl
= description
->decls
[i
];
8094 if (DECL_INSN_RESERV (decl
)->default_latency
> UCHAR_MAX
8095 && tabletype
[0] != 'i') /* Don't shrink it. */
8096 tabletype
= "unsigned short";
8097 if (DECL_INSN_RESERV (decl
)->default_latency
> USHRT_MAX
)
8101 fprintf (output_file
, " static const %s default_latencies[] =\n {",
8104 for (i
= 0, j
= 0, col
= 7; i
< description
->decls_num
; i
++)
8105 if (description
->decls
[i
]->mode
== dm_insn_reserv
8106 && description
->decls
[i
] != advance_cycle_insn_decl
)
8108 if ((col
= (col
+1) % 8) == 0)
8109 fputs ("\n ", output_file
);
8110 decl
= description
->decls
[i
];
8111 gcc_assert (j
++ == DECL_INSN_RESERV (decl
)->insn_num
);
8112 fprintf (output_file
, "% 4d,",
8113 DECL_INSN_RESERV (decl
)->default_latency
);
8115 gcc_assert (j
== DECL_INSN_RESERV (advance_cycle_insn_decl
)->insn_num
);
8116 fputs ("\n };\n", output_file
);
8119 /* Output function `internal_insn_latency'. */
8121 output_internal_insn_latency_func (void)
8125 struct bypass_decl
*bypass
;
8127 fprintf (output_file
, "static int\n%s (int %s ATTRIBUTE_UNUSED,\n\tint %s ATTRIBUTE_UNUSED,\n\trtx %s ATTRIBUTE_UNUSED,\n\trtx %s ATTRIBUTE_UNUSED)\n",
8128 INTERNAL_INSN_LATENCY_FUNC_NAME
, INTERNAL_INSN_CODE_NAME
,
8129 INTERNAL_INSN2_CODE_NAME
, INSN_PARAMETER_NAME
,
8130 INSN2_PARAMETER_NAME
);
8131 fprintf (output_file
, "{\n");
8133 if (DECL_INSN_RESERV (advance_cycle_insn_decl
)->insn_num
== 0)
8135 fputs (" return 0;\n}\n\n", output_file
);
8139 fprintf (output_file
, " if (%s >= %s || %s >= %s)\n return 0;\n",
8140 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
,
8141 INTERNAL_INSN2_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
);
8143 fprintf (output_file
, " switch (%s)\n {\n", INTERNAL_INSN_CODE_NAME
);
8144 for (i
= 0; i
< description
->decls_num
; i
++)
8145 if (description
->decls
[i
]->mode
== dm_insn_reserv
8146 && DECL_INSN_RESERV (description
->decls
[i
])->bypass_list
)
8148 decl
= description
->decls
[i
];
8149 fprintf (output_file
,
8150 " case %d:\n switch (%s)\n {\n",
8151 DECL_INSN_RESERV (decl
)->insn_num
,
8152 INTERNAL_INSN2_CODE_NAME
);
8153 for (bypass
= DECL_INSN_RESERV (decl
)->bypass_list
;
8155 bypass
= bypass
->next
)
8157 gcc_assert (bypass
->in_insn_reserv
->insn_num
8158 != (DECL_INSN_RESERV
8159 (advance_cycle_insn_decl
)->insn_num
));
8160 fprintf (output_file
, " case %d:\n",
8161 bypass
->in_insn_reserv
->insn_num
);
8162 if (bypass
->bypass_guard_name
== NULL
)
8163 fprintf (output_file
, " return %d;\n",
8167 fprintf (output_file
,
8168 " if (%s (%s, %s))\n",
8169 bypass
->bypass_guard_name
, INSN_PARAMETER_NAME
,
8170 INSN2_PARAMETER_NAME
);
8171 fprintf (output_file
,
8172 " return %d;\n break;\n",
8176 fputs (" }\n break;\n", output_file
);
8179 fprintf (output_file
, " }\n return default_latencies[%s];\n}\n\n",
8180 INTERNAL_INSN_CODE_NAME
);
8183 /* Output function `internal_maximum_insn_latency'. */
8185 output_internal_maximal_insn_latency_func (void)
8188 struct bypass_decl
*bypass
;
8192 fprintf (output_file
, "static int\n%s (int %s ATTRIBUTE_UNUSED,\n\trtx %s ATTRIBUTE_UNUSED)\n",
8193 "internal_maximal_insn_latency", INTERNAL_INSN_CODE_NAME
,
8194 INSN_PARAMETER_NAME
);
8195 fprintf (output_file
, "{\n");
8197 if (DECL_INSN_RESERV (advance_cycle_insn_decl
)->insn_num
== 0)
8199 fputs (" return 0;\n}\n\n", output_file
);
8203 fprintf (output_file
, " switch (%s)\n {\n", INTERNAL_INSN_CODE_NAME
);
8204 for (i
= 0; i
< description
->decls_num
; i
++)
8205 if (description
->decls
[i
]->mode
== dm_insn_reserv
8206 && DECL_INSN_RESERV (description
->decls
[i
])->bypass_list
)
8208 decl
= description
->decls
[i
];
8209 max
= DECL_INSN_RESERV (decl
)->default_latency
;
8210 fprintf (output_file
,
8212 DECL_INSN_RESERV (decl
)->insn_num
);
8213 for (bypass
= DECL_INSN_RESERV (decl
)->bypass_list
;
8215 bypass
= bypass
->next
)
8217 if (bypass
->latency
> max
)
8218 max
= bypass
->latency
;
8220 fprintf (output_file
, " return %d; }\n break;\n", max
);
8223 fprintf (output_file
, " }\n return default_latencies[%s];\n}\n\n",
8224 INTERNAL_INSN_CODE_NAME
);
8227 /* The function outputs PHR interface function `insn_latency'. */
8229 output_insn_latency_func (void)
8231 fprintf (output_file
, "int\n%s (rtx %s, rtx %s)\n",
8232 INSN_LATENCY_FUNC_NAME
, INSN_PARAMETER_NAME
, INSN2_PARAMETER_NAME
);
8233 fprintf (output_file
, "{\n int %s, %s;\n",
8234 INTERNAL_INSN_CODE_NAME
, INTERNAL_INSN2_CODE_NAME
);
8235 output_internal_insn_code_evaluation (INSN_PARAMETER_NAME
,
8236 INTERNAL_INSN_CODE_NAME
, 0);
8237 output_internal_insn_code_evaluation (INSN2_PARAMETER_NAME
,
8238 INTERNAL_INSN2_CODE_NAME
, 0);
8239 fprintf (output_file
, " return %s (%s, %s, %s, %s);\n}\n\n",
8240 INTERNAL_INSN_LATENCY_FUNC_NAME
,
8241 INTERNAL_INSN_CODE_NAME
, INTERNAL_INSN2_CODE_NAME
,
8242 INSN_PARAMETER_NAME
, INSN2_PARAMETER_NAME
);
8245 /* The function outputs PHR interface function `maximal_insn_latency'. */
8247 output_maximal_insn_latency_func (void)
8249 fprintf (output_file
, "int\n%s (rtx %s)\n",
8250 "maximal_insn_latency", INSN_PARAMETER_NAME
);
8251 fprintf (output_file
, "{\n int %s;\n",
8252 INTERNAL_INSN_CODE_NAME
);
8253 output_internal_insn_code_evaluation (INSN_PARAMETER_NAME
,
8254 INTERNAL_INSN_CODE_NAME
, 0);
8255 fprintf (output_file
, " return %s (%s, %s);\n}\n\n",
8256 "internal_maximal_insn_latency",
8257 INTERNAL_INSN_CODE_NAME
, INSN_PARAMETER_NAME
);
8260 /* The function outputs PHR interface function `print_reservation'. */
8262 output_print_reservation_func (void)
8267 fprintf (output_file
,
8268 "void\n%s (FILE *%s, rtx %s ATTRIBUTE_UNUSED)\n{\n",
8269 PRINT_RESERVATION_FUNC_NAME
, FILE_PARAMETER_NAME
,
8270 INSN_PARAMETER_NAME
);
8272 if (DECL_INSN_RESERV (advance_cycle_insn_decl
)->insn_num
== 0)
8274 fprintf (output_file
, " fputs (\"%s\", %s);\n}\n\n",
8275 NOTHING_NAME
, FILE_PARAMETER_NAME
);
8280 fputs (" static const char *const reservation_names[] =\n {",
8283 for (i
= 0, j
= 0; i
< description
->decls_num
; i
++)
8285 decl
= description
->decls
[i
];
8286 if (decl
->mode
== dm_insn_reserv
&& decl
!= advance_cycle_insn_decl
)
8288 gcc_assert (j
== DECL_INSN_RESERV (decl
)->insn_num
);
8291 fprintf (output_file
, "\n \"%s\",",
8292 regexp_representation (DECL_INSN_RESERV (decl
)->regexp
));
8293 finish_regexp_representation ();
8296 gcc_assert (j
== DECL_INSN_RESERV (advance_cycle_insn_decl
)->insn_num
);
8298 fprintf (output_file
, "\n \"%s\"\n };\n int %s;\n\n",
8299 NOTHING_NAME
, INTERNAL_INSN_CODE_NAME
);
8301 fprintf (output_file
, " if (%s == 0)\n %s = %s;\n",
8302 INSN_PARAMETER_NAME
,
8303 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
);
8304 fprintf (output_file
, " else\n\
8310 INTERNAL_INSN_CODE_NAME
, DFA_INSN_CODE_FUNC_NAME
,
8311 INSN_PARAMETER_NAME
,
8312 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
,
8313 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
);
8315 fprintf (output_file
, " fputs (reservation_names[%s], %s);\n}\n\n",
8316 INTERNAL_INSN_CODE_NAME
, FILE_PARAMETER_NAME
);
8319 /* The following function is used to sort unit declaration by their
8322 units_cmp (const void *unit1
, const void *unit2
)
8324 const_unit_decl_t
const u1
= *(const_unit_decl_t
const*) unit1
;
8325 const_unit_decl_t
const u2
= *(const_unit_decl_t
const*) unit2
;
8327 return strcmp (u1
->name
, u2
->name
);
8330 /* The following macro value is name of struct containing unit name
8332 #define NAME_CODE_STRUCT_NAME "name_code"
8334 /* The following macro value is name of table of struct name_code. */
8335 #define NAME_CODE_TABLE_NAME "name_code_table"
8337 /* The following macro values are member names for struct name_code. */
8338 #define NAME_MEMBER_NAME "name"
8339 #define CODE_MEMBER_NAME "code"
8341 /* The following macro values are local variable names for function
8342 `get_cpu_unit_code'. */
8343 #define CMP_VARIABLE_NAME "cmp"
8344 #define LOW_VARIABLE_NAME "l"
8345 #define MIDDLE_VARIABLE_NAME "m"
8346 #define HIGH_VARIABLE_NAME "h"
8348 /* The following function outputs function to obtain internal cpu unit
8349 code by the cpu unit name. */
8351 output_get_cpu_unit_code_func (void)
8356 fprintf (output_file
, "int\n%s (const char *%s)\n",
8357 GET_CPU_UNIT_CODE_FUNC_NAME
, CPU_UNIT_NAME_PARAMETER_NAME
);
8358 fprintf (output_file
, "{\n struct %s {const char *%s; int %s;};\n",
8359 NAME_CODE_STRUCT_NAME
, NAME_MEMBER_NAME
, CODE_MEMBER_NAME
);
8360 fprintf (output_file
, " int %s, %s, %s, %s;\n", CMP_VARIABLE_NAME
,
8361 LOW_VARIABLE_NAME
, MIDDLE_VARIABLE_NAME
, HIGH_VARIABLE_NAME
);
8362 fprintf (output_file
, " static struct %s %s [] =\n {\n",
8363 NAME_CODE_STRUCT_NAME
, NAME_CODE_TABLE_NAME
);
8364 units
= XNEWVEC (unit_decl_t
, description
->units_num
);
8365 memcpy (units
, units_array
, sizeof (unit_decl_t
) * description
->units_num
);
8366 qsort (units
, description
->units_num
, sizeof (unit_decl_t
), units_cmp
);
8367 for (i
= 0; i
< description
->units_num
; i
++)
8368 if (units
[i
]->query_p
)
8369 fprintf (output_file
, " {\"%s\", %d},\n",
8370 units
[i
]->name
, units
[i
]->query_num
);
8371 fprintf (output_file
, " };\n\n");
8372 fprintf (output_file
, " /* The following is binary search: */\n");
8373 fprintf (output_file
, " %s = 0;\n", LOW_VARIABLE_NAME
);
8374 fprintf (output_file
, " %s = sizeof (%s) / sizeof (struct %s) - 1;\n",
8375 HIGH_VARIABLE_NAME
, NAME_CODE_TABLE_NAME
, NAME_CODE_STRUCT_NAME
);
8376 fprintf (output_file
, " while (%s <= %s)\n {\n",
8377 LOW_VARIABLE_NAME
, HIGH_VARIABLE_NAME
);
8378 fprintf (output_file
, " %s = (%s + %s) / 2;\n",
8379 MIDDLE_VARIABLE_NAME
, LOW_VARIABLE_NAME
, HIGH_VARIABLE_NAME
);
8380 fprintf (output_file
, " %s = strcmp (%s, %s [%s].%s);\n",
8381 CMP_VARIABLE_NAME
, CPU_UNIT_NAME_PARAMETER_NAME
,
8382 NAME_CODE_TABLE_NAME
, MIDDLE_VARIABLE_NAME
, NAME_MEMBER_NAME
);
8383 fprintf (output_file
, " if (%s < 0)\n", CMP_VARIABLE_NAME
);
8384 fprintf (output_file
, " %s = %s - 1;\n",
8385 HIGH_VARIABLE_NAME
, MIDDLE_VARIABLE_NAME
);
8386 fprintf (output_file
, " else if (%s > 0)\n", CMP_VARIABLE_NAME
);
8387 fprintf (output_file
, " %s = %s + 1;\n",
8388 LOW_VARIABLE_NAME
, MIDDLE_VARIABLE_NAME
);
8389 fprintf (output_file
, " else\n");
8390 fprintf (output_file
, " return %s [%s].%s;\n }\n",
8391 NAME_CODE_TABLE_NAME
, MIDDLE_VARIABLE_NAME
, CODE_MEMBER_NAME
);
8392 fprintf (output_file
, " return -1;\n}\n\n");
8396 /* The following function outputs function to check reservation of cpu
8397 unit (its internal code will be passed as the function argument) in
8400 output_cpu_unit_reservation_p (void)
8402 automaton_t automaton
;
8404 fprintf (output_file
, "int\n%s (%s %s, int %s)\n",
8405 CPU_UNIT_RESERVATION_P_FUNC_NAME
,
8406 STATE_TYPE_NAME
, STATE_NAME
,
8407 CPU_CODE_PARAMETER_NAME
);
8408 fprintf (output_file
, "{\n gcc_assert (%s >= 0 && %s < %d);\n",
8409 CPU_CODE_PARAMETER_NAME
, CPU_CODE_PARAMETER_NAME
,
8410 description
->query_units_num
);
8411 if (description
->query_units_num
> 0)
8412 for (automaton
= description
->first_automaton
;
8414 automaton
= automaton
->next_automaton
)
8416 fprintf (output_file
, " if ((");
8417 output_reserved_units_table_name (output_file
, automaton
);
8418 fprintf (output_file
, " [((struct %s *) %s)->", CHIP_NAME
, STATE_NAME
);
8419 output_chip_member_name (output_file
, automaton
);
8420 fprintf (output_file
, " * %d + %s / 8] >> (%s %% 8)) & 1)\n",
8421 (description
->query_units_num
+ 7) / 8,
8422 CPU_CODE_PARAMETER_NAME
, CPU_CODE_PARAMETER_NAME
);
8423 fprintf (output_file
, " return 1;\n");
8425 fprintf (output_file
, " return 0;\n}\n\n");
8428 /* The following function outputs a function to check if insn
8429 has a dfa reservation. */
8431 output_insn_has_dfa_reservation_p (void)
8433 fprintf (output_file
,
8434 "bool\n%s (rtx %s ATTRIBUTE_UNUSED)\n{\n",
8435 INSN_HAS_DFA_RESERVATION_P_FUNC_NAME
,
8436 INSN_PARAMETER_NAME
);
8438 if (DECL_INSN_RESERV (advance_cycle_insn_decl
)->insn_num
== 0)
8440 fprintf (output_file
, " return false;\n}\n\n");
8444 fprintf (output_file
, " int %s;\n\n", INTERNAL_INSN_CODE_NAME
);
8446 fprintf (output_file
, " if (%s == 0)\n %s = %s;\n",
8447 INSN_PARAMETER_NAME
,
8448 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
);
8449 fprintf (output_file
, " else\n\
8455 INTERNAL_INSN_CODE_NAME
, DFA_INSN_CODE_FUNC_NAME
,
8456 INSN_PARAMETER_NAME
,
8457 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
,
8458 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
);
8460 fprintf (output_file
, " return %s != %s;\n}\n\n",
8461 INTERNAL_INSN_CODE_NAME
, ADVANCE_CYCLE_VALUE_NAME
);
8464 /* The function outputs PHR interface functions `dfa_clean_insn_cache'
8465 and 'dfa_clear_single_insn_cache'. */
8467 output_dfa_clean_insn_cache_func (void)
8469 fprintf (output_file
,
8470 "void\n%s (void)\n{\n int %s;\n\n",
8471 DFA_CLEAN_INSN_CACHE_FUNC_NAME
, I_VARIABLE_NAME
);
8472 fprintf (output_file
,
8473 " for (%s = 0; %s < %s; %s++)\n %s [%s] = -1;\n}\n\n",
8474 I_VARIABLE_NAME
, I_VARIABLE_NAME
,
8475 DFA_INSN_CODES_LENGTH_VARIABLE_NAME
, I_VARIABLE_NAME
,
8476 DFA_INSN_CODES_VARIABLE_NAME
, I_VARIABLE_NAME
);
8478 fprintf (output_file
,
8479 "void\n%s (rtx %s)\n{\n int %s;\n\n",
8480 DFA_CLEAR_SINGLE_INSN_CACHE_FUNC_NAME
, INSN_PARAMETER_NAME
,
8482 fprintf (output_file
,
8483 " %s = INSN_UID (%s);\n if (%s < %s)\n %s [%s] = -1;\n}\n\n",
8484 I_VARIABLE_NAME
, INSN_PARAMETER_NAME
, I_VARIABLE_NAME
,
8485 DFA_INSN_CODES_LENGTH_VARIABLE_NAME
, DFA_INSN_CODES_VARIABLE_NAME
,
8489 /* The function outputs PHR interface function `dfa_start'. */
8491 output_dfa_start_func (void)
8493 fprintf (output_file
,
8494 "void\n%s (void)\n{\n %s = get_max_uid ();\n",
8495 DFA_START_FUNC_NAME
, DFA_INSN_CODES_LENGTH_VARIABLE_NAME
);
8496 fprintf (output_file
, " %s = XNEWVEC (int, %s);\n",
8497 DFA_INSN_CODES_VARIABLE_NAME
, DFA_INSN_CODES_LENGTH_VARIABLE_NAME
);
8498 fprintf (output_file
, " %s ();\n}\n\n", DFA_CLEAN_INSN_CACHE_FUNC_NAME
);
8501 /* The function outputs PHR interface function `dfa_finish'. */
8503 output_dfa_finish_func (void)
8505 fprintf (output_file
, "void\n%s (void)\n{\n free (%s);\n}\n\n",
8506 DFA_FINISH_FUNC_NAME
, DFA_INSN_CODES_VARIABLE_NAME
);
8511 /* The page contains code for output description file (readable
8512 representation of original description and generated DFA(s). */
8514 /* The function outputs string representation of IR reservation. */
8516 output_regexp (regexp_t regexp
)
8518 fprintf (output_description_file
, "%s", regexp_representation (regexp
));
8519 finish_regexp_representation ();
8522 /* Output names of units in LIST separated by comma. */
8524 output_unit_set_el_list (unit_set_el_t list
)
8528 for (el
= list
; el
!= NULL
; el
= el
->next_unit_set_el
)
8531 fprintf (output_description_file
, ", ");
8532 fprintf (output_description_file
, "%s", el
->unit_decl
->name
);
8536 /* Output patterns in LIST separated by comma. */
8538 output_pattern_set_el_list (pattern_set_el_t list
)
8540 pattern_set_el_t el
;
8543 for (el
= list
; el
!= NULL
; el
= el
->next_pattern_set_el
)
8546 fprintf (output_description_file
, ", ");
8547 for (i
= 0; i
< el
->units_num
; i
++)
8548 fprintf (output_description_file
, (i
== 0 ? "%s" : " %s"),
8549 el
->unit_decls
[i
]->name
);
8553 /* The function outputs string representation of IR define_reservation
8554 and define_insn_reservation. */
8556 output_description (void)
8561 for (i
= 0; i
< description
->decls_num
; i
++)
8563 decl
= description
->decls
[i
];
8564 if (decl
->mode
== dm_unit
)
8566 if (DECL_UNIT (decl
)->excl_list
!= NULL
)
8568 fprintf (output_description_file
, "unit %s exclusion_set: ",
8569 DECL_UNIT (decl
)->name
);
8570 output_unit_set_el_list (DECL_UNIT (decl
)->excl_list
);
8571 fprintf (output_description_file
, "\n");
8573 if (DECL_UNIT (decl
)->presence_list
!= NULL
)
8575 fprintf (output_description_file
, "unit %s presence_set: ",
8576 DECL_UNIT (decl
)->name
);
8577 output_pattern_set_el_list (DECL_UNIT (decl
)->presence_list
);
8578 fprintf (output_description_file
, "\n");
8580 if (DECL_UNIT (decl
)->final_presence_list
!= NULL
)
8582 fprintf (output_description_file
, "unit %s final_presence_set: ",
8583 DECL_UNIT (decl
)->name
);
8584 output_pattern_set_el_list
8585 (DECL_UNIT (decl
)->final_presence_list
);
8586 fprintf (output_description_file
, "\n");
8588 if (DECL_UNIT (decl
)->absence_list
!= NULL
)
8590 fprintf (output_description_file
, "unit %s absence_set: ",
8591 DECL_UNIT (decl
)->name
);
8592 output_pattern_set_el_list (DECL_UNIT (decl
)->absence_list
);
8593 fprintf (output_description_file
, "\n");
8595 if (DECL_UNIT (decl
)->final_absence_list
!= NULL
)
8597 fprintf (output_description_file
, "unit %s final_absence_set: ",
8598 DECL_UNIT (decl
)->name
);
8599 output_pattern_set_el_list
8600 (DECL_UNIT (decl
)->final_absence_list
);
8601 fprintf (output_description_file
, "\n");
8605 fprintf (output_description_file
, "\n");
8606 for (i
= 0; i
< description
->decls_num
; i
++)
8608 decl
= description
->decls
[i
];
8609 if (decl
->mode
== dm_reserv
)
8611 fprintf (output_description_file
, "reservation %s: ",
8612 DECL_RESERV (decl
)->name
);
8613 output_regexp (DECL_RESERV (decl
)->regexp
);
8614 fprintf (output_description_file
, "\n");
8616 else if (decl
->mode
== dm_insn_reserv
&& decl
!= advance_cycle_insn_decl
)
8618 fprintf (output_description_file
, "insn reservation %s ",
8619 DECL_INSN_RESERV (decl
)->name
);
8620 print_rtl (output_description_file
,
8621 DECL_INSN_RESERV (decl
)->condexp
);
8622 fprintf (output_description_file
, ": ");
8623 output_regexp (DECL_INSN_RESERV (decl
)->regexp
);
8624 fprintf (output_description_file
, "\n");
8626 else if (decl
->mode
== dm_bypass
)
8627 fprintf (output_description_file
, "bypass %d %s %s\n",
8628 DECL_BYPASS (decl
)->latency
,
8629 DECL_BYPASS (decl
)->out_insn_name
,
8630 DECL_BYPASS (decl
)->in_insn_name
);
8632 fprintf (output_description_file
, "\n\f\n");
8635 /* The function outputs name of AUTOMATON. */
8637 output_automaton_name (FILE *f
, automaton_t automaton
)
8639 if (automaton
->corresponding_automaton_decl
== NULL
)
8640 fprintf (f
, "#%d", automaton
->automaton_order_num
);
8642 fprintf (f
, "`%s'", automaton
->corresponding_automaton_decl
->name
);
8645 /* Maximal length of line for pretty printing into description
8647 #define MAX_LINE_LENGTH 70
8649 /* The function outputs units name belonging to AUTOMATON. */
8651 output_automaton_units (automaton_t automaton
)
8655 int curr_line_length
;
8656 int there_is_an_automaton_unit
;
8659 fprintf (output_description_file
, "\n Corresponding units:\n");
8660 fprintf (output_description_file
, " ");
8661 curr_line_length
= 4;
8662 there_is_an_automaton_unit
= 0;
8663 for (i
= 0; i
< description
->decls_num
; i
++)
8665 decl
= description
->decls
[i
];
8666 if (decl
->mode
== dm_unit
8667 && (DECL_UNIT (decl
)->corresponding_automaton_num
8668 == automaton
->automaton_order_num
))
8670 there_is_an_automaton_unit
= 1;
8671 name
= DECL_UNIT (decl
)->name
;
8672 if (curr_line_length
+ strlen (name
) + 1 > MAX_LINE_LENGTH
)
8674 curr_line_length
= strlen (name
) + 4;
8675 fprintf (output_description_file
, "\n ");
8679 curr_line_length
+= strlen (name
) + 1;
8680 fprintf (output_description_file
, " ");
8682 fprintf (output_description_file
, "%s", name
);
8685 if (!there_is_an_automaton_unit
)
8686 fprintf (output_description_file
, "<None>");
8687 fprintf (output_description_file
, "\n\n");
8690 /* The following variable is used for forming array of all possible cpu unit
8691 reservations described by the current DFA state. */
8692 static VEC(reserv_sets_t
,heap
) *state_reservs
;
8694 /* The function forms `state_reservs' for STATE. */
8696 add_state_reservs (state_t state
)
8698 alt_state_t curr_alt_state
;
8700 if (state
->component_states
!= NULL
)
8701 for (curr_alt_state
= state
->component_states
;
8702 curr_alt_state
!= NULL
;
8703 curr_alt_state
= curr_alt_state
->next_sorted_alt_state
)
8704 add_state_reservs (curr_alt_state
->state
);
8706 VEC_safe_push (reserv_sets_t
,heap
, state_reservs
, state
->reservs
);
8709 /* The function outputs readable representation of all out arcs of
8712 output_state_arcs (state_t state
)
8716 const char *insn_name
;
8717 int curr_line_length
;
8719 for (arc
= first_out_arc (state
); arc
!= NULL
; arc
= next_out_arc (arc
))
8722 gcc_assert (ainsn
->first_insn_with_same_reservs
);
8723 fprintf (output_description_file
, " ");
8724 curr_line_length
= 7;
8725 fprintf (output_description_file
, "%2d: ", ainsn
->insn_equiv_class_num
);
8728 insn_name
= ainsn
->insn_reserv_decl
->name
;
8729 if (curr_line_length
+ strlen (insn_name
) > MAX_LINE_LENGTH
)
8731 if (ainsn
!= arc
->insn
)
8733 fprintf (output_description_file
, ",\n ");
8734 curr_line_length
= strlen (insn_name
) + 6;
8737 curr_line_length
+= strlen (insn_name
);
8741 curr_line_length
+= strlen (insn_name
);
8742 if (ainsn
!= arc
->insn
)
8744 curr_line_length
+= 2;
8745 fprintf (output_description_file
, ", ");
8748 fprintf (output_description_file
, "%s", insn_name
);
8749 ainsn
= ainsn
->next_same_reservs_insn
;
8751 while (ainsn
!= NULL
);
8752 fprintf (output_description_file
, " %d \n",
8753 arc
->to_state
->order_state_num
);
8755 fprintf (output_description_file
, "\n");
8758 /* The following function is used for sorting possible cpu unit
8759 reservation of a DFA state. */
8761 state_reservs_cmp (const void *reservs_ptr_1
, const void *reservs_ptr_2
)
8763 return reserv_sets_cmp (*(const_reserv_sets_t
const*) reservs_ptr_1
,
8764 *(const_reserv_sets_t
const*) reservs_ptr_2
);
8767 /* The following function is used for sorting possible cpu unit
8768 reservation of a DFA state. */
8770 remove_state_duplicate_reservs (void)
8774 for (i
= 1, j
= 0; i
< VEC_length (reserv_sets_t
, state_reservs
); i
++)
8775 if (reserv_sets_cmp (VEC_index (reserv_sets_t
, state_reservs
, j
),
8776 VEC_index (reserv_sets_t
, state_reservs
, i
)))
8779 VEC_replace (reserv_sets_t
, state_reservs
, j
,
8780 VEC_index (reserv_sets_t
, state_reservs
, i
));
8782 VEC_truncate (reserv_sets_t
, state_reservs
, j
+ 1);
8785 /* The following function output readable representation of DFA(s)
8786 state used for fast recognition of pipeline hazards. State is
8787 described by possible (current and scheduled) cpu unit
8790 output_state (state_t state
)
8796 fprintf (output_description_file
, " State #%d", state
->order_state_num
);
8797 fprintf (output_description_file
,
8798 state
->new_cycle_p
? " (new cycle)\n" : "\n");
8799 add_state_reservs (state
);
8800 qsort (VEC_address (reserv_sets_t
, state_reservs
),
8801 VEC_length (reserv_sets_t
, state_reservs
),
8802 sizeof (reserv_sets_t
), state_reservs_cmp
);
8803 remove_state_duplicate_reservs ();
8804 for (i
= 1; i
< VEC_length (reserv_sets_t
, state_reservs
); i
++)
8806 fprintf (output_description_file
, " ");
8807 output_reserv_sets (output_description_file
,
8808 VEC_index (reserv_sets_t
, state_reservs
, i
));
8809 fprintf (output_description_file
, "\n");
8811 fprintf (output_description_file
, "\n");
8812 output_state_arcs (state
);
8813 VEC_free (reserv_sets_t
,heap
, state_reservs
);
8816 /* The following function output readable representation of
8817 DFAs used for fast recognition of pipeline hazards. */
8819 output_automaton_descriptions (void)
8821 automaton_t automaton
;
8823 for (automaton
= description
->first_automaton
;
8825 automaton
= automaton
->next_automaton
)
8827 fprintf (output_description_file
, "\nAutomaton ");
8828 output_automaton_name (output_description_file
, automaton
);
8829 fprintf (output_description_file
, "\n");
8830 output_automaton_units (automaton
);
8831 pass_states (automaton
, output_state
);
8837 /* The page contains top level function for generation DFA(s) used for
8840 /* The function outputs statistics about work of different phases of
8843 output_statistics (FILE *f
)
8845 automaton_t automaton
;
8848 int transition_comb_vect_els
= 0;
8849 int transition_full_vect_els
= 0;
8850 int min_issue_delay_vect_els
= 0;
8851 int locked_states
= 0;
8854 for (automaton
= description
->first_automaton
;
8856 automaton
= automaton
->next_automaton
)
8858 fprintf (f
, "\nAutomaton ");
8859 output_automaton_name (f
, automaton
);
8860 fprintf (f
, "\n %5d NDFA states, %5d NDFA arcs\n",
8861 automaton
->NDFA_states_num
, automaton
->NDFA_arcs_num
);
8862 fprintf (f
, " %5d DFA states, %5d DFA arcs\n",
8863 automaton
->DFA_states_num
, automaton
->DFA_arcs_num
);
8864 states_num
= automaton
->DFA_states_num
;
8865 if (!no_minimization_flag
)
8867 fprintf (f
, " %5d minimal DFA states, %5d minimal DFA arcs\n",
8868 automaton
->minimal_DFA_states_num
,
8869 automaton
->minimal_DFA_arcs_num
);
8870 states_num
= automaton
->minimal_DFA_states_num
;
8872 fprintf (f
, " %5d all insns %5d insn equivalence classes\n",
8873 description
->insns_num
, automaton
->insn_equiv_classes_num
);
8874 fprintf (f
, " %d locked states\n", automaton
->locked_states
);
8877 (f
, "%5ld transition comb vector els, %5ld trans table els: %s\n",
8878 (long) VEC_length (vect_el_t
, automaton
->trans_table
->comb_vect
),
8879 (long) VEC_length (vect_el_t
, automaton
->trans_table
->full_vect
),
8880 (comb_vect_p (automaton
->trans_table
)
8881 ? "use comb vect" : "use simple vect"));
8883 (f
, "%5ld min delay table els, compression factor %d\n",
8884 (long) states_num
* automaton
->insn_equiv_classes_num
,
8885 automaton
->min_issue_delay_table_compression_factor
);
8886 transition_comb_vect_els
8887 += VEC_length (vect_el_t
, automaton
->trans_table
->comb_vect
);
8888 transition_full_vect_els
8889 += VEC_length (vect_el_t
, automaton
->trans_table
->full_vect
);
8890 min_issue_delay_vect_els
8891 += states_num
* automaton
->insn_equiv_classes_num
;
8893 += automaton
->locked_states
;
8897 fprintf (f
, "\n%5d all allocated states, %5d all allocated arcs\n",
8898 allocated_states_num
, allocated_arcs_num
);
8899 fprintf (f
, "%5d all allocated alternative states\n",
8900 allocated_alt_states_num
);
8901 fprintf (f
, "%5d all transition comb vector els, %5d all trans table els\n",
8902 transition_comb_vect_els
, transition_full_vect_els
);
8903 fprintf (f
, "%5d all min delay table els\n", min_issue_delay_vect_els
);
8904 fprintf (f
, "%5d all locked states\n", locked_states
);
8908 /* The function output times of work of different phases of DFA
8911 output_time_statistics (FILE *f
)
8913 fprintf (f
, "\n transformation: ");
8914 print_active_time (f
, transform_time
);
8915 fprintf (f
, (!ndfa_flag
? ", building DFA: " : ", building NDFA: "));
8916 print_active_time (f
, NDFA_time
);
8919 fprintf (f
, ", NDFA -> DFA: ");
8920 print_active_time (f
, NDFA_to_DFA_time
);
8922 fprintf (f
, "\n DFA minimization: ");
8923 print_active_time (f
, minimize_time
);
8924 fprintf (f
, ", making insn equivalence: ");
8925 print_active_time (f
, equiv_time
);
8926 fprintf (f
, "\n all automaton generation: ");
8927 print_active_time (f
, automaton_generation_time
);
8928 fprintf (f
, ", output: ");
8929 print_active_time (f
, output_time
);
8933 /* The function generates DFA (deterministic finite state automaton)
8934 for fast recognition of pipeline hazards. No errors during
8935 checking must be fixed before this function call. */
8939 automata_num
= split_argument
;
8940 if (description
->units_num
< automata_num
)
8941 automata_num
= description
->units_num
;
8944 initiate_automata_lists ();
8945 initiate_pass_states ();
8946 initiate_excl_sets ();
8947 initiate_presence_absence_pattern_sets ();
8948 automaton_generation_time
= create_ticker ();
8950 ticker_off (&automaton_generation_time
);
8955 /* This page mainly contains top level functions of pipeline hazards
8956 description translator. */
8958 /* The following macro value is suffix of name of description file of
8959 pipeline hazards description translator. */
8960 #define STANDARD_OUTPUT_DESCRIPTION_FILE_SUFFIX ".dfa"
8962 /* The function returns suffix of given file name. The returned
8963 string can not be changed. */
8965 file_name_suffix (const char *file_name
)
8967 const char *last_period
;
8969 for (last_period
= NULL
; *file_name
!= '\0'; file_name
++)
8970 if (*file_name
== '.')
8971 last_period
= file_name
;
8972 return (last_period
== NULL
? file_name
: last_period
);
8975 /* The function returns base name of given file name, i.e. pointer to
8976 first char after last `/' (or `\' for WIN32) in given file name,
8977 given file name itself if the directory name is absent. The
8978 returned string can not be changed. */
8980 base_file_name (const char *file_name
)
8982 int directory_name_length
;
8984 directory_name_length
= strlen (file_name
);
8986 while (directory_name_length
>= 0 && file_name
[directory_name_length
] != '/'
8987 && file_name
[directory_name_length
] != '\\')
8989 while (directory_name_length
>= 0 && file_name
[directory_name_length
] != '/')
8991 directory_name_length
--;
8992 return file_name
+ directory_name_length
+ 1;
8995 /* The following is top level function to initialize the work of
8996 pipeline hazards description translator. */
8998 initiate_automaton_gen (int argc
, char **argv
)
9000 const char *base_name
;
9004 split_argument
= 0; /* default value */
9005 no_minimization_flag
= 0;
9011 for (i
= 2; i
< argc
; i
++)
9012 if (strcmp (argv
[i
], NO_MINIMIZATION_OPTION
) == 0)
9013 no_minimization_flag
= 1;
9014 else if (strcmp (argv
[i
], TIME_OPTION
) == 0)
9016 else if (strcmp (argv
[i
], STATS_OPTION
) == 0)
9018 else if (strcmp (argv
[i
], V_OPTION
) == 0)
9020 else if (strcmp (argv
[i
], W_OPTION
) == 0)
9022 else if (strcmp (argv
[i
], NDFA_OPTION
) == 0)
9024 else if (strcmp (argv
[i
], PROGRESS_OPTION
) == 0)
9026 else if (strcmp (argv
[i
], "-split") == 0)
9029 fatal ("-split has no argument.");
9030 fatal ("option `-split' has not been implemented yet\n");
9031 /* split_argument = atoi (argument_vect [i + 1]); */
9034 /* Initialize IR storage. */
9035 obstack_init (&irp
);
9036 initiate_automaton_decl_table ();
9037 initiate_insn_decl_table ();
9038 initiate_decl_table ();
9039 output_file
= stdout
;
9040 output_description_file
= NULL
;
9041 base_name
= base_file_name (argv
[1]);
9042 obstack_grow (&irp
, base_name
,
9043 strlen (base_name
) - strlen (file_name_suffix (base_name
)));
9044 obstack_grow (&irp
, STANDARD_OUTPUT_DESCRIPTION_FILE_SUFFIX
,
9045 strlen (STANDARD_OUTPUT_DESCRIPTION_FILE_SUFFIX
) + 1);
9046 obstack_1grow (&irp
, '\0');
9047 output_description_file_name
= obstack_base (&irp
);
9048 obstack_finish (&irp
);
9051 /* The following function checks existence at least one arc marked by
9054 check_automata_insn_issues (void)
9056 automaton_t automaton
;
9057 ainsn_t ainsn
, reserv_ainsn
;
9059 for (automaton
= description
->first_automaton
;
9061 automaton
= automaton
->next_automaton
)
9063 for (ainsn
= automaton
->ainsn_list
;
9065 ainsn
= ainsn
->next_ainsn
)
9066 if (ainsn
->first_insn_with_same_reservs
&& !ainsn
->arc_exists_p
)
9068 for (reserv_ainsn
= ainsn
;
9069 reserv_ainsn
!= NULL
;
9070 reserv_ainsn
= reserv_ainsn
->next_same_reservs_insn
)
9071 if (automaton
->corresponding_automaton_decl
!= NULL
)
9074 error ("Automaton `%s': Insn `%s' will never be issued",
9075 automaton
->corresponding_automaton_decl
->name
,
9076 reserv_ainsn
->insn_reserv_decl
->name
);
9079 (0, "Automaton `%s': Insn `%s' will never be issued",
9080 automaton
->corresponding_automaton_decl
->name
,
9081 reserv_ainsn
->insn_reserv_decl
->name
);
9086 error ("Insn `%s' will never be issued",
9087 reserv_ainsn
->insn_reserv_decl
->name
);
9089 warning (0, "Insn `%s' will never be issued",
9090 reserv_ainsn
->insn_reserv_decl
->name
);
9096 /* The following vla is used for storing pointers to all achieved
9098 static VEC(state_t
,heap
) *automaton_states
;
9100 /* This function is called by function pass_states to add an achieved
9103 add_automaton_state (state_t state
)
9105 VEC_safe_push (state_t
,heap
, automaton_states
, state
);
9108 /* The following function forms list of important automata (whose
9109 states may be changed after the insn issue) for each insn. */
9111 form_important_insn_automata_lists (void)
9113 automaton_t automaton
;
9120 automaton_states
= 0;
9121 /* Mark important ainsns. */
9122 for (automaton
= description
->first_automaton
;
9124 automaton
= automaton
->next_automaton
)
9126 VEC_truncate (state_t
, automaton_states
, 0);
9127 pass_states (automaton
, add_automaton_state
);
9128 for (n
= 0; n
< VEC_length (state_t
, automaton_states
); n
++)
9130 state_t s
= VEC_index (state_t
, automaton_states
, n
);
9131 for (arc
= first_out_arc (s
);
9133 arc
= next_out_arc (arc
))
9134 if (arc
->to_state
!= s
)
9136 gcc_assert (arc
->insn
->first_insn_with_same_reservs
);
9137 for (ainsn
= arc
->insn
;
9139 ainsn
= ainsn
->next_same_reservs_insn
)
9140 ainsn
->important_p
= TRUE
;
9144 VEC_free (state_t
,heap
, automaton_states
);
9146 /* Create automata sets for the insns. */
9147 for (i
= 0; i
< description
->decls_num
; i
++)
9149 decl
= description
->decls
[i
];
9150 if (decl
->mode
== dm_insn_reserv
)
9152 automata_list_start ();
9153 for (automaton
= description
->first_automaton
;
9155 automaton
= automaton
->next_automaton
)
9156 for (ainsn
= automaton
->ainsn_list
;
9158 ainsn
= ainsn
->next_ainsn
)
9159 if (ainsn
->important_p
9160 && ainsn
->insn_reserv_decl
== DECL_INSN_RESERV (decl
))
9162 automata_list_add (automaton
);
9165 DECL_INSN_RESERV (decl
)->important_automata_list
9166 = automata_list_finish ();
9172 /* The following is top level function to generate automat(a,on) for
9173 fast recognition of pipeline hazards. */
9175 expand_automata (void)
9179 description
= XCREATENODEVAR (struct description
,
9180 sizeof (struct description
)
9181 /* One entry for cycle advancing insn. */
9182 + sizeof (decl_t
) * VEC_length (decl_t
, decls
));
9183 description
->decls_num
= VEC_length (decl_t
, decls
);
9184 description
->query_units_num
= 0;
9185 for (i
= 0; i
< description
->decls_num
; i
++)
9187 description
->decls
[i
] = VEC_index (decl_t
, decls
, i
);
9188 if (description
->decls
[i
]->mode
== dm_unit
9189 && DECL_UNIT (description
->decls
[i
])->query_p
)
9190 DECL_UNIT (description
->decls
[i
])->query_num
9191 = description
->query_units_num
++;
9193 all_time
= create_ticker ();
9194 check_time
= create_ticker ();
9196 fprintf (stderr
, "Check description...");
9197 check_all_description ();
9199 fprintf (stderr
, "done\n");
9200 ticker_off (&check_time
);
9201 generation_time
= create_ticker ();
9204 transform_insn_regexps ();
9205 check_unit_distributions_to_automata ();
9210 check_automata_insn_issues ();
9214 form_important_insn_automata_lists ();
9216 ticker_off (&generation_time
);
9219 /* The following is top level function to output PHR and to finish
9220 work with pipeline description translator. */
9222 write_automata (void)
9224 output_time
= create_ticker ();
9226 fprintf (stderr
, "Forming and outputting automata tables...");
9230 fprintf (stderr
, "done\n");
9231 fprintf (stderr
, "Output functions to work with automata...");
9233 output_chip_definitions ();
9234 output_max_insn_queue_index_def ();
9235 output_internal_min_issue_delay_func ();
9236 output_internal_trans_func ();
9237 /* Cache of insn dfa codes: */
9238 fprintf (output_file
, "\nstatic int *%s;\n", DFA_INSN_CODES_VARIABLE_NAME
);
9239 fprintf (output_file
, "\nstatic int %s;\n\n",
9240 DFA_INSN_CODES_LENGTH_VARIABLE_NAME
);
9241 output_dfa_insn_code_func ();
9242 output_trans_func ();
9243 output_min_issue_delay_func ();
9244 output_internal_dead_lock_func ();
9245 output_dead_lock_func ();
9246 output_size_func ();
9247 output_internal_reset_func ();
9248 output_reset_func ();
9249 output_min_insn_conflict_delay_func ();
9250 output_default_latencies ();
9251 output_internal_insn_latency_func ();
9252 output_insn_latency_func ();
9253 output_internal_maximal_insn_latency_func ();
9254 output_maximal_insn_latency_func ();
9255 output_print_reservation_func ();
9256 /* Output function get_cpu_unit_code. */
9257 fprintf (output_file
, "\n#if %s\n\n", CPU_UNITS_QUERY_MACRO_NAME
);
9258 output_get_cpu_unit_code_func ();
9259 output_cpu_unit_reservation_p ();
9260 output_insn_has_dfa_reservation_p ();
9261 fprintf (output_file
, "\n#endif /* #if %s */\n\n",
9262 CPU_UNITS_QUERY_MACRO_NAME
);
9263 output_dfa_clean_insn_cache_func ();
9264 output_dfa_start_func ();
9265 output_dfa_finish_func ();
9267 fprintf (stderr
, "done\n");
9270 output_description_file
= fopen (output_description_file_name
, "w");
9271 if (output_description_file
== NULL
)
9273 perror (output_description_file_name
);
9274 exit (FATAL_EXIT_CODE
);
9277 fprintf (stderr
, "Output automata description...");
9278 output_description ();
9279 output_automaton_descriptions ();
9281 fprintf (stderr
, "done\n");
9282 output_statistics (output_description_file
);
9285 output_statistics (stderr
);
9286 ticker_off (&output_time
);
9288 output_time_statistics (stderr
);
9291 finish_automata_lists ();
9294 fprintf (stderr
, "Summary:\n");
9295 fprintf (stderr
, " check time ");
9296 print_active_time (stderr
, check_time
);
9297 fprintf (stderr
, ", generation time ");
9298 print_active_time (stderr
, generation_time
);
9299 fprintf (stderr
, ", all time ");
9300 print_active_time (stderr
, all_time
);
9301 fprintf (stderr
, "\n");
9303 /* Finish all work. */
9304 if (output_description_file
!= NULL
)
9306 fflush (output_description_file
);
9307 if (ferror (stdout
) != 0)
9308 fatal ("Error in writing DFA description file %s: %s",
9309 output_description_file_name
, xstrerror (errno
));
9310 fclose (output_description_file
);
9312 finish_automaton_decl_table ();
9313 finish_insn_decl_table ();
9314 finish_decl_table ();
9315 obstack_free (&irp
, NULL
);
9316 if (have_error
&& output_description_file
!= NULL
)
9317 remove (output_description_file_name
);
9321 main (int argc
, char **argv
)
9325 progname
= "genautomata";
9327 if (init_md_reader_args (argc
, argv
) != SUCCESS_EXIT_CODE
)
9328 return (FATAL_EXIT_CODE
);
9330 initiate_automaton_gen (argc
, argv
);
9334 int insn_code_number
;
9336 desc
= read_md_rtx (&lineno
, &insn_code_number
);
9340 switch (GET_CODE (desc
))
9342 case DEFINE_CPU_UNIT
:
9343 gen_cpu_unit (desc
);
9346 case DEFINE_QUERY_CPU_UNIT
:
9347 gen_query_cpu_unit (desc
);
9355 gen_excl_set (desc
);
9359 gen_presence_set (desc
);
9362 case FINAL_PRESENCE_SET
:
9363 gen_final_presence_set (desc
);
9367 gen_absence_set (desc
);
9370 case FINAL_ABSENCE_SET
:
9371 gen_final_absence_set (desc
);
9374 case DEFINE_AUTOMATON
:
9375 gen_automaton (desc
);
9378 case AUTOMATA_OPTION
:
9379 gen_automata_option (desc
);
9382 case DEFINE_RESERVATION
:
9386 case DEFINE_INSN_RESERVATION
:
9387 gen_insn_reserv (desc
);
9396 return FATAL_EXIT_CODE
;
9398 puts ("/* Generated automatically by the program `genautomata'\n"
9399 " from the machine description file `md'. */\n\n"
9400 "#include \"config.h\"\n"
9401 "#include \"system.h\"\n"
9402 "#include \"coretypes.h\"\n"
9403 "#include \"tm.h\"\n"
9404 "#include \"rtl.h\"\n"
9405 "#include \"tm_p.h\"\n"
9406 "#include \"insn-config.h\"\n"
9407 "#include \"recog.h\"\n"
9408 "#include \"regs.h\"\n"
9409 "#include \"real.h\"\n"
9410 "#include \"output.h\"\n"
9411 "#include \"insn-attr.h\"\n"
9412 "#include \"toplev.h\"\n"
9413 "#include \"flags.h\"\n"
9414 "#include \"function.h\"\n");
9416 if (VEC_length (decl_t
, decls
) > 0)
9423 return (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);