Debug Info: this reverts commit r189600.

We had further discussions on how to retain types, whether to do it in front end
or in DIBuilder. And we agree to do it in DIBuilder so front ends
generating unique identifier do not need to worry about retaining them.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189609 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index bd19737..fd495fe 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -599,29 +599,6 @@
                                Ty->getPointeeType(), Unit);
 }
 
-/// In C++ mode, types have linkage, so we can rely on the ODR and
-/// on their mangled names, if they're external. Otherwise, we append
-/// the CU's directory and file name.
-static void getUniqueTagTypeName(const TagType *Ty, CodeGenModule &CGM,
-                                 llvm::DICompileUnit TheCU,
-                                 SmallString<256> &FullName) {
-  // FIXME: ODR should apply to ObjC++ exactly the same wasy it does to C++.
-  // For now, only apply ODR with C++.
-  const TagDecl *TD = Ty->getDecl();
-  if (TheCU.getLanguage() != llvm::dwarf::DW_LANG_C_plus_plus ||
-      !TD->isExternallyVisible())
-    return;
-  // Microsoft Mangler does not have support for mangleCXXRTTIName yet.
-  if (CGM.getTarget().getCXXABI().isMicrosoft())
-    return;
-
-  // TODO: This is using the RTTI name. Is there a better way to get
-  // a unique string for a type?
-  llvm::raw_svector_ostream Out(FullName);
-  CGM.getCXXABI().getMangleContext().mangleCXXRTTIName(QualType(Ty, 0), Out);
-  Out.flush();
-}
-
 // Creates a forward declaration for a RecordDecl in the given context.
 llvm::DICompositeType
 CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty,
@@ -644,14 +621,7 @@
   }
 
   // Create the type.
-  SmallString<256> FullName;
-  getUniqueTagTypeName(Ty, CGM, TheCU, FullName);
-  if (!FullName.empty()) {
-    QualType QTy(Ty, 0);
-    RetainedTypes.push_back(QTy.getAsOpaquePtr());
-  }
-  return DBuilder.createForwardDecl(Tag, RDName, Ctx, DefUnit, Line, 0, 0, 0,
-                                    FullName.str());
+  return DBuilder.createForwardDecl(Tag, RDName, Ctx, DefUnit, Line);
 }
 
 // Walk up the context chain and create forward decls for record decls,
@@ -1914,13 +1884,6 @@
     Align = CGM.getContext().getTypeAlign(ED->getTypeForDecl());
   }
 
-  SmallString<256> FullName;
-  getUniqueTagTypeName(Ty, CGM, TheCU, FullName);
-  if (!FullName.empty()) {
-    QualType QTy(Ty, 0);
-    RetainedTypes.push_back(QTy.getAsOpaquePtr());
-  }
-
   // If this is just a forward declaration, construct an appropriately
   // marked node and just return it.
   if (!ED->getDefinition()) {
@@ -1931,7 +1894,7 @@
     StringRef EDName = ED->getName();
     return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_enumeration_type,
                                       EDName, EDContext, DefUnit, Line, 0,
-                                      Size, Align, FullName.str());
+                                      Size, Align);
   }
 
   // Create DIEnumerator elements for each enumerator.
@@ -1957,7 +1920,7 @@
   llvm::DIType DbgTy =
     DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit, Line,
                                    Size, Align, EltArray,
-                                   ClassTy, FullName.str());
+                                   ClassTy);
   return DbgTy;
 }
 
@@ -2307,28 +2270,20 @@
   uint64_t Align = CGM.getContext().getTypeAlign(Ty);
   llvm::DICompositeType RealDecl;
 
-  SmallString<256> FullName;
-  getUniqueTagTypeName(Ty, CGM, TheCU, FullName);
-  if (!FullName.empty()) {
-    QualType QTy(Ty, 0);
-    RetainedTypes.push_back(QTy.getAsOpaquePtr());
-  }
-
   if (RD->isUnion())
     RealDecl = DBuilder.createUnionType(RDContext, RDName, DefUnit, Line,
-                                        Size, Align, 0, llvm::DIArray(), 0,
-                                        FullName.str());
+                                        Size, Align, 0, llvm::DIArray());
   else if (RD->isClass()) {
     // FIXME: This could be a struct type giving a default visibility different
     // than C++ class type, but needs llvm metadata changes first.
     RealDecl = DBuilder.createClassType(RDContext, RDName, DefUnit, Line,
                                         Size, Align, 0, 0, llvm::DIType(),
                                         llvm::DIArray(), llvm::DIType(),
-                                        llvm::DIArray(), FullName.str());
+                                        llvm::DIArray());
   } else
     RealDecl = DBuilder.createStructType(RDContext, RDName, DefUnit, Line,
                                          Size, Align, 0, llvm::DIType(),
-                                         llvm::DIArray(), 0, 0, FullName.str());
+                                         llvm::DIArray());
 
   RegionMap[Ty->getDecl()] = llvm::WeakVH(RealDecl);
   TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl;
@@ -3335,17 +3290,9 @@
 
   // We keep our own list of retained types, because we need to look
   // up the final type in the type cache.
-  // Both createForwardDecl and createLimitedType can add the same type to
-  // RetainedTypes. A set is used to avoid duplication.
-  llvm::SmallPtrSet<void *, 16> RetainSet;
   for (std::vector<void *>::const_iterator RI = RetainedTypes.begin(),
          RE = RetainedTypes.end(); RI != RE; ++RI)
-    if (RetainSet.insert(*RI)) {
-      llvm::DenseMap<void *, llvm::WeakVH>::iterator it =
-        TypeCache.find(*RI);
-      if (it != TypeCache.end() && it->second)
-        DBuilder.retainType(llvm::DIType(cast<llvm::MDNode>(it->second)));
-    }
+    DBuilder.retainType(llvm::DIType(cast<llvm::MDNode>(TypeCache[*RI])));
 
   DBuilder.finalize();
 }