aboutsummaryrefslogtreecommitdiff
path: root/gcc/melt/libmelt-ana-base.melt
blob: 7337318e3d5356eb7ad97bdbf7b8067ddfc54a3d (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
;; -*- Lisp -*-
;; file libmelt-ana-base.melt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(comment "***
    Copyright 2008 - 2016 Free Software Foundation, Inc.
    Contributed by Basile Starynkevitch <basile@starynkevitch.net>
                and Jeremie Salvucci  <jeremie.salvucci@free.fr>
                and Pierre Vittet  <piervit@pvittet.com>
                and Romain Geissler  <romain.geissler@gmail.com>

    This file libmelt-ana-base.{melt,c} is part of GCC.

    GCC is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3, or (at your option)
    any later version.

    GCC is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with GCC; see the file COPYING3.  If not see
    <http://www.gnu.org/licenses/>.
***")

;; the copyright notice above apply both to libmelt-ana-base.melt and 
;; to the generated file  libmelt-ana-base*.c


;; This MELT module is GPL compatible since it is GPLv3+ licensed.
(module_is_gpl_compatible "GPLv3+")


;; a class containing the analysis state
(defclass class_analysis_state
  :doc #{A class containing some analysis state, to be subclassed.}#
  :super class_proped
  :fields (
))

(defprimitive main_input_filename () :cstring
  :doc #{The main input file name given to GCC thru $MAIN_INPUT_FILENAME}#
  #{ main_input_filename }#)
  



;;;;;;;;;;;;;;;;
(cheader 
 #{
MELT_EXTERN bool melthk_gimple_gate(void) MELT_MODULE_VISIBILITY;
MELT_EXTERN unsigned int melthk_gimple_execute(void) MELT_MODULE_VISIBILITY;
MELT_EXTERN unsigned int melthk_simple_ipa_execute(void) MELT_MODULE_VISIBILITY;
MELT_EXTERN bool melthk_rtl_gate(void) MELT_MODULE_VISIBILITY;
MELT_EXTERN unsigned int melthk_rtl_execute(void) MELT_MODULE_VISIBILITY;

class melt_gimple_pass : public gimple_opt_pass {
  long _instance_index;
public:
  long index () const { return _instance_index; };
  melt_gimple_pass (const pass_data& passdata, gcc::context*ctxt) 
    : gimple_opt_pass (passdata, ctxt), _instance_index(++melt_pass_instance_counter) {};
  virtual ~melt_gimple_pass() { _instance_index=0; };
  bool gate () { 
    bool fla;
    long oldindex = melt_current_pass_index_var;
    opt_pass* oldpassptr = melt_current_pass_ptr;
    melt_current_pass_index_var = index ();
    melt_current_pass_ptr = this;
    fla = melthk_gimple_gate(); 
    melt_current_pass_index_var = oldindex;
    melt_current_pass_ptr = oldpassptr;
    return fla;
 };
  unsigned execute () { 
    unsigned r = 0;
    long oldindex = melt_current_pass_index_var;
    opt_pass* oldpassptr = melt_current_pass_ptr;
    melt_current_pass_index_var = index ();
    melt_current_pass_ptr = this;
    r = melthk_gimple_execute(); 
    melt_current_pass_index_var = oldindex;
    melt_current_pass_ptr = oldpassptr;
    return r;
  };
  opt_pass* clone () { 
    melt_gimple_pass *p = new melt_gimple_pass(*this); 
    p->_instance_index = ++melt_pass_instance_counter;
    return p;
  };
}; // end of melt_gimple_pass class

class melt_simple_ipa_pass : public simple_ipa_opt_pass {
  long _simpleipa_instance_index;
public:
  long index () const { return _simpleipa_instance_index; };
   melt_simple_ipa_pass (const pass_data& passdata, gcc::context*ctxt) 
    : simple_ipa_opt_pass(passdata, ctxt),  _simpleipa_instance_index(++melt_pass_instance_counter) {};
  virtual ~melt_simple_ipa_pass() { _simpleipa_instance_index=0; };
   unsigned int execute () 
    {
      unsigned r = 0;
      long oldindex = melt_current_pass_index_var;
      opt_pass* oldpassptr = melt_current_pass_ptr;
      melt_current_pass_index_var = index ();
      melt_current_pass_ptr = this;
      r = melthk_simple_ipa_execute(); 
      melt_current_pass_index_var = oldindex;
      melt_current_pass_ptr = oldpassptr;
      return r;
    };
  opt_pass* clone () { 
    melt_simple_ipa_pass *p = new melt_simple_ipa_pass(*this); 
    p->_simpleipa_instance_index = ++melt_pass_instance_counter;
    return p;
  };
}; // end of melt_simple_ipa_pass class

static inline long melt_get_current_pass_index (void) {
   return current_pass?melt_current_pass_index_var:0L;
}


}#)

(cimplement 
 #{
 
/* implementation of wrapping gate and exec functions from libmelt-ana-base.melt */
bool melthk_gimple_gate(void)
{ 
  return melthookproc_HOOK_GIMPLE_GATE () != 0L; 
}

unsigned int melthk_gimple_execute(void) 
{
  return (unsigned) melthookproc_HOOK_GIMPLE_EXECUTE (); 
}


unsigned int melthk_simple_ipa_execute(void) 
{return (unsigned) melthookproc_HOOK_SIMPLE_IPA_EXECUTE (); }

bool melthk_rtl_gate(void)
{ return melthookproc_HOOK_RTL_GATE () != 0L; }

unsigned int melthk_rtl_execute(void) 
{return (unsigned) melthookproc_HOOK_RTL_EXECUTE (); }

}#)



;; new function to install a melt pass in gcc
(defun install_melt_pass_in_gcc 
  (:value pass positioning refpassname :long refpassnum) 
  :doc #{$INSTALL_MELT_PASS_IN_GCC is installing your GCC pass coded
  in MELT. The $PASS should be an object, instance of a sub-class of
  $CLASS_GCC_PASS, e.g. of $CLASS_GCC_GIMPLE_PASS. The $POSITIONNING
  is :before or :after or :replace. The reference pass is given thru
  $REFPASSNAME -a boxed string- and $REFPASSNUM. Usually
  $INSTALL_MELT_PASS_IN_GCC is called from a mode initializer, see
  also $INSTALL_MELT_MODE.}#
  (debug "install_melt_gcc_pass pass=" pass 
	 " positioning=" positioning " refpassname=" refpassname " refpassnum=" refpassnum)
  ;; check that we have a mode
  (let ( (:long badmodeflag 0)
	 (passname (get_field :named_name pass))
	 )
    (code_chunk badmode_chk
       #{/*install_melt_gcc_pass $BADMODE_CHK */
         const char* modstr = melt_argument("mode");
	 if (!modstr || !modstr[0])
           $BADMODEFLAG = 1;
	   }#)
    (when (not (is_string passname))
      (error_at () "MELT corrupted nameless pass to install")
      (return))
    (when badmodeflag 
      (warning_at () "MELT does not install pass $1 without a mode" passname)
      (return)) 
  ;;; check the pass
  (when (is_not_a pass class_gcc_pass)
    (error_at () "MELT bad pass $1 to install" passname)
    (return))
  (let ( (passdict (get_field :sysdata_pass_dict initial_system_data))
	 )
  ;; check the refpassname
    (when (not (is_string refpassname))
      (error_at () "cannot install MELT pass $1 without reference pass name" passname)
      (return))
  ;; check that the pass is not already installed
    (when (mapstring_getstr passdict passname)
      (error_at () "MELT pass of same name $1 already installed" passname)
      (return)
      )
    (let (
	  (propreqv (get_field :gccpass_properties_required pass))
	  (propprov (get_field :gccpass_properties_provided pass))
	  (propdestrv (get_field :gccpass_properties_destroyed pass))
	  (todostartv (get_field :gccpass_todo_flags_start pass))
	  (todofinishv (get_field :gccpass_todo_flags_finish pass))
	  (gatefun (get_field :gccpass_gate pass))
	  (execfun (get_field :gccpass_exec pass))
	  (:long posopl 
		 (match positioning
			(:before 
			 (expr_chunk before_chk :long #{(long)PASS_POS_INSERT_BEFORE}#))
			(:after
			 (expr_chunk after_chk :long #{(long)PASS_POS_INSERT_AFTER}#))
			(:replace
			 (expr_chunk replace_chk :long #{(long)PASS_POS_REPLACE}#))
			(?_
			 (errormsg_strv "bad pass positioning; should be :BEFORE or :AFTER or :REPLACE"
					passname)
			 (return)
			 -1
			 )))
	  )
      (cond 
       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       ;; installing gimple passes
       ((is_a pass class_gcc_gimple_pass)
	(code_chunk 
	 gimplepass_chk
	 #{ /* start install_melt_gcc_pass $GIMPLEPASS_CHK */
	 struct register_pass_info rpassinfo;
	 memset (&rpassinfo, 0, sizeof(rpassinfo));
	 struct pass_data rpassdata;
	 memset (&rpassdata, 0, sizeof(rpassdata));
	 rpassdata.type = GIMPLE_PASS;
	 rpassdata.name = melt_intern_cstring (melt_string_str((melt_ptr_t) $PASSNAME));
	 rpassdata.optinfo_flags = OPTGROUP_NONE;
	 rpassdata.tv_id = TV_PLUGIN_RUN;
	 rpassdata.properties_required = melt_val2passflag ((melt_ptr_t) $PROPREQV);
	 rpassdata.properties_provided = melt_val2passflag ((melt_ptr_t) $PROPPROV);
	 rpassdata.properties_destroyed = melt_val2passflag ((melt_ptr_t) $PROPDESTRV);
	 rpassdata.todo_flags_start = melt_val2passflag ((melt_ptr_t) $TODOSTARTV);
	 rpassdata.todo_flags_finish = melt_val2passflag ((melt_ptr_t) $TODOFINISHV);
	 rpassinfo.pass = new melt_gimple_pass (rpassdata, g); // the g is from context.h
	 rpassinfo.reference_pass_name = 
	   melt_intern_cstring (melt_string_str((melt_ptr_t) $REFPASSNAME));
	 melt_intern_cstring (melt_string_str((melt_ptr_t) $REFPASSNAME));
	 rpassinfo.ref_pass_instance_number = $REFPASSNUM;
	 rpassinfo.pos_op = (enum pass_positioning_ops)$POSOPL;
	 melt_debugeprintf("installing MELT gimple classy pass named %s w.r.t. %s", 
		      rpassdata.name,  rpassinfo.reference_pass_name);
	 register_callback (melt_plugin_name, PLUGIN_PASS_MANAGER_SETUP,
			    NULL, &rpassinfo);
	 melt_debugeprintf("installed MELT gimple classy pass named %s", 
		      rpassdata.name);
	 /* end install_melt_gcc_pass $GIMPLEPASS_CHK */
	 }#)
	(mapstring_putstr passdict passname pass)
	(debug "install_melt_pass_in_gcc installed gimple pass=" pass)
	)
       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       ;; installing simple_ipa passes
       ((is_a pass class_gcc_simple_ipa_pass)
	(if gatefun 
	    (error_at () "MELT simple ipa pass $1 should not have any gate function" passname))
	(code_chunk 
	 simipapass_chk
	 #{ /* start install_melt_gcc_pass $SIMIPAPASS_CHK */
	 struct register_pass_info rpassinfo;
	 memset (&rpassinfo, 0, sizeof(rpassinfo));
	 struct pass_data rpassdata;
	 memset (&rpassdata, 0, sizeof(rpassdata));
	 rpassdata.type = SIMPLE_IPA_PASS;
	 rpassdata.name = melt_intern_cstring (melt_string_str((melt_ptr_t) $PASSNAME));
	 rpassdata.optinfo_flags = OPTGROUP_NONE;
	 rpassdata.tv_id = TV_PLUGIN_RUN;
	 rpassdata.properties_required = melt_val2passflag ((melt_ptr_t) $PROPREQV);
	 rpassdata.properties_provided = melt_val2passflag ((melt_ptr_t) $PROPPROV);
	 rpassdata.properties_destroyed = melt_val2passflag ((melt_ptr_t) $PROPDESTRV);
	 rpassdata.todo_flags_start = melt_val2passflag ((melt_ptr_t) $TODOSTARTV);
	 rpassdata.todo_flags_finish = melt_val2passflag ((melt_ptr_t) $TODOFINISHV);
	 rpassinfo.pass = new melt_simple_ipa_pass (rpassdata, g); // the g is from context.h
	 rpassinfo.reference_pass_name = 
	   melt_intern_cstring (melt_string_str((melt_ptr_t) $REFPASSNAME));
	 melt_intern_cstring (melt_string_str((melt_ptr_t) $REFPASSNAME));
	 rpassinfo.ref_pass_instance_number = $REFPASSNUM;
	 rpassinfo.pos_op = (enum pass_positioning_ops)$POSOPL;
	 melt_debugeprintf("installing MELT simple_ipa classy pass named %s w.r.t %s", 
		      rpassdata.name, rpassinfo.reference_pass_name);
	 register_callback (melt_plugin_name, PLUGIN_PASS_MANAGER_SETUP,
			    NULL, &rpassinfo);
	 melt_debugeprintf("installed MELT simple_ipa classy pass named %s", 
		      rpassdata.name);
	 /* end install_melt_gcc_pass $SIMIPAPASS_CHK */
	 }#)
	(debug "install_melt_pass_in_gcc installed simple ipa pass=" pass)
	(mapstring_putstr passdict passname pass)
	)
       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       ;; installing rtl passes
       ((is_a pass class_gcc_rtl_pass)
	(code_chunk 
	 rtlpass_chk
	 #{ /* start install_melt_gcc_pass $RTLPASS_CHK */
#warning install_melt_gcc_pass $RTLPASS_CHK not implemented for class_gcc_rtl_pass
         melt_fatal_error ("install_melt_gcc_pass unimplemented for MELT pass %s (RTL)",
			   melt_string_str((melt_ptr_t) $PASSNAME));
	 /* end install_melt_gcc_pass $RTLPASS_CHK */
	 }#)
	(debug "install_melt_pass_in_gcc installed simple ipa pass=" pass)
	(mapstring_putstr passdict passname pass)
	)
       ;;
       (:else
	(error_at () 
		  "MELT failed to install pass $1 of unexpected class" passname
		  (get_field :named_name (discrim pass)))
	(return)
	)
       )	     
    )
    (debug "install_melt_pass_in_gcc end pass=" pass "\n ... updated passdict=" passdict)
    )))					;end install_melt_pass_in_gcc


;;;;;;;;;;;;;;;;;;;;;; obsolete install a MELT GCC PASS; for compatibility
(defun install_melt_gcc_pass  
   (:value pass :cstring positioning refpassname :long refpassnum) 
   :doc #{@b{Obsolete function} to install a GCC pass coded in MELT,
  replaced with $INSTALL_MELT_PASS_IN_GCC. The $PASS should be an
  object, instance of a sub-class of $CLASS_GCC_PASS, e.g. of
  $CLASS_GCC_GIMPLE_PASS. The $POSITIONNING is "before" or "after"
  or "replace". The reference pass is given thru $REFPASSNAME and
  $REFPASSNUM. Usually $INSTALL_MELT_GCC_PASS is called from a mode
  initializer.}# 
  (debug "install_melt_gcc_pass pass=" pass " positioning=" positioning 
	 "refpassname=" refpassname " refpassnum=" refpassnum)
  (shortbacktrace_dbg "install_melt_gcc_pass" 19)
  (let ( (positv ())
	 (refpanamv ())
	 (passname (get_field :named_name pass))
	 )
    (code_chunk makeval_chk 
		#{ /* install_melt_gcc_pass $MAKEVAL_CHK start */
		warning (0, "MELT obsolete usage of INSTALL_MELT_GCC_PASS for %s."
			    " Use INSTALL_MELT_PASS_IN_GCC instead.",
			    melt_string_str ($PASSNAME));
		$POSITV = melthookproc_HOOK_NAMED_KEYWORD ($POSITIONING, (long) MELT_CREATE);
		$REFPANAMV = meltgc_new_stringdup ((meltobject_ptr_t) MELT_PREDEF(DISCR_STRING),
						   $POSITIONING);
		 /* install_melt_gcc_pass $MAKEVAL_CHK end */ }#)
    (debug "install_melt_gcc_pass pass=" pass " positv=" positv " refpanamv=" refpanamv 
	   " refpassnum=" refpassnum)
    (install_melt_pass_in_gcc pass positv refpanamv refpassnum)
    (return ())
    )
)


;;; edge related primitives
(defprimitive make_edge (discr :edge edg) :value
  :doc #{Box the edge stuff $EDG with discriminant $DISCR as a boxed edge value.}#
  #{(meltgc_new_edge((meltobject_ptr_t)($DISCR),($EDG)))}# )

(defprimitive edge_content (val) :edge
  :doc #{Retrieve the edge stuff from boxed edge value $VAL.}#
  #{(melt_edge_content((melt_ptr_t)($VAL)))}# )

(defprimitive is_edge (val) :long
  :doc #{Test that $VAL is indeed a boxed edge value.}#
  #{(($VAL) && melt_magic_discr ((melt_ptr_t)$VAL) == MELTOBMAG_EDGE)}#)

(defprimitive ==e (:edge e1 e2) :long
  :doc #{Test physical equality, that is identity, of edge stuff $E1 and $E2.}#
  #{(($E1) == ($E2))}#)

(defprimitive null_edge () :edge
  :doc #{The null edge stuff.}#
   #{((edge)0)}#)


;;;;;;;;;;;;;;;; map associating GCC edge-s to non-null MELT values
(defprimitive is_mapedge (map) :long
  :doc #{Test if $MAP is a map keyed by edges.}#
  #{ (melt_magic_discr((melt_ptr_t)($map)) == MELTOBMAG_MAPEDGES) }#)
(defprimitive mapedge_size (map) :long
  :doc #{Get the allocated size of an edge map $MAP.}#
 #{ (melt_size_mapedges((struct meltmapedges_st*)($map))) }#)
;; primitive to get the attribute count of a mapedge
(defprimitive mapedge_count (map) :long
  :doc #{Get the counted length of an edge map $MAP.}#
  #{ (melt_count_mapedges((struct meltmapedges_st*)($map))) }# )
;; get an entry in a mapedge from a C edge
(defprimitive mapedge_get (map :edge ed) :value
  :doc #{Get the value in edge map $MAP associted to edge $ED.}#
  #{(melt_get_mapedges((melt_ptr_t) ($MAP), ($ED)))}#)
;; primitive for making a new map of edges
(defprimitive make_mapedge (discr :long len) :value
  :doc #{Make a new map of edges with $DISCR and initial $LEN.}#
 #{(meltgc_new_mapedges((meltobject_ptr_t) ($discr), ($len)))}#)
;; primitive for putting into a map of edges
(defprimitive mapedge_put (map :edge ekey :value val) :void
  :doc #{Safely put into map $MAP the edge $EKEY associated to value $VAL.}#
  #{melt_put_mapedges((melt_ptr_t) ($MAP), 
		      ($EKEY), (melt_ptr_t) ($VAL))}#)
;; primitive for removing from a map of edges
(defprimitive mapedge_remove (map :edge key) :void
  :doc #{Safely remove in map $MAP the entry for edge $EKEY.}#
  #{melt_remove_mapedges((melt_ptr_t)($MAP), ($KEY))}#)
;; retrieve the auxiliary data in a map of edges
(defprimitive mapedge_aux (map) :value
  :doc #{Retrieve the auxiliary data of edge map $MAP.}#
  #{melt_auxdata_mapedges ((melt_ptr_t)$MAP)}#)
;; put the auxiliary data in a map of edges
(defprimitive mapedge_auxput (map aux) :void
  :doc #{Put the auxiliary data of edge map $MAP as $AUX.}#
  #{melt_auxput_mapedges((melt_ptr_t)$MAP, (melt_ptr_t)$AUX)}#)

;; primitive to get the nth edge of a mapedge
(defprimitive mapedge_nth_attr (map :long n) :edge
  #{(melt_nthattr_mapedges((struct meltmapedges_st*)($map), (int)($n)))}#)
;; primitive to get the nth value of a mapedge
(defprimitive mapedge_nth_val (map :long n) :value
  #{(melt_nthval_mapedges((struct meltmapedges_st*)($map), (int)($n)))}# )
;; iterator inside mapedge
(defciterator foreach_mapedge 
  (edgmap)				; startformals
  eachedgemap 				;state symbol
  (:edge att :value val)	;local formals
  ;; before expansion
  #{
   /* foreach_mapedge $EACHEDGEMAP*/ { int $EACHEDGEMAP#_rk=0;
   for ($EACHEDGEMAP#_rk=0;
        $EACHEDGEMAP#_rk< (int) melt_size_mapedges((struct meltmapedges_st*)($EDGMAP));
	$EACHEDGEMAP#_rk++) {
   edge $EACHEDGEMAP#_ed = ((struct meltmapedges_st*)($EDGMAP))->entab[$EACHEDGEMAP#_rk].e_at;
   $ATT = NULL;
   $VAL = NULL;
   if (!$EACHEDGEMAP#_ed 
       || (void*) $EACHEDGEMAP#_ed == (void*) HTAB_DELETED_ENTRY) 
     continue;
   $ATT = $EACHEDGEMAP#_ed;
   $VAL = ((struct meltmapedges_st*)($EDGMAP))->entab[$EACHEDGEMAP#_rk].e_va;
   }#
  ;;after expansion
   #{
   } } /*end foreach_mapedge $EACHEDGEMAP*/
   $ATT = NULL;
   $VAL = NULL;
   }#
  )

;;;;;;;;;;;;;;;; map associating GCC loop-s to non-null MELT values
(defprimitive is_maploop (map) :long
  :doc #{Test if $MAP is a map of loops.}#
  #{ (melt_magic_discr((melt_ptr_t)($map)) == MELTOBMAG_MAPLOOPS) }#)

(defprimitive maploop_size (map) :long
  :doc #{Return allocated size of loop map $MAP.}#
 #{ (melt_size_maploops((struct meltmaploops_st*)($map))) }#)

;; primitive to get the attribute count of a maploop
(defprimitive maploop_count (map) :long
  :doc #{Return used count of loop map $MAP.}#
  #{ (melt_count_maploops((struct meltmaploops_st*)($map))) }# )

;; get an entry in a maploop from a C loop
(defprimitive maploop_get (map :loop lo) :value
  :doc #{Safely get in $MAP value associated to loop $LO.}#
  #{(melt_get_maploops((melt_ptr_t) ($map), ($lo)))}#)

;; primitive for making a new map of loops
(defprimitive make_maploop (discr :long len) :value
  :doc #{Make a map of loops with given $DISCR and estimated $LEN.}#
 #{(meltgc_new_maploops((meltobject_ptr_t) ($discr), ($len)))}#)

;; primitive for putting into a map of loops
(defprimitive maploop_put (map :loop keylo :value val) :void
  :doc #{Safely put in $MAP loop $KEYLO associated to $VAL.}#
  #{melt_put_maploops((melt_ptr_t) ($MAP), 
		      ($KEYLO), (melt_ptr_t) ($VAL))}#)

;; primitive for removing from a map of loops
(defprimitive maploop_remove (map :loop keylo) :void
  :doc #{Safely remove in $MAP entry for loop $KEYLO}#
  #{melt_remove_maploops((melt_ptr_t) ($MAP), ($KEYLO))}#)

;; primitive to get the nth loop of a maploop
(defprimitive maploop_nth_attr (map :long n) :loop
  :doc #{Safely retrieve the in map of loops $MAP the $N loop key}#
  #{(melt_nthattr_maploops((struct meltmaploops_st*)($MAP), (int)($N)))}#)

;; primitive to get the nth value of a maploop
(defprimitive maploop_nth_val (map :long n) :value
  :doc #{Safely retrieve the in map of loops $MAP the $N value}#
  #{(melt_nthval_maploops((struct meltmaploops_st*)($MAP), (int)($N)))}# )

;; iterator inside maploop
(defciterator foreach_maploop 
  (loomap)				; startformals
  eachloomap 				;state symbol
  (:loop loatt :value val)	;local formals
  :doc #{Iterate inside map of loops $LOOMAP for each loop key $LOATT and value $VAL.}#
  ;; before expansion
  #{ /* foreach_maploop $EACHLOOMAP*/ { int $EACHLOOMAP#_rk=0;
   for ($EACHLOOMAP#_rk=0;
        $EACHLOOMAP#_rk < (int) melt_size_maploops((struct meltmaploops_st*)($LOOMAP));
	$EACHLOOMAP#_rk++) {
   $LOATT = NULL;
   $VAL = NULL;
   loop_p $EACHLOOMAP#_lo = 
     ((struct meltmaploops_st*)($LOOMAP))->entab[$EACHLOOMAP#_rk].e_at;
   if (!$EACHLOOMAP#_lo
       || (void*) $EACHLOOMAP#_lo == (void*) HTAB_DELETED_ENTRY) 
     continue;
   $LOATT = $EACHLOOMAP#_lo;
   $VAL = 
     ((struct meltmaploops_st*)($LOOMAP))->entab[$EACHLOOMAP#_rk].e_va;
   }#
  ;;after expansion
   #{ 
   } /*end  foreach_maploop $EACHLOOMAP*/
   $LOATT = NULL;
   $VAL = NULL; }
   }#
  )


;; iterator on all the loops

 (defciterator each_loop
   ()
   eachloop
   (:loop curloop :long loopix)
   :doc #{Iterate on all loops $CURLOOP of index $LOOPIX.}#
   ;; before expansion
   #{ /* each_loop $EACHLOOP +*/ {
   FOR_EACH_LOOP($CURLOOP, 0) {
   $LOOPIX = $CURLOOP->num		;
   }#
   ;;after expansion
   #{ } /*each_loop $EACHLOOP -*/ }
   }#
   )
 (export_values each_loop)
 



(defprimitive loop_can_be_parallel (:loop lo) :long
  :doc #{Test if loop $LO can be parallel, as detected by Graphite analysis.}#
  #{ (($LO) && ($LO)->can_be_parallel) }#)

(defprimitive loop_header (:loop lo) :basic_block
  :doc #{The header if any of loop $LO}#
  #{($LO)?(($LO)->header):(basic_block)0}#)

(defprimitive loop_latch (:loop lo) :basic_block
  :doc #{The latch if any of loop $LO}#
  #{($LO)?(($LO)->latch):(basic_block)0}#)

(defprimitive loop_inner (:loop lo) :loop
  :doc #{The inner if any of loop $LO}#
  #{($LO)?(($LO)->inner):(loop_p)NULL}#)

(defprimitive loop_index_number (:loop lo) :long
  :doc #{The index number if any of loop $LO}#
  #{($LO)?(($LO)->num):0L}#)

(defprimitive loop_depth (:loop lo) :long
  :doc #{The depth of loop $LO}#
  #{($LO)?loop_depth($LO):0L}#)

(defprimitive number_of_loops () :long 
  :doc #{Return the number of loops in current_loops.}#
  #{ /* number_of_loops primitive */
  number_of_loops (cfun)
  }#)

(defprimitive superloop_at_depth (:loop lo :long depth) :loop
  :doc #{Return the containing superloop of loop $LO at given $DEPTH or else null.}#
  #{(($LO && $DEPTH>=0 && $DEPTH<=loop_depth ($LO))?superloop_at_depth($LO, $DEPTH):NULL)}#)

(defciterator foreach_superloop
  (:loop lo)
  eachsuperloop
  (:loop curloop :long loopix)
  :doc #{Iterate of each superloop of given loop $LO, for each $CURLOOP of indec $LOOPIX.}#
  ;; before expansion
  #{ /* foreach_superloop $EACHSUPERLOOP */ 
   unsigned $EACHSUPERLOOP#_ix = 0;
   loop_p $EACHSUPERLOOP#_loop = NULL;
   if ($LO) { 
     FOR_EACH_VEC_SAFE_ELT ($LO->superloops, $EACHSUPERLOOP#_ix, 
		       $EACHSUPERLOOP#_loop) 
       {
       $LOOPIX = $EACHSUPERLOOP#_ix;
       $CURLOOP = $EACHSUPERLOOP#_loop;
  }#
  ;; after expansion
  #{ }} /* end $EACHSUPERLOOP */ }#
)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
(defprimitive is_basicblock (v) :long
  :doc #{Test if $V is a boxed basic block value.}#
 #{ (melt_magic_discr((melt_ptr_t)($v)) == MELTOBMAG_BASICBLOCK)}# )

(defprimitive isnull_basicblock (:basic_block bb) :long
  :doc #{Test if $BB is the null raw basic block.}#
  #{($BB == (basic_block)0)}# )

(defprimitive ==bb (:basic_block bb1 bb2) :long
  :doc #{Identity [i.e. pointer equality] of raw basic_blocks.}#
  #{ ($BB1) == ($BB2) }#)

(defprimitive notnull_basicblock (:basic_block bb) :long
  :doc #{Test if $BB is a real not null raw basic_block.}#
 #{/* notnull_basicblock */ ($BB != (basic_block)0)}# )

(defprimitive null_basicblock () :basic_block
  :doc #{Gives the null raw basic_block pointer}#
  #{/* null_basicblock */ ((basic_block)0)}#)

(defprimitive basicblock_index (:basic_block bb) :long
  :doc #{Gives the index of a basic block.}#
  #{/* basicblock_index */ (($BB)?(($BB)->index):0L) }#)

(defprimitive make_basicblock (discr :basic_block bb) :value
  :doc #{Box with given $DISCR the raw basic_block $BB into a value.}#
 #{/*make_basicblock*/(meltgc_new_basicblock((meltobject_ptr_t)($DISCR),($BB)))}# )

(defprimitive basicblock_content (v) :basic_block
  :doc #{Safely retrieve the raw basic_block inside value $V}#
 #{(melt_basicblock_content ((melt_ptr_t)($V)))}# )

(defprimitive basicblock_gimpleseq (v) :gimple_seq
  :doc #{Safely retrieve the sequence of statements inside a boxed
  basic block value $V.}#
  #{(melt_basicblock_gimpleseq ((melt_ptr_t)($V)))}# )
  
(defprimitive basicblock_phinodes (v) :gimple_seq
  :doc #{Safely retrieve the phinodes, if any, inside a boxed basic
  block value $V.}# 
  #{(melt_basicblock_phinodes ((melt_ptr_t)($V)))}# )

(defprimitive ppstrbuf_gimple (sbuf :long indent :gimple g) :void
  :doc #{Pretty-print inside strbuf $SBUF with indentation $INDENT the raw gimple $G.}#
  #{ meltgc_ppstrbuf_gimple((melt_ptr_t)($sbuf), 
			       (int) ($INDENT), ($G)) }# )

(defprimitive ppstrbuf_gimple_seq (sbuf :long indent :gimple_seq gseq) :void
  :doc #{Pretty-print inside strbuf $SBUF with indentation $INDENT the raw gimple_seq $GSEQ.}#
  #{ meltgc_ppstrbuf_gimple_seq((melt_ptr_t)($SBUF),
				   (int) ($INDENT), ($GSEQ)) }# )

(defprimitive ppstrbuf_tree (sbuf :long indent :tree t) :void
  :doc #{Pretty-print inside strbuf $SBUF with indentation $INDENT the raw tree $T.}#
  #{ meltgc_ppstrbuf_tree((melt_ptr_t)($sbuf), 
			     (int) ($INDENT), ($T)) }# )

(defprimitive ppstrbuf_basicblock (sbuf :long indent :basic_block bb) :void
  :doc #{Pretty-print inside strbuf $SBUF with indentation $INDENT the raw basic_block $BB.}#
  #{ meltgc_ppstrbuf_basicblock((melt_ptr_t)($sbuf),
				   (int) ($indent), ($bb)) }# )

(defprimitive output_edge (out :edge edg) :void
  :doc #{Output to $OUT the edge $EDG}#
  #{ meltgc_out_edge((melt_ptr_t)($OUT), ($EDG)) }# )

(defprimitive basicblock_single_succ (:basic_block bb) :basic_block
  #{(($bb && single_succ_p($bb))?single_succ($bb):NULL)}# )

(defprimitive basicblock_nb_succ (:basic_block bb) :long
  #{(($bb)?EDGE_COUNT($bb->succs):0)}#)

(defprimitive basicblock_nb_pred (:basic_block bb) :long
  #{(($bb)?EDGE_COUNT($bb->preds):0)}#)

(defprimitive basicblock_nth_succ_edge  (:basic_block bb :long ix) :edge
  #{(($BB && $IX>=0 && $IX<EDGE_COUNT($BB->succs))?EDGE_SUCC($BB,$IX):NULL)}#)

(defprimitive basicblock_nth_pred_edge  (:basic_block bb :long ix) :edge
  #{(($BB && $IX>=0 && $IX<EDGE_COUNT($BB->preds))?EDGE_PRED($BB,$IX):NULL)}#)

;; Primitives concerning dominance in basic_blocks
;; those functions mainly come from gcc/dominance.c

(defprimitive is_dominance_info_available () :long
  :doc #{Check if dominance info are already calculated.
        User normally doesn't have to call this primitive, as MELT functions
        check if there is a need to use this.}#
  #{dom_info_available_p(CDI_DOMINATORS)}#
)

(defprimitive is_post_dominance_info_available () :long
  :doc #{Check if post dominance info are already calculated.
        User normally doesn't have to call this primitive, as MELT functions
        check if there is a need to use this.}#
  #{dom_info_available_p(CDI_POST_DOMINATORS)}#
)

(defprimitive calculate_dominance_info_unsafe () :void
  :doc #{This primitive is internally called, user doesn't need it.
        Build the struct containing dominance info.
        This struct is necessary to use others dominance related function.
        This function is unsafe because it does not register any future call to
        free_dominance_info.}#
  #{calculate_dominance_info(CDI_DOMINATORS)}#
)

(defprimitive calculate_post_dominance_info_unsafe () :void
  :doc #{This primitive is internally called, user doesn't need it.
        Build the struct containing post dominance info.
        This struct is necessary to use other dominance related function.
        This function is unsafe because it does not register any future call to
        free_dominance_info.}#
  #{calculate_dominance_info(CDI_POST_DOMINATORS)}#
)

(defun free_dominance_info () 
  (code_chunk freedominf_chk #{/* free_dominance_info $FREEDOMINF_CHK */ free_dominance_info(CDI_DOMINATORS)}#)
)

(defun free_post_dominance_info () 
  (code_chunk freepostdominf_chk 
  #{/* free_post_dominance_info $FREEPOSTDOMINF_CHK */ free_dominance_info(CDI_POST_DOMINATORS)}#)
)

(defun calculate_dominance_info ()
  (if (is_dominance_info_available)
    () ;; do nothing
    (progn ;; else calculate dom and ask to free them at end of pass
      (calculate_dominance_info_unsafe)
      (at_end_of_this_melt_pass_last free_dominance_info))
    ))


(defun calculate_post_dominance_info () 
  (if (is_post_dominance_info_available)
    ()  ;; do nothing
    (progn ;; else calculate dom and ask to free them at end of pass
      (calculate_post_dominance_info_unsafe)
      (at_end_of_this_melt_pass_last free_post_dominance_info))
    ))


(defprimitive debug_dominance_info (:cstring msg) :void
  :doc #{Debug-print the dominance information.}#
  ;; be careful to keep the __LINE__ on the first line of the macrostring.
  #{ if (melt_flag_debug) { const int thislineno = __LINE__ ;
       extern void debug_dominance_info (enum cdi_direction);
       if (dom_info_available_p(CDI_DOMINATORS)) {
         melt_debugeprintflinenonl (thislineno,
			       "debug_dominance_info %s", $MSG);
         debug_dominance_info (CDI_DOMINATORS);
       } 
       else melt_debugeprintfline (thislineno, 
			      "debug_dominance_info %s not available", $MSG);
     }}#
)

(defprimitive debug_post_dominance_info (:cstring msg) :void
  :doc #{Debug-print the post dominance information.}#
  ;; be careful to keep the __LINE__ on the first line of the macrostring.
  #{ if (melt_flag_debug) { const int thislineno = __LINE__ ;
       extern void debug_dominance_info (enum cdi_direction);
       if (dom_info_available_p(CDI_POST_DOMINATORS)) {
         melt_debugeprintflinenonl (thislineno, 
			       "debug_post_dominance_info %s", $MSG);
         debug_dominance_info (CDI_POST_DOMINATORS);
       } 
       else melt_debugeprintfline (thislineno,
			      "debug_post_dominance_info %s not available", 
			      $MSG);
     }}#
)

(defprimitive get_immediate_dominator_unsafe (:basic_block bb) :basic_block
  :doc#{It doesn't check that dominance info are build, use
      get_immediate_dominator instead.}#
  #{($bb) ? get_immediate_dominator (CDI_DOMINATORS, $bb) : NULL}#
)

(defun get_immediate_dominator (bb) 
 :doc#{Return the next immediate dominator of the boxed basic_block $BB as a
      MELT value.}#
  (if (is_basicblock bb)
  (progn
    (calculate_dominance_info) 
    (return (make_basicblock discr_basic_block 
      (get_immediate_dominator_unsafe (basicblock_content bb))))))
)

(defprimitive get_immediate_post_dominator_unsafe (:basic_block bb) 
  :basic_block
  :doc#{It doesn't check that post_dominance info are build, use
      get_immediate_post_dominator instead.}#
  #{($bb) ? get_immediate_dominator (CDI_POST_DOMINATORS, $bb) : NULL}#
)

(defun get_immediate_post_dominator (bb)
  :doc#{Return the next immediate post dominator of the boxed basic_block $BB as
  a MELT value.}#
  (if (is_basicblock bb)
      (progn
	(calculate_post_dominance_info) 
	(return (make_basicblock discr_basic_block 
				 (get_immediate_post_dominator_unsafe (basicblock_content bb))))))
  )

(defprimitive dominated_by_other_unsafe (:basic_block bba bbb) :long
  :doc#{It doesn't check that dominance info is built, use
  dominated_by_other instead.}#
  #{ (($BBA) && ($BBB) && dominated_by_p (CDI_DOMINATORS, $BBA, $BBB)) }#
  )

(defun dominated_by_other (bbA bbB)
  :doc#{true if boxed basic_block $BBA is dominated by boxed basic_block $BBB.}#
  (if (and (is_basicblock bbA) (is_basicblock bbB))
  (progn
    (calculate_dominance_info) 
    (if (dominated_by_other_unsafe (basicblock_content bbA) 
                                   (basicblock_content bbB))
      (return :true)
    )))
)

(defprimitive post_dominated_by_other_unsafe (:basic_block bbA bbB) :long
  :doc#{It doesn't check that post_dominance info are build, use
      post_dominated_by_other instead.}#
  #{ (($bbA) && ($bbB)) ?
      dominated_by_p (CDI_POST_DOMINATORS, $bbA, $bbB) 
      : 0 
  }#
)

(defun post_dominated_by_other (bbA bbB)
  :doc#{true if boxed basic_block $BBA is post dominated by boxed basic_block
      $BBB.}#
  (if (and (is_basicblock bbA) (is_basicblock bbB))
  (progn
    (calculate_post_dominance_info) 
    (if (post_dominated_by_other_unsafe (basicblock_content bbA) 
                                   (basicblock_content bbB))
      (return :true)
    )))
)

(defciterator foreach_dominated_unsafe
  (:basic_block dominator_bb)
  ebbdomd
  (:basic_block dominated_bb)
  #{
    /* foreach_dominated_unsafe $EBBDOMD before+ */

    vec<basic_block> $EBBDOMD#_bbvec;
    unsigned int $EBBDOMD#_ix = 0;
    basic_block $EBBDOMD#_bb = 0;

    if($DOMINATOR_BB) {
      $EBBDOMD#_bbvec = get_dominated_by (CDI_DOMINATORS, $DOMINATOR_BB);
        FOR_EACH_VEC_ELT ($EBBDOMD#_bbvec, 
          $EBBDOMD#_ix, $EBBDOMD#_bb) 
        {
          if (!$EBBDOMD#_ix)
            continue;
          $DOMINATED_BB = $EBBDOMD#_bb;
     /*$EBBDOMD before- */}#
      ;; after expansion
  #{/* foreach_dominated_unsafe $EBBDOMD after+ */
        }
      }
   /* foreach_dominated_unsafe dont need to free $EBBDOMD#_bbvec */
    $EBBDOMD#_bb = 0;
    /* $EBBDOMD after- */}#
)

(defun dominated_by_bb_iterator (f data bb)
  :doc #{run function $F on every basicblocks dominated by boxed basic_block
      $BB with $DATA as first parameters and ending with the dominated
      basicblock as last parameters.}#
  (calculate_dominance_info)
  (foreach_dominated_unsafe
    ((basicblock_content bb))
    (:basic_block dominated_bb)
    (f data dominated_bb)
  )
)

;;;;;;;;;;;;;;;; iterating on edges succeeding a given basic_block	
;;;see also foreach_basicblock_succ_edge
(defciterator foreach_edge_bb_succs
  (:basic_block bb)			;the input formal
  eachedgebbsucc			;the state symbol
  (:edge edg)				;the local formal
  :doc #{$FOREACH_EDGE_BB_SUCC iterates on the basic block $BB edges succeeding it $EDG}#
  ;;
  ;; before expansion
  #{ /*  foreach_edge_bb_succs $EACHEDGEBBSUCC++ */		
  if ($BB) {
    edge_iterator $EACHEDGEBBSUCC#_iter;
    edge $EACHEDGEBBSUCC#_edge = NULL;
    FOR_EACH_EDGE($EACHEDGEBBSUCC#_edge, $EACHEDGEBBSUCC#_iter, ($BB)->succs) 
      {
        if (!$EACHEDGEBBSUCC#_edge) continue;
	$EDG = $EACHEDGEBBSUCC#_edge;
  }#
  ;;
  ;; after expansion 
  #{ /* foreach_edge_bb_succs $EACHEDGEBBSUCC-- */
     }; /* end FOR_EACH_EDGE $EACHEDGEBBSUCC */
   } /* end if $EACHEDGEBBSUCC */
   }#
)

;;
(defun bb_dominator_iterator (bb f data)
  :doc #{apply function $F on each dominator of $BB.}#
  (calculate_dominance_info)
  (let ( (dom (get_immediate_dominator bb)) )
  (if dom
    (progn 
      (f data dom)
      (bb_dominator_iterator dom f data)
    )
  ))
)

;;
(defun bb_post_dominator_iterator (bb f data)
  :doc #{apply function $F on each dominator of $BB.}#
  (debug "entering bb_post_dominator_iterator bb=" bb " data=" data)
  (calculate_post_dominance_info)
  (let ( (dom (get_immediate_post_dominator bb)) )
  (if (basicblock_content dom)
    (progn 
      (f data dom)
      (bb_post_dominator_iterator dom f data)
    )
  ))
)

;;;;;;;;;;;;;;;; iterating on edges preceding a given basic_block
(defciterator foreach_edge_bb_preds
  (:basic_block bb)			;the input formal
  eachedgebbpred			;the state symbol
  (:edge edg)				;the local formal
  ;;
  ;; before expansion
  #{ /* $EACHEDGEBBPRED++ */		
  if ($BB) {
    edge_iterator $EACHEDGEBBPRED#_iter;
    edge $EACHEDGEBBPRED#_edge = NULL;
    FOR_EACH_EDGE($EACHEDGEBBPRED#_edge, $EACHEDGEBBPRED#_iter, ($BB)->preds) 
      {
        if (!$EACHEDGEBBPRED#_edge) continue;
	$EDG = $EACHEDGEBBPRED#_edge;
  }#
  ;;
  ;; after expansion 
  #{ /* $EACHEDGEBBPRED-- */
     }; /* end FOR_EACH_EDGE $EACHEDGEBBPRED */
   } /* end if $EACHEDGEBBPRED */
   }#
)

;;;;;;;;;;;;;;;;

(defprimitive is_mapbasicblock (map) :long
  :doc #{Test if $MAP is a map keyed by basicblocks.}#
  #{(melt_magic_discr((melt_ptr_t)($map)) == MELTOBMAG_MAPBASICBLOCKS)}# )
(defprimitive mapbasicblock_size (map) :long
  :doc #{Retrieve the allocated size of a basicblock map.}#
  #{(melt_size_mapbasicblocks((struct meltmapbasicblocks_st*)($map)))}#)
;; primitive to get the attribute count of a mapbasicblock
(defprimitive mapbasicblock_count (map) :long
  :doc #{Retrieve the used count of a map of basicblocks.}#
  #{(melt_count_mapbasicblocks((struct meltmapbasicblocks_st*)($map)))}#)
;; get an entry in a mapbasicblock from a C basicblock
(defprimitive mapbasicblock_get (map :basic_block bb) :value
  :doc #{Safely get in a a basic block map $MAP the value associated to basic block $BB.}#
  #{(melt_get_mapbasicblocks((melt_ptr_t) ($map), ($bb)))}#)
;; primitive for making a new map of basicblocks
(defprimitive make_mapbasicblock (discr :long len) :value
  :doc #{Make a map keyed by basic blocks, of given $DISCR and allocated $LEN.}#
  #{(meltgc_new_mapbasicblocks( (meltobject_ptr_t) ($discr),
				   ($len)))}#)

;; primitive for putting into a map of basicblocks
(defprimitive mapbasicblock_put (map :basic_block key :value val) :void
  :doc #{Put into map $MAP the basic_block $KEY associated to $VAL.}#
  #{melt_put_mapbasicblocks((melt_ptr_t) ($map), ($key), (melt_ptr_t) ($val))}#)

;; primitive for removing from a map of basicblocks
(defprimitive mapbasicblock_remove (map :basic_block key) :void
  :doc #{Remove from map $MAP the entry for basic_block $KEY.}#
 #{melt_remove_mapbasicblocks((melt_ptr_t) ($MAP), ($KEY))}#)

;; primitive to get the auxiliary data of a basicblocks map
(defprimitive mapbasicblock_aux (map) :value
  :doc #{Safely retrieve the auxiliary data of map of basic blocks $MAP.}#
  #{melt_auxdata_mapbasicblocks((melt_ptr_t)$MAP)}#)

;; put
(defprimitive mapbasicblock_auxput (map aux) :void
  :doc #{Safely put the auxiliary data of map of basic blocks $MAP to $AUX.}#
  #{melt_auxput_mapbasicblocks((melt_ptr_t) (melt_ptr_t)$MAP, (melt_ptr_t)$AUX)}#)

;; primitive to get the nth basicblock of a mapbasicblock
(defprimitive mapbasicblock_nth_attr (map :long n) :basic_block
 #{(melt_nthattr_mapbasicblocks((struct meltmapbasicblocks_st*)($map), 
				   (int)($n)))}#)
;; primitive to get the nth value of a mapbasicblock
(defprimitive mapbasicblock_nth_val (map :long n) :value
 #{(melt_nthval_mapbasicblocks((struct meltmapbasicblocks_st*)($map),
				  (int)($n)))}#)
(defciterator foreach_mapbasicblock 
  (bbmap)				; startformals
  eachmapbb 				;state symbol
  (:basic_block bbatt :value bbval)	;local formals
  ;; before expansion
  #{ /* foreach_mapbasicblock $EACHMAPBB */ {
   int  $EACHMAPBB#_rk=0;
   for ( $EACHMAPBB#_rk=0;  
	 $EACHMAPBB#_rk< (int) melt_size_mapbasicblocks((struct meltmapbasicblocks_st*)($BBMAP));  
	 $EACHMAPBB#_rk++) {
   basic_block $EACHMAPBB#_bb =
     melt_nthattr_mapbasicblocks((struct meltmapbasicblocks_st*)($BBMAP), $EACHMAPBB#_rk);
   if (!$EACHMAPBB#_bb) continue;
   $BBATT = $eachmapbb#_bb;
   $BBVAL = melt_nthval_mapbasicblocks((struct meltmapbasicblocks_st*)($BBMAP), $EACHMAPBB#_rk);
   }#
  ;;after expansion
   #{ }
   } /*end foreach_mapbasicblock $EACHMAPBB*/
   }#
  )


;; see also foreach_edge_bb_succs
(defciterator foreach_basicblock_succ_edge
  (:basic_block bb)
  eachbbsucc
  (:edge e :long eix)
  #{
  /* $eachbbsucc start */
   int $eachbbsucc#_nbsuc = $bb ? EDGE_COUNT($bb->succs) : 0;
   int $eachbbsucc#_ix = 0;
   for ($eachbbsucc#_ix=0; 
	$eachbbsucc#_ix < $eachbbsucc#_nbsuc;  
	$eachbbsucc#_ix++) {
     $e = EDGE_SUCC(($bb), $eachbbsucc#_ix);
     if (!$e) continue;
     $eix = $eachbbsucc#_ix;
   }#
   #{  /* $eachbbsucc end */ }  }#
)

;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; iterators needed in our analysis

;;; an iterator is simply something which translates to a for loop in
;;; C. It usually binds some variables (local to the iterated body)
;;; to some C stuff.

;;; Be careful to not declare any iterator related stuff in
;;; warmelt*.melt file, because we want to be able to bootstrap
;;; Melt/MELT (ie to generate the warmelt*.c files) even when GCC
;;; internal representation changes a little.

;;;;;;;;;;;;;;;;
;;;; iterate on every cgraph_node which is a function with a body
(defciterator each_cgraph_fun_body 
  ()					; startformals
  eachcgrfun 				;state symbol
  (:tree funtree :gimple_seq funbody)	;local formals
  :doc #{$EACH_CGRAPH_FUN_BODY iterates on every cgraph_node which is
  a function declared as $FUNTREE with a body $FUNBODY.}#
  ;; before expansion
  #{ /*  each_cgraph_fun_body $EACHCGRFUN + */
   struct cgraph_node *$EACHCGRFUN#_nd = NULL; 
   /* each_cgraph_fun_body $EACHCGRFUN */
   FOR_EACH_DEFINED_FUNCTION($EACHCGRFUN#_nd)
     {  /* each_cgraph_fun_body $EACHCGRFUN inside for */
       tree $EACHCGRFUN#_dcl = NULL;
       gimple_seq  $EACHCGRFUN#_bdy = NULL;
   /* in each_cgraph_fun_body $EACHCGRFUN */
       $EACHCGRFUN#_dcl =  $EACHCGRFUN#_nd->decl;
       if (!$EACHCGRFUN#_dcl) continue;
       if (TREE_CODE($EACHCGRFUN#_dcl) != FUNCTION_DECL) continue;
       $EACHCGRFUN#_bdy = gimple_body($EACHCGRFUN#_dcl);
       if (!$EACHCGRFUN#_bdy) continue;
       $FUNTREE = $EACHCGRFUN#_dcl;
       $FUNBODY = $EACHCGRFUN#_bdy;
  }#
   ;;after expansion
   #{ } /*  each_cgraph_fun_body $EACHCGRFUN - */ }#  )


;;; iterate on every cgraph_node which is a function with a CFG and an
;;; entryblock
(defciterator each_cgraph_fun_entryblock
  ()					;startformals
  eachcgrafunentrblo				;state symbol
  (:tree funtree :basic_block funentrybb funexitbb)	;local formals
  ;;before expansion
  #{ /* each_cgraph_fun_entryblock $EACHCGRAFUNENTRBLO + */
   struct cgraph_node *$EACHCGRAFUNENTRBLO#_nd = NULL; 
   /* each_cgraph_fun_entryblock $EACHCGRAFUNENTRBLO */
   FOR_EACH_DEFINED_FUNCTION($EACHCGRAFUNENTRBLO#_nd)
   {
   tree  $EACHCGRAFUNENTRBLO#_dcl = NULL;
   basic_block  $EACHCGRAFUNENTRBLO#_entrybb = NULL;
   basic_block  $EACHCGRAFUNENTRBLO#_exitbb = NULL;
   struct function *$EACHCGRAFUNENTRBLO#_fun = NULL;
   /* in each_cgraph_fun_entryblock $EACHCGRAFUNENTRBLO */
   $EACHCGRAFUNENTRBLO#_dcl = $EACHCGRAFUNENTRBLO#_nd->decl;
   if (! $EACHCGRAFUNENTRBLO#_dcl) continue;
   if (TREE_CODE($EACHCGRAFUNENTRBLO#_dcl) != FUNCTION_DECL) continue;
   $EACHCGRAFUNENTRBLO#_fun = DECL_STRUCT_FUNCTION($EACHCGRAFUNENTRBLO#_dcl);
   if (!$EACHCGRAFUNENTRBLO#_fun) continue;
   /* this assert fails when in a pass without control flow graph */
   melt_assertmsg ("no cfg in each_cgraph_fun_entryblock $EACHCGRAFUNENTRBLO",
		   $EACHCGRAFUNENTRBLO#_fun->cfg != NULL);
   /* each_cgraph_fun_entryblock $EACHCGRAFUNENTRBLO : */
   $EACHCGRAFUNENTRBLO#_entrybb =
     ENTRY_BLOCK_PTR_FOR_FN ($EACHCGRAFUNENTRBLO#_fun);
   if (!$EACHCGRAFUNENTRBLO#_entrybb) continue;
   $EACHCGRAFUNENTRBLO#_exitbb =
     EXIT_BLOCK_PTR_FOR_FN ($EACHCGRAFUNENTRBLO#_fun);
   if (! $EACHCGRAFUNENTRBLO#_exitbb) continue;
   $funtree = $EACHCGRAFUNENTRBLO#_dcl;
   $funentrybb = $EACHCGRAFUNENTRBLO#_entrybb;
   $funexitbb = $EACHCGRAFUNENTRBLO#_exitbb;
  }#
  ;;after expansion
  #{ } /* each_cgraph_fun_entryblock $EACHCGRAFUNENTRBLO - */ }# )


;; iterator on every cgraph_node which is a function with a CFG, and
;; retrieve its entry block, exit block, tuple of blocks, and uses a
;; temporary value TMPV
(defciterator each_cgraph_fun_call_flow_graph
  ()	      ;start formals
  eachcgrafuncfg
  (:tree funtree :basic_block funentrybb funexitbb :value bbtup tmpv)
  :doc #{$EACH_CGRAPH_FUN_CALL_FLOW_GRAPH iterates on every callgraph
  function with a body and a control flow graph, giving the
  declaration $FUNTREE, the entry and exit basic blocks $FUNENTRYBB
  and $FUNEXITBB, the tuple of boxed basic blocks $BBTUP, and needs an
  internal temporary value $TMPV}#
  ;; before expansion
  #{ /* each_cgraph_fun_call_flow_graph $EACHCGRAFUNCFG + */
   struct cgraph_node *$EACHCGRAFUNCFG#_nd = NULL; 
   /* each_cgraph_fun_call_flow_graph loop  $EACHCGRAFUNCFG */
   FOR_EACH_DEFINED_FUNCTION($EACHCGRAFUNCFG#_nd)
    {
      tree  $EACHCGRAFUNCFG#_dcl = NULL;
      basic_block $EACHCGRAFUNCFG#_curbb = NULL;
      struct function *$EACHCGRAFUNCFG#_fun = NULL;
      int $EACHCGRAFUNCFG#_n_bb = 0;
      int $EACHCGRAFUNCFG#_ix = 0;
      /* inside  each_cgraph_fun_call_flow_graph loop  $EACHCGRAFUNCFG */
      $EACHCGRAFUNCFG#_dcl = $EACHCGRAFUNCFG#_nd->decl;
      if (! $EACHCGRAFUNCFG#_dcl) 
        continue;
      if (TREE_CODE($EACHCGRAFUNCFG#_dcl) != FUNCTION_DECL) 
        continue;
      $EACHCGRAFUNCFG#_fun = DECL_STRUCT_FUNCTION($EACHCGRAFUNCFG#_dcl);
      if (!$EACHCGRAFUNCFG#_fun) 
        continue;
      melt_debugeprintf("$EACHCGRAFUNCFG#_fun %p", (void*) $EACHCGRAFUNCFG#_fun);
      $FUNTREE = $EACHCGRAFUNCFG#_dcl;
      $TMPV = NULL;
      $EACHCGRAFUNCFG#_n_bb = ($EACHCGRAFUNCFG#_fun->cfg)
                              ? n_basic_blocks_for_fn
                                   ($EACHCGRAFUNCFG#_fun)
	         	      : 0;
      /*  each_cgraph_fun_call_flow_graph $EACHCGRAFUNCFG create the tuple of basic blocks */
      $BBTUP = meltgc_new_multiple
        ((meltobject_ptr_t) MELT_PREDEF (DISCR_MULTIPLE),
	 $EACHCGRAFUNCFG#_n_bb);
      for ($EACHCGRAFUNCFG#_ix = 0;
	   $EACHCGRAFUNCFG#_ix < $EACHCGRAFUNCFG#_n_bb;
	   $EACHCGRAFUNCFG#_ix ++) {
           $EACHCGRAFUNCFG#_curbb =
              BASIC_BLOCK_FOR_FN ($EACHCGRAFUNCFG#_fun,
				  $EACHCGRAFUNCFG#_ix);
	   if (!$EACHCGRAFUNCFG#_curbb) 
	     continue;
	   $TMPV = 
	   meltgc_new_basicblock 
	   ((meltobject_ptr_t) MELT_PREDEF (DISCR_BASIC_BLOCK),
	    $EACHCGRAFUNCFG#_curbb);
	   meltgc_multiple_put_nth ((melt_ptr_t)$BBTUP,
				    $EACHCGRAFUNCFG#_ix,
				    $TMPV);
      } /* each_cgraph_fun_call_flow_graph $EACHCGRAFUNCFG done bb tuple */
      $TMPV = NULL;
  }#
  ;; after expansion
  #{ /*  each_cgraph_fun_call_flow_graph $EACHCGRAFUNCFG - */
     $TMPV = NULL;
   }
  }#
)


;; iterator to get the current cfun decl
(defciterator with_cfun_decl
  ()
  withcfundecl
  (:tree cfundecl)
  :doc #{iterator done one giving the current $CFUNDECL, if cfun exists}#
  #{ /*starting with_cfun_decl $WITHCFUNDECL*/
   $CFUNDECL = (tree) NULL;
   if (cfun) {
     $CFUNDECL = cfun->decl;
  }#
  #{ /*end with_cfun_decl $WITHCFUNDECL*/ }
  }#)


;; iterator to push then pop every declared function
(defciterator each_cgraph_pushed_cfun
  () ;;;; no start formals
  eachcgrapushcfun
  (:tree funtree :basic_block funentrybb funexitbb)
  :doc #{$EACH_CGRAPH_PUSHED_CFUN iterates on every callgraph
  function with a body and a control flow graph, giving the
  declaration $FUNTREE, the entry and exit basic blocks $FUNENTRYBB
  and $FUNEXITBB, and pushing then popping at end of loop that
  function as the current cfun.}#
  ;; before expansion
  #{ /* each_cgraph_pushed_cfun start $EACHCGRAPUSHCFUN */
   struct cgraph_node *$EACHCGRAPUSHCFUN#_nd = NULL; 
   /* each_cgraph_fun_call_flow_graph loop  $EACHCGRAPUSHCFUN  */
   FOR_EACH_DEFINED_FUNCTION($EACHCGRAPUSHCFUN#_nd)
    {
      tree  $EACHCGRAPUSHCFUN#_dcl = NULL;
      basic_block $EACHCGRAPUSHCFUN#_entrybb = NULL;
      basic_block $EACHCGRAPUSHCFUN#_exitbb = NULL;
      struct function *$EACHCGRAPUSHCFUN#_fun = NULL;
      /* inside  each_cgraph_fun_call_flow_graph loop  $EACHCGRAPUSHCFUN */
      $EACHCGRAPUSHCFUN#_dcl = $EACHCGRAPUSHCFUN#_nd->decl;
      if (! $EACHCGRAPUSHCFUN#_dcl) 
        continue;
      if (TREE_CODE($EACHCGRAPUSHCFUN#_dcl) != FUNCTION_DECL) 
        continue;
      $EACHCGRAPUSHCFUN#_fun = DECL_STRUCT_FUNCTION($EACHCGRAPUSHCFUN#_dcl);
      if (!$EACHCGRAPUSHCFUN#_fun) 
        continue;
      melt_debugeprintf("$EACHCGRAPUSHCFUN#_fun %p",
			(void*) $EACHCGRAPUSHCFUN#_fun);
      $FUNTREE = $EACHCGRAPUSHCFUN#_dcl;
   /* each_cgraph_fun_push_cfun $EACHCGRAPUSHCFUN : */
   $EACHCGRAPUSHCFUN#_entrybb =
     ENTRY_BLOCK_PTR_FOR_FN ($EACHCGRAPUSHCFUN#_fun);
   if (!$EACHCGRAPUSHCFUN#_entrybb) continue;
   $EACHCGRAPUSHCFUN#_exitbb =
     EXIT_BLOCK_PTR_FOR_FN ($EACHCGRAPUSHCFUN#_fun);
   if (! $EACHCGRAPUSHCFUN#_exitbb) continue;
   $FUNENTRYBB = $EACHCGRAPUSHCFUN#_entrybb;
   $FUNEXITBB = $EACHCGRAPUSHCFUN#_exitbb;
   push_cfun ($EACHCGRAPUSHCFUN#_fun);
   /* each_cgraph_pushed_cfun started $EACHCGRAPUSHCFUN */
   }#
   ;; after expansion
   #{ /* each_cgraph_pushed_cfun ending $EACHCGRAPUSHCFUN */
   $FUNENTRYBB = NULL;
   $FUNEXITBB = NULL;
   pop_cfun ();
   } /* each_cgraph_pushed_cfun ended $EACHCGRAPUSHCFUN */
   }#
   )


;;; iterate on evey basicblock of the current cfun
(defciterator each_bb_current_fun
  ()					;startformals
  eachbbcurfun				;state symbol
  (					;local formals
   :basic_block curbb 
   )	
  ;;before expansion
  #{ /* start each_bb_current_fun $EACHBBCURFUN */ { const int $EACHBBCURFUN#_line = __LINE__;
   $CURBB = (basic_block) NULL;
   if (cfun && cfun->cfg) {
     basic_block  $EACHBBCURFUN#_bb = NULL;
     FOR_EACH_BB_FN($EACHBBCURFUN#_bb, cfun) {
       $CURBB = (basic_block) NULL;
       if (!$EACHBBCURFUN#_bb) continue;
       $CURBB  = $EACHBBCURFUN#_bb;
 }#
 ;;after expansion
 #{ /* ending each_bb_current_fun $EACHBBCURFUN */ }} else 
      melt_fatal_error_at_line
       ($EACHBBCURFUN#_line,
	"each_bb_current_fun used with invalid cfun=%p [$EACHBBCURFUN]", 
	(void*) cfun);
  /* end each_bb_current_fun $EACHBBCURFUN */  }
 }# )

;;; iterate on evey basicblock of the current cfun & its decl
(defciterator each_bb_cfun
  ()					;startformals
  eachbbcfun				;state symbol
  (					;local formals
   :basic_block cfunbb 
   :tree cfundecl
   )
  :doc #{$EACH_BB_CFUN iterates on every basic block $CFUNBB of the 
current function and gives its declaration in $CFUNDECL}#
  ;;before expansion
  #{ /* start each_bb_cfun $EACHBBCFUN */ const int $EACHBBCFUN#_line = __LINE__;
   $CFUNBB = (basic_block) NULL;
   $CFUNDECL = (tree) NULL;
   if (cfun && cfun->cfg) {
     basic_block  $EACHBBCFUN#_bb = NULL;
     $CFUNDECL  = cfun->decl;
    FOR_EACH_BB_FN($EACHBBCFUN#_bb, cfun) {
      $CFUNBB = (basic_block) NULL;
      if (!$EACHBBCFUN#_bb) continue;
      $CFUNBB  = $EACHBBCFUN#_bb;
 }#
 ;;after expansion
 #{  /*ending each_bb_cfun  $EACHBBCFUN */
      $CFUNBB = (basic_block) NULL;
       } /* end FOR_EACH_BB_FN $EACHBBCFUN */ 
     $CFUNDECL = (tree) NULL;
   } else /* no cfg in $EACHBBCFUN */
      melt_fatal_error_at_line 
       ($EACHBBCFUN#_line,
	"each_bb_cfun used with invalid cfun=%p without cfg [$EACHBBCFUN]", 
	(void*) cfun);
   $CFUNBB = (basic_block) NULL;
   $CFUNDECL = (tree) NULL;
  /* end  each_bb_cfun $EACHBBCFUN */  
 }# )

;;; iterate on evey local declaration of the current cfun
(defciterator each_local_decl_cfun
  ()					;startformals
  eachlocalcfun				;state symbol
  (					;local formals
   :tree tlocdecl :long ix
  )
  :doc #{$EACH_LOCAL_DECL_CFUN iterates on every local declaration
  $TLOCDECK of index $IX in the current cfun using
  @code{FOR_EACH_LOCAL_DECL}.}#
  ;;before expansion
  #{ /* start each_local_decl_cfun $EACHLOCALCFUN */ const int $EACHLOCALCFUN#_line = __LINE__;
   $TLOCDECL = (tree) NULL;
   $IX = 0;
   if (!cfun)
     melt_fatal_error_at_line
      ($EACHLOCALCFUN#_line,
       "each_local_decl_cfun [$EACHLOCALCFUN] called without cfun %p", 
       (void*) cfun);
   if (cfun->local_decls) {
     unsigned $EACHLOCALCFUN#_ix = 0;
     tree $EACHLOCALCFUN#_tdcl = NULL_TREE;
     FOR_EACH_LOCAL_DECL (cfun, $EACHLOCALCFUN#_ix, $EACHLOCALCFUN#_tdcl) {
        $TLOCDECL = $EACHLOCALCFUN#_tdcl;
        $IX = $EACHLOCALCFUN#_ix;
  }#
  ;; after expansion
  #{ /* ending each_local_decl_cfun $EACHLOCALCFUN */
        $TLOCDECL = NULL_TREE;
      }; /* end FOR_EACH_LOCAL_DECL $EACHLOCALCFUN */
    $EACHLOCALCFUN#_tdcl = NULL_TREE;
    $EACHLOCALCFUN#_ix = 0;
    } /* end  each_local_decl_cfun if cfun $EACHLOCALCFUN */ 
  }#
)


;; the basic block source of an edge
(defprimitive edge_src_bb (:edge eg) :basic_block
#{ ($eg)?($eg->src):NULL }#)

;; the basic block destination of an edge
(defprimitive edge_dest_bb (:edge eg) :basic_block
#{ ($eg)?($eg->dest):NULL }#)

;; test if an edge is for a true value of a branch
(defprimitive edge_for_true_value (:edge eg) :long
#{ ($eg && $eg->flags & EDGE_TRUE_VALUE) }#)
;; test if an edge is for a false value of a branch
(defprimitive edge_for_false_value (:edge eg) :long
#{ ($eg && $eg->flags & EDGE_FALSE_VALUE) }#)



;;;;;;;;;;;;;;;;;;;;;;;;;;;; basicblock iteration

(defciterator eachgimple_in_basicblock
  (:basic_block bb)			;start formals
  eachgimpbb
  (:gimple g)				;local formals
;;; before expansion
  #{
  /* start  eachgimple_in_basicblock $EACHGIMPBB */ 
  gimple_stmt_iterator gsi_$EACHGIMPBB	;
  if ($BB) 
    for (gsi_$EACHGIMPBB = gsi_start_bb ($BB) ;
		       !gsi_end_p (gsi_$EACHGIMPBB) ;
		       gsi_next (&gsi_$EACHGIMPBB)) {
  $G = gsi_stmt (gsi_$EACHGIMPBB)	;
  }#
;;; after expansion
  #{ } /* end  eachgimple_in_basicblock $EACHGIMPBB */ }#  
  )
  

(defciterator eachgimplephi_in_basicblock
  (:basic_block bb)			;start formals
  eachgimphi
  (:gimple g)				;local formals
  ;;; before expansion
  #{
   /* start $EACHGIMPHI */ 
   gimple_stmt_iterator gsi_$EACHGIMPHI;
   if ($BB) 
     for (gsi_$EACHGIMPHI = gsi_start_phis ($BB);
          !gsi_end_p (gsi_$EACHGIMPHI);
          gsi_next (&gsi_$EACHGIMPHI)) {
       $G = gsi_stmt (gsi_$EACHGIMPHI);
  }#
  ;;; after expansion
  #{ } /* end $EACHGIMPHI */ }#  )
  


;;;;;;;;;;;;;;;;;;;;;;;;;;;; gimpleseq iteration
;;;; iterate on a function formal parameters
(defciterator each_param_in_fundecl
  ( :tree fundeclt )			;start formals
  eachparamfun
  ( :tree paramdclt )				;local formals
  ;;; before expansion
  #{
   /*eachparaminfunctiondecl*/
   tree $eachparamfun#_tr=NULL;
   if (($fundeclt) && TREE_CODE($fundeclt) == FUNCTION_DECL)
     for ($eachparamfun#_tr = DECL_ARGUMENTS($fundeclt);
          $eachparamfun#_tr != NULL;
          $eachparamfun#_tr = TREE_CHAIN($eachparamfun#_tr)) {
 	    $paramdclt = $eachparamfun#_tr;
  }#
  ;;; after expansion
  #{
   }/*end eachparaminfunctiondecl*/
  }# )

;;; iterate on fields of a structure
(defciterator foreach_field_in_record_type
  (:tree first_field)
  efirt
  (:tree field)

  #{   /* $EFIRT + */
       if ($first_field && TREE_CODE ($first_field) == FIELD_DECL)
       {
           tree $efirt#_current;
	   for ($efirt#_current = $first_field; 
		$efirt#_current != NULL;
		$efirt#_current = TREE_CHAIN ($efirt#_current))
	   {
	       $field = $efirt#_current;
  }#

  #{ /* $EFIRT - */
           }
       }
  }#)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; loop related operations

(defprimitive is_loop (v) :long
   #{(melt_magic_discr((melt_ptr_t)($v)) == MELTOBMAG_LOOP)}# )

(defprimitive make_loop (discr :loop l) :value
  #{(meltgc_new_loop((meltobject_ptr_t)($discr),($l)))}# )

(defprimitive loop_content (v) :loop
  #{(melt_loop_content((melt_ptr_t)($v)))}# )


(defprimitive output_loop (out :loop lo) :void
  :doc #{Output to $OUT the loop $LO}#
  #{ meltgc_out_loop((melt_ptr_t)($OUT), ($LO)) }# )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; retrieve the loop body as a tuple of boxed basic_block-s
(defun loop_body_tuple (discr :loop lo) 
  (debug "loop_body_tuple lo=" lo)
  (if (null discr) (setq discr discr_multiple))
  (if lo
      (let ( (:long loopnbnodes 0) 
	     )
	(code_chunk 
	 getloopnbnodeschunk
	 #{/*$GETLOOPNBNODESCHUNK*/
	 $LOOPNBNODES = $LO?($LO -> num_nodes):0 ; }#
	 )
	(let ( (tupbody (make_multiple discr loopnbnodes))
	       )
	  (if (null tupbody) (return)) 
	  ;; first, fill the tuple with empty basic block boxes
	  (foreach_long_upto 
	   (0 (-i loopnbnodes 1))
	   (:long ix)
	     (multiple_put_nth 
	      tupbody ix 
	      (make_basicblock discr_basic_block (null_basicblock)))
	   )
	  (let ( (ourbb ())
		 )
	  ;; retrieve the malloc-ed array of basic blocks and use it to fill the tuple
	  ;; then free it
	  (code_chunk
	   fillbbboxeschunk
	   #{ /*$FILLBBBOXESCHUNK*/
	   long $FILLBBBOXESCHUNK#_ix = 0 ;
	   basic_block* $FILLBBBOXESCHUNK#_bbtab = 0 ;
	   $FILLBBBOXESCHUNK#_bbtab = get_loop_body ($LO) ; /* a malloc-ed array */
	   for ($FILLBBBOXESCHUNK#_ix = 0 ;
				      $FILLBBBOXESCHUNK#_ix < $LOOPNBNODES ;
				      $FILLBBBOXESCHUNK#_ix++) {
	   $OURBB = melt_multiple_nth ((melt_ptr_t) $TUPBODY, $FILLBBBOXESCHUNK#_ix)	;
	   meltgc_basicblock_updatebox
                ((melt_ptr_t) $OURBB, 
		 $FILLBBBOXESCHUNK#_bbtab[$FILLBBBOXESCHUNK#_ix]) ;
	   }
	   free ($FILLBBBOXESCHUNK#_bbtab), $FILLBBBOXESCHUNK#_bbtab=0 ;
	   $OURBB = (melt_ptr_t)0;
	   /*end $FILLBBBOXESCHUNK*/
	   }#)
	  )
	  (debug "loop_body_tuple return tupbody=" tupbody)
	  (return tupbody)
	  ))))

;;; iterator to retrieve loop exit edges & iterate on them
(defciterator foreach_loop_exit_edges
  (:loop lo)				;start formal
  eachloopexitedge			;state symbol
  (:edge ed :long ix)			;local formals
  ;; before expansion
  #{ /* $EACHLOOPEXITEDGE before+ */
  vec<edge> $EACHLOOPEXITEDGE#_edgevec;
  unsigned $EACHLOOPEXITEDGE#_ix = 0;
  edge $EACHLOOPEXITEDGE#_edge = 0;
  if ($LO) 
    $EACHLOOPEXITEDGE#_edgevec = get_loop_exit_edges ($LO);
      FOR_EACH_VEC_ELT ($EACHLOOPEXITEDGE#_edgevec, 
		      $EACHLOOPEXITEDGE#_ix, $EACHLOOPEXITEDGE#_edge) 
    {
      if (!$EACHLOOPEXITEDGE#_edge) 
        continue;
      $ED = $EACHLOOPEXITEDGE#_edge; 
      $IX = $EACHLOOPEXITEDGE#_ix;
/* $EACHLOOPEXITEDGE before- */}#
  ;; after expansion
  #{ /* $EACHLOOPEXITEDGE after+ */
  } /* end FOR_EACH_VEC_ELT  $EACHLOOPEXITEDGE*/
  /* no need to free $EACHLOOPEXITEDGE#_edgevec */
  $EACHLOOPEXITEDGE#_edge = 0;
/* $EACHLOOPEXITEDGE after- */}#
)
 
;; retrieve the loop exit edges as a tuple of boxed edge-s
(defun loop_exit_edges_tuple (discr :loop lo) 
  (debug "loop_exit_edges_tuple lo=" lo)
  (if (null discr) (setq discr discr_multiple))
  (let ( (:long maxix 0)
	 (edglis (make_list discr_list))
	 )
    (foreach_loop_exit_edges
     (lo)
     (:edge ed :long ix)
     (let ( (boxedge (make_edge discr_edge ed))
	    )
       (if (>=i maxix ix) (setq maxix (+i 1 ix)))
       (list_append edglis boxedge)
       ))
    (let ( (edgevec (make_multiple discr maxix))
	   (:long ix 0)
	   )
      (foreach_pair_component_in_list
       (edglis)
       (curpair edgebox)
       (multiple_put_nth edgevec ix edgebox)
       (setq ix (+i ix 1)))
      (debug "loop_exit_edges_tuple return edgevec=" edgevec)
      (return edgevec)))
  )

;;;;;;;;;;;;;;;;
(defun superloop_tuple (loopv)
  :doc #{Given a boxed loop $LOOPV, return the tuple of its boxed superloops.}#
  (if (is_loop loopv)
      (let ( (:loop lo (loop_content loopv))
	     )
	(if lo
	    (let (
		  (:long lodepth (loop_depth lo))
		  (tup (make_multiple discr_multiple lodepth))
		  )
	      (foreach_superloop
	       (lo)
	       (:loop curloop :long loopix)
		 (multiple_put_nth tup loopix 
				   (make_loop discr_loop curloop))
	       )
	      (return tup)
	      )))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; safe queries to the cfun (when cfun is null, return null or 0)
(defprimitive has_cfun () :long #{ cfun != NULL }#)

(defprimitive cfun_decl () :tree 
  #{ (cfun?(cfun->decl):NULL) }#)

(defprimitive cfun_static_chain_decl () :tree
  #{ (cfun?(cfun->static_chain_decl):NULL) }#)

(defprimitive cfun_nonlocal_goto_save_area () :tree
  #{ (cfun?(cfun->nonlocal_goto_save_area):NULL) }#)


(defprimitive cfun_has_cfg () :long
  #{ (cfun?(cfun->cfg != NULL):0) }#)


;; EXIT_BLOCK_PTR_FOR_FN
(defprimitive cfun_cfg_entry_block () :basic_block
  #{ /* cfun_cfg_entry_block */
((cfun && cfun->cfg)? ENTRY_BLOCK_PTR_FOR_FN(cfun):NULL)
  }#)

(defprimitive cfun_cfg_exit_block () :basic_block
  #{
  /* cfun_cfg_exit_block */
((cfun && cfun->cfg)? EXIT_BLOCK_PTR_FOR_FN(cfun):NULL)
  }#)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;; debug support
(defun debugfun_tree (dbgi :tree tr)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (let ( (out (get_field :dbgi_out dbgi))
	 )
    (if tr
	(code_chunk 
	 treeoutch
	 #{ /* $TREEOUTCH */ meltgc_ppout_tree ((melt_ptr_t)$OUT, 0, $TR); }#
	 )
      (add2out_strconst out "*nulltree*")
      )))
(register_tree_debug_fun debugfun_tree)

(defun output_tree_briefly (out :tree tr)
  (if (is_out out)
      (if tr
	  (code_chunk 
	   treeoutbchbr
	   #{ /* output_tree_briefly $TREEOUTBCHBR */ meltgc_ppout_tree_briefly ((melt_ptr_t)$OUT, 0, $TR) ; }#
	   )
	(add2out_strconst out "*nulltree*")
	)))

(defun output_tree (out :tree tr)
  (if (is_out out)
      (if tr
	  (code_chunk 
	   treeoutchbr
	   #{ /* output_tree $TREEOUTCHBR */ meltgc_ppout_tree ((melt_ptr_t)$OUT, 0, $TR) ; }#
	   )
	(add2out_strconst out "*nulltree*")
	)))

(defun dbgfun_tree_briefly (dbgi :tree tr)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (output_tree_briefly (get_field :dbgi_out dbgi) tr)
  )

(define dbg_tree_briefly 
  (clone_with_discriminant dbgfun_tree_briefly discr_debug_closure))

(defun dbgfun_tree_more (dbgi :tree tr)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (output_tree (get_field :dbgi_out dbgi) tr)
  )

(define dbg_tree_more 
  (clone_with_discriminant dbgfun_tree_more discr_debug_closure))

;;;;;;;;;;;;;;;;
(defun debugfun_basicblock (dbgi :basic_block bb)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (let ( (out (get_field :dbgi_out dbgi))
	 )
    (if bb
	(code_chunk
	 outbbchk
	 #{ /*$OUTBBCHK*/ meltgc_ppout_basicblock ((melt_ptr_t)$OUT, 0, $BB);}#
	 )
      (add2out_strconst out "*nullbasicblock*")
      )))
(register_basicblock_debug_fun debugfun_basicblock)

;;;;;;;;;;;;;;;;
(defun debugfun_edge (dbgi :edge ed)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (let ( (out (get_field :dbgi_out dbgi))
	 )
    (if ed
	(code_chunk
	 outedgechk
	 #{ /*$OUTEDGECHK*/ meltgc_out_edge ((melt_ptr_t)$OUT, $ED);}#
	 )
      (add2out_strconst out "*nulledge*")
      )))
(register_edge_debug_fun debugfun_edge)


;;;;;;;;;;;;;;;;
(defun debugfun_loop (dbgi :loop lo)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (let ( (out (get_field :dbgi_out dbgi))
	 )
    (if lo
	(code_chunk
	 outloopchk
	 #{ /*$OUTLOOPCHK*/ meltgc_out_loop ((melt_ptr_t)$OUT, $LO);}#
	 )
      (add2out_strconst out "*nullloop*")
      )))
(register_loop_debug_fun debugfun_loop)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEBUG OUTPUT 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;; boxed basicblock debug
(defun dbgout_boxbasicblock_method (self dbgi :long depth)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (let ( (dis (discrim self)) 
	 (out  (unsafe_get_field :dbgi_out dbgi)) ) 
    (add2out_strconst out " ?/")
    (if (is_a dis class_named) (add2out_string out (unsafe_get_field :named_name dis)))
    (add2out_strconst out "/{")
    (add2out_indentnl out (+i 1 depth))
    (ppstrbuf_basicblock out (+i 1 depth) (basicblock_content self))
    (add2out_strconst out "}/")
    (add2out_indentnl out depth)
    )
  )
(install_method discr_basic_block dbg_output dbgout_boxbasicblock_method)


;;;; boxed edge debug
(defun dbgout_boxedge_method (self dbgi :long depth)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (assert_msg "check self" (is_edge self) self)
  (let ( (dis (discrim self)) 
	 (out  (unsafe_get_field :dbgi_out dbgi)) ) 
    (add2out_strconst out " ?/")
    (if (is_a dis class_named) (add2out_string out (unsafe_get_field :named_name dis)))
    (add2out_strconst out "/[")
    (output_edge out (edge_content self))
    (add2out_strconst out "]/")
    (add2out_indentnl out depth)
    )
  )
(install_method discr_edge dbg_output dbgout_boxedge_method)


;;; boxed loop debug
(defun dbgout_boxloop_method (self dbgi :long depth)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (assert_msg "check self" (is_loop self) self)
  (let ( (dis (discrim self)) 
	 (out  (unsafe_get_field :dbgi_out dbgi)) ) 
    (add2out_strconst out " ?/")
    (if (is_a dis class_named) (add2out_string out (unsafe_get_field :named_name dis)))
    (add2out_strconst out "/[")
    (output_loop out (loop_content self))
    (add2out_strconst out "]/")
    (add2out_indentnl out depth)
    )
  )
(install_method discr_loop dbg_output dbgout_boxloop_method)


;;;; basicblockmap debug
(defun dbgout_mapbasicblock_method (self dbgi :long depth)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (assert_msg "check self" (is_mapbasicblock self) self)
  (let ( (dis (discrim self)) 
	 (:long mapcount (mapbasicblock_count self))
	 (out  (unsafe_get_field :dbgi_out dbgi)) 
	 (aux (mapbasicblock_aux self))
	 ) 
    (add2out_strconst out " !bbmap.")
    (if (is_a dis class_named) (add2out_string out (unsafe_get_field :named_name dis)))
    (add2out_strconst out "/")
    (add2out_longdec out mapcount)
    (add2out_strconst out "!{")
    (if (and aux (<=i depth 1))
	(progn
	  (add2out out " aux:")
	  (dbg_out aux dbgi (+i depth 3))))
    (foreach_mapbasicblock
     (self)
     (:basic_block bbatt :value bbval)
     (add2out_indentnl out (+i depth 1))
     (add2out_strconst out "*")
     (ppstrbuf_basicblock out (+i depth 1) bbatt)
     (add2out_strconst out " == ")
     (dbg_out bbval dbgi (+i depth 2))
     )
    (add2out_strconst out "}!")
    (add2out_indentnl out depth)
    ))
(install_method discr_map_basic_blocks dbg_output dbgout_mapbasicblock_method)




;;;; edgemap debug
(defun dbgout_mapedge_method (self dbgi :long depth)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information) dbgi)
  (assert_msg "check self" (is_mapedge self) self)
  (let ( (dis (discrim self)) 
	 (:long mapcount (mapedge_count self))
	 (out  (unsafe_get_field :dbgi_out dbgi)) 
	 (aux (mapedge_aux self))
	 ) 
    (add2out_strconst out " !edgemap.")
    (if (is_a dis class_named) (add2out_string out (unsafe_get_field :named_name dis)))
    (add2out_strconst out "/")
    (add2out_longdec out mapcount)
    (add2out_strconst out "!{")
    (if (and aux (<=i depth 1))
	(progn
	  (add2out out " aux:")
	  (dbg_out aux dbgi (+i depth 3))))
    (foreach_mapedge
     (self)
     (:edge edatt :value bbval)
     (add2out_indentnl out (+i depth 1))
     (add2out_strconst out "*")
     (output_edge out edatt)
     (add2out_strconst out " == ")
     (dbg_out bbval dbgi (+i depth 2))
     )
    (add2out_strconst out "}!")
    (add2out_indentnl out depth)
    ))
(install_method discr_map_edges dbg_output dbgout_mapedge_method)


(defun read_arg_list (locs :cstring argname)
  :doc #{If plugin argument $ARGNAME is provided, read it into a list located thru $LOCS, or else nil.}#
  (debug "read_arg_list argname=" argname)
  (let ( (:cstring sarg (melt_argument argname))
	 (argstr (if sarg (constant_box sarg)))
	 (arglist (if argstr (read_strv_loc argstr locs)))
	 )
    (debug "read_arg_list result arglist=" arglist)
    (return arglist)
))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(export_values
;; in alphanumerical order
 ==bb
 ==e
 basicblock_content
 basicblock_gimpleseq
 basicblock_index
 basicblock_nb_pred
 basicblock_nb_succ
 basicblock_phinodes
 basicblock_single_succ 
 basicblock_nth_pred_edge
 basicblock_nth_succ_edge
 bb_dominator_iterator
 bb_post_dominator_iterator
 cfun_cfg_entry_block
 cfun_cfg_exit_block
 cfun_decl
 cfun_has_cfg
 cfun_nonlocal_goto_save_area
 cfun_static_chain_decl
 dbg_tree_briefly
 dbg_tree_more
 debug_dominance_info
 debug_post_dominance_info
 dominated_by_bb_iterator
 dominated_by_other
 dominated_by_other
 each_bb_cfun
 each_bb_current_fun
 each_cgraph_fun_body
 each_cgraph_fun_call_flow_graph
 each_cgraph_fun_entryblock
 each_cgraph_pushed_cfun
 each_local_decl_cfun
 each_param_in_fundecl
 eachgimple_in_basicblock
 eachgimplephi_in_basicblock
 edge_content
 edge_dest_bb
 edge_for_false_value
 edge_for_true_value 
 edge_src_bb
 foreach_basicblock_succ_edge
 foreach_edge_bb_preds
 foreach_edge_bb_succs
 foreach_field_in_record_type
 foreach_loop_exit_edges
 foreach_mapbasicblock
 foreach_mapedge
 foreach_maploop
 foreach_superloop
 get_immediate_dominator
 get_immediate_post_dominator
 has_cfun
 install_melt_gcc_pass
 install_melt_pass_in_gcc
 is_basicblock
 is_edge
 is_loop
 is_mapbasicblock 
 is_mapedge
 is_maploop
 isnull_basicblock
 loop_body_tuple
 loop_can_be_parallel
 loop_content
 loop_depth
 loop_exit_edges_tuple
 loop_header
 loop_index_number
 loop_inner
 loop_latch
 main_input_filename
 make_basicblock
 make_edge
 make_loop
 make_mapbasicblock
 make_mapedge
 make_maploop
 mapbasicblock_aux
 mapbasicblock_auxput
 mapbasicblock_count
 mapbasicblock_get
 mapbasicblock_nth_attr
 mapbasicblock_nth_val 
 mapbasicblock_put
 mapbasicblock_remove  
 mapbasicblock_size
 mapedge_aux 
 mapedge_auxput 
 mapedge_count
 mapedge_get
 mapedge_nth_attr
 mapedge_nth_val
 mapedge_put
 mapedge_remove
 mapedge_size
 maploop_count
 maploop_get
 maploop_nth_attr
 maploop_nth_val
 maploop_put
 maploop_remove
 maploop_size
 notnull_basicblock
 null_basicblock
 null_edge
 number_of_loops
 output_edge
 output_loop
 output_tree
 output_tree_briefly
 post_dominated_by_other
 post_dominated_by_other
 ppstrbuf_basicblock 
 ppstrbuf_gimple
 ppstrbuf_gimple_seq
 ppstrbuf_tree
 read_arg_list
 superloop_at_depth
 superloop_tuple
 with_cfun_decl
 )

(export_class
 class_analysis_state
)
;; eof libmelt-ana-base.melt