Define FUNCTION_ATTRIBUTE_INLINABLE_P, a target macro to allow functions with
[official-gcc.git] / gcc / integrate.c
blob6fa0be17fc73e59dc496ba7f3e3e008fba5ccff4
1 /* Procedure integration for GNU CC.
2 Copyright (C) 1988, 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "config.h"
25 #include "system.h"
27 #include "rtl.h"
28 #include "tree.h"
29 #include "tm_p.h"
30 #include "regs.h"
31 #include "flags.h"
32 #include "insn-config.h"
33 #include "insn-flags.h"
34 #include "expr.h"
35 #include "output.h"
36 #include "recog.h"
37 #include "integrate.h"
38 #include "real.h"
39 #include "except.h"
40 #include "function.h"
41 #include "toplev.h"
42 #include "intl.h"
43 #include "loop.h"
45 #include "obstack.h"
46 #define obstack_chunk_alloc xmalloc
47 #define obstack_chunk_free free
49 extern struct obstack *function_maybepermanent_obstack;
51 /* Similar, but round to the next highest integer that meets the
52 alignment. */
53 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
55 /* Default max number of insns a function can have and still be inline.
56 This is overridden on RISC machines. */
57 #ifndef INTEGRATE_THRESHOLD
58 /* Inlining small functions might save more space then not inlining at
59 all. Assume 1 instruction for the call and 1.5 insns per argument. */
60 #define INTEGRATE_THRESHOLD(DECL) \
61 (optimize_size \
62 ? (1 + (3 * list_length (DECL_ARGUMENTS (DECL))) / 2) \
63 : (8 * (8 + list_length (DECL_ARGUMENTS (DECL)))))
64 #endif
66 /* Decide whether a function with a target specific attribute
67 attached can be inlined. By default we disallow this. */
68 #ifndef FUNCTION_ATTRIBUTE_INLINABLE_P
69 #define FUNCTION_ATTRIBUTE_INLINABLE_P(FNDECL) 0
70 #endif
72 static rtvec initialize_for_inline PARAMS ((tree));
73 static void note_modified_parmregs PARAMS ((rtx, rtx, void *));
74 static void integrate_parm_decls PARAMS ((tree, struct inline_remap *,
75 rtvec));
76 static tree integrate_decl_tree PARAMS ((tree,
77 struct inline_remap *));
78 static void subst_constants PARAMS ((rtx *, rtx,
79 struct inline_remap *, int));
80 static void set_block_origin_self PARAMS ((tree));
81 static void set_decl_origin_self PARAMS ((tree));
82 static void set_block_abstract_flags PARAMS ((tree, int));
83 static void process_reg_param PARAMS ((struct inline_remap *, rtx,
84 rtx));
85 void set_decl_abstract_flags PARAMS ((tree, int));
86 static rtx expand_inline_function_eh_labelmap PARAMS ((rtx));
87 static void mark_stores PARAMS ((rtx, rtx, void *));
88 static void save_parm_insns PARAMS ((rtx, rtx));
89 static void copy_insn_list PARAMS ((rtx, struct inline_remap *,
90 rtx));
91 static int compare_blocks PARAMS ((const PTR, const PTR));
92 static int find_block PARAMS ((const PTR, const PTR));
94 /* The maximum number of instructions accepted for inlining a
95 function. Increasing values mean more agressive inlining.
96 This affects currently only functions explicitly marked as
97 inline (or methods defined within the class definition for C++).
98 The default value of 10000 is arbitrary but high to match the
99 previously unlimited gcc capabilities. */
101 int inline_max_insns = 10000;
103 /* Used by copy_rtx_and_substitute; this indicates whether the function is
104 called for the purpose of inlining or some other purpose (i.e. loop
105 unrolling). This affects how constant pool references are handled.
106 This variable contains the FUNCTION_DECL for the inlined function. */
107 static struct function *inlining = 0;
109 /* Returns the Ith entry in the label_map contained in MAP. If the
110 Ith entry has not yet been set, return a fresh label. This function
111 performs a lazy initialization of label_map, thereby avoiding huge memory
112 explosions when the label_map gets very large. */
115 get_label_from_map (map, i)
116 struct inline_remap *map;
117 int i;
119 rtx x = map->label_map[i];
121 if (x == NULL_RTX)
122 x = map->label_map[i] = gen_label_rtx();
124 return x;
127 /* Zero if the current function (whose FUNCTION_DECL is FNDECL)
128 is safe and reasonable to integrate into other functions.
129 Nonzero means value is a warning msgid with a single %s
130 for the function's name. */
132 const char *
133 function_cannot_inline_p (fndecl)
134 register tree fndecl;
136 register rtx insn;
137 tree last = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
139 /* For functions marked as inline increase the maximum size to
140 inline_max_insns (-finline-limit-<n>). For regular functions
141 use the limit given by INTEGRATE_THRESHOLD. */
143 int max_insns = (DECL_INLINE (fndecl))
144 ? (inline_max_insns
145 + 8 * list_length (DECL_ARGUMENTS (fndecl)))
146 : INTEGRATE_THRESHOLD (fndecl);
148 register int ninsns = 0;
149 register tree parms;
150 rtx result;
152 /* No inlines with varargs. */
153 if ((last && TREE_VALUE (last) != void_type_node)
154 || current_function_varargs)
155 return N_("varargs function cannot be inline");
157 if (current_function_calls_alloca)
158 return N_("function using alloca cannot be inline");
160 if (current_function_calls_setjmp)
161 return N_("function using setjmp cannot be inline");
163 if (current_function_contains_functions)
164 return N_("function with nested functions cannot be inline");
166 if (forced_labels)
167 return
168 N_("function with label addresses used in initializers cannot inline");
170 if (current_function_cannot_inline)
171 return current_function_cannot_inline;
173 /* If its not even close, don't even look. */
174 if (get_max_uid () > 3 * max_insns)
175 return N_("function too large to be inline");
177 #if 0
178 /* Don't inline functions which do not specify a function prototype and
179 have BLKmode argument or take the address of a parameter. */
180 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
182 if (TYPE_MODE (TREE_TYPE (parms)) == BLKmode)
183 TREE_ADDRESSABLE (parms) = 1;
184 if (last == NULL_TREE && TREE_ADDRESSABLE (parms))
185 return N_("no prototype, and parameter address used; cannot be inline");
187 #endif
189 /* We can't inline functions that return structures
190 the old-fashioned PCC way, copying into a static block. */
191 if (current_function_returns_pcc_struct)
192 return N_("inline functions not supported for this return value type");
194 /* We can't inline functions that return structures of varying size. */
195 if (TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
196 && int_size_in_bytes (TREE_TYPE (TREE_TYPE (fndecl))) < 0)
197 return N_("function with varying-size return value cannot be inline");
199 /* Cannot inline a function with a varying size argument or one that
200 receives a transparent union. */
201 for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
203 if (int_size_in_bytes (TREE_TYPE (parms)) < 0)
204 return N_("function with varying-size parameter cannot be inline");
205 else if (TYPE_TRANSPARENT_UNION (TREE_TYPE (parms)))
206 return N_("function with transparent unit parameter cannot be inline");
209 if (get_max_uid () > max_insns)
211 for (ninsns = 0, insn = get_first_nonparm_insn ();
212 insn && ninsns < max_insns;
213 insn = NEXT_INSN (insn))
214 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
215 ninsns++;
217 if (ninsns >= max_insns)
218 return N_("function too large to be inline");
221 /* We will not inline a function which uses computed goto. The addresses of
222 its local labels, which may be tucked into global storage, are of course
223 not constant across instantiations, which causes unexpected behaviour. */
224 if (current_function_has_computed_jump)
225 return N_("function with computed jump cannot inline");
227 /* We cannot inline a nested function that jumps to a nonlocal label. */
228 if (current_function_has_nonlocal_goto)
229 return N_("function with nonlocal goto cannot be inline");
231 /* This is a hack, until the inliner is taught about eh regions at
232 the start of the function. */
233 for (insn = get_insns ();
234 insn
235 && ! (GET_CODE (insn) == NOTE
236 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG);
237 insn = NEXT_INSN (insn))
239 if (insn && GET_CODE (insn) == NOTE
240 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
241 return N_("function with complex parameters cannot be inline");
244 /* We can't inline functions that return a PARALLEL rtx. */
245 result = DECL_RTL (DECL_RESULT (fndecl));
246 if (result && GET_CODE (result) == PARALLEL)
247 return N_("inline functions not supported for this return value type");
249 /* If the function has a target specific attribute attached to it,
250 then we assume that we should not inline it. This can be overriden
251 by the target if it defines FUNCTION_ATTRIBUTE_INLINABLE_P. */
252 if (DECL_MACHINE_ATTRIBUTES (fndecl)
253 && ! FUNCTION_ATTRIBUTE_INLINABLE_P (fndecl))
254 return N_("function with target specific attribute(s) cannot be inlined");
256 return NULL;
259 /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
260 Zero for a reg that isn't a parm's home.
261 Only reg numbers less than max_parm_reg are mapped here. */
262 static tree *parmdecl_map;
264 /* In save_for_inline, nonzero if past the parm-initialization insns. */
265 static int in_nonparm_insns;
267 /* Subroutine for `save_for_inline_nocopy'. Performs initialization
268 needed to save FNDECL's insns and info for future inline expansion. */
270 static rtvec
271 initialize_for_inline (fndecl)
272 tree fndecl;
274 int i;
275 rtvec arg_vector;
276 tree parms;
278 /* Clear out PARMDECL_MAP. It was allocated in the caller's frame. */
279 bzero ((char *) parmdecl_map, max_parm_reg * sizeof (tree));
280 arg_vector = rtvec_alloc (list_length (DECL_ARGUMENTS (fndecl)));
282 for (parms = DECL_ARGUMENTS (fndecl), i = 0;
283 parms;
284 parms = TREE_CHAIN (parms), i++)
286 rtx p = DECL_RTL (parms);
288 /* If we have (mem (addressof (mem ...))), use the inner MEM since
289 otherwise the copy_rtx call below will not unshare the MEM since
290 it shares ADDRESSOF. */
291 if (GET_CODE (p) == MEM && GET_CODE (XEXP (p, 0)) == ADDRESSOF
292 && GET_CODE (XEXP (XEXP (p, 0), 0)) == MEM)
293 p = XEXP (XEXP (p, 0), 0);
295 RTVEC_ELT (arg_vector, i) = p;
297 if (GET_CODE (p) == REG)
298 parmdecl_map[REGNO (p)] = parms;
299 else if (GET_CODE (p) == CONCAT)
301 rtx preal = gen_realpart (GET_MODE (XEXP (p, 0)), p);
302 rtx pimag = gen_imagpart (GET_MODE (preal), p);
304 if (GET_CODE (preal) == REG)
305 parmdecl_map[REGNO (preal)] = parms;
306 if (GET_CODE (pimag) == REG)
307 parmdecl_map[REGNO (pimag)] = parms;
310 /* This flag is cleared later
311 if the function ever modifies the value of the parm. */
312 TREE_READONLY (parms) = 1;
315 return arg_vector;
318 /* Copy NODE (which must be a DECL, but not a PARM_DECL). The DECL
319 originally was in the FROM_FN, but now it will be in the
320 TO_FN. */
322 tree
323 copy_decl_for_inlining (decl, from_fn, to_fn)
324 tree decl;
325 tree from_fn;
326 tree to_fn;
328 tree copy;
330 /* Copy the declaration. */
331 if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL)
333 /* For a parameter, we must make an equivalent VAR_DECL, not a
334 new PARM_DECL. */
335 copy = build_decl (VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
336 TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
338 else
340 copy = copy_node (decl);
341 if (DECL_LANG_SPECIFIC (copy))
342 copy_lang_decl (copy);
344 /* TREE_ADDRESSABLE isn't used to indicate that a label's
345 address has been taken; it's for internal bookkeeping in
346 expand_goto_internal. */
347 if (TREE_CODE (copy) == LABEL_DECL)
348 TREE_ADDRESSABLE (copy) = 0;
351 /* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what
352 declaration inspired this copy. */
353 DECL_ABSTRACT_ORIGIN (copy) = DECL_ORIGIN (decl);
355 /* The new variable/label has no RTL, yet. */
356 DECL_RTL (copy) = NULL_RTX;
358 /* These args would always appear unused, if not for this. */
359 TREE_USED (copy) = 1;
361 /* Set the context for the new declaration. */
362 if (!DECL_CONTEXT (decl))
363 /* Globals stay global. */
365 else if (DECL_CONTEXT (decl) != from_fn)
366 /* Things that weren't in the scope of the function we're inlining
367 from aren't in the scope we're inlining too, either. */
369 else if (TREE_STATIC (decl))
370 /* Function-scoped static variables should say in the original
371 function. */
373 else
374 /* Ordinary automatic local variables are now in the scope of the
375 new function. */
376 DECL_CONTEXT (copy) = to_fn;
378 return copy;
381 /* Make the insns and PARM_DECLs of the current function permanent
382 and record other information in DECL_SAVED_INSNS to allow inlining
383 of this function in subsequent calls.
385 This routine need not copy any insns because we are not going
386 to immediately compile the insns in the insn chain. There
387 are two cases when we would compile the insns for FNDECL:
388 (1) when FNDECL is expanded inline, and (2) when FNDECL needs to
389 be output at the end of other compilation, because somebody took
390 its address. In the first case, the insns of FNDECL are copied
391 as it is expanded inline, so FNDECL's saved insns are not
392 modified. In the second case, FNDECL is used for the last time,
393 so modifying the rtl is not a problem.
395 We don't have to worry about FNDECL being inline expanded by
396 other functions which are written at the end of compilation
397 because flag_no_inline is turned on when we begin writing
398 functions at the end of compilation. */
400 void
401 save_for_inline_nocopy (fndecl)
402 tree fndecl;
404 rtx insn;
405 rtvec argvec;
406 rtx first_nonparm_insn;
408 /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
409 Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
410 Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
411 for the parms, prior to elimination of virtual registers.
412 These values are needed for substituting parms properly. */
414 parmdecl_map = (tree *) xmalloc (max_parm_reg * sizeof (tree));
416 /* Make and emit a return-label if we have not already done so. */
418 if (return_label == 0)
420 return_label = gen_label_rtx ();
421 emit_label (return_label);
424 argvec = initialize_for_inline (fndecl);
426 /* If there are insns that copy parms from the stack into pseudo registers,
427 those insns are not copied. `expand_inline_function' must
428 emit the correct code to handle such things. */
430 insn = get_insns ();
431 if (GET_CODE (insn) != NOTE)
432 abort ();
434 /* Get the insn which signals the end of parameter setup code. */
435 first_nonparm_insn = get_first_nonparm_insn ();
437 /* Now just scan the chain of insns to see what happens to our
438 PARM_DECLs. If a PARM_DECL is used but never modified, we
439 can substitute its rtl directly when expanding inline (and
440 perform constant folding when its incoming value is constant).
441 Otherwise, we have to copy its value into a new register and track
442 the new register's life. */
443 in_nonparm_insns = 0;
444 save_parm_insns (insn, first_nonparm_insn);
446 /* We have now allocated all that needs to be allocated permanently
447 on the rtx obstack. Set our high-water mark, so that we
448 can free the rest of this when the time comes. */
450 preserve_data ();
452 cfun->inl_max_label_num = max_label_num ();
453 cfun->inl_last_parm_insn = cfun->x_last_parm_insn;
454 cfun->original_arg_vector = argvec;
455 cfun->original_decl_initial = DECL_INITIAL (fndecl);
456 DECL_SAVED_INSNS (fndecl) = cfun;
458 /* Clean up. */
459 free (parmdecl_map);
462 /* Scan the chain of insns to see what happens to our PARM_DECLs. If a
463 PARM_DECL is used but never modified, we can substitute its rtl directly
464 when expanding inline (and perform constant folding when its incoming
465 value is constant). Otherwise, we have to copy its value into a new
466 register and track the new register's life. */
468 static void
469 save_parm_insns (insn, first_nonparm_insn)
470 rtx insn;
471 rtx first_nonparm_insn;
473 if (insn == NULL_RTX)
474 return;
476 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
478 if (insn == first_nonparm_insn)
479 in_nonparm_insns = 1;
481 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
483 /* Record what interesting things happen to our parameters. */
484 note_stores (PATTERN (insn), note_modified_parmregs, NULL);
486 /* If this is a CALL_PLACEHOLDER insn then we need to look into the
487 three attached sequences: normal call, sibling call and tail
488 recursion. */
489 if (GET_CODE (insn) == CALL_INSN
490 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
492 int i;
494 for (i = 0; i < 3; i++)
495 save_parm_insns (XEXP (PATTERN (insn), i),
496 first_nonparm_insn);
502 /* Note whether a parameter is modified or not. */
504 static void
505 note_modified_parmregs (reg, x, data)
506 rtx reg;
507 rtx x ATTRIBUTE_UNUSED;
508 void *data ATTRIBUTE_UNUSED;
510 if (GET_CODE (reg) == REG && in_nonparm_insns
511 && REGNO (reg) < max_parm_reg
512 && REGNO (reg) >= FIRST_PSEUDO_REGISTER
513 && parmdecl_map[REGNO (reg)] != 0)
514 TREE_READONLY (parmdecl_map[REGNO (reg)]) = 0;
517 /* Unfortunately, we need a global copy of const_equiv map for communication
518 with a function called from note_stores. Be *very* careful that this
519 is used properly in the presence of recursion. */
521 varray_type global_const_equiv_varray;
523 #define FIXED_BASE_PLUS_P(X) \
524 (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
525 && GET_CODE (XEXP (X, 0)) == REG \
526 && REGNO (XEXP (X, 0)) >= FIRST_VIRTUAL_REGISTER \
527 && REGNO (XEXP (X, 0)) <= LAST_VIRTUAL_REGISTER)
529 /* Called to set up a mapping for the case where a parameter is in a
530 register. If it is read-only and our argument is a constant, set up the
531 constant equivalence.
533 If LOC is REG_USERVAR_P, the usual case, COPY must also have that flag set
534 if it is a register.
536 Also, don't allow hard registers here; they might not be valid when
537 substituted into insns. */
538 static void
539 process_reg_param (map, loc, copy)
540 struct inline_remap *map;
541 rtx loc, copy;
543 if ((GET_CODE (copy) != REG && GET_CODE (copy) != SUBREG)
544 || (GET_CODE (copy) == REG && REG_USERVAR_P (loc)
545 && ! REG_USERVAR_P (copy))
546 || (GET_CODE (copy) == REG
547 && REGNO (copy) < FIRST_PSEUDO_REGISTER))
549 rtx temp = copy_to_mode_reg (GET_MODE (loc), copy);
550 REG_USERVAR_P (temp) = REG_USERVAR_P (loc);
551 if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
552 SET_CONST_EQUIV_DATA (map, temp, copy, CONST_AGE_PARM);
553 copy = temp;
555 map->reg_map[REGNO (loc)] = copy;
558 /* Used by duplicate_eh_handlers to map labels for the exception table */
559 static struct inline_remap *eif_eh_map;
561 static rtx
562 expand_inline_function_eh_labelmap (label)
563 rtx label;
565 int index = CODE_LABEL_NUMBER (label);
566 return get_label_from_map (eif_eh_map, index);
569 /* Compare two BLOCKs for qsort. The key we sort on is the
570 BLOCK_ABSTRACT_ORIGIN of the blocks. */
572 static int
573 compare_blocks (v1, v2)
574 const PTR v1;
575 const PTR v2;
577 tree b1 = *((const tree *) v1);
578 tree b2 = *((const tree *) v2);
580 return ((char *) BLOCK_ABSTRACT_ORIGIN (b1)
581 - (char *) BLOCK_ABSTRACT_ORIGIN (b2));
584 /* Compare two BLOCKs for bsearch. The first pointer corresponds to
585 an original block; the second to a remapped equivalent. */
587 static int
588 find_block (v1, v2)
589 const PTR v1;
590 const PTR v2;
592 const union tree_node *b1 = (const union tree_node *) v1;
593 tree b2 = *((const tree *) v2);
595 return ((const char *) b1 - (char *) BLOCK_ABSTRACT_ORIGIN (b2));
598 /* Integrate the procedure defined by FNDECL. Note that this function
599 may wind up calling itself. Since the static variables are not
600 reentrant, we do not assign them until after the possibility
601 of recursion is eliminated.
603 If IGNORE is nonzero, do not produce a value.
604 Otherwise store the value in TARGET if it is nonzero and that is convenient.
606 Value is:
607 (rtx)-1 if we could not substitute the function
608 0 if we substituted it and it does not produce a value
609 else an rtx for where the value is stored. */
612 expand_inline_function (fndecl, parms, target, ignore, type,
613 structure_value_addr)
614 tree fndecl, parms;
615 rtx target;
616 int ignore;
617 tree type;
618 rtx structure_value_addr;
620 struct function *inlining_previous;
621 struct function *inl_f = DECL_SAVED_INSNS (fndecl);
622 tree formal, actual, block;
623 rtx parm_insns = inl_f->emit->x_first_insn;
624 rtx insns = (inl_f->inl_last_parm_insn
625 ? NEXT_INSN (inl_f->inl_last_parm_insn)
626 : parm_insns);
627 tree *arg_trees;
628 rtx *arg_vals;
629 int max_regno;
630 register int i;
631 int min_labelno = inl_f->emit->x_first_label_num;
632 int max_labelno = inl_f->inl_max_label_num;
633 int nargs;
634 rtx loc;
635 rtx stack_save = 0;
636 rtx temp;
637 struct inline_remap *map = 0;
638 #ifdef HAVE_cc0
639 rtx cc0_insn = 0;
640 #endif
641 rtvec arg_vector = (rtvec) inl_f->original_arg_vector;
642 rtx static_chain_value = 0;
643 int inl_max_uid;
645 /* The pointer used to track the true location of the memory used
646 for MAP->LABEL_MAP. */
647 rtx *real_label_map = 0;
649 /* Allow for equivalences of the pseudos we make for virtual fp and ap. */
650 max_regno = inl_f->emit->x_reg_rtx_no + 3;
651 if (max_regno < FIRST_PSEUDO_REGISTER)
652 abort ();
654 nargs = list_length (DECL_ARGUMENTS (fndecl));
656 if (cfun->preferred_stack_boundary < inl_f->preferred_stack_boundary)
657 cfun->preferred_stack_boundary = inl_f->preferred_stack_boundary;
659 /* Check that the parms type match and that sufficient arguments were
660 passed. Since the appropriate conversions or default promotions have
661 already been applied, the machine modes should match exactly. */
663 for (formal = DECL_ARGUMENTS (fndecl), actual = parms;
664 formal;
665 formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual))
667 tree arg;
668 enum machine_mode mode;
670 if (actual == 0)
671 return (rtx) (HOST_WIDE_INT) -1;
673 arg = TREE_VALUE (actual);
674 mode = TYPE_MODE (DECL_ARG_TYPE (formal));
676 if (mode != TYPE_MODE (TREE_TYPE (arg))
677 /* If they are block mode, the types should match exactly.
678 They don't match exactly if TREE_TYPE (FORMAL) == ERROR_MARK_NODE,
679 which could happen if the parameter has incomplete type. */
680 || (mode == BLKmode
681 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg))
682 != TYPE_MAIN_VARIANT (TREE_TYPE (formal)))))
683 return (rtx) (HOST_WIDE_INT) -1;
686 /* Extra arguments are valid, but will be ignored below, so we must
687 evaluate them here for side-effects. */
688 for (; actual; actual = TREE_CHAIN (actual))
689 expand_expr (TREE_VALUE (actual), const0_rtx,
690 TYPE_MODE (TREE_TYPE (TREE_VALUE (actual))), 0);
692 /* Expand the function arguments. Do this first so that any
693 new registers get created before we allocate the maps. */
695 arg_vals = (rtx *) xmalloc (nargs * sizeof (rtx));
696 arg_trees = (tree *) xmalloc (nargs * sizeof (tree));
698 for (formal = DECL_ARGUMENTS (fndecl), actual = parms, i = 0;
699 formal;
700 formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual), i++)
702 /* Actual parameter, converted to the type of the argument within the
703 function. */
704 tree arg = convert (TREE_TYPE (formal), TREE_VALUE (actual));
705 /* Mode of the variable used within the function. */
706 enum machine_mode mode = TYPE_MODE (TREE_TYPE (formal));
707 int invisiref = 0;
709 arg_trees[i] = arg;
710 loc = RTVEC_ELT (arg_vector, i);
712 /* If this is an object passed by invisible reference, we copy the
713 object into a stack slot and save its address. If this will go
714 into memory, we do nothing now. Otherwise, we just expand the
715 argument. */
716 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
717 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
719 rtx stack_slot
720 = assign_stack_temp (TYPE_MODE (TREE_TYPE (arg)),
721 int_size_in_bytes (TREE_TYPE (arg)), 1);
722 MEM_SET_IN_STRUCT_P (stack_slot,
723 AGGREGATE_TYPE_P (TREE_TYPE (arg)));
725 store_expr (arg, stack_slot, 0);
727 arg_vals[i] = XEXP (stack_slot, 0);
728 invisiref = 1;
730 else if (GET_CODE (loc) != MEM)
732 if (GET_MODE (loc) != TYPE_MODE (TREE_TYPE (arg)))
733 /* The mode if LOC and ARG can differ if LOC was a variable
734 that had its mode promoted via PROMOTED_MODE. */
735 arg_vals[i] = convert_modes (GET_MODE (loc),
736 TYPE_MODE (TREE_TYPE (arg)),
737 expand_expr (arg, NULL_RTX, mode,
738 EXPAND_SUM),
739 TREE_UNSIGNED (TREE_TYPE (formal)));
740 else
741 arg_vals[i] = expand_expr (arg, NULL_RTX, mode, EXPAND_SUM);
743 else
744 arg_vals[i] = 0;
746 if (arg_vals[i] != 0
747 && (! TREE_READONLY (formal)
748 /* If the parameter is not read-only, copy our argument through
749 a register. Also, we cannot use ARG_VALS[I] if it overlaps
750 TARGET in any way. In the inline function, they will likely
751 be two different pseudos, and `safe_from_p' will make all
752 sorts of smart assumptions about their not conflicting.
753 But if ARG_VALS[I] overlaps TARGET, these assumptions are
754 wrong, so put ARG_VALS[I] into a fresh register.
755 Don't worry about invisible references, since their stack
756 temps will never overlap the target. */
757 || (target != 0
758 && ! invisiref
759 && (GET_CODE (arg_vals[i]) == REG
760 || GET_CODE (arg_vals[i]) == SUBREG
761 || GET_CODE (arg_vals[i]) == MEM)
762 && reg_overlap_mentioned_p (arg_vals[i], target))
763 /* ??? We must always copy a SUBREG into a REG, because it might
764 get substituted into an address, and not all ports correctly
765 handle SUBREGs in addresses. */
766 || (GET_CODE (arg_vals[i]) == SUBREG)))
767 arg_vals[i] = copy_to_mode_reg (GET_MODE (loc), arg_vals[i]);
769 if (arg_vals[i] != 0 && GET_CODE (arg_vals[i]) == REG
770 && POINTER_TYPE_P (TREE_TYPE (formal)))
771 mark_reg_pointer (arg_vals[i],
772 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (formal))));
775 /* Allocate the structures we use to remap things. */
777 map = (struct inline_remap *) xmalloc (sizeof (struct inline_remap));
778 map->fndecl = fndecl;
780 VARRAY_TREE_INIT (map->block_map, 10, "block_map");
781 map->reg_map = (rtx *) xcalloc (max_regno, sizeof (rtx));
783 /* We used to use alloca here, but the size of what it would try to
784 allocate would occasionally cause it to exceed the stack limit and
785 cause unpredictable core dumps. */
786 real_label_map
787 = (rtx *) xmalloc ((max_labelno) * sizeof (rtx));
788 map->label_map = real_label_map;
790 inl_max_uid = (inl_f->emit->x_cur_insn_uid + 1);
791 map->insn_map = (rtx *) xcalloc (inl_max_uid, sizeof (rtx));
792 map->min_insnno = 0;
793 map->max_insnno = inl_max_uid;
795 map->integrating = 1;
797 /* const_equiv_varray maps pseudos in our routine to constants, so
798 it needs to be large enough for all our pseudos. This is the
799 number we are currently using plus the number in the called
800 routine, plus 15 for each arg, five to compute the virtual frame
801 pointer, and five for the return value. This should be enough
802 for most cases. We do not reference entries outside the range of
803 the map.
805 ??? These numbers are quite arbitrary and were obtained by
806 experimentation. At some point, we should try to allocate the
807 table after all the parameters are set up so we an more accurately
808 estimate the number of pseudos we will need. */
810 VARRAY_CONST_EQUIV_INIT (map->const_equiv_varray,
811 (max_reg_num ()
812 + (max_regno - FIRST_PSEUDO_REGISTER)
813 + 15 * nargs
814 + 10),
815 "expand_inline_function");
816 map->const_age = 0;
818 /* Record the current insn in case we have to set up pointers to frame
819 and argument memory blocks. If there are no insns yet, add a dummy
820 insn that can be used as an insertion point. */
821 map->insns_at_start = get_last_insn ();
822 if (map->insns_at_start == 0)
823 map->insns_at_start = emit_note (NULL_PTR, NOTE_INSN_DELETED);
825 map->regno_pointer_flag = inl_f->emit->regno_pointer_flag;
826 map->regno_pointer_align = inl_f->emit->regno_pointer_align;
828 /* Update the outgoing argument size to allow for those in the inlined
829 function. */
830 if (inl_f->outgoing_args_size > current_function_outgoing_args_size)
831 current_function_outgoing_args_size = inl_f->outgoing_args_size;
833 /* If the inline function needs to make PIC references, that means
834 that this function's PIC offset table must be used. */
835 if (inl_f->uses_pic_offset_table)
836 current_function_uses_pic_offset_table = 1;
838 /* If this function needs a context, set it up. */
839 if (inl_f->needs_context)
840 static_chain_value = lookup_static_chain (fndecl);
842 if (GET_CODE (parm_insns) == NOTE
843 && NOTE_LINE_NUMBER (parm_insns) > 0)
845 rtx note = emit_note (NOTE_SOURCE_FILE (parm_insns),
846 NOTE_LINE_NUMBER (parm_insns));
847 if (note)
848 RTX_INTEGRATED_P (note) = 1;
851 /* Process each argument. For each, set up things so that the function's
852 reference to the argument will refer to the argument being passed.
853 We only replace REG with REG here. Any simplifications are done
854 via const_equiv_map.
856 We make two passes: In the first, we deal with parameters that will
857 be placed into registers, since we need to ensure that the allocated
858 register number fits in const_equiv_map. Then we store all non-register
859 parameters into their memory location. */
861 /* Don't try to free temp stack slots here, because we may put one of the
862 parameters into a temp stack slot. */
864 for (i = 0; i < nargs; i++)
866 rtx copy = arg_vals[i];
868 loc = RTVEC_ELT (arg_vector, i);
870 /* There are three cases, each handled separately. */
871 if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
872 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
874 /* This must be an object passed by invisible reference (it could
875 also be a variable-sized object, but we forbid inlining functions
876 with variable-sized arguments). COPY is the address of the
877 actual value (this computation will cause it to be copied). We
878 map that address for the register, noting the actual address as
879 an equivalent in case it can be substituted into the insns. */
881 if (GET_CODE (copy) != REG)
883 temp = copy_addr_to_reg (copy);
884 if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
885 SET_CONST_EQUIV_DATA (map, temp, copy, CONST_AGE_PARM);
886 copy = temp;
888 map->reg_map[REGNO (XEXP (loc, 0))] = copy;
890 else if (GET_CODE (loc) == MEM)
892 /* This is the case of a parameter that lives in memory. It
893 will live in the block we allocate in the called routine's
894 frame that simulates the incoming argument area. Do nothing
895 with the parameter now; we will call store_expr later. In
896 this case, however, we must ensure that the virtual stack and
897 incoming arg rtx values are expanded now so that we can be
898 sure we have enough slots in the const equiv map since the
899 store_expr call can easily blow the size estimate. */
900 if (DECL_FRAME_SIZE (fndecl) != 0)
901 copy_rtx_and_substitute (virtual_stack_vars_rtx, map, 0);
903 if (DECL_SAVED_INSNS (fndecl)->args_size != 0)
904 copy_rtx_and_substitute (virtual_incoming_args_rtx, map, 0);
906 else if (GET_CODE (loc) == REG)
907 process_reg_param (map, loc, copy);
908 else if (GET_CODE (loc) == CONCAT)
910 rtx locreal = gen_realpart (GET_MODE (XEXP (loc, 0)), loc);
911 rtx locimag = gen_imagpart (GET_MODE (XEXP (loc, 0)), loc);
912 rtx copyreal = gen_realpart (GET_MODE (locreal), copy);
913 rtx copyimag = gen_imagpart (GET_MODE (locimag), copy);
915 process_reg_param (map, locreal, copyreal);
916 process_reg_param (map, locimag, copyimag);
918 else
919 abort ();
922 /* Tell copy_rtx_and_substitute to handle constant pool SYMBOL_REFs
923 specially. This function can be called recursively, so we need to
924 save the previous value. */
925 inlining_previous = inlining;
926 inlining = inl_f;
928 /* Now do the parameters that will be placed in memory. */
930 for (formal = DECL_ARGUMENTS (fndecl), i = 0;
931 formal; formal = TREE_CHAIN (formal), i++)
933 loc = RTVEC_ELT (arg_vector, i);
935 if (GET_CODE (loc) == MEM
936 /* Exclude case handled above. */
937 && ! (GET_CODE (XEXP (loc, 0)) == REG
938 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER))
940 rtx note = emit_note (DECL_SOURCE_FILE (formal),
941 DECL_SOURCE_LINE (formal));
942 if (note)
943 RTX_INTEGRATED_P (note) = 1;
945 /* Compute the address in the area we reserved and store the
946 value there. */
947 temp = copy_rtx_and_substitute (loc, map, 1);
948 subst_constants (&temp, NULL_RTX, map, 1);
949 apply_change_group ();
950 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
951 temp = change_address (temp, VOIDmode, XEXP (temp, 0));
952 store_expr (arg_trees[i], temp, 0);
956 /* Deal with the places that the function puts its result.
957 We are driven by what is placed into DECL_RESULT.
959 Initially, we assume that we don't have anything special handling for
960 REG_FUNCTION_RETURN_VALUE_P. */
962 map->inline_target = 0;
963 loc = DECL_RTL (DECL_RESULT (fndecl));
965 if (TYPE_MODE (type) == VOIDmode)
966 /* There is no return value to worry about. */
968 else if (GET_CODE (loc) == MEM)
970 if (GET_CODE (XEXP (loc, 0)) == ADDRESSOF)
972 temp = copy_rtx_and_substitute (loc, map, 1);
973 subst_constants (&temp, NULL_RTX, map, 1);
974 apply_change_group ();
975 target = temp;
977 else
979 if (! structure_value_addr
980 || ! aggregate_value_p (DECL_RESULT (fndecl)))
981 abort ();
983 /* Pass the function the address in which to return a structure
984 value. Note that a constructor can cause someone to call us
985 with STRUCTURE_VALUE_ADDR, but the initialization takes place
986 via the first parameter, rather than the struct return address.
988 We have two cases: If the address is a simple register
989 indirect, use the mapping mechanism to point that register to
990 our structure return address. Otherwise, store the structure
991 return value into the place that it will be referenced from. */
993 if (GET_CODE (XEXP (loc, 0)) == REG)
995 temp = force_operand (structure_value_addr, NULL_RTX);
996 temp = force_reg (Pmode, temp);
997 map->reg_map[REGNO (XEXP (loc, 0))] = temp;
999 if (CONSTANT_P (structure_value_addr)
1000 || GET_CODE (structure_value_addr) == ADDRESSOF
1001 || (GET_CODE (structure_value_addr) == PLUS
1002 && (XEXP (structure_value_addr, 0)
1003 == virtual_stack_vars_rtx)
1004 && (GET_CODE (XEXP (structure_value_addr, 1))
1005 == CONST_INT)))
1007 SET_CONST_EQUIV_DATA (map, temp, structure_value_addr,
1008 CONST_AGE_PARM);
1011 else
1013 temp = copy_rtx_and_substitute (loc, map, 1);
1014 subst_constants (&temp, NULL_RTX, map, 0);
1015 apply_change_group ();
1016 emit_move_insn (temp, structure_value_addr);
1020 else if (ignore)
1021 /* We will ignore the result value, so don't look at its structure.
1022 Note that preparations for an aggregate return value
1023 do need to be made (above) even if it will be ignored. */
1025 else if (GET_CODE (loc) == REG)
1027 /* The function returns an object in a register and we use the return
1028 value. Set up our target for remapping. */
1030 /* Machine mode function was declared to return. */
1031 enum machine_mode departing_mode = TYPE_MODE (type);
1032 /* (Possibly wider) machine mode it actually computes
1033 (for the sake of callers that fail to declare it right).
1034 We have to use the mode of the result's RTL, rather than
1035 its type, since expand_function_start may have promoted it. */
1036 enum machine_mode arriving_mode
1037 = GET_MODE (DECL_RTL (DECL_RESULT (fndecl)));
1038 rtx reg_to_map;
1040 /* Don't use MEMs as direct targets because on some machines
1041 substituting a MEM for a REG makes invalid insns.
1042 Let the combiner substitute the MEM if that is valid. */
1043 if (target == 0 || GET_CODE (target) != REG
1044 || GET_MODE (target) != departing_mode)
1046 /* Don't make BLKmode registers. If this looks like
1047 a BLKmode object being returned in a register, get
1048 the mode from that, otherwise abort. */
1049 if (departing_mode == BLKmode)
1051 if (REG == GET_CODE (DECL_RTL (DECL_RESULT (fndecl))))
1053 departing_mode = GET_MODE (DECL_RTL (DECL_RESULT (fndecl)));
1054 arriving_mode = departing_mode;
1056 else
1057 abort();
1060 target = gen_reg_rtx (departing_mode);
1063 /* If function's value was promoted before return,
1064 avoid machine mode mismatch when we substitute INLINE_TARGET.
1065 But TARGET is what we will return to the caller. */
1066 if (arriving_mode != departing_mode)
1068 /* Avoid creating a paradoxical subreg wider than
1069 BITS_PER_WORD, since that is illegal. */
1070 if (GET_MODE_BITSIZE (arriving_mode) > BITS_PER_WORD)
1072 if (!TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (departing_mode),
1073 GET_MODE_BITSIZE (arriving_mode)))
1074 /* Maybe could be handled by using convert_move () ? */
1075 abort ();
1076 reg_to_map = gen_reg_rtx (arriving_mode);
1077 target = gen_lowpart (departing_mode, reg_to_map);
1079 else
1080 reg_to_map = gen_rtx_SUBREG (arriving_mode, target, 0);
1082 else
1083 reg_to_map = target;
1085 /* Usually, the result value is the machine's return register.
1086 Sometimes it may be a pseudo. Handle both cases. */
1087 if (REG_FUNCTION_VALUE_P (loc))
1088 map->inline_target = reg_to_map;
1089 else
1090 map->reg_map[REGNO (loc)] = reg_to_map;
1092 else
1093 abort ();
1095 /* Initialize label_map. get_label_from_map will actually make
1096 the labels. */
1097 bzero ((char *) &map->label_map [min_labelno],
1098 (max_labelno - min_labelno) * sizeof (rtx));
1100 /* Make copies of the decls of the symbols in the inline function, so that
1101 the copies of the variables get declared in the current function. Set
1102 up things so that lookup_static_chain knows that to interpret registers
1103 in SAVE_EXPRs for TYPE_SIZEs as local. */
1104 inline_function_decl = fndecl;
1105 integrate_parm_decls (DECL_ARGUMENTS (fndecl), map, arg_vector);
1106 block = integrate_decl_tree (inl_f->original_decl_initial, map);
1107 BLOCK_ABSTRACT_ORIGIN (block) = DECL_ORIGIN (fndecl);
1108 inline_function_decl = 0;
1110 /* Make a fresh binding contour that we can easily remove. Do this after
1111 expanding our arguments so cleanups are properly scoped. */
1112 expand_start_bindings_and_block (0, block);
1114 /* Sort the block-map so that it will be easy to find remapped
1115 blocks later. */
1116 qsort (&VARRAY_TREE (map->block_map, 0),
1117 map->block_map->elements_used,
1118 sizeof (tree),
1119 compare_blocks);
1121 /* Perform postincrements before actually calling the function. */
1122 emit_queue ();
1124 /* Clean up stack so that variables might have smaller offsets. */
1125 do_pending_stack_adjust ();
1127 /* Save a copy of the location of const_equiv_varray for
1128 mark_stores, called via note_stores. */
1129 global_const_equiv_varray = map->const_equiv_varray;
1131 /* If the called function does an alloca, save and restore the
1132 stack pointer around the call. This saves stack space, but
1133 also is required if this inline is being done between two
1134 pushes. */
1135 if (inl_f->calls_alloca)
1136 emit_stack_save (SAVE_BLOCK, &stack_save, NULL_RTX);
1138 /* Now copy the insns one by one. */
1139 copy_insn_list (insns, map, static_chain_value);
1141 /* Restore the stack pointer if we saved it above. */
1142 if (inl_f->calls_alloca)
1143 emit_stack_restore (SAVE_BLOCK, stack_save, NULL_RTX);
1145 if (! cfun->x_whole_function_mode_p)
1146 /* In statement-at-a-time mode, we just tell the front-end to add
1147 this block to the list of blocks at this binding level. We
1148 can't do it the way it's done for function-at-a-time mode the
1149 superblocks have not been created yet. */
1150 insert_block (block);
1151 else
1153 BLOCK_CHAIN (block)
1154 = BLOCK_CHAIN (DECL_INITIAL (current_function_decl));
1155 BLOCK_CHAIN (DECL_INITIAL (current_function_decl)) = block;
1158 /* End the scope containing the copied formal parameter variables
1159 and copied LABEL_DECLs. We pass NULL_TREE for the variables list
1160 here so that expand_end_bindings will not check for unused
1161 variables. That's already been checked for when the inlined
1162 function was defined. */
1163 expand_end_bindings (NULL_TREE, 1, 1);
1165 /* Must mark the line number note after inlined functions as a repeat, so
1166 that the test coverage code can avoid counting the call twice. This
1167 just tells the code to ignore the immediately following line note, since
1168 there already exists a copy of this note before the expanded inline call.
1169 This line number note is still needed for debugging though, so we can't
1170 delete it. */
1171 if (flag_test_coverage)
1172 emit_note (0, NOTE_INSN_REPEATED_LINE_NUMBER);
1174 emit_line_note (input_filename, lineno);
1176 /* If the function returns a BLKmode object in a register, copy it
1177 out of the temp register into a BLKmode memory object. */
1178 if (target
1179 && TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == BLKmode
1180 && ! aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl))))
1181 target = copy_blkmode_from_reg (0, target, TREE_TYPE (TREE_TYPE (fndecl)));
1183 if (structure_value_addr)
1185 target = gen_rtx_MEM (TYPE_MODE (type),
1186 memory_address (TYPE_MODE (type),
1187 structure_value_addr));
1188 MEM_SET_IN_STRUCT_P (target, 1);
1191 /* Make sure we free the things we explicitly allocated with xmalloc. */
1192 if (real_label_map)
1193 free (real_label_map);
1194 VARRAY_FREE (map->const_equiv_varray);
1195 free (map->reg_map);
1196 VARRAY_FREE (map->block_map);
1197 free (map->insn_map);
1198 free (map);
1199 free (arg_vals);
1200 free (arg_trees);
1202 inlining = inlining_previous;
1204 return target;
1207 /* Make copies of each insn in the given list using the mapping
1208 computed in expand_inline_function. This function may call itself for
1209 insns containing sequences.
1211 Copying is done in two passes, first the insns and then their REG_NOTES,
1212 just like save_for_inline.
1214 If static_chain_value is non-zero, it represents the context-pointer
1215 register for the function. */
1217 static void
1218 copy_insn_list (insns, map, static_chain_value)
1219 rtx insns;
1220 struct inline_remap *map;
1221 rtx static_chain_value;
1223 register int i;
1224 rtx insn;
1225 rtx temp;
1226 rtx local_return_label = NULL_RTX;
1227 #ifdef HAVE_cc0
1228 rtx cc0_insn = 0;
1229 #endif
1231 /* Copy the insns one by one. Do this in two passes, first the insns and
1232 then their REG_NOTES, just like save_for_inline. */
1234 /* This loop is very similar to the loop in copy_loop_body in unroll.c. */
1236 for (insn = insns; insn; insn = NEXT_INSN (insn))
1238 rtx copy, pattern, set;
1240 map->orig_asm_operands_vector = 0;
1242 switch (GET_CODE (insn))
1244 case INSN:
1245 pattern = PATTERN (insn);
1246 set = single_set (insn);
1247 copy = 0;
1248 if (GET_CODE (pattern) == USE
1249 && GET_CODE (XEXP (pattern, 0)) == REG
1250 && REG_FUNCTION_VALUE_P (XEXP (pattern, 0)))
1251 /* The (USE (REG n)) at return from the function should
1252 be ignored since we are changing (REG n) into
1253 inline_target. */
1254 break;
1256 /* If the inline fn needs eh context, make sure that
1257 the current fn has one. */
1258 if (GET_CODE (pattern) == USE
1259 && find_reg_note (insn, REG_EH_CONTEXT, 0) != 0)
1260 get_eh_context ();
1262 /* Ignore setting a function value that we don't want to use. */
1263 if (map->inline_target == 0
1264 && set != 0
1265 && GET_CODE (SET_DEST (set)) == REG
1266 && REG_FUNCTION_VALUE_P (SET_DEST (set)))
1268 if (volatile_refs_p (SET_SRC (set)))
1270 rtx new_set;
1272 /* If we must not delete the source,
1273 load it into a new temporary. */
1274 copy = emit_insn (copy_rtx_and_substitute (pattern, map, 0));
1276 new_set = single_set (copy);
1277 if (new_set == 0)
1278 abort ();
1280 SET_DEST (new_set)
1281 = gen_reg_rtx (GET_MODE (SET_DEST (new_set)));
1283 /* If the source and destination are the same and it
1284 has a note on it, keep the insn. */
1285 else if (rtx_equal_p (SET_DEST (set), SET_SRC (set))
1286 && REG_NOTES (insn) != 0)
1287 copy = emit_insn (copy_rtx_and_substitute (pattern, map, 0));
1288 else
1289 break;
1292 /* If this is setting the static chain rtx, omit it. */
1293 else if (static_chain_value != 0
1294 && set != 0
1295 && GET_CODE (SET_DEST (set)) == REG
1296 && rtx_equal_p (SET_DEST (set),
1297 static_chain_incoming_rtx))
1298 break;
1300 /* If this is setting the static chain pseudo, set it from
1301 the value we want to give it instead. */
1302 else if (static_chain_value != 0
1303 && set != 0
1304 && rtx_equal_p (SET_SRC (set),
1305 static_chain_incoming_rtx))
1307 rtx newdest = copy_rtx_and_substitute (SET_DEST (set), map, 1);
1309 copy = emit_move_insn (newdest, static_chain_value);
1310 static_chain_value = 0;
1313 /* If this is setting the virtual stack vars register, this must
1314 be the code at the handler for a builtin longjmp. The value
1315 saved in the setjmp buffer will be the address of the frame
1316 we've made for this inlined instance within our frame. But we
1317 know the offset of that value so we can use it to reconstruct
1318 our virtual stack vars register from that value. If we are
1319 copying it from the stack pointer, leave it unchanged. */
1320 else if (set != 0
1321 && rtx_equal_p (SET_DEST (set), virtual_stack_vars_rtx))
1323 HOST_WIDE_INT offset;
1324 temp = map->reg_map[REGNO (SET_DEST (set))];
1325 temp = VARRAY_CONST_EQUIV (map->const_equiv_varray,
1326 REGNO (temp)).rtx;
1328 if (rtx_equal_p (temp, virtual_stack_vars_rtx))
1329 offset = 0;
1330 else if (GET_CODE (temp) == PLUS
1331 && rtx_equal_p (XEXP (temp, 0), virtual_stack_vars_rtx)
1332 && GET_CODE (XEXP (temp, 1)) == CONST_INT)
1333 offset = INTVAL (XEXP (temp, 1));
1334 else
1335 abort ();
1337 if (rtx_equal_p (SET_SRC (set), stack_pointer_rtx))
1338 temp = SET_SRC (set);
1339 else
1340 temp = force_operand (plus_constant (SET_SRC (set),
1341 - offset),
1342 NULL_RTX);
1344 copy = emit_move_insn (virtual_stack_vars_rtx, temp);
1347 else
1348 copy = emit_insn (copy_rtx_and_substitute (pattern, map, 0));
1349 /* REG_NOTES will be copied later. */
1351 #ifdef HAVE_cc0
1352 /* If this insn is setting CC0, it may need to look at
1353 the insn that uses CC0 to see what type of insn it is.
1354 In that case, the call to recog via validate_change will
1355 fail. So don't substitute constants here. Instead,
1356 do it when we emit the following insn.
1358 For example, see the pyr.md file. That machine has signed and
1359 unsigned compares. The compare patterns must check the
1360 following branch insn to see which what kind of compare to
1361 emit.
1363 If the previous insn set CC0, substitute constants on it as
1364 well. */
1365 if (sets_cc0_p (PATTERN (copy)) != 0)
1366 cc0_insn = copy;
1367 else
1369 if (cc0_insn)
1370 try_constants (cc0_insn, map);
1371 cc0_insn = 0;
1372 try_constants (copy, map);
1374 #else
1375 try_constants (copy, map);
1376 #endif
1377 break;
1379 case JUMP_INSN:
1380 if (GET_CODE (PATTERN (insn)) == RETURN
1381 || (GET_CODE (PATTERN (insn)) == PARALLEL
1382 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN))
1384 if (local_return_label == 0)
1385 local_return_label = gen_label_rtx ();
1386 pattern = gen_jump (local_return_label);
1388 else
1389 pattern = copy_rtx_and_substitute (PATTERN (insn), map, 0);
1391 copy = emit_jump_insn (pattern);
1393 #ifdef HAVE_cc0
1394 if (cc0_insn)
1395 try_constants (cc0_insn, map);
1396 cc0_insn = 0;
1397 #endif
1398 try_constants (copy, map);
1400 /* If this used to be a conditional jump insn but whose branch
1401 direction is now know, we must do something special. */
1402 if (condjump_p (insn) && ! simplejump_p (insn) && map->last_pc_value)
1404 #ifdef HAVE_cc0
1405 /* If the previous insn set cc0 for us, delete it. */
1406 if (sets_cc0_p (PREV_INSN (copy)))
1407 delete_insn (PREV_INSN (copy));
1408 #endif
1410 /* If this is now a no-op, delete it. */
1411 if (map->last_pc_value == pc_rtx)
1413 delete_insn (copy);
1414 copy = 0;
1416 else
1417 /* Otherwise, this is unconditional jump so we must put a
1418 BARRIER after it. We could do some dead code elimination
1419 here, but jump.c will do it just as well. */
1420 emit_barrier ();
1422 break;
1424 case CALL_INSN:
1425 /* If this is a CALL_PLACEHOLDER insn then we need to copy the
1426 three attached sequences: normal call, sibling call and tail
1427 recursion. */
1428 if (GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
1430 rtx sequence[3];
1431 rtx tail_label;
1433 for (i = 0; i < 3; i++)
1435 rtx seq;
1437 sequence[i] = NULL_RTX;
1438 seq = XEXP (PATTERN (insn), i);
1439 if (seq)
1441 start_sequence ();
1442 copy_insn_list (seq, map, static_chain_value);
1443 sequence[i] = get_insns ();
1444 end_sequence ();
1448 /* Find the new tail recursion label.
1449 It will already be substituted into sequence[2]. */
1450 tail_label = copy_rtx_and_substitute (XEXP (PATTERN (insn), 3),
1451 map, 0);
1453 copy = emit_call_insn (gen_rtx_CALL_PLACEHOLDER (VOIDmode,
1454 sequence[0],
1455 sequence[1],
1456 sequence[2],
1457 tail_label));
1458 break;
1461 pattern = copy_rtx_and_substitute (PATTERN (insn), map, 0);
1462 copy = emit_call_insn (pattern);
1464 SIBLING_CALL_P (copy) = SIBLING_CALL_P (insn);
1466 /* Because the USAGE information potentially contains objects other
1467 than hard registers, we need to copy it. */
1469 CALL_INSN_FUNCTION_USAGE (copy)
1470 = copy_rtx_and_substitute (CALL_INSN_FUNCTION_USAGE (insn),
1471 map, 0);
1473 #ifdef HAVE_cc0
1474 if (cc0_insn)
1475 try_constants (cc0_insn, map);
1476 cc0_insn = 0;
1477 #endif
1478 try_constants (copy, map);
1480 /* Be lazy and assume CALL_INSNs clobber all hard registers. */
1481 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1482 VARRAY_CONST_EQUIV (map->const_equiv_varray, i).rtx = 0;
1483 break;
1485 case CODE_LABEL:
1486 copy = emit_label (get_label_from_map (map,
1487 CODE_LABEL_NUMBER (insn)));
1488 LABEL_NAME (copy) = LABEL_NAME (insn);
1489 map->const_age++;
1490 break;
1492 case BARRIER:
1493 copy = emit_barrier ();
1494 break;
1496 case NOTE:
1497 /* NOTE_INSN_FUNCTION_END and NOTE_INSN_FUNCTION_BEG are
1498 discarded because it is important to have only one of
1499 each in the current function.
1501 NOTE_INSN_DELETED notes aren't useful (save_for_inline
1502 deleted these in the copy used for continuing compilation,
1503 not the copy used for inlining).
1505 NOTE_INSN_BASIC_BLOCK is discarded because the saved bb
1506 pointer (which will soon be dangling) confuses flow's
1507 attempts to preserve bb structures during the compilation
1508 of a function. */
1510 if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END
1511 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_BEG
1512 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
1513 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK)
1515 copy = emit_note (NOTE_SOURCE_FILE (insn),
1516 NOTE_LINE_NUMBER (insn));
1517 if (copy
1518 && (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG
1519 || NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_END))
1521 rtx label
1522 = get_label_from_map (map, NOTE_EH_HANDLER (copy));
1524 /* we have to duplicate the handlers for the original */
1525 if (NOTE_LINE_NUMBER (copy) == NOTE_INSN_EH_REGION_BEG)
1527 /* We need to duplicate the handlers for the EH region
1528 and we need to indicate where the label map is */
1529 eif_eh_map = map;
1530 duplicate_eh_handlers (NOTE_EH_HANDLER (copy),
1531 CODE_LABEL_NUMBER (label),
1532 expand_inline_function_eh_labelmap);
1535 /* We have to forward these both to match the new exception
1536 region. */
1537 NOTE_EH_HANDLER (copy) = CODE_LABEL_NUMBER (label);
1539 else if (copy
1540 && (NOTE_LINE_NUMBER (copy) == NOTE_INSN_BLOCK_BEG
1541 || NOTE_LINE_NUMBER (copy) == NOTE_INSN_BLOCK_END)
1542 && NOTE_BLOCK (insn))
1544 tree *mapped_block_p;
1546 mapped_block_p
1547 = (tree *) bsearch (NOTE_BLOCK (insn),
1548 &VARRAY_TREE (map->block_map, 0),
1549 map->block_map->elements_used,
1550 sizeof (tree),
1551 find_block);
1553 if (!mapped_block_p)
1554 abort ();
1555 else
1556 NOTE_BLOCK (copy) = *mapped_block_p;
1559 else
1560 copy = 0;
1561 break;
1563 default:
1564 abort ();
1567 if (copy)
1568 RTX_INTEGRATED_P (copy) = 1;
1570 map->insn_map[INSN_UID (insn)] = copy;
1573 /* Now copy the REG_NOTES. Increment const_age, so that only constants
1574 from parameters can be substituted in. These are the only ones that
1575 are valid across the entire function. */
1576 map->const_age++;
1577 for (insn = insns; insn; insn = NEXT_INSN (insn))
1578 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
1579 && map->insn_map[INSN_UID (insn)]
1580 && REG_NOTES (insn))
1582 rtx tem = copy_rtx_and_substitute (REG_NOTES (insn), map, 0);
1584 /* We must also do subst_constants, in case one of our parameters
1585 has const type and constant value. */
1586 subst_constants (&tem, NULL_RTX, map, 0);
1587 apply_change_group ();
1588 REG_NOTES (map->insn_map[INSN_UID (insn)]) = tem;
1591 if (local_return_label)
1592 emit_label (local_return_label);
1595 /* Given a chain of PARM_DECLs, ARGS, copy each decl into a VAR_DECL,
1596 push all of those decls and give each one the corresponding home. */
1598 static void
1599 integrate_parm_decls (args, map, arg_vector)
1600 tree args;
1601 struct inline_remap *map;
1602 rtvec arg_vector;
1604 register tree tail;
1605 register int i;
1607 for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
1609 tree decl = copy_decl_for_inlining (tail, map->fndecl,
1610 current_function_decl);
1611 rtx new_decl_rtl
1612 = copy_rtx_and_substitute (RTVEC_ELT (arg_vector, i), map, 1);
1614 /* We really should be setting DECL_INCOMING_RTL to something reasonable
1615 here, but that's going to require some more work. */
1616 /* DECL_INCOMING_RTL (decl) = ?; */
1617 /* Fully instantiate the address with the equivalent form so that the
1618 debugging information contains the actual register, instead of the
1619 virtual register. Do this by not passing an insn to
1620 subst_constants. */
1621 subst_constants (&new_decl_rtl, NULL_RTX, map, 1);
1622 apply_change_group ();
1623 DECL_RTL (decl) = new_decl_rtl;
1627 /* Given a BLOCK node LET, push decls and levels so as to construct in the
1628 current function a tree of contexts isomorphic to the one that is given.
1630 MAP, if nonzero, is a pointer to an inline_remap map which indicates how
1631 registers used in the DECL_RTL field should be remapped. If it is zero,
1632 no mapping is necessary. */
1634 static tree
1635 integrate_decl_tree (let, map)
1636 tree let;
1637 struct inline_remap *map;
1639 tree t;
1640 tree new_block;
1641 tree *next;
1643 new_block = make_node (BLOCK);
1644 VARRAY_PUSH_TREE (map->block_map, new_block);
1645 next = &BLOCK_VARS (new_block);
1647 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
1649 tree d;
1651 push_obstacks_nochange ();
1652 saveable_allocation ();
1653 d = copy_decl_for_inlining (t, map->fndecl, current_function_decl);
1654 pop_obstacks ();
1656 if (DECL_RTL (t) != 0)
1658 DECL_RTL (d) = copy_rtx_and_substitute (DECL_RTL (t), map, 1);
1660 /* Fully instantiate the address with the equivalent form so that the
1661 debugging information contains the actual register, instead of the
1662 virtual register. Do this by not passing an insn to
1663 subst_constants. */
1664 subst_constants (&DECL_RTL (d), NULL_RTX, map, 1);
1665 apply_change_group ();
1668 /* Add this declaration to the list of variables in the new
1669 block. */
1670 *next = d;
1671 next = &TREE_CHAIN (d);
1674 next = &BLOCK_SUBBLOCKS (new_block);
1675 for (t = BLOCK_SUBBLOCKS (let); t; t = BLOCK_CHAIN (t))
1677 *next = integrate_decl_tree (t, map);
1678 BLOCK_SUPERCONTEXT (*next) = new_block;
1679 next = &BLOCK_CHAIN (*next);
1682 TREE_USED (new_block) = TREE_USED (let);
1683 BLOCK_ABSTRACT_ORIGIN (new_block) = let;
1685 return new_block;
1688 /* Create a new copy of an rtx. Recursively copies the operands of the rtx,
1689 except for those few rtx codes that are sharable.
1691 We always return an rtx that is similar to that incoming rtx, with the
1692 exception of possibly changing a REG to a SUBREG or vice versa. No
1693 rtl is ever emitted.
1695 If FOR_LHS is nonzero, if means we are processing something that will
1696 be the LHS of a SET. In that case, we copy RTX_UNCHANGING_P even if
1697 inlining since we need to be conservative in how it is set for
1698 such cases.
1700 Handle constants that need to be placed in the constant pool by
1701 calling `force_const_mem'. */
1704 copy_rtx_and_substitute (orig, map, for_lhs)
1705 register rtx orig;
1706 struct inline_remap *map;
1707 int for_lhs;
1709 register rtx copy, temp;
1710 register int i, j;
1711 register RTX_CODE code;
1712 register enum machine_mode mode;
1713 register const char *format_ptr;
1714 int regno;
1716 if (orig == 0)
1717 return 0;
1719 code = GET_CODE (orig);
1720 mode = GET_MODE (orig);
1722 switch (code)
1724 case REG:
1725 /* If the stack pointer register shows up, it must be part of
1726 stack-adjustments (*not* because we eliminated the frame pointer!).
1727 Small hard registers are returned as-is. Pseudo-registers
1728 go through their `reg_map'. */
1729 regno = REGNO (orig);
1730 if (regno <= LAST_VIRTUAL_REGISTER
1731 || (map->integrating
1732 && DECL_SAVED_INSNS (map->fndecl)->internal_arg_pointer == orig))
1734 /* Some hard registers are also mapped,
1735 but others are not translated. */
1736 if (map->reg_map[regno] != 0)
1737 return map->reg_map[regno];
1739 /* If this is the virtual frame pointer, make space in current
1740 function's stack frame for the stack frame of the inline function.
1742 Copy the address of this area into a pseudo. Map
1743 virtual_stack_vars_rtx to this pseudo and set up a constant
1744 equivalence for it to be the address. This will substitute the
1745 address into insns where it can be substituted and use the new
1746 pseudo where it can't. */
1747 if (regno == VIRTUAL_STACK_VARS_REGNUM)
1749 rtx loc, seq;
1750 int size = get_func_frame_size (DECL_SAVED_INSNS (map->fndecl));
1751 #ifdef FRAME_GROWS_DOWNWARD
1752 int alignment
1753 = (DECL_SAVED_INSNS (map->fndecl)->stack_alignment_needed
1754 / BITS_PER_UNIT);
1756 /* In this case, virtual_stack_vars_rtx points to one byte
1757 higher than the top of the frame area. So make sure we
1758 allocate a big enough chunk to keep the frame pointer
1759 aligned like a real one. */
1760 if (alignment)
1761 size = CEIL_ROUND (size, alignment);
1762 #endif
1763 start_sequence ();
1764 loc = assign_stack_temp (BLKmode, size, 1);
1765 loc = XEXP (loc, 0);
1766 #ifdef FRAME_GROWS_DOWNWARD
1767 /* In this case, virtual_stack_vars_rtx points to one byte
1768 higher than the top of the frame area. So compute the offset
1769 to one byte higher than our substitute frame. */
1770 loc = plus_constant (loc, size);
1771 #endif
1772 map->reg_map[regno] = temp
1773 = force_reg (Pmode, force_operand (loc, NULL_RTX));
1775 #ifdef STACK_BOUNDARY
1776 mark_reg_pointer (map->reg_map[regno], STACK_BOUNDARY);
1777 #endif
1779 SET_CONST_EQUIV_DATA (map, temp, loc, CONST_AGE_PARM);
1781 seq = gen_sequence ();
1782 end_sequence ();
1783 emit_insn_after (seq, map->insns_at_start);
1784 return temp;
1786 else if (regno == VIRTUAL_INCOMING_ARGS_REGNUM
1787 || (map->integrating
1788 && (DECL_SAVED_INSNS (map->fndecl)->internal_arg_pointer
1789 == orig)))
1791 /* Do the same for a block to contain any arguments referenced
1792 in memory. */
1793 rtx loc, seq;
1794 int size = DECL_SAVED_INSNS (map->fndecl)->args_size;
1796 start_sequence ();
1797 loc = assign_stack_temp (BLKmode, size, 1);
1798 loc = XEXP (loc, 0);
1799 /* When arguments grow downward, the virtual incoming
1800 args pointer points to the top of the argument block,
1801 so the remapped location better do the same. */
1802 #ifdef ARGS_GROW_DOWNWARD
1803 loc = plus_constant (loc, size);
1804 #endif
1805 map->reg_map[regno] = temp
1806 = force_reg (Pmode, force_operand (loc, NULL_RTX));
1808 #ifdef STACK_BOUNDARY
1809 mark_reg_pointer (map->reg_map[regno], STACK_BOUNDARY);
1810 #endif
1812 SET_CONST_EQUIV_DATA (map, temp, loc, CONST_AGE_PARM);
1814 seq = gen_sequence ();
1815 end_sequence ();
1816 emit_insn_after (seq, map->insns_at_start);
1817 return temp;
1819 else if (REG_FUNCTION_VALUE_P (orig))
1821 /* This is a reference to the function return value. If
1822 the function doesn't have a return value, error. If the
1823 mode doesn't agree, and it ain't BLKmode, make a SUBREG. */
1824 if (map->inline_target == 0)
1825 /* Must be unrolling loops or replicating code if we
1826 reach here, so return the register unchanged. */
1827 return orig;
1828 else if (GET_MODE (map->inline_target) != BLKmode
1829 && mode != GET_MODE (map->inline_target))
1830 return gen_lowpart (mode, map->inline_target);
1831 else
1832 return map->inline_target;
1834 return orig;
1836 if (map->reg_map[regno] == NULL)
1838 map->reg_map[regno] = gen_reg_rtx (mode);
1839 REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (orig);
1840 REG_LOOP_TEST_P (map->reg_map[regno]) = REG_LOOP_TEST_P (orig);
1841 RTX_UNCHANGING_P (map->reg_map[regno]) = RTX_UNCHANGING_P (orig);
1842 /* A reg with REG_FUNCTION_VALUE_P true will never reach here. */
1844 if (map->regno_pointer_flag[regno])
1845 mark_reg_pointer (map->reg_map[regno],
1846 map->regno_pointer_align[regno]);
1848 return map->reg_map[regno];
1850 case SUBREG:
1851 copy = copy_rtx_and_substitute (SUBREG_REG (orig), map, for_lhs);
1852 /* SUBREG is ordinary, but don't make nested SUBREGs. */
1853 if (GET_CODE (copy) == SUBREG)
1854 return gen_rtx_SUBREG (GET_MODE (orig), SUBREG_REG (copy),
1855 SUBREG_WORD (orig) + SUBREG_WORD (copy));
1856 else if (GET_CODE (copy) == CONCAT)
1858 rtx retval = subreg_realpart_p (orig) ? XEXP (copy, 0) : XEXP (copy, 1);
1860 if (GET_MODE (retval) == GET_MODE (orig))
1861 return retval;
1862 else
1863 return gen_rtx_SUBREG (GET_MODE (orig), retval,
1864 (SUBREG_WORD (orig) %
1865 (GET_MODE_UNIT_SIZE (GET_MODE (SUBREG_REG (orig)))
1866 / (unsigned) UNITS_PER_WORD)));
1868 else
1869 return gen_rtx_SUBREG (GET_MODE (orig), copy,
1870 SUBREG_WORD (orig));
1872 case ADDRESSOF:
1873 copy = gen_rtx_ADDRESSOF (mode,
1874 copy_rtx_and_substitute (XEXP (orig, 0),
1875 map, for_lhs),
1876 0, ADDRESSOF_DECL(orig));
1877 regno = ADDRESSOF_REGNO (orig);
1878 if (map->reg_map[regno])
1879 regno = REGNO (map->reg_map[regno]);
1880 else if (regno > LAST_VIRTUAL_REGISTER)
1882 temp = XEXP (orig, 0);
1883 map->reg_map[regno] = gen_reg_rtx (GET_MODE (temp));
1884 REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (temp);
1885 REG_LOOP_TEST_P (map->reg_map[regno]) = REG_LOOP_TEST_P (temp);
1886 RTX_UNCHANGING_P (map->reg_map[regno]) = RTX_UNCHANGING_P (temp);
1887 /* A reg with REG_FUNCTION_VALUE_P true will never reach here. */
1889 if (map->regno_pointer_flag[regno])
1890 mark_reg_pointer (map->reg_map[regno],
1891 map->regno_pointer_align[regno]);
1892 regno = REGNO (map->reg_map[regno]);
1894 ADDRESSOF_REGNO (copy) = regno;
1895 return copy;
1897 case USE:
1898 case CLOBBER:
1899 /* USE and CLOBBER are ordinary, but we convert (use (subreg foo))
1900 to (use foo) if the original insn didn't have a subreg.
1901 Removing the subreg distorts the VAX movstrhi pattern
1902 by changing the mode of an operand. */
1903 copy = copy_rtx_and_substitute (XEXP (orig, 0), map, code == CLOBBER);
1904 if (GET_CODE (copy) == SUBREG && GET_CODE (XEXP (orig, 0)) != SUBREG)
1905 copy = SUBREG_REG (copy);
1906 return gen_rtx_fmt_e (code, VOIDmode, copy);
1908 case CODE_LABEL:
1909 LABEL_PRESERVE_P (get_label_from_map (map, CODE_LABEL_NUMBER (orig)))
1910 = LABEL_PRESERVE_P (orig);
1911 return get_label_from_map (map, CODE_LABEL_NUMBER (orig));
1913 /* We need to handle "deleted" labels that appear in the DECL_RTL
1914 of a LABEL_DECL. */
1915 case NOTE:
1916 if (NOTE_LINE_NUMBER (orig) == NOTE_INSN_DELETED_LABEL)
1917 return map->insn_map[INSN_UID (orig)];
1918 break;
1920 case LABEL_REF:
1921 copy
1922 = gen_rtx_LABEL_REF
1923 (mode,
1924 LABEL_REF_NONLOCAL_P (orig) ? XEXP (orig, 0)
1925 : get_label_from_map (map, CODE_LABEL_NUMBER (XEXP (orig, 0))));
1927 LABEL_OUTSIDE_LOOP_P (copy) = LABEL_OUTSIDE_LOOP_P (orig);
1929 /* The fact that this label was previously nonlocal does not mean
1930 it still is, so we must check if it is within the range of
1931 this function's labels. */
1932 LABEL_REF_NONLOCAL_P (copy)
1933 = (LABEL_REF_NONLOCAL_P (orig)
1934 && ! (CODE_LABEL_NUMBER (XEXP (copy, 0)) >= get_first_label_num ()
1935 && CODE_LABEL_NUMBER (XEXP (copy, 0)) < max_label_num ()));
1937 /* If we have made a nonlocal label local, it means that this
1938 inlined call will be referring to our nonlocal goto handler.
1939 So make sure we create one for this block; we normally would
1940 not since this is not otherwise considered a "call". */
1941 if (LABEL_REF_NONLOCAL_P (orig) && ! LABEL_REF_NONLOCAL_P (copy))
1942 function_call_count++;
1944 return copy;
1946 case PC:
1947 case CC0:
1948 case CONST_INT:
1949 return orig;
1951 case SYMBOL_REF:
1952 /* Symbols which represent the address of a label stored in the constant
1953 pool must be modified to point to a constant pool entry for the
1954 remapped label. Otherwise, symbols are returned unchanged. */
1955 if (CONSTANT_POOL_ADDRESS_P (orig))
1957 struct function *f = inlining ? inlining : cfun;
1958 rtx constant = get_pool_constant_for_function (f, orig);
1959 enum machine_mode const_mode = get_pool_mode_for_function (f, orig);
1960 if (inlining)
1962 rtx temp = force_const_mem (const_mode,
1963 copy_rtx_and_substitute (constant,
1964 map, 0));
1966 #if 0
1967 /* Legitimizing the address here is incorrect.
1969 Since we had a SYMBOL_REF before, we can assume it is valid
1970 to have one in this position in the insn.
1972 Also, change_address may create new registers. These
1973 registers will not have valid reg_map entries. This can
1974 cause try_constants() to fail because assumes that all
1975 registers in the rtx have valid reg_map entries, and it may
1976 end up replacing one of these new registers with junk. */
1978 if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
1979 temp = change_address (temp, GET_MODE (temp), XEXP (temp, 0));
1980 #endif
1982 temp = XEXP (temp, 0);
1984 #ifdef POINTERS_EXTEND_UNSIGNED
1985 if (GET_MODE (temp) != GET_MODE (orig))
1986 temp = convert_memory_address (GET_MODE (orig), temp);
1987 #endif
1988 return temp;
1990 else if (GET_CODE (constant) == LABEL_REF)
1991 return XEXP (force_const_mem
1992 (GET_MODE (orig),
1993 copy_rtx_and_substitute (constant, map, for_lhs)),
1996 else
1997 if (SYMBOL_REF_NEED_ADJUST (orig))
1999 eif_eh_map = map;
2000 return rethrow_symbol_map (orig,
2001 expand_inline_function_eh_labelmap);
2004 return orig;
2006 case CONST_DOUBLE:
2007 /* We have to make a new copy of this CONST_DOUBLE because don't want
2008 to use the old value of CONST_DOUBLE_MEM. Also, this may be a
2009 duplicate of a CONST_DOUBLE we have already seen. */
2010 if (GET_MODE_CLASS (GET_MODE (orig)) == MODE_FLOAT)
2012 REAL_VALUE_TYPE d;
2014 REAL_VALUE_FROM_CONST_DOUBLE (d, orig);
2015 return CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (orig));
2017 else
2018 return immed_double_const (CONST_DOUBLE_LOW (orig),
2019 CONST_DOUBLE_HIGH (orig), VOIDmode);
2021 case CONST:
2022 /* Make new constant pool entry for a constant
2023 that was in the pool of the inline function. */
2024 if (RTX_INTEGRATED_P (orig))
2025 abort ();
2026 break;
2028 case ASM_OPERANDS:
2029 /* If a single asm insn contains multiple output operands
2030 then it contains multiple ASM_OPERANDS rtx's that share operand 3.
2031 We must make sure that the copied insn continues to share it. */
2032 if (map->orig_asm_operands_vector == XVEC (orig, 3))
2034 copy = rtx_alloc (ASM_OPERANDS);
2035 copy->volatil = orig->volatil;
2036 XSTR (copy, 0) = XSTR (orig, 0);
2037 XSTR (copy, 1) = XSTR (orig, 1);
2038 XINT (copy, 2) = XINT (orig, 2);
2039 XVEC (copy, 3) = map->copy_asm_operands_vector;
2040 XVEC (copy, 4) = map->copy_asm_constraints_vector;
2041 XSTR (copy, 5) = XSTR (orig, 5);
2042 XINT (copy, 6) = XINT (orig, 6);
2043 return copy;
2045 break;
2047 case CALL:
2048 /* This is given special treatment because the first
2049 operand of a CALL is a (MEM ...) which may get
2050 forced into a register for cse. This is undesirable
2051 if function-address cse isn't wanted or if we won't do cse. */
2052 #ifndef NO_FUNCTION_CSE
2053 if (! (optimize && ! flag_no_function_cse))
2054 #endif
2055 return
2056 gen_rtx_CALL
2057 (GET_MODE (orig),
2058 gen_rtx_MEM (GET_MODE (XEXP (orig, 0)),
2059 copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0),
2060 map, 0)),
2061 copy_rtx_and_substitute (XEXP (orig, 1), map, 0));
2062 break;
2064 #if 0
2065 /* Must be ifdefed out for loop unrolling to work. */
2066 case RETURN:
2067 abort ();
2068 #endif
2070 case SET:
2071 /* If this is setting fp or ap, it means that we have a nonlocal goto.
2072 Adjust the setting by the offset of the area we made.
2073 If the nonlocal goto is into the current function,
2074 this will result in unnecessarily bad code, but should work. */
2075 if (SET_DEST (orig) == virtual_stack_vars_rtx
2076 || SET_DEST (orig) == virtual_incoming_args_rtx)
2078 /* In case a translation hasn't occurred already, make one now. */
2079 rtx equiv_reg;
2080 rtx equiv_loc;
2081 HOST_WIDE_INT loc_offset;
2083 copy_rtx_and_substitute (SET_DEST (orig), map, for_lhs);
2084 equiv_reg = map->reg_map[REGNO (SET_DEST (orig))];
2085 equiv_loc = VARRAY_CONST_EQUIV (map->const_equiv_varray,
2086 REGNO (equiv_reg)).rtx;
2087 loc_offset
2088 = GET_CODE (equiv_loc) == REG ? 0 : INTVAL (XEXP (equiv_loc, 1));
2090 return gen_rtx_SET (VOIDmode, SET_DEST (orig),
2091 force_operand
2092 (plus_constant
2093 (copy_rtx_and_substitute (SET_SRC (orig),
2094 map, 0),
2095 - loc_offset),
2096 NULL_RTX));
2098 else
2099 return gen_rtx_SET (VOIDmode,
2100 copy_rtx_and_substitute (SET_DEST (orig), map, 1),
2101 copy_rtx_and_substitute (SET_SRC (orig), map, 0));
2102 break;
2104 case MEM:
2105 if (inlining
2106 && GET_CODE (XEXP (orig, 0)) == SYMBOL_REF
2107 && CONSTANT_POOL_ADDRESS_P (XEXP (orig, 0)))
2109 enum machine_mode const_mode
2110 = get_pool_mode_for_function (inlining, XEXP (orig, 0));
2111 rtx constant
2112 = get_pool_constant_for_function (inlining, XEXP (orig, 0));
2114 constant = copy_rtx_and_substitute (constant, map, 0);
2116 /* If this was an address of a constant pool entry that itself
2117 had to be placed in the constant pool, it might not be a
2118 valid address. So the recursive call might have turned it
2119 into a register. In that case, it isn't a constant any
2120 more, so return it. This has the potential of changing a
2121 MEM into a REG, but we'll assume that it safe. */
2122 if (! CONSTANT_P (constant))
2123 return constant;
2125 return validize_mem (force_const_mem (const_mode, constant));
2128 copy = rtx_alloc (MEM);
2129 PUT_MODE (copy, mode);
2130 XEXP (copy, 0) = copy_rtx_and_substitute (XEXP (orig, 0), map, 0);
2131 MEM_COPY_ATTRIBUTES (copy, orig);
2132 MEM_ALIAS_SET (copy) = MEM_ALIAS_SET (orig);
2133 RTX_UNCHANGING_P (copy) = RTX_UNCHANGING_P (orig);
2134 return copy;
2136 default:
2137 break;
2140 copy = rtx_alloc (code);
2141 PUT_MODE (copy, mode);
2142 copy->in_struct = orig->in_struct;
2143 copy->volatil = orig->volatil;
2144 copy->unchanging = orig->unchanging;
2146 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
2148 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
2150 switch (*format_ptr++)
2152 case '0':
2153 /* Copy this through the wide int field; that's safest. */
2154 X0WINT (copy, i) = X0WINT (orig, i);
2155 break;
2157 case 'e':
2158 XEXP (copy, i)
2159 = copy_rtx_and_substitute (XEXP (orig, i), map, for_lhs);
2160 break;
2162 case 'u':
2163 /* Change any references to old-insns to point to the
2164 corresponding copied insns. */
2165 XEXP (copy, i) = map->insn_map[INSN_UID (XEXP (orig, i))];
2166 break;
2168 case 'E':
2169 XVEC (copy, i) = XVEC (orig, i);
2170 if (XVEC (orig, i) != NULL && XVECLEN (orig, i) != 0)
2172 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
2173 for (j = 0; j < XVECLEN (copy, i); j++)
2174 XVECEXP (copy, i, j)
2175 = copy_rtx_and_substitute (XVECEXP (orig, i, j),
2176 map, for_lhs);
2178 break;
2180 case 'w':
2181 XWINT (copy, i) = XWINT (orig, i);
2182 break;
2184 case 'i':
2185 XINT (copy, i) = XINT (orig, i);
2186 break;
2188 case 's':
2189 XSTR (copy, i) = XSTR (orig, i);
2190 break;
2192 case 't':
2193 XTREE (copy, i) = XTREE (orig, i);
2194 break;
2196 default:
2197 abort ();
2201 if (code == ASM_OPERANDS && map->orig_asm_operands_vector == 0)
2203 map->orig_asm_operands_vector = XVEC (orig, 3);
2204 map->copy_asm_operands_vector = XVEC (copy, 3);
2205 map->copy_asm_constraints_vector = XVEC (copy, 4);
2208 return copy;
2211 /* Substitute known constant values into INSN, if that is valid. */
2213 void
2214 try_constants (insn, map)
2215 rtx insn;
2216 struct inline_remap *map;
2218 int i;
2220 map->num_sets = 0;
2222 /* First try just updating addresses, then other things. This is
2223 important when we have something like the store of a constant
2224 into memory and we can update the memory address but the machine
2225 does not support a constant source. */
2226 subst_constants (&PATTERN (insn), insn, map, 1);
2227 apply_change_group ();
2228 subst_constants (&PATTERN (insn), insn, map, 0);
2229 apply_change_group ();
2231 /* Show we don't know the value of anything stored or clobbered. */
2232 note_stores (PATTERN (insn), mark_stores, NULL);
2233 map->last_pc_value = 0;
2234 #ifdef HAVE_cc0
2235 map->last_cc0_value = 0;
2236 #endif
2238 /* Set up any constant equivalences made in this insn. */
2239 for (i = 0; i < map->num_sets; i++)
2241 if (GET_CODE (map->equiv_sets[i].dest) == REG)
2243 int regno = REGNO (map->equiv_sets[i].dest);
2245 MAYBE_EXTEND_CONST_EQUIV_VARRAY (map, regno);
2246 if (VARRAY_CONST_EQUIV (map->const_equiv_varray, regno).rtx == 0
2247 /* Following clause is a hack to make case work where GNU C++
2248 reassigns a variable to make cse work right. */
2249 || ! rtx_equal_p (VARRAY_CONST_EQUIV (map->const_equiv_varray,
2250 regno).rtx,
2251 map->equiv_sets[i].equiv))
2252 SET_CONST_EQUIV_DATA (map, map->equiv_sets[i].dest,
2253 map->equiv_sets[i].equiv, map->const_age);
2255 else if (map->equiv_sets[i].dest == pc_rtx)
2256 map->last_pc_value = map->equiv_sets[i].equiv;
2257 #ifdef HAVE_cc0
2258 else if (map->equiv_sets[i].dest == cc0_rtx)
2259 map->last_cc0_value = map->equiv_sets[i].equiv;
2260 #endif
2264 /* Substitute known constants for pseudo regs in the contents of LOC,
2265 which are part of INSN.
2266 If INSN is zero, the substitution should always be done (this is used to
2267 update DECL_RTL).
2268 These changes are taken out by try_constants if the result is not valid.
2270 Note that we are more concerned with determining when the result of a SET
2271 is a constant, for further propagation, than actually inserting constants
2272 into insns; cse will do the latter task better.
2274 This function is also used to adjust address of items previously addressed
2275 via the virtual stack variable or virtual incoming arguments registers.
2277 If MEMONLY is nonzero, only make changes inside a MEM. */
2279 static void
2280 subst_constants (loc, insn, map, memonly)
2281 rtx *loc;
2282 rtx insn;
2283 struct inline_remap *map;
2284 int memonly;
2286 rtx x = *loc;
2287 register int i, j;
2288 register enum rtx_code code;
2289 register const char *format_ptr;
2290 int num_changes = num_validated_changes ();
2291 rtx new = 0;
2292 enum machine_mode op0_mode = MAX_MACHINE_MODE;
2294 code = GET_CODE (x);
2296 switch (code)
2298 case PC:
2299 case CONST_INT:
2300 case CONST_DOUBLE:
2301 case SYMBOL_REF:
2302 case CONST:
2303 case LABEL_REF:
2304 case ADDRESS:
2305 return;
2307 #ifdef HAVE_cc0
2308 case CC0:
2309 if (! memonly)
2310 validate_change (insn, loc, map->last_cc0_value, 1);
2311 return;
2312 #endif
2314 case USE:
2315 case CLOBBER:
2316 /* The only thing we can do with a USE or CLOBBER is possibly do
2317 some substitutions in a MEM within it. */
2318 if (GET_CODE (XEXP (x, 0)) == MEM)
2319 subst_constants (&XEXP (XEXP (x, 0), 0), insn, map, 0);
2320 return;
2322 case REG:
2323 /* Substitute for parms and known constants. Don't replace
2324 hard regs used as user variables with constants. */
2325 if (! memonly)
2327 int regno = REGNO (x);
2328 struct const_equiv_data *p;
2330 if (! (regno < FIRST_PSEUDO_REGISTER && REG_USERVAR_P (x))
2331 && (size_t) regno < VARRAY_SIZE (map->const_equiv_varray)
2332 && (p = &VARRAY_CONST_EQUIV (map->const_equiv_varray, regno),
2333 p->rtx != 0)
2334 && p->age >= map->const_age)
2335 validate_change (insn, loc, p->rtx, 1);
2337 return;
2339 case SUBREG:
2340 /* SUBREG applied to something other than a reg
2341 should be treated as ordinary, since that must
2342 be a special hack and we don't know how to treat it specially.
2343 Consider for example mulsidi3 in m68k.md.
2344 Ordinary SUBREG of a REG needs this special treatment. */
2345 if (! memonly && GET_CODE (SUBREG_REG (x)) == REG)
2347 rtx inner = SUBREG_REG (x);
2348 rtx new = 0;
2350 /* We can't call subst_constants on &SUBREG_REG (x) because any
2351 constant or SUBREG wouldn't be valid inside our SUBEG. Instead,
2352 see what is inside, try to form the new SUBREG and see if that is
2353 valid. We handle two cases: extracting a full word in an
2354 integral mode and extracting the low part. */
2355 subst_constants (&inner, NULL_RTX, map, 0);
2357 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2358 && GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD
2359 && GET_MODE (SUBREG_REG (x)) != VOIDmode)
2360 new = operand_subword (inner, SUBREG_WORD (x), 0,
2361 GET_MODE (SUBREG_REG (x)));
2363 cancel_changes (num_changes);
2364 if (new == 0 && subreg_lowpart_p (x))
2365 new = gen_lowpart_common (GET_MODE (x), inner);
2367 if (new)
2368 validate_change (insn, loc, new, 1);
2370 return;
2372 break;
2374 case MEM:
2375 subst_constants (&XEXP (x, 0), insn, map, 0);
2377 /* If a memory address got spoiled, change it back. */
2378 if (! memonly && insn != 0 && num_validated_changes () != num_changes
2379 && ! memory_address_p (GET_MODE (x), XEXP (x, 0)))
2380 cancel_changes (num_changes);
2381 return;
2383 case SET:
2385 /* Substitute constants in our source, and in any arguments to a
2386 complex (e..g, ZERO_EXTRACT) destination, but not in the destination
2387 itself. */
2388 rtx *dest_loc = &SET_DEST (x);
2389 rtx dest = *dest_loc;
2390 rtx src, tem;
2392 subst_constants (&SET_SRC (x), insn, map, memonly);
2393 src = SET_SRC (x);
2395 while (GET_CODE (*dest_loc) == ZERO_EXTRACT
2396 || GET_CODE (*dest_loc) == SUBREG
2397 || GET_CODE (*dest_loc) == STRICT_LOW_PART)
2399 if (GET_CODE (*dest_loc) == ZERO_EXTRACT)
2401 subst_constants (&XEXP (*dest_loc, 1), insn, map, memonly);
2402 subst_constants (&XEXP (*dest_loc, 2), insn, map, memonly);
2404 dest_loc = &XEXP (*dest_loc, 0);
2407 /* Do substitute in the address of a destination in memory. */
2408 if (GET_CODE (*dest_loc) == MEM)
2409 subst_constants (&XEXP (*dest_loc, 0), insn, map, 0);
2411 /* Check for the case of DEST a SUBREG, both it and the underlying
2412 register are less than one word, and the SUBREG has the wider mode.
2413 In the case, we are really setting the underlying register to the
2414 source converted to the mode of DEST. So indicate that. */
2415 if (GET_CODE (dest) == SUBREG
2416 && GET_MODE_SIZE (GET_MODE (dest)) <= UNITS_PER_WORD
2417 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) <= UNITS_PER_WORD
2418 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2419 <= GET_MODE_SIZE (GET_MODE (dest)))
2420 && (tem = gen_lowpart_if_possible (GET_MODE (SUBREG_REG (dest)),
2421 src)))
2422 src = tem, dest = SUBREG_REG (dest);
2424 /* If storing a recognizable value save it for later recording. */
2425 if ((map->num_sets < MAX_RECOG_OPERANDS)
2426 && (CONSTANT_P (src)
2427 || (GET_CODE (src) == REG
2428 && (REGNO (src) == VIRTUAL_INCOMING_ARGS_REGNUM
2429 || REGNO (src) == VIRTUAL_STACK_VARS_REGNUM))
2430 || (GET_CODE (src) == PLUS
2431 && GET_CODE (XEXP (src, 0)) == REG
2432 && (REGNO (XEXP (src, 0)) == VIRTUAL_INCOMING_ARGS_REGNUM
2433 || REGNO (XEXP (src, 0)) == VIRTUAL_STACK_VARS_REGNUM)
2434 && CONSTANT_P (XEXP (src, 1)))
2435 || GET_CODE (src) == COMPARE
2436 #ifdef HAVE_cc0
2437 || dest == cc0_rtx
2438 #endif
2439 || (dest == pc_rtx
2440 && (src == pc_rtx || GET_CODE (src) == RETURN
2441 || GET_CODE (src) == LABEL_REF))))
2443 /* Normally, this copy won't do anything. But, if SRC is a COMPARE
2444 it will cause us to save the COMPARE with any constants
2445 substituted, which is what we want for later. */
2446 map->equiv_sets[map->num_sets].equiv = copy_rtx (src);
2447 map->equiv_sets[map->num_sets++].dest = dest;
2450 return;
2452 default:
2453 break;
2456 format_ptr = GET_RTX_FORMAT (code);
2458 /* If the first operand is an expression, save its mode for later. */
2459 if (*format_ptr == 'e')
2460 op0_mode = GET_MODE (XEXP (x, 0));
2462 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2464 switch (*format_ptr++)
2466 case '0':
2467 break;
2469 case 'e':
2470 if (XEXP (x, i))
2471 subst_constants (&XEXP (x, i), insn, map, memonly);
2472 break;
2474 case 'u':
2475 case 'i':
2476 case 's':
2477 case 'w':
2478 case 'n':
2479 case 't':
2480 break;
2482 case 'E':
2483 if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
2484 for (j = 0; j < XVECLEN (x, i); j++)
2485 subst_constants (&XVECEXP (x, i, j), insn, map, memonly);
2487 break;
2489 default:
2490 abort ();
2494 /* If this is a commutative operation, move a constant to the second
2495 operand unless the second operand is already a CONST_INT. */
2496 if (! memonly
2497 && (GET_RTX_CLASS (code) == 'c' || code == NE || code == EQ)
2498 && CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT)
2500 rtx tem = XEXP (x, 0);
2501 validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
2502 validate_change (insn, &XEXP (x, 1), tem, 1);
2505 /* Simplify the expression in case we put in some constants. */
2506 if (! memonly)
2507 switch (GET_RTX_CLASS (code))
2509 case '1':
2510 if (op0_mode == MAX_MACHINE_MODE)
2511 abort ();
2512 new = simplify_unary_operation (code, GET_MODE (x),
2513 XEXP (x, 0), op0_mode);
2514 break;
2516 case '<':
2518 enum machine_mode op_mode = GET_MODE (XEXP (x, 0));
2520 if (op_mode == VOIDmode)
2521 op_mode = GET_MODE (XEXP (x, 1));
2522 new = simplify_relational_operation (code, op_mode,
2523 XEXP (x, 0), XEXP (x, 1));
2524 #ifdef FLOAT_STORE_FLAG_VALUE
2525 if (new != 0 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2527 enum machine_mode mode = GET_MODE (x);
2528 if (new == const0_rtx)
2529 new = CONST0_RTX (mode);
2530 else
2532 REAL_VALUE_TYPE val = FLOAT_STORE_FLAG_VALUE (mode);
2533 new = CONST_DOUBLE_FROM_REAL_VALUE (val, mode);
2536 #endif
2537 break;
2540 case '2':
2541 case 'c':
2542 new = simplify_binary_operation (code, GET_MODE (x),
2543 XEXP (x, 0), XEXP (x, 1));
2544 break;
2546 case 'b':
2547 case '3':
2548 if (op0_mode == MAX_MACHINE_MODE)
2549 abort ();
2551 new = simplify_ternary_operation (code, GET_MODE (x), op0_mode,
2552 XEXP (x, 0), XEXP (x, 1),
2553 XEXP (x, 2));
2554 break;
2557 if (new)
2558 validate_change (insn, loc, new, 1);
2561 /* Show that register modified no longer contain known constants. We are
2562 called from note_stores with parts of the new insn. */
2564 static void
2565 mark_stores (dest, x, data)
2566 rtx dest;
2567 rtx x ATTRIBUTE_UNUSED;
2568 void *data ATTRIBUTE_UNUSED;
2570 int regno = -1;
2571 enum machine_mode mode = VOIDmode;
2573 /* DEST is always the innermost thing set, except in the case of
2574 SUBREGs of hard registers. */
2576 if (GET_CODE (dest) == REG)
2577 regno = REGNO (dest), mode = GET_MODE (dest);
2578 else if (GET_CODE (dest) == SUBREG && GET_CODE (SUBREG_REG (dest)) == REG)
2580 regno = REGNO (SUBREG_REG (dest)) + SUBREG_WORD (dest);
2581 mode = GET_MODE (SUBREG_REG (dest));
2584 if (regno >= 0)
2586 unsigned int uregno = regno;
2587 unsigned int last_reg = (uregno >= FIRST_PSEUDO_REGISTER ? uregno
2588 : uregno + HARD_REGNO_NREGS (uregno, mode) - 1);
2589 unsigned int i;
2591 /* Ignore virtual stack var or virtual arg register since those
2592 are handled separately. */
2593 if (uregno != VIRTUAL_INCOMING_ARGS_REGNUM
2594 && uregno != VIRTUAL_STACK_VARS_REGNUM)
2595 for (i = uregno; i <= last_reg; i++)
2596 if ((size_t) i < VARRAY_SIZE (global_const_equiv_varray))
2597 VARRAY_CONST_EQUIV (global_const_equiv_varray, i).rtx = 0;
2601 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
2602 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
2603 that it points to the node itself, thus indicating that the node is its
2604 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
2605 the given node is NULL, recursively descend the decl/block tree which
2606 it is the root of, and for each other ..._DECL or BLOCK node contained
2607 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
2608 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
2609 values to point to themselves. */
2611 static void
2612 set_block_origin_self (stmt)
2613 register tree stmt;
2615 if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
2617 BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
2620 register tree local_decl;
2622 for (local_decl = BLOCK_VARS (stmt);
2623 local_decl != NULL_TREE;
2624 local_decl = TREE_CHAIN (local_decl))
2625 set_decl_origin_self (local_decl); /* Potential recursion. */
2629 register tree subblock;
2631 for (subblock = BLOCK_SUBBLOCKS (stmt);
2632 subblock != NULL_TREE;
2633 subblock = BLOCK_CHAIN (subblock))
2634 set_block_origin_self (subblock); /* Recurse. */
2639 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
2640 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
2641 node to so that it points to the node itself, thus indicating that the
2642 node represents its own (abstract) origin. Additionally, if the
2643 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
2644 the decl/block tree of which the given node is the root of, and for
2645 each other ..._DECL or BLOCK node contained therein whose
2646 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
2647 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
2648 point to themselves. */
2650 static void
2651 set_decl_origin_self (decl)
2652 register tree decl;
2654 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
2656 DECL_ABSTRACT_ORIGIN (decl) = decl;
2657 if (TREE_CODE (decl) == FUNCTION_DECL)
2659 register tree arg;
2661 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
2662 DECL_ABSTRACT_ORIGIN (arg) = arg;
2663 if (DECL_INITIAL (decl) != NULL_TREE
2664 && DECL_INITIAL (decl) != error_mark_node)
2665 set_block_origin_self (DECL_INITIAL (decl));
2670 /* Given a pointer to some BLOCK node, and a boolean value to set the
2671 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
2672 the given block, and for all local decls and all local sub-blocks
2673 (recursively) which are contained therein. */
2675 static void
2676 set_block_abstract_flags (stmt, setting)
2677 register tree stmt;
2678 register int setting;
2680 register tree local_decl;
2681 register tree subblock;
2683 BLOCK_ABSTRACT (stmt) = setting;
2685 for (local_decl = BLOCK_VARS (stmt);
2686 local_decl != NULL_TREE;
2687 local_decl = TREE_CHAIN (local_decl))
2688 set_decl_abstract_flags (local_decl, setting);
2690 for (subblock = BLOCK_SUBBLOCKS (stmt);
2691 subblock != NULL_TREE;
2692 subblock = BLOCK_CHAIN (subblock))
2693 set_block_abstract_flags (subblock, setting);
2696 /* Given a pointer to some ..._DECL node, and a boolean value to set the
2697 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
2698 given decl, and (in the case where the decl is a FUNCTION_DECL) also
2699 set the abstract flags for all of the parameters, local vars, local
2700 blocks and sub-blocks (recursively) to the same setting. */
2702 void
2703 set_decl_abstract_flags (decl, setting)
2704 register tree decl;
2705 register int setting;
2707 DECL_ABSTRACT (decl) = setting;
2708 if (TREE_CODE (decl) == FUNCTION_DECL)
2710 register tree arg;
2712 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
2713 DECL_ABSTRACT (arg) = setting;
2714 if (DECL_INITIAL (decl) != NULL_TREE
2715 && DECL_INITIAL (decl) != error_mark_node)
2716 set_block_abstract_flags (DECL_INITIAL (decl), setting);
2720 /* Output the assembly language code for the function FNDECL
2721 from its DECL_SAVED_INSNS. Used for inline functions that are output
2722 at end of compilation instead of where they came in the source. */
2724 void
2725 output_inline_function (fndecl)
2726 tree fndecl;
2728 struct function *old_cfun = cfun;
2729 struct function *f = DECL_SAVED_INSNS (fndecl);
2731 cfun = f;
2732 current_function_decl = fndecl;
2733 clear_emit_caches ();
2735 /* Things we allocate from here on are part of this function, not
2736 permanent. */
2737 temporary_allocation ();
2739 set_new_last_label_num (f->inl_max_label_num);
2741 /* We must have already output DWARF debugging information for the
2742 original (abstract) inline function declaration/definition, so
2743 we want to make sure that the debugging information we generate
2744 for this special instance of the inline function refers back to
2745 the information we already generated. To make sure that happens,
2746 we simply have to set the DECL_ABSTRACT_ORIGIN for the function
2747 node (and for all of the local ..._DECL nodes which are its children)
2748 so that they all point to themselves. */
2750 set_decl_origin_self (fndecl);
2752 /* We're not deferring this any longer. */
2753 DECL_DEFER_OUTPUT (fndecl) = 0;
2755 /* We can't inline this anymore. */
2756 f->inlinable = 0;
2757 DECL_INLINE (fndecl) = 0;
2759 /* Compile this function all the way down to assembly code. */
2760 rest_of_compilation (fndecl);
2762 cfun = old_cfun;
2763 current_function_decl = old_cfun ? old_cfun->decl : 0;