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

Dipanjan Das via llvm-dev llvm-dev at lists.llvm.org
Sat Jun 10 06:21:34 PDT 2017


On 10 June 2017 at 05:02, 陳韋任 <chenwj.cs97g at g2.nctu.edu.tw> 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?


> [1] http://llvm.org/doxygen/classllvm_1_1AllocaInst.html
>
> HTH,
> chenwj
>
>
> 2017-06-10 14:49 GMT+08:00 Dipanjan Das via llvm-dev <
> llvm-dev at lists.llvm.org>:
>
>>
>> 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
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
>
> --
> Wei-Ren Chen (陳韋任)
> Homepage: https://people.cs.nctu.edu.tw/~chenwj
>



-- 

Thanks & Regards,
Dipanjan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170610/7eb29f84/attachment-0001.html>


More information about the llvm-dev mailing list