summaryrefslogtreecommitdiff
path: root/gcc/config/visium/visium.c
blob: 341666c04ed15a068032329f4fac2ff1ea363f88 (plain)
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
/* Output routines for Visium.
   Copyright (C) 2002-2015 Free Software Foundation, Inc.
   Contributed by C.Nettleton, J.P.Parkes and P.Garbett.

   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 "alias.h"
#include "flags.h"
#include "symtab.h"
#include "tree-core.h"
#include "fold-const.h"
#include "tree-check.h"
#include "tree.h"
#include "stringpool.h"
#include "stor-layout.h"
#include "calls.h"
#include "varasm.h"
#include "rtl.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "insn-config.h"
#include "conditions.h"
#include "output.h"
#include "insn-attr.h"
#include "function.h"
#include "expmed.h"
#include "dojump.h"
#include "explow.h"
#include "emit-rtl.h"
#include "stmt.h"
#include "expr.h"
#include "recog.h"
#include "diagnostic-core.h"
#include "tm_p.h"
#include "optabs.h"
#include "target.h"
#include "target-def.h"
#include "common/common-target.h"
#include "predict.h"
#include "basic-block.h"
#include "gimple-expr.h"
#include "gimplify.h"
#include "langhooks.h"
#include "reload.h"
#include "tm-constrs.h"
#include "df.h"
#include "params.h"
#include "errors.h"
#include "tree-pass.h"
#include "context.h"
#include "builtins.h"

/* Machine specific function data. */
struct GTY (()) machine_function
{
  /* Size of the frame of the function.  */
  int frame_size;

  /* Size of the reg parm save area, non-zero only for functions with variable
     argument list.  We cannot use the crtl->args.pretend_args_size machinery
     for this purpose because this size is added to virtual_incoming_args_rtx
     to give the location of the first parameter passed by the caller on the
     stack and virtual_incoming_args_rtx is also the location of the first
     parameter on the stack.  So crtl->args.pretend_args_size can be non-zero
     only if the first non-register named parameter is not passed entirely on
     the stack and this runs afoul of the need to have a reg parm save area
     even with a variable argument list starting on the stack because of the
     separate handling of general and floating-point registers.  */
  int reg_parm_save_area_size;

  /* True if we have created an rtx which relies on the frame pointer.  */
  bool frame_needed;

  /* True if we have exposed the flags register.  From this moment on, we
     cannot generate simple operations for integer registers.  We could
     use reload_completed for this purpose, but this would cripple the
     postreload CSE and GCSE passes which run before postreload split.  */
  bool flags_exposed;
};

#define visium_frame_size		cfun->machine->frame_size
#define visium_reg_parm_save_area_size 	cfun->machine->reg_parm_save_area_size
#define visium_frame_needed		cfun->machine->frame_needed
#define visium_flags_exposed		cfun->machine->flags_exposed

/* 1 if the next opcode is to be specially indented.  */
int visium_indent_opcode = 0;

/* Register number used for long branches when LR isn't available.  It
   must be a call-used register since it isn't saved on function entry.
   We do not care whether the branch is predicted or not on the GR6,
   given how unlikely it is to have a long branch in a leaf function.  */
static unsigned int long_branch_regnum = 31;

static void visium_output_address (FILE *, enum machine_mode, rtx);
static tree visium_handle_interrupt_attr (tree *, tree, tree, int, bool *);
static inline bool current_function_saves_fp (void);
static inline bool current_function_saves_lr (void);
static inline bool current_function_has_lr_slot (void);

/* Supported attributes:
   interrupt -- specifies this function is an interrupt handler.   */
static const struct attribute_spec visium_attribute_table[] =
{
  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
       affects_type_identity } */
  {"interrupt", 0, 0, true, false, false, visium_handle_interrupt_attr, false},
  {NULL, 0, 0, false, false, false, NULL, false}
};

static struct machine_function *visium_init_machine_status (void);

/* Target hooks and TARGET_INITIALIZER  */

static bool visium_pass_by_reference (cumulative_args_t, enum machine_mode,
				      const_tree, bool);

static rtx visium_function_arg (cumulative_args_t, enum machine_mode,
				const_tree, bool);

static void visium_function_arg_advance (cumulative_args_t, enum machine_mode,
					 const_tree, bool);

static bool visium_return_in_memory (const_tree, const_tree fntype);

static rtx visium_function_value (const_tree, const_tree fn_decl_or_type,
				  bool);

static rtx visium_libcall_value (enum machine_mode, const_rtx);

static void visium_setup_incoming_varargs (cumulative_args_t,
					   enum machine_mode,
					   tree, int *, int);

static void visium_va_start (tree valist, rtx nextarg);

static tree visium_gimplify_va_arg (tree, tree, gimple_seq *, gimple_seq *);

static bool visium_function_ok_for_sibcall (tree, tree);

static bool visium_frame_pointer_required (void);

static tree visium_build_builtin_va_list (void);

static rtx_insn *visium_md_asm_adjust (vec<rtx> &, vec<rtx> &,
				       vec<const char *> &,
				       vec<rtx> &, HARD_REG_SET &);

static bool visium_legitimate_constant_p (enum machine_mode, rtx);

static bool visium_legitimate_address_p (enum machine_mode, rtx, bool);

static void visium_conditional_register_usage (void);

static rtx visium_legitimize_address (rtx, rtx, enum machine_mode);

static reg_class_t visium_secondary_reload (bool, rtx, reg_class_t,
					    enum machine_mode,
					    secondary_reload_info *);

static bool visium_class_likely_spilled_p (reg_class_t);

static void visium_trampoline_init (rtx, tree, rtx);

static int visium_issue_rate (void);

static int visium_adjust_priority (rtx_insn *, int);

static int visium_adjust_cost (rtx_insn *, rtx, rtx_insn *, int);

static int visium_register_move_cost (enum machine_mode, reg_class_t,
				      reg_class_t);

static int visium_memory_move_cost (enum machine_mode, reg_class_t, bool);

static bool visium_rtx_costs (rtx, int, int, int, int *, bool);

static void visium_option_override (void);

static unsigned int visium_reorg (void);

/* Setup the global target hooks structure.  */

#undef  TARGET_MAX_ANCHOR_OFFSET
#define TARGET_MAX_ANCHOR_OFFSET 31

#undef  TARGET_PASS_BY_REFERENCE
#define TARGET_PASS_BY_REFERENCE visium_pass_by_reference

#undef  TARGET_FUNCTION_ARG
#define TARGET_FUNCTION_ARG visium_function_arg

#undef  TARGET_FUNCTION_ARG_ADVANCE
#define TARGET_FUNCTION_ARG_ADVANCE visium_function_arg_advance

#undef  TARGET_RETURN_IN_MEMORY
#define TARGET_RETURN_IN_MEMORY visium_return_in_memory

#undef  TARGET_FUNCTION_VALUE
#define TARGET_FUNCTION_VALUE visium_function_value

#undef  TARGET_LIBCALL_VALUE
#define TARGET_LIBCALL_VALUE visium_libcall_value

#undef  TARGET_SETUP_INCOMING_VARARGS
#define TARGET_SETUP_INCOMING_VARARGS visium_setup_incoming_varargs

#undef  TARGET_EXPAND_BUILTIN_VA_START
#define TARGET_EXPAND_BUILTIN_VA_START visium_va_start

#undef  TARGET_BUILD_BUILTIN_VA_LIST
#define TARGET_BUILD_BUILTIN_VA_LIST visium_build_builtin_va_list

#undef  TARGET_GIMPLIFY_VA_ARG_EXPR
#define TARGET_GIMPLIFY_VA_ARG_EXPR visium_gimplify_va_arg

#undef  TARGET_LEGITIMATE_CONSTANT_P
#define TARGET_LEGITIMATE_CONSTANT_P visium_legitimate_constant_p

#undef  TARGET_LEGITIMATE_ADDRESS_P
#define TARGET_LEGITIMATE_ADDRESS_P visium_legitimate_address_p

#undef  TARGET_ATTRIBUTE_TABLE
#define TARGET_ATTRIBUTE_TABLE visium_attribute_table

#undef  TARGET_ADDRESS_COST
#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0

#undef  TARGET_STRICT_ARGUMENT_NAMING
#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true

#undef  TARGET_SCHED_ISSUE_RATE
#define TARGET_SCHED_ISSUE_RATE visium_issue_rate

#undef  TARGET_SCHED_ADJUST_PRIORITY
#define TARGET_SCHED_ADJUST_PRIORITY visium_adjust_priority

#undef  TARGET_SCHED_ADJUST_COST
#define TARGET_SCHED_ADJUST_COST visium_adjust_cost

#undef  TARGET_MEMORY_MOVE_COST
#define TARGET_MEMORY_MOVE_COST visium_memory_move_cost

#undef  TARGET_REGISTER_MOVE_COST
#define TARGET_REGISTER_MOVE_COST visium_register_move_cost

#undef  TARGET_RTX_COSTS
#define TARGET_RTX_COSTS visium_rtx_costs

#undef  TARGET_FUNCTION_OK_FOR_SIBCALL
#define TARGET_FUNCTION_OK_FOR_SIBCALL visium_function_ok_for_sibcall

#undef  TARGET_FRAME_POINTER_REQUIRED
#define TARGET_FRAME_POINTER_REQUIRED visium_frame_pointer_required

#undef  TARGET_SECONDARY_RELOAD
#define TARGET_SECONDARY_RELOAD visium_secondary_reload

#undef  TARGET_CLASS_LIKELY_SPILLED_P
#define TARGET_CLASS_LIKELY_SPILLED_P visium_class_likely_spilled_p

#undef  TARGET_LEGITIMIZE_ADDRESS
#define TARGET_LEGITIMIZE_ADDRESS visium_legitimize_address

#undef  TARGET_OPTION_OVERRIDE
#define TARGET_OPTION_OVERRIDE visium_option_override

#undef  TARGET_CONDITIONAL_REGISTER_USAGE
#define TARGET_CONDITIONAL_REGISTER_USAGE visium_conditional_register_usage

#undef  TARGET_TRAMPOLINE_INIT
#define TARGET_TRAMPOLINE_INIT visium_trampoline_init

#undef TARGET_MD_ASM_ADJUST
#define TARGET_MD_ASM_ADJUST visium_md_asm_adjust

#undef TARGET_FLAGS_REGNUM
#define TARGET_FLAGS_REGNUM FLAGS_REGNUM

struct gcc_target targetm = TARGET_INITIALIZER;

namespace {

const pass_data pass_data_visium_reorg =
{
  RTL_PASS, /* type */
  "mach2", /* name */
  OPTGROUP_NONE, /* optinfo_flags */
  TV_MACH_DEP, /* tv_id */
  0, /* properties_required */
  0, /* properties_provided */
  0, /* properties_destroyed */
  0, /* todo_flags_start */
  0, /* todo_flags_finish */
};

class pass_visium_reorg : public rtl_opt_pass
{
public:
  pass_visium_reorg(gcc::context *ctxt)
    : rtl_opt_pass(pass_data_visium_reorg, ctxt)
  {}

  /* opt_pass methods: */
  virtual unsigned int execute (function *)
    {
      return visium_reorg ();
    }

}; // class pass_work_around_errata

} // anon namespace

rtl_opt_pass *
make_pass_visium_reorg (gcc::context *ctxt)
{
  return new pass_visium_reorg (ctxt);
}

/* Options override for Visium.  */

static void
visium_option_override (void)
{
  if (flag_pic == 1)
    warning (OPT_fpic, "-fpic is not supported");
  if (flag_pic == 2)
    warning (OPT_fPIC, "-fPIC is not supported");

  /* MCM is the default in the GR5/GR6 era.  */
  target_flags |= MASK_MCM;

  /* FPU is the default with MCM, but don't override an explicit option.  */
  if ((target_flags_explicit & MASK_FPU) == 0)
    target_flags |= MASK_FPU;

  /* The supervisor mode is the default.  */
  if ((target_flags_explicit & MASK_SV_MODE) == 0)
    target_flags |= MASK_SV_MODE;

  /* The GR6 has the Block Move Instructions and an IEEE-compliant FPU.  */
  if (visium_cpu_and_features == PROCESSOR_GR6)
    {
      target_flags |= MASK_BMI;
      if (target_flags & MASK_FPU)
	target_flags |= MASK_FPU_IEEE;
    }

  /* Set -mtune from -mcpu if not specified.  */
  if (!global_options_set.x_visium_cpu)
    visium_cpu = visium_cpu_and_features;

  /* Align functions on 256-byte (32-quadword) for GR5 and 64-byte (8-quadword)
     boundaries for GR6 so they start a new burst mode window.  */
  if (align_functions == 0)
    {
      if (visium_cpu == PROCESSOR_GR6)
	align_functions = 64;
      else
	align_functions = 256;

      /* Allow the size of compilation units to double because of inlining.
	 In practice the global size of the object code is hardly affected
	 because the additional instructions will take up the padding.  */
      maybe_set_param_value (PARAM_INLINE_UNIT_GROWTH, 100,
			     global_options.x_param_values,
			     global_options_set.x_param_values);
    }

  /* Likewise for loops.  */
  if (align_loops == 0)
    {
      if (visium_cpu == PROCESSOR_GR6)
	align_loops = 64;
      else
	{
	  align_loops = 256;
	  /* But not if they are too far away from a 256-byte boundary.  */
	  align_loops_max_skip = 31;
	}
    }

  /* Align all jumps on quadword boundaries for the burst mode, and even
     on 8-quadword boundaries for GR6 so they start a new window.  */
  if (align_jumps == 0)
    {
      if (visium_cpu == PROCESSOR_GR6)
	align_jumps = 64;
      else
	align_jumps = 8;
    }

  /* We register a machine-specific pass.  This pass must be scheduled as
     late as possible so that we have the (essentially) final form of the
     insn stream to work on.  Registering the pass must be done at start up.
     It's convenient to do it here.  */
  opt_pass *visium_reorg_pass = make_pass_visium_reorg (g);
  struct register_pass_info insert_pass_visium_reorg =
    {
      visium_reorg_pass,		/* pass */
      "dbr",				/* reference_pass_name */
      1,				/* ref_pass_instance_number */
      PASS_POS_INSERT_AFTER		/* po_op */
    };
  register_pass (&insert_pass_visium_reorg);
}

/* Return the number of instructions that can issue on the same cycle.  */

static int
visium_issue_rate (void)
{
  switch (visium_cpu)
    {
    case PROCESSOR_GR5:
      return 1;

    case PROCESSOR_GR6:
      return 2;

    default:
      gcc_unreachable ();
    }
}

/* Return the adjusted PRIORITY of INSN.  */

static int
visium_adjust_priority (rtx_insn *insn, int priority)
{
  /* On the GR5, we slightly increase the priority of writes in order to avoid
     scheduling a read on the next cycle.  This is necessary in addition to the
     associated insn reservation because there are no data dependencies.
     We also slightly increase the priority of reads from ROM in order to group
     them as much as possible.  These reads are a bit problematic because they
     conflict with the instruction fetches, i.e. the data and instruction buses
     tread on each other's toes when they are executed.  */
  if (visium_cpu == PROCESSOR_GR5
      && reload_completed
      && INSN_P (insn)
      && recog_memoized (insn) >= 0)
    {
      enum attr_type attr_type = get_attr_type (insn);
      if (attr_type == TYPE_REG_MEM
	  || (attr_type == TYPE_MEM_REG
	      && MEM_READONLY_P (SET_SRC (PATTERN (insn)))))
	return priority + 1;
    }

  return priority;
}

/* Adjust the cost of a scheduling dependency.  Return the new cost of
   a dependency LINK of INSN on DEP_INSN.  COST is the current cost.  */

