comparison gcc/genrecog.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Generate code from machine description to recognize rtl as insns. 1 /* Generate code from machine description to recognize rtl as insns.
2 Copyright (C) 1987-2018 Free Software Foundation, Inc. 2 Copyright (C) 1987-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it 6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by 7 under the terms of the GNU General Public License as published by
716 validate_pattern (SET_SRC (pattern), info, NULL_RTX, 0); 716 validate_pattern (SET_SRC (pattern), info, NULL_RTX, 0);
717 return; 717 return;
718 } 718 }
719 719
720 case CLOBBER: 720 case CLOBBER:
721 case CLOBBER_HIGH:
722 validate_pattern (SET_DEST (pattern), info, pattern, '='); 721 validate_pattern (SET_DEST (pattern), info, pattern, '=');
723 return; 722 return;
724 723
725 case ZERO_EXTRACT: 724 case ZERO_EXTRACT:
726 validate_pattern (XEXP (pattern, 0), info, set, set ? '+' : 0); 725 validate_pattern (XEXP (pattern, 0), info, set, set ? '+' : 0);
816 /* Simple list structure for items of type T, for use when being part 815 /* Simple list structure for items of type T, for use when being part
817 of a list is an inherent property of T. T must have members equivalent 816 of a list is an inherent property of T. T must have members equivalent
818 to "T *prev, *next;" and a function "void set_parent (list_head <T> *)" 817 to "T *prev, *next;" and a function "void set_parent (list_head <T> *)"
819 to set the parent list. */ 818 to set the parent list. */
820 template <typename T> 819 template <typename T>
821 struct list_head 820 class list_head
822 { 821 {
822 public:
823 /* A range of linked items. */ 823 /* A range of linked items. */
824 struct range 824 class range
825 { 825 {
826 public:
826 range (T *); 827 range (T *);
827 range (T *, T *); 828 range (T *, T *);
828 829
829 T *start, *end; 830 T *start, *end;
830 void set_parent (list_head *); 831 void set_parent (list_head *);
946 list_head <T>::singleton () const 947 list_head <T>::singleton () const
947 { 948 {
948 return first == last ? first : 0; 949 return first == last ? first : 0;
949 } 950 }
950 951
951 struct state; 952 class state;
952 953
953 /* Describes a possible successful return from a routine. */ 954 /* Describes a possible successful return from a routine. */
954 struct acceptance_type 955 struct acceptance_type
955 { 956 {
956 /* The type of routine we're returning from. */ 957 /* The type of routine we're returning from. */
1006 { 1007 {
1007 return !operator == (a, b); 1008 return !operator == (a, b);
1008 } 1009 }
1009 1010
1010 /* Represents a parameter to a pattern routine. */ 1011 /* Represents a parameter to a pattern routine. */
1011 struct parameter 1012 class parameter
1012 { 1013 {
1014 public:
1013 /* The C type of parameter. */ 1015 /* The C type of parameter. */
1014 enum type_enum { 1016 enum type_enum {
1015 /* Represents an invalid parameter. */ 1017 /* Represents an invalid parameter. */
1016 UNSET, 1018 UNSET,
1017 1019
1067 1069
1068 /* Represents a routine that matches a partial rtx pattern, returning 1070 /* Represents a routine that matches a partial rtx pattern, returning
1069 an ad-hoc enum value on success and -1 on failure. The routine can 1071 an ad-hoc enum value on success and -1 on failure. The routine can
1070 be used by any subroutine type. The match can be parameterized by 1072 be used by any subroutine type. The match can be parameterized by
1071 things like mode, code and UNSPEC number. */ 1073 things like mode, code and UNSPEC number. */
1072 struct pattern_routine 1074 class pattern_routine
1073 { 1075 {
1076 public:
1074 /* The state that implements the pattern. */ 1077 /* The state that implements the pattern. */
1075 state *s; 1078 state *s;
1076 1079
1077 /* The deepest root position from which S can access all the rtxes it needs. 1080 /* The deepest root position from which S can access all the rtxes it needs.
1078 This is NULL if the pattern doesn't need an rtx input, usually because 1081 This is NULL if the pattern doesn't need an rtx input, usually because
1094 1097
1095 /* All defined patterns. */ 1098 /* All defined patterns. */
1096 static vec <pattern_routine *> patterns; 1099 static vec <pattern_routine *> patterns;
1097 1100
1098 /* Represents one use of a pattern routine. */ 1101 /* Represents one use of a pattern routine. */
1099 struct pattern_use 1102 class pattern_use
1100 { 1103 {
1104 public:
1101 /* The pattern routine to use. */ 1105 /* The pattern routine to use. */
1102 pattern_routine *routine; 1106 pattern_routine *routine;
1103 1107
1104 /* The values to pass as parameters. This vector has the same length 1108 /* The values to pass as parameters. This vector has the same length
1105 as ROUTINE->PARAM_TYPES. */ 1109 as ROUTINE->PARAM_TYPES. */
1106 auto_vec <parameter, MAX_PATTERN_PARAMS> params; 1110 auto_vec <parameter, MAX_PATTERN_PARAMS> params;
1107 }; 1111 };
1108 1112
1109 /* Represents a test performed by a decision. */ 1113 /* Represents a test performed by a decision. */
1110 struct rtx_test 1114 class rtx_test
1111 { 1115 {
1116 public:
1112 rtx_test (); 1117 rtx_test ();
1113 1118
1114 /* The types of test that can be performed. Most of them take as input 1119 /* The types of test that can be performed. Most of them take as input
1115 an rtx X. Some also take as input a transition label LABEL; the others 1120 an rtx X. Some also take as input a transition label LABEL; the others
1116 are booleans for which the transition label is always "true". 1121 are booleans for which the transition label is always "true".
1425 return !operator == (a, b); 1430 return !operator == (a, b);
1426 } 1431 }
1427 1432
1428 /* A simple set of transition labels. Most transitions have a singleton 1433 /* A simple set of transition labels. Most transitions have a singleton
1429 label, so try to make that case as efficient as possible. */ 1434 label, so try to make that case as efficient as possible. */
1430 struct int_set : public auto_vec <uint64_t, 1> 1435 class int_set : public auto_vec <uint64_t, 1>
1431 { 1436 {
1437 public:
1432 typedef uint64_t *iterator; 1438 typedef uint64_t *iterator;
1433 1439
1434 int_set (); 1440 int_set ();
1435 int_set (uint64_t); 1441 int_set (uint64_t);
1436 int_set (const int_set &); 1442 int_set (const int_set &);
1490 operator != (const int_set &a, const int_set &b) 1496 operator != (const int_set &a, const int_set &b)
1491 { 1497 {
1492 return !operator == (a, b); 1498 return !operator == (a, b);
1493 } 1499 }
1494 1500
1495 struct decision; 1501 class decision;
1496 1502
1497 /* Represents a transition between states, dependent on the result of 1503 /* Represents a transition between states, dependent on the result of
1498 a test T. */ 1504 a test T. */
1499 struct transition 1505 class transition
1500 { 1506 {
1507 public:
1501 transition (const int_set &, state *, bool); 1508 transition (const int_set &, state *, bool);
1502 1509
1503 void set_parent (list_head <transition> *); 1510 void set_parent (list_head <transition> *);
1504 1511
1505 /* Links to other transitions for T. Always null for boolean tests. */ 1512 /* Links to other transitions for T. Always null for boolean tests. */
1534 /* Represents a test and the action that should be taken on the result. 1541 /* Represents a test and the action that should be taken on the result.
1535 If a transition exists for the test outcome, the machine switches 1542 If a transition exists for the test outcome, the machine switches
1536 to the transition's target state. If no suitable transition exists, 1543 to the transition's target state. If no suitable transition exists,
1537 the machine either falls through to the next decision or, if there are no 1544 the machine either falls through to the next decision or, if there are no
1538 more decisions to try, fails the match. */ 1545 more decisions to try, fails the match. */
1539 struct decision : list_head <transition> 1546 class decision : public list_head <transition>
1540 { 1547 {
1548 public:
1541 decision (const rtx_test &); 1549 decision (const rtx_test &);
1542 1550
1543 void set_parent (list_head <decision> *s); 1551 void set_parent (list_head <decision> *s);
1544 bool if_statement_p (uint64_t * = 0) const; 1552 bool if_statement_p (uint64_t * = 0) const;
1545 1553
1554 }; 1562 };
1555 1563
1556 /* Represents one machine state. For each state the machine tries a list 1564 /* Represents one machine state. For each state the machine tries a list
1557 of decisions, in order, and acts on the first match. It fails without 1565 of decisions, in order, and acts on the first match. It fails without
1558 further backtracking if no decisions match. */ 1566 further backtracking if no decisions match. */
1559 struct state : list_head <decision> 1567 class state : public list_head <decision>
1560 { 1568 {
1569 public:
1561 void set_parent (list_head <state> *) {} 1570 void set_parent (list_head <state> *) {}
1562 }; 1571 };
1563 1572
1564 transition::transition (const int_set &labels_in, state *to_in, 1573 transition::transition (const int_set &labels_in, state *to_in,
1565 bool optional_in) 1574 bool optional_in)
1765 1774
1766 /* Indicates that we have tested XVECLEN (X, 0) for a particular rtx X. */ 1775 /* Indicates that we have tested XVECLEN (X, 0) for a particular rtx X. */
1767 const unsigned char TESTED_VECLEN = 2; 1776 const unsigned char TESTED_VECLEN = 2;
1768 1777
1769 /* Represents a set of conditions that are known to hold. */ 1778 /* Represents a set of conditions that are known to hold. */
1770 struct known_conditions 1779 class known_conditions
1771 { 1780 {
1781 public:
1772 /* A mask of TESTED_ values for each position, indexed by the position's 1782 /* A mask of TESTED_ values for each position, indexed by the position's
1773 id field. */ 1783 id field. */
1774 auto_vec <unsigned char> position_tests; 1784 auto_vec <unsigned char> position_tests;
1775 1785
1776 /* Index N says whether operands[N] has been set. */ 1786 /* Index N says whether operands[N] has been set. */
2093 operand_pos[d->test.pos->id] = this_operand; 2103 operand_pos[d->test.pos->id] = this_operand;
2094 } 2104 }
2095 } 2105 }
2096 2106
2097 /* Statistics about a matching routine. */ 2107 /* Statistics about a matching routine. */
2098 struct stats 2108 class stats
2099 { 2109 {
2110 public:
2100 stats (); 2111 stats ();
2101 2112
2102 /* The total number of decisions in the routine, excluding trivial 2113 /* The total number of decisions in the routine, excluding trivial
2103 ones that never fail. */ 2114 ones that never fail. */
2104 unsigned int num_decisions; 2115 unsigned int num_decisions;
2230 st.longest_path, st.longest_path_code); 2241 st.longest_path, st.longest_path_code);
2231 fprintf (stderr, " longest backtrack: %6d (code: %6d)\n", 2242 fprintf (stderr, " longest backtrack: %6d (code: %6d)\n",
2232 st.longest_backtrack, st.longest_backtrack_code); 2243 st.longest_backtrack, st.longest_backtrack_code);
2233 } 2244 }
2234 2245
2235 struct merge_pattern_info; 2246 class merge_pattern_info;
2236 2247
2237 /* Represents a transition from one pattern to another. */ 2248 /* Represents a transition from one pattern to another. */
2238 struct merge_pattern_transition 2249 class merge_pattern_transition
2239 { 2250 {
2251 public:
2240 merge_pattern_transition (merge_pattern_info *); 2252 merge_pattern_transition (merge_pattern_info *);
2241 2253
2242 /* The target pattern. */ 2254 /* The target pattern. */
2243 merge_pattern_info *to; 2255 merge_pattern_info *to;
2244 2256
2254 } 2266 }
2255 2267
2256 /* Represents a pattern that can might match several states. The pattern 2268 /* Represents a pattern that can might match several states. The pattern
2257 may replace parts of the test with a parameter value. It may also 2269 may replace parts of the test with a parameter value. It may also
2258 replace transition labels with parameters. */ 2270 replace transition labels with parameters. */
2259 struct merge_pattern_info 2271 class merge_pattern_info
2260 { 2272 {
2273 public:
2261 merge_pattern_info (unsigned int); 2274 merge_pattern_info (unsigned int);
2262 2275
2263 /* If PARAM_TEST_P, the state's singleton test should be generalized 2276 /* If PARAM_TEST_P, the state's singleton test should be generalized
2264 to use the runtime value of PARAMS[PARAM_TEST]. */ 2277 to use the runtime value of PARAMS[PARAM_TEST]. */
2265 unsigned int param_test : 8; 2278 unsigned int param_test : 8;
2327 transitions.safe_grow_cleared (num_transitions); 2340 transitions.safe_grow_cleared (num_transitions);
2328 } 2341 }
2329 2342
2330 /* Describes one way of matching a particular state to a particular 2343 /* Describes one way of matching a particular state to a particular
2331 pattern. */ 2344 pattern. */
2332 struct merge_state_result 2345 class merge_state_result
2333 { 2346 {
2347 public:
2334 merge_state_result (merge_pattern_info *, position *, merge_state_result *); 2348 merge_state_result (merge_pattern_info *, position *, merge_state_result *);
2335 2349
2336 /* A pattern that matches the state. */ 2350 /* A pattern that matches the state. */
2337 merge_pattern_info *pattern; 2351 merge_pattern_info *pattern;
2338 2352
2358 : pattern (pattern_in), root (root_in), prev (prev_in) 2372 : pattern (pattern_in), root (root_in), prev (prev_in)
2359 {} 2373 {}
2360 2374
2361 /* Information about a state, used while trying to match it against 2375 /* Information about a state, used while trying to match it against
2362 a pattern. */ 2376 a pattern. */
2363 struct merge_state_info 2377 class merge_state_info
2364 { 2378 {
2379 public:
2365 merge_state_info (state *); 2380 merge_state_info (state *);
2366 2381
2367 /* The state itself. */ 2382 /* The state itself. */
2368 state *s; 2383 state *s;
2369 2384
3858 continue; 3873 continue;
3859 } 3874 }
3860 3875
3861 /* Pairs a pattern that needs to be matched with the rtx position at 3876 /* Pairs a pattern that needs to be matched with the rtx position at
3862 which the pattern should occur. */ 3877 which the pattern should occur. */
3863 struct pattern_pos { 3878 class pattern_pos {
3879 public:
3864 pattern_pos () {} 3880 pattern_pos () {}
3865 pattern_pos (rtx, position *); 3881 pattern_pos (rtx, position *);
3866 3882
3867 rtx pattern; 3883 rtx pattern;
3868 position *pos; 3884 position *pos;
4382 ES_FALLTHROUGH 4398 ES_FALLTHROUGH
4383 }; 4399 };
4384 4400
4385 /* Information used while writing out code. */ 4401 /* Information used while writing out code. */
4386 4402
4387 struct output_state 4403 class output_state
4388 { 4404 {
4405 public:
4389 /* The type of routine that we're generating. */ 4406 /* The type of routine that we're generating. */
4390 routine_type type; 4407 routine_type type;
4391 4408
4392 /* Maps position ids to xN variable numbers. The entry is only valid if 4409 /* Maps position ids to xN variable numbers. The entry is only valid if
4393 it is less than the length of VAR_TO_ID, but this holds for every position 4410 it is less than the length of VAR_TO_ID, but this holds for every position
5293 /* Find the last non-clobber in the parallel. */ 5310 /* Find the last non-clobber in the parallel. */
5294 rtx pattern = *pattern_ptr; 5311 rtx pattern = *pattern_ptr;
5295 for (i = XVECLEN (pattern, 0); i > 0; i--) 5312 for (i = XVECLEN (pattern, 0); i > 0; i--)
5296 { 5313 {
5297 rtx x = XVECEXP (pattern, 0, i - 1); 5314 rtx x = XVECEXP (pattern, 0, i - 1);
5298 if ((GET_CODE (x) != CLOBBER && GET_CODE (x) != CLOBBER_HIGH) 5315 if (GET_CODE (x) != CLOBBER
5299 || (!REG_P (XEXP (x, 0)) 5316 || (!REG_P (XEXP (x, 0))
5300 && GET_CODE (XEXP (x, 0)) != MATCH_SCRATCH)) 5317 && GET_CODE (XEXP (x, 0)) != MATCH_SCRATCH))
5301 break; 5318 break;
5302 } 5319 }
5303 5320