1 //===-- llvm/iPHINode.h - PHI instruction definition -------------*- C++ -*--=//
3 // This file defines the PHINode class.
5 //===----------------------------------------------------------------------===//
7 #ifndef LLVM_IPHINODE_H
8 #define LLVM_IPHINODE_H
10 #include "llvm/Instruction.h"
13 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
17 // PHINode - The PHINode class is used to represent the magical mystical PHI
18 // node, that can not exist in nature, but can be synthesized in a computer
19 // scientist's overactive imagination.
21 class PHINode : public Instruction {
22 PHINode(const PHINode &PN);
24 PHINode(const Type *Ty, const std::string &Name = "");
26 virtual Instruction *clone() const { return new PHINode(*this); }
27 virtual const char *getOpcodeName() const { return "phi"; }
29 // getNumIncomingValues - Return the number of incoming edges the PHI node has
30 inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
32 // getIncomingValue - Return incoming value #x
33 inline const Value *getIncomingValue(unsigned i) const {
36 inline Value *getIncomingValue(unsigned i) {
39 inline void setIncomingValue(unsigned i, Value *V) {
43 // getIncomingBlock - Return incoming basic block #x
44 inline const BasicBlock *getIncomingBlock(unsigned i) const {
45 return (const BasicBlock*)Operands[i*2+1].get();
47 inline BasicBlock *getIncomingBlock(unsigned i) {
48 return (BasicBlock*)Operands[i*2+1].get();
50 inline void setIncomingBlock(unsigned i, BasicBlock *BB) {
51 Operands[i*2+1] = (Value*)BB;
54 // addIncoming - Add an incoming value to the end of the PHI list
55 void addIncoming(Value *D, BasicBlock *BB);
57 // removeIncomingValue - Remove an incoming value. This is useful if a
58 // predecessor basic block is deleted. The value removed is returned.
59 Value *removeIncomingValue(const BasicBlock *BB);
61 // getBasicBlockIndex - Return the first index of the specified basic
62 // block in the value list for this PHI. Returns -1 if no instance.
64 int getBasicBlockIndex(const BasicBlock *BB) const {
65 for (unsigned i = 0; i < Operands.size()/2; ++i)
66 if (getIncomingBlock(i) == BB) return i;
70 // Methods for support type inquiry through isa, cast, and dyn_cast:
71 static inline bool classof(const PHINode *) { return true; }
72 static inline bool classof(const Instruction *I) {
73 return I->getOpcode() == Instruction::PHINode;
75 static inline bool classof(const Value *V) {
76 return isa<Instruction>(V) && classof(cast<Instruction>(V));