static int
visium_adjust_cost (rtx_insn *insn, rtx link, rtx_insn *dep_insn, int cost)
{
  enum attr_type attr_type;

  /* Don't adjust costs for true dependencies as they are described with
     bypasses.  But we make an exception for the first scheduling pass to
     help the subsequent postreload compare elimination pass.  */
  if (REG_NOTE_KIND (link) == REG_DEP_TRUE)
    {
      if (!reload_completed
	  && recog_memoized (insn) >= 0
	  && get_attr_type (insn) == TYPE_CMP)
	{
	  rtx pat = PATTERN (insn);
	  gcc_assert (GET_CODE (pat) == SET);
	  rtx src = SET_SRC (pat);

	  /* Only the branches can be modified by the postreload compare
	     elimination pass, not the cstores because they accept only
	     unsigned comparison operators and they are eliminated if
	     one of the operands is zero.  */
	  if (GET_CODE (src) == IF_THEN_ELSE
	      && XEXP (XEXP (src, 0), 1) == const0_rtx
	      && recog_memoized (dep_insn) >= 0)
	    {
	      enum attr_type dep_attr_type = get_attr_type (dep_insn);

	      /* The logical instructions use CCmode and thus work with any
		 comparison operator, whereas the arithmetic instructions use
		 CC_NOOVmode and thus work with only a small subset.  */
	      if (dep_attr_type == TYPE_LOGIC
		  || (dep_attr_type == TYPE_ARITH
		      && visium_noov_operator (XEXP (src, 0),
					       GET_MODE (XEXP (src, 0)))))
		return 0;
	    }
	}

      return cost;
    }

  if (recog_memoized (insn) < 0)
    return 0;

  attr_type = get_attr_type (insn);

  /* Anti dependency: DEP_INSN reads a register that INSN writes some
     cycles later.  */
  if (REG_NOTE_KIND (link) == REG_DEP_ANTI)
    {
      /* On the GR5, the latency of FP instructions needs to be taken into
	 account for every dependency involving a write.  */
      if (attr_type == TYPE_REG_FP && visium_cpu == PROCESSOR_GR5)
	{
	  /* INSN is FLOAD. */
	  rtx pat = PATTERN (insn);
	  rtx dep_pat = PATTERN (dep_insn);

	  if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
	    /* If this happens, we have to extend this to schedule
	       optimally. Return 0 for now. */
	    return 0;

	  if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
	    {
	      if (recog_memoized (dep_insn) < 0)
		return 0;

	      switch (get_attr_type (dep_insn))
		{
		case TYPE_FDIV:
		case TYPE_FSQRT:
		case TYPE_FTOI:
		case TYPE_ITOF:
		case TYPE_FP:
		case TYPE_FMOVE:
		  /* A fload can't be issued until a preceding arithmetic
		     operation has finished if the target of the fload is
		     any of the sources (or destination) of the arithmetic
		     operation. Note that the latency may be (much)
		     greater than this if the preceding instruction
		     concerned is in a queue. */
		  return insn_default_latency (dep_insn);

		default:
		  return 0;
		}
	    }
	}

      /* On the GR6, we try to make sure that the link register is restored
	 sufficiently ahead of the return as to yield a correct prediction
	 from the branch predictor.  By default there is no true dependency
	 but an anti dependency between them, so we simply reuse it.  */
      else if (attr_type == TYPE_RET && visium_cpu == PROCESSOR_GR6)
	{
	  rtx dep_pat = PATTERN (dep_insn);
	  if (GET_CODE (dep_pat) == SET
	      && REG_P (SET_DEST (dep_pat))
	      && REGNO (SET_DEST (dep_pat)) == LINK_REGNUM)
	    return 8;
	}

      /* For other anti dependencies, the cost is 0. */
      return 0;
    }

  /* Output dependency: DEP_INSN writes a register that INSN writes some
     cycles later.  */
  else if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT)
    {
      /* On the GR5, the latency of FP instructions needs to be taken into
	 account for every dependency involving a write.  */
      if (attr_type == TYPE_REG_FP && visium_cpu == PROCESSOR_GR5)
	{
	  /* INSN is FLOAD. */
	  rtx pat = PATTERN (insn);
	  rtx dep_pat = PATTERN (dep_insn);

	  if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
	    /* If this happens, we have to extend this to schedule
	       optimally. Return 0 for now. */
	    return 0;

	  if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
	    {
	      if (recog_memoized (dep_insn) < 0)
		return 0;

	      switch (get_attr_type (dep_insn))
		{
		case TYPE_FDIV:
		case TYPE_FSQRT:
		case TYPE_FTOI:
		case TYPE_ITOF:
		case TYPE_FP:
		case TYPE_FMOVE:
		  /* A fload can't be issued until a preceding arithmetic
		     operation has finished if the target of the fload is
		     the destination of the arithmetic operation. Note that
		     the latency may be (much) greater than this if the
		     preceding instruction concerned is in a queue. */
		  return insn_default_latency (dep_insn);

		default:
		  return 0;
		}
	    }
	}

      /* For other output dependencies, the cost is 0. */
      return 0;
    }

  return 0;
}

/* Handle an "interrupt_handler" attribute; arguments as in
   struct attribute_spec.handler.  */

static tree
visium_handle_interrupt_attr (tree *node, tree name,
			      tree args ATTRIBUTE_UNUSED,
			      int flags ATTRIBUTE_UNUSED,
			      bool *no_add_attrs)
{
  if (TREE_CODE (*node) != FUNCTION_DECL)
    {
      warning (OPT_Wattributes, "%qE attribute only applies to functions",
	       name);
      *no_add_attrs = true;
    }
  else if (!TARGET_SV_MODE)
    {
      error ("an interrupt handler cannot be compiled with -muser-mode");
      *no_add_attrs = true;
    }

  return NULL_TREE;
}

/* Return non-zero if the current function is an interrupt function.  */

int
visium_interrupt_function_p (void)
{
  return
    lookup_attribute ("interrupt",
		      DECL_ATTRIBUTES (current_function_decl)) != NULL_TREE;
}

/* Conditionally modify the settings of the register file.  */

static void
visium_conditional_register_usage (void)
{
  /* If the supervisor mode is disabled, mask some general registers.  */
  if (!TARGET_SV_MODE)
    {
      if (visium_cpu_and_features == PROCESSOR_GR5)
	{
	  fixed_regs[24] = call_used_regs[24] = 1;
	  fixed_regs[25] = call_used_regs[25] = 1;
	  fixed_regs[26] = call_used_regs[26] = 1;
	  fixed_regs[27] = call_used_regs[27] = 1;
	  fixed_regs[28] = call_used_regs[28] = 1;
	  call_really_used_regs[24] = 0;
	  call_really_used_regs[25] = 0;
	  call_really_used_regs[26] = 0;
	  call_really_used_regs[27] = 0;
	  call_really_used_regs[28] = 0;
	}

      fixed_regs[31] = call_used_regs[31] = 1;
      call_really_used_regs[31] = 0;

      /* We also need to change the long-branch register.  */
      if (visium_cpu_and_features == PROCESSOR_GR5)
	long_branch_regnum = 20;
      else
	long_branch_regnum = 28;
    }

  /* If the FPU is disabled, mask the FP registers.  */
  if (!TARGET_FPU)
    {
      for (int i = FP_FIRST_REGNUM; i <= FP_LAST_REGNUM; i++)
	{
	  fixed_regs[i] = call_used_regs[i] = 1;
	  call_really_used_regs[i] = 0;
	}
    }
}

/* Prepend to CLOBBERS hard registers that are automatically clobbered for
   an asm   We do this for the FLAGS to maintain source compatibility with
   the original cc0-based compiler.  */

static rtx_insn *
visium_md_asm_adjust (vec<rtx> &/*outputs*/, vec<rtx> &/*inputs*/,
		      vec<const char *> &/*constraints*/,
		      vec<rtx> &clobbers, HARD_REG_SET &clobbered_regs)
{
  clobbers.safe_push (gen_rtx_REG (CCmode, FLAGS_REGNUM));
  SET_HARD_REG_BIT (clobbered_regs, FLAGS_REGNUM);
  return NULL;
}

/* Return true if X is a legitimate constant for a MODE immediate operand.
   X is guaranteed to satisfy the CONSTANT_P predicate.  */

static bool
visium_legitimate_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED,
			      rtx x ATTRIBUTE_UNUSED)
{
  return true;
}

/* Compute the alignment for a variable.  The alignment of an aggregate is
   set to be at least that of a scalar less than or equal to it in size.  */

unsigned int
visium_data_alignment (tree type, unsigned int align)
{
  if (AGGREGATE_TYPE_P (type)
      && TYPE_SIZE (type)
      && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST && align < 32)
    {
      if (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 32)
	return 32;

      if (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 16 && align < 16)
	return 16;
    }

  return align;
}

/* Helper function for HARD_REGNO_RENAME_OK (FROM, TO).  Return non-zero if
   it is OK to rename a hard register FROM to another hard register TO.  */

int
visium_hard_regno_rename_ok (unsigned int from ATTRIBUTE_UNUSED,
			     unsigned int to)
{
  /* If the function doesn't save LR, then the long-branch register will be
     used for long branches so we need to know whether it is live before the
     frame layout is computed.  */
  if (!current_function_saves_lr () && to == long_branch_regnum)
    return 0;

  /* Interrupt functions can only use registers that have already been
     saved by the prologue, even if they would normally be call-clobbered.  */
  if (crtl->is_leaf
      && !df_regs_ever_live_p (to)
      && visium_interrupt_function_p ())
    return 0;

  return 1;
}

/* Return true if it is ok to do sibling call optimization for the specified
   call expression EXP.  DECL will be the called function, or NULL if this
   is an indirect call.  */

static bool
visium_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED,
				tree exp ATTRIBUTE_UNUSED)
{
  return !visium_interrupt_function_p ();
}

/* Prepare operands for a move define_expand in MODE.  */

void
prepare_move_operands (rtx *operands, enum machine_mode mode)
{
  /* If the output is not a register, the input must be.  */
  if (GET_CODE (operands[0]) == MEM && !reg_or_0_operand (operands[1], mode))
    operands[1] = force_reg (mode, operands[1]);
}

/* Return true if the operands are valid for a simple move insn.  */

bool
ok_for_simple_move_operands (rtx *operands, enum machine_mode mode)
{
  /* One of the operands must be a register.  */
  if (!register_operand (operands[0], mode)
      && !reg_or_0_operand (operands[1], mode))
    return false;

  /* Once the flags are exposed, no simple moves between integer registers.  */
  if (visium_flags_exposed
      && gpc_reg_operand (operands[0], mode)
      && gpc_reg_operand (operands[1], mode))
    return false;

 return true;
}

/* Return true if the operands are valid for a simple move strict insn.  */

bool
ok_for_simple_move_strict_operands (rtx *operands, enum machine_mode mode)
{
  /* Once the flags are exposed, no simple moves between integer registers.
     Note that, in QImode only, a zero source counts as an integer register
     since it will be emitted as r0.  */
  if (visium_flags_exposed
      && gpc_reg_operand (operands[0], mode)
      && (gpc_reg_operand (operands[1], mode)
	  || (mode == QImode && operands[1] == const0_rtx)))
    return false;

 return true;
}

/* Return true if the operands are valid for a simple arithmetic or logical
   insn.  */

bool
ok_for_simple_arith_logic_operands (rtx *, enum machine_mode)
{
  /* Once the flags are exposed, no simple arithmetic or logical operations
     between integer registers.  */
  return !visium_flags_exposed;
}

/* Return non-zero if a branch or call instruction will be emitting a nop
   into its delay slot.  */

int
empty_delay_slot (rtx_insn *insn)
{
  rtx seq;

  /* If no previous instruction (should not happen), return true.  */
  if (PREV_INSN (insn) == NULL)
    return 1;

  seq = NEXT_INSN (PREV_INSN (insn));
  if (GET_CODE (PATTERN (seq)) == SEQUENCE)
    return 0;

  return 1;
}

/* Wrapper around single_set which returns the first SET of a pair if the
   second SET is to the flags register.  */

static rtx
single_set_and_flags (rtx_insn *insn)
{
  if (multiple_sets (insn))
    {
      rtx pat = PATTERN (insn);
      if (XVECLEN (pat, 0) == 2
	  && GET_CODE (XVECEXP (pat, 0, 1)) == SET
	  && REG_P (SET_DEST (XVECEXP (pat, 0, 1)))
	  && REGNO (SET_DEST (XVECEXP (pat, 0, 1))) == FLAGS_REGNUM)
	return XVECEXP (pat, 0, 0);
    }

  return single_set (insn);
}

/* This is called with OUT_INSN an instruction setting a (base) register
   and IN_INSN a read or a write.  Return 1 if these instructions together
   constitute a pipeline hazard.

   On the original architecture, a pipeline data hazard occurs when the Dest
   of one instruction becomes the SrcA for an immediately following READ or
   WRITE instruction with a non-zero index (indexing occurs at the decode
   stage and so a NOP must be inserted in-between for this to work).

   An example is:

	move.l  r2,r1
	read.l  r4,10(r2)

   On the MCM, the non-zero index condition is lifted but the hazard is
   patched up by the hardware through the injection of wait states:

        move.l  r2,r1
        read.l  r4,(r2)

   We nevertheless try to schedule instructions around this.  */

int
gr5_hazard_bypass_p (rtx_insn *out_insn, rtx_insn *in_insn)
{
  rtx out_set, in_set, dest, memexpr;
  unsigned int out_reg, in_reg;

  /* A CALL is storage register class, but the link register is of no
     interest here. */
  if (GET_CODE (out_insn) == CALL_INSN)
    return 0;

  out_set = single_set_and_flags (out_insn);
  dest = SET_DEST (out_set);

  /* Should be no stall/hazard if OUT_INSN is MEM := ???.  This only
     occurs prior to reload. */
  if (GET_CODE (dest) == MEM)
    return 0;

  if (GET_CODE (dest) == STRICT_LOW_PART)
    dest = XEXP (dest, 0);
  if (GET_CODE (dest) == SUBREG)
    dest = SUBREG_REG (dest);
  out_reg = REGNO (dest);

  in_set = single_set_and_flags (in_insn);

  /* If IN_INSN is MEM := MEM, it's the source that counts. */
  if (GET_CODE (SET_SRC (in_set)) == MEM)
    memexpr = XEXP (SET_SRC (in_set), 0);
  else
    memexpr = XEXP (SET_DEST (in_set), 0);

  if (GET_CODE (memexpr) == PLUS)
    {
      memexpr = XEXP (memexpr, 0);
      if (GET_CODE (memexpr) == SUBREG)
	in_reg = REGNO (SUBREG_REG (memexpr));
      else
	in_reg = REGNO (memexpr);

      if (in_reg == out_reg)
	return 1;
    }
  else if (TARGET_MCM)
    {
      if (GET_CODE (memexpr) == STRICT_LOW_PART)
	memexpr = XEXP (memexpr, 0);
      if (GET_CODE (memexpr) == SUBREG)
	memexpr = SUBREG_REG (memexpr);
      in_reg = REGNO (memexpr);

      if (in_reg == out_reg)
	return 1;
    }

  return 0;
}

/* Return true if INSN is an empty asm instruction.  */

static bool
empty_asm_p (rtx insn)
{
  rtx body = PATTERN (insn);
  const char *templ;

  if (GET_CODE (body) == ASM_INPUT)
    templ = XSTR (body, 0);
  else if (asm_noperands (body) >= 0)
    templ = decode_asm_operands (body, NULL, NULL, NULL, NULL, NULL);
  else
    templ = NULL;

  return (templ && templ[0] == '\0');
}

/* Insert a NOP immediately before INSN wherever there is a pipeline hazard.
   LAST_REG records the register set in the last insn and LAST_INSN_CALL
   records whether the last insn was a call insn.  */

