@@ -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);
@@ -5061,7 +5071,7 @@ void IRGenSILFunction::emitErrorResultVar(CanSILFunctionType FnTy,
5061
5071
auto Var = DbgValue->getVarInfo ();
5062
5072
assert (Var && " error result without debug info" );
5063
5073
auto Storage =
5064
- emitShadowCopyIfNeeded (ErrorResultSlot.getAddress (), getDebugScope (),
5074
+ emitShadowCopyIfNeeded (ErrorResultSlot.getAddress (), nullptr , getDebugScope (),
5065
5075
*Var, false , false /* was move*/ );
5066
5076
if (!IGM.DebugInfo )
5067
5077
return ;
@@ -5108,7 +5118,7 @@ void IRGenSILFunction::emitPoisonDebugValueInst(DebugValueInst *i) {
5108
5118
// copy--poison should never affect program behavior. Also filter everything
5109
5119
// not handled by emitShadowCopyIfNeeded to avoid extra shadow copies.
5110
5120
if (!shouldShadowVariable (*varInfo, isAnonymous)
5111
- || !shouldShadowStorage (storage)) {
5121
+ || !shouldShadowStorage (storage, nullptr )) {
5112
5122
return ;
5113
5123
}
5114
5124
@@ -5255,13 +5265,15 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
5255
5265
5256
5266
// Put the value into a shadow-copy stack slot at -Onone.
5257
5267
llvm::SmallVector<llvm::Value *, 8 > Copy;
5258
- if (IsAddrVal)
5268
+ if (IsAddrVal) {
5269
+ auto &ti = getTypeInfo (SILVal->getType ());
5259
5270
Copy.emplace_back (emitShadowCopyIfNeeded (
5260
- getLoweredAddress (SILVal).getAddress (), i->getDebugScope (), *VarInfo,
5271
+ getLoweredAddress (SILVal).getAddress (), ti. getStorageType (), i->getDebugScope (), *VarInfo,
5261
5272
IsAnonymous, i->getUsesMoveableValueDebugInfo ()));
5262
- else
5273
+ } else {
5263
5274
emitShadowCopyIfNeeded (SILVal, i->getDebugScope (), *VarInfo, IsAnonymous,
5264
5275
i->getUsesMoveableValueDebugInfo (), Copy);
5276
+ }
5265
5277
5266
5278
bindArchetypes (DbgTy.getType ());
5267
5279
if (!IGM.DebugInfo )
@@ -5882,9 +5894,10 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
5882
5894
auto VarInfo = i->getVarInfo ();
5883
5895
if (!VarInfo)
5884
5896
return ;
5885
-
5897
+ auto &ti = getTypeInfo (SILTy);
5886
5898
auto Storage =
5887
- emitShadowCopyIfNeeded (boxWithAddr.getAddress (), i->getDebugScope (),
5899
+ emitShadowCopyIfNeeded (boxWithAddr.getAddress (), ti.getStorageType (),
5900
+ i->getDebugScope (),
5888
5901
*VarInfo, IsAnonymous, false /* was moved*/ );
5889
5902
5890
5903
if (!IGM.DebugInfo )
0 commit comments