aboutsummaryrefslogtreecommitdiff
path: root/src/share/vm/adlc/output_h.cpp
blob: 04cddcd28c8d16cfa20a77bf152bab6a8dc705f4 (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
/*
 * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code 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
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 */

// output_h.cpp - Class HPP file output routines for architecture definition
#include "adlc.hpp"


// Generate the #define that describes the number of registers.
static void defineRegCount(FILE *fp, RegisterForm *registers) {
  if (registers) {
    int regCount =  AdlcVMDeps::Physical + registers->_rdefs.count();
    fprintf(fp,"\n");
    fprintf(fp,"// the number of reserved registers + machine registers.\n");
    fprintf(fp,"#define REG_COUNT    %d\n", regCount);
  }
}

// Output enumeration of machine register numbers
// (1)
// // Enumerate machine registers starting after reserved regs.
// // in the order of occurrence in the register block.
// enum MachRegisterNumbers {
//   EAX_num = 0,
//   ...
//   _last_Mach_Reg
// }
void ArchDesc::buildMachRegisterNumbers(FILE *fp_hpp) {
  if (_register) {
    RegDef *reg_def = NULL;

    // Output a #define for the number of machine registers
    defineRegCount(fp_hpp, _register);

    // Count all the Save_On_Entry and Always_Save registers
    int    saved_on_entry = 0;
    int  c_saved_on_entry = 0;
    _register->reset_RegDefs();
    while( (reg_def = _register->iter_RegDefs()) != NULL ) {
      if( strcmp(reg_def->_callconv,"SOE") == 0 ||
          strcmp(reg_def->_callconv,"AS")  == 0 )  ++saved_on_entry;
      if( strcmp(reg_def->_c_conv,"SOE") == 0 ||
          strcmp(reg_def->_c_conv,"AS")  == 0 )  ++c_saved_on_entry;
    }
    fprintf(fp_hpp, "\n");
    fprintf(fp_hpp, "// the number of save_on_entry + always_saved registers.\n");
    fprintf(fp_hpp, "#define MAX_SAVED_ON_ENTRY_REG_COUNT    %d\n",   max(saved_on_entry,c_saved_on_entry));
    fprintf(fp_hpp, "#define     SAVED_ON_ENTRY_REG_COUNT    %d\n",   saved_on_entry);
    fprintf(fp_hpp, "#define   C_SAVED_ON_ENTRY_REG_COUNT    %d\n", c_saved_on_entry);

    // (1)
    // Build definition for enumeration of register numbers
    fprintf(fp_hpp, "\n");
    fprintf(fp_hpp, "// Enumerate machine register numbers starting after reserved regs.\n");
    fprintf(fp_hpp, "// in the order of occurrence in the register block.\n");
    fprintf(fp_hpp, "enum MachRegisterNumbers {\n");

    // Output the register number for each register in the allocation classes
    _register->reset_RegDefs();
    int i = 0;
    while( (reg_def = _register->iter_RegDefs()) != NULL ) {
      fprintf(fp_hpp,"  %s_num,\t\t// %d\n", reg_def->_regname, i++);
    }
    // Finish defining enumeration
    fprintf(fp_hpp, "  _last_Mach_Reg\t// %d\n", i);
    fprintf(fp_hpp, "};\n");
  }

  fprintf(fp_hpp, "\n// Size of register-mask in ints\n");
  fprintf(fp_hpp, "#define RM_SIZE %d\n",RegisterForm::RegMask_Size());
  fprintf(fp_hpp, "// Unroll factor for loops over the data in a RegMask\n");
  fprintf(fp_hpp, "#define FORALL_BODY ");
  int len = RegisterForm::RegMask_Size();
  for( int i = 0; i < len; i++ )
    fprintf(fp_hpp, "BODY(%d) ",i);
  fprintf(fp_hpp, "\n\n");

  fprintf(fp_hpp,"class RegMask;\n");
  // All RegMasks are declared "extern const ..." in ad_<arch>.hpp
  // fprintf(fp_hpp,"extern RegMask STACK_OR_STACK_SLOTS_mask;\n\n");
}


// Output enumeration of machine register encodings
// (2)
// // Enumerate machine registers starting after reserved regs.
// // in the order of occurrence in the alloc_class(es).
// enum MachRegisterEncodes {
//   EAX_enc = 0x00,
//   ...
// }
void ArchDesc::buildMachRegisterEncodes(FILE *fp_hpp) {
  if (_register) {
    RegDef *reg_def = NULL;
    RegDef *reg_def_next = NULL;

    // (2)
    // Build definition for enumeration of encode values
    fprintf(fp_hpp, "\n");
    fprintf(fp_hpp, "// Enumerate machine registers starting after reserved regs.\n");
    fprintf(fp_hpp, "// in the order of occurrence in the alloc_class(es).\n");
    fprintf(fp_hpp, "enum MachRegisterEncodes {\n");

    // Output the register encoding for each register in the allocation classes
    _register->reset_RegDefs();
    reg_def_next = _register->iter_RegDefs();
    while( (reg_def = reg_def_next) != NULL ) {
      reg_def_next = _register->iter_RegDefs();
      fprintf(fp_hpp,"  %s_enc = %s%s\n",
              reg_def->_regname, reg_def->register_encode(), reg_def_next == NULL? "" : "," );
    }
    // Finish defining enumeration
    fprintf(fp_hpp, "};\n");

  } // Done with register form
}


// Declare an array containing the machine register names, strings.
static void declareRegNames(FILE *fp, RegisterForm *registers) {
  if (registers) {
//    fprintf(fp,"\n");
//    fprintf(fp,"// An array of character pointers to machine register names.\n");
//    fprintf(fp,"extern const char *regName[];\n");
  }
}

// Declare an array containing the machine register sizes in 32-bit words.
void ArchDesc::declareRegSizes(FILE *fp) {
// regSize[] is not used
}

// Declare an array containing the machine register encoding values
static void declareRegEncodes(FILE *fp, RegisterForm *registers) {
  if (registers) {
    // // //
    // fprintf(fp,"\n");
    // fprintf(fp,"// An array containing the machine register encode values\n");
    // fprintf(fp,"extern const char  regEncode[];\n");
  }
}


// ---------------------------------------------------------------------------
//------------------------------Utilities to build Instruction Classes--------
// ---------------------------------------------------------------------------
static void out_RegMask(FILE *fp) {
  fprintf(fp,"  virtual const RegMask &out_RegMask() const;\n");
}

// ---------------------------------------------------------------------------
//--------Utilities to build MachOper and MachNode derived Classes------------
// ---------------------------------------------------------------------------

//------------------------------Utilities to build Operand Classes------------
static void in_RegMask(FILE *fp) {
  fprintf(fp,"  virtual const RegMask *in_RegMask(int index) const;\n");
}

static void declare_hash(FILE *fp) {
  fprintf(fp,"  virtual uint           hash() const;\n");
}

static void declare_cmp(FILE *fp) {
  fprintf(fp,"  virtual uint           cmp( const MachOper &oper ) const;\n");
}

static void declareConstStorage(FILE *fp, FormDict &globals, OperandForm *oper) {
  int i = 0;
  Component *comp;

  if (oper->num_consts(globals) == 0) return;
  // Iterate over the component list looking for constants
  oper->_components.reset();
  if ((comp = oper->_components.iter()) == NULL) {
    assert(oper->num_consts(globals) == 1, "Bad component list detected.\n");
    const char *type = oper->ideal_type(globals);
    if (!strcmp(type, "ConI")) {
      if (i > 0) fprintf(fp,", ");
      fprintf(fp,"  int32          _c%d;\n", i);
    }
    else if (!strcmp(type, "ConP")) {
      if (i > 0) fprintf(fp,", ");
      fprintf(fp,"  const TypePtr *_c%d;\n", i);
    }
    else if (!strcmp(type, "ConN")) {
      if (i > 0) fprintf(fp,", ");
      fprintf(fp,"  const TypeNarrowOop *_c%d;\n", i);
    }
    else if (!strcmp(type, "ConL")) {
      if (i > 0) fprintf(fp,", ");
      fprintf(fp,"  jlong          _c%d;\n", i);
    }
    else if (!strcmp(type, "ConF")) {
      if (i > 0) fprintf(fp,", ");
      fprintf(fp,"  jfloat         _c%d;\n", i);
    }
    else if (!strcmp(type, "ConD")) {
      if (i > 0) fprintf(fp,", ");
      fprintf(fp,"  jdouble        _c%d;\n", i);
    }
    else if (!strcmp(type, "Bool")) {
      fprintf(fp,"private:\n");
      fprintf(fp,"  BoolTest::mask _c%d;\n", i);
      fprintf(fp,"public:\n");
    }
    else {
      assert(0, "Non-constant operand lacks component list.");
    }
  } // end if NULL
  else {
    oper->_components.reset();
    while ((comp = oper->_components.iter()) != NULL) {
      if (!strcmp(comp->base_type(globals), "ConI")) {
        fprintf(fp,"  jint             _c%d;\n", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConP")) {
        fprintf(fp,"  const TypePtr *_c%d;\n", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConN")) {
        fprintf(fp,"  const TypePtr *_c%d;\n", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConL")) {
        fprintf(fp,"  jlong            _c%d;\n", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConF")) {
        fprintf(fp,"  jfloat           _c%d;\n", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConD")) {
        fprintf(fp,"  jdouble          _c%d;\n", i);
        i++;
      }
    }
  }
}

// Declare constructor.
// Parameters start with condition code, then all other constants
//
// (0) public:
// (1)  MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)
// (2)     : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }
//
static void defineConstructor(FILE *fp, const char *name, uint num_consts,
                              ComponentList &lst, bool is_ideal_bool,
                              Form::DataType constant_type, FormDict &globals) {
  fprintf(fp,"public:\n");
  // generate line (1)
  fprintf(fp,"  %sOper(", name);
  if( num_consts == 0 ) {
    fprintf(fp,") {}\n");
    return;
  }

  // generate parameters for constants
  uint i = 0;
  Component *comp;
  lst.reset();
  if ((comp = lst.iter()) == NULL) {
    assert(num_consts == 1, "Bad component list detected.\n");
    switch( constant_type ) {
    case Form::idealI : {
      fprintf(fp,is_ideal_bool ? "BoolTest::mask c%d" : "int32 c%d", i);
      break;
    }
    case Form::idealN : { fprintf(fp,"const TypeNarrowOop *c%d", i); break; }
    case Form::idealP : { fprintf(fp,"const TypePtr *c%d", i); break; }
    case Form::idealL : { fprintf(fp,"jlong c%d", i);   break;        }
    case Form::idealF : { fprintf(fp,"jfloat c%d", i);  break;        }
    case Form::idealD : { fprintf(fp,"jdouble c%d", i); break;        }
    default:
      assert(!is_ideal_bool, "Non-constant operand lacks component list.");
      break;
    }
  } // end if NULL
  else {
    lst.reset();
    while((comp = lst.iter()) != NULL) {
      if (!strcmp(comp->base_type(globals), "ConI")) {
        if (i > 0) fprintf(fp,", ");
        fprintf(fp,"int32 c%d", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConP")) {
        if (i > 0) fprintf(fp,", ");
        fprintf(fp,"const TypePtr *c%d", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConN")) {
        if (i > 0) fprintf(fp,", ");
        fprintf(fp,"const TypePtr *c%d", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConL")) {
        if (i > 0) fprintf(fp,", ");
        fprintf(fp,"jlong c%d", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConF")) {
        if (i > 0) fprintf(fp,", ");
        fprintf(fp,"jfloat c%d", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "ConD")) {
        if (i > 0) fprintf(fp,", ");
        fprintf(fp,"jdouble c%d", i);
        i++;
      }
      else if (!strcmp(comp->base_type(globals), "Bool")) {
        if (i > 0) fprintf(fp,", ");
        fprintf(fp,"BoolTest::mask c%d", i);
        i++;
      }
    }
  }
  // finish line (1) and start line (2)
  fprintf(fp,")  : ");
  // generate initializers for constants
  i = 0;
  fprintf(fp,"_c%d(c%d)", i, i);
  for( i = 1; i < num_consts; ++i) {
    fprintf(fp,", _c%d(c%d)", i, i);
  }
  // The body for the constructor is empty
  fprintf(fp," {}\n");
}

// ---------------------------------------------------------------------------
// Utilities to generate format rules for machine operands and instructions
// ---------------------------------------------------------------------------

// Generate the format rule for condition codes
static void defineCCodeDump(FILE *fp, int i) {
  fprintf(fp, "         if( _c%d == BoolTest::eq ) st->print(\"eq\");\n",i);
  fprintf(fp, "    else if( _c%d == BoolTest::ne ) st->print(\"ne\");\n",i);
  fprintf(fp, "    else if( _c%d == BoolTest::le ) st->print(\"le\");\n",i);
  fprintf(fp, "    else if( _c%d == BoolTest::ge ) st->print(\"ge\");\n",i);
  fprintf(fp, "    else if( _c%d == BoolTest::lt ) st->print(\"lt\");\n",i);
  fprintf(fp, "    else if( _c%d == BoolTest::gt ) st->print(\"gt\");\n",i);
}

// Output code that dumps constant values, increment "i" if type is constant
static uint dump_spec_constant(FILE *fp, const char *ideal_type, uint i) {
  if (!strcmp(ideal_type, "ConI")) {
    fprintf(fp,"   st->print(\"#%%d\", _c%d);\n", i);
    ++i;
  }
  else if (!strcmp(ideal_type, "ConP")) {
    fprintf(fp,"    _c%d->dump_on(st);\n", i);
    ++i;
  }
  else if (!strcmp(ideal_type, "ConN")) {
    fprintf(fp,"    _c%d->dump();\n", i);
    ++i;
  }
  else if (!strcmp(ideal_type, "ConL")) {
    fprintf(fp,"    st->print(\"#\" INT64_FORMAT, _c%d);\n", i);
    ++i;
  }
  else if (!strcmp(ideal_type, "ConF")) {
    fprintf(fp,"    st->print(\"#%%f\", _c%d);\n", i);
    ++i;
  }
  else if (!strcmp(ideal_type, "ConD")) {
    fprintf(fp,"    st->print(\"#%%f\", _c%d);\n", i);
    ++i;
  }
  else if (!strcmp(ideal_type, "Bool")) {
    defineCCodeDump(fp,i);
    ++i;
  }

  return i;
}

// Generate the format rule for an operand
void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file = false) {
  if (!for_c_file) {
    // invoked after output #ifndef PRODUCT to ad_<arch>.hpp
    // compile the bodies separately, to cut down on recompilations
    fprintf(fp,"  virtual void           int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const;\n");
    fprintf(fp,"  virtual void           ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const;\n");
    return;
  }

  // Local pointer indicates remaining part of format rule
  uint  idx = 0;                   // position of operand in match rule

  // Generate internal format function, used when stored locally
  fprintf(fp, "\n#ifndef PRODUCT\n");
  fprintf(fp,"void %sOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {\n", oper._ident);
  // Generate the user-defined portion of the format
  if (oper._format) {
    if ( oper._format->_strings.count() != 0 ) {
      // No initialization code for int_format

      // Build the format from the entries in strings and rep_vars
      const char  *string  = NULL;
      oper._format->_rep_vars.reset();
      oper._format->_strings.reset();
      while ( (string = oper._format->_strings.iter()) != NULL ) {
        fprintf(fp,"  ");

        // Check if this is a standard string or a replacement variable
        if ( string != NameList::_signal ) {
          // Normal string
          // Pass through to st->print
          fprintf(fp,"st->print(\"%s\");\n", string);
        } else {
          // Replacement variable
          const char *rep_var = oper._format->_rep_vars.iter();
          // Check that it is a local name, and an operand
          const Form* form = oper._localNames[rep_var];
          if (form == NULL) {
            globalAD->syntax_err(oper._linenum,
                                 "\'%s\' not found in format for %s\n", rep_var, oper._ident);
            assert(form, "replacement variable was not found in local names");
          }
          OperandForm *op      = form->is_operand();
          // Get index if register or constant
          if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
            idx  = oper.register_position( globals, rep_var);
          }
          else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
            idx  = oper.constant_position( globals, rep_var);
          } else {
            idx = 0;
          }

          // output invocation of "$..."s format function
          if ( op != NULL )   op->int_format(fp, globals, idx);

          if ( idx == -1 ) {
            fprintf(stderr,
                    "Using a name, %s, that isn't in match rule\n", rep_var);
            assert( strcmp(op->_ident,"label")==0, "Unimplemented");
          }
        } // Done with a replacement variable
      } // Done with all format strings
    } else {
      // Default formats for base operands (RegI, RegP, ConI, ConP, ...)
      oper.int_format(fp, globals, 0);
    }

  } else { // oper._format == NULL
    // Provide a few special case formats where the AD writer cannot.
    if ( strcmp(oper._ident,"Universe")==0 ) {
      fprintf(fp, "  st->print(\"$$univ\");\n");
    }
    // labelOper::int_format is defined in ad_<...>.cpp
  }
  // ALWAYS! Provide a special case output for condition codes.
  if( oper.is_ideal_bool() ) {
    defineCCodeDump(fp,0);
  }
  fprintf(fp,"}\n");

  // Generate external format function, when data is stored externally
  fprintf(fp,"void %sOper::ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const {\n", oper._ident);
  // Generate the user-defined portion of the format
  if (oper._format) {
    if ( oper._format->_strings.count() != 0 ) {

      // Check for a replacement string "$..."
      if ( oper._format->_rep_vars.count() != 0 ) {
        // Initialization code for ext_format
      }

      // Build the format from the entries in strings and rep_vars
      const char  *string  = NULL;
      oper._format->_rep_vars.reset();
      oper._format->_strings.reset();
      while ( (string = oper._format->_strings.iter()) != NULL ) {
        fprintf(fp,"  ");

        // Check if this is a standard string or a replacement variable
        if ( string != NameList::_signal ) {
          // Normal string
          // Pass through to st->print
          fprintf(fp,"st->print(\"%s\");\n", string);
        } else {
          // Replacement variable
          const char *rep_var = oper._format->_rep_vars.iter();
         // Check that it is a local name, and an operand
          const Form* form = oper._localNames[rep_var];
          if (form == NULL) {
            globalAD->syntax_err(oper._linenum,
                                 "\'%s\' not found in format for %s\n", rep_var, oper._ident);
            assert(form, "replacement variable was not found in local names");
          }
          OperandForm *op      = form->is_operand();
          // Get index if register or constant
          if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
            idx  = oper.register_position( globals, rep_var);
          }
          else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
            idx  = oper.constant_position( globals, rep_var);
          } else {
            idx = 0;
          }
          // output invocation of "$..."s format function
          if ( op != NULL )   op->ext_format(fp, globals, idx);

          // Lookup the index position of the replacement variable
          idx      = oper._components.operand_position_format(rep_var);
          if ( idx == -1 ) {
            fprintf(stderr,
                    "Using a name, %s, that isn't in match rule\n", rep_var);
            assert( strcmp(op->_ident,"label")==0, "Unimplemented");
          }
        } // Done with a replacement variable
      } // Done with all format strings

    } else {
      // Default formats for base operands (RegI, RegP, ConI, ConP, ...)
      oper.ext_format(fp, globals, 0);
    }
  } else { // oper._format == NULL
    // Provide a few special case formats where the AD writer cannot.
    if ( strcmp(oper._ident,"Universe")==0 ) {
      fprintf(fp, "  st->print(\"$$univ\");\n");
    }
    // labelOper::ext_format is defined in ad_<...>.cpp
  }
  // ALWAYS! Provide a special case output for condition codes.
  if( oper.is_ideal_bool() ) {
    defineCCodeDump(fp,0);
  }
  fprintf(fp, "}\n");
  fprintf(fp, "#endif\n");
}


// Generate the format rule for an instruction
void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &inst, bool for_c_file = false) {
  if (!for_c_file) {
    // compile the bodies separately, to cut down on recompilations
    // #ifndef PRODUCT region generated by caller
    fprintf(fp,"  virtual void           format(PhaseRegAlloc *ra, outputStream *st) const;\n");
    return;
  }

  // Define the format function
  fprintf(fp, "#ifndef PRODUCT\n");
  fprintf(fp, "void %sNode::format(PhaseRegAlloc *ra, outputStream *st) const {\n", inst._ident);

  // Generate the user-defined portion of the format
  if( inst._format ) {
    // If there are replacement variables,
    // Generate index values needed for determing the operand position
    if( inst._format->_rep_vars.count() )
      inst.index_temps(fp, globals);

    // Build the format from the entries in strings and rep_vars
    const char  *string  = NULL;
    inst._format->_rep_vars.reset();
    inst._format->_strings.reset();
    while( (string = inst._format->_strings.iter()) != NULL ) {
      fprintf(fp,"    ");
      // Check if this is a standard string or a replacement variable
      if( string != NameList::_signal )  // Normal string.  Pass through.
        fprintf(fp,"st->print(\"%s\");\n", string);
      else                      // Replacement variable
        inst.rep_var_format( fp, inst._format->_rep_vars.iter() );
    } // Done with all format strings
  } // Done generating the user-defined portion of the format

  // Add call debug info automatically
  Form::CallType call_type = inst.is_ideal_call();
  if( call_type != Form::invalid_type ) {
    switch( call_type ) {
    case Form::JAVA_DYNAMIC:
      fprintf(fp,"    _method->print_short_name();\n");
      break;
    case Form::JAVA_STATIC:
      fprintf(fp,"    if( _method ) _method->print_short_name(st); else st->print(\" wrapper for: %%s\", _name);\n");
      fprintf(fp,"    if( !_method ) dump_trap_args(st);\n");
      break;
    case Form::JAVA_COMPILED:
    case Form::JAVA_INTERP:
      break;
    case Form::JAVA_RUNTIME:
    case Form::JAVA_LEAF:
    case Form::JAVA_NATIVE:
      fprintf(fp,"    st->print(\" %%s\", _name);");
      break;
    default:
      assert(0,"ShouldNotReacHere");
    }
    fprintf(fp,  "    st->print_cr(\"\");\n" );
    fprintf(fp,  "    if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\"        No JVM State Info\");\n" );
    fprintf(fp,  "    st->print(\"        # \");\n" );
    fprintf(fp,  "    if( _jvms ) _oop_map->print_on(st);\n");
  }
  else if(inst.is_ideal_safepoint()) {
    fprintf(fp,  "    st->print(\"\");\n" );
    fprintf(fp,  "    if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\"        No JVM State Info\");\n" );
    fprintf(fp,  "    st->print(\"        # \");\n" );
    fprintf(fp,  "    if( _jvms ) _oop_map->print_on(st);\n");
  }
  else if( inst.is_ideal_if() ) {
    fprintf(fp,  "    st->print(\"  P=%%f C=%%f\",_prob,_fcnt);\n" );
  }
  else if( inst.is_ideal_mem() ) {
    // Print out the field name if available to improve readability
    fprintf(fp,  "    if (ra->C->alias_type(adr_type())->field() != NULL) {\n");
    fprintf(fp,  "      st->print(\" ! Field \");\n");
    fprintf(fp,  "      if( ra->C->alias_type(adr_type())->is_volatile() )\n");
    fprintf(fp,  "        st->print(\" Volatile\");\n");
    fprintf(fp,  "      ra->C->alias_type(adr_type())->field()->holder()->name()->print_symbol_on(st);\n");
    fprintf(fp,  "      st->print(\".\");\n");
    fprintf(fp,  "      ra->C->alias_type(adr_type())->field()->name()->print_symbol_on(st);\n");
    fprintf(fp,  "    } else\n");
    // Make sure 'Volatile' gets printed out
    fprintf(fp,  "    if( ra->C->alias_type(adr_type())->is_volatile() )\n");
    fprintf(fp,  "      st->print(\" Volatile!\");\n");
  }

  // Complete the definition of the format function
  fprintf(fp, "  }\n#endif\n");
}

static bool is_non_constant(char* x) {
  // Tells whether the string (part of an operator interface) is non-constant.
  // Simply detect whether there is an occurrence of a formal parameter,
  // which will always begin with '$'.
  return strchr(x, '$') == 0;
}

void ArchDesc::declare_pipe_classes(FILE *fp_hpp) {
  if (!_pipeline)
    return;

  fprintf(fp_hpp, "\n");
  fprintf(fp_hpp, "// Pipeline_Use_Cycle_Mask Class\n");
  fprintf(fp_hpp, "class Pipeline_Use_Cycle_Mask {\n");

  if (_pipeline->_maxcycleused <=
#ifdef SPARC
    64
#else
    32
#endif
      ) {
    fprintf(fp_hpp, "protected:\n");
    fprintf(fp_hpp, "  %s _mask;\n\n", _pipeline->_maxcycleused <= 32 ? "uint" : "uint64_t" );
    fprintf(fp_hpp, "public:\n");
    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask() : _mask(0) {}\n\n");
    if (_pipeline->_maxcycleused <= 32)
      fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask(uint mask) : _mask(mask) {}\n\n");
    else {
      fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask(uint mask1, uint mask2) : _mask((((uint64_t)mask1) << 32) | mask2) {}\n\n");
      fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask(uint64_t mask) : _mask(mask) {}\n\n");
    }
    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n");
    fprintf(fp_hpp, "    _mask = in._mask;\n");
    fprintf(fp_hpp, "    return *this;\n");
    fprintf(fp_hpp, "  }\n\n");
    fprintf(fp_hpp, "  bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");
    fprintf(fp_hpp, "    return ((_mask & in2._mask) != 0);\n");
    fprintf(fp_hpp, "  }\n\n");
    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");
    fprintf(fp_hpp, "    _mask <<= n;\n");
    fprintf(fp_hpp, "    return *this;\n");
    fprintf(fp_hpp, "  }\n\n");
    fprintf(fp_hpp, "  void Or(const Pipeline_Use_Cycle_Mask &in2) {\n");
    fprintf(fp_hpp, "    _mask |= in2._mask;\n");
    fprintf(fp_hpp, "  }\n\n");
    fprintf(fp_hpp, "  friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");
    fprintf(fp_hpp, "  friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");
  }
  else {
    fprintf(fp_hpp, "protected:\n");
    uint masklen = (_pipeline->_maxcycleused + 31) >> 5;
    uint l;
    fprintf(fp_hpp, "  uint ");
    for (l = 1; l <= masklen; l++)
      fprintf(fp_hpp, "_mask%d%s", l, l < masklen ? ", " : ";\n\n");
    fprintf(fp_hpp, "public:\n");
    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask() : ");
    for (l = 1; l <= masklen; l++)
      fprintf(fp_hpp, "_mask%d(0)%s", l, l < masklen ? ", " : " {}\n\n");
    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask(");
    for (l = 1; l <= masklen; l++)
      fprintf(fp_hpp, "uint mask%d%s", l, l < masklen ? ", " : ") : ");
    for (l = 1; l <= masklen; l++)
      fprintf(fp_hpp, "_mask%d(mask%d)%s", l, l, l < masklen ? ", " : " {}\n\n");

    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n");
    for (l = 1; l <= masklen; l++)
      fprintf(fp_hpp, "    _mask%d = in._mask%d;\n", l, l);
    fprintf(fp_hpp, "    return *this;\n");
    fprintf(fp_hpp, "  }\n\n");
    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask intersect(const Pipeline_Use_Cycle_Mask &in2) {\n");
    fprintf(fp_hpp, "    Pipeline_Use_Cycle_Mask out;\n");
    for (l = 1; l <= masklen; l++)
      fprintf(fp_hpp, "    out._mask%d = _mask%d & in2._mask%d;\n", l, l, l);
    fprintf(fp_hpp, "    return out;\n");
    fprintf(fp_hpp, "  }\n\n");
    fprintf(fp_hpp, "  bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");
    fprintf(fp_hpp, "    return (");
    for (l = 1; l <= masklen; l++)
      fprintf(fp_hpp, "((_mask%d & in2._mask%d) != 0)%s", l, l, l < masklen ? " || " : "");
    fprintf(fp_hpp, ") ? true : false;\n");
    fprintf(fp_hpp, "  }\n\n");
    fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");
    fprintf(fp_hpp, "    if (n >= 32)\n");
    fprintf(fp_hpp, "      do {\n       ");
    for (l = masklen; l > 1; l--)
      fprintf(fp_hpp, " _mask%d = _mask%d;", l, l-1);
    fprintf(fp_hpp, " _mask%d = 0;\n", 1);
    fprintf(fp_hpp, "      } while ((n -= 32) >= 32);\n\n");
    fprintf(fp_hpp, "    if (n > 0) {\n");
    fprintf(fp_hpp, "      uint m = 32 - n;\n");
    fprintf(fp_hpp, "      uint mask = (1 << n) - 1;\n");
    fprintf(fp_hpp, "      uint temp%d = mask & (_mask%d >> m); _mask%d <<= n;\n", 2, 1, 1);
    for (l = 2; l < masklen; l++) {
      fprintf(fp_hpp, "      uint temp%d = mask & (_mask%d >> m); _mask%d <<= n; _mask%d |= temp%d;\n", l+1, l, l, l, l);
    }
    fprintf(fp_hpp, "      _mask%d <<= n; _mask%d |= temp%d;\n", masklen, masklen, masklen);
    fprintf(fp_hpp, "    }\n");

    fprintf(fp_hpp, "    return *this;\n");
    fprintf(fp_hpp, "  }\n\n");
    fprintf(fp_hpp, "  void Or(const Pipeline_Use_Cycle_Mask &);\n\n");
    fprintf(fp_hpp, "  friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");
    fprintf(fp_hpp, "  friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");
  }

  fprintf(fp_hpp, "  friend class Pipeline_Use;\n\n");
  fprintf(fp_hpp, "  friend class Pipeline_Use_Element;\n\n");
  fprintf(fp_hpp, "};\n\n");

  uint rescount = 0;
  const char *resource;

  for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {
      int mask = _pipeline->_resdict[resource]->is_resource()->mask();
      if ((mask & (mask-1)) == 0)
        rescount++;
    }

  fprintf(fp_hpp, "// Pipeline_Use_Element Class\n");
  fprintf(fp_hpp, "class Pipeline_Use_Element {\n");
  fprintf(fp_hpp, "protected:\n");
  fprintf(fp_hpp, "  // Mask of used functional units\n");
  fprintf(fp_hpp, "  uint _used;\n\n");
  fprintf(fp_hpp, "  // Lower and upper bound of functional unit number range\n");
  fprintf(fp_hpp, "  uint _lb, _ub;\n\n");
  fprintf(fp_hpp, "  // Indicates multiple functionals units available\n");
  fprintf(fp_hpp, "  bool _multiple;\n\n");
  fprintf(fp_hpp, "  // Mask of specific used cycles\n");
  fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask _mask;\n\n");
  fprintf(fp_hpp, "public:\n");
  fprintf(fp_hpp, "  Pipeline_Use_Element() {}\n\n");
  fprintf(fp_hpp, "  Pipeline_Use_Element(uint used, uint lb, uint ub, bool multiple, Pipeline_Use_Cycle_Mask mask)\n");
  fprintf(fp_hpp, "  : _used(used), _lb(lb), _ub(ub), _multiple(multiple), _mask(mask) {}\n\n");
  fprintf(fp_hpp, "  uint used() const { return _used; }\n\n");
  fprintf(fp_hpp, "  uint lowerBound() const { return _lb; }\n\n");
  fprintf(fp_hpp, "  uint upperBound() const { return _ub; }\n\n");
  fprintf(fp_hpp, "  bool multiple() const { return _multiple; }\n\n");
  fprintf(fp_hpp, "  Pipeline_Use_Cycle_Mask mask() const { return _mask; }\n\n");
  fprintf(fp_hpp, "  bool overlaps(const Pipeline_Use_Element &in2) const {\n");
  fprintf(fp_hpp, "    return ((_used & in2._used) != 0 && _mask.overlaps(in2._mask));\n");
  fprintf(fp_hpp, "  }\n\n");
  fprintf(fp_hpp, "  void step(uint cycles) {\n");
  fprintf(fp_hpp, "    _used = 0;\n");
  fprintf(fp_hpp, "    _mask <<= cycles;\n");
  fprintf(fp_hpp, "  }\n\n");
  fprintf(fp_hpp, "  friend class Pipeline_Use;\n");
  fprintf(fp_hpp, "};\n\n");

  fprintf(fp_hpp, "// Pipeline_Use Class\n");
  fprintf(fp_hpp, "class Pipeline_Use {\n");
  fprintf(fp_hpp, "protected:\n");
  fprintf(fp_hpp, "  // These resources can be used\n");
  fprintf(fp_hpp, "  uint _resources_used;\n\n");
  fprintf(fp_hpp, "  // These resources are used; excludes multiple choice functional units\n");
  fprintf(fp_hpp, "  uint _resources_used_exclusively;\n\n");
  fprintf(fp_hpp, "  // Number of elements\n");
  fprintf(fp_hpp, "  uint _count;\n\n");
  fprintf(fp_hpp, "  // This is the array of Pipeline_Use_Elements\n");
  fprintf(fp_hpp, "  Pipeline_Use_Element * _elements;\n\n");
  fprintf(fp_hpp, "public:\n");
  fprintf(fp_hpp, "  Pipeline_Use(uint resources_used, uint resources_used_exclusively, uint count, Pipeline_Use_Element *elements)\n");
  fprintf(fp_hpp, "  : _resources_used(resources_used)\n");
  fprintf(fp_hpp, "  , _resources_used_exclusively(resources_used_exclusively)\n");
  fprintf(fp_hpp, "  , _count(count)\n");
  fprintf(fp_hpp, "  , _elements(elements)\n");
  fprintf(fp_hpp, "  {}\n\n");
  fprintf(fp_hpp, "  uint resourcesUsed() const { return _resources_used; }\n\n");
  fprintf(fp_hpp, "  uint resourcesUsedExclusively() const { return _resources_used_exclusively; }\n\n");
  fprintf(fp_hpp, "  uint count() const { return _count; }\n\n");
  fprintf(fp_hpp, "  Pipeline_Use_Element * element(uint i) const { return &_elements[i]; }\n\n");
  fprintf(fp_hpp, "  uint full_latency(uint delay, const Pipeline_Use &pred) const;\n\n");
  fprintf(fp_hpp, "  void add_usage(const Pipeline_Use &pred);\n\n");
  fprintf(fp_hpp, "  void reset() {\n");
  fprintf(fp_hpp, "    _resources_used = _resources_used_exclusively = 0;\n");
  fprintf(fp_hpp, "  };\n\n");
  fprintf(fp_hpp, "  void step(uint cycles) {\n");
  fprintf(fp_hpp, "    reset();\n");
  fprintf(fp_hpp, "    for (uint i = 0; i < %d; i++)\n",
    rescount);
  fprintf(fp_hpp, "      (&_elements[i])->step(cycles);\n");
  fprintf(fp_hpp, "  };\n\n");
  fprintf(fp_hpp, "  static const Pipeline_Use         elaborated_use;\n");
  fprintf(fp_hpp, "  static const Pipeline_Use_Element elaborated_elements[%d];\n\n",
    rescount);
  fprintf(fp_hpp, "  friend class Pipeline;\n");
  fprintf(fp_hpp, "};\n\n");

  fprintf(fp_hpp, "// Pipeline Class\n");
  fprintf(fp_hpp, "class Pipeline {\n");
  fprintf(fp_hpp, "public:\n");

  fprintf(fp_hpp, "  static bool enabled() { return %s; }\n\n",
    _pipeline ? "true" : "false" );

  assert( _pipeline->_maxInstrsPerBundle &&
        ( _pipeline->_instrUnitSize || _pipeline->_bundleUnitSize) &&
          _pipeline->_instrFetchUnitSize &&
          _pipeline->_instrFetchUnits,
    "unspecified pipeline architecture units");

  uint unitSize = _pipeline->_instrUnitSize ? _pipeline->_instrUnitSize : _pipeline->_bundleUnitSize;

  fprintf(fp_hpp, "  enum {\n");
  fprintf(fp_hpp, "    _variable_size_instructions = %d,\n",
    _pipeline->_variableSizeInstrs ? 1 : 0);
  fprintf(fp_hpp, "    _fixed_size_instructions = %d,\n",
    _pipeline->_variableSizeInstrs ? 0 : 1);
  fprintf(fp_hpp, "    _branch_has_delay_slot = %d,\n",
    _pipeline->_branchHasDelaySlot ? 1 : 0);
  fprintf(fp_hpp, "    _max_instrs_per_bundle = %d,\n",
    _pipeline->_maxInstrsPerBundle);
  fprintf(fp_hpp, "    _max_bundles_per_cycle = %d,\n",
    _pipeline->_maxBundlesPerCycle);
  fprintf(fp_hpp, "    _max_instrs_per_cycle = %d\n",
    _pipeline->_maxBundlesPerCycle * _pipeline->_maxInstrsPerBundle);
  fprintf(fp_hpp, "  };\n\n");

  fprintf(fp_hpp, "  static bool instr_has_unit_size() { return %s; }\n\n",
    _pipeline->_instrUnitSize != 0 ? "true" : "false" );
  if( _pipeline->_bundleUnitSize != 0 )
    if( _pipeline->_instrUnitSize != 0 )
      fprintf(fp_hpp, "// Individual Instructions may be bundled together by the hardware\n\n");
    else
      fprintf(fp_hpp, "// Instructions exist only in bundles\n\n");
  else
    fprintf(fp_hpp, "// Bundling is not supported\n\n");
  if( _pipeline->_instrUnitSize != 0 )
    fprintf(fp_hpp, "  // Size of an instruction\n");
  else
    fprintf(fp_hpp, "  // Size of an individual instruction does not exist - unsupported\n");
  fprintf(fp_hpp, "  static uint instr_unit_size() {");
  if( _pipeline->_instrUnitSize == 0 )
    fprintf(fp_hpp, " assert( false, \"Instructions are only in bundles\" );");
  fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_instrUnitSize);

  if( _pipeline->_bundleUnitSize != 0 )
    fprintf(fp_hpp, "  // Size of a bundle\n");
  else
    fprintf(fp_hpp, "  // Bundles do not exist - unsupported\n");
  fprintf(fp_hpp, "  static uint bundle_unit_size() {");
  if( _pipeline->_bundleUnitSize == 0 )
    fprintf(fp_hpp, " assert( false, \"Bundles are not supported\" );");
  fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_bundleUnitSize);

  fprintf(fp_hpp, "  static bool requires_bundling() { return %s; }\n\n",
    _pipeline->_bundleUnitSize != 0 && _pipeline->_instrUnitSize == 0 ? "true" : "false" );

  fprintf(fp_hpp, "private:\n");
  fprintf(fp_hpp, "  Pipeline();  // Not a legal constructor\n");
  fprintf(fp_hpp, "\n");
  fprintf(fp_hpp, "  const unsigned char                   _read_stage_count;\n");
  fprintf(fp_hpp, "  const unsigned char                   _write_stage;\n");
  fprintf(fp_hpp, "  const unsigned char                   _fixed_latency;\n");
  fprintf(fp_hpp, "  const unsigned char                   _instruction_count;\n");
  fprintf(fp_hpp, "  const bool                            _has_fixed_latency;\n");
  fprintf(fp_hpp, "  const bool                            _has_branch_delay;\n");
  fprintf(fp_hpp, "  const bool                            _has_multiple_bundles;\n");
  fprintf(fp_hpp, "  const bool                            _force_serialization;\n");
  fprintf(fp_hpp, "  const bool                            _may_have_no_code;\n");
  fprintf(fp_hpp, "  const enum machPipelineStages * const _read_stages;\n");
  fprintf(fp_hpp, "  const enum machPipelineStages * const _resource_stage;\n");
  fprintf(fp_hpp, "  const uint                    * const _resource_cycles;\n");
  fprintf(fp_hpp, "  const Pipeline_Use                    _resource_use;\n");
  fprintf(fp_hpp, "\n");
  fprintf(fp_hpp, "public:\n");
  fprintf(fp_hpp, "  Pipeline(uint                            write_stage,\n");
  fprintf(fp_hpp, "           uint                            count,\n");
  fprintf(fp_hpp, "           bool                            has_fixed_latency,\n");
  fprintf(fp_hpp, "           uint                            fixed_latency,\n");
  fprintf(fp_hpp, "           uint                            instruction_count,\n");
  fprintf(fp_hpp, "           bool                            has_branch_delay,\n");
  fprintf(fp_hpp, "           bool                            has_multiple_bundles,\n");
  fprintf(fp_hpp, "           bool                            force_serialization,\n");
  fprintf(fp_hpp, "           bool                            may_have_no_code,\n");
  fprintf(fp_hpp, "           enum machPipelineStages * const dst,\n");
  fprintf(fp_hpp, "           enum machPipelineStages * const stage,\n");
  fprintf(fp_hpp, "           uint                    * const cycles,\n");
  fprintf(fp_hpp, "           Pipeline_Use                    resource_use)\n");
  fprintf(fp_hpp, "  : _write_stage(write_stage)\n");
  fprintf(fp_hpp, "  , _read_stage_count(count)\n");
  fprintf(fp_hpp, "  , _has_fixed_latency(has_fixed_latency)\n");
  fprintf(fp_hpp, "  , _fixed_latency(fixed_latency)\n");
  fprintf(fp_hpp, "  , _read_stages(dst)\n");
  fprintf(fp_hpp, "  , _resource_stage(stage)\n");
  fprintf(fp_hpp, "  , _resource_cycles(cycles)\n");
  fprintf(fp_hpp, "  , _resource_use(resource_use)\n");
  fprintf(fp_hpp, "  , _instruction_count(instruction_count)\n");
  fprintf(fp_hpp, "  , _has_branch_delay(has_branch_delay)\n");
  fprintf(fp_hpp, "  , _has_multiple_bundles(has_multiple_bundles)\n");
  fprintf(fp_hpp, "  , _force_serialization(force_serialization)\n");
  fprintf(fp_hpp, "  , _may_have_no_code(may_have_no_code)\n");
  fprintf(fp_hpp, "  {};\n");
  fprintf(fp_hpp, "\n");
  fprintf(fp_hpp, "  uint writeStage() const {\n");
  fprintf(fp_hpp, "    return (_write_stage);\n");
  fprintf(fp_hpp, "  }\n");
  fprintf(fp_hpp, "\n");
  fprintf(fp_hpp, "  enum machPipelineStages readStage(int ndx) const {\n");
  fprintf(fp_hpp, "    return (ndx < _read_stage_count ? _read_stages[ndx] : stage_undefined);");
  fprintf(fp_hpp, "  }\n\n");
  fprintf(fp_hpp, "  uint resourcesUsed() const {\n");
  fprintf(fp_hpp, "    return _resource_use.resourcesUsed();\n  }\n\n");
  fprintf(fp_hpp, "  uint resourcesUsedExclusively() const {\n");
  fprintf(fp_hpp, "    return _resource_use.resourcesUsedExclusively();\n  }\n\n");
  fprintf(fp_hpp, "  bool hasFixedLatency() const {\n");
  fprintf(fp_hpp, "    return (_has_fixed_latency);\n  }\n\n");
  fprintf(fp_hpp, "  uint fixedLatency() const {\n");
  fprintf(fp_hpp, "    return (_fixed_latency);\n  }\n\n");
  fprintf(fp_hpp, "  uint functional_unit_latency(uint start, const Pipeline *pred) const;\n\n");
  fprintf(fp_hpp, "  uint operand_latency(uint opnd, const Pipeline *pred) const;\n\n");
  fprintf(fp_hpp, "  const Pipeline_Use& resourceUse() const {\n");
  fprintf(fp_hpp, "    return (_resource_use); }\n\n");
  fprintf(fp_hpp, "  const Pipeline_Use_Element * resourceUseElement(uint i) const {\n");
  fprintf(fp_hpp, "    return (&_resource_use._elements[i]); }\n\n");
  fprintf(fp_hpp, "  uint resourceUseCount() const {\n");
  fprintf(fp_hpp, "    return (_resource_use._count); }\n\n");
  fprintf(fp_hpp, "  uint instructionCount() const {\n");
  fprintf(fp_hpp, "    return (_instruction_count); }\n\n");
  fprintf(fp_hpp, "  bool hasBranchDelay() const {\n");
  fprintf(fp_hpp, "    return (_has_branch_delay); }\n\n");
  fprintf(fp_hpp, "  bool hasMultipleBundles() const {\n");
  fprintf(fp_hpp, "    return (_has_multiple_bundles); }\n\n");
  fprintf(fp_hpp, "  bool forceSerialization() const {\n");
  fprintf(fp_hpp, "    return (_force_serialization); }\n\n");
  fprintf(fp_hpp, "  bool mayHaveNoCode() const {\n");
  fprintf(fp_hpp, "    return (_may_have_no_code); }\n\n");
  fprintf(fp_hpp, "//const Pipeline_Use_Cycle_Mask& resourceUseMask(int resource) const {\n");
  fprintf(fp_hpp, "//  return (_resource_use_masks[resource]); }\n\n");
  fprintf(fp_hpp, "\n#ifndef PRODUCT\n");
  fprintf(fp_hpp, "  static const char * stageName(uint i);\n");
  fprintf(fp_hpp, "#endif\n");
  fprintf(fp_hpp, "};\n\n");

  fprintf(fp_hpp, "// Bundle class\n");
  fprintf(fp_hpp, "class Bundle {\n");

  uint mshift = 0;
  for (uint msize = _pipeline->_maxInstrsPerBundle * _pipeline->_maxBundlesPerCycle; msize != 0; msize >>= 1)
    mshift++;

  uint rshift = rescount;

  fprintf(fp_hpp, "protected:\n");
  fprintf(fp_hpp, "  enum {\n");
  fprintf(fp_hpp, "    _unused_delay                   = 0x%x,\n", 0);
  fprintf(fp_hpp, "    _use_nop_delay                  = 0x%x,\n", 1);
  fprintf(fp_hpp, "    _use_unconditional_delay        = 0x%x,\n", 2);
  fprintf(fp_hpp, "    _use_conditional_delay          = 0x%x,\n", 3);
  fprintf(fp_hpp, "    _used_in_conditional_delay      = 0x%x,\n", 4);
  fprintf(fp_hpp, "    _used_in_unconditional_delay    = 0x%x,\n", 5);
  fprintf(fp_hpp, "    _used_in_all_conditional_delays = 0x%x,\n", 6);
  fprintf(fp_hpp, "\n");
  fprintf(fp_hpp, "    _use_delay                      = 0x%x,\n", 3);
  fprintf(fp_hpp, "    _used_in_delay                  = 0x%x\n",  4);
  fprintf(fp_hpp, "  };\n\n");
  fprintf(fp_hpp, "  uint _flags          : 3,\n");
  fprintf(fp_hpp, "       _starts_bundle  : 1,\n");
  fprintf(fp_hpp, "       _instr_count    : %d,\n",   mshift);
  fprintf(fp_hpp, "       _resources_used : %d;\n",   rshift);
  fprintf(fp_hpp, "public:\n");
  fprintf(fp_hpp, "  Bundle() : _flags(_unused_delay), _starts_bundle(0), _instr_count(0), _resources_used(0) {}\n\n");
  fprintf(fp_hpp, "  void set_instr_count(uint i) { _instr_count  = i; }\n");
  fprintf(fp_hpp, "  void set_resources_used(uint i) { _resources_used   = i; }\n");
  fprintf(fp_hpp, "  void clear_usage() { _flags = _unused_delay; }\n");
  fprintf(fp_hpp, "  void set_starts_bundle() { _starts_bundle = true; }\n");

  fprintf(fp_hpp, "  uint flags() const { return (_flags); }\n");
  fprintf(fp_hpp, "  uint instr_count() const { return (_instr_count); }\n");
  fprintf(fp_hpp, "  uint resources_used() const { return (_resources_used); }\n");
  fprintf(fp_hpp, "  bool starts_bundle() const { return (_starts_bundle != 0); }\n");

  fprintf(fp_hpp, "  void set_use_nop_delay() { _flags = _use_nop_delay; }\n");
  fprintf(fp_hpp, "  void set_use_unconditional_delay() { _flags = _use_unconditional_delay; }\n");
  fprintf(fp_hpp, "  void set_use_conditional_delay() { _flags = _use_conditional_delay; }\n");
  fprintf(fp_hpp, "  void set_used_in_unconditional_delay() { _flags = _used_in_unconditional_delay; }\n");
  fprintf(fp_hpp, "  void set_used_in_conditional_delay() { _flags = _used_in_conditional_delay; }\n");
  fprintf(fp_hpp, "  void set_used_in_all_conditional_delays() { _flags = _used_in_all_conditional_delays; }\n");

  fprintf(fp_hpp, "  bool use_nop_delay() { return (_flags == _use_nop_delay); }\n");
  fprintf(fp_hpp, "  bool use_unconditional_delay() { return (_flags == _use_unconditional_delay); }\n");
  fprintf(fp_hpp, "  bool use_conditional_delay() { return (_flags == _use_conditional_delay); }\n");
  fprintf(fp_hpp, "  bool used_in_unconditional_delay() { return (_flags == _used_in_unconditional_delay); }\n");
  fprintf(fp_hpp, "  bool used_in_conditional_delay() { return (_flags == _used_in_conditional_delay); }\n");
  fprintf(fp_hpp, "  bool used_in_all_conditional_delays() { return (_flags == _used_in_all_conditional_delays); }\n");
  fprintf(fp_hpp, "  bool use_delay() { return ((_flags & _use_delay) != 0); }\n");
  fprintf(fp_hpp, "  bool used_in_delay() { return ((_flags & _used_in_delay) != 0); }\n\n");

  fprintf(fp_hpp, "  enum {\n");
  fprintf(fp_hpp, "    _nop_count = %d\n",
    _pipeline->_nopcnt);
  fprintf(fp_hpp, "  };\n\n");
  fprintf(fp_hpp, "  static void initialize_nops(MachNode *nop_list[%d], Compile* C);\n\n",
    _pipeline->_nopcnt);
  fprintf(fp_hpp, "#ifndef PRODUCT\n");
  fprintf(fp_hpp, "  void dump() const;\n");
  fprintf(fp_hpp, "#endif\n");
  fprintf(fp_hpp, "};\n\n");

//  const char *classname;
//  for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) {
//    PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass();
//    fprintf(fp_hpp, "// Pipeline Class Instance for \"%s\"\n", classname);
//  }
}

//------------------------------declareClasses---------------------------------
// Construct the class hierarchy of MachNode classes from the instruction &
// operand lists
void ArchDesc::declareClasses(FILE *fp) {

  // Declare an array containing the machine register names, strings.
  declareRegNames(fp, _register);

  // Declare an array containing the machine register encoding values
  declareRegEncodes(fp, _register);

  // Generate declarations for the total number of operands
  fprintf(fp,"\n");
  fprintf(fp,"// Total number of operands defined in architecture definition\n");
  int num_operands = 0;
  OperandForm *op;
  for (_operands.reset(); (op = (OperandForm*)_operands.iter()) != NULL; ) {
    // Ensure this is a machine-world instruction
    if (op->ideal_only()) continue;

    ++num_operands;
  }
  int first_operand_class = num_operands;
  OpClassForm *opc;
  for (_opclass.reset(); (opc = (OpClassForm*)_opclass.iter()) != NULL; ) {
    // Ensure this is a machine-world instruction
    if (opc->ideal_only()) continue;

    ++num_operands;
  }
  fprintf(fp,"#define FIRST_OPERAND_CLASS   %d\n", first_operand_class);
  fprintf(fp,"#define NUM_OPERANDS          %d\n", num_operands);
  fprintf(fp,"\n");
  // Generate declarations for the total number of instructions
  fprintf(fp,"// Total number of instructions defined in architecture definition\n");
  fprintf(fp,"#define NUM_INSTRUCTIONS   %d\n",instructFormCount());


  // Generate Machine Classes for each operand defined in AD file
  fprintf(fp,"\n");
  fprintf(fp,"//----------------------------Declare classes derived from MachOper----------\n");
  // Iterate through all operands
  _operands.reset();
  OperandForm *oper;
  for( ; (oper = (OperandForm*)_operands.iter()) != NULL;) {
    // Ensure this is a machine-world instruction
    if (oper->ideal_only() ) continue;
    // The declaration of labelOper is in machine-independent file: machnode
    if ( strcmp(oper->_ident,"label")  == 0 ) continue;
    // The declaration of methodOper is in machine-independent file: machnode
    if ( strcmp(oper->_ident,"method") == 0 ) continue;

    // Build class definition for this operand
    fprintf(fp,"\n");
    fprintf(fp,"class %sOper : public MachOper { \n",oper->_ident);
    fprintf(fp,"private:\n");
    // Operand definitions that depend upon number of input edges
    {
      uint num_edges = oper->num_edges(_globalNames);
      if( num_edges != 1 ) { // Use MachOper::num_edges() {return 1;}
        fprintf(fp,"  virtual uint           num_edges() const { return %d; }\n",
              num_edges );
      }
      if( num_edges > 0 ) {
        in_RegMask(fp);
      }
    }

    // Support storing constants inside the MachOper
    declareConstStorage(fp,_globalNames,oper);

    // Support storage of the condition codes
    if( oper->is_ideal_bool() ) {
      fprintf(fp,"  virtual int ccode() const { \n");
      fprintf(fp,"    switch (_c0) {\n");
      fprintf(fp,"    case  BoolTest::eq : return equal();\n");
      fprintf(fp,"    case  BoolTest::gt : return greater();\n");
      fprintf(fp,"    case  BoolTest::lt : return less();\n");
      fprintf(fp,"    case  BoolTest::ne : return not_equal();\n");
      fprintf(fp,"    case  BoolTest::le : return less_equal();\n");
      fprintf(fp,"    case  BoolTest::ge : return greater_equal();\n");
      fprintf(fp,"    default : ShouldNotReachHere(); return 0;\n");
      fprintf(fp,"    }\n");
      fprintf(fp,"  };\n");
    }

    // Support storage of the condition codes
    if( oper->is_ideal_bool() ) {
      fprintf(fp,"  virtual void negate() { \n");
      fprintf(fp,"    _c0 = (BoolTest::mask)((int)_c0^0x4); \n");
      fprintf(fp,"  };\n");
    }

    // Declare constructor.
    // Parameters start with condition code, then all other constants
    //
    // (1)  MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)
    // (2)     : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }
    //
    Form::DataType constant_type = oper->simple_type(_globalNames);
    defineConstructor(fp, oper->_ident, oper->num_consts(_globalNames),
                      oper->_components, oper->is_ideal_bool(),
                      constant_type, _globalNames);

    // Clone function
    fprintf(fp,"  virtual MachOper      *clone(Compile* C) const;\n");

    // Support setting a spill offset into a constant operand.
    // We only support setting an 'int' offset, while in the
    // LP64 build spill offsets are added with an AddP which
    // requires a long constant.  Thus we don't support spilling
    // in frames larger than 4Gig.
    if( oper->has_conI(_globalNames) ||
        oper->has_conL(_globalNames) )
      fprintf(fp, "  virtual void set_con( jint c0 ) { _c0 = c0; }\n");

    // virtual functions for encoding and format
    //    fprintf(fp,"  virtual void           encode()   const {\n    %s }\n",
    //            (oper->_encrule)?(oper->_encrule->_encrule):"");
    // Check the interface type, and generate the correct query functions
    // encoding queries based upon MEMORY_INTER, REG_INTER, CONST_INTER.

    fprintf(fp,"  virtual uint           opcode() const { return %s; }\n",
            machOperEnum(oper->_ident));

    // virtual function to look up ideal return type of machine instruction
    //
    // (1)  virtual const Type    *type() const { return .....; }
    //
    if ((oper->_matrule) && (oper->_matrule->_lChild == NULL) &&
        (oper->_matrule->_rChild == NULL)) {
      unsigned int position = 0;
      const char  *opret, *opname, *optype;
      oper->_matrule->base_operand(position,_globalNames,opret,opname,optype);
      fprintf(fp,"  virtual const Type *type() const {");
      const char *type = getIdealType(optype);
      if( type != NULL ) {
        Form::DataType data_type = oper->is_base_constant(_globalNames);
        // Check if we are an ideal pointer type
        if( data_type == Form::idealP || data_type == Form::idealN ) {
          // Return the ideal type we already have: <TypePtr *>
          fprintf(fp," return _c0;");
        } else {
          // Return the appropriate bottom type
          fprintf(fp," return %s;", getIdealType(optype));
        }
      } else {
        fprintf(fp," ShouldNotCallThis(); return Type::BOTTOM;");
      }
      fprintf(fp," }\n");
    } else {
      // Check for user-defined stack slots, based upon sRegX
      Form::DataType data_type = oper->is_user_name_for_sReg();
      if( data_type != Form::none ){
        const char *type = NULL;
        switch( data_type ) {
        case Form::idealI: type = "TypeInt::INT";   break;
        case Form::idealP: type = "TypePtr::BOTTOM";break;
        case Form::idealF: type = "Type::FLOAT";    break;
        case Form::idealD: type = "Type::DOUBLE";   break;
        case Form::idealL: type = "TypeLong::LONG"; break;
        case Form::none: // fall through
        default:
          assert( false, "No support for this type of stackSlot");
        }
        fprintf(fp,"  virtual const Type    *type() const { return %s; } // stackSlotX\n", type);
      }
    }


    //
    // virtual functions for defining the encoding interface.
    //
    // Access the linearized ideal register mask,
    // map to physical register encoding
    if ( oper->_matrule && oper->_matrule->is_base_register(_globalNames) ) {
      // Just use the default virtual 'reg' call
    } else if ( oper->ideal_to_sReg_type(oper->_ident) != Form::none ) {
      // Special handling for operand 'sReg', a Stack Slot Register.
      // Map linearized ideal register mask to stack slot number
      fprintf(fp,"  virtual int            reg(PhaseRegAlloc *ra_, const Node *node) const {\n");
      fprintf(fp,"    return (int)OptoReg::reg2stack(ra_->get_reg_first(node));/* sReg */\n");
      fprintf(fp,"  }\n");
      fprintf(fp,"  virtual int            reg(PhaseRegAlloc *ra_, const Node *node, int idx) const {\n");
      fprintf(fp,"    return (int)OptoReg::reg2stack(ra_->get_reg_first(node->in(idx)));/* sReg */\n");
      fprintf(fp,"  }\n");
    }

    // Output the operand specific access functions used by an enc_class
    // These are only defined when we want to override the default virtual func
    if (oper->_interface != NULL) {
      fprintf(fp,"\n");
      // Check if it is a Memory Interface
      if ( oper->_interface->is_MemInterface() != NULL ) {
        MemInterface *mem_interface = oper->_interface->is_MemInterface();
        const char *base = mem_interface->_base;
        if( base != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "base", base);
        }
        char *index = mem_interface->_index;
        if( index != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "index", index);
        }
        const char *scale = mem_interface->_scale;
        if( scale != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "scale", scale);
        }
        const char *disp = mem_interface->_disp;
        if( disp != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "disp", disp);
          oper->disp_is_oop(fp, _globalNames);
        }
        if( oper->stack_slots_only(_globalNames) ) {
          // should not call this:
          fprintf(fp,"  virtual int       constant_disp() const { return Type::OffsetBot; }");
        } else if ( disp != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "constant_disp", disp);
        }
      } // end Memory Interface
      // Check if it is a Conditional Interface
      else if (oper->_interface->is_CondInterface() != NULL) {
        CondInterface *cInterface = oper->_interface->is_CondInterface();
        const char *equal = cInterface->_equal;
        if( equal != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "equal", equal);
        }
        const char *not_equal = cInterface->_not_equal;
        if( not_equal != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "not_equal", not_equal);
        }
        const char *less = cInterface->_less;
        if( less != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "less", less);
        }
        const char *greater_equal = cInterface->_greater_equal;
        if( greater_equal != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "greater_equal", greater_equal);
        }
        const char *less_equal = cInterface->_less_equal;
        if( less_equal != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "less_equal", less_equal);
        }
        const char *greater = cInterface->_greater;
        if( greater != NULL ) {
          define_oper_interface(fp, *oper, _globalNames, "greater", greater);
        }
      } // end Conditional Interface
      // Check if it is a Constant Interface
      else if (oper->_interface->is_ConstInterface() != NULL ) {
        assert( oper->num_consts(_globalNames) == 1,
                "Must have one constant when using CONST_INTER encoding");
        if (!strcmp(oper->ideal_type(_globalNames), "ConI")) {
          // Access the locally stored constant
          fprintf(fp,"  virtual intptr_t       constant() const {");
          fprintf(fp,   " return (intptr_t)_c0;");
          fprintf(fp,"  }\n");
        }
        else if (!strcmp(oper->ideal_type(_globalNames), "ConP")) {
          // Access the locally stored constant
          fprintf(fp,"  virtual intptr_t       constant() const {");
          fprintf(fp,   " return _c0->get_con();");
          fprintf(fp, " }\n");
          // Generate query to determine if this pointer is an oop
          fprintf(fp,"  virtual bool           constant_is_oop() const {");
          fprintf(fp,   " return _c0->isa_oop_ptr();");
          fprintf(fp, " }\n");
        }
        else if (!strcmp(oper->ideal_type(_globalNames), "ConN")) {
          // Access the locally stored constant
          fprintf(fp,"  virtual intptr_t       constant() const {");
          fprintf(fp,   " return _c0->make_oopptr()->get_con();");
          fprintf(fp, " }\n");
          // Generate query to determine if this pointer is an oop
          fprintf(fp,"  virtual bool           constant_is_oop() const {");
          fprintf(fp,   " return _c0->make_oopptr()->isa_oop_ptr();");
          fprintf(fp, " }\n");
        }
        else if (!strcmp(oper->ideal_type(_globalNames), "ConL")) {
          fprintf(fp,"  virtual intptr_t       constant() const {");
          // We don't support addressing modes with > 4Gig offsets.
          // Truncate to int.
          fprintf(fp,   "  return (intptr_t)_c0;");
          fprintf(fp, " }\n");
          fprintf(fp,"  virtual jlong          constantL() const {");
          fprintf(fp,   " return _c0;");
          fprintf(fp, " }\n");
        }
        else if (!strcmp(oper->ideal_type(_globalNames), "ConF")) {
          fprintf(fp,"  virtual intptr_t       constant() const {");
          fprintf(fp,   " ShouldNotReachHere(); return 0; ");
          fprintf(fp, " }\n");
          fprintf(fp,"  virtual jfloat         constantF() const {");
          fprintf(fp,   " return (jfloat)_c0;");
          fprintf(fp, " }\n");
        }
        else if (!strcmp(oper->ideal_type(_globalNames), "ConD")) {
          fprintf(fp,"  virtual intptr_t       constant() const {");
          fprintf(fp,   " ShouldNotReachHere(); return 0; ");
          fprintf(fp, " }\n");
          fprintf(fp,"  virtual jdouble        constantD() const {");
          fprintf(fp,   " return _c0;");
          fprintf(fp, " }\n");
        }
      }
      else if (oper->_interface->is_RegInterface() != NULL) {
        // make sure that a fixed format string isn't used for an
        // operand which might be assiged to multiple registers.
        // Otherwise the opto assembly output could be misleading.
        if (oper->_format->_strings.count() != 0 && !oper->is_bound_register()) {
          syntax_err(oper->_linenum,
                     "Only bound registers can have fixed formats: %s\n",
                     oper->_ident);
        }
      }
      else {
        assert( false, "ShouldNotReachHere();");
      }
    }

    fprintf(fp,"\n");
    // // Currently all XXXOper::hash() methods are identical (990820)
    // declare_hash(fp);
    // // Currently all XXXOper::Cmp() methods are identical (990820)
    // declare_cmp(fp);

    // Do not place dump_spec() and Name() into PRODUCT code
    // int_format and ext_format are not needed in PRODUCT code either
    fprintf(fp, "#ifndef PRODUCT\n");

    // Declare int_format() and ext_format()
    gen_oper_format(fp, _globalNames, *oper);

    // Machine independent print functionality for debugging
    // IF we have constants, create a dump_spec function for the derived class
    //
    // (1)  virtual void           dump_spec() const {
    // (2)    st->print("#%d", _c#);        // Constant != ConP
    //  OR    _c#->dump_on(st);             // Type ConP
    //  ...
    // (3)  }
    uint num_consts = oper->num_consts(_globalNames);
    if( num_consts > 0 ) {
      // line (1)
      fprintf(fp, "  virtual void           dump_spec(outputStream *st) const {\n");
      // generate format string for st->print
      // Iterate over the component list & spit out the right thing
      uint i = 0;
      const char *type = oper->ideal_type(_globalNames);
      Component  *comp;
      oper->_components.reset();
      if ((comp = oper->_components.iter()) == NULL) {
        assert(num_consts == 1, "Bad component list detected.\n");
        i = dump_spec_constant( fp, type, i );
        // Check that type actually matched
        assert( i != 0, "Non-constant operand lacks component list.");
      } // end if NULL
      else {
        // line (2)
        // dump all components
        oper->_components.reset();
        while((comp = oper->_components.iter()) != NULL) {
          type = comp->base_type(_globalNames);
          i = dump_spec_constant( fp, type, i );
        }
      }
      // finish line (3)
      fprintf(fp,"  }\n");
    }

    fprintf(fp,"  virtual const char    *Name() const { return \"%s\";}\n",
            oper->_ident);

    fprintf(fp,"#endif\n");

    // Close definition of this XxxMachOper
    fprintf(fp,"};\n");
  }


  // Generate Machine Classes for each instruction defined in AD file
  fprintf(fp,"\n");
  fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n");
  declare_pipe_classes(fp);

  // Generate Machine Classes for each instruction defined in AD file
  fprintf(fp,"\n");
  fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n");
  _instructions.reset();
  InstructForm *instr;
  for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
    // Ensure this is a machine-world instruction
    if ( instr->ideal_only() ) continue;

    // Build class definition for this instruction
    fprintf(fp,"\n");
    fprintf(fp,"class %sNode : public %s { \n",
            instr->_ident, instr->mach_base_class() );
    fprintf(fp,"private:\n");
    fprintf(fp,"  MachOper *_opnd_array[%d];\n", instr->num_opnds() );
    if ( instr->is_ideal_jump() ) {
      fprintf(fp, "  GrowableArray<Label*> _index2label;\n");
    }
    fprintf(fp,"public:\n");
    fprintf(fp,"  MachOper *opnd_array(uint operand_index) const { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); return _opnd_array[operand_index]; }\n");
    fprintf(fp,"  void      set_opnd_array(uint operand_index, MachOper *operand) { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); _opnd_array[operand_index] = operand; }\n");
    fprintf(fp,"private:\n");
    if ( instr->is_ideal_jump() ) {
      fprintf(fp,"  virtual void           add_case_label(int index_num, Label* blockLabel) {\n");
      fprintf(fp,"                                          _index2label.at_put_grow(index_num, blockLabel);}\n");
    }
    if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {
      fprintf(fp,"  const RegMask  *_cisc_RegMask;\n");
    }

    out_RegMask(fp);                      // output register mask
    fprintf(fp,"  virtual uint           rule() const { return %s_rule; }\n",
            instr->_ident);

    // If this instruction contains a labelOper
    // Declare Node::methods that set operand Label's contents
    int label_position = instr->label_position();
    if( label_position != -1 ) {
      // Set the label, stored in labelOper::_branch_label
      fprintf(fp,"  virtual void           label_set( Label& label, uint block_num );\n");
    }

    // If this instruction contains a methodOper
    // Declare Node::methods that set operand method's contents
    int method_position = instr->method_position();
    if( method_position != -1 ) {
      // Set the address method, stored in methodOper::_method
      fprintf(fp,"  virtual void           method_set( intptr_t method );\n");
    }

    // virtual functions for attributes
    //
    // Each instruction attribute results in a virtual call of same name.
    // The ins_cost is not handled here.
    Attribute *attr = instr->_attribs;
    bool is_pc_relative = false;
    while (attr != NULL) {
      if (strcmp(attr->_ident,"ins_cost") &&
          strcmp(attr->_ident,"ins_pc_relative")) {
        fprintf(fp,"  int             %s() const { return %s; }\n",
                attr->_ident, attr->_val);
      }
      // Check value for ins_pc_relative, and if it is true (1), set the flag
      if (!strcmp(attr->_ident,"ins_pc_relative") && attr->int_val(*this) != 0)
        is_pc_relative = true;
      attr = (Attribute *)attr->_next;
    }

    // virtual functions for encode and format
    //
    // Output the opcode function and the encode function here using the
    // encoding class information in the _insencode slot.
    if ( instr->_insencode ) {
      fprintf(fp,"  virtual void           emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const;\n");
    }

    // virtual function for getting the size of an instruction
    if ( instr->_size ) {
       fprintf(fp,"  virtual uint           size(PhaseRegAlloc *ra_) const;\n");
    }

    // Return the top-level ideal opcode.
    // Use MachNode::ideal_Opcode() for nodes based on MachNode class
    // if the ideal_Opcode == Op_Node.
    if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 ||
         strcmp("MachNode", instr->mach_base_class()) != 0 ) {
      fprintf(fp,"  virtual int            ideal_Opcode() const { return Op_%s; }\n",
            instr->ideal_Opcode(_globalNames) );
    }

    // Allow machine-independent optimization, invert the sense of the IF test
    if( instr->is_ideal_if() ) {
      fprintf(fp,"  virtual void           negate() { \n");
      // Identify which operand contains the negate(able) ideal condition code
      int   idx = 0;
      instr->_components.reset();
      for( Component *comp; (comp = instr->_components.iter()) != NULL; ) {
        // Check that component is an operand
        Form *form = (Form*)_globalNames[comp->_type];
        OperandForm *opForm = form ? form->is_operand() : NULL;
        if( opForm == NULL ) continue;

        // Lookup the position of the operand in the instruction.
        if( opForm->is_ideal_bool() ) {
          idx = instr->operand_position(comp->_name, comp->_usedef);
          assert( idx != NameList::Not_in_list, "Did not find component in list that contained it.");
          break;
        }
      }
      fprintf(fp,"    opnd_array(%d)->negate();\n", idx);
      fprintf(fp,"    _prob = 1.0f - _prob;\n");
      fprintf(fp,"  };\n");
    }


    // Identify which input register matches the input register.
    uint  matching_input = instr->two_address(_globalNames);

    // Generate the method if it returns != 0 otherwise use MachNode::two_adr()
    if( matching_input != 0 ) {
      fprintf(fp,"  virtual uint           two_adr() const  ");
      fprintf(fp,"{ return oper_input_base()");
      for( uint i = 2; i <= matching_input; i++ )
        fprintf(fp," + opnd_array(%d)->num_edges()",i-1);
      fprintf(fp,"; }\n");
    }

    // Declare cisc_version, if applicable
    //   MachNode *cisc_version( int offset /* ,... */ );
    instr->declare_cisc_version(*this, fp);

    // If there is an explicit peephole rule, build it
    if ( instr->peepholes() != NULL ) {
      fprintf(fp,"  virtual MachNode      *peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile *C);\n");
    }

    // Output the declaration for number of relocation entries
    if ( instr->reloc(_globalNames) != 0 ) {
      fprintf(fp,"  virtual int            reloc()   const;\n");
    }

    if (instr->alignment() != 1) {
      fprintf(fp,"  virtual int            alignment_required()   const { return %d; }\n", instr->alignment());
      fprintf(fp,"  virtual int            compute_padding(int current_offset)   const;\n");
    }

    // Starting point for inputs matcher wants.
    // Use MachNode::oper_input_base() for nodes based on MachNode class
    // if the base == 1.
    if ( instr->oper_input_base(_globalNames) != 1 ||
         strcmp("MachNode", instr->mach_base_class()) != 0 ) {
      fprintf(fp,"  virtual uint           oper_input_base() const { return %d; }\n",
            instr->oper_input_base(_globalNames));
    }

    // Make the constructor and following methods 'public:'
    fprintf(fp,"public:\n");

    // Constructor
    if ( instr->is_ideal_jump() ) {
      fprintf(fp,"  %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident);
    } else {
      fprintf(fp,"  %sNode() { ", instr->_ident);
      if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {
        fprintf(fp,"_cisc_RegMask = NULL; ");
      }
    }

    fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds());

    bool node_flags_set = false;
    // flag: if this instruction matches an ideal 'Goto' node
    if ( instr->is_ideal_goto() ) {
      fprintf(fp,"init_flags(Flag_is_Goto");
      node_flags_set = true;
    }

    // flag: if this instruction matches an ideal 'Copy*' node
    if ( instr->is_ideal_copy() != 0 ) {
      if ( node_flags_set ) {
        fprintf(fp," | Flag_is_Copy");
      } else {
        fprintf(fp,"init_flags(Flag_is_Copy");
        node_flags_set = true;
      }
    }

    // Is an instruction is a constant?  If so, get its type
    Form::DataType  data_type;
    const char     *opType = NULL;
    const char     *result = NULL;
    data_type    = instr->is_chain_of_constant(_globalNames, opType, result);
    // Check if this instruction is a constant
    if ( data_type != Form::none ) {
      if ( node_flags_set ) {
        fprintf(fp," | Flag_is_Con");
      } else {
        fprintf(fp,"init_flags(Flag_is_Con");
        node_flags_set = true;
      }
    }

    // flag: if instruction matches 'If' | 'Goto' | 'CountedLoopEnd | 'Jump'
    if ( instr->is_ideal_branch() ) {
      if ( node_flags_set ) {
        fprintf(fp," | Flag_is_Branch");
      } else {
        fprintf(fp,"init_flags(Flag_is_Branch");
        node_flags_set = true;
      }
    }

    // flag: if this instruction is cisc alternate
    if ( can_cisc_spill() && instr->is_cisc_alternate() ) {
      if ( node_flags_set ) {
        fprintf(fp," | Flag_is_cisc_alternate");
      } else {
        fprintf(fp,"init_flags(Flag_is_cisc_alternate");
        node_flags_set = true;
      }
    }

    // flag: if this instruction is pc relative
    if ( is_pc_relative ) {
      if ( node_flags_set ) {
        fprintf(fp," | Flag_is_pc_relative");
      } else {
        fprintf(fp,"init_flags(Flag_is_pc_relative");
        node_flags_set = true;
      }
    }

    // flag: if this instruction has short branch form
    if ( instr->has_short_branch_form() ) {
      if ( node_flags_set ) {
        fprintf(fp," | Flag_may_be_short_branch");
      } else {
        fprintf(fp,"init_flags(Flag_may_be_short_branch");
        node_flags_set = true;
      }
    }

    // Check if machine instructions that USE memory, but do not DEF memory,
    // depend upon a node that defines memory in machine-independent graph.
    if ( instr->needs_anti_dependence_check(_globalNames) ) {
      if ( node_flags_set ) {
        fprintf(fp," | Flag_needs_anti_dependence_check");
      } else {
        fprintf(fp,"init_flags(Flag_needs_anti_dependence_check");
        node_flags_set = true;
      }
    }

    if ( node_flags_set ) {
      fprintf(fp,"); ");
    }

    if (instr->is_ideal_unlock() || instr->is_ideal_call_leaf()) {
      fprintf(fp,"clear_flag(Flag_is_safepoint_node); ");
    }

    fprintf(fp,"}\n");

    // size_of, used by base class's clone to obtain the correct size.
    fprintf(fp,"  virtual uint           size_of() const {");
    fprintf(fp,   " return sizeof(%sNode);", instr->_ident);
    fprintf(fp, " }\n");

    // Virtual methods which are only generated to override base class
    if( instr->expands() || instr->needs_projections() ||
        instr->has_temps() ||
        instr->_matrule != NULL &&
        instr->num_opnds() != instr->num_unique_opnds() ) {
      fprintf(fp,"  virtual MachNode      *Expand(State *state, Node_List &proj_list);\n");
    }

    if (instr->is_pinned(_globalNames)) {
      fprintf(fp,"  virtual bool           pinned() const { return ");
      if (instr->is_parm(_globalNames)) {
        fprintf(fp,"_in[0]->pinned();");
      } else {
        fprintf(fp,"true;");
      }
      fprintf(fp," }\n");
    }
    if (instr->is_projection(_globalNames)) {
      fprintf(fp,"  virtual const Node *is_block_proj() const { return this; }\n");
    }
    if ( instr->num_post_match_opnds() != 0
         || instr->is_chain_of_constant(_globalNames) ) {
      fprintf(fp,"  friend MachNode *State::MachNodeGenerator(int opcode, Compile* C);\n");
    }
    if ( instr->rematerialize(_globalNames, get_registers()) ) {
      fprintf(fp,"  // Rematerialize %s\n", instr->_ident);
    }

    // Declare short branch methods, if applicable
    instr->declare_short_branch_methods(fp);

    // Instructions containing a constant that will be entered into the
    // float/double table redefine the base virtual function
