LLVM  3.7.0
IntrinsicInst.h
Go to the documentation of this file.
1 //===-- llvm/IntrinsicInst.h - Intrinsic Instruction Wrappers ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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:
13 //
14 // if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst))
15 // ... MCI->getDest() ... MCI->getSource() ...
16 //
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
20 // hack working.
21 //
22 //===----------------------------------------------------------------------===//
23 
24 #ifndef LLVM_IR_INTRINSICINST_H
25 #define LLVM_IR_INTRINSICINST_H
26 
27 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/Function.h"
29 #include "llvm/IR/Instructions.h"
30 #include "llvm/IR/Intrinsics.h"
31 #include "llvm/IR/Metadata.h"
32 
33 namespace llvm {
34  /// IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic
35  /// functions. This allows the standard isa/dyncast/cast functionality to
36  /// work with calls to intrinsic functions.
37  class IntrinsicInst : public CallInst {
38  IntrinsicInst() = delete;
39  IntrinsicInst(const IntrinsicInst&) = delete;
40  void operator=(const IntrinsicInst&) = delete;
41  public:
42  /// getIntrinsicID - Return the intrinsic ID of this intrinsic.
43  ///
46  }
47 
48  // Methods for support type inquiry through isa, cast, and dyn_cast:
49  static inline bool classof(const CallInst *I) {
50  if (const Function *CF = I->getCalledFunction())
51  return CF->isIntrinsic();
52  return false;
53  }
54  static inline bool classof(const Value *V) {
55  return isa<CallInst>(V) && classof(cast<CallInst>(V));
56  }
57  };
58 
59  /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
60  ///
62  public:
63 
64  // Methods for support type inquiry through isa, cast, and dyn_cast:
65  static inline bool classof(const IntrinsicInst *I) {
66  switch (I->getIntrinsicID()) {
67  case Intrinsic::dbg_declare:
68  case Intrinsic::dbg_value:
69  return true;
70  default: return false;
71  }
72  }
73  static inline bool classof(const Value *V) {
74  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
75  }
76 
77  static Value *StripCast(Value *C);
78  };
79 
80  /// DbgDeclareInst - This represents the llvm.dbg.declare instruction.
81  ///
83  public:
84  Value *getAddress() const;
86  return cast<DILocalVariable>(getRawVariable());
87  }
89  return cast<DIExpression>(getRawExpression());
90  }
91 
93  return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
94  }
96  return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
97  }
98 
99  // Methods for support type inquiry through isa, cast, and dyn_cast:
100  static inline bool classof(const IntrinsicInst *I) {
101  return I->getIntrinsicID() == Intrinsic::dbg_declare;
102  }
103  static inline bool classof(const Value *V) {
104  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
105  }
106  };
107 
108  /// DbgValueInst - This represents the llvm.dbg.value instruction.
109  ///
111  public:
112  const Value *getValue() const;
113  Value *getValue();
114  uint64_t getOffset() const {
115  return cast<ConstantInt>(
116  const_cast<Value*>(getArgOperand(1)))->getZExtValue();
117  }
119  return cast<DILocalVariable>(getRawVariable());
120  }
122  return cast<DIExpression>(getRawExpression());
123  }
124 
126  return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
127  }
129  return cast<MetadataAsValue>(getArgOperand(3))->getMetadata();
130  }
131 
132  // Methods for support type inquiry through isa, cast, and dyn_cast:
133  static inline bool classof(const IntrinsicInst *I) {
134  return I->getIntrinsicID() == Intrinsic::dbg_value;
135  }
136  static inline bool classof(const Value *V) {
137  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
138  }
139  };
140 
141  /// MemIntrinsic - This is the common base class for memset/memcpy/memmove.
142  ///
143  class MemIntrinsic : public IntrinsicInst {
144  public:
145  Value *getRawDest() const { return const_cast<Value*>(getArgOperand(0)); }
146  const Use &getRawDestUse() const { return getArgOperandUse(0); }
148 
149  Value *getLength() const { return const_cast<Value*>(getArgOperand(2)); }
150  const Use &getLengthUse() const { return getArgOperandUse(2); }
152 
154  return cast<ConstantInt>(const_cast<Value*>(getArgOperand(3)));
155  }
156 
157  unsigned getAlignment() const {
158  return getAlignmentCst()->getZExtValue();
159  }
160 
162  return cast<ConstantInt>(const_cast<Value*>(getArgOperand(4)));
163  }
164  bool isVolatile() const {
165  return !getVolatileCst()->isZero();
166  }
167 
168  unsigned getDestAddressSpace() const {
169  return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
170  }
171 
172  /// getDest - This is just like getRawDest, but it strips off any cast
173  /// instructions that feed it, giving the original input. The returned
174  /// value is guaranteed to be a pointer.
175  Value *getDest() const { return getRawDest()->stripPointerCasts(); }
176 
177  /// set* - Set the specified arguments of the instruction.
178  ///
179  void setDest(Value *Ptr) {
180  assert(getRawDest()->getType() == Ptr->getType() &&
181  "setDest called with pointer of wrong type!");
182  setArgOperand(0, Ptr);
183  }
184 
185  void setLength(Value *L) {
186  assert(getLength()->getType() == L->getType() &&
187  "setLength called with value of wrong type!");
188  setArgOperand(2, L);
189  }
190 
192  setArgOperand(3, A);
193  }
194 
196  setArgOperand(4, V);
197  }
198 
200  return getArgOperand(3)->getType();
201  }
202 
203  // Methods for support type inquiry through isa, cast, and dyn_cast:
204  static inline bool classof(const IntrinsicInst *I) {
205  switch (I->getIntrinsicID()) {
206  case Intrinsic::memcpy:
207  case Intrinsic::memmove:
208  case Intrinsic::memset:
209  return true;
210  default: return false;
211  }
212  }
213  static inline bool classof(const Value *V) {
214  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
215  }
216  };
217 
218  /// MemSetInst - This class wraps the llvm.memset intrinsic.
219  ///
220  class MemSetInst : public MemIntrinsic {
221  public:
222  /// get* - Return the arguments to the instruction.
223  ///
224  Value *getValue() const { return const_cast<Value*>(getArgOperand(1)); }
225  const Use &getValueUse() const { return getArgOperandUse(1); }
226  Use &getValueUse() { return getArgOperandUse(1); }
227 
228  void setValue(Value *Val) {
229  assert(getValue()->getType() == Val->getType() &&
230  "setValue called with value of wrong type!");
231  setArgOperand(1, Val);
232  }
233 
234  // Methods for support type inquiry through isa, cast, and dyn_cast:
235  static inline bool classof(const IntrinsicInst *I) {
236  return I->getIntrinsicID() == Intrinsic::memset;
237  }
238  static inline bool classof(const Value *V) {
239  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
240  }
241  };
242 
243  /// MemTransferInst - This class wraps the llvm.memcpy/memmove intrinsics.
244  ///
245  class MemTransferInst : public MemIntrinsic {
246  public:
247  /// get* - Return the arguments to the instruction.
248  ///
249  Value *getRawSource() const { return const_cast<Value*>(getArgOperand(1)); }
250  const Use &getRawSourceUse() const { return getArgOperandUse(1); }
252 
253  /// getSource - This is just like getRawSource, but it strips off any cast
254  /// instructions that feed it, giving the original input. The returned
255  /// value is guaranteed to be a pointer.
256  Value *getSource() const { return getRawSource()->stripPointerCasts(); }
257 
258  unsigned getSourceAddressSpace() const {
259  return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
260  }
261 
262  void setSource(Value *Ptr) {
263  assert(getRawSource()->getType() == Ptr->getType() &&
264  "setSource called with pointer of wrong type!");
265  setArgOperand(1, Ptr);
266  }
267 
268  // Methods for support type inquiry through isa, cast, and dyn_cast:
269  static inline bool classof(const IntrinsicInst *I) {
270  return I->getIntrinsicID() == Intrinsic::memcpy ||
271  I->getIntrinsicID() == Intrinsic::memmove;
272  }
273  static inline bool classof(const Value *V) {
274  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
275  }
276  };
277 
278 
279  /// MemCpyInst - This class wraps the llvm.memcpy intrinsic.
280  ///
281  class MemCpyInst : public MemTransferInst {
282  public:
283  // Methods for support type inquiry through isa, cast, and dyn_cast:
284  static inline bool classof(const IntrinsicInst *I) {
285  return I->getIntrinsicID() == Intrinsic::memcpy;
286  }
287  static inline bool classof(const Value *V) {
288  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
289  }
290  };
291 
292  /// MemMoveInst - This class wraps the llvm.memmove intrinsic.
293  ///
294  class MemMoveInst : public MemTransferInst {
295  public:
296  // Methods for support type inquiry through isa, cast, and dyn_cast:
297  static inline bool classof(const IntrinsicInst *I) {
298  return I->getIntrinsicID() == Intrinsic::memmove;
299  }
300  static inline bool classof(const Value *V) {
301  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
302  }
303  };
304 
305  /// VAStartInst - This represents the llvm.va_start intrinsic.
306  ///
307  class VAStartInst : public IntrinsicInst {
308  public:
309  static inline bool classof(const IntrinsicInst *I) {
310  return I->getIntrinsicID() == Intrinsic::vastart;
311  }
312  static inline bool classof(const Value *V) {
313  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
314  }
315 
316  Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
317  };
318 
319  /// VAEndInst - This represents the llvm.va_end intrinsic.
320  ///
321  class VAEndInst : public IntrinsicInst {
322  public:
323  static inline bool classof(const IntrinsicInst *I) {
324  return I->getIntrinsicID() == Intrinsic::vaend;
325  }
326  static inline bool classof(const Value *V) {
327  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
328  }
329 
330  Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
331  };
332 
333  /// VACopyInst - This represents the llvm.va_copy intrinsic.
334  ///
335  class VACopyInst : public IntrinsicInst {
336  public:
337  static inline bool classof(const IntrinsicInst *I) {
338  return I->getIntrinsicID() == Intrinsic::vacopy;
339  }
340  static inline bool classof(const Value *V) {
341  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
342  }
343 
344  Value *getDest() const { return const_cast<Value*>(getArgOperand(0)); }
345  Value *getSrc() const { return const_cast<Value*>(getArgOperand(1)); }
346  };
347 
348  /// This represents the llvm.instrprof_increment intrinsic.
350  public:
351  static inline bool classof(const IntrinsicInst *I) {
352  return I->getIntrinsicID() == Intrinsic::instrprof_increment;
353  }
354  static inline bool classof(const Value *V) {
355  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
356  }
357 
359  return cast<GlobalVariable>(
360  const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
361  }
362 
363  ConstantInt *getHash() const {
364  return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
365  }
366 
368  return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
369  }
370 
372  return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
373  }
374  };
375 }
376 
377 #endif
unsigned getAlignment() const
Value * getDest() const
static bool classof(const IntrinsicInst *I)
Metadata * getRawVariable() const
bool isVolatile() const
VAEndInst - This represents the llvm.va_end intrinsic.
Intrinsic::ID getIntrinsicID() const
getIntrinsicID - Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:44
ConstantInt * getAlignmentCst() const
Value * getValue() const
get* - Return the arguments to the instruction.
CallInst - This class represents a function call, abstracting a target machine's calling convention...
This file contains the declarations for metadata subclasses.
static bool classof(const CallInst *I)
Definition: IntrinsicInst.h:49
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
MemSetInst - This class wraps the llvm.memset intrinsic.
void setVolatile(Constant *V)
void setValue(Value *Val)
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
void setDest(Value *Ptr)
set* - Set the specified arguments of the instruction.
void setAlignment(Constant *A)
uint64_t getOffset() const
ConstantInt * getHash() const
static bool classof(const IntrinsicInst *I)
Definition: IntrinsicInst.h:65
Value * getArgList() const
MemMoveInst - This class wraps the llvm.memmove intrinsic.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:69
static Value * StripCast(Value *C)
ConstantInt * getIndex() const
Type * getAlignmentType() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
ConstantInt * getNumCounters() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:117
VAStartInst - This represents the llvm.va_start intrinsic.
Metadata * getRawExpression() const
static bool classof(const Value *V)
static bool classof(const Value *V)
const Use & getValueUse() const
Value * getArgList() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
GlobalVariable * getName() const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
DIExpression * getExpression() const
Definition: IntrinsicInst.h:88
This is an important base class in LLVM.
Definition: Constant.h:41
Value * getSrc() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Value * getRawDest() const
Metadata * getRawVariable() const
Definition: IntrinsicInst.h:92
ConstantInt * getVolatileCst() const
static bool classof(const Value *V)
Definition: IntrinsicInst.h:73
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
const Use & getRawSourceUse() const
DIExpression * getExpression() const
MemIntrinsic - This is the common base class for memset/memcpy/memmove.
This is the shared class of boolean and integer constants.
Definition: Constants.h:47
Value * getDest() const
getDest - This is just like getRawDest, but it strips off any cast instructions that feed it...
Metadata * getRawExpression() const
Definition: IntrinsicInst.h:95
static bool classof(const Value *V)
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:222
MDNode * getMetadata(unsigned KindID) const
getMetadata - Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:167
DbgInfoIntrinsic - This is the common base class for debug info intrinsics.
Definition: IntrinsicInst.h:61
static bool classof(const Value *V)
Value * getLength() const
static bool classof(const IntrinsicInst *I)
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:458
MemCpyInst - This class wraps the llvm.memcpy intrinsic.
Function * getCalledFunction() const
getCalledFunction - Return the function called, or null if this is an indirect function invocation...
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constants.h:161
static bool classof(const Value *V)
DWARF expression.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:159
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
static bool classof(const Value *V)
void setLength(Value *L)
This represents the llvm.instrprof_increment intrinsic.
Value * getSource() const
getSource - This is just like getRawSource, but it strips off any cast instructions that feed it...
MemTransferInst - This class wraps the llvm.memcpy/memmove intrinsics.
DbgValueInst - This represents the llvm.dbg.value instruction.
#define I(x, y, z)
Definition: MD5.cpp:54
void setArgOperand(unsigned i, Value *v)
void setSource(Value *Ptr)
static bool classof(const Value *V)
static bool classof(const Value *V)
Definition: IntrinsicInst.h:54
static bool classof(const IntrinsicInst *I)
Value * getRawSource() const
get* - Return the arguments to the instruction.
VACopyInst - This represents the llvm.va_copy intrinsic.
DILocalVariable * getVariable() const
Definition: IntrinsicInst.h:85
LLVM Value Representation.
Definition: Value.h:69
Value * getAddress() const
DbgDeclareInst - This represents the llvm.dbg.declare instruction.
DILocalVariable * getVariable() const
unsigned getDestAddressSpace() const
const Value * getValue() const
DbgValueInst - This represents the llvm.dbg.value instruction.
const Use & getLengthUse() const
const Use & getRawDestUse() const
unsigned getSourceAddressSpace() const
DbgDeclareInst - This represents the llvm.dbg.declare instruction.
Definition: IntrinsicInst.h:82
Root of the metadata hierarchy.
Definition: Metadata.h:45
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:37