@@ -295,6 +295,8 @@ class IRGenSILFunction :
295
295
// / Keeps track of the mapping of source variables to -O0 shadow copy allocas.
296
296
llvm::SmallDenseMap<std::pair<const SILDebugScope *, StringRef>, Address, 8 >
297
297
ShadowStackSlots;
298
+ llvm::SmallDenseMap<Decl *, SmallString<4 >, 8 > AnonymousVariables;
299
+ unsigned NumAnonVars = 0 ;
298
300
299
301
// / Accumulative amount of allocated bytes on the stack. Used to limit the
300
302
// / size for stack promoted objects.
@@ -481,6 +483,26 @@ class IRGenSILFunction :
481
483
return foundBB->second ;
482
484
}
483
485
486
+ StringRef getOrCreateAnonymousVarName (VarDecl *Decl) {
487
+ llvm::SmallString<4 > &Name = AnonymousVariables[Decl];
488
+ if (Name.empty ()) {
489
+ {
490
+ llvm::raw_svector_ostream S (Name);
491
+ S << ' _' << NumAnonVars++;
492
+ }
493
+ AnonymousVariables.insert ({Decl, Name});
494
+ }
495
+ return Name;
496
+ }
497
+
498
+ template <class DebugVarCarryingInst >
499
+ StringRef getVarName (DebugVarCarryingInst *i) {
500
+ StringRef Name = i->getVarInfo ().Name ;
501
+ if (Name.empty () && i->getDecl ())
502
+ return getOrCreateAnonymousVarName (i->getDecl ());
503
+ return Name;
504
+ }
505
+
484
506
// / At -O0, emit a shadow copy of an Address in an alloca, so the
485
507
// / register allocator doesn't elide the dbg.value intrinsic when
486
508
// / register pressure is high. There is a trade-off to this: With
@@ -587,6 +609,8 @@ class IRGenSILFunction :
587
609
588
610
void emitFunctionArgDebugInfo (SILBasicBlock *BB);
589
611
612
+ void emitDebugInfoForAllocStack (AllocStackInst *i, const TypeInfo &type,
613
+ llvm::Value *addr);
590
614
void visitAllocStackInst (AllocStackInst *i);
591
615
void visitAllocRefInst (AllocRefInst *i);
592
616
void visitAllocRefDynamicInst (AllocRefDynamicInst *i);
@@ -2949,7 +2973,7 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
2949
2973
if (isa<SILUndef>(SILVal))
2950
2974
return ;
2951
2975
2952
- StringRef Name = i-> getVarInfo (). Name ;
2976
+ StringRef Name = getVarName (i) ;
2953
2977
DebugTypeInfo DbgTy;
2954
2978
SILType SILTy = SILVal.getType ();
2955
2979
if (VarDecl *Decl = i->getDecl ())
@@ -2983,7 +3007,7 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
2983
3007
if (isa<SILUndef>(SILVal))
2984
3008
return ;
2985
3009
2986
- StringRef Name = i-> getVarInfo (). Name ;
3010
+ StringRef Name = getVarName (i) ;
2987
3011
auto Addr = getLoweredAddress (SILVal).getAddress ();
2988
3012
DebugTypeInfo DbgTy (Decl, Decl->getType (), getTypeInfo (SILVal.getType ()));
2989
3013
// Put the value into a stack slot at -Onone and emit a debug intrinsic.
@@ -3231,25 +3255,23 @@ static bool tryDeferFixedSizeBufferInitialization(IRGenSILFunction &IGF,
3231
3255
return false ;
3232
3256
}
3233
3257
3234
- static void emitDebugDeclarationForAllocStack (IRGenSILFunction &IGF,
3235
- AllocStackInst *i,
3236
- const TypeInfo &type,
3237
- llvm::Value *addr) {
3258
+ void IRGenSILFunction::emitDebugInfoForAllocStack (AllocStackInst *i,
3259
+ const TypeInfo &type,
3260
+ llvm::Value *addr) {
3238
3261
VarDecl *Decl = i->getDecl ();
3239
- if (IGF. IGM .DebugInfo && Decl) {
3262
+ if (IGM.DebugInfo && Decl) {
3240
3263
auto *Pattern = Decl->getParentPattern ();
3241
3264
if (!Pattern || !Pattern->isImplicit ()) {
3242
3265
auto DbgTy = DebugTypeInfo (Decl, type);
3243
3266
// Discard any inout or lvalue qualifiers. Since the object itself
3244
3267
// is stored in the alloca, emitting it as a reference type would
3245
3268
// be wrong.
3246
3269
DbgTy.unwrapLValueOrInOutType ();
3247
- auto Name = i->getVarInfo ().Name .empty () ? " _" : i->getVarInfo ().Name ;
3248
- auto DS = i->getDebugScope ();
3249
- if (DS) {
3250
- assert (DS->SILFn == IGF.CurSILFn || DS->InlinedCallSite );
3251
- IGF.emitDebugVariableDeclaration (addr, DbgTy, DS, Name,
3252
- i->getVarInfo ().ArgNo );
3270
+ StringRef Name = getVarName (i);
3271
+ if (auto DS = i->getDebugScope ()) {
3272
+ assert (DS->SILFn == CurSILFn || DS->InlinedCallSite );
3273
+ emitDebugVariableDeclaration (addr, DbgTy, DS, Name,
3274
+ i->getVarInfo ().ArgNo );
3253
3275
}
3254
3276
}
3255
3277
}
@@ -3263,7 +3285,7 @@ void IRGenSILFunction::visitAllocStackInst(swift::AllocStackInst *i) {
3263
3285
StringRef dbgname;
3264
3286
# ifndef NDEBUG
3265
3287
// If this is a DEBUG build, use pretty names for the LLVM IR.
3266
- dbgname = i-> getVarInfo (). Name ;
3288
+ dbgname = getVarName (i) ;
3267
3289
# endif
3268
3290
3269
3291
(void ) Decl;
@@ -3280,10 +3302,8 @@ void IRGenSILFunction::visitAllocStackInst(swift::AllocStackInst *i) {
3280
3302
auto addr = type.allocateStack (*this ,
3281
3303
i->getElementType (),
3282
3304
dbgname);
3283
-
3284
- emitDebugDeclarationForAllocStack (*this , i, type,
3285
- addr.getAddress ().getAddress ());
3286
-
3305
+
3306
+ emitDebugInfoForAllocStack (i, type, addr.getAddress ().getAddress ());
3287
3307
setLoweredAddress (i->getContainerResult (), addr.getContainer ());
3288
3308
setLoweredAddress (i->getAddressResult (), addr.getAddress ());
3289
3309
}
@@ -3377,7 +3397,7 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
3377
3397
3378
3398
// Derive name from SIL location.
3379
3399
VarDecl *Decl = i->getDecl ();
3380
- StringRef Name = i-> getVarInfo (). Name ;
3400
+ StringRef Name = getVarName (i) ;
3381
3401
StringRef DbgName =
3382
3402
# ifndef NDEBUG
3383
3403
// If this is a DEBUG build, use pretty names for the LLVM IR.
@@ -4332,15 +4352,15 @@ void IRGenSILFunction::visitWitnessMethodInst(swift::WitnessMethodInst *i) {
4332
4352
4333
4353
void IRGenSILFunction::setAllocatedAddressForBuffer (SILValue v,
4334
4354
const Address &allocedAddress) {
4335
- assert (getLoweredValue (v).kind == LoweredValue::Kind::UnallocatedAddressInBuffer
4336
- && " not an unallocated address" );
4337
-
4355
+ assert (getLoweredValue (v).kind ==
4356
+ LoweredValue::Kind::UnallocatedAddressInBuffer &&
4357
+ " not an unallocated address" );
4358
+
4338
4359
overwriteLoweredAddress (v, allocedAddress);
4339
4360
// Emit the debug info for the variable if any.
4340
4361
if (auto allocStack = dyn_cast<AllocStackInst>(v)) {
4341
- emitDebugDeclarationForAllocStack (*this , allocStack,
4342
- getTypeInfo (v.getType ()),
4343
- allocedAddress.getAddress ());
4362
+ emitDebugInfoForAllocStack (allocStack, getTypeInfo (v.getType ()),
4363
+ allocedAddress.getAddress ());
4344
4364
}
4345
4365
}
4346
4366
0 commit comments