[semantic-sil] Define ValueOwnershipKind SILValue::getOwnershipKind().

The implementation will rely on a SILVisitor to ensure that we properly handle
all relevant cases. Right now, there are only stubs and we assert in all of
them.

rdar://29671437
This commit is contained in:
Michael Gottesman
2016-12-16 16:52:33 -08:00
parent 57d3f848a6
commit d4fb21d50f
2 changed files with 45 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
#include "swift/SIL/SILValue.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILVisitor.h"
using namespace swift;
@@ -105,3 +106,39 @@ swift::ValueOwnershipKindMerge(Optional<ValueOwnershipKind> LHS,
return (LHSVal == RHSVal) ? LHS : None;
}
//===----------------------------------------------------------------------===//
// Instruction ValueOwnershipKind Computation
//===----------------------------------------------------------------------===//
namespace {
class ValueOwnershipKindVisitor
: public SILVisitor<ValueOwnershipKindVisitor,
Optional<ValueOwnershipKind>> {
public:
ValueOwnershipKindVisitor() = default;
~ValueOwnershipKindVisitor() = default;
ValueOwnershipKindVisitor(const ValueOwnershipKindVisitor &) = delete;
ValueOwnershipKindVisitor(ValueOwnershipKindVisitor &&) = delete;
Optional<ValueOwnershipKind> visitForwardingInst(SILInstruction *I);
Optional<ValueOwnershipKind> visitPHISILArgument(SILArgument *Arg);
Optional<ValueOwnershipKind> visitValueBase(ValueBase *V) {
llvm_unreachable("unimplemented method on ValueBaseOwnershipVisitor");
}
#define VALUE(Id, Parent) \
Optional<ValueOwnershipKind> visit##Id(Id *ID) { \
llvm_unreachable("unimplemented"); \
}
#include "swift/SIL/SILNodes.def"
};
} // end anonymous namespace
Optional<ValueOwnershipKind> SILValue::getOwnershipKind() const {
// Once we have multiple return values, this must be changed.
return ValueOwnershipKindVisitor().visit(const_cast<ValueBase *>(Value));
}