How could I get some semantic information from IR?

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,
1-3.png
1-2.png
I can only get the following IR structures, and the variable %aaaa1 is just a temporary name
1-1.png

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.

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]

1-3.png

1-1.png

1-2.png

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?

1-2.png

1-3.png

1-1.png