Recommitted r261633 "Supporting all entities declared in lexical scope in LLVM debug info."
After fixing PR26715 at r263379.

llvm-svn: 263424
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
index bacf87d..38772fd 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
@@ -15,6 +15,7 @@
 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
 
 #include "DwarfUnit.h"
+#include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/Support/Dwarf.h"
@@ -48,11 +49,10 @@
   /// The start of the unit macro info within macro section.
   MCSymbol *MacroLabelBegin;
 
-  typedef llvm::SmallVector<const MDNode *, 8> ImportedEntityList;
-  typedef llvm::DenseMap<const MDNode *, ImportedEntityList>
-  ImportedEntityMap;
+  typedef llvm::SmallVector<const MDNode *, 8> LocalDeclNodeList;
+  typedef llvm::DenseMap<const MDNode *, LocalDeclNodeList> LocalScopesMap;
 
-  ImportedEntityMap ImportedEntities;
+  LocalScopesMap LocalDeclNodes;
 
   /// GlobalNames - A map of globally visible named entities for this unit.
   StringMap<const DIE *> GlobalNames;
@@ -71,6 +71,15 @@
   // ranges/locs.
   const MCSymbol *BaseAddress;
 
+  struct LocalScopeDieInfo {
+    DIE *ConcreteLSDie = nullptr;
+    DIE *AbstractLSDie = nullptr;
+    SetVector<DIE *> InlineLSDies;
+    SetVector<DIE *> LocalDclDies;
+  };
+  // Collection of local scope DIE info.
+  DenseMap<const MDNode *, LocalScopeDieInfo> LocalScopeDieInfoMap;
+
   /// \brief Construct a DIE for the given DbgVariable without initializing the
   /// DbgVariable's DIE reference.
   DIE *constructVariableDIEImpl(const DbgVariable &DV, bool Abstract);
@@ -117,8 +126,8 @@
 
   unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override;
 
-  void addImportedEntity(const DIImportedEntity* IE) {
-    ImportedEntities[IE->getScope()].push_back(IE);
+  void addLocalDeclNode(const DINode *DI, DILocalScope *Scope) {
+    LocalDeclNodes[Scope].push_back(DI);
   }
 
   /// addRange - Add an address range to the list of ranges for this unit.
@@ -166,7 +175,7 @@
   /// A helper function to create children of a Scope DIE.
   DIE *createScopeChildrenDIE(LexicalScope *Scope,
                               SmallVectorImpl<DIE *> &Children,
-                              unsigned *ChildScopeCount = nullptr);
+                              bool *HasNonScopeChildren = nullptr);
 
   /// \brief Construct a DIE for this subprogram scope.
   void constructSubprogramScopeDIE(LexicalScope *Scope);
@@ -175,11 +184,15 @@
 
   void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);
 
+  /// \brief Get or create import_module DIE.
+  DIE *getOrCreateImportedEntityDIE(const DIImportedEntity *Module);
   /// \brief Construct import_module DIE.
   DIE *constructImportedEntityDIE(const DIImportedEntity *Module);
 
   void finishSubprogramDefinition(const DISubprogram *SP);
 
+  void finishLocalScopeDefinitions();
+
   void collectDeadVariables(const DISubprogram *SP);
 
   /// Set the skeleton unit associated with this unit.
@@ -253,6 +266,15 @@
 
   void setBaseAddress(const MCSymbol *Base) { BaseAddress = Base; }
   const MCSymbol *getBaseAddress() const { return BaseAddress; }
+
+  DenseMap<const MDNode *, LocalScopeDieInfo> &getLSDieInfoMap() {
+    return LocalScopeDieInfoMap;
+  }
+
+  /// Add local scope DIE entry to lexical scope info.
+  void addLocalScopeDieToLexicalScope(LexicalScope *LS, DIE *D);
+  /// Add local declaration DIE entry to lexical scope info.
+  void addLocalDclDieToLexicalScope(LexicalScope *LS, DIE *D);
 };
 
 } // end llvm namespace