static void
gr5_avoid_hazard (rtx_insn *insn, unsigned int *last_reg, bool *last_insn_call)
{
  unsigned int dest_reg = 0;
  rtx set;

  switch (GET_CODE (insn))
    {
    case CALL_INSN:
      *last_reg = 0;
      *last_insn_call = true;
      return;

    case JUMP_INSN:
      /* If this is an empty asm, just skip it.  */
      if (!empty_asm_p (insn))
	{
	  *last_reg = 0;
	  *last_insn_call = false;
	}
      return;

    case INSN:
      /* If this is an empty asm, just skip it.  */
      if (empty_asm_p (insn))
	return;
      break;

    default:
      return;
    }

  set = single_set_and_flags (insn);
  if (set != NULL_RTX)
    {
      rtx dest = SET_DEST (set);
      const bool double_p = GET_MODE_SIZE (GET_MODE (dest)) > UNITS_PER_WORD;
      rtx memrtx = NULL;

      if (GET_CODE (SET_SRC (set)) == MEM)
	{
	  memrtx = XEXP (SET_SRC (set), 0);
	  if (GET_CODE (dest) == STRICT_LOW_PART)
	    dest = XEXP (dest, 0);
	  if (REG_P (dest))
	    dest_reg = REGNO (dest);

	  /* If this is a DI or DF mode memory to register
	     copy, then if rd = rs we get

	     rs + 1 := 1[rs]
	     rs     :=  [rs]

	     otherwise the order is

	     rd     :=  [rs]
	     rd + 1 := 1[rs] */

	  if (double_p)
	    {
	      unsigned int base_reg;

	      if (GET_CODE (memrtx) == PLUS)
		base_reg = REGNO (XEXP (memrtx, 0));
	      else
		base_reg = REGNO (memrtx);

	      if (dest_reg != base_reg)
		dest_reg++;
	    }
	}

      else if (GET_CODE (dest) == MEM)
	memrtx = XEXP (dest, 0);

      else if (GET_MODE_CLASS (GET_MODE (dest)) != MODE_CC)
	{
	  if (GET_CODE (dest) == STRICT_LOW_PART
	      ||GET_CODE (dest) == ZERO_EXTRACT)
	    dest = XEXP (dest, 0);
	  dest_reg = REGNO (dest);

	  if (GET_CODE (SET_SRC (set)) == REG)
	    {
	      unsigned int srcreg = REGNO (SET_SRC (set));

	      /* Check for rs := rs, which will be deleted.  */
	      if (srcreg == dest_reg)
		return;

	      /* In the case of a DI or DF mode move from register to
	         register there is overlap if rd = rs + 1 in which case
	         the order of the copies is reversed :

	         rd + 1 := rs + 1;
	         rd     := rs   */

	      if (double_p && dest_reg != srcreg + 1)
		dest_reg++;
	    }
	}

      /* If this is the delay slot of a call insn, any register it sets
         is not relevant.  */
      if (*last_insn_call)
	dest_reg = 0;

      /* If the previous insn sets the value of a register, and this insn
	 uses a base register, check for the pipeline hazard where it is
	 the same register in each case.  */
      if (*last_reg != 0 && memrtx != NULL_RTX)
	{
	  unsigned int reg = 0;

	  /* Check for an index (original architecture).  */
	  if (GET_CODE (memrtx) == PLUS)
	    reg = REGNO (XEXP (memrtx, 0));

	  /* Check for an MCM target or rs := [rs], in DI or DF mode.  */
	  else if (TARGET_MCM || (double_p && REGNO (memrtx) == dest_reg))
	    reg = REGNO (memrtx);

	  /* Remove any pipeline hazard by inserting a NOP.  */
	  if (reg == *last_reg)
	    {
	      if (dump_file)
	        fprintf (dump_file,
			 "inserting nop before insn %d\n", INSN_UID (insn));
	      emit_insn_after (gen_hazard_nop (), prev_active_insn (insn));
	      emit_insn_after (gen_blockage (), insn);
	    }
	}

      *last_reg = dest_reg;
    }

  *last_insn_call = false;
}

/* Go through the instruction stream and insert nops where necessary to avoid
   pipeline hazards.  There are two cases:

     1. On the original architecture, it is invalid to set the value of a
	(base) register and then use it in an address with a non-zero index
	in the next instruction.

     2. On the MCM, setting the value of a (base) register and then using
	it in address (including with zero index) in the next instruction
	will result in a pipeline stall of 3 cycles.  */

static void
gr5_hazard_avoidance (void)
{
  unsigned int last_reg = 0;
  bool last_insn_call = false;
  rtx_insn *insn;

  for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
    if (INSN_P (insn))
      {
	rtx pat = PATTERN (insn);

	if (GET_CODE (pat) == SEQUENCE)
	  {
	    for (int i = 0; i < XVECLEN (pat, 0); i++)
	      gr5_avoid_hazard (as_a <rtx_insn *> (XVECEXP (pat, 0, i)),
				&last_reg, &last_insn_call);
	  }

	else if (GET_CODE (insn) == CALL_INSN)
	  {
	    /* This call is going to get a nop in its delay slot.  */
	    last_reg = 0;
	    last_insn_call = false;
	  }

	else
	  gr5_avoid_hazard (insn, &last_reg, &last_insn_call);
      }

    else if (GET_CODE (insn) == BARRIER)
      last_reg = 0;
}

/* Perform a target-specific pass over the instruction stream.  The compiler
   will run it at all optimization levels, just after the point at which it
   normally does delayed-branch scheduling.  */

static unsigned int
visium_reorg (void)
{
  if (visium_cpu == PROCESSOR_GR5)
    gr5_hazard_avoidance ();

  return 0;
}
/* Return true if an argument must be passed by indirect reference.  */

static bool
visium_pass_by_reference (cumulative_args_t ca ATTRIBUTE_UNUSED,
			  enum machine_mode mode ATTRIBUTE_UNUSED,
			  const_tree type,
			  bool named ATTRIBUTE_UNUSED)
{
  return type && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == VECTOR_TYPE);
}

/* Define how arguments are passed.

   A range of general registers and floating registers is available
   for passing arguments.  When the class of registers which an
   argument would normally use is exhausted, that argument, is passed
   in the overflow region of the stack.  No argument is split between
   registers and stack.

   Arguments of type float or _Complex float go in FP registers if FP
   hardware is available.  If there is no FP hardware, arguments of
   type float go in general registers.  All other arguments are passed
   in general registers.  */

static rtx
visium_function_arg (cumulative_args_t pcum_v, enum machine_mode mode,
		     const_tree type ATTRIBUTE_UNUSED,
		     bool named ATTRIBUTE_UNUSED)
{
  int size;
  CUMULATIVE_ARGS *ca = get_cumulative_args (pcum_v);

  size = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  if (mode == VOIDmode)
    return GEN_INT (0);

  /* Scalar or complex single precision floating point arguments are returned
     in floating registers.  */
  if (TARGET_FPU
      && ((GET_MODE_CLASS (mode) == MODE_FLOAT
	   && GET_MODE_SIZE (mode) <= UNITS_PER_HWFPVALUE)
	  || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
	      && GET_MODE_SIZE (mode) <= UNITS_PER_HWFPVALUE * 2)))
    {
      if (ca->frcount + size <= MAX_ARGS_IN_FP_REGISTERS)
	return gen_rtx_REG (mode, FP_ARG_FIRST + ca->frcount);
      else
	return NULL_RTX;
    }

  if (ca->grcount + size <= MAX_ARGS_IN_GP_REGISTERS)
    return gen_rtx_REG (mode, ca->grcount + GP_ARG_FIRST);

  return NULL_RTX;
}

/* Update the summarizer variable pointed to by PCUM_V to advance past an
   argument in the argument list.  The values MODE, TYPE and NAMED describe
   that argument.  Once this is done, the variable CUM is suitable for
   analyzing the _following_ argument with visium_function_arg.  */

static void
visium_function_arg_advance (cumulative_args_t pcum_v,
			     enum machine_mode mode,
			     const_tree type ATTRIBUTE_UNUSED,
			     bool named)
{
  int size = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  int stack_size = 0;
  CUMULATIVE_ARGS *ca = get_cumulative_args (pcum_v);

  /* Scalar or complex single precision floating point arguments are returned
     in floating registers.  */
  if (TARGET_FPU
      && ((GET_MODE_CLASS (mode) == MODE_FLOAT
	   && GET_MODE_SIZE (mode) <= UNITS_PER_HWFPVALUE)
	  || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
	      && GET_MODE_SIZE (mode) <= UNITS_PER_HWFPVALUE * 2)))
    {
      if (ca->frcount + size <= MAX_ARGS_IN_FP_REGISTERS)
	ca->frcount += size;
      else
	{
	  stack_size = size;
	  ca->frcount = MAX_ARGS_IN_FP_REGISTERS;
	}
    }
  else
    {
      /* Everything else goes in a general register, if enough are
	 available.  */
      if (ca->grcount + size <= MAX_ARGS_IN_GP_REGISTERS)
	ca->grcount += size;
      else
	{
	  stack_size = size;
	  ca->grcount = MAX_ARGS_IN_GP_REGISTERS;
	}
    }

  if (named)
    ca->stack_words += stack_size;
}

/* Specify whether to return the return value in memory.  */

static bool
visium_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
{
  return (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == VECTOR_TYPE);
}

/* Define how scalar values are returned.  */

static rtx
visium_function_value_1 (enum machine_mode mode)
{
  /* Scalar or complex single precision floating point values
     are returned in floating register f1.  */
  if (TARGET_FPU
      && ((GET_MODE_CLASS (mode) == MODE_FLOAT
	   && GET_MODE_SIZE (mode) <= UNITS_PER_HWFPVALUE)
	  || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
	      && GET_MODE_SIZE (mode) <= UNITS_PER_HWFPVALUE * 2)))
    return gen_rtx_REG (mode, FP_RETURN_REGNUM);

  /* All others are returned in r1.  */
  return gen_rtx_REG (mode, RETURN_REGNUM);
}

/* Return an RTX representing the place where a function returns or receives
   a value of data type RET_TYPE.  */

static rtx
visium_function_value (const_tree ret_type,
		       const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
		       bool outgoing ATTRIBUTE_UNUSED)
{
  return visium_function_value_1 (TYPE_MODE (ret_type));
}

/* Return an RTX representing the place where the library function result will
   be returned.  */

static rtx
visium_libcall_value (enum machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED)
{
  return visium_function_value_1 (mode);
}

/* Store the anonymous register arguments into the stack so that all the
   arguments appear to have been passed consecutively on the stack.  */

static void
visium_setup_incoming_varargs (cumulative_args_t pcum_v,
			       enum machine_mode mode,
			       tree type,
			       int *pretend_size ATTRIBUTE_UNUSED,
			       int no_rtl)
{
  cumulative_args_t local_args_so_far;
  CUMULATIVE_ARGS local_copy;
  CUMULATIVE_ARGS *locargs;
  int gp_saved, fp_saved, size;

  /* Create an internal cumulative_args_t pointer to internally define
     storage to ensure calling TARGET_FUNCTION_ARG_ADVANCE does not
     make global changes.  */
  local_args_so_far.p = &local_copy;
  locargs = get_cumulative_args (pcum_v);

#ifdef ENABLE_CHECKING
  local_args_so_far.magic = CUMULATIVE_ARGS_MAGIC;
#endif

  local_copy.grcount = locargs->grcount;
  local_copy.frcount = locargs->frcount;
  local_copy.stack_words = locargs->stack_words;

  /* The caller has advanced ARGS_SO_FAR up to, but not beyond, the last named
     argument.  Advance a local copy of ARGS_SO_FAR past the last "real" named
     argument, to find out how many registers are left over.  */
  TARGET_FUNCTION_ARG_ADVANCE (local_args_so_far, mode, type, 1);

  /* Find how many registers we need to save.  */
  locargs = get_cumulative_args (local_args_so_far);
  gp_saved = MAX_ARGS_IN_GP_REGISTERS - locargs->grcount;
  fp_saved = (TARGET_FPU ? MAX_ARGS_IN_FP_REGISTERS - locargs->frcount : 0);
  size = (gp_saved * UNITS_PER_WORD) + (fp_saved * UNITS_PER_HWFPVALUE);

  if (!no_rtl && size > 0)
    {
      /* To avoid negative offsets, which are not valid addressing modes on
	 the Visium, we create a base register for the pretend args.  */
      rtx ptr
	= force_reg (Pmode,
		     plus_constant (Pmode, virtual_incoming_args_rtx, -size));

      if (gp_saved > 0)
	{
	  rtx mem
	    = gen_rtx_MEM (BLKmode,
			   plus_constant (Pmode,
					  ptr,
					  fp_saved * UNITS_PER_HWFPVALUE));
	  MEM_NOTRAP_P (mem) = 1;
	  set_mem_alias_set (mem, get_varargs_alias_set ());
	  move_block_from_reg (locargs->grcount + GP_ARG_FIRST, mem, gp_saved);
	}

      if (fp_saved > 0)
	{
	  rtx mem = gen_rtx_MEM (BLKmode, ptr);
	  MEM_NOTRAP_P (mem) = 1;
	  set_mem_alias_set (mem, get_varargs_alias_set ());
	  gcc_assert (UNITS_PER_WORD == UNITS_PER_HWFPVALUE);
	  move_block_from_reg (locargs->frcount + FP_ARG_FIRST, mem, fp_saved);
	}
    }

  visium_reg_parm_save_area_size = size;
}

/* Define the `__builtin_va_list' type for the ABI.  */

static tree
visium_build_builtin_va_list (void)
{
  tree f_ovfl, f_gbase, f_fbase, f_gbytes, f_fbytes, record;

  record = (*lang_hooks.types.make_type) (RECORD_TYPE);
  f_ovfl = build_decl (BUILTINS_LOCATION, FIELD_DECL,
		       get_identifier ("__overflow_argptr"), ptr_type_node);
  f_gbase = build_decl (BUILTINS_LOCATION, FIELD_DECL,
			get_identifier ("__gpr_base"), ptr_type_node);
  f_fbase = build_decl (BUILTINS_LOCATION, FIELD_DECL,
			get_identifier ("__fpr_base"), ptr_type_node);
  f_gbytes = build_decl (BUILTINS_LOCATION, FIELD_DECL,
			 get_identifier ("__gpr_bytes"),
			 short_unsigned_type_node);
  f_fbytes = build_decl (BUILTINS_LOCATION, FIELD_DECL,
			 get_identifier ("__fpr_bytes"),
			 short_unsigned_type_node);

  DECL_FIELD_CONTEXT (f_ovfl) = record;
  DECL_FIELD_CONTEXT (f_gbase) = record;
  DECL_FIELD_CONTEXT (f_fbase) = record;
  DECL_FIELD_CONTEXT (f_gbytes) = record;
  DECL_FIELD_CONTEXT (f_fbytes) = record;
  TYPE_FIELDS (record) = f_ovfl;
  TREE_CHAIN (f_ovfl) = f_gbase;
  TREE_CHAIN (f_gbase) = f_fbase;
  TREE_CHAIN (f_fbase) = f_gbytes;
  TREE_CHAIN (f_gbytes) = f_fbytes;
  layout_type (record);

  return record;
}

/* Implement `va_start' for varargs and stdarg.  */

static void
visium_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
{
  const CUMULATIVE_ARGS *ca = &crtl->args.info;
  int gp_saved = MAX_ARGS_IN_GP_REGISTERS - ca->grcount;
  int fp_saved = (TARGET_FPU ? MAX_ARGS_IN_FP_REGISTERS - ca->frcount : 0);
  int named_stack_size = ca->stack_words * UNITS_PER_WORD, offset;
  tree f_ovfl, f_gbase, f_fbase, f_gbytes, f_fbytes;
  tree ovfl, gbase, gbytes, fbase, fbytes, t;

  f_ovfl = TYPE_FIELDS (va_list_type_node);
  f_gbase = TREE_CHAIN (f_ovfl);
  f_fbase = TREE_CHAIN (f_gbase);
  f_gbytes = TREE_CHAIN (f_fbase);
  f_fbytes = TREE_CHAIN (f_gbytes);
  ovfl = build3 (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl, NULL_TREE);
  gbase = build3 (COMPONENT_REF, TREE_TYPE (f_gbase), valist, f_gbase,
		  NULL_TREE);
  fbase = build3 (COMPONENT_REF, TREE_TYPE (f_fbase), valist, f_fbase,
		  NULL_TREE);
  gbytes = build3 (COMPONENT_REF, TREE_TYPE (f_gbytes), valist, f_gbytes,
		   NULL_TREE);
  fbytes = build3 (COMPONENT_REF, TREE_TYPE (f_fbytes), valist, f_fbytes,
		   NULL_TREE);

  /* Store the stacked vararg pointer in the OVFL member.  */
  t = make_tree (TREE_TYPE (ovfl), virtual_incoming_args_rtx);
  t = fold_build_pointer_plus_hwi (t, named_stack_size);
  t = build2 (MODIFY_EXPR, TREE_TYPE (ovfl), ovfl, t);
  expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);

  /* Store the base address of the GPR save area into GBASE.  */
  t = make_tree (TREE_TYPE (gbase), virtual_incoming_args_rtx);
  offset = MAX_ARGS_IN_GP_REGISTERS * UNITS_PER_WORD;
  t = fold_build_pointer_plus_hwi (t, -offset);
  t = build2 (MODIFY_EXPR, TREE_TYPE (gbase), gbase, t);
  expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);

  /* Store the base address of the FPR save area into FBASE.  */
  if (fp_saved)
    {
      t = make_tree (TREE_TYPE (fbase), virtual_incoming_args_rtx);
      offset = gp_saved * UNITS_PER_WORD
	         + MAX_ARGS_IN_FP_REGISTERS * UNITS_PER_HWFPVALUE;
      t = fold_build_pointer_plus_hwi (t, -offset);
      t = build2 (MODIFY_EXPR, TREE_TYPE (fbase), fbase, t);
      expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
    }

  /* Fill in the GBYTES member.  */
  t = build2 (MODIFY_EXPR, TREE_TYPE (gbytes), gbytes,
	      size_int (gp_saved * UNITS_PER_WORD));
  expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);

  /* Fill in the FBYTES member.  */
  t = build2 (MODIFY_EXPR, TREE_TYPE (fbytes),
	      fbytes, size_int (fp_saved * UNITS_PER_HWFPVALUE));
  expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}

/* Implement `va_arg'.  */

