[cfe-commits] r98021 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h

Devang Patel dpatel at apple.com
Mon Mar 8 16:44:50 PST 2010


Author: dpatel
Date: Mon Mar  8 18:44:50 2010
New Revision: 98021

URL: http://llvm.org/viewvc/llvm-project?rev=98021&view=rev
Log:
Start using DIFile. Corresponding llvm patch is r98020.

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=98021&r1=98020&r2=98021&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Mar  8 18:44:50 2010
@@ -36,8 +36,9 @@
 using namespace clang::CodeGen;
 
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
-  : CGM(CGM), isMainCompileUnitCreated(false), DebugFactory(CGM.getModule()),
+  : CGM(CGM), DebugFactory(CGM.getModule()),
     BlockLiteralGenericSet(false) {
+  CreateCompileUnit();
 }
 
 CGDebugInfo::~CGDebugInfo() {
@@ -85,45 +86,29 @@
   return llvm::StringRef(StrPtr, NS.length());
 }
 
-/// getOrCreateCompileUnit - Get the compile unit from the cache or create a new
-/// one if necessary. This returns null for invalid source locations.
-llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) {
-  // Get source file information.
-  const char *FileName =  "<unknown>";
+/// getOrCreateFile - Get the file debug info descriptor for the input location.
+llvm::DIFile CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
+  if (!Loc.isValid()) 
+    // If Location is not valid then use main input file.
+    return DebugFactory.CreateFile(TheCU.getFilename(), TheCU.getDirectory(),
+                                   TheCU);
   SourceManager &SM = CGM.getContext().getSourceManager();
-  if (Loc.isValid()) {
-    PresumedLoc PLoc = SM.getPresumedLoc(Loc);
-    FileName = PLoc.getFilename();
-    unsigned FID = PLoc.getIncludeLoc().getRawEncoding();
-
-    // See if this compile unit has been used before for this valid location.
-    llvm::DICompileUnit &Unit = CompileUnitCache[FID];
-    if (Unit.Verify()) return Unit;
-  }
+  PresumedLoc PLoc = SM.getPresumedLoc(Loc);
+  llvm::sys::Path AbsFileName(PLoc.getFilename());
+  AbsFileName.makeAbsolute();
+
+  return DebugFactory.CreateFile(AbsFileName.getBasename(), 
+                                 AbsFileName.getDirname(), TheCU);
+}
+/// CreateCompileUnit - Create new compile unit.
+void CGDebugInfo::CreateCompileUnit() {
 
   // Get absolute path name.
-  llvm::sys::Path AbsFileName(FileName);
+  llvm::sys::Path AbsFileName(CGM.getCodeGenOpts().MainFileName);
   AbsFileName.makeAbsolute();
 
-  // See if thie compile unit is representing main source file. Each source
-  // file has corresponding compile unit. There is only one main source
-  // file at a time.
-  bool isMain = false;
-  const LangOptions &LO = CGM.getLangOptions();
-  const CodeGenOptions &CGO = CGM.getCodeGenOpts();
-  if (isMainCompileUnitCreated == false) {
-    if (!CGO.MainFileName.empty()) {
-      if (AbsFileName.getLast() == CGO.MainFileName)
-        isMain = true;
-    } else {
-      if (Loc.isValid() && SM.isFromMainFile(Loc))
-        isMain = true;
-    }
-    if (isMain)
-      isMainCompileUnitCreated = true;
-  }
-
   unsigned LangTag;
+  const LangOptions &LO = CGM.getLangOptions();
   if (LO.CPlusPlus) {
     if (LO.ObjC1)
       LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
@@ -149,22 +134,15 @@
     RuntimeVers = LO.ObjCNonFragileABI ? 2 : 1;
 
   // Create new compile unit.
-  llvm::DICompileUnit Unit = DebugFactory.CreateCompileUnit(
-    LangTag, AbsFileName.getLast(), AbsFileName.getDirname(), Producer, isMain,
+  TheCU = DebugFactory.CreateCompileUnit(
+    LangTag, AbsFileName.getLast(), AbsFileName.getDirname(), Producer, true,
     LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers);
-
-  if (Loc.isValid()) {
-    PresumedLoc PLoc = SM.getPresumedLoc(Loc);
-    unsigned FID = PLoc.getIncludeLoc().getRawEncoding();
-    CompileUnitCache[FID] = Unit;
-  }
-  return Unit;
 }
 
 /// CreateType - Get the Basic type from the cache or create a new
 /// one if necessary.
 llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   unsigned Encoding = 0;
   switch (BT->getKind()) {
   default:
@@ -201,7 +179,7 @@
 }
 
 llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   // Bit size, align and offset of the type.
   unsigned Encoding = llvm::dwarf::DW_ATE_complex_float;
   if (Ty->isComplexIntegerType())
@@ -220,7 +198,7 @@
 
 /// CreateCVRType - Get the qualified type from the cache or create
 /// a new one if necessary.
-llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DICompileUnit Unit) {
+llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DIFile Unit) {
   QualifierCollector Qc;
   const Type *T = Qc.strip(Ty);
 
@@ -250,13 +228,13 @@
   // No need to fill in the Name, Line, Size, Alignment, Offset in case of
   // CVR derived types.
   llvm::DIType DbgTy =
-    DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(),
+    DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DIFile(),
                                    0, 0, 0, 0, 0, FromTy);
   return DbgTy;
 }
 
 llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   llvm::DIType DbgTy =
     CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, 
                           Ty->getPointeeType(), Unit);
