[llvm-dev] Get the variable size and count from AllocaInst IR instruction

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

[llvm-dev] Get the variable size and count from AllocaInst IR instruction

Gerolf Hoflehner via llvm-dev

Let's say we the following: AllocaInst *alloca_inst = dyn_cast<AllocaInst>(&I) // I = instruction
Corresponding alloca instructions in IR are as follows:

%var1 = alloca [3 x i32], align 4
%var2 = alloca i32*, align 8

How can I have the size and count (in case of array) of the allocated variables?

--

Thanks & Regards,

Dipanjan

_______________________________________________
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] Get the variable size and count from AllocaInst IR instruction

Gerolf Hoflehner via llvm-dev
+llvm-dev list

2017-06-10 20:02 GMT+08:00 陳韋任 <[hidden email]>:
Refer to [1], I believe you can use `getArraySize()` and `getType()` to get what you want.
Of course, you have to make sure the alloca does allocate an array by using `isArrayAllocation()`. 


HTH,
chenwj


2017-06-10 14:49 GMT+08:00 Dipanjan Das via llvm-dev <[hidden email]>:

Let's say we the following: AllocaInst *alloca_inst = dyn_cast<AllocaInst>(&I) // I = instruction
Corresponding alloca instructions in IR are as follows:

%var1 = alloca [3 x i32], align 4
%var2 = alloca i32*, align 8

How can I have the size and count (in case of array) of the allocated variables?

--

Thanks & Regards,

Dipanjan

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




--
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj



--
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj

_______________________________________________
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] Get the variable size and count from AllocaInst IR instruction

Gerolf Hoflehner via llvm-dev
In reply to this post by Gerolf Hoflehner via llvm-dev


On 10 June 2017 at 05:02, 陳韋任 <[hidden email]> wrote:
Refer to [1], I believe you can use `getArraySize()` and `getType()` to get what you want.
Of course, you have to make sure the alloca does allocate an array by using `isArrayAllocation()`. 


I tried getArraySize() before posting. For var1 in my example, it returns 1 instead of 3. getType() will return the Type, but how to translate that in terms of bytes?
 

2017-06-10 14:49 GMT+08:00 Dipanjan Das via llvm-dev <[hidden email]>:

Let's say we the following: AllocaInst *alloca_inst = dyn_cast<AllocaInst>(&I) // I = instruction
Corresponding alloca instructions in IR are as follows:

%var1 = alloca [3 x i32], align 4
%var2 = alloca i32*, align 8

How can I have the size and count (in case of array) of the allocated variables?

--

Thanks & Regards,

Dipanjan

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




--
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj



--

Thanks & Regards,

Dipanjan

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