Skip to content

Commit 4ad25e9

Browse files
committed
[SSADestroyHoisting] Extracted classifying insts.
Extract code for classifying instructions out of the one data flow where it is currently used into the DeinitBarriers type. This will facilitate a second data flow which needs to access the same info and adding an isBarrier member function to DeinitBarriers for use by folding.
1 parent 304d2bb commit 4ad25e9

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

lib/SILOptimizer/Transforms/SSADestroyHoisting.cpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,27 @@ class DeinitBarriers {
225225
const KnownStorageUses &knownUses;
226226
SILInstruction *storageDefInst = nullptr;
227227

228+
enum class Classification { DeadUser, Barrier, Other };
229+
230+
Classification classifyInstruction(SILInstruction *inst) {
231+
return classifyInstruction(inst, ignoreDeinitBarriers, storageDefInst,
232+
knownUses);
233+
}
234+
235+
static Classification classifyInstruction(SILInstruction *inst,
236+
bool ignoreDeinitBarriers,
237+
SILInstruction *storageDefInst,
238+
const KnownStorageUses &knownUses);
239+
240+
void visitedInstruction(SILInstruction *instruction,
241+
Classification classification);
242+
243+
static bool classificationIsBarrier(Classification classification);
244+
228245
// Implements BackwardReachability::BlockReachability
229246
class DestroyReachability {
230247
DeinitBarriers &result;
231248

232-
enum class Classification { DeadUser, Barrier, Other };
233-
234249
BackwardReachability<DestroyReachability> reachability;
235250

236251
public:
@@ -254,13 +269,6 @@ class DeinitBarriers {
254269
result.destroyReachesEndBlocks.insert(block);
255270
}
256271

257-
Classification classifyInstruction(SILInstruction *inst);
258-
259-
bool classificationIsBarrier(Classification classification);
260-
261-
void visitedInstruction(SILInstruction *instruction,
262-
Classification classification);
263-
264272
bool checkReachableBarrier(SILInstruction *);
265273

266274
bool checkReachablePhiBarrier(SILBasicBlock *);
@@ -269,25 +277,25 @@ class DeinitBarriers {
269277
};
270278
};
271279

272-
DeinitBarriers::DestroyReachability::Classification
273-
DeinitBarriers::DestroyReachability::classifyInstruction(SILInstruction *inst) {
274-
if (result.knownUses.debugInsts.contains(inst)) {
280+
DeinitBarriers::Classification DeinitBarriers::classifyInstruction(
281+
SILInstruction *inst, bool ignoreDeinitBarriers,
282+
SILInstruction *storageDefInst, const KnownStorageUses &knownUses) {
283+
if (knownUses.debugInsts.contains(inst)) {
275284
return Classification::DeadUser;
276285
}
277-
if (inst == result.storageDefInst) {
286+
if (inst == storageDefInst) {
278287
return Classification::Barrier;
279288
}
280-
if (result.knownUses.storageUsers.contains(inst)) {
289+
if (knownUses.storageUsers.contains(inst)) {
281290
return Classification::Barrier;
282291
}
283-
if (!result.ignoreDeinitBarriers && isDeinitBarrier(inst)) {
292+
if (!ignoreDeinitBarriers && isDeinitBarrier(inst)) {
284293
return Classification::Barrier;
285294
}
286295
return Classification::Other;
287296
}
288297

289-
bool DeinitBarriers::DestroyReachability::classificationIsBarrier(
290-
Classification classification) {
298+
bool DeinitBarriers::classificationIsBarrier(Classification classification) {
291299
switch (classification) {
292300
case Classification::DeadUser:
293301
case Classification::Other:
@@ -298,15 +306,15 @@ bool DeinitBarriers::DestroyReachability::classificationIsBarrier(
298306
llvm_unreachable("exhaustive switch is not exhaustive?!");
299307
}
300308

301-
void DeinitBarriers::DestroyReachability::visitedInstruction(
302-
SILInstruction *instruction, Classification classification) {
309+
void DeinitBarriers::visitedInstruction(SILInstruction *instruction,
310+
Classification classification) {
303311
assert(classifyInstruction(instruction) == classification);
304312
switch (classification) {
305313
case Classification::DeadUser:
306-
result.deadUsers.push_back(instruction);
314+
deadUsers.push_back(instruction);
307315
break;
308316
case Classification::Barrier:
309-
result.barriers.push_back(instruction);
317+
barriers.push_back(instruction);
310318
break;
311319
case Classification::Other:
312320
break;
@@ -321,18 +329,18 @@ void DeinitBarriers::DestroyReachability::visitedInstruction(
321329
/// which is a storageUser and therefore a barrier.
322330
bool DeinitBarriers::DestroyReachability::checkReachableBarrier(
323331
SILInstruction *instruction) {
324-
auto classification = classifyInstruction(instruction);
325-
visitedInstruction(instruction, classification);
326-
return classificationIsBarrier(classification);
332+
auto classification = result.classifyInstruction(instruction);
333+
result.visitedInstruction(instruction, classification);
334+
return result.classificationIsBarrier(classification);
327335
}
328336

329337
bool DeinitBarriers::DestroyReachability::checkReachablePhiBarrier(
330338
SILBasicBlock *block) {
331339
assert(llvm::all_of(block->getArguments(),
332340
[&](auto argument) { return PhiValue(argument); }));
333341
return llvm::any_of(block->getPredecessorBlocks(), [&](auto *predecessor) {
334-
return classificationIsBarrier(
335-
classifyInstruction(predecessor->getTerminator()));
342+
return result.classificationIsBarrier(
343+
result.classifyInstruction(predecessor->getTerminator()));
336344
});
337345
}
338346

0 commit comments

Comments
 (0)