29InsertPosition::InsertPosition(
Instruction *InsertBefore)
30 : InsertAt(InsertBefore ? InsertBefore->getIterator()
31 : InstListType::iterator()) {}
32InsertPosition::InsertPosition(
BasicBlock *InsertAtEnd)
33 : InsertAt(InsertAtEnd ? InsertAtEnd->
end() : InstListType::iterator()) {}
39 if (InstListType::iterator InsertIt = InsertBefore; InsertIt.isValid()) {
41 assert(BB &&
"Instruction to insert before is not in a basic block!");
42 insertInto(BB, InsertBefore);
46Instruction::~Instruction() {
58 if (isUsedByMetadata())
59 ValueAsMetadata::handleRAUW(
this, UndefValue::get(
getType()));
63 setMetadata(LLVMContext::MD_DIAssignID,
nullptr);
66const Module *Instruction::getModule()
const {
70const Function *Instruction::getFunction()
const {
74const DataLayout &Instruction::getDataLayout()
const {
75 return getModule()->getDataLayout();
78void Instruction::removeFromParent() {
80 handleMarkerRemoval();
82 getParent()->getInstList().remove(getIterator());
85void Instruction::handleMarkerRemoval() {
86 if (!
getParent()->IsNewDbgInfoFormat || !DebugMarker)
89 DebugMarker->removeMarker();
93 handleMarkerRemoval();
94 return getParent()->getInstList().erase(getIterator());
97void Instruction::insertBefore(
Instruction *InsertPos) {
104 insertBefore(*InsertPos->getParent(), InsertPos);
109void Instruction::insertAfter(
Instruction *InsertPos) {
118 assert((It == ParentBB->
end() || It->getParent() == ParentBB) &&
119 "It not in ParentBB");
120 insertBefore(*ParentBB, It);
121 return getIterator();
127 InstListType::iterator InsertPos) {
130 BB.getInstList().
insert(InsertPos,
this);
138 bool InsertAtHead = InsertPos.getHeadBit();
141 if (SrcMarker && !SrcMarker->
empty()) {
153 assert(!isa<PHINode>(
this) &&
"Inserting PHI after debug-records!");
154 adoptDbgRecords(&BB, InsertPos,
false);
162 getParent()->flushTerminatorDbgRecords();
167void Instruction::moveBefore(
Instruction *MovePos) {
171void Instruction::moveBeforePreserving(
Instruction *MovePos) {
179 NextIt.setHeadBit(
true);
180 moveBeforeImpl(*MovePos->
getParent(), NextIt,
false);
183void Instruction::moveAfterPreserving(
Instruction *MovePos) {
187 NextIt.setHeadBit(
true);
188 moveBeforeImpl(*MovePos->
getParent(), NextIt,
true);
191void Instruction::moveBefore(
BasicBlock &BB, InstListType::iterator
I) {
192 moveBeforeImpl(BB,
I,
false);
195void Instruction::moveBeforePreserving(
BasicBlock &BB,
196 InstListType::iterator
I) {
197 moveBeforeImpl(BB,
I,
true);
200void Instruction::moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
203 bool InsertAtHead =
I.getHeadBit();
208 if (
I != this->getIterator() || InsertAtHead) {
211 handleMarkerRemoval();
224 if (!InsertAtHead && NextMarker && !NextMarker->
empty()) {
225 adoptDbgRecords(&BB,
I,
false);
230 getParent()->flushTerminatorDbgRecords();
234 const Instruction *
From, std::optional<DbgRecord::self_iterator> FromHere,
236 if (!
From->DebugMarker)
237 return DbgMarker::getEmptyDbgRecordRange();
241 From->getParent()->IsNewDbgInfoFormat);
246 return DebugMarker->cloneDebugInfoFrom(
From->DebugMarker, FromHere,
250std::optional<DbgRecord::self_iterator>
251Instruction::getDbgReinsertionPosition() {
269 auto ReleaseTrailingDbgRecords = [BB, It, SrcMarker]() {
270 if (BB->
end() == It) {
277 ReleaseTrailingDbgRecords();
284 if (DebugMarker || It == BB->
end()) {
287 DebugMarker->absorbDebugValues(*SrcMarker, InsertAtHead);
298 ReleaseTrailingDbgRecords();
303 DebugMarker = SrcMarker;
309void Instruction::dropDbgRecords() {
314void Instruction::dropOneDbgRecord(
DbgRecord *DVR) {
315 DebugMarker->dropOneDbgRecord(DVR);
320 "instructions without BB parents have no order");
322 "cross-BB instruction order comparison");
325 return Order <
Other->Order;
328std::optional<BasicBlock::iterator> Instruction::getInsertionPointAfterDef() {
329 assert(!
getType()->isVoidTy() &&
"Instruction must define result");
332 if (
auto *PN = dyn_cast<PHINode>(
this)) {
335 }
else if (
auto *
II = dyn_cast<InvokeInst>(
this)) {
336 InsertBB =
II->getNormalDest();
338 }
else if (isa<CallBrInst>(
this)) {
343 assert(!isTerminator() &&
"Only invoke/callbr terminators return value");
345 InsertPt = std::next(getIterator());
349 InsertPt.setHeadBit(
true);
354 if (InsertPt == InsertBB->
end())
359bool Instruction::isOnlyUserOfAnyOperand() {
360 return any_of(operands(), [](
Value *V) {
return V->hasOneUser(); });
363void Instruction::setHasNoUnsignedWrap(
bool b) {
364 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
365 Inst->setHasNoUnsignedWrap(b);
367 cast<TruncInst>(
this)->setHasNoUnsignedWrap(b);
370void Instruction::setHasNoSignedWrap(
bool b) {
371 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
372 Inst->setHasNoSignedWrap(b);
374 cast<TruncInst>(
this)->setHasNoSignedWrap(b);
377void Instruction::setIsExact(
bool b) {
378 cast<PossiblyExactOperator>(
this)->setIsExact(b);
381void Instruction::setNonNeg(
bool b) {
382 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
384 (b * PossiblyNonNegInst::NonNeg);
387bool Instruction::hasNoUnsignedWrap()
const {
388 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
389 return Inst->hasNoUnsignedWrap();
391 return cast<TruncInst>(
this)->hasNoUnsignedWrap();
394bool Instruction::hasNoSignedWrap()
const {
395 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
396 return Inst->hasNoSignedWrap();
398 return cast<TruncInst>(
this)->hasNoSignedWrap();
401bool Instruction::hasNonNeg()
const {
402 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
403 return (SubclassOptionalData & PossiblyNonNegInst::NonNeg) != 0;
406bool Instruction::hasPoisonGeneratingFlags()
const {
407 return cast<Operator>(
this)->hasPoisonGeneratingFlags();
410void Instruction::dropPoisonGeneratingFlags() {
412 case Instruction::Add:
413 case Instruction::Sub:
414 case Instruction::Mul:
415 case Instruction::Shl:
416 cast<OverflowingBinaryOperator>(
this)->setHasNoUnsignedWrap(
false);
417 cast<OverflowingBinaryOperator>(
this)->setHasNoSignedWrap(
false);
420 case Instruction::UDiv:
421 case Instruction::SDiv:
422 case Instruction::AShr:
423 case Instruction::LShr:
424 cast<PossiblyExactOperator>(
this)->setIsExact(
false);
427 case Instruction::Or:
428 cast<PossiblyDisjointInst>(
this)->setIsDisjoint(
false);
431 case Instruction::GetElementPtr:
432 cast<GetElementPtrInst>(
this)->setNoWrapFlags(GEPNoWrapFlags::none());
435 case Instruction::UIToFP:
436 case Instruction::ZExt:
440 case Instruction::Trunc:
441 cast<TruncInst>(
this)->setHasNoUnsignedWrap(
false);
442 cast<TruncInst>(
this)->setHasNoSignedWrap(
false);
445 case Instruction::ICmp:
446 cast<ICmpInst>(
this)->setSameSign(
false);
450 if (isa<FPMathOperator>(
this)) {
455 assert(!hasPoisonGeneratingFlags() &&
"must be kept in sync");
458bool Instruction::hasPoisonGeneratingMetadata()
const {
459 return hasMetadata(LLVMContext::MD_range) ||
460 hasMetadata(LLVMContext::MD_nonnull) ||
461 hasMetadata(LLVMContext::MD_align);
464void Instruction::dropPoisonGeneratingMetadata() {
465 eraseMetadata(LLVMContext::MD_range);
466 eraseMetadata(LLVMContext::MD_nonnull);
467 eraseMetadata(LLVMContext::MD_align);
470bool Instruction::hasPoisonGeneratingReturnAttributes()
const {
471 if (
const auto *CB = dyn_cast<CallBase>(
this)) {
472 AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
480void Instruction::dropPoisonGeneratingReturnAttributes() {
481 if (
auto *CB = dyn_cast<CallBase>(
this)) {
486 CB->removeRetAttrs(AM);
488 assert(!hasPoisonGeneratingReturnAttributes() &&
"must be kept in sync");
491void Instruction::dropUBImplyingAttrsAndUnknownMetadata(
493 dropUnknownNonDebugMetadata(KnownIDs);
494 auto *CB = dyn_cast<CallBase>(
this);
504 AttributeFuncs::getUBImplyingAttributes();
505 for (
unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
506 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
507 CB->removeRetAttrs(UBImplyingAttributes);
510void Instruction::dropUBImplyingAttrsAndMetadata() {
515 unsigned KnownIDs[] = {LLVMContext::MD_annotation, LLVMContext::MD_range,
516 LLVMContext::MD_nonnull, LLVMContext::MD_align};
517 dropUBImplyingAttrsAndUnknownMetadata(KnownIDs);
520bool Instruction::isExact()
const {
521 return cast<PossiblyExactOperator>(
this)->isExact();
524void Instruction::setFast(
bool B) {
525 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
526 cast<FPMathOperator>(
this)->setFast(
B);
529void Instruction::setHasAllowReassoc(
bool B) {
530 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
531 cast<FPMathOperator>(
this)->setHasAllowReassoc(
B);
534void Instruction::setHasNoNaNs(
bool B) {
535 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
536 cast<FPMathOperator>(
this)->setHasNoNaNs(
B);
539void Instruction::setHasNoInfs(
bool B) {
540 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
541 cast<FPMathOperator>(
this)->setHasNoInfs(
B);
544void Instruction::setHasNoSignedZeros(
bool B) {
545 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
546 cast<FPMathOperator>(
this)->setHasNoSignedZeros(
B);
549void Instruction::setHasAllowReciprocal(
bool B) {
550 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
551 cast<FPMathOperator>(
this)->setHasAllowReciprocal(
B);
554void Instruction::setHasAllowContract(
bool B) {
555 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
556 cast<FPMathOperator>(
this)->setHasAllowContract(
B);
559void Instruction::setHasApproxFunc(
bool B) {
560 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
561 cast<FPMathOperator>(
this)->setHasApproxFunc(
B);
565 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
566 cast<FPMathOperator>(
this)->setFastMathFlags(FMF);
570 assert(isa<FPMathOperator>(
this) &&
"copying fast-math flag on invalid op");
571 cast<FPMathOperator>(
this)->copyFastMathFlags(FMF);
574bool Instruction::isFast()
const {
575 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
576 return cast<FPMathOperator>(
this)->isFast();
579bool Instruction::hasAllowReassoc()
const {
580 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
581 return cast<FPMathOperator>(
this)->hasAllowReassoc();
584bool Instruction::hasNoNaNs()
const {
585 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
586 return cast<FPMathOperator>(
this)->hasNoNaNs();
589bool Instruction::hasNoInfs()
const {
590 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
591 return cast<FPMathOperator>(
this)->hasNoInfs();
594bool Instruction::hasNoSignedZeros()
const {
595 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
596 return cast<FPMathOperator>(
this)->hasNoSignedZeros();
599bool Instruction::hasAllowReciprocal()
const {
600 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
601 return cast<FPMathOperator>(
this)->hasAllowReciprocal();
604bool Instruction::hasAllowContract()
const {
605 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
606 return cast<FPMathOperator>(
this)->hasAllowContract();
609bool Instruction::hasApproxFunc()
const {
610 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
611 return cast<FPMathOperator>(
this)->hasApproxFunc();
615 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
616 return cast<FPMathOperator>(
this)->getFastMathFlags();
619void Instruction::copyFastMathFlags(
const Instruction *
I) {
620 copyFastMathFlags(
I->getFastMathFlags());
623void Instruction::copyIRFlags(
const Value *V,
bool IncludeWrapFlags) {
625 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(
this)) {
626 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
627 setHasNoSignedWrap(
OB->hasNoSignedWrap());
628 setHasNoUnsignedWrap(
OB->hasNoUnsignedWrap());
632 if (
auto *TI = dyn_cast<TruncInst>(V)) {
633 if (isa<TruncInst>(
this)) {
634 setHasNoSignedWrap(TI->hasNoSignedWrap());
635 setHasNoUnsignedWrap(TI->hasNoUnsignedWrap());
640 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
641 if (isa<PossiblyExactOperator>(
this))
642 setIsExact(PE->isExact());
644 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
645 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
646 DestPD->setIsDisjoint(SrcPD->isDisjoint());
649 if (
auto *
FP = dyn_cast<FPMathOperator>(V))
650 if (isa<FPMathOperator>(
this))
651 copyFastMathFlags(
FP->getFastMathFlags());
653 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
654 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
655 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() |
656 DestGEP->getNoWrapFlags());
658 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
659 if (isa<PossiblyNonNegInst>(
this))
660 setNonNeg(NNI->hasNonNeg());
662 if (
auto *SrcICmp = dyn_cast<ICmpInst>(V))
663 if (
auto *DestICmp = dyn_cast<ICmpInst>(
this))
664 DestICmp->setSameSign(SrcICmp->hasSameSign());
667void Instruction::andIRFlags(
const Value *V) {
668 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
669 if (isa<OverflowingBinaryOperator>(
this)) {
675 if (
auto *TI = dyn_cast<TruncInst>(V)) {
676 if (isa<TruncInst>(
this)) {
682 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
683 if (isa<PossiblyExactOperator>(
this))
684 setIsExact(isExact() && PE->isExact());
686 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
687 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
688 DestPD->setIsDisjoint(DestPD->isDisjoint() && SrcPD->isDisjoint());
690 if (
auto *
FP = dyn_cast<FPMathOperator>(V)) {
691 if (isa<FPMathOperator>(
this)) {
693 FM &=
FP->getFastMathFlags();
694 copyFastMathFlags(FM);
698 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
699 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
700 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() &
701 DestGEP->getNoWrapFlags());
703 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
704 if (isa<PossiblyNonNegInst>(
this))
705 setNonNeg(hasNonNeg() && NNI->hasNonNeg());
707 if (
auto *SrcICmp = dyn_cast<ICmpInst>(V))
708 if (
auto *DestICmp = dyn_cast<ICmpInst>(
this))
709 DestICmp->setSameSign(DestICmp->hasSameSign() && SrcICmp->hasSameSign());
712const char *Instruction::getOpcodeName(
unsigned OpCode) {
715 case Ret:
return "ret";
716 case Br:
return "br";
717 case Switch:
return "switch";
718 case IndirectBr:
return "indirectbr";
719 case Invoke:
return "invoke";
720 case Resume:
return "resume";
721 case Unreachable:
return "unreachable";
722 case CleanupRet:
return "cleanupret";
723 case CatchRet:
return "catchret";
724 case CatchPad:
return "catchpad";
725 case CatchSwitch:
return "catchswitch";
726 case CallBr:
return "callbr";
729 case FNeg:
return "fneg";
732 case Add:
return "add";
733 case FAdd:
return "fadd";
734 case Sub:
return "sub";
735 case FSub:
return "fsub";
736 case Mul:
return "mul";
737 case FMul:
return "fmul";
738 case UDiv:
return "udiv";
739 case SDiv:
return "sdiv";
740 case FDiv:
return "fdiv";
741 case URem:
return "urem";
742 case SRem:
return "srem";
743 case FRem:
return "frem";
746 case And:
return "and";
747 case Or :
return "or";
748 case Xor:
return "xor";
751 case Alloca:
return "alloca";
752 case Load:
return "load";
753 case Store:
return "store";
754 case AtomicCmpXchg:
return "cmpxchg";
755 case AtomicRMW:
return "atomicrmw";
756 case Fence:
return "fence";
757 case GetElementPtr:
return "getelementptr";
760 case Trunc:
return "trunc";
761 case ZExt:
return "zext";
762 case SExt:
return "sext";
763 case FPTrunc:
return "fptrunc";
764 case FPExt:
return "fpext";
765 case FPToUI:
return "fptoui";
766 case FPToSI:
return "fptosi";
767 case UIToFP:
return "uitofp";
768 case SIToFP:
return "sitofp";
769 case IntToPtr:
return "inttoptr";
770 case PtrToInt:
return "ptrtoint";
771 case BitCast:
return "bitcast";
772 case AddrSpaceCast:
return "addrspacecast";
775 case ICmp:
return "icmp";
776 case FCmp:
return "fcmp";
777 case PHI:
return "phi";
778 case Select:
return "select";
779 case Call:
return "call";
780 case Shl:
return "shl";
781 case LShr:
return "lshr";
782 case AShr:
return "ashr";
783 case VAArg:
return "va_arg";
784 case ExtractElement:
return "extractelement";
785 case InsertElement:
return "insertelement";
786 case ShuffleVector:
return "shufflevector";
787 case ExtractValue:
return "extractvalue";
788 case InsertValue:
return "insertvalue";
789 case LandingPad:
return "landingpad";
790 case CleanupPad:
return "cleanuppad";
791 case Freeze:
return "freeze";
793 default:
return "<Invalid operator> ";
799bool Instruction::hasSameSpecialState(
const Instruction *I2,
800 bool IgnoreAlignment,
801 bool IntersectAttrs)
const {
804 "Can not compare special state of different instructions");
806 auto CheckAttrsSame = [IntersectAttrs](
const CallBase *CB0,
808 return IntersectAttrs
815 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
816 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
817 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
819 if (
const LoadInst *LI = dyn_cast<LoadInst>(I1))
820 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
821 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
823 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
824 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
826 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
827 (
SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
829 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
830 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
831 if (
const CmpInst *CI = dyn_cast<CmpInst>(I1))
832 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
833 if (
const CallInst *CI = dyn_cast<CallInst>(I1))
834 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
835 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
836 CheckAttrsSame(CI, cast<CallInst>(I2)) &&
837 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
838 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
839 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
840 CheckAttrsSame(CI, cast<InvokeInst>(I2)) &&
841 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
842 if (
const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
843 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
844 CheckAttrsSame(CI, cast<CallBrInst>(I2)) &&
845 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
847 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
849 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
850 if (
const FenceInst *FI = dyn_cast<FenceInst>(I1))
851 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
852 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
854 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
855 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
856 CXI->getSuccessOrdering() ==
857 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
858 CXI->getFailureOrdering() ==
859 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
860 CXI->getSyncScopeID() ==
861 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
863 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
864 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
865 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
866 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
868 return SVI->getShuffleMask() ==
869 cast<ShuffleVectorInst>(I2)->getShuffleMask();
871 return GEP->getSourceElementType() ==
872 cast<GetElementPtrInst>(I2)->getSourceElementType();
877bool Instruction::isIdenticalTo(
const Instruction *
I)
const {
878 return isIdenticalToWhenDefined(
I) &&
879 SubclassOptionalData ==
I->SubclassOptionalData;
882bool Instruction::isIdenticalToWhenDefined(
const Instruction *
I,
883 bool IntersectAttrs)
const {
885 getNumOperands() !=
I->getNumOperands() ||
getType() !=
I->getType())
889 if (getNumOperands() == 0 &&
I->getNumOperands() == 0)
890 return this->hasSameSpecialState(
I,
false,
895 if (!std::equal(op_begin(), op_end(),
I->op_begin()))
899 if (
const PHINode *thisPHI = dyn_cast<PHINode>(
this)) {
900 const PHINode *otherPHI = cast<PHINode>(
I);
901 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
905 return this->hasSameSpecialState(
I,
false,
911bool Instruction::isSameOperationAs(
const Instruction *
I,
912 unsigned flags)
const {
913 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
914 bool UseScalarTypes = flags & CompareUsingScalarTypes;
915 bool IntersectAttrs = flags & CompareUsingIntersectedAttrs;
918 getNumOperands() !=
I->getNumOperands() ||
920 getType()->getScalarType() !=
I->getType()->getScalarType() :
926 for (
unsigned i = 0, e = getNumOperands(); i !=
e; ++i)
928 getOperand(i)->
getType()->getScalarType() !=
929 I->getOperand(i)->getType()->getScalarType() :
930 getOperand(i)->
getType() !=
I->getOperand(i)->getType())
933 return this->hasSameSpecialState(
I, IgnoreAlignment, IntersectAttrs);
936bool Instruction::isUsedOutsideOfBlock(
const BasicBlock *BB)
const {
941 const PHINode *PN = dyn_cast<PHINode>(
I);
943 if (
I->getParent() != BB)
954bool Instruction::mayReadFromMemory()
const {
956 default:
return false;
957 case Instruction::VAArg:
958 case Instruction::Load:
959 case Instruction::Fence:
960 case Instruction::AtomicCmpXchg:
961 case Instruction::AtomicRMW:
962 case Instruction::CatchPad:
963 case Instruction::CatchRet:
965 case Instruction::Call:
966 case Instruction::Invoke:
967 case Instruction::CallBr:
968 return !cast<CallBase>(
this)->onlyWritesMemory();
969 case Instruction::Store:
970 return !cast<StoreInst>(
this)->isUnordered();
974bool Instruction::mayWriteToMemory()
const {
976 default:
return false;
977 case Instruction::Fence:
978 case Instruction::Store:
979 case Instruction::VAArg:
980 case Instruction::AtomicCmpXchg:
981 case Instruction::AtomicRMW:
982 case Instruction::CatchPad:
983 case Instruction::CatchRet:
985 case Instruction::Call:
986 case Instruction::Invoke:
987 case Instruction::CallBr:
988 return !cast<CallBase>(
this)->onlyReadsMemory();
989 case Instruction::Load:
990 return !cast<LoadInst>(
this)->isUnordered();
994bool Instruction::isAtomic()
const {
998 case Instruction::AtomicCmpXchg:
999 case Instruction::AtomicRMW:
1000 case Instruction::Fence:
1002 case Instruction::Load:
1003 return cast<LoadInst>(
this)->getOrdering() != AtomicOrdering::NotAtomic;
1004 case Instruction::Store:
1005 return cast<StoreInst>(
this)->getOrdering() != AtomicOrdering::NotAtomic;
1009bool Instruction::hasAtomicLoad()
const {
1014 case Instruction::AtomicCmpXchg:
1015 case Instruction::AtomicRMW:
1016 case Instruction::Load:
1021bool Instruction::hasAtomicStore()
const {
1026 case Instruction::AtomicCmpXchg:
1027 case Instruction::AtomicRMW:
1028 case Instruction::Store:
1033bool Instruction::isVolatile()
const {
1037 case Instruction::AtomicRMW:
1038 return cast<AtomicRMWInst>(
this)->isVolatile();
1039 case Instruction::Store:
1040 return cast<StoreInst>(
this)->isVolatile();
1041 case Instruction::Load:
1042 return cast<LoadInst>(
this)->isVolatile();
1043 case Instruction::AtomicCmpXchg:
1044 return cast<AtomicCmpXchgInst>(
this)->isVolatile();
1045 case Instruction::Call:
1046 case Instruction::Invoke:
1048 if (
auto *
II = dyn_cast<IntrinsicInst>(
this)) {
1049 if (
auto *
MI = dyn_cast<MemIntrinsic>(
II))
1050 return MI->isVolatile();
1051 switch (
II->getIntrinsicID()) {
1053 case Intrinsic::matrix_column_major_load:
1054 return cast<ConstantInt>(
II->getArgOperand(2))->isOne();
1055 case Intrinsic::matrix_column_major_store:
1056 return cast<ConstantInt>(
II->getArgOperand(3))->isOne();
1063Type *Instruction::getAccessType()
const {
1065 case Instruction::Store:
1066 return cast<StoreInst>(
this)->getValueOperand()->getType();
1067 case Instruction::Load:
1068 case Instruction::AtomicRMW:
1070 case Instruction::AtomicCmpXchg:
1071 return cast<AtomicCmpXchgInst>(
this)->getNewValOperand()->getType();
1072 case Instruction::Call:
1073 case Instruction::Invoke:
1075 switch (
II->getIntrinsicID()) {
1076 case Intrinsic::masked_load:
1077 case Intrinsic::masked_gather:
1078 case Intrinsic::masked_expandload:
1079 case Intrinsic::vp_load:
1080 case Intrinsic::vp_gather:
1081 case Intrinsic::experimental_vp_strided_load:
1082 return II->getType();
1083 case Intrinsic::masked_store:
1084 case Intrinsic::masked_scatter:
1085 case Intrinsic::masked_compressstore:
1086 case Intrinsic::vp_store:
1087 case Intrinsic::vp_scatter:
1088 case Intrinsic::experimental_vp_strided_store:
1089 return II->getOperand(0)->getType();
1100 bool IncludePhaseOneUnwind) {
1104 return IncludePhaseOneUnwind;
1121bool Instruction::mayThrow(
bool IncludePhaseOneUnwind)
const {
1123 case Instruction::Call:
1124 return !cast<CallInst>(
this)->doesNotThrow();
1125 case Instruction::CleanupRet:
1126 return cast<CleanupReturnInst>(
this)->unwindsToCaller();
1127 case Instruction::CatchSwitch:
1128 return cast<CatchSwitchInst>(
this)->unwindsToCaller();
1129 case Instruction::Resume:
1131 case Instruction::Invoke: {
1134 BasicBlock *UnwindDest = cast<InvokeInst>(
this)->getUnwindDest();
1136 if (
auto *LP = dyn_cast<LandingPadInst>(Pad))
1140 case Instruction::CleanupPad:
1142 return IncludePhaseOneUnwind;
1148bool Instruction::mayHaveSideEffects()
const {
1149 return mayWriteToMemory() ||
mayThrow() || !willReturn();
1152bool Instruction::isSafeToRemove()
const {
1154 !this->isTerminator() && !this->isEHPad();
1157bool Instruction::willReturn()
const {
1159 if (
auto *
SI = dyn_cast<StoreInst>(
this))
1160 return !
SI->isVolatile();
1162 if (
const auto *CB = dyn_cast<CallBase>(
this))
1163 return CB->hasFnAttr(Attribute::WillReturn);
1167bool Instruction::isLifetimeStartOrEnd()
const {
1168 auto *
II = dyn_cast<IntrinsicInst>(
this);
1172 return ID == Intrinsic::lifetime_start ||
ID == Intrinsic::lifetime_end;
1175bool Instruction::isLaunderOrStripInvariantGroup()
const {
1176 auto *
II = dyn_cast<IntrinsicInst>(
this);
1180 return ID == Intrinsic::launder_invariant_group ||
1181 ID == Intrinsic::strip_invariant_group;
1184bool Instruction::isDebugOrPseudoInst()
const {
1185 return isa<DbgInfoIntrinsic>(
this) || isa<PseudoProbeInst>(
this);
1189Instruction::getNextNonDebugInstruction(
bool SkipPseudoOp)
const {
1191 if (!isa<DbgInfoIntrinsic>(
I) && !(SkipPseudoOp && isa<PseudoProbeInst>(
I)))
1197Instruction::getPrevNonDebugInstruction(
bool SkipPseudoOp)
const {
1199 if (!isa<DbgInfoIntrinsic>(
I) &&
1200 !(SkipPseudoOp && isa<PseudoProbeInst>(
I)) &&
1201 !(isa<IntrinsicInst>(
I) &&
1207const DebugLoc &Instruction::getStableDebugLoc()
const {
1208 if (isa<DbgInfoIntrinsic>(
this))
1209 if (
const Instruction *Next = getNextNonDebugInstruction())
1210 return Next->getDebugLoc();
1214bool Instruction::isAssociative()
const {
1215 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1216 return II->isAssociative();
1224 return cast<FPMathOperator>(
this)->hasAllowReassoc() &&
1225 cast<FPMathOperator>(
this)->hasNoSignedZeros();
1231bool Instruction::isCommutative()
const {
1232 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1233 return II->isCommutative();
1238unsigned Instruction::getNumSuccessors()
const {
1240#define HANDLE_TERM_INST(N, OPC, CLASS) \
1241 case Instruction::OPC: \
1242 return static_cast<const CLASS *>(this)->getNumSuccessors();
1243#include "llvm/IR/Instruction.def"
1250BasicBlock *Instruction::getSuccessor(
unsigned idx)
const {
1252#define HANDLE_TERM_INST(N, OPC, CLASS) \
1253 case Instruction::OPC: \
1254 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1255#include "llvm/IR/Instruction.def"
1262void Instruction::setSuccessor(
unsigned idx,
BasicBlock *
B) {
1264#define HANDLE_TERM_INST(N, OPC, CLASS) \
1265 case Instruction::OPC: \
1266 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1267#include "llvm/IR/Instruction.def"
1275 for (
unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
1276 Idx != NumSuccessors; ++
Idx)
1277 if (getSuccessor(
Idx) == OldBB)
1278 setSuccessor(
Idx, NewBB);
1285void Instruction::swapProfMetadata() {
1293 unsigned SecondIdx = FirstIdx + 1;
1298 for (
unsigned Idx = 0;
Idx < FirstIdx; ++
Idx) {
1304 setMetadata(LLVMContext::MD_prof,
1305 MDNode::get(ProfileData->
getContext(), Ops));
1308void Instruction::copyMetadata(
const Instruction &SrcInst,
1319 for (
const auto &MD : TheMDs) {
1320 if (WL.
empty() ||
WLS.count(MD.first))
1321 setMetadata(MD.first, MD.second);
1323 if (WL.
empty() ||
WLS.count(LLVMContext::MD_dbg))
1332#define HANDLE_INST(num, opc, clas) \
1333 case Instruction::opc: \
1334 New = cast<clas>(this)->cloneImpl(); \
1336#include "llvm/IR/Instruction.def"
1340 New->SubclassOptionalData = SubclassOptionalData;
1341 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.
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
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.
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.
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.