2002-09-10 15:45:53 +00:00
|
|
|
//===-- InstrTypes.cpp - Implement Instruction subclasses -------*- C++ -*-===//
|
2003-10-20 19:43:21 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
// This file implements
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-07-29 17:30:56 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2002-03-26 18:01:55 +00:00
|
|
|
#include "llvm/Function.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/SymbolTable.h"
|
2002-10-08 21:34:58 +00:00
|
|
|
#include "llvm/Constant.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/Type.h"
|
2001-07-07 08:36:50 +00:00
|
|
|
#include <algorithm> // find
|
2003-11-20 17:45:12 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TerminatorInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-09-10 15:45:53 +00:00
|
|
|
TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB)
|
|
|
|
: Instruction(Type::VoidTy, iType, "", IB) {
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2003-11-20 17:45:12 +00:00
|
|
|
TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
|
2004-05-26 21:41:09 +00:00
|
|
|
: Instruction(Type::VoidTy, iType, "", IAE) {
|
2003-11-20 17:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PHINode Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-09-10 15:45:53 +00:00
|
|
|
PHINode::PHINode(const PHINode &PN)
|
2003-10-19 21:34:28 +00:00
|
|
|
: Instruction(PN.getType(), Instruction::PHI) {
|
2001-07-07 08:36:50 +00:00
|
|
|
Operands.reserve(PN.Operands.size());
|
|
|
|
for (unsigned i = 0; i < PN.Operands.size(); i+=2) {
|
|
|
|
Operands.push_back(Use(PN.Operands[i], this));
|
|
|
|
Operands.push_back(Use(PN.Operands[i+1], this));
|
2001-06-11 15:04:40 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2001-06-07 16:59:37 +00:00
|
|
|
// removeIncomingValue - Remove an incoming value. This is useful if a
|
|
|
|
// predecessor basic block is deleted.
|
2003-03-05 21:15:12 +00:00
|
|
|
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);
|
2002-10-08 21:34:58 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2001-06-07 16:59:37 +00:00
|
|
|
return Removed;
|
|
|
|
}
|