This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++0x] contiguous bitfields race implementation
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Aldy Hernandez <aldyh at redhat dot com>
- Cc: Jason Merrill <jason at redhat dot com>, Jeff Law <law at redhat dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Jakub Jelinek <jakub at redhat dot com>
- Date: Mon, 1 Aug 2011 15:50:54 +0200
- Subject: Re: [C++0x] contiguous bitfields race implementation
- References: <4DC8155A.3040401@redhat.com> <4DC82136.6030802@redhat.com> <4DC83549.8010709@redhat.com> <4DC83F49.5020101@redhat.com> <4DCD8412.9020005@redhat.com> <4DD440EA.2080500@redhat.com> <4DD5AA47.4000902@redhat.com> <4DDE8CE6.40203@redhat.com> <4DDE9040.8000807@redhat.com> <4DDE99D2.4020502@redhat.com> <4DDE9DED.6040801@redhat.com> <4DDFF90E.7070408@redhat.com> <4E2420E6.8090809@redhat.com> <4E29C502.8020100@redhat.com> <4E2DA2BA.1010003@redhat.com> <4E2E0264.30909@redhat.com> <4E2EED10.5030901@redhat.com> <4E2EF1E7.4020606@redhat.com> <4E2EFA1C.10803@redhat.com> <4E2EFB89.7060503@redhat.com> <CAFiYyc2Li+KXHKsG268UvPWJE-s+wVNuC7A5GsT8f5dTV9Gzsw@mail.gmail.com> <CAFiYyc0TnEwvrUG2oofTp1NNBfxVuKPze7W1FOni6XybbY0D8g@mail.gmail.com> <CAFiYyc1Z95E8gsyvrR=EsHXo30Qyz3dN1DmS+os1ROzwTcPC3Q@mail.gmail.com> <CAFiYyc0+mTBfXtDdNaYGExHwk3CBDK63jhehwEtMcMh+mtGbUg@mail.gmail.com> <4E3216F7.10504@redhat.com> <CAFiYyc1kqhnhXA2sDN2L4On0mNAnVK6tcxNL9szH7YFvbKPSVw@mail.gmail.com>
On Fri, Jul 29, 2011 at 11:37 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Fri, Jul 29, 2011 at 4:12 AM, Aldy Hernandez <aldyh@redhat.com> wrote:
>> On 07/28/11 06:40, Richard Guenther wrote:
>>
>>> Looking at the C++ memory model what you need is indeed simple enough
>>> to recover here. ?Still this loop does quadratic work for a struct with
>>> N bitfield members and a function which stores into all of them.
>>> And that with a big constant factor as you build a component-ref
>>> and even unshare trees (which isn't necessary here anyway). ?In fact
>>> you could easily manually keep track of bitpos when walking adjacent
>>> bitfield members. ?An initial call to get_inner_reference on
>>> TREE_OPERAND (exp, 0) would give you the starting position of the record.
>>>
>>> That would still be quadratic of course.
>>
>> Actually, we don't need to call get_inner_reference at all. ?It seems
>> DECL_FIELD_BIT_OFFSET has all the information we need.
>>
>> How about we simplify things further as in the attached patch?
>>
>> Tested on x86-64 Linux.
>>
>> OK for mainline?
>
> Well ... byte pieces of the offset can be in the tree offset
> (DECL_FIELD_OFFSET). ?Only up to DECL_OFFSET_ALIGN bits
> are tracked in DECL_FIELD_BIT_OFFSET (and DECL_FIELD_OFFSET
> can be a non-constant - at least for Ada, not sure about C++).
>
> But - can you please expand a bit on the desired semantics of
> get_bit_range? ?Especially, relative to what is *bitstart / *bitend
> supposed to be? ?Why do you pass in bitpos and bitsize - they
> seem to be used as local variables only. ?Why is the check for
> thread-local storage in this function and not in the caller (and
> what's the magic [0,0] bit-range relative to?)?
>
> The existing get_inner_reference calls give you a bitpos relative
> to the start of the containing object - but
>
> ? ? ?/* If this is the last element in the structure, include the padding
> ? ? ? ? at the end of structure. ?*/
> ? ? ?*bitend = TREE_INT_CST_LOW (TYPE_SIZE (record_type)) - 1;
>
> will set *bitend to the size of the direct parent structure size, not the
> size of the underlying object. ?Your proposed patch changes
> bitpos to be relative to the direct parent structure.
Using TYPE_SIZE can also run into issues with C++ tail packing,
you need to use DECL_SIZE of the respective field instead. Consider
struct A {
int : 17;
};
struct B : public A {
char c;
};
where I'm not sure we are not allowed to pack c into the tail padding
in A. Also neither TYPE_SIZE nor DECL_SIZE have to be constant,
at least in Ada you can have a variable-sized array before, and in
C you can have a trailing one.
Richard.
> So - I guess you need to play with some testcases like
>
> struct {
> ? int some_padding;
> ? struct {
> ? ? ?int bitfield :1;
> ? } x;
> };
>
> and split / clarify some of get_bit_range comments.
>
> Thanks,
> Richard.
>
>>
>