Files
swift-mirror/include/swift/SIL/DynamicCasts.h
Roman Levenstein c97f748fb9 Move the logic for folding type casts using statically known protocol conformances into DynamicCasts.cpp.
The logic for different special cases of type casting is spread over multiple places currently. This patch simply re-factors some of that  code (folding of of type casts using statically known protocol conformances) and moves it into one central place, which makes it easier to maintain. Plus, it allows other clients of DynamicCasts benefit from it as well, e.g. the inliner can use this now. NFC.

Swift SVN r25486
2015-02-23 21:30:48 +00:00

82 lines
3.2 KiB
C++

//===--- DynamicsCasts.h - SIL dynamic-cast utilities -----------*- 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
//
//===----------------------------------------------------------------------===//
//
// This file provides basic utilities for working with subtyping
// relationships.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SIL_SUBTYPING_H
#define SWIFT_SIL_SUBTYPING_H
namespace swift {
class CanType;
class Module;
class SILBuilder;
class SILLocation;
class SILValue;
class SILModule;
class SILType;
enum class CastConsumptionKind : unsigned char;
enum class DynamicCastFeasibility {
/// The cast will always succeed.
WillSucceed,
/// The cast can succeed for some values.
MaySucceed,
/// The cast cannot succeed.
WillFail,
};
/// Classify the feasibility of a dynamic cast. The source and target
/// types should be unlowered formal types.
DynamicCastFeasibility classifyDynamicCast(Module *context,
CanType sourceType,
CanType targetType,
bool isSourceTypeExact = false,
bool isWholdModuleOpts = false);
SILValue emitSuccessfulScalarUnconditionalCast(SILBuilder &B, Module *M,
SILLocation loc, SILValue value,
SILType loweredTargetType,
CanType formalSourceType,
CanType formalTargetType);
void emitSuccessfulIndirectUnconditionalCast(SILBuilder &B, Module *M,
SILLocation loc,
CastConsumptionKind consumption,
SILValue src, CanType sourceType,
SILValue dest, CanType targetType);
/// Can the given cast be performed by the scalar checked-cast
/// instructions, or does we need to use the indirect instructions?
bool canUseScalarCheckedCastInstructions(SILModule &M, CanType sourceType,
CanType targetType);
/// Carry out the operations required for an indirect conditional cast
/// using a scalar cast operation.
void emitIndirectConditionalCastWithScalar(SILBuilder &B, Module *M,
SILLocation loc,
CastConsumptionKind consumption,
SILValue src, CanType sourceType,
SILValue dest, CanType targetType,
SILBasicBlock *trueBB,
SILBasicBlock *falseBB);
} // end namespace swift
#endif