mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This is in prepration for other bug fixes. Clarify the SIL utilities that return canonical address values for formal access given the address used by some memory operation: - stripAccessMarkers - getAddressAccess - getAccessedAddress These are closely related to the code in MemAccessUtils. Make sure passes use these utilities consistently so that optimizations aren't defeated by normal variations in SIL patterns. Create an isLetAddress() utility alongside these basic utilities to make sure it is used consistently with the address corresponding to formal access. When this query is used inconsistently, it defeats optimization. It can also cause correctness bugs because some optimizations assume that 'let' initialization is only performed on a unique address value. Functional changes to Memory Behavior: - An instruction with side effects now conservatively still has side effects even when the queried value is a 'let'. Let values are certainly sensitive to side effects, such as the parent object being deallocated. - Return the correct MemBehavior for begin/end_access markers.
82 lines
3.0 KiB
C++
82 lines
3.0 KiB
C++
//===--- ValueTracking.h - SIL Value Tracking Analysis ----------*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains routines which analyze chains of computations.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_SILOPTIMIZER_ANALYSIS_VALUETRACKING_H
|
|
#define SWIFT_SILOPTIMIZER_ANALYSIS_VALUETRACKING_H
|
|
|
|
#include "swift/SIL/MemAccessUtils.h"
|
|
#include "swift/SIL/SILArgument.h"
|
|
#include "swift/SIL/SILInstruction.h"
|
|
|
|
namespace swift {
|
|
|
|
/// Returns true if \p V is a function argument which may not alias to
|
|
/// any other pointer in the function.
|
|
///
|
|
/// This does not look through any projections. The caller must do that.
|
|
bool isExclusiveArgument(SILValue V);
|
|
|
|
/// Returns true if \p V is a locally allocated object.
|
|
///
|
|
/// Note: this may look through a single level of indirection (via
|
|
/// ref_element_addr) when \p V is the address of a class property. However, it
|
|
/// does not look through init/open_existential_addr.
|
|
bool pointsToLocalObject(SILValue V);
|
|
|
|
/// Returns true if \p V is a uniquely identified address or reference. It may
|
|
/// be any of:
|
|
///
|
|
/// - an address projection based on a locally allocated address with no
|
|
/// indirection
|
|
///
|
|
/// - a locally allocated reference, or an address projection based on that
|
|
/// reference with one level of indirection (an address into the locally
|
|
/// allocated object).
|
|
///
|
|
/// - an address projection based on an exclusive argument with no levels of
|
|
/// indirection (e.g. ref_element_addr, project_box, etc.).
|
|
inline bool isUniquelyIdentified(SILValue V) {
|
|
return pointsToLocalObject(V)
|
|
|| (V->getType().isAddress()
|
|
&& isExclusiveArgument(getAccessedAddress(V)));
|
|
}
|
|
|
|
enum class IsZeroKind {
|
|
Zero,
|
|
NotZero,
|
|
Unknown
|
|
};
|
|
|
|
/// Check if the value \p Value is known to be zero, non-zero or unknown.
|
|
IsZeroKind isZeroValue(SILValue Value);
|
|
|
|
/// Checks if a sign bit of a value is known to be set, not set or unknown.
|
|
/// Essentially, it is a simple form of a range analysis.
|
|
/// This approach is inspired by the corresponding implementation of
|
|
/// ComputeSignBit in LLVM's value tracking implementation.
|
|
/// It is planned to extend this approach to track all bits of a value.
|
|
/// Therefore it can be considered to be the beginning of a range analysis
|
|
/// infrastructure for the Swift compiler.
|
|
Optional<bool> computeSignBit(SILValue Value);
|
|
|
|
/// Check if execution of a given builtin instruction can result in overflows.
|
|
/// Returns true of an overflow can happen. Otherwise returns false.
|
|
bool canOverflow(BuiltinInst *BI);
|
|
|
|
} // end namespace swift
|
|
|
|
#endif // SWIFT_SILOPTIMIZER_ANALYSIS_VALUETRACKING_H
|