Skip to content

Commit ae7c69b

Browse files
committed
[AddressLowering] Lower address-of variants.
Now that generic values have been lowered to addresses, create the address_to_pointer instructions.
1 parent 520dfc2 commit ae7c69b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,13 +2617,29 @@ class UseRewriter : SILInstructionVisitor<UseRewriter> {
26172617
vmi->setOperand(opAddr);
26182618
}
26192619

2620+
void visitAddressOfBorrowBuiltinInst(BuiltinInst *bi, bool stackProtected) {
2621+
SILValue value = bi->getOperand(0);
2622+
SILValue addr = pass.valueStorageMap.getStorage(value).storageAddress;
2623+
auto &astCtx = pass.getModule()->getASTContext();
2624+
SILType rawPointerType = SILType::getRawPointerType(astCtx);
2625+
SILValue result = builder.createAddressToPointer(
2626+
bi->getLoc(), addr, rawPointerType, stackProtected);
2627+
bi->replaceAllUsesWith(result);
2628+
}
2629+
26202630
void visitBuiltinInst(BuiltinInst *bi) {
26212631
switch (bi->getBuiltinKind().getValueOr(BuiltinValueKind::None)) {
26222632
case BuiltinValueKind::Copy: {
26232633
SILValue opAddr = addrMat.materializeAddress(use->get());
26242634
bi->setOperand(0, opAddr);
26252635
break;
26262636
}
2637+
case BuiltinValueKind::AddressOfBorrowOpaque:
2638+
visitAddressOfBorrowBuiltinInst(bi, /*stackProtected=*/true);
2639+
break;
2640+
case BuiltinValueKind::UnprotectedAddressOfBorrowOpaque:
2641+
visitAddressOfBorrowBuiltinInst(bi, /*stackProtected=*/false);
2642+
break;
26272643
default:
26282644
bi->dump();
26292645
llvm::report_fatal_error("^^^ Unimplemented builtin opaque value use.");

0 commit comments

Comments
 (0)