Instruction ID or number in LLVM IR

1k Views Asked by At

In Execution.cpp, I can get all instructions and the values of all variables. Is there any method to get the ID or the number of each instruction.

1

There are 1 best solutions below

0
evzh On

I'm not sure if there's anything in LLVM that acts like an instruction ID, but the value of the instruction pointer (Instruction*) seems to serve your purpose. LLVM does not move instructions around, so you'll be safe as long as you don't move them yourself.

Meanwhile, if you prefer the string representation of instructions that's also doable, by

Instruction *I /* = what_ever_you_have */;
std::string str;
llvm::raw_string_ostream rso(str);
I->print(rso);

but note that a string does not suffice as a unique identifier of an instruction.

(Code is taken from How can I print to a string in LLVM.)