Files
swift-mirror/include/swift/SILAnalysis/CFG.h
Michael Gottesman 841aa449cf [cfg] Add a new analysis findAllNonFailureExitBBs.
Even though there is only one "return" from a SILFunction, there may be multiple
non-failure exits via no return functions. findAllNonFailureExitBBs

The verifier currently enforces that all no-return function applications must be
immediately followed by an unreachable. Thus to identify all such functions, we
must just visit all unreachables and visit the previous instruction of the
unreachable. If we don't have an apply in such case, then we must be in a
failure code path.

This code attempts to identify all ways of exiting a function in a non-failure
code path. Thus it places into the result vector the return from the BB and all
no-return function applications that it can not identify as a "failure"
function. The function ignores any paths that it identifies as failure paths.

Failure functions will be identified in the future via an @semantic tag but for
now we just check for functions with the appropriate "fatal error" suffix as we
do in the ARC optimizer.

I am going to use this in the closure specializer to insert releases for
"copied" closures that were originally passed in @guaranteed. Since the closure
was passed in originally @guaranteed there will be no matching -1 unless we
insert it ourselves.

Swift SVN r25051
2015-02-06 21:59:53 +00:00

50 lines
1.5 KiB
C++

//===--- CFG.h - Routines which analyze the CFG of a function ---*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SILANALYSIS_CFG_H
#define SWIFT_SILANALYSIS_CFG_H
namespace llvm {
template <typename T> class TinyPtrVector;
} // end namespace llvm
namespace swift {
class SILFunction;
class SILBasicBlock;
/// Return true if we conservativly find all BB's that are non-failure exit
/// basic blocks and place them in \p BBs. If we find something we don't
/// understand, bail.
///
/// A non-failure exit BB is defined as a BB that:
///
/// 1. Has a return terminator.
/// 2. unreachable + noreturn terminator sequence.
///
/// If we just have an unreachable without a noreturn call before it, we must
/// have a failure BB.
///
/// We use a TinyPtrVector since in most cases this will only return one
/// SILBasicBlock since non-failure noreturn functions should not occur often
/// implying in most cases this will be one element.
///
/// TODO:
bool findAllNonFailureExitBBs(SILFunction *F,
llvm::TinyPtrVector<SILBasicBlock *> &BBs);
} // end namespace swift
#endif