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 // TODO: Move to getUnaryOperator iUnary.cpp when and if it exists!
15 UnaryOperator *UnaryOperator::create(unsigned Op, Value *Source) {
18 cerr << "Don't know how to GetUnaryOperator " << Op << endl;
23 //===----------------------------------------------------------------------===//
24 // TerminatorInst Class
25 //===----------------------------------------------------------------------===//
27 TerminatorInst::TerminatorInst(unsigned iType)
28 : Instruction(Type::VoidTy, iType, "") {
32 //===----------------------------------------------------------------------===//
33 // MethodArgument Class
34 //===----------------------------------------------------------------------===//
36 // Specialize setName to take care of symbol table majik
37 void MethodArgument::setName(const string &name) {
39 if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
41 if (P && hasName()) P->getSymbolTable()->insert(this);
45 //===----------------------------------------------------------------------===//
47 //===----------------------------------------------------------------------===//
49 PHINode::PHINode(const Type *Ty, const string &name)
50 : Instruction(Ty, Instruction::PHINode, name) {
53 PHINode::PHINode(const PHINode &PN)
54 : Instruction(PN.getType(), Instruction::PHINode) {
55 Operands.reserve(PN.Operands.size());
56 for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
57 Operands.push_back(Use(PN.Operands[i], this));
58 Operands.push_back(Use(PN.Operands[i+1], this));
62 void PHINode::addIncoming(Value *D, BasicBlock *BB) {
63 Operands.push_back(Use(D, this));
64 Operands.push_back(Use(BB, this));
67 // removeIncomingValue - Remove an incoming value. This is useful if a
68 // predecessor basic block is deleted.
69 Value *PHINode::removeIncomingValue(const BasicBlock *BB) {
70 op_iterator Idx = find(Operands.begin(), Operands.end(), (const Value*)BB);
71 assert(Idx != Operands.end() && "BB not in PHI node!");
72 --Idx; // Back up to value prior to Basic block
73 Value *Removed = *Idx;
74 Operands.erase(Idx, Idx+2); // Erase Value and BasicBlock