@@ -264,7 +242,7 @@
 }
 
 llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, 
                                Ty->getPointeeType(), Unit);
 }
@@ -272,7 +250,7 @@
 llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag,
                                                 const Type *Ty, 
                                                 QualType PointeeTy,
-                                                llvm::DICompileUnit Unit) {
+                                                llvm::DIFile Unit) {
   llvm::DIType EltTy = getOrCreateType(PointeeTy, Unit);
 
   // Bit size, align and offset of the type.
@@ -284,17 +262,17 @@
   uint64_t Align = CGM.getContext().getTypeAlign(Ty);
 
   return
-    DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(),
+    DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DIFile(),
                                    0, Size, Align, 0, 0, EltTy);
   
 }
 
 llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   if (BlockLiteralGenericSet)
     return BlockLiteralGeneric;
 
-  llvm::DICompileUnit DefUnit;
+  llvm::DIFile DefUnit;
   unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
 
   llvm::SmallVector<llvm::DIDescriptor, 5> EltTys;
@@ -345,7 +323,7 @@
   uint64_t Align = CGM.getContext().getTypeAlign(Ty);
 
   DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
-                                          Unit, "", llvm::DICompileUnit(),
+                                          Unit, "", llvm::DIFile(),
                                           0, Size, Align, 0, 0, EltTy);
 
   FieldOffset = 0;
@@ -413,13 +391,13 @@
   BlockLiteralGenericSet = true;
   BlockLiteralGeneric
     = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit,
-                                     "", llvm::DICompileUnit(),
+                                     "", llvm::DIFile(),
                                      0, Size, Align, 0, 0, EltTy);
   return BlockLiteralGeneric;
 }
 
 llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   // Typedefs are derived from some other type.  If we have a typedef of a
   // typedef, make sure to emit the whole chain.
   llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit);
@@ -442,7 +420,7 @@
 }
 
 llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
 
   // Add the result type at least.
@@ -462,7 +440,7 @@
 
   llvm::DIType DbgTy =
     DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
-                                     Unit, "", llvm::DICompileUnit(),
+                                     Unit, "", llvm::DIFile(),
                                      0, 0, 0, 0, 0,
                                      llvm::DIType(), EltTypeArray);
   return DbgTy;