#ifdef SPARC
    // Sparc doubles entries in the constant table require more space for
    // alignment. (expires 9/98)
    int table_entries = (3 * instr->num_consts( _globalNames, Form::idealD ))
      + instr->num_consts( _globalNames, Form::idealF );
#else
    int table_entries = instr->num_consts( _globalNames, Form::idealD )
      + instr->num_consts( _globalNames, Form::idealF );
#endif
    if( table_entries != 0 ) {
      fprintf(fp,"  virtual int            const_size() const {");
      fprintf(fp,   " return %d;", table_entries);
      fprintf(fp, " }\n");
    }


    // See if there is an "ins_pipe" declaration for this instruction
    if (instr->_ins_pipe) {
      fprintf(fp,"  static  const Pipeline *pipeline_class();\n");
      fprintf(fp,"  virtual const Pipeline *pipeline() const;\n");
    }

    // Generate virtual function for MachNodeX::bottom_type when necessary
    //
    // Note on accuracy:  Pointer-types of machine nodes need to be accurate,
    // or else alias analysis on the matched graph may produce bad code.
    // Moreover, the aliasing decisions made on machine-node graph must be
    // no less accurate than those made on the ideal graph, or else the graph
    // may fail to schedule.  (Reason:  Memory ops which are reordered in
    // the ideal graph might look interdependent in the machine graph,
    // thereby removing degrees of scheduling freedom that the optimizer
    // assumed would be available.)
    //
    // %%% We should handle many of these cases with an explicit ADL clause:
    // instruct foo() %{ ... bottom_type(TypeRawPtr::BOTTOM); ... %}
    if( data_type != Form::none ) {
      // A constant's bottom_type returns a Type containing its constant value

      // !!!!!
      // Convert all ints, floats, ... to machine-independent TypeXs
      // as is done for pointers
      //
      // Construct appropriate constant type containing the constant value.
      fprintf(fp,"  virtual const class Type *bottom_type() const{\n");
      switch( data_type ) {
      case Form::idealI:
        fprintf(fp,"    return  TypeInt::make(opnd_array(1)->constant());\n");
        break;
      case Form::idealP:
      case Form::idealN:
        fprintf(fp,"    return  opnd_array(1)->type();\n",result);
        break;
      case Form::idealD:
        fprintf(fp,"    return  TypeD::make(opnd_array(1)->constantD());\n");
        break;
      case Form::idealF:
        fprintf(fp,"    return  TypeF::make(opnd_array(1)->constantF());\n");
        break;
      case Form::idealL:
        fprintf(fp,"    return  TypeLong::make(opnd_array(1)->constantL());\n");
        break;
      default:
        assert( false, "Unimplemented()" );
        break;
      }
      fprintf(fp,"  };\n");
    }
