[llvm-commits] CVS: llvm/include/llvm/InstrTypes.h Instruction.h iMemory.h iOther.h iPHINode.h iTerminators.h

Chris Lattner lattner at cs.uiuc.edu
Tue Sep 10 10:37:00 PDT 2002


Changes in directory llvm/include/llvm:

InstrTypes.h updated: 1.28 -> 1.29
Instruction.h updated: 1.33 -> 1.34
iMemory.h updated: 1.34 -> 1.35
iOther.h updated: 1.29 -> 1.30
iPHINode.h updated: 1.3 -> 1.4
iTerminators.h updated: 1.22 -> 1.23

---
Log message:

Implement support for inserting an instruction into a basic block right when it
is created.


---
Diffs of the changes:

Index: llvm/include/llvm/InstrTypes.h
diff -u llvm/include/llvm/InstrTypes.h:1.28 llvm/include/llvm/InstrTypes.h:1.29
--- llvm/include/llvm/InstrTypes.h:1.28	Sun Aug 25 17:54:54 2002
+++ llvm/include/llvm/InstrTypes.h	Tue Sep 10 10:36:07 2002
@@ -20,9 +20,11 @@
 ///
 class TerminatorInst : public Instruction {
 protected:
-  TerminatorInst(Instruction::TermOps iType);
+  TerminatorInst(Instruction::TermOps iType, Instruction *InsertBefore = 0);
   TerminatorInst(const Type *Ty, Instruction::TermOps iType,
-                 const std::string &Name = "");
+                 const std::string &Name = "", Instruction *InsertBefore = 0)
+    : Instruction(Ty, iType, Name, InsertBefore) {
+  }
 public:
 
   /// Terminators must implement the methods required by Instruction...
@@ -59,23 +61,20 @@
 
 class BinaryOperator : public Instruction {
 protected:
-  BinaryOperator(BinaryOps iType, Value *S1, Value *S2, 
-                 const std::string &Name = "") 
-    : Instruction(S1->getType(), iType, Name) {
-    Operands.reserve(2);
-    Operands.push_back(Use(S1, this));
-    Operands.push_back(Use(S2, this));
-    assert(Operands[0] && Operands[1] && 
-	   Operands[0]->getType() == Operands[1]->getType());
-  }
+  BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
+                 const std::string &Name, Instruction *InsertBefore);
 
 public:
 
-  /// create() - Construct a binary instruction, given the opcode
-  /// and the two operands.
+  /// create() - Construct a binary instruction, given the opcode and the two
+  /// operands.  Optionally (if InstBefore is specified) insert the instruction
+  /// into a BasicBlock right before the specified instruction.  The specified
+  /// Instruction is allowed to be a dereferenced end iterator.
   ///
   static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
-				const std::string &Name = "");
+				const std::string &Name = "",
+                                Instruction *InsertBefore = 0);
+                               
 
   /// Helper functions to construct and inspect unary operations (NEG and NOT)
   /// via binary operators SUB and XOR:
@@ -83,8 +82,10 @@
   /// createNeg, createNot - Create the NEG and NOT
   ///     instructions out of SUB and XOR instructions.
   ///
-  static BinaryOperator *createNeg(Value *Op, const std::string &Name = "");
-  static BinaryOperator *createNot(Value *Op, const std::string &Name = "");
+  static BinaryOperator *createNeg(Value *Op, const std::string &Name = "",
+                                   Instruction *InsertBefore = 0);
+  static BinaryOperator *createNot(Value *Op, const std::string &Name = "",
+                                   Instruction *InsertBefore = 0);
 
   /// isNeg, isNot - Check if the given Value is a NEG or NOT instruction.
   ///


