llvm.org GIT mirror llvm / dab3d29
Convert ConstantExpr::getGetElementPtr and ConstantExpr::getInBoundsGetElementPtr to use ArrayRef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135673 91177308-0d34-0410-b5e6-96231b3b80d8 Jay Foad 8 years ago
20 changed file(s) with 99 addition(s) and 106 deletion(s). Raw diff Collapse all Expand all
622622
  • ComputeLinearIndex (in llvm/CodeGen/Analysis.h)
  • 623623
  • ConstantArray::get
  • 624624
  • ConstantExpr::getExtractElement
  • 625
  • ConstantExpr::getGetElementPtr
  • 626
  • ConstantExpr::getInBoundsGetElementPtr
  • 625627
  • ConstantExpr::getIndices
  • 626628
  • ConstantExpr::getInsertElement
  • 627629
  • ConstantExpr::getWithOperands
  • 161161 };
    162162
    163163 Constant *msgptr = ConstantExpr::
    164 getGetElementPtr(aberrormsg, gep_params,
    165 array_lengthof(gep_params));
    164 getGetElementPtr(aberrormsg, gep_params);
    166165
    167166 Value *puts_params[] = {
    168167 msgptr
    787787 /// all elements must be Constant's.
    788788 ///
    789789 static Constant *getGetElementPtr(Constant *C,
    790 Constant *const *IdxList, unsigned NumIdx,
    790 ArrayRef IdxList,
    791791 bool InBounds = false) {
    792 return getGetElementPtr(C, (Value**)IdxList, NumIdx, InBounds);
    792 return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(),
    793 IdxList.size()),
    794 InBounds);
    793795 }
    794796 static Constant *getGetElementPtr(Constant *C,
    795 Value *const *IdxList, unsigned NumIdx,
    797 Constant *Idx,
    798 bool InBounds = false) {
    799 // This form of the function only exists to avoid ambiguous overload
    800 // warnings about whether to convert Idx to ArrayRef or
    801 // ArrayRef.
    802 return getGetElementPtr(C, cast(Idx), InBounds);
    803 }
    804 static Constant *getGetElementPtr(Constant *C,
    805 ArrayRef IdxList,
    796806 bool InBounds = false);
    797807
    798808 /// Create an "inbounds" getelementptr. See the documentation for the
    799809 /// "inbounds" flag in LangRef.html for details.
    800810 static Constant *getInBoundsGetElementPtr(Constant *C,
    801 Constant *const *IdxList,
    802 unsigned NumIdx) {
    803 return getGetElementPtr(C, IdxList, NumIdx, true);
    811 ArrayRef IdxList) {
    812 return getGetElementPtr(C, IdxList, true);
    804813 }
    805814 static Constant *getInBoundsGetElementPtr(Constant *C,
    806 Value* const *IdxList,
    807 unsigned NumIdx) {
    808 return getGetElementPtr(C, IdxList, NumIdx, true);
    815 Constant *Idx) {
    816 // This form of the function only exists to avoid ambiguous overload
    817 // warnings about whether to convert Idx to ArrayRef or
    818 // ArrayRef.
    819 return getGetElementPtr(C, Idx, true);
    820 }
    821 static Constant *getInBoundsGetElementPtr(Constant *C,
    822 ArrayRef IdxList) {
    823 return getGetElementPtr(C, IdxList, true);
    809824 }
    810825
    811826 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
    119119
    120120 Constant *CreateGetElementPtr(Constant *C,
    121121 ArrayRef IdxList) const {
    122 return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size());
    122 return ConstantExpr::getGetElementPtr(C, IdxList);
    123123 }
    124124 Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const {
    125125 // This form of the function only exists to avoid ambiguous overload
    126126 // warnings about whether to convert Idx to ArrayRef or
    127127 // ArrayRef.
    128 return ConstantExpr::getGetElementPtr(C, &Idx, 1);
    128 return ConstantExpr::getGetElementPtr(C, Idx);
    129129 }
    130130 Constant *CreateGetElementPtr(Constant *C,
    131131 ArrayRef IdxList) const {
    132 return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size());
    132 return ConstantExpr::getGetElementPtr(C, IdxList);
    133133 }
    134134
    135135 Constant *CreateInBoundsGetElementPtr(Constant *C,
    136136 ArrayRef IdxList) const {
    137 return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
    138 IdxList.size());
    137 return ConstantExpr::getInBoundsGetElementPtr(C, IdxList);
    139138 }
    140139 Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const {
    141140 // This form of the function only exists to avoid ambiguous overload
    142141 // warnings about whether to convert Idx to ArrayRef or
    143142 // ArrayRef.
    144 return ConstantExpr::getInBoundsGetElementPtr(C, &Idx, 1);
    143 return ConstantExpr::getInBoundsGetElementPtr(C, Idx);
    145144 }
    146145 Constant *CreateInBoundsGetElementPtr(Constant *C,
    147146 ArrayRef IdxList) const {
    148 return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
    149 IdxList.size());
    147 return ConstantExpr::getInBoundsGetElementPtr(C, IdxList);
    150148 }
    151149
    152150 //===--------------------------------------------------------------------===//
    178178
    179179 Constant *CreateGetElementPtr(Constant *C,
    180180 ArrayRef IdxList) const {
    181 return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size());
    181 return ConstantExpr::getGetElementPtr(C, IdxList);
    182182 }
    183183 Instruction *CreateGetElementPtr(Constant *C,
    184184 ArrayRef IdxList) const {
    187187
    188188 Constant *CreateInBoundsGetElementPtr(Constant *C,
    189189 ArrayRef IdxList) const {
    190 return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
    191 IdxList.size());
    190 return ConstantExpr::getInBoundsGetElementPtr(C, IdxList);
    192191 }
    193192 Instruction *CreateInBoundsGetElementPtr(Constant *C,
    194193 ArrayRef IdxList) const {
    131131
    132132 Constant *CreateGetElementPtr(Constant *C,
    133133 ArrayRef IdxList) const {
    134 return Fold(ConstantExpr::getGetElementPtr(C, IdxList.data(),
    135 IdxList.size()));
    134 return Fold(ConstantExpr::getGetElementPtr(C, IdxList));
    136135 }
    137136 Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const {
    138137 // This form of the function only exists to avoid ambiguous overload
    139138 // warnings about whether to convert Idx to ArrayRef or
    140139 // ArrayRef.
    141 return Fold(ConstantExpr::getGetElementPtr(C, &Idx, 1));
    140 return Fold(ConstantExpr::getGetElementPtr(C, Idx));
    142141 }
    143142 Constant *CreateGetElementPtr(Constant *C,
    144143 ArrayRef IdxList) const {
    145 return Fold(ConstantExpr::getGetElementPtr(C, IdxList.data(),
    146 IdxList.size()));
    144 return Fold(ConstantExpr::getGetElementPtr(C, IdxList));
    147145 }
    148146
    149147 Constant *CreateInBoundsGetElementPtr(Constant *C,
    150148 ArrayRef IdxList) const {
    151 return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
    152 IdxList.size()));
    149 return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList));
    153150 }
    154151 Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const {
    155152 // This form of the function only exists to avoid ambiguous overload
    156153 // warnings about whether to convert Idx to ArrayRef or
    157154 // ArrayRef.
    158 return Fold(ConstantExpr::getInBoundsGetElementPtr(C, &Idx, 1));
    155 return Fold(ConstantExpr::getInBoundsGetElementPtr(C, Idx));
    159156 }
    160157 Constant *CreateInBoundsGetElementPtr(Constant *C,
    161158 ArrayRef IdxList) const {
    162 return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
    163 IdxList.size()));
    159 return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList));
    164160 }
    165161
    166162 //===--------------------------------------------------------------------===//
    561561 if (!Any) return 0;
    562562
    563563 Constant *C =
    564 ConstantExpr::getGetElementPtr(Ops[0], &NewIdxs[0], NewIdxs.size());
    564 ConstantExpr::getGetElementPtr(Ops[0], NewIdxs);
    565565 if (ConstantExpr *CE = dyn_cast(C))
    566566 if (Constant *Folded = ConstantFoldConstantExpression(CE, TD))
    567567 C = Folded;
    701701
    702702 // Create a GEP.
    703703 Constant *C =
    704 ConstantExpr::getGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size());
    704 ConstantExpr::getGetElementPtr(Ptr, NewIdxs);
    705705 assert(cast(C->getType())->getElementType() == Ty &&
    706706 "Computed GetElementPtr has unexpected type!");
    707707
    888888 if (Constant *C = SymbolicallyEvaluateGEP(Ops, DestTy, TD))
    889889 return C;
    890890
    891 return ConstantExpr::getGetElementPtr(Ops[0], Ops.data() + 1,
    892 Ops.size() - 1);
    891 return ConstantExpr::getGetElementPtr(Ops[0], Ops.slice(1));
    893892 }
    894893 }
    895894
    22532253 if (!isa(Ops[i]))
    22542254 return 0;
    22552255
    2256 return ConstantExpr::getGetElementPtr(cast(Ops[0]),
    2257 (Constant *const*)Ops.data() + 1,
    2258 Ops.size() - 1);
    2256 return ConstantExpr::getGetElementPtr(cast(Ops[0]), Ops.slice(1));
    22592257 }
    22602258
    22612259 /// SimplifyPHINode - See if we can fold the given phi. If not, returns null.
    493493 // Fold a GEP with constant operands.
    494494 if (Constant *CLHS = dyn_cast(V))
    495495 if (Constant *CRHS = dyn_cast(Idx))
    496 return ConstantExpr::getGetElementPtr(CLHS, &CRHS, 1);
    496 return ConstantExpr::getGetElementPtr(CLHS, CRHS);
    497497
    498498 // Do a quick scan to see if we have this GEP nearby. If so, reuse it.
    499499 unsigned ScanLimit = 6;
    22722272 if (Elts.size() == 0 || !Elts[0]->getType()->isPointerTy())
    22732273 return Error(ID.Loc, "getelementptr requires pointer operand");
    22742274
    2275 ArrayRef Indices(Elts.begin() + 1, Elts.end());
    22752276 if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(),
    22762277 (Value**)(Elts.data() + 1),
    22772278 Elts.size() - 1))
    22782279 return Error(ID.Loc, "invalid indices for getelementptr");
    22792280 ID.ConstantVal = InBounds ?
    2280 ConstantExpr::getInBoundsGetElementPtr(Elts[0],
    2281 Elts.data() + 1,
    2282 Elts.size() - 1) :
    2283 ConstantExpr::getGetElementPtr(Elts[0],
    2284 Elts.data() + 1, Elts.size() - 1);
    2281 ConstantExpr::getInBoundsGetElementPtr(Elts[0], Indices) :
    2282 ConstantExpr::getGetElementPtr(Elts[0], Indices);
    22852283 } else if (Opc == Instruction::Select) {
    22862284 if (Elts.size() != 3)
    22872285 return Error(ID.Loc, "expected three operands to select");
    13501350 if (!ElTy) return Error("Invalid CE_GEP record");
    13511351 Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
    13521352 }
    1353 ArrayRef Indices(Elts.begin() + 1, Elts.end());
    13531354 if (BitCode == bitc::CST_CODE_CE_INBOUNDS_GEP)
    1354 V = ConstantExpr::getInBoundsGetElementPtr(Elts[0], &Elts[1],
    1355 Elts.size()-1);
    1355 V = ConstantExpr::getInBoundsGetElementPtr(Elts[0], Indices);
    13561356 else
    1357 V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1],
    1358 Elts.size()-1);
    1357 V = ConstantExpr::getGetElementPtr(Elts[0], Indices);
    13591358 break;
    13601359 }
    13611360 case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
    149149 ConstantInt::get(Int32Ty, 0),
    150150 ConstantInt::get(Int32Ty, k-i)
    151151 };
    152 Constant *GEP = ConstantExpr::getInBoundsGetElementPtr(MergedGV, Idx, 2);
    152 Constant *GEP = ConstantExpr::getInBoundsGetElementPtr(MergedGV, Idx);
    153153 Globals[k]->replaceAllUsesWith(GEP);
    154154 Globals[k]->eraseFromParent();
    155155 }
    595595 Idxs.push_back(NullInt);
    596596 for (unsigned i = 3, e = CE->getNumOperands(); i != e; ++i)
    597597 Idxs.push_back(CE->getOperand(i));
    598 NewPtr = ConstantExpr::getGetElementPtr(cast(NewPtr),
    599 &Idxs[0], Idxs.size());
    598 NewPtr = ConstantExpr::getGetElementPtr(cast(NewPtr), Idxs);
    600599 } else {
    601600 GetElementPtrInst *GEPI = cast(GEP);
    602601 SmallVector Idxs;
    752751 break;
    753752 if (Idxs.size() == GEPI->getNumOperands()-1)
    754753 Changed |= OptimizeAwayTrappingUsesOfValue(GEPI,
    755 ConstantExpr::getGetElementPtr(NewV, &Idxs[0],
    756 Idxs.size()));
    754 ConstantExpr::getGetElementPtr(NewV, Idxs));
    757755 if (GEPI->use_empty()) {
    758756 Changed = true;
    759757 GEPI->eraseFromParent();
    24092407 i != e; ++i)
    24102408 GEPOps.push_back(getVal(Values, *i));
    24112409 InstResult = cast(GEP)->isInBounds() ?
    2412 ConstantExpr::getInBoundsGetElementPtr(P, &GEPOps[0], GEPOps.size()) :
    2413 ConstantExpr::getGetElementPtr(P, &GEPOps[0], GEPOps.size());
    2410 ConstantExpr::getInBoundsGetElementPtr(P, GEPOps) :
    2411 ConstantExpr::getGetElementPtr(P, GEPOps);
    24142412 } else if (LoadInst *LI = dyn_cast(CurInst)) {
    24152413 if (LI->isVolatile()) return false; // no volatile accesses.
    24162414 InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)),
    5050 Constant::getNullValue(Type::getInt32Ty(Context)));
    5151 unsigned NumElements = 0;
    5252 if (Array) {
    53 Args[2] = ConstantExpr::getGetElementPtr(Array, &GEPIndices[0],
    54 GEPIndices.size());
    53 Args[2] = ConstantExpr::getGetElementPtr(Array, GEPIndices);
    5554 NumElements =
    5655 cast(Array->getType()->getElementType())->getNumElements();
    5756 } else {
    119118 Indices[0] = Constant::getNullValue(Type::getInt32Ty(Context));
    120119 Indices[1] = ConstantInt::get(Type::getInt32Ty(Context), CounterNum);
    121120 Constant *ElementPtr =
    122 ConstantExpr::getGetElementPtr(CounterArray, &Indices[0], Indices.size());
    121 ConstantExpr::getGetElementPtr(CounterArray, Indices);
    123122
    124123 // Load, increment and store the value back.
    125124 Value *OldVal = new LoadInst(ElementPtr, "OldFuncCounter", InsertPos);
    919919 llvm::Type::getInt8PtrTy(Src->getContext()));
    920920 Constant *OffsetCst =
    921921 ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
    922 Src = ConstantExpr::getGetElementPtr(Src, &OffsetCst, 1);
    922 Src = ConstantExpr::getGetElementPtr(Src, OffsetCst);
    923923 Src = ConstantExpr::getBitCast(Src, PointerType::getUnqual(LoadTy));
    924924 if (ConstantFoldLoadFromConstPtr(Src, &TD))
    925925 return Offset;
    10801080 llvm::Type::getInt8PtrTy(Src->getContext()));
    10811081 Constant *OffsetCst =
    10821082 ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
    1083 Src = ConstantExpr::getGetElementPtr(Src, &OffsetCst, 1);
    1083 Src = ConstantExpr::getGetElementPtr(Src, OffsetCst);
    10841084 Src = ConstantExpr::getBitCast(Src, PointerType::getUnqual(LoadTy));
    10851085 return ConstantFoldLoadFromConstPtr(Src, &TD);
    10861086 }
    11791179 }
    11801180
    11811181 Constant *Ptr = Operands[0];
    1182 markConstant(&I, ConstantExpr::getGetElementPtr(Ptr, &Operands[0]+1,
    1183 Operands.size()-1));
    1182 ArrayRef Indices(Operands.begin() + 1, Operands.end());
    1183 markConstant(&I, ConstantExpr::getGetElementPtr(Ptr, Indices));
    11841184 }
    11851185
    11861186 void SCCPSolver::visitStoreInst(StoreInst &SI) {
    126126
    127127 if (ElTy == DPTy->getElementType())
    128128 // This GEP is inbounds because all indices are zero.
    129 return ConstantExpr::getInBoundsGetElementPtr(V, &IdxList[0],
    130 IdxList.size());
    129 return ConstantExpr::getInBoundsGetElementPtr(V, IdxList);
    131130 }
    132131
    133132 // Handle casts from one vector constant to another. We know that the src
    21452144 /// isInBoundsIndices - Test whether the given sequence of *normalized* indices
    21462145 /// is "inbounds".
    21472146 template
    2148 static bool isInBoundsIndices(IndexTy const *Idxs, size_t NumIdx) {
    2147 static bool isInBoundsIndices(ArrayRef Idxs) {
    21492148 // No indices means nothing that could be out of bounds.
    2150 if (NumIdx == 0) return true;
    2149 if (Idxs.empty()) return true;
    21512150
    21522151 // If the first index is zero, it's in bounds.
    21532152 if (cast(Idxs[0])->isNullValue()) return true;
    21562155 // by the one-past-the-end rule.
    21572156 if (!cast(Idxs[0])->isOne())
    21582157 return false;
    2159 for (unsigned i = 1, e = NumIdx; i != e; ++i)
    2158 for (unsigned i = 1, e = Idxs.size(); i != e; ++i)
    21602159 if (!cast(Idxs[i])->isNullValue())
    21612160 return false;
    21622161 return true;
    22332232 NewIndices.append(Idxs.begin() + 1, Idxs.end());
    22342233 return (inBounds && cast(CE)->isInBounds()) ?
    22352234 ConstantExpr::getInBoundsGetElementPtr(CE->getOperand(0),
    2236 &NewIndices[0],
    2237 NewIndices.size()) :
    2238 ConstantExpr::getGetElementPtr(CE->getOperand(0),
    2239 &NewIndices[0],
    2240 NewIndices.size());
    2235 NewIndices) :
    2236 ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices);
    22412237 }
    22422238 }
    22432239
    22552251 if (CAT->getElementType() == SAT->getElementType())
    22562252 return inBounds ?
    22572253 ConstantExpr::getInBoundsGetElementPtr(
    2258 (Constant*)CE->getOperand(0), Idxs.data(), Idxs.size()) :
    2254 (Constant*)CE->getOperand(0), Idxs) :
    22592255 ConstantExpr::getGetElementPtr(
    2260 (Constant*)CE->getOperand(0), Idxs.data(), Idxs.size());
    2256 (Constant*)CE->getOperand(0), Idxs);
    22612257 }
    22622258 }
    22632259
    23132309 for (unsigned i = 0, e = Idxs.size(); i != e; ++i)
    23142310 if (!NewIdxs[i]) NewIdxs[i] = cast(Idxs[i]);
    23152311 return inBounds ?
    2316 ConstantExpr::getInBoundsGetElementPtr(C, NewIdxs.data(),
    2317 NewIdxs.size()) :
    2318 ConstantExpr::getGetElementPtr(C, NewIdxs.data(), NewIdxs.size());
    2312 ConstantExpr::getInBoundsGetElementPtr(C, NewIdxs) :
    2313 ConstantExpr::getGetElementPtr(C, NewIdxs);
    23192314 }
    23202315
    23212316 // If all indices are known integers and normalized, we can do a simple
    23222317 // check for the "inbounds" property.
    23232318 if (!Unknown && !inBounds &&
    2324 isa(C) && isInBoundsIndices(Idxs.data(), Idxs.size()))
    2325 return ConstantExpr::getInBoundsGetElementPtr(C, Idxs.data(), Idxs.size());
    2319 isa(C) && isInBoundsIndices(Idxs))
    2320 return ConstantExpr::getInBoundsGetElementPtr(C, Idxs);
    23262321
    23272322 return 0;
    23282323 }
    839839 Ops[i-1] = getOperand(i);
    840840 if (OpNo == 0)
    841841 return cast(this)->isInBounds() ?
    842 ConstantExpr::getInBoundsGetElementPtr(Op, &Ops[0], Ops.size()) :
    843 ConstantExpr::getGetElementPtr(Op, &Ops[0], Ops.size());
    842 ConstantExpr::getInBoundsGetElementPtr(Op, Ops) :
    843 ConstantExpr::getGetElementPtr(Op, Ops);
    844844 Ops[OpNo-1] = Op;
    845845 return cast(this)->isInBounds() ?
    846 ConstantExpr::getInBoundsGetElementPtr(getOperand(0), &Ops[0],Ops.size()):
    847 ConstantExpr::getGetElementPtr(getOperand(0), &Ops[0], Ops.size());
    846 ConstantExpr::getInBoundsGetElementPtr(getOperand(0), Ops) :
    847 ConstantExpr::getGetElementPtr(getOperand(0), Ops);
    848848 }
    849849 default:
    850850 assert(getNumOperands() == 2 && "Must be binary operator?");
    891891 return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]);
    892892 case Instruction::GetElementPtr:
    893893 return cast(this)->isInBounds() ?
    894 ConstantExpr::getInBoundsGetElementPtr(Ops[0], &Ops[1], Ops.size()-1) :
    895 ConstantExpr::getGetElementPtr(Ops[0], &Ops[1], Ops.size()-1);
    894 ConstantExpr::getInBoundsGetElementPtr(Ops[0], Ops.slice(1)) :
    895 ConstantExpr::getGetElementPtr(Ops[0], Ops.slice(1));
    896896 case Instruction::ICmp:
    897897 case Instruction::FCmp:
    898898 return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1]);
    15171517 // Note that a non-inbounds gep is used, as null isn't within any object.
    15181518 Constant *GEPIdx = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
    15191519 Constant *GEP = getGetElementPtr(
    1520 Constant::getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1);
    1520 Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx);
    15211521 return getPtrToInt(GEP,
    15221522 Type::getInt64Ty(Ty->getContext()));
    15231523 }
    15311531 Constant *Zero = ConstantInt::get(Type::getInt64Ty(Ty->getContext()), 0);
    15321532 Constant *One = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
    15331533 Constant *Indices[2] = { Zero, One };
    1534 Constant *GEP = getGetElementPtr(NullPtr, Indices, 2);
    1534 Constant *GEP = getGetElementPtr(NullPtr, Indices);
    15351535 return getPtrToInt(GEP,
    15361536 Type::getInt64Ty(Ty->getContext()));
    15371537 }
    15491549 FieldNo
    15501550 };
    15511551 Constant *GEP = getGetElementPtr(
    1552 Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx, 2);
    1552 Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx);
    15531553 return getPtrToInt(GEP,
    15541554 Type::getInt64Ty(Ty->getContext()));
    15551555 }
    15911591 return pImpl->ExprConstants.getOrCreate(V1->getType(), Key);
    15921592 }
    15931593
    1594 Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
    1595 unsigned NumIdx, bool InBounds) {
    1596 if (Constant *FC = ConstantFoldGetElementPtr(C, InBounds,
    1597 makeArrayRef(Idxs, NumIdx)))
    1594 Constant *ConstantExpr::getGetElementPtr(Constant *C, ArrayRef Idxs,
    1595 bool InBounds) {
    1596 if (Constant *FC = ConstantFoldGetElementPtr(C, InBounds, Idxs))
    15981597 return FC; // Fold a few common cases.
    15991598
    16001599 // Get the result type of the getelementptr!
    1601 Type *Ty =
    1602 GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx);
    1600 Type *Ty =
    1601 GetElementPtrInst::getIndexedType(C->getType(), Idxs.begin(), Idxs.end());
    16031602 assert(Ty && "GEP indices invalid!");
    16041603 unsigned AS = cast(C->getType())->getAddressSpace();
    16051604 Type *ReqTy = Ty->getPointerTo(AS);
    16081607 "Non-pointer type for constant GetElementPtr expression");
    16091608 // Look up the constant in the table first to ensure uniqueness
    16101609 std::vector ArgVec;
    1611 ArgVec.reserve(NumIdx+1);
    1610 ArgVec.reserve(1 + Idxs.size());
    16121611 ArgVec.push_back(C);
    1613 for (unsigned i = 0; i != NumIdx; ++i)
    1612 for (unsigned i = 0, e = Idxs.size(); i != e; ++i)
    16141613 ArgVec.push_back(cast(Idxs[i]));
    16151614 const ExprMapKeyType Key(Instruction::GetElementPtr, ArgVec, 0,
    16161615 InBounds ? GEPOperator::IsInBounds : 0);
    20912090 if (Val == From) Val = To;
    20922091 Indices.push_back(Val);
    20932092 }
    2094 Replacement = ConstantExpr::getGetElementPtr(Pointer,
    2095 &Indices[0], Indices.size(),
    2093 Replacement = ConstantExpr::getGetElementPtr(Pointer, Indices,
    20962094 cast(this)->isInBounds());
    20972095 } else if (getOpcode() == Instruction::ExtractValue) {
    20982096 Constant *Agg = getOperand(0);
    791791
    792792 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
    793793 LLVMValueRef *ConstantIndices, unsigned NumIndices) {
    794 ArrayRef IdxList(unwrap(ConstantIndices, NumIndices),
    795 NumIndices);
    794796 return wrap(ConstantExpr::getGetElementPtr(unwrap(ConstantVal),
    795 unwrap(ConstantIndices,
    796 NumIndices),
    797 NumIndices));
    797 IdxList));
    798798 }
    799799
    800800 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
    801801 LLVMValueRef *ConstantIndices,
    802802 unsigned NumIndices) {
    803803 Constant* Val = unwrap(ConstantVal);
    804 Constant** Idxs = unwrap(ConstantIndices, NumIndices);
    805 return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, Idxs, NumIndices));
    804 ArrayRef IdxList(unwrap(ConstantIndices, NumIndices),
    805 NumIndices);
    806 return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, IdxList));
    806807 }
    807808
    808809 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
    833833 // GetElementPtr *funcName, ulong 0, ulong 0
    834834 std::vector GEPargs(2,
    835835 Constant::getNullValue(Type::getInt32Ty(F->getContext())));
    836 Value *GEP =
    837 ConstantExpr::getGetElementPtr(funcName, &GEPargs[0], 2);
    836 Value *GEP = ConstantExpr::getGetElementPtr(funcName, GEPargs);
    838837 std::vector ResolverArgs;
    839838 ResolverArgs.push_back(GEP);
    840839