@@ -156,103 +156,13 @@ static bool isForwardableEdge(SILBasicBlock *BB) {
156
156
return false ;
157
157
}
158
158
159
- // ===----------------------------------------------------------------------===//
160
- // RLEContext Interface
161
- // ===----------------------------------------------------------------------===//
162
-
163
- namespace {
164
-
165
- class BBState ;
166
- // / This class stores global state that we use when processing and also drives
167
- // / the computation. We put its interface at the top for use in other parts of
168
- // / the pass which may want to use this global information.
169
- class RLEContext {
170
- // / The alias analysis that we will use during all computations.
171
- AliasAnalysis *AA;
172
-
173
- // / The range that we use to iterate over the reverse post order of the given
174
- // / function.
175
- PostOrderFunctionInfo::reverse_range ReversePostOrder;
176
-
177
- // / Keeps all the locations for the current function. The BitVector in each
178
- // / BBState is then laid on top of it to keep track of which MemLocation
179
- // / has a downward available value.
180
- std::vector<MemLocation> MemLocationVault;
181
-
182
- // / Caches a list of projection paths to leaf nodes in the given type.
183
- TypeExpansionMap TypeExpansionCache;
184
-
185
- // / Contains a map between MemLocation to their index in the MemLocationVault.
186
- // / Use for fast lookup.
187
- llvm::DenseMap<MemLocation, unsigned > LocToBitIndex;
188
-
189
- // / A map from each BasicBlock to its BBState.
190
- llvm::DenseMap<SILBasicBlock *, BBState> BBToLocState;
191
-
192
- // / A map for each basic block and whether its predecessors have forwardable
193
- // / edges.
194
- llvm::DenseMap<SILBasicBlock *, bool > ForwardableEdge;
195
-
196
- public:
197
- RLEContext (SILFunction *F, AliasAnalysis *AA,
198
- PostOrderFunctionInfo::reverse_range RPOT);
199
-
200
- RLEContext (const RLEContext &) = delete ;
201
- RLEContext (RLEContext &&) = default ;
202
- ~RLEContext () = default ;
203
-
204
- bool run ();
205
-
206
- // / Returns the alias analysis we will use during all computations.
207
- AliasAnalysis *getAA () const { return AA; }
208
-
209
- // / Returns the TypeExpansionCache we will use during expanding MemLocations.
210
- TypeExpansionMap &getTypeExpansionCache () { return TypeExpansionCache; }
211
-
212
- // / Return the BBState for the basic block this basic block belongs to.
213
- BBState &getBBLocState (SILBasicBlock *B) { return BBToLocState[B]; }
214
-
215
- // / Get the bit representing the MemLocation in the MemLocationVault.
216
- unsigned getMemLocationBit (const MemLocation &L);
217
-
218
- // / Given the bit, get the MemLocation from the MemLocationVault.
219
- MemLocation &getMemLocation (const unsigned index);
220
-
221
- // / Go to the predecessors of the given basic block, compute the value
222
- // / for the given MemLocation.
223
- SILValue computePredecessorCoveringValue (SILBasicBlock *B, MemLocation &L);
224
-
225
- // / Return true if all the predecessors of the basic block can have
226
- // / BBArgument.
227
- bool withTransistivelyForwardableEdges (SILBasicBlock *BB);
228
-
229
- // / Given a MemLocation, try to collect all the LoadStoreValues for this
230
- // / MemLocation in the given basic block. If a LoadStoreValue is a covering
231
- // / value, collectForwardingValues also create a SILArgument for it. As a
232
- // / a result, collectForwardingValues may invalidate TerminatorInsts for
233
- // / basic blocks.
234
- // /
235
- // / UseForwardValOut tells whether to use the ForwardValOut or not. i.e.
236
- // / when materialize a covering value, we go to each predecessors and
237
- // / collect forwarding values from their ForwardValOuts.
238
- bool gatherValues (SILBasicBlock *B, MemLocation &L, MemLocationValueMap &Vs,
239
- bool UseForwardValOut);
240
-
241
- // / Dump all the MemLocations in the MemLocationVault.
242
- void printMemLocationVault () const {
243
- for (auto &X : MemLocationVault) {
244
- X.print ();
245
- }
246
- }
247
- };
248
-
249
- } // end anonymous namespace
250
-
251
159
// ===----------------------------------------------------------------------===//
252
160
// Basic Block Location State
253
161
// ===----------------------------------------------------------------------===//
254
162
namespace {
255
163
164
+ // / forward declaration.
165
+ class RLEContext ;
256
166
// / State of the load store in one basic block which allows for forwarding from
257
167
// / loads, stores -> loads
258
168
class BBState {
@@ -385,6 +295,98 @@ class BBState {
385
295
386
296
} // end anonymous namespace
387
297
298
+
299
+ // ===----------------------------------------------------------------------===//
300
+ // RLEContext Interface
301
+ // ===----------------------------------------------------------------------===//
302
+
303
+ namespace {
304
+
305
+ // / This class stores global state that we use when processing and also drives
306
+ // / the computation. We put its interface at the top for use in other parts of
307
+ // / the pass which may want to use this global information.
308
+ class RLEContext {
309
+ // / The alias analysis that we will use during all computations.
310
+ AliasAnalysis *AA;
311
+
312
+ // / The range that we use to iterate over the reverse post order of the given
313
+ // / function.
314
+ PostOrderFunctionInfo::reverse_range ReversePostOrder;
315
+
316
+ // / Keeps all the locations for the current function. The BitVector in each
317
+ // / BBState is then laid on top of it to keep track of which MemLocation
318
+ // / has a downward available value.
319
+ std::vector<MemLocation> MemLocationVault;
320
+
321
+ // / Caches a list of projection paths to leaf nodes in the given type.
322
+ TypeExpansionMap TypeExpansionCache;
323
+
324
+ // / Contains a map between MemLocation to their index in the MemLocationVault.
325
+ // / Use for fast lookup.
326
+ llvm::DenseMap<MemLocation, unsigned > LocToBitIndex;
327
+
328
+ // / A map from each BasicBlock to its BBState.
329
+ llvm::DenseMap<SILBasicBlock *, BBState> BBToLocState;
330
+
331
+ // / A map for each basic block and whether its predecessors have forwardable
332
+ // / edges.
333
+ llvm::DenseMap<SILBasicBlock *, bool > ForwardableEdge;
334
+
335
+ public:
336
+ RLEContext (SILFunction *F, AliasAnalysis *AA,
337
+ PostOrderFunctionInfo::reverse_range RPOT);
338
+
339
+ RLEContext (const RLEContext &) = delete ;
340
+ RLEContext (RLEContext &&) = default ;
341
+ ~RLEContext () = default ;
342
+
343
+ bool run ();
344
+
345
+ // / Returns the alias analysis we will use during all computations.
346
+ AliasAnalysis *getAA () const { return AA; }
347
+
348
+ // / Returns the TypeExpansionCache we will use during expanding MemLocations.
349
+ TypeExpansionMap &getTypeExpansionCache () { return TypeExpansionCache; }
350
+
351
+ // / Return the BBState for the basic block this basic block belongs to.
352
+ BBState &getBBLocState (SILBasicBlock *B) { return BBToLocState[B]; }
353
+
354
+ // / Get the bit representing the MemLocation in the MemLocationVault.
355
+ unsigned getMemLocationBit (const MemLocation &L);
356
+
357
+ // / Given the bit, get the MemLocation from the MemLocationVault.
358
+ MemLocation &getMemLocation (const unsigned index);
359
+
360
+ // / Go to the predecessors of the given basic block, compute the value
361
+ // / for the given MemLocation.
362
+ SILValue computePredecessorCoveringValue (SILBasicBlock *B, MemLocation &L);
363
+
364
+ // / Return true if all the predecessors of the basic block can have
365
+ // / BBArgument.
366
+ bool withTransistivelyForwardableEdges (SILBasicBlock *BB);
367
+
368
+ // / Given a MemLocation, try to collect all the LoadStoreValues for this
369
+ // / MemLocation in the given basic block. If a LoadStoreValue is a covering
370
+ // / value, collectForwardingValues also create a SILArgument for it. As a
371
+ // / a result, collectForwardingValues may invalidate TerminatorInsts for
372
+ // / basic blocks.
373
+ // /
374
+ // / UseForwardValOut tells whether to use the ForwardValOut or not. i.e.
375
+ // / when materialize a covering value, we go to each predecessors and
376
+ // / collect forwarding values from their ForwardValOuts.
377
+ bool gatherValues (SILBasicBlock *B, MemLocation &L, MemLocationValueMap &Vs,
378
+ bool UseForwardValOut);
379
+
380
+ // / Dump all the MemLocations in the MemLocationVault.
381
+ void printMemLocationVault () const {
382
+ for (auto &X : MemLocationVault) {
383
+ X.print ();
384
+ }
385
+ }
386
+ };
387
+
388
+ } // end anonymous namespace
389
+
388
390
bool BBState::isTrackingMemLocation (unsigned bit) {
389
391
return ForwardSetIn.test (bit);
390
392
}
0 commit comments