Home | History | Annotate | Download | only in Analysis

Lines Matching full:constant

42 // Constant Folding internal helper functions
45 /// FoldBitCast - Constant fold bitcast, symbolically evaluating it with
46 /// DataLayout. This always returns a non-null constant, but it may be a
48 static Constant *FoldBitCast(Constant *C, Type *DestTy,
52 return Constant::getNullValue(DestTy);
54 return Constant::getAllOnesValue(DestTy);
102 Constant *Ops = C; // don't take the address of C!
106 // If this is a bitcast from constant vector -> vector, fold it.
161 SmallVector<Constant*, 32> Result;
164 Constant *Zero = Constant::getNullValue(DstEltTy);
170 Constant *Elt = Zero;
173 Constant *Src =dyn_cast<ConstantInt>(C->getAggregateElement(SrcElt++));
199 Constant *Src = dyn_cast<ConstantInt>(C->getAggregateElement(i));
207 Constant *Elt = ConstantExpr::getLShr(Src,
220 /// IsConstantOffsetFromGlobal - If this constant is actually a constant offset
221 /// from a global, return the global and the constant. Because of
223 static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV,
225 // Trivial case, constant is the global.
231 // Otherwise, if this isn't a constant expr, bail out.
242 // If the base isn't a global+constant, we aren't either.
254 /// constant being copied out of. ByteOffset is an offset into C. CurPtr is the
257 static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
379 static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
405 if (Constant *Res = FoldReinterpretLoadFromConstPtr(C, TD))
427 // If we're not accessing anything in this constant, the result is undefined.
456 /// produce if it is constant and determinable. If this is not determinable,
458 Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C,
465 // If the loaded value isn't a constant expr, we can't handle it.
472 if (Constant *V =
477 // Instead of loading constant c string, use corresponding integer value
505 Constant *Res = ConstantInt::get(CE->getContext(), StrVal);
512 // If this load comes from anywhere in a constant global, and if the global
519 return Constant::getNullValue(ResTy);
531 static Constant *ConstantFoldLoadInst(const LoadInst *LI, const DataLayout *TD){
534 if (Constant *C = dyn_cast<Constant>(LI->getOperand(0)))
540 /// SymbolicallyEvaluateBinop - One of Op0/Op1 is a constant expression.
544 static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0,
545 Constant *Op1, const DataLayout *DL){
575 // If the constant expr is something like &A[123] - &A[4].f, fold this into a
576 // constant. This happens frequently when iterating over a global array.
600 static Constant *CastGEPIndices(ArrayRef<Constant *> Ops,
607 SmallVector<Constant*, 32> NewIdxs;
624 Constant *C =
627 if (Constant *Folded = ConstantFoldConstantExpression(CE, TD, TLI))
633 static Constant* StripPtrCastKeepAS(Constant* Ptr) {
636 Ptr = cast<Constant>(Ptr->stripPointerCasts());
649 /// constant expression, do so.
650 static Constant *SymbolicallyEvaluateGEP(ArrayRef<Constant *> Ops,
653 Constant *Ptr = Ops[0];
660 // If this is a constant expr gep that is effectively computing an
674 Constant *Res = ConstantExpr::getPtrToInt(Ptr, CE->getType());
707 Ptr = cast<Constant>(GEP->getOperand(0));
721 Constant *C = ConstantInt::get(Ptr->getContext(), Offset+BasePtr);
731 SmallVector<Constant*, 32> NewIdxs;
790 Constant *C =
806 // Constant Folding public APIs
809 /// ConstantFoldInstruction - Try to constant fold the specified instruction.
810 /// If successful, the constant result is returned, if not, null is returned.
811 /// Note that this fails if not all of the operands are constant. Otherwise,
813 /// and stores, which have no constant expression form.
814 Constant *llvm::ConstantFoldInstruction(Instruction *I,
819 Constant *CommonValue = 0;
825 // because that would break the rule that constant folding only applies if
829 // If the incoming value is not a constant, then give up.
830 Constant *C = dyn_cast<Constant>(Incoming);
836 // If the incoming value is a different constant to
844 // If we reach here, all incoming values are the same constant or undef.
850 SmallVector<Constant*, 8> Ops;
852 Constant *Op = dyn_cast<Constant>(*i);
854 return 0; // All operands not constant!
872 cast<Constant>(IVI->getAggregateOperand()),
873 cast<Constant>(IVI->getInsertedValueOperand()),
878 cast<Constant>(EVI->getAggregateOperand()),
884 static Constant *
888 SmallVector<Constant *, 8> Ops;
891 Constant *NewC = cast<Constant>(*i);
907 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
908 /// using the specified DataLayout. If successful, the constant result is
910 Constant *llvm::ConstantFoldConstantExpression(const ConstantExpr *CE,
917 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
918 /// specified opcode and operands. If successful, the constant result is
921 /// constant expression form.
924 /// information, due to only being passed an opcode and operands. Constant
927 Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
928 ArrayRef<Constant *> Ops,
934 if (Constant *C = SymbolicallyEvaluateBinop(Opcode, Ops[0], Ops[1], TD))
954 Constant *Input = CE->getOperand(0);
957 Constant *Mask =
1001 if (Constant *C = CastGEPIndices(Ops, DestTy, TD, TLI))
1003 if (Constant *C = SymbolicallyEvaluateGEP(Ops, DestTy, TD, TLI))
1010 /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
1012 /// returns a constant expression of the specified operands.
1014 Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate,
1015 Constant *Ops0, Constant *Ops1,
1031 Constant *C = ConstantExpr::getIntegerCast(CE0->getOperand(0),
1033 Constant *Null = Constant::getNullValue(C->getType());
1041 Constant *C = CE0->getOperand(0);
1042 Constant *Null = Constant::getNullValue(C->getType());
1054 Constant *C0 = ConstantExpr::getIntegerCast(CE0->getOperand(0),
1056 Constant *C1 = ConstantExpr::getIntegerCast(CE1->getOperand(0),
1075 Constant *LHS =
1078 Constant *RHS =
1083 Constant *Ops[] = { LHS, RHS };
1092 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
1093 /// getelementptr constantexpr, return the constant value being addressed by the
1094 /// constant expression, or null if something is funny and we can't decide.
1095 Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
1109 /// ConstantFoldLoadThroughGEPIndices - Given a constant and getelementptr
1111 /// return the constant value being addressed by a virtual load, or null if
1113 Constant *llvm::ConstantFoldLoadThroughGEPIndices(Constant *C,
1114 ArrayRef<Constant*> Indices) {
1126 // Constant Folding for Calls
1198 static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
1217 llvm_unreachable("Can only constant fold half/float/double");
1220 static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
1239 llvm_unreachable("Can only constant fold half/float/double");
1243 /// conversion of a constant floating point. If roundTowardZero is false, the
1248 /// performed, otherwise returns the Constant value resulting from the
1250 static Constant *ConstantFoldConvertToInt(const APFloat &Val,
1255 "Can only constant fold conversions to 64 and 32 bit ints");
1269 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
1271 Constant *
1272 llvm::ConstantFoldCall(Function *F, ArrayRef<Constant *> Operands,
1368 // Constant fold exp2(x) as pow(2,x) in case the host doesn't have a
1389 return Constant::getNullValue(Ty);
1444 Constant *Op = cast<Constant>(Operands[0]);
1568 Constant *Ops[] = {