static tree
visium_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
			gimple_seq *post_p)
{
  tree f_ovfl, f_gbase, f_fbase, f_gbytes, f_fbytes;
  tree ovfl, base, bytes;
  HOST_WIDE_INT size, rsize;
  const bool by_reference_p
    = pass_by_reference (NULL, TYPE_MODE (type), type, false);
  const bool float_reg_arg_p
    = (TARGET_FPU && !by_reference_p
       && ((GET_MODE_CLASS (TYPE_MODE (type)) == MODE_FLOAT
	    && GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_HWFPVALUE)
	   || (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_COMPLEX_FLOAT
	       && (GET_MODE_SIZE (TYPE_MODE (type))
		   <= UNITS_PER_HWFPVALUE * 2))));
  const int max_save_area_size
    = (float_reg_arg_p ? MAX_ARGS_IN_FP_REGISTERS * UNITS_PER_HWFPVALUE
       : MAX_ARGS_IN_GP_REGISTERS * UNITS_PER_WORD);
  tree t, u, offs;
  tree lab_false, lab_over, addr;
  tree ptrtype = build_pointer_type (type);

  if (by_reference_p)
    {
      t = visium_gimplify_va_arg (valist, ptrtype, pre_p, post_p);
      return build_va_arg_indirect_ref (t);
    }

  size = int_size_in_bytes (type);
  rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
  f_ovfl = TYPE_FIELDS (va_list_type_node);
  f_gbase = TREE_CHAIN (f_ovfl);
  f_fbase = TREE_CHAIN (f_gbase);
  f_gbytes = TREE_CHAIN (f_fbase);
  f_fbytes = TREE_CHAIN (f_gbytes);

  /* We maintain separate pointers and offsets for floating-point and
     general registers, but we need similar code in both cases.

     Let:

     BYTES be the number of unused bytes in the register save area.
     BASE be the base address of the register save area.
     OFFS be the current offset into the register save area. Either
     MAX_ARGS_IN_GP_REGISTERS * UNITS_PER_WORD - bytes or
     MAX_ARGS_IN_FP_REGISTERS * UNITS_PER_HWFPVALUE - bytes
     depending upon whether the argument is in general or floating
     registers.
     ADDR_RTX be the address of the argument.
     RSIZE be the size in bytes of the argument.
     OVFL be the pointer to the stack overflow area.

     The code we want is:

     1: if (bytes >= rsize)
     2:   {
     3:     addr_rtx = base + offs;
     4:     bytes -= rsize;
     5:   }
     6: else
     7:   {
     8:     bytes = 0;
     9:     addr_rtx = ovfl;
     10:     ovfl += rsize;
     11:   }

   */

  addr = create_tmp_var (ptr_type_node, "addr");
  lab_false = create_artificial_label (UNKNOWN_LOCATION);
  lab_over = create_artificial_label (UNKNOWN_LOCATION);
  if (float_reg_arg_p)
    bytes = build3 (COMPONENT_REF, TREE_TYPE (f_fbytes), unshare_expr (valist),
		    f_fbytes, NULL_TREE);
  else
    bytes = build3 (COMPONENT_REF, TREE_TYPE (f_gbytes), unshare_expr (valist),
		    f_gbytes, NULL_TREE);

  /* [1] Emit code to branch if bytes < rsize.  */
  t = fold_convert (TREE_TYPE (bytes), size_int (rsize));
  t = build2 (LT_EXPR, boolean_type_node, bytes, t);
  u = build1 (GOTO_EXPR, void_type_node, lab_false);
  t = build3 (COND_EXPR, void_type_node, t, u, NULL_TREE);
  gimplify_and_add (t, pre_p);

  /* [3] Emit code for: addr_rtx = base + offs, where
     offs = max_save_area_size - bytes.  */
  t = fold_convert (sizetype, bytes);
  offs = build2 (MINUS_EXPR, sizetype, size_int (max_save_area_size), t);
  if (float_reg_arg_p)
    base = build3 (COMPONENT_REF, TREE_TYPE (f_fbase), valist, f_fbase,
		   NULL_TREE);
  else
    base = build3 (COMPONENT_REF, TREE_TYPE (f_gbase), valist, f_gbase,
		   NULL_TREE);

  t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (base), base, offs);
  t = build2 (MODIFY_EXPR, void_type_node, addr, t);
  gimplify_and_add (t, pre_p);

  /* [4] Emit code for: bytes -= rsize. */
  t = fold_convert (TREE_TYPE (bytes), size_int (rsize));
  t = build2 (MINUS_EXPR, TREE_TYPE (bytes), bytes, t);
  t = build2 (MODIFY_EXPR, TREE_TYPE (bytes), bytes, t);
  gimplify_and_add (t, pre_p);

  /* [6] Emit code to branch over the else clause, then the label.  */
  t = build1 (GOTO_EXPR, void_type_node, lab_over);
  gimplify_and_add (t, pre_p);
  t = build1 (LABEL_EXPR, void_type_node, lab_false);
  gimplify_and_add (t, pre_p);

  /* [8] Emit code for: bytes = 0. */
  t = fold_convert (TREE_TYPE (bytes), size_int (0));
  t = build2 (MODIFY_EXPR, TREE_TYPE (bytes), unshare_expr (bytes), t);
  gimplify_and_add (t, pre_p);

  /* [9] Emit code for: addr_rtx = ovfl. */
  ovfl = build3 (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl, NULL_TREE);
  t = build2 (MODIFY_EXPR, void_type_node, addr, ovfl);
  gimplify_and_add (t, pre_p);

  /* [10] Emit code for: ovfl += rsize. */
  t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ovfl), ovfl, size_int (rsize));
  t = build2 (MODIFY_EXPR, TREE_TYPE (ovfl), unshare_expr (ovfl), t);
  gimplify_and_add (t, pre_p);
  t = build1 (LABEL_EXPR, void_type_node, lab_over);
  gimplify_and_add (t, pre_p);
  addr = fold_convert (ptrtype, addr);

  return build_va_arg_indirect_ref (addr);
}

/* Return true if OP is an offset suitable for use as a displacement in the
   address of a memory access in mode MODE.  */

static bool
rtx_ok_for_offset_p (enum machine_mode mode, rtx op)
{
  if (!CONST_INT_P (op) || INTVAL (op) < 0)
    return false;

  switch (mode)
    {
    case QImode:
      return INTVAL (op) <= 31;

    case HImode:
      return (INTVAL (op) % 2) == 0 && INTVAL (op) < 63;

    case SImode:
    case SFmode:
      return (INTVAL (op) % 4) == 0 && INTVAL (op) < 127;

    case DImode:
    case DFmode:
      return (INTVAL (op) % 4) == 0 && INTVAL (op) < 123;

    default:
      return false;
    }
}

/* Return whether X is a legitimate memory address for a memory operand
   of mode MODE.

   Legitimate addresses are defined in two variants: a strict variant
   and a non-strict one.  The STRICT parameter chooses which variant
   is desired by the caller.

   The strict variant is used in the reload pass.  It must be defined
   so that any pseudo-register that has not been allocated a hard
   register is considered a memory reference.  This is because in
   contexts where some kind of register is required, a
   pseudo-register with no hard register must be rejected.  For
   non-hard registers, the strict variant should look up the
   `reg_renumber' array; it should then proceed using the hard
   register number in the array, or treat the pseudo as a memory
   reference if the array holds `-1'.

   The non-strict variant is used in other passes.  It must be
   defined to accept all pseudo-registers in every context where some
   kind of register is required.  */

static bool
visium_legitimate_address_p (enum machine_mode mode, rtx x, bool strict)
{
  rtx base;
  unsigned int regno;

  /* If X is base+disp, check that we have an appropriate offset.  */
  if (GET_CODE (x) == PLUS)
    {
      if (!rtx_ok_for_offset_p (mode, XEXP (x, 1)))
	return false;
      base = XEXP (x, 0);
    }
  else
    base = x;

  /* Now check the base: it must be either a register or a subreg thereof.  */
  if (GET_CODE (base) == SUBREG)
    base = SUBREG_REG (base);
  if (!REG_P (base))
    return false;

  regno = REGNO (base);

  /* For the strict variant, the register must be REGNO_OK_FOR_BASE_P.  */
  if (strict)
    return REGNO_OK_FOR_BASE_P (regno);

  /* For the non-strict variant, the register may also be a pseudo.  */
  return BASE_REGISTER_P (regno) || regno >= FIRST_PSEUDO_REGISTER;
}

/* Try machine-dependent ways of modifying an illegitimate address
   to be legitimate.  If we find one, return the new, valid address.
   This macro is used in only one place: `memory_address' in explow.c.

   OLDX is the address as it was before break_out_memory_refs was called.
   In some cases it is useful to look at this to decide what needs to be done.

   MODE and WIN are passed so that this macro can use
   GO_IF_LEGITIMATE_ADDRESS.

   It is always safe for this macro to do nothing.  It exists to recognize
   opportunities to optimize the output.

   For Visium

	memory (reg + <out of range int>)

   is transformed to

	base_int = <out of range int> & ~mask
        ptr_reg = reg + base_int
        memory (ptr_reg + <out of range int> - base_int)

   Thus ptr_reg is a base register for a range of addresses,
   which should help CSE.

   For a 1 byte reference mask is 0x1f
   for a 2 byte reference mask is 0x3f
   For a 4 byte reference mask is 0x7f

   This reflects the indexing range of the processor.

   For a > 4 byte reference the mask is 0x7f provided all of the words
   can be accessed with the base address obtained.  Otherwise a mask
   of 0x3f is used.

   On rare occasions an unaligned base register value with an
   unaligned offset is generated. Unaligned offsets are left alone for
   this reason. */

static rtx
visium_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
			   enum machine_mode mode)
{
  if (GET_CODE (x) == PLUS
      && GET_CODE (XEXP (x, 1)) == CONST_INT
      && GET_CODE (XEXP (x, 0)) == REG && mode != BLKmode)
    {
      int offset = INTVAL (XEXP (x, 1));
      int size = GET_MODE_SIZE (mode);
      int mask = (size == 1 ? 0x1f : (size == 2 ? 0x3f : 0x7f));
      int mask1 = (size == 1 ? 0 : (size == 2 ? 1 : 3));
      int offset_base = offset & ~mask;

      /* Check that all of the words can be accessed.  */
      if (4 < size && 0x80 < size + offset - offset_base)
	offset_base = offset & ~0x3f;
      if (offset_base != 0 && offset_base != offset && (offset & mask1) == 0)
	{
	  rtx ptr_reg = force_reg (Pmode,
				   gen_rtx_PLUS (Pmode,
						 XEXP (x, 0),
						 GEN_INT (offset_base)));

	  return plus_constant (Pmode, ptr_reg, offset - offset_base);
	}
    }

  return x;
}

/* Perform a similar function to visium_legitimize_address, but this time
   for reload.  Generating new registers is not an option here.  Parts
   that need reloading are indicated by calling push_reload.  */

rtx
visium_legitimize_reload_address (rtx x, enum machine_mode mode, int opnum,
				  int type, int ind ATTRIBUTE_UNUSED)
{
  rtx newrtx, tem = NULL_RTX;

  if (mode == BLKmode)
    return NULL_RTX;

  if (optimize && GET_CODE (x) == PLUS)
    tem = simplify_binary_operation (PLUS, GET_MODE (x), XEXP (x, 0),
				     XEXP (x, 1));

  newrtx = tem ? tem : x;
  if (GET_CODE (newrtx) == PLUS
      && GET_CODE (XEXP (newrtx, 1)) == CONST_INT
      && GET_CODE (XEXP (newrtx, 0)) == REG
      && BASE_REGISTER_P (REGNO (XEXP (newrtx, 0))))
    {
      int offset = INTVAL (XEXP (newrtx, 1));
      int size = GET_MODE_SIZE (mode);
      int mask = (size == 1 ? 0x1f : (size == 2 ? 0x3f : 0x7f));
      int mask1 = (size == 1 ? 0 : (size == 2 ? 1 : 3));
      int offset_base = offset & ~mask;

      /* Check that all of the words can be accessed.  */
      if (4 < size && 0x80 < size + offset - offset_base)
	offset_base = offset & ~0x3f;

      if (offset_base && (offset & mask1) == 0)
	{
	  rtx temp = gen_rtx_PLUS (Pmode,
				   XEXP (newrtx, 0), GEN_INT (offset_base));

	  x = gen_rtx_PLUS (Pmode, temp, GEN_INT (offset - offset_base));
	  push_reload (XEXP (x, 0), 0, &XEXP (x, 0), 0,
		       BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, opnum,
		       (enum reload_type) type);
	  return x;
	}
    }

  return NULL_RTX;
}

/* Return the cost of moving data of mode MODE from a register in class FROM to
   one in class TO.  A value of 2 is the default; other values are interpreted
   relative to that.  */

static int
visium_register_move_cost (enum machine_mode mode, reg_class_t from,
			   reg_class_t to)
{
  const int numwords = (GET_MODE_SIZE (mode) <= UNITS_PER_WORD) ? 1 : 2;

  if (from == MDB || to == MDB)
    return 4;
  else if (from == MDC || to == MDC || (from == FP_REGS) != (to == FP_REGS))
    return 4 * numwords;
  else
    return 2 * numwords;
}

/* Return the cost of moving data of mode MODE between a register of class
   CLASS and memory.  IN is zero if the value is to be written to memory,
   non-zero if it is to be read in.  This cost is relative to those in
   visium_register_move_cost.  */

static int
visium_memory_move_cost (enum machine_mode mode,
			 reg_class_t to ATTRIBUTE_UNUSED,
			 bool in)
{
  /* Moving data in can be from PROM and this is expensive.  */
  if (in)
    {
      if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
	return 7;
      else
	return 13;
    }

  /* Moving data out is mostly to RAM and should be cheaper.  */
  else
    {
      if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
	return 6;
      else
	return 12;
    }
}

/* Return the relative costs of expression X.  */

static bool
visium_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
		  int opno ATTRIBUTE_UNUSED, int *total,
		  bool speed ATTRIBUTE_UNUSED)
{
  enum machine_mode mode = GET_MODE (x);

  switch (code)
    {
    case CONST_INT:
      /* Small integers are as cheap as registers.  4-byte values can
	 be fetched as immediate constants - let's give that the cost
	 of an extra insn.  */
      *total = COSTS_N_INSNS (!satisfies_constraint_J (x));
      return true;

    case CONST:
    case LABEL_REF:
    case SYMBOL_REF:
      *total = COSTS_N_INSNS (2);
      return true;

    case CONST_DOUBLE:
      {
	rtx high, low;
	split_double (x, &high, &low);
	*total =
	  COSTS_N_INSNS
	  (!satisfies_constraint_J (high) + !satisfies_constraint_J (low));
	return true;
      }

    case MULT:
      *total = COSTS_N_INSNS (3);
      return false;

    case DIV:
    case UDIV:
    case MOD:
    case UMOD:
      if (mode == DImode)
	*total = COSTS_N_INSNS (64);
      else
	*total = COSTS_N_INSNS (32);
      return false;

    case PLUS:
    case MINUS:
    case NEG:
      /* DImode operations are performed directly on the ALU.  */
      if (mode == DImode)
	*total = COSTS_N_INSNS (2);
      else
	*total = COSTS_N_INSNS (1);
      return false;

    case ASHIFT:
    case ASHIFTRT:
    case LSHIFTRT:
      /* DImode operations are performed on the EAM instead.  */
      if (mode == DImode)
	*total = COSTS_N_INSNS (3);
      else
	*total = COSTS_N_INSNS (1);
      return false;

    case COMPARE:
      /* This matches the btst pattern.  */
      if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
	  && XEXP (x, 1) == const0_rtx
	  && XEXP (XEXP (x, 0), 1) == const1_rtx
	  && satisfies_constraint_K (XEXP (XEXP (x, 0), 2)))
	*total = COSTS_N_INSNS (1);
      return false;

    default:
      return false;
    }
}

/* Split a double move of OPERANDS in MODE.  */

void
split_double_move (rtx *operands, enum machine_mode mode)
{
  bool swap = false;

  /* Check register to register with overlap.  */
  if (GET_CODE (operands[0]) == REG
       && GET_CODE (operands[1]) == REG
       && REGNO (operands[0]) == REGNO (operands[1]) + 1)
    swap = true;

  /* Check memory to register where the base reg overlaps the destination.  */
  if (GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == MEM)
    {
      rtx op = XEXP (operands[1], 0);

      if (GET_CODE (op) == SUBREG)
	op = SUBREG_REG (op);

      if (GET_CODE (op) == REG  && REGNO (op) == REGNO (operands[0]))
	swap = true;

      if (GET_CODE (op) == PLUS)
	{
	  rtx x = XEXP (op, 0);
	  rtx y = XEXP (op, 1);

	  if (GET_CODE (x) == REG && REGNO (x) == REGNO (operands[0]))
	    swap = true;

	  if (GET_CODE (y) == REG && REGNO (y) == REGNO (operands[0]))
	    swap = true;
	}
    }

  if (swap)
    {
      operands[2] = operand_subword (operands[0], 1, 1, mode);
      operands[3] = operand_subword (operands[1], 1, 1, mode);
      operands[4] = operand_subword (operands[0], 0, 1, mode);
      operands[5] = operand_subword (operands[1], 0, 1, mode);
    }
  else
    {
      operands[2] = operand_subword (operands[0], 0, 1, mode);
      operands[3] = operand_subword (operands[1], 0, 1, mode);
      operands[4] = operand_subword (operands[0], 1, 1, mode);
      operands[5] = operand_subword (operands[1], 1, 1, mode);
    }
}

/* Expand a copysign of OPERANDS in MODE.  */

void
visium_expand_copysign (rtx *operands, enum machine_mode mode)
{
  rtx dest = operands[0];
  rtx op0 = operands[1];
  rtx op1 = operands[2];
  rtx mask = force_reg (SImode, GEN_INT (0x7fffffff));
  rtx x;

  /* We manually handle SFmode because the abs and neg instructions of
     the FPU on the MCM have a non-standard behavior wrt NaNs.  */
  gcc_assert (mode == SFmode);

  /* First get all the non-sign bits of OP0.  */
  if (GET_CODE (op0) == CONST_DOUBLE)
    {
      if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
	op0 = simplify_unary_operation (ABS, mode, op0, mode);
      if (op0 != CONST0_RTX (mode))
	{
	  long l;
	  REAL_VALUE_TYPE rv;
	  REAL_VALUE_FROM_CONST_DOUBLE (rv, op0);
	  REAL_VALUE_TO_TARGET_SINGLE (rv, l);
	  op0 = force_reg (SImode, GEN_INT (trunc_int_for_mode (l, SImode)));
	}
    }
  else
    {
      op0 = copy_to_mode_reg (SImode, gen_lowpart (SImode, op0));
      op0 = force_reg (SImode, gen_rtx_AND (SImode, op0, mask));
    }

  /* Then get the sign bit of OP1.  */
  mask = force_reg (SImode, gen_rtx_NOT (SImode, mask));
  op1 = copy_to_mode_reg (SImode, gen_lowpart (SImode, op1));
  op1 = force_reg (SImode, gen_rtx_AND (SImode, op1, mask));

  /* Finally OR the two values.  */
  if (op0 == CONST0_RTX (SFmode))
    x = op1;
  else
    x = force_reg (SImode, gen_rtx_IOR (SImode, op0, op1));

  /* And move the result to the destination.  */
  emit_insn (gen_rtx_SET (dest, gen_lowpart (SFmode, x)));
}

/* Expand a cstore of OPERANDS in MODE for EQ/NE/LTU/GTU/GEU/LEU.  We generate
   the result in the C flag and use the ADC/SUBC instructions to write it into
   the destination register.

   It would also be possible to implement support for LT/GT/LE/GE by means of
   the RFLAG instruction followed by some shifts, but this can pessimize the
   generated code.  */

void
visium_expand_int_cstore (rtx *operands, enum machine_mode mode)
{
  enum rtx_code code = GET_CODE (operands[1]);
  rtx op0 = operands[0], op1 = operands[2], op2 = operands[3], sltu;
  bool reverse = false;

  switch (code)
    {
    case EQ:
    case NE:
      /* We use a special comparison to get the result in the C flag.  */
      if (op2 != const0_rtx)
	op1 = force_reg (mode, gen_rtx_XOR (mode, op1, op2));
      op1 = gen_rtx_NOT (mode, op1);
      op2 = constm1_rtx;
      if (code == EQ)
	reverse = true;
      break;

    case LEU:
    case GEU:
      /* The result is naturally in the C flag modulo a couple of tricks.  */
      code = reverse_condition (code);
      reverse = true;

      /* ... fall through ...  */

    case LTU:
    case GTU:
      if (code == GTU)
	{
	  rtx tmp = op1;
	  op1 = op2;
	  op2 = tmp;
	}
      break;

    default:
      gcc_unreachable ();
    }

  /* We need either a single ADC or a SUBC and a PLUS.  */
  sltu = gen_rtx_LTU (SImode, op1, op2);

  if (reverse)
    {
      rtx tmp = copy_to_mode_reg (SImode, gen_rtx_NEG (SImode, sltu));
      emit_insn (gen_add3_insn (op0, tmp, const1_rtx));
    }
  else
    emit_insn (gen_rtx_SET (op0, sltu));
}

/* Expand a cstore of OPERANDS in MODE for LT/GT/UNGE/UNLE.  We generate the
   result in the C flag and use the ADC/SUBC instructions to write it into
   the destination register.  */

void
visium_expand_fp_cstore (rtx *operands,
			 enum machine_mode mode ATTRIBUTE_UNUSED)
{
  enum rtx_code code = GET_CODE (operands[1]);
  rtx op0 = operands[0], op1 = operands[2], op2 = operands[3], slt;
  bool reverse = false;

  switch (code)
    {
    case UNLE:
    case UNGE:
      /* The result is naturally in the C flag modulo a couple of tricks.  */
      code = reverse_condition_maybe_unordered (code);
      reverse = true;

      /* ... fall through ...  */

    case LT:
    case GT:
      if (code == GT)
	{
	  rtx tmp = op1;
	  op1 = op2;
	  op2 = tmp;
	}
      break;

    default:
      gcc_unreachable ();
    }

  /* We need either a single ADC or a SUBC and a PLUS.  */
  slt = gen_rtx_LT (SImode, op1, op2);

  if (reverse)
    {
      rtx tmp = copy_to_mode_reg (SImode, gen_rtx_NEG (SImode, slt));
      emit_insn (gen_add3_insn (op0, tmp, const1_rtx));
    }
  else
    emit_insn (gen_rtx_SET (op0, slt));
}

/* Split a compare-and-store with CODE, operands OP2 and OP3, combined with
   operation with OP_CODE, operands OP0 and OP1.  */

void
visium_split_cstore (enum rtx_code op_code, rtx op0, rtx op1,
		     enum rtx_code code, rtx op2, rtx op3)
{
  enum machine_mode cc_mode = visium_select_cc_mode (code, op2, op3);

  /* If a FP cstore was reversed, then it was originally UNGE/UNLE.  */
  if (cc_mode == CCFPEmode && (op_code == NEG || op_code == MINUS))
    cc_mode = CCFPmode;

  rtx flags = gen_rtx_REG (cc_mode, FLAGS_REGNUM);
  rtx x = gen_rtx_COMPARE (cc_mode, op2, op3);
  x = gen_rtx_SET (flags, x);
  emit_insn (x);

  x = gen_rtx_fmt_ee (code, SImode, flags, const0_rtx);
  switch (op_code)
    {
    case SET:
      break;
    case NEG:
      x = gen_rtx_NEG (SImode, x);
      break;
    case PLUS:
    case MINUS:
      x = gen_rtx_fmt_ee (op_code, SImode, op1, x);
      break;
    default:
      gcc_unreachable ();
    }

  rtx pat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
  XVECEXP (pat, 0, 0) = gen_rtx_SET (op0, x);
  flags = gen_rtx_REG (CCmode, FLAGS_REGNUM);
  XVECEXP (pat, 0, 1) = gen_rtx_CLOBBER (VOIDmode, flags);
  emit_insn (pat);

  visium_flags_exposed = true;
}

/* Generate a call to a library function to move BYTES_RTX bytes from SRC with
   address SRC_REG to DST with address DST_REG in 4-byte chunks.  */

static void
expand_block_move_4 (rtx dst, rtx dst_reg, rtx src, rtx src_reg, rtx bytes_rtx)
{
  const rtx sym = gen_rtx_SYMBOL_REF (Pmode, "__long_int_memcpy");
  unsigned HOST_WIDE_INT bytes = UINTVAL (bytes_rtx);
  unsigned int rem = bytes % 4;

  if (TARGET_BMI)
    {
      unsigned int i;
      rtx insn;

      emit_move_insn (regno_reg_rtx[1], dst_reg);
      emit_move_insn (regno_reg_rtx[2], src_reg);
      emit_move_insn (regno_reg_rtx[3], bytes_rtx);

      insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (8));
      XVECEXP (insn, 0, 0)
	= gen_rtx_SET (replace_equiv_address_nv (dst, regno_reg_rtx[1]),
		       replace_equiv_address_nv (src, regno_reg_rtx[2]));
      XVECEXP (insn, 0, 1) = gen_rtx_USE (VOIDmode, regno_reg_rtx[3]);
      for (i = 1; i <= 6; i++)
	XVECEXP (insn, 0, 1 + i)
	  = gen_rtx_CLOBBER (VOIDmode, regno_reg_rtx[i]);
      emit_insn (insn);
    }
  else
    emit_library_call (sym, LCT_NORMAL, VOIDmode, 3, dst_reg, Pmode, src_reg,
		       Pmode,
		       convert_to_mode (TYPE_MODE (sizetype),
					GEN_INT (bytes >> 2),
				        TYPE_UNSIGNED (sizetype)),
		       TYPE_MODE (sizetype));
  if (rem == 0)
    return;

  dst = replace_equiv_address_nv (dst, dst_reg);
  src = replace_equiv_address_nv (src, src_reg);
  bytes -= rem;

  if (rem > 1)
    {
      emit_move_insn (adjust_address_nv (dst, HImode, bytes),
		      adjust_address_nv (src, HImode, bytes));
      bytes += 2;
      rem -= 2;
    }

  if (rem > 0)
    emit_move_insn (adjust_address_nv (dst, QImode, bytes),
		    adjust_address_nv (src, QImode, bytes));
}

/* Generate a call to a library function to move BYTES_RTX bytes from SRC with
   address SRC_REG to DST with address DST_REG in 2-bytes chunks.  */

static void
expand_block_move_2 (rtx dst, rtx dst_reg, rtx src, rtx src_reg, rtx bytes_rtx)
{
  const rtx sym = gen_rtx_SYMBOL_REF (Pmode, "__wrd_memcpy");
  unsigned HOST_WIDE_INT bytes = UINTVAL (bytes_rtx);
  unsigned int rem = bytes % 2;

  emit_library_call (sym, LCT_NORMAL, VOIDmode, 3, dst_reg, Pmode, src_reg,
		     Pmode,
		     convert_to_mode (TYPE_MODE (sizetype),
				      GEN_INT (bytes >> 1),
				      TYPE_UNSIGNED (sizetype)),
		     TYPE_MODE (sizetype));
  if (rem == 0)
    return;

  dst = replace_equiv_address_nv (dst, dst_reg);
  src = replace_equiv_address_nv (src, src_reg);
  bytes -= rem;

  emit_move_insn (adjust_address_nv (dst, QImode, bytes),
		  adjust_address_nv (src, QImode, bytes));
}

/* Generate a call to a library function to move BYTES_RTX bytes from address
   SRC_REG to address DST_REG in 1-byte chunks.  */

static void
expand_block_move_1 (rtx dst_reg, rtx src_reg, rtx bytes_rtx)
{
  const rtx sym = gen_rtx_SYMBOL_REF (Pmode, "__byt_memcpy");

  emit_library_call (sym, LCT_NORMAL, VOIDmode, 3, dst_reg, Pmode,
		     src_reg, Pmode,
		     convert_to_mode (TYPE_MODE (sizetype),
				      bytes_rtx,
				      TYPE_UNSIGNED (sizetype)),
		     TYPE_MODE (sizetype));
}

/* Generate a call to a library function to set BYTES_RTX bytes of DST with
   address DST_REG to VALUE_RTX in 4-byte chunks.  */

static void
expand_block_set_4 (rtx dst, rtx dst_reg, rtx value_rtx, rtx bytes_rtx)
{
  const rtx sym = gen_rtx_SYMBOL_REF (Pmode, "__long_int_memset");
  unsigned HOST_WIDE_INT bytes = UINTVAL (bytes_rtx);
  unsigned int rem = bytes % 4;

  value_rtx = convert_to_mode (Pmode, value_rtx, 1);
  emit_library_call (sym, LCT_NORMAL, VOIDmode, 3, dst_reg, Pmode,
		     value_rtx, Pmode,
		     convert_to_mode (TYPE_MODE (sizetype),
				      GEN_INT (bytes >> 2),
				      TYPE_UNSIGNED (sizetype)),
		     TYPE_MODE (sizetype));
  if (rem == 0)
    return;

  dst = replace_equiv_address_nv (dst, dst_reg);
  bytes -= rem;

  if (rem > 1)
    {
      if (CONST_INT_P (value_rtx))
	{
	  const unsigned HOST_WIDE_INT value = UINTVAL (value_rtx) & 0xff;
	  emit_move_insn (adjust_address_nv (dst, HImode, bytes),
			  gen_int_mode ((value << 8) | value, HImode));
	}
      else
	{
	  rtx temp = convert_to_mode (QImode, value_rtx, 1);
	  emit_move_insn (adjust_address_nv (dst, QImode, bytes), temp);
	  emit_move_insn (adjust_address_nv (dst, QImode, bytes + 1), temp);
	}
      bytes += 2;
      rem -= 2;
    }

  if (rem > 0)
    emit_move_insn (adjust_address_nv (dst, QImode, bytes),
		    convert_to_mode (QImode, value_rtx, 1));
}

/* Generate a call to a library function to set BYTES_RTX bytes of DST with
   address DST_REG to VALUE_RTX in 2-byte chunks.  */

static void
expand_block_set_2 (rtx dst, rtx dst_reg, rtx value_rtx, rtx bytes_rtx)
{
  const rtx sym = gen_rtx_SYMBOL_REF (Pmode, "__wrd_memset");
  unsigned HOST_WIDE_INT bytes = UINTVAL (bytes_rtx);
  unsigned int rem = bytes % 2;

  value_rtx = convert_to_mode (Pmode, value_rtx, 1);
  emit_library_call (sym, LCT_NORMAL, VOIDmode, 3, dst_reg, Pmode,
		     value_rtx, Pmode,
		     convert_to_mode (TYPE_MODE (sizetype),
				      GEN_INT (bytes >> 1),
				      TYPE_UNSIGNED (sizetype)),
		     TYPE_MODE (sizetype));
  if (rem == 0)
    return;

  dst = replace_equiv_address_nv (dst, dst_reg);
  bytes -= rem;

  emit_move_insn (adjust_address_nv (dst, QImode, bytes),
		  convert_to_mode (QImode, value_rtx, 1));
}

/* Generate a call to a library function to set BYTES_RTX bytes at address
   DST_REG to VALUE_RTX in 1-byte chunks.  */

static void
expand_block_set_1 (rtx dst_reg, rtx value_rtx, rtx bytes_rtx)
{
  const rtx sym = gen_rtx_SYMBOL_REF (Pmode, "__byt_memset");

  value_rtx = convert_to_mode (Pmode, value_rtx, 1);
  emit_library_call (sym, LCT_NORMAL, VOIDmode, 3, dst_reg, Pmode,
		     value_rtx, Pmode,
		     convert_to_mode (TYPE_MODE (sizetype),
				      bytes_rtx,
				      TYPE_UNSIGNED (sizetype)),
		     TYPE_MODE (sizetype));
}

/* Expand string/block move operations.

   operands[0] is the pointer to the destination.
   operands[1] is the pointer to the source.
   operands[2] is the number of bytes to move.
   operands[3] is the alignment.

   Return 1 upon success, 0 otherwise.  */

int
visium_expand_block_move (rtx *operands)
{
  rtx dst = operands[0];
  rtx src = operands[1];
  rtx bytes_rtx = operands[2];
  rtx align_rtx = operands[3];
  const int align = INTVAL (align_rtx);
  rtx dst_reg, src_reg;
  tree dst_expr, src_expr;

  /* We only handle a fixed number of bytes for now.  */
  if (!CONST_INT_P (bytes_rtx) || INTVAL (bytes_rtx) <= 0)
    return 0;

  /* Copy the addresses into scratch registers.  */
  dst_reg = copy_addr_to_reg (XEXP (dst, 0));
  src_reg = copy_addr_to_reg (XEXP (src, 0));

  /* Move the data with the appropriate granularity.  */
  if (align >= 4)
    expand_block_move_4 (dst, dst_reg, src, src_reg, bytes_rtx);
  else if (align >= 2)
    expand_block_move_2 (dst, dst_reg, src, src_reg, bytes_rtx);
  else
    expand_block_move_1 (dst_reg, src_reg, bytes_rtx);

  /* Since DST and SRC are passed to a libcall, mark the corresponding
     tree EXPR as addressable.  */
  dst_expr = MEM_EXPR (dst);
  src_expr = MEM_EXPR (src);
  if (dst_expr)
    mark_addressable (dst_expr);
  if (src_expr)
    mark_addressable (src_expr);

  return 1;
}

