[llvm-dev] Converting i32** to [4 x i32]* ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[llvm-dev] Converting i32** to [4 x i32]* ?

George Karpenkov via llvm-dev
Hello all,

This is a general question regarding type conversion:

from: <ty>** 
to: [<size> x <ty>]*

From what I understand, bitcast  is wrong in this case because a GEP into a <ty>** should be computed differently from a GEP into [<size> x <ty>]*. 

So, what is the correct way to perform this type conversion?

Thanks,
Siddharth

--
Sending this from my phone, please excuse any typos!

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] Converting i32** to [4 x i32]* ?

George Karpenkov via llvm-dev
On 8/11/2017 3:40 PM, Siddharth Bhat via llvm-dev wrote:

>
> This is a general question regarding type conversion:
>
> from: <ty>**
> to: [<size> x <ty>]*
>
>  From what I understand, bitcast  is wrong in this case because a GEP
> into a <ty>** should be computed differently from a GEP into [<size> x
> <ty>]*.
>
> So, what is the correct way to perform this type conversion?

Bitcast, then use the correct form of GEP and other affected instructions.

-Krzysztof

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] Converting i32** to [4 x i32]* ?

George Karpenkov via llvm-dev

What would the "correct form of GEP be"?

Thanks,
Siddharth


On Fri 11 Aug, 2017, 23:47 Krzysztof Parzyszek via llvm-dev, <[hidden email]> wrote:
On 8/11/2017 3:40 PM, Siddharth Bhat via llvm-dev wrote:
>
> This is a general question regarding type conversion:
>
> from: <ty>**
> to: [<size> x <ty>]*
>
>  From what I understand, bitcast  is wrong in this case because a GEP
> into a <ty>** should be computed differently from a GEP into [<size> x
> <ty>]*.
>
> So, what is the correct way to perform this type conversion?

Bitcast, then use the correct form of GEP and other affected instructions.

-Krzysztof

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
--
Sending this from my phone, please excuse any typos!

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] Converting i32** to [4 x i32]* ?

George Karpenkov via llvm-dev
On 12 August 2017 at 04:13, Siddharth Bhat via llvm-dev
<[hidden email]> wrote:
> What would the "correct form of GEP be"?

I don't think there is one. The types are not compatible. In your
situation i32** is an array of N pointers to i32 arrays. [4 x i32]* is
a contiguous array of 4N i32s.

If you really need to use a function that takes the second type then
copying the data is the only option I see.

Cheers.

Tim.
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] Converting i32** to [4 x i32]* ?

George Karpenkov via llvm-dev
On 8/12/2017 9:32 AM, Tim Northover wrote:

> On 12 August 2017 at 04:13, Siddharth Bhat via llvm-dev
> <[hidden email]> wrote:
>> What would the "correct form of GEP be"?
>
> I don't think there is one. The types are not compatible. In your
> situation i32** is an array of N pointers to i32 arrays. [4 x i32]* is
> a contiguous array of 4N i32s.
>
> If you really need to use a function that takes the second type then
> copying the data is the only option I see.

Ah, right.  I was assuming that OP wanted to load pointers instead of i32s.

-Krzysztof
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] Converting i32** to [4 x i32]* ?

George Karpenkov via llvm-dev
Look at it from a "C" perspective.

If you have `int **`, and want `intx4 *`, what do you need to do?

You will need to load (copy, read) the content of the pointer.
But it's the wrong type, you only get a single `int` that way. So you need to cast the pointer to `intx4 **` first.

So, in essence:
    int **p;
    ...
    auto tmp = (intx4**)p;    // Bitcast
    intx4 val = *tmp;            // Load

In IR, that becomes a bitcast and load instruction.

If you also want to do tmp[3] or some such, there would be a GEP instruction after the bitcast.

--
Mats

On 12 August 2017 at 15:40, Krzysztof Parzyszek via llvm-dev <[hidden email]> wrote:
On 8/12/2017 9:32 AM, Tim Northover wrote:
On 12 August 2017 at 04:13, Siddharth Bhat via llvm-dev
<[hidden email]> wrote:
What would the "correct form of GEP be"?

I don't think there is one. The types are not compatible. In your
situation i32** is an array of N pointers to i32 arrays. [4 x i32]* is
a contiguous array of 4N i32s.

If you really need to use a function that takes the second type then
copying the data is the only option I see.

Ah, right.  I was assuming that OP wanted to load pointers instead of i32s.

-Krzysztof

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Loading...