30 : InsertAt(InsertBefore ? InsertBefore->getIterator()
33 : InsertAt(InsertAtEnd ? InsertAtEnd->end() :
InstListType::iterator()) {}
37 :
User(ty,
Value::InstructionVal + it, Ops, NumOps) {
41 assert(BB &&
"Instruction to insert before is not in a basic block!");
118 assert((It == ParentBB->
end() || It->getParent() == ParentBB) &&
119 "It not in ParentBB");
130 BB.getInstList().
insert(InsertPos,
this);
138 bool InsertAtHead = InsertPos.getHeadBit();
141 if (SrcMarker && !SrcMarker->
empty()) {
153 assert(!isa<PHINode>(
this) &&
"Inserting PHI after debug-records!");
162 getParent()->flushTerminatorDbgRecords();
179 NextIt.setHeadBit(
true);
180 moveBeforeImpl(*MovePos->
getParent(), NextIt,
false);
187 NextIt.setHeadBit(
true);
188 moveBeforeImpl(*MovePos->
getParent(), NextIt,
true);
192 moveBeforeImpl(BB,
I,
false);
197 moveBeforeImpl(BB,
I,
true);
200void Instruction::moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
203 bool InsertAtHead =
I.getHeadBit();
224 if (!InsertAtHead && NextMarker && !NextMarker->
empty()) {
230 getParent()->flushTerminatorDbgRecords();
234 const Instruction *
From, std::optional<DbgRecord::self_iterator> FromHere,
236 if (!
From->DebugMarker)
241 From->getParent()->IsNewDbgInfoFormat);
250std::optional<DbgRecord::self_iterator>
269 auto ReleaseTrailingDbgRecords = [BB, It, SrcMarker]() {
270 if (BB->
end() == It) {
277 ReleaseTrailingDbgRecords();
298 ReleaseTrailingDbgRecords();
320 "instructions without BB parents have no order");
322 "cross-BB instruction order comparison");
325 return Order <
Other->Order;
329 assert(!
getType()->isVoidTy() &&
"Instruction must define result");
332 if (
auto *PN = dyn_cast<PHINode>(
this)) {
335 }
else if (
auto *
II = dyn_cast<InvokeInst>(
this)) {
336 InsertBB =
II->getNormalDest();
338 }
else if (isa<CallBrInst>(
this)) {
349 InsertPt.setHeadBit(
true);
354 if (InsertPt == InsertBB->
end())
364 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
365 Inst->setHasNoUnsignedWrap(b);
367 cast<TruncInst>(
this)->setHasNoUnsignedWrap(b);
371 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
372 Inst->setHasNoSignedWrap(b);
374 cast<TruncInst>(
this)->setHasNoSignedWrap(b);
378 cast<PossiblyExactOperator>(
this)->setIsExact(b);
382 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
388 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
389 return Inst->hasNoUnsignedWrap();
391 return cast<TruncInst>(
this)->hasNoUnsignedWrap();
395 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
396 return Inst->hasNoSignedWrap();
398 return cast<TruncInst>(
this)->hasNoSignedWrap();
402 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
407 return cast<Operator>(
this)->hasPoisonGeneratingFlags();
412 case Instruction::Add:
413 case Instruction::Sub:
414 case Instruction::Mul:
415 case Instruction::Shl:
416 cast<OverflowingBinaryOperator>(
this)->setHasNoUnsignedWrap(
false);
417 cast<OverflowingBinaryOperator>(
this)->setHasNoSignedWrap(
false);
420 case Instruction::UDiv:
421 case Instruction::SDiv:
422 case Instruction::AShr:
423 case Instruction::LShr:
424 cast<PossiblyExactOperator>(
this)->setIsExact(
false);
427 case Instruction::Or:
428 cast<PossiblyDisjointInst>(
this)->setIsDisjoint(
false);
431 case Instruction::GetElementPtr:
435 case Instruction::UIToFP:
436 case Instruction::ZExt:
440 case Instruction::Trunc:
441 cast<TruncInst>(
this)->setHasNoUnsignedWrap(
false);
442 cast<TruncInst>(
this)->setHasNoSignedWrap(
false);
446 if (isa<FPMathOperator>(
this)) {
467 if (
const auto *CB = dyn_cast<CallBase>(
this)) {
468 AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
477 if (
auto *CB = dyn_cast<CallBase>(
this)) {
482 CB->removeRetAttrs(AM);
490 auto *CB = dyn_cast<CallBase>(
this);
501 for (
unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
502 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
503 CB->removeRetAttrs(UBImplyingAttributes);
511 unsigned KnownIDs[] = {LLVMContext::MD_annotation, LLVMContext::MD_range,
512 LLVMContext::MD_nonnull, LLVMContext::MD_align};
517 return cast<PossiblyExactOperator>(
this)->isExact();
521 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
522 cast<FPMathOperator>(
this)->setFast(
B);
526 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
527 cast<FPMathOperator>(
this)->setHasAllowReassoc(
B);
531 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
532 cast<FPMathOperator>(
this)->setHasNoNaNs(
B);
536 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
537 cast<FPMathOperator>(
this)->setHasNoInfs(
B);
541 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
542 cast<FPMathOperator>(
this)->setHasNoSignedZeros(
B);
546 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
547 cast<FPMathOperator>(
this)->setHasAllowReciprocal(
B);
551 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
552 cast<FPMathOperator>(
this)->setHasAllowContract(
B);
556 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
557 cast<FPMathOperator>(
this)->setHasApproxFunc(
B);
561 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
562 cast<FPMathOperator>(
this)->setFastMathFlags(FMF);
566 assert(isa<FPMathOperator>(
this) &&
"copying fast-math flag on invalid op");
567 cast<FPMathOperator>(
this)->copyFastMathFlags(FMF);
571 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
572 return cast<FPMathOperator>(
this)->isFast();
576 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
577 return cast<FPMathOperator>(
this)->hasAllowReassoc();
581 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
582 return cast<FPMathOperator>(
this)->hasNoNaNs();
586 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
587 return cast<FPMathOperator>(
this)->hasNoInfs();
591 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
592 return cast<FPMathOperator>(
this)->hasNoSignedZeros();
596 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
597 return cast<FPMathOperator>(
this)->hasAllowReciprocal();
601 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
602 return cast<FPMathOperator>(
this)->hasAllowContract();
606 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
607 return cast<FPMathOperator>(
this)->hasApproxFunc();
611 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
612 return cast<FPMathOperator>(
this)->getFastMathFlags();
621 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(
this)) {
622 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
628 if (
auto *TI = dyn_cast<TruncInst>(V)) {
629 if (isa<TruncInst>(
this)) {
636 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
637 if (isa<PossiblyExactOperator>(
this))
640 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
641 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
642 DestPD->setIsDisjoint(SrcPD->isDisjoint());
645 if (
auto *
FP = dyn_cast<FPMathOperator>(V))
646 if (isa<FPMathOperator>(
this))
649 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
650 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
651 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() |
652 DestGEP->getNoWrapFlags());
654 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
655 if (isa<PossiblyNonNegInst>(
this))
660 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
661 if (isa<OverflowingBinaryOperator>(
this)) {
667 if (
auto *TI = dyn_cast<TruncInst>(V)) {
668 if (isa<TruncInst>(
this)) {
674 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
675 if (isa<PossiblyExactOperator>(
this))
678 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
679 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
680 DestPD->setIsDisjoint(DestPD->isDisjoint() && SrcPD->isDisjoint());
682 if (
auto *
FP = dyn_cast<FPMathOperator>(V)) {
683 if (isa<FPMathOperator>(
this)) {
685 FM &=
FP->getFastMathFlags();
690 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
691 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
692 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() &
693 DestGEP->getNoWrapFlags());
695 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
696 if (isa<PossiblyNonNegInst>(
this))
703 case Ret:
return "ret";
704 case Br:
return "br";
705 case Switch:
return "switch";
706 case IndirectBr:
return "indirectbr";
707 case Invoke:
return "invoke";
708 case Resume:
return "resume";
709 case Unreachable:
return "unreachable";
710 case CleanupRet:
return "cleanupret";
711 case CatchRet:
return "catchret";
712 case CatchPad:
return "catchpad";
713 case CatchSwitch:
return "catchswitch";
714 case CallBr:
return "callbr";
717 case FNeg:
return "fneg";
720 case Add:
return "add";
721 case FAdd:
return "fadd";
722 case Sub:
return "sub";
723 case FSub:
return "fsub";
724 case Mul:
return "mul";
725 case FMul:
return "fmul";
726 case UDiv:
return "udiv";
727 case SDiv:
return "sdiv";
728 case FDiv:
return "fdiv";
729 case URem:
return "urem";
730 case SRem:
return "srem";
731 case FRem:
return "frem";
734 case And:
return "and";
735 case Or :
return "or";
736 case Xor:
return "xor";
739 case Alloca:
return "alloca";
740 case Load:
return "load";
741 case Store:
return "store";
742 case AtomicCmpXchg:
return "cmpxchg";
743 case AtomicRMW:
return "atomicrmw";
744 case Fence:
return "fence";
745 case GetElementPtr:
return "getelementptr";
748 case Trunc:
return "trunc";
749 case ZExt:
return "zext";
750 case SExt:
return "sext";
751 case FPTrunc:
return "fptrunc";
752 case FPExt:
return "fpext";
753 case FPToUI:
return "fptoui";
754 case FPToSI:
return "fptosi";
755 case UIToFP:
return "uitofp";
756 case SIToFP:
return "sitofp";
757 case IntToPtr:
return "inttoptr";
758 case PtrToInt:
return "ptrtoint";
759 case BitCast:
return "bitcast";
760 case AddrSpaceCast:
return "addrspacecast";
763 case ICmp:
return "icmp";
764 case FCmp:
return "fcmp";
765 case PHI:
return "phi";
766 case Select:
return "select";
767 case Call:
return "call";
768 case Shl:
return "shl";
769 case LShr:
return "lshr";
770 case AShr:
return "ashr";
771 case VAArg:
return "va_arg";
772 case ExtractElement:
return "extractelement";
773 case InsertElement:
return "insertelement";
774 case ShuffleVector:
return "shufflevector";
775 case ExtractValue:
return "extractvalue";
776 case InsertValue:
return "insertvalue";
777 case LandingPad:
return "landingpad";
778 case CleanupPad:
return "cleanuppad";
779 case Freeze:
return "freeze";
781 default:
return "<Invalid operator> ";
788 bool IgnoreAlignment)
const {
791 "Can not compare special state of different instructions");
793 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
794 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
795 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
797 if (
const LoadInst *LI = dyn_cast<LoadInst>(I1))
798 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
799 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
801 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
802 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
803 if (
const StoreInst *SI = dyn_cast<StoreInst>(I1))
804 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
805 (SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
807 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
808 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
809 if (
const CmpInst *CI = dyn_cast<CmpInst>(I1))
810 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
811 if (
const CallInst *CI = dyn_cast<CallInst>(I1))
812 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
813 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
814 CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
815 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
816 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
817 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
818 CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
819 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
820 if (
const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
821 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
822 CI->getAttributes() == cast<CallBrInst>(I2)->getAttributes() &&
823 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
825 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
827 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
828 if (
const FenceInst *FI = dyn_cast<FenceInst>(I1))
829 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
830 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
832 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
833 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
834 CXI->getSuccessOrdering() ==
835 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
836 CXI->getFailureOrdering() ==
837 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
838 CXI->getSyncScopeID() ==
839 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
841 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
842 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
843 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
844 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
846 return SVI->getShuffleMask() ==
847 cast<ShuffleVectorInst>(I2)->getShuffleMask();
849 return GEP->getSourceElementType() ==
850 cast<GetElementPtrInst>(I2)->getSourceElementType();
876 if (
const PHINode *thisPHI = dyn_cast<PHINode>(
this)) {
877 const PHINode *otherPHI = cast<PHINode>(
I);
878 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
888 unsigned flags)
const {
895 getType()->getScalarType() !=
I->getType()->getScalarType() :
904 I->getOperand(i)->getType()->getScalarType() :
916 const PHINode *PN = dyn_cast<PHINode>(
I);
918 if (
I->getParent() != BB)
931 default:
return false;
932 case Instruction::VAArg:
933 case Instruction::Load:
934 case Instruction::Fence:
935 case Instruction::AtomicCmpXchg:
936 case Instruction::AtomicRMW:
937 case Instruction::CatchPad:
938 case Instruction::CatchRet:
940 case Instruction::Call:
941 case Instruction::Invoke:
942 case Instruction::CallBr:
943 return !cast<CallBase>(
this)->onlyWritesMemory();
944 case Instruction::Store:
945 return !cast<StoreInst>(
this)->isUnordered();
951 default:
return false;
952 case Instruction::Fence:
953 case Instruction::Store:
954 case Instruction::VAArg:
955 case Instruction::AtomicCmpXchg:
956 case Instruction::AtomicRMW:
957 case Instruction::CatchPad:
958 case Instruction::CatchRet:
960 case Instruction::Call:
961 case Instruction::Invoke:
962 case Instruction::CallBr:
963 return !cast<CallBase>(
this)->onlyReadsMemory();
964 case Instruction::Load:
965 return !cast<LoadInst>(
this)->isUnordered();
973 case Instruction::AtomicCmpXchg:
974 case Instruction::AtomicRMW:
975 case Instruction::Fence:
977 case Instruction::Load:
979 case Instruction::Store:
989 case Instruction::AtomicCmpXchg:
990 case Instruction::AtomicRMW:
991 case Instruction::Load:
1001 case Instruction::AtomicCmpXchg:
1002 case Instruction::AtomicRMW:
1003 case Instruction::Store:
1012 case Instruction::AtomicRMW:
1013 return cast<AtomicRMWInst>(
this)->isVolatile();
1014 case Instruction::Store:
1015 return cast<StoreInst>(
this)->isVolatile();
1016 case Instruction::Load:
1017 return cast<LoadInst>(
this)->isVolatile();
1018 case Instruction::AtomicCmpXchg:
1019 return cast<AtomicCmpXchgInst>(
this)->isVolatile();
1020 case Instruction::Call:
1021 case Instruction::Invoke:
1023 if (
auto *
II = dyn_cast<IntrinsicInst>(
this)) {
1024 if (
auto *
MI = dyn_cast<MemIntrinsic>(
II))
1025 return MI->isVolatile();
1026 switch (
II->getIntrinsicID()) {
1028 case Intrinsic::matrix_column_major_load:
1029 return cast<ConstantInt>(
II->getArgOperand(2))->isOne();
1030 case Intrinsic::matrix_column_major_store:
1031 return cast<ConstantInt>(
II->getArgOperand(3))->isOne();
1040 case Instruction::Store:
1041 return cast<StoreInst>(
this)->getValueOperand()->getType();
1042 case Instruction::Load:
1043 case Instruction::AtomicRMW:
1045 case Instruction::AtomicCmpXchg:
1046 return cast<AtomicCmpXchgInst>(
this)->getNewValOperand()->getType();
1047 case Instruction::Call:
1048 case Instruction::Invoke:
1050 switch (
II->getIntrinsicID()) {
1051 case Intrinsic::masked_load:
1052 case Intrinsic::masked_gather:
1053 case Intrinsic::masked_expandload:
1054 case Intrinsic::vp_load:
1055 case Intrinsic::vp_gather:
1056 case Intrinsic::experimental_vp_strided_load:
1057 return II->getType();
1058 case Intrinsic::masked_store:
1059 case Intrinsic::masked_scatter:
1060 case Intrinsic::masked_compressstore:
1061 case Intrinsic::vp_store:
1062 case Intrinsic::vp_scatter:
1063 case Intrinsic::experimental_vp_strided_store:
1064 return II->getOperand(0)->getType();
1075 bool IncludePhaseOneUnwind) {
1079 return IncludePhaseOneUnwind;
1098 case Instruction::Call:
1099 return !cast<CallInst>(
this)->doesNotThrow();
1100 case Instruction::CleanupRet:
1101 return cast<CleanupReturnInst>(
this)->unwindsToCaller();
1102 case Instruction::CatchSwitch:
1103 return cast<CatchSwitchInst>(
this)->unwindsToCaller();
1104 case Instruction::Resume:
1106 case Instruction::Invoke: {
1109 BasicBlock *UnwindDest = cast<InvokeInst>(
this)->getUnwindDest();
1111 if (
auto *LP = dyn_cast<LandingPadInst>(Pad))
1115 case Instruction::CleanupPad:
1117 return IncludePhaseOneUnwind;
1134 if (
auto *SI = dyn_cast<StoreInst>(
this))
1135 return !SI->isVolatile();
1137 if (
const auto *CB = dyn_cast<CallBase>(
this))
1138 return CB->hasFnAttr(Attribute::WillReturn);
1143 auto *
II = dyn_cast<IntrinsicInst>(
this);
1147 return ID == Intrinsic::lifetime_start ||
ID == Intrinsic::lifetime_end;
1151 auto *
II = dyn_cast<IntrinsicInst>(
this);
1155 return ID == Intrinsic::launder_invariant_group ||
1156 ID == Intrinsic::strip_invariant_group;
1160 return isa<DbgInfoIntrinsic>(
this) || isa<PseudoProbeInst>(
this);
1166 if (!isa<DbgInfoIntrinsic>(
I) && !(SkipPseudoOp && isa<PseudoProbeInst>(
I)))
1174 if (!isa<DbgInfoIntrinsic>(
I) && !(SkipPseudoOp && isa<PseudoProbeInst>(
I)))
1180 if (isa<DbgInfoIntrinsic>(
this))
1182 return Next->getDebugLoc();
1187 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1188 return II->isAssociative();
1196 return cast<FPMathOperator>(
this)->hasAllowReassoc() &&
1197 cast<FPMathOperator>(
this)->hasNoSignedZeros();
1204 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1205 return II->isCommutative();
1212#define HANDLE_TERM_INST(N, OPC, CLASS) \
1213 case Instruction::OPC: \
1214 return static_cast<const CLASS *>(this)->getNumSuccessors();
1215#include "llvm/IR/Instruction.def"
1224#define HANDLE_TERM_INST(N, OPC, CLASS) \
1225 case Instruction::OPC: \
1226 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1227#include "llvm/IR/Instruction.def"
1236#define HANDLE_TERM_INST(N, OPC, CLASS) \
1237 case Instruction::OPC: \
1238 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1239#include "llvm/IR/Instruction.def"
1248 Idx != NumSuccessors; ++
Idx)
1265 unsigned SecondIdx = FirstIdx + 1;
1270 for (
unsigned Idx = 0;
Idx < FirstIdx; ++
Idx) {
1291 for (
const auto &MD : TheMDs) {
1292 if (WL.
empty() || WLS.count(MD.first))
1295 if (WL.
empty() || WLS.count(LLVMContext::MD_dbg))
1304#define HANDLE_INST(num, opc, clas) \
1305 case Instruction::opc: \
1306 New = cast<clas>(this)->cloneImpl(); \
1308#include "llvm/IR/Instruction.def"
1313 New->copyMetadata(*
this);
amdgpu AMDGPU Register Bank Select
This file contains the simple types necessary to represent the attributes associated with functions a...
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseSet and SmallDenseSet classes.
static bool canUnwindPastLandingPad(const LandingPadInst *LP, bool IncludePhaseOneUnwind)
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
Module.h This file contains the declarations for the Module class.
uint64_t IntrinsicInst * II
llvm::cl::opt< bool > UseNewDbgInfoFormat
This file contains the declarations for profiling metadata utility functions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
an instruction to allocate memory on the stack
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
AttributeMask & addAttribute(Attribute::AttrKind Val)
Add an attribute to the mask.
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
LLVM Basic Block Representation.
void deleteTrailingDbgRecords()
Delete any trailing DbgRecords at the end of this block, see setTrailingDbgRecords.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const Function * getParent() const
Return the enclosing method, or null if none.
DbgMarker * getMarker(InstListType::iterator It)
Return the DbgMarker for the position given by It, so that DbgRecords can be inserted there.
InstListType::iterator iterator
Instruction iterators...
bool IsNewDbgInfoFormat
Flag recording whether or not this block stores debug-info in the form of intrinsic instructions (fal...
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
This class is the base class for the comparison instructions.
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
Per-instruction record of debug-info.
static iterator_range< simple_ilist< DbgRecord >::iterator > getEmptyDbgRecordRange()
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(DbgMarker *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere, bool InsertAtHead=false)
Clone all DbgMarkers from From into this marker.
void removeMarker()
Handle the removal of a marker: the position of debug-info has gone away, but the stored debug record...
void absorbDebugValues(DbgMarker &Src, bool InsertAtHead)
Transfer any DbgRecords from Src into this DbgMarker.
void dropDbgRecords()
Erase all DbgRecords in this DbgMarker.
void dropOneDbgRecord(DbgRecord *DR)
Erase a single DbgRecord from this marker.
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
Base class for non-instruction debug metadata records that have positions within IR.
Convenience struct for specifying and reasoning about fast-math flags.
An instruction for ordering other memory operations.
static GEPNoWrapFlags none()
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
InsertPosition(std::nullptr_t)
This instruction inserts a struct field of array element value into an aggregate value.
const DebugLoc & getStableDebugLoc() const
Fetch the debug location for this node, unless this is a debug intrinsic, in which case fetch the deb...
DbgMarker * DebugMarker
Optional marker recording the position for debugging information that takes effect immediately before...
bool mayThrow(bool IncludePhaseOneUnwind=false) const LLVM_READONLY
Return true if this instruction may throw an exception.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
bool hasNoNaNs() const LLVM_READONLY
Determine whether the no-NaNs flag is set.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
bool hasNoInfs() const LLVM_READONLY
Determine whether the no-infs flag is set.
bool isLifetimeStartOrEnd() const LLVM_READONLY
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const LLVM_READONLY
This function determines if the specified instruction executes the same operation as the current one.
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
void moveBeforePreserving(Instruction *MovePos)
Perform a moveBefore operation, while signalling that the caller intends to preserve the original ord...
bool hasNoSignedZeros() const LLVM_READONLY
Determine whether the no-signed-zeros flag is set.
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(const Instruction *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere=std::nullopt, bool InsertAtHead=false)
Clone any debug-info attached to From onto this instruction.
bool hasPoisonGeneratingReturnAttributes() const LLVM_READONLY
Return true if this instruction has poison-generating attribute.
bool isDebugOrPseudoInst() const LLVM_READONLY
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
bool hasNoSignedWrap() const LLVM_READONLY
Determine whether the no signed wrap flag is set.
bool mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
bool hasAtomicStore() const LLVM_READONLY
Return true if this atomic instruction stores to memory.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
bool isOnlyUserOfAnyOperand()
It checks if this instruction is the only user of at least one of its operands.
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange() const
Return a range over the DbgRecords attached to this instruction.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
const Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the previous non-debug instruction in the same basic block as 'this',...
void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
void dropPoisonGeneratingReturnAttributes()
Drops return attributes that may generate poison.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
bool isFast() const LLVM_READONLY
Determine whether all fast-math-flags are set.
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
bool isExact() const LLVM_READONLY
Determine whether the exact flag is set.
bool isIdenticalToWhenDefined(const Instruction *I) const LLVM_READONLY
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
const Function * getFunction() const
Return the function this instruction belongs to.
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
void dropOneDbgRecord(DbgRecord *I)
Erase a single DbgRecord I that is attached to this instruction.
void setNonNeg(bool b=true)
Set or clear the nneg flag on this instruction, which must be a zext instruction.
bool isTerminator() const
Type * getAccessType() const LLVM_READONLY
Return the type this instruction accesses in memory, if any.
bool hasSameSpecialState(const Instruction *I2, bool IgnoreAlignment=false) const LLVM_READONLY
This function determines if the speficied instruction has the same "special" characteristics as the c...
bool hasAllowReciprocal() const LLVM_READONLY
Determine whether the allow-reciprocal flag is set.
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
void dropUBImplyingAttrsAndMetadata()
Drop any attributes or metadata that can cause immediate undefined behavior.
void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs=std::nullopt)
Drop all unknown metadata except for debug locations.
bool hasNonNeg() const LLVM_READONLY
Determine whether the the nneg flag is set.
bool hasPoisonGeneratingFlags() const LLVM_READONLY
Return true if this operator has flags which may cause this instruction to evaluate to poison despite...
bool mayReadFromMemory() const LLVM_READONLY
Return true if this instruction may read memory.
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
bool isUsedOutsideOfBlock(const BasicBlock *BB) const LLVM_READONLY
Return true if there are any uses of this instruction in blocks other than the specified block.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool isVolatile() const LLVM_READONLY
Return true if this instruction has a volatile memory access.
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
void adoptDbgRecords(BasicBlock *BB, InstListType::iterator It, bool InsertAtHead)
Transfer any DbgRecords on the position It onto this instruction, by simply adopting the sequence of ...
FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const char * getOpcodeName() const
bool willReturn() const LLVM_READONLY
Return true if the instruction will return (unwinding is considered as a form of returning control fl...
bool hasApproxFunc() const LLVM_READONLY
Determine whether the approximate-math-functions flag is set.
@ CompareIgnoringAlignment
Check for equivalence ignoring load/store alignment.
@ CompareUsingScalarTypes
Check for equivalence treating a type and a vector of that type as equivalent.
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
void moveAfterPreserving(Instruction *MovePos)
See moveBeforePreserving .
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool hasAtomicLoad() const LLVM_READONLY
Return true if this atomic instruction loads from memory.
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
void dropPoisonGeneratingMetadata()
Drops metadata that may generate poison.
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
void handleMarkerRemoval()
Handle the debug-info implications of this instruction being removed.
std::optional< InstListType::iterator > getInsertionPointAfterDef()
Get the first insertion point at which the result of this instruction is defined.
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
void dropUBImplyingAttrsAndUnknownMetadata(ArrayRef< unsigned > KnownIDs={})
This function drops non-debug unknown metadata (through dropUnknownNonDebugMetadata).
bool isIdenticalTo(const Instruction *I) const LLVM_READONLY
Return true if the specified instruction is exactly identical to the current one.
std::optional< simple_ilist< DbgRecord >::iterator > getDbgReinsertionPosition()
Return an iterator to the position of the "Next" DbgRecord after this instruction,...
bool isLaunderOrStripInvariantGroup() const LLVM_READONLY
Return true if the instruction is a llvm.launder.invariant.group or llvm.strip.invariant....
bool hasAllowContract() const LLVM_READONLY
Determine whether the allow-contract flag is set.
bool hasPoisonGeneratingMetadata() const LLVM_READONLY
Return true if this instruction has poison-generating metadata.
Instruction(const Instruction &)=delete
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
bool hasAllowReassoc() const LLVM_READONLY
Determine whether the allow-reassociation flag is set.
void dropDbgRecords()
Erase any DbgRecords attached to this instruction.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isSafeToRemove() const LLVM_READONLY
Return true if the instruction can be removed if the result is unused.
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
bool hasDbgRecords() const
Returns true if any DbgRecords are attached to this instruction.
A wrapper class for inspecting calls to intrinsic functions.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
An instruction for reading from memory.
const MDOperand & getOperand(unsigned I) const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
LLVMContext & getContext() const
A Module instance is used to store all the information related to an LLVM module.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
const_block_iterator block_begin() const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Instruction that can have a nneg flag (zext/uitofp).
This instruction constructs a fixed permutation of two input vectors.
Implements a dense probed hash-table based set with some number of buckets stored inline.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
The instances of the Type class are immutable: once they are created, they are never changed.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
iterator_range< use_iterator > uses()
const ParentTy * getParent() const
self_iterator getIterator()
Instruction * getPrevNode()
Instruction * getNextNode()
Get the next node, or nullptr for the list tail.
void splice(iterator where, iplist_impl &L2)
base_list_type::iterator iterator
iterator insertAfter(iterator where, pointer New)
iterator insert(iterator where, pointer New)
A range adaptor for a pair of iterators.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
AttributeMask getUBImplyingAttributes()
Get param/return attributes which imply immediate undefined behavior if an invalid value is passed.
This is an optimization pass for GlobalISel generic memory operations.
unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
MDNode * getBranchWeightMDNode(const Instruction &I)
Get the branch weights metadata node.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND of integers.