/* Expand string/block set operations.

   operands[0] is the pointer to the destination.
   operands[1] is the number of bytes to set.
   operands[2] is the source value.
   operands[3] is the alignment.

   Return 1 upon success, 0 otherwise.  */

int
visium_expand_block_set (rtx *operands)
{
  rtx dst = operands[0];
  rtx bytes_rtx = operands[1];
  rtx value_rtx = operands[2];
  rtx align_rtx = operands[3];
  const int align = INTVAL (align_rtx);
  rtx dst_reg;
  tree dst_expr;

  /* We only handle a fixed number of bytes for now.  */
  if (!CONST_INT_P (bytes_rtx) || INTVAL (bytes_rtx) <= 0)
    return 0;

  /* Copy the address into a scratch register.  */
  dst_reg = copy_addr_to_reg (XEXP (dst, 0));

  /* Set the data with the appropriate granularity.  */
  if (align >= 4)
    expand_block_set_4 (dst, dst_reg, value_rtx, bytes_rtx);
  else if (align >= 2)
    expand_block_set_2 (dst, dst_reg, value_rtx, bytes_rtx);
  else
    expand_block_set_1 (dst_reg, value_rtx, bytes_rtx);

  /* Since DST is passed to a libcall, mark the corresponding
     tree EXPR as addressable.  */
  dst_expr = MEM_EXPR (dst);
  if (dst_expr)
    mark_addressable (dst_expr);

  return 1;
}

/* Initialize a trampoline.  M_TRAMP is an RTX for the memory block for the
   trampoline, FNDECL is the FUNCTION_DECL for the nested function and
   STATIC_CHAIN is an RTX for the static chain value that should be passed
   to the function when it is called.  */

static void
visium_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
{
  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
  rtx addr = XEXP (m_tramp, 0);

  /* The trampoline initialization sequence is:

	moviu   r9,%u FUNCTION
	movil   r9,%l FUNCTION
	moviu   r20,%u STATIC
	bra     tr,r9,r9
	 movil   r20,%l STATIC

     We don't use r0 as the destination register of the branch because we want
     the Branch Pre-decode Logic of the GR6 to use the Address Load Array to
     predict the branch target.  */

  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, addr, 0)),
		  plus_constant (SImode,
				 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
					       16, NULL_RTX, 1),
				 0x04a90000));

  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, addr, 4)),
		  plus_constant (SImode,
				 expand_and (SImode, fnaddr, GEN_INT (0xffff),
					     NULL_RTX),
				 0x04890000));

  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, addr, 8)),
		  plus_constant (SImode,
				 expand_shift (RSHIFT_EXPR, SImode,
					       static_chain,
					       16, NULL_RTX, 1),
				 0x04b40000));

  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, addr, 12)),
		  gen_int_mode (0xff892404, SImode));

  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, addr, 16)),
		  plus_constant (SImode,
				 expand_and (SImode, static_chain,
					     GEN_INT (0xffff), NULL_RTX),
				 0x04940000));

  emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__set_trampoline_parity"),
		     LCT_NORMAL, VOIDmode, 1, addr, SImode);
}

/* Return true if the current function must have and use a frame pointer.  */

static bool
visium_frame_pointer_required (void)
{
  /* The frame pointer is required if the function isn't leaf to be able to
     do manual stack unwinding.  */
  if (!crtl->is_leaf)
    return true;

  /* If the stack pointer is dynamically modified in the function, it cannot
     serve as the frame pointer.  */
  if (!crtl->sp_is_unchanging)
    return true;

  /* If the function receives nonlocal gotos, it needs to save the frame
     pointer in the nonlocal_goto_save_area object.  */
  if (cfun->has_nonlocal_label)
    return true;

  /* The frame also needs to be established in some special cases.  */
  if (visium_frame_needed)
    return true;

  return false;
}

/* Profiling support.  Just a call to MCOUNT is needed.  No labelled counter
   location is involved.  Proper support for __builtin_return_address is also
   required, which is fairly straightforward provided a frame gets created.  */

void
visium_profile_hook (void)
{
  visium_frame_needed = true;
  emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "mcount"), LCT_NORMAL,
		     VOIDmode, 0);
}

/* A C expression whose value is RTL representing the address in a stack frame
   where the pointer to the caller's frame is stored.  Assume that FRAMEADDR is
   an RTL expression for the address of the stack frame itself.

   If you don't define this macro, the default is to return the value of
   FRAMEADDR--that is, the stack frame address is also the address of the stack
   word that points to the previous frame.  */

rtx
visium_dynamic_chain_address (rtx frame)
{
  /* This is the default, but we need to make sure the frame gets created.  */
  visium_frame_needed = true;
  return frame;
}

/* A C expression whose value is RTL representing the value of the return
   address for the frame COUNT steps up from the current frame, after the
   prologue.  FRAMEADDR is the frame pointer of the COUNT frame, or the frame
   pointer of the COUNT - 1 frame if `RETURN_ADDR_IN_PREVIOUS_FRAME' is
   defined.

   The value of the expression must always be the correct address when COUNT is
   zero, but may be `NULL_RTX' if there is not way to determine the return
   address of other frames.  */

rtx
visium_return_addr_rtx (int count, rtx frame ATTRIBUTE_UNUSED)
{
  /* Dont try to compute anything other than frame zero.  */
  if (count != 0)
    return NULL_RTX;

  visium_frame_needed = true;
  return
    gen_frame_mem (Pmode, plus_constant (Pmode, hard_frame_pointer_rtx, 4));
}

/* Helper function for EH_RETURN_HANDLER_RTX.  Return the RTX representing a
   location in which to store the address of an exception handler to which we
   should return.  */

rtx
visium_eh_return_handler_rtx (void)
{
  rtx mem
    = gen_frame_mem (SImode, plus_constant (Pmode, hard_frame_pointer_rtx, 4));
  MEM_VOLATILE_P (mem) = 1;
  return mem;
}

static struct machine_function *
visium_init_machine_status (void)
{
  return ggc_cleared_alloc<machine_function> ();
}

/* The per-function data machinery is needed to indicate when a frame
   is required. */

void
visium_init_expanders (void)
{
  init_machine_status = visium_init_machine_status;
}

/* Given a comparison code (EQ, NE, etc.) and the operands of a COMPARE,
   return the mode to be used for the comparison.  */

enum machine_mode
visium_select_cc_mode (enum rtx_code code, rtx op0, rtx op1)
{
  if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_FLOAT)
    {
      switch (code)
	{
	case EQ:
	case NE:
	case ORDERED:
	case UNORDERED:
	case UNLT:
	case UNLE:
	case UNGT:
	case UNGE:
	  return CCFPmode;

	case LT:
	case LE:
	case GT:
	case GE:
	  return CCFPEmode;

	/* These 2 comparison codes are not supported.  */
	case UNEQ:
	case LTGT:
	default:
	  gcc_unreachable ();
	}
    }

  if (op1 != const0_rtx)
    return CCmode;

  switch (GET_CODE (op0))
    {
    case PLUS:
    case MINUS:
    case NEG:
    case ASHIFT:
    case LTU:
    case LT:
      /* The V flag may be set differently from a COMPARE with zero.
	 The consequence is that a comparison operator testing V must
	 be turned into another operator not testing V and yielding
	 the same result for a comparison with zero.  That's possible
	 for GE/LT which become NC/NS respectively, but not for GT/LE
	 for which the altered operator doesn't exist on the Visium.  */
      return CC_NOOVmode;

    case ZERO_EXTRACT:
      /* This is a btst, the result is in C instead of Z.  */
      return CC_BTSTmode;

    case CONST_INT:
      /* This is a degenerate case, typically an uninitialized variable.  */
      gcc_assert (op0 == constm1_rtx);
    case REG:
    case AND:
    case IOR:
    case XOR:
    case NOT:
    case ASHIFTRT:
    case LSHIFTRT:
    case TRUNCATE:
    case SIGN_EXTEND:
      /* Pretend that the flags are set as for a COMPARE with zero.
	 That's mostly true, except for the 2 right shift insns that
	 will set the C flag.  But the C flag is relevant only for
	 the unsigned comparison operators and they are eliminated
	 when applied to a comparison with zero.  */
      return CCmode;

    default:
      gcc_unreachable ();
    }
}

/* Split a compare-and-branch with CODE, operands OP0 and OP1, and LABEL.  */

void
visium_split_cbranch (enum rtx_code code, rtx op0, rtx op1, rtx label)
{
  enum machine_mode cc_mode = visium_select_cc_mode (code, op0, op1);
  rtx flags = gen_rtx_REG (cc_mode, FLAGS_REGNUM);

  rtx x = gen_rtx_COMPARE (cc_mode, op0, op1);
  x = gen_rtx_SET (flags, x);
  emit_insn (x);

  x = gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
  x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, gen_rtx_LABEL_REF (Pmode, label),
			    pc_rtx);
  x = gen_rtx_SET (pc_rtx, x);
  emit_jump_insn (x);

  visium_flags_exposed = true;
}

/* Branch instructions on the Visium.

   Setting aside the interrupt-handling specific instructions, the ISA has
   two branch instructions: BRR and BRA.  The former is used to implement
   short branches (+/- 2^17) within functions and its target is encoded in
   the instruction.  The latter is used to implement all the other types
   of control flow changes and its target might not be statically known
   or even easily predictable at run time.  Here's a complete summary of
   the patterns that generate a BRA instruction:

     1. Indirect jump
     2. Table jump
     3. Call
     4. Sibling call
     5. Return
     6. Long branch
     7. Trampoline

   Among these patterns, only the return (5) and the long branch (6) can be
   conditional; all the other patterns are always unconditional.

   The following algorithm can be used to identify the pattern for which
   the BRA instruction was generated and work out its target:

     A. If the source is r21 and the destination is r0, this is a return (5)
	and the target is the caller (i.e. the value of r21 on function's
	entry).

     B. If the source is rN, N != 21 and the destination is r0, this is either
	an indirect jump or a table jump (1, 2) and the target is not easily
	predictable.

     C. If the source is rN, N != 21 and the destination is r21, this is a call
	(3) and the target is given by the preceding MOVIL/MOVIU pair for rN,
	unless this is an indirect call in which case the target is not easily
	predictable.

     D. If the source is rN, N != 21 and the destination is also rN, this is
	either a sibling call or a trampoline (4, 7) and the target is given
	by the preceding MOVIL/MOVIU pair for rN.

     E. If the source is r21 and the destination is also r21, this is a long
	branch (6) and the target is given by the preceding MOVIL/MOVIU pair
	for r21.

   The other combinations are not used.  This implementation has been devised
   to accommodate the branch predictor of the GR6 but is used unconditionally
   by the compiler, i.e. including for earlier processors.  */

/* Output a conditional/unconditional branch to LABEL.  COND is the string
   condition.  INSN is the instruction.  */

static const char *
output_branch (rtx label, const char *cond, rtx_insn *insn)
{
  char str[64];
  rtx operands[2];

  gcc_assert (cond);
  operands[0] = label;

  /* If the length of the instruction is greater than 8, then this is a
     long branch and we need to work harder to emit it properly.  */
  if (get_attr_length (insn) > 8)
    {
      bool spilled;

      /* If the link register has been saved, then we use it.  */
      if (current_function_saves_lr ())
	{
	  operands[1] = regno_reg_rtx [LINK_REGNUM];
	  spilled = false;
	}

      /* Or else, if the long-branch register isn't live, we use it.  */
      else if (!df_regs_ever_live_p (long_branch_regnum))
	{
	  operands[1] = regno_reg_rtx [long_branch_regnum];
	  spilled = false;
	}

      /* Otherwise, we will use the long-branch register but we need to
	 spill it to the stack and reload it at the end.  We should have
	 reserved the LR slot for this purpose.  */
      else
	{
	  operands[1] = regno_reg_rtx [long_branch_regnum];
	  spilled = true;
	  gcc_assert (current_function_has_lr_slot ());
	}

      /* First emit the spill to the stack:

	   insn_in_delay_slot
	   write.l [1](sp),reg  */
      if (spilled)
	{
	  if (final_sequence)
	    {
	      rtx_insn *delay = NEXT_INSN (insn);
	      int seen;
	      gcc_assert (delay);

	      final_scan_insn (delay, asm_out_file, optimize, 0, &seen);
	      PATTERN (delay) = gen_blockage ();
	      INSN_CODE (delay) = -1;
	    }

	  if (current_function_saves_fp ())
	    output_asm_insn ("write.l 1(sp),%1", operands);
	  else
	    output_asm_insn ("write.l (sp),%1", operands);
	}

      /* Then emit the core sequence:

	   moviu   reg,%u label
	   movil   reg,%l label
	   bra     tr,reg,reg

	 We don't use r0 as the destination register of the branch because we
	 want the Branch Pre-decode Logic of the GR6 to use the Address Load
	 Array to predict the branch target.  */
      output_asm_insn ("moviu   %1,%%u %0", operands);
      output_asm_insn ("movil   %1,%%l %0", operands);
      strcpy (str, "bra     ");
      strcat (str, cond);
      strcat (str, ",%1,%1");
      if (!spilled)
	strcat (str, "%#");
      strcat (str, "\t\t;long branch");
      output_asm_insn (str, operands);

      /* Finally emit the reload:

	    read.l reg,[1](sp)  */
      if (spilled)
	{
	  if (current_function_saves_fp ())
	    output_asm_insn (" read.l %1,1(sp)", operands);
	  else
	    output_asm_insn (" read.l %1,(sp)", operands);
	}
    }

  /* Or else, if the label is PC, then this is a return.  */
  else if (label == pc_rtx)
    {
      strcpy (str, "bra     ");
      strcat (str, cond);
      strcat (str, ",r21,r0%#\t\t;return");
      output_asm_insn (str, operands);
    }

  /* Otherwise, this is a short branch.  */
  else
    {
      strcpy (str, "brr     ");
      strcat (str, cond);
      strcat (str, ",%0%#");
      output_asm_insn (str, operands);
    }

  return "";
}

/* Output an unconditional branch to LABEL.  INSN is the instruction.  */

const char *
output_ubranch (rtx label, rtx_insn *insn)
{
  return output_branch (label, "tr", insn);
}

/* Output a conditional branch to LABEL.  CODE is the comparison code.
   CC_MODE is the mode of the CC register.  REVERSED is non-zero if we
   should reverse the sense of the comparison.  INSN is the instruction.  */

const char *
output_cbranch (rtx label, enum rtx_code code, enum machine_mode cc_mode,
		int reversed, rtx_insn *insn)
{
  const char *cond;

  if (reversed)
    {
      if (cc_mode == CCFPmode || cc_mode == CCFPEmode)
	code = reverse_condition_maybe_unordered (code);
      else
	code = reverse_condition (code);
    }

  switch (code)
    {
    case NE:
      if (cc_mode == CC_BTSTmode)
	cond = "cs";
      else
	cond = "ne";
      break;

    case EQ:
      if (cc_mode == CC_BTSTmode)
	cond = "cc";
      else
	cond = "eq";
      break;

    case GE:
      if (cc_mode == CC_NOOVmode)
	cond = "nc";
      else
	cond = "ge";
      break;

    case GT:
      cond = "gt";
      break;

    case LE:
      if (cc_mode == CCFPmode || cc_mode == CCFPEmode)
	cond = "ls";
      else
	cond = "le";
      break;

    case LT:
      if (cc_mode == CCFPmode || cc_mode == CCFPEmode)
	cond = "ns";
      else if (cc_mode == CC_NOOVmode)
	cond = "ns";
      else
	cond = "lt";
      break;

    case GEU:
      cond = "cc";
      break;

    case GTU:
      cond = "hi";
      break;

    case LEU:
      cond = "ls";
      break;

    case LTU:
      cond = "cs";
      break;

    case UNORDERED:
      cond = "os";
      break;

    case ORDERED:
      cond = "oc";
      break;

    case UNGE:
      cond = "nc";
      break;

    case UNGT:
      cond = "hi";
      break;

    case UNLE:
      cond = "le";
      break;

    case UNLT:
      cond = "lt";
      break;

    /* These 2 comparison codes are not supported.  */
    case UNEQ:
    case LTGT:
    default:
      gcc_unreachable ();
    }

  return output_branch (label, cond, insn);
}

/* Helper function for PRINT_OPERAND (STREAM, X, CODE).  Output to stdio
   stream FILE the assembler syntax for an instruction operand OP subject
   to the modifier LETTER.  */

