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
39 extern int xmalloc ();
42 extern struct obstack *function_maybepermanent_obstack;
44 extern tree pushdecl ();
45 extern tree poplevel ();
47 /* Similar, but round to the next highest integer that meets the
49 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
51 /* Default max number of insns a function can have and still be inline.
52 This is overridden on RISC machines. */
53 #ifndef INTEGRATE_THRESHOLD
54 #define INTEGRATE_THRESHOLD(DECL) \
55 (8 * (8 + list_length (DECL_ARGUMENTS (DECL))))
58 /* Save any constant pool constants in an insn. */
59 static void save_constants ();
61 /* Note when parameter registers are the destination of a SET. */
62 static void note_modified_parmregs ();
64 /* Copy an rtx for save_for_inline_copying. */
65 static rtx copy_for_inline ();
67 /* Make copies of MEMs in DECL_RTLs. */
68 static void copy_decl_rtls ();
70 static tree copy_decl_tree ();
72 /* Return the constant equivalent of a given rtx, or 0 if none. */
73 static rtx const_equiv ();
75 static void integrate_parm_decls ();
76 static void integrate_decl_tree ();
78 static void subst_constants ();
79 static rtx fold_out_const_cc0 ();
81 /* Zero if the current function (whose FUNCTION_DECL is FNDECL)
82 is safe and reasonable to integrate into other functions.
83 Nonzero means value is a warning message with a single %s
84 for the function's name. */
87 function_cannot_inline_p (fndecl)
91 tree last = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
92 int max_insns = INTEGRATE_THRESHOLD (fndecl);
93 register int ninsns = 0;
96 /* No inlines with varargs. `grokdeclarator' gives a warning
97 message about that if `inline' is specified. This code
98 it put in to catch the volunteers. */
99 if ((last && TREE_VALUE (last) != void_type_node)
100 || (DECL_ARGUMENTS (fndecl) && DECL_NAME (DECL_ARGUMENTS (fndecl))
101 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (DECL_ARGUMENTS (fndecl))),
102 "__builtin_va_alist")))
103 return "varargs function cannot be inline";
105 if (current_function_calls_alloca)
106 return "function using alloca cannot be inline";
108 if (current_function_contains_functions)
109 return "function with nested functions cannot be inline";
111 /* This restriction may be eliminated sometime soon. But for now, don't
112 worry about remapping the static chain. */
113 if (current_function_needs_context)
114 return "nested function cannot be inline";
116 /* If its not even close, don't even look. */
117 if (!TREE_INLINE (fndecl) && get_max_uid () > 3 * max_insns)
118 return "function too large to be inline";
121 /* Large stacks are OK now that inlined functions can share them. */
122 /* Don't inline functions with large stack usage,
123 since they can make other recursive functions burn up stack. */
124 if (!TREE_INLINE (fndecl) && get_frame_size () > 100)
125 return "function stack frame for inlining";
129 /* Don't inline functions which do not specify a function prototype and
130 have BLKmode argument or take the address of a parameter. */
131 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
133 if (TYPE_MODE (TREE_TYPE (parms)) == BLKmode)
134 TREE_ADDRESSABLE (parms) = 1;
135 if (last == NULL_TREE && TREE_ADDRESSABLE (parms))
136 return "no prototype, and parameter address used; cannot be inline";
140 /* We can't inline functions that return structures
141 the old-fashioned PCC way, copying into a static block. */
142 if (current_function_returns_pcc_struct)
143 return "inline functions not supported for this return value type";
145 /* We can't inline functions that return structures of varying size. */
146 if (int_size_in_bytes (TREE_TYPE (TREE_TYPE (fndecl))) < 0)
147 return "function with varying-size return value cannot be inline";
149 /* Cannot inline a function with a varying size argument. */
150 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
151 if (int_size_in_bytes (TREE_TYPE (parms)) < 0)
152 return "function with varying-size parameter cannot be inline";
154 if (!TREE_INLINE (fndecl) && get_max_uid () > max_insns)
156 for (ninsns = 0, insn = get_first_nonparm_insn (); insn && ninsns < max_insns;
157 insn = NEXT_INSN (insn))
159 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
163 if (ninsns >= max_insns)
164 return "function too large to be inline";
170 /* Variables used within save_for_inline. */
172 /* Mapping from old pseudo-register to new pseudo-registers.
173 The first element of this map is reg_map[FIRST_PSEUDO_REGISTER].
174 It is allocated in `save_for_inline' and `expand_inline_function',
175 and deallocated on exit from each of those routines. */
178 /* Mapping from old code-labels to new code-labels.
179 The first element of this map is label_map[min_labelno].
180 It is allocated in `save_for_inline' and `expand_inline_function',
181 and deallocated on exit from each of those routines. */
182 static rtx *label_map;
184 /* Mapping from old insn uid's to copied insns.
185 It is allocated in `save_for_inline' and `expand_inline_function',
186 and deallocated on exit from each of those routines. */
187 static rtx *insn_map;
189 /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
190 Zero for a reg that isn't a parm's home.
191 Only reg numbers less than max_parm_reg are mapped here. */
192 static tree *parmdecl_map;
194 /* Keep track of first pseudo-register beyond those that are parms. */
195 static int max_parm_reg;
197 /* When an insn is being copied by copy_for_inline,
198 this is nonzero if we have copied an ASM_OPERANDS.
199 In that case, it is the original input-operand vector. */
200 static rtvec orig_asm_operands_vector;
202 /* When an insn is being copied by copy_for_inline,
203 this is nonzero if we have copied an ASM_OPERANDS.
204 In that case, it is the copied input-operand vector. */
205 static rtvec copy_asm_operands_vector;
207 /* Likewise, this is the copied constraints vector. */
208 static rtvec copy_asm_constraints_vector;
210 /* In save_for_inline, nonzero if past the parm-initialization insns. */
211 static int in_nonparm_insns;
213 /* Subroutine for `save_for_inline{copying,nocopy}'. Performs initialization
214 needed to save FNDECL's insns and info for future inline expansion. */
217 initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, copy)
224 int function_flags, i;
228 /* Compute the values of any flags we must restore when inlining this. */
231 = (current_function_calls_alloca * FUNCTION_FLAGS_CALLS_ALLOCA
232 + current_function_calls_setjmp * FUNCTION_FLAGS_CALLS_SETJMP
233 + current_function_calls_longjmp * FUNCTION_FLAGS_CALLS_LONGJMP
234 + current_function_returns_struct * FUNCTION_FLAGS_RETURNS_STRUCT
235 + current_function_returns_pcc_struct * FUNCTION_FLAGS_RETURNS_PCC_STRUCT
236 + current_function_needs_context * FUNCTION_FLAGS_NEEDS_CONTEXT
237 + current_function_has_nonlocal_label * FUNCTION_FLAGS_HAS_NONLOCAL_LABEL
238 + current_function_returns_pointer * FUNCTION_FLAGS_RETURNS_POINTER
239 + current_function_uses_const_pool * FUNCTION_FLAGS_USES_CONST_POOL
240 + current_function_uses_pic_offset_table * FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE);
242 /* Clear out PARMDECL_MAP. It was allocated in the caller's frame. */
243 bzero (parmdecl_map, max_parm_reg * sizeof (tree));
244 arg_vector = rtvec_alloc (list_length (DECL_ARGUMENTS (fndecl)));
246 for (parms = DECL_ARGUMENTS (fndecl), i = 0;
248 parms = TREE_CHAIN (parms), i++)
250 rtx p = DECL_RTL (parms);
252 if (GET_CODE (p) == MEM && copy)
253 /* Copy the rtl so that modifications of the address
254 later in compilation won't affect this arg_vector.
255 Virtual register instantiation can screw the address
257 DECL_RTL (parms) = copy_rtx (p);
259 RTVEC_ELT (arg_vector, i) = p;
261 if (GET_CODE (p) == REG)
262 parmdecl_map[REGNO (p)] = parms;
263 TREE_READONLY (parms) = 1;
266 /* Assume we start out in the insns that set up the parameters. */
267 in_nonparm_insns = 0;
269 /* The list of DECL_SAVED_INSNS, starts off with a header which
270 contains the following information:
272 the first insn of the function (not including the insns that copy
273 parameters into registers).
274 the first parameter insn of the function,
275 the first label used by that function,
276 the last label used by that function,
277 the highest register number used for parameters,
278 the total number of registers used,
279 the size of the incoming stack area for parameters,
280 the number of bytes popped on return,
282 some flags that are used to restore compiler globals,
283 the value of current_function_outgoing_args_size,
284 the original argument vector,
285 and the original DECL_INITIAL. */
287 return gen_inline_header_rtx (NULL, NULL, min_labelno, max_labelno,
288 max_parm_reg, max_reg,
289 current_function_args_size,
290 current_function_pops_args,
291 stack_slot_list, function_flags,
292 current_function_outgoing_args_size,
293 arg_vector, (rtx) DECL_INITIAL (fndecl));
296 /* Subroutine for `save_for_inline{copying,nocopy}'. Finishes up the
297 things that must be done to make FNDECL expandable as an inline function.
298 HEAD contains the chain of insns to which FNDECL will expand. */
301 finish_inline (fndecl, head)
305 NEXT_INSN (head) = get_first_nonparm_insn ();
306 FIRST_PARM_INSN (head) = get_insns ();
307 DECL_SAVED_INSNS (fndecl) = head;
308 DECL_FRAME_SIZE (fndecl) = get_frame_size ();
309 TREE_INLINE (fndecl) = 1;
312 /* Make the insns and PARM_DECLs of the current function permanent
313 and record other information in DECL_SAVED_INSNS to allow inlining
314 of this function in subsequent calls.
316 This function is called when we are going to immediately compile
317 the insns for FNDECL. The insns in maybepermanent_obstack cannot be
318 modified by the compilation process, so we copy all of them to
319 new storage and consider the new insns to be the insn chain to be
323 save_for_inline_copying (fndecl)
326 rtx first_insn, last_insn, insn;
328 int max_labelno, min_labelno, i, len;
331 rtx first_nonparm_insn;
333 /* Make and emit a return-label if we have not already done so.
334 Do this before recording the bounds on label numbers. */
336 if (return_label == 0)
338 return_label = gen_label_rtx ();
339 emit_label (return_label);
342 /* Get some bounds on the labels and registers used. */
344 max_labelno = max_label_num ();
345 min_labelno = get_first_label_num ();
346 max_reg = max_reg_num ();
348 /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
349 Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
350 Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
351 for the parms, prior to elimination of virtual registers.
352 These values are needed for substituting parms properly. */
354 max_parm_reg = max_parm_reg_num ();
355 parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
357 head = initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, 1);
359 if (current_function_uses_const_pool)
361 /* Replace any constant pool references with the actual constant. We
362 will put the constants back in the copy made below. */
363 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
364 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
366 save_constants (&PATTERN (insn));
367 if (REG_NOTES (insn))
368 save_constants (®_NOTES (insn));
371 /* Clear out the constant pool so that we can recreate it with the
372 copied constants below. */
373 init_const_rtx_hash_table ();
374 clear_const_double_mem ();
377 max_uid = INSN_UID (head);
379 /* We have now allocated all that needs to be allocated permanently
380 on the rtx obstack. Set our high-water mark, so that we
381 can free the rest of this when the time comes. */
385 /* Copy the chain insns of this function.
386 Install the copied chain as the insns of this function,
387 for continued compilation;
388 the original chain is recorded as the DECL_SAVED_INSNS
389 for inlining future calls. */
391 /* If there are insns that copy parms from the stack into pseudo registers,
392 those insns are not copied. `expand_inline_function' must
393 emit the correct code to handle such things. */
396 if (GET_CODE (insn) != NOTE)
398 first_insn = rtx_alloc (NOTE);
399 NOTE_SOURCE_FILE (first_insn) = NOTE_SOURCE_FILE (insn);
400 NOTE_LINE_NUMBER (first_insn) = NOTE_LINE_NUMBER (insn);
401 INSN_UID (first_insn) = INSN_UID (insn);
402 PREV_INSN (first_insn) = NULL;
403 NEXT_INSN (first_insn) = NULL;
404 last_insn = first_insn;
406 /* Each pseudo-reg in the old insn chain must have a unique rtx in the copy.
407 Make these new rtx's now, and install them in regno_reg_rtx, so they
408 will be the official pseudo-reg rtx's for the rest of compilation. */
410 reg_map = (rtx *) alloca ((max_reg + 1) * sizeof (rtx));
412 len = sizeof (struct rtx_def) + (GET_RTX_LENGTH (REG) - 1) * sizeof (rtunion);
413 for (i = max_reg - 1; i > LAST_VIRTUAL_REGISTER; i--)
414 reg_map[i] = (rtx)obstack_copy (function_maybepermanent_obstack,
415 regno_reg_rtx[i], len);
417 bcopy (reg_map + LAST_VIRTUAL_REGISTER + 1,
418 regno_reg_rtx + LAST_VIRTUAL_REGISTER + 1,
419 (max_reg - (LAST_VIRTUAL_REGISTER + 1)) * sizeof (rtx));
421 /* Likewise each label rtx must have a unique rtx as its copy. */
423 label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
424 label_map -= min_labelno;
426 for (i = min_labelno; i < max_labelno; i++)
427 label_map[i] = gen_label_rtx ();
429 /* Record the mapping of old insns to copied insns. */
431 insn_map = (rtx *) alloca (max_uid * sizeof (rtx));
432 bzero (insn_map, max_uid * sizeof (rtx));
434 /* Get the insn which signals the end of parameter setup code. */
435 first_nonparm_insn = get_first_nonparm_insn ();
437 /* Copy any entries in regno_reg_rtx or DECL_RTLs that reference MEM
438 (the former occurs when a variable has its address taken)
439 since these may be shared and can be changed by virtual
440 register instantiation. DECL_RTL values for our arguments
441 have already been copied by initialize_for_inline. */
442 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_reg; i++)
443 if (GET_CODE (regno_reg_rtx[i]) == MEM)
444 XEXP (regno_reg_rtx[i], 0)
445 = copy_for_inline (XEXP (regno_reg_rtx[i], 0));
447 /* Copy the tree of subblocks of the function, and the decls in them.
448 We will use the copy for compiling this function, then restore the original
449 subblocks and decls for use when inlining this function.
451 Several parts of the compiler modify BLOCK trees. In particular,
452 instantiate_virtual_regs will instantiate any virtual regs
453 mentioned in the DECL_RTLs of the decls, and loop
454 unrolling will replicate any BLOCK trees inside an unrolled loop.
456 The modified subblocks or DECL_RTLs would be incorrect for the original rtl
457 which we will use for inlining. The rtl might even contain pseudoregs
458 whose space has been freed. */
460 DECL_INITIAL (fndecl) = copy_decl_tree (DECL_INITIAL (fndecl));
462 /* Now copy each DECL_RTL which is a MEM,
463 so it is safe to modify their addresses. */
464 copy_decl_rtls (DECL_INITIAL (fndecl));
466 /* Now copy the chain of insns. Do this twice. The first copy the insn
467 itself and its body. The second time copy of REG_NOTES. This is because
468 a REG_NOTE may have a forward pointer to another insn. */
470 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
472 orig_asm_operands_vector = 0;
474 if (insn == first_nonparm_insn)
475 in_nonparm_insns = 1;
477 switch (GET_CODE (insn))
480 /* No need to keep these. */
481 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
484 copy = rtx_alloc (NOTE);
485 NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
486 NOTE_LINE_NUMBER (copy) = NOTE_LINE_NUMBER (insn);
492 copy = rtx_alloc (GET_CODE (insn));
493 PATTERN (copy) = copy_for_inline (PATTERN (insn));
494 INSN_CODE (copy) = -1;
495 LOG_LINKS (copy) = NULL;
496 RTX_INTEGRATED_P (copy) = RTX_INTEGRATED_P (insn);
500 copy = label_map[CODE_LABEL_NUMBER (insn)];
504 copy = rtx_alloc (BARRIER);
510 INSN_UID (copy) = INSN_UID (insn);
511 insn_map[INSN_UID (insn)] = copy;
512 NEXT_INSN (last_insn) = copy;
513 PREV_INSN (copy) = last_insn;
517 /* Now copy the REG_NOTES. */
518 for (insn = NEXT_INSN (get_insns ()); insn; insn = NEXT_INSN (insn))
519 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
520 && insn_map[INSN_UID(insn)])
521 REG_NOTES (insn_map[INSN_UID (insn)])
522 = copy_for_inline (REG_NOTES (insn));
524 NEXT_INSN (last_insn) = NULL;
526 finish_inline (fndecl, head);
528 set_new_first_and_last_insn (first_insn, last_insn);
531 /* Make a copy of the entire tree of blocks BLOCK, and return it. */
534 copy_decl_tree (block)
537 tree t, vars, subblocks;
539 vars = copy_list (BLOCK_VARS (block));
542 /* Process all subblocks. */
543 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
545 tree copy = copy_decl_tree (t);
546 TREE_CHAIN (copy) = subblocks;
550 t = copy_node (block);
551 BLOCK_VARS (t) = vars;
552 BLOCK_SUBBLOCKS (t) = nreverse (subblocks);
556 /* Copy DECL_RTLs in all decls in the given BLOCK node. */
559 copy_decl_rtls (block)
564 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
565 if (DECL_RTL (t) && GET_CODE (DECL_RTL (t)) == MEM)
566 DECL_RTL (t) = copy_for_inline (DECL_RTL (t));
568 /* Process all subblocks. */
569 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
573 /* Make the insns and PARM_DECLs of the current function permanent
574 and record other information in DECL_SAVED_INSNS to allow inlining
575 of this function in subsequent calls.
577 This routine need not copy any insns because we are not going
578 to immediately compile the insns in the insn chain. There
579 are two cases when we would compile the insns for FNDECL:
580 (1) when FNDECL is expanded inline, and (2) when FNDECL needs to
581 be output at the end of other compilation, because somebody took
582 its address. In the first case, the insns of FNDECL are copied
583 as it is expanded inline, so FNDECL's saved insns are not
584 modified. In the second case, FNDECL is used for the last time,
585 so modifying the rtl is not a problem.
587 ??? Actually, we do not verify that FNDECL is not inline expanded
588 by other functions which must also be written down at the end
589 of compilation. We could set flag_no_inline to nonzero when
590 the time comes to write down such functions. */
593 save_for_inline_nocopy (fndecl)
599 int max_labelno, min_labelno, i, len;
602 rtx first_nonparm_insn;
605 /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
606 Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
607 Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
608 for the parms, prior to elimination of virtual registers.
609 These values are needed for substituting parms properly. */
611 max_parm_reg = max_parm_reg_num ();
612 parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
614 /* Make and emit a return-label if we have not already done so. */
616 if (return_label == 0)
618 return_label = gen_label_rtx ();
619 emit_label (return_label);
622 head = initialize_for_inline (fndecl, get_first_label_num (),
623 max_label_num (), max_reg_num (), 0);
625 /* If there are insns that copy parms from the stack into pseudo registers,
626 those insns are not copied. `expand_inline_function' must
627 emit the correct code to handle such things. */
630 if (GET_CODE (insn) != NOTE)
633 /* Get the insn which signals the end of parameter setup code. */
634 first_nonparm_insn = get_first_nonparm_insn ();
636 /* Now just scan the chain of insns to see what happens to our
637 PARM_DECLs. If a PARM_DECL is used but never modified, we
638 can substitute its rtl directly when expanding inline (and
639 perform constant folding when its incoming value is constant).
640 Otherwise, we have to copy its value into a new register and track
641 the new register's life. */
643 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
645 if (insn == first_nonparm_insn)
646 in_nonparm_insns = 1;
648 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
650 if (current_function_uses_const_pool)
652 /* Replace any constant pool references with the actual constant.
653 We will put the constant back if we need to write the
654 function out after all. */
655 save_constants (&PATTERN (insn));
656 if (REG_NOTES (insn))
657 save_constants (®_NOTES (insn));
660 /* Record what interesting things happen to our parameters. */
661 note_stores (PATTERN (insn), note_modified_parmregs);
665 /* We have now allocated all that needs to be allocated permanently
666 on the rtx obstack. Set our high-water mark, so that we
667 can free the rest of this when the time comes. */
671 finish_inline (fndecl, head);
674 /* Given PX, a pointer into an insn, search for references to the constant
675 pool. Replace each with a CONST that has the mode of the original
676 constant, contains the constant, and has RTX_INTEGRATED_P set.
677 Similarly, constant pool addresses not enclosed in a MEM are replaced
678 with an ADDRESS rtx which also gives the constant, mode, and has
679 RTX_INTEGRATED_P set. */
691 /* If this is a CONST_DOUBLE, don't try to fix things up in
692 CONST_DOUBLE_MEM, because this is an infinite recursion. */
693 if (GET_CODE (x) == CONST_DOUBLE)
695 else if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
696 && CONSTANT_POOL_ADDRESS_P (XEXP (x,0)))
698 enum machine_mode const_mode = get_pool_mode (XEXP (x, 0));
699 rtx new = gen_rtx (CONST, const_mode, get_pool_constant (XEXP (x, 0)));
700 RTX_INTEGRATED_P (new) = 1;
702 /* If the MEM was in a different mode than the constant (perhaps we
703 were only looking at the low-order part), surround it with a
704 SUBREG so we can save both modes. */
706 if (GET_MODE (x) != const_mode)
708 new = gen_rtx (SUBREG, GET_MODE (x), new, 0);
709 RTX_INTEGRATED_P (new) = 1;
713 save_constants (&XEXP (*px, 0));
715 else if (GET_CODE (x) == SYMBOL_REF
716 && CONSTANT_POOL_ADDRESS_P (x))
718 *px = gen_rtx (ADDRESS, get_pool_mode (x), get_pool_constant (x));
719 save_constants (&XEXP (*px, 0));
720 RTX_INTEGRATED_P (*px) = 1;
725 char *fmt = GET_RTX_FORMAT (GET_CODE (x));
726 int len = GET_RTX_LENGTH (GET_CODE (x));
728 for (i = len-1; i >= 0; i--)
733 for (j = 0; j < XVECLEN (x, i); j++)
734 save_constants (&XVECEXP (x, i, j));
738 if (XEXP (x, i) == 0)
742 /* Hack tail-recursion here. */
746 save_constants (&XEXP (x, i));
753 /* Note whether a parameter is modified or not. */
756 note_modified_parmregs (reg, x)
760 if (GET_CODE (reg) == REG && in_nonparm_insns
761 && REGNO (reg) < max_parm_reg
762 && REGNO (reg) >= FIRST_PSEUDO_REGISTER
763 && parmdecl_map[REGNO (reg)] != 0)
764 TREE_READONLY (parmdecl_map[REGNO (reg)]) = 0;
767 /* Copy the rtx ORIG recursively, replacing pseudo-regs and labels
768 according to `reg_map' and `label_map'. The original rtl insns
769 will be saved for inlining; this is used to make a copy
770 which is used to finish compiling the inline function itself.
772 If we find a "saved" constant pool entry, one which was replaced with
773 the value of the constant, convert it back to a constant pool entry.
774 Since the pool wasn't touched, this should simply restore the old
777 All other kinds of rtx are copied except those that can never be
778 changed during compilation. */
781 copy_for_inline (orig)
784 register rtx x = orig;
786 register enum rtx_code code;
787 register char *format_ptr;
794 /* These types may be freely shared. */
806 /* We have to make a new CONST_DOUBLE to ensure that we account for
807 it correctly. Using the old CONST_DOUBLE_MEM data is wrong. */
808 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
812 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
813 return immed_real_const_1 (d, GET_MODE (x));
816 return immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
820 /* Get constant pool entry for constant in the pool. */
821 if (RTX_INTEGRATED_P (x))
822 return validize_mem (force_const_mem (GET_MODE (x),
823 copy_for_inline (XEXP (x, 0))));
827 /* Get constant pool entry, but access in different mode. */
828 if (RTX_INTEGRATED_P (x))
831 = force_const_mem (GET_MODE (SUBREG_REG (x)),
832 copy_for_inline (XEXP (SUBREG_REG (x), 0)));
834 PUT_MODE (new, GET_MODE (x));
835 return validize_mem (new);
840 /* If not special for constant pool error. Else get constant pool
842 if (! RTX_INTEGRATED_P (x))
845 return XEXP (force_const_mem (GET_MODE (x),
846 copy_for_inline (XEXP (x, 0))), 0);
849 /* If a single asm insn contains multiple output operands
850 then it contains multiple ASM_OPERANDS rtx's that share operand 3.
851 We must make sure that the copied insn continues to share it. */
852 if (orig_asm_operands_vector == XVEC (orig, 3))
854 x = rtx_alloc (ASM_OPERANDS);
855 XSTR (x, 0) = XSTR (orig, 0);
856 XSTR (x, 1) = XSTR (orig, 1);
857 XINT (x, 2) = XINT (orig, 2);
858 XVEC (x, 3) = copy_asm_operands_vector;
859 XVEC (x, 4) = copy_asm_constraints_vector;
860 XSTR (x, 5) = XSTR (orig, 5);
861 XINT (x, 6) = XINT (orig, 6);
867 /* A MEM is usually allowed to be shared if its address is constant
868 or is a constant plus one of the special registers.
870 We do not allow sharing of addresses that are either a special
871 register or the sum of a constant and a special register because
872 it is possible for unshare_all_rtl to copy the address, into memory
873 that won't be saved. Although the MEM can safely be shared, and
874 won't be copied there, the address itself cannot be shared, and may
877 There are also two exceptions with constants: The first is if the
878 constant is a LABEL_REF or the sum of the LABEL_REF
879 and an integer. This case can happen if we have an inline
880 function that supplies a constant operand to the call of another
881 inline function that uses it in a switch statement. In this case,
882 we will be replacing the LABEL_REF, so we have to replace this MEM
885 The second case is if we have a (const (plus (address ..) ...)).
886 In that case we need to put back the address of the constant pool
889 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
890 && GET_CODE (XEXP (x, 0)) != LABEL_REF
891 && ! (GET_CODE (XEXP (x, 0)) == CONST
892 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS
893 && ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
895 || (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
902 /* Must point to the new insn. */
903 return gen_rtx (LABEL_REF, GET_MODE (orig),
904 label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))]);
908 if (REGNO (x) > LAST_VIRTUAL_REGISTER)
909 return reg_map [REGNO (x)];
914 /* If a parm that gets modified lives in a pseudo-reg,
915 clear its TREE_READONLY to prevent certain optimizations. */
917 rtx dest = SET_DEST (x);
919 while (GET_CODE (dest) == STRICT_LOW_PART
920 || GET_CODE (dest) == ZERO_EXTRACT
921 || GET_CODE (dest) == SUBREG)
922 dest = XEXP (dest, 0);
924 if (GET_CODE (dest) == REG
925 && REGNO (dest) < max_parm_reg
926 && REGNO (dest) >= FIRST_PSEUDO_REGISTER
927 && parmdecl_map[REGNO (dest)] != 0
928 /* The insn to load an arg pseudo from a stack slot
929 does not count as modifying it. */
931 TREE_READONLY (parmdecl_map[REGNO (dest)]) = 0;
935 #if 0 /* This is a good idea, but here is the wrong place for it. */
936 /* Arrange that CONST_INTs always appear as the second operand
937 if they appear, and that `frame_pointer_rtx' or `arg_pointer_rtx'
938 always appear as the first. */
940 if (GET_CODE (XEXP (x, 0)) == CONST_INT
941 || (XEXP (x, 1) == frame_pointer_rtx
942 || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
943 && XEXP (x, 1) == arg_pointer_rtx)))
946 XEXP (x, 0) = XEXP (x, 1);
953 /* Replace this rtx with a copy of itself. */
955 x = rtx_alloc (code);
956 bcopy (orig, x, (sizeof (*x) - sizeof (x->fld)
957 + sizeof (x->fld[0]) * GET_RTX_LENGTH (code)));
959 /* Now scan the subexpressions recursively.
960 We can store any replaced subexpressions directly into X
961 since we know X is not shared! Any vectors in X
962 must be copied if X was copied. */
964 format_ptr = GET_RTX_FORMAT (code);
966 for (i = 0; i < GET_RTX_LENGTH (code); i++)
968 switch (*format_ptr++)
971 XEXP (x, i) = copy_for_inline (XEXP (x, i));
975 /* Change any references to old-insns to point to the
976 corresponding copied insns. */
977 XEXP (x, i) = insn_map[INSN_UID (XEXP (x, i))];
981 if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
985 XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
986 for (j = 0; j < XVECLEN (x, i); j++)
988 = copy_for_inline (XVECEXP (x, i, j));
994 if (code == ASM_OPERANDS && orig_asm_operands_vector == 0)
996 orig_asm_operands_vector = XVEC (orig, 3);
997 copy_asm_operands_vector = XVEC (x, 3);
998 copy_asm_constraints_vector = XVEC (x, 4);
1004 /* Unfortunately, we need a global copy of const_equiv map for communication
1005 with a function called from note_stores. Be *very* careful that this
1006 is used properly in the presence of recursion. */
1008 rtx *global_const_equiv_map;
1010 #define FIXED_BASE_PLUS_P(X) \
1011 (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
1012 && GET_CODE (XEXP (X, 0)) == REG \
1013 && REGNO (XEXP (X, 0)) >= FIRST_VIRTUAL_REGISTER \
1014 && REGNO (XEXP (X, 0)) < LAST_VIRTUAL_REGISTER)
1016 /* Integrate the procedure defined by FNDECL. Note that this function
1017 may wind up calling itself. Since the static variables are not
1018 reentrant, we do not assign them until after the possibility
1019 or recursion is eliminated.
1021 If IGNORE is nonzero, do not produce a value.
1022 Otherwise store the value in TARGET if it is nonzero and that is convenient.
1025 (rtx)-1 if we could not substitute the function
1026 0 if we substituted it and it does not produce a value
1027 else an rtx for where the value is stored. */
1030 expand_inline_function (fndecl, parms, target, ignore, type, structure_value_addr)
1035 rtx structure_value_addr;
1037 tree formal, actual;
1038 rtx header = DECL_SAVED_INSNS (fndecl);
1039 rtx insns = FIRST_FUNCTION_INSN (header);
1040 rtx parm_insns = FIRST_PARM_INSN (header);
1047 int min_labelno = FIRST_LABELNO (header);
1048 int max_labelno = LAST_LABELNO (header);
1050 rtx local_return_label = 0;
1053 struct inline_remap *map;
1055 rtvec arg_vector = ORIGINAL_ARG_VECTOR (header);
1057 /* Allow for equivalences of the pseudos we make for virtual fp and ap. */
1058 max_regno = MAX_REGNUM (header) + 3;
1059 if (max_regno < FIRST_PSEUDO_REGISTER)
1062 nargs = list_length (DECL_ARGUMENTS (fndecl));
1064 /* We expect PARMS to have the right length; don't crash if not. */
1065 if (list_length (parms) != nargs)
1067 /* Also check that the parms type match. Since the appropriate
1068 conversions or default promotions have already been applied,
1069 the machine modes should match exactly. */
1070 for (formal = DECL_ARGUMENTS (fndecl),
1073 formal = TREE_CHAIN (formal),
1074 actual = TREE_CHAIN (actual))
1076 tree arg = TREE_VALUE (actual);
1077 enum machine_mode mode = TYPE_MODE (DECL_ARG_TYPE (formal));
1078 if (mode != TYPE_MODE (TREE_TYPE (arg)))
1080 /* If they are block mode, the types should match exactly.
1081 They don't match exactly if TREE_TYPE (FORMAL) == ERROR_MARK_NODE,
1082 which could happen if the parameter has incomplete type. */
1083 if (mode == BLKmode && TREE_TYPE (arg) != TREE_TYPE (formal))
1087 /* Make a binding contour to keep inline cleanups called at
1088 outer function-scope level from looking like they are shadowing
1089 parameter declarations. */
1092 /* Make a fresh binding contour that we can easily remove. */
1094 expand_start_bindings (0);
1095 if (GET_CODE (parm_insns) == NOTE
1096 && NOTE_LINE_NUMBER (parm_insns) > 0)
1097 emit_note (NOTE_SOURCE_FILE (parm_insns), NOTE_LINE_NUMBER (parm_insns));
1099 /* Expand the function arguments. Do this first so that any
1100 new registers get created before we allocate the maps. */
1102 arg_vals = (rtx *) alloca (nargs * sizeof (rtx));
1103 arg_trees = (tree *) alloca (nargs * sizeof (tree));
1105 for (formal = DECL_ARGUMENTS (fndecl), actual = parms, i = 0;
1107 formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual), i++)
1109 /* Actual parameter, converted to the type of the argument within the
1111 tree arg = convert (TREE_TYPE (formal), TREE_VALUE (actual));
1112 /* Mode of the variable used within the function. */
1113 enum machine_mode mode = TYPE_MODE (TREE_TYPE (formal));
1114 /* Where parameter is located in the function. */
1117 emit_note (DECL_SOURCE_FILE (formal), DECL_SOURCE_LINE (formal));
1120 loc = RTVEC_ELT (arg_vector, i);
1122 /* If this is an object passed by invisible reference, we copy the
1123 object into a stack slot and save its address. If this will go
1124 into memory, we do nothing now. Otherwise, we just expand the
1126 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1127 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1129 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
1130 rtx stack_slot = assign_stack_temp (mode, int_size_in_bytes (TREE_TYPE (arg)), 1);
1132 store_expr (arg, stack_slot, 0);
1134 arg_vals[i] = XEXP (stack_slot, 0);
1136 else if (GET_CODE (loc) != MEM)
1137 arg_vals[i] = expand_expr (arg, 0, mode, EXPAND_SUM);
1141 if (arg_vals[i] != 0
1142 && (! TREE_READONLY (formal)
1143 /* If the parameter is not read-only, copy our argument through
1144 a register. Also, we cannot use ARG_VALS[I] if it overlaps
1145 TARGET in any way. In the inline function, they will likely
1146 be two different pseudos, and `safe_from_p' will make all
1147 sorts of smart assumptions about their not conflicting.
1148 But if ARG_VALS[I] overlaps TARGET, these assumptions are
1149 wrong, so put ARG_VALS[I] into a fresh register. */
1151 && (GET_CODE (arg_vals[i]) == REG
1152 || GET_CODE (arg_vals[i]) == SUBREG
1153 || GET_CODE (arg_vals[i]) == MEM)
1154 && reg_overlap_mentioned_p (arg_vals[i], target))))
1155 arg_vals[i] = copy_to_mode_reg (mode, arg_vals[i]);
1158 /* Allocate the structures we use to remap things. */
1160 map = (struct inline_remap *) alloca (sizeof (struct inline_remap));
1161 map->fndecl = fndecl;
1163 map->reg_map = (rtx *) alloca (max_regno * sizeof (rtx));
1164 bzero (map->reg_map, max_regno * sizeof (rtx));
1166 map->label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
1167 map->label_map -= min_labelno;
1169 map->insn_map = (rtx *) alloca (INSN_UID (header) * sizeof (rtx));
1170 bzero (map->insn_map, INSN_UID (header) * sizeof (rtx));
1171 map->min_insnno = 0;
1172 map->max_insnno = INSN_UID (header);
1174 /* const_equiv_map maps pseudos in our routine to constants, so it needs to
1175 be large enough for all our pseudos. This is the number we are currently
1176 using plus the number in the called routine, plus one for each arg and
1177 one for the return value. */
1179 = max_reg_num () + (max_regno - FIRST_PSEUDO_REGISTER) + nargs + 1;
1181 map->const_equiv_map = (rtx *)alloca (equiv_map_size * sizeof (rtx));
1182 bzero (map->const_equiv_map, equiv_map_size * sizeof (rtx));
1184 map->const_age_map = (unsigned *)alloca (equiv_map_size * sizeof (unsigned));
1185 bzero (map->const_age_map, equiv_map_size * sizeof (unsigned));
1188 /* Record the current insn in case we have to set up pointers to frame
1189 and argument memory blocks. */
1190 map->insns_at_start = get_last_insn ();
1192 /* Update the outgoing argument size to allow for those in the inlined
1194 if (OUTGOING_ARGS_SIZE (header) > current_function_outgoing_args_size)
1195 current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (header);
1197 /* If the inline function needs to make PIC references, that means
1198 that this function's PIC offset table must be used. */
1199 if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE)
1200 current_function_uses_pic_offset_table = 1;
1202 /* Process each argument. For each, set up things so that the function's
1203 reference to the argument will refer to the argument being passed.
1204 We only replace REG with REG here. Any simplifications are done
1205 via const_equiv_map.
1207 We make two passes: In the first, we deal with parameters that will
1208 be placed into registers, since we need to ensure that the allocated
1209 register number fits in const_equiv_map. Then we store all non-register
1210 parameters into their memory location. */
1212 for (i = 0; i < nargs; i++)
1214 rtx copy = arg_vals[i];
1216 loc = RTVEC_ELT (arg_vector, i);
1218 /* There are three cases, each handled separately. */
1219 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1220 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1222 /* This must be an object passed by invisible reference (it could
1223 also be a variable-sized object, but we forbid inlining functions
1224 with variable-sized arguments). COPY is the address of the
1225 actual value (this computation will cause it to be copied). We
1226 map that address for the register, noting the actual address as
1227 an equivalent in case it can be substituted into the insns. */
1229 if (GET_CODE (copy) != REG)
1231 temp = copy_addr_to_reg (copy);
1232 if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1234 map->const_equiv_map[REGNO (temp)] = copy;
1235 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1239 map->reg_map[REGNO (XEXP (loc, 0))] = copy;
1241 else if (GET_CODE (loc) == MEM)
1243 /* This is the case of a parameter that lives in memory.
1244 It will live in the block we allocate in the called routine's
1245 frame that simulates the incoming argument area. Do nothing
1246 now; we will call store_expr later. */
1249 else if (GET_CODE (loc) == REG)
1251 /* This is the good case where the parameter is in a register.
1252 If it is read-only and our argument is a constant, set up the
1253 constant equivalence. */
1254 if (GET_CODE (copy) != REG && GET_CODE (copy) != SUBREG)
1256 temp = copy_to_mode_reg (GET_MODE (loc), copy);
1257 if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1259 map->const_equiv_map[REGNO (temp)] = copy;
1260 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1264 map->reg_map[REGNO (loc)] = copy;
1269 /* Free any temporaries we made setting up this parameter. */
1273 /* Now do the parameters that will be placed in memory. */
1275 for (formal = DECL_ARGUMENTS (fndecl), i = 0;
1276 formal; formal = TREE_CHAIN (formal), i++)
1278 rtx copy = arg_vals[i];
1280 loc = RTVEC_ELT (arg_vector, i);
1282 if (GET_CODE (loc) == MEM
1283 /* Exclude case handled above. */
1284 && ! (GET_CODE (XEXP (loc, 0)) == REG
1285 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER))
1287 emit_note (DECL_SOURCE_FILE (formal), DECL_SOURCE_LINE (formal));
1289 /* Compute the address in the area we reserved and store the
1291 temp = copy_rtx_and_substitute (loc, map);
1292 subst_constants (&temp, 0, map);
1293 apply_change_group ();
1294 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
1295 temp = change_address (temp, VOIDmode, XEXP (temp, 0));
1296 store_expr (arg_trees[i], temp, 0);
1298 /* Free any temporaries we made setting up this parameter. */
1303 /* Deal with the places that the function puts its result.
1304 We are driven by what is placed into DECL_RESULT.
1306 Initially, we assume that we don't have anything special handling for
1307 REG_FUNCTION_RETURN_VALUE_P. */
1309 map->inline_target = 0;
1310 loc = DECL_RTL (DECL_RESULT (fndecl));
1311 if (TYPE_MODE (type) == VOIDmode)
1312 /* There is no return value to worry about. */
1314 else if (GET_CODE (loc) == MEM)
1316 if (! structure_value_addr || ! aggregate_value_p (DECL_RESULT (fndecl)))
1319 /* Pass the function the address in which to return a structure value.
1320 Note that a constructor can cause someone to call us with
1321 STRUCTURE_VALUE_ADDR, but the initialization takes place
1322 via the first parameter, rather than the struct return address.
1324 We have two cases: If the address is a simple register indirect,
1325 use the mapping mechanism to point that register to our structure
1326 return address. Otherwise, store the structure return value into
1327 the place that it will be referenced from. */
1329 if (GET_CODE (XEXP (loc, 0)) == REG)
1331 temp = force_reg (Pmode, structure_value_addr);
1332 map->reg_map[REGNO (XEXP (loc, 0))] = temp;
1333 if (CONSTANT_P (structure_value_addr)
1334 || (GET_CODE (structure_value_addr) == PLUS
1335 && XEXP (structure_value_addr, 0) == virtual_stack_vars_rtx
1336 && GET_CODE (XEXP (structure_value_addr, 1)) == CONST_INT))
1338 map->const_equiv_map[REGNO (temp)] = structure_value_addr;
1339 map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1344 temp = copy_rtx_and_substitute (loc, map);
1345 subst_constants (&temp, 0, map);
1346 apply_change_group ();
1347 emit_move_insn (temp, structure_value_addr);
1351 /* We will ignore the result value, so don't look at its structure.
1352 Note that preparations for an aggregate return value
1353 do need to be made (above) even if it will be ignored. */
1355 else if (GET_CODE (loc) == REG)
1357 /* The function returns an object in a register and we use the return
1358 value. Set up our target for remapping. */
1360 /* Machine mode function was declared to return. */
1361 enum machine_mode departing_mode = TYPE_MODE (type);
1362 /* (Possibly wider) machine mode it actually computes
1363 (for the sake of callers that fail to declare it right). */
1364 enum machine_mode arriving_mode
1365 = TYPE_MODE (TREE_TYPE (DECL_RESULT (fndecl)));
1368 /* Don't use MEMs as direct targets because on some machines
1369 substituting a MEM for a REG makes invalid insns.
1370 Let the combiner substitute the MEM if that is valid. */
1371 if (target == 0 || GET_CODE (target) != REG
1372 || GET_MODE (target) != departing_mode)
1373 target = gen_reg_rtx (departing_mode);
1375 /* If function's value was promoted before return,
1376 avoid machine mode mismatch when we substitute INLINE_TARGET.
1377 But TARGET is what we will return to the caller. */
1378 if (arriving_mode != departing_mode)
1379 reg_to_map = gen_rtx (SUBREG, arriving_mode, target, 0);
1381 reg_to_map = target;
1383 /* Usually, the result value is the machine's return register.
1384 Sometimes it may be a pseudo. Handle both cases. */
1385 if (REG_FUNCTION_VALUE_P (loc))
1386 map->inline_target = reg_to_map;
1388 map->reg_map[REGNO (loc)] = reg_to_map;
1391 /* Make new label equivalences for the labels in the called function. */
1392 for (i = min_labelno; i < max_labelno; i++)
1393 map->label_map[i] = gen_label_rtx ();
1395 /* Perform postincrements before actually calling the function. */
1398 /* Clean up stack so that variables might have smaller offsets. */
1399 do_pending_stack_adjust ();
1401 /* Save a copy of the location of const_equiv_map for mark_stores, called
1403 global_const_equiv_map = map->const_equiv_map;
1405 /* Now copy the insns one by one. Do this in two passes, first the insns and
1406 then their REG_NOTES, just like save_for_inline. */
1408 /* This loop is very similar to the loop in copy_loop_body in unroll.c. */
1410 for (insn = insns; insn; insn = NEXT_INSN (insn))
1414 map->orig_asm_operands_vector = 0;
1416 switch (GET_CODE (insn))
1419 pattern = PATTERN (insn);
1421 if (GET_CODE (pattern) == USE
1422 && GET_CODE (XEXP (pattern, 0)) == REG
1423 && REG_FUNCTION_VALUE_P (XEXP (pattern, 0)))
1424 /* The (USE (REG n)) at return from the function should
1425 be ignored since we are changing (REG n) into
1429 /* Ignore setting a function value that we don't want to use. */
1430 if (map->inline_target == 0
1431 && GET_CODE (pattern) == SET
1432 && GET_CODE (SET_DEST (pattern)) == REG
1433 && REG_FUNCTION_VALUE_P (SET_DEST (pattern)))
1436 copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1437 /* REG_NOTES will be copied later. */
1440 /* If this insn is setting CC0, it may need to look at
1441 the insn that uses CC0 to see what type of insn it is.
1442 In that case, the call to recog via validate_change will
1443 fail. So don't substitute constants here. Instead,
1444 do it when we emit the following insn.
1446 For example, see the pyr.md file. That machine has signed and
1447 unsigned compares. The compare patterns must check the
1448 following branch insn to see which what kind of compare to
1451 If the previous insn set CC0, substitute constants on it as
1453 if (sets_cc0_p (PATTERN (copy)) != 0)
1458 try_constants (cc0_insn, map);
1460 try_constants (copy, map);
1463 try_constants (copy, map);
1468 if (GET_CODE (PATTERN (insn)) == RETURN)
1470 if (local_return_label == 0)
1471 local_return_label = gen_label_rtx ();
1472 pattern = gen_jump (local_return_label);
1475 pattern = copy_rtx_and_substitute (PATTERN (insn), map);
1477 copy = emit_jump_insn (pattern);
1481 try_constants (cc0_insn, map);
1484 try_constants (copy, map);
1486 /* If this used to be a conditional jump insn but whose branch
1487 direction is now know, we must do something special. */
1488 if (condjump_p (insn) && ! simplejump_p (insn) && map->last_pc_value)
1491 /* The previous insn set cc0 for us. So delete it. */
1492 delete_insn (PREV_INSN (copy));
1495 /* If this is now a no-op, delete it. */
1496 if (map->last_pc_value == pc_rtx)
1502 /* Otherwise, this is unconditional jump so we must put a
1503 BARRIER after it. We could do some dead code elimination
1504 here, but jump.c will do it just as well. */
1510 pattern = copy_rtx_and_substitute (PATTERN (insn), map);
1511 copy = emit_call_insn (pattern);
1515 try_constants (cc0_insn, map);
1518 try_constants (copy, map);
1520 /* Be lazy and assume CALL_INSNs clobber all hard registers. */
1521 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1522 map->const_equiv_map[i] = 0;
1526 copy = emit_label (map->label_map[CODE_LABEL_NUMBER (insn)]);
1531 copy = emit_barrier ();
1535 /* It is important to discard function-end and function-beg notes,
1536 so we have only one of each in the current function.
1537 Also, NOTE_INSN_DELETED notes aren't useful (save_for_inline
1538 deleted these in the copy used for continuing compilation,
1539 not the copy used for inlining). */
1540 if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END
1541 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_BEG
1542 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
1543 copy = emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
1554 RTX_INTEGRATED_P (copy) = 1;
1556 map->insn_map[INSN_UID (insn)] = copy;
1559 /* Now copy the REG_NOTES. */
1560 for (insn = insns; insn; insn = NEXT_INSN (insn))
1561 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
1562 && map->insn_map[INSN_UID (insn)])
1563 REG_NOTES (map->insn_map[INSN_UID (insn)])
1564 = copy_rtx_and_substitute (REG_NOTES (insn), map);
1566 if (local_return_label)
1567 emit_label (local_return_label);
1569 /* Make copies of the decls of the symbols in the inline function, so that
1570 the copies of the variables get declared in the current function. Set
1571 up things so that lookup_static_chain knows that to interpret registers
1572 in SAVE_EXPRs for TYPE_SIZEs as local. */
1574 inline_function_decl = fndecl;
1575 integrate_decl_tree ((tree) ORIGINAL_DECL_INITIAL (header), 0, map, 0);
1576 integrate_parm_decls (DECL_ARGUMENTS (fndecl), map, arg_vector);
1577 inline_function_decl = 0;
1579 /* End the scope containing the copied formal parameter variables. */
1581 expand_end_bindings (getdecls (), 1, 1);
1584 emit_line_note (input_filename, lineno);
1586 if (structure_value_addr)
1587 return gen_rtx (MEM, TYPE_MODE (type),
1588 memory_address (TYPE_MODE (type), structure_value_addr));
1592 /* Given a chain of PARM_DECLs, ARGS, copy each decl into a VAR_DECL,
1593 push all of those decls and give each one the corresponding home. */
1596 integrate_parm_decls (args, map, arg_vector)
1598 struct inline_remap *map;
1604 for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
1606 register tree decl = build_decl (VAR_DECL, DECL_NAME (tail),
1609 = copy_rtx_and_substitute (RTVEC_ELT (arg_vector, i), map);
1611 /* These args would always appear unused, if not for this. */
1612 TREE_USED (decl) = 1;
1613 /* Prevent warning for shadowing with these. */
1614 DECL_FROM_INLINE (decl) = 1;
1616 /* Fully instantiate the address with the equivalent form so that the
1617 debugging information contains the actual register, instead of the
1618 virtual register. Do this by not passing an insn to
1620 subst_constants (&new_decl_rtl, 0, map);
1621 apply_change_group ();
1622 DECL_RTL (decl) = new_decl_rtl;
1626 /* Given a BLOCK node LET, push decls and levels so as to construct in the
1627 current function a tree of contexts isomorphic to the one that is given.
1629 LEVEL indicates how far down into the BLOCK tree is the node we are
1630 currently traversing. It is always zero for the initial call.
1632 MAP, if nonzero, is a pointer to a inline_remap map which indicates how
1633 registers used in the DECL_RTL field should be remapped. If it is zero,
1634 no mapping is necessary.
1636 FUNCTIONBODY indicates whether the top level block tree corresponds to
1637 a function body. This is identical in meaning to the functionbody
1638 argument of poplevel. */
1641 integrate_decl_tree (let, level, map, functionbody)
1644 struct inline_remap *map;
1651 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
1653 tree d = build_decl (TREE_CODE (t), DECL_NAME (t), TREE_TYPE (t));
1654 DECL_SOURCE_LINE (d) = DECL_SOURCE_LINE (t);
1655 DECL_SOURCE_FILE (d) = DECL_SOURCE_FILE (t);
1656 if (! functionbody && DECL_RTL (t) != 0)
1658 DECL_RTL (d) = copy_rtx_and_substitute (DECL_RTL (t), map);
1659 /* Fully instantiate the address with the equivalent form so that the
1660 debugging information contains the actual register, instead of the
1661 virtual register. Do this by not passing an insn to
1663 subst_constants (&DECL_RTL (d), 0, map);
1664 apply_change_group ();
1666 else if (DECL_RTL (t))
1667 DECL_RTL (d) = copy_rtx (DECL_RTL (t));
1668 TREE_EXTERNAL (d) = TREE_EXTERNAL (t);
1669 TREE_STATIC (d) = TREE_STATIC (t);
1670 TREE_PUBLIC (d) = TREE_PUBLIC (t);
1671 TREE_CONSTANT (d) = TREE_CONSTANT (t);
1672 TREE_ADDRESSABLE (d) = TREE_ADDRESSABLE (t);
1673 TREE_READONLY (d) = TREE_READONLY (t);
1674 TREE_SIDE_EFFECTS (d) = TREE_SIDE_EFFECTS (t);
1675 /* These args would always appear unused, if not for this. */
1677 /* Prevent warning for shadowing with these. */
1678 DECL_FROM_INLINE (d) = 1;
1682 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
1683 integrate_decl_tree (t, level + 1, map, functionbody);
1685 node = poplevel (level > 0, 0, level == 0 && functionbody);
1687 TREE_USED (node) = TREE_USED (let);
1690 /* Create a new copy of an rtx.
1691 Recursively copies the operands of the rtx,
1692 except for those few rtx codes that are sharable.
1694 We always return an rtx that is similar to that incoming rtx, with the
1695 exception of possibly changing a REG to a SUBREG or vice versa. No
1696 rtl is ever emitted.
1698 Handle constants that need to be placed in the constant pool by
1699 calling `force_const_mem'. */
1702 copy_rtx_and_substitute (orig, map)
1704 struct inline_remap *map;
1706 register rtx copy, temp;
1708 register RTX_CODE code;
1709 register enum machine_mode mode;
1710 register char *format_ptr;
1716 code = GET_CODE (orig);
1717 mode = GET_MODE (orig);
1722 /* If the stack pointer register shows up, it must be part of
1723 stack-adjustments (*not* because we eliminated the frame pointer!).
1724 Small hard registers are returned as-is. Pseudo-registers
1725 go through their `reg_map'. */
1726 regno = REGNO (orig);
1727 if (regno <= LAST_VIRTUAL_REGISTER)
1729 /* Some hard registers are also mapped,
1730 but others are not translated. */
1731 if (map->reg_map[regno] != 0)
1732 return map->reg_map[regno];
1734 /* If this is the virtual frame pointer, make space in current
1735 function's stack frame for the stack frame of the inline function.
1737 Copy the address of this area into a pseudo. Map
1738 virtual_stack_vars_rtx to this pseudo and set up a constant
1739 equivalence for it to be the address. This will substitute the
1740 address into insns where it can be substituted and use the new
1741 pseudo where it can't. */
1742 if (regno == VIRTUAL_STACK_VARS_REGNUM)
1745 int size = DECL_FRAME_SIZE (map->fndecl);
1749 loc = assign_stack_temp (BLKmode, size, 1);
1750 loc = XEXP (loc, 0);
1751 #ifdef FRAME_GROWS_DOWNWARD
1752 /* In this case, virtual_stack_vars_rtx points to one byte
1753 higher than the top of the frame area. So compute the offset
1754 to one byte higher than our substitute frame.
1755 Keep the fake frame pointer aligned like a real one. */
1756 rounded = CEIL_ROUND (size, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
1757 loc = plus_constant (loc, rounded);
1759 map->reg_map[regno] = force_operand (loc, 0);
1760 map->const_equiv_map[regno] = loc;
1761 map->const_age_map[regno] = CONST_AGE_PARM;
1763 seq = gen_sequence ();
1765 emit_insn_after (seq, map->insns_at_start);
1766 return map->reg_map[regno];
1768 else if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
1770 /* Do the same for a block to contain any arguments referenced
1773 int size = FUNCTION_ARGS_SIZE (DECL_SAVED_INSNS (map->fndecl));
1776 loc = assign_stack_temp (BLKmode, size, 1);
1777 loc = XEXP (loc, 0);
1778 map->reg_map[regno] = force_operand (loc, 0);
1779 map->const_equiv_map[regno] = loc;
1780 map->const_age_map[regno] = CONST_AGE_PARM;
1782 seq = gen_sequence ();
1784 emit_insn_after (seq, map->insns_at_start);
1785 return map->reg_map[regno];
1787 else if (REG_FUNCTION_VALUE_P (orig))
1789 /* This is a reference to the function return value. If
1790 the function doesn't have a return value, error. If the
1791 mode doesn't agree, make a SUBREG. */
1792 if (map->inline_target == 0)
1793 /* Must be unrolling loops or replicating code if we
1794 reach here, so return the register unchanged. */
1796 else if (mode != GET_MODE (map->inline_target))
1797 return gen_rtx (SUBREG, mode, map->inline_target, 0);
1799 return map->inline_target;
1803 if (map->reg_map[regno] == NULL)
1805 map->reg_map[regno] = gen_reg_rtx (mode);
1806 REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (orig);
1807 REG_LOOP_TEST_P (map->reg_map[regno]) = REG_LOOP_TEST_P (orig);
1808 RTX_UNCHANGING_P (map->reg_map[regno]) = RTX_UNCHANGING_P (orig);
1809 /* A reg with REG_FUNCTION_VALUE_P true will never reach here. */
1811 return map->reg_map[regno];
1814 copy = copy_rtx_and_substitute (SUBREG_REG (orig), map);
1815 /* SUBREG is ordinary, but don't make nested SUBREGs. */
1816 if (GET_CODE (copy) == SUBREG)
1817 return gen_rtx (SUBREG, GET_MODE (orig), SUBREG_REG (copy),
1818 SUBREG_WORD (orig) + SUBREG_WORD (copy));
1820 return gen_rtx (SUBREG, GET_MODE (orig), copy,
1821 SUBREG_WORD (orig));
1825 /* USE and CLOBBER are ordinary, but we convert (use (subreg foo))
1827 copy = copy_rtx_and_substitute (XEXP (orig, 0), map);
1828 if (GET_CODE (copy) == SUBREG)
1829 copy = SUBREG_REG (copy);
1830 return gen_rtx (code, VOIDmode, copy);
1833 LABEL_PRESERVE_P (map->label_map[CODE_LABEL_NUMBER (orig)])
1834 = LABEL_PRESERVE_P (orig);
1835 return map->label_map[CODE_LABEL_NUMBER (orig)];
1838 copy = rtx_alloc (LABEL_REF);
1839 PUT_MODE (copy, mode);
1840 XEXP (copy, 0) = map->label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))];
1841 LABEL_OUTSIDE_LOOP_P (copy) = LABEL_OUTSIDE_LOOP_P (orig);
1851 /* We have to make a new copy of this CONST_DOUBLE because don't want
1852 to use the old value of CONST_DOUBLE_MEM. Also, this may be a
1853 duplicate of a CONST_DOUBLE we have already seen. */
1854 if (GET_MODE_CLASS (GET_MODE (orig)) == MODE_FLOAT)
1858 REAL_VALUE_FROM_CONST_DOUBLE (d, orig);
1859 return immed_real_const_1 (d, GET_MODE (orig));
1862 return immed_double_const (CONST_DOUBLE_LOW (orig),
1863 CONST_DOUBLE_HIGH (orig), VOIDmode);
1866 /* Make new constant pool entry for a constant
1867 that was in the pool of the inline function. */
1868 if (RTX_INTEGRATED_P (orig))
1870 /* If this was an address of a constant pool entry that itself
1871 had to be placed in the constant pool, it might not be a
1872 valid address. So the recursive call below might turn it
1873 into a register. In that case, it isn't a constant any
1874 more, so return it. This has the potential of changing a
1875 MEM into a REG, but we'll assume that it safe. */
1876 temp = copy_rtx_and_substitute (XEXP (orig, 0), map);
1877 if (! CONSTANT_P (temp))
1879 return validize_mem (force_const_mem (GET_MODE (orig), temp));
1884 /* If from constant pool address, make new constant pool entry and
1885 return its address. */
1886 if (! RTX_INTEGRATED_P (orig))
1889 temp = force_const_mem (GET_MODE (orig),
1890 copy_rtx_and_substitute (XEXP (orig, 0), map));
1893 /* Legitimizing the address here is incorrect.
1895 The only ADDRESS rtx's that can reach here are ones created by
1896 save_constants. Hence the operand of the ADDRESS is always legal
1897 in this position of the instruction, since the original rtx without
1898 the ADDRESS was legal.
1900 The reason we don't legitimize the address here is that on the
1901 Sparc, the caller may have a (high ...) surrounding this ADDRESS.
1902 This code forces the operand of the address to a register, which
1903 fails because we can not take the HIGH part of a register.
1905 Also, change_address may create new registers. These registers
1906 will not have valid reg_map entries. This can cause try_constants()
1907 to fail because assumes that all registers in the rtx have valid
1908 reg_map entries, and it may end up replacing one of these new
1909 registers with junk. */
1911 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
1912 temp = change_address (temp, GET_MODE (temp), XEXP (temp, 0));
1915 return XEXP (temp, 0);
1918 /* If a single asm insn contains multiple output operands
1919 then it contains multiple ASM_OPERANDS rtx's that share operand 3.
1920 We must make sure that the copied insn continues to share it. */
1921 if (map->orig_asm_operands_vector == XVEC (orig, 3))
1923 copy = rtx_alloc (ASM_OPERANDS);
1924 XSTR (copy, 0) = XSTR (orig, 0);
1925 XSTR (copy, 1) = XSTR (orig, 1);
1926 XINT (copy, 2) = XINT (orig, 2);
1927 XVEC (copy, 3) = map->copy_asm_operands_vector;
1928 XVEC (copy, 4) = map->copy_asm_constraints_vector;
1929 XSTR (copy, 5) = XSTR (orig, 5);
1930 XINT (copy, 6) = XINT (orig, 6);
1936 /* This is given special treatment because the first
1937 operand of a CALL is a (MEM ...) which may get
1938 forced into a register for cse. This is undesirable
1939 if function-address cse isn't wanted or if we won't do cse. */
1940 #ifndef NO_FUNCTION_CSE
1941 if (! (optimize && ! flag_no_function_cse))
1943 return gen_rtx (CALL, GET_MODE (orig),
1944 gen_rtx (MEM, GET_MODE (XEXP (orig, 0)),
1945 copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0), map)),
1946 copy_rtx_and_substitute (XEXP (orig, 1), map));
1950 /* Must be ifdefed out for loop unrolling to work. */
1956 /* If this is setting fp or ap, it means that we have a nonlocal goto.
1958 If the nonlocal goto is into the current function,
1959 this will result in unnecessarily bad code, but should work. */
1960 if (SET_DEST (orig) == virtual_stack_vars_rtx
1961 || SET_DEST (orig) == virtual_incoming_args_rtx)
1962 return gen_rtx (SET, VOIDmode, SET_DEST (orig),
1963 copy_rtx_and_substitute (SET_SRC (orig), map));
1967 copy = rtx_alloc (MEM);
1968 PUT_MODE (copy, mode);
1969 XEXP (copy, 0) = copy_rtx_and_substitute (XEXP (orig, 0), map);
1970 MEM_IN_STRUCT_P (copy) = MEM_IN_STRUCT_P (orig);
1971 MEM_VOLATILE_P (copy) = MEM_VOLATILE_P (orig);
1972 RTX_UNCHANGING_P (copy) = RTX_UNCHANGING_P (orig);
1976 copy = rtx_alloc (code);
1977 PUT_MODE (copy, mode);
1978 copy->in_struct = orig->in_struct;
1979 copy->volatil = orig->volatil;
1980 copy->unchanging = orig->unchanging;
1982 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
1984 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
1986 switch (*format_ptr++)
1992 XEXP (copy, i) = copy_rtx_and_substitute (XEXP (orig, i), map);
1996 /* Change any references to old-insns to point to the
1997 corresponding copied insns. */
1998 XEXP (copy, i) = map->insn_map[INSN_UID (XEXP (orig, i))];
2002 XVEC (copy, i) = XVEC (orig, i);
2003 if (XVEC (orig, i) != NULL && XVECLEN (orig, i) != 0)
2005 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
2006 for (j = 0; j < XVECLEN (copy, i); j++)
2007 XVECEXP (copy, i, j)
2008 = copy_rtx_and_substitute (XVECEXP (orig, i, j), map);
2013 XINT (copy, i) = XINT (orig, i);
2017 XSTR (copy, i) = XSTR (orig, i);
2025 if (code == ASM_OPERANDS && map->orig_asm_operands_vector == 0)
2027 map->orig_asm_operands_vector = XVEC (orig, 3);
2028 map->copy_asm_operands_vector = XVEC (copy, 3);
2029 map->copy_asm_constraints_vector = XVEC (copy, 4);
2035 /* Substitute known constant values into INSN, if that is valid. */
2038 try_constants (insn, map)
2040 struct inline_remap *map;
2045 subst_constants (&PATTERN (insn), insn, map);
2047 /* Apply the changes if they are valid; otherwise discard them. */
2048 apply_change_group ();
2050 /* Show we don't know the value of anything stored or clobbered. */
2051 note_stores (PATTERN (insn), mark_stores);
2052 map->last_pc_value = 0;
2054 map->last_cc0_value = 0;
2057 /* Set up any constant equivalences made in this insn. */
2058 for (i = 0; i < map->num_sets; i++)
2060 if (GET_CODE (map->equiv_sets[i].dest) == REG)
2062 int regno = REGNO (map->equiv_sets[i].dest);
2064 if (map->const_equiv_map[regno] == 0
2065 /* Following clause is a hack to make case work where GNU C++
2066 reassigns a variable to make cse work right. */
2067 || ! rtx_equal_p (map->const_equiv_map[regno],
2068 map->equiv_sets[i].equiv))
2070 map->const_equiv_map[regno] = map->equiv_sets[i].equiv;
2071 map->const_age_map[regno] = map->const_age;
2074 else if (map->equiv_sets[i].dest == pc_rtx)
2075 map->last_pc_value = map->equiv_sets[i].equiv;
2077 else if (map->equiv_sets[i].dest == cc0_rtx)
2078 map->last_cc0_value = map->equiv_sets[i].equiv;
2083 /* Substitute known constants for pseudo regs in the contents of LOC,
2084 which are part of INSN.
2085 If INSN is zero, the substition should always be done (this is used to
2087 These changes are taken out by try_constants if the result is not valid.
2089 Note that we are more concerned with determining when the result of a SET
2090 is a constant, for further propagation, than actually inserting constants
2091 into insns; cse will do the latter task better.
2093 This function is also used to adjust address of items previously addressed
2094 via the virtual stack variable or virtual incoming arguments registers. */
2097 subst_constants (loc, insn, map)
2100 struct inline_remap *map;
2104 register enum rtx_code code;
2105 register char *format_ptr;
2106 int num_changes = num_validated_changes ();
2108 enum machine_mode op0_mode;
2110 code = GET_CODE (x);
2125 validate_change (insn, loc, map->last_cc0_value, 1);
2131 /* The only thing we can do with a USE or CLOBBER is possibly do
2132 some substitutions in a MEM within it. */
2133 if (GET_CODE (XEXP (x, 0)) == MEM)
2134 subst_constants (&XEXP (XEXP (x, 0), 0), insn, map);
2138 /* Substitute for parms and known constants. Don't replace
2139 hard regs used as user variables with constants. */
2141 int regno = REGNO (x);
2142 if (! (regno < FIRST_PSEUDO_REGISTER && REG_USERVAR_P (x))
2143 && map->const_equiv_map[regno] != 0
2144 && map->const_age_map[regno] >= map->const_age)
2145 validate_change (insn, loc, map->const_equiv_map[regno], 1);
2150 /* SUBREG is ordinary, but don't make nested SUBREGs and try to simplify
2153 rtx inner = SUBREG_REG (x);
2156 /* We can't call subst_constants on &SUBREG_REG (x) because any
2157 constant or SUBREG wouldn't be valid inside our SUBEG. Instead,
2158 see what is inside, try to form the new SUBREG and see if that is
2159 valid. We handle two cases: extracting a full word in an
2160 integral mode and extracting the low part. */
2161 subst_constants (&inner, 0, map);
2163 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2164 && GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD
2165 && GET_MODE (SUBREG_REG (x)) != VOIDmode)
2166 new = operand_subword (inner, SUBREG_WORD (x), 0,
2167 GET_MODE (SUBREG_REG (x)));
2169 if (new == 0 && subreg_lowpart_p (x))
2170 new = gen_lowpart_common (GET_MODE (x), inner);
2173 validate_change (insn, loc, new, 1);
2179 subst_constants (&XEXP (x, 0), insn, map);
2181 /* If a memory address got spoiled, change it back. */
2182 if (insn != 0 && num_validated_changes () != num_changes
2183 && !memory_address_p (GET_MODE (x), XEXP (x, 0)))
2184 cancel_changes (num_changes);
2189 /* Substitute constants in our source, and in any arguments to a
2190 complex (e..g, ZERO_EXTRACT) destination, but not in the destination
2192 rtx *dest_loc = &SET_DEST (x);
2193 rtx dest = *dest_loc;
2196 subst_constants (&SET_SRC (x), insn, map);
2199 while (GET_CODE (*dest_loc) == ZERO_EXTRACT
2200 || GET_CODE (*dest_loc) == SIGN_EXTRACT
2201 || GET_CODE (*dest_loc) == SUBREG
2202 || GET_CODE (*dest_loc) == STRICT_LOW_PART)
2204 if (GET_CODE (*dest_loc) == ZERO_EXTRACT)
2206 subst_constants (&XEXP (*dest_loc, 1), insn, map);
2207 subst_constants (&XEXP (*dest_loc, 2), insn, map);
2209 dest_loc = &XEXP (*dest_loc, 0);
2212 /* Check for the case of DEST a SUBREG, both it and the underlying
2213 register are less than one word, and the SUBREG has the wider mode.
2214 In the case, we are really setting the underlying register to the
2215 source converted to the mode of DEST. So indicate that. */
2216 if (GET_CODE (dest) == SUBREG
2217 && GET_MODE_SIZE (GET_MODE (dest)) <= UNITS_PER_WORD
2218 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) <= UNITS_PER_WORD
2219 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2220 <= GET_MODE_SIZE (GET_MODE (dest)))
2221 && (tem = gen_lowpart_if_possible (GET_MODE (dest), src)))
2222 src = tem, dest = SUBREG_REG (dest);
2224 /* If storing a recognizable value save it for later recording. */
2225 if ((map->num_sets < MAX_RECOG_OPERANDS)
2226 && (CONSTANT_P (src)
2227 || (GET_CODE (src) == PLUS
2228 && GET_CODE (XEXP (src, 0)) == REG
2229 && REGNO (XEXP (src, 0)) >= FIRST_VIRTUAL_REGISTER
2230 && REGNO (XEXP (src, 0)) <= LAST_VIRTUAL_REGISTER
2231 && CONSTANT_P (XEXP (src, 1)))
2232 || GET_CODE (src) == COMPARE
2237 && (src == pc_rtx || GET_CODE (src) == RETURN
2238 || GET_CODE (src) == LABEL_REF))))
2240 /* Normally, this copy won't do anything. But, if SRC is a COMPARE
2241 it will cause us to save the COMPARE with any constants
2242 substituted, which is what we want for later. */
2243 map->equiv_sets[map->num_sets].equiv = copy_rtx (src);
2244 map->equiv_sets[map->num_sets++].dest = dest;
2251 format_ptr = GET_RTX_FORMAT (code);
2253 /* If the first operand is an expression, save its mode for later. */
2254 if (*format_ptr == 'e')
2255 op0_mode = GET_MODE (XEXP (x, 0));
2257 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2259 switch (*format_ptr++)
2266 subst_constants (&XEXP (x, i), insn, map);
2275 if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
2278 for (j = 0; j < XVECLEN (x, i); j++)
2279 subst_constants (&XVECEXP (x, i, j), insn, map);
2288 /* If this is a commutative operation, move a constant to the second
2289 operand unless the second operand is already a CONST_INT. */
2290 if ((GET_RTX_CLASS (code) == 'c' || code == NE || code == EQ)
2291 && CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT)
2293 rtx tem = XEXP (x, 0);
2294 validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
2295 validate_change (insn, &XEXP (x, 1), tem, 1);
2298 /* Simplify the expression in case we put in some constants. */
2299 switch (GET_RTX_CLASS (code))
2302 new = simplify_unary_operation (code, GET_MODE (x),
2303 XEXP (x, 0), op0_mode);
2308 enum machine_mode op_mode = GET_MODE (XEXP (x, 0));
2309 if (op_mode == VOIDmode)
2310 op_mode = GET_MODE (XEXP (x, 1));
2311 new = simplify_relational_operation (code, op_mode,
2312 XEXP (x, 0), XEXP (x, 1));
2318 new = simplify_binary_operation (code, GET_MODE (x),
2319 XEXP (x, 0), XEXP (x, 1));
2324 new = simplify_ternary_operation (code, GET_MODE (x), op0_mode,
2325 XEXP (x, 0), XEXP (x, 1), XEXP (x, 2));
2330 validate_change (insn, loc, new, 1);
2333 /* Show that register modified no longer contain known constants. We are
2334 called from note_stores with parts of the new insn. */
2337 mark_stores (dest, x)
2341 if (GET_CODE (dest) == SUBREG)
2342 dest = SUBREG_REG (dest);
2344 if (GET_CODE (dest) == REG)
2345 global_const_equiv_map[REGNO (dest)] = 0;
2348 /* If any CONST expressions with RTX_INTEGRATED_P are present in the rtx
2349 pointed to by PX, they represent constants in the constant pool.
2350 Replace these with a new memory reference obtained from force_const_mem.
2351 Similarly, ADDRESS expressions with RTX_INTEGRATED_P represent the
2352 address of a constant pool entry. Replace them with the address of
2353 a new constant pool entry obtained from force_const_mem. */
2356 restore_constants (px)
2366 if (GET_CODE (x) == CONST_DOUBLE)
2368 /* We have to make a new CONST_DOUBLE to ensure that we account for
2369 it correctly. Using the old CONST_DOUBLE_MEM data is wrong. */
2370 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2374 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2375 *px = immed_real_const_1 (d, GET_MODE (x));
2378 *px = immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
2382 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == CONST)
2384 restore_constants (&XEXP (x, 0));
2385 *px = validize_mem (force_const_mem (GET_MODE (x), XEXP (x, 0)));
2387 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == SUBREG)
2389 /* This must be (subreg/i:M1 (const/i:M2 ...) 0). */
2390 rtx new = XEXP (SUBREG_REG (x), 0);
2392 restore_constants (&new);
2393 new = force_const_mem (GET_MODE (SUBREG_REG (x)), new);
2394 PUT_MODE (new, GET_MODE (x));
2395 *px = validize_mem (new);
2397 else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == ADDRESS)
2399 restore_constants (&XEXP (x, 0));
2400 *px = XEXP (force_const_mem (GET_MODE (x), XEXP (x, 0)), 0);
2404 fmt = GET_RTX_FORMAT (GET_CODE (x));
2405 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
2410 for (j = 0; j < XVECLEN (x, i); j++)
2411 restore_constants (&XVECEXP (x, i, j));
2415 restore_constants (&XEXP (x, i));
2422 /* Output the assembly language code for the function FNDECL
2423 from its DECL_SAVED_INSNS. Used for inline functions that are output
2424 at end of compilation instead of where they came in the source. */
2427 output_inline_function (fndecl)
2430 rtx head = DECL_SAVED_INSNS (fndecl);
2433 temporary_allocation ();
2435 current_function_decl = fndecl;
2437 /* This call is only used to initialize global variables. */
2438 init_function_start (fndecl, "lossage", 1);
2440 /* Redo parameter determinations in case the FUNCTION_...
2441 macros took machine-specific actions that need to be redone. */
2442 assign_parms (fndecl, 1);
2444 /* Set stack frame size. */
2445 assign_stack_local (BLKmode, DECL_FRAME_SIZE (fndecl), 0);
2447 restore_reg_data (FIRST_PARM_INSN (head));
2449 stack_slot_list = STACK_SLOT_LIST (head);
2451 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_ALLOCA)
2452 current_function_calls_alloca = 1;
2454 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_SETJMP)
2455 current_function_calls_setjmp = 1;
2457 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_LONGJMP)
2458 current_function_calls_longjmp = 1;
2460 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_STRUCT)
2461 current_function_returns_struct = 1;
2463 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_PCC_STRUCT)
2464 current_function_returns_pcc_struct = 1;
2466 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_NEEDS_CONTEXT)
2467 current_function_needs_context = 1;
2469 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_HAS_NONLOCAL_LABEL)
2470 current_function_has_nonlocal_label = 1;
2472 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_POINTER)
2473 current_function_returns_pointer = 1;
2475 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_USES_CONST_POOL)
2476 current_function_uses_const_pool = 1;
2478 if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE)
2479 current_function_uses_pic_offset_table = 1;
2481 current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (head);
2482 current_function_pops_args = POPS_ARGS (head);
2484 /* There is no need to output a return label again. */
2487 expand_function_end (DECL_SOURCE_FILE (fndecl), DECL_SOURCE_LINE (fndecl));
2489 /* Find last insn and rebuild the constant pool. */
2490 for (last = FIRST_PARM_INSN (head);
2491 NEXT_INSN (last); last = NEXT_INSN (last))
2493 if (GET_RTX_CLASS (GET_CODE (last)) == 'i')
2495 restore_constants (&PATTERN (last));
2496 restore_constants (®_NOTES (last));
2500 set_new_first_and_last_insn (FIRST_PARM_INSN (head), last);
2501 set_new_first_and_last_label_num (FIRST_LABELNO (head), LAST_LABELNO (head));
2503 /* Compile this function all the way down to assembly code. */
2504 rest_of_compilation (fndecl);
2506 current_function_decl = 0;
2508 permanent_allocation ();