Skip to content

Commit 2b5cf8b

Browse files
committed
[RLE-DSE] Refactor RLE. NFC
1 parent 14731ce commit 2b5cf8b

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

lib/SILPasses/Scalar/RedundantLoadElimination.cpp

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
/// 4. An optimistic iterative intersection-based dataflow is performed on the
3939
/// gen sets until convergence.
4040
///
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
4242
/// abstraction of an object field in program. It consists of a base and a
4343
/// projection path to the field accessed.
4444
///
@@ -48,12 +48,12 @@
4848
/// keeps their available LoadStoreValues. We call it *indivisible* because it
4949
/// can not be broken down to more MemLocations.
5050
///
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,
5252
/// as well as a projection path to which the field it represents. So, a
5353
/// store to an 2-field struct as mentioned above will generate 2 MemLocations
5454
/// and 2 LoadStoreValues.
5555
///
56-
/// Every basic block keeps a map between MemLocation <-> LoadStoreValue. By
56+
/// Every basic block keeps a map between MemLocation and LoadStoreValue. By
5757
/// keeping the MemLocation and LoadStoreValue in their indivisible form, one
5858
/// can easily find which part of the load is redundant and how to compute its
5959
/// forwarding value.
@@ -74,7 +74,6 @@
7474
//===----------------------------------------------------------------------===//
7575

7676
#define DEBUG_TYPE "sil-redundant-load-elim"
77-
#include "swift/SILPasses/Passes.h"
7877
#include "swift/SIL/MemLocation.h"
7978
#include "swift/SIL/Projection.h"
8079
#include "swift/SIL/SILArgument.h"
@@ -83,17 +82,18 @@
8382
#include "swift/SILAnalysis/DominanceAnalysis.h"
8483
#include "swift/SILAnalysis/PostOrderAnalysis.h"
8584
#include "swift/SILAnalysis/ValueTracking.h"
85+
#include "swift/SILPasses/Passes.h"
86+
#include "swift/SILPasses/Transforms.h"
8687
#include "swift/SILPasses/Utils/CFG.h"
8788
#include "swift/SILPasses/Utils/Local.h"
8889
#include "swift/SILPasses/Utils/SILSSAUpdater.h"
89-
#include "swift/SILPasses/Transforms.h"
9090
#include "llvm/ADT/BitVector.h"
91-
#include "llvm/Support/CommandLine.h"
92-
#include "llvm/Support/Debug.h"
9391
#include "llvm/ADT/MapVector.h"
9492
#include "llvm/ADT/None.h"
9593
#include "llvm/ADT/Statistic.h"
9694
#include "llvm/ADT/TinyPtrVector.h"
95+
#include "llvm/Support/CommandLine.h"
96+
#include "llvm/Support/Debug.h"
9797

9898
using namespace swift;
9999

@@ -169,19 +169,14 @@ class BBState {
169169
/// A bit vector for which the ith bit represents the ith MemLocation in
170170
/// MemLocationVault. If the bit is set, then the location currently has an
171171
/// 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.
176172
llvm::BitVector ForwardSetIn;
177173

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.
185180
ValueTableMap ForwardValIn;
186181

187182
/// This is map between MemLocations and their available values at the end of
@@ -255,15 +250,17 @@ class BBState {
255250
ForwardSetOut.resize(bitcnt, reachable);
256251
}
257252

253+
/// Returns the current basic block we are processing.
254+
SILBasicBlock *getBB() const { return BB; }
255+
258256
/// Returns the ForwardValIn for the current basic block.
259257
ValueTableMap &getForwardValIn() { return ForwardValIn; }
260258

261259
/// Returns the ForwardValOut for the current basic block.
262260
ValueTableMap &getForwardValOut() { return ForwardValOut; }
263261

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.
267264
llvm::DenseMap<SILInstruction *, SILValue> &getRL() { return RedundantLoads; }
268265

269266
bool optimize(RLEContext &Ctx, bool PF);
@@ -299,9 +296,8 @@ class BBState {
299296

300297
namespace {
301298

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.
305301
class RLEContext {
306302
/// The alias analysis that we will use during all computations.
307303
AliasAnalysis *AA;
@@ -373,13 +369,6 @@ class RLEContext {
373369
/// collect forwarding values from their ForwardValOuts.
374370
bool gatherValues(SILBasicBlock *B, MemLocation &L, MemLocationValueMap &Vs,
375371
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-
}
383372
};
384373

385374
} // end anonymous namespace

0 commit comments

Comments
 (0)