Skip to content

Commit a0483e9

Browse files
authored
Merge pull request #12780 from gottesmm/pmopt_before_big_changes
PMOpt refactoring before big changes
2 parents 414614c + f08553a commit a0483e9

File tree

3 files changed

+371
-171
lines changed

3 files changed

+371
-171
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,53 @@ class SILBuilder {
18641864
lowering.emitDestroyValue(*this, Loc, v);
18651865
}
18661866

1867+
/// Convenience function for handling begin_borrow instructions in ownership
1868+
/// and non-ownership SIL. In non-ownership SIL we just forward the input
1869+
/// value. Otherwise, we emit the begin_borrow instruction.
1870+
SILValue emitBeginBorrowOperation(SILLocation Loc, SILValue Value) {
1871+
assert(!Value->getType().isAddress());
1872+
// If ownership is not enabled in the function, just return our original
1873+
// value.
1874+
if (getFunction().hasUnqualifiedOwnership())
1875+
return Value;
1876+
1877+
// If we have a trivial value, just return the value. Trivial values have
1878+
// lifetimes independent of any other values.
1879+
//
1880+
// *NOTE* For now to be conservative since we do not have the ownership
1881+
// verifier everywhere, we use getType()::isTrivial() instead of
1882+
// getOwnershipKind().
1883+
if (Value->getType().isTrivial(getModule())) {
1884+
return Value;
1885+
}
1886+
1887+
// Otherwise, we have a non-trivial value, perform the borrow.
1888+
return createBeginBorrow(Loc, Value);
1889+
}
1890+
1891+
/// Convenience function for handling end_borrow instructions in ownership and
1892+
/// non-ownership SIL. In non-ownership SIL we just early exit. Otherwise, we
1893+
/// emit the end_borrow.
1894+
void emitEndBorrowOperation(SILLocation Loc, SILValue Borrowed,
1895+
SILValue Original) {
1896+
assert(!Borrowed->getType().isAddress());
1897+
// If ownership is not enabled, just return.
1898+
if (getFunction().hasUnqualifiedOwnership())
1899+
return;
1900+
1901+
// If we have a trivial value, just return. Trivial values have lifetimes
1902+
// independent of any other values.
1903+
//
1904+
// *NOTE* For now to be conservative since we do not have the ownership
1905+
// verifier everywhere, we use getType()::isTrivial() instead of
1906+
// getOwnershipKind().
1907+
if (Borrowed->getType().isTrivial(getModule())) {
1908+
return;
1909+
}
1910+
1911+
createEndBorrow(Loc, Borrowed, Original);
1912+
}
1913+
18671914
SILValue emitTupleExtract(SILLocation Loc, SILValue Operand, unsigned FieldNo,
18681915
SILType ResultTy) {
18691916
// Fold tuple_extract(tuple(x,y,z),2)

0 commit comments

Comments
 (0)