1 //===-- llvm/iMemory.h - Memory Operator node definitions --------*- C++ -*--=//
3 // This file contains the declarations of all of the memory related operators.
4 // This includes: malloc, free, alloca, load, store, getfield, putfield
6 //===----------------------------------------------------------------------===//
11 #include "llvm/Instruction.h"
12 #include "llvm/DerivedTypes.h"
14 class AllocationInst : public Instruction {
16 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
17 const string &Name = "")
18 : Instruction(Ty, iTy, Name) {
19 assert(Ty->isPointerType() && "Can't allocate a non pointer type!");
22 // Make sure they didn't try to specify a size for !(unsized array) type...
23 assert((getType()->getValueType()->isArrayType() &&
24 ((const ArrayType*)getType()->getValueType())->isUnsized()) &&
25 "Trying to allocate something other than unsized array, with size!");
28 Operands.push_back(Use(ArraySize, this));
32 // getType - Overload to return most specific pointer type...
33 inline const PointerType *getType() const {
34 return (const PointerType*)Instruction::getType();
37 virtual Instruction *clone() const = 0;
40 class MallocInst : public AllocationInst {
42 MallocInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "")
43 : AllocationInst(Ty, ArraySize, Instruction::Malloc, Name) {}
45 virtual Instruction *clone() const {
46 return new MallocInst(getType(), Operands.size() ? Operands[1] : 0);
49 virtual const char *getOpcodeName() const { return "malloc"; }
52 class AllocaInst : public AllocationInst {
54 AllocaInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "")
55 : AllocationInst(Ty, ArraySize, Instruction::Alloca, Name) {}
57 virtual Instruction *clone() const {
58 return new AllocaInst(getType(), Operands.size() ? Operands[1] : 0);
61 virtual const char *getOpcodeName() const { return "alloca"; }
66 class FreeInst : public Instruction {
68 FreeInst(Value *Ptr, const string &Name = "")
69 : Instruction(Type::VoidTy, Instruction::Free, Name) {
70 assert(Ptr->getType()->isPointerType() && "Can't free nonpointer!");
72 Operands.push_back(Use(Ptr, this));
76 virtual Instruction *clone() const { return new FreeInst(Operands[0]); }
78 virtual const char *getOpcodeName() const { return "free"; }
81 #endif // LLVM_IMEMORY_H