Skip to content

[AST] Stop using PointerIntPair for SIL params/results #32646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3641,7 +3641,7 @@ inline CanGenericSignature CanAnyFunctionType::getOptGenericSignature() const {
}

/// Conventions for passing arguments as parameters.
enum class ParameterConvention {
enum class ParameterConvention : uint8_t {
/// This argument is passed indirectly, i.e. by directly passing the address
/// of an object in memory. The callee is responsible for destroying the
/// object. The callee may assume that the address does not alias any valid
Expand Down Expand Up @@ -3687,7 +3687,7 @@ enum class ParameterConvention {
};
// Check that the enum values fit inside Bits.SILFunctionType.
static_assert(unsigned(ParameterConvention::Direct_Guaranteed) < (1<<3),
"fits in Bits.SILFunctionType and SILParameterInfo");
"fits in Bits.SILFunctionType");

// Does this parameter convention require indirect storage? This reflects a
// SILFunctionType's formal (immutable) conventions, as opposed to the transient
Expand Down Expand Up @@ -3746,7 +3746,7 @@ inline bool isGuaranteedParameter(ParameterConvention conv) {
}

/// The differentiability of a SIL function type parameter.
enum class SILParameterDifferentiability : unsigned {
enum class SILParameterDifferentiability : bool {
/// Either differentiable or not applicable.
///
/// - If the function type is not `@differentiable`, parameter
Expand All @@ -3764,16 +3764,17 @@ enum class SILParameterDifferentiability : unsigned {

/// A parameter type and the rules for passing it.
class SILParameterInfo {
llvm::PointerIntPair<CanType, 3, ParameterConvention> TypeAndConvention;
SILParameterDifferentiability Differentiability : 1;
CanType Type;
ParameterConvention Convention;
SILParameterDifferentiability Differentiability;

public:
SILParameterInfo() = default;//: Ty(), Convention((ParameterConvention)0) {}
SILParameterInfo(
CanType type, ParameterConvention conv,
SILParameterDifferentiability differentiability =
SILParameterDifferentiability::DifferentiableOrNotApplicable)
: TypeAndConvention(type, conv), Differentiability(differentiability) {
: Type(type), Convention(conv), Differentiability(differentiability) {
assert(type->isLegalSILType() && "SILParameterInfo has illegal SIL type");
}

Expand All @@ -3782,15 +3783,15 @@ class SILParameterInfo {
///
/// For most purposes, you probably want \c getArgumentType .
CanType getInterfaceType() const {
return TypeAndConvention.getPointer();
return Type;
}

/// Return the type of a call argument matching this parameter.
///
/// \c t must refer back to the function type this is a parameter for.
CanType getArgumentType(SILModule &M, const SILFunctionType *t, TypeExpansionContext context) const;
ParameterConvention getConvention() const {
return TypeAndConvention.getInt();
return Convention;
}
// Does this parameter convention require indirect storage? This reflects a
// SILFunctionType's formal (immutable) conventions, as opposed to the
Expand Down Expand Up @@ -3909,7 +3910,7 @@ class SILParameterInfo {
};

/// Conventions for returning values.
enum class ResultConvention {
enum class ResultConvention : uint8_t {
/// This result is returned indirectly, i.e. by passing the address
/// of an uninitialized object in memory. The callee is responsible
/// for leaving an initialized object at this address. The callee
Expand Down Expand Up @@ -3944,7 +3945,7 @@ inline bool isIndirectFormalResult(ResultConvention convention) {
}

/// The differentiability of a SIL function type result.
enum class SILResultDifferentiability : unsigned {
enum class SILResultDifferentiability : bool {
/// Either differentiable or not applicable.
///
/// - If the function type is not `@differentiable`, result
Expand All @@ -3962,15 +3963,16 @@ enum class SILResultDifferentiability : unsigned {

/// A result type and the rules for returning it.
class SILResultInfo {
llvm::PointerIntPair<CanType, 3, ResultConvention> TypeAndConvention;
SILResultDifferentiability Differentiability : 1;
CanType Type;
ResultConvention Convention;
SILResultDifferentiability Differentiability;

public:
SILResultInfo() = default;
SILResultInfo(CanType type, ResultConvention conv,
SILResultDifferentiability differentiability =
SILResultDifferentiability::DifferentiableOrNotApplicable)
: TypeAndConvention(type, conv), Differentiability(differentiability) {
: Type(type), Convention(conv), Differentiability(differentiability) {
assert(type->isLegalSILType() && "SILResultInfo has illegal SIL type");
}

Expand All @@ -3979,7 +3981,7 @@ class SILResultInfo {
///
/// For most purposes, you probably want \c getReturnValueType .
CanType getInterfaceType() const {
return TypeAndConvention.getPointer();
return Type;
}

/// The type of a return value corresponding to this result.
Expand All @@ -3989,7 +3991,7 @@ class SILResultInfo {
TypeExpansionContext context) const;

ResultConvention getConvention() const {
return TypeAndConvention.getInt();
return Convention;
}

SILResultDifferentiability getDifferentiability() const {
Expand Down Expand Up @@ -4057,8 +4059,9 @@ class SILResultInfo {
}

void profile(llvm::FoldingSetNodeID &id) {
id.AddPointer(TypeAndConvention.getOpaqueValue());
id.AddInteger((unsigned)getDifferentiability());
id.AddPointer(Type.getPointer());
id.AddInteger(unsigned(getConvention()));
id.AddInteger(unsigned(getDifferentiability()));
}

SWIFT_DEBUG_DUMP;
Expand All @@ -4075,7 +4078,8 @@ class SILResultInfo {
getOwnershipKind(SILFunction &, CanSILFunctionType fTy) const; // in SILType.cpp

bool operator==(SILResultInfo rhs) const {
return TypeAndConvention == rhs.TypeAndConvention;
return Type == rhs.Type && Convention == rhs.Convention
&& Differentiability == rhs.Differentiability;
}
bool operator!=(SILResultInfo rhs) const {
return !(*this == rhs);
Expand Down