@@ -471,7 +449,7 @@
 /// CollectRecordFields - A helper function to collect debug info for
 /// record fields. This is used while creating debug info entry for a Record.
 void CGDebugInfo::
-CollectRecordFields(const RecordDecl *RD, llvm::DICompileUnit Unit,
+CollectRecordFields(const RecordDecl *RD, llvm::DIFile Unit,
                     llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) {
   unsigned FieldNo = 0;
   SourceManager &SM = CGM.getContext().getSourceManager();
@@ -491,11 +469,11 @@
     // Get the location for the field.
     SourceLocation FieldDefLoc = Field->getLocation();
     PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc);
-    llvm::DICompileUnit FieldDefUnit;
+    llvm::DIFile FieldDefUnit;
     unsigned FieldLine = 0;
 
     if (!PLoc.isInvalid()) {
-      FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc);
+      FieldDefUnit = getOrCreateFile(FieldDefLoc);
       FieldLine = PLoc.getLine();
     }
 
@@ -531,7 +509,7 @@
 /// routine to get a method type which includes "this" pointer.
 llvm::DIType
 CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method,
-                                   llvm::DICompileUnit Unit) {
+                                   llvm::DIFile Unit) {
   llvm::DIType FnTy = getOrCreateType(Method->getType(), Unit);
   
   // Static methods do not need "this" pointer argument.
@@ -566,7 +544,7 @@
 
   return
     DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
-                                     Unit, "", llvm::DICompileUnit(),
+                                     Unit, "", llvm::DIFile(),
                                      0, 0, 0, 0, 0,
                                      llvm::DIType(), EltTypeArray);
 }
@@ -575,7 +553,7 @@
 /// a single member function GlobalDecl.
 llvm::DISubprogram
 CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method,
-                                     llvm::DICompileUnit Unit,
+                                     llvm::DIFile Unit,
                                      llvm::DICompositeType &RecordTy) {
   bool IsCtorOrDtor = 
     isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method);
@@ -594,11 +572,11 @@
   // Get the location for the method.
   SourceLocation MethodDefLoc = Method->getLocation();
   PresumedLoc PLoc = SM.getPresumedLoc(MethodDefLoc);
-  llvm::DICompileUnit MethodDefUnit;
+  llvm::DIFile MethodDefUnit;
   unsigned MethodLine = 0;
 
   if (!PLoc.isInvalid()) {
-    MethodDefUnit = getOrCreateCompileUnit(MethodDefLoc);
+    MethodDefUnit = getOrCreateFile(MethodDefLoc);
     MethodLine = PLoc.getLine();
   }
 
@@ -640,7 +618,7 @@
 /// C++ member functions.This is used while creating debug info entry for 
 /// a Record.
 void CGDebugInfo::
-CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DICompileUnit Unit,
+CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DIFile Unit,
                           llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys,
                           llvm::DICompositeType &RecordTy) {
   for(CXXRecordDecl::method_iterator I = RD->method_begin(),
@@ -658,7 +636,7 @@
 /// C++ base classes. This is used while creating debug info entry for 
 /// a Record.
 void CGDebugInfo::
-CollectCXXBases(const CXXRecordDecl *RD, llvm::DICompileUnit Unit,
+CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile Unit,
                 llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys,
                 llvm::DICompositeType &RecordTy) {
 
@@ -688,7 +666,7 @@
     llvm::DIType DTy =
       DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance,
                                      RecordTy, llvm::StringRef(), 
-                                     llvm::DICompileUnit(), 0, 0, 0,
+                                     llvm::DIFile(), 0, 0, 0,
                                      BaseOffset, BFlags,
                                      getOrCreateType(BI->getType(),
                                                      Unit));
@@ -697,7 +675,7 @@
 }
 
 /// getOrCreateVTablePtrType - Return debug info descriptor for vtable.
-llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DICompileUnit Unit) {
+llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile Unit) {
   if (VTablePtrType.isValid())
     return VTablePtrType;
 
@@ -710,17 +688,17 @@
     DebugFactory.GetOrCreateArray(STys.data(), STys.size());
   llvm::DIType SubTy =
     DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
-                                     Unit, "", llvm::DICompileUnit(),
+                                     Unit, "", llvm::DIFile(),
                                      0, 0, 0, 0, 0, llvm::DIType(), SElements);
 
   unsigned Size = Context.getTypeSize(Context.VoidPtrTy);
   llvm::DIType vtbl_ptr_type 
     = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
