Skip to content

Commit 25f1743

Browse files
Xin TongXin Tong
authored andcommitted
[RLE-DSE] Refactor in RLE, move declarations around. NFC
1 parent f431025 commit 25f1743

File tree

1 file changed

+94
-92
lines changed

1 file changed

+94
-92
lines changed

lib/SILPasses/Scalar/RedundantLoadElimination.cpp

Lines changed: 94 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -156,103 +156,13 @@ static bool isForwardableEdge(SILBasicBlock *BB) {
156156
return false;
157157
}
158158

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-
251159
//===----------------------------------------------------------------------===//
252160
// Basic Block Location State
253161
//===----------------------------------------------------------------------===//
254162
namespace {
255163

164+
/// forward declaration.
165+
class RLEContext;
256166
/// State of the load store in one basic block which allows for forwarding from
257167
/// loads, stores -> loads
258168
class BBState {
@@ -385,6 +295,98 @@ class BBState {
385295

386296
} // end anonymous namespace
387297

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+
388390
bool BBState::isTrackingMemLocation(unsigned bit) {
389391
return ForwardSetIn.test(bit);
390392
}

0 commit comments

Comments
 (0)