X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FInstrTypes.cpp;h=b53f480b14861580f28236a94d55ca7e410f1288;hb=62815d96727768b3bd3178929b3912ecde65c6a2;hp=decb4ad386412ef4981b4d943f737f65ba790fad;hpb=b0b0aa384941279f6954f254b055e6810bb7be83;p=oota-llvm.git diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp index decb4ad3864..b53f480b148 100644 --- a/lib/VMCore/InstrTypes.cpp +++ b/lib/VMCore/InstrTypes.cpp @@ -1,73 +1,51 @@ -//===-- InstrTypes.cpp - Implement Instruction subclasses --------*- C++ -*--=// +//===-- InstrTypes.cpp - Implement Instruction subclasses -------*- C++ -*-===// // // This file implements // //===----------------------------------------------------------------------===// #include "llvm/iOther.h" -#include "llvm/BasicBlock.h" -#include "llvm/Method.h" +#include "llvm/iPHINode.h" +#include "llvm/Function.h" #include "llvm/SymbolTable.h" #include "llvm/Type.h" -#include +#include // find //===----------------------------------------------------------------------===// // TerminatorInst Class //===----------------------------------------------------------------------===// -TerminatorInst::TerminatorInst(unsigned iType) - : Instruction(Type::VoidTy, iType, "") { +TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB) + : Instruction(Type::VoidTy, iType, "", IB) { } - -//===----------------------------------------------------------------------===// -// MethodArgument Class -//===----------------------------------------------------------------------===// - -// Specialize setName to take care of symbol table majik -void MethodArgument::setName(const string &name) { - Method *P; - if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this); - Value::setName(name); - if (P && hasName()) P->getSymbolTable()->insert(this); -} - - //===----------------------------------------------------------------------===// // PHINode Class //===----------------------------------------------------------------------===// -PHINode::PHINode(const Type *Ty, const string &name) - : Instruction(Ty, Instruction::PHINode, name) { -} - -PHINode::PHINode(const PHINode &PN) +PHINode::PHINode(const PHINode &PN) : Instruction(PN.getType(), Instruction::PHINode) { - - for (unsigned i = 0; i < PN.IncomingValues.size(); i++) - IncomingValues.push_back(Use(PN.IncomingValues[i], this)); -} - -void PHINode::dropAllReferences() { - IncomingValues.clear(); -} - -bool PHINode::setOperand(unsigned i, Value *Val) { - assert(Val && "PHI node must only reference nonnull definitions!"); - if (i >= IncomingValues.size()) return false; - - IncomingValues[i] = Val; - return true; + Operands.reserve(PN.Operands.size()); + for (unsigned i = 0; i < PN.Operands.size(); i+=2) { + Operands.push_back(Use(PN.Operands[i], this)); + Operands.push_back(Use(PN.Operands[i+1], this)); + } } -void PHINode::addIncoming(Value *D) { - IncomingValues.push_back(Use(D, this)); +void PHINode::addIncoming(Value *D, BasicBlock *BB) { + assert(getType() == D->getType() && + "All operands to PHI node must be the same type as the PHI node!"); + Operands.push_back(Use(D, this)); + Operands.push_back(Use(BB, this)); } // removeIncomingValue - Remove an incoming value. This is useful if a // predecessor basic block is deleted. -Value *PHINode::removeIncomingValue(unsigned idx) { - Value *Removed = IncomingValues[idx]; - IncomingValues.erase(IncomingValues.begin()+idx); +Value *PHINode::removeIncomingValue(const BasicBlock *BB) { + op_iterator Idx = find(Operands.begin(), Operands.end(), (const Value*)BB); + assert(Idx != Operands.end() && "BB not in PHI node!"); + --Idx; // Back up to value prior to Basic block + Value *Removed = *Idx; + Operands.erase(Idx, Idx+2); // Erase Value and BasicBlock return Removed; }