-                                     Unit, "__vtbl_ptr_type", llvm::DICompileUnit(),
+                                     Unit, "__vtbl_ptr_type", llvm::DIFile(),
                                      0, Size, 0, 0, 0, SubTy);
 
   VTablePtrType = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
-                                          Unit, "", llvm::DICompileUnit(),
+                                          Unit, "", llvm::DIFile(),
                                           0, Size, 0, 0, 0, vtbl_ptr_type);
   return VTablePtrType;
 }
@@ -740,7 +718,7 @@
 /// CollectVtableInfo - If the C++ class has vtable info then insert appropriate
 /// debug info entry in EltTys vector.
 void CGDebugInfo::
-CollectVtableInfo(const CXXRecordDecl *RD, llvm::DICompileUnit Unit,
+CollectVtableInfo(const CXXRecordDecl *RD, llvm::DIFile Unit,
                   llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) {
   const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
 
@@ -755,7 +733,7 @@
   unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
   llvm::DIType VPTR
     = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
-                                     getVtableName(RD), llvm::DICompileUnit(),
+                                     getVtableName(RD), llvm::DIFile(),
                                      0, Size, 0, 0, 0, 
                                      getOrCreateVTablePtrType(Unit));
   EltTys.push_back(VPTR);
@@ -763,7 +741,7 @@
 
 /// CreateType - get structure or union type.
 llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   RecordDecl *RD = Ty->getDecl();
 
   unsigned Tag;
@@ -780,10 +758,10 @@
 
   // Get overall information about the record type for the debug info.
   PresumedLoc PLoc = SM.getPresumedLoc(RD->getLocation());
-  llvm::DICompileUnit DefUnit;
+  llvm::DIFile DefUnit;
   unsigned Line = 0;
   if (!PLoc.isInvalid()) {
-    DefUnit = getOrCreateCompileUnit(RD->getLocation());
+    DefUnit = getOrCreateFile(RD->getLocation());
     Line = PLoc.getLine();
   }
 
@@ -861,19 +839,19 @@
 
 /// CreateType - get objective-c interface type.
 llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   ObjCInterfaceDecl *ID = Ty->getDecl();
 
   unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
   SourceManager &SM = CGM.getContext().getSourceManager();
 
   // Get overall information about the record type for the debug info.
-  llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(ID->getLocation());
+  llvm::DIFile DefUnit = getOrCreateFile(ID->getLocation());
   PresumedLoc PLoc = SM.getPresumedLoc(ID->getLocation());
   unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine();
 
 
-  unsigned RuntimeLang = DefUnit.getLanguage();
+  unsigned RuntimeLang = TheCU.getLanguage();
 
   // To handle recursive interface, we
   // first generate a debug descriptor for the struct as a forward declaration.
@@ -905,7 +883,7 @@
       getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit);
     llvm::DIType InhTag =
       DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance,
-                                     Unit, "", llvm::DICompileUnit(), 0, 0, 0,
+                                     Unit, "", llvm::DIFile(), 0, 0, 0,
                                      0 /* offset */, 0, SClassTy);
     EltTys.push_back(InhTag);
   }
@@ -926,7 +904,7 @@
 
     // Get the location for the field.
     SourceLocation FieldDefLoc = Field->getLocation();
