mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This will make the forthcoming CanonicalizeInstruction interface more clear. This is generally the better approach to utilities that mutate the instruction stream. It avoids the temptation to assume that only a single instruction will be deleted or that only instructions before the current iterator will be deleted. This often happens to work but eventually fails in the presense of debug and end-of-scope instructions. A function returning an iterator has a more clear contract than one accepting some iterator reference of unknown providence. Unfortunately, it doesn't work at the lowest level of utilities, such as recursivelyDeleteTriviallyDeadInstructions, where we want to handle instruction batches.
58 lines
2.4 KiB
C++
58 lines
2.4 KiB
C++
//===--- SimplifyInstruction.h - Fold instructions --------------*- C++ -*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// An analysis that provides utilities for folding instructions. Since it is an
|
|
// analysis it does not modify the IR in anyway. This is left to actual
|
|
// SIL Transforms.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_SILOPTIMIZER_ANALYSIS_SIMPLIFYINSTRUCTION_H
|
|
#define SWIFT_SILOPTIMIZER_ANALYSIS_SIMPLIFYINSTRUCTION_H
|
|
|
|
#include "swift/SIL/SILBasicBlock.h"
|
|
#include "swift/SIL/SILInstruction.h"
|
|
|
|
namespace swift {
|
|
|
|
class SILInstruction;
|
|
|
|
/// Try to simplify the specified instruction, performing local
|
|
/// analysis of the operands of the instruction, without looking at its uses
|
|
/// (e.g. constant folding). If a simpler result can be found, it is
|
|
/// returned, otherwise a null SILValue is returned.
|
|
SILValue simplifyInstruction(SILInstruction *I);
|
|
|
|
/// Replace an instruction with a simplified result and erase it. If the
|
|
/// instruction initiates a scope, do not replace the end of its scope; it will
|
|
/// be deleted along with its parent.
|
|
///
|
|
/// If it is nonnull, eraseNotify will be called before each instruction is
|
|
/// deleted.
|
|
SILBasicBlock::iterator replaceAllSimplifiedUsesAndErase(
|
|
SILInstruction *I, SILValue result,
|
|
std::function<void(SILInstruction *)> eraseNotify = nullptr);
|
|
|
|
/// Simplify invocations of builtin operations that may overflow.
|
|
/// All such operations return a tuple (result, overflow_flag).
|
|
/// This function try to simplify such operations, but returns only a
|
|
/// simplified first element of a tuple. The overflow flag is not returned
|
|
/// explicitly, because this simplification is only possible if there is
|
|
/// no overflow. Therefore the overflow flag is known to have a value of 0 if
|
|
/// simplification was successful.
|
|
/// In case when a simplification is not possible, a null SILValue is returned.
|
|
SILValue simplifyOverflowBuiltinInstruction(BuiltinInst *BI);
|
|
|
|
} // end namespace swift
|
|
|
|
#endif // SWIFT_SILOPTIMIZER_ANALYSIS_SIMPLIFYINSTRUCTION_H
|