mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ownership] Make ForwardingOperand truly a loose wrapper around an operand.
This implies making -> and * return an Operand * instead of an OwnershipForwardingInst. So one can thus do: ForwardingOperand op; op.myForwardingOperandMethod(); op->myOperandMethod();
This commit is contained in:
@@ -82,29 +82,24 @@ class ForwardingOperand {
|
||||
public:
|
||||
static Optional<ForwardingOperand> get(Operand *use);
|
||||
|
||||
Operand *getUse() const { return use; }
|
||||
OwnershipConstraint getOwnershipConstraint() const {
|
||||
// We use a force unwrap since a ForwardingOperand should always have an
|
||||
// ownership constraint.
|
||||
return use->getOwnershipConstraint();
|
||||
}
|
||||
|
||||
ValueOwnershipKind getOwnershipKind() const;
|
||||
void setOwnershipKind(ValueOwnershipKind newKind) const;
|
||||
void replaceOwnershipKind(ValueOwnershipKind oldKind,
|
||||
ValueOwnershipKind newKind) const;
|
||||
|
||||
const OwnershipForwardingInst *operator->() const {
|
||||
return cast<OwnershipForwardingInst>(use->getUser());
|
||||
}
|
||||
OwnershipForwardingInst *operator->() {
|
||||
return cast<OwnershipForwardingInst>(use->getUser());
|
||||
}
|
||||
const OwnershipForwardingInst &operator*() const {
|
||||
return *cast<OwnershipForwardingInst>(use->getUser());
|
||||
}
|
||||
OwnershipForwardingInst &operator*() {
|
||||
return *cast<OwnershipForwardingInst>(use->getUser());
|
||||
}
|
||||
const Operand *operator->() const { return use; }
|
||||
|
||||
Operand *operator->() { return use; }
|
||||
|
||||
const Operand &operator*() const { return *use; }
|
||||
|
||||
Operand &operator*() { return *use; }
|
||||
|
||||
/// Call \p visitor with each value that contains the final forwarded
|
||||
/// ownership of. E.x.: result of a unchecked_ref_cast, phi arguments of a
|
||||
|
||||
@@ -900,7 +900,35 @@ Optional<ForwardingOperand> ForwardingOperand::get(Operand *use) {
|
||||
}
|
||||
|
||||
ValueOwnershipKind ForwardingOperand::getOwnershipKind() const {
|
||||
return (*this)->getOwnershipKind();
|
||||
auto *user = use->getUser();
|
||||
|
||||
// NOTE: This if chain is meant to be a covered switch, so make sure to return
|
||||
// in each if itself since we have an unreachable at the bottom to ensure if a
|
||||
// new subclass of OwnershipForwardingInst is added
|
||||
if (auto *ofsvi = dyn_cast<AllArgOwnershipForwardingSingleValueInst>(user))
|
||||
return ofsvi->getOwnershipKind();
|
||||
|
||||
if (auto *ofsvi = dyn_cast<FirstArgOwnershipForwardingSingleValueInst>(user))
|
||||
return ofsvi->getOwnershipKind();
|
||||
|
||||
if (auto *ofci = dyn_cast<OwnershipForwardingConversionInst>(user))
|
||||
return ofci->getOwnershipKind();
|
||||
|
||||
if (auto *ofseib = dyn_cast<OwnershipForwardingSelectEnumInstBase>(user))
|
||||
return ofseib->getOwnershipKind();
|
||||
|
||||
if (auto *ofmvi =
|
||||
dyn_cast<OwnershipForwardingMultipleValueInstruction>(user)) {
|
||||
assert(ofmvi->getNumOperands() == 1);
|
||||
return ofmvi->getOwnershipKind();
|
||||
}
|
||||
|
||||
if (auto *ofti = dyn_cast<OwnershipForwardingTermInst>(user)) {
|
||||
assert(ofti->getNumOperands() == 1);
|
||||
return ofti->getOwnershipKind();
|
||||
}
|
||||
|
||||
llvm_unreachable("Unhandled forwarding inst?!");
|
||||
}
|
||||
|
||||
void ForwardingOperand::setOwnershipKind(ValueOwnershipKind newKind) const {
|
||||
|
||||
Reference in New Issue
Block a user