1//===- Function.cpp - Implement the Global object classes -----------------===//
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 the Function class for the IR library.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/Function.h"
14#include "SymbolTableListTraitsImpl.h"
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/ADT/BitVector.h"
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/SmallString.h"
20#include "llvm/ADT/SmallVector.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/IR/AbstractCallSite.h"
23#include "llvm/IR/Argument.h"
24#include "llvm/IR/Attributes.h"
25#include "llvm/IR/BasicBlock.h"
26#include "llvm/IR/Constant.h"
27#include "llvm/IR/ConstantRange.h"
28#include "llvm/IR/Constants.h"
29#include "llvm/IR/DerivedTypes.h"
30#include "llvm/IR/GlobalValue.h"
31#include "llvm/IR/InstIterator.h"
32#include "llvm/IR/Instruction.h"
33#include "llvm/IR/IntrinsicInst.h"
34#include "llvm/IR/Intrinsics.h"
35#include "llvm/IR/LLVMContext.h"
36#include "llvm/IR/MDBuilder.h"
37#include "llvm/IR/Metadata.h"
38#include "llvm/IR/Module.h"
39#include "llvm/IR/Operator.h"
40#include "llvm/IR/ProfDataUtils.h"
41#include "llvm/IR/SymbolTableListTraits.h"
42#include "llvm/IR/Type.h"
43#include "llvm/IR/Use.h"
44#include "llvm/IR/User.h"
45#include "llvm/IR/Value.h"
46#include "llvm/IR/ValueSymbolTable.h"
47#include "llvm/Support/Casting.h"
48#include "llvm/Support/CommandLine.h"
49#include "llvm/Support/Compiler.h"
50#include "llvm/Support/ErrorHandling.h"
51#include "llvm/Support/ModRef.h"
52#include <cassert>
53#include <cstddef>
54#include <cstdint>
55#include <cstring>
56#include <string>
57
58using namespace llvm;
59
60// Explicit instantiations of SymbolTableListTraits since some of the methods
61// are not in the public header file...
62template class LLVM_EXPORT_TEMPLATE llvm::SymbolTableListTraits<BasicBlock>;
63
64static cl::opt<int> NonGlobalValueMaxNameSize(
65 "non-global-value-max-name-size", cl::Hidden, cl::init(Val: 1024),
66 cl::desc("Maximum size for the name of non-global values."));
67
68void Function::renumberBlocks() {
69 validateBlockNumbers();
70
71 NextBlockNum = 0;
72 for (auto &BB : *this)
73 BB.Number = NextBlockNum++;
74 BlockNumEpoch++;
75}
76
77void Function::validateBlockNumbers() const {
78#ifndef NDEBUG
79 BitVector Numbers(NextBlockNum);
80 for (const auto &BB : *this) {
81 unsigned Num = BB.getNumber();
82 assert(Num < NextBlockNum && "out of range block number");
83 assert(!Numbers[Num] && "duplicate block numbers");
84 Numbers.set(Num);
85 }
86#endif
87}
88
89void Function::convertToNewDbgValues() {
90 for (auto &BB : *this) {
91 BB.convertToNewDbgValues();
92 }
93}
94
95void Function::convertFromNewDbgValues() {
96 for (auto &BB : *this) {
97 BB.convertFromNewDbgValues();
98 }
99}
100
101//===----------------------------------------------------------------------===//
102// Argument Implementation
103//===----------------------------------------------------------------------===//
104
105Argument::Argument(Type *Ty, const Twine &Name, Function *Par, unsigned ArgNo)
106 : Value(Ty, Value::ArgumentVal), Parent(Par), ArgNo(ArgNo) {
107 setName(Name);
108}
109
110void Argument::setParent(Function *parent) {
111 Parent = parent;
112}
113
114bool Argument::hasNonNullAttr(bool AllowUndefOrPoison) const {
115 if (!getType()->isPointerTy()) return false;
116 AttributeSet Attrs = getAttributes();
117 if (Attrs.hasAttribute(Kind: Attribute::NonNull) &&
118 (AllowUndefOrPoison || Attrs.hasAttribute(Kind: Attribute::NoUndef)))
119 return true;
120 else if (getDereferenceableBytes() > 0 &&
121 !NullPointerIsDefined(F: getParent(),
122 AS: getType()->getPointerAddressSpace()))
123 return true;
124 return false;
125}
126
127bool Argument::hasByValAttr() const {
128 if (!getType()->isPointerTy()) return false;
129 return hasAttribute(Kind: Attribute::ByVal);
130}
131
132DeadOnReturnInfo Argument::getDeadOnReturnInfo() const {
133 assert(getType()->isPointerTy() && "Only pointers have dead_on_return bytes");
134 return getParent()->getDeadOnReturnInfo(ArgNo: getArgNo());
135}
136
137bool Argument::hasByRefAttr() const {
138 if (!getType()->isPointerTy())
139 return false;
140 return hasAttribute(Kind: Attribute::ByRef);
141}
142
143bool Argument::hasSwiftSelfAttr() const {
144 return getParent()->hasParamAttribute(ArgNo: getArgNo(), Kind: Attribute::SwiftSelf);
145}
146
147bool Argument::hasSwiftErrorAttr() const {
148 return getParent()->hasParamAttribute(ArgNo: getArgNo(), Kind: Attribute::SwiftError);
149}
150
151bool Argument::hasInAllocaAttr() const {
152 if (!getType()->isPointerTy()) return false;
153 return hasAttribute(Kind: Attribute::InAlloca);
154}
155
156bool Argument::hasPreallocatedAttr() const {
157 if (!getType()->isPointerTy())
158 return false;
159 return hasAttribute(Kind: Attribute::Preallocated);
160}
161
162bool Argument::hasPassPointeeByValueCopyAttr() const {
163 if (!getType()->isPointerTy()) return false;
164 AttributeSet Attrs = getAttributes();
165 return Attrs.hasAttribute(Kind: Attribute::ByVal) ||
166 Attrs.hasAttribute(Kind: Attribute::InAlloca) ||
167 Attrs.hasAttribute(Kind: Attribute::Preallocated);
168}
169
170bool Argument::hasPointeeInMemoryValueAttr() const {
171 if (!getType()->isPointerTy())
172 return false;
173 AttributeSet Attrs = getAttributes();
174 return Attrs.hasAttribute(Kind: Attribute::ByVal) ||
175 Attrs.hasAttribute(Kind: Attribute::StructRet) ||
176 Attrs.hasAttribute(Kind: Attribute::InAlloca) ||
177 Attrs.hasAttribute(Kind: Attribute::Preallocated) ||
178 Attrs.hasAttribute(Kind: Attribute::ByRef);
179}
180
181/// For a byval, sret, inalloca, or preallocated parameter, get the in-memory
182/// parameter type.
183static Type *getMemoryParamAllocType(AttributeSet ParamAttrs) {
184 // FIXME: All the type carrying attributes are mutually exclusive, so there
185 // should be a single query to get the stored type that handles any of them.
186 if (Type *ByValTy = ParamAttrs.getByValType())
187 return ByValTy;
188 if (Type *ByRefTy = ParamAttrs.getByRefType())
189 return ByRefTy;
190 if (Type *PreAllocTy = ParamAttrs.getPreallocatedType())
191 return PreAllocTy;
192 if (Type *InAllocaTy = ParamAttrs.getInAllocaType())
193 return InAllocaTy;
194 if (Type *SRetTy = ParamAttrs.getStructRetType())
195 return SRetTy;
196
197 return nullptr;
198}
199
200uint64_t Argument::getPassPointeeByValueCopySize(const DataLayout &DL) const {
201 if (Type *MemTy = getMemoryParamAllocType(ParamAttrs: getAttributes()))
202 return DL.getTypeAllocSize(Ty: MemTy);
203 return 0;
204}
205
206Type *Argument::getPointeeInMemoryValueType() const {
207 return getMemoryParamAllocType(ParamAttrs: getAttributes());
208}
209
210MaybeAlign Argument::getParamAlign() const {
211 assert(getType()->isPointerTy() && "Only pointers have alignments");
212 return getParent()->getParamAlign(ArgNo: getArgNo());
213}
214
215MaybeAlign Argument::getParamStackAlign() const {
216 return getParent()->getParamStackAlign(ArgNo: getArgNo());
217}
218
219Type *Argument::getParamByValType() const {
220 assert(getType()->isPointerTy() && "Only pointers have byval types");
221 return getParent()->getParamByValType(ArgNo: getArgNo());
222}
223
224Type *Argument::getParamStructRetType() const {
225 assert(getType()->isPointerTy() && "Only pointers have sret types");
226 return getParent()->getParamStructRetType(ArgNo: getArgNo());
227}
228
229Type *Argument::getParamByRefType() const {
230 assert(getType()->isPointerTy() && "Only pointers have byref types");
231 return getParent()->getParamByRefType(ArgNo: getArgNo());
232}
233
234Type *Argument::getParamInAllocaType() const {
235 assert(getType()->isPointerTy() && "Only pointers have inalloca types");
236 return getParent()->getParamInAllocaType(ArgNo: getArgNo());
237}
238
239uint64_t Argument::getDereferenceableBytes() const {
240 assert(getType()->isPointerTy() &&
241 "Only pointers have dereferenceable bytes");
242 return getParent()->getParamDereferenceableBytes(ArgNo: getArgNo());
243}
244
245uint64_t Argument::getDereferenceableOrNullBytes() const {
246 assert(getType()->isPointerTy() &&
247 "Only pointers have dereferenceable bytes");
248 return getParent()->getParamDereferenceableOrNullBytes(ArgNo: getArgNo());
249}
250
251FPClassTest Argument::getNoFPClass() const {
252 return getParent()->getParamNoFPClass(ArgNo: getArgNo());
253}
254
255std::optional<ConstantRange> Argument::getRange() const {
256 const Attribute RangeAttr = getAttribute(Kind: llvm::Attribute::Range);
257 if (RangeAttr.isValid())
258 return RangeAttr.getRange();
259 return std::nullopt;
260}
261
262bool Argument::hasNestAttr() const {
263 if (!getType()->isPointerTy()) return false;
264 return hasAttribute(Kind: Attribute::Nest);
265}
266
267bool Argument::hasNoAliasAttr() const {
268 if (!getType()->isPointerTy()) return false;
269 return hasAttribute(Kind: Attribute::NoAlias);
270}
271
272bool Argument::hasNoCaptureAttr() const {
273 if (!getType()->isPointerTy()) return false;
274 return capturesNothing(CC: getAttributes().getCaptureInfo());
275}
276
277bool Argument::hasNoFreeAttr() const {
278 if (!getType()->isPointerTy()) return false;
279 return hasAttribute(Kind: Attribute::NoFree);
280}
281
282bool Argument::hasStructRetAttr() const {
283 if (!getType()->isPointerTy()) return false;
284 return hasAttribute(Kind: Attribute::StructRet);
285}
286
287bool Argument::hasInRegAttr() const {
288 return hasAttribute(Kind: Attribute::InReg);
289}
290
291bool Argument::hasReturnedAttr() const {
292 return hasAttribute(Kind: Attribute::Returned);
293}
294
295bool Argument::hasZExtAttr() const {
296 return hasAttribute(Kind: Attribute::ZExt);
297}
298
299bool Argument::hasSExtAttr() const {
300 return hasAttribute(Kind: Attribute::SExt);
301}
302
303bool Argument::onlyReadsMemory() const {
304 AttributeSet Attrs = getAttributes();
305 return Attrs.hasAttribute(Kind: Attribute::ReadOnly) ||
306 Attrs.hasAttribute(Kind: Attribute::ReadNone);
307}
308
309void Argument::addAttrs(AttrBuilder &B) {
310 AttributeList AL = getParent()->getAttributes();
311 AL = AL.addParamAttributes(C&: Parent->getContext(), ArgNo: getArgNo(), B);
312 getParent()->setAttributes(AL);
313}
314
315void Argument::addAttr(Attribute::AttrKind Kind) {
316 getParent()->addParamAttr(ArgNo: getArgNo(), Kind);
317}
318
319void Argument::addAttr(Attribute Attr) {
320 getParent()->addParamAttr(ArgNo: getArgNo(), Attr);
321}
322
323void Argument::removeAttr(Attribute::AttrKind Kind) {
324 getParent()->removeParamAttr(ArgNo: getArgNo(), Kind);
325}
326
327void Argument::removeAttrs(const AttributeMask &AM) {
328 AttributeList AL = getParent()->getAttributes();
329 AL = AL.removeParamAttributes(C&: Parent->getContext(), ArgNo: getArgNo(), AttrsToRemove: AM);
330 getParent()->setAttributes(AL);
331}
332
333bool Argument::hasAttribute(Attribute::AttrKind Kind) const {
334 return getParent()->hasParamAttribute(ArgNo: getArgNo(), Kind);
335}
336
337bool Argument::hasAttribute(StringRef Kind) const {
338 return getParent()->hasParamAttribute(ArgNo: getArgNo(), Kind);
339}
340
341Attribute Argument::getAttribute(Attribute::AttrKind Kind) const {
342 return getParent()->getParamAttribute(ArgNo: getArgNo(), Kind);
343}
344
345AttributeSet Argument::getAttributes() const {
346 return getParent()->getAttributes().getParamAttrs(ArgNo: getArgNo());
347}
348
349//===----------------------------------------------------------------------===//
350// Helper Methods in Function
351//===----------------------------------------------------------------------===//
352
353LLVMContext &Function::getContext() const {
354 return getType()->getContext();
355}
356
357const DataLayout &Function::getDataLayout() const {
358 return getParent()->getDataLayout();
359}
360
361unsigned Function::getInstructionCount() const {
362 unsigned NumInstrs = 0;
363 for (const BasicBlock &BB : BasicBlocks)
364 NumInstrs += BB.size();
365 return NumInstrs;
366}
367
368Function *Function::Create(FunctionType *Ty, LinkageTypes Linkage,
369 const Twine &N, Module &M) {
370 return Create(Ty, Linkage, AddrSpace: M.getDataLayout().getProgramAddressSpace(), N, M: &M);
371}
372
373Function *Function::createWithDefaultAttr(FunctionType *Ty,
374 LinkageTypes Linkage,
375 unsigned AddrSpace, const Twine &N,
376 Module *M) {
377 auto *F = new (AllocMarker) Function(Ty, Linkage, AddrSpace, N, M);
378 AttrBuilder B(F->getContext());
379 UWTableKind UWTable = M->getUwtable();
380 if (UWTable != UWTableKind::None)
381 B.addUWTableAttr(Kind: UWTable);
382 switch (M->getFramePointer()) {
383 case FramePointerKind::None:
384 // 0 ("none") is the default.
385 break;
386 case FramePointerKind::Reserved:
387 B.addAttribute(A: "frame-pointer", V: "reserved");
388 break;
389 case FramePointerKind::NonLeaf:
390 B.addAttribute(A: "frame-pointer", V: "non-leaf");
391 break;
392 case FramePointerKind::NonLeafNoReserve:
393 B.addAttribute(A: "frame-pointer", V: "non-leaf-no-reserve");
394 break;
395 case FramePointerKind::All:
396 B.addAttribute(A: "frame-pointer", V: "all");
397 break;
398 }
399 if (M->getModuleFlag(Key: "function_return_thunk_extern"))
400 B.addAttribute(Val: Attribute::FnRetThunkExtern);
401 StringRef DefaultCPU = F->getContext().getDefaultTargetCPU();
402 if (!DefaultCPU.empty())
403 B.addAttribute(A: "target-cpu", V: DefaultCPU);
404 StringRef DefaultFeatures = F->getContext().getDefaultTargetFeatures();
405 if (!DefaultFeatures.empty())
406 B.addAttribute(A: "target-features", V: DefaultFeatures);
407
408 // Check if the module attribute is present and not zero.
409 auto isModuleAttributeSet = [&](const StringRef &ModAttr) -> bool {
410 const auto *Attr =
411 mdconst::extract_or_null<ConstantInt>(MD: M->getModuleFlag(Key: ModAttr));
412 return Attr && !Attr->isZero();
413 };
414
415 auto AddAttributeIfSet = [&](const StringRef &ModAttr) {
416 if (isModuleAttributeSet(ModAttr))
417 B.addAttribute(A: ModAttr);
418 };
419
420 StringRef SignType = "none";
421 if (isModuleAttributeSet("sign-return-address"))
422 SignType = "non-leaf";
423 if (isModuleAttributeSet("sign-return-address-all"))
424 SignType = "all";
425 if (SignType != "none") {
426 B.addAttribute(A: "sign-return-address", V: SignType);
427 B.addAttribute(A: "sign-return-address-key",
428 V: isModuleAttributeSet("sign-return-address-with-bkey")
429 ? "b_key"
430 : "a_key");
431 }
432 AddAttributeIfSet("branch-target-enforcement");
433 AddAttributeIfSet("branch-protection-pauth-lr");
434 AddAttributeIfSet("guarded-control-stack");
435 AddAttributeIfSet("ptrauth-returns");
436 AddAttributeIfSet("ptrauth-auth-traps");
437 AddAttributeIfSet("ptrauth-indirect-gotos");
438 AddAttributeIfSet("aarch64-jump-table-hardening");
439
440 F->addFnAttrs(Attrs: B);
441 return F;
442}
443
444void Function::removeFromParent() {
445 getParent()->getFunctionList().remove(IT: getIterator());
446}
447
448void Function::eraseFromParent() {
449 getParent()->getFunctionList().erase(where: getIterator());
450}
451
452void Function::splice(Function::iterator ToIt, Function *FromF,
453 Function::iterator FromBeginIt,
454 Function::iterator FromEndIt) {
455#ifdef EXPENSIVE_CHECKS
456 // Check that FromBeginIt is before FromEndIt.
457 auto FromFEnd = FromF->end();
458 for (auto It = FromBeginIt; It != FromEndIt; ++It)
459 assert(It != FromFEnd && "FromBeginIt not before FromEndIt!");
460#endif // EXPENSIVE_CHECKS
461 BasicBlocks.splice(where: ToIt, L2&: FromF->BasicBlocks, first: FromBeginIt, last: FromEndIt);
462}
463
464Function::iterator Function::erase(Function::iterator FromIt,
465 Function::iterator ToIt) {
466 return BasicBlocks.erase(first: FromIt, last: ToIt);
467}
468
469//===----------------------------------------------------------------------===//
470// Function Implementation
471//===----------------------------------------------------------------------===//
472
473static unsigned computeAddrSpace(unsigned AddrSpace, Module *M) {
474 // If AS == -1 and we are passed a valid module pointer we place the function
475 // in the program address space. Otherwise we default to AS0.
476 if (AddrSpace == static_cast<unsigned>(-1))
477 return M ? M->getDataLayout().getProgramAddressSpace() : 0;
478 return AddrSpace;
479}
480
481Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
482 const Twine &name, Module *ParentModule)
483 : GlobalObject(Ty, Value::FunctionVal, AllocMarker, Linkage, name,
484 computeAddrSpace(AddrSpace, M: ParentModule)),
485 NumArgs(Ty->getNumParams()) {
486 assert(FunctionType::isValidReturnType(getReturnType()) &&
487 "invalid return type");
488 setGlobalObjectSubClassData(0);
489
490 // We only need a symbol table for a function if the context keeps value names
491 if (!getContext().shouldDiscardValueNames())
492 SymTab = std::make_unique<ValueSymbolTable>(args&: NonGlobalValueMaxNameSize);
493
494 // If the function has arguments, mark them as lazily built.
495 if (Ty->getNumParams())
496 setValueSubclassData(1); // Set the "has lazy arguments" bit.
497
498 if (ParentModule) {
499 ParentModule->getFunctionList().push_back(val: this);
500 }
501
502 HasLLVMReservedName = getName().starts_with(Prefix: "llvm.");
503 // Ensure intrinsics have the right parameter attributes.
504 // Note, the IntID field will have been set in Value::setName if this function
505 // name is a valid intrinsic ID.
506 if (IntID) {
507 // Don't set the attributes if the intrinsic signature is invalid. This
508 // case will either be auto-upgraded or fail verification.
509 SmallVector<Type *> OverloadTys;
510 if (!Intrinsic::isSignatureValid(ID: IntID, FT: Ty, OverloadTys))
511 return;
512
513 setAttributes(Intrinsic::getAttributes(C&: getContext(), id: IntID, FT: Ty));
514 }
515}
516
517Function::~Function() {
518 validateBlockNumbers();
519
520 dropAllReferences(); // After this it is safe to delete instructions.
521
522 // Delete all of the method arguments and unlink from symbol table...
523 if (Arguments)
524 clearArguments();
525
526 // Remove the function from the on-the-side GC table.
527 clearGC();
528}
529
530void Function::BuildLazyArguments() const {
531 // Create the arguments vector, all arguments start out unnamed.
532 auto *FT = getFunctionType();
533 if (NumArgs > 0) {
534 Arguments = std::allocator<Argument>().allocate(n: NumArgs);
535 for (unsigned i = 0, e = NumArgs; i != e; ++i) {
536 Type *ArgTy = FT->getParamType(i);
537 assert(!ArgTy->isVoidTy() && "Cannot have void typed arguments!");
538 new (Arguments + i) Argument(ArgTy, "", const_cast<Function *>(this), i);
539 }
540 }
541
542 // Clear the lazy arguments bit.
543 unsigned SDC = getSubclassDataFromValue();
544 SDC &= ~(1 << 0);
545 const_cast<Function*>(this)->setValueSubclassData(SDC);
546 assert(!hasLazyArguments());
547}
548
549static MutableArrayRef<Argument> makeArgArray(Argument *Args, size_t Count) {
550 return MutableArrayRef<Argument>(Args, Count);
551}
552
553bool Function::isConstrainedFPIntrinsic() const {
554 return Intrinsic::isConstrainedFPIntrinsic(QID: getIntrinsicID());
555}
556
557void Function::clearArguments() {
558 for (Argument &A : makeArgArray(Args: Arguments, Count: NumArgs)) {
559 A.setName("");
560 A.~Argument();
561 }
562 std::allocator<Argument>().deallocate(p: Arguments, n: NumArgs);
563 Arguments = nullptr;
564}
565
566void Function::stealArgumentListFrom(Function &Src) {
567 assert(isDeclaration() && "Expected no references to current arguments");
568
569 // Drop the current arguments, if any, and set the lazy argument bit.
570 if (!hasLazyArguments()) {
571 assert(llvm::all_of(makeArgArray(Arguments, NumArgs),
572 [](const Argument &A) { return A.use_empty(); }) &&
573 "Expected arguments to be unused in declaration");
574 clearArguments();
575 setValueSubclassData(getSubclassDataFromValue() | (1 << 0));
576 }
577
578 // Nothing to steal if Src has lazy arguments.
579 if (Src.hasLazyArguments())
580 return;
581
582 // Steal arguments from Src, and fix the lazy argument bits.
583 assert(arg_size() == Src.arg_size());
584 Arguments = Src.Arguments;
585 Src.Arguments = nullptr;
586 for (Argument &A : makeArgArray(Args: Arguments, Count: NumArgs)) {
587 // FIXME: This does the work of transferNodesFromList inefficiently.
588 SmallString<128> Name;
589 if (A.hasName())
590 Name = A.getName();
591 if (!Name.empty())
592 A.setName("");
593 A.setParent(this);
594 if (!Name.empty())
595 A.setName(Name);
596 }
597
598 setValueSubclassData(getSubclassDataFromValue() & ~(1 << 0));
599 assert(!hasLazyArguments());
600 Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0));
601}
602
603void Function::deleteBodyImpl(bool ShouldDrop) {
604 setIsMaterializable(false);
605
606 for (BasicBlock &BB : *this)
607 BB.dropAllReferences();
608
609 // Delete all basic blocks. They are now unused, except possibly by
610 // blockaddresses, but BasicBlock's destructor takes care of those.
611 while (!BasicBlocks.empty())
612 BasicBlocks.begin()->eraseFromParent();
613
614 if (getNumOperands()) {
615 if (ShouldDrop) {
616 // Drop uses of any optional data (real or placeholder).
617 User::dropAllReferences();
618 setNumHungOffUseOperands(0);
619 } else {
620 // The code needs to match Function::allocHungoffUselist().
621 auto *CPN = ConstantPointerNull::get(T: PointerType::get(C&: getContext(), AddressSpace: 0));
622 Op<0>().set(CPN);
623 Op<1>().set(CPN);
624 Op<2>().set(CPN);
625 }
626 setValueSubclassData(getSubclassDataFromValue() & ~0xe);
627 }
628
629 // Metadata is stored in a side-table.
630 clearMetadata();
631}
632
633void Function::addAttributeAtIndex(unsigned i, Attribute Attr) {
634 AttributeSets = AttributeSets.addAttributeAtIndex(C&: getContext(), Index: i, A: Attr);
635}
636
637void Function::addFnAttr(Attribute::AttrKind Kind) {
638 AttributeSets = AttributeSets.addFnAttribute(C&: getContext(), Kind);
639}
640
641void Function::addFnAttr(StringRef Kind, StringRef Val) {
642 AttributeSets = AttributeSets.addFnAttribute(C&: getContext(), Kind, Value: Val);
643}
644
645void Function::addFnAttr(Attribute Attr) {
646 AttributeSets = AttributeSets.addFnAttribute(C&: getContext(), Attr);
647}
648
649void Function::addFnAttrs(const AttrBuilder &Attrs) {
650 AttributeSets = AttributeSets.addFnAttributes(C&: getContext(), B: Attrs);
651}
652
653void Function::addRetAttr(Attribute::AttrKind Kind) {
654 AttributeSets = AttributeSets.addRetAttribute(C&: getContext(), Kind);
655}
656
657void Function::addRetAttr(Attribute Attr) {
658 AttributeSets = AttributeSets.addRetAttribute(C&: getContext(), Attr);
659}
660
661void Function::addRetAttrs(const AttrBuilder &Attrs) {
662 AttributeSets = AttributeSets.addRetAttributes(C&: getContext(), B: Attrs);
663}
664
665void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
666 AttributeSets = AttributeSets.addParamAttribute(C&: getContext(), ArgNo, Kind);
667}
668
669void Function::addParamAttr(unsigned ArgNo, Attribute Attr) {
670 AttributeSets = AttributeSets.addParamAttribute(C&: getContext(), ArgNos: ArgNo, A: Attr);
671}
672
673void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {
674 AttributeSets = AttributeSets.addParamAttributes(C&: getContext(), ArgNo, B: Attrs);
675}
676
677void Function::removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) {
678 AttributeSets = AttributeSets.removeAttributeAtIndex(C&: getContext(), Index: i, Kind);
679}
680
681void Function::removeAttributeAtIndex(unsigned i, StringRef Kind) {
682 AttributeSets = AttributeSets.removeAttributeAtIndex(C&: getContext(), Index: i, Kind);
683}
684
685void Function::removeFnAttr(Attribute::AttrKind Kind) {
686 AttributeSets = AttributeSets.removeFnAttribute(C&: getContext(), Kind);
687}
688
689void Function::removeFnAttr(StringRef Kind) {
690 AttributeSets = AttributeSets.removeFnAttribute(C&: getContext(), Kind);
691}
692
693void Function::removeFnAttrs(const AttributeMask &AM) {
694 AttributeSets = AttributeSets.removeFnAttributes(C&: getContext(), AttrsToRemove: AM);
695}
696
697void Function::removeRetAttr(Attribute::AttrKind Kind) {
698 AttributeSets = AttributeSets.removeRetAttribute(C&: getContext(), Kind);
699}
700
701void Function::removeRetAttr(StringRef Kind) {
702 AttributeSets = AttributeSets.removeRetAttribute(C&: getContext(), Kind);
703}
704
705void Function::removeRetAttrs(const AttributeMask &Attrs) {
706 AttributeSets = AttributeSets.removeRetAttributes(C&: getContext(), AttrsToRemove: Attrs);
707}
708
709void Function::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
710 AttributeSets = AttributeSets.removeParamAttribute(C&: getContext(), ArgNo, Kind);
711}
712
713void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) {
714 AttributeSets = AttributeSets.removeParamAttribute(C&: getContext(), ArgNo, Kind);
715}
716
717void Function::removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs) {
718 AttributeSets =
719 AttributeSets.removeParamAttributes(C&: getContext(), ArgNo, AttrsToRemove: Attrs);
720}
721
722void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) {
723 AttributeSets =
724 AttributeSets.addDereferenceableParamAttr(C&: getContext(), ArgNo, Bytes);
725}
726
727bool Function::hasFnAttribute(Attribute::AttrKind Kind) const {
728 return AttributeSets.hasFnAttr(Kind);
729}
730
731bool Function::hasFnAttribute(StringRef Kind) const {
732 return AttributeSets.hasFnAttr(Kind);
733}
734
735bool Function::hasRetAttribute(Attribute::AttrKind Kind) const {
736 return AttributeSets.hasRetAttr(Kind);
737}
738
739bool Function::hasParamAttribute(unsigned ArgNo,
740 Attribute::AttrKind Kind) const {
741 return AttributeSets.hasParamAttr(ArgNo, Kind);
742}
743
744bool Function::hasParamAttribute(unsigned ArgNo, StringRef Kind) const {
745 return AttributeSets.hasParamAttr(ArgNo, Kind);
746}
747
748Attribute Function::getAttributeAtIndex(unsigned i,
749 Attribute::AttrKind Kind) const {
750 return AttributeSets.getAttributeAtIndex(Index: i, Kind);
751}
752
753Attribute Function::getAttributeAtIndex(unsigned i, StringRef Kind) const {
754 return AttributeSets.getAttributeAtIndex(Index: i, Kind);
755}
756
757bool Function::hasAttributeAtIndex(unsigned Idx,
758 Attribute::AttrKind Kind) const {
759 return AttributeSets.hasAttributeAtIndex(Index: Idx, Kind);
760}
761
762Attribute Function::getFnAttribute(Attribute::AttrKind Kind) const {
763 return AttributeSets.getFnAttr(Kind);
764}
765
766Attribute Function::getFnAttribute(StringRef Kind) const {
767 return AttributeSets.getFnAttr(Kind);
768}
769
770Attribute Function::getRetAttribute(Attribute::AttrKind Kind) const {
771 return AttributeSets.getRetAttr(Kind);
772}
773
774uint64_t Function::getFnAttributeAsParsedInteger(StringRef Name,
775 uint64_t Default) const {
776 Attribute A = getFnAttribute(Kind: Name);
777 uint64_t Result = Default;
778 if (A.isStringAttribute()) {
779 StringRef Str = A.getValueAsString();
780 if (Str.getAsInteger(Radix: 0, Result))
781 getContext().emitError(ErrorStr: "cannot parse integer attribute " + Name);
782 }
783
784 return Result;
785}
786
787/// gets the specified attribute from the list of attributes.
788Attribute Function::getParamAttribute(unsigned ArgNo,
789 Attribute::AttrKind Kind) const {
790 return AttributeSets.getParamAttr(ArgNo, Kind);
791}
792
793void Function::addDereferenceableOrNullParamAttr(unsigned ArgNo,
794 uint64_t Bytes) {
795 AttributeSets = AttributeSets.addDereferenceableOrNullParamAttr(C&: getContext(),
796 ArgNo, Bytes);
797}
798
799void Function::addRangeRetAttr(const ConstantRange &CR) {
800 AttributeSets = AttributeSets.addRangeRetAttr(C&: getContext(), CR);
801}
802
803DenormalMode Function::getDenormalMode(const fltSemantics &FPType) const {
804 Attribute Attr = getFnAttribute(Kind: Attribute::DenormalFPEnv);
805 if (!Attr.isValid())
806 return DenormalMode::getDefault();
807
808 DenormalFPEnv FPEnv = Attr.getDenormalFPEnv();
809 return &FPType == &APFloat::IEEEsingle() ? FPEnv.F32Mode : FPEnv.DefaultMode;
810}
811
812DenormalFPEnv Function::getDenormalFPEnv() const {
813 Attribute Attr = getFnAttribute(Kind: Attribute::DenormalFPEnv);
814 return Attr.isValid() ? Attr.getDenormalFPEnv() : DenormalFPEnv::getDefault();
815}
816
817const std::string &Function::getGC() const {
818 assert(hasGC() && "Function has no collector");
819 return getContext().getGC(Fn: *this);
820}
821
822void Function::setGC(std::string Str) {
823 setValueSubclassDataBit(Bit: 14, On: !Str.empty());
824 getContext().setGC(Fn: *this, GCName: std::move(Str));
825}
826
827void Function::clearGC() {
828 if (!hasGC())
829 return;
830 getContext().deleteGC(Fn: *this);
831 setValueSubclassDataBit(Bit: 14, On: false);
832}
833
834bool Function::hasStackProtectorFnAttr() const {
835 return hasFnAttribute(Kind: Attribute::StackProtect) ||
836 hasFnAttribute(Kind: Attribute::StackProtectStrong) ||
837 hasFnAttribute(Kind: Attribute::StackProtectReq);
838}
839
840/// Copy all additional attributes (those not needed to create a Function) from
841/// the Function Src to this one.
842void Function::copyAttributesFrom(const Function *Src) {
843 GlobalObject::copyAttributesFrom(Src);
844 setCallingConv(Src->getCallingConv());
845 setAttributes(Src->getAttributes());
846 if (Src->hasGC())
847 setGC(Src->getGC());
848 else
849 clearGC();
850 if (Src->hasPersonalityFn())
851 setPersonalityFn(Src->getPersonalityFn());
852 if (Src->hasPrefixData())
853 setPrefixData(Src->getPrefixData());
854 if (Src->hasPrologueData())
855 setPrologueData(Src->getPrologueData());
856}
857
858MemoryEffects Function::getMemoryEffects() const {
859 return getAttributes().getMemoryEffects();
860}
861void Function::setMemoryEffects(MemoryEffects ME) {
862 addFnAttr(Attr: Attribute::getWithMemoryEffects(Context&: getContext(), ME));
863}
864
865/// Determine if the function does not access memory.
866bool Function::doesNotAccessMemory() const {
867 return getMemoryEffects().doesNotAccessMemory();
868}
869void Function::setDoesNotAccessMemory() {
870 setMemoryEffects(MemoryEffects::none());
871}
872
873/// Determine if the function does not access or only reads memory.
874bool Function::onlyReadsMemory() const {
875 return getMemoryEffects().onlyReadsMemory();
876}
877void Function::setOnlyReadsMemory() {
878 setMemoryEffects(getMemoryEffects() & MemoryEffects::readOnly());
879}
880
881/// Determine if the function does not access or only writes memory.
882bool Function::onlyWritesMemory() const {
883 return getMemoryEffects().onlyWritesMemory();
884}
885void Function::setOnlyWritesMemory() {
886 setMemoryEffects(getMemoryEffects() & MemoryEffects::writeOnly());
887}
888
889/// Determine if the call can access memory only using pointers based
890/// on its arguments.
891bool Function::onlyAccessesArgMemory() const {
892 return getMemoryEffects().onlyAccessesArgPointees();
893}
894void Function::setOnlyAccessesArgMemory() {
895 setMemoryEffects(getMemoryEffects() & MemoryEffects::argMemOnly());
896}
897
898/// Determine if the function may only access memory that is
899/// inaccessible from the IR.
900bool Function::onlyAccessesInaccessibleMemory() const {
901 return getMemoryEffects().onlyAccessesInaccessibleMem();
902}
903void Function::setOnlyAccessesInaccessibleMemory() {
904 setMemoryEffects(getMemoryEffects() & MemoryEffects::inaccessibleMemOnly());
905}
906
907/// Determine if the function may only access memory that is
908/// either inaccessible from the IR or pointed to by its arguments.
909bool Function::onlyAccessesInaccessibleMemOrArgMem() const {
910 return getMemoryEffects().onlyAccessesInaccessibleOrArgMem();
911}
912void Function::setOnlyAccessesInaccessibleMemOrArgMem() {
913 setMemoryEffects(getMemoryEffects() &
914 MemoryEffects::inaccessibleOrArgMemOnly());
915}
916
917bool Function::isTargetIntrinsic() const {
918 return Intrinsic::isTargetIntrinsic(IID: IntID);
919}
920
921void Function::updateAfterNameChange() {
922 LibFuncCache = UnknownLibFunc;
923 StringRef Name = getName();
924 if (!Name.starts_with(Prefix: "llvm.")) {
925 HasLLVMReservedName = false;
926 IntID = Intrinsic::not_intrinsic;
927 return;
928 }
929 HasLLVMReservedName = true;
930 IntID = Intrinsic::lookupIntrinsicID(Name);
931}
932
933/// hasAddressTaken - returns true if there are any uses of this function
934/// other than direct calls or invokes to it. Optionally ignores callback
935/// uses, assume like pointer annotation calls, and references in llvm.used
936/// and llvm.compiler.used variables.
937bool Function::hasAddressTaken(const User **PutOffender,
938 bool IgnoreCallbackUses,
939 bool IgnoreAssumeLikeCalls, bool IgnoreLLVMUsed,
940 bool IgnoreARCAttachedCall,
941 bool IgnoreCastedDirectCall) const {
942 for (const Use &U : uses()) {
943 const User *FU = U.getUser();
944 if (IgnoreCallbackUses) {
945 AbstractCallSite ACS(&U);
946 if (ACS && ACS.isCallbackCall())
947 continue;
948 }
949
950 const auto *Call = dyn_cast<CallBase>(Val: FU);
951 if (!Call) {
952 if (IgnoreAssumeLikeCalls &&
953 isa<BitCastOperator, AddrSpaceCastOperator>(Val: FU) &&
954 all_of(Range: FU->users(), P: [](const User *U) {
955 if (const auto *I = dyn_cast<IntrinsicInst>(Val: U))
956 return I->isAssumeLikeIntrinsic();
957 return false;
958 })) {
959 continue;
960 }
961
962 if (IgnoreLLVMUsed && !FU->user_empty()) {
963 const User *FUU = FU;
964 if (isa<BitCastOperator, AddrSpaceCastOperator>(Val: FU) &&
965 FU->hasOneUse() && !FU->user_begin()->user_empty())
966 FUU = *FU->user_begin();
967 if (llvm::all_of(Range: FUU->users(), P: [](const User *U) {
968 if (const auto *GV = dyn_cast<GlobalVariable>(Val: U))
969 return GV->hasName() &&
970 (GV->getName() == "llvm.compiler.used" ||
971 GV->getName() == "llvm.used");
972 return false;
973 }))
974 continue;
975 }
976 if (PutOffender)
977 *PutOffender = FU;
978 return true;
979 }
980
981 if (IgnoreAssumeLikeCalls) {
982 if (const auto *I = dyn_cast<IntrinsicInst>(Val: Call))
983 if (I->isAssumeLikeIntrinsic())
984 continue;
985 }
986
987 if (!Call->isCallee(U: &U) || (!IgnoreCastedDirectCall &&
988 Call->getFunctionType() != getFunctionType())) {
989 if (IgnoreARCAttachedCall &&
990 Call->isOperandBundleOfType(ID: LLVMContext::OB_clang_arc_attachedcall,
991 Idx: U.getOperandNo()))
992 continue;
993
994 if (PutOffender)
995 *PutOffender = FU;
996 return true;
997 }
998 }
999 return false;
1000}
1001
1002bool Function::isDefTriviallyDead() const {
1003 // Check the linkage
1004 if (!hasLinkOnceLinkage() && !hasLocalLinkage() &&
1005 !hasAvailableExternallyLinkage())
1006 return false;
1007
1008 return use_empty();
1009}
1010
1011/// callsFunctionThatReturnsTwice - Return true if the function has a call to
1012/// setjmp or other function that gcc recognizes as "returning twice".
1013bool Function::callsFunctionThatReturnsTwice() const {
1014 for (const Instruction &I : instructions(F: this))
1015 if (const auto *Call = dyn_cast<CallBase>(Val: &I))
1016 if (Call->hasFnAttr(Kind: Attribute::ReturnsTwice))
1017 return true;
1018
1019 return false;
1020}
1021
1022Constant *Function::getPersonalityFn() const {
1023 assert(hasPersonalityFn() && getNumOperands());
1024 return cast<Constant>(Val: Op<0>());
1025}
1026
1027void Function::setPersonalityFn(Constant *Fn) {
1028 setHungoffOperand<0>(Fn);
1029 setValueSubclassDataBit(Bit: 3, On: Fn != nullptr);
1030}
1031
1032Constant *Function::getPrefixData() const {
1033 assert(hasPrefixData() && getNumOperands());
1034 return cast<Constant>(Val: Op<1>());
1035}
1036
1037void Function::setPrefixData(Constant *PrefixData) {
1038 setHungoffOperand<1>(PrefixData);
1039 setValueSubclassDataBit(Bit: 1, On: PrefixData != nullptr);
1040}
1041
1042Constant *Function::getPrologueData() const {
1043 assert(hasPrologueData() && getNumOperands());
1044 return cast<Constant>(Val: Op<2>());
1045}
1046
1047void Function::setPrologueData(Constant *PrologueData) {
1048 setHungoffOperand<2>(PrologueData);
1049 setValueSubclassDataBit(Bit: 2, On: PrologueData != nullptr);
1050}
1051
1052void Function::allocHungoffUselist() {
1053 // If we've already allocated a uselist, stop here.
1054 if (getNumOperands())
1055 return;
1056
1057 allocHungoffUses(N: 3, /*IsPhi=*/ WithExtraValues: false);
1058 setNumHungOffUseOperands(3);
1059
1060 // Initialize the uselist with placeholder operands to allow traversal.
1061 auto *CPN = ConstantPointerNull::get(T: PointerType::get(C&: getContext(), AddressSpace: 0));
1062 Op<0>().set(CPN);
1063 Op<1>().set(CPN);
1064 Op<2>().set(CPN);
1065}
1066
1067template <int Idx>
1068void Function::setHungoffOperand(Constant *C) {
1069 if (C) {
1070 allocHungoffUselist();
1071 Op<Idx>().set(C);
1072 } else if (getNumOperands()) {
1073 Op<Idx>().set(ConstantPointerNull::get(T: PointerType::get(C&: getContext(), AddressSpace: 0)));
1074 }
1075}
1076
1077void Function::setValueSubclassDataBit(unsigned Bit, bool On) {
1078 assert(Bit < 16 && "SubclassData contains only 16 bits");
1079 if (On)
1080 setValueSubclassData(getSubclassDataFromValue() | (1 << Bit));
1081 else
1082 setValueSubclassData(getSubclassDataFromValue() & ~(1 << Bit));
1083}
1084
1085void Function::setEntryCount(uint64_t Count,
1086 const DenseSet<GlobalValue::GUID> *S) {
1087 auto ImportGUIDs = getImportGUIDs();
1088 if (S == nullptr && ImportGUIDs.size())
1089 S = &ImportGUIDs;
1090
1091 MDBuilder MDB(getContext());
1092 setMetadata(KindID: LLVMContext::MD_prof,
1093 Node: MDB.createFunctionEntryCount(Count, Synthetic: false, Imports: S));
1094}
1095
1096std::optional<uint64_t> Function::getEntryCount() const {
1097 MDNode *MD = getMetadata(KindID: LLVMContext::MD_prof);
1098 if (MD && MD->getOperand(I: 0))
1099 if (MDString *MDS = dyn_cast<MDString>(Val: MD->getOperand(I: 0))) {
1100 if (MDS->getString() != MDProfLabels::FunctionEntryCount)
1101 return std::nullopt;
1102 ConstantInt *CI = mdconst::extract<ConstantInt>(MD: MD->getOperand(I: 1));
1103 uint64_t Count = CI->getValue().getZExtValue();
1104 // A value of -1 is used for SamplePGO when there were no samples.
1105 // Treat this the same as unknown.
1106 if (Count == static_cast<uint64_t>(-1))
1107 return std::nullopt;
1108 return Count;
1109 }
1110 return std::nullopt;
1111}
1112
1113DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const {
1114 DenseSet<GlobalValue::GUID> R;
1115 if (MDNode *MD = getMetadata(KindID: LLVMContext::MD_prof))
1116 if (MDString *MDS = dyn_cast<MDString>(Val: MD->getOperand(I: 0)))
1117 if (MDS->getString() == MDProfLabels::FunctionEntryCount)
1118 for (unsigned i = 2; i < MD->getNumOperands(); i++)
1119 R.insert(V: mdconst::extract<ConstantInt>(MD: MD->getOperand(I: i))
1120 ->getValue()
1121 .getZExtValue());
1122 return R;
1123}
1124
1125bool Function::nullPointerIsDefined() const {
1126 return hasFnAttribute(Kind: Attribute::NullPointerIsValid);
1127}
1128
1129unsigned Function::getVScaleValue() const {
1130 Attribute Attr = getFnAttribute(Kind: Attribute::VScaleRange);
1131 if (!Attr.isValid())
1132 return 0;
1133
1134 unsigned VScale = Attr.getVScaleRangeMin();
1135 if (VScale && VScale == Attr.getVScaleRangeMax())
1136 return VScale;
1137
1138 return 0;
1139}
1140
1141bool llvm::NullPointerIsDefined(const Function *F, unsigned AS) {
1142 if (F && F->nullPointerIsDefined())
1143 return true;
1144
1145 if (AS != 0)
1146 return true;
1147
1148 return false;
1149}
1150
1151bool llvm::CallingConv::supportsNonVoidReturnType(CallingConv::ID CC) {
1152 switch (CC) {
1153 case CallingConv::C:
1154 case CallingConv::Fast:
1155 case CallingConv::Cold:
1156 case CallingConv::GHC:
1157 case CallingConv::HiPE:
1158 case CallingConv::AnyReg:
1159 case CallingConv::PreserveMost:
1160 case CallingConv::PreserveAll:
1161 case CallingConv::Swift:
1162 case CallingConv::CXX_FAST_TLS:
1163 case CallingConv::Tail:
1164 case CallingConv::CFGuard_Check:
1165 case CallingConv::SwiftTail:
1166 case CallingConv::PreserveNone:
1167 case CallingConv::X86_StdCall:
1168 case CallingConv::X86_FastCall:
1169 case CallingConv::ARM_APCS:
1170 case CallingConv::ARM_AAPCS:
1171 case CallingConv::ARM_AAPCS_VFP:
1172 case CallingConv::MSP430_INTR:
1173 case CallingConv::X86_ThisCall:
1174 case CallingConv::PTX_Device:
1175 case CallingConv::SPIR_FUNC:
1176 case CallingConv::Intel_OCL_BI:
1177 case CallingConv::X86_64_SysV:
1178 case CallingConv::Win64:
1179 case CallingConv::X86_VectorCall:
1180 case CallingConv::DUMMY_HHVM:
1181 case CallingConv::DUMMY_HHVM_C:
1182 case CallingConv::X86_INTR:
1183 case CallingConv::AVR_INTR:
1184 case CallingConv::AVR_SIGNAL:
1185 case CallingConv::AVR_BUILTIN:
1186 return true;
1187 case CallingConv::AMDGPU_KERNEL:
1188 case CallingConv::SPIR_KERNEL:
1189 case CallingConv::AMDGPU_CS_Chain:
1190 case CallingConv::AMDGPU_CS_ChainPreserve:
1191 return false;
1192 case CallingConv::AMDGPU_VS:
1193 case CallingConv::AMDGPU_HS:
1194 case CallingConv::AMDGPU_GS:
1195 case CallingConv::AMDGPU_PS:
1196 case CallingConv::AMDGPU_CS:
1197 case CallingConv::AMDGPU_LS:
1198 case CallingConv::AMDGPU_ES:
1199 case CallingConv::MSP430_BUILTIN:
1200 case CallingConv::AArch64_VectorCall:
1201 case CallingConv::AArch64_SVE_VectorCall:
1202 case CallingConv::WASM_EmscriptenInvoke:
1203 case CallingConv::AMDGPU_Gfx:
1204 case CallingConv::AMDGPU_Gfx_WholeWave:
1205 case CallingConv::M68k_INTR:
1206 case CallingConv::AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0:
1207 case CallingConv::AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2:
1208 case CallingConv::M68k_RTD:
1209 case CallingConv::GRAAL:
1210 case CallingConv::ARM64EC_Thunk_X64:
1211 case CallingConv::ARM64EC_Thunk_Native:
1212 case CallingConv::RISCV_VectorCall:
1213 case CallingConv::AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1:
1214 case CallingConv::RISCV_VLSCall_32:
1215 case CallingConv::RISCV_VLSCall_64:
1216 case CallingConv::RISCV_VLSCall_128:
1217 case CallingConv::RISCV_VLSCall_256:
1218 case CallingConv::RISCV_VLSCall_512:
1219 case CallingConv::RISCV_VLSCall_1024:
1220 case CallingConv::RISCV_VLSCall_2048:
1221 case CallingConv::RISCV_VLSCall_4096:
1222 case CallingConv::RISCV_VLSCall_8192:
1223 case CallingConv::RISCV_VLSCall_16384:
1224 case CallingConv::RISCV_VLSCall_32768:
1225 case CallingConv::RISCV_VLSCall_65536:
1226 return true;
1227 default:
1228 return false;
1229 }
1230
1231 llvm_unreachable("covered callingconv switch");
1232}
1233