[llvm-commits] CVS: llvm/lib/VMCore/InstrTypes.cpp Instruction.cpp iBranch.cpp iCall.cpp iMemory.cpp iOperators.cpp iSwitch.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Sep 10 10:46:01 PDT 2002


Changes in directory llvm/lib/VMCore:

InstrTypes.cpp updated: 1.17 -> 1.18
Instruction.cpp updated: 1.18 -> 1.19
iBranch.cpp updated: 1.5 -> 1.6
iCall.cpp updated: 1.13 -> 1.14
iMemory.cpp updated: 1.25 -> 1.26
iOperators.cpp updated: 1.17 -> 1.18
iSwitch.cpp updated: 1.5 -> 1.6

---
Log message:

Add capability to insert an instruction into a basic block immediately after 
it is created, as part of the ctor call.

Eliminate the GenericBinaryInst class


---
Diffs of the changes:

Index: llvm/lib/VMCore/InstrTypes.cpp
diff -u llvm/lib/VMCore/InstrTypes.cpp:1.17 llvm/lib/VMCore/InstrTypes.cpp:1.18
--- llvm/lib/VMCore/InstrTypes.cpp:1.17	Wed Jul 24 17:08:49 2002
+++ llvm/lib/VMCore/InstrTypes.cpp	Tue Sep 10 10:45:53 2002
@@ -1,4 +1,4 @@
-//===-- InstrTypes.cpp - Implement Instruction subclasses --------*- C++ -*--=//
+//===-- InstrTypes.cpp - Implement Instruction subclasses -------*- C++ -*-===//
 //
 // This file implements 
 //
@@ -15,25 +15,15 @@
 //                            TerminatorInst Class
 //===----------------------------------------------------------------------===//
 
-TerminatorInst::TerminatorInst(Instruction::TermOps iType) 
-  : Instruction(Type::VoidTy, iType, "") {
+TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB) 
+  : Instruction(Type::VoidTy, iType, "", IB) {
 }
 
-TerminatorInst::TerminatorInst(const Type *Ty, Instruction::TermOps iType,
-			       const std::string &Name)
-  : Instruction(Ty, iType, Name) {
-}
-
-
 //===----------------------------------------------------------------------===//
 //                               PHINode Class
 //===----------------------------------------------------------------------===//
 
-PHINode::PHINode(const Type *Ty, const std::string &name) 
-  : Instruction(Ty, Instruction::PHINode, name) {
-}
-
-PHINode::PHINode(const PHINode &PN) 
+PHINode::PHINode(const PHINode &PN)
   : Instruction(PN.getType(), Instruction::PHINode) {
   Operands.reserve(PN.Operands.size());
   for (unsigned i = 0; i < PN.Operands.size(); i+=2) {


Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.18 llvm/lib/VMCore/Instruction.cpp:1.19
--- llvm/lib/VMCore/Instruction.cpp:1.18	Sun Sep  8 13:59:35 2002
+++ llvm/lib/VMCore/Instruction.cpp	Tue Sep 10 10:45:53 2002
@@ -9,13 +9,21 @@
 #include "llvm/Type.h"
 #include "Support/LeakDetector.h"
 
-Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name) 
+Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name,
+                         Instruction *InsertBefore)
   : User(ty, Value::InstructionVal, Name) {
   Parent = 0;
   iType = it;
 
   // Make sure that we get added to a basicblock
   LeakDetector::addGarbageObject(this);
+
+  // If requested, insert this instruction into a basic block...
+  if (InsertBefore) {
+    assert(InsertBefore->getParent() &&
+           "Instruction to insert before is not in a basic block!");
+    InsertBefore->getParent()->getInstList().insert(InsertBefore, this);
+  }
 }
 
 void Instruction::setParent(BasicBlock *P) {


Index: llvm/lib/VMCore/iBranch.cpp
diff -u llvm/lib/VMCore/iBranch.cpp:1.5 llvm/lib/VMCore/iBranch.cpp:1.6
--- llvm/lib/VMCore/iBranch.cpp:1.5	Tue Jun 25 11:13:05 2002
+++ llvm/lib/VMCore/iBranch.cpp	Tue Sep 10 10:45:53 2002
@@ -9,8 +9,9 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Type.h"
 
-BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond) 
-  : TerminatorInst(Instruction::Br) {
+BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
+                       Instruction *InsertBefore) 
+  : TerminatorInst(Instruction::Br, InsertBefore) {
   assert(True != 0 && "True branch destination may not be null!!!");
   Operands.reserve(False ? 3 : 1);
   Operands.push_back(Use(True, this));


Index: llvm/lib/VMCore/iCall.cpp
diff -u llvm/lib/VMCore/iCall.cpp:1.13 llvm/lib/VMCore/iCall.cpp:1.14
--- llvm/lib/VMCore/iCall.cpp:1.13	Tue Apr  9 13:36:52 2002
+++ llvm/lib/VMCore/iCall.cpp	Tue Sep 10 10:45:53 2002
@@ -14,10 +14,10 @@
 //===----------------------------------------------------------------------===//
 
 CallInst::CallInst(Value *Func, const std::vector<Value*> &params, 
-                   const std::string &Name) 
+                   const std::string &Name, Instruction *InsertBefore) 
   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
 				 ->getElementType())->getReturnType(),
