@@ -981,17 +981,24 @@ class IRGenSILFunction :
981
981
&& !isAnonymous;
982
982
}
983
983
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);
988
994
}
989
995
990
996
// / At -Onone, emit a shadow copy of an Address in an alloca, so the
991
997
// / register allocator doesn't elide the dbg.value intrinsic when
992
998
// / register pressure is high. There is a trade-off to this: With
993
999
// / shadow copies, we lose the precise lifetime.
994
1000
llvm::Value *emitShadowCopyIfNeeded (llvm::Value *Storage,
1001
+ llvm::Type *StorageType,
995
1002
const SILDebugScope *Scope,
996
1003
SILDebugVariable VarInfo,
997
1004
bool IsAnonymous, bool WasMoved,
@@ -1011,7 +1018,7 @@ class IRGenSILFunction :
1011
1018
// This condition must be consistent with emitPoisonDebugValueInst to avoid
1012
1019
// generating extra shadow copies for debug_value [poison].
1013
1020
if (!shouldShadowVariable (VarInfo, IsAnonymous)
1014
- || !shouldShadowStorage (Storage)) {
1021
+ || !shouldShadowStorage (Storage, StorageType )) {
1015
1022
return Storage;
1016
1023
}
1017
1024
@@ -1034,11 +1041,12 @@ class IRGenSILFunction :
1034
1041
// / Like \c emitShadowCopyIfNeeded() but takes an \c Address instead of an
1035
1042
// / \c llvm::Value.
1036
1043
llvm::Value *emitShadowCopyIfNeeded (Address Storage,
1044
+ llvm::Type *StorageType,
1037
1045
const SILDebugScope *Scope,
1038
1046
SILDebugVariable VarInfo,
1039
1047
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,
1042
1050
Storage.getAlignment ());
1043
1051
}
1044
1052
@@ -1072,7 +1080,9 @@ class IRGenSILFunction :
1072
1080
return ;
1073
1081
1074
1082
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,
1076
1086
IsAnonymous, WasMoved));
1077
1087
return ;
1078
1088
}
@@ -1116,7 +1126,7 @@ class IRGenSILFunction :
1116
1126
llvm::raw_svector_ostream (Buf) << " $pack_count_" << Position;
1117
1127
auto Name = IGM.Context .getIdentifier (Buf.str ());
1118
1128
SILDebugVariable Var (Name.str (), true , 0 );
1119
- Shape = emitShadowCopyIfNeeded (Shape, getDebugScope (), Var, false ,
1129
+ Shape = emitShadowCopyIfNeeded (Shape, nullptr , getDebugScope (), Var, false ,
1120
1130
false /* was move*/ );
1121
1131
if (IGM.DebugInfo )
1122
1132
IGM.DebugInfo ->emitPackCountParameter (*this , Shape, Var);
@@ -5078,7 +5088,7 @@ void IRGenSILFunction::emitErrorResultVar(CanSILFunctionType FnTy,
5078
5088
auto Var = DbgValue->getVarInfo ();
5079
5089
assert (Var && " error result without debug info" );
5080
5090
auto Storage =
5081
- emitShadowCopyIfNeeded (ErrorResultSlot.getAddress (), getDebugScope (),
5091
+ emitShadowCopyIfNeeded (ErrorResultSlot.getAddress (), nullptr , getDebugScope (),
5082
5092
*Var, false , false /* was move*/ );
5083
5093
if (!IGM.DebugInfo )
5084
5094
return ;
@@ -5125,7 +5135,7 @@ void IRGenSILFunction::emitPoisonDebugValueInst(DebugValueInst *i) {
5125
5135
// copy--poison should never affect program behavior. Also filter everything
5126
5136
// not handled by emitShadowCopyIfNeeded to avoid extra shadow copies.
5127
5137
if (!shouldShadowVariable (*varInfo, isAnonymous)
5128
- || !shouldShadowStorage (storage)) {
5138
+ || !shouldShadowStorage (storage, nullptr )) {
5129
5139
return ;
5130
5140
}
5131
5141
@@ -5272,13 +5282,15 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
5272
5282
5273
5283
// Put the value into a shadow-copy stack slot at -Onone.
5274
5284
llvm::SmallVector<llvm::Value *, 8 > Copy;
5275
- if (IsAddrVal)
5285
+ if (IsAddrVal) {
5286
+ auto &ti = getTypeInfo (SILVal->getType ());
5276
5287
Copy.emplace_back (emitShadowCopyIfNeeded (
5277
- getLoweredAddress (SILVal).getAddress (), i->getDebugScope (), *VarInfo,
5288
+ getLoweredAddress (SILVal).getAddress (), ti. getStorageType (), i->getDebugScope (), *VarInfo,
5278
5289
IsAnonymous, i->getUsesMoveableValueDebugInfo ()));
5279
- else
5290
+ } else {
5280
5291
emitShadowCopyIfNeeded (SILVal, i->getDebugScope (), *VarInfo, IsAnonymous,
5281
5292
i->getUsesMoveableValueDebugInfo (), Copy);
5293
+ }
5282
5294
5283
5295
bindArchetypes (DbgTy.getType ());
5284
5296
if (!IGM.DebugInfo )
@@ -5899,9 +5911,10 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
5899
5911
auto VarInfo = i->getVarInfo ();
5900
5912
if (!VarInfo)
5901
5913
return ;
5902
-
5914
+ auto &ti = getTypeInfo (SILTy);
5903
5915
auto Storage =
5904
- emitShadowCopyIfNeeded (boxWithAddr.getAddress (), i->getDebugScope (),
5916
+ emitShadowCopyIfNeeded (boxWithAddr.getAddress (), ti.getStorageType (),
5917
+ i->getDebugScope (),
5905
5918
*VarInfo, IsAnonymous, false /* was moved*/ );
5906
5919
5907
5920
if (!IGM.DebugInfo )
0 commit comments