1 //===-- InstrTypes.cpp - Implement Instruction subclasses --------*- C++ -*--=//
3 // This file implements
5 //===----------------------------------------------------------------------===//
7 #include "llvm/iOther.h"
8 #include "llvm/BasicBlock.h"
9 #include "llvm/Method.h"
10 #include "llvm/SymbolTable.h"
11 #include "llvm/Type.h"
12 #include <algorithm> // find
14 //===----------------------------------------------------------------------===//
15 // TerminatorInst Class
16 //===----------------------------------------------------------------------===//
18 TerminatorInst::TerminatorInst(unsigned iType)
19 : Instruction(Type::VoidTy, iType, "") {
23 //===----------------------------------------------------------------------===//
24 // MethodArgument Class
25 //===----------------------------------------------------------------------===//
27 // Specialize setName to take care of symbol table majik
28 void MethodArgument::setName(const string &name) {
30 if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
32 if (P && hasName()) P->getSymbolTable()->insert(this);
36 //===----------------------------------------------------------------------===//
38 //===----------------------------------------------------------------------===//
40 PHINode::PHINode(const Type *Ty, const string &name)
41 : Instruction(Ty, Instruction::PHINode, name) {
44 PHINode::PHINode(const PHINode &PN)
45 : Instruction(PN.getType(), Instruction::PHINode) {
46 Operands.reserve(PN.Operands.size());
47 for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
48 Operands.push_back(Use(PN.Operands[i], this));
49 Operands.push_back(Use(PN.Operands[i+1], this));
53 void PHINode::addIncoming(Value *D, BasicBlock *BB) {
54 Operands.push_back(Use(D, this));
55 Operands.push_back(Use(BB, this));
58 // removeIncomingValue - Remove an incoming value. This is useful if a
59 // predecessor basic block is deleted.
60 Value *PHINode::removeIncomingValue(const BasicBlock *BB) {
61 op_iterator Idx = find(Operands.begin(), Operands.end(), (const Value*)BB);
62 assert(Idx != Operands.end() && "BB not in PHI node!");
63 --Idx; // Back up to value prior to Basic block
64 Value *Removed = *Idx;
65 Operands.erase(Idx, Idx+2); // Erase Value and BasicBlock