37 "profcheck-disable-metadata-fixes", cl::Hidden, cl::init(
false),
39 "Disable metadata propagation fixes discovered through Issue #147390"));
41InsertPosition::InsertPosition(
Instruction *InsertBefore)
42 : InsertAt(InsertBefore ? InsertBefore->getIterator()
43 : InstListType::iterator()) {}
44InsertPosition::InsertPosition(
BasicBlock *InsertAtEnd)
45 : InsertAt(InsertAtEnd ? InsertAtEnd->
end() : InstListType::iterator()) {}
51 if (InstListType::iterator InsertIt = InsertBefore; InsertIt.isValid()) {
53 assert(BB &&
"Instruction to insert before is not in a basic block!");
54 insertInto(BB, InsertBefore);
58Instruction::~Instruction() {
70 if (isUsedByMetadata())
71 ValueAsMetadata::handleRAUW(
this, PoisonValue::get(
getType()));
75 setMetadata(LLVMContext::MD_DIAssignID,
nullptr);
78const Module *Instruction::getModule()
const {
82const Function *Instruction::getFunction()
const {
86const DataLayout &Instruction::getDataLayout()
const {
87 return getModule()->getDataLayout();
90void Instruction::removeFromParent() {
92 handleMarkerRemoval();
94 getParent()->getInstList().remove(getIterator());
97void Instruction::handleMarkerRemoval() {
101 DebugMarker->removeMarker();
105 handleMarkerRemoval();
106 return getParent()->getInstList().erase(getIterator());
109void Instruction::insertBefore(
Instruction *InsertPos) {
116 insertBefore(*InsertPos->getParent(), InsertPos);
121void Instruction::insertAfter(
Instruction *InsertPos) {
130 DestParent->getInstList().
insertAfter(InsertPos,
this);
136 assert((It == ParentBB->
end() || It->getParent() == ParentBB) &&
137 "It not in ParentBB");
138 insertBefore(*ParentBB, It);
139 return getIterator();
143 InstListType::iterator InsertPos) {
146 BB.getInstList().
insert(InsertPos,
this);
151 bool InsertAtHead = InsertPos.getHeadBit();
154 if (SrcMarker && !SrcMarker->
empty()) {
166 assert(!isa<PHINode>(
this) &&
"Inserting PHI after debug-records!");
167 adoptDbgRecords(&BB, InsertPos,
false);
175 getParent()->flushTerminatorDbgRecords();
180void Instruction::moveBefore(
Instruction *MovePos) {
185 moveBeforeImpl(*MovePos->getParent(), MovePos,
false);
188void Instruction::moveBeforePreserving(
Instruction *MovePos) {
193 moveBeforeImpl(*MovePos->getParent(), MovePos,
true);
200 NextIt.setHeadBit(
true);
201 moveBeforeImpl(*MovePos->
getParent(), NextIt,
false);
204void Instruction::moveAfter(InstListType::iterator MovePos) {
207 MovePos.setHeadBit(
true);
208 moveBeforeImpl(*MovePos->getParent(), MovePos,
false);
211void Instruction::moveAfterPreserving(
Instruction *MovePos) {
215 NextIt.setHeadBit(
true);
216 moveBeforeImpl(*MovePos->
getParent(), NextIt,
true);
219void Instruction::moveBefore(
BasicBlock &BB, InstListType::iterator
I) {
220 moveBeforeImpl(BB,
I,
false);
223void Instruction::moveBeforePreserving(
BasicBlock &BB,
224 InstListType::iterator
I) {
225 moveBeforeImpl(BB,
I,
true);
228void Instruction::moveBeforeImpl(
BasicBlock &BB, InstListType::iterator
I,
231 bool InsertAtHead =
I.getHeadBit();
235 if (DebugMarker && !Preserve) {
236 if (
I != this->getIterator() || InsertAtHead) {
239 handleMarkerRemoval();
252 if (!InsertAtHead && NextMarker && !NextMarker->
empty()) {
253 adoptDbgRecords(&BB,
I,
false);
258 getParent()->flushTerminatorDbgRecords();
262 const Instruction *
From, std::optional<DbgRecord::self_iterator> FromHere,
264 if (!
From->DebugMarker)
265 return DbgMarker::getEmptyDbgRecordRange();
270 return DebugMarker->cloneDebugInfoFrom(
From->DebugMarker, FromHere,
274std::optional<DbgRecord::self_iterator>
275Instruction::getDbgReinsertionPosition() {
293 auto ReleaseTrailingDbgRecords = [BB, It, SrcMarker]() {
294 if (BB->
end() == It) {
301 ReleaseTrailingDbgRecords();
308 if (DebugMarker || It == BB->
end()) {
311 DebugMarker->absorbDebugValues(*SrcMarker, InsertAtHead);
322 ReleaseTrailingDbgRecords();
327 DebugMarker = SrcMarker;
333void Instruction::dropDbgRecords() {
338void Instruction::dropOneDbgRecord(
DbgRecord *DVR) {
339 DebugMarker->dropOneDbgRecord(DVR);
344 "instructions without BB parents have no order");
346 "cross-BB instruction order comparison");
349 return Order <
Other->Order;
352std::optional<BasicBlock::iterator> Instruction::getInsertionPointAfterDef() {
353 assert(!
getType()->isVoidTy() &&
"Instruction must define result");
356 if (
auto *PN = dyn_cast<PHINode>(
this)) {
359 }
else if (
auto *
II = dyn_cast<InvokeInst>(
this)) {
360 InsertBB =
II->getNormalDest();
362 }
else if (isa<CallBrInst>(
this)) {
367 assert(!isTerminator() &&
"Only invoke/callbr terminators return value");
369 InsertPt = std::next(getIterator());
373 InsertPt.setHeadBit(
true);
378 if (InsertPt == InsertBB->
end())
383bool Instruction::isOnlyUserOfAnyOperand() {
384 return any_of(operands(), [](
const Value *V) {
return V->hasOneUser(); });
387void Instruction::setHasNoUnsignedWrap(
bool b) {
388 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
389 Inst->setHasNoUnsignedWrap(b);
391 cast<TruncInst>(
this)->setHasNoUnsignedWrap(b);
394void Instruction::setHasNoSignedWrap(
bool b) {
395 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
396 Inst->setHasNoSignedWrap(b);
398 cast<TruncInst>(
this)->setHasNoSignedWrap(b);
401void Instruction::setIsExact(
bool b) {
402 cast<PossiblyExactOperator>(
this)->setIsExact(b);
405void Instruction::setNonNeg(
bool b) {
406 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
408 (b * PossiblyNonNegInst::NonNeg);
411bool Instruction::hasNoUnsignedWrap()
const {
412 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
413 return Inst->hasNoUnsignedWrap();
415 return cast<TruncInst>(
this)->hasNoUnsignedWrap();
418bool Instruction::hasNoSignedWrap()
const {
419 if (
auto *Inst = dyn_cast<OverflowingBinaryOperator>(
this))
420 return Inst->hasNoSignedWrap();
422 return cast<TruncInst>(
this)->hasNoSignedWrap();
425bool Instruction::hasNonNeg()
const {
426 assert(isa<PossiblyNonNegInst>(
this) &&
"Must be zext/uitofp");
427 return (SubclassOptionalData & PossiblyNonNegInst::NonNeg) != 0;
430bool Instruction::hasPoisonGeneratingFlags()
const {
431 return cast<Operator>(
this)->hasPoisonGeneratingFlags();
434void Instruction::dropPoisonGeneratingFlags() {
436 case Instruction::Add:
437 case Instruction::Sub:
438 case Instruction::Mul:
439 case Instruction::Shl:
440 cast<OverflowingBinaryOperator>(
this)->setHasNoUnsignedWrap(
false);
441 cast<OverflowingBinaryOperator>(
this)->setHasNoSignedWrap(
false);
444 case Instruction::UDiv:
445 case Instruction::SDiv:
446 case Instruction::AShr:
447 case Instruction::LShr:
448 cast<PossiblyExactOperator>(
this)->setIsExact(
false);
451 case Instruction::Or:
452 cast<PossiblyDisjointInst>(
this)->setIsDisjoint(
false);
455 case Instruction::GetElementPtr:
456 cast<GetElementPtrInst>(
this)->setNoWrapFlags(GEPNoWrapFlags::none());
459 case Instruction::UIToFP:
460 case Instruction::ZExt:
464 case Instruction::Trunc:
465 cast<TruncInst>(
this)->setHasNoUnsignedWrap(
false);
466 cast<TruncInst>(
this)->setHasNoSignedWrap(
false);
469 case Instruction::ICmp:
470 cast<ICmpInst>(
this)->setSameSign(
false);
474 if (isa<FPMathOperator>(
this)) {
479 assert(!hasPoisonGeneratingFlags() &&
"must be kept in sync");
482bool Instruction::hasPoisonGeneratingMetadata()
const {
483 return any_of(Metadata::PoisonGeneratingIDs,
484 [
this](
unsigned ID) {
return hasMetadata(
ID); });
487bool Instruction::hasNonDebugLocLoopMetadata()
const {
490 if (!hasMetadata(LLVMContext::MD_loop))
494 MDNode *LoopMD = getMetadata(LLVMContext::MD_loop);
501 if (!isa<DILocation>(
Op)) {
510void Instruction::dropPoisonGeneratingMetadata() {
511 for (
unsigned ID : Metadata::PoisonGeneratingIDs)
515bool Instruction::hasPoisonGeneratingReturnAttributes()
const {
516 if (
const auto *CB = dyn_cast<CallBase>(
this)) {
517 AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
525void Instruction::dropPoisonGeneratingReturnAttributes() {
526 if (
auto *CB = dyn_cast<CallBase>(
this)) {
531 CB->removeRetAttrs(AM);
533 assert(!hasPoisonGeneratingReturnAttributes() &&
"must be kept in sync");
536void Instruction::dropUBImplyingAttrsAndUnknownMetadata(
538 dropUnknownNonDebugMetadata(KnownIDs);
539 auto *CB = dyn_cast<CallBase>(
this);
549 AttributeFuncs::getUBImplyingAttributes();
550 for (
unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
551 CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
552 CB->removeRetAttrs(UBImplyingAttributes);
560 static const unsigned KnownIDs[] = {
561 LLVMContext::MD_annotation, LLVMContext::MD_range,
562 LLVMContext::MD_nonnull, LLVMContext::MD_align};
564 KeepIDs.
reserve(
Keep.size() + std::size(KnownIDs));
567 dropUBImplyingAttrsAndUnknownMetadata(KeepIDs);
570bool Instruction::hasUBImplyingAttrs()
const {
571 auto *CB = dyn_cast<CallBase>(
this);
576 for (
unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
577 if (CB->isPassingUndefUB(ArgNo))
579 return CB->hasRetAttr(Attribute::NoUndef) ||
580 CB->hasRetAttr(Attribute::Dereferenceable) ||
581 CB->hasRetAttr(Attribute::DereferenceableOrNull);
584bool Instruction::isExact()
const {
585 return cast<PossiblyExactOperator>(
this)->isExact();
588void Instruction::setFast(
bool B) {
589 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
590 cast<FPMathOperator>(
this)->setFast(
B);
593void Instruction::setHasAllowReassoc(
bool B) {
594 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
595 cast<FPMathOperator>(
this)->setHasAllowReassoc(
B);
598void Instruction::setHasNoNaNs(
bool B) {
599 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
600 cast<FPMathOperator>(
this)->setHasNoNaNs(
B);
603void Instruction::setHasNoInfs(
bool B) {
604 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
605 cast<FPMathOperator>(
this)->setHasNoInfs(
B);
608void Instruction::setHasNoSignedZeros(
bool B) {
609 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
610 cast<FPMathOperator>(
this)->setHasNoSignedZeros(
B);
613void Instruction::setHasAllowReciprocal(
bool B) {
614 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
615 cast<FPMathOperator>(
this)->setHasAllowReciprocal(
B);
618void Instruction::setHasAllowContract(
bool B) {
619 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
620 cast<FPMathOperator>(
this)->setHasAllowContract(
B);
623void Instruction::setHasApproxFunc(
bool B) {
624 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
625 cast<FPMathOperator>(
this)->setHasApproxFunc(
B);
629 assert(isa<FPMathOperator>(
this) &&
"setting fast-math flag on invalid op");
630 cast<FPMathOperator>(
this)->setFastMathFlags(FMF);
634 assert(isa<FPMathOperator>(
this) &&
"copying fast-math flag on invalid op");
635 cast<FPMathOperator>(
this)->copyFastMathFlags(FMF);
638bool Instruction::isFast()
const {
639 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
640 return cast<FPMathOperator>(
this)->isFast();
643bool Instruction::hasAllowReassoc()
const {
644 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
645 return cast<FPMathOperator>(
this)->hasAllowReassoc();
648bool Instruction::hasNoNaNs()
const {
649 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
650 return cast<FPMathOperator>(
this)->hasNoNaNs();
653bool Instruction::hasNoInfs()
const {
654 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
655 return cast<FPMathOperator>(
this)->hasNoInfs();
658bool Instruction::hasNoSignedZeros()
const {
659 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
660 return cast<FPMathOperator>(
this)->hasNoSignedZeros();
663bool Instruction::hasAllowReciprocal()
const {
664 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
665 return cast<FPMathOperator>(
this)->hasAllowReciprocal();
668bool Instruction::hasAllowContract()
const {
669 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
670 return cast<FPMathOperator>(
this)->hasAllowContract();
673bool Instruction::hasApproxFunc()
const {
674 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
675 return cast<FPMathOperator>(
this)->hasApproxFunc();
679 assert(isa<FPMathOperator>(
this) &&
"getting fast-math flag on invalid op");
680 return cast<FPMathOperator>(
this)->getFastMathFlags();
683void Instruction::copyFastMathFlags(
const Instruction *
I) {
684 copyFastMathFlags(
I->getFastMathFlags());
687void Instruction::copyIRFlags(
const Value *V,
bool IncludeWrapFlags) {
689 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(
this)) {
690 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
691 setHasNoSignedWrap(
OB->hasNoSignedWrap());
692 setHasNoUnsignedWrap(
OB->hasNoUnsignedWrap());
696 if (
auto *TI = dyn_cast<TruncInst>(V)) {
697 if (isa<TruncInst>(
this)) {
698 setHasNoSignedWrap(TI->hasNoSignedWrap());
699 setHasNoUnsignedWrap(TI->hasNoUnsignedWrap());
704 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
705 if (isa<PossiblyExactOperator>(
this))
706 setIsExact(PE->isExact());
708 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
709 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
710 DestPD->setIsDisjoint(SrcPD->isDisjoint());
713 if (
auto *
FP = dyn_cast<FPMathOperator>(V))
714 if (isa<FPMathOperator>(
this))
715 copyFastMathFlags(
FP->getFastMathFlags());
717 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
718 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
719 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() |
720 DestGEP->getNoWrapFlags());
722 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
723 if (isa<PossiblyNonNegInst>(
this))
724 setNonNeg(NNI->hasNonNeg());
726 if (
auto *SrcICmp = dyn_cast<ICmpInst>(V))
727 if (
auto *DestICmp = dyn_cast<ICmpInst>(
this))
728 DestICmp->setSameSign(SrcICmp->hasSameSign());
731void Instruction::andIRFlags(
const Value *V) {
732 if (
auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
733 if (isa<OverflowingBinaryOperator>(
this)) {
739 if (
auto *TI = dyn_cast<TruncInst>(V)) {
740 if (isa<TruncInst>(
this)) {
746 if (
auto *PE = dyn_cast<PossiblyExactOperator>(V))
747 if (isa<PossiblyExactOperator>(
this))
748 setIsExact(isExact() && PE->isExact());
750 if (
auto *SrcPD = dyn_cast<PossiblyDisjointInst>(V))
751 if (
auto *DestPD = dyn_cast<PossiblyDisjointInst>(
this))
752 DestPD->setIsDisjoint(DestPD->isDisjoint() && SrcPD->isDisjoint());
754 if (
auto *
FP = dyn_cast<FPMathOperator>(V)) {
755 if (isa<FPMathOperator>(
this)) {
757 FM &=
FP->getFastMathFlags();
758 copyFastMathFlags(FM);
762 if (
auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
763 if (
auto *DestGEP = dyn_cast<GetElementPtrInst>(
this))
764 DestGEP->setNoWrapFlags(SrcGEP->getNoWrapFlags() &
765 DestGEP->getNoWrapFlags());
767 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(V))
768 if (isa<PossiblyNonNegInst>(
this))
769 setNonNeg(hasNonNeg() && NNI->hasNonNeg());
771 if (
auto *SrcICmp = dyn_cast<ICmpInst>(V))
772 if (
auto *DestICmp = dyn_cast<ICmpInst>(
this))
773 DestICmp->setSameSign(DestICmp->hasSameSign() && SrcICmp->hasSameSign());
776const char *Instruction::getOpcodeName(
unsigned OpCode) {
779 case Ret:
return "ret";
780 case Br:
return "br";
781 case Switch:
return "switch";
782 case IndirectBr:
return "indirectbr";
783 case Invoke:
return "invoke";
784 case Resume:
return "resume";
785 case Unreachable:
return "unreachable";
786 case CleanupRet:
return "cleanupret";
787 case CatchRet:
return "catchret";
788 case CatchPad:
return "catchpad";
789 case CatchSwitch:
return "catchswitch";
790 case CallBr:
return "callbr";
793 case FNeg:
return "fneg";
796 case Add:
return "add";
797 case FAdd:
return "fadd";
798 case Sub:
return "sub";
799 case FSub:
return "fsub";
800 case Mul:
return "mul";
801 case FMul:
return "fmul";
802 case UDiv:
return "udiv";
803 case SDiv:
return "sdiv";
804 case FDiv:
return "fdiv";
805 case URem:
return "urem";
806 case SRem:
return "srem";
807 case FRem:
return "frem";
810 case And:
return "and";
811 case Or :
return "or";
812 case Xor:
return "xor";
815 case Alloca:
return "alloca";
816 case Load:
return "load";
817 case Store:
return "store";
818 case AtomicCmpXchg:
return "cmpxchg";
819 case AtomicRMW:
return "atomicrmw";
820 case Fence:
return "fence";
821 case GetElementPtr:
return "getelementptr";
824 case Trunc:
return "trunc";
825 case ZExt:
return "zext";
826 case SExt:
return "sext";
827 case FPTrunc:
return "fptrunc";
828 case FPExt:
return "fpext";
829 case FPToUI:
return "fptoui";
830 case FPToSI:
return "fptosi";
831 case UIToFP:
return "uitofp";
832 case SIToFP:
return "sitofp";
833 case IntToPtr:
return "inttoptr";
834 case PtrToAddr:
return "ptrtoaddr";
835 case PtrToInt:
return "ptrtoint";
836 case BitCast:
return "bitcast";
837 case AddrSpaceCast:
return "addrspacecast";
840 case ICmp:
return "icmp";
841 case FCmp:
return "fcmp";
842 case PHI:
return "phi";
843 case Select:
return "select";
844 case Call:
return "call";
845 case Shl:
return "shl";
846 case LShr:
return "lshr";
847 case AShr:
return "ashr";
848 case VAArg:
return "va_arg";
849 case ExtractElement:
return "extractelement";
850 case InsertElement:
return "insertelement";
851 case ShuffleVector:
return "shufflevector";
852 case ExtractValue:
return "extractvalue";
853 case InsertValue:
return "insertvalue";
854 case LandingPad:
return "landingpad";
855 case CleanupPad:
return "cleanuppad";
856 case Freeze:
return "freeze";
858 default:
return "<Invalid operator> ";
864bool Instruction::hasSameSpecialState(
const Instruction *I2,
865 bool IgnoreAlignment,
866 bool IntersectAttrs)
const {
869 "Can not compare special state of different instructions");
871 auto CheckAttrsSame = [IntersectAttrs](
const CallBase *CB0,
873 return IntersectAttrs
880 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
881 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
882 (AI->getAlign() == cast<AllocaInst>(I2)->getAlign() ||
884 if (
const LoadInst *LI = dyn_cast<LoadInst>(I1))
885 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
886 (LI->getAlign() == cast<LoadInst>(I2)->getAlign() ||
888 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
889 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
891 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
892 (
SI->getAlign() == cast<StoreInst>(I2)->getAlign() ||
894 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
895 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
896 if (
const CmpInst *CI = dyn_cast<CmpInst>(I1))
897 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
898 if (
const CallInst *CI = dyn_cast<CallInst>(I1))
899 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
900 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
901 CheckAttrsSame(CI, cast<CallInst>(I2)) &&
902 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
903 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
904 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
905 CheckAttrsSame(CI, cast<InvokeInst>(I2)) &&
906 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
907 if (
const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
908 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
909 CheckAttrsSame(CI, cast<CallBrInst>(I2)) &&
910 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
912 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
914 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
915 if (
const FenceInst *FI = dyn_cast<FenceInst>(I1))
916 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
917 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
919 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
920 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
921 CXI->getSuccessOrdering() ==
922 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
923 CXI->getFailureOrdering() ==
924 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
925 CXI->getSyncScopeID() ==
926 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
928 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
929 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
930 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
931 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
933 return SVI->getShuffleMask() ==
934 cast<ShuffleVectorInst>(I2)->getShuffleMask();
936 return GEP->getSourceElementType() ==
937 cast<GetElementPtrInst>(I2)->getSourceElementType();
942bool Instruction::isIdenticalTo(
const Instruction *
I)
const {
943 return isIdenticalToWhenDefined(
I) &&
944 SubclassOptionalData ==
I->SubclassOptionalData;
947bool Instruction::isIdenticalToWhenDefined(
const Instruction *
I,
948 bool IntersectAttrs)
const {
950 getNumOperands() !=
I->getNumOperands() ||
getType() !=
I->getType())
954 if (getNumOperands() == 0 &&
I->getNumOperands() == 0)
955 return this->hasSameSpecialState(
I,
false,
960 if (!
equal(operands(),
I->operands()))
964 if (
const PHINode *Phi = dyn_cast<PHINode>(
this)) {
965 const PHINode *OtherPhi = cast<PHINode>(
I);
969 return this->hasSameSpecialState(
I,
false,
975bool Instruction::isSameOperationAs(
const Instruction *
I,
976 unsigned flags)
const {
977 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
978 bool UseScalarTypes = flags & CompareUsingScalarTypes;
979 bool IntersectAttrs = flags & CompareUsingIntersectedAttrs;
982 getNumOperands() !=
I->getNumOperands() ||
984 getType()->getScalarType() !=
I->getType()->getScalarType() :
990 for (
unsigned i = 0, e = getNumOperands(); i !=
e; ++i)
992 getOperand(i)->
getType()->getScalarType() !=
993 I->getOperand(i)->getType()->getScalarType() :
994 getOperand(i)->
getType() !=
I->getOperand(i)->getType())
997 return this->hasSameSpecialState(
I, IgnoreAlignment, IntersectAttrs);
1000bool Instruction::isUsedOutsideOfBlock(
const BasicBlock *BB)
const {
1005 const PHINode *PN = dyn_cast<PHINode>(
I);
1007 if (
I->getParent() != BB)
1018bool Instruction::mayReadFromMemory()
const {
1020 default:
return false;
1021 case Instruction::VAArg:
1022 case Instruction::Load:
1023 case Instruction::Fence:
1024 case Instruction::AtomicCmpXchg:
1025 case Instruction::AtomicRMW:
1026 case Instruction::CatchPad:
1027 case Instruction::CatchRet:
1029 case Instruction::Call:
1030 case Instruction::Invoke:
1031 case Instruction::CallBr:
1032 return !cast<CallBase>(
this)->onlyWritesMemory();
1033 case Instruction::Store:
1034 return !cast<StoreInst>(
this)->isUnordered();
1038bool Instruction::mayWriteToMemory()
const {
1040 default:
return false;
1041 case Instruction::Fence:
1042 case Instruction::Store:
1043 case Instruction::VAArg:
1044 case Instruction::AtomicCmpXchg:
1045 case Instruction::AtomicRMW:
1046 case Instruction::CatchPad:
1047 case Instruction::CatchRet:
1049 case Instruction::Call:
1050 case Instruction::Invoke:
1051 case Instruction::CallBr:
1052 return !cast<CallBase>(
this)->onlyReadsMemory();
1053 case Instruction::Load:
1054 return !cast<LoadInst>(
this)->isUnordered();
1058bool Instruction::isAtomic()
const {
1062 case Instruction::AtomicCmpXchg:
1063 case Instruction::AtomicRMW:
1064 case Instruction::Fence:
1066 case Instruction::Load:
1067 return cast<LoadInst>(
this)->getOrdering() != AtomicOrdering::NotAtomic;
1068 case Instruction::Store:
1069 return cast<StoreInst>(
this)->getOrdering() != AtomicOrdering::NotAtomic;
1073bool Instruction::hasAtomicLoad()
const {
1078 case Instruction::AtomicCmpXchg:
1079 case Instruction::AtomicRMW:
1080 case Instruction::Load:
1085bool Instruction::hasAtomicStore()
const {
1090 case Instruction::AtomicCmpXchg:
1091 case Instruction::AtomicRMW:
1092 case Instruction::Store:
1097bool Instruction::isVolatile()
const {
1101 case Instruction::AtomicRMW:
1102 return cast<AtomicRMWInst>(
this)->isVolatile();
1103 case Instruction::Store:
1104 return cast<StoreInst>(
this)->isVolatile();
1105 case Instruction::Load:
1106 return cast<LoadInst>(
this)->isVolatile();
1107 case Instruction::AtomicCmpXchg:
1108 return cast<AtomicCmpXchgInst>(
this)->isVolatile();
1109 case Instruction::Call:
1110 case Instruction::Invoke:
1112 if (
auto *
II = dyn_cast<IntrinsicInst>(
this)) {
1113 if (
auto *
MI = dyn_cast<MemIntrinsic>(
II))
1114 return MI->isVolatile();
1115 switch (
II->getIntrinsicID()) {
1117 case Intrinsic::matrix_column_major_load:
1118 return cast<ConstantInt>(
II->getArgOperand(2))->isOne();
1119 case Intrinsic::matrix_column_major_store:
1120 return cast<ConstantInt>(
II->getArgOperand(3))->isOne();
1127Type *Instruction::getAccessType()
const {
1129 case Instruction::Store:
1130 return cast<StoreInst>(
this)->getValueOperand()->getType();
1131 case Instruction::Load:
1132 case Instruction::AtomicRMW:
1134 case Instruction::AtomicCmpXchg:
1135 return cast<AtomicCmpXchgInst>(
this)->getNewValOperand()->getType();
1136 case Instruction::Call:
1137 case Instruction::Invoke:
1139 switch (
II->getIntrinsicID()) {
1140 case Intrinsic::masked_load:
1141 case Intrinsic::masked_gather:
1142 case Intrinsic::masked_expandload:
1143 case Intrinsic::vp_load:
1144 case Intrinsic::vp_gather:
1145 case Intrinsic::experimental_vp_strided_load:
1146 return II->getType();
1147 case Intrinsic::masked_store:
1148 case Intrinsic::masked_scatter:
1149 case Intrinsic::masked_compressstore:
1150 case Intrinsic::vp_store:
1151 case Intrinsic::vp_scatter:
1152 case Intrinsic::experimental_vp_strided_store:
1153 return II->getOperand(0)->getType();
1164 bool IncludePhaseOneUnwind) {
1168 return IncludePhaseOneUnwind;
1185bool Instruction::mayThrow(
bool IncludePhaseOneUnwind)
const {
1187 case Instruction::Call:
1188 return !cast<CallInst>(
this)->doesNotThrow();
1189 case Instruction::CleanupRet:
1190 return cast<CleanupReturnInst>(
this)->unwindsToCaller();
1191 case Instruction::CatchSwitch:
1192 return cast<CatchSwitchInst>(
this)->unwindsToCaller();
1193 case Instruction::Resume:
1195 case Instruction::Invoke: {
1198 BasicBlock *UnwindDest = cast<InvokeInst>(
this)->getUnwindDest();
1200 if (
auto *LP = dyn_cast<LandingPadInst>(Pad))
1204 case Instruction::CleanupPad:
1206 return IncludePhaseOneUnwind;
1212bool Instruction::mayHaveSideEffects()
const {
1213 return mayWriteToMemory() ||
mayThrow() || !willReturn();
1216bool Instruction::isSafeToRemove()
const {
1218 !this->isTerminator() && !this->isEHPad();
1221bool Instruction::willReturn()
const {
1223 if (
auto *
SI = dyn_cast<StoreInst>(
this))
1224 return !
SI->isVolatile();
1226 if (
const auto *CB = dyn_cast<CallBase>(
this))
1227 return CB->hasFnAttr(Attribute::WillReturn);
1231bool Instruction::isLifetimeStartOrEnd()
const {
1232 auto *
II = dyn_cast<IntrinsicInst>(
this);
1236 return ID == Intrinsic::lifetime_start ||
ID == Intrinsic::lifetime_end;
1239bool Instruction::isLaunderOrStripInvariantGroup()
const {
1240 auto *
II = dyn_cast<IntrinsicInst>(
this);
1244 return ID == Intrinsic::launder_invariant_group ||
1245 ID == Intrinsic::strip_invariant_group;
1248bool Instruction::isDebugOrPseudoInst()
const {
1249 return isa<DbgInfoIntrinsic>(
this) || isa<PseudoProbeInst>(
this);
1252const DebugLoc &Instruction::getStableDebugLoc()
const {
1256bool Instruction::isAssociative()
const {
1257 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1258 return II->isAssociative();
1266 return cast<FPMathOperator>(
this)->hasAllowReassoc() &&
1267 cast<FPMathOperator>(
this)->hasNoSignedZeros();
1273bool Instruction::isCommutative()
const {
1274 if (
auto *
II = dyn_cast<IntrinsicInst>(
this))
1275 return II->isCommutative();
1280unsigned Instruction::getNumSuccessors()
const {
1282#define HANDLE_TERM_INST(N, OPC, CLASS) \
1283 case Instruction::OPC: \
1284 return static_cast<const CLASS *>(this)->getNumSuccessors();
1285#include "llvm/IR/Instruction.def"
1292BasicBlock *Instruction::getSuccessor(
unsigned idx)
const {
1294#define HANDLE_TERM_INST(N, OPC, CLASS) \
1295 case Instruction::OPC: \
1296 return static_cast<const CLASS *>(this)->getSuccessor(idx);
1297#include "llvm/IR/Instruction.def"
1304void Instruction::setSuccessor(
unsigned idx,
BasicBlock *
B) {
1306#define HANDLE_TERM_INST(N, OPC, CLASS) \
1307 case Instruction::OPC: \
1308 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
1309#include "llvm/IR/Instruction.def"
1317 for (
unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
1318 Idx != NumSuccessors; ++
Idx)
1319 if (getSuccessor(
Idx) == OldBB)
1320 setSuccessor(
Idx, NewBB);
1327void Instruction::swapProfMetadata() {
1335 unsigned SecondIdx = FirstIdx + 1;
1340 for (
unsigned Idx = 0;
Idx < FirstIdx; ++
Idx) {
1346 setMetadata(LLVMContext::MD_prof,
1347 MDNode::get(ProfileData->
getContext(), Ops));
1350void Instruction::copyMetadata(
const Instruction &SrcInst,
1364 for (
const auto &MD : TheMDs) {
1365 if (WL.
empty() ||
WLS.count(MD.first))
1366 setMetadata(MD.first, MD.second);
1375#define HANDLE_INST(num, opc, clas) \
1376 case Instruction::opc: \
1377 New = cast<clas>(this)->cloneImpl(); \
1379#include "llvm/IR/Instruction.def"
1383 New->SubclassOptionalData = SubclassOptionalData;
1384 New->copyMetadata(*
this);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
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)
This file contains the declarations for profiling metadata utility functions.
static bool mayHaveSideEffects(MachineInstr &MI)
static bool isCommutative(Instruction *I, Value *ValWithUses)
static bool canUnwindPastLandingPad(const LandingPadInst *LP, bool IncludePhaseOneUnwind)
cl::opt< bool > ProfcheckDisableMetadataFixes("profcheck-disable-metadata-fixes", cl::Hidden, cl::init(false), cl::desc("Disable metadata propagation fixes discovered through Issue #147390"))
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,...
LLVM_ABI AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
LLVM_ABI 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.
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
LLVM Basic Block Representation.
LLVM_ABI void deleteTrailingDbgRecords()
Delete any trailing DbgRecords at the end of this block, see setTrailingDbgRecords.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator 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.
LLVM_ABI 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...
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.
LLVM_ABI void dropDbgRecords()
Erase all DbgRecords in this DbgMarker.
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
LLVM_ABI void eraseFromParent()
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc orElse(DebugLoc Other) const
If this DebugLoc is non-empty, returns this DebugLoc; otherwise, selects Other.
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.
iterator_range< const_block_iterator > blocks() 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 reserve(size_type N)
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.
LLVM_ABI 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...
NodeAddr< PhiNode * > Phi
LLVM_ABI 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.
LLVM_ABI unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
LLVM_ABI MDNode * getBranchWeightMDNode(const Instruction &I)
Get the branch weights metadata node.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
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.
@ Xor
Bitwise or logical XOR of integers.
@ Sub
Subtraction of integers.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
@ Keep
No function return thunk.
Summary of memprof metadata on allocations.