1 /* Procedure integration for GNU CC.
2 Copyright (C) 1988, 1991 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #include "insn-config.h"
29 #include "insn-flags.h"
32 #include "integrate.h"
37 #define obstack_chunk_alloc xmalloc
38 #define obstack_chunk_free free
40 extern struct obstack *function_maybepermanent_obstack;
42 extern tree pushdecl ();
43 extern tree poplevel ();
45 /* Similar, but round to the next highest integer that meets the
47 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
49 /* Default max number of insns a function can have and still be inline.
50 This is overridden on RISC machines. */
51 #ifndef INTEGRATE_THRESHOLD
52 #define INTEGRATE_THRESHOLD(DECL) \
53 (8 * (8 + list_length (DECL_ARGUMENTS (DECL))))
56 /* Save any constant pool constants in an insn. */
57 static void save_constants ();
59 /* Note when parameter registers are the destination of a SET. */
60 static void note_modified_parmregs ();
62 /* Copy an rtx for save_for_inline_copying. */
63 static rtx copy_for_inline ();
65 /* Make copies of MEMs in DECL_RTLs. */
66 static void copy_decl_rtls ();
68 static tree copy_decl_tree ();
69 static tree copy_decl_list ();
71 /* Return the constant equivalent of a given rtx, or 0 if none. */
72 static rtx const_equiv ();
74 static void integrate_parm_decls ();
75 static void integrate_decl_tree ();
77 static void subst_constants ();
78 static rtx fold_out_const_cc0 ();
80 /* Zero if the current function (whose FUNCTION_DECL is FNDECL)
81 is safe and reasonable to integrate into other functions.
82 Nonzero means value is a warning message with a single %s
83 for the function's name. */
86 function_cannot_inline_p (fndecl)
90 tree last = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
91 int max_insns = INTEGRATE_THRESHOLD (fndecl);
92 register int ninsns = 0;
95 /* No inlines with varargs. `grokdeclarator' gives a warning
96 message about that if `inline' is specified. This code
97 it put in to catch the volunteers. */
98 if ((last && TREE_VALUE (last) != void_type_node)
99 || (DECL_ARGUMENTS (fndecl) && DECL_NAME (DECL_ARGUMENTS (fndecl))
100 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (DECL_ARGUMENTS (fndecl))),
101 "__builtin_va_alist")))
102 return "varargs function cannot be inline";
104 if (current_function_calls_alloca)
105 return "function using alloca cannot be inline";
107 if (current_function_contains_functions)
108 return "function with nested functions cannot be inline";
110 /* This restriction may be eliminated sometime soon. But for now, don't
111 worry about remapping the static chain. */
112 if (current_function_needs_context)
113 return "nested function cannot be inline";
115 /* If its not even close, don't even look. */
116 if (!DECL_INLINE (fndecl) && get_max_uid () > 3 * max_insns)
117 return "function too large to be inline";
120 /* Large stacks are OK now that inlined functions can share them. */
121 /* Don't inline functions with large stack usage,
122 since they can make other recursive functions burn up stack. */
123 if (!DECL_INLINE (fndecl) && get_frame_size () > 100)
124 return "function stack frame for inlining";
128 /* Don't inline functions which do not specify a function prototype and
129 have BLKmode argument or take the address of a parameter. */
130 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
132 if (TYPE_MODE (TREE_TYPE (parms)) == BLKmode)
133 TREE_ADDRESSABLE (parms) = 1;
134 if (last == NULL_TREE && TREE_ADDRESSABLE (parms))
135 return "no prototype, and parameter address used; cannot be inline";
139 /* We can't inline functions that return structures
140 the old-fashioned PCC way, copying into a static block. */
141 if (current_function_returns_pcc_struct)
142 return "inline functions not supported for this return value type";
144 /* We can't inline functions that return structures of varying size. */
145 if (int_size_in_bytes (TREE_TYPE (TREE_TYPE (fndecl))) < 0)
146 return "function with varying-size return value cannot be inline";
148 /* Cannot inline a function with a varying size argument. */
149 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
150 if (int_size_in_bytes (TREE_TYPE (parms)) < 0)
151 return "function with varying-size parameter cannot be inline";
153 if (!DECL_INLINE (fndecl) && get_max_uid () > max_insns)
155 for (ninsns = 0, insn = get_first_nonparm_insn (); insn && ninsns < max_insns;
156 insn = NEXT_INSN (insn))
158 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
162 if (ninsns >= max_insns)
163 return "function too large to be inline";
166 /* We cannot inline this function if forced_labels is non-zero. This
167 implies that a label in this function was used as an initializer.
168 Because labels can not be duplicated, all labels in the function
169 will be renamed when it is inlined. However, there is no way to find
170 and fix all variables initialized with addresses of labels in this
171 function, hence inlining is impossible. */
174 return "function with label addresses used in initializers cannot inline";
179 /* Variables used within save_for_inline. */
181 /* Mapping from old pseudo-register to new pseudo-registers.
182 The first element of this map is reg_map[FIRST_PSEUDO_REGISTER].
183 It is allocated in `save_for_inline' and `expand_inline_function',
184 and deallocated on exit from each of those routines. */
187 /* Mapping from old code-labels to new code-labels.
188 The first element of this map is label_map[min_labelno].
189 It is allocated in `save_for_inline' and `expand_inline_function',
190 and deallocated on exit from each of those routines. */
191 static rtx *label_map;
193 /* Mapping from old insn uid's to copied insns.
194 It is allocated in `save_for_inline' and `expand_inline_function',
195 and deallocated on exit from each of those routines. */
196 static rtx *insn_map;
198 /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
199 Zero for a reg that isn't a parm's home.
200 Only reg numbers less than max_parm_reg are mapped here. */
201 static tree *parmdecl_map;
203 /* Keep track of first pseudo-register beyond those that are parms. */
204 static int max_parm_reg;
206 /* When an insn is being copied by copy_for_inline,
207 this is nonzero if we have copied an ASM_OPERANDS.
208 In that case, it is the original input-operand vector. */
209 static rtvec orig_asm_operands_vector;
211 /* When an insn is being copied by copy_for_inline,
212 this is nonzero if we have copied an ASM_OPERANDS.
213 In that case, it is the copied input-operand vector. */
214 static rtvec copy_asm_operands_vector;
216 /* Likewise, this is the copied constraints vector. */
217 static rtvec copy_asm_constraints_vector;
219 /* In save_for_inline, nonzero if past the parm-initialization insns. */
220 static int in_nonparm_insns;
222 /* Subroutine for `save_for_inline{copying,nocopy}'. Performs initialization
223 needed to save FNDECL's insns and info for future inline expansion. */
226 initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, copy)
233 int function_flags, i;
237 /* Compute the values of any flags we must restore when inlining this. */
240 = (current_function_calls_alloca * FUNCTION_FLAGS_CALLS_ALLOCA
241 + current_function_calls_setjmp * FUNCTION_FLAGS_CALLS_SETJMP
242 + current_function_calls_longjmp * FUNCTION_FLAGS_CALLS_LONGJMP
243 + current_function_returns_struct * FUNCTION_FLAGS_RETURNS_STRUCT
244 + current_function_returns_pcc_struct * FUNCTION_FLAGS_RETURNS_PCC_STRUCT
245 + current_function_needs_context * FUNCTION_FLAGS_NEEDS_CONTEXT
246 + current_function_has_nonlocal_label * FUNCTION_FLAGS_HAS_NONLOCAL_LABEL
247 + current_function_returns_pointer * FUNCTION_FLAGS_RETURNS_POINTER
248 + current_function_uses_const_pool * FUNCTION_FLAGS_USES_CONST_POOL
249 + current_function_uses_pic_offset_table * FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE);
251 /* Clear out PARMDECL_MAP. It was allocated in the caller's frame. */
252 bzero (parmdecl_map, max_parm_reg * sizeof (tree));
253 arg_vector = rtvec_alloc (list_length (DECL_ARGUMENTS (fndecl)));
255 for (parms = DECL_ARGUMENTS (fndecl), i = 0;
257 parms = TREE_CHAIN (parms), i++)
259 rtx p = DECL_RTL (parms);
261 if (GET_CODE (p) == MEM && copy)
263 /* Copy the rtl so that modifications of the addresses
264 later in compilation won't affect this arg_vector.
265 Virtual register instantiation can screw the address
267 rtx new = copy_rtx (p);
269 /* Don't leave the old copy anywhere in this decl. */
270 if (DECL_RTL (parms) == DECL_INCOMING_RTL (parms)
271 || (GET_CODE (DECL_RTL (parms)) == MEM
272 && GET_CODE (DECL_INCOMING_RTL (parms)) == MEM
273 && (XEXP (DECL_RTL (parms), 0)
274 == XEXP (DECL_INCOMING_RTL (parms), 0))))
275 DECL_INCOMING_RTL (parms) = new;
276 DECL_RTL (parms) = new;
279 RTVEC_ELT (arg_vector, i) = p;
281 if (GET_CODE (p) == REG)
282 parmdecl_map[REGNO (p)] = parms;
283 /* This flag is cleared later
284 if the function ever modifies the value of the parm. */
285 TREE_READONLY (parms) = 1;
288 /* Assume we start out in the insns that set up the parameters. */
289 in_nonparm_insns = 0;
291 /* The list of DECL_SAVED_INSNS, starts off with a header which
292 contains the following information:
294 the first insn of the function (not including the insns that copy
295 parameters into registers).
296 the first parameter insn of the function,
297 the first label used by that function,
298 the last label used by that function,
299 the highest register number used for parameters,
300 the total number of registers used,
301 the size of the incoming stack area for parameters,
302 the number of bytes popped on return,
304 some flags that are used to restore compiler globals,
305 the value of current_function_outgoing_args_size,
306 the original argument vector,
307 and the original DECL_INITIAL. */
309 return gen_inline_header_rtx (NULL_RTX, NULL_RTX, min_labelno, max_labelno,
310 max_parm_reg, max_reg,
311 current_function_args_size,
312 current_function_pops_args,
313 stack_slot_list, function_flags,
314 current_function_outgoing_args_size,
315 arg_vector, (rtx) DECL_INITIAL (fndecl));
318 /* Subroutine for `save_for_inline{copying,nocopy}'. Finishes up the
319 things that must be done to make FNDECL expandable as an inline function.
320 HEAD contains the chain of insns to which FNDECL will expand. */
323 finish_inline (fndecl, head)
327 NEXT_INSN (head) = get_first_nonparm_insn ();
328 FIRST_PARM_INSN (head) = get_insns ();
329 DECL_SAVED_INSNS (fndecl) = head;
330 DECL_FRAME_SIZE (fndecl) = get_frame_size ();
331 DECL_INLINE (fndecl) = 1;
334 /* Adjust the BLOCK_END_NOTE pointers in a given copied DECL tree so that
335 they all point to the new (copied) rtxs. */
338 adjust_copied_decl_tree (block)
341 register tree subblock;
342 register rtx original_end;
344 original_end = BLOCK_END_NOTE (block);
347 BLOCK_END_NOTE (block) = (rtx) NOTE_SOURCE_FILE (original_end);
348 NOTE_SOURCE_FILE (original_end) = 0;
351 /* Process all subblocks. */
352 for (subblock = BLOCK_SUBBLOCKS (block);
354 subblock = TREE_CHAIN (subblock))
355 adjust_copied_decl_tree (subblock);
358 /* Make the insns and PARM_DECLs of the current function permanent
359 and record other information in DECL_SAVED_INSNS to allow inlining
360 of this function in subsequent calls.
362 This function is called when we are going to immediately compile
363 the insns for FNDECL. The insns in maybepermanent_obstack cannot be
364 modified by the compilation process, so we copy all of them to
365 new storage and consider the new insns to be the insn chain to be
366 compiled. Our caller (rest_of_compilation) saves the original
367 DECL_INITIAL and DECL_ARGUMENTS; here we copy them. */
370 save_for_inline_copying (fndecl)
373 rtx first_insn, last_insn, insn;
375 int max_labelno, min_labelno, i, len;
378 rtx first_nonparm_insn;
380 /* Make and emit a return-label if we have not already done so.
381 Do this before recording the bounds on label numbers. */
383 if (return_label == 0)
385 return_label = gen_label_rtx ();
386 emit_label (return_label);
389 /* Get some bounds on the labels and registers used. */
391 max_labelno = max_label_num ();
392 min_labelno = get_first_label_num ();
393 max_reg = max_reg_num ();
395 /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
396 Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
397 Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
398 for the parms, prior to elimination of virtual registers.
399 These values are needed for substituting parms properly. */
401 max_parm_reg = max_parm_reg_num ();
402 parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
404 head = initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, 1);
406 if (current_function_uses_const_pool)
408 /* Replace any constant pool references with the actual constant. We
409 will put the constants back in the copy made below. */
410 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
411 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
413 save_constants (&PATTERN (insn));
414 if (REG_NOTES (insn))
415 save_constants (®_NOTES (insn));
418 /* Clear out the constant pool so that we can recreate it with the
419 copied constants below. */
420 init_const_rtx_hash_table ();
421 clear_const_double_mem ();
424 max_uid = INSN_UID (head);
426 /* We have now allocated all that needs to be allocated permanently
427 on the rtx obstack. Set our high-water mark, so that we
428 can free the rest of this when the time comes. */
432 /* Copy the chain insns of this function.
433 Install the copied chain as the insns of this function,
434 for continued compilation;
435 the original chain is recorded as the DECL_SAVED_INSNS
436 for inlining future calls. */
438 /* If there are insns that copy parms from the stack into pseudo registers,
439 those insns are not copied. `expand_inline_function' must
440 emit the correct code to handle such things. */
443 if (GET_CODE (insn) != NOTE)
445 first_insn = rtx_alloc (NOTE);
446 NOTE_SOURCE_FILE (first_insn) = NOTE_SOURCE_FILE (insn);
447 NOTE_LINE_NUMBER (first_insn) = NOTE_LINE_NUMBER (insn);
448 INSN_UID (first_insn) = INSN_UID (insn);
449 PREV_INSN (first_insn) = NULL;
450 NEXT_INSN (first_insn) = NULL;
451 last_insn = first_insn;
453 /* Each pseudo-reg in the old insn chain must have a unique rtx in the copy.
454 Make these new rtx's now, and install them in regno_reg_rtx, so they
455 will be the official pseudo-reg rtx's for the rest of compilation. */
457 reg_map = (rtx *) alloca ((max_reg + 1) * sizeof (rtx));
459 len = sizeof (struct rtx_def) + (GET_RTX_LENGTH (REG) - 1) * sizeof (rtunion);
460 for (i = max_reg - 1; i > LAST_VIRTUAL_REGISTER; i--)
461 reg_map[i] = (rtx)obstack_copy (function_maybepermanent_obstack,
462 regno_reg_rtx[i], len);
464 bcopy (reg_map + LAST_VIRTUAL_REGISTER + 1,
465 regno_reg_rtx + LAST_VIRTUAL_REGISTER + 1,
466 (max_reg - (LAST_VIRTUAL_REGISTER + 1)) * sizeof (rtx));
468 /* Likewise each label rtx must have a unique rtx as its copy. */
470 label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
471 label_map -= min_labelno;
473 for (i = min_labelno; i < max_labelno; i++)
474 label_map[i] = gen_label_rtx ();
476 /* Record the mapping of old insns to copied insns. */
478 insn_map = (rtx *) alloca (max_uid * sizeof (rtx));
479 bzero (insn_map, max_uid * sizeof (rtx));
481 /* Get the insn which signals the end of parameter setup code. */
482 first_nonparm_insn = get_first_nonparm_insn ();
484 /* Copy any entries in regno_reg_rtx or DECL_RTLs that reference MEM
485 (the former occurs when a variable has its address taken)
486 since these may be shared and can be changed by virtual
487 register instantiation. DECL_RTL values for our arguments
488 have already been copied by initialize_for_inline. */
489 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_reg; i++)
490 if (GET_CODE (regno_reg_rtx[i]) == MEM)
491 XEXP (regno_reg_rtx[i], 0)
492 = copy_for_inline (XEXP (regno_reg_rtx[i], 0));
494 /* Copy the tree of subblocks of the function, and the decls in them.
495 We will use the copy for compiling this function, then restore the original
496 subblocks and decls for use when inlining this function.
498 Several parts of the compiler modify BLOCK trees. In particular,
499 instantiate_virtual_regs will instantiate any virtual regs
500 mentioned in the DECL_RTLs of the decls, and loop
501 unrolling will replicate any BLOCK trees inside an unrolled loop.
503 The modified subblocks or DECL_RTLs would be incorrect for the original rtl
504 which we will use for inlining. The rtl might even contain pseudoregs
505 whose space has been freed. */
507 DECL_INITIAL (fndecl) = copy_decl_tree (DECL_INITIAL (fndecl));
508 DECL_ARGUMENTS (fndecl) = copy_decl_list (DECL_ARGUMENTS (fndecl));
510 /* Now copy each DECL_RTL which is a MEM,
511 so it is safe to modify their addresses. */
512 copy_decl_rtls (DECL_INITIAL (fndecl));
514 /* The fndecl node acts as its own progenitor, so mark it as such. */
515 DECL_ABSTRACT_ORIGIN (fndecl) = fndecl;
517 /* Now copy the chain of insns. Do this twice. The first copy the insn
518 itself and its body. The second time copy of REG_NOTES. This is because
519 a REG_NOTE may have a forward pointer to another insn. */
521 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
523 orig_asm_operands_vector = 0;
525 if (insn == first_nonparm_insn)
526 in_nonparm_insns = 1;
528 switch (GET_CODE (insn))
531 /* No need to keep these. */
532 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
535 copy = rtx_alloc (NOTE);
536 NOTE_LINE_NUMBER (copy) = NOTE_LINE_NUMBER (insn);
537 if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_BLOCK_END)
538 NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
541 NOTE_SOURCE_FILE (insn) = (char *) copy;
542 NOTE_SOURCE_FILE (copy) = 0;
549 copy = rtx_alloc (GET_CODE (insn));
550 PATTERN (copy) = copy_for_inline (PATTERN (insn));
551 INSN_CODE (copy) = -1;
552 LOG_LINKS (copy) = NULL;
553 RTX_INTEGRATED_P (copy) = RTX_INTEGRATED_P (insn);
557 copy = label_map[CODE_LABEL_NUMBER (insn)];
558 LABEL_NAME (copy) = LABEL_NAME (insn);
562 copy = rtx_alloc (BARRIER);
568 INSN_UID (copy) = INSN_UID (insn);
569 insn_map[INSN_UID (insn)] = copy;
570 NEXT_INSN (last_insn) = copy;
571 PREV_INSN (copy) = last_insn;
575 adjust_copied_decl_tree (DECL_INITIAL (fndecl));
577 /* Now copy the REG_NOTES. */
578 for (insn = NEXT_INSN (get_insns ()); insn; insn = NEXT_INSN (insn))
579 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
580 && insn_map[INSN_UID(insn)])
581 REG_NOTES (insn_map[INSN_UID (insn)])
582 = copy_for_inline (REG_NOTES (insn));
584 NEXT_INSN (last_insn) = NULL;
586 finish_inline (fndecl, head);
588 set_new_first_and_last_insn (first_insn, last_insn);
591 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
592 For example, this can copy a list made of TREE_LIST nodes. While copying,
593 for each node copied which doesn't already have is DECL_ABSTRACT_ORIGIN
594 set to some non-zero value, set the DECL_ABSTRACT_ORIGIN of the copy to
595 point to the corresponding (abstract) original node. */
598 copy_decl_list (list)
602 register tree prev, next;
607 head = prev = copy_node (list);
608 if (DECL_ABSTRACT_ORIGIN (head) == NULL_TREE)
609 DECL_ABSTRACT_ORIGIN (head) = list;
610 next = TREE_CHAIN (list);
615 copy = copy_node (next);
616 if (DECL_ABSTRACT_ORIGIN (copy) == NULL_TREE)
617 DECL_ABSTRACT_ORIGIN (copy) = next;
618 TREE_CHAIN (prev) = copy;
620 next = TREE_CHAIN (next);
625 /* Make a copy of the entire tree of blocks BLOCK, and return it. */
628 copy_decl_tree (block)
631 tree t, vars, subblocks;
633 vars = copy_decl_list (BLOCK_VARS (block));
636 /* Process all subblocks. */
637 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
639 tree copy = copy_decl_tree (t);
640 TREE_CHAIN (copy) = subblocks;
644 t = copy_node (block);
645 BLOCK_VARS (t) = vars;
646 BLOCK_SUBBLOCKS (t) = nreverse (subblocks);
647 /* If the BLOCK being cloned is already marked as having been instantiated
648 from something else, then leave that `origin' marking alone. Elsewise,
649 mark the clone as having originated from the BLOCK we are cloning. */
650 if (BLOCK_ABSTRACT_ORIGIN (t) == NULL_TREE)
651 BLOCK_ABSTRACT_ORIGIN (t) = block;
655 /* Copy DECL_RTLs in all decls in the given BLOCK node. */
658 copy_decl_rtls (block)
663 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
664 if (DECL_RTL (t) && GET_CODE (DECL_RTL (t)) == MEM)
665 DECL_RTL (t) = copy_for_inline (DECL_RTL (t));
667 /* Process all subblocks. */
668 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
672 /* Make the insns and PARM_DECLs of the current function permanent
673 and record other information in DECL_SAVED_INSNS to allow inlining
674 of this function in subsequent calls.
676 This routine need not copy any insns because we are not going
677 to immediately compile the insns in the insn chain. There
678 are two cases when we would compile the insns for FNDECL:
679 (1) when FNDECL is expanded inline, and (2) when FNDECL needs to
680 be output at the end of other compilation, because somebody took
681 its address. In the first case, the insns of FNDECL are copied
682 as it is expanded inline, so FNDECL's saved insns are not
683 modified. In the second case, FNDECL is used for the last time,
684 so modifying the rtl is not a problem.
686 ??? Actually, we do not verify that FNDECL is not inline expanded
687 by other functions which must also be written down at the end
688 of compilation. We could set flag_no_inline to nonzero when
689 the time comes to write down such functions. */
692 save_for_inline_nocopy (fndecl)
698 int max_labelno, min_labelno, i, len;
701 rtx first_nonparm_insn;
704 /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
705 Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
706 Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
707 for the parms, prior to elimination of virtual registers.
708 These values are needed for substituting parms properly. */
710 max_parm_reg = max_parm_reg_num ();
711 parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
713 /* Make and emit a return-label if we have not already done so. */
715 if (return_label == 0)
717 return_label = gen_label_rtx ();
718 emit_label (return_label);
721 head = initialize_for_inline (fndecl, get_first_label_num (),
722 max_label_num (), max_reg_num (), 0);
724 /* If there are insns that copy parms from the stack into pseudo registers,
725 those insns are not copied. `expand_inline_function' must
726 emit the correct code to handle such things. */
729 if (GET_CODE (insn) != NOTE)
732 /* Get the insn which signals the end of parameter setup code. */
733 first_nonparm_insn = get_first_nonparm_insn ();
735 /* Now just scan the chain of insns to see what happens to our
736 PARM_DECLs. If a PARM_DECL is used but never modified, we
737 can substitute its rtl directly when expanding inline (and
738 perform constant folding when its incoming value is constant).
739 Otherwise, we have to copy its value into a new register and track
740 the new register's life. */
742 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
744 if (insn == first_nonparm_insn)
745 in_nonparm_insns = 1;
747 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
749 if (current_function_uses_const_pool)
751 /* Replace any constant pool references with the actual constant.
752 We will put the constant back if we need to write the
753 function out after all. */
754 save_constants (&PATTERN (insn));
755 if (REG_NOTES (insn))
756 save_constants (®_NOTES (insn));
759 /* Record what interesting things happen to our parameters. */
760 note_stores (PATTERN (insn), note_modified_parmregs);
764 /* We have now allocated all that needs to be allocated permanently
765 on the rtx obstack. Set our high-water mark, so that we
766 can free the rest of this when the time comes. */
770 finish_inline (fndecl, head);
773 /* Given PX, a pointer into an insn, search for references to the constant
774 pool. Replace each with a CONST that has the mode of the original
775 constant, contains the constant, and has RTX_INTEGRATED_P set.
776 Similarly, constant pool addresses not enclosed in a MEM are replaced
777 with an ADDRESS rtx which also gives the constant, mode, and has
778 RTX_INTEGRATED_P set. */
790 /* If this is a CONST_DOUBLE, don't try to fix things up in
791 CONST_DOUBLE_MEM, because this is an infinite recursion. */
792 if (GET_CODE (x) == CONST_DOUBLE)
794 else if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
795 && CONSTANT_POOL_ADDRESS_P (XEXP (x,0)))
797 enum machine_mode const_mode = get_pool_mode (XEXP (x, 0));
798 rtx new = gen_rtx (CONST, const_mode, get_pool_constant (XEXP (x, 0)));
799 RTX_INTEGRATED_P (new) = 1;
801 /* If the MEM was in a different mode than the constant (perhaps we
802 were only looking at the low-order part), surround it with a
803 SUBREG so we can save both modes. */
805 if (GET_MODE (x) != const_mode)
807 new = gen_rtx (SUBREG, GET_MODE (x), new, 0);
808 RTX_INTEGRATED_P (new) = 1;
812 save_constants (&XEXP (*px, 0));
814 else if (GET_CODE (x) == SYMBOL_REF
815 && CONSTANT_POOL_ADDRESS_P (x))
817 *px = gen_rtx (ADDRESS, get_pool_mode (x), get_pool_constant (x));
818 save_constants (&XEXP (*px, 0));
819 RTX_INTEGRATED_P (*px) = 1;
824 char *fmt = GET_RTX_FORMAT (GET_CODE (x));
825 int len = GET_RTX_LENGTH (GET_CODE (x));
827 for (i = len-1; i >= 0; i--)
832 for (j = 0; j < XVECLEN (x, i); j++)
833 save_constants (&XVECEXP (x, i, j));
837 if (XEXP (x, i) == 0)
841 /* Hack tail-recursion here. */
845 save_constants (&XEXP (x, i));
852 /* Note whether a parameter is modified or not. */
855 note_modified_parmregs (reg, x)
859 if (GET_CODE (reg) == REG && in_nonparm_insns
860 && REGNO (reg) < max_parm_reg
861 && REGNO (reg) >= FIRST_PSEUDO_REGISTER
862 && parmdecl_map[REGNO (reg)] != 0)
863 TREE_READONLY (parmdecl_map[REGNO (reg)]) = 0;
866 /* Copy the rtx ORIG recursively, replacing pseudo-regs and labels
867 according to `reg_map' and `label_map'. The original rtl insns
868 will be saved for inlining; this is used to make a copy
869 which is used to finish compiling the inline function itself.
871 If we find a "saved" constant pool entry, one which was replaced with
872 the value of the constant, convert it back to a constant pool entry.
873 Since the pool wasn't touched, this should simply restore the old
876 All other kinds of rtx are copied except those that can never be
877 changed during compilation. */
880 copy_for_inline (orig)
883 register rtx x = orig;
885 register enum rtx_code code;
886 register char *format_ptr;
893 /* These types may be freely shared. */
905 /* We have to make a new CONST_DOUBLE to ensure that we account for
906 it correctly. Using the old CONST_DOUBLE_MEM data is wrong. */
907 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
911 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
912 return immed_real_const_1 (d, GET_MODE (x));
915 return immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
919 /* Get constant pool entry for constant in the pool. */
920 if (RTX_INTEGRATED_P (x))
921 return validize_mem (force_const_mem (GET_MODE (x),
922 copy_for_inline (XEXP (x, 0))));
926 /* Get constant pool entry, but access in different mode. */
927 if (RTX_INTEGRATED_P (x))
930 = force_const_mem (GET_MODE (SUBREG_REG (x)),
931 copy_for_inline (XEXP (SUBREG_REG (x), 0)));
933 PUT_MODE (new, GET_MODE (x));
934 return validize_mem (new);
939 /* If not special for constant pool error. Else get constant pool
941 if (! RTX_INTEGRATED_P (x))
944 return XEXP (force_const_mem (GET_MODE (x),
945 copy_for_inline (XEXP (x, 0))), 0);
948 /* If a single asm insn contains multiple output operands
949 then it contains multiple ASM_OPERANDS rtx's that share operand 3.
950 We must make sure that the copied insn continues to share it. */
951 if (orig_asm_operands_vector == XVEC (orig, 3))
953 x = rtx_alloc (ASM_OPERANDS);
954 XSTR (x, 0) = XSTR (orig, 0);
955 XSTR (x, 1) = XSTR (orig, 1);
956 XINT (x, 2) = XINT (orig, 2);
957 XVEC (x, 3) = copy_asm_operands_vector;
958 XVEC (x, 4) = copy_asm_constraints_vector;
959 XSTR (x, 5) = XSTR (orig, 5);
960 XINT (x, 6) = XINT (orig, 6);
966 /* A MEM is usually allowed to be shared if its address is constant
967 or is a constant plus one of the special registers.
969 We do not allow sharing of addresses that are either a special
970 register or the sum of a constant and a special register because
971 it is possible for unshare_all_rtl to copy the address, into memory
972 that won't be saved. Although the MEM can safely be shared, and
973 won't be copied there, the address itself cannot be shared, and may
976 There are also two exceptions with constants: The first is if the
977 constant is a LABEL_REF or the sum of the LABEL_REF
978 and an integer. This case can happen if we have an inline
979 function that supplies a constant operand to the call of another
980 inline function that uses it in a switch statement. In this case,
981 we will be replacing the LABEL_REF, so we have to replace this MEM
984 The second case is if we have a (const (plus (address ..) ...)).
985 In that case we need to put back the address of the constant pool
988 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
989 && GET_CODE (XEXP (x, 0)) != LABEL_REF
990 && ! (GET_CODE (XEXP (x, 0)) == CONST
991 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS
992 && ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
994 || (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1001 /* Must point to the new insn. */
1002 return gen_rtx (LABEL_REF, GET_MODE (orig),
1003 label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))]);
1007 if (REGNO (x) > LAST_VIRTUAL_REGISTER)
1008 return reg_map [REGNO (x)];
1013 /* If a parm that gets modified lives in a pseudo-reg,
1014 clear its TREE_READONLY to prevent certain optimizations. */
1016 rtx dest = SET_DEST (x);
1018 while (GET_CODE (dest) == STRICT_LOW_PART
1019 || GET_CODE (dest) == ZERO_EXTRACT
1020 || GET_CODE (dest) == SUBREG)
1021 dest = XEXP (dest, 0);
1023 if (GET_CODE (dest) == REG
1024 && REGNO (dest) < max_parm_reg
1025 && REGNO (dest) >= FIRST_PSEUDO_REGISTER
1026 && parmdecl_map[REGNO (dest)] != 0
1027 /* The insn to load an arg pseudo from a stack slot
1028 does not count as modifying it. */
1029 && in_nonparm_insns)
1030 TREE_READONLY (parmdecl_map[REGNO (dest)]) = 0;
1034 #if 0 /* This is a good idea, but here is the wrong place for it. */
1035 /* Arrange that CONST_INTs always appear as the second operand
1036 if they appear, and that `frame_pointer_rtx' or `arg_pointer_rtx'
1037 always appear as the first. */
1039 if (GET_CODE (XEXP (x, 0)) == CONST_INT
1040 || (XEXP (x, 1) == frame_pointer_rtx
1041 || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
1042 && XEXP (x, 1) == arg_pointer_rtx)))
1044 rtx t = XEXP (x, 0);
1045 XEXP (x, 0) = XEXP (x, 1);
1052 /* Replace this rtx with a copy of itself. */
1054 x = rtx_alloc (code);
1055 bcopy (orig, x, (sizeof (*x) - sizeof (x->fld)
1056 + sizeof (x->fld[0]) * GET_RTX_LENGTH (code)));
1058 /* Now scan the subexpressions recursively.
1059 We can store any replaced subexpressions directly into X
1060 since we know X is not shared! Any vectors in X
1061 must be copied if X was copied. */
1063 format_ptr = GET_RTX_FORMAT (code);
1065 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1067 switch (*format_ptr++)
1070 XEXP (x, i) = copy_for_inline (XEXP (x, i));
1074 /* Change any references to old-insns to point to the
1075 corresponding copied insns. */
1076 XEXP (x, i) = insn_map[INSN_UID (XEXP (x, i))];
1080 if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
1084 XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
1085 for (j = 0; j < XVECLEN (x, i); j++)
1087 = copy_for_inline (XVECEXP (x, i, j));
1093 if (code == ASM_OPERANDS && orig_asm_operands_vector == 0)
1095 orig_asm_operands_vector = XVEC (orig, 3);
1096 copy_asm_operands_vector = XVEC (x, 3);
1097 copy_asm_constraints_vector = XVEC (x, 4);
1103 /* Unfortunately, we need a global copy of const_equiv map for communication
1104 with a function called from note_stores. Be *very* careful that this
1105 is used properly in the presence of recursion. */
1107 rtx *global_const_equiv_map;
1109 #define FIXED_BASE_PLUS_P(X) \
1110 (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
1111 && GET_CODE (XEXP (X, 0)) == REG \
1112 && REGNO (XEXP (X, 0)) >= FIRST_VIRTUAL_REGISTER \
1113 && REGNO (XEXP (X, 0)) < LAST_VIRTUAL_REGISTER)
1115 /* Integrate the procedure defined by FNDECL. Note that this function
1116 may wind up calling itself. Since the static variables are not
1117 reentrant, we do not assign them until after the possibility
1118 of recursion is eliminated.
1120 If IGNORE is nonzero, do not produce a value.
1121 Otherwise store the value in TARGET if it is nonzero and that is convenient.
1124 (rtx)-1 if we could not substitute the function
1125 0 if we substituted it and it does not produce a value
1126 else an rtx for where the value is stored. */
1129 expand_inline_function (fndecl, parms, target, ignore, type, structure_value_addr)
1134 rtx structure_value_addr;
1136 tree formal, actual, block;
1137 rtx header = DECL_SAVED_INSNS (fndecl);
1138 rtx insns = FIRST_FUNCTION_INSN (header);
1139 rtx parm_insns = FIRST_PARM_INSN (header);
1145 int min_labelno = FIRST_LABELNO (header);
1146 int max_labelno = LAST_LABELNO (header);
1148 rtx local_return_label = 0;
1151 struct inline_remap *map;
1153 rtvec arg_vector = ORIGINAL_ARG_VECTOR (header);
1155 /* Allow for equivalences of the pseudos we make for virtual fp and ap. */
1156 max_regno = MAX_REGNUM (header) + 3;
1157 if (max_regno < FIRST_PSEUDO_REGISTER)
1160 nargs = list_length (DECL_ARGUMENTS (fndecl));
1162 /* We expect PARMS to have the right length; don't crash if not. */
1163 if (list_length (parms) != nargs)
1164 return (rtx) (HOST_WIDE_INT) -1;
1165 /* Also check that the parms type match. Since the appropriate
1166 conversions or default promotions have already been applied,
1167 the machine modes should match exactly. */
1168 for (formal = DECL_ARGUMENTS (fndecl),
1171 formal = TREE_CHAIN (formal),
1172 actual = TREE_CHAIN (actual))
1174 tree arg = TREE_VALUE (actual);
1175 enum machine_mode mode = TYPE_MODE (DECL_ARG_TYPE (formal));
1176 if (mode != TYPE_MODE (TREE_TYPE (arg)))
1177 return (rtx) (HOST_WIDE_INT) -1;
1178 /* If they are block mode, the types should match exactly.
1179 They don't match exactly if TREE_TYPE (FORMAL) == ERROR_MARK_NODE,
1180 which could happen if the parameter has incomplete type. */
1181 if (mode == BLKmode && TREE_TYPE (arg) != TREE_TYPE (formal))
1182 return (rtx) (HOST_WIDE_INT) -1;
1185 /* Make a binding contour to keep inline cleanups called at
1186 outer function-scope level from looking like they are shadowing
1187 parameter declarations. */
1190 /* Make a fresh binding contour that we can easily remove. */
1192 expand_start_bindings (0);
1193 if (GET_CODE (parm_insns) == NOTE
1194 && NOTE_LINE_NUMBER (parm_insns) > 0)
1195 emit_note (NOTE_SOURCE_FILE (parm_insns), NOTE_LINE_NUMBER (parm_insns));
1197 /* Expand the function arguments. Do this first so that any
1198 new registers get created before we allocate the maps. */
1200 arg_vals = (rtx *) alloca (nargs * sizeof (rtx));
1201 arg_trees = (tree *) alloca (nargs * sizeof (tree));
1203 for (formal = DECL_ARGUMENTS (fndecl), actual = parms, i = 0;
1205 formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual), i++)
1207 /* Actual parameter, converted to the type of the argument within the
1209 tree arg = convert (TREE_TYPE (formal), TREE_VALUE (actual));
1210 /* Mode of the variable used within the function. */
1211 enum machine_mode mode = TYPE_MODE (TREE_TYPE (formal));
1212 /* Where parameter is located in the function. */
1215 emit_note (DECL_SOURCE_FILE (formal), DECL_SOURCE_LINE (formal));
1218 loc = RTVEC_ELT (arg_vector, i);
1220 /* If this is an object passed by invisible reference, we copy the
1221 object into a stack slot and save its address. If this will go
1222 into memory, we do nothing now. Otherwise, we just expand the
1224 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1225 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1228 = assign_stack_temp (TYPE_MODE (TREE_TYPE (arg)),
1229 int_size_in_bytes (TREE_TYPE (arg)), 1);
1231 store_expr (arg, stack_slot, 0);
1233 arg_vals[i] = XEXP (stack_slot, 0);
1235 else if (GET_CODE (loc) != MEM)
1236 /* The mode if LOC and ARG can differ if LOC was a variable
1237 that had its mode promoted via PROMOTED_MODE. */
1238 arg_vals[i] = convert_to_mode (GET_MODE (loc),
1239 expand_expr (arg, NULL_RTX, mode,
1241 TREE_UNSIGNED (TREE_TYPE (formal)));
1245 if (arg_vals[i] != 0
1246 && (! TREE_READONLY (formal)
1247 /* If the parameter is not read-only, copy our argument through
1248 a register. Also, we cannot use ARG_VALS[I] if it overlaps
1249 TARGET in any way. In the inline function, they will likely
1250 be two different pseudos, and `safe_from_p' will make all
1251 sorts of smart assumptions about their not conflicting.
1252 But if ARG_VALS[I] overlaps TARGET, these assumptions are
1253 wrong, so put ARG_VALS[I] into a fresh register. */
1255 && (GET_CODE (arg_vals[i]) == REG
1256 || GET_CODE (arg_vals[i]) == SUBREG
1257 || GET_CODE (arg_vals[i]) == MEM)
1258 && reg_overlap_mentioned_p (arg_vals[i], target))))
1259 arg_vals[i] = copy_to_mode_reg (GET_MODE (loc), arg_vals[i]);
1262 /* Allocate the structures we use to remap things. */
1264 map = (struct inline_remap *) alloca (sizeof (struct inline_remap));
1265 map->fndecl = fndecl;
1267 map->reg_map = (rtx *) alloca (max_regno * sizeof (rtx));
1268 bzero (map->reg_map, max_regno * sizeof (rtx));
1270 map->label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
1271 map->label_map -= min_labelno;
1273 map->insn_map = (rtx *) alloca (INSN_UID (header) * sizeof (rtx));
1274 bzero (map->insn_map, INSN_UID (header) * sizeof (rtx));
1275 map->min_insnno = 0;
1276 map->max_insnno = INSN_UID (header);
1278 /* const_equiv_map maps pseudos in our routine to constants, so it needs to
1279 be large enough for all our pseudos. This is the number we are currently
1280 using plus the number in the called routine, plus 15 for each arg,
1281 five to compute the virtual frame pointer, and five for the return value.
1282 This should be enough for most cases. We do not reference entries
1283 outside the range of the map.
1285 ??? These numbers are quite arbitrary and were obtained by
1286 experimentation. At some point, we should try to allocate the
1287 table after all the parameters are set up so we an more accurately
1288 estimate the number of pseudos we will need. */
1290 map->const_equiv_map_size
1291 = max_reg_num () + (max_regno - FIRST_PSEUDO_REGISTER) + 15 * nargs + 10;
1293 map->const_equiv_map
1294 = (rtx *)alloca (map->const_equiv_map_size * sizeof (rtx));
1295 bzero (map->const_equiv_map, map->const_equiv_map_size * sizeof (rtx));
1298 = (unsigned *)alloca (map->const_equiv_map_size * sizeof (unsigned));
1299 bzero (map->const_age_map, map->const_equiv_map_size * sizeof (unsigned));
1302 /* Record the current insn in case we have to set up pointers to frame
1303 and argument memory blocks. */
1304 map->insns_at_start = get_last_insn ();
1306 /* Update the outgoing argument size to allow for those in the inlined
1308 if (OUTGOING_ARGS_SIZE (header) > current_function_outgoing_args_size)
1309 current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (header);
1311 /* If the inline function needs to make PIC references, that means
1312 that this function's PIC offset table must be used. */
1313 if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE)
1314 current_function_uses_pic_offset_table = 1;
1316 /* Process each argument. For each, set up things so that the function's
1317 reference to the argument will refer to the argument being passed.
1318 We only replace REG with REG here. Any simplifications are done
1319 via const_equiv_map.
1321 We make two passes: In the first, we deal with parameters that will
1322 be placed into registers, since we need to ensure that the allocated
1323 register number fits in const_equiv_map. Then we store all non-register
1324 parameters into their memory location. */
1326 for (i = 0; i < nargs; i++)
1328 rtx copy = arg_vals[i];
1330 loc = RTVEC_ELT (arg_vector, i);
1332 /* There are three cases, each handled separately. */
1333 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1334 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1336 /* This must be an object passed by invisible reference (it could
1337 also be a variable-sized object, but we forbid inlining functions
1338 with variable-sized arguments). COPY is the address of the
1339 actual value (this computation will cause it to be copied). We
1340 map that address for the register, noting the actual address as
1341 an equivalent in case it can be substituted into the insns. */
1343 if (GET_CODE (copy) != REG)
1345 temp = copy_addr_to_reg (copy);
1346 if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1348 map->const_equiv_map[REGNO (temp)] = copy;
1349 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1353 map->reg_map[REGNO (XEXP (loc, 0))] = copy;
1355 else if (GET_CODE (loc) == MEM)
1357 /* This is the case of a parameter that lives in memory.
1358 It will live in the block we allocate in the called routine's
1359 frame that simulates the incoming argument area. Do nothing
1360 now; we will call store_expr later. */
1363 else if (GET_CODE (loc) == REG)
1365 /* This is the good case where the parameter is in a register.
1366 If it is read-only and our argument is a constant, set up the
1367 constant equivalence. */
1368 if (GET_CODE (copy) != REG && GET_CODE (copy) != SUBREG)
1370 temp = copy_to_mode_reg (GET_MODE (loc), copy);
1371 if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1373 map->const_equiv_map[REGNO (temp)] = copy;
1374 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1378 map->reg_map[REGNO (loc)] = copy;
1383 /* Free any temporaries we made setting up this parameter. */
1387 /* Now do the parameters that will be placed in memory. */
1389 for (formal = DECL_ARGUMENTS (fndecl), i = 0;
1390 formal; formal = TREE_CHAIN (formal), i++)
1392 rtx copy = arg_vals[i];
1394 loc = RTVEC_ELT (arg_vector, i);
1396 if (GET_CODE (loc) == MEM
1397 /* Exclude case handled above. */
1398 && ! (GET_CODE (XEXP (loc, 0)) == REG
1399 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER))
1401 emit_note (DECL_SOURCE_FILE (formal), DECL_SOURCE_LINE (formal));
1403 /* Compute the address in the area we reserved and store the
1405 temp = copy_rtx_and_substitute (loc, map);
1406 subst_constants (&temp, NULL_RTX, map);
1407 apply_change_group ();
1408 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
1409 temp = change_address (temp, VOIDmode, XEXP (temp, 0));
1410 store_expr (arg_trees[i], temp, 0);
1412 /* Free any temporaries we made setting up this parameter. */
1417 /* Deal with the places that the function puts its result.
1418 We are driven by what is placed into DECL_RESULT.
1420 Initially, we assume that we don't have anything special handling for
1421 REG_FUNCTION_RETURN_VALUE_P. */
1423 map->inline_target = 0;
1424 loc = DECL_RTL (DECL_RESULT (fndecl));
1425 if (TYPE_MODE (type) == VOIDmode)
1426 /* There is no return value to worry about. */
1428 else if (GET_CODE (loc) == MEM)
1430 if (! structure_value_addr || ! aggregate_value_p (DECL_RESULT (fndecl)))
1433 /* Pass the function the address in which to return a structure value.
1434 Note that a constructor can cause someone to call us with
1435 STRUCTURE_VALUE_ADDR, but the initialization takes place
1436 via the first parameter, rather than the struct return address.
1438 We have two cases: If the address is a simple register indirect,
1439 use the mapping mechanism to point that register to our structure
1440 return address. Otherwise, store the structure return value into
1441 the place that it will be referenced from. */
1443 if (GET_CODE (XEXP (loc, 0)) == REG)
1445 temp = force_reg (Pmode, structure_value_addr);
1446 map->reg_map[REGNO (XEXP (loc, 0))] = temp;
1447 if (CONSTANT_P (structure_value_addr)
1448 || (GET_CODE (structure_value_addr) == PLUS
1449 && XEXP (structure_value_addr, 0) == virtual_stack_vars_rtx
1450 && GET_CODE (XEXP (structure_value_addr, 1)) == CONST_INT))
1452 map->const_equiv_map[REGNO (temp)] = structure_value_addr;
1453 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1458 temp = copy_rtx_and_substitute (loc, map);
1459 subst_constants (&temp, NULL_RTX, map);
1460 apply_change_group ();
1461 emit_move_insn (temp, structure_value_addr);
1465 /* We will ignore the result value, so don't look at its structure.
1466 Note that preparations for an aggregate return value
1467 do need to be made (above) even if it will be ignored. */
1469 else if (GET_CODE (loc) == REG)
1471 /* The function returns an object in a register and we use the return
1472 value. Set up our target for remapping. */
1474 /* Machine mode function was declared to return. */
1475 enum machine_mode departing_mode = TYPE_MODE (type);
1476 /* (Possibly wider) machine mode it actually computes
1477 (for the sake of callers that fail to declare it right). */
1478 enum machine_mode arriving_mode
1479 = TYPE_MODE (TREE_TYPE (DECL_RESULT (fndecl)));
1482 /* Don't use MEMs as direct targets because on some machines
1483 substituting a MEM for a REG makes invalid insns.
1484 Let the combiner substitute the MEM if that is valid. */
1485 if (target == 0 || GET_CODE (target) != REG
1486 || GET_MODE (target) != departing_mode)
1487 target = gen_reg_rtx (departing_mode);
1489 /* If function's value was promoted before return,
1490 avoid machine mode mismatch when we substitute INLINE_TARGET.
1491 But TARGET is what we will return to the caller. */
1492 if (arriving_mode != departing_mode)
1493 reg_to_map = gen_rtx (SUBREG, arriving_mode, target, 0);
1495 reg_to_map = target;
1497 /* Usually, the result value is the machine's return register.
1498 Sometimes it may be a pseudo. Handle both cases. */
1499 if (REG_FUNCTION_VALUE_P (loc))
1500 map->inline_target = reg_to_map;
1502 map->reg_map[REGNO (loc)] = reg_to_map;
1505 /* Make new label equivalences for the labels in the called function. */
1506 for (i = min_labelno; i < max_labelno; i++)
1507 map->label_map[i] = gen_label_rtx ();
1509 /* Perform postincrements before actually calling the function. */
1512 /* Clean up stack so that variables might have smaller offsets. */
1513 do_pending_stack_adjust ();
1515 /* Save a copy of the location of const_equiv_map for mark_stores, called
1517 global_const_equiv_map = map->const_equiv_map;
1519 /* Now copy the insns one by one. Do this in two passes, first the insns and
1520 then their REG_NOTES, just like save_for_inline. */
1522 /* This loop is very similar to the loop in copy_loop_body in unroll.c. */
1524 for (insn = insns; insn; insn = NEXT_INSN (insn))
1528 map->orig_asm_operands_vector = 0;
1530 switch (GET_CODE (insn))
1533 pattern = PATTERN (insn);
1535 if (GET_CODE (pattern) == USE
1536 && GET_CODE (XEXP (pattern, 0)) == REG
1537 && REG_FUNCTION_VALUE_P (XEXP (pattern, 0)))
1538 /* The (USE (REG n)) at return from the function should
1539 be ignored since we are changing (REG n) into
1543 /* Ignore setting a function value that we don't want to use. */
1544 if (map->inline_target == 0
1545 && GET_CODE (pattern) == SET
1546 && GET_CODE (SET_DEST (pattern)) == REG
1547 && REG_FUNCTION_VALUE_P (SET_DEST (pattern)))
1549 if (volatile_refs_p (SET_SRC (pattern)))
1551 /* If we must not delete the source,
1552 load it into a new temporary. */
1553 copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1554 SET_DEST (PATTERN (copy))
1555 = gen_reg_rtx (GET_MODE (SET_DEST (PATTERN (copy))));
1561 copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1562 /* REG_NOTES will be copied later. */
1565 /* If this insn is setting CC0, it may need to look at
1566 the insn that uses CC0 to see what type of insn it is.
1567 In that case, the call to recog via validate_change will
1568 fail. So don't substitute constants here. Instead,
1569 do it when we emit the following insn.
1571 For example, see the pyr.md file. That machine has signed and
1572 unsigned compares. The compare patterns must check the
1573 following branch insn to see which what kind of compare to
1576 If the previous insn set CC0, substitute constants on it as
1578 if (sets_cc0_p (PATTERN (copy)) != 0)
1583 try_constants (cc0_insn, map);
1585 try_constants (copy, map);
1588 try_constants (copy, map);
1593 if (GET_CODE (PATTERN (insn)) == RETURN)
1595 if (local_return_label == 0)
1596 local_return_label = gen_label_rtx ();
1597 pattern = gen_jump (local_return_label);
1600 pattern = copy_rtx_and_substitute (PATTERN (insn), map);
1602 copy = emit_jump_insn (pattern);
1606 try_constants (cc0_insn, map);
1609 try_constants (copy, map);
1611 /* If this used to be a conditional jump insn but whose branch
1612 direction is now know, we must do something special. */
1613 if (condjump_p (insn) && ! simplejump_p (insn) && map->last_pc_value)
1616 /* The previous insn set cc0 for us. So delete it. */
1617 delete_insn (PREV_INSN (copy));
1620 /* If this is now a no-op, delete it. */
1621 if (map->last_pc_value == pc_rtx)
1627 /* Otherwise, this is unconditional jump so we must put a
1628 BARRIER after it. We could do some dead code elimination
1629 here, but jump.c will do it just as well. */
1635 pattern = copy_rtx_and_substitute (PATTERN (insn), map);
1636 copy = emit_call_insn (pattern);
1640 try_constants (cc0_insn, map);
1643 try_constants (copy, map);
1645 /* Be lazy and assume CALL_INSNs clobber all hard registers. */
1646 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1647 map->const_equiv_map[i] = 0;
1651 copy = emit_label (map->label_map[CODE_LABEL_NUMBER (insn)]);
1652 LABEL_NAME (copy) = LABEL_NAME (insn);
1657 copy = emit_barrier ();
1661 /* It is important to discard function-end and function-beg notes,
1662 so we have only one of each in the current function.
1663 Also, NOTE_INSN_DELETED notes aren't useful (save_for_inline
1664 deleted these in the copy used for continuing compilation,
1665 not the copy used for inlining). */
1666 if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END
1667 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_BEG
1668 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
1669 copy = emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
1680 RTX_INTEGRATED_P (copy) = 1;
1682 map->insn_map[INSN_UID (insn)] = copy;
1685 /* Now copy the REG_NOTES. */
1686 for (insn = insns; insn; insn = NEXT_INSN (insn))
1687 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
1688 && map->insn_map[INSN_UID (insn)])
1689 REG_NOTES (map->insn_map[INSN_UID (insn)])
1690 = copy_rtx_and_substitute (REG_NOTES (insn), map);
1692 if (local_return_label)
1693 emit_label (local_return_label);
1695 /* Make copies of the decls of the symbols in the inline function, so that
1696 the copies of the variables get declared in the current function. Set
1697 up things so that lookup_static_chain knows that to interpret registers
1698 in SAVE_EXPRs for TYPE_SIZEs as local. */
1700 inline_function_decl = fndecl;
1701 integrate_parm_decls (DECL_ARGUMENTS (fndecl), map, arg_vector);
1702 integrate_decl_tree ((tree) ORIGINAL_DECL_INITIAL (header), 0, map);
1703 inline_function_decl = 0;
1705 /* End the scope containing the copied formal parameter variables
1706 and copied LABEL_DECLs. */
1708 expand_end_bindings (getdecls (), 1, 1);
1709 block = poplevel (1, 1, 0);
1710 BLOCK_ABSTRACT_ORIGIN (block) = fndecl;
1712 emit_line_note (input_filename, lineno);
1714 if (structure_value_addr)
1715 return gen_rtx (MEM, TYPE_MODE (type),
1716 memory_address (TYPE_MODE (type), structure_value_addr));
1720 /* Given a chain of PARM_DECLs, ARGS, copy each decl into a VAR_DECL,
1721 push all of those decls and give each one the corresponding home. */
1724 integrate_parm_decls (args, map, arg_vector)
1726 struct inline_remap *map;
1732 for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
1734 register tree decl = build_decl (VAR_DECL, DECL_NAME (tail),
1737 = copy_rtx_and_substitute (RTVEC_ELT (arg_vector, i), map);
1739 /* These args would always appear unused, if not for this. */
1740 TREE_USED (decl) = 1;
1741 /* Prevent warning for shadowing with these. */
1742 DECL_ABSTRACT_ORIGIN (decl) = tail;
1744 /* Fully instantiate the address with the equivalent form so that the
1745 debugging information contains the actual register, instead of the
1746 virtual register. Do this by not passing an insn to
1748 subst_constants (&new_decl_rtl, NULL_RTX, map);
1749 apply_change_group ();
1750 DECL_RTL (decl) = new_decl_rtl;
1754 /* Given a BLOCK node LET, push decls and levels so as to construct in the
1755 current function a tree of contexts isomorphic to the one that is given.
1757 LEVEL indicates how far down into the BLOCK tree is the node we are
1758 currently traversing. It is always zero except for recursive calls.
1760 MAP, if nonzero, is a pointer to an inline_remap map which indicates how
1761 registers used in the DECL_RTL field should be remapped. If it is zero,
1762 no mapping is necessary. */
1765 integrate_decl_tree (let, level, map)
1768 struct inline_remap *map;
1775 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
1777 tree d = build_decl (TREE_CODE (t), DECL_NAME (t), TREE_TYPE (t));
1778 DECL_SOURCE_LINE (d) = DECL_SOURCE_LINE (t);
1779 DECL_SOURCE_FILE (d) = DECL_SOURCE_FILE (t);
1780 if (DECL_RTL (t) != 0)
1782 DECL_RTL (d) = copy_rtx_and_substitute (DECL_RTL (t), map);
1783 /* Fully instantiate the address with the equivalent form so that the
1784 debugging information contains the actual register, instead of the
1785 virtual register. Do this by not passing an insn to
1787 subst_constants (&DECL_RTL (d), NULL_RTX, map);
1788 apply_change_group ();
1790 else if (DECL_RTL (t))
1791 DECL_RTL (d) = copy_rtx (DECL_RTL (t));
1792 DECL_EXTERNAL (d) = DECL_EXTERNAL (t);
1793 TREE_STATIC (d) = TREE_STATIC (t);
1794 TREE_PUBLIC (d) = TREE_PUBLIC (t);
1795 TREE_CONSTANT (d) = TREE_CONSTANT (t);
1796 TREE_ADDRESSABLE (d) = TREE_ADDRESSABLE (t);
1797 TREE_READONLY (d) = TREE_READONLY (t);
1798 TREE_SIDE_EFFECTS (d) = TREE_SIDE_EFFECTS (t);
1799 /* These args would always appear unused, if not for this. */
1801 /* Prevent warning for shadowing with these. */
1802 DECL_ABSTRACT_ORIGIN (d) = t;
1806 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
1807 integrate_decl_tree (t, level + 1, map);
1811 node = poplevel (1, 0, 0);
1814 TREE_USED (node) = TREE_USED (let);
1815 BLOCK_ABSTRACT_ORIGIN (node) = let;
1820 /* Create a new copy of an rtx.
1821 Recursively copies the operands of the rtx,
1822 except for those few rtx codes that are sharable.
1824 We always return an rtx that is similar to that incoming rtx, with the
1825 exception of possibly changing a REG to a SUBREG or vice versa. No
1826 rtl is ever emitted.
1828 Handle constants that need to be placed in the constant pool by
1829 calling `force_const_mem'. */
1832 copy_rtx_and_substitute (orig, map)
1834 struct inline_remap *map;
1836 register rtx copy, temp;
1838 register RTX_CODE code;
1839 register enum machine_mode mode;
1840 register char *format_ptr;
1846 code = GET_CODE (orig);
1847 mode = GET_MODE (orig);
1852 /* If the stack pointer register shows up, it must be part of
1853 stack-adjustments (*not* because we eliminated the frame pointer!).
1854 Small hard registers are returned as-is. Pseudo-registers
1855 go through their `reg_map'. */
1856 regno = REGNO (orig);
1857 if (regno <= LAST_VIRTUAL_REGISTER)
1859 /* Some hard registers are also mapped,
1860 but others are not translated. */
1861 if (map->reg_map[regno] != 0)
1862 return map->reg_map[regno];
1864 /* If this is the virtual frame pointer, make space in current
1865 function's stack frame for the stack frame of the inline function.
1867 Copy the address of this area into a pseudo. Map
1868 virtual_stack_vars_rtx to this pseudo and set up a constant
1869 equivalence for it to be the address. This will substitute the
1870 address into insns where it can be substituted and use the new
1871 pseudo where it can't. */
1872 if (regno == VIRTUAL_STACK_VARS_REGNUM)
1875 int size = DECL_FRAME_SIZE (map->fndecl);
1879 loc = assign_stack_temp (BLKmode, size, 1);
1880 loc = XEXP (loc, 0);
1881 #ifdef FRAME_GROWS_DOWNWARD
1882 /* In this case, virtual_stack_vars_rtx points to one byte
1883 higher than the top of the frame area. So compute the offset
1884 to one byte higher than our substitute frame.
1885 Keep the fake frame pointer aligned like a real one. */
1886 rounded = CEIL_ROUND (size, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
1887 loc = plus_constant (loc, rounded);
1889 map->reg_map[regno] = temp
1890 = force_reg (Pmode, force_operand (loc, NULL_RTX));
1891 map->const_equiv_map[REGNO (temp)] = loc;
1892 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1894 seq = gen_sequence ();
1896 emit_insn_after (seq, map->insns_at_start);
1899 else if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
1901 /* Do the same for a block to contain any arguments referenced
1904 int size = FUNCTION_ARGS_SIZE (DECL_SAVED_INSNS (map->fndecl));
1907 loc = assign_stack_temp (BLKmode, size, 1);
1908 loc = XEXP (loc, 0);
1909 /* When arguments grow downward, the virtual incoming
1910 args pointer points to the top of the argument block,
1911 so the remapped location better do the same. */
1912 #ifdef ARGS_GROW_DOWNWARD
1913 loc = plus_constant (loc, size);
1915 map->reg_map[regno] = temp
1916 = force_reg (Pmode, force_operand (loc, NULL_RTX));
1917 map->const_equiv_map[REGNO (temp)] = loc;
1918 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1920 seq = gen_sequence ();
1922 emit_insn_after (seq, map->insns_at_start);
1925 else if (REG_FUNCTION_VALUE_P (orig))
1927 /* This is a reference to the function return value. If
1928 the function doesn't have a return value, error. If the
1929 mode doesn't agree, make a SUBREG. */
1930 if (map->inline_target == 0)
1931 /* Must be unrolling loops or replicating code if we
1932 reach here, so return the register unchanged. */
1934 else if (mode != GET_MODE (map->inline_target))
1935 return gen_rtx (SUBREG, mode, map->inline_target, 0);
1937 return map->inline_target;
1941 if (map->reg_map[regno] == NULL)
1943 map->reg_map[regno] = gen_reg_rtx (mode);
1944 REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (orig);
1945 REG_LOOP_TEST_P (map->reg_map[regno]) = REG_LOOP_TEST_P (orig);
1946 RTX_UNCHANGING_P (map->reg_map[regno]) = RTX_UNCHANGING_P (orig);
1947 /* A reg with REG_FUNCTION_VALUE_P true will never reach here. */
1949 return map->reg_map[regno];
1952 copy = copy_rtx_and_substitute (SUBREG_REG (orig), map);
1953 /* SUBREG is ordinary, but don't make nested SUBREGs. */
1954 if (GET_CODE (copy) == SUBREG)
1955 return gen_rtx (SUBREG, GET_MODE (orig), SUBREG_REG (copy),
1956 SUBREG_WORD (orig) + SUBREG_WORD (copy));
1958 return gen_rtx (SUBREG, GET_MODE (orig), copy,
1959 SUBREG_WORD (orig));
1963 /* USE and CLOBBER are ordinary, but we convert (use (subreg foo))
1965 copy = copy_rtx_and_substitute (XEXP (orig, 0), map);
1966 if (GET_CODE (copy) == SUBREG)
1967 copy = SUBREG_REG (copy);
1968 return gen_rtx (code, VOIDmode, copy);
1971 LABEL_PRESERVE_P (map->label_map[CODE_LABEL_NUMBER (orig)])
1972 = LABEL_PRESERVE_P (orig);
1973 return map->label_map[CODE_LABEL_NUMBER (orig)];
1976 copy = rtx_alloc (LABEL_REF);
1977 PUT_MODE (copy, mode);
1978 XEXP (copy, 0) = map->label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))];
1979 LABEL_OUTSIDE_LOOP_P (copy) = LABEL_OUTSIDE_LOOP_P (orig);
1988 /* Symbols which represent the address of a label stored in the constant
1989 pool must be modified to point to a constant pool entry for the
1990 remapped label. Otherwise, symbols are returned unchanged. */
1991 if (CONSTANT_POOL_ADDRESS_P (orig))
1993 rtx constant = get_pool_constant (orig);
1994 if (GET_CODE (constant) == LABEL_REF)
1996 copy = rtx_alloc (LABEL_REF);
1997 PUT_MODE (copy, mode);
1999 = map->label_map[CODE_LABEL_NUMBER (XEXP (constant, 0))];
2000 LABEL_OUTSIDE_LOOP_P (copy) = LABEL_OUTSIDE_LOOP_P (orig);
2001 copy = force_const_mem (Pmode, copy);
2002 return XEXP (copy, 0);
2008 /* We have to make a new copy of this CONST_DOUBLE because don't want
2009 to use the old value of CONST_DOUBLE_MEM. Also, this may be a
2010 duplicate of a CONST_DOUBLE we have already seen. */
2011 if (GET_MODE_CLASS (GET_MODE (orig)) == MODE_FLOAT)
2015 REAL_VALUE_FROM_CONST_DOUBLE (d, orig);
2016 return immed_real_const_1 (d, GET_MODE (orig));
2019 return immed_double_const (CONST_DOUBLE_LOW (orig),
2020 CONST_DOUBLE_HIGH (orig), VOIDmode);
2023 /* Make new constant pool entry for a constant
2024 that was in the pool of the inline function. */
2025 if (RTX_INTEGRATED_P (orig))
2027 /* If this was an address of a constant pool entry that itself
2028 had to be placed in the constant pool, it might not be a
2029 valid address. So the recursive call below might turn it
2030 into a register. In that case, it isn't a constant any
2031 more, so return it. This has the potential of changing a
2032 MEM into a REG, but we'll assume that it safe. */
2033 temp = copy_rtx_and_substitute (XEXP (orig, 0), map);
2034 if (! CONSTANT_P (temp))
2036 return validize_mem (force_const_mem (GET_MODE (orig), temp));
2041 /* If from constant pool address, make new constant pool entry and
2042 return its address. */
2043 if (! RTX_INTEGRATED_P (orig))
2046 temp = force_const_mem (GET_MODE (orig),
2047 copy_rtx_and_substitute (XEXP (orig, 0), map));
2050 /* Legitimizing the address here is incorrect.
2052 The only ADDRESS rtx's that can reach here are ones created by
2053 save_constants. Hence the operand of the ADDRESS is always legal
2054 in this position of the instruction, since the original rtx without
2055 the ADDRESS was legal.
2057 The reason we don't legitimize the address here is that on the
2058 Sparc, the caller may have a (high ...) surrounding this ADDRESS.
2059 This code forces the operand of the address to a register, which
2060 fails because we can not take the HIGH part of a register.
2062 Also, change_address may create new registers. These registers
2063 will not have valid reg_map entries. This can cause try_constants()
2064 to fail because assumes that all registers in the rtx have valid
2065 reg_map entries, and it may end up replacing one of these new
2066 registers with junk. */
2068 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
2069 temp = change_address (temp, GET_MODE (temp), XEXP (temp, 0));
2072 return XEXP (temp, 0);
2075 /* If a single asm insn contains multiple output operands
2076 then it contains multiple ASM_OPERANDS rtx's that share operand 3.
2077 We must make sure that the copied insn continues to share it. */
2078 if (map->orig_asm_operands_vector == XVEC (orig, 3))
2080 copy = rtx_alloc (ASM_OPERANDS);
2081 XSTR (copy, 0) = XSTR (orig, 0);
2082 XSTR (copy, 1) = XSTR (orig, 1);
2083 XINT (copy, 2) = XINT (orig, 2);
2084 XVEC (copy, 3) = map->copy_asm_operands_vector;
2085 XVEC (copy, 4) = map->copy_asm_constraints_vector;
2086 XSTR (copy, 5) = XSTR (orig, 5);
2087 XINT (copy, 6) = XINT (orig, 6);
2093 /* This is given special treatment because the first
2094 operand of a CALL is a (MEM ...) which may get
2095 forced into a register for cse. This is undesirable
2096 if function-address cse isn't wanted or if we won't do cse. */
2097 #ifndef NO_FUNCTION_CSE
2098 if (! (optimize && ! flag_no_function_cse))
2100 return gen_rtx (CALL, GET_MODE (orig),
2101 gen_rtx (MEM, GET_MODE (XEXP (orig, 0)),
2102 copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0), map)),
2103 copy_rtx_and_substitute (XEXP (orig, 1), map));
2107 /* Must be ifdefed out for loop unrolling to work. */
2113 /* If this is setting fp or ap, it means that we have a nonlocal goto.
2115 If the nonlocal goto is into the current function,
2116 this will result in unnecessarily bad code, but should work. */
2117 if (SET_DEST (orig) == virtual_stack_vars_rtx
2118 || SET_DEST (orig) == virtual_incoming_args_rtx)
2119 return gen_rtx (SET, VOIDmode, SET_DEST (orig),
2120 copy_rtx_and_substitute (SET_SRC (orig), map));
2124 copy = rtx_alloc (MEM);
2125 PUT_MODE (copy, mode);
2126 XEXP (copy, 0) = copy_rtx_and_substitute (XEXP (orig, 0), map);
2127 MEM_IN_STRUCT_P (copy) = MEM_IN_STRUCT_P (orig);
2128 MEM_VOLATILE_P (copy) = MEM_VOLATILE_P (orig);
2129 RTX_UNCHANGING_P (copy) = RTX_UNCHANGING_P (orig);
2133 copy = rtx_alloc (code);
2134 PUT_MODE (copy, mode);
2135 copy->in_struct = orig->in_struct;
2136 copy->volatil = orig->volatil;
2137 copy->unchanging = orig->unchanging;
2139 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
2141 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
2143 switch (*format_ptr++)
2149 XEXP (copy, i) = copy_rtx_and_substitute (XEXP (orig, i), map);
2153 /* Change any references to old-insns to point to the
2154 corresponding copied insns. */
2155 XEXP (copy, i) = map->insn_map[INSN_UID (XEXP (orig, i))];
2159 XVEC (copy, i) = XVEC (orig, i);
2160 if (XVEC (orig, i) != NULL && XVECLEN (orig, i) != 0)
2162 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
2163 for (j = 0; j < XVECLEN (copy, i); j++)
2164 XVECEXP (copy, i, j)
2165 = copy_rtx_and_substitute (XVECEXP (orig, i, j), map);
2170 XWINT (copy, i) = XWINT (orig, i);
2174 XINT (copy, i) = XINT (orig, i);
2178 XSTR (copy, i) = XSTR (orig, i);
2186 if (code == ASM_OPERANDS && map->orig_asm_operands_vector == 0)
2188 map->orig_asm_operands_vector = XVEC (orig, 3);
2189 map->copy_asm_operands_vector = XVEC (copy, 3);
2190 map->copy_asm_constraints_vector = XVEC (copy, 4);
2196 /* Substitute known constant values into INSN, if that is valid. */
2199 try_constants (insn, map)
2201 struct inline_remap *map;
2206 subst_constants (&PATTERN (insn), insn, map);
2208 /* Apply the changes if they are valid; otherwise discard them. */
2209 apply_change_group ();
2211 /* Show we don't know the value of anything stored or clobbered. */
2212 note_stores (PATTERN (insn), mark_stores);
2213 map->last_pc_value = 0;
2215 map->last_cc0_value = 0;
2218 /* Set up any constant equivalences made in this insn. */
2219 for (i = 0; i < map->num_sets; i++)
2221 if (GET_CODE (map->equiv_sets[i].dest) == REG)
2223 int regno = REGNO (map->equiv_sets[i].dest);
2225 if (map->const_equiv_map[regno] == 0
2226 /* Following clause is a hack to make case work where GNU C++
2227 reassigns a variable to make cse work right. */
2228 || ! rtx_equal_p (map->const_equiv_map[regno],
2229 map->equiv_sets[i].equiv))
2231 map->const_equiv_map[regno] = map->equiv_sets[i].equiv;
2232 map->const_age_map[regno] = map->const_age;
2235 else if (map->equiv_sets[i].dest == pc_rtx)
2236 map->last_pc_value = map->equiv_sets[i].equiv;
2238 else if (map->equiv_sets[i].dest == cc0_rtx)
2239 map->last_cc0_value = map->equiv_sets[i].equiv;
2244 /* Substitute known constants for pseudo regs in the contents of LOC,
2245 which are part of INSN.
2246 If INSN is zero, the substitution should always be done (this is used to
2248 These changes are taken out by try_constants if the result is not valid.
2250 Note that we are more concerned with determining when the result of a SET
2251 is a constant, for further propagation, than actually inserting constants
2252 into insns; cse will do the latter task better.
2254 This function is also used to adjust address of items previously addressed
2255 via the virtual stack variable or virtual incoming arguments registers. */
2258 subst_constants (loc, insn, map)
2261 struct inline_remap *map;
2265 register enum rtx_code code;
2266 register char *format_ptr;
2267 int num_changes = num_validated_changes ();
2269 enum machine_mode op0_mode;
2271 code = GET_CODE (x);
2286 validate_change (insn, loc, map->last_cc0_value, 1);
2292 /* The only thing we can do with a USE or CLOBBER is possibly do
2293 some substitutions in a MEM within it. */
2294 if (GET_CODE (XEXP (x, 0)) == MEM)
2295 subst_constants (&XEXP (XEXP (x, 0), 0), insn, map);
2299 /* Substitute for parms and known constants. Don't replace
2300 hard regs used as user variables with constants. */
2302 int regno = REGNO (x);
2304 if (! (regno < FIRST_PSEUDO_REGISTER && REG_USERVAR_P (x))
2305 && regno < map->const_equiv_map_size
2306 && map->const_equiv_map[regno] != 0
2307 && map->const_age_map[regno] >= map->const_age)
2308 validate_change (insn, loc, map->const_equiv_map[regno], 1);
2313 /* SUBREG is ordinary, but don't make nested SUBREGs and try to simplify
2316 rtx inner = SUBREG_REG (x);
2319 /* We can't call subst_constants on &SUBREG_REG (x) because any
2320 constant or SUBREG wouldn't be valid inside our SUBEG. Instead,
2321 see what is inside, try to form the new SUBREG and see if that is
2322 valid. We handle two cases: extracting a full word in an
2323 integral mode and extracting the low part. */
2324 subst_constants (&inner, NULL_RTX, map);
2326 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2327 && GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD
2328 && GET_MODE (SUBREG_REG (x)) != VOIDmode)
2329 new = operand_subword (inner, SUBREG_WORD (x), 0,
2330 GET_MODE (SUBREG_REG (x)));
2332 if (new == 0 && subreg_lowpart_p (x))
2333 new = gen_lowpart_common (GET_MODE (x), inner);
2336 validate_change (insn, loc, new, 1);
2342 subst_constants (&XEXP (x, 0), insn, map);
2344 /* If a memory address got spoiled, change it back. */
2345 if (insn != 0 && num_validated_changes () != num_changes
2346 && !memory_address_p (GET_MODE (x), XEXP (x, 0)))
2347 cancel_changes (num_changes);
2352 /* Substitute constants in our source, and in any arguments to a
2353 complex (e..g, ZERO_EXTRACT) destination, but not in the destination
2355 rtx *dest_loc = &SET_DEST (x);
2356 rtx dest = *dest_loc;
2359 subst_constants (&SET_SRC (x), insn, map);
2362 while (GET_CODE (*dest_loc) == ZERO_EXTRACT
2363 /* By convention, we always use ZERO_EXTRACT in the dest. */
2364 /* || GET_CODE (*dest_loc) == SIGN_EXTRACT */
2365 || GET_CODE (*dest_loc) == SUBREG
2366 || GET_CODE (*dest_loc) == STRICT_LOW_PART)
2368 if (GET_CODE (*dest_loc) == ZERO_EXTRACT)
2370 subst_constants (&XEXP (*dest_loc, 1), insn, map);
2371 subst_constants (&XEXP (*dest_loc, 2), insn, map);
2373 dest_loc = &XEXP (*dest_loc, 0);
2376 /* Do substitute in the address of a destination in memory. */
2377 if (GET_CODE (*dest_loc) == MEM)
2378 subst_constants (&XEXP (*dest_loc, 0), insn, map);
2380 /* Check for the case of DEST a SUBREG, both it and the underlying
2381 register are less than one word, and the SUBREG has the wider mode.
2382 In the case, we are really setting the underlying register to the
2383 source converted to the mode of DEST. So indicate that. */
2384 if (GET_CODE (dest) == SUBREG
2385 && GET_MODE_SIZE (GET_MODE (dest)) <= UNITS_PER_WORD
2386 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) <= UNITS_PER_WORD
2387 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2388 <= GET_MODE_SIZE (GET_MODE (dest)))
2389 && (tem = gen_lowpart_if_possible (GET_MODE (dest), src)))
2390 src = tem, dest = SUBREG_REG (dest);
2392 /* If storing a recognizable value save it for later recording. */
2393 if ((map->num_sets < MAX_RECOG_OPERANDS)
2394 && (CONSTANT_P (src)
2395 || (GET_CODE (src) == PLUS
2396 && GET_CODE (XEXP (src, 0)) == REG
2397 && REGNO (XEXP (src, 0)) >= FIRST_VIRTUAL_REGISTER
2398 && REGNO (XEXP (src, 0)) <= LAST_VIRTUAL_REGISTER
2399 && CONSTANT_P (XEXP (src, 1)))
2400 || GET_CODE (src) == COMPARE
2405 && (src == pc_rtx || GET_CODE (src) == RETURN
2406 || GET_CODE (src) == LABEL_REF))))
2408 /* Normally, this copy won't do anything. But, if SRC is a COMPARE
2409 it will cause us to save the COMPARE with any constants
2410 substituted, which is what we want for later. */
2411 map->equiv_sets[map->num_sets].equiv = copy_rtx (src);
2412 map->equiv_sets[map->num_sets++].dest = dest;
2419 format_ptr = GET_RTX_FORMAT (code);
2421 /* If the first operand is an expression, save its mode for later. */
2422 if (*format_ptr == 'e')
2423 op0_mode = GET_MODE (XEXP (x, 0));
2425 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2427 switch (*format_ptr++)
2434 subst_constants (&XEXP (x, i), insn, map);
2444 if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
2447 for (j = 0; j < XVECLEN (x, i); j++)
2448 subst_constants (&XVECEXP (x, i, j), insn, map);
2457 /* If this is a commutative operation, move a constant to the second
2458 operand unless the second operand is already a CONST_INT. */
2459 if ((GET_RTX_CLASS (code) == 'c' || code == NE || code == EQ)
2460 && CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT)
2462 rtx tem = XEXP (x, 0);
2463 validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
2464 validate_change (insn, &XEXP (x, 1), tem, 1);
2467 /* Simplify the expression in case we put in some constants. */
2468 switch (GET_RTX_CLASS (code))
2471 new = simplify_unary_operation (code, GET_MODE (x),
2472 XEXP (x, 0), op0_mode);
2477 enum machine_mode op_mode = GET_MODE (XEXP (x, 0));
2478 if (op_mode == VOIDmode)
2479 op_mode = GET_MODE (XEXP (x, 1));
2480 new = simplify_relational_operation (code, op_mode,
2481 XEXP (x, 0), XEXP (x, 1));
2482 #ifdef FLOAT_STORE_FLAG_VALUE
2483 if (new != 0 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2484 new = ((new == const0_rtx) ? CONST0_RTX (GET_MODE (x))
2485 : immed_real_const_1 (FLOAT_STORE_FLAG_VALUE, GET_MODE (x)));
2492 new = simplify_binary_operation (code, GET_MODE (x),
2493 XEXP (x, 0), XEXP (x, 1));
2498 new = simplify_ternary_operation (code, GET_MODE (x), op0_mode,
2499 XEXP (x, 0), XEXP (x, 1), XEXP (x, 2));
2504 validate_change (insn, loc, new, 1);
2507 /* Show that register modified no longer contain known constants. We are
2508 called from note_stores with parts of the new insn. */
2511 mark_stores (dest, x)
2515 if (GET_CODE (dest) == SUBREG)
2516 dest = SUBREG_REG (dest);
2518 if (GET_CODE (dest) == REG)
2519 global_const_equiv_map[REGNO (dest)] = 0;
2522 /* If any CONST expressions with RTX_INTEGRATED_P are present in the rtx
2523 pointed to by PX, they represent constants in the constant pool.
2524 Replace these with a new memory reference obtained from force_const_mem.
2525 Similarly, ADDRESS expressions with RTX_INTEGRATED_P represent the
2526 address of a constant pool entry. Replace them with the address of
2527 a new constant pool entry obtained from force_const_mem. */
2530 restore_constants (px)
2540 if (GET_CODE (x) == CONST_DOUBLE)
2542 /* We have to make a new CONST_DOUBLE to ensure that we account for
2543 it correctly. Using the old CONST_DOUBLE_MEM data is wrong. */
2544 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2548 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2549 *px = immed_real_const_1 (d, GET_MODE (x));
2552 *px = immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
2556 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == CONST)
2558 restore_constants (&XEXP (x, 0));
2559 *px = validize_mem (force_const_mem (GET_MODE (x), XEXP (x, 0)));
2561 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == SUBREG)
2563 /* This must be (subreg/i:M1 (const/i:M2 ...) 0). */
2564 rtx new = XEXP (SUBREG_REG (x), 0);
2566 restore_constants (&new);
2567 new = force_const_mem (GET_MODE (SUBREG_REG (x)), new);
2568 PUT_MODE (new, GET_MODE (x));
2569 *px = validize_mem (new);
2571 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == ADDRESS)
2573 restore_constants (&XEXP (x, 0));
2574 *px = XEXP (force_const_mem (GET_MODE (x), XEXP (x, 0)), 0);
2578 fmt = GET_RTX_FORMAT (GET_CODE (x));
2579 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
2584 for (j = 0; j < XVECLEN (x, i); j++)
2585 restore_constants (&XVECEXP (x, i, j));
2589 restore_constants (&XEXP (x, i));
2596 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
2597 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
2598 that it points to the node itself, thus indicating that the node is its
2599 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
2600 the given node is NULL, recursively descend the decl/block tree which
2601 it is the root of, and for each other ..._DECL or BLOCK node contained
2602 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
2603 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
2604 values to point to themselves. */
2606 static void set_decl_origin_self ();
2609 set_block_origin_self (stmt)
2612 if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
2614 BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
2617 register tree local_decl;
2619 for (local_decl = BLOCK_VARS (stmt);
2620 local_decl != NULL_TREE;
2621 local_decl = TREE_CHAIN (local_decl))
2622 set_decl_origin_self (local_decl); /* Potential recursion. */
2626 register tree subblock;
2628 for (subblock = BLOCK_SUBBLOCKS (stmt);
2629 subblock != NULL_TREE;
2630 subblock = BLOCK_CHAIN (subblock))
2631 set_block_origin_self (subblock); /* Recurse. */
2636 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
2637 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
2638 node to so that it points to the node itself, thus indicating that the
2639 node represents its own (abstract) origin. Additionally, if the
2640 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
2641 the decl/block tree of which the given node is the root of, and for
2642 each other ..._DECL or BLOCK node contained therein whose
2643 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
2644 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
2645 point to themselves. */
2648 set_decl_origin_self (decl)
2651 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
2653 DECL_ABSTRACT_ORIGIN (decl) = decl;
2654 if (TREE_CODE (decl) == FUNCTION_DECL)
2658 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
2659 DECL_ABSTRACT_ORIGIN (arg) = arg;
2660 if (DECL_INITIAL (decl) != NULL_TREE)
2661 set_block_origin_self (DECL_INITIAL (decl));
2666 /* Given a pointer to some BLOCK node, and a boolean value to set the
2667 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
2668 the given block, and for all local decls and all local sub-blocks
2669 (recursively) which are contained therein. */
2671 void set_decl_abstract_flags ();
2674 set_block_abstract_flags (stmt, setting)
2676 register int setting;
2678 BLOCK_ABSTRACT (stmt) = setting;
2681 register tree local_decl;
2683 for (local_decl = BLOCK_VARS (stmt);
2684 local_decl != NULL_TREE;
2685 local_decl = TREE_CHAIN (local_decl))
2686 set_decl_abstract_flags (local_decl, setting);
2690 register tree subblock;
2692 for (subblock = BLOCK_SUBBLOCKS (stmt);
2693 subblock != NULL_TREE;
2694 subblock = BLOCK_CHAIN (subblock))
2695 set_block_abstract_flags (subblock, setting);
2699 /* Given a pointer to some ..._DECL node, and a boolean value to set the
2700 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
2701 given decl, and (in the case where the decl is a FUNCTION_DECL) also
2702 set the abstract flags for all of the parameters, local vars, local
2703 blocks and sub-blocks (recursively) to the same setting. */
2706 set_decl_abstract_flags (decl, setting)
2708 register int setting;
2710 DECL_ABSTRACT (decl) = setting;
2711 if (TREE_CODE (decl) == FUNCTION_DECL)
2715 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
2716 DECL_ABSTRACT (arg) = setting;
2717 if (DECL_INITIAL (decl) != NULL_TREE)
2718 set_block_abstract_flags (DECL_INITIAL (decl), setting);
2722 /* Output the assembly language code for the function FNDECL
2723 from its DECL_SAVED_INSNS. Used for inline functions that are output
2724 at end of compilation instead of where they came in the source. */
2727 output_inline_function (fndecl)
2730 rtx head = DECL_SAVED_INSNS (fndecl);
2733 temporary_allocation ();
2735 current_function_decl = fndecl;
2737 /* This call is only used to initialize global variables. */
2738 init_function_start (fndecl, "lossage", 1);
2740 /* Redo parameter determinations in case the FUNCTION_...
2741 macros took machine-specific actions that need to be redone. */
2742 assign_parms (fndecl, 1);
2744 /* Set stack frame size. */
2745 assign_stack_local (BLKmode, DECL_FRAME_SIZE (fndecl), 0);
2747 restore_reg_data (FIRST_PARM_INSN (head));
2749 stack_slot_list = STACK_SLOT_LIST (head);
2751 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_ALLOCA)
2752 current_function_calls_alloca = 1;
2754 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_SETJMP)
2755 current_function_calls_setjmp = 1;
2757 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_LONGJMP)
2758 current_function_calls_longjmp = 1;
2760 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_STRUCT)
2761 current_function_returns_struct = 1;
2763 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_PCC_STRUCT)
2764 current_function_returns_pcc_struct = 1;
2766 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_NEEDS_CONTEXT)
2767 current_function_needs_context = 1;
2769 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_HAS_NONLOCAL_LABEL)
2770 current_function_has_nonlocal_label = 1;
2772 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_POINTER)
2773 current_function_returns_pointer = 1;
2775 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_USES_CONST_POOL)
2776 current_function_uses_const_pool = 1;
2778 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE)
2779 current_function_uses_pic_offset_table = 1;
2781 current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (head);
2782 current_function_pops_args = POPS_ARGS (head);
2784 /* There is no need to output a return label again. */
2787 expand_function_end (DECL_SOURCE_FILE (fndecl), DECL_SOURCE_LINE (fndecl));
2789 /* Find last insn and rebuild the constant pool. */
2790 for (last = FIRST_PARM_INSN (head);
2791 NEXT_INSN (last); last = NEXT_INSN (last))
2793 if (GET_RTX_CLASS (GET_CODE (last)) == 'i')
2795 restore_constants (&PATTERN (last));
2796 restore_constants (®_NOTES (last));
2800 set_new_first_and_last_insn (FIRST_PARM_INSN (head), last);
2801 set_new_first_and_last_label_num (FIRST_LABELNO (head), LAST_LABELNO (head));
2803 /* We must have already output DWARF debugging information for the
2804 original (abstract) inline function declaration/definition, so
2805 we want to make sure that the debugging information we generate
2806 for this special instance of the inline function refers back to
2807 the information we already generated. To make sure that happens,
2808 we simply have to set the DECL_ABSTRACT_ORIGIN for the function
2809 node (and for all of the local ..._DECL nodes which are its children)
2810 so that they all point to themselves. */
2812 set_decl_origin_self (fndecl);
2814 /* Compile this function all the way down to assembly code. */
2815 rest_of_compilation (fndecl);
2817 current_function_decl = 0;
2819 permanent_allocation ();