How to identify the type of binaryoperator?

I’m writing my own algorithms by myself and it applies on specific instructions.

So, I have to get the operator of instruction and check what the operator is.

I’m doing like this: (for example)

if ( I->getOpcode() == 13) // if the instruction is a Add operator
{
.
.
}

But I don’t think it’s a good way to check. Because I was searching the history of instruction.def which define the opcode num, sometimes the opcode will change, and it means my algorithm need to rewrite due to the change of instruction.def.

I also do like this:

if ( ! strncmp( i->getOpcodeName(), "add", 4))
{
.
.
}

But I don’t think this is a good way.

It must have another ways better than above two examples but I don’t know how to do.

Thanks!

The opcodes make their way into an enum so you can use if (I->getOpcode() == Instruction::Add) for example.

WOW, Thanks a lot.

I got the method like if ( i->getOpcode() == llvm::Add) but it will occur the error that make me think there is no way doing like Namspace::Add form.