/*    else if ( instr->_matrule && instr->_matrule->_rChild &&
        (  strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
        || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
      // !!!!! !!!!!
      // Provide explicit bottom type for conversions to int
      // On Intel the result operand is a stackSlot, untyped.
      fprintf(fp,"  virtual const class Type *bottom_type() const{");
      fprintf(fp,   " return  TypeInt::INT;");
      fprintf(fp, " };\n");
    }*/
    else if( instr->is_ideal_copy() &&
              !strcmp(instr->_matrule->_lChild->_opType,"stackSlotP") ) {
      // !!!!!
      // Special hack for ideal Copy of pointer.  Bottom type is oop or not depending on input.
      fprintf(fp,"  const Type            *bottom_type() const { return in(1)->bottom_type(); } // Copy?\n");
    }
    else if( instr->is_ideal_loadPC() ) {
      // LoadPCNode provides the return address of a call to native code.
      // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM
      // since it is a pointer to an internal VM location and must have a zero offset.
      // Allocation detects derived pointers, in part, by their non-zero offsets.
      fprintf(fp,"  const Type            *bottom_type() const { return TypeRawPtr::BOTTOM; } // LoadPC?\n");
    }
    else if( instr->is_ideal_box() ) {
      // BoxNode provides the address of a stack slot.
      // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM
      // This prevent s insert_anti_dependencies from complaining. It will
      // complain if it see that the pointer base is TypePtr::BOTTOM since
      // it doesn't understand what that might alias.
      fprintf(fp,"  const Type            *bottom_type() const { return TypeRawPtr::BOTTOM; } // Box?\n");
    }
    else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveP") ) {
      int offset = 1;
      // Special special hack to see if the Cmp? has been incorporated in the conditional move
      MatchNode *rl = instr->_matrule->_rChild->_lChild;
      if( rl && !strcmp(rl->_opType, "Binary") ) {
          MatchNode *rlr = rl->_rChild;
          if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)
            offset = 2;
      }
      // Special hack for ideal CMoveP; ideal type depends on inputs
      fprintf(fp,"  const Type            *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // CMoveP\n",
        offset, offset+1, offset+1);
    }
    else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveN") ) {
      int offset = 1;
      // Special special hack to see if the Cmp? has been incorporated in the conditional move
      MatchNode *rl = instr->_matrule->_rChild->_lChild;
      if( rl && !strcmp(rl->_opType, "Binary") ) {
          MatchNode *rlr = rl->_rChild;
          if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)
            offset = 2;
      }
      // Special hack for ideal CMoveN; ideal type depends on inputs
      fprintf(fp,"  const Type            *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // CMoveN\n",
        offset, offset+1, offset+1);
    }
    else if( instr->needs_base_oop_edge(_globalNames) ) {
      // Special hack for ideal AddP.  Bottom type is an oop IFF it has a
      // legal base-pointer input.  Otherwise it is NOT an oop.
      fprintf(fp,"  const Type *bottom_type() const { return AddPNode::mach_bottom_type(this); } // AddP\n");
    }
    else if (instr->is_tls_instruction()) {
      // Special hack for tlsLoadP
      fprintf(fp,"  const Type            *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n");
    }
    else if ( instr->is_ideal_if() ) {
      fprintf(fp,"  const Type            *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n");
    }
    else if ( instr->is_ideal_membar() ) {
      fprintf(fp,"  const Type            *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n");
    }

    // Check where 'ideal_type' must be customized
    /*
    if ( instr->_matrule && instr->_matrule->_rChild &&
        (  strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
        || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
      fprintf(fp,"  virtual uint           ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n");
    }*/

    // Analyze machine instructions that either USE or DEF memory.
    int memory_operand = instr->memory_operand(_globalNames);
    // Some guys kill all of memory
    if ( instr->is_wide_memory_kill(_globalNames) ) {
      memory_operand = InstructForm::MANY_MEMORY_OPERANDS;
    }
    if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {
      if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) {
        fprintf(fp,"  virtual const TypePtr *adr_type() const;\n");
      }
      fprintf(fp,"  virtual const MachOper *memory_operand() const;\n");
    }

    fprintf(fp, "#ifndef PRODUCT\n");

    // virtual function for generating the user's assembler output
    gen_inst_format(fp, _globalNames,*instr);

    // Machine independent print functionality for debugging
    fprintf(fp,"  virtual const char    *Name() const { return \"%s\";}\n",
            instr->_ident);

    fprintf(fp, "#endif\n");

    // Close definition of this XxxMachNode
    fprintf(fp,"};\n");
  };

}

