X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FInstrTypes.cpp;h=aa5c3514e25417afdc04a3b4abffe74f52e5d491;hb=8b29776d680f1b80b7471291b7d41df753d28511;hp=a4c82126323047803bd0f2c3e66cdc678cfdf950;hpb=697954c15da58bd8b186dbafdedd8b06db770201;p=oota-llvm.git diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp index a4c82126323..aa5c3514e25 100644 --- a/lib/VMCore/InstrTypes.cpp +++ b/lib/VMCore/InstrTypes.cpp @@ -1,4 +1,11 @@ -//===-- InstrTypes.cpp - Implement Instruction subclasses --------*- C++ -*--=// +//===-- InstrTypes.cpp - Implement Instruction subclasses -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by the LLVM research group and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// // // This file implements // @@ -6,51 +13,33 @@ #include "llvm/iOther.h" #include "llvm/iPHINode.h" -#include "llvm/BasicBlock.h" -#include "llvm/Method.h" +#include "llvm/Function.h" #include "llvm/SymbolTable.h" +#include "llvm/Constant.h" #include "llvm/Type.h" #include // find +using namespace llvm; //===----------------------------------------------------------------------===// // TerminatorInst Class //===----------------------------------------------------------------------===// -TerminatorInst::TerminatorInst(Instruction::TermOps iType) - : Instruction(Type::VoidTy, iType, "") { +TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB) + : Instruction(Type::VoidTy, iType, "", IB) { } -TerminatorInst::TerminatorInst(const Type *Ty, Instruction::TermOps iType, - const std::string &Name = "") - : Instruction(Ty, iType, Name) { +TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE) + : Instruction(Type::VoidTy, iType, "", IAE) { } -//===----------------------------------------------------------------------===// -// MethodArgument Class -//===----------------------------------------------------------------------===// - -// Specialize setName to take care of symbol table majik -void MethodArgument::setName(const std::string &name, SymbolTable *ST) { - Method *P; - assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) && - "Invalid symtab argument!"); - 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 std::string &name) - : Instruction(Ty, Instruction::PHINode, name) { -} - -PHINode::PHINode(const PHINode &PN) - : Instruction(PN.getType(), Instruction::PHINode) { +PHINode::PHINode(const PHINode &PN) + : Instruction(PN.getType(), Instruction::PHI) { Operands.reserve(PN.Operands.size()); for (unsigned i = 0; i < PN.Operands.size(); i+=2) { Operands.push_back(Use(PN.Operands[i], this)); @@ -58,18 +47,19 @@ PHINode::PHINode(const PHINode &PN) } } -void PHINode::addIncoming(Value *D, BasicBlock *BB) { - 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) { - 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 +Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) { + assert(Idx*2 < Operands.size() && "BB not in PHI node!"); + Value *Removed = Operands[Idx*2]; + Operands.erase(Operands.begin()+Idx*2, // Erase Value and BasicBlock + Operands.begin()+Idx*2+2); + + // 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; }