1 /* Procedure integration for GNU CC.
2 Copyright (C) 1988, 91, 93-98, 1999 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
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)
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.
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. */
30 #include "insn-config.h"
31 #include "insn-flags.h"
35 #include "integrate.h"
43 #define obstack_chunk_alloc xmalloc
44 #define obstack_chunk_free free
46 extern struct obstack *function_maybepermanent_obstack;
48 /* Similar, but round to the next highest integer that meets the
50 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
52 /* Default max number of insns a function can have and still be inline.
53 This is overridden on RISC machines. */
54 #ifndef INTEGRATE_THRESHOLD
55 /* Inlining small functions might save more space then not inlining at
56 all. Assume 1 instruction for the call and 1.5 insns per argument. */
57 #define INTEGRATE_THRESHOLD(DECL) \
59 ? (1 + (3 * list_length (DECL_ARGUMENTS (DECL))) / 2) \
60 : (8 * (8 + list_length (DECL_ARGUMENTS (DECL)))))
63 static rtvec initialize_for_inline PROTO((tree, int));
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 *,
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,
86 void set_decl_abstract_flags PROTO((tree, int));
87 static tree copy_and_set_decl_abstract_origin PROTO((tree));
89 /* The maximum number of instructions accepted for inlining a
90 function. Increasing values mean more agressive inlining.
91 This affects currently only functions explicitly marked as
92 inline (or methods defined within the class definition for C++).
93 The default value of 10000 is arbitrary but high to match the
94 previously unlimited gcc capabilities. */
96 int inline_max_insns = 10000;
99 /* Returns the Ith entry in the label_map contained in MAP. If the
100 Ith entry has not yet been set, return a fresh label. This function
101 performs a lazy initialization of label_map, thereby avoiding huge memory
102 explosions when the label_map gets very large. */
105 get_label_from_map (map, i)
106 struct inline_remap *map;
109 rtx x = map->label_map[i];
112 x = map->label_map[i] = gen_label_rtx();
117 /* Zero if the current function (whose FUNCTION_DECL is FNDECL)
118 is safe and reasonable to integrate into other functions.
119 Nonzero means value is a warning msgid with a single %s
120 for the function's name. */
123 function_cannot_inline_p (fndecl)
124 register tree fndecl;
127 tree last = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
129 /* For functions marked as inline increase the maximum size to
130 inline_max_insns (-finline-limit-<n>). For regular functions
131 use the limit given by INTEGRATE_THRESHOLD. */
133 int max_insns = (DECL_INLINE (fndecl))
135 + 8 * list_length (DECL_ARGUMENTS (fndecl)))
136 : INTEGRATE_THRESHOLD (fndecl);
138 register int ninsns = 0;
142 /* No inlines with varargs. */
143 if ((last && TREE_VALUE (last) != void_type_node)
144 || current_function_varargs)
145 return N_("varargs function cannot be inline");
147 if (current_function_calls_alloca)
148 return N_("function using alloca cannot be inline");
150 if (current_function_contains_functions)
151 return N_("function with nested functions cannot be inline");
153 if (current_function_cannot_inline)
154 return current_function_cannot_inline;
156 /* If its not even close, don't even look. */
157 if (get_max_uid () > 3 * max_insns)
158 return N_("function too large to be inline");
161 /* Don't inline functions which do not specify a function prototype and
162 have BLKmode argument or take the address of a parameter. */
163 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
165 if (TYPE_MODE (TREE_TYPE (parms)) == BLKmode)
166 TREE_ADDRESSABLE (parms) = 1;
167 if (last == NULL_TREE && TREE_ADDRESSABLE (parms))
168 return N_("no prototype, and parameter address used; cannot be inline");
172 /* We can't inline functions that return structures
173 the old-fashioned PCC way, copying into a static block. */
174 if (current_function_returns_pcc_struct)
175 return N_("inline functions not supported for this return value type");
177 /* We can't inline functions that return structures of varying size. */
178 if (int_size_in_bytes (TREE_TYPE (TREE_TYPE (fndecl))) < 0)
179 return N_("function with varying-size return value cannot be inline");
181 /* Cannot inline a function with a varying size argument or one that
182 receives a transparent union. */
183 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
185 if (int_size_in_bytes (TREE_TYPE (parms)) < 0)
186 return N_("function with varying-size parameter cannot be inline");
187 else if (TYPE_TRANSPARENT_UNION (TREE_TYPE (parms)))
188 return N_("function with transparent unit parameter cannot be inline");
191 if (get_max_uid () > max_insns)
193 for (ninsns = 0, insn = get_first_nonparm_insn ();
194 insn && ninsns < max_insns;
195 insn = NEXT_INSN (insn))
196 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
199 if (ninsns >= max_insns)
200 return N_("function too large to be inline");
203 /* We will not inline a function which uses computed goto. The addresses of
204 its local labels, which may be tucked into global storage, are of course
205 not constant across instantiations, which causes unexpected behaviour. */
206 if (current_function_has_computed_jump)
207 return N_("function with computed jump cannot inline");
209 /* We cannot inline a nested function that jumps to a nonlocal label. */
210 if (current_function_has_nonlocal_goto)
211 return N_("function with nonlocal goto cannot be inline");
213 /* This is a hack, until the inliner is taught about eh regions at
214 the start of the function. */
215 for (insn = get_insns ();
217 && ! (GET_CODE (insn) == NOTE
218 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG);
219 insn = NEXT_INSN (insn))
221 if (insn && GET_CODE (insn) == NOTE
222 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
223 return N_("function with complex parameters cannot be inline");
226 /* We can't inline functions that return a PARALLEL rtx. */
227 result = DECL_RTL (DECL_RESULT (fndecl));
228 if (result && GET_CODE (result) == PARALLEL)
229 return N_("inline functions not supported for this return value type");
234 /* Variables used within save_for_inline. */
236 /* Mapping from old pseudo-register to new pseudo-registers.
237 The first element of this map is reg_map[FIRST_PSEUDO_REGISTER].
238 It is allocated in `save_for_inline' and `expand_inline_function',
239 and deallocated on exit from each of those routines. */
242 /* Mapping from old code-labels to new code-labels.
243 The first element of this map is label_map[min_labelno].
244 It is allocated in `save_for_inline' and `expand_inline_function',
245 and deallocated on exit from each of those routines. */
246 static rtx *label_map;
248 /* Mapping from old insn uid's to copied insns.
249 It is allocated in `save_for_inline' and `expand_inline_function',
250 and deallocated on exit from each of those routines. */
251 static rtx *insn_map;
253 /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
254 Zero for a reg that isn't a parm's home.
255 Only reg numbers less than max_parm_reg are mapped here. */
256 static tree *parmdecl_map;
258 /* When an insn is being copied by copy_for_inline,
259 this is nonzero if we have copied an ASM_OPERANDS.
260 In that case, it is the original input-operand vector. */
261 static rtvec orig_asm_operands_vector;
263 /* When an insn is being copied by copy_for_inline,
264 this is nonzero if we have copied an ASM_OPERANDS.
265 In that case, it is the copied input-operand vector. */
266 static rtvec copy_asm_operands_vector;
268 /* Likewise, this is the copied constraints vector. */
269 static rtvec copy_asm_constraints_vector;
271 /* In save_for_inline, nonzero if past the parm-initialization insns. */
272 static int in_nonparm_insns;
274 /* subroutines passed to duplicate_eh_handlers to map exception labels */
277 save_for_inline_eh_labelmap (label)
280 int index = CODE_LABEL_NUMBER (label);
281 return label_map[index];
284 /* Subroutine for `save_for_inline{copying,nocopy}'. Performs initialization
285 needed to save FNDECL's insns and info for future inline expansion. */
288 initialize_for_inline (fndecl, copy)
296 /* Clear out PARMDECL_MAP. It was allocated in the caller's frame. */
297 bzero ((char *) parmdecl_map, max_parm_reg * sizeof (tree));
298 arg_vector = rtvec_alloc (list_length (DECL_ARGUMENTS (fndecl)));
300 for (parms = DECL_ARGUMENTS (fndecl), i = 0;
302 parms = TREE_CHAIN (parms), i++)
304 rtx p = DECL_RTL (parms);
305 int copied_incoming = 0;
307 /* If we have (mem (addressof (mem ...))), use the inner MEM since
308 otherwise the copy_rtx call below will not unshare the MEM since
309 it shares ADDRESSOF. */
310 if (GET_CODE (p) == MEM && GET_CODE (XEXP (p, 0)) == ADDRESSOF
311 && GET_CODE (XEXP (XEXP (p, 0), 0)) == MEM)
312 p = XEXP (XEXP (p, 0), 0);
314 if (GET_CODE (p) == MEM && copy)
316 /* Copy the rtl so that modifications of the addresses
317 later in compilation won't affect this arg_vector.
318 Virtual register instantiation can screw the address
320 rtx new = copy_rtx (p);
322 /* Don't leave the old copy anywhere in this decl. */
323 if (DECL_RTL (parms) == DECL_INCOMING_RTL (parms)
324 || (GET_CODE (DECL_RTL (parms)) == MEM
325 && GET_CODE (DECL_INCOMING_RTL (parms)) == MEM
326 && (XEXP (DECL_RTL (parms), 0)
327 == XEXP (DECL_INCOMING_RTL (parms), 0))))
328 DECL_INCOMING_RTL (parms) = new, copied_incoming = 1;
330 DECL_RTL (parms) = new;
333 RTVEC_ELT (arg_vector, i) = p;
335 if (GET_CODE (p) == REG)
336 parmdecl_map[REGNO (p)] = parms;
337 else if (GET_CODE (p) == CONCAT)
339 rtx preal = gen_realpart (GET_MODE (XEXP (p, 0)), p);
340 rtx pimag = gen_imagpart (GET_MODE (preal), p);
342 if (GET_CODE (preal) == REG)
343 parmdecl_map[REGNO (preal)] = parms;
344 if (GET_CODE (pimag) == REG)
345 parmdecl_map[REGNO (pimag)] = parms;
348 /* This flag is cleared later
349 if the function ever modifies the value of the parm. */
350 TREE_READONLY (parms) = 1;
352 /* Copy DECL_INCOMING_RTL if not done already. This can
353 happen if DECL_RTL is a reg. */
354 if (copy && ! copied_incoming)
356 p = DECL_INCOMING_RTL (parms);
358 /* If we have (mem (addressof (mem ...))), use the inner MEM since
359 otherwise the copy_rtx call below will not unshare the MEM since
360 it shares ADDRESSOF. */
361 if (GET_CODE (p) == MEM && GET_CODE (XEXP (p, 0)) == ADDRESSOF
362 && GET_CODE (XEXP (XEXP (p, 0), 0)) == MEM)
363 p = XEXP (XEXP (p, 0), 0);
365 if (GET_CODE (p) == MEM)
366 DECL_INCOMING_RTL (parms) = copy_rtx (p);
373 /* Adjust the BLOCK_END_NOTE pointers in a given copied DECL tree so that
374 they all point to the new (copied) rtxs. */
377 adjust_copied_decl_tree (block)
380 register tree subblock;
381 register rtx original_end;
383 original_end = BLOCK_END_NOTE (block);
386 BLOCK_END_NOTE (block) = (rtx) NOTE_SOURCE_FILE (original_end);
387 NOTE_SOURCE_FILE (original_end) = 0;
390 /* Process all subblocks. */
391 for (subblock = BLOCK_SUBBLOCKS (block);
393 subblock = TREE_CHAIN (subblock))
394 adjust_copied_decl_tree (subblock);
397 /* Make the insns and PARM_DECLs of the current function permanent
398 and record other information in DECL_SAVED_INSNS to allow inlining
399 of this function in subsequent calls.
401 This function is called when we are going to immediately compile
402 the insns for FNDECL. The insns in maybepermanent_obstack cannot be
403 modified by the compilation process, so we copy all of them to
404 new storage and consider the new insns to be the insn chain to be
405 compiled. Our caller (rest_of_compilation) saves the original
406 DECL_INITIAL and DECL_ARGUMENTS; here we copy them. */
408 /* ??? The nonlocal_label list should be adjusted also. However, since
409 a function that contains a nested function never gets inlined currently,
410 the nonlocal_label list will always be empty, so we don't worry about
414 save_for_inline_copying (fndecl)
418 rtx new_first_insn, new_last_insn, insn;
419 int max_labelno, min_labelno, i, len;
422 rtx first_nonparm_insn;
424 rtx *new_parm_reg_stack_loc;
426 struct emit_status *es
427 = (struct emit_status *) xmalloc (sizeof (struct emit_status));
429 /* Make and emit a return-label if we have not already done so.
430 Do this before recording the bounds on label numbers. */
432 if (return_label == 0)
434 return_label = gen_label_rtx ();
435 emit_label (return_label);
438 *es = *current_function->emit;
440 /* Get some bounds on the labels and registers used. */
442 max_labelno = max_label_num ();
443 min_labelno = get_first_label_num ();
444 max_reg = max_reg_num ();
446 /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
447 Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
448 Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
449 for the parms, prior to elimination of virtual registers.
450 These values are needed for substituting parms properly. */
452 parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
454 argvec = initialize_for_inline (fndecl, 1);
456 if (current_function_uses_const_pool)
458 /* Replace any constant pool references with the actual constant. We
459 will put the constants back in the copy made below. */
460 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
461 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
463 save_constants (&PATTERN (insn));
464 if (REG_NOTES (insn))
465 save_constants (®_NOTES (insn));
468 /* Also scan all decls, and replace any constant pool references with the
470 save_constants_in_decl_trees (DECL_INITIAL (fndecl));
472 /* Clear out the constant pool so that we can recreate it with the
473 copied constants below. */
474 init_const_rtx_hash_table ();
475 clear_const_double_mem ();
478 max_uid = get_max_uid ();
480 /* We have now allocated all that needs to be allocated permanently
481 on the rtx obstack. Set our high-water mark, so that we
482 can free the rest of this when the time comes. */
486 /* Copy the chain insns of this function.
487 Install the copied chain as the insns of this function,
488 for continued compilation;
489 the original chain is recorded as the DECL_SAVED_INSNS
490 for inlining future calls. */
492 /* If there are insns that copy parms from the stack into pseudo registers,
493 those insns are not copied. `expand_inline_function' must
494 emit the correct code to handle such things. */
497 if (GET_CODE (insn) != NOTE)
499 new_first_insn = rtx_alloc (NOTE);
500 NOTE_SOURCE_FILE (new_first_insn) = NOTE_SOURCE_FILE (insn);
501 NOTE_LINE_NUMBER (new_first_insn) = NOTE_LINE_NUMBER (insn);
502 INSN_UID (new_first_insn) = INSN_UID (insn);
503 PREV_INSN (new_first_insn) = NULL;
504 NEXT_INSN (new_first_insn) = NULL;
505 new_last_insn = new_first_insn;
507 /* Each pseudo-reg in the old insn chain must have a unique rtx in the copy.
508 Make these new rtx's now, and install them in regno_reg_rtx, so they
509 will be the official pseudo-reg rtx's for the rest of compilation. */
511 reg_map = (rtx *) savealloc (es->regno_pointer_flag_length * sizeof (rtx));
513 len = sizeof (struct rtx_def) + (GET_RTX_LENGTH (REG) - 1) * sizeof (rtunion);
514 for (i = max_reg - 1; i > LAST_VIRTUAL_REGISTER; i--)
515 reg_map[i] = (rtx)obstack_copy (function_maybepermanent_obstack,
516 regno_reg_rtx[i], len);
518 es->x_regno_reg_rtx = reg_map;
520 /* Put copies of all the virtual register rtx into the new regno_reg_rtx. */
521 init_virtual_regs (es);
523 /* Likewise each label rtx must have a unique rtx as its copy. */
525 /* We used to use alloca here, but the size of what it would try to
526 allocate would occasionally cause it to exceed the stack limit and
527 cause unpredictable core dumps. Some examples were > 2Mb in size. */
528 label_map = (rtx *) xmalloc ((max_labelno) * sizeof (rtx));
530 for (i = min_labelno; i < max_labelno; i++)
531 label_map[i] = gen_label_rtx ();
533 /* Likewise for parm_reg_stack_slot. */
534 new_parm_reg_stack_loc = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
535 for (i = 0; i < max_parm_reg; i++)
536 new_parm_reg_stack_loc[i] = copy_for_inline (parm_reg_stack_loc[i]);
538 parm_reg_stack_loc = new_parm_reg_stack_loc;
540 /* Record the mapping of old insns to copied insns. */
542 insn_map = (rtx *) alloca (max_uid * sizeof (rtx));
543 bzero ((char *) insn_map, max_uid * sizeof (rtx));
545 /* Get the insn which signals the end of parameter setup code. */
546 first_nonparm_insn = get_first_nonparm_insn ();
548 /* Copy any entries in regno_reg_rtx or DECL_RTLs that reference MEM
549 (the former occurs when a variable has its address taken)
550 since these may be shared and can be changed by virtual
551 register instantiation. DECL_RTL values for our arguments
552 have already been copied by initialize_for_inline. */
553 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_reg; i++)
554 if (GET_CODE (regno_reg_rtx[i]) == MEM)
555 XEXP (regno_reg_rtx[i], 0)
556 = copy_for_inline (XEXP (regno_reg_rtx[i], 0));
558 /* Copy the parm_reg_stack_loc array, and substitute for all of the rtx
560 new2 = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
561 bcopy ((char *) parm_reg_stack_loc, (char *) new2,
562 max_parm_reg * sizeof (rtx));
563 parm_reg_stack_loc = new2;
564 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; ++i)
565 if (parm_reg_stack_loc[i])
566 parm_reg_stack_loc[i] = copy_for_inline (parm_reg_stack_loc[i]);
568 /* Copy the tree of subblocks of the function, and the decls in them.
569 We will use the copy for compiling this function, then restore the original
570 subblocks and decls for use when inlining this function.
572 Several parts of the compiler modify BLOCK trees. In particular,
573 instantiate_virtual_regs will instantiate any virtual regs
574 mentioned in the DECL_RTLs of the decls, and loop
575 unrolling will replicate any BLOCK trees inside an unrolled loop.
577 The modified subblocks or DECL_RTLs would be incorrect for the original rtl
578 which we will use for inlining. The rtl might even contain pseudoregs
579 whose space has been freed. */
581 DECL_INITIAL (fndecl) = copy_decl_tree (DECL_INITIAL (fndecl));
582 DECL_ARGUMENTS (fndecl) = copy_decl_list (DECL_ARGUMENTS (fndecl));
584 /* Now copy each DECL_RTL which is a MEM,
585 so it is safe to modify their addresses. */
586 copy_decl_rtls (DECL_INITIAL (fndecl));
588 /* The fndecl node acts as its own progenitor, so mark it as such. */
589 DECL_ABSTRACT_ORIGIN (fndecl) = fndecl;
591 /* Now copy the chain of insns. Do this twice. The first copy the insn
592 itself and its body. The second time copy of REG_NOTES. This is because
593 a REG_NOTE may have a forward pointer to another insn. */
595 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
598 orig_asm_operands_vector = 0;
600 if (insn == first_nonparm_insn)
601 in_nonparm_insns = 1;
603 switch (GET_CODE (insn))
606 /* No need to keep these. */
607 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
610 copy = rtx_alloc (NOTE);
611 NOTE_LINE_NUMBER (copy) = NOTE_LINE_NUMBER (insn);
612 if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_BLOCK_END)
613 NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
616 NOTE_SOURCE_FILE (insn) = (char *) copy;
617 NOTE_SOURCE_FILE (copy) = 0;
619 if (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG
620 || NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_END)
622 int new_region = CODE_LABEL_NUMBER
623 (label_map[NOTE_BLOCK_NUMBER (copy)]);
625 /* we have to duplicate the handlers for the original */
626 if (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG)
627 duplicate_eh_handlers (NOTE_BLOCK_NUMBER (copy), new_region,
628 save_for_inline_eh_labelmap);
630 /* We have to forward these both to match the new exception
632 NOTE_BLOCK_NUMBER (copy) = new_region;
635 RTX_INTEGRATED_P (copy) = RTX_INTEGRATED_P (insn);
641 copy = rtx_alloc (GET_CODE (insn));
643 if (GET_CODE (insn) == CALL_INSN)
644 CALL_INSN_FUNCTION_USAGE (copy)
645 = copy_for_inline (CALL_INSN_FUNCTION_USAGE (insn));
647 PATTERN (copy) = copy_for_inline (PATTERN (insn));
648 INSN_CODE (copy) = -1;
649 LOG_LINKS (copy) = NULL_RTX;
650 RTX_INTEGRATED_P (copy) = RTX_INTEGRATED_P (insn);
654 copy = label_map[CODE_LABEL_NUMBER (insn)];
655 LABEL_NAME (copy) = LABEL_NAME (insn);
659 copy = rtx_alloc (BARRIER);
665 INSN_UID (copy) = INSN_UID (insn);
666 insn_map[INSN_UID (insn)] = copy;
667 NEXT_INSN (new_last_insn) = copy;
668 PREV_INSN (copy) = new_last_insn;
669 new_last_insn = copy;
672 adjust_copied_decl_tree (DECL_INITIAL (fndecl));
674 /* Now copy the REG_NOTES. */
675 for (insn = NEXT_INSN (get_insns ()); insn; insn = NEXT_INSN (insn))
676 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
677 && insn_map[INSN_UID(insn)])
678 REG_NOTES (insn_map[INSN_UID (insn)])
679 = copy_for_inline (REG_NOTES (insn));
681 NEXT_INSN (new_last_insn) = NULL;
683 /* Make new versions of the register tables. */
684 new = (char *) savealloc (es->regno_pointer_flag_length);
685 memcpy (new, es->regno_pointer_flag, es->regno_pointer_flag_length);
686 new1 = (char *) savealloc (es->regno_pointer_flag_length);
687 memcpy (new1, es->regno_pointer_align, es->regno_pointer_flag_length);
688 es->regno_pointer_flag = new;
689 es->regno_pointer_align = new1;
693 current_function->inl_max_label_num = max_label_num ();
694 current_function->inl_last_parm_insn = current_function->x_last_parm_insn;
695 current_function->original_arg_vector = argvec;
696 current_function->original_decl_initial = DECL_INITIAL (fndecl);
697 /* Use the copy we made for compiling the function now, and
698 use the original values for inlining. */
699 current_function->inl_emit = current_function->emit;
700 current_function->emit = es;
701 set_new_first_and_last_insn (new_first_insn, new_last_insn);
702 DECL_SAVED_INSNS (fndecl) = current_function;
705 /* Copy NODE (as with copy_node). NODE must be a DECL. Set the
706 DECL_ABSTRACT_ORIGIN for the new accordinly. */
709 copy_and_set_decl_abstract_origin (node)
712 tree copy = copy_node (node);
713 if (DECL_ABSTRACT_ORIGIN (copy) != NULL_TREE)
714 /* That means that NODE already had a DECL_ABSTRACT_ORIGIN. (This
715 situation occurs if we inline a function which itself made
716 calls to inline functions.) Since DECL_ABSTRACT_ORIGIN is the
717 most distant ancestor, we don't have to do anything here. */
720 /* The most distant ancestor must be NODE. */
721 DECL_ABSTRACT_ORIGIN (copy) = node;
726 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
727 For example, this can copy a list made of TREE_LIST nodes. While copying,
728 set DECL_ABSTRACT_ORIGIN appropriately. */
731 copy_decl_list (list)
735 register tree prev, next;
740 head = prev = copy_and_set_decl_abstract_origin (list);
741 next = TREE_CHAIN (list);
746 copy = copy_and_set_decl_abstract_origin (next);
747 TREE_CHAIN (prev) = copy;
749 next = TREE_CHAIN (next);
754 /* Make a copy of the entire tree of blocks BLOCK, and return it. */
757 copy_decl_tree (block)
760 tree t, vars, subblocks;
762 vars = copy_decl_list (BLOCK_VARS (block));
765 /* Process all subblocks. */
766 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
768 tree copy = copy_decl_tree (t);
769 TREE_CHAIN (copy) = subblocks;
773 t = copy_node (block);
774 BLOCK_VARS (t) = vars;
775 BLOCK_SUBBLOCKS (t) = nreverse (subblocks);
776 /* If the BLOCK being cloned is already marked as having been instantiated
777 from something else, then leave that `origin' marking alone. Otherwise,
778 mark the clone as having originated from the BLOCK we are cloning. */
779 if (BLOCK_ABSTRACT_ORIGIN (t) == NULL_TREE)
780 BLOCK_ABSTRACT_ORIGIN (t) = block;
784 /* Copy DECL_RTLs in all decls in the given BLOCK node. */
787 copy_decl_rtls (block)
792 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
793 if (DECL_RTL (t) && GET_CODE (DECL_RTL (t)) == MEM)
794 DECL_RTL (t) = copy_for_inline (DECL_RTL (t));
796 /* Process all subblocks. */
797 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
801 /* Make the insns and PARM_DECLs of the current function permanent
802 and record other information in DECL_SAVED_INSNS to allow inlining
803 of this function in subsequent calls.
805 This routine need not copy any insns because we are not going
806 to immediately compile the insns in the insn chain. There
807 are two cases when we would compile the insns for FNDECL:
808 (1) when FNDECL is expanded inline, and (2) when FNDECL needs to
809 be output at the end of other compilation, because somebody took
810 its address. In the first case, the insns of FNDECL are copied
811 as it is expanded inline, so FNDECL's saved insns are not
812 modified. In the second case, FNDECL is used for the last time,
813 so modifying the rtl is not a problem.
815 We don't have to worry about FNDECL being inline expanded by
816 other functions which are written at the end of compilation
817 because flag_no_inline is turned on when we begin writing
818 functions at the end of compilation. */
821 save_for_inline_nocopy (fndecl)
826 rtx first_nonparm_insn;
828 /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
829 Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
830 Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
831 for the parms, prior to elimination of virtual registers.
832 These values are needed for substituting parms properly. */
834 parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
836 /* Make and emit a return-label if we have not already done so. */
838 if (return_label == 0)
840 return_label = gen_label_rtx ();
841 emit_label (return_label);
844 argvec = initialize_for_inline (fndecl, 0);
846 /* If there are insns that copy parms from the stack into pseudo registers,
847 those insns are not copied. `expand_inline_function' must
848 emit the correct code to handle such things. */
851 if (GET_CODE (insn) != NOTE)
854 /* Get the insn which signals the end of parameter setup code. */
855 first_nonparm_insn = get_first_nonparm_insn ();
857 /* Now just scan the chain of insns to see what happens to our
858 PARM_DECLs. If a PARM_DECL is used but never modified, we
859 can substitute its rtl directly when expanding inline (and
860 perform constant folding when its incoming value is constant).
861 Otherwise, we have to copy its value into a new register and track
862 the new register's life. */
864 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
866 if (insn == first_nonparm_insn)
867 in_nonparm_insns = 1;
869 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
871 if (current_function_uses_const_pool)
873 /* Replace any constant pool references with the actual constant.
874 We will put the constant back if we need to write the
875 function out after all. */
876 save_constants (&PATTERN (insn));
877 if (REG_NOTES (insn))
878 save_constants (®_NOTES (insn));
881 /* Record what interesting things happen to our parameters. */
882 note_stores (PATTERN (insn), note_modified_parmregs);
886 /* Also scan all decls, and replace any constant pool references with the
888 save_constants_in_decl_trees (DECL_INITIAL (fndecl));
890 /* We have now allocated all that needs to be allocated permanently
891 on the rtx obstack. Set our high-water mark, so that we
892 can free the rest of this when the time comes. */
896 current_function->inl_emit = current_function->emit;
897 current_function->inl_max_label_num = max_label_num ();
898 current_function->inl_last_parm_insn = current_function->x_last_parm_insn;
899 current_function->original_arg_vector = argvec;
900 current_function->original_decl_initial = DECL_INITIAL (fndecl);
901 DECL_SAVED_INSNS (fndecl) = current_function;
904 /* Given PX, a pointer into an insn, search for references to the constant
905 pool. Replace each with a CONST that has the mode of the original
906 constant, contains the constant, and has RTX_INTEGRATED_P set.
907 Similarly, constant pool addresses not enclosed in a MEM are replaced
908 with an ADDRESS and CONST rtx which also gives the constant, its
909 mode, the mode of the address, and has RTX_INTEGRATED_P set. */
921 /* If this is a CONST_DOUBLE, don't try to fix things up in
922 CONST_DOUBLE_MEM, because this is an infinite recursion. */
923 if (GET_CODE (x) == CONST_DOUBLE)
925 else if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
926 && CONSTANT_POOL_ADDRESS_P (XEXP (x,0)))
928 enum machine_mode const_mode = get_pool_mode (XEXP (x, 0));
929 rtx new = gen_rtx_CONST (const_mode, get_pool_constant (XEXP (x, 0)));
930 RTX_INTEGRATED_P (new) = 1;
932 /* If the MEM was in a different mode than the constant (perhaps we
933 were only looking at the low-order part), surround it with a
934 SUBREG so we can save both modes. */
936 if (GET_MODE (x) != const_mode)
938 new = gen_rtx_SUBREG (GET_MODE (x), new, 0);
939 RTX_INTEGRATED_P (new) = 1;
943 save_constants (&XEXP (*px, 0));
945 else if (GET_CODE (x) == SYMBOL_REF
946 && CONSTANT_POOL_ADDRESS_P (x))
948 *px = gen_rtx_ADDRESS (GET_MODE (x),
949 gen_rtx_CONST (get_pool_mode (x),
950 get_pool_constant (x)));
951 save_constants (&XEXP (*px, 0));
952 RTX_INTEGRATED_P (*px) = 1;
957 char *fmt = GET_RTX_FORMAT (GET_CODE (x));
958 int len = GET_RTX_LENGTH (GET_CODE (x));
960 for (i = len-1; i >= 0; i--)
965 for (j = 0; j < XVECLEN (x, i); j++)
966 save_constants (&XVECEXP (x, i, j));
970 if (XEXP (x, i) == 0)
974 /* Hack tail-recursion here. */
978 save_constants (&XEXP (x, i));
985 /* Note whether a parameter is modified or not. */
988 note_modified_parmregs (reg, x)
990 rtx x ATTRIBUTE_UNUSED;
992 if (GET_CODE (reg) == REG && in_nonparm_insns
993 && REGNO (reg) < max_parm_reg
994 && REGNO (reg) >= FIRST_PSEUDO_REGISTER
995 && parmdecl_map[REGNO (reg)] != 0)
996 TREE_READONLY (parmdecl_map[REGNO (reg)]) = 0;
999 /* Copy the rtx ORIG recursively, replacing pseudo-regs and labels
1000 according to `reg_map' and `label_map'. The original rtl insns
1001 will be saved for inlining; this is used to make a copy
1002 which is used to finish compiling the inline function itself.
1004 If we find a "saved" constant pool entry, one which was replaced with
1005 the value of the constant, convert it back to a constant pool entry.
1006 Since the pool wasn't touched, this should simply restore the old
1009 All other kinds of rtx are copied except those that can never be
1010 changed during compilation. */
1013 copy_for_inline (orig)
1016 register rtx x = orig;
1019 register enum rtx_code code;
1020 register char *format_ptr;
1025 code = GET_CODE (x);
1027 /* These types may be freely shared. */
1038 if (! SYMBOL_REF_NEED_ADJUST (x))
1040 return rethrow_symbol_map (x, save_for_inline_eh_labelmap);
1043 /* We have to make a new CONST_DOUBLE to ensure that we account for
1044 it correctly. Using the old CONST_DOUBLE_MEM data is wrong. */
1045 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1049 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1050 return CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (x));
1053 return immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
1057 /* Get constant pool entry for constant in the pool. */
1058 if (RTX_INTEGRATED_P (x))
1059 return validize_mem (force_const_mem (GET_MODE (x),
1060 copy_for_inline (XEXP (x, 0))));
1064 /* Get constant pool entry, but access in different mode. */
1065 if (RTX_INTEGRATED_P (x))
1067 new = force_const_mem (GET_MODE (SUBREG_REG (x)),
1068 copy_for_inline (XEXP (SUBREG_REG (x), 0)));
1070 PUT_MODE (new, GET_MODE (x));
1071 return validize_mem (new);
1076 /* If not special for constant pool error. Else get constant pool
1078 if (! RTX_INTEGRATED_P (x))
1081 new = force_const_mem (GET_MODE (XEXP (x, 0)),
1082 copy_for_inline (XEXP (XEXP (x, 0), 0)));
1083 new = XEXP (new, 0);
1085 #ifdef POINTERS_EXTEND_UNSIGNED
1086 if (GET_MODE (new) != GET_MODE (x))
1087 new = convert_memory_address (GET_MODE (x), new);
1093 /* If a single asm insn contains multiple output operands
1094 then it contains multiple ASM_OPERANDS rtx's that share operand 3.
1095 We must make sure that the copied insn continues to share it. */
1096 if (orig_asm_operands_vector == XVEC (orig, 3))
1098 x = rtx_alloc (ASM_OPERANDS);
1099 x->volatil = orig->volatil;
1100 XSTR (x, 0) = XSTR (orig, 0);
1101 XSTR (x, 1) = XSTR (orig, 1);
1102 XINT (x, 2) = XINT (orig, 2);
1103 XVEC (x, 3) = copy_asm_operands_vector;
1104 XVEC (x, 4) = copy_asm_constraints_vector;
1105 XSTR (x, 5) = XSTR (orig, 5);
1106 XINT (x, 6) = XINT (orig, 6);
1112 /* A MEM is usually allowed to be shared if its address is constant
1113 or is a constant plus one of the special registers.
1115 We do not allow sharing of addresses that are either a special
1116 register or the sum of a constant and a special register because
1117 it is possible for unshare_all_rtl to copy the address, into memory
1118 that won't be saved. Although the MEM can safely be shared, and
1119 won't be copied there, the address itself cannot be shared, and may
1122 There are also two exceptions with constants: The first is if the
1123 constant is a LABEL_REF or the sum of the LABEL_REF
1124 and an integer. This case can happen if we have an inline
1125 function that supplies a constant operand to the call of another
1126 inline function that uses it in a switch statement. In this case,
1127 we will be replacing the LABEL_REF, so we have to replace this MEM
1130 The second case is if we have a (const (plus (address ..) ...)).
1131 In that case we need to put back the address of the constant pool
1134 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1135 && GET_CODE (XEXP (x, 0)) != LABEL_REF
1136 && ! (GET_CODE (XEXP (x, 0)) == CONST
1137 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS
1138 && ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1140 || (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1146 /* If this is a non-local label, just make a new LABEL_REF.
1147 Otherwise, use the new label as well. */
1148 x = gen_rtx_LABEL_REF (GET_MODE (orig),
1149 LABEL_REF_NONLOCAL_P (orig) ? XEXP (orig, 0)
1150 : label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))]);
1151 LABEL_REF_NONLOCAL_P (x) = LABEL_REF_NONLOCAL_P (orig);
1152 LABEL_OUTSIDE_LOOP_P (x) = LABEL_OUTSIDE_LOOP_P (orig);
1156 if (REGNO (x) > LAST_VIRTUAL_REGISTER)
1157 return reg_map [REGNO (x)];
1162 /* If a parm that gets modified lives in a pseudo-reg,
1163 clear its TREE_READONLY to prevent certain optimizations. */
1165 rtx dest = SET_DEST (x);
1167 while (GET_CODE (dest) == STRICT_LOW_PART
1168 || GET_CODE (dest) == ZERO_EXTRACT
1169 || GET_CODE (dest) == SUBREG)
1170 dest = XEXP (dest, 0);
1172 if (GET_CODE (dest) == REG
1173 && REGNO (dest) < max_parm_reg
1174 && REGNO (dest) >= FIRST_PSEUDO_REGISTER
1175 && parmdecl_map[REGNO (dest)] != 0
1176 /* The insn to load an arg pseudo from a stack slot
1177 does not count as modifying it. */
1178 && in_nonparm_insns)
1179 TREE_READONLY (parmdecl_map[REGNO (dest)]) = 0;
1183 #if 0 /* This is a good idea, but here is the wrong place for it. */
1184 /* Arrange that CONST_INTs always appear as the second operand
1185 if they appear, and that `frame_pointer_rtx' or `arg_pointer_rtx'
1186 always appear as the first. */
1188 if (GET_CODE (XEXP (x, 0)) == CONST_INT
1189 || (XEXP (x, 1) == frame_pointer_rtx
1190 || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
1191 && XEXP (x, 1) == arg_pointer_rtx)))
1193 rtx t = XEXP (x, 0);
1194 XEXP (x, 0) = XEXP (x, 1);
1203 /* Replace this rtx with a copy of itself. */
1205 x = rtx_alloc (code);
1206 bcopy ((char *) orig, (char *) x,
1207 (sizeof (*x) - sizeof (x->fld)
1208 + sizeof (x->fld[0]) * GET_RTX_LENGTH (code)));
1210 /* Now scan the subexpressions recursively.
1211 We can store any replaced subexpressions directly into X
1212 since we know X is not shared! Any vectors in X
1213 must be copied if X was copied. */
1215 format_ptr = GET_RTX_FORMAT (code);
1217 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1219 switch (*format_ptr++)
1222 XEXP (x, i) = copy_for_inline (XEXP (x, i));
1226 /* Change any references to old-insns to point to the
1227 corresponding copied insns. */
1228 XEXP (x, i) = insn_map[INSN_UID (XEXP (x, i))];
1232 if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
1236 XVEC (x, i) = gen_rtvec_vv (XVECLEN (x, i), XVEC (x, i)->elem);
1237 for (j = 0; j < XVECLEN (x, i); j++)
1239 = copy_for_inline (XVECEXP (x, i, j));
1245 if (code == ASM_OPERANDS && orig_asm_operands_vector == 0)
1247 orig_asm_operands_vector = XVEC (orig, 3);
1248 copy_asm_operands_vector = XVEC (x, 3);
1249 copy_asm_constraints_vector = XVEC (x, 4);
1255 /* Unfortunately, we need a global copy of const_equiv map for communication
1256 with a function called from note_stores. Be *very* careful that this
1257 is used properly in the presence of recursion. */
1259 varray_type global_const_equiv_varray;
1261 #define FIXED_BASE_PLUS_P(X) \
1262 (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
1263 && GET_CODE (XEXP (X, 0)) == REG \
1264 && REGNO (XEXP (X, 0)) >= FIRST_VIRTUAL_REGISTER \
1265 && REGNO (XEXP (X, 0)) <= LAST_VIRTUAL_REGISTER)
1267 /* Called to set up a mapping for the case where a parameter is in a
1268 register. If it is read-only and our argument is a constant, set up the
1269 constant equivalence.
1271 If LOC is REG_USERVAR_P, the usual case, COPY must also have that flag set
1272 if it is a register.
1274 Also, don't allow hard registers here; they might not be valid when
1275 substituted into insns. */
1277 process_reg_param (map, loc, copy)
1278 struct inline_remap *map;
1281 if ((GET_CODE (copy) != REG && GET_CODE (copy) != SUBREG)
1282 || (GET_CODE (copy) == REG && REG_USERVAR_P (loc)
1283 && ! REG_USERVAR_P (copy))
1284 || (GET_CODE (copy) == REG
1285 && REGNO (copy) < FIRST_PSEUDO_REGISTER))
1287 rtx temp = copy_to_mode_reg (GET_MODE (loc), copy);
1288 REG_USERVAR_P (temp) = REG_USERVAR_P (loc);
1289 if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1290 SET_CONST_EQUIV_DATA (map, temp, copy, CONST_AGE_PARM);
1293 map->reg_map[REGNO (loc)] = copy;
1296 /* Used by duplicate_eh_handlers to map labels for the exception table */
1297 static struct inline_remap *eif_eh_map;
1300 expand_inline_function_eh_labelmap (label)
1303 int index = CODE_LABEL_NUMBER (label);
1304 return get_label_from_map (eif_eh_map, index);
1307 /* Integrate the procedure defined by FNDECL. Note that this function
1308 may wind up calling itself. Since the static variables are not
1309 reentrant, we do not assign them until after the possibility
1310 of recursion is eliminated.
1312 If IGNORE is nonzero, do not produce a value.
1313 Otherwise store the value in TARGET if it is nonzero and that is convenient.
1316 (rtx)-1 if we could not substitute the function
1317 0 if we substituted it and it does not produce a value
1318 else an rtx for where the value is stored. */
1321 expand_inline_function (fndecl, parms, target, ignore, type,
1322 structure_value_addr)
1327 rtx structure_value_addr;
1329 struct function *inl_f = DECL_SAVED_INSNS (fndecl);
1330 tree formal, actual, block;
1331 rtx parm_insns = inl_f->inl_emit->x_first_insn;
1332 rtx insns = (inl_f->inl_last_parm_insn
1333 ? NEXT_INSN (inl_f->inl_last_parm_insn)
1340 int min_labelno = inl_f->inl_emit->x_first_label_num;
1341 int max_labelno = inl_f->inl_max_label_num;
1343 rtx local_return_label = 0;
1347 struct inline_remap *map = 0;
1351 rtvec arg_vector = (rtvec) inl_f->original_arg_vector;
1352 rtx static_chain_value = 0;
1355 /* The pointer used to track the true location of the memory used
1356 for MAP->LABEL_MAP. */
1357 rtx *real_label_map = 0;
1359 /* Allow for equivalences of the pseudos we make for virtual fp and ap. */
1360 max_regno = inl_f->inl_emit->x_reg_rtx_no + 3;
1361 if (max_regno < FIRST_PSEUDO_REGISTER)
1364 nargs = list_length (DECL_ARGUMENTS (fndecl));
1366 /* Check that the parms type match and that sufficient arguments were
1367 passed. Since the appropriate conversions or default promotions have
1368 already been applied, the machine modes should match exactly. */
1370 for (formal = DECL_ARGUMENTS (fndecl), actual = parms;
1372 formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual))
1375 enum machine_mode mode;
1378 return (rtx) (HOST_WIDE_INT) -1;
1380 arg = TREE_VALUE (actual);
1381 mode = TYPE_MODE (DECL_ARG_TYPE (formal));
1383 if (mode != TYPE_MODE (TREE_TYPE (arg))
1384 /* If they are block mode, the types should match exactly.
1385 They don't match exactly if TREE_TYPE (FORMAL) == ERROR_MARK_NODE,
1386 which could happen if the parameter has incomplete type. */
1388 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg))
1389 != TYPE_MAIN_VARIANT (TREE_TYPE (formal)))))
1390 return (rtx) (HOST_WIDE_INT) -1;
1393 /* Extra arguments are valid, but will be ignored below, so we must
1394 evaluate them here for side-effects. */
1395 for (; actual; actual = TREE_CHAIN (actual))
1396 expand_expr (TREE_VALUE (actual), const0_rtx,
1397 TYPE_MODE (TREE_TYPE (TREE_VALUE (actual))), 0);
1399 /* Make a binding contour to keep inline cleanups called at
1400 outer function-scope level from looking like they are shadowing
1401 parameter declarations. */
1404 /* Expand the function arguments. Do this first so that any
1405 new registers get created before we allocate the maps. */
1407 arg_vals = (rtx *) alloca (nargs * sizeof (rtx));
1408 arg_trees = (tree *) alloca (nargs * sizeof (tree));
1410 for (formal = DECL_ARGUMENTS (fndecl), actual = parms, i = 0;
1412 formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual), i++)
1414 /* Actual parameter, converted to the type of the argument within the
1416 tree arg = convert (TREE_TYPE (formal), TREE_VALUE (actual));
1417 /* Mode of the variable used within the function. */
1418 enum machine_mode mode = TYPE_MODE (TREE_TYPE (formal));
1422 loc = RTVEC_ELT (arg_vector, i);
1424 /* If this is an object passed by invisible reference, we copy the
1425 object into a stack slot and save its address. If this will go
1426 into memory, we do nothing now. Otherwise, we just expand the
1428 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1429 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1432 = assign_stack_temp (TYPE_MODE (TREE_TYPE (arg)),
1433 int_size_in_bytes (TREE_TYPE (arg)), 1);
1434 MEM_SET_IN_STRUCT_P (stack_slot,
1435 AGGREGATE_TYPE_P (TREE_TYPE (arg)));
1437 store_expr (arg, stack_slot, 0);
1439 arg_vals[i] = XEXP (stack_slot, 0);
1442 else if (GET_CODE (loc) != MEM)
1444 if (GET_MODE (loc) != TYPE_MODE (TREE_TYPE (arg)))
1445 /* The mode if LOC and ARG can differ if LOC was a variable
1446 that had its mode promoted via PROMOTED_MODE. */
1447 arg_vals[i] = convert_modes (GET_MODE (loc),
1448 TYPE_MODE (TREE_TYPE (arg)),
1449 expand_expr (arg, NULL_RTX, mode,
1451 TREE_UNSIGNED (TREE_TYPE (formal)));
1453 arg_vals[i] = expand_expr (arg, NULL_RTX, mode, EXPAND_SUM);
1458 if (arg_vals[i] != 0
1459 && (! TREE_READONLY (formal)
1460 /* If the parameter is not read-only, copy our argument through
1461 a register. Also, we cannot use ARG_VALS[I] if it overlaps
1462 TARGET in any way. In the inline function, they will likely
1463 be two different pseudos, and `safe_from_p' will make all
1464 sorts of smart assumptions about their not conflicting.
1465 But if ARG_VALS[I] overlaps TARGET, these assumptions are
1466 wrong, so put ARG_VALS[I] into a fresh register.
1467 Don't worry about invisible references, since their stack
1468 temps will never overlap the target. */
1471 && (GET_CODE (arg_vals[i]) == REG
1472 || GET_CODE (arg_vals[i]) == SUBREG
1473 || GET_CODE (arg_vals[i]) == MEM)
1474 && reg_overlap_mentioned_p (arg_vals[i], target))
1475 /* ??? We must always copy a SUBREG into a REG, because it might
1476 get substituted into an address, and not all ports correctly
1477 handle SUBREGs in addresses. */
1478 || (GET_CODE (arg_vals[i]) == SUBREG)))
1479 arg_vals[i] = copy_to_mode_reg (GET_MODE (loc), arg_vals[i]);
1481 if (arg_vals[i] != 0 && GET_CODE (arg_vals[i]) == REG
1482 && POINTER_TYPE_P (TREE_TYPE (formal)))
1483 mark_reg_pointer (arg_vals[i],
1484 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (formal)))
1488 /* Allocate the structures we use to remap things. */
1490 map = (struct inline_remap *) alloca (sizeof (struct inline_remap));
1491 map->fndecl = fndecl;
1493 map->reg_map = (rtx *) alloca (max_regno * sizeof (rtx));
1494 bzero ((char *) map->reg_map, max_regno * sizeof (rtx));
1496 /* We used to use alloca here, but the size of what it would try to
1497 allocate would occasionally cause it to exceed the stack limit and
1498 cause unpredictable core dumps. */
1500 = (rtx *) xmalloc ((max_labelno) * sizeof (rtx));
1501 map->label_map = real_label_map;
1503 inl_max_uid = (inl_f->inl_emit->x_cur_insn_uid + 1);
1504 map->insn_map = (rtx *) alloca (inl_max_uid * sizeof (rtx));
1505 bzero ((char *) map->insn_map, inl_max_uid * sizeof (rtx));
1506 map->min_insnno = 0;
1507 map->max_insnno = inl_max_uid;
1509 map->integrating = 1;
1511 /* const_equiv_varray maps pseudos in our routine to constants, so
1512 it needs to be large enough for all our pseudos. This is the
1513 number we are currently using plus the number in the called
1514 routine, plus 15 for each arg, five to compute the virtual frame
1515 pointer, and five for the return value. This should be enough
1516 for most cases. We do not reference entries outside the range of
1519 ??? These numbers are quite arbitrary and were obtained by
1520 experimentation. At some point, we should try to allocate the
1521 table after all the parameters are set up so we an more accurately
1522 estimate the number of pseudos we will need. */
1524 VARRAY_CONST_EQUIV_INIT (map->const_equiv_varray,
1526 + (max_regno - FIRST_PSEUDO_REGISTER)
1529 "expand_inline_function");
1532 /* Record the current insn in case we have to set up pointers to frame
1533 and argument memory blocks. If there are no insns yet, add a dummy
1534 insn that can be used as an insertion point. */
1535 map->insns_at_start = get_last_insn ();
1536 if (map->insns_at_start == 0)
1537 map->insns_at_start = emit_note (NULL_PTR, NOTE_INSN_DELETED);
1539 map->regno_pointer_flag = inl_f->inl_emit->regno_pointer_flag;
1540 map->regno_pointer_align = inl_f->inl_emit->regno_pointer_align;
1542 /* Update the outgoing argument size to allow for those in the inlined
1544 if (inl_f->outgoing_args_size > current_function_outgoing_args_size)
1545 current_function_outgoing_args_size = inl_f->outgoing_args_size;
1547 /* If the inline function needs to make PIC references, that means
1548 that this function's PIC offset table must be used. */
1549 if (inl_f->uses_pic_offset_table)
1550 current_function_uses_pic_offset_table = 1;
1552 /* If this function needs a context, set it up. */
1553 if (inl_f->needs_context)
1554 static_chain_value = lookup_static_chain (fndecl);
1556 if (GET_CODE (parm_insns) == NOTE
1557 && NOTE_LINE_NUMBER (parm_insns) > 0)
1559 rtx note = emit_note (NOTE_SOURCE_FILE (parm_insns),
1560 NOTE_LINE_NUMBER (parm_insns));
1562 RTX_INTEGRATED_P (note) = 1;
1565 /* Process each argument. For each, set up things so that the function's
1566 reference to the argument will refer to the argument being passed.
1567 We only replace REG with REG here. Any simplifications are done
1568 via const_equiv_map.
1570 We make two passes: In the first, we deal with parameters that will
1571 be placed into registers, since we need to ensure that the allocated
1572 register number fits in const_equiv_map. Then we store all non-register
1573 parameters into their memory location. */
1575 /* Don't try to free temp stack slots here, because we may put one of the
1576 parameters into a temp stack slot. */
1578 for (i = 0; i < nargs; i++)
1580 rtx copy = arg_vals[i];
1582 loc = RTVEC_ELT (arg_vector, i);
1584 /* There are three cases, each handled separately. */
1585 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1586 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1588 /* This must be an object passed by invisible reference (it could
1589 also be a variable-sized object, but we forbid inlining functions
1590 with variable-sized arguments). COPY is the address of the
1591 actual value (this computation will cause it to be copied). We
1592 map that address for the register, noting the actual address as
1593 an equivalent in case it can be substituted into the insns. */
1595 if (GET_CODE (copy) != REG)
1597 temp = copy_addr_to_reg (copy);
1598 if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1599 SET_CONST_EQUIV_DATA (map, temp, copy, CONST_AGE_PARM);
1602 map->reg_map[REGNO (XEXP (loc, 0))] = copy;
1604 else if (GET_CODE (loc) == MEM)
1606 /* This is the case of a parameter that lives in memory.
1607 It will live in the block we allocate in the called routine's
1608 frame that simulates the incoming argument area. Do nothing
1609 now; we will call store_expr later. */
1612 else if (GET_CODE (loc) == REG)
1613 process_reg_param (map, loc, copy);
1614 else if (GET_CODE (loc) == CONCAT)
1616 rtx locreal = gen_realpart (GET_MODE (XEXP (loc, 0)), loc);
1617 rtx locimag = gen_imagpart (GET_MODE (XEXP (loc, 0)), loc);
1618 rtx copyreal = gen_realpart (GET_MODE (locreal), copy);
1619 rtx copyimag = gen_imagpart (GET_MODE (locimag), copy);
1621 process_reg_param (map, locreal, copyreal);
1622 process_reg_param (map, locimag, copyimag);
1628 /* Now do the parameters that will be placed in memory. */
1630 for (formal = DECL_ARGUMENTS (fndecl), i = 0;
1631 formal; formal = TREE_CHAIN (formal), i++)
1633 loc = RTVEC_ELT (arg_vector, i);
1635 if (GET_CODE (loc) == MEM
1636 /* Exclude case handled above. */
1637 && ! (GET_CODE (XEXP (loc, 0)) == REG
1638 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER))
1640 rtx note = emit_note (DECL_SOURCE_FILE (formal),
1641 DECL_SOURCE_LINE (formal));
1643 RTX_INTEGRATED_P (note) = 1;
1645 /* Compute the address in the area we reserved and store the
1647 temp = copy_rtx_and_substitute (loc, map);
1648 subst_constants (&temp, NULL_RTX, map);
1649 apply_change_group ();
1650 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
1651 temp = change_address (temp, VOIDmode, XEXP (temp, 0));
1652 store_expr (arg_trees[i], temp, 0);
1656 /* Deal with the places that the function puts its result.
1657 We are driven by what is placed into DECL_RESULT.
1659 Initially, we assume that we don't have anything special handling for
1660 REG_FUNCTION_RETURN_VALUE_P. */
1662 map->inline_target = 0;
1663 loc = DECL_RTL (DECL_RESULT (fndecl));
1665 if (TYPE_MODE (type) == VOIDmode)
1666 /* There is no return value to worry about. */
1668 else if (GET_CODE (loc) == MEM)
1670 if (GET_CODE (XEXP (loc, 0)) == ADDRESSOF)
1672 temp = copy_rtx_and_substitute (loc, map);
1673 subst_constants (&temp, NULL_RTX, map);
1674 apply_change_group ();
1679 if (! structure_value_addr
1680 || ! aggregate_value_p (DECL_RESULT (fndecl)))
1683 /* Pass the function the address in which to return a structure
1684 value. Note that a constructor can cause someone to call us
1685 with STRUCTURE_VALUE_ADDR, but the initialization takes place
1686 via the first parameter, rather than the struct return address.
1688 We have two cases: If the address is a simple register
1689 indirect, use the mapping mechanism to point that register to
1690 our structure return address. Otherwise, store the structure
1691 return value into the place that it will be referenced from. */
1693 if (GET_CODE (XEXP (loc, 0)) == REG)
1695 temp = force_operand (structure_value_addr, NULL_RTX);
1696 temp = force_reg (Pmode, temp);
1697 map->reg_map[REGNO (XEXP (loc, 0))] = temp;
1699 if (CONSTANT_P (structure_value_addr)
1700 || GET_CODE (structure_value_addr) == ADDRESSOF
1701 || (GET_CODE (structure_value_addr) == PLUS
1702 && (XEXP (structure_value_addr, 0)
1703 == virtual_stack_vars_rtx)
1704 && (GET_CODE (XEXP (structure_value_addr, 1))
1707 SET_CONST_EQUIV_DATA (map, temp, structure_value_addr,
1713 temp = copy_rtx_and_substitute (loc, map);
1714 subst_constants (&temp, NULL_RTX, map);
1715 apply_change_group ();
1716 emit_move_insn (temp, structure_value_addr);
1721 /* We will ignore the result value, so don't look at its structure.
1722 Note that preparations for an aggregate return value
1723 do need to be made (above) even if it will be ignored. */
1725 else if (GET_CODE (loc) == REG)
1727 /* The function returns an object in a register and we use the return
1728 value. Set up our target for remapping. */
1730 /* Machine mode function was declared to return. */
1731 enum machine_mode departing_mode = TYPE_MODE (type);
1732 /* (Possibly wider) machine mode it actually computes
1733 (for the sake of callers that fail to declare it right).
1734 We have to use the mode of the result's RTL, rather than
1735 its type, since expand_function_start may have promoted it. */
1736 enum machine_mode arriving_mode
1737 = GET_MODE (DECL_RTL (DECL_RESULT (fndecl)));
1740 /* Don't use MEMs as direct targets because on some machines
1741 substituting a MEM for a REG makes invalid insns.
1742 Let the combiner substitute the MEM if that is valid. */
1743 if (target == 0 || GET_CODE (target) != REG
1744 || GET_MODE (target) != departing_mode)
1746 /* Don't make BLKmode registers. If this looks like
1747 a BLKmode object being returned in a register, get
1748 the mode from that, otherwise abort. */
1749 if (departing_mode == BLKmode)
1751 if (REG == GET_CODE (DECL_RTL (DECL_RESULT (fndecl))))
1753 departing_mode = GET_MODE (DECL_RTL (DECL_RESULT (fndecl)));
1754 arriving_mode = departing_mode;
1760 target = gen_reg_rtx (departing_mode);
1763 /* If function's value was promoted before return,
1764 avoid machine mode mismatch when we substitute INLINE_TARGET.
1765 But TARGET is what we will return to the caller. */
1766 if (arriving_mode != departing_mode)
1768 /* Avoid creating a paradoxical subreg wider than
1769 BITS_PER_WORD, since that is illegal. */
1770 if (GET_MODE_BITSIZE (arriving_mode) > BITS_PER_WORD)
1772 if (!TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (departing_mode),
1773 GET_MODE_BITSIZE (arriving_mode)))
1774 /* Maybe could be handled by using convert_move () ? */
1776 reg_to_map = gen_reg_rtx (arriving_mode);
1777 target = gen_lowpart (departing_mode, reg_to_map);
1780 reg_to_map = gen_rtx_SUBREG (arriving_mode, target, 0);
1783 reg_to_map = target;
1785 /* Usually, the result value is the machine's return register.
1786 Sometimes it may be a pseudo. Handle both cases. */
1787 if (REG_FUNCTION_VALUE_P (loc))
1788 map->inline_target = reg_to_map;
1790 map->reg_map[REGNO (loc)] = reg_to_map;
1795 /* Make a fresh binding contour that we can easily remove. Do this after
1796 expanding our arguments so cleanups are properly scoped. */
1798 expand_start_bindings (0);
1800 /* Initialize label_map. get_label_from_map will actually make
1802 bzero ((char *) &map->label_map [min_labelno],
1803 (max_labelno - min_labelno) * sizeof (rtx));
1805 /* Perform postincrements before actually calling the function. */
1808 /* Clean up stack so that variables might have smaller offsets. */
1809 do_pending_stack_adjust ();
1811 /* Save a copy of the location of const_equiv_varray for
1812 mark_stores, called via note_stores. */
1813 global_const_equiv_varray = map->const_equiv_varray;
1815 /* If the called function does an alloca, save and restore the
1816 stack pointer around the call. This saves stack space, but
1817 also is required if this inline is being done between two
1819 if (inl_f->calls_alloca)
1820 emit_stack_save (SAVE_BLOCK, &stack_save, NULL_RTX);
1822 /* Now copy the insns one by one. Do this in two passes, first the insns and
1823 then their REG_NOTES, just like save_for_inline. */
1825 /* This loop is very similar to the loop in copy_loop_body in unroll.c. */
1827 for (insn = insns; insn; insn = NEXT_INSN (insn))
1829 rtx copy, pattern, set;
1831 map->orig_asm_operands_vector = 0;
1833 switch (GET_CODE (insn))
1836 pattern = PATTERN (insn);
1837 set = single_set (insn);
1839 if (GET_CODE (pattern) == USE
1840 && GET_CODE (XEXP (pattern, 0)) == REG
1841 && REG_FUNCTION_VALUE_P (XEXP (pattern, 0)))
1842 /* The (USE (REG n)) at return from the function should
1843 be ignored since we are changing (REG n) into
1847 /* If the inline fn needs eh context, make sure that
1848 the current fn has one. */
1849 if (GET_CODE (pattern) == USE
1850 && find_reg_note (insn, REG_EH_CONTEXT, 0) != 0)
1853 /* Ignore setting a function value that we don't want to use. */
1854 if (map->inline_target == 0
1856 && GET_CODE (SET_DEST (set)) == REG
1857 && REG_FUNCTION_VALUE_P (SET_DEST (set)))
1859 if (volatile_refs_p (SET_SRC (set)))
1863 /* If we must not delete the source,
1864 load it into a new temporary. */
1865 copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1867 new_set = single_set (copy);
1872 = gen_reg_rtx (GET_MODE (SET_DEST (new_set)));
1874 /* If the source and destination are the same and it
1875 has a note on it, keep the insn. */
1876 else if (rtx_equal_p (SET_DEST (set), SET_SRC (set))
1877 && REG_NOTES (insn) != 0)
1878 copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1883 /* If this is setting the static chain rtx, omit it. */
1884 else if (static_chain_value != 0
1886 && GET_CODE (SET_DEST (set)) == REG
1887 && rtx_equal_p (SET_DEST (set),
1888 static_chain_incoming_rtx))
1891 /* If this is setting the static chain pseudo, set it from
1892 the value we want to give it instead. */
1893 else if (static_chain_value != 0
1895 && rtx_equal_p (SET_SRC (set),
1896 static_chain_incoming_rtx))
1898 rtx newdest = copy_rtx_and_substitute (SET_DEST (set), map);
1900 copy = emit_move_insn (newdest, static_chain_value);
1901 static_chain_value = 0;
1904 copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1905 /* REG_NOTES will be copied later. */
1908 /* If this insn is setting CC0, it may need to look at
1909 the insn that uses CC0 to see what type of insn it is.
1910 In that case, the call to recog via validate_change will
1911 fail. So don't substitute constants here. Instead,
1912 do it when we emit the following insn.
1914 For example, see the pyr.md file. That machine has signed and
1915 unsigned compares. The compare patterns must check the
1916 following branch insn to see which what kind of compare to
1919 If the previous insn set CC0, substitute constants on it as
1921 if (sets_cc0_p (PATTERN (copy)) != 0)
1926 try_constants (cc0_insn, map);
1928 try_constants (copy, map);
1931 try_constants (copy, map);
1936 if (GET_CODE (PATTERN (insn)) == RETURN
1937 || (GET_CODE (PATTERN (insn)) == PARALLEL
1938 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN))
1940 if (local_return_label == 0)
1941 local_return_label = gen_label_rtx ();
1942 pattern = gen_jump (local_return_label);
1945 pattern = copy_rtx_and_substitute (PATTERN (insn), map);
1947 copy = emit_jump_insn (pattern);
1951 try_constants (cc0_insn, map);
1954 try_constants (copy, map);
1956 /* If this used to be a conditional jump insn but whose branch
1957 direction is now know, we must do something special. */
1958 if (condjump_p (insn) && ! simplejump_p (insn) && map->last_pc_value)
1961 /* The previous insn set cc0 for us. So delete it. */
1962 delete_insn (PREV_INSN (copy));
1965 /* If this is now a no-op, delete it. */
1966 if (map->last_pc_value == pc_rtx)
1972 /* Otherwise, this is unconditional jump so we must put a
1973 BARRIER after it. We could do some dead code elimination
1974 here, but jump.c will do it just as well. */
1980 pattern = copy_rtx_and_substitute (PATTERN (insn), map);
1981 copy = emit_call_insn (pattern);
1983 /* Because the USAGE information potentially contains objects other
1984 than hard registers, we need to copy it. */
1985 CALL_INSN_FUNCTION_USAGE (copy)
1986 = copy_rtx_and_substitute (CALL_INSN_FUNCTION_USAGE (insn), map);
1990 try_constants (cc0_insn, map);
1993 try_constants (copy, map);
1995 /* Be lazy and assume CALL_INSNs clobber all hard registers. */
1996 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1997 VARRAY_CONST_EQUIV (map->const_equiv_varray, i).rtx = 0;
2001 copy = emit_label (get_label_from_map (map,
2002 CODE_LABEL_NUMBER (insn)));
2003 LABEL_NAME (copy) = LABEL_NAME (insn);
2008 copy = emit_barrier ();
2012 /* It is important to discard function-end and function-beg notes,
2013 so we have only one of each in the current function.
2014 Also, NOTE_INSN_DELETED notes aren't useful (save_for_inline
2015 deleted these in the copy used for continuing compilation,
2016 not the copy used for inlining). */
2017 if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END
2018 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_BEG
2019 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
2021 copy = emit_note (NOTE_SOURCE_FILE (insn),
2022 NOTE_LINE_NUMBER (insn));
2024 && (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG
2025 || NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_END))
2028 = get_label_from_map (map, NOTE_BLOCK_NUMBER (copy));
2030 /* we have to duplicate the handlers for the original */
2031 if (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG)
2033 /* We need to duplicate the handlers for the EH region
2034 and we need to indicate where the label map is */
2036 duplicate_eh_handlers (NOTE_BLOCK_NUMBER (copy),
2037 CODE_LABEL_NUMBER (label),
2038 expand_inline_function_eh_labelmap);
2041 /* We have to forward these both to match the new exception
2043 NOTE_BLOCK_NUMBER (copy) = CODE_LABEL_NUMBER (label);
2056 RTX_INTEGRATED_P (copy) = 1;
2058 map->insn_map[INSN_UID (insn)] = copy;
2061 /* Now copy the REG_NOTES. Increment const_age, so that only constants
2062 from parameters can be substituted in. These are the only ones that
2063 are valid across the entire function. */
2065 for (insn = insns; insn; insn = NEXT_INSN (insn))
2066 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2067 && map->insn_map[INSN_UID (insn)]
2068 && REG_NOTES (insn))
2070 rtx tem = copy_rtx_and_substitute (REG_NOTES (insn), map);
2071 /* We must also do subst_constants, in case one of our parameters
2072 has const type and constant value. */
2073 subst_constants (&tem, NULL_RTX, map);
2074 apply_change_group ();
2075 REG_NOTES (map->insn_map[INSN_UID (insn)]) = tem;
2078 if (local_return_label)
2079 emit_label (local_return_label);
2081 /* Restore the stack pointer if we saved it above. */
2082 if (inl_f->calls_alloca)
2083 emit_stack_restore (SAVE_BLOCK, stack_save, NULL_RTX);
2085 /* Make copies of the decls of the symbols in the inline function, so that
2086 the copies of the variables get declared in the current function. Set
2087 up things so that lookup_static_chain knows that to interpret registers
2088 in SAVE_EXPRs for TYPE_SIZEs as local. */
2090 inline_function_decl = fndecl;
2091 integrate_parm_decls (DECL_ARGUMENTS (fndecl), map, arg_vector);
2092 integrate_decl_tree (inl_f->original_decl_initial, 0, map);
2093 inline_function_decl = 0;
2095 /* End the scope containing the copied formal parameter variables
2096 and copied LABEL_DECLs. */
2098 expand_end_bindings (getdecls (), 1, 1);
2099 block = poplevel (1, 1, 0);
2100 BLOCK_ABSTRACT_ORIGIN (block) = (DECL_ABSTRACT_ORIGIN (fndecl) == NULL
2101 ? fndecl : DECL_ABSTRACT_ORIGIN (fndecl));
2104 /* Must mark the line number note after inlined functions as a repeat, so
2105 that the test coverage code can avoid counting the call twice. This
2106 just tells the code to ignore the immediately following line note, since
2107 there already exists a copy of this note before the expanded inline call.
2108 This line number note is still needed for debugging though, so we can't
2110 if (flag_test_coverage)
2111 emit_note (0, NOTE_REPEATED_LINE_NUMBER);
2113 emit_line_note (input_filename, lineno);
2115 /* If the function returns a BLKmode object in a register, copy it
2116 out of the temp register into a BLKmode memory object. */
2117 if (TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == BLKmode
2118 && ! aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl))))
2119 target = copy_blkmode_from_reg (0, target, TREE_TYPE (TREE_TYPE (fndecl)));
2121 if (structure_value_addr)
2123 target = gen_rtx_MEM (TYPE_MODE (type),
2124 memory_address (TYPE_MODE (type),
2125 structure_value_addr));
2126 MEM_SET_IN_STRUCT_P (target, 1);
2129 /* Make sure we free the things we explicitly allocated with xmalloc. */
2131 free (real_label_map);
2133 VARRAY_FREE (map->const_equiv_varray);
2138 /* Given a chain of PARM_DECLs, ARGS, copy each decl into a VAR_DECL,
2139 push all of those decls and give each one the corresponding home. */
2142 integrate_parm_decls (args, map, arg_vector)
2144 struct inline_remap *map;
2150 for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
2152 register tree decl = build_decl (VAR_DECL, DECL_NAME (tail),
2155 = copy_rtx_and_substitute (RTVEC_ELT (arg_vector, i), map);
2157 DECL_ARG_TYPE (decl) = DECL_ARG_TYPE (tail);
2158 /* We really should be setting DECL_INCOMING_RTL to something reasonable
2159 here, but that's going to require some more work. */
2160 /* DECL_INCOMING_RTL (decl) = ?; */
2161 /* These args would always appear unused, if not for this. */
2162 TREE_USED (decl) = 1;
2163 /* Prevent warning for shadowing with these. */
2164 DECL_ABSTRACT_ORIGIN (decl) = DECL_ORIGIN (tail);
2166 /* Fully instantiate the address with the equivalent form so that the
2167 debugging information contains the actual register, instead of the
2168 virtual register. Do this by not passing an insn to
2170 subst_constants (&new_decl_rtl, NULL_RTX, map);
2171 apply_change_group ();
2172 DECL_RTL (decl) = new_decl_rtl;
2176 /* Given a BLOCK node LET, push decls and levels so as to construct in the
2177 current function a tree of contexts isomorphic to the one that is given.
2179 LEVEL indicates how far down into the BLOCK tree is the node we are
2180 currently traversing. It is always zero except for recursive calls.
2182 MAP, if nonzero, is a pointer to an inline_remap map which indicates how
2183 registers used in the DECL_RTL field should be remapped. If it is zero,
2184 no mapping is necessary. */
2187 integrate_decl_tree (let, level, map)
2190 struct inline_remap *map;
2197 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2201 push_obstacks_nochange ();
2202 saveable_allocation ();
2203 d = copy_and_set_decl_abstract_origin (t);
2206 if (DECL_RTL (t) != 0)
2208 DECL_RTL (d) = copy_rtx_and_substitute (DECL_RTL (t), map);
2209 /* Fully instantiate the address with the equivalent form so that the
2210 debugging information contains the actual register, instead of the
2211 virtual register. Do this by not passing an insn to
2213 subst_constants (&DECL_RTL (d), NULL_RTX, map);
2214 apply_change_group ();
2216 /* These args would always appear unused, if not for this. */
2219 if (DECL_LANG_SPECIFIC (d))
2225 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2226 integrate_decl_tree (t, level + 1, map);
2230 node = poplevel (1, 0, 0);
2233 TREE_USED (node) = TREE_USED (let);
2234 BLOCK_ABSTRACT_ORIGIN (node) = let;
2239 /* Given a BLOCK node LET, search for all DECL_RTL fields, and pass them
2240 through save_constants. */
2243 save_constants_in_decl_trees (let)
2248 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2249 if (DECL_RTL (t) != 0)
2250 save_constants (&DECL_RTL (t));
2252 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2253 save_constants_in_decl_trees (t);
2256 /* Create a new copy of an rtx.
2257 Recursively copies the operands of the rtx,
2258 except for those few rtx codes that are sharable.
2260 We always return an rtx that is similar to that incoming rtx, with the
2261 exception of possibly changing a REG to a SUBREG or vice versa. No
2262 rtl is ever emitted.
2264 Handle constants that need to be placed in the constant pool by
2265 calling `force_const_mem'. */
2268 copy_rtx_and_substitute (orig, map)
2270 struct inline_remap *map;
2272 register rtx copy, temp;
2274 register RTX_CODE code;
2275 register enum machine_mode mode;
2276 register char *format_ptr;
2282 code = GET_CODE (orig);
2283 mode = GET_MODE (orig);
2288 /* If the stack pointer register shows up, it must be part of
2289 stack-adjustments (*not* because we eliminated the frame pointer!).
2290 Small hard registers are returned as-is. Pseudo-registers
2291 go through their `reg_map'. */
2292 regno = REGNO (orig);
2293 if (regno <= LAST_VIRTUAL_REGISTER)
2295 /* Some hard registers are also mapped,
2296 but others are not translated. */
2297 if (map->reg_map[regno] != 0)
2298 return map->reg_map[regno];
2300 /* If this is the virtual frame pointer, make space in current
2301 function's stack frame for the stack frame of the inline function.
2303 Copy the address of this area into a pseudo. Map
2304 virtual_stack_vars_rtx to this pseudo and set up a constant
2305 equivalence for it to be the address. This will substitute the
2306 address into insns where it can be substituted and use the new
2307 pseudo where it can't. */
2308 if (regno == VIRTUAL_STACK_VARS_REGNUM)
2311 int size = get_func_frame_size (DECL_SAVED_INSNS (map->fndecl));
2313 #ifdef FRAME_GROWS_DOWNWARD
2314 /* In this case, virtual_stack_vars_rtx points to one byte
2315 higher than the top of the frame area. So make sure we
2316 allocate a big enough chunk to keep the frame pointer
2317 aligned like a real one. */
2318 size = CEIL_ROUND (size, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2321 loc = assign_stack_temp (BLKmode, size, 1);
2322 loc = XEXP (loc, 0);
2323 #ifdef FRAME_GROWS_DOWNWARD
2324 /* In this case, virtual_stack_vars_rtx points to one byte
2325 higher than the top of the frame area. So compute the offset
2326 to one byte higher than our substitute frame. */
2327 loc = plus_constant (loc, size);
2329 map->reg_map[regno] = temp
2330 = force_reg (Pmode, force_operand (loc, NULL_RTX));
2332 #ifdef STACK_BOUNDARY
2333 mark_reg_pointer (map->reg_map[regno],
2334 STACK_BOUNDARY / BITS_PER_UNIT);
2337 SET_CONST_EQUIV_DATA (map, temp, loc, CONST_AGE_PARM);
2339 seq = gen_sequence ();
2341 emit_insn_after (seq, map->insns_at_start);
2344 else if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
2346 /* Do the same for a block to contain any arguments referenced
2349 int size = DECL_SAVED_INSNS (map->fndecl)->args_size;
2352 loc = assign_stack_temp (BLKmode, size, 1);
2353 loc = XEXP (loc, 0);
2354 /* When arguments grow downward, the virtual incoming
2355 args pointer points to the top of the argument block,
2356 so the remapped location better do the same. */
2357 #ifdef ARGS_GROW_DOWNWARD
2358 loc = plus_constant (loc, size);
2360 map->reg_map[regno] = temp
2361 = force_reg (Pmode, force_operand (loc, NULL_RTX));
2363 #ifdef STACK_BOUNDARY
2364 mark_reg_pointer (map->reg_map[regno],
2365 STACK_BOUNDARY / BITS_PER_UNIT);
2368 SET_CONST_EQUIV_DATA (map, temp, loc, CONST_AGE_PARM);
2370 seq = gen_sequence ();
2372 emit_insn_after (seq, map->insns_at_start);
2375 else if (REG_FUNCTION_VALUE_P (orig))
2377 /* This is a reference to the function return value. If
2378 the function doesn't have a return value, error. If the
2379 mode doesn't agree, and it ain't BLKmode, make a SUBREG. */
2380 if (map->inline_target == 0)
2381 /* Must be unrolling loops or replicating code if we
2382 reach here, so return the register unchanged. */
2384 else if (GET_MODE (map->inline_target) != BLKmode
2385 && mode != GET_MODE (map->inline_target))
2386 return gen_lowpart (mode, map->inline_target);
2388 return map->inline_target;
2392 if (map->reg_map[regno] == NULL)
2394 map->reg_map[regno] = gen_reg_rtx (mode);
2395 REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (orig);
2396 REG_LOOP_TEST_P (map->reg_map[regno]) = REG_LOOP_TEST_P (orig);
2397 RTX_UNCHANGING_P (map->reg_map[regno]) = RTX_UNCHANGING_P (orig);
2398 /* A reg with REG_FUNCTION_VALUE_P true will never reach here. */
2400 if (map->regno_pointer_flag[regno])
2401 mark_reg_pointer (map->reg_map[regno],
2402 map->regno_pointer_align[regno]);
2404 return map->reg_map[regno];
2407 copy = copy_rtx_and_substitute (SUBREG_REG (orig), map);
2408 /* SUBREG is ordinary, but don't make nested SUBREGs. */
2409 if (GET_CODE (copy) == SUBREG)
2410 return gen_rtx_SUBREG (GET_MODE (orig), SUBREG_REG (copy),
2411 SUBREG_WORD (orig) + SUBREG_WORD (copy));
2412 else if (GET_CODE (copy) == CONCAT)
2414 rtx retval = subreg_realpart_p (orig) ? XEXP (copy, 0) : XEXP (copy, 1);
2416 if (GET_MODE (retval) == GET_MODE (orig))
2419 return gen_rtx_SUBREG (GET_MODE (orig), retval,
2420 (SUBREG_WORD (orig) %
2421 (GET_MODE_UNIT_SIZE (GET_MODE (SUBREG_REG (orig)))
2422 / (unsigned) UNITS_PER_WORD)));
2425 return gen_rtx_SUBREG (GET_MODE (orig), copy,
2426 SUBREG_WORD (orig));
2429 copy = gen_rtx_ADDRESSOF (mode,
2430 copy_rtx_and_substitute (XEXP (orig, 0), map), 0);
2431 SET_ADDRESSOF_DECL (copy, ADDRESSOF_DECL (orig));
2432 regno = ADDRESSOF_REGNO (orig);
2433 if (map->reg_map[regno])
2434 regno = REGNO (map->reg_map[regno]);
2435 else if (regno > LAST_VIRTUAL_REGISTER)
2437 temp = XEXP (orig, 0);
2438 map->reg_map[regno] = gen_reg_rtx (GET_MODE (temp));
2439 REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (temp);
2440 REG_LOOP_TEST_P (map->reg_map[regno]) = REG_LOOP_TEST_P (temp);
2441 RTX_UNCHANGING_P (map->reg_map[regno]) = RTX_UNCHANGING_P (temp);
2442 /* A reg with REG_FUNCTION_VALUE_P true will never reach here. */
2444 if (map->regno_pointer_flag[regno])
2445 mark_reg_pointer (map->reg_map[regno],
2446 map->regno_pointer_align[regno]);
2447 regno = REGNO (map->reg_map[regno]);
2449 ADDRESSOF_REGNO (copy) = regno;
2454 /* USE and CLOBBER are ordinary, but we convert (use (subreg foo))
2455 to (use foo) if the original insn didn't have a subreg.
2456 Removing the subreg distorts the VAX movstrhi pattern
2457 by changing the mode of an operand. */
2458 copy = copy_rtx_and_substitute (XEXP (orig, 0), map);
2459 if (GET_CODE (copy) == SUBREG && GET_CODE (XEXP (orig, 0)) != SUBREG)
2460 copy = SUBREG_REG (copy);
2461 return gen_rtx_fmt_e (code, VOIDmode, copy);
2464 LABEL_PRESERVE_P (get_label_from_map (map, CODE_LABEL_NUMBER (orig)))
2465 = LABEL_PRESERVE_P (orig);
2466 return get_label_from_map (map, CODE_LABEL_NUMBER (orig));
2469 copy = gen_rtx_LABEL_REF (mode,
2470 LABEL_REF_NONLOCAL_P (orig) ? XEXP (orig, 0)
2471 : get_label_from_map (map,
2472 CODE_LABEL_NUMBER (XEXP (orig, 0))));
2473 LABEL_OUTSIDE_LOOP_P (copy) = LABEL_OUTSIDE_LOOP_P (orig);
2475 /* The fact that this label was previously nonlocal does not mean
2476 it still is, so we must check if it is within the range of
2477 this function's labels. */
2478 LABEL_REF_NONLOCAL_P (copy)
2479 = (LABEL_REF_NONLOCAL_P (orig)
2480 && ! (CODE_LABEL_NUMBER (XEXP (copy, 0)) >= get_first_label_num ()
2481 && CODE_LABEL_NUMBER (XEXP (copy, 0)) < max_label_num ()));
2483 /* If we have made a nonlocal label local, it means that this
2484 inlined call will be referring to our nonlocal goto handler.
2485 So make sure we create one for this block; we normally would
2486 not since this is not otherwise considered a "call". */
2487 if (LABEL_REF_NONLOCAL_P (orig) && ! LABEL_REF_NONLOCAL_P (copy))
2488 function_call_count++;
2498 /* Symbols which represent the address of a label stored in the constant
2499 pool must be modified to point to a constant pool entry for the
2500 remapped label. Otherwise, symbols are returned unchanged. */
2501 if (CONSTANT_POOL_ADDRESS_P (orig))
2503 rtx constant = get_pool_constant (orig);
2504 if (GET_CODE (constant) == LABEL_REF)
2505 return XEXP (force_const_mem (GET_MODE (orig),
2506 copy_rtx_and_substitute (constant,
2511 if (SYMBOL_REF_NEED_ADJUST (orig))
2514 return rethrow_symbol_map (orig,
2515 expand_inline_function_eh_labelmap);
2521 /* We have to make a new copy of this CONST_DOUBLE because don't want
2522 to use the old value of CONST_DOUBLE_MEM. Also, this may be a
2523 duplicate of a CONST_DOUBLE we have already seen. */
2524 if (GET_MODE_CLASS (GET_MODE (orig)) == MODE_FLOAT)
2528 REAL_VALUE_FROM_CONST_DOUBLE (d, orig);
2529 return CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (orig));
2532 return immed_double_const (CONST_DOUBLE_LOW (orig),
2533 CONST_DOUBLE_HIGH (orig), VOIDmode);
2536 /* Make new constant pool entry for a constant
2537 that was in the pool of the inline function. */
2538 if (RTX_INTEGRATED_P (orig))
2540 /* If this was an address of a constant pool entry that itself
2541 had to be placed in the constant pool, it might not be a
2542 valid address. So the recursive call below might turn it
2543 into a register. In that case, it isn't a constant any
2544 more, so return it. This has the potential of changing a
2545 MEM into a REG, but we'll assume that it safe. */
2546 temp = copy_rtx_and_substitute (XEXP (orig, 0), map);
2547 if (! CONSTANT_P (temp))
2549 return validize_mem (force_const_mem (GET_MODE (orig), temp));
2554 /* If from constant pool address, make new constant pool entry and
2555 return its address. */
2556 if (! RTX_INTEGRATED_P (orig))
2560 = force_const_mem (GET_MODE (XEXP (orig, 0)),
2561 copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0),
2565 /* Legitimizing the address here is incorrect.
2567 The only ADDRESS rtx's that can reach here are ones created by
2568 save_constants. Hence the operand of the ADDRESS is always valid
2569 in this position of the instruction, since the original rtx without
2570 the ADDRESS was valid.
2572 The reason we don't legitimize the address here is that on the
2573 Sparc, the caller may have a (high ...) surrounding this ADDRESS.
2574 This code forces the operand of the address to a register, which
2575 fails because we can not take the HIGH part of a register.
2577 Also, change_address may create new registers. These registers
2578 will not have valid reg_map entries. This can cause try_constants()
2579 to fail because assumes that all registers in the rtx have valid
2580 reg_map entries, and it may end up replacing one of these new
2581 registers with junk. */
2583 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
2584 temp = change_address (temp, GET_MODE (temp), XEXP (temp, 0));
2587 temp = XEXP (temp, 0);
2589 #ifdef POINTERS_EXTEND_UNSIGNED
2590 if (GET_MODE (temp) != GET_MODE (orig))
2591 temp = convert_memory_address (GET_MODE (orig), temp);
2597 /* If a single asm insn contains multiple output operands
2598 then it contains multiple ASM_OPERANDS rtx's that share operand 3.
2599 We must make sure that the copied insn continues to share it. */
2600 if (map->orig_asm_operands_vector == XVEC (orig, 3))
2602 copy = rtx_alloc (ASM_OPERANDS);
2603 copy->volatil = orig->volatil;
2604 XSTR (copy, 0) = XSTR (orig, 0);
2605 XSTR (copy, 1) = XSTR (orig, 1);
2606 XINT (copy, 2) = XINT (orig, 2);
2607 XVEC (copy, 3) = map->copy_asm_operands_vector;
2608 XVEC (copy, 4) = map->copy_asm_constraints_vector;
2609 XSTR (copy, 5) = XSTR (orig, 5);
2610 XINT (copy, 6) = XINT (orig, 6);
2616 /* This is given special treatment because the first
2617 operand of a CALL is a (MEM ...) which may get
2618 forced into a register for cse. This is undesirable
2619 if function-address cse isn't wanted or if we won't do cse. */
2620 #ifndef NO_FUNCTION_CSE
2621 if (! (optimize && ! flag_no_function_cse))
2623 return gen_rtx_CALL (GET_MODE (orig),
2624 gen_rtx_MEM (GET_MODE (XEXP (orig, 0)),
2625 copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0), map)),
2626 copy_rtx_and_substitute (XEXP (orig, 1), map));
2630 /* Must be ifdefed out for loop unrolling to work. */
2636 /* If this is setting fp or ap, it means that we have a nonlocal goto.
2637 Adjust the setting by the offset of the area we made.
2638 If the nonlocal goto is into the current function,
2639 this will result in unnecessarily bad code, but should work. */
2640 if (SET_DEST (orig) == virtual_stack_vars_rtx
2641 || SET_DEST (orig) == virtual_incoming_args_rtx)
2643 /* In case a translation hasn't occurred already, make one now. */
2646 HOST_WIDE_INT loc_offset;
2648 copy_rtx_and_substitute (SET_DEST (orig), map);
2649 equiv_reg = map->reg_map[REGNO (SET_DEST (orig))];
2650 equiv_loc = VARRAY_CONST_EQUIV (map->const_equiv_varray, REGNO (equiv_reg)).rtx;
2652 = GET_CODE (equiv_loc) == REG ? 0 : INTVAL (XEXP (equiv_loc, 1));
2653 return gen_rtx_SET (VOIDmode, SET_DEST (orig),
2656 (copy_rtx_and_substitute (SET_SRC (orig), map),
2663 copy = rtx_alloc (MEM);
2664 PUT_MODE (copy, mode);
2665 XEXP (copy, 0) = copy_rtx_and_substitute (XEXP (orig, 0), map);
2666 MEM_COPY_ATTRIBUTES (copy, orig);
2667 MEM_ALIAS_SET (copy) = MEM_ALIAS_SET (orig);
2669 /* If doing function inlining, this MEM might not be const in the
2670 function that it is being inlined into, and thus may not be
2671 unchanging after function inlining. Constant pool references are
2672 handled elsewhere, so this doesn't lose RTX_UNCHANGING_P bits
2674 if (! map->integrating)
2675 RTX_UNCHANGING_P (copy) = RTX_UNCHANGING_P (orig);
2683 copy = rtx_alloc (code);
2684 PUT_MODE (copy, mode);
2685 copy->in_struct = orig->in_struct;
2686 copy->volatil = orig->volatil;
2687 copy->unchanging = orig->unchanging;
2689 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
2691 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
2693 switch (*format_ptr++)
2696 XEXP (copy, i) = XEXP (orig, i);
2700 XEXP (copy, i) = copy_rtx_and_substitute (XEXP (orig, i), map);
2704 /* Change any references to old-insns to point to the
2705 corresponding copied insns. */
2706 XEXP (copy, i) = map->insn_map[INSN_UID (XEXP (orig, i))];
2710 XVEC (copy, i) = XVEC (orig, i);
2711 if (XVEC (orig, i) != NULL && XVECLEN (orig, i) != 0)
2713 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
2714 for (j = 0; j < XVECLEN (copy, i); j++)
2715 XVECEXP (copy, i, j)
2716 = copy_rtx_and_substitute (XVECEXP (orig, i, j), map);
2721 XWINT (copy, i) = XWINT (orig, i);
2725 XINT (copy, i) = XINT (orig, i);
2729 XSTR (copy, i) = XSTR (orig, i);
2737 if (code == ASM_OPERANDS && map->orig_asm_operands_vector == 0)
2739 map->orig_asm_operands_vector = XVEC (orig, 3);
2740 map->copy_asm_operands_vector = XVEC (copy, 3);
2741 map->copy_asm_constraints_vector = XVEC (copy, 4);
2747 /* Substitute known constant values into INSN, if that is valid. */
2750 try_constants (insn, map)
2752 struct inline_remap *map;
2757 subst_constants (&PATTERN (insn), insn, map);
2759 /* Apply the changes if they are valid; otherwise discard them. */
2760 apply_change_group ();
2762 /* Show we don't know the value of anything stored or clobbered. */
2763 note_stores (PATTERN (insn), mark_stores);
2764 map->last_pc_value = 0;
2766 map->last_cc0_value = 0;
2769 /* Set up any constant equivalences made in this insn. */
2770 for (i = 0; i < map->num_sets; i++)
2772 if (GET_CODE (map->equiv_sets[i].dest) == REG)
2774 int regno = REGNO (map->equiv_sets[i].dest);
2776 MAYBE_EXTEND_CONST_EQUIV_VARRAY (map, regno);
2777 if (VARRAY_CONST_EQUIV (map->const_equiv_varray, regno).rtx == 0
2778 /* Following clause is a hack to make case work where GNU C++
2779 reassigns a variable to make cse work right. */
2780 || ! rtx_equal_p (VARRAY_CONST_EQUIV (map->const_equiv_varray,
2782 map->equiv_sets[i].equiv))
2783 SET_CONST_EQUIV_DATA (map, map->equiv_sets[i].dest,
2784 map->equiv_sets[i].equiv, map->const_age);
2786 else if (map->equiv_sets[i].dest == pc_rtx)
2787 map->last_pc_value = map->equiv_sets[i].equiv;
2789 else if (map->equiv_sets[i].dest == cc0_rtx)
2790 map->last_cc0_value = map->equiv_sets[i].equiv;
2795 /* Substitute known constants for pseudo regs in the contents of LOC,
2796 which are part of INSN.
2797 If INSN is zero, the substitution should always be done (this is used to
2799 These changes are taken out by try_constants if the result is not valid.
2801 Note that we are more concerned with determining when the result of a SET
2802 is a constant, for further propagation, than actually inserting constants
2803 into insns; cse will do the latter task better.
2805 This function is also used to adjust address of items previously addressed
2806 via the virtual stack variable or virtual incoming arguments registers. */
2809 subst_constants (loc, insn, map)
2812 struct inline_remap *map;
2816 register enum rtx_code code;
2817 register char *format_ptr;
2818 int num_changes = num_validated_changes ();
2820 enum machine_mode op0_mode = MAX_MACHINE_MODE;
2822 code = GET_CODE (x);
2837 validate_change (insn, loc, map->last_cc0_value, 1);
2843 /* The only thing we can do with a USE or CLOBBER is possibly do
2844 some substitutions in a MEM within it. */
2845 if (GET_CODE (XEXP (x, 0)) == MEM)
2846 subst_constants (&XEXP (XEXP (x, 0), 0), insn, map);
2850 /* Substitute for parms and known constants. Don't replace
2851 hard regs used as user variables with constants. */
2853 int regno = REGNO (x);
2854 struct const_equiv_data *p;
2856 if (! (regno < FIRST_PSEUDO_REGISTER && REG_USERVAR_P (x))
2857 && regno < VARRAY_SIZE (map->const_equiv_varray)
2858 && (p = &VARRAY_CONST_EQUIV (map->const_equiv_varray, regno),
2860 && p->age >= map->const_age)
2861 validate_change (insn, loc, p->rtx, 1);
2866 /* SUBREG applied to something other than a reg
2867 should be treated as ordinary, since that must
2868 be a special hack and we don't know how to treat it specially.
2869 Consider for example mulsidi3 in m68k.md.
2870 Ordinary SUBREG of a REG needs this special treatment. */
2871 if (GET_CODE (SUBREG_REG (x)) == REG)
2873 rtx inner = SUBREG_REG (x);
2876 /* We can't call subst_constants on &SUBREG_REG (x) because any
2877 constant or SUBREG wouldn't be valid inside our SUBEG. Instead,
2878 see what is inside, try to form the new SUBREG and see if that is
2879 valid. We handle two cases: extracting a full word in an
2880 integral mode and extracting the low part. */
2881 subst_constants (&inner, NULL_RTX, map);
2883 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2884 && GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD
2885 && GET_MODE (SUBREG_REG (x)) != VOIDmode)
2886 new = operand_subword (inner, SUBREG_WORD (x), 0,
2887 GET_MODE (SUBREG_REG (x)));
2889 cancel_changes (num_changes);
2890 if (new == 0 && subreg_lowpart_p (x))
2891 new = gen_lowpart_common (GET_MODE (x), inner);
2894 validate_change (insn, loc, new, 1);
2901 subst_constants (&XEXP (x, 0), insn, map);
2903 /* If a memory address got spoiled, change it back. */
2904 if (insn != 0 && num_validated_changes () != num_changes
2905 && !memory_address_p (GET_MODE (x), XEXP (x, 0)))
2906 cancel_changes (num_changes);
2911 /* Substitute constants in our source, and in any arguments to a
2912 complex (e..g, ZERO_EXTRACT) destination, but not in the destination
2914 rtx *dest_loc = &SET_DEST (x);
2915 rtx dest = *dest_loc;
2918 subst_constants (&SET_SRC (x), insn, map);
2921 while (GET_CODE (*dest_loc) == ZERO_EXTRACT
2922 || GET_CODE (*dest_loc) == SUBREG
2923 || GET_CODE (*dest_loc) == STRICT_LOW_PART)
2925 if (GET_CODE (*dest_loc) == ZERO_EXTRACT)
2927 subst_constants (&XEXP (*dest_loc, 1), insn, map);
2928 subst_constants (&XEXP (*dest_loc, 2), insn, map);
2930 dest_loc = &XEXP (*dest_loc, 0);
2933 /* Do substitute in the address of a destination in memory. */
2934 if (GET_CODE (*dest_loc) == MEM)
2935 subst_constants (&XEXP (*dest_loc, 0), insn, map);
2937 /* Check for the case of DEST a SUBREG, both it and the underlying
2938 register are less than one word, and the SUBREG has the wider mode.
2939 In the case, we are really setting the underlying register to the
2940 source converted to the mode of DEST. So indicate that. */
2941 if (GET_CODE (dest) == SUBREG
2942 && GET_MODE_SIZE (GET_MODE (dest)) <= UNITS_PER_WORD
2943 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) <= UNITS_PER_WORD
2944 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2945 <= GET_MODE_SIZE (GET_MODE (dest)))
2946 && (tem = gen_lowpart_if_possible (GET_MODE (SUBREG_REG (dest)),
2948 src = tem, dest = SUBREG_REG (dest);
2950 /* If storing a recognizable value save it for later recording. */
2951 if ((map->num_sets < MAX_RECOG_OPERANDS)
2952 && (CONSTANT_P (src)
2953 || (GET_CODE (src) == REG
2954 && (REGNO (src) == VIRTUAL_INCOMING_ARGS_REGNUM
2955 || REGNO (src) == VIRTUAL_STACK_VARS_REGNUM))
2956 || (GET_CODE (src) == PLUS
2957 && GET_CODE (XEXP (src, 0)) == REG
2958 && (REGNO (XEXP (src, 0)) == VIRTUAL_INCOMING_ARGS_REGNUM
2959 || REGNO (XEXP (src, 0)) == VIRTUAL_STACK_VARS_REGNUM)
2960 && CONSTANT_P (XEXP (src, 1)))
2961 || GET_CODE (src) == COMPARE
2966 && (src == pc_rtx || GET_CODE (src) == RETURN
2967 || GET_CODE (src) == LABEL_REF))))
2969 /* Normally, this copy won't do anything. But, if SRC is a COMPARE
2970 it will cause us to save the COMPARE with any constants
2971 substituted, which is what we want for later. */
2972 map->equiv_sets[map->num_sets].equiv = copy_rtx (src);
2973 map->equiv_sets[map->num_sets++].dest = dest;
2982 format_ptr = GET_RTX_FORMAT (code);
2984 /* If the first operand is an expression, save its mode for later. */
2985 if (*format_ptr == 'e')
2986 op0_mode = GET_MODE (XEXP (x, 0));
2988 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2990 switch (*format_ptr++)
2997 subst_constants (&XEXP (x, i), insn, map);
3007 if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
3010 for (j = 0; j < XVECLEN (x, i); j++)
3011 subst_constants (&XVECEXP (x, i, j), insn, map);
3020 /* If this is a commutative operation, move a constant to the second
3021 operand unless the second operand is already a CONST_INT. */
3022 if ((GET_RTX_CLASS (code) == 'c' || code == NE || code == EQ)
3023 && CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT)
3025 rtx tem = XEXP (x, 0);
3026 validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
3027 validate_change (insn, &XEXP (x, 1), tem, 1);
3030 /* Simplify the expression in case we put in some constants. */
3031 switch (GET_RTX_CLASS (code))
3034 if (op0_mode == MAX_MACHINE_MODE)
3036 new = simplify_unary_operation (code, GET_MODE (x),
3037 XEXP (x, 0), op0_mode);
3042 enum machine_mode op_mode = GET_MODE (XEXP (x, 0));
3043 if (op_mode == VOIDmode)
3044 op_mode = GET_MODE (XEXP (x, 1));
3045 new = simplify_relational_operation (code, op_mode,
3046 XEXP (x, 0), XEXP (x, 1));
3047 #ifdef FLOAT_STORE_FLAG_VALUE
3048 if (new != 0 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
3049 new = ((new == const0_rtx) ? CONST0_RTX (GET_MODE (x))
3050 : CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE,
3058 new = simplify_binary_operation (code, GET_MODE (x),
3059 XEXP (x, 0), XEXP (x, 1));
3064 if (op0_mode == MAX_MACHINE_MODE)
3066 new = simplify_ternary_operation (code, GET_MODE (x), op0_mode,
3067 XEXP (x, 0), XEXP (x, 1), XEXP (x, 2));
3072 validate_change (insn, loc, new, 1);
3075 /* Show that register modified no longer contain known constants. We are
3076 called from note_stores with parts of the new insn. */
3079 mark_stores (dest, x)
3081 rtx x ATTRIBUTE_UNUSED;
3084 enum machine_mode mode;
3086 /* DEST is always the innermost thing set, except in the case of
3087 SUBREGs of hard registers. */
3089 if (GET_CODE (dest) == REG)
3090 regno = REGNO (dest), mode = GET_MODE (dest);
3091 else if (GET_CODE (dest) == SUBREG && GET_CODE (SUBREG_REG (dest)) == REG)
3093 regno = REGNO (SUBREG_REG (dest)) + SUBREG_WORD (dest);
3094 mode = GET_MODE (SUBREG_REG (dest));
3099 int last_reg = (regno >= FIRST_PSEUDO_REGISTER ? regno
3100 : regno + HARD_REGNO_NREGS (regno, mode) - 1);
3103 /* Ignore virtual stack var or virtual arg register since those
3104 are handled separately. */
3105 if (regno != VIRTUAL_INCOMING_ARGS_REGNUM
3106 && regno != VIRTUAL_STACK_VARS_REGNUM)
3107 for (i = regno; i <= last_reg; i++)
3108 if (i < VARRAY_SIZE (global_const_equiv_varray))
3109 VARRAY_CONST_EQUIV (global_const_equiv_varray, i).rtx = 0;
3113 /* If any CONST expressions with RTX_INTEGRATED_P are present in the rtx
3114 pointed to by PX, they represent constants in the constant pool.
3115 Replace these with a new memory reference obtained from force_const_mem.
3116 Similarly, ADDRESS expressions with RTX_INTEGRATED_P represent the
3117 address of a constant pool entry. Replace them with the address of
3118 a new constant pool entry obtained from force_const_mem. */
3121 restore_constants (px)
3131 if (GET_CODE (x) == CONST_DOUBLE)
3133 /* We have to make a new CONST_DOUBLE to ensure that we account for
3134 it correctly. Using the old CONST_DOUBLE_MEM data is wrong. */
3135 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
3139 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
3140 *px = CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (x));
3143 *px = immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
3147 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == CONST)
3149 restore_constants (&XEXP (x, 0));
3150 *px = validize_mem (force_const_mem (GET_MODE (x), XEXP (x, 0)));
3152 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == SUBREG)
3154 /* This must be (subreg/i:M1 (const/i:M2 ...) 0). */
3155 rtx new = XEXP (SUBREG_REG (x), 0);
3157 restore_constants (&new);
3158 new = force_const_mem (GET_MODE (SUBREG_REG (x)), new);
3159 PUT_MODE (new, GET_MODE (x));
3160 *px = validize_mem (new);
3162 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == ADDRESS)
3164 rtx new = XEXP (force_const_mem (GET_MODE (XEXP (x, 0)),
3165 XEXP (XEXP (x, 0), 0)),
3168 #ifdef POINTERS_EXTEND_UNSIGNED
3169 if (GET_MODE (new) != GET_MODE (x))
3170 new = convert_memory_address (GET_MODE (x), new);
3177 fmt = GET_RTX_FORMAT (GET_CODE (x));
3178 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3183 for (j = 0; j < XVECLEN (x, i); j++)
3184 restore_constants (&XVECEXP (x, i, j));
3188 restore_constants (&XEXP (x, i));
3195 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
3196 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
3197 that it points to the node itself, thus indicating that the node is its
3198 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
3199 the given node is NULL, recursively descend the decl/block tree which
3200 it is the root of, and for each other ..._DECL or BLOCK node contained
3201 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
3202 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
3203 values to point to themselves. */
3206 set_block_origin_self (stmt)
3209 if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
3211 BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
3214 register tree local_decl;
3216 for (local_decl = BLOCK_VARS (stmt);
3217 local_decl != NULL_TREE;
3218 local_decl = TREE_CHAIN (local_decl))
3219 set_decl_origin_self (local_decl); /* Potential recursion. */
3223 register tree subblock;
3225 for (subblock = BLOCK_SUBBLOCKS (stmt);
3226 subblock != NULL_TREE;
3227 subblock = BLOCK_CHAIN (subblock))
3228 set_block_origin_self (subblock); /* Recurse. */
3233 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
3234 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
3235 node to so that it points to the node itself, thus indicating that the
3236 node represents its own (abstract) origin. Additionally, if the
3237 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
3238 the decl/block tree of which the given node is the root of, and for
3239 each other ..._DECL or BLOCK node contained therein whose
3240 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
3241 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
3242 point to themselves. */
3245 set_decl_origin_self (decl)
3248 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
3250 DECL_ABSTRACT_ORIGIN (decl) = decl;
3251 if (TREE_CODE (decl) == FUNCTION_DECL)
3255 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
3256 DECL_ABSTRACT_ORIGIN (arg) = arg;
3257 if (DECL_INITIAL (decl) != NULL_TREE
3258 && DECL_INITIAL (decl) != error_mark_node)
3259 set_block_origin_self (DECL_INITIAL (decl));
3264 /* Given a pointer to some BLOCK node, and a boolean value to set the
3265 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
3266 the given block, and for all local decls and all local sub-blocks
3267 (recursively) which are contained therein. */
3270 set_block_abstract_flags (stmt, setting)
3272 register int setting;
3274 register tree local_decl;
3275 register tree subblock;
3277 BLOCK_ABSTRACT (stmt) = setting;
3279 for (local_decl = BLOCK_VARS (stmt);
3280 local_decl != NULL_TREE;
3281 local_decl = TREE_CHAIN (local_decl))
3282 set_decl_abstract_flags (local_decl, setting);
3284 for (subblock = BLOCK_SUBBLOCKS (stmt);
3285 subblock != NULL_TREE;
3286 subblock = BLOCK_CHAIN (subblock))
3287 set_block_abstract_flags (subblock, setting);
3290 /* Given a pointer to some ..._DECL node, and a boolean value to set the
3291 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
3292 given decl, and (in the case where the decl is a FUNCTION_DECL) also
3293 set the abstract flags for all of the parameters, local vars, local
3294 blocks and sub-blocks (recursively) to the same setting. */
3297 set_decl_abstract_flags (decl, setting)
3299 register int setting;
3301 DECL_ABSTRACT (decl) = setting;
3302 if (TREE_CODE (decl) == FUNCTION_DECL)
3306 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
3307 DECL_ABSTRACT (arg) = setting;
3308 if (DECL_INITIAL (decl) != NULL_TREE
3309 && DECL_INITIAL (decl) != error_mark_node)
3310 set_block_abstract_flags (DECL_INITIAL (decl), setting);
3314 /* Output the assembly language code for the function FNDECL
3315 from its DECL_SAVED_INSNS. Used for inline functions that are output
3316 at end of compilation instead of where they came in the source. */
3319 output_inline_function (fndecl)
3322 struct function *f = DECL_SAVED_INSNS (fndecl);
3325 /* Things we allocate from here on are part of this function, not
3327 temporary_allocation ();
3328 current_function = f;
3329 current_function_decl = fndecl;
3330 clear_emit_caches ();
3332 /* Find last insn and rebuild the constant pool. */
3333 init_const_rtx_hash_table ();
3334 for (last = get_insns (); NEXT_INSN (last); last = NEXT_INSN (last))
3336 if (GET_RTX_CLASS (GET_CODE (last)) == 'i')
3338 restore_constants (&PATTERN (last));
3339 restore_constants (®_NOTES (last));
3343 set_new_last_label_num (f->inl_max_label_num);
3345 /* We must have already output DWARF debugging information for the
3346 original (abstract) inline function declaration/definition, so
3347 we want to make sure that the debugging information we generate
3348 for this special instance of the inline function refers back to
3349 the information we already generated. To make sure that happens,
3350 we simply have to set the DECL_ABSTRACT_ORIGIN for the function
3351 node (and for all of the local ..._DECL nodes which are its children)
3352 so that they all point to themselves. */
3354 set_decl_origin_self (fndecl);
3356 /* We're not deferring this any longer. */
3357 DECL_DEFER_OUTPUT (fndecl) = 0;
3359 /* We can't inline this anymore. */
3361 DECL_INLINE (fndecl) = 0;
3363 /* Compile this function all the way down to assembly code. */
3364 rest_of_compilation (fndecl);
3366 current_function = 0;
3367 current_function_decl = 0;