@@ -125,7 +125,7 @@ namespace {
125
125
// / non-dead store.
126
126
constexpr unsigned MaxPartialDeadStoreCountLimit = 1 ;
127
127
128
- // / DSEBBState summarizes how MemLocations are used in a basic block.
128
+ // / BlockState summarizes how MemLocations are used in a basic block.
129
129
// /
130
130
// / Initially the WriteSetOut is empty. Before a basic block is processed, it is
131
131
// / initialized to the intersection of WriteSetIns of all successors of the
@@ -145,9 +145,9 @@ constexpr unsigned MaxPartialDeadStoreCountLimit = 1;
145
145
// / 3. When an instruction reads from memory in an unknown way, the WriteSetOut
146
146
// / bit is cleared if the instruction can read the corresponding MemLocation.
147
147
// /
148
- class DSEBBState {
148
+ class BlockState {
149
149
public:
150
- // / The basic block this DSEBBState represents.
150
+ // / The basic block this BlockState represents.
151
151
SILBasicBlock *BB;
152
152
153
153
// / Keep the number of MemLocations in the LocationVault.
@@ -180,8 +180,8 @@ class DSEBBState {
180
180
llvm::DenseMap<SILValue, SILValue> LiveStores;
181
181
182
182
// / Constructors.
183
- DSEBBState () : BB(nullptr ) {}
184
- DSEBBState (SILBasicBlock *B) : BB(B) {}
183
+ BlockState () : BB(nullptr ) {}
184
+ BlockState (SILBasicBlock *B) : BB(B) {}
185
185
186
186
// / Return the current basic block.
187
187
SILBasicBlock *getBB () const { return BB; }
@@ -218,29 +218,29 @@ class DSEBBState {
218
218
void startTrackingMemLocation (unsigned bit);
219
219
void stopTrackingMemLocation (unsigned bit);
220
220
bool isTrackingMemLocation (unsigned bit);
221
- void initialize (const DSEBBState &L);
222
- void intersect (const DSEBBState &L);
221
+ void initialize (const BlockState &L);
222
+ void intersect (const BlockState &L);
223
223
};
224
224
225
225
} // end anonymous namespace
226
226
227
- bool DSEBBState ::updateWriteSetIn () {
227
+ bool BlockState ::updateWriteSetIn () {
228
228
bool Changed = (WriteSetIn != WriteSetOut);
229
229
WriteSetIn = WriteSetOut;
230
230
return Changed;
231
231
}
232
232
233
- void DSEBBState ::clearMemLocations () { WriteSetOut.reset (); }
233
+ void BlockState ::clearMemLocations () { WriteSetOut.reset (); }
234
234
235
- void DSEBBState ::startTrackingMemLocation (unsigned bit) { WriteSetOut.set (bit); }
235
+ void BlockState ::startTrackingMemLocation (unsigned bit) { WriteSetOut.set (bit); }
236
236
237
- void DSEBBState ::stopTrackingMemLocation (unsigned bit) { WriteSetOut.reset (bit); }
237
+ void BlockState ::stopTrackingMemLocation (unsigned bit) { WriteSetOut.reset (bit); }
238
238
239
- bool DSEBBState ::isTrackingMemLocation (unsigned bit) {
239
+ bool BlockState ::isTrackingMemLocation (unsigned bit) {
240
240
return WriteSetOut.test (bit);
241
241
}
242
242
243
- void DSEBBState ::initialize (const DSEBBState &Succ) { WriteSetOut = Succ.WriteSetIn ; }
243
+ void BlockState ::initialize (const BlockState &Succ) { WriteSetOut = Succ.WriteSetIn ; }
244
244
245
245
// / Intersect is very frequently performed, so it is important to make it as
246
246
// / cheap as possible.
@@ -253,7 +253,7 @@ void DSEBBState::initialize(const DSEBBState &Succ) { WriteSetOut = Succ.WriteSe
253
253
// / possible that 2 MemLocations with different bases that happen to be the
254
254
// / same object and field. In such case, we would miss a dead store
255
255
// / opportunity. But this happens less often with canonicalization.
256
- void DSEBBState ::intersect (const DSEBBState &Succ) { WriteSetOut &= Succ.WriteSetIn ; }
256
+ void BlockState ::intersect (const BlockState &Succ) { WriteSetOut &= Succ.WriteSetIn ; }
257
257
258
258
// ===----------------------------------------------------------------------===//
259
259
// Top Level Implementation
@@ -278,13 +278,13 @@ class DSEContext {
278
278
llvm::BumpPtrAllocator BPA;
279
279
280
280
// / Map every basic block to its location state.
281
- llvm::DenseMap<SILBasicBlock *, DSEBBState *> BBToLocState;
281
+ llvm::DenseMap<SILBasicBlock *, BlockState *> BBToLocState;
282
282
283
- // / Keeps the actual DSEBBStates .
284
- std::vector<DSEBBState> DSEBBStates ;
283
+ // / Keeps the actual BlockStates .
284
+ std::vector<BlockState> BlockStates ;
285
285
286
286
// / Keeps all the locations for the current function. The BitVector in each
287
- // / DSEBBState is then laid on top of it to keep track of which MemLocation
287
+ // / BlockState is then laid on top of it to keep track of which MemLocation
288
288
// / has an upward visible store.
289
289
std::vector<MemLocation> MemLocationVault;
290
290
@@ -294,40 +294,40 @@ class DSEContext {
294
294
// / Contains a map between location to their index in the MemLocationVault.
295
295
MemLocationIndexMap LocToBitIndex;
296
296
297
- // / Return the DSEBBState for the basic block this basic block belongs to.
298
- DSEBBState * getBBLocState (SILBasicBlock *B) { return BBToLocState[B]; }
297
+ // / Return the BlockState for the basic block this basic block belongs to.
298
+ BlockState * getBlockState (SILBasicBlock *B) { return BBToLocState[B]; }
299
299
300
- // / Return the DSEBBState for the basic block this instruction belongs to.
301
- DSEBBState * getBBLocState (SILInstruction *I) {
302
- return getBBLocState (I->getParent ());
300
+ // / Return the BlockState for the basic block this instruction belongs to.
301
+ BlockState * getBlockState (SILInstruction *I) {
302
+ return getBlockState (I->getParent ());
303
303
}
304
304
305
305
// / MemLocation read has been extracted, expanded and mapped to the bit
306
306
// / position in the bitvector. update the gen kill set using the bit
307
307
// / position.
308
- void updateGenKillSetForRead (DSEBBState *S, unsigned bit);
308
+ void updateGenKillSetForRead (BlockState *S, unsigned bit);
309
309
310
310
// / MemLocation written has been extracted, expanded and mapped to the bit
311
311
// / position in the bitvector. update the gen kill set using the bit
312
312
// / position.
313
- void updateGenKillSetForWrite (DSEBBState *S, unsigned bit);
313
+ void updateGenKillSetForWrite (BlockState *S, unsigned bit);
314
314
315
315
// / MemLocation read has been extracted, expanded and mapped to the bit
316
316
// / position in the bitvector. process it using the bit position.
317
- void updateWriteSetForRead (DSEBBState *S, unsigned Bit);
317
+ void updateWriteSetForRead (BlockState *S, unsigned Bit);
318
318
319
319
// / MemLocation written has been extracted, expanded and mapped to the bit
320
320
// / position in the bitvector. process it using the bit position.
321
- bool updateWriteSetForWrite (DSEBBState *S, unsigned Bit);
321
+ bool updateWriteSetForWrite (BlockState *S, unsigned Bit);
322
322
323
323
// / There is a read to a location, expand the location into individual fields
324
324
// / before processing them.
325
- void processRead (SILInstruction *Inst, DSEBBState *State, SILValue Mem,
325
+ void processRead (SILInstruction *Inst, BlockState *State, SILValue Mem,
326
326
bool BuildGenKillSet);
327
327
328
328
// / There is a write to a location, expand the location into individual fields
329
329
// / before processing them.
330
- void processWrite (SILInstruction *Inst, DSEBBState *State, SILValue Val,
330
+ void processWrite (SILInstruction *Inst, BlockState *State, SILValue Val,
331
331
SILValue Mem, bool BuildGenKillSet);
332
332
333
333
// / Process Instructions. Extract MemLocations from SIL LoadInst.
@@ -399,7 +399,7 @@ class DSEContext {
399
399
// / Intersect the successor live-ins.
400
400
void mergeSuccessorStates (SILBasicBlock *BB);
401
401
402
- // / Update the DSEBBState based on the given instruction.
402
+ // / Update the BlockState based on the given instruction.
403
403
void processInstruction (SILInstruction *I, bool BuildGenKillSet);
404
404
405
405
// / Entry point for global dead store elimination.
@@ -410,7 +410,7 @@ class DSEContext {
410
410
411
411
unsigned DSEContext::getMemLocationBit (const MemLocation &Loc) {
412
412
// Return the bit position of the given Loc in the MemLocationVault. The bit
413
- // position is then used to set/reset the bitvector kept by each DSEBBState .
413
+ // position is then used to set/reset the bitvector kept by each BlockState .
414
414
//
415
415
// We should have the location populated by the enumerateMemLocation at this
416
416
// point.
@@ -432,7 +432,7 @@ bool DSEContext::processBasicBlockWithGenKillSet(SILBasicBlock *BB) {
432
432
mergeSuccessorStates (BB);
433
433
434
434
// Compute the WriteSetOut at the beginning of the basic block.
435
- DSEBBState *S = getBBLocState (BB);
435
+ BlockState *S = getBlockState (BB);
436
436
llvm::BitVector T = S->BBKillSet ;
437
437
S->WriteSetOut &= T.flip ();
438
438
S->WriteSetOut |= S->BBGenSet ;
@@ -454,12 +454,12 @@ bool DSEContext::processBasicBlock(SILBasicBlock *BB) {
454
454
455
455
// If WriteSetIn changes, then keep iterating until reached a fixed
456
456
// point.
457
- return getBBLocState (BB)->updateWriteSetIn ();
457
+ return getBlockState (BB)->updateWriteSetIn ();
458
458
}
459
459
460
460
void DSEContext::mergeSuccessorStates (SILBasicBlock *BB) {
461
461
// First, clear the WriteSetOut for the current basicblock.
462
- DSEBBState *C = getBBLocState (BB);
462
+ BlockState *C = getBlockState (BB);
463
463
C->clearMemLocations ();
464
464
465
465
// If basic block has no successor, then all local writes can be considered
@@ -479,18 +479,18 @@ void DSEContext::mergeSuccessorStates(SILBasicBlock *BB) {
479
479
480
480
// Use the first successor as the base condition.
481
481
auto Iter = BB->succ_begin ();
482
- C->initialize (*getBBLocState (*Iter));
482
+ C->initialize (*getBlockState (*Iter));
483
483
Iter = std::next (Iter);
484
484
for (auto EndIter = BB->succ_end (); Iter != EndIter; ++Iter) {
485
- C->intersect (*getBBLocState (*Iter));
485
+ C->intersect (*getBlockState (*Iter));
486
486
}
487
487
}
488
488
489
489
void DSEContext::invalidateMemLocationBase (SILInstruction *I,
490
490
bool BuildGenKillSet) {
491
491
// If this instruction defines the base of a location, then we need to
492
492
// invalidate any locations with the same base.
493
- DSEBBState *S = getBBLocState (I);
493
+ BlockState *S = getBlockState (I);
494
494
if (BuildGenKillSet) {
495
495
for (unsigned i = 0 ; i < S->MemLocationNum ; ++i) {
496
496
if (MemLocationVault[i].getBase ().getDef () != I)
@@ -510,7 +510,7 @@ void DSEContext::invalidateMemLocationBase(SILInstruction *I,
510
510
}
511
511
}
512
512
513
- void DSEContext::updateWriteSetForRead (DSEBBState *S, unsigned bit) {
513
+ void DSEContext::updateWriteSetForRead (BlockState *S, unsigned bit) {
514
514
// Remove any may/must-aliasing stores to the MemLocation, as they cant be
515
515
// used to kill any upward visible stores due to the intefering load.
516
516
MemLocation &R = MemLocationVault[bit];
@@ -526,7 +526,7 @@ void DSEContext::updateWriteSetForRead(DSEBBState *S, unsigned bit) {
526
526
}
527
527
}
528
528
529
- void DSEContext::updateGenKillSetForRead (DSEBBState *S, unsigned bit) {
529
+ void DSEContext::updateGenKillSetForRead (BlockState *S, unsigned bit) {
530
530
// Start tracking the read to this MemLocation in the killset and update
531
531
// the genset accordingly.
532
532
//
@@ -544,7 +544,7 @@ void DSEContext::updateGenKillSetForRead(DSEBBState *S, unsigned bit) {
544
544
}
545
545
}
546
546
547
- bool DSEContext::updateWriteSetForWrite (DSEBBState *S, unsigned bit) {
547
+ bool DSEContext::updateWriteSetForWrite (BlockState *S, unsigned bit) {
548
548
// If a tracked store must aliases with this store, then this store is dead.
549
549
bool IsDead = false ;
550
550
MemLocation &R = MemLocationVault[bit];
@@ -568,12 +568,12 @@ bool DSEContext::updateWriteSetForWrite(DSEBBState *S, unsigned bit) {
568
568
return IsDead;
569
569
}
570
570
571
- void DSEContext::updateGenKillSetForWrite (DSEBBState *S, unsigned bit) {
571
+ void DSEContext::updateGenKillSetForWrite (BlockState *S, unsigned bit) {
572
572
// Start tracking the store to this MemLoation.
573
573
S->BBGenSet .set (bit);
574
574
}
575
575
576
- void DSEContext::processRead (SILInstruction *I, DSEBBState *S, SILValue Mem,
576
+ void DSEContext::processRead (SILInstruction *I, BlockState *S, SILValue Mem,
577
577
bool BuildGenKillSet) {
578
578
// Construct a MemLocation to represent the memory read by this instruction.
579
579
// NOTE: The base will point to the actual object this inst is accessing,
@@ -624,7 +624,7 @@ void DSEContext::processRead(SILInstruction *I, DSEBBState *S, SILValue Mem,
624
624
}
625
625
}
626
626
627
- void DSEContext::processWrite (SILInstruction *I, DSEBBState *S, SILValue Val,
627
+ void DSEContext::processWrite (SILInstruction *I, BlockState *S, SILValue Val,
628
628
SILValue Mem, bool BuildGenKillSet) {
629
629
// Construct a MemLocation to represent the memory read by this instruction.
630
630
// NOTE: The base will point to the actual object this inst is accessing,
@@ -741,30 +741,30 @@ void DSEContext::processWrite(SILInstruction *I, DSEBBState *S, SILValue Val,
741
741
742
742
void DSEContext::processLoadInst (SILInstruction *I, bool BuildGenKillSet) {
743
743
SILValue Mem = cast<LoadInst>(I)->getOperand ();
744
- processRead (I, getBBLocState (I), Mem, BuildGenKillSet);
744
+ processRead (I, getBlockState (I), Mem, BuildGenKillSet);
745
745
}
746
746
747
747
void DSEContext::processStoreInst (SILInstruction *I, bool BuildGenKillSet) {
748
748
SILValue Val = cast<StoreInst>(I)->getSrc ();
749
749
SILValue Mem = cast<StoreInst>(I)->getDest ();
750
- processWrite (I, getBBLocState (I), Val, Mem, BuildGenKillSet);
750
+ processWrite (I, getBlockState (I), Val, Mem, BuildGenKillSet);
751
751
}
752
752
753
753
void DSEContext::processDebugValueAddrInst (SILInstruction *I) {
754
- DSEBBState *S = getBBLocState (I);
754
+ BlockState *S = getBlockState (I);
755
755
SILValue Mem = cast<DebugValueAddrInst>(I)->getOperand ();
756
756
for (unsigned i = 0 ; i < S->WriteSetOut .size (); ++i) {
757
757
if (!S->isTrackingMemLocation (i))
758
758
continue ;
759
759
if (AA->isNoAlias (Mem, MemLocationVault[i].getBase ()))
760
760
continue ;
761
- getBBLocState (I)->stopTrackingMemLocation (i);
761
+ getBlockState (I)->stopTrackingMemLocation (i);
762
762
}
763
763
}
764
764
765
765
void DSEContext::processUnknownReadMemInst (SILInstruction *I,
766
766
bool BuildGenKillSet) {
767
- DSEBBState *S = getBBLocState (I);
767
+ BlockState *S = getBlockState (I);
768
768
// Update the gen kill set.
769
769
if (BuildGenKillSet) {
770
770
for (unsigned i = 0 ; i < S->MemLocationNum ; ++i) {
@@ -784,7 +784,7 @@ void DSEContext::processUnknownReadMemInst(SILInstruction *I,
784
784
continue ;
785
785
if (!AA->mayReadFromMemory (I, MemLocationVault[i].getBase ()))
786
786
continue ;
787
- getBBLocState (I)->stopTrackingMemLocation (i);
787
+ getBlockState (I)->stopTrackingMemLocation (i);
788
788
}
789
789
}
790
790
@@ -851,15 +851,15 @@ void DSEContext::run() {
851
851
// vector to the appropriate size.
852
852
//
853
853
// DenseMap has a minimum size of 64, while many functions do not have more
854
- // than 64 basic blocks. Therefore, allocate the DSEBBState in a vector and use
854
+ // than 64 basic blocks. Therefore, allocate the BlockState in a vector and use
855
855
// pointer in BBToLocState to access them.
856
856
for (auto &B : *F) {
857
- DSEBBStates .push_back (DSEBBState (&B));
858
- DSEBBStates .back ().init (MemLocationVault.size ());
857
+ BlockStates .push_back (BlockState (&B));
858
+ BlockStates .back ().init (MemLocationVault.size ());
859
859
}
860
860
861
861
// Initialize the BBToLocState mapping.
862
- for (auto &S : DSEBBStates ) {
862
+ for (auto &S : BlockStates ) {
863
863
BBToLocState[S.getBB ()] = &S;
864
864
}
865
865
@@ -894,13 +894,13 @@ void DSEContext::run() {
894
894
// Finally, delete the dead stores and create the live stores.
895
895
for (SILBasicBlock &BB : *F) {
896
896
// Create the stores that are alive due to partial dead stores.
897
- for (auto &I : getBBLocState (&BB)->LiveStores ) {
897
+ for (auto &I : getBlockState (&BB)->LiveStores ) {
898
898
SILInstruction *IT = cast<SILInstruction>(I.first )->getNextNode ();
899
899
SILBuilderWithScope Builder (IT);
900
900
Builder.createStore (I.first .getLoc ().getValue (), I.second , I.first );
901
901
}
902
902
// Delete the dead stores.
903
- for (auto &I : getBBLocState (&BB)->DeadStores ) {
903
+ for (auto &I : getBlockState (&BB)->DeadStores ) {
904
904
DEBUG (llvm::dbgs () << " *** Removing: " << *I << " ***\n " );
905
905
// This way, we get rid of pass dependence on DCE.
906
906
recursivelyDeleteTriviallyDeadInstructions (I, true );
0 commit comments