Skip to content

Commit b769654

Browse files
authored
Merge pull request #39082 from mshockwave/dev-deprecate-debug-val-addr
[SIL][DebugInfo] PATCH 3/3: Deprecate debug_value_addr SIL instruciton
2 parents 5dea77e + 343d842 commit b769654

File tree

135 files changed

+624
-678
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+624
-678
lines changed

include/swift/SIL/DebugUtils.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212
//
1313
// This file contains utilities to work with debug-info related instructions:
14-
// debug_value and debug_value_addr.
14+
// debug_value, alloc_stack, and alloc_box.
1515
//
1616
// SIL optimizations should deal with debug-info related instructions when
1717
// looking at the uses of a value.
@@ -228,7 +228,6 @@ struct DebugVarCarryingInst {
228228
enum class Kind {
229229
Invalid = 0,
230230
DebugValue,
231-
DebugValueAddr,
232231
AllocStack,
233232
AllocBox,
234233
};
@@ -239,8 +238,6 @@ struct DebugVarCarryingInst {
239238
DebugVarCarryingInst() : kind(Kind::Invalid), inst(nullptr) {}
240239
DebugVarCarryingInst(DebugValueInst *dvi)
241240
: kind(Kind::DebugValue), inst(dvi) {}
242-
DebugVarCarryingInst(DebugValueAddrInst *dvai)
243-
: kind(Kind::DebugValueAddr), inst(dvai) {}
244241
DebugVarCarryingInst(AllocStackInst *asi)
245242
: kind(Kind::AllocStack), inst(asi) {}
246243
DebugVarCarryingInst(AllocBoxInst *abi) : kind(Kind::AllocBox), inst(abi) {}
@@ -252,9 +249,6 @@ struct DebugVarCarryingInst {
252249
case SILInstructionKind::DebugValueInst:
253250
kind = Kind::DebugValue;
254251
break;
255-
case SILInstructionKind::DebugValueAddrInst:
256-
kind = Kind::DebugValueAddr;
257-
break;
258252
case SILInstructionKind::AllocStackInst:
259253
kind = Kind::AllocStack;
260254
break;
@@ -283,8 +277,6 @@ struct DebugVarCarryingInst {
283277
llvm_unreachable("Invalid?!");
284278
case Kind::DebugValue:
285279
return cast<DebugValueInst>(inst)->getDecl();
286-
case Kind::DebugValueAddr:
287-
return cast<DebugValueAddrInst>(inst)->getDecl();
288280
case Kind::AllocStack:
289281
return cast<AllocStackInst>(inst)->getDecl();
290282
case Kind::AllocBox:
@@ -299,8 +291,6 @@ struct DebugVarCarryingInst {
299291
llvm_unreachable("Invalid?!");
300292
case Kind::DebugValue:
301293
return cast<DebugValueInst>(inst)->getVarInfo();
302-
case Kind::DebugValueAddr:
303-
return cast<DebugValueAddrInst>(inst)->getVarInfo();
304294
case Kind::AllocStack:
305295
return cast<AllocStackInst>(inst)->getVarInfo();
306296
case Kind::AllocBox:
@@ -316,9 +306,6 @@ struct DebugVarCarryingInst {
316306
case Kind::DebugValue:
317307
cast<DebugValueInst>(inst)->setDebugVarScope(NewDS);
318308
break;
319-
case Kind::DebugValueAddr:
320-
cast<DebugValueAddrInst>(inst)->setDebugVarScope(NewDS);
321-
break;
322309
case Kind::AllocStack:
323310
cast<AllocStackInst>(inst)->setDebugVarScope(NewDS);
324311
break;

include/swift/SIL/Projection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ class ProjectionTree {
859859
ProjectionTree &operator=(ProjectionTree &&) = default;
860860

861861
/// Compute liveness and use information in this projection tree using Base.
862-
/// All debug instructions (debug_value, debug_value_addr) are ignored.
862+
/// All debug_value instructions are ignored.
863863
void computeUsesAndLiveness(SILValue Base);
864864

865865
/// Create a root SILValue iout of the given leaf node values by walking on

include/swift/SIL/SILBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,10 @@ class SILBuilder {
927927
DebugValueInst *createDebugValue(SILLocation Loc, SILValue src,
928928
SILDebugVariable Var,
929929
bool poisonRefs = false);
930-
DebugValueAddrInst *createDebugValueAddr(SILLocation Loc, SILValue src,
931-
SILDebugVariable Var);
930+
DebugValueInst *createDebugValueAddr(SILLocation Loc, SILValue src,
931+
SILDebugVariable Var);
932932

933-
/// Create a debug_value_addr if \p src is an address; a debug_value if not.
933+
/// Create a debug_value according to the type of \p src
934934
SILInstruction *emitDebugDescription(SILLocation Loc, SILValue src,
935935
SILDebugVariable Var) {
936936
if (src->getType().isAddress())

include/swift/SIL/SILCloner.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,24 +1254,6 @@ SILCloner<ImplClass>::visitDebugValueInst(DebugValueInst *Inst) {
12541254
remapDebugVarInfo(DebugVarCarryingInst(NewInst));
12551255
recordClonedInstruction(Inst, NewInst);
12561256
}
1257-
template<typename ImplClass>
1258-
void
1259-
SILCloner<ImplClass>::visitDebugValueAddrInst(DebugValueAddrInst *Inst) {
1260-
// We cannot inline/clone debug intrinsics without a scope. If they
1261-
// describe function arguments there is no way to determine which
1262-
// function they belong to.
1263-
if (!Inst->getDebugScope())
1264-
return;
1265-
1266-
// Do not remap the location for a debug Instruction.
1267-
SILDebugVariable VarInfo = *Inst->getVarInfo();
1268-
SILValue OpValue = getOpValue(Inst->getOperand());
1269-
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1270-
auto *NewInst = getBuilder().createDebugValueAddr(Inst->getLoc(), OpValue,
1271-
*Inst->getVarInfo());
1272-
remapDebugVarInfo(DebugVarCarryingInst(NewInst));
1273-
recordClonedInstruction(Inst, NewInst);
1274-
}
12751257

12761258
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
12771259
template <typename ImplClass> \

include/swift/SIL/SILDebugInfoExpression.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ class SILDebugInfoExpression {
162162
appendElements(Tail.Elements);
163163
}
164164

165+
void prependElements(llvm::ArrayRef<SILDIExprElement> NewElements) {
166+
Elements.insert(Elements.begin(),
167+
NewElements.begin(), NewElements.end());
168+
}
169+
170+
void eraseElement(const_iterator It) {
171+
Elements.erase(It);
172+
}
173+
165174
/// The iterator for SILDIExprOperand
166175
class op_iterator {
167176
friend class SILDebugInfoExpression;

include/swift/SIL/SILInstruction.h

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,7 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
734734
/// Returns true if the instruction is only relevant for debug
735735
/// informations and has no other impact on program semantics.
736736
bool isDebugInstruction() const {
737-
return getKind() == SILInstructionKind::DebugValueInst ||
738-
getKind() == SILInstructionKind::DebugValueAddrInst;
737+
return getKind() == SILInstructionKind::DebugValueInst;
739738
}
740739

741740
/// Returns true if the instruction is a meta instruction which is
@@ -1720,8 +1719,8 @@ class UnaryInstructionWithTypeDependentOperandsBase
17201719
};
17211720

17221721
/// Holds common debug information about local variables and function
1723-
/// arguments that are needed by DebugValueInst, DebugValueAddrInst,
1724-
/// AllocStackInst, and AllocBoxInst.
1722+
/// arguments that are needed by DebugValueInst, AllocStackInst,
1723+
/// and AllocBoxInst.
17251724
struct SILDebugVariable {
17261725
StringRef Name;
17271726
unsigned ArgNo : 16;
@@ -4672,6 +4671,8 @@ class DebugValueInst final
46724671
static DebugValueInst *create(SILDebugLocation DebugLoc, SILValue Operand,
46734672
SILModule &M, SILDebugVariable Var,
46744673
bool poisonRefs);
4674+
static DebugValueInst *createAddr(SILDebugLocation DebugLoc, SILValue Operand,
4675+
SILModule &M, SILDebugVariable Var);
46754676

46764677
SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL()
46774678

@@ -4706,6 +4707,23 @@ class DebugValueInst final
47064707
*getTrailingObjects<const SILDebugScope *>() = NewDS;
47074708
}
47084709

4710+
/// Whether the SSA value associated with the current debug_value
4711+
/// instruction has an address type.
4712+
bool hasAddrVal() const {
4713+
return getOperand()->getType().isAddress();
4714+
}
4715+
4716+
/// An utility to check if \p I is DebugValueInst and
4717+
/// whether it's associated with address type SSA value.
4718+
static DebugValueInst *hasAddrVal(SILInstruction *I) {
4719+
auto *DVI = dyn_cast_or_null<DebugValueInst>(I);
4720+
return DVI && DVI->hasAddrVal()? DVI : nullptr;
4721+
}
4722+
4723+
/// Whether the attached di-expression (if there is any) starts
4724+
/// with `op_deref`.
4725+
bool exprStartsWithDeref() const;
4726+
47094727
/// True if all references within this debug value will be overwritten with a
47104728
/// poison sentinel at this point in the program. This is used in debug builds
47114729
/// when shortening non-trivial value lifetimes to ensure the debugger cannot
@@ -4722,58 +4740,6 @@ class DebugValueInst final
47224740
}
47234741
};
47244742

4725-
/// Define the start or update to a symbolic variable value (for address-only
4726-
/// types) .
4727-
class DebugValueAddrInst final
4728-
: public UnaryInstructionBase<SILInstructionKind::DebugValueAddrInst,
4729-
NonValueInstruction>,
4730-
private SILDebugVariableSupplement,
4731-
private llvm::TrailingObjects<DebugValueAddrInst, SILType, SILLocation,
4732-
const SILDebugScope *, SILDIExprElement,
4733-
char> {
4734-
friend TrailingObjects;
4735-
friend SILBuilder;
4736-
4737-
TailAllocatedDebugVariable VarInfo;
4738-
4739-
DebugValueAddrInst(SILDebugLocation DebugLoc, SILValue Operand,
4740-
SILDebugVariable Var);
4741-
static DebugValueAddrInst *create(SILDebugLocation DebugLoc,
4742-
SILValue Operand, SILModule &M,
4743-
SILDebugVariable Var);
4744-
4745-
SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL()
4746-
4747-
public:
4748-
/// Return the underlying variable declaration that this denotes,
4749-
/// or null if we don't have one.
4750-
VarDecl *getDecl() const;
4751-
/// Return the debug variable information attached to this instruction.
4752-
Optional<SILDebugVariable> getVarInfo() const {
4753-
Optional<SILType> AuxVarType;
4754-
Optional<SILLocation> VarDeclLoc;
4755-
const SILDebugScope *VarDeclScope = nullptr;
4756-
if (HasAuxDebugVariableType)
4757-
AuxVarType = *getTrailingObjects<SILType>();
4758-
4759-
if (hasAuxDebugLocation())
4760-
VarDeclLoc = *getTrailingObjects<SILLocation>();
4761-
if (hasAuxDebugScope())
4762-
VarDeclScope = *getTrailingObjects<const SILDebugScope *>();
4763-
4764-
llvm::ArrayRef<SILDIExprElement> DIExprElements(
4765-
getTrailingObjects<SILDIExprElement>(), NumDIExprOperands);
4766-
4767-
return VarInfo.get(getDecl(), getTrailingObjects<char>(), AuxVarType,
4768-
VarDeclLoc, VarDeclScope, DIExprElements);
4769-
}
4770-
4771-
void setDebugVarScope(const SILDebugScope *NewDS) {
4772-
if (hasAuxDebugScope())
4773-
*getTrailingObjects<const SILDebugScope *>() = NewDS;
4774-
}
4775-
};
4776-
47774743
/// An abstract class representing a load from some kind of reference storage.
47784744
template <SILInstructionKind K>
47794745
class LoadReferenceInstBase

include/swift/SIL/SILNodes.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,6 @@ NON_VALUE_INST(MarkFunctionEscapeInst, mark_function_escape,
875875
SILInstruction, None, DoesNotRelease)
876876
BRIDGED_NON_VALUE_INST(DebugValueInst, debug_value,
877877
SILInstruction, None, DoesNotRelease)
878-
BRIDGED_NON_VALUE_INST(DebugValueAddrInst, debug_value_addr,
879-
SILInstruction, None, DoesNotRelease)
880878
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
881879
NON_VALUE_INST(Store##Name##Inst, store_##name, \
882880
SILInstruction, MayWrite, DoesNotRelease)

include/swift/SILOptimizer/Utils/CanonicalOSSALifetime.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
/// bb0(%arg : @owned $T, %addr : @trivial $*T):
2828
/// %copy = copy_value %arg : $T
2929
/// store %copy to [init] %addr : $*T
30-
/// debug_value_addr %addr : $*T
30+
/// debug_value %addr : $*T, expr op_deref
3131
/// destroy_value %arg : $T
3232
///
3333
/// Will be transformed to:
3434
///
3535
/// bb0(%arg : @owned $T, %addr : @trivial $*T):
3636
/// store %copy to [init] %addr : $*T
37-
/// debug_value_addr %addr : $*T
37+
/// debug_value %addr : $*T, expr op_deref
3838
///
3939
/// Example #2: Destroys are hoisted to the last use. Copies are inserted only
4040
/// at consumes within the lifetime (to directly satisfy ownership conventions):
@@ -43,7 +43,7 @@
4343
/// %copy1 = copy_value %arg : $T
4444
/// store %arg to [init] %addr : $*T
4545
/// %_ = apply %_(%copy1) : $@convention(thin) (@guaranteed T) -> ()
46-
/// debug_value_addr %addr : $*T
46+
/// debug_value %addr : $*T, expr op_deref
4747
/// destroy_value %copy1 : $T
4848
///
4949
/// Will be transformed to:
@@ -53,7 +53,7 @@
5353
/// store %copy1 to [init] %addr : $*T
5454
/// %_ = apply %_(%arg) : $@convention(thin) (@guaranteed T) -> ()
5555
/// destroy_value %arg : $T
56-
/// debug_value_addr %addr : $*T
56+
/// debug_value %addr : $*T, expr op_deref
5757
///
5858
/// Example #3: Handle control flow.
5959
///

include/swift/SILOptimizer/Utils/DebugOptUtils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ inline void deleteAllDebugUses(SILInstruction *inst,
4444
}
4545

4646
/// Transfer debug info associated with (the result of) \p I to a
47-
/// new `debug_value` or `debug_value_addr` instruction before \p I is
48-
/// deleted.
47+
/// new `debug_value` instruction before \p I is deleted.
4948
void salvageDebugInfo(SILInstruction *I);
5049

5150
/// Erases the instruction \p I from it's parent block and deletes it, including

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,9 @@ bool IRGenDebugInfoImpl::buildDebugInfoExpression(
24102410
if (!handleFragmentDIExpr(ExprOperand, Operands))
24112411
return false;
24122412
break;
2413+
case SILDIExprOperator::Dereference:
2414+
Operands.push_back(llvm::dwarf::DW_OP_deref);
2415+
break;
24132416
default:
24142417
llvm_unreachable("Unrecognized operator");
24152418
}

0 commit comments

Comments
 (0)