Skip to content

Commit

Permalink
Merge pull request swiftlang#32405 from davezarzycki/pr32405
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci authored Jun 16, 2020
2 parents ba59ef5 + ced3b39 commit ef1b5a8
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions include/swift/SIL/OwnershipUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,20 @@ bool isOwnedForwardingInstruction(SILInstruction *inst);
/// previous terminator.
bool isOwnedForwardingValue(SILValue value);

struct BorrowingOperandKind {
enum Kind {
class BorrowingOperandKind {
public:
enum Kind : uint8_t {
BeginBorrow,
BeginApply,
Branch,
};

private:
Kind value;

public:
BorrowingOperandKind(Kind newValue) : value(newValue) {}
BorrowingOperandKind(const BorrowingOperandKind &other)
: value(other.value) {}

operator Kind() const { return value; }

static Optional<BorrowingOperandKind> get(SILInstructionKind kind) {
Expand Down Expand Up @@ -207,15 +209,20 @@ struct BorrowingOperand {
llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
const BorrowingOperand &operand);

struct BorrowedValueKind {
class BorrowedValueKind {
public:
/// Enum we use for exhaustive pattern matching over borrow scope introducers.
enum Kind {
enum Kind : uint8_t {
LoadBorrow,
BeginBorrow,
SILFunctionArgument,
Phi,
};

private:
Kind value;

public:
static Optional<BorrowedValueKind> get(SILValue value) {
if (value.getOwnershipKind() != ValueOwnershipKind::Guaranteed)
return None;
Expand All @@ -240,10 +247,8 @@ struct BorrowedValueKind {
}
}

Kind value;

BorrowedValueKind(Kind newValue) : value(newValue) {}
BorrowedValueKind(const BorrowedValueKind &other) : value(other.value) {}

operator Kind() const { return value; }

/// Is this a borrow scope that begins and ends within the same function and
Expand Down Expand Up @@ -383,18 +388,20 @@ bool getAllBorrowIntroducingValues(SILValue value,
/// introducer, then we return a .some(BorrowScopeIntroducingValue).
Optional<BorrowedValue> getSingleBorrowIntroducingValue(SILValue inputValue);

struct InteriorPointerOperandKind {
class InteriorPointerOperandKind {
public:
enum Kind : uint8_t {
RefElementAddr,
RefTailAddr,
OpenExistentialBox,
};

private:
Kind value;

public:
InteriorPointerOperandKind(Kind newValue) : value(newValue) {}
InteriorPointerOperandKind(const InteriorPointerOperandKind &other)
: value(other.value) {}

operator Kind() const { return value; }

static Optional<InteriorPointerOperandKind> get(Operand *use) {
Expand Down Expand Up @@ -467,8 +474,9 @@ struct InteriorPointerOperand {
: operand(op), kind(kind) {}
};

struct OwnedValueIntroducerKind {
enum Kind {
class OwnedValueIntroducerKind {
public:
enum Kind : uint8_t {
/// An owned value that is a result of an Apply.
Apply,

Expand Down Expand Up @@ -519,6 +527,10 @@ struct OwnedValueIntroducerKind {
AllocRefInit,
};

private:
Kind value;

public:
static Optional<OwnedValueIntroducerKind> get(SILValue value) {
if (value.getOwnershipKind() != ValueOwnershipKind::Owned)
return None;
Expand Down Expand Up @@ -569,11 +581,8 @@ struct OwnedValueIntroducerKind {
llvm_unreachable("Default should have caught this");
}

Kind value;

OwnedValueIntroducerKind(Kind newValue) : value(newValue) {}
OwnedValueIntroducerKind(const OwnedValueIntroducerKind &other)
: value(other.value) {}

operator Kind() const { return value; }

void print(llvm::raw_ostream &os) const;
Expand Down

0 comments on commit ef1b5a8

Please sign in to comment.