From 8bf4ab319e232f185e9965c5bb417dee62706c8f Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Thu, 16 Aug 2012 23:50:46 +0000 Subject: [PATCH] Add some caching here for the builtin types. rdar://12117935 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162066 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 42 ++++++++++++++++++++++++------------- lib/CodeGen/CGDebugInfo.h | 3 +++ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index eec3b57b94..ad21d21009 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -349,42 +349,54 @@ llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT) { case BuiltinType::Void: return llvm::DIType(); case BuiltinType::ObjCClass: - return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, - "objc_class", TheCU, - getOrCreateMainFile(), 0); + if (ClassTy.Verify()) + return ClassTy; + ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, + "objc_class", TheCU, + getOrCreateMainFile(), 0); + return ClassTy; case BuiltinType::ObjCId: { // typedef struct objc_class *Class; // typedef struct objc_object { // Class isa; // } *id; - // TODO: Cache these two types to avoid duplicates. - llvm::DIType OCTy = - DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, - "objc_class", TheCU, getOrCreateMainFile(), 0); + if (ObjTy.Verify()) + return ObjTy; + + if (!ClassTy.Verify()) + ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, + "objc_class", TheCU, + getOrCreateMainFile(), 0); + unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy); - llvm::DIType ISATy = DBuilder.createPointerType(OCTy, Size); + llvm::DIType ISATy = DBuilder.createPointerType(ClassTy, Size); - llvm::MDNode *ObjTy = DBuilder.createStructType(TheCU, "objc_object", - getOrCreateMainFile(), - 0, 0, 0, 0, llvm::DIArray()); + llvm::MDNode *ObjNode = DBuilder.createStructType(TheCU, "objc_object", + getOrCreateMainFile(), + 0, 0, 0, 0, + llvm::DIArray()); SmallVector EltTys; llvm::DIType FieldTy = - DBuilder.createMemberType(llvm::DIDescriptor(ObjTy), "isa", + DBuilder.createMemberType(llvm::DIDescriptor(ObjNode), "isa", getOrCreateMainFile(), 0, Size, 0, 0, 0, ISATy); EltTys.push_back(FieldTy); llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys); - ObjTy->replaceOperandWith(10, Elements); - return llvm::DIType(ObjTy); + ObjNode->replaceOperandWith(10, Elements); + ObjTy = llvm::DIType(ObjTy); + return ObjTy; } case BuiltinType::ObjCSel: { - return + if (SelTy.Verify()) + return SelTy; + SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, "objc_selector", TheCU, getOrCreateMainFile(), 0); + return SelTy; } case BuiltinType::UChar: case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break; diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 44cc49ade1..2e88a7376a 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -50,6 +50,9 @@ class CGDebugInfo { llvm::DICompileUnit TheCU; SourceLocation CurLoc, PrevLoc; llvm::DIType VTablePtrType; + llvm::DIType ClassTy; + llvm::DIType ObjTy; + llvm::DIType SelTy; /// TypeCache - Cache of previously constructed Types. llvm::DenseMap TypeCache; -- 2.40.0