78
78
79
79
using namespace swift ;
80
80
81
+ // / If a large store is broken down to too many smaller stores, bail out.
82
+ // / Currently, we only do partial dead store if we can form a single contiguous
83
+ // / non-dead store.
84
+ static llvm::cl::opt<unsigned > MaxPartialStoreCount (" max-partial-store-count" ,
85
+ llvm::cl::init (1 ), llvm::cl::Hidden);
86
+
81
87
STATISTIC (NumDeadStores, " Number of dead stores removed" );
82
88
STATISTIC (NumPartialDeadStores, " Number of partial dead stores removed" );
83
89
@@ -163,10 +169,6 @@ constexpr unsigned MaxLSLocationBBMultiplicationNone = 256*256;
163
169
// / and 64 locations which is a sizeable function.
164
170
constexpr unsigned MaxLSLocationBBMultiplicationPessimistic = 64 *64 ;
165
171
166
- // / If a large store is broken down to too many smaller stores, bail out.
167
- // / Currently, we only do partial dead store if we can form a single contiguous
168
- // / non-dead store.
169
- constexpr unsigned MaxPartialDeadStoreCountLimit = 1 ;
170
172
171
173
// / forward declaration.
172
174
class DSEContext ;
@@ -246,6 +248,7 @@ class BlockState {
246
248
// /
247
249
// / The first SILValue keeps the address of the live store and the second
248
250
// / SILValue keeps the value of the store.
251
+ llvm::SetVector<SILValue> LiveAddr;
249
252
llvm::DenseMap<SILValue, SILValue> LiveStores;
250
253
251
254
// / Constructors.
@@ -956,7 +959,7 @@ void DSEContext::processWrite(SILInstruction *I, SILValue Val, SILValue Mem,
956
959
LSLocation::reduce (L, Mod, Alives);
957
960
958
961
// Oops, we have too many smaller stores generated, bail out.
959
- if (Alives.size () > MaxPartialDeadStoreCountLimit )
962
+ if (Alives.size () > MaxPartialStoreCount )
960
963
return ;
961
964
962
965
// At this point, we are performing a partial dead store elimination.
@@ -976,6 +979,7 @@ void DSEContext::processWrite(SILInstruction *I, SILValue Val, SILValue Mem,
976
979
for (auto &X : Alives) {
977
980
SILValue Value = X.getPath ()->createExtract (Val, I, true );
978
981
SILValue Addr = X.getPath ()->createExtract (Mem, I, false );
982
+ S->LiveAddr .insert (Addr);
979
983
S->LiveStores [Addr] = Value;
980
984
}
981
985
@@ -1200,12 +1204,14 @@ bool DSEContext::run() {
1200
1204
bool Changed = false ;
1201
1205
for (SILBasicBlock &BB : *F) {
1202
1206
// Create the stores that are alive due to partial dead stores.
1203
- for (auto &I : getBlockState (&BB)->LiveStores ) {
1207
+ auto *S = getBlockState (&BB);
1208
+ for (auto &X : S->LiveAddr ) {
1204
1209
Changed = true ;
1205
- SILInstruction *Inst = cast<SILInstruction>(I.first );
1210
+ auto I = S->LiveStores .find (X);
1211
+ SILInstruction *Inst = cast<SILInstruction>(I->first );
1206
1212
auto *IT = &*std::next (Inst->getIterator ());
1207
1213
SILBuilderWithScope Builder (IT);
1208
- Builder.createStore (Inst->getLoc (), I. second , Inst);
1214
+ Builder.createStore (Inst->getLoc (), I-> second , Inst);
1209
1215
}
1210
1216
// Delete the dead stores.
1211
1217
for (auto &I : getBlockState (&BB)->DeadStores ) {
0 commit comments