void ArchDesc::defineStateClass(FILE *fp) {
  static const char *state__valid    = "_valid[((uint)index) >> 5] &  (0x1 << (((uint)index) & 0x0001F))";
  static const char *state__set_valid= "_valid[((uint)index) >> 5] |= (0x1 << (((uint)index) & 0x0001F))";

  fprintf(fp,"\n");
  fprintf(fp,"// MACROS to inline and constant fold State::valid(index)...\n");
  fprintf(fp,"// when given a constant 'index' in dfa_<arch>.cpp\n");
  fprintf(fp,"//   uint word   = index >> 5;       // Shift out bit position\n");
  fprintf(fp,"//   uint bitpos = index & 0x0001F;  // Mask off word bits\n");
  fprintf(fp,"#define STATE__VALID(index) ");
  fprintf(fp,"    (%s)\n", state__valid);
  fprintf(fp,"\n");
  fprintf(fp,"#define STATE__NOT_YET_VALID(index) ");
  fprintf(fp,"  ( (%s) == 0 )\n", state__valid);
  fprintf(fp,"\n");
  fprintf(fp,"#define STATE__VALID_CHILD(state,index) ");
  fprintf(fp,"  ( state && (state->%s) )\n", state__valid);
  fprintf(fp,"\n");
  fprintf(fp,"#define STATE__SET_VALID(index) ");
  fprintf(fp,"  (%s)\n", state__set_valid);
  fprintf(fp,"\n");
  fprintf(fp,
          "//---------------------------State-------------------------------------------\n");
  fprintf(fp,"// State contains an integral cost vector, indexed by machine operand opcodes,\n");
  fprintf(fp,"// a rule vector consisting of machine operand/instruction opcodes, and also\n");
  fprintf(fp,"// indexed by machine operand opcodes, pointers to the children in the label\n");
  fprintf(fp,"// tree generated by the Label routines in ideal nodes (currently limited to\n");
  fprintf(fp,"// two for convenience, but this could change).\n");
  fprintf(fp,"class State : public ResourceObj {\n");
  fprintf(fp,"public:\n");
  fprintf(fp,"  int    _id;         // State identifier\n");
  fprintf(fp,"  Node  *_leaf;       // Ideal (non-machine-node) leaf of match tree\n");
  fprintf(fp,"  State *_kids[2];       // Children of state node in label tree\n");
  fprintf(fp,"  unsigned int _cost[_LAST_MACH_OPER];  // Cost vector, indexed by operand opcodes\n");
  fprintf(fp,"  unsigned int _rule[_LAST_MACH_OPER];  // Rule vector, indexed by operand opcodes\n");
  fprintf(fp,"  unsigned int _valid[(_LAST_MACH_OPER/32)+1]; // Bit Map of valid Cost/Rule entries\n");
  fprintf(fp,"\n");
  fprintf(fp,"  State(void);                      // Constructor\n");
  fprintf(fp,"  DEBUG_ONLY( ~State(void); )       // Destructor\n");
  fprintf(fp,"\n");
  fprintf(fp,"  // Methods created by ADLC and invoked by Reduce\n");
  fprintf(fp,"  MachOper *MachOperGenerator( int opcode, Compile* C );\n");
  fprintf(fp,"  MachNode *MachNodeGenerator( int opcode, Compile* C );\n");
  fprintf(fp,"\n");
  fprintf(fp,"  // Assign a state to a node, definition of method produced by ADLC\n");
  fprintf(fp,"  bool DFA( int opcode, const Node *ideal );\n");
  fprintf(fp,"\n");
  fprintf(fp,"  // Access function for _valid bit vector\n");
  fprintf(fp,"  bool valid(uint index) {\n");
  fprintf(fp,"    return( STATE__VALID(index) != 0 );\n");
  fprintf(fp,"  }\n");
  fprintf(fp,"\n");
  fprintf(fp,"  // Set function for _valid bit vector\n");
  fprintf(fp,"  void set_valid(uint index) {\n");
  fprintf(fp,"    STATE__SET_VALID(index);\n");
  fprintf(fp,"  }\n");
  fprintf(fp,"\n");
  fprintf(fp,"#ifndef PRODUCT\n");
  fprintf(fp,"  void dump();                // Debugging prints\n");
  fprintf(fp,"  void dump(int depth);\n");
  fprintf(fp,"#endif\n");
  if (_dfa_small) {
    // Generate the routine name we'll need
    for (int i = 1; i < _last_opcode; i++) {
      if (_mlistab[i] == NULL) continue;
      fprintf(fp, "  void  _sub_Op_%s(const Node *n);\n", NodeClassNames[i]);
    }
  }
  fprintf(fp,"};\n");
  fprintf(fp,"\n");
  fprintf(fp,"\n");

}


