Lines Matching +full:nand +full:- +full:style
1 //===- Instructions.cpp - Implement the LLVM instructions -----------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements all of the non-inline methods for the LLVM instruction
12 //===----------------------------------------------------------------------===//
54 "disable-i2p-p2i-opt", cl::init(false),
57 //===----------------------------------------------------------------------===//
59 //===----------------------------------------------------------------------===//
70 checkedMulUnsigned(Size.getKnownMinValue(), C->getZExtValue());
83 auto CheckedProd = checkedMulUnsigned(Size->getKnownMinValue(),
87 return TypeSize::get(*CheckedProd, Size->isScalable());
90 //===----------------------------------------------------------------------===//
92 //===----------------------------------------------------------------------===//
94 /// areInvalidOperands - Return a string if the specified operands are invalid
97 if (Op1->getType() != Op2->getType())
100 if (Op1->getType()->isTokenTy())
103 if (VectorType *VT = dyn_cast<VectorType>(Op0->getType())) {
105 if (VT->getElementType() != Type::getInt1Ty(Op0->getContext()))
107 VectorType *ET = dyn_cast<VectorType>(Op1->getType());
110 if (ET->getElementCount() != VT->getElementCount())
113 } else if (Op0->getType() != Type::getInt1Ty(Op0->getContext())) {
119 //===----------------------------------------------------------------------===//
121 //===----------------------------------------------------------------------===//
132 // removeIncomingValue - Remove an incoming value. This is useful if a
146 Op<-1>().set(nullptr);
147 setNumHungOffUseOperands(getNumOperands() - 1);
178 return RemoveIndices.contains(&BB - block_begin());
181 setNumHungOffUseOperands(getNumOperands() - RemoveIndices.size());
191 /// growOperands - grow operands - This grows the operand list in response
192 /// to a push_back style of operation. This grows the number of ops by 1.5
204 /// hasConstantValue - If the specified PHI node always merges together the same
221 /// hasConstantOrUndefValue - Whether the specified PHI node always merges
223 /// non-undefs.
225 /// unique non-undef incoming value need not dominate the PHI node.
239 //===----------------------------------------------------------------------===//
241 //===----------------------------------------------------------------------===//
277 /// growOperands - grow operands - This grows the operand list in response to a
278 /// push_back style of operation. This grows the number of ops by 2 times.
294 //===----------------------------------------------------------------------===//
296 //===----------------------------------------------------------------------===//
300 switch (CB->getOpcode()) {
308 llvm_unreachable("Unknown CallBase sub-class!");
315 for (unsigned i = 0, e = CI->getNumOperandBundles(); i < e; ++i) {
316 auto ChildOB = CI->getOperandBundleAt(i);
324 Function *CallBase::getCaller() { return getParent()->getParent(); }
328 return cast<CallBrInst>(this)->getNumIndirectDests() + 1;
342 return CI->isMustTailCall();
349 return CI->isTailCall();
355 return F->getIntrinsicID();
363 Mask |= F->getAttributes().getRetNoFPClass();
371 Mask |= F->getAttributes().getParamNoFPClass(i);
387 !NullPointerIsDefined(getCaller(), getType()->getPointerAddressSpace()))
397 return getArgOperand(Index - AttributeList::FirstArgIndex);
399 if (F->getAttributes().hasAttrSomewhere(Kind, &Index))
400 return getArgOperand(Index - AttributeList::FirstArgIndex);
416 if (!F->getAttributes().hasParamAttr(ArgNo, Kind))
434 return F->getAttributes().hasFnAttr(Kind);
441 return F->getAttributes().hasFnAttr(Kind);
449 // getMemoryEffects() correctly combines memory effects from the call-site,
455 return F->getAttributes().getFnAttr(Kind);
470 return F->getAttributes().getParamAttr(ArgNo, Kind);
500 BOI.Tag = ContextImpl->getOrInsertBundleTag(BI->getTag());
502 BOI.End = CurrentIndex + BI->input_size();
514 /// Else fallback to a binary-search that use the fact that bundles usually
516 if (bundle_op_info_end() - bundle_op_info_begin() < 8) {
525 assert(bundle_op_info_end() - bundle_op_info_begin() > 0 &&
526 OpIdx < std::prev(bundle_op_info_end())->End &&
539 NumberScaling * (std::prev(End)->End - Begin->Begin) / (End - Begin);
540 Current = Begin + (((OpIdx - Begin->Begin) * NumberScaling) /
546 if (OpIdx >= Current->Begin && OpIdx < Current->End)
548 if (OpIdx >= Current->End)
554 assert(OpIdx >= Current->Begin && OpIdx < Current->End &&
562 if (CB->getOperandBundle(ID))
566 CB->getOperandBundlesAsDefs(Bundles);
576 for (unsigned I = 0, E = CB->getNumOperandBundles(); I != E; ++I) {
577 auto Bundle = CB->getOperandBundleAt(I);
590 // bundle semantics, where *any* non-assume operand bundle (other than
607 MemoryEffects FnME = Fn->getMemoryEffects();
675 //===----------------------------------------------------------------------===//
677 //===----------------------------------------------------------------------===//
681 this->FTy = FTy;
686 assert((Args.size() == FTy->getNumParams() ||
687 (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
691 assert((i >= FTy->getNumParams() ||
692 FTy->getParamType(i) == Args[i]->getType()) &&
696 // Set operands in order of their index to match use-list-order
709 this->FTy = FTy;
713 assert(FTy->getNumParams() == 0 && "Calling a function with bad signature");
720 : CallBase(Ty->getReturnType(), Instruction::Call,
721 OperandTraits<CallBase>::op_end(this) - 1, 1, InsertBefore) {
727 OperandTraits<CallBase>::op_end(this) - CI.getNumOperands(),
740 std::vector<Value *> Args(CI->arg_begin(), CI->arg_end());
742 auto *NewCI = CallInst::Create(CI->getFunctionType(), CI->getCalledOperand(),
743 Args, OpB, CI->getName(), InsertPt);
744 NewCI->setTailCallKind(CI->getTailCallKind());
745 NewCI->setCallingConv(CI->getCallingConv());
746 NewCI->SubclassOptionalData = CI->SubclassOptionalData;
747 NewCI->setAttributes(CI->getAttributes());
748 NewCI->setDebugLoc(CI->getDebugLoc());
759 << getParent()->getParent()->getName()
761 "with non-zero prof info.");
767 //===----------------------------------------------------------------------===//
769 //===----------------------------------------------------------------------===//
775 this->FTy = FTy;
782 assert(((Args.size() == FTy->getNumParams()) ||
783 (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
787 assert((i >= FTy->getNumParams() ||
788 FTy->getParamType(i) == Args[i]->getType()) &&
792 // Set operands in order of their index to match use-list-order
808 OperandTraits<CallBase>::op_end(this) - II.getNumOperands(),
819 std::vector<Value *> Args(II->arg_begin(), II->arg_end());
822 II->getFunctionType(), II->getCalledOperand(), II->getNormalDest(),
823 II->getUnwindDest(), Args, OpB, II->getName(), InsertPt);
824 NewII->setCallingConv(II->getCallingConv());
825 NewII->SubclassOptionalData = II->SubclassOptionalData;
826 NewII->setAttributes(II->getAttributes());
827 NewII->setDebugLoc(II->getDebugLoc());
832 return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHI());
839 << getParent()->getParent()->getName()
841 "with non-zero prof info.");
847 //===----------------------------------------------------------------------===//
849 //===----------------------------------------------------------------------===//
856 this->FTy = FTy;
864 assert(((Args.size() == FTy->getNumParams()) ||
865 (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
869 assert((i >= FTy->getNumParams() ||
870 FTy->getParamType(i) == Args[i]->getType()) &&
874 // Set operands in order of their index to match use-list-order
892 OperandTraits<CallBase>::op_end(this) - CBI.getNumOperands(),
904 std::vector<Value *> Args(CBI->arg_begin(), CBI->arg_end());
907 CBI->getFunctionType(), CBI->getCalledOperand(), CBI->getDefaultDest(),
908 CBI->getIndirectDests(), Args, OpB, CBI->getName(), InsertPt);
909 NewCBI->setCallingConv(CBI->getCallingConv());
910 NewCBI->SubclassOptionalData = CBI->SubclassOptionalData;
911 NewCBI->setAttributes(CBI->getAttributes());
912 NewCBI->setDebugLoc(CBI->getDebugLoc());
913 NewCBI->NumIndirectDests = CBI->NumIndirectDests;
917 //===----------------------------------------------------------------------===//
919 //===----------------------------------------------------------------------===//
923 OperandTraits<ReturnInst>::op_end(this) - RI.getNumOperands(),
933 OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
939 //===----------------------------------------------------------------------===//
941 //===----------------------------------------------------------------------===//
950 : Instruction(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
955 //===----------------------------------------------------------------------===//
957 //===----------------------------------------------------------------------===//
961 OperandTraits<CleanupReturnInst>::op_end(this) -
983 : Instruction(Type::getVoidTy(CleanupPad->getContext()),
985 OperandTraits<CleanupReturnInst>::op_end(this) - Values,
990 //===----------------------------------------------------------------------===//
992 //===----------------------------------------------------------------------===//
1007 : Instruction(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
1013 //===----------------------------------------------------------------------===//
1015 //===----------------------------------------------------------------------===//
1021 : Instruction(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
1055 /// growOperands - grow operands - This grows the operand list in response to a
1056 /// push_back style of operation. This grows the number of ops by 2 times.
1076 Use *EndDst = op_end() - 1;
1082 setNumHungOffUseOperands(getNumOperands() - 1);
1085 //===----------------------------------------------------------------------===//
1087 //===----------------------------------------------------------------------===//
1098 OperandTraits<FuncletPadInst>::op_end(this) -
1109 : Instruction(ParentPad->getType(), Op,
1110 OperandTraits<FuncletPadInst>::op_end(this) - Values, Values,
1115 //===----------------------------------------------------------------------===//
1117 //===----------------------------------------------------------------------===//
1124 //===----------------------------------------------------------------------===//
1126 //===----------------------------------------------------------------------===//
1130 assert(getCondition()->getType()->isIntegerTy(1) &&
1135 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
1136 OperandTraits<BranchInst>::op_end(this) - 1, 1,
1139 Op<-1>() = IfTrue;
1144 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
1145 OperandTraits<BranchInst>::op_end(this) - 3, 3,
1147 // Assign in order of operand index to make use-list order predictable.
1148 Op<-3>() = Cond;
1149 Op<-2>() = IfFalse;
1150 Op<-1>() = IfTrue;
1158 OperandTraits<BranchInst>::op_end(this) - BI.getNumOperands(),
1160 // Assign in order of operand index to make use-list order predictable.
1163 Op<-3>() = BI.Op<-3>();
1164 Op<-2>() = BI.Op<-2>();
1166 Op<-1>() = BI.Op<-1>();
1173 Op<-1>().swap(Op<-2>());
1180 //===----------------------------------------------------------------------===//
1182 //===----------------------------------------------------------------------===//
1190 assert(Amt->getType()->isIntegerTy() &&
1200 assert(BB->getParent() &&
1202 const DataLayout &DL = BB->getDataLayout();
1220 getAISize(Ty->getContext(), ArraySize), InsertBefore),
1223 assert(!Ty->isVoidTy() && "Cannot allocate void!");
1229 return !CI->isOne();
1233 /// isStaticAlloca - Return true if this alloca is in the entry block of the
1242 return Parent->isEntryBlock() && !isUsedWithInAlloca();
1245 //===----------------------------------------------------------------------===//
1247 //===----------------------------------------------------------------------===//
1250 assert(getOperand(0)->getType()->isPointerTy() &&
1258 assert(BB->getParent() &&
1260 const DataLayout &DL = BB->getDataLayout();
1289 //===----------------------------------------------------------------------===//
1291 //===----------------------------------------------------------------------===//
1294 assert(getOperand(0) && getOperand(1) && "Both operands must be non-null!");
1295 assert(getOperand(1)->getType()->isPointerTy() &&
1305 computeLoadStoreDefaultAlign(val->getType(), InsertBefore),
1316 : Instruction(Type::getVoidTy(val->getContext()), Store,
1327 //===----------------------------------------------------------------------===//
1329 //===----------------------------------------------------------------------===//
1344 "All operands must be non-null!");
1345 assert(getOperand(0)->getType()->isPointerTy() &&
1347 assert(getOperand(1)->getType() == getOperand(2)->getType() &&
1358 StructType::get(Cmp->getType(), Type::getInt1Ty(Cmp->getContext())),
1364 //===----------------------------------------------------------------------===//
1366 //===----------------------------------------------------------------------===//
1382 assert(getOperand(0) && getOperand(1) && "All operands must be non-null!");
1383 assert(getOperand(0)->getType()->isPointerTy() &&
1392 : Instruction(Val->getType(), AtomicRMW,
1408 case AtomicRMWInst::Nand:
1409 return "nand";
1441 //===----------------------------------------------------------------------===//
1443 //===----------------------------------------------------------------------===//
1452 //===----------------------------------------------------------------------===//
1454 //===----------------------------------------------------------------------===//
1467 OperandTraits<GetElementPtrInst>::op_end(this) -
1478 if (!Struct->indexValid(Idx))
1480 return Struct->getTypeAtIndex(Idx);
1482 if (!Idx->getType()->isIntOrIntVectorTy())
1485 return Array->getElementType();
1487 return Vector->getElementType();
1493 if (Idx >= Struct->getNumElements())
1495 return Struct->getElementType(Idx);
1498 return Array->getElementType();
1500 return Vector->getElementType();
1529 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
1535 if (!CI->isZero()) return false;
1543 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
1559 GEPNoWrapFlags NW = cast<GEPOperator>(this)->getNoWrapFlags();
1568 return cast<GEPOperator>(this)->getNoWrapFlags();
1572 return cast<GEPOperator>(this)->isInBounds();
1576 return cast<GEPOperator>(this)->hasNoUnsignedSignedWrap();
1580 return cast<GEPOperator>(this)->hasNoUnsignedWrap();
1586 return cast<GEPOperator>(this)->accumulateConstantOffset(DL, Offset);
1594 return cast<GEPOperator>(this)->collectOffset(DL, BitWidth, VariableOffsets,
1598 //===----------------------------------------------------------------------===//
1600 //===----------------------------------------------------------------------===//
1606 cast<VectorType>(Val->getType())->getElementType(), ExtractElement,
1616 if (!Val->getType()->isVectorTy() || !Index->getType()->isIntegerTy())
1621 //===----------------------------------------------------------------------===//
1623 //===----------------------------------------------------------------------===//
1628 : Instruction(Vec->getType(), InsertElement,
1641 if (!Vec->getType()->isVectorTy())
1644 if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType())
1647 if (!Index->getType()->isIntegerTy())
1652 //===----------------------------------------------------------------------===//
1654 //===----------------------------------------------------------------------===//
1658 return PoisonValue::get(V->getType());
1676 VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1677 cast<VectorType>(Mask->getType())->getElementCount()),
1695 VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1696 Mask.size(), isa<ScalableVectorType>(V1->getType())),
1708 int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
1717 assert(MaskElt >= 0 && MaskElt < 2 * NumOpElts && "Out-of-range mask");
1718 MaskElt = (MaskElt < NumOpElts) ? MaskElt + NumOpElts : MaskElt - NumOpElts;
1728 if (!isa<VectorType>(V1->getType()) || V1->getType() != V2->getType())
1733 cast<VectorType>(V1->getType())->getElementCount().getKnownMinValue();
1738 if (isa<ScalableVectorType>(V1->getType()))
1748 if (!V1->getType()->isVectorTy() || V1->getType() != V2->getType())
1753 auto *MaskTy = dyn_cast<VectorType>(Mask->getType());
1754 if (!MaskTy || !MaskTy->getElementType()->isIntegerTy(32) ||
1755 isa<ScalableVectorType>(MaskTy) != isa<ScalableVectorType>(V1->getType()))
1763 unsigned V1Size = cast<FixedVectorType>(V1->getType())->getNumElements();
1764 for (Value *Op : MV->operands()) {
1766 if (CI->uge(V1Size*2))
1776 unsigned V1Size = cast<FixedVectorType>(V1->getType())->getNumElements();
1777 for (unsigned i = 0, e = cast<FixedVectorType>(MaskTy)->getNumElements();
1779 if (CDS->getElementAsInteger(i) >= V1Size*2)
1789 ElementCount EC = cast<VectorType>(Mask->getType())->getElementCount();
1801 int MaskVal = isa<UndefValue>(Mask) ? -1 : 0;
1811 Result.push_back(CDS->getElementAsInteger(i));
1815 Constant *C = Mask->getAggregateElement(i);
1816 Result.push_back(isa<UndefValue>(C) ? -1 :
1817 cast<ConstantInt>(C)->getZExtValue());
1828 Type *Int32Ty = Type::getInt32Ty(ResultTy->getContext());
1851 if (I == -1)
1854 "Out-of-bounds shuffle mask element");
1874 if (Mask[i] == -1)
1901 if (Mask[I] == -1)
1903 if (Mask[I] != (NumSrcElts - 1 - I) &&
1904 Mask[I] != (NumSrcElts + NumSrcElts - 1 - I))
1916 if (Mask[I] == -1)
1931 if (Mask[I] == -1)
1948 // 1. The number of elements in the mask must be a power-of-2 and at least 2.
1959 if ((Mask[1] - Mask[0]) != NumSrcElts)
1962 // 4. The difference between consecutive even-numbered and odd-numbered
1966 if (MaskEltVal == -1)
1968 int MaskEltPrevVal = Mask[I - 2];
1969 if (MaskEltVal - MaskEltPrevVal != 2)
1980 int StartIndex = -1;
1983 if (MaskEltVal == -1)
1986 if (StartIndex == -1) {
1988 // first non-undef index would access below the StartIndex.
1989 if (MaskEltVal < I || NumSrcElts <= (MaskEltVal - I))
1992 StartIndex = MaskEltVal - I;
2001 if (StartIndex == -1)
2020 int SubIndex = -1;
2025 int Offset = (M % NumSrcElts) - i;
2047 // TODO: We don't recognize self-insertion/widening.
2075 "2-source shuffle not found");
2081 int Src0Hi = NumMaskElts - Src0Elts.countl_zero();
2082 int Src1Hi = NumMaskElts - Src1Elts.countl_zero();
2087 int NumSub1Elts = Src1Hi - Src1Lo;
2099 int NumSub0Elts = Src0Hi - Src0Lo;
2117 int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2118 int NumMaskElts = cast<FixedVectorType>(getType())->getNumElements();
2129 if (Mask[i] != -1)
2141 int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2142 int NumMaskElts = cast<FixedVectorType>(getType())->getNumElements();
2159 int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2160 int NumMaskElts = cast<FixedVectorType>(getType())->getNumElements();
2193 // undef-less case is trivial.
2210 int Largest = -1;
2214 // Elements must be in non-decreasing order.
2244 VF = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2284 FixedVectorType *OpTy = dyn_cast<FixedVectorType>(getOperand(0)->getType());
2285 // shuffle_vector can only interleave fixed length vectors - for scalable
2289 unsigned OpNumElts = OpTy->getNumElements();
2316 for (J = 0; J < LaneLen - 1; J++) {
2336 // Verify this by storing the last non-undef followed by an undef
2337 // Check that following non-undef masks are incremented with the
2347 if (J < LaneLen - 1)
2354 } else if (Mask[(LaneLen - 1) * Factor + I] >= 0) {
2356 StartMask = Mask[(LaneLen - 1) * Factor + I] - J;
2358 // StartMask defined by some non-zero value in the j loop
2359 StartMask = SavedLaneValue - (LaneLen - 1 - SavedNoUndefs);
2375 /// Check if the mask is a DE-interleave mask of the given factor
2377 /// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
2381 // Check all potential start indices from 0 to (Factor - 1).
2403 /// Returns an element-wise left bit rotation amount or -1 if failed.
2408 int RotateAmt = -1;
2415 return -1;
2416 int Offset = (NumSubElts - (M - (i + j))) % NumSubElts;
2418 return -1;
2439 //===----------------------------------------------------------------------===//
2441 //===----------------------------------------------------------------------===//
2453 assert(ExtractValueInst::getIndexedType(Agg->getType(), Idxs) ==
2454 Val->getType() && "Inserted value must match indexed type!");
2471 //===----------------------------------------------------------------------===//
2473 //===----------------------------------------------------------------------===//
2492 // getIndexedType - Returns the type of the element that would be extracted
2503 // out-of-bounds indices. Since we don't allow those for extractvalue and
2508 if (Index >= AT->getNumElements())
2510 Agg = AT->getElementType();
2512 if (Index >= ST->getNumElements())
2514 Agg = ST->getElementType(Index);
2523 //===----------------------------------------------------------------------===//
2525 //===----------------------------------------------------------------------===//
2537 return new UnaryOperator(Op, S, S->getType(), Name, InsertBefore);
2546 assert(getType() == LHS->getType() &&
2548 assert(getType()->isFPOrFPVectorTy() &&
2549 "Tried to create a floating-point operation on a "
2550 "non-floating-point type!");
2557 //===----------------------------------------------------------------------===//
2559 //===----------------------------------------------------------------------===//
2574 assert(LHS->getType() == RHS->getType() &&
2580 assert(getType() == LHS->getType() &&
2582 assert(getType()->isIntOrIntVectorTy() &&
2583 "Tried to create an integer operation on a non-integer type!");
2587 assert(getType() == LHS->getType() &&
2589 assert(getType()->isFPOrFPVectorTy() &&
2590 "Tried to create a floating-point operation on a "
2591 "non-floating-point type!");
2595 assert(getType() == LHS->getType() &&
2597 assert(getType()->isIntOrIntVectorTy() &&
2601 assert(getType() == LHS->getType() &&
2603 assert(getType()->isFPOrFPVectorTy() &&
2608 assert(getType() == LHS->getType() &&
2610 assert(getType()->isIntOrIntVectorTy() &&
2614 assert(getType() == LHS->getType() &&
2616 assert(getType()->isFPOrFPVectorTy() &&
2622 assert(getType() == LHS->getType() &&
2624 assert(getType()->isIntOrIntVectorTy() &&
2625 "Tried to create a shift operation on a non-integral type!");
2629 assert(getType() == LHS->getType() &&
2631 assert(getType()->isIntOrIntVectorTy() &&
2632 "Tried to create a logical operation on a non-integral type!");
2642 assert(S1->getType() == S2->getType() &&
2644 return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
2649 Value *Zero = ConstantInt::get(Op->getType(), 0);
2650 return new BinaryOperator(Instruction::Sub, Zero, Op, Op->getType(), Name,
2656 Value *Zero = ConstantInt::get(Op->getType(), 0);
2662 Constant *C = Constant::getAllOnesValue(Op->getType());
2664 Op->getType(), Name, InsertBefore);
2669 // instruction. If the instruction is order-dependent (SetLT f.e.), the opcode
2678 //===----------------------------------------------------------------------===//
2680 //===----------------------------------------------------------------------===//
2684 cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
2687 ConstantFP *Accuracy = mdconst::extract<ConstantFP>(MD->getOperand(0));
2688 return Accuracy->getValueAPF().convertToFloat();
2691 //===----------------------------------------------------------------------===//
2693 //===----------------------------------------------------------------------===//
2695 // Just determine if this cast only deals with integral->integral conversion.
2704 return getOperand(0)->getType()->isIntegerTy() &&
2705 getType()->isIntegerTy();
2711 /// no code gen is necessary for the cast, hence the name no-op cast. For
2712 /// example, the following are all no-op casts:
2715 /// # ptrtoint i32* %x to i32 ; on 32-bit plaforms only
2716 /// Determine if the described cast is a no-op.
2739 return DL.getIntPtrType(SrcTy)->getScalarSizeInBits() ==
2740 DestTy->getScalarSizeInBits();
2742 return DL.getIntPtrType(DestTy)->getScalarSizeInBits() ==
2743 SrcTy->getScalarSizeInBits();
2748 return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), DL);
2771 // -------- ------------ ------------------- ---------------------
2786 // NOTE: some transforms are safe, but we consider them to be non-profitable.
2789 // of the produced value (we no longer know the top-part is all zeros).
2794 Instruction::CastOpsEnd - Instruction::CastOpsBegin;
2796 // T F F U S F F P I B A -+
2798 // U E E 2 2 2 2 R E I T C C +- secondOp
2800 // C T T I I P P C T T P T T -+
2801 { 1, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // Trunc -+
2806 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // UIToFP +- firstOp
2813 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13,12}, // AddrSpaceCast -+
2824 // Check if any of the casts convert scalars <-> vectors.
2830 int ElimCase = CastResults[firstOp-Instruction::CastOpsBegin]
2831 [secondOp-Instruction::CastOpsBegin];
2843 // No-op cast in second op implies firstOp as long as the DestTy
2845 // non-vector type.
2846 if (!SrcTy->isVectorTy() && DstTy->isIntegerTy())
2850 // No-op cast in second op implies firstOp as long as the DestTy
2856 // No-op cast in first op implies secondOp as long as the SrcTy
2858 if (SrcTy->isIntegerTy())
2867 if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
2870 unsigned MidSize = MidTy->getScalarSizeInBits();
2878 // ptrtoint, inttoptr -> bitcast (ptr -> ptr) if int size is >= ptr size.
2881 unsigned PtrSize = SrcIntPtrTy->getScalarSizeInBits();
2887 // ext, trunc -> bitcast, if the SrcTy and DstTy are the same
2888 // ext, trunc -> ext, if sizeof(SrcTy) < sizeof(DstTy)
2889 // ext, trunc -> trunc, if sizeof(SrcTy) > sizeof(DstTy)
2890 unsigned SrcSize = SrcTy->getScalarSizeInBits();
2891 unsigned DstSize = DstTy->getScalarSizeInBits();
2901 // zext, sext -> zext, because sext can't sign extend after zext
2904 // inttoptr, ptrtoint -> bitcast if SrcSize<=PtrSize and SrcSize==DstSize
2907 unsigned PtrSize = MidIntPtrTy->getScalarSizeInBits();
2908 unsigned SrcSize = SrcTy->getScalarSizeInBits();
2909 unsigned DstSize = DstTy->getScalarSizeInBits();
2915 // addrspacecast, addrspacecast -> bitcast, if SrcAS == DstAS
2916 // addrspacecast, addrspacecast -> addrspacecast, if SrcAS != DstAS
2917 if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
2925 SrcTy->isPtrOrPtrVectorTy() &&
2926 MidTy->isPtrOrPtrVectorTy() &&
2927 DstTy->isPtrOrPtrVectorTy() &&
2928 SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() &&
2929 MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&
2934 // bitcast, addrspacecast -> addrspacecast
2941 SrcTy->isIntOrIntVectorTy() &&
2942 MidTy->isPtrOrPtrVectorTy() &&
2943 DstTy->isPtrOrPtrVectorTy() &&
2944 MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&
2953 SrcTy->isPtrOrPtrVectorTy() &&
2954 MidTy->isPtrOrPtrVectorTy() &&
2955 DstTy->isIntOrIntVectorTy() &&
2956 SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() &&
2961 // (sitofp (zext x)) -> (uitofp x)
2999 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
3006 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
3013 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
3021 assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
3022 assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
3024 assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast");
3025 assert((!Ty->isVectorTy() ||
3026 cast<VectorType>(Ty)->getElementCount() ==
3027 cast<VectorType>(S->getType())->getElementCount()) &&
3030 if (Ty->isIntOrIntVectorTy())
3038 assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
3039 assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
3041 if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
3050 if (S->getType()->isPointerTy() && Ty->isIntegerTy())
3052 if (S->getType()->isIntegerTy() && Ty->isPointerTy())
3061 assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&
3063 unsigned SrcBits = C->getType()->getScalarSizeInBits();
3064 unsigned DstBits = Ty->getScalarSizeInBits();
3074 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
3076 unsigned SrcBits = C->getType()->getScalarSizeInBits();
3077 unsigned DstBits = Ty->getScalarSizeInBits();
3078 assert((C->getType() == Ty || SrcBits != DstBits) && "Invalid cast");
3086 if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType())
3094 if (SrcVecTy->getElementCount() == DestVecTy->getElementCount()) {
3096 SrcTy = SrcVecTy->getElementType();
3097 DestTy = DestVecTy->getElementType();
3104 return SrcPtrTy->getAddressSpace() == DestPtrTy->getAddressSpace();
3108 TypeSize SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
3109 TypeSize DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
3119 if (DestTy->isX86_MMXTy() || SrcTy->isX86_MMXTy())
3127 // ptrtoint and inttoptr are not allowed on non-integral pointers
3130 return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
3134 return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
3149 Type *SrcTy = Src->getType();
3151 assert(SrcTy->isFirstClassType() && DestTy->isFirstClassType() &&
3160 if (SrcVecTy->getElementCount() == DestVecTy->getElementCount()) {
3163 SrcTy = SrcVecTy->getElementType();
3164 DestTy = DestVecTy->getElementType();
3168 unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
3169 unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
3172 if (DestTy->isIntegerTy()) { // Casting to integral
3173 if (SrcTy->isIntegerTy()) { // Casting from integral
3175 return Trunc; // int -> smaller int
3178 return SExt; // signed -> SEXT
3180 return ZExt; // unsigned -> ZEXT
3182 return BitCast; // Same size, No-op cast
3184 } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt
3186 return FPToSI; // FP -> sint
3188 return FPToUI; // FP -> uint
3189 } else if (SrcTy->isVectorTy()) {
3192 return BitCast; // Same size, no-op cast
3194 assert(SrcTy->isPointerTy() &&
3195 "Casting from a value that is not first-class type");
3196 return PtrToInt; // ptr -> int
3198 } else if (DestTy->isFloatingPointTy()) { // Casting to floating pt
3199 if (SrcTy->isIntegerTy()) { // Casting from integral
3201 return SIToFP; // sint -> FP
3203 return UIToFP; // uint -> FP
3204 } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt
3206 return FPTrunc; // FP -> smaller FP
3208 return FPExt; // FP -> larger FP
3210 return BitCast; // same size, no-op cast
3212 } else if (SrcTy->isVectorTy()) {
3215 return BitCast; // same size, no-op cast
3217 llvm_unreachable("Casting pointer or non-first class to float");
3218 } else if (DestTy->isVectorTy()) {
3222 } else if (DestTy->isPointerTy()) {
3223 if (SrcTy->isPointerTy()) {
3224 if (DestTy->getPointerAddressSpace() != SrcTy->getPointerAddressSpace())
3226 return BitCast; // ptr -> ptr
3227 } else if (SrcTy->isIntegerTy()) {
3228 return IntToPtr; // int -> ptr
3231 } else if (DestTy->isX86_MMXTy()) {
3232 if (SrcTy->isVectorTy()) {
3234 return BitCast; // 64-bit vector to MMX
3238 llvm_unreachable("Casting to type that is not first-class");
3241 //===----------------------------------------------------------------------===//
3243 //===----------------------------------------------------------------------===//
3251 if (!SrcTy->isFirstClassType() || !DstTy->isFirstClassType() ||
3252 SrcTy->isAggregateType() || DstTy->isAggregateType())
3259 unsigned SrcScalarBitSize = SrcTy->getScalarSizeInBits();
3260 unsigned DstScalarBitSize = DstTy->getScalarSizeInBits();
3265 ElementCount SrcEC = SrcIsVec ? cast<VectorType>(SrcTy)->getElementCount()
3267 ElementCount DstEC = DstIsVec ? cast<VectorType>(DstTy)->getElementCount()
3274 return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
3277 return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
3280 return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
3283 return SrcTy->isFPOrFPVectorTy() && DstTy->isFPOrFPVectorTy() &&
3286 return SrcTy->isFPOrFPVectorTy() && DstTy->isFPOrFPVectorTy() &&
3290 return SrcTy->isIntOrIntVectorTy() && DstTy->isFPOrFPVectorTy() &&
3294 return SrcTy->isFPOrFPVectorTy() && DstTy->isIntOrIntVectorTy() &&
3299 return SrcTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy();
3303 return SrcTy->isIntOrIntVectorTy() && DstTy->isPtrOrPtrVectorTy();
3305 PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy->getScalarType());
3306 PointerType *DstPtrTy = dyn_cast<PointerType>(DstTy->getScalarType());
3308 // BitCast implies a no-op cast of type only. No bits change.
3313 // For non-pointer cases, the cast is okay if the source and destination bit
3316 return SrcTy->getPrimitiveSizeInBits() == DstTy->getPrimitiveSizeInBits();
3319 if (SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace())
3333 PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy->getScalarType());
3337 PointerType *DstPtrTy = dyn_cast<PointerType>(DstTy->getScalarType());
3341 if (SrcPtrTy->getAddressSpace() == DstPtrTy->getAddressSpace())
3427 //===----------------------------------------------------------------------===//
3429 //===----------------------------------------------------------------------===//
3469 Inst->copyIRFlags(FlagsSource);
3475 IC->swapOperands();
3477 cast<FCmpInst>(this)->swapOperands();
3482 return IC->isCommutative();
3483 return cast<FCmpInst>(this)->isCommutative();
3784 llvm_unreachable("Unexpected non-integer predicate.");
3831 "Call only with non-equality predicates!");
3904 //===----------------------------------------------------------------------===//
3906 //===----------------------------------------------------------------------===//
3918 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
3924 : Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
3942 /// addCase - Add an entry to the switch instruction...
3957 /// removeCase - This method removes the specified case and its successor
3960 unsigned idx = I->getCaseIndex();
3969 OL[2 + idx * 2] = OL[NumOps - 2];
3970 OL[2 + idx * 2 + 1] = OL[NumOps - 1];
3974 OL[NumOps-2].set(nullptr);
3975 OL[NumOps-2+1].set(nullptr);
3976 setNumHungOffUseOperands(NumOps-2);
3981 /// growOperands - grow operands - This grows the operand list in response
3982 /// to a push_back style of operation. This grows the number of ops by 3 times.
3998 assert(SI.getNumSuccessors() == Weights->size() &&
4003 if (AllZeroes || Weights->size() < 2)
4006 return MDBuilder(SI.getParent()->getContext()).createBranchWeights(*Weights);
4022 this->Weights = std::move(Weights);
4028 assert(SI.getNumSuccessors() == Weights->size() &&
4034 (*Weights)[I->getCaseIndex() + 1] = Weights->back();
4035 Weights->pop_back();
4048 (*Weights)[SI.getNumSuccessors() - 1] = *W;
4051 Weights->push_back(W.value_or(0));
4054 assert(SI.getNumSuccessors() == Weights->size() &&
4063 Weights->resize(0);
4095 if (ProfileData->getNumOperands() == SI.getNumSuccessors() + 1)
4096 return mdconst::extract<ConstantInt>(ProfileData->getOperand(idx + 1))
4097 ->getValue()
4103 //===----------------------------------------------------------------------===//
4105 //===----------------------------------------------------------------------===//
4108 assert(Address && Address->getType()->isPointerTy() &&
4118 /// growOperands - grow operands - This grows the operand list in response
4119 /// to a push_back style of operation. This grows the number of ops by 2 times.
4131 : Instruction(Type::getVoidTy(Address->getContext()),
4147 /// addDestination - Add a destination.
4159 /// removeDestination - This method removes the specified successor from the
4162 assert(idx < getNumOperands()-1 && "Successor index out of range!");
4168 OL[idx+1] = OL[NumOps-1];
4171 OL[NumOps-1].set(nullptr);
4172 setNumHungOffUseOperands(NumOps-1);
4175 //===----------------------------------------------------------------------===//
4177 //===----------------------------------------------------------------------===//
4180 : UnaryInstruction(S->getType(), Freeze, S, InsertBefore) {
4184 //===----------------------------------------------------------------------===//
4186 //===----------------------------------------------------------------------===//
4222 Result->setUsedWithInAlloca(isUsedWithInAlloca());
4223 Result->setSwiftError(isSwiftError());
4241 Result->setVolatile(isVolatile());
4242 Result->setWeak(isWeak());
4250 Result->setVolatile(isVolatile());