1 //===-- llvm/InstrinsicInst.h - Intrinsic Instruction Wrappers --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines classes that make it really easy to deal with intrinsic
11 // functions with the isa/dyncast family of functions. In particular, this
12 // allows you to do things like:
14 // if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst))
15 // ... MCI->getDest() ... MCI->getSource() ...
17 // All intrinsic function calls are instances of the call instruction, so these
18 // are all subclasses of the CallInst class. Note that none of these classes
19 // has state or virtual methods, which is an important part of this gross/neat
22 //===----------------------------------------------------------------------===//
24 #ifndef LLVM_INTRINSICINST_H
25 #define LLVM_INTRINSICINST_H
27 #include "llvm/Constants.h"
28 #include "llvm/Function.h"
29 #include "llvm/Instructions.h"
30 #include "llvm/Intrinsics.h"
33 class IntrinsicInst : public CallInst {
34 IntrinsicInst(); // DO NOT IMPLEMENT
35 IntrinsicInst(const IntrinsicInst&); // DO NOT IMPLEMENT
36 void operator=(const IntrinsicInst&); // DO NOT IMPLEMENT
39 /// StripPointerCasts - This static method strips off any unneeded pointer
40 /// casts from the specified value, returning the original uncasted value.
41 /// Note that the returned value is guaranteed to have pointer type.
42 static Value *StripPointerCasts(Value *Ptr);
45 /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
47 struct DbgInfoIntrinsic : public IntrinsicInst {
49 Value *getChain() const { return const_cast<Value*>(getOperand(1)); }
51 // Methods for support type inquiry through isa, cast, and dyn_cast:
52 static inline bool classof(const DbgInfoIntrinsic *) { return true; }
53 static inline bool classof(const CallInst *I) {
54 if (const Function *CF = I->getCalledFunction())
55 switch (CF->getIntrinsicID()) {
56 case Intrinsic::dbg_stoppoint:
57 case Intrinsic::dbg_region_start:
58 case Intrinsic::dbg_region_end:
59 case Intrinsic::dbg_func_start:
60 case Intrinsic::dbg_declare:
66 static inline bool classof(const Value *V) {
67 return isa<CallInst>(V) && classof(cast<CallInst>(V));
72 /// DbgStopPointInst - This represent llvm.dbg.stoppoint instructions.
74 struct DbgStopPointInst : public DbgInfoIntrinsic {
76 unsigned getLineNo() const {
77 return unsigned(cast<ConstantInt>(getOperand(2))->getRawValue());
79 unsigned getColNo() const {
80 return unsigned(cast<ConstantInt>(getOperand(3))->getRawValue());
82 Value *getContext() const { return const_cast<Value*>(getOperand(4)); }
85 // Methods for support type inquiry through isa, cast, and dyn_cast:
86 static inline bool classof(const DbgStopPointInst *) { return true; }
87 static inline bool classof(const CallInst *I) {
88 if (const Function *CF = I->getCalledFunction())
89 return CF->getIntrinsicID() == Intrinsic::dbg_stoppoint;
92 static inline bool classof(const Value *V) {
93 return isa<CallInst>(V) && classof(cast<CallInst>(V));
97 /// MemIntrinsic - This is the common base class for memset/memcpy/memmove.
99 struct MemIntrinsic : public IntrinsicInst {
100 Value *getRawDest() const { return const_cast<Value*>(getOperand(1)); }
102 Value *getLength() const { return const_cast<Value*>(getOperand(3)); }
103 ConstantInt *getAlignment() const {
104 return cast<ConstantInt>(const_cast<Value*>(getOperand(4)));
107 /// getDest - This is just like getRawDest, but it strips off any cast
108 /// instructions that feed it, giving the original input. The returned
109 /// value is guaranteed to be a pointer.
110 Value *getDest() const { return StripPointerCasts(getRawDest()); }
112 /// set* - Set the specified arguments of the instruction.
114 void setDest(Value *Ptr) {
115 assert(getRawDest()->getType() == Ptr->getType() &&
116 "setDest called with pointer of wrong type!");
120 void setLength(Value *L) {
121 assert(getLength()->getType() == L->getType() &&
122 "setLength called with value of wrong type!");
125 void setAlignment(ConstantInt *A) {
126 assert(getAlignment()->getType() == A->getType() &&
127 "setAlignment called with value of wrong type!");
131 // Methods for support type inquiry through isa, cast, and dyn_cast:
132 static inline bool classof(const MemIntrinsic *) { return true; }
133 static inline bool classof(const CallInst *I) {
134 if (const Function *CF = I->getCalledFunction())
135 switch (CF->getIntrinsicID()) {
136 case Intrinsic::memcpy:
137 case Intrinsic::memmove:
138 case Intrinsic::memset:
144 static inline bool classof(const Value *V) {
145 return isa<CallInst>(V) && classof(cast<CallInst>(V));
150 /// MemCpyInst - This class wraps the llvm.memcpy intrinsic.
152 struct MemCpyInst : public MemIntrinsic {
153 /// get* - Return the arguments to the instruction.
155 Value *getRawSource() const { return const_cast<Value*>(getOperand(2)); }
157 /// getSource - This is just like getRawSource, but it strips off any cast
158 /// instructions that feed it, giving the original input. The returned
159 /// value is guaranteed to be a pointer.
160 Value *getSource() const { return StripPointerCasts(getRawSource()); }
163 void setSource(Value *Ptr) {
164 assert(getRawSource()->getType() == Ptr->getType() &&
165 "setSource called with pointer of wrong type!");
169 // Methods for support type inquiry through isa, cast, and dyn_cast:
170 static inline bool classof(const MemCpyInst *) { return true; }
171 static inline bool classof(const MemIntrinsic *I) {
172 return I->getCalledFunction()->getIntrinsicID() == Intrinsic::memcpy;
174 static inline bool classof(const CallInst *I) {
175 if (const Function *CF = I->getCalledFunction())
176 if (CF->getIntrinsicID() == Intrinsic::memcpy)
180 static inline bool classof(const Value *V) {
181 return isa<CallInst>(V) && classof(cast<CallInst>(V));
185 /// MemMoveInst - This class wraps the llvm.memmove intrinsic.
187 struct MemMoveInst : public MemIntrinsic {
188 /// get* - Return the arguments to the instruction.
190 Value *getRawSource() const { return const_cast<Value*>(getOperand(2)); }
192 /// getSource - This is just like getRawSource, but it strips off any cast
193 /// instructions that feed it, giving the original input. The returned
194 /// value is guaranteed to be a pointer.
195 Value *getSource() const { return StripPointerCasts(getRawSource()); }
197 void setSource(Value *Ptr) {
198 assert(getRawSource()->getType() == Ptr->getType() &&
199 "setSource called with pointer of wrong type!");
203 // Methods for support type inquiry through isa, cast, and dyn_cast:
204 static inline bool classof(const MemMoveInst *) { return true; }
205 static inline bool classof(const MemIntrinsic *I) {
206 return I->getCalledFunction()->getIntrinsicID() == Intrinsic::memmove;
208 static inline bool classof(const CallInst *I) {
209 if (const Function *CF = I->getCalledFunction())
210 if (CF->getIntrinsicID() == Intrinsic::memmove)
214 static inline bool classof(const Value *V) {
215 return isa<CallInst>(V) && classof(cast<CallInst>(V));
219 /// MemSetInst - This class wraps the llvm.memcpy intrinsic.
221 struct MemSetInst : public MemIntrinsic {
222 /// get* - Return the arguments to the instruction.
224 Value *getValue() const { return const_cast<Value*>(getOperand(2)); }
226 void setValue(Value *Val) {
227 assert(getValue()->getType() == Val->getType() &&
228 "setSource called with pointer of wrong type!");
232 // Methods for support type inquiry through isa, cast, and dyn_cast:
233 static inline bool classof(const MemSetInst *) { return true; }
234 static inline bool classof(const MemIntrinsic *I) {
235 return I->getCalledFunction()->getIntrinsicID() == Intrinsic::memset;
237 static inline bool classof(const CallInst *I) {
238 if (const Function *CF = I->getCalledFunction())
239 if (CF->getIntrinsicID() == Intrinsic::memset)
243 static inline bool classof(const Value *V) {
244 return isa<CallInst>(V) && classof(cast<CallInst>(V));