我不确定 LLVM 中是否有任何类似于指令 ID 的东西,但指令指针 ( Instruction*
) 的值似乎可以满足您的目的。LLVM 不会移动指令,因此只要您自己不移动它们,您就会很安全。
同时,如果您更喜欢指令的字符串表示形式,这也是可行的,通过
Instruction *I /* = what_ever_you_have */;
std::string str;
llvm::raw_string_ostream rso(str);
I->print(rso);
但请注意,字符串不足以作为指令的唯一标识符。
(代码取自How can I print to a string in LLVM。)