|
| 1 | +//===--- DeadEndBlocksAnalysis.cpp ----------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h" |
| 14 | +#include "swift/AST/Decl.h" |
| 15 | +#include "swift/SIL/SILFunction.h" |
| 16 | + |
| 17 | +using namespace swift; |
| 18 | + |
| 19 | +void DeadEndBlocksAnalysis::verify(DeadEndBlocks *deBlocks) const { |
| 20 | + // If the passed in deBlocks has not computed, there is nothing to check. |
| 21 | + if (!deBlocks->isComputed()) |
| 22 | + return; |
| 23 | + |
| 24 | + // Then create our new dead end blocks instance so we can check the internal |
| 25 | + // state of our input against it. |
| 26 | + auto *fn = deBlocks->getFunction(); |
| 27 | + DeadEndBlocks newBlocks(fn); |
| 28 | + |
| 29 | + // Make sure that all values that deBlocks thinks is unreachable are |
| 30 | + // actually unreachable. |
| 31 | + // |
| 32 | + // NOTE: We verify like this b/c DeadEndBlocks looks up state lazily so we |
| 33 | + // can only check the work we have done so far. |
| 34 | + for (auto &block : *fn) { |
| 35 | + if (deBlocks->isDeadEnd(&block)) { |
| 36 | + if (!newBlocks.isDeadEnd(&block)) { |
| 37 | + llvm::errs() << "DeadEndBlocksAnalysis Error! Found dead end block " |
| 38 | + "that is no longer a dead end block?!"; |
| 39 | + llvm_unreachable("standard error assertion"); |
| 40 | + } |
| 41 | + } else { |
| 42 | + if (newBlocks.isDeadEnd(&block)) { |
| 43 | + llvm::errs() << "DeadEndBlocksAnalysis Error! Found reachable block " |
| 44 | + "that is no longer reachable?!"; |
| 45 | + llvm_unreachable("standard error assertion"); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +//===----------------------------------------------------------------------===// |
| 52 | +// Main Entry Point |
| 53 | +//===----------------------------------------------------------------------===// |
| 54 | + |
| 55 | +SILAnalysis *swift::createDeadEndBlocksAnalysis(SILModule *) { |
| 56 | + return new DeadEndBlocksAnalysis(); |
| 57 | +} |
0 commit comments