47
47
// / minimum number of stores possible using the reduce function. This is done
48
48
// / so that we do not bloat SIL IR.
49
49
// /
50
+ // / Another way to implement the DSE optimization is to keep the instructions
51
+ // / that read and/or write memory without breaking the memory read/written
52
+ // / using the ProjectionPath. However, this can easily lead to loss of
53
+ // / opportunities, e.g. a read that only kills part of a store may need to be
54
+ // / treated as killing the entire store. However, using ProjectionPath does
55
+ // / lead to more memory uses.
56
+ // /
50
57
// / TODO: Handle same value store in DSE, currently handled in RLE.
51
58
// /
52
59
// / e.g.
@@ -144,7 +151,7 @@ class BBState {
144
151
SILBasicBlock *BB;
145
152
146
153
// / Keep the number of MemLocations in the LocationVault.
147
- unsigned MemLocationCount ;
154
+ unsigned MemLocationNum ;
148
155
149
156
// / A bit vector for which the ith bit represents the ith MemLocation in
150
157
// / MemLocationVault. If the bit is set, then the location currently has an
@@ -180,7 +187,7 @@ class BBState {
180
187
SILBasicBlock *getBB () const { return BB; }
181
188
182
189
void init (unsigned lcnt) {
183
- MemLocationCount = lcnt;
190
+ MemLocationNum = lcnt;
184
191
// The initial state of WriteSetIn should be all 1's. Otherwise the
185
192
// dataflow solution could be too conservative.
186
193
//
@@ -194,12 +201,12 @@ class BBState {
194
201
// However, by doing so, we can only eliminate the dead stores after the
195
202
// data flow stablizes.
196
203
//
197
- WriteSetIn.resize (MemLocationCount , true );
198
- WriteSetOut.resize (MemLocationCount , false );
204
+ WriteSetIn.resize (MemLocationNum , true );
205
+ WriteSetOut.resize (MemLocationNum , false );
199
206
200
207
// GenSet and KillSet initially empty.
201
- BBGenSet.resize (MemLocationCount , false );
202
- BBKillSet.resize (MemLocationCount , false );
208
+ BBGenSet.resize (MemLocationNum , false );
209
+ BBKillSet.resize (MemLocationNum , false );
203
210
}
204
211
205
212
// / Check whether the WriteSetIn has changed. If it does, we need to rerun
@@ -474,7 +481,7 @@ void DSEContext::invalidateMemLocationBase(SILInstruction *I,
474
481
// invalidate any locations with the same base.
475
482
BBState *S = getBBLocState (I);
476
483
if (BuildGenKillSet) {
477
- for (unsigned i = 0 ; i < S->MemLocationCount ; ++i) {
484
+ for (unsigned i = 0 ; i < S->MemLocationNum ; ++i) {
478
485
if (MemLocationVault[i].getBase ().getDef () != I)
479
486
continue ;
480
487
S->BBGenSet .reset (i);
@@ -483,7 +490,7 @@ void DSEContext::invalidateMemLocationBase(SILInstruction *I,
483
490
return ;
484
491
}
485
492
486
- for (unsigned i = 0 ; i < S->MemLocationCount ; ++i) {
493
+ for (unsigned i = 0 ; i < S->MemLocationNum ; ++i) {
487
494
if (!S->WriteSetOut .test (i))
488
495
continue ;
489
496
if (MemLocationVault[i].getBase ().getDef () != I)
@@ -496,7 +503,7 @@ void DSEContext::updateWriteSetForRead(BBState *S, unsigned bit) {
496
503
// Remove any may/must-aliasing stores to the MemLocation, as they cant be
497
504
// used to kill any upward visible stores due to the intefering load.
498
505
MemLocation &R = MemLocationVault[bit];
499
- for (unsigned i = 0 ; i < S->MemLocationCount ; ++i) {
506
+ for (unsigned i = 0 ; i < S->MemLocationNum ; ++i) {
500
507
if (!S->isTrackingMemLocation (i))
501
508
continue ;
502
509
MemLocation &L = MemLocationVault[i];
@@ -512,7 +519,7 @@ void DSEContext::updateGenKillSetForRead(BBState *S, unsigned bit) {
512
519
// Start tracking the read to this MemLocation in the killset and update
513
520
// the genset accordingly.
514
521
MemLocation &R = MemLocationVault[bit];
515
- for (unsigned i = 0 ; i < S->MemLocationCount ; ++i) {
522
+ for (unsigned i = 0 ; i < S->MemLocationNum ; ++i) {
516
523
MemLocation &L = MemLocationVault[i];
517
524
if (!L.isMayAliasMemLocation (R, AA))
518
525
continue ;
@@ -527,7 +534,7 @@ bool DSEContext::updateWriteSetForWrite(BBState *S, unsigned bit) {
527
534
// If a tracked store must aliases with this store, then this store is dead.
528
535
bool IsDead = false ;
529
536
MemLocation &R = MemLocationVault[bit];
530
- for (unsigned i = 0 ; i < S->MemLocationCount ; ++i) {
537
+ for (unsigned i = 0 ; i < S->MemLocationNum ; ++i) {
531
538
if (!S->isTrackingMemLocation (i))
532
539
continue ;
533
540
// If 2 locations may alias, we can still keep both stores.
@@ -744,7 +751,7 @@ void DSEContext::processUnknownReadMemInst(SILInstruction *I,
744
751
BBState *S = getBBLocState (I);
745
752
// Update the gen kill set.
746
753
if (BuildGenKillSet) {
747
- for (unsigned i = 0 ; i < S->MemLocationCount ; ++i) {
754
+ for (unsigned i = 0 ; i < S->MemLocationNum ; ++i) {
748
755
if (!AA->mayReadFromMemory (I, MemLocationVault[i].getBase ()))
749
756
continue ;
750
757
S->BBKillSet .set (i);
@@ -756,7 +763,7 @@ void DSEContext::processUnknownReadMemInst(SILInstruction *I,
756
763
// We do not know what this instruction does or the memory that it *may*
757
764
// touch. Hand it to alias analysis to see whether we need to invalidate
758
765
// any MemLocation.
759
- for (unsigned i = 0 ; i < S->MemLocationCount ; ++i) {
766
+ for (unsigned i = 0 ; i < S->MemLocationNum ; ++i) {
760
767
if (!S->isTrackingMemLocation (i))
761
768
continue ;
762
769
if (!AA->mayReadFromMemory (I, MemLocationVault[i].getBase ()))
@@ -827,10 +834,9 @@ void DSEContext::run() {
827
834
// know all the locations accessed in this function, we can resize the bit
828
835
// vector to the approproate size.
829
836
//
830
- // DenseMap has a minimum size of 64, while many functions do not have over
831
- // 64 basic blocks. Therefore, allocate the BBState in a vector and use
832
- // pointer
833
- // in BBToLocState to access them.
837
+ // DenseMap has a minimum size of 64, while many functions do not have more
838
+ // than 64 basic blocks. Therefore, allocate the BBState in a vector and use
839
+ // pointer in BBToLocState to access them.
834
840
for (auto &B : *F) {
835
841
BBStates.push_back (BBState (&B));
836
842
BBStates.back ().init (MemLocationVault.size ());
@@ -871,7 +877,7 @@ void DSEContext::run() {
871
877
872
878
// Finally, delete the dead stores and create the live stores.
873
879
for (SILBasicBlock &BB : *F) {
874
- // Create the stores that are alive.
880
+ // Create the stores that are alive due to partial dead stores .
875
881
for (auto &I : getBBLocState (&BB)->LiveStores ) {
876
882
SILInstruction *IT = cast<SILInstruction>(I.first )->getNextNode ();
877
883
SILBuilderWithScope Builder (IT);
0 commit comments