]>
Commit | Line | Data |
---|---|---|
d7429b6a | 1 | /* Data flow analysis for GNU compiler. |
6a45254e | 2 | Copyright (C) 1987, 88, 92-96, 1997 Free Software Foundation, Inc. |
d7429b6a RK |
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 | |
a35311b0 RK |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
d7429b6a RK |
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 | \f | |
d7429b6a | 111 | #include "config.h" |
e9a25f70 | 112 | #include <stdio.h> |
d7429b6a RK |
113 | #include "rtl.h" |
114 | #include "basic-block.h" | |
115 | #include "insn-config.h" | |
116 | #include "regs.h" | |
117 | #include "hard-reg-set.h" | |
118 | #include "flags.h" | |
119 | #include "output.h" | |
3d195391 | 120 | #include "except.h" |
d7429b6a RK |
121 | |
122 | #include "obstack.h" | |
123 | #define obstack_chunk_alloc xmalloc | |
124 | #define obstack_chunk_free free | |
125 | ||
7eb136d6 MM |
126 | /* The contents of the current function definition are allocated |
127 | in this obstack, and all are freed at the end of the function. | |
128 | For top-level functions, this is temporary_obstack. | |
129 | Separate obstacks are made for nested functions. */ | |
130 | ||
131 | extern struct obstack *function_obstack; | |
132 | ||
d7429b6a RK |
133 | /* List of labels that must never be deleted. */ |
134 | extern rtx forced_labels; | |
135 | ||
136 | /* Get the basic block number of an insn. | |
137 | This info should not be expected to remain available | |
138 | after the end of life_analysis. */ | |
139 | ||
140 | /* This is the limit of the allocated space in the following two arrays. */ | |
141 | ||
142 | static int max_uid_for_flow; | |
143 | ||
144 | #define BLOCK_NUM(INSN) uid_block_number[INSN_UID (INSN)] | |
145 | ||
146 | /* This is where the BLOCK_NUM values are really stored. | |
147 | This is set up by find_basic_blocks and used there and in life_analysis, | |
148 | and then freed. */ | |
149 | ||
6ac271be | 150 | static int *uid_block_number; |
d7429b6a RK |
151 | |
152 | /* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile. */ | |
153 | ||
154 | #define INSN_VOLATILE(INSN) uid_volatile[INSN_UID (INSN)] | |
155 | static char *uid_volatile; | |
156 | ||
157 | /* Number of basic blocks in the current function. */ | |
158 | ||
159 | int n_basic_blocks; | |
160 | ||
161 | /* Maximum register number used in this function, plus one. */ | |
162 | ||
163 | int max_regno; | |
164 | ||
0f41302f MS |
165 | /* Maximum number of SCRATCH rtx's used in any basic block of this |
166 | function. */ | |
d7429b6a RK |
167 | |
168 | int max_scratch; | |
169 | ||
170 | /* Number of SCRATCH rtx's in the current block. */ | |
171 | ||
172 | static int num_scratch; | |
173 | ||
b1f21e0a | 174 | /* Indexed by n, giving various register information */ |
d7429b6a | 175 | |
b1f21e0a | 176 | reg_info *reg_n_info; |
d7429b6a RK |
177 | |
178 | /* Element N is the next insn that uses (hard or pseudo) register number N | |
179 | within the current basic block; or zero, if there is no such insn. | |
180 | This is valid only during the final backward scan in propagate_block. */ | |
181 | ||
182 | static rtx *reg_next_use; | |
183 | ||
184 | /* Size of a regset for the current function, | |
185 | in (1) bytes and (2) elements. */ | |
186 | ||
187 | int regset_bytes; | |
188 | int regset_size; | |
189 | ||
190 | /* Element N is first insn in basic block N. | |
191 | This info lasts until we finish compiling the function. */ | |
192 | ||
193 | rtx *basic_block_head; | |
194 | ||
195 | /* Element N is last insn in basic block N. | |
196 | This info lasts until we finish compiling the function. */ | |
197 | ||
198 | rtx *basic_block_end; | |
199 | ||
200 | /* Element N is a regset describing the registers live | |
201 | at the start of basic block N. | |
202 | This info lasts until we finish compiling the function. */ | |
203 | ||
204 | regset *basic_block_live_at_start; | |
205 | ||
206 | /* Regset of regs live when calls to `setjmp'-like functions happen. */ | |
207 | ||
208 | regset regs_live_at_setjmp; | |
209 | ||
210 | /* List made of EXPR_LIST rtx's which gives pairs of pseudo registers | |
211 | that have to go in the same hard reg. | |
212 | The first two regs in the list are a pair, and the next two | |
213 | are another pair, etc. */ | |
214 | rtx regs_may_share; | |
215 | ||
216 | /* Element N is nonzero if control can drop into basic block N | |
217 | from the preceding basic block. Freed after life_analysis. */ | |
218 | ||
219 | static char *basic_block_drops_in; | |
220 | ||
221 | /* Element N is depth within loops of the last insn in basic block number N. | |
222 | Freed after life_analysis. */ | |
223 | ||
224 | static short *basic_block_loop_depth; | |
225 | ||
226 | /* Element N nonzero if basic block N can actually be reached. | |
227 | Vector exists only during find_basic_blocks. */ | |
228 | ||
229 | static char *block_live_static; | |
230 | ||
231 | /* Depth within loops of basic block being scanned for lifetime analysis, | |
232 | plus one. This is the weight attached to references to registers. */ | |
233 | ||
234 | static int loop_depth; | |
235 | ||
236 | /* During propagate_block, this is non-zero if the value of CC0 is live. */ | |
237 | ||
238 | static int cc0_live; | |
239 | ||
240 | /* During propagate_block, this contains the last MEM stored into. It | |
241 | is used to eliminate consecutive stores to the same location. */ | |
242 | ||
243 | static rtx last_mem_set; | |
244 | ||
245 | /* Set of registers that may be eliminable. These are handled specially | |
246 | in updating regs_ever_live. */ | |
247 | ||
248 | static HARD_REG_SET elim_reg_set; | |
249 | ||
250 | /* Forward declarations */ | |
e658434c | 251 | static void find_basic_blocks PROTO((rtx, rtx)); |
e658434c RK |
252 | static void mark_label_ref PROTO((rtx, rtx, int)); |
253 | static void life_analysis PROTO((rtx, int)); | |
254 | void allocate_for_life_analysis PROTO((void)); | |
67f0e213 RK |
255 | void init_regset_vector PROTO((regset *, int, struct obstack *)); |
256 | void free_regset_vector PROTO((regset *, int)); | |
e658434c RK |
257 | static void propagate_block PROTO((regset, rtx, rtx, int, |
258 | regset, int)); | |
8329b5ec | 259 | static rtx flow_delete_insn PROTO((rtx)); |
e658434c RK |
260 | static int insn_dead_p PROTO((rtx, regset, int)); |
261 | static int libcall_dead_p PROTO((rtx, regset, rtx, rtx)); | |
262 | static void mark_set_regs PROTO((regset, regset, rtx, | |
263 | rtx, regset)); | |
264 | static void mark_set_1 PROTO((regset, regset, rtx, | |
265 | rtx, regset)); | |
266 | static void find_auto_inc PROTO((regset, rtx, rtx)); | |
267 | static void mark_used_regs PROTO((regset, regset, rtx, int, rtx)); | |
268 | static int try_pre_increment_1 PROTO((rtx)); | |
269 | static int try_pre_increment PROTO((rtx, rtx, HOST_WIDE_INT)); | |
e658434c | 270 | void dump_flow_info PROTO((FILE *)); |
d7429b6a RK |
271 | \f |
272 | /* Find basic blocks of the current function and perform data flow analysis. | |
273 | F is the first insn of the function and NREGS the number of register numbers | |
274 | in use. */ | |
275 | ||
276 | void | |
277 | flow_analysis (f, nregs, file) | |
278 | rtx f; | |
279 | int nregs; | |
280 | FILE *file; | |
281 | { | |
282 | register rtx insn; | |
283 | register int i; | |
d7e4fe8b | 284 | rtx nonlocal_label_list = nonlocal_label_rtx_list (); |
d7429b6a RK |
285 | |
286 | #ifdef ELIMINABLE_REGS | |
287 | static struct {int from, to; } eliminables[] = ELIMINABLE_REGS; | |
288 | #endif | |
289 | ||
290 | /* Record which registers will be eliminated. We use this in | |
0f41302f | 291 | mark_used_regs. */ |
d7429b6a RK |
292 | |
293 | CLEAR_HARD_REG_SET (elim_reg_set); | |
294 | ||
295 | #ifdef ELIMINABLE_REGS | |
296 | for (i = 0; i < sizeof eliminables / sizeof eliminables[0]; i++) | |
297 | SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from); | |
298 | #else | |
299 | SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM); | |
300 | #endif | |
301 | ||
302 | /* Count the basic blocks. Also find maximum insn uid value used. */ | |
303 | ||
304 | { | |
305 | register RTX_CODE prev_code = JUMP_INSN; | |
306 | register RTX_CODE code; | |
307 | ||
308 | max_uid_for_flow = 0; | |
309 | ||
310 | for (insn = f, i = 0; insn; insn = NEXT_INSN (insn)) | |
311 | { | |
312 | code = GET_CODE (insn); | |
313 | if (INSN_UID (insn) > max_uid_for_flow) | |
314 | max_uid_for_flow = INSN_UID (insn); | |
315 | if (code == CODE_LABEL | |
d7e4fe8b RS |
316 | || (GET_RTX_CLASS (code) == 'i' |
317 | && (prev_code == JUMP_INSN | |
318 | || (prev_code == CALL_INSN | |
6b67ec08 | 319 | && nonlocal_label_list != 0) |
d7e4fe8b | 320 | || prev_code == BARRIER))) |
d7429b6a | 321 | i++; |
8cfe18d6 | 322 | |
2dd4cace | 323 | if (code == CALL_INSN && find_reg_note (insn, REG_RETVAL, NULL_RTX)) |
8cfe18d6 RK |
324 | code = INSN; |
325 | ||
6b67ec08 | 326 | if (code != NOTE) |
d7429b6a RK |
327 | prev_code = code; |
328 | } | |
329 | } | |
330 | ||
331 | #ifdef AUTO_INC_DEC | |
332 | /* Leave space for insns we make in some cases for auto-inc. These cases | |
333 | are rare, so we don't need too much space. */ | |
334 | max_uid_for_flow += max_uid_for_flow / 10; | |
335 | #endif | |
336 | ||
337 | /* Allocate some tables that last till end of compiling this function | |
338 | and some needed only in find_basic_blocks and life_analysis. */ | |
339 | ||
340 | n_basic_blocks = i; | |
341 | basic_block_head = (rtx *) oballoc (n_basic_blocks * sizeof (rtx)); | |
342 | basic_block_end = (rtx *) oballoc (n_basic_blocks * sizeof (rtx)); | |
343 | basic_block_drops_in = (char *) alloca (n_basic_blocks); | |
344 | basic_block_loop_depth = (short *) alloca (n_basic_blocks * sizeof (short)); | |
345 | uid_block_number | |
6ac271be | 346 | = (int *) alloca ((max_uid_for_flow + 1) * sizeof (int)); |
d7429b6a RK |
347 | uid_volatile = (char *) alloca (max_uid_for_flow + 1); |
348 | bzero (uid_volatile, max_uid_for_flow + 1); | |
349 | ||
d7e4fe8b | 350 | find_basic_blocks (f, nonlocal_label_list); |
d7429b6a RK |
351 | life_analysis (f, nregs); |
352 | if (file) | |
353 | dump_flow_info (file); | |
354 | ||
355 | basic_block_drops_in = 0; | |
356 | uid_block_number = 0; | |
357 | basic_block_loop_depth = 0; | |
358 | } | |
359 | \f | |
360 | /* Find all basic blocks of the function whose first insn is F. | |
361 | Store the correct data in the tables that describe the basic blocks, | |
362 | set up the chains of references for each CODE_LABEL, and | |
d7e4fe8b RS |
363 | delete any entire basic blocks that cannot be reached. |
364 | ||
365 | NONLOCAL_LABEL_LIST is the same local variable from flow_analysis. */ | |
d7429b6a RK |
366 | |
367 | static void | |
d7e4fe8b RS |
368 | find_basic_blocks (f, nonlocal_label_list) |
369 | rtx f, nonlocal_label_list; | |
d7429b6a RK |
370 | { |
371 | register rtx insn; | |
372 | register int i; | |
373 | register char *block_live = (char *) alloca (n_basic_blocks); | |
374 | register char *block_marked = (char *) alloca (n_basic_blocks); | |
2ec1535d JL |
375 | /* An array of CODE_LABELs, indexed by UID for the start of the active |
376 | EH handler for each insn in F. */ | |
377 | rtx *active_eh_handler; | |
d7429b6a RK |
378 | /* List of label_refs to all labels whose addresses are taken |
379 | and used as data. */ | |
8329b5ec | 380 | rtx label_value_list; |
2ec1535d | 381 | rtx x, note, eh_note; |
e658434c | 382 | enum rtx_code prev_code, code; |
8329b5ec | 383 | int depth, pass; |
d7429b6a | 384 | |
8329b5ec | 385 | pass = 1; |
2ec1535d | 386 | active_eh_handler = (rtx *) alloca ((max_uid_for_flow + 1) * sizeof (rtx)); |
8329b5ec DE |
387 | restart: |
388 | ||
389 | label_value_list = 0; | |
d7429b6a RK |
390 | block_live_static = block_live; |
391 | bzero (block_live, n_basic_blocks); | |
392 | bzero (block_marked, n_basic_blocks); | |
2ec1535d | 393 | bzero (active_eh_handler, (max_uid_for_flow + 1) * sizeof (rtx)); |
d7429b6a RK |
394 | |
395 | /* Initialize with just block 0 reachable and no blocks marked. */ | |
396 | if (n_basic_blocks > 0) | |
397 | block_live[0] = 1; | |
398 | ||
e658434c RK |
399 | /* Initialize the ref chain of each label to 0. Record where all the |
400 | blocks start and end and their depth in loops. For each insn, record | |
401 | the block it is in. Also mark as reachable any blocks headed by labels | |
402 | that must not be deleted. */ | |
d7429b6a | 403 | |
2ec1535d | 404 | for (eh_note = NULL_RTX, insn = f, i = -1, prev_code = JUMP_INSN, depth = 1; |
e658434c RK |
405 | insn; insn = NEXT_INSN (insn)) |
406 | { | |
407 | code = GET_CODE (insn); | |
408 | if (code == NOTE) | |
409 | { | |
410 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG) | |
411 | depth++; | |
412 | else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END) | |
413 | depth--; | |
414 | } | |
d7429b6a | 415 | |
e658434c RK |
416 | /* A basic block starts at label, or after something that can jump. */ |
417 | else if (code == CODE_LABEL | |
418 | || (GET_RTX_CLASS (code) == 'i' | |
419 | && (prev_code == JUMP_INSN | |
420 | || (prev_code == CALL_INSN | |
8cfe18d6 RK |
421 | && nonlocal_label_list != 0 |
422 | && ! find_reg_note (insn, REG_RETVAL, NULL_RTX)) | |
e658434c RK |
423 | || prev_code == BARRIER))) |
424 | { | |
425 | basic_block_head[++i] = insn; | |
426 | basic_block_end[i] = insn; | |
427 | basic_block_loop_depth[i] = depth; | |
428 | ||
429 | if (code == CODE_LABEL) | |
430 | { | |
d7429b6a RK |
431 | LABEL_REFS (insn) = insn; |
432 | /* Any label that cannot be deleted | |
433 | is considered to start a reachable block. */ | |
434 | if (LABEL_PRESERVE_P (insn)) | |
435 | block_live[i] = 1; | |
436 | } | |
e658434c | 437 | } |
d7429b6a | 438 | |
e658434c RK |
439 | else if (GET_RTX_CLASS (code) == 'i') |
440 | { | |
441 | basic_block_end[i] = insn; | |
442 | basic_block_loop_depth[i] = depth; | |
42fa3cfb | 443 | } |
e658434c | 444 | |
42fa3cfb JW |
445 | if (GET_RTX_CLASS (code) == 'i') |
446 | { | |
e658434c RK |
447 | /* Make a list of all labels referred to other than by jumps. */ |
448 | for (note = REG_NOTES (insn); note; note = XEXP (note, 1)) | |
449 | if (REG_NOTE_KIND (note) == REG_LABEL) | |
d7429b6a RK |
450 | label_value_list = gen_rtx (EXPR_LIST, VOIDmode, XEXP (note, 0), |
451 | label_value_list); | |
42fa3cfb | 452 | } |
d7429b6a | 453 | |
2ec1535d JL |
454 | /* Keep a lifo list of the currently active exception handlers. */ |
455 | if (GET_CODE (insn) == NOTE) | |
456 | { | |
457 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG) | |
458 | { | |
459 | for (x = exception_handler_labels; x; x = XEXP (x, 1)) | |
460 | if (CODE_LABEL_NUMBER (XEXP (x, 0)) == NOTE_BLOCK_NUMBER (insn)) | |
461 | { | |
462 | eh_note = gen_rtx (EXPR_LIST, VOIDmode, | |
463 | XEXP (x, 0), eh_note); | |
464 | break; | |
465 | } | |
466 | if (x == NULL_RTX) | |
467 | abort (); | |
468 | } | |
469 | else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END) | |
470 | eh_note = XEXP (eh_note, 1); | |
471 | } | |
472 | /* If we encounter a CALL_INSN, note which exception handler it | |
473 | might pass control to. | |
474 | ||
475 | If doing asynchronous exceptions, record the active EH handler | |
476 | for every insn, since most insns can throw. */ | |
477 | else if (eh_note | |
478 | && (asynchronous_exceptions | |
479 | || (GET_CODE (insn) == CALL_INSN | |
480 | && ! find_reg_note (insn, REG_RETVAL, NULL_RTX)))) | |
481 | active_eh_handler[INSN_UID (insn)] = XEXP (eh_note, 0); | |
482 | ||
e658434c | 483 | BLOCK_NUM (insn) = i; |
d7e4fe8b | 484 | |
6b67ec08 | 485 | if (code != NOTE) |
e658434c RK |
486 | prev_code = code; |
487 | } | |
488 | ||
2aec79e2 DE |
489 | /* During the second pass, `n_basic_blocks' is only an upper bound. |
490 | Only perform the sanity check for the first pass, and on the second | |
491 | pass ensure `n_basic_blocks' is set to the correct value. */ | |
492 | if (pass == 1 && i + 1 != n_basic_blocks) | |
e658434c | 493 | abort (); |
2aec79e2 | 494 | n_basic_blocks = i + 1; |
d7429b6a RK |
495 | |
496 | /* Record which basic blocks control can drop in to. */ | |
497 | ||
e658434c RK |
498 | for (i = 0; i < n_basic_blocks; i++) |
499 | { | |
500 | for (insn = PREV_INSN (basic_block_head[i]); | |
501 | insn && GET_CODE (insn) == NOTE; insn = PREV_INSN (insn)) | |
502 | ; | |
503 | ||
504 | basic_block_drops_in[i] = insn && GET_CODE (insn) != BARRIER; | |
505 | } | |
d7429b6a RK |
506 | |
507 | /* Now find which basic blocks can actually be reached | |
508 | and put all jump insns' LABEL_REFS onto the ref-chains | |
509 | of their target labels. */ | |
510 | ||
511 | if (n_basic_blocks > 0) | |
512 | { | |
513 | int something_marked = 1; | |
8329b5ec | 514 | int deleted; |
d7429b6a | 515 | |
d7429b6a RK |
516 | /* Pass over all blocks, marking each block that is reachable |
517 | and has not yet been marked. | |
518 | Keep doing this until, in one pass, no blocks have been marked. | |
519 | Then blocks_live and blocks_marked are identical and correct. | |
520 | In addition, all jumps actually reachable have been marked. */ | |
521 | ||
522 | while (something_marked) | |
523 | { | |
524 | something_marked = 0; | |
525 | for (i = 0; i < n_basic_blocks; i++) | |
526 | if (block_live[i] && !block_marked[i]) | |
527 | { | |
528 | block_marked[i] = 1; | |
529 | something_marked = 1; | |
530 | if (i + 1 < n_basic_blocks && basic_block_drops_in[i + 1]) | |
531 | block_live[i + 1] = 1; | |
532 | insn = basic_block_end[i]; | |
533 | if (GET_CODE (insn) == JUMP_INSN) | |
534 | mark_label_ref (PATTERN (insn), insn, 0); | |
812059fe | 535 | |
2ec1535d JL |
536 | /* If we have any forced labels, mark them as potentially |
537 | reachable from this block. */ | |
538 | for (x = forced_labels; x; x = XEXP (x, 1)) | |
539 | if (! LABEL_REF_NONLOCAL_P (x)) | |
540 | mark_label_ref (gen_rtx (LABEL_REF, VOIDmode, XEXP (x, 0)), | |
541 | insn, 0); | |
542 | ||
543 | /* Now scan the insns for this block, we may need to make | |
544 | edges for some of them to various non-obvious locations | |
545 | (exception handlers, nonlocal labels, etc). */ | |
546 | for (insn = basic_block_head[i]; | |
547 | insn != NEXT_INSN (basic_block_end[i]); | |
548 | insn = NEXT_INSN (insn)) | |
549 | { | |
550 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') | |
551 | { | |
552 | ||
8930b063 JL |
553 | /* References to labels in non-jumping insns have |
554 | REG_LABEL notes attached to them. | |
555 | ||
556 | This can happen for computed gotos; we don't care | |
557 | about them here since the values are also on the | |
558 | label_value_list and will be marked live if we find | |
559 | a live computed goto. | |
560 | ||
561 | This can also happen when we take the address of | |
562 | a label to pass as an argument to __throw. Note | |
563 | throw only uses the value to determine what handler | |
564 | should be called -- ie the label is not used as | |
565 | a jump target, it just marks regions in the code. | |
566 | ||
567 | In theory we should be able to ignore the REG_LABEL | |
568 | notes, but we have to make sure that the label and | |
569 | associated insns aren't marked dead, so we make | |
570 | the block in question live and create an edge from | |
571 | this insn to the label. This is not strictly | |
e701eb4d | 572 | correct, but it is close enough for now. */ |
2ec1535d JL |
573 | for (note = REG_NOTES (insn); |
574 | note; | |
575 | note = XEXP (note, 1)) | |
576 | { | |
812059fe MS |
577 | if (REG_NOTE_KIND (note) == REG_LABEL) |
578 | { | |
579 | x = XEXP (note, 0); | |
580 | block_live[BLOCK_NUM (x)] = 1; | |
8930b063 JL |
581 | mark_label_ref (gen_rtx (LABEL_REF, |
582 | VOIDmode, x), | |
583 | insn, 0); | |
2ec1535d JL |
584 | } |
585 | } | |
586 | ||
587 | /* If this is a computed jump, then mark it as | |
588 | reaching everything on the label_value_list | |
589 | and forced_labels list. */ | |
590 | if (computed_jump_p (insn)) | |
591 | { | |
592 | for (x = label_value_list; x; x = XEXP (x, 1)) | |
593 | mark_label_ref (gen_rtx (LABEL_REF, VOIDmode, | |
594 | XEXP (x, 0)), | |
595 | insn, 0); | |
596 | ||
597 | for (x = forced_labels; x; x = XEXP (x, 1)) | |
598 | mark_label_ref (gen_rtx (LABEL_REF, VOIDmode, | |
599 | XEXP (x, 0)), | |
600 | insn, 0); | |
601 | } | |
602 | ||
603 | /* If this is a CALL_INSN, then mark it as reaching | |
604 | the active EH handler for this CALL_INSN. If | |
605 | we're handling asynchronous exceptions mark every | |
606 | insn as reaching the active EH handler. | |
607 | ||
608 | Also mark the CALL_INSN as reaching any nonlocal | |
609 | goto sites. */ | |
610 | else if (asynchronous_exceptions | |
611 | || (GET_CODE (insn) == CALL_INSN | |
612 | && ! find_reg_note (insn, REG_RETVAL, | |
613 | NULL_RTX))) | |
614 | { | |
615 | if (active_eh_handler[INSN_UID (insn)]) | |
616 | mark_label_ref (gen_rtx (LABEL_REF, VOIDmode, | |
617 | active_eh_handler[INSN_UID (insn)]), | |
618 | insn, 0); | |
619 | ||
620 | if (!asynchronous_exceptions) | |
621 | { | |
622 | for (x = nonlocal_label_list; | |
623 | x; | |
624 | x = XEXP (x, 1)) | |
625 | mark_label_ref (gen_rtx (LABEL_REF, VOIDmode, | |
626 | XEXP (x, 0)), | |
627 | insn, 0); | |
812059fe | 628 | } |
2ec1535d JL |
629 | /* ??? This could be made smarter: |
630 | in some cases it's possible to tell that | |
631 | certain calls will not do a nonlocal goto. | |
632 | ||
633 | For example, if the nested functions that | |
634 | do the nonlocal gotos do not have their | |
635 | addresses taken, then only calls to those | |
636 | functions or to other nested functions that | |
637 | use them could possibly do nonlocal gotos. */ | |
638 | } | |
639 | } | |
640 | } | |
d7429b6a RK |
641 | } |
642 | } | |
643 | ||
2ec1535d JL |
644 | /* This should never happen. If it does that means we've computed an |
645 | incorrect flow graph, which can lead to aborts/crashes later in the | |
646 | compiler or incorrect code generation. | |
af14ce9c | 647 | |
2ec1535d JL |
648 | We used to try and continue here, but that's just asking for trouble |
649 | later during the compile or at runtime. It's easier to debug the | |
650 | problem here than later! */ | |
af14ce9c RK |
651 | for (i = 1; i < n_basic_blocks; i++) |
652 | if (block_live[i] && ! basic_block_drops_in[i] | |
653 | && GET_CODE (basic_block_head[i]) == CODE_LABEL | |
654 | && LABEL_REFS (basic_block_head[i]) == basic_block_head[i]) | |
2ec1535d | 655 | abort (); |
af14ce9c | 656 | |
d7429b6a RK |
657 | /* Now delete the code for any basic blocks that can't be reached. |
658 | They can occur because jump_optimize does not recognize | |
659 | unreachable loops as unreachable. */ | |
660 | ||
8329b5ec | 661 | deleted = 0; |
d7429b6a RK |
662 | for (i = 0; i < n_basic_blocks; i++) |
663 | if (!block_live[i]) | |
664 | { | |
8329b5ec DE |
665 | deleted++; |
666 | ||
667 | /* Delete the insns in a (non-live) block. We physically delete | |
668 | every non-note insn except the start and end (so | |
669 | basic_block_head/end needn't be updated), we turn the latter | |
670 | into NOTE_INSN_DELETED notes. | |
671 | We use to "delete" the insns by turning them into notes, but | |
672 | we may be deleting lots of insns that subsequent passes would | |
673 | otherwise have to process. Secondly, lots of deleted blocks in | |
674 | a row can really slow down propagate_block since it will | |
675 | otherwise process insn-turned-notes multiple times when it | |
676 | looks for loop begin/end notes. */ | |
677 | if (basic_block_head[i] != basic_block_end[i]) | |
678 | { | |
49b6c81e DE |
679 | /* It would be quicker to delete all of these with a single |
680 | unchaining, rather than one at a time, but we need to keep | |
681 | the NOTE's. */ | |
8329b5ec DE |
682 | insn = NEXT_INSN (basic_block_head[i]); |
683 | while (insn != basic_block_end[i]) | |
684 | { | |
685 | if (GET_CODE (insn) == BARRIER) | |
686 | abort (); | |
687 | else if (GET_CODE (insn) != NOTE) | |
688 | insn = flow_delete_insn (insn); | |
689 | else | |
690 | insn = NEXT_INSN (insn); | |
691 | } | |
692 | } | |
d7429b6a | 693 | insn = basic_block_head[i]; |
8329b5ec | 694 | if (GET_CODE (insn) != NOTE) |
d7429b6a | 695 | { |
8329b5ec | 696 | /* Turn the head into a deleted insn note. */ |
d7429b6a RK |
697 | if (GET_CODE (insn) == BARRIER) |
698 | abort (); | |
f8671389 JL |
699 | |
700 | /* If the head of this block is a CODE_LABEL, then it might | |
701 | be the label for an exception handler which can't be | |
702 | reached. | |
703 | ||
704 | We need to remove the label from the exception_handler_label | |
705 | list and remove the associated NOTE_EH_REGION_BEG and | |
706 | NOTE_EH_REGION_END notes. */ | |
707 | if (GET_CODE (insn) == CODE_LABEL) | |
708 | { | |
709 | rtx x, *prev = &exception_handler_labels; | |
710 | ||
711 | for (x = exception_handler_labels; x; x = XEXP (x, 1)) | |
712 | { | |
713 | if (XEXP (x, 0) == insn) | |
714 | { | |
715 | /* Found a match, splice this label out of the | |
716 | EH label list. */ | |
717 | *prev = XEXP (x, 1); | |
718 | XEXP (x, 1) = NULL_RTX; | |
719 | XEXP (x, 0) = NULL_RTX; | |
720 | ||
721 | /* Now we have to find the EH_BEG and EH_END notes | |
722 | associated with this label and remove them. */ | |
723 | ||
724 | for (x = get_insns (); x; x = NEXT_INSN (x)) | |
725 | { | |
726 | if (GET_CODE (x) == NOTE | |
727 | && ((NOTE_LINE_NUMBER (x) | |
728 | == NOTE_INSN_EH_REGION_BEG) | |
729 | || (NOTE_LINE_NUMBER (x) | |
730 | == NOTE_INSN_EH_REGION_END)) | |
731 | && (NOTE_BLOCK_NUMBER (x) | |
732 | == CODE_LABEL_NUMBER (insn))) | |
733 | { | |
734 | NOTE_LINE_NUMBER (x) = NOTE_INSN_DELETED; | |
735 | NOTE_SOURCE_FILE (x) = 0; | |
736 | } | |
737 | } | |
738 | break; | |
739 | } | |
740 | prev = &XEXP (x, 1); | |
741 | } | |
742 | } | |
743 | ||
8329b5ec DE |
744 | PUT_CODE (insn, NOTE); |
745 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
746 | NOTE_SOURCE_FILE (insn) = 0; | |
747 | } | |
748 | insn = basic_block_end[i]; | |
749 | if (GET_CODE (insn) != NOTE) | |
750 | { | |
751 | /* Turn the tail into a deleted insn note. */ | |
752 | if (GET_CODE (insn) == BARRIER) | |
753 | abort (); | |
754 | PUT_CODE (insn, NOTE); | |
755 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
756 | NOTE_SOURCE_FILE (insn) = 0; | |
d7429b6a | 757 | } |
8329b5ec DE |
758 | /* BARRIERs are between basic blocks, not part of one. |
759 | Delete a BARRIER if the preceding jump is deleted. | |
760 | We cannot alter a BARRIER into a NOTE | |
761 | because it is too short; but we can really delete | |
762 | it because it is not part of a basic block. */ | |
763 | if (NEXT_INSN (insn) != 0 | |
764 | && GET_CODE (NEXT_INSN (insn)) == BARRIER) | |
765 | delete_insn (NEXT_INSN (insn)); | |
766 | ||
d7429b6a RK |
767 | /* Each time we delete some basic blocks, |
768 | see if there is a jump around them that is | |
769 | being turned into a no-op. If so, delete it. */ | |
770 | ||
771 | if (block_live[i - 1]) | |
772 | { | |
773 | register int j; | |
8329b5ec | 774 | for (j = i + 1; j < n_basic_blocks; j++) |
d7429b6a RK |
775 | if (block_live[j]) |
776 | { | |
777 | rtx label; | |
778 | insn = basic_block_end[i - 1]; | |
779 | if (GET_CODE (insn) == JUMP_INSN | |
780 | /* An unconditional jump is the only possibility | |
781 | we must check for, since a conditional one | |
782 | would make these blocks live. */ | |
783 | && simplejump_p (insn) | |
784 | && (label = XEXP (SET_SRC (PATTERN (insn)), 0), 1) | |
785 | && INSN_UID (label) != 0 | |
786 | && BLOCK_NUM (label) == j) | |
787 | { | |
788 | PUT_CODE (insn, NOTE); | |
789 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
790 | NOTE_SOURCE_FILE (insn) = 0; | |
791 | if (GET_CODE (NEXT_INSN (insn)) != BARRIER) | |
792 | abort (); | |
793 | delete_insn (NEXT_INSN (insn)); | |
794 | } | |
795 | break; | |
796 | } | |
797 | } | |
798 | } | |
8329b5ec | 799 | |
9faa82d8 | 800 | /* There are pathological cases where one function calling hundreds of |
8329b5ec DE |
801 | nested inline functions can generate lots and lots of unreachable |
802 | blocks that jump can't delete. Since we don't use sparse matrices | |
803 | a lot of memory will be needed to compile such functions. | |
804 | Implementing sparse matrices is a fair bit of work and it is not | |
805 | clear that they win more than they lose (we don't want to | |
806 | unnecessarily slow down compilation of normal code). By making | |
9faa82d8 | 807 | another pass for the pathological case, we can greatly speed up |
8329b5ec DE |
808 | their compilation without hurting normal code. This works because |
809 | all the insns in the unreachable blocks have either been deleted or | |
49b6c81e DE |
810 | turned into notes. |
811 | Note that we're talking about reducing memory usage by 10's of | |
812 | megabytes and reducing compilation time by several minutes. */ | |
8329b5ec DE |
813 | /* ??? The choice of when to make another pass is a bit arbitrary, |
814 | and was derived from empirical data. */ | |
815 | if (pass == 1 | |
49b6c81e | 816 | && deleted > 200) |
8329b5ec DE |
817 | { |
818 | pass++; | |
819 | n_basic_blocks -= deleted; | |
2aec79e2 DE |
820 | /* `n_basic_blocks' may not be correct at this point: two previously |
821 | separate blocks may now be merged. That's ok though as we | |
822 | recalculate it during the second pass. It certainly can't be | |
823 | any larger than the current value. */ | |
8329b5ec DE |
824 | goto restart; |
825 | } | |
d7429b6a RK |
826 | } |
827 | } | |
828 | \f | |
8329b5ec DE |
829 | /* Subroutines of find_basic_blocks. */ |
830 | ||
d7429b6a RK |
831 | /* Check expression X for label references; |
832 | if one is found, add INSN to the label's chain of references. | |
833 | ||
834 | CHECKDUP means check for and avoid creating duplicate references | |
835 | from the same insn. Such duplicates do no serious harm but | |
836 | can slow life analysis. CHECKDUP is set only when duplicates | |
837 | are likely. */ | |
838 | ||
839 | static void | |
840 | mark_label_ref (x, insn, checkdup) | |
841 | rtx x, insn; | |
842 | int checkdup; | |
843 | { | |
844 | register RTX_CODE code; | |
845 | register int i; | |
846 | register char *fmt; | |
847 | ||
848 | /* We can be called with NULL when scanning label_value_list. */ | |
849 | if (x == 0) | |
850 | return; | |
851 | ||
852 | code = GET_CODE (x); | |
853 | if (code == LABEL_REF) | |
854 | { | |
855 | register rtx label = XEXP (x, 0); | |
856 | register rtx y; | |
857 | if (GET_CODE (label) != CODE_LABEL) | |
858 | abort (); | |
859 | /* If the label was never emitted, this insn is junk, | |
860 | but avoid a crash trying to refer to BLOCK_NUM (label). | |
861 | This can happen as a result of a syntax error | |
862 | and a diagnostic has already been printed. */ | |
863 | if (INSN_UID (label) == 0) | |
864 | return; | |
865 | CONTAINING_INSN (x) = insn; | |
866 | /* if CHECKDUP is set, check for duplicate ref from same insn | |
867 | and don't insert. */ | |
868 | if (checkdup) | |
869 | for (y = LABEL_REFS (label); y != label; y = LABEL_NEXTREF (y)) | |
870 | if (CONTAINING_INSN (y) == insn) | |
871 | return; | |
872 | LABEL_NEXTREF (x) = LABEL_REFS (label); | |
873 | LABEL_REFS (label) = x; | |
874 | block_live_static[BLOCK_NUM (label)] = 1; | |
875 | return; | |
876 | } | |
877 | ||
878 | fmt = GET_RTX_FORMAT (code); | |
879 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
880 | { | |
881 | if (fmt[i] == 'e') | |
882 | mark_label_ref (XEXP (x, i), insn, 0); | |
883 | if (fmt[i] == 'E') | |
884 | { | |
885 | register int j; | |
886 | for (j = 0; j < XVECLEN (x, i); j++) | |
887 | mark_label_ref (XVECEXP (x, i, j), insn, 1); | |
888 | } | |
889 | } | |
890 | } | |
8329b5ec DE |
891 | |
892 | /* Delete INSN by patching it out. | |
893 | Return the next insn. */ | |
894 | ||
895 | static rtx | |
896 | flow_delete_insn (insn) | |
897 | rtx insn; | |
898 | { | |
899 | /* ??? For the moment we assume we don't have to watch for NULLs here | |
900 | since the start/end of basic blocks aren't deleted like this. */ | |
901 | NEXT_INSN (PREV_INSN (insn)) = NEXT_INSN (insn); | |
902 | PREV_INSN (NEXT_INSN (insn)) = PREV_INSN (insn); | |
903 | return NEXT_INSN (insn); | |
904 | } | |
d7429b6a RK |
905 | \f |
906 | /* Determine which registers are live at the start of each | |
907 | basic block of the function whose first insn is F. | |
908 | NREGS is the number of registers used in F. | |
909 | We allocate the vector basic_block_live_at_start | |
910 | and the regsets that it points to, and fill them with the data. | |
911 | regset_size and regset_bytes are also set here. */ | |
912 | ||
913 | static void | |
914 | life_analysis (f, nregs) | |
915 | rtx f; | |
916 | int nregs; | |
917 | { | |
d7429b6a RK |
918 | int first_pass; |
919 | int changed; | |
920 | /* For each basic block, a bitmask of regs | |
921 | live on exit from the block. */ | |
922 | regset *basic_block_live_at_end; | |
923 | /* For each basic block, a bitmask of regs | |
924 | live on entry to a successor-block of this block. | |
925 | If this does not match basic_block_live_at_end, | |
926 | that must be updated, and the block must be rescanned. */ | |
927 | regset *basic_block_new_live_at_end; | |
928 | /* For each basic block, a bitmask of regs | |
929 | whose liveness at the end of the basic block | |
930 | can make a difference in which regs are live on entry to the block. | |
931 | These are the regs that are set within the basic block, | |
932 | possibly excluding those that are used after they are set. */ | |
933 | regset *basic_block_significant; | |
934 | register int i; | |
935 | rtx insn; | |
936 | ||
937 | struct obstack flow_obstack; | |
938 | ||
939 | gcc_obstack_init (&flow_obstack); | |
940 | ||
941 | max_regno = nregs; | |
942 | ||
943 | bzero (regs_ever_live, sizeof regs_ever_live); | |
944 | ||
945 | /* Allocate and zero out many data structures | |
946 | that will record the data from lifetime analysis. */ | |
947 | ||
948 | allocate_for_life_analysis (); | |
949 | ||
950 | reg_next_use = (rtx *) alloca (nregs * sizeof (rtx)); | |
4c9a05bc | 951 | bzero ((char *) reg_next_use, nregs * sizeof (rtx)); |
d7429b6a RK |
952 | |
953 | /* Set up several regset-vectors used internally within this function. | |
954 | Their meanings are documented above, with their declarations. */ | |
955 | ||
4c9a05bc RK |
956 | basic_block_live_at_end |
957 | = (regset *) alloca (n_basic_blocks * sizeof (regset)); | |
958 | ||
d7429b6a RK |
959 | /* Don't use alloca since that leads to a crash rather than an error message |
960 | if there isn't enough space. | |
961 | Don't use oballoc since we may need to allocate other things during | |
962 | this function on the temporary obstack. */ | |
67f0e213 | 963 | init_regset_vector (basic_block_live_at_end, n_basic_blocks, &flow_obstack); |
d7429b6a | 964 | |
4c9a05bc RK |
965 | basic_block_new_live_at_end |
966 | = (regset *) alloca (n_basic_blocks * sizeof (regset)); | |
67f0e213 | 967 | init_regset_vector (basic_block_new_live_at_end, n_basic_blocks, |
7eb136d6 | 968 | &flow_obstack); |
d7429b6a | 969 | |
4c9a05bc RK |
970 | basic_block_significant |
971 | = (regset *) alloca (n_basic_blocks * sizeof (regset)); | |
67f0e213 | 972 | init_regset_vector (basic_block_significant, n_basic_blocks, &flow_obstack); |
d7429b6a RK |
973 | |
974 | /* Record which insns refer to any volatile memory | |
975 | or for any reason can't be deleted just because they are dead stores. | |
0f41302f | 976 | Also, delete any insns that copy a register to itself. */ |
d7429b6a RK |
977 | |
978 | for (insn = f; insn; insn = NEXT_INSN (insn)) | |
979 | { | |
980 | enum rtx_code code1 = GET_CODE (insn); | |
981 | if (code1 == CALL_INSN) | |
982 | INSN_VOLATILE (insn) = 1; | |
983 | else if (code1 == INSN || code1 == JUMP_INSN) | |
984 | { | |
985 | /* Delete (in effect) any obvious no-op moves. */ | |
986 | if (GET_CODE (PATTERN (insn)) == SET | |
987 | && GET_CODE (SET_DEST (PATTERN (insn))) == REG | |
988 | && GET_CODE (SET_SRC (PATTERN (insn))) == REG | |
db3cf6fb MS |
989 | && (REGNO (SET_DEST (PATTERN (insn))) |
990 | == REGNO (SET_SRC (PATTERN (insn)))) | |
d7429b6a | 991 | /* Insns carrying these notes are useful later on. */ |
5f4f0e22 | 992 | && ! find_reg_note (insn, REG_EQUAL, NULL_RTX)) |
d7429b6a RK |
993 | { |
994 | PUT_CODE (insn, NOTE); | |
995 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
996 | NOTE_SOURCE_FILE (insn) = 0; | |
997 | } | |
ac684a20 JL |
998 | /* Delete (in effect) any obvious no-op moves. */ |
999 | else if (GET_CODE (PATTERN (insn)) == SET | |
1000 | && GET_CODE (SET_DEST (PATTERN (insn))) == SUBREG | |
1001 | && GET_CODE (SUBREG_REG (SET_DEST (PATTERN (insn)))) == REG | |
1002 | && GET_CODE (SET_SRC (PATTERN (insn))) == SUBREG | |
1003 | && GET_CODE (SUBREG_REG (SET_SRC (PATTERN (insn)))) == REG | |
db3cf6fb MS |
1004 | && (REGNO (SUBREG_REG (SET_DEST (PATTERN (insn)))) |
1005 | == REGNO (SUBREG_REG (SET_SRC (PATTERN (insn))))) | |
ac684a20 JL |
1006 | && SUBREG_WORD (SET_DEST (PATTERN (insn))) == |
1007 | SUBREG_WORD (SET_SRC (PATTERN (insn))) | |
1008 | /* Insns carrying these notes are useful later on. */ | |
1009 | && ! find_reg_note (insn, REG_EQUAL, NULL_RTX)) | |
1010 | { | |
1011 | PUT_CODE (insn, NOTE); | |
1012 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
1013 | NOTE_SOURCE_FILE (insn) = 0; | |
1014 | } | |
d7429b6a RK |
1015 | else if (GET_CODE (PATTERN (insn)) == PARALLEL) |
1016 | { | |
1017 | /* If nothing but SETs of registers to themselves, | |
1018 | this insn can also be deleted. */ | |
1019 | for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++) | |
1020 | { | |
1021 | rtx tem = XVECEXP (PATTERN (insn), 0, i); | |
1022 | ||
1023 | if (GET_CODE (tem) == USE | |
1024 | || GET_CODE (tem) == CLOBBER) | |
1025 | continue; | |
1026 | ||
1027 | if (GET_CODE (tem) != SET | |
1028 | || GET_CODE (SET_DEST (tem)) != REG | |
1029 | || GET_CODE (SET_SRC (tem)) != REG | |
1030 | || REGNO (SET_DEST (tem)) != REGNO (SET_SRC (tem))) | |
1031 | break; | |
1032 | } | |
1033 | ||
1034 | if (i == XVECLEN (PATTERN (insn), 0) | |
1035 | /* Insns carrying these notes are useful later on. */ | |
5f4f0e22 | 1036 | && ! find_reg_note (insn, REG_EQUAL, NULL_RTX)) |
d7429b6a RK |
1037 | { |
1038 | PUT_CODE (insn, NOTE); | |
1039 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
1040 | NOTE_SOURCE_FILE (insn) = 0; | |
1041 | } | |
1042 | else | |
1043 | INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn)); | |
1044 | } | |
1045 | else if (GET_CODE (PATTERN (insn)) != USE) | |
1046 | INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn)); | |
1047 | /* A SET that makes space on the stack cannot be dead. | |
1048 | (Such SETs occur only for allocating variable-size data, | |
1049 | so they will always have a PLUS or MINUS according to the | |
1050 | direction of stack growth.) | |
1051 | Even if this function never uses this stack pointer value, | |
1052 | signal handlers do! */ | |
1053 | else if (code1 == INSN && GET_CODE (PATTERN (insn)) == SET | |
1054 | && SET_DEST (PATTERN (insn)) == stack_pointer_rtx | |
1055 | #ifdef STACK_GROWS_DOWNWARD | |
1056 | && GET_CODE (SET_SRC (PATTERN (insn))) == MINUS | |
1057 | #else | |
1058 | && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS | |
1059 | #endif | |
1060 | && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx) | |
1061 | INSN_VOLATILE (insn) = 1; | |
1062 | } | |
1063 | } | |
1064 | ||
1065 | if (n_basic_blocks > 0) | |
1066 | #ifdef EXIT_IGNORE_STACK | |
1067 | if (! EXIT_IGNORE_STACK | |
1068 | || (! FRAME_POINTER_REQUIRED && flag_omit_frame_pointer)) | |
1069 | #endif | |
1070 | { | |
1071 | /* If exiting needs the right stack value, | |
1072 | consider the stack pointer live at the end of the function. */ | |
916b1701 MM |
1073 | SET_REGNO_REG_SET (basic_block_live_at_end[n_basic_blocks - 1], |
1074 | STACK_POINTER_REGNUM); | |
1075 | SET_REGNO_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1], | |
1076 | STACK_POINTER_REGNUM); | |
d7429b6a RK |
1077 | } |
1078 | ||
fe0f9c4b RK |
1079 | /* Mark the frame pointer is needed at the end of the function. If |
1080 | we end up eliminating it, it will be removed from the live list | |
1081 | of each basic block by reload. */ | |
1082 | ||
1083 | if (n_basic_blocks > 0) | |
1084 | { | |
916b1701 MM |
1085 | SET_REGNO_REG_SET (basic_block_live_at_end[n_basic_blocks - 1], |
1086 | FRAME_POINTER_REGNUM); | |
1087 | SET_REGNO_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1], | |
1088 | FRAME_POINTER_REGNUM); | |
73a187c1 DE |
1089 | #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM |
1090 | /* If they are different, also mark the hard frame pointer as live */ | |
916b1701 MM |
1091 | SET_REGNO_REG_SET (basic_block_live_at_end[n_basic_blocks - 1], |
1092 | HARD_FRAME_POINTER_REGNUM); | |
1093 | SET_REGNO_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1], | |
1094 | HARD_FRAME_POINTER_REGNUM); | |
73a187c1 | 1095 | #endif |
fe0f9c4b RK |
1096 | } |
1097 | ||
632c9d9e MS |
1098 | /* Mark all global registers and all registers used by the epilogue |
1099 | as being live at the end of the function since they may be | |
1100 | referenced by our caller. */ | |
d7429b6a RK |
1101 | |
1102 | if (n_basic_blocks > 0) | |
1103 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
632c9d9e MS |
1104 | if (global_regs[i] |
1105 | #ifdef EPILOGUE_USES | |
1106 | || EPILOGUE_USES (i) | |
1107 | #endif | |
1108 | ) | |
d7429b6a | 1109 | { |
916b1701 MM |
1110 | SET_REGNO_REG_SET (basic_block_live_at_end[n_basic_blocks - 1], i); |
1111 | SET_REGNO_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1], i); | |
d7429b6a RK |
1112 | } |
1113 | ||
1114 | /* Propagate life info through the basic blocks | |
1115 | around the graph of basic blocks. | |
1116 | ||
1117 | This is a relaxation process: each time a new register | |
1118 | is live at the end of the basic block, we must scan the block | |
1119 | to determine which registers are, as a consequence, live at the beginning | |
1120 | of that block. These registers must then be marked live at the ends | |
1121 | of all the blocks that can transfer control to that block. | |
1122 | The process continues until it reaches a fixed point. */ | |
1123 | ||
1124 | first_pass = 1; | |
1125 | changed = 1; | |
1126 | while (changed) | |
1127 | { | |
1128 | changed = 0; | |
1129 | for (i = n_basic_blocks - 1; i >= 0; i--) | |
1130 | { | |
1131 | int consider = first_pass; | |
1132 | int must_rescan = first_pass; | |
1133 | register int j; | |
1134 | ||
1135 | if (!first_pass) | |
1136 | { | |
1137 | /* Set CONSIDER if this block needs thinking about at all | |
1138 | (that is, if the regs live now at the end of it | |
1139 | are not the same as were live at the end of it when | |
1140 | we last thought about it). | |
1141 | Set must_rescan if it needs to be thought about | |
1142 | instruction by instruction (that is, if any additional | |
1143 | reg that is live at the end now but was not live there before | |
1144 | is one of the significant regs of this basic block). */ | |
1145 | ||
b5835272 RK |
1146 | EXECUTE_IF_AND_COMPL_IN_REG_SET |
1147 | (basic_block_new_live_at_end[i], | |
1148 | basic_block_live_at_end[i], 0, j, | |
1149 | { | |
1150 | consider = 1; | |
1151 | if (REGNO_REG_SET_P (basic_block_significant[i], j)) | |
1152 | { | |
1153 | must_rescan = 1; | |
1154 | goto done; | |
1155 | } | |
1156 | }); | |
916b1701 | 1157 | done: |
d7429b6a RK |
1158 | if (! consider) |
1159 | continue; | |
1160 | } | |
1161 | ||
1162 | /* The live_at_start of this block may be changing, | |
1163 | so another pass will be required after this one. */ | |
1164 | changed = 1; | |
1165 | ||
1166 | if (! must_rescan) | |
1167 | { | |
1168 | /* No complete rescan needed; | |
1169 | just record those variables newly known live at end | |
1170 | as live at start as well. */ | |
916b1701 MM |
1171 | IOR_AND_COMPL_REG_SET (basic_block_live_at_start[i], |
1172 | basic_block_new_live_at_end[i], | |
1173 | basic_block_live_at_end[i]); | |
1174 | ||
1175 | IOR_AND_COMPL_REG_SET (basic_block_live_at_end[i], | |
1176 | basic_block_new_live_at_end[i], | |
1177 | basic_block_live_at_end[i]); | |
d7429b6a RK |
1178 | } |
1179 | else | |
1180 | { | |
1181 | /* Update the basic_block_live_at_start | |
1182 | by propagation backwards through the block. */ | |
916b1701 MM |
1183 | COPY_REG_SET (basic_block_live_at_end[i], |
1184 | basic_block_new_live_at_end[i]); | |
1185 | COPY_REG_SET (basic_block_live_at_start[i], | |
1186 | basic_block_live_at_end[i]); | |
d7429b6a RK |
1187 | propagate_block (basic_block_live_at_start[i], |
1188 | basic_block_head[i], basic_block_end[i], 0, | |
5f4f0e22 CH |
1189 | first_pass ? basic_block_significant[i] |
1190 | : (regset) 0, | |
d7429b6a RK |
1191 | i); |
1192 | } | |
1193 | ||
1194 | { | |
1195 | register rtx jump, head; | |
af14ce9c | 1196 | |
d7429b6a RK |
1197 | /* Update the basic_block_new_live_at_end's of the block |
1198 | that falls through into this one (if any). */ | |
1199 | head = basic_block_head[i]; | |
d7429b6a | 1200 | if (basic_block_drops_in[i]) |
916b1701 MM |
1201 | IOR_REG_SET (basic_block_new_live_at_end[i-1], |
1202 | basic_block_live_at_start[i]); | |
af14ce9c | 1203 | |
d7429b6a RK |
1204 | /* Update the basic_block_new_live_at_end's of |
1205 | all the blocks that jump to this one. */ | |
1206 | if (GET_CODE (head) == CODE_LABEL) | |
1207 | for (jump = LABEL_REFS (head); | |
1208 | jump != head; | |
1209 | jump = LABEL_NEXTREF (jump)) | |
1210 | { | |
1211 | register int from_block = BLOCK_NUM (CONTAINING_INSN (jump)); | |
916b1701 MM |
1212 | IOR_REG_SET (basic_block_new_live_at_end[from_block], |
1213 | basic_block_live_at_start[i]); | |
d7429b6a RK |
1214 | } |
1215 | } | |
1216 | #ifdef USE_C_ALLOCA | |
1217 | alloca (0); | |
1218 | #endif | |
1219 | } | |
1220 | first_pass = 0; | |
1221 | } | |
1222 | ||
1223 | /* The only pseudos that are live at the beginning of the function are | |
1224 | those that were not set anywhere in the function. local-alloc doesn't | |
1225 | know how to handle these correctly, so mark them as not local to any | |
1226 | one basic block. */ | |
1227 | ||
1228 | if (n_basic_blocks > 0) | |
916b1701 MM |
1229 | EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[0], |
1230 | FIRST_PSEUDO_REGISTER, i, | |
1231 | { | |
1232 | REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL; | |
1233 | }); | |
d7429b6a RK |
1234 | |
1235 | /* Now the life information is accurate. | |
1236 | Make one more pass over each basic block | |
1237 | to delete dead stores, create autoincrement addressing | |
1238 | and record how many times each register is used, is set, or dies. | |
1239 | ||
1240 | To save time, we operate directly in basic_block_live_at_end[i], | |
1241 | thus destroying it (in fact, converting it into a copy of | |
1242 | basic_block_live_at_start[i]). This is ok now because | |
1243 | basic_block_live_at_end[i] is no longer used past this point. */ | |
1244 | ||
1245 | max_scratch = 0; | |
1246 | ||
1247 | for (i = 0; i < n_basic_blocks; i++) | |
1248 | { | |
1249 | propagate_block (basic_block_live_at_end[i], | |
5f4f0e22 CH |
1250 | basic_block_head[i], basic_block_end[i], 1, |
1251 | (regset) 0, i); | |
d7429b6a RK |
1252 | #ifdef USE_C_ALLOCA |
1253 | alloca (0); | |
1254 | #endif | |
1255 | } | |
1256 | ||
1257 | #if 0 | |
1258 | /* Something live during a setjmp should not be put in a register | |
1259 | on certain machines which restore regs from stack frames | |
1260 | rather than from the jmpbuf. | |
1261 | But we don't need to do this for the user's variables, since | |
1262 | ANSI says only volatile variables need this. */ | |
1263 | #ifdef LONGJMP_RESTORE_FROM_STACK | |
916b1701 MM |
1264 | EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp, |
1265 | FIRST_PSEUDO_REGISTER, i, | |
1266 | { | |
1267 | if (regno_reg_rtx[i] != 0 | |
1268 | && ! REG_USERVAR_P (regno_reg_rtx[i])) | |
1269 | { | |
1270 | REG_LIVE_LENGTH (i) = -1; | |
1271 | REG_BASIC_BLOCK (i) = -1; | |
1272 | } | |
1273 | }); | |
d7429b6a RK |
1274 | #endif |
1275 | #endif | |
1276 | ||
1277 | /* We have a problem with any pseudoreg that | |
1278 | lives across the setjmp. ANSI says that if a | |
1279 | user variable does not change in value | |
1280 | between the setjmp and the longjmp, then the longjmp preserves it. | |
1281 | This includes longjmp from a place where the pseudo appears dead. | |
1282 | (In principle, the value still exists if it is in scope.) | |
1283 | If the pseudo goes in a hard reg, some other value may occupy | |
1284 | that hard reg where this pseudo is dead, thus clobbering the pseudo. | |
1285 | Conclusion: such a pseudo must not go in a hard reg. */ | |
916b1701 MM |
1286 | EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp, |
1287 | FIRST_PSEUDO_REGISTER, i, | |
1288 | { | |
1289 | if (regno_reg_rtx[i] != 0) | |
1290 | { | |
1291 | REG_LIVE_LENGTH (i) = -1; | |
1292 | REG_BASIC_BLOCK (i) = -1; | |
1293 | } | |
1294 | }); | |
d7429b6a | 1295 | |
67f0e213 RK |
1296 | |
1297 | free_regset_vector (basic_block_live_at_end, n_basic_blocks); | |
1298 | free_regset_vector (basic_block_new_live_at_end, n_basic_blocks); | |
1299 | free_regset_vector (basic_block_significant, n_basic_blocks); | |
1300 | basic_block_live_at_end = (regset *)0; | |
1301 | basic_block_new_live_at_end = (regset *)0; | |
1302 | basic_block_significant = (regset *)0; | |
1303 | ||
5f4f0e22 | 1304 | obstack_free (&flow_obstack, NULL_PTR); |
d7429b6a RK |
1305 | } |
1306 | \f | |
1307 | /* Subroutines of life analysis. */ | |
1308 | ||
1309 | /* Allocate the permanent data structures that represent the results | |
1310 | of life analysis. Not static since used also for stupid life analysis. */ | |
1311 | ||
1312 | void | |
1313 | allocate_for_life_analysis () | |
1314 | { | |
1315 | register int i; | |
d7429b6a | 1316 | |
67f0e213 RK |
1317 | /* Recalculate the register space, in case it has grown. Old style |
1318 | vector oriented regsets would set regset_{size,bytes} here also. */ | |
1319 | allocate_reg_info (max_regno, FALSE, FALSE); | |
d7429b6a | 1320 | |
b1f21e0a MM |
1321 | /* Because both reg_scan and flow_analysis want to set up the REG_N_SETS |
1322 | information, explicitly reset it here. The allocation should have | |
1323 | already happened on the previous reg_scan pass. Make sure in case | |
1324 | some more registers were allocated. */ | |
d7429b6a | 1325 | for (i = 0; i < max_regno; i++) |
b1f21e0a | 1326 | REG_N_SETS (i) = 0; |
d7429b6a | 1327 | |
4c9a05bc RK |
1328 | basic_block_live_at_start |
1329 | = (regset *) oballoc (n_basic_blocks * sizeof (regset)); | |
67f0e213 | 1330 | init_regset_vector (basic_block_live_at_start, n_basic_blocks, |
7eb136d6 | 1331 | function_obstack); |
d7429b6a | 1332 | |
7eb136d6 MM |
1333 | regs_live_at_setjmp = OBSTACK_ALLOC_REG_SET (function_obstack); |
1334 | CLEAR_REG_SET (regs_live_at_setjmp); | |
d7429b6a RK |
1335 | } |
1336 | ||
67f0e213 RK |
1337 | /* Make each element of VECTOR point at a regset. The vector has |
1338 | NELTS elements, and space is allocated from the ALLOC_OBSTACK | |
1339 | obstack. */ | |
d7429b6a | 1340 | |
67f0e213 RK |
1341 | void |
1342 | init_regset_vector (vector, nelts, alloc_obstack) | |
d7429b6a | 1343 | regset *vector; |
d7429b6a | 1344 | int nelts; |
7eb136d6 | 1345 | struct obstack *alloc_obstack; |
d7429b6a RK |
1346 | { |
1347 | register int i; | |
d7429b6a RK |
1348 | |
1349 | for (i = 0; i < nelts; i++) | |
1350 | { | |
7eb136d6 MM |
1351 | vector[i] = OBSTACK_ALLOC_REG_SET (alloc_obstack); |
1352 | CLEAR_REG_SET (vector[i]); | |
d7429b6a RK |
1353 | } |
1354 | } | |
e658434c | 1355 | |
67f0e213 RK |
1356 | /* Release any additional space allocated for each element of VECTOR point |
1357 | other than the regset header itself. The vector has NELTS elements. */ | |
1358 | ||
1359 | void | |
1360 | free_regset_vector (vector, nelts) | |
1361 | regset *vector; | |
1362 | int nelts; | |
1363 | { | |
1364 | register int i; | |
1365 | ||
1366 | for (i = 0; i < nelts; i++) | |
1367 | FREE_REG_SET (vector[i]); | |
1368 | } | |
1369 | ||
d7429b6a RK |
1370 | /* Compute the registers live at the beginning of a basic block |
1371 | from those live at the end. | |
1372 | ||
1373 | When called, OLD contains those live at the end. | |
1374 | On return, it contains those live at the beginning. | |
1375 | FIRST and LAST are the first and last insns of the basic block. | |
1376 | ||
1377 | FINAL is nonzero if we are doing the final pass which is not | |
1378 | for computing the life info (since that has already been done) | |
1379 | but for acting on it. On this pass, we delete dead stores, | |
1380 | set up the logical links and dead-variables lists of instructions, | |
1381 | and merge instructions for autoincrement and autodecrement addresses. | |
1382 | ||
1383 | SIGNIFICANT is nonzero only the first time for each basic block. | |
1384 | If it is nonzero, it points to a regset in which we store | |
1385 | a 1 for each register that is set within the block. | |
1386 | ||
1387 | BNUM is the number of the basic block. */ | |
1388 | ||
1389 | static void | |
1390 | propagate_block (old, first, last, final, significant, bnum) | |
1391 | register regset old; | |
1392 | rtx first; | |
1393 | rtx last; | |
1394 | int final; | |
1395 | regset significant; | |
1396 | int bnum; | |
1397 | { | |
1398 | register rtx insn; | |
1399 | rtx prev; | |
1400 | regset live; | |
1401 | regset dead; | |
1402 | ||
1403 | /* The following variables are used only if FINAL is nonzero. */ | |
1404 | /* This vector gets one element for each reg that has been live | |
1405 | at any point in the basic block that has been scanned so far. | |
916b1701 MM |
1406 | SOMETIMES_MAX says how many elements are in use so far. */ |
1407 | register int *regs_sometimes_live; | |
d7429b6a RK |
1408 | int sometimes_max = 0; |
1409 | /* This regset has 1 for each reg that we have seen live so far. | |
1410 | It and REGS_SOMETIMES_LIVE are updated together. */ | |
1411 | regset maxlive; | |
1412 | ||
1413 | /* The loop depth may change in the middle of a basic block. Since we | |
1414 | scan from end to beginning, we start with the depth at the end of the | |
1415 | current basic block, and adjust as we pass ends and starts of loops. */ | |
1416 | loop_depth = basic_block_loop_depth[bnum]; | |
1417 | ||
7eb136d6 MM |
1418 | dead = ALLOCA_REG_SET (); |
1419 | live = ALLOCA_REG_SET (); | |
d7429b6a RK |
1420 | |
1421 | cc0_live = 0; | |
1422 | last_mem_set = 0; | |
1423 | ||
1424 | /* Include any notes at the end of the block in the scan. | |
1425 | This is in case the block ends with a call to setjmp. */ | |
1426 | ||
1427 | while (NEXT_INSN (last) != 0 && GET_CODE (NEXT_INSN (last)) == NOTE) | |
1428 | { | |
1429 | /* Look for loop boundaries, we are going forward here. */ | |
1430 | last = NEXT_INSN (last); | |
1431 | if (NOTE_LINE_NUMBER (last) == NOTE_INSN_LOOP_BEG) | |
1432 | loop_depth++; | |
1433 | else if (NOTE_LINE_NUMBER (last) == NOTE_INSN_LOOP_END) | |
1434 | loop_depth--; | |
1435 | } | |
1436 | ||
1437 | if (final) | |
1438 | { | |
916b1701 | 1439 | register int i; |
d7429b6a RK |
1440 | |
1441 | num_scratch = 0; | |
7eb136d6 | 1442 | maxlive = ALLOCA_REG_SET (); |
916b1701 MM |
1443 | COPY_REG_SET (maxlive, old); |
1444 | regs_sometimes_live = (int *) alloca (max_regno * sizeof (int)); | |
d7429b6a RK |
1445 | |
1446 | /* Process the regs live at the end of the block. | |
1447 | Enter them in MAXLIVE and REGS_SOMETIMES_LIVE. | |
916b1701 MM |
1448 | Also mark them as not local to any one basic block. */ |
1449 | EXECUTE_IF_SET_IN_REG_SET (old, 0, i, | |
1450 | { | |
1451 | REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL; | |
1452 | regs_sometimes_live[sometimes_max] = i; | |
1453 | sometimes_max++; | |
1454 | }); | |
d7429b6a RK |
1455 | } |
1456 | ||
1457 | /* Scan the block an insn at a time from end to beginning. */ | |
1458 | ||
1459 | for (insn = last; ; insn = prev) | |
1460 | { | |
1461 | prev = PREV_INSN (insn); | |
1462 | ||
8329b5ec | 1463 | if (GET_CODE (insn) == NOTE) |
d7429b6a | 1464 | { |
8329b5ec DE |
1465 | /* Look for loop boundaries, remembering that we are going |
1466 | backwards. */ | |
1467 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END) | |
1468 | loop_depth++; | |
1469 | else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG) | |
1470 | loop_depth--; | |
1471 | ||
1472 | /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error. | |
1473 | Abort now rather than setting register status incorrectly. */ | |
1474 | if (loop_depth == 0) | |
1475 | abort (); | |
1476 | ||
1477 | /* If this is a call to `setjmp' et al, | |
1478 | warn if any non-volatile datum is live. */ | |
1479 | ||
1480 | if (final && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP) | |
916b1701 | 1481 | IOR_REG_SET (regs_live_at_setjmp, old); |
d7429b6a RK |
1482 | } |
1483 | ||
1484 | /* Update the life-status of regs for this insn. | |
1485 | First DEAD gets which regs are set in this insn | |
1486 | then LIVE gets which regs are used in this insn. | |
1487 | Then the regs live before the insn | |
1488 | are those live after, with DEAD regs turned off, | |
1489 | and then LIVE regs turned on. */ | |
1490 | ||
8329b5ec | 1491 | else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') |
d7429b6a RK |
1492 | { |
1493 | register int i; | |
5f4f0e22 | 1494 | rtx note = find_reg_note (insn, REG_RETVAL, NULL_RTX); |
d7429b6a RK |
1495 | int insn_is_dead |
1496 | = (insn_dead_p (PATTERN (insn), old, 0) | |
1497 | /* Don't delete something that refers to volatile storage! */ | |
1498 | && ! INSN_VOLATILE (insn)); | |
1499 | int libcall_is_dead | |
1500 | = (insn_is_dead && note != 0 | |
1501 | && libcall_dead_p (PATTERN (insn), old, note, insn)); | |
1502 | ||
1503 | /* If an instruction consists of just dead store(s) on final pass, | |
1504 | "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED. | |
1505 | We could really delete it with delete_insn, but that | |
1506 | can cause trouble for first or last insn in a basic block. */ | |
1507 | if (final && insn_is_dead) | |
1508 | { | |
1509 | PUT_CODE (insn, NOTE); | |
1510 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
1511 | NOTE_SOURCE_FILE (insn) = 0; | |
1512 | ||
e5df1ea3 RK |
1513 | /* CC0 is now known to be dead. Either this insn used it, |
1514 | in which case it doesn't anymore, or clobbered it, | |
1515 | so the next insn can't use it. */ | |
1516 | cc0_live = 0; | |
1517 | ||
d7429b6a RK |
1518 | /* If this insn is copying the return value from a library call, |
1519 | delete the entire library call. */ | |
1520 | if (libcall_is_dead) | |
1521 | { | |
1522 | rtx first = XEXP (note, 0); | |
1523 | rtx p = insn; | |
1524 | while (INSN_DELETED_P (first)) | |
1525 | first = NEXT_INSN (first); | |
1526 | while (p != first) | |
1527 | { | |
1528 | p = PREV_INSN (p); | |
1529 | PUT_CODE (p, NOTE); | |
1530 | NOTE_LINE_NUMBER (p) = NOTE_INSN_DELETED; | |
1531 | NOTE_SOURCE_FILE (p) = 0; | |
1532 | } | |
1533 | } | |
1534 | goto flushed; | |
1535 | } | |
1536 | ||
916b1701 MM |
1537 | CLEAR_REG_SET (dead); |
1538 | CLEAR_REG_SET (live); | |
d7429b6a RK |
1539 | |
1540 | /* See if this is an increment or decrement that can be | |
1541 | merged into a following memory address. */ | |
1542 | #ifdef AUTO_INC_DEC | |
1543 | { | |
956d6950 JL |
1544 | register rtx x = single_set (insn); |
1545 | ||
d7429b6a | 1546 | /* Does this instruction increment or decrement a register? */ |
956d6950 | 1547 | if (final && x != 0 |
d7429b6a RK |
1548 | && GET_CODE (SET_DEST (x)) == REG |
1549 | && (GET_CODE (SET_SRC (x)) == PLUS | |
1550 | || GET_CODE (SET_SRC (x)) == MINUS) | |
1551 | && XEXP (SET_SRC (x), 0) == SET_DEST (x) | |
1552 | && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT | |
1553 | /* Ok, look for a following memory ref we can combine with. | |
1554 | If one is found, change the memory ref to a PRE_INC | |
1555 | or PRE_DEC, cancel this insn, and return 1. | |
1556 | Return 0 if nothing has been done. */ | |
1557 | && try_pre_increment_1 (insn)) | |
1558 | goto flushed; | |
1559 | } | |
1560 | #endif /* AUTO_INC_DEC */ | |
1561 | ||
1562 | /* If this is not the final pass, and this insn is copying the | |
1563 | value of a library call and it's dead, don't scan the | |
1564 | insns that perform the library call, so that the call's | |
1565 | arguments are not marked live. */ | |
1566 | if (libcall_is_dead) | |
1567 | { | |
1568 | /* Mark the dest reg as `significant'. */ | |
5f4f0e22 | 1569 | mark_set_regs (old, dead, PATTERN (insn), NULL_RTX, significant); |
d7429b6a RK |
1570 | |
1571 | insn = XEXP (note, 0); | |
1572 | prev = PREV_INSN (insn); | |
1573 | } | |
1574 | else if (GET_CODE (PATTERN (insn)) == SET | |
1575 | && SET_DEST (PATTERN (insn)) == stack_pointer_rtx | |
1576 | && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS | |
1577 | && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx | |
1578 | && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT) | |
1579 | /* We have an insn to pop a constant amount off the stack. | |
1580 | (Such insns use PLUS regardless of the direction of the stack, | |
1581 | and any insn to adjust the stack by a constant is always a pop.) | |
1582 | These insns, if not dead stores, have no effect on life. */ | |
1583 | ; | |
1584 | else | |
1585 | { | |
1586 | /* LIVE gets the regs used in INSN; | |
1587 | DEAD gets those set by it. Dead insns don't make anything | |
1588 | live. */ | |
1589 | ||
5f4f0e22 CH |
1590 | mark_set_regs (old, dead, PATTERN (insn), |
1591 | final ? insn : NULL_RTX, significant); | |
d7429b6a RK |
1592 | |
1593 | /* If an insn doesn't use CC0, it becomes dead since we | |
1594 | assume that every insn clobbers it. So show it dead here; | |
1595 | mark_used_regs will set it live if it is referenced. */ | |
1596 | cc0_live = 0; | |
1597 | ||
1598 | if (! insn_is_dead) | |
1599 | mark_used_regs (old, live, PATTERN (insn), final, insn); | |
1600 | ||
1601 | /* Sometimes we may have inserted something before INSN (such as | |
1602 | a move) when we make an auto-inc. So ensure we will scan | |
1603 | those insns. */ | |
1604 | #ifdef AUTO_INC_DEC | |
1605 | prev = PREV_INSN (insn); | |
1606 | #endif | |
1607 | ||
1608 | if (! insn_is_dead && GET_CODE (insn) == CALL_INSN) | |
1609 | { | |
1610 | register int i; | |
1611 | ||
6b67ec08 RK |
1612 | rtx note; |
1613 | ||
1614 | for (note = CALL_INSN_FUNCTION_USAGE (insn); | |
1615 | note; | |
1616 | note = XEXP (note, 1)) | |
1617 | if (GET_CODE (XEXP (note, 0)) == USE) | |
1618 | mark_used_regs (old, live, SET_DEST (XEXP (note, 0)), | |
1619 | final, insn); | |
1620 | ||
d7429b6a | 1621 | /* Each call clobbers all call-clobbered regs that are not |
e4329280 | 1622 | global or fixed. Note that the function-value reg is a |
d7429b6a RK |
1623 | call-clobbered reg, and mark_set_regs has already had |
1624 | a chance to handle it. */ | |
1625 | ||
1626 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
e4329280 RK |
1627 | if (call_used_regs[i] && ! global_regs[i] |
1628 | && ! fixed_regs[i]) | |
916b1701 | 1629 | SET_REGNO_REG_SET (dead, i); |
d7429b6a RK |
1630 | |
1631 | /* The stack ptr is used (honorarily) by a CALL insn. */ | |
916b1701 | 1632 | SET_REGNO_REG_SET (live, STACK_POINTER_REGNUM); |
d7429b6a RK |
1633 | |
1634 | /* Calls may also reference any of the global registers, | |
1635 | so they are made live. */ | |
d7429b6a RK |
1636 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
1637 | if (global_regs[i]) | |
9b316aa2 RK |
1638 | mark_used_regs (old, live, |
1639 | gen_rtx (REG, reg_raw_mode[i], i), | |
1640 | final, insn); | |
d7429b6a RK |
1641 | |
1642 | /* Calls also clobber memory. */ | |
1643 | last_mem_set = 0; | |
1644 | } | |
1645 | ||
1646 | /* Update OLD for the registers used or set. */ | |
916b1701 MM |
1647 | AND_COMPL_REG_SET (old, dead); |
1648 | IOR_REG_SET (old, live); | |
d7429b6a RK |
1649 | |
1650 | if (GET_CODE (insn) == CALL_INSN && final) | |
1651 | { | |
1652 | /* Any regs live at the time of a call instruction | |
1653 | must not go in a register clobbered by calls. | |
1654 | Find all regs now live and record this for them. */ | |
1655 | ||
916b1701 | 1656 | register int *p = regs_sometimes_live; |
d7429b6a RK |
1657 | |
1658 | for (i = 0; i < sometimes_max; i++, p++) | |
916b1701 MM |
1659 | if (REGNO_REG_SET_P (old, *p)) |
1660 | REG_N_CALLS_CROSSED (*p)++; | |
d7429b6a RK |
1661 | } |
1662 | } | |
1663 | ||
1664 | /* On final pass, add any additional sometimes-live regs | |
1665 | into MAXLIVE and REGS_SOMETIMES_LIVE. | |
1666 | Also update counts of how many insns each reg is live at. */ | |
1667 | ||
1668 | if (final) | |
1669 | { | |
916b1701 MM |
1670 | register int regno; |
1671 | register int *p; | |
d7429b6a | 1672 | |
b5835272 RK |
1673 | EXECUTE_IF_AND_COMPL_IN_REG_SET |
1674 | (live, maxlive, 0, regno, | |
1675 | { | |
1676 | regs_sometimes_live[sometimes_max++] = regno; | |
1677 | SET_REGNO_REG_SET (maxlive, regno); | |
1678 | }); | |
d7429b6a | 1679 | |
916b1701 MM |
1680 | p = regs_sometimes_live; |
1681 | for (i = 0; i < sometimes_max; i++) | |
1682 | { | |
1683 | regno = *p++; | |
1684 | if (REGNO_REG_SET_P (old, regno)) | |
1685 | REG_LIVE_LENGTH (regno)++; | |
1686 | } | |
d7429b6a RK |
1687 | } |
1688 | } | |
1689 | flushed: ; | |
1690 | if (insn == first) | |
1691 | break; | |
1692 | } | |
1693 | ||
67f0e213 RK |
1694 | FREE_REG_SET (dead); |
1695 | FREE_REG_SET (live); | |
1696 | if (final) | |
1697 | FREE_REG_SET (maxlive); | |
1698 | ||
d7429b6a RK |
1699 | if (num_scratch > max_scratch) |
1700 | max_scratch = num_scratch; | |
1701 | } | |
1702 | \f | |
1703 | /* Return 1 if X (the body of an insn, or part of it) is just dead stores | |
1704 | (SET expressions whose destinations are registers dead after the insn). | |
1705 | NEEDED is the regset that says which regs are alive after the insn. | |
1706 | ||
1707 | Unless CALL_OK is non-zero, an insn is needed if it contains a CALL. */ | |
1708 | ||
1709 | static int | |
1710 | insn_dead_p (x, needed, call_ok) | |
1711 | rtx x; | |
1712 | regset needed; | |
1713 | int call_ok; | |
1714 | { | |
1715 | register RTX_CODE code = GET_CODE (x); | |
1716 | /* If setting something that's a reg or part of one, | |
1717 | see if that register's altered value will be live. */ | |
1718 | ||
1719 | if (code == SET) | |
1720 | { | |
1721 | register rtx r = SET_DEST (x); | |
1722 | /* A SET that is a subroutine call cannot be dead. */ | |
1723 | if (! call_ok && GET_CODE (SET_SRC (x)) == CALL) | |
1724 | return 0; | |
1725 | ||
1726 | #ifdef HAVE_cc0 | |
1727 | if (GET_CODE (r) == CC0) | |
1728 | return ! cc0_live; | |
1729 | #endif | |
1730 | ||
1731 | if (GET_CODE (r) == MEM && last_mem_set && ! MEM_VOLATILE_P (r) | |
1732 | && rtx_equal_p (r, last_mem_set)) | |
1733 | return 1; | |
1734 | ||
1735 | while (GET_CODE (r) == SUBREG | |
1736 | || GET_CODE (r) == STRICT_LOW_PART | |
1737 | || GET_CODE (r) == ZERO_EXTRACT | |
1738 | || GET_CODE (r) == SIGN_EXTRACT) | |
1739 | r = SUBREG_REG (r); | |
1740 | ||
1741 | if (GET_CODE (r) == REG) | |
1742 | { | |
1743 | register int regno = REGNO (r); | |
d7429b6a | 1744 | |
d8c8b8e3 | 1745 | /* Don't delete insns to set global regs. */ |
d7429b6a RK |
1746 | if ((regno < FIRST_PSEUDO_REGISTER && global_regs[regno]) |
1747 | /* Make sure insns to set frame pointer aren't deleted. */ | |
1748 | || regno == FRAME_POINTER_REGNUM | |
73a187c1 DE |
1749 | #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM |
1750 | || regno == HARD_FRAME_POINTER_REGNUM | |
1751 | #endif | |
d7e4fe8b RS |
1752 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
1753 | /* Make sure insns to set arg pointer are never deleted | |
1754 | (if the arg pointer isn't fixed, there will be a USE for | |
0f41302f | 1755 | it, so we can treat it normally). */ |
d7e4fe8b RS |
1756 | || (regno == ARG_POINTER_REGNUM && fixed_regs[regno]) |
1757 | #endif | |
916b1701 | 1758 | || REGNO_REG_SET_P (needed, regno)) |
d7429b6a RK |
1759 | return 0; |
1760 | ||
1761 | /* If this is a hard register, verify that subsequent words are | |
1762 | not needed. */ | |
1763 | if (regno < FIRST_PSEUDO_REGISTER) | |
1764 | { | |
1765 | int n = HARD_REGNO_NREGS (regno, GET_MODE (r)); | |
1766 | ||
1767 | while (--n > 0) | |
916b1701 | 1768 | if (REGNO_REG_SET_P (needed, regno+n)) |
d7429b6a RK |
1769 | return 0; |
1770 | } | |
1771 | ||
1772 | return 1; | |
1773 | } | |
1774 | } | |
1775 | /* If performing several activities, | |
1776 | insn is dead if each activity is individually dead. | |
1777 | Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE | |
1778 | that's inside a PARALLEL doesn't make the insn worth keeping. */ | |
1779 | else if (code == PARALLEL) | |
1780 | { | |
1781 | register int i = XVECLEN (x, 0); | |
1782 | for (i--; i >= 0; i--) | |
1783 | { | |
1784 | rtx elt = XVECEXP (x, 0, i); | |
1785 | if (!insn_dead_p (elt, needed, call_ok) | |
1786 | && GET_CODE (elt) != CLOBBER | |
1787 | && GET_CODE (elt) != USE) | |
1788 | return 0; | |
1789 | } | |
1790 | return 1; | |
1791 | } | |
1792 | /* We do not check CLOBBER or USE here. | |
1793 | An insn consisting of just a CLOBBER or just a USE | |
1794 | should not be deleted. */ | |
1795 | return 0; | |
1796 | } | |
1797 | ||
1798 | /* If X is the pattern of the last insn in a libcall, and assuming X is dead, | |
1799 | return 1 if the entire library call is dead. | |
1800 | This is true if X copies a register (hard or pseudo) | |
1801 | and if the hard return reg of the call insn is dead. | |
1802 | (The caller should have tested the destination of X already for death.) | |
1803 | ||
1804 | If this insn doesn't just copy a register, then we don't | |
1805 | have an ordinary libcall. In that case, cse could not have | |
1806 | managed to substitute the source for the dest later on, | |
1807 | so we can assume the libcall is dead. | |
1808 | ||
1809 | NEEDED is the bit vector of pseudoregs live before this insn. | |
1810 | NOTE is the REG_RETVAL note of the insn. INSN is the insn itself. */ | |
1811 | ||
1812 | static int | |
1813 | libcall_dead_p (x, needed, note, insn) | |
1814 | rtx x; | |
1815 | regset needed; | |
1816 | rtx note; | |
1817 | rtx insn; | |
1818 | { | |
1819 | register RTX_CODE code = GET_CODE (x); | |
1820 | ||
1821 | if (code == SET) | |
1822 | { | |
1823 | register rtx r = SET_SRC (x); | |
1824 | if (GET_CODE (r) == REG) | |
1825 | { | |
1826 | rtx call = XEXP (note, 0); | |
1827 | register int i; | |
1828 | ||
1829 | /* Find the call insn. */ | |
1830 | while (call != insn && GET_CODE (call) != CALL_INSN) | |
1831 | call = NEXT_INSN (call); | |
1832 | ||
1833 | /* If there is none, do nothing special, | |
1834 | since ordinary death handling can understand these insns. */ | |
1835 | if (call == insn) | |
1836 | return 0; | |
1837 | ||
1838 | /* See if the hard reg holding the value is dead. | |
1839 | If this is a PARALLEL, find the call within it. */ | |
1840 | call = PATTERN (call); | |
1841 | if (GET_CODE (call) == PARALLEL) | |
1842 | { | |
1843 | for (i = XVECLEN (call, 0) - 1; i >= 0; i--) | |
1844 | if (GET_CODE (XVECEXP (call, 0, i)) == SET | |
1845 | && GET_CODE (SET_SRC (XVECEXP (call, 0, i))) == CALL) | |
1846 | break; | |
1847 | ||
761a5bcd JW |
1848 | /* This may be a library call that is returning a value |
1849 | via invisible pointer. Do nothing special, since | |
1850 | ordinary death handling can understand these insns. */ | |
d7429b6a | 1851 | if (i < 0) |
761a5bcd | 1852 | return 0; |
d7429b6a RK |
1853 | |
1854 | call = XVECEXP (call, 0, i); | |
1855 | } | |
1856 | ||
1857 | return insn_dead_p (call, needed, 1); | |
1858 | } | |
1859 | } | |
1860 | return 1; | |
1861 | } | |
1862 | ||
1863 | /* Return 1 if register REGNO was used before it was set. | |
944e5f77 | 1864 | In other words, if it is live at function entry. |
6a45254e RK |
1865 | Don't count global register variables or variables in registers |
1866 | that can be used for function arg passing, though. */ | |
d7429b6a RK |
1867 | |
1868 | int | |
1869 | regno_uninitialized (regno) | |
1870 | int regno; | |
1871 | { | |
b0b7b46a | 1872 | if (n_basic_blocks == 0 |
6a45254e RK |
1873 | || (regno < FIRST_PSEUDO_REGISTER |
1874 | && (global_regs[regno] || FUNCTION_ARG_REGNO_P (regno)))) | |
d7429b6a RK |
1875 | return 0; |
1876 | ||
916b1701 | 1877 | return REGNO_REG_SET_P (basic_block_live_at_start[0], regno); |
d7429b6a RK |
1878 | } |
1879 | ||
1880 | /* 1 if register REGNO was alive at a place where `setjmp' was called | |
1881 | and was set more than once or is an argument. | |
1882 | Such regs may be clobbered by `longjmp'. */ | |
1883 | ||
1884 | int | |
1885 | regno_clobbered_at_setjmp (regno) | |
1886 | int regno; | |
1887 | { | |
1888 | if (n_basic_blocks == 0) | |
1889 | return 0; | |
1890 | ||
b1f21e0a | 1891 | return ((REG_N_SETS (regno) > 1 |
916b1701 MM |
1892 | || REGNO_REG_SET_P (basic_block_live_at_start[0], regno)) |
1893 | && REGNO_REG_SET_P (regs_live_at_setjmp, regno)); | |
d7429b6a RK |
1894 | } |
1895 | \f | |
1896 | /* Process the registers that are set within X. | |
1897 | Their bits are set to 1 in the regset DEAD, | |
1898 | because they are dead prior to this insn. | |
1899 | ||
1900 | If INSN is nonzero, it is the insn being processed | |
1901 | and the fact that it is nonzero implies this is the FINAL pass | |
1902 | in propagate_block. In this case, various info about register | |
1903 | usage is stored, LOG_LINKS fields of insns are set up. */ | |
1904 | ||
d7429b6a RK |
1905 | static void |
1906 | mark_set_regs (needed, dead, x, insn, significant) | |
1907 | regset needed; | |
1908 | regset dead; | |
1909 | rtx x; | |
1910 | rtx insn; | |
1911 | regset significant; | |
1912 | { | |
1913 | register RTX_CODE code = GET_CODE (x); | |
1914 | ||
1915 | if (code == SET || code == CLOBBER) | |
1916 | mark_set_1 (needed, dead, x, insn, significant); | |
1917 | else if (code == PARALLEL) | |
1918 | { | |
1919 | register int i; | |
1920 | for (i = XVECLEN (x, 0) - 1; i >= 0; i--) | |
1921 | { | |
1922 | code = GET_CODE (XVECEXP (x, 0, i)); | |
1923 | if (code == SET || code == CLOBBER) | |
1924 | mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant); | |
1925 | } | |
1926 | } | |
1927 | } | |
1928 | ||
1929 | /* Process a single SET rtx, X. */ | |
1930 | ||
1931 | static void | |
1932 | mark_set_1 (needed, dead, x, insn, significant) | |
1933 | regset needed; | |
1934 | regset dead; | |
1935 | rtx x; | |
1936 | rtx insn; | |
1937 | regset significant; | |
1938 | { | |
1939 | register int regno; | |
1940 | register rtx reg = SET_DEST (x); | |
1941 | ||
1942 | /* Modifying just one hardware register of a multi-reg value | |
1943 | or just a byte field of a register | |
1944 | does not mean the value from before this insn is now dead. | |
1945 | But it does mean liveness of that register at the end of the block | |
1946 | is significant. | |
1947 | ||
1948 | Within mark_set_1, however, we treat it as if the register is | |
1949 | indeed modified. mark_used_regs will, however, also treat this | |
1950 | register as being used. Thus, we treat these insns as setting a | |
1951 | new value for the register as a function of its old value. This | |
1952 | cases LOG_LINKS to be made appropriately and this will help combine. */ | |
1953 | ||
1954 | while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT | |
1955 | || GET_CODE (reg) == SIGN_EXTRACT | |
1956 | || GET_CODE (reg) == STRICT_LOW_PART) | |
1957 | reg = XEXP (reg, 0); | |
1958 | ||
1959 | /* If we are writing into memory or into a register mentioned in the | |
1960 | address of the last thing stored into memory, show we don't know | |
1961 | what the last store was. If we are writing memory, save the address | |
1962 | unless it is volatile. */ | |
1963 | if (GET_CODE (reg) == MEM | |
1964 | || (GET_CODE (reg) == REG | |
1965 | && last_mem_set != 0 && reg_overlap_mentioned_p (reg, last_mem_set))) | |
1966 | last_mem_set = 0; | |
1967 | ||
1968 | if (GET_CODE (reg) == MEM && ! side_effects_p (reg) | |
1969 | /* There are no REG_INC notes for SP, so we can't assume we'll see | |
1970 | everything that invalidates it. To be safe, don't eliminate any | |
1971 | stores though SP; none of them should be redundant anyway. */ | |
1972 | && ! reg_mentioned_p (stack_pointer_rtx, reg)) | |
1973 | last_mem_set = reg; | |
1974 | ||
1975 | if (GET_CODE (reg) == REG | |
1976 | && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM) | |
73a187c1 DE |
1977 | #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM |
1978 | && regno != HARD_FRAME_POINTER_REGNUM | |
1979 | #endif | |
d7e4fe8b RS |
1980 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
1981 | && ! (regno == ARG_POINTER_REGNUM && fixed_regs[regno]) | |
1982 | #endif | |
d7429b6a RK |
1983 | && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno])) |
1984 | /* && regno != STACK_POINTER_REGNUM) -- let's try without this. */ | |
1985 | { | |
916b1701 MM |
1986 | int some_needed = REGNO_REG_SET_P (needed, regno); |
1987 | int some_not_needed = ! some_needed; | |
d7429b6a RK |
1988 | |
1989 | /* Mark it as a significant register for this basic block. */ | |
1990 | if (significant) | |
916b1701 | 1991 | SET_REGNO_REG_SET (significant, regno); |
d7429b6a RK |
1992 | |
1993 | /* Mark it as as dead before this insn. */ | |
916b1701 | 1994 | SET_REGNO_REG_SET (dead, regno); |
d7429b6a RK |
1995 | |
1996 | /* A hard reg in a wide mode may really be multiple registers. | |
1997 | If so, mark all of them just like the first. */ | |
1998 | if (regno < FIRST_PSEUDO_REGISTER) | |
1999 | { | |
2000 | int n; | |
2001 | ||
2002 | /* Nothing below is needed for the stack pointer; get out asap. | |
2003 | Eg, log links aren't needed, since combine won't use them. */ | |
2004 | if (regno == STACK_POINTER_REGNUM) | |
2005 | return; | |
2006 | ||
2007 | n = HARD_REGNO_NREGS (regno, GET_MODE (reg)); | |
2008 | while (--n > 0) | |
2009 | { | |
916b1701 MM |
2010 | int regno_n = regno + n; |
2011 | int needed_regno = REGNO_REG_SET_P (needed, regno_n); | |
d7429b6a | 2012 | if (significant) |
916b1701 | 2013 | SET_REGNO_REG_SET (significant, regno_n); |
cb9e8ad1 | 2014 | |
916b1701 MM |
2015 | SET_REGNO_REG_SET (dead, regno_n); |
2016 | some_needed |= needed_regno; | |
2017 | some_not_needed |= ! needed_regno; | |
d7429b6a RK |
2018 | } |
2019 | } | |
2020 | /* Additional data to record if this is the final pass. */ | |
2021 | if (insn) | |
2022 | { | |
2023 | register rtx y = reg_next_use[regno]; | |
2024 | register int blocknum = BLOCK_NUM (insn); | |
2025 | ||
2026 | /* If this is a hard reg, record this function uses the reg. */ | |
2027 | ||
2028 | if (regno < FIRST_PSEUDO_REGISTER) | |
2029 | { | |
2030 | register int i; | |
2031 | int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg)); | |
2032 | ||
2033 | for (i = regno; i < endregno; i++) | |
2034 | { | |
93514916 JW |
2035 | /* The next use is no longer "next", since a store |
2036 | intervenes. */ | |
2037 | reg_next_use[i] = 0; | |
2038 | ||
d7429b6a | 2039 | regs_ever_live[i] = 1; |
b1f21e0a | 2040 | REG_N_SETS (i)++; |
d7429b6a RK |
2041 | } |
2042 | } | |
2043 | else | |
2044 | { | |
93514916 JW |
2045 | /* The next use is no longer "next", since a store |
2046 | intervenes. */ | |
2047 | reg_next_use[regno] = 0; | |
2048 | ||
d7429b6a RK |
2049 | /* Keep track of which basic blocks each reg appears in. */ |
2050 | ||
b1f21e0a MM |
2051 | if (REG_BASIC_BLOCK (regno) == REG_BLOCK_UNKNOWN) |
2052 | REG_BASIC_BLOCK (regno) = blocknum; | |
2053 | else if (REG_BASIC_BLOCK (regno) != blocknum) | |
2054 | REG_BASIC_BLOCK (regno) = REG_BLOCK_GLOBAL; | |
d7429b6a RK |
2055 | |
2056 | /* Count (weighted) references, stores, etc. This counts a | |
2057 | register twice if it is modified, but that is correct. */ | |
b1f21e0a | 2058 | REG_N_SETS (regno)++; |
d7429b6a | 2059 | |
b1f21e0a | 2060 | REG_N_REFS (regno) += loop_depth; |
d7429b6a RK |
2061 | |
2062 | /* The insns where a reg is live are normally counted | |
2063 | elsewhere, but we want the count to include the insn | |
2064 | where the reg is set, and the normal counting mechanism | |
2065 | would not count it. */ | |
b1f21e0a | 2066 | REG_LIVE_LENGTH (regno)++; |
d7429b6a RK |
2067 | } |
2068 | ||
cb9e8ad1 | 2069 | if (! some_not_needed) |
d7429b6a RK |
2070 | { |
2071 | /* Make a logical link from the next following insn | |
2072 | that uses this register, back to this insn. | |
2073 | The following insns have already been processed. | |
2074 | ||
2075 | We don't build a LOG_LINK for hard registers containing | |
2076 | in ASM_OPERANDs. If these registers get replaced, | |
2077 | we might wind up changing the semantics of the insn, | |
2078 | even if reload can make what appear to be valid assignments | |
2079 | later. */ | |
2080 | if (y && (BLOCK_NUM (y) == blocknum) | |
2081 | && (regno >= FIRST_PSEUDO_REGISTER | |
2082 | || asm_noperands (PATTERN (y)) < 0)) | |
2083 | LOG_LINKS (y) | |
2084 | = gen_rtx (INSN_LIST, VOIDmode, insn, LOG_LINKS (y)); | |
2085 | } | |
2086 | else if (! some_needed) | |
2087 | { | |
2088 | /* Note that dead stores have already been deleted when possible | |
2089 | If we get here, we have found a dead store that cannot | |
2090 | be eliminated (because the same insn does something useful). | |
2091 | Indicate this by marking the reg being set as dying here. */ | |
2092 | REG_NOTES (insn) | |
2093 | = gen_rtx (EXPR_LIST, REG_UNUSED, reg, REG_NOTES (insn)); | |
b1f21e0a | 2094 | REG_N_DEATHS (REGNO (reg))++; |
d7429b6a RK |
2095 | } |
2096 | else | |
2097 | { | |
2098 | /* This is a case where we have a multi-word hard register | |
2099 | and some, but not all, of the words of the register are | |
2100 | needed in subsequent insns. Write REG_UNUSED notes | |
2101 | for those parts that were not needed. This case should | |
2102 | be rare. */ | |
2103 | ||
2104 | int i; | |
2105 | ||
2106 | for (i = HARD_REGNO_NREGS (regno, GET_MODE (reg)) - 1; | |
2107 | i >= 0; i--) | |
916b1701 | 2108 | if (!REGNO_REG_SET_P (needed, regno + i)) |
d7429b6a RK |
2109 | REG_NOTES (insn) |
2110 | = gen_rtx (EXPR_LIST, REG_UNUSED, | |
04227afa DE |
2111 | gen_rtx (REG, reg_raw_mode[regno + i], |
2112 | regno + i), | |
d7429b6a RK |
2113 | REG_NOTES (insn)); |
2114 | } | |
2115 | } | |
2116 | } | |
8244fc4f RS |
2117 | else if (GET_CODE (reg) == REG) |
2118 | reg_next_use[regno] = 0; | |
d7429b6a RK |
2119 | |
2120 | /* If this is the last pass and this is a SCRATCH, show it will be dying | |
2121 | here and count it. */ | |
2122 | else if (GET_CODE (reg) == SCRATCH && insn != 0) | |
2123 | { | |
2124 | REG_NOTES (insn) | |
2125 | = gen_rtx (EXPR_LIST, REG_UNUSED, reg, REG_NOTES (insn)); | |
2126 | num_scratch++; | |
2127 | } | |
2128 | } | |
2129 | \f | |
2130 | #ifdef AUTO_INC_DEC | |
2131 | ||
2132 | /* X is a MEM found in INSN. See if we can convert it into an auto-increment | |
2133 | reference. */ | |
2134 | ||
2135 | static void | |
2136 | find_auto_inc (needed, x, insn) | |
2137 | regset needed; | |
2138 | rtx x; | |
2139 | rtx insn; | |
2140 | { | |
2141 | rtx addr = XEXP (x, 0); | |
e658434c | 2142 | HOST_WIDE_INT offset = 0; |
05ed5d57 | 2143 | rtx set; |
d7429b6a RK |
2144 | |
2145 | /* Here we detect use of an index register which might be good for | |
2146 | postincrement, postdecrement, preincrement, or predecrement. */ | |
2147 | ||
2148 | if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
2149 | offset = INTVAL (XEXP (addr, 1)), addr = XEXP (addr, 0); | |
2150 | ||
2151 | if (GET_CODE (addr) == REG) | |
2152 | { | |
2153 | register rtx y; | |
2154 | register int size = GET_MODE_SIZE (GET_MODE (x)); | |
2155 | rtx use; | |
2156 | rtx incr; | |
2157 | int regno = REGNO (addr); | |
2158 | ||
2159 | /* Is the next use an increment that might make auto-increment? */ | |
05ed5d57 RK |
2160 | if ((incr = reg_next_use[regno]) != 0 |
2161 | && (set = single_set (incr)) != 0 | |
2162 | && GET_CODE (set) == SET | |
d7429b6a RK |
2163 | && BLOCK_NUM (incr) == BLOCK_NUM (insn) |
2164 | /* Can't add side effects to jumps; if reg is spilled and | |
2165 | reloaded, there's no way to store back the altered value. */ | |
2166 | && GET_CODE (insn) != JUMP_INSN | |
05ed5d57 | 2167 | && (y = SET_SRC (set), GET_CODE (y) == PLUS) |
d7429b6a RK |
2168 | && XEXP (y, 0) == addr |
2169 | && GET_CODE (XEXP (y, 1)) == CONST_INT | |
2170 | && (0 | |
2171 | #ifdef HAVE_POST_INCREMENT | |
2172 | || (INTVAL (XEXP (y, 1)) == size && offset == 0) | |
2173 | #endif | |
2174 | #ifdef HAVE_POST_DECREMENT | |
2175 | || (INTVAL (XEXP (y, 1)) == - size && offset == 0) | |
2176 | #endif | |
2177 | #ifdef HAVE_PRE_INCREMENT | |
2178 | || (INTVAL (XEXP (y, 1)) == size && offset == size) | |
2179 | #endif | |
2180 | #ifdef HAVE_PRE_DECREMENT | |
2181 | || (INTVAL (XEXP (y, 1)) == - size && offset == - size) | |
2182 | #endif | |
2183 | ) | |
2184 | /* Make sure this reg appears only once in this insn. */ | |
2185 | && (use = find_use_as_address (PATTERN (insn), addr, offset), | |
2186 | use != 0 && use != (rtx) 1)) | |
2187 | { | |
05ed5d57 | 2188 | rtx q = SET_DEST (set); |
7280c2a4 RK |
2189 | enum rtx_code inc_code = (INTVAL (XEXP (y, 1)) == size |
2190 | ? (offset ? PRE_INC : POST_INC) | |
2191 | : (offset ? PRE_DEC : POST_DEC)); | |
d7429b6a RK |
2192 | |
2193 | if (dead_or_set_p (incr, addr)) | |
7280c2a4 RK |
2194 | { |
2195 | /* This is the simple case. Try to make the auto-inc. If | |
2196 | we can't, we are done. Otherwise, we will do any | |
2197 | needed updates below. */ | |
2198 | if (! validate_change (insn, &XEXP (x, 0), | |
2199 | gen_rtx (inc_code, Pmode, addr), | |
2200 | 0)) | |
2201 | return; | |
2202 | } | |
5175ad37 DE |
2203 | else if (GET_CODE (q) == REG |
2204 | /* PREV_INSN used here to check the semi-open interval | |
2205 | [insn,incr). */ | |
b24884cd JL |
2206 | && ! reg_used_between_p (q, PREV_INSN (insn), incr) |
2207 | /* We must also check for sets of q as q may be | |
2208 | a call clobbered hard register and there may | |
2209 | be a call between PREV_INSN (insn) and incr. */ | |
2210 | && ! reg_set_between_p (q, PREV_INSN (insn), incr)) | |
d7429b6a | 2211 | { |
5175ad37 | 2212 | /* We have *p followed sometime later by q = p+size. |
d7429b6a | 2213 | Both p and q must be live afterward, |
5175ad37 | 2214 | and q is not used between INSN and it's assignment. |
d7429b6a RK |
2215 | Change it to q = p, ...*q..., q = q+size. |
2216 | Then fall into the usual case. */ | |
2217 | rtx insns, temp; | |
2218 | ||
2219 | start_sequence (); | |
2220 | emit_move_insn (q, addr); | |
2221 | insns = get_insns (); | |
2222 | end_sequence (); | |
2223 | ||
2224 | /* If anything in INSNS have UID's that don't fit within the | |
2225 | extra space we allocate earlier, we can't make this auto-inc. | |
2226 | This should never happen. */ | |
2227 | for (temp = insns; temp; temp = NEXT_INSN (temp)) | |
2228 | { | |
2229 | if (INSN_UID (temp) > max_uid_for_flow) | |
2230 | return; | |
2231 | BLOCK_NUM (temp) = BLOCK_NUM (insn); | |
2232 | } | |
2233 | ||
7280c2a4 RK |
2234 | /* If we can't make the auto-inc, or can't make the |
2235 | replacement into Y, exit. There's no point in making | |
2236 | the change below if we can't do the auto-inc and doing | |
2237 | so is not correct in the pre-inc case. */ | |
2238 | ||
2239 | validate_change (insn, &XEXP (x, 0), | |
2240 | gen_rtx (inc_code, Pmode, q), | |
2241 | 1); | |
2242 | validate_change (incr, &XEXP (y, 0), q, 1); | |
2243 | if (! apply_change_group ()) | |
2244 | return; | |
2245 | ||
2246 | /* We now know we'll be doing this change, so emit the | |
2247 | new insn(s) and do the updates. */ | |
d7429b6a | 2248 | emit_insns_before (insns, insn); |
e8b641a1 RK |
2249 | |
2250 | if (basic_block_head[BLOCK_NUM (insn)] == insn) | |
2251 | basic_block_head[BLOCK_NUM (insn)] = insns; | |
2252 | ||
d7429b6a RK |
2253 | /* INCR will become a NOTE and INSN won't contain a |
2254 | use of ADDR. If a use of ADDR was just placed in | |
2255 | the insn before INSN, make that the next use. | |
2256 | Otherwise, invalidate it. */ | |
2257 | if (GET_CODE (PREV_INSN (insn)) == INSN | |
2258 | && GET_CODE (PATTERN (PREV_INSN (insn))) == SET | |
2259 | && SET_SRC (PATTERN (PREV_INSN (insn))) == addr) | |
2260 | reg_next_use[regno] = PREV_INSN (insn); | |
2261 | else | |
2262 | reg_next_use[regno] = 0; | |
2263 | ||
2264 | addr = q; | |
2265 | regno = REGNO (q); | |
d7429b6a RK |
2266 | |
2267 | /* REGNO is now used in INCR which is below INSN, but | |
2268 | it previously wasn't live here. If we don't mark | |
2269 | it as needed, we'll put a REG_DEAD note for it | |
2270 | on this insn, which is incorrect. */ | |
916b1701 | 2271 | SET_REGNO_REG_SET (needed, regno); |
d7429b6a RK |
2272 | |
2273 | /* If there are any calls between INSN and INCR, show | |
2274 | that REGNO now crosses them. */ | |
2275 | for (temp = insn; temp != incr; temp = NEXT_INSN (temp)) | |
2276 | if (GET_CODE (temp) == CALL_INSN) | |
b1f21e0a | 2277 | REG_N_CALLS_CROSSED (regno)++; |
d7429b6a | 2278 | } |
02df8aba RK |
2279 | else |
2280 | return; | |
d7429b6a | 2281 | |
7280c2a4 RK |
2282 | /* If we haven't returned, it means we were able to make the |
2283 | auto-inc, so update the status. First, record that this insn | |
2284 | has an implicit side effect. */ | |
2285 | ||
2286 | REG_NOTES (insn) | |
2287 | = gen_rtx (EXPR_LIST, REG_INC, addr, REG_NOTES (insn)); | |
2288 | ||
2289 | /* Modify the old increment-insn to simply copy | |
2290 | the already-incremented value of our register. */ | |
2291 | if (! validate_change (incr, &SET_SRC (set), addr, 0)) | |
2292 | abort (); | |
2293 | ||
2294 | /* If that makes it a no-op (copying the register into itself) delete | |
2295 | it so it won't appear to be a "use" and a "set" of this | |
2296 | register. */ | |
2297 | if (SET_DEST (set) == addr) | |
d7429b6a | 2298 | { |
7280c2a4 RK |
2299 | PUT_CODE (incr, NOTE); |
2300 | NOTE_LINE_NUMBER (incr) = NOTE_INSN_DELETED; | |
2301 | NOTE_SOURCE_FILE (incr) = 0; | |
2302 | } | |
d7429b6a | 2303 | |
7280c2a4 RK |
2304 | if (regno >= FIRST_PSEUDO_REGISTER) |
2305 | { | |
2306 | /* Count an extra reference to the reg. When a reg is | |
2307 | incremented, spilling it is worse, so we want to make | |
2308 | that less likely. */ | |
b1f21e0a | 2309 | REG_N_REFS (regno) += loop_depth; |
7280c2a4 RK |
2310 | |
2311 | /* Count the increment as a setting of the register, | |
2312 | even though it isn't a SET in rtl. */ | |
b1f21e0a | 2313 | REG_N_SETS (regno)++; |
d7429b6a RK |
2314 | } |
2315 | } | |
2316 | } | |
2317 | } | |
2318 | #endif /* AUTO_INC_DEC */ | |
2319 | \f | |
2320 | /* Scan expression X and store a 1-bit in LIVE for each reg it uses. | |
2321 | This is done assuming the registers needed from X | |
2322 | are those that have 1-bits in NEEDED. | |
2323 | ||
2324 | On the final pass, FINAL is 1. This means try for autoincrement | |
2325 | and count the uses and deaths of each pseudo-reg. | |
2326 | ||
2327 | INSN is the containing instruction. If INSN is dead, this function is not | |
2328 | called. */ | |
2329 | ||
2330 | static void | |
2331 | mark_used_regs (needed, live, x, final, insn) | |
2332 | regset needed; | |
2333 | regset live; | |
2334 | rtx x; | |
d7429b6a | 2335 | int final; |
e658434c | 2336 | rtx insn; |
d7429b6a RK |
2337 | { |
2338 | register RTX_CODE code; | |
2339 | register int regno; | |
2340 | int i; | |
2341 | ||
2342 | retry: | |
2343 | code = GET_CODE (x); | |
2344 | switch (code) | |
2345 | { | |
2346 | case LABEL_REF: | |
2347 | case SYMBOL_REF: | |
2348 | case CONST_INT: | |
2349 | case CONST: | |
2350 | case CONST_DOUBLE: | |
2351 | case PC: | |
d7429b6a RK |
2352 | case ADDR_VEC: |
2353 | case ADDR_DIFF_VEC: | |
2354 | case ASM_INPUT: | |
2355 | return; | |
2356 | ||
2357 | #ifdef HAVE_cc0 | |
2358 | case CC0: | |
2359 | cc0_live = 1; | |
2360 | return; | |
2361 | #endif | |
2362 | ||
2f1553a4 RK |
2363 | case CLOBBER: |
2364 | /* If we are clobbering a MEM, mark any registers inside the address | |
2365 | as being used. */ | |
2366 | if (GET_CODE (XEXP (x, 0)) == MEM) | |
2367 | mark_used_regs (needed, live, XEXP (XEXP (x, 0), 0), final, insn); | |
2368 | return; | |
2369 | ||
d7429b6a | 2370 | case MEM: |
7eb136d6 MM |
2371 | /* Invalidate the data for the last MEM stored, but only if MEM is |
2372 | something that can be stored into. */ | |
2373 | if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF | |
2374 | && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0))) | |
2375 | ; /* needn't clear last_mem_set */ | |
2376 | else | |
2377 | last_mem_set = 0; | |
d7429b6a RK |
2378 | |
2379 | #ifdef AUTO_INC_DEC | |
2380 | if (final) | |
2381 | find_auto_inc (needed, x, insn); | |
2382 | #endif | |
2383 | break; | |
2384 | ||
80f8f04a RK |
2385 | case SUBREG: |
2386 | if (GET_CODE (SUBREG_REG (x)) == REG | |
2387 | && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER | |
2388 | && (GET_MODE_SIZE (GET_MODE (x)) | |
88285acf | 2389 | != GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))) |
b1f21e0a | 2390 | REG_CHANGES_SIZE (REGNO (SUBREG_REG (x))) = 1; |
80f8f04a RK |
2391 | |
2392 | /* While we're here, optimize this case. */ | |
2393 | x = SUBREG_REG (x); | |
2394 | ||
e100a3bb | 2395 | /* In case the SUBREG is not of a register, don't optimize */ |
ce79abf3 | 2396 | if (GET_CODE (x) != REG) |
e100a3bb MM |
2397 | { |
2398 | mark_used_regs (needed, live, x, final, insn); | |
2399 | return; | |
2400 | } | |
ce79abf3 | 2401 | |
0f41302f | 2402 | /* ... fall through ... */ |
80f8f04a | 2403 | |
d7429b6a RK |
2404 | case REG: |
2405 | /* See a register other than being set | |
2406 | => mark it as needed. */ | |
2407 | ||
2408 | regno = REGNO (x); | |
2409 | { | |
67f0e213 RK |
2410 | int some_needed = REGNO_REG_SET_P (needed, regno); |
2411 | int some_not_needed = ! some_needed; | |
d7429b6a | 2412 | |
916b1701 | 2413 | SET_REGNO_REG_SET (live, regno); |
cb9e8ad1 | 2414 | |
d7429b6a RK |
2415 | /* A hard reg in a wide mode may really be multiple registers. |
2416 | If so, mark all of them just like the first. */ | |
2417 | if (regno < FIRST_PSEUDO_REGISTER) | |
2418 | { | |
2419 | int n; | |
2420 | ||
d7e4fe8b | 2421 | /* For stack ptr or fixed arg pointer, |
d7429b6a RK |
2422 | nothing below can be necessary, so waste no more time. */ |
2423 | if (regno == STACK_POINTER_REGNUM | |
73a187c1 DE |
2424 | #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM |
2425 | || regno == HARD_FRAME_POINTER_REGNUM | |
2426 | #endif | |
d7e4fe8b RS |
2427 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
2428 | || (regno == ARG_POINTER_REGNUM && fixed_regs[regno]) | |
2429 | #endif | |
d7429b6a RK |
2430 | || regno == FRAME_POINTER_REGNUM) |
2431 | { | |
2432 | /* If this is a register we are going to try to eliminate, | |
2433 | don't mark it live here. If we are successful in | |
2434 | eliminating it, it need not be live unless it is used for | |
2435 | pseudos, in which case it will have been set live when | |
2436 | it was allocated to the pseudos. If the register will not | |
2437 | be eliminated, reload will set it live at that point. */ | |
2438 | ||
2439 | if (! TEST_HARD_REG_BIT (elim_reg_set, regno)) | |
2440 | regs_ever_live[regno] = 1; | |
2441 | return; | |
2442 | } | |
2443 | /* No death notes for global register variables; | |
2444 | their values are live after this function exits. */ | |
2445 | if (global_regs[regno]) | |
d8c8b8e3 RS |
2446 | { |
2447 | if (final) | |
2448 | reg_next_use[regno] = insn; | |
2449 | return; | |
2450 | } | |
d7429b6a RK |
2451 | |
2452 | n = HARD_REGNO_NREGS (regno, GET_MODE (x)); | |
2453 | while (--n > 0) | |
2454 | { | |
916b1701 MM |
2455 | int regno_n = regno + n; |
2456 | int needed_regno = REGNO_REG_SET_P (needed, regno_n); | |
cb9e8ad1 | 2457 | |
916b1701 MM |
2458 | SET_REGNO_REG_SET (live, regno_n); |
2459 | some_needed |= needed_regno; | |
931c6c7a | 2460 | some_not_needed |= ! needed_regno; |
d7429b6a RK |
2461 | } |
2462 | } | |
2463 | if (final) | |
2464 | { | |
2465 | /* Record where each reg is used, so when the reg | |
2466 | is set we know the next insn that uses it. */ | |
2467 | ||
2468 | reg_next_use[regno] = insn; | |
2469 | ||
2470 | if (regno < FIRST_PSEUDO_REGISTER) | |
2471 | { | |
2472 | /* If a hard reg is being used, | |
2473 | record that this function does use it. */ | |
2474 | ||
2475 | i = HARD_REGNO_NREGS (regno, GET_MODE (x)); | |
2476 | if (i == 0) | |
2477 | i = 1; | |
2478 | do | |
2479 | regs_ever_live[regno + --i] = 1; | |
2480 | while (i > 0); | |
2481 | } | |
2482 | else | |
2483 | { | |
2484 | /* Keep track of which basic block each reg appears in. */ | |
2485 | ||
2486 | register int blocknum = BLOCK_NUM (insn); | |
2487 | ||
b1f21e0a MM |
2488 | if (REG_BASIC_BLOCK (regno) == REG_BLOCK_UNKNOWN) |
2489 | REG_BASIC_BLOCK (regno) = blocknum; | |
2490 | else if (REG_BASIC_BLOCK (regno) != blocknum) | |
2491 | REG_BASIC_BLOCK (regno) = REG_BLOCK_GLOBAL; | |
d7429b6a RK |
2492 | |
2493 | /* Count (weighted) number of uses of each reg. */ | |
2494 | ||
b1f21e0a | 2495 | REG_N_REFS (regno) += loop_depth; |
d7429b6a RK |
2496 | } |
2497 | ||
2498 | /* Record and count the insns in which a reg dies. | |
2499 | If it is used in this insn and was dead below the insn | |
2500 | then it dies in this insn. If it was set in this insn, | |
2501 | we do not make a REG_DEAD note; likewise if we already | |
2502 | made such a note. */ | |
2503 | ||
cb9e8ad1 | 2504 | if (some_not_needed |
d7429b6a RK |
2505 | && ! dead_or_set_p (insn, x) |
2506 | #if 0 | |
2507 | && (regno >= FIRST_PSEUDO_REGISTER || ! fixed_regs[regno]) | |
2508 | #endif | |
2509 | ) | |
2510 | { | |
ab28041e JW |
2511 | /* Check for the case where the register dying partially |
2512 | overlaps the register set by this insn. */ | |
2513 | if (regno < FIRST_PSEUDO_REGISTER | |
2514 | && HARD_REGNO_NREGS (regno, GET_MODE (x)) > 1) | |
2515 | { | |
480eac3b | 2516 | int n = HARD_REGNO_NREGS (regno, GET_MODE (x)); |
ab28041e JW |
2517 | while (--n >= 0) |
2518 | some_needed |= dead_or_set_regno_p (insn, regno + n); | |
2519 | } | |
2520 | ||
d7429b6a RK |
2521 | /* If none of the words in X is needed, make a REG_DEAD |
2522 | note. Otherwise, we must make partial REG_DEAD notes. */ | |
2523 | if (! some_needed) | |
2524 | { | |
2525 | REG_NOTES (insn) | |
2526 | = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (insn)); | |
b1f21e0a | 2527 | REG_N_DEATHS (regno)++; |
d7429b6a RK |
2528 | } |
2529 | else | |
2530 | { | |
2531 | int i; | |
2532 | ||
2533 | /* Don't make a REG_DEAD note for a part of a register | |
2534 | that is set in the insn. */ | |
2535 | ||
2536 | for (i = HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1; | |
2537 | i >= 0; i--) | |
916b1701 | 2538 | if (!REGNO_REG_SET_P (needed, regno + i) |
d7429b6a RK |
2539 | && ! dead_or_set_regno_p (insn, regno + i)) |
2540 | REG_NOTES (insn) | |
2541 | = gen_rtx (EXPR_LIST, REG_DEAD, | |
04227afa DE |
2542 | gen_rtx (REG, reg_raw_mode[regno + i], |
2543 | regno + i), | |
d7429b6a RK |
2544 | REG_NOTES (insn)); |
2545 | } | |
2546 | } | |
2547 | } | |
2548 | } | |
2549 | return; | |
2550 | ||
2551 | case SET: | |
2552 | { | |
2553 | register rtx testreg = SET_DEST (x); | |
2554 | int mark_dest = 0; | |
2555 | ||
2556 | /* If storing into MEM, don't show it as being used. But do | |
2557 | show the address as being used. */ | |
2558 | if (GET_CODE (testreg) == MEM) | |
2559 | { | |
2560 | #ifdef AUTO_INC_DEC | |
2561 | if (final) | |
2562 | find_auto_inc (needed, testreg, insn); | |
2563 | #endif | |
2564 | mark_used_regs (needed, live, XEXP (testreg, 0), final, insn); | |
2565 | mark_used_regs (needed, live, SET_SRC (x), final, insn); | |
2566 | return; | |
2567 | } | |
2568 | ||
2569 | /* Storing in STRICT_LOW_PART is like storing in a reg | |
2570 | in that this SET might be dead, so ignore it in TESTREG. | |
2571 | but in some other ways it is like using the reg. | |
2572 | ||
2573 | Storing in a SUBREG or a bit field is like storing the entire | |
2574 | register in that if the register's value is not used | |
2575 | then this SET is not needed. */ | |
2576 | while (GET_CODE (testreg) == STRICT_LOW_PART | |
2577 | || GET_CODE (testreg) == ZERO_EXTRACT | |
2578 | || GET_CODE (testreg) == SIGN_EXTRACT | |
2579 | || GET_CODE (testreg) == SUBREG) | |
2580 | { | |
88285acf RK |
2581 | if (GET_CODE (testreg) == SUBREG |
2582 | && GET_CODE (SUBREG_REG (testreg)) == REG | |
2583 | && REGNO (SUBREG_REG (testreg)) >= FIRST_PSEUDO_REGISTER | |
2584 | && (GET_MODE_SIZE (GET_MODE (testreg)) | |
2585 | != GET_MODE_SIZE (GET_MODE (SUBREG_REG (testreg))))) | |
b1f21e0a | 2586 | REG_CHANGES_SIZE (REGNO (SUBREG_REG (testreg))) = 1; |
88285acf | 2587 | |
d7429b6a RK |
2588 | /* Modifying a single register in an alternate mode |
2589 | does not use any of the old value. But these other | |
2590 | ways of storing in a register do use the old value. */ | |
2591 | if (GET_CODE (testreg) == SUBREG | |
2592 | && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg))) | |
2593 | ; | |
2594 | else | |
2595 | mark_dest = 1; | |
2596 | ||
2597 | testreg = XEXP (testreg, 0); | |
2598 | } | |
2599 | ||
2600 | /* If this is a store into a register, | |
2601 | recursively scan the value being stored. */ | |
2602 | ||
2603 | if (GET_CODE (testreg) == REG | |
2604 | && (regno = REGNO (testreg), regno != FRAME_POINTER_REGNUM) | |
73a187c1 DE |
2605 | #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM |
2606 | && regno != HARD_FRAME_POINTER_REGNUM | |
2607 | #endif | |
d7e4fe8b RS |
2608 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
2609 | && ! (regno == ARG_POINTER_REGNUM && fixed_regs[regno]) | |
2610 | #endif | |
d8c8b8e3 RS |
2611 | ) |
2612 | /* We used to exclude global_regs here, but that seems wrong. | |
2613 | Storing in them is like storing in mem. */ | |
d7429b6a RK |
2614 | { |
2615 | mark_used_regs (needed, live, SET_SRC (x), final, insn); | |
2616 | if (mark_dest) | |
2617 | mark_used_regs (needed, live, SET_DEST (x), final, insn); | |
2618 | return; | |
2619 | } | |
2620 | } | |
2621 | break; | |
2622 | ||
2623 | case RETURN: | |
2624 | /* If exiting needs the right stack value, consider this insn as | |
2625 | using the stack pointer. In any event, consider it as using | |
632c9d9e | 2626 | all global registers and all registers used by return. */ |
d7429b6a RK |
2627 | |
2628 | #ifdef EXIT_IGNORE_STACK | |
2629 | if (! EXIT_IGNORE_STACK | |
2630 | || (! FRAME_POINTER_REQUIRED && flag_omit_frame_pointer)) | |
2631 | #endif | |
916b1701 | 2632 | SET_REGNO_REG_SET (live, STACK_POINTER_REGNUM); |
d7429b6a RK |
2633 | |
2634 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
632c9d9e MS |
2635 | if (global_regs[i] |
2636 | #ifdef EPILOGUE_USES | |
2637 | || EPILOGUE_USES (i) | |
2638 | #endif | |
2639 | ) | |
916b1701 | 2640 | SET_REGNO_REG_SET (live, i); |
d7429b6a | 2641 | break; |
e9a25f70 JL |
2642 | |
2643 | default: | |
2644 | break; | |
d7429b6a RK |
2645 | } |
2646 | ||
2647 | /* Recursively scan the operands of this expression. */ | |
2648 | ||
2649 | { | |
2650 | register char *fmt = GET_RTX_FORMAT (code); | |
2651 | register int i; | |
2652 | ||
2653 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
2654 | { | |
2655 | if (fmt[i] == 'e') | |
2656 | { | |
2657 | /* Tail recursive case: save a function call level. */ | |
2658 | if (i == 0) | |
2659 | { | |
2660 | x = XEXP (x, 0); | |
2661 | goto retry; | |
2662 | } | |
2663 | mark_used_regs (needed, live, XEXP (x, i), final, insn); | |
2664 | } | |
2665 | else if (fmt[i] == 'E') | |
2666 | { | |
2667 | register int j; | |
2668 | for (j = 0; j < XVECLEN (x, i); j++) | |
2669 | mark_used_regs (needed, live, XVECEXP (x, i, j), final, insn); | |
2670 | } | |
2671 | } | |
2672 | } | |
2673 | } | |
2674 | \f | |
2675 | #ifdef AUTO_INC_DEC | |
2676 | ||
2677 | static int | |
2678 | try_pre_increment_1 (insn) | |
2679 | rtx insn; | |
2680 | { | |
2681 | /* Find the next use of this reg. If in same basic block, | |
2682 | make it do pre-increment or pre-decrement if appropriate. */ | |
956d6950 | 2683 | rtx x = single_set (insn); |
5f4f0e22 | 2684 | HOST_WIDE_INT amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1) |
d7429b6a RK |
2685 | * INTVAL (XEXP (SET_SRC (x), 1))); |
2686 | int regno = REGNO (SET_DEST (x)); | |
2687 | rtx y = reg_next_use[regno]; | |
2688 | if (y != 0 | |
2689 | && BLOCK_NUM (y) == BLOCK_NUM (insn) | |
89861c38 | 2690 | /* Don't do this if the reg dies, or gets set in y; a standard addressing |
0f41302f | 2691 | mode would be better. */ |
89861c38 | 2692 | && ! dead_or_set_p (y, SET_DEST (x)) |
956d6950 | 2693 | && try_pre_increment (y, SET_DEST (x), amount)) |
d7429b6a RK |
2694 | { |
2695 | /* We have found a suitable auto-increment | |
2696 | and already changed insn Y to do it. | |
2697 | So flush this increment-instruction. */ | |
2698 | PUT_CODE (insn, NOTE); | |
2699 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
2700 | NOTE_SOURCE_FILE (insn) = 0; | |
2701 | /* Count a reference to this reg for the increment | |
2702 | insn we are deleting. When a reg is incremented. | |
2703 | spilling it is worse, so we want to make that | |
2704 | less likely. */ | |
2705 | if (regno >= FIRST_PSEUDO_REGISTER) | |
2706 | { | |
b1f21e0a MM |
2707 | REG_N_REFS (regno) += loop_depth; |
2708 | REG_N_SETS (regno)++; | |
d7429b6a RK |
2709 | } |
2710 | return 1; | |
2711 | } | |
2712 | return 0; | |
2713 | } | |
2714 | ||
2715 | /* Try to change INSN so that it does pre-increment or pre-decrement | |
2716 | addressing on register REG in order to add AMOUNT to REG. | |
2717 | AMOUNT is negative for pre-decrement. | |
2718 | Returns 1 if the change could be made. | |
2719 | This checks all about the validity of the result of modifying INSN. */ | |
2720 | ||
2721 | static int | |
2722 | try_pre_increment (insn, reg, amount) | |
2723 | rtx insn, reg; | |
5f4f0e22 | 2724 | HOST_WIDE_INT amount; |
d7429b6a RK |
2725 | { |
2726 | register rtx use; | |
2727 | ||
2728 | /* Nonzero if we can try to make a pre-increment or pre-decrement. | |
2729 | For example, addl $4,r1; movl (r1),... can become movl +(r1),... */ | |
2730 | int pre_ok = 0; | |
2731 | /* Nonzero if we can try to make a post-increment or post-decrement. | |
2732 | For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,... | |
2733 | It is possible for both PRE_OK and POST_OK to be nonzero if the machine | |
2734 | supports both pre-inc and post-inc, or both pre-dec and post-dec. */ | |
2735 | int post_ok = 0; | |
2736 | ||
2737 | /* Nonzero if the opportunity actually requires post-inc or post-dec. */ | |
2738 | int do_post = 0; | |
2739 | ||
2740 | /* From the sign of increment, see which possibilities are conceivable | |
2741 | on this target machine. */ | |
2742 | #ifdef HAVE_PRE_INCREMENT | |
2743 | if (amount > 0) | |
2744 | pre_ok = 1; | |
2745 | #endif | |
2746 | #ifdef HAVE_POST_INCREMENT | |
2747 | if (amount > 0) | |
2748 | post_ok = 1; | |
2749 | #endif | |
2750 | ||
2751 | #ifdef HAVE_PRE_DECREMENT | |
2752 | if (amount < 0) | |
2753 | pre_ok = 1; | |
2754 | #endif | |
2755 | #ifdef HAVE_POST_DECREMENT | |
2756 | if (amount < 0) | |
2757 | post_ok = 1; | |
2758 | #endif | |
2759 | ||
2760 | if (! (pre_ok || post_ok)) | |
2761 | return 0; | |
2762 | ||
2763 | /* It is not safe to add a side effect to a jump insn | |
2764 | because if the incremented register is spilled and must be reloaded | |
2765 | there would be no way to store the incremented value back in memory. */ | |
2766 | ||
2767 | if (GET_CODE (insn) == JUMP_INSN) | |
2768 | return 0; | |
2769 | ||
2770 | use = 0; | |
2771 | if (pre_ok) | |
2772 | use = find_use_as_address (PATTERN (insn), reg, 0); | |
2773 | if (post_ok && (use == 0 || use == (rtx) 1)) | |
2774 | { | |
2775 | use = find_use_as_address (PATTERN (insn), reg, -amount); | |
2776 | do_post = 1; | |
2777 | } | |
2778 | ||
2779 | if (use == 0 || use == (rtx) 1) | |
2780 | return 0; | |
2781 | ||
2782 | if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount)) | |
2783 | return 0; | |
2784 | ||
a0fbc3a9 SC |
2785 | /* See if this combination of instruction and addressing mode exists. */ |
2786 | if (! validate_change (insn, &XEXP (use, 0), | |
2787 | gen_rtx (amount > 0 | |
2788 | ? (do_post ? POST_INC : PRE_INC) | |
2789 | : (do_post ? POST_DEC : PRE_DEC), | |
2790 | Pmode, reg), 0)) | |
2791 | return 0; | |
d7429b6a RK |
2792 | |
2793 | /* Record that this insn now has an implicit side effect on X. */ | |
2794 | REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, reg, REG_NOTES (insn)); | |
2795 | return 1; | |
2796 | } | |
2797 | ||
2798 | #endif /* AUTO_INC_DEC */ | |
2799 | \f | |
2800 | /* Find the place in the rtx X where REG is used as a memory address. | |
2801 | Return the MEM rtx that so uses it. | |
2802 | If PLUSCONST is nonzero, search instead for a memory address equivalent to | |
2803 | (plus REG (const_int PLUSCONST)). | |
2804 | ||
2805 | If such an address does not appear, return 0. | |
2806 | If REG appears more than once, or is used other than in such an address, | |
2807 | return (rtx)1. */ | |
2808 | ||
8c660648 | 2809 | rtx |
d7429b6a RK |
2810 | find_use_as_address (x, reg, plusconst) |
2811 | register rtx x; | |
2812 | rtx reg; | |
e658434c | 2813 | HOST_WIDE_INT plusconst; |
d7429b6a RK |
2814 | { |
2815 | enum rtx_code code = GET_CODE (x); | |
2816 | char *fmt = GET_RTX_FORMAT (code); | |
2817 | register int i; | |
2818 | register rtx value = 0; | |
2819 | register rtx tem; | |
2820 | ||
2821 | if (code == MEM && XEXP (x, 0) == reg && plusconst == 0) | |
2822 | return x; | |
2823 | ||
2824 | if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS | |
2825 | && XEXP (XEXP (x, 0), 0) == reg | |
2826 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
2827 | && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst) | |
2828 | return x; | |
2829 | ||
2830 | if (code == SIGN_EXTRACT || code == ZERO_EXTRACT) | |
2831 | { | |
2832 | /* If REG occurs inside a MEM used in a bit-field reference, | |
2833 | that is unacceptable. */ | |
2834 | if (find_use_as_address (XEXP (x, 0), reg, 0) != 0) | |
6fa5c106 | 2835 | return (rtx) (HOST_WIDE_INT) 1; |
d7429b6a RK |
2836 | } |
2837 | ||
2838 | if (x == reg) | |
6fa5c106 | 2839 | return (rtx) (HOST_WIDE_INT) 1; |
d7429b6a RK |
2840 | |
2841 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
2842 | { | |
2843 | if (fmt[i] == 'e') | |
2844 | { | |
2845 | tem = find_use_as_address (XEXP (x, i), reg, plusconst); | |
2846 | if (value == 0) | |
2847 | value = tem; | |
2848 | else if (tem != 0) | |
6fa5c106 | 2849 | return (rtx) (HOST_WIDE_INT) 1; |
d7429b6a RK |
2850 | } |
2851 | if (fmt[i] == 'E') | |
2852 | { | |
2853 | register int j; | |
2854 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
2855 | { | |
2856 | tem = find_use_as_address (XVECEXP (x, i, j), reg, plusconst); | |
2857 | if (value == 0) | |
2858 | value = tem; | |
2859 | else if (tem != 0) | |
6fa5c106 | 2860 | return (rtx) (HOST_WIDE_INT) 1; |
d7429b6a RK |
2861 | } |
2862 | } | |
2863 | } | |
2864 | ||
2865 | return value; | |
2866 | } | |
2867 | \f | |
2868 | /* Write information about registers and basic blocks into FILE. | |
2869 | This is part of making a debugging dump. */ | |
2870 | ||
2871 | void | |
2872 | dump_flow_info (file) | |
2873 | FILE *file; | |
2874 | { | |
2875 | register int i; | |
2876 | static char *reg_class_names[] = REG_CLASS_NAMES; | |
2877 | ||
2878 | fprintf (file, "%d registers.\n", max_regno); | |
2879 | ||
2880 | for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) | |
b1f21e0a | 2881 | if (REG_N_REFS (i)) |
d7429b6a | 2882 | { |
e4600702 | 2883 | enum reg_class class, altclass; |
d7429b6a | 2884 | fprintf (file, "\nRegister %d used %d times across %d insns", |
b1f21e0a MM |
2885 | i, REG_N_REFS (i), REG_LIVE_LENGTH (i)); |
2886 | if (REG_BASIC_BLOCK (i) >= 0) | |
2887 | fprintf (file, " in block %d", REG_BASIC_BLOCK (i)); | |
2888 | if (REG_N_DEATHS (i) != 1) | |
2889 | fprintf (file, "; dies in %d places", REG_N_DEATHS (i)); | |
2890 | if (REG_N_CALLS_CROSSED (i) == 1) | |
d7429b6a | 2891 | fprintf (file, "; crosses 1 call"); |
b1f21e0a MM |
2892 | else if (REG_N_CALLS_CROSSED (i)) |
2893 | fprintf (file, "; crosses %d calls", REG_N_CALLS_CROSSED (i)); | |
d7429b6a RK |
2894 | if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD) |
2895 | fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i)); | |
2896 | class = reg_preferred_class (i); | |
e4600702 RK |
2897 | altclass = reg_alternate_class (i); |
2898 | if (class != GENERAL_REGS || altclass != ALL_REGS) | |
d7429b6a | 2899 | { |
e4600702 RK |
2900 | if (altclass == ALL_REGS || class == ALL_REGS) |
2901 | fprintf (file, "; pref %s", reg_class_names[(int) class]); | |
2902 | else if (altclass == NO_REGS) | |
d7429b6a RK |
2903 | fprintf (file, "; %s or none", reg_class_names[(int) class]); |
2904 | else | |
e4600702 RK |
2905 | fprintf (file, "; pref %s, else %s", |
2906 | reg_class_names[(int) class], | |
2907 | reg_class_names[(int) altclass]); | |
d7429b6a RK |
2908 | } |
2909 | if (REGNO_POINTER_FLAG (i)) | |
2910 | fprintf (file, "; pointer"); | |
2911 | fprintf (file, ".\n"); | |
2912 | } | |
2913 | fprintf (file, "\n%d basic blocks.\n", n_basic_blocks); | |
2914 | for (i = 0; i < n_basic_blocks; i++) | |
2915 | { | |
2916 | register rtx head, jump; | |
2917 | register int regno; | |
2918 | fprintf (file, "\nBasic block %d: first insn %d, last %d.\n", | |
2919 | i, | |
2920 | INSN_UID (basic_block_head[i]), | |
2921 | INSN_UID (basic_block_end[i])); | |
2922 | /* The control flow graph's storage is freed | |
2923 | now when flow_analysis returns. | |
2924 | Don't try to print it if it is gone. */ | |
2925 | if (basic_block_drops_in) | |
2926 | { | |
2927 | fprintf (file, "Reached from blocks: "); | |
2928 | head = basic_block_head[i]; | |
2929 | if (GET_CODE (head) == CODE_LABEL) | |
2930 | for (jump = LABEL_REFS (head); | |
2931 | jump != head; | |
2932 | jump = LABEL_NEXTREF (jump)) | |
2933 | { | |
2934 | register int from_block = BLOCK_NUM (CONTAINING_INSN (jump)); | |
2935 | fprintf (file, " %d", from_block); | |
2936 | } | |
2937 | if (basic_block_drops_in[i]) | |
2938 | fprintf (file, " previous"); | |
2939 | } | |
2940 | fprintf (file, "\nRegisters live at start:"); | |
2941 | for (regno = 0; regno < max_regno; regno++) | |
916b1701 MM |
2942 | if (REGNO_REG_SET_P (basic_block_live_at_start[i], regno)) |
2943 | fprintf (file, " %d", regno); | |
d7429b6a RK |
2944 | fprintf (file, "\n"); |
2945 | } | |
2946 | fprintf (file, "\n"); | |
2947 | } | |
3e28fe44 MM |
2948 | |
2949 | \f | |
2950 | /* Like print_rtl, but also print out live information for the start of each | |
2951 | basic block. */ | |
2952 | ||
2953 | void | |
2954 | print_rtl_with_bb (outf, rtx_first) | |
2955 | FILE *outf; | |
2956 | rtx rtx_first; | |
2957 | { | |
2958 | register rtx tmp_rtx; | |
2959 | ||
2960 | if (rtx_first == 0) | |
2961 | fprintf (outf, "(nil)\n"); | |
2962 | ||
2963 | else | |
2964 | { | |
2965 | int i, bb; | |
2966 | enum bb_state { NOT_IN_BB, IN_ONE_BB, IN_MULTIPLE_BB }; | |
2967 | int max_uid = get_max_uid (); | |
adfc539e PDM |
2968 | int *start = (int *) alloca (max_uid * sizeof (int)); |
2969 | int *end = (int *) alloca (max_uid * sizeof (int)); | |
d8d64559 | 2970 | char *in_bb_p = (char *) alloca (max_uid * sizeof (enum bb_state)); |
3e28fe44 MM |
2971 | |
2972 | for (i = 0; i < max_uid; i++) | |
2973 | { | |
2974 | start[i] = end[i] = -1; | |
2975 | in_bb_p[i] = NOT_IN_BB; | |
2976 | } | |
2977 | ||
2978 | for (i = n_basic_blocks-1; i >= 0; i--) | |
2979 | { | |
2980 | rtx x; | |
2981 | start[INSN_UID (basic_block_head[i])] = i; | |
2982 | end[INSN_UID (basic_block_end[i])] = i; | |
2983 | for (x = basic_block_head[i]; x != NULL_RTX; x = NEXT_INSN (x)) | |
2984 | { | |
1791f8e2 MM |
2985 | in_bb_p[ INSN_UID(x)] |
2986 | = (in_bb_p[ INSN_UID(x)] == NOT_IN_BB) | |
3b33f637 | 2987 | ? IN_ONE_BB : IN_MULTIPLE_BB; |
3e28fe44 MM |
2988 | if (x == basic_block_end[i]) |
2989 | break; | |
2990 | } | |
2991 | } | |
2992 | ||
2993 | for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx)) | |
2994 | { | |
2995 | if ((bb = start[INSN_UID (tmp_rtx)]) >= 0) | |
2996 | { | |
2997 | fprintf (outf, ";; Start of basic block %d, registers live:", | |
2998 | bb); | |
2999 | ||
3000 | EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[bb], 0, i, | |
3001 | { | |
3002 | fprintf (outf, " %d", i); | |
3003 | if (i < FIRST_PSEUDO_REGISTER) | |
3004 | fprintf (outf, " [%s]", | |
3005 | reg_names[i]); | |
3006 | }); | |
3007 | putc ('\n', outf); | |
3008 | } | |
3009 | ||
3010 | if (in_bb_p[ INSN_UID(tmp_rtx)] == NOT_IN_BB | |
3011 | && GET_CODE (tmp_rtx) != NOTE | |
3012 | && GET_CODE (tmp_rtx) != BARRIER) | |
3013 | fprintf (outf, ";; Insn is not within a basic block\n"); | |
3014 | else if (in_bb_p[ INSN_UID(tmp_rtx)] == IN_MULTIPLE_BB) | |
3015 | fprintf (outf, ";; Insn is in multiple basic blocks\n"); | |
3016 | ||
3017 | print_rtl_single (outf, tmp_rtx); | |
3018 | ||
3019 | if ((bb = end[INSN_UID (tmp_rtx)]) >= 0) | |
3020 | fprintf (outf, ";; End of basic block %d\n", bb); | |
3021 | ||
3022 | putc ('\n', outf); | |
3023 | } | |
3024 | } | |
3025 | } |