summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorAlkis Evlogimenos <alkis@evlogimenos.com>2004-05-27 00:15:23 +0000
committerAlkis Evlogimenos <alkis@evlogimenos.com>2004-05-27 00:15:23 +0000
commite3260007bc8b93359717f7e7cd0e5844e5578512 (patch)
treeb51196714b93246f5836d2a63a0c5870c57008bb /llvm/lib
parent52a71340c15d46a0af14b92ce050dfe86aff7b92 (diff)
downloadbcm5719-llvm-e3260007bc8b93359717f7e7cd0e5844e5578512.tar.gz
bcm5719-llvm-e3260007bc8b93359717f7e7cd0e5844e5578512.zip
Add constructors that take a BasicBlock to append to, to the rest of
the llvm::Instruction hierarchy. llvm-svn: 13800
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/iCall.cpp89
-rw-r--r--llvm/lib/VMCore/iMemory.cpp68
-rw-r--r--llvm/lib/VMCore/iOperators.cpp63
3 files changed, 175 insertions, 45 deletions
diff --git a/llvm/lib/VMCore/iCall.cpp b/llvm/lib/VMCore/iCall.cpp
index edd55933014..9a81f7948f9 100644
--- a/llvm/lib/VMCore/iCall.cpp
+++ b/llvm/lib/VMCore/iCall.cpp
@@ -23,29 +23,37 @@ using namespace llvm;
// 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 @@ CallInst::CallInst(Value *Func, const std::string &Name,
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)
diff --git a/llvm/lib/VMCore/iMemory.cpp b/llvm/lib/VMCore/iMemory.cpp
index 2b731b45c5a..bcba93e253a 100644
--- a/llvm/lib/VMCore/iMemory.cpp
+++ b/llvm/lib/VMCore/iMemory.cpp
@@ -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 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
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 @@ MallocInst::MallocInst(const MallocInst &MI)
// 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 @@ LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef)
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 @@ LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
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 @@ StoreInst::StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore)
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
@@ -122,6 +168,14 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
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);
+}
+
// getIndexedType - Returns the type of the element that would be loaded with
// a load instruction with the specified parameters.
//
diff --git a/llvm/lib/VMCore/iOperators.cpp b/llvm/lib/VMCore/iOperators.cpp
index 977849e22cc..b2569e61836 100644
--- a/llvm/lib/VMCore/iOperators.cpp
+++ b/llvm/lib/VMCore/iOperators.cpp
@@ -21,11 +21,8 @@ using namespace llvm;
// 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 @@ BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
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,
}
}
+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 @@ BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
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 @@ BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
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) {
@@ -173,6 +202,14 @@ SetCondInst::SetCondInst(BinaryOps Opcode, Value *S1, Value *S2,
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));
+}
+
// getInverseCondition - Return the inverse of the current condition opcode.
// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
//
OpenPOWER on IntegriCloud