I am writing an LLVM pass. For an instruction (llvm::Instruction Class), how can I check if an instruction is a PHI instruction?
Asked
Active
Viewed 4,183 times
10
-
1Would a `dyn_cast
(x) == NULL` have worked? – Mysticial Feb 27 '12 at 19:04 -
Mystical - yup, something similar, that is, isa
(x), worked for me! – MetallicPriest Feb 27 '12 at 19:28
2 Answers
15
I found the solution. You can check for a PHI node like this, isa<PHINode>(inst)
.

MetallicPriest
- 29,191
- 52
- 200
- 356
-
-
6@Mystical, http://llvm.org/docs/ProgrammersManual.html is a good source of information :) – Anton Korobeynikov Feb 27 '12 at 20:43
1
Instruction* I;
if(I->getOpcode()==Instruction::PHI){
//code
}

blankboy2011
- 349
- 1
- 10
-
4the 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