[llvm] r183446 - Debug Info: simplify parameter ordering preservation

David Blaikie dblaikie at gmail.com
Thu Jun 6 14:04:52 PDT 2013


Author: dblaikie
Date: Thu Jun  6 16:04:51 2013
New Revision: 183446

URL: http://llvm.org/viewvc/llvm-project?rev=183446&view=rev
Log:
Debug Info: simplify parameter ordering preservation

Seems we emit the parameter ordering number (spuriously named 'arg
number') in the debug info, so there's no need to search through the
variable list to figure out the parameter ordering. This implementation
does 'always' do the work, even in non-optimized debug info (the
previous implementation checked the existence of the 'variables' list on
the subprogram which is only present in optimized builds).

No intended functionality change.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=183446&r1=183445&r2=183446&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Thu Jun  6 16:04:51 2013
@@ -1628,32 +1628,28 @@ void DwarfDebug::beginFunction(const Mac
 void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
   SmallVectorImpl<DbgVariable *> &Vars = ScopeVariables[LS];
   DIVariable DV = Var->getVariable();
-  if (DV.getTag() == dwarf::DW_TAG_arg_variable) {
-    DISubprogram Ctxt(DV.getContext());
-    DIArray Variables = Ctxt.getVariables();
-    // If the variable is a parameter (arg_variable) and this is an optimized
-    // build (the subprogram has a 'variables' list) make sure we keep the
-    // parameters in order. Otherwise we would produce an incorrect function
-    // type with parameters out of order if function parameters were used out of
-    // order or unused (see the call to addScopeVariable in endFunction where
-    // the remaining unused variables (including parameters) are added).
-    if (unsigned NumVariables = Variables.getNumElements()) {
-      // Keep the parameters at the start of the variables list. Search through
-      // current variable list (Vars) and the full function variable list in
-      // lock-step looking for this parameter in the full list to find the
-      // insertion point.
-      SmallVectorImpl<DbgVariable *>::iterator I = Vars.begin();
-      unsigned j = 0;
-      while (I != Vars.end() && j != NumVariables &&
-             Variables.getElement(j) != DV &&
-             (*I)->getVariable().getTag() == dwarf::DW_TAG_arg_variable) {
-        if (Variables.getElement(j) == (*I)->getVariable())
-          ++I;
-        ++j;
-      }
-      Vars.insert(I, Var);
-      return;
+  // 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<DbgVariable *>::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;
     }
+    Vars.insert(I, Var);
+    return;
   }
 
   Vars.push_back(Var);





More information about the llvm-commits mailing list