forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcalls.c
5600 lines (4805 loc) · 176 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-2017 Free Software Foundation, Inc.
This file is part of GCC.
GCC 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 3, or (at your option) any later
version.
GCC 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 GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "rtl.h"
#include "tree.h"
#include "gimple.h"
#include "predict.h"
#include "memmodel.h"
#include "tm_p.h"
#include "stringpool.h"
#include "expmed.h"
#include "optabs.h"
#include "emit-rtl.h"
#include "cgraph.h"
#include "diagnostic-core.h"
#include "fold-const.h"
#include "stor-layout.h"
#include "varasm.h"
#include "internal-fn.h"
#include "dojump.h"
#include "explow.h"
#include "calls.h"
#include "expr.h"
#include "output.h"
#include "langhooks.h"
#include "except.h"
#include "dbgcnt.h"
#include "rtl-iter.h"
#include "tree-chkp.h"
#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "rtl-chkp.h"
#include "intl.h"
#include "stringpool.h"
#include "attribs.h"
/* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
#define STACK_BYTES (PREFERRED_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. */
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
PARALLEL if the arg is to be copied into multiple non-contiguous
registers. */
rtx reg;
/* Register to pass this argument in when generating tail call sequence.
This is not the same register as for normal calls on machines with
register windows. */
rtx tail_call_reg;
/* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
form for emit_group_move. */
rtx parallel_value;
/* If value is passed in neither reg nor stack, this field holds a number
of a special slot to be used. */
rtx special_slot;
/* For pointer bounds hold an index of parm bounds are bound to. -1 if
there is no such pointer. */
int pointer_arg;
/* If pointer_arg refers a structure, then pointer_offset holds an offset
of a pointer in this structure. */
int pointer_offset;
/* 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 bytes to put in registers. 0 means put the whole arg
in registers. Also 0 if not passed in registers. */
int partial;
/* Nonzero 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;
/* Some fields packaged up for locate_and_pad_parm. */
struct locate_and_pad_arg_data locate;
/* 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 TARGET_FUNCTION_ARG_BOUNDARY. */
rtx stack_slot;
/* Place that this stack area has been saved, if needed. */
rtx save_area;
/* 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;
};
/* A vector of one char per byte of stack space. A byte if nonzero 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;
/* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
stack location's tail call argument has been already stored into the stack.
This bitmap is used to prevent sibling call optimization if function tries
to use parent's incoming argument slots when they have been already
overwritten with tail call arguments. */
static sbitmap stored_args_map;
/* 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. */
static int stack_arg_under_construction;
static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
HOST_WIDE_INT, rtx, rtx, int, rtx, int,
cumulative_args_t);
static void precompute_register_parameters (int, struct arg_data *, int *);
static void store_bounds (struct arg_data *, struct arg_data *);
static int store_one_arg (struct arg_data *, rtx, int, int, int);
static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
static int finalize_must_preallocate (int, int, struct arg_data *,
struct args_size *);
static void precompute_arguments (int, struct arg_data *);
static int compute_argument_block_size (int, struct args_size *, tree, tree, int);
static void initialize_argument_information (int, struct arg_data *,
struct args_size *, int,
tree, tree,
tree, tree, cumulative_args_t, int,
rtx *, int *, int *, int *,
bool *, bool);
static void compute_argument_addresses (struct arg_data *, rtx, int);
static rtx rtx_for_function_call (tree, tree);
static void load_register_parameters (struct arg_data *, int, rtx *, int,
int, int *);
static int special_function_p (const_tree, int);
static int check_sibcall_argument_overlap_1 (rtx);
static int check_sibcall_argument_overlap (rtx_insn *, struct arg_data *, int);
static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
unsigned int);
static tree split_complex_types (tree);
#ifdef REG_PARM_STACK_SPACE
static rtx save_fixed_argument_area (int, rtx, int *, int *);
static void restore_fixed_argument_area (rtx, rtx, int, int);
#endif
/* 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 (tree fndecl_or_type, rtx funexp, rtx static_chain_value,
rtx *call_fusage, int reg_parm_seen, int flags)
{
/* Make a valid memory address and copy constants through pseudo-regs,
but not for a constant address if -fno-function-cse. */
if (GET_CODE (funexp) != SYMBOL_REF)
{
/* If it's an indirect call by descriptor, generate code to perform
runtime identification of the pointer and load the descriptor. */
if ((flags & ECF_BY_DESCRIPTOR) && !flag_trampolines)
{
const int bit_val = targetm.calls.custom_function_descriptors;
rtx call_lab = gen_label_rtx ();
gcc_assert (fndecl_or_type && TYPE_P (fndecl_or_type));
fndecl_or_type
= build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, NULL_TREE,
fndecl_or_type);
DECL_STATIC_CHAIN (fndecl_or_type) = 1;
rtx chain = targetm.calls.static_chain (fndecl_or_type, false);
if (GET_MODE (funexp) != Pmode)
funexp = convert_memory_address (Pmode, funexp);
/* Avoid long live ranges around function calls. */
funexp = copy_to_mode_reg (Pmode, funexp);
if (REG_P (chain))
emit_insn (gen_rtx_CLOBBER (VOIDmode, chain));
/* Emit the runtime identification pattern. */
rtx mask = gen_rtx_AND (Pmode, funexp, GEN_INT (bit_val));
emit_cmp_and_jump_insns (mask, const0_rtx, EQ, NULL_RTX, Pmode, 1,
call_lab);
/* Statically predict the branch to very likely taken. */
rtx_insn *insn = get_last_insn ();
if (JUMP_P (insn))
predict_insn_def (insn, PRED_BUILTIN_EXPECT, TAKEN);
/* Load the descriptor. */
rtx mem = gen_rtx_MEM (ptr_mode,
plus_constant (Pmode, funexp, - bit_val));
MEM_NOTRAP_P (mem) = 1;
mem = convert_memory_address (Pmode, mem);
emit_move_insn (chain, mem);
mem = gen_rtx_MEM (ptr_mode,
plus_constant (Pmode, funexp,
POINTER_SIZE / BITS_PER_UNIT
- bit_val));
MEM_NOTRAP_P (mem) = 1;
mem = convert_memory_address (Pmode, mem);
emit_move_insn (funexp, mem);
emit_label (call_lab);
if (REG_P (chain))
{
use_reg (call_fusage, chain);
STATIC_CHAIN_REG_P (chain) = 1;
}
/* Make sure we're not going to be overwritten below. */
gcc_assert (!static_chain_value);
}
/* If we are using registers for parameters, force the
function address into a register now. */
funexp = ((reg_parm_seen
&& targetm.small_register_classes_for_mode_p (FUNCTION_MODE))
? force_not_mem (memory_address (FUNCTION_MODE, funexp))
: memory_address (FUNCTION_MODE, funexp));
}
else
{
/* funexp could be a SYMBOL_REF represents a function pointer which is
of ptr_mode. In this case, it should be converted into address mode
to be a valid address for memory rtx pattern. See PR 64971. */
if (GET_MODE (funexp) != Pmode)
funexp = convert_memory_address (Pmode, funexp);
if (!(flags & ECF_SIBCALL))
{
if (!NO_FUNCTION_CSE && optimize && ! flag_no_function_cse)
funexp = force_reg (Pmode, funexp);
}
}
if (static_chain_value != 0
&& (TREE_CODE (fndecl_or_type) != FUNCTION_DECL
|| DECL_STATIC_CHAIN (fndecl_or_type)))
{
rtx chain;
chain = targetm.calls.static_chain (fndecl_or_type, false);
static_chain_value = convert_memory_address (Pmode, static_chain_value);
emit_move_insn (chain, static_chain_value);
if (REG_P (chain))
{
use_reg (call_fusage, chain);
STATIC_CHAIN_REG_P (chain) = 1;
}
}
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 to the
hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
its own args.
FUNTYPE is the data type of the function. This is given to the hook
TARGET_RETURN_POPS_ARGS to determine whether this function pops its
own args. We used to allow an identifier for library functions, but
that doesn't work when the return type is an aggregate type and the
calling convention says that the pointer to this aggregate is to be
popped by the callee.
STACK_SIZE is the number of bytes of arguments on the stack,
ROUNDED_STACK_SIZE is that number rounded up to
PREFERRED_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
targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true)
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. */
static void
emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED,
tree funtype ATTRIBUTE_UNUSED,
HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
HOST_WIDE_INT rounded_stack_size,
HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
cumulative_args_t args_so_far ATTRIBUTE_UNUSED)
{
rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
rtx call, funmem, pat;
int already_popped = 0;
HOST_WIDE_INT n_popped = 0;
/* Sibling call patterns never pop arguments (no sibcall(_value)_pop
patterns exist). Any popping that the callee does on return will
be from our caller's frame rather than ours. */
if (!(ecf_flags & ECF_SIBCALL))
{
n_popped += targetm.calls.return_pops_args (fndecl, funtype, stack_size);
#ifdef CALL_POPS_ARGS
n_popped += CALL_POPS_ARGS (*get_cumulative_args (args_so_far));
#endif
}
/* 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);
funmem = gen_rtx_MEM (FUNCTION_MODE, funexp);
if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL)
{
tree t = fndecl;
/* Although a built-in FUNCTION_DECL and its non-__builtin
counterpart compare equal and get a shared mem_attrs, they
produce different dump output in compare-debug compilations,
if an entry gets garbage collected in one compilation, then
adds a different (but equivalent) entry, while the other
doesn't run the garbage collector at the same spot and then
shares the mem_attr with the equivalent entry. */
if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
{
tree t2 = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
if (t2)
t = t2;
}
set_mem_expr (funmem, t);
}
else if (fntree)
set_mem_expr (funmem, build_simple_mem_ref (CALL_EXPR_FN (fntree)));
if (ecf_flags & ECF_SIBCALL)
{
if (valreg)
pat = targetm.gen_sibcall_value (valreg, funmem,
rounded_stack_size_rtx,
next_arg_reg, NULL_RTX);
else
pat = targetm.gen_sibcall (funmem, rounded_stack_size_rtx,
next_arg_reg, GEN_INT (struct_value_size));
}
/* If the target has "call" or "call_value" insns, then prefer them
if no arguments are actually popped. If the target does not have
"call" or "call_value" insns, then we must use the popping versions
even if the call has no arguments to pop. */
else if (n_popped > 0
|| !(valreg
? targetm.have_call_value ()
: targetm.have_call ()))
{
rtx n_pop = GEN_INT (n_popped);
/* 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 = targetm.gen_call_value_pop (valreg, funmem,
rounded_stack_size_rtx,
next_arg_reg, n_pop);
else
pat = targetm.gen_call_pop (funmem, rounded_stack_size_rtx,
next_arg_reg, n_pop);
already_popped = 1;
}
else
{
if (valreg)
pat = targetm.gen_call_value (valreg, funmem, rounded_stack_size_rtx,
next_arg_reg, NULL_RTX);
else
pat = targetm.gen_call (funmem, rounded_stack_size_rtx, next_arg_reg,
GEN_INT (struct_value_size));
}
emit_insn (pat);
/* Find the call we just emitted. */
rtx_call_insn *call_insn = last_call_insn ();
/* Some target create a fresh MEM instead of reusing the one provided
above. Set its MEM_EXPR. */
call = get_call_rtx_from (call_insn);
if (call
&& MEM_EXPR (XEXP (call, 0)) == NULL_TREE
&& MEM_EXPR (funmem) != NULL_TREE)
set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem));
/* Mark instrumented calls. */
if (call && fntree)
CALL_EXPR_WITH_BOUNDS_P (call) = CALL_WITH_BOUNDS_P (fntree);
/* Put the register usage information there. */
add_function_usage_to (call_insn, call_fusage);
/* If this is a const call, then set the insn's unchanging bit. */
if (ecf_flags & ECF_CONST)
RTL_CONST_CALL_P (call_insn) = 1;
/* If this is a pure call, then set the insn's unchanging bit. */
if (ecf_flags & ECF_PURE)
RTL_PURE_CALL_P (call_insn) = 1;
/* If this is a const call, then set the insn's unchanging bit. */
if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn) = 1;
/* Create a nothrow REG_EH_REGION note, if needed. */
make_reg_eh_region_note (call_insn, ecf_flags, 0);
if (ecf_flags & ECF_NORETURN)
add_reg_note (call_insn, REG_NORETURN, const0_rtx);
if (ecf_flags & ECF_RETURNS_TWICE)
{
add_reg_note (call_insn, REG_SETJMP, const0_rtx);
cfun->calls_setjmp = 1;
}
SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
/* 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;
if (n_popped > 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));
rounded_stack_size -= n_popped;
rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
stack_pointer_delta -= n_popped;
add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
/* If popup is needed, stack realign must use DRAP */
if (SUPPORTS_STACK_ALIGNMENT)
crtl->need_drap = true;
}
/* For noreturn calls when not accumulating outgoing args force
REG_ARGS_SIZE note to prevent crossjumping of calls with different
args sizes. */
else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0)
add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
if (!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 (rounded_stack_size != 0)
{
if (ecf_flags & ECF_NORETURN)
/* Just pretend we did the pop. */
stack_pointer_delta -= rounded_stack_size;
else if (flag_defer_pop && inhibit_defer_pop == 0
&& ! (ecf_flags & (ECF_CONST | ECF_PURE)))
pending_stack_adjust += rounded_stack_size;
else
adjust_stack (rounded_stack_size_rtx);
}
}
/* When we accumulate outgoing args, we must avoid any stack manipulations.
Restore the stack pointer to its original value now. Usually
ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
popping variants of functions exist as well.
??? We may optimize similar to defer_pop above, but it is
probably not worthwhile.
??? It will be worthwhile to enable combine_stack_adjustments even for
such machines. */
else if (n_popped)
anti_adjust_stack (GEN_INT (n_popped));
}
/* Determine if the function identified by FNDECL is one with
special properties we wish to know about. Modify FLAGS accordingly.
For example, if the function might return more than one time (setjmp), then
set ECF_RETURNS_TWICE.
Set ECF_MAY_BE_ALLOCA for any memory allocation function that might allocate
space from the stack such as alloca. */
static int
special_function_p (const_tree fndecl, int flags)
{
tree name_decl = DECL_NAME (fndecl);
/* For instrumentation clones we want to derive flags
from the original name. */
if (cgraph_node::get (fndecl)
&& cgraph_node::get (fndecl)->instrumentation_clone)
name_decl = DECL_NAME (cgraph_node::get (fndecl)->orig_decl);
if (fndecl && name_decl
&& IDENTIFIER_LENGTH (name_decl) <= 11
/* Exclude functions not at the file scope, or not `extern',
since they are not the magic functions we would otherwise
think they are.
FIXME: this should be handled with attributes, not with this
hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
because you can declare fork() inside a function if you
wish. */
&& (DECL_CONTEXT (fndecl) == NULL_TREE
|| TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL)
&& TREE_PUBLIC (fndecl))
{
const char *name = IDENTIFIER_POINTER (name_decl);
const char *tname = name;
/* 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. */
if (IDENTIFIER_LENGTH (name_decl) == 6
&& name[0] == 'a'
&& ! strcmp (name, "alloca"))
flags |= ECF_MAY_BE_ALLOCA;
/* Disregard prefix _ or __. */
if (name[0] == '_')
{
if (name[1] == '_')
tname += 2;
else
tname += 1;
}
/* ECF_RETURNS_TWICE is safe even for -ffreestanding. */
if (! strcmp (tname, "setjmp")
|| ! strcmp (tname, "sigsetjmp")
|| ! strcmp (name, "savectx")
|| ! strcmp (name, "vfork")
|| ! strcmp (name, "getcontext"))
flags |= ECF_RETURNS_TWICE;
}
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
&& ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (fndecl)))
flags |= ECF_MAY_BE_ALLOCA;
return flags;
}
/* Similar to special_function_p; return a set of ERF_ flags for the
function FNDECL. */
static int
decl_return_flags (tree fndecl)
{
tree attr;
tree type = TREE_TYPE (fndecl);
if (!type)
return 0;
attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
if (!attr)
return 0;
attr = TREE_VALUE (TREE_VALUE (attr));
if (!attr || TREE_STRING_LENGTH (attr) < 1)
return 0;
switch (TREE_STRING_POINTER (attr)[0])
{
case '1':
case '2':
case '3':
case '4':
return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
case 'm':
return ERF_NOALIAS;
case '.':
default:
return 0;
}
}
/* Return nonzero when FNDECL represents a call to setjmp. */
int
setjmp_call_p (const_tree fndecl)
{
if (DECL_IS_RETURNS_TWICE (fndecl))
return ECF_RETURNS_TWICE;
return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
}
/* Return true if STMT may be an alloca call. */
bool
gimple_maybe_alloca_call_p (const gimple *stmt)
{
tree fndecl;
if (!is_gimple_call (stmt))
return false;
fndecl = gimple_call_fndecl (stmt);
if (fndecl && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
return true;
return false;
}
/* Return true if STMT is a builtin alloca call. */
bool
gimple_alloca_call_p (const gimple *stmt)
{
tree fndecl;
if (!is_gimple_call (stmt))
return false;
fndecl = gimple_call_fndecl (stmt);
if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
switch (DECL_FUNCTION_CODE (fndecl))
{
CASE_BUILT_IN_ALLOCA:
return true;
default:
break;
}
return false;
}
/* Return true when exp contains a builtin alloca call. */
bool
alloca_call_p (const_tree exp)
{
tree fndecl;
if (TREE_CODE (exp) == CALL_EXPR
&& (fndecl = get_callee_fndecl (exp))
&& DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
switch (DECL_FUNCTION_CODE (fndecl))
{
CASE_BUILT_IN_ALLOCA:
return true;
default:
break;
}
return false;
}
/* Return TRUE if FNDECL is either a TM builtin or a TM cloned
function. Return FALSE otherwise. */
static bool
is_tm_builtin (const_tree fndecl)
{
if (fndecl == NULL)
return false;
if (decl_is_tm_clone (fndecl))
return true;
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
{
switch (DECL_FUNCTION_CODE (fndecl))
{
case BUILT_IN_TM_COMMIT:
case BUILT_IN_TM_COMMIT_EH:
case BUILT_IN_TM_ABORT:
case BUILT_IN_TM_IRREVOCABLE:
case BUILT_IN_TM_GETTMCLONE_IRR:
case BUILT_IN_TM_MEMCPY:
case BUILT_IN_TM_MEMMOVE:
case BUILT_IN_TM_MEMSET:
CASE_BUILT_IN_TM_STORE (1):
CASE_BUILT_IN_TM_STORE (2):
CASE_BUILT_IN_TM_STORE (4):
CASE_BUILT_IN_TM_STORE (8):
CASE_BUILT_IN_TM_STORE (FLOAT):
CASE_BUILT_IN_TM_STORE (DOUBLE):
CASE_BUILT_IN_TM_STORE (LDOUBLE):
CASE_BUILT_IN_TM_STORE (M64):
CASE_BUILT_IN_TM_STORE (M128):
CASE_BUILT_IN_TM_STORE (M256):
CASE_BUILT_IN_TM_LOAD (1):
CASE_BUILT_IN_TM_LOAD (2):
CASE_BUILT_IN_TM_LOAD (4):
CASE_BUILT_IN_TM_LOAD (8):
CASE_BUILT_IN_TM_LOAD (FLOAT):
CASE_BUILT_IN_TM_LOAD (DOUBLE):
CASE_BUILT_IN_TM_LOAD (LDOUBLE):
CASE_BUILT_IN_TM_LOAD (M64):
CASE_BUILT_IN_TM_LOAD (M128):
CASE_BUILT_IN_TM_LOAD (M256):
case BUILT_IN_TM_LOG:
case BUILT_IN_TM_LOG_1:
case BUILT_IN_TM_LOG_2:
case BUILT_IN_TM_LOG_4:
case BUILT_IN_TM_LOG_8:
case BUILT_IN_TM_LOG_FLOAT:
case BUILT_IN_TM_LOG_DOUBLE:
case BUILT_IN_TM_LOG_LDOUBLE:
case BUILT_IN_TM_LOG_M64:
case BUILT_IN_TM_LOG_M128:
case BUILT_IN_TM_LOG_M256:
return true;
default:
break;
}
}
return false;
}
/* Detect flags (function attributes) from the function decl or type node. */
int
flags_from_decl_or_type (const_tree exp)
{
int flags = 0;
if (DECL_P (exp))
{
/* The function exp may have the `malloc' attribute. */
if (DECL_IS_MALLOC (exp))
flags |= ECF_MALLOC;
/* The function exp may have the `returns_twice' attribute. */
if (DECL_IS_RETURNS_TWICE (exp))
flags |= ECF_RETURNS_TWICE;
/* Process the pure and const attributes. */
if (TREE_READONLY (exp))
flags |= ECF_CONST;
if (DECL_PURE_P (exp))
flags |= ECF_PURE;
if (DECL_LOOPING_CONST_OR_PURE_P (exp))
flags |= ECF_LOOPING_CONST_OR_PURE;
if (DECL_IS_NOVOPS (exp))
flags |= ECF_NOVOPS;
if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp)))
flags |= ECF_LEAF;
if (lookup_attribute ("cold", DECL_ATTRIBUTES (exp)))
flags |= ECF_COLD;
if (TREE_NOTHROW (exp))
flags |= ECF_NOTHROW;
if (flag_tm)
{
if (is_tm_builtin (exp))
flags |= ECF_TM_BUILTIN;
else if ((flags & (ECF_CONST|ECF_NOVOPS)) != 0
|| lookup_attribute ("transaction_pure",
TYPE_ATTRIBUTES (TREE_TYPE (exp))))
flags |= ECF_TM_PURE;
}
flags = special_function_p (exp, flags);
}
else if (TYPE_P (exp))
{
if (TYPE_READONLY (exp))
flags |= ECF_CONST;
if (flag_tm
&& ((flags & ECF_CONST) != 0
|| lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp))))
flags |= ECF_TM_PURE;
}
else
gcc_unreachable ();
if (TREE_THIS_VOLATILE (exp))
{
flags |= ECF_NORETURN;
if (flags & (ECF_CONST|ECF_PURE))
flags |= ECF_LOOPING_CONST_OR_PURE;
}
return flags;
}
/* Detect flags from a CALL_EXPR. */
int
call_expr_flags (const_tree t)
{
int flags;
tree decl = get_callee_fndecl (t);
if (decl)
flags = flags_from_decl_or_type (decl);
else if (CALL_EXPR_FN (t) == NULL_TREE)
flags = internal_fn_flags (CALL_EXPR_IFN (t));
else
{
tree type = TREE_TYPE (CALL_EXPR_FN (t));
if (type && TREE_CODE (type) == POINTER_TYPE)
flags = flags_from_decl_or_type (TREE_TYPE (type));
else
flags = 0;
if (CALL_EXPR_BY_DESCRIPTOR (t))
flags |= ECF_BY_DESCRIPTOR;
}
return flags;
}
/* Return true if TYPE should be passed by invisible reference. */
bool
pass_by_reference (CUMULATIVE_ARGS *ca, machine_mode mode,
tree type, bool named_arg)
{
if (type)
{
/* If this type contains non-trivial constructors, then it is
forbidden for the middle-end to create any new copies. */
if (TREE_ADDRESSABLE (type))
return true;
/* GCC post 3.4 passes *all* variable sized types by reference. */
if (!TYPE_SIZE (type) || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
return true;
/* If a record type should be passed the same as its first (and only)
member, use the type and mode of that member. */
if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
{
type = TREE_TYPE (first_field (type));
mode = TYPE_MODE (type);
}
}
return targetm.calls.pass_by_reference (pack_cumulative_args (ca), mode,
type, named_arg);
}
/* Return true if TYPE, which is passed by reference, should be callee
copied instead of caller copied. */
bool
reference_callee_copied (CUMULATIVE_ARGS *ca, machine_mode mode,
tree type, bool named_arg)
{
if (type && TREE_ADDRESSABLE (type))
return false;
return targetm.calls.callee_copies (pack_cumulative_args (ca), mode, type,
named_arg);
}
/* Precompute all register parameters as described by ARGS, storing values
into fields within the ARGS array.
NUM_ACTUALS indicates the total number elements in the ARGS array.
Set REG_PARM_SEEN if we encounter a register parameter. */
static void
precompute_register_parameters (int num_actuals, struct arg_data *args,
int *reg_parm_seen)
{
int i;
*reg_parm_seen = 0;
for (i = 0; i < num_actuals; i++)
if (args[i].reg != 0 && ! args[i].pass_on_stack)
{
*reg_parm_seen = 1;
if (args[i].value == 0)
{
push_temp_slots ();
args[i].value = expand_normal (args[i].tree_value);
preserve_temp_slots (args[i].value);
pop_temp_slots ();
}
/* If we are to promote the function arg to a wider mode,
do it now. */
if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
args[i].value
= convert_modes (args[i].mode,
TYPE_MODE (TREE_TYPE (args[i].tree_value)),
args[i].value, args[i].unsignedp);
/* If the value is a non-legitimate constant, force it into a
pseudo now. TLS symbols sometimes need a call to resolve. */
if (CONSTANT_P (args[i].value)
&& !targetm.legitimate_constant_p (args[i].mode, args[i].value))
args[i].value = force_reg (args[i].mode, args[i].value);
/* If we're going to have to load the value by parts, pull the
parts into pseudos. The part extraction process can involve
non-trivial computation. */
if (GET_CODE (args[i].reg) == PARALLEL)
{
tree type = TREE_TYPE (args[i].tree_value);
args[i].parallel_value
= emit_group_load_into_temps (args[i].reg, args[i].value,
type, int_size_in_bytes (type));
}
/* If the value is expensive, and we are inside an appropriately
short loop, put the value into a pseudo and then put the pseudo
into the hard reg.
For small register classes, also do this if this call uses
register parameters. This is to avoid reload conflicts while
loading the parameters registers. */
else if ((! (REG_P (args[i].value)
|| (GET_CODE (args[i].value) == SUBREG
&& REG_P (SUBREG_REG (args[i].value)))))
&& args[i].mode != BLKmode
&& (set_src_cost (args[i].value, args[i].mode,
optimize_insn_for_speed_p ())
> COSTS_N_INSNS (1))
&& ((*reg_parm_seen
&& targetm.small_register_classes_for_mode_p (args[i].mode))
|| optimize))
args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
}
}