@@ -75,16 +75,21 @@ class SILArgument : public ValueBase {
7575protected:
7676 SILArgument (ValueKind subClassKind, SILBasicBlock *inputParentBlock,
7777 SILType type, ValueOwnershipKind ownershipKind,
78- const ValueDecl *inputDecl = nullptr );
78+ const ValueDecl *inputDecl = nullptr , bool reborrow = false ,
79+ bool escaping = false );
7980
8081 // A special constructor, only intended for use in
8182 // SILBasicBlock::replacePHIArg and replaceFunctionArg.
8283 explicit SILArgument (ValueKind subClassKind, SILType type,
8384 ValueOwnershipKind ownershipKind,
84- const ValueDecl *inputDecl = nullptr )
85- : ValueBase(subClassKind, type),
86- parentBlock(nullptr ), decl(inputDecl) {
85+ const ValueDecl *inputDecl = nullptr ,
86+ bool reborrow = false , bool escaping = false )
87+ : ValueBase(subClassKind, type), parentBlock(nullptr ), decl(inputDecl) {
8788 sharedUInt8 ().SILArgument .valueOwnershipKind = uint8_t (ownershipKind);
89+ // When the optimizer creates reborrows, reborrow flag needs to be set by
90+ // calling setReborrow.
91+ sharedUInt8 ().SILArgument .reborrow = false ;
92+ sharedUInt8 ().SILArgument .escaping = false ;
8893 }
8994
9095public:
@@ -95,10 +100,41 @@ class SILArgument : public ValueBase {
95100 return ValueOwnershipKind (sharedUInt8 ().SILArgument .valueOwnershipKind );
96101 }
97102
103+ bool isScoped () const {
104+ auto ownershipKind = getOwnershipKind ();
105+ if (ownershipKind == OwnershipKind::Owned) {
106+ return true ;
107+ }
108+ if (ownershipKind != OwnershipKind::Guaranteed) {
109+ return false ;
110+ }
111+ return isReborrow ();
112+ }
113+
114+ bool isReborrow () const {
115+ return ValueOwnershipKind (sharedUInt8 ().SILArgument .reborrow );
116+ }
117+
118+ bool isGuaranteedForwarding () const {
119+ return getOwnershipKind () == OwnershipKind::Guaranteed && !isReborrow ();
120+ }
121+
122+ bool isEscaping () const {
123+ return ValueOwnershipKind (sharedUInt8 ().SILArgument .escaping );
124+ }
125+
98126 void setOwnershipKind (ValueOwnershipKind newKind) {
99127 sharedUInt8 ().SILArgument .valueOwnershipKind = uint8_t (newKind);
100128 }
101129
130+ void setReborrow (bool isReborrow) {
131+ sharedUInt8 ().SILArgument .reborrow = isReborrow;
132+ }
133+
134+ void setEscaping (bool isEscaping) {
135+ sharedUInt8 ().SILArgument .escaping = isEscaping;
136+ }
137+
102138 SILBasicBlock *getParent () const { return parentBlock; }
103139
104140 // / Returns true if this argument is erased from a basic block.
@@ -223,14 +259,18 @@ class SILPhiArgument : public SILArgument {
223259
224260 SILPhiArgument (SILBasicBlock *parentBlock, SILType type,
225261 ValueOwnershipKind ownershipKind,
226- const ValueDecl *decl = nullptr )
262+ const ValueDecl *decl = nullptr , bool isReborrow = false ,
263+ bool isEscaping = false )
227264 : SILArgument(ValueKind::SILPhiArgument, parentBlock, type, ownershipKind,
228- decl) {}
265+ decl, isReborrow, isEscaping) {}
266+
229267 // A special constructor, only intended for use in
230268 // SILBasicBlock::replacePHIArg.
231269 explicit SILPhiArgument (SILType type, ValueOwnershipKind ownershipKind,
232- const ValueDecl *decl = nullptr )
233- : SILArgument(ValueKind::SILPhiArgument, type, ownershipKind, decl) {}
270+ const ValueDecl *decl = nullptr ,
271+ bool isReborrow = false , bool isEscaping = false )
272+ : SILArgument(ValueKind::SILPhiArgument, type, ownershipKind, decl,
273+ isReborrow, isEscaping) {}
234274
235275public:
236276 // / Return true if this is block argument is a phi, as opposed to a terminator
0 commit comments