void
print_operand (FILE *file, rtx op, int letter)
{
  switch (letter)
    {
    case '#':
      /* Output an insn in a delay slot.  */
      if (final_sequence)
	visium_indent_opcode = 1;
      else
	fputs ("\n\t nop", file);
      return;

    case 'b':
      /* Print LS 8 bits of operand.  */
      fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, UINTVAL (op) & 0xff);
      return;

    case 'w':
      /* Print LS 16 bits of operand.  */
      fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, UINTVAL (op) & 0xffff);
      return;

    case 'u':
      /* Print MS 16 bits of operand.  */
      fprintf (file,
	       HOST_WIDE_INT_PRINT_UNSIGNED, (UINTVAL (op) >> 16) & 0xffff);
      return;

    case 'r':
      /* It's either a register or zero.  */
      if (GET_CODE (op) == REG)
	fputs (reg_names[REGNO (op)], file);
      else
	fputs (reg_names[0], file);
      return;

    case 'f':
      /* It's either a FP register or zero.  */
       if (GET_CODE (op) == REG)
	fputs (reg_names[REGNO (op)], file);
       else
	fputs (reg_names[FP_FIRST_REGNUM], file);
       return;
    }

  switch (GET_CODE (op))
    {
    case REG:
      if (letter == 'd')
	fputs (reg_names[REGNO (op) + 1], file);
      else
	fputs (reg_names[REGNO (op)], file);
      break;

    case SYMBOL_REF:
    case LABEL_REF:
    case CONST:
      output_addr_const (file, op);
      break;

    case MEM:
      visium_output_address (file, GET_MODE (op), XEXP (op, 0));
      break;

    case CONST_INT:
      fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op));
      break;

    case CODE_LABEL:
      asm_fprintf (file, "%LL%d", CODE_LABEL_NUMBER (op));
      break;

    case HIGH:
      print_operand (file, XEXP (op, 1), letter);
      break;

    default:
      fatal_insn ("illegal operand ", op);
    }
}

/* Output to stdio stream FILE the assembler syntax for an instruction operand
   that is a memory reference in MODE and whose address is ADDR.  */

static void
visium_output_address (FILE *file, enum machine_mode mode, rtx addr)
{
  switch (GET_CODE (addr))
    {
    case REG:
    case SUBREG:
      fprintf (file, "(%s)", reg_names[true_regnum (addr)]);
      break;

    case PLUS:
      {
	rtx x = XEXP (addr, 0), y = XEXP (addr, 1);

	switch (GET_CODE (x))
	  {
	  case REG:
	  case SUBREG:
	    if (CONST_INT_P (y))
	      {
		unsigned int regno = true_regnum (x);
		HOST_WIDE_INT val = INTVAL (y);
		switch (mode)
		  {
		  case SImode:
		  case DImode:
		  case SFmode:
		  case DFmode:
		    val >>= 2;
		    break;

		  case HImode:
		    val >>= 1;
		    break;

		  case QImode:
		  default:
		    break;
		  }
	        fprintf (file, HOST_WIDE_INT_PRINT_DEC"(%s)", val,
			 reg_names[regno]);
	      }
	    else
	      fatal_insn ("illegal operand address (1)", addr);
	    break;

	  default:
	    if (CONSTANT_P (x) && CONSTANT_P (y))
	      output_addr_const (file, addr);
	    else
	      fatal_insn ("illegal operand address (2)", addr);
	    break;
	  }
      }
      break;

    case LABEL_REF:
    case SYMBOL_REF:
    case CONST_INT:
    case CONST:
      output_addr_const (file, addr);
      break;

    case NOTE:
      if (NOTE_KIND (addr) != NOTE_INSN_DELETED_LABEL)
	fatal_insn ("illegal operand address (3)", addr);
      break;

    case CODE_LABEL:
      asm_fprintf (file, "%LL%d", CODE_LABEL_NUMBER (addr));
      break;

    default:
      fatal_insn ("illegal operand address (4)", addr);
      break;
    }
}

/* Helper function for PRINT_OPERAND_ADDRESS (STREAM, X).  Output to stdio
   stream FILE the assembler syntax for an instruction operand that is a
   memory reference whose address is ADDR.  */

void
print_operand_address (FILE *file, rtx addr)
{
  visium_output_address (file, QImode, addr);
}

/* The Visium stack frames look like:

              Before call                      After call
        +-----------------------+       +-----------------------+
        |                       |       |                       |
   high |      previous         |       |      previous         |
   mem  |      frame            |       |      frame            |
        |                       |       |                       |
        +-----------------------+       +-----------------------+
        |                       |       |                       |
        |  arguments on stack   |       |  arguments on stack   |
        |                       |       |                       |
  SP+0->+-----------------------+       +-----------------------+
                                        |  reg parm save area,  |
                                        |  only created for     |
                                        |  variable argument    |
                                        |  functions            |
                                        +-----------------------+
                                        |                       |
                                        |  register save area   |
                                        |                       |
                                        +-----------------------+
                                        |                       |
                                        |  local variables      |
                                        |                       |
                                  FP+8->+-----------------------+
                                        |    return address     |
                                  FP+4->+-----------------------+
                                        |      previous FP      |
                                  FP+0->+-----------------------+
                                        |                       |
                                        |  alloca allocations   |
                                        |                       |
                                        +-----------------------+
                                        |                       |
   low                                  |  arguments on stack   |
   mem                                  |                       |
                                  SP+0->+-----------------------+

   Notes:
   1) The "reg parm save area" does not exist for non variable argument fns.
   2) The FP register is not saved if `frame_pointer_needed' is zero and it
      is not altered in the current function.
   3) The return address is not saved if there is no frame pointer and the
      current function is leaf.
   4) If the return address is not saved and the static chain register is
      live in the function, we allocate the return address slot to be able
      to spill the register for a long branch.  */

/* Define the register classes for local purposes.  */
enum reg_type { general, mdb, mdc, floating, last_type};

#define GET_REG_TYPE(regno)          \
  (GP_REGISTER_P (regno) ? general : \
   (regno) == MDB_REGNUM ? mdb :      \
   (regno) == MDC_REGNUM ? mdc :      \
   floating)

/* First regno of each register type.  */
const int first_regno[last_type] = {0, MDB_REGNUM, MDC_REGNUM, FP_FIRST_REGNUM};

/* Size in bytes of each register type.  */
const int reg_type_size[last_type] = {4, 8, 4, 4};

/* Structure to be filled in by visium_compute_frame_size.  */
struct visium_frame_info
{
  unsigned int save_area_size;	/* # bytes in the reg parm save area.  */
  unsigned int reg_size1;	/* # bytes to store first block of regs.  */
  unsigned int reg_size2;	/* # bytes to store second block of regs.  */
  unsigned int max_reg1;	/* max. regno in first block */
  unsigned int var_size;	/* # bytes that variables take up.  */
  unsigned int save_fp;		/* Nonzero if fp must be saved.  */
  unsigned int save_lr;		/* Nonzero if lr must be saved.  */
  unsigned int lr_slot;		/* Nonzero if the lr slot is needed.  */
  unsigned int combine;		/* Nonzero if we can combine the allocation of
				   variables and regs. */
  unsigned int interrupt;	/* Nonzero if the function is an interrupt
				   handler. */
  unsigned int mask[last_type];	/* Masks of saved regs: gp, mdb, mdc, fp */
};

/* Current frame information calculated by visium_compute_frame_size.  */
static struct visium_frame_info current_frame_info;

/* Accessor for current_frame_info.save_fp.  */

static inline bool
current_function_saves_fp (void)
{
  return current_frame_info.save_fp != 0;
}

/* Accessor for current_frame_info.save_lr.  */

static inline bool
current_function_saves_lr (void)
{
  return current_frame_info.save_lr != 0;
}

/* Accessor for current_frame_info.lr_slot.  */

static inline bool
current_function_has_lr_slot (void)
{
  return current_frame_info.lr_slot != 0;
}

/* Return non-zero if register REGNO needs to be saved in the frame.  */

static int
visium_save_reg_p (int interrupt, int regno)
{
  switch (regno)
    {
    case HARD_FRAME_POINTER_REGNUM:
      /* This register is call-saved but handled specially.  */
      return 0;

    case MDC_REGNUM:
      /* This register is fixed but can be modified.  */
      break;

    case 29:
    case 30:
      /* These registers are fixed and hold the interrupt context.  */
      return (interrupt != 0);

    default:
      /* The other fixed registers are either immutable or special.  */
      if (fixed_regs[regno])
	return 0;
      break;
    }

  if (interrupt)
    {
      if (crtl->is_leaf)
	{
	  if (df_regs_ever_live_p (regno))
	    return 1;
	}
      else if (call_used_regs[regno])
	return 1;

      /* To save mdb requires two temporary registers.  To save mdc or
         any of the floating registers requires one temporary
         register.  If this is an interrupt routine, the temporary
         registers need to be saved as well.  These temporary registers
         are call used, so we only need deal with the case of leaf
         functions here.  */
      if (regno == PROLOGUE_TMP_REGNUM)
	{
	  if (df_regs_ever_live_p (MDB_REGNUM)
	      || df_regs_ever_live_p (MDC_REGNUM))
	    return 1;

	  for (int i = FP_FIRST_REGNUM; i <= FP_LAST_REGNUM; i++)
	    if (df_regs_ever_live_p (i))
	      return 1;
	}

      else if (regno == PROLOGUE_TMP_REGNUM + 1)
	{
	  if (df_regs_ever_live_p (MDB_REGNUM))
	    return 1;
	}
    }

  return df_regs_ever_live_p (regno) && !call_used_regs[regno];
}

/* Compute the frame size required by the function.  This function is called
   during the reload pass and also by visium_expand_prologue.  */

static int
visium_compute_frame_size (int size)
{
  const int save_area_size = visium_reg_parm_save_area_size;
  const int var_size = VISIUM_STACK_ALIGN (size);
  const int save_fp
    = frame_pointer_needed || df_regs_ever_live_p (HARD_FRAME_POINTER_REGNUM);
  const int save_lr = frame_pointer_needed || !crtl->is_leaf;
  const int lr_slot = !save_lr && df_regs_ever_live_p (long_branch_regnum);
  const int local_frame_offset
    = (save_fp + save_lr + lr_slot) * UNITS_PER_WORD;
  const int interrupt = visium_interrupt_function_p ();
  unsigned int mask[last_type];
  int reg_size1 = 0;
  int max_reg1 = 0;
  int reg_size2 = 0;
  int reg_size;
  int combine;
  int frame_size;
  int regno;

  memset (mask, 0, last_type * sizeof (unsigned int));

  /* The registers may need stacking in 2 blocks since only 32 32-bit words
     can be indexed from a given base address.  */
  for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
    {
      if (visium_save_reg_p (interrupt, regno))
	{
	  enum reg_type reg_type = GET_REG_TYPE (regno);
	  int mask_bit = 1 << (regno - first_regno[reg_type]);
	  int nbytes = reg_type_size[reg_type];

	  if (reg_size1 + nbytes > 32 * UNITS_PER_WORD)
	    break;

	  reg_size1 += nbytes;
	  max_reg1 = regno;
	  mask[reg_type] |= mask_bit;
	}
    }

  for (regno = max_reg1 + 1; regno < FIRST_PSEUDO_REGISTER; regno++)
    {
      if (visium_save_reg_p (interrupt, regno))
	{
	  enum reg_type reg_type = GET_REG_TYPE (regno);
	  int mask_bit = 1 << (regno - first_regno[reg_type]);
	  int nbytes = reg_type_size[reg_type];

	  reg_size2 += nbytes;
	  mask[reg_type] |= mask_bit;
	}
    }

  reg_size = reg_size2 ? reg_size2 : reg_size1;
  combine = (local_frame_offset + var_size + reg_size) <= 32 * UNITS_PER_WORD;
  frame_size
    = local_frame_offset + var_size + reg_size2 + reg_size1 + save_area_size;

  current_frame_info.save_area_size = save_area_size;
  current_frame_info.reg_size1 = reg_size1;
  current_frame_info.max_reg1 = max_reg1;
  current_frame_info.reg_size2 = reg_size2;
  current_frame_info.var_size = var_size;
  current_frame_info.save_fp = save_fp;
  current_frame_info.save_lr = save_lr;
  current_frame_info.lr_slot = lr_slot;
  current_frame_info.combine = combine;
  current_frame_info.interrupt = interrupt;

  memcpy (current_frame_info.mask, mask, last_type * sizeof (unsigned int));

  return frame_size;
}

/* Helper function for INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET).  Define
   the offset between two registers, one to be eliminated, and the other its
   replacement, at the start of a routine.  */

int
visium_initial_elimination_offset (int from, int to ATTRIBUTE_UNUSED)
{
  const int frame_size = visium_compute_frame_size (get_frame_size ());
  const int save_fp = current_frame_info.save_fp;
  const int save_lr = current_frame_info.save_lr;
  const int lr_slot = current_frame_info.lr_slot;
  const int local_frame_offset
    = (save_fp + save_lr + lr_slot) * UNITS_PER_WORD;
  int offset;

  if (from == FRAME_POINTER_REGNUM)
    offset = local_frame_offset;
  else if (from == ARG_POINTER_REGNUM)
    offset = frame_size;
  else
    gcc_unreachable ();

  return offset;
}

/* For an interrupt handler, we may be saving call-clobbered registers.
   Say the epilogue uses these in addition to the link register.  */

int
visium_epilogue_uses (int regno)
{
  if (regno == LINK_REGNUM)
    return 1;

  if (reload_completed)
    {
      enum reg_type reg_type = GET_REG_TYPE (regno);
      int mask_bit = 1 << (regno - first_regno[reg_type]);

      return (current_frame_info.mask[reg_type] & mask_bit) != 0;
    }

  return 0;
}

/* Wrapper around emit_insn that sets RTX_FRAME_RELATED_P on the insn.  */

static rtx
emit_frame_insn (rtx x)
{
  x = emit_insn (x);
  RTX_FRAME_RELATED_P (x) = 1;
  return x;
}

/* Allocate ALLOC bytes on the stack and save the registers LOW_REGNO to
   HIGH_REGNO at OFFSET from the stack pointer.  */

static void
visium_save_regs (int alloc, int offset, int low_regno, int high_regno)
{
  /* If this is an interrupt handler function, then mark the register
     stores as volatile.  This will prevent the instruction scheduler
     from scrambling the order of register saves.  */
  const int volatile_p = current_frame_info.interrupt;
  int regno;

  /* Allocate the stack space.  */
  emit_frame_insn (gen_addsi3_flags (stack_pointer_rtx, stack_pointer_rtx,
				     GEN_INT (-alloc)));

  for (regno = low_regno; regno <= high_regno; regno++)
    {
      enum reg_type reg_type = GET_REG_TYPE (regno);
      int mask_bit = 1 << (regno - first_regno[reg_type]);
      rtx insn;

      if (current_frame_info.mask[reg_type] & mask_bit)
	{
	  offset -= reg_type_size[reg_type];
	  switch (reg_type)
	    {
	    case general:
	      {
		rtx mem
		  = gen_frame_mem (SImode,
				   plus_constant (Pmode,
						  stack_pointer_rtx, offset));
		MEM_VOLATILE_P (mem) = volatile_p;
		emit_frame_insn (gen_movsi (mem, gen_rtx_REG (SImode, regno)));
	      }
	      break;

	    case mdb:
	      {
		rtx tmp = gen_rtx_REG (DImode, PROLOGUE_TMP_REGNUM);
		rtx mem
		  = gen_frame_mem (DImode,
				   plus_constant (Pmode,
						  stack_pointer_rtx, offset));
		rtx reg = gen_rtx_REG (DImode, regno);
		MEM_VOLATILE_P (mem) = volatile_p;
		emit_insn (gen_movdi (tmp, reg));
		/* Do not generate CFI if in interrupt handler.  */
		if (volatile_p)
		  emit_insn (gen_movdi (mem, tmp));
		else
		  {
		    insn = emit_frame_insn (gen_movdi (mem, tmp));
		    add_reg_note (insn, REG_FRAME_RELATED_EXPR,
				  gen_rtx_SET (mem, reg));
		  }
	      }
	      break;

	    case mdc:
	      {
		rtx tmp = gen_rtx_REG (SImode, PROLOGUE_TMP_REGNUM);
		rtx mem
		  = gen_frame_mem (SImode,
				   plus_constant (Pmode,
						  stack_pointer_rtx, offset));
		rtx reg = gen_rtx_REG (SImode, regno);
		MEM_VOLATILE_P (mem) = volatile_p;
		emit_insn (gen_movsi (tmp, reg));
		insn = emit_frame_insn (gen_movsi (mem, tmp));
		add_reg_note (insn, REG_FRAME_RELATED_EXPR,
			      gen_rtx_SET (mem, reg));
	      }
	      break;

	    case floating:
	      {
		rtx tmp = gen_rtx_REG (SFmode, PROLOGUE_TMP_REGNUM);
		rtx mem
		  = gen_frame_mem (SFmode,
				   plus_constant (Pmode,
						  stack_pointer_rtx, offset));
		rtx reg = gen_rtx_REG (SFmode, regno);
		MEM_VOLATILE_P (mem) = volatile_p;
		emit_insn (gen_movsf (tmp, reg));
		insn = emit_frame_insn (gen_movsf (mem, tmp));
		add_reg_note (insn, REG_FRAME_RELATED_EXPR,
			      gen_rtx_SET (mem, reg));
	      }
	      break;

	    default:
	      break;
	    }
	}
    }
}

