Hi, I wonder whether we can easily retrieve an LLVM instruction ID that uniquely identifies the instruction. In my case, I need to avoid using llvm::Instruction* directly. Given an 'inst' of type llvm::instruction*, is there some readily usable method as simple as "int id = inst->id( )"? Thanks. Zhoulai -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150506/d6700b03/attachment.html>
What’s wrong with the pointer address? —Owen> On May 6, 2015, at 3:33 PM, Zhoulai <zell08v at gmail.com> wrote: > > Hi, > > I wonder whether we can easily retrieve an LLVM instruction ID that uniquely identifies the instruction. In my case, I need to avoid using llvm::Instruction* directly. Given an 'inst' of type llvm::instruction*, is there some readily usable method as simple as “int id = inst->id( )”? Thanks. > > Zhoulai > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
intptr_t id = static_cast<intptr_t>(inst); ? On Wed, May 6, 2015 at 3:33 PM, Zhoulai <zell08v at gmail.com> wrote:> Hi, > > I wonder whether we can easily retrieve an LLVM instruction ID that > uniquely identifies the instruction. In my case, I need to avoid using > llvm::Instruction* directly. Given an 'inst' of type llvm::instruction*, is > there some readily usable method as simple as “int id = inst->id( )”? > Thanks. > > Zhoulai > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150506/2c73f616/attachment.html>
Thanks for asking. In my case, I need to avoid llvm:;instruction* as the identifier because the ID is to be passed to a callback function which only accepts primitive input values. Or, just imagine that you do not want the program segment that uses the identifier to be linked with LLVM. Zhoulai On Wed, May 6, 2015 at 3:57 PM, Owen Anderson <resistor at mac.com> wrote:> What's wrong with the pointer address? > > --Owen > > > On May 6, 2015, at 3:33 PM, Zhoulai <zell08v at gmail.com> wrote: > > > > Hi, > > > > I wonder whether we can easily retrieve an LLVM instruction ID that > uniquely identifies the instruction. In my case, I need to avoid using > llvm::Instruction* directly. Given an 'inst' of type llvm::instruction*, is > there some readily usable method as simple as "int id = inst->id( )"? > Thanks. > > > > Zhoulai > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150506/203ce2a1/attachment.html>
Thanks. I did not know this simple mechanism, shame... Is it safe? Can I then pass the intptr_t to int or long int? In my case, the ID has to be passed to a call back function accepting only primitive typed parameters. Zhoulai On Wed, May 6, 2015 at 4:12 PM, David Blaikie <dblaikie at gmail.com> wrote:> intptr_t id = static_cast<intptr_t>(inst); > > ? > > On Wed, May 6, 2015 at 3:33 PM, Zhoulai <zell08v at gmail.com> wrote: > >> Hi, >> >> I wonder whether we can easily retrieve an LLVM instruction ID that >> uniquely identifies the instruction. In my case, I need to avoid using >> llvm::Instruction* directly. Given an 'inst' of type llvm::instruction*, is >> there some readily usable method as simple as "int id = inst->id( )"? >> Thanks. >> >> Zhoulai >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150506/59c8b0b2/attachment.html>
David, As you suggested, I try to compile the following test code: *include "llvm/IR/Instruction.h"#include "stdint.h"extern void callback(intptr_t);void foo(){ llvm::Instruction* i; intptr_t zzzz=static_cast<intptr_t>(i); callback(zzzz);}* but got this compilation error: * 'intptr_t' (aka 'long') is not allowed intptr_t zzzz=static_cast<intptr_t>(i); ^~~~~~~~~~~~~~~~~~~~~~~~1 warning and 1 error generated.* For information, my OS is a Ubuntu 14.04 (VM), and my command line used to compile the program is *clang prog.cpp -c -fno-rtti -std=c++11 `llvm-config --cxxflags` -o prog.cpp.bc * Any idea on why the casting does not work? Thanks in advance. Zhoulai On Wed, May 6, 2015 at 4:12 PM, David Blaikie <dblaikie at gmail.com> wrote:> intptr_t id = static_cast<intptr_t>(inst); > > ? > > On Wed, May 6, 2015 at 3:33 PM, Zhoulai <zell08v at gmail.com> wrote: > >> Hi, >> >> I wonder whether we can easily retrieve an LLVM instruction ID that >> uniquely identifies the instruction. In my case, I need to avoid using >> llvm::Instruction* directly. Given an 'inst' of type llvm::instruction*, is >> there some readily usable method as simple as "int id = inst->id( )"? >> Thanks. >> >> Zhoulai >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150506/4db542f4/attachment.html>