[codeview] Emit non-virtual method type.

Differential Revision: http://reviews.llvm.org/D21011

llvm-svn: 273084
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
index 2e3e167..b54463d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
@@ -31,6 +31,7 @@
 
 class StringRef;
 class LexicalScope;
+struct ClassInfo;
 
 /// \brief Collects and handles line tables information in a CodeView format.
 class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
@@ -136,14 +137,21 @@
   /// All inlined subprograms in the order they should be emitted.
   SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;
 
-  /// Map from DI metadata nodes to CodeView type indices. Primarily indexed by
-  /// DIType* and DISubprogram*.
-  DenseMap<const DINode *, codeview::TypeIndex> TypeIndices;
+  /// Map from a pair of DI metadata nodes and its DI type (or scope) that can
+  /// be nullptr, to CodeView type indices. Primarily indexed by
+  /// {DIType*, DIType*} and {DISubprogram*, DIType*}.
+  ///
+  /// The second entry in the key is needed for methods as DISubroutineType
+  /// representing static method type are shared with non-method function type.
+  DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex>
+      TypeIndices;
 
   /// Map from DICompositeType* to complete type index. Non-record types are
   /// always looked up in the normal TypeIndices map.
   DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;
 
+  /// Map from DICompositeType* to class info.
+  DenseMap<const DICompositeType *, std::unique_ptr<ClassInfo>> ClassInfoMap;
   const DISubprogram *CurrentSubprogram = nullptr;
 
   // The UDTs we have seen while processing types; each entry is a pair of type
@@ -159,14 +167,7 @@
 
   void maybeRecordLocation(const DebugLoc &DL, const MachineFunction *MF);
 
-  void clear() {
-    assert(CurFn == nullptr);
-    FileIdMap.clear();
-    FnDebugInfo.clear();
-    FileToFilepathMap.clear();
-    LocalUDTs.clear();
-    GlobalUDTs.clear();
-  }
+  void clear();
 
   void setCurrentSubprogram(const DISubprogram *SP) {
     CurrentSubprogram = SP;
@@ -214,9 +215,10 @@
 
   /// Translates the DIType to codeview if necessary and returns a type index
   /// for it.
-  codeview::TypeIndex getTypeIndex(DITypeRef TypeRef);
+  codeview::TypeIndex getTypeIndex(DITypeRef TypeRef,
+                                   DITypeRef ClassTyRef = DITypeRef());
 
-  codeview::TypeIndex lowerType(const DIType *Ty);
+  codeview::TypeIndex lowerType(const DIType *Ty, const DIType *ClassTy);
   codeview::TypeIndex lowerTypeAlias(const DIDerivedType *Ty);
   codeview::TypeIndex lowerTypeArray(const DICompositeType *Ty);
   codeview::TypeIndex lowerTypeBasic(const DIBasicType *Ty);
@@ -224,6 +226,8 @@
   codeview::TypeIndex lowerTypeMemberPointer(const DIDerivedType *Ty);
   codeview::TypeIndex lowerTypeModifier(const DIDerivedType *Ty);
   codeview::TypeIndex lowerTypeFunction(const DISubroutineType *Ty);
+  codeview::TypeIndex lowerTypeMemberFunction(const DISubroutineType *Ty,
+                                              const DIType *ClassTy);
   codeview::TypeIndex lowerTypeEnum(const DICompositeType *Ty);
   codeview::TypeIndex lowerTypeClass(const DICompositeType *Ty);
   codeview::TypeIndex lowerTypeUnion(const DICompositeType *Ty);
@@ -238,14 +242,22 @@
   codeview::TypeIndex lowerCompleteTypeClass(const DICompositeType *Ty);
   codeview::TypeIndex lowerCompleteTypeUnion(const DICompositeType *Ty);
 
+  codeview::TypeIndex lowerSubprogramType(const DISubprogram *SP);
+
+  void collectMemberInfo(ClassInfo &Info, const DIDerivedType *DDTy);
+  ClassInfo &collectClassInfo(const DICompositeType *Ty);
+
   /// Common record member lowering functionality for record types, which are
   /// structs, classes, and unions. Returns the field list index and the member
   /// count.
-  std::pair<codeview::TypeIndex, unsigned>
+  std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned>
   lowerRecordFieldList(const DICompositeType *Ty);
 
-  /// Inserts {Node, TI} into TypeIndices and checks for duplicates.
-  void recordTypeIndexForDINode(const DINode *Node, codeview::TypeIndex TI);
+  /// Inserts {{Node, ClassTy}, TI} into TypeIndices and checks for duplicates.
+  void recordTypeIndexForDINode(const DINode *Node, codeview::TypeIndex TI,
+                                const DIType *ClassTy = nullptr);
+
+  unsigned getPointerSizeInBytes();
 
 public:
   CodeViewDebug(AsmPrinter *Asm);