Remove explicit inline qualifiers when the implicit ones work just as well
[oota-llvm.git] / include / llvm / iPHINode.h
1 //===-- llvm/iPHINode.h - PHI instruction definition ------------*- C++ -*-===//
2 //
3 // This file defines the PHINode class.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_IPHINODE_H
8 #define LLVM_IPHINODE_H
9
10 #include "llvm/Instruction.h"
11 class BasicBlock;
12
13 //===----------------------------------------------------------------------===//
14 //                               PHINode Class
15 //===----------------------------------------------------------------------===//
16
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.
20 //
21 class PHINode : public Instruction {
22   PHINode(const PHINode &PN);
23 public:
24   PHINode(const Type *Ty, const std::string &Name = "",
25           Instruction *InsertBefore = 0)
26     : Instruction(Ty, Instruction::PHINode, Name, InsertBefore) {
27   }
28
29   virtual Instruction *clone() const { return new PHINode(*this); }
30
31   /// getNumIncomingValues - Return the number of incoming edges the PHI node
32   /// has
33   unsigned getNumIncomingValues() const { return Operands.size()/2; }
34
35   /// getIncomingValue - Return incoming value #x
36   Value *getIncomingValue(unsigned i) const {
37     assert(i*2 < Operands.size() && "Invalid value number!");
38     return Operands[i*2];
39   }
40   void setIncomingValue(unsigned i, Value *V) {
41     assert(i*2 < Operands.size() && "Invalid value number!");
42     Operands[i*2] = V;
43   }
44   inline unsigned getOperandNumForIncomingValue(unsigned i) {
45     return i*2;
46   }
47
48   /// getIncomingBlock - Return incoming basic block #x
49   BasicBlock *getIncomingBlock(unsigned i) const { 
50     assert(i*2+1 < Operands.size() && "Invalid value number!");
51     return (BasicBlock*)Operands[i*2+1].get();
52   }
53   void setIncomingBlock(unsigned i, BasicBlock *BB) {
54     assert(i*2+1 < Operands.size() && "Invalid value number!");
55     Operands[i*2+1] = (Value*)BB;
56   }
57   unsigned getOperandNumForIncomingBlock(unsigned i) {
58     return i*2+1;
59   }
60
61   /// addIncoming - Add an incoming value to the end of the PHI list
62   void addIncoming(Value *D, BasicBlock *BB) {
63     assert(getType() == D->getType() &&
64            "All operands to PHI node must be the same type as the PHI node!");
65     Operands.push_back(Use(D, this));
66     Operands.push_back(Use((Value*)BB, this));
67   }
68   
69   /// removeIncomingValue - Remove an incoming value.  This is useful if a
70   /// predecessor basic block is deleted.  The value removed is returned.
71   ///
72   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
73   /// is true), the PHI node is destroyed and any uses of it are replaced with
74   /// dummy values.  The only time there should be zero incoming values to a PHI
75   /// node is when the block is dead, so this strategy is sound.
76   ///
77   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
78
79   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
80     int Idx = getBasicBlockIndex(BB);
81     assert(Idx >= 0 && "Invalid basic block argument to remove!");
82     return removeIncomingValue(Idx, DeletePHIIfEmpty);
83   }
84
85   /// getBasicBlockIndex - Return the first index of the specified basic 
86   /// block in the value list for this PHI.  Returns -1 if no instance.
87   ///
88   int getBasicBlockIndex(const BasicBlock *BB) const {
89     for (unsigned i = 0; i < Operands.size()/2; ++i) 
90       if (getIncomingBlock(i) == BB) return i;
91     return -1;
92   }
93
94   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
95     return getIncomingValue(getBasicBlockIndex(BB));
96   }
97
98   /// Methods for support type inquiry through isa, cast, and dyn_cast:
99   static inline bool classof(const PHINode *) { return true; }
100   static inline bool classof(const Instruction *I) {
101     return I->getOpcode() == Instruction::PHINode; 
102   }
103   static inline bool classof(const Value *V) {
104     return isa<Instruction>(V) && classof(cast<Instruction>(V));
105   }
106 };
107
108 #endif