llvm.org GIT mirror llvm / 6e7ad95
Revert 80959. It isn't sufficient to solve the full problem. And it introduced regressions in the Ocaml bindings tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80969 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
9 changed file(s) with 92 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
647647 static Constant *getIntToPtr(Constant *C, const Type *Ty);
648648 static Constant *getBitCast (Constant *C, const Type *Ty);
649649
650 static Constant* getNSWAdd(Constant* C1, Constant* C2);
651 static Constant* getExactSDiv(Constant* C1, Constant* C2);
652
650653 /// Transparently provide more efficient getOperand methods.
651654 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
652655
732735 Constant* const *IdxList, unsigned NumIdx);
733736 static Constant *getGetElementPtr(Constant *C,
734737 Value* const *IdxList, unsigned NumIdx);
738
739 /// Create an "inbounds" getelementptr. See the documentation for the
740 /// "inbounds" flag in LangRef.html for details.
741 static Constant *getInBoundsGetElementPtr(Constant *C,
742 Constant* const *IdxList,
743 unsigned NumIdx);
744 static Constant *getInBoundsGetElementPtr(Constant *C,
745 Value* const *IdxList,
746 unsigned NumIdx);
735747
736748 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
737749 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
3535 return ConstantExpr::getAdd(LHS, RHS);
3636 }
3737 Constant *CreateNSWAdd(Constant *LHS, Constant *RHS) const {
38 return ConstantExpr::getAdd(LHS, RHS);
38 return ConstantExpr::getNSWAdd(LHS, RHS);
3939 }
4040 Constant *CreateFAdd(Constant *LHS, Constant *RHS) const {
4141 return ConstantExpr::getFAdd(LHS, RHS);
5959 return ConstantExpr::getSDiv(LHS, RHS);
6060 }
6161 Constant *CreateExactSDiv(Constant *LHS, Constant *RHS) const {
62 return ConstantExpr::getSDiv(LHS, RHS);
62 return ConstantExpr::getExactSDiv(LHS, RHS);
6363 }
6464 Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {
6565 return ConstantExpr::getFDiv(LHS, RHS);
126126
127127 Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
128128 unsigned NumIdx) const {
129 return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
129 return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
130130 }
131131 Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
132132 unsigned NumIdx) const {
133 return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
133 return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
134134 }
135135
136136 //===--------------------------------------------------------------------===//
130130
131131 Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
132132 unsigned NumIdx) const {
133 return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
133 return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
134134 }
135135 Value *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
136136 unsigned NumIdx) const {
5151 return Fold(ConstantExpr::getAdd(LHS, RHS));
5252 }
5353 Constant *CreateNSWAdd(Constant *LHS, Constant *RHS) const {
54 return Fold(ConstantExpr::getAdd(LHS, RHS));
54 return Fold(ConstantExpr::getNSWAdd(LHS, RHS));
5555 }
5656 Constant *CreateFAdd(Constant *LHS, Constant *RHS) const {
5757 return Fold(ConstantExpr::getFAdd(LHS, RHS));
7575 return Fold(ConstantExpr::getSDiv(LHS, RHS));
7676 }
7777 Constant *CreateExactSDiv(Constant *LHS, Constant *RHS) const {
78 return Fold(ConstantExpr::getSDiv(LHS, RHS));
78 return Fold(ConstantExpr::getExactSDiv(LHS, RHS));
7979 }
8080 Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {
8181 return Fold(ConstantExpr::getFDiv(LHS, RHS));
142142
143143 Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
144144 unsigned NumIdx) const {
145 return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx));
145 return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
146146 }
147147 Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
148148 unsigned NumIdx) const {
149 return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx));
149 return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
150150 }
151151
152152 //===--------------------------------------------------------------------===//
469469 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
470470 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
471471 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
472 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
472473 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
473474 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
474475 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
476477 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
477478 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
478479 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
480 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
479481 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
480482 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
481483 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
492494 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
493495 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
494496 LLVMValueRef *ConstantIndices, unsigned NumIndices);
497 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
498 LLVMValueRef *ConstantIndices,
499 unsigned NumIndices);
495500 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
496501 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
497502 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
202202 if (Offset != 0)
203203 return 0;
204204
205 // Create the GEP constant expr.
206 Constant *C = ConstantExpr::getGetElementPtr(Ptr,
207 &NewIdxs[0], NewIdxs.size());
208 assert(cast(C->getType())->getElementType() == Ty &&
209 "Computed GetElementPtr has unexpected type!");
210
211205 // If the base is the start of a GlobalVariable and all the array indices
212206 // remain in their static bounds, the GEP is inbounds. We can check that
213207 // all indices are in bounds by just checking the first index only
214 // because we've just normalized all the indices. We can mutate the
215 // Constant in place because we've proven that the indices are in bounds,
216 // so they'll always be in bounds.
217 if (isa(Ptr) && NewIdxs[0]->isNullValue())
218 if (GEPOperator *GEP = dyn_cast(C))
219 GEP->setIsInBounds(true);
208 // because we've just normalized all the indices.
209 Constant *C = isa(Ptr) && NewIdxs[0]->isNullValue() ?
210 ConstantExpr::getInBoundsGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size()) :
211 ConstantExpr::getGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size());
212 assert(cast(C->getType())->getElementType() == Ty &&
213 "Computed GetElementPtr has unexpected type!");
220214
221215 // If we ended up indexing a member with a type that doesn't match
222216 // the type of what the original indices indexed, add a cast.
121121 }
122122
123123 if (ElTy == DPTy->getElementType())
124 return ConstantExpr::getGetElementPtr(V, &IdxList[0], IdxList.size());
124 // This GEP is inbounds because all indices are zero.
125 return ConstantExpr::getInBoundsGetElementPtr(V, &IdxList[0],
126 IdxList.size());
125127 }
126128
127129 // Handle casts from one vector constant to another. We know that the src
628628 Constant* ConstantVector::get(Constant* const* Vals, unsigned NumVals) {
629629 // FIXME: make this the primary ctor method.
630630 return get(std::vector(Vals, Vals+NumVals));
631 }
632
633 Constant* ConstantExpr::getNSWAdd(Constant* C1, Constant* C2) {
634 Constant *C = getAdd(C1, C2);
635 // Set nsw attribute, assuming constant folding didn't eliminate the
636 // Add.
637 if (AddOperator *Add = dyn_cast(C))
638 Add->setHasNoSignedWrap(true);
639 return C;
640 }
641
642 Constant* ConstantExpr::getExactSDiv(Constant* C1, Constant* C2) {
643 Constant *C = getSDiv(C1, C2);
644 // Set exact attribute, assuming constant folding didn't eliminate the
645 // SDiv.
646 if (SDivOperator *SDiv = dyn_cast(C))
647 SDiv->setIsExact(true);
648 return C;
631649 }
632650
633651 // Utility function for determining if a ConstantExpr is a CastOp or not. This
14721490 return getGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx);
14731491 }
14741492
1493 Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
1494 Value* const *Idxs,
1495 unsigned NumIdx) {
1496 Constant *Result = getGetElementPtr(C, Idxs, NumIdx);
1497 // Set in bounds attribute, assuming constant folding didn't eliminate the
1498 // GEP.
1499 if (GEPOperator *GEP = dyn_cast(Result))
1500 GEP->setIsInBounds(true);
1501 return Result;
1502 }
1503
14751504 Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant* const *Idxs,
14761505 unsigned NumIdx) {
14771506 return getGetElementPtr(C, (Value* const *)Idxs, NumIdx);
1507 }
1508
1509 Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
1510 Constant* const *Idxs,
1511 unsigned NumIdx) {
1512 return getInBoundsGetElementPtr(C, (Value* const *)Idxs, NumIdx);
14781513 }
14791514
14801515 Constant *
534534 unwrap(RHSConstant)));
535535 }
536536
537 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant,
538 LLVMValueRef RHSConstant) {
539 return wrap(ConstantExpr::getNSWAdd(
540 unwrap(LHSConstant),
541 unwrap(RHSConstant)));
542 }
543
537544 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
538545 return wrap(ConstantExpr::getFAdd(
539546 unwrap(LHSConstant),
573580 return wrap(ConstantExpr::getSDiv(
574581 unwrap(LHSConstant),
575582 unwrap(RHSConstant)));
583 }
584
585 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant,
586 LLVMValueRef RHSConstant) {
587 return wrap(ConstantExpr::getExactSDiv(
588 unwrap(LHSConstant),
589 unwrap(RHSConstant)));
576590 }
577591
578592 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
656670 unwrap(ConstantIndices,
657671 NumIndices),
658672 NumIndices));
673 }
674
675 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
676 LLVMValueRef *ConstantIndices,
677 unsigned NumIndices) {
678 Constant* Val = unwrap(ConstantVal);
679 Constant** Idxs = unwrap(ConstantIndices, NumIndices);
680 return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, Idxs, NumIndices));
659681 }
660682
661683 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {