@@ -162,7 +162,7 @@ namespace {
162
162
class RLEContext ;
163
163
// / State of the load store in one basic block which allows for forwarding from
164
164
// / loads, stores -> loads
165
- class RLEBBState {
165
+ class BlockState {
166
166
// / The basic block that we are optimizing.
167
167
SILBasicBlock *BB;
168
168
@@ -199,7 +199,7 @@ class RLEBBState {
199
199
}
200
200
201
201
// / Merge in the state of an individual predecessor.
202
- void mergePredecessorState (RLEBBState &OtherState);
202
+ void mergePredecessorState (BlockState &OtherState);
203
203
204
204
// / MemLocation read has been extracted, expanded and mapped to the bit
205
205
// / position in the bitvector. process it using the bit position.
@@ -229,7 +229,7 @@ class RLEBBState {
229
229
bool isTrackingMemLocation (unsigned bit);
230
230
231
231
public:
232
- RLEBBState () = default ;
232
+ BlockState () = default ;
233
233
234
234
void init (SILBasicBlock *NewBB, unsigned bitcnt, bool reachable) {
235
235
BB = NewBB;
@@ -307,7 +307,7 @@ class RLEContext {
307
307
PostOrderFunctionInfo::reverse_range ReversePostOrder;
308
308
309
309
// / Keeps all the locations for the current function. The BitVector in each
310
- // / RLEBBState is then laid on top of it to keep track of which MemLocation
310
+ // / BlockState is then laid on top of it to keep track of which MemLocation
311
311
// / has a downward available value.
312
312
std::vector<MemLocation> MemLocationVault;
313
313
@@ -318,8 +318,8 @@ class RLEContext {
318
318
// / Use for fast lookup.
319
319
llvm::DenseMap<MemLocation, unsigned > LocToBitIndex;
320
320
321
- // / A map from each BasicBlock to its RLEBBState .
322
- llvm::SmallDenseMap<SILBasicBlock *, RLEBBState , 4 > BBToLocState;
321
+ // / A map from each BasicBlock to its BlockState .
322
+ llvm::SmallDenseMap<SILBasicBlock *, BlockState , 4 > BBToLocState;
323
323
324
324
// / A map for each basic block and whether its predecessors have forwardable
325
325
// / edges.
@@ -341,8 +341,8 @@ class RLEContext {
341
341
// / Returns the TypeExpansionCache we will use during expanding MemLocations.
342
342
TypeExpansionMap &getTypeExpansionCache () { return TypeExpansionCache; }
343
343
344
- // / Return the RLEBBState for the basic block this basic block belongs to.
345
- RLEBBState & getBBLocState (SILBasicBlock *B) { return BBToLocState[B]; }
344
+ // / Return the BlockState for the basic block this basic block belongs to.
345
+ BlockState & getBlockState (SILBasicBlock *B) { return BBToLocState[B]; }
346
346
347
347
// / Get the bit representing the MemLocation in the MemLocationVault.
348
348
unsigned getMemLocationBit (const MemLocation &L);
@@ -373,30 +373,30 @@ class RLEContext {
373
373
374
374
} // end anonymous namespace
375
375
376
- bool RLEBBState ::isTrackingMemLocation (unsigned bit) {
376
+ bool BlockState ::isTrackingMemLocation (unsigned bit) {
377
377
return ForwardSetIn.test (bit);
378
378
}
379
379
380
- void RLEBBState ::stopTrackingMemLocation (unsigned bit) {
380
+ void BlockState ::stopTrackingMemLocation (unsigned bit) {
381
381
ForwardSetIn.reset (bit);
382
382
ForwardValIn.erase (bit);
383
383
}
384
384
385
- void RLEBBState ::clearMemLocations () {
385
+ void BlockState ::clearMemLocations () {
386
386
ForwardSetIn.reset ();
387
387
ForwardValIn.clear ();
388
388
}
389
389
390
- void RLEBBState ::startTrackingMemLocation (unsigned bit, LoadStoreValue Val) {
390
+ void BlockState ::startTrackingMemLocation (unsigned bit, LoadStoreValue Val) {
391
391
ForwardSetIn.set (bit);
392
392
ForwardValIn[bit] = Val;
393
393
}
394
394
395
- void RLEBBState ::updateTrackedMemLocation (unsigned bit, LoadStoreValue Val) {
395
+ void BlockState ::updateTrackedMemLocation (unsigned bit, LoadStoreValue Val) {
396
396
ForwardValIn[bit] = Val;
397
397
}
398
398
399
- SILValue RLEBBState ::computeForwardingValues (RLEContext &Ctx, MemLocation &L,
399
+ SILValue BlockState ::computeForwardingValues (RLEContext &Ctx, MemLocation &L,
400
400
SILInstruction *InsertPt,
401
401
bool UseForwardValOut) {
402
402
SILBasicBlock *ParentBB = InsertPt->getParent ();
@@ -426,7 +426,7 @@ SILValue RLEBBState::computeForwardingValues(RLEContext &Ctx, MemLocation &L,
426
426
return TheForwardingValue;
427
427
}
428
428
429
- bool RLEBBState ::setupRLE (RLEContext &Ctx, SILInstruction *I, SILValue Mem) {
429
+ bool BlockState ::setupRLE (RLEContext &Ctx, SILInstruction *I, SILValue Mem) {
430
430
// Try to construct a SILValue for the current MemLocation.
431
431
//
432
432
// Collect the locations and their corresponding values into a map.
@@ -468,7 +468,7 @@ bool RLEBBState::setupRLE(RLEContext &Ctx, SILInstruction *I, SILValue Mem) {
468
468
return true ;
469
469
}
470
470
471
- void RLEBBState ::updateForwardSetForRead (RLEContext &Ctx, unsigned bit,
471
+ void BlockState ::updateForwardSetForRead (RLEContext &Ctx, unsigned bit,
472
472
LoadStoreValue Val) {
473
473
// If there is already an available value for this location, use
474
474
// the existing value.
@@ -479,7 +479,7 @@ void RLEBBState::updateForwardSetForRead(RLEContext &Ctx, unsigned bit,
479
479
startTrackingMemLocation (bit, Val);
480
480
}
481
481
482
- void RLEBBState ::updateForwardSetForWrite (RLEContext &Ctx, unsigned bit,
482
+ void BlockState ::updateForwardSetForWrite (RLEContext &Ctx, unsigned bit,
483
483
LoadStoreValue Val) {
484
484
// This is a store. Invalidate any Memlocation that this location may
485
485
// alias, as their value can no longer be forwarded.
@@ -498,7 +498,7 @@ void RLEBBState::updateForwardSetForWrite(RLEContext &Ctx, unsigned bit,
498
498
startTrackingMemLocation (bit, Val);
499
499
}
500
500
501
- void RLEBBState ::processWrite (RLEContext &Ctx, SILInstruction *I, SILValue Mem,
501
+ void BlockState ::processWrite (RLEContext &Ctx, SILInstruction *I, SILValue Mem,
502
502
SILValue Val) {
503
503
// Initialize the MemLocation.
504
504
MemLocation L (Mem);
@@ -520,7 +520,7 @@ void RLEBBState::processWrite(RLEContext &Ctx, SILInstruction *I, SILValue Mem,
520
520
}
521
521
}
522
522
523
- void RLEBBState ::processRead (RLEContext &Ctx, SILInstruction *I, SILValue Mem,
523
+ void BlockState ::processRead (RLEContext &Ctx, SILInstruction *I, SILValue Mem,
524
524
SILValue Val, bool PF) {
525
525
// Initialize the MemLocation.
526
526
MemLocation L (Mem);
@@ -560,15 +560,15 @@ void RLEBBState::processRead(RLEContext &Ctx, SILInstruction *I, SILValue Mem,
560
560
setupRLE (Ctx, I, Mem);
561
561
}
562
562
563
- void RLEBBState ::processStoreInst (RLEContext &Ctx, StoreInst *SI) {
563
+ void BlockState ::processStoreInst (RLEContext &Ctx, StoreInst *SI) {
564
564
processWrite (Ctx, SI, SI->getDest (), SI->getSrc ());
565
565
}
566
566
567
- void RLEBBState ::processLoadInst (RLEContext &Ctx, LoadInst *LI, bool PF) {
567
+ void BlockState ::processLoadInst (RLEContext &Ctx, LoadInst *LI, bool PF) {
568
568
processRead (Ctx, LI, LI->getOperand (), SILValue (LI), PF);
569
569
}
570
570
571
- void RLEBBState ::processUnknownWriteInst (RLEContext &Ctx, SILInstruction *I) {
571
+ void BlockState ::processUnknownWriteInst (RLEContext &Ctx, SILInstruction *I) {
572
572
auto *AA = Ctx.getAA ();
573
573
for (unsigned i = 0 ; i < ForwardSetIn.size (); ++i) {
574
574
if (!isTrackingMemLocation (i))
@@ -586,7 +586,7 @@ void RLEBBState::processUnknownWriteInst(RLEContext &Ctx, SILInstruction *I) {
586
586
}
587
587
588
588
// / Promote stored values to loads and merge duplicated loads.
589
- bool RLEBBState ::optimize (RLEContext &Ctx, bool PF) {
589
+ bool BlockState ::optimize (RLEContext &Ctx, bool PF) {
590
590
for (auto &II : *BB) {
591
591
SILInstruction *Inst = &II;
592
592
DEBUG (llvm::dbgs () << " Visiting: " << *Inst);
@@ -633,14 +633,14 @@ bool RLEBBState::optimize(RLEContext &Ctx, bool PF) {
633
633
return updateForwardSetOut ();
634
634
}
635
635
636
- void RLEBBState ::mergePredecessorState (RLEBBState &OtherState) {
636
+ void BlockState ::mergePredecessorState (BlockState &OtherState) {
637
637
// Merge in the predecessor state.
638
638
llvm::SmallVector<unsigned , 8 > LocDeleteList;
639
639
for (unsigned i = 0 ; i < ForwardSetIn.size (); ++i) {
640
640
if (OtherState.ForwardSetOut [i]) {
641
641
// There are multiple values from multiple predecessors, set this as
642
642
// a covering value. We do not need to track the value itself, as we
643
- // can always go to the predecessors RLEBBState to find it.
643
+ // can always go to the predecessors BlockState to find it.
644
644
ForwardValIn[i].setCoveringValue ();
645
645
continue ;
646
646
}
@@ -649,7 +649,7 @@ void RLEBBState::mergePredecessorState(RLEBBState &OtherState) {
649
649
}
650
650
}
651
651
652
- void RLEBBState ::mergePredecessorStates (RLEContext &Ctx) {
652
+ void BlockState ::mergePredecessorStates (RLEContext &Ctx) {
653
653
// Clear the state if the basic block has no predecessor.
654
654
if (BB->getPreds ().begin () == BB->getPreds ().end ()) {
655
655
clearMemLocations ();
@@ -661,9 +661,9 @@ void RLEBBState::mergePredecessorStates(RLEContext &Ctx) {
661
661
bool HasAtLeastOnePred = false ;
662
662
// For each predecessor of BB...
663
663
for (auto Pred : BB->getPreds ()) {
664
- RLEBBState &Other = Ctx.getBBLocState (Pred);
664
+ BlockState &Other = Ctx.getBlockState (Pred);
665
665
666
- // If we have not had at least one predecessor, initialize RLEBBState
666
+ // If we have not had at least one predecessor, initialize BlockState
667
667
// with the state of the initial predecessor.
668
668
// If BB is also a predecessor of itself, we should not initialize.
669
669
if (!HasAtLeastOnePred) {
@@ -699,7 +699,7 @@ RLEContext::RLEContext(SILFunction *F, AliasAnalysis *AA,
699
699
// know all the locations accessed in this function, we can resize the bit
700
700
// vector to the appropriate size.
701
701
for (auto &B : *F) {
702
- BBToLocState[&B] = RLEBBState ();
702
+ BBToLocState[&B] = BlockState ();
703
703
// We set the initial state of unreachable block to 0, as we do not have
704
704
// a value for the location.
705
705
//
@@ -765,7 +765,7 @@ SILValue RLEContext::computePredecessorCoveringValue(SILBasicBlock *BB,
765
765
// At this point, we know this MemLocation has available value and we also
766
766
// know we can forward a SILValue from every predecesor. It is safe to
767
767
// insert the basic block argument.
768
- RLEBBState &Forwarder = getBBLocState (BB);
768
+ BlockState &Forwarder = getBlockState (BB);
769
769
SILValue TheForwardingValue = BB->createBBArg (L.getType ());
770
770
771
771
// For the given MemLocation, we just created a concrete value at the
@@ -810,7 +810,7 @@ SILValue RLEContext::computePredecessorCoveringValue(SILBasicBlock *BB,
810
810
811
811
llvm::DenseMap<SILBasicBlock *, SILValue> Args;
812
812
for (auto Pred : Preds) {
813
- RLEBBState &Forwarder = getBBLocState (Pred);
813
+ BlockState &Forwarder = getBlockState (Pred);
814
814
// Call computeForwardingValues with using ForwardValOut as we are
815
815
// computing the MemLocation value at the end of each predecessor.
816
816
Args[Pred] = Forwarder.computeForwardingValues (*this , L,
@@ -834,7 +834,7 @@ MemLocation &RLEContext::getMemLocation(const unsigned index) {
834
834
835
835
unsigned RLEContext::getMemLocationBit (const MemLocation &Loc) {
836
836
// Return the bit position of the given Loc in the MemLocationVault. The bit
837
- // position is then used to set/reset the bitvector kept by each RLEBBState .
837
+ // position is then used to set/reset the bitvector kept by each BlockState .
838
838
//
839
839
// We should have the location populated by the enumerateMemLocation at this
840
840
// point.
@@ -855,7 +855,7 @@ bool RLEContext::gatherValues(SILBasicBlock *BB, MemLocation &L,
855
855
// If we are collecting values at the end of the basic block, we can
856
856
// use its ForwardValOut.
857
857
//
858
- RLEBBState &Forwarder = getBBLocState (BB);
858
+ BlockState &Forwarder = getBlockState (BB);
859
859
ValueTableMap &OTM = UseForwardValOut ? Forwarder.getForwardValOut ()
860
860
: Forwarder.getForwardValIn ();
861
861
for (auto &X : Locs) {
@@ -905,9 +905,9 @@ bool RLEContext::run() {
905
905
do {
906
906
ForwardSetChanged = false ;
907
907
for (SILBasicBlock *BB : ReversePostOrder) {
908
- RLEBBState &Forwarder = getBBLocState (BB);
908
+ BlockState &Forwarder = getBlockState (BB);
909
909
910
- // Merge the predecessors. After merging, RLEBBState now contains
910
+ // Merge the predecessors. After merging, BlockState now contains
911
911
// lists of available MemLocations and their values that reach the
912
912
// beginning of the basic block along all paths.
913
913
Forwarder.mergePredecessorStates (*this );
0 commit comments