//---------------------------buildMachOperEnum---------------------------------
// Build enumeration for densely packed operands.
// This enumeration is used to index into the arrays in the State objects
// that indicate cost and a successfull rule match.

// Information needed to generate the ReduceOp mapping for the DFA
class OutputMachOperands : public OutputMap {
public:
  OutputMachOperands(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
    : OutputMap(hpp, cpp, globals, AD) {};

  void declaration() { }
  void definition()  { fprintf(_cpp, "enum MachOperands {\n"); }
  void closing()     { fprintf(_cpp, "  _LAST_MACH_OPER\n");
                       OutputMap::closing();
  }
  void map(OpClassForm &opc)  { fprintf(_cpp, "  %s", _AD.machOperEnum(opc._ident) ); }
  void map(OperandForm &oper) { fprintf(_cpp, "  %s", _AD.machOperEnum(oper._ident) ); }
  void map(char        *name) { fprintf(_cpp, "  %s", _AD.machOperEnum(name)); }

  bool do_instructions()      { return false; }
  void map(InstructForm &inst){ assert( false, "ShouldNotCallThis()"); }
};


void ArchDesc::buildMachOperEnum(FILE *fp_hpp) {
  // Construct the table for MachOpcodes
  OutputMachOperands output_mach_operands(fp_hpp, fp_hpp, _globalNames, *this);
  build_map(output_mach_operands);
}


//---------------------------buildMachEnum----------------------------------
// Build enumeration for all MachOpers and all MachNodes

// Information needed to generate the ReduceOp mapping for the DFA
class OutputMachOpcodes : public OutputMap {
  int begin_inst_chain_rule;
  int end_inst_chain_rule;
  int begin_rematerialize;
  int end_rematerialize;
  int end_instructions;
public:
  OutputMachOpcodes(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
    : OutputMap(hpp, cpp, globals, AD),
      begin_inst_chain_rule(-1), end_inst_chain_rule(-1), end_instructions(-1)
  {};

  void declaration() { }
  void definition()  { fprintf(_cpp, "enum MachOpcodes {\n"); }
  void closing()     {
    if( begin_inst_chain_rule != -1 )
      fprintf(_cpp, "  _BEGIN_INST_CHAIN_RULE = %d,\n", begin_inst_chain_rule);
    if( end_inst_chain_rule   != -1 )
      fprintf(_cpp, "  _END_INST_CHAIN_RULE  = %d,\n", end_inst_chain_rule);
    if( begin_rematerialize   != -1 )
      fprintf(_cpp, "  _BEGIN_REMATERIALIZE   = %d,\n", begin_rematerialize);
    if( end_rematerialize     != -1 )
      fprintf(_cpp, "  _END_REMATERIALIZE    = %d,\n", end_rematerialize);
    // always execute since do_instructions() is true, and avoids trailing comma
    fprintf(_cpp, "  _last_Mach_Node  = %d \n",  end_instructions);
    OutputMap::closing();
  }
  void map(OpClassForm &opc)  { fprintf(_cpp, "  %s_rule", opc._ident ); }
  void map(OperandForm &oper) { fprintf(_cpp, "  %s_rule", oper._ident ); }
  void map(char        *name) { if (name) fprintf(_cpp, "  %s_rule", name);
                                else      fprintf(_cpp, "  0"); }
  void map(InstructForm &inst) {fprintf(_cpp, "  %s_rule", inst._ident ); }

  void record_position(OutputMap::position place, int idx ) {
    switch(place) {
    case OutputMap::BEGIN_INST_CHAIN_RULES :
      begin_inst_chain_rule = idx;
      break;
    case OutputMap::END_INST_CHAIN_RULES :
      end_inst_chain_rule   = idx;
      break;
    case OutputMap::BEGIN_REMATERIALIZE :
      begin_rematerialize   = idx;
      break;
    case OutputMap::END_REMATERIALIZE :
      end_rematerialize     = idx;
      break;
    case OutputMap::END_INSTRUCTIONS :
      end_instructions      = idx;
      break;
    default:
      break;
    }
  }
};


void ArchDesc::buildMachOpcodesEnum(FILE *fp_hpp) {
  // Construct the table for MachOpcodes
  OutputMachOpcodes output_mach_opcodes(fp_hpp, fp_hpp, _globalNames, *this);
  build_map(output_mach_opcodes);
}


// Generate an enumeration of the pipeline states, and both
// the functional units (resources) and the masks for
// specifying resources
void ArchDesc::build_pipeline_enums(FILE *fp_hpp) {
  int stagelen = (int)strlen("undefined");
  int stagenum = 0;

  if (_pipeline) {              // Find max enum string length
    const char *stage;
    for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; ) {
      int len = (int)strlen(stage);
      if (stagelen < len) stagelen = len;
    }
  }

