2001-12-03 19:02:31 +01:00
|
|
|
//===-- llvm/iPHINode.h - PHI instruction definition -------------*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// This file defines the PHINode class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_IPHINODE_H
|
|
|
|
#define LLVM_IPHINODE_H
|
|
|
|
|
|
|
|
#include "llvm/Instruction.h"
|
|
|
|
class BasicBlock;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PHINode Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// PHINode - The PHINode class is used to represent the magical mystical PHI
|
|
|
|
// node, that can not exist in nature, but can be synthesized in a computer
|
|
|
|
// scientist's overactive imagination.
|
|
|
|
//
|
|
|
|
class PHINode : public Instruction {
|
|
|
|
PHINode(const PHINode &PN);
|
|
|
|
public:
|
2002-09-10 17:36:11 +02:00
|
|
|
PHINode(const Type *Ty, const std::string &Name = "",
|
|
|
|
Instruction *InsertBefore = 0)
|
|
|
|
: Instruction(Ty, Instruction::PHINode, Name, InsertBefore) {
|
|
|
|
}
|
2001-12-03 19:02:31 +01:00
|
|
|
|
|
|
|
virtual Instruction *clone() const { return new PHINode(*this); }
|
|
|
|
|
2002-09-10 17:36:11 +02:00
|
|
|
/// getNumIncomingValues - Return the number of incoming edges the PHI node
|
|
|
|
/// has
|
|
|
|
unsigned getNumIncomingValues() const { return Operands.size()/2; }
|
2001-12-03 19:02:31 +01:00
|
|
|
|
2002-09-10 17:36:11 +02:00
|
|
|
/// getIncomingValue - Return incoming value #x
|
|
|
|
const Value *getIncomingValue(unsigned i) const {
|
2001-12-03 19:02:31 +01:00
|
|
|
return Operands[i*2];
|
|
|
|
}
|
2002-09-10 17:36:11 +02:00
|
|
|
Value *getIncomingValue(unsigned i) {
|
2001-12-03 19:02:31 +01:00
|
|
|
return Operands[i*2];
|
|
|
|
}
|
2002-09-10 17:36:11 +02:00
|
|
|
void setIncomingValue(unsigned i, Value *V) {
|
2001-12-03 19:02:31 +01:00
|
|
|
Operands[i*2] = V;
|
|
|
|
}
|
2002-09-16 18:06:12 +02:00
|
|
|
inline unsigned getOperandNumForIncomingValue(unsigned i) {
|
|
|
|
return i*2;
|
|
|
|
}
|
2001-12-03 19:02:31 +01:00
|
|
|
|
2002-09-10 17:36:11 +02:00
|
|
|
/// getIncomingBlock - Return incoming basic block #x
|
|
|
|
const BasicBlock *getIncomingBlock(unsigned i) const {
|
2001-12-03 19:02:31 +01:00
|
|
|
return (const BasicBlock*)Operands[i*2+1].get();
|
|
|
|
}
|
|
|
|
inline BasicBlock *getIncomingBlock(unsigned i) {
|
|
|
|
return (BasicBlock*)Operands[i*2+1].get();
|
|
|
|
}
|
|
|
|
inline void setIncomingBlock(unsigned i, BasicBlock *BB) {
|
|
|
|
Operands[i*2+1] = (Value*)BB;
|
|
|
|
}
|
2002-09-16 18:06:12 +02:00
|
|
|
inline unsigned getOperandNumForIncomingBlock(unsigned i) {
|
|
|
|
return i*2+1;
|
|
|
|
}
|
2001-12-03 19:02:31 +01:00
|
|
|
|
2002-09-10 17:36:11 +02:00
|
|
|
/// addIncoming - Add an incoming value to the end of the PHI list
|
2001-12-03 19:02:31 +01:00
|
|
|
void addIncoming(Value *D, BasicBlock *BB);
|
2002-09-10 17:36:11 +02:00
|
|
|
|
|
|
|
/// removeIncomingValue - Remove an incoming value. This is useful if a
|
|
|
|
/// predecessor basic block is deleted. The value removed is returned.
|
2002-10-08 23:31:56 +02:00
|
|
|
///
|
|
|
|
/// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
|
|
|
|
/// is true), the PHI node is destroyed and any uses of it are replaced with
|
|
|
|
/// dummy values. The only time there should be zero incoming values to a PHI
|
|
|
|
/// node is when the block is dead, so this strategy is sound.
|
|
|
|
///
|
|
|
|
Value *removeIncomingValue(const BasicBlock *BB,
|
|
|
|
bool DeletePHIIfEmpty = true);
|
2001-12-03 19:02:31 +01:00
|
|
|
|
2002-09-10 17:36:11 +02:00
|
|
|
/// getBasicBlockIndex - Return the first index of the specified basic
|
|
|
|
/// block in the value list for this PHI. Returns -1 if no instance.
|
|
|
|
///
|
2001-12-03 19:02:31 +01:00
|
|
|
int getBasicBlockIndex(const BasicBlock *BB) const {
|
|
|
|
for (unsigned i = 0; i < Operands.size()/2; ++i)
|
|
|
|
if (getIncomingBlock(i) == BB) return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-09-10 17:36:11 +02:00
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2001-12-03 19:02:31 +01:00
|
|
|
static inline bool classof(const PHINode *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::PHINode;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|