@@ -1806,6 +1806,50 @@ class TailAllocatedDebugVariable {
18061806static_assert (sizeof (TailAllocatedDebugVariable) == 4 ,
18071807 " SILNode inline bitfield needs updating" );
18081808
1809+ // / Used for keeping track of advanced / supplement debug variable info
1810+ // / stored in trailing objects space inside debug instructions (e.g.
1811+ // / debug_value)
1812+ class SILDebugVariableSupplement {
1813+ protected:
1814+ enum SourceLocKind : unsigned { SLK_Loc = 0b01 , SLK_Scope = 0b10 };
1815+
1816+ unsigned NumDIExprOperands : 8 ;
1817+
1818+ unsigned HasAuxDebugVariableType : 1 ;
1819+
1820+ unsigned AuxVariableSourceLoc : 2 ;
1821+
1822+ SILDebugVariableSupplement (unsigned NumDIExprOps, bool AuxType, bool AuxLoc,
1823+ bool AuxScope)
1824+ : NumDIExprOperands(NumDIExprOps), HasAuxDebugVariableType(AuxType),
1825+ AuxVariableSourceLoc ((AuxLoc ? SLK_Loc : 0 ) |
1826+ (AuxScope ? SLK_Scope : 0 )) {}
1827+ };
1828+
1829+ #define SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL () \
1830+ inline bool hasAuxDebugLocation () const { \
1831+ return AuxVariableSourceLoc & SLK_Loc; \
1832+ } \
1833+ inline bool hasAuxDebugScope () const { \
1834+ return AuxVariableSourceLoc & SLK_Scope; \
1835+ } \
1836+ \
1837+ size_t numTrailingObjects (OverloadToken<SILType>) const { \
1838+ return HasAuxDebugVariableType ? 1 : 0 ; \
1839+ } \
1840+ \
1841+ size_t numTrailingObjects (OverloadToken<SILLocation>) const { \
1842+ return hasAuxDebugLocation () ? 1 : 0 ; \
1843+ } \
1844+ \
1845+ size_t numTrailingObjects (OverloadToken<const SILDebugScope *>) const { \
1846+ return hasAuxDebugScope () ? 1 : 0 ; \
1847+ } \
1848+ \
1849+ size_t numTrailingObjects (OverloadToken<SILDIExprElement>) const { \
1850+ return NumDIExprOperands; \
1851+ }
1852+
18091853// ===----------------------------------------------------------------------===//
18101854// Allocation Instructions
18111855// ===----------------------------------------------------------------------===//
@@ -1833,7 +1877,10 @@ class DeallocStackInst;
18331877class AllocStackInst final
18341878 : public InstructionBase<SILInstructionKind::AllocStackInst,
18351879 AllocationInst>,
1836- private llvm::TrailingObjects<AllocStackInst, Operand, char > {
1880+ private SILDebugVariableSupplement,
1881+ private llvm::TrailingObjects<AllocStackInst, SILType, SILLocation,
1882+ const SILDebugScope *, SILDIExprElement,
1883+ Operand, char > {
18371884 friend TrailingObjects;
18381885 friend SILBuilder;
18391886
@@ -1849,6 +1896,8 @@ class AllocStackInst final
18491896 Optional<SILDebugVariable> Var,
18501897 bool hasDynamicLifetime);
18511898
1899+ SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL ()
1900+
18521901 size_t numTrailingObjects (OverloadToken<Operand>) const {
18531902 return SILNode::Bits.AllocStackInst .NumOperands ;
18541903 }
@@ -1878,9 +1927,24 @@ class AllocStackInst final
18781927
18791928 // / Return the debug variable information attached to this instruction.
18801929 Optional<SILDebugVariable> getVarInfo () const {
1930+ Optional<SILType> AuxVarType;
1931+ Optional<SILLocation> VarDeclLoc;
1932+ const SILDebugScope *VarDeclScope = nullptr ;
1933+ if (HasAuxDebugVariableType)
1934+ AuxVarType = *getTrailingObjects<SILType>();
1935+
1936+ if (hasAuxDebugLocation ())
1937+ VarDeclLoc = *getTrailingObjects<SILLocation>();
1938+ if (hasAuxDebugScope ())
1939+ VarDeclScope = *getTrailingObjects<const SILDebugScope *>();
1940+
1941+ llvm::ArrayRef<SILDIExprElement> DIExprElements (
1942+ getTrailingObjects<SILDIExprElement>(), NumDIExprOperands);
1943+
18811944 auto RawValue = SILNode::Bits.AllocStackInst .VarInfo ;
18821945 auto VI = TailAllocatedDebugVariable (RawValue);
1883- return VI.get (getDecl (), getTrailingObjects<char >());
1946+ return VI.get (getDecl (), getTrailingObjects<char >(), AuxVarType, VarDeclLoc,
1947+ VarDeclScope, DIExprElements);
18841948 };
18851949 void setArgNo (unsigned N) {
18861950 auto RawValue = SILNode::Bits.AllocStackInst .VarInfo ;
@@ -4560,29 +4624,18 @@ class MarkFunctionEscapeInst final
45604624 }
45614625};
45624626
4563- // / Simple bitmasks that represent whether a SIL instruction
4564- // / or debug variable has SILLocation, DebugScope, or both of them
4565- // / attached.
4566- struct SILSourceLocKind {
4567- static constexpr unsigned Loc = 0b01 ;
4568- static constexpr unsigned Scope = 0b10 ;
4569- };
4570-
45714627// / Define the start or update to a symbolic variable value (for loadable
45724628// / types).
45734629class DebugValueInst final
45744630 : public UnaryInstructionBase<SILInstructionKind::DebugValueInst,
45754631 NonValueInstruction>,
4632+ private SILDebugVariableSupplement,
45764633 private llvm::TrailingObjects<DebugValueInst, SILType, SILLocation,
45774634 const SILDebugScope *, SILDIExprElement,
45784635 char > {
45794636 friend TrailingObjects;
45804637 friend SILBuilder;
45814638
4582- unsigned NumDIExprOperands;
4583- bool HasAuxDebugVariableType;
4584- unsigned AuxVariableSourceLoc : 2 ;
4585-
45864639 TailAllocatedDebugVariable VarInfo;
45874640
45884641 DebugValueInst (SILDebugLocation DebugLoc, SILValue Operand,
@@ -4591,28 +4644,7 @@ class DebugValueInst final
45914644 SILModule &M, SILDebugVariable Var,
45924645 bool poisonRefs);
45934646
4594- inline bool hasAuxDebugLocation () const {
4595- return AuxVariableSourceLoc & SILSourceLocKind::Loc;
4596- }
4597- inline bool hasAuxDebugScope () const {
4598- return AuxVariableSourceLoc & SILSourceLocKind::Scope;
4599- }
4600-
4601- size_t numTrailingObjects (OverloadToken<SILType>) const {
4602- return HasAuxDebugVariableType ? 1 : 0 ;
4603- }
4604-
4605- size_t numTrailingObjects (OverloadToken<SILLocation>) const {
4606- return hasAuxDebugLocation () ? 1 : 0 ;
4607- }
4608-
4609- size_t numTrailingObjects (OverloadToken<const SILDebugScope *>) const {
4610- return hasAuxDebugScope () ? 1 : 0 ;
4611- }
4612-
4613- size_t numTrailingObjects (OverloadToken<SILDIExprElement>) const {
4614- return NumDIExprOperands;
4615- }
4647+ SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL ()
46164648
46174649 size_t numTrailingObjects (OverloadToken<char >) const { return 1 ; }
46184650
@@ -4622,7 +4654,6 @@ class DebugValueInst final
46224654 VarDecl *getDecl () const ;
46234655 // / Return the debug variable information attached to this instruction.
46244656 Optional<SILDebugVariable> getVarInfo () const {
4625- ;
46264657 Optional<SILType> AuxVarType;
46274658 Optional<SILLocation> VarDeclLoc;
46284659 const SILDebugScope *VarDeclScope = nullptr ;
@@ -4662,16 +4693,13 @@ class DebugValueInst final
46624693class DebugValueAddrInst final
46634694 : public UnaryInstructionBase<SILInstructionKind::DebugValueAddrInst,
46644695 NonValueInstruction>,
4696+ private SILDebugVariableSupplement,
46654697 private llvm::TrailingObjects<DebugValueAddrInst, SILType, SILLocation,
46664698 const SILDebugScope *, SILDIExprElement,
46674699 char > {
46684700 friend TrailingObjects;
46694701 friend SILBuilder;
46704702
4671- unsigned NumDIExprOperands;
4672- bool HasAuxDebugVariableType;
4673- unsigned AuxVariableSourceLoc : 2 ;
4674-
46754703 TailAllocatedDebugVariable VarInfo;
46764704
46774705 DebugValueAddrInst (SILDebugLocation DebugLoc, SILValue Operand,
@@ -4680,28 +4708,7 @@ class DebugValueAddrInst final
46804708 SILValue Operand, SILModule &M,
46814709 SILDebugVariable Var);
46824710
4683- inline bool hasAuxDebugLocation () const {
4684- return AuxVariableSourceLoc & SILSourceLocKind::Loc;
4685- }
4686- inline bool hasAuxDebugScope () const {
4687- return AuxVariableSourceLoc & SILSourceLocKind::Scope;
4688- }
4689-
4690- size_t numTrailingObjects (OverloadToken<SILType>) const {
4691- return HasAuxDebugVariableType ? 1 : 0 ;
4692- }
4693-
4694- size_t numTrailingObjects (OverloadToken<SILLocation>) const {
4695- return hasAuxDebugLocation () ? 1 : 0 ;
4696- }
4697-
4698- size_t numTrailingObjects (OverloadToken<const SILDebugScope *>) const {
4699- return hasAuxDebugScope () ? 1 : 0 ;
4700- }
4701-
4702- size_t numTrailingObjects (OverloadToken<SILDIExprElement>) const {
4703- return NumDIExprOperands;
4704- }
4711+ SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL ()
47054712
47064713public:
47074714 // / Return the underlying variable declaration that this denotes,
0 commit comments