@@ -400,6 +400,10 @@ class BlockState {
400
400
// / Returns a *single* forwardable SILValue for the given LSLocation right
401
401
// / before the InsertPt instruction.
402
402
SILValue reduceValuesAtEndOfBlock (RLEContext &Ctx, LSLocation &L);
403
+
404
+ #ifndef NDEBUG
405
+ void dump (RLEContext &Ctx);
406
+ #endif
403
407
};
404
408
405
409
} // end anonymous namespace
@@ -477,6 +481,10 @@ class RLEContext {
477
481
// / walked, i.e. when the we generate the genset and killset.
478
482
llvm::DenseSet<SILBasicBlock *> BBWithLoads;
479
483
484
+ #ifndef NDEBUG
485
+ SILPrintContext printCtx;
486
+ #endif
487
+
480
488
public:
481
489
RLEContext (SILFunction *F, SILPassManager *PM, AliasAnalysis *AA,
482
490
TypeExpansionAnalysis *TE, PostOrderFunctionInfo *PO,
@@ -489,6 +497,8 @@ class RLEContext {
489
497
// / Entry point to redundant load elimination.
490
498
bool run ();
491
499
500
+ SILFunction *getFunction () const { return Fn; }
501
+
492
502
// / Use a set of ad hoc rules to tell whether we should run a pessimistic
493
503
// / one iteration data flow on the function.
494
504
ProcessKind getProcessFunctionKind (unsigned LoadCount, unsigned StoreCount);
@@ -714,6 +724,8 @@ bool BlockState::setupRLE(RLEContext &Ctx, SILInstruction *I, SILValue Mem) {
714
724
// forwardable values are recorded in the function.
715
725
//
716
726
RedundantLoads[I] = TheForwardingValue;
727
+
728
+ DEBUG (llvm::dbgs () << " FORWARD " << TheForwardingValue << " to" << *I);
717
729
return true ;
718
730
}
719
731
@@ -1065,9 +1077,11 @@ void BlockState::processInstructionWithKind(RLEContext &Ctx,
1065
1077
// that it and its operands cannot alias a load we have visited,
1066
1078
// invalidate that load.
1067
1079
if (Inst->mayWriteToMemory ()) {
1080
+ DEBUG (llvm::dbgs () << " WRITE " << *Inst);
1068
1081
processUnknownWriteInst (Ctx, Inst, Kind);
1069
1082
return ;
1070
1083
}
1084
+ DEBUG (llvm::dbgs () << " READ " << *Inst);
1071
1085
}
1072
1086
1073
1087
RLEContext::ProcessKind
@@ -1121,14 +1135,52 @@ getProcessFunctionKind(unsigned LoadCount, unsigned StoreCount) {
1121
1135
return ProcessKind::ProcessMultipleIterations;
1122
1136
}
1123
1137
1138
+ #ifndef NDEBUG
1139
+ void BlockState::dump (RLEContext &Ctx) {
1140
+ for (unsigned i = 0 ; i < LocationNum; ++i) {
1141
+ if (!isTrackingLocation (ForwardSetMax, i))
1142
+ continue ;
1143
+
1144
+ llvm::dbgs () << " Loc #" << i << " :" << (BBGenSet[i] ? " Gen" : " " )
1145
+ << (BBKillSet[i] ? " Kill" : " " );
1146
+ if (!ForwardSetIn.empty () && ForwardSetIn.test (i)) {
1147
+ llvm::dbgs () << " IN " ;
1148
+ ValueTableMap::const_iterator inIter = ForwardValIn.find (i);
1149
+ if (inIter != ForwardValIn.end ()) {
1150
+ if (SILValue base = Ctx.getValue (inIter->second ).getBase ())
1151
+ llvm::dbgs () << base;
1152
+ else
1153
+ llvm::dbgs () << " no base" ;
1154
+ }
1155
+ }
1156
+ if (!ForwardSetOut.empty () && ForwardSetOut.test (i)) {
1157
+ llvm::dbgs () << " OUT " ;
1158
+ ValueTableMap::const_iterator outIter = ForwardValOut.find (i);
1159
+ if (outIter != ForwardValOut.end ()) {
1160
+ if (SILValue base = Ctx.getValue (outIter->second ).getBase ())
1161
+ llvm::dbgs () << base;
1162
+ else
1163
+ llvm::dbgs () << " no base" ;
1164
+ }
1165
+ }
1166
+ llvm::dbgs () << " \n " ;
1167
+ }
1168
+ }
1169
+ #endif
1170
+
1124
1171
// ===----------------------------------------------------------------------===//
1125
1172
// RLEContext Implementation
1126
1173
// ===----------------------------------------------------------------------===//
1127
1174
1128
1175
RLEContext::RLEContext (SILFunction *F, SILPassManager *PM, AliasAnalysis *AA,
1129
1176
TypeExpansionAnalysis *TE, PostOrderFunctionInfo *PO,
1130
1177
EpilogueARCFunctionInfo *EAFI)
1131
- : Fn(F), PM(PM), AA(AA), TE(TE), PO(PO), EAFI(EAFI) {
1178
+ : Fn(F), PM(PM), AA(AA), TE(TE), PO(PO), EAFI(EAFI)
1179
+ #ifndef NDEBUG
1180
+ ,
1181
+ printCtx (llvm::dbgs(), /* Verbose=*/ false, /* Sorted=*/ true)
1182
+ #endif
1183
+ {
1132
1184
}
1133
1185
1134
1186
LSLocation &RLEContext::getLocation (const unsigned index) {
@@ -1306,6 +1358,10 @@ bool RLEContext::collectLocationValues(SILBasicBlock *BB, LSLocation &L,
1306
1358
1307
1359
void RLEContext::processBasicBlocksForGenKillSet () {
1308
1360
for (SILBasicBlock *BB : PO->getReversePostOrder ()) {
1361
+ DEBUG (llvm::dbgs () << " PROCESS " << printCtx.getID (BB)
1362
+ << " for Gen/Kill:\n " ;
1363
+ BB->print (llvm::dbgs (), printCtx));
1364
+
1309
1365
BlockState &S = getBlockState (BB);
1310
1366
1311
1367
// Compute the AvailSetMax at the beginning of the basic block.
@@ -1327,6 +1383,7 @@ void RLEContext::processBasicBlocksForGenKillSet() {
1327
1383
1328
1384
S.processInstructionWithKind (*this , &*I, RLEKind::ComputeAvailGenKillSet);
1329
1385
}
1386
+ DEBUG (S.dump (*this ));
1330
1387
}
1331
1388
}
1332
1389
@@ -1345,6 +1402,8 @@ void RLEContext::processBasicBlocksWithGenKillSet() {
1345
1402
}
1346
1403
while (!WorkList.empty ()) {
1347
1404
SILBasicBlock *BB = WorkList.pop_back_val ();
1405
+ DEBUG (llvm::dbgs () << " PROCESS " << printCtx.getID (BB)
1406
+ << " with Gen/Kill.\n " );
1348
1407
HandledBBs.erase (BB);
1349
1408
1350
1409
// Intersection.
@@ -1361,11 +1420,15 @@ void RLEContext::processBasicBlocksWithGenKillSet() {
1361
1420
WorkList.push_back (X);
1362
1421
}
1363
1422
}
1423
+ DEBUG (Forwarder.dump (*this ));
1364
1424
}
1365
1425
}
1366
1426
1367
1427
void RLEContext::processBasicBlocksForAvailValue () {
1368
1428
for (SILBasicBlock *BB : PO->getReversePostOrder ()) {
1429
+ DEBUG (llvm::dbgs () << " PROCESS " << printCtx.getID (BB)
1430
+ << " for available.\n " );
1431
+
1369
1432
BlockState &Forwarder = getBlockState (BB);
1370
1433
1371
1434
// Merge the predecessors. After merging, BlockState now contains
@@ -1382,11 +1445,15 @@ void RLEContext::processBasicBlocksForAvailValue() {
1382
1445
// the available BitVector here as they should have been initialized and
1383
1446
// stabilized in the processBasicBlocksWithGenKillSet.
1384
1447
Forwarder.updateForwardValOut ();
1448
+
1449
+ DEBUG (Forwarder.dump (*this ));
1385
1450
}
1386
1451
}
1387
1452
1388
1453
void RLEContext::processBasicBlocksForRLE (bool Optimistic) {
1389
1454
for (SILBasicBlock *BB : PO->getReversePostOrder ()) {
1455
+ DEBUG (llvm::dbgs () << " PROCESS " << printCtx.getID (BB) << " for RLE.\n " );
1456
+
1390
1457
// If we know this is not a one iteration function which means its
1391
1458
// forward sets have been computed and converged,
1392
1459
// and this basic block does not even have LoadInsts, there is no point
@@ -1402,6 +1469,8 @@ void RLEContext::processBasicBlocksForRLE(bool Optimistic) {
1402
1469
// beginning of the basic block along all paths.
1403
1470
Forwarder.mergePredecessorAvailSetAndValue (*this );
1404
1471
1472
+ DEBUG (Forwarder.dump (*this ));
1473
+
1405
1474
// Perform the actual redundant load elimination.
1406
1475
Forwarder.processBasicBlockWithKind (*this , RLEKind::PerformRLE);
1407
1476
@@ -1478,11 +1547,10 @@ bool RLEContext::run() {
1478
1547
BBToProcess.find (&B) != BBToProcess.end ());
1479
1548
}
1480
1549
1481
- DEBUG (llvm::dbgs () << " RLE START\n " ;
1482
- for (unsigned i = 0 ; i < LocationVault.size (); ++i) {
1483
- llvm::dbgs () << " LSLocation #" << i;
1484
- getLocation (i).print (llvm::dbgs (), &Fn->getModule ());
1485
- });
1550
+ DEBUG (for (unsigned i = 0 ; i < LocationVault.size (); ++i) {
1551
+ llvm::dbgs () << " LSLocation #" << i;
1552
+ getLocation (i).print (llvm::dbgs (), &Fn->getModule ());
1553
+ });
1486
1554
1487
1555
if (Optimistic)
1488
1556
runIterativeRLE ();
0 commit comments