2006-03-16 19:15:12 +01:00
|
|
|
//===-- llvm/IntrinsicInst.h - Intrinsic Instruction Wrappers ---*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2004-10-12 06:20:46 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2004-10-12 06:20:46 +02: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 20:49:02 +01: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 06:20:46 +02: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 20:49:02 +01:00
|
|
|
/// getIntrinsicID - Return the intrinsic ID of this intrinsic.
|
|
|
|
///
|
|
|
|
Intrinsic::ID getIntrinsicID() const {
|
|
|
|
return (Intrinsic::ID)getCalledFunction()->getIntrinsicID();
|
|
|
|
}
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2006-01-13 20:49:02 +01:00
|
|
|
// 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 06:20:46 +02:00
|
|
|
};
|
2010-11-30 03:03:47 +01:00
|
|
|
|
2004-11-22 18:18:05 +01:00
|
|
|
/// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
|
2004-11-18 22:41:16 +01:00
|
|
|
///
|
2010-01-05 06:21:26 +01:00
|
|
|
class DbgInfoIntrinsic : public IntrinsicInst {
|
|
|
|
public:
|
2004-11-18 22:41:16 +01:00
|
|
|
|
2004-11-22 18:18:05 +01:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const DbgInfoIntrinsic *) { return true; }
|
2006-01-13 21:00:51 +01:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
|
|
|
switch (I->getIntrinsicID()) {
|
2006-03-23 19:05:12 +01:00
|
|
|
case Intrinsic::dbg_declare:
|
2009-12-07 20:36:34 +01:00
|
|
|
case Intrinsic::dbg_value:
|
2006-01-13 21:00:51 +01:00
|
|
|
return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
2004-11-22 18:18:05 +01:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 21:00:51 +01:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-11-22 18:18:05 +01:00
|
|
|
}
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2006-03-23 19:05:12 +01:00
|
|
|
static Value *StripCast(Value *C);
|
2004-11-22 18:18:05 +01:00
|
|
|
};
|
|
|
|
|
2006-03-23 19:05:12 +01:00
|
|
|
/// DbgDeclareInst - This represents the llvm.dbg.declare instruction.
|
|
|
|
///
|
2010-01-05 06:21:26 +01:00
|
|
|
class DbgDeclareInst : public DbgInfoIntrinsic {
|
|
|
|
public:
|
2010-01-15 20:04:09 +01:00
|
|
|
Value *getAddress() const;
|
2010-06-29 18:01:30 +02:00
|
|
|
MDNode *getVariable() const { return cast<MDNode>(getArgOperand(1)); }
|
2006-03-23 19:05:12 +01: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 22:41:16 +01:00
|
|
|
|
2009-12-07 20:36:34 +01:00
|
|
|
/// DbgValueInst - This represents the llvm.dbg.value instruction.
|
|
|
|
///
|
2010-01-05 06:21:26 +01:00
|
|
|
class DbgValueInst : public DbgInfoIntrinsic {
|
|
|
|
public:
|
2010-01-11 08:45:19 +01:00
|
|
|
const Value *getValue() const;
|
|
|
|
Value *getValue();
|
|
|
|
uint64_t getOffset() const {
|
|
|
|
return cast<ConstantInt>(
|
2010-07-22 16:13:14 +02:00
|
|
|
const_cast<Value*>(getArgOperand(1)))->getZExtValue();
|
2010-01-11 08:45:19 +01:00
|
|
|
}
|
2010-06-29 18:01:30 +02:00
|
|
|
MDNode *getVariable() const { return cast<MDNode>(getArgOperand(2)); }
|
2009-12-07 20:36:34 +01: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 06:20:46 +02:00
|
|
|
/// MemIntrinsic - This is the common base class for memset/memcpy/memmove.
|
|
|
|
///
|
2010-01-05 06:21:26 +01:00
|
|
|
class MemIntrinsic : public IntrinsicInst {
|
|
|
|
public:
|
2010-06-29 18:01:30 +02:00
|
|
|
Value *getRawDest() const { return const_cast<Value*>(getArgOperand(0)); }
|
2004-10-12 06:20:46 +02:00
|
|
|
|
2010-06-29 18:01:30 +02:00
|
|
|
Value *getLength() const { return const_cast<Value*>(getArgOperand(2)); }
|
2009-03-08 04:59:00 +01:00
|
|
|
ConstantInt *getAlignmentCst() const {
|
2010-06-29 18:01:30 +02:00
|
|
|
return cast<ConstantInt>(const_cast<Value*>(getArgOperand(3)));
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2009-03-08 04:59:00 +01:00
|
|
|
unsigned getAlignment() const {
|
|
|
|
return getAlignmentCst()->getZExtValue();
|
|
|
|
}
|
2004-10-12 06:20:46 +02:00
|
|
|
|
Reapply address space patch after fixing an issue in MemCopyOptimizer.
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset,
e.g., llvm.memcpy.i32(i8*, i8*, i32, i32) -> llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
llvm-svn: 100304
2010-04-04 05:10:48 +02:00
|
|
|
ConstantInt *getVolatileCst() const {
|
2010-06-29 18:01:30 +02:00
|
|
|
return cast<ConstantInt>(const_cast<Value*>(getArgOperand(4)));
|
Reapply address space patch after fixing an issue in MemCopyOptimizer.
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset,
e.g., llvm.memcpy.i32(i8*, i8*, i32, i32) -> llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
llvm-svn: 100304
2010-04-04 05:10:48 +02:00
|
|
|
}
|
|
|
|
bool isVolatile() const {
|
2010-06-18 16:22:04 +02:00
|
|
|
return !getVolatileCst()->isZero();
|
Reapply address space patch after fixing an issue in MemCopyOptimizer.
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset,
e.g., llvm.memcpy.i32(i8*, i8*, i32, i32) -> llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
llvm-svn: 100304
2010-04-04 05:10:48 +02:00
|
|
|
}
|
|
|
|
|
2011-05-31 22:40:16 +02:00
|
|
|
unsigned getDestAddressSpace() const {
|
2011-01-15 10:16:12 +01:00
|
|
|
return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
|
|
|
|
}
|
|
|
|
|
2004-10-12 06:20:46 +02: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-08 00:54:15 +02:00
|
|
|
Value *getDest() const { return getRawDest()->stripPointerCasts(); }
|
2004-10-12 06:20:46 +02: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!");
|
2010-06-29 18:01:30 +02:00
|
|
|
setArgOperand(0, Ptr);
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setLength(Value *L) {
|
|
|
|
assert(getLength()->getType() == L->getType() &&
|
|
|
|
"setLength called with value of wrong type!");
|
2010-06-29 18:01:30 +02:00
|
|
|
setArgOperand(2, L);
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2009-07-09 20:36:20 +02:00
|
|
|
void setAlignment(Constant* A) {
|
2010-06-29 18:01:30 +02:00
|
|
|
setArgOperand(3, A);
|
2009-07-09 20:36:20 +02:00
|
|
|
}
|
Reapply address space patch after fixing an issue in MemCopyOptimizer.
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset,
e.g., llvm.memcpy.i32(i8*, i8*, i32, i32) -> llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
llvm-svn: 100304
2010-04-04 05:10:48 +02:00
|
|
|
|
|
|
|
void setVolatile(Constant* V) {
|
2010-06-29 18:01:30 +02:00
|
|
|
setArgOperand(4, V);
|
Reapply address space patch after fixing an issue in MemCopyOptimizer.
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset,
e.g., llvm.memcpy.i32(i8*, i8*, i32, i32) -> llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
llvm-svn: 100304
2010-04-04 05:10:48 +02:00
|
|
|
}
|
|
|
|
|
2011-07-18 06:54:35 +02:00
|
|
|
Type *getAlignmentType() const {
|
2010-06-29 18:01:30 +02:00
|
|
|
return getArgOperand(3)->getType();
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2004-10-12 06:20:46 +02:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const MemIntrinsic *) { return true; }
|
2006-01-13 21:00:51 +01:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
|
|
|
switch (I->getIntrinsicID()) {
|
2008-11-21 17:42:48 +01:00
|
|
|
case Intrinsic::memcpy:
|
|
|
|
case Intrinsic::memmove:
|
|
|
|
case Intrinsic::memset:
|
2006-01-13 21:00:51 +01:00
|
|
|
return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 21:00:51 +01:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-03-08 04:37:16 +01:00
|
|
|
/// MemSetInst - This class wraps the llvm.memset intrinsic.
|
2004-10-12 06:20:46 +02:00
|
|
|
///
|
2010-01-05 06:21:26 +01:00
|
|
|
class MemSetInst : public MemIntrinsic {
|
|
|
|
public:
|
2004-10-12 06:20:46 +02:00
|
|
|
/// get* - Return the arguments to the instruction.
|
|
|
|
///
|
2010-06-29 18:01:30 +02:00
|
|
|
Value *getValue() const { return const_cast<Value*>(getArgOperand(1)); }
|
|
|
|
|
2009-03-08 04:37:16 +01:00
|
|
|
void setValue(Value *Val) {
|
|
|
|
assert(getValue()->getType() == Val->getType() &&
|
2010-06-29 18:01:30 +02:00
|
|
|
"setValue called with value of wrong type!");
|
|
|
|
setArgOperand(1, Val);
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2004-10-12 06:20:46 +02:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-03-08 04:37:16 +01:00
|
|
|
static inline bool classof(const MemSetInst *) { return true; }
|
2006-01-13 21:00:51 +01:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
2009-03-08 04:37:16 +01:00
|
|
|
return I->getIntrinsicID() == Intrinsic::memset;
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 21:00:51 +01:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
};
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2009-03-08 04:37:16 +01:00
|
|
|
/// MemTransferInst - This class wraps the llvm.memcpy/memmove intrinsics.
|
2004-10-12 06:20:46 +02:00
|
|
|
///
|
2010-01-05 06:21:26 +01:00
|
|
|
class MemTransferInst : public MemIntrinsic {
|
|
|
|
public:
|
2004-10-12 06:20:46 +02:00
|
|
|
/// get* - Return the arguments to the instruction.
|
|
|
|
///
|
2010-06-29 18:01:30 +02:00
|
|
|
Value *getRawSource() const { return const_cast<Value*>(getArgOperand(1)); }
|
|
|
|
|
2004-10-12 06:20:46 +02: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-08 00:54:15 +02:00
|
|
|
Value *getSource() const { return getRawSource()->stripPointerCasts(); }
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2011-05-31 22:40:16 +02:00
|
|
|
unsigned getSourceAddressSpace() const {
|
|
|
|
return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
|
|
|
|
}
|
|
|
|
|
2004-10-12 06:20:46 +02:00
|
|
|
void setSource(Value *Ptr) {
|
|
|
|
assert(getRawSource()->getType() == Ptr->getType() &&
|
|
|
|
"setSource called with pointer of wrong type!");
|
2010-06-29 18:01:30 +02:00
|
|
|
setArgOperand(1, Ptr);
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2004-10-12 06:20:46 +02:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-03-08 04:37:16 +01:00
|
|
|
static inline bool classof(const MemTransferInst *) { return true; }
|
2006-01-13 21:00:51 +01:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
2009-03-08 04:37:16 +01:00
|
|
|
return I->getIntrinsicID() == Intrinsic::memcpy ||
|
|
|
|
I->getIntrinsicID() == Intrinsic::memmove;
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 21:00:51 +01:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
};
|
2010-06-29 18:01:30 +02:00
|
|
|
|
|
|
|
|
2009-03-08 04:37:16 +01:00
|
|
|
/// MemCpyInst - This class wraps the llvm.memcpy intrinsic.
|
2004-10-12 06:20:46 +02:00
|
|
|
///
|
2010-01-05 06:21:26 +01:00
|
|
|
class MemCpyInst : public MemTransferInst {
|
|
|
|
public:
|
2009-03-08 04:37:16 +01: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 06:20:46 +02:00
|
|
|
}
|
2009-03-08 04:37:16 +01:00
|
|
|
};
|
2004-10-12 06:20:46 +02:00
|
|
|
|
2009-03-08 04:37:16 +01:00
|
|
|
/// MemMoveInst - This class wraps the llvm.memmove intrinsic.
|
|
|
|
///
|
2010-01-05 06:21:26 +01:00
|
|
|
class MemMoveInst : public MemTransferInst {
|
|
|
|
public:
|
2004-10-12 06:20:46 +02:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-03-08 04:37:16 +01:00
|
|
|
static inline bool classof(const MemMoveInst *) { return true; }
|
2006-01-13 21:00:51 +01:00
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
2009-03-08 04:37:16 +01:00
|
|
|
return I->getIntrinsicID() == Intrinsic::memmove;
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
2006-01-13 21:00:51 +01:00
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
};
|
2006-06-07 22:00:19 +02:00
|
|
|
|
2010-09-01 11:26:00 +02:00
|
|
|
/// EHExceptionInst - This represents the llvm.eh.exception instruction.
|
|
|
|
///
|
|
|
|
class EHExceptionInst : public IntrinsicInst {
|
|
|
|
public:
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const EHExceptionInst *) { return true; }
|
|
|
|
static inline bool classof(const IntrinsicInst *I) {
|
|
|
|
return I->getIntrinsicID() == Intrinsic::eh_exception;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-09-03 18:12:24 +02:00
|
|
|
/// EHSelectorInst - This represents the llvm.eh.selector instruction.
|
|
|
|
///
|
2010-01-05 06:21:26 +01:00
|
|
|
class EHSelectorInst : public IntrinsicInst {
|
|
|
|
public:
|
2008-09-03 18:12:24 +02: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 18:11:37 +02:00
|
|
|
return I->getIntrinsicID() == Intrinsic::eh_selector;
|
2008-09-03 18:12:24 +02:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
|
|
|
}
|
|
|
|
};
|
2010-06-29 18:01:30 +02:00
|
|
|
|
2004-10-12 06:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|