mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-31 09:11:13 +00:00
a576e17ced
more tolerable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84 91177308-0d34-0410-b5e6-96231b3b80d8
158 lines
5.7 KiB
C++
158 lines
5.7 KiB
C++
//===-- 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"
|
|
#include "llvm/BasicBlock.h"
|
|
#include "llvm/ConstPoolVals.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 {
|
|
Use Val; // Will be null if returning void...
|
|
ReturnInst(const ReturnInst &RI);
|
|
public:
|
|
ReturnInst(Value *value = 0);
|
|
inline ~ReturnInst() { dropAllReferences(); }
|
|
|
|
virtual Instruction *clone() const { return new ReturnInst(*this); }
|
|
|
|
virtual string getOpcode() const { return "ret"; }
|
|
|
|
inline const Value *getReturnValue() const { return Val; }
|
|
inline Value *getReturnValue() { return Val; }
|
|
|
|
virtual void dropAllReferences();
|
|
virtual const Value *getOperand(unsigned i) const {
|
|
return (i == 0) ? Val : 0;
|
|
}
|
|
inline Value *getOperand(unsigned i) { return (i == 0) ? Val : 0; }
|
|
virtual bool setOperand(unsigned i, Value *Val);
|
|
virtual unsigned getNumOperands() const { return Val != 0; }
|
|
|
|
// Additionally, they must provide a method to get at the successors of this
|
|
// terminator instruction. If 'idx' is out of range, a null pointer shall be
|
|
// returned.
|
|
//
|
|
virtual const BasicBlock *getSuccessor(unsigned idx) const { return 0; }
|
|
virtual unsigned getNumSuccessors() const { return 0; }
|
|
};
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
// BranchInst - Conditional or Unconditional Branch instruction.
|
|
//
|
|
class BranchInst : public TerminatorInst {
|
|
BasicBlockUse TrueDest, FalseDest;
|
|
Use Condition;
|
|
|
|
BranchInst(const BranchInst &BI);
|
|
public:
|
|
// If cond = null, then is an unconditional br...
|
|
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse = 0, Value *cond = 0);
|
|
inline ~BranchInst() { dropAllReferences(); }
|
|
|
|
virtual Instruction *clone() const { return new BranchInst(*this); }
|
|
|
|
virtual void dropAllReferences();
|
|
|
|
inline const Value *getCondition() const { return Condition; }
|
|
inline Value *getCondition() { return Condition; }
|
|
|
|
inline bool isUnconditional() const {
|
|
return Condition == 0 || !FalseDest;
|
|
}
|
|
|
|
virtual string getOpcode() const { return "br"; }
|
|
|
|
inline Value *getOperand(unsigned i) {
|
|
return (Value*)((const BranchInst *)this)->getOperand(i);
|
|
}
|
|
virtual const Value *getOperand(unsigned i) const;
|
|
virtual bool setOperand(unsigned i, Value *Val);
|
|
virtual unsigned getNumOperands() const { return isUnconditional() ? 1 : 3; }
|
|
inline BasicBlock *getSuccessor(unsigned idx) {
|
|
return (BasicBlock*)((const BranchInst *)this)->getSuccessor(idx);
|
|
}
|
|
|
|
// Additionally, they must provide a method to get at the successors of this
|
|
// terminator instruction. If 'idx' is out of range, a null pointer shall be
|
|
// returned.
|
|
//
|
|
virtual const BasicBlock *getSuccessor(unsigned idx) const;
|
|
virtual unsigned getNumSuccessors() const { return 1+!isUnconditional(); }
|
|
};
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
// SwitchInst - Multiway switch
|
|
//
|
|
class SwitchInst : public TerminatorInst {
|
|
public:
|
|
typedef pair<ConstPoolUse, BasicBlockUse> dest_value;
|
|
private:
|
|
BasicBlockUse DefaultDest;
|
|
Use Val;
|
|
vector<dest_value> Destinations;
|
|
|
|
SwitchInst(const SwitchInst &RI);
|
|
public:
|
|
typedef vector<dest_value>::iterator dest_iterator;
|
|
typedef vector<dest_value>::const_iterator dest_const_iterator;
|
|
|
|
SwitchInst(Value *Value, BasicBlock *Default);
|
|
inline ~SwitchInst() { dropAllReferences(); }
|
|
|
|
virtual Instruction *clone() const { return new SwitchInst(*this); }
|
|
|
|
// Accessor Methods for Switch stmt
|
|
//
|
|
inline dest_iterator dest_begin() { return Destinations.begin(); }
|
|
inline dest_iterator dest_end () { return Destinations.end(); }
|
|
inline dest_const_iterator dest_begin() const { return Destinations.begin(); }
|
|
inline dest_const_iterator dest_end () const { return Destinations.end(); }
|
|
|
|
inline const Value *getCondition() const { return Val; }
|
|
inline Value *getCondition() { return Val; }
|
|
inline const BasicBlock *getDefaultDest() const { return DefaultDest; }
|
|
inline BasicBlock *getDefaultDest() { return DefaultDest; }
|
|
|
|
void dest_push_back(ConstPoolVal *OnVal, BasicBlock *Dest);
|
|
|
|
virtual string getOpcode() const { return "switch"; }
|
|
inline Value *getOperand(unsigned i) {
|
|
return (Value*)((const SwitchInst*)this)->getOperand(i);
|
|
}
|
|
virtual const Value *getOperand(unsigned i) const;
|
|
virtual bool setOperand(unsigned i, Value *Val);
|
|
virtual unsigned getNumOperands() const;
|
|
virtual void dropAllReferences();
|
|
|
|
// Additionally, they must provide a method to get at the successors of this
|
|
// terminator instruction. If 'idx' is out of range, a null pointer shall be
|
|
// returned.
|
|
//
|
|
virtual const BasicBlock *getSuccessor(unsigned idx) const;
|
|
virtual unsigned getNumSuccessors() const { return 1+Destinations.size(); }
|
|
inline BasicBlock *getSuccessor(unsigned idx) {
|
|
return (BasicBlock*)((const SwitchInst *)this)->getSuccessor(idx);
|
|
}
|
|
};
|
|
|
|
#endif
|