Eirini Psallida
2013-Sep-24 15:53 UTC
[LLVMdev] get the address in memory where an instruction lives
On 24.09.2013, at 17:38, Eirini Psallida <eirini.psallida at gmail.com <lists.cs.uiuc.edu/mailman/listinfo/llvmdev>> wrote:>* Hi, *>* i want to get the address in memory of an instruction pointer and use it as a key in my tables.*>* i iterate over the instructions in LLVM IR like this:*>* for (Module::iterator fi = Mod->begin(), fi_end = Mod->end(); fi != fi_end; ++fi) {*>* for (inst_iterator I = inst_begin(fi), E = inst_end(fi); I != E; ++I) { *>* Instruction *ii = dyn_cast<Instruction>(&*I);*>* errs() << &ii << "\n";*>* }*>* *>* but i get the same address for every instruction, eg 0xbfc979fc*>* Why is this happening and how can i get the rigth address?* > You're printing the address of a variable on the stack. Try removing the '&' before 'ii'.But then i will have the address of where 'ii' points to. This might not be unique if other instruction pointers point to the same instruction. I want the address of the instruction pointer that's why i used '&ii'. Eirini -------------- next part -------------- An HTML attachment was scrubbed... URL: <lists.llvm.org/pipermail/llvm-dev/attachments/20130924/ad1d13d0/attachment.html>
Tim Northover
2013-Sep-24 16:06 UTC
[LLVMdev] get the address in memory where an instruction lives
Hi Eirini,> But then i will have the address of where 'ii' points to. This might not be > uniqueEach instruction can be in at most one basic block, so you won't see any duplicates in the iteration you wrote. In fact I think that's enforced by the design itself: they're intrusive linked lists. Cheers. Tim.