LLVM 23.0.0git
IntrinsicInst.cpp
Go to the documentation of this file.
1//===-- IntrinsicInst.cpp - Intrinsic Instruction Wrappers ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements methods that make it really easy to deal with intrinsic
10// functions.
11//
12// All intrinsic function calls are instances of the call instruction, so these
13// are all subclasses of the CallInst class. Note that none of these classes
14// has state or virtual methods, which is an important part of this gross/neat
15// hack working.
16//
17// In some cases, arguments to intrinsics need to be generic and are defined as
18// type pointer to empty struct { }*. To access the real item of interest the
19// cast instruction needs to be stripped away.
20//
21//===----------------------------------------------------------------------===//
22
25#include "llvm/IR/Constants.h"
27#include "llvm/IR/Metadata.h"
28#include "llvm/IR/Module.h"
29#include "llvm/IR/Operator.h"
31#include "llvm/IR/Statepoint.h"
32#include <optional>
33
34using namespace llvm;
35
37 switch (IID) {
38 case Intrinsic::objc_autorelease:
39 case Intrinsic::objc_autoreleasePoolPop:
40 case Intrinsic::objc_autoreleasePoolPush:
41 case Intrinsic::objc_autoreleaseReturnValue:
42 case Intrinsic::objc_claimAutoreleasedReturnValue:
43 case Intrinsic::objc_copyWeak:
44 case Intrinsic::objc_destroyWeak:
45 case Intrinsic::objc_initWeak:
46 case Intrinsic::objc_loadWeak:
47 case Intrinsic::objc_loadWeakRetained:
48 case Intrinsic::objc_moveWeak:
49 case Intrinsic::objc_release:
50 case Intrinsic::objc_retain:
51 case Intrinsic::objc_retainAutorelease:
52 case Intrinsic::objc_retainAutoreleaseReturnValue:
53 case Intrinsic::objc_retainAutoreleasedReturnValue:
54 case Intrinsic::objc_retainBlock:
55 case Intrinsic::objc_storeStrong:
56 case Intrinsic::objc_storeWeak:
57 case Intrinsic::objc_unsafeClaimAutoreleasedReturnValue:
58 case Intrinsic::objc_retainedObject:
59 case Intrinsic::objc_unretainedObject:
60 case Intrinsic::objc_unretainedPointer:
61 case Intrinsic::objc_retain_autorelease:
62 case Intrinsic::objc_sync_enter:
63 case Intrinsic::objc_sync_exit:
64 return true;
65 default:
66 return false;
67 }
68}
69
70//===----------------------------------------------------------------------===//
71/// DbgVariableIntrinsic - This is the common base class for debug info
72/// intrinsics for variables.
73///
74
77 assert(MD && "First operand of DbgVariableIntrinsic should be non-null.");
78 // If operand is ValueAsMetadata, return a range over just that operand.
79 if (auto *VAM = dyn_cast<ValueAsMetadata>(MD)) {
80 return {location_op_iterator(VAM), location_op_iterator(VAM + 1)};
81 }
82 // If operand is DIArgList, return a range over its args.
83 if (auto *AL = dyn_cast<DIArgList>(MD))
84 return {location_op_iterator(AL->args_begin()),
85 location_op_iterator(AL->args_end())};
86 // Operand must be an empty metadata tuple, so return empty iterator.
87 return {location_op_iterator(static_cast<ValueAsMetadata *>(nullptr)),
88 location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
89}
90
95
99
101 Metadata *MD = getRawLocation();
102 assert(MD && "First operand of DbgVariableIntrinsic should be non-null.");
103 if (auto *AL = dyn_cast<DIArgList>(MD))
104 return AL->getArgs()[OpIdx]->getValue();
105 if (isa<MDNode>(MD))
106 return nullptr;
107 assert(
109 "Attempted to get location operand from DbgVariableIntrinsic with none.");
110 auto *V = cast<ValueAsMetadata>(MD);
111 assert(OpIdx == 0 && "Operand Index must be 0 for a debug intrinsic with a "
112 "single location operand.");
113 return V->getValue();
114}
115
121
123 Value *NewValue,
124 bool AllowEmpty) {
125 // If OldValue is used as the address part of a dbg.assign intrinsic replace
126 // it with NewValue and return true.
127 auto ReplaceDbgAssignAddress = [this, OldValue, NewValue]() -> bool {
128 auto *DAI = dyn_cast<DbgAssignIntrinsic>(this);
129 if (!DAI || OldValue != DAI->getAddress())
130 return false;
131 DAI->setAddress(NewValue);
132 return true;
133 };
134 bool DbgAssignAddrReplaced = ReplaceDbgAssignAddress();
135 (void)DbgAssignAddrReplaced;
136
137 assert(NewValue && "Values must be non-null");
138 auto Locations = location_ops();
139 auto OldIt = find(Locations, OldValue);
140 if (OldIt == Locations.end()) {
141 if (AllowEmpty || DbgAssignAddrReplaced)
142 return;
143 assert(DbgAssignAddrReplaced &&
144 "OldValue must be dbg.assign addr if unused in DIArgList");
145 return;
146 }
147
148 assert(OldIt != Locations.end() && "OldValue must be a current location");
149 if (!hasArgList()) {
150 Value *NewOperand = isa<MetadataAsValue>(NewValue)
151 ? NewValue
153 getContext(), ValueAsMetadata::get(NewValue));
154 return setArgOperand(0, NewOperand);
155 }
157 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
158 for (auto *VMD : Locations)
159 MDs.push_back(VMD == *OldIt ? NewOperand : getAsMetadata(VMD));
162}
164 Value *NewValue) {
165 assert(OpIdx < getNumVariableLocationOps() && "Invalid Operand Index");
166 if (!hasArgList()) {
167 Value *NewOperand = isa<MetadataAsValue>(NewValue)
168 ? NewValue
170 getContext(), ValueAsMetadata::get(NewValue));
171 return setArgOperand(0, NewOperand);
172 }
174 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
175 for (unsigned Idx = 0; Idx < getNumVariableLocationOps(); ++Idx)
176 MDs.push_back(Idx == OpIdx ? NewOperand
180}
181
184 assert(NewExpr->hasAllLocationOps(getNumVariableLocationOps() +
185 NewValues.size()) &&
186 "NewExpr for debug variable intrinsic does not reference every "
187 "location operand.");
188 assert(!is_contained(NewValues, nullptr) && "New values must be non-null");
191 for (auto *VMD : location_ops())
192 MDs.push_back(getAsMetadata(VMD));
193 for (auto *VMD : NewValues)
194 MDs.push_back(getAsMetadata(VMD));
197}
198
199std::optional<uint64_t> DbgVariableIntrinsic::getFragmentSizeInBits() const {
200 if (auto Fragment = getExpression()->getFragmentInfo())
201 return Fragment->SizeInBits;
202 return getVariable()->getSizeInBits();
203}
204
206 auto *MD = getRawAddress();
207 if (auto *V = dyn_cast<ValueAsMetadata>(MD))
208 return V->getValue();
209
210 // When the value goes to null, it gets replaced by an empty MDNode.
211 assert(!cast<MDNode>(MD)->getNumOperands() && "Expected an empty MDNode");
212 return nullptr;
213}
214
218
223
229
231 Value *Addr = getAddress();
232 return !Addr || isa<UndefValue>(Addr);
233}
234
239
242 llvm_unreachable("InstrProfValueProfileInst does not have counters!");
244}
245
248 llvm_unreachable("Please use InstrProfValueProfileInst::getIndex()");
250}
251
256
259 return getArgOperand(4);
260 }
261 const Module *M = getModule();
262 LLVMContext &Context = M->getContext();
263 return ConstantInt::get(Type::getInt64Ty(Context), 1);
264}
265
267 if (isa<InstrProfCallsite>(this))
268 return getArgOperand(4);
269 return nullptr;
270}
271
274 setArgOperand(4, Callee);
275}
276
277std::optional<RoundingMode> ConstrainedFPIntrinsic::getRoundingMode() const {
278 unsigned NumOperands = arg_size();
279 Metadata *MD = nullptr;
280 auto *MAV = dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 2));
281 if (MAV)
282 MD = MAV->getMetadata();
283 if (!MD || !isa<MDString>(MD))
284 return std::nullopt;
285 return convertStrToRoundingMode(cast<MDString>(MD)->getString());
286}
287
288std::optional<fp::ExceptionBehavior>
290 unsigned NumOperands = arg_size();
291 Metadata *MD = nullptr;
292 auto *MAV = dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 1));
293 if (MAV)
294 MD = MAV->getMetadata();
295 if (!MD || !isa<MDString>(MD))
296 return std::nullopt;
297 return convertStrToExceptionBehavior(cast<MDString>(MD)->getString());
298}
299
301 std::optional<fp::ExceptionBehavior> Except = getExceptionBehavior();
302 if (Except) {
303 if (*Except != fp::ebIgnore)
304 return false;
305 }
306
307 std::optional<RoundingMode> Rounding = getRoundingMode();
308 if (Rounding) {
309 if (*Rounding != RoundingMode::NearestTiesToEven)
310 return false;
311 }
312
313 return true;
314}
315
337
341
343 // All constrained fp intrinsics have "fpexcept" metadata.
344 unsigned NumArgs = arg_size() - 1;
345
346 // Some intrinsics have "round" metadata.
348 NumArgs -= 1;
349
350 // Compare intrinsics take their predicate as metadata.
352 NumArgs -= 1;
353
354 return NumArgs;
355}
356
360
362 auto GetVectorLengthOfType = [](const Type *T) -> ElementCount {
363 const auto *VT = cast<VectorType>(T);
364 auto ElemCount = VT->getElementCount();
365 return ElemCount;
366 };
367
368 Value *VPMask = getMaskParam();
369 if (!VPMask) {
370 assert((getIntrinsicID() == Intrinsic::vp_merge ||
371 getIntrinsicID() == Intrinsic::vp_select) &&
372 "Unexpected VP intrinsic without mask operand");
373 return GetVectorLengthOfType(getType());
374 }
375 return GetVectorLengthOfType(VPMask->getType());
376}
377
379 if (auto MaskPos = getMaskParamPos(getIntrinsicID()))
380 return getArgOperand(*MaskPos);
381 return nullptr;
382}
383
385 auto MaskPos = getMaskParamPos(getIntrinsicID());
386 setArgOperand(*MaskPos, NewMask);
387}
388
390 if (auto EVLPos = getVectorLengthParamPos(getIntrinsicID()))
391 return getArgOperand(*EVLPos);
392 return nullptr;
393}
394
397 setArgOperand(*EVLPos, NewEVL);
398}
399
400std::optional<unsigned>
402 switch (IntrinsicID) {
403 default:
404 return std::nullopt;
405
406#define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \
407 case Intrinsic::VPID: \
408 return MASKPOS;
409#include "llvm/IR/VPIntrinsics.def"
410 }
411}
412
413std::optional<unsigned>
415 switch (IntrinsicID) {
416 default:
417 return std::nullopt;
418
419#define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \
420 case Intrinsic::VPID: \
421 return VLENPOS;
422#include "llvm/IR/VPIntrinsics.def"
423 }
424}
425
426/// \return the alignment of the pointer used by this load/store/gather or
427/// scatter.
429 std::optional<unsigned> PtrParamOpt =
431 assert(PtrParamOpt && "no pointer argument!");
432 return getParamAlign(*PtrParamOpt);
433}
434
435/// \return The pointer operand of this load,store, gather or scatter.
437 if (auto PtrParamOpt = getMemoryPointerParamPos(getIntrinsicID()))
438 return getArgOperand(*PtrParamOpt);
439 return nullptr;
440}
441
442std::optional<unsigned>
444 switch (VPID) {
445 default:
446 return std::nullopt;
447 case Intrinsic::vp_store:
448 case Intrinsic::vp_scatter:
449 case Intrinsic::experimental_vp_strided_store:
450 return 1;
451 case Intrinsic::vp_load:
452 case Intrinsic::vp_load_ff:
453 case Intrinsic::vp_gather:
454 case Intrinsic::experimental_vp_strided_load:
455 return 0;
456 }
457}
458
459/// \return The data (payload) operand of this store or scatter.
461 auto DataParamOpt = getMemoryDataParamPos(getIntrinsicID());
462 if (!DataParamOpt)
463 return nullptr;
464 return getArgOperand(*DataParamOpt);
465}
466
468 switch (VPID) {
469 default:
470 return std::nullopt;
471 case Intrinsic::vp_store:
472 case Intrinsic::vp_scatter:
473 case Intrinsic::experimental_vp_strided_store:
474 return 0;
475 }
476}
477
479 switch (ID) {
480 default:
481 break;
482#define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \
483 case Intrinsic::VPID: \
484 return true;
485#include "llvm/IR/VPIntrinsics.def"
486 }
487 return false;
488}
489
491 return ::isVPIntrinsic(ID);
492}
493
494// Equivalent non-predicated opcode
495constexpr static std::optional<unsigned>
497 switch (ID) {
498 default:
499 break;
500#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
501#define VP_PROPERTY_FUNCTIONAL_OPC(OPC) return Instruction::OPC;
502#define END_REGISTER_VP_INTRINSIC(VPID) break;
503#include "llvm/IR/VPIntrinsics.def"
504 }
505 return std::nullopt;
506}
507
508std::optional<unsigned>
510 return ::getFunctionalOpcodeForVP(ID);
511}
512
513// Equivalent non-predicated intrinsic ID
514constexpr static std::optional<Intrinsic::ID>
516 switch (ID) {
517 default:
518 break;
519#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
520#define VP_PROPERTY_FUNCTIONAL_INTRINSIC(INTRIN) return Intrinsic::INTRIN;
521#define END_REGISTER_VP_INTRINSIC(VPID) break;
522#include "llvm/IR/VPIntrinsics.def"
523 }
524 return std::nullopt;
525}
526
527std::optional<Intrinsic::ID>
529 return ::getFunctionalIntrinsicIDForVP(ID);
530}
531
533 switch (ID) {
534 default:
535 break;
536#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
537#define VP_PROPERTY_NO_FUNCTIONAL return true;
538#define END_REGISTER_VP_INTRINSIC(VPID) break;
539#include "llvm/IR/VPIntrinsics.def"
540 }
541 return false;
542}
543
544// All VP intrinsics should have an equivalent non-VP opcode or intrinsic
545// defined, or be marked that they don't have one.
546#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) \
547 static_assert(doesVPHaveNoFunctionalEquivalent(Intrinsic::VPID) || \
548 getFunctionalOpcodeForVP(Intrinsic::VPID) || \
549 getFunctionalIntrinsicIDForVP(Intrinsic::VPID));
550#include "llvm/IR/VPIntrinsics.def"
551
552// Equivalent non-predicated constrained intrinsic
553std::optional<Intrinsic::ID>
555 switch (ID) {
556 default:
557 break;
558#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
559#define VP_PROPERTY_CONSTRAINEDFP(CID) return Intrinsic::CID;
560#define END_REGISTER_VP_INTRINSIC(VPID) break;
561#include "llvm/IR/VPIntrinsics.def"
562 }
563 return std::nullopt;
564}
565
567 switch (IROPC) {
568 default:
569 break;
570
571#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) break;
572#define VP_PROPERTY_FUNCTIONAL_OPC(OPC) case Instruction::OPC:
573#define END_REGISTER_VP_INTRINSIC(VPID) return Intrinsic::VPID;
574#include "llvm/IR/VPIntrinsics.def"
575 }
577}
578
580 if (::isVPIntrinsic(Id))
581 return Id;
582
583 switch (Id) {
584 default:
585 break;
586#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) break;
587#define VP_PROPERTY_FUNCTIONAL_INTRINSIC(INTRIN) case Intrinsic::INTRIN:
588#define END_REGISTER_VP_INTRINSIC(VPID) return Intrinsic::VPID;
589#include "llvm/IR/VPIntrinsics.def"
590 }
592}
593
595 return ::getForIntrinsic(Id);
596}
597
599 using namespace PatternMatch;
600
602
603 // No vlen param - no lanes masked-off by it.
604 auto *VLParam = getVectorLengthParam();
605 if (!VLParam)
606 return true;
607
608 // Note that the VP intrinsic causes undefined behavior if the Explicit Vector
609 // Length parameter is strictly greater-than the number of vector elements of
610 // the operation. This function returns true when this is detected statically
611 // in the IR.
612
613 // Check whether "W == vscale * EC.getKnownMinValue()"
614 if (EC.isScalable()) {
615 // Compare vscale patterns
616 uint64_t VScaleFactor;
617 if (match(VLParam, m_Mul(m_VScale(), m_ConstantInt(VScaleFactor))))
618 return VScaleFactor >= EC.getKnownMinValue();
619 return (EC.getKnownMinValue() == 1) && match(VLParam, m_VScale());
620 }
621
622 // standard SIMD operation
623 const auto *VLConst = dyn_cast<ConstantInt>(VLParam);
624 if (!VLConst)
625 return false;
626
627 uint64_t VLNum = VLConst->getZExtValue();
628 if (VLNum >= EC.getKnownMinValue())
629 return true;
630
631 return false;
632}
633
635 Module *M, Intrinsic::ID VPID, Type *ReturnType, ArrayRef<Value *> Params) {
636 assert(isVPIntrinsic(VPID) && "not a VP intrinsic");
637 Function *VPFunc;
638 switch (VPID) {
639 default: {
640 Type *OverloadTy = Params[0]->getType();
642 OverloadTy =
643 Params[*VPReductionIntrinsic::getVectorParamPos(VPID)]->getType();
644
645 VPFunc = Intrinsic::getOrInsertDeclaration(M, VPID, OverloadTy);
646 break;
647 }
648 case Intrinsic::vp_trunc:
649 case Intrinsic::vp_sext:
650 case Intrinsic::vp_zext:
651 case Intrinsic::vp_fptoui:
652 case Intrinsic::vp_fptosi:
653 case Intrinsic::vp_uitofp:
654 case Intrinsic::vp_sitofp:
655 case Intrinsic::vp_fptrunc:
656 case Intrinsic::vp_fpext:
657 case Intrinsic::vp_ptrtoint:
658 case Intrinsic::vp_inttoptr:
659 case Intrinsic::vp_lrint:
660 case Intrinsic::vp_llrint:
661 case Intrinsic::vp_cttz_elts:
663 M, VPID, {ReturnType, Params[0]->getType()});
664 break;
665 case Intrinsic::vp_is_fpclass:
666 VPFunc = Intrinsic::getOrInsertDeclaration(M, VPID, {Params[0]->getType()});
667 break;
668 case Intrinsic::vp_merge:
669 case Intrinsic::vp_select:
670 VPFunc = Intrinsic::getOrInsertDeclaration(M, VPID, {Params[1]->getType()});
671 break;
672 case Intrinsic::vp_load:
674 M, VPID, {ReturnType, Params[0]->getType()});
675 break;
676 case Intrinsic::vp_load_ff:
678 M, VPID, {ReturnType->getStructElementType(0), Params[0]->getType()});
679 break;
680 case Intrinsic::experimental_vp_strided_load:
682 M, VPID, {ReturnType, Params[0]->getType(), Params[1]->getType()});
683 break;
684 case Intrinsic::vp_gather:
686 M, VPID, {ReturnType, Params[0]->getType()});
687 break;
688 case Intrinsic::vp_store:
690 M, VPID, {Params[0]->getType(), Params[1]->getType()});
691 break;
692 case Intrinsic::experimental_vp_strided_store:
694 M, VPID,
695 {Params[0]->getType(), Params[1]->getType(), Params[2]->getType()});
696 break;
697 case Intrinsic::vp_scatter:
699 M, VPID, {Params[0]->getType(), Params[1]->getType()});
700 break;
701 }
702 assert(VPFunc && "Could not declare VP intrinsic");
703 return VPFunc;
704}
705
707 switch (ID) {
708 case Intrinsic::vp_reduce_add:
709 case Intrinsic::vp_reduce_mul:
710 case Intrinsic::vp_reduce_and:
711 case Intrinsic::vp_reduce_or:
712 case Intrinsic::vp_reduce_xor:
713 case Intrinsic::vp_reduce_smax:
714 case Intrinsic::vp_reduce_smin:
715 case Intrinsic::vp_reduce_umax:
716 case Intrinsic::vp_reduce_umin:
717 case Intrinsic::vp_reduce_fmax:
718 case Intrinsic::vp_reduce_fmin:
719 case Intrinsic::vp_reduce_fmaximum:
720 case Intrinsic::vp_reduce_fminimum:
721 case Intrinsic::vp_reduce_fadd:
722 case Intrinsic::vp_reduce_fmul:
723 return true;
724 default:
725 return false;
726 }
727}
728
730 // All of the vp.casts correspond to instructions
731 if (std::optional<unsigned> Opc = getFunctionalOpcodeForVP(ID))
732 return Instruction::isCast(*Opc);
733 return false;
734}
735
737 switch (ID) {
738 default:
739 return false;
740 case Intrinsic::vp_fcmp:
741 case Intrinsic::vp_icmp:
742 return true;
743 }
744}
745
747 switch (ID) {
748 default:
749 break;
750#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
751#define VP_PROPERTY_BINARYOP return true;
752#define END_REGISTER_VP_INTRINSIC(VPID) break;
753#include "llvm/IR/VPIntrinsics.def"
754 }
755 return false;
756}
757
775
782
786
790
791std::optional<unsigned>
793 if (isVPReduction(ID))
794 return 1;
795 return std::nullopt;
796}
797
798std::optional<unsigned>
800 if (isVPReduction(ID))
801 return 0;
802 return std::nullopt;
803}
804
806 switch (getIntrinsicID()) {
807 case Intrinsic::uadd_with_overflow:
808 case Intrinsic::sadd_with_overflow:
809 case Intrinsic::uadd_sat:
810 case Intrinsic::sadd_sat:
811 return Instruction::Add;
812 case Intrinsic::usub_with_overflow:
813 case Intrinsic::ssub_with_overflow:
814 case Intrinsic::usub_sat:
815 case Intrinsic::ssub_sat:
816 return Instruction::Sub;
817 case Intrinsic::umul_with_overflow:
818 case Intrinsic::smul_with_overflow:
819 return Instruction::Mul;
820 default:
821 llvm_unreachable("Invalid intrinsic");
822 }
823}
824
826 switch (getIntrinsicID()) {
827 case Intrinsic::sadd_with_overflow:
828 case Intrinsic::ssub_with_overflow:
829 case Intrinsic::smul_with_overflow:
830 case Intrinsic::sadd_sat:
831 case Intrinsic::ssub_sat:
832 return true;
833 default:
834 return false;
835 }
836}
837
844
846 const Value *Token = getArgOperand(0);
847 if (isa<UndefValue>(Token))
848 return Token;
849
850 // Treat none token as if it was undef here
851 if (isa<ConstantTokenNone>(Token))
852 return UndefValue::get(Token->getType());
853
854 // This takes care both of relocates for call statepoints and relocates
855 // on normal path of invoke statepoint.
856 if (!isa<LandingPadInst>(Token))
857 return cast<GCStatepointInst>(Token);
858
859 // This relocate is on exceptional path of an invoke statepoint
860 const BasicBlock *InvokeBB =
861 cast<Instruction>(Token)->getParent()->getUniquePredecessor();
862
863 assert(InvokeBB && "safepoints should have unique landingpads");
864 assert(InvokeBB->getTerminator() &&
865 "safepoint block should be well formed");
866
867 return cast<GCStatepointInst>(InvokeBB->getTerminator());
868}
869
871 auto Statepoint = getStatepoint();
872 if (isa<UndefValue>(Statepoint))
873 return UndefValue::get(Statepoint->getType());
874
875 auto *GCInst = cast<GCStatepointInst>(Statepoint);
876 if (auto Opt = GCInst->getOperandBundle(LLVMContext::OB_gc_live))
877 return *(Opt->Inputs.begin() + getBasePtrIndex());
878 return *(GCInst->arg_begin() + getBasePtrIndex());
879}
880
882 auto *Statepoint = getStatepoint();
883 if (isa<UndefValue>(Statepoint))
884 return UndefValue::get(Statepoint->getType());
885
886 auto *GCInst = cast<GCStatepointInst>(Statepoint);
887 if (auto Opt = GCInst->getOperandBundle(LLVMContext::OB_gc_live))
888 return *(Opt->Inputs.begin() + getDerivedPtrIndex());
889 return *(GCInst->arg_begin() + getDerivedPtrIndex());
890}
891
893 Module *M = BB.getModule();
895 M, llvm::Intrinsic::experimental_convergence_anchor);
896 auto *Call = CallInst::Create(Fn, "", BB.getFirstInsertionPt());
898}
899
901 Module *M = BB.getModule();
903 M, llvm::Intrinsic::experimental_convergence_entry);
904 auto *Call = CallInst::Create(Fn, "", BB.getFirstInsertionPt());
906}
907
910 ConvergenceControlInst *ParentToken) {
911 Module *M = BB.getModule();
913 M, llvm::Intrinsic::experimental_convergence_loop);
914 llvm::Value *BundleArgs[] = {ParentToken};
915 llvm::OperandBundleDef OB("convergencectrl", BundleArgs);
916 auto *Call = CallInst::Create(Fn, {}, {OB}, "", BB.getFirstInsertionPt());
918}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static ValueAsMetadata * getAsMetadata(Value *V)
Module.h This file contains the declarations for the Module class.
static constexpr std::optional< Intrinsic::ID > getFunctionalIntrinsicIDForVP(Intrinsic::ID ID)
static constexpr std::optional< unsigned > getFunctionalOpcodeForVP(Intrinsic::ID ID)
static ICmpInst::Predicate getIntPredicateFromMD(const Value *Op)
static constexpr bool doesVPHaveNoFunctionalEquivalent(Intrinsic::ID ID)
constexpr bool isVPIntrinsic(Intrinsic::ID ID)
static constexpr Intrinsic::ID getForIntrinsic(Intrinsic::ID Id)
static FCmpInst::Predicate getFPPredicateFromMD(const Value *Op)
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
#define T
MachineInstr unsigned OpIdx
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
LLVM Basic Block Representation.
Definition BasicBlock.h:62
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...
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
LLVM_ABI const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
LLVM_ABI unsigned getNoWrapKind() const
Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
LLVM_ABI bool isSigned() const
Whether the intrinsic is signed or unsigned.
LLVM_ABI Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Value * getArgOperand(unsigned i) const
void setArgOperand(unsigned i, Value *v)
unsigned arg_size() const
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:679
@ ICMP_SLT
signed less than
Definition InstrTypes.h:705
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:706
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:682
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:691
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:680
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:681
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:700
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:699
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:703
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:690
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:684
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:687
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:701
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:688
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:683
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:685
@ ICMP_NE
not equal
Definition InstrTypes.h:698
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:704
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:692
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:702
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:689
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:686
This is the shared class of boolean and integer constants.
Definition Constants.h:87
LLVM_ABI FCmpInst::Predicate getPredicate() const
LLVM_ABI std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
LLVM_ABI std::optional< RoundingMode > getRoundingMode() const
LLVM_ABI unsigned getNonMetadataArgCount() const
static LLVM_ABI bool classof(const IntrinsicInst *I)
LLVM_ABI bool isDefaultFPEnvironment() const
Represents calls to the llvm.experimintal.convergence.* intrinsics.
static LLVM_ABI ConvergenceControlInst * CreateAnchor(BasicBlock &BB)
static LLVM_ABI ConvergenceControlInst * CreateLoop(BasicBlock &BB, ConvergenceControlInst *Parent)
static LLVM_ABI ConvergenceControlInst * CreateEntry(BasicBlock &BB)
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
DWARF expression.
LLVM_ABI std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
LLVM_ABI void setValue(Value *V)
LLVM_ABI void setAssignId(DIAssignID *New)
LLVM_ABI void setKillAddress()
Kill the address component.
LLVM_ABI bool isKillAddress() const
Check whether this kills the address component.
Metadata * getRawAddress() const
LLVM_ABI Value * getAddress() const
LLVM_ABI void setAddress(Value *V)
LLVM_ABI iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
LLVM_ABI void addVariableLocationOps(ArrayRef< Value * > NewValues, DIExpression *NewExpr)
Adding a new location operand will always result in this intrinsic using an ArgList,...
LLVM_ABI void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
LLVM_ABI Value * getVariableLocationOp(unsigned OpIdx) const
DILocalVariable * getVariable() const
unsigned getNumVariableLocationOps() const
void setOperand(unsigned i, Value *v)
LLVM_ABI std::optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
DIExpression * getExpression() const
void setArgOperand(unsigned i, Value *v)
RawLocationWrapper getWrappedLocation() const
LLVM_ABI const Value * getStatepoint() const
The statepoint with which this gc.relocate is associated.
LLVM_ABI Value * getBasePtr() const
unsigned getBasePtrIndex() const
The index into the associate statepoint's argument list which contains the base pointer of the pointe...
LLVM_ABI Value * getDerivedPtr() const
unsigned getDerivedPtrIndex() const
The index into the associate statepoint's argument list which contains the pointer whose relocation t...
LLVM_ABI void setCallee(Value *Callee)
LLVM_ABI Value * getCallee() const
LLVM_ABI ConstantInt * getIndex() const
LLVM_ABI void setIndex(uint32_t Idx)
LLVM_ABI ConstantInt * getNumCounters() const
static bool classof(const IntrinsicInst *I)
LLVM_ABI Value * getStep() const
static bool classof(const IntrinsicInst *I)
bool isCast() const
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static LLVM_ABI bool mayLowerToFunctionCall(Intrinsic::ID IID)
Check if the intrinsic might lower into a regular function call in the course of IR transformations.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:110
Root of the metadata hierarchy.
Definition Metadata.h:64
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Metadata * getRawLocation() const
LLVM_ABI iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
LLVM_ABI Value * getVariableLocationOp(unsigned OpIdx) const
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:314
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:313
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
unsigned getNumOperands() const
Definition User.h:229
static LLVM_ABI bool isVPBinOp(Intrinsic::ID ID)
static LLVM_ABI bool isVPCast(Intrinsic::ID ID)
static LLVM_ABI bool isVPCmp(Intrinsic::ID ID)
LLVM_ABI CmpInst::Predicate getPredicate() const
static LLVM_ABI std::optional< unsigned > getMaskParamPos(Intrinsic::ID IntrinsicID)
LLVM_ABI bool canIgnoreVectorLengthParam() const
LLVM_ABI void setMaskParam(Value *)
static LLVM_ABI std::optional< unsigned > getFunctionalOpcodeForVP(Intrinsic::ID ID)
static LLVM_ABI std::optional< unsigned > getMemoryDataParamPos(Intrinsic::ID)
LLVM_ABI Value * getVectorLengthParam() const
static LLVM_ABI std::optional< Intrinsic::ID > getFunctionalIntrinsicIDForVP(Intrinsic::ID ID)
LLVM_ABI void setVectorLengthParam(Value *)
static LLVM_ABI std::optional< unsigned > getVectorLengthParamPos(Intrinsic::ID IntrinsicID)
static LLVM_ABI Intrinsic::ID getForOpcode(unsigned OC)
The llvm.vp.* intrinsics for this instruction Opcode.
static LLVM_ABI Function * getOrInsertDeclarationForParams(Module *M, Intrinsic::ID, Type *ReturnType, ArrayRef< Value * > Params)
Declares a llvm.vp.
static LLVM_ABI std::optional< unsigned > getMemoryPointerParamPos(Intrinsic::ID)
static LLVM_ABI bool isVPIntrinsic(Intrinsic::ID)
LLVM_ABI Value * getMemoryDataParam() const
static LLVM_ABI Intrinsic::ID getForIntrinsic(Intrinsic::ID Id)
The llvm.vp.
LLVM_ABI Value * getMemoryPointerParam() const
LLVM_ABI MaybeAlign getPointerAlignment() const
LLVM_ABI Value * getMaskParam() const
LLVM_ABI ElementCount getStaticVectorLength() const
static LLVM_ABI std::optional< Intrinsic::ID > getConstrainedIntrinsicIDForVP(Intrinsic::ID ID)
static LLVM_ABI bool isVPReduction(Intrinsic::ID ID)
LLVM_ABI unsigned getStartParamPos() const
LLVM_ABI unsigned getVectorParamPos() const
Value wrapper in the Metadata hierarchy.
Definition Metadata.h:459
static LLVM_ABI ValueAsMetadata * get(Value *V)
Definition Metadata.cpp:509
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:259
A range adaptor for a pair of iterators.
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics" that take r...
LLVM_ABI bool isConstrainedFPIntrinsic(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics".
bool match(Val *V, const Pattern &P)
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
IntrinsicID_match m_VScale()
Matches a call to llvm.vscale().
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition FPEnv.h:40
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1765
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
OperandBundleDefT< Value * > OperandBundleDef
Definition AutoUpgrade.h:34
LLVM_ABI std::optional< fp::ExceptionBehavior > convertStrToExceptionBehavior(StringRef)
Returns a valid ExceptionBehavior enumerator when given a string valid as input in constrained intrin...
Definition FPEnv.cpp:67
DWARFExpression::Operation Op
@ NearestTiesToEven
roundTiesToEven.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
Definition FPEnv.cpp:25
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106