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