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, "", IAE) {
37 //===----------------------------------------------------------------------===//
39 //===----------------------------------------------------------------------===//
41 PHINode::PHINode(const PHINode &PN)
42 : Instruction(PN.getType(), Instruction::PHI) {
43 Operands.reserve(PN.Operands.size());
44 for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
45 Operands.push_back(Use(PN.Operands[i], this));
46 Operands.push_back(Use(PN.Operands[i+1], this));
50 // removeIncomingValue - Remove an incoming value. This is useful if a
51 // predecessor basic block is deleted.
52 Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
53 assert(Idx*2 < Operands.size() && "BB not in PHI node!");
54 Value *Removed = Operands[Idx*2];
55 Operands.erase(Operands.begin()+Idx*2, // Erase Value and BasicBlock
56 Operands.begin()+Idx*2+2);
58 // If the PHI node is dead, because it has zero entries, nuke it now.
59 if (getNumOperands() == 0 && DeletePHIIfEmpty) {
60 // If anyone is using this PHI, make them use a dummy value instead...
61 replaceAllUsesWith(Constant::getNullValue(getType()));
62 getParent()->getInstList().erase(this);