@@ -1864,6 +1864,53 @@ class SILBuilder {
1864
1864
lowering.emitDestroyValue (*this , Loc, v);
1865
1865
}
1866
1866
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
+
1867
1914
SILValue emitTupleExtract (SILLocation Loc, SILValue Operand, unsigned FieldNo,
1868
1915
SILType ResultTy) {
1869
1916
// Fold tuple_extract(tuple(x,y,z),2)
0 commit comments