OSDN Git Service

* gcc.c-torture/compile/20001226-1.x: Only xfail for Xtensa
[pf3gnuchains/gcc-fork.git] / gcc / sibcall.c
1 /* Generic sibling call optimization support
2    Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING.  If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23
24 #include "rtl.h"
25 #include "regs.h"
26 #include "function.h"
27 #include "hard-reg-set.h"
28 #include "flags.h"
29 #include "insn-config.h"
30 #include "recog.h"
31 #include "basic-block.h"
32 #include "output.h"
33 #include "except.h"
34 #include "tree.h"
35
36 /* In case alternate_exit_block contains copy from pseudo, to return value,
37    record the pseudo here.  In such case the pseudo must be set to function
38    return in the sibcall sequence.  */
39 static rtx return_value_pseudo;
40
41 static int identify_call_return_value   PARAMS ((rtx, rtx *, rtx *));
42 static rtx skip_copy_to_return_value    PARAMS ((rtx));
43 static rtx skip_use_of_return_value     PARAMS ((rtx, enum rtx_code));
44 static rtx skip_stack_adjustment        PARAMS ((rtx));
45 static rtx skip_pic_restore             PARAMS ((rtx));
46 static rtx skip_jump_insn               PARAMS ((rtx));
47 static int call_ends_block_p            PARAMS ((rtx, rtx));
48 static int uses_addressof               PARAMS ((rtx));
49 static int sequence_uses_addressof      PARAMS ((rtx));
50 static void purge_reg_equiv_notes       PARAMS ((void));
51 static void purge_mem_unchanging_flag   PARAMS ((rtx));
52 static rtx skip_unreturned_value        PARAMS ((rtx));
53
54 /* Examine a CALL_PLACEHOLDER pattern and determine where the call's
55    return value is located.  P_HARD_RETURN receives the hard register
56    that the function used; P_SOFT_RETURN receives the pseudo register
57    that the sequence used.  Return non-zero if the values were located.  */
58
59 static int
60 identify_call_return_value (cp, p_hard_return, p_soft_return)
61      rtx cp;
62      rtx *p_hard_return, *p_soft_return;
63 {
64   rtx insn, set, hard, soft;
65
66   insn = XEXP (cp, 0);
67   /* Search backward through the "normal" call sequence to the CALL insn.  */
68   while (NEXT_INSN (insn))
69     insn = NEXT_INSN (insn);
70   while (GET_CODE (insn) != CALL_INSN)
71     insn = PREV_INSN (insn);
72
73   /* Assume the pattern is (set (dest) (call ...)), or that the first
74      member of a parallel is.  This is the hard return register used
75      by the function.  */
76   if (GET_CODE (PATTERN (insn)) == SET
77       && GET_CODE (SET_SRC (PATTERN (insn))) == CALL)
78     hard = SET_DEST (PATTERN (insn));
79   else if (GET_CODE (PATTERN (insn)) == PARALLEL
80            && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET
81            && GET_CODE (SET_SRC (XVECEXP (PATTERN (insn), 0, 0))) == CALL)
82     hard = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
83   else
84     return 0;
85
86   /* If we didn't get a single hard register (e.g. a parallel), give up.  */
87   if (GET_CODE (hard) != REG)
88     return 0;
89
90   /* Stack adjustment done after call may appear here.  */
91   insn = skip_stack_adjustment (insn);
92   if (! insn)
93     return 0;
94
95   /* Restore of GP register may appear here.  */
96   insn = skip_pic_restore (insn);
97   if (! insn)
98     return 0;
99
100   /* If there's nothing after, there's no soft return value.  */
101   insn = NEXT_INSN (insn);
102   if (! insn)
103     return 0;
104
105   /* We're looking for a source of the hard return register.  */
106   set = single_set (insn);
107   if (! set || SET_SRC (set) != hard)
108     return 0;
109
110   soft = SET_DEST (set);
111   insn = NEXT_INSN (insn);
112
113   /* Allow this first destination to be copied to a second register,
114      as might happen if the first register wasn't the particular pseudo
115      we'd been expecting.  */
116   if (insn
117       && (set = single_set (insn)) != NULL_RTX
118       && SET_SRC (set) == soft)
119     {
120       soft = SET_DEST (set);
121       insn = NEXT_INSN (insn);
122     }
123
124   /* Don't fool with anything but pseudo registers.  */
125   if (GET_CODE (soft) != REG || REGNO (soft) < FIRST_PSEUDO_REGISTER)
126     return 0;
127
128   /* This value must not be modified before the end of the sequence.  */
129   if (reg_set_between_p (soft, insn, NULL_RTX))
130     return 0;
131
132   *p_hard_return = hard;
133   *p_soft_return = soft;
134
135   return 1;
136 }
137
138 /* If the first real insn after ORIG_INSN copies to this function's
139    return value from RETVAL, then return the insn which performs the
140    copy.  Otherwise return ORIG_INSN.  */
141
142 static rtx
143 skip_copy_to_return_value (orig_insn)
144      rtx orig_insn;
145 {
146   rtx insn, set = NULL_RTX;
147   rtx hardret, softret;
148
149   /* If there is no return value, we have nothing to do.  */
150   if (! identify_call_return_value (PATTERN (orig_insn), &hardret, &softret))
151     return orig_insn;
152
153   insn = next_nonnote_insn (orig_insn);
154   if (! insn)
155     return orig_insn;
156
157   set = single_set (insn);
158   if (! set)
159     return orig_insn;
160
161   if (return_value_pseudo)
162     {
163       if (SET_DEST (set) == return_value_pseudo
164           && SET_SRC (set) == softret)
165         return insn;
166       return orig_insn;
167     }
168
169   /* The destination must be the same as the called function's return
170      value to ensure that any return value is put in the same place by the
171      current function and the function we're calling.
172
173      Further, the source must be the same as the pseudo into which the
174      called function's return value was copied.  Otherwise we're returning
175      some other value.  */
176
177 #ifndef OUTGOING_REGNO
178 #define OUTGOING_REGNO(N) (N)
179 #endif
180
181   if (SET_DEST (set) == current_function_return_rtx
182       && REG_P (SET_DEST (set))
183       && OUTGOING_REGNO (REGNO (SET_DEST (set))) == REGNO (hardret)
184       && SET_SRC (set) == softret)
185     return insn;
186
187   /* Recognize the situation when the called function's return value
188      is copied in two steps: first into an intermediate pseudo, then
189      the into the calling functions return value register.  */
190
191   if (REG_P (SET_DEST (set))
192       && SET_SRC (set) == softret)
193     {
194       rtx x = SET_DEST (set);
195
196       insn = next_nonnote_insn (insn);
197       if (! insn)
198         return orig_insn;
199
200       set = single_set (insn);
201       if (! set)
202         return orig_insn;
203
204       if (SET_DEST (set) == current_function_return_rtx
205           && REG_P (SET_DEST (set))
206           && OUTGOING_REGNO (REGNO (SET_DEST (set))) == REGNO (hardret)
207           && SET_SRC (set) == x)
208         return insn;
209     }
210
211   /* It did not look like a copy of the return value, so return the
212      same insn we were passed.  */
213   return orig_insn;
214 }
215
216 /* If the first real insn after ORIG_INSN is a CODE of this function's return
217    value, return insn.  Otherwise return ORIG_INSN.  */
218
219 static rtx
220 skip_use_of_return_value (orig_insn, code)
221      rtx orig_insn;
222      enum rtx_code code;
223 {
224   rtx insn;
225
226   insn = next_nonnote_insn (orig_insn);
227
228   if (insn
229       && GET_CODE (insn) == INSN
230       && GET_CODE (PATTERN (insn)) == code
231       && (XEXP (PATTERN (insn), 0) == current_function_return_rtx
232           || XEXP (PATTERN (insn), 0) == const0_rtx))
233     return insn;
234
235   return orig_insn;
236 }
237
238 /* In case function does not return value,  we get clobber of pseudo followed
239    by set to hard return value.  */
240 static rtx
241 skip_unreturned_value (orig_insn)
242      rtx orig_insn;
243 {
244   rtx insn = next_nonnote_insn (orig_insn);
245
246   /* Skip possible clobber of pseudo return register.  */
247   if (insn
248       && GET_CODE (insn) == INSN
249       && GET_CODE (PATTERN (insn)) == CLOBBER
250       && REG_P (XEXP (PATTERN (insn), 0))
251       && (REGNO (XEXP (PATTERN (insn), 0)) >= FIRST_PSEUDO_REGISTER))
252     {
253       rtx set_insn = next_nonnote_insn (insn);
254       rtx set;
255       if (!set_insn)
256         return insn;
257       set = single_set (set_insn);
258       if (!set
259           || SET_SRC (set) != XEXP (PATTERN (insn), 0)
260           || SET_DEST (set) != current_function_return_rtx)
261         return insn;
262       return set_insn;
263     }
264   return orig_insn;
265 }
266
267 /* If the first real insn after ORIG_INSN adjusts the stack pointer
268    by a constant, return the insn with the stack pointer adjustment.
269    Otherwise return ORIG_INSN.  */
270
271 static rtx
272 skip_stack_adjustment (orig_insn)
273      rtx orig_insn;
274 {
275   rtx insn, set = NULL_RTX;
276
277   insn = next_nonnote_insn (orig_insn);
278
279   if (insn)
280     set = single_set (insn);
281
282   if (insn
283       && set
284       && GET_CODE (SET_SRC (set)) == PLUS
285       && XEXP (SET_SRC (set), 0) == stack_pointer_rtx
286       && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT
287       && SET_DEST (set) == stack_pointer_rtx)
288     return insn;
289
290   return orig_insn;
291 }
292
293 /* If the first real insn after ORIG_INSN sets the pic register,
294    return it.  Otherwise return ORIG_INSN.  */
295
296 static rtx
297 skip_pic_restore (orig_insn)
298      rtx orig_insn;
299 {
300   rtx insn, set = NULL_RTX;
301
302   insn = next_nonnote_insn (orig_insn);
303
304   if (insn)
305     set = single_set (insn);
306
307   if (insn && set && SET_DEST (set) == pic_offset_table_rtx)
308     return insn;
309
310   return orig_insn;
311 }
312
313 /* If the first real insn after ORIG_INSN is a jump, return the JUMP_INSN.
314    Otherwise return ORIG_INSN.  */
315
316 static rtx
317 skip_jump_insn (orig_insn)
318      rtx orig_insn;
319 {
320   rtx insn;
321
322   insn = next_nonnote_insn (orig_insn);
323
324   if (insn
325       && GET_CODE (insn) == JUMP_INSN
326       && any_uncondjump_p (insn))
327     return insn;
328
329   return orig_insn;
330 }
331 \f
332 /* Using the above functions, see if INSN, skipping any of the above,
333    goes all the way to END, the end of a basic block.  Return 1 if so.  */
334
335 static int
336 call_ends_block_p (insn, end)
337      rtx insn;
338      rtx end;
339 {
340   rtx new_insn;
341   /* END might be a note, so get the last nonnote insn of the block.  */
342   end = next_nonnote_insn (PREV_INSN (end));
343
344   /* If the call was the end of the block, then we're OK.  */
345   if (insn == end)
346     return 1;
347
348   /* Skip over copying from the call's return value pseudo into
349      this function's hard return register and if that's the end
350      of the block, we're OK.  */
351   new_insn = skip_copy_to_return_value (insn);
352
353   /* In case we return value in pseudo, we must set the pseudo to
354      return value of called function, otherwise we are returning
355      something else.  */
356   if (return_value_pseudo && insn == new_insn)
357     return 0;
358   insn = new_insn;
359
360   if (insn == end)
361     return 1;
362
363   /* Skip any stack adjustment.  */
364   insn = skip_stack_adjustment (insn);
365   if (insn == end)
366     return 1;
367
368   /* Skip over a CLOBBER of the return value as a hard reg.  */
369   insn = skip_use_of_return_value (insn, CLOBBER);
370   if (insn == end)
371     return 1;
372
373   /* Skip over a CLOBBER of the return value as a hard reg.  */
374   insn = skip_unreturned_value (insn);
375   if (insn == end)
376     return 1;
377
378   /* Skip over a USE of the return value (as a hard reg).  */
379   insn = skip_use_of_return_value (insn, USE);
380   if (insn == end)
381     return 1;
382
383   /* Skip over a JUMP_INSN at the end of the block.  If that doesn't end the
384      block, the original CALL_INSN didn't.  */
385   insn = skip_jump_insn (insn);
386   return insn == end;
387 }
388
389 /* Scan the rtx X for ADDRESSOF expressions or
390    current_function_internal_arg_pointer registers.
391    Return nonzero if an ADDRESSOF or current_function_internal_arg_pointer
392    is found outside of some MEM expression, else return zero.  */
393
394 static int
395 uses_addressof (x)
396      rtx x;
397 {
398   RTX_CODE code;
399   int i, j;
400   const char *fmt;
401
402   if (x == NULL_RTX)
403     return 0;
404
405   code = GET_CODE (x);
406
407   if (code == ADDRESSOF || x == current_function_internal_arg_pointer)
408     return 1;
409
410   if (code == MEM)
411     return 0;
412
413   /* Scan all subexpressions.  */
414   fmt = GET_RTX_FORMAT (code);
415   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
416     {
417       if (*fmt == 'e')
418         {
419           if (uses_addressof (XEXP (x, i)))
420             return 1;
421         }
422       else if (*fmt == 'E')
423         {
424           for (j = 0; j < XVECLEN (x, i); j++)
425             if (uses_addressof (XVECEXP (x, i, j)))
426               return 1;
427         }
428     }
429   return 0;
430 }
431
432 /* Scan the sequence of insns in SEQ to see if any have an ADDRESSOF
433    rtl expression or current_function_internal_arg_pointer occurrences
434    not enclosed within a MEM.  If an ADDRESSOF expression or
435    current_function_internal_arg_pointer is found, return nonzero, otherwise
436    return zero.
437
438    This function handles CALL_PLACEHOLDERs which contain multiple sequences
439    of insns.  */
440
441 static int
442 sequence_uses_addressof (seq)
443      rtx seq;
444 {
445   rtx insn;
446
447   for (insn = seq; insn; insn = NEXT_INSN (insn))
448     if (INSN_P (insn))
449       {
450         /* If this is a CALL_PLACEHOLDER, then recursively call ourselves
451            with each nonempty sequence attached to the CALL_PLACEHOLDER.  */
452         if (GET_CODE (insn) == CALL_INSN
453             && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
454           {
455             if (XEXP (PATTERN (insn), 0) != NULL_RTX
456                 && sequence_uses_addressof (XEXP (PATTERN (insn), 0)))
457               return 1;
458             if (XEXP (PATTERN (insn), 1) != NULL_RTX
459                 && sequence_uses_addressof (XEXP (PATTERN (insn), 1)))
460               return 1;
461             if (XEXP (PATTERN (insn), 2) != NULL_RTX
462                 && sequence_uses_addressof (XEXP (PATTERN (insn), 2)))
463               return 1;
464           }
465         else if (uses_addressof (PATTERN (insn))
466                  || (REG_NOTES (insn) && uses_addressof (REG_NOTES (insn))))
467           return 1;
468       }
469   return 0;
470 }
471
472 /* Remove all REG_EQUIV notes found in the insn chain.  */
473
474 static void
475 purge_reg_equiv_notes ()
476 {
477   rtx insn;
478
479   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
480     {
481       while (1)
482         {
483           rtx note = find_reg_note (insn, REG_EQUIV, 0);
484           if (note)
485             {
486               /* Remove the note and keep looking at the notes for
487                  this insn.  */
488               remove_note (insn, note);
489               continue;
490             }
491           break;
492         }
493     }
494 }
495
496 /* Clear RTX_UNCHANGING_P flag of incoming argument MEMs.  */
497
498 static void
499 purge_mem_unchanging_flag (x)
500      rtx x;
501 {
502   RTX_CODE code;
503   int i, j;
504   const char *fmt;
505
506   if (x == NULL_RTX)
507     return;
508
509   code = GET_CODE (x);
510
511   if (code == MEM)
512     {
513       if (RTX_UNCHANGING_P (x)
514           && (XEXP (x, 0) == current_function_internal_arg_pointer
515               || (GET_CODE (XEXP (x, 0)) == PLUS
516                   && XEXP (XEXP (x, 0), 0) ==
517                      current_function_internal_arg_pointer
518                   && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
519         RTX_UNCHANGING_P (x) = 0;
520       return;
521     }
522
523   /* Scan all subexpressions.  */
524   fmt = GET_RTX_FORMAT (code);
525   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
526     {
527       if (*fmt == 'e')
528         purge_mem_unchanging_flag (XEXP (x, i));
529       else if (*fmt == 'E')
530         for (j = 0; j < XVECLEN (x, i); j++)
531           purge_mem_unchanging_flag (XVECEXP (x, i, j));
532     }
533 }
534
535 /* Replace the CALL_PLACEHOLDER with one of its children.  INSN should be
536    the CALL_PLACEHOLDER insn; USE tells which child to use.  */
537
538 void
539 replace_call_placeholder (insn, use)
540      rtx insn;
541      sibcall_use_t use;
542 {
543   if (use == sibcall_use_tail_recursion)
544     emit_insns_before (XEXP (PATTERN (insn), 2), insn);
545   else if (use == sibcall_use_sibcall)
546     emit_insns_before (XEXP (PATTERN (insn), 1), insn);
547   else if (use == sibcall_use_normal)
548     emit_insns_before (XEXP (PATTERN (insn), 0), insn);
549   else
550     abort ();
551
552   /* Turn off LABEL_PRESERVE_P for the tail recursion label if it
553      exists.  We only had to set it long enough to keep the jump
554      pass above from deleting it as unused.  */
555   if (XEXP (PATTERN (insn), 3))
556     LABEL_PRESERVE_P (XEXP (PATTERN (insn), 3)) = 0;
557
558   /* "Delete" the placeholder insn.  */
559   remove_insn (insn);
560 }
561
562 /* Given a (possibly empty) set of potential sibling or tail recursion call
563    sites, determine if optimization is possible.
564
565    Potential sibling or tail recursion calls are marked with CALL_PLACEHOLDER
566    insns.  The CALL_PLACEHOLDER insn holds chains of insns to implement a
567    normal call, sibling call or tail recursive call.
568
569    Replace the CALL_PLACEHOLDER with an appropriate insn chain.  */
570
571 void
572 optimize_sibling_and_tail_recursive_calls ()
573 {
574   rtx insn, insns;
575   basic_block alternate_exit = EXIT_BLOCK_PTR;
576   bool no_sibcalls_this_function = false;
577   int successful_sibling_call = 0;
578   int replaced_call_placeholder = 0;
579   edge e;
580
581   insns = get_insns ();
582
583   cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
584
585   /* If there are no basic blocks, then there is nothing to do.  */
586   if (n_basic_blocks == 0)
587     return;
588
589   /* If we are using sjlj exceptions, we may need to add a call to
590      _Unwind_SjLj_Unregister at exit of the function.  Which means
591      that we cannot do any sibcall transformations.  */
592   if (USING_SJLJ_EXCEPTIONS && current_function_has_exception_handlers ())
593     no_sibcalls_this_function = true;
594
595   return_value_pseudo = NULL_RTX;
596
597   /* Find the exit block.
598
599      It is possible that we have blocks which can reach the exit block
600      directly.  However, most of the time a block will jump (or fall into)
601      N_BASIC_BLOCKS - 1, which in turn falls into the exit block.  */
602   for (e = EXIT_BLOCK_PTR->pred;
603        e && alternate_exit == EXIT_BLOCK_PTR;
604        e = e->pred_next)
605     {
606       rtx insn;
607
608       if (e->dest != EXIT_BLOCK_PTR || e->succ_next != NULL)
609         continue;
610
611       /* Walk forwards through the last normal block and see if it
612          does nothing except fall into the exit block.  */
613       for (insn = EXIT_BLOCK_PTR->prev_bb->head;
614            insn;
615            insn = NEXT_INSN (insn))
616         {
617           rtx set;
618           /* This should only happen once, at the start of this block.  */
619           if (GET_CODE (insn) == CODE_LABEL)
620             continue;
621
622           if (GET_CODE (insn) == NOTE)
623             continue;
624
625           if (GET_CODE (insn) == INSN
626               && GET_CODE (PATTERN (insn)) == USE)
627             continue;
628
629           /* Exit block also may contain copy from pseudo containing
630              return value to hard register.  */
631           if (GET_CODE (insn) == INSN
632               && (set = single_set (insn))
633               && SET_DEST (set) == current_function_return_rtx
634               && REG_P (SET_SRC (set))
635               && !return_value_pseudo)
636             {
637               return_value_pseudo = SET_SRC (set);
638               continue;
639             }
640
641           break;
642         }
643
644       /* If INSN is zero, then the search walked all the way through the
645          block without hitting anything interesting.  This block is a
646          valid alternate exit block.  */
647       if (insn == NULL)
648         alternate_exit = e->src;
649       else
650         return_value_pseudo = NULL;
651     }
652
653   /* If the function uses ADDRESSOF, we can't (easily) determine
654      at this point if the value will end up on the stack.  */
655   no_sibcalls_this_function |= sequence_uses_addressof (insns);
656
657   /* Walk the insn chain and find any CALL_PLACEHOLDER insns.  We need to
658      select one of the insn sequences attached to each CALL_PLACEHOLDER.
659
660      The different sequences represent different ways to implement the call,
661      ie, tail recursion, sibling call or normal call.
662
663      Since we do not create nested CALL_PLACEHOLDERs, the scan
664      continues with the insn that was after a replaced CALL_PLACEHOLDER;
665      we don't rescan the replacement insns.  */
666   for (insn = insns; insn; insn = NEXT_INSN (insn))
667     {
668       if (GET_CODE (insn) == CALL_INSN
669           && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
670         {
671           int sibcall = (XEXP (PATTERN (insn), 1) != NULL_RTX);
672           int tailrecursion = (XEXP (PATTERN (insn), 2) != NULL_RTX);
673           basic_block call_block = BLOCK_FOR_INSN (insn);
674
675           /* alloca (until we have stack slot life analysis) inhibits
676              sibling call optimizations, but not tail recursion.
677              Similarly if we use varargs or stdarg since they implicitly
678              may take the address of an argument.  */
679           if (current_function_calls_alloca
680               || current_function_varargs || current_function_stdarg)
681             sibcall = 0;
682
683           /* See if there are any reasons we can't perform either sibling or
684              tail call optimizations.  We must be careful with stack slots
685              which are live at potential optimization sites.  */
686           if (no_sibcalls_this_function
687               /* ??? Overly conservative.  */
688               || frame_offset
689               /* Any function that calls setjmp might have longjmp called from
690                  any called function.  ??? We really should represent this
691                  properly in the CFG so that this needn't be special cased.  */
692               || current_function_calls_setjmp
693               /* Can't if more than one successor or single successor is not
694                  exit block.  These two tests prevent tail call optimization
695                  in the presense of active exception handlers.  */
696               || call_block->succ == NULL
697               || call_block->succ->succ_next != NULL
698               || (call_block->succ->dest != EXIT_BLOCK_PTR
699                   && call_block->succ->dest != alternate_exit)
700               /* If this call doesn't end the block, there are operations at
701                  the end of the block which we must execute after returning.  */
702               || ! call_ends_block_p (insn, call_block->end))
703             sibcall = 0, tailrecursion = 0;
704
705           /* Select a set of insns to implement the call and emit them.
706              Tail recursion is the most efficient, so select it over
707              a tail/sibling call.  */
708           if (sibcall)
709             successful_sibling_call = 1;
710
711           replaced_call_placeholder = 1;
712           replace_call_placeholder (insn,
713                                     tailrecursion != 0
714                                       ? sibcall_use_tail_recursion
715                                       : sibcall != 0
716                                          ? sibcall_use_sibcall
717                                          : sibcall_use_normal);
718         }
719     }
720
721   if (successful_sibling_call)
722     {
723       rtx insn;
724       tree arg;
725
726       /* A sibling call sequence invalidates any REG_EQUIV notes made for
727          this function's incoming arguments.
728
729          At the start of RTL generation we know the only REG_EQUIV notes
730          in the rtl chain are those for incoming arguments, so we can safely
731          flush any REG_EQUIV note.
732
733          This is (slight) overkill.  We could keep track of the highest
734          argument we clobber and be more selective in removing notes, but it
735          does not seem to be worth the effort.  */
736       purge_reg_equiv_notes ();
737
738       /* A sibling call sequence also may invalidate RTX_UNCHANGING_P
739          flag of some incoming arguments MEM RTLs, because it can write into
740          those slots.  We clear all those bits now.
741
742          This is (slight) overkill, we could keep track of which arguments
743          we actually write into.  */
744       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
745         {
746           if (INSN_P (insn))
747             purge_mem_unchanging_flag (PATTERN (insn));
748         }
749
750       /* Similarly, invalidate RTX_UNCHANGING_P for any incoming
751          arguments passed in registers.  */
752       for (arg = DECL_ARGUMENTS (current_function_decl);
753            arg;
754            arg = TREE_CHAIN (arg))
755         {
756           if (REG_P (DECL_RTL (arg)))
757             RTX_UNCHANGING_P (DECL_RTL (arg)) = false;
758         }
759     }
760
761   /* There may have been NOTE_INSN_BLOCK_{BEGIN,END} notes in the
762      CALL_PLACEHOLDER alternatives that we didn't emit.  Rebuild the
763      lexical block tree to correspond to the notes that still exist.  */
764   if (replaced_call_placeholder)
765     reorder_blocks ();
766
767   /* This information will be invalid after inline expansion.  Kill it now.  */
768   free_basic_block_vars (0);
769   free_EXPR_LIST_list (&tail_recursion_label_list);
770 }