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/Instructions.h"
15 #include "llvm/Function.h"
16 #include "llvm/SymbolTable.h"
17 #include "llvm/Constant.h"
18 #include "llvm/Type.h"
19 #include <algorithm> // find
22 //===----------------------------------------------------------------------===//
23 // TerminatorInst Class
24 //===----------------------------------------------------------------------===//
26 TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB)
27 : Instruction(Type::VoidTy, iType, "", IB) {
30 TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
31 : Instruction(Type::VoidTy, iType, "", IAE) {
36 //===----------------------------------------------------------------------===//
38 //===----------------------------------------------------------------------===//
40 PHINode::PHINode(const PHINode &PN)
41 : Instruction(PN.getType(), Instruction::PHI) {
42 Operands.reserve(PN.Operands.size());
43 for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
44 Operands.push_back(Use(PN.Operands[i], this));
45 Operands.push_back(Use(PN.Operands[i+1], this));
49 // removeIncomingValue - Remove an incoming value. This is useful if a
50 // predecessor basic block is deleted.
51 Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
52 assert(Idx*2 < Operands.size() && "BB not in PHI node!");
53 Value *Removed = Operands[Idx*2];
54 Operands.erase(Operands.begin()+Idx*2, // Erase Value and BasicBlock
55 Operands.begin()+Idx*2+2);
57 // If the PHI node is dead, because it has zero entries, nuke it now.
58 if (getNumOperands() == 0 && DeletePHIIfEmpty) {
59 // If anyone is using this PHI, make them use a dummy value instead...
60 replaceAllUsesWith(Constant::getNullValue(getType()));
61 getParent()->getInstList().erase(this);