]> gcc.gnu.org Git - gcc.git/blob - gcc/integrate.c
loop.c (count_one_set): New static function, broken out of count_loop_regs_set
[gcc.git] / gcc / integrate.c
1 /* Procedure integration for GNU CC.
2 Copyright (C) 1988, 91, 93-97, 1998 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22
23 #include "config.h"
24 #include "system.h"
25
26 #include "rtl.h"
27 #include "tree.h"
28 #include "regs.h"
29 #include "flags.h"
30 #include "insn-config.h"
31 #include "insn-flags.h"
32 #include "expr.h"
33 #include "output.h"
34 #include "recog.h"
35 #include "integrate.h"
36 #include "real.h"
37 #include "except.h"
38 #include "function.h"
39 #include "toplev.h"
40
41 #include "obstack.h"
42 #define obstack_chunk_alloc xmalloc
43 #define obstack_chunk_free free
44
45 extern struct obstack *function_maybepermanent_obstack;
46
47 /* Similar, but round to the next highest integer that meets the
48 alignment. */
49 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
50
51 /* Default max number of insns a function can have and still be inline.
52 This is overridden on RISC machines. */
53 #ifndef INTEGRATE_THRESHOLD
54 /* Inlining small functions might save more space then not inlining at
55 all. Assume 1 instruction for the call and 1.5 insns per argument. */
56 #define INTEGRATE_THRESHOLD(DECL) \
57 (optimize_size \
58 ? (1 + (3 * list_length (DECL_ARGUMENTS (DECL)) / 2)) \
59 : (8 * (8 + list_length (DECL_ARGUMENTS (DECL)))))
60 #endif
61 \f
62 static rtx initialize_for_inline PROTO((tree, int, int, int, int));
63 static void finish_inline PROTO((tree, rtx));
64 static void adjust_copied_decl_tree PROTO((tree));
65 static tree copy_decl_list PROTO((tree));
66 static tree copy_decl_tree PROTO((tree));
67 static void copy_decl_rtls PROTO((tree));
68 static void save_constants PROTO((rtx *));
69 static void note_modified_parmregs PROTO((rtx, rtx));
70 static rtx copy_for_inline PROTO((rtx));
71 static void integrate_parm_decls PROTO((tree, struct inline_remap *,
72 rtvec));
73 static void integrate_decl_tree PROTO((tree, int,
74 struct inline_remap *));
75 static void save_constants_in_decl_trees PROTO ((tree));
76 static void subst_constants PROTO((rtx *, rtx,
77 struct inline_remap *));
78 static void restore_constants PROTO((rtx *));
79 static void set_block_origin_self PROTO((tree));
80 static void set_decl_origin_self PROTO((tree));
81 static void set_block_abstract_flags PROTO((tree, int));
82 static void process_reg_param PROTO((struct inline_remap *, rtx,
83 rtx));
84
85
86 void set_decl_abstract_flags PROTO((tree, int));
87 static tree copy_and_set_decl_abstract_origin PROTO((tree));
88 \f
89 /* Returns the Ith entry in the label_map contained in MAP. If the
90 Ith entry has not yet been set, return a fresh label. This function
91 performs a lazy initialization of label_map, thereby avoiding huge memory
92 explosions when the label_map gets very large. */
93
94 rtx
95 get_label_from_map (map, i)
96 struct inline_remap *map;
97 int i;
98 {
99 rtx x = map->label_map[i];
100
101 if (x == NULL_RTX)
102 {
103 push_obstacks_nochange ();
104 end_temporary_allocation ();
105 x = map->label_map[i] = gen_label_rtx();
106 pop_obstacks ();
107 }
108
109 return x;
110 }
111
112 /* Zero if the current function (whose FUNCTION_DECL is FNDECL)
113 is safe and reasonable to integrate into other functions.
114 Nonzero means value is a warning message with a single %s
115 for the function's name. */
116
117 char *
118 function_cannot_inline_p (fndecl)
119 register tree fndecl;
120 {
121 register rtx insn;
122 tree last = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
123 int max_insns = INTEGRATE_THRESHOLD (fndecl);
124 register int ninsns = 0;
125 register tree parms;
126 rtx result;
127
128 /* No inlines with varargs. */
129 if ((last && TREE_VALUE (last) != void_type_node)
130 || current_function_varargs)
131 return "varargs function cannot be inline";
132
133 if (current_function_calls_alloca)
134 return "function using alloca cannot be inline";
135
136 if (current_function_contains_functions)
137 return "function with nested functions cannot be inline";
138
139 if (current_function_cannot_inline)
140 return current_function_cannot_inline;
141
142 /* If its not even close, don't even look. */
143 if (!DECL_INLINE (fndecl) && get_max_uid () > 3 * max_insns)
144 return "function too large to be inline";
145
146 #if 0
147 /* Don't inline functions which do not specify a function prototype and
148 have BLKmode argument or take the address of a parameter. */
149 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
150 {
151 if (TYPE_MODE (TREE_TYPE (parms)) == BLKmode)
152 TREE_ADDRESSABLE (parms) = 1;
153 if (last == NULL_TREE && TREE_ADDRESSABLE (parms))
154 return "no prototype, and parameter address used; cannot be inline";
155 }
156 #endif
157
158 /* We can't inline functions that return structures
159 the old-fashioned PCC way, copying into a static block. */
160 if (current_function_returns_pcc_struct)
161 return "inline functions not supported for this return value type";
162
163 /* We can't inline functions that return structures of varying size. */
164 if (int_size_in_bytes (TREE_TYPE (TREE_TYPE (fndecl))) < 0)
165 return "function with varying-size return value cannot be inline";
166
167 /* Cannot inline a function with a varying size argument or one that
168 receives a transparent union. */
169 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
170 {
171 if (int_size_in_bytes (TREE_TYPE (parms)) < 0)
172 return "function with varying-size parameter cannot be inline";
173 else if (TYPE_TRANSPARENT_UNION (TREE_TYPE (parms)))
174 return "function with transparent unit parameter cannot be inline";
175 }
176
177 if (!DECL_INLINE (fndecl) && get_max_uid () > max_insns)
178 {
179 for (ninsns = 0, insn = get_first_nonparm_insn ();
180 insn && ninsns < max_insns;
181 insn = NEXT_INSN (insn))
182 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
183 ninsns++;
184
185 if (ninsns >= max_insns)
186 return "function too large to be inline";
187 }
188
189 /* We cannot inline this function if forced_labels is non-zero. This
190 implies that a label in this function was used as an initializer.
191 Because labels can not be duplicated, all labels in the function
192 will be renamed when it is inlined. However, there is no way to find
193 and fix all variables initialized with addresses of labels in this
194 function, hence inlining is impossible. */
195
196 if (forced_labels)
197 return "function with label addresses used in initializers cannot inline";
198
199 /* We cannot inline a nested function that jumps to a nonlocal label. */
200 if (current_function_has_nonlocal_goto)
201 return "function with nonlocal goto cannot be inline";
202
203 /* This is a hack, until the inliner is taught about eh regions at
204 the start of the function. */
205 for (insn = get_insns ();
206 insn
207 && ! (GET_CODE (insn) == NOTE
208 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG);
209 insn = NEXT_INSN (insn))
210 {
211 if (insn && GET_CODE (insn) == NOTE
212 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
213 return "function with complex parameters cannot be inline";
214 }
215
216 /* We can't inline functions that return a PARALLEL rtx. */
217 result = DECL_RTL (DECL_RESULT (fndecl));
218 if (result && GET_CODE (result) == PARALLEL)
219 return "inline functions not supported for this return value type";
220
221 return 0;
222 }
223 \f
224 /* Variables used within save_for_inline. */
225
226 /* Mapping from old pseudo-register to new pseudo-registers.
227 The first element of this map is reg_map[FIRST_PSEUDO_REGISTER].
228 It is allocated in `save_for_inline' and `expand_inline_function',
229 and deallocated on exit from each of those routines. */
230 static rtx *reg_map;
231
232 /* Mapping from old code-labels to new code-labels.
233 The first element of this map is label_map[min_labelno].
234 It is allocated in `save_for_inline' and `expand_inline_function',
235 and deallocated on exit from each of those routines. */
236 static rtx *label_map;
237
238 /* Mapping from old insn uid's to copied insns.
239 It is allocated in `save_for_inline' and `expand_inline_function',
240 and deallocated on exit from each of those routines. */
241 static rtx *insn_map;
242
243 /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
244 Zero for a reg that isn't a parm's home.
245 Only reg numbers less than max_parm_reg are mapped here. */
246 static tree *parmdecl_map;
247
248 /* Keep track of first pseudo-register beyond those that are parms. */
249 extern int max_parm_reg;
250 extern rtx *parm_reg_stack_loc;
251
252 /* When an insn is being copied by copy_for_inline,
253 this is nonzero if we have copied an ASM_OPERANDS.
254 In that case, it is the original input-operand vector. */
255 static rtvec orig_asm_operands_vector;
256
257 /* When an insn is being copied by copy_for_inline,
258 this is nonzero if we have copied an ASM_OPERANDS.
259 In that case, it is the copied input-operand vector. */
260 static rtvec copy_asm_operands_vector;
261
262 /* Likewise, this is the copied constraints vector. */
263 static rtvec copy_asm_constraints_vector;
264
265 /* In save_for_inline, nonzero if past the parm-initialization insns. */
266 static int in_nonparm_insns;
267 \f
268 /* Subroutine for `save_for_inline{copying,nocopy}'. Performs initialization
269 needed to save FNDECL's insns and info for future inline expansion. */
270
271 static rtx
272 initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, copy)
273 tree fndecl;
274 int min_labelno;
275 int max_labelno;
276 int max_reg;
277 int copy;
278 {
279 int function_flags, i;
280 rtvec arg_vector;
281 tree parms;
282
283 /* Compute the values of any flags we must restore when inlining this. */
284
285 function_flags
286 = (current_function_calls_alloca * FUNCTION_FLAGS_CALLS_ALLOCA
287 + current_function_calls_setjmp * FUNCTION_FLAGS_CALLS_SETJMP
288 + current_function_calls_longjmp * FUNCTION_FLAGS_CALLS_LONGJMP
289 + current_function_returns_struct * FUNCTION_FLAGS_RETURNS_STRUCT
290 + current_function_returns_pcc_struct * FUNCTION_FLAGS_RETURNS_PCC_STRUCT
291 + current_function_needs_context * FUNCTION_FLAGS_NEEDS_CONTEXT
292 + current_function_has_nonlocal_label * FUNCTION_FLAGS_HAS_NONLOCAL_LABEL
293 + current_function_returns_pointer * FUNCTION_FLAGS_RETURNS_POINTER
294 + current_function_uses_const_pool * FUNCTION_FLAGS_USES_CONST_POOL
295 + current_function_uses_pic_offset_table * FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE);
296
297 /* Clear out PARMDECL_MAP. It was allocated in the caller's frame. */
298 bzero ((char *) parmdecl_map, max_parm_reg * sizeof (tree));
299 arg_vector = rtvec_alloc (list_length (DECL_ARGUMENTS (fndecl)));
300
301 for (parms = DECL_ARGUMENTS (fndecl), i = 0;
302 parms;
303 parms = TREE_CHAIN (parms), i++)
304 {
305 rtx p = DECL_RTL (parms);
306 int copied_incoming = 0;
307
308 /* If we have (mem (addressof (mem ...))), use the inner MEM since
309 otherwise the copy_rtx call below will not unshare the MEM since
310 it shares ADDRESSOF. */
311 if (GET_CODE (p) == MEM && GET_CODE (XEXP (p, 0)) == ADDRESSOF
312 && GET_CODE (XEXP (XEXP (p, 0), 0)) == MEM)
313 p = XEXP (XEXP (p, 0), 0);
314
315 if (GET_CODE (p) == MEM && copy)
316 {
317 /* Copy the rtl so that modifications of the addresses
318 later in compilation won't affect this arg_vector.
319 Virtual register instantiation can screw the address
320 of the rtl. */
321 rtx new = copy_rtx (p);
322
323 /* Don't leave the old copy anywhere in this decl. */
324 if (DECL_RTL (parms) == DECL_INCOMING_RTL (parms)
325 || (GET_CODE (DECL_RTL (parms)) == MEM
326 && GET_CODE (DECL_INCOMING_RTL (parms)) == MEM
327 && (XEXP (DECL_RTL (parms), 0)
328 == XEXP (DECL_INCOMING_RTL (parms), 0))))
329 DECL_INCOMING_RTL (parms) = new, copied_incoming = 1;
330
331 DECL_RTL (parms) = new;
332 }
333
334 RTVEC_ELT (arg_vector, i) = p;
335
336 if (GET_CODE (p) == REG)
337 parmdecl_map[REGNO (p)] = parms;
338 else if (GET_CODE (p) == CONCAT)
339 {
340 rtx preal = gen_realpart (GET_MODE (XEXP (p, 0)), p);
341 rtx pimag = gen_imagpart (GET_MODE (preal), p);
342
343 if (GET_CODE (preal) == REG)
344 parmdecl_map[REGNO (preal)] = parms;
345 if (GET_CODE (pimag) == REG)
346 parmdecl_map[REGNO (pimag)] = parms;
347 }
348
349 /* This flag is cleared later
350 if the function ever modifies the value of the parm. */
351 TREE_READONLY (parms) = 1;
352
353 /* Copy DECL_INCOMING_RTL if not done already. This can
354 happen if DECL_RTL is a reg. */
355 if (copy && ! copied_incoming)
356 {
357 p = DECL_INCOMING_RTL (parms);
358
359 /* If we have (mem (addressof (mem ...))), use the inner MEM since
360 otherwise the copy_rtx call below will not unshare the MEM since
361 it shares ADDRESSOF. */
362 if (GET_CODE (p) == MEM && GET_CODE (XEXP (p, 0)) == ADDRESSOF
363 && GET_CODE (XEXP (XEXP (p, 0), 0)) == MEM)
364 p = XEXP (XEXP (p, 0), 0);
365
366 if (GET_CODE (p) == MEM)
367 DECL_INCOMING_RTL (parms) = copy_rtx (p);
368 }
369 }
370
371 /* Assume we start out in the insns that set up the parameters. */
372 in_nonparm_insns = 0;
373
374 /* The list of DECL_SAVED_INSNS, starts off with a header which
375 contains the following information:
376
377 the first insn of the function (not including the insns that copy
378 parameters into registers).
379 the first parameter insn of the function,
380 the first label used by that function,
381 the last label used by that function,
382 the highest register number used for parameters,
383 the total number of registers used,
384 the size of the incoming stack area for parameters,
385 the number of bytes popped on return,
386 the stack slot list,
387 the labels that are forced to exist,
388 some flags that are used to restore compiler globals,
389 the value of current_function_outgoing_args_size,
390 the original argument vector,
391 the original DECL_INITIAL,
392 and pointers to the table of pseudo regs, pointer flags, and alignment. */
393
394 return gen_inline_header_rtx (NULL_RTX, NULL_RTX, min_labelno, max_labelno,
395 max_parm_reg, max_reg,
396 current_function_args_size,
397 current_function_pops_args,
398 stack_slot_list, forced_labels, function_flags,
399 current_function_outgoing_args_size,
400 arg_vector, (rtx) DECL_INITIAL (fndecl),
401 (rtvec) regno_reg_rtx, regno_pointer_flag,
402 regno_pointer_align,
403 (rtvec) parm_reg_stack_loc);
404 }
405
406 /* Subroutine for `save_for_inline{copying,nocopy}'. Finishes up the
407 things that must be done to make FNDECL expandable as an inline function.
408 HEAD contains the chain of insns to which FNDECL will expand. */
409
410 static void
411 finish_inline (fndecl, head)
412 tree fndecl;
413 rtx head;
414 {
415 FIRST_FUNCTION_INSN (head) = get_first_nonparm_insn ();
416 FIRST_PARM_INSN (head) = get_insns ();
417 DECL_SAVED_INSNS (fndecl) = head;
418 DECL_FRAME_SIZE (fndecl) = get_frame_size ();
419 }
420
421 /* Adjust the BLOCK_END_NOTE pointers in a given copied DECL tree so that
422 they all point to the new (copied) rtxs. */
423
424 static void
425 adjust_copied_decl_tree (block)
426 register tree block;
427 {
428 register tree subblock;
429 register rtx original_end;
430
431 original_end = BLOCK_END_NOTE (block);
432 if (original_end)
433 {
434 BLOCK_END_NOTE (block) = (rtx) NOTE_SOURCE_FILE (original_end);
435 NOTE_SOURCE_FILE (original_end) = 0;
436 }
437
438 /* Process all subblocks. */
439 for (subblock = BLOCK_SUBBLOCKS (block);
440 subblock;
441 subblock = TREE_CHAIN (subblock))
442 adjust_copied_decl_tree (subblock);
443 }
444
445 /* Make the insns and PARM_DECLs of the current function permanent
446 and record other information in DECL_SAVED_INSNS to allow inlining
447 of this function in subsequent calls.
448
449 This function is called when we are going to immediately compile
450 the insns for FNDECL. The insns in maybepermanent_obstack cannot be
451 modified by the compilation process, so we copy all of them to
452 new storage and consider the new insns to be the insn chain to be
453 compiled. Our caller (rest_of_compilation) saves the original
454 DECL_INITIAL and DECL_ARGUMENTS; here we copy them. */
455
456 /* ??? The nonlocal_label list should be adjusted also. However, since
457 a function that contains a nested function never gets inlined currently,
458 the nonlocal_label list will always be empty, so we don't worry about
459 it for now. */
460
461 void
462 save_for_inline_copying (fndecl)
463 tree fndecl;
464 {
465 rtx first_insn, last_insn, insn;
466 rtx head, copy;
467 int max_labelno, min_labelno, i, len;
468 int max_reg;
469 int max_uid;
470 rtx first_nonparm_insn;
471 char *new, *new1;
472 rtx *new_parm_reg_stack_loc;
473 rtx *new2;
474
475 /* Make and emit a return-label if we have not already done so.
476 Do this before recording the bounds on label numbers. */
477
478 if (return_label == 0)
479 {
480 return_label = gen_label_rtx ();
481 emit_label (return_label);
482 }
483
484 /* Get some bounds on the labels and registers used. */
485
486 max_labelno = max_label_num ();
487 min_labelno = get_first_label_num ();
488 max_reg = max_reg_num ();
489
490 /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
491 Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
492 Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
493 for the parms, prior to elimination of virtual registers.
494 These values are needed for substituting parms properly. */
495
496 parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
497
498 head = initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, 1);
499
500 if (current_function_uses_const_pool)
501 {
502 /* Replace any constant pool references with the actual constant. We
503 will put the constants back in the copy made below. */
504 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
505 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
506 {
507 save_constants (&PATTERN (insn));
508 if (REG_NOTES (insn))
509 save_constants (&REG_NOTES (insn));
510 }
511
512 /* Also scan all decls, and replace any constant pool references with the
513 actual constant. */
514 save_constants_in_decl_trees (DECL_INITIAL (fndecl));
515
516 /* Clear out the constant pool so that we can recreate it with the
517 copied constants below. */
518 init_const_rtx_hash_table ();
519 clear_const_double_mem ();
520 }
521
522 max_uid = INSN_UID (head);
523
524 /* We have now allocated all that needs to be allocated permanently
525 on the rtx obstack. Set our high-water mark, so that we
526 can free the rest of this when the time comes. */
527
528 preserve_data ();
529
530 /* Copy the chain insns of this function.
531 Install the copied chain as the insns of this function,
532 for continued compilation;
533 the original chain is recorded as the DECL_SAVED_INSNS
534 for inlining future calls. */
535
536 /* If there are insns that copy parms from the stack into pseudo registers,
537 those insns are not copied. `expand_inline_function' must
538 emit the correct code to handle such things. */
539
540 insn = get_insns ();
541 if (GET_CODE (insn) != NOTE)
542 abort ();
543 first_insn = rtx_alloc (NOTE);
544 NOTE_SOURCE_FILE (first_insn) = NOTE_SOURCE_FILE (insn);
545 NOTE_LINE_NUMBER (first_insn) = NOTE_LINE_NUMBER (insn);
546 INSN_UID (first_insn) = INSN_UID (insn);
547 PREV_INSN (first_insn) = NULL;
548 NEXT_INSN (first_insn) = NULL;
549 last_insn = first_insn;
550
551 /* Each pseudo-reg in the old insn chain must have a unique rtx in the copy.
552 Make these new rtx's now, and install them in regno_reg_rtx, so they
553 will be the official pseudo-reg rtx's for the rest of compilation. */
554
555 reg_map = (rtx *) savealloc (regno_pointer_flag_length * sizeof (rtx));
556
557 len = sizeof (struct rtx_def) + (GET_RTX_LENGTH (REG) - 1) * sizeof (rtunion);
558 for (i = max_reg - 1; i > LAST_VIRTUAL_REGISTER; i--)
559 reg_map[i] = (rtx)obstack_copy (function_maybepermanent_obstack,
560 regno_reg_rtx[i], len);
561
562 regno_reg_rtx = reg_map;
563
564 /* Put copies of all the virtual register rtx into the new regno_reg_rtx. */
565 init_virtual_regs ();
566
567 /* Likewise each label rtx must have a unique rtx as its copy. */
568
569 /* We used to use alloca here, but the size of what it would try to
570 allocate would occasionally cause it to exceed the stack limit and
571 cause unpredictable core dumps. Some examples were > 2Mb in size. */
572 label_map = (rtx *) xmalloc ((max_labelno) * sizeof (rtx));
573
574 for (i = min_labelno; i < max_labelno; i++)
575 label_map[i] = gen_label_rtx ();
576
577 /* Likewise for parm_reg_stack_slot. */
578 new_parm_reg_stack_loc = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
579 for (i = 0; i < max_parm_reg; i++)
580 new_parm_reg_stack_loc[i] = copy_for_inline (parm_reg_stack_loc[i]);
581
582 parm_reg_stack_loc = new_parm_reg_stack_loc;
583
584 /* Record the mapping of old insns to copied insns. */
585
586 insn_map = (rtx *) alloca (max_uid * sizeof (rtx));
587 bzero ((char *) insn_map, max_uid * sizeof (rtx));
588
589 /* Get the insn which signals the end of parameter setup code. */
590 first_nonparm_insn = get_first_nonparm_insn ();
591
592 /* Copy any entries in regno_reg_rtx or DECL_RTLs that reference MEM
593 (the former occurs when a variable has its address taken)
594 since these may be shared and can be changed by virtual
595 register instantiation. DECL_RTL values for our arguments
596 have already been copied by initialize_for_inline. */
597 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_reg; i++)
598 if (GET_CODE (regno_reg_rtx[i]) == MEM)
599 XEXP (regno_reg_rtx[i], 0)
600 = copy_for_inline (XEXP (regno_reg_rtx[i], 0));
601
602 /* Copy the parm_reg_stack_loc array, and substitute for all of the rtx
603 contained in it. */
604 new2 = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
605 bcopy ((char *) parm_reg_stack_loc, (char *) new2,
606 max_parm_reg * sizeof (rtx));
607 parm_reg_stack_loc = new2;
608 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; ++i)
609 if (parm_reg_stack_loc[i])
610 parm_reg_stack_loc[i] = copy_for_inline (parm_reg_stack_loc[i]);
611
612 /* Copy the tree of subblocks of the function, and the decls in them.
613 We will use the copy for compiling this function, then restore the original
614 subblocks and decls for use when inlining this function.
615
616 Several parts of the compiler modify BLOCK trees. In particular,
617 instantiate_virtual_regs will instantiate any virtual regs
618 mentioned in the DECL_RTLs of the decls, and loop
619 unrolling will replicate any BLOCK trees inside an unrolled loop.
620
621 The modified subblocks or DECL_RTLs would be incorrect for the original rtl
622 which we will use for inlining. The rtl might even contain pseudoregs
623 whose space has been freed. */
624
625 DECL_INITIAL (fndecl) = copy_decl_tree (DECL_INITIAL (fndecl));
626 DECL_ARGUMENTS (fndecl) = copy_decl_list (DECL_ARGUMENTS (fndecl));
627
628 /* Now copy each DECL_RTL which is a MEM,
629 so it is safe to modify their addresses. */
630 copy_decl_rtls (DECL_INITIAL (fndecl));
631
632 /* The fndecl node acts as its own progenitor, so mark it as such. */
633 DECL_ABSTRACT_ORIGIN (fndecl) = fndecl;
634
635 /* Now copy the chain of insns. Do this twice. The first copy the insn
636 itself and its body. The second time copy of REG_NOTES. This is because
637 a REG_NOTE may have a forward pointer to another insn. */
638
639 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
640 {
641 orig_asm_operands_vector = 0;
642
643 if (insn == first_nonparm_insn)
644 in_nonparm_insns = 1;
645
646 switch (GET_CODE (insn))
647 {
648 case NOTE:
649 /* No need to keep these. */
650 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
651 continue;
652
653 copy = rtx_alloc (NOTE);
654 NOTE_LINE_NUMBER (copy) = NOTE_LINE_NUMBER (insn);
655 if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_BLOCK_END)
656 NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
657 else
658 {
659 NOTE_SOURCE_FILE (insn) = (char *) copy;
660 NOTE_SOURCE_FILE (copy) = 0;
661 }
662 if (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG
663 || NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_END)
664 {
665 int new_region = CODE_LABEL_NUMBER
666 (label_map[NOTE_BLOCK_NUMBER (copy)]);
667
668 /* we have to duplicate the handlers for the original */
669 if (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG)
670 {
671 handler_info *ptr, *temp;
672 int nr;
673 nr = new_eh_region_entry (new_region);
674 ptr = get_first_handler (NOTE_BLOCK_NUMBER (copy));
675 for ( ; ptr; ptr = ptr->next)
676 {
677 temp = get_new_handler (
678 label_map[CODE_LABEL_NUMBER (ptr->handler_label)],
679 ptr->type_info);
680 add_new_handler (nr, temp);
681 }
682 }
683
684 /* We have to forward these both to match the new exception
685 region. */
686 NOTE_BLOCK_NUMBER (copy) = new_region;
687
688 }
689 RTX_INTEGRATED_P (copy) = RTX_INTEGRATED_P (insn);
690 break;
691
692 case INSN:
693 case JUMP_INSN:
694 case CALL_INSN:
695 copy = rtx_alloc (GET_CODE (insn));
696
697 if (GET_CODE (insn) == CALL_INSN)
698 CALL_INSN_FUNCTION_USAGE (copy)
699 = copy_for_inline (CALL_INSN_FUNCTION_USAGE (insn));
700
701 PATTERN (copy) = copy_for_inline (PATTERN (insn));
702 INSN_CODE (copy) = -1;
703 LOG_LINKS (copy) = NULL_RTX;
704 RTX_INTEGRATED_P (copy) = RTX_INTEGRATED_P (insn);
705 break;
706
707 case CODE_LABEL:
708 copy = label_map[CODE_LABEL_NUMBER (insn)];
709 LABEL_NAME (copy) = LABEL_NAME (insn);
710 break;
711
712 case BARRIER:
713 copy = rtx_alloc (BARRIER);
714 break;
715
716 default:
717 abort ();
718 }
719 INSN_UID (copy) = INSN_UID (insn);
720 insn_map[INSN_UID (insn)] = copy;
721 NEXT_INSN (last_insn) = copy;
722 PREV_INSN (copy) = last_insn;
723 last_insn = copy;
724 }
725
726 adjust_copied_decl_tree (DECL_INITIAL (fndecl));
727
728 /* Now copy the REG_NOTES. */
729 for (insn = NEXT_INSN (get_insns ()); insn; insn = NEXT_INSN (insn))
730 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
731 && insn_map[INSN_UID(insn)])
732 REG_NOTES (insn_map[INSN_UID (insn)])
733 = copy_for_inline (REG_NOTES (insn));
734
735 NEXT_INSN (last_insn) = NULL;
736
737 finish_inline (fndecl, head);
738
739 /* Make new versions of the register tables. */
740 new = (char *) savealloc (regno_pointer_flag_length);
741 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
742 new1 = (char *) savealloc (regno_pointer_flag_length);
743 bcopy (regno_pointer_align, new1, regno_pointer_flag_length);
744
745 regno_pointer_flag = new;
746 regno_pointer_align = new1;
747
748 set_new_first_and_last_insn (first_insn, last_insn);
749
750 if (label_map)
751 free (label_map);
752 }
753
754 /* Copy NODE (as with copy_node). NODE must be a DECL. Set the
755 DECL_ABSTRACT_ORIGIN for the new accordinly. */
756
757 static tree
758 copy_and_set_decl_abstract_origin (node)
759 tree node;
760 {
761 tree copy = copy_node (node);
762 if (DECL_ABSTRACT_ORIGIN (copy) != NULL_TREE)
763 /* That means that NODE already had a DECL_ABSTRACT_ORIGIN. (This
764 situation occurs if we inline a function which itself made
765 calls to inline functions.) Since DECL_ABSTRACT_ORIGIN is the
766 most distant ancestor, we don't have to do anything here. */
767 ;
768 else
769 /* The most distant ancestor must be NODE. */
770 DECL_ABSTRACT_ORIGIN (copy) = node;
771
772 return copy;
773 }
774
775 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
776 For example, this can copy a list made of TREE_LIST nodes. While copying,
777 set DECL_ABSTRACT_ORIGIN appropriately. */
778
779 static tree
780 copy_decl_list (list)
781 tree list;
782 {
783 tree head;
784 register tree prev, next;
785
786 if (list == 0)
787 return 0;
788
789 head = prev = copy_and_set_decl_abstract_origin (list);
790 next = TREE_CHAIN (list);
791 while (next)
792 {
793 register tree copy;
794
795 copy = copy_and_set_decl_abstract_origin (next);
796 TREE_CHAIN (prev) = copy;
797 prev = copy;
798 next = TREE_CHAIN (next);
799 }
800 return head;
801 }
802
803 /* Make a copy of the entire tree of blocks BLOCK, and return it. */
804
805 static tree
806 copy_decl_tree (block)
807 tree block;
808 {
809 tree t, vars, subblocks;
810
811 vars = copy_decl_list (BLOCK_VARS (block));
812 subblocks = 0;
813
814 /* Process all subblocks. */
815 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
816 {
817 tree copy = copy_decl_tree (t);
818 TREE_CHAIN (copy) = subblocks;
819 subblocks = copy;
820 }
821
822 t = copy_node (block);
823 BLOCK_VARS (t) = vars;
824 BLOCK_SUBBLOCKS (t) = nreverse (subblocks);
825 /* If the BLOCK being cloned is already marked as having been instantiated
826 from something else, then leave that `origin' marking alone. Otherwise,
827 mark the clone as having originated from the BLOCK we are cloning. */
828 if (BLOCK_ABSTRACT_ORIGIN (t) == NULL_TREE)
829 BLOCK_ABSTRACT_ORIGIN (t) = block;
830 return t;
831 }
832
833 /* Copy DECL_RTLs in all decls in the given BLOCK node. */
834
835 static void
836 copy_decl_rtls (block)
837 tree block;
838 {
839 tree t;
840
841 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
842 if (DECL_RTL (t) && GET_CODE (DECL_RTL (t)) == MEM)
843 DECL_RTL (t) = copy_for_inline (DECL_RTL (t));
844
845 /* Process all subblocks. */
846 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
847 copy_decl_rtls (t);
848 }
849
850 /* Make the insns and PARM_DECLs of the current function permanent
851 and record other information in DECL_SAVED_INSNS to allow inlining
852 of this function in subsequent calls.
853
854 This routine need not copy any insns because we are not going
855 to immediately compile the insns in the insn chain. There
856 are two cases when we would compile the insns for FNDECL:
857 (1) when FNDECL is expanded inline, and (2) when FNDECL needs to
858 be output at the end of other compilation, because somebody took
859 its address. In the first case, the insns of FNDECL are copied
860 as it is expanded inline, so FNDECL's saved insns are not
861 modified. In the second case, FNDECL is used for the last time,
862 so modifying the rtl is not a problem.
863
864 We don't have to worry about FNDECL being inline expanded by
865 other functions which are written at the end of compilation
866 because flag_no_inline is turned on when we begin writing
867 functions at the end of compilation. */
868
869 void
870 save_for_inline_nocopy (fndecl)
871 tree fndecl;
872 {
873 rtx insn;
874 rtx head;
875 rtx first_nonparm_insn;
876
877 /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
878 Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
879 Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
880 for the parms, prior to elimination of virtual registers.
881 These values are needed for substituting parms properly. */
882
883 parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
884
885 /* Make and emit a return-label if we have not already done so. */
886
887 if (return_label == 0)
888 {
889 return_label = gen_label_rtx ();
890 emit_label (return_label);
891 }
892
893 head = initialize_for_inline (fndecl, get_first_label_num (),
894 max_label_num (), max_reg_num (), 0);
895
896 /* If there are insns that copy parms from the stack into pseudo registers,
897 those insns are not copied. `expand_inline_function' must
898 emit the correct code to handle such things. */
899
900 insn = get_insns ();
901 if (GET_CODE (insn) != NOTE)
902 abort ();
903
904 /* Get the insn which signals the end of parameter setup code. */
905 first_nonparm_insn = get_first_nonparm_insn ();
906
907 /* Now just scan the chain of insns to see what happens to our
908 PARM_DECLs. If a PARM_DECL is used but never modified, we
909 can substitute its rtl directly when expanding inline (and
910 perform constant folding when its incoming value is constant).
911 Otherwise, we have to copy its value into a new register and track
912 the new register's life. */
913
914 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
915 {
916 if (insn == first_nonparm_insn)
917 in_nonparm_insns = 1;
918
919 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
920 {
921 if (current_function_uses_const_pool)
922 {
923 /* Replace any constant pool references with the actual constant.
924 We will put the constant back if we need to write the
925 function out after all. */
926 save_constants (&PATTERN (insn));
927 if (REG_NOTES (insn))
928 save_constants (&REG_NOTES (insn));
929 }
930
931 /* Record what interesting things happen to our parameters. */
932 note_stores (PATTERN (insn), note_modified_parmregs);
933 }
934 }
935
936 /* Also scan all decls, and replace any constant pool references with the
937 actual constant. */
938 save_constants_in_decl_trees (DECL_INITIAL (fndecl));
939
940 /* We have now allocated all that needs to be allocated permanently
941 on the rtx obstack. Set our high-water mark, so that we
942 can free the rest of this when the time comes. */
943
944 preserve_data ();
945
946 finish_inline (fndecl, head);
947 }
948 \f
949 /* Given PX, a pointer into an insn, search for references to the constant
950 pool. Replace each with a CONST that has the mode of the original
951 constant, contains the constant, and has RTX_INTEGRATED_P set.
952 Similarly, constant pool addresses not enclosed in a MEM are replaced
953 with an ADDRESS and CONST rtx which also gives the constant, its
954 mode, the mode of the address, and has RTX_INTEGRATED_P set. */
955
956 static void
957 save_constants (px)
958 rtx *px;
959 {
960 rtx x;
961 int i, j;
962
963 again:
964 x = *px;
965
966 /* If this is a CONST_DOUBLE, don't try to fix things up in
967 CONST_DOUBLE_MEM, because this is an infinite recursion. */
968 if (GET_CODE (x) == CONST_DOUBLE)
969 return;
970 else if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
971 && CONSTANT_POOL_ADDRESS_P (XEXP (x,0)))
972 {
973 enum machine_mode const_mode = get_pool_mode (XEXP (x, 0));
974 rtx new = gen_rtx_CONST (const_mode, get_pool_constant (XEXP (x, 0)));
975 RTX_INTEGRATED_P (new) = 1;
976
977 /* If the MEM was in a different mode than the constant (perhaps we
978 were only looking at the low-order part), surround it with a
979 SUBREG so we can save both modes. */
980
981 if (GET_MODE (x) != const_mode)
982 {
983 new = gen_rtx_SUBREG (GET_MODE (x), new, 0);
984 RTX_INTEGRATED_P (new) = 1;
985 }
986
987 *px = new;
988 save_constants (&XEXP (*px, 0));
989 }
990 else if (GET_CODE (x) == SYMBOL_REF
991 && CONSTANT_POOL_ADDRESS_P (x))
992 {
993 *px = gen_rtx_ADDRESS (GET_MODE (x),
994 gen_rtx_CONST (get_pool_mode (x),
995 get_pool_constant (x)));
996 save_constants (&XEXP (*px, 0));
997 RTX_INTEGRATED_P (*px) = 1;
998 }
999
1000 else
1001 {
1002 char *fmt = GET_RTX_FORMAT (GET_CODE (x));
1003 int len = GET_RTX_LENGTH (GET_CODE (x));
1004
1005 for (i = len-1; i >= 0; i--)
1006 {
1007 switch (fmt[i])
1008 {
1009 case 'E':
1010 for (j = 0; j < XVECLEN (x, i); j++)
1011 save_constants (&XVECEXP (x, i, j));
1012 break;
1013
1014 case 'e':
1015 if (XEXP (x, i) == 0)
1016 continue;
1017 if (i == 0)
1018 {
1019 /* Hack tail-recursion here. */
1020 px = &XEXP (x, 0);
1021 goto again;
1022 }
1023 save_constants (&XEXP (x, i));
1024 break;
1025 }
1026 }
1027 }
1028 }
1029 \f
1030 /* Note whether a parameter is modified or not. */
1031
1032 static void
1033 note_modified_parmregs (reg, x)
1034 rtx reg;
1035 rtx x ATTRIBUTE_UNUSED;
1036 {
1037 if (GET_CODE (reg) == REG && in_nonparm_insns
1038 && REGNO (reg) < max_parm_reg
1039 && REGNO (reg) >= FIRST_PSEUDO_REGISTER
1040 && parmdecl_map[REGNO (reg)] != 0)
1041 TREE_READONLY (parmdecl_map[REGNO (reg)]) = 0;
1042 }
1043
1044 /* Copy the rtx ORIG recursively, replacing pseudo-regs and labels
1045 according to `reg_map' and `label_map'. The original rtl insns
1046 will be saved for inlining; this is used to make a copy
1047 which is used to finish compiling the inline function itself.
1048
1049 If we find a "saved" constant pool entry, one which was replaced with
1050 the value of the constant, convert it back to a constant pool entry.
1051 Since the pool wasn't touched, this should simply restore the old
1052 address.
1053
1054 All other kinds of rtx are copied except those that can never be
1055 changed during compilation. */
1056
1057 static rtx
1058 copy_for_inline (orig)
1059 rtx orig;
1060 {
1061 register rtx x = orig;
1062 register rtx new;
1063 register int i;
1064 register enum rtx_code code;
1065 register char *format_ptr;
1066
1067 if (x == 0)
1068 return x;
1069
1070 code = GET_CODE (x);
1071
1072 /* These types may be freely shared. */
1073
1074 switch (code)
1075 {
1076 case QUEUED:
1077 case CONST_INT:
1078 case SYMBOL_REF:
1079 case PC:
1080 case CC0:
1081 return x;
1082
1083 case CONST_DOUBLE:
1084 /* We have to make a new CONST_DOUBLE to ensure that we account for
1085 it correctly. Using the old CONST_DOUBLE_MEM data is wrong. */
1086 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1087 {
1088 REAL_VALUE_TYPE d;
1089
1090 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1091 return CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (x));
1092 }
1093 else
1094 return immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
1095 VOIDmode);
1096
1097 case CONST:
1098 /* Get constant pool entry for constant in the pool. */
1099 if (RTX_INTEGRATED_P (x))
1100 return validize_mem (force_const_mem (GET_MODE (x),
1101 copy_for_inline (XEXP (x, 0))));
1102 break;
1103
1104 case SUBREG:
1105 /* Get constant pool entry, but access in different mode. */
1106 if (RTX_INTEGRATED_P (x))
1107 {
1108 new = force_const_mem (GET_MODE (SUBREG_REG (x)),
1109 copy_for_inline (XEXP (SUBREG_REG (x), 0)));
1110
1111 PUT_MODE (new, GET_MODE (x));
1112 return validize_mem (new);
1113 }
1114 break;
1115
1116 case ADDRESS:
1117 /* If not special for constant pool error. Else get constant pool
1118 address. */
1119 if (! RTX_INTEGRATED_P (x))
1120 abort ();
1121
1122 new = force_const_mem (GET_MODE (XEXP (x, 0)),
1123 copy_for_inline (XEXP (XEXP (x, 0), 0)));
1124 new = XEXP (new, 0);
1125
1126 #ifdef POINTERS_EXTEND_UNSIGNED
1127 if (GET_MODE (new) != GET_MODE (x))
1128 new = convert_memory_address (GET_MODE (x), new);
1129 #endif
1130
1131 return new;
1132
1133 case ASM_OPERANDS:
1134 /* If a single asm insn contains multiple output operands
1135 then it contains multiple ASM_OPERANDS rtx's that share operand 3.
1136 We must make sure that the copied insn continues to share it. */
1137 if (orig_asm_operands_vector == XVEC (orig, 3))
1138 {
1139 x = rtx_alloc (ASM_OPERANDS);
1140 x->volatil = orig->volatil;
1141 XSTR (x, 0) = XSTR (orig, 0);
1142 XSTR (x, 1) = XSTR (orig, 1);
1143 XINT (x, 2) = XINT (orig, 2);
1144 XVEC (x, 3) = copy_asm_operands_vector;
1145 XVEC (x, 4) = copy_asm_constraints_vector;
1146 XSTR (x, 5) = XSTR (orig, 5);
1147 XINT (x, 6) = XINT (orig, 6);
1148 return x;
1149 }
1150 break;
1151
1152 case MEM:
1153 /* A MEM is usually allowed to be shared if its address is constant
1154 or is a constant plus one of the special registers.
1155
1156 We do not allow sharing of addresses that are either a special
1157 register or the sum of a constant and a special register because
1158 it is possible for unshare_all_rtl to copy the address, into memory
1159 that won't be saved. Although the MEM can safely be shared, and
1160 won't be copied there, the address itself cannot be shared, and may
1161 need to be copied.
1162
1163 There are also two exceptions with constants: The first is if the
1164 constant is a LABEL_REF or the sum of the LABEL_REF
1165 and an integer. This case can happen if we have an inline
1166 function that supplies a constant operand to the call of another
1167 inline function that uses it in a switch statement. In this case,
1168 we will be replacing the LABEL_REF, so we have to replace this MEM
1169 as well.
1170
1171 The second case is if we have a (const (plus (address ..) ...)).
1172 In that case we need to put back the address of the constant pool
1173 entry. */
1174
1175 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1176 && GET_CODE (XEXP (x, 0)) != LABEL_REF
1177 && ! (GET_CODE (XEXP (x, 0)) == CONST
1178 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS
1179 && ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1180 == LABEL_REF)
1181 || (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1182 == ADDRESS)))))
1183 return x;
1184 break;
1185
1186 case LABEL_REF:
1187 /* If this is a non-local label, just make a new LABEL_REF.
1188 Otherwise, use the new label as well. */
1189 x = gen_rtx_LABEL_REF (GET_MODE (orig),
1190 LABEL_REF_NONLOCAL_P (orig) ? XEXP (orig, 0)
1191 : label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))]);
1192 LABEL_REF_NONLOCAL_P (x) = LABEL_REF_NONLOCAL_P (orig);
1193 LABEL_OUTSIDE_LOOP_P (x) = LABEL_OUTSIDE_LOOP_P (orig);
1194 return x;
1195
1196 case REG:
1197 if (REGNO (x) > LAST_VIRTUAL_REGISTER)
1198 return reg_map [REGNO (x)];
1199 else
1200 return x;
1201
1202 case SET:
1203 /* If a parm that gets modified lives in a pseudo-reg,
1204 clear its TREE_READONLY to prevent certain optimizations. */
1205 {
1206 rtx dest = SET_DEST (x);
1207
1208 while (GET_CODE (dest) == STRICT_LOW_PART
1209 || GET_CODE (dest) == ZERO_EXTRACT
1210 || GET_CODE (dest) == SUBREG)
1211 dest = XEXP (dest, 0);
1212
1213 if (GET_CODE (dest) == REG
1214 && REGNO (dest) < max_parm_reg
1215 && REGNO (dest) >= FIRST_PSEUDO_REGISTER
1216 && parmdecl_map[REGNO (dest)] != 0
1217 /* The insn to load an arg pseudo from a stack slot
1218 does not count as modifying it. */
1219 && in_nonparm_insns)
1220 TREE_READONLY (parmdecl_map[REGNO (dest)]) = 0;
1221 }
1222 break;
1223
1224 #if 0 /* This is a good idea, but here is the wrong place for it. */
1225 /* Arrange that CONST_INTs always appear as the second operand
1226 if they appear, and that `frame_pointer_rtx' or `arg_pointer_rtx'
1227 always appear as the first. */
1228 case PLUS:
1229 if (GET_CODE (XEXP (x, 0)) == CONST_INT
1230 || (XEXP (x, 1) == frame_pointer_rtx
1231 || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
1232 && XEXP (x, 1) == arg_pointer_rtx)))
1233 {
1234 rtx t = XEXP (x, 0);
1235 XEXP (x, 0) = XEXP (x, 1);
1236 XEXP (x, 1) = t;
1237 }
1238 break;
1239 #endif
1240 default:
1241 break;
1242 }
1243
1244 /* Replace this rtx with a copy of itself. */
1245
1246 x = rtx_alloc (code);
1247 bcopy ((char *) orig, (char *) x,
1248 (sizeof (*x) - sizeof (x->fld)
1249 + sizeof (x->fld[0]) * GET_RTX_LENGTH (code)));
1250
1251 /* Now scan the subexpressions recursively.
1252 We can store any replaced subexpressions directly into X
1253 since we know X is not shared! Any vectors in X
1254 must be copied if X was copied. */
1255
1256 format_ptr = GET_RTX_FORMAT (code);
1257
1258 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1259 {
1260 switch (*format_ptr++)
1261 {
1262 case 'e':
1263 XEXP (x, i) = copy_for_inline (XEXP (x, i));
1264 break;
1265
1266 case 'u':
1267 /* Change any references to old-insns to point to the
1268 corresponding copied insns. */
1269 XEXP (x, i) = insn_map[INSN_UID (XEXP (x, i))];
1270 break;
1271
1272 case 'E':
1273 if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
1274 {
1275 register int j;
1276
1277 XVEC (x, i) = gen_rtvec_vv (XVECLEN (x, i), XVEC (x, i)->elem);
1278 for (j = 0; j < XVECLEN (x, i); j++)
1279 XVECEXP (x, i, j)
1280 = copy_for_inline (XVECEXP (x, i, j));
1281 }
1282 break;
1283 }
1284 }
1285
1286 if (code == ASM_OPERANDS && orig_asm_operands_vector == 0)
1287 {
1288 orig_asm_operands_vector = XVEC (orig, 3);
1289 copy_asm_operands_vector = XVEC (x, 3);
1290 copy_asm_constraints_vector = XVEC (x, 4);
1291 }
1292
1293 return x;
1294 }
1295
1296 /* Unfortunately, we need a global copy of const_equiv map for communication
1297 with a function called from note_stores. Be *very* careful that this
1298 is used properly in the presence of recursion. */
1299
1300 rtx *global_const_equiv_map;
1301 int global_const_equiv_map_size;
1302 \f
1303 #define FIXED_BASE_PLUS_P(X) \
1304 (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
1305 && GET_CODE (XEXP (X, 0)) == REG \
1306 && REGNO (XEXP (X, 0)) >= FIRST_VIRTUAL_REGISTER \
1307 && REGNO (XEXP (X, 0)) <= LAST_VIRTUAL_REGISTER)
1308
1309 /* Called to set up a mapping for the case where a parameter is in a
1310 register. If it is read-only and our argument is a constant, set up the
1311 constant equivalence.
1312
1313 If LOC is REG_USERVAR_P, the usual case, COPY must also have that flag set
1314 if it is a register.
1315
1316 Also, don't allow hard registers here; they might not be valid when
1317 substituted into insns. */
1318 static void
1319 process_reg_param (map, loc, copy)
1320 struct inline_remap *map;
1321 rtx loc, copy;
1322 {
1323 if ((GET_CODE (copy) != REG && GET_CODE (copy) != SUBREG)
1324 || (GET_CODE (copy) == REG && REG_USERVAR_P (loc)
1325 && ! REG_USERVAR_P (copy))
1326 || (GET_CODE (copy) == REG
1327 && REGNO (copy) < FIRST_PSEUDO_REGISTER))
1328 {
1329 rtx temp = copy_to_mode_reg (GET_MODE (loc), copy);
1330 REG_USERVAR_P (temp) = REG_USERVAR_P (loc);
1331 if ((CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1332 && REGNO (temp) < map->const_equiv_map_size)
1333 {
1334 map->const_equiv_map[REGNO (temp)] = copy;
1335 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1336 }
1337 copy = temp;
1338 }
1339 map->reg_map[REGNO (loc)] = copy;
1340 }
1341 /* Integrate the procedure defined by FNDECL. Note that this function
1342 may wind up calling itself. Since the static variables are not
1343 reentrant, we do not assign them until after the possibility
1344 of recursion is eliminated.
1345
1346 If IGNORE is nonzero, do not produce a value.
1347 Otherwise store the value in TARGET if it is nonzero and that is convenient.
1348
1349 Value is:
1350 (rtx)-1 if we could not substitute the function
1351 0 if we substituted it and it does not produce a value
1352 else an rtx for where the value is stored. */
1353
1354 rtx
1355 expand_inline_function (fndecl, parms, target, ignore, type,
1356 structure_value_addr)
1357 tree fndecl, parms;
1358 rtx target;
1359 int ignore;
1360 tree type;
1361 rtx structure_value_addr;
1362 {
1363 tree formal, actual, block;
1364 rtx header = DECL_SAVED_INSNS (fndecl);
1365 rtx insns = FIRST_FUNCTION_INSN (header);
1366 rtx parm_insns = FIRST_PARM_INSN (header);
1367 tree *arg_trees;
1368 rtx *arg_vals;
1369 rtx insn;
1370 int max_regno;
1371 register int i;
1372 int min_labelno = FIRST_LABELNO (header);
1373 int max_labelno = LAST_LABELNO (header);
1374 int nargs;
1375 rtx local_return_label = 0;
1376 rtx loc;
1377 rtx stack_save = 0;
1378 rtx temp;
1379 struct inline_remap *map;
1380 #ifdef HAVE_cc0
1381 rtx cc0_insn = 0;
1382 #endif
1383 rtvec arg_vector = ORIGINAL_ARG_VECTOR (header);
1384 rtx static_chain_value = 0;
1385
1386 /* The pointer used to track the true location of the memory used
1387 for MAP->LABEL_MAP. */
1388 rtx *real_label_map = 0;
1389
1390 /* Allow for equivalences of the pseudos we make for virtual fp and ap. */
1391 max_regno = MAX_REGNUM (header) + 3;
1392 if (max_regno < FIRST_PSEUDO_REGISTER)
1393 abort ();
1394
1395 nargs = list_length (DECL_ARGUMENTS (fndecl));
1396
1397 /* Check that the parms type match and that sufficient arguments were
1398 passed. Since the appropriate conversions or default promotions have
1399 already been applied, the machine modes should match exactly. */
1400
1401 for (formal = DECL_ARGUMENTS (fndecl), actual = parms;
1402 formal;
1403 formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual))
1404 {
1405 tree arg;
1406 enum machine_mode mode;
1407
1408 if (actual == 0)
1409 return (rtx) (HOST_WIDE_INT) -1;
1410
1411 arg = TREE_VALUE (actual);
1412 mode = TYPE_MODE (DECL_ARG_TYPE (formal));
1413
1414 if (mode != TYPE_MODE (TREE_TYPE (arg))
1415 /* If they are block mode, the types should match exactly.
1416 They don't match exactly if TREE_TYPE (FORMAL) == ERROR_MARK_NODE,
1417 which could happen if the parameter has incomplete type. */
1418 || (mode == BLKmode
1419 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg))
1420 != TYPE_MAIN_VARIANT (TREE_TYPE (formal)))))
1421 return (rtx) (HOST_WIDE_INT) -1;
1422 }
1423
1424 /* Extra arguments are valid, but will be ignored below, so we must
1425 evaluate them here for side-effects. */
1426 for (; actual; actual = TREE_CHAIN (actual))
1427 expand_expr (TREE_VALUE (actual), const0_rtx,
1428 TYPE_MODE (TREE_TYPE (TREE_VALUE (actual))), 0);
1429
1430 /* Make a binding contour to keep inline cleanups called at
1431 outer function-scope level from looking like they are shadowing
1432 parameter declarations. */
1433 pushlevel (0);
1434
1435 /* Expand the function arguments. Do this first so that any
1436 new registers get created before we allocate the maps. */
1437
1438 arg_vals = (rtx *) alloca (nargs * sizeof (rtx));
1439 arg_trees = (tree *) alloca (nargs * sizeof (tree));
1440
1441 for (formal = DECL_ARGUMENTS (fndecl), actual = parms, i = 0;
1442 formal;
1443 formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual), i++)
1444 {
1445 /* Actual parameter, converted to the type of the argument within the
1446 function. */
1447 tree arg = convert (TREE_TYPE (formal), TREE_VALUE (actual));
1448 /* Mode of the variable used within the function. */
1449 enum machine_mode mode = TYPE_MODE (TREE_TYPE (formal));
1450 int invisiref = 0;
1451
1452 arg_trees[i] = arg;
1453 loc = RTVEC_ELT (arg_vector, i);
1454
1455 /* If this is an object passed by invisible reference, we copy the
1456 object into a stack slot and save its address. If this will go
1457 into memory, we do nothing now. Otherwise, we just expand the
1458 argument. */
1459 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1460 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1461 {
1462 rtx stack_slot
1463 = assign_stack_temp (TYPE_MODE (TREE_TYPE (arg)),
1464 int_size_in_bytes (TREE_TYPE (arg)), 1);
1465 MEM_IN_STRUCT_P (stack_slot) = AGGREGATE_TYPE_P (TREE_TYPE (arg));
1466
1467 store_expr (arg, stack_slot, 0);
1468
1469 arg_vals[i] = XEXP (stack_slot, 0);
1470 invisiref = 1;
1471 }
1472 else if (GET_CODE (loc) != MEM)
1473 {
1474 if (GET_MODE (loc) != TYPE_MODE (TREE_TYPE (arg)))
1475 /* The mode if LOC and ARG can differ if LOC was a variable
1476 that had its mode promoted via PROMOTED_MODE. */
1477 arg_vals[i] = convert_modes (GET_MODE (loc),
1478 TYPE_MODE (TREE_TYPE (arg)),
1479 expand_expr (arg, NULL_RTX, mode,
1480 EXPAND_SUM),
1481 TREE_UNSIGNED (TREE_TYPE (formal)));
1482 else
1483 arg_vals[i] = expand_expr (arg, NULL_RTX, mode, EXPAND_SUM);
1484 }
1485 else
1486 arg_vals[i] = 0;
1487
1488 if (arg_vals[i] != 0
1489 && (! TREE_READONLY (formal)
1490 /* If the parameter is not read-only, copy our argument through
1491 a register. Also, we cannot use ARG_VALS[I] if it overlaps
1492 TARGET in any way. In the inline function, they will likely
1493 be two different pseudos, and `safe_from_p' will make all
1494 sorts of smart assumptions about their not conflicting.
1495 But if ARG_VALS[I] overlaps TARGET, these assumptions are
1496 wrong, so put ARG_VALS[I] into a fresh register.
1497 Don't worry about invisible references, since their stack
1498 temps will never overlap the target. */
1499 || (target != 0
1500 && ! invisiref
1501 && (GET_CODE (arg_vals[i]) == REG
1502 || GET_CODE (arg_vals[i]) == SUBREG
1503 || GET_CODE (arg_vals[i]) == MEM)
1504 && reg_overlap_mentioned_p (arg_vals[i], target))
1505 /* ??? We must always copy a SUBREG into a REG, because it might
1506 get substituted into an address, and not all ports correctly
1507 handle SUBREGs in addresses. */
1508 || (GET_CODE (arg_vals[i]) == SUBREG)))
1509 arg_vals[i] = copy_to_mode_reg (GET_MODE (loc), arg_vals[i]);
1510
1511 if (arg_vals[i] != 0 && GET_CODE (arg_vals[i]) == REG
1512 && POINTER_TYPE_P (TREE_TYPE (formal)))
1513 mark_reg_pointer (arg_vals[i],
1514 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (formal)))
1515 / BITS_PER_UNIT));
1516 }
1517
1518 /* Allocate the structures we use to remap things. */
1519
1520 map = (struct inline_remap *) alloca (sizeof (struct inline_remap));
1521 map->fndecl = fndecl;
1522
1523 map->reg_map = (rtx *) alloca (max_regno * sizeof (rtx));
1524 bzero ((char *) map->reg_map, max_regno * sizeof (rtx));
1525
1526 /* We used to use alloca here, but the size of what it would try to
1527 allocate would occasionally cause it to exceed the stack limit and
1528 cause unpredictable core dumps. */
1529 real_label_map
1530 = (rtx *) xmalloc ((max_labelno) * sizeof (rtx));
1531 map->label_map = real_label_map;
1532
1533 map->insn_map = (rtx *) alloca (INSN_UID (header) * sizeof (rtx));
1534 bzero ((char *) map->insn_map, INSN_UID (header) * sizeof (rtx));
1535 map->min_insnno = 0;
1536 map->max_insnno = INSN_UID (header);
1537
1538 map->integrating = 1;
1539
1540 /* const_equiv_map maps pseudos in our routine to constants, so it needs to
1541 be large enough for all our pseudos. This is the number we are currently
1542 using plus the number in the called routine, plus 15 for each arg,
1543 five to compute the virtual frame pointer, and five for the return value.
1544 This should be enough for most cases. We do not reference entries
1545 outside the range of the map.
1546
1547 ??? These numbers are quite arbitrary and were obtained by
1548 experimentation. At some point, we should try to allocate the
1549 table after all the parameters are set up so we an more accurately
1550 estimate the number of pseudos we will need. */
1551
1552 map->const_equiv_map_size
1553 = max_reg_num () + (max_regno - FIRST_PSEUDO_REGISTER) + 15 * nargs + 10;
1554
1555 map->const_equiv_map
1556 = (rtx *)alloca (map->const_equiv_map_size * sizeof (rtx));
1557 bzero ((char *) map->const_equiv_map,
1558 map->const_equiv_map_size * sizeof (rtx));
1559
1560 map->const_age_map
1561 = (unsigned *)alloca (map->const_equiv_map_size * sizeof (unsigned));
1562 bzero ((char *) map->const_age_map,
1563 map->const_equiv_map_size * sizeof (unsigned));
1564 map->const_age = 0;
1565
1566 /* Record the current insn in case we have to set up pointers to frame
1567 and argument memory blocks. If there are no insns yet, add a dummy
1568 insn that can be used as an insertion point. */
1569 map->insns_at_start = get_last_insn ();
1570 if (map->insns_at_start == 0)
1571 map->insns_at_start = emit_note (NULL_PTR, NOTE_INSN_DELETED);
1572
1573 map->regno_pointer_flag = INLINE_REGNO_POINTER_FLAG (header);
1574 map->regno_pointer_align = INLINE_REGNO_POINTER_ALIGN (header);
1575
1576 /* Update the outgoing argument size to allow for those in the inlined
1577 function. */
1578 if (OUTGOING_ARGS_SIZE (header) > current_function_outgoing_args_size)
1579 current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (header);
1580
1581 /* If the inline function needs to make PIC references, that means
1582 that this function's PIC offset table must be used. */
1583 if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE)
1584 current_function_uses_pic_offset_table = 1;
1585
1586 /* If this function needs a context, set it up. */
1587 if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_NEEDS_CONTEXT)
1588 static_chain_value = lookup_static_chain (fndecl);
1589
1590 if (GET_CODE (parm_insns) == NOTE
1591 && NOTE_LINE_NUMBER (parm_insns) > 0)
1592 {
1593 rtx note = emit_note (NOTE_SOURCE_FILE (parm_insns),
1594 NOTE_LINE_NUMBER (parm_insns));
1595 if (note)
1596 RTX_INTEGRATED_P (note) = 1;
1597 }
1598
1599 /* Process each argument. For each, set up things so that the function's
1600 reference to the argument will refer to the argument being passed.
1601 We only replace REG with REG here. Any simplifications are done
1602 via const_equiv_map.
1603
1604 We make two passes: In the first, we deal with parameters that will
1605 be placed into registers, since we need to ensure that the allocated
1606 register number fits in const_equiv_map. Then we store all non-register
1607 parameters into their memory location. */
1608
1609 /* Don't try to free temp stack slots here, because we may put one of the
1610 parameters into a temp stack slot. */
1611
1612 for (i = 0; i < nargs; i++)
1613 {
1614 rtx copy = arg_vals[i];
1615
1616 loc = RTVEC_ELT (arg_vector, i);
1617
1618 /* There are three cases, each handled separately. */
1619 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1620 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1621 {
1622 /* This must be an object passed by invisible reference (it could
1623 also be a variable-sized object, but we forbid inlining functions
1624 with variable-sized arguments). COPY is the address of the
1625 actual value (this computation will cause it to be copied). We
1626 map that address for the register, noting the actual address as
1627 an equivalent in case it can be substituted into the insns. */
1628
1629 if (GET_CODE (copy) != REG)
1630 {
1631 temp = copy_addr_to_reg (copy);
1632 if ((CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1633 && REGNO (temp) < map->const_equiv_map_size)
1634 {
1635 map->const_equiv_map[REGNO (temp)] = copy;
1636 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1637 }
1638 copy = temp;
1639 }
1640 map->reg_map[REGNO (XEXP (loc, 0))] = copy;
1641 }
1642 else if (GET_CODE (loc) == MEM)
1643 {
1644 /* This is the case of a parameter that lives in memory.
1645 It will live in the block we allocate in the called routine's
1646 frame that simulates the incoming argument area. Do nothing
1647 now; we will call store_expr later. */
1648 ;
1649 }
1650 else if (GET_CODE (loc) == REG)
1651 process_reg_param (map, loc, copy);
1652 else if (GET_CODE (loc) == CONCAT)
1653 {
1654 rtx locreal = gen_realpart (GET_MODE (XEXP (loc, 0)), loc);
1655 rtx locimag = gen_imagpart (GET_MODE (XEXP (loc, 0)), loc);
1656 rtx copyreal = gen_realpart (GET_MODE (locreal), copy);
1657 rtx copyimag = gen_imagpart (GET_MODE (locimag), copy);
1658
1659 process_reg_param (map, locreal, copyreal);
1660 process_reg_param (map, locimag, copyimag);
1661 }
1662 else
1663 abort ();
1664 }
1665
1666 /* Now do the parameters that will be placed in memory. */
1667
1668 for (formal = DECL_ARGUMENTS (fndecl), i = 0;
1669 formal; formal = TREE_CHAIN (formal), i++)
1670 {
1671 loc = RTVEC_ELT (arg_vector, i);
1672
1673 if (GET_CODE (loc) == MEM
1674 /* Exclude case handled above. */
1675 && ! (GET_CODE (XEXP (loc, 0)) == REG
1676 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER))
1677 {
1678 rtx note = emit_note (DECL_SOURCE_FILE (formal),
1679 DECL_SOURCE_LINE (formal));
1680 if (note)
1681 RTX_INTEGRATED_P (note) = 1;
1682
1683 /* Compute the address in the area we reserved and store the
1684 value there. */
1685 temp = copy_rtx_and_substitute (loc, map);
1686 subst_constants (&temp, NULL_RTX, map);
1687 apply_change_group ();
1688 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
1689 temp = change_address (temp, VOIDmode, XEXP (temp, 0));
1690 store_expr (arg_trees[i], temp, 0);
1691 }
1692 }
1693
1694 /* Deal with the places that the function puts its result.
1695 We are driven by what is placed into DECL_RESULT.
1696
1697 Initially, we assume that we don't have anything special handling for
1698 REG_FUNCTION_RETURN_VALUE_P. */
1699
1700 map->inline_target = 0;
1701 loc = DECL_RTL (DECL_RESULT (fndecl));
1702 if (TYPE_MODE (type) == VOIDmode)
1703 /* There is no return value to worry about. */
1704 ;
1705 else if (GET_CODE (loc) == MEM)
1706 {
1707 if (! structure_value_addr || ! aggregate_value_p (DECL_RESULT (fndecl)))
1708 abort ();
1709
1710 /* Pass the function the address in which to return a structure value.
1711 Note that a constructor can cause someone to call us with
1712 STRUCTURE_VALUE_ADDR, but the initialization takes place
1713 via the first parameter, rather than the struct return address.
1714
1715 We have two cases: If the address is a simple register indirect,
1716 use the mapping mechanism to point that register to our structure
1717 return address. Otherwise, store the structure return value into
1718 the place that it will be referenced from. */
1719
1720 if (GET_CODE (XEXP (loc, 0)) == REG)
1721 {
1722 temp = force_reg (Pmode,
1723 force_operand (structure_value_addr, NULL_RTX));
1724 map->reg_map[REGNO (XEXP (loc, 0))] = temp;
1725 if ((CONSTANT_P (structure_value_addr)
1726 || GET_CODE (structure_value_addr) == ADDRESSOF
1727 || (GET_CODE (structure_value_addr) == PLUS
1728 && XEXP (structure_value_addr, 0) == virtual_stack_vars_rtx
1729 && GET_CODE (XEXP (structure_value_addr, 1)) == CONST_INT))
1730 && REGNO (temp) < map->const_equiv_map_size)
1731 {
1732 map->const_equiv_map[REGNO (temp)] = structure_value_addr;
1733 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1734 }
1735 }
1736 else
1737 {
1738 temp = copy_rtx_and_substitute (loc, map);
1739 subst_constants (&temp, NULL_RTX, map);
1740 apply_change_group ();
1741 emit_move_insn (temp, structure_value_addr);
1742 }
1743 }
1744 else if (ignore)
1745 /* We will ignore the result value, so don't look at its structure.
1746 Note that preparations for an aggregate return value
1747 do need to be made (above) even if it will be ignored. */
1748 ;
1749 else if (GET_CODE (loc) == REG)
1750 {
1751 /* The function returns an object in a register and we use the return
1752 value. Set up our target for remapping. */
1753
1754 /* Machine mode function was declared to return. */
1755 enum machine_mode departing_mode = TYPE_MODE (type);
1756 /* (Possibly wider) machine mode it actually computes
1757 (for the sake of callers that fail to declare it right).
1758 We have to use the mode of the result's RTL, rather than
1759 its type, since expand_function_start may have promoted it. */
1760 enum machine_mode arriving_mode
1761 = GET_MODE (DECL_RTL (DECL_RESULT (fndecl)));
1762 rtx reg_to_map;
1763
1764 /* Don't use MEMs as direct targets because on some machines
1765 substituting a MEM for a REG makes invalid insns.
1766 Let the combiner substitute the MEM if that is valid. */
1767 if (target == 0 || GET_CODE (target) != REG
1768 || GET_MODE (target) != departing_mode)
1769 {
1770 /* Don't make BLKmode registers. If this looks like
1771 a BLKmode object being returned in a register, get
1772 the mode from that, otherwise abort. */
1773 if (departing_mode == BLKmode)
1774 {
1775 if (REG == GET_CODE (DECL_RTL (DECL_RESULT (fndecl))))
1776 {
1777 departing_mode = GET_MODE (DECL_RTL (DECL_RESULT (fndecl)));
1778 arriving_mode = departing_mode;
1779 }
1780 else
1781 abort();
1782 }
1783
1784 target = gen_reg_rtx (departing_mode);
1785 }
1786
1787 /* If function's value was promoted before return,
1788 avoid machine mode mismatch when we substitute INLINE_TARGET.
1789 But TARGET is what we will return to the caller. */
1790 if (arriving_mode != departing_mode)
1791 {
1792 /* Avoid creating a paradoxical subreg wider than
1793 BITS_PER_WORD, since that is illegal. */
1794 if (GET_MODE_BITSIZE (arriving_mode) > BITS_PER_WORD)
1795 {
1796 if (!TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (departing_mode),
1797 GET_MODE_BITSIZE (arriving_mode)))
1798 /* Maybe could be handled by using convert_move () ? */
1799 abort ();
1800 reg_to_map = gen_reg_rtx (arriving_mode);
1801 target = gen_lowpart (departing_mode, reg_to_map);
1802 }
1803 else
1804 reg_to_map = gen_rtx_SUBREG (arriving_mode, target, 0);
1805 }
1806 else
1807 reg_to_map = target;
1808
1809 /* Usually, the result value is the machine's return register.
1810 Sometimes it may be a pseudo. Handle both cases. */
1811 if (REG_FUNCTION_VALUE_P (loc))
1812 map->inline_target = reg_to_map;
1813 else
1814 map->reg_map[REGNO (loc)] = reg_to_map;
1815 }
1816 else
1817 abort ();
1818
1819 /* Make a fresh binding contour that we can easily remove. Do this after
1820 expanding our arguments so cleanups are properly scoped. */
1821 pushlevel (0);
1822 expand_start_bindings (0);
1823
1824 /* Initialize label_map. get_label_from_map will actually make
1825 the labels. */
1826 bzero ((char *) &map->label_map [min_labelno],
1827 (max_labelno - min_labelno) * sizeof (rtx));
1828
1829 /* Perform postincrements before actually calling the function. */
1830 emit_queue ();
1831
1832 /* Clean up stack so that variables might have smaller offsets. */
1833 do_pending_stack_adjust ();
1834
1835 /* Save a copy of the location of const_equiv_map for mark_stores, called
1836 via note_stores. */
1837 global_const_equiv_map = map->const_equiv_map;
1838 global_const_equiv_map_size = map->const_equiv_map_size;
1839
1840 /* If the called function does an alloca, save and restore the
1841 stack pointer around the call. This saves stack space, but
1842 also is required if this inline is being done between two
1843 pushes. */
1844 if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_CALLS_ALLOCA)
1845 emit_stack_save (SAVE_BLOCK, &stack_save, NULL_RTX);
1846
1847 /* Now copy the insns one by one. Do this in two passes, first the insns and
1848 then their REG_NOTES, just like save_for_inline. */
1849
1850 /* This loop is very similar to the loop in copy_loop_body in unroll.c. */
1851
1852 for (insn = insns; insn; insn = NEXT_INSN (insn))
1853 {
1854 rtx copy, pattern, set;
1855
1856 map->orig_asm_operands_vector = 0;
1857
1858 switch (GET_CODE (insn))
1859 {
1860 case INSN:
1861 pattern = PATTERN (insn);
1862 set = single_set (insn);
1863 copy = 0;
1864 if (GET_CODE (pattern) == USE
1865 && GET_CODE (XEXP (pattern, 0)) == REG
1866 && REG_FUNCTION_VALUE_P (XEXP (pattern, 0)))
1867 /* The (USE (REG n)) at return from the function should
1868 be ignored since we are changing (REG n) into
1869 inline_target. */
1870 break;
1871
1872 /* If the inline fn needs eh context, make sure that
1873 the current fn has one. */
1874 if (GET_CODE (pattern) == USE
1875 && find_reg_note (insn, REG_EH_CONTEXT, 0) != 0)
1876 get_eh_context ();
1877
1878 /* Ignore setting a function value that we don't want to use. */
1879 if (map->inline_target == 0
1880 && set != 0
1881 && GET_CODE (SET_DEST (set)) == REG
1882 && REG_FUNCTION_VALUE_P (SET_DEST (set)))
1883 {
1884 if (volatile_refs_p (SET_SRC (set)))
1885 {
1886 rtx new_set;
1887
1888 /* If we must not delete the source,
1889 load it into a new temporary. */
1890 copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1891
1892 new_set = single_set (copy);
1893 if (new_set == 0)
1894 abort ();
1895
1896 SET_DEST (new_set)
1897 = gen_reg_rtx (GET_MODE (SET_DEST (new_set)));
1898 }
1899 /* If the source and destination are the same and it
1900 has a note on it, keep the insn. */
1901 else if (rtx_equal_p (SET_DEST (set), SET_SRC (set))
1902 && REG_NOTES (insn) != 0)
1903 copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1904 else
1905 break;
1906 }
1907
1908 /* If this is setting the static chain rtx, omit it. */
1909 else if (static_chain_value != 0
1910 && set != 0
1911 && GET_CODE (SET_DEST (set)) == REG
1912 && rtx_equal_p (SET_DEST (set),
1913 static_chain_incoming_rtx))
1914 break;
1915
1916 /* If this is setting the static chain pseudo, set it from
1917 the value we want to give it instead. */
1918 else if (static_chain_value != 0
1919 && set != 0
1920 && rtx_equal_p (SET_SRC (set),
1921 static_chain_incoming_rtx))
1922 {
1923 rtx newdest = copy_rtx_and_substitute (SET_DEST (set), map);
1924
1925 copy = emit_move_insn (newdest, static_chain_value);
1926 static_chain_value = 0;
1927 }
1928 else
1929 copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1930 /* REG_NOTES will be copied later. */
1931
1932 #ifdef HAVE_cc0
1933 /* If this insn is setting CC0, it may need to look at
1934 the insn that uses CC0 to see what type of insn it is.
1935 In that case, the call to recog via validate_change will
1936 fail. So don't substitute constants here. Instead,
1937 do it when we emit the following insn.
1938
1939 For example, see the pyr.md file. That machine has signed and
1940 unsigned compares. The compare patterns must check the
1941 following branch insn to see which what kind of compare to
1942 emit.
1943
1944 If the previous insn set CC0, substitute constants on it as
1945 well. */
1946 if (sets_cc0_p (PATTERN (copy)) != 0)
1947 cc0_insn = copy;
1948 else
1949 {
1950 if (cc0_insn)
1951 try_constants (cc0_insn, map);
1952 cc0_insn = 0;
1953 try_constants (copy, map);
1954 }
1955 #else
1956 try_constants (copy, map);
1957 #endif
1958 break;
1959
1960 case JUMP_INSN:
1961 if (GET_CODE (PATTERN (insn)) == RETURN
1962 || (GET_CODE (PATTERN (insn)) == PARALLEL
1963 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN))
1964 {
1965 if (local_return_label == 0)
1966 local_return_label = gen_label_rtx ();
1967 pattern = gen_jump (local_return_label);
1968 }
1969 else
1970 pattern = copy_rtx_and_substitute (PATTERN (insn), map);
1971
1972 copy = emit_jump_insn (pattern);
1973
1974 #ifdef HAVE_cc0
1975 if (cc0_insn)
1976 try_constants (cc0_insn, map);
1977 cc0_insn = 0;
1978 #endif
1979 try_constants (copy, map);
1980
1981 /* If this used to be a conditional jump insn but whose branch
1982 direction is now know, we must do something special. */
1983 if (condjump_p (insn) && ! simplejump_p (insn) && map->last_pc_value)
1984 {
1985 #ifdef HAVE_cc0
1986 /* The previous insn set cc0 for us. So delete it. */
1987 delete_insn (PREV_INSN (copy));
1988 #endif
1989
1990 /* If this is now a no-op, delete it. */
1991 if (map->last_pc_value == pc_rtx)
1992 {
1993 delete_insn (copy);
1994 copy = 0;
1995 }
1996 else
1997 /* Otherwise, this is unconditional jump so we must put a
1998 BARRIER after it. We could do some dead code elimination
1999 here, but jump.c will do it just as well. */
2000 emit_barrier ();
2001 }
2002 break;
2003
2004 case CALL_INSN:
2005 pattern = copy_rtx_and_substitute (PATTERN (insn), map);
2006 copy = emit_call_insn (pattern);
2007
2008 /* Because the USAGE information potentially contains objects other
2009 than hard registers, we need to copy it. */
2010 CALL_INSN_FUNCTION_USAGE (copy)
2011 = copy_rtx_and_substitute (CALL_INSN_FUNCTION_USAGE (insn), map);
2012
2013 #ifdef HAVE_cc0
2014 if (cc0_insn)
2015 try_constants (cc0_insn, map);
2016 cc0_insn = 0;
2017 #endif
2018 try_constants (copy, map);
2019
2020 /* Be lazy and assume CALL_INSNs clobber all hard registers. */
2021 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2022 map->const_equiv_map[i] = 0;
2023 break;
2024
2025 case CODE_LABEL:
2026 copy = emit_label (get_label_from_map (map,
2027 CODE_LABEL_NUMBER (insn)));
2028 LABEL_NAME (copy) = LABEL_NAME (insn);
2029 map->const_age++;
2030 break;
2031
2032 case BARRIER:
2033 copy = emit_barrier ();
2034 break;
2035
2036 case NOTE:
2037 /* It is important to discard function-end and function-beg notes,
2038 so we have only one of each in the current function.
2039 Also, NOTE_INSN_DELETED notes aren't useful (save_for_inline
2040 deleted these in the copy used for continuing compilation,
2041 not the copy used for inlining). */
2042 if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END
2043 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_BEG
2044 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
2045 {
2046 copy = emit_note (NOTE_SOURCE_FILE (insn),
2047 NOTE_LINE_NUMBER (insn));
2048 if (copy
2049 && (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG
2050 || NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_END))
2051 {
2052 rtx label
2053 = get_label_from_map (map, NOTE_BLOCK_NUMBER (copy));
2054
2055 /* we have to duplicate the handlers for the original */
2056 if (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG)
2057 {
2058 handler_info *ptr, *temp;
2059 int nr;
2060 nr = new_eh_region_entry (CODE_LABEL_NUMBER (label));
2061 ptr = get_first_handler (NOTE_BLOCK_NUMBER (copy));
2062 for ( ; ptr; ptr = ptr->next)
2063 {
2064 temp = get_new_handler ( get_label_from_map (map,
2065 CODE_LABEL_NUMBER (ptr->handler_label)),
2066 ptr->type_info);
2067 add_new_handler (nr, temp);
2068 }
2069 }
2070
2071 /* We have to forward these both to match the new exception
2072 region. */
2073 NOTE_BLOCK_NUMBER (copy) = CODE_LABEL_NUMBER (label);
2074 }
2075 }
2076 else
2077 copy = 0;
2078 break;
2079
2080 default:
2081 abort ();
2082 break;
2083 }
2084
2085 if (copy)
2086 RTX_INTEGRATED_P (copy) = 1;
2087
2088 map->insn_map[INSN_UID (insn)] = copy;
2089 }
2090
2091 /* Now copy the REG_NOTES. Increment const_age, so that only constants
2092 from parameters can be substituted in. These are the only ones that
2093 are valid across the entire function. */
2094 map->const_age++;
2095 for (insn = insns; insn; insn = NEXT_INSN (insn))
2096 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2097 && map->insn_map[INSN_UID (insn)]
2098 && REG_NOTES (insn))
2099 {
2100 rtx tem = copy_rtx_and_substitute (REG_NOTES (insn), map);
2101 /* We must also do subst_constants, in case one of our parameters
2102 has const type and constant value. */
2103 subst_constants (&tem, NULL_RTX, map);
2104 apply_change_group ();
2105 REG_NOTES (map->insn_map[INSN_UID (insn)]) = tem;
2106 }
2107
2108 if (local_return_label)
2109 emit_label (local_return_label);
2110
2111 /* Restore the stack pointer if we saved it above. */
2112 if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_CALLS_ALLOCA)
2113 emit_stack_restore (SAVE_BLOCK, stack_save, NULL_RTX);
2114
2115 /* Make copies of the decls of the symbols in the inline function, so that
2116 the copies of the variables get declared in the current function. Set
2117 up things so that lookup_static_chain knows that to interpret registers
2118 in SAVE_EXPRs for TYPE_SIZEs as local. */
2119
2120 inline_function_decl = fndecl;
2121 integrate_parm_decls (DECL_ARGUMENTS (fndecl), map, arg_vector);
2122 integrate_decl_tree ((tree) ORIGINAL_DECL_INITIAL (header), 0, map);
2123 inline_function_decl = 0;
2124
2125 /* End the scope containing the copied formal parameter variables
2126 and copied LABEL_DECLs. */
2127
2128 expand_end_bindings (getdecls (), 1, 1);
2129 block = poplevel (1, 1, 0);
2130 BLOCK_ABSTRACT_ORIGIN (block) = (DECL_ABSTRACT_ORIGIN (fndecl) == NULL
2131 ? fndecl : DECL_ABSTRACT_ORIGIN (fndecl));
2132 poplevel (0, 0, 0);
2133
2134 /* Must mark the line number note after inlined functions as a repeat, so
2135 that the test coverage code can avoid counting the call twice. This
2136 just tells the code to ignore the immediately following line note, since
2137 there already exists a copy of this note before the expanded inline call.
2138 This line number note is still needed for debugging though, so we can't
2139 delete it. */
2140 if (flag_test_coverage)
2141 emit_note (0, NOTE_REPEATED_LINE_NUMBER);
2142
2143 emit_line_note (input_filename, lineno);
2144
2145 /* If the function returns a BLKmode object in a register, copy it
2146 out of the temp register into a BLKmode memory object. */
2147 if (TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == BLKmode
2148 && ! aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl))))
2149 target = copy_blkmode_from_reg (0, target, TREE_TYPE (TREE_TYPE (fndecl)));
2150
2151 if (structure_value_addr)
2152 {
2153 target = gen_rtx_MEM (TYPE_MODE (type),
2154 memory_address (TYPE_MODE (type),
2155 structure_value_addr));
2156 MEM_IN_STRUCT_P (target) = 1;
2157 }
2158
2159 /* Make sure we free the things we explicitly allocated with xmalloc. */
2160 if (real_label_map)
2161 free (real_label_map);
2162
2163 return target;
2164 }
2165 \f
2166 /* Given a chain of PARM_DECLs, ARGS, copy each decl into a VAR_DECL,
2167 push all of those decls and give each one the corresponding home. */
2168
2169 static void
2170 integrate_parm_decls (args, map, arg_vector)
2171 tree args;
2172 struct inline_remap *map;
2173 rtvec arg_vector;
2174 {
2175 register tree tail;
2176 register int i;
2177
2178 for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
2179 {
2180 register tree decl = build_decl (VAR_DECL, DECL_NAME (tail),
2181 TREE_TYPE (tail));
2182 rtx new_decl_rtl
2183 = copy_rtx_and_substitute (RTVEC_ELT (arg_vector, i), map);
2184
2185 DECL_ARG_TYPE (decl) = DECL_ARG_TYPE (tail);
2186 /* We really should be setting DECL_INCOMING_RTL to something reasonable
2187 here, but that's going to require some more work. */
2188 /* DECL_INCOMING_RTL (decl) = ?; */
2189 /* These args would always appear unused, if not for this. */
2190 TREE_USED (decl) = 1;
2191 /* Prevent warning for shadowing with these. */
2192 DECL_ABSTRACT_ORIGIN (decl) = DECL_ORIGIN (tail);
2193 pushdecl (decl);
2194 /* Fully instantiate the address with the equivalent form so that the
2195 debugging information contains the actual register, instead of the
2196 virtual register. Do this by not passing an insn to
2197 subst_constants. */
2198 subst_constants (&new_decl_rtl, NULL_RTX, map);
2199 apply_change_group ();
2200 DECL_RTL (decl) = new_decl_rtl;
2201 }
2202 }
2203
2204 /* Given a BLOCK node LET, push decls and levels so as to construct in the
2205 current function a tree of contexts isomorphic to the one that is given.
2206
2207 LEVEL indicates how far down into the BLOCK tree is the node we are
2208 currently traversing. It is always zero except for recursive calls.
2209
2210 MAP, if nonzero, is a pointer to an inline_remap map which indicates how
2211 registers used in the DECL_RTL field should be remapped. If it is zero,
2212 no mapping is necessary. */
2213
2214 static void
2215 integrate_decl_tree (let, level, map)
2216 tree let;
2217 int level;
2218 struct inline_remap *map;
2219 {
2220 tree t, node;
2221
2222 if (level > 0)
2223 pushlevel (0);
2224
2225 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2226 {
2227 tree d;
2228
2229 push_obstacks_nochange ();
2230 saveable_allocation ();
2231 d = copy_and_set_decl_abstract_origin (t);
2232 pop_obstacks ();
2233
2234 if (DECL_RTL (t) != 0)
2235 {
2236 DECL_RTL (d) = copy_rtx_and_substitute (DECL_RTL (t), map);
2237 /* Fully instantiate the address with the equivalent form so that the
2238 debugging information contains the actual register, instead of the
2239 virtual register. Do this by not passing an insn to
2240 subst_constants. */
2241 subst_constants (&DECL_RTL (d), NULL_RTX, map);
2242 apply_change_group ();
2243 }
2244 /* These args would always appear unused, if not for this. */
2245 TREE_USED (d) = 1;
2246
2247 if (DECL_LANG_SPECIFIC (d))
2248 copy_lang_decl (d);
2249
2250 pushdecl (d);
2251 }
2252
2253 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2254 integrate_decl_tree (t, level + 1, map);
2255
2256 if (level > 0)
2257 {
2258 node = poplevel (1, 0, 0);
2259 if (node)
2260 {
2261 TREE_USED (node) = TREE_USED (let);
2262 BLOCK_ABSTRACT_ORIGIN (node) = let;
2263 }
2264 }
2265 }
2266
2267 /* Given a BLOCK node LET, search for all DECL_RTL fields, and pass them
2268 through save_constants. */
2269
2270 static void
2271 save_constants_in_decl_trees (let)
2272 tree let;
2273 {
2274 tree t;
2275
2276 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2277 if (DECL_RTL (t) != 0)
2278 save_constants (&DECL_RTL (t));
2279
2280 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2281 save_constants_in_decl_trees (t);
2282 }
2283 \f
2284 /* Create a new copy of an rtx.
2285 Recursively copies the operands of the rtx,
2286 except for those few rtx codes that are sharable.
2287
2288 We always return an rtx that is similar to that incoming rtx, with the
2289 exception of possibly changing a REG to a SUBREG or vice versa. No
2290 rtl is ever emitted.
2291
2292 Handle constants that need to be placed in the constant pool by
2293 calling `force_const_mem'. */
2294
2295 rtx
2296 copy_rtx_and_substitute (orig, map)
2297 register rtx orig;
2298 struct inline_remap *map;
2299 {
2300 register rtx copy, temp;
2301 register int i, j;
2302 register RTX_CODE code;
2303 register enum machine_mode mode;
2304 register char *format_ptr;
2305 int regno;
2306
2307 if (orig == 0)
2308 return 0;
2309
2310 code = GET_CODE (orig);
2311 mode = GET_MODE (orig);
2312
2313 switch (code)
2314 {
2315 case REG:
2316 /* If the stack pointer register shows up, it must be part of
2317 stack-adjustments (*not* because we eliminated the frame pointer!).
2318 Small hard registers are returned as-is. Pseudo-registers
2319 go through their `reg_map'. */
2320 regno = REGNO (orig);
2321 if (regno <= LAST_VIRTUAL_REGISTER)
2322 {
2323 /* Some hard registers are also mapped,
2324 but others are not translated. */
2325 if (map->reg_map[regno] != 0)
2326 return map->reg_map[regno];
2327
2328 /* If this is the virtual frame pointer, make space in current
2329 function's stack frame for the stack frame of the inline function.
2330
2331 Copy the address of this area into a pseudo. Map
2332 virtual_stack_vars_rtx to this pseudo and set up a constant
2333 equivalence for it to be the address. This will substitute the
2334 address into insns where it can be substituted and use the new
2335 pseudo where it can't. */
2336 if (regno == VIRTUAL_STACK_VARS_REGNUM)
2337 {
2338 rtx loc, seq;
2339 int size = DECL_FRAME_SIZE (map->fndecl);
2340
2341 #ifdef FRAME_GROWS_DOWNWARD
2342 /* In this case, virtual_stack_vars_rtx points to one byte
2343 higher than the top of the frame area. So make sure we
2344 allocate a big enough chunk to keep the frame pointer
2345 aligned like a real one. */
2346 size = CEIL_ROUND (size, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2347 #endif
2348 start_sequence ();
2349 loc = assign_stack_temp (BLKmode, size, 1);
2350 loc = XEXP (loc, 0);
2351 #ifdef FRAME_GROWS_DOWNWARD
2352 /* In this case, virtual_stack_vars_rtx points to one byte
2353 higher than the top of the frame area. So compute the offset
2354 to one byte higher than our substitute frame. */
2355 loc = plus_constant (loc, size);
2356 #endif
2357 map->reg_map[regno] = temp
2358 = force_reg (Pmode, force_operand (loc, NULL_RTX));
2359
2360 #ifdef STACK_BOUNDARY
2361 mark_reg_pointer (map->reg_map[regno],
2362 STACK_BOUNDARY / BITS_PER_UNIT);
2363 #endif
2364
2365 if (REGNO (temp) < map->const_equiv_map_size)
2366 {
2367 map->const_equiv_map[REGNO (temp)] = loc;
2368 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
2369 }
2370
2371 seq = gen_sequence ();
2372 end_sequence ();
2373 emit_insn_after (seq, map->insns_at_start);
2374 return temp;
2375 }
2376 else if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
2377 {
2378 /* Do the same for a block to contain any arguments referenced
2379 in memory. */
2380 rtx loc, seq;
2381 int size = FUNCTION_ARGS_SIZE (DECL_SAVED_INSNS (map->fndecl));
2382
2383 start_sequence ();
2384 loc = assign_stack_temp (BLKmode, size, 1);
2385 loc = XEXP (loc, 0);
2386 /* When arguments grow downward, the virtual incoming
2387 args pointer points to the top of the argument block,
2388 so the remapped location better do the same. */
2389 #ifdef ARGS_GROW_DOWNWARD
2390 loc = plus_constant (loc, size);
2391 #endif
2392 map->reg_map[regno] = temp
2393 = force_reg (Pmode, force_operand (loc, NULL_RTX));
2394
2395 #ifdef STACK_BOUNDARY
2396 mark_reg_pointer (map->reg_map[regno],
2397 STACK_BOUNDARY / BITS_PER_UNIT);
2398 #endif
2399
2400 if (REGNO (temp) < map->const_equiv_map_size)
2401 {
2402 map->const_equiv_map[REGNO (temp)] = loc;
2403 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
2404 }
2405
2406 seq = gen_sequence ();
2407 end_sequence ();
2408 emit_insn_after (seq, map->insns_at_start);
2409 return temp;
2410 }
2411 else if (REG_FUNCTION_VALUE_P (orig))
2412 {
2413 /* This is a reference to the function return value. If
2414 the function doesn't have a return value, error. If the
2415 mode doesn't agree, and it ain't BLKmode, make a SUBREG. */
2416 if (map->inline_target == 0)
2417 /* Must be unrolling loops or replicating code if we
2418 reach here, so return the register unchanged. */
2419 return orig;
2420 else if (GET_MODE (map->inline_target) != BLKmode
2421 && mode != GET_MODE (map->inline_target))
2422 return gen_lowpart (mode, map->inline_target);
2423 else
2424 return map->inline_target;
2425 }
2426 return orig;
2427 }
2428 if (map->reg_map[regno] == NULL)
2429 {
2430 map->reg_map[regno] = gen_reg_rtx (mode);
2431 REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (orig);
2432 REG_LOOP_TEST_P (map->reg_map[regno]) = REG_LOOP_TEST_P (orig);
2433 RTX_UNCHANGING_P (map->reg_map[regno]) = RTX_UNCHANGING_P (orig);
2434 /* A reg with REG_FUNCTION_VALUE_P true will never reach here. */
2435
2436 if (map->regno_pointer_flag[regno])
2437 mark_reg_pointer (map->reg_map[regno],
2438 map->regno_pointer_align[regno]);
2439 }
2440 return map->reg_map[regno];
2441
2442 case SUBREG:
2443 copy = copy_rtx_and_substitute (SUBREG_REG (orig), map);
2444 /* SUBREG is ordinary, but don't make nested SUBREGs. */
2445 if (GET_CODE (copy) == SUBREG)
2446 return gen_rtx_SUBREG (GET_MODE (orig), SUBREG_REG (copy),
2447 SUBREG_WORD (orig) + SUBREG_WORD (copy));
2448 else if (GET_CODE (copy) == CONCAT)
2449 return (subreg_realpart_p (orig) ? XEXP (copy, 0) : XEXP (copy, 1));
2450 else
2451 return gen_rtx_SUBREG (GET_MODE (orig), copy,
2452 SUBREG_WORD (orig));
2453
2454 case ADDRESSOF:
2455 copy = gen_rtx_ADDRESSOF (mode,
2456 copy_rtx_and_substitute (XEXP (orig, 0), map), 0);
2457 SET_ADDRESSOF_DECL (copy, ADDRESSOF_DECL (orig));
2458 regno = ADDRESSOF_REGNO (orig);
2459 if (map->reg_map[regno])
2460 regno = REGNO (map->reg_map[regno]);
2461 else if (regno > LAST_VIRTUAL_REGISTER)
2462 {
2463 temp = XEXP (orig, 0);
2464 map->reg_map[regno] = gen_reg_rtx (GET_MODE (temp));
2465 REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (temp);
2466 REG_LOOP_TEST_P (map->reg_map[regno]) = REG_LOOP_TEST_P (temp);
2467 RTX_UNCHANGING_P (map->reg_map[regno]) = RTX_UNCHANGING_P (temp);
2468 /* A reg with REG_FUNCTION_VALUE_P true will never reach here. */
2469
2470 if (map->regno_pointer_flag[regno])
2471 mark_reg_pointer (map->reg_map[regno],
2472 map->regno_pointer_align[regno]);
2473 regno = REGNO (map->reg_map[regno]);
2474 }
2475 ADDRESSOF_REGNO (copy) = regno;
2476 return copy;
2477
2478 case USE:
2479 case CLOBBER:
2480 /* USE and CLOBBER are ordinary, but we convert (use (subreg foo))
2481 to (use foo) if the original insn didn't have a subreg.
2482 Removing the subreg distorts the VAX movstrhi pattern
2483 by changing the mode of an operand. */
2484 copy = copy_rtx_and_substitute (XEXP (orig, 0), map);
2485 if (GET_CODE (copy) == SUBREG && GET_CODE (XEXP (orig, 0)) != SUBREG)
2486 copy = SUBREG_REG (copy);
2487 return gen_rtx_fmt_e (code, VOIDmode, copy);
2488
2489 case CODE_LABEL:
2490 LABEL_PRESERVE_P (get_label_from_map (map, CODE_LABEL_NUMBER (orig)))
2491 = LABEL_PRESERVE_P (orig);
2492 return get_label_from_map (map, CODE_LABEL_NUMBER (orig));
2493
2494 case LABEL_REF:
2495 copy = gen_rtx_LABEL_REF (mode,
2496 LABEL_REF_NONLOCAL_P (orig) ? XEXP (orig, 0)
2497 : get_label_from_map (map,
2498 CODE_LABEL_NUMBER (XEXP (orig, 0))));
2499 LABEL_OUTSIDE_LOOP_P (copy) = LABEL_OUTSIDE_LOOP_P (orig);
2500
2501 /* The fact that this label was previously nonlocal does not mean
2502 it still is, so we must check if it is within the range of
2503 this function's labels. */
2504 LABEL_REF_NONLOCAL_P (copy)
2505 = (LABEL_REF_NONLOCAL_P (orig)
2506 && ! (CODE_LABEL_NUMBER (XEXP (copy, 0)) >= get_first_label_num ()
2507 && CODE_LABEL_NUMBER (XEXP (copy, 0)) < max_label_num ()));
2508
2509 /* If we have made a nonlocal label local, it means that this
2510 inlined call will be referring to our nonlocal goto handler.
2511 So make sure we create one for this block; we normally would
2512 not since this is not otherwise considered a "call". */
2513 if (LABEL_REF_NONLOCAL_P (orig) && ! LABEL_REF_NONLOCAL_P (copy))
2514 function_call_count++;
2515
2516 return copy;
2517
2518 case PC:
2519 case CC0:
2520 case CONST_INT:
2521 return orig;
2522
2523 case SYMBOL_REF:
2524 /* Symbols which represent the address of a label stored in the constant
2525 pool must be modified to point to a constant pool entry for the
2526 remapped label. Otherwise, symbols are returned unchanged. */
2527 if (CONSTANT_POOL_ADDRESS_P (orig))
2528 {
2529 rtx constant = get_pool_constant (orig);
2530 if (GET_CODE (constant) == LABEL_REF)
2531 return XEXP (force_const_mem (GET_MODE (orig),
2532 copy_rtx_and_substitute (constant,
2533 map)),
2534 0);
2535 }
2536
2537 return orig;
2538
2539 case CONST_DOUBLE:
2540 /* We have to make a new copy of this CONST_DOUBLE because don't want
2541 to use the old value of CONST_DOUBLE_MEM. Also, this may be a
2542 duplicate of a CONST_DOUBLE we have already seen. */
2543 if (GET_MODE_CLASS (GET_MODE (orig)) == MODE_FLOAT)
2544 {
2545 REAL_VALUE_TYPE d;
2546
2547 REAL_VALUE_FROM_CONST_DOUBLE (d, orig);
2548 return CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (orig));
2549 }
2550 else
2551 return immed_double_const (CONST_DOUBLE_LOW (orig),
2552 CONST_DOUBLE_HIGH (orig), VOIDmode);
2553
2554 case CONST:
2555 /* Make new constant pool entry for a constant
2556 that was in the pool of the inline function. */
2557 if (RTX_INTEGRATED_P (orig))
2558 {
2559 /* If this was an address of a constant pool entry that itself
2560 had to be placed in the constant pool, it might not be a
2561 valid address. So the recursive call below might turn it
2562 into a register. In that case, it isn't a constant any
2563 more, so return it. This has the potential of changing a
2564 MEM into a REG, but we'll assume that it safe. */
2565 temp = copy_rtx_and_substitute (XEXP (orig, 0), map);
2566 if (! CONSTANT_P (temp))
2567 return temp;
2568 return validize_mem (force_const_mem (GET_MODE (orig), temp));
2569 }
2570 break;
2571
2572 case ADDRESS:
2573 /* If from constant pool address, make new constant pool entry and
2574 return its address. */
2575 if (! RTX_INTEGRATED_P (orig))
2576 abort ();
2577
2578 temp
2579 = force_const_mem (GET_MODE (XEXP (orig, 0)),
2580 copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0),
2581 map));
2582
2583 #if 0
2584 /* Legitimizing the address here is incorrect.
2585
2586 The only ADDRESS rtx's that can reach here are ones created by
2587 save_constants. Hence the operand of the ADDRESS is always valid
2588 in this position of the instruction, since the original rtx without
2589 the ADDRESS was valid.
2590
2591 The reason we don't legitimize the address here is that on the
2592 Sparc, the caller may have a (high ...) surrounding this ADDRESS.
2593 This code forces the operand of the address to a register, which
2594 fails because we can not take the HIGH part of a register.
2595
2596 Also, change_address may create new registers. These registers
2597 will not have valid reg_map entries. This can cause try_constants()
2598 to fail because assumes that all registers in the rtx have valid
2599 reg_map entries, and it may end up replacing one of these new
2600 registers with junk. */
2601
2602 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
2603 temp = change_address (temp, GET_MODE (temp), XEXP (temp, 0));
2604 #endif
2605
2606 temp = XEXP (temp, 0);
2607
2608 #ifdef POINTERS_EXTEND_UNSIGNED
2609 if (GET_MODE (temp) != GET_MODE (orig))
2610 temp = convert_memory_address (GET_MODE (orig), temp);
2611 #endif
2612
2613 return temp;
2614
2615 case ASM_OPERANDS:
2616 /* If a single asm insn contains multiple output operands
2617 then it contains multiple ASM_OPERANDS rtx's that share operand 3.
2618 We must make sure that the copied insn continues to share it. */
2619 if (map->orig_asm_operands_vector == XVEC (orig, 3))
2620 {
2621 copy = rtx_alloc (ASM_OPERANDS);
2622 copy->volatil = orig->volatil;
2623 XSTR (copy, 0) = XSTR (orig, 0);
2624 XSTR (copy, 1) = XSTR (orig, 1);
2625 XINT (copy, 2) = XINT (orig, 2);
2626 XVEC (copy, 3) = map->copy_asm_operands_vector;
2627 XVEC (copy, 4) = map->copy_asm_constraints_vector;
2628 XSTR (copy, 5) = XSTR (orig, 5);
2629 XINT (copy, 6) = XINT (orig, 6);
2630 return copy;
2631 }
2632 break;
2633
2634 case CALL:
2635 /* This is given special treatment because the first
2636 operand of a CALL is a (MEM ...) which may get
2637 forced into a register for cse. This is undesirable
2638 if function-address cse isn't wanted or if we won't do cse. */
2639 #ifndef NO_FUNCTION_CSE
2640 if (! (optimize && ! flag_no_function_cse))
2641 #endif
2642 return gen_rtx_CALL (GET_MODE (orig),
2643 gen_rtx_MEM (GET_MODE (XEXP (orig, 0)),
2644 copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0), map)),
2645 copy_rtx_and_substitute (XEXP (orig, 1), map));
2646 break;
2647
2648 #if 0
2649 /* Must be ifdefed out for loop unrolling to work. */
2650 case RETURN:
2651 abort ();
2652 #endif
2653
2654 case SET:
2655 /* If this is setting fp or ap, it means that we have a nonlocal goto.
2656 Adjust the setting by the offset of the area we made.
2657 If the nonlocal goto is into the current function,
2658 this will result in unnecessarily bad code, but should work. */
2659 if (SET_DEST (orig) == virtual_stack_vars_rtx
2660 || SET_DEST (orig) == virtual_incoming_args_rtx)
2661 {
2662 /* In case a translation hasn't occurred already, make one now. */
2663 rtx equiv_reg;
2664 rtx equiv_loc;
2665 HOST_WIDE_INT loc_offset;
2666
2667 copy_rtx_and_substitute (SET_DEST (orig), map);
2668 equiv_reg = map->reg_map[REGNO (SET_DEST (orig))];
2669 equiv_loc = map->const_equiv_map[REGNO (equiv_reg)];
2670 loc_offset
2671 = GET_CODE (equiv_loc) == REG ? 0 : INTVAL (XEXP (equiv_loc, 1));
2672 return gen_rtx_SET (VOIDmode, SET_DEST (orig),
2673 force_operand
2674 (plus_constant
2675 (copy_rtx_and_substitute (SET_SRC (orig), map),
2676 - loc_offset),
2677 NULL_RTX));
2678 }
2679 break;
2680
2681 case MEM:
2682 copy = rtx_alloc (MEM);
2683 PUT_MODE (copy, mode);
2684 XEXP (copy, 0) = copy_rtx_and_substitute (XEXP (orig, 0), map);
2685 MEM_IN_STRUCT_P (copy) = MEM_IN_STRUCT_P (orig);
2686 MEM_VOLATILE_P (copy) = MEM_VOLATILE_P (orig);
2687 MEM_ALIAS_SET (copy) = MEM_ALIAS_SET (orig);
2688
2689 /* If doing function inlining, this MEM might not be const in the
2690 function that it is being inlined into, and thus may not be
2691 unchanging after function inlining. Constant pool references are
2692 handled elsewhere, so this doesn't lose RTX_UNCHANGING_P bits
2693 for them. */
2694 if (! map->integrating)
2695 RTX_UNCHANGING_P (copy) = RTX_UNCHANGING_P (orig);
2696
2697 return copy;
2698
2699 default:
2700 break;
2701 }
2702
2703 copy = rtx_alloc (code);
2704 PUT_MODE (copy, mode);
2705 copy->in_struct = orig->in_struct;
2706 copy->volatil = orig->volatil;
2707 copy->unchanging = orig->unchanging;
2708
2709 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
2710
2711 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
2712 {
2713 switch (*format_ptr++)
2714 {
2715 case '0':
2716 XEXP (copy, i) = XEXP (orig, i);
2717 break;
2718
2719 case 'e':
2720 XEXP (copy, i) = copy_rtx_and_substitute (XEXP (orig, i), map);
2721 break;
2722
2723 case 'u':
2724 /* Change any references to old-insns to point to the
2725 corresponding copied insns. */
2726 XEXP (copy, i) = map->insn_map[INSN_UID (XEXP (orig, i))];
2727 break;
2728
2729 case 'E':
2730 XVEC (copy, i) = XVEC (orig, i);
2731 if (XVEC (orig, i) != NULL && XVECLEN (orig, i) != 0)
2732 {
2733 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
2734 for (j = 0; j < XVECLEN (copy, i); j++)
2735 XVECEXP (copy, i, j)
2736 = copy_rtx_and_substitute (XVECEXP (orig, i, j), map);
2737 }
2738 break;
2739
2740 case 'w':
2741 XWINT (copy, i) = XWINT (orig, i);
2742 break;
2743
2744 case 'i':
2745 XINT (copy, i) = XINT (orig, i);
2746 break;
2747
2748 case 's':
2749 XSTR (copy, i) = XSTR (orig, i);
2750 break;
2751
2752 default:
2753 abort ();
2754 }
2755 }
2756
2757 if (code == ASM_OPERANDS && map->orig_asm_operands_vector == 0)
2758 {
2759 map->orig_asm_operands_vector = XVEC (orig, 3);
2760 map->copy_asm_operands_vector = XVEC (copy, 3);
2761 map->copy_asm_constraints_vector = XVEC (copy, 4);
2762 }
2763
2764 return copy;
2765 }
2766 \f
2767 /* Substitute known constant values into INSN, if that is valid. */
2768
2769 void
2770 try_constants (insn, map)
2771 rtx insn;
2772 struct inline_remap *map;
2773 {
2774 int i;
2775
2776 map->num_sets = 0;
2777 subst_constants (&PATTERN (insn), insn, map);
2778
2779 /* Apply the changes if they are valid; otherwise discard them. */
2780 apply_change_group ();
2781
2782 /* Show we don't know the value of anything stored or clobbered. */
2783 note_stores (PATTERN (insn), mark_stores);
2784 map->last_pc_value = 0;
2785 #ifdef HAVE_cc0
2786 map->last_cc0_value = 0;
2787 #endif
2788
2789 /* Set up any constant equivalences made in this insn. */
2790 for (i = 0; i < map->num_sets; i++)
2791 {
2792 if (GET_CODE (map->equiv_sets[i].dest) == REG)
2793 {
2794 int regno = REGNO (map->equiv_sets[i].dest);
2795
2796 if (regno < map->const_equiv_map_size
2797 && (map->const_equiv_map[regno] == 0
2798 /* Following clause is a hack to make case work where GNU C++
2799 reassigns a variable to make cse work right. */
2800 || ! rtx_equal_p (map->const_equiv_map[regno],
2801 map->equiv_sets[i].equiv)))
2802 {
2803 map->const_equiv_map[regno] = map->equiv_sets[i].equiv;
2804 map->const_age_map[regno] = map->const_age;
2805 }
2806 }
2807 else if (map->equiv_sets[i].dest == pc_rtx)
2808 map->last_pc_value = map->equiv_sets[i].equiv;
2809 #ifdef HAVE_cc0
2810 else if (map->equiv_sets[i].dest == cc0_rtx)
2811 map->last_cc0_value = map->equiv_sets[i].equiv;
2812 #endif
2813 }
2814 }
2815 \f
2816 /* Substitute known constants for pseudo regs in the contents of LOC,
2817 which are part of INSN.
2818 If INSN is zero, the substitution should always be done (this is used to
2819 update DECL_RTL).
2820 These changes are taken out by try_constants if the result is not valid.
2821
2822 Note that we are more concerned with determining when the result of a SET
2823 is a constant, for further propagation, than actually inserting constants
2824 into insns; cse will do the latter task better.
2825
2826 This function is also used to adjust address of items previously addressed
2827 via the virtual stack variable or virtual incoming arguments registers. */
2828
2829 static void
2830 subst_constants (loc, insn, map)
2831 rtx *loc;
2832 rtx insn;
2833 struct inline_remap *map;
2834 {
2835 rtx x = *loc;
2836 register int i;
2837 register enum rtx_code code;
2838 register char *format_ptr;
2839 int num_changes = num_validated_changes ();
2840 rtx new = 0;
2841 enum machine_mode op0_mode;
2842
2843 code = GET_CODE (x);
2844
2845 switch (code)
2846 {
2847 case PC:
2848 case CONST_INT:
2849 case CONST_DOUBLE:
2850 case SYMBOL_REF:
2851 case CONST:
2852 case LABEL_REF:
2853 case ADDRESS:
2854 return;
2855
2856 #ifdef HAVE_cc0
2857 case CC0:
2858 validate_change (insn, loc, map->last_cc0_value, 1);
2859 return;
2860 #endif
2861
2862 case USE:
2863 case CLOBBER:
2864 /* The only thing we can do with a USE or CLOBBER is possibly do
2865 some substitutions in a MEM within it. */
2866 if (GET_CODE (XEXP (x, 0)) == MEM)
2867 subst_constants (&XEXP (XEXP (x, 0), 0), insn, map);
2868 return;
2869
2870 case REG:
2871 /* Substitute for parms and known constants. Don't replace
2872 hard regs used as user variables with constants. */
2873 {
2874 int regno = REGNO (x);
2875
2876 if (! (regno < FIRST_PSEUDO_REGISTER && REG_USERVAR_P (x))
2877 && regno < map->const_equiv_map_size
2878 && map->const_equiv_map[regno] != 0
2879 && map->const_age_map[regno] >= map->const_age)
2880 validate_change (insn, loc, map->const_equiv_map[regno], 1);
2881 return;
2882 }
2883
2884 case SUBREG:
2885 /* SUBREG applied to something other than a reg
2886 should be treated as ordinary, since that must
2887 be a special hack and we don't know how to treat it specially.
2888 Consider for example mulsidi3 in m68k.md.
2889 Ordinary SUBREG of a REG needs this special treatment. */
2890 if (GET_CODE (SUBREG_REG (x)) == REG)
2891 {
2892 rtx inner = SUBREG_REG (x);
2893 rtx new = 0;
2894
2895 /* We can't call subst_constants on &SUBREG_REG (x) because any
2896 constant or SUBREG wouldn't be valid inside our SUBEG. Instead,
2897 see what is inside, try to form the new SUBREG and see if that is
2898 valid. We handle two cases: extracting a full word in an
2899 integral mode and extracting the low part. */
2900 subst_constants (&inner, NULL_RTX, map);
2901
2902 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2903 && GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD
2904 && GET_MODE (SUBREG_REG (x)) != VOIDmode)
2905 new = operand_subword (inner, SUBREG_WORD (x), 0,
2906 GET_MODE (SUBREG_REG (x)));
2907
2908 cancel_changes (num_changes);
2909 if (new == 0 && subreg_lowpart_p (x))
2910 new = gen_lowpart_common (GET_MODE (x), inner);
2911
2912 if (new)
2913 validate_change (insn, loc, new, 1);
2914
2915 return;
2916 }
2917 break;
2918
2919 case MEM:
2920 subst_constants (&XEXP (x, 0), insn, map);
2921
2922 /* If a memory address got spoiled, change it back. */
2923 if (insn != 0 && num_validated_changes () != num_changes
2924 && !memory_address_p (GET_MODE (x), XEXP (x, 0)))
2925 cancel_changes (num_changes);
2926 return;
2927
2928 case SET:
2929 {
2930 /* Substitute constants in our source, and in any arguments to a
2931 complex (e..g, ZERO_EXTRACT) destination, but not in the destination
2932 itself. */
2933 rtx *dest_loc = &SET_DEST (x);
2934 rtx dest = *dest_loc;
2935 rtx src, tem;
2936
2937 subst_constants (&SET_SRC (x), insn, map);
2938 src = SET_SRC (x);
2939
2940 while (GET_CODE (*dest_loc) == ZERO_EXTRACT
2941 || GET_CODE (*dest_loc) == SUBREG
2942 || GET_CODE (*dest_loc) == STRICT_LOW_PART)
2943 {
2944 if (GET_CODE (*dest_loc) == ZERO_EXTRACT)
2945 {
2946 subst_constants (&XEXP (*dest_loc, 1), insn, map);
2947 subst_constants (&XEXP (*dest_loc, 2), insn, map);
2948 }
2949 dest_loc = &XEXP (*dest_loc, 0);
2950 }
2951
2952 /* Do substitute in the address of a destination in memory. */
2953 if (GET_CODE (*dest_loc) == MEM)
2954 subst_constants (&XEXP (*dest_loc, 0), insn, map);
2955
2956 /* Check for the case of DEST a SUBREG, both it and the underlying
2957 register are less than one word, and the SUBREG has the wider mode.
2958 In the case, we are really setting the underlying register to the
2959 source converted to the mode of DEST. So indicate that. */
2960 if (GET_CODE (dest) == SUBREG
2961 && GET_MODE_SIZE (GET_MODE (dest)) <= UNITS_PER_WORD
2962 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) <= UNITS_PER_WORD
2963 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2964 <= GET_MODE_SIZE (GET_MODE (dest)))
2965 && (tem = gen_lowpart_if_possible (GET_MODE (SUBREG_REG (dest)),
2966 src)))
2967 src = tem, dest = SUBREG_REG (dest);
2968
2969 /* If storing a recognizable value save it for later recording. */
2970 if ((map->num_sets < MAX_RECOG_OPERANDS)
2971 && (CONSTANT_P (src)
2972 || (GET_CODE (src) == REG
2973 && (REGNO (src) == VIRTUAL_INCOMING_ARGS_REGNUM
2974 || REGNO (src) == VIRTUAL_STACK_VARS_REGNUM))
2975 || (GET_CODE (src) == PLUS
2976 && GET_CODE (XEXP (src, 0)) == REG
2977 && (REGNO (XEXP (src, 0)) == VIRTUAL_INCOMING_ARGS_REGNUM
2978 || REGNO (XEXP (src, 0)) == VIRTUAL_STACK_VARS_REGNUM)
2979 && CONSTANT_P (XEXP (src, 1)))
2980 || GET_CODE (src) == COMPARE
2981 #ifdef HAVE_cc0
2982 || dest == cc0_rtx
2983 #endif
2984 || (dest == pc_rtx
2985 && (src == pc_rtx || GET_CODE (src) == RETURN
2986 || GET_CODE (src) == LABEL_REF))))
2987 {
2988 /* Normally, this copy won't do anything. But, if SRC is a COMPARE
2989 it will cause us to save the COMPARE with any constants
2990 substituted, which is what we want for later. */
2991 map->equiv_sets[map->num_sets].equiv = copy_rtx (src);
2992 map->equiv_sets[map->num_sets++].dest = dest;
2993 }
2994 }
2995 return;
2996
2997 default:
2998 break;
2999 }
3000
3001 format_ptr = GET_RTX_FORMAT (code);
3002
3003 /* If the first operand is an expression, save its mode for later. */
3004 if (*format_ptr == 'e')
3005 op0_mode = GET_MODE (XEXP (x, 0));
3006
3007 for (i = 0; i < GET_RTX_LENGTH (code); i++)
3008 {
3009 switch (*format_ptr++)
3010 {
3011 case '0':
3012 break;
3013
3014 case 'e':
3015 if (XEXP (x, i))
3016 subst_constants (&XEXP (x, i), insn, map);
3017 break;
3018
3019 case 'u':
3020 case 'i':
3021 case 's':
3022 case 'w':
3023 break;
3024
3025 case 'E':
3026 if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
3027 {
3028 int j;
3029 for (j = 0; j < XVECLEN (x, i); j++)
3030 subst_constants (&XVECEXP (x, i, j), insn, map);
3031 }
3032 break;
3033
3034 default:
3035 abort ();
3036 }
3037 }
3038
3039 /* If this is a commutative operation, move a constant to the second
3040 operand unless the second operand is already a CONST_INT. */
3041 if ((GET_RTX_CLASS (code) == 'c' || code == NE || code == EQ)
3042 && CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT)
3043 {
3044 rtx tem = XEXP (x, 0);
3045 validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
3046 validate_change (insn, &XEXP (x, 1), tem, 1);
3047 }
3048
3049 /* Simplify the expression in case we put in some constants. */
3050 switch (GET_RTX_CLASS (code))
3051 {
3052 case '1':
3053 new = simplify_unary_operation (code, GET_MODE (x),
3054 XEXP (x, 0), op0_mode);
3055 break;
3056
3057 case '<':
3058 {
3059 enum machine_mode op_mode = GET_MODE (XEXP (x, 0));
3060 if (op_mode == VOIDmode)
3061 op_mode = GET_MODE (XEXP (x, 1));
3062 new = simplify_relational_operation (code, op_mode,
3063 XEXP (x, 0), XEXP (x, 1));
3064 #ifdef FLOAT_STORE_FLAG_VALUE
3065 if (new != 0 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
3066 new = ((new == const0_rtx) ? CONST0_RTX (GET_MODE (x))
3067 : CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE,
3068 GET_MODE (x)));
3069 #endif
3070 break;
3071 }
3072
3073 case '2':
3074 case 'c':
3075 new = simplify_binary_operation (code, GET_MODE (x),
3076 XEXP (x, 0), XEXP (x, 1));
3077 break;
3078
3079 case 'b':
3080 case '3':
3081 new = simplify_ternary_operation (code, GET_MODE (x), op0_mode,
3082 XEXP (x, 0), XEXP (x, 1), XEXP (x, 2));
3083 break;
3084 }
3085
3086 if (new)
3087 validate_change (insn, loc, new, 1);
3088 }
3089
3090 /* Show that register modified no longer contain known constants. We are
3091 called from note_stores with parts of the new insn. */
3092
3093 void
3094 mark_stores (dest, x)
3095 rtx dest;
3096 rtx x ATTRIBUTE_UNUSED;
3097 {
3098 int regno = -1;
3099 enum machine_mode mode;
3100
3101 /* DEST is always the innermost thing set, except in the case of
3102 SUBREGs of hard registers. */
3103
3104 if (GET_CODE (dest) == REG)
3105 regno = REGNO (dest), mode = GET_MODE (dest);
3106 else if (GET_CODE (dest) == SUBREG && GET_CODE (SUBREG_REG (dest)) == REG)
3107 {
3108 regno = REGNO (SUBREG_REG (dest)) + SUBREG_WORD (dest);
3109 mode = GET_MODE (SUBREG_REG (dest));
3110 }
3111
3112 if (regno >= 0)
3113 {
3114 int last_reg = (regno >= FIRST_PSEUDO_REGISTER ? regno
3115 : regno + HARD_REGNO_NREGS (regno, mode) - 1);
3116 int i;
3117
3118 /* Ignore virtual stack var or virtual arg register since those
3119 are handled separately. */
3120 if (regno != VIRTUAL_INCOMING_ARGS_REGNUM
3121 && regno != VIRTUAL_STACK_VARS_REGNUM)
3122 for (i = regno; i <= last_reg; i++)
3123 if (i < global_const_equiv_map_size)
3124 global_const_equiv_map[i] = 0;
3125 }
3126 }
3127 \f
3128 /* If any CONST expressions with RTX_INTEGRATED_P are present in the rtx
3129 pointed to by PX, they represent constants in the constant pool.
3130 Replace these with a new memory reference obtained from force_const_mem.
3131 Similarly, ADDRESS expressions with RTX_INTEGRATED_P represent the
3132 address of a constant pool entry. Replace them with the address of
3133 a new constant pool entry obtained from force_const_mem. */
3134
3135 static void
3136 restore_constants (px)
3137 rtx *px;
3138 {
3139 rtx x = *px;
3140 int i, j;
3141 char *fmt;
3142
3143 if (x == 0)
3144 return;
3145
3146 if (GET_CODE (x) == CONST_DOUBLE)
3147 {
3148 /* We have to make a new CONST_DOUBLE to ensure that we account for
3149 it correctly. Using the old CONST_DOUBLE_MEM data is wrong. */
3150 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
3151 {
3152 REAL_VALUE_TYPE d;
3153
3154 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
3155 *px = CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (x));
3156 }
3157 else
3158 *px = immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
3159 VOIDmode);
3160 }
3161
3162 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == CONST)
3163 {
3164 restore_constants (&XEXP (x, 0));
3165 *px = validize_mem (force_const_mem (GET_MODE (x), XEXP (x, 0)));
3166 }
3167 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == SUBREG)
3168 {
3169 /* This must be (subreg/i:M1 (const/i:M2 ...) 0). */
3170 rtx new = XEXP (SUBREG_REG (x), 0);
3171
3172 restore_constants (&new);
3173 new = force_const_mem (GET_MODE (SUBREG_REG (x)), new);
3174 PUT_MODE (new, GET_MODE (x));
3175 *px = validize_mem (new);
3176 }
3177 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == ADDRESS)
3178 {
3179 rtx new = XEXP (force_const_mem (GET_MODE (XEXP (x, 0)),
3180 XEXP (XEXP (x, 0), 0)),
3181 0);
3182
3183 #ifdef POINTERS_EXTEND_UNSIGNED
3184 if (GET_MODE (new) != GET_MODE (x))
3185 new = convert_memory_address (GET_MODE (x), new);
3186 #endif
3187
3188 *px = new;
3189 }
3190 else
3191 {
3192 fmt = GET_RTX_FORMAT (GET_CODE (x));
3193 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3194 {
3195 switch (*fmt++)
3196 {
3197 case 'E':
3198 for (j = 0; j < XVECLEN (x, i); j++)
3199 restore_constants (&XVECEXP (x, i, j));
3200 break;
3201
3202 case 'e':
3203 restore_constants (&XEXP (x, i));
3204 break;
3205 }
3206 }
3207 }
3208 }
3209 \f
3210 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
3211 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
3212 that it points to the node itself, thus indicating that the node is its
3213 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
3214 the given node is NULL, recursively descend the decl/block tree which
3215 it is the root of, and for each other ..._DECL or BLOCK node contained
3216 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
3217 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
3218 values to point to themselves. */
3219
3220 static void
3221 set_block_origin_self (stmt)
3222 register tree stmt;
3223 {
3224 if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
3225 {
3226 BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
3227
3228 {
3229 register tree local_decl;
3230
3231 for (local_decl = BLOCK_VARS (stmt);
3232 local_decl != NULL_TREE;
3233 local_decl = TREE_CHAIN (local_decl))
3234 set_decl_origin_self (local_decl); /* Potential recursion. */
3235 }
3236
3237 {
3238 register tree subblock;
3239
3240 for (subblock = BLOCK_SUBBLOCKS (stmt);
3241 subblock != NULL_TREE;
3242 subblock = BLOCK_CHAIN (subblock))
3243 set_block_origin_self (subblock); /* Recurse. */
3244 }
3245 }
3246 }
3247
3248 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
3249 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
3250 node to so that it points to the node itself, thus indicating that the
3251 node represents its own (abstract) origin. Additionally, if the
3252 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
3253 the decl/block tree of which the given node is the root of, and for
3254 each other ..._DECL or BLOCK node contained therein whose
3255 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
3256 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
3257 point to themselves. */
3258
3259 static void
3260 set_decl_origin_self (decl)
3261 register tree decl;
3262 {
3263 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
3264 {
3265 DECL_ABSTRACT_ORIGIN (decl) = decl;
3266 if (TREE_CODE (decl) == FUNCTION_DECL)
3267 {
3268 register tree arg;
3269
3270 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
3271 DECL_ABSTRACT_ORIGIN (arg) = arg;
3272 if (DECL_INITIAL (decl) != NULL_TREE
3273 && DECL_INITIAL (decl) != error_mark_node)
3274 set_block_origin_self (DECL_INITIAL (decl));
3275 }
3276 }
3277 }
3278 \f
3279 /* Given a pointer to some BLOCK node, and a boolean value to set the
3280 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
3281 the given block, and for all local decls and all local sub-blocks
3282 (recursively) which are contained therein. */
3283
3284 static void
3285 set_block_abstract_flags (stmt, setting)
3286 register tree stmt;
3287 register int setting;
3288 {
3289 register tree local_decl;
3290 register tree subblock;
3291
3292 BLOCK_ABSTRACT (stmt) = setting;
3293
3294 for (local_decl = BLOCK_VARS (stmt);
3295 local_decl != NULL_TREE;
3296 local_decl = TREE_CHAIN (local_decl))
3297 set_decl_abstract_flags (local_decl, setting);
3298
3299 for (subblock = BLOCK_SUBBLOCKS (stmt);
3300 subblock != NULL_TREE;
3301 subblock = BLOCK_CHAIN (subblock))
3302 set_block_abstract_flags (subblock, setting);
3303 }
3304
3305 /* Given a pointer to some ..._DECL node, and a boolean value to set the
3306 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
3307 given decl, and (in the case where the decl is a FUNCTION_DECL) also
3308 set the abstract flags for all of the parameters, local vars, local
3309 blocks and sub-blocks (recursively) to the same setting. */
3310
3311 void
3312 set_decl_abstract_flags (decl, setting)
3313 register tree decl;
3314 register int setting;
3315 {
3316 DECL_ABSTRACT (decl) = setting;
3317 if (TREE_CODE (decl) == FUNCTION_DECL)
3318 {
3319 register tree arg;
3320
3321 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
3322 DECL_ABSTRACT (arg) = setting;
3323 if (DECL_INITIAL (decl) != NULL_TREE
3324 && DECL_INITIAL (decl) != error_mark_node)
3325 set_block_abstract_flags (DECL_INITIAL (decl), setting);
3326 }
3327 }
3328 \f
3329 /* Output the assembly language code for the function FNDECL
3330 from its DECL_SAVED_INSNS. Used for inline functions that are output
3331 at end of compilation instead of where they came in the source. */
3332
3333 void
3334 output_inline_function (fndecl)
3335 tree fndecl;
3336 {
3337 rtx head;
3338 rtx last;
3339
3340 /* Things we allocate from here on are part of this function, not
3341 permanent. */
3342 temporary_allocation ();
3343
3344 head = DECL_SAVED_INSNS (fndecl);
3345 current_function_decl = fndecl;
3346
3347 /* This call is only used to initialize global variables. */
3348 init_function_start (fndecl, "lossage", 1);
3349
3350 /* Redo parameter determinations in case the FUNCTION_...
3351 macros took machine-specific actions that need to be redone. */
3352 assign_parms (fndecl, 1);
3353
3354 /* Set stack frame size. */
3355 assign_stack_local (BLKmode, DECL_FRAME_SIZE (fndecl), 0);
3356
3357 /* The first is a bit of a lie (the array may be larger), but doesn't
3358 matter too much and it isn't worth saving the actual bound. */
3359 reg_rtx_no = regno_pointer_flag_length = MAX_REGNUM (head);
3360 regno_reg_rtx = (rtx *) INLINE_REGNO_REG_RTX (head);
3361 regno_pointer_flag = INLINE_REGNO_POINTER_FLAG (head);
3362 regno_pointer_align = INLINE_REGNO_POINTER_ALIGN (head);
3363 max_parm_reg = MAX_PARMREG (head);
3364 parm_reg_stack_loc = (rtx *) PARMREG_STACK_LOC (head);
3365
3366 stack_slot_list = STACK_SLOT_LIST (head);
3367 forced_labels = FORCED_LABELS (head);
3368
3369 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_ALLOCA)
3370 current_function_calls_alloca = 1;
3371
3372 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_SETJMP)
3373 current_function_calls_setjmp = 1;
3374
3375 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_LONGJMP)
3376 current_function_calls_longjmp = 1;
3377
3378 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_STRUCT)
3379 current_function_returns_struct = 1;
3380
3381 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_PCC_STRUCT)
3382 current_function_returns_pcc_struct = 1;
3383
3384 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_NEEDS_CONTEXT)
3385 current_function_needs_context = 1;
3386
3387 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_HAS_NONLOCAL_LABEL)
3388 current_function_has_nonlocal_label = 1;
3389
3390 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_POINTER)
3391 current_function_returns_pointer = 1;
3392
3393 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_USES_CONST_POOL)
3394 current_function_uses_const_pool = 1;
3395
3396 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE)
3397 current_function_uses_pic_offset_table = 1;
3398
3399 current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (head);
3400 current_function_pops_args = POPS_ARGS (head);
3401
3402 /* This is the only thing the expand_function_end call that uses to be here
3403 actually does and that call can cause problems. */
3404 immediate_size_expand--;
3405
3406 /* Find last insn and rebuild the constant pool. */
3407 for (last = FIRST_PARM_INSN (head);
3408 NEXT_INSN (last); last = NEXT_INSN (last))
3409 {
3410 if (GET_RTX_CLASS (GET_CODE (last)) == 'i')
3411 {
3412 restore_constants (&PATTERN (last));
3413 restore_constants (&REG_NOTES (last));
3414 }
3415 }
3416
3417 set_new_first_and_last_insn (FIRST_PARM_INSN (head), last);
3418 set_new_first_and_last_label_num (FIRST_LABELNO (head), LAST_LABELNO (head));
3419
3420 /* We must have already output DWARF debugging information for the
3421 original (abstract) inline function declaration/definition, so
3422 we want to make sure that the debugging information we generate
3423 for this special instance of the inline function refers back to
3424 the information we already generated. To make sure that happens,
3425 we simply have to set the DECL_ABSTRACT_ORIGIN for the function
3426 node (and for all of the local ..._DECL nodes which are its children)
3427 so that they all point to themselves. */
3428
3429 set_decl_origin_self (fndecl);
3430
3431 /* We're not deferring this any longer. */
3432 DECL_DEFER_OUTPUT (fndecl) = 0;
3433
3434 /* We can't inline this anymore. */
3435 DECL_INLINE (fndecl) = 0;
3436
3437 /* Compile this function all the way down to assembly code. */
3438 rest_of_compilation (fndecl);
3439
3440 current_function_decl = 0;
3441 }
This page took 1.486159 seconds and 6 git commands to generate.