-
Notifications
You must be signed in to change notification settings - Fork 3
/
calls.c
3203 lines (2704 loc) · 102 KB
/
calls.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Convert function calls to rtl insns, for GNU C compiler.
Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "rtl.h"
#include "tree.h"
#include "flags.h"
#include "expr.h"
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "insn-flags.h"
/* Decide whether a function's arguments should be processed
from first to last or from last to first.
They should if the stack and args grow in opposite directions, but
only if we have push insns. */
#ifdef PUSH_ROUNDING
#if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
#define PUSH_ARGS_REVERSED /* If it's last to first */
#endif
#endif
/* Like STACK_BOUNDARY but in units of bytes, not bits. */
#define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
/* Data structure and subroutines used within expand_call. */
struct arg_data
{
/* Tree node for this argument. */
tree tree_value;
/* Mode for value; TYPE_MODE unless promoted. */
enum machine_mode mode;
/* Current RTL value for argument, or 0 if it isn't precomputed. */
rtx value;
/* Initially-compute RTL value for argument; only for const functions. */
rtx initial_value;
/* Register to pass this argument in, 0 if passed on stack, or an
EXPR_LIST if the arg is to be copied into multiple different
registers. */
rtx reg;
/* If REG was promoted from the actual mode of the argument expression,
indicates whether the promotion is sign- or zero-extended. */
int unsignedp;
/* Number of registers to use. 0 means put the whole arg in registers.
Also 0 if not passed in registers. */
int partial;
/* Non-zero if argument must be passed on stack.
Note that some arguments may be passed on the stack
even though pass_on_stack is zero, just because FUNCTION_ARG says so.
pass_on_stack identifies arguments that *cannot* go in registers. */
int pass_on_stack;
/* Offset of this argument from beginning of stack-args. */
struct args_size offset;
/* Similar, but offset to the start of the stack slot. Different from
OFFSET if this arg pads downward. */
struct args_size slot_offset;
/* Size of this argument on the stack, rounded up for any padding it gets,
parts of the argument passed in registers do not count.
If REG_PARM_STACK_SPACE is defined, then register parms
are counted here as well. */
struct args_size size;
/* Location on the stack at which parameter should be stored. The store
has already been done if STACK == VALUE. */
rtx stack;
/* Location on the stack of the start of this argument slot. This can
differ from STACK if this arg pads downward. This location is known
to be aligned to FUNCTION_ARG_BOUNDARY. */
rtx stack_slot;
#ifdef ACCUMULATE_OUTGOING_ARGS
/* Place that this stack area has been saved, if needed. */
rtx save_area;
#endif
#ifdef STRICT_ALIGNMENT
/* If an argument's alignment does not permit direct copying into registers,
copy in smaller-sized pieces into pseudos. These are stored in a
block pointed to by this field. The next field says how many
word-sized pseudos we made. */
rtx *aligned_regs;
int n_aligned_regs;
#endif
};
#ifdef ACCUMULATE_OUTGOING_ARGS
/* A vector of one char per byte of stack space. A byte if non-zero if
the corresponding stack location has been used.
This vector is used to prevent a function call within an argument from
clobbering any stack already set up. */
static char *stack_usage_map;
/* Size of STACK_USAGE_MAP. */
static int highest_outgoing_arg_in_use;
/* stack_arg_under_construction is nonzero when an argument may be
initialized with a constructor call (including a C function that
returns a BLKmode struct) and expand_call must take special action
to make sure the object being constructed does not overlap the
argument list for the constructor call. */
int stack_arg_under_construction;
#endif
static int calls_function PROTO((tree, int));
static int calls_function_1 PROTO((tree, int));
static void emit_call_1 PROTO((rtx, tree, tree, int, int, rtx, rtx,
int, rtx, int));
static void store_one_arg PROTO ((struct arg_data *, rtx, int, int,
tree, int));
/* If WHICH is 1, return 1 if EXP contains a call to the built-in function
`alloca'.
If WHICH is 0, return 1 if EXP contains a call to any function.
Actually, we only need return 1 if evaluating EXP would require pushing
arguments on the stack, but that is too difficult to compute, so we just
assume any function call might require the stack. */
static tree calls_function_save_exprs;
static int
calls_function (exp, which)
tree exp;
int which;
{
int val;
calls_function_save_exprs = 0;
val = calls_function_1 (exp, which);
calls_function_save_exprs = 0;
return val;
}
static int
calls_function_1 (exp, which)
tree exp;
int which;
{
register int i;
enum tree_code code = TREE_CODE (exp);
int type = TREE_CODE_CLASS (code);
int length = tree_code_length[(int) code];
/* If this code is language-specific, we don't know what it will do. */
if ((int) code >= NUM_TREE_CODES)
return 1;
/* Only expressions and references can contain calls. */
if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
&& type != 'b')
return 0;
switch (code)
{
case CALL_EXPR:
if (which == 0)
return 1;
else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
&& (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
== FUNCTION_DECL))
{
tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
if ((DECL_BUILT_IN (fndecl)
&& DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
|| (DECL_SAVED_INSNS (fndecl)
&& (FUNCTION_FLAGS (DECL_SAVED_INSNS (fndecl))
& FUNCTION_FLAGS_CALLS_ALLOCA)))
return 1;
}
/* Third operand is RTL. */
length = 2;
break;
case SAVE_EXPR:
if (SAVE_EXPR_RTL (exp) != 0)
return 0;
if (value_member (exp, calls_function_save_exprs))
return 0;
calls_function_save_exprs = tree_cons (NULL_TREE, exp,
calls_function_save_exprs);
return (TREE_OPERAND (exp, 0) != 0
&& calls_function_1 (TREE_OPERAND (exp, 0), which));
case BLOCK:
{
register tree local;
for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
if (DECL_INITIAL (local) != 0
&& calls_function_1 (DECL_INITIAL (local), which))
return 1;
}
{
register tree subblock;
for (subblock = BLOCK_SUBBLOCKS (exp);
subblock;
subblock = TREE_CHAIN (subblock))
if (calls_function_1 (subblock, which))
return 1;
}
return 0;
case METHOD_CALL_EXPR:
length = 3;
break;
case WITH_CLEANUP_EXPR:
length = 1;
break;
case RTL_EXPR:
return 0;
}
for (i = 0; i < length; i++)
if (TREE_OPERAND (exp, i) != 0
&& calls_function_1 (TREE_OPERAND (exp, i), which))
return 1;
return 0;
}
/* Force FUNEXP into a form suitable for the address of a CALL,
and return that as an rtx. Also load the static chain register
if FNDECL is a nested function.
CALL_FUSAGE points to a variable holding the prospective
CALL_INSN_FUNCTION_USAGE information. */
rtx
prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
rtx funexp;
tree fndecl;
rtx *call_fusage;
int reg_parm_seen;
{
rtx static_chain_value = 0;
funexp = protect_from_queue (funexp, 0);
if (fndecl != 0)
/* Get possible static chain value for nested function in C. */
static_chain_value = lookup_static_chain (fndecl);
/* Make a valid memory address and copy constants thru pseudo-regs,
but not for a constant address if -fno-function-cse. */
if (GET_CODE (funexp) != SYMBOL_REF)
funexp =
#ifdef SMALL_REGISTER_CLASSES
/* If we are using registers for parameters, force the
function address into a register now. */
reg_parm_seen ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
:
#endif
memory_address (FUNCTION_MODE, funexp);
else
{
#ifndef NO_FUNCTION_CSE
if (optimize && ! flag_no_function_cse)
#ifdef NO_RECURSIVE_FUNCTION_CSE
if (fndecl != current_function_decl)
#endif
funexp = force_reg (Pmode, funexp);
#endif
}
if (static_chain_value != 0)
{
emit_move_insn (static_chain_rtx, static_chain_value);
if (GET_CODE (static_chain_rtx) == REG)
use_reg (call_fusage, static_chain_rtx);
}
return funexp;
}
/* Generate instructions to call function FUNEXP,
and optionally pop the results.
The CALL_INSN is the first insn generated.
FNDECL is the declaration node of the function. This is given ot the
macro RETURN_POPS_ARGS to determine whether this function pops its own args.
FUNTYPE is the data type of the function, or, for a library call,
the identifier for the name of the call. This is given to the
macro RETURN_POPS_ARGS to determine whether this function pops its own args.
STACK_SIZE is the number of bytes of arguments on the stack,
rounded up to STACK_BOUNDARY; zero if the size is variable.
This is both to put into the call insn and
to generate explicit popping code if necessary.
STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
It is zero if this call doesn't want a structure value.
NEXT_ARG_REG is the rtx that results from executing
FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
just after all the args have had their registers assigned.
This could be whatever you like, but normally it is the first
arg-register beyond those used for args in this call,
or 0 if all the arg-registers are used in this call.
It is passed on to `gen_call' so you can put this info in the call insn.
VALREG is a hard register in which a value is returned,
or 0 if the call does not return a value.
OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
the args to this call were processed.
We restore `inhibit_defer_pop' to that value.
CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
denote registers used by the called function.
IS_CONST is true if this is a `const' call. */
static void
emit_call_1 (funexp, fndecl, funtype, stack_size, struct_value_size,
next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
is_const)
rtx funexp;
tree fndecl;
tree funtype;
int stack_size;
int struct_value_size;
rtx next_arg_reg;
rtx valreg;
int old_inhibit_defer_pop;
rtx call_fusage;
int is_const;
{
rtx stack_size_rtx = GEN_INT (stack_size);
rtx struct_value_size_rtx = GEN_INT (struct_value_size);
rtx call_insn;
int already_popped = 0;
/* Ensure address is valid. SYMBOL_REF is already valid, so no need,
and we don't want to load it into a register as an optimization,
because prepare_call_address already did it if it should be done. */
if (GET_CODE (funexp) != SYMBOL_REF)
funexp = memory_address (FUNCTION_MODE, funexp);
#ifndef ACCUMULATE_OUTGOING_ARGS
#if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
if (HAVE_call_pop && HAVE_call_value_pop
&& (RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0
|| stack_size == 0))
{
rtx n_pop = GEN_INT (RETURN_POPS_ARGS (fndecl, funtype, stack_size));
rtx pat;
/* If this subroutine pops its own args, record that in the call insn
if possible, for the sake of frame pointer elimination. */
if (valreg)
pat = gen_call_value_pop (valreg,
gen_rtx (MEM, FUNCTION_MODE, funexp),
stack_size_rtx, next_arg_reg, n_pop);
else
pat = gen_call_pop (gen_rtx (MEM, FUNCTION_MODE, funexp),
stack_size_rtx, next_arg_reg, n_pop);
emit_call_insn (pat);
already_popped = 1;
}
else
#endif
#endif
#if defined (HAVE_call) && defined (HAVE_call_value)
if (HAVE_call && HAVE_call_value)
{
if (valreg)
emit_call_insn (gen_call_value (valreg,
gen_rtx (MEM, FUNCTION_MODE, funexp),
stack_size_rtx, next_arg_reg,
NULL_RTX));
else
emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp),
stack_size_rtx, next_arg_reg,
struct_value_size_rtx));
}
else
#endif
abort ();
/* Find the CALL insn we just emitted. */
for (call_insn = get_last_insn ();
call_insn && GET_CODE (call_insn) != CALL_INSN;
call_insn = PREV_INSN (call_insn))
;
if (! call_insn)
abort ();
/* Put the register usage information on the CALL. If there is already
some usage information, put ours at the end. */
if (CALL_INSN_FUNCTION_USAGE (call_insn))
{
rtx link;
for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
link = XEXP (link, 1))
;
XEXP (link, 1) = call_fusage;
}
else
CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
/* If this is a const call, then set the insn's unchanging bit. */
if (is_const)
CONST_CALL_P (call_insn) = 1;
/* Restore this now, so that we do defer pops for this call's args
if the context of the call as a whole permits. */
inhibit_defer_pop = old_inhibit_defer_pop;
#ifndef ACCUMULATE_OUTGOING_ARGS
/* If returning from the subroutine does not automatically pop the args,
we need an instruction to pop them sooner or later.
Perhaps do it now; perhaps just record how much space to pop later.
If returning from the subroutine does pop the args, indicate that the
stack pointer will be changed. */
if (stack_size != 0 && RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0)
{
if (!already_popped)
CALL_INSN_FUNCTION_USAGE (call_insn) =
gen_rtx (EXPR_LIST, VOIDmode,
gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx),
CALL_INSN_FUNCTION_USAGE (call_insn));
stack_size -= RETURN_POPS_ARGS (fndecl, funtype, stack_size);
stack_size_rtx = GEN_INT (stack_size);
}
if (stack_size != 0)
{
if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
pending_stack_adjust += stack_size;
else
adjust_stack (stack_size_rtx);
}
#endif
}
/* Generate all the code for a function call
and return an rtx for its value.
Store the value in TARGET (specified as an rtx) if convenient.
If the value is stored in TARGET then TARGET is returned.
If IGNORE is nonzero, then we ignore the value of the function call. */
rtx
expand_call (exp, target, ignore)
tree exp;
rtx target;
int ignore;
{
/* List of actual parameters. */
tree actparms = TREE_OPERAND (exp, 1);
/* RTX for the function to be called. */
rtx funexp;
/* Tree node for the function to be called (not the address!). */
tree funtree;
/* Data type of the function. */
tree funtype;
/* Declaration of the function being called,
or 0 if the function is computed (not known by name). */
tree fndecl = 0;
char *name = 0;
/* Register in which non-BLKmode value will be returned,
or 0 if no value or if value is BLKmode. */
rtx valreg;
/* Address where we should return a BLKmode value;
0 if value not BLKmode. */
rtx structure_value_addr = 0;
/* Nonzero if that address is being passed by treating it as
an extra, implicit first parameter. Otherwise,
it is passed by being copied directly into struct_value_rtx. */
int structure_value_addr_parm = 0;
/* Size of aggregate value wanted, or zero if none wanted
or if we are using the non-reentrant PCC calling convention
or expecting the value in registers. */
int struct_value_size = 0;
/* Nonzero if called function returns an aggregate in memory PCC style,
by returning the address of where to find it. */
int pcc_struct_value = 0;
/* Number of actual parameters in this call, including struct value addr. */
int num_actuals;
/* Number of named args. Args after this are anonymous ones
and they must all go on the stack. */
int n_named_args;
/* Count arg position in order args appear. */
int argpos;
/* Vector of information about each argument.
Arguments are numbered in the order they will be pushed,
not the order they are written. */
struct arg_data *args;
/* Total size in bytes of all the stack-parms scanned so far. */
struct args_size args_size;
/* Size of arguments before any adjustments (such as rounding). */
struct args_size original_args_size;
/* Data on reg parms scanned so far. */
CUMULATIVE_ARGS args_so_far;
/* Nonzero if a reg parm has been scanned. */
int reg_parm_seen;
/* Nonzero if this is an indirect function call. */
int current_call_is_indirect = 0;
/* Nonzero if we must avoid push-insns in the args for this call.
If stack space is allocated for register parameters, but not by the
caller, then it is preallocated in the fixed part of the stack frame.
So the entire argument block must then be preallocated (i.e., we
ignore PUSH_ROUNDING in that case). */
#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
int must_preallocate = 1;
#else
#ifdef PUSH_ROUNDING
int must_preallocate = 0;
#else
int must_preallocate = 1;
#endif
#endif
/* Size of the stack reserved for parameter registers. */
int reg_parm_stack_space = 0;
/* 1 if scanning parms front to back, -1 if scanning back to front. */
int inc;
/* Address of space preallocated for stack parms
(on machines that lack push insns), or 0 if space not preallocated. */
rtx argblock = 0;
/* Nonzero if it is plausible that this is a call to alloca. */
int may_be_alloca;
/* Nonzero if this is a call to setjmp or a related function. */
int returns_twice;
/* Nonzero if this is a call to `longjmp'. */
int is_longjmp;
/* Nonzero if this is a call to an inline function. */
int is_integrable = 0;
/* Nonzero if this is a call to a `const' function.
Note that only explicitly named functions are handled as `const' here. */
int is_const = 0;
/* Nonzero if this is a call to a `volatile' function. */
int is_volatile = 0;
#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
/* Define the boundary of the register parm stack space that needs to be
save, if any. */
int low_to_save = -1, high_to_save;
rtx save_area = 0; /* Place that it is saved */
#endif
#ifdef ACCUMULATE_OUTGOING_ARGS
int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
char *initial_stack_usage_map = stack_usage_map;
#endif
rtx old_stack_level = 0;
int old_pending_adj = 0;
int old_stack_arg_under_construction;
int old_inhibit_defer_pop = inhibit_defer_pop;
tree old_cleanups = cleanups_this_call;
rtx call_fusage = 0;
register tree p;
register int i, j;
/* See if we can find a DECL-node for the actual function.
As a result, decide whether this is a call to an integrable function. */
p = TREE_OPERAND (exp, 0);
if (TREE_CODE (p) == ADDR_EXPR)
{
fndecl = TREE_OPERAND (p, 0);
if (TREE_CODE (fndecl) != FUNCTION_DECL)
fndecl = 0;
else
{
if (!flag_no_inline
&& fndecl != current_function_decl
&& DECL_INLINE (fndecl)
&& DECL_SAVED_INSNS (fndecl))
is_integrable = 1;
else if (! TREE_ADDRESSABLE (fndecl))
{
/* In case this function later becomes inlinable,
record that there was already a non-inline call to it.
Use abstraction instead of setting TREE_ADDRESSABLE
directly. */
if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline)
{
warning_with_decl (fndecl, "can't inline call to `%s'");
warning ("called from here");
}
mark_addressable (fndecl);
}
if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
&& TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
is_const = 1;
if (TREE_THIS_VOLATILE (fndecl))
is_volatile = 1;
}
}
/* If we don't have specific function to call, see if we have a
constant or `noreturn' function from the type. */
if (fndecl == 0)
{
is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
}
#ifdef REG_PARM_STACK_SPACE
#ifdef MAYBE_REG_PARM_STACK_SPACE
reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
#else
reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
#endif
#endif
/* Warn if this value is an aggregate type,
regardless of which calling convention we are using for it. */
if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
warning ("function call has aggregate value");
/* Set up a place to return a structure. */
/* Cater to broken compilers. */
if (aggregate_value_p (exp))
{
/* This call returns a big structure. */
is_const = 0;
#ifdef PCC_STATIC_STRUCT_RETURN
{
pcc_struct_value = 1;
/* Easier than making that case work right. */
if (is_integrable)
{
/* In case this is a static function, note that it has been
used. */
if (! TREE_ADDRESSABLE (fndecl))
mark_addressable (fndecl);
is_integrable = 0;
}
}
#else /* not PCC_STATIC_STRUCT_RETURN */
{
struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
if (target && GET_CODE (target) == MEM)
structure_value_addr = XEXP (target, 0);
else
{
/* Assign a temporary on the stack to hold the value. */
/* For variable-sized objects, we must be called with a target
specified. If we were to allocate space on the stack here,
we would have no way of knowing when to free it. */
if (struct_value_size < 0)
abort ();
structure_value_addr
= XEXP (assign_stack_temp (BLKmode, struct_value_size, 1), 0);
MEM_IN_STRUCT_P (structure_value_addr)
= AGGREGATE_TYPE_P (TREE_TYPE (exp));
target = 0;
}
}
#endif /* not PCC_STATIC_STRUCT_RETURN */
}
/* If called function is inline, try to integrate it. */
if (is_integrable)
{
rtx temp;
rtx before_call = get_last_insn ();
temp = expand_inline_function (fndecl, actparms, target,
ignore, TREE_TYPE (exp),
structure_value_addr);
/* If inlining succeeded, return. */
if ((HOST_WIDE_INT) temp != -1)
{
if (flag_short_temps)
{
/* Perform all cleanups needed for the arguments of this
call (i.e. destructors in C++). It is ok if these
destructors clobber RETURN_VALUE_REG, because the
only time we care about this is when TARGET is that
register. But in C++, we take care to never return
that register directly. */
expand_cleanups_to (old_cleanups);
}
#ifdef ACCUMULATE_OUTGOING_ARGS
/* If the outgoing argument list must be preserved, push
the stack before executing the inlined function if it
makes any calls. */
for (i = reg_parm_stack_space - 1; i >= 0; i--)
if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
break;
if (stack_arg_under_construction || i >= 0)
{
rtx insn = NEXT_INSN (before_call), seq;
/* Look for a call in the inline function code.
If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
nonzero then there is a call and it is not necessary
to scan the insns. */
if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
for (; insn; insn = NEXT_INSN (insn))
if (GET_CODE (insn) == CALL_INSN)
break;
if (insn)
{
/* Reserve enough stack space so that the largest
argument list of any function call in the inline
function does not overlap the argument list being
evaluated. This is usually an overestimate because
allocate_dynamic_stack_space reserves space for an
outgoing argument list in addition to the requested
space, but there is no way to ask for stack space such
that an argument list of a certain length can be
safely constructed. */
int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl));
#ifdef REG_PARM_STACK_SPACE
/* Add the stack space reserved for register arguments
in the inline function. What is really needed is the
largest value of reg_parm_stack_space in the inline
function, but that is not available. Using the current
value of reg_parm_stack_space is wrong, but gives
correct results on all supported machines. */
adjust += reg_parm_stack_space;
#endif
start_sequence ();
emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
allocate_dynamic_stack_space (GEN_INT (adjust),
NULL_RTX, BITS_PER_UNIT);
seq = get_insns ();
end_sequence ();
emit_insns_before (seq, NEXT_INSN (before_call));
emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
}
}
#endif
/* If the result is equivalent to TARGET, return TARGET to simplify
checks in store_expr. They can be equivalent but not equal in the
case of a function that returns BLKmode. */
if (temp != target && rtx_equal_p (temp, target))
return target;
return temp;
}
/* If inlining failed, mark FNDECL as needing to be compiled
separately after all. If function was declared inline,
give a warning. */
if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
&& ! TREE_ADDRESSABLE (fndecl))
{
warning_with_decl (fndecl, "inlining failed in call to `%s'");
warning ("called from here");
}
mark_addressable (fndecl);
}
/* When calling a const function, we must pop the stack args right away,
so that the pop is deleted or moved with the call. */
if (is_const)
NO_DEFER_POP;
function_call_count++;
if (fndecl && DECL_NAME (fndecl))
name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
/* On some machines (such as the PA) indirect calls have a different
calling convention than normal calls. FUNCTION_ARG in the target
description can look at current_call_is_indirect to determine which
calling convention to use. */
current_call_is_indirect = (fndecl == 0);
#if 0
= TREE_CODE (TREE_OPERAND (exp, 0)) == NON_LVALUE_EXPR ? 1 : 0;
#endif
#if 0
/* Unless it's a call to a specific function that isn't alloca,
if it has one argument, we must assume it might be alloca. */
may_be_alloca =
(!(fndecl != 0 && strcmp (name, "alloca"))
&& actparms != 0
&& TREE_CHAIN (actparms) == 0);
#else
/* We assume that alloca will always be called by name. It
makes no sense to pass it as a pointer-to-function to
anything that does not understand its behavior. */
may_be_alloca =
(name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
&& name[0] == 'a'
&& ! strcmp (name, "alloca"))
|| (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
&& name[0] == '_'
&& ! strcmp (name, "__builtin_alloca"))));
#endif
/* See if this is a call to a function that can return more than once
or a call to longjmp. */
returns_twice = 0;
is_longjmp = 0;
if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15)
{
char *tname = name;
/* Disregard prefix _, __ or __x. */
if (name[0] == '_')
{
if (name[1] == '_' && name[2] == 'x')
tname += 3;
else if (name[1] == '_')
tname += 2;
else
tname += 1;
}
if (tname[0] == 's')
{
returns_twice
= ((tname[1] == 'e'
&& (! strcmp (tname, "setjmp")
|| ! strcmp (tname, "setjmp_syscall")))
|| (tname[1] == 'i'
&& ! strcmp (tname, "sigsetjmp"))
|| (tname[1] == 'a'
&& ! strcmp (tname, "savectx")));
if (tname[1] == 'i'
&& ! strcmp (tname, "siglongjmp"))
is_longjmp = 1;
}
else if ((tname[0] == 'q' && tname[1] == 's'
&& ! strcmp (tname, "qsetjmp"))
|| (tname[0] == 'v' && tname[1] == 'f'
&& ! strcmp (tname, "vfork")))
returns_twice = 1;
else if (tname[0] == 'l' && tname[1] == 'o'
&& ! strcmp (tname, "longjmp"))
is_longjmp = 1;
}
if (may_be_alloca)
current_function_calls_alloca = 1;
/* Don't let pending stack adjusts add up to too much.
Also, do all pending adjustments now
if there is any chance this might be a call to alloca. */
if (pending_stack_adjust >= 32
|| (pending_stack_adjust > 0 && may_be_alloca))
do_pending_stack_adjust ();
/* Operand 0 is a pointer-to-function; get the type of the function. */
funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
if (TREE_CODE (funtype) != POINTER_TYPE)
abort ();
funtype = TREE_TYPE (funtype);
/* Push the temporary stack slot level so that we can free any temporaries
we make. */
push_temp_slots ();
/* Start updating where the next arg would go. */
INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX);
/* If struct_value_rtx is 0, it means pass the address
as if it were an extra parameter. */
if (structure_value_addr && struct_value_rtx == 0)
{
/* If structure_value_addr is a REG other than
virtual_outgoing_args_rtx, we can use always use it. If it
is not a REG, we must always copy it into a register.
If it is virtual_outgoing_args_rtx, we must copy it to another
register in some cases. */
rtx temp = (GET_CODE (structure_value_addr) != REG
#ifdef ACCUMULATE_OUTGOING_ARGS
|| (stack_arg_under_construction
&& structure_value_addr == virtual_outgoing_args_rtx)
#endif
? copy_addr_to_reg (structure_value_addr)
: structure_value_addr);
actparms
= tree_cons (error_mark_node,
make_tree (build_pointer_type (TREE_TYPE (funtype)),
temp),
actparms);
structure_value_addr_parm = 1;
}
/* Count the arguments and set NUM_ACTUALS. */
for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
num_actuals = i;
/* Compute number of named args.
Normally, don't include the last named arg if anonymous args follow.
We do include the last named arg if STRICT_ARGUMENT_NAMING is defined.
(If no anonymous args follow, the result of list_length is actually
one too large. This is harmless.)
If SETUP_INCOMING_VARARGS is defined and STRICT_ARGUMENT_NAMING is not,
this machine will be able to place unnamed args that were passed in
registers into the stack. So treat all args as named. This allows the
insns emitting for a specific argument list to be independent of the
function declaration.
If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
way to pass unnamed args in registers, so we must force them into
memory. */
#if !defined(SETUP_INCOMING_VARARGS) || defined(STRICT_ARGUMENT_NAMING)
if (TYPE_ARG_TYPES (funtype) != 0)
n_named_args
= (list_length (TYPE_ARG_TYPES (funtype))
#ifndef STRICT_ARGUMENT_NAMING
/* Don't include the last named arg. */
- 1
#endif
/* Count the struct value address, if it is passed as a parm. */
+ structure_value_addr_parm);
else
#endif
/* If we know nothing, treat all args as named. */
n_named_args = num_actuals;
/* Make a vector to hold all the information about each arg. */
args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
bzero ((char *) args, num_actuals * sizeof (struct arg_data));
args_size.constant = 0;
args_size.var = 0;
/* In this loop, we consider args in the order they are written.
We fill up ARGS from the front or from the back if necessary
so that in any case the first arg to be pushed ends up at the front. */
#ifdef PUSH_ARGS_REVERSED
i = num_actuals - 1, inc = -1;
/* In this case, must reverse order of args
so that we compute and push the last arg first. */
#else
i = 0, inc = 1;
#endif
/* I counts args in order (to be) pushed; ARGPOS counts in order written. */
for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
{
tree type = TREE_TYPE (TREE_VALUE (p));