linearizing aggregates

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

linearizing aggregates

shreyas krishnan
Hi

 I have asked the clang mailing list if it can be done in clang.
However, i would like to also check if it
 can be done as a BC level transformation.

  I would like to address  aggregates (structures, arrays)  in a
linear fashion and in terms of the simplest target type that is
embedded in these data structures,   So a 2 dimensional array becomes
a single dimension array. A structure with a character and array is
addressed in terms of the target size of character.  So hopefully
express the
address calculation in terms of one GEP(base, offset) or if  GEP cant
express it  use my intrinsic.
Is that feasible ? If so, can that be done as a bc transformation.

thanks'
shrey
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: linearizing aggregates

Duncan Sands
Hi shrey,

>    I would like to address  aggregates (structures, arrays)  in a
> linear fashion and in terms of the simplest target type that is
> embedded in these data structures,   So a 2 dimensional array becomes
> a single dimension array. A structure with a character and array is
> addressed in terms of the target size of character.  So hopefully
> express the
> address calculation in terms of one GEP(base, offset) or if  GEP cant
> express it  use my intrinsic.
> Is that feasible ? If so, can that be done as a bc transformation.

it sounds like you want to turn GEP into pointer arithmetic.  It is easy
to do this directly, but here is a trick: suppose you originally have
   %p = GEP(base, offset0, offset1, ...)
Form
   %q = GEP(0, offset0, offset1, ...)
i.e. where you replaced base by a null pointer.  Now do
   %r = ptrtoint %q to i64
So %r holds the offset in octets from base.  Then the original GEP is the
same as
   $p2 = GEP(base, %r)

Ciao, Duncan.

PS: If you constant fold %r probably it will get turned into a more explicit
value.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev