@@ -478,67 +478,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
478478 // / or `Unknown` if it's known to be immutable.
479479 SILAccessEnforcement access;
480480
481- // / A structure used for bookkeeping the on-demand formation and cleanup
482- // / of an addressable representation for an immutable value binding.
483- struct AddressableBuffer {
484- struct State {
485- // If the value needs to be reabstracted to provide an addressable
486- // representation, this SILValue owns the reabstracted representation.
487- SILValue reabstraction = SILValue();
488- // The stack allocation for the addressable representation.
489- SILValue allocStack = SILValue();
490- // The initiation of the in-memory borrow.
491- SILValue storeBorrow = SILValue();
492-
493- State (SILValue reabstraction,
494- SILValue allocStack,
495- SILValue storeBorrow)
496- : reabstraction(reabstraction), allocStack(allocStack),
497- storeBorrow (storeBorrow)
498- {}
499- };
500-
501- llvm::PointerUnion<State *, VarDecl*> stateOrAlias = (State*)nullptr ;
502-
503- // If the variable cleanup is triggered before the addressable
504- // representation is demanded, but the addressable representation
505- // gets demanded later, we save the insertion points where the
506- // representation would be cleaned up so we can backfill them.
507- llvm::SmallVector<SILInstruction*, 1 > cleanupPoints;
508-
509- AddressableBuffer () = default;
510-
511- AddressableBuffer (VarDecl *original)
512- : stateOrAlias(original)
513- {
514- }
515-
516- AddressableBuffer (AddressableBuffer &&other)
517- : stateOrAlias(other.stateOrAlias)
518- {
519- other.stateOrAlias = (State*)nullptr ;
520- cleanupPoints.swap (other.cleanupPoints );
521- }
522-
523- AddressableBuffer &operator =(AddressableBuffer &&other) {
524- if (auto state = stateOrAlias.dyn_cast <State*>()) {
525- delete state;
526- }
527- stateOrAlias = other.stateOrAlias ;
528- cleanupPoints.swap (other.cleanupPoints );
529- return *this ;
530- }
531-
532- State *getState () {
533- ASSERT (!isa<VarDecl *>(stateOrAlias) &&
534- " must get state from original AddressableBuffer" );
535- return stateOrAlias.dyn_cast <State*>();
536- }
537-
538- ~AddressableBuffer ();
539- };
540- AddressableBuffer addressableBuffer;
541-
542481 VarLoc () = default ;
543482
544483 VarLoc (SILValue value, SILAccessEnforcement access,
@@ -552,55 +491,71 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
552491 // / a local variable.
553492 llvm::DenseMap<ValueDecl*, VarLoc> VarLocs;
554493
555- VarLoc::AddressableBuffer *getAddressableBufferInfo (ValueDecl *vd);
556-
557- // Represents an addressable buffer that has been allocated but not yet used.
558- struct PreparedAddressableBuffer {
559- llvm::PointerUnion<SILInstruction *, VarDecl *> insertPointOrAlias
560- = (SILInstruction*)nullptr ;
494+ // / A structure used for bookkeeping the on-demand formation and cleanup
495+ // / of an addressable representation for an immutable value binding.
496+ struct AddressableBuffer {
497+ struct State {
498+ // If the value needs to be reabstracted to provide an addressable
499+ // representation, this SILValue owns the reabstracted representation.
500+ SILValue reabstraction = SILValue();
501+ // The stack allocation for the addressable representation.
502+ SILValue allocStack = SILValue();
503+ // The initiation of the in-memory borrow.
504+ SILValue storeBorrow = SILValue();
505+
506+ State (SILValue reabstraction,
507+ SILValue allocStack,
508+ SILValue storeBorrow)
509+ : reabstraction(reabstraction), allocStack(allocStack),
510+ storeBorrow (storeBorrow)
511+ {}
512+ };
561513
562- PreparedAddressableBuffer () = default ;
514+ llvm::PointerUnion<State *, VarDecl*> stateOrAlias = (State*)nullptr ;
515+
516+ // The point at which the buffer will be inserted.
517+ SILInstruction *insertPoint = nullptr ;
563518
564- PreparedAddressableBuffer (SILInstruction *insertPoint)
565- : insertPointOrAlias(insertPoint)
566- {
567- ASSERT (insertPoint && " null insertion point provided" );
568- }
519+ // If the variable cleanup is triggered before the addressable
520+ // representation is demanded, but the addressable representation
521+ // gets demanded later, we save the insertion points where the
522+ // representation would be cleaned up so we can backfill them.
523+ llvm::SmallVector<SILInstruction*, 1 > cleanupPoints;
524+
525+ AddressableBuffer () = default;
569526
570- PreparedAddressableBuffer (VarDecl *alias )
571- : insertPointOrAlias(alias )
527+ AddressableBuffer (VarDecl *original )
528+ : stateOrAlias(original )
572529 {
573- ASSERT (alias && " null alias provided" );
574530 }
575531
576- PreparedAddressableBuffer (PreparedAddressableBuffer &&other)
577- : insertPointOrAlias (other.insertPointOrAlias )
532+ AddressableBuffer (AddressableBuffer &&other)
533+ : stateOrAlias (other.stateOrAlias )
578534 {
579- other.insertPointOrAlias = (SILInstruction*)nullptr ;
535+ other.stateOrAlias = (State*)nullptr ;
536+ cleanupPoints.swap (other.cleanupPoints );
580537 }
581538
582- PreparedAddressableBuffer &operator =(PreparedAddressableBuffer &&other) {
583- insertPointOrAlias = other.insertPointOrAlias ;
584- other.insertPointOrAlias = nullptr ;
539+ AddressableBuffer &operator =(AddressableBuffer &&other) {
540+ if (auto state = stateOrAlias.dyn_cast <State*>()) {
541+ delete state;
542+ }
543+ stateOrAlias = other.stateOrAlias ;
544+ cleanupPoints.swap (other.cleanupPoints );
585545 return *this ;
586546 }
587547
588- SILInstruction *getInsertPoint () const {
589- return insertPointOrAlias.dyn_cast <SILInstruction*>();
548+ State *getState () {
549+ ASSERT (!isa<VarDecl *>(stateOrAlias) &&
550+ " must get state from original AddressableBuffer" );
551+ return stateOrAlias.dyn_cast <State*>();
590552 }
591553
592- VarDecl *getOriginalForAlias () const {
593- return insertPointOrAlias.dyn_cast <VarDecl*>();
594- }
595-
596- ~PreparedAddressableBuffer () {
597- if (auto insertPoint = getInsertPoint ()) {
598- // Remove the insertion point if it went unused.
599- insertPoint->eraseFromParent ();
600- }
601- }
554+ ~AddressableBuffer ();
602555 };
603- llvm::DenseMap<VarDecl *, PreparedAddressableBuffer> AddressableBuffers;
556+ llvm::DenseMap<ValueDecl *, AddressableBuffer> AddressableBuffers;
557+
558+ AddressableBuffer *getAddressableBufferInfo (ValueDecl *vd);
604559
605560 // / Establish the scope for the addressable buffer that might be allocated
606561 // / for a local variable binding.
0 commit comments