Simplify conditional and fix LICM/2004-11-17-UndefIndexCrash.ll
[oota-llvm.git] / lib / VMCore / InstrTypes.cpp
index ff9d4059d24329ddf57df6e32a7e56838132cfff..5d0e727ccc611082a23b5d99f9ca22ebd605270a 100644 (file)
@@ -1,16 +1,23 @@
 //===-- InstrTypes.cpp - Implement Instruction subclasses -------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This file implements 
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/iOther.h"
-#include "llvm/iPHINode.h"
+#include "llvm/Instructions.h"
 #include "llvm/Function.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Constant.h"
 #include "llvm/Type.h"
 #include <algorithm>  // find
+using namespace llvm;
 
 //===----------------------------------------------------------------------===//
 //                            TerminatorInst Class
@@ -20,12 +27,18 @@ TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB)
   : Instruction(Type::VoidTy, iType, "", IB) {
 }
 
+TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
+  : Instruction(Type::VoidTy, iType, "", IAE) {
+}
+
+
+
 //===----------------------------------------------------------------------===//
 //                               PHINode Class
 //===----------------------------------------------------------------------===//
 
 PHINode::PHINode(const PHINode &PN)
-  : Instruction(PN.getType(), Instruction::PHINode) {
+  : Instruction(PN.getType(), Instruction::PHI) {
   Operands.reserve(PN.Operands.size());
   for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
     Operands.push_back(Use(PN.Operands[i], this));
@@ -33,22 +46,13 @@ PHINode::PHINode(const PHINode &PN)
   }
 }
 
-void PHINode::addIncoming(Value *D, BasicBlock *BB) {
-  assert(getType() == D->getType() &&
-         "All operands to PHI node must be the same type as the PHI node!");
-  Operands.push_back(Use(D, this));
-  Operands.push_back(Use(BB, this));
-}
-
 // removeIncomingValue - Remove an incoming value.  This is useful if a
 // predecessor basic block is deleted.
-Value *PHINode::removeIncomingValue(const BasicBlock *BB,
-                                    bool DeletePHIIfEmpty) {
-  op_iterator Idx = find(Operands.begin(), Operands.end(), (const Value*)BB);
-  assert(Idx != Operands.end() && "BB not in PHI node!");
-  --Idx;  // Back up to value prior to Basic block
-  Value *Removed = *Idx;
-  Operands.erase(Idx, Idx+2);  // Erase Value and BasicBlock
+Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
+  assert(Idx*2 < Operands.size() && "BB not in PHI node!");
+  Value *Removed = Operands[Idx*2];
+  Operands.erase(Operands.begin()+Idx*2,     // Erase Value and BasicBlock
+                 Operands.begin()+Idx*2+2);
 
   // If the PHI node is dead, because it has zero entries, nuke it now.
   if (getNumOperands() == 0 && DeletePHIIfEmpty) {