Skip to content

Commit 7821341

Browse files
committed
Add an argument-number field to DebugValueInst and friends.
This commit adds a DebugVariable field that is shared by - AllocBoxInst - AllocStackInst - DebugValueInst - DebugValueAddrInst Currently DebugVariable only holds the Swift argument number. This allows us to retire several expensive heuristics in IRGen that attempted to identify which local variables actually where arguments and recover their relative order. Memory footprint notes: This commit adds a 4-byte field to 4 SILInstructin subclasses. This was offset by 8ab1e2d which removed 20 bytes from *every* SILInstruction. Caveats: This commit surfaces a known bug in FunctionSigantureOpts, tracked in rdar://problem/23727705 — debug info for exploded function arguments cannot be expressed until this is fixed. This reapplies ed2b16d with a bugfix for generic function arrguments and an additional testcase. <rdar://problem/21185379&22705926>
1 parent c2448f4 commit 7821341

35 files changed

+326
-271
lines changed

include/swift/SIL/SILBuilder.h

+14-9
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,11 @@ class SILBuilder {
219219
// SILInstruction Creation Methods
220220
//===--------------------------------------------------------------------===//
221221

222-
AllocStackInst *createAllocStack(SILLocation Loc, SILType elementType) {
222+
AllocStackInst *createAllocStack(SILLocation Loc, SILType elementType,
223+
unsigned ArgNo = 0) {
223224
Loc.markAsPrologue();
224225
return insert(new (F.getModule()) AllocStackInst(
225-
createSILDebugLocation(Loc), elementType, F));
226+
createSILDebugLocation(Loc), elementType, F, ArgNo));
226227
}
227228

228229
AllocRefInst *createAllocRef(SILLocation Loc, SILType elementType, bool objc,
@@ -249,10 +250,11 @@ class SILBuilder {
249250
createSILDebugLocation(Loc), valueType, operand));
250251
}
251252

252-
AllocBoxInst *createAllocBox(SILLocation Loc, SILType ElementType) {
253+
AllocBoxInst *createAllocBox(SILLocation Loc, SILType ElementType,
254+
unsigned ArgNo = 0) {
253255
Loc.markAsPrologue();
254256
return insert(new (F.getModule()) AllocBoxInst(createSILDebugLocation(Loc),
255-
ElementType, F));
257+
ElementType, F, ArgNo));
256258
}
257259

