Nayden Nedev
2010-Aug-07 02:41 UTC
[LLVMdev] Determine whether a stored variable is local or global in the code of LLVM 2.7
Hi, I am trying to modify visitStoreInst() function in Execution.cpp of LLVM 2.7 to do some extra things. How I can determine whether the stored variable is global or local for some function? Regards, Nayden -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100806/fba58a79/attachment.html>
Patrick Marlier
2010-Aug-07 07:22 UTC
[LLVMdev] Determine whether a stored variable is local or global in the code of LLVM 2.7
On 08/07/2010 04:41 AM, Nayden Nedev wrote:> Hi, > > I am trying to modify visitStoreInst() function in Execution.cpp of LLVM > 2.7 to do some extra things. How I can determine whether the stored > variable is global or local for some function? > > Regards, > NaydenHello, Here the answer: http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033267.html Patrick Marlier.
Nayden Nedev
2010-Aug-09 03:32 UTC
[LLVMdev] Determine whether a stored variable is local or global in the code of LLVM 2.7
I would like to know something different than that. How I can determine if the address at which data is stored is part of the heap or part of the stack. Regards, Nayden On Sat, Aug 7, 2010 at 3:22 AM, Patrick Marlier <patrick.marlier at unine.ch>wrote:> >> On 08/07/2010 04:41 AM, Nayden Nedev wrote: >> >>> Hi, >>> >>> I am trying to modify visitStoreInst() function in Execution.cpp of LLVM >>> 2.7 to do some extra things. How I can determine whether the stored >>> variable is global or local for some function? >>> >>> Regards, >>> Nayden >>> >> Hello, >> >> Here the answer: >> http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033267.html >> >> Patrick Marlier. >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100808/f8c515d2/attachment.html>
Renato Golin
2010-Aug-09 08:25 UTC
[LLVMdev] Determine whether a stored variable is local or global in the code of LLVM 2.7
On 9 August 2010 04:32, Nayden Nedev <ndn.nedev at gmail.com> wrote:> I would like to know something different than that. How I can determine if > the address at which data is stored is part of the heap or part of the > stack.Hi Nayden, Apart from the fact that this is implementation dependent (ABI issues aside), an AllocaInst means that the variable was allocated in the pool where all local variables are. If that's the stack in your case, there you have it. GlobalVariable is somewhat more complex, since it can be external, static, const, zero-initialized and that changes where it's going to be stored (not to mention linker scripts and scattered images). About heap variables, well, the pointer has to be locally allocated (or global), so there will be an AllocaInst (or GlobalVariable) to point to that region in (what we're calling) the heap. If the AllocaInst is a pointer and point to a local variable (another AllocaInst) or a random region in memory (heap? source? data?), it up to the program and it's not always possible to determine just by looking at the pointer itself. For that case, you'll have to do some deeper analysis or keep track whenever you call malloc-like functions to make sure they're pointing to heap, rather than stack, source or data. There will be a time-frame when the pointer will be assigned with malloc and not by anything else (any other assignment will invalidate the assumption, unless the assignee is also a malloc'ed variable itself), etc. I'm not sure LLVM has something like this but wouldn't be too hard to implement, I guess. cheers, --renato