From: David Blaikie Date: Thu, 23 Oct 2014 22:04:30 +0000 (+0000) Subject: DebugInfo: Sink DwarfDebug::addNonArgumentScopeVariable into DwarfFile. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=48ba51a8cddd823f1c6823218b982b87b0018c0d;p=oota-llvm.git DebugInfo: Sink DwarfDebug::addNonArgumentScopeVariable into DwarfFile. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220520 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 151790ccfe8..29685abab48 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -770,7 +770,7 @@ DbgVariable *DwarfDebug::getExistingAbstractVariable(const DIVariable &DV) { void DwarfDebug::createAbstractVariable(const DIVariable &Var, LexicalScope *Scope) { auto AbsDbgVariable = make_unique(Var, DIExpression(), this); - addNonArgumentScopeVariable(Scope, AbsDbgVariable.get()); + InfoHolder.addNonArgumentScopeVariable(Scope, AbsDbgVariable.get()); AbstractVariables[Var] = std::move(AbsDbgVariable); } @@ -1256,39 +1256,7 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) { void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) { if (InfoHolder.addCurrentFnArgument(Var, LS)) return; - addNonArgumentScopeVariable(LS, Var); -} - -void DwarfDebug::addNonArgumentScopeVariable(LexicalScope *LS, - DbgVariable *Var) { - SmallVectorImpl &Vars = ScopeVariables[LS]; - DIVariable DV = Var->getVariable(); - // Variables with positive arg numbers are parameters. - if (unsigned ArgNum = DV.getArgNumber()) { - // Keep all parameters in order at the start of the variable list to ensure - // function types are correct (no out-of-order parameters) - // - // This could be improved by only doing it for optimized builds (unoptimized - // builds have the right order to begin with), searching from the back (this - // would catch the unoptimized case quickly), or doing a binary search - // rather than linear search. - SmallVectorImpl::iterator I = Vars.begin(); - while (I != Vars.end()) { - unsigned CurNum = (*I)->getVariable().getArgNumber(); - // A local (non-parameter) variable has been found, insert immediately - // before it. - if (CurNum == 0) - break; - // A later indexed parameter has been found, insert immediately before it. - if (CurNum > ArgNum) - break; - ++I; - } - Vars.insert(I, Var); - return; - } - - Vars.push_back(Var); + InfoHolder.addNonArgumentScopeVariable(LS, Var); } // Gather and emit post-function debug information. diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index ec5618f5da7..d1fae7285f5 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -334,7 +334,6 @@ class DwarfDebug : public AsmPrinterHandler { MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &); void addScopeVariable(LexicalScope *LS, DbgVariable *Var); - void addNonArgumentScopeVariable(LexicalScope *LS, DbgVariable *Var); const SmallVectorImpl> &getUnits() { return InfoHolder.getUnits(); diff --git a/lib/CodeGen/AsmPrinter/DwarfFile.cpp b/lib/CodeGen/AsmPrinter/DwarfFile.cpp index 7ad28225e96..6b3d148ee06 100644 --- a/lib/CodeGen/AsmPrinter/DwarfFile.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfFile.cpp @@ -176,4 +176,36 @@ bool DwarfFile::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) { CurrentFnArguments[ArgNo - 1] = Var; return true; } + +void DwarfFile::addNonArgumentScopeVariable(LexicalScope *LS, + DbgVariable *Var) { + SmallVectorImpl &Vars = DD.getScopeVariables()[LS]; + DIVariable DV = Var->getVariable(); + // Variables with positive arg numbers are parameters. + if (unsigned ArgNum = DV.getArgNumber()) { + // Keep all parameters in order at the start of the variable list to ensure + // function types are correct (no out-of-order parameters) + // + // This could be improved by only doing it for optimized builds (unoptimized + // builds have the right order to begin with), searching from the back (this + // would catch the unoptimized case quickly), or doing a binary search + // rather than linear search. + auto I = Vars.begin(); + while (I != Vars.end()) { + unsigned CurNum = (*I)->getVariable().getArgNumber(); + // A local (non-parameter) variable has been found, insert immediately + // before it. + if (CurNum == 0) + break; + // A later indexed parameter has been found, insert immediately before it. + if (CurNum > ArgNum) + break; + ++I; + } + Vars.insert(I, Var); + return; + } + + Vars.push_back(Var); +} } diff --git a/lib/CodeGen/AsmPrinter/DwarfFile.h b/lib/CodeGen/AsmPrinter/DwarfFile.h index ce12f1246cd..0ce9072fb1e 100644 --- a/lib/CodeGen/AsmPrinter/DwarfFile.h +++ b/lib/CodeGen/AsmPrinter/DwarfFile.h @@ -85,6 +85,7 @@ public: DwarfStringPool &getStringPool() { return StrPool; } bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope); + void addNonArgumentScopeVariable(LexicalScope *LS, DbgVariable *Var); }; } #endif