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