2006-03-16 18:15:12 +00:00
|
|
|
//===-- llvm/IntrinsicInst.h - Intrinsic Instruction Wrappers ---*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2004-10-12 04:20:46 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2004-10-12 04:20:46 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines classes that make it really easy to deal with intrinsic
|
|
|
|
// functions with the isa/dyncast family of functions. In particular, this
|
|
|
|
// allows you to do things like:
|
|
|
|
//
|
|
|
|
// if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst))
|
|
|
|
// ... MCI->getDest() ... MCI->getSource() ...
|
|
|
|
//
|
|
|
|
// All intrinsic function calls are instances of the call instruction, so these
|
|
|
|
// are all subclasses of the CallInst class. Note that none of these classes
|
|
|
|
// has state or virtual methods, which is an important part of this gross/neat
|
|
|
|
// hack working.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_INTRINSICINST_H
|
|
|
|
#define LLVM_INTRINSICINST_H
|
|
|
|
|
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/Intrinsics.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
2006-01-13 19:49:02 +00:00
|
|
|
/// IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic
|
|
|
|
/// functions. This allows the standard isa/dyncast/cast functionality to
|
|
|
|
/// work with calls to intrinsic functions.
|
2004-10-12 04:20:46 +00:00
|
|
|
class IntrinsicInst : public CallInst {
|
|
|
|
IntrinsicInst(); // DO NOT IMPLEMENT
|
|
|
|
IntrinsicInst(const IntrinsicInst&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const IntrinsicInst&); // DO NOT IMPLEMENT
|
|
|
|
public:
|
2006-01-13 19:49:02 +00:00
|
|
|
/// getIntrinsicID - Return the intrinsic ID of this intrinsic.
|
|
|
|
///
|
|
|
|
Intrinsic::ID getIntrinsicID() const {
|
|
|
|
return (Intrinsic::ID)getCalledFunction()->getIntrinsicID();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const IntrinsicInst *) { return true; }
|
|
|
|
static inline bool classof(const CallInst *I) {
|
|
|
|
if (const Function *CF = I->getCalledFunction())
|
|
|
|
return CF->getIntrinsicID() != 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<CallInst>(V) && classof(cast<CallInst>(V));
|
|
|
|
}
|
2004-10-12 04:20:46 +00:00
|
|
|
};
|
|
|
|
|
2004-11-22 17:18:05 +00:00
|
|
|
/// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
|
2004-11-18 21:41:16 +00:00
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class DbgInfoIntrinsic : public IntrinsicInst {
|
|
|
|
public:
|
2004-11-18 21:41:16 +00:00
|
|
|
|
2004-11-22 17:18:05 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const DbgInfoIntrinsic *) { return true; }
|
2006-01-13 20:00:51 +00:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
|
|
|
switch (I->getIntrinsicID()) {
|
2006-03-23 18:05:12 +00:00
|
|
|
case Intrinsic::dbg_declare:
|
2009-12-07 19:36:34 +00:00
|
|
|
case Intrinsic::dbg_value:
|
2006-01-13 20:00:51 +00:00
|
|
|
return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
2004-11-22 17:18:05 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 20:00:51 +00:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-11-22 17:18:05 +00:00
|
|
|
}
|
2006-03-23 18:05:12 +00:00
|
|
|
|
|
|
|
static Value *StripCast(Value *C);
|
2004-11-22 17:18:05 +00:00
|
|
|
};
|
|
|
|
|
2006-03-23 18:05:12 +00:00
|
|
|
/// DbgDeclareInst - This represents the llvm.dbg.declare instruction.
|
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class DbgDeclareInst : public DbgInfoIntrinsic {
|
|
|
|
public:
|
2010-01-15 19:04:09 +00:00
|
|
|
Value *getAddress() const;
|
2009-08-28 23:24:31 +00:00
|
|
|
MDNode *getVariable() const { return cast<MDNode>(getOperand(2)); }
|
2006-03-23 18:05:12 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const DbgDeclareInst *) { return true; }
|
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
|
|
|
return I->getIntrinsicID() == Intrinsic::dbg_declare;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
|
|
|
}
|
|
|
|
};
|
2004-11-18 21:41:16 +00:00
|
|
|
|
2009-12-07 19:36:34 +00:00
|
|
|
/// DbgValueInst - This represents the llvm.dbg.value instruction.
|
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class DbgValueInst : public DbgInfoIntrinsic {
|
|
|
|
public:
|
2010-01-11 07:45:19 +00:00
|
|
|
const Value *getValue() const;
|
|
|
|
Value *getValue();
|
|
|
|
uint64_t getOffset() const {
|
|
|
|
return cast<ConstantInt>(
|
|
|
|
const_cast<Value*>(getOperand(2)))->getZExtValue();
|
|
|
|
}
|
|
|
|
const MDNode *getVariable() const { return cast<MDNode>(getOperand(3)); }
|
|
|
|
MDNode *getVariable() { return cast<MDNode>(getOperand(3)); }
|
2009-12-07 19:36:34 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const DbgValueInst *) { return true; }
|
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
|
|
|
return I->getIntrinsicID() == Intrinsic::dbg_value;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-10-12 04:20:46 +00:00
|
|
|
/// MemIntrinsic - This is the common base class for memset/memcpy/memmove.
|
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class MemIntrinsic : public IntrinsicInst {
|
|
|
|
public:
|
2004-10-12 04:45:20 +00:00
|
|
|
Value *getRawDest() const { return const_cast<Value*>(getOperand(1)); }
|
2004-10-12 04:20:46 +00:00
|
|
|
|
2004-10-12 04:45:20 +00:00
|
|
|
Value *getLength() const { return const_cast<Value*>(getOperand(3)); }
|
2009-03-08 03:59:00 +00:00
|
|
|
ConstantInt *getAlignmentCst() const {
|
2004-10-12 04:45:20 +00:00
|
|
|
return cast<ConstantInt>(const_cast<Value*>(getOperand(4)));
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
2009-03-08 03:59:00 +00:00
|
|
|
|
|
|
|
unsigned getAlignment() const {
|
|
|
|
return getAlignmentCst()->getZExtValue();
|
|
|
|
}
|
2004-10-12 04:20:46 +00:00
|
|
|
|
|
|
|
/// getDest - This is just like getRawDest, but it strips off any cast
|
|
|
|
/// instructions that feed it, giving the original input. The returned
|
|
|
|
/// value is guaranteed to be a pointer.
|
2008-05-07 22:54:15 +00:00
|
|
|
Value *getDest() const { return getRawDest()->stripPointerCasts(); }
|
2004-10-12 04:20:46 +00:00
|
|
|
|
|
|
|
/// set* - Set the specified arguments of the instruction.
|
|
|
|
///
|
|
|
|
void setDest(Value *Ptr) {
|
|
|
|
assert(getRawDest()->getType() == Ptr->getType() &&
|
|
|
|
"setDest called with pointer of wrong type!");
|
2004-10-12 04:45:20 +00:00
|
|
|
setOperand(1, Ptr);
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setLength(Value *L) {
|
|
|
|
assert(getLength()->getType() == L->getType() &&
|
|
|
|
"setLength called with value of wrong type!");
|
2004-10-12 04:45:20 +00:00
|
|
|
setOperand(3, L);
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
2009-07-09 18:36:20 +00:00
|
|
|
|
|
|
|
void setAlignment(Constant* A) {
|
|
|
|
setOperand(4, A);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Type *getAlignmentType() const {
|
|
|
|
return getOperand(4)->getType();
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
2009-03-08 03:59:00 +00:00
|
|
|
|
2004-10-12 04:20:46 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const MemIntrinsic *) { return true; }
|
2006-01-13 20:00:51 +00:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
|
|
|
switch (I->getIntrinsicID()) {
|
2008-11-21 16:42:48 +00:00
|
|
|
case Intrinsic::memcpy:
|
|
|
|
case Intrinsic::memmove:
|
|
|
|
case Intrinsic::memset:
|
2006-01-13 20:00:51 +00:00
|
|
|
return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 20:00:51 +00:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-03-08 03:37:16 +00:00
|
|
|
/// MemSetInst - This class wraps the llvm.memset intrinsic.
|
2004-10-12 04:20:46 +00:00
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class MemSetInst : public MemIntrinsic {
|
|
|
|
public:
|
2004-10-12 04:20:46 +00:00
|
|
|
/// get* - Return the arguments to the instruction.
|
|
|
|
///
|
2009-03-08 03:37:16 +00:00
|
|
|
Value *getValue() const { return const_cast<Value*>(getOperand(2)); }
|
|
|
|
|
|
|
|
void setValue(Value *Val) {
|
|
|
|
assert(getValue()->getType() == Val->getType() &&
|
2004-10-12 04:20:46 +00:00
|
|
|
"setSource called with pointer of wrong type!");
|
2009-03-08 03:37:16 +00:00
|
|
|
setOperand(2, Val);
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
2009-03-08 03:37:16 +00:00
|
|
|
|
2004-10-12 04:20:46 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-03-08 03:37:16 +00:00
|
|
|
static inline bool classof(const MemSetInst *) { return true; }
|
2006-01-13 20:00:51 +00:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
2009-03-08 03:37:16 +00:00
|
|
|
return I->getIntrinsicID() == Intrinsic::memset;
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 20:00:51 +00:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
};
|
2009-03-08 03:37:16 +00:00
|
|
|
|
|
|
|
/// MemTransferInst - This class wraps the llvm.memcpy/memmove intrinsics.
|
2004-10-12 04:20:46 +00:00
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class MemTransferInst : public MemIntrinsic {
|
|
|
|
public:
|
2004-10-12 04:20:46 +00:00
|
|
|
/// get* - Return the arguments to the instruction.
|
|
|
|
///
|
2004-10-12 04:45:20 +00:00
|
|
|
Value *getRawSource() const { return const_cast<Value*>(getOperand(2)); }
|
2009-03-08 03:37:16 +00:00
|
|
|
|
2004-10-12 04:20:46 +00:00
|
|
|
/// getSource - This is just like getRawSource, but it strips off any cast
|
|
|
|
/// instructions that feed it, giving the original input. The returned
|
|
|
|
/// value is guaranteed to be a pointer.
|
2008-05-07 22:54:15 +00:00
|
|
|
Value *getSource() const { return getRawSource()->stripPointerCasts(); }
|
2009-03-08 03:37:16 +00:00
|
|
|
|
2004-10-12 04:20:46 +00:00
|
|
|
void setSource(Value *Ptr) {
|
|
|
|
assert(getRawSource()->getType() == Ptr->getType() &&
|
|
|
|
"setSource called with pointer of wrong type!");
|
2004-10-12 04:45:20 +00:00
|
|
|
setOperand(2, Ptr);
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
2009-03-08 03:37:16 +00:00
|
|
|
|
2004-10-12 04:20:46 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-03-08 03:37:16 +00:00
|
|
|
static inline bool classof(const MemTransferInst *) { return true; }
|
2006-01-13 20:00:51 +00:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
2009-03-08 03:37:16 +00:00
|
|
|
return I->getIntrinsicID() == Intrinsic::memcpy ||
|
|
|
|
I->getIntrinsicID() == Intrinsic::memmove;
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 20:00:51 +00:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
};
|
2009-03-08 03:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// MemCpyInst - This class wraps the llvm.memcpy intrinsic.
|
2004-10-12 04:20:46 +00:00
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class MemCpyInst : public MemTransferInst {
|
|
|
|
public:
|
2009-03-08 03:37:16 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const MemCpyInst *) { return true; }
|
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
|
|
|
return I->getIntrinsicID() == Intrinsic::memcpy;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
2009-03-08 03:37:16 +00:00
|
|
|
};
|
2004-10-12 04:20:46 +00:00
|
|
|
|
2009-03-08 03:37:16 +00:00
|
|
|
/// MemMoveInst - This class wraps the llvm.memmove intrinsic.
|
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class MemMoveInst : public MemTransferInst {
|
|
|
|
public:
|
2004-10-12 04:20:46 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-03-08 03:37:16 +00:00
|
|
|
static inline bool classof(const MemMoveInst *) { return true; }
|
2006-01-13 20:00:51 +00:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
2009-03-08 03:37:16 +00:00
|
|
|
return I->getIntrinsicID() == Intrinsic::memmove;
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 20:00:51 +00:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
};
|
2006-06-07 20:00:19 +00:00
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
/// EHSelectorInst - This represents the llvm.eh.selector instruction.
|
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class EHSelectorInst : public IntrinsicInst {
|
|
|
|
public:
|
2008-09-03 16:12:24 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const EHSelectorInst *) { return true; }
|
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
2009-10-14 16:11:37 +00:00
|
|
|
return I->getIntrinsicID() == Intrinsic::eh_selector;
|
2008-09-03 16:12:24 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-11-11 15:34:13 +00:00
|
|
|
/// MemoryUseIntrinsic - This is the common base class for the memory use
|
|
|
|
/// marker intrinsics.
|
|
|
|
///
|
2010-01-05 05:21:26 +00:00
|
|
|
class MemoryUseIntrinsic : public IntrinsicInst {
|
|
|
|
public:
|
2009-11-11 15:34:13 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const MemoryUseIntrinsic *) { return true; }
|
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
|
|
|
switch (I->getIntrinsicID()) {
|
|
|
|
case Intrinsic::lifetime_start:
|
|
|
|
case Intrinsic::lifetime_end:
|
|
|
|
case Intrinsic::invariant_start:
|
|
|
|
case Intrinsic::invariant_end:
|
|
|
|
return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-10-12 04:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|