First cut at the Code Generator using the TableGen methodology.
[oota-llvm.git] / include / llvm / iMemory.h
index ab1b593387ba66ce6513614697042e8b0186c702..09c94a2c77db62203120acfa34f89a2d66a5b43a 100644 (file)
@@ -21,7 +21,7 @@ class PointerType;
 class AllocationInst : public Instruction {
 protected:
   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, 
-                const std::string &Name = "");
+                const std::string &Name = "", Instruction *InsertBefore = 0);
 public:
 
   // isArrayAllocation - Return true if there is an allocation size parameter
@@ -63,12 +63,15 @@ public:
 //                                MallocInst Class
 //===----------------------------------------------------------------------===//
 
-struct MallocInst : public AllocationInst {
-  MallocInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "")
-    : AllocationInst(Ty, ArraySize, Malloc, Name) {}
+class MallocInst : public AllocationInst {
+  MallocInst(const MallocInst &MI);
+public:
+  MallocInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "",
+             Instruction *InsertBefore = 0)
+    : AllocationInst(Ty, ArraySize, Malloc, Name, InsertBefore) {}
 
   virtual Instruction *clone() const { 
-    return new MallocInst((Type*)getType(), (Value*)Operands[0].get());
+    return new MallocInst(*this);
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -86,12 +89,15 @@ struct MallocInst : public AllocationInst {
 //                                AllocaInst Class
 //===----------------------------------------------------------------------===//
 
-struct AllocaInst : public AllocationInst {
-  AllocaInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "")
-    : AllocationInst(Ty, ArraySize, Alloca, Name) {}
+class AllocaInst : public AllocationInst {
+  AllocaInst(const AllocaInst &);
+public:
+  AllocaInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "",
+             Instruction *InsertBefore = 0)
+    : AllocationInst(Ty, ArraySize, Alloca, Name, InsertBefore) {}
 
   virtual Instruction *clone() const { 
-    return new AllocaInst((Type*)getType(), (Value*)Operands[0].get());
+    return new AllocaInst(*this);
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -110,11 +116,11 @@ struct AllocaInst : public AllocationInst {
 //===----------------------------------------------------------------------===//
 
 struct FreeInst : public Instruction {
-  FreeInst(Value *Ptr);
+  FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
 
   virtual Instruction *clone() const { return new FreeInst(Operands[0]); }
 
-  virtual bool hasSideEffects() const { return true; }
+  virtual bool mayWriteToMemory() const { return true; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const FreeInst *) { return true; }
@@ -137,12 +143,14 @@ class LoadInst : public Instruction {
     Operands.push_back(Use(LI.Operands[0], this));
   }
 public:
-  LoadInst(Value *Ptr, const std::string &Name = "");
+  LoadInst(Value *Ptr, const std::string &Name = "",
+           Instruction *InsertBefore = 0);
 
   virtual Instruction *clone() const { return new LoadInst(*this); }
 
   Value *getPointerOperand() { return getOperand(0); }
   const Value *getPointerOperand() const { return getOperand(0); }
+  static unsigned getPointerOperandIndex() { return 0U; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const LoadInst *) { return true; }
@@ -166,13 +174,14 @@ class StoreInst : public Instruction {
     Operands.push_back(Use(SI.Operands[1], this));
   }
 public:
-  StoreInst(Value *Val, Value *Ptr);
+  StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore = 0);
   virtual Instruction *clone() const { return new StoreInst(*this); }
 
-  virtual bool hasSideEffects() const { return true; }
+  virtual bool mayWriteToMemory() const { return true; }
 
   Value *getPointerOperand() { return getOperand(1); }
   const Value *getPointerOperand() const { return getOperand(1); }
+  static unsigned getPointerOperandIndex() { return 1U; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const StoreInst *) { return true; }
@@ -198,7 +207,7 @@ class GetElementPtrInst : public Instruction {
   }
 public:
   GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
-                   const std::string &Name = "");
+                   const std::string &Name = "", Instruction *InsertBefore =0);
   virtual Instruction *clone() const { return new GetElementPtrInst(*this); }
   
   // getType - Overload to return most specific pointer type...
@@ -231,7 +240,10 @@ public:
   const Value *getPointerOperand() const {
     return getOperand(0);
   }
-  
+  static unsigned getPointerOperandIndex() {
+    return 0U;                      // get index for modifying correct operand
+  }
+
   inline unsigned getNumIndices() const {  // Note: always non-negative
     return getNumOperands() - 1;
   }