[llvm-dev] How could I get some semantic information from IR?

周书林 via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 29 05:47:15 PST 2015


I'd want to do some dataflow analysis for the specific structure, so I need
to get the member name of the structure to record the condition while doing
analysis.
I was working on AST to get such information right now, but I found it is
too complicated. So I want to directly get the information from LLVM IR
while doing dataflow analysis.
As for your advise, I have read the manual of GEP in llvm.org,  and I could
get the indexes in GEP instructions. So in next step, could I get some
semantic information from the indexes I got in GEP instruction?

2015-12-27 20:20 GMT+08:00 mats petersson <mats at planetcatfish.com>:

> You will need to find out the argument for the getElementPtr, and get the
> type of that, then use the index for the GEP to find what element it is in
> the struct.
>
> Why do you want to do this at LLVM level, shouldn't AST be a better place
> to do this? [You haven't exactly said what it is you're trying to do, so
> it's hard to give specific advice, but knowing about structures and such
> seems more like something the C/AST level should deal with]
>
> --
> Mats
>
> On 25 December 2015 at 03:11, 周书林 via llvm-dev <llvm-dev at lists.llvm.org>
> wrote:
>
>> I am working on my first llvm Pass to analyze some structure variables in
>> source code, but in IR, there are only getelementptr to calculate the
>> memory address to fetch the value of a specific member in the structure.
>> For example, when I try to get the member  name of Structure S in statement
>> "if(ss.aaaa == b)", where ss is a object of Structure S and b is an
>> integer,
>> [image: 内嵌图片 2]
>> [image: 内嵌图片 4]
>> I can only get the following IR structures, and the variable %aaaa1 is
>> just a temporary name
>> [image: 内嵌图片 1]
>>
>> So, the problem is, how could I get the member name of a structure in IR?
>> more specific, how could I get the name "aaaa" while access to the
>> "ss.aaaa"?
>>
>> Thanks a lot.
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151229/693873ac/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1-2.png
Type: image/png
Size: 1302 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151229/693873ac/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1-3.png
Type: image/png
Size: 3263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151229/693873ac/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1-1.png
Type: image/png
Size: 22134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151229/693873ac/attachment-0002.png>


More information about the llvm-dev mailing list