@@ -4869,7 +4869,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
48694869 CGBuilderTy &Builder,
48704870 const bool UsePointerValue) {
48714871 if (CGM.getCodeGenOpts ().isHeterogeneousDwarfEnabled ())
4872- return EmitDef (VD, Storage, ArgNo, Builder, UsePointerValue);
4872+ return EmitDeclareForHeterogeneousDwarf (VD, Storage, ArgNo, Builder,
4873+ UsePointerValue);
48734874
48744875 assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
48754876 assert (!LexicalBlockStack.empty () && " Region stack mismatch, stack empty!" );
@@ -5051,11 +5052,9 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
50515052 return D;
50525053}
50535054
5054- llvm::DILocalVariable *CGDebugInfo::EmitDef (const BindingDecl *BD,
5055- llvm::Value *Storage,
5056- std::optional<unsigned > ArgNo,
5057- CGBuilderTy &Builder,
5058- const bool UsePointerValue) {
5055+ llvm::DILocalVariable *CGDebugInfo::EmitDeclareForHeterogeneousDwarf (
5056+ const BindingDecl *BD, llvm::Value *Storage, std::optional<unsigned > ArgNo,
5057+ CGBuilderTy &Builder, const bool UsePointerValue) {
50595058 assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
50605059 assert (!LexicalBlockStack.empty () && " Region stack mismatch, stack empty!" );
50615060 if (BD->hasAttr <NoDebugAttr>())
@@ -5077,10 +5076,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const BindingDecl *BD,
50775076 CGM.getTypes ().ConvertTypeForMem (BD->getDecomposedDecl ()->getType ());
50785077
50795078 llvm::DIExprBuilder ExprBuilder (CGM.getLLVMContext ());
5080- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5081- ExprBuilder.append <llvm::DIOp::Referrer>(Storage->getType ());
5082- else
5083- ExprBuilder.append <llvm::DIOp::Arg>(0u , Storage->getType ());
5079+ ExprBuilder.append <llvm::DIOp::Arg>(0u , Storage->getType ());
50845080 ExprBuilder.append <llvm::DIOp::Deref>(DecomposedTy);
50855081
50865082 if (UsePointerValue) {
@@ -5129,25 +5125,16 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const BindingDecl *BD,
51295125 }
51305126 }
51315127
5132- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5133- DBuilder.insertDef (
5134- DBuilder.createBoundedLifetime (D, ExprBuilder.intoExpr ()), Storage,
5135- llvm::DILocation::get (CGM.getLLVMContext (), Line, Column, Scope,
5136- CurInlinedAt),
5137- Builder.GetInsertBlock ());
5138- else
5139- DBuilder.insertDeclare (Storage, D, ExprBuilder.intoExpression (),
5140- llvm::DILocation::get (CGM.getLLVMContext (), Line,
5141- Column, Scope, CurInlinedAt),
5142- Builder.GetInsertBlock ());
5128+ DBuilder.insertDeclare (Storage, D, ExprBuilder.intoExpression (),
5129+ llvm::DILocation::get (CGM.getLLVMContext (), Line,
5130+ Column, Scope, CurInlinedAt),
5131+ Builder.GetInsertBlock ());
51435132 return D;
51445133}
51455134
5146- llvm::DILocalVariable *CGDebugInfo::EmitDef (const VarDecl *VD,
5147- llvm::Value *Storage,
5148- std::optional<unsigned > ArgNo,
5149- CGBuilderTy &Builder,
5150- const bool UsePointerValue) {
5135+ llvm::DILocalVariable *CGDebugInfo::EmitDeclareForHeterogeneousDwarf (
5136+ const VarDecl *VD, llvm::Value *Storage, std::optional<unsigned > ArgNo,
5137+ CGBuilderTy &Builder, const bool UsePointerValue) {
51515138 assert (CGM.getCodeGenOpts ().hasReducedDebugInfo () &&
51525139 " Call to EmitDef below ReducedDebugInfo" );
51535140 assert (CGM.getCodeGenOpts ().isHeterogeneousDwarfEnabled () &&
@@ -5203,10 +5190,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const VarDecl *VD,
52035190 CGM.getLLVMContext ());
52045191
52055192 llvm::DIExprBuilder ExprBuilder (CGM.getLLVMContext ());
5206- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5207- ExprBuilder.append <llvm::DIOp::Referrer>(Storage->getType ());
5208- else
5209- ExprBuilder.append <llvm::DIOp::Arg>(0u , Storage->getType ());
5193+ ExprBuilder.append <llvm::DIOp::Arg>(0u , Storage->getType ());
52105194 llvm::Type *ReferrerPointeeTy =
52115195 (!Name.empty () && VD->isEscapingByref ()) ? BlockPtrTy : VDMemTy;
52125196 if (UsePointerValue)
@@ -5249,12 +5233,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const VarDecl *VD,
52495233 const RecordDecl *RD = RT->getDecl ();
52505234 if (RD->isUnion () && RD->isAnonymousStructOrUnion ()) {
52515235 llvm::DIExprBuilder UnionExprBuilder{ExprBuilder};
5252- llvm::DIExpr *UnionDIExpr = nullptr ;
5253- llvm::DIExpression *UnionDIExpression = nullptr ;
5254- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5255- UnionDIExpr = UnionExprBuilder.intoExpr ();
5256- else
5257- UnionDIExpression = UnionExprBuilder.intoExpression ();
5236+ llvm::DIExpression *UnionDIExpression = UnionExprBuilder.intoExpression ();
52585237
52595238 // GDB has trouble finding local variables in anonymous unions, so we emit
52605239 // artificial local variables for each of the members.
@@ -5278,18 +5257,11 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const VarDecl *VD,
52785257 Flags | llvm::DINode::FlagArtificial, MS, FieldAlign);
52795258
52805259 // Insert an intrinsic into the current block.
5281- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5282- DBuilder.insertDef (DBuilder.createBoundedLifetime (D, UnionDIExpr),
5283- Storage,
5284- llvm::DILocation::get (CGM.getLLVMContext (), Line,
5285- Column, Scope, CurInlinedAt),
5286- Builder.GetInsertBlock ());
5287- else
5288- DBuilder.insertDeclare (Storage, D, UnionDIExpression,
5289- llvm::DILocation::get (CGM.getLLVMContext (),
5290- Line, Column, Scope,
5291- CurInlinedAt),
5292- Builder.GetInsertBlock ());
5260+ DBuilder.insertDeclare (Storage, D, UnionDIExpression,
5261+ llvm::DILocation::get (CGM.getLLVMContext (), Line,
5262+ Column, Scope,
5263+ CurInlinedAt),
5264+ Builder.GetInsertBlock ());
52935265 }
52945266 }
52955267 }
@@ -5349,17 +5321,10 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const VarDecl *VD,
53495321 Align);
53505322 }
53515323 // Insert an intrinsic into the current block.
5352- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
5353- DBuilder.insertDef (
5354- DBuilder.createBoundedLifetime (D, ExprBuilder.intoExpr ()), Storage,
5355- llvm::DILocation::get (CGM.getLLVMContext (), Line, Column, Scope,
5356- CurInlinedAt),
5357- Builder.GetInsertBlock ());
5358- else
5359- DBuilder.insertDeclare (Storage, D, ExprBuilder.intoExpression (),
5360- llvm::DILocation::get (CGM.getLLVMContext (), Line,
5361- Column, Scope, CurInlinedAt),
5362- Builder.GetInsertBlock ());
5324+ DBuilder.insertDeclare (Storage, D, ExprBuilder.intoExpression (),
5325+ llvm::DILocation::get (CGM.getLLVMContext (), Line,
5326+ Column, Scope, CurInlinedAt),
5327+ Builder.GetInsertBlock ());
53635328
53645329 llvm::Function *Parent = Builder.GetInsertBlock ()->getParent ();
53655330 assert (Parent->getSubprogram () && " expected DISubprogram" );
@@ -5374,7 +5339,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
53745339 const bool UsePointerValue) {
53755340
53765341 if (CGM.getCodeGenOpts ().isHeterogeneousDwarfEnabled ())
5377- return EmitDef (BD, Storage, ArgNo, Builder, UsePointerValue);
5342+ return EmitDeclareForHeterogeneousDwarf (BD, Storage, ArgNo, Builder,
5343+ UsePointerValue);
53785344
53795345 assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
53805346 assert (!LexicalBlockStack.empty () && " Region stack mismatch, stack empty!" );
@@ -5837,41 +5803,12 @@ llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
58375803 return GVE;
58385804}
58395805
5840- llvm::DIGlobalVariable *
5841- CGDebugInfo::CollectAnonRecordDeclsForHeterogeneousDwarfDIExpr (
5842- const RecordDecl *RD, llvm::DIFile *Unit, unsigned LineNo,
5843- StringRef LinkageName, llvm::dwarf::MemorySpace MS,
5844- llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
5845- assert (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ());
5846-
5847- llvm::DIGlobalVariable *GV = nullptr ;
5848-
5849- for (const auto *Field : RD->fields ()) {
5850- llvm::DIType *FieldTy = getOrCreateType (Field->getType (), Unit);
5851- StringRef FieldName = Field->getName ();
5852-
5853- // Ignore unnamed fields, but recurse into anonymous records.
5854- if (FieldName.empty ()) {
5855- if (const auto *RT = dyn_cast<RecordType>(Field->getType ()))
5856- GV = CollectAnonRecordDeclsForHeterogeneousDwarfDIExpr (
5857- RT->getDecl (), Unit, LineNo, LinkageName, MS, Var, DContext);
5858- continue ;
5859- }
5860- // Use VarDecl's Tag, Scope and Line number.
5861- GV = DBuilder.createGlobalVariable (DContext, FieldName, LinkageName, Unit,
5862- LineNo, FieldTy, Var->hasLocalLinkage (),
5863- MS);
5864- Var->addDebugInfo (GV);
5865- }
5866- return GV;
5867- }
5868-
58695806llvm::DIGlobalVariableExpression *
5870- CGDebugInfo::CollectAnonRecordDeclsForHeterogeneousDwarfDIExpression (
5807+ CGDebugInfo::CollectAnonRecordDeclsForHeterogeneousDwarf (
58715808 const RecordDecl *RD, llvm::DIFile *Unit, unsigned LineNo,
58725809 StringRef LinkageName, llvm::dwarf::MemorySpace MS,
58735810 llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
5874- assert (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpression ());
5811+ assert (CGM.getCodeGenOpts ().isHeterogeneousDwarfEnabled ());
58755812
58765813 llvm::DIGlobalVariableExpression *GVE = nullptr ;
58775814
@@ -5882,7 +5819,7 @@ CGDebugInfo::CollectAnonRecordDeclsForHeterogeneousDwarfDIExpression(
58825819 // Ignore unnamed fields, but recurse into anonymous records.
58835820 if (FieldName.empty ()) {
58845821 if (const auto *RT = dyn_cast<RecordType>(Field->getType ()))
5885- GVE = CollectAnonRecordDeclsForHeterogeneousDwarfDIExpression (
5822+ GVE = CollectAnonRecordDeclsForHeterogeneousDwarf (
58865823 RT->getDecl (), Unit, LineNo, LinkageName, MS, Var, DContext);
58875824 continue ;
58885825 }
@@ -6239,7 +6176,6 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
62396176
62406177 // Attempt to store one global variable for the declaration - even if we
62416178 // emit a lot of fields.
6242- llvm::DIGlobalVariable *DGV = nullptr ;
62436179 llvm::DIGlobalVariableExpression *GVE = nullptr ;
62446180
62456181 // If this is an anonymous union then we'll want to emit a global
@@ -6251,12 +6187,8 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
62516187 assert (RD->isAnonymousStructOrUnion () &&
62526188 " unnamed non-anonymous struct or union?" );
62536189 // FIXME(KZHURAVL): No tests for this path.
6254- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
6255- DGV = CollectAnonRecordDeclsForHeterogeneousDwarfDIExpr (
6256- RD, Unit, LineNo, LinkageName, MS, Var, DContext);
6257- else
6258- GVE = CollectAnonRecordDeclsForHeterogeneousDwarfDIExpression (
6259- RD, Unit, LineNo, LinkageName, MS, Var, DContext);
6190+ GVE = CollectAnonRecordDeclsForHeterogeneousDwarf (
6191+ RD, Unit, LineNo, LinkageName, MS, Var, DContext);
62606192 } else {
62616193 auto Align = getDeclAlignIfRequired (D, CGM.getContext ());
62626194
@@ -6267,38 +6199,14 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
62676199
62686200 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations (D);
62696201
6270- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ()) {
6271- DGV = DBuilder.createGlobalVariable (
6272- DContext, DeclName, LinkageName, Unit, LineNo,
6273- getOrCreateType (T, Unit), Var->hasLocalLinkage (), true ,
6274- getOrCreateStaticDataMemberDeclarationOrNull (D), TemplateParameters,
6275- MS, getDeclAlignIfRequired (D, CGM.getContext ()));
6276-
6277- // Create DIFragment.
6278- llvm::DIFragment *Fragment = DBuilder.createFragment ();
6279- SmallVector<llvm::Metadata *> LifetimeArgs;
6280- LifetimeArgs.push_back (Fragment);
6281-
6282- // Create DILifetime and add to llvm.dbg.retainedNodes named metadata.
6283- DBuilder.createComputedLifetime (DGV, ExprBuilder.intoExpr (),
6284- LifetimeArgs);
6285-
6286- Var->setDbgDef (Fragment);
6287-
6288- } else {
6289- GVE = DBuilder.createGlobalVariableExpression (
6290- DContext, DeclName, LinkageName, Unit, LineNo,
6291- getOrCreateType (T, Unit), Var->hasLocalLinkage (), true ,
6292- ExprBuilder.intoExpression (),
6293- getOrCreateStaticDataMemberDeclarationOrNull (D), TemplateParameters,
6294- MS, Align, Annotations);
6295- Var->addDebugInfo (GVE);
6296- }
6202+ GVE = DBuilder.createGlobalVariableExpression (
6203+ DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType (T, Unit),
6204+ Var->hasLocalLinkage (), true , ExprBuilder.intoExpression (),
6205+ getOrCreateStaticDataMemberDeclarationOrNull (D), TemplateParameters, MS,
6206+ Align, Annotations);
6207+ Var->addDebugInfo (GVE);
62976208 }
6298- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ())
6299- GV.reset (DGV);
6300- else
6301- DeclCache[D->getCanonicalDecl ()].reset (GVE);
6209+ DeclCache[D->getCanonicalDecl ()].reset (GVE);
63026210}
63036211
63046212void CGDebugInfo::EmitGlobalVariable (const ValueDecl *VD, const APValue &Init) {
@@ -6462,22 +6370,11 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
64626370 ExprBuilder.append <llvm::DIOp::Constant>(
64636371 llvm::ConstantFP::get (CGM.getLLVMContext (), Init.getFloat ()));
64646372
6465- if (CGM.getCodeGenOpts ().isHeterogeneousDwarfDIExpr ()) {
6466- llvm::DIGlobalVariable *DGV = DBuilder.createGlobalVariable (
6467- DContext, Name, StringRef (), Unit, getLineNumber (VD->getLocation ()), Ty,
6468- true , true , getOrCreateStaticDataMemberDeclarationOrNull (VarD),
6469- TemplateParameters, MS, Align);
6470-
6471- DBuilder.createComputedLifetime (DGV, ExprBuilder.intoExpr (), {});
6472-
6473- GV.reset (DGV);
6474- } else {
6475- GV.reset (DBuilder.createGlobalVariableExpression (
6476- DContext, Name, StringRef (), Unit, getLineNumber (VD->getLocation ()), Ty,
6477- true , true , ExprBuilder.intoExpression (),
6478- getOrCreateStaticDataMemberDeclarationOrNull (VarD), TemplateParameters,
6479- MS, Align));
6480- }
6373+ GV.reset (DBuilder.createGlobalVariableExpression (
6374+ DContext, Name, StringRef (), Unit, getLineNumber (VD->getLocation ()), Ty,
6375+ true , true , ExprBuilder.intoExpression (),
6376+ getOrCreateStaticDataMemberDeclarationOrNull (VarD), TemplateParameters,
6377+ MS, Align));
64816378}
64826379
64836380void CGDebugInfo::EmitExternalVariable (llvm::GlobalVariable *Var,
0 commit comments