@@ -473,6 +473,50 @@ void TypeTreeLeafTypeRange::constructFilteredProjections(
473
473
llvm_unreachable (" Not understand subtype" );
474
474
}
475
475
476
+ std::optional<TypeTreeLeafTypeRange>
477
+ TypeTreeLeafTypeRange::get (Operand *op, SILValue rootValue) {
478
+ auto projectedValue = op->get ();
479
+ auto startEltOffset = SubElementOffset::compute (projectedValue, rootValue);
480
+ if (!startEltOffset)
481
+ return std::nullopt;
482
+
483
+ // A drop_deinit only consumes the deinit bit of its operand.
484
+ if (isa<DropDeinitInst>(op->getUser ())) {
485
+ auto upperBound = *startEltOffset + TypeSubElementCount (projectedValue);
486
+ return {{upperBound - 1 , upperBound}};
487
+ }
488
+
489
+ // An `inject_enum_addr` only initializes the enum tag.
490
+ if (auto inject = dyn_cast<InjectEnumAddrInst>(op->getUser ())) {
491
+ auto upperBound = *startEltOffset + TypeSubElementCount (projectedValue);
492
+ unsigned payloadUpperBound = 0 ;
493
+ if (inject->getElement ()->hasAssociatedValues ()) {
494
+ auto payloadTy = projectedValue->getType ().getEnumElementType (
495
+ inject->getElement (), op->getFunction ());
496
+
497
+ payloadUpperBound =
498
+ *startEltOffset + TypeSubElementCount (payloadTy, op->getFunction ());
499
+ }
500
+ // TODO: account for deinit component if enum has deinit.
501
+ assert (!projectedValue->getType ().isValueTypeWithDeinit ());
502
+ return {{payloadUpperBound, upperBound}};
503
+ }
504
+
505
+ // Uses that borrow a value do not involve the deinit bit.
506
+ //
507
+ // FIXME: This shouldn't be limited to applies.
508
+ unsigned deinitBitOffset = 0 ;
509
+ if (op->get ()->getType ().isValueTypeWithDeinit () &&
510
+ op->getOperandOwnership () == OperandOwnership::Borrow &&
511
+ ApplySite::isa (op->getUser ())) {
512
+ deinitBitOffset = 1 ;
513
+ }
514
+
515
+ return {{*startEltOffset, *startEltOffset +
516
+ TypeSubElementCount (projectedValue) -
517
+ deinitBitOffset}};
518
+ }
519
+
476
520
void TypeTreeLeafTypeRange::constructProjectionsForNeededElements (
477
521
SILValue rootValue, SILInstruction *insertPt,
478
522
SmallBitVector &neededElements,
0 commit comments