Improve printing of dominator sets
[oota-llvm.git] / lib / VMCore / InstrTypes.cpp
1 //===-- InstrTypes.cpp - Implement Instruction subclasses -------*- C++ -*-===//
2 //
3 // This file implements 
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "llvm/iOther.h"
8 #include "llvm/iPHINode.h"
9 #include "llvm/Function.h"
10 #include "llvm/SymbolTable.h"
11 #include "llvm/Type.h"
12 #include <algorithm>  // find
13
14 //===----------------------------------------------------------------------===//
15 //                            TerminatorInst Class
16 //===----------------------------------------------------------------------===//
17
18 TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB) 
19   : Instruction(Type::VoidTy, iType, "", IB) {
20 }
21
22 //===----------------------------------------------------------------------===//
23 //                               PHINode Class
24 //===----------------------------------------------------------------------===//
25
26 PHINode::PHINode(const PHINode &PN)
27   : Instruction(PN.getType(), Instruction::PHINode) {
28   Operands.reserve(PN.Operands.size());
29   for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
30     Operands.push_back(Use(PN.Operands[i], this));
31     Operands.push_back(Use(PN.Operands[i+1], this));
32   }
33 }
34
35 void PHINode::addIncoming(Value *D, BasicBlock *BB) {
36   assert(getType() == D->getType() &&
37          "All operands to PHI node must be the same type as the PHI node!");
38   Operands.push_back(Use(D, this));
39   Operands.push_back(Use(BB, this));
40 }
41
42 // removeIncomingValue - Remove an incoming value.  This is useful if a
43 // predecessor basic block is deleted.
44 Value *PHINode::removeIncomingValue(const BasicBlock *BB) {
45   op_iterator Idx = find(Operands.begin(), Operands.end(), (const Value*)BB);
46   assert(Idx != Operands.end() && "BB not in PHI node!");
47   --Idx;  // Back up to value prior to Basic block
48   Value *Removed = *Idx;
49   Operands.erase(Idx, Idx+2);  // Erase Value and BasicBlock
50   return Removed;
51 }