  // Generate a list of stages
  fprintf(fp_hpp, "\n");
  fprintf(fp_hpp, "// Pipeline Stages\n");
  fprintf(fp_hpp, "enum machPipelineStages {\n");
  fprintf(fp_hpp, "   stage_%-*s = 0,\n", stagelen, "undefined");

  if( _pipeline ) {
    const char *stage;
    for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; )
      fprintf(fp_hpp, "   stage_%-*s = %d,\n", stagelen, stage, ++stagenum);
  }

  fprintf(fp_hpp, "   stage_%-*s = %d\n", stagelen, "count", stagenum);
  fprintf(fp_hpp, "};\n");

  fprintf(fp_hpp, "\n");
  fprintf(fp_hpp, "// Pipeline Resources\n");
  fprintf(fp_hpp, "enum machPipelineResources {\n");
  int rescount = 0;

  if( _pipeline ) {
    const char *resource;
    int reslen = 0;

    // Generate a list of resources, and masks
    for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {
      int len = (int)strlen(resource);
      if (reslen < len)
        reslen = len;
    }

    for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {
      const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();
      int mask = resform->mask();
      if ((mask & (mask-1)) == 0)
        fprintf(fp_hpp, "   resource_%-*s = %d,\n", reslen, resource, rescount++);
    }
    fprintf(fp_hpp, "\n");
    for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {
      const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();
      fprintf(fp_hpp, "   res_mask_%-*s = 0x%08x,\n", reslen, resource, resform->mask());
    }
    fprintf(fp_hpp, "\n");
  }
  fprintf(fp_hpp, "   resource_count = %d\n", rescount);
  fprintf(fp_hpp, "};\n");
}