Index: llvm/include/llvm/Instruction.h
diff -u llvm/include/llvm/Instruction.h:1.33 llvm/include/llvm/Instruction.h:1.34
--- llvm/include/llvm/Instruction.h:1.33	Fri Sep  6 16:31:57 2002
+++ llvm/include/llvm/Instruction.h	Tue Sep 10 10:36:08 2002
@@ -1,4 +1,4 @@
-//===-- llvm/Instruction.h - Instruction class definition --------*- C++ -*--=//
+//===-- llvm/Instruction.h - Instruction class definition -------*- C++ -*-===//
 //
 // This file contains the declaration of the Instruction class, which is the
 // base class for all of the LLVM instructions.
@@ -25,8 +25,10 @@
   void setParent(BasicBlock *P);
 protected:
   unsigned iType;      // InstructionType: The opcode of the instruction
+
+  Instruction(const Type *Ty, unsigned iType, const std::string &Name = "",
+              Instruction *InsertBefore = 0);
 public:
-  Instruction(const Type *Ty, unsigned iType, const std::string &Name = "");
   virtual ~Instruction() {
     assert(Parent == 0 && "Instruction still embedded in basic block!");
   }


Index: llvm/include/llvm/iMemory.h
diff -u llvm/include/llvm/iMemory.h:1.34 llvm/include/llvm/iMemory.h:1.35
--- llvm/include/llvm/iMemory.h:1.34	Thu Aug 22 18:37:20 2002
+++ llvm/include/llvm/iMemory.h	Tue Sep 10 10:36:09 2002
@@ -21,7 +21,7 @@
 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
@@ -64,8 +64,9 @@
 //===----------------------------------------------------------------------===//
 
 struct MallocInst : public AllocationInst {
-  MallocInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "")
-    : AllocationInst(Ty, ArraySize, Malloc, Name) {}
+  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());
@@ -87,8 +88,9 @@
 //===----------------------------------------------------------------------===//
 
 struct AllocaInst : public AllocationInst {
-  AllocaInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "")
-    : AllocationInst(Ty, ArraySize, Alloca, Name) {}
+  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());
@@ -110,7 +112,7 @@
 //===----------------------------------------------------------------------===//
 
 struct FreeInst : public Instruction {
-  FreeInst(Value *Ptr);
+  FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
 
   virtual Instruction *clone() const { return new FreeInst(Operands[0]); }
 
@@ -137,7 +139,8 @@
     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); }
 
@@ -166,7 +169,7 @@
     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; }
@@ -198,7 +201,7 @@
   }
 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...


Index: llvm/include/llvm/iOther.h
diff -u llvm/include/llvm/iOther.h:1.29 llvm/include/llvm/iOther.h:1.30
--- llvm/include/llvm/iOther.h:1.29	Sun Jul 14 17:43:35 2002
+++ llvm/include/llvm/iOther.h	Tue Sep 10 10:36:10 2002
@@ -1,7 +1,7 @@
 //===-- llvm/iOther.h - "Other" instruction node definitions -----*- C++ -*--=//
 //
 // This file contains the declarations for instructions that fall into the 
-// grandios 'other' catagory...
+// grandiose 'other' catagory...
 //
 //===----------------------------------------------------------------------===//
 
@@ -14,17 +14,18 @@
 //                                 CastInst Class
 //===----------------------------------------------------------------------===//
 
-// CastInst - This class represents a cast from Operand[0] to the type of
-// the instruction (i->getType()).
-//
+/// CastInst - This class represents a cast from Operand[0] to the type of
+/// the instruction (i->getType()).
+///
 class CastInst : public Instruction {
   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
     Operands.reserve(1);
     Operands.push_back(Use(CI.Operands[0], this));
   }
 public:
