@@ -292,6 +292,9 @@ class IRGenSILFunction :
292
292
293
293
// / All alloc_ref instructions which allocate the object on the stack.
294
294
llvm::SmallPtrSet<SILInstruction *, 8 > StackAllocs;
295
+ // / Keeps track of the mapping of source variables to -O0 shadow copy allocas.
296
+ llvm::SmallDenseMap<std::pair<const SILDebugScope *, StringRef>, Address, 8 >
297
+ ShadowStackSlots;
295
298
296
299
// / Accumulative amount of allocated bytes on the stack. Used to limit the
297
300
// / size for stack promoted objects.
@@ -483,6 +486,7 @@ class IRGenSILFunction :
483
486
// / register pressure is high. There is a trade-off to this: With
484
487
// / shadow copies, we lose the precise lifetime.
485
488
llvm::Value *emitShadowCopy (llvm::Value *Storage,
489
+ const SILDebugScope *Scope,
486
490
StringRef Name,
487
491
Alignment Align = Alignment(0 )) {
488
492
auto Ty = Storage->getType ();
@@ -495,16 +499,21 @@ class IRGenSILFunction :
495
499
if (Align.isZero ())
496
500
Align = IGM.getPointerAlignment ();
497
501
498
- auto Alloca = createAlloca (Ty, Align, Name+" .addr" );
502
+ auto &Alloca = ShadowStackSlots[{Scope, Name}];
503
+ if (!Alloca.isValid ())
504
+ Alloca = createAlloca (Ty, Align, Name+" .addr" );
499
505
Builder.CreateStore (Storage, Alloca.getAddress (), Align);
500
506
return Alloca.getAddress ();
501
507
}
502
508
503
- llvm::Value *emitShadowCopy (Address storage, StringRef name) {
504
- return emitShadowCopy (storage.getAddress (), name, storage.getAlignment ());
509
+ llvm::Value *emitShadowCopy (Address Storage, const SILDebugScope *Scope,
510
+ StringRef Name) {
511
+ return emitShadowCopy (Storage.getAddress (), Scope, Name,
512
+ Storage.getAlignment ());
505
513
}
506
514
507
- void emitShadowCopy (ArrayRef<llvm::Value *> vals, StringRef name,
515
+ void emitShadowCopy (ArrayRef<llvm::Value *> vals, const SILDebugScope *scope,
516
+ StringRef name,
508
517
llvm::SmallVectorImpl<llvm::Value *> ©) {
509
518
// Only do this at -O0.
510
519
if (IGM.Opts .Optimize ) {
@@ -515,7 +524,7 @@ class IRGenSILFunction :
515
524
// Single or empty values.
516
525
if (vals.size () <= 1 ) {
517
526
for (auto val : vals)
518
- copy.push_back (emitShadowCopy (val, name));
527
+ copy.push_back (emitShadowCopy (val, scope, name));
519
528
return ;
520
529
}
521
530
@@ -1402,8 +1411,9 @@ void IRGenSILFunction::emitFunctionArgDebugInfo(SILBasicBlock *BB) {
1402
1411
unsigned ArgNo =
1403
1412
countArgs (CurSILFn->getDeclContext ()) + 1 + BB->getBBArgs ().size ();
1404
1413
IGM.DebugInfo ->emitVariableDeclaration (
1405
- Builder, emitShadowCopy (ErrorResultSlot.getAddress (), Name), DTI,
1406
- getDebugScope (), Name, ArgNo, IndirectValue, ArtificialValue);
1414
+ Builder,
1415
+ emitShadowCopy (ErrorResultSlot.getAddress (), getDebugScope (), Name),
1416
+ DTI, getDebugScope (), Name, ArgNo, IndirectValue, ArtificialValue);
1407
1417
}
1408
1418
}
1409
1419
@@ -2935,24 +2945,29 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
2935
2945
if (!IGM.DebugInfo )
2936
2946
return ;
2937
2947
2938
- VarDecl *Decl = i->getDecl ();
2939
- if (!Decl)
2940
- return ;
2941
-
2942
2948
auto SILVal = i->getOperand ();
2943
2949
if (isa<SILUndef>(SILVal))
2944
2950
return ;
2945
2951
2946
2952
StringRef Name = i->getVarInfo ().Name ;
2947
- Explosion e = getLoweredExplosion (SILVal);
2948
- DebugTypeInfo DbgTy (Decl, Decl->getType (), getTypeInfo (SILVal.getType ()));
2953
+ DebugTypeInfo DbgTy;
2954
+ SILType SILTy = SILVal.getType ();
2955
+ if (VarDecl *Decl = i->getDecl ())
2956
+ DbgTy = DebugTypeInfo (Decl, Decl->getType (), getTypeInfo (SILTy));
2957
+ else if (i->getFunction ()->isBare () &&
2958
+ !SILTy.getSwiftType ()->hasArchetype () && !Name.empty ())
2959
+ // Preliminary support for .sil debug information.
2960
+ DbgTy = DebugTypeInfo (SILTy.getSwiftType (), getTypeInfo (SILTy), nullptr );
2961
+ else
2962
+ return ;
2949
2963
// An inout/lvalue type that is described by a debug value has been
2950
2964
// promoted by an optimization pass. Unwrap the type.
2951
2965
DbgTy.unwrapLValueOrInOutType ();
2952
2966
2953
2967
// Put the value into a stack slot at -Onone.
2954
- llvm::SmallVector<llvm::Value *, 8 > Copy;
2955
- emitShadowCopy (e.claimAll (), Name, Copy);
2968
+ llvm::SmallVector<llvm::Value *, 8 > Copy;
2969
+ Explosion e = getLoweredExplosion (SILVal);
2970
+ emitShadowCopy (e.claimAll (), i->getDebugScope (), Name, Copy);
2956
2971
emitDebugVariableDeclaration (Copy, DbgTy, i->getDebugScope (), Name,
2957
2972
i->getVarInfo ().ArgNo );
2958
2973
}
@@ -2972,9 +2987,9 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
2972
2987
auto Addr = getLoweredAddress (SILVal).getAddress ();
2973
2988
DebugTypeInfo DbgTy (Decl, Decl->getType (), getTypeInfo (SILVal.getType ()));
2974
2989
// Put the value into a stack slot at -Onone and emit a debug intrinsic.
2975
- emitDebugVariableDeclaration (emitShadowCopy (Addr, Name), DbgTy,
2976
- i->getDebugScope (), Name,
2977
- i->getVarInfo ().ArgNo , IndirectValue);
2990
+ emitDebugVariableDeclaration (
2991
+ emitShadowCopy (Addr, i->getDebugScope (), Name), DbgTy ,
2992
+ i-> getDebugScope (), Name, i->getVarInfo ().ArgNo , IndirectValue);
2978
2993
}
2979
2994
2980
2995
void IRGenSILFunction::visitLoadWeakInst (swift::LoadWeakInst *i) {
@@ -3390,7 +3405,7 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
3390
3405
return ;
3391
3406
3392
3407
IGM.DebugInfo ->emitVariableDeclaration (
3393
- Builder, emitShadowCopy (addr.getAddress (), Name),
3408
+ Builder, emitShadowCopy (addr.getAddress (), i-> getDebugScope (), Name),
3394
3409
DebugTypeInfo (Decl, i->getElementType ().getSwiftType (), type),
3395
3410
i->getDebugScope (), Name, 0 , IndirectValue);
3396
3411
}
0 commit comments