This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ARRAY_REF patch


Daniel Berlin wrote:
On Mon, 2005-08-29 at 07:03 -0700, Mark Mitchell wrote:

Daniel Berlin wrote:

On Sun, 2005-08-28 at 23:14 -0700, Mark Mitchell wrote:

In other words, does your patch result in better code?

No, not at the moment.

Given that, I think we should see if we can get this ready to be checked in immediately after 4.1 branches.



On the technical side, my most basic question is about the representation you chose. Why did you choose to have the first operand be a POINTER_TYPE rather than an ARRAY_TYPE?


Because that is what the user wrote, and all my attempts to transform
the POINTER_TYPE into an ARRAY_TYPE acceptable by the middle end failed
miserably.
:)


I think a better tree representation would be to use the tree equivalent of:

*((T (*)[]) p)


Honestly, I have no idea how to do this.

I would think something like this, assuming that the user has a pointer expression "p":


  elt_type = TREE_TYPE (p);
  array_type = build_array_type (elt_type, /*index_type=*/NULL_TREE);
  pointer_type = build_pointer_type (array_type);
  p = build1 (NOP_EXPR, pointer_type, p);
  p = build1 (INDIRECT_REF, array_type, p);



So wait, i'm lost :)
If i wanted to transform p[5] into this representation, what does the
code to do so look like. (I'm not quite clear on how this isn't just pointer arithmetic, since
you are putting it back in INDIRECT_REF form)

After the code I wrote, add:


expr = build2 (ARRAY_REF, elt_type, p, build_int_cst (5));

I don't promise to have all of this *exactly* right, but close enough...

The key point is to treat "p" as a pointer not a single element, but rather as a pointer to an array of elements.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]