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 assert(MD && "First operand of DbgVariableIntrinsic should be non-null.");
77 // If operand is ValueAsMetadata, return a range over just that operand.
78 if (auto *VAM = dyn_cast<ValueAsMetadata>(MD)) {
79 return {location_op_iterator(VAM), location_op_iterator(VAM + 1)};
80 }
81 // If operand is DIArgList, return a range over its args.
82 if (auto *AL = dyn_cast<DIArgList>(MD))
83 return {location_op_iterator(AL->args_begin()),
84 location_op_iterator(AL->args_end())};
85 // Operand must be an empty metadata tuple, so return empty iterator.
86 return {location_op_iterator(static_cast<ValueAsMetadata *>(nullptr)),
87 location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
88}
89
93}
94
97}
98
100 Metadata *MD = getRawLocation();
101 assert(MD && "First operand of DbgVariableIntrinsic should be non-null.");
102 if (auto *AL = dyn_cast<DIArgList>(MD))
103 return AL->getArgs()[OpIdx]->getValue();
104 if (isa<MDNode>(MD))
105 return nullptr;
106 assert(
107 isa<ValueAsMetadata>(MD) &&
108 "Attempted to get location operand from DbgVariableIntrinsic with none.");
109 auto *V = cast<ValueAsMetadata>(MD);
110 assert(OpIdx == 0 && "Operand Index must be 0 for a debug intrinsic with a "
111 "single location operand.");
112 return V->getValue();
113}
114
116 return isa<MetadataAsValue>(V) ? dyn_cast<ValueAsMetadata>(
117 cast<MetadataAsValue>(V)->getMetadata())
119}
120
122 Value *NewValue) {
123 // If OldValue is used as the address part of a dbg.assign intrinsic replace
124 // it with NewValue and return true.
125 auto ReplaceDbgAssignAddress = [this, OldValue, NewValue]() -> bool {
126 auto *DAI = dyn_cast<DbgAssignIntrinsic>(this);
127 if (!DAI || OldValue != DAI->getAddress())
128 return false;
129 DAI->setAddress(NewValue);
130 return true;
131 };
132 bool DbgAssignAddrReplaced = ReplaceDbgAssignAddress();
133 (void)DbgAssignAddrReplaced;
134
135 assert(NewValue && "Values must be non-null");
136 auto Locations = location_ops();
137 auto OldIt = find(Locations, OldValue);
138 assert((OldIt != Locations.end() || DbgAssignAddrReplaced) &&
139 "OldValue must be a current location");
140 if (!hasArgList()) {
141 // Additional check necessary to avoid unconditionally replacing this
142 // operand when a dbg.assign address is replaced (DbgAssignAddrReplaced is
143 // true).
144 if (OldValue != getVariableLocationOp(0))
145 return;
146 Value *NewOperand = isa<MetadataAsValue>(NewValue)
147 ? NewValue
149 getContext(), ValueAsMetadata::get(NewValue));
150 return setArgOperand(0, NewOperand);
151 }
153 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
154 for (auto *VMD : Locations)
155 MDs.push_back(VMD == *OldIt ? NewOperand : getAsMetadata(VMD));
158}
160 Value *NewValue) {
161 assert(OpIdx < getNumVariableLocationOps() && "Invalid Operand Index");
162 if (!hasArgList()) {
163 Value *NewOperand = isa<MetadataAsValue>(NewValue)
164 ? NewValue
166 getContext(), ValueAsMetadata::get(NewValue));
167 return setArgOperand(0, NewOperand);
168 }
170 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
171 for (unsigned Idx = 0; Idx < getNumVariableLocationOps(); ++Idx)
172 MDs.push_back(Idx == OpIdx ? NewOperand
176}
177
180 assert(NewExpr->hasAllLocationOps(getNumVariableLocationOps() +
181 NewValues.size()) &&
182 "NewExpr for debug variable intrinsic does not reference every "
183 "location operand.");
184 assert(!is_contained(NewValues, nullptr) && "New values must be non-null");
187 for (auto *VMD : location_ops())
188 MDs.push_back(getAsMetadata(VMD));
189 for (auto *VMD : NewValues)
190 MDs.push_back(getAsMetadata(VMD));
193}
194
195std::optional<uint64_t> DbgVariableIntrinsic::getFragmentSizeInBits() const {
196 if (auto Fragment = getExpression()->getFragmentInfo())
197 return Fragment->SizeInBits;
198 return getVariable()->getSizeInBits();
199}
200
202 auto *MD = getRawAddress();
203 if (auto *V = dyn_cast<ValueAsMetadata>(MD))
204 return V->getValue();
205
206 // When the value goes to null, it gets replaced by an empty MDNode.
207 assert(!cast<MDNode>(MD)->getNumOperands() && "Expected an empty MDNode");
208 return nullptr;
209}
210
212 setOperand(OpAssignID, MetadataAsValue::get(getContext(), New));
213}
214
216 assert(V->getType()->isPointerTy() &&
217 "Destination Component must be a pointer type");
218 setOperand(OpAddress,
220}
221
223 if (isKillAddress())
224 return;
226}
227
229 Value *Addr = getAddress();
230 return !Addr || isa<UndefValue>(Addr);
231}
232
234 setOperand(OpValue,
236}
237
239 StringRef Name) {
240 assert(Name.startswith("llvm."));
241
242 // Do successive binary searches of the dotted name components. For
243 // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
244 // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
245 // "llvm.gc.experimental.statepoint", and then we will stop as the range is
246 // size 1. During the search, we can skip the prefix that we already know is
247 // identical. By using strncmp we consider names with differing suffixes to
248 // be part of the equal range.
249 size_t CmpEnd = 4; // Skip the "llvm" component.
250 const char *const *Low = NameTable.begin();
251 const char *const *High = NameTable.end();
252 const char *const *LastLow = Low;
253 while (CmpEnd < Name.size() && High - Low > 0) {
254 size_t CmpStart = CmpEnd;
255 CmpEnd = Name.find('.', CmpStart + 1);
256 CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
257 auto Cmp = [CmpStart, CmpEnd](const char *LHS, const char *RHS) {
258 return strncmp(LHS + CmpStart, RHS + CmpStart, CmpEnd - CmpStart) < 0;
259 };
260 LastLow = Low;
261 std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
262 }
263 if (High - Low > 0)
264 LastLow = Low;
265
266 if (LastLow == NameTable.end())
267 return -1;
268 StringRef NameFound = *LastLow;
269 if (Name == NameFound ||
270 (Name.startswith(NameFound) && Name[NameFound.size()] == '.'))
271 return LastLow - NameTable.begin();
272 return -1;
273}
274
277 llvm_unreachable("InstrProfValueProfileInst does not have counters!");
278 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
279}
280
283 llvm_unreachable("Please use InstrProfValueProfileInst::getIndex()");
284 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
285}
286
289 return const_cast<Value *>(getArgOperand(4));
290 }
291 const Module *M = getModule();
292 LLVMContext &Context = M->getContext();
294}
295
296std::optional<RoundingMode> ConstrainedFPIntrinsic::getRoundingMode() const {
297 unsigned NumOperands = arg_size();
298 Metadata *MD = nullptr;
299 auto *MAV = dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 2));
300 if (MAV)
301 MD = MAV->getMetadata();
302 if (!MD || !isa<MDString>(MD))
303 return std::nullopt;
304 return convertStrToRoundingMode(cast<MDString>(MD)->getString());
305}
306
307std::optional<fp::ExceptionBehavior>
309 unsigned NumOperands = arg_size();
310 Metadata *MD = nullptr;
311 auto *MAV = dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 1));
312 if (MAV)
313 MD = MAV->getMetadata();
314 if (!MD || !isa<MDString>(MD))
315 return std::nullopt;
316 return convertStrToExceptionBehavior(cast<MDString>(MD)->getString());
317}
318
320 std::optional<fp::ExceptionBehavior> Except = getExceptionBehavior();
321 if (Except) {
322 if (*Except != fp::ebIgnore)
323 return false;
324 }
325
326 std::optional<RoundingMode> Rounding = getRoundingMode();
327 if (Rounding) {
328 if (*Rounding != RoundingMode::NearestTiesToEven)
329 return false;
330 }
331
332 return true;
333}
334
336 Metadata *MD = cast<MetadataAsValue>(Op)->getMetadata();
337 if (!MD || !isa<MDString>(MD))
339 return StringSwitch<FCmpInst::Predicate>(cast<MDString>(MD)->getString())
340 .Case("oeq", FCmpInst::FCMP_OEQ)
341 .Case("ogt", FCmpInst::FCMP_OGT)
342 .Case("oge", FCmpInst::FCMP_OGE)
343 .Case("olt", FCmpInst::FCMP_OLT)
344 .Case("ole", FCmpInst::FCMP_OLE)
345 .Case("one", FCmpInst::FCMP_ONE)
346 .Case("ord", FCmpInst::FCMP_ORD)
347 .Case("uno", FCmpInst::FCMP_UNO)
348 .Case("ueq", FCmpInst::FCMP_UEQ)
349 .Case("ugt", FCmpInst::FCMP_UGT)
350 .Case("uge", FCmpInst::FCMP_UGE)
351 .Case("ult", FCmpInst::FCMP_ULT)
352 .Case("ule", FCmpInst::FCMP_ULE)
353 .Case("une", FCmpInst::FCMP_UNE)
355}
356
359}
360
362 switch (getIntrinsicID()) {
363 default:
364 return false;
365#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
366 case Intrinsic::INTRINSIC: \
367 return NARG == 1;
368#include "llvm/IR/ConstrainedOps.def"
369 }
370}
371
373 switch (getIntrinsicID()) {
374 default:
375 return false;
376#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
377 case Intrinsic::INTRINSIC: \
378 return NARG == 3;
379#include "llvm/IR/ConstrainedOps.def"
380 }
381}
382
384 switch (I->getIntrinsicID()) {
385#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
386 case Intrinsic::INTRINSIC:
387#include "llvm/IR/ConstrainedOps.def"
388 return true;
389 default:
390 return false;
391 }
392}
393
395 auto GetVectorLengthOfType = [](const Type *T) -> ElementCount {
396 const auto *VT = cast<VectorType>(T);
397 auto ElemCount = VT->getElementCount();
398 return ElemCount;
399 };
400
401 Value *VPMask = getMaskParam();
402 if (!VPMask) {
403 assert((getIntrinsicID() == Intrinsic::vp_merge ||
404 getIntrinsicID() == Intrinsic::vp_select) &&
405 "Unexpected VP intrinsic without mask operand");
406 return GetVectorLengthOfType(getType());
407 }
408 return GetVectorLengthOfType(VPMask->getType());
409}
410
412 if (auto MaskPos = getMaskParamPos(getIntrinsicID()))
413 return getArgOperand(*MaskPos);
414 return nullptr;
415}
416
418 auto MaskPos = getMaskParamPos(getIntrinsicID());
419 setArgOperand(*MaskPos, NewMask);
420}
421
423 if (auto EVLPos = getVectorLengthParamPos(getIntrinsicID()))
424 return getArgOperand(*EVLPos);
425 return nullptr;
426}
427
430 setArgOperand(*EVLPos, NewEVL);
431}
432
433std::optional<unsigned>
435 switch (IntrinsicID) {
436 default:
437 return std::nullopt;
438
439#define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \
440 case Intrinsic::VPID: \
441 return MASKPOS;
442#include "llvm/IR/VPIntrinsics.def"
443 }
444}
445
446std::optional<unsigned>
448 switch (IntrinsicID) {
449 default:
450 return std::nullopt;
451
452#define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \
453 case Intrinsic::VPID: \
454 return VLENPOS;
455#include "llvm/IR/VPIntrinsics.def"
456 }
457}
458
459/// \return the alignment of the pointer used by this load/store/gather or
460/// scatter.
462 std::optional<unsigned> PtrParamOpt =
464 assert(PtrParamOpt && "no pointer argument!");
465 return getParamAlign(*PtrParamOpt);
466}
467
468/// \return The pointer operand of this load,store, gather or scatter.
470 if (auto PtrParamOpt = getMemoryPointerParamPos(getIntrinsicID()))
471 return getArgOperand(*PtrParamOpt);
472 return nullptr;
473}
474
475std::optional<unsigned>
477 switch (VPID) {
478 default:
479 break;
480#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
481#define VP_PROPERTY_MEMOP(POINTERPOS, ...) return POINTERPOS;
482#define END_REGISTER_VP_INTRINSIC(VPID) break;
483#include "llvm/IR/VPIntrinsics.def"
484 }
485 return std::nullopt;
486}
487
488/// \return The data (payload) operand of this store or scatter.
490 auto DataParamOpt = getMemoryDataParamPos(getIntrinsicID());
491 if (!DataParamOpt)
492 return nullptr;
493 return getArgOperand(*DataParamOpt);
494}
495
497 switch (VPID) {
498 default:
499 break;
500#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
501#define VP_PROPERTY_MEMOP(POINTERPOS, DATAPOS) return DATAPOS;
502#define END_REGISTER_VP_INTRINSIC(VPID) break;
503#include "llvm/IR/VPIntrinsics.def"
504 }
505 return std::nullopt;
506}
507
509 switch (ID) {
510 default:
511 break;
512#define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \
513 case Intrinsic::VPID: \
514 return true;
515#include "llvm/IR/VPIntrinsics.def"
516 }
517 return false;
518}
519
520// Equivalent non-predicated opcode
521std::optional<unsigned>
523 switch (ID) {
524 default:
525 break;
526#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
527#define VP_PROPERTY_FUNCTIONAL_OPC(OPC) return Instruction::OPC;
528#define END_REGISTER_VP_INTRINSIC(VPID) break;
529#include "llvm/IR/VPIntrinsics.def"
530 }
531 return std::nullopt;
532}
533
535 switch (IROPC) {
536 default:
537 break;
538
539#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) break;
540#define VP_PROPERTY_FUNCTIONAL_OPC(OPC) case Instruction::OPC:
541#define END_REGISTER_VP_INTRINSIC(VPID) return Intrinsic::VPID;
542#include "llvm/IR/VPIntrinsics.def"
543 }
545}
546
548 using namespace PatternMatch;
549
551
552 // No vlen param - no lanes masked-off by it.
553 auto *VLParam = getVectorLengthParam();
554 if (!VLParam)
555 return true;
556
557 // Note that the VP intrinsic causes undefined behavior if the Explicit Vector
558 // Length parameter is strictly greater-than the number of vector elements of
559 // the operation. This function returns true when this is detected statically
560 // in the IR.
561
562 // Check whether "W == vscale * EC.getKnownMinValue()"
563 if (EC.isScalable()) {
564 // Compare vscale patterns
565 uint64_t VScaleFactor;
566 if (match(VLParam, m_c_Mul(m_ConstantInt(VScaleFactor), m_VScale())))
567 return VScaleFactor >= EC.getKnownMinValue();
568 return (EC.getKnownMinValue() == 1) && match(VLParam, m_VScale());
569 }
570
571 // standard SIMD operation
572 const auto *VLConst = dyn_cast<ConstantInt>(VLParam);
573 if (!VLConst)
574 return false;
575
576 uint64_t VLNum = VLConst->getZExtValue();
577 if (VLNum >= EC.getKnownMinValue())
578 return true;
579
580 return false;
581}
582
584 Type *ReturnType,
585 ArrayRef<Value *> Params) {
586 assert(isVPIntrinsic(VPID) && "not a VP intrinsic");
587 Function *VPFunc;
588 switch (VPID) {
589 default: {
590 Type *OverloadTy = Params[0]->getType();
592 OverloadTy =
593 Params[*VPReductionIntrinsic::getVectorParamPos(VPID)]->getType();
594
595 VPFunc = Intrinsic::getDeclaration(M, VPID, OverloadTy);
596 break;
597 }
598 case Intrinsic::vp_trunc:
599 case Intrinsic::vp_sext:
600 case Intrinsic::vp_zext:
601 case Intrinsic::vp_fptoui:
602 case Intrinsic::vp_fptosi:
603 case Intrinsic::vp_uitofp:
604 case Intrinsic::vp_sitofp:
605 case Intrinsic::vp_fptrunc:
606 case Intrinsic::vp_fpext:
607 case Intrinsic::vp_ptrtoint:
608 case Intrinsic::vp_inttoptr:
609 VPFunc =
610 Intrinsic::getDeclaration(M, VPID, {ReturnType, Params[0]->getType()});
611 break;
612 case Intrinsic::vp_merge:
613 case Intrinsic::vp_select:
614 VPFunc = Intrinsic::getDeclaration(M, VPID, {Params[1]->getType()});
615 break;
616 case Intrinsic::vp_load:
618 M, VPID, {ReturnType, Params[0]->getType()});
619 break;
620 case Intrinsic::experimental_vp_strided_load:
622 M, VPID, {ReturnType, Params[0]->getType(), Params[1]->getType()});
623 break;
624 case Intrinsic::vp_gather:
626 M, VPID, {ReturnType, Params[0]->getType()});
627 break;
628 case Intrinsic::vp_store:
630 M, VPID, {Params[0]->getType(), Params[1]->getType()});
631 break;
632 case Intrinsic::experimental_vp_strided_store:
634 M, VPID,
635 {Params[0]->getType(), Params[1]->getType(), Params[2]->getType()});
636 break;
637 case Intrinsic::vp_scatter:
639 M, VPID, {Params[0]->getType(), Params[1]->getType()});
640 break;
641 }
642 assert(VPFunc && "Could not declare VP intrinsic");
643 return VPFunc;
644}
645
647 switch (ID) {
648 default:
649 break;
650#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
651#define VP_PROPERTY_REDUCTION(STARTPOS, ...) return true;
652#define END_REGISTER_VP_INTRINSIC(VPID) break;
653#include "llvm/IR/VPIntrinsics.def"
654 }
655 return false;
656}
657
659 switch (ID) {
660 default:
661 break;
662#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
663#define VP_PROPERTY_CASTOP return true;
664#define END_REGISTER_VP_INTRINSIC(VPID) break;
665#include "llvm/IR/VPIntrinsics.def"
666 }
667 return false;
668}
669
671 switch (ID) {
672 default:
673 break;
674#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
675#define VP_PROPERTY_CMP(CCPOS, ...) return true;
676#define END_REGISTER_VP_INTRINSIC(VPID) break;
677#include "llvm/IR/VPIntrinsics.def"
678 }
679 return false;
680}
681
683 Metadata *MD = cast<MetadataAsValue>(Op)->getMetadata();
684 if (!MD || !isa<MDString>(MD))
686 return StringSwitch<ICmpInst::Predicate>(cast<MDString>(MD)->getString())
687 .Case("eq", ICmpInst::ICMP_EQ)
688 .Case("ne", ICmpInst::ICMP_NE)
689 .Case("ugt", ICmpInst::ICMP_UGT)
690 .Case("uge", ICmpInst::ICMP_UGE)
691 .Case("ult", ICmpInst::ICMP_ULT)
692 .Case("ule", ICmpInst::ICMP_ULE)
693 .Case("sgt", ICmpInst::ICMP_SGT)
694 .Case("sge", ICmpInst::ICMP_SGE)
695 .Case("slt", ICmpInst::ICMP_SLT)
696 .Case("sle", ICmpInst::ICMP_SLE)
698}
699
701 bool IsFP = true;
702 std::optional<unsigned> CCArgIdx;
703 switch (getIntrinsicID()) {
704 default:
705 break;
706#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
707#define VP_PROPERTY_CMP(CCPOS, ISFP) \
708 CCArgIdx = CCPOS; \
709 IsFP = ISFP; \
710 break;
711#define END_REGISTER_VP_INTRINSIC(VPID) break;
712#include "llvm/IR/VPIntrinsics.def"
713 }
714 assert(CCArgIdx && "Unexpected vector-predicated comparison");
715 return IsFP ? getFPPredicateFromMD(getArgOperand(*CCArgIdx))
717}
718
721}
722
725}
726
727std::optional<unsigned>
729 switch (ID) {
730#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
731#define VP_PROPERTY_REDUCTION(STARTPOS, VECTORPOS) return VECTORPOS;
732#define END_REGISTER_VP_INTRINSIC(VPID) break;
733#include "llvm/IR/VPIntrinsics.def"
734 default:
735 break;
736 }
737 return std::nullopt;
738}
739
740std::optional<unsigned>
742 switch (ID) {
743#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
744#define VP_PROPERTY_REDUCTION(STARTPOS, VECTORPOS) return STARTPOS;
745#define END_REGISTER_VP_INTRINSIC(VPID) break;
746#include "llvm/IR/VPIntrinsics.def"
747 default:
748 break;
749 }
750 return std::nullopt;
751}
752
754 switch (getIntrinsicID()) {
755 case Intrinsic::uadd_with_overflow:
756 case Intrinsic::sadd_with_overflow:
757 case Intrinsic::uadd_sat:
758 case Intrinsic::sadd_sat:
759 return Instruction::Add;
760 case Intrinsic::usub_with_overflow:
761 case Intrinsic::ssub_with_overflow:
762 case Intrinsic::usub_sat:
763 case Intrinsic::ssub_sat:
764 return Instruction::Sub;
765 case Intrinsic::umul_with_overflow:
766 case Intrinsic::smul_with_overflow:
767 return Instruction::Mul;
768 default:
769 llvm_unreachable("Invalid intrinsic");
770 }
771}
772
774 switch (getIntrinsicID()) {
775 case Intrinsic::sadd_with_overflow:
776 case Intrinsic::ssub_with_overflow:
777 case Intrinsic::smul_with_overflow:
778 case Intrinsic::sadd_sat:
779 case Intrinsic::ssub_sat:
780 return true;
781 default:
782 return false;
783 }
784}
785
787 if (isSigned())
789 else
791}
792
794 const Value *Token = getArgOperand(0);
795 if (isa<UndefValue>(Token))
796 return Token;
797
798 // This takes care both of relocates for call statepoints and relocates
799 // on normal path of invoke statepoint.
800 if (!isa<LandingPadInst>(Token))
801 return cast<GCStatepointInst>(Token);
802
803 // This relocate is on exceptional path of an invoke statepoint
804 const BasicBlock *InvokeBB =
805 cast<Instruction>(Token)->getParent()->getUniquePredecessor();
806
807 assert(InvokeBB && "safepoints should have unique landingpads");
808 assert(InvokeBB->getTerminator() &&
809 "safepoint block should be well formed");
810
811 return cast<GCStatepointInst>(InvokeBB->getTerminator());
812}
813
815 auto Statepoint = getStatepoint();
816 if (isa<UndefValue>(Statepoint))
817 return UndefValue::get(Statepoint->getType());
818
819 auto *GCInst = cast<GCStatepointInst>(Statepoint);
820 if (auto Opt = GCInst->getOperandBundle(LLVMContext::OB_gc_live))
821 return *(Opt->Inputs.begin() + getBasePtrIndex());
822 return *(GCInst->arg_begin() + getBasePtrIndex());
823}
824
826 auto *Statepoint = getStatepoint();
827 if (isa<UndefValue>(Statepoint))
828 return UndefValue::get(Statepoint->getType());
829
830 auto *GCInst = cast<GCStatepointInst>(Statepoint);
831 if (auto Opt = GCInst->getOperandBundle(LLVMContext::OB_gc_live))
832 return *(Opt->Inputs.begin() + getDerivedPtrIndex());
833 return *(GCInst->arg_begin() + getDerivedPtrIndex());
834}
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:1754
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1353
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1358
unsigned arg_size() const
Definition: InstrTypes.h:1351
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:888
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
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
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
DILocalVariable * getVariable() const
unsigned getNumVariableLocationOps() const
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)
RawLocationWrapper getWrappedLocation() const
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
Metadata * getRawLocation() const
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
Value * getVariableLocationOp(unsigned OpIdx) const
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
static IntegerType * getInt64Ty(LLVMContext &C)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1731
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:1506
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()
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:1839
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)
Returns true if Element is found in Range.
Definition: STLExtras.h:1976
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117