1 //===-- InstrTypes.cpp - Implement Instruction subclasses -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements
12 //===----------------------------------------------------------------------===//
14 #include "llvm/iOther.h"
15 #include "llvm/iPHINode.h"
16 #include "llvm/Function.h"
17 #include "llvm/SymbolTable.h"
18 #include "llvm/Constant.h"
19 #include "llvm/Type.h"
20 #include <algorithm> // find
23 //===----------------------------------------------------------------------===//
24 // TerminatorInst Class
25 //===----------------------------------------------------------------------===//
27 TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB)
28 : Instruction(Type::VoidTy, iType, "", IB) {
31 TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
32 : Instruction(Type::VoidTy, iType) {
33 if (IAE) IAE->getInstList().push_back(this);
38 //===----------------------------------------------------------------------===//
40 //===----------------------------------------------------------------------===//
42 PHINode::PHINode(const PHINode &PN)
43 : Instruction(PN.getType(), Instruction::PHI) {
44 Operands.reserve(PN.Operands.size());
45 for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
46 Operands.push_back(Use(PN.Operands[i], this));
47 Operands.push_back(Use(PN.Operands[i+1], this));
51 // removeIncomingValue - Remove an incoming value. This is useful if a
52 // predecessor basic block is deleted.
53 Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
54 assert(Idx*2 < Operands.size() && "BB not in PHI node!");
55 Value *Removed = Operands[Idx*2];
56 Operands.erase(Operands.begin()+Idx*2, // Erase Value and BasicBlock
57 Operands.begin()+Idx*2+2);
59 // If the PHI node is dead, because it has zero entries, nuke it now.
60 if (getNumOperands() == 0 && DeletePHIIfEmpty) {
61 // If anyone is using this PHI, make them use a dummy value instead...
62 replaceAllUsesWith(Constant::getNullValue(getType()));
63 getParent()->getInstList().erase(this);