[LLVMdev] Is there a way to address an instruction?
criswell at illinois.edu
Tue Jul 27 11:18:30 PDT 2010
Guoliang Jin wrote:
>>> In the objdump for binary, there is always an address associated with an
>>> In the bitcode file, is there a way to address an instruction? It does
>>> not have to be a single ID like objdump.
>> no, there is no way in general. You can always start a new basic block
>> just before your instruction and take the address of that basic block.
>> However later optimizations may move your instruction out of the basic
>> block. What do you want this for?
> Suppose I magically know that some instruction need special attention
> after reviewing one .ll file. Then I have a tool will handle them. The
> problem is how should I name that instruction so that my tool can
> identify it?
One possible solution is to give the instruction a name that is unique
across all value names found in the LLVM module. I think Instruction
(or one of its parent classes) has a setName() method. Your code will
have to ensure that the names are unique; the LLVM naming methods will
change the name if it finds that something else has the same name in the
Another possibility is to attach LLVM metadata to the instruction. I
think LLVM 2.7 and later supports that. The metadata can contain
whatever sort of data you want to use (e.g., integers, strings) to
uniquely identify instructions.
A third option is the llvm.pcmarker() intrinsic, although I don't know
how well it works today or exactly what it does on x86. Others more
knowledgeable can comment on it, or you can try it out and see what it does.
A fourth option is to insert inline assembly that exports a symbol.
Be aware that all of these should be done after all optimization is
done, and even then, code generation optimization may move instructions
around a little bit. I don't know exactly what you're trying to do, so
I don't know which one is best, but these are some ideas you can
-- John T.
> One way I can think of is using a triplet: function_name, the number of
> iterations to go to the block, and finally the number of iterations to
> reach the instruction.
> I also noticed some instructions have name associated. But I cannot find
> too much about instruction name. If this is the way to go, then I have
> concern that whether two instructions will have the same name, and also
> I noticed some instructions do not have names.
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
More information about the llvm-dev