Skip to content

Commit 0287ac7

Browse files
committed
Rename DSEBBState to BlockState
1 parent 69e6275 commit 0287ac7

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

lib/SILPasses/Scalar/DeadStoreElimination.cpp

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ namespace {
125125
/// non-dead store.
126126
constexpr unsigned MaxPartialDeadStoreCountLimit = 1;
127127

128-
/// DSEBBState summarizes how MemLocations are used in a basic block.
128+
/// BlockState summarizes how MemLocations are used in a basic block.
129129
///
130130
/// Initially the WriteSetOut is empty. Before a basic block is processed, it is
131131
/// initialized to the intersection of WriteSetIns of all successors of the
@@ -145,9 +145,9 @@ constexpr unsigned MaxPartialDeadStoreCountLimit = 1;
145145
/// 3. When an instruction reads from memory in an unknown way, the WriteSetOut
146146
/// bit is cleared if the instruction can read the corresponding MemLocation.
147147
///
148-
class DSEBBState {
148+
class BlockState {
149149
public:
150-
/// The basic block this DSEBBState represents.
150+
/// The basic block this BlockState represents.
151151
SILBasicBlock *BB;
152152

153153
/// Keep the number of MemLocations in the LocationVault.
@@ -180,8 +180,8 @@ class DSEBBState {
180180
llvm::DenseMap<SILValue, SILValue> LiveStores;
181181

182182
/// Constructors.
183-
DSEBBState() : BB(nullptr) {}
184-
DSEBBState(SILBasicBlock *B) : BB(B) {}
183+
BlockState() : BB(nullptr) {}
184+
BlockState(SILBasicBlock *B) : BB(B) {}
185185

186186
/// Return the current basic block.
187187
SILBasicBlock *getBB() const { return BB; }
@@ -218,29 +218,29 @@ class DSEBBState {
218218
void startTrackingMemLocation(unsigned bit);
219219
void stopTrackingMemLocation(unsigned bit);
220220
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);
223223
};
224224

225225
} // end anonymous namespace
226226

227-
bool DSEBBState::updateWriteSetIn() {
227+
bool BlockState::updateWriteSetIn() {
228228
bool Changed = (WriteSetIn != WriteSetOut);
229229
WriteSetIn = WriteSetOut;
230230
return Changed;
231231
}
232232

233-
void DSEBBState::clearMemLocations() { WriteSetOut.reset(); }
233+
void BlockState::clearMemLocations() { WriteSetOut.reset(); }
234234

235-
void DSEBBState::startTrackingMemLocation(unsigned bit) { WriteSetOut.set(bit); }
235+
void BlockState::startTrackingMemLocation(unsigned bit) { WriteSetOut.set(bit); }
236236

237-
void DSEBBState::stopTrackingMemLocation(unsigned bit) { WriteSetOut.reset(bit); }
237+
void BlockState::stopTrackingMemLocation(unsigned bit) { WriteSetOut.reset(bit); }
238238

239-
bool DSEBBState::isTrackingMemLocation(unsigned bit) {
239+
bool BlockState::isTrackingMemLocation(unsigned bit) {
240240
return WriteSetOut.test(bit);
241241
}
242242

243-
void DSEBBState::initialize(const DSEBBState &Succ) { WriteSetOut = Succ.WriteSetIn; }
243+
void BlockState::initialize(const BlockState &Succ) { WriteSetOut = Succ.WriteSetIn; }
244244

245245
/// Intersect is very frequently performed, so it is important to make it as
246246
/// cheap as possible.
@@ -253,7 +253,7 @@ void DSEBBState::initialize(const DSEBBState &Succ) { WriteSetOut = Succ.WriteSe
253253
/// possible that 2 MemLocations with different bases that happen to be the
254254
/// same object and field. In such case, we would miss a dead store
255255
/// 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; }
257257

258258
//===----------------------------------------------------------------------===//
259259
// Top Level Implementation
@@ -278,13 +278,13 @@ class DSEContext {
278278
llvm::BumpPtrAllocator BPA;
279279

280280
/// Map every basic block to its location state.
281-
llvm::DenseMap<SILBasicBlock *, DSEBBState *> BBToLocState;
281+
llvm::DenseMap<SILBasicBlock *, BlockState *> BBToLocState;
282282

283-
/// Keeps the actual DSEBBStates.
284-
std::vector<DSEBBState> DSEBBStates;
283+
/// Keeps the actual BlockStates.
284+
std::vector<BlockState> BlockStates;
285285

286286
/// 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
288288
/// has an upward visible store.
289289
std::vector<MemLocation> MemLocationVault;
290290

@@ -294,40 +294,40 @@ class DSEContext {
294294
/// Contains a map between location to their index in the MemLocationVault.
295295
MemLocationIndexMap LocToBitIndex;
296296

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]; }
299299

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());
303303
}
304304

305305
/// MemLocation read has been extracted, expanded and mapped to the bit
306306
/// position in the bitvector. update the gen kill set using the bit
307307
/// position.
308-
void updateGenKillSetForRead(DSEBBState *S, unsigned bit);
308+
void updateGenKillSetForRead(BlockState *S, unsigned bit);
309309

310310
/// MemLocation written has been extracted, expanded and mapped to the bit
311311
/// position in the bitvector. update the gen kill set using the bit
312312
/// position.
313-
void updateGenKillSetForWrite(DSEBBState *S, unsigned bit);
313+
void updateGenKillSetForWrite(BlockState *S, unsigned bit);
314314

315315
/// MemLocation read has been extracted, expanded and mapped to the bit
316316
/// position in the bitvector. process it using the bit position.
317-
void updateWriteSetForRead(DSEBBState *S, unsigned Bit);
317+
void updateWriteSetForRead(BlockState *S, unsigned Bit);
318318

319319
/// MemLocation written has been extracted, expanded and mapped to the bit
320320
/// position in the bitvector. process it using the bit position.
321-
bool updateWriteSetForWrite(DSEBBState *S, unsigned Bit);
321+
bool updateWriteSetForWrite(BlockState *S, unsigned Bit);
322322

323323
/// There is a read to a location, expand the location into individual fields
324324
/// before processing them.
325-
void processRead(SILInstruction *Inst, DSEBBState *State, SILValue Mem,
325+
void processRead(SILInstruction *Inst, BlockState *State, SILValue Mem,
326326
bool BuildGenKillSet);
327327

328328
/// There is a write to a location, expand the location into individual fields
329329
/// before processing them.
330-
void processWrite(SILInstruction *Inst, DSEBBState *State, SILValue Val,
330+
void processWrite(SILInstruction *Inst, BlockState *State, SILValue Val,
331331
SILValue Mem, bool BuildGenKillSet);
332332

333333
/// Process Instructions. Extract MemLocations from SIL LoadInst.
@@ -399,7 +399,7 @@ class DSEContext {
399399
/// Intersect the successor live-ins.
400400
void mergeSuccessorStates(SILBasicBlock *BB);
401401

402-
/// Update the DSEBBState based on the given instruction.
402+
/// Update the BlockState based on the given instruction.
403403
void processInstruction(SILInstruction *I, bool BuildGenKillSet);
404404

405405
/// Entry point for global dead store elimination.
@@ -410,7 +410,7 @@ class DSEContext {
410410

411411
unsigned DSEContext::getMemLocationBit(const MemLocation &Loc) {
412412
// 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.
414414
//
415415
// We should have the location populated by the enumerateMemLocation at this
416416
// point.
@@ -432,7 +432,7 @@ bool DSEContext::processBasicBlockWithGenKillSet(SILBasicBlock *BB) {
432432
mergeSuccessorStates(BB);
433433

434434
// Compute the WriteSetOut at the beginning of the basic block.
435-
DSEBBState *S = getBBLocState(BB);
435+
BlockState *S = getBlockState(BB);
436436
llvm::BitVector T = S->BBKillSet;
437437
S->WriteSetOut &= T.flip();
438438
S->WriteSetOut |= S->BBGenSet;
@@ -454,12 +454,12 @@ bool DSEContext::processBasicBlock(SILBasicBlock *BB) {
454454

455455
// If WriteSetIn changes, then keep iterating until reached a fixed
456456
// point.
457-
return getBBLocState(BB)->updateWriteSetIn();
457+
return getBlockState(BB)->updateWriteSetIn();
458458
}
459459

460460
void DSEContext::mergeSuccessorStates(SILBasicBlock *BB) {
461461
// First, clear the WriteSetOut for the current basicblock.
462-
DSEBBState *C = getBBLocState(BB);
462+
BlockState *C = getBlockState(BB);
463463
C->clearMemLocations();
464464

465465
// If basic block has no successor, then all local writes can be considered
@@ -479,18 +479,18 @@ void DSEContext::mergeSuccessorStates(SILBasicBlock *BB) {
479479

480480
// Use the first successor as the base condition.
481481
auto Iter = BB->succ_begin();
482-
C->initialize(*getBBLocState(*Iter));
482+
C->initialize(*getBlockState(*Iter));
483483
Iter = std::next(Iter);
484484
for (auto EndIter = BB->succ_end(); Iter != EndIter; ++Iter) {
485-
C->intersect(*getBBLocState(*Iter));
485+
C->intersect(*getBlockState(*Iter));
486486
}
487487
}
488488

489489
void DSEContext::invalidateMemLocationBase(SILInstruction *I,
490490
bool BuildGenKillSet) {
491491
// If this instruction defines the base of a location, then we need to
492492
// invalidate any locations with the same base.
493-
DSEBBState *S = getBBLocState(I);
493+
BlockState *S = getBlockState(I);
494494
if (BuildGenKillSet) {
495495
for (unsigned i = 0; i < S->MemLocationNum; ++i) {
496496
if (MemLocationVault[i].getBase().getDef() != I)
@@ -510,7 +510,7 @@ void DSEContext::invalidateMemLocationBase(SILInstruction *I,
510510
}
511511
}
512512

513-
void DSEContext::updateWriteSetForRead(DSEBBState *S, unsigned bit) {
513+
void DSEContext::updateWriteSetForRead(BlockState *S, unsigned bit) {
514514
// Remove any may/must-aliasing stores to the MemLocation, as they cant be
515515
// used to kill any upward visible stores due to the intefering load.
516516
MemLocation &R = MemLocationVault[bit];
@@ -526,7 +526,7 @@ void DSEContext::updateWriteSetForRead(DSEBBState *S, unsigned bit) {
526526
}
527527
}
528528

529-
void DSEContext::updateGenKillSetForRead(DSEBBState *S, unsigned bit) {
529+
void DSEContext::updateGenKillSetForRead(BlockState *S, unsigned bit) {
530530
// Start tracking the read to this MemLocation in the killset and update
531531
// the genset accordingly.
532532
//
@@ -544,7 +544,7 @@ void DSEContext::updateGenKillSetForRead(DSEBBState *S, unsigned bit) {
544544
}
545545
}
546546

547-
bool DSEContext::updateWriteSetForWrite(DSEBBState *S, unsigned bit) {
547+
bool DSEContext::updateWriteSetForWrite(BlockState *S, unsigned bit) {
548548
// If a tracked store must aliases with this store, then this store is dead.
549549
bool IsDead = false;
550550
MemLocation &R = MemLocationVault[bit];
@@ -568,12 +568,12 @@ bool DSEContext::updateWriteSetForWrite(DSEBBState *S, unsigned bit) {
568568
return IsDead;
569569
}
570570

571-
void DSEContext::updateGenKillSetForWrite(DSEBBState *S, unsigned bit) {
571+
void DSEContext::updateGenKillSetForWrite(BlockState *S, unsigned bit) {
572572
// Start tracking the store to this MemLoation.
573573
S->BBGenSet.set(bit);
574574
}
575575

576-
void DSEContext::processRead(SILInstruction *I, DSEBBState *S, SILValue Mem,
576+
void DSEContext::processRead(SILInstruction *I, BlockState *S, SILValue Mem,
577577
bool BuildGenKillSet) {
578578
// Construct a MemLocation to represent the memory read by this instruction.
579579
// 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,
624624
}
625625
}
626626

627-
void DSEContext::processWrite(SILInstruction *I, DSEBBState *S, SILValue Val,
627+
void DSEContext::processWrite(SILInstruction *I, BlockState *S, SILValue Val,
628628
SILValue Mem, bool BuildGenKillSet) {
629629
// Construct a MemLocation to represent the memory read by this instruction.
630630
// 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,
741741

742742
void DSEContext::processLoadInst(SILInstruction *I, bool BuildGenKillSet) {
743743
SILValue Mem = cast<LoadInst>(I)->getOperand();
744-
processRead(I, getBBLocState(I), Mem, BuildGenKillSet);
744+
processRead(I, getBlockState(I), Mem, BuildGenKillSet);
745745
}
746746

747747
void DSEContext::processStoreInst(SILInstruction *I, bool BuildGenKillSet) {
748748
SILValue Val = cast<StoreInst>(I)->getSrc();
749749
SILValue Mem = cast<StoreInst>(I)->getDest();
750-
processWrite(I, getBBLocState(I), Val, Mem, BuildGenKillSet);
750+
processWrite(I, getBlockState(I), Val, Mem, BuildGenKillSet);
751751
}
752752

753753
void DSEContext::processDebugValueAddrInst(SILInstruction *I) {
754-
DSEBBState *S = getBBLocState(I);
754+
BlockState *S = getBlockState(I);
755755
SILValue Mem = cast<DebugValueAddrInst>(I)->getOperand();
756756
for (unsigned i = 0; i < S->WriteSetOut.size(); ++i) {
757757
if (!S->isTrackingMemLocation(i))
758758
continue;
759759
if (AA->isNoAlias(Mem, MemLocationVault[i].getBase()))
760760
continue;
761-
getBBLocState(I)->stopTrackingMemLocation(i);
761+
getBlockState(I)->stopTrackingMemLocation(i);
762762
}
763763
}
764764

765765
void DSEContext::processUnknownReadMemInst(SILInstruction *I,
766766
bool BuildGenKillSet) {
767-
DSEBBState *S = getBBLocState(I);
767+
BlockState *S = getBlockState(I);
768768
// Update the gen kill set.
769769
if (BuildGenKillSet) {
770770
for (unsigned i = 0; i < S->MemLocationNum; ++i) {
@@ -784,7 +784,7 @@ void DSEContext::processUnknownReadMemInst(SILInstruction *I,
784784
continue;
785785
if (!AA->mayReadFromMemory(I, MemLocationVault[i].getBase()))
786786
continue;
787-
getBBLocState(I)->stopTrackingMemLocation(i);
787+
getBlockState(I)->stopTrackingMemLocation(i);
788788
}
789789
}
790790

@@ -851,15 +851,15 @@ void DSEContext::run() {
851851
// vector to the appropriate size.
852852
//
853853
// 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
855855
// pointer in BBToLocState to access them.
856856
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());
859859
}
860860

861861
// Initialize the BBToLocState mapping.
862-
for (auto &S : DSEBBStates) {
862+
for (auto &S : BlockStates) {
863863
BBToLocState[S.getBB()] = &S;
864864
}
865865

@@ -894,13 +894,13 @@ void DSEContext::run() {
894894
// Finally, delete the dead stores and create the live stores.
895895
for (SILBasicBlock &BB : *F) {
896896
// 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) {
898898
SILInstruction *IT = cast<SILInstruction>(I.first)->getNextNode();
899899
SILBuilderWithScope Builder(IT);
900900
Builder.createStore(I.first.getLoc().getValue(), I.second, I.first);
901901
}
902902
// Delete the dead stores.
903-
for (auto &I : getBBLocState(&BB)->DeadStores) {
903+
for (auto &I : getBlockState(&BB)->DeadStores) {
904904
DEBUG(llvm::dbgs() << "*** Removing: " << *I << " ***\n");
905905
// This way, we get rid of pass dependence on DCE.
906906
recursivelyDeleteTriviallyDeadInstructions(I, true);

0 commit comments

Comments
 (0)