30 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
34 assert(BB &&
"Instruction to insert before is not in a basic block!");
40 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
45 assert(BB &&
"Instruction to insert before is not in a basic block!");
52 :
User(ty,
Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
60 assert(!Parent &&
"Instruction still linked in the program!");
131 assert((It == ParentBB->
end() || It->getParent() == ParentBB) &&
132 "It not in ParentBB");
143 BB.getInstList().
insert(InsertPos,
this);
151 bool InsertAtHead = InsertPos.getHeadBit();
154 if (SrcMarker && !SrcMarker->
empty()) {
166 assert(!isa<PHINode>(
this) &&
"Inserting PHI after debug-records!");
192 NextIt.setHeadBit(
true);
193 moveBeforeImpl(*MovePos->
getParent(), NextIt,
false);
200 NextIt.setHeadBit(
true);
201 moveBeforeImpl(*MovePos->
getParent(), NextIt,
true);
205 moveBeforeImpl(BB,
I,
false);
210 moveBeforeImpl(BB,
I,
true);
213void Instruction::moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
216 bool InsertAtHead =
I.getHeadBit();
237 if (!InsertAtHead && NextMarker && !NextMarker->
empty()) {
247 const Instruction *
From, std::optional<DbgRecord::self_iterator> FromHere,
249 if (!
From->DebugMarker)
254 From->getParent()->IsNewDbgInfoFormat);
263std::optional<DbgRecord::self_iterator>
282 auto ReleaseTrailingDbgRecords = [BB, It, SrcMarker]() {
283 if (BB->
end() == It) {
290 ReleaseTrailingDbgRecords();
311 ReleaseTrailingDbgRecords();
333 "instructions without BB parents have no order");
334 assert(Parent ==
Other->Parent &&
"cross-BB instruction order comparison");
337 return Order <
Other->Order;
341 assert(!
getType()->isVoidTy() &&
"Instruction must define result");
344 if (
auto *PN = dyn_cast<PHINode>(
this)) {
347 }
else if (
auto *II = dyn_cast<InvokeInst>(
this)) {
348 InsertBB = II->getNormalDest();
350 }
else if (isa<CallBrInst>(
this)) {
361 InsertPt.setHeadBit(
true);
366 if (InsertPt == InsertBB->
end())
376 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
377 Inst->setHasNoUnsignedWrap(b);
379 cast<TruncInst>(
this)->setHasNoUnsignedWrap(b);
383 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
384 Inst->setHasNoSignedWrap(b);
386 cast<TruncInst>(
this)->setHasNoSignedWrap(b);
390 cast<PossiblyExactOperator>(
this)->setIsExact(b);
394 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
400 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
401 return Inst->hasNoUnsignedWrap();
403 return cast<TruncInst>(
this)->hasNoUnsignedWrap();
407 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
408 return Inst->hasNoSignedWrap();
410 return cast<TruncInst>(
this)->hasNoSignedWrap();
414 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
419 return cast<Operator>(
this)->hasPoisonGeneratingFlags();
424 case Instruction::Add:
425 case Instruction::Sub:
426 case Instruction::Mul:
427 case Instruction::Shl:
428 cast<OverflowingBinaryOperator>(
this)->setHasNoUnsignedWrap(
false);
429 cast<OverflowingBinaryOperator>(
this)->setHasNoSignedWrap(
false);
432 case Instruction::UDiv:
433 case Instruction::SDiv:
434 case Instruction::AShr:
435 case Instruction::LShr:
436 cast<PossiblyExactOperator>(
this)->setIsExact(
false);
439 case Instruction::Or:
440 cast<PossiblyDisjointInst>(
this)->setIsDisjoint(
false);
443 case Instruction::GetElementPtr:
444 cast<GetElementPtrInst>(
this)->setIsInBounds(
false);
447 case Instruction::UIToFP:
448 case Instruction::ZExt:
452 case Instruction::Trunc:
453 cast<TruncInst>(
this)->setHasNoUnsignedWrap(
false);
454 cast<TruncInst>(
this)->setHasNoSignedWrap(
false);
458 if (isa<FPMathOperator>(
this)) {
479 if (
const auto *CB = dyn_cast<CallBase>(
this)) {
480 AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
489 if (
auto *CB = dyn_cast<CallBase>(
this)) {
494 CB->removeRetAttrs(AM);
502 auto *CB = dyn_cast<CallBase>(
this);
513 for (
unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
514 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
515 CB->removeRetAttrs(UBImplyingAttributes);
523 unsigned KnownIDs[] = {LLVMContext::MD_annotation, LLVMContext::MD_range,
524 LLVMContext::MD_nonnull, LLVMContext::MD_align};
529 return cast<PossiblyExactOperator>(
this)->isExact();
533 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
534 cast<FPMathOperator>(
this)->setFast(
B);
538 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
539 cast<FPMathOperator>(
this)->setHasAllowReassoc(
B);
543 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
544 cast<FPMathOperator>(
this)->setHasNoNaNs(
B);
548 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
549 cast<FPMathOperator>(
this)->setHasNoInfs(
B);
553 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
554 cast<FPMathOperator>(
this)->setHasNoSignedZeros(
B);
558 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
559 cast<FPMathOperator>(
this)->setHasAllowReciprocal(
B);
563 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
564 cast<FPMathOperator>(
this)->setHasAllowContract(
B);
568 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
569 cast<FPMathOperator>(
this)->setHasApproxFunc(
B);
573 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
574 cast<FPMathOperator>(
this)->setFastMathFlags(FMF);
578 assert(isa<FPMathOperator>(
this) &&
"copying fast-math flag on invalid op");
579 cast<FPMathOperator>(
this)->copyFastMathFlags(FMF);
583 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
584 return cast<FPMathOperator>(
this)->isFast();
588 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
589 return cast<FPMathOperator>(
this)->hasAllowReassoc();
593 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
594 return cast<FPMathOperator>(
this)->hasNoNaNs();
598 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
599 return cast<FPMathOperator>(
this)->hasNoInfs();
603 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
604 return cast<FPMathOperator>(
this)->hasNoSignedZeros();
608 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
609 return cast<FPMathOperator>(
this)->hasAllowReciprocal();
613 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
614 return cast<FPMathOperator>(
this)->hasAllowContract();
618 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
619 return cast<FPMathOperator>(
this)->hasApproxFunc();
623 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
624 return cast<FPMathOperator>(
this)->getFastMathFlags();
633 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(
this)) {
634 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
640 if (
auto *TI = dyn_cast<TruncInst>(V)) {
641 if (isa<TruncInst>(
this)) {
648 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
649 if (isa<PossiblyExactOperator>(
this))
652 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
653 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
654 DestPD->setIsDisjoint(SrcPD->isDisjoint());
657 if (
auto *
FP = dyn_cast<FPMathOperator>(V))
658 if (isa<FPMathOperator>(
this))
661 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
662 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
663 DestGEP->setIsInBounds(SrcGEP->isInBounds() || DestGEP->isInBounds());
665 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
666 if (isa<PossiblyNonNegInst>(
this))
671 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
672 if (isa<OverflowingBinaryOperator>(
this)) {
678 if (
auto *TI = dyn_cast<TruncInst>(V)) {
679 if (isa<TruncInst>(
this)) {
685 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
686 if (isa<PossiblyExactOperator>(
this))
689 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
690 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
691 DestPD->setIsDisjoint(DestPD->isDisjoint() && SrcPD->isDisjoint());
693 if (
auto *
FP = dyn_cast<FPMathOperator>(V)) {
694 if (isa<FPMathOperator>(
this)) {
696 FM &=
FP->getFastMathFlags();
701 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
702 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
703 DestGEP->setIsInBounds(SrcGEP->isInBounds() && DestGEP->isInBounds());
705 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
706 if (isa<PossiblyNonNegInst>(
this))
713 case Ret:
return "ret";
714 case Br:
return "br";
715 case Switch:
return "switch";
716 case IndirectBr:
return "indirectbr";
717 case Invoke:
return "invoke";
718 case Resume:
return "resume";
719 case Unreachable:
return "unreachable";
720 case CleanupRet:
return "cleanupret";
721 case CatchRet:
return "catchret";
722 case CatchPad:
return "catchpad";
723 case CatchSwitch:
return "catchswitch";
724 case CallBr:
return "callbr";
727 case FNeg:
return "fneg";
730 case Add:
return "add";
731 case FAdd:
return "fadd";
732 case Sub:
return "sub";
733 case FSub:
return "fsub";
734 case Mul:
return "mul";
735 case FMul:
return "fmul";
736 case UDiv:
return "udiv";
737 case SDiv:
return "sdiv";
738 case FDiv:
return "fdiv";
739 case URem:
return "urem";
740 case SRem:
return "srem";
741 case FRem:
return "frem";
744 case And:
return "and";
745 case Or :
return "or";
746 case Xor:
return "xor";
749 case Alloca:
return "alloca";
750 case Load:
return "load";
751 case Store:
return "store";
752 case AtomicCmpXchg:
return "cmpxchg";
753 case AtomicRMW:
return "atomicrmw";
754 case Fence:
return "fence";
755 case GetElementPtr:
return "getelementptr";
758 case Trunc:
return "trunc";
759 case ZExt:
return "zext";
760 case SExt:
return "sext";
761 case FPTrunc:
return "fptrunc";
762 case FPExt:
return "fpext";
763 case FPToUI:
return "fptoui";
764 case FPToSI:
return "fptosi";
765 case UIToFP:
return "uitofp";
766 case SIToFP:
return "sitofp";
767 case IntToPtr:
return "inttoptr";
768 case PtrToInt:
return "ptrtoint";
769 case BitCast:
return "bitcast";
770 case AddrSpaceCast:
return "addrspacecast";
773 case ICmp:
return "icmp";
774 case FCmp:
return "fcmp";
775 case PHI:
return "phi";
776 case Select:
return "select";
777 case Call:
return "call";
778 case Shl:
return "shl";
779 case LShr:
return "lshr";
780 case AShr:
return "ashr";
781 case VAArg:
return "va_arg";
782 case ExtractElement:
return "extractelement";
783 case InsertElement:
return "insertelement";
784 case ShuffleVector:
return "shufflevector";
785 case ExtractValue:
return "extractvalue";
786 case InsertValue:
return "insertvalue";
787 case LandingPad:
return "landingpad";
788 case CleanupPad:
return "cleanuppad";
789 case Freeze:
return "freeze";
791 default:
return "<Invalid operator> ";
798 bool IgnoreAlignment)
const {
801 "Can not compare special state of different instructions");
803 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
804 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
805 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
807 if (
const LoadInst *LI = dyn_cast<LoadInst>(I1))
808 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
809 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
811 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
812 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
813 if (
const StoreInst *SI = dyn_cast<StoreInst>(I1))
814 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
815 (SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
817 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
818 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
819 if (
const CmpInst *CI = dyn_cast<CmpInst>(I1))
820 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
821 if (
const CallInst *CI = dyn_cast<CallInst>(I1))
822 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
823 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
824 CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
825 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
826 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
827 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
828 CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
829 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
830 if (
const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
831 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
832 CI->getAttributes() == cast<CallBrInst>(I2)->getAttributes() &&
833 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
835 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
837 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
838 if (
const FenceInst *FI = dyn_cast<FenceInst>(I1))
839 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
840 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
842 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
843 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
844 CXI->getSuccessOrdering() ==
845 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
846 CXI->getFailureOrdering() ==
847 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
848 CXI->getSyncScopeID() ==
849 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
851 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
852 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
853 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
854 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
856 return SVI->getShuffleMask() ==
857 cast<ShuffleVectorInst>(I2)->getShuffleMask();
859 return GEP->getSourceElementType() ==
860 cast<GetElementPtrInst>(I2)->getSourceElementType();
886 if (
const PHINode *thisPHI = dyn_cast<PHINode>(
this)) {
887 const PHINode *otherPHI = cast<PHINode>(
I);
888 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
898 unsigned flags)
const {
905 getType()->getScalarType() !=
I->getType()->getScalarType() :
914 I->getOperand(i)->getType()->getScalarType() :
926 const PHINode *PN = dyn_cast<PHINode>(
I);
928 if (
I->getParent() != BB)
941 default:
return false;
942 case Instruction::VAArg:
943 case Instruction::Load:
944 case Instruction::Fence:
945 case Instruction::AtomicCmpXchg:
946 case Instruction::AtomicRMW:
947 case Instruction::CatchPad:
948 case Instruction::CatchRet:
950 case Instruction::Call:
951 case Instruction::Invoke:
952 case Instruction::CallBr:
953 return !cast<CallBase>(
this)->onlyWritesMemory();
954 case Instruction::Store:
955 return !cast<StoreInst>(
this)->isUnordered();
961 default:
return false;
962 case Instruction::Fence:
963 case Instruction::Store:
964 case Instruction::VAArg:
965 case Instruction::AtomicCmpXchg:
966 case Instruction::AtomicRMW:
967 case Instruction::CatchPad:
968 case Instruction::CatchRet:
970 case Instruction::Call:
971 case Instruction::Invoke:
972 case Instruction::CallBr:
973 return !cast<CallBase>(
this)->onlyReadsMemory();
974 case Instruction::Load:
975 return !cast<LoadInst>(
this)->isUnordered();
983 case Instruction::AtomicCmpXchg:
984 case Instruction::AtomicRMW:
985 case Instruction::Fence:
987 case Instruction::Load:
989 case Instruction::Store:
999 case Instruction::AtomicCmpXchg:
1000 case Instruction::AtomicRMW:
1001 case Instruction::Load:
1011 case Instruction::AtomicCmpXchg:
1012 case Instruction::AtomicRMW:
1013 case Instruction::Store:
1022 case Instruction::AtomicRMW:
1023 return cast<AtomicRMWInst>(
this)->isVolatile();
1024 case Instruction::Store:
1025 return cast<StoreInst>(
this)->isVolatile();
1026 case Instruction::Load:
1027 return cast<LoadInst>(
this)->isVolatile();
1028 case Instruction::AtomicCmpXchg:
1029 return cast<AtomicCmpXchgInst>(
this)->isVolatile();
1030 case Instruction::Call:
1031 case Instruction::Invoke:
1033 if (
auto *II = dyn_cast<IntrinsicInst>(
this)) {
1034 if (
auto *
MI = dyn_cast<MemIntrinsic>(II))
1035 return MI->isVolatile();
1036 switch (II->getIntrinsicID()) {
1038 case Intrinsic::matrix_column_major_load:
1039 return cast<ConstantInt>(II->getArgOperand(2))->isOne();
1040 case Intrinsic::matrix_column_major_store:
1041 return cast<ConstantInt>(II->getArgOperand(3))->isOne();
1050 case Instruction::Store:
1051 return cast<StoreInst>(
this)->getValueOperand()->getType();
1052 case Instruction::Load:
1053 case Instruction::AtomicRMW:
1055 case Instruction::AtomicCmpXchg:
1056 return cast<AtomicCmpXchgInst>(
this)->getNewValOperand()->getType();
1057 case Instruction::Call:
1058 case Instruction::Invoke:
1059 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(
this)) {
1060 switch (II->getIntrinsicID()) {
1061 case Intrinsic::masked_load:
1062 case Intrinsic::masked_gather:
1063 case Intrinsic::masked_expandload:
1064 case Intrinsic::vp_load:
1065 case Intrinsic::vp_gather:
1066 case Intrinsic::experimental_vp_strided_load:
1067 return II->getType();
1068 case Intrinsic::masked_store:
1069 case Intrinsic::masked_scatter:
1070 case Intrinsic::masked_compressstore:
1071 case Intrinsic::vp_store:
1072 case Intrinsic::vp_scatter:
1073 case Intrinsic::experimental_vp_strided_store:
1074 return II->getOperand(0)->getType();
1085 bool IncludePhaseOneUnwind) {
1089 return IncludePhaseOneUnwind;
1108 case Instruction::Call:
1109 return !cast<CallInst>(
this)->doesNotThrow();
1110 case Instruction::CleanupRet:
1111 return cast<CleanupReturnInst>(
this)->unwindsToCaller();
1112 case Instruction::CatchSwitch:
1113 return cast<CatchSwitchInst>(
this)->unwindsToCaller();
1114 case Instruction::Resume:
1116 case Instruction::Invoke: {
1119 BasicBlock *UnwindDest = cast<InvokeInst>(
this)->getUnwindDest();
1121 if (
auto *LP = dyn_cast<LandingPadInst>(Pad))
1125 case Instruction::CleanupPad:
1127 return IncludePhaseOneUnwind;
1144 if (
auto *SI = dyn_cast<StoreInst>(
this))
1145 return !SI->isVolatile();
1147 if (
const auto *CB = dyn_cast<CallBase>(
this))
1148 return CB->hasFnAttr(Attribute::WillReturn);
1153 auto *II = dyn_cast<IntrinsicInst>(
this);
1157 return ID == Intrinsic::lifetime_start ||
ID == Intrinsic::lifetime_end;
1161 auto *II = dyn_cast<IntrinsicInst>(
this);
1165 return ID == Intrinsic::launder_invariant_group ||
1166 ID == Intrinsic::strip_invariant_group;
1170 return isa<DbgInfoIntrinsic>(
this) || isa<PseudoProbeInst>(
this);
1176 if (!isa<DbgInfoIntrinsic>(
I) && !(SkipPseudoOp && isa<PseudoProbeInst>(
I)))
1184 if (!isa<DbgInfoIntrinsic>(
I) && !(SkipPseudoOp && isa<PseudoProbeInst>(
I)))
1190 if (isa<DbgInfoIntrinsic>(
this))
1192 return Next->getDebugLoc();
1197 if (
auto *II = dyn_cast<IntrinsicInst>(
this))
1198 return II->isAssociative();
1206 return cast<FPMathOperator>(
this)->hasAllowReassoc() &&
1207 cast<FPMathOperator>(
this)->hasNoSignedZeros();
1214 if (
auto *II = dyn_cast<IntrinsicInst>(
this))
1215 return II->isCommutative();
1222#define HANDLE_TERM_INST(N, OPC, CLASS) \
1223 case Instruction::OPC: \
1224 return static_cast<const CLASS *>(this)->getNumSuccessors();
1225#include "llvm/IR/Instruction.def"
1234#define HANDLE_TERM_INST(N, OPC, CLASS) \
1235 case Instruction::OPC: \
1236 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1237#include "llvm/IR/Instruction.def"
1246#define HANDLE_TERM_INST(N, OPC, CLASS) \
1247 case Instruction::OPC: \
1248 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1249#include "llvm/IR/Instruction.def"
1258 Idx != NumSuccessors; ++
Idx)
1290 for (
const auto &MD : TheMDs) {
1291 if (WL.
empty() || WLS.count(MD.first))
1294 if (WL.
empty() || WLS.count(LLVMContext::MD_dbg))
1303#define HANDLE_INST(num, opc, clas) \
1304 case Instruction::opc: \
1305 New = cast<clas>(this)->cloneImpl(); \
1307#include "llvm/IR/Instruction.def"
1312 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).
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...
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
DbgMarker * createMarker(Instruction *I)
Attach a DbgMarker to the given instruction.
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
void flushTerminatorDbgRecords()
Eject any debug-info trailing at the end of a block.
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...
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
DbgMarker * getNextMarker(Instruction *I)
Return the DbgMarker for the position that comes after I.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
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.
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.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
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.
const BasicBlock * getParent() const
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.
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 dropUnknownNonDebugMetadata()
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.
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_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.
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()
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 erase(iterator where)
pointer remove(iterator &IT)
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.
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.