-    llvm::DICompileUnit FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc);
+    llvm::DIFile FieldDefUnit = getOrCreateFile(FieldDefLoc);
     PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc);
     unsigned FieldLine = PLoc.isInvalid() ? 0 : PLoc.getLine();
 
@@ -984,7 +962,7 @@
 }
 
 llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   EnumDecl *ED = Ty->getDecl();
 
   llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators;
@@ -1002,7 +980,7 @@
     DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size());
 
   SourceLocation DefLoc = ED->getLocation();
-  llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc);
+  llvm::DIFile DefUnit = getOrCreateFile(DefLoc);
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(DefLoc);
   unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine();
@@ -1025,7 +1003,7 @@
 }
 
 llvm::DIType CGDebugInfo::CreateType(const TagType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   if (const RecordType *RT = dyn_cast<RecordType>(Ty))
     return CreateType(RT, Unit);
   else if (const EnumType *ET = dyn_cast<EnumType>(Ty))
@@ -1035,7 +1013,7 @@
 }
 
 llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty,
-				     llvm::DICompileUnit Unit) {
+				     llvm::DIFile Unit) {
   llvm::DIType ElementTy = getOrCreateType(Ty->getElementType(), Unit);
   uint64_t NumElems = Ty->getNumElements();
   if (NumElems > 0)
@@ -1051,13 +1029,13 @@
 
   return
     DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_vector_type,
-                                     Unit, "", llvm::DICompileUnit(),
+                                     Unit, "", llvm::DIFile(),
                                      0, Size, Align, 0, 0,
 				     ElementTy,  SubscriptArray);
 }
 
 llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty,
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   uint64_t Size;
   uint64_t Align;
 
@@ -1096,7 +1074,7 @@
 
   llvm::DIType DbgTy = 
     DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type,
-                                     Unit, "", llvm::DICompileUnit(),
+                                     Unit, "", llvm::DIFile(),
                                      0, Size, Align, 0, 0,
                                      getOrCreateType(EltTy, Unit),
                                      SubscriptArray);
@@ -1104,13 +1082,13 @@
 }
 
 llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty, 
-                                     llvm::DICompileUnit Unit) {
+                                     llvm::DIFile Unit) {
   return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, 
                                Ty, Ty->getPointeeType(), Unit);
 }
 
 llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, 
-                                     llvm::DICompileUnit U) {
+                                     llvm::DIFile U) {
   QualType PointerDiffTy = CGM.getContext().getPointerDiffType();
   llvm::DIType PointerDiffDITy = getOrCreateType(PointerDiffTy, U);
   
@@ -1129,14 +1107,14 @@
   // FIXME: This should probably be a function type instead.
   ElementTypes[0] =
     DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U,
-                                   "ptr", llvm::DICompileUnit(), 0,
+                                   "ptr", llvm::DIFile(), 0,
                                    Info.first, Info.second, FieldOffset, 0,
                                    PointerDiffDITy);
   FieldOffset += Info.first;
   
   ElementTypes[1] =
     DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U,
-                                   "ptr", llvm::DICompileUnit(), 0,
+                                   "ptr", llvm::DIFile(), 0,
                                    Info.first, Info.second, FieldOffset, 0,
                                    PointerDiffDITy);
   
@@ -1146,7 +1124,7 @@
 
   return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, 
                                           U, llvm::StringRef("test"), 
-                                          llvm::DICompileUnit(), 0, FieldOffset, 
+                                          llvm::DIFile(), 0, FieldOffset, 
                                           0, 0, 0, llvm::DIType(), Elements);
 }
 
@@ -1192,7 +1170,7 @@
 /// getOrCreateType - Get the type from the cache or create a new
 /// one if necessary.
 llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty,
