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 7986687 : init_recog_no_volatile (void)
111 : {
112 7986687 : volatile_ok = 0;
113 7986687 : }
114 :
115 : void
116 11880913 : init_recog (void)
117 : {
118 11880913 : volatile_ok = 1;
119 11880913 : }
120 :
121 :
122 : /* Return true if labels in asm operands BODY are LABEL_REFs. */
123 :
124 : static bool
125 108084107 : asm_labels_ok (rtx body)
126 : {
127 108084107 : rtx asmop;
128 108084107 : int i;
129 :
130 108084107 : asmop = extract_asm_operands (body);
131 108084107 : if (asmop == NULL_RTX)
132 : return true;
133 :
134 823861 : for (i = 0; i < ASM_OPERANDS_LABEL_LENGTH (asmop); i++)
135 7640 : 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 108084107 : check_asm_operands (rtx x)
146 : {
147 108084107 : int noperands;
148 108084107 : rtx *operands;
149 108084107 : const char **constraints;
150 108084107 : int i;
151 :
152 108084107 : if (!asm_labels_ok (x))
153 : return false;
154 :
155 : /* Post-reload, be more strict with things. */
156 108084107 : if (reload_completed)
157 : {
158 : /* ??? Doh! We've not got the wrapping insn. Cook one up. */
159 29273 : rtx_insn *insn = make_insn_raw (x);
160 29273 : extract_insn (insn);
161 29273 : constrain_operands (1, get_enabled_alternatives (insn));
162 29273 : return which_alternative >= 0;
163 : }
164 :
165 108054834 : noperands = asm_noperands (x);
166 108054834 : if (noperands < 0)
167 : return false;
168 771164 : if (noperands == 0)
169 : return true;
170 :
171 671833 : operands = XALLOCAVEC (rtx, noperands);
172 671833 : constraints = XALLOCAVEC (const char *, noperands);
173 :
174 671833 : decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
175 :
176 3923474 : for (i = 0; i < noperands; i++)
177 : {
178 2872704 : const char *c = constraints[i];
179 2872704 : if (c[0] == '%')
180 12333 : c++;
181 2872704 : 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 1841231353 : validate_change_1 (rtx object, rtx *loc, rtx new_rtx, bool in_group,
228 : bool unshare, int new_len = -1)
229 : {
230 1841231353 : gcc_assert (!undo_recog_changes::is_active ());
231 1841231353 : rtx old = *loc;
232 :
233 : /* Single-element parallels aren't valid and won't match anything.
234 : Replace them with the single element. */
235 1841231353 : if (new_len == 1 && GET_CODE (new_rtx) == PARALLEL)
236 : {
237 6505644 : new_rtx = XVECEXP (new_rtx, 0, 0);
238 6505644 : 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 1841231353 : if (!in_group
246 214258061 : && (old == new_rtx || rtx_equal_p (old, new_rtx))
247 2036872120 : && (new_len < 0 || XVECLEN (new_rtx, 0) == new_len))
248 : return true;
249 :
250 1645590586 : gcc_assert ((in_group != 0 || num_changes == 0)
251 : && (new_len < 0 || new_rtx == *loc));
252 :
253 1645590586 : *loc = new_rtx;
254 :
255 : /* Save the information describing this change. */
256 1645590586 : if (num_changes >= changes_allocated)
257 : {
258 177426 : 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 1235 : changes_allocated *= 2;
264 :
265 177426 : changes = XRESIZEVEC (change_t, changes, changes_allocated);
266 : }
267 :
268 1645590586 : changes[num_changes].object = object;
269 1645590586 : changes[num_changes].loc = loc;
270 1645590586 : changes[num_changes].old = old;
271 1645590586 : changes[num_changes].old_len = (new_len >= 0 ? XVECLEN (new_rtx, 0) : -1);
272 1645590586 : changes[num_changes].unshare = unshare;
273 :
274 1645590586 : if (new_len >= 0)
275 11769324 : XVECLEN (new_rtx, 0) = new_len;
276 :
277 1645590586 : if (object && !MEM_P (object))
278 : {
279 : /* Set INSN_CODE to force rerecognition of insn. Save old code in
280 : case invalid. */
281 1620964848 : changes[num_changes].old_code = INSN_CODE (object);
282 1620964848 : INSN_CODE (object) = -1;
283 : }
284 :
285 1645590586 : num_changes++;
286 :
287 : /* If we are making a group of changes, return 1. Otherwise, validate the
288 : change group we made. */
289 :
290 1645590586 : if (in_group)
291 : return true;
292 : else
293 18617294 : 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 1529996311 : validate_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
301 : {
302 1529996311 : 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 292960074 : validate_unshare_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
310 : {
311 292960074 : 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 18274968 : validate_change_xveclen (rtx object, rtx *loc, int new_len, bool in_group)
319 : {
320 18274968 : 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 1872122 : canonicalize_change_group (rtx_insn *insn, rtx x)
330 : {
331 1872122 : if (COMMUTATIVE_P (x)
332 1872122 : && 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 104824 : rtx tem = XEXP (x, 0);
337 104824 : validate_unshare_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
338 104824 : validate_unshare_change (insn, &XEXP (x, 1), tem, 1);
339 104824 : 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 477570421 : insn_invalid_p (rtx_insn *insn, bool in_group)
366 : {
367 477570421 : rtx pat = PATTERN (insn);
368 477570421 : int num_clobbers = 0;
369 : /* If we are before reload and the pattern is a SET, see if we can add
370 : clobbers. */
371 477570421 : int icode = recog (pat, insn,
372 477570421 : (GET_CODE (pat) == SET
373 394826140 : && ! reload_completed
374 374918195 : && ! reload_in_progress)
375 : ? &num_clobbers : 0);
376 477570421 : 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 581054 : if ((is_asm && ! check_asm_operands (PATTERN (insn)))
382 477362501 : || (!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 459459689 : if (num_clobbers > 0)
389 : {
390 1976 : rtx newpat;
391 :
392 1976 : if (added_clobbers_hard_reg_p (icode))
393 : return true;
394 :
395 625 : newpat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_clobbers + 1));
396 625 : XVECEXP (newpat, 0, 0) = pat;
397 625 : add_clobbers (newpat, icode);
398 625 : if (in_group)
399 624 : 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 459458338 : if (reload_completed)
406 : {
407 19850245 : extract_insn (insn);
408 :
409 19850245 : if (! constrain_operands (1, get_preferred_alternatives (insn)))
410 : return true;
411 : }
412 :
413 : /* Punt if REG_INC argument overlaps some stored REG. */
414 459441274 : for (rtx link = FIND_REG_INC_NOTE (insn, NULL_RTX);
415 459441274 : 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 459441274 : INSN_CODE (insn) = icode;
425 459441274 : return false;
426 : }
427 :
428 : /* Return number of changes made and not validated yet. */
429 : int
430 4922407 : num_changes_pending (void)
431 : {
432 4922407 : 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 784820134 : verify_changes (int num)
440 : {
441 784820134 : int i;
442 784820134 : 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 2291367416 : for (i = num; i < num_changes; i++)
454 : {
455 1521420816 : 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 1521420816 : if (object == 0 || object == last_validated)
460 777223241 : continue;
461 :
462 744197575 : if (MEM_P (object))
463 : {
464 36806 : if (! memory_address_addr_space_p (GET_MODE (object),
465 : XEXP (object, 0),
466 18403 : MEM_ADDR_SPACE (object)))
467 : break;
468 : }
469 744179172 : else if (/* changes[i].old might be zero, e.g. when putting a
470 : REG_FRAME_RELATED_EXPR into a previously empty list. */
471 744179172 : changes[i].old
472 744179172 : && REG_P (changes[i].old)
473 237373190 : && asm_noperands (PATTERN (object)) > 0
474 744383204 : && 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 744179171 : else if (DEBUG_INSN_P (object))
481 267543201 : continue;
482 476635970 : else if (insn_invalid_p (as_a <rtx_insn *> (object), true))
483 : {
484 17565170 : 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 17565170 : if (GET_CODE (pat) == PARALLEL
492 4153953 : && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
493 20449852 : && asm_noperands (PATTERN (object)) < 0)
494 : {
495 2678422 : rtx newpat;
496 :
497 2678422 : if (XVECLEN (pat, 0) == 2)
498 2266041 : newpat = XVECEXP (pat, 0, 0);
499 : else
500 : {
501 412381 : int j;
502 :
503 412381 : newpat
504 412381 : = gen_rtx_PARALLEL (VOIDmode,
505 : rtvec_alloc (XVECLEN (pat, 0) - 1));
506 1271696 : for (j = 0; j < XVECLEN (newpat, 0); j++)
507 859315 : 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 2678422 : validate_change (object, &PATTERN (object), newpat, 1);
520 2678422 : continue;
521 2678422 : }
522 14886748 : else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER
523 14873462 : || GET_CODE (pat) == VAR_LOCATION)
524 : /* If this insn is a CLOBBER or USE, it is always valid, but is
525 : never recognized. */
526 13286 : continue;
527 : else
528 : break;
529 : }
530 : last_validated = object;
531 : }
532 :
533 784820134 : 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 781094944 : confirm_change_group (void)
542 : {
543 781094944 : int i;
544 781094944 : rtx last_object = NULL;
545 :
546 781094944 : gcc_assert (!undo_recog_changes::is_active ());
547 2297336652 : for (i = 0; i < num_changes; i++)
548 : {
549 1516241708 : rtx object = changes[i].object;
550 :
551 1516241708 : if (changes[i].unshare)
552 20203904 : *changes[i].loc = copy_rtx (*changes[i].loc);
553 :
554 : /* Avoid unnecessary rescanning when multiple changes to same instruction
555 : are made. */
556 1516241708 : if (object)
557 : {
558 1513902481 : if (object != last_object && last_object && INSN_P (last_object))
559 7730368 : df_insn_rescan (as_a <rtx_insn *> (last_object));
560 : last_object = object;
561 : }
562 : }
563 :
564 781094944 : if (last_object && INSN_P (last_object))
565 613667681 : df_insn_rescan (as_a <rtx_insn *> (last_object));
566 781094944 : num_changes = 0;
567 781094944 : }
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 777558594 : apply_change_group (void)
575 : {
576 777558594 : if (verify_changes (0))
577 : {
578 765481310 : confirm_change_group ();
579 765481310 : return true;
580 : }
581 : else
582 : {
583 12077284 : cancel_changes (0);
584 12077284 : return false;
585 : }
586 : }
587 :
588 :
589 : /* Return the number of changes so far in the current group. */
590 :
591 : int
592 752349197 : num_validated_changes (void)
593 : {
594 752349197 : return num_changes;
595 : }
596 :
597 : /* Retract the changes numbered NUM and up. */
598 :
599 : void
600 171810599 : cancel_changes (int num)
601 : {
602 171810599 : gcc_assert (!undo_recog_changes::is_active ());
603 171810599 : int i;
604 :
605 : /* Back out all the changes. Do this in the opposite order in which
606 : they were made. */
607 301159477 : for (i = num_changes - 1; i >= num; i--)
608 : {
609 129348878 : if (changes[i].old_len >= 0)
610 10880913 : XVECLEN (*changes[i].loc, 0) = changes[i].old_len;
611 : else
612 118467965 : *changes[i].loc = changes[i].old;
613 129348878 : if (changes[i].object && !MEM_P (changes[i].object))
614 : {
615 107080699 : INSN_CODE (changes[i].object) = changes[i].old_code;
616 107080699 : if (recog_data.insn == changes[i].object)
617 184 : recog_data.insn = nullptr;
618 : }
619 : }
620 171810599 : num_changes = num;
621 171810599 : }
622 :
623 : /* Swap the status of change NUM from being applied to not being applied,
624 : or vice versa. */
625 :
626 : static void
627 48272068 : swap_change (int num)
628 : {
629 48272068 : if (changes[num].old_len >= 0)
630 2213710 : std::swap (XVECLEN (*changes[num].loc, 0), changes[num].old_len);
631 : else
632 46058358 : std::swap (*changes[num].loc, changes[num].old);
633 48272068 : if (changes[num].object && !MEM_P (changes[num].object))
634 : {
635 48272068 : std::swap (INSN_CODE (changes[num].object), changes[num].old_code);
636 48272068 : if (recog_data.insn == changes[num].object)
637 8 : recog_data.insn = nullptr;
638 : }
639 48272068 : }
640 :
641 28030670 : undo_recog_changes::undo_recog_changes (int num)
642 28030670 : : m_old_num_changes (s_num_changes)
643 : {
644 28030670 : gcc_assert (num <= num_changes - s_num_changes);
645 52166704 : for (int i = num_changes - s_num_changes - 1; i >= num; i--)
646 24136034 : swap_change (i);
647 28030670 : s_num_changes = num_changes - num;
648 28030670 : }
649 :
650 28030670 : undo_recog_changes::~undo_recog_changes ()
651 : {
652 52166704 : for (int i = num_changes - s_num_changes;
653 52166704 : i < num_changes - m_old_num_changes; ++i)
654 24136034 : swap_change (i);
655 28030670 : s_num_changes = m_old_num_changes;
656 28030670 : }
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 12614301 : simplify_while_replacing (rtx *loc, rtx to, rtx_insn *object,
664 : machine_mode op0_mode)
665 : {
666 12614301 : rtx x = *loc;
667 12614301 : enum rtx_code code = GET_CODE (x);
668 12614301 : rtx new_rtx = NULL_RTX;
669 12614301 : scalar_int_mode is_mode;
670 :
671 12614301 : if (SWAPPABLE_OPERANDS_P (x)
672 12614301 : && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
673 : {
674 464594 : validate_unshare_change (object, loc,
675 464594 : 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 464594 : x = *loc;
680 464594 : code = GET_CODE (x);
681 : }
682 :
683 : /* Canonicalize arithmetics with all constant operands. */
684 12614301 : switch (GET_RTX_CLASS (code))
685 : {
686 826154 : case RTX_UNARY:
687 826154 : if (CONSTANT_P (XEXP (x, 0)))
688 573635 : new_rtx = simplify_unary_operation (code, GET_MODE (x), XEXP (x, 0),
689 : op0_mode);
690 : break;
691 6451842 : case RTX_COMM_ARITH:
692 6451842 : case RTX_BIN_ARITH:
693 6451842 : if (CONSTANT_P (XEXP (x, 0)) && CONSTANT_P (XEXP (x, 1)))
694 310867 : new_rtx = simplify_binary_operation (code, GET_MODE (x), XEXP (x, 0),
695 : XEXP (x, 1));
696 : break;
697 116713 : case RTX_COMPARE:
698 116713 : case RTX_COMM_COMPARE:
699 116713 : if (CONSTANT_P (XEXP (x, 0)) && CONSTANT_P (XEXP (x, 1)))
700 3231 : 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 887733 : if (new_rtx)
707 : {
708 837199 : validate_change (object, loc, new_rtx, 1);
709 837199 : return;
710 : }
711 :
712 11777102 : switch (code)
713 : {
714 2220456 : 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 2220456 : if (CONST_INT_P (XEXP (x, 1)) && XEXP (x, 1) == to)
720 206409 : validate_change (object, loc,
721 : simplify_gen_binary
722 206409 : (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
723 : break;
724 480975 : case MINUS:
725 480975 : if (CONST_SCALAR_INT_P (XEXP (x, 1)))
726 23342 : validate_change (object, loc,
727 : simplify_gen_binary
728 23342 : (PLUS, GET_MODE (x), XEXP (x, 0),
729 : simplify_gen_unary (NEG,
730 : GET_MODE (x), XEXP (x, 1),
731 23342 : GET_MODE (x))), 1);
732 : break;
733 185843 : case ZERO_EXTEND:
734 185843 : case SIGN_EXTEND:
735 185843 : 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 160119 : case SUBREG:
747 : /* All subregs possible to simplify should be simplified. */
748 320238 : new_rtx = simplify_subreg (GET_MODE (x), SUBREG_REG (x), op0_mode,
749 160119 : SUBREG_BYTE (x));
750 :
751 : /* Subregs of VOIDmode operands are incorrect. */
752 160119 : 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 136731 : validate_change (object, loc, new_rtx, 1);
756 : break;
757 5401 : case ZERO_EXTRACT:
758 5401 : 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 5401 : if (MEM_P (XEXP (x, 0))
765 379 : && is_a <scalar_int_mode> (GET_MODE (XEXP (x, 0)), &is_mode)
766 379 : && CONST_INT_P (XEXP (x, 1))
767 379 : && 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 5673 : && !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 70966765 : validate_replace_rtx_1 (rtx *loc, rtx from, rtx to, rtx_insn *object,
818 : bool simplify)
819 : {
820 70966765 : int i, j;
821 70966765 : const char *fmt;
822 70966765 : rtx x = *loc;
823 70966765 : enum rtx_code code;
824 70966765 : machine_mode op0_mode = VOIDmode;
825 70966765 : int prev_changes = num_changes;
826 :
827 70966765 : if (!x)
828 : return;
829 :
830 70966765 : code = GET_CODE (x);
831 70966765 : fmt = GET_RTX_FORMAT (code);
832 70966765 : if (fmt[0] == 'e')
833 24266196 : 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 70966765 : if (x == from
840 54817332 : || (REG_P (x) && REG_P (from)
841 15780143 : && GET_MODE (x) == GET_MODE (from)
842 9286797 : && REGNO (x) == REGNO (from))
843 125784097 : || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
844 9286797 : && rtx_equal_p (x, from)))
845 : {
846 16149433 : validate_unshare_change (object, loc, to, 1);
847 16149433 : 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 54817332 : if (GET_CODE (x) == PARALLEL)
856 : {
857 1431684 : for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
858 : {
859 1054016 : if (j && GET_CODE (XVECEXP (x, 0, j)) == SET
860 31423 : && 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 1053732 : validate_replace_rtx_1 (&XVECEXP (x, 0, j), from, to, object,
871 : simplify);
872 : }
873 : }
874 : else
875 138958010 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
876 : {
877 84518346 : if (fmt[i] == 'e')
878 41512743 : validate_replace_rtx_1 (&XEXP (x, i), from, to, object, simplify);
879 43005603 : else if (fmt[i] == 'E')
880 6555789 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
881 3578204 : 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 54817332 : 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 12614366 : if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
893 9593303 : 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 12614366 : if (simplify)
898 12614301 : 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 2139837 : validate_replace_rtx (rtx from, rtx to, rtx_insn *insn)
917 : {
918 2139837 : validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
919 2139837 : 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 83 : validate_replace_rtx_part_nosimplify (rtx from, rtx to, rtx *where,
938 : rtx_insn *insn)
939 : {
940 83 : validate_replace_rtx_1 (where, from, to, insn, false);
941 83 : 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 22681861 : validate_replace_src_1 (rtx *x, void *data)
969 : {
970 22681861 : struct validate_replace_src_data *d
971 : = (struct validate_replace_src_data *) data;
972 :
973 22681861 : validate_replace_rtx_1 (x, d->from, d->to, d->insn, true);
974 22681861 : }
975 :
976 : /* Try replacing every occurrence of FROM in INSN with TO, avoiding
977 : SET_DESTs. */
978 :
979 : void
980 16149865 : validate_replace_src_group (rtx from, rtx to, rtx_insn *insn)
981 : {
982 16149865 : struct validate_replace_src_data d;
983 :
984 16149865 : d.from = from;
985 16149865 : d.to = to;
986 16149865 : d.insn = insn;
987 16149865 : note_uses (&PATTERN (insn), validate_replace_src_1, &d);
988 16149865 : }
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 24636549 : insn_propagation::apply_to_mem_1 (rtx mem)
1035 : {
1036 24636549 : auto old_num_changes = num_validated_changes ();
1037 24636549 : mem_depth += 1;
1038 24636549 : bool res = apply_to_rvalue_1 (&XEXP (mem, 0));
1039 24636549 : mem_depth -= 1;
1040 24636549 : if (!res)
1041 : return false;
1042 :
1043 24635971 : if (old_num_changes != num_validated_changes ()
1044 7891963 : && should_check_mems
1045 27993762 : && !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 240612558 : insn_propagation::apply_to_rvalue_1 (rtx *loc)
1056 : {
1057 240612558 : rtx x = *loc;
1058 240612558 : enum rtx_code code = GET_CODE (x);
1059 240612558 : machine_mode mode = GET_MODE (x);
1060 :
1061 240612558 : auto old_num_changes = num_validated_changes ();
1062 240612558 : if (from
1063 229481163 : && GET_CODE (x) == GET_CODE (from)
1064 334692332 : && (REG_P (x)
1065 94079774 : ? REGNO (x) == REGNO (from)
1066 24940 : : 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 60541858 : if (REG_P (x)
1071 60517830 : && HARD_REGISTER_P (x)
1072 18423689 : && register_asm_p (x)
1073 60543910 : && asm_noperands (PATTERN (insn)) > 0)
1074 : return false;
1075 :
1076 60539977 : rtx newval = to;
1077 60539977 : if (GET_MODE (x) != GET_MODE (from))
1078 : {
1079 713337 : gcc_assert (REG_P (x) && HARD_REGISTER_P (x));
1080 713337 : if (REG_NREGS (x) != REG_NREGS (from)
1081 713337 : || !REG_CAN_CHANGE_MODE_P (REGNO (x), GET_MODE (from),
1082 : GET_MODE (x)))
1083 368278 : 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 628047 : if (paradoxical_subreg_p (GET_MODE (x), GET_MODE (from))
1091 628047 : && !CONSTANT_P (to))
1092 : return false;
1093 :
1094 608846 : newval = simplify_subreg (GET_MODE (x), to, GET_MODE (from),
1095 : subreg_lowpart_offset (GET_MODE (x),
1096 : GET_MODE (from)));
1097 608846 : 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 348068 : subrtx_iterator::array_type array;
1114 1334456 : FOR_EACH_SUBRTX (iter, array, newval, NONCONST)
1115 989397 : if (GET_CODE (*iter) == SUBREG)
1116 3009 : return false;
1117 348068 : }
1118 :
1119 60171699 : if (should_unshare)
1120 60171699 : validate_unshare_change (insn, loc, newval, 1);
1121 : else
1122 0 : validate_change (insn, loc, newval, 1);
1123 60171699 : 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 3548117 : insn_propagation subprop (insn);
1129 3548117 : subprop.mem_depth += 1;
1130 3548117 : if (!subprop.apply_to_rvalue (loc))
1131 0 : gcc_unreachable ();
1132 3548117 : if (should_unshare
1133 3548117 : && 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 280901 : newval = copy_rtx (*loc);
1138 280901 : cancel_changes (old_num_changes);
1139 280901 : validate_change (insn, loc, newval, 1);
1140 : }
1141 : }
1142 60171699 : num_replacements += 1;
1143 60171699 : should_unshare = true;
1144 60171699 : result_flags |= UNSIMPLIFIED;
1145 60171699 : 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 180070700 : auto old_result_flags = result_flags;
1153 180070700 : rtx newx = NULL_RTX;
1154 180070700 : bool recurse_p = false;
1155 180070700 : switch (GET_RTX_CLASS (code))
1156 : {
1157 3180073 : case RTX_UNARY:
1158 3180073 : {
1159 3180073 : machine_mode op0_mode = GET_MODE (XEXP (x, 0));
1160 3180073 : if (!apply_to_rvalue_1 (&XEXP (x, 0)))
1161 : return false;
1162 3136519 : if (from && old_num_changes == num_validated_changes ())
1163 : return true;
1164 :
1165 2502955 : newx = simplify_unary_operation (code, mode, XEXP (x, 0), op0_mode);
1166 2502955 : break;
1167 : }
1168 :
1169 46622232 : case RTX_BIN_ARITH:
1170 46622232 : case RTX_COMM_ARITH:
1171 46622232 : {
1172 46622232 : if (!apply_to_rvalue_1 (&XEXP (x, 0))
1173 46622232 : || !apply_to_rvalue_1 (&XEXP (x, 1)))
1174 : return false;
1175 46140317 : if (from && old_num_changes == num_validated_changes ())
1176 : return true;
1177 :
1178 35354121 : if (GET_RTX_CLASS (code) == RTX_COMM_ARITH
1179 35354121 : && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
1180 2672248 : newx = simplify_gen_binary (code, mode, XEXP (x, 1), XEXP (x, 0));
1181 : else
1182 32681873 : newx = simplify_binary_operation (code, mode,
1183 : XEXP (x, 0), XEXP (x, 1));
1184 : break;
1185 : }
1186 :
1187 6083635 : case RTX_COMPARE:
1188 6083635 : case RTX_COMM_COMPARE:
1189 6083635 : {
1190 12167390 : machine_mode op_mode = (GET_MODE (XEXP (x, 0)) != VOIDmode
1191 6083635 : ? GET_MODE (XEXP (x, 0))
1192 120 : : GET_MODE (XEXP (x, 1)));
1193 6083635 : if (!apply_to_rvalue_1 (&XEXP (x, 0))
1194 6083635 : || !apply_to_rvalue_1 (&XEXP (x, 1)))
1195 : return false;
1196 6079271 : if (from && old_num_changes == num_validated_changes ())
1197 : return true;
1198 :
1199 5140669 : newx = simplify_relational_operation (code, mode, op_mode,
1200 : XEXP (x, 0), XEXP (x, 1));
1201 5140669 : break;
1202 : }
1203 :
1204 5503371 : case RTX_TERNARY:
1205 5503371 : case RTX_BITFIELD_OPS:
1206 5503371 : {
1207 5503371 : machine_mode op0_mode = GET_MODE (XEXP (x, 0));
1208 5503371 : if (!apply_to_rvalue_1 (&XEXP (x, 0))
1209 5492445 : || !apply_to_rvalue_1 (&XEXP (x, 1))
1210 10974104 : || !apply_to_rvalue_1 (&XEXP (x, 2)))
1211 : return false;
1212 5468404 : if (from && old_num_changes == num_validated_changes ())
1213 : return true;
1214 :
1215 5399510 : newx = simplify_ternary_operation (code, mode, op0_mode,
1216 : XEXP (x, 0), XEXP (x, 1),
1217 : XEXP (x, 2));
1218 5399510 : break;
1219 : }
1220 :
1221 11480581 : case RTX_EXTRA:
1222 11480581 : if (code == SUBREG)
1223 : {
1224 2626325 : machine_mode inner_mode = GET_MODE (SUBREG_REG (x));
1225 2626325 : if (!apply_to_rvalue_1 (&SUBREG_REG (x)))
1226 : return false;
1227 2626314 : if (from && old_num_changes == num_validated_changes ())
1228 : return true;
1229 :
1230 1926181 : rtx inner = SUBREG_REG (x);
1231 1926181 : newx = simplify_subreg (mode, inner, inner_mode, SUBREG_BYTE (x));
1232 : /* Reject the same cases that simplify_gen_subreg would. */
1233 1926181 : if (!newx
1234 1926181 : && (GET_CODE (inner) == SUBREG
1235 1208002 : || GET_CODE (inner) == CONCAT
1236 1195913 : || GET_MODE (inner) == VOIDmode
1237 1208002 : || !validate_subreg (mode, inner_mode,
1238 1195912 : inner, SUBREG_BYTE (x))))
1239 : {
1240 12134 : failure_reason = "would create an invalid subreg";
1241 12134 : return false;
1242 : }
1243 : break;
1244 : }
1245 : else
1246 : recurse_p = true;
1247 : break;
1248 :
1249 54601005 : case RTX_OBJ:
1250 54601005 : 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 54601005 : else if (code == REG)
1271 : {
1272 37680176 : if (from && REG_P (from) && reg_overlap_mentioned_p (x, from))
1273 : {
1274 63283 : failure_reason = "inexact register overlap";
1275 63283 : return false;
1276 : }
1277 : }
1278 16920829 : else if (code == MEM)
1279 12828056 : return apply_to_mem_1 (x);
1280 : else
1281 : recurse_p = true;
1282 : break;
1283 :
1284 : case RTX_CONST_OBJ:
1285 : break;
1286 :
1287 1429272 : case RTX_AUTOINC:
1288 1429272 : 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 50311302 : if (recurse_p)
1302 : {
1303 14376301 : const char *fmt = GET_RTX_FORMAT (code);
1304 32847496 : for (int i = 0; fmt[i]; i++)
1305 18585228 : switch (fmt[i])
1306 : {
1307 : case 'E':
1308 6464572 : for (int j = 0; j < XVECLEN (x, i); j++)
1309 4631273 : if (!apply_to_rvalue_1 (&XVECEXP (x, i, j)))
1310 : return false;
1311 : break;
1312 :
1313 12630079 : case 'e':
1314 12630079 : if (XEXP (x, i) && !apply_to_rvalue_1 (&XEXP (x, i)))
1315 : return false;
1316 : break;
1317 : }
1318 : }
1319 139098726 : else if (newx && !rtx_equal_p (x, newx))
1320 : {
1321 : /* All substitutions made by OLD_NUM_CHANGES onwards have been
1322 : simplified. */
1323 10798224 : result_flags = ((result_flags & ~UNSIMPLIFIED)
1324 : | (old_result_flags & UNSIMPLIFIED));
1325 :
1326 10798224 : if (should_note_simplifications)
1327 3966061 : 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 10798224 : bool unshare = false;
1332 21591844 : for (int i = old_num_changes; i < num_changes; ++i)
1333 : {
1334 10793620 : unshare |= changes[i].unshare;
1335 10793620 : changes[i].unshare = false;
1336 : }
1337 10798224 : if (unshare)
1338 10406035 : validate_unshare_change (insn, loc, newx, 1);
1339 : else
1340 392189 : 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 64440902 : insn_propagation::apply_to_lvalue_1 (rtx dest)
1351 : {
1352 64440902 : rtx old_dest = dest;
1353 64440902 : while (GET_CODE (dest) == SUBREG
1354 64654652 : || GET_CODE (dest) == ZERO_EXTRACT
1355 64654652 : || GET_CODE (dest) == STRICT_LOW_PART)
1356 : {
1357 213750 : if (GET_CODE (dest) == ZERO_EXTRACT
1358 213750 : && (!apply_to_rvalue_1 (&XEXP (dest, 1))
1359 2662 : || !apply_to_rvalue_1 (&XEXP (dest, 2))))
1360 : return false;
1361 213750 : dest = XEXP (dest, 0);
1362 : }
1363 :
1364 64440902 : if (MEM_P (dest))
1365 11808493 : return apply_to_mem_1 (dest);
1366 :
1367 : /* Check whether the substitution is safe in the presence of this lvalue. */
1368 52632409 : if (!from
1369 52632409 : || dest == old_dest
1370 209473 : || !REG_P (dest)
1371 52841882 : || !reg_overlap_mentioned_p (dest, from))
1372 : return true;
1373 :
1374 103598 : if (SUBREG_P (old_dest)
1375 98977 : && SUBREG_REG (old_dest) == dest
1376 202575 : && !read_modify_subreg_p (old_dest))
1377 : return true;
1378 :
1379 103290 : failure_reason = "is part of a read-write destination";
1380 103290 : 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 68143520 : insn_propagation::apply_to_pattern_1 (rtx *loc)
1388 : {
1389 68143520 : rtx body = *loc;
1390 68143520 : 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 14909000 : for (int i = 0; i < XVECLEN (body, 0); ++i)
1398 : {
1399 10193309 : rtx *subloc = &XVECEXP (body, 0, i);
1400 10193309 : if (GET_CODE (*subloc) == SET)
1401 : {
1402 5536204 : 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 775554 : if ((i == 0 || GET_CODE (SET_SRC (*subloc)) != ASM_OPERANDS)
1407 6173426 : && !apply_to_rvalue_1 (&SET_SRC (*subloc)))
1408 : return false;
1409 : }
1410 : else
1411 : {
1412 4657105 : if (!apply_to_pattern_1 (subloc))
1413 : return false;
1414 : }
1415 : }
1416 : return true;
1417 :
1418 8719 : case ASM_OPERANDS:
1419 30696 : for (int i = 0, len = ASM_OPERANDS_INPUT_LENGTH (body); i < len; ++i)
1420 22197 : if (!apply_to_rvalue_1 (&ASM_OPERANDS_INPUT (body, i)))
1421 : return false;
1422 : return true;
1423 :
1424 4453070 : case CLOBBER:
1425 4453070 : return apply_to_lvalue_1 (XEXP (body, 0));
1426 :
1427 54451628 : case SET:
1428 54451628 : return (apply_to_lvalue_1 (SET_DEST (body))
1429 54451628 : && apply_to_rvalue_1 (&SET_SRC (body)));
1430 :
1431 4459056 : 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 4459056 : 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 63486415 : insn_propagation::apply_to_pattern (rtx *loc)
1449 : {
1450 63486415 : unsigned int num_changes = num_validated_changes ();
1451 63486415 : bool res = apply_to_pattern_1 (loc);
1452 63486415 : if (!res)
1453 2311947 : cancel_changes (num_changes);
1454 63486415 : 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 7570272 : insn_propagation::apply_to_rvalue (rtx *loc)
1462 : {
1463 7570272 : unsigned int num_changes = num_validated_changes ();
1464 7570272 : bool res = apply_to_rvalue_1 (loc);
1465 7570272 : if (!res)
1466 20337 : cancel_changes (num_changes);
1467 7570272 : 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 192402 : insn_propagation::apply_to_note (rtx *loc)
1475 : {
1476 192402 : auto old_code = INSN_CODE (insn);
1477 192402 : bool res = apply_to_rvalue (loc);
1478 192402 : if (INSN_CODE (insn) != old_code)
1479 96201 : INSN_CODE (insn) = old_code;
1480 192402 : 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 5029147985 : general_operand (rtx op, machine_mode mode)
1515 : {
1516 5029147985 : enum rtx_code code = GET_CODE (op);
1517 :
1518 5029147985 : if (mode == VOIDmode)
1519 1322388639 : mode = GET_MODE (op);
1520 :
1521 : /* Don't accept CONST_INT or anything similar
1522 : if the caller wants something floating. */
1523 5029147985 : if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1524 225460778 : && GET_MODE_CLASS (mode) != MODE_INT
1525 4571 : && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1526 : return false;
1527 :
1528 5029143414 : if (CONST_INT_P (op)
1529 277625509 : && mode != VOIDmode
1530 5251329675 : && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1531 : return false;
1532 :
1533 5029143275 : if (CONSTANT_P (op))
1534 65289183 : return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
1535 7905 : || mode == VOIDmode)
1536 343500689 : && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1537 741945318 : && targetm.legitimate_constant_p (mode == VOIDmode
1538 55517724 : ? 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 4685634681 : if (GET_MODE (op) != mode)
1545 : return false;
1546 :
1547 4631115590 : if (code == SUBREG)
1548 : {
1549 36676697 : 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 36628643 : if (!reload_completed && MEM_P (sub)
1557 36741527 : && 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 36612189 : if (!reload_completed
1567 36564135 : && maybe_ne (SUBREG_BYTE (op), 0)
1568 41992959 : && MEM_P (sub))
1569 : return false;
1570 :
1571 36612189 : if (REG_P (sub)
1572 34908131 : && REGNO (sub) < FIRST_PSEUDO_REGISTER
1573 4489 : && !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 36612189 : && ! 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 36612189 : 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 312724 : && ! lra_in_progress
1591 36913490 : && paradoxical_subreg_p (op))
1592 : return false;
1593 :
1594 36612189 : op = sub;
1595 36612189 : code = GET_CODE (op);
1596 : }
1597 :
1598 4631051082 : if (code == REG)
1599 3804917515 : return (REGNO (op) >= FIRST_PSEUDO_REGISTER
1600 3804917515 : || in_hard_reg_set_p (operand_reg_set, GET_MODE (op), REGNO (op)));
1601 :
1602 826133567 : if (code == MEM)
1603 : {
1604 730313613 : rtx y = XEXP (op, 0);
1605 :
1606 : /* If -ffuse-ops-with-volatile-access is enabled, allow volatile
1607 : memory reference. */
1608 730313613 : if (!flag_fuse_ops_with_volatile_access
1609 176742 : && !volatile_ok
1610 730363663 : && 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 730306723 : if (lra_in_progress
1618 784549703 : || 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 117320508 : address_operand (rtx op, machine_mode mode)
1633 : {
1634 : /* Wrong mode for an address expr. */
1635 117320508 : if (GET_MODE (op) != VOIDmode
1636 104749919 : && ! SCALAR_INT_MODE_P (GET_MODE (op))
1637 917723 : && ! (GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_INT))
1638 : return false;
1639 :
1640 116852269 : 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 2746613045 : register_operand (rtx op, machine_mode mode)
1651 : {
1652 2746613045 : if (GET_CODE (op) == SUBREG)
1653 : {
1654 12578382 : 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 12578382 : if (!REG_P (sub) && (reload_completed || !MEM_P (sub)))
1663 : return false;
1664 : }
1665 2734034663 : else if (!REG_P (op))
1666 : return false;
1667 2020447237 : 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 787238 : scratch_operand (rtx op, machine_mode mode)
1683 : {
1684 787238 : if (GET_MODE (op) != mode && mode != VOIDmode)
1685 : return false;
1686 :
1687 748509 : return (GET_CODE (op) == SCRATCH
1688 748509 : || (REG_P (op)
1689 121171 : && (lra_in_progress
1690 101925 : || (REGNO (op) < FIRST_PSEUDO_REGISTER
1691 98436 : && 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 513042959 : 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 513042959 : if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1705 146423699 : && GET_MODE_CLASS (mode) != MODE_INT
1706 0 : && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1707 : return false;
1708 :
1709 513042959 : if (CONST_INT_P (op)
1710 329500178 : && mode != VOIDmode
1711 656297479 : && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1712 : return false;
1713 :
1714 512809050 : return (CONSTANT_P (op)
1715 394373575 : && (GET_MODE (op) == mode || mode == VOIDmode
1716 147676450 : || GET_MODE (op) == VOIDmode)
1717 391785539 : && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1718 1122642350 : && targetm.legitimate_constant_p (mode == VOIDmode
1719 222816564 : ? 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 39443644 : const_int_operand (rtx op, machine_mode mode)
1727 : {
1728 39443644 : if (!CONST_INT_P (op))
1729 : return false;
1730 :
1731 33307983 : if (mode != VOIDmode
1732 33307983 : && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1733 712 : 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 2466158 : const_scalar_int_operand (rtx op, machine_mode mode)
1743 : {
1744 2466158 : if (!CONST_SCALAR_INT_P (op))
1745 : return false;
1746 :
1747 2085085 : if (CONST_INT_P (op))
1748 213693 : return const_int_operand (op, mode);
1749 :
1750 1871392 : if (mode != VOIDmode)
1751 : {
1752 1871392 : scalar_int_mode int_mode = as_a <scalar_int_mode> (mode);
1753 1871392 : int prec = GET_MODE_PRECISION (int_mode);
1754 1871392 : int bitsize = GET_MODE_BITSIZE (int_mode);
1755 :
1756 1871392 : if (CONST_WIDE_INT_NUNITS (op) * HOST_BITS_PER_WIDE_INT > bitsize)
1757 : return false;
1758 :
1759 1871387 : 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 1931485498 : nonimmediate_operand (rtx op, machine_mode mode)
1805 : {
1806 1931485498 : 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 557173781 : nonmemory_operand (rtx op, machine_mode mode)
1814 : {
1815 557173781 : if (CONSTANT_P (op))
1816 33219106 : return immediate_operand (op, mode);
1817 523954675 : 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 863826347 : push_operand (rtx op, machine_mode mode)
1828 : {
1829 863826347 : if (!MEM_P (op))
1830 : return false;
1831 :
1832 252880774 : if (mode != VOIDmode && GET_MODE (op) != mode)
1833 : return false;
1834 :
1835 478721634 : poly_int64 rounded_size = GET_MODE_SIZE (mode);
1836 :
1837 : #ifdef PUSH_ROUNDING
1838 239360817 : rounded_size = PUSH_ROUNDING (MACRO_INT (rounded_size));
1839 : #endif
1840 :
1841 239360817 : op = XEXP (op, 0);
1842 :
1843 478721634 : if (known_eq (rounded_size, GET_MODE_SIZE (mode)))
1844 : {
1845 203103703 : if (GET_CODE (op) != STACK_PUSH_CODE)
1846 : return false;
1847 : }
1848 : else
1849 : {
1850 36257114 : poly_int64 offset;
1851 36257114 : if (GET_CODE (op) != PRE_MODIFY
1852 1209124 : || GET_CODE (XEXP (op, 1)) != PLUS
1853 1209124 : || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1854 1209124 : || !poly_int_rtx_p (XEXP (XEXP (op, 1), 1), &offset)
1855 36257114 : || (STACK_GROWS_DOWNWARD
1856 1209124 : ? maybe_ne (offset, -rounded_size)
1857 : : maybe_ne (offset, rounded_size)))
1858 863826347 : return false;
1859 : }
1860 :
1861 43858954 : 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 297966026 : pop_operand (rtx op, machine_mode mode)
1872 : {
1873 297966026 : if (!MEM_P (op))
1874 : return false;
1875 :
1876 68070152 : if (mode != VOIDmode && GET_MODE (op) != mode)
1877 : return false;
1878 :
1879 68070152 : op = XEXP (op, 0);
1880 :
1881 68070152 : if (GET_CODE (op) != STACK_POP_CODE)
1882 : return false;
1883 :
1884 1405362 : 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 1458492945 : 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 1458492945 : 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 1264638821 : memory_operand (rtx op, machine_mode mode)
1914 : {
1915 1264638821 : rtx inner;
1916 :
1917 1264638821 : 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 131624011 : return MEM_P (op) && general_operand (op, mode);
1921 :
1922 1133014810 : if (mode != VOIDmode && GET_MODE (op) != mode)
1923 : return false;
1924 :
1925 829130317 : inner = op;
1926 829130317 : if (GET_CODE (inner) == SUBREG)
1927 8183 : inner = SUBREG_REG (inner);
1928 :
1929 829130317 : 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 29000774 : ordered_comparison_operator (rtx op, machine_mode mode)
1965 : {
1966 29000774 : if (mode != VOIDmode && GET_MODE (op) != mode)
1967 : return false;
1968 29000774 : 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 117304151 : comparison_operator (rtx op, machine_mode mode)
1991 : {
1992 5019174 : return ((mode == VOIDmode || GET_MODE (op) == mode)
1993 121887644 : && COMPARISON_P (op));
1994 : }
1995 :
1996 : /* If BODY is an insn body that uses ASM_OPERANDS, return it. */
1997 :
1998 : rtx
1999 2177012448 : extract_asm_operands (rtx body)
2000 : {
2001 2177012448 : rtx tmp;
2002 2177012448 : switch (GET_CODE (body))
2003 : {
2004 : case ASM_OPERANDS:
2005 : return body;
2006 :
2007 1684358254 : case SET:
2008 : /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
2009 1684358254 : tmp = SET_SRC (body);
2010 1684358254 : if (GET_CODE (tmp) == ASM_OPERANDS)
2011 : return tmp;
2012 : break;
2013 :
2014 355590300 : case PARALLEL:
2015 355590300 : tmp = XVECEXP (body, 0, 0);
2016 355590300 : if (GET_CODE (tmp) == ASM_OPERANDS)
2017 : return tmp;
2018 353674132 : if (GET_CODE (tmp) == SET)
2019 : {
2020 349286303 : tmp = SET_SRC (tmp);
2021 349286303 : if (GET_CODE (tmp) == ASM_OPERANDS)
2022 : return tmp;
2023 : }
2024 : break;
2025 :
2026 : default:
2027 : break;
2028 : }
2029 2171312024 : 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 1700485755 : asm_noperands (const_rtx body)
2040 : {
2041 1700485755 : rtx asm_op = extract_asm_operands (const_cast<rtx> (body));
2042 1700485755 : int i, n_sets = 0;
2043 :
2044 1700485755 : if (asm_op == NULL)
2045 : {
2046 1695910339 : if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) >= 2
2047 261697665 : && GET_CODE (XVECEXP (body, 0, 0)) == ASM_INPUT)
2048 : {
2049 : /* body is [(asm_input ...) (clobber (reg ...))...]. */
2050 61566 : for (i = XVECLEN (body, 0) - 1; i > 0; i--)
2051 41044 : if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
2052 : return -1;
2053 : return 0;
2054 : }
2055 : return -1;
2056 : }
2057 :
2058 4575416 : if (GET_CODE (body) == SET)
2059 : n_sets = 1;
2060 4566887 : else if (GET_CODE (body) == PARALLEL)
2061 : {
2062 4556958 : 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 6022199 : for (i = XVECLEN (body, 0); i > 0; i--)
2072 : {
2073 6022199 : if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
2074 : break;
2075 3046612 : if (GET_CODE (XVECEXP (body, 0, i - 1)) != USE
2076 3046612 : && GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
2077 : return -1;
2078 : }
2079 :
2080 : /* N_SETS is now number of output operands. */
2081 11455312 : 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 11455312 : for (i = 0; i < n_sets; i++)
2087 : {
2088 8520049 : rtx elt = XVECEXP (body, 0, i);
2089 8520049 : if (GET_CODE (elt) != SET)
2090 : return -1;
2091 8514590 : 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 8497926 : if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
2096 8497926 : != 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 5215958 : for (i = XVECLEN (body, 0) - 1; i > 0; i--)
2108 3636979 : if (GET_CODE (XVECEXP (body, 0, i)) != USE
2109 3636979 : && GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
2110 : return -1;
2111 : }
2112 : }
2113 :
2114 4532700 : return (ASM_OPERANDS_INPUT_LENGTH (asm_op)
2115 4532700 : + 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 2069749 : decode_asm_operands (rtx body, rtx *operands, rtx **operand_locs,
2133 : const char **constraints, machine_mode *modes,
2134 : location_t *loc)
2135 : {
2136 2069749 : int nbase = 0, n, i;
2137 2069749 : rtx asmop;
2138 :
2139 2069749 : 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 2061426 : case PARALLEL:
2164 2061426 : {
2165 2061426 : int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
2166 :
2167 2061426 : asmop = XVECEXP (body, 0, 0);
2168 2061426 : if (GET_CODE (asmop) == SET)
2169 : {
2170 1217622 : 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 4509378 : for (i = 0; i < nparallel; i++)
2175 : {
2176 4488164 : if (GET_CODE (XVECEXP (body, 0, i)) == USE
2177 4488164 : || GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
2178 : break; /* Past last SET */
2179 3291756 : gcc_assert (GET_CODE (XVECEXP (body, 0, i)) == SET);
2180 3291756 : if (operands)
2181 3118008 : operands[i] = SET_DEST (XVECEXP (body, 0, i));
2182 3291756 : if (operand_locs)
2183 1193826 : operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
2184 3291756 : if (constraints)
2185 3131583 : constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
2186 3291756 : if (modes)
2187 1193826 : modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
2188 : }
2189 : nbase = i;
2190 : }
2191 843804 : else if (GET_CODE (asmop) == ASM_INPUT)
2192 : {
2193 10457 : if (loc)
2194 0 : *loc = ASM_INPUT_SOURCE_LOCATION (asmop);
2195 10457 : return XSTR (asmop, 0);
2196 : }
2197 : break;
2198 : }
2199 :
2200 0 : default:
2201 0 : gcc_unreachable ();
2202 : }
2203 :
2204 2059292 : n = ASM_OPERANDS_INPUT_LENGTH (asmop);
2205 4137441 : for (i = 0; i < n; i++)
2206 : {
2207 2078149 : if (operand_locs)
2208 885012 : operand_locs[nbase + i] = &ASM_OPERANDS_INPUT (asmop, i);
2209 2078149 : if (operands)
2210 1940095 : operands[nbase + i] = ASM_OPERANDS_INPUT (asmop, i);
2211 2078149 : if (constraints)
2212 1957013 : constraints[nbase + i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
2213 2078149 : if (modes)
2214 885012 : modes[nbase + i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
2215 : }
2216 2059292 : nbase += n;
2217 :
2218 2059292 : n = ASM_OPERANDS_LABEL_LENGTH (asmop);
2219 2081126 : for (i = 0; i < n; i++)
2220 : {
2221 21834 : if (operand_locs)
2222 12455 : operand_locs[nbase + i] = &ASM_OPERANDS_LABEL (asmop, i);
2223 21834 : if (operands)
2224 19779 : operands[nbase + i] = ASM_OPERANDS_LABEL (asmop, i);
2225 21834 : if (constraints)
2226 19846 : constraints[nbase + i] = "";
2227 21834 : if (modes)
2228 12455 : modes[nbase + i] = Pmode;
2229 : }
2230 :
2231 2059292 : if (loc)
2232 93124 : *loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
2233 :
2234 2059292 : 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 3608553 : asm_operand_ok (rtx op, const char *constraint, const char **constraints)
2345 : {
2346 3608553 : int result = 0;
2347 3608553 : bool incdec_ok = false;
2348 :
2349 : /* Use constrain_operands after reload. */
2350 3608553 : 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 3608553 : if (*constraint == '\0')
2355 3914 : result = 1;
2356 :
2357 9948330 : while (*constraint)
2358 : {
2359 6339779 : enum constraint_num cn;
2360 6339779 : char c = *constraint;
2361 6339779 : int len;
2362 6339779 : switch (c)
2363 : {
2364 11497 : case ',':
2365 11497 : raw_constraint_p = false;
2366 11497 : constraint++;
2367 11497 : continue;
2368 :
2369 677500 : case '0': case '1': case '2': case '3': case '4':
2370 677500 : 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 677500 : if (constraints)
2377 : {
2378 677299 : char *end;
2379 677299 : unsigned long match;
2380 :
2381 677299 : match = strtoul (constraint, &end, 10);
2382 677299 : if (!result)
2383 677038 : result = asm_operand_ok (op, constraints[match], NULL);
2384 677299 : constraint = (const char *) end;
2385 : }
2386 : else
2387 : {
2388 225 : do
2389 225 : constraint++;
2390 225 : while (ISDIGIT (*constraint));
2391 201 : if (! result)
2392 174 : result = -1;
2393 : }
2394 677500 : 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 2429653 : result = 1;
2409 : break;
2410 :
2411 140970 : case 'g':
2412 140970 : if (general_operand (op, VOIDmode))
2413 2429653 : 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 5509744 : incdec_ok = true;
2430 : /* FALLTHRU */
2431 5509744 : default:
2432 5509744 : cn = lookup_constraint (constraint);
2433 5509744 : rtx mem = NULL;
2434 5509744 : switch (get_constraint_type (cn))
2435 : {
2436 5306185 : case CT_REGISTER:
2437 5306185 : if (!result
2438 2611749 : && (reg_class_for_constraint (cn) != NO_REGS
2439 2692467 : || constraint[0] == '{')
2440 2612407 : && GET_MODE (op) != BLKmode
2441 7918557 : && 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 180469 : case CT_MEMORY:
2453 180469 : case CT_RELAXED_MEMORY:
2454 180469 : mem = op;
2455 : /* Fall through. */
2456 180469 : case CT_SPECIAL_MEMORY:
2457 : /* Every memory operand can be reloaded to fit. */
2458 180469 : if (!mem)
2459 0 : mem = extract_mem_from_operand (op);
2460 180469 : result = result || memory_operand (mem, VOIDmode);
2461 180469 : 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 22943 : case CT_FIXED_FORM:
2469 22943 : result = result || constraint_satisfied_p (op, cn);
2470 22943 : break;
2471 : }
2472 : break;
2473 689029 : }
2474 5650750 : len = CONSTRAINT_LEN (c, constraint);
2475 5654829 : do
2476 5654829 : constraint++;
2477 11305579 : while (--len && *constraint && *constraint != ',');
2478 5650750 : if (len)
2479 : {
2480 2 : raw_constraint_p = false;
2481 2 : return 0;
2482 : }
2483 : }
2484 3608551 : raw_constraint_p = false;
2485 :
2486 : /* For operands without < or > constraints reject side-effects. */
2487 3608551 : 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 3608551 : 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 26905143 : find_constant_term_loc (rtx *p)
2510 : {
2511 40393832 : rtx *tem;
2512 40393832 : enum rtx_code code = GET_CODE (*p);
2513 :
2514 : /* If *P IS such a constant term, P is its location. */
2515 :
2516 40393832 : 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 15226838 : return 0;
2524 :
2525 : /* If one of the summands is constant, return its location. */
2526 :
2527 13488689 : 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 13488689 : if (XEXP (*p, 0) != 0)
2534 : {
2535 13488689 : tem = find_constant_term_loc (&XEXP (*p, 0));
2536 13488689 : if (tem != 0)
2537 : return tem;
2538 : }
2539 :
2540 13488689 : if (XEXP (*p, 1) != 0)
2541 : {
2542 13488689 : 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 5656260 : offsettable_memref_p (rtx op)
2561 : {
2562 5656260 : return ((MEM_P (op))
2563 11307354 : && offsettable_address_addr_space_p (1, GET_MODE (op), XEXP (op, 0),
2564 5651094 : 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 11764657 : offsettable_nonstrict_memref_p (rtx op)
2572 : {
2573 11764657 : return ((MEM_P (op))
2574 23529280 : && offsettable_address_addr_space_p (0, GET_MODE (op), XEXP (op, 0),
2575 11764623 : 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 17415717 : offsettable_address_addr_space_p (int strictp, machine_mode mode, rtx y,
2590 : addr_space_t as)
2591 : {
2592 17415717 : enum rtx_code ycode = GET_CODE (y);
2593 17415717 : rtx z;
2594 17415717 : rtx y1 = y;
2595 17415717 : rtx *y2;
2596 11764623 : bool (*addressp) (machine_mode, rtx, addr_space_t, code_helper) =
2597 17415717 : (strictp ? strict_memory_address_addr_space_p
2598 : : memory_address_addr_space_p);
2599 34831434 : poly_int64 mode_sz = GET_MODE_SIZE (mode);
2600 :
2601 17415717 : 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 14735471 : if (mode_dependent_address_p (y, as))
2608 : return false;
2609 :
2610 14551302 : machine_mode address_mode = GET_MODE (y);
2611 14551302 : if (address_mode == VOIDmode)
2612 0 : address_mode = targetm.addr_space.address_mode (as);
2613 : #ifdef POINTERS_EXTEND_UNSIGNED
2614 14551302 : 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 14551302 : 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 14551302 : if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
2628 : {
2629 11678305 : bool good;
2630 :
2631 11678305 : y1 = *y2;
2632 11678305 : *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 11678305 : good = (*addressp) (QImode, y, as, ERROR_MARK);
2636 :
2637 : /* In any case, restore old contents of memory. */
2638 11678305 : *y2 = y1;
2639 11678305 : return good;
2640 : }
2641 :
2642 2872997 : 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 2872997 : if (GET_CODE (y) == LO_SUM
2651 0 : && mode != BLKmode
2652 2872997 : && 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 2872997 : else if (POINTERS_EXTEND_UNSIGNED > 0
2659 2872997 : && 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 2872990 : 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 2872997 : 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 40609694 : 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 40609694 : if (GET_CODE (addr) == PRE_INC
2688 40609694 : || GET_CODE (addr) == POST_INC
2689 40609688 : || GET_CODE (addr) == PRE_DEC
2690 36821830 : || GET_CODE (addr) == POST_DEC)
2691 : return true;
2692 :
2693 36821830 : return targetm.mode_dependent_address_p (addr, addrspace);
2694 : }
2695 :
2696 : /* Return true if boolean attribute ATTR is supported. */
2697 :
2698 : static bool
2699 1669867446 : have_bool_attr (bool_attr attr)
2700 : {
2701 1669867446 : 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 1768224566 : get_bool_attr (rtx_insn *insn, bool_attr attr)
2717 : {
2718 1768224566 : switch (attr)
2719 : {
2720 749170214 : case BA_ENABLED:
2721 749170214 : return get_attr_enabled (insn);
2722 366287008 : case BA_PREFERRED_FOR_SIZE:
2723 366287008 : return get_attr_enabled (insn) && get_attr_preferred_for_size (insn);
2724 652767344 : case BA_PREFERRED_FOR_SPEED:
2725 652767344 : 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 105457508 : 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 105457508 : rtx_insn *old_insn = recog_data.insn;
2740 105457508 : int old_alternative = which_alternative;
2741 :
2742 105457508 : recog_data.insn = insn;
2743 105457508 : alternative_mask mask = ALL_ALTERNATIVES;
2744 105457508 : int n_alternatives = insn_data[INSN_CODE (insn)].n_alternatives;
2745 1873682074 : for (int i = 0; i < n_alternatives; i++)
2746 : {
2747 1768224566 : which_alternative = i;
2748 1768224566 : if (!get_bool_attr (insn, attr))
2749 536696322 : mask &= ~ALTERNATIVE_BIT (i);
2750 : }
2751 :
2752 105457508 : recog_data.insn = old_insn;
2753 105457508 : which_alternative = old_alternative;
2754 105457508 : 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 1672129114 : 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 1672129114 : int code = INSN_CODE (insn);
2767 1672129114 : 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 1669867446 : if (!this_target_recog->x_bool_attr_masks[code][attr])
2773 13286256 : this_target_recog->x_bool_attr_masks[code][attr]
2774 13286256 : = get_bool_attr_mask_uncached (insn, attr);
2775 1669867446 : 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 1208557564 : get_enabled_alternatives (rtx_insn *insn)
2783 : {
2784 1208557564 : 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 463491206 : get_preferred_alternatives (rtx_insn *insn)
2793 : {
2794 463491206 : if (optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn)))
2795 405983024 : return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SPEED);
2796 : else
2797 57508182 : 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 80344 : get_preferred_alternatives (rtx_insn *insn, basic_block bb)
2808 : {
2809 80344 : if (optimize_bb_for_speed_p (bb))
2810 75124 : return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SPEED);
2811 : else
2812 5220 : 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 37241159 : check_bool_attrs (rtx_insn *insn)
2822 : {
2823 37241159 : int code = INSN_CODE (insn);
2824 37241159 : if (code >= 0)
2825 148964636 : for (int i = 0; i <= BA_LAST; ++i)
2826 : {
2827 111723477 : enum bool_attr attr = (enum bool_attr) i;
2828 111723477 : if (this_target_recog->x_bool_attr_masks[code][attr])
2829 92171252 : gcc_assert (this_target_recog->x_bool_attr_masks[code][attr]
2830 : == get_bool_attr_mask_uncached (insn, attr));
2831 : }
2832 37241159 : 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 10825135975 : extract_insn_cached (rtx_insn *insn)
2841 : {
2842 10825135975 : if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
2843 : return;
2844 848483946 : extract_insn (insn);
2845 848483946 : 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 271333570 : extract_constrain_insn (rtx_insn *insn)
2853 : {
2854 271333570 : extract_insn (insn);
2855 271333570 : if (!constrain_operands (reload_completed, get_enabled_alternatives (insn)))
2856 0 : fatal_insn_not_found (insn);
2857 271333570 : }
2858 :
2859 : /* Do cached extract_insn, constrain_operands and complain about failures.
2860 : Used by insn_attrtab. */
2861 : void
2862 9524879271 : extract_constrain_insn_cached (rtx_insn *insn)
2863 : {
2864 9524879271 : extract_insn_cached (insn);
2865 9524879271 : if (which_alternative == -1
2866 9524879271 : && !constrain_operands (reload_completed,
2867 : get_enabled_alternatives (insn)))
2868 0 : fatal_insn_not_found (insn);
2869 9524879271 : }
2870 :
2871 : /* Do cached constrain_operands on INSN and complain about failures. */
2872 : bool
2873 347045671 : constrain_operands_cached (rtx_insn *insn, int strict)
2874 : {
2875 347045671 : if (which_alternative == -1)
2876 94776527 : 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 2581580477 : extract_insn (rtx_insn *insn)
2885 : {
2886 2581580477 : int i;
2887 2581580477 : int icode;
2888 2581580477 : int noperands;
2889 2581580477 : rtx body = PATTERN (insn);
2890 :
2891 2581580477 : recog_data.n_operands = 0;
2892 2581580477 : recog_data.n_alternatives = 0;
2893 2581580477 : recog_data.n_dups = 0;
2894 2581580477 : recog_data.is_asm = false;
2895 :
2896 2581580477 : 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 1912805180 : case SET:
2908 1912805180 : if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
2909 400 : goto asm_insn;
2910 : else
2911 1912804780 : goto normal_insn;
2912 254821928 : case PARALLEL:
2913 254821928 : if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
2914 250321924 : && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
2915 254337734 : || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS
2916 253736144 : || GET_CODE (XVECEXP (body, 0, 0)) == ASM_INPUT)
2917 1094490 : goto asm_insn;
2918 : else
2919 253727438 : goto normal_insn;
2920 1095030 : case ASM_OPERANDS:
2921 1095030 : asm_insn:
2922 1095030 : recog_data.n_operands = noperands = asm_noperands (body);
2923 1095030 : 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 1095030 : gcc_assert (noperands <= MAX_RECOG_OPERANDS);
2929 :
2930 : /* Now get the operand values and constraints out of the insn. */
2931 1095030 : decode_asm_operands (body, recog_data.operand,
2932 1095030 : recog_data.operand_loc,
2933 1095030 : recog_data.constraints,
2934 1095030 : recog_data.operand_mode, NULL);
2935 1095030 : memset (recog_data.is_operator, 0, sizeof recog_data.is_operator);
2936 1095030 : if (noperands > 0)
2937 : {
2938 591547 : const char *p = recog_data.constraints[0];
2939 591547 : recog_data.n_alternatives = 1;
2940 1670195 : while (*p)
2941 1078648 : recog_data.n_alternatives += (*p++ == ',');
2942 : }
2943 1095030 : recog_data.is_asm = true;
2944 1095030 : break;
2945 : }
2946 0 : fatal_insn_not_found (insn);
2947 :
2948 2230710580 : default:
2949 2230710580 : normal_insn:
2950 : /* Ordinary insn: recognize it, get the operands via insn_extract
2951 : and get the constraints. */
2952 :
2953 2230710580 : icode = recog_memoized (insn);
2954 2230710580 : if (icode < 0)
2955 0 : fatal_insn_not_found (insn);
2956 :
2957 2230710580 : recog_data.n_operands = noperands = insn_data[icode].n_operands;
2958 2230710580 : recog_data.n_alternatives = insn_data[icode].n_alternatives;
2959 2230710580 : recog_data.n_dups = insn_data[icode].n_dups;
2960 :
2961 2230710580 : insn_extract (insn);
2962 :
2963 9237600962 : for (i = 0; i < noperands; i++)
2964 : {
2965 4776179802 : recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2966 4776179802 : recog_data.is_operator[i] = insn_data[icode].operand[i].is_operator;
2967 4776179802 : recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2968 : /* VOIDmode match_operands gets mode from their real operand. */
2969 4776179802 : if (recog_data.operand_mode[i] == VOIDmode)
2970 474940725 : recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2971 : }
2972 : }
2973 7009908990 : for (i = 0; i < noperands; i++)
2974 4778103380 : recog_data.operand_type[i]
2975 7755221408 : = (recog_data.constraints[i][0] == '=' ? OP_OUT
2976 2977118028 : : recog_data.constraints[i][0] == '+' ? OP_INOUT
2977 : : OP_IN);
2978 :
2979 2231805610 : gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2980 :
2981 2231805610 : recog_data.insn = NULL;
2982 2231805610 : 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 4858932 : preprocess_constraints (int n_operands, int n_alternatives,
2996 : const char **constraints,
2997 : operand_alternative *op_alt_base,
2998 : rtx **oploc)
2999 : {
3000 12606037 : for (int i = 0; i < n_operands; i++)
3001 : {
3002 7747105 : int j;
3003 7747105 : struct operand_alternative *op_alt;
3004 7747105 : const char *p = constraints[i];
3005 :
3006 7747105 : op_alt = op_alt_base;
3007 :
3008 50246563 : for (j = 0; j < n_alternatives; j++, op_alt += n_operands)
3009 : {
3010 42499458 : op_alt[i].cl = NO_REGS;
3011 42499458 : op_alt[i].register_filters = 0;
3012 42499458 : op_alt[i].dependent_filters = 0;
3013 42499458 : op_alt[i].constraint = p;
3014 42499458 : op_alt[i].matches = -1;
3015 42499458 : op_alt[i].matched = -1;
3016 :
3017 42499458 : if (*p == '\0' || *p == ',')
3018 : {
3019 1837301 : op_alt[i].anything_ok = 1;
3020 1837301 : continue;
3021 : }
3022 :
3023 106497367 : for (;;)
3024 : {
3025 106497367 : char c = *p;
3026 106497367 : if (c == '#')
3027 0 : do
3028 0 : c = *++p;
3029 0 : while (c != ',' && c != '\0');
3030 106497367 : if (c == ',' || c == '\0')
3031 : {
3032 40662157 : p++;
3033 40662157 : break;
3034 : }
3035 :
3036 65835210 : switch (c)
3037 : {
3038 5882221 : case '?':
3039 5882221 : op_alt[i].reject += 6;
3040 5882221 : break;
3041 415987 : case '!':
3042 415987 : op_alt[i].reject += 600;
3043 415987 : break;
3044 62637 : case '&':
3045 62637 : op_alt[i].earlyclobber = 1;
3046 62637 : break;
3047 :
3048 2098077 : case '0': case '1': case '2': case '3': case '4':
3049 2098077 : case '5': case '6': case '7': case '8': case '9':
3050 2098077 : {
3051 2098077 : char *end;
3052 2098077 : op_alt[i].matches = strtoul (p, &end, 10);
3053 2098077 : op_alt[op_alt[i].matches].matched = i;
3054 2098077 : p = end;
3055 : }
3056 2098077 : continue;
3057 :
3058 32640 : case 'X':
3059 32640 : op_alt[i].anything_ok = 1;
3060 32640 : break;
3061 :
3062 214498 : case 'g':
3063 214498 : op_alt[i].cl =
3064 214498 : reg_class_subunion[(int) op_alt[i].cl][(int) GENERAL_REGS];
3065 214498 : break;
3066 :
3067 57129150 : default:
3068 57129150 : enum constraint_num cn = lookup_constraint (p);
3069 57129150 : enum reg_class cl;
3070 57129150 : switch (get_constraint_type (cn))
3071 : {
3072 40825127 : case CT_REGISTER:
3073 40825127 : cl = reg_class_for_constraint (cn);
3074 29665801 : if (cl != NO_REGS)
3075 : {
3076 26025980 : op_alt[i].cl = reg_class_subunion[op_alt[i].cl][cl];
3077 26025980 : auto filter_id = get_register_filter_id (cn);
3078 26025980 : if (filter_id >= 0)
3079 : op_alt[i].register_filters |= 1U << filter_id;
3080 26025980 : auto dep_filter_id = get_dependent_filter_id (cn);
3081 26025980 : 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 8075920 : case CT_MEMORY:
3090 8075920 : case CT_SPECIAL_MEMORY:
3091 8075920 : case CT_RELAXED_MEMORY:
3092 8075920 : op_alt[i].memory_ok = 1;
3093 8075920 : break;
3094 :
3095 89946 : case CT_ADDRESS:
3096 89946 : if (oploc && !address_operand (*oploc[i], VOIDmode))
3097 : break;
3098 :
3099 89927 : op_alt[i].is_address = 1;
3100 89927 : op_alt[i].cl
3101 89927 : = (reg_class_subunion
3102 89927 : [(int) op_alt[i].cl]
3103 89927 : [(int) base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
3104 89927 : ADDRESS, SCRATCH)]);
3105 89927 : break;
3106 :
3107 : case CT_FIXED_FORM:
3108 : break;
3109 : }
3110 : break;
3111 2098077 : }
3112 63737133 : p += CONSTRAINT_LEN (c, p);
3113 : }
3114 : }
3115 : }
3116 4858932 : }
3117 :
3118 : /* Return an array of operand_alternative instructions for
3119 : instruction ICODE. */
3120 :
3121 : const operand_alternative *
3122 299429232 : preprocess_insn_constraints (unsigned int icode)
3123 : {
3124 299429232 : gcc_checking_assert (IN_RANGE (icode, 0, NUM_INSN_CODES - 1));
3125 299429232 : if (this_target_recog->x_op_alt[icode])
3126 : return this_target_recog->x_op_alt[icode];
3127 :
3128 5575796 : int n_operands = insn_data[icode].n_operands;
3129 5575796 : 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 3040750 : int n_alternatives = MAX (insn_data[icode].n_alternatives, 1);
3136 3040750 : int n_entries = n_operands * n_alternatives;
3137 :
3138 3040750 : operand_alternative *op_alt = XCNEWVEC (operand_alternative, n_entries);
3139 3040750 : const char **constraints = XALLOCAVEC (const char *, n_operands);
3140 :
3141 10330239 : for (int i = 0; i < n_operands; ++i)
3142 7289489 : constraints[i] = insn_data[icode].operand[i].constraint;
3143 3040750 : preprocess_constraints (n_operands, n_alternatives, constraints, op_alt,
3144 : NULL);
3145 :
3146 3040750 : this_target_recog->x_op_alt[icode] = op_alt;
3147 3040750 : 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 204107297 : preprocess_constraints (rtx_insn *insn)
3156 : {
3157 204107297 : int icode = INSN_CODE (insn);
3158 204107297 : if (icode >= 0)
3159 202333271 : recog_op_alt = preprocess_insn_constraints (icode);
3160 : else
3161 : {
3162 1774026 : int n_operands = recog_data.n_operands;
3163 1774026 : int n_alternatives = recog_data.n_alternatives;
3164 1774026 : int n_entries = n_operands * n_alternatives;
3165 1774026 : memset (asm_op_alt, 0, n_entries * sizeof (operand_alternative));
3166 1774026 : preprocess_constraints (n_operands, n_alternatives,
3167 1774026 : recog_data.constraints, asm_op_alt,
3168 : NULL);
3169 1774026 : recog_op_alt = asm_op_alt;
3170 : }
3171 204107297 : }
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 1156201744 : constrain_operands (int strict, alternative_mask alternatives)
3231 : {
3232 1157127613 : const char *constraints[MAX_RECOG_OPERANDS];
3233 1157127613 : int matching_operands[MAX_RECOG_OPERANDS];
3234 1157127613 : int earlyclobber[MAX_RECOG_OPERANDS];
3235 1157127613 : int c;
3236 :
3237 1157127613 : struct funny_match funny_match[MAX_RECOG_OPERANDS];
3238 1157127613 : int funny_match_index;
3239 :
3240 1157127613 : which_alternative = 0;
3241 1157127613 : if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
3242 : return true;
3243 :
3244 3440858234 : for (c = 0; c < recog_data.n_operands; c++)
3245 2344574516 : constraints[c] = recog_data.constraints[c];
3246 :
3247 4108817163 : do
3248 : {
3249 4108817163 : int seen_earlyclobber_at = -1;
3250 4108817163 : int opno;
3251 4108817163 : bool lose = false;
3252 4108817163 : funny_match_index = 0;
3253 :
3254 4108817163 : if (!TEST_BIT (alternatives, which_alternative))
3255 : {
3256 : int i;
3257 :
3258 2794866540 : for (i = 0; i < recog_data.n_operands; i++)
3259 3753062754 : constraints[i] = skip_alternative (constraints[i]);
3260 :
3261 918335163 : which_alternative++;
3262 918335163 : continue;
3263 918335163 : }
3264 :
3265 9811996695 : for (opno = 0; opno < recog_data.n_operands; opno++)
3266 6621514695 : matching_operands[opno] = -1;
3267 :
3268 9811996695 : for (opno = 0; opno < recog_data.n_operands; opno++)
3269 : {
3270 6621514695 : rtx op = recog_data.operand[opno];
3271 6621514695 : machine_mode mode = GET_MODE (op);
3272 6621514695 : const char *p = constraints[opno];
3273 6621514695 : int offset = 0;
3274 6621514695 : bool win = false;
3275 6621514695 : int val;
3276 6621514695 : int len;
3277 :
3278 6621514695 : earlyclobber[opno] = 0;
3279 :
3280 6621514695 : if (GET_CODE (op) == SUBREG)
3281 : {
3282 1545227 : if (REG_P (SUBREG_REG (op))
3283 1545227 : && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
3284 421 : offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
3285 421 : GET_MODE (SUBREG_REG (op)),
3286 421 : SUBREG_BYTE (op),
3287 : GET_MODE (op));
3288 1545227 : op = SUBREG_REG (op);
3289 : }
3290 :
3291 : /* An empty constraint or empty alternative
3292 : allows anything which matched the pattern. */
3293 6621514695 : if (*p == 0 || *p == ',')
3294 98646842 : win = true;
3295 :
3296 16717828329 : do
3297 16717828329 : switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
3298 : {
3299 : case '\0':
3300 : len = 0;
3301 : break;
3302 6267082165 : case ',':
3303 6267082165 : c = '\0';
3304 6267082165 : 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 486559 : case '&':
3319 486559 : earlyclobber[opno] = 1;
3320 486559 : if (seen_earlyclobber_at < 0)
3321 464773 : seen_earlyclobber_at = opno;
3322 : break;
3323 :
3324 192963323 : case '0': case '1': case '2': case '3': case '4':
3325 192963323 : case '5': case '6': case '7': case '8': case '9':
3326 192963323 : {
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 192963323 : char *end;
3337 192963323 : int match;
3338 :
3339 192963323 : match = strtoul (p, &end, 10);
3340 192963323 : p = end;
3341 :
3342 192963323 : if (strict < 0)
3343 : val = 1;
3344 : else
3345 : {
3346 192015554 : rtx op1 = recog_data.operand[match];
3347 192015554 : rtx op2 = recog_data.operand[opno];
3348 192015554 : val = operands_match_p (op1, op2);
3349 : }
3350 :
3351 192963323 : matching_operands[opno] = match;
3352 192963323 : matching_operands[match] = opno;
3353 :
3354 192963323 : if (val != 0)
3355 159093657 : 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 192963323 : 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 192963323 : len = 0;
3367 192963323 : 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 126565992 : 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 126565992 : if (REG_P (op))
3395 : {
3396 47683064 : if (strict < 0
3397 : || GENERAL_REGS == ALL_REGS
3398 47683012 : || (reload_in_progress
3399 0 : && REGNO (op) >= FIRST_PSEUDO_REGISTER)
3400 95366076 : || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
3401 : win = true;
3402 : }
3403 78882928 : else if (strict < 0 || general_operand (op, mode))
3404 : win = true;
3405 : break;
3406 :
3407 231 : case '{':
3408 222 : if ((REG_P (op) && HARD_REGISTER_P (op)
3409 222 : && (int) REGNO (op) == decode_hard_reg_constraint (p))
3410 242 : || !reload_completed)
3411 : win = true;
3412 : break;
3413 :
3414 9776029968 : default:
3415 9776029968 : {
3416 9776029968 : enum constraint_num cn = lookup_constraint (p);
3417 9776029968 : enum reg_class cl = reg_class_for_constraint (cn);
3418 4531390604 : if (cl != NO_REGS)
3419 : {
3420 4352121743 : auto *filter = get_register_filter (cn);
3421 4352121743 : if (strict < 0
3422 4350408055 : || (strict == 0
3423 23443037 : && REG_P (op)
3424 17137406 : && REGNO (op) >= FIRST_PSEUDO_REGISTER)
3425 6380744 : || (strict == 0 && GET_CODE (op) == SCRATCH)
3426 8685449373 : || (REG_P (op)
3427 3125304582 : && 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 5423908225 : else if (constraint_satisfied_p (op, cn))
3438 : win = true;
3439 :
3440 4530282356 : else if ((insn_extra_memory_constraint (cn)
3441 : || insn_extra_relaxed_memory_constraint (cn))
3442 : /* Every memory operand can be reloaded to fit. */
3443 4530282356 : && ((strict < 0 && MEM_P (op))
3444 : /* Before reload, accept what reload can turn
3445 : into a mem. */
3446 700816 : || (strict < 0 && CONSTANT_P (op))
3447 : /* Before reload, accept a pseudo or hard register,
3448 : since LRA can turn it into a mem. */
3449 700409 : || (strict < 0 && targetm.lra_p () && REG_P (op))
3450 : /* During reload, accept a pseudo */
3451 957659688 : || (reload_in_progress && REG_P (op)
3452 0 : && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
3453 : win = true;
3454 4529581540 : else if (insn_extra_address_constraint (cn)
3455 : /* Every address operand can be reloaded to fit. */
3456 4529581540 : && strict < 0)
3457 : win = true;
3458 : /* Cater to architectures like IA-64 that define extra memory
3459 : constraints without using define_memory_constraint. */
3460 4529581540 : 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 4529581540 : && constraint_satisfied_p
3466 0 : (reg_equiv_mem (REGNO (op)), cn))
3467 : win = true;
3468 : break;
3469 : }
3470 : }
3471 16717828329 : while (p += len, c);
3472 :
3473 6621514695 : raw_constraint_p = false;
3474 6621514695 : constraints[opno] = p;
3475 : /* If this operand did not win somehow,
3476 : this alternative loses. */
3477 6621514695 : if (! win)
3478 3193812779 : lose = true;
3479 : }
3480 : /* This alternative won; the operands are ok.
3481 : Change whichever operands this alternative says to change. */
3482 3190482000 : if (! lose)
3483 : {
3484 1091905813 : int opno, eopno;
3485 :
3486 : /* See if any earlyclobber operand conflicts with some other
3487 : operand. */
3488 :
3489 1091905813 : if (strict > 0 && seen_earlyclobber_at >= 0)
3490 1179715 : for (eopno = seen_earlyclobber_at;
3491 1556975 : 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 1179715 : if (earlyclobber[eopno]
3497 397214 : && REG_P (recog_data.operand[eopno]))
3498 2003603 : for (opno = 0; opno < recog_data.n_operands; opno++)
3499 1606389 : if ((MEM_P (recog_data.operand[opno])
3500 1468031 : || recog_data.operand_type[opno] != OP_OUT)
3501 936399 : && opno != eopno
3502 : /* Ignore things like match_operator operands. */
3503 935829 : && *recog_data.constraints[opno] != 0
3504 969446 : && ! (matching_operands[opno] == eopno
3505 109346 : && operands_match_p (recog_data.operand[opno],
3506 : recog_data.operand[eopno]))
3507 2359223 : && ! safe_from_earlyclobber (recog_data.operand[opno],
3508 752834 : recog_data.operand[eopno]))
3509 : lose = true;
3510 :
3511 1091905813 : if (! lose)
3512 : {
3513 1091901503 : 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 2098580497 : which_alternative++;
3547 : }
3548 3016915660 : while (which_alternative < recog_data.n_alternatives);
3549 :
3550 4382215 : 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 4382215 : 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 3425462691 : reg_fits_class_p (const_rtx operand, reg_class_t cl, int offset,
3566 : machine_mode mode)
3567 : {
3568 3425462691 : unsigned int regno = REGNO (operand);
3569 :
3570 3425462691 : if (cl == NO_REGS)
3571 : return false;
3572 :
3573 : /* Regno must not be a pseudo register. Offset may be negative. */
3574 3326125134 : return (HARD_REGISTER_NUM_P (regno)
3575 3326049007 : && HARD_REGISTER_NUM_P (regno + offset)
3576 6652174141 : && 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 394989920 : split_insn (rtx_insn *insn)
3586 : {
3587 : /* Split insns here to get max fine-grain parallelism. */
3588 394989920 : rtx_insn *first = PREV_INSN (insn);
3589 394989920 : rtx_insn *last = try_split (PATTERN (insn), insn, 1);
3590 394989920 : rtx insn_set, last_set, note;
3591 :
3592 394989920 : 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 6273944 : insn_set = single_set (insn);
3600 6273944 : if (insn_set)
3601 : {
3602 6150352 : last_set = single_set (last);
3603 6150352 : if (last_set && rtx_equal_p (SET_DEST (last_set), SET_DEST (insn_set)))
3604 : {
3605 2907439 : note = find_reg_equal_equiv_note (insn);
3606 2907439 : if (note && CONSTANT_P (XEXP (note, 0)))
3607 76345 : set_unique_reg_note (last, REG_EQUAL, XEXP (note, 0));
3608 2831094 : else if (CONSTANT_P (SET_SRC (insn_set)))
3609 34149 : 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 6273944 : 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 6273944 : if (reload_completed && first != last)
3620 : {
3621 5843360 : auto old_post_ra_split_completed = post_ra_split_completed;
3622 5843360 : post_ra_split_completed = true;
3623 5843360 : first = NEXT_INSN (first);
3624 2787296 : for (;;)
3625 : {
3626 8630656 : if (INSN_P (first))
3627 8626617 : cleanup_subreg_operands (first);
3628 8630656 : if (first == last)
3629 : break;
3630 2787296 : first = NEXT_INSN (first);
3631 : }
3632 5843360 : 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 4099303 : split_all_insns (void)
3642 : {
3643 4099303 : bool changed;
3644 4099303 : bool need_cfg_cleanup = false;
3645 4099303 : basic_block bb;
3646 :
3647 4099303 : auto_sbitmap blocks (last_basic_block_for_fn (cfun));
3648 4099303 : bitmap_clear (blocks);
3649 4099303 : changed = false;
3650 :
3651 44463802 : FOR_EACH_BB_REVERSE_FN (bb, cfun)
3652 : {
3653 40364499 : rtx_insn *insn, *next;
3654 40364499 : bool finish = false;
3655 :
3656 40364499 : rtl_profile_for_bb (bb);
3657 517884790 : 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 477520291 : next = NEXT_INSN (insn);
3662 477520291 : 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 477520291 : rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3675 477520291 : if (INSN_P (insn))
3676 : {
3677 395025424 : 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 395025424 : 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 35504 : if (reload_completed)
3690 35504 : delete_insn_and_edges (insn);
3691 35504 : if (note)
3692 0 : need_cfg_cleanup = true;
3693 : }
3694 : else
3695 : {
3696 394989920 : if (split_insn (insn))
3697 : {
3698 6273944 : bitmap_set_bit (blocks, bb->index);
3699 6273944 : changed = true;
3700 6273944 : if (note)
3701 2790 : need_cfg_cleanup = true;
3702 : }
3703 : }
3704 : }
3705 : }
3706 : }
3707 :
3708 4099303 : if (reload_completed)
3709 2582178 : post_ra_split_completed = true;
3710 :
3711 4099303 : default_rtl_profile ();
3712 4099303 : if (changed)
3713 : {
3714 774884 : 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 774884 : if (need_cfg_cleanup)
3721 1336 : cleanup_cfg (0);
3722 : }
3723 :
3724 4099303 : checking_verify_flow_info ();
3725 4099303 : }
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 435143967 : peep2_buf_position (int n)
3788 : {
3789 0 : if (n >= MAX_INSNS_PER_PEEP2 + 1)
3790 146794164 : n -= MAX_INSNS_PER_PEEP2 + 1;
3791 435143967 : 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 225685571 : peep2_next_insn (int n)
3800 : {
3801 225685571 : gcc_assert (n <= peep2_current_count);
3802 :
3803 225685571 : n = peep2_buf_position (peep2_current + n);
3804 :
3805 225685571 : 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 13448546 : peep2_regno_dead_p (int ofs, int regno)
3813 : {
3814 13448546 : gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3815 :
3816 13448546 : ofs = peep2_buf_position (peep2_current + ofs);
3817 :
3818 13448546 : gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3819 :
3820 13448546 : return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
3821 : }
3822 :
3823 : /* Similarly for a REG. */
3824 :
3825 : bool
3826 289549 : peep2_reg_dead_p (int ofs, rtx reg)
3827 : {
3828 289549 : gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3829 :
3830 289549 : ofs = peep2_buf_position (peep2_current + ofs);
3831 :
3832 289549 : gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3833 :
3834 289549 : unsigned int end_regno = END_REGNO (reg);
3835 371406 : for (unsigned int regno = REGNO (reg); regno < end_regno; ++regno)
3836 289549 : 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 608733 : peep2_find_free_register (int from, int to, const char *class_str,
3857 : machine_mode mode, HARD_REG_SET *reg_set)
3858 : {
3859 608733 : enum reg_class cl;
3860 608733 : HARD_REG_SET live;
3861 608733 : df_ref def;
3862 608733 : int i;
3863 :
3864 608733 : gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
3865 608733 : gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
3866 :
3867 608733 : from = peep2_buf_position (peep2_current + from);
3868 608733 : to = peep2_buf_position (peep2_current + to);
3869 :
3870 608733 : gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3871 608733 : REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
3872 :
3873 1238700 : while (from != to)
3874 : {
3875 21234 : gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3876 :
3877 : /* Don't use registers set or clobbered by the insn. */
3878 84936 : FOR_EACH_INSN_DEF (def, peep2_insn_data[from].insn)
3879 63702 : SET_HARD_REG_BIT (live, DF_REF_REGNO (def));
3880 :
3881 24327 : from = peep2_buf_position (from + 1);
3882 : }
3883 :
3884 608733 : cl = reg_class_for_constraint (lookup_constraint (class_str));
3885 :
3886 5960192 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3887 : {
3888 5955097 : int raw_regno, regno, j;
3889 5955097 : bool success;
3890 :
3891 : /* Distribute the free registers as much as possible. */
3892 5955097 : raw_regno = search_ofs + i;
3893 5955097 : if (raw_regno >= FIRST_PSEUDO_REGISTER)
3894 291428 : raw_regno -= FIRST_PSEUDO_REGISTER;
3895 : #ifdef REG_ALLOC_ORDER
3896 5955097 : regno = reg_alloc_order[raw_regno];
3897 : #else
3898 : regno = raw_regno;
3899 : #endif
3900 :
3901 : /* Can it support the mode we need? */
3902 5955097 : if (!targetm.hard_regno_mode_ok (regno, mode))
3903 1800864 : continue;
3904 :
3905 4757871 : success = true;
3906 4757871 : for (j = 0; success && j < hard_regno_nregs (regno, mode); j++)
3907 : {
3908 : /* Don't allocate fixed registers. */
3909 4154233 : if (fixed_regs[regno + j])
3910 : {
3911 : success = false;
3912 : break;
3913 : }
3914 : /* Don't allocate global registers. */
3915 2220137 : if (global_regs[regno + j])
3916 : {
3917 : success = false;
3918 : break;
3919 : }
3920 : /* Make sure the register is of the right class. */
3921 2220137 : 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 1234700 : if (! crtl->abi->clobbers_full_reg_p (regno + j)
3928 1234700 : && ! df_regs_ever_live_p (regno + j))
3929 : {
3930 : success = false;
3931 : break;
3932 : }
3933 :
3934 1198885 : 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 1198700 : if ((regno + j == FRAME_POINTER_REGNUM
3942 1198700 : || regno + j == HARD_FRAME_POINTER_REGNUM)
3943 50242 : && (! reload_completed || frame_pointer_needed))
3944 : {
3945 : success = false;
3946 : break;
3947 : }
3948 :
3949 1187953 : if (TEST_HARD_REG_BIT (*reg_set, regno + j)
3950 1187953 : || TEST_HARD_REG_BIT (live, regno + j))
3951 : {
3952 : success = false;
3953 : break;
3954 : }
3955 : }
3956 :
3957 4154233 : if (success)
3958 : {
3959 603638 : add_to_hard_reg_set (reg_set, mode, regno);
3960 :
3961 : /* Start the next search with the next register. */
3962 603638 : if (++raw_regno >= FIRST_PSEUDO_REGISTER)
3963 3912 : raw_regno = 0;
3964 603638 : search_ofs = raw_regno;
3965 :
3966 603638 : return gen_rtx_REG (mode, regno);
3967 : }
3968 : }
3969 :
3970 5095 : search_ofs = 0;
3971 5095 : return NULL_RTX;
3972 : }
3973 :
3974 : /* Forget all currently tracked instructions, only remember current
3975 : LIVE regset. */
3976 :
3977 : static void
3978 11024214 : peep2_reinit_state (regset live)
3979 : {
3980 11024214 : int i;
3981 :
3982 : /* Indicate that all slots except the last holds invalid data. */
3983 77169498 : for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
3984 66145284 : peep2_insn_data[i].insn = NULL;
3985 11024214 : peep2_current_count = 0;
3986 :
3987 : /* Indicate that the last slot contains live_after data. */
3988 11024214 : peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
3989 11024214 : peep2_current = MAX_INSNS_PER_PEEP2;
3990 :
3991 11024214 : COPY_REG_SET (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
3992 11024214 : }
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 135025 : copy_frame_info_to_split_insn (rtx_insn *old_insn, rtx_insn *new_insn)
3999 : {
4000 135025 : bool any_note = false;
4001 135025 : rtx note;
4002 :
4003 135025 : if (!RTX_FRAME_RELATED_P (old_insn))
4004 : return;
4005 :
4006 135025 : RTX_FRAME_RELATED_P (new_insn) = 1;
4007 :
4008 : /* Allow the backend to fill in a note during the split. */
4009 135025 : 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 135025 : if (!any_note)
4028 330218 : for (note = REG_NOTES (old_insn); note ; note = XEXP (note, 1))
4029 195193 : switch (REG_NOTE_KIND (note))
4030 : {
4031 147058 : case REG_FRAME_RELATED_EXPR:
4032 147058 : case REG_CFA_DEF_CFA:
4033 147058 : case REG_CFA_ADJUST_CFA:
4034 147058 : case REG_CFA_OFFSET:
4035 147058 : case REG_CFA_REGISTER:
4036 147058 : case REG_CFA_EXPRESSION:
4037 147058 : case REG_CFA_RESTORE:
4038 147058 : case REG_CFA_SET_VDRAP:
4039 147058 : add_reg_note (new_insn, REG_NOTE_KIND (note), XEXP (note, 0));
4040 147058 : any_note = true;
4041 147058 : 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 135025 : if (!any_note)
4049 : {
4050 2445 : rtx old_set, new_set;
4051 :
4052 : /* The old insn had better have been simple, or annotated. */
4053 2445 : old_set = single_set (old_insn);
4054 2445 : gcc_assert (old_set != NULL);
4055 :
4056 2445 : new_set = single_set (new_insn);
4057 2445 : 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 135025 : 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 2293153 : peep2_attempt (basic_block bb, rtx_insn *insn, int match_len, rtx_insn *attempt)
4073 : {
4074 2293153 : int i;
4075 2293153 : rtx_insn *last, *before_try, *x;
4076 2293153 : rtx eh_note, as_note;
4077 2293153 : rtx_insn *old_insn;
4078 2293153 : rtx_insn *new_insn;
4079 2293153 : 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 2293153 : old_insn = peep2_insn_data[peep2_current].insn;
4084 2293153 : if (RTX_FRAME_RELATED_P (old_insn))
4085 : {
4086 137828 : 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 137828 : if (active_insn_p (attempt))
4092 : new_insn = attempt;
4093 : else
4094 35400 : new_insn = next_active_insn (attempt);
4095 137828 : if (next_active_insn (new_insn))
4096 : return NULL;
4097 :
4098 : /* We have a 1-1 replacement. Copy over any frame-related info. */
4099 134988 : 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 4803777 : for (i = 0; i <= match_len; ++i)
4106 : {
4107 2514999 : int j;
4108 2514999 : rtx note;
4109 :
4110 2514999 : j = peep2_buf_position (peep2_current + i);
4111 2514999 : old_insn = peep2_insn_data[j].insn;
4112 2514999 : if (!CALL_P (old_insn))
4113 2513464 : 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 2290313 : as_note = NULL;
4161 4685718 : for (i = match_len; i >= 0; --i)
4162 : {
4163 2514999 : int j = peep2_buf_position (peep2_current + i);
4164 2514999 : old_insn = peep2_insn_data[j].insn;
4165 :
4166 2514999 : as_note = find_reg_note (old_insn, REG_ARGS_SIZE, NULL);
4167 2514999 : if (as_note)
4168 : break;
4169 : }
4170 :
4171 2290313 : i = peep2_buf_position (peep2_current + match_len);
4172 2290313 : 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 2290313 : rtx_insn *peepinsn = peep2_insn_data[i].insn;
4176 4580626 : last = emit_insn_after_setloc (attempt,
4177 : peep2_insn_data[i].insn,
4178 2290313 : INSN_LOCATION (peepinsn));
4179 2290313 : if (JUMP_P (peepinsn) && JUMP_P (last))
4180 832 : set_crossing_jump (last, CROSSING_JUMP_P (peepinsn));
4181 2290313 : before_try = PREV_INSN (insn);
4182 2290313 : delete_insn_chain (insn, peep2_insn_data[i].insn, false);
4183 :
4184 : /* Re-insert the EH_REGION notes. */
4185 2290313 : 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 2290313 : if (as_note)
4229 119594 : 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 2290313 : 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 5337847 : for (x = last; x != before_try; x = PREV_INSN (x))
4241 3048366 : 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 2290313 : peep2_update_life (basic_block bb, int match_len, rtx_insn *last,
4258 : rtx_insn *prev)
4259 : {
4260 2290313 : int i = peep2_buf_position (peep2_current + match_len + 1);
4261 2290313 : rtx_insn *x;
4262 2290313 : regset_head live;
4263 :
4264 2290313 : INIT_REG_SET (&live);
4265 2290313 : COPY_REG_SET (&live, peep2_insn_data[i].live_before);
4266 :
4267 2290313 : gcc_assert (peep2_current_count >= match_len + 1);
4268 2290313 : peep2_current_count -= match_len + 1;
4269 :
4270 2290313 : x = last;
4271 3049090 : do
4272 : {
4273 3049090 : if (INSN_P (x))
4274 : {
4275 3049090 : df_insn_rescan (x);
4276 3049090 : if (peep2_current_count < MAX_INSNS_PER_PEEP2)
4277 : {
4278 2899742 : peep2_current_count++;
4279 2899742 : if (--i < 0)
4280 842628 : i = MAX_INSNS_PER_PEEP2;
4281 2899742 : peep2_insn_data[i].insn = x;
4282 2899742 : df_simulate_one_insn_backwards (bb, x, &live);
4283 2899742 : COPY_REG_SET (peep2_insn_data[i].live_before, &live);
4284 : }
4285 : }
4286 3049090 : x = PREV_INSN (x);
4287 : }
4288 3049090 : while (x != prev);
4289 2290313 : CLEAR_REG_SET (&live);
4290 :
4291 2290313 : peep2_current = i;
4292 2290313 : }
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 84367495 : peep2_fill_buffer (basic_block bb, rtx_insn *insn, regset live)
4301 : {
4302 84367495 : 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 84367495 : 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 64944443 : if (RTX_FRAME_RELATED_P (insn))
4314 : {
4315 : /* Let the buffer drain first. */
4316 7787252 : if (peep2_current_count > 0)
4317 : return false;
4318 : /* Now the insn will be the only thing in the buffer. */
4319 : }
4320 :
4321 60603726 : pos = peep2_buf_position (peep2_current + peep2_current_count);
4322 60603726 : peep2_insn_data[pos].insn = insn;
4323 60603726 : COPY_REG_SET (peep2_insn_data[pos].live_before, live);
4324 60603726 : peep2_current_count++;
4325 :
4326 60603726 : df_simulate_one_insn_forwards (bb, insn, live);
4327 60603726 : return true;
4328 : }
4329 :
4330 : /* Perform the peephole2 optimization pass. */
4331 :
4332 : static void
4333 982739 : peephole2_optimize (void)
4334 : {
4335 982739 : rtx_insn *insn;
4336 982739 : bitmap live;
4337 982739 : int i;
4338 982739 : basic_block bb;
4339 :
4340 982739 : peep2_do_cleanup_cfg = false;
4341 982739 : peep2_do_rebuild_jump_labels = false;
4342 :
4343 982739 : df_set_flags (DF_LR_RUN_DCE);
4344 982739 : df_note_add_problem ();
4345 982739 : df_analyze ();
4346 :
4347 : /* Initialize the regsets we're going to use. */
4348 8844651 : for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
4349 6879173 : peep2_insn_data[i].live_before = BITMAP_ALLOC (®_obstack);
4350 982739 : search_ofs = 0;
4351 982739 : live = BITMAP_ALLOC (®_obstack);
4352 :
4353 12006953 : FOR_EACH_BB_REVERSE_FN (bb, cfun)
4354 : {
4355 11024214 : bool past_end = false;
4356 11024214 : int pos;
4357 :
4358 11024214 : rtl_profile_for_bb (bb);
4359 :
4360 : /* Start up propagation. */
4361 22048428 : bitmap_copy (live, DF_LR_IN (bb));
4362 11024214 : df_simulate_initialize_forwards (bb, live);
4363 11024214 : peep2_reinit_state (live);
4364 :
4365 11024214 : insn = BB_HEAD (bb);
4366 211062781 : for (;;)
4367 : {
4368 211062781 : rtx_insn *attempt, *head;
4369 211062781 : int match_len;
4370 :
4371 211062781 : if (!past_end && !NONDEBUG_INSN_P (insn))
4372 : {
4373 76156059 : next_insn:
4374 136759785 : insn = NEXT_INSN (insn);
4375 136759785 : if (insn == NEXT_INSN (BB_END (bb)))
4376 11024214 : past_end = true;
4377 139050098 : continue;
4378 : }
4379 84367495 : if (!past_end && peep2_fill_buffer (bb, insn, live))
4380 60603726 : goto next_insn;
4381 :
4382 : /* If we did not fill an empty buffer, it signals the end of the
4383 : block. */
4384 74302996 : if (peep2_current_count == 0)
4385 : break;
4386 :
4387 : /* The buffer filled to the current maximum, so try to match. */
4388 :
4389 63278782 : pos = peep2_buf_position (peep2_current + peep2_current_count);
4390 63278782 : peep2_insn_data[pos].insn = PEEP2_EOB;
4391 63278782 : COPY_REG_SET (peep2_insn_data[pos].live_before, live);
4392 :
4393 : /* Match the peephole. */
4394 63278782 : head = peep2_insn_data[peep2_current].insn;
4395 63278782 : attempt = peephole2_insns (PATTERN (head), head, &match_len);
4396 63278782 : if (attempt != NULL)
4397 : {
4398 2293153 : rtx_insn *last = peep2_attempt (bb, head, match_len, attempt);
4399 2293153 : if (last)
4400 : {
4401 2290313 : peep2_update_life (bb, match_len, last, PREV_INSN (attempt));
4402 2290313 : continue;
4403 : }
4404 : }
4405 :
4406 : /* No match: advance the buffer by one insn. */
4407 60988469 : peep2_current = peep2_buf_position (peep2_current + 1);
4408 60988469 : peep2_current_count--;
4409 : }
4410 : }
4411 :
4412 982739 : default_rtl_profile ();
4413 8844651 : for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
4414 6879173 : BITMAP_FREE (peep2_insn_data[i].live_before);
4415 982739 : BITMAP_FREE (live);
4416 982739 : if (peep2_do_rebuild_jump_labels)
4417 746 : rebuild_jump_labels (get_insns ());
4418 982739 : if (peep2_do_cleanup_cfg)
4419 0 : cleanup_cfg (CLEANUP_CFG_CHANGED);
4420 982739 : }
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 982739 : rest_of_handle_peephole2 (void)
4544 : {
4545 982739 : if (HAVE_peephole2)
4546 0 : peephole2_optimize ();
4547 :
4548 982739 : 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 297180 : pass_peephole2 (gcc::context *ctxt)
4570 594360 : : 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 1517135 : bool gate (function *) final override
4578 : {
4579 1517135 : return (optimize > 0 && flag_peephole2);
4580 : }
4581 982739 : unsigned int execute (function *) final override
4582 : {
4583 982739 : return rest_of_handle_peephole2 ();
4584 : }
4585 :
4586 : }; // class pass_peephole2
4587 :
4588 : } // anon namespace
4589 :
4590 : rtl_opt_pass *
4591 297180 : make_pass_peephole2 (gcc::context *ctxt)
4592 : {
4593 297180 : 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 297180 : pass_split_all_insns (gcc::context *ctxt)
4615 594360 : : 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 1517125 : unsigned int execute (function *) final override
4626 : {
4627 1517125 : split_all_insns ();
4628 1517125 : return 0;
4629 : }
4630 :
4631 : }; // class pass_split_all_insns
4632 :
4633 : } // anon namespace
4634 :
4635 : rtl_opt_pass *
4636 297180 : make_pass_split_all_insns (gcc::context *ctxt)
4637 : {
4638 297180 : 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 297180 : pass_split_after_reload (gcc::context *ctxt)
4660 594360 : : rtl_opt_pass (pass_data_split_after_reload, ctxt)
4661 : {}
4662 :
4663 : /* opt_pass methods: */
4664 1517135 : bool gate (function *) final override
4665 : {
4666 : /* If optimizing, then go ahead and split insns now. */
4667 1517135 : return optimize > 0;
4668 : }
4669 :
4670 1064963 : unsigned int execute (function *) final override
4671 : {
4672 1064963 : split_all_insns ();
4673 1064963 : return 0;
4674 : }
4675 :
4676 : }; // class pass_split_after_reload
4677 :
4678 : } // anon namespace
4679 :
4680 : rtl_opt_pass *
4681 297180 : make_pass_split_after_reload (gcc::context *ctxt)
4682 : {
4683 297180 : return new pass_split_after_reload (ctxt);
4684 : }
4685 :
4686 : static bool
4687 3034270 : enable_split_before_sched2 (void)
4688 : {
4689 : #ifdef INSN_SCHEDULING
4690 2129928 : 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 297180 : pass_split_before_sched2 (gcc::context *ctxt)
4715 594360 : : rtl_opt_pass (pass_data_split_before_sched2, ctxt)
4716 : {}
4717 :
4718 : /* opt_pass methods: */
4719 1517135 : bool gate (function *) final override
4720 : {
4721 1517135 : return enable_split_before_sched2 ();
4722 : }
4723 :
4724 982732 : unsigned int execute (function *) final override
4725 : {
4726 982732 : split_all_insns ();
4727 982732 : return 0;
4728 : }
4729 :
4730 : }; // class pass_split_before_sched2
4731 :
4732 : } // anon namespace
4733 :
4734 : rtl_opt_pass *
4735 297180 : make_pass_split_before_sched2 (gcc::context *ctxt)
4736 : {
4737 297180 : 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 297180 : pass_split_before_regstack (gcc::context *ctxt)
4759 594360 : : rtl_opt_pass (pass_data_split_before_regstack, ctxt)
4760 : {}
4761 :
4762 : /* opt_pass methods: */
4763 : bool gate (function *) final override;
4764 534483 : unsigned int execute (function *) final override
4765 : {
4766 534483 : split_all_insns ();
4767 534483 : return 0;
4768 : }
4769 :
4770 : }; // class pass_split_before_regstack
4771 :
4772 : bool
4773 1517135 : 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 2499868 : 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 297180 : make_pass_split_before_regstack (gcc::context *ctxt)
4795 : {
4796 297180 : 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 297180 : pass_split_for_shorten_branches (gcc::context *ctxt)
4818 594360 : : rtl_opt_pass (pass_data_split_for_shorten_branches, ctxt)
4819 : {}
4820 :
4821 : /* opt_pass methods: */
4822 1517135 : 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 1517135 : 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 297180 : make_pass_split_for_shorten_branches (gcc::context *ctxt)
4845 : {
4846 297180 : 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 222149 : recog_init ()
4853 : {
4854 : /* The information is zero-initialized, so we don't need to do anything
4855 : first time round. */
4856 222149 : if (!this_target_recog->x_initialized)
4857 : {
4858 221089 : this_target_recog->x_initialized = true;
4859 221089 : return;
4860 : }
4861 1060 : memset (this_target_recog->x_bool_attr_masks, 0,
4862 : sizeof (this_target_recog->x_bool_attr_masks));
4863 14873920 : for (unsigned int i = 0; i < NUM_INSN_CODES; ++i)
4864 14872860 : if (this_target_recog->x_op_alt[i])
4865 : {
4866 9946 : free (this_target_recog->x_op_alt[i]);
4867 9946 : this_target_recog->x_op_alt[i] = 0;
4868 : }
4869 : }
|