There is no error message to print out, end sentence with `!'
[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 using namespace llvm;
22
23 //===----------------------------------------------------------------------===//
24 //                            TerminatorInst Class
25 //===----------------------------------------------------------------------===//
26
27 TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB) 
28   : Instruction(Type::VoidTy, iType, "", IB) {
29 }
30
31 TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
32   : Instruction(Type::VoidTy, iType, "", IAE) {
33 }
34
35
36
37 //===----------------------------------------------------------------------===//
38 //                               PHINode Class
39 //===----------------------------------------------------------------------===//
40
41 PHINode::PHINode(const PHINode &PN)
42   : Instruction(PN.getType(), Instruction::PHI) {
43   Operands.reserve(PN.Operands.size());
44   for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
45     Operands.push_back(Use(PN.Operands[i], this));
46     Operands.push_back(Use(PN.Operands[i+1], this));
47   }
48 }
49
50 // removeIncomingValue - Remove an incoming value.  This is useful if a
51 // predecessor basic block is deleted.
52 Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
53   assert(Idx*2 < Operands.size() && "BB not in PHI node!");
54   Value *Removed = Operands[Idx*2];
55   Operands.erase(Operands.begin()+Idx*2,     // Erase Value and BasicBlock
56                  Operands.begin()+Idx*2+2);
57
58   // If the PHI node is dead, because it has zero entries, nuke it now.
59   if (getNumOperands() == 0 && DeletePHIIfEmpty) {
60     // If anyone is using this PHI, make them use a dummy value instead...
61     replaceAllUsesWith(Constant::getNullValue(getType()));
62     getParent()->getInstList().erase(this);
63   }
64   return Removed;
65 }