@@ -62,29 +62,52 @@ struct SILArgumentKind {
62
62
};
63
63
64
64
class SILArgument : public ValueBase {
65
- void operator =(const SILArgument &) = delete ;
66
- void operator delete (void *Ptr, size_t ) SWIFT_DELETE_OPERATOR_DELETED
65
+ friend class SILBasicBlock ;
66
+
67
+ SILBasicBlock *parentBlock;
68
+ const ValueDecl *decl;
69
+
70
+ protected:
71
+ SILArgument (ValueKind subClassKind, SILBasicBlock *inputParentBlock,
72
+ SILType type, ValueOwnershipKind ownershipKind,
73
+ const ValueDecl *inputDecl = nullptr );
74
+
75
+ SILArgument (ValueKind subClassKind, SILBasicBlock *inputParentBlock,
76
+ SILBasicBlock::arg_iterator positionInArgumentArray, SILType type,
77
+ ValueOwnershipKind ownershipKind,
78
+ const ValueDecl *inputDecl = nullptr );
67
79
68
- SILBasicBlock *ParentBB;
69
- const ValueDecl *Decl;
80
+ // A special constructor, only intended for use in
81
+ // SILBasicBlock::replacePHIArg and replaceFunctionArg.
82
+ explicit SILArgument (ValueKind subClassKind, SILType type,
83
+ ValueOwnershipKind ownershipKind,
84
+ const ValueDecl *inputDecl = nullptr )
85
+ : ValueBase(subClassKind, type, IsRepresentative::Yes),
86
+ parentBlock(nullptr ), decl(inputDecl) {
87
+ Bits.SILArgument .VOKind = static_cast <unsigned >(ownershipKind);
88
+ }
70
89
71
90
public:
91
+ void operator =(const SILArgument &) = delete ;
92
+ void operator delete (void *, size_t ) SWIFT_DELETE_OPERATOR_DELETED;
93
+
72
94
ValueOwnershipKind getOwnershipKind () const {
73
95
return static_cast <ValueOwnershipKind>(Bits.SILArgument .VOKind );
74
96
}
75
- void setOwnershipKind (ValueOwnershipKind NewKind) {
76
- Bits.SILArgument .VOKind = static_cast <unsigned >(NewKind);
97
+
98
+ void setOwnershipKind (ValueOwnershipKind newKind) {
99
+ Bits.SILArgument .VOKind = static_cast <unsigned >(newKind);
77
100
}
78
101
79
- SILBasicBlock *getParent () { return ParentBB ; }
80
- const SILBasicBlock *getParent () const { return ParentBB ; }
102
+ SILBasicBlock *getParent () { return parentBlock ; }
103
+ const SILBasicBlock *getParent () const { return parentBlock ; }
81
104
82
105
SILFunction *getFunction ();
83
106
const SILFunction *getFunction () const ;
84
107
85
108
SILModule &getModule () const ;
86
109
87
- const ValueDecl *getDecl () const { return Decl ; }
110
+ const ValueDecl *getDecl () const { return decl ; }
88
111
89
112
static bool classof (const SILInstruction *) = delete;
90
113
static bool classof (const SILUndef *) = delete;
@@ -94,31 +117,32 @@ class SILArgument : public ValueBase {
94
117
}
95
118
96
119
unsigned getIndex () const {
97
- ArrayRef<SILArgument *> Args = getParent ()->getArguments ();
98
- for (unsigned i = 0 , e = Args.size (); i != e; ++i)
99
- if (Args[i] == this )
100
- return i;
120
+ for (auto p : llvm::enumerate (getParent ()->getArguments ())) {
121
+ if (p.value () == this ) {
122
+ return p.index ();
123
+ }
124
+ }
101
125
llvm_unreachable (" SILArgument not argument of its parent BB" );
102
126
}
103
127
104
128
// / Return true if this block argument is actually a phi argument as
105
129
// / opposed to a cast or projection.
106
- bool isPhiArgument ();
130
+ bool isPhiArgument () const ;
107
131
108
132
// / If this argument is a phi, return the incoming phi value for the given
109
133
// / predecessor BB. If this argument is not a phi, return an invalid SILValue.
110
- SILValue getIncomingPhiValue (SILBasicBlock *predBB) ;
134
+ SILValue getIncomingPhiValue (SILBasicBlock *predBlock) const ;
111
135
112
136
// / If this argument is a phi, populate `OutArray` with the incoming phi
113
137
// / values for each predecessor BB. If this argument is not a phi, return
114
138
// / false.
115
- bool getIncomingPhiValues (llvm:: SmallVectorImpl<SILValue> &ReturnedPhiValues) ;
139
+ bool getIncomingPhiValues (SmallVectorImpl<SILValue> &returnedPhiValues) const ;
116
140
117
141
// / If this argument is a phi, populate `OutArray` with each predecessor block
118
142
// / and its incoming phi value. If this argument is not a phi, return false.
119
- bool getIncomingPhiValues (
120
- llvm:: SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>>
121
- &ReturnedPredAndPhiValuePairs) ;
143
+ bool
144
+ getIncomingPhiValues ( SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>>
145
+ &returnedPredAndPhiValuePairs) const ;
122
146
123
147
// / Returns true if we were able to find a single terminator operand value for
124
148
// / each predecessor of this arguments basic block. The found values are
@@ -127,7 +151,8 @@ class SILArgument : public ValueBase {
127
151
// / Note: this peeks through any projections or cast implied by the
128
152
// / terminator. e.g. the incoming value for a switch_enum payload argument is
129
153
// / the enum itself (the operand of the switch_enum).
130
- bool getSingleTerminatorOperands (llvm::SmallVectorImpl<SILValue> &OutArray);
154
+ bool getSingleTerminatorOperands (
155
+ SmallVectorImpl<SILValue> &returnedSingleTermOperands) const ;
131
156
132
157
// / Returns true if we were able to find single terminator operand values for
133
158
// / each predecessor of this arguments basic block. The found values are
@@ -137,7 +162,8 @@ class SILArgument : public ValueBase {
137
162
// / terminator. e.g. the incoming value for a switch_enum payload argument is
138
163
// / the enum itself (the operand of the switch_enum).
139
164
bool getSingleTerminatorOperands (
140
- llvm::SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>> &OutArray);
165
+ SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>>
166
+ &returnedSingleTermOperands) const ;
141
167
142
168
// / If this SILArgument's parent block has a single predecessor whose
143
169
// / terminator has a single operand, return the incoming operand of the
@@ -153,56 +179,61 @@ class SILArgument : public ValueBase {
153
179
}
154
180
155
181
protected:
156
- SILArgument (ValueKind SubClassKind, SILBasicBlock *ParentBB, SILType Ty,
157
- ValueOwnershipKind OwnershipKind,
158
- const ValueDecl *D = nullptr );
159
- SILArgument (ValueKind SubClassKind, SILBasicBlock *ParentBB,
160
- SILBasicBlock::arg_iterator Pos, SILType Ty,
161
- ValueOwnershipKind OwnershipKind,
162
- const ValueDecl *D = nullptr );
163
-
164
- // A special constructor, only intended for use in
165
- // SILBasicBlock::replacePHIArg and replaceFunctionArg.
166
- explicit SILArgument (ValueKind SubClassKind, SILType Ty,
167
- ValueOwnershipKind OwnershipKind,
168
- const ValueDecl *D = nullptr )
169
- : ValueBase(SubClassKind, Ty, IsRepresentative::Yes), ParentBB(nullptr ),
170
- Decl(D) {
171
- Bits.SILArgument .VOKind = static_cast <unsigned >(OwnershipKind);
182
+ void setParent (SILBasicBlock *newParentBlock) {
183
+ parentBlock = newParentBlock;
172
184
}
173
- void setParent (SILBasicBlock *P) { ParentBB = P; }
174
-
175
- friend SILBasicBlock;
176
185
};
177
186
178
187
class SILPhiArgument : public SILArgument {
188
+ friend class SILBasicBlock ;
189
+
190
+ SILPhiArgument (SILBasicBlock *parentBlock, SILType type,
191
+ ValueOwnershipKind ownershipKind,
192
+ const ValueDecl *decl = nullptr )
193
+ : SILArgument(ValueKind::SILPhiArgument, parentBlock, type, ownershipKind,
194
+ decl) {}
195
+
196
+ SILPhiArgument (SILBasicBlock *parentBlock,
197
+ SILBasicBlock::arg_iterator argArrayInsertPt, SILType type,
198
+ ValueOwnershipKind ownershipKind,
199
+ const ValueDecl *decl = nullptr )
200
+ : SILArgument(ValueKind::SILPhiArgument, parentBlock, argArrayInsertPt,
201
+ type, ownershipKind, decl) {}
202
+
203
+ // A special constructor, only intended for use in
204
+ // SILBasicBlock::replacePHIArg.
205
+ explicit SILPhiArgument (SILType type, ValueOwnershipKind ownershipKind,
206
+ const ValueDecl *decl = nullptr )
207
+ : SILArgument(ValueKind::SILPhiArgument, type, ownershipKind, decl) {}
208
+
179
209
public:
180
210
// / Return true if this is block argument is actually a phi argument as
181
211
// / opposed to a cast or projection.
182
- bool isPhiArgument ();
212
+ bool isPhiArgument () const ;
183
213
184
214
// / If this argument is a phi, return the incoming phi value for the given
185
215
// / predecessor BB. If this argument is not a phi, return an invalid SILValue.
186
216
// /
187
217
// / FIXME: Once SILPhiArgument actually implies that it is a phi argument,
188
218
// / this will be guaranteed to return a valid SILValue.
189
- SILValue getIncomingPhiValue (SILBasicBlock *BB) ;
219
+ SILValue getIncomingPhiValue (SILBasicBlock *predBlock) const ;
190
220
191
221
// / If this argument is a phi, populate `OutArray` with the incoming phi
192
222
// / values for each predecessor BB. If this argument is not a phi, return
193
223
// / false.
194
224
// /
195
225
// / FIXME: Once SILPhiArgument actually implies that it is a phi argument,
196
226
// / this will always succeed.
197
- bool getIncomingPhiValues (llvm:: SmallVectorImpl<SILValue> &OutArray) ;
227
+ bool getIncomingPhiValues (SmallVectorImpl<SILValue> &returnedPhiValues) const ;
198
228
199
229
// / If this argument is a phi, populate `OutArray` with each predecessor block
200
230
// / and its incoming phi value. If this argument is not a phi, return false.
201
231
// /
202
232
// / FIXME: Once SILPhiArgument actually implies that it is a phi argument,
203
233
// / this will always succeed.
204
- bool getIncomingPhiValues (
205
- llvm::SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>> &OutArray);
234
+ bool
235
+ getIncomingPhiValues (SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>>
236
+ &returnedPredAndPhiValuePairs) const ;
206
237
207
238
// / Returns true if we were able to find a single terminator operand value for
208
239
// / each predecessor of this arguments basic block. The found values are
@@ -211,7 +242,8 @@ class SILPhiArgument : public SILArgument {
211
242
// / Note: this peeks through any projections or cast implied by the
212
243
// / terminator. e.g. the incoming value for a switch_enum payload argument is
213
244
// / the enum itself (the operand of the switch_enum).
214
- bool getSingleTerminatorOperands (llvm::SmallVectorImpl<SILValue> &OutArray);
245
+ bool getSingleTerminatorOperands (
246
+ SmallVectorImpl<SILValue> &returnedSingleTermOperands) const ;
215
247
216
248
// / Returns true if we were able to find single terminator operand values for
217
249
// / each predecessor of this arguments basic block. The found values are
@@ -221,7 +253,8 @@ class SILPhiArgument : public SILArgument {
221
253
// / terminator. e.g. the incoming value for a switch_enum payload argument is
222
254
// / the enum itself (the operand of the switch_enum).
223
255
bool getSingleTerminatorOperands (
224
- llvm::SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>> &OutArray);
256
+ SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>>
257
+ &returnedSingleTermOperands) const ;
225
258
226
259
// / If this SILArgument's parent block has a single predecessor whose
227
260
// / terminator has a single operand, return the incoming operand of the
@@ -236,30 +269,35 @@ class SILPhiArgument : public SILArgument {
236
269
static bool classof (const SILNode *node) {
237
270
return node->getKind () == SILNodeKind::SILPhiArgument;
238
271
}
272
+ };
239
273
240
- private:
241
- friend SILBasicBlock;
242
- SILPhiArgument (SILBasicBlock *ParentBB, SILType Ty, ValueOwnershipKind OwnershipKind,
243
- const ValueDecl *D = nullptr )
244
- : SILArgument(ValueKind::SILPhiArgument, ParentBB, Ty, OwnershipKind, D) {}
245
- SILPhiArgument (SILBasicBlock *ParentBB, SILBasicBlock::arg_iterator Pos,
246
- SILType Ty, ValueOwnershipKind OwnershipKind,
247
- const ValueDecl *D = nullptr )
248
- : SILArgument(ValueKind::SILPhiArgument, ParentBB, Pos, Ty, OwnershipKind, D) {}
274
+ class SILFunctionArgument : public SILArgument {
275
+ friend class SILBasicBlock ;
276
+
277
+ SILFunctionArgument (SILBasicBlock *parentBlock, SILType type,
278
+ ValueOwnershipKind ownershipKind,
279
+ const ValueDecl *decl = nullptr )
280
+ : SILArgument(ValueKind::SILFunctionArgument, parentBlock, type,
281
+ ownershipKind, decl) {}
282
+ SILFunctionArgument (SILBasicBlock *parentBlock,
283
+ SILBasicBlock::arg_iterator argArrayInsertPt,
284
+ SILType type, ValueOwnershipKind ownershipKind,
285
+ const ValueDecl *decl = nullptr )
286
+ : SILArgument(ValueKind::SILFunctionArgument, parentBlock,
287
+ argArrayInsertPt, type, ownershipKind, decl) {}
249
288
250
289
// A special constructor, only intended for use in
251
- // SILBasicBlock::replacePHIArg .
252
- explicit SILPhiArgument (SILType Ty , ValueOwnershipKind OwnershipKind ,
253
- const ValueDecl *D = nullptr )
254
- : SILArgument(ValueKind::SILPhiArgument, Ty, OwnershipKind, D ) {}
255
- };
290
+ // SILBasicBlock::replaceFunctionArg .
291
+ explicit SILFunctionArgument (SILType type , ValueOwnershipKind ownershipKind ,
292
+ const ValueDecl *decl = nullptr )
293
+ : SILArgument(ValueKind::SILFunctionArgument, type, ownershipKind, decl ) {
294
+ }
256
295
257
- class SILFunctionArgument : public SILArgument {
258
296
public:
259
297
bool isIndirectResult () const {
260
298
auto numIndirectResults =
261
299
getFunction ()->getConventions ().getNumIndirectSILResults ();
262
- return ( getIndex () < numIndirectResults) ;
300
+ return getIndex () < numIndirectResults;
263
301
}
264
302
265
303
SILArgumentConvention getArgumentConvention () const {
@@ -280,76 +318,66 @@ class SILFunctionArgument : public SILArgument {
280
318
bool isSelf () const ;
281
319
282
320
// / Returns true if this SILArgument is passed via the given convention.
283
- bool hasConvention (SILArgumentConvention P ) const {
284
- return getArgumentConvention () == P ;
321
+ bool hasConvention (SILArgumentConvention convention ) const {
322
+ return getArgumentConvention () == convention ;
285
323
}
286
324
287
325
static bool classof (const SILInstruction *) = delete;
288
326
static bool classof (const SILUndef *) = delete;
289
327
static bool classof (const SILNode *node) {
290
328
return node->getKind () == SILNodeKind::SILFunctionArgument;
291
329
}
292
-
293
- private:
294
- friend SILBasicBlock;
295
-
296
- SILFunctionArgument (SILBasicBlock *ParentBB, SILType Ty, ValueOwnershipKind OwnershipKind,
297
- const ValueDecl *D = nullptr )
298
- : SILArgument(ValueKind::SILFunctionArgument, ParentBB, Ty, OwnershipKind, D) {}
299
- SILFunctionArgument (SILBasicBlock *ParentBB, SILBasicBlock::arg_iterator Pos,
300
- SILType Ty, ValueOwnershipKind OwnershipKind, const ValueDecl *D = nullptr )
301
- : SILArgument(ValueKind::SILFunctionArgument, ParentBB, Pos, Ty, OwnershipKind, D) {}
302
-
303
- // A special constructor, only intended for use in
304
- // SILBasicBlock::replaceFunctionArg.
305
- explicit SILFunctionArgument (SILType Ty, ValueOwnershipKind OwnershipKind,
306
- const ValueDecl *D = nullptr )
307
- : SILArgument(ValueKind::SILFunctionArgument, Ty, OwnershipKind, D) {}
308
330
};
309
331
310
332
// ===----------------------------------------------------------------------===//
311
333
// Out of line Definitions for SILArgument to avoid Forward Decl issues
312
334
// ===----------------------------------------------------------------------===//
313
335
314
- inline bool SILArgument::isPhiArgument () {
336
+ inline bool SILArgument::isPhiArgument () const {
315
337
if (auto *phiArg = dyn_cast<SILPhiArgument>(this ))
316
338
return phiArg->isPhiArgument ();
317
339
318
340
return false ;
319
341
}
320
342
321
- inline SILValue SILArgument::getIncomingPhiValue (SILBasicBlock *BB) {
343
+ inline SILValue
344
+ SILArgument::getIncomingPhiValue (SILBasicBlock *predBlock) const {
322
345
if (isa<SILFunctionArgument>(this ))
323
346
return SILValue ();
324
- return cast<SILPhiArgument>(this )->getIncomingPhiValue (BB );
347
+ return cast<SILPhiArgument>(this )->getIncomingPhiValue (predBlock );
325
348
}
326
349
327
- inline bool
328
- SILArgument::getIncomingPhiValues (llvm:: SmallVectorImpl<SILValue> &OutArray) {
350
+ inline bool SILArgument::getIncomingPhiValues (
351
+ SmallVectorImpl<SILValue> &returnedPhiValues) const {
329
352
if (isa<SILFunctionArgument>(this ))
330
353
return false ;
331
- return cast<SILPhiArgument>(this )->getIncomingPhiValues (OutArray );
354
+ return cast<SILPhiArgument>(this )->getIncomingPhiValues (returnedPhiValues );
332
355
}
333
356
334
357
inline bool SILArgument::getIncomingPhiValues (
335
- llvm::SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>> &OutArray) {
358
+ SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>>
359
+ &returnedPredAndPhiValuePairs) const {
336
360
if (isa<SILFunctionArgument>(this ))
337
361
return false ;
338
- return cast<SILPhiArgument>(this )->getIncomingPhiValues (OutArray);
362
+ return cast<SILPhiArgument>(this )->getIncomingPhiValues (
363
+ returnedPredAndPhiValuePairs);
339
364
}
340
365
341
366
inline bool SILArgument::getSingleTerminatorOperands (
342
- llvm:: SmallVectorImpl<SILValue> &OutArray) {
367
+ SmallVectorImpl<SILValue> &returnedSingleTermOperands) const {
343
368
if (isa<SILFunctionArgument>(this ))
344
369
return false ;
345
- return cast<SILPhiArgument>(this )->getSingleTerminatorOperands (OutArray);
370
+ return cast<SILPhiArgument>(this )->getSingleTerminatorOperands (
371
+ returnedSingleTermOperands);
346
372
}
347
373
348
374
inline bool SILArgument::getSingleTerminatorOperands (
349
- llvm::SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>> &OutArray) {
375
+ SmallVectorImpl<std::pair<SILBasicBlock *, SILValue>>
376
+ &returnedSingleTermOperands) const {
350
377
if (isa<SILFunctionArgument>(this ))
351
378
return false ;
352
- return cast<SILPhiArgument>(this )->getSingleTerminatorOperands (OutArray);
379
+ return cast<SILPhiArgument>(this )->getSingleTerminatorOperands (
380
+ returnedSingleTermOperands);
353
381
}
354
382
355
383
} // end swift namespace
0 commit comments