From e02e5e465b8d3bee69561d114f7584710cccad75 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 19 Feb 2007 19:23:41 +0000 Subject: [PATCH] Temporarily reverting the patch. It's breaking llvm-gcc build. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34423 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Constants.h | 14 ++++++++++++++ lib/VMCore/Constants.cpp | 35 ++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 1ee00aadb31..58def86fc84 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -550,6 +550,10 @@ public: /// static Constant *getSizeOf(const Type *Ty); + /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array, + /// return a pointer to a pointer of the array element type. + static Constant *getPtrPtrFromArrayPtr(Constant *C); + /// ConstantExpr::get - Return a binary or shift operator constant expression, /// folding if possible. /// @@ -589,6 +593,16 @@ public: static Constant *getGetElementPtr(Constant *C, Value* const *IdxList, unsigned NumIdx); + // FIXME: Remove these. + static Constant *getGetElementPtr(Constant *C, + const std::vector &IdxList) { + return getGetElementPtr(C, &IdxList[0], IdxList.size()); + } + static Constant *getGetElementPtr(Constant *C, + const std::vector &IdxList) { + return getGetElementPtr(C, &IdxList[0], IdxList.size()); + } + static Constant *getExtractElement(Constant *Vec, Constant *Idx); static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx); static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask); diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index c89609ec9fd..ab2d2732fd1 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -22,7 +22,6 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MathExtras.h" -#include "llvm/ADT/SmallVector.h" #include #include using namespace llvm; @@ -483,14 +482,13 @@ ConstantExpr::getWithOperandReplaced(unsigned OpNo, Constant *Op) const { Op2 = (OpNo == 2) ? Op : getOperand(2); return ConstantExpr::getShuffleVector(Op0, Op1, Op2); case Instruction::GetElementPtr: { - SmallVector Ops; - Ops.resize(getNumOperands()); + std::vector Ops; for (unsigned i = 1, e = getNumOperands(); i != e; ++i) - Ops[i] = getOperand(i); + Ops.push_back(getOperand(i)); if (OpNo == 0) - return ConstantExpr::getGetElementPtr(Op, &Ops[0], Ops.size()); + return ConstantExpr::getGetElementPtr(Op, Ops); Ops[OpNo-1] = Op; - return ConstantExpr::getGetElementPtr(getOperand(0), &Ops[0], Ops.size()); + return ConstantExpr::getGetElementPtr(getOperand(0), Ops); } default: assert(getNumOperands() == 2 && "Must be binary operator?"); @@ -537,8 +535,10 @@ getWithOperands(const std::vector &Ops) const { return ConstantExpr::getExtractElement(Ops[0], Ops[1]); case Instruction::ShuffleVector: return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]); - case Instruction::GetElementPtr: - return ConstantExpr::getGetElementPtr(Ops[0], &Ops[1], Ops.size()-1); + case Instruction::GetElementPtr: { + std::vector ActualOps(Ops.begin()+1, Ops.end()); + return ConstantExpr::getGetElementPtr(Ops[0], ActualOps); + } case Instruction::ICmp: case Instruction::FCmp: return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1]); @@ -1578,10 +1578,16 @@ Constant *ConstantExpr::getBitCast(Constant *C, const Type *DstTy) { Constant *ConstantExpr::getSizeOf(const Type *Ty) { // sizeof is implemented as: (ulong) gep (Ty*)null, 1 - Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1); - Constant *GEP = - getGetElementPtr(getNullValue(PointerType::get(Ty)), &GEPIdx, 1); - return getCast(Instruction::PtrToInt, GEP, Type::Int64Ty); + return getCast(Instruction::PtrToInt, getGetElementPtr(getNullValue( + PointerType::get(Ty)), std::vector(1, + ConstantInt::get(Type::Int32Ty, 1))), Type::Int64Ty); +} + +Constant *ConstantExpr::getPtrPtrFromArrayPtr(Constant *C) { + // pointer from array is implemented as: getelementptr arr ptr, 0, 0 + static std::vector Indices(2, ConstantInt::get(Type::Int32Ty, 0)); + + return ConstantExpr::getGetElementPtr(C, Indices); } Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode, @@ -2023,7 +2029,7 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV, Constant *Replacement = 0; if (getOpcode() == Instruction::GetElementPtr) { - SmallVector Indices; + std::vector Indices; Constant *Pointer = getOperand(0); Indices.reserve(getNumOperands()-1); if (Pointer == From) Pointer = To; @@ -2033,8 +2039,7 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV, if (Val == From) Val = To; Indices.push_back(Val); } - Replacement = ConstantExpr::getGetElementPtr(Pointer, - &Indices[0], Indices.size()); + Replacement = ConstantExpr::getGetElementPtr(Pointer, Indices); } else if (isCast()) { assert(getOperand(0) == From && "Cast only has one use!"); Replacement = ConstantExpr::getCast(getOpcode(), To, getType()); -- 2.34.1