-                                          llvm::DICompileUnit Unit) {
+                                          llvm::DIFile Unit) {
   if (Ty.isNull())
     return llvm::DIType();
 
@@ -1218,7 +1196,7 @@
 
 /// CreateTypeNode - Create a new debug type node.
 llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty,
-                                         llvm::DICompileUnit Unit) {
+                                         llvm::DIFile Unit) {
   // Handle qualifiers, which recursively handles what they refer to.
   if (Ty.hasLocalQualifiers())
     return CreateQualifiedType(Ty, Unit);
@@ -1329,7 +1307,7 @@
   // It is expected that CurLoc is set before using EmitFunctionStart.
   // Usually, CurLoc points to the left bracket location of compound
   // statement representing function body.
-  llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc);
+  llvm::DIFile Unit = getOrCreateFile(CurLoc);
   SourceManager &SM = CGM.getContext().getSourceManager();
   unsigned LineNo = SM.getPresumedLoc(CurLoc).getLine();
 
@@ -1359,7 +1337,7 @@
   PrevLoc = CurLoc;
 
   // Get the appropriate compile unit.
-  llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc);
+  llvm::DIFile Unit = getOrCreateFile(CurLoc);
   PresumedLoc PLoc = SM.getPresumedLoc(CurLoc);
 
   llvm::DIDescriptor DR(RegionStack.back());
@@ -1406,7 +1384,7 @@
   uint64_t FieldSize, FieldOffset;
   unsigned FieldAlign;
   
-  llvm::DICompileUnit Unit = getOrCreateCompileUnit(VD->getLocation());
+  llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
   QualType Type = VD->getType();  
 
   FieldOffset = 0;
@@ -1415,7 +1393,7 @@
   FieldSize = CGM.getContext().getTypeSize(FType);
   FieldAlign = CGM.getContext().getTypeAlign(FType);
   FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
-                                           "__isa", llvm::DICompileUnit(),
+                                           "__isa", llvm::DIFile(),
                                            0, FieldSize, FieldAlign,
                                            FieldOffset, 0, FieldTy);
   EltTys.push_back(FieldTy);
@@ -1426,7 +1404,7 @@
   FieldSize = CGM.getContext().getTypeSize(FType);
   FieldAlign = CGM.getContext().getTypeAlign(FType);
   FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
-                                           "__forwarding", llvm::DICompileUnit(),
+                                           "__forwarding", llvm::DIFile(),
                                            0, FieldSize, FieldAlign,
                                            FieldOffset, 0, FieldTy);
   EltTys.push_back(FieldTy);
@@ -1437,7 +1415,7 @@
   FieldSize = CGM.getContext().getTypeSize(FType);
   FieldAlign = CGM.getContext().getTypeAlign(FType);
   FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
-                                           "__flags", llvm::DICompileUnit(),
+                                           "__flags", llvm::DIFile(),
                                            0, FieldSize, FieldAlign,
                                            FieldOffset, 0, FieldTy);
   EltTys.push_back(FieldTy);
@@ -1448,7 +1426,7 @@
   FieldSize = CGM.getContext().getTypeSize(FType);
   FieldAlign = CGM.getContext().getTypeAlign(FType);
   FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
-                                           "__size", llvm::DICompileUnit(),
+                                           "__size", llvm::DIFile(),
                                            0, FieldSize, FieldAlign,
                                            FieldOffset, 0, FieldTy);
   EltTys.push_back(FieldTy);
@@ -1462,7 +1440,7 @@
     FieldAlign = CGM.getContext().getTypeAlign(FType);
     FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
                                              "__copy_helper", 
-                                             llvm::DICompileUnit(),
+                                             llvm::DIFile(),
                                              0, FieldSize, FieldAlign,
                                              FieldOffset, 0, FieldTy);
     EltTys.push_back(FieldTy);
@@ -1474,7 +1452,7 @@
     FieldAlign = CGM.getContext().getTypeAlign(FType);
     FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
                                              "__destroy_helper", 
