diff options
author | Chris Lattner <sabre@nondot.org> | 2004-10-11 22:52:25 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-10-11 22:52:25 +0000 |
commit | 7fa6e666ece60455cf9d75eff6e6915bebf05cbc (patch) | |
tree | 22e77ddd89c2978b3dd2a49878fdcc242a88e5ab /lib/VMCore/Constants.cpp | |
parent | 4b83380f330b1c77bb9b4ad8f63bdcf1a596afd6 (diff) |
Allow creation of GEP constantexprs with a vector of value* operands as
well as a vector of constant*'s. It turns out that this is more efficient
and all of the clients want to do that, so we should cater to them.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16923 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r-- | lib/VMCore/Constants.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index a029d8466b..8d964bcb24 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1148,10 +1148,8 @@ namespace llvm { break; case Instruction::GetElementPtr: // Make everyone now use a constant of the new type... - std::vector<Constant*> C; - for (unsigned i = 1, e = OldC->getNumOperands(); i != e; ++i) - C.push_back(cast<Constant>(OldC->getOperand(i))); - New = ConstantExpr::getGetElementPtrTy(NewTy, OldC->getOperand(0), C); + std::vector<Value*> Idx(OldC->op_begin()+1, OldC->op_end()); + New = ConstantExpr::getGetElementPtrTy(NewTy, OldC->getOperand(0), Idx); break; } @@ -1298,9 +1296,8 @@ Constant *ConstantExpr::getShiftTy(const Type *ReqTy, unsigned Opcode, Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C, - const std::vector<Constant*> &IdxList) { - assert(GetElementPtrInst::getIndexedType(C->getType(), - std::vector<Value*>(IdxList.begin(), IdxList.end()), true) && + const std::vector<Value*> &IdxList) { + assert(GetElementPtrInst::getIndexedType(C->getType(), IdxList, true) && "GEP indices invalid!"); if (Constant *FC = ConstantFoldGetElementPtr(C, IdxList)) @@ -1309,9 +1306,12 @@ Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C, assert(isa<PointerType>(C->getType()) && "Non-pointer type for constant GetElementPtr expression"); // Look up the constant in the table first to ensure uniqueness - std::vector<Constant*> argVec(1, C); - argVec.insert(argVec.end(), IdxList.begin(), IdxList.end()); - const ExprMapKeyType &Key = std::make_pair(Instruction::GetElementPtr,argVec); + std::vector<Constant*> ArgVec; + ArgVec.reserve(IdxList.size()+1); + ArgVec.push_back(C); + for (unsigned i = 0, e = IdxList.size(); i != e; ++i) + ArgVec.push_back(cast<Constant>(IdxList[i])); + const ExprMapKeyType &Key = std::make_pair(Instruction::GetElementPtr,ArgVec); return ExprConstants.getOrCreate(ReqTy, Key); } @@ -1323,6 +1323,15 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), VIdxList, true); assert(Ty && "GEP indices invalid!"); + return getGetElementPtrTy(PointerType::get(Ty), C, VIdxList); +} + +Constant *ConstantExpr::getGetElementPtr(Constant *C, + const std::vector<Value*> &IdxList) { + // Get the result type of the getelementptr! + const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), IdxList, + true); + assert(Ty && "GEP indices invalid!"); return getGetElementPtrTy(PointerType::get(Ty), C, IdxList); } |