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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
|
/* Subroutines used by or related to instruction recognition.
Copyright (C) 1987, 1988 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 1, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "config.h"
#include "rtl.h"
#include <stdio.h>
#include "insn-config.h"
#include "recog.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "real.h"
static int inequality_comparisons_p ();
int strict_memory_address_p ();
int memory_address_p ();
/* Nonzero means allow operands to be volatile.
This is 1 if you use recog_memoized, 0 if you don't.
init_recog and recog_memoized are responsible for setting it.
This way of handling it is not really clean and will be change later. */
int volatile_ok;
rtx recog_addr_dummy;
/* On return from `constrain_operands', indicate which alternative
was satisfied. */
int which_alternative;
/* Nonzero after end of reload pass.
Set to 1 or 0 by toplev.c.
Controls the significance of (SUBREG (MEM)). */
int reload_completed;
/* Initialize data used by the function `recog'.
This must be called once in the compilation of a function
before any insn recognition may be done in the function. */
void
init_recog ()
{
volatile_ok = 0;
recog_addr_dummy = gen_rtx (MEM, VOIDmode, 0);
}
/* Try recognizing the instruction INSN,
and return the code number that results.
Remeber the code so that repeated calls do not
need to spend the time for actual rerecognition.
This function is the normal interface to instruction recognition.
The automatically-generated function `recog' is normally called
through this one. (The only exception is in combine.c.) */
int
recog_memoized (insn)
rtx insn;
{
volatile_ok = 1;
if (INSN_CODE (insn) < 0)
INSN_CODE (insn) = recog (PATTERN (insn), insn);
return INSN_CODE (insn);
}
/* Return 1 if the insn following INSN does not contain
any ordered tests applied to the condition codes.
EQ and NE tests do not count. */
int
next_insn_tests_no_inequality (insn)
rtx insn;
{
register rtx next = NEXT_INSN (insn);
return ((GET_CODE (next) == JUMP_INSN
|| GET_CODE (next) == INSN
|| GET_CODE (next) == CALL_INSN)
&& ! inequality_comparisons_p (PATTERN (next)));
}
/* Return 1 if the CC value set up by INSN is not used. */
int
next_insns_test_no_inequality (insn)
rtx insn;
{
register rtx next = NEXT_INSN (insn);
for (; next != 0; next = NEXT_INSN (next))
{
if (GET_CODE (next) == CODE_LABEL
|| GET_CODE (next) == BARRIER)
return 1;
if (GET_CODE (next) == NOTE)
continue;
if (inequality_comparisons_p (PATTERN (next)))
return 0;
if (GET_CODE (PATTERN (next)) == SET
&& SET_DEST (PATTERN (next)) == cc0_rtx)
return 1;
if (! reg_mentioned_p (cc0_rtx, PATTERN (next)))
return 1;
}
return 1;
}
static int
inequality_comparisons_p (x)
rtx x;
{
register char *fmt;
register int len, i;
register enum rtx_code code = GET_CODE (x);
switch (code)
{
case REG:
case PC:
case CC0:
case CONST_INT:
case CONST_DOUBLE:
case CONST:
case LABEL_REF:
case SYMBOL_REF:
return 0;
case LT:
case LTU:
case GT:
case GTU:
case LE:
case LEU:
case GE:
case GEU:
return (XEXP (x, 0) == cc0_rtx || XEXP (x, 1) == cc0_rtx);
}
len = GET_RTX_LENGTH (code);
fmt = GET_RTX_FORMAT (code);
for (i = 0; i < len; i++)
{
if (fmt[i] == 'e')
{
if (inequality_comparisons_p (XEXP (x, i)))
return 1;
}
else if (fmt[i] == 'E')
{
register int j;
for (j = XVECLEN (x, i) - 1; j >= 0; j--)
if (inequality_comparisons_p (XVECEXP (x, i, j)))
return 1;
}
}
return 0;
}
/* Return 1 if OP is a valid general operand for machine mode MODE.
This is either a register reference, a memory reference,
or a constant. In the case of a memory reference, the address
is checked for general validity for the target machine.
Register and memory references must have mode MODE in order to be valid,
but some constants have no machine mode and are valid for any mode.
If MODE is VOIDmode, OP is checked for validity for whatever mode
it has.
The main use of this function is as a predicate in match_operand
expressions in the machine description. */
int
general_operand (op, mode)
register rtx op;
enum machine_mode mode;
{
register enum rtx_code code = GET_CODE (op);
int mode_altering_drug = 0;
if (mode == VOIDmode)
mode = GET_MODE (op);
if (CONSTANT_P (op))
return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
&& LEGITIMATE_CONSTANT_P (op));
/* Except for certain constants with VOIDmode, already checked for,
OP's mode must match MODE if MODE specifies a mode. */
if (GET_MODE (op) != mode)
return 0;
while (code == SUBREG)
{
op = SUBREG_REG (op);
code = GET_CODE (op);
#if 0
/* No longer needed, since (SUBREG (MEM...))
will load the MEM into a reload reg in the MEM's own mode. */
mode_altering_drug = 1;
#endif
}
if (code == REG)
return 1;
if (code == CONST_DOUBLE)
return LEGITIMATE_CONSTANT_P (op);
if (code == MEM)
{
register rtx y = XEXP (op, 0);
if (! volatile_ok && MEM_VOLATILE_P (op))
return 0;
/* Use the mem's mode, since it will be reloaded thus. */
mode = GET_MODE (op);
GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
}
return 0;
win:
if (mode_altering_drug)
return ! mode_dependent_address_p (XEXP (op, 0));
return 1;
}
/* Return 1 if OP is a valid memory address for a memory reference
of mode MODE.
The main use of this function is as a predicate in match_operand
expressions in the machine description. */
int
address_operand (op, mode)
register rtx op;
enum machine_mode mode;
{
return (memory_address_p (mode, op)
&& (GET_CODE (op) != MEM || !MEM_VOLATILE_P (op) || volatile_ok));
}
/* Return 1 if OP is a register reference of mode MODE.
If MODE is VOIDmode, accept a register in any mode.
The main use of this function is as a predicate in match_operand
expressions in the machine description. */
int
register_operand (op, mode)
register rtx op;
enum machine_mode mode;
{
if (GET_MODE (op) != mode && mode != VOIDmode)
return 0;
if (GET_CODE (op) == SUBREG)
{
/* Before reload, we can allow (SUBREG (MEM...)) as a register operand
because it is guaranteed to be reloaded into one.
Just make sure the MEM is valid in itself.
(Ideally, (SUBREG (MEM)...) should not exist after reload,
but currently it does result from (SUBREG (REG)...) where the
reg went on the stack.) */
if (! reload_completed)
return general_operand (op, mode);
}
while (GET_CODE (op) == SUBREG)
op = SUBREG_REG (op);
return GET_CODE (op) == REG;
}
/* Return 1 if OP is a valid immediate operand for mode MODE.
The main use of this function is as a predicate in match_operand
expressions in the machine description. */
int
immediate_operand (op, mode)
register rtx op;
enum machine_mode mode;
{
return ((CONSTANT_P (op)
|| (GET_CODE (op) == CONST_DOUBLE
&& (GET_MODE (op) == mode || mode == VOIDmode)))
&& LEGITIMATE_CONSTANT_P (op));
}
/* Return 1 if OP is a general operand that is not an immediate operand. */
int
nonimmediate_operand (op, mode)
register rtx op;
enum machine_mode mode;
{
return (general_operand (op, mode)
&& ! CONSTANT_P (op) && GET_CODE (op) != CONST_DOUBLE);
}
/* Return 1 if OP is a register reference or immediate value of mode MODE. */
int
nonmemory_operand (op, mode)
register rtx op;
enum machine_mode mode;
{
if (CONSTANT_P (op) || GET_CODE (op) == CONST_DOUBLE)
return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
&& LEGITIMATE_CONSTANT_P (op));
if (GET_MODE (op) != mode && mode != VOIDmode)
return 0;
if (GET_CODE (op) == SUBREG)
{
/* Before reload, we can allow (SUBREG (MEM...)) as a register operand
because it is guaranteed to be reloaded into one.
Just make sure the MEM is valid in itself.
(Ideally, (SUBREG (MEM)...) should not exist after reload,
but currently it does result from (SUBREG (REG)...) where the
reg went on the stack.) */
if (! reload_completed)
return general_operand (op, mode);
}
while (GET_CODE (op) == SUBREG)
op = SUBREG_REG (op);
return GET_CODE (op) == REG;
}
/* Return 1 if OP is a valid operand that stands for pushing a
value of mode MODE onto the stack.
The main use of this function is as a predicate in match_operand
expressions in the machine description. */
int
push_operand (op, mode)
rtx op;
enum machine_mode mode;
{
if (GET_CODE (op) != MEM)
return 0;
if (GET_MODE (op) != mode)
return 0;
op = XEXP (op, 0);
#ifdef STACK_GROWS_DOWNWARD
if (GET_CODE (op) != PRE_DEC)
return 0;
#else
if (GET_CODE (op) != PRE_INC)
return 0;
#endif
return XEXP (op, 0) == stack_pointer_rtx;
}
/* Return 1 if ADDR is a valid memory address for mode MODE. */
int
memory_address_p (mode, addr)
enum machine_mode mode;
register rtx addr;
{
GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
return 0;
win:
return 1;
}
/* Return 1 if OP is a valid memory reference with mode MODE,
including a valid address.
The main use of this function is as a predicate in match_operand
expressions in the machine description. */
int
memory_operand (op, mode)
register rtx op;
enum machine_mode mode;
{
rtx inner;
int mode_altering_drug = 0;
if (! reload_completed)
/* Note that no SUBREG is a memory operand before end of reload pass,
because (SUBREG (MEM...)) forces reloading into a register. */
return GET_CODE (op) == MEM && general_operand (op, mode);
if (mode != VOIDmode && GET_MODE (op) != mode)
return 0;
inner = op;
while (GET_CODE (inner) == SUBREG)
inner = SUBREG_REG (inner);
return (GET_CODE (inner) == MEM && general_operand (op, mode));
}
/* Return 1 if OP is a valid indirect memory reference with mode MODE;
that is, a memory reference whose address is a general_operand. */
int
indirect_operand (op, mode)
register rtx op;
enum machine_mode mode;
{
return (GET_MODE (op) == mode && memory_operand (op, mode)
&& general_operand (XEXP (op, 0), Pmode));
}
/* If BODY is an insn body that uses ASM_OPERANDS,
return the number of operands (both input and output) in the insn.
Otherwise return -1. */
int
asm_noperands (body)
rtx body;
{
if (GET_CODE (body) == ASM_OPERANDS)
/* No output operands: return number of input operands. */
return XVECLEN (body, 3);
if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
/* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
return XVECLEN (SET_SRC (body), 3) + 1;
else if (GET_CODE (body) == PARALLEL
&& GET_CODE (XVECEXP (body, 0, 0)) == SET
&& GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
{
/* Multiple output operands, or 1 output plus some clobbers:
body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
int i;
int n_sets;
/* Count backwards through CLOBBERs to determine number of SETs. */
for (i = XVECLEN (body, 0); i > 0; i--)
{
if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
break;
if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
return -1;
}
/* N_SETS is now number of output operands. */
n_sets = i;
/* Verify that all the SETs we have
came from a single original asm_operands insn
(so that invalid combinations are blocked). */
for (i = 0; i < n_sets; i++)
{
rtx elt = XVECEXP (body, 0, i);
if (GET_CODE (elt) != SET)
return -1;
if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
return -1;
/* If these ASM_OPERANDS rtx's came from different original insns
then they aren't allowed together. */
if (XVEC (SET_SRC (elt), 3)
!= XVEC (SET_SRC (XVECEXP (body, 0, 0)), 3))
return -1;
}
return XVECLEN (SET_SRC (XVECEXP (body, 0, 0)), 3) + n_sets;
}
else if (GET_CODE (body) == PARALLEL
&& GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
{
/* 0 outputs, but some clobbers:
body is [(asm_operands ...) (clobber (reg ...))...]. */
int i;
int n_sets;
/* Make sure all the other parallel things really are clobbers. */
for (i = XVECLEN (body, 0) - 1; i > 0; i--)
if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
return -1;
return XVECLEN (XVECEXP (body, 0, 0), 3);
}
else
return -1;
}
/* Assuming BODY is an insn body that uses ASM_OPERANDS,
copy its operands (both input and output) into the vector OPERANDS,
the locations of the operands within the insn into the vector OPERAND_LOCS,
and the constraints for the operands into CONSTRAINTS.
Write the modes of the operands into MODES.
Return the assembler-template.
If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
we don't store that info. */
char *
decode_asm_operands (body, operands, operand_locs, constraints, modes)
rtx body;
rtx *operands;
rtx **operand_locs;
char **constraints;
enum machine_mode *modes;
{
register int i;
int noperands;
char *template = 0;
if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
{
rtx asmop = SET_SRC (body);
/* Single output operand: BODY is (set OUTPUT (asm_operands ....)). */
noperands = XVECLEN (asmop, 3) + 1;
/* The input operands are found in the 1st element vector. */
/* Constraints for inputs are in the 2nd element vector. */
for (i = 1; i < noperands; i++)
{
if (operand_locs)
operand_locs[i] = &XVECEXP (asmop, 3, i - 1);
if (operands)
operands[i] = XVECEXP (asmop, 3, i - 1);
if (constraints)
constraints[i] = XSTR (XVECEXP (asmop, 4, i - 1), 0);
if (modes)
modes[i] = GET_MODE (XVECEXP (asmop, 4, i - 1));
}
/* The output is in the SET.
Its constraint is in the ASM_OPERANDS itself. */
if (operands)
operands[0] = SET_DEST (body);
if (operand_locs)
operand_locs[0] = &SET_DEST (body);
if (constraints)
constraints[0] = XSTR (asmop, 1);
if (modes)
modes[0] = GET_MODE (SET_DEST (body));
template = XSTR (asmop, 0);
}
else if (GET_CODE (body) == ASM_OPERANDS)
{
rtx asmop = body;
/* No output operands: BODY is (asm_operands ....). */
noperands = XVECLEN (asmop, 3);
/* The input operands are found in the 1st element vector. */
/* Constraints for inputs are in the 2nd element vector. */
for (i = 0; i < noperands; i++)
{
if (operand_locs)
operand_locs[i] = &XVECEXP (asmop, 3, i);
if (operands)
operands[i] = XVECEXP (asmop, 3, i);
if (constraints)
constraints[i] = XSTR (XVECEXP (asmop, 4, i), 0);
if (modes)
modes[i] = GET_MODE (XVECEXP (asmop, 4, i));
}
template = XSTR (asmop, 0);
}
else if (GET_CODE (body) == PARALLEL
&& GET_CODE (XVECEXP (body, 0, 0)) == SET)
{
rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
int nin = XVECLEN (asmop, 3);
int nout = 0; /* Does not include CLOBBERs. */
/* At least one output, plus some CLOBBERs. */
/* The outputs are in the SETs.
Their constraints are in the ASM_OPERANDS itself. */
for (i = 0; i < nparallel; i++)
{
if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
break; /* Past last SET */
if (operands)
operands[i] = SET_DEST (XVECEXP (body, 0, i));
if (operand_locs)
operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
if (constraints)
constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
if (modes)
modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
nout++;
}
/* The input operands are found in the 1st element vector. */
/* Constraints for inputs are in the 2nd element vector. */
for (i = 0; i < nin; i++)
{
if (operand_locs)
operand_locs[i + nout] = &XVECEXP (asmop, 3, i);
if (operands)
operands[i + nout] = XVECEXP (asmop, 3, i);
if (constraints)
constraints[i + nout] = XSTR (XVECEXP (asmop, 4, i), 0);
if (modes)
modes[i + nout] = GET_MODE (XVECEXP (asmop, 4, i));
}
template = XSTR (asmop, 0);
}
else if (GET_CODE (body) == PARALLEL
&& GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
{
/* No outputs, but some CLOBBERs. */
rtx asmop = XVECEXP (body, 0, 0);
int nin = XVECLEN (asmop, 3);
/* The input operands are found in the 1st element vector. */
/* Constraints for inputs are in the 2nd element vector. */
for (i = 0; i < nin; i++)
{
if (operand_locs)
operand_locs[i] = &XVECEXP (asmop, 3, i);
if (operands)
operands[i] = XVECEXP (asmop, 3, i);
if (constraints)
constraints[i] = XSTR (XVECEXP (asmop, 4, i), 0);
if (modes)
modes[i] = GET_MODE (XVECEXP (asmop, 4, i));
}
template = XSTR (asmop, 0);
}
return template;
}
extern rtx plus_constant ();
extern rtx copy_rtx ();
/* Given an rtx *P, if it is a sum containing an integer constant term,
return the location (type rtx *) of the pointer to that constant term.
Otherwise, return a null pointer. */
static rtx *
find_constant_term_loc (p)
rtx *p;
{
register rtx *tem;
register enum rtx_code code = GET_CODE (*p);
/* If *P IS such a constant term, P is its location. */
if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
|| code == CONST)
return p;
/* Otherwise, if not a sum, it has no constant term. */
if (GET_CODE (*p) != PLUS)
return 0;
/* If one of the summands is constant, return its location. */
if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
&& XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
return p;
/* Otherwise, check each summand for containing a constant term. */
if (XEXP (*p, 0) != 0)
{
tem = find_constant_term_loc (&XEXP (*p, 0));
if (tem != 0)
return tem;
}
if (XEXP (*p, 1) != 0)
{
tem = find_constant_term_loc (&XEXP (*p, 1));
if (tem != 0)
return tem;
}
return 0;
}
/* Return 1 if OP is a memory reference
whose address contains no side effects
and remains valid after the addition
of a positive integer less than the
size of the object being referenced.
We assume that the original address is valid and do not check it.
This uses strict_memory_address_p as a subroutine, so
don't use it before reload. */
int
offsettable_memref_p (op)
rtx op;
{
return ((GET_CODE (op) == MEM)
&& offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
}
/* Return 1 if Y is a memory address which contains no side effects
and would remain valid for mode MODE
after the addition of a positive integer less than the
size of that mode.
We assume that the original address is valid and do not check it.
If STRICTP is nonzero, we require a strictly valid address,
for the sake of use in reload.c. */
int
offsettable_address_p (strictp, mode, y)
int strictp;
enum machine_mode mode;
register rtx y;
{
register enum rtx_code ycode = GET_CODE (y);
register rtx z;
rtx y1 = y;
rtx *y2;
int (*addressp) () = (strictp ? strict_memory_address_p : memory_address_p);
if (CONSTANT_ADDRESS_P (y))
return 1;
#ifdef OFFSETTABLE_ADDRESS_P
return OFFSETTABLE_ADDRESS_P (mode, y);
#else
/* If the expression contains a constant term,
see if it remains valid when max possible offset is added. */
if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
{
int old = INTVAL (y1 = *y2);
int good;
INTVAL (y1) += GET_MODE_SIZE (mode) - 1;
good = (*addressp) (mode, y);
/* In any case, restore old contents of memory. */
INTVAL (y1) = old;
return good;
}
if (ycode == PRE_DEC || ycode == PRE_INC
|| ycode == POST_DEC || ycode == POST_INC)
return 0;
/* The offset added here is chosen as the maximum offset that
any instruction could need to add when operating on something
of the specified mode. We assume that if Y and Y+c are
valid addresses then so is Y+d for all 0<d<c. */
z = plus_constant (y, GET_MODE_SIZE (mode) - 1);
return (*addressp) (mode, z);
#endif
}
/* Return 1 if ADDR is an address-expression whose effect depends
on the mode of the memory reference it is used in.
Autoincrement addressing is a typical example of mode-dependence
because the amount of the increment depends on the mode. */
int
mode_dependent_address_p (addr)
rtx addr;
{
GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
return 0;
win:
return 1;
}
/* Return 1 if OP is a general operand
other than a memory ref with a mode dependent address. */
int
mode_independent_operand (op, mode)
enum machine_mode mode;
rtx op;
{
rtx addr;
if (! general_operand (op, mode))
return 0;
if (GET_CODE (op) != MEM)
return 1;
addr = XEXP (op, 0);
GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
return 1;
lose:
return 0;
}
/* Given an operand OP that is a valid memory reference
which satisfies offsettable_memref_p,
return a new memory reference whose address has been adjusted by OFFSET.
OFFSET should be positive and less than the size of the object referenced.
*/
rtx
adj_offsettable_operand (op, offset)
rtx op;
int offset;
{
register enum rtx_code code = GET_CODE (op);
if (code == MEM)
{
register rtx y = XEXP (op, 0);
if (CONSTANT_ADDRESS_P (y))
return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
if (GET_CODE (y) == PLUS)
{
rtx z = y;
register rtx *const_loc;
op = copy_rtx (op);
z = XEXP (op, 0);
const_loc = find_constant_term_loc (&z);
if (const_loc)
{
*const_loc = plus_constant (*const_loc, offset);
return op;
}
}
return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
}
abort ();
}
#ifdef REGISTER_CONSTRAINTS
/* Check the operands of an insn (found in recog_operands)
against the insn's operand constraints (found via INSN_CODE_NUM)
and return 1 if they are valid.
WHICH_ALTERNATIVE is set to a number which indicates which
alternative of constraints was matched: 0 for the first alternative,
1 for the next, etc.
In addition, when two operands are match
and it happens that the output operand is (reg) while the
input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
make the output operand look like the input.
This is because the output operand is the one the template will print.
This is used in final, just before printing the assembler code. */
struct funny_match
{
int this, other;
};
int
constrain_operands (insn_code_num)
int insn_code_num;
{
char *constraints[MAX_RECOG_OPERANDS];
register int c;
int noperands = insn_n_operands[insn_code_num];
struct funny_match funny_match[MAX_RECOG_OPERANDS];
int funny_match_index;
int nalternatives = insn_n_alternatives[insn_code_num];
if (noperands == 0 || nalternatives == 0)
return 1;
for (c = 0; c < noperands; c++)
constraints[c] = insn_operand_constraint[insn_code_num][c];
which_alternative = 0;
while (which_alternative < nalternatives)
{
register int opno;
int lose = 0;
funny_match_index = 0;
for (opno = 0; opno < noperands; opno++)
{
register rtx op = recog_operand[opno];
register char *p = constraints[opno];
int win = 0;
int val;
/* `alter_subreg' should already have converted any SUBREG
that appears at the level of an operand. */
while (GET_CODE (op) == SUBREG)
abort ();
/* An empty constraint or empty alternative
allows anything which matched the pattern. */
if (*p == 0 || *p == ',')
win = 1;
while (*p && (c = *p++) != ',')
switch (c)
{
case '=':
case '+':
case '?':
case '#':
case '&':
case '!':
case '*':
case '%':
break;
case '0':
case '1':
case '2':
case '3':
case '4':
/* This operand must be the same as a previous one. */
/* This kind of constraint is used for instructions such
as add when they take only two operands. */
/* Note that the lower-numbered operand is passed first. */
val = operands_match_p (recog_operand[c - '0'],
recog_operand[opno]);
if (val != 0)
win = 1;
/* If output is *x and input is *--x,
arrange later to change the output to *--x as well,
since the output op is the one that will be printed. */
if (val == 2)
{
funny_match[funny_match_index].this = opno;
funny_match[funny_match_index++].other = c - '0';
}
break;
case 'p':
/* p is used for address_operands, and everything
that must be checked was checked already. */
win = 1;
break;
/* No need to check general_operand again;
it was done in insn-recog.c. */
case 'g':
/* Anything goes unless it is a REG and really has a hard reg
but the hard reg is not in the class GENERAL_REGS. */
if (GENERAL_REGS == ALL_REGS
|| GET_CODE (op) != REG
|| reg_fits_class_p (op, GENERAL_REGS, 0, GET_MODE (op)))
win = 1;
break;
case 'r':
if (GET_CODE (op) == REG
&& (GENERAL_REGS == ALL_REGS
|| reg_fits_class_p (op, GENERAL_REGS, 0, GET_MODE (op))))
win = 1;
break;
case 'm':
if (GET_CODE (op) == MEM)
win = 1;
break;
case '<':
if (GET_CODE (op) == MEM
&& (GET_CODE (XEXP (op, 0)) == PRE_DEC
|| GET_CODE (XEXP (op, 0)) == POST_DEC))
win = 1;
break;
case '>':
if (GET_CODE (op) == MEM
&& (GET_CODE (XEXP (op, 0)) == PRE_INC
|| GET_CODE (XEXP (op, 0)) == POST_INC))
win = 1;
break;
case 'F':
if (GET_CODE (op) == CONST_DOUBLE)
win = 1;
break;
case 'G':
case 'H':
if (GET_CODE (op) == CONST_DOUBLE
&& CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
win = 1;
break;
case 's':
if (GET_CODE (op) == CONST_INT)
break;
case 'i':
if (CONSTANT_P (op))
win = 1;
break;
case 'n':
if (GET_CODE (op) == CONST_INT)
win = 1;
break;
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
if (GET_CODE (op) == CONST_INT
&& CONST_OK_FOR_LETTER_P (INTVAL (op), c))
win = 1;
break;
case 'o':
if (offsettable_memref_p (op))
win = 1;
break;
default:
if (GET_CODE (op) == REG
&& reg_fits_class_p (op, REG_CLASS_FROM_LETTER (c),
0, GET_MODE (op)))
win = 1;
}
constraints[opno] = p;
/* If this operand did not win somehow,
this alternative loses. */
if (! win)
lose = 1;
}
/* This alternative won; the operands are ok.
Change whichever operands this alternative says to change. */
if (! lose)
{
while (--funny_match_index >= 0)
{
recog_operand[funny_match[funny_match_index].other]
= recog_operand[funny_match[funny_match_index].this];
}
return 1;
}
which_alternative++;
}
return 0;
}
/* Return 1 iff OPERAND (assumed to be a REG rtx)
is a hard reg in class CLASS when its regno is offsetted by OFFSET
and changed to mode MODE.
If REG occupies multiple hard regs, all of them must be in CLASS. */
int
reg_fits_class_p (operand, class, offset, mode)
rtx operand;
register enum reg_class class;
int offset;
enum machine_mode mode;
{
register int regno = REGNO (operand);
if (regno < FIRST_PSEUDO_REGISTER
&& TEST_HARD_REG_BIT (reg_class_contents[(int) class],
regno + offset))
{
register int sr;
regno += offset;
for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
sr > 0; sr--)
if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
regno + sr))
break;
return sr == 0;
}
return 0;
}
#endif /* REGISTER_CONSTRAINTS */
|