[llvm-commits] CVS: llvm/lib/VMCore/iOperators.cpp iMemory.cpp iCall.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Wed May 26 19:18:01 PDT 2004


Changes in directory llvm/lib/VMCore:

iOperators.cpp updated: 1.26 -> 1.27
iMemory.cpp updated: 1.39 -> 1.40
iCall.cpp updated: 1.24 -> 1.25

---
Log message:

Add constructors that take a BasicBlock to append to, to the rest of
the llvm::Instruction hierarchy.


---
Diffs of the changes:  (+175 -45)

Index: llvm/lib/VMCore/iOperators.cpp
diff -u llvm/lib/VMCore/iOperators.cpp:1.26 llvm/lib/VMCore/iOperators.cpp:1.27
--- llvm/lib/VMCore/iOperators.cpp:1.26	Mon Feb  2 14:21:29 2004
+++ llvm/lib/VMCore/iOperators.cpp	Wed May 26 19:15:23 2004
@@ -21,11 +21,8 @@
 //                             BinaryOperator Class
 //===----------------------------------------------------------------------===//
 
-BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2, 
-                               const Type *Ty, const std::string &Name,
-                               Instruction *InsertBefore)
-  : Instruction(Ty, iType, Name, InsertBefore) {
-
+void BinaryOperator::init(BinaryOps iType, Value *S1, Value *S2)
+{
   Operands.reserve(2);
   Operands.push_back(Use(S1, this));
   Operands.push_back(Use(S2, this));
@@ -36,30 +33,27 @@
   case Add: case Sub:
   case Mul: case Div:
   case Rem:
-    assert(Ty == S1->getType() &&
+    assert(getType() == S1->getType() &&
            "Arithmetic operation should return same type as operands!");
-    assert((Ty->isInteger() || Ty->isFloatingPoint()) && 
+    assert((getType()->isInteger() || getType()->isFloatingPoint()) && 
            "Tried to create an arithmetic operation on a non-arithmetic type!");
     break;
   case And: case Or:
   case Xor:
-    assert(Ty == S1->getType() &&
+    assert(getType() == S1->getType() &&
            "Logical operation should return same type as operands!");
-    assert(Ty->isIntegral() &&
+    assert(getType()->isIntegral() &&
            "Tried to create an logical operation on a non-integral type!");
     break;
   case SetLT: case SetGT: case SetLE:
   case SetGE: case SetEQ: case SetNE:
-    assert(Ty == Type::BoolTy && "Setcc must return bool!");
+    assert(getType() == Type::BoolTy && "Setcc must return bool!");
   default:
     break;
   }
 #endif
 }
 
-
-
-
 BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
 				       const std::string &Name,
                                        Instruction *InsertBefore) {
@@ -76,6 +70,22 @@
   }
 }
 
+BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
+				       const std::string &Name,
+                                       BasicBlock *InsertAtEnd) {
+  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, InsertAtEnd);
+
+  default:
+    return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertAtEnd);
+  }
+}
+
 BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
                                           Instruction *InsertBefore) {
   if (!Op->getType()->isFloatingPoint())
@@ -88,6 +98,18 @@
                               Op->getType(), Name, InsertBefore);
 }
 
+BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
+                                          BasicBlock *InsertAtEnd) {
+  if (!Op->getType()->isFloatingPoint())
+    return new BinaryOperator(Instruction::Sub,
+                              Constant::getNullValue(Op->getType()), Op,
+                              Op->getType(), Name, InsertAtEnd);
+  else
+    return new BinaryOperator(Instruction::Sub,
+                              ConstantFP::get(Op->getType(), -0.0), Op,
+                              Op->getType(), Name, InsertAtEnd);
+}
+
 BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
                                           Instruction *InsertBefore) {
   return new BinaryOperator(Instruction::Xor, Op,
@@ -95,6 +117,13 @@
                             Op->getType(), Name, InsertBefore);
 }
 
+BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
+                                          BasicBlock *InsertAtEnd) {
+  return new BinaryOperator(Instruction::Xor, Op,
+                            ConstantIntegral::getAllOnesValue(Op->getType()),
+                            Op->getType(), Name, InsertAtEnd);
+}
+
 
 // isConstantAllOnes - Helper function for several functions below
 static inline bool isConstantAllOnes(const Value *V) {
@@ -168,6 +197,14 @@
 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... getInverseCondition will assert out if not.
+  assert(getInverseCondition(Opcode));
+}
+
+SetCondInst::SetCondInst(BinaryOps Opcode, Value *S1, Value *S2, 
+                         const std::string &Name, BasicBlock *InsertAtEnd)
+  : BinaryOperator(Opcode, S1, S2, Type::BoolTy, Name, InsertAtEnd) {
 
   // Make sure it's a valid type... getInverseCondition will assert out if not.
   assert(getInverseCondition(Opcode));


Index: llvm/lib/VMCore/iMemory.cpp
diff -u llvm/lib/VMCore/iMemory.cpp:1.39 llvm/lib/VMCore/iMemory.cpp:1.40
--- llvm/lib/VMCore/iMemory.cpp:1.39	Wed May 26 16:41:09 2004
+++ llvm/lib/VMCore/iMemory.cpp	Wed May 26 19:15:23 2004
@@ -16,10 +16,8 @@
 #include "llvm/DerivedTypes.h"
 using namespace llvm;
 
-AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, 
-                               const std::string &Name, Instruction *InsertBef)
-  : Instruction(PointerType::get(Ty), iTy, Name, InsertBef) {
-
+void AllocationInst::init(const Type *Ty, Value *ArraySize, unsigned iTy)
+{
   // ArraySize defaults to 1.
   if (!ArraySize) ArraySize = ConstantUInt::get(Type::UIntTy, 1);
 
@@ -30,6 +28,20 @@
   Operands.push_back(Use(ArraySize, this));
 }
 
+AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, 
+                               const std::string &Name,
+                               Instruction *InsertBefore)
+  : Instruction(PointerType::get(Ty), iTy, Name, InsertBefore) {
+  init(Ty, ArraySize, iTy);
+}
+
+AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, 
+                               const std::string &Name,
+                               BasicBlock *InsertAtEnd)
+  : Instruction(PointerType::get(Ty), iTy, Name, InsertAtEnd) {
+  init(Ty, ArraySize, iTy);
+}
+
 bool AllocationInst::isArrayAllocation() const {
   return getOperand(0) != ConstantUInt::get(Type::UIntTy, 1);
 }
@@ -52,13 +64,23 @@
 //                             FreeInst Implementation
 //===----------------------------------------------------------------------===//
 
-FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore)
-  : Instruction(Type::VoidTy, Free, "", InsertBefore) {
-  assert(isa<PointerType>(Ptr->getType()) && "Can't free nonpointer!");
+void FreeInst::init(Value *Ptr)
+{
+  assert(Ptr && isa<PointerType>(Ptr->getType()) && "Can't free nonpointer!");
   Operands.reserve(1);
   Operands.push_back(Use(Ptr, this));
 }
 
+FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore)
+  : Instruction(Type::VoidTy, Free, "", InsertBefore) {
+  init(Ptr);
+}
+
+FreeInst::FreeInst(Value *Ptr, BasicBlock *InsertAtEnd)
+  : Instruction(Type::VoidTy, Free, "", InsertAtEnd) {
+  init(Ptr);
+}
+
 
 //===----------------------------------------------------------------------===//
 //                           LoadInst Implementation
@@ -70,6 +92,12 @@
   init(Ptr);
 }
 
+LoadInst::LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAE)
+  : Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
+                Load, Name, InsertAE), Volatile(false) {
+  init(Ptr);
+}
+
 LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
                    Instruction *InsertBef)
   : Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
@@ -77,6 +105,13 @@
   init(Ptr);
 }
 
+LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
+                   BasicBlock *InsertAE)
+  : Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
+                Load, Name, InsertAE), Volatile(isVolatile) {
+  init(Ptr);
+}
+
 //===----------------------------------------------------------------------===//
 //                           StoreInst Implementation
 //===----------------------------------------------------------------------===//
@@ -86,12 +121,23 @@
   init(Val, Ptr);
 }
 
+StoreInst::StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd)
+  : Instruction(Type::VoidTy, Store, "", InsertAtEnd), Volatile(false) {
+  init(Val, Ptr);
+}
+
 StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile, 
                      Instruction *InsertBefore)
   : Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(isVolatile) {
   init(Val, Ptr);
 }
 
+StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile, 
+                     BasicBlock *InsertAtEnd)
+  : Instruction(Type::VoidTy, Store, "", InsertAtEnd), Volatile(isVolatile) {
+  init(Val, Ptr);
+}
+
 
 //===----------------------------------------------------------------------===//
 //                       GetElementPtrInst Implementation
@@ -119,6 +165,14 @@
   : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
                                                           Idx, true))),
                 GetElementPtr, Name, InBe) {
+  init(Ptr, Idx);
+}
+
+GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
+				     const std::string &Name, BasicBlock *IAE)
+  : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
+                                                          Idx, true))),
+                GetElementPtr, Name, IAE) {
   init(Ptr, Idx);
 }
 


