Skip to content

[+0-all-args] Add SILGenBuilder APIs for createRefToBridgeObject and … #14648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/SILGen/SILGenBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,14 @@ ManagedValue SILGenBuilder::createBridgeObjectToRef(SILLocation loc,
return cloner.clone(result);
}

ManagedValue SILGenBuilder::createRefToBridgeObject(SILLocation loc,
ManagedValue mv,
SILValue bits) {
CleanupCloner cloner(*this, mv);
SILValue result = createRefToBridgeObject(loc, mv.forward(SGF), bits);
return cloner.clone(result);
}

ManagedValue SILGenBuilder::createBlockToAnyObject(SILLocation loc,
ManagedValue v,
SILType destType) {
Expand Down
4 changes: 4 additions & 0 deletions lib/SILGen/SILGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ class SILGenBuilder : public SILBuilder {
ManagedValue createBridgeObjectToRef(SILLocation loc, ManagedValue mv,
SILType destType);

using SILBuilder::createRefToBridgeObject;
ManagedValue createRefToBridgeObject(SILLocation loc, ManagedValue mv,
SILValue bits);

using SILBuilder::createBranch;
BranchInst *createBranch(SILLocation Loc, SILBasicBlock *TargetBlock,
ArrayRef<ManagedValue> Args);
Expand Down
12 changes: 4 additions & 8 deletions lib/SILGen/SILGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,8 @@ static ManagedValue emitBuiltinCastToBridgeObject(SILGenFunction &SGF,
SILValue undef = SILUndef::get(objPointerType, SGF.SGM.M);
return ManagedValue::forUnmanaged(undef);
}

// Save the cleanup on the argument so we can forward it onto the cast
// result.
auto refCleanup = args[0].getCleanup();
SILValue ref = args[0].getValue();

ManagedValue ref = args[0];
SILValue bits = args[1].getUnmanagedValue();

// If the argument is existential, open it.
Expand All @@ -691,9 +688,8 @@ static ManagedValue emitBuiltinCastToBridgeObject(SILGenFunction &SGF,
SILType loweredOpenedTy = SGF.getLoweredLoadableType(openedTy);
ref = SGF.B.createOpenExistentialRef(loc, ref, loweredOpenedTy);
}

SILValue result = SGF.B.createRefToBridgeObject(loc, ref, bits);
return ManagedValue(result, refCleanup);

return SGF.B.createRefToBridgeObject(loc, ref, bits);
}

/// Specialized emitter for Builtin.castReferenceFromBridgeObject.
Expand Down