-                                             llvm::DICompileUnit(),
+                                             llvm::DIFile(),
                                              0, FieldSize, FieldAlign,
                                              FieldOffset, 0, FieldTy);
     EltTys.push_back(FieldTy);
@@ -1497,7 +1475,7 @@
       FieldSize = CGM.getContext().getTypeSize(FType);
       FieldAlign = CGM.getContext().getTypeAlign(FType);
       FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member,
-                                               Unit, "", llvm::DICompileUnit(),
+                                               Unit, "", llvm::DIFile(),
                                                0, FieldSize, FieldAlign,
                                                FieldOffset, 0, FieldTy);
       EltTys.push_back(FieldTy);
@@ -1512,7 +1490,7 @@
 
   *XOffset = FieldOffset;  
   FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
-                                           VD->getName(), llvm::DICompileUnit(),
+                                           VD->getName(), llvm::DIFile(),
                                            0, FieldSize, FieldAlign,
                                            FieldOffset, 0, FieldTy);
   EltTys.push_back(FieldTy);
@@ -1525,7 +1503,7 @@
   
   return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, 
                                           Unit, "",
-                                          llvm::DICompileUnit(),
+                                          llvm::DIFile(),
                                           0, FieldOffset, 0, 0, Flags,
                                           llvm::DIType(), Elements);
   
@@ -1542,7 +1520,7 @@
   if (CGO.OptimizationLevel)
     return;
 
-  llvm::DICompileUnit Unit = getOrCreateCompileUnit(VD->getLocation());
+  llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
   llvm::DIType Ty;
   uint64_t XOffset = 0;
   if (VD->hasAttr<BlocksAttr>())
@@ -1560,9 +1538,9 @@
   if (PLoc.isValid()) {
     Line = PLoc.getLine();
     Column = PLoc.getColumn();
-    Unit = getOrCreateCompileUnit(CurLoc);
+    Unit = getOrCreateFile(CurLoc);
   } else {
-    Unit = llvm::DICompileUnit();
+    Unit = llvm::DIFile();
   }
 
   // Create the descriptor for the variable.
@@ -1596,7 +1574,7 @@
     return;
 
   uint64_t XOffset = 0;
-  llvm::DICompileUnit Unit = getOrCreateCompileUnit(VD->getLocation());
+  llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
   llvm::DIType Ty;
   if (VD->hasAttr<BlocksAttr>())
     Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset);
@@ -1610,7 +1588,7 @@
   if (!PLoc.isInvalid())
     Line = PLoc.getLine();
   else
-    Unit = llvm::DICompileUnit();
+    Unit = llvm::DIFile();
 
   CharUnits offset = CGF->BlockDecls[VD];
   llvm::SmallVector<llvm::Value *, 9> addr;
@@ -1675,7 +1653,7 @@
                                      const VarDecl *D) {
   
   // Create global variable debug descriptor.
-  llvm::DICompileUnit Unit = getOrCreateCompileUnit(D->getLocation());
+  llvm::DIFile Unit = getOrCreateFile(D->getLocation());
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(D->getLocation());
   unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
@@ -1706,7 +1684,7 @@
 void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
                                      ObjCInterfaceDecl *ID) {
   // Create global variable debug descriptor.
-  llvm::DICompileUnit Unit = getOrCreateCompileUnit(ID->getLocation());
+  llvm::DIFile Unit = getOrCreateFile(ID->getLocation());
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(ID->getLocation());
   unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
@@ -1750,7 +1728,7 @@
     getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext()), Unit);
   llvm::DINameSpace NS =
     DebugFactory.CreateNameSpace(Context, NSDecl->getName(), 
-	llvm::DICompileUnit(Unit.getNode()), LineNo);
+	llvm::DIFile(Unit.getNode()), LineNo);
   NameSpaceCache[NSDecl] = llvm::WeakVH(NS.getNode());
   return NS;
 }

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=98021&r1=98020&r2=98021&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Mon Mar  8 18:44:50 2010
@@ -43,16 +43,14 @@
 /// the backend.
 class CGDebugInfo {
   CodeGenModule &CGM;
-  bool isMainCompileUnitCreated;
   llvm::DIFactory DebugFactory;
+  llvm::DICompileUnit TheCU;
 
   SourceLocation CurLoc, PrevLoc;
   
   llvm::DIType VTablePtrType;
 
-  /// CompileUnitCache - Cache of previously constructed CompileUnits.
-  llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache;
-
+  
   /// TypeCache - Cache of previously constructed Types.
   // FIXME: Eliminate this map.  Be careful of iterator invalidation.
   std::map<void *, llvm::WeakVH> TypeCache;
@@ -71,52 +69,52 @@
   llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
 
   /// Helper functions for getOrCreateType.
-  llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateQualifiedType(QualType Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U);
+  llvm::DIType CreateType(const BuiltinType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const ComplexType *Ty, llvm::DIFile F);
+  llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile F);
   llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
