mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
rtlanal.cc
7039 lines (6018 loc) · 194 KB
/
rtlanal.cc
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
/* Analyze RTL for GNU compiler.
Copyright (C) 1987-2024 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 "rtlanal.h"
#include "tree.h"
#include "predict.h"
#include "df.h"
#include "memmodel.h"
#include "tm_p.h"
#include "insn-config.h"
#include "regs.h"
#include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
#include "recog.h"
#include "addresses.h"
#include "rtl-iter.h"
#include "hard-reg-set.h"
#include "function-abi.h"
/* Forward declarations */
static void set_of_1 (rtx, const_rtx, void *);
static bool covers_regno_p (const_rtx, unsigned int);
static bool covers_regno_no_parallel_p (const_rtx, unsigned int);
static bool computed_jump_p_1 (const_rtx);
static void parms_set (rtx, const_rtx, void *);
static unsigned HOST_WIDE_INT cached_nonzero_bits (const_rtx, scalar_int_mode,
const_rtx, machine_mode,
unsigned HOST_WIDE_INT);
static unsigned HOST_WIDE_INT nonzero_bits1 (const_rtx, scalar_int_mode,
const_rtx, machine_mode,
unsigned HOST_WIDE_INT);
static unsigned int cached_num_sign_bit_copies (const_rtx, scalar_int_mode,
const_rtx, machine_mode,
unsigned int);
static unsigned int num_sign_bit_copies1 (const_rtx, scalar_int_mode,
const_rtx, machine_mode,
unsigned int);
rtx_subrtx_bound_info rtx_all_subrtx_bounds[NUM_RTX_CODE];
rtx_subrtx_bound_info rtx_nonconst_subrtx_bounds[NUM_RTX_CODE];
/* Truncation narrows the mode from SOURCE mode to DESTINATION mode.
If TARGET_MODE_REP_EXTENDED (DESTINATION, DESTINATION_REP) is
SIGN_EXTEND then while narrowing we also have to enforce the
representation and sign-extend the value to mode DESTINATION_REP.
If the value is already sign-extended to DESTINATION_REP mode we
can just switch to DESTINATION mode on it. For each pair of
integral modes SOURCE and DESTINATION, when truncating from SOURCE
to DESTINATION, NUM_SIGN_BIT_COPIES_IN_REP[SOURCE][DESTINATION]
contains the number of high-order bits in SOURCE that have to be
copies of the sign-bit so that we can do this mode-switch to
DESTINATION. */
static unsigned int
num_sign_bit_copies_in_rep[MAX_MODE_INT + 1][MAX_MODE_INT + 1];
/* Store X into index I of ARRAY. ARRAY is known to have at least I
elements. Return the new base of ARRAY. */
template <typename T>
typename T::value_type *
generic_subrtx_iterator <T>::add_single_to_queue (array_type &array,
value_type *base,
size_t i, value_type x)
{
if (base == array.stack)
{
if (i < LOCAL_ELEMS)
{
base[i] = x;
return base;
}
gcc_checking_assert (i == LOCAL_ELEMS);
/* A previous iteration might also have moved from the stack to the
heap, in which case the heap array will already be big enough. */
if (vec_safe_length (array.heap) <= i)
vec_safe_grow (array.heap, i + 1, true);
base = array.heap->address ();
memcpy (base, array.stack, sizeof (array.stack));
base[LOCAL_ELEMS] = x;
return base;
}
unsigned int length = array.heap->length ();
if (length > i)
{
gcc_checking_assert (base == array.heap->address ());
base[i] = x;
return base;
}
else
{
gcc_checking_assert (i == length);
vec_safe_push (array.heap, x);
return array.heap->address ();
}
}
/* Add the subrtxes of X to worklist ARRAY, starting at END. Return the
number of elements added to the worklist. */
template <typename T>
size_t
generic_subrtx_iterator <T>::add_subrtxes_to_queue (array_type &array,
value_type *base,
size_t end, rtx_type x)
{
enum rtx_code code = GET_CODE (x);
const char *format = GET_RTX_FORMAT (code);
size_t orig_end = end;
if (UNLIKELY (INSN_P (x)))
{
/* Put the pattern at the top of the queue, since that's what
we're likely to want most. It also allows for the SEQUENCE
code below. */
for (int i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; --i)
if (format[i] == 'e')
{
value_type subx = T::get_value (x->u.fld[i].rt_rtx);
if (LIKELY (end < LOCAL_ELEMS))
base[end++] = subx;
else
base = add_single_to_queue (array, base, end++, subx);
}
}
else
for (int i = 0; format[i]; ++i)
if (format[i] == 'e')
{
value_type subx = T::get_value (x->u.fld[i].rt_rtx);
if (LIKELY (end < LOCAL_ELEMS))
base[end++] = subx;
else
base = add_single_to_queue (array, base, end++, subx);
}
else if (format[i] == 'E')
{
unsigned int length = GET_NUM_ELEM (x->u.fld[i].rt_rtvec);
rtx *vec = x->u.fld[i].rt_rtvec->elem;
if (LIKELY (end + length <= LOCAL_ELEMS))
for (unsigned int j = 0; j < length; j++)
base[end++] = T::get_value (vec[j]);
else
for (unsigned int j = 0; j < length; j++)
base = add_single_to_queue (array, base, end++,
T::get_value (vec[j]));
if (code == SEQUENCE && end == length)
/* If the subrtxes of the sequence fill the entire array then
we know that no other parts of a containing insn are queued.
The caller is therefore iterating over the sequence as a
PATTERN (...), so we also want the patterns of the
subinstructions. */
for (unsigned int j = 0; j < length; j++)
{
typename T::rtx_type x = T::get_rtx (base[j]);
if (INSN_P (x))
base[j] = T::get_value (PATTERN (x));
}
}
return end - orig_end;
}
template <typename T>
void
generic_subrtx_iterator <T>::free_array (array_type &array)
{
vec_free (array.heap);
}
template <typename T>
const size_t generic_subrtx_iterator <T>::LOCAL_ELEMS;
template class generic_subrtx_iterator <const_rtx_accessor>;
template class generic_subrtx_iterator <rtx_var_accessor>;
template class generic_subrtx_iterator <rtx_ptr_accessor>;
/* Return true if the value of X is unstable
(would be different at a different point in the program).
The frame pointer, arg pointer, etc. are considered stable
(within one function) and so is anything marked `unchanging'. */
bool
rtx_unstable_p (const_rtx x)
{
const RTX_CODE code = GET_CODE (x);
int i;
const char *fmt;
switch (code)
{
case MEM:
return !MEM_READONLY_P (x) || rtx_unstable_p (XEXP (x, 0));
case CONST:
CASE_CONST_ANY:
case SYMBOL_REF:
case LABEL_REF:
return false;
case REG:
/* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
/* The arg pointer varies if it is not a fixed register. */
|| (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
return false;
/* ??? When call-clobbered, the value is stable modulo the restore
that must happen after a call. This currently screws up local-alloc
into believing that the restore is not needed. */
if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED && x == pic_offset_table_rtx)
return false;
return true;
case ASM_OPERANDS:
if (MEM_VOLATILE_P (x))
return true;
/* Fall through. */
default:
break;
}
fmt = GET_RTX_FORMAT (code);
for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
if (fmt[i] == 'e')
{
if (rtx_unstable_p (XEXP (x, i)))
return true;
}
else if (fmt[i] == 'E')
{
int j;
for (j = 0; j < XVECLEN (x, i); j++)
if (rtx_unstable_p (XVECEXP (x, i, j)))
return true;
}
return false;
}
/* Return true if X has a value that can vary even between two
executions of the program. false means X can be compared reliably
against certain constants or near-constants.
FOR_ALIAS is nonzero if we are called from alias analysis; if it is
zero, we are slightly more conservative.
The frame pointer and the arg pointer are considered constant. */
bool
rtx_varies_p (const_rtx x, bool for_alias)
{
RTX_CODE code;
int i;
const char *fmt;
if (!x)
return false;
code = GET_CODE (x);
switch (code)
{
case MEM:
return !MEM_READONLY_P (x) || rtx_varies_p (XEXP (x, 0), for_alias);
case CONST:
CASE_CONST_ANY:
case SYMBOL_REF:
case LABEL_REF:
return false;
case REG:
/* Note that we have to test for the actual rtx used for the frame
and arg pointers and not just the register number in case we have
eliminated the frame and/or arg pointer and are using it
for pseudos. */
if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
/* The arg pointer varies if it is not a fixed register. */
|| (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
return false;
if (x == pic_offset_table_rtx
/* ??? When call-clobbered, the value is stable modulo the restore
that must happen after a call. This currently screws up
local-alloc into believing that the restore is not needed, so we
must return 0 only if we are called from alias analysis. */
&& (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED || for_alias))
return false;
return true;
case LO_SUM:
/* The operand 0 of a LO_SUM is considered constant
(in fact it is related specifically to operand 1)
during alias analysis. */
return (! for_alias && rtx_varies_p (XEXP (x, 0), for_alias))
|| rtx_varies_p (XEXP (x, 1), for_alias);
case ASM_OPERANDS:
if (MEM_VOLATILE_P (x))
return true;
/* Fall through. */
default:
break;
}
fmt = GET_RTX_FORMAT (code);
for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
if (fmt[i] == 'e')
{
if (rtx_varies_p (XEXP (x, i), for_alias))
return true;
}
else if (fmt[i] == 'E')
{
int j;
for (j = 0; j < XVECLEN (x, i); j++)
if (rtx_varies_p (XVECEXP (x, i, j), for_alias))
return true;
}
return false;
}
/* Compute an approximation for the offset between the register
FROM and TO for the current function, as it was at the start
of the routine. */
static poly_int64
get_initial_register_offset (int from, int to)
{
static const struct elim_table_t
{
const int from;
const int to;
} table[] = ELIMINABLE_REGS;
poly_int64 offset1, offset2;
unsigned int i, j;
if (to == from)
return 0;
/* It is not safe to call INITIAL_ELIMINATION_OFFSET before the epilogue
is completed, but we need to give at least an estimate for the stack
pointer based on the frame size. */
if (!epilogue_completed)
{
offset1 = crtl->outgoing_args_size + get_frame_size ();
#if !STACK_GROWS_DOWNWARD
offset1 = - offset1;
#endif
if (to == STACK_POINTER_REGNUM)
return offset1;
else if (from == STACK_POINTER_REGNUM)
return - offset1;
else
return 0;
}
for (i = 0; i < ARRAY_SIZE (table); i++)
if (table[i].from == from)
{
if (table[i].to == to)
{
INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
offset1);
return offset1;
}
for (j = 0; j < ARRAY_SIZE (table); j++)
{
if (table[j].to == to
&& table[j].from == table[i].to)
{
INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
offset1);
INITIAL_ELIMINATION_OFFSET (table[j].from, table[j].to,
offset2);
return offset1 + offset2;
}
if (table[j].from == to
&& table[j].to == table[i].to)
{
INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
offset1);
INITIAL_ELIMINATION_OFFSET (table[j].from, table[j].to,
offset2);
return offset1 - offset2;
}
}
}
else if (table[i].to == from)
{
if (table[i].from == to)
{
INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
offset1);
return - offset1;
}
for (j = 0; j < ARRAY_SIZE (table); j++)
{
if (table[j].to == to
&& table[j].from == table[i].from)
{
INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
offset1);
INITIAL_ELIMINATION_OFFSET (table[j].from, table[j].to,
offset2);
return - offset1 + offset2;
}
if (table[j].from == to
&& table[j].to == table[i].from)
{
INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
offset1);
INITIAL_ELIMINATION_OFFSET (table[j].from, table[j].to,
offset2);
return - offset1 - offset2;
}
}
}
/* If the requested register combination was not found,
try a different more simple combination. */
if (from == ARG_POINTER_REGNUM)
return get_initial_register_offset (HARD_FRAME_POINTER_REGNUM, to);
else if (to == ARG_POINTER_REGNUM)
return get_initial_register_offset (from, HARD_FRAME_POINTER_REGNUM);
else if (from == HARD_FRAME_POINTER_REGNUM)
return get_initial_register_offset (FRAME_POINTER_REGNUM, to);
else if (to == HARD_FRAME_POINTER_REGNUM)
return get_initial_register_offset (from, FRAME_POINTER_REGNUM);
else
return 0;
}
/* Return true if the use of X+OFFSET as an address in a MEM with SIZE
bytes can cause a trap. MODE is the mode of the MEM (not that of X) and
UNALIGNED_MEMS controls whether true is returned for unaligned memory
references on strict alignment machines. */
static bool
rtx_addr_can_trap_p_1 (const_rtx x, poly_int64 offset, poly_int64 size,
machine_mode mode, bool unaligned_mems)
{
enum rtx_code code = GET_CODE (x);
gcc_checking_assert (mode == BLKmode
|| mode == VOIDmode
|| known_size_p (size));
poly_int64 const_x1;
/* The offset must be a multiple of the mode size if we are considering
unaligned memory references on strict alignment machines. */
if (STRICT_ALIGNMENT
&& unaligned_mems
&& mode != BLKmode
&& mode != VOIDmode)
{
poly_int64 actual_offset = offset;
#ifdef SPARC_STACK_BOUNDARY_HACK
/* ??? The SPARC port may claim a STACK_BOUNDARY higher than
the real alignment of %sp. However, when it does this, the
alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY. */
if (SPARC_STACK_BOUNDARY_HACK
&& (x == stack_pointer_rtx || x == hard_frame_pointer_rtx))
actual_offset -= STACK_POINTER_OFFSET;
#endif
if (!multiple_p (actual_offset, GET_MODE_SIZE (mode)))
return true;
}
switch (code)
{
case SYMBOL_REF:
if (SYMBOL_REF_WEAK (x))
return true;
if (!CONSTANT_POOL_ADDRESS_P (x) && !SYMBOL_REF_FUNCTION_P (x))
{
tree decl;
poly_int64 decl_size;
if (maybe_lt (offset, 0))
return true;
if (!known_size_p (size))
return maybe_ne (offset, 0);
/* If the size of the access or of the symbol is unknown,
assume the worst. */
decl = SYMBOL_REF_DECL (x);
/* Else check that the access is in bounds. TODO: restructure
expr_size/tree_expr_size/int_expr_size and just use the latter. */
if (!decl)
decl_size = -1;
else if (DECL_P (decl) && DECL_SIZE_UNIT (decl))
{
if (!poly_int_tree_p (DECL_SIZE_UNIT (decl), &decl_size))
decl_size = -1;
}
else if (TREE_CODE (decl) == STRING_CST)
decl_size = TREE_STRING_LENGTH (decl);
else if (TYPE_SIZE_UNIT (TREE_TYPE (decl)))
decl_size = int_size_in_bytes (TREE_TYPE (decl));
else
decl_size = -1;
return (!known_size_p (decl_size) || known_eq (decl_size, 0)
? maybe_ne (offset, 0)
: !known_subrange_p (offset, size, 0, decl_size));
}
return false;
case LABEL_REF:
return false;
case REG:
/* Stack references are assumed not to trap, but we need to deal with
nonsensical offsets. */
if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
|| x == stack_pointer_rtx
/* The arg pointer varies if it is not a fixed register. */
|| (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
{
#ifdef RED_ZONE_SIZE
poly_int64 red_zone_size = RED_ZONE_SIZE;
#else
poly_int64 red_zone_size = 0;
#endif
poly_int64 stack_boundary = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
poly_int64 low_bound, high_bound;
if (!known_size_p (size))
return true;
if (x == frame_pointer_rtx)
{
if (FRAME_GROWS_DOWNWARD)
{
high_bound = targetm.starting_frame_offset ();
low_bound = high_bound - get_frame_size ();
}
else
{
low_bound = targetm.starting_frame_offset ();
high_bound = low_bound + get_frame_size ();
}
}
else if (x == hard_frame_pointer_rtx)
{
poly_int64 sp_offset
= get_initial_register_offset (STACK_POINTER_REGNUM,
HARD_FRAME_POINTER_REGNUM);
poly_int64 ap_offset
= get_initial_register_offset (ARG_POINTER_REGNUM,
HARD_FRAME_POINTER_REGNUM);
#if STACK_GROWS_DOWNWARD
low_bound = sp_offset - red_zone_size - stack_boundary;
high_bound = ap_offset
+ FIRST_PARM_OFFSET (current_function_decl)
#if !ARGS_GROW_DOWNWARD
+ crtl->args.size
#endif
+ stack_boundary;
#else
high_bound = sp_offset + red_zone_size + stack_boundary;
low_bound = ap_offset
+ FIRST_PARM_OFFSET (current_function_decl)
#if ARGS_GROW_DOWNWARD
- crtl->args.size
#endif
- stack_boundary;
#endif
}
else if (x == stack_pointer_rtx)
{
poly_int64 ap_offset
= get_initial_register_offset (ARG_POINTER_REGNUM,
STACK_POINTER_REGNUM);
#if STACK_GROWS_DOWNWARD
low_bound = - red_zone_size - stack_boundary;
high_bound = ap_offset
+ FIRST_PARM_OFFSET (current_function_decl)
#if !ARGS_GROW_DOWNWARD
+ crtl->args.size
#endif
+ stack_boundary;
#else
high_bound = red_zone_size + stack_boundary;
low_bound = ap_offset
+ FIRST_PARM_OFFSET (current_function_decl)
#if ARGS_GROW_DOWNWARD
- crtl->args.size
#endif
- stack_boundary;
#endif
}
else
{
/* We assume that accesses are safe to at least the
next stack boundary.
Examples are varargs and __builtin_return_address. */
#if ARGS_GROW_DOWNWARD
high_bound = FIRST_PARM_OFFSET (current_function_decl)
+ stack_boundary;
low_bound = FIRST_PARM_OFFSET (current_function_decl)
- crtl->args.size - stack_boundary;
#else
low_bound = FIRST_PARM_OFFSET (current_function_decl)
- stack_boundary;
high_bound = FIRST_PARM_OFFSET (current_function_decl)
+ crtl->args.size + stack_boundary;
#endif
}
if (known_ge (offset, low_bound)
&& known_le (offset, high_bound - size))
return false;
return true;
}
/* All of the virtual frame registers are stack references. */
if (VIRTUAL_REGISTER_P (x))
return false;
return true;
case CONST:
return rtx_addr_can_trap_p_1 (XEXP (x, 0), offset, size,
mode, unaligned_mems);
case PLUS:
/* An address is assumed not to trap if:
- it is the pic register plus a const unspec without offset. */
if (XEXP (x, 0) == pic_offset_table_rtx
&& GET_CODE (XEXP (x, 1)) == CONST
&& GET_CODE (XEXP (XEXP (x, 1), 0)) == UNSPEC
&& known_eq (offset, 0))
return false;
/* - or it is an address that can't trap plus a constant integer. */
if (poly_int_rtx_p (XEXP (x, 1), &const_x1)
&& !rtx_addr_can_trap_p_1 (XEXP (x, 0), offset + const_x1,
size, mode, unaligned_mems))
return false;
return true;
case LO_SUM:
case PRE_MODIFY:
return rtx_addr_can_trap_p_1 (XEXP (x, 1), offset, size,
mode, unaligned_mems);
case PRE_DEC:
case PRE_INC:
case POST_DEC:
case POST_INC:
case POST_MODIFY:
return rtx_addr_can_trap_p_1 (XEXP (x, 0), offset, size,
mode, unaligned_mems);
default:
break;
}
/* If it isn't one of the case above, it can cause a trap. */
return true;
}
/* Return true if the use of X as an address in a MEM can cause a trap. */
bool
rtx_addr_can_trap_p (const_rtx x)
{
return rtx_addr_can_trap_p_1 (x, 0, -1, BLKmode, false);
}
/* Return true if X contains a MEM subrtx. */
bool
contains_mem_rtx_p (rtx x)
{
subrtx_iterator::array_type array;
FOR_EACH_SUBRTX (iter, array, x, ALL)
if (MEM_P (*iter))
return true;
return false;
}
/* Return true if X is an address that is known to not be zero. */
bool
nonzero_address_p (const_rtx x)
{
const enum rtx_code code = GET_CODE (x);
switch (code)
{
case SYMBOL_REF:
return flag_delete_null_pointer_checks && !SYMBOL_REF_WEAK (x);
case LABEL_REF:
return true;
case REG:
/* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
|| x == stack_pointer_rtx
|| (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
return true;
/* All of the virtual frame registers are stack references. */
if (VIRTUAL_REGISTER_P (x))
return true;
return false;
case CONST:
return nonzero_address_p (XEXP (x, 0));
case PLUS:
/* Handle PIC references. */
if (XEXP (x, 0) == pic_offset_table_rtx
&& CONSTANT_P (XEXP (x, 1)))
return true;
return false;
case PRE_MODIFY:
/* Similar to the above; allow positive offsets. Further, since
auto-inc is only allowed in memories, the register must be a
pointer. */
if (CONST_INT_P (XEXP (x, 1))
&& INTVAL (XEXP (x, 1)) > 0)
return true;
return nonzero_address_p (XEXP (x, 0));
case PRE_INC:
/* Similarly. Further, the offset is always positive. */
return true;
case PRE_DEC:
case POST_DEC:
case POST_INC:
case POST_MODIFY:
return nonzero_address_p (XEXP (x, 0));
case LO_SUM:
return nonzero_address_p (XEXP (x, 1));
default:
break;
}
/* If it isn't one of the case above, might be zero. */
return false;
}
/* Return true if X refers to a memory location whose address
cannot be compared reliably with constant addresses,
or if X refers to a BLKmode memory object.
FOR_ALIAS is nonzero if we are called from alias analysis; if it is
zero, we are slightly more conservative. */
bool
rtx_addr_varies_p (const_rtx x, bool for_alias)
{
enum rtx_code code;
int i;
const char *fmt;
if (x == 0)
return false;
code = GET_CODE (x);
if (code == MEM)
return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0), for_alias);
fmt = GET_RTX_FORMAT (code);
for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
if (fmt[i] == 'e')
{
if (rtx_addr_varies_p (XEXP (x, i), for_alias))
return true;
}
else if (fmt[i] == 'E')
{
int j;
for (j = 0; j < XVECLEN (x, i); j++)
if (rtx_addr_varies_p (XVECEXP (x, i, j), for_alias))
return true;
}
return false;
}
/* Return the CALL in X if there is one. */
rtx
get_call_rtx_from (const rtx_insn *insn)
{
rtx x = PATTERN (insn);
if (GET_CODE (x) == PARALLEL)
x = XVECEXP (x, 0, 0);
if (GET_CODE (x) == SET)
x = SET_SRC (x);
if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
return x;
return NULL_RTX;
}
/* Get the declaration of the function called by INSN. */
tree
get_call_fndecl (const rtx_insn *insn)
{
rtx note, datum;
note = find_reg_note (insn, REG_CALL_DECL, NULL_RTX);
if (note == NULL_RTX)
return NULL_TREE;
datum = XEXP (note, 0);
if (datum != NULL_RTX)
return SYMBOL_REF_DECL (datum);
return NULL_TREE;
}
/* Return the value of the integer term in X, if one is apparent;
otherwise return 0.
Only obvious integer terms are detected.
This is used in cse.cc with the `related_value' field. */
HOST_WIDE_INT
get_integer_term (const_rtx x)
{
if (GET_CODE (x) == CONST)
x = XEXP (x, 0);
if (GET_CODE (x) == MINUS
&& CONST_INT_P (XEXP (x, 1)))
return - INTVAL (XEXP (x, 1));
if (GET_CODE (x) == PLUS
&& CONST_INT_P (XEXP (x, 1)))
return INTVAL (XEXP (x, 1));
return 0;
}
/* If X is a constant, return the value sans apparent integer term;
otherwise return 0.
Only obvious integer terms are detected. */
rtx
get_related_value (const_rtx x)
{
if (GET_CODE (x) != CONST)
return 0;
x = XEXP (x, 0);
if (GET_CODE (x) == PLUS
&& CONST_INT_P (XEXP (x, 1)))
return XEXP (x, 0);
else if (GET_CODE (x) == MINUS
&& CONST_INT_P (XEXP (x, 1)))
return XEXP (x, 0);
return 0;
}
/* Return true if SYMBOL is a SYMBOL_REF and OFFSET + SYMBOL points
to somewhere in the same object or object_block as SYMBOL. */
bool
offset_within_block_p (const_rtx symbol, HOST_WIDE_INT offset)
{
tree decl;
if (GET_CODE (symbol) != SYMBOL_REF)
return false;
if (offset == 0)
return true;
if (offset > 0)
{
if (CONSTANT_POOL_ADDRESS_P (symbol)
&& offset < (int) GET_MODE_SIZE (get_pool_mode (symbol)))
return true;
decl = SYMBOL_REF_DECL (symbol);
if (decl && offset < int_size_in_bytes (TREE_TYPE (decl)))
return true;
}
if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol)
&& SYMBOL_REF_BLOCK (symbol)
&& SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0
&& ((unsigned HOST_WIDE_INT) offset + SYMBOL_REF_BLOCK_OFFSET (symbol)
< (unsigned HOST_WIDE_INT) SYMBOL_REF_BLOCK (symbol)->size))
return true;
return false;
}
/* Split X into a base and a constant offset, storing them in *BASE_OUT
and *OFFSET_OUT respectively. */
void
split_const (rtx x, rtx *base_out, rtx *offset_out)
{
if (GET_CODE (x) == CONST)
{
x = XEXP (x, 0);
if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1)))
{
*base_out = XEXP (x, 0);
*offset_out = XEXP (x, 1);
return;
}
}
*base_out = x;
*offset_out = const0_rtx;
}
/* Express integer value X as some value Y plus a polynomial offset,
where Y is either const0_rtx, X or something within X (as opposed
to a new rtx). Return the Y and store the offset in *OFFSET_OUT. */
rtx
strip_offset (rtx x, poly_int64 *offset_out)
{
rtx base = const0_rtx;
rtx test = x;
if (GET_CODE (test) == CONST)
test = XEXP (test, 0);
if (GET_CODE (test) == PLUS)
{
base = XEXP (test, 0);
test = XEXP (test, 1);
}
if (poly_int_rtx_p (test, offset_out))
return base;
*offset_out = 0;
return x;
}
/* Return the argument size in REG_ARGS_SIZE note X. */
poly_int64
get_args_size (const_rtx x)
{
gcc_checking_assert (REG_NOTE_KIND (x) == REG_ARGS_SIZE);
return rtx_to_poly_int64 (XEXP (x, 0));
}
/* Return the number of places FIND appears within X. If COUNT_DEST is
zero, we do not count occurrences inside the destination of a SET. */
int
count_occurrences (const_rtx x, const_rtx find, int count_dest)
{
int i, j;
enum rtx_code code;
const char *format_ptr;
int count;
if (x == find)
return 1;
code = GET_CODE (x);
switch (code)
{
case REG:
CASE_CONST_ANY:
case SYMBOL_REF:
case CODE_LABEL:
case PC:
return 0;
case EXPR_LIST:
count = count_occurrences (XEXP (x, 0), find, count_dest);