How to check the instruction opcode?
isa
used to test an existing dirived class. class i.getopcode()
can help you get all the information about operations.
In accordance with Inheritance diagram forllvm::Instruction
LLVM internally divides all of the instructions into several classes, e.g. llvm::BinaryOperator
, llvm::CallInst
, llvm::CmpInst
etc. But there is no exact information about the operation for these classes.
However, for Instruction::getOpcode()
it will directly receive the operation from the object llvm::Instruction
. You can refer to Instruction.def for the idea of protecting each team. Basically, the opcode will be the exact operation the instruction intends to do.
Let's say for LLVM IR add
. You can use isa<llvm::BinaryOperator>
to know what it is BinaryOperator
. But that's just for what the instruction class is. If you want to know if it is add
or SUB
. i.getopcode()
should be used here.
source to share