Move to include/llvm/CodeGen
[oota-llvm.git] / include / llvm / iPHINode.h
index 0ac0d44c6694d47bf9d87f7b9209b477184b63e8..4e217e971e8c6200b9b844fbafd79fa31265d2f9 100644 (file)
@@ -21,27 +21,33 @@ class BasicBlock;
 class PHINode : public Instruction {
   PHINode(const PHINode &PN);
 public:
-  PHINode(const Type *Ty, const std::string &Name = "");
+  PHINode(const Type *Ty, const std::string &Name = "",
+          Instruction *InsertBefore = 0)
+    : Instruction(Ty, Instruction::PHINode, Name, InsertBefore) {
+  }
 
   virtual Instruction *clone() const { return new PHINode(*this); }
-  virtual const char *getOpcodeName() const { return "phi"; }
 
-  // getNumIncomingValues - Return the number of incoming edges the PHI node has
-  inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
+  /// getNumIncomingValues - Return the number of incoming edges the PHI node
+  /// has
+  unsigned getNumIncomingValues() const { return Operands.size()/2; }
 
-  // getIncomingValue - Return incoming value #x
-  inline const Value *getIncomingValue(unsigned i) const {
+  /// getIncomingValue - Return incoming value #x
+  const Value *getIncomingValue(unsigned i) const {
     return Operands[i*2];
   }
-  inline Value *getIncomingValue(unsigned i) {
+  Value *getIncomingValue(unsigned i) {
     return Operands[i*2];
   }
-  inline void setIncomingValue(unsigned i, Value *V) {
+  void setIncomingValue(unsigned i, Value *V) {
     Operands[i*2] = V;
   }
+  inline unsigned getOperandNumForIncomingValue(unsigned i) {
+    return i*2;
+  }
 
-  // getIncomingBlock - Return incoming basic block #x
-  inline const BasicBlock *getIncomingBlock(unsigned i) const { 
+  /// getIncomingBlock - Return incoming basic block #x
+  const BasicBlock *getIncomingBlock(unsigned i) const { 
     return (const BasicBlock*)Operands[i*2+1].get();
   }
   inline BasicBlock *getIncomingBlock(unsigned i) { 
@@ -50,24 +56,34 @@ public:
   inline void setIncomingBlock(unsigned i, BasicBlock *BB) {
     Operands[i*2+1] = (Value*)BB;
   }
+  inline unsigned getOperandNumForIncomingBlock(unsigned i) {
+    return i*2+1;
+  }
 
-  // addIncoming - Add an incoming value to the end of the PHI list
+  /// addIncoming - Add an incoming value to the end of the PHI list
   void addIncoming(Value *D, BasicBlock *BB);
+  
+  /// removeIncomingValue - Remove an incoming value.  This is useful if a
+  /// predecessor basic block is deleted.  The value removed is returned.
+  ///
+  /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
+  /// is true), the PHI node is destroyed and any uses of it are replaced with
+  /// dummy values.  The only time there should be zero incoming values to a PHI
+  /// node is when the block is dead, so this strategy is sound.
+  ///
+  Value *removeIncomingValue(const BasicBlock *BB,
+                             bool DeletePHIIfEmpty = true);
 
-  // removeIncomingValue - Remove an incoming value.  This is useful if a
-  // predecessor basic block is deleted.  The value removed is returned.
-  Value *removeIncomingValue(const BasicBlock *BB);
-
-  // getBasicBlockIndex - Return the first index of the specified basic 
-  // block in the value list for this PHI.  Returns -1 if no instance.
-  //
+  /// getBasicBlockIndex - Return the first index of the specified basic 
+  /// block in the value list for this PHI.  Returns -1 if no instance.
+  ///
   int getBasicBlockIndex(const BasicBlock *BB) const {
     for (unsigned i = 0; i < Operands.size()/2; ++i) 
       if (getIncomingBlock(i) == BB) return i;
     return -1;
   }
 
-  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const PHINode *) { return true; }
   static inline bool classof(const Instruction *I) {
     return I->getOpcode() == Instruction::PHINode;