Lines Matching refs:Ty

111 Constant *Constant::getNullValue(Type *Ty) {
112 switch (Ty->getTypeID()) {
114 return ConstantInt::get(Ty, 0);
116 return ConstantFP::get(Ty->getContext(),
119 return ConstantFP::get(Ty->getContext(),
122 return ConstantFP::get(Ty->getContext(),
125 return ConstantFP::get(Ty->getContext(),
128 return ConstantFP::get(Ty->getContext(),
131 return ConstantFP::get(Ty->getContext(),
135 return ConstantPointerNull::get(cast<PointerType>(Ty));
139 return ConstantAggregateZero::get(Ty);
146 Constant *Constant::getIntegerValue(Type *Ty, const APInt &V) {
147 Type *ScalarTy = Ty->getScalarType();
150 Constant *C = ConstantInt::get(Ty->getContext(), V);
157 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
163 Constant *Constant::getAllOnesValue(Type *Ty) {
164 if (IntegerType *ITy = dyn_cast<IntegerType>(Ty))
165 return ConstantInt::get(Ty->getContext(),
168 if (Ty->isFloatingPointTy()) {
169 APFloat FL = APFloat::getAllOnesValue(Ty->getPrimitiveSizeInBits(),
170 !Ty->isPPC_FP128Ty());
171 return ConstantFP::get(Ty->getContext(), FL);
174 VectorType *VTy = cast<VectorType>(Ty);
433 ConstantInt::ConstantInt(IntegerType *Ty, const APInt& V)
434 : Constant(Ty, ConstantIntVal, 0, 0), Val(V) {
435 assert(V.getBitWidth() == Ty->getBitWidth() && "Invalid constant for type");
452 Constant *ConstantInt::getTrue(Type *Ty) {
453 VectorType *VTy = dyn_cast<VectorType>(Ty);
455 assert(Ty->isIntegerTy(1) && "True must be i1 or vector of i1.");
456 return ConstantInt::getTrue(Ty->getContext());
461 ConstantInt::getTrue(Ty->getContext()));
464 Constant *ConstantInt::getFalse(Type *Ty) {
465 VectorType *VTy = dyn_cast<VectorType>(Ty);
467 assert(Ty->isIntegerTy(1) && "False must be i1 or vector of i1.");
468 return ConstantInt::getFalse(Ty->getContext());
473 ConstantInt::getFalse(Ty->getContext()));
492 Constant *ConstantInt::get(Type *Ty, uint64_t V, bool isSigned) {
493 Constant *C = get(cast<IntegerType>(Ty->getScalarType()), V, isSigned);
496 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
502 ConstantInt *ConstantInt::get(IntegerType *Ty, uint64_t V,
504 return get(Ty->getContext(), APInt(Ty->getBitWidth(), V, isSigned));
507 ConstantInt *ConstantInt::getSigned(IntegerType *Ty, int64_t V) {
508 return get(Ty, V, true);
511 Constant *ConstantInt::getSigned(Type *Ty, int64_t V) {
512 return get(Ty, V, true);
515 Constant *ConstantInt::get(Type *Ty, const APInt& V) {
516 ConstantInt *C = get(Ty->getContext(), V);
517 assert(C->getType() == Ty->getScalarType() &&
521 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
527 ConstantInt *ConstantInt::get(IntegerType* Ty, StringRef Str,
529 return get(Ty->getContext(), APInt(Ty->getBitWidth(), Str, radix));
536 static const fltSemantics *TypeToFloatSemantics(Type *Ty) {
537 if (Ty->isHalfTy())
539 if (Ty->isFloatTy())
541 if (Ty->isDoubleTy())
543 if (Ty->isX86_FP80Ty())
545 else if (Ty->isFP128Ty())
548 assert(Ty->isPPC_FP128Ty() && "Unknown FP format");
557 Constant *ConstantFP::get(Type *Ty, double V) {
558 LLVMContext &Context = Ty->getContext();
562 FV.convert(*TypeToFloatSemantics(Ty->getScalarType()),
567 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
574 Constant *ConstantFP::get(Type *Ty, StringRef Str) {
575 LLVMContext &Context = Ty->getContext();
577 APFloat FV(*TypeToFloatSemantics(Ty->getScalarType()), Str);
581 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
588 ConstantFP *ConstantFP::getNegativeZero(Type *Ty) {
589 LLVMContext &Context = Ty->getContext();
590 APFloat apf = cast<ConstantFP>(Constant::getNullValue(Ty))->getValueAPF();
596 Constant *ConstantFP::getZeroValueForNegation(Type *Ty) {
597 Type *ScalarTy = Ty->getScalarType();
600 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
605 return Constant::getNullValue(Ty);
616 Type *Ty;
618 Ty = Type::getHalfTy(Context);
620 Ty = Type::getFloatTy(Context);
622 Ty = Type::getDoubleTy(Context);
624 Ty = Type::getX86_FP80Ty(Context);
626 Ty = Type::getFP128Ty(Context);
630 Ty = Type::getPPC_FP128Ty(Context);
632 Slot = new ConstantFP(Ty, V);
638 ConstantFP *ConstantFP::getInfinity(Type *Ty, bool Negative) {
639 const fltSemantics &Semantics = *TypeToFloatSemantics(Ty);
640 return ConstantFP::get(Ty->getContext(),
644 ConstantFP::ConstantFP(Type *Ty, const APFloat& V)
645 : Constant(Ty, ConstantFPVal, 0, 0), Val(V) {
646 assert(&V.getSemantics() == TypeToFloatSemantics(Ty) &&
745 Constant *ConstantArray::get(ArrayType *Ty, ArrayRef<Constant*> V) {
748 return ConstantAggregateZero::get(Ty);
751 assert(V[i]->getType() == Ty->getElementType() &&
754 LLVMContextImpl *pImpl = Ty->getContext().pImpl;
761 return UndefValue::get(Ty);
764 return ConstantAggregateZero::get(Ty);
836 return pImpl->ArrayConstants.getOrCreate(Ty, V);
1107 getWithOperands(ArrayRef<Constant*> Ops, Type *Ty) const {
1109 bool AnyChange = Ty != getType();
1130 return ConstantExpr::getCast(getOpcode(), Ops[0], Ty);
1159 bool ConstantInt::isValueValidForType(Type *Ty, uint64_t Val) {
1160 unsigned NumBits = Ty->getIntegerBitWidth(); // assert okay
1161 if (Ty->isIntegerTy(1))
1169 bool ConstantInt::isValueValidForType(Type *Ty, int64_t Val) {
1170 unsigned NumBits = Ty->getIntegerBitWidth();
1171 if (Ty->isIntegerTy(1))
1180 bool ConstantFP::isValueValidForType(Type *Ty, const APFloat& Val) {
1184 switch (Ty->getTypeID()) {
1231 ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) {
1232 assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
1235 ConstantAggregateZero *&Entry = Ty->getContext().pImpl->CAZConstants[Ty];
1237 Entry = new ConstantAggregateZero(Ty);
1314 ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) {
1315 ConstantPointerNull *&Entry = Ty->getContext().pImpl->CPNConstants[Ty];
1317 Entry = new ConstantPointerNull(Ty);
1334 UndefValue *UndefValue::get(Type *Ty) {
1335 UndefValue *&Entry = Ty->getContext().pImpl->UVConstants[Ty];
1337 Entry = new UndefValue(Ty);
1430 Instruction::CastOps opc, Constant *C, Type *Ty) {
1431 assert(Ty->isFirstClassType() && "Cannot cast to an aggregate type!");
1433 if (Constant *FC = ConstantFoldCastInstruction(opc, C, Ty))
1436 LLVMContextImpl *pImpl = Ty->getContext().pImpl;
1441 return pImpl->ExprConstants.getOrCreate(Ty, Key);
1444 Constant *ConstantExpr::getCast(unsigned oc, Constant *C, Type *Ty) {
1447 assert(C && Ty && "Null arguments to getCast");
1448 assert(CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!");
1453 case Instruction::Trunc: return getTrunc(C, Ty);
1454 case Instruction::ZExt: return getZExt(C, Ty);
1455 case Instruction::SExt: return getSExt(C, Ty);
1456 case Instruction::FPTrunc: return getFPTrunc(C, Ty);
1457 case Instruction::FPExt: return getFPExtend(C, Ty);
1458 case Instruction::UIToFP: return getUIToFP(C, Ty);
1459 case Instruction::SIToFP: return getSIToFP(C, Ty);
1460 case Instruction::FPToUI: return getFPToUI(C, Ty);
1461 case Instruction::FPToSI: return getFPToSI(C, Ty);
1462 case Instruction::PtrToInt: return getPtrToInt(C, Ty);
1463 case Instruction::IntToPtr: return getIntToPtr(C, Ty);
1464 case Instruction::BitCast: return getBitCast(C, Ty);
1465 case Instruction::AddrSpaceCast: return getAddrSpaceCast(C, Ty);
1469 Constant *ConstantExpr::getZExtOrBitCast(Constant *C, Type *Ty) {
1470 if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
1471 return getBitCast(C, Ty);
1472 return getZExt(C, Ty);
1475 Constant *ConstantExpr::getSExtOrBitCast(Constant *C, Type *Ty) {
1476 if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
1477 return getBitCast(C, Ty);
1478 return getSExt(C, Ty);
1481 Constant *ConstantExpr::getTruncOrBitCast(Constant *C, Type *Ty) {
1482 if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
1483 return getBitCast(C, Ty);
1484 return getTrunc(C, Ty);
1487 Constant *ConstantExpr::getPointerCast(Constant *S, Type *Ty) {
1489 assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
1492 if (Ty->isIntOrIntVectorTy())
1493 return getPtrToInt(S, Ty);
1496 if (Ty->isPtrOrPtrVectorTy() && SrcAS != Ty->getPointerAddressSpace())
1497 return getAddrSpaceCast(S, Ty);
1499 return getBitCast(S, Ty);
1503 Type *Ty) {
1505 assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
1507 if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
1508 return getAddrSpaceCast(S, Ty);
1510 return getBitCast(S, Ty);
1513 Constant *ConstantExpr::getIntegerCast(Constant *C, Type *Ty,
1516 Ty->isIntOrIntVectorTy() && "Invalid cast");
1518 unsigned DstBits = Ty->getScalarSizeInBits();
1523 return getCast(opcode, C, Ty);
1526 Constant *ConstantExpr::getFPCast(Constant *C, Type *Ty) {
1527 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
1530 unsigned DstBits = Ty->getScalarSizeInBits();
1535 return getCast(opcode, C, Ty);
1538 Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty) {
1541 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1545 assert(Ty->isIntOrIntVectorTy() && "Trunc produces only integral");
1546 assert(C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
1549 return getFoldedCast(Instruction::Trunc, C, Ty);
1552 Constant *ConstantExpr::getSExt(Constant *C, Type *Ty) {
1555 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1559 assert(Ty->isIntOrIntVectorTy() && "SExt produces only integer");
1560 assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
1563 return getFoldedCast(Instruction::SExt, C, Ty);
1566 Constant *ConstantExpr::getZExt(Constant *C, Type *Ty) {
1569 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1573 assert(Ty->isIntOrIntVectorTy() && "ZExt produces only integer");
1574 assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
1577 return getFoldedCast(Instruction::ZExt, C, Ty);
1580 Constant *ConstantExpr::getFPTrunc(Constant *C, Type *Ty) {
1583 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1586 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
1587 C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
1589 return getFoldedCast(Instruction::FPTrunc, C, Ty);
1592 Constant *ConstantExpr::getFPExtend(Constant *C, Type *Ty) {
1595 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1598 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
1599 C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
1601 return getFoldedCast(Instruction::FPExt, C, Ty);
1604 Constant *ConstantExpr::getUIToFP(Constant *C, Type *Ty) {
1607 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1610 assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
1612 return getFoldedCast(Instruction::UIToFP, C, Ty);
1615 Constant *ConstantExpr::getSIToFP(Constant *C, Type *Ty) {
1618 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1621 assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
1623 return getFoldedCast(Instruction::SIToFP, C, Ty);
1626 Constant *ConstantExpr::getFPToUI(Constant *C, Type *Ty) {
1629 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1632 assert(C->getType()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() &&
1634 return getFoldedCast(Instruction::FPToUI, C, Ty);
1637 Constant *ConstantExpr::getFPToSI(Constant *C, Type *Ty) {
1640 bool toVec = Ty->getTypeID() == Type::VectorTyID;
1643 assert(C->getType()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() &&
1645 return getFoldedCast(Instruction::FPToSI, C, Ty);
1767 Constant *ConstantExpr::getSizeOf(Type* Ty) {
1768 // sizeof is implemented as: (i64) gep (Ty*)null, 1
1770 Constant *GEPIdx = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
1772 Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx);
1774 Type::getInt64Ty(Ty->getContext()));
1777 Constant *ConstantExpr::getAlignOf(Type* Ty) {
1778 // alignof is implemented as: (i64) gep ({i1,Ty}*)null, 0, 1
1781 StructType::get(Type::getInt1Ty(Ty->getContext()), Ty, NULL);
1783 Constant *Zero = ConstantInt::get(Type::getInt64Ty(Ty->getContext()), 0);
1784 Constant *One = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
1788 Type::getInt64Ty(Ty->getContext()));
1796 Constant *ConstantExpr::getOffsetOf(Type* Ty, Constant *FieldNo) {
1797 // offsetof is implemented as: (i64) gep (Ty*)null, 0, FieldNo
1800 ConstantInt::get(Type::getInt64Ty(Ty->getContext()), 0),
1804 Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx);
1806 Type::getInt64Ty(Ty->getContext()));
1853 Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), Idxs);
1854 assert(Ty && "GEP indices invalid!");
1856 Type *ReqTy = Ty->getPointerTo(AS);
2131 Constant *ConstantExpr::getBinOpIdentity(unsigned Opcode, Type *Ty) {
2140 return Constant::getNullValue(Ty);
2143 return ConstantInt::get(Ty, 1);
2146 return Constant::getAllOnesValue(Ty);
2154 Constant *ConstantExpr::getBinOpAbsorber(unsigned Opcode, Type *Ty) {
2161 return Constant::getAllOnesValue(Ty);
2165 return Constant::getNullValue(Ty);
2212 bool ConstantDataSequential::isElementTypeCompatible(const Type *Ty) {
2213 if (Ty->isFloatTy() || Ty->isDoubleTy()) return true;
2214 if (const IntegerType *IT = dyn_cast<IntegerType>(Ty)) {
2259 Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) {
2260 assert(isElementTypeCompatible(Ty->getSequentialElementType()));
2264 return ConstantAggregateZero::get(Ty);
2268 Ty->getContext().pImpl->CDSConstants.GetOrCreateValue(Elements);
2277 if (Node->getType() == Ty)
2282 if (isa<ArrayType>(Ty))
2283 return *Entry = new ConstantDataArray(Ty, Slot.getKeyData());
2285 assert(isa<VectorType>(Ty));
2286 return *Entry = new ConstantDataVector(Ty, Slot.getKeyData());
2333 Type *Ty = ArrayType::get(Type::getInt8Ty(Context), Elts.size());
2335 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*1), Ty);
2338 Type *Ty = ArrayType::get(Type::getInt16Ty(Context), Elts.size());
2340 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*2), Ty);
2343 Type *Ty = ArrayType::get(Type::getInt32Ty(Context), Elts.size());
2345 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*4), Ty);
2348 Type *Ty = ArrayType::get(Type::getInt64Ty(Context), Elts.size());
2350 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*8), Ty);
2353 Type *Ty = ArrayType::get(Type::getFloatTy(Context), Elts.size());
2355 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*4), Ty);
2358 Type *Ty = ArrayType::get(Type::getDoubleTy(Context), Elts.size());
2360 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*8), Ty);
2386 Type *Ty = VectorType::get(Type::getInt8Ty(Context), Elts.size());
2388 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*1), Ty);
2391 Type *Ty = VectorType::get(Type::getInt16Ty(Context), Elts.size());
2393 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*2), Ty);
2396 Type *Ty = VectorType::get(Type::getInt32Ty(Context), Elts.size());
2398 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*4), Ty);
2401 Type *Ty = VectorType::get(Type::getInt64Ty(Context), Elts.size());
2403 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*8), Ty);
2406 Type *Ty = VectorType::get(Type::getFloatTy(Context), Elts.size());
2408 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*4), Ty);
2411 Type *Ty = VectorType::get(Type::getDoubleTy(Context), Elts.size());
2413 return getImpl(StringRef(const_cast<char *>(Data), Elts.size()*8), Ty);