10

I am writing an LLVM pass. For an instruction (llvm::Instruction Class), how can I check if an instruction is a PHI instruction?

MetallicPriest
  • 29,191
  • 52
  • 200
  • 356

2 Answers2

15

I found the solution. You can check for a PHI node like this, isa<PHINode>(inst).

MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
1
    Instruction* I;

    if(I->getOpcode()==Instruction::PHI){
    //code
    }
blankboy2011
  • 349
  • 1
  • 10
  • 4
    the isa<> solution is how these checks should be carried out. If I had enough reputation I would downvoat this so you should maybe delete it. – baibo Jan 10 '15 at 10:50
  • @baibo Do you mean that for a higher level instruction like `PHINode`, `isa` is more idiomatic? Is there any room for error or any maintainability issue with using the opcode? – Hari Jun 26 '23 at 10:03
  • @Hari No idea, I wrote this 8 years ago and I have since long moved away from working on LLVM. Maybe it is :D – baibo Aug 05 '23 at 07:49