[OpaqueValues] Handle Builtin.copy.

Specify the operand ownership of the Builtin differently depending on
whether lowered addresses are used.  Handle rewriting the value version
of the builtin as the address version of the builtin in AddressLowering.
This commit is contained in:
Nate Chandler
2022-11-02 10:40:50 -07:00
parent 332750d1fd
commit e357fb45c5
3 changed files with 71 additions and 1 deletions

View File

@@ -2617,6 +2617,19 @@ protected:
vmi->setOperand(opAddr);
}
void visitBuiltinInst(BuiltinInst *bi) {
switch (bi->getBuiltinKind().getValueOr(BuiltinValueKind::None)) {
case BuiltinValueKind::Copy: {
SILValue opAddr = addrMat.materializeAddress(use->get());
bi->setOperand(0, opAddr);
break;
}
default:
bi->dump();
llvm::report_fatal_error("^^^ Unimplemented builtin opaque value use.");
}
}
void visitBeginBorrowInst(BeginBorrowInst *borrow);
void visitEndBorrowInst(EndBorrowInst *end) {}
@@ -3112,6 +3125,22 @@ protected:
ApplyRewriter(bai, pass).convertBeginApplyWithOpaqueYield();
}
void visitBuiltinInst(BuiltinInst *bi) {
switch (bi->getBuiltinKind().getValueOr(BuiltinValueKind::None)) {
case BuiltinValueKind::Copy: {
SILValue addr = addrMat.materializeAddress(bi);
builder.createBuiltin(
bi->getLoc(), bi->getName(),
SILType::getEmptyTupleType(bi->getType().getASTContext()),
bi->getSubstitutions(), {addr, bi->getOperand(0)});
break;
}
default:
bi->dump();
llvm::report_fatal_error("^^^ Unimplemented builtin opaque value def.");
}
}
// Rewrite the apply for an indirect result.
void visitDestructureTupleInst(DestructureTupleInst *destructure) {
SILValue srcVal = destructure->getOperand();