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
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
|
/* Definitions for Toshiba Media Processor
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
Contributed by Red Hat, 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 "tm.h"
#include "rtl.h"
#include "tree.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "insn-config.h"
#include "conditions.h"
#include "insn-flags.h"
#include "output.h"
#include "insn-attr.h"
#include "flags.h"
#include "recog.h"
#include "obstack.h"
#include "tree.h"
#include "expr.h"
#include "except.h"
#include "function.h"
#include "optabs.h"
#include "reload.h"
#include "tm_p.h"
#include "ggc.h"
#include "toplev.h"
#include "integrate.h"
#include "target.h"
#include "target-def.h"
#include "langhooks.h"
#include "df.h"
#include "gimple.h"
/* Structure of this file:
+ Command Line Option Support
+ Pattern support - constraints, predicates, expanders
+ Reload Support
+ Costs
+ Functions to save and restore machine-specific function data.
+ Frame/Epilog/Prolog Related
+ Operand Printing
+ Function args in registers
+ Handle pipeline hazards
+ Handle attributes
+ Trampolines
+ Machine-dependent Reorg
+ Builtins. */
/* Symbol encodings:
Symbols are encoded as @ <char> . <name> where <char> is one of these:
b - based
t - tiny
n - near
f - far
i - io, near
I - io, far
c - cb (control bus) */
struct GTY(()) machine_function
{
int mep_frame_pointer_needed;
/* For varargs. */
int arg_regs_to_save;
int regsave_filler;
int frame_filler;
int frame_locked;
/* Records __builtin_return address. */
rtx eh_stack_adjust;
int reg_save_size;
int reg_save_slot[FIRST_PSEUDO_REGISTER];
unsigned char reg_saved[FIRST_PSEUDO_REGISTER];
/* 2 if the current function has an interrupt attribute, 1 if not, 0
if unknown. This is here because resource.c uses EPILOGUE_USES
which needs it. */
int interrupt_handler;
/* Likewise, for disinterrupt attribute. */
int disable_interrupts;
/* Number of doloop tags used so far. */
int doloop_tags;
/* True if the last tag was allocated to a doloop_end. */
bool doloop_tag_from_end;
/* True if reload changes $TP. */
bool reload_changes_tp;
/* 2 if there are asm()s without operands, 1 if not, 0 if unknown.
We only set this if the function is an interrupt handler. */
int asms_without_operands;
};
#define MEP_CONTROL_REG(x) \
(GET_CODE (x) == REG && ANY_CONTROL_REGNO_P (REGNO (x)))
static const struct attribute_spec mep_attribute_table[11];
static GTY(()) section * based_section;
static GTY(()) section * tinybss_section;
static GTY(()) section * far_section;
static GTY(()) section * farbss_section;
static GTY(()) section * frodata_section;
static GTY(()) section * srodata_section;
static GTY(()) section * vtext_section;
static GTY(()) section * vftext_section;
static GTY(()) section * ftext_section;
static void mep_set_leaf_registers (int);
static bool symbol_p (rtx);
static bool symbolref_p (rtx);
static void encode_pattern_1 (rtx);
static void encode_pattern (rtx);
static bool const_in_range (rtx, int, int);
static void mep_rewrite_mult (rtx, rtx);
static void mep_rewrite_mulsi3 (rtx, rtx, rtx, rtx);
static void mep_rewrite_maddsi3 (rtx, rtx, rtx, rtx, rtx);
static bool mep_reuse_lo_p_1 (rtx, rtx, rtx, bool);
static bool move_needs_splitting (rtx, rtx, enum machine_mode);
static bool mep_expand_setcc_1 (enum rtx_code, rtx, rtx, rtx);
static bool mep_nongeneral_reg (rtx);
static bool mep_general_copro_reg (rtx);
static bool mep_nonregister (rtx);
static struct machine_function* mep_init_machine_status (void);
static rtx mep_tp_rtx (void);
static rtx mep_gp_rtx (void);
static bool mep_interrupt_p (void);
static bool mep_disinterrupt_p (void);
static bool mep_reg_set_p (rtx, rtx);
static bool mep_reg_set_in_function (int);
static bool mep_interrupt_saved_reg (int);
static bool mep_call_saves_register (int);
static rtx F (rtx);
static void add_constant (int, int, int, int);
static rtx maybe_dead_move (rtx, rtx, bool);
static void mep_reload_pointer (int, const char *);
static void mep_start_function (FILE *, HOST_WIDE_INT);
static bool mep_function_ok_for_sibcall (tree, tree);
static int unique_bit_in (HOST_WIDE_INT);
static int bit_size_for_clip (HOST_WIDE_INT);
static int bytesize (const_tree, enum machine_mode);
static tree mep_validate_based_tiny (tree *, tree, tree, int, bool *);
static tree mep_validate_near_far (tree *, tree, tree, int, bool *);
static tree mep_validate_disinterrupt (tree *, tree, tree, int, bool *);
static tree mep_validate_interrupt (tree *, tree, tree, int, bool *);
static tree mep_validate_io_cb (tree *, tree, tree, int, bool *);
static tree mep_validate_vliw (tree *, tree, tree, int, bool *);
static bool mep_function_attribute_inlinable_p (const_tree);
static bool mep_can_inline_p (tree, tree);
static bool mep_lookup_pragma_disinterrupt (const char *);
static int mep_multiple_address_regions (tree, bool);
static int mep_attrlist_to_encoding (tree, tree);
static void mep_insert_attributes (tree, tree *);
static void mep_encode_section_info (tree, rtx, int);
static section * mep_select_section (tree, int, unsigned HOST_WIDE_INT);
static void mep_unique_section (tree, int);
static unsigned int mep_section_type_flags (tree, const char *, int);
static void mep_asm_named_section (const char *, unsigned int, tree);
static bool mep_mentioned_p (rtx, rtx, int);
static void mep_reorg_regmove (rtx);
static rtx mep_insert_repeat_label_last (rtx, rtx, bool, bool);
static void mep_reorg_repeat (rtx);
static bool mep_invertable_branch_p (rtx);
static void mep_invert_branch (rtx, rtx);
static void mep_reorg_erepeat (rtx);
static void mep_jmp_return_reorg (rtx);
static void mep_reorg_addcombine (rtx);
static void mep_reorg (void);
static void mep_init_intrinsics (void);
static void mep_init_builtins (void);
static void mep_intrinsic_unavailable (int);
static bool mep_get_intrinsic_insn (int, const struct cgen_insn **);
static bool mep_get_move_insn (int, const struct cgen_insn **);
static rtx mep_convert_arg (enum machine_mode, rtx);
static rtx mep_convert_regnum (const struct cgen_regnum_operand *, rtx);
static rtx mep_legitimize_arg (const struct insn_operand_data *, rtx, int);
static void mep_incompatible_arg (const struct insn_operand_data *, rtx, int, tree);
static rtx mep_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
static int mep_adjust_cost (rtx, rtx, rtx, int);
static int mep_issue_rate (void);
static rtx mep_find_ready_insn (rtx *, int, enum attr_slot, int);
static void mep_move_ready_insn (rtx *, int, rtx);
static int mep_sched_reorder (FILE *, int, rtx *, int *, int);
static rtx mep_make_bundle (rtx, rtx);
static void mep_bundle_insns (rtx);
static bool mep_rtx_cost (rtx, int, int, int *, bool);
static int mep_address_cost (rtx, bool);
static void mep_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
tree, int *, int);
static bool mep_pass_by_reference (CUMULATIVE_ARGS * cum, enum machine_mode,
const_tree, bool);
static bool mep_vector_mode_supported_p (enum machine_mode);
static bool mep_handle_option (size_t, const char *, int);
static rtx mep_allocate_initial_value (rtx);
static void mep_asm_init_sections (void);
static int mep_comp_type_attributes (const_tree, const_tree);
static bool mep_narrow_volatile_bitfield (void);
static rtx mep_expand_builtin_saveregs (void);
static tree mep_build_builtin_va_list (void);
static void mep_expand_va_start (tree, rtx);
static tree mep_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
static bool mep_can_eliminate (const int, const int);
static void mep_trampoline_init (rtx, tree, rtx);
/* Initialize the GCC target structure. */
#undef TARGET_ASM_FUNCTION_PROLOGUE
#define TARGET_ASM_FUNCTION_PROLOGUE mep_start_function
#undef TARGET_ATTRIBUTE_TABLE
#define TARGET_ATTRIBUTE_TABLE mep_attribute_table
#undef TARGET_COMP_TYPE_ATTRIBUTES
#define TARGET_COMP_TYPE_ATTRIBUTES mep_comp_type_attributes
#undef TARGET_INSERT_ATTRIBUTES
#define TARGET_INSERT_ATTRIBUTES mep_insert_attributes
#undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
#define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P mep_function_attribute_inlinable_p
#undef TARGET_CAN_INLINE_P
#define TARGET_CAN_INLINE_P mep_can_inline_p
#undef TARGET_SECTION_TYPE_FLAGS
#define TARGET_SECTION_TYPE_FLAGS mep_section_type_flags
#undef TARGET_ASM_NAMED_SECTION
#define TARGET_ASM_NAMED_SECTION mep_asm_named_section
#undef TARGET_INIT_BUILTINS
#define TARGET_INIT_BUILTINS mep_init_builtins
#undef TARGET_EXPAND_BUILTIN
#define TARGET_EXPAND_BUILTIN mep_expand_builtin
#undef TARGET_SCHED_ADJUST_COST
#define TARGET_SCHED_ADJUST_COST mep_adjust_cost
#undef TARGET_SCHED_ISSUE_RATE
#define TARGET_SCHED_ISSUE_RATE mep_issue_rate
#undef TARGET_SCHED_REORDER
#define TARGET_SCHED_REORDER mep_sched_reorder
#undef TARGET_STRIP_NAME_ENCODING
#define TARGET_STRIP_NAME_ENCODING mep_strip_name_encoding
#undef TARGET_ASM_SELECT_SECTION
#define TARGET_ASM_SELECT_SECTION mep_select_section
#undef TARGET_ASM_UNIQUE_SECTION
#define TARGET_ASM_UNIQUE_SECTION mep_unique_section
#undef TARGET_ENCODE_SECTION_INFO
#define TARGET_ENCODE_SECTION_INFO mep_encode_section_info
#undef TARGET_FUNCTION_OK_FOR_SIBCALL
#define TARGET_FUNCTION_OK_FOR_SIBCALL mep_function_ok_for_sibcall
#undef TARGET_RTX_COSTS
#define TARGET_RTX_COSTS mep_rtx_cost
#undef TARGET_ADDRESS_COST
#define TARGET_ADDRESS_COST mep_address_cost
#undef TARGET_MACHINE_DEPENDENT_REORG
#define TARGET_MACHINE_DEPENDENT_REORG mep_reorg
#undef TARGET_SETUP_INCOMING_VARARGS
#define TARGET_SETUP_INCOMING_VARARGS mep_setup_incoming_varargs
#undef TARGET_PASS_BY_REFERENCE
#define TARGET_PASS_BY_REFERENCE mep_pass_by_reference
#undef TARGET_VECTOR_MODE_SUPPORTED_P
#define TARGET_VECTOR_MODE_SUPPORTED_P mep_vector_mode_supported_p
#undef TARGET_HANDLE_OPTION
#define TARGET_HANDLE_OPTION mep_handle_option
#undef TARGET_DEFAULT_TARGET_FLAGS
#define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
#undef TARGET_ALLOCATE_INITIAL_VALUE
#define TARGET_ALLOCATE_INITIAL_VALUE mep_allocate_initial_value
#undef TARGET_ASM_INIT_SECTIONS
#define TARGET_ASM_INIT_SECTIONS mep_asm_init_sections
#undef TARGET_RETURN_IN_MEMORY
#define TARGET_RETURN_IN_MEMORY mep_return_in_memory
#undef TARGET_NARROW_VOLATILE_BITFIELD
#define TARGET_NARROW_VOLATILE_BITFIELD mep_narrow_volatile_bitfield
#undef TARGET_EXPAND_BUILTIN_SAVEREGS
#define TARGET_EXPAND_BUILTIN_SAVEREGS mep_expand_builtin_saveregs
#undef TARGET_BUILD_BUILTIN_VA_LIST
#define TARGET_BUILD_BUILTIN_VA_LIST mep_build_builtin_va_list
#undef TARGET_EXPAND_BUILTIN_VA_START
#define TARGET_EXPAND_BUILTIN_VA_START mep_expand_va_start
#undef TARGET_GIMPLIFY_VA_ARG_EXPR
#define TARGET_GIMPLIFY_VA_ARG_EXPR mep_gimplify_va_arg_expr
#undef TARGET_CAN_ELIMINATE
#define TARGET_CAN_ELIMINATE mep_can_eliminate
#undef TARGET_TRAMPOLINE_INIT
#define TARGET_TRAMPOLINE_INIT mep_trampoline_init
struct gcc_target targetm = TARGET_INITIALIZER;
#define WANT_GCC_DEFINITIONS
#include "mep-intrin.h"
#undef WANT_GCC_DEFINITIONS
/* Command Line Option Support. */
char mep_leaf_registers [FIRST_PSEUDO_REGISTER];
/* True if we can use cmov instructions to move values back and forth
between core and coprocessor registers. */
bool mep_have_core_copro_moves_p;
/* True if we can use cmov instructions (or a work-alike) to move
values between coprocessor registers. */
bool mep_have_copro_copro_moves_p;
/* A table of all coprocessor instructions that can act like
a coprocessor-to-coprocessor cmov. */
static const int mep_cmov_insns[] = {
mep_cmov,
mep_cpmov,
mep_fmovs,
mep_caddi3,
mep_csubi3,
mep_candi3,
mep_cori3,
mep_cxori3,
mep_cand3,
mep_cor3
};
static int option_mtiny_specified = 0;
static void
mep_set_leaf_registers (int enable)
{
int i;
if (mep_leaf_registers[0] != enable)
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
mep_leaf_registers[i] = enable;
}
void
mep_conditional_register_usage (char *fixed_regs, char *call_used_regs)
{
int i;
if (!TARGET_OPT_MULT && !TARGET_OPT_DIV)
{
fixed_regs[HI_REGNO] = 1;
fixed_regs[LO_REGNO] = 1;
call_used_regs[HI_REGNO] = 1;
call_used_regs[LO_REGNO] = 1;
}
for (i = FIRST_SHADOW_REGISTER; i <= LAST_SHADOW_REGISTER; i++)
global_regs[i] = 1;
}
void
mep_optimization_options (void)
{
/* The first scheduling pass often increases register pressure and tends
to result in more spill code. Only run it when specifically asked. */
flag_schedule_insns = 0;
/* Using $fp doesn't gain us much, even when debugging is important. */
flag_omit_frame_pointer = 1;
}
void
mep_override_options (void)
{
if (flag_pic == 1)
warning (OPT_fpic, "-fpic is not supported");
if (flag_pic == 2)
warning (OPT_fPIC, "-fPIC is not supported");
if (TARGET_S && TARGET_M)
error ("only one of -ms and -mm may be given");
if (TARGET_S && TARGET_L)
error ("only one of -ms and -ml may be given");
if (TARGET_M && TARGET_L)
error ("only one of -mm and -ml may be given");
if (TARGET_S && option_mtiny_specified)
error ("only one of -ms and -mtiny= may be given");
if (TARGET_M && option_mtiny_specified)
error ("only one of -mm and -mtiny= may be given");
if (TARGET_OPT_CLIP && ! TARGET_OPT_MINMAX)
warning (0, "-mclip currently has no effect without -mminmax");
if (mep_const_section)
{
if (strcmp (mep_const_section, "tiny") != 0
&& strcmp (mep_const_section, "near") != 0
&& strcmp (mep_const_section, "far") != 0)
error ("-mc= must be -mc=tiny, -mc=near, or -mc=far");
}
if (TARGET_S)
mep_tiny_cutoff = 65536;
if (TARGET_M)
mep_tiny_cutoff = 0;
if (TARGET_L && ! option_mtiny_specified)
mep_tiny_cutoff = 0;
if (TARGET_64BIT_CR_REGS)
flag_split_wide_types = 0;
init_machine_status = mep_init_machine_status;
mep_init_intrinsics ();
}
/* Pattern Support - constraints, predicates, expanders. */
/* MEP has very few instructions that can refer to the span of
addresses used by symbols, so it's common to check for them. */
static bool
symbol_p (rtx x)
{
int c = GET_CODE (x);
return (c == CONST_INT
|| c == CONST
|| c == SYMBOL_REF);
}
static bool
symbolref_p (rtx x)
{
int c;
if (GET_CODE (x) != MEM)
return false;
c = GET_CODE (XEXP (x, 0));
return (c == CONST_INT
|| c == CONST
|| c == SYMBOL_REF);
}
/* static const char *reg_class_names[] = REG_CLASS_NAMES; */
#define GEN_REG(R, STRICT) \
(GR_REGNO_P (R) \
|| (!STRICT \
&& ((R) == ARG_POINTER_REGNUM \
|| (R) >= FIRST_PSEUDO_REGISTER)))
static char pattern[12], *patternp;
static GTY(()) rtx patternr[12];
#define RTX_IS(x) (strcmp (pattern, x) == 0)
static void
encode_pattern_1 (rtx x)
{
int i;
if (patternp == pattern + sizeof (pattern) - 2)
{
patternp[-1] = '?';
return;
}
patternr[patternp-pattern] = x;
switch (GET_CODE (x))
{
case REG:
*patternp++ = 'r';
break;
case MEM:
*patternp++ = 'm';
case CONST:
encode_pattern_1 (XEXP(x, 0));
break;
case PLUS:
*patternp++ = '+';
encode_pattern_1 (XEXP(x, 0));
encode_pattern_1 (XEXP(x, 1));
break;
case LO_SUM:
*patternp++ = 'L';
encode_pattern_1 (XEXP(x, 0));
encode_pattern_1 (XEXP(x, 1));
break;
case HIGH:
*patternp++ = 'H';
encode_pattern_1 (XEXP(x, 0));
break;
case SYMBOL_REF:
*patternp++ = 's';
break;
case LABEL_REF:
*patternp++ = 'l';
break;
case CONST_INT:
case CONST_DOUBLE:
*patternp++ = 'i';
break;
case UNSPEC:
*patternp++ = 'u';
*patternp++ = '0' + XCINT(x, 1, UNSPEC);
for (i=0; i<XVECLEN (x, 0); i++)
encode_pattern_1 (XVECEXP (x, 0, i));
break;
case USE:
*patternp++ = 'U';
break;
default:
*patternp++ = '?';
#if 0
fprintf (stderr, "can't encode pattern %s\n", GET_RTX_NAME(GET_CODE(x)));
debug_rtx (x);
gcc_unreachable ();
#endif
break;
}
}
static void
encode_pattern (rtx x)
{
patternp = pattern;
encode_pattern_1 (x);
*patternp = 0;
}
int
mep_section_tag (rtx x)
{
const char *name;
while (1)
{
switch (GET_CODE (x))
{
case MEM:
case CONST:
x = XEXP (x, 0);
break;
case UNSPEC:
x = XVECEXP (x, 0, 0);
break;
case PLUS:
if (GET_CODE (XEXP (x, 1)) != CONST_INT)
return 0;
x = XEXP (x, 0);
break;
default:
goto done;
}
}
done:
if (GET_CODE (x) != SYMBOL_REF)
return 0;
name = XSTR (x, 0);
if (name[0] == '@' && name[2] == '.')
{
if (name[1] == 'i' || name[1] == 'I')
{
if (name[1] == 'I')
return 'f'; /* near */
return 'n'; /* far */
}
return name[1];
}
return 0;
}
int
mep_regno_reg_class (int regno)
{
switch (regno)
{
case SP_REGNO: return SP_REGS;
case TP_REGNO: return TP_REGS;
case GP_REGNO: return GP_REGS;
case 0: return R0_REGS;
case HI_REGNO: return HI_REGS;
case LO_REGNO: return LO_REGS;
case ARG_POINTER_REGNUM: return GENERAL_REGS;
}
if (GR_REGNO_P (regno))
return regno < FIRST_GR_REGNO + 8 ? TPREL_REGS : GENERAL_REGS;
if (CONTROL_REGNO_P (regno))
return CONTROL_REGS;
if (CR_REGNO_P (regno))
{
int i, j;
/* Search for the register amongst user-defined subclasses of
the coprocessor registers. */
for (i = USER0_REGS; i <= USER3_REGS; ++i)
{
if (! TEST_HARD_REG_BIT (reg_class_contents[i], regno))
continue;
for (j = 0; j < N_REG_CLASSES; ++j)
{
enum reg_class sub = reg_class_subclasses[i][j];
if (sub == LIM_REG_CLASSES)
return i;
if (TEST_HARD_REG_BIT (reg_class_contents[sub], regno))
break;
}
}
return LOADABLE_CR_REGNO_P (regno) ? LOADABLE_CR_REGS : CR_REGS;
}
if (CCR_REGNO_P (regno))
return CCR_REGS;
gcc_assert (regno >= FIRST_SHADOW_REGISTER && regno <= LAST_SHADOW_REGISTER);
return NO_REGS;
}
#if 0
int
mep_reg_class_from_constraint (int c, const char *str)
{
switch (c)
{
case 'a':
return SP_REGS;
case 'b':
return TP_REGS;
case 'c':
return CONTROL_REGS;
case 'd':
return HILO_REGS;
case 'e':
{
switch (str[1])
{
case 'm':
return LOADABLE_CR_REGS;
case 'x':
return mep_have_copro_copro_moves_p ? CR_REGS : NO_REGS;
case 'r':
return mep_have_core_copro_moves_p ? CR_REGS : NO_REGS;
default:
return NO_REGS;
}
}
case 'h':
return HI_REGS;
case 'j':
return RPC_REGS;
case 'l':
return LO_REGS;
case 't':
return TPREL_REGS;
case 'v':
return GP_REGS;
case 'x':
return CR_REGS;
case 'y':
return CCR_REGS;
case 'z':
return R0_REGS;
case 'A':
case 'B':
case 'C':
case 'D':
{
enum reg_class which = c - 'A' + USER0_REGS;
return (reg_class_size[which] > 0 ? which : NO_REGS);
}
default:
return NO_REGS;
}
}
bool
mep_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
{
switch (c)
{
case 'I': return value >= -32768 && value < 32768;
case 'J': return value >= 0 && value < 65536;
case 'K': return value >= 0 && value < 0x01000000;
case 'L': return value >= -32 && value < 32;
case 'M': return value >= 0 && value < 32;
case 'N': return value >= 0 && value < 16;
case 'O':
if (value & 0xffff)
return false;
return value >= -2147483647-1 && value <= 2147483647;
default:
gcc_unreachable ();
}
}
bool
mep_extra_constraint (rtx value, int c)
{
encode_pattern (value);
switch (c)
{
case 'R':
/* For near symbols, like what call uses. */
if (GET_CODE (value) == REG)
return 0;
return mep_call_address_operand (value, GET_MODE (value));
case 'S':
/* For signed 8-bit immediates. */
return (GET_CODE (value) == CONST_INT
&& INTVAL (value) >= -128
&& INTVAL (value) <= 127);
case 'T':
/* For tp/gp relative symbol values. */
return (RTX_IS ("u3s") || RTX_IS ("u2s")
|| RTX_IS ("+u3si") || RTX_IS ("+u2si"));
case 'U':
/* Non-absolute memories. */
return GET_CODE (value) == MEM && ! CONSTANT_P (XEXP (value, 0));
case 'W':
/* %hi(sym) */
return RTX_IS ("Hs");
case 'Y':
/* Register indirect. */
return RTX_IS ("mr");
case 'Z':
return mep_section_tag (value) == 'c' && RTX_IS ("ms");
}
return false;
}
#endif
#undef PASS
#undef FAIL
static bool
const_in_range (rtx x, int minv, int maxv)
{
return (GET_CODE (x) == CONST_INT
&& INTVAL (x) >= minv
&& INTVAL (x) <= maxv);
}
/* Given three integer registers DEST, SRC1 and SRC2, return an rtx X
such that "mulr DEST,X" will calculate DEST = SRC1 * SRC2. If a move
is needed, emit it before INSN if INSN is nonnull, otherwise emit it
at the end of the insn stream. */
rtx
mep_mulr_source (rtx insn, rtx dest, rtx src1, rtx src2)
{
if (rtx_equal_p (dest, src1))
return src2;
else if (rtx_equal_p (dest, src2))
return src1;
else
{
if (insn == 0)
emit_insn (gen_movsi (copy_rtx (dest), src1));
else
emit_insn_before (gen_movsi (copy_rtx (dest), src1), insn);
return src2;
}
}
/* Replace INSN's pattern with PATTERN, a multiplication PARALLEL.
Change the last element of PATTERN from (clobber (scratch:SI))
to (clobber (reg:SI HI_REGNO)). */
static void
mep_rewrite_mult (rtx insn, rtx pattern)
{
rtx hi_clobber;
hi_clobber = XVECEXP (pattern, 0, XVECLEN (pattern, 0) - 1);
XEXP (hi_clobber, 0) = gen_rtx_REG (SImode, HI_REGNO);
PATTERN (insn) = pattern;
INSN_CODE (insn) = -1;
}
/* Subroutine of mep_reuse_lo_p. Rewrite instruction INSN so that it
calculates SRC1 * SRC2 and stores the result in $lo. Also make it
store the result in DEST if nonnull. */
static void
mep_rewrite_mulsi3 (rtx insn, rtx dest, rtx src1, rtx src2)
{
rtx lo, pattern;
lo = gen_rtx_REG (SImode, LO_REGNO);
if (dest)
pattern = gen_mulsi3r (lo, dest, copy_rtx (dest),
mep_mulr_source (insn, dest, src1, src2));
else
pattern = gen_mulsi3_lo (lo, src1, src2);
mep_rewrite_mult (insn, pattern);
}
/* Like mep_rewrite_mulsi3, but calculate SRC1 * SRC2 + SRC3. First copy
SRC3 into $lo, then use either madd or maddr. The move into $lo will
be deleted by a peephole2 if SRC3 is already in $lo. */
static void
mep_rewrite_maddsi3 (rtx insn, rtx dest, rtx src1, rtx src2, rtx src3)
{
rtx lo, pattern;
lo = gen_rtx_REG (SImode, LO_REGNO);
emit_insn_before (gen_movsi (copy_rtx (lo), src3), insn);
if (dest)
pattern = gen_maddsi3r (lo, dest, copy_rtx (dest),
mep_mulr_source (insn, dest, src1, src2),
copy_rtx (lo));
else
pattern = gen_maddsi3_lo (lo, src1, src2, copy_rtx (lo));
mep_rewrite_mult (insn, pattern);
}
/* Return true if $lo has the same value as integer register GPR when
instruction INSN is reached. If necessary, rewrite the instruction
that sets $lo so that it uses a proper SET, not a CLOBBER. LO is an
rtx for (reg:SI LO_REGNO).
This function is intended to be used by the peephole2 pass. Since
that pass goes from the end of a basic block to the beginning, and
propagates liveness information on the way, there is no need to
update register notes here.
If GPR_DEAD_P is true on entry, and this function returns true,
then the caller will replace _every_ use of GPR in and after INSN
with LO. This means that if the instruction that sets $lo is a
mulr- or maddr-type instruction, we can rewrite it to use mul or
madd instead. In combination with the copy progagation pass,
this allows us to replace sequences like:
mov GPR,R1
mulr GPR,R2
with:
mul R1,R2
if GPR is no longer used. */
static bool
mep_reuse_lo_p_1 (rtx lo, rtx gpr, rtx insn, bool gpr_dead_p)
{
do
{
insn = PREV_INSN (insn);
if (INSN_P (insn))
switch (recog_memoized (insn))
{
case CODE_FOR_mulsi3_1:
extract_insn (insn);
if (rtx_equal_p (recog_data.operand[0], gpr))
{
mep_rewrite_mulsi3 (insn,
gpr_dead_p ? NULL : recog_data.operand[0],
recog_data.operand[1],
recog_data.operand[2]);
return true;
}
return false;
case CODE_FOR_maddsi3:
extract_insn (insn);
if (rtx_equal_p (recog_data.operand[0], gpr))
{
mep_rewrite_maddsi3 (insn,
gpr_dead_p ? NULL : recog_data.operand[0],
recog_data.operand[1],
recog_data.operand[2],
recog_data.operand[3]);
return true;
}
return false;
case CODE_FOR_mulsi3r:
case CODE_FOR_maddsi3r:
extract_insn (insn);
return rtx_equal_p (recog_data.operand[1], gpr);
default:
if (reg_set_p (lo, insn)
|| reg_set_p (gpr, insn)
|| volatile_insn_p (PATTERN (insn)))
return false;
if (gpr_dead_p && reg_referenced_p (gpr, PATTERN (insn)))
gpr_dead_p = false;
break;
}
}
while (!NOTE_INSN_BASIC_BLOCK_P (insn));
return false;
}
/* A wrapper around mep_reuse_lo_p_1 that preserves recog_data. */
bool
mep_reuse_lo_p (rtx lo, rtx gpr, rtx insn, bool gpr_dead_p)
{
bool result = mep_reuse_lo_p_1 (lo, gpr, insn, gpr_dead_p);
extract_insn (insn);
return result;
}
/* Return true if SET can be turned into a post-modify load or store
that adds OFFSET to GPR. In other words, return true if SET can be
changed into:
(parallel [SET (set GPR (plus:SI GPR OFFSET))]).
It's OK to change SET to an equivalent operation in order to
make it match. */
static bool
mep_use_post_modify_for_set_p (rtx set, rtx gpr, rtx offset)
{
rtx *reg, *mem;
unsigned int reg_bytes, mem_bytes;
enum machine_mode reg_mode, mem_mode;
/* Only simple SETs can be converted. */
if (GET_CODE (set) != SET)
return false;
/* Point REG to what we hope will be the register side of the set and
MEM to what we hope will be the memory side. */
if (GET_CODE (SET_DEST (set)) == MEM)
{
mem = &SET_DEST (set);
reg = &SET_SRC (set);
}
else
{
reg = &SET_DEST (set);
mem = &SET_SRC (set);
if (GET_CODE (*mem) == SIGN_EXTEND)
mem = &XEXP (*mem, 0);
}
/* Check that *REG is a suitable coprocessor register. */
if (GET_CODE (*reg) != REG || !LOADABLE_CR_REGNO_P (REGNO (*reg)))
return false;
/* Check that *MEM is a suitable memory reference. */
if (GET_CODE (*mem) != MEM || !rtx_equal_p (XEXP (*mem, 0), gpr))
return false;
/* Get the number of bytes in each operand. */
mem_bytes = GET_MODE_SIZE (GET_MODE (*mem));
reg_bytes = GET_MODE_SIZE (GET_MODE (*reg));
/* Check that OFFSET is suitably aligned. */
if (INTVAL (offset) & (mem_bytes - 1))
return false;
/* Convert *MEM to a normal integer mode. */
mem_mode = mode_for_size (mem_bytes * BITS_PER_UNIT, MODE_INT, 0);
*mem = change_address (*mem, mem_mode, NULL);
/* Adjust *REG as well. */
*reg = shallow_copy_rtx (*reg);
if (reg == &SET_DEST (set) && reg_bytes < UNITS_PER_WORD)
{
/* SET is a subword load. Convert it to an explicit extension. */
PUT_MODE (*reg, SImode);
*mem = gen_rtx_SIGN_EXTEND (SImode, *mem);
}
else
{
reg_mode = mode_for_size (reg_bytes * BITS_PER_UNIT, MODE_INT, 0);
PUT_MODE (*reg, reg_mode);
}
return true;
}
/* Return the effect of frame-related instruction INSN. */
static rtx
mep_frame_expr (rtx insn)
{
rtx note, expr;
note = find_reg_note (insn, REG_FRAME_RELATED_EXPR, 0);
expr = (note != 0 ? XEXP (note, 0) : copy_rtx (PATTERN (insn)));
RTX_FRAME_RELATED_P (expr) = 1;
return expr;
}
/* Merge instructions INSN1 and INSN2 using a PARALLEL. Store the
new pattern in INSN1; INSN2 will be deleted by the caller. */
static void
mep_make_parallel (rtx insn1, rtx insn2)
{
rtx expr;
if (RTX_FRAME_RELATED_P (insn2))
{
expr = mep_frame_expr (insn2);
if (RTX_FRAME_RELATED_P (insn1))
expr = gen_rtx_SEQUENCE (VOIDmode,
gen_rtvec (2, mep_frame_expr (insn1), expr));
set_unique_reg_note (insn1, REG_FRAME_RELATED_EXPR, expr);
RTX_FRAME_RELATED_P (insn1) = 1;
}
PATTERN (insn1) = gen_rtx_PARALLEL (VOIDmode,
gen_rtvec (2, PATTERN (insn1),
PATTERN (insn2)));
INSN_CODE (insn1) = -1;
}
/* SET_INSN is an instruction that adds OFFSET to REG. Go back through
the basic block to see if any previous load or store instruction can
be persuaded to do SET_INSN as a side-effect. Return true if so. */
static bool
mep_use_post_modify_p_1 (rtx set_insn, rtx reg, rtx offset)
{
rtx insn;
insn = set_insn;
do
{
insn = PREV_INSN (insn);
if (INSN_P (insn))
{
if (mep_use_post_modify_for_set_p (PATTERN (insn), reg, offset))
{
mep_make_parallel (insn, set_insn);
return true;
}
if (reg_set_p (reg, insn)
|| reg_referenced_p (reg, PATTERN (insn))
|| volatile_insn_p (PATTERN (insn)))
return false;
}
}
while (!NOTE_INSN_BASIC_BLOCK_P (insn));
return false;
}
/* A wrapper around mep_use_post_modify_p_1 that preserves recog_data. */
bool
mep_use_post_modify_p (rtx insn, rtx reg, rtx offset)
{
bool result = mep_use_post_modify_p_1 (insn, reg, offset);
extract_insn (insn);
return result;
}
bool
mep_allow_clip (rtx ux, rtx lx, int s)
{
HOST_WIDE_INT u = INTVAL (ux);
HOST_WIDE_INT l = INTVAL (lx);
int i;
if (!TARGET_OPT_CLIP)
return false;
if (s)
{
for (i = 0; i < 30; i ++)
if ((u == ((HOST_WIDE_INT) 1 << i) - 1)
&& (l == - ((HOST_WIDE_INT) 1 << i)))
return true;
}
else
{
if (l != 0)
return false;
for (i = 0; i < 30; i ++)
if ((u == ((HOST_WIDE_INT) 1 << i) - 1))
return true;
}
return false;
}
bool
mep_bit_position_p (rtx x, bool looking_for)
{
if (GET_CODE (x) != CONST_INT)
return false;
switch ((int) INTVAL(x) & 0xff)
{
case 0x01: case 0x02: case 0x04: case 0x08:
case 0x10: case 0x20: case 0x40: case 0x80:
return looking_for;
case 0xfe: case 0xfd: case 0xfb: case 0xf7:
case 0xef: case 0xdf: case 0xbf: case 0x7f:
return !looking_for;
}
return false;
}
static bool
move_needs_splitting (rtx dest, rtx src,
enum machine_mode mode ATTRIBUTE_UNUSED)
{
int s = mep_section_tag (src);
while (1)
{
if (GET_CODE (src) == CONST
|| GET_CODE (src) == MEM)
src = XEXP (src, 0);
else if (GET_CODE (src) == SYMBOL_REF
|| GET_CODE (src) == LABEL_REF
|| GET_CODE (src) == PLUS)
break;
else
return false;
}
if (s == 'f'
|| (GET_CODE (src) == PLUS
&& GET_CODE (XEXP (src, 1)) == CONST_INT
&& (INTVAL (XEXP (src, 1)) < -65536
|| INTVAL (XEXP (src, 1)) > 0xffffff))
|| (GET_CODE (dest) == REG
&& REGNO (dest) > 7 && REGNO (dest) < FIRST_PSEUDO_REGISTER))
return true;
return false;
}
bool
mep_split_mov (rtx *operands, int symbolic)
{
if (symbolic)
{
if (move_needs_splitting (operands[0], operands[1], SImode))
return true;
return false;
}
if (GET_CODE (operands[1]) != CONST_INT)
return false;
if (constraint_satisfied_p (operands[1], CONSTRAINT_I)
|| constraint_satisfied_p (operands[1], CONSTRAINT_J)
|| constraint_satisfied_p (operands[1], CONSTRAINT_O))
return false;
if (((!reload_completed && !reload_in_progress)
|| (REG_P (operands[0]) && REGNO (operands[0]) < 8))
&& constraint_satisfied_p (operands[1], CONSTRAINT_K))
return false;
return true;
}
/* Irritatingly, the "jsrv" insn *toggles* PSW.OM rather than set
it to one specific value. So the insn chosen depends on whether
the source and destination modes match. */
bool
mep_vliw_mode_match (rtx tgt)
{
bool src_vliw = mep_vliw_function_p (cfun->decl);
bool tgt_vliw = INTVAL (tgt);
return src_vliw == tgt_vliw;
}
/* Like the above, but also test for near/far mismatches. */
bool
mep_vliw_jmp_match (rtx tgt)
{
bool src_vliw = mep_vliw_function_p (cfun->decl);
bool tgt_vliw = INTVAL (tgt);
if (mep_section_tag (DECL_RTL (cfun->decl)) == 'f')
return false;
return src_vliw == tgt_vliw;
}
bool
mep_multi_slot (rtx x)
{
return get_attr_slot (x) == SLOT_MULTI;
}
bool
mep_legitimate_constant_p (rtx x)
{
/* We can't convert symbol values to gp- or tp-rel values after
reload, as reload might have used $gp or $tp for other
purposes. */
if (GET_CODE (x) == SYMBOL_REF && (reload_in_progress || reload_completed))
{
char e = mep_section_tag (x);
return (e != 't' && e != 'b');
}
return 1;
}
/* Be careful not to use macros that need to be compiled one way for
strict, and another way for not-strict, like REG_OK_FOR_BASE_P. */
bool
mep_legitimate_address (enum machine_mode mode, rtx x, int strict)
{
int the_tag;
#define DEBUG_LEGIT 0
#if DEBUG_LEGIT
fprintf (stderr, "legit: mode %s strict %d ", mode_name[mode], strict);
debug_rtx (x);
#endif
if (GET_CODE (x) == LO_SUM
&& GET_CODE (XEXP (x, 0)) == REG
&& GEN_REG (REGNO (XEXP (x, 0)), strict)
&& CONSTANT_P (XEXP (x, 1)))
{
if (GET_MODE_SIZE (mode) > 4)
{
/* We will end up splitting this, and lo_sums are not
offsettable for us. */
#if DEBUG_LEGIT
fprintf(stderr, " - nope, %%lo(sym)[reg] not splittable\n");
#endif
return false;
}
#if DEBUG_LEGIT
fprintf (stderr, " - yup, %%lo(sym)[reg]\n");
#endif
return true;
}
if (GET_CODE (x) == REG
&& GEN_REG (REGNO (x), strict))
{
#if DEBUG_LEGIT
fprintf (stderr, " - yup, [reg]\n");
#endif
return true;
}
if (GET_CODE (x) == PLUS
&& GET_CODE (XEXP (x, 0)) == REG
&& GEN_REG (REGNO (XEXP (x, 0)), strict)
&& const_in_range (XEXP (x, 1), -32768, 32767))
{
#if DEBUG_LEGIT
fprintf (stderr, " - yup, [reg+const]\n");
#endif
return true;
}
if (GET_CODE (x) == PLUS
&& GET_CODE (XEXP (x, 0)) == REG
&& GEN_REG (REGNO (XEXP (x, 0)), strict)
&& GET_CODE (XEXP (x, 1)) == CONST
&& (GET_CODE (XEXP (XEXP (x, 1), 0)) == UNSPEC
|| (GET_CODE (XEXP (XEXP (x, 1), 0)) == PLUS
&& GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == UNSPEC
&& GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == CONST_INT)))
{
#if DEBUG_LEGIT
fprintf (stderr, " - yup, [reg+unspec]\n");
#endif
return true;
}
the_tag = mep_section_tag (x);
if (the_tag == 'f')
{
#if DEBUG_LEGIT
fprintf (stderr, " - nope, [far]\n");
#endif
return false;
}
if (mode == VOIDmode
&& GET_CODE (x) == SYMBOL_REF)
{
#if DEBUG_LEGIT
fprintf (stderr, " - yup, call [symbol]\n");
#endif
return true;
}
if ((mode == SImode || mode == SFmode)
&& CONSTANT_P (x)
&& LEGITIMATE_CONSTANT_P (x)
&& the_tag != 't' && the_tag != 'b')
{
if (GET_CODE (x) != CONST_INT
|| (INTVAL (x) <= 0xfffff
&& INTVAL (x) >= 0
&& (INTVAL (x) % 4) == 0))
{
#if DEBUG_LEGIT
fprintf (stderr, " - yup, [const]\n");
#endif
return true;
}
}
#if DEBUG_LEGIT
fprintf (stderr, " - nope.\n");
#endif
return false;
}
int
mep_legitimize_reload_address (rtx *x, enum machine_mode mode, int opnum,
enum reload_type type,
int ind_levels ATTRIBUTE_UNUSED)
{
if (GET_CODE (*x) == PLUS
&& GET_CODE (XEXP (*x, 0)) == MEM
&& GET_CODE (XEXP (*x, 1)) == REG)
{
/* GCC will by default copy the MEM into a REG, which results in
an invalid address. For us, the best thing to do is move the
whole expression to a REG. */
push_reload (*x, NULL_RTX, x, NULL,
GENERAL_REGS, mode, VOIDmode,
0, 0, opnum, type);
return 1;
}
if (GET_CODE (*x) == PLUS
&& GET_CODE (XEXP (*x, 0)) == SYMBOL_REF
&& GET_CODE (XEXP (*x, 1)) == CONST_INT)
{
char e = mep_section_tag (XEXP (*x, 0));
if (e != 't' && e != 'b')
{
/* GCC thinks that (sym+const) is a valid address. Well,
sometimes it is, this time it isn't. The best thing to
do is reload the symbol to a register, since reg+int
tends to work, and we can't just add the symbol and
constant anyway. */
push_reload (XEXP (*x, 0), NULL_RTX, &(XEXP(*x, 0)), NULL,
GENERAL_REGS, mode, VOIDmode,
0, 0, opnum, type);
return 1;
}
}
return 0;
}
int
mep_core_address_length (rtx insn, int opn)
{
rtx set = single_set (insn);
rtx mem = XEXP (set, opn);
rtx other = XEXP (set, 1-opn);
rtx addr = XEXP (mem, 0);
if (register_operand (addr, Pmode))
return 2;
if (GET_CODE (addr) == PLUS)
{
rtx addend = XEXP (addr, 1);
gcc_assert (REG_P (XEXP (addr, 0)));
switch (REGNO (XEXP (addr, 0)))
{
case STACK_POINTER_REGNUM:
if (GET_MODE_SIZE (GET_MODE (mem)) == 4
&& mep_imm7a4_operand (addend, VOIDmode))
return 2;
break;
case 13: /* TP */
gcc_assert (REG_P (other));
if (REGNO (other) >= 8)
break;
if (GET_CODE (addend) == CONST
&& GET_CODE (XEXP (addend, 0)) == UNSPEC
&& XINT (XEXP (addend, 0), 1) == UNS_TPREL)
return 2;
if (GET_CODE (addend) == CONST_INT
&& INTVAL (addend) >= 0
&& INTVAL (addend) <= 127
&& INTVAL (addend) % GET_MODE_SIZE (GET_MODE (mem)) == 0)
return 2;
break;
}
}
return 4;
}
int
mep_cop_address_length (rtx insn, int opn)
{
rtx set = single_set (insn);
rtx mem = XEXP (set, opn);
rtx addr = XEXP (mem, 0);
if (GET_CODE (mem) != MEM)
return 2;
if (register_operand (addr, Pmode))
return 2;
if (GET_CODE (addr) == POST_INC)
return 2;
return 4;
}
#define DEBUG_EXPAND_MOV 0
bool
mep_expand_mov (rtx *operands, enum machine_mode mode)
{
int i, t;
int tag[2];
rtx tpsym, tpoffs;
int post_reload = 0;
tag[0] = mep_section_tag (operands[0]);
tag[1] = mep_section_tag (operands[1]);
if (!reload_in_progress
&& !reload_completed
&& GET_CODE (operands[0]) != REG
&& GET_CODE (operands[0]) != SUBREG
&& GET_CODE (operands[1]) != REG
&& GET_CODE (operands[1]) != SUBREG)
operands[1] = copy_to_mode_reg (mode, operands[1]);
#if DEBUG_EXPAND_MOV
fprintf(stderr, "expand move %s %d\n", mode_name[mode],
reload_in_progress || reload_completed);
debug_rtx (operands[0]);
debug_rtx (operands[1]);
#endif
if (mode == DImode || mode == DFmode)
return false;
if (reload_in_progress || reload_completed)
{
rtx r;
if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == TP_REGNO)
cfun->machine->reload_changes_tp = true;
if (tag[0] == 't' || tag[1] == 't')
{
r = has_hard_reg_initial_val (Pmode, GP_REGNO);
if (!r || GET_CODE (r) != REG || REGNO (r) != GP_REGNO)
post_reload = 1;
}
if (tag[0] == 'b' || tag[1] == 'b')
{
r = has_hard_reg_initial_val (Pmode, TP_REGNO);
if (!r || GET_CODE (r) != REG || REGNO (r) != TP_REGNO)
post_reload = 1;
}
if (cfun->machine->reload_changes_tp == true)
post_reload = 1;
}
if (!post_reload)
{
rtx n;
if (symbol_p (operands[1]))
{
t = mep_section_tag (operands[1]);
if (t == 'b' || t == 't')
{
if (GET_CODE (operands[1]) == SYMBOL_REF)
{
tpsym = operands[1];
n = gen_rtx_UNSPEC (mode,
gen_rtvec (1, operands[1]),
t == 'b' ? UNS_TPREL : UNS_GPREL);
n = gen_rtx_CONST (mode, n);
}
else if (GET_CODE (operands[1]) == CONST
&& GET_CODE (XEXP (operands[1], 0)) == PLUS
&& GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF
&& GET_CODE (XEXP (XEXP (operands[1], 0), 1)) == CONST_INT)
{
tpsym = XEXP (XEXP (operands[1], 0), 0);
tpoffs = XEXP (XEXP (operands[1], 0), 1);
n = gen_rtx_UNSPEC (mode,
gen_rtvec (1, tpsym),
t == 'b' ? UNS_TPREL : UNS_GPREL);
n = gen_rtx_PLUS (mode, n, tpoffs);
n = gen_rtx_CONST (mode, n);
}
else if (GET_CODE (operands[1]) == CONST
&& GET_CODE (XEXP (operands[1], 0)) == UNSPEC)
return false;
else
{
error ("unusual TP-relative address");
return false;
}
n = gen_rtx_PLUS (mode, (t == 'b' ? mep_tp_rtx ()
: mep_gp_rtx ()), n);
n = emit_insn (gen_rtx_SET (mode, operands[0], n));
#if DEBUG_EXPAND_MOV
fprintf(stderr, "mep_expand_mov emitting ");
debug_rtx(n);
#endif
return true;
}
}
for (i=0; i < 2; i++)
{
t = mep_section_tag (operands[i]);
if (GET_CODE (operands[i]) == MEM && (t == 'b' || t == 't'))
{
rtx sym, n, r;
int u;
sym = XEXP (operands[i], 0);
if (GET_CODE (sym) == CONST
&& GET_CODE (XEXP (sym, 0)) == UNSPEC)
sym = XVECEXP (XEXP (sym, 0), 0, 0);
if (t == 'b')
{
r = mep_tp_rtx ();
u = UNS_TPREL;
}
else
{
r = mep_gp_rtx ();
u = UNS_GPREL;
}
n = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, sym), u);
n = gen_rtx_CONST (Pmode, n);
n = gen_rtx_PLUS (Pmode, r, n);
operands[i] = replace_equiv_address (operands[i], n);
}
}
}
if ((GET_CODE (operands[1]) != REG
&& MEP_CONTROL_REG (operands[0]))
|| (GET_CODE (operands[0]) != REG
&& MEP_CONTROL_REG (operands[1])))
{
rtx temp;
#if DEBUG_EXPAND_MOV
fprintf (stderr, "cr-mem, forcing op1 to reg\n");
#endif
temp = gen_reg_rtx (mode);
emit_move_insn (temp, operands[1]);
operands[1] = temp;
}
if (symbolref_p (operands[0])
&& (mep_section_tag (XEXP (operands[0], 0)) == 'f'
|| (GET_MODE_SIZE (mode) != 4)))
{
rtx temp;
gcc_assert (!reload_in_progress && !reload_completed);
temp = force_reg (Pmode, XEXP (operands[0], 0));
operands[0] = replace_equiv_address (operands[0], temp);
emit_move_insn (operands[0], operands[1]);
return true;
}
if (!post_reload && (tag[1] == 't' || tag[1] == 'b'))
tag[1] = 0;
if (symbol_p (operands[1])
&& (tag[1] == 'f' || tag[1] == 't' || tag[1] == 'b'))
{
emit_insn (gen_movsi_topsym_s (operands[0], operands[1]));
emit_insn (gen_movsi_botsym_s (operands[0], operands[0], operands[1]));
return true;
}
if (symbolref_p (operands[1])
&& (tag[1] == 'f' || tag[1] == 't' || tag[1] == 'b'))
{
rtx temp;
if (reload_in_progress || reload_completed)
temp = operands[0];
else
temp = gen_reg_rtx (Pmode);
emit_insn (gen_movsi_topsym_s (temp, operands[1]));
emit_insn (gen_movsi_botsym_s (temp, temp, operands[1]));
emit_move_insn (operands[0], replace_equiv_address (operands[1], temp));
return true;
}
return false;
}
/* Cases where the pattern can't be made to use at all. */
bool
mep_mov_ok (rtx *operands, enum machine_mode mode ATTRIBUTE_UNUSED)
{
int i;
#define DEBUG_MOV_OK 0
#if DEBUG_MOV_OK
fprintf (stderr, "mep_mov_ok %s %c=%c\n", mode_name[mode], mep_section_tag (operands[0]),
mep_section_tag (operands[1]));
debug_rtx (operands[0]);
debug_rtx (operands[1]);
#endif
/* We want the movh patterns to get these. */
if (GET_CODE (operands[1]) == HIGH)
return false;
/* We can't store a register to a far variable without using a
scratch register to hold the address. Using far variables should
be split by mep_emit_mov anyway. */
if (mep_section_tag (operands[0]) == 'f'
|| mep_section_tag (operands[1]) == 'f')
{
#if DEBUG_MOV_OK
fprintf (stderr, " - no, f\n");
#endif
return false;
}
i = mep_section_tag (operands[1]);
if ((i == 'b' || i == 't') && !reload_completed && !reload_in_progress)
/* These are supposed to be generated with adds of the appropriate
register. During and after reload, however, we allow them to
be accessed as normal symbols because adding a dependency on
the base register now might cause problems. */
{
#if DEBUG_MOV_OK
fprintf (stderr, " - no, bt\n");
#endif
return false;
}
/* The only moves we can allow involve at least one general
register, so require it. */
for (i = 0; i < 2; i ++)
{
/* Allow subregs too, before reload. */
rtx x = operands[i];
if (GET_CODE (x) == SUBREG)
x = XEXP (x, 0);
if (GET_CODE (x) == REG
&& ! MEP_CONTROL_REG (x))
{
#if DEBUG_MOV_OK
fprintf (stderr, " - ok\n");
#endif
return true;
}
}
#if DEBUG_MOV_OK
fprintf (stderr, " - no, no gen reg\n");
#endif
return false;
}
#define DEBUG_SPLIT_WIDE_MOVE 0
void
mep_split_wide_move (rtx *operands, enum machine_mode mode)
{
int i;
#if DEBUG_SPLIT_WIDE_MOVE
fprintf (stderr, "\n\033[34mmep_split_wide_move\033[0m mode %s\n", mode_name[mode]);
debug_rtx (operands[0]);
debug_rtx (operands[1]);
#endif
for (i = 0; i <= 1; i++)
{
rtx op = operands[i], hi, lo;
switch (GET_CODE (op))
{
case REG:
{
unsigned int regno = REGNO (op);
if (TARGET_64BIT_CR_REGS && CR_REGNO_P (regno))
{
rtx i32;
lo = gen_rtx_REG (SImode, regno);
i32 = GEN_INT (32);
hi = gen_rtx_ZERO_EXTRACT (SImode,
gen_rtx_REG (DImode, regno),
i32, i32);
}
else
{
hi = gen_rtx_REG (SImode, regno + TARGET_LITTLE_ENDIAN);
lo = gen_rtx_REG (SImode, regno + TARGET_BIG_ENDIAN);
}
}
break;
case CONST_INT:
case CONST_DOUBLE:
case MEM:
hi = operand_subword (op, TARGET_LITTLE_ENDIAN, 0, mode);
lo = operand_subword (op, TARGET_BIG_ENDIAN, 0, mode);
break;
default:
gcc_unreachable ();
}
/* The high part of CR <- GPR moves must be done after the low part. */
operands [i + 4] = lo;
operands [i + 2] = hi;
}
if (reg_mentioned_p (operands[2], operands[5])
|| GET_CODE (operands[2]) == ZERO_EXTRACT
|| GET_CODE (operands[4]) == ZERO_EXTRACT)
{
rtx tmp;
/* Overlapping register pairs -- make sure we don't
early-clobber ourselves. */
tmp = operands[2];
operands[2] = operands[4];
operands[4] = tmp;
tmp = operands[3];
operands[3] = operands[5];
operands[5] = tmp;
}
#if DEBUG_SPLIT_WIDE_MOVE
fprintf(stderr, "\033[34m");
debug_rtx (operands[2]);
debug_rtx (operands[3]);
debug_rtx (operands[4]);
debug_rtx (operands[5]);
fprintf(stderr, "\033[0m");
#endif
}
/* Emit a setcc instruction in its entirity. */
static bool
mep_expand_setcc_1 (enum rtx_code code, rtx dest, rtx op1, rtx op2)
{
rtx tmp;
switch (code)
{
case GT:
case GTU:
tmp = op1, op1 = op2, op2 = tmp;
code = swap_condition (code);
/* FALLTHRU */
case LT:
case LTU:
op1 = force_reg (SImode, op1);
emit_insn (gen_rtx_SET (VOIDmode, dest,
gen_rtx_fmt_ee (code, SImode, op1, op2)));
return true;
case EQ:
if (op2 != const0_rtx)
op1 = expand_binop (SImode, sub_optab, op1, op2, NULL, 1, OPTAB_WIDEN);
mep_expand_setcc_1 (LTU, dest, op1, const1_rtx);
return true;
case NE:
/* Branchful sequence:
mov dest, 0 16-bit
beq op1, op2, Lover 16-bit (op2 < 16), 32-bit otherwise
mov dest, 1 16-bit
Branchless sequence:
add3 tmp, op1, -op2 32-bit (or mov + sub)
sltu3 tmp, tmp, 1 16-bit
xor3 dest, tmp, 1 32-bit
*/
if (optimize_size && op2 != const0_rtx)
return false;
if (op2 != const0_rtx)
op1 = expand_binop (SImode, sub_optab, op1, op2, NULL, 1, OPTAB_WIDEN);
op2 = gen_reg_rtx (SImode);
mep_expand_setcc_1 (LTU, op2, op1, const1_rtx);
emit_insn (gen_rtx_SET (VOIDmode, dest,
gen_rtx_XOR (SImode, op2, const1_rtx)));
return true;
case LE:
if (GET_CODE (op2) != CONST_INT
|| INTVAL (op2) == 0x7ffffff)
return false;
op2 = GEN_INT (INTVAL (op2) + 1);
return mep_expand_setcc_1 (LT, dest, op1, op2);
case LEU:
if (GET_CODE (op2) != CONST_INT
|| INTVAL (op2) == -1)
return false;
op2 = GEN_INT (trunc_int_for_mode (INTVAL (op2) + 1, SImode));
return mep_expand_setcc_1 (LTU, dest, op1, op2);
case GE:
if (GET_CODE (op2) != CONST_INT
|| INTVAL (op2) == trunc_int_for_mode (0x80000000, SImode))
return false;
op2 = GEN_INT (INTVAL (op2) - 1);
return mep_expand_setcc_1 (GT, dest, op1, op2);
case GEU:
if (GET_CODE (op2) != CONST_INT
|| op2 == const0_rtx)
return false;
op2 = GEN_INT (trunc_int_for_mode (INTVAL (op2) - 1, SImode));
return mep_expand_setcc_1 (GTU, dest, op1, op2);
default:
gcc_unreachable ();
}
}
bool
mep_expand_setcc (rtx *operands)
{
rtx dest = operands[0];
enum rtx_code code = GET_CODE (operands[1]);
rtx op0 = operands[2];
rtx op1 = operands[3];
return mep_expand_setcc_1 (code, dest, op0, op1);
}
rtx
mep_expand_cbranch (rtx *operands)
{
enum rtx_code code = GET_CODE (operands[0]);
rtx op0 = operands[1];
rtx op1 = operands[2];
rtx tmp;
restart:
switch (code)
{
case LT:
if (mep_imm4_operand (op1, SImode))
break;
tmp = gen_reg_rtx (SImode);
gcc_assert (mep_expand_setcc_1 (LT, tmp, op0, op1));
code = NE;
op0 = tmp;
op1 = const0_rtx;
break;
case GE:
if (mep_imm4_operand (op1, SImode))
break;
tmp = gen_reg_rtx (SImode);
gcc_assert (mep_expand_setcc_1 (LT, tmp, op0, op1));
code = EQ;
op0 = tmp;
op1 = const0_rtx;
break;
case EQ:
case NE:
if (! mep_reg_or_imm4_operand (op1, SImode))
op1 = force_reg (SImode, op1);
break;
case LE:
case GT:
if (GET_CODE (op1) == CONST_INT
&& INTVAL (op1) != 0x7fffffff)
{
op1 = GEN_INT (INTVAL (op1) + 1);
code = (code == LE ? LT : GE);
goto restart;
}
tmp = gen_reg_rtx (SImode);
gcc_assert (mep_expand_setcc_1 (LT, tmp, op1, op0));
code = (code == LE ? EQ : NE);
op0 = tmp;
op1 = const0_rtx;
break;
case LTU:
if (op1 == const1_rtx)
{
code = EQ;
op1 = const0_rtx;
break;
}
tmp = gen_reg_rtx (SImode);
gcc_assert (mep_expand_setcc_1 (LTU, tmp, op0, op1));
code = NE;
op0 = tmp;
op1 = const0_rtx;
break;
case LEU:
tmp = gen_reg_rtx (SImode);
if (mep_expand_setcc_1 (LEU, tmp, op0, op1))
code = NE;
else if (mep_expand_setcc_1 (LTU, tmp, op1, op0))
code = EQ;
else
gcc_unreachable ();
op0 = tmp;
op1 = const0_rtx;
break;
case GTU:
tmp = gen_reg_rtx (SImode);
gcc_assert (mep_expand_setcc_1 (GTU, tmp, op0, op1)
|| mep_expand_setcc_1 (LTU, tmp, op1, op0));
code = NE;
op0 = tmp;
op1 = const0_rtx;
break;
case GEU:
tmp = gen_reg_rtx (SImode);
if (mep_expand_setcc_1 (GEU, tmp, op0, op1))
code = NE;
else if (mep_expand_setcc_1 (LTU, tmp, op0, op1))
code = EQ;
else
gcc_unreachable ();
op0 = tmp;
op1 = const0_rtx;
break;
default:
gcc_unreachable ();
}
return gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
}
const char *
mep_emit_cbranch (rtx *operands, int ne)
{
if (GET_CODE (operands[1]) == REG)
return ne ? "bne\t%0, %1, %l2" : "beq\t%0, %1, %l2";
else if (INTVAL (operands[1]) == 0 && !mep_vliw_function_p(cfun->decl))
return ne ? "bnez\t%0, %l2" : "beqz\t%0, %l2";
else
return ne ? "bnei\t%0, %1, %l2" : "beqi\t%0, %1, %l2";
}
void
mep_expand_call (rtx *operands, int returns_value)
{
rtx addr = operands[returns_value];
rtx tp = mep_tp_rtx ();
rtx gp = mep_gp_rtx ();
gcc_assert (GET_CODE (addr) == MEM);
addr = XEXP (addr, 0);
if (! mep_call_address_operand (addr, VOIDmode))
addr = force_reg (SImode, addr);
if (! operands[returns_value+2])
operands[returns_value+2] = const0_rtx;
if (returns_value)
emit_call_insn (gen_call_value_internal (operands[0], addr, operands[2],
operands[3], tp, gp));
else
emit_call_insn (gen_call_internal (addr, operands[1],
operands[2], tp, gp));
}
/* Aliasing Support. */
/* If X is a machine specific address (i.e. a symbol or label being
referenced as a displacement from the GOT implemented using an
UNSPEC), then return the base term. Otherwise return X. */
rtx
mep_find_base_term (rtx x)
{
rtx base, term;
int unspec;
if (GET_CODE (x) != PLUS)
return x;
base = XEXP (x, 0);
term = XEXP (x, 1);
if (has_hard_reg_initial_val(Pmode, TP_REGNO)
&& base == mep_tp_rtx ())
unspec = UNS_TPREL;
else if (has_hard_reg_initial_val(Pmode, GP_REGNO)
&& base == mep_gp_rtx ())
unspec = UNS_GPREL;
else
return x;
if (GET_CODE (term) != CONST)
return x;
term = XEXP (term, 0);
if (GET_CODE (term) != UNSPEC
|| XINT (term, 1) != unspec)
return x;
return XVECEXP (term, 0, 0);
}
/* Reload Support. */
/* Return true if the registers in CLASS cannot represent the change from
modes FROM to TO. */
bool
mep_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
enum reg_class regclass)
{
if (from == to)
return false;
/* 64-bit COP regs must remain 64-bit COP regs. */
if (TARGET_64BIT_CR_REGS
&& (regclass == CR_REGS
|| regclass == LOADABLE_CR_REGS)
&& (GET_MODE_SIZE (to) < 8
|| GET_MODE_SIZE (from) < 8))
return true;
return false;
}
#define MEP_NONGENERAL_CLASS(C) (!reg_class_subset_p (C, GENERAL_REGS))
static bool
mep_general_reg (rtx x)
{
while (GET_CODE (x) == SUBREG)
x = XEXP (x, 0);
return GET_CODE (x) == REG && GR_REGNO_P (REGNO (x));
}
static bool
mep_nongeneral_reg (rtx x)
{
while (GET_CODE (x) == SUBREG)
x = XEXP (x, 0);
return (GET_CODE (x) == REG
&& !GR_REGNO_P (REGNO (x)) && REGNO (x) < FIRST_PSEUDO_REGISTER);
}
static bool
mep_general_copro_reg (rtx x)
{
while (GET_CODE (x) == SUBREG)
x = XEXP (x, 0);
return (GET_CODE (x) == REG && CR_REGNO_P (REGNO (x)));
}
static bool
mep_nonregister (rtx x)
{
while (GET_CODE (x) == SUBREG)
x = XEXP (x, 0);
return (GET_CODE (x) != REG || REGNO (x) >= FIRST_PSEUDO_REGISTER);
}
#define DEBUG_RELOAD 0
/* Return the secondary reload class needed for moving value X to or
from a register in coprocessor register class CLASS. */
static enum reg_class
mep_secondary_copro_reload_class (enum reg_class rclass, rtx x)
{
if (mep_general_reg (x))
/* We can do the move directly if mep_have_core_copro_moves_p,
otherwise we need to go through memory. Either way, no secondary
register is needed. */
return NO_REGS;
if (mep_general_copro_reg (x))
{
/* We can do the move directly if mep_have_copro_copro_moves_p. */
if (mep_have_copro_copro_moves_p)
return NO_REGS;
/* Otherwise we can use a temporary if mep_have_core_copro_moves_p. */
if (mep_have_core_copro_moves_p)
return GENERAL_REGS;
/* Otherwise we need to do it through memory. No secondary
register is needed. */
return NO_REGS;
}
if (reg_class_subset_p (rclass, LOADABLE_CR_REGS)
&& constraint_satisfied_p (x, CONSTRAINT_U))
/* X is a memory value that we can access directly. */
return NO_REGS;
/* We have to move X into a GPR first and then copy it to
the coprocessor register. The move from the GPR to the
coprocessor might be done directly or through memory,
depending on mep_have_core_copro_moves_p. */
return GENERAL_REGS;
}
/* Copying X to register in RCLASS. */
int
mep_secondary_input_reload_class (enum reg_class rclass,
enum machine_mode mode ATTRIBUTE_UNUSED,
rtx x)
{
int rv = NO_REGS;
#if DEBUG_RELOAD
fprintf (stderr, "secondary input reload copy to %s %s from ", reg_class_names[rclass], mode_name[mode]);
debug_rtx (x);
#endif
if (reg_class_subset_p (rclass, CR_REGS))
rv = mep_secondary_copro_reload_class (rclass, x);
else if (MEP_NONGENERAL_CLASS (rclass)
&& (mep_nonregister (x) || mep_nongeneral_reg (x)))
rv = GENERAL_REGS;
#if DEBUG_RELOAD
fprintf (stderr, " - requires %s\n", reg_class_names[rv]);
#endif
return rv;
}
/* Copying register in RCLASS to X. */
int
mep_secondary_output_reload_class (enum reg_class rclass,
enum machine_mode mode ATTRIBUTE_UNUSED,
rtx x)
{
int rv = NO_REGS;
#if DEBUG_RELOAD
fprintf (stderr, "secondary output reload copy from %s %s to ", reg_class_names[rclass], mode_name[mode]);
debug_rtx (x);
#endif
if (reg_class_subset_p (rclass, CR_REGS))
rv = mep_secondary_copro_reload_class (rclass, x);
else if (MEP_NONGENERAL_CLASS (rclass)
&& (mep_nonregister (x) || mep_nongeneral_reg (x)))
rv = GENERAL_REGS;
#if DEBUG_RELOAD
fprintf (stderr, " - requires %s\n", reg_class_names[rv]);
#endif
return rv;
}
/* Implement SECONDARY_MEMORY_NEEDED. */
bool
mep_secondary_memory_needed (enum reg_class rclass1, enum reg_class rclass2,
enum machine_mode mode ATTRIBUTE_UNUSED)
{
if (!mep_have_core_copro_moves_p)
{
if (reg_classes_intersect_p (rclass1, CR_REGS)
&& reg_classes_intersect_p (rclass2, GENERAL_REGS))
return true;
if (reg_classes_intersect_p (rclass2, CR_REGS)
&& reg_classes_intersect_p (rclass1, GENERAL_REGS))
return true;
if (!mep_have_copro_copro_moves_p
&& reg_classes_intersect_p (rclass1, CR_REGS)
&& reg_classes_intersect_p (rclass2, CR_REGS))
return true;
}
return false;
}
void
mep_expand_reload (rtx *operands, enum machine_mode mode)
{
/* There are three cases for each direction:
register, farsym
control, farsym
control, nearsym */
int s0 = mep_section_tag (operands[0]) == 'f';
int s1 = mep_section_tag (operands[1]) == 'f';
int c0 = mep_nongeneral_reg (operands[0]);
int c1 = mep_nongeneral_reg (operands[1]);
int which = (s0 ? 20:0) + (c0 ? 10:0) + (s1 ? 2:0) + (c1 ? 1:0);
#if DEBUG_RELOAD
fprintf (stderr, "expand_reload %s\n", mode_name[mode]);
debug_rtx (operands[0]);
debug_rtx (operands[1]);
#endif
switch (which)
{
case 00: /* Don't know why this gets here. */
case 02: /* general = far */
emit_move_insn (operands[0], operands[1]);
return;
case 10: /* cr = mem */
case 11: /* cr = cr */
case 01: /* mem = cr */
case 12: /* cr = far */
emit_move_insn (operands[2], operands[1]);
emit_move_insn (operands[0], operands[2]);
return;
case 20: /* far = general */
emit_move_insn (operands[2], XEXP (operands[1], 0));
emit_move_insn (operands[0], gen_rtx_MEM (mode, operands[2]));
return;
case 21: /* far = cr */
case 22: /* far = far */
default:
fprintf (stderr, "unsupported expand reload case %02d for mode %s\n",
which, mode_name[mode]);
debug_rtx (operands[0]);
debug_rtx (operands[1]);
gcc_unreachable ();
}
}
/* Implement PREFERRED_RELOAD_CLASS. See whether X is a constant that
can be moved directly into registers 0 to 7, but not into the rest.
If so, and if the required class includes registers 0 to 7, restrict
it to those registers. */
enum reg_class
mep_preferred_reload_class (rtx x, enum reg_class rclass)
{
switch (GET_CODE (x))
{
case CONST_INT:
if (INTVAL (x) >= 0x10000
&& INTVAL (x) < 0x01000000
&& (INTVAL (x) & 0xffff) != 0
&& reg_class_subset_p (TPREL_REGS, rclass))
rclass = TPREL_REGS;
break;
case CONST:
case SYMBOL_REF:
case LABEL_REF:
if (mep_section_tag (x) != 'f'
&& reg_class_subset_p (TPREL_REGS, rclass))
rclass = TPREL_REGS;
break;
default:
break;
}
return rclass;
}
/* Implement REGISTER_MOVE_COST. Return 2 for direct single-register
moves, 4 for direct double-register moves, and 1000 for anything
that requires a temporary register or temporary stack slot. */
int
mep_register_move_cost (enum machine_mode mode, enum reg_class from, enum reg_class to)
{
if (mep_have_copro_copro_moves_p
&& reg_class_subset_p (from, CR_REGS)
&& reg_class_subset_p (to, CR_REGS))
{
if (TARGET_32BIT_CR_REGS && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
return 4;
return 2;
}
if (reg_class_subset_p (from, CR_REGS)
&& reg_class_subset_p (to, CR_REGS))
{
if (TARGET_32BIT_CR_REGS && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
return 8;
return 4;
}
if (reg_class_subset_p (from, CR_REGS)
|| reg_class_subset_p (to, CR_REGS))
{
if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
return 4;
return 2;
}
if (mep_secondary_memory_needed (from, to, mode))
return 1000;
if (MEP_NONGENERAL_CLASS (from) && MEP_NONGENERAL_CLASS (to))
return 1000;
if (GET_MODE_SIZE (mode) > 4)
return 4;
return 2;
}
/* Functions to save and restore machine-specific function data. */
static struct machine_function *
mep_init_machine_status (void)
{
return ggc_alloc_cleared_machine_function ();
}
static rtx
mep_allocate_initial_value (rtx reg)
{
int rss;
if (GET_CODE (reg) != REG)
return NULL_RTX;
if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
return NULL_RTX;
/* In interrupt functions, the "initial" values of $gp and $tp are
provided by the prologue. They are not necessarily the same as
the values that the caller was using. */
if (REGNO (reg) == TP_REGNO || REGNO (reg) == GP_REGNO)
if (mep_interrupt_p ())
return NULL_RTX;
if (! cfun->machine->reg_save_slot[REGNO(reg)])
{
cfun->machine->reg_save_size += 4;
cfun->machine->reg_save_slot[REGNO(reg)] = cfun->machine->reg_save_size;
}
rss = cfun->machine->reg_save_slot[REGNO(reg)];
return gen_rtx_MEM (SImode, plus_constant (arg_pointer_rtx, -rss));
}
rtx
mep_return_addr_rtx (int count)
{
if (count != 0)
return const0_rtx;
return get_hard_reg_initial_val (Pmode, LP_REGNO);
}
static rtx
mep_tp_rtx (void)
{
return get_hard_reg_initial_val (Pmode, TP_REGNO);
}
static rtx
mep_gp_rtx (void)
{
return get_hard_reg_initial_val (Pmode, GP_REGNO);
}
static bool
mep_interrupt_p (void)
{
if (cfun->machine->interrupt_handler == 0)
{
int interrupt_handler
= (lookup_attribute ("interrupt",
DECL_ATTRIBUTES (current_function_decl))
!= NULL_TREE);
cfun->machine->interrupt_handler = interrupt_handler ? 2 : 1;
}
return cfun->machine->interrupt_handler == 2;
}
static bool
mep_disinterrupt_p (void)
{
if (cfun->machine->disable_interrupts == 0)
{
int disable_interrupts
= (lookup_attribute ("disinterrupt",
DECL_ATTRIBUTES (current_function_decl))
!= NULL_TREE);
cfun->machine->disable_interrupts = disable_interrupts ? 2 : 1;
}
return cfun->machine->disable_interrupts == 2;
}
/* Frame/Epilog/Prolog Related. */
static bool
mep_reg_set_p (rtx reg, rtx insn)
{
/* Similar to reg_set_p in rtlanal.c, but we ignore calls */
if (INSN_P (insn))
{
if (FIND_REG_INC_NOTE (insn, reg))
return true;
insn = PATTERN (insn);
}
if (GET_CODE (insn) == SET
&& GET_CODE (XEXP (insn, 0)) == REG
&& GET_CODE (XEXP (insn, 1)) == REG
&& REGNO (XEXP (insn, 0)) == REGNO (XEXP (insn, 1)))
return false;
return set_of (reg, insn) != NULL_RTX;
}
#define MEP_SAVES_UNKNOWN 0
#define MEP_SAVES_YES 1
#define MEP_SAVES_MAYBE 2
#define MEP_SAVES_NO 3
static bool
mep_reg_set_in_function (int regno)
{
rtx reg, insn;
if (mep_interrupt_p () && df_regs_ever_live_p(regno))
return true;
if (regno == LP_REGNO && (profile_arc_flag > 0 || profile_flag > 0))
return true;
push_topmost_sequence ();
insn = get_insns ();
pop_topmost_sequence ();
if (!insn)
return false;
reg = gen_rtx_REG (SImode, regno);
for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
if (INSN_P (insn) && mep_reg_set_p (reg, insn))
return true;
return false;
}
static bool
mep_asm_without_operands_p (void)
{
if (cfun->machine->asms_without_operands == 0)
{
rtx insn;
push_topmost_sequence ();
insn = get_insns ();
pop_topmost_sequence ();
cfun->machine->asms_without_operands = 1;
while (insn)
{
if (INSN_P (insn)
&& GET_CODE (PATTERN (insn)) == ASM_INPUT)
{
cfun->machine->asms_without_operands = 2;
break;
}
insn = NEXT_INSN (insn);
}
}
return cfun->machine->asms_without_operands == 2;
}
/* Interrupt functions save/restore every call-preserved register, and
any call-used register it uses (or all if it calls any function,
since they may get clobbered there too). Here we check to see
which call-used registers need saving. */
#define IVC2_ISAVED_REG(r) (TARGET_IVC2 \
&& (r == FIRST_CCR_REGNO + 1 \
|| (r >= FIRST_CCR_REGNO + 8 && r <= FIRST_CCR_REGNO + 11) \
|| (r >= FIRST_CCR_REGNO + 16 && r <= FIRST_CCR_REGNO + 31)))
static bool
mep_interrupt_saved_reg (int r)
{
if (!mep_interrupt_p ())
return false;
if (r == REGSAVE_CONTROL_TEMP
|| (TARGET_64BIT_CR_REGS && TARGET_COP && r == REGSAVE_CONTROL_TEMP+1))
return true;
if (mep_asm_without_operands_p ()
&& (!fixed_regs[r]
|| (r == RPB_REGNO || r == RPE_REGNO || r == RPC_REGNO || r == LP_REGNO)
|| IVC2_ISAVED_REG (r)))
return true;
if (!current_function_is_leaf)
/* Function calls mean we need to save $lp. */
if (r == LP_REGNO || IVC2_ISAVED_REG (r))
return true;
if (!current_function_is_leaf || cfun->machine->doloop_tags > 0)
/* The interrupt handler might use these registers for repeat blocks,
or it might call a function that does so. */
if (r == RPB_REGNO || r == RPE_REGNO || r == RPC_REGNO)
return true;
if (current_function_is_leaf && call_used_regs[r] && !df_regs_ever_live_p(r))
return false;
/* Functions we call might clobber these. */
if (call_used_regs[r] && !fixed_regs[r])
return true;
/* Additional registers that need to be saved for IVC2. */
if (IVC2_ISAVED_REG (r))
return true;
return false;
}
static bool
mep_call_saves_register (int r)
{
if (! cfun->machine->frame_locked)
{
int rv = MEP_SAVES_NO;
if (cfun->machine->reg_save_slot[r])
rv = MEP_SAVES_YES;
else if (r == LP_REGNO && (profile_arc_flag > 0 || profile_flag > 0))
rv = MEP_SAVES_YES;
else if (r == FRAME_POINTER_REGNUM && frame_pointer_needed)
rv = MEP_SAVES_YES;
else if ((!call_used_regs[r] || r == LP_REGNO) && df_regs_ever_live_p(r))
rv = MEP_SAVES_YES;
else if (crtl->calls_eh_return && (r == 10 || r == 11))
/* We need these to have stack slots so that they can be set during
unwinding. */
rv = MEP_SAVES_YES;
else if (mep_interrupt_saved_reg (r))
rv = MEP_SAVES_YES;
cfun->machine->reg_saved[r] = rv;
}
return cfun->machine->reg_saved[r] == MEP_SAVES_YES;
}
/* Return true if epilogue uses register REGNO. */
bool
mep_epilogue_uses (int regno)
{
/* Since $lp is a call-saved register, the generic code will normally
mark it used in the epilogue if it needs to be saved and restored.
However, when profiling is enabled, the profiling code will implicitly
clobber $11. This case has to be handled specially both here and in
mep_call_saves_register. */
if (regno == LP_REGNO && (profile_arc_flag > 0 || profile_flag > 0))
return true;
/* Interrupt functions save/restore pretty much everything. */
return (reload_completed && mep_interrupt_saved_reg (regno));
}
static int
mep_reg_size (int regno)
{
if (CR_REGNO_P (regno) && TARGET_64BIT_CR_REGS)
return 8;
return 4;
}
/* Worker function for TARGET_CAN_ELIMINATE. */
bool
mep_can_eliminate (const int from, const int to)
{
return (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM
? ! frame_pointer_needed
: true);
}
int
mep_elimination_offset (int from, int to)
{
int reg_save_size;
int i;
int frame_size = get_frame_size () + crtl->outgoing_args_size;
int total_size;
if (!cfun->machine->frame_locked)
memset (cfun->machine->reg_saved, 0, sizeof (cfun->machine->reg_saved));
/* We don't count arg_regs_to_save in the arg pointer offset, because
gcc thinks the arg pointer has moved along with the saved regs.
However, we do count it when we adjust $sp in the prologue. */
reg_save_size = 0;
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
if (mep_call_saves_register (i))
reg_save_size += mep_reg_size (i);
if (reg_save_size % 8)
cfun->machine->regsave_filler = 8 - (reg_save_size % 8);
else
cfun->machine->regsave_filler = 0;
/* This is what our total stack adjustment looks like. */
total_size = (reg_save_size + frame_size + cfun->machine->regsave_filler);
if (total_size % 8)
cfun->machine->frame_filler = 8 - (total_size % 8);
else
cfun->machine->frame_filler = 0;
if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
return reg_save_size + cfun->machine->regsave_filler;
if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
return cfun->machine->frame_filler + frame_size;
if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
return reg_save_size + cfun->machine->regsave_filler + cfun->machine->frame_filler + frame_size;
gcc_unreachable ();
}
static rtx
F (rtx x)
{
RTX_FRAME_RELATED_P (x) = 1;
return x;
}
/* Since the prologue/epilogue code is generated after optimization,
we can't rely on gcc to split constants for us. So, this code
captures all the ways to add a constant to a register in one logic
chunk, including optimizing away insns we just don't need. This
makes the prolog/epilog code easier to follow. */
static void
add_constant (int dest, int src, int value, int mark_frame)
{
rtx insn;
int hi, lo;
if (src == dest && value == 0)
return;
if (value == 0)
{
insn = emit_move_insn (gen_rtx_REG (SImode, dest),
gen_rtx_REG (SImode, src));
if (mark_frame)
RTX_FRAME_RELATED_P(insn) = 1;
return;
}
if (value >= -32768 && value <= 32767)
{
insn = emit_insn (gen_addsi3 (gen_rtx_REG (SImode, dest),
gen_rtx_REG (SImode, src),
GEN_INT (value)));
if (mark_frame)
RTX_FRAME_RELATED_P(insn) = 1;
return;
}
/* Big constant, need to use a temp register. We use
REGSAVE_CONTROL_TEMP because it's call clobberable (the reg save
area is always small enough to directly add to). */
hi = trunc_int_for_mode (value & 0xffff0000, SImode);
lo = value & 0xffff;
insn = emit_move_insn (gen_rtx_REG (SImode, REGSAVE_CONTROL_TEMP),
GEN_INT (hi));
if (lo)
{
insn = emit_insn (gen_iorsi3 (gen_rtx_REG (SImode, REGSAVE_CONTROL_TEMP),
gen_rtx_REG (SImode, REGSAVE_CONTROL_TEMP),
GEN_INT (lo)));
}
insn = emit_insn (gen_addsi3 (gen_rtx_REG (SImode, dest),
gen_rtx_REG (SImode, src),
gen_rtx_REG (SImode, REGSAVE_CONTROL_TEMP)));
if (mark_frame)
{
RTX_FRAME_RELATED_P(insn) = 1;
add_reg_note (insn, REG_FRAME_RELATED_EXPR,
gen_rtx_SET (SImode,
gen_rtx_REG (SImode, dest),
gen_rtx_PLUS (SImode,
gen_rtx_REG (SImode, dest),
GEN_INT (value))));
}
}
/* Move SRC to DEST. Mark the move as being potentially dead if
MAYBE_DEAD_P. */
static rtx
maybe_dead_move (rtx dest, rtx src, bool ATTRIBUTE_UNUSED maybe_dead_p)
{
rtx insn = emit_move_insn (dest, src);
#if 0
if (maybe_dead_p)
REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, const0_rtx, NULL);
#endif
return insn;
}
/* Used for interrupt functions, which can't assume that $tp and $gp
contain the correct pointers. */
static void
mep_reload_pointer (int regno, const char *symbol)
{
rtx reg, sym;
if (!df_regs_ever_live_p(regno) && current_function_is_leaf)
return;
reg = gen_rtx_REG (SImode, regno);
sym = gen_rtx_SYMBOL_REF (SImode, symbol);
emit_insn (gen_movsi_topsym_s (reg, sym));
emit_insn (gen_movsi_botsym_s (reg, reg, sym));
}
/* Assign save slots for any register not already saved. DImode
registers go at the end of the reg save area; the rest go at the
beginning. This is for alignment purposes. Returns true if a frame
is really needed. */
static bool
mep_assign_save_slots (int reg_save_size)
{
bool really_need_stack_frame = false;
int di_ofs = 0;
int i;
for (i=0; i<FIRST_PSEUDO_REGISTER; i++)
if (mep_call_saves_register(i))
{
int regsize = mep_reg_size (i);
if ((i != TP_REGNO && i != GP_REGNO && i != LP_REGNO)
|| mep_reg_set_in_function (i))
really_need_stack_frame = true;
if (cfun->machine->reg_save_slot[i])
continue;
if (regsize < 8)
{
cfun->machine->reg_save_size += regsize;
cfun->machine->reg_save_slot[i] = cfun->machine->reg_save_size;
}
else
{
cfun->machine->reg_save_slot[i] = reg_save_size - di_ofs;
di_ofs += 8;
}
}
cfun->machine->frame_locked = 1;
return really_need_stack_frame;
}
void
mep_expand_prologue (void)
{
int i, rss, sp_offset = 0;
int reg_save_size;
int frame_size;
int really_need_stack_frame;
/* We must not allow register renaming in interrupt functions,
because that invalidates the correctness of the set of call-used
registers we're going to save/restore. */
mep_set_leaf_registers (mep_interrupt_p () ? 0 : 1);
if (mep_disinterrupt_p ())
emit_insn (gen_mep_disable_int ());
cfun->machine->mep_frame_pointer_needed = frame_pointer_needed;
reg_save_size = mep_elimination_offset (ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM);
frame_size = mep_elimination_offset (FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM);
really_need_stack_frame = frame_size;
really_need_stack_frame |= mep_assign_save_slots (reg_save_size);
sp_offset = reg_save_size;
if (sp_offset + frame_size < 128)
sp_offset += frame_size ;
add_constant (SP_REGNO, SP_REGNO, -sp_offset, 1);
for (i=0; i<FIRST_PSEUDO_REGISTER; i++)
if (mep_call_saves_register(i))
{
rtx mem;
bool maybe_dead_p;
enum machine_mode rmode;
rss = cfun->machine->reg_save_slot[i];
if ((i == TP_REGNO || i == GP_REGNO || i == LP_REGNO)
&& (!mep_reg_set_in_function (i)
&& !mep_interrupt_p ()))
continue;
if (mep_reg_size (i) == 8)
rmode = DImode;
else
rmode = SImode;
/* If there is a pseudo associated with this register's initial value,
reload might have already spilt it to the stack slot suggested by
ALLOCATE_INITIAL_VALUE. The moves emitted here can then be safely
deleted as dead. */
mem = gen_rtx_MEM (rmode,
plus_constant (stack_pointer_rtx, sp_offset - rss));
maybe_dead_p = rtx_equal_p (mem, has_hard_reg_initial_val (rmode, i));
if (GR_REGNO_P (i) || LOADABLE_CR_REGNO_P (i))
F(maybe_dead_move (mem, gen_rtx_REG (rmode, i), maybe_dead_p));
else if (rmode == DImode)
{
rtx insn;
int be = TARGET_BIG_ENDIAN ? 4 : 0;
mem = gen_rtx_MEM (SImode,
plus_constant (stack_pointer_rtx, sp_offset - rss + be));
maybe_dead_move (gen_rtx_REG (SImode, REGSAVE_CONTROL_TEMP),
gen_rtx_REG (SImode, i),
maybe_dead_p);
maybe_dead_move (gen_rtx_REG (SImode, REGSAVE_CONTROL_TEMP+1),
gen_rtx_ZERO_EXTRACT (SImode,
gen_rtx_REG (DImode, i),
GEN_INT (32),
GEN_INT (32)),
maybe_dead_p);
insn = maybe_dead_move (mem,
gen_rtx_REG (SImode, REGSAVE_CONTROL_TEMP),
maybe_dead_p);
RTX_FRAME_RELATED_P (insn) = 1;
add_reg_note (insn, REG_FRAME_RELATED_EXPR,
gen_rtx_SET (VOIDmode,
copy_rtx (mem),
gen_rtx_REG (rmode, i)));
mem = gen_rtx_MEM (SImode,
plus_constant (stack_pointer_rtx, sp_offset - rss + (4-be)));
insn = maybe_dead_move (mem,
gen_rtx_REG (SImode, REGSAVE_CONTROL_TEMP+1),
maybe_dead_p);
}
else
{
rtx insn;
maybe_dead_move (gen_rtx_REG (rmode, REGSAVE_CONTROL_TEMP),
gen_rtx_REG (rmode, i),
maybe_dead_p);
insn = maybe_dead_move (mem,
gen_rtx_REG (rmode, REGSAVE_CONTROL_TEMP),
maybe_dead_p);
RTX_FRAME_RELATED_P (insn) = 1;
add_reg_note (insn, REG_FRAME_RELATED_EXPR,
gen_rtx_SET (VOIDmode,
copy_rtx (mem),
gen_rtx_REG (rmode, i)));
}
}
if (frame_pointer_needed)
{
/* We've already adjusted down by sp_offset. Total $sp change
is reg_save_size + frame_size. We want a net change here of
just reg_save_size. */
add_constant (FP_REGNO, SP_REGNO, sp_offset - reg_save_size, 1);
}
add_constant (SP_REGNO, SP_REGNO, sp_offset-(reg_save_size+frame_size), 1);
if (mep_interrupt_p ())
{
mep_reload_pointer(GP_REGNO, "__sdabase");
mep_reload_pointer(TP_REGNO, "__tpbase");
}
}
static void
mep_start_function (FILE *file, HOST_WIDE_INT hwi_local)
{
int local = hwi_local;
int frame_size = local + crtl->outgoing_args_size;
int reg_save_size;
int ffill;
int i, sp, skip;
int sp_offset;
int slot_map[FIRST_PSEUDO_REGISTER], si, sj;
reg_save_size = mep_elimination_offset (ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM);
frame_size = mep_elimination_offset (FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM);
sp_offset = reg_save_size + frame_size;
ffill = cfun->machine->frame_filler;
if (cfun->machine->mep_frame_pointer_needed)
reg_names[FP_REGNO] = "$fp";
else
reg_names[FP_REGNO] = "$8";
if (sp_offset == 0)
return;
if (debug_info_level == DINFO_LEVEL_NONE)
{
fprintf (file, "\t# frame: %d", sp_offset);
if (reg_save_size)
fprintf (file, " %d regs", reg_save_size);
if (local)
fprintf (file, " %d locals", local);
if (crtl->outgoing_args_size)
fprintf (file, " %d args", crtl->outgoing_args_size);
fprintf (file, "\n");
return;
}
fprintf (file, "\t#\n");
fprintf (file, "\t# Initial Frame Information:\n");
if (sp_offset || !frame_pointer_needed)
fprintf (file, "\t# Entry ---------- 0\n");
/* Sort registers by save slots, so they're printed in the order
they appear in memory, not the order they're saved in. */
for (si=0; si<FIRST_PSEUDO_REGISTER; si++)
slot_map[si] = si;
for (si=0; si<FIRST_PSEUDO_REGISTER-1; si++)
for (sj=si+1; sj<FIRST_PSEUDO_REGISTER; sj++)
if (cfun->machine->reg_save_slot[slot_map[si]]
> cfun->machine->reg_save_slot[slot_map[sj]])
{
int t = slot_map[si];
slot_map[si] = slot_map[sj];
slot_map[sj] = t;
}
sp = 0;
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
{
int rsize;
int r = slot_map[i];
int rss = cfun->machine->reg_save_slot[r];
if (!mep_call_saves_register (r))
continue;
if ((r == TP_REGNO || r == GP_REGNO || r == LP_REGNO)
&& (!mep_reg_set_in_function (r)
&& !mep_interrupt_p ()))
continue;
rsize = mep_reg_size(r);
skip = rss - (sp+rsize);
if (skip)
fprintf (file, "\t# %3d bytes for alignment\n", skip);
fprintf (file, "\t# %3d bytes for saved %-3s %3d($sp)\n",
rsize, reg_names[r], sp_offset - rss);
sp = rss;
}
skip = reg_save_size - sp;
if (skip)
fprintf (file, "\t# %3d bytes for alignment\n", skip);
if (frame_pointer_needed)
fprintf (file, "\t# FP ---> ---------- %d (sp-%d)\n", reg_save_size, sp_offset-reg_save_size);
if (local)
fprintf (file, "\t# %3d bytes for local vars\n", local);
if (ffill)
fprintf (file, "\t# %3d bytes for alignment\n", ffill);
if (crtl->outgoing_args_size)
fprintf (file, "\t# %3d bytes for outgoing args\n",
crtl->outgoing_args_size);
fprintf (file, "\t# SP ---> ---------- %d\n", sp_offset);
fprintf (file, "\t#\n");
}
static int mep_prevent_lp_restore = 0;
static int mep_sibcall_epilogue = 0;
void
mep_expand_epilogue (void)
{
int i, sp_offset = 0;
int reg_save_size = 0;
int frame_size;
int lp_temp = LP_REGNO, lp_slot = -1;
int really_need_stack_frame = get_frame_size() + crtl->outgoing_args_size;
int interrupt_handler = mep_interrupt_p ();
if (profile_arc_flag == 2)
emit_insn (gen_mep_bb_trace_ret ());
reg_save_size = mep_elimination_offset (ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM);
frame_size = mep_elimination_offset (FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM);
really_need_stack_frame |= mep_assign_save_slots (reg_save_size);
if (frame_pointer_needed)
{
/* If we have a frame pointer, we won't have a reliable stack
pointer (alloca, you know), so rebase SP from FP */
emit_move_insn (gen_rtx_REG (SImode, SP_REGNO),
gen_rtx_REG (SImode, FP_REGNO));
sp_offset = reg_save_size;
}
else
{
/* SP is right under our local variable space. Adjust it if
needed. */
sp_offset = reg_save_size + frame_size;
if (sp_offset >= 128)
{
add_constant (SP_REGNO, SP_REGNO, frame_size, 0);
sp_offset -= frame_size;
}
}
/* This is backwards so that we restore the control and coprocessor
registers before the temporary registers we use to restore
them. */
for (i=FIRST_PSEUDO_REGISTER-1; i>=1; i--)
if (mep_call_saves_register (i))
{
enum machine_mode rmode;
int rss = cfun->machine->reg_save_slot[i];
if (mep_reg_size (i) == 8)
rmode = DImode;
else
rmode = SImode;
if ((i == TP_REGNO || i == GP_REGNO || i == LP_REGNO)
&& !(mep_reg_set_in_function (i) || interrupt_handler))
continue;
if (mep_prevent_lp_restore && i == LP_REGNO)
continue;
if (!mep_prevent_lp_restore
&& !interrupt_handler
&& (i == 10 || i == 11))
continue;
if (GR_REGNO_P (i) || LOADABLE_CR_REGNO_P (i))
emit_move_insn (gen_rtx_REG (rmode, i),
gen_rtx_MEM (rmode,
plus_constant (stack_pointer_rtx,
sp_offset-rss)));
else
{
if (i == LP_REGNO && !mep_sibcall_epilogue && !interrupt_handler)
/* Defer this one so we can jump indirect rather than
copying the RA to $lp and "ret". EH epilogues
automatically skip this anyway. */
lp_slot = sp_offset-rss;
else
{
emit_move_insn (gen_rtx_REG (rmode, REGSAVE_CONTROL_TEMP),
gen_rtx_MEM (rmode,
plus_constant (stack_pointer_rtx,
sp_offset-rss)));
emit_move_insn (gen_rtx_REG (rmode, i),
gen_rtx_REG (rmode, REGSAVE_CONTROL_TEMP));
}
}
}
if (lp_slot != -1)
{
/* Restore this one last so we know it will be in the temp
register when we return by jumping indirectly via the temp. */
emit_move_insn (gen_rtx_REG (SImode, REGSAVE_CONTROL_TEMP),
gen_rtx_MEM (SImode,
plus_constant (stack_pointer_rtx,
lp_slot)));
lp_temp = REGSAVE_CONTROL_TEMP;
}
add_constant (SP_REGNO, SP_REGNO, sp_offset, 0);
if (crtl->calls_eh_return && mep_prevent_lp_restore)
emit_insn (gen_addsi3 (gen_rtx_REG (SImode, SP_REGNO),
gen_rtx_REG (SImode, SP_REGNO),
cfun->machine->eh_stack_adjust));
if (mep_sibcall_epilogue)
return;
if (mep_disinterrupt_p ())
emit_insn (gen_mep_enable_int ());
if (mep_prevent_lp_restore)
{
emit_jump_insn (gen_eh_return_internal ());
emit_barrier ();
}
else if (interrupt_handler)
emit_jump_insn (gen_mep_reti ());
else
emit_jump_insn (gen_return_internal (gen_rtx_REG (SImode, lp_temp)));
}
void
mep_expand_eh_return (rtx *operands)
{
if (GET_CODE (operands[0]) != REG || REGNO (operands[0]) != LP_REGNO)
{
rtx ra = gen_rtx_REG (Pmode, LP_REGNO);
emit_move_insn (ra, operands[0]);
operands[0] = ra;
}
emit_insn (gen_eh_epilogue (operands[0]));
}
void
mep_emit_eh_epilogue (rtx *operands ATTRIBUTE_UNUSED)
{
cfun->machine->eh_stack_adjust = gen_rtx_REG (Pmode, 0);
mep_prevent_lp_restore = 1;
mep_expand_epilogue ();
mep_prevent_lp_restore = 0;
}
void
mep_expand_sibcall_epilogue (void)
{
mep_sibcall_epilogue = 1;
mep_expand_epilogue ();
mep_sibcall_epilogue = 0;
}
static bool
mep_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
{
if (decl == NULL)
return false;
if (mep_section_tag (DECL_RTL (decl)) == 'f')
return false;
/* Can't call to a sibcall from an interrupt or disinterrupt function. */
if (mep_interrupt_p () || mep_disinterrupt_p ())
return false;
return true;
}
rtx
mep_return_stackadj_rtx (void)
{
return gen_rtx_REG (SImode, 10);
}
rtx
mep_return_handler_rtx (void)
{
return gen_rtx_REG (SImode, LP_REGNO);
}
void
mep_function_profiler (FILE *file)
{
/* Always right at the beginning of the function. */
fprintf (file, "\t# mep function profiler\n");
fprintf (file, "\tadd\t$sp, -8\n");
fprintf (file, "\tsw\t$0, ($sp)\n");
fprintf (file, "\tldc\t$0, $lp\n");
fprintf (file, "\tsw\t$0, 4($sp)\n");
fprintf (file, "\tbsr\t__mep_mcount\n");
fprintf (file, "\tlw\t$0, 4($sp)\n");
fprintf (file, "\tstc\t$0, $lp\n");
fprintf (file, "\tlw\t$0, ($sp)\n");
fprintf (file, "\tadd\t$sp, 8\n\n");
}
const char *
mep_emit_bb_trace_ret (void)
{
fprintf (asm_out_file, "\t# end of block profiling\n");
fprintf (asm_out_file, "\tadd\t$sp, -8\n");
fprintf (asm_out_file, "\tsw\t$0, ($sp)\n");
fprintf (asm_out_file, "\tldc\t$0, $lp\n");
fprintf (asm_out_file, "\tsw\t$0, 4($sp)\n");
fprintf (asm_out_file, "\tbsr\t__bb_trace_ret\n");
fprintf (asm_out_file, "\tlw\t$0, 4($sp)\n");
fprintf (asm_out_file, "\tstc\t$0, $lp\n");
fprintf (asm_out_file, "\tlw\t$0, ($sp)\n");
fprintf (asm_out_file, "\tadd\t$sp, 8\n\n");
return "";
}
#undef SAVE
#undef RESTORE
/* Operand Printing. */
void
mep_print_operand_address (FILE *stream, rtx address)
{
if (GET_CODE (address) == MEM)
address = XEXP (address, 0);
else
/* cf: gcc.dg/asm-4.c. */
gcc_assert (GET_CODE (address) == REG);
mep_print_operand (stream, address, 0);
}
static struct
{
char code;
const char *pattern;
const char *format;
}
const conversions[] =
{
{ 0, "r", "0" },
{ 0, "m+ri", "3(2)" },
{ 0, "mr", "(1)" },
{ 0, "ms", "(1)" },
{ 0, "ml", "(1)" },
{ 0, "mLrs", "%lo(3)(2)" },
{ 0, "mLr+si", "%lo(4+5)(2)" },
{ 0, "m+ru2s", "%tpoff(5)(2)" },
{ 0, "m+ru3s", "%sdaoff(5)(2)" },
{ 0, "m+r+u2si", "%tpoff(6+7)(2)" },
{ 0, "m+ru2+si", "%tpoff(6+7)(2)" },
{ 0, "m+r+u3si", "%sdaoff(6+7)(2)" },
{ 0, "m+ru3+si", "%sdaoff(6+7)(2)" },
{ 0, "mi", "(1)" },
{ 0, "m+si", "(2+3)" },
{ 0, "m+li", "(2+3)" },
{ 0, "i", "0" },
{ 0, "s", "0" },
{ 0, "+si", "1+2" },
{ 0, "+u2si", "%tpoff(3+4)" },
{ 0, "+u3si", "%sdaoff(3+4)" },
{ 0, "l", "0" },
{ 'b', "i", "0" },
{ 'B', "i", "0" },
{ 'U', "i", "0" },
{ 'h', "i", "0" },
{ 'h', "Hs", "%hi(1)" },
{ 'I', "i", "0" },
{ 'I', "u2s", "%tpoff(2)" },
{ 'I', "u3s", "%sdaoff(2)" },
{ 'I', "+u2si", "%tpoff(3+4)" },
{ 'I', "+u3si", "%sdaoff(3+4)" },
{ 'J', "i", "0" },
{ 'P', "mr", "(1\\+),\\0" },
{ 'x', "i", "0" },
{ 0, 0, 0 }
};
static int
unique_bit_in (HOST_WIDE_INT i)
{
switch (i & 0xff)
{
case 0x01: case 0xfe: return 0;
case 0x02: case 0xfd: return 1;
case 0x04: case 0xfb: return 2;
case 0x08: case 0xf7: return 3;
case 0x10: case 0x7f: return 4;
case 0x20: case 0xbf: return 5;
case 0x40: case 0xdf: return 6;
case 0x80: case 0xef: return 7;
default:
gcc_unreachable ();
}
}
static int
bit_size_for_clip (HOST_WIDE_INT i)
{
int rv;
for (rv = 0; rv < 31; rv ++)
if (((HOST_WIDE_INT) 1 << rv) > i)
return rv + 1;
gcc_unreachable ();
}
/* Print an operand to a assembler instruction. */
void
mep_print_operand (FILE *file, rtx x, int code)
{
int i, j;
const char *real_name;
if (code == '<')
{
/* Print a mnemonic to do CR <- CR moves. Find out which intrinsic
we're using, then skip over the "mep_" part of its name. */
const struct cgen_insn *insn;
if (mep_get_move_insn (mep_cmov, &insn))
fputs (cgen_intrinsics[insn->intrinsic] + 4, file);
else
mep_intrinsic_unavailable (mep_cmov);
return;
}
if (code == 'L')
{
switch (GET_CODE (x))
{
case AND:
fputs ("clr", file);
return;
case IOR:
fputs ("set", file);
return;
case XOR:
fputs ("not", file);
return;
default:
output_operand_lossage ("invalid %%L code");
}
}
if (code == 'M')
{
/* Print the second operand of a CR <- CR move. If we're using
a two-operand instruction (i.e., a real cmov), then just print
the operand normally. If we're using a "reg, reg, immediate"
instruction such as caddi3, print the operand followed by a
zero field. If we're using a three-register instruction,
print the operand twice. */
const struct cgen_insn *insn;
mep_print_operand (file, x, 0);
if (mep_get_move_insn (mep_cmov, &insn)
&& insn_data[insn->icode].n_operands == 3)
{
fputs (", ", file);
if (insn_data[insn->icode].operand[2].predicate (x, VOIDmode))
mep_print_operand (file, x, 0);
else
mep_print_operand (file, const0_rtx, 0);
}
return;
}
encode_pattern (x);
for (i = 0; conversions[i].pattern; i++)
if (conversions[i].code == code
&& strcmp(conversions[i].pattern, pattern) == 0)
{
for (j = 0; conversions[i].format[j]; j++)
if (conversions[i].format[j] == '\\')
{
fputc (conversions[i].format[j+1], file);
j++;
}
else if (ISDIGIT(conversions[i].format[j]))
{
rtx r = patternr[conversions[i].format[j] - '0'];
switch (GET_CODE (r))
{
case REG:
fprintf (file, "%s", reg_names [REGNO (r)]);
break;
case CONST_INT:
switch (code)
{
case 'b':
fprintf (file, "%d", unique_bit_in (INTVAL (r)));
break;
case 'B':
fprintf (file, "%d", bit_size_for_clip (INTVAL (r)));
break;
case 'h':
fprintf (file, "0x%x", ((int) INTVAL (r) >> 16) & 0xffff);
break;
case 'U':
fprintf (file, "%d", bit_size_for_clip (INTVAL (r)) - 1);
break;
case 'J':
fprintf (file, "0x%x", (int) INTVAL (r) & 0xffff);
break;
case 'x':
if (INTVAL (r) & ~(HOST_WIDE_INT)0xff
&& !(INTVAL (r) & 0xff))
fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL(r));
else
fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL(r));
break;
case 'I':
if (INTVAL (r) & ~(HOST_WIDE_INT)0xff
&& conversions[i].format[j+1] == 0)
{
fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (r));
fprintf (file, " # 0x%x", (int) INTVAL(r) & 0xffff);
}
else
fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL(r));
break;
default:
fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL(r));
break;
}
break;
case CONST_DOUBLE:
fprintf(file, "[const_double 0x%lx]",
(unsigned long) CONST_DOUBLE_HIGH(r));
break;
case SYMBOL_REF:
real_name = TARGET_STRIP_NAME_ENCODING (XSTR (r, 0));
assemble_name (file, real_name);
break;
case LABEL_REF:
output_asm_label (r);
break;
default:
fprintf (stderr, "don't know how to print this operand:");
debug_rtx (r);
gcc_unreachable ();
}
}
else
{
if (conversions[i].format[j] == '+'
&& (!code || code == 'I')
&& ISDIGIT (conversions[i].format[j+1])
&& GET_CODE (patternr[conversions[i].format[j+1] - '0']) == CONST_INT
&& INTVAL (patternr[conversions[i].format[j+1] - '0']) < 0)
continue;
fputc(conversions[i].format[j], file);
}
break;
}
if (!conversions[i].pattern)
{
error ("unconvertible operand %c %qs", code?code:'-', pattern);
debug_rtx(x);
}
return;
}
void
mep_final_prescan_insn (rtx insn, rtx *operands ATTRIBUTE_UNUSED,
int noperands ATTRIBUTE_UNUSED)
{
/* Despite the fact that MeP is perfectly capable of branching and
doing something else in the same bundle, gcc does jump
optimization *after* scheduling, so we cannot trust the bundling
flags on jump instructions. */
if (GET_MODE (insn) == BImode
&& get_attr_slots (insn) != SLOTS_CORE)
fputc ('+', asm_out_file);
}
/* Function args in registers. */
static void
mep_setup_incoming_varargs (CUMULATIVE_ARGS *cum,
enum machine_mode mode ATTRIBUTE_UNUSED,
tree type ATTRIBUTE_UNUSED, int *pretend_size,
int second_time ATTRIBUTE_UNUSED)
{
int nsave = 4 - (cum->nregs + 1);
if (nsave > 0)
cfun->machine->arg_regs_to_save = nsave;
*pretend_size = nsave * 4;
}
static int
bytesize (const_tree type, enum machine_mode mode)
{
if (mode == BLKmode)
return int_size_in_bytes (type);
return GET_MODE_SIZE (mode);
}
static rtx
mep_expand_builtin_saveregs (void)
{
int bufsize, i, ns;
rtx regbuf;
ns = cfun->machine->arg_regs_to_save;
if (TARGET_IVC2)
{
bufsize = 8 * ((ns + 1) / 2) + 8 * ns;
regbuf = assign_stack_local (SImode, bufsize, 64);
}
else
{
bufsize = ns * 4;
regbuf = assign_stack_local (SImode, bufsize, 32);
}
move_block_from_reg (5-ns, regbuf, ns);
if (TARGET_IVC2)
{
rtx tmp = gen_rtx_MEM (DImode, XEXP (regbuf, 0));
int ofs = 8 * ((ns+1)/2);
for (i=0; i<ns; i++)
{
int rn = (4-ns) + i + 49;
rtx ptr;
ptr = offset_address (tmp, GEN_INT (ofs), 2);
emit_move_insn (ptr, gen_rtx_REG (DImode, rn));
ofs += 8;
}
}
return XEXP (regbuf, 0);
}
#define VECTOR_TYPE_P(t) (TREE_CODE(t) == VECTOR_TYPE)
static tree
mep_build_builtin_va_list (void)
{
tree f_next_gp, f_next_gp_limit, f_next_cop, f_next_stack;
tree record;
record = (*lang_hooks.types.make_type) (RECORD_TYPE);
f_next_gp = build_decl (BUILTINS_LOCATION, FIELD_DECL,
get_identifier ("__va_next_gp"), ptr_type_node);
f_next_gp_limit = build_decl (BUILTINS_LOCATION, FIELD_DECL,
get_identifier ("__va_next_gp_limit"),
ptr_type_node);
f_next_cop = build_decl (BUILTINS_LOCATION, FIELD_DECL, get_identifier ("__va_next_cop"),
ptr_type_node);
f_next_stack = build_decl (BUILTINS_LOCATION, FIELD_DECL, get_identifier ("__va_next_stack"),
ptr_type_node);
DECL_FIELD_CONTEXT (f_next_gp) = record;
DECL_FIELD_CONTEXT (f_next_gp_limit) = record;
DECL_FIELD_CONTEXT (f_next_cop) = record;
DECL_FIELD_CONTEXT (f_next_stack) = record;
TYPE_FIELDS (record) = f_next_gp;
TREE_CHAIN (f_next_gp) = f_next_gp_limit;
TREE_CHAIN (f_next_gp_limit) = f_next_cop;
TREE_CHAIN (f_next_cop) = f_next_stack;
layout_type (record);
return record;
}
static void
mep_expand_va_start (tree valist, rtx nextarg)
{
tree f_next_gp, f_next_gp_limit, f_next_cop, f_next_stack;
tree next_gp, next_gp_limit, next_cop, next_stack;
tree t, u;
int ns;
ns = cfun->machine->arg_regs_to_save;
f_next_gp = TYPE_FIELDS (va_list_type_node);
f_next_gp_limit = TREE_CHAIN (f_next_gp);
f_next_cop = TREE_CHAIN (f_next_gp_limit);
f_next_stack = TREE_CHAIN (f_next_cop);
next_gp = build3 (COMPONENT_REF, TREE_TYPE (f_next_gp), valist, f_next_gp,
NULL_TREE);
next_gp_limit = build3 (COMPONENT_REF, TREE_TYPE (f_next_gp_limit),
valist, f_next_gp_limit, NULL_TREE);
next_cop = build3 (COMPONENT_REF, TREE_TYPE (f_next_cop), valist, f_next_cop,
NULL_TREE);
next_stack = build3 (COMPONENT_REF, TREE_TYPE (f_next_stack),
valist, f_next_stack, NULL_TREE);
/* va_list.next_gp = expand_builtin_saveregs (); */
u = make_tree (sizetype, expand_builtin_saveregs ());
u = fold_convert (ptr_type_node, u);
t = build2 (MODIFY_EXPR, ptr_type_node, next_gp, u);
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
/* va_list.next_gp_limit = va_list.next_gp + 4 * ns; */
u = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node, u,
size_int (4 * ns));
t = build2 (MODIFY_EXPR, ptr_type_node, next_gp_limit, u);
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
u = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node, u,
size_int (8 * ((ns+1)/2)));
/* va_list.next_cop = ROUND_UP(va_list.next_gp_limit,8); */
t = build2 (MODIFY_EXPR, ptr_type_node, next_cop, u);
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
/* va_list.next_stack = nextarg; */
u = make_tree (ptr_type_node, nextarg);
t = build2 (MODIFY_EXPR, ptr_type_node, next_stack, u);
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
static tree
mep_gimplify_va_arg_expr (tree valist, tree type,
gimple_seq *pre_p,
gimple_seq *post_p ATTRIBUTE_UNUSED)
{
HOST_WIDE_INT size, rsize;
bool by_reference, ivc2_vec;
tree f_next_gp, f_next_gp_limit, f_next_cop, f_next_stack;
tree next_gp, next_gp_limit, next_cop, next_stack;
tree label_sover, label_selse;
tree tmp, res_addr;
ivc2_vec = TARGET_IVC2 && VECTOR_TYPE_P (type);
size = int_size_in_bytes (type);
by_reference = (size > (ivc2_vec ? 8 : 4)) || (size <= 0);
if (by_reference)
{
type = build_pointer_type (type);
size = 4;
}
rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
f_next_gp = TYPE_FIELDS (va_list_type_node);
f_next_gp_limit = TREE_CHAIN (f_next_gp);
f_next_cop = TREE_CHAIN (f_next_gp_limit);
f_next_stack = TREE_CHAIN (f_next_cop);
next_gp = build3 (COMPONENT_REF, TREE_TYPE (f_next_gp), valist, f_next_gp,
NULL_TREE);
next_gp_limit = build3 (COMPONENT_REF, TREE_TYPE (f_next_gp_limit),
valist, f_next_gp_limit, NULL_TREE);
next_cop = build3 (COMPONENT_REF, TREE_TYPE (f_next_cop), valist, f_next_cop,
NULL_TREE);
next_stack = build3 (COMPONENT_REF, TREE_TYPE (f_next_stack),
valist, f_next_stack, NULL_TREE);
/* if f_next_gp < f_next_gp_limit
IF (VECTOR_P && IVC2)
val = *f_next_cop;
ELSE
val = *f_next_gp;
f_next_gp += 4;
f_next_cop += 8;
else
label_selse:
val = *f_next_stack;
f_next_stack += rsize;
label_sover:
*/
label_sover = create_artificial_label (UNKNOWN_LOCATION);
label_selse = create_artificial_label (UNKNOWN_LOCATION);
res_addr = create_tmp_var (ptr_type_node, NULL);
tmp = build2 (GE_EXPR, boolean_type_node, next_gp,
unshare_expr (next_gp_limit));
tmp = build3 (COND_EXPR, void_type_node, tmp,
build1 (GOTO_EXPR, void_type_node,
unshare_expr (label_selse)),
NULL_TREE);
gimplify_and_add (tmp, pre_p);
if (ivc2_vec)
{
tmp = build2 (MODIFY_EXPR, void_type_node, res_addr, next_cop);
gimplify_and_add (tmp, pre_p);
}
else
{
tmp = build2 (MODIFY_EXPR, void_type_node, res_addr, next_gp);
gimplify_and_add (tmp, pre_p);
}
tmp = build2 (POINTER_PLUS_EXPR, ptr_type_node,
unshare_expr (next_gp), size_int (4));
gimplify_assign (unshare_expr (next_gp), tmp, pre_p);
tmp = build2 (POINTER_PLUS_EXPR, ptr_type_node,
unshare_expr (next_cop), size_int (8));
gimplify_assign (unshare_expr (next_cop), tmp, pre_p);
tmp = build1 (GOTO_EXPR, void_type_node, unshare_expr (label_sover));
gimplify_and_add (tmp, pre_p);
/* - - */
tmp = build1 (LABEL_EXPR, void_type_node, unshare_expr (label_selse));
gimplify_and_add (tmp, pre_p);
tmp = build2 (MODIFY_EXPR, void_type_node, res_addr, unshare_expr (next_stack));
gimplify_and_add (tmp, pre_p);
tmp = build2 (POINTER_PLUS_EXPR, ptr_type_node,
unshare_expr (next_stack), size_int (rsize));
gimplify_assign (unshare_expr (next_stack), tmp, pre_p);
/* - - */
tmp = build1 (LABEL_EXPR, void_type_node, unshare_expr (label_sover));
gimplify_and_add (tmp, pre_p);
res_addr = fold_convert (build_pointer_type (type), res_addr);
if (by_reference)
res_addr = build_va_arg_indirect_ref (res_addr);
return build_va_arg_indirect_ref (res_addr);
}
void
mep_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype,
rtx libname ATTRIBUTE_UNUSED,
tree fndecl ATTRIBUTE_UNUSED)
{
pcum->nregs = 0;
if (fntype && lookup_attribute ("vliw", TYPE_ATTRIBUTES (fntype)))
pcum->vliw = 1;
else
pcum->vliw = 0;
}
rtx
mep_function_arg (CUMULATIVE_ARGS cum, enum machine_mode mode,
tree type ATTRIBUTE_UNUSED, int named ATTRIBUTE_UNUSED)
{
/* VOIDmode is a signal for the backend to pass data to the call
expander via the second operand to the call pattern. We use
this to determine whether to use "jsr" or "jsrv". */
if (mode == VOIDmode)
return GEN_INT (cum.vliw);
/* If we havn't run out of argument registers, return the next. */
if (cum.nregs < 4)
{
if (type && TARGET_IVC2 && VECTOR_TYPE_P (type))
return gen_rtx_REG (mode, cum.nregs + 49);
else
return gen_rtx_REG (mode, cum.nregs + 1);
}
/* Otherwise the argument goes on the stack. */
return NULL_RTX;
}
static bool
mep_pass_by_reference (CUMULATIVE_ARGS * cum ATTRIBUTE_UNUSED,
enum machine_mode mode,
const_tree type,
bool named ATTRIBUTE_UNUSED)
{
int size = bytesize (type, mode);
/* This is non-obvious, but yes, large values passed after we've run
out of registers are *still* passed by reference - we put the
address of the parameter on the stack, as well as putting the
parameter itself elsewhere on the stack. */
if (size <= 0 || size > 8)
return true;
if (size <= 4)
return false;
if (TARGET_IVC2 && cum->nregs < 4 && type != NULL_TREE && VECTOR_TYPE_P (type))
return false;
return true;
}
void
mep_arg_advance (CUMULATIVE_ARGS *pcum,
enum machine_mode mode ATTRIBUTE_UNUSED,
tree type ATTRIBUTE_UNUSED, int named ATTRIBUTE_UNUSED)
{
pcum->nregs += 1;
}
bool
mep_return_in_memory (const_tree type, const_tree decl ATTRIBUTE_UNUSED)
{
int size = bytesize (type, BLKmode);
if (TARGET_IVC2 && VECTOR_TYPE_P (type))
return size > 0 && size <= 8 ? 0 : 1;
return size > 0 && size <= 4 ? 0 : 1;
}
static bool
mep_narrow_volatile_bitfield (void)
{
return true;
return false;
}
/* Implement FUNCTION_VALUE. All values are returned in $0. */
rtx
mep_function_value (tree type, tree func ATTRIBUTE_UNUSED)
{
if (TARGET_IVC2 && VECTOR_TYPE_P (type))
return gen_rtx_REG (TYPE_MODE (type), 48);
return gen_rtx_REG (TYPE_MODE (type), RETURN_VALUE_REGNUM);
}
/* Implement LIBCALL_VALUE, using the same rules as mep_function_value. */
rtx
mep_libcall_value (enum machine_mode mode)
{
return gen_rtx_REG (mode, RETURN_VALUE_REGNUM);
}
/* Handle pipeline hazards. */
typedef enum { op_none, op_stc, op_fsft, op_ret } op_num;
static const char *opnames[] = { "", "stc", "fsft", "ret" };
static int prev_opcode = 0;
/* This isn't as optimal as it could be, because we don't know what
control register the STC opcode is storing in. We only need to add
the nop if it's the relevent register, but we add it for irrelevent
registers also. */
void
mep_asm_output_opcode (FILE *file, const char *ptr)
{
int this_opcode = op_none;
const char *hazard = 0;
switch (*ptr)
{
case 'f':
if (strncmp (ptr, "fsft", 4) == 0 && !ISGRAPH (ptr[4]))
this_opcode = op_fsft;
break;
case 'r':
if (strncmp (ptr, "ret", 3) == 0 && !ISGRAPH (ptr[3]))
this_opcode = op_ret;
break;
case 's':
if (strncmp (ptr, "stc", 3) == 0 && !ISGRAPH (ptr[3]))
this_opcode = op_stc;
break;
}
if (prev_opcode == op_stc && this_opcode == op_fsft)
hazard = "nop";
if (prev_opcode == op_stc && this_opcode == op_ret)
hazard = "nop";
if (hazard)
fprintf(file, "%s\t# %s-%s hazard\n\t",
hazard, opnames[prev_opcode], opnames[this_opcode]);
prev_opcode = this_opcode;
}
/* Handle attributes. */
static tree
mep_validate_based_tiny (tree *node, tree name, tree args,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
if (TREE_CODE (*node) != VAR_DECL
&& TREE_CODE (*node) != POINTER_TYPE
&& TREE_CODE (*node) != TYPE_DECL)
{
warning (0, "%qE attribute only applies to variables", name);
*no_add = true;
}
else if (args == NULL_TREE && TREE_CODE (*node) == VAR_DECL)
{
if (! (TREE_PUBLIC (*node) || TREE_STATIC (*node)))
{
warning (0, "address region attributes not allowed with auto storage class");
*no_add = true;
}
/* Ignore storage attribute of pointed to variable: char __far * x; */
if (TREE_TYPE (*node) && TREE_CODE (TREE_TYPE (*node)) == POINTER_TYPE)
{
warning (0, "address region attributes on pointed-to types ignored");
*no_add = true;
}
}
return NULL_TREE;
}
static int
mep_multiple_address_regions (tree list, bool check_section_attr)
{
tree a;
int count_sections = 0;
int section_attr_count = 0;
for (a = list; a; a = TREE_CHAIN (a))
{
if (is_attribute_p ("based", TREE_PURPOSE (a))
|| is_attribute_p ("tiny", TREE_PURPOSE (a))
|| is_attribute_p ("near", TREE_PURPOSE (a))
|| is_attribute_p ("far", TREE_PURPOSE (a))
|| is_attribute_p ("io", TREE_PURPOSE (a)))
count_sections ++;
if (check_section_attr)
section_attr_count += is_attribute_p ("section", TREE_PURPOSE (a));
}
if (check_section_attr)
return section_attr_count;
else
return count_sections;
}
#define MEP_ATTRIBUTES(decl) \
(TYPE_P (decl)) ? TYPE_ATTRIBUTES (decl) \
: DECL_ATTRIBUTES (decl) \
? (DECL_ATTRIBUTES (decl)) \
: TYPE_ATTRIBUTES (TREE_TYPE (decl))
static tree
mep_validate_near_far (tree *node, tree name, tree args,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
if (TREE_CODE (*node) != VAR_DECL
&& TREE_CODE (*node) != FUNCTION_DECL
&& TREE_CODE (*node) != METHOD_TYPE
&& TREE_CODE (*node) != POINTER_TYPE
&& TREE_CODE (*node) != TYPE_DECL)
{
warning (0, "%qE attribute only applies to variables and functions",
name);
*no_add = true;
}
else if (args == NULL_TREE && TREE_CODE (*node) == VAR_DECL)
{
if (! (TREE_PUBLIC (*node) || TREE_STATIC (*node)))
{
warning (0, "address region attributes not allowed with auto storage class");
*no_add = true;
}
/* Ignore storage attribute of pointed to variable: char __far * x; */
if (TREE_TYPE (*node) && TREE_CODE (TREE_TYPE (*node)) == POINTER_TYPE)
{
warning (0, "address region attributes on pointed-to types ignored");
*no_add = true;
}
}
else if (mep_multiple_address_regions (MEP_ATTRIBUTES (*node), false) > 0)
{
warning (0, "duplicate address region attribute %qE in declaration of %qE on line %d",
name, DECL_NAME (*node), DECL_SOURCE_LINE (*node));
DECL_ATTRIBUTES (*node) = NULL_TREE;
}
return NULL_TREE;
}
static tree
mep_validate_disinterrupt (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
if (TREE_CODE (*node) != FUNCTION_DECL
&& TREE_CODE (*node) != METHOD_TYPE)
{
warning (0, "%qE attribute only applies to functions", name);
*no_add = true;
}
return NULL_TREE;
}
static tree
mep_validate_interrupt (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
tree function_type;
if (TREE_CODE (*node) != FUNCTION_DECL)
{
warning (0, "%qE attribute only applies to functions", name);
*no_add = true;
return NULL_TREE;
}
if (DECL_DECLARED_INLINE_P (*node))
error ("cannot inline interrupt function %qE", DECL_NAME (*node));
DECL_UNINLINABLE (*node) = 1;
function_type = TREE_TYPE (*node);
if (TREE_TYPE (function_type) != void_type_node)
error ("interrupt function must have return type of void");
if (TYPE_ARG_TYPES (function_type)
&& (TREE_VALUE (TYPE_ARG_TYPES (function_type)) != void_type_node
|| TREE_CHAIN (TYPE_ARG_TYPES (function_type)) != NULL_TREE))
error ("interrupt function must have no arguments");
return NULL_TREE;
}
static tree
mep_validate_io_cb (tree *node, tree name, tree args,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
if (TREE_CODE (*node) != VAR_DECL)
{
warning (0, "%qE attribute only applies to variables", name);
*no_add = true;
}
if (args != NULL_TREE)
{
if (TREE_CODE (TREE_VALUE (args)) == NON_LVALUE_EXPR)
TREE_VALUE (args) = TREE_OPERAND (TREE_VALUE (args), 0);
if (TREE_CODE (TREE_VALUE (args)) != INTEGER_CST)
{
warning (0, "%qE attribute allows only an integer constant argument",
name);
*no_add = true;
}
}
if (*no_add == false && !TARGET_IO_NO_VOLATILE)
TREE_THIS_VOLATILE (*node) = 1;
return NULL_TREE;
}
static tree
mep_validate_vliw (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
if (TREE_CODE (*node) != FUNCTION_TYPE
&& TREE_CODE (*node) != FUNCTION_DECL
&& TREE_CODE (*node) != METHOD_TYPE
&& TREE_CODE (*node) != FIELD_DECL
&& TREE_CODE (*node) != TYPE_DECL)
{
static int gave_pointer_note = 0;
static int gave_array_note = 0;
static const char * given_type = NULL;
given_type = tree_code_name[TREE_CODE (*node)];
if (TREE_CODE (*node) == POINTER_TYPE)
given_type = "pointers";
if (TREE_CODE (*node) == ARRAY_TYPE)
given_type = "arrays";
if (given_type)
warning (0, "%qE attribute only applies to functions, not %s",
name, given_type);
else
warning (0, "%qE attribute only applies to functions",
name);
*no_add = true;
if (TREE_CODE (*node) == POINTER_TYPE
&& !gave_pointer_note)
{
inform (input_location, "To describe a pointer to a VLIW function, use syntax like this:");
inform (input_location, " typedef int (__vliw *vfuncptr) ();");
gave_pointer_note = 1;
}
if (TREE_CODE (*node) == ARRAY_TYPE
&& !gave_array_note)
{
inform (input_location, "To describe an array of VLIW function pointers, use syntax like this:");
inform (input_location, " typedef int (__vliw *vfuncptr[]) ();");
gave_array_note = 1;
}
}
if (!TARGET_VLIW)
error ("VLIW functions are not allowed without a VLIW configuration");
return NULL_TREE;
}
static const struct attribute_spec mep_attribute_table[11] =
{
/* name min max decl type func handler */
{ "based", 0, 0, false, false, false, mep_validate_based_tiny },
{ "tiny", 0, 0, false, false, false, mep_validate_based_tiny },
{ "near", 0, 0, false, false, false, mep_validate_near_far },
{ "far", 0, 0, false, false, false, mep_validate_near_far },
{ "disinterrupt", 0, 0, false, false, false, mep_validate_disinterrupt },
{ "interrupt", 0, 0, false, false, false, mep_validate_interrupt },
{ "io", 0, 1, false, false, false, mep_validate_io_cb },
{ "cb", 0, 1, false, false, false, mep_validate_io_cb },
{ "vliw", 0, 0, false, true, false, mep_validate_vliw },
{ NULL, 0, 0, false, false, false, NULL }
};
static bool
mep_function_attribute_inlinable_p (const_tree callee)
{
tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (callee));
if (!attrs) attrs = DECL_ATTRIBUTES (callee);
return (lookup_attribute ("disinterrupt", attrs) == 0
&& lookup_attribute ("interrupt", attrs) == 0);
}
static bool
mep_can_inline_p (tree caller, tree callee)
{
if (TREE_CODE (callee) == ADDR_EXPR)
callee = TREE_OPERAND (callee, 0);
if (!mep_vliw_function_p (caller)
&& mep_vliw_function_p (callee))
{
return false;
}
return true;
}
#define FUNC_CALL 1
#define FUNC_DISINTERRUPT 2
struct GTY(()) pragma_entry {
int used;
int flag;
const char *funcname;
};
typedef struct pragma_entry pragma_entry;
/* Hash table of farcall-tagged sections. */
static GTY((param_is (pragma_entry))) htab_t pragma_htab;
static int
pragma_entry_eq (const void *p1, const void *p2)
{
const pragma_entry *old = (const pragma_entry *) p1;
const char *new_name = (const char *) p2;
return strcmp (old->funcname, new_name) == 0;
}
static hashval_t
pragma_entry_hash (const void *p)
{
const pragma_entry *old = (const pragma_entry *) p;
return htab_hash_string (old->funcname);
}
static void
mep_note_pragma_flag (const char *funcname, int flag)
{
pragma_entry **slot;
if (!pragma_htab)
pragma_htab = htab_create_ggc (31, pragma_entry_hash,
pragma_entry_eq, NULL);
slot = (pragma_entry **)
htab_find_slot_with_hash (pragma_htab, funcname,
htab_hash_string (funcname), INSERT);
if (!*slot)
{
*slot = ggc_alloc_pragma_entry ();
(*slot)->flag = 0;
(*slot)->used = 0;
(*slot)->funcname = ggc_strdup (funcname);
}
(*slot)->flag |= flag;
}
static bool
mep_lookup_pragma_flag (const char *funcname, int flag)
{
pragma_entry **slot;
if (!pragma_htab)
return false;
if (funcname[0] == '@' && funcname[2] == '.')
funcname += 3;
slot = (pragma_entry **)
htab_find_slot_with_hash (pragma_htab, funcname,
htab_hash_string (funcname), NO_INSERT);
if (slot && *slot && ((*slot)->flag & flag))
{
(*slot)->used |= flag;
return true;
}
return false;
}
bool
mep_lookup_pragma_call (const char *funcname)
{
return mep_lookup_pragma_flag (funcname, FUNC_CALL);
}
void
mep_note_pragma_call (const char *funcname)
{
mep_note_pragma_flag (funcname, FUNC_CALL);
}
bool
mep_lookup_pragma_disinterrupt (const char *funcname)
{
return mep_lookup_pragma_flag (funcname, FUNC_DISINTERRUPT);
}
void
mep_note_pragma_disinterrupt (const char *funcname)
{
mep_note_pragma_flag (funcname, FUNC_DISINTERRUPT);
}
static int
note_unused_pragma_disinterrupt (void **slot, void *data ATTRIBUTE_UNUSED)
{
const pragma_entry *d = (const pragma_entry *)(*slot);
if ((d->flag & FUNC_DISINTERRUPT)
&& !(d->used & FUNC_DISINTERRUPT))
warning (0, "\"#pragma disinterrupt %s\" not used", d->funcname);
return 1;
}
void
mep_file_cleanups (void)
{
if (pragma_htab)
htab_traverse (pragma_htab, note_unused_pragma_disinterrupt, NULL);
}
static int
mep_attrlist_to_encoding (tree list, tree decl)
{
if (mep_multiple_address_regions (list, false) > 1)
{
warning (0, "duplicate address region attribute %qE in declaration of %qE on line %d",
TREE_PURPOSE (TREE_CHAIN (list)),
DECL_NAME (decl),
DECL_SOURCE_LINE (decl));
TREE_CHAIN (list) = NULL_TREE;
}
while (list)
{
if (is_attribute_p ("based", TREE_PURPOSE (list)))
return 'b';
if (is_attribute_p ("tiny", TREE_PURPOSE (list)))
return 't';
if (is_attribute_p ("near", TREE_PURPOSE (list)))
return 'n';
if (is_attribute_p ("far", TREE_PURPOSE (list)))
return 'f';
if (is_attribute_p ("io", TREE_PURPOSE (list)))
{
if (TREE_VALUE (list)
&& TREE_VALUE (TREE_VALUE (list))
&& TREE_CODE (TREE_VALUE (TREE_VALUE (list))) == INTEGER_CST)
{
int location = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE(list)));
if (location >= 0
&& location <= 0x1000000)
return 'i';
}
return 'I';
}
if (is_attribute_p ("cb", TREE_PURPOSE (list)))
return 'c';
list = TREE_CHAIN (list);
}
if (TARGET_TF
&& TREE_CODE (decl) == FUNCTION_DECL
&& DECL_SECTION_NAME (decl) == 0)
return 'f';
return 0;
}
static int
mep_comp_type_attributes (const_tree t1, const_tree t2)
{
int vliw1, vliw2;
vliw1 = (lookup_attribute ("vliw", TYPE_ATTRIBUTES (t1)) != 0);
vliw2 = (lookup_attribute ("vliw", TYPE_ATTRIBUTES (t2)) != 0);
if (vliw1 != vliw2)
return 0;
return 1;
}
static void
mep_insert_attributes (tree decl, tree *attributes)
{
int size;
const char *secname = 0;
tree attrib, attrlist;
char encoding;
if (TREE_CODE (decl) == FUNCTION_DECL)
{
const char *funcname = IDENTIFIER_POINTER (DECL_NAME (decl));
if (mep_lookup_pragma_disinterrupt (funcname))
{
attrib = build_tree_list (get_identifier ("disinterrupt"), NULL_TREE);
*attributes = chainon (*attributes, attrib);
}
}
if (TREE_CODE (decl) != VAR_DECL
|| ! (TREE_PUBLIC (decl) || TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
return;
if (TREE_READONLY (decl) && TARGET_DC)
/* -mdc means that const variables default to the near section,
regardless of the size cutoff. */
return;
/* User specified an attribute, so override the default.
Ignore storage attribute of pointed to variable. char __far * x; */
if (! (TREE_TYPE (decl) && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE))
{
if (TYPE_P (decl) && TYPE_ATTRIBUTES (decl) && *attributes)
TYPE_ATTRIBUTES (decl) = NULL_TREE;
else if (DECL_ATTRIBUTES (decl) && *attributes)
DECL_ATTRIBUTES (decl) = NULL_TREE;
}
attrlist = *attributes ? *attributes : DECL_ATTRIBUTES (decl);
encoding = mep_attrlist_to_encoding (attrlist, decl);
if (!encoding && TYPE_P (TREE_TYPE (decl)))
{
attrlist = TYPE_ATTRIBUTES (TREE_TYPE (decl));
encoding = mep_attrlist_to_encoding (attrlist, decl);
}
if (encoding)
{
/* This means that the declaration has a specific section
attribute, so we should not apply the default rules. */
if (encoding == 'i' || encoding == 'I')
{
tree attr = lookup_attribute ("io", attrlist);
if (attr
&& TREE_VALUE (attr)
&& TREE_VALUE (TREE_VALUE(attr)))
{
int location = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE(attr)));
static tree previous_value = 0;
static int previous_location = 0;
static tree previous_name = 0;
/* We take advantage of the fact that gcc will reuse the
same tree pointer when applying an attribute to a
list of decls, but produce a new tree for attributes
on separate source lines, even when they're textually
identical. This is the behavior we want. */
if (TREE_VALUE (attr) == previous_value
&& location == previous_location)
{
warning(0, "__io address 0x%x is the same for %qE and %qE",
location, previous_name, DECL_NAME (decl));
}
previous_name = DECL_NAME (decl);
previous_location = location;
previous_value = TREE_VALUE (attr);
}
}
return;
}
/* Declarations of arrays can change size. Don't trust them. */
if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
size = 0;
else
size = int_size_in_bytes (TREE_TYPE (decl));
if (TARGET_RAND_TPGP && size <= 4 && size > 0)
{
if (TREE_PUBLIC (decl)
|| DECL_EXTERNAL (decl)
|| TREE_STATIC (decl))
{
const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
int key = 0;
while (*name)
key += *name++;
switch (key & 3)
{
case 0:
secname = "based";
break;
case 1:
secname = "tiny";
break;
case 2:
secname = "far";
break;
default:
;
}
}
}
else
{
if (size <= mep_based_cutoff && size > 0)
secname = "based";
else if (size <= mep_tiny_cutoff && size > 0)
secname = "tiny";
else if (TARGET_L)
secname = "far";
}
if (mep_const_section && TREE_READONLY (decl))
{
if (strcmp (mep_const_section, "tiny") == 0)
secname = "tiny";
else if (strcmp (mep_const_section, "near") == 0)
return;
else if (strcmp (mep_const_section, "far") == 0)
secname = "far";
}
if (!secname)
return;
if (!mep_multiple_address_regions (*attributes, true)
&& !mep_multiple_address_regions (DECL_ATTRIBUTES (decl), false))
{
attrib = build_tree_list (get_identifier (secname), NULL_TREE);
/* Chain the attribute directly onto the variable's DECL_ATTRIBUTES
in order to avoid the POINTER_TYPE bypasses in mep_validate_near_far
and mep_validate_based_tiny. */
DECL_ATTRIBUTES (decl) = chainon (DECL_ATTRIBUTES (decl), attrib);
}
}
static void
mep_encode_section_info (tree decl, rtx rtl, int first)
{
rtx rtlname;
const char *oldname;
const char *secname;
char encoding;
char *newname;
tree idp;
int maxsize;
tree type;
tree mep_attributes;
if (! first)
return;
if (TREE_CODE (decl) != VAR_DECL
&& TREE_CODE (decl) != FUNCTION_DECL)
return;
rtlname = XEXP (rtl, 0);
if (GET_CODE (rtlname) == SYMBOL_REF)
oldname = XSTR (rtlname, 0);
else if (GET_CODE (rtlname) == MEM
&& GET_CODE (XEXP (rtlname, 0)) == SYMBOL_REF)
oldname = XSTR (XEXP (rtlname, 0), 0);
else
gcc_unreachable ();
type = TREE_TYPE (decl);
if (type == error_mark_node)
return;
mep_attributes = MEP_ATTRIBUTES (decl);
encoding = mep_attrlist_to_encoding (mep_attributes, decl);
if (encoding)
{
newname = (char *) alloca (strlen (oldname) + 4);
sprintf (newname, "@%c.%s", encoding, oldname);
idp = get_identifier (newname);
XEXP (rtl, 0) =
gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (idp));
SYMBOL_REF_WEAK (XEXP (rtl, 0)) = DECL_WEAK (decl);
SET_SYMBOL_REF_DECL (XEXP (rtl, 0), decl);
switch (encoding)
{
case 'b':
maxsize = 128;
secname = "based";
break;
case 't':
maxsize = 65536;
secname = "tiny";
break;
case 'n':
maxsize = 0x1000000;
secname = "near";
break;
default:
maxsize = 0;
secname = 0;
break;
}
if (maxsize && int_size_in_bytes (TREE_TYPE (decl)) > maxsize)
{
warning (0, "variable %s (%ld bytes) is too large for the %s section (%d bytes)",
oldname,
(long) int_size_in_bytes (TREE_TYPE (decl)),
secname,
maxsize);
}
}
}
const char *
mep_strip_name_encoding (const char *sym)
{
while (1)
{
if (*sym == '*')
sym++;
else if (*sym == '@' && sym[2] == '.')
sym += 3;
else
return sym;
}
}
static section *
mep_select_section (tree decl, int reloc ATTRIBUTE_UNUSED,
unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
{
int readonly = 1;
int encoding;
switch (TREE_CODE (decl))
{
case VAR_DECL:
if (!TREE_READONLY (decl)
|| TREE_SIDE_EFFECTS (decl)
|| !DECL_INITIAL (decl)
|| (DECL_INITIAL (decl) != error_mark_node
&& !TREE_CONSTANT (DECL_INITIAL (decl))))
readonly = 0;
break;
case CONSTRUCTOR:
if (! TREE_CONSTANT (decl))
readonly = 0;
break;
default:
break;
}
if (TREE_CODE (decl) == FUNCTION_DECL)
{
const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
if (name[0] == '@' && name[2] == '.')
encoding = name[1];
else
encoding = 0;
if (flag_function_sections || DECL_ONE_ONLY (decl))
mep_unique_section (decl, 0);
else if (lookup_attribute ("vliw", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
{
if (encoding == 'f')
return vftext_section;
else
return vtext_section;
}
else if (encoding == 'f')
return ftext_section;
else
return text_section;
}
if (TREE_CODE (decl) == VAR_DECL)
{
const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
if (name[0] == '@' && name[2] == '.')
switch (name[1])
{
case 'b':
return based_section;
case 't':
if (readonly)
return srodata_section;
if (DECL_INITIAL (decl))
return sdata_section;
return tinybss_section;
case 'f':
if (readonly)
return frodata_section;
return far_section;
case 'i':
case 'I':
error_at (DECL_SOURCE_LOCATION (decl),
"variable %D of type %<io%> must be uninitialized", decl);
return data_section;
case 'c':
error_at (DECL_SOURCE_LOCATION (decl),
"variable %D of type %<cb%> must be uninitialized", decl);
return data_section;
}
}
if (readonly)
return readonly_data_section;
return data_section;
}
static void
mep_unique_section (tree decl, int reloc)
{
static const char *prefixes[][2] =
{
{ ".text.", ".gnu.linkonce.t." },
{ ".rodata.", ".gnu.linkonce.r." },
{ ".data.", ".gnu.linkonce.d." },
{ ".based.", ".gnu.linkonce.based." },
{ ".sdata.", ".gnu.linkonce.s." },
{ ".far.", ".gnu.linkonce.far." },
{ ".ftext.", ".gnu.linkonce.ft." },
{ ".frodata.", ".gnu.linkonce.frd." },
{ ".srodata.", ".gnu.linkonce.srd." },
{ ".vtext.", ".gnu.linkonce.v." },
{ ".vftext.", ".gnu.linkonce.vf." }
};
int sec = 2; /* .data */
int len;
const char *name, *prefix;
char *string;
name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
if (DECL_RTL (decl))
name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
if (TREE_CODE (decl) == FUNCTION_DECL)
{
if (lookup_attribute ("vliw", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
sec = 9; /* .vtext */
else
sec = 0; /* .text */
}
else if (decl_readonly_section (decl, reloc))
sec = 1; /* .rodata */
if (name[0] == '@' && name[2] == '.')
{
switch (name[1])
{
case 'b':
sec = 3; /* .based */
break;
case 't':
if (sec == 1)
sec = 8; /* .srodata */
else
sec = 4; /* .sdata */
break;
case 'f':
if (sec == 0)
sec = 6; /* .ftext */
else if (sec == 9)
sec = 10; /* .vftext */
else if (sec == 1)
sec = 7; /* .frodata */
else
sec = 5; /* .far. */
break;
}
name += 3;
}
prefix = prefixes[sec][DECL_ONE_ONLY(decl)];
len = strlen (name) + strlen (prefix);
string = (char *) alloca (len + 1);
sprintf (string, "%s%s", prefix, name);
DECL_SECTION_NAME (decl) = build_string (len, string);
}
/* Given a decl, a section name, and whether the decl initializer
has relocs, choose attributes for the section. */
#define SECTION_MEP_VLIW SECTION_MACH_DEP
static unsigned int
mep_section_type_flags (tree decl, const char *name, int reloc)
{
unsigned int flags = default_section_type_flags (decl, name, reloc);
if (decl && TREE_CODE (decl) == FUNCTION_DECL
&& lookup_attribute ("vliw", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
flags |= SECTION_MEP_VLIW;
return flags;
}
/* Switch to an arbitrary section NAME with attributes as specified
by FLAGS. ALIGN specifies any known alignment requirements for
the section; 0 if the default should be used.
Differs from the standard ELF version only in support of VLIW mode. */
static void
mep_asm_named_section (const char *name, unsigned int flags, tree decl ATTRIBUTE_UNUSED)
{
char flagchars[8], *f = flagchars;
const char *type;
if (!(flags & SECTION_DEBUG))
*f++ = 'a';
if (flags & SECTION_WRITE)
*f++ = 'w';
if (flags & SECTION_CODE)
*f++ = 'x';
if (flags & SECTION_SMALL)
*f++ = 's';
if (flags & SECTION_MEP_VLIW)
*f++ = 'v';
*f = '\0';
if (flags & SECTION_BSS)
type = "nobits";
else
type = "progbits";
fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
name, flagchars, type);
if (flags & SECTION_CODE)
fputs ((flags & SECTION_MEP_VLIW ? "\t.vliw\n" : "\t.core\n"),
asm_out_file);
}
void
mep_output_aligned_common (FILE *stream, tree decl, const char *name,
int size, int align, int global)
{
/* We intentionally don't use mep_section_tag() here. */
if (name[0] == '@'
&& (name[1] == 'i' || name[1] == 'I' || name[1] == 'c')
&& name[2] == '.')
{
int location = -1;
tree attr = lookup_attribute ((name[1] == 'c' ? "cb" : "io"),
DECL_ATTRIBUTES (decl));
if (attr
&& TREE_VALUE (attr)
&& TREE_VALUE (TREE_VALUE(attr)))
location = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE(attr)));
if (location == -1)
return;
if (global)
{
fprintf (stream, "\t.globl\t");
assemble_name (stream, name);
fprintf (stream, "\n");
}
assemble_name (stream, name);
fprintf (stream, " = %d\n", location);
return;
}
if (name[0] == '@' && name[2] == '.')
{
const char *sec = 0;
switch (name[1])
{
case 'b':
switch_to_section (based_section);
sec = ".based";
break;
case 't':
switch_to_section (tinybss_section);
sec = ".sbss";
break;
case 'f':
switch_to_section (farbss_section);
sec = ".farbss";
break;
}
if (sec)
{
const char *name2;
int p2align = 0;
while (align > BITS_PER_UNIT)
{
align /= 2;
p2align ++;
}
name2 = TARGET_STRIP_NAME_ENCODING (name);
if (global)
fprintf (stream, "\t.globl\t%s\n", name2);
fprintf (stream, "\t.p2align %d\n", p2align);
fprintf (stream, "\t.type\t%s,@object\n", name2);
fprintf (stream, "\t.size\t%s,%d\n", name2, size);
fprintf (stream, "%s:\n\t.zero\t%d\n", name2, size);
return;
}
}
if (!global)
{
fprintf (stream, "\t.local\t");
assemble_name (stream, name);
fprintf (stream, "\n");
}
fprintf (stream, "\t.comm\t");
assemble_name (stream, name);
fprintf (stream, ",%u,%u\n", size, align / BITS_PER_UNIT);
}
/* Trampolines. */
static void
mep_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
{
rtx addr = XEXP (m_tramp, 0);
rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__mep_trampoline_helper"),
LCT_NORMAL, VOIDmode, 3,
addr, Pmode,
fnaddr, Pmode,
static_chain, Pmode);
}
/* Experimental Reorg. */
static bool
mep_mentioned_p (rtx in,
rtx reg, /* NULL for mem */
int modes_too) /* if nonzero, modes must match also. */
{
const char *fmt;
int i;
enum rtx_code code;
if (in == 0)
return false;
if (reg && GET_CODE (reg) != REG)
return false;
if (GET_CODE (in) == LABEL_REF)
return (reg == 0);
code = GET_CODE (in);
switch (code)
{
case MEM:
if (reg)
return mep_mentioned_p (XEXP (in, 0), reg, modes_too);
return true;
case REG:
if (!reg)
return false;
if (modes_too && (GET_MODE (in) != GET_MODE (reg)))
return false;
return (REGNO (in) == REGNO (reg));
case SCRATCH:
case CC0:
case PC:
case CONST_INT:
case CONST_DOUBLE:
return false;
default:
break;
}
/* Set's source should be read-only. */
if (code == SET && !reg)
return mep_mentioned_p (SET_DEST (in), reg, modes_too);
fmt = GET_RTX_FORMAT (code);
for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
{
if (fmt[i] == 'E')
{
register int j;
for (j = XVECLEN (in, i) - 1; j >= 0; j--)
if (mep_mentioned_p (XVECEXP (in, i, j), reg, modes_too))
return true;
}
else if (fmt[i] == 'e'
&& mep_mentioned_p (XEXP (in, i), reg, modes_too))
return true;
}
return false;
}
#define EXPERIMENTAL_REGMOVE_REORG 1
#if EXPERIMENTAL_REGMOVE_REORG
static int
mep_compatible_reg_class (int r1, int r2)
{
if (GR_REGNO_P (r1) && GR_REGNO_P (r2))
return 1;
if (CR_REGNO_P (r1) && CR_REGNO_P (r2))
return 1;
return 0;
}
static void
mep_reorg_regmove (rtx insns)
{
rtx insn, next, pat, follow, *where;
int count = 0, done = 0, replace, before = 0;
if (dump_file)
for (insn = insns; insn; insn = NEXT_INSN (insn))
if (GET_CODE (insn) == INSN)
before++;
/* We're looking for (set r2 r1) moves where r1 dies, followed by a
set that uses the r2 and r2 dies there. We replace r2 with r1
and see if it's still a valid insn. If so, delete the first set.
Copied from reorg.c. */
while (!done)
{
done = 1;
for (insn = insns; insn; insn = next)
{
next = NEXT_INSN (insn);
if (GET_CODE (insn) != INSN)
continue;
pat = PATTERN (insn);
replace = 0;
if (GET_CODE (pat) == SET
&& GET_CODE (SET_SRC (pat)) == REG
&& GET_CODE (SET_DEST (pat)) == REG
&& find_regno_note (insn, REG_DEAD, REGNO (SET_SRC (pat)))
&& mep_compatible_reg_class (REGNO (SET_SRC (pat)), REGNO (SET_DEST (pat))))
{
follow = next_nonnote_insn (insn);
if (dump_file)
fprintf (dump_file, "superfluous moves: considering %d\n", INSN_UID (insn));
while (follow && GET_CODE (follow) == INSN
&& GET_CODE (PATTERN (follow)) == SET
&& !dead_or_set_p (follow, SET_SRC (pat))
&& !mep_mentioned_p (PATTERN (follow), SET_SRC (pat), 0)
&& !mep_mentioned_p (PATTERN (follow), SET_DEST (pat), 0))
{
if (dump_file)
fprintf (dump_file, "\tskipping %d\n", INSN_UID (follow));
follow = next_nonnote_insn (follow);
}
if (dump_file)
fprintf (dump_file, "\tfollow is %d\n", INSN_UID (follow));
if (follow && GET_CODE (follow) == INSN
&& GET_CODE (PATTERN (follow)) == SET
&& find_regno_note (follow, REG_DEAD, REGNO (SET_DEST (pat))))
{
if (GET_CODE (SET_DEST (PATTERN (follow))) == REG)
{
if (mep_mentioned_p (SET_SRC (PATTERN (follow)), SET_DEST (pat), 1))
{
replace = 1;
where = & SET_SRC (PATTERN (follow));
}
}
else if (GET_CODE (SET_DEST (PATTERN (follow))) == MEM)
{
if (mep_mentioned_p (PATTERN (follow), SET_DEST (pat), 1))
{
replace = 1;
where = & PATTERN (follow);
}
}
}
}
/* If so, follow is the corresponding insn */
if (replace)
{
if (dump_file)
{
rtx x;
fprintf (dump_file, "----- Candidate for superfluous move deletion:\n\n");
for (x = insn; x ;x = NEXT_INSN (x))
{
print_rtl_single (dump_file, x);
if (x == follow)
break;
fprintf (dump_file, "\n");
}
}
if (validate_replace_rtx_subexp (SET_DEST (pat), SET_SRC (pat),
follow, where))
{
count ++;
next = delete_insn (insn);
if (dump_file)
{
fprintf (dump_file, "\n----- Success! new insn:\n\n");
print_rtl_single (dump_file, follow);
}
done = 0;
}
}
}
}
if (dump_file)
{
fprintf (dump_file, "\n%d insn%s deleted out of %d.\n\n", count, count == 1 ? "" : "s", before);
fprintf (dump_file, "=====\n");
}
}
#endif
/* Figure out where to put LABEL, which is the label for a repeat loop.
If INCLUDING, LAST_INSN is the last instruction in the loop, otherwise
the loop ends just before LAST_INSN. If SHARED, insns other than the
"repeat" might use LABEL to jump to the loop's continuation point.
Return the last instruction in the adjusted loop. */
static rtx
mep_insert_repeat_label_last (rtx last_insn, rtx label, bool including,
bool shared)
{
rtx next, prev;
int count = 0, code, icode;
if (dump_file)
fprintf (dump_file, "considering end of repeat loop at insn %d\n",
INSN_UID (last_insn));
/* Set PREV to the last insn in the loop. */
prev = last_insn;
if (!including)
prev = PREV_INSN (prev);
/* Set NEXT to the next insn after the repeat label. */
next = last_insn;
if (!shared)
while (prev != 0)
{
code = GET_CODE (prev);
if (code == CALL_INSN || code == CODE_LABEL || code == BARRIER)
break;
if (INSN_P (prev))
{
if (GET_CODE (PATTERN (prev)) == SEQUENCE)
prev = XVECEXP (PATTERN (prev), 0, 1);
/* Other insns that should not be in the last two opcodes. */
icode = recog_memoized (prev);
if (icode < 0
|| icode == CODE_FOR_repeat
|| icode == CODE_FOR_erepeat
|| get_attr_may_trap (prev) == MAY_TRAP_YES)
break;
/* That leaves JUMP_INSN and INSN. It will have BImode if it
is the second instruction in a VLIW bundle. In that case,
loop again: if the first instruction also satisfies the
conditions above then we will reach here again and put
both of them into the repeat epilogue. Otherwise both
should remain outside. */
if (GET_MODE (prev) != BImode)
{
count++;
next = prev;
if (dump_file)
print_rtl_single (dump_file, next);
if (count == 2)
break;
}
}
prev = PREV_INSN (prev);
}
/* See if we're adding the label immediately after the repeat insn.
If so, we need to separate them with a nop. */
prev = prev_real_insn (next);
if (prev)
switch (recog_memoized (prev))
{
case CODE_FOR_repeat:
case CODE_FOR_erepeat:
if (dump_file)
fprintf (dump_file, "Adding nop inside loop\n");
emit_insn_before (gen_nop (), next);
break;
default:
break;
}
/* Insert the label. */
emit_label_before (label, next);
/* Insert the nops. */
if (dump_file && count < 2)
fprintf (dump_file, "Adding %d nop%s\n\n",
2 - count, count == 1 ? "" : "s");
for (; count < 2; count++)
if (including)
last_insn = emit_insn_after (gen_nop (), last_insn);
else
emit_insn_before (gen_nop (), last_insn);
return last_insn;
}
void
mep_emit_doloop (rtx *operands, int is_end)
{
rtx tag;
if (cfun->machine->doloop_tags == 0
|| cfun->machine->doloop_tag_from_end == is_end)
{
cfun->machine->doloop_tags++;
cfun->machine->doloop_tag_from_end = is_end;
}
tag = GEN_INT (cfun->machine->doloop_tags - 1);
if (is_end)
emit_jump_insn (gen_doloop_end_internal (operands[0], operands[4], tag));
else
emit_insn (gen_doloop_begin_internal (operands[0], operands[0], tag));
}
/* Code for converting doloop_begins and doloop_ends into valid
MeP instructions. A doloop_begin is just a placeholder:
$count = unspec ($count)
where $count is initially the number of iterations - 1.
doloop_end has the form:
if ($count-- == 0) goto label
The counter variable is private to the doloop insns, nothing else
relies on its value.
There are three cases, in decreasing order of preference:
1. A loop has exactly one doloop_begin and one doloop_end.
The doloop_end branches to the first instruction after
the doloop_begin.
In this case we can replace the doloop_begin with a repeat
instruction and remove the doloop_end. I.e.:
$count1 = unspec ($count1)
label:
...
insn1
insn2
if ($count2-- == 0) goto label
becomes:
repeat $count1,repeat_label
label:
...
repeat_label:
insn1
insn2
# end repeat
2. As for (1), except there are several doloop_ends. One of them
(call it X) falls through to a label L. All the others fall
through to branches to L.
In this case, we remove X and replace the other doloop_ends
with branches to the repeat label. For example:
$count1 = unspec ($count1)
start:
...
if ($count2-- == 0) goto label
end:
...
if ($count3-- == 0) goto label
goto end
becomes:
repeat $count1,repeat_label
start:
...
repeat_label:
nop
nop
# end repeat
end:
...
goto repeat_label
3. The fallback case. Replace doloop_begins with:
$count = $count + 1
Replace doloop_ends with the equivalent of:
$count = $count - 1
if ($count == 0) goto label
Note that this might need a scratch register if $count
is stored in memory. */
/* A structure describing one doloop_begin. */
struct mep_doloop_begin {
/* The next doloop_begin with the same tag. */
struct mep_doloop_begin *next;
/* The instruction itself. */
rtx insn;
/* The initial counter value. This is known to be a general register. */
rtx counter;
};
/* A structure describing a doloop_end. */
struct mep_doloop_end {
/* The next doloop_end with the same loop tag. */
struct mep_doloop_end *next;
/* The instruction itself. */
rtx insn;
/* The first instruction after INSN when the branch isn't taken. */
rtx fallthrough;
/* The location of the counter value. Since doloop_end_internal is a
jump instruction, it has to allow the counter to be stored anywhere
(any non-fixed register or memory location). */
rtx counter;
/* The target label (the place where the insn branches when the counter
isn't zero). */
rtx label;
/* A scratch register. Only available when COUNTER isn't stored
in a general register. */
rtx scratch;
};
/* One do-while loop. */
struct mep_doloop {
/* All the doloop_begins for this loop (in no particular order). */
struct mep_doloop_begin *begin;
/* All the doloop_ends. When there is more than one, arrange things
so that the first one is the most likely to be X in case (2) above. */
struct mep_doloop_end *end;
};
/* Return true if LOOP can be converted into repeat/repeat_end form
(that is, if it matches cases (1) or (2) above). */
static bool
mep_repeat_loop_p (struct mep_doloop *loop)
{
struct mep_doloop_end *end;
rtx fallthrough;
/* There must be exactly one doloop_begin and at least one doloop_end. */
if (loop->begin == 0 || loop->end == 0 || loop->begin->next != 0)
return false;
/* The first doloop_end (X) must branch back to the insn after
the doloop_begin. */
if (prev_real_insn (loop->end->label) != loop->begin->insn)
return false;
/* All the other doloop_ends must branch to the same place as X.
When the branch isn't taken, they must jump to the instruction
after X. */
fallthrough = loop->end->fallthrough;
for (end = loop->end->next; end != 0; end = end->next)
if (end->label != loop->end->label
|| !simplejump_p (end->fallthrough)
|| next_real_insn (JUMP_LABEL (end->fallthrough)) != fallthrough)
return false;
return true;
}
/* The main repeat reorg function. See comment above for details. */
static void
mep_reorg_repeat (rtx insns)
{
rtx insn;
struct mep_doloop *loops, *loop;
struct mep_doloop_begin *begin;
struct mep_doloop_end *end;
/* Quick exit if we haven't created any loops. */
if (cfun->machine->doloop_tags == 0)
return;
/* Create an array of mep_doloop structures. */
loops = (struct mep_doloop *) alloca (sizeof (loops[0]) * cfun->machine->doloop_tags);
memset (loops, 0, sizeof (loops[0]) * cfun->machine->doloop_tags);
/* Search the function for do-while insns and group them by loop tag. */
for (insn = insns; insn; insn = NEXT_INSN (insn))
if (INSN_P (insn))
switch (recog_memoized (insn))
{
case CODE_FOR_doloop_begin_internal:
insn_extract (insn);
loop = &loops[INTVAL (recog_data.operand[2])];
begin = (struct mep_doloop_begin *) alloca (sizeof (struct mep_doloop_begin));
begin->next = loop->begin;
begin->insn = insn;
begin->counter = recog_data.operand[0];
loop->begin = begin;
break;
case CODE_FOR_doloop_end_internal:
insn_extract (insn);
loop = &loops[INTVAL (recog_data.operand[2])];
end = (struct mep_doloop_end *) alloca (sizeof (struct mep_doloop_end));
end->insn = insn;
end->fallthrough = next_real_insn (insn);
end->counter = recog_data.operand[0];
end->label = recog_data.operand[1];
end->scratch = recog_data.operand[3];
/* If this insn falls through to an unconditional jump,
give it a lower priority than the others. */
if (loop->end != 0 && simplejump_p (end->fallthrough))
{
end->next = loop->end->next;
loop->end->next = end;
}
else
{
end->next = loop->end;
loop->end = end;
}
break;
}
/* Convert the insns for each loop in turn. */
for (loop = loops; loop < loops + cfun->machine->doloop_tags; loop++)
if (mep_repeat_loop_p (loop))
{
/* Case (1) or (2). */
rtx repeat_label, label_ref;
/* Create a new label for the repeat insn. */
repeat_label = gen_label_rtx ();
/* Replace the doloop_begin with a repeat. */
label_ref = gen_rtx_LABEL_REF (VOIDmode, repeat_label);
emit_insn_before (gen_repeat (loop->begin->counter, label_ref),
loop->begin->insn);
delete_insn (loop->begin->insn);
/* Insert the repeat label before the first doloop_end.
Fill the gap with nops if there are other doloop_ends. */
mep_insert_repeat_label_last (loop->end->insn, repeat_label,
false, loop->end->next != 0);
/* Emit a repeat_end (to improve the readability of the output). */
emit_insn_before (gen_repeat_end (), loop->end->insn);
/* Delete the first doloop_end. */
delete_insn (loop->end->insn);
/* Replace the others with branches to REPEAT_LABEL. */
for (end = loop->end->next; end != 0; end = end->next)
{
emit_jump_insn_before (gen_jump (repeat_label), end->insn);
delete_insn (end->insn);
delete_insn (end->fallthrough);
}
}
else
{
/* Case (3). First replace all the doloop_begins with increment
instructions. */
for (begin = loop->begin; begin != 0; begin = begin->next)
{
emit_insn_before (gen_add3_insn (copy_rtx (begin->counter),
begin->counter, const1_rtx),
begin->insn);
delete_insn (begin->insn);
}
/* Replace all the doloop_ends with decrement-and-branch sequences. */
for (end = loop->end; end != 0; end = end->next)
{
rtx reg;
start_sequence ();
/* Load the counter value into a general register. */
reg = end->counter;
if (!REG_P (reg) || REGNO (reg) > 15)
{
reg = end->scratch;
emit_move_insn (copy_rtx (reg), copy_rtx (end->counter));
}
/* Decrement the counter. */
emit_insn (gen_add3_insn (copy_rtx (reg), copy_rtx (reg),
constm1_rtx));
/* Copy it back to its original location. */
if (reg != end->counter)
emit_move_insn (copy_rtx (end->counter), copy_rtx (reg));
/* Jump back to the start label. */
insn = emit_jump_insn (gen_mep_bne_true (reg, const0_rtx,
end->label));
JUMP_LABEL (insn) = end->label;
LABEL_NUSES (end->label)++;
/* Emit the whole sequence before the doloop_end. */
insn = get_insns ();
end_sequence ();
emit_insn_before (insn, end->insn);
/* Delete the doloop_end. */
delete_insn (end->insn);
}
}
}
static bool
mep_invertable_branch_p (rtx insn)
{
rtx cond, set;
enum rtx_code old_code;
int i;
set = PATTERN (insn);
if (GET_CODE (set) != SET)
return false;
if (GET_CODE (XEXP (set, 1)) != IF_THEN_ELSE)
return false;
cond = XEXP (XEXP (set, 1), 0);
old_code = GET_CODE (cond);
switch (old_code)
{
case EQ:
PUT_CODE (cond, NE);
break;
case NE:
PUT_CODE (cond, EQ);
break;
case LT:
PUT_CODE (cond, GE);
break;
case GE:
PUT_CODE (cond, LT);
break;
default:
return false;
}
INSN_CODE (insn) = -1;
i = recog_memoized (insn);
PUT_CODE (cond, old_code);
INSN_CODE (insn) = -1;
return i >= 0;
}
static void
mep_invert_branch (rtx insn, rtx after)
{
rtx cond, set, label;
int i;
set = PATTERN (insn);
gcc_assert (GET_CODE (set) == SET);
gcc_assert (GET_CODE (XEXP (set, 1)) == IF_THEN_ELSE);
cond = XEXP (XEXP (set, 1), 0);
switch (GET_CODE (cond))
{
case EQ:
PUT_CODE (cond, NE);
break;
case NE:
PUT_CODE (cond, EQ);
break;
case LT:
PUT_CODE (cond, GE);
break;
case GE:
PUT_CODE (cond, LT);
break;
default:
gcc_unreachable ();
}
label = gen_label_rtx ();
emit_label_after (label, after);
for (i=1; i<=2; i++)
if (GET_CODE (XEXP (XEXP (set, 1), i)) == LABEL_REF)
{
rtx ref = XEXP (XEXP (set, 1), i);
if (LABEL_NUSES (XEXP (ref, 0)) == 1)
delete_insn (XEXP (ref, 0));
XEXP (ref, 0) = label;
LABEL_NUSES (label) ++;
JUMP_LABEL (insn) = label;
}
INSN_CODE (insn) = -1;
i = recog_memoized (insn);
gcc_assert (i >= 0);
}
static void
mep_reorg_erepeat (rtx insns)
{
rtx insn, prev, label_before, l, x;
int count;
for (insn = insns; insn; insn = NEXT_INSN (insn))
if (JUMP_P (insn)
&& ! JUMP_TABLE_DATA_P (insn)
&& mep_invertable_branch_p (insn))
{
if (dump_file)
{
fprintf (dump_file, "\n------------------------------\n");
fprintf (dump_file, "erepeat: considering this jump:\n");
print_rtl_single (dump_file, insn);
}
count = simplejump_p (insn) ? 0 : 1;
label_before = 0;
for (prev = PREV_INSN (insn); prev; prev = PREV_INSN (prev))
{
if (GET_CODE (prev) == CALL_INSN
|| BARRIER_P (prev))
break;
if (prev == JUMP_LABEL (insn))
{
rtx newlast;
if (dump_file)
fprintf (dump_file, "found loop top, %d insns\n", count);
if (LABEL_NUSES (prev) == 1)
/* We're the only user, always safe */ ;
else if (LABEL_NUSES (prev) == 2)
{
/* See if there's a barrier before this label. If
so, we know nobody inside the loop uses it.
But we must be careful to put the erepeat
*after* the label. */
rtx barrier;
for (barrier = PREV_INSN (prev);
barrier && GET_CODE (barrier) == NOTE;
barrier = PREV_INSN (barrier))
;
if (barrier && GET_CODE (barrier) != BARRIER)
break;
}
else
{
/* We don't know who else, within or without our loop, uses this */
if (dump_file)
fprintf (dump_file, "... but there are multiple users, too risky.\n");
break;
}
/* Generate a label to be used by the erepat insn. */
l = gen_label_rtx ();
/* Insert the erepeat after INSN's target label. */
x = gen_erepeat (gen_rtx_LABEL_REF (VOIDmode, l));
LABEL_NUSES (l)++;
emit_insn_after (x, prev);
/* Insert the erepeat label. */
newlast = (mep_insert_repeat_label_last
(insn, l, !simplejump_p (insn), false));
if (simplejump_p (insn))
{
emit_insn_before (gen_erepeat_end (), insn);
delete_insn (insn);
}
else
{
mep_invert_branch (insn, newlast);
emit_insn_after (gen_erepeat_end (), newlast);
}
break;
}
if (LABEL_P (prev))
{
/* A label is OK if there is exactly one user, and we
can find that user before the next label. */
rtx user = 0;
int safe = 0;
if (LABEL_NUSES (prev) == 1)
{
for (user = PREV_INSN (prev);
user && (INSN_P (user) || GET_CODE (user) == NOTE);
user = PREV_INSN (user))
if (GET_CODE (user) == JUMP_INSN
&& JUMP_LABEL (user) == prev)
{
safe = INSN_UID (user);
break;
}
}
if (!safe)
break;
if (dump_file)
fprintf (dump_file, "... ignoring jump from insn %d to %d\n",
safe, INSN_UID (prev));
}
if (INSN_P (prev))
{
count ++;
if (count == 2)
label_before = prev;
}
}
}
if (dump_file)
fprintf (dump_file, "\n==============================\n");
}
/* Replace a jump to a return, with a copy of the return. GCC doesn't
always do this on its own. */
static void
mep_jmp_return_reorg (rtx insns)
{
rtx insn, label, ret;
int ret_code;
for (insn = insns; insn; insn = NEXT_INSN (insn))
if (simplejump_p (insn))
{
/* Find the fist real insn the jump jumps to. */
label = ret = JUMP_LABEL (insn);
while (ret
&& (GET_CODE (ret) == NOTE
|| GET_CODE (ret) == CODE_LABEL
|| GET_CODE (PATTERN (ret)) == USE))
ret = NEXT_INSN (ret);
if (ret)
{
/* Is it a return? */
ret_code = recog_memoized (ret);
if (ret_code == CODE_FOR_return_internal
|| ret_code == CODE_FOR_eh_return_internal)
{
/* It is. Replace the jump with a return. */
LABEL_NUSES (label) --;
if (LABEL_NUSES (label) == 0)
delete_insn (label);
PATTERN (insn) = copy_rtx (PATTERN (ret));
INSN_CODE (insn) = -1;
}
}
}
}
static void
mep_reorg_addcombine (rtx insns)
{
rtx i, n;
for (i = insns; i; i = NEXT_INSN (i))
if (INSN_P (i)
&& INSN_CODE (i) == CODE_FOR_addsi3
&& GET_CODE (SET_DEST (PATTERN (i))) == REG
&& GET_CODE (XEXP (SET_SRC (PATTERN (i)), 0)) == REG
&& REGNO (SET_DEST (PATTERN (i))) == REGNO (XEXP (SET_SRC (PATTERN (i)), 0))
&& GET_CODE (XEXP (SET_SRC (PATTERN (i)), 1)) == CONST_INT)
{
n = NEXT_INSN (i);
if (INSN_P (n)
&& INSN_CODE (n) == CODE_FOR_addsi3
&& GET_CODE (SET_DEST (PATTERN (n))) == REG
&& GET_CODE (XEXP (SET_SRC (PATTERN (n)), 0)) == REG
&& REGNO (SET_DEST (PATTERN (n))) == REGNO (XEXP (SET_SRC (PATTERN (n)), 0))
&& GET_CODE (XEXP (SET_SRC (PATTERN (n)), 1)) == CONST_INT)
{
int ic = INTVAL (XEXP (SET_SRC (PATTERN (i)), 1));
int nc = INTVAL (XEXP (SET_SRC (PATTERN (n)), 1));
if (REGNO (SET_DEST (PATTERN (i))) == REGNO (SET_DEST (PATTERN (n)))
&& ic + nc < 32767
&& ic + nc > -32768)
{
XEXP (SET_SRC (PATTERN (i)), 1) = GEN_INT (ic + nc);
NEXT_INSN (i) = NEXT_INSN (n);
if (NEXT_INSN (i))
PREV_INSN (NEXT_INSN (i)) = i;
}
}
}
}
/* If this insn adjusts the stack, return the adjustment, else return
zero. */
static int
add_sp_insn_p (rtx insn)
{
rtx pat;
if (! single_set (insn))
return 0;
pat = PATTERN (insn);
if (GET_CODE (SET_DEST (pat)) != REG)
return 0;
if (REGNO (SET_DEST (pat)) != SP_REGNO)
return 0;
if (GET_CODE (SET_SRC (pat)) != PLUS)
return 0;
if (GET_CODE (XEXP (SET_SRC (pat), 0)) != REG)
return 0;
if (REGNO (XEXP (SET_SRC (pat), 0)) != SP_REGNO)
return 0;
if (GET_CODE (XEXP (SET_SRC (pat), 1)) != CONST_INT)
return 0;
return INTVAL (XEXP (SET_SRC (pat), 1));
}
/* Check for trivial functions that set up an unneeded stack
frame. */
static void
mep_reorg_noframe (rtx insns)
{
rtx start_frame_insn;
rtx end_frame_insn = 0;
int sp_adjust, sp2;
rtx sp;
/* The first insn should be $sp = $sp + N */
while (insns && ! INSN_P (insns))
insns = NEXT_INSN (insns);
if (!insns)
return;
sp_adjust = add_sp_insn_p (insns);
if (sp_adjust == 0)
return;
start_frame_insn = insns;
sp = SET_DEST (PATTERN (start_frame_insn));
insns = next_real_insn (insns);
while (insns)
{
rtx next = next_real_insn (insns);
if (!next)
break;
sp2 = add_sp_insn_p (insns);
if (sp2)
{
if (end_frame_insn)
return;
end_frame_insn = insns;
if (sp2 != -sp_adjust)
return;
}
else if (mep_mentioned_p (insns, sp, 0))
return;
else if (CALL_P (insns))
return;
insns = next;
}
if (end_frame_insn)
{
delete_insn (start_frame_insn);
delete_insn (end_frame_insn);
}
}
static void
mep_reorg (void)
{
rtx insns = get_insns ();
/* We require accurate REG_DEAD notes. */
compute_bb_for_insn ();
df_note_add_problem ();
df_analyze ();
mep_reorg_addcombine (insns);
#if EXPERIMENTAL_REGMOVE_REORG
/* VLIW packing has been done already, so we can't just delete things. */
if (!mep_vliw_function_p (cfun->decl))
mep_reorg_regmove (insns);
#endif
mep_jmp_return_reorg (insns);
mep_bundle_insns (insns);
mep_reorg_repeat (insns);
if (optimize
&& !profile_flag
&& !profile_arc_flag
&& TARGET_OPT_REPEAT
&& (!mep_interrupt_p () || mep_interrupt_saved_reg (RPB_REGNO)))
mep_reorg_erepeat (insns);
/* This may delete *insns so make sure it's last. */
mep_reorg_noframe (insns);
df_finish_pass (false);
}
/*----------------------------------------------------------------------*/
/* Builtins */
/*----------------------------------------------------------------------*/
/* Element X gives the index into cgen_insns[] of the most general
implementation of intrinsic X. Unimplemented intrinsics are
mapped to -1. */
int mep_intrinsic_insn[ARRAY_SIZE (cgen_intrinsics)];
/* Element X gives the index of another instruction that is mapped to
the same intrinsic as cgen_insns[X]. It is -1 when there is no other
instruction.
Things are set up so that mep_intrinsic_chain[X] < X. */
static int mep_intrinsic_chain[ARRAY_SIZE (cgen_insns)];
/* The bitmask for the current ISA. The ISA masks are declared
in mep-intrin.h. */
unsigned int mep_selected_isa;
struct mep_config {
const char *config_name;
unsigned int isa;
};
static struct mep_config mep_configs[] = {
#ifdef COPROC_SELECTION_TABLE
COPROC_SELECTION_TABLE,
#endif
{ 0, 0 }
};
/* Initialize the global intrinsics variables above. */
static void
mep_init_intrinsics (void)
{
size_t i;
/* Set MEP_SELECTED_ISA to the ISA flag for this configuration. */
mep_selected_isa = mep_configs[0].isa;
if (mep_config_string != 0)
for (i = 0; mep_configs[i].config_name; i++)
if (strcmp (mep_config_string, mep_configs[i].config_name) == 0)
{
mep_selected_isa = mep_configs[i].isa;
break;
}
/* Assume all intrinsics are unavailable. */
for (i = 0; i < ARRAY_SIZE (mep_intrinsic_insn); i++)
mep_intrinsic_insn[i] = -1;
/* Build up the global intrinsic tables. */
for (i = 0; i < ARRAY_SIZE (cgen_insns); i++)
if ((cgen_insns[i].isas & mep_selected_isa) != 0)
{
mep_intrinsic_chain[i] = mep_intrinsic_insn[cgen_insns[i].intrinsic];
mep_intrinsic_insn[cgen_insns[i].intrinsic] = i;
}
/* See whether we can directly move values between one coprocessor
register and another. */
for (i = 0; i < ARRAY_SIZE (mep_cmov_insns); i++)
if (MEP_INTRINSIC_AVAILABLE_P (mep_cmov_insns[i]))
mep_have_copro_copro_moves_p = true;
/* See whether we can directly move values between core and
coprocessor registers. */
mep_have_core_copro_moves_p = (MEP_INTRINSIC_AVAILABLE_P (mep_cmov1)
&& MEP_INTRINSIC_AVAILABLE_P (mep_cmov2));
mep_have_core_copro_moves_p = 1;
}
/* Declare all available intrinsic functions. Called once only. */
static tree cp_data_bus_int_type_node;
static tree opaque_vector_type_node;
static tree v8qi_type_node;
static tree v4hi_type_node;
static tree v2si_type_node;
static tree v8uqi_type_node;
static tree v4uhi_type_node;
static tree v2usi_type_node;
static tree
mep_cgen_regnum_to_type (enum cgen_regnum_operand_type cr)
{
switch (cr)
{
case cgen_regnum_operand_type_POINTER: return ptr_type_node;
case cgen_regnum_operand_type_LONG: return long_integer_type_node;
case cgen_regnum_operand_type_ULONG: return long_unsigned_type_node;
case cgen_regnum_operand_type_SHORT: return short_integer_type_node;
case cgen_regnum_operand_type_USHORT: return short_unsigned_type_node;
case cgen_regnum_operand_type_CHAR: return char_type_node;
case cgen_regnum_operand_type_UCHAR: return unsigned_char_type_node;
case cgen_regnum_operand_type_SI: return intSI_type_node;
case cgen_regnum_operand_type_DI: return intDI_type_node;
case cgen_regnum_operand_type_VECTOR: return opaque_vector_type_node;
case cgen_regnum_operand_type_V8QI: return v8qi_type_node;
case cgen_regnum_operand_type_V4HI: return v4hi_type_node;
case cgen_regnum_operand_type_V2SI: return v2si_type_node;
case cgen_regnum_operand_type_V8UQI: return v8uqi_type_node;
case cgen_regnum_operand_type_V4UHI: return v4uhi_type_node;
case cgen_regnum_operand_type_V2USI: return v2usi_type_node;
case cgen_regnum_operand_type_CP_DATA_BUS_INT: return cp_data_bus_int_type_node;
default:
return void_type_node;
}
}
static void
mep_init_builtins (void)
{
size_t i;
if (TARGET_64BIT_CR_REGS)
cp_data_bus_int_type_node = long_long_integer_type_node;
else
cp_data_bus_int_type_node = long_integer_type_node;
opaque_vector_type_node = build_opaque_vector_type (intQI_type_node, 8);
v8qi_type_node = build_vector_type (intQI_type_node, 8);
v4hi_type_node = build_vector_type (intHI_type_node, 4);
v2si_type_node = build_vector_type (intSI_type_node, 2);
v8uqi_type_node = build_vector_type (unsigned_intQI_type_node, 8);
v4uhi_type_node = build_vector_type (unsigned_intHI_type_node, 4);
v2usi_type_node = build_vector_type (unsigned_intSI_type_node, 2);
(*lang_hooks.decls.pushdecl)
(build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("cp_data_bus_int"),
cp_data_bus_int_type_node));
(*lang_hooks.decls.pushdecl)
(build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("cp_vector"),
opaque_vector_type_node));
(*lang_hooks.decls.pushdecl)
(build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("cp_v8qi"),
v8qi_type_node));
(*lang_hooks.decls.pushdecl)
(build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("cp_v4hi"),
v4hi_type_node));
(*lang_hooks.decls.pushdecl)
(build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("cp_v2si"),
v2si_type_node));
(*lang_hooks.decls.pushdecl)
(build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("cp_v8uqi"),
v8uqi_type_node));
(*lang_hooks.decls.pushdecl)
(build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("cp_v4uhi"),
v4uhi_type_node));
(*lang_hooks.decls.pushdecl)
(build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("cp_v2usi"),
v2usi_type_node));
/* Intrinsics like mep_cadd3 are implemented with two groups of
instructions, one which uses UNSPECs and one which uses a specific
rtl code such as PLUS. Instructions in the latter group belong
to GROUP_KNOWN_CODE.
In such cases, the intrinsic will have two entries in the global
tables above. The unspec form is accessed using builtin functions
while the specific form is accessed using the mep_* enum in
mep-intrin.h.
The idea is that __cop arithmetic and builtin functions have
different optimization requirements. If mep_cadd3() appears in
the source code, the user will surely except gcc to use cadd3
rather than a work-alike such as add3. However, if the user
just writes "a + b", where a or b are __cop variables, it is
reasonable for gcc to choose a core instruction rather than
cadd3 if it believes that is more optimal. */
for (i = 0; i < ARRAY_SIZE (cgen_insns); i++)
if ((cgen_insns[i].groups & GROUP_KNOWN_CODE) == 0
&& mep_intrinsic_insn[cgen_insns[i].intrinsic] >= 0)
{
tree ret_type = void_type_node;
tree bi_type;
if (i > 0 && cgen_insns[i].intrinsic == cgen_insns[i-1].intrinsic)
continue;
if (cgen_insns[i].cret_p)
ret_type = mep_cgen_regnum_to_type (cgen_insns[i].regnums[0].type);
bi_type = build_function_type (ret_type, 0);
add_builtin_function (cgen_intrinsics[cgen_insns[i].intrinsic],
bi_type,
cgen_insns[i].intrinsic, BUILT_IN_MD, NULL, NULL);
}
}
/* Report the unavailablity of the given intrinsic. */
#if 1
static void
mep_intrinsic_unavailable (int intrinsic)
{
static int already_reported_p[ARRAY_SIZE (cgen_intrinsics)];
if (already_reported_p[intrinsic])
return;
if (mep_intrinsic_insn[intrinsic] < 0)
error ("coprocessor intrinsic %qs is not available in this configuration",
cgen_intrinsics[intrinsic]);
else if (CGEN_CURRENT_GROUP == GROUP_VLIW)
error ("%qs is not available in VLIW functions",
cgen_intrinsics[intrinsic]);
else
error ("%qs is not available in non-VLIW functions",
cgen_intrinsics[intrinsic]);
already_reported_p[intrinsic] = 1;
}
#endif
/* See if any implementation of INTRINSIC is available to the
current function. If so, store the most general implementation
in *INSN_PTR and return true. Return false otherwise. */
static bool
mep_get_intrinsic_insn (int intrinsic ATTRIBUTE_UNUSED, const struct cgen_insn **insn_ptr ATTRIBUTE_UNUSED)
{
int i;
i = mep_intrinsic_insn[intrinsic];
while (i >= 0 && !CGEN_ENABLE_INSN_P (i))
i = mep_intrinsic_chain[i];
if (i >= 0)
{
*insn_ptr = &cgen_insns[i];
return true;
}
return false;
}
/* Like mep_get_intrinsic_insn, but with extra handling for moves.
If INTRINSIC is mep_cmov, but there is no pure CR <- CR move insn,
try using a work-alike instead. In this case, the returned insn
may have three operands rather than two. */
static bool
mep_get_move_insn (int intrinsic, const struct cgen_insn **cgen_insn)
{
size_t i;
if (intrinsic == mep_cmov)
{
for (i = 0; i < ARRAY_SIZE (mep_cmov_insns); i++)
if (mep_get_intrinsic_insn (mep_cmov_insns[i], cgen_insn))
return true;
return false;
}
return mep_get_intrinsic_insn (intrinsic, cgen_insn);
}
/* If ARG is a register operand that is the same size as MODE, convert it
to MODE using a subreg. Otherwise return ARG as-is. */
static rtx
mep_convert_arg (enum machine_mode mode, rtx arg)
{
if (GET_MODE (arg) != mode
&& register_operand (arg, VOIDmode)
&& GET_MODE_SIZE (GET_MODE (arg)) == GET_MODE_SIZE (mode))
return simplify_gen_subreg (mode, arg, GET_MODE (arg), 0);
return arg;
}
/* Apply regnum conversions to ARG using the description given by REGNUM.
Return the new argument on success and null on failure. */
static rtx
mep_convert_regnum (const struct cgen_regnum_operand *regnum, rtx arg)
{
if (regnum->count == 0)
return arg;
if (GET_CODE (arg) != CONST_INT
|| INTVAL (arg) < 0
|| INTVAL (arg) >= regnum->count)
return 0;
return gen_rtx_REG (SImode, INTVAL (arg) + regnum->base);
}
/* Try to make intrinsic argument ARG match the given operand.
UNSIGNED_P is true if the argument has an unsigned type. */
static rtx
mep_legitimize_arg (const struct insn_operand_data *operand, rtx arg,
int unsigned_p)
{
if (GET_CODE (arg) == CONST_INT)
{
/* CONST_INTs can only be bound to integer operands. */
if (GET_MODE_CLASS (operand->mode) != MODE_INT)
return 0;
}
else if (GET_CODE (arg) == CONST_DOUBLE)
/* These hold vector constants. */;
else if (GET_MODE_SIZE (GET_MODE (arg)) != GET_MODE_SIZE (operand->mode))
{
/* If the argument is a different size from what's expected, we must
have a value in the right mode class in order to convert it. */
if (GET_MODE_CLASS (operand->mode) != GET_MODE_CLASS (GET_MODE (arg)))
return 0;
/* If the operand is an rvalue, promote or demote it to match the
operand's size. This might not need extra instructions when
ARG is a register value. */
if (operand->constraint[0] != '=')
arg = convert_to_mode (operand->mode, arg, unsigned_p);
}
/* If the operand is an lvalue, bind the operand to a new register.
The caller will copy this value into ARG after the main
instruction. By doing this always, we produce slightly more
optimal code. */
/* But not for control registers. */
if (operand->constraint[0] == '='
&& (! REG_P (arg)
|| ! (CONTROL_REGNO_P (REGNO (arg))
|| CCR_REGNO_P (REGNO (arg))
|| CR_REGNO_P (REGNO (arg)))
))
return gen_reg_rtx (operand->mode);
/* Try simple mode punning. */
arg = mep_convert_arg (operand->mode, arg);
if (operand->predicate (arg, operand->mode))
return arg;
/* See if forcing the argument into a register will make it match. */
if (GET_CODE (arg) == CONST_INT || GET_CODE (arg) == CONST_DOUBLE)
arg = force_reg (operand->mode, arg);
else
arg = mep_convert_arg (operand->mode, force_reg (GET_MODE (arg), arg));
if (operand->predicate (arg, operand->mode))
return arg;
return 0;
}
/* Report that ARG cannot be passed to argument ARGNUM of intrinsic
function FNNAME. OPERAND describes the operand to which ARGNUM
is mapped. */
static void
mep_incompatible_arg (const struct insn_operand_data *operand, rtx arg,
int argnum, tree fnname)
{
size_t i;
if (GET_CODE (arg) == CONST_INT)
for (i = 0; i < ARRAY_SIZE (cgen_immediate_predicates); i++)
if (operand->predicate == cgen_immediate_predicates[i].predicate)
{
const struct cgen_immediate_predicate *predicate;
HOST_WIDE_INT argval;
predicate = &cgen_immediate_predicates[i];
argval = INTVAL (arg);
if (argval < predicate->lower || argval >= predicate->upper)
error ("argument %d of %qE must be in the range %d...%d",
argnum, fnname, predicate->lower, predicate->upper - 1);
else
error ("argument %d of %qE must be a multiple of %d",
argnum, fnname, predicate->align);
return;
}
error ("incompatible type for argument %d of %qE", argnum, fnname);
}
static rtx
mep_expand_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
rtx subtarget ATTRIBUTE_UNUSED,
enum machine_mode mode ATTRIBUTE_UNUSED,
int ignore ATTRIBUTE_UNUSED)
{
rtx pat, op[10], arg[10];
unsigned int a;
int opindex, unsigned_p[10];
tree fndecl, args;
unsigned int n_args;
tree fnname;
const struct cgen_insn *cgen_insn;
const struct insn_data_d *idata;
unsigned int first_arg = 0;
tree return_type = void_type_node;
unsigned int builtin_n_args;
fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
fnname = DECL_NAME (fndecl);
/* Find out which instruction we should emit. Note that some coprocessor
intrinsics may only be available in VLIW mode, or only in normal mode. */
if (!mep_get_intrinsic_insn (DECL_FUNCTION_CODE (fndecl), &cgen_insn))
{
mep_intrinsic_unavailable (DECL_FUNCTION_CODE (fndecl));
return NULL_RTX;
}
idata = &insn_data[cgen_insn->icode];
builtin_n_args = cgen_insn->num_args;
if (cgen_insn->cret_p)
{
if (cgen_insn->cret_p > 1)
builtin_n_args ++;
first_arg = 1;
return_type = mep_cgen_regnum_to_type (cgen_insn->regnums[0].type);
builtin_n_args --;
}
/* Evaluate each argument. */
n_args = call_expr_nargs (exp);
if (n_args < builtin_n_args)
{
error ("too few arguments to %qE", fnname);
return NULL_RTX;
}
if (n_args > builtin_n_args)
{
error ("too many arguments to %qE", fnname);
return NULL_RTX;
}
for (a = first_arg; a < builtin_n_args + first_arg; a++)
{
tree value;
args = CALL_EXPR_ARG (exp, a - first_arg);
value = args;
#if 0
if (cgen_insn->regnums[a].reference_p)
{
if (TREE_CODE (value) != ADDR_EXPR)
{
debug_tree(value);
error ("argument %d of %qE must be an address", a+1, fnname);
return NULL_RTX;
}
value = TREE_OPERAND (value, 0);
}
#endif
/* If the argument has been promoted to int, get the unpromoted
value. This is necessary when sub-int memory values are bound
to reference parameters. */
if (TREE_CODE (value) == NOP_EXPR
&& TREE_TYPE (value) == integer_type_node
&& INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
&& (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))
< TYPE_PRECISION (TREE_TYPE (value))))
value = TREE_OPERAND (value, 0);
/* If the argument has been promoted to double, get the unpromoted
SFmode value. This is necessary for FMAX support, for example. */
if (TREE_CODE (value) == NOP_EXPR
&& SCALAR_FLOAT_TYPE_P (TREE_TYPE (value))
&& SCALAR_FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
&& TYPE_MODE (TREE_TYPE (value)) == DFmode
&& TYPE_MODE (TREE_TYPE (TREE_OPERAND (value, 0))) == SFmode)
value = TREE_OPERAND (value, 0);
unsigned_p[a] = TYPE_UNSIGNED (TREE_TYPE (value));
arg[a] = expand_expr (value, NULL, VOIDmode, EXPAND_NORMAL);
arg[a] = mep_convert_regnum (&cgen_insn->regnums[a], arg[a]);
if (cgen_insn->regnums[a].reference_p)
{
tree pointed_to = TREE_TYPE (TREE_TYPE (value));
enum machine_mode pointed_mode = TYPE_MODE (pointed_to);
arg[a] = gen_rtx_MEM (pointed_mode, arg[a]);
}
if (arg[a] == 0)
{
error ("argument %d of %qE must be in the range %d...%d",
a + 1, fnname, 0, cgen_insn->regnums[a].count - 1);
return NULL_RTX;
}
}
for (a = 0; a < first_arg; a++)
{
if (a == 0 && target && GET_MODE (target) == idata->operand[0].mode)
arg[a] = target;
else
arg[a] = gen_reg_rtx (idata->operand[0].mode);
}
/* Convert the arguments into a form suitable for the intrinsic.
Report an error if this isn't possible. */
for (opindex = 0; opindex < idata->n_operands; opindex++)
{
a = cgen_insn->op_mapping[opindex];
op[opindex] = mep_legitimize_arg (&idata->operand[opindex],
arg[a], unsigned_p[a]);
if (op[opindex] == 0)
{
mep_incompatible_arg (&idata->operand[opindex],
arg[a], a + 1 - first_arg, fnname);
return NULL_RTX;
}
}
/* Emit the instruction. */
pat = idata->genfun (op[0], op[1], op[2], op[3], op[4],
op[5], op[6], op[7], op[8], op[9]);
if (GET_CODE (pat) == SET
&& GET_CODE (SET_DEST (pat)) == PC
&& GET_CODE (SET_SRC (pat)) == IF_THEN_ELSE)
emit_jump_insn (pat);
else
emit_insn (pat);
/* Copy lvalues back to their final locations. */
for (opindex = 0; opindex < idata->n_operands; opindex++)
if (idata->operand[opindex].constraint[0] == '=')
{
a = cgen_insn->op_mapping[opindex];
if (a >= first_arg)
{
if (GET_MODE_CLASS (GET_MODE (arg[a]))
!= GET_MODE_CLASS (GET_MODE (op[opindex])))
emit_move_insn (arg[a], gen_lowpart (GET_MODE (arg[a]),
op[opindex]));
else
{
/* First convert the operand to the right mode, then copy it
into the destination. Doing the conversion as a separate
step (rather than using convert_move) means that we can
avoid creating no-op moves when ARG[A] and OP[OPINDEX]
refer to the same register. */
op[opindex] = convert_to_mode (GET_MODE (arg[a]),
op[opindex], unsigned_p[a]);
if (!rtx_equal_p (arg[a], op[opindex]))
emit_move_insn (arg[a], op[opindex]);
}
}
}
if (first_arg > 0 && target && target != op[0])
{
emit_move_insn (target, op[0]);
}
return target;
}
static bool
mep_vector_mode_supported_p (enum machine_mode mode ATTRIBUTE_UNUSED)
{
return false;
}
/* A subroutine of global_reg_mentioned_p, returns 1 if *LOC mentions
a global register. */
static int
global_reg_mentioned_p_1 (rtx *loc, void *data ATTRIBUTE_UNUSED)
{
int regno;
rtx x = *loc;
if (! x)
return 0;
switch (GET_CODE (x))
{
case SUBREG:
if (REG_P (SUBREG_REG (x)))
{
if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER
&& global_regs[subreg_regno (x)])
return 1;
return 0;
}
break;
case REG:
regno = REGNO (x);
if (regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
return 1;
return 0;
case SCRATCH:
case PC:
case CC0:
case CONST_INT:
case CONST_DOUBLE:
case CONST:
case LABEL_REF:
return 0;
case CALL:
/* A non-constant call might use a global register. */
return 1;
default:
break;
}
return 0;
}
/* Returns nonzero if X mentions a global register. */
static int
global_reg_mentioned_p (rtx x)
{
if (INSN_P (x))
{
if (CALL_P (x))
{
if (! RTL_CONST_OR_PURE_CALL_P (x))
return 1;
x = CALL_INSN_FUNCTION_USAGE (x);
if (x == 0)
return 0;
}
else
x = PATTERN (x);
}
return for_each_rtx (&x, global_reg_mentioned_p_1, NULL);
}
/* Scheduling hooks for VLIW mode.
Conceptually this is very simple: we have a two-pack architecture
that takes one core insn and one coprocessor insn to make up either
a 32- or 64-bit instruction word (depending on the option bit set in
the chip). I.e. in VL32 mode, we can pack one 16-bit core insn and
one 16-bit cop insn; in VL64 mode we can pack one 16-bit core insn
and one 48-bit cop insn or two 32-bit core/cop insns.
In practice, instruction selection will be a bear. Consider in
VL64 mode the following insns
add $1, 1
cmov $cr0, $0
these cannot pack, since the add is a 16-bit core insn and cmov
is a 32-bit cop insn. However,
add3 $1, $1, 1
cmov $cr0, $0
packs just fine. For good VLIW code generation in VL64 mode, we
will have to have 32-bit alternatives for many of the common core
insns. Not implemented. */
static int
mep_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
{
int cost_specified;
if (REG_NOTE_KIND (link) != 0)
{
/* See whether INSN and DEP_INSN are intrinsics that set the same
hard register. If so, it is more important to free up DEP_INSN
than it is to free up INSN.
Note that intrinsics like mep_mulr are handled differently from
the equivalent mep.md patterns. In mep.md, if we don't care
about the value of $lo and $hi, the pattern will just clobber
the registers, not set them. Since clobbers don't count as
output dependencies, it is often possible to reorder two mulrs,
even after reload.
In contrast, mep_mulr() sets both $lo and $hi to specific values,
so any pair of mep_mulr()s will be inter-dependent. We should
therefore give the first mep_mulr() a higher priority. */
if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT
&& global_reg_mentioned_p (PATTERN (insn))
&& global_reg_mentioned_p (PATTERN (dep_insn)))
return 1;
/* If the dependence is an anti or output dependence, assume it
has no cost. */
return 0;
}
/* If we can't recognize the insns, we can't really do anything. */
if (recog_memoized (dep_insn) < 0)
return cost;
/* The latency attribute doesn't apply to MeP-h1: we use the stall
attribute instead. */
if (!TARGET_H1)
{
cost_specified = get_attr_latency (dep_insn);
if (cost_specified != 0)
return cost_specified;
}
return cost;
}
/* ??? We don't properly compute the length of a load/store insn,
taking into account the addressing mode. */
static int
mep_issue_rate (void)
{
return TARGET_IVC2 ? 3 : 2;
}
/* Return true if function DECL was declared with the vliw attribute. */
bool
mep_vliw_function_p (tree decl)
{
return lookup_attribute ("vliw", TYPE_ATTRIBUTES (TREE_TYPE (decl))) != 0;
}
static rtx
mep_find_ready_insn (rtx *ready, int nready, enum attr_slot slot, int length)
{
int i;
for (i = nready - 1; i >= 0; --i)
{
rtx insn = ready[i];
if (recog_memoized (insn) >= 0
&& get_attr_slot (insn) == slot
&& get_attr_length (insn) == length)
return insn;
}
return NULL_RTX;
}
static void
mep_move_ready_insn (rtx *ready, int nready, rtx insn)
{
int i;
for (i = 0; i < nready; ++i)
if (ready[i] == insn)
{
for (; i < nready - 1; ++i)
ready[i] = ready[i + 1];
ready[i] = insn;
return;
}
gcc_unreachable ();
}
static void
mep_print_sched_insn (FILE *dump, rtx insn)
{
const char *slots = "none";
const char *name = NULL;
int code;
char buf[30];
if (GET_CODE (PATTERN (insn)) == SET
|| GET_CODE (PATTERN (insn)) == PARALLEL)
{
switch (get_attr_slots (insn))
{
case SLOTS_CORE: slots = "core"; break;
case SLOTS_C3: slots = "c3"; break;
case SLOTS_P0: slots = "p0"; break;
case SLOTS_P0_P0S: slots = "p0,p0s"; break;
case SLOTS_P0_P1: slots = "p0,p1"; break;
case SLOTS_P0S: slots = "p0s"; break;
case SLOTS_P0S_P1: slots = "p0s,p1"; break;
case SLOTS_P1: slots = "p1"; break;
default:
sprintf(buf, "%d", get_attr_slots (insn));
slots = buf;
break;
}
}
if (GET_CODE (PATTERN (insn)) == USE)
slots = "use";
code = INSN_CODE (insn);
if (code >= 0)
name = get_insn_name (code);
if (!name)
name = "{unknown}";
fprintf (dump,
"insn %4d %4d %8s %s\n",
code,
INSN_UID (insn),
name,
slots);
}
static int
mep_sched_reorder (FILE *dump ATTRIBUTE_UNUSED,
int sched_verbose ATTRIBUTE_UNUSED, rtx *ready,
int *pnready, int clock ATTRIBUTE_UNUSED)
{
int nready = *pnready;
rtx core_insn, cop_insn;
int i;
if (dump && sched_verbose > 1)
{
fprintf (dump, "\nsched_reorder: clock %d nready %d\n", clock, nready);
for (i=0; i<nready; i++)
mep_print_sched_insn (dump, ready[i]);
fprintf (dump, "\n");
}
if (!mep_vliw_function_p (cfun->decl))
return 1;
if (nready < 2)
return 1;
/* IVC2 uses a DFA to determine what's ready and what's not. */
if (TARGET_IVC2)
return nready;
/* We can issue either a core or coprocessor instruction.
Look for a matched pair of insns to reorder. If we don't
find any, don't second-guess the scheduler's priorities. */
if ((core_insn = mep_find_ready_insn (ready, nready, SLOT_CORE, 2))
&& (cop_insn = mep_find_ready_insn (ready, nready, SLOT_COP,
TARGET_OPT_VL64 ? 6 : 2)))
;
else if (TARGET_OPT_VL64
&& (core_insn = mep_find_ready_insn (ready, nready, SLOT_CORE, 4))
&& (cop_insn = mep_find_ready_insn (ready, nready, SLOT_COP, 4)))
;
else
/* We didn't find a pair. Issue the single insn at the head
of the ready list. */
return 1;
/* Reorder the two insns first. */
mep_move_ready_insn (ready, nready, core_insn);
mep_move_ready_insn (ready, nready - 1, cop_insn);
return 2;
}
/* A for_each_rtx callback. Return true if *X is a register that is
set by insn PREV. */
static int
mep_store_find_set (rtx *x, void *prev)
{
return REG_P (*x) && reg_set_p (*x, (const_rtx) prev);
}
/* Like mep_store_bypass_p, but takes a pattern as the second argument,
not the containing insn. */
static bool
mep_store_data_bypass_1 (rtx prev, rtx pat)
{
/* Cope with intrinsics like swcpa. */
if (GET_CODE (pat) == PARALLEL)
{
int i;
for (i = 0; i < XVECLEN (pat, 0); i++)
if (mep_store_data_bypass_p (prev, XVECEXP (pat, 0, i)))
return true;
return false;
}
/* Check for some sort of store. */
if (GET_CODE (pat) != SET
|| GET_CODE (SET_DEST (pat)) != MEM)
return false;
/* Intrinsics use patterns of the form (set (mem (scratch)) (unspec ...)).
The first operand to the unspec is the store data and the other operands
are used to calculate the address. */
if (GET_CODE (SET_SRC (pat)) == UNSPEC)
{
rtx src;
int i;
src = SET_SRC (pat);
for (i = 1; i < XVECLEN (src, 0); i++)
if (for_each_rtx (&XVECEXP (src, 0, i), mep_store_find_set, prev))
return false;
return true;
}
/* Otherwise just check that PREV doesn't modify any register mentioned
in the memory destination. */
return !for_each_rtx (&SET_DEST (pat), mep_store_find_set, prev);
}
/* Return true if INSN is a store instruction and if the store address
has no true dependence on PREV. */
bool
mep_store_data_bypass_p (rtx prev, rtx insn)
{
return INSN_P (insn) ? mep_store_data_bypass_1 (prev, PATTERN (insn)) : false;
}
/* A for_each_rtx subroutine of mep_mul_hilo_bypass_p. Return 1 if *X
is a register other than LO or HI and if PREV sets *X. */
static int
mep_mul_hilo_bypass_1 (rtx *x, void *prev)
{
return (REG_P (*x)
&& REGNO (*x) != LO_REGNO
&& REGNO (*x) != HI_REGNO
&& reg_set_p (*x, (const_rtx) prev));
}
/* Return true if, apart from HI/LO, there are no true dependencies
between multiplication instructions PREV and INSN. */
bool
mep_mul_hilo_bypass_p (rtx prev, rtx insn)
{
rtx pat;
pat = PATTERN (insn);
if (GET_CODE (pat) == PARALLEL)
pat = XVECEXP (pat, 0, 0);
return (GET_CODE (pat) == SET
&& !for_each_rtx (&SET_SRC (pat), mep_mul_hilo_bypass_1, prev));
}
/* Return true if INSN is an ldc instruction that issues to the
MeP-h1 integer pipeline. This is true for instructions that
read from PSW, LP, SAR, HI and LO. */
bool
mep_ipipe_ldc_p (rtx insn)
{
rtx pat, src;
pat = PATTERN (insn);
/* Cope with instrinsics that set both a hard register and its shadow.
The set of the hard register comes first. */
if (GET_CODE (pat) == PARALLEL)
pat = XVECEXP (pat, 0, 0);
if (GET_CODE (pat) == SET)
{
src = SET_SRC (pat);
/* Cope with intrinsics. The first operand to the unspec is
the source register. */
if (GET_CODE (src) == UNSPEC || GET_CODE (src) == UNSPEC_VOLATILE)
src = XVECEXP (src, 0, 0);
if (REG_P (src))
switch (REGNO (src))
{
case PSW_REGNO:
case LP_REGNO:
case SAR_REGNO:
case HI_REGNO:
case LO_REGNO:
return true;
}
}
return false;
}
/* Create a VLIW bundle from core instruction CORE and coprocessor
instruction COP. COP always satisfies INSN_P, but CORE can be
either a new pattern or an existing instruction.
Emit the bundle in place of COP and return it. */
static rtx
mep_make_bundle (rtx core, rtx cop)
{
rtx insn;
/* If CORE is an existing instruction, remove it, otherwise put
the new pattern in an INSN harness. */
if (INSN_P (core))
remove_insn (core);
else
core = make_insn_raw (core);
/* Generate the bundle sequence and replace COP with it. */
insn = gen_rtx_SEQUENCE (VOIDmode, gen_rtvec (2, core, cop));
insn = emit_insn_after (insn, cop);
remove_insn (cop);
/* Set up the links of the insns inside the SEQUENCE. */
PREV_INSN (core) = PREV_INSN (insn);
NEXT_INSN (core) = cop;
PREV_INSN (cop) = core;
NEXT_INSN (cop) = NEXT_INSN (insn);
/* Set the VLIW flag for the coprocessor instruction. */
PUT_MODE (core, VOIDmode);
PUT_MODE (cop, BImode);
/* Derive a location for the bundle. Individual instructions cannot
have their own location because there can be no assembler labels
between CORE and COP. */
INSN_LOCATOR (insn) = INSN_LOCATOR (INSN_LOCATOR (core) ? core : cop);
INSN_LOCATOR (core) = 0;
INSN_LOCATOR (cop) = 0;
return insn;
}
/* A helper routine for ms1_insn_dependent_p called through note_stores. */
static void
mep_insn_dependent_p_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
{
rtx * pinsn = (rtx *) data;
if (*pinsn && reg_mentioned_p (x, *pinsn))
*pinsn = NULL_RTX;
}
/* Return true if anything in insn X is (anti,output,true) dependent on
anything in insn Y. */
static int
mep_insn_dependent_p (rtx x, rtx y)
{
rtx tmp;
gcc_assert (INSN_P (x));
gcc_assert (INSN_P (y));
tmp = PATTERN (y);
note_stores (PATTERN (x), mep_insn_dependent_p_1, &tmp);
if (tmp == NULL_RTX)
return 1;
tmp = PATTERN (x);
note_stores (PATTERN (y), mep_insn_dependent_p_1, &tmp);
if (tmp == NULL_RTX)
return 1;
return 0;
}
static int
core_insn_p (rtx insn)
{
if (GET_CODE (PATTERN (insn)) == USE)
return 0;
if (get_attr_slot (insn) == SLOT_CORE)
return 1;
return 0;
}
/* Mark coprocessor instructions that can be bundled together with
the immediately preceeding core instruction. This is later used
to emit the "+" that tells the assembler to create a VLIW insn.
For unbundled insns, the assembler will automatically add coprocessor
nops, and 16-bit core nops. Due to an apparent oversight in the
spec, the assembler will _not_ automatically add 32-bit core nops,
so we have to emit those here.
Called from mep_insn_reorg. */
static void
mep_bundle_insns (rtx insns)
{
rtx insn, last = NULL_RTX, first = NULL_RTX;
int saw_scheduling = 0;
/* Only do bundling if we're in vliw mode. */
if (!mep_vliw_function_p (cfun->decl))
return;
/* The first insn in a bundle are TImode, the remainder are
VOIDmode. After this function, the first has VOIDmode and the
rest have BImode. */
/* Note: this doesn't appear to be true for JUMP_INSNs. */
/* First, move any NOTEs that are within a bundle, to the beginning
of the bundle. */
for (insn = insns; insn ; insn = NEXT_INSN (insn))
{
if (NOTE_P (insn) && first)
/* Don't clear FIRST. */;
else if (NONJUMP_INSN_P (insn) && GET_MODE (insn) == TImode)
first = insn;
else if (NONJUMP_INSN_P (insn) && GET_MODE (insn) == VOIDmode && first)
{
rtx note, prev;
/* INSN is part of a bundle; FIRST is the first insn in that
bundle. Move all intervening notes out of the bundle.
In addition, since the debug pass may insert a label
whenever the current line changes, set the location info
for INSN to match FIRST. */
INSN_LOCATOR (insn) = INSN_LOCATOR (first);
note = PREV_INSN (insn);
while (note && note != first)
{
prev = PREV_INSN (note);
if (NOTE_P (note))
{
/* Remove NOTE from here... */
PREV_INSN (NEXT_INSN (note)) = PREV_INSN (note);
NEXT_INSN (PREV_INSN (note)) = NEXT_INSN (note);
/* ...and put it in here. */
NEXT_INSN (note) = first;
PREV_INSN (note) = PREV_INSN (first);
NEXT_INSN (PREV_INSN (note)) = note;
PREV_INSN (NEXT_INSN (note)) = note;
}
note = prev;
}
}
else if (!NONJUMP_INSN_P (insn))
first = 0;
}
/* Now fix up the bundles. */
for (insn = insns; insn ; insn = NEXT_INSN (insn))
{
if (NOTE_P (insn))
continue;
if (!NONJUMP_INSN_P (insn))
{
last = 0;
continue;
}
/* If we're not optimizing enough, there won't be scheduling
info. We detect that here. */
if (GET_MODE (insn) == TImode)
saw_scheduling = 1;
if (!saw_scheduling)
continue;
if (TARGET_IVC2)
{
rtx core_insn = NULL_RTX;
/* IVC2 slots are scheduled by DFA, so we just accept
whatever the scheduler gives us. However, we must make
sure the core insn (if any) is the first in the bundle.
The IVC2 assembler can insert whatever NOPs are needed,
and allows a COP insn to be first. */
if (NONJUMP_INSN_P (insn)
&& GET_CODE (PATTERN (insn)) != USE
&& GET_MODE (insn) == TImode)
{
for (last = insn;
NEXT_INSN (last)
&& GET_MODE (NEXT_INSN (last)) == VOIDmode
&& NONJUMP_INSN_P (NEXT_INSN (last));
last = NEXT_INSN (last))
{
if (core_insn_p (last))
core_insn = last;
}
if (core_insn_p (last))
core_insn = last;
if (core_insn && core_insn != insn)
{
/* Swap core insn to first in the bundle. */
/* Remove core insn. */
if (PREV_INSN (core_insn))
NEXT_INSN (PREV_INSN (core_insn)) = NEXT_INSN (core_insn);
if (NEXT_INSN (core_insn))
PREV_INSN (NEXT_INSN (core_insn)) = PREV_INSN (core_insn);
/* Re-insert core insn. */
PREV_INSN (core_insn) = PREV_INSN (insn);
NEXT_INSN (core_insn) = insn;
if (PREV_INSN (core_insn))
NEXT_INSN (PREV_INSN (core_insn)) = core_insn;
PREV_INSN (insn) = core_insn;
PUT_MODE (core_insn, TImode);
PUT_MODE (insn, VOIDmode);
}
}
/* The first insn has TImode, the rest have VOIDmode */
if (GET_MODE (insn) == TImode)
PUT_MODE (insn, VOIDmode);
else
PUT_MODE (insn, BImode);
continue;
}
PUT_MODE (insn, VOIDmode);
if (recog_memoized (insn) >= 0
&& get_attr_slot (insn) == SLOT_COP)
{
if (GET_CODE (insn) == JUMP_INSN
|| ! last
|| recog_memoized (last) < 0
|| get_attr_slot (last) != SLOT_CORE
|| (get_attr_length (insn)
!= (TARGET_OPT_VL64 ? 8 : 4) - get_attr_length (last))
|| mep_insn_dependent_p (insn, last))
{
switch (get_attr_length (insn))
{
case 8:
break;
case 6:
insn = mep_make_bundle (gen_nop (), insn);
break;
case 4:
if (TARGET_OPT_VL64)
insn = mep_make_bundle (gen_nop32 (), insn);
break;
case 2:
if (TARGET_OPT_VL64)
error ("2 byte cop instructions are"
" not allowed in 64-bit VLIW mode");
else
insn = mep_make_bundle (gen_nop (), insn);
break;
default:
error ("unexpected %d byte cop instruction",
get_attr_length (insn));
break;
}
}
else
insn = mep_make_bundle (last, insn);
}
last = insn;
}
}
/* Try to instantiate INTRINSIC with the operands given in OPERANDS.
Return true on success. This function can fail if the intrinsic
is unavailable or if the operands don't satisfy their predicates. */
bool
mep_emit_intrinsic (int intrinsic, const rtx *operands)
{
const struct cgen_insn *cgen_insn;
const struct insn_data_d *idata;
rtx newop[10];
int i;
if (!mep_get_intrinsic_insn (intrinsic, &cgen_insn))
return false;
idata = &insn_data[cgen_insn->icode];
for (i = 0; i < idata->n_operands; i++)
{
newop[i] = mep_convert_arg (idata->operand[i].mode, operands[i]);
if (!idata->operand[i].predicate (newop[i], idata->operand[i].mode))
return false;
}
emit_insn (idata->genfun (newop[0], newop[1], newop[2],
newop[3], newop[4], newop[5],
newop[6], newop[7], newop[8]));
return true;
}
/* Apply the given unary intrinsic to OPERANDS[1] and store it on
OPERANDS[0]. Report an error if the instruction could not
be synthesized. OPERANDS[1] is a register_operand. For sign
and zero extensions, it may be smaller than SImode. */
bool
mep_expand_unary_intrinsic (int ATTRIBUTE_UNUSED intrinsic,
rtx * operands ATTRIBUTE_UNUSED)
{
return false;
}
/* Likewise, but apply a binary operation to OPERANDS[1] and
OPERANDS[2]. OPERANDS[1] is a register_operand, OPERANDS[2]
can be a general_operand.
IMMEDIATE and IMMEDIATE3 are intrinsics that take an immediate
third operand. REG and REG3 take register operands only. */
bool
mep_expand_binary_intrinsic (int ATTRIBUTE_UNUSED immediate,
int ATTRIBUTE_UNUSED immediate3,
int ATTRIBUTE_UNUSED reg,
int ATTRIBUTE_UNUSED reg3,
rtx * operands ATTRIBUTE_UNUSED)
{
return false;
}
static bool
mep_rtx_cost (rtx x, int code, int outer_code ATTRIBUTE_UNUSED, int *total, bool ATTRIBUTE_UNUSED speed_t)
{
switch (code)
{
case CONST_INT:
if (INTVAL (x) >= -128 && INTVAL (x) < 127)
*total = 0;
else if (INTVAL (x) >= -32768 && INTVAL (x) < 65536)
*total = 1;
else
*total = 3;
return true;
case SYMBOL_REF:
*total = optimize_size ? COSTS_N_INSNS (0) : COSTS_N_INSNS (1);
return true;
case MULT:
*total = (GET_CODE (XEXP (x, 1)) == CONST_INT
? COSTS_N_INSNS (3)
: COSTS_N_INSNS (2));
return true;
}
return false;
}
static int
mep_address_cost (rtx addr ATTRIBUTE_UNUSED, bool ATTRIBUTE_UNUSED speed_p)
{
return 1;
}
static bool
mep_handle_option (size_t code,
const char *arg ATTRIBUTE_UNUSED,
int value ATTRIBUTE_UNUSED)
{
int i;
switch (code)
{
case OPT_mall_opts:
target_flags |= MEP_ALL_OPTS;
break;
case OPT_mno_opts:
target_flags &= ~ MEP_ALL_OPTS;
break;
case OPT_mcop64:
target_flags |= MASK_COP;
target_flags |= MASK_64BIT_CR_REGS;
break;
case OPT_mtiny_:
option_mtiny_specified = 1;
case OPT_mivc2:
target_flags |= MASK_COP;
target_flags |= MASK_64BIT_CR_REGS;
target_flags |= MASK_VLIW;
target_flags |= MASK_OPT_VL64;
target_flags |= MASK_IVC2;
for (i=0; i<32; i++)
fixed_regs[i+48] = 0;
for (i=0; i<32; i++)
call_used_regs[i+48] = 1;
for (i=6; i<8; i++)
call_used_regs[i+48] = 0;
#define RN(n,s) reg_names[FIRST_CCR_REGNO + n] = s
RN (0, "$csar0");
RN (1, "$cc");
RN (4, "$cofr0");
RN (5, "$cofr1");
RN (6, "$cofa0");
RN (7, "$cofa1");
RN (15, "$csar1");
RN (16, "$acc0_0");
RN (17, "$acc0_1");
RN (18, "$acc0_2");
RN (19, "$acc0_3");
RN (20, "$acc0_4");
RN (21, "$acc0_5");
RN (22, "$acc0_6");
RN (23, "$acc0_7");
RN (24, "$acc1_0");
RN (25, "$acc1_1");
RN (26, "$acc1_2");
RN (27, "$acc1_3");
RN (28, "$acc1_4");
RN (29, "$acc1_5");
RN (30, "$acc1_6");
RN (31, "$acc1_7");
#undef RN
break;
default:
break;
}
return TRUE;
}
static void
mep_asm_init_sections (void)
{
based_section
= get_unnamed_section (SECTION_WRITE, output_section_asm_op,
"\t.section .based,\"aw\"");
tinybss_section
= get_unnamed_section (SECTION_WRITE | SECTION_BSS, output_section_asm_op,
"\t.section .sbss,\"aw\"");
sdata_section
= get_unnamed_section (SECTION_WRITE, output_section_asm_op,
"\t.section .sdata,\"aw\",@progbits");
far_section
= get_unnamed_section (SECTION_WRITE, output_section_asm_op,
"\t.section .far,\"aw\"");
farbss_section
= get_unnamed_section (SECTION_WRITE | SECTION_BSS, output_section_asm_op,
"\t.section .farbss,\"aw\"");
frodata_section
= get_unnamed_section (0, output_section_asm_op,
"\t.section .frodata,\"a\"");
srodata_section
= get_unnamed_section (0, output_section_asm_op,
"\t.section .srodata,\"a\"");
vtext_section
= get_unnamed_section (SECTION_CODE | SECTION_MEP_VLIW, output_section_asm_op,
"\t.section .vtext,\"axv\"\n\t.vliw");
vftext_section
= get_unnamed_section (SECTION_CODE | SECTION_MEP_VLIW, output_section_asm_op,
"\t.section .vftext,\"axv\"\n\t.vliw");
ftext_section
= get_unnamed_section (SECTION_CODE, output_section_asm_op,
"\t.section .ftext,\"ax\"\n\t.core");
}
#include "gt-mep.h"
|