Constant pointer refs are causing these to fail unnecessarily, which is causing
[oota-llvm.git] / lib / VMCore / InstrTypes.cpp
1 //===-- InstrTypes.cpp - Implement Instruction subclasses -------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements 
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/iOther.h"
15 #include "llvm/iPHINode.h"
16 #include "llvm/Function.h"
17 #include "llvm/SymbolTable.h"
18 #include "llvm/Constant.h"
19 #include "llvm/Type.h"
20 #include <algorithm>  // find
21
22 //===----------------------------------------------------------------------===//
23 //                            TerminatorInst Class
24 //===----------------------------------------------------------------------===//
25
26 TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB) 
27   : Instruction(Type::VoidTy, iType, "", IB) {
28 }
29
30 //===----------------------------------------------------------------------===//
31 //                               PHINode Class
32 //===----------------------------------------------------------------------===//
33
34 PHINode::PHINode(const PHINode &PN)
35   : Instruction(PN.getType(), Instruction::PHI) {
36   Operands.reserve(PN.Operands.size());
37   for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
38     Operands.push_back(Use(PN.Operands[i], this));
39     Operands.push_back(Use(PN.Operands[i+1], this));
40   }
41 }
42
43 // removeIncomingValue - Remove an incoming value.  This is useful if a
44 // predecessor basic block is deleted.
45 Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
46   assert(Idx*2 < Operands.size() && "BB not in PHI node!");
47   Value *Removed = Operands[Idx*2];
48   Operands.erase(Operands.begin()+Idx*2,     // Erase Value and BasicBlock
49                  Operands.begin()+Idx*2+2);
50
51   // If the PHI node is dead, because it has zero entries, nuke it now.
52   if (getNumOperands() == 0 && DeletePHIIfEmpty) {
53     // If anyone is using this PHI, make them use a dummy value instead...
54     replaceAllUsesWith(Constant::getNullValue(getType()));
55     getParent()->getInstList().erase(this);
56   }
57   return Removed;
58 }