LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

InstrTypes.cpp

Go to the documentation of this file.
00001 //===-- InstrTypes.cpp - Implement Instruction subclasses -------*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements 
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Instructions.h"
00015 #include "llvm/Function.h"
00016 #include "llvm/SymbolTable.h"
00017 #include "llvm/Constant.h"
00018 #include "llvm/Type.h"
00019 #include <algorithm>  // find
00020 using namespace llvm;
00021 
00022 //===----------------------------------------------------------------------===//
00023 //                            TerminatorInst Class
00024 //===----------------------------------------------------------------------===//
00025 
00026 TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB) 
00027   : Instruction(Type::VoidTy, iType, "", IB) {
00028 }
00029 
00030 TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
00031   : Instruction(Type::VoidTy, iType, "", IAE) {
00032 }
00033 
00034 
00035 
00036 //===----------------------------------------------------------------------===//
00037 //                               PHINode Class
00038 //===----------------------------------------------------------------------===//
00039 
00040 PHINode::PHINode(const PHINode &PN)
00041   : Instruction(PN.getType(), Instruction::PHI) {
00042   Operands.reserve(PN.Operands.size());
00043   for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
00044     Operands.push_back(Use(PN.Operands[i], this));
00045     Operands.push_back(Use(PN.Operands[i+1], this));
00046   }
00047 }
00048 
00049 // removeIncomingValue - Remove an incoming value.  This is useful if a
00050 // predecessor basic block is deleted.
00051 Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
00052   assert(Idx*2 < Operands.size() && "BB not in PHI node!");
00053   Value *Removed = Operands[Idx*2];
00054   Operands.erase(Operands.begin()+Idx*2,     // Erase Value and BasicBlock
00055                  Operands.begin()+Idx*2+2);
00056 
00057   // If the PHI node is dead, because it has zero entries, nuke it now.
00058   if (getNumOperands() == 0 && DeletePHIIfEmpty) {
00059     // If anyone is using this PHI, make them use a dummy value instead...
00060     replaceAllUsesWith(Constant::getNullValue(getType()));
00061     getParent()->getInstList().erase(this);
00062   }
00063   return Removed;
00064 }