/* This function generates the code for function entry.  */

void
visium_expand_prologue (void)
{
  const int frame_size = visium_compute_frame_size (get_frame_size ());
  const int save_area_size = current_frame_info.save_area_size;
  const int reg_size1 = current_frame_info.reg_size1;
  const int max_reg1 = current_frame_info.max_reg1;
  const int reg_size2 = current_frame_info.reg_size2;
  const int var_size = current_frame_info.var_size;
  const int save_fp = current_frame_info.save_fp;
  const int save_lr = current_frame_info.save_lr;
  const int lr_slot = current_frame_info.lr_slot;
  const int local_frame_offset
    = (save_fp + save_lr + lr_slot) * UNITS_PER_WORD;
  const int combine = current_frame_info.combine;
  int reg_size;
  int first_reg;
  int fsize;

  /* Save the frame size for future references.  */
  visium_frame_size = frame_size;

  if (flag_stack_usage_info)
    current_function_static_stack_size = frame_size;

  /* If the registers have to be stacked in 2 blocks, stack the first one.  */
  if (reg_size2)
    {
      visium_save_regs (reg_size1 + save_area_size, reg_size1, 0, max_reg1);
      reg_size = reg_size2;
      first_reg = max_reg1 + 1;
      fsize = local_frame_offset + var_size + reg_size2;
    }
  else
    {
      reg_size = reg_size1;
      first_reg = 0;
      fsize = local_frame_offset + var_size + reg_size1 + save_area_size;
    }

  /* If we can't combine register stacking with variable allocation, partially
     allocate and stack the (remaining) registers now.  */
  if (reg_size && !combine)
    visium_save_regs (fsize - local_frame_offset - var_size, reg_size,
		      first_reg, FIRST_PSEUDO_REGISTER - 1);

  /* If we can combine register stacking with variable allocation, fully
     allocate and stack the (remaining) registers now.  */
  if (reg_size && combine)
    visium_save_regs (fsize, local_frame_offset + var_size + reg_size,
		      first_reg, FIRST_PSEUDO_REGISTER - 1);

  /* Otherwise space may still need to be allocated for the variables.  */
  else if (fsize)
    {
      const int alloc_size = reg_size ? local_frame_offset + var_size : fsize;

      if (alloc_size > 65535)
	{
	  rtx tmp = gen_rtx_REG (SImode, PROLOGUE_TMP_REGNUM), insn;
	  emit_insn (gen_movsi (tmp, GEN_INT (alloc_size)));
	  insn = emit_frame_insn (gen_subsi3_flags (stack_pointer_rtx,
						    stack_pointer_rtx,
						    tmp));
	  add_reg_note (insn, REG_FRAME_RELATED_EXPR,
			gen_rtx_SET (stack_pointer_rtx,
				     gen_rtx_PLUS (Pmode, stack_pointer_rtx,
						   GEN_INT (-alloc_size))));
	}
      else
	emit_frame_insn (gen_addsi3_flags (stack_pointer_rtx,
					   stack_pointer_rtx,
					   GEN_INT (-alloc_size)));
    }

  if (save_fp)
    emit_frame_insn (gen_movsi (gen_frame_mem (SImode, stack_pointer_rtx),
				hard_frame_pointer_rtx));

  if (frame_pointer_needed)
    emit_frame_insn (gen_stack_save ());

  if (save_lr)
    {
      rtx base_rtx, mem;

      /* Normally the frame pointer and link register get saved via
         write.l (sp),fp
         move.l  fp,sp
         write.l 1(sp),r21

         Indexing off sp rather than fp to store the link register
         avoids presenting the instruction scheduler with an initial
         pipeline hazard.  If however the frame is needed for eg.
         __builtin_return_address which needs to retrieve the saved
         value of the link register from the stack at fp + 4 then
         indexing from sp can confuse the dataflow, causing the link
         register to be retrieved before it has been saved.  */
      if (cfun->machine->frame_needed)
	base_rtx = hard_frame_pointer_rtx;
      else
	base_rtx = stack_pointer_rtx;

      mem = gen_frame_mem (SImode,
			   plus_constant (Pmode,
					  base_rtx, save_fp * UNITS_PER_WORD));
      emit_frame_insn (gen_movsi (mem, gen_rtx_REG (SImode, LINK_REGNUM)));
    }
}

static GTY(()) rtx cfa_restores;

/* Queue a REG_CFA_RESTORE note until next stack manipulation insn.  */

static void
visium_add_cfa_restore_note (rtx reg)
{
  cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, cfa_restores);
}

/* Add queued REG_CFA_RESTORE notes to INSN, if any.  */

static void
visium_add_queued_cfa_restore_notes (rtx insn)
{
  rtx last;
  if (!cfa_restores)
    return;
  for (last = cfa_restores; XEXP (last, 1); last = XEXP (last, 1))
    ;
  XEXP (last, 1) = REG_NOTES (insn);
  REG_NOTES (insn) = cfa_restores;
  cfa_restores = NULL_RTX;
}

/* Restore the registers LOW_REGNO to HIGH_REGNO from the save area at OFFSET
   from the stack pointer and pop DEALLOC bytes off the stack.  */

static void
visium_restore_regs (int dealloc, int offset, int high_regno, int low_regno)
{
  /* If this is an interrupt handler function, then mark the register
     restores as volatile.  This will prevent the instruction scheduler
     from scrambling the order of register restores.  */
  const int volatile_p = current_frame_info.interrupt;
  int r30_offset = -1;
  int regno;

  for (regno = high_regno; regno >= low_regno; --regno)
    {
      enum reg_type reg_type = GET_REG_TYPE (regno);
      int mask_bit = 1 << (regno - first_regno[reg_type]);

      if (current_frame_info.mask[reg_type] & mask_bit)
	{
	  switch (reg_type)
	    {
	    case general:
	      /* Postpone restoring the interrupted context registers
	         until last, since they need to be preceded by a dsi.  */
	      if (regno == 29)
		;
	      else if (regno == 30)
		r30_offset = offset;
	      else
		{
		  rtx mem
		    = gen_frame_mem (SImode,
				     plus_constant (Pmode,
						    stack_pointer_rtx,
						    offset));
		  rtx reg = gen_rtx_REG (SImode, regno);
		  MEM_VOLATILE_P (mem) = volatile_p;
		  emit_insn (gen_movsi (reg, mem));
		  visium_add_cfa_restore_note (reg);
		}
	      break;

	    case mdb:
	      {
		rtx tmp = gen_rtx_REG (DImode, PROLOGUE_TMP_REGNUM);
		rtx mem
		  = gen_frame_mem (DImode,
				   plus_constant (Pmode,
						  stack_pointer_rtx, offset));
		rtx reg = gen_rtx_REG (DImode, regno);
		MEM_VOLATILE_P (mem) = volatile_p;
		emit_insn (gen_movdi (tmp, mem));
		emit_insn (gen_movdi (reg, tmp));
		/* Do not generate CFI if in interrupt handler.  */
		if (!volatile_p)
		  visium_add_cfa_restore_note (reg);
	      }
	      break;

	    case mdc:
	      {
		rtx tmp = gen_rtx_REG (SImode, PROLOGUE_TMP_REGNUM);
		rtx mem
		  = gen_frame_mem (SImode,
				   plus_constant (Pmode,
						  stack_pointer_rtx, offset));
		rtx reg = gen_rtx_REG (SImode, regno);
		MEM_VOLATILE_P (mem) = volatile_p;
		emit_insn (gen_movsi (tmp, mem));
		emit_insn (gen_movsi (reg, tmp));
		visium_add_cfa_restore_note (reg);
	      }
	      break;

	    case floating:
	      {
		rtx tmp = gen_rtx_REG (SFmode, PROLOGUE_TMP_REGNUM);
		rtx mem
		  = gen_frame_mem (SFmode,
				   plus_constant (Pmode,
						  stack_pointer_rtx, offset));
		rtx reg = gen_rtx_REG (SFmode, regno);
		MEM_VOLATILE_P (mem) = volatile_p;
		emit_insn (gen_movsf (tmp, mem));
		emit_insn (gen_movsf (reg, tmp));
		visium_add_cfa_restore_note (reg);
	      }
	      break;

	    default:
	      break;
	    }

	  offset += reg_type_size[reg_type];
	}
    }

  /* If the interrupted context needs to be restored, precede the
     restores of r29 and r30 by a dsi.  */
  if (r30_offset >= 0)
    {
      emit_insn (gen_dsi ());
      emit_move_insn (gen_rtx_REG (SImode, 30),
		      gen_frame_mem (SImode,
				     plus_constant (Pmode,
						    stack_pointer_rtx,
						    r30_offset)));
      emit_move_insn (gen_rtx_REG (SImode, 29),
		      gen_frame_mem (SImode,
				     plus_constant (Pmode,
						    stack_pointer_rtx,
						    r30_offset + 4)));
    }

  /* Deallocate the stack space.  */
  rtx insn = emit_frame_insn (gen_stack_pop (GEN_INT (dealloc)));
  add_reg_note (insn, REG_FRAME_RELATED_EXPR,
		gen_rtx_SET (stack_pointer_rtx,
			     gen_rtx_PLUS (Pmode, stack_pointer_rtx,
					   GEN_INT (dealloc))));
  visium_add_queued_cfa_restore_notes (insn);
}

/* This function generates the code for function exit.  */

void
visium_expand_epilogue (void)
{
  const int save_area_size = current_frame_info.save_area_size;
  const int reg_size1 = current_frame_info.reg_size1;
  const int max_reg1 = current_frame_info.max_reg1;
  const int reg_size2 = current_frame_info.reg_size2;
  const int var_size = current_frame_info.var_size;
  const int restore_fp = current_frame_info.save_fp;
  const int restore_lr = current_frame_info.save_lr;
  const int lr_slot = current_frame_info.lr_slot;
  const int local_frame_offset
    = (restore_fp + restore_lr + lr_slot) * UNITS_PER_WORD;
  const int combine = current_frame_info.combine;
  int reg_size;
  int last_reg;
  int fsize;

  /* Do not bother restoring the stack pointer if it hasn't been changed in
     the function since it was saved _after_ the allocation of the frame.  */
  if (!crtl->sp_is_unchanging)
    emit_insn (gen_stack_restore ());

  /* Restore the frame pointer if necessary.  The usual code would be:

       move.l  sp,fp
       read.l  fp,(sp)

     but for the MCM this constitutes a stall/hazard so it is changed to:

       move.l  sp,fp
       read.l  fp,(fp)

     if the stack pointer has actually been restored.  */
  if (restore_fp)
    {
      rtx src;

      if (TARGET_MCM && !crtl->sp_is_unchanging)
	src = gen_frame_mem (SImode, hard_frame_pointer_rtx);
      else
	src = gen_frame_mem (SImode, stack_pointer_rtx);

      rtx insn = emit_frame_insn (gen_movsi (hard_frame_pointer_rtx, src));
      add_reg_note (insn, REG_CFA_ADJUST_CFA,
		    gen_rtx_SET (stack_pointer_rtx,
				 hard_frame_pointer_rtx));
      visium_add_cfa_restore_note (hard_frame_pointer_rtx);
    }

  /* Restore the link register if necessary.  */
  if (restore_lr)
    {
      rtx mem = gen_frame_mem (SImode,
			       plus_constant (Pmode,
					      stack_pointer_rtx,
					      restore_fp * UNITS_PER_WORD));
      rtx reg = gen_rtx_REG (SImode, LINK_REGNUM);
      emit_insn (gen_movsi (reg, mem));
      visium_add_cfa_restore_note (reg);
    }

  /* If we have two blocks of registers, deal with the second one first.  */
  if (reg_size2)
    {
      reg_size = reg_size2;
      last_reg = max_reg1 + 1;
      fsize = local_frame_offset + var_size + reg_size2;
    }
  else
    {
      reg_size = reg_size1;
      last_reg = 0;
      fsize = local_frame_offset + var_size + reg_size1 + save_area_size;
    }

  /* If the variable allocation could be combined with register stacking,
     restore the (remaining) registers and fully deallocate now.  */
  if (reg_size && combine)
    visium_restore_regs (fsize, local_frame_offset + var_size,
			 FIRST_PSEUDO_REGISTER - 1, last_reg);

  /* Otherwise deallocate the variables first.  */
  else if (fsize)
    {
      const int pop_size = reg_size ? local_frame_offset + var_size : fsize;
      rtx insn;

      if (pop_size > 65535)
	{
	  rtx tmp = gen_rtx_REG (SImode, PROLOGUE_TMP_REGNUM);
	  emit_move_insn (tmp, GEN_INT (pop_size));
	  insn = emit_frame_insn (gen_stack_pop (tmp));
        }
      else
	insn = emit_frame_insn (gen_stack_pop (GEN_INT (pop_size)));
      add_reg_note (insn, REG_FRAME_RELATED_EXPR,
		    gen_rtx_SET (stack_pointer_rtx,
				 gen_rtx_PLUS (Pmode, stack_pointer_rtx,
					       GEN_INT (pop_size))));
      visium_add_queued_cfa_restore_notes (insn);
    }

  /* If the variable allocation couldn't be combined with register stacking,
     restore the (remaining) registers now and partially deallocate.  */
  if (reg_size && !combine)
    visium_restore_regs (fsize - local_frame_offset - var_size, 0,
			 FIRST_PSEUDO_REGISTER - 1, last_reg);

  /* If the first block of registers has yet to be restored, do it now.  */
  if (reg_size2)
    visium_restore_regs (reg_size1 + save_area_size, 0, max_reg1, 0);

  /* If this is an exception return, make the necessary stack adjustment.  */
  if (crtl->calls_eh_return)
    emit_insn (gen_stack_pop (EH_RETURN_STACKADJ_RTX));
}

/* Return true if it is appropriate to emit `return' instructions in the
   body of a function.  */

bool
visium_can_use_return_insn_p (void)
{
  return reload_completed
	 && visium_frame_size == 0
	 && !visium_interrupt_function_p ();
}

/* Return the register class required for an intermediate register used to
   copy a register of RCLASS from/to X.  If no such intermediate register is
   required, return NO_REGS.  If more than one such intermediate register is
   required, describe the one that is closest in the copy chain to the reload
   register.  */

static reg_class_t
visium_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x,
			 reg_class_t rclass,
			 enum machine_mode mode ATTRIBUTE_UNUSED,
			 secondary_reload_info *sri ATTRIBUTE_UNUSED)
{
  int regno = true_regnum (x);

  /* For MDB, MDC and FP_REGS, a general register is needed for a move to
     or from memory. */
  if (regno == -1 && (rclass == MDB || rclass == MDC || rclass == FP_REGS))
    return GENERAL_REGS;

  /* Moves between MDB, MDC and FP_REGS also require a general register. */
  else if (((regno == R_MDB || regno == R_MDC) && rclass == FP_REGS)
      || (FP_REGISTER_P (regno) && (rclass == MDB || rclass == MDC)))
    return GENERAL_REGS;

  /* Finally an (unlikely ?) move between MDB and MDC needs a general reg. */
  else if ((regno == R_MDB && rclass == MDC)
	   || (rclass == MDB && regno == R_MDC))
    return GENERAL_REGS;

  return NO_REGS;
}

/* Return true if pseudos that have been assigned to registers of RCLASS
   would likely be spilled because registers of RCLASS are needed for
   spill registers.  */

static bool
visium_class_likely_spilled_p (reg_class_t rclass ATTRIBUTE_UNUSED)
{
  /* Return false for classes R1, R2 and R3, which are intended to be used
     only in the source code in conjunction with block move instructions.  */
  return false;
}

/* Return the register number if OP is a REG or a SUBREG of a REG, and
   INVALID_REGNUM in all the other cases.  */

unsigned int
reg_or_subreg_regno (rtx op)
{
  unsigned int regno;

  if (GET_CODE (op) == REG)
    regno = REGNO (op);
  else if (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG)
    {
      if (REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
	regno = subreg_regno (op);
      else
	regno = REGNO (SUBREG_REG (op));
    }
  else
    regno = INVALID_REGNUM;

  return regno;
}

#include "gt-visium.h"