In fact I have found two solutions, and I want to know if there is any difference:
isa<LoadInst>(i)
i.getopcode()
method and comparing to Load)Which one should I use to check the opcode of an instruction?
isa
is used to check for an existing derived instruction class. class i.getopcode()
could help you to get all of the operations' information.
According to the Inheritance diagram for llvm::Instruction
,LLVM internally will divide all instructions into several different classes like llvm::BinaryOperator
, llvm::CallInst
, llvm::CmpInst
, etc. But there is no exact operation information for these classes.
However, for Instruction::getOpcode()
, it will directly get the operation from the llvm::Instruction
object. You could refer to Instruction.def for an idea about definition of each instruction. Basically, the opcode will be the exact operations the instruction intends to do.
Say, for an LLVM IR add
, you can use isa<llvm::BinaryOperator>
to know that this is a BinaryOperator
. But this is only for what the instruction class it is. If you want to know whether it is an ADD
or a SUB
. i.getopcode()
should be used here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With