-                          llvm::DICompileUnit Unit);
-  llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const VectorType *Ty, llvm::DICompileUnit Unit);
-  llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DICompileUnit U);
-  llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DICompileUnit U);
+                          llvm::DIFile F);
+  llvm::DIType CreateType(const PointerType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const TagType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const RecordType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const EnumType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F);
+  llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F);
   llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method,
-                                     llvm::DICompileUnit Unit);
-  llvm::DIType getOrCreateVTablePtrType(llvm::DICompileUnit Unit);
+                                     llvm::DIFile F);
+  llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F);
   llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N, 
                                          llvm::DIDescriptor Unit);
 
   llvm::DIType CreatePointerLikeType(unsigned Tag,
                                      const Type *Ty, QualType PointeeTy,
-                                     llvm::DICompileUnit U);
+                                     llvm::DIFile F);
   
   llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method,
-                                             llvm::DICompileUnit Unit,
+                                             llvm::DIFile F,
                                              llvm::DICompositeType &RecordTy);
   
   void CollectCXXMemberFunctions(const CXXRecordDecl *Decl,
-                                 llvm::DICompileUnit U,
+                                 llvm::DIFile F,
                                  llvm::SmallVectorImpl<llvm::DIDescriptor> &E,
                                  llvm::DICompositeType &T);
   void CollectCXXBases(const CXXRecordDecl *Decl,
-                       llvm::DICompileUnit Unit,
+                       llvm::DIFile F,
                        llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys,
                        llvm::DICompositeType &RecordTy);
 
 
-  void CollectRecordFields(const RecordDecl *Decl, llvm::DICompileUnit U,
+  void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F,
                            llvm::SmallVectorImpl<llvm::DIDescriptor> &E);
 
   void CollectVtableInfo(const CXXRecordDecl *Decl,
-                         llvm::DICompileUnit Unit,
+                         llvm::DIFile F,
                          llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys);
 
 public:
@@ -185,16 +183,19 @@
   llvm::DIDescriptor getContextDescriptor(const Decl *Decl,
                                           llvm::DIDescriptor &CU);
 
-  /// getOrCreateCompileUnit - Get the compile unit from the cache or create a
-  /// new one if necessary.
-  llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc);
+  /// CreateCompileUnit - Create new compile unit.
+  void CreateCompileUnit();
+
+  /// getOrCreateFile - Get the file debug info descriptor for the input 
+  /// location.
+  llvm::DIFile getOrCreateFile(SourceLocation Loc);
 
   /// getOrCreateType - Get the type from the cache or create a new type if
   /// necessary.
-  llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit);
+  llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F);
 
   /// CreateTypeNode - Create type metadata for a source language type.
-  llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit);
+  llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile F);
 
   /// getFunctionName - Get function name for the given FunctionDecl. If the
   /// name is constructred on demand (e.g. C++ destructor) then the name





More information about the cfe-commits mailing list