How to check the instruction opcode?

I actually found two solutions and I want to know if there is a difference:

  • using isa for example isa<LoadInst>(i)

    .
  • using getopcode method ( i.getopcode()

    and comparison with Load

Which one to use?

+3


source to share


1 answer


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.

+5


source







All Articles