mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SIL: Replace TransitivelyUnreachableBlocks with DeadEndBlocks
We had both utilities doing the same thing. NFC
This commit is contained in:
41
lib/SIL/BasicBlockUtils.cpp
Normal file
41
lib/SIL/BasicBlockUtils.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
//===--- BasicBlockUtils.cpp - Utilities for SILBasicBlock ----------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/SIL/BasicBlockUtils.h"
|
||||
#include "swift/SIL/SILFunction.h"
|
||||
#include "swift/SIL/SILBasicBlock.h"
|
||||
|
||||
using namespace swift;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// DeadEndBlocks
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void DeadEndBlocks::compute() {
|
||||
assert(ReachableBlocks.empty() && "Computed twice");
|
||||
|
||||
// First step: find blocks which end up in a no-return block (terminated by
|
||||
// an unreachable instruction).
|
||||
// Search for function-exiting blocks, i.e. return and throw.
|
||||
for (const SILBasicBlock &BB : *F) {
|
||||
const TermInst *TI = BB.getTerminator();
|
||||
if (TI->isFunctionExiting())
|
||||
ReachableBlocks.insert(&BB);
|
||||
}
|
||||
// Propagate the reachability up the control flow graph.
|
||||
unsigned Idx = 0;
|
||||
while (Idx < ReachableBlocks.size()) {
|
||||
const SILBasicBlock *BB = ReachableBlocks[Idx++];
|
||||
for (SILBasicBlock *Pred : BB->getPredecessorBlocks())
|
||||
ReachableBlocks.insert(Pred);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user