X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FInstrTypes.cpp;h=ff9d4059d24329ddf57df6e32a7e56838132cfff;hb=2fe6626eade0f21654b710023eec769f4dba6dc9;hp=9d3262cbda7209a70a66be854ce93ce75f63d56e;hpb=9f3d27654a9c60104c93cacc869709d5d30e5367;p=oota-llvm.git diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp index 9d3262cbda7..ff9d4059d24 100644 --- a/lib/VMCore/InstrTypes.cpp +++ b/lib/VMCore/InstrTypes.cpp @@ -1,56 +1,30 @@ -//===-- 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/Constant.h" #include "llvm/Type.h" #include // find -// TODO: Move to getUnaryOperator iUnary.cpp when and if it exists! -UnaryOperator *UnaryOperator::create(UnaryOps Op, Value *Source) { - switch (Op) { - default: - cerr << "Don't know how to GetUnaryOperator " << Op << endl; - return 0; - } -} - //===----------------------------------------------------------------------===// // TerminatorInst Class //===----------------------------------------------------------------------===// -TerminatorInst::TerminatorInst(unsigned iType) - : Instruction(Type::VoidTy, iType, "") { -} - - -//===----------------------------------------------------------------------===// -// 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); +TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB) + : Instruction(Type::VoidTy, iType, "", IB) { } - //===----------------------------------------------------------------------===// // 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) { Operands.reserve(PN.Operands.size()); for (unsigned i = 0; i < PN.Operands.size(); i+=2) { @@ -60,17 +34,27 @@ PHINode::PHINode(const PHINode &PN) } 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(const BasicBlock *BB) { +Value *PHINode::removeIncomingValue(const BasicBlock *BB, + bool DeletePHIIfEmpty) { 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 + + // If the PHI node is dead, because it has zero entries, nuke it now. + if (getNumOperands() == 0 && DeletePHIIfEmpty) { + // If anyone is using this PHI, make them use a dummy value instead... + replaceAllUsesWith(Constant::getNullValue(getType())); + getParent()->getInstList().erase(this); + } return Removed; }