1 //===-- llvm/iOther.h - "Other" instruction node definitions -----*- C++ -*--=//
3 // This file contains the declarations for instructions that fall into the
4 // grandios 'other' catagory...
6 //===----------------------------------------------------------------------===//
11 #include "llvm/InstrTypes.h"
12 #include "llvm/Function.h"
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
18 // CastInst - This class represents a cast from Operand[0] to the type of
19 // the instruction (i->getType()).
21 class CastInst : public Instruction {
22 CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
24 Operands.push_back(Use(CI.Operands[0], this));
27 CastInst(Value *S, const Type *Ty, const std::string &Name = "")
28 : Instruction(Ty, Cast, Name) {
30 Operands.push_back(Use(S, this));
33 virtual Instruction *clone() const { return new CastInst(*this); }
34 virtual const char *getOpcodeName() const { return "cast"; }
36 // Methods for support type inquiry through isa, cast, and dyn_cast:
37 static inline bool classof(const CastInst *) { return true; }
38 static inline bool classof(const Instruction *I) {
39 return I->getOpcode() == Cast;
41 static inline bool classof(const Value *V) {
42 return isa<Instruction>(V) && classof(cast<Instruction>(V));
47 //===----------------------------------------------------------------------===//
48 // FunctionArgument Class
49 //===----------------------------------------------------------------------===//
51 class FunctionArgument : public Value { // Defined in the InstrType.cpp file
54 friend class ValueHolder<FunctionArgument,Function,Function>;
55 inline void setParent(Function *parent) { Parent = parent; }
58 FunctionArgument(const Type *Ty, const std::string &Name = "")
59 : Value(Ty, Value::FunctionArgumentVal, Name) {
63 // Specialize setName to handle symbol table majik...
64 virtual void setName(const std::string &name, SymbolTable *ST = 0);
66 inline const Function *getParent() const { return Parent; }
67 inline Function *getParent() { return Parent; }
69 virtual void print(std::ostream &OS) const;
71 // Methods for support type inquiry through isa, cast, and dyn_cast:
72 static inline bool classof(const FunctionArgument *) { return true; }
73 static inline bool classof(const Value *V) {
74 return V->getValueType() == FunctionArgumentVal;
79 //===----------------------------------------------------------------------===//
80 // Classes to function calls and method invocations
81 //===----------------------------------------------------------------------===//
83 class CallInst : public Instruction {
84 CallInst(const CallInst &CI);
86 CallInst(Value *M, const std::vector<Value*> &Par, const std::string & = "");
88 virtual const char *getOpcodeName() const { return "call"; }
90 virtual Instruction *clone() const { return new CallInst(*this); }
91 bool hasSideEffects() const { return true; }
93 const Function *getCalledFunction() const {
94 return dyn_cast<Function>(Operands[0]);
96 Function *getCalledFunction() {
97 return dyn_cast<Function>(Operands[0]);
100 // getCalledValue - Get a pointer to a method that is invoked by this inst.
101 inline const Value *getCalledValue() const { return Operands[0]; }
102 inline Value *getCalledValue() { return Operands[0]; }
104 // Methods for support type inquiry through isa, cast, and dyn_cast:
105 static inline bool classof(const CallInst *) { return true; }
106 static inline bool classof(const Instruction *I) {
107 return I->getOpcode() == Instruction::Call;
109 static inline bool classof(const Value *V) {
110 return isa<Instruction>(V) && classof(cast<Instruction>(V));
115 //===----------------------------------------------------------------------===//
117 //===----------------------------------------------------------------------===//
119 // ShiftInst - This class represents left and right shift instructions.
121 class ShiftInst : public Instruction {
122 ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
124 Operands.push_back(Use(SI.Operands[0], this));
125 Operands.push_back(Use(SI.Operands[1], this));
128 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "")
129 : Instruction(S->getType(), Opcode, Name) {
130 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
132 Operands.push_back(Use(S, this));
133 Operands.push_back(Use(SA, this));
136 OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
138 virtual Instruction *clone() const { return new ShiftInst(*this); }
139 virtual const char *getOpcodeName() const {
140 return getOpcode() == Shl ? "shl" : "shr";
143 // Methods for support type inquiry through isa, cast, and dyn_cast:
144 static inline bool classof(const ShiftInst *) { return true; }
145 static inline bool classof(const Instruction *I) {
146 return (I->getOpcode() == Instruction::Shr) |
147 (I->getOpcode() == Instruction::Shl);
149 static inline bool classof(const Value *V) {
150 return isa<Instruction>(V) && classof(cast<Instruction>(V));