Skip to content

Commit ead5fa3

Browse files
committed
Move getOwnershipKind from SILValue to ValueBase.
The API for values is on the ValueBase. SILValue is supposed to be a pointer-like wrapper class. Accessing a value's API is always done as 'value->api()'. The ValueBase subclasses, like SingleValueInstruction, need to inherit the API. I didn't have time to fix all the cases of value.isOwnershipKind() throughout the code.
1 parent fdab5f2 commit ead5fa3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

include/swift/SIL/SILValue.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,16 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
515515
/// result index, or None if it is not defined by an instruction.
516516
Optional<DefiningInstructionResult> getDefiningInstructionResult();
517517

518+
/// Returns the ValueOwnershipKind that describes this SILValue's ownership
519+
/// semantics if the SILValue has ownership semantics. Returns is a value
520+
/// without any Ownership Semantics.
521+
///
522+
/// An example of a SILValue without ownership semantics is a
523+
/// struct_element_addr.
524+
///
525+
/// NOTE: This is implemented in ValueOwnership.cpp not SILValue.cpp.
526+
ValueOwnershipKind getOwnershipKind() const;
527+
518528
static bool classof(SILNodePointer node) {
519529
return node->getKind() >= SILNodeKind::First_ValueBase &&
520530
node->getKind() <= SILNodeKind::Last_ValueBase;
@@ -592,6 +602,8 @@ class SILValue {
592602

593603
/// If this SILValue is a result of an instruction, return its
594604
/// defining instruction. Returns nullptr otherwise.
605+
///
606+
/// FIXME: remove this redundant API from SILValue.
595607
SILInstruction *getDefiningInstruction() {
596608
return Value->getDefiningInstruction();
597609
}
@@ -610,7 +622,11 @@ class SILValue {
610622
/// struct_element_addr.
611623
///
612624
/// NOTE: This is implemented in ValueOwnership.cpp not SILValue.cpp.
613-
ValueOwnershipKind getOwnershipKind() const;
625+
///
626+
/// FIXME: remove this redundant API from SILValue.
627+
ValueOwnershipKind getOwnershipKind() const {
628+
return Value->getOwnershipKind();
629+
}
614630

615631
/// Verify that this SILValue and its uses respects ownership invariants.
616632
void verifyOwnership(DeadEndBlocks *DEBlocks) const;

lib/SIL/IR/ValueOwnership.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,15 +586,15 @@ ValueOwnershipKindClassifier::visitBuiltinInst(BuiltinInst *BI) {
586586
// Top Level Entrypoint
587587
//===----------------------------------------------------------------------===//
588588

589-
ValueOwnershipKind SILValue::getOwnershipKind() const {
589+
ValueOwnershipKind ValueBase::getOwnershipKind() const {
590590
// If we do not have an undef, we should always be able to get to our function
591591
// here. If we do not have ownership enabled, just return none for everything
592592
// to short circuit ownership optimizations. Since SILUndef in either case
593593
// will be ValueOwnershipKind::None, we will not get any wonky behavior here.
594594
//
595595
// We assume that any time we are in SILBuilder and call this without having a
596596
// value in a block yet, ossa is enabled.
597-
if (auto *block = Value->getParentBlock()) {
597+
if (auto *block = getParentBlock()) {
598598
auto *f = block->getParent();
599599
// If our block isn't in a function, then it must be in a global
600600
// variable. We don't verify ownership there so just return
@@ -609,7 +609,7 @@ ValueOwnershipKind SILValue::getOwnershipKind() const {
609609
}
610610

611611
ValueOwnershipKindClassifier Classifier;
612-
auto result = Classifier.visit(const_cast<ValueBase *>(Value));
612+
auto result = Classifier.visit(const_cast<ValueBase *>(this));
613613
assert(result && "Returned ownership kind invalid on values");
614614
return result;
615615
}

0 commit comments

Comments
 (0)