1 //===-- InstrTypes.cpp - Implement Instruction subclasses --------*- C++ -*--=//
3 // This file implements
5 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
15 // TerminatorInst Class
16 //===----------------------------------------------------------------------===//
18 TerminatorInst::TerminatorInst(Instruction::TermOps iType)
19 : Instruction(Type::VoidTy, iType, "") {
22 TerminatorInst::TerminatorInst(const Type *Ty, Instruction::TermOps iType,
23 const std::string &Name = "")
24 : Instruction(Ty, iType, Name) {
28 //===----------------------------------------------------------------------===//
30 //===----------------------------------------------------------------------===//
32 PHINode::PHINode(const Type *Ty, const std::string &name)
33 : Instruction(Ty, Instruction::PHINode, name) {
36 PHINode::PHINode(const PHINode &PN)
37 : Instruction(PN.getType(), Instruction::PHINode) {
38 Operands.reserve(PN.Operands.size());
39 for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
40 Operands.push_back(Use(PN.Operands[i], this));
41 Operands.push_back(Use(PN.Operands[i+1], this));
45 void PHINode::addIncoming(Value *D, BasicBlock *BB) {
46 assert(getType() == D->getType() &&
47 "All operands to PHI node must be the same type as the PHI node!");
48 Operands.push_back(Use(D, this));
49 Operands.push_back(Use(BB, this));
52 // removeIncomingValue - Remove an incoming value. This is useful if a
53 // predecessor basic block is deleted.
54 Value *PHINode::removeIncomingValue(const BasicBlock *BB) {
55 op_iterator Idx = find(Operands.begin(), Operands.end(), (const Value*)BB);
56 assert(Idx != Operands.end() && "BB not in PHI node!");
57 --Idx; // Back up to value prior to Basic block
58 Value *Removed = *Idx;
59 Operands.erase(Idx, Idx+2); // Erase Value and BasicBlock