Interface to target-specific routines that support machine code optimization.
[oota-llvm.git] / include / llvm / iOther.h
1 //===-- llvm/iOther.h - "Other" instruction node definitions -----*- C++ -*--=//
2 //
3 // This file contains the declarations for instructions that fall into the 
4 // grandiose 'other' catagory...
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_IOTHER_H
9 #define LLVM_IOTHER_H
10
11 #include "llvm/InstrTypes.h"
12
13 //===----------------------------------------------------------------------===//
14 //                                 CastInst Class
15 //===----------------------------------------------------------------------===//
16
17 /// CastInst - This class represents a cast from Operand[0] to the type of
18 /// the instruction (i->getType()).
19 ///
20 class CastInst : public Instruction {
21   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
22     Operands.reserve(1);
23     Operands.push_back(Use(CI.Operands[0], this));
24   }
25 public:
26   CastInst(Value *S, const Type *Ty, const std::string &Name = "",
27            Instruction *InsertBefore = 0)
28     : Instruction(Ty, Cast, Name, InsertBefore) {
29     Operands.reserve(1);
30     Operands.push_back(Use(S, this));
31   }
32
33   virtual Instruction *clone() const { return new CastInst(*this); }
34
35   // Methods for support type inquiry through isa, cast, and dyn_cast:
36   static inline bool classof(const CastInst *) { return true; }
37   static inline bool classof(const Instruction *I) {
38     return I->getOpcode() == Cast;
39   }
40   static inline bool classof(const Value *V) {
41     return isa<Instruction>(V) && classof(cast<Instruction>(V));
42   }
43 };
44
45
46 //===----------------------------------------------------------------------===//
47 //                                 CallInst Class
48 //===----------------------------------------------------------------------===//
49
50 class CallInst : public Instruction {
51   CallInst(const CallInst &CI);
52 public:
53   CallInst(Value *F, const std::vector<Value*> &Par,
54            const std::string &Name = "", Instruction *InsertBefore = 0);
55
56   virtual Instruction *clone() const { return new CallInst(*this); }
57   bool hasSideEffects() const { return true; }
58
59   const Function *getCalledFunction() const {
60     return dyn_cast<Function>(Operands[0].get());
61   }
62   Function *getCalledFunction() {
63     return dyn_cast<Function>(Operands[0].get());
64   }
65
66   // getCalledValue - Get a pointer to a method that is invoked by this inst.
67   inline const Value *getCalledValue() const { return Operands[0]; }
68   inline       Value *getCalledValue()       { return Operands[0]; }
69
70   // Methods for support type inquiry through isa, cast, and dyn_cast:
71   static inline bool classof(const CallInst *) { return true; }
72   static inline bool classof(const Instruction *I) {
73     return I->getOpcode() == Instruction::Call; 
74   }
75   static inline bool classof(const Value *V) {
76     return isa<Instruction>(V) && classof(cast<Instruction>(V));
77   }
78 };
79
80
81 //===----------------------------------------------------------------------===//
82 //                                 ShiftInst Class
83 //===----------------------------------------------------------------------===//
84
85 // ShiftInst - This class represents left and right shift instructions.
86 //
87 class ShiftInst : public Instruction {
88   ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
89     Operands.reserve(2);
90     Operands.push_back(Use(SI.Operands[0], this));
91     Operands.push_back(Use(SI.Operands[1], this));
92   }
93 public:
94   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
95             Instruction *InsertBefore = 0)
96     : Instruction(S->getType(), Opcode, Name, InsertBefore) {
97     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
98     Operands.reserve(2);
99     Operands.push_back(Use(S, this));
100     Operands.push_back(Use(SA, this));
101   }
102
103   OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
104
105   virtual Instruction *clone() const { return new ShiftInst(*this); }
106
107   // Methods for support type inquiry through isa, cast, and dyn_cast:
108   static inline bool classof(const ShiftInst *) { return true; }
109   static inline bool classof(const Instruction *I) {
110     return (I->getOpcode() == Instruction::Shr) | 
111            (I->getOpcode() == Instruction::Shl);
112   }
113   static inline bool classof(const Value *V) {
114     return isa<Instruction>(V) && classof(cast<Instruction>(V));
115   }
116 };
117
118 #endif