LLVM 17.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_copyWeak:
43 case Intrinsic::objc_destroyWeak:
44 case Intrinsic::objc_initWeak:
45 case Intrinsic::objc_loadWeak:
46 case Intrinsic::objc_loadWeakRetained:
47 case Intrinsic::objc_moveWeak:
48 case Intrinsic::objc_release:
49 case Intrinsic::objc_retain:
50 case Intrinsic::objc_retainAutorelease:
51 case Intrinsic::objc_retainAutoreleaseReturnValue:
52 case Intrinsic::objc_retainAutoreleasedReturnValue:
53 case Intrinsic::objc_retainBlock:
54 case Intrinsic::objc_storeStrong:
55 case Intrinsic::objc_storeWeak:
56 case Intrinsic::objc_unsafeClaimAutoreleasedReturnValue:
57 case Intrinsic::objc_retainedObject:
58 case Intrinsic::objc_unretainedObject:
59 case Intrinsic::objc_unretainedPointer:
60 case Intrinsic::objc_retain_autorelease:
61 case Intrinsic::objc_sync_enter:
62 case Intrinsic::objc_sync_exit:
63 return true;
64 default:
65 return false;
66 }
67}
68
69//===----------------------------------------------------------------------===//
70/// DbgVariableIntrinsic - This is the common base class for debug info
71/// intrinsics for variables.
72///
73
76 auto *MD = getRawLocation();
77 assert(MD && "First operand of DbgVariableIntrinsic should be non-null.");
78
79 // If operand is ValueAsMetadata, return a range over just that operand.
80 if (auto *VAM = dyn_cast<ValueAsMetadata>(MD)) {
81 return {location_op_iterator(VAM), location_op_iterator(VAM + 1)};
82 }
83 // If operand is DIArgList, return a range over its args.
84 if (auto *AL = dyn_cast<DIArgList>(MD))
85 return {location_op_iterator(AL->args_begin()),
86 location_op_iterator(AL->args_end())};
87 // Operand must be an empty metadata tuple, so return empty iterator.
88 return {location_op_iterator(static_cast<ValueAsMetadata *>(nullptr)),
89 location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
90}
91
93 auto *MD = getRawLocation();
94 assert(MD && "First operand of DbgVariableIntrinsic should be non-null.");
95 if (auto *AL = dyn_cast<DIArgList>(MD))
96 return AL->getArgs()[OpIdx]->getValue();
97 if (isa<MDNode>(MD))
98 return nullptr;
99 assert(
100 isa<ValueAsMetadata>(MD) &&
101 "Attempted to get location operand from DbgVariableIntrinsic with none.");
102 auto *V = cast<ValueAsMetadata>(MD);
103 assert(OpIdx == 0 && "Operand Index must be 0 for a debug intrinsic with a "
104 "single location operand.");
105 return V->getValue();
106}
107
109 return isa<MetadataAsValue>(V) ? dyn_cast<ValueAsMetadata>(
110 cast<MetadataAsValue>(V)->getMetadata())
112}
113
115 Value *NewValue) {
116 // If OldValue is used as the address part of a dbg.assign intrinsic replace
117 // it with NewValue and return true.
118 auto ReplaceDbgAssignAddress = [this, OldValue, NewValue]() -> bool {
119 auto *DAI = dyn_cast<DbgAssignIntrinsic>(this);
120 if (!DAI || OldValue != DAI->getAddress())
121 return false;
122 DAI->setAddress(NewValue);
123 return true;
124 };
125 bool DbgAssignAddrReplaced = ReplaceDbgAssignAddress();
126 (void)DbgAssignAddrReplaced;
127
128 assert(NewValue && "Values must be non-null");
129 auto Locations = location_ops();
130 auto OldIt = find(Locations, OldValue);
131 assert((OldIt != Locations.end() || DbgAssignAddrReplaced) &&
132 "OldValue must be a current location");
133 if (!hasArgList()) {
134 // Additional check necessary to avoid unconditionally replacing this
135 // operand when a dbg.assign address is replaced (DbgAssignAddrReplaced is
136 // true).
137 if (OldValue != getVariableLocationOp(0))
138 return;
139 Value *NewOperand = isa<MetadataAsValue>(NewValue)
140 ? NewValue
142 getContext(), ValueAsMetadata::get(NewValue));
143 return setArgOperand(0, NewOperand);
144 }
146 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
147 for (auto *VMD : Locations)
148 MDs.push_back(VMD == *OldIt ? NewOperand : getAsMetadata(VMD));
151}
153 Value *NewValue) {
154 assert(OpIdx < getNumVariableLocationOps() && "Invalid Operand Index");
155 if (!hasArgList()) {
156 Value *NewOperand = isa<MetadataAsValue>(NewValue)
157 ? NewValue
159 getContext(), ValueAsMetadata::get(NewValue));
160 return setArgOperand(0, NewOperand);
161 }
163 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
164 for (unsigned Idx = 0; Idx < getNumVariableLocationOps(); ++Idx)
165 MDs.push_back(Idx == OpIdx ? NewOperand
169}
170
173 assert(NewExpr->hasAllLocationOps(getNumVariableLocationOps() +
174 NewValues.size()) &&
175 "NewExpr for debug variable intrinsic does not reference every "
176 "location operand.");
177 assert(!is_contained(NewValues, nullptr) && "New values must be non-null");
180 for (auto *VMD : location_ops())
181 MDs.push_back(getAsMetadata(VMD));
182 for (auto *VMD : NewValues)
183 MDs.push_back(getAsMetadata(VMD));
186}
187
188std::optional<uint64_t> DbgVariableIntrinsic::getFragmentSizeInBits() const {
189 if (auto Fragment = getExpression()->getFragmentInfo())
190 return Fragment->SizeInBits;
191 return getVariable()->getSizeInBits();
192}
193
195 auto *MD = getRawAddress();
196 if (auto *V = dyn_cast<ValueAsMetadata>(MD))
197 return V->getValue();
198
199 // When the value goes to null, it gets replaced by an empty MDNode.
200 assert(!cast<MDNode>(MD)->getNumOperands() && "Expected an empty MDNode");
201 return nullptr;
202}
203
205 setOperand(OpAssignID, MetadataAsValue::get(getContext(), New));
206}
207
209 assert(V->getType()->isPointerTy() &&
210 "Destination Component must be a pointer type");
211 setOperand(OpAddress,
213}
214
216 if (isKillAddress())
217 return;
219}
220
222 Value *Addr = getAddress();
223 return !Addr || isa<UndefValue>(Addr);
224}
225
227 setOperand(OpValue,
229}
230
232 StringRef Name) {
233 assert(Name.startswith("llvm."));
234
235 // Do successive binary searches of the dotted name components. For
236 // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
237 // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
238 // "llvm.gc.experimental.statepoint", and then we will stop as the range is
239 // size 1. During the search, we can skip the prefix that we already know is
240 // identical. By using strncmp we consider names with differing suffixes to
241 // be part of the equal range.
242 size_t CmpEnd = 4; // Skip the "llvm" component.
243 const char *const *Low = NameTable.begin();
244 const char *const *High = NameTable.end();
245 const char *const *LastLow = Low;
246 while (CmpEnd < Name.size() && High - Low > 0) {
247 size_t CmpStart = CmpEnd;
248 CmpEnd = Name.find('.', CmpStart + 1);
249 CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
250 auto Cmp = [CmpStart, CmpEnd](const char *LHS, const char *RHS) {
251 return strncmp(LHS + CmpStart, RHS + CmpStart, CmpEnd - CmpStart) < 0;
252 };
253 LastLow = Low;
254 std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
255 }
256 if (High - Low > 0)
257 LastLow = Low;
258
259 if (LastLow == NameTable.end())
260 return -1;
261 StringRef NameFound = *LastLow;
262 if (Name == NameFound ||
263 (Name.startswith(NameFound) && Name[NameFound.size()] == '.'))
264 return LastLow - NameTable.begin();
265 return -1;
266}
267
270 llvm_unreachable("InstrProfValueProfileInst does not have counters!");
271 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
272}
273
276 llvm_unreachable("Please use InstrProfValueProfileInst::getIndex()");
277 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
278}
279
282 return const_cast<Value *>(getArgOperand(4));
283 }
284 const Module *M = getModule();
285 LLVMContext &Context = M->getContext();
287}
288
289std::optional<RoundingMode> ConstrainedFPIntrinsic::getRoundingMode() const {
290 unsigned NumOperands = arg_size();
291 Metadata *MD = nullptr;
292 auto *MAV = dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 2));
293 if (MAV)
294 MD = MAV->getMetadata();
295 if (!MD || !isa<MDString>(MD))
296 return std::nullopt;
297 return convertStrToRoundingMode(cast<MDString>(MD)->getString());
298}
299
300std::optional<fp::ExceptionBehavior>
302 unsigned NumOperands = arg_size();
303 Metadata *MD = nullptr;
304 auto *MAV = dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 1));
305 if (MAV)
306 MD = MAV->getMetadata();
307 if (!MD || !isa<MDString>(MD))
308 return std::nullopt;
309 return convertStrToExceptionBehavior(cast<MDString>(MD)->getString());
310}
311
313 std::optional<fp::ExceptionBehavior> Except = getExceptionBehavior();
314 if (Except) {
315 if (*Except != fp::ebIgnore)
316 return false;
317 }
318
319 std::optional<RoundingMode> Rounding = getRoundingMode();
320 if (Rounding) {
321 if (*Rounding != RoundingMode::NearestTiesToEven)
322 return false;
323 }
324
325 return true;
326}
327
329 Metadata *MD = cast<MetadataAsValue>(Op)->getMetadata();
330 if (!MD || !isa<MDString>(MD))
332 return StringSwitch<FCmpInst::Predicate>(cast<MDString>(MD)->getString())
333 .Case("oeq", FCmpInst::FCMP_OEQ)
334 .Case("ogt", FCmpInst::FCMP_OGT)
335 .Case("oge", FCmpInst::FCMP_OGE)
336 .Case("olt", FCmpInst::FCMP_OLT)
337 .Case("ole", FCmpInst::FCMP_OLE)
338 .Case("one", FCmpInst::FCMP_ONE)
339 .Case("ord", FCmpInst::FCMP_ORD)
340 .Case("uno", FCmpInst::FCMP_UNO)
341 .Case("ueq", FCmpInst::FCMP_UEQ)
342 .Case("ugt", FCmpInst::FCMP_UGT)
343 .Case("uge", FCmpInst::FCMP_UGE)
344 .Case("ult", FCmpInst::FCMP_ULT)
345 .Case("ule", FCmpInst::FCMP_ULE)
346 .Case("une", FCmpInst::FCMP_UNE)
348}
349
352}
353
355 switch (getIntrinsicID()) {
356 default:
357 return false;
358#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
359 case Intrinsic::INTRINSIC: \
360 return NARG == 1;
361#include "llvm/IR/ConstrainedOps.def"
362 }
363}
364
366 switch (getIntrinsicID()) {
367 default:
368 return false;
369#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
370 case Intrinsic::INTRINSIC: \
371 return NARG == 3;
372#include "llvm/IR/ConstrainedOps.def"
373 }
374}
375
377 switch (I->getIntrinsicID()) {
378#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
379 case Intrinsic::INTRINSIC:
380#include "llvm/IR/ConstrainedOps.def"
381 return true;
382 default:
383 return false;
384 }
385}
386
388 auto GetVectorLengthOfType = [](const Type *T) -> ElementCount {
389 const auto *VT = cast<VectorType>(T);
390 auto ElemCount = VT->getElementCount();
391 return ElemCount;
392 };
393
394 Value *VPMask = getMaskParam();
395 if (!VPMask) {
396 assert((getIntrinsicID() == Intrinsic::vp_merge ||
397 getIntrinsicID() == Intrinsic::vp_select) &&
398 "Unexpected VP intrinsic without mask operand");
399 return GetVectorLengthOfType(getType());
400 }
401 return GetVectorLengthOfType(VPMask->getType());
402}
403
405 if (auto MaskPos = getMaskParamPos(getIntrinsicID()))
406 return getArgOperand(*MaskPos);
407 return nullptr;
408}
409
411 auto MaskPos = getMaskParamPos(getIntrinsicID());
412 setArgOperand(*MaskPos, NewMask);
413}
414
416 if (auto EVLPos = getVectorLengthParamPos(getIntrinsicID()))
417 return getArgOperand(*EVLPos);
418 return nullptr;
419}
420
423 setArgOperand(*EVLPos, NewEVL);
424}
425
426std::optional<unsigned>
428 switch (IntrinsicID) {
429 default:
430 return std::nullopt;
431
432#define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \
433 case Intrinsic::VPID: \
434 return MASKPOS;
435#include "llvm/IR/VPIntrinsics.def"
436 }
437}
438
439std::optional<unsigned>
441 switch (IntrinsicID) {
442 default:
443 return std::nullopt;
444
445#define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \
446 case Intrinsic::VPID: \
447 return VLENPOS;
448#include "llvm/IR/VPIntrinsics.def"
449 }
450}
451
452/// \return the alignment of the pointer used by this load/store/gather or
453/// scatter.
455 std::optional<unsigned> PtrParamOpt =
457 assert(PtrParamOpt && "no pointer argument!");
458 return getParamAlign(*PtrParamOpt);
459}
460
461/// \return The pointer operand of this load,store, gather or scatter.
463 if (auto PtrParamOpt = getMemoryPointerParamPos(getIntrinsicID()))
464 return getArgOperand(*PtrParamOpt);
465 return nullptr;
466}
467
468std::optional<unsigned>
470 switch (VPID) {
471 default:
472 break;
473#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
474#define VP_PROPERTY_MEMOP(POINTERPOS, ...) return POINTERPOS;
475#define END_REGISTER_VP_INTRINSIC(VPID) break;
476#include "llvm/IR/VPIntrinsics.def"
477 }
478 return std::nullopt;
479}
480
481/// \return The data (payload) operand of this store or scatter.
483 auto DataParamOpt = getMemoryDataParamPos(getIntrinsicID());
484 if (!DataParamOpt)
485 return nullptr;
486 return getArgOperand(*DataParamOpt);
487}
488
490 switch (VPID) {
491 default:
492 break;
493#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
494#define VP_PROPERTY_MEMOP(POINTERPOS, DATAPOS) return DATAPOS;
495#define END_REGISTER_VP_INTRINSIC(VPID) break;
496#include "llvm/IR/VPIntrinsics.def"
497 }
498 return std::nullopt;
499}
500
502 switch (ID) {
503 default:
504 break;
505#define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \
506 case Intrinsic::VPID: \
507 return true;
508#include "llvm/IR/VPIntrinsics.def"
509 }
510 return false;
511}
512
513// Equivalent non-predicated opcode
514std::optional<unsigned>
516 switch (ID) {
517 default:
518 break;
519#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
520#define VP_PROPERTY_FUNCTIONAL_OPC(OPC) return Instruction::OPC;
521#define END_REGISTER_VP_INTRINSIC(VPID) break;
522#include "llvm/IR/VPIntrinsics.def"
523 }
524 return std::nullopt;
525}
526
528 switch (IROPC) {
529 default:
530 break;
531
532#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) break;
533#define VP_PROPERTY_FUNCTIONAL_OPC(OPC) case Instruction::OPC:
534#define END_REGISTER_VP_INTRINSIC(VPID) return Intrinsic::VPID;
535#include "llvm/IR/VPIntrinsics.def"
536 }
538}
539
541 using namespace PatternMatch;
542
544
545 // No vlen param - no lanes masked-off by it.
546 auto *VLParam = getVectorLengthParam();
547 if (!VLParam)
548 return true;
549
550 // Note that the VP intrinsic causes undefined behavior if the Explicit Vector
551 // Length parameter is strictly greater-than the number of vector elements of
552 // the operation. This function returns true when this is detected statically
553 // in the IR.
554
555 // Check whether "W == vscale * EC.getKnownMinValue()"
556 if (EC.isScalable()) {
557 // Undig the DL
558 const auto *ParMod = this->getModule();
559 if (!ParMod)
560 return false;
561 const auto &DL = ParMod->getDataLayout();
562
563 // Compare vscale patterns
564 uint64_t VScaleFactor;
565 if (match(VLParam, m_c_Mul(m_ConstantInt(VScaleFactor), m_VScale(DL))))
566 return VScaleFactor >= EC.getKnownMinValue();
567 return (EC.getKnownMinValue() == 1) && match(VLParam, m_VScale(DL));
568 }
569
570 // standard SIMD operation
571 const auto *VLConst = dyn_cast<ConstantInt>(VLParam);
572 if (!VLConst)
573 return false;
574
575 uint64_t VLNum = VLConst->getZExtValue();
576 if (VLNum >= EC.getKnownMinValue())
577 return true;
578
579 return false;
580}
581
583 Type *ReturnType,
584 ArrayRef<Value *> Params) {
585 assert(isVPIntrinsic(VPID) && "not a VP intrinsic");
586 Function *VPFunc;
587 switch (VPID) {
588 default: {
589 Type *OverloadTy = Params[0]->getType();
591 OverloadTy =
592 Params[*VPReductionIntrinsic::getVectorParamPos(VPID)]->getType();
593
594 VPFunc = Intrinsic::getDeclaration(M, VPID, OverloadTy);
595 break;
596 }
597 case Intrinsic::vp_trunc:
598 case Intrinsic::vp_sext:
599 case Intrinsic::vp_zext:
600 case Intrinsic::vp_fptoui:
601 case Intrinsic::vp_fptosi:
602 case Intrinsic::vp_uitofp:
603 case Intrinsic::vp_sitofp:
604 case Intrinsic::vp_fptrunc:
605 case Intrinsic::vp_fpext:
606 case Intrinsic::vp_ptrtoint:
607 case Intrinsic::vp_inttoptr:
608 VPFunc =
609 Intrinsic::getDeclaration(M, VPID, {ReturnType, Params[0]->getType()});
610 break;
611 case Intrinsic::vp_merge:
612 case Intrinsic::vp_select:
613 VPFunc = Intrinsic::getDeclaration(M, VPID, {Params[1]->getType()});
614 break;
615 case Intrinsic::vp_load:
617 M, VPID, {ReturnType, Params[0]->getType()});
618 break;
619 case Intrinsic::experimental_vp_strided_load:
621 M, VPID, {ReturnType, Params[0]->getType(), Params[1]->getType()});
622 break;
623 case Intrinsic::vp_gather:
625 M, VPID, {ReturnType, Params[0]->getType()});
626 break;
627 case Intrinsic::vp_store:
629 M, VPID, {Params[0]->getType(), Params[1]->getType()});
630 break;
631 case Intrinsic::experimental_vp_strided_store:
633 M, VPID,
634 {Params[0]->getType(), Params[1]->getType(), Params[2]->getType()});
635 break;
636 case Intrinsic::vp_scatter:
638 M, VPID, {Params[0]->getType(), Params[1]->getType()});
639 break;
640 }
641 assert(VPFunc && "Could not declare VP intrinsic");
642 return VPFunc;
643}
644
646 switch (ID) {
647 default:
648 break;
649#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
650#define VP_PROPERTY_REDUCTION(STARTPOS, ...) return true;
651#define END_REGISTER_VP_INTRINSIC(VPID) break;
652#include "llvm/IR/VPIntrinsics.def"
653 }
654 return false;
655}
656
658 switch (ID) {
659 default:
660 break;
661#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
662#define VP_PROPERTY_CASTOP return true;
663#define END_REGISTER_VP_INTRINSIC(VPID) break;
664#include "llvm/IR/VPIntrinsics.def"
665 }
666 return false;
667}
668
670 switch (ID) {
671 default:
672 break;
673#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
674#define VP_PROPERTY_CMP(CCPOS, ...) return true;
675#define END_REGISTER_VP_INTRINSIC(VPID) break;
676#include "llvm/IR/VPIntrinsics.def"
677 }
678 return false;
679}
680
682 Metadata *MD = cast<MetadataAsValue>(Op)->getMetadata();
683 if (!MD || !isa<MDString>(MD))
685 return StringSwitch<ICmpInst::Predicate>(cast<MDString>(MD)->getString())
686 .Case("eq", ICmpInst::ICMP_EQ)
687 .Case("ne", ICmpInst::ICMP_NE)
688 .Case("ugt", ICmpInst::ICMP_UGT)
689 .Case("uge", ICmpInst::ICMP_UGE)
690 .Case("ult", ICmpInst::ICMP_ULT)
691 .Case("ule", ICmpInst::ICMP_ULE)
692 .Case("sgt", ICmpInst::ICMP_SGT)
693 .Case("sge", ICmpInst::ICMP_SGE)
694 .Case("slt", ICmpInst::ICMP_SLT)
695 .Case("sle", ICmpInst::ICMP_SLE)
697}
698
700 bool IsFP = true;
701 std::optional<unsigned> CCArgIdx;
702 switch (getIntrinsicID()) {
703 default:
704 break;
705#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
706#define VP_PROPERTY_CMP(CCPOS, ISFP) \
707 CCArgIdx = CCPOS; \
708 IsFP = ISFP; \
709 break;
710#define END_REGISTER_VP_INTRINSIC(VPID) break;
711#include "llvm/IR/VPIntrinsics.def"
712 }
713 assert(CCArgIdx && "Unexpected vector-predicated comparison");
714 return IsFP ? getFPPredicateFromMD(getArgOperand(*CCArgIdx))
716}
717
720}
721
724}
725
726std::optional<unsigned>
728 switch (ID) {
729#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
730#define VP_PROPERTY_REDUCTION(STARTPOS, VECTORPOS) return VECTORPOS;
731#define END_REGISTER_VP_INTRINSIC(VPID) break;
732#include "llvm/IR/VPIntrinsics.def"
733 default:
734 break;
735 }
736 return std::nullopt;
737}
738
739std::optional<unsigned>
741 switch (ID) {
742#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
743#define VP_PROPERTY_REDUCTION(STARTPOS, VECTORPOS) return STARTPOS;
744#define END_REGISTER_VP_INTRINSIC(VPID) break;
745#include "llvm/IR/VPIntrinsics.def"
746 default:
747 break;
748 }
749 return std::nullopt;
750}
751
753 switch (getIntrinsicID()) {
754 case Intrinsic::uadd_with_overflow:
755 case Intrinsic::sadd_with_overflow:
756 case Intrinsic::uadd_sat:
757 case Intrinsic::sadd_sat:
758 return Instruction::Add;
759 case Intrinsic::usub_with_overflow:
760 case Intrinsic::ssub_with_overflow:
761 case Intrinsic::usub_sat:
762 case Intrinsic::ssub_sat:
763 return Instruction::Sub;
764 case Intrinsic::umul_with_overflow:
765 case Intrinsic::smul_with_overflow:
766 return Instruction::Mul;
767 default:
768 llvm_unreachable("Invalid intrinsic");
769 }
770}
771
773 switch (getIntrinsicID()) {
774 case Intrinsic::sadd_with_overflow:
775 case Intrinsic::ssub_with_overflow:
776 case Intrinsic::smul_with_overflow:
777 case Intrinsic::sadd_sat:
778 case Intrinsic::ssub_sat:
779 return true;
780 default:
781 return false;
782 }
783}
784
786 if (isSigned())
788 else
790}
791
793 const Value *Token = getArgOperand(0);
794 if (isa<UndefValue>(Token))
795 return Token;
796
797 // This takes care both of relocates for call statepoints and relocates
798 // on normal path of invoke statepoint.
799 if (!isa<LandingPadInst>(Token))
800 return cast<GCStatepointInst>(Token);
801
802 // This relocate is on exceptional path of an invoke statepoint
803 const BasicBlock *InvokeBB =
804 cast<Instruction>(Token)->getParent()->getUniquePredecessor();
805
806 assert(InvokeBB && "safepoints should have unique landingpads");
807 assert(InvokeBB->getTerminator() &&
808 "safepoint block should be well formed");
809
810 return cast<GCStatepointInst>(InvokeBB->getTerminator());
811}
812
814 auto Statepoint = getStatepoint();
815 if (isa<UndefValue>(Statepoint))
816 return UndefValue::get(Statepoint->getType());
817
818 auto *GCInst = cast<GCStatepointInst>(Statepoint);
819 if (auto Opt = GCInst->getOperandBundle(LLVMContext::OB_gc_live))
820 return *(Opt->Inputs.begin() + getBasePtrIndex());
821 return *(GCInst->arg_begin() + getBasePtrIndex());
822}
823
825 auto *Statepoint = getStatepoint();
826 if (isa<UndefValue>(Statepoint))
827 return UndefValue::get(Statepoint->getType());
828
829 auto *GCInst = cast<GCStatepointInst>(Statepoint);
830 if (auto Opt = GCInst->getOperandBundle(LLVMContext::OB_gc_live))
831 return *(Opt->Inputs.begin() + getDerivedPtrIndex());
832 return *(GCInst->arg_begin() + getDerivedPtrIndex());
833}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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
uint64_t Addr
std::string Name
static ICmpInst::Predicate getIntPredicateFromMD(const Value *Op)
static ValueAsMetadata * getAsMetadata(Value *V)
static FCmpInst::Predicate getFPPredicateFromMD(const Value *Op)
#define I(x, y, z)
Definition: MD5.cpp:58
This file contains the declarations for metadata subclasses.
Module.h This file contains the declarations for the Module class.
uint64_t High
LLVMContext & Context
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:152
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
iterator begin() const
Definition: ArrayRef.h:151
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:112
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.h:127
unsigned getNoWrapKind() const
Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
bool isSigned() const
Whether the intrinsic is signed or unsigned.
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).
Definition: InstrTypes.h:1752
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1351
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1356
unsigned arg_size() const
Definition: InstrTypes.h:1349
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:718
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:721
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:747
@ ICMP_SLE
signed less or equal
Definition: InstrTypes.h:748
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:724
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:733
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:722
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:723
@ ICMP_UGE
unsigned greater or equal
Definition: InstrTypes.h:742
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:741
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:745
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:732
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:726
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:729
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:743
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:730
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:725
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:727
@ ICMP_EQ
equal
Definition: InstrTypes.h:739
@ ICMP_NE
not equal
Definition: InstrTypes.h:740
@ ICMP_SGE
signed greater or equal
Definition: InstrTypes.h:746
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:734
@ ICMP_ULE
unsigned less or equal
Definition: InstrTypes.h:744
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:731
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition: InstrTypes.h:728
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:887
FCmpInst::Predicate getPredicate() const
std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
std::optional< RoundingMode > getRoundingMode() const
static bool classof(const IntrinsicInst *I)
Assignment ID.
DWARF expression.
std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
void setAssignId(DIAssignID *New)
void setKillAddress()
Kill the address component.
bool isKillAddress() const
Check whether this kills the address component.
Metadata * getRawAddress() const
Value * getAddress() const
void addVariableLocationOps(ArrayRef< Value * > NewValues, DIExpression *NewExpr)
Adding a new location operand will always result in this intrinsic using an ArgList,...
void replaceVariableLocationOp(Value *OldValue, Value *NewValue)
Value * getVariableLocationOp(unsigned OpIdx) const
Metadata * getRawLocation() const
DILocalVariable * getVariable() const
unsigned getNumVariableLocationOps() const
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
void setOperand(unsigned i, Value *v)
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)
const Value * getStatepoint() const
The statepoint with which this gc.relocate is associated.
Value * getBasePtr() const
unsigned getBasePtrIndex() const
The index into the associate statepoint's argument list which contains the base pointer of the pointe...
Value * getDerivedPtr() const
unsigned getDerivedPtrIndex() const
The index into the associate statepoint's argument list which contains the pointer whose relocation t...
static bool classof(const IntrinsicInst *I)
ConstantInt * getNumCounters() const
ConstantInt * getIndex() const
static bool classof(const IntrinsicInst *I)
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:70
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:47
static 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.
Definition: IntrinsicInst.h:54
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1399
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:102
Root of the metadata hierarchy.
Definition: Metadata.h:61
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
static constexpr size_t npos
Definition: StringRef.h:52
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:249
static IntegerType * getInt64Ty(LLVMContext &C)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1740
unsigned getNumOperands() const
Definition: User.h:191
static bool isVPCast(Intrinsic::ID ID)
static bool isVPCmp(Intrinsic::ID ID)
CmpInst::Predicate getPredicate() const
static Function * getDeclarationForParams(Module *M, Intrinsic::ID, Type *ReturnType, ArrayRef< Value * > Params)
Declares a llvm.vp.
static std::optional< unsigned > getMaskParamPos(Intrinsic::ID IntrinsicID)
bool canIgnoreVectorLengthParam() const
void setMaskParam(Value *)
static std::optional< unsigned > getFunctionalOpcodeForVP(Intrinsic::ID ID)
static std::optional< unsigned > getMemoryDataParamPos(Intrinsic::ID)
Value * getVectorLengthParam() const
void setVectorLengthParam(Value *)
static std::optional< unsigned > getVectorLengthParamPos(Intrinsic::ID IntrinsicID)
static Intrinsic::ID getForOpcode(unsigned OC)
The llvm.vp.* intrinsics for this instruction Opcode.
static std::optional< unsigned > getMemoryPointerParamPos(Intrinsic::ID)
static bool isVPIntrinsic(Intrinsic::ID)
Value * getMemoryDataParam() const
Value * getMemoryPointerParam() const
MaybeAlign getPointerAlignment() const
Value * getMaskParam() const
ElementCount getStaticVectorLength() const
static bool isVPReduction(Intrinsic::ID ID)
unsigned getStartParamPos() const
unsigned getVectorParamPos() const
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:344
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:392
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
A range adaptor for a pair of iterators.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
int lookupLLVMIntrinsicByName(ArrayRef< const char * > NameTable, StringRef Name)
Looks up Name in NameTable via binary search.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1502
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Definition: PatternMatch.h:147
VScaleVal_match m_VScale(const DataLayout &DL)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition: FPEnv.h:39
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
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:1755
std::optional< fp::ExceptionBehavior > convertStrToExceptionBehavior(StringRef)
Returns a valid ExceptionBehavior enumerator when given a string valid as input in constrained intrin...
Definition: FPEnv.cpp:65
@ NearestTiesToEven
roundTiesToEven.
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:24
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1869
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117