Remove the statistics
[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) {
33   if (IAE) IAE->getInstList().push_back(this);
34 }
35
36
37
38 //===----------------------------------------------------------------------===//
39 //                               PHINode Class
40 //===----------------------------------------------------------------------===//
41
42 PHINode::PHINode(const PHINode &PN)
43   : Instruction(PN.getType(), Instruction::PHI) {
44   Operands.reserve(PN.Operands.size());
45   for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
46     Operands.push_back(Use(PN.Operands[i], this));
47     Operands.push_back(Use(PN.Operands[i+1], this));
48   }
49 }
50
51 // removeIncomingValue - Remove an incoming value.  This is useful if a
52 // predecessor basic block is deleted.
53 Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
54   assert(Idx*2 < Operands.size() && "BB not in PHI node!");
55   Value *Removed = Operands[Idx*2];
56   Operands.erase(Operands.begin()+Idx*2,     // Erase Value and BasicBlock
57                  Operands.begin()+Idx*2+2);
58
59   // If the PHI node is dead, because it has zero entries, nuke it now.
60   if (getNumOperands() == 0 && DeletePHIIfEmpty) {
61     // If anyone is using this PHI, make them use a dummy value instead...
62     replaceAllUsesWith(Constant::getNullValue(getType()));
63     getParent()->getInstList().erase(this);
64   }
65   return Removed;
66 }