@@ -341,13 +341,45 @@ class UnaryInstructionBase : public BASE {
341
341
// / Holds common debug information about local variables and function
342
342
// / arguments that are needed by DebugValueInst, DebugValueAddrInst,
343
343
// / AllocStackInst, and AllocBoxInst.
344
- class DebugVariable {
344
+ struct SILDebugVariable {
345
+ SILDebugVariable () : Constant(true ), ArgNo(0 ) {}
346
+ SILDebugVariable (bool Constant, unsigned ArgNo)
347
+ : Constant(Constant), ArgNo(ArgNo) {}
348
+ SILDebugVariable (StringRef Name, bool Constant, unsigned ArgNo)
349
+ : Name(Name), Constant(Constant), ArgNo(ArgNo) {}
350
+ StringRef Name;
351
+ bool Constant;
352
+ unsigned ArgNo;
353
+ };
354
+
355
+ // / A DebugVariable where storage for the strings has been
356
+ // / tail-allocated following the parent SILInstruction.
357
+ class TailAllocatedDebugVariable {
345
358
// / The source function argument position from left to right
346
359
// / starting with 1 or 0 if this is a local variable.
347
- unsigned char ArgNo;
360
+ unsigned ArgNo : 16 ;
361
+ // / When this is nonzero there is a tail-allocated string storing
362
+ // / variable name present. This typically only happens for
363
+ // / instructions that were created from parsing SIL assembler.
364
+ unsigned NameLength : 15 ;
365
+ bool Constant : 1 ;
348
366
public:
349
- DebugVariable (unsigned ArgNo) : ArgNo(ArgNo) {};
367
+ TailAllocatedDebugVariable (SILDebugVariable DbgVar, char *buf);
368
+
350
369
unsigned getArgNo () const { return ArgNo; }
370
+ void setArgNo (unsigned N) { ArgNo = N; }
371
+ // / Returns the name of the source variable, if it is stored in the
372
+ // / instruction.
373
+ StringRef getName (const char *buf) const ;
374
+ bool isLet () const { return Constant; }
375
+
376
+ SILDebugVariable get (VarDecl *VD, const char *buf) const {
377
+ if (VD)
378
+ return {VD->getName ().empty () ? " " : VD->getName ().str (), VD->isLet (),
379
+ getArgNo ()};
380
+ else
381
+ return {getName (buf), isLet (), getArgNo ()};
382
+ }
351
383
};
352
384
353
385
// ===----------------------------------------------------------------------===//
@@ -394,19 +426,24 @@ class StackPromotable {
394
426
// / reference count) stack memory. The memory is provided uninitialized.
395
427
class AllocStackInst : public AllocationInst {
396
428
friend class SILBuilder ;
397
- DebugVariable VarInfo;
429
+ TailAllocatedDebugVariable VarInfo;
398
430
399
431
AllocStackInst (SILDebugLocation *Loc, SILType elementType, SILFunction &F,
400
- unsigned ArgNo);
432
+ SILDebugVariable Var);
433
+ static AllocStackInst *create (SILDebugLocation *Loc, SILType elementType,
434
+ SILFunction &F, SILDebugVariable Var);
401
435
402
436
public:
403
437
404
- // / getDecl - Return the underlying variable declaration associated with this
438
+ // / Return the underlying variable declaration associated with this
405
439
// / allocation, or null if this is a temporary allocation.
406
440
VarDecl *getDecl () const ;
407
441
408
- DebugVariable getVarInfo () const { return VarInfo; };
409
- void setArgNo (unsigned N) { VarInfo = DebugVariable (N); }
442
+ // / Return the debug variable information attached to this instruction.
443
+ SILDebugVariable getVarInfo () const {
444
+ return VarInfo.get (getDecl (), reinterpret_cast <const char *>(this + 1 ));
445
+ };
446
+ void setArgNo (unsigned N) { VarInfo.setArgNo (N); }
410
447
411
448
// / getElementType - Get the type of the allocated memory (as opposed to the
412
449
// / (second) type of the instruction itself, which will be an address type).
@@ -494,10 +531,12 @@ class AllocValueBufferInst :
494
531
class AllocBoxInst : public AllocationInst {
495
532
friend class SILBuilder ;
496
533
497
- DebugVariable VarInfo;
534
+ TailAllocatedDebugVariable VarInfo;
498
535
499
536
AllocBoxInst (SILDebugLocation *DebugLoc, SILType ElementType, SILFunction &F,
500
- unsigned ArgNo);
537
+ SILDebugVariable Var);
538
+ static AllocBoxInst *create (SILDebugLocation *Loc, SILType elementType,
539
+ SILFunction &F, SILDebugVariable Var);
501
540
502
541
public:
503
542
@@ -508,11 +547,14 @@ class AllocBoxInst : public AllocationInst {
508
547
SILValue getContainerResult () const { return SILValue (this , 0 ); }
509
548
SILValue getAddressResult () const { return SILValue (this , 1 ); }
510
549
511
- // / getDecl - Return the underlying variable declaration associated with this
550
+ // / Return the underlying variable declaration associated with this
512
551
// / allocation, or null if this is a temporary allocation.
513
552
VarDecl *getDecl () const ;
514
553
515
- DebugVariable getVarInfo () const { return VarInfo; };
554
+ // / Return the debug variable information attached to this instruction.
555
+ SILDebugVariable getVarInfo () const {
556
+ return VarInfo.get (getDecl (), reinterpret_cast <const char *>(this + 1 ));
557
+ };
516
558
517
559
ArrayRef<Operand> getAllOperands () const { return {}; }
518
560
MutableArrayRef<Operand> getAllOperands () { return {}; }
@@ -1377,34 +1419,44 @@ class MarkFunctionEscapeInst : public SILInstruction {
1377
1419
// / types).
1378
1420
class DebugValueInst : public UnaryInstructionBase <ValueKind::DebugValueInst> {
1379
1421
friend class SILBuilder ;
1380
- DebugVariable VarInfo;
1422
+ TailAllocatedDebugVariable VarInfo;
1381
1423
1382
- DebugValueInst (SILDebugLocation *DebugLoc, SILValue Operand, unsigned ArgNo)
1383
- : UnaryInstructionBase(DebugLoc, Operand), VarInfo(ArgNo) {}
1424
+ DebugValueInst (SILDebugLocation *DebugLoc, SILValue Operand,
1425
+ SILDebugVariable Var);
1426
+ static DebugValueInst *create (SILDebugLocation *DebugLoc, SILValue Operand,
1427
+ SILModule &M, SILDebugVariable Var);
1384
1428
1385
1429
public:
1386
- // / getDecl - Return the underlying variable declaration that this denotes,
1430
+ // / Return the underlying variable declaration that this denotes,
1387
1431
// / or null if we don't have one.
1388
1432
VarDecl *getDecl () const ;
1389
- DebugVariable getVarInfo () const { return VarInfo; }
1433
+ // / Return the debug variable information attached to this instruction.
1434
+ SILDebugVariable getVarInfo () const {
1435
+ return VarInfo.get (getDecl (), reinterpret_cast <const char *>(this + 1 ));
1436
+ }
1390
1437
};
1391
1438
1392
1439
// / Define the start or update to a symbolic variable value (for address-only
1393
1440
// / types) .
1394
1441
class DebugValueAddrInst
1395
1442
: public UnaryInstructionBase<ValueKind::DebugValueAddrInst> {
1396
1443
friend class SILBuilder ;
1397
- DebugVariable VarInfo;
1444
+ TailAllocatedDebugVariable VarInfo;
1398
1445
1399
1446
DebugValueAddrInst (SILDebugLocation *DebugLoc, SILValue Operand,
1400
- unsigned ArgNo)
1401
- : UnaryInstructionBase(DebugLoc, Operand), VarInfo(ArgNo) {}
1447
+ SILDebugVariable Var);
1448
+ static DebugValueAddrInst *create (SILDebugLocation *DebugLoc,
1449
+ SILValue Operand, SILModule &M,
1450
+ SILDebugVariable Var);
1402
1451
1403
1452
public:
1404
- // / getDecl - Return the underlying variable declaration that this denotes,
1453
+ // / Return the underlying variable declaration that this denotes,
1405
1454
// / or null if we don't have one.
1406
1455
VarDecl *getDecl () const ;
1407
- DebugVariable getVarInfo () const { return VarInfo; }
1456
+ // / Return the debug variable information attached to this instruction.
1457
+ SILDebugVariable getVarInfo () const {
1458
+ return VarInfo.get (getDecl (), reinterpret_cast <const char *>(this + 1 ));
1459
+ };
1408
1460
};
1409
1461
1410
1462
0 commit comments