Lines Matching refs:Ty

133 Constant *Constant::getNullValue(Type *Ty) {
134 switch (Ty->getTypeID()) {
136 return ConstantInt::get(Ty, 0);
138 return ConstantFP::get(Ty->getContext(),
141 return ConstantFP::get(Ty->getContext(),
144 return ConstantFP::get(Ty->getContext(),
147 return ConstantFP::get(Ty->getContext(),
150 return ConstantFP::get(Ty->getContext(),
153 return ConstantFP::get(Ty->getContext(),
157 return ConstantPointerNull::get(cast<PointerType>(Ty));
161 return ConstantAggregateZero::get(Ty);
168 Constant *Constant::getIntegerValue(Type *Ty, const APInt &V) {
169 Type *ScalarTy = Ty->getScalarType();
172 Constant *C = ConstantInt::get(Ty->getContext(), V);
179 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
185 Constant *Constant::getAllOnesValue(Type *Ty) {
186 if (IntegerType *ITy = dyn_cast<IntegerType>(Ty))
187 return ConstantInt::get(Ty->getContext(),
190 if (Ty->isFloatingPointTy()) {
191 APFloat FL = APFloat::getAllOnesValue(Ty->getPrimitiveSizeInBits(),
192 !Ty->isPPC_FP128Ty());
193 return ConstantFP::get(Ty->getContext(), FL);
196 VectorType *VTy = cast<VectorType>(Ty);
469 ConstantInt::ConstantInt(IntegerType *Ty, const APInt& V)
470 : Constant(Ty, ConstantIntVal, nullptr, 0), Val(V) {
471 assert(V.getBitWidth() == Ty->getBitWidth() && "Invalid constant for type");
488 Constant *ConstantInt::getTrue(Type *Ty) {
489 VectorType *VTy = dyn_cast<VectorType>(Ty);
491 assert(Ty->isIntegerTy(1) && "True must be i1 or vector of i1.");
492 return ConstantInt::getTrue(Ty->getContext());
497 ConstantInt::getTrue(Ty->getContext()));
500 Constant *ConstantInt::getFalse(Type *Ty) {
501 VectorType *VTy = dyn_cast<VectorType>(Ty);
503 assert(Ty->isIntegerTy(1) && "False must be i1 or vector of i1.");
504 return ConstantInt::getFalse(Ty->getContext());
509 ConstantInt::getFalse(Ty->getContext()));
528 Constant *ConstantInt::get(Type *Ty, uint64_t V, bool isSigned) {
529 Constant *C = get(cast<IntegerType>(Ty->getScalarType()), V, isSigned);
532 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
538 ConstantInt *ConstantInt::get(IntegerType *Ty, uint64_t V,
540 return get(Ty->getContext(), APInt(Ty->getBitWidth(), V, isSigned));
543 ConstantInt *ConstantInt::getSigned(IntegerType *Ty, int64_t V) {
544 return get(Ty, V, true);
547 Constant *ConstantInt::getSigned(Type *Ty, int64_t V) {
548 return get(Ty, V, true);
551 Constant *ConstantInt::get(Type *Ty, const APInt& V) {
552 ConstantInt *C = get(Ty->getContext(), V);
553 assert(C->getType() == Ty->getScalarType() &&
557 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
563 ConstantInt *ConstantInt::get(IntegerType* Ty, StringRef Str,
565 return get(Ty->getContext(), APInt(Ty->getBitWidth(), Str, radix));
572 static const fltSemantics *TypeToFloatSemantics(Type *Ty) {
573 if (Ty->isHalfTy())
575 if (Ty->isFloatTy())
577 if (Ty->isDoubleTy())
579 if (Ty->isX86_FP80Ty())
581 else if (Ty->isFP128Ty())
584 assert(Ty->isPPC_FP128Ty() && "Unknown FP format");
593 Constant *ConstantFP::get(Type *Ty, double V) {
594 LLVMContext &Context = Ty->getContext();
598 FV.convert(*TypeToFloatSemantics(Ty->getScalarType()),
603 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
610 Constant *ConstantFP::get(Type *Ty, StringRef Str) {
611 LLVMContext &Context = Ty->getContext();
613 APFloat FV(*TypeToFloatSemantics(Ty->getScalarType()), Str);
617 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
623 Constant *ConstantFP::getNegativeZero(Type *Ty) {
624 const fltSemantics &Semantics = *TypeToFloatSemantics(Ty->getScalarType());
626 Constant *C = get(Ty->getContext(), NegZero);
628 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
635 Constant *ConstantFP::getZeroValueForNegation(Type *Ty) {
636 if (Ty->isFPOrFPVectorTy())
637 return getNegativeZero(Ty);
639 return Constant::getNullValue(Ty);
650 Type *Ty;
652 Ty = Type::getHalfTy(Context);
654 Ty = Type::getFloatTy(Context);
656 Ty = Type::getDoubleTy(Context);
658 Ty = Type::getX86_FP80Ty(Context);
660 Ty = Type::getFP128Ty(Context);
664 Ty = Type::getPPC_FP128Ty(Context);
666 Slot = new ConstantFP(Ty, V);
672 Constant *ConstantFP::getInfinity(Type *Ty, bool Negative) {
673 const fltSemantics &Semantics = *TypeToFloatSemantics(Ty->getScalarType());
674 Constant *C = get(Ty->getContext(), APFloat::getInf(Semantics, Negative));
676 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
682 ConstantFP::ConstantFP(Type *Ty, const APFloat& V)
683 : Constant(Ty, ConstantFPVal, nullptr, 0), Val(V) {
684 assert(&V.getSemantics() == TypeToFloatSemantics(Ty) &&
783 Constant *ConstantArray::get(ArrayType *Ty, ArrayRef<Constant*> V) {
786 return ConstantAggregateZero::get(Ty);
789 assert(V[i]->getType() == Ty->getElementType() &&
792 LLVMContextImpl *pImpl = Ty->getContext().pImpl;
799 return UndefValue::get(Ty);
802 return ConstantAggregateZero::get(Ty);
874 return pImpl->ArrayConstants.getOrCreate(Ty, V);
1145 getWithOperands(ArrayRef<Constant*> Ops, Type *Ty) const {
1147 bool AnyChange = Ty != getType();
1168 return ConstantExpr::getCast(getOpcode(), Ops[0], Ty);
1197 bool ConstantInt::isValueValidForType(Type *Ty, uint64_t Val) {
1198 unsigned NumBits = Ty->getIntegerBitWidth(); // assert okay
1199 if (Ty->isIntegerTy(1))
1207 bool ConstantInt::isValueValidForType(Type *Ty, int64_t Val) {
1208 unsigned NumBits = Ty->getIntegerBitWidth();
1209 if (Ty->isIntegerTy(1))
1218 bool ConstantFP::isValueValidForType(Type *Ty, const APFloat& Val) {
1222 switch (Ty->getTypeID()) {
1269 ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) {
1270 assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
1273 ConstantAggregateZero *&Entry = Ty->getContext().pImpl->CAZConstants[Ty];
1275 Entry = new ConstantAggregateZero(Ty);
1352 ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) {
1353 ConstantPointerNull *&Entry = Ty->getContext().pImpl->CPNConstants[Ty];
1355 Entry = new ConstantPointerNull(Ty);
1372 UndefValue *UndefValue::get(Type *Ty) {
1373 UndefValue *&Entry = Ty->getContext().pImpl->UVConstants[Ty];
1375 Entry = new UndefValue(Ty);
1479 Instruction::CastOps opc, Constant *C, Type *Ty) {
1480 assert(Ty->isFirstClassType() && "Cannot cast to an aggregate type!");
1482 if (Constant *FC = ConstantFoldCastInstruction(opc, C, Ty))
1485 LLVMContextImpl *pImpl = Ty->getContext().pImpl;
1490 return pImpl->ExprConstants.getOrCreate(Ty, Key);
1493 Constant *ConstantExpr::getCast(unsigned oc, Constant *C, Type *Ty) {
1496 assert(C && Ty && "Null arguments to getCast");
1497 assert(CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!");
1502 case Instruction::Trunc: return getTrunc(C, Ty);
1503 case Instruction::ZExt: return getZExt(C, Ty);
1504 case Instruction::SExt: return getSExt(C, Ty);
1505 case Instruction::FPTrunc: return getFPTrunc(C, Ty);
1506 case Instruction::FPExt: return getFPExtend(C, Ty);
1507 case Instruction::UIToFP: return getUIToFP(C, Ty);
1508 case Instruction::SIToFP: return getSIToFP(C, Ty);
1509 case Instruction::FPToUI: return getFPToUI(C, Ty);
1510 case Instruction::FPToSI: return getFPToSI(C, Ty);
1511 case Instruction::PtrToInt: return getPtrToInt(C, Ty);
1512 case Instruction::IntToPtr: return getIntToPtr(C, Ty);
1513 case Instruction::BitCast: return getBitCast(C, Ty);
1514 case Instruction::AddrSpaceCast: return getAddrSpaceCast(C, Ty);
1518 Constant *ConstantExpr::getZExtOrBitCast(Constant *C, Type *Ty) {
1519 if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
1520 return getBitCast(C, Ty);
1521 return getZExt(C, Ty);
1524 Constant *ConstantExpr::getSExtOrBitCast(Constant *C, Type *Ty) {
1525 if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
1526 return getBitCast(C, Ty);
1527 return getSExt(C, Ty);
1530 Constant *ConstantExpr::getTruncOrBitCast(Constant *C, Type *Ty) {
1531 if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
1532 return getBitCast(C, Ty);
1533 return getTrunc(C, Ty);
1536 Constant *ConstantExpr::getPointerCast(Constant *S, Type *Ty) {
1538 assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
1541 if (Ty->isIntOrIntVectorTy())
1542 return getPtrToInt(S, Ty);
1545 if (Ty->isPtrOrPtrVectorTy() && SrcAS != Ty->getPointerAddressSpace())
1546 return getAddrSpaceCast(S, Ty);
1548 return getBitCast(S, Ty);
1552 Type *Ty) {
1554 assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
1556 if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
1557 return getAddrSpaceCast(S, Ty);
1559 return getBitCast(S, Ty);
1562 Constant *ConstantExpr::getIntegerCast(Constant *C, Type *Ty,
1565 Ty->isIntOrIntVectorTy() && "Invalid cast");
1567 unsigned DstBits = Ty->getScalarSizeInBits();
1572 return getCast(opcode, C, Ty);
1575 Constant *ConstantExpr::getFPCast(Constant *C, Type *Ty) {
1576 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
1579 unsigned DstBits = Ty->getScalarSizeInBits();
1584 return getCast(opcode, C, Ty);
1587 Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty) {
1590 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1594 assert(Ty->isIntOrIntVectorTy() && "Trunc produces only integral");
1595 assert(C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
1598 return getFoldedCast(Instruction::Trunc, C, Ty);
1601 Constant *ConstantExpr::getSExt(Constant *C, Type *Ty) {
1604 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1608 assert(Ty->isIntOrIntVectorTy() && "SExt produces only integer");
1609 assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
1612 return getFoldedCast(Instruction::SExt, C, Ty);
1615 Constant *ConstantExpr::getZExt(Constant *C, Type *Ty) {
1618 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1622 assert(Ty->isIntOrIntVectorTy() && "ZExt produces only integer");
1623 assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
1626 return getFoldedCast(Instruction::ZExt, C, Ty);
1629 Constant *ConstantExpr::getFPTrunc(Constant *C, Type *Ty) {
1632 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1635 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
1636 C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
1638 return getFoldedCast(Instruction::FPTrunc, C, Ty);
1641 Constant *ConstantExpr::getFPExtend(Constant *C, Type *Ty) {
1644 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1647 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
1648 C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
1650 return getFoldedCast(Instruction::FPExt, C, Ty);
1653 Constant *ConstantExpr::getUIToFP(Constant *C, Type *Ty) {
1656 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1659 assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
1661 return getFoldedCast(Instruction::UIToFP, C, Ty);
1664 Constant *ConstantExpr::getSIToFP(Constant *C, Type *Ty) {
1667 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1670 assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
1672 return getFoldedCast(Instruction::SIToFP, C, Ty);
1675 Constant *ConstantExpr::getFPToUI(Constant *C, Type *Ty) {
1678 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1681 assert(C->getType()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() &&
1683 return getFoldedCast(Instruction::FPToUI, C, Ty);
1686 Constant *ConstantExpr::getFPToSI(Constant *C, Type *Ty) {
1689 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1692 assert(C->getType()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() &&
1694 return getFoldedCast(Instruction::FPToSI, C, Ty);
1829 Constant *ConstantExpr::getSizeOf(Type* Ty) {
1830 // sizeof is implemented as: (i64) gep (Ty*)null, 1
1832 Constant *GEPIdx = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
1834 Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx);
1836 Type::getInt64Ty(Ty->getContext()));
1839 Constant *ConstantExpr::getAlignOf(Type* Ty) {
1840 // alignof is implemented as: (i64) gep ({i1,Ty}*)null, 0, 1
1843 StructType::get(Type::getInt1Ty(Ty->getContext()), Ty, NULL);
1845 Constant *Zero = ConstantInt::get(Type::getInt64Ty(Ty->getContext()), 0);
1846 Constant *One = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
1850 Type::getInt64Ty(Ty->getContext()));
1858 Constant *ConstantExpr::getOffsetOf(Type* Ty, Constant *FieldNo) {
1859 // offsetof is implemented as: (i64) gep (Ty*)null, 0, FieldNo
1862 ConstantInt::get(Type::getInt64Ty(Ty->getContext()), 0),
1866 Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx);
1868 Type::getInt64Ty(Ty->getContext()));
1915 Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), Idxs);
1916 assert(Ty && "GEP indices invalid!");
1918 Type *ReqTy = Ty->getPointerTo(AS);
2193 Constant *ConstantExpr::getBinOpIdentity(unsigned Opcode, Type *Ty) {
2202 return Constant::getNullValue(Ty);
2205 return ConstantInt::get(Ty, 1);
2208 return Constant::getAllOnesValue(Ty);
2216 Constant *ConstantExpr::getBinOpAbsorber(unsigned Opcode, Type *Ty) {
2223 return Constant::getAllOnesValue(Ty);
2227 return Constant::getNullValue(Ty);
2274 bool ConstantDataSequential::isElementTypeCompatible(const Type *Ty) {
2275 if (Ty->isFloatTy() || Ty->isDoubleTy()) return true;
2276 if (const IntegerType *IT = dyn_cast<IntegerType>(Ty)) {
2321 Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) {
2322 assert(isElementTypeCompatible(Ty->getSequentialElementType()));
2326 return ConstantAggregateZero::get(Ty);
2330 Ty->getContext().pImpl->CDSConstants.GetOrCreateValue(Elements);
2339 if (Node->getType() == Ty)
2344 if (isa<ArrayType>(Ty))
2345 return *Entry = new ConstantDataArray(Ty, Slot.getKeyData());
2347 assert(isa<VectorType>(Ty));
2348 return *Entry = new ConstantDataVector(Ty, Slot.getKeyData());
2395 Type *Ty = ArrayType::get(Type::getInt8Ty(Context), Elts.size());
2397 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*1), Ty);
2400 Type *Ty = ArrayType::get(Type::getInt16Ty(Context), Elts.size());
2402 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*2), Ty);
2405 Type *Ty = ArrayType::get(Type::getInt32Ty(Context), Elts.size());
2407 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*4), Ty);
2410 Type *Ty = ArrayType::get(Type::getInt64Ty(Context), Elts.size());
2412 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*8), Ty);
2415 Type *Ty = ArrayType::get(Type::getFloatTy(Context), Elts.size());
2417 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*4), Ty);
2420 Type *Ty = ArrayType::get(Type::getDoubleTy(Context), Elts.size());
2422 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*8), Ty);
2448 Type *Ty = VectorType::get(Type::getInt8Ty(Context), Elts.size());
2450 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*1), Ty);
2453 Type *Ty = VectorType::get(Type::getInt16Ty(Context), Elts.size());
2455 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*2), Ty);
2458 Type *Ty = VectorType::get(Type::getInt32Ty(Context), Elts.size());
2460 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*4), Ty);
2463 Type *Ty = VectorType::get(Type::getInt64Ty(Context), Elts.size());
2465 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*8), Ty);
2468 Type *Ty = VectorType::get(Type::getFloatTy(Context), Elts.size());
2470 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*4), Ty);
2473 Type *Ty = VectorType::get(Type::getDoubleTy(Context), Elts.size());
2475 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*8), Ty);