Skip to content

PMOpt refactoring before big changes #12780

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
merged 6 commits into from
Nov 6, 2017
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
47 changes: 47 additions & 0 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,53 @@ class SILBuilder {
lowering.emitDestroyValue(*this, Loc, v);
}

/// Convenience function for handling begin_borrow instructions in ownership
/// and non-ownership SIL. In non-ownership SIL we just forward the input
/// value. Otherwise, we emit the begin_borrow instruction.
SILValue emitBeginBorrowOperation(SILLocation Loc, SILValue Value) {
assert(!Value->getType().isAddress());
// If ownership is not enabled in the function, just return our original
// value.
if (getFunction().hasUnqualifiedOwnership())
return Value;

// If we have a trivial value, just return the value. Trivial values have
// lifetimes independent of any other values.
//
// *NOTE* For now to be conservative since we do not have the ownership
// verifier everywhere, we use getType()::isTrivial() instead of
// getOwnershipKind().
if (Value->getType().isTrivial(getModule())) {
return Value;
}

// Otherwise, we have a non-trivial value, perform the borrow.
return createBeginBorrow(Loc, Value);
}

/// Convenience function for handling end_borrow instructions in ownership and
/// non-ownership SIL. In non-ownership SIL we just early exit. Otherwise, we
/// emit the end_borrow.
void emitEndBorrowOperation(SILLocation Loc, SILValue Borrowed,
SILValue Original) {
assert(!Borrowed->getType().isAddress());
// If ownership is not enabled, just return.
if (getFunction().hasUnqualifiedOwnership())
return;

// If we have a trivial value, just return. Trivial values have lifetimes
// independent of any other values.
//
// *NOTE* For now to be conservative since we do not have the ownership
// verifier everywhere, we use getType()::isTrivial() instead of
// getOwnershipKind().
if (Borrowed->getType().isTrivial(getModule())) {
return;
}

createEndBorrow(Loc, Borrowed, Original);
}

SILValue emitTupleExtract(SILLocation Loc, SILValue Operand, unsigned FieldNo,
SILType ResultTy) {
// Fold tuple_extract(tuple(x,y,z),2)
Expand Down
Loading