[cfe-commits] r149474 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGenCXX/debug-info-limit-type.cpp
Eric Christopher
echristo at apple.com
Tue Jan 31 22:07:23 PST 2012
Author: echristo
Date: Wed Feb 1 00:07:23 2012
New Revision: 149474
URL: http://llvm.org/viewvc/llvm-project?rev=149474&view=rev
Log:
For pass-by-value record arguments to functions emit a forward decl
instead of the entire class definition.
Added:
cfe/trunk/test/CodeGenCXX/debug-info-limit-type.cpp
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=149474&r1=149473&r2=149474&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Feb 1 00:07:23 2012
@@ -671,8 +671,12 @@
if (isa<FunctionNoProtoType>(Ty))
EltTys.push_back(DBuilder.createUnspecifiedParameter());
else if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) {
- for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
- EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit));
+ for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) {
+ if (CGM.getCodeGenOpts().LimitDebugInfo)
+ EltTys.push_back(getOrCreateLimitedType(FTP->getArgType(i), Unit));
+ else
+ EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit));
+ }
}
llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(EltTys);
@@ -681,7 +685,6 @@
return DbgTy;
}
-
void CGDebugInfo::
CollectRecordStaticVars(const RecordDecl *RD, llvm::DIType FwdDecl) {
@@ -1646,6 +1649,64 @@
return Res;
}
+/// getOrCreateLimitedType - Get the type from the cache or create a new
+/// limited type if necessary.
+llvm::DIType CGDebugInfo::getOrCreateLimitedType(QualType Ty,
+ llvm::DIFile Unit) {
+ if (Ty.isNull())
+ return llvm::DIType();
+
+ // Unwrap the type as needed for debug information.
+ Ty = UnwrapTypeForDebugInfo(Ty);
+
+ llvm::DIType T = getTypeOrNull(Ty);
+ if (T.Verify()) return T;
+
+ // Otherwise create the type.
+ llvm::DIType Res = CreateLimitedTypeNode(Ty, Unit);
+
+ // And update the type cache.
+ TypeCache[Ty.getAsOpaquePtr()] = Res;
+ return Res;
+}
+
+// TODO: Not safe to use for inner types or for fields. Currently only
+// used for by value arguments to functions anything else needs to be
+// audited carefully.
+llvm::DIType CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
+ RecordDecl *RD = Ty->getDecl();
+
+ // For templated records we want the full type information and
+ // our forward decls don't handle this correctly.
+ if (isa<ClassTemplateSpecializationDecl>(RD))
+ return CreateType(Ty);
+
+ llvm::DIDescriptor RDContext
+ = createContextChain(cast<Decl>(RD->getDeclContext()));
+
+ return createRecordFwdDecl(RD, RDContext);
+}
+
+/// CreateLimitedTypeNode - Create a new debug type node, but only forward
+/// declare composite types that haven't been processed yet.
+llvm::DIType CGDebugInfo::CreateLimitedTypeNode(QualType Ty,llvm::DIFile Unit) {
+
+ // Work out details of type.
+ switch (Ty->getTypeClass()) {
+#define TYPE(Class, Base)
+#define ABSTRACT_TYPE(Class, Base)
+#define NON_CANONICAL_TYPE(Class, Base)
+#define DEPENDENT_TYPE(Class, Base) case Type::Class:
+ #include "clang/AST/TypeNodes.def"
+ llvm_unreachable("Dependent types cannot show up in debug information");
+
+ case Type::Record:
+ return CreateLimitedType(cast<RecordType>(Ty));
+ default:
+ return CreateTypeNode(Ty, Unit);
+ }
+}
+
/// CreateTypeNode - Create a new debug type node.
llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile Unit) {
// Handle qualifiers, which recursively handles what they refer to.
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=149474&r1=149473&r2=149474&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Wed Feb 1 00:07:23 2012
@@ -73,6 +73,9 @@
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
+ /// Helper functions for getOrCreateLimitedType.
+ llvm::DIType CreateLimitedType(const RecordType *Ty);
+
/// Helper functions for getOrCreateType.
llvm::DIType CreateType(const BuiltinType *Ty);
llvm::DIType CreateType(const ComplexType *Ty);
@@ -257,9 +260,17 @@
/// necessary.
llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F);
+ /// getOrCreateLimitedType - Get the type from the cache or create a flat
+ /// limited type.
+ llvm::DIType getOrCreateLimitedType(QualType Ty, llvm::DIFile F);
+
/// CreateTypeNode - Create type metadata for a source language type.
llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile F);
+ /// CreateLimitedTypeNode - Create type metadata for a source language type,
+ /// but create as little as possible.
+ llvm::DIType CreateLimitedTypeNode(QualType Ty, llvm::DIFile F);
+
/// CreateMemberType - Create new member and increase Offset by FType's size.
llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType,
StringRef Name, uint64_t *Offset);
Added: cfe/trunk/test/CodeGenCXX/debug-info-limit-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-limit-type.cpp?rev=149474&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-limit-type.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-info-limit-type.cpp Wed Feb 1 00:07:23 2012
@@ -0,0 +1,23 @@
+// RUN: %clang -emit-llvm -g -S %s -o - | FileCheck %s
+
+class B {
+public:
+ int bb;
+ void fn2() {}
+};
+
+class A {
+public:
+ int aa;
+ void fn1(B b) { b.fn2(); }
+};
+
+void foo(A *aptr) {
+}
+
+void bar() {
+ A a;
+}
+
+// B should only be emitted as a forward reference.
+// CHECK: metadata !"B", metadata !6, i32 3, i64 0, i64 0, i32 0, i32 4, null, null, i32 0, null, null} ; [ DW_TAG_class_type
More information about the cfe-commits
mailing list