258260
AllocExistentialBoxInst *
@@ -431,13 +433,16 @@ class SILBuilder {
431433
return insert(
432434
MarkFunctionEscapeInst::create(createSILDebugLocation(Loc), vars, F));
433435
}
434-
DebugValueInst *createDebugValue(SILLocation Loc, SILValue src) {
436+
437+
DebugValueInst *createDebugValue(SILLocation Loc, SILValue src,
438+
unsigned ArgNo = 0) {
435439
return insert(new (F.getModule())
436-
DebugValueInst(createSILDebugLocation(Loc), src));
440+
DebugValueInst(createSILDebugLocation(Loc), src, ArgNo));
437441
}
438-
DebugValueAddrInst *createDebugValueAddr(SILLocation Loc, SILValue src) {
439-
return insert(new (F.getModule())
440-
DebugValueAddrInst(createSILDebugLocation(Loc), src));
442+
DebugValueAddrInst *createDebugValueAddr(SILLocation Loc, SILValue src,
443+
unsigned ArgNo = 0) {
444+
return insert(new (F.getModule()) DebugValueAddrInst(
445+
createSILDebugLocation(Loc), src, ArgNo));
441446
}
442447

443448
LoadWeakInst *createLoadWeak(SILLocation Loc, SILValue src, IsTake_t isTake) {

include/swift/SIL/SILCloner.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,9 @@ SILCloner<ImplClass>::visitDebugValueInst(DebugValueInst *Inst) {
668668

669669
// Since we want the debug info to survive, we do not remap the location here.
670670
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
671-
doPostProcess(Inst,
672-
getBuilder().createDebugValue(Inst->getLoc(),
673-
getOpValue(Inst->getOperand())));
671+
doPostProcess(Inst, getBuilder().createDebugValue(
672+
Inst->getLoc(), getOpValue(Inst->getOperand()),
673+
Inst->getVarInfo().getArgNo()));
674674
}
675675
template<typename ImplClass>
676676
void
@@ -684,9 +684,9 @@ SILCloner<ImplClass>::visitDebugValueAddrInst(DebugValueAddrInst *Inst) {
684684
// Do not remap the location for a debug Instruction.
685685
SILValue OpValue = getOpValue(Inst->getOperand());
686686
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
687-
doPostProcess(Inst,
688-
getBuilder().createDebugValueAddr(Inst->getLoc(),
689-
OpValue));
687+
doPostProcess(
688+
Inst, getBuilder().createDebugValueAddr(Inst->getLoc(), OpValue,
689+
Inst->getVarInfo().getArgNo()));
690690
}
691691

692692

include/swift/SIL/SILInstruction.h

+35-7
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,27 @@ class UnaryInstructionBase : public BASE {
316316
typename std::enable_if<has_result<X>::value, SILType>::type
317317
getType(unsigned i = 0) const { return ValueBase::getType(i); }
318318

319-
ArrayRef<Operand> getAllOperands() const { return Operands.asArray(); }
319+
ArrayRef<Operand> getAllOperands() const { return Operands.asArray(); }\
320320
MutableArrayRef<Operand> getAllOperands() { return Operands.asArray(); }
321321

322322
static bool classof(const ValueBase *V) {
323323
return V->getKind() == KIND;
324324
}
325325
};
326326

327+
328+
/// Holds common debug information about local variables and function
329+
/// arguments that are needed by DebugValueInst, DebugValueAddrInst,
330+
/// AllocStackInst, and AllocBoxInst.
331+
class DebugVariable {
332+
/// The source function argument position from left to right
333+
/// starting with 1 or 0 if this is a local variable.
334+
unsigned char ArgNo;
335+
public:
336+
DebugVariable(unsigned ArgNo) : ArgNo(ArgNo) {};
337+
unsigned getArgNo() const { return ArgNo; }
338+
};
339+
327340
//===----------------------------------------------------------------------===//
328341
// Allocation Instructions
329342
//===----------------------------------------------------------------------===//
@@ -368,15 +381,20 @@ class StackPromotable {
368381
/// reference count) stack memory. The memory is provided uninitialized.
369382
class AllocStackInst : public AllocationInst {
370383
friend class SILBuilder;
384+
DebugVariable VarInfo;
371385

372-
AllocStackInst(SILDebugLocation *Loc, SILType elementType, SILFunction &F);
386+
AllocStackInst(SILDebugLocation *Loc, SILType elementType, SILFunction &F,
387+
unsigned ArgNo);
373388

374389
public:
375390

376391
/// getDecl - Return the underlying variable declaration associated with this
377392
/// allocation, or null if this is a temporary allocation.
378393
VarDecl *getDecl() const;
379394

395+
DebugVariable getVarInfo() const { return VarInfo; };
396+
void setArgNo(unsigned N) { VarInfo = DebugVariable(N); }
397+
380398
/// getElementType - Get the type of the allocated memory (as opposed to the
381399
/// (second) type of the instruction itself, which will be an address type).
382400
SILType getElementType() const {
@@ -463,7 +481,10 @@ class AllocValueBufferInst :
463481
class AllocBoxInst : public AllocationInst {
464482
friend class SILBuilder;
465483

466-
AllocBoxInst(SILDebugLocation *DebugLoc, SILType ElementType, SILFunction &F);
484+
DebugVariable VarInfo;
485+
486+
AllocBoxInst(SILDebugLocation *DebugLoc, SILType ElementType, SILFunction &F,
487+
unsigned ArgNo);
467488

468489
public:
469490

@@ -478,6 +499,8 @@ class AllocBoxInst : public AllocationInst {
478499
/// allocation, or null if this is a temporary allocation.
479500
VarDecl *getDecl() const;
480501

502+
DebugVariable getVarInfo() const { return VarInfo; };
503+
481504
ArrayRef<Operand> getAllOperands() const { return {}; }
482505
MutableArrayRef<Operand> getAllOperands() { return {}; }
483506

@@ -1341,29 +1364,34 @@ class MarkFunctionEscapeInst : public SILInstruction {
13411364
/// types).
13421365
class DebugValueInst : public UnaryInstructionBase<ValueKind::DebugValueInst> {
13431366
friend class SILBuilder;
1367+
DebugVariable VarInfo;
13441368

1345-
DebugValueInst(SILDebugLocation *DebugLoc, SILValue Operand)
1346-
: UnaryInstructionBase(DebugLoc, Operand) {}
1369+
DebugValueInst(SILDebugLocation *DebugLoc, SILValue Operand, unsigned ArgNo)
1370+
: UnaryInstructionBase(DebugLoc, Operand), VarInfo(ArgNo) {}
13471371

13481372
public:
13491373
/// getDecl - Return the underlying variable declaration that this denotes,
13501374
/// or null if we don't have one.
13511375
VarDecl *getDecl() const;
1376+
DebugVariable getVarInfo() const { return VarInfo; }
13521377
};
13531378

13541379
/// Define the start or update to a symbolic variable value (for address-only
13551380
/// types) .
13561381
class DebugValueAddrInst
13571382
: public UnaryInstructionBase<ValueKind::DebugValueAddrInst> {
13581383
friend class SILBuilder;
1384+
DebugVariable VarInfo;
13591385

1360-
DebugValueAddrInst(SILDebugLocation *DebugLoc, SILValue Operand)
1361-
: UnaryInstructionBase(DebugLoc, Operand) {}
1386+
DebugValueAddrInst(SILDebugLocation *DebugLoc, SILValue Operand,
1387+
unsigned ArgNo)
1388+
: UnaryInstructionBase(DebugLoc, Operand), VarInfo(ArgNo) {}
13621389

13631390
public:
13641391
/// getDecl - Return the underlying variable declaration that this denotes,
13651392
/// or null if we don't have one.
13661393
VarDecl *getDecl() const;
1394+
DebugVariable getVarInfo() const { return VarInfo; }
13671395
};
13681396

13691397

lib/IRGen/DebugTypeInfo.h

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ namespace swift {
7171
if (ValueDecl *D = getDecl()) return D->getDeclContext();
7272
else return DeclOrContext.get<DeclContext*>();
7373
}
74+
75+
void unwrapInOutType() {
76+
Type = Type->castTo<InOutType>()->getObjectType().getPointer();
77+
}
78+
7479
bool isNull() const { return Type == nullptr; }
7580
bool operator==(DebugTypeInfo T) const;
7681
bool operator!=(DebugTypeInfo T) const;

0 commit comments

Comments
 (0)