@@ -4875,7 +4875,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
48754875 CGBuilderTy &Builder,
48764876 const bool UsePointerValue) {
48774877 if (CGM.getCodeGenOpts ().isHeterogeneousDwarfEnabled ())
4878- return EmitDef (VD, Storage, ArgNo, Builder, UsePointerValue);
4878+ return EmitDeclareForHeterogeneousDwarf (VD, Storage, ArgNo, Builder,
4879+ UsePointerValue);
48794880
48804881 assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
48814882 assert (!LexicalBlockStack.empty () && " Region stack mismatch, stack empty!" );
@@ -5057,11 +5058,9 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
50575058 return D;
50585059}
50595060
5060- llvm::DILocalVariable *CGDebugInfo::EmitDef (const BindingDecl *BD,
5061- llvm::Value *Storage,
5062- std::optional<unsigned > ArgNo,
5063- CGBuilderTy &Builder,
5064- const bool UsePointerValue) {
5061+ llvm::DILocalVariable *CGDebugInfo::EmitDeclareForHeterogeneousDwarf (
5062+ const BindingDecl *BD, llvm::Value *Storage, std::optional<unsigned > ArgNo,
5063+ CGBuilderTy &Builder, const bool UsePointerValue) {
50655064 assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
50665065 assert (!LexicalBlockStack.empty () && " Region stack mismatch, stack empty!" );
50675066 if (BD->hasAttr <NoDebugAttr>())
@@ -5083,10 +5082,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const BindingDecl *BD,
50835082 CGM.getTypes ().ConvertTypeForMem (BD->getDecomposedDecl ()->getType ());
50845083
50855084 llvm::DIExprBuilder ExprBuilder (CGM.getLLVMContext ());
5086- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5087- ExprBuilder.append <llvm::DIOp::Referrer>(Storage->getType ());
5088- else
5089- ExprBuilder.append <llvm::DIOp::Arg>(0u , Storage->getType ());
5085+ ExprBuilder.append <llvm::DIOp::Arg>(0u , Storage->getType ());
50905086 ExprBuilder.append <llvm::DIOp::Deref>(DecomposedTy);
50915087
50925088 if (UsePointerValue) {
@@ -5135,25 +5131,16 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const BindingDecl *BD,
51355131 }
51365132 }
51375133
5138- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5139- DBuilder.insertDef (
5140- DBuilder.createBoundedLifetime (D, ExprBuilder.intoExpr ()), Storage,
5141- llvm::DILocation::get (CGM.getLLVMContext (), Line, Column, Scope,
5142- CurInlinedAt),
5143- Builder.GetInsertBlock ());
5144- else
5145- DBuilder.insertDeclare (Storage, D, ExprBuilder.intoExpression (),
5146- llvm::DILocation::get (CGM.getLLVMContext (), Line,
5147- Column, Scope, CurInlinedAt),
5148- Builder.GetInsertBlock ());
5134+ DBuilder.insertDeclare (Storage, D, ExprBuilder.intoExpression (),
5135+ llvm::DILocation::get (CGM.getLLVMContext (), Line,
5136+ Column, Scope, CurInlinedAt),
5137+ Builder.GetInsertBlock ());
51495138 return D;
51505139}
51515140
5152- llvm::DILocalVariable *CGDebugInfo::EmitDef (const VarDecl *VD,
5153- llvm::Value *Storage,
5154- std::optional<unsigned > ArgNo,
5155- CGBuilderTy &Builder,
5156- const bool UsePointerValue) {
5141+ llvm::DILocalVariable *CGDebugInfo::EmitDeclareForHeterogeneousDwarf (
5142+ const VarDecl *VD, llvm::Value *Storage, std::optional<unsigned > ArgNo,
5143+ CGBuilderTy &Builder, const bool UsePointerValue) {
51575144 assert (CGM.getCodeGenOpts ().hasReducedDebugInfo () &&
51585145 " Call to EmitDef below ReducedDebugInfo" );
51595146 assert (CGM.getCodeGenOpts ().isHeterogeneousDwarfEnabled () &&
@@ -5209,10 +5196,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const VarDecl *VD,
52095196 CGM.getLLVMContext ());
52105197
52115198 llvm::DIExprBuilder ExprBuilder (CGM.getLLVMContext ());
5212- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5213- ExprBuilder.append <llvm::DIOp::Referrer>(Storage->getType ());
5214- else
5215- ExprBuilder.append <llvm::DIOp::Arg>(0u , Storage->getType ());
5199+ ExprBuilder.append <llvm::DIOp::Arg>(0u , Storage->getType ());
52165200 llvm::Type *ReferrerPointeeTy =
52175201 (!Name.empty () && VD->isEscapingByref ()) ? BlockPtrTy : VDMemTy;
52185202 if (UsePointerValue)
@@ -5255,12 +5239,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const VarDecl *VD,
52555239 const RecordDecl *RD = RT->getDecl ();
52565240 if (RD->isUnion () && RD->isAnonymousStructOrUnion ()) {
52575241 llvm::DIExprBuilder UnionExprBuilder{ExprBuilder};
5258- llvm::DIExpr *UnionDIExpr = nullptr ;
5259- llvm::DIExpression *UnionDIExpression = nullptr ;
5260- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5261- UnionDIExpr = UnionExprBuilder.intoExpr ();
5262- else
5263- UnionDIExpression = UnionExprBuilder.intoExpression ();
5242+ llvm::DIExpression *UnionDIExpression = UnionExprBuilder.intoExpression ();
52645243
52655244 // GDB has trouble finding local variables in anonymous unions, so we emit
52665245 // artificial local variables for each of the members.
@@ -5284,18 +5263,11 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const VarDecl *VD,
52845263 Flags | llvm::DINode::FlagArtificial, MS, FieldAlign);
52855264
52865265 // Insert an intrinsic into the current block.
5287- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5288- DBuilder.insertDef (DBuilder.createBoundedLifetime (D, UnionDIExpr),
5289- Storage,
5290- llvm::DILocation::get (CGM.getLLVMContext (), Line,
5291- Column, Scope, CurInlinedAt),
5292- Builder.GetInsertBlock ());
5293- else
5294- DBuilder.insertDeclare (Storage, D, UnionDIExpression,
5295- llvm::DILocation::get (CGM.getLLVMContext (),
5296- Line, Column, Scope,
5297- CurInlinedAt),
5298- Builder.GetInsertBlock ());
5266+ DBuilder.insertDeclare (Storage, D, UnionDIExpression,
5267+ llvm::DILocation::get (CGM.getLLVMContext (), Line,
5268+ Column, Scope,
5269+ CurInlinedAt),
5270+ Builder.GetInsertBlock ());
52995271 }
53005272 }
53015273 }
@@ -5355,17 +5327,10 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const VarDecl *VD,
53555327 Align);
53565328 }
53575329 // Insert an intrinsic into the current block.
5358- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5359- DBuilder.insertDef (
5360- DBuilder.createBoundedLifetime (D, ExprBuilder.intoExpr ()), Storage,
5361- llvm::DILocation::get (CGM.getLLVMContext (), Line, Column, Scope,
5362- CurInlinedAt),
5363- Builder.GetInsertBlock ());
5364- else
5365- DBuilder.insertDeclare (Storage, D, ExprBuilder.intoExpression (),
5366- llvm::DILocation::get (CGM.getLLVMContext (), Line,
5367- Column, Scope, CurInlinedAt),
5368- Builder.GetInsertBlock ());
5330+ DBuilder.insertDeclare (Storage, D, ExprBuilder.intoExpression (),
5331+ llvm::DILocation::get (CGM.getLLVMContext (), Line,
5332+ Column, Scope, CurInlinedAt),
5333+ Builder.GetInsertBlock ());
53695334
53705335 llvm::Function *Parent = Builder.GetInsertBlock ()->getParent ();
53715336 assert (Parent->getSubprogram () && " expected DISubprogram" );
@@ -5380,7 +5345,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
53805345 const bool UsePointerValue) {
53815346
53825347 if (CGM.getCodeGenOpts ().isHeterogeneousDwarfEnabled ())
5383- return EmitDef (BD, Storage, ArgNo, Builder, UsePointerValue);
5348+ return EmitDeclareForHeterogeneousDwarf (BD, Storage, ArgNo, Builder,
5349+ UsePointerValue);
53845350
53855351 assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
53865352 assert (!LexicalBlockStack.empty () && " Region stack mismatch, stack empty!" );
@@ -5843,41 +5809,12 @@ llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
58435809 return GVE;
58445810}
58455811
5846- llvm::DIGlobalVariable *
5847- CGDebugInfo::CollectAnonRecordDeclsForHeterogeneousDwarfDIExpr (
5848- const RecordDecl *RD, llvm::DIFile *Unit, unsigned LineNo,
5849- StringRef LinkageName, llvm::dwarf::MemorySpace MS,
5850- llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
5851- assert (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ());
5852-
5853- llvm::DIGlobalVariable *GV = nullptr ;
5854-
5855- for (const auto *Field : RD->fields ()) {
5856- llvm::DIType *FieldTy = getOrCreateType (Field->getType (), Unit);
5857- StringRef FieldName = Field->getName ();
5858-
5859- // Ignore unnamed fields, but recurse into anonymous records.
5860- if (FieldName.empty ()) {
5861- if (const auto *RT = dyn_cast<RecordType>(Field->getType ()))
5862- GV = CollectAnonRecordDeclsForHeterogeneousDwarfDIExpr (
5863- RT->getDecl (), Unit, LineNo, LinkageName, MS, Var, DContext);
5864- continue ;
5865- }
5866- // Use VarDecl's Tag, Scope and Line number.
5867- GV = DBuilder.createGlobalVariable (DContext, FieldName, LinkageName, Unit,
5868- LineNo, FieldTy, Var->hasLocalLinkage (),
5869- MS);
5870- Var->addDebugInfo (GV);
5871- }
5872- return GV;
5873- }
5874-
58755812llvm::DIGlobalVariableExpression *
5876- CGDebugInfo::CollectAnonRecordDeclsForHeterogeneousDwarfDIExpression (
5813+ CGDebugInfo::CollectAnonRecordDeclsForHeterogeneousDwarf (
58775814 const RecordDecl *RD, llvm::DIFile *Unit, unsigned LineNo,
58785815 StringRef LinkageName, llvm::dwarf::MemorySpace MS,
58795816 llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
5880- assert (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpression ());
5817+ assert (CGM.getCodeGenOpts ().isHeterogeneousDwarfEnabled ());
58815818
58825819 llvm::DIGlobalVariableExpression *GVE = nullptr ;
58835820
@@ -5888,7 +5825,7 @@ CGDebugInfo::CollectAnonRecordDeclsForHeterogeneousDwarfDIExpression(
58885825 // Ignore unnamed fields, but recurse into anonymous records.
58895826 if (FieldName.empty ()) {
58905827 if (const auto *RT = dyn_cast<RecordType>(Field->getType ()))
5891- GVE = CollectAnonRecordDeclsForHeterogeneousDwarfDIExpression (
5828+ GVE = CollectAnonRecordDeclsForHeterogeneousDwarf (
58925829 RT->getDecl (), Unit, LineNo, LinkageName, MS, Var, DContext);
58935830 continue ;
58945831 }
@@ -6245,7 +6182,6 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
62456182
62466183 // Attempt to store one global variable for the declaration - even if we
62476184 // emit a lot of fields.
6248- llvm::DIGlobalVariable *DGV = nullptr ;
62496185 llvm::DIGlobalVariableExpression *GVE = nullptr ;
62506186
62516187 // If this is an anonymous union then we'll want to emit a global
@@ -6257,12 +6193,8 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
62576193 assert (RD->isAnonymousStructOrUnion () &&
62586194 " unnamed non-anonymous struct or union?" );
62596195 // FIXME(KZHURAVL): No tests for this path.
6260- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
6261- DGV = CollectAnonRecordDeclsForHeterogeneousDwarfDIExpr (
6262- RD, Unit, LineNo, LinkageName, MS, Var, DContext);
6263- else
6264- GVE = CollectAnonRecordDeclsForHeterogeneousDwarfDIExpression (
6265- RD, Unit, LineNo, LinkageName, MS, Var, DContext);
6196+ GVE = CollectAnonRecordDeclsForHeterogeneousDwarf (
6197+ RD, Unit, LineNo, LinkageName, MS, Var, DContext);
62666198 } else {
62676199 auto Align = getDeclAlignIfRequired (D, CGM.getContext ());
62686200
@@ -6273,38 +6205,14 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
62736205
62746206 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations (D);
62756207
6276- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ()) {
6277- DGV = DBuilder.createGlobalVariable (
6278- DContext, DeclName, LinkageName, Unit, LineNo,
6279- getOrCreateType (T, Unit), Var->hasLocalLinkage (), true ,
6280- getOrCreateStaticDataMemberDeclarationOrNull (D), TemplateParameters,
6281- MS, getDeclAlignIfRequired (D, CGM.getContext ()));
6282-
6283- // Create DIFragment.
6284- llvm::DIFragment *Fragment = DBuilder.createFragment ();
6285- SmallVector<llvm::Metadata *> LifetimeArgs;
6286- LifetimeArgs.push_back (Fragment);
6287-
6288- // Create DILifetime and add to llvm.dbg.retainedNodes named metadata.
6289- DBuilder.createComputedLifetime (DGV, ExprBuilder.intoExpr (),
6290- LifetimeArgs);
6291-
6292- Var->setDbgDef (Fragment);
6293-
6294- } else {
6295- GVE = DBuilder.createGlobalVariableExpression (
6296- DContext, DeclName, LinkageName, Unit, LineNo,
6297- getOrCreateType (T, Unit), Var->hasLocalLinkage (), true ,
6298- ExprBuilder.intoExpression (),
6299- getOrCreateStaticDataMemberDeclarationOrNull (D), TemplateParameters,
6300- MS, Align, Annotations);
6301- Var->addDebugInfo (GVE);
6302- }
6208+ GVE = DBuilder.createGlobalVariableExpression (
6209+ DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType (T, Unit),
6210+ Var->hasLocalLinkage (), true , ExprBuilder.intoExpression (),
6211+ getOrCreateStaticDataMemberDeclarationOrNull (D), TemplateParameters, MS,
6212+ Align, Annotations);
6213+ Var->addDebugInfo (GVE);
63036214 }
6304- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
6305- GV.reset (DGV);
6306- else
6307- DeclCache[D->getCanonicalDecl ()].reset (GVE);
6215+ DeclCache[D->getCanonicalDecl ()].reset (GVE);
63086216}
63096217
63106218void CGDebugInfo::EmitGlobalVariable (const ValueDecl *VD, const APValue &Init) {
@@ -6468,22 +6376,11 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
64686376 ExprBuilder.append <llvm::DIOp::Constant>(
64696377 llvm::ConstantFP::get (CGM.getLLVMContext (), Init.getFloat ()));
64706378
6471- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ()) {
6472- llvm::DIGlobalVariable *DGV = DBuilder.createGlobalVariable (
6473- DContext, Name, StringRef (), Unit, getLineNumber (VD->getLocation ()), Ty,
6474- true , true , getOrCreateStaticDataMemberDeclarationOrNull (VarD),
6475- TemplateParameters, MS, Align);
6476-
6477- DBuilder.createComputedLifetime (DGV, ExprBuilder.intoExpr (), {});
6478-
6479- GV.reset (DGV);
6480- } else {
6481- GV.reset (DBuilder.createGlobalVariableExpression (
6482- DContext, Name, StringRef (), Unit, getLineNumber (VD->getLocation ()), Ty,
6483- true , true , ExprBuilder.intoExpression (),
6484- getOrCreateStaticDataMemberDeclarationOrNull (VarD), TemplateParameters,
6485- MS, Align));
6486- }
6379+ GV.reset (DBuilder.createGlobalVariableExpression (
6380+ DContext, Name, StringRef (), Unit, getLineNumber (VD->getLocation ()), Ty,
6381+ true , true , ExprBuilder.intoExpression (),
6382+ getOrCreateStaticDataMemberDeclarationOrNull (VarD), TemplateParameters,
6383+ MS, Align));
64876384}
64886385
64896386void CGDebugInfo::EmitExternalVariable (llvm::GlobalVariable *Var,
0 commit comments