LLVM API Documentation
00001 //===-- llvm/InstrinsicInst.h - Intrinsic Instruction Wrappers --*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines classes that make it really easy to deal with intrinsic 00011 // functions with the isa/dyncast family of functions. In particular, this 00012 // allows you to do things like: 00013 // 00014 // if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst)) 00015 // ... MCI->getDest() ... MCI->getSource() ... 00016 // 00017 // All intrinsic function calls are instances of the call instruction, so these 00018 // are all subclasses of the CallInst class. Note that none of these classes 00019 // has state or virtual methods, which is an important part of this gross/neat 00020 // hack working. 00021 // 00022 //===----------------------------------------------------------------------===// 00023 00024 #ifndef LLVM_INTRINSICINST_H 00025 #define LLVM_INTRINSICINST_H 00026 00027 #include "llvm/Constants.h" 00028 #include "llvm/Function.h" 00029 #include "llvm/Instructions.h" 00030 #include "llvm/Intrinsics.h" 00031 00032 namespace llvm { 00033 class IntrinsicInst : public CallInst { 00034 IntrinsicInst(); // DO NOT IMPLEMENT 00035 IntrinsicInst(const IntrinsicInst&); // DO NOT IMPLEMENT 00036 void operator=(const IntrinsicInst&); // DO NOT IMPLEMENT 00037 public: 00038 00039 /// StripPointerCasts - This static method strips off any unneeded pointer 00040 /// casts from the specified value, returning the original uncasted value. 00041 /// Note that the returned value is guaranteed to have pointer type. 00042 static Value *StripPointerCasts(Value *Ptr); 00043 }; 00044 00045 /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics 00046 /// 00047 struct DbgInfoIntrinsic : public IntrinsicInst { 00048 00049 Value *getChain() const { return const_cast<Value*>(getOperand(1)); } 00050 00051 // Methods for support type inquiry through isa, cast, and dyn_cast: 00052 static inline bool classof(const DbgInfoIntrinsic *) { return true; } 00053 static inline bool classof(const CallInst *I) { 00054 if (const Function *CF = I->getCalledFunction()) 00055 switch (CF->getIntrinsicID()) { 00056 case Intrinsic::dbg_stoppoint: 00057 case Intrinsic::dbg_region_start: 00058 case Intrinsic::dbg_region_end: 00059 case Intrinsic::dbg_func_start: 00060 case Intrinsic::dbg_declare: 00061 return true; 00062 default: break; 00063 } 00064 return false; 00065 } 00066 static inline bool classof(const Value *V) { 00067 return isa<CallInst>(V) && classof(cast<CallInst>(V)); 00068 } 00069 }; 00070 00071 00072 /// DbgStopPointInst - This represent llvm.dbg.stoppoint instructions. 00073 /// 00074 struct DbgStopPointInst : public DbgInfoIntrinsic { 00075 00076 unsigned getLineNo() const { 00077 return cast<ConstantInt>(getOperand(2))->getRawValue(); 00078 } 00079 unsigned getColNo() const { 00080 return cast<ConstantInt>(getOperand(3))->getRawValue(); 00081 } 00082 Value *getContext() const { return const_cast<Value*>(getOperand(4)); } 00083 00084 00085 // Methods for support type inquiry through isa, cast, and dyn_cast: 00086 static inline bool classof(const DbgStopPointInst *) { return true; } 00087 static inline bool classof(const CallInst *I) { 00088 if (const Function *CF = I->getCalledFunction()) 00089 return CF->getIntrinsicID() == Intrinsic::dbg_stoppoint; 00090 return false; 00091 } 00092 static inline bool classof(const Value *V) { 00093 return isa<CallInst>(V) && classof(cast<CallInst>(V)); 00094 } 00095 }; 00096 00097 /// MemIntrinsic - This is the common base class for memset/memcpy/memmove. 00098 /// 00099 struct MemIntrinsic : public IntrinsicInst { 00100 Value *getRawDest() const { return const_cast<Value*>(getOperand(1)); } 00101 00102 Value *getLength() const { return const_cast<Value*>(getOperand(3)); } 00103 ConstantInt *getAlignment() const { 00104 return cast<ConstantInt>(const_cast<Value*>(getOperand(4))); 00105 } 00106 00107 /// getDest - This is just like getRawDest, but it strips off any cast 00108 /// instructions that feed it, giving the original input. The returned 00109 /// value is guaranteed to be a pointer. 00110 Value *getDest() const { return StripPointerCasts(getRawDest()); } 00111 00112 /// set* - Set the specified arguments of the instruction. 00113 /// 00114 void setDest(Value *Ptr) { 00115 assert(getRawDest()->getType() == Ptr->getType() && 00116 "setDest called with pointer of wrong type!"); 00117 setOperand(1, Ptr); 00118 } 00119 00120 void setLength(Value *L) { 00121 assert(getLength()->getType() == L->getType() && 00122 "setLength called with value of wrong type!"); 00123 setOperand(3, L); 00124 } 00125 void setAlignment(ConstantInt *A) { 00126 assert(getAlignment()->getType() == A->getType() && 00127 "setAlignment called with value of wrong type!"); 00128 setOperand(4, A); 00129 } 00130 00131 // Methods for support type inquiry through isa, cast, and dyn_cast: 00132 static inline bool classof(const MemIntrinsic *) { return true; } 00133 static inline bool classof(const CallInst *I) { 00134 if (const Function *CF = I->getCalledFunction()) 00135 switch (CF->getIntrinsicID()) { 00136 case Intrinsic::memcpy: 00137 case Intrinsic::memmove: 00138 case Intrinsic::memset: 00139 return true; 00140 default: break; 00141 } 00142 return false; 00143 } 00144 static inline bool classof(const Value *V) { 00145 return isa<CallInst>(V) && classof(cast<CallInst>(V)); 00146 } 00147 }; 00148 00149 00150 /// MemCpyInst - This class wraps the llvm.memcpy intrinsic. 00151 /// 00152 struct MemCpyInst : public MemIntrinsic { 00153 /// get* - Return the arguments to the instruction. 00154 /// 00155 Value *getRawSource() const { return const_cast<Value*>(getOperand(2)); } 00156 00157 /// getSource - This is just like getRawSource, but it strips off any cast 00158 /// instructions that feed it, giving the original input. The returned 00159 /// value is guaranteed to be a pointer. 00160 Value *getSource() const { return StripPointerCasts(getRawSource()); } 00161 00162 00163 void setSource(Value *Ptr) { 00164 assert(getRawSource()->getType() == Ptr->getType() && 00165 "setSource called with pointer of wrong type!"); 00166 setOperand(2, Ptr); 00167 } 00168 00169 // Methods for support type inquiry through isa, cast, and dyn_cast: 00170 static inline bool classof(const MemCpyInst *) { return true; } 00171 static inline bool classof(const MemIntrinsic *I) { 00172 return I->getCalledFunction()->getIntrinsicID() == Intrinsic::memcpy; 00173 } 00174 static inline bool classof(const CallInst *I) { 00175 if (const Function *CF = I->getCalledFunction()) 00176 if (CF->getIntrinsicID() == Intrinsic::memcpy) 00177 return true; 00178 return false; 00179 } 00180 static inline bool classof(const Value *V) { 00181 return isa<CallInst>(V) && classof(cast<CallInst>(V)); 00182 } 00183 }; 00184 00185 /// MemMoveInst - This class wraps the llvm.memmove intrinsic. 00186 /// 00187 struct MemMoveInst : public MemIntrinsic { 00188 /// get* - Return the arguments to the instruction. 00189 /// 00190 Value *getRawSource() const { return const_cast<Value*>(getOperand(2)); } 00191 00192 /// getSource - This is just like getRawSource, but it strips off any cast 00193 /// instructions that feed it, giving the original input. The returned 00194 /// value is guaranteed to be a pointer. 00195 Value *getSource() const { return StripPointerCasts(getRawSource()); } 00196 00197 void setSource(Value *Ptr) { 00198 assert(getRawSource()->getType() == Ptr->getType() && 00199 "setSource called with pointer of wrong type!"); 00200 setOperand(2, Ptr); 00201 } 00202 00203 // Methods for support type inquiry through isa, cast, and dyn_cast: 00204 static inline bool classof(const MemMoveInst *) { return true; } 00205 static inline bool classof(const MemIntrinsic *I) { 00206 return I->getCalledFunction()->getIntrinsicID() == Intrinsic::memmove; 00207 } 00208 static inline bool classof(const CallInst *I) { 00209 if (const Function *CF = I->getCalledFunction()) 00210 if (CF->getIntrinsicID() == Intrinsic::memmove) 00211 return true; 00212 return false; 00213 } 00214 static inline bool classof(const Value *V) { 00215 return isa<CallInst>(V) && classof(cast<CallInst>(V)); 00216 } 00217 }; 00218 00219 /// MemSetInst - This class wraps the llvm.memcpy intrinsic. 00220 /// 00221 struct MemSetInst : public MemIntrinsic { 00222 /// get* - Return the arguments to the instruction. 00223 /// 00224 Value *getValue() const { return const_cast<Value*>(getOperand(2)); } 00225 00226 void setValue(Value *Val) { 00227 assert(getValue()->getType() == Val->getType() && 00228 "setSource called with pointer of wrong type!"); 00229 setOperand(2, Val); 00230 } 00231 00232 // Methods for support type inquiry through isa, cast, and dyn_cast: 00233 static inline bool classof(const MemSetInst *) { return true; } 00234 static inline bool classof(const MemIntrinsic *I) { 00235 return I->getCalledFunction()->getIntrinsicID() == Intrinsic::memset; 00236 } 00237 static inline bool classof(const CallInst *I) { 00238 if (const Function *CF = I->getCalledFunction()) 00239 if (CF->getIntrinsicID() == Intrinsic::memset) 00240 return true; 00241 return false; 00242 } 00243 static inline bool classof(const Value *V) { 00244 return isa<CallInst>(V) && classof(cast<CallInst>(V)); 00245 } 00246 }; 00247 } 00248 00249 #endif