|
38 | 38 | /// 4. An optimistic iterative intersection-based dataflow is performed on the
|
39 | 39 | /// gen sets until convergence.
|
40 | 40 | ///
|
41 |
| -/// At the core of RLE, there is the MemLocation class. a MemLocation is an |
| 41 | +/// At the core of RLE, there is the MemLocation class. A MemLocation is an |
42 | 42 | /// abstraction of an object field in program. It consists of a base and a
|
43 | 43 | /// projection path to the field accessed.
|
44 | 44 | ///
|
|
48 | 48 | /// keeps their available LoadStoreValues. We call it *indivisible* because it
|
49 | 49 | /// can not be broken down to more MemLocations.
|
50 | 50 | ///
|
51 |
| -/// LoadStoreValues consists of a base - a SILValue from the load or store inst, |
| 51 | +/// LoadStoreValue consists of a base - a SILValue from the load or store inst, |
52 | 52 | /// as well as a projection path to which the field it represents. So, a
|
53 | 53 | /// store to an 2-field struct as mentioned above will generate 2 MemLocations
|
54 | 54 | /// and 2 LoadStoreValues.
|
55 | 55 | ///
|
56 |
| -/// Every basic block keeps a map between MemLocation <-> LoadStoreValue. By |
| 56 | +/// Every basic block keeps a map between MemLocation and LoadStoreValue. By |
57 | 57 | /// keeping the MemLocation and LoadStoreValue in their indivisible form, one
|
58 | 58 | /// can easily find which part of the load is redundant and how to compute its
|
59 | 59 | /// forwarding value.
|
|
74 | 74 | //===----------------------------------------------------------------------===//
|
75 | 75 |
|
76 | 76 | #define DEBUG_TYPE "sil-redundant-load-elim"
|
77 |
| -#include "swift/SILPasses/Passes.h" |
78 | 77 | #include "swift/SIL/MemLocation.h"
|
79 | 78 | #include "swift/SIL/Projection.h"
|
80 | 79 | #include "swift/SIL/SILArgument.h"
|
|
83 | 82 | #include "swift/SILAnalysis/DominanceAnalysis.h"
|
84 | 83 | #include "swift/SILAnalysis/PostOrderAnalysis.h"
|
85 | 84 | #include "swift/SILAnalysis/ValueTracking.h"
|
| 85 | +#include "swift/SILPasses/Passes.h" |
| 86 | +#include "swift/SILPasses/Transforms.h" |
86 | 87 | #include "swift/SILPasses/Utils/CFG.h"
|
87 | 88 | #include "swift/SILPasses/Utils/Local.h"
|
88 | 89 | #include "swift/SILPasses/Utils/SILSSAUpdater.h"
|
89 |
| -#include "swift/SILPasses/Transforms.h" |
90 | 90 | #include "llvm/ADT/BitVector.h"
|
91 |
| -#include "llvm/Support/CommandLine.h" |
92 |
| -#include "llvm/Support/Debug.h" |
93 | 91 | #include "llvm/ADT/MapVector.h"
|
94 | 92 | #include "llvm/ADT/None.h"
|
95 | 93 | #include "llvm/ADT/Statistic.h"
|
96 | 94 | #include "llvm/ADT/TinyPtrVector.h"
|
| 95 | +#include "llvm/Support/CommandLine.h" |
| 96 | +#include "llvm/Support/Debug.h" |
97 | 97 |
|
98 | 98 | using namespace swift;
|
99 | 99 |
|
@@ -169,19 +169,14 @@ class BBState {
|
169 | 169 | /// A bit vector for which the ith bit represents the ith MemLocation in
|
170 | 170 | /// MemLocationVault. If the bit is set, then the location currently has an
|
171 | 171 | /// downward visible value.
|
172 |
| - llvm::BitVector ForwardSetOut; |
173 |
| - |
174 |
| - /// If ForwardSetIn changes while processing a basicblock, then all its |
175 |
| - /// predecessors needs to be rerun. |
176 | 172 | llvm::BitVector ForwardSetIn;
|
177 | 173 |
|
178 |
| - /// This is a list of MemLocations and their LoadStoreValues. |
179 |
| - /// |
180 |
| - /// TODO: can we create a LoadStoreValue vault so that we do not need to keep |
181 |
| - /// them per basic block. This would also give ForwardValIn more symmetry. |
182 |
| - /// i.e. MemLocation and LoadStoreValue both represented as bit vector |
183 |
| - /// indices. |
184 |
| - /// |
| 174 | + /// If ForwardSetOut changes while processing a basicblock, then all its |
| 175 | + /// successors need to be rerun. |
| 176 | + llvm::BitVector ForwardSetOut; |
| 177 | + |
| 178 | + /// This is map between MemLocations and their available values at the |
| 179 | + /// beginning of this basic block. |
185 | 180 | ValueTableMap ForwardValIn;
|
186 | 181 |
|
187 | 182 | /// This is map between MemLocations and their available values at the end of
|
@@ -255,15 +250,17 @@ class BBState {
|
255 | 250 | ForwardSetOut.resize(bitcnt, reachable);
|
256 | 251 | }
|
257 | 252 |
|
| 253 | + /// Returns the current basic block we are processing. |
| 254 | + SILBasicBlock *getBB() const { return BB; } |
| 255 | + |
258 | 256 | /// Returns the ForwardValIn for the current basic block.
|
259 | 257 | ValueTableMap &getForwardValIn() { return ForwardValIn; }
|
260 | 258 |
|
261 | 259 | /// Returns the ForwardValOut for the current basic block.
|
262 | 260 | ValueTableMap &getForwardValOut() { return ForwardValOut; }
|
263 | 261 |
|
264 |
| - /// Returns the current basic block we are processing. |
265 |
| - SILBasicBlock *getBB() const { return BB; } |
266 |
| - |
| 262 | + /// Returns the redundant loads and their replacement in the currently basic |
| 263 | + /// block. |
267 | 264 | llvm::DenseMap<SILInstruction *, SILValue> &getRL() { return RedundantLoads; }
|
268 | 265 |
|
269 | 266 | bool optimize(RLEContext &Ctx, bool PF);
|
@@ -299,9 +296,8 @@ class BBState {
|
299 | 296 |
|
300 | 297 | namespace {
|
301 | 298 |
|
302 |
| -/// This class stores global state that we use when processing and also drives |
303 |
| -/// the computation. We put its interface at the top for use in other parts of |
304 |
| -/// the pass which may want to use this global information. |
| 299 | +/// This class stores global state that we use when computing redudant load and |
| 300 | +/// their replacement in each basic block. |
305 | 301 | class RLEContext {
|
306 | 302 | /// The alias analysis that we will use during all computations.
|
307 | 303 | AliasAnalysis *AA;
|
@@ -373,13 +369,6 @@ class RLEContext {
|
373 | 369 | /// collect forwarding values from their ForwardValOuts.
|
374 | 370 | bool gatherValues(SILBasicBlock *B, MemLocation &L, MemLocationValueMap &Vs,
|
375 | 371 | bool UseForwardValOut);
|
376 |
| - |
377 |
| - /// Dump all the MemLocations in the MemLocationVault. |
378 |
| - void printMemLocationVault() const { |
379 |
| - for (auto &X : MemLocationVault) { |
380 |
| - X.print(); |
381 |
| - } |
382 |
| - } |
383 | 372 | };
|
384 | 373 |
|
385 | 374 | } // end anonymous namespace
|
|
0 commit comments