@@ -981,17 +981,24 @@ class IRGenSILFunction :
981981 && !isAnonymous;
982982 }
983983
984- bool shouldShadowStorage (llvm::Value *Storage) {
985- return !isa<llvm::AllocaInst>(Storage)
986- && !isa<llvm::UndefValue>(Storage)
987- && needsShadowCopy (Storage);
984+ bool shouldShadowStorage (llvm::Value *Storage,
985+ llvm::Type *StorageType) {
986+ Storage = Storage->stripPointerCasts ();
987+ if (isa<llvm::UndefValue>(Storage))
988+ return false ;
989+ if (auto *Alloca = dyn_cast<llvm::AllocaInst>(Storage);
990+ Alloca && Alloca->isStaticAlloca () &&
991+ Alloca->getAllocatedType () == StorageType)
992+ return false ;
993+ return needsShadowCopy (Storage);
988994 }
989995
990996 // / At -Onone, emit a shadow copy of an Address in an alloca, so the
991997 // / register allocator doesn't elide the dbg.value intrinsic when
992998 // / register pressure is high. There is a trade-off to this: With
993999 // / shadow copies, we lose the precise lifetime.
9941000 llvm::Value *emitShadowCopyIfNeeded (llvm::Value *Storage,
1001+ llvm::Type *StorageType,
9951002 const SILDebugScope *Scope,
9961003 SILDebugVariable VarInfo,
9971004 bool IsAnonymous, bool WasMoved,
@@ -1011,7 +1018,7 @@ class IRGenSILFunction :
10111018 // This condition must be consistent with emitPoisonDebugValueInst to avoid
10121019 // generating extra shadow copies for debug_value [poison].
10131020 if (!shouldShadowVariable (VarInfo, IsAnonymous)
1014- || !shouldShadowStorage (Storage)) {
1021+ || !shouldShadowStorage (Storage, StorageType )) {
10151022 return Storage;
10161023 }
10171024
@@ -1034,11 +1041,12 @@ class IRGenSILFunction :
10341041 // / Like \c emitShadowCopyIfNeeded() but takes an \c Address instead of an
10351042 // / \c llvm::Value.
10361043 llvm::Value *emitShadowCopyIfNeeded (Address Storage,
1044+ llvm::Type *StorageType,
10371045 const SILDebugScope *Scope,
10381046 SILDebugVariable VarInfo,
10391047 bool IsAnonymous, bool WasMoved) {
1040- return emitShadowCopyIfNeeded (Storage.getAddress (), Scope, VarInfo ,
1041- IsAnonymous, WasMoved,
1048+ return emitShadowCopyIfNeeded (Storage.getAddress (), StorageType, Scope ,
1049+ VarInfo, IsAnonymous, WasMoved,
10421050 Storage.getAlignment ());
10431051 }
10441052
@@ -1072,7 +1080,9 @@ class IRGenSILFunction :
10721080 return ;
10731081
10741082 if (e.size () == 1 ) {
1075- copy.push_back (emitShadowCopyIfNeeded (e.claimNext (), Scope, VarInfo,
1083+ auto &ti = getTypeInfo (SILVal->getType ());
1084+ copy.push_back (emitShadowCopyIfNeeded (e.claimNext (), ti.getStorageType (),
1085+ Scope, VarInfo,
10761086 IsAnonymous, WasMoved));
10771087 return ;
10781088 }
@@ -1116,7 +1126,7 @@ class IRGenSILFunction :
11161126 llvm::raw_svector_ostream (Buf) << " $pack_count_" << Position;
11171127 auto Name = IGM.Context .getIdentifier (Buf.str ());
11181128 SILDebugVariable Var (Name.str (), true , 0 );
1119- Shape = emitShadowCopyIfNeeded (Shape, getDebugScope (), Var, false ,
1129+ Shape = emitShadowCopyIfNeeded (Shape, nullptr , getDebugScope (), Var, false ,
11201130 false /* was move*/ );
11211131 if (IGM.DebugInfo )
11221132 IGM.DebugInfo ->emitPackCountParameter (*this , Shape, Var);
@@ -5061,7 +5071,7 @@ void IRGenSILFunction::emitErrorResultVar(CanSILFunctionType FnTy,
50615071 auto Var = DbgValue->getVarInfo ();
50625072 assert (Var && " error result without debug info" );
50635073 auto Storage =
5064- emitShadowCopyIfNeeded (ErrorResultSlot.getAddress (), getDebugScope (),
5074+ emitShadowCopyIfNeeded (ErrorResultSlot.getAddress (), nullptr , getDebugScope (),
50655075 *Var, false , false /* was move*/ );
50665076 if (!IGM.DebugInfo )
50675077 return ;
@@ -5108,7 +5118,7 @@ void IRGenSILFunction::emitPoisonDebugValueInst(DebugValueInst *i) {
51085118 // copy--poison should never affect program behavior. Also filter everything
51095119 // not handled by emitShadowCopyIfNeeded to avoid extra shadow copies.
51105120 if (!shouldShadowVariable (*varInfo, isAnonymous)
5111- || !shouldShadowStorage (storage)) {
5121+ || !shouldShadowStorage (storage, nullptr )) {
51125122 return ;
51135123 }
51145124
@@ -5255,13 +5265,15 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
52555265
52565266 // Put the value into a shadow-copy stack slot at -Onone.
52575267 llvm::SmallVector<llvm::Value *, 8 > Copy;
5258- if (IsAddrVal)
5268+ if (IsAddrVal) {
5269+ auto &ti = getTypeInfo (SILVal->getType ());
52595270 Copy.emplace_back (emitShadowCopyIfNeeded (
5260- getLoweredAddress (SILVal).getAddress (), i->getDebugScope (), *VarInfo,
5271+ getLoweredAddress (SILVal).getAddress (), ti. getStorageType (), i->getDebugScope (), *VarInfo,
52615272 IsAnonymous, i->getUsesMoveableValueDebugInfo ()));
5262- else
5273+ } else {
52635274 emitShadowCopyIfNeeded (SILVal, i->getDebugScope (), *VarInfo, IsAnonymous,
52645275 i->getUsesMoveableValueDebugInfo (), Copy);
5276+ }
52655277
52665278 bindArchetypes (DbgTy.getType ());
52675279 if (!IGM.DebugInfo )
@@ -5882,9 +5894,10 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
58825894 auto VarInfo = i->getVarInfo ();
58835895 if (!VarInfo)
58845896 return ;
5885-
5897+ auto &ti = getTypeInfo (SILTy);
58865898 auto Storage =
5887- emitShadowCopyIfNeeded (boxWithAddr.getAddress (), i->getDebugScope (),
5899+ emitShadowCopyIfNeeded (boxWithAddr.getAddress (), ti.getStorageType (),
5900+ i->getDebugScope (),
58885901 *VarInfo, IsAnonymous, false /* was moved*/ );
58895902
58905903 if (!IGM.DebugInfo )
0 commit comments