From 9f0fdf748243844ae04aa3561b591edb2d9283e4 Mon Sep 17 00:00:00 2001 From: Alkis Evlogimenos Date: Wed, 26 May 2004 21:41:09 +0000 Subject: Refactor common initialization code in private init() functions. This is a first step in supplying append to basic block constructors for all instruction types. llvm-svn: 13793 --- llvm/lib/VMCore/iMemory.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'llvm/lib/VMCore/iMemory.cpp') diff --git a/llvm/lib/VMCore/iMemory.cpp b/llvm/lib/VMCore/iMemory.cpp index da4cc7483f0..2b731b45c5a 100644 --- a/llvm/lib/VMCore/iMemory.cpp +++ b/llvm/lib/VMCore/iMemory.cpp @@ -67,16 +67,14 @@ FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore) LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef) : Instruction(cast(Ptr->getType())->getElementType(), Load, Name, InsertBef), Volatile(false) { - Operands.reserve(1); - Operands.push_back(Use(Ptr, this)); + init(Ptr); } LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, Instruction *InsertBef) : Instruction(cast(Ptr->getType())->getElementType(), Load, Name, InsertBef), Volatile(isVolatile) { - Operands.reserve(1); - Operands.push_back(Use(Ptr, this)); + init(Ptr); } //===----------------------------------------------------------------------===// @@ -85,19 +83,13 @@ LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, StoreInst::StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore) : Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(false) { - - Operands.reserve(2); - Operands.push_back(Use(Val, this)); - Operands.push_back(Use(Ptr, this)); + init(Val, Ptr); } StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile, Instruction *InsertBefore) : Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(isVolatile) { - - Operands.reserve(2); - Operands.push_back(Use(Val, this)); - Operands.push_back(Use(Ptr, this)); + init(Val, Ptr); } @@ -113,11 +105,8 @@ static inline const Type *checkType(const Type *Ty) { return Ty; } -GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector &Idx, - const std::string &Name, Instruction *InBe) - : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), - Idx, true))), - GetElementPtr, Name, InBe) { +void GetElementPtrInst::init(Value *Ptr, const std::vector &Idx) +{ Operands.reserve(1+Idx.size()); Operands.push_back(Use(Ptr, this)); @@ -125,6 +114,14 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector &Idx, Operands.push_back(Use(Idx[i], this)); } +GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector &Idx, + const std::string &Name, Instruction *InBe) + : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), + Idx, true))), + GetElementPtr, Name, InBe) { + init(Ptr, Idx); +} + // getIndexedType - Returns the type of the element that would be loaded with // a load instruction with the specified parameters. // -- cgit v1.2.3