r217495 - CodeGen: Use a fixed alignment for vtables.

David Blaikie dblaikie at gmail.com
Wed Sep 10 23:25:40 PDT 2014


On Wed, Sep 10, 2014 at 12:18 PM, Benjamin Kramer <benny.kra at gmail.com>
wrote:

>
> On 10.09.2014, at 20:24, David Blaikie <dblaikie at gmail.com> wrote:
>
> >
> >
> > On Wed, Sep 10, 2014 at 5:50 AM, Benjamin Kramer <
> benny.kra at googlemail.com> wrote:
> > Author: d0k
> > Date: Wed Sep 10 07:50:59 2014
> > New Revision: 217495
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=217495&view=rev
> > Log:
> > CodeGen: Use a fixed alignment for vtables.
> >
> > Any chance this change is to blame for
> http://lab.llvm.org:8011/builders/clang-x86_64-ubuntu-gdb-75/builds/17224
> ? Anything I can do to help debug this?
>
> I'm relatively sure that the test cases are just broken. It displays
> different symbols in some places in what looks like a very fragile test.
> Maybe it's best to just disable them or strip the <> symbol strings from
> the expected output.
>

Fair - took a hack at generalizing these in 217571.


>
> - Ben
>
> >
> >
> > Pointer-sized alignment is sufficient as we only ever read single values
> > from the table. Otherwise we'd bump the alignment to 16 bytes in the
> > backend if the vtable is larger than 16 bytes. This is great for
> > structures that are accessed with vector instructions or copied around,
> but
> > that's simply not the case for vtables.
> >
> > Shrinks the data segment of a Release x86_64 clang by 0.3%. The wins are
> > larger for i386 and code bases that use vtables more often than we do.
> >
> > This matches the behavior of GCC 5.
> >
> > Added:
> >     cfe/trunk/test/CodeGenCXX/vtable-align.cpp
> > Modified:
> >     cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
> >
> > Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=217495&r1=217494&r2=217495&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
> > +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Sep 10 07:50:59 2014
> > @@ -1207,6 +1207,12 @@ void ItaniumCXXABI::emitVTableDefinition
> >    // Set the right visibility.
> >    CGM.setGlobalVisibility(VTable, RD);
> >
> > +  // Use pointer alignment for the vtable. Otherwise we would align
> them based
> > +  // on the size of the initializer which doesn't make sense as only
> single
> > +  // values are read.
> > +  unsigned PAlign = CGM.getTarget().getPointerAlign(0);
> > +
> VTable->setAlignment(getContext().toCharUnitsFromBits(PAlign).getQuantity());
> > +
> >    // If this is the magic class __cxxabiv1::__fundamental_type_info,
> >    // we will emit the typeinfo for the fundamental types. This is the
> >    // same behaviour as GCC.
> >
> > Added: cfe/trunk/test/CodeGenCXX/vtable-align.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-align.cpp?rev=217495&view=auto
> >
> ==============================================================================
> > --- cfe/trunk/test/CodeGenCXX/vtable-align.cpp (added)
> > +++ cfe/trunk/test/CodeGenCXX/vtable-align.cpp Wed Sep 10 07:50:59 2014
> > @@ -0,0 +1,14 @@
> > +// RUN: %clang_cc1 %s -triple=i386-apple-darwin10 -emit-llvm -o - |
> FileCheck %s -check-prefix=CHECK-32
> > +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - |
> FileCheck %s -check-prefix=CHECK-64
> > +
> > +struct A {
> > +  virtual void f();
> > +  virtual void g();
> > +  virtual void h();
> > +};
> > +
> > +void A::f() {}
> > +
> > +// CHECK-32: @_ZTV1A = unnamed_addr constant [5 x i8*] [i8* null, i8*
> bitcast ({ i8*, i8* }* @_ZTI1A to i8*), i8* bitcast (void (%struct.A*)*
> @_ZN1A1fEv to i8*), i8* bitcast (void (%struct.A*)* @_ZN1A1gEv to i8*), i8*
> bitcast (void (%struct.A*)* @_ZN1A1hEv to i8*)], align 4
> > +
> > +// CHECK-64: @_ZTV1A = unnamed_addr constant [5 x i8*] [i8* null, i8*
> bitcast ({ i8*, i8* }* @_ZTI1A to i8*), i8* bitcast (void (%struct.A*)*
> @_ZN1A1fEv to i8*), i8* bitcast (void (%struct.A*)* @_ZN1A1gEv to i8*), i8*
> bitcast (void (%struct.A*)* @_ZN1A1hEv to i8*)], align 8
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140910/f0c5d33a/attachment.html>


More information about the cfe-commits mailing list