r362856 - DebugInfo: Add support for 'nodebug' attribute on typedefs and alias templates

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 17 11:19:21 PDT 2019


Oh, yeah - so the trick here is that you don't just drop the typedef, but
you drop an context for that typedef (if it's not otherwise used) - like
namespaces (probably otherwise used) and classes (in the class of C++ type
traits these aren't generally referenced in ways other than the typedef
they contain).

See http://lists.llvm.org/pipermail/libcxx-commits/2019-June/004697.html for
some stats/usage.



On Mon, Jun 17, 2019 at 11:00 AM <paul.robinson at sony.com> wrote:

> Is this really measurable?  All you're suppressing are the typedef DIEs
> and their names; the DIEs are small, although I admit the names can take
> up space.
> (I'm not really objecting, it's just hard to intuit a big size benefit.)
> --paulr
>
> > -----Original Message-----
> > From: cfe-commits [mailto:cfe-commits-bounces at lists.llvm.org] On Behalf
> Of
> > David Blaikie via cfe-commits
> > Sent: Friday, June 07, 2019 8:01 PM
> > To: cfe-commits at lists.llvm.org
> > Subject: r362856 - DebugInfo: Add support for 'nodebug' attribute on
> > typedefs and alias templates
> >
> > Author: dblaikie
> > Date: Fri Jun  7 17:01:21 2019
> > New Revision: 362856
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=362856&view=rev
> > Log:
> > DebugInfo: Add support for 'nodebug' attribute on typedefs and alias
> > templates
> >
> > Seems like a logical extension to me - and of interest because it might
> > help reduce the debug info size of libc++ by applying this attribute to
> > type traits that have a disproportionate debug info cost compared to the
> > benefit (& possibly harm/confusion) they cause users.
> >
> > Modified:
> >     cfe/trunk/include/clang/Basic/Attr.td
> >     cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> >     cfe/trunk/test/CodeGenCXX/debug-info-nodebug.cpp
> >     cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test
> >     cfe/trunk/test/Sema/attr-nodebug.c
> >
> > Modified: cfe/trunk/include/clang/Basic/Attr.td
> > URL: http://llvm.org/viewvc/llvm-
> >
> project/cfe/trunk/include/clang/Basic/Attr.td?rev=362856&r1=362855&r2=3628
> > 56&view=diff
> >
> ==========================================================================
> > ====
> > --- cfe/trunk/include/clang/Basic/Attr.td (original)
> > +++ cfe/trunk/include/clang/Basic/Attr.td Fri Jun  7 17:01:21 2019
> > @@ -1434,7 +1434,7 @@ def NoCommon : InheritableAttr {
> >
> >  def NoDebug : InheritableAttr {
> >    let Spellings = [GCC<"nodebug">];
> > -  let Subjects = SubjectList<[FunctionLike, ObjCMethod, NonParmVar]>;
> > +  let Subjects = SubjectList<[TypedefName, FunctionLike, ObjCMethod,
> > NonParmVar]>;
> >    let Documentation = [NoDebugDocs];
> >  }
> >
> >
> > Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> > URL: http://llvm.org/viewvc/llvm-
> >
> project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=362856&r1=362855&r2=3628
> > 56&view=diff
> >
> ==========================================================================
> > ====
> > --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> > +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Jun  7 17:01:21 2019
> > @@ -1091,15 +1091,18 @@ llvm::DIType *CGDebugInfo::CreateType(co
> >    assert(Ty->isTypeAlias());
> >    llvm::DIType *Src = getOrCreateType(Ty->getAliasedType(), Unit);
> >
> > +  auto *AliasDecl =
> > +      cast<TypeAliasTemplateDecl>(Ty-
> > >getTemplateName().getAsTemplateDecl())
> > +          ->getTemplatedDecl();
> > +
> > +  if (AliasDecl->hasAttr<NoDebugAttr>())
> > +    return Src;
> > +
> >    SmallString<128> NS;
> >    llvm::raw_svector_ostream OS(NS);
> >    Ty->getTemplateName().print(OS, getPrintingPolicy(), /*qualified*/
> > false);
> >    printTemplateArgumentList(OS, Ty->template_arguments(),
> > getPrintingPolicy());
> >
> > -  auto *AliasDecl =
> > -      cast<TypeAliasTemplateDecl>(Ty-
> > >getTemplateName().getAsTemplateDecl())
> > -          ->getTemplatedDecl();
> > -
> >    SourceLocation Loc = AliasDecl->getLocation();
> >    return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
> >                                  getLineNumber(Loc),
> > @@ -1108,15 +1111,20 @@ llvm::DIType *CGDebugInfo::CreateType(co
> >
> >  llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
> >                                        llvm::DIFile *Unit) {
> > +  llvm::DIType *Underlying =
> > +      getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit);
> > +
> > +  if (Ty->getDecl()->hasAttr<NoDebugAttr>())
> > +    return Underlying;
> > +
> >    // We don't set size information, but do specify where the typedef was
> >    // declared.
> >    SourceLocation Loc = Ty->getDecl()->getLocation();
> >
> >    // Typedefs are derived from some other type.
> > -  return DBuilder.createTypedef(
> > -      getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
> > -      Ty->getDecl()->getName(), getOrCreateFile(Loc),
> getLineNumber(Loc),
> > -      getDeclContextDescriptor(Ty->getDecl()));
> > +  return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(),
> > +                                getOrCreateFile(Loc),
> getLineNumber(Loc),
> > +
> getDeclContextDescriptor(Ty->getDecl()));
> >  }
> >
> >  static unsigned getDwarfCC(CallingConv CC) {
> >
> > Modified: cfe/trunk/test/CodeGenCXX/debug-info-nodebug.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-
> > info-nodebug.cpp?rev=362856&r1=362855&r2=362856&view=diff
> >
> ==========================================================================
> > ====
> > --- cfe/trunk/test/CodeGenCXX/debug-info-nodebug.cpp (original)
> > +++ cfe/trunk/test/CodeGenCXX/debug-info-nodebug.cpp Fri Jun  7 17:01:21
> > 2019
> > @@ -1,5 +1,5 @@
> > -// RUN: %clang_cc1 -DSETNODEBUG=0 -emit-llvm -debug-info-kind=limited %s
> > -o - | FileCheck %s --check-prefix=YESINFO
> > -// RUN: %clang_cc1 -DSETNODEBUG=1 -emit-llvm -debug-info-kind=limited %s
> > -o - | FileCheck %s --check-prefix=NOINFO
> > +// RUN: %clang_cc1 -DSETNODEBUG=0 -emit-llvm -std=c++14 -debug-info-
> > kind=limited %s -o - | FileCheck %s --check-prefix=YESINFO
> > +// RUN: %clang_cc1 -DSETNODEBUG=1 -emit-llvm -std=c++14 -debug-info-
> > kind=limited %s -o - | FileCheck %s --check-prefix=NOINFO
> >
> >  #if SETNODEBUG
> >  #define NODEBUG __attribute__((nodebug))
> > @@ -53,3 +53,15 @@ void func4() {
> >  // NOINFO-NOT:  !DIGlobalVariable(name: "static_local"
> >  // YESINFO-DAG: !DILocalVariable(name: "normal_local"
> >  // NOINFO-NOT:  !DILocalVariable(name: "normal_local"
> > +
> > +template <typename T>
> > +using y NODEBUG = int;
> > +void func5() {
> > +  NODEBUG typedef int x;
> > +  x a;
> > +  y<int> b;
> > +}
> > +// YESINFO-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "x"
> > +// NOINFO-NOT:  !DIDerivedType(tag: DW_TAG_typedef, name: "x"
> > +// YESINFO-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "y<int>"
> > +// NOINFO-NOT:  !DIDerivedType(tag: DW_TAG_typedef, name: "y<int>"
> >
> > Modified: cfe/trunk/test/Misc/pragma-attribute-supported-attributes-
> > list.test
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/pragma-
> > attribute-supported-attributes-
> > list.test?rev=362856&r1=362855&r2=362856&view=diff
> >
> ==========================================================================
> > ====
> > --- cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test
> > (original)
> > +++ cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test
> > Fri Jun  7 17:01:21 2019
> > @@ -72,7 +72,7 @@
> >  // CHECK-NEXT: NSConsumesSelf (SubjectMatchRule_objc_method)
> >  // CHECK-NEXT: Naked (SubjectMatchRule_function)
> >  // CHECK-NEXT: NoCommon (SubjectMatchRule_variable)
> > -// CHECK-NEXT: NoDebug (SubjectMatchRule_hasType_functionType,
> > SubjectMatchRule_objc_method, SubjectMatchRule_variable_not_is_parameter)
> > +// CHECK-NEXT: NoDebug (SubjectMatchRule_type_alias,
> > SubjectMatchRule_hasType_functionType, SubjectMatchRule_objc_method,
> > SubjectMatchRule_variable_not_is_parameter)
> >  // CHECK-NEXT: NoDestroy (SubjectMatchRule_variable)
> >  // CHECK-NEXT: NoDuplicate (SubjectMatchRule_function)
> >  // CHECK-NEXT: NoEscape (SubjectMatchRule_variable_is_parameter)
> >
> > Modified: cfe/trunk/test/Sema/attr-nodebug.c
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-
> > nodebug.c?rev=362856&r1=362855&r2=362856&view=diff
> >
> ==========================================================================
> > ====
> > --- cfe/trunk/test/Sema/attr-nodebug.c (original)
> > +++ cfe/trunk/test/Sema/attr-nodebug.c Fri Jun  7 17:01:21 2019
> > @@ -2,7 +2,7 @@
> >
> >  int a __attribute__((nodebug));
> >
> > -void b(int p __attribute__((nodebug))) { // expected-warning {{'nodebug'
> > attribute only applies to functions, function pointers, Objective-C
> > methods, and variables}}
> > +void b(int p __attribute__((nodebug))) { // expected-warning {{'nodebug'
> > attribute only applies to typedefs, functions, function pointers,
> > Objective-C methods, and variables}}
> >    int b __attribute__((nodebug));
> >  }
> >
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190617/0f26f209/attachment-0001.html>


More information about the cfe-commits mailing list