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