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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX XX
XX BasicBlock XX
XX XX
XX XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/
#include "jitpch.h"
#ifdef _MSC_VER
#pragma hdrstop
#endif
#if MEASURE_BLOCK_SIZE
/* static */
size_t BasicBlock::s_Size;
/* static */
size_t BasicBlock::s_Count;
#endif // MEASURE_BLOCK_SIZE
#ifdef DEBUG
// The max # of tree nodes in any BB
/* static */
unsigned BasicBlock::s_nMaxTrees;
#endif // DEBUG
#ifdef DEBUG
flowList* ShuffleHelper(unsigned hash, flowList* res)
{
flowList* head = res;
for (flowList *prev = nullptr; res != nullptr; prev = res, res = res->flNext)
{
unsigned blkHash = (hash ^ (res->flBlock->bbNum << 16) ^ res->flBlock->bbNum);
if (((blkHash % 1879) & 1) && prev != nullptr)
{
// Swap res with head.
prev->flNext = head;
jitstd::swap(head->flNext, res->flNext);
jitstd::swap(head, res);
}
}
return head;
}
unsigned SsaStressHashHelper()
{
// hash = 0: turned off, hash = 1: use method hash, hash = *: use custom hash.
unsigned hash = JitConfig.JitSsaStress();
if (hash == 0)
{
return hash;
}
if (hash == 1)
{
return JitTls::GetCompiler()->info.compMethodHash();
}
return ((hash >> 16) == 0) ? ((hash << 16) | hash) : hash;
}
#endif
EHSuccessorIterPosition::EHSuccessorIterPosition(Compiler* comp, BasicBlock* block)
: m_remainingRegSuccs(block->NumSucc(comp)), m_curRegSucc(nullptr), m_curTry(comp->ehGetBlockExnFlowDsc(block))
{
// If "block" is a "leave helper" block (the empty BBJ_ALWAYS block that pairs with a
// preceding BBJ_CALLFINALLY block to implement a "leave" IL instruction), then no exceptions
// can occur within it, so clear m_curTry if it's non-null.
if (m_curTry != nullptr)
{
BasicBlock* beforeBlock = block->bbPrev;
if (beforeBlock != nullptr && beforeBlock->isBBCallAlwaysPair())
{
m_curTry = nullptr;
}
}
if (m_curTry == nullptr && m_remainingRegSuccs > 0)
{
// Examine the successors to see if any are the start of try blocks.
FindNextRegSuccTry(comp, block);
}
}
void EHSuccessorIterPosition::FindNextRegSuccTry(Compiler* comp, BasicBlock* block)
{
assert(m_curTry == nullptr);
// Must now consider the next regular successor, if any.
while (m_remainingRegSuccs > 0)
{
m_remainingRegSuccs--;
m_curRegSucc = block->GetSucc(m_remainingRegSuccs, comp);
if (comp->bbIsTryBeg(m_curRegSucc))
{
assert(m_curRegSucc->hasTryIndex()); // Since it is a try begin.
unsigned newTryIndex = m_curRegSucc->getTryIndex();
// If the try region started by "m_curRegSucc" (represented by newTryIndex) contains m_block,
// we've already yielded its handler, as one of the EH handler successors of m_block itself.
if (comp->bbInExnFlowRegions(newTryIndex, block))
{
continue;
}
// Otherwise, consider this try.
m_curTry = comp->ehGetDsc(newTryIndex);
break;
}
}
}
void EHSuccessorIterPosition::Advance(Compiler* comp, BasicBlock* block)
{
assert(m_curTry != nullptr);
if (m_curTry->ebdEnclosingTryIndex != EHblkDsc::NO_ENCLOSING_INDEX)
{
m_curTry = comp->ehGetDsc(m_curTry->ebdEnclosingTryIndex);
// If we've gone over into considering try's containing successors,
// then the enclosing try must have the successor as its first block.
if (m_curRegSucc == nullptr || m_curTry->ebdTryBeg == m_curRegSucc)
{
return;
}
// Otherwise, give up, try the next regular successor.
m_curTry = nullptr;
}
else
{
m_curTry = nullptr;
}
// We've exhausted all try blocks.
// See if there are any remaining regular successors that start try blocks.
FindNextRegSuccTry(comp, block);
}
BasicBlock* EHSuccessorIterPosition::Current(Compiler* comp, BasicBlock* block)
{
assert(m_curTry != nullptr);
return m_curTry->ExFlowBlock();
}
flowList* Compiler::BlockPredsWithEH(BasicBlock* blk)
{
BlockToFlowListMap* ehPreds = GetBlockToEHPreds();
flowList* res;
if (ehPreds->Lookup(blk, &res))
{
return res;
}
res = blk->bbPreds;
unsigned tryIndex;
if (bbIsExFlowBlock(blk, &tryIndex))
{
// Find the first block of the try.
EHblkDsc* ehblk = ehGetDsc(tryIndex);
BasicBlock* tryStart = ehblk->ebdTryBeg;
for (flowList* tryStartPreds = tryStart->bbPreds; tryStartPreds != nullptr;
tryStartPreds = tryStartPreds->flNext)
{
res = new (this, CMK_FlowList) flowList(tryStartPreds->flBlock, res);
#if MEASURE_BLOCK_SIZE
genFlowNodeCnt += 1;
genFlowNodeSize += sizeof(flowList);
#endif // MEASURE_BLOCK_SIZE
}
// Now add all blocks handled by this handler (except for second blocks of BBJ_CALLFINALLY/BBJ_ALWAYS pairs;
// these cannot cause transfer to the handler...)
BasicBlock* prevBB = nullptr;
// TODO-Throughput: It would be nice if we could iterate just over the blocks in the try, via
// something like:
// for (BasicBlock* bb = ehblk->ebdTryBeg; bb != ehblk->ebdTryLast->bbNext; bb = bb->bbNext)
// (plus adding in any filter blocks outside the try whose exceptions are handled here).
// That doesn't work, however: funclets have caused us to sometimes split the body of a try into
// more than one sequence of contiguous blocks. We need to find a better way to do this.
for (BasicBlock *bb = fgFirstBB; bb != nullptr; prevBB = bb, bb = bb->bbNext)
{
if (bbInExnFlowRegions(tryIndex, bb) && (prevBB == nullptr || !prevBB->isBBCallAlwaysPair()))
{
res = new (this, CMK_FlowList) flowList(bb, res);
#if MEASURE_BLOCK_SIZE
genFlowNodeCnt += 1;
genFlowNodeSize += sizeof(flowList);
#endif // MEASURE_BLOCK_SIZE
}
}
#ifdef DEBUG
unsigned hash = SsaStressHashHelper();
if (hash != 0)
{
res = ShuffleHelper(hash, res);
}
#endif // DEBUG
ehPreds->Set(blk, res);
}
return res;
}
#ifdef DEBUG
//------------------------------------------------------------------------
// dspBlockILRange(): Display the block's IL range as [XXX...YYY), where XXX and YYY might be "???" for BAD_IL_OFFSET.
//
void BasicBlock::dspBlockILRange() const
{
if (bbCodeOffs != BAD_IL_OFFSET)
{
printf("[%03X..", bbCodeOffs);
}
else
{
printf("[???"
"..");
}
if (bbCodeOffsEnd != BAD_IL_OFFSET)
{
// brace-matching editor workaround for following line: (
printf("%03X)", bbCodeOffsEnd);
}
else
{
// brace-matching editor workaround for following line: (
printf("???"
")");
}
}
//------------------------------------------------------------------------
// dspFlags: Print out the block's flags
//
void BasicBlock::dspFlags()
{
if (bbFlags & BBF_VISITED)
{
printf("v ");
}
if (bbFlags & BBF_MARKED)
{
printf("m ");
}
if (bbFlags & BBF_CHANGED)
{
printf("! ");
}
if (bbFlags & BBF_REMOVED)
{
printf("del ");
}
if (bbFlags & BBF_DONT_REMOVE)
{
printf("keep ");
}
if (bbFlags & BBF_IMPORTED)
{
printf("i ");
}
if (bbFlags & BBF_INTERNAL)
{
printf("internal ");
}
if (bbFlags & BBF_FAILED_VERIFICATION)
{
printf("failV ");
}
if (bbFlags & BBF_TRY_BEG)
{
printf("try ");
}
if (bbFlags & BBF_NEEDS_GCPOLL)
{
printf("poll ");
}
if (bbFlags & BBF_RUN_RARELY)
{
printf("rare ");
}
if (bbFlags & BBF_LOOP_HEAD)
{
printf("Loop ");
}
if (bbFlags & BBF_LOOP_CALL0)
{
printf("Loop0 ");
}
if (bbFlags & BBF_LOOP_CALL1)
{
printf("Loop1 ");
}
if (bbFlags & BBF_HAS_LABEL)
{
printf("label ");
}
if (bbFlags & BBF_JMP_TARGET)
{
printf("target ");
}
if (bbFlags & BBF_HAS_JMP)
{
printf("jmp ");
}
if (bbFlags & BBF_GC_SAFE_POINT)
{
printf("gcsafe ");
}
if (bbFlags & BBF_FUNCLET_BEG)
{
printf("flet ");
}
if (bbFlags & BBF_HAS_IDX_LEN)
{
printf("idxlen ");
}
if (bbFlags & BBF_HAS_NEWARRAY)
{
printf("new[] ");
}
if (bbFlags & BBF_HAS_NEWOBJ)
{
printf("newobj ");
}
#if FEATURE_EH_FUNCLETS && defined(_TARGET_ARM_)
if (bbFlags & BBF_FINALLY_TARGET)
{
printf("ftarget ");
}
#endif // FEATURE_EH_FUNCLETS && defined(_TARGET_ARM_)
if (bbFlags & BBF_BACKWARD_JUMP)
{
printf("bwd ");
}
if (bbFlags & BBF_RETLESS_CALL)
{
printf("retless ");
}
if (bbFlags & BBF_LOOP_PREHEADER)
{
printf("LoopPH ");
}
if (bbFlags & BBF_COLD)
{
printf("cold ");
}
if (bbFlags & BBF_PROF_WEIGHT)
{
printf("IBC ");
}
if (bbFlags & BBF_IS_LIR)
{
printf("LIR ");
}
if (bbFlags & BBF_KEEP_BBJ_ALWAYS)
{
printf("KEEP ");
}
if (bbFlags & BBF_CLONED_FINALLY_BEGIN)
{
printf("cfb ");
}
if (bbFlags & BBF_CLONED_FINALLY_END)
{
printf("cfe ");
}
}
/*****************************************************************************
*
* Display the bbPreds basic block list (the block predecessors).
* Returns the number of characters printed.
*/
unsigned BasicBlock::dspPreds()
{
unsigned count = 0;
for (flowList* pred = bbPreds; pred != nullptr; pred = pred->flNext)
{
if (count != 0)
{
printf(",");
count += 1;
}
printf(FMT_BB, pred->flBlock->bbNum);
count += 4;
// Account for %02u only handling 2 digits, but we can display more than that.
unsigned digits = CountDigits(pred->flBlock->bbNum);
if (digits > 2)
{
count += digits - 2;
}
// Does this predecessor have an interesting dup count? If so, display it.
if (pred->flDupCount > 1)
{
printf("(%u)", pred->flDupCount);
count += 2 + CountDigits(pred->flDupCount);
}
}
return count;
}
/*****************************************************************************
*
* Display the bbCheapPreds basic block list (the block predecessors).
* Returns the number of characters printed.
*/
unsigned BasicBlock::dspCheapPreds()
{
unsigned count = 0;
for (BasicBlockList* pred = bbCheapPreds; pred != nullptr; pred = pred->next)
{
if (count != 0)
{
printf(",");
count += 1;
}
printf(FMT_BB, pred->block->bbNum);
count += 4;
// Account for %02u only handling 2 digits, but we can display more than that.
unsigned digits = CountDigits(pred->block->bbNum);
if (digits > 2)
{
count += digits - 2;
}
}
return count;
}
/*****************************************************************************
*
* Display the basic block successors.
* Returns the count of successors.
*/
unsigned BasicBlock::dspSuccs(Compiler* compiler)
{
unsigned numSuccs = NumSucc(compiler);
unsigned count = 0;
for (unsigned i = 0; i < numSuccs; i++)
{
printf("%s", (count == 0) ? "" : ",");
printf(FMT_BB, GetSucc(i, compiler)->bbNum);
count++;
}
return count;
}
// Display a compact representation of the bbJumpKind, that is, where this block branches.
// This is similar to code in Compiler::fgTableDispBasicBlock(), but doesn't have that code's requirements to align
// things strictly.
void BasicBlock::dspJumpKind()
{
switch (bbJumpKind)
{
case BBJ_EHFINALLYRET:
printf(" (finret)");
break;
case BBJ_EHFILTERRET:
printf(" (fltret)");
break;
case BBJ_EHCATCHRET:
printf(" -> " FMT_BB " (cret)", bbJumpDest->bbNum);
break;
case BBJ_THROW:
printf(" (throw)");
break;
case BBJ_RETURN:
printf(" (return)");
break;
case BBJ_NONE:
// For fall-through blocks, print nothing.
break;
case BBJ_ALWAYS:
if (bbFlags & BBF_KEEP_BBJ_ALWAYS)
{
printf(" -> " FMT_BB " (ALWAYS)", bbJumpDest->bbNum);
}
else
{
printf(" -> " FMT_BB " (always)", bbJumpDest->bbNum);
}
break;
case BBJ_LEAVE:
printf(" -> " FMT_BB " (leave)", bbJumpDest->bbNum);
break;
case BBJ_CALLFINALLY:
printf(" -> " FMT_BB " (callf)", bbJumpDest->bbNum);
break;
case BBJ_COND:
printf(" -> " FMT_BB " (cond)", bbJumpDest->bbNum);
break;
case BBJ_SWITCH:
printf(" ->");
unsigned jumpCnt;
jumpCnt = bbJumpSwt->bbsCount;
BasicBlock** jumpTab;
jumpTab = bbJumpSwt->bbsDstTab;
do
{
printf("%c" FMT_BB, (jumpTab == bbJumpSwt->bbsDstTab) ? ' ' : ',', (*jumpTab)->bbNum);
} while (++jumpTab, --jumpCnt);
printf(" (switch)");
break;
default:
unreached();
break;
}
}
void BasicBlock::dspBlockHeader(Compiler* compiler,
bool showKind /*= true*/,
bool showFlags /*= false*/,
bool showPreds /*= true*/)
{
printf(FMT_BB " ", bbNum);
dspBlockILRange();
if (showKind)
{
dspJumpKind();
}
if (showPreds)
{
printf(", preds={");
if (compiler->fgCheapPredsValid)
{
dspCheapPreds();
}
else
{
dspPreds();
}
printf("} succs={");
dspSuccs(compiler);
printf("}");
}
if (showFlags)
{
const unsigned lowFlags = (unsigned)bbFlags;
const unsigned highFlags = (unsigned)(bbFlags >> 32);
printf(" flags=0x%08x.%08x: ", highFlags, lowFlags);
dspFlags();
}
printf("\n");
}
const char* BasicBlock::dspToString(int blockNumPadding /* = 2*/)
{
static char buffers[3][64]; // static array of 3 to allow 3 concurrent calls in one printf()
static int nextBufferIndex = 0;
auto& buffer = buffers[nextBufferIndex];
nextBufferIndex = (nextBufferIndex + 1) % _countof(buffers);
_snprintf_s(buffer, _countof(buffer), _countof(buffer), FMT_BB "%*s [%04u]", bbNum, blockNumPadding, "", bbID);
return buffer;
}
#endif // DEBUG
// Allocation function for MemoryPhiArg.
void* BasicBlock::MemoryPhiArg::operator new(size_t sz, Compiler* comp)
{
return comp->getAllocator(CMK_MemoryPhiArg).allocate<char>(sz);
}
//------------------------------------------------------------------------
// CloneBlockState: Try to populate `to` block with a copy of `from` block's statements, replacing
// uses of local `varNum` with IntCns `varVal`.
//
// Arguments:
// compiler - Jit compiler instance
// to - New/empty block to copy statements into
// from - Block to copy statements from
// varNum - lclVar uses with lclNum `varNum` will be replaced; can be ~0 to indicate no replacement.
// varVal - If replacing uses of `varNum`, replace them with int constants with value `varVal`.
//
// Return Value:
// Cloning may fail because this routine uses `gtCloneExpr` for cloning and it can't handle all
// IR nodes. If cloning of any statement fails, `false` will be returned and block `to` may be
// partially populated. If cloning of all statements succeeds, `true` will be returned and
// block `to` will be fully populated.
bool BasicBlock::CloneBlockState(
Compiler* compiler, BasicBlock* to, const BasicBlock* from, unsigned varNum, int varVal)
{
assert(to->bbTreeList == nullptr);
to->bbFlags = from->bbFlags;
to->bbWeight = from->bbWeight;
BlockSetOps::AssignAllowUninitRhs(compiler, to->bbReach, from->bbReach);
to->copyEHRegion(from);
to->bbCatchTyp = from->bbCatchTyp;
to->bbRefs = from->bbRefs;
to->bbStkTempsIn = from->bbStkTempsIn;
to->bbStkTempsOut = from->bbStkTempsOut;
to->bbStkDepth = from->bbStkDepth;
to->bbCodeOffs = from->bbCodeOffs;
to->bbCodeOffsEnd = from->bbCodeOffsEnd;
VarSetOps::AssignAllowUninitRhs(compiler, to->bbScope, from->bbScope);
to->bbNatLoopNum = from->bbNatLoopNum;
#ifdef DEBUG
to->bbLoopNum = from->bbLoopNum;
to->bbTgtStkDepth = from->bbTgtStkDepth;
#endif // DEBUG
for (GenTreeStmt* fromStmt = from->firstStmt(); fromStmt != nullptr; fromStmt = fromStmt->getNextStmt())
{
auto newExpr = compiler->gtCloneExpr(fromStmt->gtStmtExpr, 0, varNum, varVal);
if (!newExpr)
{
// gtCloneExpr doesn't handle all opcodes, so may fail to clone a statement.
// When that happens, it returns nullptr; abandon the rest of this block and
// return `false` to the caller to indicate that cloning was unsuccessful.
return false;
}
compiler->fgInsertStmtAtEnd(to, compiler->fgNewStmtFromTree(newExpr));
}
return true;
}
// LIR helpers
void BasicBlock::MakeLIR(GenTree* firstNode, GenTree* lastNode)
{
assert(!IsLIR());
assert((firstNode == nullptr) == (lastNode == nullptr));
assert((firstNode == lastNode) || firstNode->Precedes(lastNode));
m_firstNode = firstNode;
m_lastNode = lastNode;
bbFlags |= BBF_IS_LIR;
}
bool BasicBlock::IsLIR()
{
const bool isLIR = (bbFlags & BBF_IS_LIR) != 0;
assert((bbTreeList == nullptr) || ((isLIR) == !bbTreeList->IsStatement()));
return isLIR;
}
//------------------------------------------------------------------------
// firstStmt: Returns the first statement in the block
//
// Arguments:
// None.
//
// Return Value:
// The first statement in the block's bbTreeList.
//
GenTreeStmt* BasicBlock::firstStmt() const
{
if (bbTreeList == nullptr)
{
return nullptr;
}
return bbTreeList->AsStmt();
}
//------------------------------------------------------------------------
// lastStmt: Returns the last statement in the block
//
// Arguments:
// None.
//
// Return Value:
// The last statement in the block's bbTreeList.
//
GenTreeStmt* BasicBlock::lastStmt() const
{
if (bbTreeList == nullptr)
{
return nullptr;
}
GenTree* result = bbTreeList->gtPrev;
assert(result && result->gtNext == nullptr);
return result->AsStmt();
}
//------------------------------------------------------------------------
// BasicBlock::firstNode: Returns the first node in the block.
//
GenTree* BasicBlock::firstNode()
{
return IsLIR() ? bbTreeList : Compiler::fgGetFirstNode(firstStmt()->gtStmtExpr);
}
//------------------------------------------------------------------------
// BasicBlock::lastNode: Returns the last node in the block.
//
GenTree* BasicBlock::lastNode()
{
return IsLIR() ? m_lastNode : lastStmt()->gtStmtExpr;
}
//------------------------------------------------------------------------
// GetUniquePred: Returns the unique predecessor of a block, if one exists.
// The predecessor lists must be accurate.
//
// Arguments:
// None.
//
// Return Value:
// The unique predecessor of a block, or nullptr if there is no unique predecessor.
//
// Notes:
// If the first block has a predecessor (which it may have, if it is the target of
// a backedge), we never want to consider it "unique" because the prolog is an
// implicit predecessor.
BasicBlock* BasicBlock::GetUniquePred(Compiler* compiler)
{
if ((bbPreds == nullptr) || (bbPreds->flNext != nullptr) || (this == compiler->fgFirstBB))
{
return nullptr;
}
else
{
return bbPreds->flBlock;
}
}
//------------------------------------------------------------------------
// GetUniqueSucc: Returns the unique successor of a block, if one exists.
// Only considers BBJ_ALWAYS and BBJ_NONE block types.
//
// Arguments:
// None.
//
// Return Value:
// The unique successor of a block, or nullptr if there is no unique successor.
BasicBlock* BasicBlock::GetUniqueSucc()
{
if (bbJumpKind == BBJ_ALWAYS)
{
return bbJumpDest;
}
else if (bbJumpKind == BBJ_NONE)
{
return bbNext;
}
else
{
return nullptr;
}
}
// Static vars.
BasicBlock::MemoryPhiArg* BasicBlock::EmptyMemoryPhiDef = (BasicBlock::MemoryPhiArg*)0x1;
unsigned JitPtrKeyFuncs<BasicBlock>::GetHashCode(const BasicBlock* ptr)
{
#ifdef DEBUG
unsigned hash = SsaStressHashHelper();
if (hash != 0)
{
return (hash ^ (ptr->bbNum << 16) ^ ptr->bbNum);
}
#endif
return ptr->bbNum;
}
bool BasicBlock::isEmpty()
{
if (!IsLIR())
{
return (this->FirstNonPhiDef() == nullptr);
}
for (GenTree* node : LIR::AsRange(this).NonPhiNodes())
{
if (node->OperGet() != GT_IL_OFFSET)
{
return false;
}
}
return true;
}
GenTreeStmt* BasicBlock::FirstNonPhiDef()
{
GenTreeStmt* stmt = firstStmt();
if (stmt == nullptr)
{
return nullptr;
}
GenTree* tree = stmt->gtStmtExpr;
while ((tree->OperGet() == GT_ASG && tree->gtOp.gtOp2->OperGet() == GT_PHI) ||
(tree->OperGet() == GT_STORE_LCL_VAR && tree->gtOp.gtOp1->OperGet() == GT_PHI))
{
stmt = stmt->getNextStmt();
if (stmt == nullptr)
{
return nullptr;
}
tree = stmt->gtStmtExpr;
}
return stmt;
}
GenTreeStmt* BasicBlock::FirstNonPhiDefOrCatchArgAsg()
{
GenTreeStmt* stmt = FirstNonPhiDef();
if (stmt == nullptr)
{
return nullptr;
}
GenTree* tree = stmt->gtStmtExpr;
if ((tree->OperGet() == GT_ASG && tree->gtOp.gtOp2->OperGet() == GT_CATCH_ARG) ||
(tree->OperGet() == GT_STORE_LCL_VAR && tree->gtOp.gtOp1->OperGet() == GT_CATCH_ARG))
{
stmt = stmt->getNextStmt();
}
return stmt;
}
/*****************************************************************************
*
* Mark a block as rarely run, we also don't want to have a loop in a
* rarely run block, and we set it's weight to zero.
*/
void BasicBlock::bbSetRunRarely()
{
setBBWeight(BB_ZERO_WEIGHT);
if (bbWeight == BB_ZERO_WEIGHT)
{
bbFlags |= BBF_RUN_RARELY; // This block is never/rarely run
}
}
/*****************************************************************************
*
* Can a BasicBlock be inserted after this without altering the flowgraph
*/
bool BasicBlock::bbFallsThrough()
{
switch (bbJumpKind)
{
case BBJ_THROW:
case BBJ_EHFINALLYRET:
case BBJ_EHFILTERRET:
case BBJ_EHCATCHRET:
case BBJ_RETURN:
case BBJ_ALWAYS:
case BBJ_LEAVE:
case BBJ_SWITCH:
return false;
case BBJ_NONE:
case BBJ_COND:
return true;
case BBJ_CALLFINALLY:
return ((bbFlags & BBF_RETLESS_CALL) == 0);
default:
assert(!"Unknown bbJumpKind in bbFallsThrough()");
return true;
}
}
//------------------------------------------------------------------------
// NumSucc: Returns the count of block successors. See the declaration comment for details.
//
// Arguments:
// None.
//
// Return Value:
// Count of block successors.
//
unsigned BasicBlock::NumSucc()
{
switch (bbJumpKind)
{
case BBJ_THROW:
case BBJ_RETURN:
case BBJ_EHFINALLYRET:
case BBJ_EHFILTERRET:
return 0;
case BBJ_CALLFINALLY:
case BBJ_ALWAYS:
case BBJ_EHCATCHRET:
case BBJ_LEAVE:
case BBJ_NONE:
return 1;
case BBJ_COND:
if (bbJumpDest == bbNext)
{
return 1;
}
else
{
return 2;
}
case BBJ_SWITCH:
return bbJumpSwt->bbsCount;
default:
unreached();
}
}
//------------------------------------------------------------------------
// GetSucc: Returns the requested block successor. See the declaration comment for details.
//
// Arguments:
// i - index of successor to return. 0 <= i <= NumSucc().
//
// Return Value:
// Requested successor block
//
BasicBlock* BasicBlock::GetSucc(unsigned i)
{
assert(i < NumSucc()); // Index bounds check.
switch (bbJumpKind)
{
case BBJ_CALLFINALLY:
case BBJ_ALWAYS:
case BBJ_EHCATCHRET:
case BBJ_LEAVE:
return bbJumpDest;
case BBJ_NONE:
return bbNext;
case BBJ_COND:
if (i == 0)
{
return bbNext;
}
else
{
assert(i == 1);
return bbJumpDest;
}
case BBJ_SWITCH:
return bbJumpSwt->bbsDstTab[i];
default:
unreached();
}
}
//------------------------------------------------------------------------
// NumSucc: Returns the count of block successors. See the declaration comment for details.
//
// Arguments:
// comp - Compiler instance
//
// Return Value:
// Count of block successors.
//
unsigned BasicBlock::NumSucc(Compiler* comp)
{
assert(comp != nullptr);
switch (bbJumpKind)
{
case BBJ_THROW:
case BBJ_RETURN:
return 0;
case BBJ_EHFINALLYRET:
{
// The first block of the handler is labelled with the catch type.
BasicBlock* hndBeg = comp->fgFirstBlockOfHandler(this);
if (hndBeg->bbCatchTyp == BBCT_FINALLY)
{
return comp->fgNSuccsOfFinallyRet(this);
}
else
{
assert(hndBeg->bbCatchTyp == BBCT_FAULT); // We can only BBJ_EHFINALLYRET from FINALLY and FAULT.
// A FAULT block has no successors.
return 0;
}
}
case BBJ_CALLFINALLY:
case BBJ_ALWAYS:
case BBJ_EHCATCHRET:
case BBJ_EHFILTERRET:
case BBJ_LEAVE:
case BBJ_NONE:
return 1;
case BBJ_COND:
if (bbJumpDest == bbNext)
{
return 1;
}
else
{
return 2;
}
case BBJ_SWITCH:
{
Compiler::SwitchUniqueSuccSet sd = comp->GetDescriptorForSwitch(this);
return sd.numDistinctSuccs;
}
default:
unreached();
}
}
//------------------------------------------------------------------------
// GetSucc: Returns the requested block successor. See the declaration comment for details.
//
// Arguments:
// i - index of successor to return. 0 <= i <= NumSucc(comp).
// comp - Compiler instance
//
// Return Value:
// Requested successor block
//
BasicBlock* BasicBlock::GetSucc(unsigned i, Compiler* comp)
{
assert(comp != nullptr);
assert(i < NumSucc(comp)); // Index bounds check.
switch (bbJumpKind)
{
case BBJ_EHFILTERRET:
{
// Handler is the (sole) normal successor of the filter.
assert(comp->fgFirstBlockOfHandler(this) == bbJumpDest);
return bbJumpDest;
}
case BBJ_EHFINALLYRET:
// Note: the following call is expensive.
return comp->fgSuccOfFinallyRet(this, i);
case BBJ_CALLFINALLY:
case BBJ_ALWAYS:
case BBJ_EHCATCHRET:
case BBJ_LEAVE:
return bbJumpDest;
case BBJ_NONE:
return bbNext;
case BBJ_COND:
if (i == 0)
{
return bbNext;
}
else
{
assert(i == 1);
return bbJumpDest;
}
case BBJ_SWITCH:
{
Compiler::SwitchUniqueSuccSet sd = comp->GetDescriptorForSwitch(this);
assert(i < sd.numDistinctSuccs); // Range check.
return sd.nonDuplicates[i];
}
default:
unreached();
}
}
void BasicBlock::InitVarSets(Compiler* comp)
{
VarSetOps::AssignNoCopy(comp, bbVarUse, VarSetOps::MakeEmpty(comp));
VarSetOps::AssignNoCopy(comp, bbVarDef, VarSetOps::MakeEmpty(comp));
VarSetOps::AssignNoCopy(comp, bbLiveIn, VarSetOps::MakeEmpty(comp));
VarSetOps::AssignNoCopy(comp, bbLiveOut, VarSetOps::MakeEmpty(comp));
VarSetOps::AssignNoCopy(comp, bbScope, VarSetOps::MakeEmpty(comp));
bbMemoryUse = emptyMemoryKindSet;
bbMemoryDef = emptyMemoryKindSet;
bbMemoryLiveIn = emptyMemoryKindSet;
bbMemoryLiveOut = emptyMemoryKindSet;
}
// Returns true if the basic block ends with GT_JMP
bool BasicBlock::endsWithJmpMethod(Compiler* comp)
{
if (comp->compJmpOpUsed && (bbJumpKind == BBJ_RETURN) && (bbFlags & BBF_HAS_JMP))
{
GenTree* lastNode = this->lastNode();
assert(lastNode != nullptr);
return lastNode->OperGet() == GT_JMP;
}
return false;
}
// Returns true if the basic block ends with either
// i) GT_JMP or
// ii) tail call (implicit or explicit)
//
// Params:
// comp - Compiler instance
// fastTailCallsOnly - Only consider fast tail calls excluding tail calls via helper.
//
bool BasicBlock::endsWithTailCallOrJmp(Compiler* comp, bool fastTailCallsOnly /*=false*/)
{
GenTree* tailCall = nullptr;
bool tailCallsConvertibleToLoopOnly = false;
return endsWithJmpMethod(comp) ||
endsWithTailCall(comp, fastTailCallsOnly, tailCallsConvertibleToLoopOnly, &tailCall);
}
//------------------------------------------------------------------------------
// endsWithTailCall : Check if the block ends with a tail call.
//
// Arguments:
// comp - compiler instance
// fastTailCallsOnly - check for fast tail calls only
// tailCallsConvertibleToLoopOnly - check for tail calls convertible to loop only
// tailCall - a pointer to a tree that will be set to the call tree if the block
// ends with a tail call and will be set to nullptr otherwise.
//
// Return Value:
// true if the block ends with a tail call; false otherwise.
//
// Notes:
// At most one of fastTailCallsOnly and tailCallsConvertibleToLoopOnly flags can be true.
//
bool BasicBlock::endsWithTailCall(Compiler* comp,
bool fastTailCallsOnly,
bool tailCallsConvertibleToLoopOnly,
GenTree** tailCall)
{
assert(!fastTailCallsOnly || !tailCallsConvertibleToLoopOnly);
*tailCall = nullptr;
bool result = false;
// Is this a tail call?
// The reason for keeping this under RyuJIT is so as not to impact existing Jit32 x86 and arm
// targets.
if (comp->compTailCallUsed)
{
if (fastTailCallsOnly || tailCallsConvertibleToLoopOnly)
{
// Only fast tail calls or only tail calls convertible to loops
result = (bbFlags & BBF_HAS_JMP) && (bbJumpKind == BBJ_RETURN);
}
else
{
// Fast tail calls, tail calls convertible to loops, and tails calls dispatched via helper
result = (bbJumpKind == BBJ_THROW) || ((bbFlags & BBF_HAS_JMP) && (bbJumpKind == BBJ_RETURN));
}
if (result)
{
GenTree* lastNode = this->lastNode();
if (lastNode->OperGet() == GT_CALL)
{
GenTreeCall* call = lastNode->AsCall();
if (tailCallsConvertibleToLoopOnly)
{
result = call->IsTailCallConvertibleToLoop();
}
else if (fastTailCallsOnly)
{
result = call->IsFastTailCall();
}
else
{
result = call->IsTailCall();
}
if (result)
{
*tailCall = call;
}
}
else
{
result = false;
}
}
}
return result;
}
//------------------------------------------------------------------------------
// endsWithTailCallConvertibleToLoop : Check if the block ends with a tail call convertible to loop.
//
// Arguments:
// comp - compiler instance
// tailCall - a pointer to a tree that will be set to the call tree if the block
// ends with a tail call convertible to loop and will be set to nullptr otherwise.
//
// Return Value:
// true if the block ends with a tail call convertible to loop.
//
bool BasicBlock::endsWithTailCallConvertibleToLoop(Compiler* comp, GenTree** tailCall)
{
bool fastTailCallsOnly = false;
bool tailCallsConvertibleToLoopOnly = true;
return endsWithTailCall(comp, fastTailCallsOnly, tailCallsConvertibleToLoopOnly, tailCall);
}
/*****************************************************************************
*
* Allocate a basic block but don't append it to the current BB list.
*/
BasicBlock* Compiler::bbNewBasicBlock(BBjumpKinds jumpKind)
{
BasicBlock* block;
/* Allocate the block descriptor and zero it out */
assert(fgSafeBasicBlockCreation);
block = new (this, CMK_BasicBlock) BasicBlock;
#if MEASURE_BLOCK_SIZE
BasicBlock::s_Count += 1;
BasicBlock::s_Size += sizeof(*block);
#endif
#ifdef DEBUG
// fgLookupBB() is invalid until fgInitBBLookup() is called again.
fgBBs = (BasicBlock**)0xCDCD;
#endif
// TODO-Throughput: The following memset is pretty expensive - do something else?
// Note that some fields have to be initialized to 0 (like bbFPStateX87)
memset(block, 0, sizeof(*block));
// scopeInfo needs to be able to differentiate between blocks which
// correspond to some instrs (and so may have some LocalVarInfo
// boundaries), or have been inserted by the JIT
block->bbCodeOffs = BAD_IL_OFFSET;
block->bbCodeOffsEnd = BAD_IL_OFFSET;
#ifdef DEBUG
block->bbID = compBasicBlockID++;
#endif
/* Give the block a number, set the ancestor count and weight */
++fgBBcount;
if (compIsForInlining())
{
block->bbNum = ++impInlineInfo->InlinerCompiler->fgBBNumMax;
}
else
{
block->bbNum = ++fgBBNumMax;
}
if (compRationalIRForm)
{
block->bbFlags |= BBF_IS_LIR;
}
block->bbRefs = 1;
block->bbWeight = BB_UNITY_WEIGHT;
block->bbStkTempsIn = NO_BASE_TMP;
block->bbStkTempsOut = NO_BASE_TMP;
block->bbEntryState = nullptr;
/* Record the jump kind in the block */
block->bbJumpKind = jumpKind;
if (jumpKind == BBJ_THROW)
{
block->bbSetRunRarely();
}
#ifdef DEBUG
if (verbose)
{
printf("New Basic Block %s created.\n", block->dspToString());
}
#endif
// We will give all the blocks var sets after the number of tracked variables
// is determined and frozen. After that, if we dynamically create a basic block,
// we will initialize its var sets.
if (fgBBVarSetsInited)
{
VarSetOps::AssignNoCopy(this, block->bbVarUse, VarSetOps::MakeEmpty(this));
VarSetOps::AssignNoCopy(this, block->bbVarDef, VarSetOps::MakeEmpty(this));
VarSetOps::AssignNoCopy(this, block->bbLiveIn, VarSetOps::MakeEmpty(this));
VarSetOps::AssignNoCopy(this, block->bbLiveOut, VarSetOps::MakeEmpty(this));
VarSetOps::AssignNoCopy(this, block->bbScope, VarSetOps::MakeEmpty(this));
}
else
{
VarSetOps::AssignNoCopy(this, block->bbVarUse, VarSetOps::UninitVal());
VarSetOps::AssignNoCopy(this, block->bbVarDef, VarSetOps::UninitVal());
VarSetOps::AssignNoCopy(this, block->bbLiveIn, VarSetOps::UninitVal());
VarSetOps::AssignNoCopy(this, block->bbLiveOut, VarSetOps::UninitVal());
VarSetOps::AssignNoCopy(this, block->bbScope, VarSetOps::UninitVal());
}
block->bbMemoryUse = emptyMemoryKindSet;
block->bbMemoryDef = emptyMemoryKindSet;
block->bbMemoryLiveIn = emptyMemoryKindSet;
block->bbMemoryLiveOut = emptyMemoryKindSet;
for (MemoryKind memoryKind : allMemoryKinds())
{
block->bbMemorySsaPhiFunc[memoryKind] = nullptr;
block->bbMemorySsaNumIn[memoryKind] = 0;
block->bbMemorySsaNumOut[memoryKind] = 0;
}
// Make sure we reserve a NOT_IN_LOOP value that isn't a legal table index.
static_assert_no_msg(MAX_LOOP_NUM < BasicBlock::NOT_IN_LOOP);
block->bbNatLoopNum = BasicBlock::NOT_IN_LOOP;
return block;
}
//------------------------------------------------------------------------------
// DisplayStaticSizes: display various static sizes of the BasicBlock data structure.
//
// Arguments:
// fout - where to write the output
//
// Return Value:
// None
//
// Note: This function only does something if MEASURE_BLOCK_SIZE is defined, which it might
// be in private Release builds.
//
/* static */
void BasicBlock::DisplayStaticSizes(FILE* fout)
{
#if MEASURE_BLOCK_SIZE
BasicBlock* bbDummy = nullptr;
fprintf(fout, "\n");
fprintf(fout, "Offset / size of bbNext = %3u / %3u\n", offsetof(BasicBlock, bbNext),
sizeof(bbDummy->bbNext));
fprintf(fout, "Offset / size of bbPrev = %3u / %3u\n", offsetof(BasicBlock, bbPrev),
sizeof(bbDummy->bbPrev));
fprintf(fout, "Offset / size of bbFlags = %3u / %3u\n", offsetof(BasicBlock, bbFlags),
sizeof(bbDummy->bbFlags));
fprintf(fout, "Offset / size of bbNum = %3u / %3u\n", offsetof(BasicBlock, bbNum),
sizeof(bbDummy->bbNum));
fprintf(fout, "Offset / size of bbPostOrderNum = %3u / %3u\n", offsetof(BasicBlock, bbPostOrderNum),
sizeof(bbDummy->bbPostOrderNum));
fprintf(fout, "Offset / size of bbRefs = %3u / %3u\n", offsetof(BasicBlock, bbRefs),
sizeof(bbDummy->bbRefs));
fprintf(fout, "Offset / size of bbWeight = %3u / %3u\n", offsetof(BasicBlock, bbWeight),
sizeof(bbDummy->bbWeight));
fprintf(fout, "Offset / size of bbJumpKind = %3u / %3u\n", offsetof(BasicBlock, bbJumpKind),
sizeof(bbDummy->bbJumpKind));
fprintf(fout, "Offset / size of bbJumpOffs = %3u / %3u\n", offsetof(BasicBlock, bbJumpOffs),
sizeof(bbDummy->bbJumpOffs));
fprintf(fout, "Offset / size of bbJumpDest = %3u / %3u\n", offsetof(BasicBlock, bbJumpDest),
sizeof(bbDummy->bbJumpDest));
fprintf(fout, "Offset / size of bbJumpSwt = %3u / %3u\n", offsetof(BasicBlock, bbJumpSwt),
sizeof(bbDummy->bbJumpSwt));
fprintf(fout, "Offset / size of bbEntryState = %3u / %3u\n", offsetof(BasicBlock, bbEntryState),
sizeof(bbDummy->bbEntryState));
fprintf(fout, "Offset / size of bbStkTempsIn = %3u / %3u\n", offsetof(BasicBlock, bbStkTempsIn),
sizeof(bbDummy->bbStkTempsIn));
fprintf(fout, "Offset / size of bbStkTempsOut = %3u / %3u\n", offsetof(BasicBlock, bbStkTempsOut),
sizeof(bbDummy->bbStkTempsOut));
fprintf(fout, "Offset / size of bbTryIndex = %3u / %3u\n", offsetof(BasicBlock, bbTryIndex),
sizeof(bbDummy->bbTryIndex));
fprintf(fout, "Offset / size of bbHndIndex = %3u / %3u\n", offsetof(BasicBlock, bbHndIndex),
sizeof(bbDummy->bbHndIndex));
fprintf(fout, "Offset / size of bbCatchTyp = %3u / %3u\n", offsetof(BasicBlock, bbCatchTyp),
sizeof(bbDummy->bbCatchTyp));
fprintf(fout, "Offset / size of bbStkDepth = %3u / %3u\n", offsetof(BasicBlock, bbStkDepth),
sizeof(bbDummy->bbStkDepth));
fprintf(fout, "Offset / size of bbFPinVars = %3u / %3u\n", offsetof(BasicBlock, bbFPinVars),
sizeof(bbDummy->bbFPinVars));
fprintf(fout, "Offset / size of bbCheapPreds = %3u / %3u\n", offsetof(BasicBlock, bbCheapPreds),
sizeof(bbDummy->bbCheapPreds));
fprintf(fout, "Offset / size of bbPreds = %3u / %3u\n", offsetof(BasicBlock, bbPreds),
sizeof(bbDummy->bbPreds));
fprintf(fout, "Offset / size of bbReach = %3u / %3u\n", offsetof(BasicBlock, bbReach),
sizeof(bbDummy->bbReach));
fprintf(fout, "Offset / size of bbIDom = %3u / %3u\n", offsetof(BasicBlock, bbIDom),
sizeof(bbDummy->bbIDom));
fprintf(fout, "Offset / size of bbDfsNum = %3u / %3u\n", offsetof(BasicBlock, bbDfsNum),
sizeof(bbDummy->bbDfsNum));
fprintf(fout, "Offset / size of bbCodeOffs = %3u / %3u\n", offsetof(BasicBlock, bbCodeOffs),
sizeof(bbDummy->bbCodeOffs));
fprintf(fout, "Offset / size of bbCodeOffsEnd = %3u / %3u\n", offsetof(BasicBlock, bbCodeOffsEnd),
sizeof(bbDummy->bbCodeOffsEnd));
fprintf(fout, "Offset / size of bbVarUse = %3u / %3u\n", offsetof(BasicBlock, bbVarUse),
sizeof(bbDummy->bbVarUse));
fprintf(fout, "Offset / size of bbVarDef = %3u / %3u\n", offsetof(BasicBlock, bbVarDef),
sizeof(bbDummy->bbVarDef));
fprintf(fout, "Offset / size of bbLiveIn = %3u / %3u\n", offsetof(BasicBlock, bbLiveIn),
sizeof(bbDummy->bbLiveIn));
fprintf(fout, "Offset / size of bbLiveOut = %3u / %3u\n", offsetof(BasicBlock, bbLiveOut),
sizeof(bbDummy->bbLiveOut));
// Can't do bitfield bbMemoryUse, bbMemoryDef, bbMemoryLiveIn, bbMemoryLiveOut, bbMemoryHavoc
fprintf(fout, "Offset / size of bbMemorySsaPhiFunc = %3u / %3u\n", offsetof(BasicBlock, bbMemorySsaPhiFunc),
sizeof(bbDummy->bbMemorySsaPhiFunc));
fprintf(fout, "Offset / size of bbMemorySsaNumIn = %3u / %3u\n", offsetof(BasicBlock, bbMemorySsaNumIn),
sizeof(bbDummy->bbMemorySsaNumIn));
fprintf(fout, "Offset / size of bbMemorySsaNumOut = %3u / %3u\n", offsetof(BasicBlock, bbMemorySsaNumOut),
sizeof(bbDummy->bbMemorySsaNumOut));
fprintf(fout, "Offset / size of bbScope = %3u / %3u\n", offsetof(BasicBlock, bbScope),
sizeof(bbDummy->bbScope));
fprintf(fout, "Offset / size of bbCseGen = %3u / %3u\n", offsetof(BasicBlock, bbCseGen),
sizeof(bbDummy->bbCseGen));
#if ASSERTION_PROP
fprintf(fout, "Offset / size of bbAssertionGen = %3u / %3u\n", offsetof(BasicBlock, bbAssertionGen),
sizeof(bbDummy->bbAssertionGen));
#endif // ASSERTION_PROP
fprintf(fout, "Offset / size of bbCseIn = %3u / %3u\n", offsetof(BasicBlock, bbCseIn),
sizeof(bbDummy->bbCseIn));
#if ASSERTION_PROP
fprintf(fout, "Offset / size of bbAssertionIn = %3u / %3u\n", offsetof(BasicBlock, bbAssertionIn),
sizeof(bbDummy->bbAssertionIn));
#endif // ASSERTION_PROP
fprintf(fout, "Offset / size of bbCseOut = %3u / %3u\n", offsetof(BasicBlock, bbCseOut),
sizeof(bbDummy->bbCseOut));
#if ASSERTION_PROP
fprintf(fout, "Offset / size of bbAssertionOut = %3u / %3u\n", offsetof(BasicBlock, bbAssertionOut),
sizeof(bbDummy->bbAssertionOut));
#endif // ASSERTION_PROP
fprintf(fout, "Offset / size of bbEmitCookie = %3u / %3u\n", offsetof(BasicBlock, bbEmitCookie),
sizeof(bbDummy->bbEmitCookie));
#if FEATURE_EH_FUNCLETS && defined(_TARGET_ARM_)
fprintf(fout, "Offset / size of bbUnwindNopEmitCookie = %3u / %3u\n", offsetof(BasicBlock, bbUnwindNopEmitCookie),
sizeof(bbDummy->bbUnwindNopEmitCookie));
#endif // FEATURE_EH_FUNCLETS && defined(_TARGET_ARM_)
#ifdef VERIFIER
fprintf(fout, "Offset / size of bbStackIn = %3u / %3u\n", offsetof(BasicBlock, bbStackIn),
sizeof(bbDummy->bbStackIn));
fprintf(fout, "Offset / size of bbStackOut = %3u / %3u\n", offsetof(BasicBlock, bbStackOut),
sizeof(bbDummy->bbStackOut));
fprintf(fout, "Offset / size of bbTypesIn = %3u / %3u\n", offsetof(BasicBlock, bbTypesIn),
sizeof(bbDummy->bbTypesIn));
fprintf(fout, "Offset / size of bbTypesOut = %3u / %3u\n", offsetof(BasicBlock, bbTypesOut),
sizeof(bbDummy->bbTypesOut));
#endif // VERIFIER
#ifdef DEBUG
fprintf(fout, "Offset / size of bbLoopNum = %3u / %3u\n", offsetof(BasicBlock, bbLoopNum),
sizeof(bbDummy->bbLoopNum));
#endif // DEBUG
fprintf(fout, "Offset / size of bbNatLoopNum = %3u / %3u\n", offsetof(BasicBlock, bbNatLoopNum),
sizeof(bbDummy->bbNatLoopNum));
fprintf(fout, "\n");
fprintf(fout, "Size of BasicBlock = %3u\n", sizeof(BasicBlock));
#endif // MEASURE_BLOCK_SIZE
}
|