@@ -257,14 +257,27 @@ class TypeLowering {
257
257
virtual void emitDestroyRValue (SILBuilder &B, SILLocation loc,
258
258
SILValue value) const = 0;
259
259
260
- enum class LoweringStyle { Shallow, Deep };
260
+ // / When using "Lowered" APIs on a type lowering, how far should type lowering
261
+ // / expand a type into its subtypes when emitting an operation.
262
+ // /
263
+ // / If we emit operations on a subtype of the type, we expand the type into
264
+ // / the subtypes and perform the requested operation at that level of the
265
+ // / type tree.
266
+ enum class TypeExpansionKind {
267
+ None, // /> Emit operations on the actual value.
268
+ DirectChildren, // /> Expand the value into its direct children and place
269
+ // /> operations on the children.
270
+ MostDerivedDescendents, // /> Expand the value into its most derived
271
+ // /> substypes and perform operations on these
272
+ // /> types.
273
+ };
261
274
262
275
// / Given the result of the expansion heuristic,
263
276
// / return appropriate lowering style.
264
- static LoweringStyle getLoweringStyle (bool shouldExpand) {
277
+ static TypeExpansionKind getLoweringStyle (bool shouldExpand) {
265
278
if (shouldExpand)
266
- return TypeLowering::LoweringStyle::Deep ;
267
- return TypeLowering::LoweringStyle::Shallow ;
279
+ return TypeLowering::TypeExpansionKind::MostDerivedDescendents ;
280
+ return TypeLowering::TypeExpansionKind::DirectChildren ;
268
281
}
269
282
270
283
// ===--------------------------------------------------------------------===//
@@ -274,32 +287,39 @@ class TypeLowering {
274
287
// / Emit a lowered destroy value operation.
275
288
// /
276
289
// / This type must be loadable.
277
- virtual void emitLoweredDestroyValue (SILBuilder &B, SILLocation loc,
278
- SILValue value,
279
- LoweringStyle loweringStyle) const = 0;
290
+ virtual void
291
+ emitLoweredDestroyValue (SILBuilder &B, SILLocation loc, SILValue value,
292
+ TypeExpansionKind loweringStyle) const = 0 ;
280
293
281
294
void emitLoweredDestroyChildValue (SILBuilder &B, SILLocation loc,
282
295
SILValue value,
283
- LoweringStyle loweringStyle) const {
284
- if (loweringStyle != LoweringStyle::Shallow)
285
- return emitLoweredDestroyValue (B, loc, value, loweringStyle);
286
- return emitDestroyValue (B, loc, value);
296
+ TypeExpansionKind loweringStyle) const {
297
+ switch (loweringStyle) {
298
+ case TypeExpansionKind::None:
299
+ llvm_unreachable (" This does not apply to children of aggregate types" );
300
+ case TypeExpansionKind::DirectChildren:
301
+ return emitDestroyValue (B, loc, value);
302
+ case TypeExpansionKind::MostDerivedDescendents:
303
+ return emitLoweredDestroyValueMostDerivedDescendents (B, loc, value);
304
+ }
287
305
}
288
306
289
307
// / Emit a lowered destroy value operation.
290
308
// /
291
309
// / This type must be loadable.
292
- void emitLoweredDestroyValueShallow (SILBuilder &B, SILLocation loc,
293
- SILValue value) const {
294
- emitLoweredDestroyValue (B, loc, value, LoweringStyle::Shallow );
310
+ void emitLoweredDestroyValueDirectChildren (SILBuilder &B, SILLocation loc,
311
+ SILValue value) const {
312
+ emitLoweredDestroyValue (B, loc, value, TypeExpansionKind::DirectChildren );
295
313
}
296
314
297
315
// / Emit a lowered destroy_value operation.
298
316
// /
299
317
// / This type must be loadable.
300
- void emitLoweredDestroyValueDeep (SILBuilder &B, SILLocation loc,
301
- SILValue value) const {
302
- emitLoweredDestroyValue (B, loc, value, LoweringStyle::Deep);
318
+ void emitLoweredDestroyValueMostDerivedDescendents (SILBuilder &B,
319
+ SILLocation loc,
320
+ SILValue value) const {
321
+ emitLoweredDestroyValue (B, loc, value,
322
+ TypeExpansionKind::MostDerivedDescendents);
303
323
}
304
324
305
325
// / Given a primitively loaded value of this type (which must be
@@ -322,22 +342,25 @@ class TypeLowering {
322
342
// / This type must be loadable.
323
343
virtual SILValue emitLoweredCopyValue (SILBuilder &B, SILLocation loc,
324
344
SILValue value,
325
- LoweringStyle style) const = 0;
345
+ TypeExpansionKind style) const = 0;
326
346
327
347
// / Emit a lowered copy value operation.
328
348
// /
329
349
// / This type must be loadable.
330
- SILValue emitLoweredCopyValueShallow (SILBuilder &B, SILLocation loc,
331
- SILValue value) const {
332
- return emitLoweredCopyValue (B, loc, value, LoweringStyle::Shallow);
350
+ SILValue emitLoweredCopyValueDirectChildren (SILBuilder &B, SILLocation loc,
351
+ SILValue value) const {
352
+ return emitLoweredCopyValue (B, loc, value,
353
+ TypeExpansionKind::DirectChildren);
333
354
}
334
355
335
356
// / Emit a lowered copy value operation.
336
357
// /
337
358
// / This type must be loadable.
338
- SILValue emitLoweredCopyValueDeep (SILBuilder &B, SILLocation loc,
339
- SILValue value) const {
340
- return emitLoweredCopyValue (B, loc, value, LoweringStyle::Deep);
359
+ SILValue emitLoweredCopyValueMostDerivedDescendents (SILBuilder &B,
360
+ SILLocation loc,
361
+ SILValue value) const {
362
+ return emitLoweredCopyValue (B, loc, value,
363
+ TypeExpansionKind::MostDerivedDescendents);
341
364
}
342
365
343
366
// / Given a primitively loaded value of this type (which must be
@@ -353,11 +376,14 @@ class TypeLowering {
353
376
354
377
SILValue emitLoweredCopyChildValue (SILBuilder &B, SILLocation loc,
355
378
SILValue value,
356
- LoweringStyle style) const {
357
- if (style != LoweringStyle::Shallow) {
358
- return emitLoweredCopyValue (B, loc, value, style);
359
- } else {
379
+ TypeExpansionKind style) const {
380
+ switch (style) {
381
+ case TypeExpansionKind::None:
382
+ llvm_unreachable (" This does not apply to children of aggregate" );
383
+ case TypeExpansionKind::DirectChildren:
360
384
return emitCopyValue (B, loc, value);
385
+ case TypeExpansionKind::MostDerivedDescendents:
386
+ return emitLoweredCopyValueMostDerivedDescendents (B, loc, value);
361
387
}
362
388
}
363
389
0 commit comments