-		Instruction::Call, Name) {
+		Instruction::Call, Name, InsertBefore) {
   Operands.reserve(1+params.size());
   Operands.push_back(Use(Func, this));
 
@@ -46,10 +46,10 @@
 InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
 		       BasicBlock *IfException,
                        const std::vector<Value*> &params,
-		       const std::string &Name)
+		       const std::string &Name, Instruction *InsertBefore)
   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
 				    ->getElementType())->getReturnType(),
-		   Instruction::Invoke, Name) {
+		   Instruction::Invoke, Name, InsertBefore) {
   Operands.reserve(3+params.size());
   Operands.push_back(Use(Func, this));
   Operands.push_back(Use((Value*)IfNormal, this));


Index: llvm/lib/VMCore/iMemory.cpp
diff -u llvm/lib/VMCore/iMemory.cpp:1.25 llvm/lib/VMCore/iMemory.cpp:1.26
--- llvm/lib/VMCore/iMemory.cpp:1.25	Thu Aug 22 18:37:09 2002
+++ llvm/lib/VMCore/iMemory.cpp	Tue Sep 10 10:45:53 2002
@@ -8,14 +8,9 @@
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 
-static inline const Type *checkType(const Type *Ty) {
-  assert(Ty && "Invalid indices for type!");
-  return Ty;
-}
-
 AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, 
-                               const std::string &Name)
-  : Instruction(Ty, iTy, Name) {
+                               const std::string &Name, Instruction *InsertBef)
+  : Instruction(Ty, iTy, Name, InsertBef) {
   assert(isa<PointerType>(Ty) && "Can't allocate a non pointer type!");
 
   // ArraySize defaults to 1.
@@ -37,14 +32,25 @@
   return getType()->getElementType();
 }
 
+//===----------------------------------------------------------------------===//
+//                             FreeInst Implementation
+//===----------------------------------------------------------------------===//
+
+FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore)
+  : Instruction(Type::VoidTy, Free, "", InsertBefore) {
+  assert(isa<PointerType>(Ptr->getType()) && "Can't free nonpointer!");
+  Operands.reserve(1);
+  Operands.push_back(Use(Ptr, this));
+}
+
 
 //===----------------------------------------------------------------------===//
 //                           LoadInst Implementation
 //===----------------------------------------------------------------------===//
 
-LoadInst::LoadInst(Value *Ptr, const std::string &Name)
+LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef)
   : Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
-                Load, Name) {
+                Load, Name, InsertBef) {
   Operands.reserve(1);
   Operands.push_back(Use(Ptr, this));
 }
@@ -54,8 +60,8 @@
 //                           StoreInst Implementation
 //===----------------------------------------------------------------------===//
 
-StoreInst::StoreInst(Value *Val, Value *Ptr)
-  : Instruction(Type::VoidTy, Store, "") {
+StoreInst::StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore)
+  : Instruction(Type::VoidTy, Store, "", InsertBefore) {
   
   Operands.reserve(2);
   Operands.push_back(Use(Val, this));
@@ -67,11 +73,19 @@
 //                       GetElementPtrInst Implementation
 //===----------------------------------------------------------------------===//
 
+// checkType - Simple wrapper function to give a better assertion failure
+// message on bad indexes for a gep instruction.
+//
+static inline const Type *checkType(const Type *Ty) {
+  assert(Ty && "Invalid indices for type!");
+  return Ty;
+}
+
 GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
-				     const std::string &Name)
+				     const std::string &Name, Instruction *InBe)
   : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
                                                             Idx, true))),
-		  GetElementPtr, Name) {
+		  GetElementPtr, Name, InBe) {
   assert(getIndexedType(Ptr->getType(), Idx, true) && "gep operands invalid!");
   Operands.reserve(1+Idx.size());
   Operands.push_back(Use(Ptr, this));
@@ -107,15 +121,3 @@
   }
   return CurIDX == Idx.size() ? Ptr : 0;
 }
-
-
-//===----------------------------------------------------------------------===//
-//                             FreeInst Implementation
-//===----------------------------------------------------------------------===//
-
-FreeInst::FreeInst(Value *Ptr) : Instruction(Type::VoidTy, Free, "") {
-  assert(isa<PointerType>(Ptr->getType()) && "Can't free nonpointer!");
-  Operands.reserve(1);
-  Operands.push_back(Use(Ptr, this));
-}
-