Index: llvm/lib/VMCore/iCall.cpp
diff -u llvm/lib/VMCore/iCall.cpp:1.24 llvm/lib/VMCore/iCall.cpp:1.25
--- llvm/lib/VMCore/iCall.cpp:1.24	Wed May 26 16:41:09 2004
+++ llvm/lib/VMCore/iCall.cpp	Wed May 26 19:15:23 2004
@@ -23,29 +23,37 @@
 //                        CallInst Implementation
 //===----------------------------------------------------------------------===//
 
-CallInst::CallInst(Value *Func, const std::vector<Value*> &params, 
-                   const std::string &Name, Instruction *InsertBefore) 
-  : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
-				 ->getElementType())->getReturnType(),
-		Instruction::Call, Name, InsertBefore) {
-  Operands.reserve(1+params.size());
+void CallInst::init(Value *Func, const std::vector<Value*> &Params)
+{
+  Operands.reserve(1+Params.size());
   Operands.push_back(Use(Func, this));
 
   const FunctionType *FTy = 
     cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
 
-  assert((params.size() == FTy->getNumParams() || 
-          (FTy->isVarArg() && params.size() > FTy->getNumParams())) &&
+  assert((Params.size() == FTy->getNumParams() || 
+          (FTy->isVarArg() && Params.size() > FTy->getNumParams())) &&
 	 "Calling a function with bad signature");
-  for (unsigned i = 0; i != params.size(); i++)
-    Operands.push_back(Use(params[i], this));
+  for (unsigned i = 0; i != Params.size(); i++)
+    Operands.push_back(Use(Params[i], this));
 }
 
-CallInst::CallInst(Value *Func, const std::string &Name,
-                   Instruction *InsertBefore)
-  : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
-                                   ->getElementType())->getReturnType(),
-                Instruction::Call, Name, InsertBefore) {
+void CallInst::init(Value *Func, Value *Actual)
+{
+  Operands.reserve(2);
+  Operands.push_back(Use(Func, this));
+  
+  const FunctionType *MTy = 
+    cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
+
+  assert((MTy->getNumParams() == 1 ||
+          (MTy->isVarArg() && MTy->getNumParams() == 0)) &&
+	 "Calling a function with bad signature");
+  Operands.push_back(Use(Actual, this));
+}
+
+void CallInst::init(Value *Func)
+{
   Operands.reserve(1);
   Operands.push_back(Use(Func, this));
   
@@ -55,21 +63,52 @@
   assert(MTy->getNumParams() == 0 && "Calling a function with bad signature");
 }
 
-CallInst::CallInst(Value *Func, Value* A, const std::string &Name,
+CallInst::CallInst(Value *Func, const std::vector<Value*> &Params, 
+                   const std::string &Name, Instruction *InsertBefore) 
+  : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+				 ->getElementType())->getReturnType(),
+		Instruction::Call, Name, InsertBefore) {
+  init(Func, Params);
+}
+
+CallInst::CallInst(Value *Func, const std::vector<Value*> &Params, 
+                   const std::string &Name, BasicBlock *InsertAtEnd) 
+  : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+				 ->getElementType())->getReturnType(),
+		Instruction::Call, Name, InsertAtEnd) {
+  init(Func, Params);
+}
+
+CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name,
                    Instruction  *InsertBefore)
   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
                                    ->getElementType())->getReturnType(),
                 Instruction::Call, Name, InsertBefore) {
-  Operands.reserve(2);
-  Operands.push_back(Use(Func, this));
-  
-  const FunctionType *MTy = 
-    cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
+  init(Func, Actual);
+}
 
-  assert((MTy->getNumParams() == 1 ||
-          (MTy->isVarArg() && MTy->getNumParams() == 0)) &&
-	 "Calling a function with bad signature");
-  Operands.push_back(Use(A, this));
+CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name,
+                   BasicBlock  *InsertAtEnd)
+  : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+                                   ->getElementType())->getReturnType(),
+                Instruction::Call, Name, InsertAtEnd) {
+  init(Func, Actual);
+}
+
+CallInst::CallInst(Value *Func, const std::string &Name,
+                   Instruction *InsertBefore)
+  : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+                                   ->getElementType())->getReturnType(),
+                Instruction::Call, Name, InsertBefore) {
+  init(Func);
+}
+
+CallInst::CallInst(Value *Func, const std::string &Name,
+                   BasicBlock *InsertAtEnd)
+  : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+                                   ->getElementType())->getReturnType(),
+                Instruction::Call, Name, InsertAtEnd) {
+  init(Func);
 }
 
 CallInst::CallInst(const CallInst &CI) 





More information about the llvm-commits mailing list