@@ -52,23 +52,11 @@ void DIBuilder::trackIfUnresolved(MDNode *N) {
52
52
}
53
53
54
54
void DIBuilder::finalizeSubprogram (DISubprogram *SP) {
55
- MDTuple *Temp = SP->getRetainedNodes ().get ();
56
- if (!Temp || !Temp->isTemporary ())
57
- return ;
58
-
59
- SmallVector<Metadata *, 16 > RetainedNodes;
60
-
61
- auto PV = PreservedVariables.find (SP);
62
- if (PV != PreservedVariables.end ())
63
- RetainedNodes.append (PV->second .begin (), PV->second .end ());
64
-
65
- auto PL = PreservedLabels.find (SP);
66
- if (PL != PreservedLabels.end ())
67
- RetainedNodes.append (PL->second .begin (), PL->second .end ());
68
-
69
- DINodeArray Node = getOrCreateArray (RetainedNodes);
70
-
71
- TempMDTuple (Temp)->replaceAllUsesWith (Node.get ());
55
+ auto PN = SubprogramTrackedNodes.find (SP);
56
+ if (PN != SubprogramTrackedNodes.end ())
57
+ SP->replaceRetainedNodes (
58
+ MDTuple::get (VMContext, SmallVector<Metadata *, 16 >(PN->second .begin (),
59
+ PN->second .end ())));
72
60
}
73
61
74
62
void DIBuilder::finalize () {
@@ -766,26 +754,20 @@ DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
766
754
767
755
static DILocalVariable *createLocalVariable (
768
756
LLVMContext &VMContext,
769
- DenseMap<MDNode *, SmallVector< TrackingMDNodeRef, 1 >> &PreservedVariables ,
770
- DIScope *Scope , StringRef Name, unsigned ArgNo, DIFile *File,
757
+ SmallVectorImpl< TrackingMDNodeRef> &PreservedNodes ,
758
+ DIScope *Context , StringRef Name, unsigned ArgNo, DIFile *File,
771
759
unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
772
760
uint32_t AlignInBits, DINodeArray Annotations = nullptr ) {
773
- // FIXME: Why getNonCompileUnitScope()?
774
- // FIXME: Why is "!Context" okay here?
775
761
// FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
776
762
// the only valid scopes)?
777
- DIScope *Context = getNonCompileUnitScope (Scope);
778
-
779
- auto *Node = DILocalVariable::get (
780
- VMContext, cast_or_null<DILocalScope>(Context), Name, File, LineNo, Ty,
781
- ArgNo, Flags, AlignInBits, Annotations);
763
+ auto *Scope = cast<DILocalScope>(Context);
764
+ auto *Node = DILocalVariable::get (VMContext, Scope, Name, File, LineNo, Ty,
765
+ ArgNo, Flags, AlignInBits, Annotations);
782
766
if (AlwaysPreserve) {
783
767
// The optimizer may remove local variables. If there is an interest
784
768
// to preserve variable info in such situation then stash it in a
785
769
// named mdnode.
786
- DISubprogram *Fn = getDISubprogram (Scope);
787
- assert (Fn && " Missing subprogram for local variable" );
788
- PreservedVariables[Fn].emplace_back (Node);
770
+ PreservedNodes.emplace_back (Node);
789
771
}
790
772
return Node;
791
773
}
@@ -795,35 +777,35 @@ DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name,
795
777
DIType *Ty, bool AlwaysPreserve,
796
778
DINode::DIFlags Flags,
797
779
uint32_t AlignInBits) {
798
- return createLocalVariable (VMContext, PreservedVariables, Scope, Name,
799
- /* ArgNo */ 0 , File, LineNo, Ty, AlwaysPreserve,
800
- Flags, AlignInBits);
780
+ assert (Scope && isa<DILocalScope>(Scope) &&
781
+ " Unexpected scope for a local variable." );
782
+ return createLocalVariable (
783
+ VMContext, getSubprogramNodesTrackingVector (Scope), Scope, Name,
784
+ /* ArgNo */ 0 , File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);
801
785
}
802
786
803
787
DILocalVariable *DIBuilder::createParameterVariable (
804
788
DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
805
789
unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
806
790
DINodeArray Annotations) {
807
791
assert (ArgNo && " Expected non-zero argument number for parameter" );
808
- return createLocalVariable (VMContext, PreservedVariables, Scope, Name, ArgNo,
809
- File, LineNo, Ty, AlwaysPreserve, Flags,
810
- /* AlignInBits=*/ 0 , Annotations);
792
+ assert (Scope && isa<DILocalScope>(Scope) &&
793
+ " Unexpected scope for a local variable." );
794
+ return createLocalVariable (
795
+ VMContext, getSubprogramNodesTrackingVector (Scope), Scope, Name, ArgNo,
796
+ File, LineNo, Ty, AlwaysPreserve, Flags, /* AlignInBits=*/ 0 , Annotations);
811
797
}
812
798
813
- DILabel *DIBuilder::createLabel (DIScope *Scope, StringRef Name, DIFile *File,
814
- unsigned LineNo, bool AlwaysPreserve) {
815
- DIScope *Context = getNonCompileUnitScope (Scope);
816
-
817
- auto *Node = DILabel::get (VMContext, cast_or_null<DILocalScope>(Context),
818
- Name, File, LineNo);
799
+ DILabel *DIBuilder::createLabel (DIScope *Context, StringRef Name, DIFile *File,
800
+ unsigned LineNo, bool AlwaysPreserve) {
801
+ auto *Scope = cast<DILocalScope>(Context);
802
+ auto *Node = DILabel::get (VMContext, Scope, Name, File, LineNo);
819
803
820
804
if (AlwaysPreserve) {
821
805
// / The optimizer may remove labels. If there is an interest
822
806
// / to preserve label info in such situation then append it to
823
807
// / the list of retained nodes of the DISubprogram.
824
- DISubprogram *Fn = getDISubprogram (Scope);
825
- assert (Fn && " Missing subprogram for label" );
826
- PreservedLabels[Fn].emplace_back (Node);
808
+ getSubprogramNodesTrackingVector (Scope).emplace_back (Node);
827
809
}
828
810
return Node;
829
811
}
@@ -850,9 +832,8 @@ DISubprogram *DIBuilder::createFunction(
850
832
auto *Node = getSubprogram (
851
833
/* IsDistinct=*/ IsDefinition, VMContext, getNonCompileUnitScope (Context),
852
834
Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr , 0 , 0 , Flags,
853
- SPFlags, IsDefinition ? CUNode : nullptr , TParams, Decl,
854
- MDTuple::getTemporary (VMContext, std::nullopt).release (), ThrownTypes,
855
- Annotations, TargetFuncName);
835
+ SPFlags, IsDefinition ? CUNode : nullptr , TParams, Decl, nullptr ,
836
+ ThrownTypes, Annotations, TargetFuncName);
856
837
857
838
if (IsDefinition)
858
839
AllSubprograms.push_back (Node);
0 commit comments