Index: llvm/lib/VMCore/iOperators.cpp
diff -u llvm/lib/VMCore/iOperators.cpp:1.17 llvm/lib/VMCore/iOperators.cpp:1.18
--- llvm/lib/VMCore/iOperators.cpp:1.17	Sun Sep  1 14:46:40 2002
+++ llvm/lib/VMCore/iOperators.cpp	Tue Sep 10 10:45:53 2002
@@ -7,33 +7,54 @@
 #include "llvm/iOperators.h"
 #include "llvm/Type.h"
 #include "llvm/Constants.h"
+#include "llvm/BasicBlock.h"
 
 //===----------------------------------------------------------------------===//
 //                             BinaryOperator Class
 //===----------------------------------------------------------------------===//
 
+BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2, 
+                               const Type *Ty, const std::string &Name,
+                               Instruction *InsertBefore)
+  : Instruction(Ty, iType, Name, InsertBefore) {
+  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 *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
-				       const std::string &Name) {
+				       const std::string &Name,
+                                       Instruction *InsertBefore) {
+  assert(S1->getType() == S2->getType() &&
+         "Cannot create binary operator with two operands of differing type!");
   switch (Op) {
   // Binary comparison operators...
   case SetLT: case SetGT: case SetLE:
   case SetGE: case SetEQ: case SetNE:
-    return new SetCondInst(Op, S1, S2, Name);
+    return new SetCondInst(Op, S1, S2, Name, InsertBefore);
 
   default:
-    return new GenericBinaryInst(Op, S1, S2, Name);
+    return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
   }
 }
 
-BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name) {
-  return new GenericBinaryInst(Instruction::Sub,
-                               Constant::getNullValue(Op->getType()), Op, Name);
+BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
+                                          Instruction *InsertBefore) {
+  return new BinaryOperator(Instruction::Sub,
+                            Constant::getNullValue(Op->getType()), Op,
+                            Op->getType(), Name, InsertBefore);
 }
 
-BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name) {
-  return new GenericBinaryInst(Instruction::Xor, Op,
-                               ConstantIntegral::getAllOnesValue(Op->getType()),
-                               Name);
+BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
+                                          Instruction *InsertBefore) {
+  return new BinaryOperator(Instruction::Xor, Op,
+                            ConstantIntegral::getAllOnesValue(Op->getType()),
+                            Op->getType(), Name, InsertBefore);
 }
 
 
@@ -111,15 +132,12 @@
 //                             SetCondInst Class
 //===----------------------------------------------------------------------===//
 
-SetCondInst::SetCondInst(BinaryOps opType, Value *S1, Value *S2, 
-                         const std::string &Name) 
-  : BinaryOperator(opType, S1, S2, Name) {
-
-  OpType = opType;
-  setType(Type::BoolTy);   // setcc instructions always return bool type.
+SetCondInst::SetCondInst(BinaryOps Opcode, Value *S1, Value *S2, 
+                         const std::string &Name, Instruction *InsertBefore)
+  : BinaryOperator(Opcode, S1, S2, Type::BoolTy, Name, InsertBefore) {
 
-  // Make sure it's a valid type...
-  assert(getOpcodeName() != 0);
+  // Make sure it's a valid type... getInverseCondition will assert out if not.
+  assert(getInverseCondition(Opcode));
 }
 
 // getInverseCondition - Return the inverse of the current condition opcode.


Index: llvm/lib/VMCore/iSwitch.cpp
diff -u llvm/lib/VMCore/iSwitch.cpp:1.5 llvm/lib/VMCore/iSwitch.cpp:1.6
--- llvm/lib/VMCore/iSwitch.cpp:1.5	Tue Jun 25 11:13:05 2002
+++ llvm/lib/VMCore/iSwitch.cpp	Tue Sep 10 10:45:53 2002
@@ -7,11 +7,12 @@
 #include "llvm/iTerminators.h"
 #include "llvm/BasicBlock.h"
 
-SwitchInst::SwitchInst(Value *V, BasicBlock *DefDest) 
-  : TerminatorInst(Instruction::Switch) {
-  assert(V && DefDest);
+SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
+                       Instruction *InsertBefore) 
+  : TerminatorInst(Instruction::Switch, InsertBefore) {
+  assert(V && DefaultDest);
   Operands.push_back(Use(V, this));
-  Operands.push_back(Use(DefDest, this));
+  Operands.push_back(Use(DefaultDest, this));
 }
 
 SwitchInst::SwitchInst(const SwitchInst &SI) 





More information about the llvm-commits mailing list