2001-06-06 20:29:01 +00:00
|
|
|
//===-- llvm/iMemory.h - Memory Operator node definitions --------*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// This file contains the declarations of all of the memory related operators.
|
|
|
|
// This includes: malloc, free, alloca, load, store, getfield, putfield
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_IMEMORY_H
|
|
|
|
#define LLVM_IMEMORY_H
|
|
|
|
|
|
|
|
#include "llvm/Instruction.h"
|
2002-04-29 18:46:22 +00:00
|
|
|
class PointerType;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-07-08 23:22:50 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AllocationInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// AllocationInst - This class is the common base class of MallocInst and
|
|
|
|
// AllocaInst.
|
|
|
|
//
|
2001-06-06 20:29:01 +00:00
|
|
|
class AllocationInst : public Instruction {
|
2002-03-21 22:37:01 +00:00
|
|
|
protected:
|
2001-07-07 08:36:50 +00:00
|
|
|
AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
|
2002-09-10 15:36:11 +00:00
|
|
|
const std::string &Name = "", Instruction *InsertBefore = 0);
|
2002-03-21 22:37:01 +00:00
|
|
|
public:
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-11-01 02:39:36 +00:00
|
|
|
// isArrayAllocation - Return true if there is an allocation size parameter
|
2002-02-19 21:24:17 +00:00
|
|
|
// to the allocation instruction that is not 1.
|
2001-11-01 02:39:36 +00:00
|
|
|
//
|
2002-02-19 21:24:17 +00:00
|
|
|
bool isArrayAllocation() const;
|
2001-11-01 02:39:36 +00:00
|
|
|
|
2002-03-21 22:37:01 +00:00
|
|
|
// getArraySize - Get the number of element allocated, for a simple allocation
|
|
|
|
// of a single element, this will return a constant 1 value.
|
|
|
|
//
|
|
|
|
inline const Value *getArraySize() const { return Operands[0]; }
|
|
|
|
inline Value *getArraySize() { return Operands[0]; }
|
2001-11-01 02:39:36 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
// getType - Overload to return most specific pointer type...
|
|
|
|
inline const PointerType *getType() const {
|
|
|
|
return (const PointerType*)Instruction::getType();
|
|
|
|
}
|
|
|
|
|
2001-11-01 02:39:36 +00:00
|
|
|
// getAllocatedType - Return the type that is being allocated by the
|
|
|
|
// instruction.
|
2002-04-29 18:46:22 +00:00
|
|
|
//
|
|
|
|
const Type *getAllocatedType() const;
|
2001-11-01 02:39:36 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
virtual Instruction *clone() const = 0;
|
2002-03-18 05:00:51 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const AllocationInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Alloca ||
|
|
|
|
I->getOpcode() == Instruction::Malloc;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2001-07-08 21:10:27 +00:00
|
|
|
|
2001-07-08 23:22:50 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MallocInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-09-13 22:28:50 +00:00
|
|
|
class MallocInst : public AllocationInst {
|
|
|
|
MallocInst(const MallocInst &MI);
|
|
|
|
public:
|
2002-09-10 15:36:11 +00:00
|
|
|
MallocInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "",
|
|
|
|
Instruction *InsertBefore = 0)
|
|
|
|
: AllocationInst(Ty, ArraySize, Malloc, Name, InsertBefore) {}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
virtual Instruction *clone() const {
|
2002-09-13 22:28:50 +00:00
|
|
|
return new MallocInst(*this);
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2001-10-02 03:41:24 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const MallocInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Malloc);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2001-07-08 21:10:27 +00:00
|
|
|
|
2001-07-08 23:22:50 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AllocaInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-09-13 22:28:50 +00:00
|
|
|
class AllocaInst : public AllocationInst {
|
|
|
|
AllocaInst(const AllocaInst &);
|
|
|
|
public:
|
2002-09-10 15:36:11 +00:00
|
|
|
AllocaInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "",
|
|
|
|
Instruction *InsertBefore = 0)
|
|
|
|
: AllocationInst(Ty, ArraySize, Alloca, Name, InsertBefore) {}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
virtual Instruction *clone() const {
|
2002-09-13 22:28:50 +00:00
|
|
|
return new AllocaInst(*this);
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2001-10-02 03:41:24 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const AllocaInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Alloca);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-07-08 23:22:50 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FreeInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-04-29 18:46:22 +00:00
|
|
|
struct FreeInst : public Instruction {
|
2002-09-10 15:36:11 +00:00
|
|
|
FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-07-07 08:36:50 +00:00
|
|
|
virtual Instruction *clone() const { return new FreeInst(Operands[0]); }
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-02-24 20:48:32 +00:00
|
|
|
virtual bool mayWriteToMemory() const { return true; }
|
2001-10-02 03:41:24 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const FreeInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Free);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2001-07-08 21:10:27 +00:00
|
|
|
|
2001-07-08 23:22:50 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LoadInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-08-22 22:47:47 +00:00
|
|
|
class LoadInst : public Instruction {
|
|
|
|
LoadInst(const LoadInst &LI) : Instruction(LI.getType(), Load) {
|
|
|
|
Operands.reserve(1);
|
|
|
|
Operands.push_back(Use(LI.Operands[0], this));
|
2001-07-08 21:10:27 +00:00
|
|
|
}
|
|
|
|
public:
|
2002-09-10 15:36:11 +00:00
|
|
|
LoadInst(Value *Ptr, const std::string &Name = "",
|
|
|
|
Instruction *InsertBefore = 0);
|
2001-11-01 05:54:28 +00:00
|
|
|
|
2001-11-04 08:08:34 +00:00
|
|
|
virtual Instruction *clone() const { return new LoadInst(*this); }
|
2001-11-14 11:27:58 +00:00
|
|
|
|
2002-08-22 22:47:47 +00:00
|
|
|
Value *getPointerOperand() { return getOperand(0); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(0); }
|
2002-09-16 16:06:12 +00:00
|
|
|
static unsigned getPointerOperandIndex() { return 0U; }
|
2001-10-02 03:41:24 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const LoadInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Load);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-07-08 23:22:50 +00:00
|
|
|
};
|
2001-07-08 21:10:27 +00:00
|
|
|
|
2001-07-08 23:22:50 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// StoreInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-08-22 22:47:47 +00:00
|
|
|
class StoreInst : public Instruction {
|
|
|
|
StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store) {
|
|
|
|
Operands.reserve(2);
|
|
|
|
Operands.push_back(Use(SI.Operands[0], this));
|
|
|
|
Operands.push_back(Use(SI.Operands[1], this));
|
2001-07-08 23:22:50 +00:00
|
|
|
}
|
|
|
|
public:
|
2002-09-10 15:36:11 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore = 0);
|
2001-07-08 23:22:50 +00:00
|
|
|
virtual Instruction *clone() const { return new StoreInst(*this); }
|
2001-11-01 05:54:28 +00:00
|
|
|
|
2003-02-24 20:48:32 +00:00
|
|
|
virtual bool mayWriteToMemory() const { return true; }
|
2002-08-22 22:47:47 +00:00
|
|
|
|
|
|
|
Value *getPointerOperand() { return getOperand(1); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(1); }
|
2002-09-16 16:06:12 +00:00
|
|
|
static unsigned getPointerOperandIndex() { return 1U; }
|
2001-10-02 03:41:24 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const StoreInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Store);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-07-08 23:22:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// GetElementPtrInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-08-22 23:37:20 +00:00
|
|
|
class GetElementPtrInst : public Instruction {
|
2001-07-08 23:22:50 +00:00
|
|
|
GetElementPtrInst(const GetElementPtrInst &EPI)
|
2002-08-22 23:37:20 +00:00
|
|
|
: Instruction((Type*)EPI.getType(), GetElementPtr) {
|
2001-07-08 23:22:50 +00:00
|
|
|
Operands.reserve(EPI.Operands.size());
|
|
|
|
for (unsigned i = 0, E = EPI.Operands.size(); i != E; ++i)
|
|
|
|
Operands.push_back(Use(EPI.Operands[i], this));
|
|
|
|
}
|
|
|
|
public:
|
2002-01-20 22:54:45 +00:00
|
|
|
GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
|
2002-09-10 15:36:11 +00:00
|
|
|
const std::string &Name = "", Instruction *InsertBefore =0);
|
2001-07-08 23:22:50 +00:00
|
|
|
virtual Instruction *clone() const { return new GetElementPtrInst(*this); }
|
2001-07-20 21:07:06 +00:00
|
|
|
|
2001-11-01 05:54:28 +00:00
|
|
|
// getType - Overload to return most specific pointer type...
|
|
|
|
inline const PointerType *getType() const {
|
2002-04-29 18:46:22 +00:00
|
|
|
return (PointerType*)Instruction::getType();
|
2001-11-01 05:54:28 +00:00
|
|
|
}
|
2001-10-02 03:41:24 +00:00
|
|
|
|
2002-08-22 23:37:20 +00:00
|
|
|
/// getIndexedType - Returns the type of the element that would be loaded with
|
|
|
|
/// a load instruction with the specified parameters.
|
|
|
|
///
|
|
|
|
/// A null type is returned if the indices are invalid for the specified
|
|
|
|
/// pointer type.
|
|
|
|
///
|
|
|
|
static const Type *getIndexedType(const Type *Ptr,
|
|
|
|
const std::vector<Value*> &Indices,
|
|
|
|
bool AllowStructLeaf = false);
|
|
|
|
|
|
|
|
inline op_iterator idx_begin() {
|
|
|
|
return op_begin()+1;
|
|
|
|
}
|
|
|
|
inline const_op_iterator idx_begin() const {
|
|
|
|
return op_begin()+1;
|
|
|
|
}
|
|
|
|
inline op_iterator idx_end() { return op_end(); }
|
|
|
|
inline const_op_iterator idx_end() const { return op_end(); }
|
|
|
|
|
|
|
|
Value *getPointerOperand() {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
const Value *getPointerOperand() const {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
2002-09-16 16:06:12 +00:00
|
|
|
static unsigned getPointerOperandIndex() {
|
|
|
|
return 0U; // get index for modifying correct operand
|
|
|
|
}
|
|
|
|
|
2002-08-22 23:37:20 +00:00
|
|
|
inline unsigned getNumIndices() const { // Note: always non-negative
|
|
|
|
return getNumOperands() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool hasIndices() const {
|
|
|
|
return getNumOperands() > 1;
|
|
|
|
}
|
|
|
|
|
2001-10-02 03:41:24 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const GetElementPtrInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::GetElementPtr);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2001-07-08 21:10:27 +00:00
|
|
|
};
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif // LLVM_IMEMORY_H
|