rtl.def (CALL_PLACEHOLDER): New rtx code.
[gcc.git] / gcc / flow.c
1 /* Data flow analysis for GNU compiler.
2 Copyright (C) 1987, 88, 92-98, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21
22 /* This file contains the data flow analysis pass of the compiler.
23 It computes data flow information
24 which tells combine_instructions which insns to consider combining
25 and controls register allocation.
26
27 Additional data flow information that is too bulky to record
28 is generated during the analysis, and is used at that time to
29 create autoincrement and autodecrement addressing.
30
31 The first step is dividing the function into basic blocks.
32 find_basic_blocks does this. Then life_analysis determines
33 where each register is live and where it is dead.
34
35 ** find_basic_blocks **
36
37 find_basic_blocks divides the current function's rtl
38 into basic blocks. It records the beginnings and ends of the
39 basic blocks in the vectors basic_block_head and basic_block_end,
40 and the number of blocks in n_basic_blocks.
41
42 find_basic_blocks also finds any unreachable loops
43 and deletes them.
44
45 ** life_analysis **
46
47 life_analysis is called immediately after find_basic_blocks.
48 It uses the basic block information to determine where each
49 hard or pseudo register is live.
50
51 ** live-register info **
52
53 The information about where each register is live is in two parts:
54 the REG_NOTES of insns, and the vector basic_block_live_at_start.
55
56 basic_block_live_at_start has an element for each basic block,
57 and the element is a bit-vector with a bit for each hard or pseudo
58 register. The bit is 1 if the register is live at the beginning
59 of the basic block.
60
61 Two types of elements can be added to an insn's REG_NOTES.
62 A REG_DEAD note is added to an insn's REG_NOTES for any register
63 that meets both of two conditions: The value in the register is not
64 needed in subsequent insns and the insn does not replace the value in
65 the register (in the case of multi-word hard registers, the value in
66 each register must be replaced by the insn to avoid a REG_DEAD note).
67
68 In the vast majority of cases, an object in a REG_DEAD note will be
69 used somewhere in the insn. The (rare) exception to this is if an
70 insn uses a multi-word hard register and only some of the registers are
71 needed in subsequent insns. In that case, REG_DEAD notes will be
72 provided for those hard registers that are not subsequently needed.
73 Partial REG_DEAD notes of this type do not occur when an insn sets
74 only some of the hard registers used in such a multi-word operand;
75 omitting REG_DEAD notes for objects stored in an insn is optional and
76 the desire to do so does not justify the complexity of the partial
77 REG_DEAD notes.
78
79 REG_UNUSED notes are added for each register that is set by the insn
80 but is unused subsequently (if every register set by the insn is unused
81 and the insn does not reference memory or have some other side-effect,
82 the insn is deleted instead). If only part of a multi-word hard
83 register is used in a subsequent insn, REG_UNUSED notes are made for
84 the parts that will not be used.
85
86 To determine which registers are live after any insn, one can
87 start from the beginning of the basic block and scan insns, noting
88 which registers are set by each insn and which die there.
89
90 ** Other actions of life_analysis **
91
92 life_analysis sets up the LOG_LINKS fields of insns because the
93 information needed to do so is readily available.
94
95 life_analysis deletes insns whose only effect is to store a value
96 that is never used.
97
98 life_analysis notices cases where a reference to a register as
99 a memory address can be combined with a preceding or following
100 incrementation or decrementation of the register. The separate
101 instruction to increment or decrement is deleted and the address
102 is changed to a POST_INC or similar rtx.
103
104 Each time an incrementing or decrementing address is created,
105 a REG_INC element is added to the insn's REG_NOTES list.
106
107 life_analysis fills in certain vectors containing information about
108 register usage: reg_n_refs, reg_n_deaths, reg_n_sets, reg_live_length,
109 reg_n_calls_crosses and reg_basic_block.
110
111 life_analysis sets current_function_sp_is_unchanging if the function
112 doesn't modify the stack pointer. */
113 \f
114 #include "config.h"
115 #include "system.h"
116 #include "rtl.h"
117 #include "basic-block.h"
118 #include "insn-config.h"
119 #include "regs.h"
120 #include "hard-reg-set.h"
121 #include "flags.h"
122 #include "output.h"
123 #include "except.h"
124 #include "toplev.h"
125 #include "recog.h"
126
127 #include "obstack.h"
128 #define obstack_chunk_alloc xmalloc
129 #define obstack_chunk_free free
130
131 #define XNMALLOC(TYPE, COUNT) ((TYPE *) xmalloc ((COUNT) * sizeof (TYPE)))
132
133 /* The contents of the current function definition are allocated
134 in this obstack, and all are freed at the end of the function.
135 For top-level functions, this is temporary_obstack.
136 Separate obstacks are made for nested functions. */
137
138 extern struct obstack *function_obstack;
139
140 /* List of labels that must never be deleted. */
141 extern rtx forced_labels;
142
143 /* Get the basic block number of an insn.
144 This info should not be expected to remain available
145 after the end of life_analysis. */
146
147 /* This is the limit of the allocated space in the following two arrays. */
148
149 static int max_uid_for_flow;
150
151 #define BLOCK_NUM(INSN) uid_block_number[INSN_UID (INSN)]
152
153 /* This is where the BLOCK_NUM values are really stored.
154 This is set up by find_basic_blocks and used there and in life_analysis,
155 and then freed. */
156
157 int *uid_block_number;
158
159 /* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile. */
160
161 #define INSN_VOLATILE(INSN) uid_volatile[INSN_UID (INSN)]
162 static char *uid_volatile;
163
164 /* Nonzero if the second flow pass has completed. */
165 int flow2_completed;
166
167 /* Number of basic blocks in the current function. */
168
169 int n_basic_blocks;
170
171 /* Maximum register number used in this function, plus one. */
172
173 int max_regno;
174
175 /* Indexed by n, giving various register information */
176
177 varray_type reg_n_info;
178
179 /* Size of the reg_n_info table. */
180
181 unsigned int reg_n_max;
182
183 /* Element N is the next insn that uses (hard or pseudo) register number N
184 within the current basic block; or zero, if there is no such insn.
185 This is valid only during the final backward scan in propagate_block. */
186
187 static rtx *reg_next_use;
188
189 /* Size of a regset for the current function,
190 in (1) bytes and (2) elements. */
191
192 int regset_bytes;
193 int regset_size;
194
195 /* Element N is first insn in basic block N.
196 This info lasts until we finish compiling the function. */
197
198 rtx *x_basic_block_head;
199
200 /* Element N is last insn in basic block N.
201 This info lasts until we finish compiling the function. */
202
203 rtx *x_basic_block_end;
204
205 /* Element N indicates whether basic block N can be reached through a
206 computed jump. */
207
208 char *basic_block_computed_jump_target;
209
210 /* Element N is a regset describing the registers live
211 at the start of basic block N.
212 This info lasts until we finish compiling the function. */
213
214 regset *basic_block_live_at_start;
215
216 /* Regset of regs live when calls to `setjmp'-like functions happen. */
217
218 regset regs_live_at_setjmp;
219
220 /* List made of EXPR_LIST rtx's which gives pairs of pseudo registers
221 that have to go in the same hard reg.
222 The first two regs in the list are a pair, and the next two
223 are another pair, etc. */
224 rtx regs_may_share;
225
226 /* Pointer to head of predecessor/successor block list. */
227 static int_list_block *flow_int_list_blocks;
228
229 /* Element N is the list of successors of basic block N. */
230 static int_list_ptr *basic_block_succ;
231
232 /* Element N is the list of predecessors of basic block N. */
233 static int_list_ptr *basic_block_pred;
234
235 /* Element N is depth within loops of the last insn in basic block number N.
236 Freed after life_analysis. */
237
238 static short *basic_block_loop_depth;
239
240 /* Depth within loops of basic block being scanned for lifetime analysis,
241 plus one. This is the weight attached to references to registers. */
242
243 static int loop_depth;
244
245 /* During propagate_block, this is non-zero if the value of CC0 is live. */
246
247 static int cc0_live;
248
249 /* During propagate_block, this contains a list of all the MEMs we are
250 tracking for dead store elimination. */
251
252 static rtx mem_set_list;
253
254 /* Set of registers that may be eliminable. These are handled specially
255 in updating regs_ever_live. */
256
257 static HARD_REG_SET elim_reg_set;
258
259 /* Forward declarations */
260 static void find_basic_blocks_1 PROTO((rtx, rtx));
261 static void add_edge PROTO((int, int));
262 static void add_edge_to_label PROTO((int, rtx));
263 static void make_edges PROTO((int));
264 static void mark_label_ref PROTO((int, rtx));
265 static void delete_unreachable_blocks PROTO((void));
266 static int delete_block PROTO((int));
267 static void life_analysis_1 PROTO((rtx, int));
268 static void propagate_block PROTO((regset, rtx, rtx, int,
269 regset, int));
270 static int set_noop_p PROTO((rtx));
271 static int noop_move_p PROTO((rtx));
272 static void record_volatile_insns PROTO((rtx));
273 static void mark_regs_live_at_end PROTO((regset));
274 static int insn_dead_p PROTO((rtx, regset, int, rtx));
275 static int libcall_dead_p PROTO((rtx, regset, rtx, rtx));
276 static void mark_set_regs PROTO((regset, regset, rtx,
277 rtx, regset));
278 static void mark_set_1 PROTO((regset, regset, rtx,
279 rtx, regset));
280 #ifdef AUTO_INC_DEC
281 static void find_auto_inc PROTO((regset, rtx, rtx));
282 static int try_pre_increment_1 PROTO((rtx));
283 static int try_pre_increment PROTO((rtx, rtx, HOST_WIDE_INT));
284 #endif
285 static void mark_used_regs PROTO((regset, regset, rtx, int, rtx));
286 void dump_flow_info PROTO((FILE *));
287 static void add_pred_succ PROTO ((int, int, int_list_ptr *,
288 int_list_ptr *, int *, int *));
289 static int_list_ptr alloc_int_list_node PROTO ((int_list_block **));
290 static int_list_ptr add_int_list_node PROTO ((int_list_block **,
291 int_list **, int));
292 static void init_regset_vector PROTO ((regset *, int,
293 struct obstack *));
294 static void count_reg_sets_1 PROTO ((rtx));
295 static void count_reg_sets PROTO ((rtx));
296 static void count_reg_references PROTO ((rtx));
297 static void notice_stack_pointer_modification PROTO ((rtx, rtx));
298 static void invalidate_mems_from_autoinc PROTO ((rtx));
299 \f
300 /* Find basic blocks of the current function.
301 F is the first insn of the function and NREGS the number of register numbers
302 in use. */
303
304 void
305 find_basic_blocks (f, nregs, file)
306 rtx f;
307 int nregs;
308 FILE *file;
309 {
310 register rtx insn;
311 register int i;
312 rtx nonlocal_label_list = nonlocal_label_rtx_list ();
313
314 /* Avoid leaking memory if this is called multiple times per compiled
315 function. */
316 free_bb_memory ();
317
318 /* Count the basic blocks. Also find maximum insn uid value used. */
319
320 {
321 rtx prev_call = 0;
322 register RTX_CODE prev_code = JUMP_INSN;
323 register RTX_CODE code;
324 int eh_region = 0;
325 int call_had_abnormal_edge = 0;
326
327 for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
328 {
329 code = GET_CODE (insn);
330
331 /* A basic block starts at label, or after something that can jump. */
332 if (code == CODE_LABEL
333 || (GET_RTX_CLASS (code) == 'i'
334 && (prev_code == JUMP_INSN
335 || (prev_code == CALL_INSN && call_had_abnormal_edge)
336 || prev_code == BARRIER)))
337 {
338 i++;
339
340 /* If the previous insn was a call that did not create an
341 abnormal edge, we want to add a nop so that the CALL_INSN
342 itself is not at basic block end. This allows us to easily
343 distinguish between normal calls and those which create
344 abnormal edges in the flow graph. */
345
346 if (i > 0 && !call_had_abnormal_edge && prev_call != 0)
347 {
348 rtx nop = gen_rtx_USE (VOIDmode, const0_rtx);
349 emit_insn_after (nop, prev_call);
350 }
351 }
352
353 if (code == CALL_INSN)
354 {
355 rtx note = find_reg_note(insn, REG_EH_REGION, NULL_RTX);
356
357 /* We change the code of the CALL_INSN, so that it won't start a
358 new block. */
359 if (note && XINT (XEXP (note, 0), 0) == 0)
360 code = INSN;
361 else
362 {
363 prev_call = insn;
364 call_had_abnormal_edge = (nonlocal_label_list != 0
365 || eh_region);
366 }
367 }
368
369 else if (code != NOTE && code != BARRIER)
370 prev_call = 0;
371
372 if (code != NOTE)
373 prev_code = code;
374 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
375 ++eh_region;
376 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
377 --eh_region;
378 }
379 }
380
381 n_basic_blocks = i;
382
383 max_uid_for_flow = get_max_uid ();
384 #ifdef AUTO_INC_DEC
385 /* Leave space for insns life_analysis makes in some cases for auto-inc.
386 These cases are rare, so we don't need too much space. */
387 max_uid_for_flow += max_uid_for_flow / 10;
388 #endif
389
390 /* Allocate some tables that last till end of compiling this function
391 and some needed only in find_basic_blocks and life_analysis. */
392
393 x_basic_block_head = XNMALLOC (rtx, n_basic_blocks);
394 x_basic_block_end = XNMALLOC (rtx, n_basic_blocks);
395 basic_block_succ = XNMALLOC (int_list_ptr, n_basic_blocks);
396 basic_block_pred = XNMALLOC (int_list_ptr, n_basic_blocks);
397 bzero ((char *)basic_block_succ, n_basic_blocks * sizeof (int_list_ptr));
398 bzero ((char *)basic_block_pred, n_basic_blocks * sizeof (int_list_ptr));
399
400 basic_block_computed_jump_target = (char *) oballoc (n_basic_blocks);
401 basic_block_loop_depth = XNMALLOC (short, n_basic_blocks);
402 uid_block_number = XNMALLOC (int, (max_uid_for_flow + 1));
403 uid_volatile = XNMALLOC (char, (max_uid_for_flow + 1));
404 bzero (uid_volatile, max_uid_for_flow + 1);
405
406 find_basic_blocks_1 (f, nonlocal_label_list);
407 }
408
409 /* For communication between find_basic_blocks_1 and its subroutines. */
410
411 /* An array of CODE_LABELs, indexed by UID for the start of the active
412 EH handler for each insn in F. */
413 static int *active_eh_region;
414 static int *nested_eh_region;
415
416 /* Element N nonzero if basic block N can actually be reached. */
417
418 static char *block_live_static;
419
420 /* List of label_refs to all labels whose addresses are taken
421 and used as data. */
422 static rtx label_value_list;
423
424 /* a list of non-local labels in the function. */
425 static rtx nonlocal_label_list;
426
427 /* Find all basic blocks of the function whose first insn is F.
428 Store the correct data in the tables that describe the basic blocks,
429 set up the chains of references for each CODE_LABEL, and
430 delete any entire basic blocks that cannot be reached.
431
432 NONLOCAL_LABELS is a list of non-local labels in the function.
433 Blocks that are otherwise unreachable may be reachable with a non-local
434 goto. */
435
436 static void
437 find_basic_blocks_1 (f, nonlocal_labels)
438 rtx f, nonlocal_labels;
439 {
440 register rtx insn;
441 register int i;
442 register char *block_live = (char *) alloca (n_basic_blocks);
443 register char *block_marked = (char *) alloca (n_basic_blocks);
444 rtx note, eh_note;
445 enum rtx_code prev_code, code;
446 int depth;
447 int call_had_abnormal_edge = 0;
448
449 active_eh_region = (int *) alloca ((max_uid_for_flow + 1) * sizeof (int));
450 nested_eh_region = (int *) alloca ((max_label_num () + 1) * sizeof (int));
451 nonlocal_label_list = nonlocal_labels;
452
453 label_value_list = 0;
454 block_live_static = block_live;
455 bzero (block_live, n_basic_blocks);
456 bzero (block_marked, n_basic_blocks);
457 bzero (basic_block_computed_jump_target, n_basic_blocks);
458 bzero ((char *) active_eh_region, (max_uid_for_flow + 1) * sizeof (int));
459 bzero ((char *) nested_eh_region, (max_label_num () + 1) * sizeof (int));
460 current_function_has_computed_jump = 0;
461
462 /* Initialize with just block 0 reachable and no blocks marked. */
463 if (n_basic_blocks > 0)
464 block_live[0] = 1;
465
466 /* Initialize the ref chain of each label to 0. Record where all the
467 blocks start and end and their depth in loops. For each insn, record
468 the block it is in. Also mark as reachable any blocks headed by labels
469 that must not be deleted. */
470
471 for (eh_note = NULL_RTX, insn = f, i = -1, prev_code = JUMP_INSN, depth = 1;
472 insn; insn = NEXT_INSN (insn))
473 {
474 code = GET_CODE (insn);
475 if (code == NOTE)
476 {
477 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
478 depth++;
479 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
480 depth--;
481 }
482
483 /* A basic block starts at label, or after something that can jump. */
484 else if (code == CODE_LABEL
485 || (GET_RTX_CLASS (code) == 'i'
486 && (prev_code == JUMP_INSN
487 || (prev_code == CALL_INSN && call_had_abnormal_edge)
488 || prev_code == BARRIER)))
489 {
490 BLOCK_HEAD (++i) = insn;
491 BLOCK_END (i) = insn;
492 basic_block_loop_depth[i] = depth;
493
494 if (code == CODE_LABEL)
495 {
496 LABEL_REFS (insn) = insn;
497 /* Any label that cannot be deleted
498 is considered to start a reachable block. */
499 if (LABEL_PRESERVE_P (insn))
500 block_live[i] = 1;
501 }
502 }
503
504 else if (GET_RTX_CLASS (code) == 'i')
505 {
506 BLOCK_END (i) = insn;
507 basic_block_loop_depth[i] = depth;
508 }
509
510 if (GET_RTX_CLASS (code) == 'i')
511 {
512 /* Make a list of all labels referred to other than by jumps. */
513 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
514 if (REG_NOTE_KIND (note) == REG_LABEL
515 && XEXP (note, 0) != eh_return_stub_label)
516 label_value_list = gen_rtx_EXPR_LIST (VOIDmode, XEXP (note, 0),
517 label_value_list);
518 }
519
520 /* Keep a lifo list of the currently active exception notes. */
521 if (GET_CODE (insn) == NOTE)
522 {
523 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
524 {
525 if (eh_note)
526 nested_eh_region [NOTE_BLOCK_NUMBER (insn)] =
527 NOTE_BLOCK_NUMBER (XEXP (eh_note, 0));
528 else
529 nested_eh_region [NOTE_BLOCK_NUMBER (insn)] = 0;
530 eh_note = gen_rtx_EXPR_LIST (VOIDmode,
531 insn, eh_note);
532 }
533 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
534 eh_note = XEXP (eh_note, 1);
535 }
536 /* If we encounter a CALL_INSN, note which exception handler it
537 might pass control to.
538
539 If doing asynchronous exceptions, record the active EH handler
540 for every insn, since most insns can throw. */
541 else if (eh_note
542 && (asynchronous_exceptions
543 || (GET_CODE (insn) == CALL_INSN)))
544 active_eh_region[INSN_UID (insn)] =
545 NOTE_BLOCK_NUMBER (XEXP (eh_note, 0));
546 BLOCK_NUM (insn) = i;
547
548 /* We change the code of the CALL_INSN, so that it won't start a
549 new block if it doesn't throw. */
550 if (code == CALL_INSN)
551 {
552 rtx rnote = find_reg_note(insn, REG_EH_REGION, NULL_RTX);
553 if (rnote && XINT (XEXP (rnote, 0), 0) == 0)
554 code = INSN;
555 }
556
557 /* Record whether this call created an edge. */
558 if (code == CALL_INSN)
559 call_had_abnormal_edge = (nonlocal_label_list != 0 || eh_note);
560
561 if (code != NOTE)
562 prev_code = code;
563
564 }
565
566 if (i + 1 != n_basic_blocks)
567 abort ();
568
569 /* Now find which basic blocks can actually be reached
570 and put all jump insns' LABEL_REFS onto the ref-chains
571 of their target labels. */
572
573 if (n_basic_blocks > 0)
574 {
575 int something_marked = 1;
576
577 /* Pass over all blocks, marking each block that is reachable
578 and has not yet been marked.
579 Keep doing this until, in one pass, no blocks have been marked.
580 Then blocks_live and blocks_marked are identical and correct.
581 In addition, all jumps actually reachable have been marked. */
582
583 while (something_marked)
584 {
585 something_marked = 0;
586 for (i = 0; i < n_basic_blocks; i++)
587 if (block_live[i] && !block_marked[i])
588 {
589 int_list_ptr p;
590
591 block_marked[i] = 1;
592 something_marked = 1;
593
594 make_edges (i);
595
596 for (p = basic_block_succ[i]; p; p = p->next)
597 block_live[INT_LIST_VAL (p)] = 1;
598 }
599 }
600
601 /* This should never happen. If it does that means we've computed an
602 incorrect flow graph, which can lead to aborts/crashes later in the
603 compiler or incorrect code generation.
604
605 We used to try and continue here, but that's just asking for trouble
606 later during the compile or at runtime. It's easier to debug the
607 problem here than later! */
608 for (i = 1; i < n_basic_blocks; i++)
609 if (block_live[i] && basic_block_pred[i] == 0)
610 abort ();
611
612 if (! reload_completed)
613 delete_unreachable_blocks ();
614 }
615 }
616
617 /* Record INSN's block number as BB. */
618
619 void
620 set_block_num (insn, bb)
621 rtx insn;
622 int bb;
623 {
624 if (INSN_UID (insn) >= max_uid_for_flow)
625 {
626 /* Add one-eighth the size so we don't keep calling xrealloc. */
627 max_uid_for_flow = INSN_UID (insn) + (INSN_UID (insn) + 7) / 8;
628 uid_block_number = (int *)
629 xrealloc (uid_block_number, (max_uid_for_flow + 1) * sizeof (int));
630 }
631 BLOCK_NUM (insn) = bb;
632 }
633 \f
634 /* Subroutines of find_basic_blocks. */
635
636 void
637 free_bb_memory ()
638 {
639 free_int_list (&flow_int_list_blocks);
640 }
641
642 /* Make an edge in the cfg from block PRED to block SUCC. */
643 static void
644 add_edge (pred, succ)
645 int pred, succ;
646 {
647 add_int_list_node (&flow_int_list_blocks, basic_block_pred + succ, pred);
648 add_int_list_node (&flow_int_list_blocks, basic_block_succ + pred, succ);
649 }
650
651 /* Make an edge in the cfg from block PRED to the block starting with
652 label LABEL. */
653 static void
654 add_edge_to_label (pred, label)
655 int pred;
656 rtx label;
657 {
658 /* If the label was never emitted, this insn is junk,
659 but avoid a crash trying to refer to BLOCK_NUM (label).
660 This can happen as a result of a syntax error
661 and a diagnostic has already been printed. */
662 if (INSN_UID (label) == 0)
663 return;
664
665 add_edge (pred, BLOCK_NUM (label));
666 }
667
668 /* Check expression X for label references. If one is found, add an edge
669 from basic block PRED to the block beginning with the label. */
670
671 static void
672 mark_label_ref (pred, x)
673 int pred;
674 rtx x;
675 {
676 register RTX_CODE code;
677 register int i;
678 register char *fmt;
679
680 code = GET_CODE (x);
681 if (code == LABEL_REF)
682 {
683 add_edge_to_label (pred, XEXP (x, 0));
684 return;
685 }
686
687 fmt = GET_RTX_FORMAT (code);
688 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
689 {
690 if (fmt[i] == 'e')
691 mark_label_ref (pred, XEXP (x, i));
692 if (fmt[i] == 'E')
693 {
694 register int j;
695 for (j = 0; j < XVECLEN (x, i); j++)
696 mark_label_ref (pred, XVECEXP (x, i, j));
697 }
698 }
699 }
700
701 /* For basic block I, make edges and mark live all blocks which are reachable
702 from it. */
703 static void
704 make_edges (i)
705 int i;
706 {
707 rtx insn, x;
708 rtx pending_eh_region = NULL_RTX;
709
710 /* See if control drops into the next block. */
711 if (i + 1 < n_basic_blocks)
712 {
713 for (insn = PREV_INSN (BLOCK_HEAD (i + 1));
714 insn && GET_CODE (insn) == NOTE; insn = PREV_INSN (insn))
715 ;
716
717 if (insn && GET_CODE (insn) != BARRIER)
718 add_edge (i, i + 1);
719 }
720
721 insn = BLOCK_END (i);
722 if (GET_CODE (insn) == JUMP_INSN)
723 mark_label_ref (i, PATTERN (insn));
724
725 /* If we have any forced labels, mark them as potentially reachable from
726 this block. */
727 for (x = forced_labels; x; x = XEXP (x, 1))
728 if (! LABEL_REF_NONLOCAL_P (x))
729 add_edge_to_label (i, XEXP (x, 0));
730
731 /* Now scan the insns for this block, we may need to make edges for some of
732 them to various non-obvious locations (exception handlers, nonlocal
733 labels, etc). */
734 for (insn = BLOCK_HEAD (i);
735 insn != NEXT_INSN (BLOCK_END (i));
736 insn = NEXT_INSN (insn))
737 {
738 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
739 {
740 rtx note;
741 /* References to labels in non-jumping insns have REG_LABEL notes
742 attached to them.
743
744 This can happen for computed gotos; we don't care about them
745 here since the values are also on the label_value_list and will
746 be marked live if we find a live computed goto.
747
748 This can also happen when we take the address of a label to pass
749 as an argument to __throw. Note throw only uses the value to
750 determine what handler should be called -- ie the label is not
751 used as a jump target, it just marks regions in the code.
752
753 In theory we should be able to ignore the REG_LABEL notes, but
754 we have to make sure that the label and associated insns aren't
755 marked dead, so we make the block in question live and create an
756 edge from this insn to the label. This is not strictly correct,
757 but it is close enough for now.
758
759 See below for code that handles the eh_stub label specially. */
760 for (note = REG_NOTES (insn);
761 note;
762 note = XEXP (note, 1))
763 {
764 if (REG_NOTE_KIND (note) == REG_LABEL
765 && XEXP (note, 0) != eh_return_stub_label)
766 add_edge_to_label (i, XEXP (note, 0));
767 }
768
769 /* If this is a computed jump, then mark it as reaching everything
770 on the label_value_list and forced_labels list. */
771 if (computed_jump_p (insn))
772 {
773 current_function_has_computed_jump = 1;
774 for (x = label_value_list; x; x = XEXP (x, 1))
775 {
776 int b = BLOCK_NUM (XEXP (x, 0));
777 basic_block_computed_jump_target[b] = 1;
778 add_edge (i, b);
779 }
780
781 for (x = forced_labels; x; x = XEXP (x, 1))
782 {
783 int b = BLOCK_NUM (XEXP (x, 0));
784 basic_block_computed_jump_target[b] = 1;
785 add_edge (i, b);
786 }
787 }
788
789 /* If this is a call with an EH_RETHROW note, then we
790 know its a rethrow call, and we know exactly where
791 this call can end up going. */
792 else if (GET_CODE (insn) == CALL_INSN
793 && (note = find_reg_note (insn, REG_EH_RETHROW, NULL_RTX)))
794 {
795 int region = XINT (XEXP (note, 0), 0);
796 /* if nested region is not 0, we know for sure it has been
797 processed. If it is zero, we dont know whether its an
798 outer region, or hasn't been seen yet, so defer it */
799 if (nested_eh_region[region] != 0)
800 {
801 /* start with the first region OUTSIDE the one specified
802 in the rethrow parameter. (since a rethrow behaves
803 as if a handler in the region didn't handle the
804 exception, so the handlers for the next outer region
805 are going to get a shot at it.*/
806 for ( region = nested_eh_region[region]; region;
807 region = nested_eh_region[region])
808 {
809 handler_info *ptr = get_first_handler (region);
810 for ( ; ptr ; ptr = ptr->next)
811 add_edge_to_label (i, ptr->handler_label);
812 }
813 }
814 else
815 {
816 /* Push this region onto a list, and after we've done the
817 whole procedure, we'll process everything on the list */
818 pending_eh_region = gen_rtx_EXPR_LIST (VOIDmode, insn,
819 pending_eh_region);
820 }
821 }
822
823 /* If this is a CALL_INSN, then mark it as reaching the active EH
824 handler for this CALL_INSN. If we're handling asynchronous
825 exceptions mark every insn as reaching the active EH handler.
826
827 Also mark the CALL_INSN as reaching any nonlocal goto sites. */
828 else if (asynchronous_exceptions
829 || (GET_CODE (insn) == CALL_INSN
830 && ! find_reg_note (insn, REG_RETVAL, NULL_RTX)))
831 {
832 int region = active_eh_region[INSN_UID (insn)];
833 note = find_reg_note(insn, REG_EH_REGION, NULL_RTX);
834
835 /* Override region if we see a REG_EH_REGION note. */
836 if (note)
837 region = XINT (XEXP (note, 0), 0);
838
839 if (region)
840 {
841 handler_info *ptr;
842 region = active_eh_region[INSN_UID (insn)];
843 for ( ; region; region = nested_eh_region[region])
844 {
845 ptr = get_first_handler (region);
846 for ( ; ptr ; ptr = ptr->next)
847 add_edge_to_label (i, ptr->handler_label);
848 }
849 }
850 if (! asynchronous_exceptions)
851 {
852 for (x = nonlocal_label_list; x; x = XEXP (x, 1))
853 add_edge_to_label (i, XEXP (x, 0));
854 }
855 /* ??? This could be made smarter: in some cases it's possible
856 to tell that certain calls will not do a nonlocal goto.
857
858 For example, if the nested functions that do the nonlocal
859 gotos do not have their addresses taken, then only calls to
860 those functions or to other nested functions that use them
861 could possibly do nonlocal gotos. */
862 }
863 }
864 }
865
866 while (pending_eh_region != NULL_RTX)
867 {
868 rtx insn = XEXP (pending_eh_region, 0);
869 rtx note = find_reg_note (insn, REG_EH_RETHROW, NULL_RTX);
870 int region = XINT (XEXP (note, 0), 0);
871 /* start with the first region OUTSIDE the one specified
872 in the rethrow parameter */
873 for ( region = nested_eh_region[region]; region;
874 region = nested_eh_region[region])
875 {
876 handler_info *ptr = get_first_handler (region);
877 for ( ; ptr ; ptr = ptr->next)
878 add_edge_to_label (BLOCK_NUM (insn), ptr->handler_label);
879 }
880 pending_eh_region = XEXP (pending_eh_region, 1);
881 }
882
883 /* We know something about the structure of the function __throw in
884 libgcc2.c. It is the only function that ever contains eh_stub labels.
885 It modifies its return address so that the last block returns to one of
886 the eh_stub labels within it. So we have to make additional edges in
887 the flow graph. */
888 if (i + 1 == n_basic_blocks && eh_return_stub_label != 0)
889 add_edge_to_label (i, eh_return_stub_label);
890 }
891
892 /* Now delete the code for any basic blocks that can't be reached.
893 They can occur because jump_optimize does not recognize unreachable loops
894 as unreachable. */
895 static void
896 delete_unreachable_blocks ()
897 {
898 int deleted_handler = 0;
899 int deleted = 0;
900 int i, j;
901 rtx insn;
902 int *block_num_map = XNMALLOC (int, n_basic_blocks);
903
904 for (i = n_basic_blocks - 1; i >= 0; i--)
905 if (! block_live_static[i])
906 deleted_handler |= delete_block (i);
907
908 for (i = 0; i < n_basic_blocks; i++)
909 if (block_live_static[i])
910 block_num_map[i] = i - deleted;
911 else
912 {
913 deleted++;
914 block_num_map[i] = -1;
915 }
916
917 /* Eliminate all traces of the deleted blocks by renumbering the remaining
918 ones. */
919 for (i = j = 0; i < n_basic_blocks; i++)
920 {
921 int_list_ptr p;
922
923 if (block_num_map[i] == -1)
924 continue;
925
926 for (p = basic_block_pred[i]; p; p = p->next)
927 INT_LIST_VAL (p) = block_num_map[INT_LIST_VAL (p)];
928 for (p = basic_block_succ[i]; p; p = p->next)
929 INT_LIST_VAL (p) = block_num_map[INT_LIST_VAL (p)];
930
931 if (i != j)
932 {
933 rtx tmp = BLOCK_HEAD (i);
934 for (;;)
935 {
936 BLOCK_NUM (tmp) = j;
937 if (tmp == BLOCK_END (i))
938 break;
939 tmp = NEXT_INSN (tmp);
940 }
941 BLOCK_HEAD (j) = BLOCK_HEAD (i);
942 BLOCK_END (j) = BLOCK_END (i);
943 basic_block_pred[j] = basic_block_pred[i];
944 basic_block_succ[j] = basic_block_succ[i];
945 basic_block_loop_depth[j] = basic_block_loop_depth[i];
946 basic_block_computed_jump_target[j]
947 = basic_block_computed_jump_target[i];
948 }
949 j++;
950 }
951 n_basic_blocks -= deleted;
952 free (block_num_map);
953
954 /* If we deleted an exception handler, we may have EH region
955 begin/end blocks to remove as well. */
956 if (deleted_handler)
957 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
958 if (GET_CODE (insn) == NOTE)
959 {
960 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG ||
961 NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
962 {
963 int num = CODE_LABEL_NUMBER (insn);
964 /* A NULL handler indicates a region is no longer needed,
965 unless its the target of a rethrow. */
966 if (get_first_handler (num) == NULL && !rethrow_used (num))
967 {
968 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
969 NOTE_SOURCE_FILE (insn) = 0;
970 }
971 }
972 }
973 }
974
975 /* Delete the insns in a (non-live) block. We physically delete every
976 non-note insn except the start and end (so BLOCK_HEAD/END needn't
977 be updated), we turn the latter into NOTE_INSN_DELETED notes.
978
979 We use to "delete" the insns by turning them into notes, but we may be
980 deleting lots of insns that subsequent passes would otherwise have to
981 process. Secondly, lots of deleted blocks in a row can really slow down
982 propagate_block since it will otherwise process insn-turned-notes multiple
983 times when it looks for loop begin/end notes.
984
985 Return nonzero if we deleted an exception handler. */
986 static int
987 delete_block (i)
988 int i;
989 {
990 int deleted_handler = 0;
991 rtx insn;
992 rtx kept_head = 0;
993 rtx kept_tail = 0;
994
995 /* If the head of this block is a CODE_LABEL, then it might
996 be the label for an exception handler which can't be
997 reached.
998
999 We need to remove the label from the exception_handler_label
1000 list and remove the associated NOTE_EH_REGION_BEG and
1001 NOTE_EH_REGION_END notes. */
1002 insn = BLOCK_HEAD (i);
1003 if (GET_CODE (insn) == CODE_LABEL)
1004 {
1005 rtx x, *prev = &exception_handler_labels;
1006
1007 for (x = exception_handler_labels; x; x = XEXP (x, 1))
1008 {
1009 if (XEXP (x, 0) == insn)
1010 {
1011 /* Found a match, splice this label out of the
1012 EH label list. */
1013 *prev = XEXP (x, 1);
1014 XEXP (x, 1) = NULL_RTX;
1015 XEXP (x, 0) = NULL_RTX;
1016
1017 /* Remove the handler from all regions */
1018 remove_handler (insn);
1019 deleted_handler = 1;
1020 break;
1021 }
1022 prev = &XEXP (x, 1);
1023 }
1024 }
1025
1026 /* Walk the insns of the block, building a chain of NOTEs that need to be
1027 kept. */
1028 insn = BLOCK_HEAD (i);
1029 for (;;)
1030 {
1031 if (GET_CODE (insn) == BARRIER)
1032 abort ();
1033 else if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
1034 {
1035 if (kept_head == 0)
1036 kept_head = kept_tail = insn;
1037 else
1038 {
1039 NEXT_INSN (kept_tail) = insn;
1040 PREV_INSN (insn) = kept_tail;
1041 kept_tail = insn;
1042 }
1043 }
1044 if (insn == BLOCK_END (i))
1045 break;
1046 insn = NEXT_INSN (insn);
1047 }
1048 insn = NEXT_INSN (insn);
1049
1050 /* BARRIERs are between basic blocks, not part of one.
1051 Delete a BARRIER if the preceding jump is deleted.
1052 We cannot alter a BARRIER into a NOTE
1053 because it is too short; but we can really delete
1054 it because it is not part of a basic block. */
1055 if (insn != 0 && GET_CODE (insn) == BARRIER)
1056 insn = NEXT_INSN (insn);
1057
1058 /* Now unchain all of the block, and put the chain of kept notes in its
1059 place. */
1060 if (kept_head == 0)
1061 {
1062 NEXT_INSN (PREV_INSN (BLOCK_HEAD (i))) = insn;
1063 if (insn != 0)
1064 PREV_INSN (insn) = PREV_INSN (BLOCK_HEAD (i));
1065 else
1066 set_last_insn (PREV_INSN (BLOCK_HEAD(i)));
1067 }
1068 else
1069 {
1070 NEXT_INSN (PREV_INSN (BLOCK_HEAD (i))) = kept_head;
1071 if (insn != 0)
1072 PREV_INSN (insn) = kept_tail;
1073
1074 PREV_INSN (kept_head) = PREV_INSN (BLOCK_HEAD (i));
1075 NEXT_INSN (kept_tail) = insn;
1076
1077 /* This must happen after NEXT_INSN (kept_tail) has been reinitialized
1078 since set_last_insn will abort if it detects a non-NULL NEXT_INSN
1079 field in its argument. */
1080 if (insn == NULL_RTX)
1081 set_last_insn (kept_tail);
1082 }
1083
1084 /* Each time we delete some basic blocks,
1085 see if there is a jump around them that is
1086 being turned into a no-op. If so, delete it. */
1087
1088 if (block_live_static[i - 1])
1089 {
1090 register int j;
1091 for (j = i + 1; j < n_basic_blocks; j++)
1092 if (block_live_static[j])
1093 {
1094 rtx label;
1095 insn = BLOCK_END (i - 1);
1096 if (GET_CODE (insn) == JUMP_INSN
1097 /* An unconditional jump is the only possibility
1098 we must check for, since a conditional one
1099 would make these blocks live. */
1100 && simplejump_p (insn)
1101 && (label = XEXP (SET_SRC (PATTERN (insn)), 0), 1)
1102 && INSN_UID (label) != 0
1103 && BLOCK_NUM (label) == j)
1104 {
1105 PUT_CODE (insn, NOTE);
1106 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1107 NOTE_SOURCE_FILE (insn) = 0;
1108 if (GET_CODE (NEXT_INSN (insn)) != BARRIER)
1109 abort ();
1110 delete_insn (NEXT_INSN (insn));
1111 }
1112 break;
1113 }
1114 }
1115
1116 return deleted_handler;
1117 }
1118 \f
1119 /* Perform data flow analysis.
1120 F is the first insn of the function and NREGS the number of register numbers
1121 in use. */
1122
1123 void
1124 life_analysis (f, nregs, file)
1125 rtx f;
1126 int nregs;
1127 FILE *file;
1128 {
1129 #ifdef ELIMINABLE_REGS
1130 register size_t i;
1131 static struct {int from, to; } eliminables[] = ELIMINABLE_REGS;
1132 #endif
1133
1134 /* Record which registers will be eliminated. We use this in
1135 mark_used_regs. */
1136
1137 CLEAR_HARD_REG_SET (elim_reg_set);
1138
1139 #ifdef ELIMINABLE_REGS
1140 for (i = 0; i < sizeof eliminables / sizeof eliminables[0]; i++)
1141 SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
1142 #else
1143 SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
1144 #endif
1145
1146 /* We want alias analysis information for local dead store elimination. */
1147 init_alias_analysis ();
1148 life_analysis_1 (f, nregs);
1149 end_alias_analysis ();
1150
1151 if (file)
1152 dump_flow_info (file);
1153
1154 free_basic_block_vars (1);
1155 }
1156
1157 /* Free the variables allocated by find_basic_blocks.
1158
1159 KEEP_HEAD_END_P is non-zero if BLOCK_HEAD and BLOCK_END
1160 are not to be freed. */
1161
1162 void
1163 free_basic_block_vars (keep_head_end_p)
1164 int keep_head_end_p;
1165 {
1166 if (basic_block_loop_depth)
1167 {
1168 free (basic_block_loop_depth);
1169 basic_block_loop_depth = 0;
1170 }
1171 if (uid_block_number)
1172 {
1173 free (uid_block_number);
1174 uid_block_number = 0;
1175 }
1176 if (uid_volatile)
1177 {
1178 free (uid_volatile);
1179 uid_volatile = 0;
1180 }
1181
1182 if (! keep_head_end_p && x_basic_block_head)
1183 {
1184 free (x_basic_block_head);
1185 x_basic_block_head = 0;
1186 free (x_basic_block_end);
1187 x_basic_block_end = 0;
1188 }
1189 }
1190
1191 /* Return nonzero if the destination of SET equals the source. */
1192 static int
1193 set_noop_p (set)
1194 rtx set;
1195 {
1196 rtx src = SET_SRC (set);
1197 rtx dst = SET_DEST (set);
1198 if (GET_CODE (src) == REG && GET_CODE (dst) == REG
1199 && REGNO (src) == REGNO (dst))
1200 return 1;
1201 if (GET_CODE (src) != SUBREG || GET_CODE (dst) != SUBREG
1202 || SUBREG_WORD (src) != SUBREG_WORD (dst))
1203 return 0;
1204 src = SUBREG_REG (src);
1205 dst = SUBREG_REG (dst);
1206 if (GET_CODE (src) == REG && GET_CODE (dst) == REG
1207 && REGNO (src) == REGNO (dst))
1208 return 1;
1209 return 0;
1210 }
1211
1212 /* Return nonzero if an insn consists only of SETs, each of which only sets a
1213 value to itself. */
1214 static int
1215 noop_move_p (insn)
1216 rtx insn;
1217 {
1218 rtx pat = PATTERN (insn);
1219
1220 /* Insns carrying these notes are useful later on. */
1221 if (find_reg_note (insn, REG_EQUAL, NULL_RTX))
1222 return 0;
1223
1224 if (GET_CODE (pat) == SET && set_noop_p (pat))
1225 return 1;
1226
1227 if (GET_CODE (pat) == PARALLEL)
1228 {
1229 int i;
1230 /* If nothing but SETs of registers to themselves,
1231 this insn can also be deleted. */
1232 for (i = 0; i < XVECLEN (pat, 0); i++)
1233 {
1234 rtx tem = XVECEXP (pat, 0, i);
1235
1236 if (GET_CODE (tem) == USE
1237 || GET_CODE (tem) == CLOBBER)
1238 continue;
1239
1240 if (GET_CODE (tem) != SET || ! set_noop_p (tem))
1241 return 0;
1242 }
1243
1244 return 1;
1245 }
1246 return 0;
1247 }
1248
1249 static void
1250 notice_stack_pointer_modification (x, pat)
1251 rtx x;
1252 rtx pat ATTRIBUTE_UNUSED;
1253 {
1254 if (x == stack_pointer_rtx
1255 /* The stack pointer is only modified indirectly as the result
1256 of a push until later in flow. See the comments in rtl.texi
1257 regarding Embedded Side-Effects on Addresses. */
1258 || (GET_CODE (x) == MEM
1259 && (GET_CODE (XEXP (x, 0)) == PRE_DEC
1260 || GET_CODE (XEXP (x, 0)) == PRE_INC
1261 || GET_CODE (XEXP (x, 0)) == POST_DEC
1262 || GET_CODE (XEXP (x, 0)) == POST_INC)
1263 && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
1264 current_function_sp_is_unchanging = 0;
1265 }
1266
1267 /* Record which insns refer to any volatile memory
1268 or for any reason can't be deleted just because they are dead stores.
1269 Also, delete any insns that copy a register to itself.
1270 And see if the stack pointer is modified. */
1271 static void
1272 record_volatile_insns (f)
1273 rtx f;
1274 {
1275 rtx insn;
1276 for (insn = f; insn; insn = NEXT_INSN (insn))
1277 {
1278 enum rtx_code code1 = GET_CODE (insn);
1279 if (code1 == CALL_INSN)
1280 INSN_VOLATILE (insn) = 1;
1281 else if (code1 == INSN || code1 == JUMP_INSN)
1282 {
1283 if (GET_CODE (PATTERN (insn)) != USE
1284 && volatile_refs_p (PATTERN (insn)))
1285 INSN_VOLATILE (insn) = 1;
1286
1287 /* A SET that makes space on the stack cannot be dead.
1288 (Such SETs occur only for allocating variable-size data,
1289 so they will always have a PLUS or MINUS according to the
1290 direction of stack growth.)
1291 Even if this function never uses this stack pointer value,
1292 signal handlers do! */
1293 else if (code1 == INSN && GET_CODE (PATTERN (insn)) == SET
1294 && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
1295 #ifdef STACK_GROWS_DOWNWARD
1296 && GET_CODE (SET_SRC (PATTERN (insn))) == MINUS
1297 #else
1298 && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
1299 #endif
1300 && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx)
1301 INSN_VOLATILE (insn) = 1;
1302
1303 /* Delete (in effect) any obvious no-op moves. */
1304 else if (noop_move_p (insn))
1305 {
1306 PUT_CODE (insn, NOTE);
1307 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1308 NOTE_SOURCE_FILE (insn) = 0;
1309 }
1310 }
1311
1312 /* Check if insn modifies the stack pointer. */
1313 if ( current_function_sp_is_unchanging
1314 && GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1315 note_stores (PATTERN (insn), notice_stack_pointer_modification);
1316 }
1317 }
1318
1319 /* Mark those regs which are needed at the end of the function as live
1320 at the end of the last basic block. */
1321 static void
1322 mark_regs_live_at_end (set)
1323 regset set;
1324 {
1325 int i;
1326
1327 #ifdef EXIT_IGNORE_STACK
1328 if (! EXIT_IGNORE_STACK
1329 || (! FRAME_POINTER_REQUIRED
1330 && ! current_function_calls_alloca
1331 && flag_omit_frame_pointer)
1332 || current_function_sp_is_unchanging)
1333 #endif
1334 /* If exiting needs the right stack value,
1335 consider the stack pointer live at the end of the function. */
1336 SET_REGNO_REG_SET (set, STACK_POINTER_REGNUM);
1337
1338 /* Mark the frame pointer is needed at the end of the function. If
1339 we end up eliminating it, it will be removed from the live list
1340 of each basic block by reload. */
1341
1342 SET_REGNO_REG_SET (set, FRAME_POINTER_REGNUM);
1343 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
1344 /* If they are different, also mark the hard frame pointer as live */
1345 SET_REGNO_REG_SET (set, HARD_FRAME_POINTER_REGNUM);
1346 #endif
1347
1348
1349 /* Mark all global registers and all registers used by the epilogue
1350 as being live at the end of the function since they may be
1351 referenced by our caller. */
1352 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1353 if (global_regs[i]
1354 #ifdef EPILOGUE_USES
1355 || EPILOGUE_USES (i)
1356 #endif
1357 )
1358 SET_REGNO_REG_SET (set, i);
1359 }
1360
1361 /* Determine which registers are live at the start of each
1362 basic block of the function whose first insn is F.
1363 NREGS is the number of registers used in F.
1364 We allocate the vector basic_block_live_at_start
1365 and the regsets that it points to, and fill them with the data.
1366 regset_size and regset_bytes are also set here. */
1367
1368 static void
1369 life_analysis_1 (f, nregs)
1370 rtx f;
1371 int nregs;
1372 {
1373 int first_pass;
1374 int changed;
1375 /* For each basic block, a bitmask of regs
1376 live on exit from the block. */
1377 regset *basic_block_live_at_end;
1378 /* For each basic block, a bitmask of regs
1379 live on entry to a successor-block of this block.
1380 If this does not match basic_block_live_at_end,
1381 that must be updated, and the block must be rescanned. */
1382 regset *basic_block_new_live_at_end;
1383 /* For each basic block, a bitmask of regs
1384 whose liveness at the end of the basic block
1385 can make a difference in which regs are live on entry to the block.
1386 These are the regs that are set within the basic block,
1387 possibly excluding those that are used after they are set. */
1388 regset *basic_block_significant;
1389 register int i;
1390 char save_regs_ever_live[FIRST_PSEUDO_REGISTER];
1391
1392 struct obstack flow_obstack;
1393
1394 gcc_obstack_init (&flow_obstack);
1395
1396 max_regno = nregs;
1397
1398 /* The post-reload life analysis have (on a global basis) the same registers
1399 live as was computed by reload itself.
1400
1401 Otherwise elimination offsets and such may be incorrect.
1402
1403 Reload will make some registers as live even though they do not appear
1404 in the rtl. */
1405 if (reload_completed)
1406 bcopy (regs_ever_live, save_regs_ever_live, (sizeof (regs_ever_live)));
1407
1408 bzero (regs_ever_live, sizeof regs_ever_live);
1409
1410 /* Allocate and zero out many data structures
1411 that will record the data from lifetime analysis. */
1412
1413 allocate_for_life_analysis ();
1414
1415 reg_next_use = (rtx *) alloca (nregs * sizeof (rtx));
1416 bzero ((char *) reg_next_use, nregs * sizeof (rtx));
1417
1418 /* Set up several regset-vectors used internally within this function.
1419 Their meanings are documented above, with their declarations. */
1420
1421 basic_block_live_at_end
1422 = (regset *) alloca (n_basic_blocks * sizeof (regset));
1423
1424 /* Don't use alloca since that leads to a crash rather than an error message
1425 if there isn't enough space.
1426 Don't use oballoc since we may need to allocate other things during
1427 this function on the temporary obstack. */
1428 init_regset_vector (basic_block_live_at_end, n_basic_blocks, &flow_obstack);
1429
1430 basic_block_new_live_at_end
1431 = (regset *) alloca (n_basic_blocks * sizeof (regset));
1432 init_regset_vector (basic_block_new_live_at_end, n_basic_blocks,
1433 &flow_obstack);
1434
1435 basic_block_significant
1436 = (regset *) alloca (n_basic_blocks * sizeof (regset));
1437 init_regset_vector (basic_block_significant, n_basic_blocks, &flow_obstack);
1438
1439 /* Assume that the stack pointer is unchanging if alloca hasn't been used.
1440 This will be cleared by record_volatile_insns if it encounters an insn
1441 which modifies the stack pointer. */
1442 current_function_sp_is_unchanging = !current_function_calls_alloca;
1443
1444 record_volatile_insns (f);
1445
1446 if (n_basic_blocks > 0)
1447 {
1448 mark_regs_live_at_end (basic_block_live_at_end[n_basic_blocks - 1]);
1449 COPY_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1],
1450 basic_block_live_at_end[n_basic_blocks - 1]);
1451 }
1452
1453 /* Propagate life info through the basic blocks
1454 around the graph of basic blocks.
1455
1456 This is a relaxation process: each time a new register
1457 is live at the end of the basic block, we must scan the block
1458 to determine which registers are, as a consequence, live at the beginning
1459 of that block. These registers must then be marked live at the ends
1460 of all the blocks that can transfer control to that block.
1461 The process continues until it reaches a fixed point. */
1462
1463 first_pass = 1;
1464 changed = 1;
1465 while (changed)
1466 {
1467 changed = 0;
1468 for (i = n_basic_blocks - 1; i >= 0; i--)
1469 {
1470 int consider = first_pass;
1471 int must_rescan = first_pass;
1472 register int j;
1473
1474 if (!first_pass)
1475 {
1476 /* Set CONSIDER if this block needs thinking about at all
1477 (that is, if the regs live now at the end of it
1478 are not the same as were live at the end of it when
1479 we last thought about it).
1480 Set must_rescan if it needs to be thought about
1481 instruction by instruction (that is, if any additional
1482 reg that is live at the end now but was not live there before
1483 is one of the significant regs of this basic block). */
1484
1485 EXECUTE_IF_AND_COMPL_IN_REG_SET
1486 (basic_block_new_live_at_end[i],
1487 basic_block_live_at_end[i], 0, j,
1488 {
1489 consider = 1;
1490 if (REGNO_REG_SET_P (basic_block_significant[i], j))
1491 {
1492 must_rescan = 1;
1493 goto done;
1494 }
1495 });
1496 done:
1497 if (! consider)
1498 continue;
1499 }
1500
1501 /* The live_at_start of this block may be changing,
1502 so another pass will be required after this one. */
1503 changed = 1;
1504
1505 if (! must_rescan)
1506 {
1507 /* No complete rescan needed;
1508 just record those variables newly known live at end
1509 as live at start as well. */
1510 IOR_AND_COMPL_REG_SET (basic_block_live_at_start[i],
1511 basic_block_new_live_at_end[i],
1512 basic_block_live_at_end[i]);
1513
1514 IOR_AND_COMPL_REG_SET (basic_block_live_at_end[i],
1515 basic_block_new_live_at_end[i],
1516 basic_block_live_at_end[i]);
1517 }
1518 else
1519 {
1520 /* Update the basic_block_live_at_start
1521 by propagation backwards through the block. */
1522 COPY_REG_SET (basic_block_live_at_end[i],
1523 basic_block_new_live_at_end[i]);
1524 COPY_REG_SET (basic_block_live_at_start[i],
1525 basic_block_live_at_end[i]);
1526 propagate_block (basic_block_live_at_start[i],
1527 BLOCK_HEAD (i), BLOCK_END (i), 0,
1528 first_pass ? basic_block_significant[i]
1529 : (regset) 0,
1530 i);
1531 }
1532
1533 {
1534 int_list_ptr p;
1535
1536 /* Update the basic_block_new_live_at_end's of
1537 all the blocks that reach this one. */
1538 for (p = basic_block_pred[i]; p; p = p->next)
1539 {
1540 register int from_block = INT_LIST_VAL (p);
1541 IOR_REG_SET (basic_block_new_live_at_end[from_block],
1542 basic_block_live_at_start[i]);
1543 }
1544 }
1545 #ifdef USE_C_ALLOCA
1546 alloca (0);
1547 #endif
1548 }
1549 first_pass = 0;
1550 }
1551
1552 /* The only pseudos that are live at the beginning of the function are
1553 those that were not set anywhere in the function. local-alloc doesn't
1554 know how to handle these correctly, so mark them as not local to any
1555 one basic block. */
1556
1557 if (n_basic_blocks > 0)
1558 EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[0],
1559 FIRST_PSEUDO_REGISTER, i,
1560 {
1561 REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL;
1562 });
1563
1564 /* Now the life information is accurate.
1565 Make one more pass over each basic block
1566 to delete dead stores, create autoincrement addressing
1567 and record how many times each register is used, is set, or dies.
1568
1569 To save time, we operate directly in basic_block_live_at_end[i],
1570 thus destroying it (in fact, converting it into a copy of
1571 basic_block_live_at_start[i]). This is ok now because
1572 basic_block_live_at_end[i] is no longer used past this point. */
1573
1574 for (i = 0; i < n_basic_blocks; i++)
1575 {
1576 propagate_block (basic_block_live_at_end[i],
1577 BLOCK_HEAD (i), BLOCK_END (i), 1,
1578 (regset) 0, i);
1579 #ifdef USE_C_ALLOCA
1580 alloca (0);
1581 #endif
1582 }
1583
1584 #if 0
1585 /* Something live during a setjmp should not be put in a register
1586 on certain machines which restore regs from stack frames
1587 rather than from the jmpbuf.
1588 But we don't need to do this for the user's variables, since
1589 ANSI says only volatile variables need this. */
1590 #ifdef LONGJMP_RESTORE_FROM_STACK
1591 EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp,
1592 FIRST_PSEUDO_REGISTER, i,
1593 {
1594 if (regno_reg_rtx[i] != 0
1595 && ! REG_USERVAR_P (regno_reg_rtx[i]))
1596 {
1597 REG_LIVE_LENGTH (i) = -1;
1598 REG_BASIC_BLOCK (i) = -1;
1599 }
1600 });
1601 #endif
1602 #endif
1603
1604 /* We have a problem with any pseudoreg that
1605 lives across the setjmp. ANSI says that if a
1606 user variable does not change in value
1607 between the setjmp and the longjmp, then the longjmp preserves it.
1608 This includes longjmp from a place where the pseudo appears dead.
1609 (In principle, the value still exists if it is in scope.)
1610 If the pseudo goes in a hard reg, some other value may occupy
1611 that hard reg where this pseudo is dead, thus clobbering the pseudo.
1612 Conclusion: such a pseudo must not go in a hard reg. */
1613 EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp,
1614 FIRST_PSEUDO_REGISTER, i,
1615 {
1616 if (regno_reg_rtx[i] != 0)
1617 {
1618 REG_LIVE_LENGTH (i) = -1;
1619 REG_BASIC_BLOCK (i) = -1;
1620 }
1621 });
1622
1623 /* Restore regs_ever_live that was provided by reload. */
1624 if (reload_completed)
1625 bcopy (save_regs_ever_live, regs_ever_live, (sizeof (regs_ever_live)));
1626
1627 free_regset_vector (basic_block_live_at_end, n_basic_blocks);
1628 free_regset_vector (basic_block_new_live_at_end, n_basic_blocks);
1629 free_regset_vector (basic_block_significant, n_basic_blocks);
1630 basic_block_live_at_end = (regset *)0;
1631 basic_block_new_live_at_end = (regset *)0;
1632 basic_block_significant = (regset *)0;
1633
1634 obstack_free (&flow_obstack, NULL_PTR);
1635 }
1636 \f
1637 /* Subroutines of life analysis. */
1638
1639 /* Allocate the permanent data structures that represent the results
1640 of life analysis. Not static since used also for stupid life analysis. */
1641
1642 void
1643 allocate_for_life_analysis ()
1644 {
1645 register int i;
1646
1647 /* Recalculate the register space, in case it has grown. Old style
1648 vector oriented regsets would set regset_{size,bytes} here also. */
1649 allocate_reg_info (max_regno, FALSE, FALSE);
1650
1651 /* Because both reg_scan and flow_analysis want to set up the REG_N_SETS
1652 information, explicitly reset it here. The allocation should have
1653 already happened on the previous reg_scan pass. Make sure in case
1654 some more registers were allocated. */
1655 for (i = 0; i < max_regno; i++)
1656 REG_N_SETS (i) = 0;
1657
1658 basic_block_live_at_start
1659 = (regset *) oballoc (n_basic_blocks * sizeof (regset));
1660 init_regset_vector (basic_block_live_at_start, n_basic_blocks,
1661 function_obstack);
1662
1663 regs_live_at_setjmp = OBSTACK_ALLOC_REG_SET (function_obstack);
1664 CLEAR_REG_SET (regs_live_at_setjmp);
1665 }
1666
1667 /* Make each element of VECTOR point at a regset. The vector has
1668 NELTS elements, and space is allocated from the ALLOC_OBSTACK
1669 obstack. */
1670
1671 static void
1672 init_regset_vector (vector, nelts, alloc_obstack)
1673 regset *vector;
1674 int nelts;
1675 struct obstack *alloc_obstack;
1676 {
1677 register int i;
1678
1679 for (i = 0; i < nelts; i++)
1680 {
1681 vector[i] = OBSTACK_ALLOC_REG_SET (alloc_obstack);
1682 CLEAR_REG_SET (vector[i]);
1683 }
1684 }
1685
1686 /* Release any additional space allocated for each element of VECTOR point
1687 other than the regset header itself. The vector has NELTS elements. */
1688
1689 void
1690 free_regset_vector (vector, nelts)
1691 regset *vector;
1692 int nelts;
1693 {
1694 register int i;
1695
1696 for (i = 0; i < nelts; i++)
1697 FREE_REG_SET (vector[i]);
1698 }
1699
1700 /* Compute the registers live at the beginning of a basic block
1701 from those live at the end.
1702
1703 When called, OLD contains those live at the end.
1704 On return, it contains those live at the beginning.
1705 FIRST and LAST are the first and last insns of the basic block.
1706
1707 FINAL is nonzero if we are doing the final pass which is not
1708 for computing the life info (since that has already been done)
1709 but for acting on it. On this pass, we delete dead stores,
1710 set up the logical links and dead-variables lists of instructions,
1711 and merge instructions for autoincrement and autodecrement addresses.
1712
1713 SIGNIFICANT is nonzero only the first time for each basic block.
1714 If it is nonzero, it points to a regset in which we store
1715 a 1 for each register that is set within the block.
1716
1717 BNUM is the number of the basic block. */
1718
1719 static void
1720 propagate_block (old, first, last, final, significant, bnum)
1721 register regset old;
1722 rtx first;
1723 rtx last;
1724 int final;
1725 regset significant;
1726 int bnum;
1727 {
1728 register rtx insn;
1729 rtx prev;
1730 regset live;
1731 regset dead;
1732
1733 /* The loop depth may change in the middle of a basic block. Since we
1734 scan from end to beginning, we start with the depth at the end of the
1735 current basic block, and adjust as we pass ends and starts of loops. */
1736 loop_depth = basic_block_loop_depth[bnum];
1737
1738 dead = ALLOCA_REG_SET ();
1739 live = ALLOCA_REG_SET ();
1740
1741 cc0_live = 0;
1742 mem_set_list = NULL_RTX;
1743
1744 /* Include any notes at the end of the block in the scan.
1745 This is in case the block ends with a call to setjmp. */
1746
1747 while (NEXT_INSN (last) != 0 && GET_CODE (NEXT_INSN (last)) == NOTE)
1748 {
1749 /* Look for loop boundaries, we are going forward here. */
1750 last = NEXT_INSN (last);
1751 if (NOTE_LINE_NUMBER (last) == NOTE_INSN_LOOP_BEG)
1752 loop_depth++;
1753 else if (NOTE_LINE_NUMBER (last) == NOTE_INSN_LOOP_END)
1754 loop_depth--;
1755 }
1756
1757 if (final)
1758 {
1759 register int i;
1760
1761 /* Process the regs live at the end of the block.
1762 Mark them as not local to any one basic block. */
1763 EXECUTE_IF_SET_IN_REG_SET (old, 0, i,
1764 {
1765 REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL;
1766 });
1767 }
1768
1769 /* Scan the block an insn at a time from end to beginning. */
1770
1771 for (insn = last; ; insn = prev)
1772 {
1773 prev = PREV_INSN (insn);
1774
1775 if (GET_CODE (insn) == NOTE)
1776 {
1777 /* Look for loop boundaries, remembering that we are going
1778 backwards. */
1779 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1780 loop_depth++;
1781 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
1782 loop_depth--;
1783
1784 /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error.
1785 Abort now rather than setting register status incorrectly. */
1786 if (loop_depth == 0)
1787 abort ();
1788
1789 /* If this is a call to `setjmp' et al,
1790 warn if any non-volatile datum is live. */
1791
1792 if (final && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)
1793 IOR_REG_SET (regs_live_at_setjmp, old);
1794 }
1795
1796 /* Update the life-status of regs for this insn.
1797 First DEAD gets which regs are set in this insn
1798 then LIVE gets which regs are used in this insn.
1799 Then the regs live before the insn
1800 are those live after, with DEAD regs turned off,
1801 and then LIVE regs turned on. */
1802
1803 else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1804 {
1805 register int i;
1806 rtx note = find_reg_note (insn, REG_RETVAL, NULL_RTX);
1807 int insn_is_dead
1808 = (insn_dead_p (PATTERN (insn), old, 0, REG_NOTES (insn))
1809 /* Don't delete something that refers to volatile storage! */
1810 && ! INSN_VOLATILE (insn));
1811 int libcall_is_dead
1812 = (insn_is_dead && note != 0
1813 && libcall_dead_p (PATTERN (insn), old, note, insn));
1814
1815 /* If an instruction consists of just dead store(s) on final pass,
1816 "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
1817 We could really delete it with delete_insn, but that
1818 can cause trouble for first or last insn in a basic block. */
1819 if (final && insn_is_dead)
1820 {
1821 PUT_CODE (insn, NOTE);
1822 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1823 NOTE_SOURCE_FILE (insn) = 0;
1824
1825 /* CC0 is now known to be dead. Either this insn used it,
1826 in which case it doesn't anymore, or clobbered it,
1827 so the next insn can't use it. */
1828 cc0_live = 0;
1829
1830 /* If this insn is copying the return value from a library call,
1831 delete the entire library call. */
1832 if (libcall_is_dead)
1833 {
1834 rtx first = XEXP (note, 0);
1835 rtx p = insn;
1836 while (INSN_DELETED_P (first))
1837 first = NEXT_INSN (first);
1838 while (p != first)
1839 {
1840 p = PREV_INSN (p);
1841 PUT_CODE (p, NOTE);
1842 NOTE_LINE_NUMBER (p) = NOTE_INSN_DELETED;
1843 NOTE_SOURCE_FILE (p) = 0;
1844 }
1845 }
1846 goto flushed;
1847 }
1848
1849 CLEAR_REG_SET (dead);
1850 CLEAR_REG_SET (live);
1851
1852 /* See if this is an increment or decrement that can be
1853 merged into a following memory address. */
1854 #ifdef AUTO_INC_DEC
1855 {
1856 register rtx x = single_set (insn);
1857
1858 /* Does this instruction increment or decrement a register? */
1859 if (!reload_completed
1860 && final && x != 0
1861 && GET_CODE (SET_DEST (x)) == REG
1862 && (GET_CODE (SET_SRC (x)) == PLUS
1863 || GET_CODE (SET_SRC (x)) == MINUS)
1864 && XEXP (SET_SRC (x), 0) == SET_DEST (x)
1865 && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
1866 /* Ok, look for a following memory ref we can combine with.
1867 If one is found, change the memory ref to a PRE_INC
1868 or PRE_DEC, cancel this insn, and return 1.
1869 Return 0 if nothing has been done. */
1870 && try_pre_increment_1 (insn))
1871 goto flushed;
1872 }
1873 #endif /* AUTO_INC_DEC */
1874
1875 /* If this is not the final pass, and this insn is copying the
1876 value of a library call and it's dead, don't scan the
1877 insns that perform the library call, so that the call's
1878 arguments are not marked live. */
1879 if (libcall_is_dead)
1880 {
1881 /* Mark the dest reg as `significant'. */
1882 mark_set_regs (old, dead, PATTERN (insn), NULL_RTX, significant);
1883
1884 insn = XEXP (note, 0);
1885 prev = PREV_INSN (insn);
1886 }
1887 else if (GET_CODE (PATTERN (insn)) == SET
1888 && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
1889 && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
1890 && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
1891 && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
1892 /* We have an insn to pop a constant amount off the stack.
1893 (Such insns use PLUS regardless of the direction of the stack,
1894 and any insn to adjust the stack by a constant is always a pop.)
1895 These insns, if not dead stores, have no effect on life. */
1896 ;
1897 else
1898 {
1899 /* Any regs live at the time of a call instruction
1900 must not go in a register clobbered by calls.
1901 Find all regs now live and record this for them. */
1902
1903 if (GET_CODE (insn) == CALL_INSN && final)
1904 EXECUTE_IF_SET_IN_REG_SET (old, 0, i,
1905 {
1906 REG_N_CALLS_CROSSED (i)++;
1907 });
1908
1909 /* LIVE gets the regs used in INSN;
1910 DEAD gets those set by it. Dead insns don't make anything
1911 live. */
1912
1913 mark_set_regs (old, dead, PATTERN (insn),
1914 final ? insn : NULL_RTX, significant);
1915
1916 /* If an insn doesn't use CC0, it becomes dead since we
1917 assume that every insn clobbers it. So show it dead here;
1918 mark_used_regs will set it live if it is referenced. */
1919 cc0_live = 0;
1920
1921 if (! insn_is_dead)
1922 mark_used_regs (old, live, PATTERN (insn), final, insn);
1923
1924 /* Sometimes we may have inserted something before INSN (such as
1925 a move) when we make an auto-inc. So ensure we will scan
1926 those insns. */
1927 #ifdef AUTO_INC_DEC
1928 prev = PREV_INSN (insn);
1929 #endif
1930
1931 if (! insn_is_dead && GET_CODE (insn) == CALL_INSN)
1932 {
1933 register int i;
1934
1935 rtx note;
1936
1937 for (note = CALL_INSN_FUNCTION_USAGE (insn);
1938 note;
1939 note = XEXP (note, 1))
1940 if (GET_CODE (XEXP (note, 0)) == USE)
1941 mark_used_regs (old, live, SET_DEST (XEXP (note, 0)),
1942 final, insn);
1943
1944 /* Each call clobbers all call-clobbered regs that are not
1945 global or fixed. Note that the function-value reg is a
1946 call-clobbered reg, and mark_set_regs has already had
1947 a chance to handle it. */
1948
1949 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1950 if (call_used_regs[i] && ! global_regs[i]
1951 && ! fixed_regs[i])
1952 SET_REGNO_REG_SET (dead, i);
1953
1954 /* The stack ptr is used (honorarily) by a CALL insn. */
1955 SET_REGNO_REG_SET (live, STACK_POINTER_REGNUM);
1956
1957 /* Calls may also reference any of the global registers,
1958 so they are made live. */
1959 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1960 if (global_regs[i])
1961 mark_used_regs (old, live,
1962 gen_rtx_REG (reg_raw_mode[i], i),
1963 final, insn);
1964
1965 /* Calls also clobber memory. */
1966 mem_set_list = NULL_RTX;
1967 }
1968
1969 /* Update OLD for the registers used or set. */
1970 AND_COMPL_REG_SET (old, dead);
1971 IOR_REG_SET (old, live);
1972
1973 }
1974
1975 /* On final pass, update counts of how many insns each reg is live
1976 at. */
1977 if (final)
1978 EXECUTE_IF_SET_IN_REG_SET (old, 0, i,
1979 { REG_LIVE_LENGTH (i)++; });
1980 }
1981 flushed: ;
1982 if (insn == first)
1983 break;
1984 }
1985
1986 FREE_REG_SET (dead);
1987 FREE_REG_SET (live);
1988 }
1989 \f
1990 /* Return 1 if X (the body of an insn, or part of it) is just dead stores
1991 (SET expressions whose destinations are registers dead after the insn).
1992 NEEDED is the regset that says which regs are alive after the insn.
1993
1994 Unless CALL_OK is non-zero, an insn is needed if it contains a CALL.
1995
1996 If X is the entire body of an insn, NOTES contains the reg notes
1997 pertaining to the insn. */
1998
1999 static int
2000 insn_dead_p (x, needed, call_ok, notes)
2001 rtx x;
2002 regset needed;
2003 int call_ok;
2004 rtx notes ATTRIBUTE_UNUSED;
2005 {
2006 enum rtx_code code = GET_CODE (x);
2007
2008 #ifdef AUTO_INC_DEC
2009 /* If flow is invoked after reload, we must take existing AUTO_INC
2010 expresions into account. */
2011 if (reload_completed)
2012 {
2013 for ( ; notes; notes = XEXP (notes, 1))
2014 {
2015 if (REG_NOTE_KIND (notes) == REG_INC)
2016 {
2017 int regno = REGNO (XEXP (notes, 0));
2018
2019 /* Don't delete insns to set global regs. */
2020 if ((regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
2021 || REGNO_REG_SET_P (needed, regno))
2022 return 0;
2023 }
2024 }
2025 }
2026 #endif
2027
2028 /* If setting something that's a reg or part of one,
2029 see if that register's altered value will be live. */
2030
2031 if (code == SET)
2032 {
2033 rtx r = SET_DEST (x);
2034
2035 /* A SET that is a subroutine call cannot be dead. */
2036 if (! call_ok && GET_CODE (SET_SRC (x)) == CALL)
2037 return 0;
2038
2039 #ifdef HAVE_cc0
2040 if (GET_CODE (r) == CC0)
2041 return ! cc0_live;
2042 #endif
2043
2044 if (GET_CODE (r) == MEM && ! MEM_VOLATILE_P (r))
2045 {
2046 rtx temp;
2047 /* Walk the set of memory locations we are currently tracking
2048 and see if one is an identical match to this memory location.
2049 If so, this memory write is dead (remember, we're walking
2050 backwards from the end of the block to the start. */
2051 temp = mem_set_list;
2052 while (temp)
2053 {
2054 if (rtx_equal_p (XEXP (temp, 0), r))
2055 return 1;
2056 temp = XEXP (temp, 1);
2057 }
2058 }
2059
2060 while (GET_CODE (r) == SUBREG || GET_CODE (r) == STRICT_LOW_PART
2061 || GET_CODE (r) == ZERO_EXTRACT)
2062 r = SUBREG_REG (r);
2063
2064 if (GET_CODE (r) == REG)
2065 {
2066 int regno = REGNO (r);
2067
2068 /* Don't delete insns to set global regs. */
2069 if ((regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
2070 /* Make sure insns to set frame pointer aren't deleted. */
2071 || regno == FRAME_POINTER_REGNUM
2072 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2073 || regno == HARD_FRAME_POINTER_REGNUM
2074 #endif
2075 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2076 /* Make sure insns to set arg pointer are never deleted
2077 (if the arg pointer isn't fixed, there will be a USE for
2078 it, so we can treat it normally). */
2079 || (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
2080 #endif
2081 || REGNO_REG_SET_P (needed, regno))
2082 return 0;
2083
2084 /* If this is a hard register, verify that subsequent words are
2085 not needed. */
2086 if (regno < FIRST_PSEUDO_REGISTER)
2087 {
2088 int n = HARD_REGNO_NREGS (regno, GET_MODE (r));
2089
2090 while (--n > 0)
2091 if (REGNO_REG_SET_P (needed, regno+n))
2092 return 0;
2093 }
2094
2095 return 1;
2096 }
2097 }
2098
2099 /* If performing several activities,
2100 insn is dead if each activity is individually dead.
2101 Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
2102 that's inside a PARALLEL doesn't make the insn worth keeping. */
2103 else if (code == PARALLEL)
2104 {
2105 int i = XVECLEN (x, 0);
2106
2107 for (i--; i >= 0; i--)
2108 if (GET_CODE (XVECEXP (x, 0, i)) != CLOBBER
2109 && GET_CODE (XVECEXP (x, 0, i)) != USE
2110 && ! insn_dead_p (XVECEXP (x, 0, i), needed, call_ok, NULL_RTX))
2111 return 0;
2112
2113 return 1;
2114 }
2115
2116 /* A CLOBBER of a pseudo-register that is dead serves no purpose. That
2117 is not necessarily true for hard registers. */
2118 else if (code == CLOBBER && GET_CODE (XEXP (x, 0)) == REG
2119 && REGNO (XEXP (x, 0)) >= FIRST_PSEUDO_REGISTER
2120 && ! REGNO_REG_SET_P (needed, REGNO (XEXP (x, 0))))
2121 return 1;
2122
2123 /* We do not check other CLOBBER or USE here. An insn consisting of just
2124 a CLOBBER or just a USE should not be deleted. */
2125 return 0;
2126 }
2127
2128 /* If X is the pattern of the last insn in a libcall, and assuming X is dead,
2129 return 1 if the entire library call is dead.
2130 This is true if X copies a register (hard or pseudo)
2131 and if the hard return reg of the call insn is dead.
2132 (The caller should have tested the destination of X already for death.)
2133
2134 If this insn doesn't just copy a register, then we don't
2135 have an ordinary libcall. In that case, cse could not have
2136 managed to substitute the source for the dest later on,
2137 so we can assume the libcall is dead.
2138
2139 NEEDED is the bit vector of pseudoregs live before this insn.
2140 NOTE is the REG_RETVAL note of the insn. INSN is the insn itself. */
2141
2142 static int
2143 libcall_dead_p (x, needed, note, insn)
2144 rtx x;
2145 regset needed;
2146 rtx note;
2147 rtx insn;
2148 {
2149 register RTX_CODE code = GET_CODE (x);
2150
2151 if (code == SET)
2152 {
2153 register rtx r = SET_SRC (x);
2154 if (GET_CODE (r) == REG)
2155 {
2156 rtx call = XEXP (note, 0);
2157 rtx call_pat;
2158 register int i;
2159
2160 /* Find the call insn. */
2161 while (call != insn && GET_CODE (call) != CALL_INSN)
2162 call = NEXT_INSN (call);
2163
2164 /* If there is none, do nothing special,
2165 since ordinary death handling can understand these insns. */
2166 if (call == insn)
2167 return 0;
2168
2169 /* See if the hard reg holding the value is dead.
2170 If this is a PARALLEL, find the call within it. */
2171 call_pat = PATTERN (call);
2172 if (GET_CODE (call_pat) == PARALLEL)
2173 {
2174 for (i = XVECLEN (call_pat, 0) - 1; i >= 0; i--)
2175 if (GET_CODE (XVECEXP (call_pat, 0, i)) == SET
2176 && GET_CODE (SET_SRC (XVECEXP (call_pat, 0, i))) == CALL)
2177 break;
2178
2179 /* This may be a library call that is returning a value
2180 via invisible pointer. Do nothing special, since
2181 ordinary death handling can understand these insns. */
2182 if (i < 0)
2183 return 0;
2184
2185 call_pat = XVECEXP (call_pat, 0, i);
2186 }
2187
2188 return insn_dead_p (call_pat, needed, 1, REG_NOTES (call));
2189 }
2190 }
2191 return 1;
2192 }
2193
2194 /* Return 1 if register REGNO was used before it was set, i.e. if it is
2195 live at function entry. Don't count global register variables, variables
2196 in registers that can be used for function arg passing, or variables in
2197 fixed hard registers. */
2198
2199 int
2200 regno_uninitialized (regno)
2201 int regno;
2202 {
2203 if (n_basic_blocks == 0
2204 || (regno < FIRST_PSEUDO_REGISTER
2205 && (global_regs[regno]
2206 || fixed_regs[regno]
2207 || FUNCTION_ARG_REGNO_P (regno))))
2208 return 0;
2209
2210 return REGNO_REG_SET_P (basic_block_live_at_start[0], regno);
2211 }
2212
2213 /* 1 if register REGNO was alive at a place where `setjmp' was called
2214 and was set more than once or is an argument.
2215 Such regs may be clobbered by `longjmp'. */
2216
2217 int
2218 regno_clobbered_at_setjmp (regno)
2219 int regno;
2220 {
2221 if (n_basic_blocks == 0)
2222 return 0;
2223
2224 return ((REG_N_SETS (regno) > 1
2225 || REGNO_REG_SET_P (basic_block_live_at_start[0], regno))
2226 && REGNO_REG_SET_P (regs_live_at_setjmp, regno));
2227 }
2228 \f
2229 /* INSN references memory, possibly using autoincrement addressing modes.
2230 Find any entries on the mem_set_list that need to be invalidated due
2231 to an address change. */
2232 static void
2233 invalidate_mems_from_autoinc (insn)
2234 rtx insn;
2235 {
2236 rtx note = REG_NOTES (insn);
2237 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2238 {
2239 if (REG_NOTE_KIND (note) == REG_INC)
2240 {
2241 rtx temp = mem_set_list;
2242 rtx prev = NULL_RTX;
2243
2244 while (temp)
2245 {
2246 if (reg_overlap_mentioned_p (XEXP (note, 0), XEXP (temp, 0)))
2247 {
2248 /* Splice temp out of list. */
2249 if (prev)
2250 XEXP (prev, 1) = XEXP (temp, 1);
2251 else
2252 mem_set_list = XEXP (temp, 1);
2253 }
2254 else
2255 prev = temp;
2256 temp = XEXP (temp, 1);
2257 }
2258 }
2259 }
2260 }
2261
2262 /* Process the registers that are set within X.
2263 Their bits are set to 1 in the regset DEAD,
2264 because they are dead prior to this insn.
2265
2266 If INSN is nonzero, it is the insn being processed
2267 and the fact that it is nonzero implies this is the FINAL pass
2268 in propagate_block. In this case, various info about register
2269 usage is stored, LOG_LINKS fields of insns are set up. */
2270
2271 static void
2272 mark_set_regs (needed, dead, x, insn, significant)
2273 regset needed;
2274 regset dead;
2275 rtx x;
2276 rtx insn;
2277 regset significant;
2278 {
2279 register RTX_CODE code = GET_CODE (x);
2280
2281 if (code == SET || code == CLOBBER)
2282 mark_set_1 (needed, dead, x, insn, significant);
2283 else if (code == PARALLEL)
2284 {
2285 register int i;
2286 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
2287 {
2288 code = GET_CODE (XVECEXP (x, 0, i));
2289 if (code == SET || code == CLOBBER)
2290 mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant);
2291 }
2292 }
2293 }
2294
2295 /* Process a single SET rtx, X. */
2296
2297 static void
2298 mark_set_1 (needed, dead, x, insn, significant)
2299 regset needed;
2300 regset dead;
2301 rtx x;
2302 rtx insn;
2303 regset significant;
2304 {
2305 register int regno;
2306 register rtx reg = SET_DEST (x);
2307
2308 /* Some targets place small structures in registers for
2309 return values of functions. We have to detect this
2310 case specially here to get correct flow information. */
2311 if (GET_CODE (reg) == PARALLEL
2312 && GET_MODE (reg) == BLKmode)
2313 {
2314 register int i;
2315
2316 for (i = XVECLEN (reg, 0) - 1; i >= 0; i--)
2317 mark_set_1 (needed, dead, XVECEXP (reg, 0, i), insn, significant);
2318 return;
2319 }
2320
2321 /* Modifying just one hardware register of a multi-reg value
2322 or just a byte field of a register
2323 does not mean the value from before this insn is now dead.
2324 But it does mean liveness of that register at the end of the block
2325 is significant.
2326
2327 Within mark_set_1, however, we treat it as if the register is
2328 indeed modified. mark_used_regs will, however, also treat this
2329 register as being used. Thus, we treat these insns as setting a
2330 new value for the register as a function of its old value. This
2331 cases LOG_LINKS to be made appropriately and this will help combine. */
2332
2333 while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
2334 || GET_CODE (reg) == SIGN_EXTRACT
2335 || GET_CODE (reg) == STRICT_LOW_PART)
2336 reg = XEXP (reg, 0);
2337
2338 /* If this set is a MEM, then it kills any aliased writes.
2339 If this set is a REG, then it kills any MEMs which use the reg. */
2340 if (GET_CODE (reg) == MEM
2341 || GET_CODE (reg) == REG)
2342 {
2343 rtx temp = mem_set_list;
2344 rtx prev = NULL_RTX;
2345
2346 while (temp)
2347 {
2348 if ((GET_CODE (reg) == MEM
2349 && output_dependence (XEXP (temp, 0), reg))
2350 || (GET_CODE (reg) == REG
2351 && reg_overlap_mentioned_p (reg, XEXP (temp, 0))))
2352 {
2353 /* Splice this entry out of the list. */
2354 if (prev)
2355 XEXP (prev, 1) = XEXP (temp, 1);
2356 else
2357 mem_set_list = XEXP (temp, 1);
2358 }
2359 else
2360 prev = temp;
2361 temp = XEXP (temp, 1);
2362 }
2363 }
2364
2365 /* If the memory reference had embedded side effects (autoincrement
2366 address modes. Then we may need to kill some entries on the
2367 memory set list. */
2368 if (insn && GET_CODE (reg) == MEM)
2369 invalidate_mems_from_autoinc (insn);
2370
2371 if (GET_CODE (reg) == MEM && ! side_effects_p (reg)
2372 /* There are no REG_INC notes for SP, so we can't assume we'll see
2373 everything that invalidates it. To be safe, don't eliminate any
2374 stores though SP; none of them should be redundant anyway. */
2375 && ! reg_mentioned_p (stack_pointer_rtx, reg))
2376 mem_set_list = gen_rtx_EXPR_LIST (VOIDmode, reg, mem_set_list);
2377
2378 if (GET_CODE (reg) == REG
2379 && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM)
2380 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2381 && regno != HARD_FRAME_POINTER_REGNUM
2382 #endif
2383 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2384 && ! (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
2385 #endif
2386 && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]))
2387 /* && regno != STACK_POINTER_REGNUM) -- let's try without this. */
2388 {
2389 int some_needed = REGNO_REG_SET_P (needed, regno);
2390 int some_not_needed = ! some_needed;
2391
2392 /* Mark it as a significant register for this basic block. */
2393 if (significant)
2394 SET_REGNO_REG_SET (significant, regno);
2395
2396 /* Mark it as dead before this insn. */
2397 SET_REGNO_REG_SET (dead, regno);
2398
2399 /* A hard reg in a wide mode may really be multiple registers.
2400 If so, mark all of them just like the first. */
2401 if (regno < FIRST_PSEUDO_REGISTER)
2402 {
2403 int n;
2404
2405 /* Nothing below is needed for the stack pointer; get out asap.
2406 Eg, log links aren't needed, since combine won't use them. */
2407 if (regno == STACK_POINTER_REGNUM)
2408 return;
2409
2410 n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
2411 while (--n > 0)
2412 {
2413 int regno_n = regno + n;
2414 int needed_regno = REGNO_REG_SET_P (needed, regno_n);
2415 if (significant)
2416 SET_REGNO_REG_SET (significant, regno_n);
2417
2418 SET_REGNO_REG_SET (dead, regno_n);
2419 some_needed |= needed_regno;
2420 some_not_needed |= ! needed_regno;
2421 }
2422 }
2423 /* Additional data to record if this is the final pass. */
2424 if (insn)
2425 {
2426 register rtx y = reg_next_use[regno];
2427 register int blocknum = BLOCK_NUM (insn);
2428
2429 /* If this is a hard reg, record this function uses the reg. */
2430
2431 if (regno < FIRST_PSEUDO_REGISTER)
2432 {
2433 register int i;
2434 int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
2435
2436 for (i = regno; i < endregno; i++)
2437 {
2438 /* The next use is no longer "next", since a store
2439 intervenes. */
2440 reg_next_use[i] = 0;
2441
2442 regs_ever_live[i] = 1;
2443 REG_N_SETS (i)++;
2444 }
2445 }
2446 else
2447 {
2448 /* The next use is no longer "next", since a store
2449 intervenes. */
2450 reg_next_use[regno] = 0;
2451
2452 /* Keep track of which basic blocks each reg appears in. */
2453
2454 if (REG_BASIC_BLOCK (regno) == REG_BLOCK_UNKNOWN)
2455 REG_BASIC_BLOCK (regno) = blocknum;
2456 else if (REG_BASIC_BLOCK (regno) != blocknum)
2457 REG_BASIC_BLOCK (regno) = REG_BLOCK_GLOBAL;
2458
2459 /* Count (weighted) references, stores, etc. This counts a
2460 register twice if it is modified, but that is correct. */
2461 REG_N_SETS (regno)++;
2462
2463 REG_N_REFS (regno) += loop_depth;
2464
2465 /* The insns where a reg is live are normally counted
2466 elsewhere, but we want the count to include the insn
2467 where the reg is set, and the normal counting mechanism
2468 would not count it. */
2469 REG_LIVE_LENGTH (regno)++;
2470 }
2471
2472 if (! some_not_needed)
2473 {
2474 /* Make a logical link from the next following insn
2475 that uses this register, back to this insn.
2476 The following insns have already been processed.
2477
2478 We don't build a LOG_LINK for hard registers containing
2479 in ASM_OPERANDs. If these registers get replaced,
2480 we might wind up changing the semantics of the insn,
2481 even if reload can make what appear to be valid assignments
2482 later. */
2483 if (y && (BLOCK_NUM (y) == blocknum)
2484 && (regno >= FIRST_PSEUDO_REGISTER
2485 || asm_noperands (PATTERN (y)) < 0))
2486 LOG_LINKS (y)
2487 = gen_rtx_INSN_LIST (VOIDmode, insn, LOG_LINKS (y));
2488 }
2489 else if (! some_needed)
2490 {
2491 /* Note that dead stores have already been deleted when possible
2492 If we get here, we have found a dead store that cannot
2493 be eliminated (because the same insn does something useful).
2494 Indicate this by marking the reg being set as dying here. */
2495 REG_NOTES (insn)
2496 = gen_rtx_EXPR_LIST (REG_UNUSED, reg, REG_NOTES (insn));
2497 REG_N_DEATHS (REGNO (reg))++;
2498 }
2499 else
2500 {
2501 /* This is a case where we have a multi-word hard register
2502 and some, but not all, of the words of the register are
2503 needed in subsequent insns. Write REG_UNUSED notes
2504 for those parts that were not needed. This case should
2505 be rare. */
2506
2507 int i;
2508
2509 for (i = HARD_REGNO_NREGS (regno, GET_MODE (reg)) - 1;
2510 i >= 0; i--)
2511 if (!REGNO_REG_SET_P (needed, regno + i))
2512 REG_NOTES (insn)
2513 = gen_rtx_EXPR_LIST (REG_UNUSED,
2514 gen_rtx_REG (reg_raw_mode[regno + i],
2515 regno + i),
2516 REG_NOTES (insn));
2517 }
2518 }
2519 }
2520 else if (GET_CODE (reg) == REG)
2521 reg_next_use[regno] = 0;
2522
2523 /* If this is the last pass and this is a SCRATCH, show it will be dying
2524 here and count it. */
2525 else if (GET_CODE (reg) == SCRATCH && insn != 0)
2526 {
2527 REG_NOTES (insn)
2528 = gen_rtx_EXPR_LIST (REG_UNUSED, reg, REG_NOTES (insn));
2529 }
2530 }
2531 \f
2532 #ifdef AUTO_INC_DEC
2533
2534 /* X is a MEM found in INSN. See if we can convert it into an auto-increment
2535 reference. */
2536
2537 static void
2538 find_auto_inc (needed, x, insn)
2539 regset needed;
2540 rtx x;
2541 rtx insn;
2542 {
2543 rtx addr = XEXP (x, 0);
2544 HOST_WIDE_INT offset = 0;
2545 rtx set;
2546
2547 /* Here we detect use of an index register which might be good for
2548 postincrement, postdecrement, preincrement, or predecrement. */
2549
2550 if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2551 offset = INTVAL (XEXP (addr, 1)), addr = XEXP (addr, 0);
2552
2553 if (GET_CODE (addr) == REG)
2554 {
2555 register rtx y;
2556 register int size = GET_MODE_SIZE (GET_MODE (x));
2557 rtx use;
2558 rtx incr;
2559 int regno = REGNO (addr);
2560
2561 /* Is the next use an increment that might make auto-increment? */
2562 if ((incr = reg_next_use[regno]) != 0
2563 && (set = single_set (incr)) != 0
2564 && GET_CODE (set) == SET
2565 && BLOCK_NUM (incr) == BLOCK_NUM (insn)
2566 /* Can't add side effects to jumps; if reg is spilled and
2567 reloaded, there's no way to store back the altered value. */
2568 && GET_CODE (insn) != JUMP_INSN
2569 && (y = SET_SRC (set), GET_CODE (y) == PLUS)
2570 && XEXP (y, 0) == addr
2571 && GET_CODE (XEXP (y, 1)) == CONST_INT
2572 && ((HAVE_POST_INCREMENT
2573 && (INTVAL (XEXP (y, 1)) == size && offset == 0))
2574 || (HAVE_POST_DECREMENT
2575 && (INTVAL (XEXP (y, 1)) == - size && offset == 0))
2576 || (HAVE_PRE_INCREMENT
2577 && (INTVAL (XEXP (y, 1)) == size && offset == size))
2578 || (HAVE_PRE_DECREMENT
2579 && (INTVAL (XEXP (y, 1)) == - size && offset == - size)))
2580 /* Make sure this reg appears only once in this insn. */
2581 && (use = find_use_as_address (PATTERN (insn), addr, offset),
2582 use != 0 && use != (rtx) 1))
2583 {
2584 rtx q = SET_DEST (set);
2585 enum rtx_code inc_code = (INTVAL (XEXP (y, 1)) == size
2586 ? (offset ? PRE_INC : POST_INC)
2587 : (offset ? PRE_DEC : POST_DEC));
2588
2589 if (dead_or_set_p (incr, addr))
2590 {
2591 /* This is the simple case. Try to make the auto-inc. If
2592 we can't, we are done. Otherwise, we will do any
2593 needed updates below. */
2594 if (! validate_change (insn, &XEXP (x, 0),
2595 gen_rtx_fmt_e (inc_code, Pmode, addr),
2596 0))
2597 return;
2598 }
2599 else if (GET_CODE (q) == REG
2600 /* PREV_INSN used here to check the semi-open interval
2601 [insn,incr). */
2602 && ! reg_used_between_p (q, PREV_INSN (insn), incr)
2603 /* We must also check for sets of q as q may be
2604 a call clobbered hard register and there may
2605 be a call between PREV_INSN (insn) and incr. */
2606 && ! reg_set_between_p (q, PREV_INSN (insn), incr))
2607 {
2608 /* We have *p followed sometime later by q = p+size.
2609 Both p and q must be live afterward,
2610 and q is not used between INSN and its assignment.
2611 Change it to q = p, ...*q..., q = q+size.
2612 Then fall into the usual case. */
2613 rtx insns, temp;
2614
2615 start_sequence ();
2616 emit_move_insn (q, addr);
2617 insns = get_insns ();
2618 end_sequence ();
2619
2620 /* If anything in INSNS have UID's that don't fit within the
2621 extra space we allocate earlier, we can't make this auto-inc.
2622 This should never happen. */
2623 for (temp = insns; temp; temp = NEXT_INSN (temp))
2624 {
2625 if (INSN_UID (temp) > max_uid_for_flow)
2626 return;
2627 BLOCK_NUM (temp) = BLOCK_NUM (insn);
2628 }
2629
2630 /* If we can't make the auto-inc, or can't make the
2631 replacement into Y, exit. There's no point in making
2632 the change below if we can't do the auto-inc and doing
2633 so is not correct in the pre-inc case. */
2634
2635 validate_change (insn, &XEXP (x, 0),
2636 gen_rtx_fmt_e (inc_code, Pmode, q),
2637 1);
2638 validate_change (incr, &XEXP (y, 0), q, 1);
2639 if (! apply_change_group ())
2640 return;
2641
2642 /* We now know we'll be doing this change, so emit the
2643 new insn(s) and do the updates. */
2644 emit_insns_before (insns, insn);
2645
2646 if (BLOCK_HEAD (BLOCK_NUM (insn)) == insn)
2647 BLOCK_HEAD (BLOCK_NUM (insn)) = insns;
2648
2649 /* INCR will become a NOTE and INSN won't contain a
2650 use of ADDR. If a use of ADDR was just placed in
2651 the insn before INSN, make that the next use.
2652 Otherwise, invalidate it. */
2653 if (GET_CODE (PREV_INSN (insn)) == INSN
2654 && GET_CODE (PATTERN (PREV_INSN (insn))) == SET
2655 && SET_SRC (PATTERN (PREV_INSN (insn))) == addr)
2656 reg_next_use[regno] = PREV_INSN (insn);
2657 else
2658 reg_next_use[regno] = 0;
2659
2660 addr = q;
2661 regno = REGNO (q);
2662
2663 /* REGNO is now used in INCR which is below INSN, but
2664 it previously wasn't live here. If we don't mark
2665 it as needed, we'll put a REG_DEAD note for it
2666 on this insn, which is incorrect. */
2667 SET_REGNO_REG_SET (needed, regno);
2668
2669 /* If there are any calls between INSN and INCR, show
2670 that REGNO now crosses them. */
2671 for (temp = insn; temp != incr; temp = NEXT_INSN (temp))
2672 if (GET_CODE (temp) == CALL_INSN)
2673 REG_N_CALLS_CROSSED (regno)++;
2674 }
2675 else
2676 return;
2677
2678 /* If we haven't returned, it means we were able to make the
2679 auto-inc, so update the status. First, record that this insn
2680 has an implicit side effect. */
2681
2682 REG_NOTES (insn)
2683 = gen_rtx_EXPR_LIST (REG_INC, addr, REG_NOTES (insn));
2684
2685 /* Modify the old increment-insn to simply copy
2686 the already-incremented value of our register. */
2687 if (! validate_change (incr, &SET_SRC (set), addr, 0))
2688 abort ();
2689
2690 /* If that makes it a no-op (copying the register into itself) delete
2691 it so it won't appear to be a "use" and a "set" of this
2692 register. */
2693 if (SET_DEST (set) == addr)
2694 {
2695 PUT_CODE (incr, NOTE);
2696 NOTE_LINE_NUMBER (incr) = NOTE_INSN_DELETED;
2697 NOTE_SOURCE_FILE (incr) = 0;
2698 }
2699
2700 if (regno >= FIRST_PSEUDO_REGISTER)
2701 {
2702 /* Count an extra reference to the reg. When a reg is
2703 incremented, spilling it is worse, so we want to make
2704 that less likely. */
2705 REG_N_REFS (regno) += loop_depth;
2706
2707 /* Count the increment as a setting of the register,
2708 even though it isn't a SET in rtl. */
2709 REG_N_SETS (regno)++;
2710 }
2711 }
2712 }
2713 }
2714 #endif /* AUTO_INC_DEC */
2715 \f
2716 /* Scan expression X and store a 1-bit in LIVE for each reg it uses.
2717 This is done assuming the registers needed from X
2718 are those that have 1-bits in NEEDED.
2719
2720 On the final pass, FINAL is 1. This means try for autoincrement
2721 and count the uses and deaths of each pseudo-reg.
2722
2723 INSN is the containing instruction. If INSN is dead, this function is not
2724 called. */
2725
2726 static void
2727 mark_used_regs (needed, live, x, final, insn)
2728 regset needed;
2729 regset live;
2730 rtx x;
2731 int final;
2732 rtx insn;
2733 {
2734 register RTX_CODE code;
2735 register int regno;
2736 int i;
2737
2738 retry:
2739 code = GET_CODE (x);
2740 switch (code)
2741 {
2742 case LABEL_REF:
2743 case SYMBOL_REF:
2744 case CONST_INT:
2745 case CONST:
2746 case CONST_DOUBLE:
2747 case PC:
2748 case ADDR_VEC:
2749 case ADDR_DIFF_VEC:
2750 case ASM_INPUT:
2751 return;
2752
2753 #ifdef HAVE_cc0
2754 case CC0:
2755 cc0_live = 1;
2756 return;
2757 #endif
2758
2759 case CLOBBER:
2760 /* If we are clobbering a MEM, mark any registers inside the address
2761 as being used. */
2762 if (GET_CODE (XEXP (x, 0)) == MEM)
2763 mark_used_regs (needed, live, XEXP (XEXP (x, 0), 0), final, insn);
2764 return;
2765
2766 case MEM:
2767 /* Invalidate the data for the last MEM stored, but only if MEM is
2768 something that can be stored into. */
2769 if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
2770 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
2771 ; /* needn't clear the memory set list */
2772 else
2773 {
2774 rtx temp = mem_set_list;
2775 rtx prev = NULL_RTX;
2776
2777 while (temp)
2778 {
2779 if (anti_dependence (XEXP (temp, 0), x))
2780 {
2781 /* Splice temp out of the list. */
2782 if (prev)
2783 XEXP (prev, 1) = XEXP (temp, 1);
2784 else
2785 mem_set_list = XEXP (temp, 1);
2786 }
2787 else
2788 prev = temp;
2789 temp = XEXP (temp, 1);
2790 }
2791 }
2792
2793 /* If the memory reference had embedded side effects (autoincrement
2794 address modes. Then we may need to kill some entries on the
2795 memory set list. */
2796 if (insn)
2797 invalidate_mems_from_autoinc (insn);
2798
2799 #ifdef AUTO_INC_DEC
2800 if (final)
2801 find_auto_inc (needed, x, insn);
2802 #endif
2803 break;
2804
2805 case SUBREG:
2806 if (GET_CODE (SUBREG_REG (x)) == REG
2807 && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER
2808 && (GET_MODE_SIZE (GET_MODE (x))
2809 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
2810 REG_CHANGES_SIZE (REGNO (SUBREG_REG (x))) = 1;
2811
2812 /* While we're here, optimize this case. */
2813 x = SUBREG_REG (x);
2814
2815 /* In case the SUBREG is not of a register, don't optimize */
2816 if (GET_CODE (x) != REG)
2817 {
2818 mark_used_regs (needed, live, x, final, insn);
2819 return;
2820 }
2821
2822 /* ... fall through ... */
2823
2824 case REG:
2825 /* See a register other than being set
2826 => mark it as needed. */
2827
2828 regno = REGNO (x);
2829 {
2830 int some_needed = REGNO_REG_SET_P (needed, regno);
2831 int some_not_needed = ! some_needed;
2832
2833 SET_REGNO_REG_SET (live, regno);
2834
2835 /* A hard reg in a wide mode may really be multiple registers.
2836 If so, mark all of them just like the first. */
2837 if (regno < FIRST_PSEUDO_REGISTER)
2838 {
2839 int n;
2840
2841 /* For stack ptr or fixed arg pointer,
2842 nothing below can be necessary, so waste no more time. */
2843 if (regno == STACK_POINTER_REGNUM
2844 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2845 || regno == HARD_FRAME_POINTER_REGNUM
2846 #endif
2847 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2848 || (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
2849 #endif
2850 || regno == FRAME_POINTER_REGNUM)
2851 {
2852 /* If this is a register we are going to try to eliminate,
2853 don't mark it live here. If we are successful in
2854 eliminating it, it need not be live unless it is used for
2855 pseudos, in which case it will have been set live when
2856 it was allocated to the pseudos. If the register will not
2857 be eliminated, reload will set it live at that point. */
2858
2859 if (! TEST_HARD_REG_BIT (elim_reg_set, regno))
2860 regs_ever_live[regno] = 1;
2861 return;
2862 }
2863 /* No death notes for global register variables;
2864 their values are live after this function exits. */
2865 if (global_regs[regno])
2866 {
2867 if (final)
2868 reg_next_use[regno] = insn;
2869 return;
2870 }
2871
2872 n = HARD_REGNO_NREGS (regno, GET_MODE (x));
2873 while (--n > 0)
2874 {
2875 int regno_n = regno + n;
2876 int needed_regno = REGNO_REG_SET_P (needed, regno_n);
2877
2878 SET_REGNO_REG_SET (live, regno_n);
2879 some_needed |= needed_regno;
2880 some_not_needed |= ! needed_regno;
2881 }
2882 }
2883 if (final)
2884 {
2885 /* Record where each reg is used, so when the reg
2886 is set we know the next insn that uses it. */
2887
2888 reg_next_use[regno] = insn;
2889
2890 if (regno < FIRST_PSEUDO_REGISTER)
2891 {
2892 /* If a hard reg is being used,
2893 record that this function does use it. */
2894
2895 i = HARD_REGNO_NREGS (regno, GET_MODE (x));
2896 if (i == 0)
2897 i = 1;
2898 do
2899 regs_ever_live[regno + --i] = 1;
2900 while (i > 0);
2901 }
2902 else
2903 {
2904 /* Keep track of which basic block each reg appears in. */
2905
2906 register int blocknum = BLOCK_NUM (insn);
2907
2908 if (REG_BASIC_BLOCK (regno) == REG_BLOCK_UNKNOWN)
2909 REG_BASIC_BLOCK (regno) = blocknum;
2910 else if (REG_BASIC_BLOCK (regno) != blocknum)
2911 REG_BASIC_BLOCK (regno) = REG_BLOCK_GLOBAL;
2912
2913 /* Count (weighted) number of uses of each reg. */
2914
2915 REG_N_REFS (regno) += loop_depth;
2916 }
2917
2918 /* Record and count the insns in which a reg dies.
2919 If it is used in this insn and was dead below the insn
2920 then it dies in this insn. If it was set in this insn,
2921 we do not make a REG_DEAD note; likewise if we already
2922 made such a note. */
2923
2924 if (some_not_needed
2925 && ! dead_or_set_p (insn, x)
2926 #if 0
2927 && (regno >= FIRST_PSEUDO_REGISTER || ! fixed_regs[regno])
2928 #endif
2929 )
2930 {
2931 /* Check for the case where the register dying partially
2932 overlaps the register set by this insn. */
2933 if (regno < FIRST_PSEUDO_REGISTER
2934 && HARD_REGNO_NREGS (regno, GET_MODE (x)) > 1)
2935 {
2936 int n = HARD_REGNO_NREGS (regno, GET_MODE (x));
2937 while (--n >= 0)
2938 some_needed |= dead_or_set_regno_p (insn, regno + n);
2939 }
2940
2941 /* If none of the words in X is needed, make a REG_DEAD
2942 note. Otherwise, we must make partial REG_DEAD notes. */
2943 if (! some_needed)
2944 {
2945 REG_NOTES (insn)
2946 = gen_rtx_EXPR_LIST (REG_DEAD, x, REG_NOTES (insn));
2947 REG_N_DEATHS (regno)++;
2948 }
2949 else
2950 {
2951 int i;
2952
2953 /* Don't make a REG_DEAD note for a part of a register
2954 that is set in the insn. */
2955
2956 for (i = HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1;
2957 i >= 0; i--)
2958 if (!REGNO_REG_SET_P (needed, regno + i)
2959 && ! dead_or_set_regno_p (insn, regno + i))
2960 REG_NOTES (insn)
2961 = gen_rtx_EXPR_LIST (REG_DEAD,
2962 gen_rtx_REG (reg_raw_mode[regno + i],
2963 regno + i),
2964 REG_NOTES (insn));
2965 }
2966 }
2967 }
2968 }
2969 return;
2970
2971 case SET:
2972 {
2973 register rtx testreg = SET_DEST (x);
2974 int mark_dest = 0;
2975
2976 /* If storing into MEM, don't show it as being used. But do
2977 show the address as being used. */
2978 if (GET_CODE (testreg) == MEM)
2979 {
2980 #ifdef AUTO_INC_DEC
2981 if (final)
2982 find_auto_inc (needed, testreg, insn);
2983 #endif
2984 mark_used_regs (needed, live, XEXP (testreg, 0), final, insn);
2985 mark_used_regs (needed, live, SET_SRC (x), final, insn);
2986 return;
2987 }
2988
2989 /* Storing in STRICT_LOW_PART is like storing in a reg
2990 in that this SET might be dead, so ignore it in TESTREG.
2991 but in some other ways it is like using the reg.
2992
2993 Storing in a SUBREG or a bit field is like storing the entire
2994 register in that if the register's value is not used
2995 then this SET is not needed. */
2996 while (GET_CODE (testreg) == STRICT_LOW_PART
2997 || GET_CODE (testreg) == ZERO_EXTRACT
2998 || GET_CODE (testreg) == SIGN_EXTRACT
2999 || GET_CODE (testreg) == SUBREG)
3000 {
3001 if (GET_CODE (testreg) == SUBREG
3002 && GET_CODE (SUBREG_REG (testreg)) == REG
3003 && REGNO (SUBREG_REG (testreg)) >= FIRST_PSEUDO_REGISTER
3004 && (GET_MODE_SIZE (GET_MODE (testreg))
3005 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (testreg)))))
3006 REG_CHANGES_SIZE (REGNO (SUBREG_REG (testreg))) = 1;
3007
3008 /* Modifying a single register in an alternate mode
3009 does not use any of the old value. But these other
3010 ways of storing in a register do use the old value. */
3011 if (GET_CODE (testreg) == SUBREG
3012 && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
3013 ;
3014 else
3015 mark_dest = 1;
3016
3017 testreg = XEXP (testreg, 0);
3018 }
3019
3020 /* If this is a store into a register,
3021 recursively scan the value being stored. */
3022
3023 if ((GET_CODE (testreg) == PARALLEL
3024 && GET_MODE (testreg) == BLKmode)
3025 || (GET_CODE (testreg) == REG
3026 && (regno = REGNO (testreg), regno != FRAME_POINTER_REGNUM)
3027 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3028 && regno != HARD_FRAME_POINTER_REGNUM
3029 #endif
3030 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3031 && ! (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
3032 #endif
3033 ))
3034 /* We used to exclude global_regs here, but that seems wrong.
3035 Storing in them is like storing in mem. */
3036 {
3037 mark_used_regs (needed, live, SET_SRC (x), final, insn);
3038 if (mark_dest)
3039 mark_used_regs (needed, live, SET_DEST (x), final, insn);
3040 return;
3041 }
3042 }
3043 break;
3044
3045 case RETURN:
3046 /* If exiting needs the right stack value, consider this insn as
3047 using the stack pointer. In any event, consider it as using
3048 all global registers and all registers used by return. */
3049
3050 #ifdef EXIT_IGNORE_STACK
3051 if (! EXIT_IGNORE_STACK
3052 || (! FRAME_POINTER_REQUIRED
3053 && ! current_function_calls_alloca
3054 && flag_omit_frame_pointer)
3055 || current_function_sp_is_unchanging)
3056 #endif
3057 SET_REGNO_REG_SET (live, STACK_POINTER_REGNUM);
3058
3059 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3060 if (global_regs[i]
3061 #ifdef EPILOGUE_USES
3062 || EPILOGUE_USES (i)
3063 #endif
3064 )
3065 SET_REGNO_REG_SET (live, i);
3066 break;
3067
3068 default:
3069 break;
3070 }
3071
3072 /* Recursively scan the operands of this expression. */
3073
3074 {
3075 register char *fmt = GET_RTX_FORMAT (code);
3076 register int i;
3077
3078 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3079 {
3080 if (fmt[i] == 'e')
3081 {
3082 /* Tail recursive case: save a function call level. */
3083 if (i == 0)
3084 {
3085 x = XEXP (x, 0);
3086 goto retry;
3087 }
3088 mark_used_regs (needed, live, XEXP (x, i), final, insn);
3089 }
3090 else if (fmt[i] == 'E')
3091 {
3092 register int j;
3093 for (j = 0; j < XVECLEN (x, i); j++)
3094 mark_used_regs (needed, live, XVECEXP (x, i, j), final, insn);
3095 }
3096 }
3097 }
3098 }
3099 \f
3100 #ifdef AUTO_INC_DEC
3101
3102 static int
3103 try_pre_increment_1 (insn)
3104 rtx insn;
3105 {
3106 /* Find the next use of this reg. If in same basic block,
3107 make it do pre-increment or pre-decrement if appropriate. */
3108 rtx x = single_set (insn);
3109 HOST_WIDE_INT amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1)
3110 * INTVAL (XEXP (SET_SRC (x), 1)));
3111 int regno = REGNO (SET_DEST (x));
3112 rtx y = reg_next_use[regno];
3113 if (y != 0
3114 && BLOCK_NUM (y) == BLOCK_NUM (insn)
3115 /* Don't do this if the reg dies, or gets set in y; a standard addressing
3116 mode would be better. */
3117 && ! dead_or_set_p (y, SET_DEST (x))
3118 && try_pre_increment (y, SET_DEST (x), amount))
3119 {
3120 /* We have found a suitable auto-increment
3121 and already changed insn Y to do it.
3122 So flush this increment-instruction. */
3123 PUT_CODE (insn, NOTE);
3124 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
3125 NOTE_SOURCE_FILE (insn) = 0;
3126 /* Count a reference to this reg for the increment
3127 insn we are deleting. When a reg is incremented.
3128 spilling it is worse, so we want to make that
3129 less likely. */
3130 if (regno >= FIRST_PSEUDO_REGISTER)
3131 {
3132 REG_N_REFS (regno) += loop_depth;
3133 REG_N_SETS (regno)++;
3134 }
3135 return 1;
3136 }
3137 return 0;
3138 }
3139
3140 /* Try to change INSN so that it does pre-increment or pre-decrement
3141 addressing on register REG in order to add AMOUNT to REG.
3142 AMOUNT is negative for pre-decrement.
3143 Returns 1 if the change could be made.
3144 This checks all about the validity of the result of modifying INSN. */
3145
3146 static int
3147 try_pre_increment (insn, reg, amount)
3148 rtx insn, reg;
3149 HOST_WIDE_INT amount;
3150 {
3151 register rtx use;
3152
3153 /* Nonzero if we can try to make a pre-increment or pre-decrement.
3154 For example, addl $4,r1; movl (r1),... can become movl +(r1),... */
3155 int pre_ok = 0;
3156 /* Nonzero if we can try to make a post-increment or post-decrement.
3157 For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
3158 It is possible for both PRE_OK and POST_OK to be nonzero if the machine
3159 supports both pre-inc and post-inc, or both pre-dec and post-dec. */
3160 int post_ok = 0;
3161
3162 /* Nonzero if the opportunity actually requires post-inc or post-dec. */
3163 int do_post = 0;
3164
3165 /* From the sign of increment, see which possibilities are conceivable
3166 on this target machine. */
3167 if (HAVE_PRE_INCREMENT && amount > 0)
3168 pre_ok = 1;
3169 if (HAVE_POST_INCREMENT && amount > 0)
3170 post_ok = 1;
3171
3172 if (HAVE_PRE_DECREMENT && amount < 0)
3173 pre_ok = 1;
3174 if (HAVE_POST_DECREMENT && amount < 0)
3175 post_ok = 1;
3176
3177 if (! (pre_ok || post_ok))
3178 return 0;
3179
3180 /* It is not safe to add a side effect to a jump insn
3181 because if the incremented register is spilled and must be reloaded
3182 there would be no way to store the incremented value back in memory. */
3183
3184 if (GET_CODE (insn) == JUMP_INSN)
3185 return 0;
3186
3187 use = 0;
3188 if (pre_ok)
3189 use = find_use_as_address (PATTERN (insn), reg, 0);
3190 if (post_ok && (use == 0 || use == (rtx) 1))
3191 {
3192 use = find_use_as_address (PATTERN (insn), reg, -amount);
3193 do_post = 1;
3194 }
3195
3196 if (use == 0 || use == (rtx) 1)
3197 return 0;
3198
3199 if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount))
3200 return 0;
3201
3202 /* See if this combination of instruction and addressing mode exists. */
3203 if (! validate_change (insn, &XEXP (use, 0),
3204 gen_rtx_fmt_e (amount > 0
3205 ? (do_post ? POST_INC : PRE_INC)
3206 : (do_post ? POST_DEC : PRE_DEC),
3207 Pmode, reg), 0))
3208 return 0;
3209
3210 /* Record that this insn now has an implicit side effect on X. */
3211 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_INC, reg, REG_NOTES (insn));
3212 return 1;
3213 }
3214
3215 #endif /* AUTO_INC_DEC */
3216 \f
3217 /* Find the place in the rtx X where REG is used as a memory address.
3218 Return the MEM rtx that so uses it.
3219 If PLUSCONST is nonzero, search instead for a memory address equivalent to
3220 (plus REG (const_int PLUSCONST)).
3221
3222 If such an address does not appear, return 0.
3223 If REG appears more than once, or is used other than in such an address,
3224 return (rtx)1. */
3225
3226 rtx
3227 find_use_as_address (x, reg, plusconst)
3228 register rtx x;
3229 rtx reg;
3230 HOST_WIDE_INT plusconst;
3231 {
3232 enum rtx_code code = GET_CODE (x);
3233 char *fmt = GET_RTX_FORMAT (code);
3234 register int i;
3235 register rtx value = 0;
3236 register rtx tem;
3237
3238 if (code == MEM && XEXP (x, 0) == reg && plusconst == 0)
3239 return x;
3240
3241 if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS
3242 && XEXP (XEXP (x, 0), 0) == reg
3243 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3244 && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst)
3245 return x;
3246
3247 if (code == SIGN_EXTRACT || code == ZERO_EXTRACT)
3248 {
3249 /* If REG occurs inside a MEM used in a bit-field reference,
3250 that is unacceptable. */
3251 if (find_use_as_address (XEXP (x, 0), reg, 0) != 0)
3252 return (rtx) (HOST_WIDE_INT) 1;
3253 }
3254
3255 if (x == reg)
3256 return (rtx) (HOST_WIDE_INT) 1;
3257
3258 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3259 {
3260 if (fmt[i] == 'e')
3261 {
3262 tem = find_use_as_address (XEXP (x, i), reg, plusconst);
3263 if (value == 0)
3264 value = tem;
3265 else if (tem != 0)
3266 return (rtx) (HOST_WIDE_INT) 1;
3267 }
3268 if (fmt[i] == 'E')
3269 {
3270 register int j;
3271 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3272 {
3273 tem = find_use_as_address (XVECEXP (x, i, j), reg, plusconst);
3274 if (value == 0)
3275 value = tem;
3276 else if (tem != 0)
3277 return (rtx) (HOST_WIDE_INT) 1;
3278 }
3279 }
3280 }
3281
3282 return value;
3283 }
3284 \f
3285 /* Write information about registers and basic blocks into FILE.
3286 This is part of making a debugging dump. */
3287
3288 void
3289 dump_flow_info (file)
3290 FILE *file;
3291 {
3292 register int i;
3293 static char *reg_class_names[] = REG_CLASS_NAMES;
3294
3295 fprintf (file, "%d registers.\n", max_regno);
3296
3297 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
3298 if (REG_N_REFS (i))
3299 {
3300 enum reg_class class, altclass;
3301 fprintf (file, "\nRegister %d used %d times across %d insns",
3302 i, REG_N_REFS (i), REG_LIVE_LENGTH (i));
3303 if (REG_BASIC_BLOCK (i) >= 0)
3304 fprintf (file, " in block %d", REG_BASIC_BLOCK (i));
3305 if (REG_N_SETS (i))
3306 fprintf (file, "; set %d time%s", REG_N_SETS (i),
3307 (REG_N_SETS (i) == 1) ? "" : "s");
3308 if (REG_USERVAR_P (regno_reg_rtx[i]))
3309 fprintf (file, "; user var");
3310 if (REG_N_DEATHS (i) != 1)
3311 fprintf (file, "; dies in %d places", REG_N_DEATHS (i));
3312 if (REG_N_CALLS_CROSSED (i) == 1)
3313 fprintf (file, "; crosses 1 call");
3314 else if (REG_N_CALLS_CROSSED (i))
3315 fprintf (file, "; crosses %d calls", REG_N_CALLS_CROSSED (i));
3316 if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
3317 fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
3318 class = reg_preferred_class (i);
3319 altclass = reg_alternate_class (i);
3320 if (class != GENERAL_REGS || altclass != ALL_REGS)
3321 {
3322 if (altclass == ALL_REGS || class == ALL_REGS)
3323 fprintf (file, "; pref %s", reg_class_names[(int) class]);
3324 else if (altclass == NO_REGS)
3325 fprintf (file, "; %s or none", reg_class_names[(int) class]);
3326 else
3327 fprintf (file, "; pref %s, else %s",
3328 reg_class_names[(int) class],
3329 reg_class_names[(int) altclass]);
3330 }
3331 if (REGNO_POINTER_FLAG (i))
3332 fprintf (file, "; pointer");
3333 fprintf (file, ".\n");
3334 }
3335 fprintf (file, "\n%d basic blocks.\n", n_basic_blocks);
3336 dump_bb_data (file, basic_block_pred, basic_block_succ, 1);
3337 }
3338
3339 \f
3340 /* Like print_rtl, but also print out live information for the start of each
3341 basic block. */
3342
3343 void
3344 print_rtl_with_bb (outf, rtx_first)
3345 FILE *outf;
3346 rtx rtx_first;
3347 {
3348 register rtx tmp_rtx;
3349
3350 if (rtx_first == 0)
3351 fprintf (outf, "(nil)\n");
3352
3353 else
3354 {
3355 int i, bb;
3356 enum bb_state { NOT_IN_BB, IN_ONE_BB, IN_MULTIPLE_BB };
3357 int max_uid = get_max_uid ();
3358 int *start = (int *) alloca (max_uid * sizeof (int));
3359 int *end = (int *) alloca (max_uid * sizeof (int));
3360 enum bb_state *in_bb_p = (enum bb_state *)
3361 alloca (max_uid * sizeof (enum bb_state));
3362
3363 for (i = 0; i < max_uid; i++)
3364 {
3365 start[i] = end[i] = -1;
3366 in_bb_p[i] = NOT_IN_BB;
3367 }
3368
3369 for (i = n_basic_blocks-1; i >= 0; i--)
3370 {
3371 rtx x;
3372 start[INSN_UID (BLOCK_HEAD (i))] = i;
3373 end[INSN_UID (BLOCK_END (i))] = i;
3374 for (x = BLOCK_HEAD (i); x != NULL_RTX; x = NEXT_INSN (x))
3375 {
3376 in_bb_p[ INSN_UID(x)]
3377 = (in_bb_p[ INSN_UID(x)] == NOT_IN_BB)
3378 ? IN_ONE_BB : IN_MULTIPLE_BB;
3379 if (x == BLOCK_END (i))
3380 break;
3381 }
3382 }
3383
3384 for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx))
3385 {
3386 int did_output;
3387
3388 if ((bb = start[INSN_UID (tmp_rtx)]) >= 0)
3389 {
3390 fprintf (outf, ";; Start of basic block %d, registers live:",
3391 bb);
3392
3393 EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[bb], 0, i,
3394 {
3395 fprintf (outf, " %d", i);
3396 if (i < FIRST_PSEUDO_REGISTER)
3397 fprintf (outf, " [%s]",
3398 reg_names[i]);
3399 });
3400 putc ('\n', outf);
3401 }
3402
3403 if (in_bb_p[ INSN_UID(tmp_rtx)] == NOT_IN_BB
3404 && GET_CODE (tmp_rtx) != NOTE
3405 && GET_CODE (tmp_rtx) != BARRIER)
3406 fprintf (outf, ";; Insn is not within a basic block\n");
3407 else if (in_bb_p[ INSN_UID(tmp_rtx)] == IN_MULTIPLE_BB)
3408 fprintf (outf, ";; Insn is in multiple basic blocks\n");
3409
3410 did_output = print_rtl_single (outf, tmp_rtx);
3411
3412 if ((bb = end[INSN_UID (tmp_rtx)]) >= 0)
3413 fprintf (outf, ";; End of basic block %d\n", bb);
3414
3415 if (did_output)
3416 putc ('\n', outf);
3417 }
3418 }
3419 }
3420
3421 \f
3422 /* Integer list support. */
3423
3424 /* Allocate a node from list *HEAD_PTR. */
3425
3426 static int_list_ptr
3427 alloc_int_list_node (head_ptr)
3428 int_list_block **head_ptr;
3429 {
3430 struct int_list_block *first_blk = *head_ptr;
3431
3432 if (first_blk == NULL || first_blk->nodes_left <= 0)
3433 {
3434 first_blk = (struct int_list_block *) xmalloc (sizeof (struct int_list_block));
3435 first_blk->nodes_left = INT_LIST_NODES_IN_BLK;
3436 first_blk->next = *head_ptr;
3437 *head_ptr = first_blk;
3438 }
3439
3440 first_blk->nodes_left--;
3441 return &first_blk->nodes[first_blk->nodes_left];
3442 }
3443
3444 /* Pointer to head of predecessor/successor block list. */
3445 static int_list_block *pred_int_list_blocks;
3446
3447 /* Add a new node to integer list LIST with value VAL.
3448 LIST is a pointer to a list object to allow for different implementations.
3449 If *LIST is initially NULL, the list is empty.
3450 The caller must not care whether the element is added to the front or
3451 to the end of the list (to allow for different implementations). */
3452
3453 static int_list_ptr
3454 add_int_list_node (blk_list, list, val)
3455 int_list_block **blk_list;
3456 int_list **list;
3457 int val;
3458 {
3459 int_list_ptr p = alloc_int_list_node (blk_list);
3460
3461 p->val = val;
3462 p->next = *list;
3463 *list = p;
3464 return p;
3465 }
3466
3467 /* Free the blocks of lists at BLK_LIST. */
3468
3469 void
3470 free_int_list (blk_list)
3471 int_list_block **blk_list;
3472 {
3473 int_list_block *p, *next;
3474
3475 for (p = *blk_list; p != NULL; p = next)
3476 {
3477 next = p->next;
3478 free (p);
3479 }
3480
3481 /* Mark list as empty for the next function we compile. */
3482 *blk_list = NULL;
3483 }
3484 \f
3485 /* Predecessor/successor computation. */
3486
3487 /* Mark PRED_BB a precessor of SUCC_BB,
3488 and conversely SUCC_BB a successor of PRED_BB. */
3489
3490 static void
3491 add_pred_succ (pred_bb, succ_bb, s_preds, s_succs, num_preds, num_succs)
3492 int pred_bb;
3493 int succ_bb;
3494 int_list_ptr *s_preds;
3495 int_list_ptr *s_succs;
3496 int *num_preds;
3497 int *num_succs;
3498 {
3499 if (succ_bb != EXIT_BLOCK)
3500 {
3501 add_int_list_node (&pred_int_list_blocks, &s_preds[succ_bb], pred_bb);
3502 num_preds[succ_bb]++;
3503 }
3504 if (pred_bb != ENTRY_BLOCK)
3505 {
3506 add_int_list_node (&pred_int_list_blocks, &s_succs[pred_bb], succ_bb);
3507 num_succs[pred_bb]++;
3508 }
3509 }
3510
3511 /* Compute the predecessors and successors for each block. */
3512 void
3513 compute_preds_succs (s_preds, s_succs, num_preds, num_succs)
3514 int_list_ptr *s_preds;
3515 int_list_ptr *s_succs;
3516 int *num_preds;
3517 int *num_succs;
3518 {
3519 int bb;
3520
3521 bzero ((char *) s_preds, n_basic_blocks * sizeof (int_list_ptr));
3522 bzero ((char *) s_succs, n_basic_blocks * sizeof (int_list_ptr));
3523 bzero ((char *) num_preds, n_basic_blocks * sizeof (int));
3524 bzero ((char *) num_succs, n_basic_blocks * sizeof (int));
3525
3526 /* It's somewhat stupid to simply copy the information. The passes
3527 which use this function ought to be changed to refer directly to
3528 basic_block_succ and its relatives. */
3529 for (bb = 0; bb < n_basic_blocks; bb++)
3530 {
3531 rtx jump = BLOCK_END (bb);
3532 enum rtx_code code = GET_CODE (jump);
3533 int_list_ptr p;
3534
3535 for (p = basic_block_succ[bb]; p; p = p->next)
3536 add_pred_succ (bb, INT_LIST_VAL (p), s_preds, s_succs, num_preds,
3537 num_succs);
3538
3539 /* If this is a RETURN insn or a conditional jump in the last
3540 basic block, or a non-jump insn in the last basic block, then
3541 this block reaches the exit block. */
3542 if ((code == JUMP_INSN && GET_CODE (PATTERN (jump)) == RETURN)
3543 || (((code == JUMP_INSN
3544 && condjump_p (jump) && !simplejump_p (jump))
3545 || code != JUMP_INSN)
3546 && bb == n_basic_blocks - 1))
3547 add_pred_succ (bb, EXIT_BLOCK, s_preds, s_succs, num_preds, num_succs);
3548 }
3549
3550 add_pred_succ (ENTRY_BLOCK, 0, s_preds, s_succs, num_preds, num_succs);
3551 }
3552
3553 void
3554 dump_bb_data (file, preds, succs, live_info)
3555 FILE *file;
3556 int_list_ptr *preds;
3557 int_list_ptr *succs;
3558 int live_info;
3559 {
3560 int bb;
3561 int_list_ptr p;
3562
3563 fprintf (file, "BB data\n\n");
3564 for (bb = 0; bb < n_basic_blocks; bb++)
3565 {
3566 fprintf (file, "BB %d, start %d, end %d\n", bb,
3567 INSN_UID (BLOCK_HEAD (bb)), INSN_UID (BLOCK_END (bb)));
3568 fprintf (file, " preds:");
3569 for (p = preds[bb]; p != NULL; p = p->next)
3570 {
3571 int pred_bb = INT_LIST_VAL (p);
3572 if (pred_bb == ENTRY_BLOCK)
3573 fprintf (file, " entry");
3574 else
3575 fprintf (file, " %d", pred_bb);
3576 }
3577 fprintf (file, "\n");
3578 fprintf (file, " succs:");
3579 for (p = succs[bb]; p != NULL; p = p->next)
3580 {
3581 int succ_bb = INT_LIST_VAL (p);
3582 if (succ_bb == EXIT_BLOCK)
3583 fprintf (file, " exit");
3584 else
3585 fprintf (file, " %d", succ_bb);
3586 }
3587 if (live_info)
3588 {
3589 int regno;
3590 fprintf (file, "\nRegisters live at start:");
3591 for (regno = 0; regno < max_regno; regno++)
3592 if (REGNO_REG_SET_P (basic_block_live_at_start[bb], regno))
3593 fprintf (file, " %d", regno);
3594 fprintf (file, "\n");
3595 }
3596 fprintf (file, "\n");
3597 }
3598 fprintf (file, "\n");
3599 }
3600
3601 /* Free basic block data storage. */
3602
3603 void
3604 free_bb_mem ()
3605 {
3606 free_int_list (&pred_int_list_blocks);
3607 }
3608
3609 /* Compute dominator relationships. */
3610 void
3611 compute_dominators (dominators, post_dominators, s_preds, s_succs)
3612 sbitmap *dominators;
3613 sbitmap *post_dominators;
3614 int_list_ptr *s_preds;
3615 int_list_ptr *s_succs;
3616 {
3617 int bb, changed, passes;
3618 sbitmap *temp_bitmap;
3619
3620 temp_bitmap = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
3621 sbitmap_vector_ones (dominators, n_basic_blocks);
3622 sbitmap_vector_ones (post_dominators, n_basic_blocks);
3623 sbitmap_vector_zero (temp_bitmap, n_basic_blocks);
3624
3625 sbitmap_zero (dominators[0]);
3626 SET_BIT (dominators[0], 0);
3627
3628 sbitmap_zero (post_dominators[n_basic_blocks-1]);
3629 SET_BIT (post_dominators[n_basic_blocks-1], 0);
3630
3631 passes = 0;
3632 changed = 1;
3633 while (changed)
3634 {
3635 changed = 0;
3636 for (bb = 1; bb < n_basic_blocks; bb++)
3637 {
3638 sbitmap_intersect_of_predecessors (temp_bitmap[bb], dominators,
3639 bb, s_preds);
3640 SET_BIT (temp_bitmap[bb], bb);
3641 changed |= sbitmap_a_and_b (dominators[bb],
3642 dominators[bb],
3643 temp_bitmap[bb]);
3644 sbitmap_intersect_of_successors (temp_bitmap[bb], post_dominators,
3645 bb, s_succs);
3646 SET_BIT (temp_bitmap[bb], bb);
3647 changed |= sbitmap_a_and_b (post_dominators[bb],
3648 post_dominators[bb],
3649 temp_bitmap[bb]);
3650 }
3651 passes++;
3652 }
3653
3654 free (temp_bitmap);
3655 }
3656
3657 /* Count for a single SET rtx, X. */
3658
3659 static void
3660 count_reg_sets_1 (x)
3661 rtx x;
3662 {
3663 register int regno;
3664 register rtx reg = SET_DEST (x);
3665
3666 /* Find the register that's set/clobbered. */
3667 while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
3668 || GET_CODE (reg) == SIGN_EXTRACT
3669 || GET_CODE (reg) == STRICT_LOW_PART)
3670 reg = XEXP (reg, 0);
3671
3672 if (GET_CODE (reg) == PARALLEL
3673 && GET_MODE (reg) == BLKmode)
3674 {
3675 register int i;
3676 for (i = XVECLEN (reg, 0) - 1; i >= 0; i--)
3677 count_reg_sets_1 (XVECEXP (reg, 0, i));
3678 return;
3679 }
3680
3681 if (GET_CODE (reg) == REG)
3682 {
3683 regno = REGNO (reg);
3684 if (regno >= FIRST_PSEUDO_REGISTER)
3685 {
3686 /* Count (weighted) references, stores, etc. This counts a
3687 register twice if it is modified, but that is correct. */
3688 REG_N_SETS (regno)++;
3689
3690 REG_N_REFS (regno) += loop_depth;
3691 }
3692 }
3693 }
3694
3695 /* Increment REG_N_SETS for each SET or CLOBBER found in X; also increment
3696 REG_N_REFS by the current loop depth for each SET or CLOBBER found. */
3697
3698 static void
3699 count_reg_sets (x)
3700 rtx x;
3701 {
3702 register RTX_CODE code = GET_CODE (x);
3703
3704 if (code == SET || code == CLOBBER)
3705 count_reg_sets_1 (x);
3706 else if (code == PARALLEL)
3707 {
3708 register int i;
3709 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
3710 {
3711 code = GET_CODE (XVECEXP (x, 0, i));
3712 if (code == SET || code == CLOBBER)
3713 count_reg_sets_1 (XVECEXP (x, 0, i));
3714 }
3715 }
3716 }
3717
3718 /* Increment REG_N_REFS by the current loop depth each register reference
3719 found in X. */
3720
3721 static void
3722 count_reg_references (x)
3723 rtx x;
3724 {
3725 register RTX_CODE code;
3726
3727 retry:
3728 code = GET_CODE (x);
3729 switch (code)
3730 {
3731 case LABEL_REF:
3732 case SYMBOL_REF:
3733 case CONST_INT:
3734 case CONST:
3735 case CONST_DOUBLE:
3736 case PC:
3737 case ADDR_VEC:
3738 case ADDR_DIFF_VEC:
3739 case ASM_INPUT:
3740 return;
3741
3742 #ifdef HAVE_cc0
3743 case CC0:
3744 return;
3745 #endif
3746
3747 case CLOBBER:
3748 /* If we are clobbering a MEM, mark any registers inside the address
3749 as being used. */
3750 if (GET_CODE (XEXP (x, 0)) == MEM)
3751 count_reg_references (XEXP (XEXP (x, 0), 0));
3752 return;
3753
3754 case SUBREG:
3755 /* While we're here, optimize this case. */
3756 x = SUBREG_REG (x);
3757
3758 /* In case the SUBREG is not of a register, don't optimize */
3759 if (GET_CODE (x) != REG)
3760 {
3761 count_reg_references (x);
3762 return;
3763 }
3764
3765 /* ... fall through ... */
3766
3767 case REG:
3768 if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
3769 REG_N_REFS (REGNO (x)) += loop_depth;
3770 return;
3771
3772 case SET:
3773 {
3774 register rtx testreg = SET_DEST (x);
3775 int mark_dest = 0;
3776
3777 /* If storing into MEM, don't show it as being used. But do
3778 show the address as being used. */
3779 if (GET_CODE (testreg) == MEM)
3780 {
3781 count_reg_references (XEXP (testreg, 0));
3782 count_reg_references (SET_SRC (x));
3783 return;
3784 }
3785
3786 /* Storing in STRICT_LOW_PART is like storing in a reg
3787 in that this SET might be dead, so ignore it in TESTREG.
3788 but in some other ways it is like using the reg.
3789
3790 Storing in a SUBREG or a bit field is like storing the entire
3791 register in that if the register's value is not used
3792 then this SET is not needed. */
3793 while (GET_CODE (testreg) == STRICT_LOW_PART
3794 || GET_CODE (testreg) == ZERO_EXTRACT
3795 || GET_CODE (testreg) == SIGN_EXTRACT
3796 || GET_CODE (testreg) == SUBREG)
3797 {
3798 /* Modifying a single register in an alternate mode
3799 does not use any of the old value. But these other
3800 ways of storing in a register do use the old value. */
3801 if (GET_CODE (testreg) == SUBREG
3802 && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
3803 ;
3804 else
3805 mark_dest = 1;
3806
3807 testreg = XEXP (testreg, 0);
3808 }
3809
3810 /* If this is a store into a register,
3811 recursively scan the value being stored. */
3812
3813 if ((GET_CODE (testreg) == PARALLEL
3814 && GET_MODE (testreg) == BLKmode)
3815 || GET_CODE (testreg) == REG)
3816 {
3817 count_reg_references (SET_SRC (x));
3818 if (mark_dest)
3819 count_reg_references (SET_DEST (x));
3820 return;
3821 }
3822 }
3823 break;
3824
3825 default:
3826 break;
3827 }
3828
3829 /* Recursively scan the operands of this expression. */
3830
3831 {
3832 register char *fmt = GET_RTX_FORMAT (code);
3833 register int i;
3834
3835 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3836 {
3837 if (fmt[i] == 'e')
3838 {
3839 /* Tail recursive case: save a function call level. */
3840 if (i == 0)
3841 {
3842 x = XEXP (x, 0);
3843 goto retry;
3844 }
3845 count_reg_references (XEXP (x, i));
3846 }
3847 else if (fmt[i] == 'E')
3848 {
3849 register int j;
3850 for (j = 0; j < XVECLEN (x, i); j++)
3851 count_reg_references (XVECEXP (x, i, j));
3852 }
3853 }
3854 }
3855 }
3856
3857 /* Recompute register set/reference counts immediately prior to register
3858 allocation.
3859
3860 This avoids problems with set/reference counts changing to/from values
3861 which have special meanings to the register allocators.
3862
3863 Additionally, the reference counts are the primary component used by the
3864 register allocators to prioritize pseudos for allocation to hard regs.
3865 More accurate reference counts generally lead to better register allocation.
3866
3867 F is the first insn to be scanned.
3868 LOOP_STEP denotes how much loop_depth should be incremented per
3869 loop nesting level in order to increase the ref count more for references
3870 in a loop.
3871
3872 It might be worthwhile to update REG_LIVE_LENGTH, REG_BASIC_BLOCK and
3873 possibly other information which is used by the register allocators. */
3874
3875 void
3876 recompute_reg_usage (f, loop_step)
3877 rtx f;
3878 int loop_step;
3879 {
3880 rtx insn;
3881 int i, max_reg;
3882
3883 /* Clear out the old data. */
3884 max_reg = max_reg_num ();
3885 for (i = FIRST_PSEUDO_REGISTER; i < max_reg; i++)
3886 {
3887 REG_N_SETS (i) = 0;
3888 REG_N_REFS (i) = 0;
3889 }
3890
3891 /* Scan each insn in the chain and count how many times each register is
3892 set/used. */
3893 loop_depth = 1;
3894 for (insn = f; insn; insn = NEXT_INSN (insn))
3895 {
3896 /* Keep track of loop depth. */
3897 if (GET_CODE (insn) == NOTE)
3898 {
3899 /* Look for loop boundaries. */
3900 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
3901 loop_depth -= loop_step;
3902 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
3903 loop_depth += loop_step;
3904
3905 /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error.
3906 Abort now rather than setting register status incorrectly. */
3907 if (loop_depth == 0)
3908 abort ();
3909 }
3910 else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3911 {
3912 rtx links;
3913
3914 /* This call will increment REG_N_SETS for each SET or CLOBBER
3915 of a register in INSN. It will also increment REG_N_REFS
3916 by the loop depth for each set of a register in INSN. */
3917 count_reg_sets (PATTERN (insn));
3918
3919 /* count_reg_sets does not detect autoincrement address modes, so
3920 detect them here by looking at the notes attached to INSN. */
3921 for (links = REG_NOTES (insn); links; links = XEXP (links, 1))
3922 {
3923 if (REG_NOTE_KIND (links) == REG_INC)
3924 /* Count (weighted) references, stores, etc. This counts a
3925 register twice if it is modified, but that is correct. */
3926 REG_N_SETS (REGNO (XEXP (links, 0)))++;
3927 }
3928
3929 /* This call will increment REG_N_REFS by the current loop depth for
3930 each reference to a register in INSN. */
3931 count_reg_references (PATTERN (insn));
3932
3933 /* count_reg_references will not include counts for arguments to
3934 function calls, so detect them here by examining the
3935 CALL_INSN_FUNCTION_USAGE data. */
3936 if (GET_CODE (insn) == CALL_INSN)
3937 {
3938 rtx note;
3939
3940 for (note = CALL_INSN_FUNCTION_USAGE (insn);
3941 note;
3942 note = XEXP (note, 1))
3943 if (GET_CODE (XEXP (note, 0)) == USE)
3944 count_reg_references (SET_DEST (XEXP (note, 0)));
3945 }
3946 }
3947 }
3948 }