Line data Source code
1 : /* Subroutines used by or related to instruction recognition.
2 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it under
7 : the terms of the GNU General Public License as published by the Free
8 : Software Foundation; either version 3, or (at your option) any later
9 : version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 :
21 : #include "config.h"
22 : #include "system.h"
23 : #include "coretypes.h"
24 : #include "backend.h"
25 : #include "target.h"
26 : #include "rtl.h"
27 : #include "tree.h"
28 : #include "stmt.h"
29 : #include "cfghooks.h"
30 : #include "df.h"
31 : #include "memmodel.h"
32 : #include "tm_p.h"
33 : #include "insn-config.h"
34 : #include "regs.h"
35 : #include "emit-rtl.h"
36 : #include "recog.h"
37 : #include "insn-attr.h"
38 : #include "addresses.h"
39 : #include "cfgrtl.h"
40 : #include "cfgbuild.h"
41 : #include "cfgcleanup.h"
42 : #include "reload.h"
43 : #include "tree-pass.h"
44 : #include "function-abi.h"
45 : #include "rtl-iter.h"
46 :
47 : #ifndef STACK_POP_CODE
48 : #if STACK_GROWS_DOWNWARD
49 : #define STACK_POP_CODE POST_INC
50 : #else
51 : #define STACK_POP_CODE POST_DEC
52 : #endif
53 : #endif
54 :
55 : static void validate_replace_rtx_1 (rtx *, rtx, rtx, rtx_insn *, bool);
56 : static void validate_replace_src_1 (rtx *, void *);
57 : static rtx_insn *split_insn (rtx_insn *);
58 :
59 : struct target_recog default_target_recog;
60 : #if SWITCHABLE_TARGET
61 : struct target_recog *this_target_recog = &default_target_recog;
62 : #endif
63 :
64 : /* Nonzero means allow operands to be volatile.
65 : This should be 0 if you are generating rtl, such as if you are calling
66 : the functions in optabs.cc and expmed.cc (most of the time).
67 : This should be 1 if all valid insns need to be recognized,
68 : such as in reginfo.cc and final.cc and reload.cc.
69 :
70 : init_recog and init_recog_no_volatile are responsible for setting this. */
71 :
72 : int volatile_ok;
73 :
74 : static struct recog_data_d main_recog_data;
75 : struct recog_data_d *recog_data_ptr = &main_recog_data;
76 :
77 : /* Contains a vector of operand_alternative structures, such that
78 : operand OP of alternative A is at index A * n_operands + OP.
79 : Set up by preprocess_constraints. */
80 : const operand_alternative *recog_op_alt;
81 :
82 : /* Used to provide recog_op_alt for asms. */
83 : static operand_alternative asm_op_alt[MAX_RECOG_OPERANDS
84 : * MAX_RECOG_ALTERNATIVES];
85 :
86 : /* On return from `constrain_operands', indicate which alternative
87 : was satisfied. */
88 :
89 : int which_alternative;
90 :
91 : /* True for inline asm operands with - constraint modifier. */
92 : bool raw_constraint_p;
93 :
94 : /* Nonzero after end of reload pass.
95 : Set to 1 or 0 by toplev.cc.
96 : Controls the significance of (SUBREG (MEM)). */
97 :
98 : int reload_completed;
99 :
100 : bool post_ra_split_completed;
101 :
102 : /* Nonzero after thread_prologue_and_epilogue_insns has run. */
103 : int epilogue_completed;
104 :
105 : /* Initialize data used by the function `recog'.
106 : This must be called once in the compilation of a function
107 : before any insn recognition may be done in the function. */
108 :
109 : void
110 8038850 : init_recog_no_volatile (void)
111 : {
112 8038850 : volatile_ok = 0;
113 8038850 : }
114 :
115 : void
116 11959597 : init_recog (void)
117 : {
118 11959597 : volatile_ok = 1;
119 11959597 : }
120 :
121 :
122 : /* Return true if labels in asm operands BODY are LABEL_REFs. */
123 :
124 : static bool
125 108782793 : asm_labels_ok (rtx body)
126 : {
127 108782793 : rtx asmop;
128 108782793 : int i;
129 :
130 108782793 : asmop = extract_asm_operands (body);
131 108782793 : if (asmop == NULL_RTX)
132 : return true;
133 :
134 832945 : for (i = 0; i < ASM_OPERANDS_LABEL_LENGTH (asmop); i++)
135 7654 : if (GET_CODE (ASM_OPERANDS_LABEL (asmop, i)) != LABEL_REF)
136 : return false;
137 :
138 : return true;
139 : }
140 :
141 : /* Check that X is an insn-body for an `asm' with operands
142 : and that the operands mentioned in it are legitimate. */
143 :
144 : bool
145 108782793 : check_asm_operands (rtx x)
146 : {
147 108782793 : int noperands;
148 108782793 : rtx *operands;
149 108782793 : const char **constraints;
150 108782793 : int i;
151 :
152 108782793 : if (!asm_labels_ok (x))
153 : return false;
154 :
155 : /* Post-reload, be more strict with things. */
156 108782793 : if (reload_completed)
157 : {
158 : /* ??? Doh! We've not got the wrapping insn. Cook one up. */
159 29600 : rtx_insn *insn = make_insn_raw (x);
160 29600 : extract_insn (insn);
161 29600 : constrain_operands (1, get_enabled_alternatives (insn));
162 29600 : return which_alternative >= 0;
163 : }
164 :
165 108753193 : noperands = asm_noperands (x);
166 108753193 : if (noperands < 0)
167 : return false;
168 779670 : if (noperands == 0)
169 : return true;
170 :
171 680292 : operands = XALLOCAVEC (rtx, noperands);
172 680292 : constraints = XALLOCAVEC (const char *, noperands);
173 :
174 680292 : decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
175 :
176 3982098 : for (i = 0; i < noperands; i++)
177 : {
178 2919049 : const char *c = constraints[i];
179 2919049 : if (c[0] == '%')
180 13363 : c++;
181 2919049 : if (! asm_operand_ok (operands[i], c, constraints))
182 : return false;
183 : }
184 :
185 : return true;
186 : }
187 :
188 : /* Static data for the next two routines. */
189 :
190 : struct change_t
191 : {
192 : rtx object;
193 : int old_code;
194 : int old_len;
195 : bool unshare;
196 : rtx *loc;
197 : rtx old;
198 : };
199 :
200 : static change_t *changes;
201 : static int changes_allocated;
202 :
203 : static int num_changes = 0;
204 : int undo_recog_changes::s_num_changes = 0;
205 :
206 : /* Validate a proposed change to OBJECT. LOC is the location in the rtl
207 : at which NEW_RTX will be placed. If NEW_LEN is >= 0, XVECLEN (NEW_RTX, 0)
208 : will also be changed to NEW_LEN, which is no greater than the current
209 : XVECLEN. If OBJECT is zero, no validation is done, the change is
210 : simply made.
211 :
212 : Two types of objects are supported: If OBJECT is a MEM, memory_address_p
213 : will be called with the address and mode as parameters. If OBJECT is
214 : an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
215 : the change in place.
216 :
217 : IN_GROUP is nonzero if this is part of a group of changes that must be
218 : performed as a group. In that case, the changes will be stored. The
219 : function `apply_change_group' will validate and apply the changes.
220 :
221 : If IN_GROUP is zero, this is a single change. Try to recognize the insn
222 : or validate the memory reference with the change applied. If the result
223 : is not valid for the machine, suppress the change and return false.
224 : Otherwise, perform the change and return true. */
225 :
226 : static bool
227 1847859930 : validate_change_1 (rtx object, rtx *loc, rtx new_rtx, bool in_group,
228 : bool unshare, int new_len = -1)
229 : {
230 1847859930 : gcc_assert (!undo_recog_changes::is_active ());
231 1847859930 : rtx old = *loc;
232 :
233 : /* Single-element parallels aren't valid and won't match anything.
234 : Replace them with the single element. */
235 1847859930 : if (new_len == 1 && GET_CODE (new_rtx) == PARALLEL)
236 : {
237 6606443 : new_rtx = XVECEXP (new_rtx, 0, 0);
238 6606443 : new_len = -1;
239 : }
240 :
241 : /* When a change is part of a group, callers expect to be able to change
242 : INSN_CODE after making the change and have the code reset to its old
243 : value by a later cancel_changes. We therefore need to register group
244 : changes even if they're no-ops. */
245 1847859930 : if (!in_group
246 215499662 : && (old == new_rtx || rtx_equal_p (old, new_rtx))
247 2044609323 : && (new_len < 0 || XVECLEN (new_rtx, 0) == new_len))
248 : return true;
249 :
250 1651110537 : gcc_assert ((in_group != 0 || num_changes == 0)
251 : && (new_len < 0 || new_rtx == *loc));
252 :
253 1651110537 : *loc = new_rtx;
254 :
255 : /* Save the information describing this change. */
256 1651110537 : if (num_changes >= changes_allocated)
257 : {
258 179370 : if (changes_allocated == 0)
259 : /* This value allows for repeated substitutions inside complex
260 : indexed addresses, or changes in up to 5 insns. */
261 : changes_allocated = MAX_RECOG_OPERANDS * 5;
262 : else
263 1222 : changes_allocated *= 2;
264 :
265 179370 : changes = XRESIZEVEC (change_t, changes, changes_allocated);
266 : }
267 :
268 1651110537 : changes[num_changes].object = object;
269 1651110537 : changes[num_changes].loc = loc;
270 1651110537 : changes[num_changes].old = old;
271 1651110537 : changes[num_changes].old_len = (new_len >= 0 ? XVECLEN (new_rtx, 0) : -1);
272 1651110537 : changes[num_changes].unshare = unshare;
273 :
274 1651110537 : if (new_len >= 0)
275 11930988 : XVECLEN (new_rtx, 0) = new_len;
276 :
277 1651110537 : if (object && !MEM_P (object))
278 : {
279 : /* Set INSN_CODE to force rerecognition of insn. Save old code in
280 : case invalid. */
281 1626475290 : changes[num_changes].old_code = INSN_CODE (object);
282 1626475290 : INSN_CODE (object) = -1;
283 : }
284 :
285 1651110537 : num_changes++;
286 :
287 : /* If we are making a group of changes, return 1. Otherwise, validate the
288 : change group we made. */
289 :
290 1651110537 : if (in_group)
291 : return true;
292 : else
293 18750269 : return apply_change_group ();
294 : }
295 :
296 : /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
297 : UNSHARE to false. */
298 :
299 : bool
300 1534431430 : validate_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
301 : {
302 1534431430 : return validate_change_1 (object, loc, new_rtx, in_group, false);
303 : }
304 :
305 : /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
306 : UNSHARE to true. */
307 :
308 : bool
309 294891069 : validate_unshare_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
310 : {
311 294891069 : return validate_change_1 (object, loc, new_rtx, in_group, true);
312 : }
313 :
314 : /* Change XVECLEN (*LOC, 0) to NEW_LEN. OBJECT, IN_GROUP and the return
315 : value are as for validate_change_1. */
316 :
317 : bool
318 18537431 : validate_change_xveclen (rtx object, rtx *loc, int new_len, bool in_group)
319 : {
320 18537431 : return validate_change_1 (object, loc, *loc, in_group, false, new_len);
321 : }
322 :
323 : /* Keep X canonicalized if some changes have made it non-canonical; only
324 : modifies the operands of X, not (for example) its code. Simplifications
325 : are not the job of this routine.
326 :
327 : Return true if anything was changed. */
328 : bool
329 1916774 : canonicalize_change_group (rtx_insn *insn, rtx x)
330 : {
331 1916774 : if (COMMUTATIVE_P (x)
332 1916774 : && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
333 : {
334 : /* Oops, the caller has made X no longer canonical.
335 : Let's redo the changes in the correct order. */
336 106929 : rtx tem = XEXP (x, 0);
337 106929 : validate_unshare_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
338 106929 : validate_unshare_change (insn, &XEXP (x, 1), tem, 1);
339 106929 : return true;
340 : }
341 : else
342 : return false;
343 : }
344 :
345 : /* Check if REG_INC argument in *data overlaps a stored REG. */
346 :
347 : static void
348 0 : check_invalid_inc_dec (rtx reg, const_rtx, void *data)
349 : {
350 0 : rtx *pinc = (rtx *) data;
351 0 : if (*pinc == NULL_RTX || MEM_P (reg))
352 : return;
353 0 : if (reg_overlap_mentioned_p (reg, *pinc))
354 0 : *pinc = NULL_RTX;
355 : }
356 :
357 : /* This subroutine of apply_change_group verifies whether the changes to INSN
358 : were valid; i.e. whether INSN can still be recognized.
359 :
360 : If IN_GROUP is true clobbers which have to be added in order to
361 : match the instructions will be added to the current change group.
362 : Otherwise the changes will take effect immediately. */
363 :
364 : bool
365 480336218 : insn_invalid_p (rtx_insn *insn, bool in_group)
366 : {
367 480336218 : rtx pat = PATTERN (insn);
368 480336218 : int num_clobbers = 0;
369 : /* If we are before reload and the pattern is a SET, see if we can add
370 : clobbers. */
371 480336218 : int icode = recog (pat, insn,
372 480336218 : (GET_CODE (pat) == SET
373 396833827 : && ! reload_completed
374 376762088 : && ! reload_in_progress)
375 : ? &num_clobbers : 0);
376 480336218 : bool is_asm = icode < 0 && asm_noperands (PATTERN (insn)) >= 0;
377 :
378 :
379 : /* If this is an asm and the operand aren't legal, then fail. Likewise if
380 : this is not an asm and the insn wasn't recognized. */
381 588284 : if ((is_asm && ! check_asm_operands (PATTERN (insn)))
382 480124526 : || (!is_asm && icode < 0))
383 : return true;
384 :
385 : /* If we have to add CLOBBERs, fail if we have to add ones that reference
386 : hard registers since our callers can't know if they are live or not.
387 : Otherwise, add them. */
388 462068642 : if (num_clobbers > 0)
389 : {
390 1981 : rtx newpat;
391 :
392 1981 : if (added_clobbers_hard_reg_p (icode))
393 : return true;
394 :
395 628 : newpat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_clobbers + 1));
396 628 : XVECEXP (newpat, 0, 0) = pat;
397 628 : add_clobbers (newpat, icode);
398 628 : if (in_group)
399 627 : validate_change (insn, &PATTERN (insn), newpat, 1);
400 : else
401 1 : PATTERN (insn) = pat = newpat;
402 : }
403 :
404 : /* After reload, verify that all constraints are satisfied. */
405 462067289 : if (reload_completed)
406 : {
407 20017610 : extract_insn (insn);
408 :
409 20017610 : if (! constrain_operands (1, get_preferred_alternatives (insn)))
410 : return true;
411 : }
412 :
413 : /* Punt if REG_INC argument overlaps some stored REG. */
414 462048808 : for (rtx link = FIND_REG_INC_NOTE (insn, NULL_RTX);
415 462048808 : link; link = XEXP (link, 1))
416 : if (REG_NOTE_KIND (link) == REG_INC)
417 : {
418 : rtx reg = XEXP (link, 0);
419 : note_stores (insn, check_invalid_inc_dec, ®);
420 : if (reg == NULL_RTX)
421 : return true;
422 : }
423 :
424 462048808 : INSN_CODE (insn) = icode;
425 462048808 : return false;
426 : }
427 :
428 : /* Return number of changes made and not validated yet. */
429 : int
430 4972194 : num_changes_pending (void)
431 : {
432 4972194 : return num_changes;
433 : }
434 :
435 : /* Tentatively apply the changes numbered NUM and up.
436 : Return true if all changes are valid, false otherwise. */
437 :
438 : bool
439 786455798 : verify_changes (int num)
440 : {
441 786455798 : int i;
442 786455798 : rtx last_validated = NULL_RTX;
443 :
444 : /* The changes have been applied and all INSN_CODEs have been reset to force
445 : rerecognition.
446 :
447 : The changes are valid if we aren't given an object, or if we are
448 : given a MEM and it still is a valid address, or if this is in insn
449 : and it is recognized. In the latter case, if reload has completed,
450 : we also require that the operands meet the constraints for
451 : the insn. */
452 :
453 2297487895 : for (i = num; i < num_changes; i++)
454 : {
455 1526032828 : rtx object = changes[i].object;
456 :
457 : /* If there is no object to test or if it is the same as the one we
458 : already tested, ignore it. */
459 1526032828 : if (object == 0 || object == last_validated)
460 782068619 : continue;
461 :
462 743964209 : if (MEM_P (object))
463 : {
464 37014 : if (! memory_address_addr_space_p (GET_MODE (object),
465 : XEXP (object, 0),
466 18507 : MEM_ADDR_SPACE (object)))
467 : break;
468 : }
469 743945702 : else if (/* changes[i].old might be zero, e.g. when putting a
470 : REG_FRAME_RELATED_EXPR into a previously empty list. */
471 743945702 : changes[i].old
472 743945702 : && REG_P (changes[i].old)
473 238030286 : && asm_noperands (PATTERN (object)) > 0
474 744153513 : && register_asm_p (changes[i].old))
475 : {
476 : /* Don't allow changes of hard register operands to inline
477 : assemblies if they have been defined as register asm ("x"). */
478 : break;
479 : }
480 743945701 : else if (DEBUG_INSN_P (object))
481 264546342 : continue;
482 479399359 : else if (insn_invalid_p (as_a <rtx_insn *> (object), true))
483 : {
484 17721959 : rtx pat = PATTERN (object);
485 :
486 : /* Perhaps we couldn't recognize the insn because there were
487 : extra CLOBBERs at the end. If so, try to re-recognize
488 : without the last CLOBBER (later iterations will cause each of
489 : them to be eliminated, in turn). But don't do this if we
490 : have an ASM_OPERAND. */
491 17721959 : if (GET_CODE (pat) == PARALLEL
492 4212653 : && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
493 20639938 : && asm_noperands (PATTERN (object)) < 0)
494 : {
495 2707947 : rtx newpat;
496 :
497 2707947 : if (XVECLEN (pat, 0) == 2)
498 2285031 : newpat = XVECEXP (pat, 0, 0);
499 : else
500 : {
501 422916 : int j;
502 :
503 422916 : newpat
504 422916 : = gen_rtx_PARALLEL (VOIDmode,
505 : rtvec_alloc (XVECLEN (pat, 0) - 1));
506 1303211 : for (j = 0; j < XVECLEN (newpat, 0); j++)
507 880295 : XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
508 : }
509 :
510 : /* Add a new change to this group to replace the pattern
511 : with this new pattern. Then consider this change
512 : as having succeeded. The change we added will
513 : cause the entire call to fail if things remain invalid.
514 :
515 : Note that this can lose if a later change than the one
516 : we are processing specified &XVECEXP (PATTERN (object), 0, X)
517 : but this shouldn't occur. */
518 :
519 2707947 : validate_change (object, &PATTERN (object), newpat, 1);
520 2707947 : continue;
521 2707947 : }
522 15014012 : else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER
523 15000660 : || GET_CODE (pat) == VAR_LOCATION)
524 : /* If this insn is a CLOBBER or USE, it is always valid, but is
525 : never recognized. */
526 13352 : continue;
527 : else
528 : break;
529 : }
530 : last_validated = object;
531 : }
532 :
533 786455798 : return (i == num_changes);
534 : }
535 :
536 : /* A group of changes has previously been issued with validate_change
537 : and verified with verify_changes. Call df_insn_rescan for each of
538 : the insn changed and clear num_changes. */
539 :
540 : void
541 782681121 : confirm_change_group (void)
542 : {
543 782681121 : int i;
544 782681121 : rtx last_object = NULL;
545 :
546 782681121 : gcc_assert (!undo_recog_changes::is_active ());
547 2303435784 : for (i = 0; i < num_changes; i++)
548 : {
549 1520754663 : rtx object = changes[i].object;
550 :
551 1520754663 : if (changes[i].unshare)
552 20350814 : *changes[i].loc = copy_rtx (*changes[i].loc);
553 :
554 : /* Avoid unnecessary rescanning when multiple changes to same instruction
555 : are made. */
556 1520754663 : if (object)
557 : {
558 1518361932 : if (object != last_object && last_object && INSN_P (last_object))
559 7764292 : df_insn_rescan (as_a <rtx_insn *> (last_object));
560 : last_object = object;
561 : }
562 : }
563 :
564 782681121 : if (last_object && INSN_P (last_object))
565 614774861 : df_insn_rescan (as_a <rtx_insn *> (last_object));
566 782681121 : num_changes = 0;
567 782681121 : }
568 :
569 : /* Apply a group of changes previously issued with `validate_change'.
570 : If all changes are valid, call confirm_change_group and return true,
571 : otherwise, call cancel_changes and return false. */
572 :
573 : bool
574 779159086 : apply_change_group (void)
575 : {
576 779159086 : if (verify_changes (0))
577 : {
578 766969416 : confirm_change_group ();
579 766969416 : return true;
580 : }
581 : else
582 : {
583 12189670 : cancel_changes (0);
584 12189670 : return false;
585 : }
586 : }
587 :
588 :
589 : /* Return the number of changes so far in the current group. */
590 :
591 : int
592 757894334 : num_validated_changes (void)
593 : {
594 757894334 : return num_changes;
595 : }
596 :
597 : /* Retract the changes numbered NUM and up. */
598 :
599 : void
600 172371453 : cancel_changes (int num)
601 : {
602 172371453 : gcc_assert (!undo_recog_changes::is_active ());
603 172371453 : int i;
604 :
605 : /* Back out all the changes. Do this in the opposite order in which
606 : they were made. */
607 302727327 : for (i = num_changes - 1; i >= num; i--)
608 : {
609 130355874 : if (changes[i].old_len >= 0)
610 11028335 : XVECLEN (*changes[i].loc, 0) = changes[i].old_len;
611 : else
612 119327539 : *changes[i].loc = changes[i].old;
613 130355874 : if (changes[i].object && !MEM_P (changes[i].object))
614 : {
615 108131795 : INSN_CODE (changes[i].object) = changes[i].old_code;
616 108131795 : if (recog_data.insn == changes[i].object)
617 184 : recog_data.insn = nullptr;
618 : }
619 : }
620 172371453 : num_changes = num;
621 172371453 : }
622 :
623 : /* Swap the status of change NUM from being applied to not being applied,
624 : or vice versa. */
625 :
626 : static void
627 48651934 : swap_change (int num)
628 : {
629 48651934 : if (changes[num].old_len >= 0)
630 2256336 : std::swap (XVECLEN (*changes[num].loc, 0), changes[num].old_len);
631 : else
632 46395598 : std::swap (*changes[num].loc, changes[num].old);
633 48651934 : if (changes[num].object && !MEM_P (changes[num].object))
634 : {
635 48651934 : std::swap (INSN_CODE (changes[num].object), changes[num].old_code);
636 48651934 : if (recog_data.insn == changes[num].object)
637 8 : recog_data.insn = nullptr;
638 : }
639 48651934 : }
640 :
641 28249415 : undo_recog_changes::undo_recog_changes (int num)
642 28249415 : : m_old_num_changes (s_num_changes)
643 : {
644 28249415 : gcc_assert (num <= num_changes - s_num_changes);
645 52575382 : for (int i = num_changes - s_num_changes - 1; i >= num; i--)
646 24325967 : swap_change (i);
647 28249415 : s_num_changes = num_changes - num;
648 28249415 : }
649 :
650 28249415 : undo_recog_changes::~undo_recog_changes ()
651 : {
652 52575382 : for (int i = num_changes - s_num_changes;
653 52575382 : i < num_changes - m_old_num_changes; ++i)
654 24325967 : swap_change (i);
655 28249415 : s_num_changes = m_old_num_changes;
656 28249415 : }
657 :
658 : /* Reduce conditional compilation elsewhere. */
659 : /* A subroutine of validate_replace_rtx_1 that tries to simplify the resulting
660 : rtx. */
661 :
662 : static void
663 12803484 : simplify_while_replacing (rtx *loc, rtx to, rtx_insn *object,
664 : machine_mode op0_mode)
665 : {
666 12803484 : rtx x = *loc;
667 12803484 : enum rtx_code code = GET_CODE (x);
668 12803484 : rtx new_rtx = NULL_RTX;
669 12803484 : scalar_int_mode is_mode;
670 :
671 12803484 : if (SWAPPABLE_OPERANDS_P (x)
672 12803484 : && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
673 : {
674 470145 : validate_unshare_change (object, loc,
675 470145 : gen_rtx_fmt_ee (COMMUTATIVE_ARITH_P (x) ? code
676 : : swap_condition (code),
677 : GET_MODE (x), XEXP (x, 1),
678 : XEXP (x, 0)), 1);
679 470145 : x = *loc;
680 470145 : code = GET_CODE (x);
681 : }
682 :
683 : /* Canonicalize arithmetics with all constant operands. */
684 12803484 : switch (GET_RTX_CLASS (code))
685 : {
686 836147 : case RTX_UNARY:
687 836147 : if (CONSTANT_P (XEXP (x, 0)))
688 581561 : new_rtx = simplify_unary_operation (code, GET_MODE (x), XEXP (x, 0),
689 : op0_mode);
690 : break;
691 6504955 : case RTX_COMM_ARITH:
692 6504955 : case RTX_BIN_ARITH:
693 6504955 : if (CONSTANT_P (XEXP (x, 0)) && CONSTANT_P (XEXP (x, 1)))
694 318807 : new_rtx = simplify_binary_operation (code, GET_MODE (x), XEXP (x, 0),
695 : XEXP (x, 1));
696 : break;
697 118654 : case RTX_COMPARE:
698 118654 : case RTX_COMM_COMPARE:
699 118654 : if (CONSTANT_P (XEXP (x, 0)) && CONSTANT_P (XEXP (x, 1)))
700 3224 : new_rtx = simplify_relational_operation (code, GET_MODE (x), op0_mode,
701 : XEXP (x, 0), XEXP (x, 1));
702 : break;
703 : default:
704 : break;
705 : }
706 903592 : if (new_rtx)
707 : {
708 852881 : validate_change (object, loc, new_rtx, 1);
709 852881 : return;
710 : }
711 :
712 11950603 : switch (code)
713 : {
714 2234718 : case PLUS:
715 : /* If we have a PLUS whose second operand is now a CONST_INT, use
716 : simplify_gen_binary to try to simplify it.
717 : ??? We may want later to remove this, once simplification is
718 : separated from this function. */
719 2234718 : if (CONST_INT_P (XEXP (x, 1)) && XEXP (x, 1) == to)
720 208491 : validate_change (object, loc,
721 : simplify_gen_binary
722 208491 : (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
723 : break;
724 485920 : case MINUS:
725 485920 : if (CONST_SCALAR_INT_P (XEXP (x, 1)))
726 23360 : validate_change (object, loc,
727 : simplify_gen_binary
728 23360 : (PLUS, GET_MODE (x), XEXP (x, 0),
729 : simplify_gen_unary (NEG,
730 : GET_MODE (x), XEXP (x, 1),
731 23360 : GET_MODE (x))), 1);
732 : break;
733 187548 : case ZERO_EXTEND:
734 187548 : case SIGN_EXTEND:
735 187548 : if (GET_MODE (XEXP (x, 0)) == VOIDmode)
736 : {
737 0 : new_rtx = simplify_gen_unary (code, GET_MODE (x), XEXP (x, 0),
738 : op0_mode);
739 : /* If any of the above failed, substitute in something that
740 : we know won't be recognized. */
741 0 : if (!new_rtx)
742 0 : new_rtx = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
743 0 : validate_change (object, loc, new_rtx, 1);
744 : }
745 : break;
746 160867 : case SUBREG:
747 : /* All subregs possible to simplify should be simplified. */
748 321734 : new_rtx = simplify_subreg (GET_MODE (x), SUBREG_REG (x), op0_mode,
749 160867 : SUBREG_BYTE (x));
750 :
751 : /* Subregs of VOIDmode operands are incorrect. */
752 160867 : if (!new_rtx && GET_MODE (SUBREG_REG (x)) == VOIDmode)
753 2 : new_rtx = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
754 2 : if (new_rtx)
755 137111 : validate_change (object, loc, new_rtx, 1);
756 : break;
757 5493 : case ZERO_EXTRACT:
758 5493 : case SIGN_EXTRACT:
759 : /* If we are replacing a register with memory, try to change the memory
760 : to be the mode required for memory in extract operations (this isn't
761 : likely to be an insertion operation; if it was, nothing bad will
762 : happen, we might just fail in some cases). */
763 :
764 5493 : if (MEM_P (XEXP (x, 0))
765 369 : && is_a <scalar_int_mode> (GET_MODE (XEXP (x, 0)), &is_mode)
766 369 : && CONST_INT_P (XEXP (x, 1))
767 369 : && CONST_INT_P (XEXP (x, 2))
768 272 : && !mode_dependent_address_p (XEXP (XEXP (x, 0), 0),
769 290 : MEM_ADDR_SPACE (XEXP (x, 0)))
770 5765 : && !MEM_VOLATILE_P (XEXP (x, 0)))
771 : {
772 268 : int pos = INTVAL (XEXP (x, 2));
773 268 : machine_mode new_mode = is_mode;
774 268 : if (GET_CODE (x) == ZERO_EXTRACT && targetm.have_extzv ())
775 0 : new_mode = insn_data[targetm.code_for_extzv].operand[1].mode;
776 268 : else if (GET_CODE (x) == SIGN_EXTRACT && targetm.have_extv ())
777 0 : new_mode = insn_data[targetm.code_for_extv].operand[1].mode;
778 268 : scalar_int_mode wanted_mode = (new_mode == VOIDmode
779 268 : ? word_mode
780 268 : : as_a <scalar_int_mode> (new_mode));
781 :
782 : /* If we have a narrower mode, we can do something. */
783 804 : if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
784 : {
785 0 : int offset = pos / BITS_PER_UNIT;
786 0 : rtx newmem;
787 :
788 : /* If the bytes and bits are counted differently, we
789 : must adjust the offset. */
790 0 : if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
791 : offset =
792 : (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) -
793 : offset);
794 :
795 0 : gcc_assert (GET_MODE_PRECISION (wanted_mode)
796 : == GET_MODE_BITSIZE (wanted_mode));
797 0 : pos %= GET_MODE_BITSIZE (wanted_mode);
798 :
799 0 : newmem = adjust_address_nv (XEXP (x, 0), wanted_mode, offset);
800 :
801 0 : validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
802 0 : validate_change (object, &XEXP (x, 0), newmem, 1);
803 : }
804 : }
805 :
806 : break;
807 :
808 : default:
809 : break;
810 : }
811 : }
812 :
813 : /* Replace every occurrence of FROM in X with TO. Mark each change with
814 : validate_change passing OBJECT. */
815 :
816 : static void
817 71615831 : validate_replace_rtx_1 (rtx *loc, rtx from, rtx to, rtx_insn *object,
818 : bool simplify)
819 : {
820 71615831 : int i, j;
821 71615831 : const char *fmt;
822 71615831 : rtx x = *loc;
823 71615831 : enum rtx_code code;
824 71615831 : machine_mode op0_mode = VOIDmode;
825 71615831 : int prev_changes = num_changes;
826 :
827 71615831 : if (!x)
828 : return;
829 :
830 71615831 : code = GET_CODE (x);
831 71615831 : fmt = GET_RTX_FORMAT (code);
832 71615831 : if (fmt[0] == 'e')
833 24434127 : op0_mode = GET_MODE (XEXP (x, 0));
834 :
835 : /* X matches FROM if it is the same rtx or they are both referring to the
836 : same register in the same mode. Avoid calling rtx_equal_p unless the
837 : operands look similar. */
838 :
839 71615831 : if (x == from
840 55341112 : || (REG_P (x) && REG_P (from)
841 15907728 : && GET_MODE (x) == GET_MODE (from)
842 9368945 : && REGNO (x) == REGNO (from))
843 126956943 : || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
844 9368945 : && rtx_equal_p (x, from)))
845 : {
846 16274719 : validate_unshare_change (object, loc, to, 1);
847 16274719 : return;
848 : }
849 :
850 : /* Call ourself recursively to perform the replacements.
851 : We must not replace inside already replaced expression, otherwise we
852 : get infinite recursion for replacements like (reg X)->(subreg (reg X))
853 : so we must special case shared ASM_OPERANDS. */
854 :
855 55341112 : if (GET_CODE (x) == PARALLEL)
856 : {
857 1439662 : for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
858 : {
859 1060199 : if (j && GET_CODE (XVECEXP (x, 0, j)) == SET
860 31509 : && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == ASM_OPERANDS)
861 : {
862 : /* Verify that operands are really shared. */
863 284 : gcc_assert (ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (x, 0, 0)))
864 : == ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP
865 : (x, 0, j))));
866 284 : validate_replace_rtx_1 (&SET_DEST (XVECEXP (x, 0, j)),
867 : from, to, object, simplify);
868 : }
869 : else
870 1059915 : validate_replace_rtx_1 (&XVECEXP (x, 0, j), from, to, object,
871 : simplify);
872 : }
873 : }
874 : else
875 140377477 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
876 : {
877 85415828 : if (fmt[i] == 'e')
878 41826950 : validate_replace_rtx_1 (&XEXP (x, i), from, to, object, simplify);
879 43588878 : else if (fmt[i] == 'E')
880 6831376 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
881 3720530 : validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object,
882 : simplify);
883 : }
884 :
885 : /* If we didn't substitute, there is nothing more to do. */
886 55341112 : if (num_changes == prev_changes)
887 : return;
888 :
889 : /* ??? The regmove is no more, so is this aberration still necessary? */
890 : /* Allow substituted expression to have different mode. This is used by
891 : regmove to change mode of pseudo register. */
892 12803548 : if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
893 9648793 : op0_mode = GET_MODE (XEXP (x, 0));
894 :
895 : /* Do changes needed to keep rtx consistent. Don't do any other
896 : simplifications, as it is not our job. */
897 12803548 : if (simplify)
898 12803484 : simplify_while_replacing (loc, to, object, op0_mode);
899 : }
900 :
901 : /* Try replacing every occurrence of FROM in subexpression LOC of INSN
902 : with TO. After all changes have been made, validate by seeing
903 : if INSN is still valid. */
904 :
905 : bool
906 0 : validate_replace_rtx_subexp (rtx from, rtx to, rtx_insn *insn, rtx *loc)
907 : {
908 0 : validate_replace_rtx_1 (loc, from, to, insn, true);
909 0 : return apply_change_group ();
910 : }
911 :
912 : /* Try replacing every occurrence of FROM in INSN with TO. After all
913 : changes have been made, validate by seeing if INSN is still valid. */
914 :
915 : bool
916 2149738 : validate_replace_rtx (rtx from, rtx to, rtx_insn *insn)
917 : {
918 2149738 : validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
919 2149738 : return apply_change_group ();
920 : }
921 :
922 : /* Try replacing every occurrence of FROM in WHERE with TO. Assume that WHERE
923 : is a part of INSN. After all changes have been made, validate by seeing if
924 : INSN is still valid.
925 : validate_replace_rtx (from, to, insn) is equivalent to
926 : validate_replace_rtx_part (from, to, &PATTERN (insn), insn). */
927 :
928 : bool
929 0 : validate_replace_rtx_part (rtx from, rtx to, rtx *where, rtx_insn *insn)
930 : {
931 0 : validate_replace_rtx_1 (where, from, to, insn, true);
932 0 : return apply_change_group ();
933 : }
934 :
935 : /* Same as above, but do not simplify rtx afterwards. */
936 : bool
937 82 : validate_replace_rtx_part_nosimplify (rtx from, rtx to, rtx *where,
938 : rtx_insn *insn)
939 : {
940 82 : validate_replace_rtx_1 (where, from, to, insn, false);
941 82 : return apply_change_group ();
942 :
943 : }
944 :
945 : /* Try replacing every occurrence of FROM in INSN with TO. This also
946 : will replace in REG_EQUAL and REG_EQUIV notes. */
947 :
948 : void
949 21 : validate_replace_rtx_group (rtx from, rtx to, rtx_insn *insn)
950 : {
951 21 : rtx note;
952 21 : validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
953 28 : for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
954 7 : if (REG_NOTE_KIND (note) == REG_EQUAL
955 7 : || REG_NOTE_KIND (note) == REG_EQUIV)
956 0 : validate_replace_rtx_1 (&XEXP (note, 0), from, to, insn, true);
957 21 : }
958 :
959 : /* Function called by note_uses to replace used subexpressions. */
960 : struct validate_replace_src_data
961 : {
962 : rtx from; /* Old RTX */
963 : rtx to; /* New RTX */
964 : rtx_insn *insn; /* Insn in which substitution is occurring. */
965 : };
966 :
967 : static void
968 22858311 : validate_replace_src_1 (rtx *x, void *data)
969 : {
970 22858311 : struct validate_replace_src_data *d
971 : = (struct validate_replace_src_data *) data;
972 :
973 22858311 : validate_replace_rtx_1 (x, d->from, d->to, d->insn, true);
974 22858311 : }
975 :
976 : /* Try replacing every occurrence of FROM in INSN with TO, avoiding
977 : SET_DESTs. */
978 :
979 : void
980 16264997 : validate_replace_src_group (rtx from, rtx to, rtx_insn *insn)
981 : {
982 16264997 : struct validate_replace_src_data d;
983 :
984 16264997 : d.from = from;
985 16264997 : d.to = to;
986 16264997 : d.insn = insn;
987 16264997 : note_uses (&PATTERN (insn), validate_replace_src_1, &d);
988 16264997 : }
989 :
990 : /* Try simplify INSN.
991 : Invoke simplify_rtx () on every SET_SRC and SET_DEST inside the INSN's
992 : pattern and return true if something was simplified. */
993 :
994 : bool
995 0 : validate_simplify_insn (rtx_insn *insn)
996 : {
997 0 : int i;
998 0 : rtx pat = NULL;
999 0 : rtx newpat = NULL;
1000 :
1001 0 : pat = PATTERN (insn);
1002 :
1003 0 : if (GET_CODE (pat) == SET)
1004 : {
1005 0 : newpat = simplify_rtx (SET_SRC (pat));
1006 0 : if (newpat && !rtx_equal_p (SET_SRC (pat), newpat))
1007 0 : validate_change (insn, &SET_SRC (pat), newpat, 1);
1008 0 : newpat = simplify_rtx (SET_DEST (pat));
1009 0 : if (newpat && !rtx_equal_p (SET_DEST (pat), newpat))
1010 0 : validate_change (insn, &SET_DEST (pat), newpat, 1);
1011 : }
1012 0 : else if (GET_CODE (pat) == PARALLEL)
1013 0 : for (i = 0; i < XVECLEN (pat, 0); i++)
1014 : {
1015 0 : rtx s = XVECEXP (pat, 0, i);
1016 :
1017 0 : if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
1018 : {
1019 0 : newpat = simplify_rtx (SET_SRC (s));
1020 0 : if (newpat && !rtx_equal_p (SET_SRC (s), newpat))
1021 0 : validate_change (insn, &SET_SRC (s), newpat, 1);
1022 0 : newpat = simplify_rtx (SET_DEST (s));
1023 0 : if (newpat && !rtx_equal_p (SET_DEST (s), newpat))
1024 0 : validate_change (insn, &SET_DEST (s), newpat, 1);
1025 : }
1026 : }
1027 0 : return ((num_changes_pending () > 0) && (apply_change_group () > 0));
1028 : }
1029 :
1030 : /* Try to process the address of memory expression MEM. Return true on
1031 : success; leave the caller to clean up on failure. */
1032 :
1033 : bool
1034 24720072 : insn_propagation::apply_to_mem_1 (rtx mem)
1035 : {
1036 24720072 : auto old_num_changes = num_validated_changes ();
1037 24720072 : mem_depth += 1;
1038 24720072 : bool res = apply_to_rvalue_1 (&XEXP (mem, 0));
1039 24720072 : mem_depth -= 1;
1040 24720072 : if (!res)
1041 : return false;
1042 :
1043 24719500 : if (old_num_changes != num_validated_changes ()
1044 7937432 : && should_check_mems
1045 28085678 : && !check_mem (old_num_changes, mem))
1046 : return false;
1047 :
1048 : return true;
1049 : }
1050 :
1051 : /* Try to process the rvalue expression at *LOC. Return true on success;
1052 : leave the caller to clean up on failure. */
1053 :
1054 : bool
1055 242323636 : insn_propagation::apply_to_rvalue_1 (rtx *loc)
1056 : {
1057 242323636 : rtx x = *loc;
1058 242323636 : enum rtx_code code = GET_CODE (x);
1059 242323636 : machine_mode mode = GET_MODE (x);
1060 :
1061 242323636 : auto old_num_changes = num_validated_changes ();
1062 242323636 : if (from
1063 231153379 : && GET_CODE (x) == GET_CODE (from)
1064 337125401 : && (REG_P (x)
1065 94801765 : ? REGNO (x) == REGNO (from)
1066 26198 : : rtx_equal_p (x, from)))
1067 : {
1068 : /* Don't replace register asms in asm statements; we mustn't
1069 : change the user's register allocation. */
1070 61000463 : if (REG_P (x)
1071 60975195 : && HARD_REGISTER_P (x)
1072 18577876 : && register_asm_p (x)
1073 61002519 : && asm_noperands (PATTERN (insn)) > 0)
1074 : return false;
1075 :
1076 60998578 : rtx newval = to;
1077 60998578 : if (GET_MODE (x) != GET_MODE (from))
1078 : {
1079 724053 : gcc_assert (REG_P (x) && HARD_REGISTER_P (x));
1080 724053 : if (REG_NREGS (x) != REG_NREGS (from)
1081 724053 : || !REG_CAN_CHANGE_MODE_P (REGNO (x), GET_MODE (from),
1082 : GET_MODE (x)))
1083 372834 : return false;
1084 :
1085 : /* If the reference is paradoxical and the replacement
1086 : value contains registers, we would need to check that the
1087 : simplification below does not increase REG_NREGS for those
1088 : registers either. It seems simpler to punt on nonconstant
1089 : values instead. */
1090 638723 : if (paradoxical_subreg_p (GET_MODE (x), GET_MODE (from))
1091 638723 : && !CONSTANT_P (to))
1092 : return false;
1093 :
1094 619322 : newval = simplify_subreg (GET_MODE (x), to, GET_MODE (from),
1095 : subreg_lowpart_offset (GET_MODE (x),
1096 : GET_MODE (from)));
1097 619322 : if (!newval)
1098 : return false;
1099 :
1100 : /* Check that the simplification didn't just push an explicit
1101 : subreg down into subexpressions. In particular, for a register
1102 : R that has a fixed mode, such as the stack pointer, a subreg of:
1103 :
1104 : (plus:M (reg:M R) (const_int C))
1105 :
1106 : would be:
1107 :
1108 : (plus:N (subreg:N (reg:M R) ...) (const_int C'))
1109 :
1110 : But targets can legitimately assume that subregs of hard registers
1111 : will not be created after RA (except in special circumstances,
1112 : such as strict_low_part). */
1113 354354 : subrtx_iterator::array_type array;
1114 1350405 : FOR_EACH_SUBRTX (iter, array, newval, NONCONST)
1115 999186 : if (GET_CODE (*iter) == SUBREG)
1116 3135 : return false;
1117 354354 : }
1118 :
1119 60625744 : if (should_unshare)
1120 60625744 : validate_unshare_change (insn, loc, newval, 1);
1121 : else
1122 0 : validate_change (insn, loc, newval, 1);
1123 60625744 : if (mem_depth && !REG_P (newval) && !CONSTANT_P (newval))
1124 : {
1125 : /* We're substituting into an address, but TO will have the
1126 : form expected outside an address. Canonicalize it if
1127 : necessary. */
1128 3562909 : insn_propagation subprop (insn);
1129 3562909 : subprop.mem_depth += 1;
1130 3562909 : if (!subprop.apply_to_rvalue (loc))
1131 0 : gcc_unreachable ();
1132 3562909 : if (should_unshare
1133 3562909 : && num_validated_changes () != old_num_changes + 1)
1134 : {
1135 : /* TO is owned by someone else, so create a copy and
1136 : return TO to its original form. */
1137 285210 : newval = copy_rtx (*loc);
1138 285210 : cancel_changes (old_num_changes);
1139 285210 : validate_change (insn, loc, newval, 1);
1140 : }
1141 : }
1142 60625744 : num_replacements += 1;
1143 60625744 : should_unshare = true;
1144 60625744 : result_flags |= UNSIMPLIFIED;
1145 60625744 : return true;
1146 : }
1147 :
1148 : /* Recursively apply the substitution and see if we can simplify
1149 : the result. This specifically shouldn't use simplify_gen_* for
1150 : speculative simplifications, since we want to avoid generating new
1151 : expressions where possible. */
1152 181323173 : auto old_result_flags = result_flags;
1153 181323173 : rtx newx = NULL_RTX;
1154 181323173 : bool recurse_p = false;
1155 181323173 : switch (GET_RTX_CLASS (code))
1156 : {
1157 3213826 : case RTX_UNARY:
1158 3213826 : {
1159 3213826 : machine_mode op0_mode = GET_MODE (XEXP (x, 0));
1160 3213826 : if (!apply_to_rvalue_1 (&XEXP (x, 0)))
1161 : return false;
1162 3169827 : if (from && old_num_changes == num_validated_changes ())
1163 : return true;
1164 :
1165 2532940 : newx = simplify_unary_operation (code, mode, XEXP (x, 0), op0_mode);
1166 2532940 : break;
1167 : }
1168 :
1169 46997833 : case RTX_BIN_ARITH:
1170 46997833 : case RTX_COMM_ARITH:
1171 46997833 : {
1172 46997833 : if (!apply_to_rvalue_1 (&XEXP (x, 0))
1173 46997833 : || !apply_to_rvalue_1 (&XEXP (x, 1)))
1174 : return false;
1175 46508374 : if (from && old_num_changes == num_validated_changes ())
1176 : return true;
1177 :
1178 35676379 : if (GET_RTX_CLASS (code) == RTX_COMM_ARITH
1179 35676379 : && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
1180 2712916 : newx = simplify_gen_binary (code, mode, XEXP (x, 1), XEXP (x, 0));
1181 : else
1182 32963463 : newx = simplify_binary_operation (code, mode,
1183 : XEXP (x, 0), XEXP (x, 1));
1184 : break;
1185 : }
1186 :
1187 6137491 : case RTX_COMPARE:
1188 6137491 : case RTX_COMM_COMPARE:
1189 6137491 : {
1190 12275104 : machine_mode op_mode = (GET_MODE (XEXP (x, 0)) != VOIDmode
1191 6137491 : ? GET_MODE (XEXP (x, 0))
1192 122 : : GET_MODE (XEXP (x, 1)));
1193 6137491 : if (!apply_to_rvalue_1 (&XEXP (x, 0))
1194 6137491 : || !apply_to_rvalue_1 (&XEXP (x, 1)))
1195 : return false;
1196 6133180 : if (from && old_num_changes == num_validated_changes ())
1197 : return true;
1198 :
1199 5185672 : newx = simplify_relational_operation (code, mode, op_mode,
1200 : XEXP (x, 0), XEXP (x, 1));
1201 5185672 : break;
1202 : }
1203 :
1204 5540800 : case RTX_TERNARY:
1205 5540800 : case RTX_BITFIELD_OPS:
1206 5540800 : {
1207 5540800 : machine_mode op0_mode = GET_MODE (XEXP (x, 0));
1208 5540800 : if (!apply_to_rvalue_1 (&XEXP (x, 0))
1209 5529778 : || !apply_to_rvalue_1 (&XEXP (x, 1))
1210 11049685 : || !apply_to_rvalue_1 (&XEXP (x, 2)))
1211 : return false;
1212 5506538 : if (from && old_num_changes == num_validated_changes ())
1213 : return true;
1214 :
1215 5436880 : newx = simplify_ternary_operation (code, mode, op0_mode,
1216 : XEXP (x, 0), XEXP (x, 1),
1217 : XEXP (x, 2));
1218 5436880 : break;
1219 : }
1220 :
1221 11572181 : case RTX_EXTRA:
1222 11572181 : if (code == SUBREG)
1223 : {
1224 2660436 : machine_mode inner_mode = GET_MODE (SUBREG_REG (x));
1225 2660436 : if (!apply_to_rvalue_1 (&SUBREG_REG (x)))
1226 : return false;
1227 2660424 : if (from && old_num_changes == num_validated_changes ())
1228 : return true;
1229 :
1230 1952498 : rtx inner = SUBREG_REG (x);
1231 1952498 : newx = simplify_subreg (mode, inner, inner_mode, SUBREG_BYTE (x));
1232 : /* Reject the same cases that simplify_gen_subreg would. */
1233 1952498 : if (!newx
1234 1952498 : && (GET_CODE (inner) == SUBREG
1235 1223285 : || GET_CODE (inner) == CONCAT
1236 1211174 : || GET_MODE (inner) == VOIDmode
1237 1223285 : || !validate_subreg (mode, inner_mode,
1238 1211173 : inner, SUBREG_BYTE (x))))
1239 : {
1240 12154 : failure_reason = "would create an invalid subreg";
1241 12154 : return false;
1242 : }
1243 : break;
1244 : }
1245 : else
1246 : recurse_p = true;
1247 : break;
1248 :
1249 54936886 : case RTX_OBJ:
1250 54936886 : if (code == LO_SUM)
1251 : {
1252 0 : if (!apply_to_rvalue_1 (&XEXP (x, 0))
1253 0 : || !apply_to_rvalue_1 (&XEXP (x, 1)))
1254 : return false;
1255 0 : if (from && old_num_changes == num_validated_changes ())
1256 : return true;
1257 :
1258 : /* (lo_sum (high x) y) -> y where x and y have the same base. */
1259 0 : rtx op0 = XEXP (x, 0);
1260 0 : rtx op1 = XEXP (x, 1);
1261 0 : if (GET_CODE (op0) == HIGH)
1262 : {
1263 0 : rtx base0, base1, offset0, offset1;
1264 0 : split_const (XEXP (op0, 0), &base0, &offset0);
1265 0 : split_const (op1, &base1, &offset1);
1266 0 : if (rtx_equal_p (base0, base1))
1267 0 : newx = op1;
1268 : }
1269 : }
1270 54936886 : else if (code == REG)
1271 : {
1272 37961354 : if (from && REG_P (from) && reg_overlap_mentioned_p (x, from))
1273 : {
1274 63276 : failure_reason = "inexact register overlap";
1275 63276 : return false;
1276 : }
1277 : }
1278 16975532 : else if (code == MEM)
1279 12856937 : return apply_to_mem_1 (x);
1280 : else
1281 : recurse_p = true;
1282 : break;
1283 :
1284 : case RTX_CONST_OBJ:
1285 : break;
1286 :
1287 1435223 : case RTX_AUTOINC:
1288 1435223 : if (from && reg_overlap_mentioned_p (XEXP (x, 0), from))
1289 : {
1290 0 : failure_reason = "is subject to autoinc";
1291 0 : return false;
1292 : }
1293 : recurse_p = true;
1294 : break;
1295 :
1296 0 : case RTX_MATCH:
1297 0 : case RTX_INSN:
1298 0 : gcc_unreachable ();
1299 : }
1300 :
1301 50772215 : if (recurse_p)
1302 : {
1303 14465563 : const char *fmt = GET_RTX_FORMAT (code);
1304 33056997 : for (int i = 0; fmt[i]; i++)
1305 18702572 : switch (fmt[i])
1306 : {
1307 : case 'E':
1308 6582397 : for (int j = 0; j < XVECLEN (x, i); j++)
1309 4699190 : if (!apply_to_rvalue_1 (&XVECEXP (x, i, j)))
1310 : return false;
1311 : break;
1312 :
1313 12654964 : case 'e':
1314 12654964 : if (XEXP (x, i) && !apply_to_rvalue_1 (&XEXP (x, i)))
1315 : return false;
1316 : break;
1317 : }
1318 : }
1319 140159226 : else if (newx && !rtx_equal_p (x, newx))
1320 : {
1321 : /* All substitutions made by OLD_NUM_CHANGES onwards have been
1322 : simplified. */
1323 10909910 : result_flags = ((result_flags & ~UNSIMPLIFIED)
1324 : | (old_result_flags & UNSIMPLIFIED));
1325 :
1326 10909910 : if (should_note_simplifications)
1327 4013973 : note_simplification (old_num_changes, old_result_flags, x, newx);
1328 :
1329 : /* There's no longer any point unsharing the substitutions made
1330 : for subexpressions, since we'll just copy this one instead. */
1331 10909910 : bool unshare = false;
1332 21812112 : for (int i = old_num_changes; i < num_changes; ++i)
1333 : {
1334 10902202 : unshare |= changes[i].unshare;
1335 10902202 : changes[i].unshare = false;
1336 : }
1337 10909910 : if (unshare)
1338 10511995 : validate_unshare_change (insn, loc, newx, 1);
1339 : else
1340 397915 : validate_change (insn, loc, newx, 1);
1341 : }
1342 :
1343 : return true;
1344 : }
1345 :
1346 : /* Try to process the lvalue expression at *LOC. Return true on success;
1347 : leave the caller to clean up on failure. */
1348 :
1349 : bool
1350 64987258 : insn_propagation::apply_to_lvalue_1 (rtx dest)
1351 : {
1352 64987258 : rtx old_dest = dest;
1353 64987258 : while (GET_CODE (dest) == SUBREG
1354 65201420 : || GET_CODE (dest) == ZERO_EXTRACT
1355 65201420 : || GET_CODE (dest) == STRICT_LOW_PART)
1356 : {
1357 214162 : if (GET_CODE (dest) == ZERO_EXTRACT
1358 214162 : && (!apply_to_rvalue_1 (&XEXP (dest, 1))
1359 2664 : || !apply_to_rvalue_1 (&XEXP (dest, 2))))
1360 : return false;
1361 214162 : dest = XEXP (dest, 0);
1362 : }
1363 :
1364 64987258 : if (MEM_P (dest))
1365 11863135 : return apply_to_mem_1 (dest);
1366 :
1367 : /* Check whether the substitution is safe in the presence of this lvalue. */
1368 53124123 : if (!from
1369 53124123 : || dest == old_dest
1370 209871 : || !REG_P (dest)
1371 53333994 : || !reg_overlap_mentioned_p (dest, from))
1372 : return true;
1373 :
1374 103764 : if (SUBREG_P (old_dest)
1375 99115 : && SUBREG_REG (old_dest) == dest
1376 202879 : && !read_modify_subreg_p (old_dest))
1377 : return true;
1378 :
1379 103445 : failure_reason = "is part of a read-write destination";
1380 103445 : return false;
1381 : }
1382 :
1383 : /* Try to process the instruction pattern at *LOC. Return true on success;
1384 : leave the caller to clean up on failure. */
1385 :
1386 : bool
1387 68655267 : insn_propagation::apply_to_pattern_1 (rtx *loc)
1388 : {
1389 68655267 : rtx body = *loc;
1390 68655267 : switch (GET_CODE (body))
1391 : {
1392 0 : case COND_EXEC:
1393 0 : return (apply_to_rvalue_1 (&COND_EXEC_TEST (body))
1394 0 : && apply_to_pattern_1 (&COND_EXEC_CODE (body)));
1395 :
1396 : case PARALLEL:
1397 15143187 : for (int i = 0; i < XVECLEN (body, 0); ++i)
1398 : {
1399 10354291 : rtx *subloc = &XVECEXP (body, 0, i);
1400 10354291 : if (GET_CODE (*subloc) == SET)
1401 : {
1402 5627094 : if (!apply_to_lvalue_1 (SET_DEST (*subloc)))
1403 : return false;
1404 : /* ASM_OPERANDS are shared between SETs in the same PARALLEL.
1405 : Only process them on the first iteration. */
1406 792419 : if ((i == 0 || GET_CODE (SET_SRC (*subloc)) != ASM_OPERANDS)
1407 6278721 : && !apply_to_rvalue_1 (&SET_SRC (*subloc)))
1408 : return false;
1409 : }
1410 : else
1411 : {
1412 4727197 : if (!apply_to_pattern_1 (subloc))
1413 : return false;
1414 : }
1415 : }
1416 : return true;
1417 :
1418 8729 : case ASM_OPERANDS:
1419 30716 : for (int i = 0, len = ASM_OPERANDS_INPUT_LENGTH (body); i < len; ++i)
1420 22207 : if (!apply_to_rvalue_1 (&ASM_OPERANDS_INPUT (body, i)))
1421 : return false;
1422 : return true;
1423 :
1424 4521437 : case CLOBBER:
1425 4521437 : return apply_to_lvalue_1 (XEXP (body, 0));
1426 :
1427 54838727 : case SET:
1428 54838727 : return (apply_to_lvalue_1 (SET_DEST (body))
1429 54838727 : && apply_to_rvalue_1 (&SET_SRC (body)));
1430 :
1431 4441267 : default:
1432 : /* All the other possibilities never store and can use a normal
1433 : rtx walk. This includes:
1434 :
1435 : - USE
1436 : - TRAP_IF
1437 : - PREFETCH
1438 : - UNSPEC
1439 : - UNSPEC_VOLATILE. */
1440 4441267 : return apply_to_rvalue_1 (loc);
1441 : }
1442 : }
1443 :
1444 : /* Apply this insn_propagation object's simplification or substitution
1445 : to the instruction pattern at LOC. */
1446 :
1447 : bool
1448 63928070 : insn_propagation::apply_to_pattern (rtx *loc)
1449 : {
1450 63928070 : unsigned int num_changes = num_validated_changes ();
1451 63928070 : bool res = apply_to_pattern_1 (loc);
1452 63928070 : if (!res)
1453 2318994 : cancel_changes (num_changes);
1454 63928070 : return res;
1455 : }
1456 :
1457 : /* Apply this insn_propagation object's simplification or substitution
1458 : to the rvalue expression at LOC. */
1459 :
1460 : bool
1461 7613298 : insn_propagation::apply_to_rvalue (rtx *loc)
1462 : {
1463 7613298 : unsigned int num_changes = num_validated_changes ();
1464 7613298 : bool res = apply_to_rvalue_1 (loc);
1465 7613298 : if (!res)
1466 20365 : cancel_changes (num_changes);
1467 7613298 : return res;
1468 : }
1469 :
1470 : /* Like apply_to_rvalue, but specifically for the case where *LOC is in
1471 : a note. This never changes the INSN_CODE. */
1472 :
1473 : bool
1474 194121 : insn_propagation::apply_to_note (rtx *loc)
1475 : {
1476 194121 : auto old_code = INSN_CODE (insn);
1477 194121 : bool res = apply_to_rvalue (loc);
1478 194121 : if (INSN_CODE (insn) != old_code)
1479 97268 : INSN_CODE (insn) = old_code;
1480 194121 : return res;
1481 : }
1482 :
1483 : /* Check whether INSN matches a specific alternative of an .md pattern. */
1484 :
1485 : bool
1486 0 : valid_insn_p (rtx_insn *insn)
1487 : {
1488 0 : recog_memoized (insn);
1489 0 : if (INSN_CODE (insn) < 0)
1490 : return false;
1491 0 : extract_insn (insn);
1492 : /* We don't know whether the insn will be in code that is optimized
1493 : for size or speed, so consider all enabled alternatives. */
1494 0 : if (!constrain_operands (1, get_enabled_alternatives (insn)))
1495 : return false;
1496 : return true;
1497 : }
1498 :
1499 : /* Return true if OP is a valid general operand for machine mode MODE.
1500 : This is either a register reference, a memory reference,
1501 : or a constant. In the case of a memory reference, the address
1502 : is checked for general validity for the target machine.
1503 :
1504 : Register and memory references must have mode MODE in order to be valid,
1505 : but some constants have no machine mode and are valid for any mode.
1506 :
1507 : If MODE is VOIDmode, OP is checked for validity for whatever mode
1508 : it has.
1509 :
1510 : The main use of this function is as a predicate in match_operand
1511 : expressions in the machine description. */
1512 :
1513 : bool
1514 5086662706 : general_operand (rtx op, machine_mode mode)
1515 : {
1516 5086662706 : enum rtx_code code = GET_CODE (op);
1517 :
1518 5086662706 : if (mode == VOIDmode)
1519 1339888716 : mode = GET_MODE (op);
1520 :
1521 : /* Don't accept CONST_INT or anything similar
1522 : if the caller wants something floating. */
1523 5086662706 : if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1524 226999498 : && GET_MODE_CLASS (mode) != MODE_INT
1525 4618 : && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1526 : return false;
1527 :
1528 5086658088 : if (CONST_INT_P (op)
1529 279708780 : && mode != VOIDmode
1530 5310368241 : && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1531 : return false;
1532 :
1533 5086657949 : if (CONSTANT_P (op))
1534 65563693 : return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
1535 7897 : || mode == VOIDmode)
1536 345864953 : && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1537 747232193 : && targetm.legitimate_constant_p (mode == VOIDmode
1538 56077553 : ? GET_MODE (op)
1539 : : mode, op));
1540 :
1541 : /* Except for certain constants with VOIDmode, already checked for,
1542 : OP's mode must match MODE if MODE specifies a mode. */
1543 :
1544 4740785099 : if (GET_MODE (op) != mode)
1545 : return false;
1546 :
1547 4685911433 : if (code == SUBREG)
1548 : {
1549 37012619 : rtx sub = SUBREG_REG (op);
1550 :
1551 : #ifdef INSN_SCHEDULING
1552 : /* On machines that have insn scheduling, we want all memory
1553 : reference to be explicit, so outlaw paradoxical SUBREGs.
1554 : However, we must allow them after reload so that they can
1555 : get cleaned up by cleanup_subreg_operands. */
1556 36964284 : if (!reload_completed && MEM_P (sub)
1557 37077775 : && paradoxical_subreg_p (op))
1558 : return false;
1559 : #endif
1560 : /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
1561 : may result in incorrect reference. We should simplify all valid
1562 : subregs of MEM anyway. But allow this after reload because we
1563 : might be called from cleanup_subreg_operands.
1564 :
1565 : ??? This is a kludge. */
1566 36947785 : if (!reload_completed
1567 36899450 : && maybe_ne (SUBREG_BYTE (op), 0)
1568 42350621 : && MEM_P (sub))
1569 : return false;
1570 :
1571 36947785 : if (REG_P (sub)
1572 35205262 : && REGNO (sub) < FIRST_PSEUDO_REGISTER
1573 4537 : && !REG_CAN_CHANGE_MODE_P (REGNO (sub), GET_MODE (sub), mode)
1574 0 : && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
1575 0 : && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT
1576 : /* LRA can generate some invalid SUBREGS just for matched
1577 : operand reload presentation. LRA needs to treat them as
1578 : valid. */
1579 36947785 : && ! LRA_SUBREG_P (op))
1580 : return false;
1581 :
1582 : /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
1583 : create such rtl, and we must reject it. */
1584 36947785 : if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
1585 : /* LRA can use subreg to store a floating point value in an
1586 : integer mode. Although the floating point and the
1587 : integer modes need the same number of hard registers, the
1588 : size of floating point mode can be less than the integer
1589 : mode. */
1590 317980 : && ! lra_in_progress
1591 37254142 : && paradoxical_subreg_p (op))
1592 : return false;
1593 :
1594 36947785 : op = sub;
1595 36947785 : code = GET_CODE (op);
1596 : }
1597 :
1598 4685846599 : if (code == REG)
1599 3854003459 : return (REGNO (op) >= FIRST_PSEUDO_REGISTER
1600 3854003459 : || in_hard_reg_set_p (operand_reg_set, GET_MODE (op), REGNO (op)));
1601 :
1602 831843140 : if (code == MEM)
1603 : {
1604 735095622 : rtx y = XEXP (op, 0);
1605 :
1606 : /* If -ffuse-ops-with-volatile-access is enabled, allow volatile
1607 : memory reference. */
1608 735095622 : if (!flag_fuse_ops_with_volatile_access
1609 176290 : && !volatile_ok
1610 735145220 : && MEM_VOLATILE_P (op))
1611 : return false;
1612 :
1613 : /* Use the mem's mode, since it will be reloaded thus. LRA can
1614 : generate move insn with invalid addresses which is made valid
1615 : and efficiently calculated by LRA through further numerous
1616 : transformations. */
1617 735089184 : if (lra_in_progress
1618 789807112 : || memory_address_addr_space_p (GET_MODE (op), y, MEM_ADDR_SPACE (op)))
1619 : return true;
1620 : }
1621 :
1622 : return false;
1623 : }
1624 :
1625 : /* Return true if OP is a valid memory address for a memory reference
1626 : of mode MODE.
1627 :
1628 : The main use of this function is as a predicate in match_operand
1629 : expressions in the machine description. */
1630 :
1631 : bool
1632 118259410 : address_operand (rtx op, machine_mode mode)
1633 : {
1634 : /* Wrong mode for an address expr. */
1635 118259410 : if (GET_MODE (op) != VOIDmode
1636 105632636 : && ! SCALAR_INT_MODE_P (GET_MODE (op))
1637 914676 : && ! (GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_INT))
1638 : return false;
1639 :
1640 117809179 : return memory_address_p (mode, op);
1641 : }
1642 :
1643 : /* Return true if OP is a register reference of mode MODE.
1644 : If MODE is VOIDmode, accept a register in any mode.
1645 :
1646 : The main use of this function is as a predicate in match_operand
1647 : expressions in the machine description. */
1648 :
1649 : bool
1650 2780324418 : register_operand (rtx op, machine_mode mode)
1651 : {
1652 2780324418 : if (GET_CODE (op) == SUBREG)
1653 : {
1654 12692653 : rtx sub = SUBREG_REG (op);
1655 :
1656 : /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1657 : because it is guaranteed to be reloaded into one.
1658 : Just make sure the MEM is valid in itself.
1659 : (Ideally, (SUBREG (MEM)...) should not exist after reload,
1660 : but currently it does result from (SUBREG (REG)...) where the
1661 : reg went on the stack.) */
1662 12692653 : if (!REG_P (sub) && (reload_completed || !MEM_P (sub)))
1663 : return false;
1664 : }
1665 2767631765 : else if (!REG_P (op))
1666 : return false;
1667 2050678967 : return general_operand (op, mode);
1668 : }
1669 :
1670 : /* Return true for a register in Pmode; ignore the tested mode. */
1671 :
1672 : bool
1673 0 : pmode_register_operand (rtx op, machine_mode mode ATTRIBUTE_UNUSED)
1674 : {
1675 0 : return register_operand (op, Pmode);
1676 : }
1677 :
1678 : /* Return true if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1679 : or a hard register. */
1680 :
1681 : bool
1682 798657 : scratch_operand (rtx op, machine_mode mode)
1683 : {
1684 798657 : if (GET_MODE (op) != mode && mode != VOIDmode)
1685 : return false;
1686 :
1687 759917 : return (GET_CODE (op) == SCRATCH
1688 759917 : || (REG_P (op)
1689 122031 : && (lra_in_progress
1690 102454 : || (REGNO (op) < FIRST_PSEUDO_REGISTER
1691 98942 : && REGNO_REG_CLASS (REGNO (op)) != NO_REGS))));
1692 : }
1693 :
1694 : /* Return true if OP is a valid immediate operand for mode MODE.
1695 :
1696 : The main use of this function is as a predicate in match_operand
1697 : expressions in the machine description. */
1698 :
1699 : bool
1700 515031516 : immediate_operand (rtx op, machine_mode mode)
1701 : {
1702 : /* Don't accept CONST_INT or anything similar
1703 : if the caller wants something floating. */
1704 515031516 : if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1705 147234453 : && GET_MODE_CLASS (mode) != MODE_INT
1706 0 : && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1707 : return false;
1708 :
1709 515031516 : if (CONST_INT_P (op)
1710 329527880 : && mode != VOIDmode
1711 659091149 : && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1712 : return false;
1713 :
1714 514794546 : return (CONSTANT_P (op)
1715 394751333 : && (GET_MODE (op) == mode || mode == VOIDmode
1716 148488945 : || GET_MODE (op) == VOIDmode)
1717 392154675 : && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1718 1124471488 : && targetm.legitimate_constant_p (mode == VOIDmode
1719 222289864 : ? GET_MODE (op)
1720 : : mode, op));
1721 : }
1722 :
1723 : /* Return true if OP is an operand that is a CONST_INT of mode MODE. */
1724 :
1725 : bool
1726 39800731 : const_int_operand (rtx op, machine_mode mode)
1727 : {
1728 39800731 : if (!CONST_INT_P (op))
1729 : return false;
1730 :
1731 33610378 : if (mode != VOIDmode
1732 33610378 : && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1733 780 : return false;
1734 :
1735 : return true;
1736 : }
1737 :
1738 : #if TARGET_SUPPORTS_WIDE_INT
1739 : /* Return true if OP is an operand that is a CONST_INT or CONST_WIDE_INT
1740 : of mode MODE. */
1741 : bool
1742 2472235 : const_scalar_int_operand (rtx op, machine_mode mode)
1743 : {
1744 2472235 : if (!CONST_SCALAR_INT_P (op))
1745 : return false;
1746 :
1747 2083955 : if (CONST_INT_P (op))
1748 214921 : return const_int_operand (op, mode);
1749 :
1750 1869034 : if (mode != VOIDmode)
1751 : {
1752 1869034 : scalar_int_mode int_mode = as_a <scalar_int_mode> (mode);
1753 1869034 : int prec = GET_MODE_PRECISION (int_mode);
1754 1869034 : int bitsize = GET_MODE_BITSIZE (int_mode);
1755 :
1756 1869034 : if (CONST_WIDE_INT_NUNITS (op) * HOST_BITS_PER_WIDE_INT > bitsize)
1757 : return false;
1758 :
1759 1869029 : if (prec == bitsize)
1760 : return true;
1761 : else
1762 : {
1763 : /* Multiword partial int. */
1764 5496 : HOST_WIDE_INT x
1765 5496 : = CONST_WIDE_INT_ELT (op, CONST_WIDE_INT_NUNITS (op) - 1);
1766 5496 : return (sext_hwi (x, prec & (HOST_BITS_PER_WIDE_INT - 1)) == x);
1767 : }
1768 : }
1769 : return true;
1770 : }
1771 :
1772 : /* Return true if OP is an operand that is a constant integer or constant
1773 : floating-point number of MODE. */
1774 :
1775 : bool
1776 0 : const_double_operand (rtx op, machine_mode mode)
1777 : {
1778 0 : return (GET_CODE (op) == CONST_DOUBLE)
1779 0 : && (GET_MODE (op) == mode || mode == VOIDmode);
1780 : }
1781 : #else
1782 : /* Return true if OP is an operand that is a constant integer or constant
1783 : floating-point number of MODE. */
1784 :
1785 : bool
1786 : const_double_operand (rtx op, machine_mode mode)
1787 : {
1788 : /* Don't accept CONST_INT or anything similar
1789 : if the caller wants something floating. */
1790 : if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1791 : && GET_MODE_CLASS (mode) != MODE_INT
1792 : && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1793 : return false;
1794 :
1795 : return ((CONST_DOUBLE_P (op) || CONST_INT_P (op))
1796 : && (mode == VOIDmode || GET_MODE (op) == mode
1797 : || GET_MODE (op) == VOIDmode));
1798 : }
1799 : #endif
1800 : /* Return true if OP is a general operand that is not an immediate
1801 : operand of mode MODE. */
1802 :
1803 : bool
1804 1951149858 : nonimmediate_operand (rtx op, machine_mode mode)
1805 : {
1806 1951149858 : return (general_operand (op, mode) && ! CONSTANT_P (op));
1807 : }
1808 :
1809 : /* Return true if OP is a register reference or
1810 : immediate value of mode MODE. */
1811 :
1812 : bool
1813 566630729 : nonmemory_operand (rtx op, machine_mode mode)
1814 : {
1815 566630729 : if (CONSTANT_P (op))
1816 33661963 : return immediate_operand (op, mode);
1817 532968766 : return register_operand (op, mode);
1818 : }
1819 :
1820 : /* Return true if OP is a valid operand that stands for pushing a
1821 : value of mode MODE onto the stack.
1822 :
1823 : The main use of this function is as a predicate in match_operand
1824 : expressions in the machine description. */
1825 :
1826 : bool
1827 870795564 : push_operand (rtx op, machine_mode mode)
1828 : {
1829 870795564 : if (!MEM_P (op))
1830 : return false;
1831 :
1832 254436129 : if (mode != VOIDmode && GET_MODE (op) != mode)
1833 : return false;
1834 :
1835 481688038 : poly_int64 rounded_size = GET_MODE_SIZE (mode);
1836 :
1837 : #ifdef PUSH_ROUNDING
1838 240844019 : rounded_size = PUSH_ROUNDING (MACRO_INT (rounded_size));
1839 : #endif
1840 :
1841 240844019 : op = XEXP (op, 0);
1842 :
1843 481688038 : if (known_eq (rounded_size, GET_MODE_SIZE (mode)))
1844 : {
1845 204239457 : if (GET_CODE (op) != STACK_PUSH_CODE)
1846 : return false;
1847 : }
1848 : else
1849 : {
1850 36604562 : poly_int64 offset;
1851 36604562 : if (GET_CODE (op) != PRE_MODIFY
1852 1226546 : || GET_CODE (XEXP (op, 1)) != PLUS
1853 1226546 : || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1854 1226546 : || !poly_int_rtx_p (XEXP (XEXP (op, 1), 1), &offset)
1855 36604562 : || (STACK_GROWS_DOWNWARD
1856 1226546 : ? maybe_ne (offset, -rounded_size)
1857 : : maybe_ne (offset, rounded_size)))
1858 870795564 : return false;
1859 : }
1860 :
1861 44031807 : return XEXP (op, 0) == stack_pointer_rtx;
1862 : }
1863 :
1864 : /* Return true if OP is a valid operand that stands for popping a
1865 : value of mode MODE off the stack.
1866 :
1867 : The main use of this function is as a predicate in match_operand
1868 : expressions in the machine description. */
1869 :
1870 : bool
1871 299784739 : pop_operand (rtx op, machine_mode mode)
1872 : {
1873 299784739 : if (!MEM_P (op))
1874 : return false;
1875 :
1876 68366961 : if (mode != VOIDmode && GET_MODE (op) != mode)
1877 : return false;
1878 :
1879 68366961 : op = XEXP (op, 0);
1880 :
1881 68366961 : if (GET_CODE (op) != STACK_POP_CODE)
1882 : return false;
1883 :
1884 1423679 : return XEXP (op, 0) == stack_pointer_rtx;
1885 : }
1886 :
1887 : /* Return true if ADDR is a valid memory address
1888 : for mode MODE in address space AS. */
1889 :
1890 : bool
1891 1467826888 : memory_address_addr_space_p (machine_mode mode ATTRIBUTE_UNUSED, rtx addr,
1892 : addr_space_t as, code_helper ch ATTRIBUTE_UNUSED)
1893 : {
1894 : #ifdef GO_IF_LEGITIMATE_ADDRESS
1895 : gcc_assert (ADDR_SPACE_GENERIC_P (as));
1896 : GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1897 : return false;
1898 :
1899 : win:
1900 : return true;
1901 : #else
1902 1467826888 : return targetm.addr_space.legitimate_address_p (mode, addr, 0, as, ch);
1903 : #endif
1904 : }
1905 :
1906 : /* Return true if OP is a valid memory reference with mode MODE,
1907 : including a valid address.
1908 :
1909 : The main use of this function is as a predicate in match_operand
1910 : expressions in the machine description. */
1911 :
1912 : bool
1913 1275386085 : memory_operand (rtx op, machine_mode mode)
1914 : {
1915 1275386085 : rtx inner;
1916 :
1917 1275386085 : if (! reload_completed)
1918 : /* Note that no SUBREG is a memory operand before end of reload pass,
1919 : because (SUBREG (MEM...)) forces reloading into a register. */
1920 133207807 : return MEM_P (op) && general_operand (op, mode);
1921 :
1922 1142178278 : if (mode != VOIDmode && GET_MODE (op) != mode)
1923 : return false;
1924 :
1925 836213886 : inner = op;
1926 836213886 : if (GET_CODE (inner) == SUBREG)
1927 8407 : inner = SUBREG_REG (inner);
1928 :
1929 836213886 : return (MEM_P (inner) && general_operand (op, mode));
1930 : }
1931 :
1932 : /* Return true if OP is a valid indirect memory reference with mode MODE;
1933 : that is, a memory reference whose address is a general_operand. */
1934 :
1935 : bool
1936 0 : indirect_operand (rtx op, machine_mode mode)
1937 : {
1938 : /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1939 0 : if (! reload_completed
1940 0 : && GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))
1941 : {
1942 0 : if (mode != VOIDmode && GET_MODE (op) != mode)
1943 : return false;
1944 :
1945 : /* The only way that we can have a general_operand as the resulting
1946 : address is if OFFSET is zero and the address already is an operand
1947 : or if the address is (plus Y (const_int -OFFSET)) and Y is an
1948 : operand. */
1949 0 : poly_int64 offset;
1950 0 : rtx addr = strip_offset (XEXP (SUBREG_REG (op), 0), &offset);
1951 0 : return (known_eq (offset + SUBREG_BYTE (op), 0)
1952 0 : && general_operand (addr, Pmode));
1953 : }
1954 :
1955 0 : return (MEM_P (op)
1956 0 : && memory_operand (op, mode)
1957 0 : && general_operand (XEXP (op, 0), Pmode));
1958 : }
1959 :
1960 : /* Return true if this is an ordered comparison operator (not including
1961 : ORDERED and UNORDERED). */
1962 :
1963 : bool
1964 29242923 : ordered_comparison_operator (rtx op, machine_mode mode)
1965 : {
1966 29242923 : if (mode != VOIDmode && GET_MODE (op) != mode)
1967 : return false;
1968 29242923 : switch (GET_CODE (op))
1969 : {
1970 : case EQ:
1971 : case NE:
1972 : case LT:
1973 : case LTU:
1974 : case LE:
1975 : case LEU:
1976 : case GT:
1977 : case GTU:
1978 : case GE:
1979 : case GEU:
1980 : return true;
1981 : default:
1982 : return false;
1983 : }
1984 : }
1985 :
1986 : /* Return true if this is a comparison operator. This allows the use of
1987 : MATCH_OPERATOR to recognize all the branch insns. */
1988 :
1989 : bool
1990 118112278 : comparison_operator (rtx op, machine_mode mode)
1991 : {
1992 5089300 : return ((mode == VOIDmode || GET_MODE (op) == mode)
1993 122758596 : && COMPARISON_P (op));
1994 : }
1995 :
1996 : /* If BODY is an insn body that uses ASM_OPERANDS, return it. */
1997 :
1998 : rtx
1999 2192394558 : extract_asm_operands (rtx body)
2000 : {
2001 2192394558 : rtx tmp;
2002 2192394558 : switch (GET_CODE (body))
2003 : {
2004 : case ASM_OPERANDS:
2005 : return body;
2006 :
2007 1696656890 : case SET:
2008 : /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
2009 1696656890 : tmp = SET_SRC (body);
2010 1696656890 : if (GET_CODE (tmp) == ASM_OPERANDS)
2011 : return tmp;
2012 : break;
2013 :
2014 359033952 : case PARALLEL:
2015 359033952 : tmp = XVECEXP (body, 0, 0);
2016 359033952 : if (GET_CODE (tmp) == ASM_OPERANDS)
2017 : return tmp;
2018 357116447 : if (GET_CODE (tmp) == SET)
2019 : {
2020 352716739 : tmp = SET_SRC (tmp);
2021 352716739 : if (GET_CODE (tmp) == ASM_OPERANDS)
2022 : return tmp;
2023 : }
2024 : break;
2025 :
2026 : default:
2027 : break;
2028 : }
2029 2186646082 : return NULL;
2030 : }
2031 :
2032 : /* If BODY is an insn body that uses ASM_OPERANDS,
2033 : return the number of operands (both input and output) in the insn.
2034 : If BODY is an insn body that uses ASM_INPUT with CLOBBERS in PARALLEL,
2035 : return 0.
2036 : Otherwise return -1. */
2037 :
2038 : int
2039 1712713441 : asm_noperands (const_rtx body)
2040 : {
2041 1712713441 : rtx asm_op = extract_asm_operands (const_cast<rtx> (body));
2042 1712713441 : int i, n_sets = 0;
2043 :
2044 1712713441 : if (asm_op == NULL)
2045 : {
2046 1708100338 : if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) >= 2
2047 264397574 : && GET_CODE (XVECEXP (body, 0, 0)) == ASM_INPUT)
2048 : {
2049 : /* body is [(asm_input ...) (clobber (reg ...))...]. */
2050 63240 : for (i = XVECLEN (body, 0) - 1; i > 0; i--)
2051 42160 : if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
2052 : return -1;
2053 : return 0;
2054 : }
2055 : return -1;
2056 : }
2057 :
2058 4613103 : if (GET_CODE (body) == SET)
2059 : n_sets = 1;
2060 4604574 : else if (GET_CODE (body) == PARALLEL)
2061 : {
2062 4594643 : if (GET_CODE (XVECEXP (body, 0, 0)) == SET)
2063 : {
2064 : /* Multiple output operands, or 1 output plus some clobbers:
2065 : body is
2066 : [(set OUTPUT (asm_operands ...))...
2067 : (use (reg ...))...
2068 : (clobber (reg ...))...]. */
2069 : /* Count backwards through USEs and CLOBBERs to determine
2070 : number of SETs. */
2071 6094587 : for (i = XVECLEN (body, 0); i > 0; i--)
2072 : {
2073 6094587 : if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
2074 : break;
2075 3082449 : if (GET_CODE (XVECEXP (body, 0, i - 1)) != USE
2076 3082449 : && GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
2077 : return -1;
2078 : }
2079 :
2080 : /* N_SETS is now number of output operands. */
2081 11633084 : n_sets = i;
2082 :
2083 : /* Verify that all the SETs we have
2084 : came from a single original asm_operands insn
2085 : (so that invalid combinations are blocked). */
2086 11633084 : for (i = 0; i < n_sets; i++)
2087 : {
2088 8661648 : rtx elt = XVECEXP (body, 0, i);
2089 8661648 : if (GET_CODE (elt) != SET)
2090 : return -1;
2091 8656094 : if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
2092 : return -1;
2093 : /* If these ASM_OPERANDS rtx's came from different original insns
2094 : then they aren't allowed together. */
2095 8639147 : if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
2096 8639147 : != ASM_OPERANDS_INPUT_VEC (asm_op))
2097 : return -1;
2098 : }
2099 : }
2100 : else
2101 : {
2102 : /* 0 outputs, but some clobbers:
2103 : body is [(asm_operands ...)
2104 : (use (reg ...))...
2105 : (clobber (reg ...))...]. */
2106 : /* Make sure all the other parallel things really are clobbers. */
2107 5218430 : for (i = XVECLEN (body, 0) - 1; i > 0; i--)
2108 3638317 : if (GET_CODE (XVECEXP (body, 0, i)) != USE
2109 3638317 : && GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
2110 : return -1;
2111 : }
2112 : }
2113 :
2114 4570009 : return (ASM_OPERANDS_INPUT_LENGTH (asm_op)
2115 4570009 : + ASM_OPERANDS_LABEL_LENGTH (asm_op) + n_sets);
2116 : }
2117 :
2118 : /* Assuming BODY is an insn body that uses ASM_OPERANDS,
2119 : copy its operands (both input and output) into the vector OPERANDS,
2120 : the locations of the operands within the insn into the vector OPERAND_LOCS,
2121 : and the constraints for the operands into CONSTRAINTS.
2122 : Write the modes of the operands into MODES.
2123 : Write the location info into LOC.
2124 : Return the assembler-template.
2125 : If BODY is an insn body that uses ASM_INPUT with CLOBBERS in PARALLEL,
2126 : return the basic assembly string.
2127 :
2128 : If LOC, MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
2129 : we don't store that info. */
2130 :
2131 : const char *
2132 2084236 : decode_asm_operands (rtx body, rtx *operands, rtx **operand_locs,
2133 : const char **constraints, machine_mode *modes,
2134 : location_t *loc)
2135 : {
2136 2084236 : int nbase = 0, n, i;
2137 2084236 : rtx asmop;
2138 :
2139 2084236 : switch (GET_CODE (body))
2140 : {
2141 : case ASM_OPERANDS:
2142 : /* Zero output asm: BODY is (asm_operands ...). */
2143 : asmop = body;
2144 : break;
2145 :
2146 4125 : case SET:
2147 : /* Single output asm: BODY is (set OUTPUT (asm_operands ...)). */
2148 4125 : asmop = SET_SRC (body);
2149 :
2150 : /* The output is in the SET.
2151 : Its constraint is in the ASM_OPERANDS itself. */
2152 4125 : if (operands)
2153 4015 : operands[0] = SET_DEST (body);
2154 4125 : if (operand_locs)
2155 455 : operand_locs[0] = &SET_DEST (body);
2156 4125 : if (constraints)
2157 4015 : constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
2158 4125 : if (modes)
2159 455 : modes[0] = GET_MODE (SET_DEST (body));
2160 : nbase = 1;
2161 : break;
2162 :
2163 2075912 : case PARALLEL:
2164 2075912 : {
2165 2075912 : int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
2166 :
2167 2075912 : asmop = XVECEXP (body, 0, 0);
2168 2075912 : if (GET_CODE (asmop) == SET)
2169 : {
2170 1231194 : asmop = SET_SRC (asmop);
2171 :
2172 : /* At least one output, plus some CLOBBERs. The outputs are in
2173 : the SETs. Their constraints are in the ASM_OPERANDS itself. */
2174 4575443 : for (i = 0; i < nparallel; i++)
2175 : {
2176 4554005 : if (GET_CODE (XVECEXP (body, 0, i)) == USE
2177 4554005 : || GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
2178 : break; /* Past last SET */
2179 3344249 : gcc_assert (GET_CODE (XVECEXP (body, 0, i)) == SET);
2180 3344249 : if (operands)
2181 3167882 : operands[i] = SET_DEST (XVECEXP (body, 0, i));
2182 3344249 : if (operand_locs)
2183 1210683 : operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
2184 3344249 : if (constraints)
2185 3181456 : constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
2186 3344249 : if (modes)
2187 1210683 : modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
2188 : }
2189 : nbase = i;
2190 : }
2191 844718 : else if (GET_CODE (asmop) == ASM_INPUT)
2192 : {
2193 10781 : if (loc)
2194 0 : *loc = ASM_INPUT_SOURCE_LOCATION (asmop);
2195 10781 : return XSTR (asmop, 0);
2196 : }
2197 : break;
2198 : }
2199 :
2200 0 : default:
2201 0 : gcc_unreachable ();
2202 : }
2203 :
2204 2073455 : n = ASM_OPERANDS_INPUT_LENGTH (asmop);
2205 4177171 : for (i = 0; i < n; i++)
2206 : {
2207 2103716 : if (operand_locs)
2208 893877 : operand_locs[nbase + i] = &ASM_OPERANDS_INPUT (asmop, i);
2209 2103716 : if (operands)
2210 1964127 : operands[nbase + i] = ASM_OPERANDS_INPUT (asmop, i);
2211 2103716 : if (constraints)
2212 1981180 : constraints[nbase + i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
2213 2103716 : if (modes)
2214 893877 : modes[nbase + i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
2215 : }
2216 2073455 : nbase += n;
2217 :
2218 2073455 : n = ASM_OPERANDS_LABEL_LENGTH (asmop);
2219 2095335 : for (i = 0; i < n; i++)
2220 : {
2221 21880 : if (operand_locs)
2222 12483 : operand_locs[nbase + i] = &ASM_OPERANDS_LABEL (asmop, i);
2223 21880 : if (operands)
2224 19821 : operands[nbase + i] = ASM_OPERANDS_LABEL (asmop, i);
2225 21880 : if (constraints)
2226 19888 : constraints[nbase + i] = "";
2227 21880 : if (modes)
2228 12483 : modes[nbase + i] = Pmode;
2229 : }
2230 :
2231 2073455 : if (loc)
2232 93509 : *loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
2233 :
2234 2073455 : return ASM_OPERANDS_TEMPLATE (asmop);
2235 : }
2236 :
2237 : /* Parse an operand reference that starts with %[...].
2238 :
2239 : The forms are %[N] and %[MODIFIER:N[,N...]]. */
2240 :
2241 : bool
2242 248 : parse_bracketed_operand (const char **p, bracketed_operand &operand)
2243 : {
2244 248 : const char *start = *p;
2245 248 : gcc_assert (*start == '[');
2246 248 : operand.opnums.truncate (0);
2247 :
2248 248 : const char *end = strchr (start + 1, ']');
2249 248 : if (!end)
2250 : return false;
2251 :
2252 244 : const char *contents = start + 1;
2253 244 : const char *colon = (const char *) memchr (contents, ':', end - contents);
2254 :
2255 244 : if (colon)
2256 : {
2257 52 : if (colon == contents)
2258 : return false;
2259 204 : for (const char *q = contents; q != colon; ++q)
2260 168 : if (*q == ',' && (q == contents || q[-1] == ',' || q + 1 == colon))
2261 : return false;
2262 : }
2263 :
2264 228 : const char *number = colon ? colon + 1 : contents;
2265 248 : char *next;
2266 248 : do
2267 : {
2268 248 : if (!ISDIGIT (*number))
2269 32 : return false;
2270 224 : unsigned long opnum = strtoul (number, &next, 10);
2271 224 : if (next != end && (!colon || *next != ','))
2272 : return false;
2273 216 : operand.opnums.safe_push (opnum);
2274 216 : number = next + 1;
2275 : }
2276 216 : while (next != end);
2277 :
2278 196 : operand.modifier = string_slice (contents, colon ? colon : contents);
2279 196 : *p = end + 1;
2280 196 : return true;
2281 : }
2282 :
2283 : /* Parse inline assembly string STRING and determine which operands are
2284 : referenced by % markers. For the first NOPERANDS operands, set USED[I]
2285 : to true if operand I is referenced.
2286 :
2287 : This is intended to distinguish barrier-like asms such as:
2288 :
2289 : asm ("" : "=m" (...));
2290 :
2291 : from real references such as:
2292 :
2293 : asm ("sw\t$0, %0" : "=m" (...)); */
2294 :
2295 : void
2296 28 : get_referenced_operands (const char *string, bool *used,
2297 : unsigned int noperands)
2298 : {
2299 28 : memset (used, 0, sizeof (bool) * noperands);
2300 28 : const char *p = string;
2301 184 : while (*p)
2302 156 : switch (*p)
2303 : {
2304 52 : case '%':
2305 52 : p += 1;
2306 52 : if (*p == '[')
2307 : {
2308 24 : bracketed_operand operand;
2309 24 : if (parse_bracketed_operand (&p, operand))
2310 : {
2311 88 : for (unsigned long opnum : operand.opnums)
2312 28 : if (opnum < noperands)
2313 24 : used[opnum] = true;
2314 20 : break;
2315 : }
2316 24 : }
2317 : /* A letter followed by a digit indicates an operand number. */
2318 32 : if (p[0] == 'c' && p[1] == 'c')
2319 4 : p += 1;
2320 32 : if (ISALPHA (p[0]) && ISDIGIT (p[1]))
2321 8 : p += 1;
2322 32 : if (ISDIGIT (*p))
2323 : {
2324 16 : char *endptr;
2325 16 : unsigned long opnum = strtoul (p, &endptr, 10);
2326 16 : if (endptr != p && opnum < noperands)
2327 16 : used[opnum] = true;
2328 16 : p = endptr;
2329 : }
2330 16 : else if (*p)
2331 12 : p += 1;
2332 : break;
2333 :
2334 104 : default:
2335 104 : p++;
2336 104 : break;
2337 : }
2338 28 : }
2339 :
2340 : /* Check if an asm_operand matches its constraints.
2341 : Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
2342 :
2343 : int
2344 3667549 : asm_operand_ok (rtx op, const char *constraint, const char **constraints)
2345 : {
2346 3667549 : int result = 0;
2347 3667549 : bool incdec_ok = false;
2348 :
2349 : /* Use constrain_operands after reload. */
2350 3667549 : gcc_assert (!reload_completed);
2351 :
2352 : /* Empty constraint string is the same as "X,...,X", i.e. X for as
2353 : many alternatives as required to match the other operands. */
2354 3667549 : if (*constraint == '\0')
2355 3928 : result = 1;
2356 :
2357 10113657 : while (*constraint)
2358 : {
2359 6446110 : enum constraint_num cn;
2360 6446110 : char c = *constraint;
2361 6446110 : int len;
2362 6446110 : switch (c)
2363 : {
2364 11502 : case ',':
2365 11502 : raw_constraint_p = false;
2366 11502 : constraint++;
2367 11502 : continue;
2368 :
2369 689512 : case '0': case '1': case '2': case '3': case '4':
2370 689512 : case '5': case '6': case '7': case '8': case '9':
2371 : /* If caller provided constraints pointer, look up
2372 : the matching constraint. Otherwise, our caller should have
2373 : given us the proper matching constraint, but we can't
2374 : actually fail the check if they didn't. Indicate that
2375 : results are inconclusive. */
2376 689512 : if (constraints)
2377 : {
2378 689309 : char *end;
2379 689309 : unsigned long match;
2380 :
2381 689309 : match = strtoul (constraint, &end, 10);
2382 689309 : if (!result)
2383 689047 : result = asm_operand_ok (op, constraints[match], NULL);
2384 689309 : constraint = (const char *) end;
2385 : }
2386 : else
2387 : {
2388 227 : do
2389 227 : constraint++;
2390 227 : while (ISDIGIT (*constraint));
2391 203 : if (! result)
2392 175 : result = -1;
2393 : }
2394 689512 : continue;
2395 :
2396 : /* The rest of the compiler assumes that reloading the address
2397 : of a MEM into a register will make it fit an 'o' constraint.
2398 : That is, if it sees a MEM operand for an 'o' constraint,
2399 : it assumes that (mem (base-reg)) will fit.
2400 :
2401 : That assumption fails on targets that don't have offsettable
2402 : addresses at all. We therefore need to treat 'o' asm
2403 : constraints as a special case and only accept operands that
2404 : are already offsettable, thus proving that at least one
2405 : offsettable address exists. */
2406 36 : case 'o': /* offsettable */
2407 36 : if (offsettable_nonstrict_memref_p (op))
2408 2471154 : result = 1;
2409 : break;
2410 :
2411 141831 : case 'g':
2412 141831 : if (general_operand (op, VOIDmode))
2413 2471154 : result = 1;
2414 : break;
2415 :
2416 32 : case '-':
2417 32 : raw_constraint_p = true;
2418 32 : constraint++;
2419 32 : continue;
2420 :
2421 : case '<':
2422 : case '>':
2423 : /* ??? Before auto-inc-dec, auto inc/dec insns are not supposed
2424 : to exist, excepting those that expand_call created. Further,
2425 : on some machines which do not have generalized auto inc/dec,
2426 : an inc/dec is not a memory_operand.
2427 :
2428 : Match any memory and hope things are resolved after reload. */
2429 5603197 : incdec_ok = true;
2430 : /* FALLTHRU */
2431 5603197 : default:
2432 5603197 : cn = lookup_constraint (constraint);
2433 5603197 : rtx mem = NULL;
2434 5603197 : switch (get_constraint_type (cn))
2435 : {
2436 5398984 : case CT_REGISTER:
2437 5398984 : if (!result
2438 2657720 : && (reg_class_for_constraint (cn) != NO_REGS
2439 2739292 : || constraint[0] == '{')
2440 2658382 : && GET_MODE (op) != BLKmode
2441 8057331 : && register_operand (op, VOIDmode))
2442 : result = 1;
2443 : break;
2444 :
2445 4 : case CT_CONST_INT:
2446 4 : if (!result
2447 4 : && CONST_INT_P (op)
2448 6 : && insn_const_int_ok_for_constraint (INTVAL (op), cn))
2449 : result = 1;
2450 : break;
2451 :
2452 180671 : case CT_MEMORY:
2453 180671 : case CT_RELAXED_MEMORY:
2454 180671 : mem = op;
2455 : /* Fall through. */
2456 180671 : case CT_SPECIAL_MEMORY:
2457 : /* Every memory operand can be reloaded to fit. */
2458 180671 : if (!mem)
2459 0 : mem = extract_mem_from_operand (op);
2460 180671 : result = result || memory_operand (mem, VOIDmode);
2461 180671 : break;
2462 :
2463 143 : case CT_ADDRESS:
2464 : /* Every address operand can be reloaded to fit. */
2465 143 : result = result || address_operand (op, VOIDmode);
2466 143 : break;
2467 :
2468 23395 : case CT_FIXED_FORM:
2469 23395 : result = result || constraint_satisfied_p (op, cn);
2470 23395 : break;
2471 : }
2472 : break;
2473 701046 : }
2474 5745064 : len = CONSTRAINT_LEN (c, constraint);
2475 5749157 : do
2476 5749157 : constraint++;
2477 11494221 : while (--len && *constraint && *constraint != ',');
2478 5745064 : if (len)
2479 : {
2480 2 : raw_constraint_p = false;
2481 2 : return 0;
2482 : }
2483 : }
2484 3667547 : raw_constraint_p = false;
2485 :
2486 : /* For operands without < or > constraints reject side-effects. */
2487 3667547 : if (AUTO_INC_DEC && !incdec_ok && result && MEM_P (op))
2488 : switch (GET_CODE (XEXP (op, 0)))
2489 : {
2490 : case PRE_INC:
2491 : case POST_INC:
2492 : case PRE_DEC:
2493 : case POST_DEC:
2494 : case PRE_MODIFY:
2495 : case POST_MODIFY:
2496 : return 0;
2497 : default:
2498 : break;
2499 : }
2500 :
2501 3667547 : return result;
2502 : }
2503 :
2504 : /* Given an rtx *P, if it is a sum containing an integer constant term,
2505 : return the location (type rtx *) of the pointer to that constant term.
2506 : Otherwise, return a null pointer. */
2507 :
2508 : rtx *
2509 27007767 : find_constant_term_loc (rtx *p)
2510 : {
2511 40547474 : rtx *tem;
2512 40547474 : enum rtx_code code = GET_CODE (*p);
2513 :
2514 : /* If *P IS such a constant term, P is its location. */
2515 :
2516 40547474 : if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
2517 : || code == CONST)
2518 : return p;
2519 :
2520 : /* Otherwise, if not a sum, it has no constant term. */
2521 :
2522 : if (GET_CODE (*p) != PLUS)
2523 15277274 : return 0;
2524 :
2525 : /* If one of the summands is constant, return its location. */
2526 :
2527 13539707 : if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
2528 0 : && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
2529 : return p;
2530 :
2531 : /* Otherwise, check each summand for containing a constant term. */
2532 :
2533 13539707 : if (XEXP (*p, 0) != 0)
2534 : {
2535 13539707 : tem = find_constant_term_loc (&XEXP (*p, 0));
2536 13539707 : if (tem != 0)
2537 : return tem;
2538 : }
2539 :
2540 13539707 : if (XEXP (*p, 1) != 0)
2541 : {
2542 13539707 : tem = find_constant_term_loc (&XEXP (*p, 1));
2543 : if (tem != 0)
2544 : return tem;
2545 : }
2546 :
2547 : return 0;
2548 : }
2549 :
2550 : /* Return true if OP is a memory reference whose address contains
2551 : no side effects and remains valid after the addition of a positive
2552 : integer less than the size of the object being referenced.
2553 :
2554 : We assume that the original address is valid and do not check it.
2555 :
2556 : This uses strict_memory_address_p as a subroutine, so
2557 : don't use it before reload. */
2558 :
2559 : bool
2560 5670136 : offsettable_memref_p (rtx op)
2561 : {
2562 5670136 : return ((MEM_P (op))
2563 11335094 : && offsettable_address_addr_space_p (1, GET_MODE (op), XEXP (op, 0),
2564 5664958 : MEM_ADDR_SPACE (op)));
2565 : }
2566 :
2567 : /* Similar, but don't require a strictly valid mem ref:
2568 : consider pseudo-regs valid as index or base regs. */
2569 :
2570 : bool
2571 11806539 : offsettable_nonstrict_memref_p (rtx op)
2572 : {
2573 11806539 : return ((MEM_P (op))
2574 23613044 : && offsettable_address_addr_space_p (0, GET_MODE (op), XEXP (op, 0),
2575 11806505 : MEM_ADDR_SPACE (op)));
2576 : }
2577 :
2578 : /* Return true if Y is a memory address which contains no side effects
2579 : and would remain valid for address space AS after the addition of
2580 : a positive integer less than the size of that mode.
2581 :
2582 : We assume that the original address is valid and do not check it.
2583 : We do check that it is valid for narrower modes.
2584 :
2585 : If STRICTP is nonzero, we require a strictly valid address,
2586 : for the sake of use in reload.cc. */
2587 :
2588 : bool
2589 17471463 : offsettable_address_addr_space_p (int strictp, machine_mode mode, rtx y,
2590 : addr_space_t as)
2591 : {
2592 17471463 : enum rtx_code ycode = GET_CODE (y);
2593 17471463 : rtx z;
2594 17471463 : rtx y1 = y;
2595 17471463 : rtx *y2;
2596 11806505 : bool (*addressp) (machine_mode, rtx, addr_space_t, code_helper) =
2597 17471463 : (strictp ? strict_memory_address_addr_space_p
2598 : : memory_address_addr_space_p);
2599 34942926 : poly_int64 mode_sz = GET_MODE_SIZE (mode);
2600 :
2601 17471463 : if (CONSTANT_ADDRESS_P (y))
2602 : return true;
2603 :
2604 : /* Adjusting an offsettable address involves changing to a narrower mode.
2605 : Make sure that's OK. */
2606 :
2607 14789664 : if (mode_dependent_address_p (y, as))
2608 : return false;
2609 :
2610 14605100 : machine_mode address_mode = GET_MODE (y);
2611 14605100 : if (address_mode == VOIDmode)
2612 0 : address_mode = targetm.addr_space.address_mode (as);
2613 : #ifdef POINTERS_EXTEND_UNSIGNED
2614 14605100 : machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
2615 : #endif
2616 :
2617 : /* ??? How much offset does an offsettable BLKmode reference need?
2618 : Clearly that depends on the situation in which it's being used.
2619 : However, the current situation in which we test 0xffffffff is
2620 : less than ideal. Caveat user. */
2621 14605100 : if (known_eq (mode_sz, 0))
2622 0 : mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2623 :
2624 : /* If the expression contains a constant term,
2625 : see if it remains valid when max possible offset is added. */
2626 :
2627 14605100 : if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
2628 : {
2629 11730493 : bool good;
2630 :
2631 11730493 : y1 = *y2;
2632 11730493 : *y2 = plus_constant (address_mode, *y2, mode_sz - 1);
2633 : /* Use QImode because an odd displacement may be automatically invalid
2634 : for any wider mode. But it should be valid for a single byte. */
2635 11730493 : good = (*addressp) (QImode, y, as, ERROR_MARK);
2636 :
2637 : /* In any case, restore old contents of memory. */
2638 11730493 : *y2 = y1;
2639 11730493 : return good;
2640 : }
2641 :
2642 2874607 : if (GET_RTX_CLASS (ycode) == RTX_AUTOINC)
2643 : return false;
2644 :
2645 : /* The offset added here is chosen as the maximum offset that
2646 : any instruction could need to add when operating on something
2647 : of the specified mode. We assume that if Y and Y+c are
2648 : valid addresses then so is Y+d for all 0<d<c. adjust_address will
2649 : go inside a LO_SUM here, so we do so as well. */
2650 2874607 : if (GET_CODE (y) == LO_SUM
2651 0 : && mode != BLKmode
2652 2874607 : && known_le (mode_sz, GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT))
2653 0 : z = gen_rtx_LO_SUM (address_mode, XEXP (y, 0),
2654 : plus_constant (address_mode, XEXP (y, 1),
2655 : mode_sz - 1));
2656 : #ifdef POINTERS_EXTEND_UNSIGNED
2657 : /* Likewise for a ZERO_EXTEND from pointer_mode. */
2658 2874607 : else if (POINTERS_EXTEND_UNSIGNED > 0
2659 2874607 : && GET_CODE (y) == ZERO_EXTEND
2660 13 : && GET_MODE (XEXP (y, 0)) == pointer_mode)
2661 7 : z = gen_rtx_ZERO_EXTEND (address_mode,
2662 : plus_constant (pointer_mode, XEXP (y, 0),
2663 : mode_sz - 1));
2664 : #endif
2665 : else
2666 2874600 : z = plus_constant (address_mode, y, mode_sz - 1);
2667 :
2668 : /* Use QImode because an odd displacement may be automatically invalid
2669 : for any wider mode. But it should be valid for a single byte. */
2670 2874607 : return (*addressp) (QImode, z, as, ERROR_MARK);
2671 : }
2672 :
2673 : /* Return true if ADDR is an address-expression whose effect depends
2674 : on the mode of the memory reference it is used in.
2675 :
2676 : ADDRSPACE is the address space associated with the address.
2677 :
2678 : Autoincrement addressing is a typical example of mode-dependence
2679 : because the amount of the increment depends on the mode. */
2680 :
2681 : bool
2682 40712924 : mode_dependent_address_p (rtx addr, addr_space_t addrspace)
2683 : {
2684 : /* Auto-increment addressing with anything other than post_modify
2685 : or pre_modify always introduces a mode dependency. Catch such
2686 : cases now instead of deferring to the target. */
2687 40712924 : if (GET_CODE (addr) == PRE_INC
2688 40712924 : || GET_CODE (addr) == POST_INC
2689 40712918 : || GET_CODE (addr) == PRE_DEC
2690 36917225 : || GET_CODE (addr) == POST_DEC)
2691 : return true;
2692 :
2693 36917225 : return targetm.mode_dependent_address_p (addr, addrspace);
2694 : }
2695 :
2696 : /* Return true if boolean attribute ATTR is supported. */
2697 :
2698 : static bool
2699 1685999672 : have_bool_attr (bool_attr attr)
2700 : {
2701 1685999672 : switch (attr)
2702 : {
2703 : case BA_ENABLED:
2704 : return HAVE_ATTR_enabled;
2705 : case BA_PREFERRED_FOR_SIZE:
2706 : return HAVE_ATTR_enabled || HAVE_ATTR_preferred_for_size;
2707 : case BA_PREFERRED_FOR_SPEED:
2708 : return HAVE_ATTR_enabled || HAVE_ATTR_preferred_for_speed;
2709 : }
2710 0 : gcc_unreachable ();
2711 : }
2712 :
2713 : /* Return the value of ATTR for instruction INSN. */
2714 :
2715 : static bool
2716 1778413717 : get_bool_attr (rtx_insn *insn, bool_attr attr)
2717 : {
2718 1778413717 : switch (attr)
2719 : {
2720 754847816 : case BA_ENABLED:
2721 754847816 : return get_attr_enabled (insn);
2722 366752877 : case BA_PREFERRED_FOR_SIZE:
2723 366752877 : return get_attr_enabled (insn) && get_attr_preferred_for_size (insn);
2724 656813024 : case BA_PREFERRED_FOR_SPEED:
2725 656813024 : return get_attr_enabled (insn) && get_attr_preferred_for_speed (insn);
2726 : }
2727 0 : gcc_unreachable ();
2728 : }
2729 :
2730 : /* Like get_bool_attr_mask, but don't use the cache. */
2731 :
2732 : static alternative_mask
2733 106128067 : get_bool_attr_mask_uncached (rtx_insn *insn, bool_attr attr)
2734 : {
2735 : /* Temporarily install enough information for get_attr_<foo> to assume
2736 : that the insn operands are already cached. As above, the attribute
2737 : mustn't depend on the values of operands, so we don't provide their
2738 : real values here. */
2739 106128067 : rtx_insn *old_insn = recog_data.insn;
2740 106128067 : int old_alternative = which_alternative;
2741 :
2742 106128067 : recog_data.insn = insn;
2743 106128067 : alternative_mask mask = ALL_ALTERNATIVES;
2744 106128067 : int n_alternatives = insn_data[INSN_CODE (insn)].n_alternatives;
2745 1884541784 : for (int i = 0; i < n_alternatives; i++)
2746 : {
2747 1778413717 : which_alternative = i;
2748 1778413717 : if (!get_bool_attr (insn, attr))
2749 539459682 : mask &= ~ALTERNATIVE_BIT (i);
2750 : }
2751 :
2752 106128067 : recog_data.insn = old_insn;
2753 106128067 : which_alternative = old_alternative;
2754 106128067 : return mask;
2755 : }
2756 :
2757 : /* Return the mask of operand alternatives that are allowed for INSN
2758 : by boolean attribute ATTR. This mask depends only on INSN and on
2759 : the current target; it does not depend on things like the values of
2760 : operands. */
2761 :
2762 : static alternative_mask
2763 1688274586 : get_bool_attr_mask (rtx_insn *insn, bool_attr attr)
2764 : {
2765 : /* Quick exit for asms and for targets that don't use these attributes. */
2766 1688274586 : int code = INSN_CODE (insn);
2767 1688274586 : if (code < 0 || !have_bool_attr (attr))
2768 : return ALL_ALTERNATIVES;
2769 :
2770 : /* Calling get_attr_<foo> can be expensive, so cache the mask
2771 : for speed. */
2772 1685999672 : if (!this_target_recog->x_bool_attr_masks[code][attr])
2773 13503189 : this_target_recog->x_bool_attr_masks[code][attr]
2774 13503189 : = get_bool_attr_mask_uncached (insn, attr);
2775 1685999672 : return this_target_recog->x_bool_attr_masks[code][attr];
2776 : }
2777 :
2778 : /* Return the set of alternatives of INSN that are allowed by the current
2779 : target. */
2780 :
2781 : alternative_mask
2782 1221020764 : get_enabled_alternatives (rtx_insn *insn)
2783 : {
2784 1221020764 : return get_bool_attr_mask (insn, BA_ENABLED);
2785 : }
2786 :
2787 : /* Return the set of alternatives of INSN that are allowed by the current
2788 : target and are preferred for the current size/speed optimization
2789 : choice. */
2790 :
2791 : alternative_mask
2792 467174127 : get_preferred_alternatives (rtx_insn *insn)
2793 : {
2794 467174127 : if (optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn)))
2795 409551701 : return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SPEED);
2796 : else
2797 57622426 : return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SIZE);
2798 : }
2799 :
2800 : /* Return the set of alternatives of INSN that are allowed by the current
2801 : target and are preferred for the size/speed optimization choice
2802 : associated with BB. Passing a separate BB is useful if INSN has not
2803 : been emitted yet or if we are considering moving it to a different
2804 : block. */
2805 :
2806 : alternative_mask
2807 79695 : get_preferred_alternatives (rtx_insn *insn, basic_block bb)
2808 : {
2809 79695 : if (optimize_bb_for_speed_p (bb))
2810 74401 : return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SPEED);
2811 : else
2812 5294 : return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SIZE);
2813 : }
2814 :
2815 : /* Assert that the cached boolean attributes for INSN are still accurate.
2816 : The backend is required to define these attributes in a way that only
2817 : depends on the current target (rather than operands, compiler phase,
2818 : etc.). */
2819 :
2820 : bool
2821 37455204 : check_bool_attrs (rtx_insn *insn)
2822 : {
2823 37455204 : int code = INSN_CODE (insn);
2824 37455204 : if (code >= 0)
2825 149820816 : for (int i = 0; i <= BA_LAST; ++i)
2826 : {
2827 112365612 : enum bool_attr attr = (enum bool_attr) i;
2828 112365612 : if (this_target_recog->x_bool_attr_masks[code][attr])
2829 92624878 : gcc_assert (this_target_recog->x_bool_attr_masks[code][attr]
2830 : == get_bool_attr_mask_uncached (insn, attr));
2831 : }
2832 37455204 : return true;
2833 : }
2834 :
2835 : /* Like extract_insn, but save insn extracted and don't extract again, when
2836 : called again for the same insn expecting that recog_data still contain the
2837 : valid information. This is used primary by gen_attr infrastructure that
2838 : often does extract insn again and again. */
2839 : void
2840 10919581071 : extract_insn_cached (rtx_insn *insn)
2841 : {
2842 10919581071 : if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
2843 : return;
2844 855552551 : extract_insn (insn);
2845 855552551 : recog_data.insn = insn;
2846 : }
2847 :
2848 : /* Do uncached extract_insn, constrain_operands and complain about failures.
2849 : This should be used when extracting a pre-existing constrained instruction
2850 : if the caller wants to know which alternative was chosen. */
2851 : void
2852 273413163 : extract_constrain_insn (rtx_insn *insn)
2853 : {
2854 273413163 : extract_insn (insn);
2855 273413163 : if (!constrain_operands (reload_completed, get_enabled_alternatives (insn)))
2856 0 : fatal_insn_not_found (insn);
2857 273413163 : }
2858 :
2859 : /* Do cached extract_insn, constrain_operands and complain about failures.
2860 : Used by insn_attrtab. */
2861 : void
2862 9607426412 : extract_constrain_insn_cached (rtx_insn *insn)
2863 : {
2864 9607426412 : extract_insn_cached (insn);
2865 9607426412 : if (which_alternative == -1
2866 9607426412 : && !constrain_operands (reload_completed,
2867 : get_enabled_alternatives (insn)))
2868 0 : fatal_insn_not_found (insn);
2869 9607426412 : }
2870 :
2871 : /* Do cached constrain_operands on INSN and complain about failures. */
2872 : bool
2873 350259872 : constrain_operands_cached (rtx_insn *insn, int strict)
2874 : {
2875 350259872 : if (which_alternative == -1)
2876 95530174 : return constrain_operands (strict, get_enabled_alternatives (insn));
2877 : else
2878 : return true;
2879 : }
2880 :
2881 : /* Analyze INSN and fill in recog_data. */
2882 :
2883 : void
2884 2597731249 : extract_insn (rtx_insn *insn)
2885 : {
2886 2597731249 : int i;
2887 2597731249 : int icode;
2888 2597731249 : int noperands;
2889 2597731249 : rtx body = PATTERN (insn);
2890 :
2891 2597731249 : recog_data.n_operands = 0;
2892 2597731249 : recog_data.n_alternatives = 0;
2893 2597731249 : recog_data.n_dups = 0;
2894 2597731249 : recog_data.is_asm = false;
2895 :
2896 2597731249 : switch (GET_CODE (body))
2897 : {
2898 : case USE:
2899 : case CLOBBER:
2900 : case ASM_INPUT:
2901 : case ADDR_VEC:
2902 : case ADDR_DIFF_VEC:
2903 : case VAR_LOCATION:
2904 : case DEBUG_MARKER:
2905 : return;
2906 :
2907 1928940251 : case SET:
2908 1928940251 : if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
2909 400 : goto asm_insn;
2910 : else
2911 1928939851 : goto normal_insn;
2912 257477451 : case PARALLEL:
2913 257477451 : if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
2914 252972340 : && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
2915 256989110 : || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS
2916 256387203 : || GET_CODE (XVECEXP (body, 0, 0)) == ASM_INPUT)
2917 1099206 : goto asm_insn;
2918 : else
2919 256378245 : goto normal_insn;
2920 1099746 : case ASM_OPERANDS:
2921 1099746 : asm_insn:
2922 1099746 : recog_data.n_operands = noperands = asm_noperands (body);
2923 1099746 : if (noperands >= 0)
2924 : {
2925 : /* This insn is an `asm' with operands. */
2926 :
2927 : /* expand_asm_operands makes sure there aren't too many operands. */
2928 1099746 : gcc_assert (noperands <= MAX_RECOG_OPERANDS);
2929 :
2930 : /* Now get the operand values and constraints out of the insn. */
2931 1099746 : decode_asm_operands (body, recog_data.operand,
2932 1099746 : recog_data.operand_loc,
2933 1099746 : recog_data.constraints,
2934 1099746 : recog_data.operand_mode, NULL);
2935 1099746 : memset (recog_data.is_operator, 0, sizeof recog_data.is_operator);
2936 1099746 : if (noperands > 0)
2937 : {
2938 596029 : const char *p = recog_data.constraints[0];
2939 596029 : recog_data.n_alternatives = 1;
2940 1683378 : while (*p)
2941 1087349 : recog_data.n_alternatives += (*p++ == ',');
2942 : }
2943 1099746 : recog_data.is_asm = true;
2944 1099746 : break;
2945 : }
2946 0 : fatal_insn_not_found (insn);
2947 :
2948 2249835306 : default:
2949 2249835306 : normal_insn:
2950 : /* Ordinary insn: recognize it, get the operands via insn_extract
2951 : and get the constraints. */
2952 :
2953 2249835306 : icode = recog_memoized (insn);
2954 2249835306 : if (icode < 0)
2955 0 : fatal_insn_not_found (insn);
2956 :
2957 2249835306 : recog_data.n_operands = noperands = insn_data[icode].n_operands;
2958 2249835306 : recog_data.n_alternatives = insn_data[icode].n_alternatives;
2959 2249835306 : recog_data.n_dups = insn_data[icode].n_dups;
2960 :
2961 2249835306 : insn_extract (insn);
2962 :
2963 9317391173 : for (i = 0; i < noperands; i++)
2964 : {
2965 4817720561 : recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2966 4817720561 : recog_data.is_operator[i] = insn_data[icode].operand[i].is_operator;
2967 4817720561 : recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2968 : /* VOIDmode match_operands gets mode from their real operand. */
2969 4817720561 : if (recog_data.operand_mode[i] == VOIDmode)
2970 477633558 : recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2971 : }
2972 : }
2973 7070602852 : for (i = 0; i < noperands; i++)
2974 4819667800 : recog_data.operand_type[i]
2975 7821586561 : = (recog_data.constraints[i][0] == '=' ? OP_OUT
2976 3001918761 : : recog_data.constraints[i][0] == '+' ? OP_INOUT
2977 : : OP_IN);
2978 :
2979 2250935052 : gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2980 :
2981 2250935052 : recog_data.insn = NULL;
2982 2250935052 : which_alternative = -1;
2983 : }
2984 :
2985 : /* Fill in OP_ALT_BASE for an instruction that has N_OPERANDS
2986 : operands, N_ALTERNATIVES alternatives and constraint strings
2987 : CONSTRAINTS. OP_ALT_BASE has N_ALTERNATIVES * N_OPERANDS entries
2988 : and CONSTRAINTS has N_OPERANDS entries. OPLOC should be passed in
2989 : if the insn is an asm statement and preprocessing should take the
2990 : asm operands into account, e.g. to determine whether they could be
2991 : addresses in constraints that require addresses; it should then
2992 : point to an array of pointers to each operand. */
2993 :
2994 : void
2995 4911402 : preprocess_constraints (int n_operands, int n_alternatives,
2996 : const char **constraints,
2997 : operand_alternative *op_alt_base,
2998 : rtx **oploc)
2999 : {
3000 12764341 : for (int i = 0; i < n_operands; i++)
3001 : {
3002 7852939 : int j;
3003 7852939 : struct operand_alternative *op_alt;
3004 7852939 : const char *p = constraints[i];
3005 :
3006 7852939 : op_alt = op_alt_base;
3007 :
3008 50975905 : for (j = 0; j < n_alternatives; j++, op_alt += n_operands)
3009 : {
3010 43122966 : op_alt[i].cl = NO_REGS;
3011 43122966 : op_alt[i].register_filters = 0;
3012 43122966 : op_alt[i].dependent_filters = 0;
3013 43122966 : op_alt[i].constraint = p;
3014 43122966 : op_alt[i].matches = -1;
3015 43122966 : op_alt[i].matched = -1;
3016 :
3017 43122966 : if (*p == '\0' || *p == ',')
3018 : {
3019 1861856 : op_alt[i].anything_ok = 1;
3020 1861856 : continue;
3021 : }
3022 :
3023 108063485 : for (;;)
3024 : {
3025 108063485 : char c = *p;
3026 108063485 : if (c == '#')
3027 0 : do
3028 0 : c = *++p;
3029 0 : while (c != ',' && c != '\0');
3030 108063485 : if (c == ',' || c == '\0')
3031 : {
3032 41261110 : p++;
3033 41261110 : break;
3034 : }
3035 :
3036 66802375 : switch (c)
3037 : {
3038 5973433 : case '?':
3039 5973433 : op_alt[i].reject += 6;
3040 5973433 : break;
3041 419387 : case '!':
3042 419387 : op_alt[i].reject += 600;
3043 419387 : break;
3044 63721 : case '&':
3045 63721 : op_alt[i].earlyclobber = 1;
3046 63721 : break;
3047 :
3048 2129993 : case '0': case '1': case '2': case '3': case '4':
3049 2129993 : case '5': case '6': case '7': case '8': case '9':
3050 2129993 : {
3051 2129993 : char *end;
3052 2129993 : op_alt[i].matches = strtoul (p, &end, 10);
3053 2129993 : op_alt[op_alt[i].matches].matched = i;
3054 2129993 : p = end;
3055 : }
3056 2129993 : continue;
3057 :
3058 33293 : case 'X':
3059 33293 : op_alt[i].anything_ok = 1;
3060 33293 : break;
3061 :
3062 218152 : case 'g':
3063 218152 : op_alt[i].cl =
3064 218152 : reg_class_subunion[(int) op_alt[i].cl][(int) GENERAL_REGS];
3065 218152 : break;
3066 :
3067 57964396 : default:
3068 57964396 : enum constraint_num cn = lookup_constraint (p);
3069 57964396 : enum reg_class cl;
3070 57964396 : switch (get_constraint_type (cn))
3071 : {
3072 41425948 : case CT_REGISTER:
3073 41425948 : cl = reg_class_for_constraint (cn);
3074 30103288 : if (cl != NO_REGS)
3075 : {
3076 26407035 : op_alt[i].cl = reg_class_subunion[op_alt[i].cl][cl];
3077 26407035 : auto filter_id = get_register_filter_id (cn);
3078 26407035 : if (filter_id >= 0)
3079 : op_alt[i].register_filters |= 1U << filter_id;
3080 26407035 : auto dep_filter_id = get_dependent_filter_id (cn);
3081 26407035 : if (dep_filter_id >= 0)
3082 : op_alt[i].dependent_filters |= 1U << dep_filter_id;
3083 : }
3084 : break;
3085 :
3086 : case CT_CONST_INT:
3087 : break;
3088 :
3089 8192022 : case CT_MEMORY:
3090 8192022 : case CT_SPECIAL_MEMORY:
3091 8192022 : case CT_RELAXED_MEMORY:
3092 8192022 : op_alt[i].memory_ok = 1;
3093 8192022 : break;
3094 :
3095 90898 : case CT_ADDRESS:
3096 90898 : if (oploc && !address_operand (*oploc[i], VOIDmode))
3097 : break;
3098 :
3099 90879 : op_alt[i].is_address = 1;
3100 90879 : op_alt[i].cl
3101 90879 : = (reg_class_subunion
3102 90879 : [(int) op_alt[i].cl]
3103 90879 : [(int) base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
3104 90879 : ADDRESS, SCRATCH)]);
3105 90879 : break;
3106 :
3107 : case CT_FIXED_FORM:
3108 : break;
3109 : }
3110 : break;
3111 2129993 : }
3112 64672382 : p += CONSTRAINT_LEN (c, p);
3113 : }
3114 : }
3115 : }
3116 4911402 : }
3117 :
3118 : /* Return an array of operand_alternative instructions for
3119 : instruction ICODE. */
3120 :
3121 : const operand_alternative *
3122 301740757 : preprocess_insn_constraints (unsigned int icode)
3123 : {
3124 301740757 : gcc_checking_assert (IN_RANGE (icode, 0, NUM_INSN_CODES - 1));
3125 301740757 : if (this_target_recog->x_op_alt[icode])
3126 : return this_target_recog->x_op_alt[icode];
3127 :
3128 5648513 : int n_operands = insn_data[icode].n_operands;
3129 5648513 : if (n_operands == 0)
3130 : return 0;
3131 : /* Always provide at least one alternative so that which_op_alt ()
3132 : works correctly. If the instruction has 0 alternatives (i.e. all
3133 : constraint strings are empty) then each operand in this alternative
3134 : will have anything_ok set. */
3135 3081989 : int n_alternatives = MAX (insn_data[icode].n_alternatives, 1);
3136 3081989 : int n_entries = n_operands * n_alternatives;
3137 :
3138 3081989 : operand_alternative *op_alt = XCNEWVEC (operand_alternative, n_entries);
3139 3081989 : const char **constraints = XALLOCAVEC (const char *, n_operands);
3140 :
3141 10471258 : for (int i = 0; i < n_operands; ++i)
3142 7389269 : constraints[i] = insn_data[icode].operand[i].constraint;
3143 3081989 : preprocess_constraints (n_operands, n_alternatives, constraints, op_alt,
3144 : NULL);
3145 :
3146 3081989 : this_target_recog->x_op_alt[icode] = op_alt;
3147 3081989 : return op_alt;
3148 : }
3149 :
3150 : /* After calling extract_insn, you can use this function to extract some
3151 : information from the constraint strings into a more usable form.
3152 : The collected data is stored in recog_op_alt. */
3153 :
3154 : void
3155 205665207 : preprocess_constraints (rtx_insn *insn)
3156 : {
3157 205665207 : int icode = INSN_CODE (insn);
3158 205665207 : if (icode >= 0)
3159 203880324 : recog_op_alt = preprocess_insn_constraints (icode);
3160 : else
3161 : {
3162 1784883 : int n_operands = recog_data.n_operands;
3163 1784883 : int n_alternatives = recog_data.n_alternatives;
3164 1784883 : int n_entries = n_operands * n_alternatives;
3165 1784883 : memset (asm_op_alt, 0, n_entries * sizeof (operand_alternative));
3166 1784883 : preprocess_constraints (n_operands, n_alternatives,
3167 1784883 : recog_data.constraints, asm_op_alt,
3168 : NULL);
3169 1784883 : recog_op_alt = asm_op_alt;
3170 : }
3171 205665207 : }
3172 :
3173 : /* Check the operands of an insn against the insn's operand constraints
3174 : and return 1 if they match any of the alternatives in ALTERNATIVES.
3175 :
3176 : The information about the insn's operands, constraints, operand modes
3177 : etc. is obtained from the global variables set up by extract_insn.
3178 :
3179 : WHICH_ALTERNATIVE is set to a number which indicates which
3180 : alternative of constraints was matched: 0 for the first alternative,
3181 : 1 for the next, etc.
3182 :
3183 : In addition, when two operands are required to match
3184 : and it happens that the output operand is (reg) while the
3185 : input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
3186 : make the output operand look like the input.
3187 : This is because the output operand is the one the template will print.
3188 :
3189 : This is used in final, just before printing the assembler code and by
3190 : the routines that determine an insn's attribute.
3191 :
3192 : If STRICT is a positive nonzero value, it means that we have been
3193 : called after reload has been completed. In that case, we must
3194 : do all checks strictly. If it is zero, it means that we have been called
3195 : before reload has completed. In that case, we first try to see if we can
3196 : find an alternative that matches strictly. If not, we try again, this
3197 : time assuming that reload will fix up the insn. This provides a "best
3198 : guess" for the alternative and is used to compute attributes of insns prior
3199 : to reload. A negative value of STRICT is used for this internal call. */
3200 :
3201 : struct funny_match
3202 : {
3203 : int this_op, other;
3204 : };
3205 :
3206 : /* For a register constraint CN with a dependent filter, return true if
3207 : the respective filter allows REGNO (OP) + OFFSET given the ref-operand
3208 : in recog_data.operand or false if it doesn't.
3209 : If the filter cannot be evaluated, for example when no hard reg
3210 : has been chosen yet, return true. */
3211 :
3212 : static bool
3213 0 : test_dependent_filter (constraint_num cn, rtx op, int offset,
3214 : machine_mode mode)
3215 : {
3216 0 : int id = get_dependent_filter_id (cn);
3217 0 : if (id < 0 || !REG_P (op))
3218 0 : return true;
3219 : int ref_opno = get_dependent_filter_ref (id);
3220 : if (ref_opno < 0 || ref_opno >= recog_data.n_operands)
3221 : return true;
3222 : rtx ref_op = recog_data.operand[ref_opno];
3223 : if (!REG_P (ref_op))
3224 : return true;
3225 : return eval_dependent_filter (id, REGNO (op) + offset, mode,
3226 : REGNO (ref_op), GET_MODE (ref_op));
3227 : }
3228 :
3229 : bool
3230 1168476195 : constrain_operands (int strict, alternative_mask alternatives)
3231 : {
3232 1169411543 : const char *constraints[MAX_RECOG_OPERANDS];
3233 1169411543 : int matching_operands[MAX_RECOG_OPERANDS];
3234 1169411543 : int earlyclobber[MAX_RECOG_OPERANDS];
3235 1169411543 : int c;
3236 :
3237 1169411543 : struct funny_match funny_match[MAX_RECOG_OPERANDS];
3238 1169411543 : int funny_match_index;
3239 :
3240 1169411543 : which_alternative = 0;
3241 1169411543 : if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
3242 : return true;
3243 :
3244 3478167856 : for (c = 0; c < recog_data.n_operands; c++)
3245 2369992512 : constraints[c] = recog_data.constraints[c];
3246 :
3247 4152277966 : do
3248 : {
3249 4152277966 : int seen_earlyclobber_at = -1;
3250 4152277966 : int opno;
3251 4152277966 : bool lose = false;
3252 4152277966 : funny_match_index = 0;
3253 :
3254 4152277966 : if (!TEST_BIT (alternatives, which_alternative))
3255 : {
3256 : int i;
3257 :
3258 2822165866 : for (i = 0; i < recog_data.n_operands; i++)
3259 3789591782 : constraints[i] = skip_alternative (constraints[i]);
3260 :
3261 927369975 : which_alternative++;
3262 927369975 : continue;
3263 927369975 : }
3264 :
3265 9917623917 : for (opno = 0; opno < recog_data.n_operands; opno++)
3266 6692715926 : matching_operands[opno] = -1;
3267 :
3268 9917623917 : for (opno = 0; opno < recog_data.n_operands; opno++)
3269 : {
3270 6692715926 : rtx op = recog_data.operand[opno];
3271 6692715926 : machine_mode mode = GET_MODE (op);
3272 6692715926 : const char *p = constraints[opno];
3273 6692715926 : int offset = 0;
3274 6692715926 : bool win = false;
3275 6692715926 : int val;
3276 6692715926 : int len;
3277 :
3278 6692715926 : earlyclobber[opno] = 0;
3279 :
3280 6692715926 : if (GET_CODE (op) == SUBREG)
3281 : {
3282 1560710 : if (REG_P (SUBREG_REG (op))
3283 1560710 : && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
3284 420 : offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
3285 420 : GET_MODE (SUBREG_REG (op)),
3286 420 : SUBREG_BYTE (op),
3287 : GET_MODE (op));
3288 1560710 : op = SUBREG_REG (op);
3289 : }
3290 :
3291 : /* An empty constraint or empty alternative
3292 : allows anything which matched the pattern. */
3293 6692715926 : if (*p == 0 || *p == ',')
3294 99415526 : win = true;
3295 :
3296 16900330536 : do
3297 16900330536 : switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
3298 : {
3299 : case '\0':
3300 : len = 0;
3301 : break;
3302 6335407822 : case ',':
3303 6335407822 : c = '\0';
3304 6335407822 : break;
3305 32 : case '-':
3306 32 : raw_constraint_p = true;
3307 32 : break;
3308 :
3309 0 : case '#':
3310 : /* Ignore rest of this alternative as far as
3311 : constraint checking is concerned. */
3312 0 : do
3313 0 : p++;
3314 0 : while (*p && *p != ',');
3315 : len = 0;
3316 : break;
3317 :
3318 504566 : case '&':
3319 504566 : earlyclobber[opno] = 1;
3320 504566 : if (seen_earlyclobber_at < 0)
3321 482859 : seen_earlyclobber_at = opno;
3322 : break;
3323 :
3324 194786903 : case '0': case '1': case '2': case '3': case '4':
3325 194786903 : case '5': case '6': case '7': case '8': case '9':
3326 194786903 : {
3327 : /* This operand must be the same as a previous one.
3328 : This kind of constraint is used for instructions such
3329 : as add when they take only two operands.
3330 :
3331 : Note that the lower-numbered operand is passed first.
3332 :
3333 : If we are not testing strictly, assume that this
3334 : constraint will be satisfied. */
3335 :
3336 194786903 : char *end;
3337 194786903 : int match;
3338 :
3339 194786903 : match = strtoul (p, &end, 10);
3340 194786903 : p = end;
3341 :
3342 194786903 : if (strict < 0)
3343 : val = 1;
3344 : else
3345 : {
3346 193829496 : rtx op1 = recog_data.operand[match];
3347 193829496 : rtx op2 = recog_data.operand[opno];
3348 193829496 : val = operands_match_p (op1, op2);
3349 : }
3350 :
3351 194786903 : matching_operands[opno] = match;
3352 194786903 : matching_operands[match] = opno;
3353 :
3354 194786903 : if (val != 0)
3355 160584319 : win = true;
3356 :
3357 : /* If output is *x and input is *--x, arrange later
3358 : to change the output to *--x as well, since the
3359 : output op is the one that will be printed. */
3360 194786903 : if (val == 2 && strict > 0)
3361 : {
3362 0 : funny_match[funny_match_index].this_op = opno;
3363 0 : funny_match[funny_match_index++].other = match;
3364 : }
3365 : }
3366 194786903 : len = 0;
3367 194786903 : break;
3368 :
3369 267529 : case 'p':
3370 : /* p is used for address_operands. When we are called by
3371 : gen_reload, no one will have checked that the address is
3372 : strictly valid, i.e., that all pseudos requiring hard regs
3373 : have gotten them. We also want to make sure we have a
3374 : valid mode. */
3375 267529 : {
3376 267442 : auto mem_mode = (recog_data.is_asm
3377 267529 : ? VOIDmode
3378 : : recog_data.operand_mode[opno]);
3379 267529 : if ((GET_MODE (op) == VOIDmode
3380 267529 : || SCALAR_INT_MODE_P (GET_MODE (op)))
3381 535032 : && (strict <= 0
3382 267529 : || strict_memory_address_p (mem_mode, op)))
3383 : win = true;
3384 : break;
3385 : }
3386 :
3387 : /* No need to check general_operand again;
3388 : it was done in insn-recog.cc. Well, except that reload
3389 : doesn't check the validity of its replacements, but
3390 : that should only matter when there's a bug. */
3391 128229524 : case 'g':
3392 : /* Anything goes unless it is a REG and really has a hard reg
3393 : but the hard reg is not in the class GENERAL_REGS. */
3394 128229524 : if (REG_P (op))
3395 : {
3396 48315948 : if (strict < 0
3397 : || GENERAL_REGS == ALL_REGS
3398 48315896 : || (reload_in_progress
3399 0 : && REGNO (op) >= FIRST_PSEUDO_REGISTER)
3400 96631844 : || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
3401 : win = true;
3402 : }
3403 79913576 : else if (strict < 0 || general_operand (op, mode))
3404 : win = true;
3405 : break;
3406 :
3407 233 : case '{':
3408 224 : if ((REG_P (op) && HARD_REGISTER_P (op)
3409 224 : && (int) REGNO (op) == decode_hard_reg_constraint (p))
3410 244 : || !reload_completed)
3411 : win = true;
3412 : break;
3413 :
3414 9883825823 : default:
3415 9883825823 : {
3416 9883825823 : enum constraint_num cn = lookup_constraint (p);
3417 9883825823 : enum reg_class cl = reg_class_for_constraint (cn);
3418 4581525926 : if (cl != NO_REGS)
3419 : {
3420 4400302951 : auto *filter = get_register_filter (cn);
3421 4400302951 : if (strict < 0
3422 4398571474 : || (strict == 0
3423 23659177 : && REG_P (op)
3424 17298119 : && REGNO (op) >= FIRST_PSEUDO_REGISTER)
3425 6436315 : || (strict == 0 && GET_CODE (op) == SCRATCH)
3426 8781633279 : || (REG_P (op)
3427 3166896701 : && reg_fits_class_p (op, cl, offset, mode)
3428 : && (!filter
3429 : || TEST_HARD_REG_BIT (*filter,
3430 : REGNO (op) + offset))
3431 : && (strict <= 0
3432 : || test_dependent_filter (cn, op, offset,
3433 : mode))))
3434 : win = true;
3435 : }
3436 :
3437 5483522872 : else if (constraint_satisfied_p (op, cn))
3438 : win = true;
3439 :
3440 4583829952 : else if ((insn_extra_memory_constraint (cn)
3441 : || insn_extra_relaxed_memory_constraint (cn))
3442 : /* Every memory operand can be reloaded to fit. */
3443 4583829952 : && ((strict < 0 && MEM_P (op))
3444 : /* Before reload, accept what reload can turn
3445 : into a mem. */
3446 710629 : || (strict < 0 && CONSTANT_P (op))
3447 : /* Before reload, accept a pseudo or hard register,
3448 : since LRA can turn it into a mem. */
3449 710256 : || (strict < 0 && targetm.lra_p () && REG_P (op))
3450 : /* During reload, accept a pseudo */
3451 969152447 : || (reload_in_progress && REG_P (op)
3452 0 : && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
3453 : win = true;
3454 4583119323 : else if (insn_extra_address_constraint (cn)
3455 : /* Every address operand can be reloaded to fit. */
3456 4583119323 : && strict < 0)
3457 : win = true;
3458 : /* Cater to architectures like IA-64 that define extra memory
3459 : constraints without using define_memory_constraint. */
3460 4583119323 : else if (reload_in_progress
3461 0 : && REG_P (op)
3462 0 : && REGNO (op) >= FIRST_PSEUDO_REGISTER
3463 0 : && reg_renumber[REGNO (op)] < 0
3464 0 : && reg_equiv_mem (REGNO (op)) != 0
3465 4583119323 : && constraint_satisfied_p
3466 0 : (reg_equiv_mem (REGNO (op)), cn))
3467 : win = true;
3468 : break;
3469 : }
3470 : }
3471 16900330536 : while (p += len, c);
3472 :
3473 6692715926 : raw_constraint_p = false;
3474 6692715926 : constraints[opno] = p;
3475 : /* If this operand did not win somehow,
3476 : this alternative loses. */
3477 6692715926 : if (! win)
3478 3229109875 : lose = true;
3479 : }
3480 : /* This alternative won; the operands are ok.
3481 : Change whichever operands this alternative says to change. */
3482 3224907991 : if (! lose)
3483 : {
3484 1103722331 : int opno, eopno;
3485 :
3486 : /* See if any earlyclobber operand conflicts with some other
3487 : operand. */
3488 :
3489 1103722331 : if (strict > 0 && seen_earlyclobber_at >= 0)
3490 1226836 : for (eopno = seen_earlyclobber_at;
3491 1620221 : eopno < recog_data.n_operands;
3492 : eopno++)
3493 : /* Ignore earlyclobber operands now in memory,
3494 : because we would often report failure when we have
3495 : two memory operands, one of which was formerly a REG. */
3496 1226836 : if (earlyclobber[eopno]
3497 413278 : && REG_P (recog_data.operand[eopno]))
3498 2082545 : for (opno = 0; opno < recog_data.n_operands; opno++)
3499 1669267 : if ((MEM_P (recog_data.operand[opno])
3500 1529888 : || recog_data.operand_type[opno] != OP_OUT)
3501 966988 : && opno != eopno
3502 : /* Ignore things like match_operator operands. */
3503 966416 : && *recog_data.constraints[opno] != 0
3504 1001256 : && ! (matching_operands[opno] == eopno
3505 109441 : && operands_match_p (recog_data.operand[opno],
3506 : recog_data.operand[eopno]))
3507 2453674 : && ! safe_from_earlyclobber (recog_data.operand[opno],
3508 784407 : recog_data.operand[eopno]))
3509 : lose = true;
3510 :
3511 1103722331 : if (! lose)
3512 : {
3513 1103717962 : while (--funny_match_index >= 0)
3514 : {
3515 0 : recog_data.operand[funny_match[funny_match_index].other]
3516 0 : = recog_data.operand[funny_match[funny_match_index].this_op];
3517 : }
3518 :
3519 : /* For operands without < or > constraints reject side-effects. */
3520 : if (AUTO_INC_DEC && recog_data.is_asm)
3521 : {
3522 : for (opno = 0; opno < recog_data.n_operands; opno++)
3523 : if (MEM_P (recog_data.operand[opno]))
3524 : switch (GET_CODE (XEXP (recog_data.operand[opno], 0)))
3525 : {
3526 : case PRE_INC:
3527 : case POST_INC:
3528 : case PRE_DEC:
3529 : case POST_DEC:
3530 : case PRE_MODIFY:
3531 : case POST_MODIFY:
3532 : if (strchr (recog_data.constraints[opno], '<') == NULL
3533 : && strchr (recog_data.constraints[opno], '>')
3534 : == NULL)
3535 : return false;
3536 : break;
3537 : default:
3538 : break;
3539 : }
3540 : }
3541 :
3542 : return true;
3543 : }
3544 : }
3545 :
3546 2121190029 : which_alternative++;
3547 : }
3548 3048560004 : while (which_alternative < recog_data.n_alternatives);
3549 :
3550 4457382 : which_alternative = -1;
3551 : /* If we are about to reject this, but we are not to test strictly,
3552 : try a very loose test. Only return failure if it fails also. */
3553 4457382 : if (strict == 0)
3554 : return constrain_operands (-1, alternatives);
3555 : else
3556 : return false;
3557 : }
3558 :
3559 : /* Return true iff OPERAND (assumed to be a REG rtx)
3560 : is a hard reg in class CLASS when its regno is offset by OFFSET
3561 : and changed to mode MODE.
3562 : If REG occupies multiple hard regs, all of them must be in CLASS. */
3563 :
3564 : bool
3565 3468992091 : reg_fits_class_p (const_rtx operand, reg_class_t cl, int offset,
3566 : machine_mode mode)
3567 : {
3568 3468992091 : unsigned int regno = REGNO (operand);
3569 :
3570 3468992091 : if (cl == NO_REGS)
3571 : return false;
3572 :
3573 : /* Regno must not be a pseudo register. Offset may be negative. */
3574 3369109712 : return (HARD_REGISTER_NUM_P (regno)
3575 3369032588 : && HARD_REGISTER_NUM_P (regno + offset)
3576 6738142300 : && in_hard_reg_set_p (reg_class_contents[(int) cl], mode,
3577 : regno + offset));
3578 : }
3579 :
3580 : /* Split single instruction. Helper function for split_all_insns and
3581 : split_all_insns_noflow. Return last insn in the sequence if successful,
3582 : or NULL if unsuccessful. */
3583 :
3584 : static rtx_insn *
3585 395665904 : split_insn (rtx_insn *insn)
3586 : {
3587 : /* Split insns here to get max fine-grain parallelism. */
3588 395665904 : rtx_insn *first = PREV_INSN (insn);
3589 395665904 : rtx_insn *last = try_split (PATTERN (insn), insn, 1);
3590 395665904 : rtx insn_set, last_set, note;
3591 :
3592 395665904 : if (last == insn)
3593 : return NULL;
3594 :
3595 : /* If the original instruction was a single set that was known to be
3596 : equivalent to a constant, see if we can say the same about the last
3597 : instruction in the split sequence. The two instructions must set
3598 : the same destination. */
3599 6320911 : insn_set = single_set (insn);
3600 6320911 : if (insn_set)
3601 : {
3602 6191150 : last_set = single_set (last);
3603 6191150 : if (last_set && rtx_equal_p (SET_DEST (last_set), SET_DEST (insn_set)))
3604 : {
3605 2936738 : note = find_reg_equal_equiv_note (insn);
3606 2936738 : if (note && CONSTANT_P (XEXP (note, 0)))
3607 76472 : set_unique_reg_note (last, REG_EQUAL, XEXP (note, 0));
3608 2860266 : else if (CONSTANT_P (SET_SRC (insn_set)))
3609 34151 : set_unique_reg_note (last, REG_EQUAL,
3610 : copy_rtx (SET_SRC (insn_set)));
3611 : }
3612 : }
3613 :
3614 : /* try_split returns the NOTE that INSN became. */
3615 6320911 : SET_INSN_DELETED (insn);
3616 :
3617 : /* ??? Coddle to md files that generate subregs in post-reload
3618 : splitters instead of computing the proper hard register. */
3619 6320911 : if (reload_completed && first != last)
3620 : {
3621 5881547 : auto old_post_ra_split_completed = post_ra_split_completed;
3622 5881547 : post_ra_split_completed = true;
3623 5881547 : first = NEXT_INSN (first);
3624 2800012 : for (;;)
3625 : {
3626 8681559 : if (INSN_P (first))
3627 8677522 : cleanup_subreg_operands (first);
3628 8681559 : if (first == last)
3629 : break;
3630 2800012 : first = NEXT_INSN (first);
3631 : }
3632 5881547 : post_ra_split_completed = old_post_ra_split_completed;
3633 : }
3634 :
3635 : return last;
3636 : }
3637 :
3638 : /* Split all insns in the function. If UPD_LIFE, update life info after. */
3639 :
3640 : void
3641 4132560 : split_all_insns (void)
3642 : {
3643 4132560 : bool changed;
3644 4132560 : bool need_cfg_cleanup = false;
3645 4132560 : basic_block bb;
3646 :
3647 4132560 : auto_sbitmap blocks (last_basic_block_for_fn (cfun));
3648 4132560 : bitmap_clear (blocks);
3649 4132560 : changed = false;
3650 :
3651 44753391 : FOR_EACH_BB_REVERSE_FN (bb, cfun)
3652 : {
3653 40620831 : rtx_insn *insn, *next;
3654 40620831 : bool finish = false;
3655 :
3656 40620831 : rtl_profile_for_bb (bb);
3657 519301546 : for (insn = BB_HEAD (bb); !finish ; insn = next)
3658 : {
3659 : /* Can't use `next_real_insn' because that might go across
3660 : CODE_LABELS and short-out basic blocks. */
3661 478680715 : next = NEXT_INSN (insn);
3662 478680715 : finish = (insn == BB_END (bb));
3663 :
3664 : /* If INSN has a REG_EH_REGION note and we split INSN, the
3665 : resulting split may not have/need REG_EH_REGION notes.
3666 :
3667 : If that happens and INSN was the last reference to the
3668 : given EH region, then the EH region will become unreachable.
3669 : We cannot leave the unreachable blocks in the CFG as that
3670 : will trigger a checking failure.
3671 :
3672 : So track if INSN has a REG_EH_REGION note. If so and we
3673 : split INSN, then trigger a CFG cleanup. */
3674 478680715 : rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3675 478680715 : if (INSN_P (insn))
3676 : {
3677 395703177 : rtx set = single_set (insn);
3678 :
3679 : /* Don't split no-op move insns. These should silently
3680 : disappear later in final. Splitting such insns would
3681 : break the code that handles LIBCALL blocks. */
3682 395703177 : if (set && set_noop_p (set))
3683 : {
3684 : /* Nops get in the way while scheduling, so delete them
3685 : now if register allocation has already been done. It
3686 : is too risky to try to do this before register
3687 : allocation, and there are unlikely to be very many
3688 : nops then anyways. */
3689 37273 : if (reload_completed)
3690 37273 : delete_insn_and_edges (insn);
3691 37273 : if (note)
3692 0 : need_cfg_cleanup = true;
3693 : }
3694 : else
3695 : {
3696 395665904 : if (split_insn (insn))
3697 : {
3698 6320911 : bitmap_set_bit (blocks, bb->index);
3699 6320911 : changed = true;
3700 6320911 : if (note)
3701 2794 : need_cfg_cleanup = true;
3702 : }
3703 : }
3704 : }
3705 : }
3706 : }
3707 :
3708 4132560 : if (reload_completed)
3709 2601439 : post_ra_split_completed = true;
3710 :
3711 4132560 : default_rtl_profile ();
3712 4132560 : if (changed)
3713 : {
3714 783296 : find_many_sub_basic_blocks (blocks);
3715 :
3716 : /* Splitting could drop an REG_EH_REGION if it potentially
3717 : trapped in its original form, but does not in its split
3718 : form. Consider a FLOAT_TRUNCATE which splits into a memory
3719 : store/load pair and -fnon-call-exceptions. */
3720 783296 : if (need_cfg_cleanup)
3721 1336 : cleanup_cfg (0);
3722 : }
3723 :
3724 4132560 : checking_verify_flow_info ();
3725 4132560 : }
3726 :
3727 : /* Same as split_all_insns, but do not expect CFG to be available.
3728 : Used by machine dependent reorg passes. */
3729 :
3730 : void
3731 0 : split_all_insns_noflow (void)
3732 : {
3733 0 : rtx_insn *next, *insn;
3734 :
3735 0 : for (insn = get_insns (); insn; insn = next)
3736 : {
3737 0 : next = NEXT_INSN (insn);
3738 0 : if (INSN_P (insn))
3739 : {
3740 : /* Don't split no-op move insns. These should silently
3741 : disappear later in final. Splitting such insns would
3742 : break the code that handles LIBCALL blocks. */
3743 0 : rtx set = single_set (insn);
3744 0 : if (set && set_noop_p (set))
3745 : {
3746 : /* Nops get in the way while scheduling, so delete them
3747 : now if register allocation has already been done. It
3748 : is too risky to try to do this before register
3749 : allocation, and there are unlikely to be very many
3750 : nops then anyways.
3751 :
3752 : ??? Should we use delete_insn when the CFG isn't valid? */
3753 0 : if (reload_completed)
3754 0 : delete_insn_and_edges (insn);
3755 : }
3756 : else
3757 0 : split_insn (insn);
3758 : }
3759 : }
3760 :
3761 0 : if (reload_completed)
3762 0 : post_ra_split_completed = true;
3763 0 : }
3764 :
3765 : struct peep2_insn_data
3766 : {
3767 : rtx_insn *insn;
3768 : regset live_before;
3769 : };
3770 :
3771 : static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
3772 : static int peep2_current;
3773 :
3774 : static bool peep2_do_rebuild_jump_labels;
3775 : static bool peep2_do_cleanup_cfg;
3776 :
3777 : /* The number of instructions available to match a peep2. */
3778 : int peep2_current_count;
3779 :
3780 : /* A marker indicating the last insn of the block. The live_before regset
3781 : for this element is correct, indicating DF_LIVE_OUT for the block. */
3782 : #define PEEP2_EOB invalid_insn_rtx
3783 :
3784 : /* Wrap N to fit into the peep2_insn_data buffer. */
3785 :
3786 : static int
3787 438170630 : peep2_buf_position (int n)
3788 : {
3789 0 : if (n >= MAX_INSNS_PER_PEEP2 + 1)
3790 147524523 : n -= MAX_INSNS_PER_PEEP2 + 1;
3791 438170630 : return n;
3792 : }
3793 :
3794 : /* Return the Nth non-note insn after `current', or return NULL_RTX if it
3795 : does not exist. Used by the recognizer to find the next insn to match
3796 : in a multi-insn pattern. */
3797 :
3798 : rtx_insn *
3799 227213335 : peep2_next_insn (int n)
3800 : {
3801 227213335 : gcc_assert (n <= peep2_current_count);
3802 :
3803 227213335 : n = peep2_buf_position (peep2_current + n);
3804 :
3805 227213335 : return peep2_insn_data[n].insn;
3806 : }
3807 :
3808 : /* Return true if REGNO is dead before the Nth non-note insn
3809 : after `current'. */
3810 :
3811 : bool
3812 13565562 : peep2_regno_dead_p (int ofs, int regno)
3813 : {
3814 13565562 : gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3815 :
3816 13565562 : ofs = peep2_buf_position (peep2_current + ofs);
3817 :
3818 13565562 : gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3819 :
3820 13565562 : return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
3821 : }
3822 :
3823 : /* Similarly for a REG. */
3824 :
3825 : bool
3826 293958 : peep2_reg_dead_p (int ofs, rtx reg)
3827 : {
3828 293958 : gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3829 :
3830 293958 : ofs = peep2_buf_position (peep2_current + ofs);
3831 :
3832 293958 : gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3833 :
3834 293958 : unsigned int end_regno = END_REGNO (reg);
3835 377873 : for (unsigned int regno = REGNO (reg); regno < end_regno; ++regno)
3836 293958 : if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno))
3837 : return false;
3838 : return true;
3839 : }
3840 :
3841 : /* Regno offset to be used in the register search. */
3842 : static int search_ofs;
3843 :
3844 : /* Try to find a hard register of mode MODE, matching the register class in
3845 : CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
3846 : remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
3847 : in which case the only condition is that the register must be available
3848 : before CURRENT_INSN.
3849 : Registers that already have bits set in REG_SET will not be considered.
3850 :
3851 : If an appropriate register is available, it will be returned and the
3852 : corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
3853 : returned. */
3854 :
3855 : rtx
3856 609333 : peep2_find_free_register (int from, int to, const char *class_str,
3857 : machine_mode mode, HARD_REG_SET *reg_set)
3858 : {
3859 609333 : enum reg_class cl;
3860 609333 : HARD_REG_SET live;
3861 609333 : df_ref def;
3862 609333 : int i;
3863 :
3864 609333 : gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
3865 609333 : gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
3866 :
3867 609333 : from = peep2_buf_position (peep2_current + from);
3868 609333 : to = peep2_buf_position (peep2_current + to);
3869 :
3870 609333 : gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3871 609333 : REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
3872 :
3873 1240019 : while (from != to)
3874 : {
3875 21353 : gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3876 :
3877 : /* Don't use registers set or clobbered by the insn. */
3878 85412 : FOR_EACH_INSN_DEF (def, peep2_insn_data[from].insn)
3879 64059 : SET_HARD_REG_BIT (live, DF_REF_REGNO (def));
3880 :
3881 24455 : from = peep2_buf_position (from + 1);
3882 : }
3883 :
3884 609333 : cl = reg_class_for_constraint (lookup_constraint (class_str));
3885 :
3886 5929091 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3887 : {
3888 5924097 : int raw_regno, regno, j;
3889 5924097 : bool success;
3890 :
3891 : /* Distribute the free registers as much as possible. */
3892 5924097 : raw_regno = search_ofs + i;
3893 5924097 : if (raw_regno >= FIRST_PSEUDO_REGISTER)
3894 291095 : raw_regno -= FIRST_PSEUDO_REGISTER;
3895 : #ifdef REG_ALLOC_ORDER
3896 5924097 : regno = reg_alloc_order[raw_regno];
3897 : #else
3898 : regno = raw_regno;
3899 : #endif
3900 :
3901 : /* Can it support the mode we need? */
3902 5924097 : if (!targetm.hard_regno_mode_ok (regno, mode))
3903 1787304 : continue;
3904 :
3905 4741132 : success = true;
3906 4741132 : for (j = 0; success && j < hard_regno_nregs (regno, mode); j++)
3907 : {
3908 : /* Don't allocate fixed registers. */
3909 4136793 : if (fixed_regs[regno + j])
3910 : {
3911 : success = false;
3912 : break;
3913 : }
3914 : /* Don't allocate global registers. */
3915 2208972 : if (global_regs[regno + j])
3916 : {
3917 : success = false;
3918 : break;
3919 : }
3920 : /* Make sure the register is of the right class. */
3921 2208972 : if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno + j))
3922 : {
3923 : success = false;
3924 : break;
3925 : }
3926 : /* And that we don't create an extra save/restore. */
3927 1230911 : if (! crtl->abi->clobbers_full_reg_p (regno + j)
3928 1230911 : && ! df_regs_ever_live_p (regno + j))
3929 : {
3930 : success = false;
3931 : break;
3932 : }
3933 :
3934 1196045 : if (! targetm.hard_regno_scratch_ok (regno + j))
3935 : {
3936 : success = false;
3937 : break;
3938 : }
3939 :
3940 : /* And we don't clobber traceback for noreturn functions. */
3941 1195860 : if ((regno + j == FRAME_POINTER_REGNUM
3942 1195860 : || regno + j == HARD_FRAME_POINTER_REGNUM)
3943 50120 : && (! reload_completed || frame_pointer_needed))
3944 : {
3945 : success = false;
3946 : break;
3947 : }
3948 :
3949 1185168 : if (TEST_HARD_REG_BIT (*reg_set, regno + j)
3950 1185168 : || TEST_HARD_REG_BIT (live, regno + j))
3951 : {
3952 : success = false;
3953 : break;
3954 : }
3955 : }
3956 :
3957 4136793 : if (success)
3958 : {
3959 604339 : add_to_hard_reg_set (reg_set, mode, regno);
3960 :
3961 : /* Start the next search with the next register. */
3962 604339 : if (++raw_regno >= FIRST_PSEUDO_REGISTER)
3963 3915 : raw_regno = 0;
3964 604339 : search_ofs = raw_regno;
3965 :
3966 604339 : return gen_rtx_REG (mode, regno);
3967 : }
3968 : }
3969 :
3970 4994 : search_ofs = 0;
3971 4994 : return NULL_RTX;
3972 : }
3973 :
3974 : /* Forget all currently tracked instructions, only remember current
3975 : LIVE regset. */
3976 :
3977 : static void
3978 11076139 : peep2_reinit_state (regset live)
3979 : {
3980 11076139 : int i;
3981 :
3982 : /* Indicate that all slots except the last holds invalid data. */
3983 77532973 : for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
3984 66456834 : peep2_insn_data[i].insn = NULL;
3985 11076139 : peep2_current_count = 0;
3986 :
3987 : /* Indicate that the last slot contains live_after data. */
3988 11076139 : peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
3989 11076139 : peep2_current = MAX_INSNS_PER_PEEP2;
3990 :
3991 11076139 : COPY_REG_SET (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
3992 11076139 : }
3993 :
3994 : /* Copies frame related info of an insn (OLD_INSN) to the single
3995 : insn (NEW_INSN) that was obtained by splitting OLD_INSN. */
3996 :
3997 : void
3998 137249 : copy_frame_info_to_split_insn (rtx_insn *old_insn, rtx_insn *new_insn)
3999 : {
4000 137249 : bool any_note = false;
4001 137249 : rtx note;
4002 :
4003 137249 : if (!RTX_FRAME_RELATED_P (old_insn))
4004 : return;
4005 :
4006 137249 : RTX_FRAME_RELATED_P (new_insn) = 1;
4007 :
4008 : /* Allow the backend to fill in a note during the split. */
4009 137249 : for (note = REG_NOTES (new_insn); note ; note = XEXP (note, 1))
4010 0 : switch (REG_NOTE_KIND (note))
4011 : {
4012 0 : case REG_FRAME_RELATED_EXPR:
4013 0 : case REG_CFA_DEF_CFA:
4014 0 : case REG_CFA_ADJUST_CFA:
4015 0 : case REG_CFA_OFFSET:
4016 0 : case REG_CFA_REGISTER:
4017 0 : case REG_CFA_EXPRESSION:
4018 0 : case REG_CFA_RESTORE:
4019 0 : case REG_CFA_SET_VDRAP:
4020 0 : any_note = true;
4021 0 : break;
4022 : default:
4023 : break;
4024 : }
4025 :
4026 : /* If the backend didn't supply a note, copy one over. */
4027 137249 : if (!any_note)
4028 334947 : for (note = REG_NOTES (old_insn); note ; note = XEXP (note, 1))
4029 197698 : switch (REG_NOTE_KIND (note))
4030 : {
4031 149308 : case REG_FRAME_RELATED_EXPR:
4032 149308 : case REG_CFA_DEF_CFA:
4033 149308 : case REG_CFA_ADJUST_CFA:
4034 149308 : case REG_CFA_OFFSET:
4035 149308 : case REG_CFA_REGISTER:
4036 149308 : case REG_CFA_EXPRESSION:
4037 149308 : case REG_CFA_RESTORE:
4038 149308 : case REG_CFA_SET_VDRAP:
4039 149308 : add_reg_note (new_insn, REG_NOTE_KIND (note), XEXP (note, 0));
4040 149308 : any_note = true;
4041 149308 : break;
4042 : default:
4043 : break;
4044 : }
4045 :
4046 : /* If there still isn't a note, make sure the unwind info sees the
4047 : same expression as before the split. */
4048 137249 : if (!any_note)
4049 : {
4050 2458 : rtx old_set, new_set;
4051 :
4052 : /* The old insn had better have been simple, or annotated. */
4053 2458 : old_set = single_set (old_insn);
4054 2458 : gcc_assert (old_set != NULL);
4055 :
4056 2458 : new_set = single_set (new_insn);
4057 2458 : if (!new_set || !rtx_equal_p (new_set, old_set))
4058 281 : add_reg_note (new_insn, REG_FRAME_RELATED_EXPR, old_set);
4059 : }
4060 :
4061 : /* Copy prologue/epilogue status. This is required in order to keep
4062 : proper placement of EPILOGUE_BEG and the DW_CFA_remember_state. */
4063 137249 : maybe_copy_prologue_epilogue_insn (old_insn, new_insn);
4064 : }
4065 :
4066 : /* While scanning basic block BB, we found a match of length MATCH_LEN + 1,
4067 : starting at INSN. Perform the replacement, removing the old insns and
4068 : replacing them with ATTEMPT. Returns the last insn emitted, or NULL
4069 : if the replacement is rejected. */
4070 :
4071 : static rtx_insn *
4072 2316078 : peep2_attempt (basic_block bb, rtx_insn *insn, int match_len, rtx_insn *attempt)
4073 : {
4074 2316078 : int i;
4075 2316078 : rtx_insn *last, *before_try, *x;
4076 2316078 : rtx eh_note, as_note;
4077 2316078 : rtx_insn *old_insn;
4078 2316078 : rtx_insn *new_insn;
4079 2316078 : bool was_call = false;
4080 :
4081 : /* If we are splitting an RTX_FRAME_RELATED_P insn, do not allow it to
4082 : match more than one insn, or to be split into more than one insn. */
4083 2316078 : old_insn = peep2_insn_data[peep2_current].insn;
4084 2316078 : if (RTX_FRAME_RELATED_P (old_insn))
4085 : {
4086 140047 : if (match_len != 0)
4087 : return NULL;
4088 :
4089 : /* Look for one "active" insn. I.e. ignore any "clobber" insns that
4090 : may be in the stream for the purpose of register allocation. */
4091 140047 : if (active_insn_p (attempt))
4092 : new_insn = attempt;
4093 : else
4094 35505 : new_insn = next_active_insn (attempt);
4095 140047 : if (next_active_insn (new_insn))
4096 : return NULL;
4097 :
4098 : /* We have a 1-1 replacement. Copy over any frame-related info. */
4099 137212 : copy_frame_info_to_split_insn (old_insn, new_insn);
4100 : }
4101 :
4102 : /* If we are splitting a CALL_INSN, look for the CALL_INSN
4103 : in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
4104 : cfg-related call notes. */
4105 4853245 : for (i = 0; i <= match_len; ++i)
4106 : {
4107 2541537 : int j;
4108 2541537 : rtx note;
4109 :
4110 2541537 : j = peep2_buf_position (peep2_current + i);
4111 2541537 : old_insn = peep2_insn_data[j].insn;
4112 2541537 : if (!CALL_P (old_insn))
4113 2540002 : continue;
4114 1535 : was_call = true;
4115 :
4116 : new_insn = attempt;
4117 1535 : while (new_insn != NULL_RTX)
4118 : {
4119 1535 : if (CALL_P (new_insn))
4120 : break;
4121 0 : new_insn = NEXT_INSN (new_insn);
4122 : }
4123 :
4124 1535 : gcc_assert (new_insn != NULL_RTX);
4125 :
4126 1535 : CALL_INSN_FUNCTION_USAGE (new_insn)
4127 1535 : = CALL_INSN_FUNCTION_USAGE (old_insn);
4128 1535 : CALL_INSN_ABI_ID (new_insn) = CALL_INSN_ABI_ID (old_insn);
4129 1535 : SIBLING_CALL_P (new_insn) = SIBLING_CALL_P (old_insn);
4130 :
4131 1535 : for (note = REG_NOTES (old_insn);
4132 6960 : note;
4133 5425 : note = XEXP (note, 1))
4134 5425 : switch (REG_NOTE_KIND (note))
4135 : {
4136 0 : case REG_NORETURN:
4137 0 : case REG_SETJMP:
4138 0 : case REG_TM:
4139 0 : case REG_CALL_NOCF_CHECK:
4140 0 : add_reg_note (new_insn, REG_NOTE_KIND (note),
4141 : XEXP (note, 0));
4142 0 : break;
4143 : default:
4144 : /* Discard all other reg notes. */
4145 : break;
4146 : }
4147 :
4148 : /* Croak if there is another call in the sequence. */
4149 1535 : while (++i <= match_len)
4150 : {
4151 0 : j = peep2_buf_position (peep2_current + i);
4152 0 : old_insn = peep2_insn_data[j].insn;
4153 0 : gcc_assert (!CALL_P (old_insn));
4154 : }
4155 : break;
4156 : }
4157 :
4158 : /* If we matched any instruction that had a REG_ARGS_SIZE, then
4159 : move those notes over to the new sequence. */
4160 2313243 : as_note = NULL;
4161 4734834 : for (i = match_len; i >= 0; --i)
4162 : {
4163 2541537 : int j = peep2_buf_position (peep2_current + i);
4164 2541537 : old_insn = peep2_insn_data[j].insn;
4165 :
4166 2541537 : as_note = find_reg_note (old_insn, REG_ARGS_SIZE, NULL);
4167 2541537 : if (as_note)
4168 : break;
4169 : }
4170 :
4171 2313243 : i = peep2_buf_position (peep2_current + match_len);
4172 2313243 : eh_note = find_reg_note (peep2_insn_data[i].insn, REG_EH_REGION, NULL_RTX);
4173 :
4174 : /* Replace the old sequence with the new. */
4175 2313243 : rtx_insn *peepinsn = peep2_insn_data[i].insn;
4176 2313243 : last = emit_insn_after_setloc (attempt,
4177 : peep2_insn_data[i].insn,
4178 : peepinsn->location ());
4179 2313243 : if (JUMP_P (peepinsn) && JUMP_P (last))
4180 832 : set_crossing_jump (last, CROSSING_JUMP_P (peepinsn));
4181 2313243 : before_try = PREV_INSN (insn);
4182 2313243 : delete_insn_chain (insn, peep2_insn_data[i].insn, false);
4183 :
4184 : /* Re-insert the EH_REGION notes. */
4185 2313243 : if (eh_note || (was_call && nonlocal_goto_handler_labels))
4186 : {
4187 36 : edge eh_edge;
4188 36 : edge_iterator ei;
4189 :
4190 44 : FOR_EACH_EDGE (eh_edge, ei, bb->succs)
4191 43 : if (eh_edge->flags & (EDGE_EH | EDGE_ABNORMAL_CALL))
4192 : break;
4193 :
4194 36 : if (eh_note)
4195 36 : copy_reg_eh_region_note_backward (eh_note, last, before_try);
4196 :
4197 36 : if (eh_edge)
4198 105 : for (x = last; x != before_try; x = PREV_INSN (x))
4199 70 : if (x != BB_END (bb)
4200 70 : && (can_throw_internal (x)
4201 35 : || can_nonlocal_goto (x)))
4202 : {
4203 0 : edge nfte, nehe;
4204 0 : int flags;
4205 :
4206 0 : nfte = split_block (bb, x);
4207 0 : flags = (eh_edge->flags
4208 : & (EDGE_EH | EDGE_ABNORMAL));
4209 0 : if (CALL_P (x))
4210 0 : flags |= EDGE_ABNORMAL_CALL;
4211 0 : nehe = make_edge (nfte->src, eh_edge->dest,
4212 : flags);
4213 :
4214 0 : nehe->probability = eh_edge->probability;
4215 0 : nfte->probability = nehe->probability.invert ();
4216 :
4217 0 : peep2_do_cleanup_cfg |= purge_dead_edges (nfte->dest);
4218 0 : bb = nfte->src;
4219 0 : eh_edge = nehe;
4220 : }
4221 :
4222 : /* Converting possibly trapping insn to non-trapping is
4223 : possible. Zap dummy outgoing edges. */
4224 36 : peep2_do_cleanup_cfg |= purge_dead_edges (bb);
4225 : }
4226 :
4227 : /* Re-insert the ARGS_SIZE notes. */
4228 2313243 : if (as_note)
4229 119946 : fixup_args_size_notes (before_try, last, get_args_size (as_note));
4230 :
4231 : /* Scan the new insns for embedded side effects and add appropriate
4232 : REG_INC notes. */
4233 2313243 : if (AUTO_INC_DEC)
4234 : for (x = last; x != before_try; x = PREV_INSN (x))
4235 : if (NONDEBUG_INSN_P (x))
4236 : add_auto_inc_notes (x, PATTERN (x));
4237 :
4238 : /* If we generated a jump instruction, it won't have
4239 : JUMP_LABEL set. Recompute after we're done. */
4240 5386816 : for (x = last; x != before_try; x = PREV_INSN (x))
4241 3074405 : if (JUMP_P (x))
4242 : {
4243 832 : peep2_do_rebuild_jump_labels = true;
4244 832 : break;
4245 : }
4246 :
4247 : return last;
4248 : }
4249 :
4250 : /* After performing a replacement in basic block BB, fix up the life
4251 : information in our buffer. LAST is the last of the insns that we
4252 : emitted as a replacement. PREV is the insn before the start of
4253 : the replacement. MATCH_LEN + 1 is the number of instructions that were
4254 : matched, and which now need to be replaced in the buffer. */
4255 :
4256 : static void
4257 2313243 : peep2_update_life (basic_block bb, int match_len, rtx_insn *last,
4258 : rtx_insn *prev)
4259 : {
4260 2313243 : int i = peep2_buf_position (peep2_current + match_len + 1);
4261 2313243 : rtx_insn *x;
4262 2313243 : regset_head live;
4263 :
4264 2313243 : INIT_REG_SET (&live);
4265 2313243 : COPY_REG_SET (&live, peep2_insn_data[i].live_before);
4266 :
4267 2313243 : gcc_assert (peep2_current_count >= match_len + 1);
4268 2313243 : peep2_current_count -= match_len + 1;
4269 :
4270 2313243 : x = last;
4271 3075131 : do
4272 : {
4273 3075131 : if (INSN_P (x))
4274 : {
4275 3075131 : df_insn_rescan (x);
4276 3075131 : if (peep2_current_count < MAX_INSNS_PER_PEEP2)
4277 : {
4278 2925232 : peep2_current_count++;
4279 2925232 : if (--i < 0)
4280 823964 : i = MAX_INSNS_PER_PEEP2;
4281 2925232 : peep2_insn_data[i].insn = x;
4282 2925232 : df_simulate_one_insn_backwards (bb, x, &live);
4283 2925232 : COPY_REG_SET (peep2_insn_data[i].live_before, &live);
4284 : }
4285 : }
4286 3075131 : x = PREV_INSN (x);
4287 : }
4288 3075131 : while (x != prev);
4289 2313243 : CLEAR_REG_SET (&live);
4290 :
4291 2313243 : peep2_current = i;
4292 2313243 : }
4293 :
4294 : /* Add INSN, which is in BB, at the end of the peep2 insn buffer if possible.
4295 : Return true if we added it, false otherwise. The caller will try to match
4296 : peepholes against the buffer if we return false; otherwise it will try to
4297 : add more instructions to the buffer. */
4298 :
4299 : static bool
4300 84996164 : peep2_fill_buffer (basic_block bb, rtx_insn *insn, regset live)
4301 : {
4302 84996164 : int pos;
4303 :
4304 : /* Once we have filled the maximum number of insns the buffer can hold,
4305 : allow the caller to match the insns against peepholes. We wait until
4306 : the buffer is full in case the target has similar peepholes of different
4307 : length; we always want to match the longest if possible. */
4308 84996164 : if (peep2_current_count == MAX_INSNS_PER_PEEP2)
4309 : return false;
4310 :
4311 : /* If an insn has RTX_FRAME_RELATED_P set, do not allow it to be matched with
4312 : any other pattern, lest it change the semantics of the frame info. */
4313 65361495 : if (RTX_FRAME_RELATED_P (insn))
4314 : {
4315 : /* Let the buffer drain first. */
4316 7812617 : if (peep2_current_count > 0)
4317 : return false;
4318 : /* Now the insn will be the only thing in the buffer. */
4319 : }
4320 :
4321 61022521 : pos = peep2_buf_position (peep2_current + peep2_current_count);
4322 61022521 : peep2_insn_data[pos].insn = insn;
4323 61022521 : COPY_REG_SET (peep2_insn_data[pos].live_before, live);
4324 61022521 : peep2_current_count++;
4325 :
4326 61022521 : df_simulate_one_insn_forwards (bb, insn, live);
4327 61022521 : return true;
4328 : }
4329 :
4330 : /* Perform the peephole2 optimization pass. */
4331 :
4332 : static void
4333 987489 : peephole2_optimize (void)
4334 : {
4335 987489 : rtx_insn *insn;
4336 987489 : bitmap live;
4337 987489 : int i;
4338 987489 : basic_block bb;
4339 :
4340 987489 : peep2_do_cleanup_cfg = false;
4341 987489 : peep2_do_rebuild_jump_labels = false;
4342 :
4343 987489 : df_set_flags (DF_LR_RUN_DCE);
4344 987489 : df_note_add_problem ();
4345 987489 : df_analyze ();
4346 :
4347 : /* Initialize the regsets we're going to use. */
4348 8887401 : for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
4349 6912423 : peep2_insn_data[i].live_before = BITMAP_ALLOC (®_obstack);
4350 987489 : search_ofs = 0;
4351 987489 : live = BITMAP_ALLOC (®_obstack);
4352 :
4353 12063628 : FOR_EACH_BB_REVERSE_FN (bb, cfun)
4354 : {
4355 11076139 : bool past_end = false;
4356 11076139 : int pos;
4357 :
4358 11076139 : rtl_profile_for_bb (bb);
4359 :
4360 : /* Start up propagation. */
4361 22152278 : bitmap_copy (live, DF_LR_IN (bb));
4362 11076139 : df_simulate_initialize_forwards (bb, live);
4363 11076139 : peep2_reinit_state (live);
4364 :
4365 11076139 : insn = BB_HEAD (bb);
4366 211713862 : for (;;)
4367 : {
4368 211713862 : rtx_insn *attempt, *head;
4369 211713862 : int match_len;
4370 :
4371 211713862 : if (!past_end && !NONDEBUG_INSN_P (insn))
4372 : {
4373 75895743 : next_insn:
4374 136918264 : insn = NEXT_INSN (insn);
4375 136918264 : if (insn == NEXT_INSN (BB_END (bb)))
4376 11076139 : past_end = true;
4377 139231507 : continue;
4378 : }
4379 84996164 : if (!past_end && peep2_fill_buffer (bb, insn, live))
4380 61022521 : goto next_insn;
4381 :
4382 : /* If we did not fill an empty buffer, it signals the end of the
4383 : block. */
4384 74795598 : if (peep2_current_count == 0)
4385 : break;
4386 :
4387 : /* The buffer filled to the current maximum, so try to match. */
4388 :
4389 63719459 : pos = peep2_buf_position (peep2_current + peep2_current_count);
4390 63719459 : peep2_insn_data[pos].insn = PEEP2_EOB;
4391 63719459 : COPY_REG_SET (peep2_insn_data[pos].live_before, live);
4392 :
4393 : /* Match the peephole. */
4394 63719459 : head = peep2_insn_data[peep2_current].insn;
4395 63719459 : attempt = peephole2_insns (PATTERN (head), head, &match_len);
4396 63719459 : if (attempt != NULL)
4397 : {
4398 2316078 : rtx_insn *last = peep2_attempt (bb, head, match_len, attempt);
4399 2316078 : if (last)
4400 : {
4401 2313243 : peep2_update_life (bb, match_len, last, PREV_INSN (attempt));
4402 2313243 : continue;
4403 : }
4404 : }
4405 :
4406 : /* No match: advance the buffer by one insn. */
4407 61406216 : peep2_current = peep2_buf_position (peep2_current + 1);
4408 61406216 : peep2_current_count--;
4409 : }
4410 : }
4411 :
4412 987489 : default_rtl_profile ();
4413 8887401 : for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
4414 6912423 : BITMAP_FREE (peep2_insn_data[i].live_before);
4415 987489 : BITMAP_FREE (live);
4416 987489 : if (peep2_do_rebuild_jump_labels)
4417 746 : rebuild_jump_labels (get_insns ());
4418 987489 : if (peep2_do_cleanup_cfg)
4419 0 : cleanup_cfg (CLEANUP_CFG_CHANGED);
4420 987489 : }
4421 :
4422 : /* Common predicates for use with define_bypass. */
4423 :
4424 : /* Helper function for store_data_bypass_p, handle just a single SET
4425 : IN_SET. */
4426 :
4427 : static bool
4428 0 : store_data_bypass_p_1 (rtx_insn *out_insn, rtx in_set)
4429 : {
4430 0 : if (!MEM_P (SET_DEST (in_set)))
4431 : return false;
4432 :
4433 0 : rtx out_set = single_set (out_insn);
4434 0 : if (out_set)
4435 0 : return !reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_set));
4436 :
4437 0 : rtx out_pat = PATTERN (out_insn);
4438 0 : if (GET_CODE (out_pat) != PARALLEL)
4439 : return false;
4440 :
4441 0 : for (int i = 0; i < XVECLEN (out_pat, 0); i++)
4442 : {
4443 0 : rtx out_exp = XVECEXP (out_pat, 0, i);
4444 :
4445 0 : if (GET_CODE (out_exp) == CLOBBER || GET_CODE (out_exp) == USE)
4446 0 : continue;
4447 :
4448 0 : gcc_assert (GET_CODE (out_exp) == SET);
4449 :
4450 0 : if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_set)))
4451 : return false;
4452 : }
4453 :
4454 : return true;
4455 : }
4456 :
4457 : /* True if the dependency between OUT_INSN and IN_INSN is on the store
4458 : data not the address operand(s) of the store. IN_INSN and OUT_INSN
4459 : must be either a single_set or a PARALLEL with SETs inside. */
4460 :
4461 : bool
4462 0 : store_data_bypass_p (rtx_insn *out_insn, rtx_insn *in_insn)
4463 : {
4464 0 : rtx in_set = single_set (in_insn);
4465 0 : if (in_set)
4466 0 : return store_data_bypass_p_1 (out_insn, in_set);
4467 :
4468 0 : rtx in_pat = PATTERN (in_insn);
4469 0 : if (GET_CODE (in_pat) != PARALLEL)
4470 : return false;
4471 :
4472 0 : for (int i = 0; i < XVECLEN (in_pat, 0); i++)
4473 : {
4474 0 : rtx in_exp = XVECEXP (in_pat, 0, i);
4475 :
4476 0 : if (GET_CODE (in_exp) == CLOBBER || GET_CODE (in_exp) == USE)
4477 0 : continue;
4478 :
4479 0 : gcc_assert (GET_CODE (in_exp) == SET);
4480 :
4481 0 : if (!store_data_bypass_p_1 (out_insn, in_exp))
4482 : return false;
4483 : }
4484 :
4485 : return true;
4486 : }
4487 :
4488 : /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
4489 : condition, and not the THEN or ELSE branch. OUT_INSN may be either a single
4490 : or multiple set; IN_INSN should be single_set for truth, but for convenience
4491 : of insn categorization may be any JUMP or CALL insn. */
4492 :
4493 : bool
4494 0 : if_test_bypass_p (rtx_insn *out_insn, rtx_insn *in_insn)
4495 : {
4496 0 : rtx out_set, in_set;
4497 :
4498 0 : in_set = single_set (in_insn);
4499 0 : if (! in_set)
4500 : {
4501 0 : gcc_assert (JUMP_P (in_insn) || CALL_P (in_insn));
4502 : return false;
4503 : }
4504 :
4505 0 : if (GET_CODE (SET_SRC (in_set)) != IF_THEN_ELSE)
4506 : return false;
4507 0 : in_set = SET_SRC (in_set);
4508 :
4509 0 : out_set = single_set (out_insn);
4510 0 : if (out_set)
4511 : {
4512 0 : if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
4513 0 : || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
4514 0 : return false;
4515 : }
4516 : else
4517 : {
4518 0 : rtx out_pat;
4519 0 : int i;
4520 :
4521 0 : out_pat = PATTERN (out_insn);
4522 0 : gcc_assert (GET_CODE (out_pat) == PARALLEL);
4523 :
4524 0 : for (i = 0; i < XVECLEN (out_pat, 0); i++)
4525 : {
4526 0 : rtx exp = XVECEXP (out_pat, 0, i);
4527 :
4528 0 : if (GET_CODE (exp) == CLOBBER)
4529 0 : continue;
4530 :
4531 0 : gcc_assert (GET_CODE (exp) == SET);
4532 :
4533 0 : if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
4534 0 : || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
4535 : return false;
4536 : }
4537 : }
4538 :
4539 : return true;
4540 : }
4541 :
4542 : static unsigned int
4543 987489 : rest_of_handle_peephole2 (void)
4544 : {
4545 987489 : if (HAVE_peephole2)
4546 0 : peephole2_optimize ();
4547 :
4548 987489 : return 0;
4549 : }
4550 :
4551 : namespace {
4552 :
4553 : const pass_data pass_data_peephole2 =
4554 : {
4555 : RTL_PASS, /* type */
4556 : "peephole2", /* name */
4557 : OPTGROUP_NONE, /* optinfo_flags */
4558 : TV_PEEPHOLE2, /* tv_id */
4559 : 0, /* properties_required */
4560 : 0, /* properties_provided */
4561 : 0, /* properties_destroyed */
4562 : 0, /* todo_flags_start */
4563 : TODO_df_finish, /* todo_flags_finish */
4564 : };
4565 :
4566 : class pass_peephole2 : public rtl_opt_pass
4567 : {
4568 : public:
4569 302985 : pass_peephole2 (gcc::context *ctxt)
4570 605970 : : rtl_opt_pass (pass_data_peephole2, ctxt)
4571 : {}
4572 :
4573 : /* opt_pass methods: */
4574 : /* The epiphany backend creates a second instance of this pass, so we need
4575 : a clone method. */
4576 0 : opt_pass * clone () final override { return new pass_peephole2 (m_ctxt); }
4577 1531131 : bool gate (function *) final override
4578 : {
4579 1531131 : return (optimize > 0 && flag_peephole2);
4580 : }
4581 987489 : unsigned int execute (function *) final override
4582 : {
4583 987489 : return rest_of_handle_peephole2 ();
4584 : }
4585 :
4586 : }; // class pass_peephole2
4587 :
4588 : } // anon namespace
4589 :
4590 : rtl_opt_pass *
4591 302985 : make_pass_peephole2 (gcc::context *ctxt)
4592 : {
4593 302985 : return new pass_peephole2 (ctxt);
4594 : }
4595 :
4596 : namespace {
4597 :
4598 : const pass_data pass_data_split_all_insns =
4599 : {
4600 : RTL_PASS, /* type */
4601 : "split1", /* name */
4602 : OPTGROUP_NONE, /* optinfo_flags */
4603 : TV_NONE, /* tv_id */
4604 : 0, /* properties_required */
4605 : PROP_rtl_split_insns, /* properties_provided */
4606 : 0, /* properties_destroyed */
4607 : 0, /* todo_flags_start */
4608 : 0, /* todo_flags_finish */
4609 : };
4610 :
4611 : class pass_split_all_insns : public rtl_opt_pass
4612 : {
4613 : public:
4614 302985 : pass_split_all_insns (gcc::context *ctxt)
4615 605970 : : rtl_opt_pass (pass_data_split_all_insns, ctxt)
4616 : {}
4617 :
4618 : /* opt_pass methods: */
4619 : /* The epiphany backend creates a second instance of this pass, so
4620 : we need a clone method. */
4621 0 : opt_pass * clone () final override
4622 : {
4623 0 : return new pass_split_all_insns (m_ctxt);
4624 : }
4625 1531121 : unsigned int execute (function *) final override
4626 : {
4627 1531121 : split_all_insns ();
4628 1531121 : return 0;
4629 : }
4630 :
4631 : }; // class pass_split_all_insns
4632 :
4633 : } // anon namespace
4634 :
4635 : rtl_opt_pass *
4636 302985 : make_pass_split_all_insns (gcc::context *ctxt)
4637 : {
4638 302985 : return new pass_split_all_insns (ctxt);
4639 : }
4640 :
4641 : namespace {
4642 :
4643 : const pass_data pass_data_split_after_reload =
4644 : {
4645 : RTL_PASS, /* type */
4646 : "split2", /* name */
4647 : OPTGROUP_NONE, /* optinfo_flags */
4648 : TV_NONE, /* tv_id */
4649 : 0, /* properties_required */
4650 : 0, /* properties_provided */
4651 : 0, /* properties_destroyed */
4652 : 0, /* todo_flags_start */
4653 : 0, /* todo_flags_finish */
4654 : };
4655 :
4656 : class pass_split_after_reload : public rtl_opt_pass
4657 : {
4658 : public:
4659 302985 : pass_split_after_reload (gcc::context *ctxt)
4660 605970 : : rtl_opt_pass (pass_data_split_after_reload, ctxt)
4661 : {}
4662 :
4663 : /* opt_pass methods: */
4664 1531131 : bool gate (function *) final override
4665 : {
4666 : /* If optimizing, then go ahead and split insns now. */
4667 1531131 : return optimize > 0;
4668 : }
4669 :
4670 1070228 : unsigned int execute (function *) final override
4671 : {
4672 1070228 : split_all_insns ();
4673 1070228 : return 0;
4674 : }
4675 :
4676 : }; // class pass_split_after_reload
4677 :
4678 : } // anon namespace
4679 :
4680 : rtl_opt_pass *
4681 302985 : make_pass_split_after_reload (gcc::context *ctxt)
4682 : {
4683 302985 : return new pass_split_after_reload (ctxt);
4684 : }
4685 :
4686 : static bool
4687 3062262 : enable_split_before_sched2 (void)
4688 : {
4689 : #ifdef INSN_SCHEDULING
4690 2140458 : return optimize > 0 && flag_schedule_insns_after_reload;
4691 : #else
4692 : return false;
4693 : #endif
4694 : }
4695 :
4696 : namespace {
4697 :
4698 : const pass_data pass_data_split_before_sched2 =
4699 : {
4700 : RTL_PASS, /* type */
4701 : "split3", /* name */
4702 : OPTGROUP_NONE, /* optinfo_flags */
4703 : TV_NONE, /* tv_id */
4704 : 0, /* properties_required */
4705 : 0, /* properties_provided */
4706 : 0, /* properties_destroyed */
4707 : 0, /* todo_flags_start */
4708 : 0, /* todo_flags_finish */
4709 : };
4710 :
4711 : class pass_split_before_sched2 : public rtl_opt_pass
4712 : {
4713 : public:
4714 302985 : pass_split_before_sched2 (gcc::context *ctxt)
4715 605970 : : rtl_opt_pass (pass_data_split_before_sched2, ctxt)
4716 : {}
4717 :
4718 : /* opt_pass methods: */
4719 1531131 : bool gate (function *) final override
4720 : {
4721 1531131 : return enable_split_before_sched2 ();
4722 : }
4723 :
4724 987482 : unsigned int execute (function *) final override
4725 : {
4726 987482 : split_all_insns ();
4727 987482 : return 0;
4728 : }
4729 :
4730 : }; // class pass_split_before_sched2
4731 :
4732 : } // anon namespace
4733 :
4734 : rtl_opt_pass *
4735 302985 : make_pass_split_before_sched2 (gcc::context *ctxt)
4736 : {
4737 302985 : return new pass_split_before_sched2 (ctxt);
4738 : }
4739 :
4740 : namespace {
4741 :
4742 : const pass_data pass_data_split_before_regstack =
4743 : {
4744 : RTL_PASS, /* type */
4745 : "split4", /* name */
4746 : OPTGROUP_NONE, /* optinfo_flags */
4747 : TV_NONE, /* tv_id */
4748 : 0, /* properties_required */
4749 : 0, /* properties_provided */
4750 : 0, /* properties_destroyed */
4751 : 0, /* todo_flags_start */
4752 : 0, /* todo_flags_finish */
4753 : };
4754 :
4755 : class pass_split_before_regstack : public rtl_opt_pass
4756 : {
4757 : public:
4758 302985 : pass_split_before_regstack (gcc::context *ctxt)
4759 605970 : : rtl_opt_pass (pass_data_split_before_regstack, ctxt)
4760 : {}
4761 :
4762 : /* opt_pass methods: */
4763 : bool gate (function *) final override;
4764 543729 : unsigned int execute (function *) final override
4765 : {
4766 543729 : split_all_insns ();
4767 543729 : return 0;
4768 : }
4769 :
4770 : }; // class pass_split_before_regstack
4771 :
4772 : bool
4773 1531131 : pass_split_before_regstack::gate (function *)
4774 : {
4775 : #if HAVE_ATTR_length && defined (STACK_REGS)
4776 : /* If flow2 creates new instructions which need splitting
4777 : and scheduling after reload is not done, they might not be
4778 : split until final which doesn't allow splitting
4779 : if HAVE_ATTR_length. Selective scheduling can result in
4780 : further instructions that need splitting. */
4781 : #ifdef INSN_SCHEDULING
4782 2518614 : return !enable_split_before_sched2 () || flag_selective_scheduling2;
4783 : #else
4784 : return !enable_split_before_sched2 ();
4785 : #endif
4786 : #else
4787 : return false;
4788 : #endif
4789 : }
4790 :
4791 : } // anon namespace
4792 :
4793 : rtl_opt_pass *
4794 302985 : make_pass_split_before_regstack (gcc::context *ctxt)
4795 : {
4796 302985 : return new pass_split_before_regstack (ctxt);
4797 : }
4798 :
4799 : namespace {
4800 :
4801 : const pass_data pass_data_split_for_shorten_branches =
4802 : {
4803 : RTL_PASS, /* type */
4804 : "split5", /* name */
4805 : OPTGROUP_NONE, /* optinfo_flags */
4806 : TV_NONE, /* tv_id */
4807 : 0, /* properties_required */
4808 : 0, /* properties_provided */
4809 : 0, /* properties_destroyed */
4810 : 0, /* todo_flags_start */
4811 : 0, /* todo_flags_finish */
4812 : };
4813 :
4814 : class pass_split_for_shorten_branches : public rtl_opt_pass
4815 : {
4816 : public:
4817 302985 : pass_split_for_shorten_branches (gcc::context *ctxt)
4818 605970 : : rtl_opt_pass (pass_data_split_for_shorten_branches, ctxt)
4819 : {}
4820 :
4821 : /* opt_pass methods: */
4822 1531131 : bool gate (function *) final override
4823 : {
4824 : /* The placement of the splitting that we do for shorten_branches
4825 : depends on whether regstack is used by the target or not. */
4826 : #if HAVE_ATTR_length && !defined (STACK_REGS)
4827 : return true;
4828 : #else
4829 1531131 : return false;
4830 : #endif
4831 : }
4832 :
4833 0 : unsigned int execute (function *) final override
4834 : {
4835 0 : split_all_insns_noflow ();
4836 0 : return 0;
4837 : }
4838 :
4839 : }; // class pass_split_for_shorten_branches
4840 :
4841 : } // anon namespace
4842 :
4843 : rtl_opt_pass *
4844 302985 : make_pass_split_for_shorten_branches (gcc::context *ctxt)
4845 : {
4846 302985 : return new pass_split_for_shorten_branches (ctxt);
4847 : }
4848 :
4849 : /* (Re)initialize the target information after a change in target. */
4850 :
4851 : void
4852 226153 : recog_init ()
4853 : {
4854 : /* The information is zero-initialized, so we don't need to do anything
4855 : first time round. */
4856 226153 : if (!this_target_recog->x_initialized)
4857 : {
4858 225084 : this_target_recog->x_initialized = true;
4859 225084 : return;
4860 : }
4861 1069 : memset (this_target_recog->x_bool_attr_masks, 0,
4862 : sizeof (this_target_recog->x_bool_attr_masks));
4863 15075038 : for (unsigned int i = 0; i < NUM_INSN_CODES; ++i)
4864 15073969 : if (this_target_recog->x_op_alt[i])
4865 : {
4866 10036 : free (this_target_recog->x_op_alt[i]);
4867 10036 : this_target_recog->x_op_alt[i] = 0;
4868 : }
4869 : }
|