@@ -563,14 +563,13 @@ DIE *DwarfDebug::createScopeChildrenDIE(DwarfCompileUnit *TheCU,
563
563
564
564
// Collect arguments for current function.
565
565
if (LScopes.isCurrentFunctionScope (Scope)) {
566
- for (DbgVariable *ArgDV : CurrentFnArguments)
567
- if (ArgDV)
568
- if (DIE *Arg =
569
- TheCU->constructVariableDIE (*ArgDV, Scope->isAbstractScope ())) {
570
- Children.push_back (Arg);
571
- if (ArgDV->isObjectPointer ())
572
- ObjectPointer = Arg;
573
- }
566
+ for (DbgVariable &ArgDV : CurrentFnArguments)
567
+ if (ArgDV.getVariable ()) {
568
+ DIE *Arg = TheCU->constructVariableDIE (ArgDV, Scope->isAbstractScope ());
569
+ Children.push_back (Arg);
570
+ if (ArgDV.isObjectPointer ())
571
+ ObjectPointer = Arg;
572
+ }
574
573
575
574
// If this is a variadic function, add an unspecified parameter.
576
575
DISubprogram SP (Scope->getScopeNode ());
@@ -583,11 +582,11 @@ DIE *DwarfDebug::createScopeChildrenDIE(DwarfCompileUnit *TheCU,
583
582
}
584
583
585
584
// Collect lexical scope children first.
586
- for (DbgVariable * DV : ScopeVariables.lookup (Scope))
587
- if (DIE *Variable = TheCU->constructVariableDIE (* DV,
585
+ for (DbgVariable & DV : ScopeVariables.lookup (Scope))
586
+ if (DIE *Variable = TheCU->constructVariableDIE (DV,
588
587
Scope->isAbstractScope ())) {
589
588
Children.push_back (Variable);
590
- if (DV-> isObjectPointer ())
589
+ if (DV. isObjectPointer ())
591
590
ObjectPointer = Variable;
592
591
}
593
592
for (LexicalScope *LS : Scope->getChildren ())
@@ -1120,32 +1119,33 @@ DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV,
1120
1119
if (!Scope)
1121
1120
return NULL ;
1122
1121
1123
- AbsDbgVariable = new DbgVariable (Var, NULL , this );
1124
- addScopeVariable (Scope, AbsDbgVariable);
1122
+ AbsDbgVariable = &addScopeVariable (Scope, DbgVariable (Var, NULL , this ));
1125
1123
AbstractVariables[Var] = AbsDbgVariable;
1126
1124
return AbsDbgVariable;
1127
1125
}
1128
1126
1129
1127
// If Var is a current function argument then add it to CurrentFnArguments list.
1130
- bool DwarfDebug::addCurrentFnArgument (DbgVariable * Var, LexicalScope *Scope) {
1128
+ DbgVariable * DwarfDebug::addCurrentFnArgument (DbgVariable & Var, LexicalScope *Scope) {
1131
1129
if (!LScopes.isCurrentFunctionScope (Scope))
1132
- return false ;
1133
- DIVariable DV = Var-> getVariable ();
1130
+ return nullptr ;
1131
+ DIVariable DV = Var. getVariable ();
1134
1132
if (DV.getTag () != dwarf::DW_TAG_arg_variable)
1135
- return false ;
1133
+ return nullptr ;
1136
1134
unsigned ArgNo = DV.getArgNumber ();
1137
1135
if (ArgNo == 0 )
1138
- return false ;
1136
+ return nullptr ;
1139
1137
1140
- size_t Size = CurrentFnArguments.size ();
1141
- if (Size == 0 )
1142
- CurrentFnArguments.resize (CurFn->getFunction ()->arg_size ());
1143
- // llvm::Function argument size is not good indicator of how many
1144
- // arguments does the function have at source level.
1145
- if (ArgNo > Size)
1146
- CurrentFnArguments.resize (ArgNo * 2 );
1147
- CurrentFnArguments[ArgNo - 1 ] = Var;
1148
- return true ;
1138
+ auto I = CurrentFnArguments.begin ();
1139
+ for (; I != CurrentFnArguments.end (); ++I)
1140
+ if (ArgNo < I->getVariable ().getArgNumber ())
1141
+ break ;
1142
+ return &*CurrentFnArguments.insert (I, std::move (Var));
1143
+ }
1144
+
1145
+ DbgVariable &DwarfDebug::addVariable (DbgVariable Var, LexicalScope *Scope) {
1146
+ if (DbgVariable *Res = addCurrentFnArgument (Var, Scope))
1147
+ return *Res;
1148
+ return addScopeVariable (Scope, std::move (Var));
1149
1149
}
1150
1150
1151
1151
// Collect variable information from side table maintained by MMI.
@@ -1163,10 +1163,9 @@ void DwarfDebug::collectVariableInfoFromMMITable(
1163
1163
continue ;
1164
1164
1165
1165
DbgVariable *AbsDbgVariable = findAbstractVariable (DV, VI.Loc );
1166
- DbgVariable *RegVar = new DbgVariable (DV, AbsDbgVariable, this );
1167
- RegVar->setFrameIndex (VI.Slot );
1168
- if (!addCurrentFnArgument (RegVar, Scope))
1169
- addScopeVariable (Scope, RegVar);
1166
+ DbgVariable RegVar (DV, AbsDbgVariable, this );
1167
+ RegVar.setFrameIndex (VI.Slot );
1168
+ addVariable (std::move (RegVar), Scope);
1170
1169
if (AbsDbgVariable)
1171
1170
AbsDbgVariable->setFrameIndex (VI.Slot );
1172
1171
}
@@ -1247,21 +1246,19 @@ DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {
1247
1246
Processed.insert (DV);
1248
1247
assert (MInsn->isDebugValue () && " History must begin with debug value" );
1249
1248
DbgVariable *AbsVar = findAbstractVariable (DV, MInsn->getDebugLoc ());
1250
- DbgVariable *RegVar = new DbgVariable (DV, AbsVar, this );
1251
- if (!addCurrentFnArgument (RegVar, Scope))
1252
- addScopeVariable (Scope, RegVar);
1249
+ DbgVariable &RegVar = addVariable (DbgVariable (DV, AbsVar, this ), Scope);
1253
1250
if (AbsVar)
1254
1251
AbsVar->setMInsn (MInsn);
1255
1252
1256
1253
// Simplify ranges that are fully coalesced.
1257
1254
if (History.size () <= 1 ||
1258
1255
(History.size () == 2 && MInsn->isIdenticalTo (History.back ()))) {
1259
- RegVar-> setMInsn (MInsn);
1256
+ RegVar. setMInsn (MInsn);
1260
1257
continue ;
1261
1258
}
1262
1259
1263
1260
// Handle multiple DBG_VALUE instructions describing one variable.
1264
- RegVar-> setDotDebugLocOffset (DotDebugLocEntries.size ());
1261
+ RegVar. setDotDebugLocOffset (DotDebugLocEntries.size ());
1265
1262
1266
1263
DotDebugLocEntries.resize (DotDebugLocEntries.size () + 1 );
1267
1264
DebugLocList &LocList = DotDebugLocEntries.back ();
@@ -1319,7 +1316,7 @@ DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {
1319
1316
if (!DV || !DV.isVariable () || !Processed.insert (DV))
1320
1317
continue ;
1321
1318
if (LexicalScope *Scope = LScopes.findLexicalScope (DV.getContext ()))
1322
- addScopeVariable (Scope, new DbgVariable (DV, NULL , this ));
1319
+ addScopeVariable (Scope, DbgVariable (DV, NULL , this ));
1323
1320
}
1324
1321
}
1325
1322
@@ -1626,9 +1623,9 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
1626
1623
}
1627
1624
}
1628
1625
1629
- void DwarfDebug::addScopeVariable (LexicalScope *LS, DbgVariable * Var) {
1630
- SmallVectorImpl<DbgVariable *> &Vars = ScopeVariables[LS];
1631
- DIVariable DV = Var-> getVariable ();
1626
+ DbgVariable & DwarfDebug::addScopeVariable (LexicalScope *LS, DbgVariable Var) {
1627
+ auto &Vars = ScopeVariables[LS];
1628
+ DIVariable DV = Var. getVariable ();
1632
1629
// Variables with positive arg numbers are parameters.
1633
1630
if (unsigned ArgNum = DV.getArgNumber ()) {
1634
1631
// Keep all parameters in order at the start of the variable list to ensure
@@ -1638,9 +1635,9 @@ void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
1638
1635
// builds have the right order to begin with), searching from the back (this
1639
1636
// would catch the unoptimized case quickly), or doing a binary search
1640
1637
// rather than linear search.
1641
- SmallVectorImpl<DbgVariable *>::iterator I = Vars.begin ();
1638
+ auto I = Vars.begin ();
1642
1639
while (I != Vars.end ()) {
1643
- unsigned CurNum = (*I) ->getVariable ().getArgNumber ();
1640
+ unsigned CurNum = I ->getVariable ().getArgNumber ();
1644
1641
// A local (non-parameter) variable has been found, insert immediately
1645
1642
// before it.
1646
1643
if (CurNum == 0 )
@@ -1650,11 +1647,11 @@ void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
1650
1647
break ;
1651
1648
++I;
1652
1649
}
1653
- Vars.insert (I, Var);
1654
- return ;
1650
+ return *Vars.insert (I, std::move (Var));
1655
1651
}
1656
1652
1657
- Vars.push_back (Var);
1653
+ Vars.push_back (std::move (Var));
1654
+ return Vars.back ();
1658
1655
}
1659
1656
1660
1657
// Gather and emit post-function debug information.
@@ -1710,7 +1707,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
1710
1707
if (AbstractVariables.lookup (CleanDV))
1711
1708
continue ;
1712
1709
if (LexicalScope *Scope = LScopes.findAbstractScope (DV.getContext ()))
1713
- addScopeVariable (Scope, new DbgVariable (DV, NULL , this ));
1710
+ addScopeVariable (Scope, DbgVariable (DV, NULL , this ));
1714
1711
}
1715
1712
}
1716
1713
if (ProcessedSPNodes.count (AScope->getScopeNode ()) == 0 )
@@ -1728,10 +1725,8 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
1728
1725
PrevCU = TheCU;
1729
1726
1730
1727
// Clear debug info
1731
- for (auto &I : ScopeVariables)
1732
- DeleteContainerPointers (I.second );
1733
1728
ScopeVariables.clear ();
1734
- DeleteContainerPointers ( CurrentFnArguments);
1729
+ CurrentFnArguments. clear ( );
1735
1730
UserVariables.clear ();
1736
1731
DbgValues.clear ();
1737
1732
AbstractVariables.clear ();
@@ -2470,7 +2465,7 @@ void DwarfDebug::emitDebugARanges() {
2470
2465
2471
2466
// Build a set of address spans, sorted by CU.
2472
2467
for (const MCSection *Section : Sections) {
2473
- SmallVector<SymbolCU, 8 > &List = SectionMap[Section];
2468
+ auto &List = SectionMap[Section];
2474
2469
if (List.size () < 2 )
2475
2470
continue ;
2476
2471
0 commit comments