31InsertPosition::InsertPosition(
Instruction *InsertBefore)
32 : InsertAt(InsertBefore ? InsertBefore->getIterator()
33 : InstListType::iterator()) {}
34InsertPosition::InsertPosition(
BasicBlock *InsertAtEnd)
35 : InsertAt(InsertAtEnd ? InsertAtEnd->
end() : InstListType::iterator()) {}
41 if (InstListType::iterator InsertIt = InsertBefore; InsertIt.isValid()) {
43 assert(BB &&
"Instruction to insert before is not in a basic block!");
44 insertInto(BB, InsertBefore);
48Instruction::~Instruction() {
60 if (isUsedByMetadata())
61 ValueAsMetadata::handleRAUW(
this, UndefValue::get(
getType()));
65 setMetadata(LLVMContext::MD_DIAssignID,
nullptr);
68const Module *Instruction::getModule()
const {
72const Function *Instruction::getFunction()
const {
76const DataLayout &Instruction::getDataLayout()
const {
77 return getModule()->getDataLayout();
80void Instruction::removeFromParent() {
82 handleMarkerRemoval();
84 getParent()->getInstList().remove(getIterator());
87void Instruction::handleMarkerRemoval() {
88 if (!
getParent()->IsNewDbgInfoFormat || !DebugMarker)
91 DebugMarker->removeMarker();
95 handleMarkerRemoval();
96 return getParent()->getInstList().erase(getIterator());
99void Instruction::insertBefore(
Instruction *InsertPos) {
106 insertBefore(*InsertPos->getParent(), InsertPos);
111void Instruction::insertAfter(
Instruction *InsertPos) {
120 assert((It == ParentBB->
end() || It->getParent() == ParentBB) &&
121 "It not in ParentBB");
122 insertBefore(*ParentBB, It);
123 return getIterator();
129 InstListType::iterator InsertPos) {
132 BB.getInstList().
insert(InsertPos,
this);
140 bool InsertAtHead = InsertPos.getHeadBit();
143 if (SrcMarker && !SrcMarker->
empty()) {
155 assert(!isa<PHINode>(
this) &&
"Inserting PHI after debug-records!");
156 adoptDbgRecords(&BB, InsertPos,
false);
164 getParent()->flushTerminatorDbgRecords();
169void Instruction::moveBefore(
Instruction *MovePos) {
173void Instruction::moveBeforePreserving(
Instruction *MovePos) {
181 NextIt.setHeadBit(
true);
182 moveBeforeImpl(*MovePos->
getParent(), NextIt,
false);
185void Instruction::moveAfterPreserving(
Instruction *MovePos) {
189 NextIt.setHeadBit(
true);
190 moveBeforeImpl(*MovePos->
getParent(), NextIt,
true);
193void Instruction::moveBefore(
BasicBlock &BB, InstListType::iterator
I) {
194 moveBeforeImpl(BB,
I,
false);
197void Instruction::moveBeforePreserving(
BasicBlock &BB,
198 InstListType::iterator
I) {
199 moveBeforeImpl(BB,
I,
true);
202void Instruction::moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
205 bool InsertAtHead =
I.getHeadBit();
210 if (
I != this->getIterator() || InsertAtHead) {
213 handleMarkerRemoval();
226 if (!InsertAtHead && NextMarker && !NextMarker->
empty()) {
227 adoptDbgRecords(&BB,
I,
false);
232 getParent()->flushTerminatorDbgRecords();
236 const Instruction *
From, std::optional<DbgRecord::self_iterator> FromHere,
238 if (!
From->DebugMarker)
239 return DbgMarker::getEmptyDbgRecordRange();
243 From->getParent()->IsNewDbgInfoFormat);
248 return DebugMarker->cloneDebugInfoFrom(
From->DebugMarker, FromHere,
252std::optional<DbgRecord::self_iterator>
253Instruction::getDbgReinsertionPosition() {
271 auto ReleaseTrailingDbgRecords = [BB, It, SrcMarker]() {
272 if (BB->
end() == It) {
279 ReleaseTrailingDbgRecords();
286 if (DebugMarker || It == BB->
end()) {
289 DebugMarker->absorbDebugValues(*SrcMarker, InsertAtHead);
300 ReleaseTrailingDbgRecords();
305 DebugMarker = SrcMarker;
311void Instruction::dropDbgRecords() {
316void Instruction::dropOneDbgRecord(
DbgRecord *DVR) {
317 DebugMarker->dropOneDbgRecord(DVR);
322 "instructions without BB parents have no order");
324 "cross-BB instruction order comparison");
327 return Order <
Other->Order;
330std::optional<BasicBlock::iterator> Instruction::getInsertionPointAfterDef() {
331 assert(!
getType()->isVoidTy() &&
"Instruction must define result");
334 if (
auto *PN = dyn_cast<PHINode>(
this)) {
337 }
else if (
auto *
II = dyn_cast<InvokeInst>(
this)) {
338 InsertBB =
II->getNormalDest();
340 }
else if (isa<CallBrInst>(
this)) {
345 assert(!isTerminator() &&
"Only invoke/callbr terminators return value");
347 InsertPt = std::next(getIterator());
351 InsertPt.setHeadBit(
true);
356 if (InsertPt == InsertBB->
end())
361bool Instruction::isOnlyUserOfAnyOperand() {
362 return any_of(operands(), [](
Value *V) {
return V->hasOneUser(); });
365void Instruction::setHasNoUnsignedWrap(
bool b) {
366 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
367 Inst->setHasNoUnsignedWrap(b);
369 cast<TruncInst>(
this)->setHasNoUnsignedWrap(b);
372void Instruction::setHasNoSignedWrap(
bool b) {
373 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
374 Inst->setHasNoSignedWrap(b);
376 cast<TruncInst>(
this)->setHasNoSignedWrap(b);
379void Instruction::setIsExact(
bool b) {
380 cast<PossiblyExactOperator>(
this)->setIsExact(b);
383void Instruction::setNonNeg(
bool b) {
384 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
386 (b * PossiblyNonNegInst::NonNeg);
389bool Instruction::hasNoUnsignedWrap()
const {
390 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
391 return Inst->hasNoUnsignedWrap();
393 return cast<TruncInst>(
this)->hasNoUnsignedWrap();
396bool Instruction::hasNoSignedWrap()
const {
397 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
398 return Inst->hasNoSignedWrap();
400 return cast<TruncInst>(
this)->hasNoSignedWrap();
403bool Instruction::hasNonNeg()
const {
404 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
405 return (SubclassOptionalData & PossiblyNonNegInst::NonNeg) != 0;
408bool Instruction::hasPoisonGeneratingFlags()
const {
409 return cast<Operator>(
this)->hasPoisonGeneratingFlags();
412void Instruction::dropPoisonGeneratingFlags() {
414 case Instruction::Add:
415 case Instruction::Sub:
416 case Instruction::Mul:
417 case Instruction::Shl:
418 cast<OverflowingBinaryOperator>(
this)->setHasNoUnsignedWrap(
false);
419 cast<OverflowingBinaryOperator>(
this)->setHasNoSignedWrap(
false);
422 case Instruction::UDiv:
423 case Instruction::SDiv:
424 case Instruction::AShr:
425 case Instruction::LShr:
426 cast<PossiblyExactOperator>(
this)->setIsExact(
false);
429 case Instruction::Or:
430 cast<PossiblyDisjointInst>(
this)->setIsDisjoint(
false);
433 case Instruction::GetElementPtr:
434 cast<GetElementPtrInst>(
this)->setNoWrapFlags(GEPNoWrapFlags::none());
437 case Instruction::UIToFP:
438 case Instruction::ZExt:
442 case Instruction::Trunc:
443 cast<TruncInst>(
this)->setHasNoUnsignedWrap(
false);
444 cast<TruncInst>(
this)->setHasNoSignedWrap(
false);
447 case Instruction::ICmp:
448 cast<ICmpInst>(
this)->setSameSign(
false);
452 if (isa<FPMathOperator>(
this)) {
457 assert(!hasPoisonGeneratingFlags() &&
"must be kept in sync");
460bool Instruction::hasPoisonGeneratingMetadata()
const {
461 return hasMetadata(LLVMContext::MD_range) ||
462 hasMetadata(LLVMContext::MD_nonnull) ||
463 hasMetadata(LLVMContext::MD_align);
466bool Instruction::hasNonDebugLocLoopMetadata()
const {
469 if (!hasMetadata(LLVMContext::MD_loop))
473 MDNode *LoopMD = getMetadata(LLVMContext::MD_loop);
480 if (!dyn_cast<DILocation>(
Op)) {
489void Instruction::dropPoisonGeneratingMetadata() {
490 eraseMetadata(LLVMContext::MD_range);
491 eraseMetadata(LLVMContext::MD_nonnull);
492 eraseMetadata(LLVMContext::MD_align);
495bool Instruction::hasPoisonGeneratingReturnAttributes()
const {
496 if (
const auto *CB = dyn_cast<CallBase>(
this)) {
497 AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
505void Instruction::dropPoisonGeneratingReturnAttributes() {
506 if (
auto *CB = dyn_cast<CallBase>(
this)) {
511 CB->removeRetAttrs(AM);
513 assert(!hasPoisonGeneratingReturnAttributes() &&
"must be kept in sync");
516void Instruction::dropUBImplyingAttrsAndUnknownMetadata(
518 dropUnknownNonDebugMetadata(KnownIDs);
519 auto *CB = dyn_cast<CallBase>(
this);
529 AttributeFuncs::getUBImplyingAttributes();
530 for (
unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
531 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
532 CB->removeRetAttrs(UBImplyingAttributes);
535void Instruction::dropUBImplyingAttrsAndMetadata() {
540 unsigned KnownIDs[] = {LLVMContext::MD_annotation, LLVMContext::MD_range,
541 LLVMContext::MD_nonnull, LLVMContext::MD_align};
542 dropUBImplyingAttrsAndUnknownMetadata(KnownIDs);
545bool Instruction::isExact()
const {
546 return cast<PossiblyExactOperator>(
this)->isExact();
549void Instruction::setFast(
bool B) {
550 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
551 cast<FPMathOperator>(
this)->setFast(
B);
554void Instruction::setHasAllowReassoc(
bool B) {
555 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
556 cast<FPMathOperator>(
this)->setHasAllowReassoc(
B);
559void Instruction::setHasNoNaNs(
bool B) {
560 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
561 cast<FPMathOperator>(
this)->setHasNoNaNs(
B);
564void Instruction::setHasNoInfs(
bool B) {
565 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
566 cast<FPMathOperator>(
this)->setHasNoInfs(
B);
569void Instruction::setHasNoSignedZeros(
bool B) {
570 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
571 cast<FPMathOperator>(
this)->setHasNoSignedZeros(
B);
574void Instruction::setHasAllowReciprocal(
bool B) {
575 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
576 cast<FPMathOperator>(
this)->setHasAllowReciprocal(
B);
579void Instruction::setHasAllowContract(
bool B) {
580 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
581 cast<FPMathOperator>(
this)->setHasAllowContract(
B);
584void Instruction::setHasApproxFunc(
bool B) {
585 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
586 cast<FPMathOperator>(
this)->setHasApproxFunc(
B);
590 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
591 cast<FPMathOperator>(
this)->setFastMathFlags(FMF);
595 assert(isa<FPMathOperator>(
this) &&
"copying fast-math flag on invalid op");
596 cast<FPMathOperator>(
this)->copyFastMathFlags(FMF);
599bool Instruction::isFast()
const {
600 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
601 return cast<FPMathOperator>(
this)->isFast();
604bool Instruction::hasAllowReassoc()
const {
605 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
606 return cast<FPMathOperator>(
this)->hasAllowReassoc();
609bool Instruction::hasNoNaNs()
const {
610 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
611 return cast<FPMathOperator>(
this)->hasNoNaNs();
614bool Instruction::hasNoInfs()
const {
615 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
616 return cast<FPMathOperator>(
this)->hasNoInfs();
619bool Instruction::hasNoSignedZeros()
const {
620 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
621 return cast<FPMathOperator>(
this)->hasNoSignedZeros();
624bool Instruction::hasAllowReciprocal()
const {
625 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
626 return cast<FPMathOperator>(
this)->hasAllowReciprocal();
629bool Instruction::hasAllowContract()
const {
630 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
631 return cast<FPMathOperator>(
this)->hasAllowContract();
634bool Instruction::hasApproxFunc()
const {
635 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
636 return cast<FPMathOperator>(
this)->hasApproxFunc();
640 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
641 return cast<FPMathOperator>(
this)->getFastMathFlags();
644void Instruction::copyFastMathFlags(
const Instruction *
I) {
645 copyFastMathFlags(
I->getFastMathFlags());
648void Instruction::copyIRFlags(
const Value *V,
bool IncludeWrapFlags) {
650 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(
this)) {
651 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
652 setHasNoSignedWrap(
OB->hasNoSignedWrap());
653 setHasNoUnsignedWrap(
OB->hasNoUnsignedWrap());
657 if (
auto *TI = dyn_cast<TruncInst>(V)) {
658 if (isa<TruncInst>(
this)) {
659 setHasNoSignedWrap(TI->hasNoSignedWrap());
660 setHasNoUnsignedWrap(TI->hasNoUnsignedWrap());
665 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
666 if (isa<PossiblyExactOperator>(
this))
667 setIsExact(PE->isExact());
669 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
670 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
671 DestPD->setIsDisjoint(SrcPD->isDisjoint());
674 if (
auto *
FP = dyn_cast<FPMathOperator>(V))
675 if (isa<FPMathOperator>(
this))
676 copyFastMathFlags(
FP->getFastMathFlags());
678 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
679 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
680 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() |
681 DestGEP->getNoWrapFlags());
683 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
684 if (isa<PossiblyNonNegInst>(
this))
685 setNonNeg(NNI->hasNonNeg());
687 if (
auto *SrcICmp = dyn_cast<ICmpInst>(V))
688 if (
auto *DestICmp = dyn_cast<ICmpInst>(
this))
689 DestICmp->setSameSign(SrcICmp->hasSameSign());
692void Instruction::andIRFlags(
const Value *V) {
693 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
694 if (isa<OverflowingBinaryOperator>(
this)) {
700 if (
auto *TI = dyn_cast<TruncInst>(V)) {
701 if (isa<TruncInst>(
this)) {
707 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
708 if (isa<PossiblyExactOperator>(
this))
709 setIsExact(isExact() && PE->isExact());
711 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
712 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
713 DestPD->setIsDisjoint(DestPD->isDisjoint() && SrcPD->isDisjoint());
715 if (
auto *
FP = dyn_cast<FPMathOperator>(V)) {
716 if (isa<FPMathOperator>(
this)) {
718 FM &=
FP->getFastMathFlags();
719 copyFastMathFlags(FM);
723 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
724 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
725 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() &
726 DestGEP->getNoWrapFlags());
728 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
729 if (isa<PossiblyNonNegInst>(
this))
730 setNonNeg(hasNonNeg() && NNI->hasNonNeg());
732 if (
auto *SrcICmp = dyn_cast<ICmpInst>(V))
733 if (
auto *DestICmp = dyn_cast<ICmpInst>(
this))
734 DestICmp->setSameSign(DestICmp->hasSameSign() && SrcICmp->hasSameSign());
737const char *Instruction::getOpcodeName(
unsigned OpCode) {
740 case Ret:
return "ret";
741 case Br:
return "br";
742 case Switch:
return "switch";
743 case IndirectBr:
return "indirectbr";
744 case Invoke:
return "invoke";
745 case Resume:
return "resume";
746 case Unreachable:
return "unreachable";
747 case CleanupRet:
return "cleanupret";
748 case CatchRet:
return "catchret";
749 case CatchPad:
return "catchpad";
750 case CatchSwitch:
return "catchswitch";
751 case CallBr:
return "callbr";
754 case FNeg:
return "fneg";
757 case Add:
return "add";
758 case FAdd:
return "fadd";
759 case Sub:
return "sub";
760 case FSub:
return "fsub";
761 case Mul:
return "mul";
762 case FMul:
return "fmul";
763 case UDiv:
return "udiv";
764 case SDiv:
return "sdiv";
765 case FDiv:
return "fdiv";
766 case URem:
return "urem";
767 case SRem:
return "srem";
768 case FRem:
return "frem";
771 case And:
return "and";
772 case Or :
return "or";
773 case Xor:
return "xor";
776 case Alloca:
return "alloca";
777 case Load:
return "load";
778 case Store:
return "store";
779 case AtomicCmpXchg:
return "cmpxchg";
780 case AtomicRMW:
return "atomicrmw";
781 case Fence:
return "fence";
782 case GetElementPtr:
return "getelementptr";
785 case Trunc:
return "trunc";
786 case ZExt:
return "zext";
787 case SExt:
return "sext";
788 case FPTrunc:
return "fptrunc";
789 case FPExt:
return "fpext";
790 case FPToUI:
return "fptoui";
791 case FPToSI:
return "fptosi";
792 case UIToFP:
return "uitofp";
793 case SIToFP:
return "sitofp";
794 case IntToPtr:
return "inttoptr";
795 case PtrToInt:
return "ptrtoint";
796 case BitCast:
return "bitcast";
797 case AddrSpaceCast:
return "addrspacecast";
800 case ICmp:
return "icmp";
801 case FCmp:
return "fcmp";
802 case PHI:
return "phi";
803 case Select:
return "select";
804 case Call:
return "call";
805 case Shl:
return "shl";
806 case LShr:
return "lshr";
807 case AShr:
return "ashr";
808 case VAArg:
return "va_arg";
809 case ExtractElement:
return "extractelement";
810 case InsertElement:
return "insertelement";
811 case ShuffleVector:
return "shufflevector";
812 case ExtractValue:
return "extractvalue";
813 case InsertValue:
return "insertvalue";
814 case LandingPad:
return "landingpad";
815 case CleanupPad:
return "cleanuppad";
816 case Freeze:
return "freeze";
818 default:
return "<Invalid operator> ";
824bool Instruction::hasSameSpecialState(
const Instruction *I2,
825 bool IgnoreAlignment,
826 bool IntersectAttrs)
const {
829 "Can not compare special state of different instructions");
831 auto CheckAttrsSame = [IntersectAttrs](
const CallBase *CB0,
833 return IntersectAttrs
840 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
841 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
842 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
844 if (
const LoadInst *LI = dyn_cast<LoadInst>(I1))
845 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
846 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
848 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
849 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
851 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
852 (
SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
854 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
855 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
856 if (
const CmpInst *CI = dyn_cast<CmpInst>(I1))
857 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
858 if (
const CallInst *CI = dyn_cast<CallInst>(I1))
859 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
860 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
861 CheckAttrsSame(CI, cast<CallInst>(I2)) &&
862 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
863 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
864 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
865 CheckAttrsSame(CI, cast<InvokeInst>(I2)) &&
866 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
867 if (
const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
868 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
869 CheckAttrsSame(CI, cast<CallBrInst>(I2)) &&
870 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
872 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
874 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
875 if (
const FenceInst *FI = dyn_cast<FenceInst>(I1))
876 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
877 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
879 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
880 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
881 CXI->getSuccessOrdering() ==
882 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
883 CXI->getFailureOrdering() ==
884 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
885 CXI->getSyncScopeID() ==
886 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
888 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
889 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
890 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
891 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
893 return SVI->getShuffleMask() ==
894 cast<ShuffleVectorInst>(I2)->getShuffleMask();
896 return GEP->getSourceElementType() ==
897 cast<GetElementPtrInst>(I2)->getSourceElementType();
902bool Instruction::isIdenticalTo(
const Instruction *
I)
const {
903 return isIdenticalToWhenDefined(
I) &&
904 SubclassOptionalData ==
I->SubclassOptionalData;
907bool Instruction::isIdenticalToWhenDefined(
const Instruction *
I,
908 bool IntersectAttrs)
const {
910 getNumOperands() !=
I->getNumOperands() ||
getType() !=
I->getType())
914 if (getNumOperands() == 0 &&
I->getNumOperands() == 0)
915 return this->hasSameSpecialState(
I,
false,
920 if (!std::equal(op_begin(), op_end(),
I->op_begin()))
924 if (
const PHINode *thisPHI = dyn_cast<PHINode>(
this)) {
925 const PHINode *otherPHI = cast<PHINode>(
I);
926 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
930 return this->hasSameSpecialState(
I,
false,
936bool Instruction::isSameOperationAs(
const Instruction *
I,
937 unsigned flags)
const {
938 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
939 bool UseScalarTypes = flags & CompareUsingScalarTypes;
940 bool IntersectAttrs = flags & CompareUsingIntersectedAttrs;
943 getNumOperands() !=
I->getNumOperands() ||
945 getType()->getScalarType() !=
I->getType()->getScalarType() :
951 for (
unsigned i = 0, e = getNumOperands(); i !=
e; ++i)
953 getOperand(i)->
getType()->getScalarType() !=
954 I->getOperand(i)->getType()->getScalarType() :
955 getOperand(i)->
getType() !=
I->getOperand(i)->getType())
958 return this->hasSameSpecialState(
I, IgnoreAlignment, IntersectAttrs);
961bool Instruction::isUsedOutsideOfBlock(
const BasicBlock *BB)
const {
966 const PHINode *PN = dyn_cast<PHINode>(
I);
968 if (
I->getParent() != BB)
979bool Instruction::mayReadFromMemory()
const {
981 default:
return false;
982 case Instruction::VAArg:
983 case Instruction::Load:
984 case Instruction::Fence:
985 case Instruction::AtomicCmpXchg:
986 case Instruction::AtomicRMW:
987 case Instruction::CatchPad:
988 case Instruction::CatchRet:
990 case Instruction::Call:
991 case Instruction::Invoke:
992 case Instruction::CallBr:
993 return !cast<CallBase>(
this)->onlyWritesMemory();
994 case Instruction::Store:
995 return !cast<StoreInst>(
this)->isUnordered();
999bool Instruction::mayWriteToMemory()
const {
1001 default:
return false;
1002 case Instruction::Fence:
1003 case Instruction::Store:
1004 case Instruction::VAArg:
1005 case Instruction::AtomicCmpXchg:
1006 case Instruction::AtomicRMW:
1007 case Instruction::CatchPad:
1008 case Instruction::CatchRet:
1010 case Instruction::Call:
1011 case Instruction::Invoke:
1012 case Instruction::CallBr:
1013 return !cast<CallBase>(
this)->onlyReadsMemory();
1014 case Instruction::Load:
1015 return !cast<LoadInst>(
this)->isUnordered();
1019bool Instruction::isAtomic()
const {
1023 case Instruction::AtomicCmpXchg:
1024 case Instruction::AtomicRMW:
1025 case Instruction::Fence:
1027 case Instruction::Load:
1028 return cast<LoadInst>(
this)->getOrdering() != AtomicOrdering::NotAtomic;
1029 case Instruction::Store:
1030 return cast<StoreInst>(
this)->getOrdering() != AtomicOrdering::NotAtomic;
1034bool Instruction::hasAtomicLoad()
const {
1039 case Instruction::AtomicCmpXchg:
1040 case Instruction::AtomicRMW:
1041 case Instruction::Load:
1046bool Instruction::hasAtomicStore()
const {
1051 case Instruction::AtomicCmpXchg:
1052 case Instruction::AtomicRMW:
1053 case Instruction::Store:
1058bool Instruction::isVolatile()
const {
1062 case Instruction::AtomicRMW:
1063 return cast<AtomicRMWInst>(
this)->isVolatile();
1064 case Instruction::Store:
1065 return cast<StoreInst>(
this)->isVolatile();
1066 case Instruction::Load:
1067 return cast<LoadInst>(
this)->isVolatile();
1068 case Instruction::AtomicCmpXchg:
1069 return cast<AtomicCmpXchgInst>(
this)->isVolatile();
1070 case Instruction::Call:
1071 case Instruction::Invoke:
1073 if (
auto *
II = dyn_cast<IntrinsicInst>(
this)) {
1074 if (
auto *
MI = dyn_cast<MemIntrinsic>(
II))
1075 return MI->isVolatile();
1076 switch (
II->getIntrinsicID()) {
1078 case Intrinsic::matrix_column_major_load:
1079 return cast<ConstantInt>(
II->getArgOperand(2))->isOne();
1080 case Intrinsic::matrix_column_major_store:
1081 return cast<ConstantInt>(
II->getArgOperand(3))->isOne();
1088Type *Instruction::getAccessType()
const {
1090 case Instruction::Store:
1091 return cast<StoreInst>(
this)->getValueOperand()->getType();
1092 case Instruction::Load:
1093 case Instruction::AtomicRMW:
1095 case Instruction::AtomicCmpXchg:
1096 return cast<AtomicCmpXchgInst>(
this)->getNewValOperand()->getType();
1097 case Instruction::Call:
1098 case Instruction::Invoke:
1100 switch (
II->getIntrinsicID()) {
1101 case Intrinsic::masked_load:
1102 case Intrinsic::masked_gather:
1103 case Intrinsic::masked_expandload:
1104 case Intrinsic::vp_load:
1105 case Intrinsic::vp_gather:
1106 case Intrinsic::experimental_vp_strided_load:
1107 return II->getType();
1108 case Intrinsic::masked_store:
1109 case Intrinsic::masked_scatter:
1110 case Intrinsic::masked_compressstore:
1111 case Intrinsic::vp_store:
1112 case Intrinsic::vp_scatter:
1113 case Intrinsic::experimental_vp_strided_store:
1114 return II->getOperand(0)->getType();
1125 bool IncludePhaseOneUnwind) {
1129 return IncludePhaseOneUnwind;
1146bool Instruction::mayThrow(
bool IncludePhaseOneUnwind)
const {
1148 case Instruction::Call:
1149 return !cast<CallInst>(
this)->doesNotThrow();
1150 case Instruction::CleanupRet:
1151 return cast<CleanupReturnInst>(
this)->unwindsToCaller();
1152 case Instruction::CatchSwitch:
1153 return cast<CatchSwitchInst>(
this)->unwindsToCaller();
1154 case Instruction::Resume:
1156 case Instruction::Invoke: {
1159 BasicBlock *UnwindDest = cast<InvokeInst>(
this)->getUnwindDest();
1161 if (
auto *LP = dyn_cast<LandingPadInst>(Pad))
1165 case Instruction::CleanupPad:
1167 return IncludePhaseOneUnwind;
1173bool Instruction::mayHaveSideEffects()
const {
1174 return mayWriteToMemory() ||
mayThrow() || !willReturn();
1177bool Instruction::isSafeToRemove()
const {
1179 !this->isTerminator() && !this->isEHPad();
1182bool Instruction::willReturn()
const {
1184 if (
auto *
SI = dyn_cast<StoreInst>(
this))
1185 return !
SI->isVolatile();
1187 if (
const auto *CB = dyn_cast<CallBase>(
this))
1188 return CB->hasFnAttr(Attribute::WillReturn);
1192bool Instruction::isLifetimeStartOrEnd()
const {
1193 auto *
II = dyn_cast<IntrinsicInst>(
this);
1197 return ID == Intrinsic::lifetime_start ||
ID == Intrinsic::lifetime_end;
1200bool Instruction::isLaunderOrStripInvariantGroup()
const {
1201 auto *
II = dyn_cast<IntrinsicInst>(
this);
1205 return ID == Intrinsic::launder_invariant_group ||
1206 ID == Intrinsic::strip_invariant_group;
1209bool Instruction::isDebugOrPseudoInst()
const {
1210 return isa<DbgInfoIntrinsic>(
this) || isa<PseudoProbeInst>(
this);
1214Instruction::getNextNonDebugInstruction(
bool SkipPseudoOp)
const {
1216 if (!isa<DbgInfoIntrinsic>(
I) && !(SkipPseudoOp && isa<PseudoProbeInst>(
I)))
1222Instruction::getPrevNonDebugInstruction(
bool SkipPseudoOp)
const {
1224 if (!isa<DbgInfoIntrinsic>(
I) &&
1225 !(SkipPseudoOp && isa<PseudoProbeInst>(
I)) &&
1226 !(isa<IntrinsicInst>(
I) &&
1232const DebugLoc &Instruction::getStableDebugLoc()
const {
1233 if (isa<DbgInfoIntrinsic>(
this))
1234 if (
const Instruction *Next = getNextNonDebugInstruction())
1235 return Next->getDebugLoc();
1239bool Instruction::isAssociative()
const {
1240 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1241 return II->isAssociative();
1249 return cast<FPMathOperator>(
this)->hasAllowReassoc() &&
1250 cast<FPMathOperator>(
this)->hasNoSignedZeros();
1256bool Instruction::isCommutative()
const {
1257 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1258 return II->isCommutative();
1263unsigned Instruction::getNumSuccessors()
const {
1265#define HANDLE_TERM_INST(N, OPC, CLASS) \
1266 case Instruction::OPC: \
1267 return static_cast<const CLASS *>(this)->getNumSuccessors();
1268#include "llvm/IR/Instruction.def"
1275BasicBlock *Instruction::getSuccessor(
unsigned idx)
const {
1277#define HANDLE_TERM_INST(N, OPC, CLASS) \
1278 case Instruction::OPC: \
1279 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1280#include "llvm/IR/Instruction.def"
1287void Instruction::setSuccessor(
unsigned idx,
BasicBlock *
B) {
1289#define HANDLE_TERM_INST(N, OPC, CLASS) \
1290 case Instruction::OPC: \
1291 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1292#include "llvm/IR/Instruction.def"
1300 for (
unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
1301 Idx != NumSuccessors; ++
Idx)
1302 if (getSuccessor(
Idx) == OldBB)
1303 setSuccessor(
Idx, NewBB);
1310void Instruction::swapProfMetadata() {
1318 unsigned SecondIdx = FirstIdx + 1;
1323 for (
unsigned Idx = 0;
Idx < FirstIdx; ++
Idx) {
1329 setMetadata(LLVMContext::MD_prof,
1330 MDNode::get(ProfileData->
getContext(), Ops));
1333void Instruction::copyMetadata(
const Instruction &SrcInst,
1344 for (
const auto &MD : TheMDs) {
1345 if (WL.
empty() ||
WLS.count(MD.first))
1346 setMetadata(MD.first, MD.second);
1348 if (WL.
empty() ||
WLS.count(LLVMContext::MD_dbg))
1357#define HANDLE_INST(num, opc, clas) \
1358 case Instruction::opc: \
1359 New = cast<clas>(this)->cloneImpl(); \
1361#include "llvm/IR/Instruction.def"
1365 New->SubclassOptionalData = SubclassOptionalData;
1366 New->copyMetadata(*
this);
static unsigned getIntrinsicID(const SDNode *N)
AMDGPU Register Bank Select
VarLocInsertPt getNextNode(const DbgRecord *DVR)
This file contains the simple types necessary to represent the attributes associated with functions a...
static const Function * getParent(const Value *V)
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
Given that RA is a live propagate it s liveness to any other values it uses(according to Uses). void DeadArgumentEliminationPass
This file defines the DenseSet and SmallDenseSet classes.
std::optional< std::vector< StOtherPiece > > Other
Module.h This file contains the declarations for the Module class.
static bool hasNoSignedWrap(BinaryOperator &I)
static bool hasNoUnsignedWrap(BinaryOperator &I)
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
uint64_t IntrinsicInst * II
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
llvm::cl::opt< bool > UseNewDbgInfoFormat
This file contains the declarations for profiling metadata utility functions.
static bool mayHaveSideEffects(MachineInstr &MI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isCommutative(Instruction *I)
static unsigned getFastMathFlags(const MachineInstr &I)
static bool canUnwindPastLandingPad(const LandingPadInst *LP, bool IncludePhaseOneUnwind)
static SymbolRef::Type getType(const Symbol *Sym)
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
static bool isAssociative(const COFFSection &Section)
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,...
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
std::optional< AttributeList > intersectWith(LLVMContext &C, AttributeList Other) const
Try to intersect this AttributeList with Other.
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...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
AttributeList getAttributes() const
Return the attributes for this call.
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.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Per-instruction record of debug-info.
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
void dropDbgRecords()
Erase all DbgRecords in this DbgMarker.
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.
DbgMarker * DebugMarker
Optional marker recording the position for debugging information that takes effect immediately before...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
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
ArrayRef< MDOperand > operands() const
unsigned getNumOperands() const
Return number of MDNode operands.
LLVMContext & getContext() const
Tracking metadata reference owned by Metadata.
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.
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.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
LLVMContext & getContext() const
All values hold a context through their type.
const ParentTy * getParent() const
self_iterator getIterator()
void splice(iterator where, iplist_impl &L2)
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.
bool mayThrow(const MachineInstr &MI)
@ OB
OB - OneByte - Set if this instruction has a one byte opcode.
@ Switch
The "resume-switch" lowering, where there are separate resume and destroy functions that are shared b...
const_iterator end(StringRef path)
Get end iterator over path.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
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.
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange(DbgMarker *DebugMarker)
Inline helper to return a range of DbgRecords attached to a marker.
@ Or
Bitwise or logical OR of integers.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND of integers.
Summary of memprof metadata on allocations.