mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
genattrtab.c
5304 lines (4478 loc) · 142 KB
/
genattrtab.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
/* Generate code from machine description to compute values of attributes.
Copyright (C) 1991-2016 Free Software Foundation, Inc.
Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
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/>. */
/* This program handles insn attributes and the DEFINE_DELAY and
DEFINE_INSN_RESERVATION definitions.
It produces a series of functions named `get_attr_...', one for each insn
attribute. Each of these is given the rtx for an insn and returns a member
of the enum for the attribute.
These subroutines have the form of a `switch' on the INSN_CODE (via
`recog_memoized'). Each case either returns a constant attribute value
or a value that depends on tests on other attributes, the form of
operands, or some random C expression (encoded with a SYMBOL_REF
expression).
If the attribute `alternative', or a random C expression is present,
`constrain_operands' is called. If either of these cases of a reference to
an operand is found, `extract_insn' is called.
The special attribute `length' is also recognized. For this operand,
expressions involving the address of an operand or the current insn,
(address (pc)), are valid. In this case, an initial pass is made to
set all lengths that do not depend on address. Those that do are set to
the maximum length. Then each insn that depends on an address is checked
and possibly has its length changed. The process repeats until no further
changed are made. The resulting lengths are saved for use by
`get_attr_length'.
A special form of DEFINE_ATTR, where the expression for default value is a
CONST expression, indicates an attribute that is constant for a given run
of the compiler. The subroutine generated for these attributes has no
parameters as it does not depend on any particular insn. Constant
attributes are typically used to specify which variety of processor is
used.
Internal attributes are defined to handle DEFINE_DELAY and
DEFINE_INSN_RESERVATION. Special routines are output for these cases.
This program works by keeping a list of possible values for each attribute.
These include the basic attribute choices, default values for attribute, and
all derived quantities.
As the description file is read, the definition for each insn is saved in a
`struct insn_def'. When the file reading is complete, a `struct insn_ent'
is created for each insn and chained to the corresponding attribute value,
either that specified, or the default.
An optimization phase is then run. This simplifies expressions for each
insn. EQ_ATTR tests are resolved, whenever possible, to a test that
indicates when the attribute has the specified value for the insn. This
avoids recursive calls during compilation.
The strategy used when processing DEFINE_DELAY definitions is to create
arbitrarily complex expressions and have the optimization simplify them.
Once optimization is complete, any required routines and definitions
will be written.
An optimization that is not yet implemented is to hoist the constant
expressions entirely out of the routines and definitions that are written.
A way to do this is to iterate over all possible combinations of values
for constant attributes and generate a set of functions for that given
combination. An initialization function would be written that evaluates
the attributes and installs the corresponding set of routines and
definitions (each would be accessed through a pointer).
We use the flags in an RTX as follows:
`unchanging' (ATTR_IND_SIMPLIFIED_P): This rtx is fully simplified
independent of the insn code.
`in_struct' (ATTR_CURR_SIMPLIFIED_P): This rtx is fully simplified
for the insn code currently being processed (see optimize_attrs).
`return_val' (ATTR_PERMANENT_P): This rtx is permanent and unique
(see attr_rtx). */
#define ATTR_IND_SIMPLIFIED_P(RTX) (RTX_FLAG ((RTX), unchanging))
#define ATTR_CURR_SIMPLIFIED_P(RTX) (RTX_FLAG ((RTX), in_struct))
#define ATTR_PERMANENT_P(RTX) (RTX_FLAG ((RTX), return_val))
#if 0
#define strcmp_check(S1, S2) ((S1) == (S2) \
? 0 \
: (gcc_assert (strcmp ((S1), (S2))), 1))
#else
#define strcmp_check(S1, S2) ((S1) != (S2))
#endif
#include "bconfig.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "rtl.h"
#include "obstack.h"
#include "errors.h"
#include "read-md.h"
#include "gensupport.h"
#include "fnmatch.h"
#define DEBUG 0
/* Flags for make_internal_attr's `special' parameter. */
#define ATTR_NONE 0
#define ATTR_SPECIAL (1 << 0)
static struct obstack obstack1, obstack2;
static struct obstack *hash_obstack = &obstack1;
static struct obstack *temp_obstack = &obstack2;
/* enough space to reserve for printing out ints */
#define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
/* Define structures used to record attributes and values. */
/* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
encountered, we store all the relevant information into a
`struct insn_def'. This is done to allow attribute definitions to occur
anywhere in the file. */
struct insn_def
{
struct insn_def *next; /* Next insn in chain. */
rtx def; /* The DEFINE_... */
int insn_code; /* Instruction number. */
int insn_index; /* Expression number in file, for errors. */
file_location loc; /* Where in the .md files it occurs. */
int num_alternatives; /* Number of alternatives. */
int vec_idx; /* Index of attribute vector in `def'. */
};
/* Once everything has been read in, we store in each attribute value a list
of insn codes that have that value. Here is the structure used for the
list. */
struct insn_ent
{
struct insn_ent *next; /* Next in chain. */
struct insn_def *def; /* Instruction definition. */
};
/* Each value of an attribute (either constant or computed) is assigned a
structure which is used as the listhead of the insns that have that
value. */
struct attr_value
{
rtx value; /* Value of attribute. */
struct attr_value *next; /* Next attribute value in chain. */
struct insn_ent *first_insn; /* First insn with this value. */
int num_insns; /* Number of insns with this value. */
int has_asm_insn; /* True if this value used for `asm' insns */
};
/* Structure for each attribute. */
struct attr_desc
{
char *name; /* Name of attribute. */
const char *enum_name; /* Enum name for DEFINE_ENUM_NAME. */
struct attr_desc *next; /* Next attribute. */
struct attr_value *first_value; /* First value of this attribute. */
struct attr_value *default_val; /* Default value for this attribute. */
file_location loc; /* Where in the .md files it occurs. */
unsigned is_numeric : 1; /* Values of this attribute are numeric. */
unsigned is_const : 1; /* Attribute value constant for each run. */
unsigned is_special : 1; /* Don't call `write_attr_set'. */
};
/* Structure for each DEFINE_DELAY. */
struct delay_desc
{
rtx def; /* DEFINE_DELAY expression. */
struct delay_desc *next; /* Next DEFINE_DELAY. */
file_location loc; /* Where in the .md files it occurs. */
int num; /* Number of DEFINE_DELAY, starting at 1. */
};
struct attr_value_list
{
struct attr_value *av;
struct insn_ent *ie;
struct attr_desc *attr;
struct attr_value_list *next;
};
/* Listheads of above structures. */
/* This one is indexed by the first character of the attribute name. */
#define MAX_ATTRS_INDEX 256
static struct attr_desc *attrs[MAX_ATTRS_INDEX];
static struct insn_def *defs;
static struct delay_desc *delays;
struct attr_value_list **insn_code_values;
/* Other variables. */
static int insn_index_number;
static int got_define_asm_attributes;
static int must_extract;
static int must_constrain;
static int address_used;
static int length_used;
static int num_delays;
static int have_annul_true, have_annul_false;
static int num_insn_ents;
/* Stores, for each insn code, the number of constraint alternatives. */
static int *insn_n_alternatives;
/* Stores, for each insn code, a bitmap that has bits on for each possible
alternative. */
static uint64_t *insn_alternatives;
/* Used to simplify expressions. */
static rtx true_rtx, false_rtx;
/* Used to reduce calls to `strcmp' */
static const char *alternative_name;
static const char *length_str;
static const char *delay_type_str;
static const char *delay_1_0_str;
static const char *num_delay_slots_str;
/* Simplify an expression. Only call the routine if there is something to
simplify. */
#define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \
(ATTR_IND_SIMPLIFIED_P (EXP) || ATTR_CURR_SIMPLIFIED_P (EXP) ? (EXP) \
: simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
#define DEF_ATTR_STRING(S) (attr_string ((S), strlen (S)))
/* Forward declarations of functions used before their definitions, only. */
static char *attr_string (const char *, int);
static char *attr_printf (unsigned int, const char *, ...)
ATTRIBUTE_PRINTF_2;
static rtx make_numeric_value (int);
static struct attr_desc *find_attr (const char **, int);
static rtx mk_attr_alt (uint64_t);
static char *next_comma_elt (const char **);
static rtx insert_right_side (enum rtx_code, rtx, rtx, int, int);
static rtx copy_boolean (rtx);
static int compares_alternatives_p (rtx);
static void make_internal_attr (const char *, rtx, int);
static void insert_insn_ent (struct attr_value *, struct insn_ent *);
static void walk_attr_value (rtx);
static int max_attr_value (rtx, int*);
static int min_attr_value (rtx, int*);
static int or_attr_value (rtx, int*);
static rtx simplify_test_exp (rtx, int, int);
static rtx simplify_test_exp_in_temp (rtx, int, int);
static rtx copy_rtx_unchanging (rtx);
static bool attr_alt_subset_p (rtx, rtx);
static bool attr_alt_subset_of_compl_p (rtx, rtx);
static void clear_struct_flag (rtx);
static void write_attr_valueq (FILE *, struct attr_desc *, const char *);
static struct attr_value *find_most_used (struct attr_desc *);
static void write_attr_set (FILE *, struct attr_desc *, int, rtx,
const char *, const char *, rtx,
int, int, unsigned int);
static void write_attr_case (FILE *, struct attr_desc *,
struct attr_value *,
int, const char *, const char *, int, rtx);
static void write_attr_value (FILE *, struct attr_desc *, rtx);
static void write_upcase (FILE *, const char *);
static void write_indent (FILE *, int);
static rtx identity_fn (rtx);
static rtx zero_fn (rtx);
static rtx one_fn (rtx);
static rtx max_fn (rtx);
static rtx min_fn (rtx);
#define oballoc(T) XOBNEW (hash_obstack, T)
#define oballocvec(T, N) XOBNEWVEC (hash_obstack, T, (N))
/* This gen* file is unique, in that it writes out multiple files.
Before GCC 4.8, insn-attrtab.c was written out containing many large
functions and tables. This made insn-attrtab.c _the_ bottle-neck in
a parallel build, and even made it impossible to build GCC on machines
with relatively small RAM space (PR other/29442). Therefore, the
atrribute functions/tables are now written out to three separate
files: all "*insn_default_latency" functions go to LATENCY_FILE_NAME,
all "*internal_dfa_insn_code" functions go to DFA_FILE_NAME, and the
rest goes to ATTR_FILE_NAME. */
static const char *attr_file_name = NULL;
static const char *dfa_file_name = NULL;
static const char *latency_file_name = NULL;
static FILE *attr_file, *dfa_file, *latency_file;
/* Hash table for sharing RTL and strings. */
/* Each hash table slot is a bucket containing a chain of these structures.
Strings are given negative hash codes; RTL expressions are given positive
hash codes. */
struct attr_hash
{
struct attr_hash *next; /* Next structure in the bucket. */
unsigned int hashcode; /* Hash code of this rtx or string. */
union
{
char *str; /* The string (negative hash codes) */
rtx rtl; /* or the RTL recorded here. */
} u;
};
/* Now here is the hash table. When recording an RTL, it is added to
the slot whose index is the hash code mod the table size. Note
that the hash table is used for several kinds of RTL (see attr_rtx)
and for strings. While all these live in the same table, they are
completely independent, and the hash code is computed differently
for each. */
#define RTL_HASH_SIZE 4093
static struct attr_hash *attr_hash_table[RTL_HASH_SIZE];
/* Here is how primitive or already-shared RTL's hash
codes are made. */
#define RTL_HASH(RTL) ((intptr_t) (RTL) & 0777777)
/* Add an entry to the hash table for RTL with hash code HASHCODE. */
static void
attr_hash_add_rtx (unsigned int hashcode, rtx rtl)
{
struct attr_hash *h;
h = XOBNEW (hash_obstack, struct attr_hash);
h->hashcode = hashcode;
h->u.rtl = rtl;
h->next = attr_hash_table[hashcode % RTL_HASH_SIZE];
attr_hash_table[hashcode % RTL_HASH_SIZE] = h;
}
/* Add an entry to the hash table for STRING with hash code HASHCODE. */
static void
attr_hash_add_string (unsigned int hashcode, char *str)
{
struct attr_hash *h;
h = XOBNEW (hash_obstack, struct attr_hash);
h->hashcode = -hashcode;
h->u.str = str;
h->next = attr_hash_table[hashcode % RTL_HASH_SIZE];
attr_hash_table[hashcode % RTL_HASH_SIZE] = h;
}
/* Generate an RTL expression, but avoid duplicates.
Set the ATTR_PERMANENT_P flag for these permanent objects.
In some cases we cannot uniquify; then we return an ordinary
impermanent rtx with ATTR_PERMANENT_P clear.
Args are as follows:
rtx attr_rtx (code, [element1, ..., elementn]) */
static rtx
attr_rtx_1 (enum rtx_code code, va_list p)
{
rtx rt_val = NULL_RTX;/* RTX to return to caller... */
unsigned int hashcode;
struct attr_hash *h;
struct obstack *old_obstack = rtl_obstack;
int permanent_p = 1;
/* For each of several cases, search the hash table for an existing entry.
Use that entry if one is found; otherwise create a new RTL and add it
to the table. */
if (GET_RTX_CLASS (code) == RTX_UNARY)
{
rtx arg0 = va_arg (p, rtx);
if (! ATTR_PERMANENT_P (arg0))
permanent_p = 0;
hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0));
for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
if (h->hashcode == hashcode
&& GET_CODE (h->u.rtl) == code
&& XEXP (h->u.rtl, 0) == arg0)
return h->u.rtl;
if (h == 0)
{
rtl_obstack = hash_obstack;
rt_val = rtx_alloc (code);
XEXP (rt_val, 0) = arg0;
}
}
else if (GET_RTX_CLASS (code) == RTX_BIN_ARITH
|| GET_RTX_CLASS (code) == RTX_COMM_ARITH
|| GET_RTX_CLASS (code) == RTX_COMPARE
|| GET_RTX_CLASS (code) == RTX_COMM_COMPARE)
{
rtx arg0 = va_arg (p, rtx);
rtx arg1 = va_arg (p, rtx);
if (! ATTR_PERMANENT_P (arg0) || ! ATTR_PERMANENT_P (arg1))
permanent_p = 0;
hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0) + RTL_HASH (arg1));
for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
if (h->hashcode == hashcode
&& GET_CODE (h->u.rtl) == code
&& XEXP (h->u.rtl, 0) == arg0
&& XEXP (h->u.rtl, 1) == arg1)
{
ATTR_CURR_SIMPLIFIED_P (h->u.rtl) = 0;
return h->u.rtl;
}
if (h == 0)
{
rtl_obstack = hash_obstack;
rt_val = rtx_alloc (code);
XEXP (rt_val, 0) = arg0;
XEXP (rt_val, 1) = arg1;
}
}
else if (code == SYMBOL_REF
|| (GET_RTX_LENGTH (code) == 1
&& GET_RTX_FORMAT (code)[0] == 's'))
{
char *arg0 = va_arg (p, char *);
arg0 = DEF_ATTR_STRING (arg0);
hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0));
for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
if (h->hashcode == hashcode
&& GET_CODE (h->u.rtl) == code
&& XSTR (h->u.rtl, 0) == arg0)
return h->u.rtl;
if (h == 0)
{
rtl_obstack = hash_obstack;
rt_val = rtx_alloc (code);
XSTR (rt_val, 0) = arg0;
if (code == SYMBOL_REF)
X0EXP (rt_val, 1) = NULL_RTX;
}
}
else if (GET_RTX_LENGTH (code) == 2
&& GET_RTX_FORMAT (code)[0] == 's'
&& GET_RTX_FORMAT (code)[1] == 's')
{
char *arg0 = va_arg (p, char *);
char *arg1 = va_arg (p, char *);
arg0 = DEF_ATTR_STRING (arg0);
arg1 = DEF_ATTR_STRING (arg1);
hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0) + RTL_HASH (arg1));
for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
if (h->hashcode == hashcode
&& GET_CODE (h->u.rtl) == code
&& XSTR (h->u.rtl, 0) == arg0
&& XSTR (h->u.rtl, 1) == arg1)
return h->u.rtl;
if (h == 0)
{
rtl_obstack = hash_obstack;
rt_val = rtx_alloc (code);
XSTR (rt_val, 0) = arg0;
XSTR (rt_val, 1) = arg1;
}
}
else if (GET_RTX_LENGTH (code) == 2
&& GET_RTX_FORMAT (code)[0] == 'i'
&& GET_RTX_FORMAT (code)[1] == 'i')
{
int arg0 = va_arg (p, int);
int arg1 = va_arg (p, int);
hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0) + RTL_HASH (arg1));
for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
if (h->hashcode == hashcode
&& GET_CODE (h->u.rtl) == code
&& XINT (h->u.rtl, 0) == arg0
&& XINT (h->u.rtl, 1) == arg1)
return h->u.rtl;
if (h == 0)
{
rtl_obstack = hash_obstack;
rt_val = rtx_alloc (code);
XINT (rt_val, 0) = arg0;
XINT (rt_val, 1) = arg1;
}
}
else if (code == CONST_INT)
{
HOST_WIDE_INT arg0 = va_arg (p, HOST_WIDE_INT);
if (arg0 == 0)
return false_rtx;
else if (arg0 == 1)
return true_rtx;
else
goto nohash;
}
else
{
int i; /* Array indices... */
const char *fmt; /* Current rtx's format... */
nohash:
rt_val = rtx_alloc (code); /* Allocate the storage space. */
fmt = GET_RTX_FORMAT (code); /* Find the right format... */
for (i = 0; i < GET_RTX_LENGTH (code); i++)
{
switch (*fmt++)
{
case '0': /* Unused field. */
break;
case 'i': /* An integer? */
XINT (rt_val, i) = va_arg (p, int);
break;
case 'w': /* A wide integer? */
XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
break;
case 's': /* A string? */
XSTR (rt_val, i) = va_arg (p, char *);
break;
case 'e': /* An expression? */
case 'u': /* An insn? Same except when printing. */
XEXP (rt_val, i) = va_arg (p, rtx);
break;
case 'E': /* An RTX vector? */
XVEC (rt_val, i) = va_arg (p, rtvec);
break;
default:
gcc_unreachable ();
}
}
return rt_val;
}
rtl_obstack = old_obstack;
attr_hash_add_rtx (hashcode, rt_val);
ATTR_PERMANENT_P (rt_val) = permanent_p;
return rt_val;
}
static rtx
attr_rtx (enum rtx_code code, ...)
{
rtx result;
va_list p;
va_start (p, code);
result = attr_rtx_1 (code, p);
va_end (p);
return result;
}
/* Create a new string printed with the printf line arguments into a space
of at most LEN bytes:
rtx attr_printf (len, format, [arg1, ..., argn]) */
static char *
attr_printf (unsigned int len, const char *fmt, ...)
{
char str[256];
va_list p;
va_start (p, fmt);
gcc_assert (len < sizeof str); /* Leave room for \0. */
vsprintf (str, fmt, p);
va_end (p);
return DEF_ATTR_STRING (str);
}
static rtx
attr_eq (const char *name, const char *value)
{
return attr_rtx (EQ_ATTR, name, value);
}
static const char *
attr_numeral (int n)
{
return XSTR (make_numeric_value (n), 0);
}
/* Return a permanent (possibly shared) copy of a string STR (not assumed
to be null terminated) with LEN bytes. */
static char *
attr_string (const char *str, int len)
{
struct attr_hash *h;
unsigned int hashcode;
int i;
char *new_str;
/* Compute the hash code. */
hashcode = (len + 1) * 613U + (unsigned) str[0];
for (i = 1; i < len; i += 2)
hashcode = ((hashcode * 613) + (unsigned) str[i]);
if ((int) hashcode < 0)
hashcode = -hashcode;
/* Search the table for the string. */
for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
if (h->hashcode == -hashcode && h->u.str[0] == str[0]
&& !strncmp (h->u.str, str, len))
return h->u.str; /* <-- return if found. */
/* Not found; create a permanent copy and add it to the hash table. */
new_str = XOBNEWVAR (hash_obstack, char, len + 1);
memcpy (new_str, str, len);
new_str[len] = '\0';
attr_hash_add_string (hashcode, new_str);
rtx_reader_ptr->copy_md_ptr_loc (new_str, str);
return new_str; /* Return the new string. */
}
/* Check two rtx's for equality of contents,
taking advantage of the fact that if both are hashed
then they can't be equal unless they are the same object. */
static int
attr_equal_p (rtx x, rtx y)
{
return (x == y || (! (ATTR_PERMANENT_P (x) && ATTR_PERMANENT_P (y))
&& rtx_equal_p (x, y)));
}
/* Given a test expression EXP for attribute ATTR, ensure it is validly
formed. LOC is the location of the .md construct that contains EXP.
Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")). Do the latter
test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
Update the string address in EQ_ATTR expression to be the same used
in the attribute (or `alternative_name') to speed up subsequent
`find_attr' calls and eliminate most `strcmp' calls.
Return the new expression, if any. */
static rtx
check_attr_test (file_location loc, rtx exp, attr_desc *attr)
{
struct attr_value *av;
const char *name_ptr, *p;
rtx orexp, newexp;
switch (GET_CODE (exp))
{
case EQ_ATTR:
/* Handle negation test. */
if (XSTR (exp, 1)[0] == '!')
return check_attr_test (loc,
attr_rtx (NOT,
attr_eq (XSTR (exp, 0),
&XSTR (exp, 1)[1])),
attr);
else if (n_comma_elts (XSTR (exp, 1)) == 1)
{
attr_desc *attr2 = find_attr (&XSTR (exp, 0), 0);
if (attr2 == NULL)
{
if (! strcmp (XSTR (exp, 0), "alternative"))
return mk_attr_alt (((uint64_t) 1) << atoi (XSTR (exp, 1)));
else
fatal_at (loc, "unknown attribute `%s' in definition of"
" attribute `%s'", XSTR (exp, 0), attr->name);
}
if (attr->is_const && ! attr2->is_const)
fatal_at (loc, "constant attribute `%s' cannot test non-constant"
" attribute `%s'", attr->name, attr2->name);
/* Copy this just to make it permanent,
so expressions using it can be permanent too. */
exp = attr_eq (XSTR (exp, 0), XSTR (exp, 1));
/* It shouldn't be possible to simplify the value given to a
constant attribute, so don't expand this until it's time to
write the test expression. */
if (attr2->is_const)
ATTR_IND_SIMPLIFIED_P (exp) = 1;
if (attr2->is_numeric)
{
for (p = XSTR (exp, 1); *p; p++)
if (! ISDIGIT (*p))
fatal_at (loc, "attribute `%s' takes only numeric values",
attr2->name);
}
else
{
for (av = attr2->first_value; av; av = av->next)
if (GET_CODE (av->value) == CONST_STRING
&& ! strcmp (XSTR (exp, 1), XSTR (av->value, 0)))
break;
if (av == NULL)
fatal_at (loc, "unknown value `%s' for attribute `%s'",
XSTR (exp, 1), attr2->name);
}
}
else
{
if (! strcmp (XSTR (exp, 0), "alternative"))
{
int set = 0;
name_ptr = XSTR (exp, 1);
while ((p = next_comma_elt (&name_ptr)) != NULL)
set |= ((uint64_t) 1) << atoi (p);
return mk_attr_alt (set);
}
else
{
/* Make an IOR tree of the possible values. */
orexp = false_rtx;
name_ptr = XSTR (exp, 1);
while ((p = next_comma_elt (&name_ptr)) != NULL)
{
newexp = attr_eq (XSTR (exp, 0), p);
orexp = insert_right_side (IOR, orexp, newexp, -2, -2);
}
return check_attr_test (loc, orexp, attr);
}
}
break;
case ATTR_FLAG:
break;
case CONST_INT:
/* Either TRUE or FALSE. */
if (XWINT (exp, 0))
return true_rtx;
else
return false_rtx;
case IOR:
case AND:
XEXP (exp, 0) = check_attr_test (loc, XEXP (exp, 0), attr);
XEXP (exp, 1) = check_attr_test (loc, XEXP (exp, 1), attr);
break;
case NOT:
XEXP (exp, 0) = check_attr_test (loc, XEXP (exp, 0), attr);
break;
case MATCH_TEST:
exp = attr_rtx (MATCH_TEST, XSTR (exp, 0));
ATTR_IND_SIMPLIFIED_P (exp) = 1;
break;
case MATCH_OPERAND:
if (attr->is_const)
fatal_at (loc, "invalid operator `%s' in definition of constant"
" attribute `%s'", GET_RTX_NAME (GET_CODE (exp)),
attr->name);
/* These cases can't be simplified. */
ATTR_IND_SIMPLIFIED_P (exp) = 1;
break;
case LE: case LT: case GT: case GE:
case LEU: case LTU: case GTU: case GEU:
case NE: case EQ:
if (GET_CODE (XEXP (exp, 0)) == SYMBOL_REF
&& GET_CODE (XEXP (exp, 1)) == SYMBOL_REF)
exp = attr_rtx (GET_CODE (exp),
attr_rtx (SYMBOL_REF, XSTR (XEXP (exp, 0), 0)),
attr_rtx (SYMBOL_REF, XSTR (XEXP (exp, 1), 0)));
/* These cases can't be simplified. */
ATTR_IND_SIMPLIFIED_P (exp) = 1;
break;
case SYMBOL_REF:
if (attr->is_const)
{
/* These cases are valid for constant attributes, but can't be
simplified. */
exp = attr_rtx (SYMBOL_REF, XSTR (exp, 0));
ATTR_IND_SIMPLIFIED_P (exp) = 1;
break;
}
/* FALLTHRU */
default:
fatal_at (loc, "invalid operator `%s' in definition of attribute"
" `%s'", GET_RTX_NAME (GET_CODE (exp)), attr->name);
}
return exp;
}
/* Given an expression EXP, ensure that it is validly formed and that
all named attribute values are valid for ATTR. Issue an error if not.
LOC is the location of the .md construct that contains EXP.
Return a perhaps modified replacement expression for the value. */
static rtx
check_attr_value (file_location loc, rtx exp, struct attr_desc *attr)
{
struct attr_value *av;
const char *p;
int i;
switch (GET_CODE (exp))
{
case CONST_INT:
if (!attr->is_numeric)
{
error_at (loc,
"CONST_INT not valid for non-numeric attribute `%s'",
attr->name);
break;
}
if (INTVAL (exp) < 0)
{
error_at (loc,
"negative numeric value specified for attribute `%s'",
attr->name);
break;
}
break;
case CONST_STRING:
if (! strcmp (XSTR (exp, 0), "*"))
break;
if (attr->is_numeric)
{
p = XSTR (exp, 0);
for (; *p; p++)
if (! ISDIGIT (*p))
{
error_at (loc,
"non-numeric value specified for numeric"
" attribute `%s'", attr->name);
break;
}
break;
}
for (av = attr->first_value; av; av = av->next)
if (GET_CODE (av->value) == CONST_STRING
&& ! strcmp (XSTR (av->value, 0), XSTR (exp, 0)))
break;
if (av == NULL)
error_at (loc, "unknown value `%s' for attribute `%s'",
XSTR (exp, 0), attr->name);
break;
case IF_THEN_ELSE:
XEXP (exp, 0) = check_attr_test (loc, XEXP (exp, 0), attr);
XEXP (exp, 1) = check_attr_value (loc, XEXP (exp, 1), attr);
XEXP (exp, 2) = check_attr_value (loc, XEXP (exp, 2), attr);
break;
case PLUS:
case MINUS:
case MULT:
case DIV:
case MOD:
if (!attr->is_numeric)
{
error_at (loc, "invalid operation `%s' for non-numeric"
" attribute `%s'", GET_RTX_NAME (GET_CODE (exp)),
attr->name);
break;
}
/* Fall through. */
case IOR:
case AND:
XEXP (exp, 0) = check_attr_value (loc, XEXP (exp, 0), attr);
XEXP (exp, 1) = check_attr_value (loc, XEXP (exp, 1), attr);
break;
case FFS:
case CLZ:
case CTZ:
case POPCOUNT:
case PARITY:
case BSWAP:
XEXP (exp, 0) = check_attr_value (loc, XEXP (exp, 0), attr);
break;
case COND:
if (XVECLEN (exp, 0) % 2 != 0)
{
error_at (loc, "first operand of COND must have even length");
break;
}
for (i = 0; i < XVECLEN (exp, 0); i += 2)
{
XVECEXP (exp, 0, i) = check_attr_test (attr->loc,
XVECEXP (exp, 0, i),
attr);
XVECEXP (exp, 0, i + 1)
= check_attr_value (loc, XVECEXP (exp, 0, i + 1), attr);
}
XEXP (exp, 1) = check_attr_value (loc, XEXP (exp, 1), attr);
break;
case ATTR:
{
struct attr_desc *attr2 = find_attr (&XSTR (exp, 0), 0);
if (attr2 == NULL)
error_at (loc, "unknown attribute `%s' in ATTR",
XSTR (exp, 0));
else if (attr->is_const && ! attr2->is_const)
error_at (attr->loc,
"constant attribute `%s' cannot refer to non-constant"
" attribute `%s'", attr->name, attr2->name);
else if (attr->is_numeric != attr2->is_numeric)
error_at (loc,
"numeric attribute mismatch calling `%s' from `%s'",
attr2->name, attr->name);
}
break;
case SYMBOL_REF:
/* A constant SYMBOL_REF is valid as a constant attribute test and
is expanded later by make_canonical into a COND. In a non-constant
attribute test, it is left be. */
return attr_rtx (SYMBOL_REF, XSTR (exp, 0));
default:
error_at (loc, "invalid operator `%s' in definition of attribute `%s'",
GET_RTX_NAME (GET_CODE (exp)), attr->name);
break;
}
return exp;
}
/* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
It becomes a COND with each test being (eq_attr "alternative" "n") */
static rtx
convert_set_attr_alternative (rtx exp, struct insn_def *id)
{
int num_alt = id->num_alternatives;
rtx condexp;
int i;
if (XVECLEN (exp, 1) != num_alt)
{
error_at (id->loc, "bad number of entries in SET_ATTR_ALTERNATIVE,"
" was %d expected %d", XVECLEN (exp, 1), num_alt);
return NULL_RTX;
}
/* Make a COND with all tests but the last. Select the last value via the