2001-06-06 20:29:01 +00:00
|
|
|
//===-- llvm/iTerminators.h - Termintator instruction nodes ------*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// This file contains the declarations for all the subclasses of the
|
|
|
|
// Instruction class, which is itself defined in the Instruction.h file. In
|
|
|
|
// between these definitions and the Instruction class are classes that expose
|
|
|
|
// the SSA properties of each instruction, and that form the SSA graph.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ITERMINATORS_H
|
|
|
|
#define LLVM_ITERMINATORS_H
|
|
|
|
|
|
|
|
#include "llvm/InstrTypes.h"
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Classes to represent Basic Block "Terminator" instructions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// ReturnInst - Return a value (possibly void), from a method. Execution does
|
|
|
|
// not continue in this method any longer.
|
|
|
|
//
|
|
|
|
class ReturnInst : public TerminatorInst {
|
2001-07-07 08:36:50 +00:00
|
|
|
ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret) {
|
|
|
|
if (RI.Operands.size()) {
|
|
|
|
assert(RI.Operands.size() == 1 && "Return insn can only have 1 operand!");
|
|
|
|
Operands.reserve(1);
|
|
|
|
Operands.push_back(Use(RI.Operands[0], this));
|
|
|
|
}
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2001-07-07 08:36:50 +00:00
|
|
|
ReturnInst(Value *RetVal = 0) : TerminatorInst(Instruction::Ret) {
|
|
|
|
if (RetVal) {
|
|
|
|
Operands.reserve(1);
|
|
|
|
Operands.push_back(Use(RetVal, this));
|
|
|
|
}
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
virtual Instruction *clone() const { return new ReturnInst(*this); }
|
|
|
|
|
2001-07-07 08:36:50 +00:00
|
|
|
inline const Value *getReturnValue() const {
|
2001-10-13 06:14:53 +00:00
|
|
|
return Operands.size() ? Operands[0].get() : 0;
|
2001-07-07 08:36:50 +00:00
|
|
|
}
|
|
|
|
inline Value *getReturnValue() {
|
2001-10-13 06:14:53 +00:00
|
|
|
return Operands.size() ? Operands[0].get() : 0;
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 03:14:12 +00:00
|
|
|
virtual const BasicBlock *getSuccessor(unsigned idx) const {
|
|
|
|
assert(0 && "ReturnInst has no successors!");
|
2002-05-10 18:53:21 +00:00
|
|
|
abort();
|
2002-04-27 03:14:12 +00:00
|
|
|
}
|
2002-05-23 15:48:41 +00:00
|
|
|
virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
|
|
|
assert(0 && "ReturnInst has no successors!");
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
virtual unsigned getNumSuccessors() const { return 0; }
|
2001-10-02 03:41:24 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const ReturnInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Ret);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// BranchInst - Conditional or Unconditional Branch instruction.
|
|
|
|
//
|
|
|
|
class BranchInst : public TerminatorInst {
|
|
|
|
BranchInst(const BranchInst &BI);
|
|
|
|
public:
|
|
|
|
// If cond = null, then is an unconditional br...
|
|
|
|
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse = 0, Value *cond = 0);
|
|
|
|
|
|
|
|
virtual Instruction *clone() const { return new BranchInst(*this); }
|
|
|
|
|
2002-04-27 03:14:12 +00:00
|
|
|
inline bool isUnconditional() const { return Operands.size() == 1; }
|
|
|
|
inline bool isConditional() const { return Operands.size() == 3; }
|
2001-07-07 08:36:50 +00:00
|
|
|
|
|
|
|
inline const Value *getCondition() const {
|
2001-10-13 06:14:53 +00:00
|
|
|
return isUnconditional() ? 0 : Operands[2].get();
|
2001-07-07 08:36:50 +00:00
|
|
|
}
|
|
|
|
inline Value *getCondition() {
|
2001-10-13 06:14:53 +00:00
|
|
|
return isUnconditional() ? 0 : Operands[2].get();
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2001-07-07 08:36:50 +00:00
|
|
|
// setUnconditionalDest - Change the current branch to an unconditional branch
|
|
|
|
// targeting the specified block.
|
|
|
|
//
|
|
|
|
void setUnconditionalDest(BasicBlock *Dest) {
|
2002-04-27 03:14:12 +00:00
|
|
|
if (isConditional()) Operands.erase(Operands.begin()+1, Operands.end());
|
2002-04-09 18:36:05 +00:00
|
|
|
Operands[0] = (Value*)Dest;
|
2001-07-07 08:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual const BasicBlock *getSuccessor(unsigned i) const {
|
2002-04-27 03:14:12 +00:00
|
|
|
assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
|
2002-04-09 18:36:05 +00:00
|
|
|
return (i == 0) ? cast<BasicBlock>(Operands[0].get()) :
|
2002-04-27 03:14:12 +00:00
|
|
|
cast<BasicBlock>(Operands[1].get());
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
2001-06-27 23:29:41 +00:00
|
|
|
inline BasicBlock *getSuccessor(unsigned idx) {
|
|
|
|
return (BasicBlock*)((const BranchInst *)this)->getSuccessor(idx);
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-05-23 15:48:41 +00:00
|
|
|
virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
|
|
|
assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
|
|
|
|
Operands[idx] = (Value*)NewSucc;
|
|
|
|
}
|
|
|
|
|
2002-04-27 03:14:12 +00:00
|
|
|
virtual unsigned getNumSuccessors() const { return 1+isConditional(); }
|
2001-10-02 03:41:24 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const BranchInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Br);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// SwitchInst - Multiway switch
|
|
|
|
//
|
|
|
|
class SwitchInst : public TerminatorInst {
|
2001-07-07 18:42:52 +00:00
|
|
|
// Operand[0] = Value to switch on
|
|
|
|
// Operand[1] = Default basic block destination
|
|
|
|
// Operand[2n ] = Value to match
|
|
|
|
// Operand[2n+1] = BasicBlock to go to on match
|
2001-06-06 20:29:01 +00:00
|
|
|
SwitchInst(const SwitchInst &RI);
|
|
|
|
public:
|
|
|
|
SwitchInst(Value *Value, BasicBlock *Default);
|
|
|
|
|
|
|
|
virtual Instruction *clone() const { return new SwitchInst(*this); }
|
|
|
|
|
2001-06-27 23:29:41 +00:00
|
|
|
// Accessor Methods for Switch stmt
|
|
|
|
//
|
2001-07-07 08:36:50 +00:00
|
|
|
inline const Value *getCondition() const { return Operands[0]; }
|
|
|
|
inline Value *getCondition() { return Operands[0]; }
|
|
|
|
inline const BasicBlock *getDefaultDest() const {
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<BasicBlock>(Operands[1].get());
|
2001-07-07 08:36:50 +00:00
|
|
|
}
|
|
|
|
inline BasicBlock *getDefaultDest() {
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<BasicBlock>(Operands[1].get());
|
2001-07-07 08:36:50 +00:00
|
|
|
}
|
2001-06-27 23:29:41 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
void dest_push_back(Constant *OnVal, BasicBlock *Dest);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-07-07 08:36:50 +00:00
|
|
|
virtual const BasicBlock *getSuccessor(unsigned idx) const {
|
2002-04-27 03:14:12 +00:00
|
|
|
assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<BasicBlock>(Operands[idx*2+1].get());
|
2001-07-07 08:36:50 +00:00
|
|
|
}
|
2001-06-27 23:29:41 +00:00
|
|
|
inline BasicBlock *getSuccessor(unsigned idx) {
|
2002-04-27 03:14:12 +00:00
|
|
|
assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<BasicBlock>(Operands[idx*2+1].get());
|
2001-07-07 08:36:50 +00:00
|
|
|
}
|
|
|
|
|
2002-05-23 15:48:41 +00:00
|
|
|
virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
|
|
|
assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
|
|
|
|
Operands[idx*2+1] = (Value*)NewSucc;
|
|
|
|
}
|
|
|
|
|
2001-07-07 18:42:52 +00:00
|
|
|
// getSuccessorValue - Return the value associated with the specified
|
2002-04-27 03:14:12 +00:00
|
|
|
// successor.
|
2001-12-03 22:26:30 +00:00
|
|
|
inline const Constant *getSuccessorValue(unsigned idx) const {
|
2001-07-07 08:36:50 +00:00
|
|
|
assert(idx < getNumSuccessors() && "Successor # out of range!");
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<Constant>(Operands[idx*2].get());
|
2001-07-07 08:36:50 +00:00
|
|
|
}
|
2001-12-03 22:26:30 +00:00
|
|
|
inline Constant *getSuccessorValue(unsigned idx) {
|
2001-07-07 08:36:50 +00:00
|
|
|
assert(idx < getNumSuccessors() && "Successor # out of range!");
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<Constant>(Operands[idx*2].get());
|
2001-06-27 23:29:41 +00:00
|
|
|
}
|
2001-07-07 08:36:50 +00:00
|
|
|
virtual unsigned getNumSuccessors() const { return Operands.size()/2; }
|
2001-10-02 03:41:24 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SwitchInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Switch);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2001-10-13 06:14:53 +00:00
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// InvokeInst - Invoke instruction
|
|
|
|
//
|
|
|
|
class InvokeInst : public TerminatorInst {
|
|
|
|
InvokeInst(const InvokeInst &BI);
|
|
|
|
public:
|
|
|
|
InvokeInst(Value *Meth, BasicBlock *IfNormal, BasicBlock *IfException,
|
2002-01-20 22:54:45 +00:00
|
|
|
const std::vector<Value*> &Params, const std::string &Name = "");
|
2001-10-13 06:14:53 +00:00
|
|
|
|
|
|
|
virtual Instruction *clone() const { return new InvokeInst(*this); }
|
|
|
|
|
2002-05-14 04:20:25 +00:00
|
|
|
bool hasSideEffects() const { return true; }
|
|
|
|
|
2002-03-29 17:08:01 +00:00
|
|
|
// getCalledFunction - Return the function called, or null if this is an
|
|
|
|
// indirect function invocation...
|
2001-10-13 06:14:53 +00:00
|
|
|
//
|
2002-03-29 17:08:01 +00:00
|
|
|
inline const Function *getCalledFunction() const {
|
2002-03-23 22:51:58 +00:00
|
|
|
return dyn_cast<Function>(Operands[0].get());
|
2001-10-13 06:14:53 +00:00
|
|
|
}
|
2002-04-08 22:03:57 +00:00
|
|
|
inline Function *getCalledFunction() {
|
|
|
|
return dyn_cast<Function>(Operands[0].get());
|
2001-10-13 06:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getCalledValue - Get a pointer to a method that is invoked by this inst.
|
|
|
|
inline const Value *getCalledValue() const { return Operands[0]; }
|
|
|
|
inline Value *getCalledValue() { return Operands[0]; }
|
|
|
|
|
|
|
|
// get*Dest - Return the destination basic blocks...
|
|
|
|
inline const BasicBlock *getNormalDest() const {
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<BasicBlock>(Operands[1].get());
|
2001-10-13 06:14:53 +00:00
|
|
|
}
|
|
|
|
inline BasicBlock *getNormalDest() {
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<BasicBlock>(Operands[1].get());
|
2001-10-13 06:14:53 +00:00
|
|
|
}
|
|
|
|
inline const BasicBlock *getExceptionalDest() const {
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<BasicBlock>(Operands[2].get());
|
2001-10-13 06:14:53 +00:00
|
|
|
}
|
|
|
|
inline BasicBlock *getExceptionalDest() {
|
2002-04-09 18:36:05 +00:00
|
|
|
return cast<BasicBlock>(Operands[2].get());
|
2001-10-13 06:14:53 +00:00
|
|
|
}
|
|
|
|
|
2002-06-25 20:17:40 +00:00
|
|
|
inline void setNormalDest(BasicBlock *B){
|
|
|
|
Operands[1] = (Value*)B;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setExceptionalDest(BasicBlock *B){
|
|
|
|
Operands[2] = (Value*)B;
|
|
|
|
}
|
|
|
|
|
2001-10-13 06:14:53 +00:00
|
|
|
virtual const BasicBlock *getSuccessor(unsigned i) const {
|
2002-04-27 03:14:12 +00:00
|
|
|
assert(i < 2 && "Successor # out of range for invoke!");
|
|
|
|
return i == 0 ? getNormalDest() : getExceptionalDest();
|
2001-10-13 06:14:53 +00:00
|
|
|
}
|
|
|
|
inline BasicBlock *getSuccessor(unsigned i) {
|
2002-04-27 03:14:12 +00:00
|
|
|
assert(i < 2 && "Successor # out of range for invoke!");
|
|
|
|
return i == 0 ? getNormalDest() : getExceptionalDest();
|
2001-10-13 06:14:53 +00:00
|
|
|
}
|
|
|
|
|
2002-05-23 15:48:41 +00:00
|
|
|
virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
|
|
|
assert(idx < 2 && "Successor # out of range for invoke!");
|
|
|
|
Operands[idx+1] = (Value*)NewSucc;
|
|
|
|
}
|
|
|
|
|
2001-10-13 06:14:53 +00:00
|
|
|
virtual unsigned getNumSuccessors() const { return 2; }
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const InvokeInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Invoke);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|