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 any_of(Metadata::PoisonGeneratingIDs,
462 [
this](
unsigned ID) {
return hasMetadata(
ID); });
465bool Instruction::hasNonDebugLocLoopMetadata()
const {
468 if (!hasMetadata(LLVMContext::MD_loop))
472 MDNode *LoopMD = getMetadata(LLVMContext::MD_loop);
479 if (!dyn_cast<DILocation>(
Op)) {
488void Instruction::dropPoisonGeneratingMetadata() {
489 for (
unsigned ID : Metadata::PoisonGeneratingIDs)
493bool Instruction::hasPoisonGeneratingReturnAttributes()
const {
494 if (
const auto *CB = dyn_cast<CallBase>(
this)) {
495 AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
503void Instruction::dropPoisonGeneratingReturnAttributes() {
504 if (
auto *CB = dyn_cast<CallBase>(
this)) {
509 CB->removeRetAttrs(AM);
511 assert(!hasPoisonGeneratingReturnAttributes() &&
"must be kept in sync");
514void Instruction::dropUBImplyingAttrsAndUnknownMetadata(
516 dropUnknownNonDebugMetadata(KnownIDs);
517 auto *CB = dyn_cast<CallBase>(
this);
527 AttributeFuncs::getUBImplyingAttributes();
528 for (
unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
529 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
530 CB->removeRetAttrs(UBImplyingAttributes);
533void Instruction::dropUBImplyingAttrsAndMetadata() {
538 unsigned KnownIDs[] = {LLVMContext::MD_annotation, LLVMContext::MD_range,
539 LLVMContext::MD_nonnull, LLVMContext::MD_align};
540 dropUBImplyingAttrsAndUnknownMetadata(KnownIDs);
543bool Instruction::isExact()
const {
544 return cast<PossiblyExactOperator>(
this)->isExact();
547void Instruction::setFast(
bool B) {
548 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
549 cast<FPMathOperator>(
this)->setFast(
B);
552void Instruction::setHasAllowReassoc(
bool B) {
553 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
554 cast<FPMathOperator>(
this)->setHasAllowReassoc(
B);
557void Instruction::setHasNoNaNs(
bool B) {
558 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
559 cast<FPMathOperator>(
this)->setHasNoNaNs(
B);
562void Instruction::setHasNoInfs(
bool B) {
563 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
564 cast<FPMathOperator>(
this)->setHasNoInfs(
B);
567void Instruction::setHasNoSignedZeros(
bool B) {
568 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
569 cast<FPMathOperator>(
this)->setHasNoSignedZeros(
B);
572void Instruction::setHasAllowReciprocal(
bool B) {
573 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
574 cast<FPMathOperator>(
this)->setHasAllowReciprocal(
B);
577void Instruction::setHasAllowContract(
bool B) {
578 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
579 cast<FPMathOperator>(
this)->setHasAllowContract(
B);
582void Instruction::setHasApproxFunc(
bool B) {
583 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
584 cast<FPMathOperator>(
this)->setHasApproxFunc(
B);
588 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
589 cast<FPMathOperator>(
this)->setFastMathFlags(FMF);
593 assert(isa<FPMathOperator>(
this) &&
"copying fast-math flag on invalid op");
594 cast<FPMathOperator>(
this)->copyFastMathFlags(FMF);
597bool Instruction::isFast()
const {
598 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
599 return cast<FPMathOperator>(
this)->isFast();
602bool Instruction::hasAllowReassoc()
const {
603 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
604 return cast<FPMathOperator>(
this)->hasAllowReassoc();
607bool Instruction::hasNoNaNs()
const {
608 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
609 return cast<FPMathOperator>(
this)->hasNoNaNs();
612bool Instruction::hasNoInfs()
const {
613 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
614 return cast<FPMathOperator>(
this)->hasNoInfs();
617bool Instruction::hasNoSignedZeros()
const {
618 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
619 return cast<FPMathOperator>(
this)->hasNoSignedZeros();
622bool Instruction::hasAllowReciprocal()
const {
623 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
624 return cast<FPMathOperator>(
this)->hasAllowReciprocal();
627bool Instruction::hasAllowContract()
const {
628 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
629 return cast<FPMathOperator>(
this)->hasAllowContract();
632bool Instruction::hasApproxFunc()
const {
633 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
634 return cast<FPMathOperator>(
this)->hasApproxFunc();
638 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
639 return cast<FPMathOperator>(
this)->getFastMathFlags();
642void Instruction::copyFastMathFlags(
const Instruction *
I) {
643 copyFastMathFlags(
I->getFastMathFlags());
646void Instruction::copyIRFlags(
const Value *V,
bool IncludeWrapFlags) {
648 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(
this)) {
649 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
650 setHasNoSignedWrap(
OB->hasNoSignedWrap());
651 setHasNoUnsignedWrap(
OB->hasNoUnsignedWrap());
655 if (
auto *TI = dyn_cast<TruncInst>(V)) {
656 if (isa<TruncInst>(
this)) {
657 setHasNoSignedWrap(TI->hasNoSignedWrap());
658 setHasNoUnsignedWrap(TI->hasNoUnsignedWrap());
663 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
664 if (isa<PossiblyExactOperator>(
this))
665 setIsExact(PE->isExact());
667 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
668 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
669 DestPD->setIsDisjoint(SrcPD->isDisjoint());
672 if (
auto *
FP = dyn_cast<FPMathOperator>(V))
673 if (isa<FPMathOperator>(
this))
674 copyFastMathFlags(
FP->getFastMathFlags());
676 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
677 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
678 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() |
679 DestGEP->getNoWrapFlags());
681 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
682 if (isa<PossiblyNonNegInst>(
this))
683 setNonNeg(NNI->hasNonNeg());
685 if (
auto *SrcICmp = dyn_cast<ICmpInst>(V))
686 if (
auto *DestICmp = dyn_cast<ICmpInst>(
this))
687 DestICmp->setSameSign(SrcICmp->hasSameSign());
690void Instruction::andIRFlags(
const Value *V) {
691 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
692 if (isa<OverflowingBinaryOperator>(
this)) {
698 if (
auto *TI = dyn_cast<TruncInst>(V)) {
699 if (isa<TruncInst>(
this)) {
705 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
706 if (isa<PossiblyExactOperator>(
this))
707 setIsExact(isExact() && PE->isExact());
709 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
710 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
711 DestPD->setIsDisjoint(DestPD->isDisjoint() && SrcPD->isDisjoint());
713 if (
auto *
FP = dyn_cast<FPMathOperator>(V)) {
714 if (isa<FPMathOperator>(
this)) {
716 FM &=
FP->getFastMathFlags();
717 copyFastMathFlags(FM);
721 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
722 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
723 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() &
724 DestGEP->getNoWrapFlags());
726 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
727 if (isa<PossiblyNonNegInst>(
this))
728 setNonNeg(hasNonNeg() && NNI->hasNonNeg());
730 if (
auto *SrcICmp = dyn_cast<ICmpInst>(V))
731 if (
auto *DestICmp = dyn_cast<ICmpInst>(
this))
732 DestICmp->setSameSign(DestICmp->hasSameSign() && SrcICmp->hasSameSign());
735const char *Instruction::getOpcodeName(
unsigned OpCode) {
738 case Ret:
return "ret";
739 case Br:
return "br";
740 case Switch:
return "switch";
741 case IndirectBr:
return "indirectbr";
742 case Invoke:
return "invoke";
743 case Resume:
return "resume";
744 case Unreachable:
return "unreachable";
745 case CleanupRet:
return "cleanupret";
746 case CatchRet:
return "catchret";
747 case CatchPad:
return "catchpad";
748 case CatchSwitch:
return "catchswitch";
749 case CallBr:
return "callbr";
752 case FNeg:
return "fneg";
755 case Add:
return "add";
756 case FAdd:
return "fadd";
757 case Sub:
return "sub";
758 case FSub:
return "fsub";
759 case Mul:
return "mul";
760 case FMul:
return "fmul";
761 case UDiv:
return "udiv";
762 case SDiv:
return "sdiv";
763 case FDiv:
return "fdiv";
764 case URem:
return "urem";
765 case SRem:
return "srem";
766 case FRem:
return "frem";
769 case And:
return "and";
770 case Or :
return "or";
771 case Xor:
return "xor";
774 case Alloca:
return "alloca";
775 case Load:
return "load";
776 case Store:
return "store";
777 case AtomicCmpXchg:
return "cmpxchg";
778 case AtomicRMW:
return "atomicrmw";
779 case Fence:
return "fence";
780 case GetElementPtr:
return "getelementptr";
783 case Trunc:
return "trunc";
784 case ZExt:
return "zext";
785 case SExt:
return "sext";
786 case FPTrunc:
return "fptrunc";
787 case FPExt:
return "fpext";
788 case FPToUI:
return "fptoui";
789 case FPToSI:
return "fptosi";
790 case UIToFP:
return "uitofp";
791 case SIToFP:
return "sitofp";
792 case IntToPtr:
return "inttoptr";
793 case PtrToInt:
return "ptrtoint";
794 case BitCast:
return "bitcast";
795 case AddrSpaceCast:
return "addrspacecast";
798 case ICmp:
return "icmp";
799 case FCmp:
return "fcmp";
800 case PHI:
return "phi";
801 case Select:
return "select";
802 case Call:
return "call";
803 case Shl:
return "shl";
804 case LShr:
return "lshr";
805 case AShr:
return "ashr";
806 case VAArg:
return "va_arg";
807 case ExtractElement:
return "extractelement";
808 case InsertElement:
return "insertelement";
809 case ShuffleVector:
return "shufflevector";
810 case ExtractValue:
return "extractvalue";
811 case InsertValue:
return "insertvalue";
812 case LandingPad:
return "landingpad";
813 case CleanupPad:
return "cleanuppad";
814 case Freeze:
return "freeze";
816 default:
return "<Invalid operator> ";
822bool Instruction::hasSameSpecialState(
const Instruction *I2,
823 bool IgnoreAlignment,
824 bool IntersectAttrs)
const {
827 "Can not compare special state of different instructions");
829 auto CheckAttrsSame = [IntersectAttrs](
const CallBase *CB0,
831 return IntersectAttrs
838 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
839 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
840 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
842 if (
const LoadInst *LI = dyn_cast<LoadInst>(I1))
843 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
844 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
846 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
847 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
849 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
850 (
SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
852 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
853 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
854 if (
const CmpInst *CI = dyn_cast<CmpInst>(I1))
855 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
856 if (
const CallInst *CI = dyn_cast<CallInst>(I1))
857 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
858 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
859 CheckAttrsSame(CI, cast<CallInst>(I2)) &&
860 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
861 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
862 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
863 CheckAttrsSame(CI, cast<InvokeInst>(I2)) &&
864 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
865 if (
const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
866 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
867 CheckAttrsSame(CI, cast<CallBrInst>(I2)) &&
868 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
870 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
872 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
873 if (
const FenceInst *FI = dyn_cast<FenceInst>(I1))
874 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
875 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
877 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
878 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
879 CXI->getSuccessOrdering() ==
880 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
881 CXI->getFailureOrdering() ==
882 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
883 CXI->getSyncScopeID() ==
884 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
886 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
887 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
888 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
889 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
891 return SVI->getShuffleMask() ==
892 cast<ShuffleVectorInst>(I2)->getShuffleMask();
894 return GEP->getSourceElementType() ==
895 cast<GetElementPtrInst>(I2)->getSourceElementType();
900bool Instruction::isIdenticalTo(
const Instruction *
I)
const {
901 return isIdenticalToWhenDefined(
I) &&
902 SubclassOptionalData ==
I->SubclassOptionalData;
905bool Instruction::isIdenticalToWhenDefined(
const Instruction *
I,
906 bool IntersectAttrs)
const {
908 getNumOperands() !=
I->getNumOperands() ||
getType() !=
I->getType())
912 if (getNumOperands() == 0 &&
I->getNumOperands() == 0)
913 return this->hasSameSpecialState(
I,
false,
918 if (!std::equal(op_begin(), op_end(),
I->op_begin()))
922 if (
const PHINode *thisPHI = dyn_cast<PHINode>(
this)) {
923 const PHINode *otherPHI = cast<PHINode>(
I);
924 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
928 return this->hasSameSpecialState(
I,
false,
934bool Instruction::isSameOperationAs(
const Instruction *
I,
935 unsigned flags)
const {
936 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
937 bool UseScalarTypes = flags & CompareUsingScalarTypes;
938 bool IntersectAttrs = flags & CompareUsingIntersectedAttrs;
941 getNumOperands() !=
I->getNumOperands() ||
943 getType()->getScalarType() !=
I->getType()->getScalarType() :
949 for (
unsigned i = 0, e = getNumOperands(); i !=
e; ++i)
951 getOperand(i)->
getType()->getScalarType() !=
952 I->getOperand(i)->getType()->getScalarType() :
953 getOperand(i)->
getType() !=
I->getOperand(i)->getType())
956 return this->hasSameSpecialState(
I, IgnoreAlignment, IntersectAttrs);
959bool Instruction::isUsedOutsideOfBlock(
const BasicBlock *BB)
const {
964 const PHINode *PN = dyn_cast<PHINode>(
I);
966 if (
I->getParent() != BB)
977bool Instruction::mayReadFromMemory()
const {
979 default:
return false;
980 case Instruction::VAArg:
981 case Instruction::Load:
982 case Instruction::Fence:
983 case Instruction::AtomicCmpXchg:
984 case Instruction::AtomicRMW:
985 case Instruction::CatchPad:
986 case Instruction::CatchRet:
988 case Instruction::Call:
989 case Instruction::Invoke:
990 case Instruction::CallBr:
991 return !cast<CallBase>(
this)->onlyWritesMemory();
992 case Instruction::Store:
993 return !cast<StoreInst>(
this)->isUnordered();
997bool Instruction::mayWriteToMemory()
const {
999 default:
return false;
1000 case Instruction::Fence:
1001 case Instruction::Store:
1002 case Instruction::VAArg:
1003 case Instruction::AtomicCmpXchg:
1004 case Instruction::AtomicRMW:
1005 case Instruction::CatchPad:
1006 case Instruction::CatchRet:
1008 case Instruction::Call:
1009 case Instruction::Invoke:
1010 case Instruction::CallBr:
1011 return !cast<CallBase>(
this)->onlyReadsMemory();
1012 case Instruction::Load:
1013 return !cast<LoadInst>(
this)->isUnordered();
1017bool Instruction::isAtomic()
const {
1021 case Instruction::AtomicCmpXchg:
1022 case Instruction::AtomicRMW:
1023 case Instruction::Fence:
1025 case Instruction::Load:
1026 return cast<LoadInst>(
this)->getOrdering() != AtomicOrdering::NotAtomic;
1027 case Instruction::Store:
1028 return cast<StoreInst>(
this)->getOrdering() != AtomicOrdering::NotAtomic;
1032bool Instruction::hasAtomicLoad()
const {
1037 case Instruction::AtomicCmpXchg:
1038 case Instruction::AtomicRMW:
1039 case Instruction::Load:
1044bool Instruction::hasAtomicStore()
const {
1049 case Instruction::AtomicCmpXchg:
1050 case Instruction::AtomicRMW:
1051 case Instruction::Store:
1056bool Instruction::isVolatile()
const {
1060 case Instruction::AtomicRMW:
1061 return cast<AtomicRMWInst>(
this)->isVolatile();
1062 case Instruction::Store:
1063 return cast<StoreInst>(
this)->isVolatile();
1064 case Instruction::Load:
1065 return cast<LoadInst>(
this)->isVolatile();
1066 case Instruction::AtomicCmpXchg:
1067 return cast<AtomicCmpXchgInst>(
this)->isVolatile();
1068 case Instruction::Call:
1069 case Instruction::Invoke:
1071 if (
auto *
II = dyn_cast<IntrinsicInst>(
this)) {
1072 if (
auto *
MI = dyn_cast<MemIntrinsic>(
II))
1073 return MI->isVolatile();
1074 switch (
II->getIntrinsicID()) {
1076 case Intrinsic::matrix_column_major_load:
1077 return cast<ConstantInt>(
II->getArgOperand(2))->isOne();
1078 case Intrinsic::matrix_column_major_store:
1079 return cast<ConstantInt>(
II->getArgOperand(3))->isOne();
1086Type *Instruction::getAccessType()
const {
1088 case Instruction::Store:
1089 return cast<StoreInst>(
this)->getValueOperand()->getType();
1090 case Instruction::Load:
1091 case Instruction::AtomicRMW:
1093 case Instruction::AtomicCmpXchg:
1094 return cast<AtomicCmpXchgInst>(
this)->getNewValOperand()->getType();
1095 case Instruction::Call:
1096 case Instruction::Invoke:
1098 switch (
II->getIntrinsicID()) {
1099 case Intrinsic::masked_load:
1100 case Intrinsic::masked_gather:
1101 case Intrinsic::masked_expandload:
1102 case Intrinsic::vp_load:
1103 case Intrinsic::vp_gather:
1104 case Intrinsic::experimental_vp_strided_load:
1105 return II->getType();
1106 case Intrinsic::masked_store:
1107 case Intrinsic::masked_scatter:
1108 case Intrinsic::masked_compressstore:
1109 case Intrinsic::vp_store:
1110 case Intrinsic::vp_scatter:
1111 case Intrinsic::experimental_vp_strided_store:
1112 return II->getOperand(0)->getType();
1123 bool IncludePhaseOneUnwind) {
1127 return IncludePhaseOneUnwind;
1144bool Instruction::mayThrow(
bool IncludePhaseOneUnwind)
const {
1146 case Instruction::Call:
1147 return !cast<CallInst>(
this)->doesNotThrow();
1148 case Instruction::CleanupRet:
1149 return cast<CleanupReturnInst>(
this)->unwindsToCaller();
1150 case Instruction::CatchSwitch:
1151 return cast<CatchSwitchInst>(
this)->unwindsToCaller();
1152 case Instruction::Resume:
1154 case Instruction::Invoke: {
1157 BasicBlock *UnwindDest = cast<InvokeInst>(
this)->getUnwindDest();
1159 if (
auto *LP = dyn_cast<LandingPadInst>(Pad))
1163 case Instruction::CleanupPad:
1165 return IncludePhaseOneUnwind;
1171bool Instruction::mayHaveSideEffects()
const {
1172 return mayWriteToMemory() ||
mayThrow() || !willReturn();
1175bool Instruction::isSafeToRemove()
const {
1177 !this->isTerminator() && !this->isEHPad();
1180bool Instruction::willReturn()
const {
1182 if (
auto *
SI = dyn_cast<StoreInst>(
this))
1183 return !
SI->isVolatile();
1185 if (
const auto *CB = dyn_cast<CallBase>(
this))
1186 return CB->hasFnAttr(Attribute::WillReturn);
1190bool Instruction::isLifetimeStartOrEnd()
const {
1191 auto *
II = dyn_cast<IntrinsicInst>(
this);
1195 return ID == Intrinsic::lifetime_start ||
ID == Intrinsic::lifetime_end;
1198bool Instruction::isLaunderOrStripInvariantGroup()
const {
1199 auto *
II = dyn_cast<IntrinsicInst>(
this);
1203 return ID == Intrinsic::launder_invariant_group ||
1204 ID == Intrinsic::strip_invariant_group;
1207bool Instruction::isDebugOrPseudoInst()
const {
1208 return isa<DbgInfoIntrinsic>(
this) || isa<PseudoProbeInst>(
this);
1212Instruction::getNextNonDebugInstruction(
bool SkipPseudoOp)
const {
1214 if (!isa<DbgInfoIntrinsic>(
I) && !(SkipPseudoOp && isa<PseudoProbeInst>(
I)))
1220Instruction::getPrevNonDebugInstruction(
bool SkipPseudoOp)
const {
1222 if (!isa<DbgInfoIntrinsic>(
I) &&
1223 !(SkipPseudoOp && isa<PseudoProbeInst>(
I)) &&
1224 !(isa<IntrinsicInst>(
I) &&
1230const DebugLoc &Instruction::getStableDebugLoc()
const {
1231 if (isa<DbgInfoIntrinsic>(
this))
1232 if (
const Instruction *Next = getNextNonDebugInstruction())
1233 return Next->getDebugLoc();
1237bool Instruction::isAssociative()
const {
1238 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1239 return II->isAssociative();
1247 return cast<FPMathOperator>(
this)->hasAllowReassoc() &&
1248 cast<FPMathOperator>(
this)->hasNoSignedZeros();
1254bool Instruction::isCommutative()
const {
1255 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1256 return II->isCommutative();
1261unsigned Instruction::getNumSuccessors()
const {
1263#define HANDLE_TERM_INST(N, OPC, CLASS) \
1264 case Instruction::OPC: \
1265 return static_cast<const CLASS *>(this)->getNumSuccessors();
1266#include "llvm/IR/Instruction.def"
1273BasicBlock *Instruction::getSuccessor(
unsigned idx)
const {
1275#define HANDLE_TERM_INST(N, OPC, CLASS) \
1276 case Instruction::OPC: \
1277 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1278#include "llvm/IR/Instruction.def"
1285void Instruction::setSuccessor(
unsigned idx,
BasicBlock *
B) {
1287#define HANDLE_TERM_INST(N, OPC, CLASS) \
1288 case Instruction::OPC: \
1289 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1290#include "llvm/IR/Instruction.def"
1298 for (
unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
1299 Idx != NumSuccessors; ++
Idx)
1300 if (getSuccessor(
Idx) == OldBB)
1301 setSuccessor(
Idx, NewBB);
1308void Instruction::swapProfMetadata() {
1316 unsigned SecondIdx = FirstIdx + 1;
1321 for (
unsigned Idx = 0;
Idx < FirstIdx; ++
Idx) {
1327 setMetadata(LLVMContext::MD_prof,
1328 MDNode::get(ProfileData->
getContext(), Ops));
1331void Instruction::copyMetadata(
const Instruction &SrcInst,
1342 for (
const auto &MD : TheMDs) {
1343 if (WL.
empty() ||
WLS.count(MD.first))
1344 setMetadata(MD.first, MD.second);
1346 if (WL.
empty() ||
WLS.count(LLVMContext::MD_dbg))
1355#define HANDLE_INST(num, opc, clas) \
1356 case Instruction::opc: \
1357 New = cast<clas>(this)->cloneImpl(); \
1359#include "llvm/IR/Instruction.def"
1363 New->SubclassOptionalData = SubclassOptionalData;
1364 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 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 LLVM_LIFETIME_BOUND)
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.