-  CastInst(Value *S, const Type *Ty, const std::string &Name = "")
-    : Instruction(Ty, Cast, Name) {
+  CastInst(Value *S, const Type *Ty, const std::string &Name = "",
+           Instruction *InsertBefore = 0)
+    : Instruction(Ty, Cast, Name, InsertBefore) {
     Operands.reserve(1);
     Operands.push_back(Use(S, this));
   }
@@ -43,13 +44,14 @@
 
 
 //===----------------------------------------------------------------------===//
-//             Classes to function calls and method invocations
+//                                 CallInst Class
 //===----------------------------------------------------------------------===//
 
 class CallInst : public Instruction {
   CallInst(const CallInst &CI);
 public:
-  CallInst(Value *M, const std::vector<Value*> &Par, const std::string & = "");
+  CallInst(Value *F, const std::vector<Value*> &Par,
+           const std::string &Name = "", Instruction *InsertBefore = 0);
 
   virtual Instruction *clone() const { return new CallInst(*this); }
   bool hasSideEffects() const { return true; }
@@ -89,8 +91,9 @@
     Operands.push_back(Use(SI.Operands[1], this));
   }
 public:
-  ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "")
-    : Instruction(S->getType(), Opcode, Name) {
+  ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
+            Instruction *InsertBefore = 0)
+    : Instruction(S->getType(), Opcode, Name, InsertBefore) {
     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
     Operands.reserve(2);
     Operands.push_back(Use(S, this));


Index: llvm/include/llvm/iPHINode.h
diff -u llvm/include/llvm/iPHINode.h:1.3 llvm/include/llvm/iPHINode.h:1.4
--- llvm/include/llvm/iPHINode.h:1.3	Sun Jul 14 17:43:36 2002
+++ llvm/include/llvm/iPHINode.h	Tue Sep 10 10:36:11 2002
@@ -21,26 +21,30 @@
 class PHINode : public Instruction {
   PHINode(const PHINode &PN);
 public:
-  PHINode(const Type *Ty, const std::string &Name = "");
+  PHINode(const Type *Ty, const std::string &Name = "",
+          Instruction *InsertBefore = 0)
+    : Instruction(Ty, Instruction::PHINode, Name, InsertBefore) {
+  }
 
   virtual Instruction *clone() const { return new PHINode(*this); }
 
-  // getNumIncomingValues - Return the number of incoming edges the PHI node has
-  inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
+  /// getNumIncomingValues - Return the number of incoming edges the PHI node
+  /// has
+  unsigned getNumIncomingValues() const { return Operands.size()/2; }
 
-  // getIncomingValue - Return incoming value #x
-  inline const Value *getIncomingValue(unsigned i) const {
+  /// getIncomingValue - Return incoming value #x
+  const Value *getIncomingValue(unsigned i) const {
     return Operands[i*2];
   }
-  inline Value *getIncomingValue(unsigned i) {
+  Value *getIncomingValue(unsigned i) {
     return Operands[i*2];
   }
-  inline void setIncomingValue(unsigned i, Value *V) {
+  void setIncomingValue(unsigned i, Value *V) {
     Operands[i*2] = V;
   }
 
-  // getIncomingBlock - Return incoming basic block #x
-  inline const BasicBlock *getIncomingBlock(unsigned i) const { 
+  /// getIncomingBlock - Return incoming basic block #x
+  const BasicBlock *getIncomingBlock(unsigned i) const { 
     return (const BasicBlock*)Operands[i*2+1].get();
   }
   inline BasicBlock *getIncomingBlock(unsigned i) { 
@@ -50,23 +54,23 @@
     Operands[i*2+1] = (Value*)BB;
   }
 
-  // addIncoming - Add an incoming value to the end of the PHI list
+  /// addIncoming - Add an incoming value to the end of the PHI list
   void addIncoming(Value *D, BasicBlock *BB);
-
-  // removeIncomingValue - Remove an incoming value.  This is useful if a
-  // predecessor basic block is deleted.  The value removed is returned.
+  
+  /// removeIncomingValue - Remove an incoming value.  This is useful if a
+  /// predecessor basic block is deleted.  The value removed is returned.
   Value *removeIncomingValue(const BasicBlock *BB);
 
-  // getBasicBlockIndex - Return the first index of the specified basic 
-  // block in the value list for this PHI.  Returns -1 if no instance.
-  //
+  /// getBasicBlockIndex - Return the first index of the specified basic 
+  /// block in the value list for this PHI.  Returns -1 if no instance.
+  ///
   int getBasicBlockIndex(const BasicBlock *BB) const {
     for (unsigned i = 0; i < Operands.size()/2; ++i) 
       if (getIncomingBlock(i) == BB) return i;
     return -1;
   }
 
-  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const PHINode *) { return true; }
   static inline bool classof(const Instruction *I) {
     return I->getOpcode() == Instruction::PHINode; 


Index: llvm/include/llvm/iTerminators.h
diff -u llvm/include/llvm/iTerminators.h:1.22 llvm/include/llvm/iTerminators.h:1.23
--- llvm/include/llvm/iTerminators.h:1.22	Thu Jul 25 10:39:05 2002
+++ llvm/include/llvm/iTerminators.h	Tue Sep 10 10:36:11 2002
@@ -1,9 +1,8 @@
-//===-- llvm/iTerminators.h - Termintator instruction nodes ------*- C++ -*--=//
+//===-- llvm/iTerminators.h - Termintator instruction nodes -----*- C++ -*-===//
 //
-// This file contains the declarations for all the subclasses of the
-// Instruction class, which is itself defined in the Instruction.h file.  In 
-// between these definitions and the Instruction class are classes that expose
-// the SSA properties of each instruction, and that form the SSA graph.
+// This file contains the declarations for all the subclasses of the Instruction
+// class which represent "terminator" instructions.  Terminator instructions are
+// the only instructions allowed and required to terminate a BasicBlock.
 //
 //===----------------------------------------------------------------------===//
 
@@ -12,11 +11,6 @@
 
 #include "llvm/InstrTypes.h"
 
-//===----------------------------------------------------------------------===//
-//         Classes to represent Basic Block "Terminator" instructions
-//===----------------------------------------------------------------------===//
-
-
 //===---------------------------------------------------------------------------
 // ReturnInst - Return a value (possibly void), from a method.  Execution does
 //              not continue in this method any longer.
@@ -30,7 +24,8 @@
     }
   }
 public:
-  ReturnInst(Value *RetVal = 0) : TerminatorInst(Instruction::Ret) {
+  ReturnInst(Value *RetVal = 0, Instruction *InsertBefore = 0)
+    : TerminatorInst(Instruction::Ret, InsertBefore) {
     if (RetVal) {
       Operands.reserve(1);
       Operands.push_back(Use(RetVal, this));
@@ -74,7 +69,8 @@
   BranchInst(const BranchInst &BI);
 public:
   // If cond = null, then is an unconditional br...
-  BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse = 0, Value *cond = 0);
+  BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse = 0, Value *cond = 0,
+             Instruction *InsertBefore = 0);
 
   virtual Instruction *clone() const { return new BranchInst(*this); }
 
@@ -84,7 +80,7 @@
   inline const Value *getCondition() const {
     return isUnconditional() ? 0 : Operands[2].get();
   }
-  inline       Value *getCondition()       {
+  Value *getCondition() {
     return isUnconditional() ? 0 : Operands[2].get();
   }
 
@@ -133,7 +129,7 @@
   // Operand[2n+1] = BasicBlock to go to on match
   SwitchInst(const SwitchInst &RI);
 public:
-  SwitchInst(Value *Value, BasicBlock *Default);
+  SwitchInst(Value *Value, BasicBlock *Default, Instruction *InsertBefore = 0);
 
   virtual Instruction *clone() const { return new SwitchInst(*this); }
 
@@ -194,7 +190,8 @@
   InvokeInst(const InvokeInst &BI);
 public:
   InvokeInst(Value *Meth, BasicBlock *IfNormal, BasicBlock *IfException,
-	     const std::vector<Value*> &Params, const std::string &Name = "");
+	     const std::vector<Value*> &Params, const std::string &Name = "",
+             Instruction *InsertBefore = 0);
 
   virtual Instruction *clone() const { return new InvokeInst(*this); }
 





More information about the llvm-commits mailing list