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"
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) {
47 for (unsigned i = 0; i < PN.IncomingValues.size(); i++)
48 IncomingValues.push_back(Use(PN.IncomingValues[i], this));
51 void PHINode::dropAllReferences() {
52 IncomingValues.clear();
55 bool PHINode::setOperand(unsigned i, Value *Val) {
56 assert(Val && "PHI node must only reference nonnull definitions!");
57 if (i >= IncomingValues.size()) return false;
59 IncomingValues[i] = Val;
63 void PHINode::addIncoming(Value *D) {
64 IncomingValues.push_back(Use(D, this));
67 // removeIncomingValue - Remove an incoming value. This is useful if a
68 // predecessor basic block is deleted.
69 Value *PHINode::removeIncomingValue(unsigned idx) {
70 Value *Removed = IncomingValues[idx];
71 IncomingValues.erase(IncomingValues.begin()+idx);