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 AddAttributeIfSet("branch-target-enforcement");
436 AddAttributeIfSet("branch-protection-pauth-lr");
437 AddAttributeIfSet("guarded-control-stack");
438 AddAttributeIfSet("ptrauth-returns");
439 AddAttributeIfSet("ptrauth-auth-traps");
440 AddAttributeIfSet("ptrauth-indirect-gotos");
441 AddAttributeIfSet("aarch64-jump-table-hardening");
442
443 F->addFnAttrs(Attrs: B);
444 return F;
445}
446
447void Function::removeFromParent() {
448 getParent()->getFunctionList().remove(IT: getIterator());
449}
450
451void Function::eraseFromParent() {
452 getParent()->getFunctionList().erase(where: getIterator());
453}
454
455void Function::splice(Function::iterator ToIt, Function *FromF,
456 Function::iterator FromBeginIt,
457 Function::iterator FromEndIt) {
458#ifdef EXPENSIVE_CHECKS
459 // Check that FromBeginIt is before FromEndIt.
460 auto FromFEnd = FromF->end();
461 for (auto It = FromBeginIt; It != FromEndIt; ++It)
462 assert(It != FromFEnd && "FromBeginIt not before FromEndIt!");
463#endif // EXPENSIVE_CHECKS
464 BasicBlocks.splice(where: ToIt, L2&: FromF->BasicBlocks, first: FromBeginIt, last: FromEndIt);
465}
466
467Function::iterator Function::erase(Function::iterator FromIt,
468 Function::iterator ToIt) {
469 return BasicBlocks.erase(first: FromIt, last: ToIt);
470}
471
472//===----------------------------------------------------------------------===//
473// Function Implementation
474//===----------------------------------------------------------------------===//
475
476static unsigned computeAddrSpace(unsigned AddrSpace, Module *M) {
477 // If AS == -1 and we are passed a valid module pointer we place the function
478 // in the program address space. Otherwise we default to AS0.
479 if (AddrSpace == static_cast<unsigned>(-1))
480 return M ? M->getDataLayout().getProgramAddressSpace() : 0;
481 return AddrSpace;
482}
483
484Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
485 const Twine &name, Module *ParentModule)
486 : GlobalObject(Ty, Value::FunctionVal, AllocMarker, Linkage, name,
487 computeAddrSpace(AddrSpace, M: ParentModule)),
488 NumArgs(Ty->getNumParams()) {
489 assert(FunctionType::isValidReturnType(getReturnType()) &&
490 "invalid return type");
491 setGlobalObjectSubClassData(0);
492
493 // We only need a symbol table for a function if the context keeps value names
494 if (!getContext().shouldDiscardValueNames())
495 SymTab = std::make_unique<ValueSymbolTable>(args&: NonGlobalValueMaxNameSize);
496
497 // If the function has arguments, mark them as lazily built.
498 if (Ty->getNumParams())
499 setValueSubclassData(1); // Set the "has lazy arguments" bit.
500
501 if (ParentModule) {
502 ParentModule->getFunctionList().push_back(val: this);
503 }
504
505 HasLLVMReservedName = getName().starts_with(Prefix: "llvm.");
506 // Ensure intrinsics have the right parameter attributes.
507 // Note, the IntID field will have been set in Value::setName if this function
508 // name is a valid intrinsic ID.
509 if (IntID) {
510 // Don't set the attributes if the intrinsic signature is invalid. This
511 // case will either be auto-upgraded or fail verification.
512 SmallVector<Type *> OverloadTys;
513 if (!Intrinsic::isSignatureValid(ID: IntID, FT: Ty, OverloadTys))
514 return;
515
516 setAttributes(Intrinsic::getAttributes(C&: getContext(), id: IntID, FT: Ty));
517 }
518}
519
520Function::~Function() {
521 validateBlockNumbers();
522
523 dropAllReferences(); // After this it is safe to delete instructions.
524
525 // Delete all of the method arguments and unlink from symbol table...
526 if (Arguments)
527 clearArguments();
528
529 // Remove the function from the on-the-side GC table.
530 clearGC();
531}
532
533void Function::BuildLazyArguments() const {
534 // Create the arguments vector, all arguments start out unnamed.
535 auto *FT = getFunctionType();
536 if (NumArgs > 0) {
537 Arguments = std::allocator<Argument>().allocate(n: NumArgs);
538 for (unsigned i = 0, e = NumArgs; i != e; ++i) {
539 Type *ArgTy = FT->getParamType(i);
540 assert(!ArgTy->isVoidTy() && "Cannot have void typed arguments!");
541 new (Arguments + i) Argument(ArgTy, "", const_cast<Function *>(this), i);
542 }
543 }
544
545 // Clear the lazy arguments bit.
546 unsigned SDC = getSubclassDataFromValue();
547 SDC &= ~(1 << 0);
548 const_cast<Function*>(this)->setValueSubclassData(SDC);
549 assert(!hasLazyArguments());
550}
551
552static MutableArrayRef<Argument> makeArgArray(Argument *Args, size_t Count) {
553 return MutableArrayRef<Argument>(Args, Count);
554}
555
556bool Function::isConstrainedFPIntrinsic() const {
557 return Intrinsic::isConstrainedFPIntrinsic(QID: getIntrinsicID());
558}
559
560void Function::clearArguments() {
561 for (Argument &A : makeArgArray(Args: Arguments, Count: NumArgs)) {
562 A.setName("");
563 A.~Argument();
564 }
565 std::allocator<Argument>().deallocate(p: Arguments, n: NumArgs);
566 Arguments = nullptr;
567}
568
569void Function::stealArgumentListFrom(Function &Src) {
570 assert(isDeclaration() && "Expected no references to current arguments");
571
572 // Drop the current arguments, if any, and set the lazy argument bit.
573 if (!hasLazyArguments()) {
574 assert(llvm::all_of(makeArgArray(Arguments, NumArgs),
575 [](const Argument &A) { return A.use_empty(); }) &&
576 "Expected arguments to be unused in declaration");
577 clearArguments();
578 setValueSubclassData(getSubclassDataFromValue() | (1 << 0));
579 }
580
581 // Nothing to steal if Src has lazy arguments.
582 if (Src.hasLazyArguments())
583 return;
584
585 // Steal arguments from Src, and fix the lazy argument bits.
586 assert(arg_size() == Src.arg_size());
587 Arguments = Src.Arguments;
588 Src.Arguments = nullptr;
589 for (Argument &A : makeArgArray(Args: Arguments, Count: NumArgs)) {
590 // FIXME: This does the work of transferNodesFromList inefficiently.
591 SmallString<128> Name;
592 if (A.hasName())
593 Name = A.getName();
594 if (!Name.empty())
595 A.setName("");
596 A.setParent(this);
597 if (!Name.empty())
598 A.setName(Name);
599 }
600
601 setValueSubclassData(getSubclassDataFromValue() & ~(1 << 0));
602 assert(!hasLazyArguments());
603 Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0));
604}
605
606void Function::deleteBodyImpl(bool ShouldDrop) {
607 setIsMaterializable(false);
608
609 for (BasicBlock &BB : *this)
610 BB.dropAllReferences();
611
612 // Delete all basic blocks. They are now unused, except possibly by
613 // blockaddresses, but BasicBlock's destructor takes care of those.
614 while (!BasicBlocks.empty())
615 BasicBlocks.begin()->eraseFromParent();
616
617 if (getNumOperands()) {
618 if (ShouldDrop) {
619 // Drop uses of any optional data (real or placeholder).
620 User::dropAllReferences();
621 setNumHungOffUseOperands(0);
622 } else {
623 // The code needs to match Function::allocHungoffUselist().
624 auto *CPN = ConstantPointerNull::get(T: PointerType::get(C&: getContext(), AddressSpace: 0));
625 Op<0>().set(CPN);
626 Op<1>().set(CPN);
627 Op<2>().set(CPN);
628 }
629 setValueSubclassData(getSubclassDataFromValue() & ~0xe);
630 }
631
632 // Metadata is stored in a side-table.
633 clearMetadata();
634}
635
636void Function::addAttributeAtIndex(unsigned i, Attribute Attr) {
637 AttributeSets = AttributeSets.addAttributeAtIndex(C&: getContext(), Index: i, A: Attr);
638}
639
640void Function::addFnAttr(Attribute::AttrKind Kind) {
641 AttributeSets = AttributeSets.addFnAttribute(C&: getContext(), Kind);
642}
643
644void Function::addFnAttr(StringRef Kind, StringRef Val) {
645 AttributeSets = AttributeSets.addFnAttribute(C&: getContext(), Kind, Value: Val);
646}
647
648void Function::addFnAttr(Attribute Attr) {
649 AttributeSets = AttributeSets.addFnAttribute(C&: getContext(), Attr);
650}
651
652void Function::addFnAttrs(const AttrBuilder &Attrs) {
653 AttributeSets = AttributeSets.addFnAttributes(C&: getContext(), B: Attrs);
654}
655
656void Function::addRetAttr(Attribute::AttrKind Kind) {
657 AttributeSets = AttributeSets.addRetAttribute(C&: getContext(), Kind);
658}
659
660void Function::addRetAttr(Attribute Attr) {
661 AttributeSets = AttributeSets.addRetAttribute(C&: getContext(), Attr);
662}
663
664void Function::addRetAttrs(const AttrBuilder &Attrs) {
665 AttributeSets = AttributeSets.addRetAttributes(C&: getContext(), B: Attrs);
666}
667
668void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
669 AttributeSets = AttributeSets.addParamAttribute(C&: getContext(), ArgNo, Kind);
670}
671
672void Function::addParamAttr(unsigned ArgNo, Attribute Attr) {
673 AttributeSets = AttributeSets.addParamAttribute(C&: getContext(), ArgNos: ArgNo, A: Attr);
674}
675
676void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {
677 AttributeSets = AttributeSets.addParamAttributes(C&: getContext(), ArgNo, B: Attrs);
678}
679
680void Function::removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) {
681 AttributeSets = AttributeSets.removeAttributeAtIndex(C&: getContext(), Index: i, Kind);
682}
683
684void Function::removeAttributeAtIndex(unsigned i, StringRef Kind) {
685 AttributeSets = AttributeSets.removeAttributeAtIndex(C&: getContext(), Index: i, Kind);
686}
687
688void Function::removeFnAttr(Attribute::AttrKind Kind) {
689 AttributeSets = AttributeSets.removeFnAttribute(C&: getContext(), Kind);
690}
691
692void Function::removeFnAttr(StringRef Kind) {
693 AttributeSets = AttributeSets.removeFnAttribute(C&: getContext(), Kind);
694}
695
696void Function::removeFnAttrs(const AttributeMask &AM) {
697 AttributeSets = AttributeSets.removeFnAttributes(C&: getContext(), AttrsToRemove: AM);
698}
699
700void Function::removeRetAttr(Attribute::AttrKind Kind) {
701 AttributeSets = AttributeSets.removeRetAttribute(C&: getContext(), Kind);
702}
703
704void Function::removeRetAttr(StringRef Kind) {
705 AttributeSets = AttributeSets.removeRetAttribute(C&: getContext(), Kind);
706}
707
708void Function::removeRetAttrs(const AttributeMask &Attrs) {
709 AttributeSets = AttributeSets.removeRetAttributes(C&: getContext(), AttrsToRemove: Attrs);
710}
711
712void Function::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
713 AttributeSets = AttributeSets.removeParamAttribute(C&: getContext(), ArgNo, Kind);
714}
715
716void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) {
717 AttributeSets = AttributeSets.removeParamAttribute(C&: getContext(), ArgNo, Kind);
718}
719
720void Function::removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs) {
721 AttributeSets =
722 AttributeSets.removeParamAttributes(C&: getContext(), ArgNo, AttrsToRemove: Attrs);
723}
724
725void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) {
726 AttributeSets =
727 AttributeSets.addDereferenceableParamAttr(C&: getContext(), ArgNo, Bytes);
728}
729
730bool Function::hasFnAttribute(Attribute::AttrKind Kind) const {
731 return AttributeSets.hasFnAttr(Kind);
732}
733
734bool Function::hasFnAttribute(StringRef Kind) const {
735 return AttributeSets.hasFnAttr(Kind);
736}
737
738bool Function::hasRetAttribute(Attribute::AttrKind Kind) const {
739 return AttributeSets.hasRetAttr(Kind);
740}
741
742bool Function::hasParamAttribute(unsigned ArgNo,
743 Attribute::AttrKind Kind) const {
744 return AttributeSets.hasParamAttr(ArgNo, Kind);
745}
746
747bool Function::hasParamAttribute(unsigned ArgNo, StringRef Kind) const {
748 return AttributeSets.hasParamAttr(ArgNo, Kind);
749}
750
751Attribute Function::getAttributeAtIndex(unsigned i,
752 Attribute::AttrKind Kind) const {
753 return AttributeSets.getAttributeAtIndex(Index: i, Kind);
754}
755
756Attribute Function::getAttributeAtIndex(unsigned i, StringRef Kind) const {
757 return AttributeSets.getAttributeAtIndex(Index: i, Kind);
758}
759
760bool Function::hasAttributeAtIndex(unsigned Idx,
761 Attribute::AttrKind Kind) const {
762 return AttributeSets.hasAttributeAtIndex(Index: Idx, Kind);
763}
764
765Attribute Function::getFnAttribute(Attribute::AttrKind Kind) const {
766 return AttributeSets.getFnAttr(Kind);
767}
768
769Attribute Function::getFnAttribute(StringRef Kind) const {
770 return AttributeSets.getFnAttr(Kind);
771}
772
773Attribute Function::getRetAttribute(Attribute::AttrKind Kind) const {
774 return AttributeSets.getRetAttr(Kind);
775}
776
777uint64_t Function::getFnAttributeAsParsedInteger(StringRef Name,
778 uint64_t Default) const {
779 Attribute A = getFnAttribute(Kind: Name);
780 uint64_t Result = Default;
781 if (A.isStringAttribute()) {
782 StringRef Str = A.getValueAsString();
783 if (Str.getAsInteger(Radix: 0, Result))
784 getContext().emitError(ErrorStr: "cannot parse integer attribute " + Name);
785 }
786
787 return Result;
788}
789
790/// gets the specified attribute from the list of attributes.
791Attribute Function::getParamAttribute(unsigned ArgNo,
792 Attribute::AttrKind Kind) const {
793 return AttributeSets.getParamAttr(ArgNo, Kind);
794}
795
796void Function::addDereferenceableOrNullParamAttr(unsigned ArgNo,
797 uint64_t Bytes) {
798 AttributeSets = AttributeSets.addDereferenceableOrNullParamAttr(C&: getContext(),
799 ArgNo, Bytes);
800}
801
802void Function::addRangeRetAttr(const ConstantRange &CR) {
803 AttributeSets = AttributeSets.addRangeRetAttr(C&: getContext(), CR);
804}
805
806DenormalMode Function::getDenormalMode(const fltSemantics &FPType) const {
807 Attribute Attr = getFnAttribute(Kind: Attribute::DenormalFPEnv);
808 if (!Attr.isValid())
809 return DenormalMode::getDefault();
810
811 DenormalFPEnv FPEnv = Attr.getDenormalFPEnv();
812 return &FPType == &APFloat::IEEEsingle() ? FPEnv.F32Mode : FPEnv.DefaultMode;
813}
814
815DenormalFPEnv Function::getDenormalFPEnv() const {
816 Attribute Attr = getFnAttribute(Kind: Attribute::DenormalFPEnv);
817 return Attr.isValid() ? Attr.getDenormalFPEnv() : DenormalFPEnv::getDefault();
818}
819
820const std::string &Function::getGC() const {
821 assert(hasGC() && "Function has no collector");
822 return getContext().getGC(Fn: *this);
823}
824
825void Function::setGC(std::string Str) {
826 setValueSubclassDataBit(Bit: 14, On: !Str.empty());
827 getContext().setGC(Fn: *this, GCName: std::move(Str));
828}
829
830void Function::clearGC() {
831 if (!hasGC())
832 return;
833 getContext().deleteGC(Fn: *this);
834 setValueSubclassDataBit(Bit: 14, On: false);
835}
836
837bool Function::hasStackProtectorFnAttr() const {
838 return hasFnAttribute(Kind: Attribute::StackProtect) ||
839 hasFnAttribute(Kind: Attribute::StackProtectStrong) ||
840 hasFnAttribute(Kind: Attribute::StackProtectReq);
841}
842
843/// Copy all additional attributes (those not needed to create a Function) from
844/// the Function Src to this one.
845void Function::copyAttributesFrom(const Function *Src) {
846 GlobalObject::copyAttributesFrom(Src);
847 setCallingConv(Src->getCallingConv());
848 setAttributes(Src->getAttributes());
849 if (Src->hasGC())
850 setGC(Src->getGC());
851 else
852 clearGC();
853 if (Src->hasPersonalityFn())
854 setPersonalityFn(Src->getPersonalityFn());
855 if (Src->hasPrefixData())
856 setPrefixData(Src->getPrefixData());
857 if (Src->hasPrologueData())
858 setPrologueData(Src->getPrologueData());
859}
860
861MemoryEffects Function::getMemoryEffects() const {
862 return getAttributes().getMemoryEffects();
863}
864void Function::setMemoryEffects(MemoryEffects ME) {
865 addFnAttr(Attr: Attribute::getWithMemoryEffects(Context&: getContext(), ME));
866}
867
868/// Determine if the function does not access memory.
869bool Function::doesNotAccessMemory() const {
870 return getMemoryEffects().doesNotAccessMemory();
871}
872void Function::setDoesNotAccessMemory() {
873 setMemoryEffects(MemoryEffects::none());
874}
875
876/// Determine if the function does not access or only reads memory.
877bool Function::onlyReadsMemory() const {
878 return getMemoryEffects().onlyReadsMemory();
879}
880void Function::setOnlyReadsMemory() {
881 setMemoryEffects(getMemoryEffects() & MemoryEffects::readOnly());
882}
883
884/// Determine if the function does not access or only writes memory.
885bool Function::onlyWritesMemory() const {
886 return getMemoryEffects().onlyWritesMemory();
887}
888void Function::setOnlyWritesMemory() {
889 setMemoryEffects(getMemoryEffects() & MemoryEffects::writeOnly());
890}
891
892/// Determine if the call can access memory only using pointers based
893/// on its arguments.
894bool Function::onlyAccessesArgMemory() const {
895 return getMemoryEffects().onlyAccessesArgPointees();
896}
897void Function::setOnlyAccessesArgMemory() {
898 setMemoryEffects(getMemoryEffects() & MemoryEffects::argMemOnly());
899}
900
901/// Determine if the function may only access memory that is
902/// inaccessible from the IR.
903bool Function::onlyAccessesInaccessibleMemory() const {
904 return getMemoryEffects().onlyAccessesInaccessibleMem();
905}
906void Function::setOnlyAccessesInaccessibleMemory() {
907 setMemoryEffects(getMemoryEffects() & MemoryEffects::inaccessibleMemOnly());
908}
909
910/// Determine if the function may only access memory that is
911/// either inaccessible from the IR or pointed to by its arguments.
912bool Function::onlyAccessesInaccessibleMemOrArgMem() const {
913 return getMemoryEffects().onlyAccessesInaccessibleOrArgMem();
914}
915void Function::setOnlyAccessesInaccessibleMemOrArgMem() {
916 setMemoryEffects(getMemoryEffects() &
917 MemoryEffects::inaccessibleOrArgMemOnly());
918}
919
920bool Function::isTargetIntrinsic() const {
921 return Intrinsic::isTargetIntrinsic(IID: IntID);
922}
923
924void Function::updateAfterNameChange() {
925 LibFuncCache = UnknownLibFunc;
926 StringRef Name = getName();
927 if (!Name.starts_with(Prefix: "llvm.")) {
928 HasLLVMReservedName = false;
929 IntID = Intrinsic::not_intrinsic;
930 return;
931 }
932 HasLLVMReservedName = true;
933 IntID = Intrinsic::lookupIntrinsicID(Name);
934}
935
936/// hasAddressTaken - returns true if there are any uses of this function
937/// other than direct calls or invokes to it. Optionally ignores callback
938/// uses, assume like pointer annotation calls, and references in llvm.used
939/// and llvm.compiler.used variables.
940bool Function::hasAddressTaken(const User **PutOffender,
941 bool IgnoreCallbackUses,
942 bool IgnoreAssumeLikeCalls, bool IgnoreLLVMUsed,
943 bool IgnoreARCAttachedCall,
944 bool IgnoreCastedDirectCall) const {
945 for (const Use &U : uses()) {
946 const User *FU = U.getUser();
947 if (IgnoreCallbackUses) {
948 AbstractCallSite ACS(&U);
949 if (ACS && ACS.isCallbackCall())
950 continue;
951 }
952
953 const auto *Call = dyn_cast<CallBase>(Val: FU);
954 if (!Call) {
955 if (IgnoreAssumeLikeCalls &&
956 isa<BitCastOperator, AddrSpaceCastOperator>(Val: FU) &&
957 all_of(Range: FU->users(), P: [](const User *U) {
958 if (const auto *I = dyn_cast<IntrinsicInst>(Val: U))
959 return I->isAssumeLikeIntrinsic();
960 return false;
961 })) {
962 continue;
963 }
964
965 if (IgnoreLLVMUsed && !FU->user_empty()) {
966 const User *FUU = FU;
967 if (isa<BitCastOperator, AddrSpaceCastOperator>(Val: FU) &&
968 FU->hasOneUse() && !FU->user_begin()->user_empty())
969 FUU = *FU->user_begin();
970 if (llvm::all_of(Range: FUU->users(), P: [](const User *U) {
971 if (const auto *GV = dyn_cast<GlobalVariable>(Val: U))
972 return GV->hasName() &&
973 (GV->getName() == "llvm.compiler.used" ||
974 GV->getName() == "llvm.used");
975 return false;
976 }))
977 continue;
978 }
979 if (PutOffender)
980 *PutOffender = FU;
981 return true;
982 }
983
984 if (IgnoreAssumeLikeCalls) {
985 if (const auto *I = dyn_cast<IntrinsicInst>(Val: Call))
986 if (I->isAssumeLikeIntrinsic())
987 continue;
988 }
989
990 if (!Call->isCallee(U: &U) || (!IgnoreCastedDirectCall &&
991 Call->getFunctionType() != getFunctionType())) {
992 if (IgnoreARCAttachedCall &&
993 Call->isOperandBundleOfType(ID: LLVMContext::OB_clang_arc_attachedcall,
994 Idx: U.getOperandNo()))
995 continue;
996
997 if (PutOffender)
998 *PutOffender = FU;
999 return true;
1000 }
1001 }
1002 return false;
1003}
1004
1005bool Function::isDefTriviallyDead() const {
1006 // Check the linkage
1007 if (!hasLinkOnceLinkage() && !hasLocalLinkage() &&
1008 !hasAvailableExternallyLinkage())
1009 return false;
1010
1011 return use_empty();
1012}
1013
1014/// callsFunctionThatReturnsTwice - Return true if the function has a call to
1015/// setjmp or other function that gcc recognizes as "returning twice".
1016bool Function::callsFunctionThatReturnsTwice() const {
1017 for (const Instruction &I : instructions(F: this))
1018 if (const auto *Call = dyn_cast<CallBase>(Val: &I))
1019 if (Call->hasFnAttr(Kind: Attribute::ReturnsTwice))
1020 return true;
1021
1022 return false;
1023}
1024
1025Constant *Function::getPersonalityFn() const {
1026 assert(hasPersonalityFn() && getNumOperands());
1027 return cast<Constant>(Val: Op<0>());
1028}
1029
1030void Function::setPersonalityFn(Constant *Fn) {
1031 setHungoffOperand<0>(Fn);
1032 setValueSubclassDataBit(Bit: 3, On: Fn != nullptr);
1033}
1034
1035Constant *Function::getPrefixData() const {
1036 assert(hasPrefixData() && getNumOperands());
1037 return cast<Constant>(Val: Op<1>());
1038}
1039
1040void Function::setPrefixData(Constant *PrefixData) {
1041 setHungoffOperand<1>(PrefixData);
1042 setValueSubclassDataBit(Bit: 1, On: PrefixData != nullptr);
1043}
1044
1045Constant *Function::getPrologueData() const {
1046 assert(hasPrologueData() && getNumOperands());
1047 return cast<Constant>(Val: Op<2>());
1048}
1049
1050void Function::setPrologueData(Constant *PrologueData) {
1051 setHungoffOperand<2>(PrologueData);
1052 setValueSubclassDataBit(Bit: 2, On: PrologueData != nullptr);
1053}
1054
1055void Function::allocHungoffUselist() {
1056 // If we've already allocated a uselist, stop here.
1057 if (getNumOperands())
1058 return;
1059
1060 allocHungoffUses(N: 3, /*IsPhi=*/ WithExtraValues: false);
1061 setNumHungOffUseOperands(3);
1062
1063 // Initialize the uselist with placeholder operands to allow traversal.
1064 auto *CPN = ConstantPointerNull::get(T: PointerType::get(C&: getContext(), AddressSpace: 0));
1065 Op<0>().set(CPN);
1066 Op<1>().set(CPN);
1067 Op<2>().set(CPN);
1068}
1069
1070template <int Idx>
1071void Function::setHungoffOperand(Constant *C) {
1072 if (C) {
1073 allocHungoffUselist();
1074 Op<Idx>().set(C);
1075 } else if (getNumOperands()) {
1076 Op<Idx>().set(ConstantPointerNull::get(T: PointerType::get(C&: getContext(), AddressSpace: 0)));
1077 }
1078}
1079
1080void Function::setValueSubclassDataBit(unsigned Bit, bool On) {
1081 assert(Bit < 16 && "SubclassData contains only 16 bits");
1082 if (On)
1083 setValueSubclassData(getSubclassDataFromValue() | (1 << Bit));
1084 else
1085 setValueSubclassData(getSubclassDataFromValue() & ~(1 << Bit));
1086}
1087
1088void Function::setEntryCount(uint64_t Count,
1089 const DenseSet<GlobalValue::GUID> *S) {
1090 auto ImportGUIDs = getImportGUIDs();
1091 if (S == nullptr && ImportGUIDs.size())
1092 S = &ImportGUIDs;
1093
1094 MDBuilder MDB(getContext());
1095 setMetadata(KindID: LLVMContext::MD_prof,
1096 Node: MDB.createFunctionEntryCount(Count, Synthetic: false, Imports: S));
1097}
1098
1099std::optional<uint64_t> Function::getEntryCount() const {
1100 MDNode *MD = getMetadata(KindID: LLVMContext::MD_prof);
1101 if (MD && MD->getOperand(I: 0))
1102 if (MDString *MDS = dyn_cast<MDString>(Val: MD->getOperand(I: 0))) {
1103 if (MDS->getString() != MDProfLabels::FunctionEntryCount)
1104 return std::nullopt;
1105 ConstantInt *CI = mdconst::extract<ConstantInt>(MD: MD->getOperand(I: 1));
1106 uint64_t Count = CI->getValue().getZExtValue();
1107 // A value of -1 is used for SamplePGO when there were no samples.
1108 // Treat this the same as unknown.
1109 if (Count == static_cast<uint64_t>(-1))
1110 return std::nullopt;
1111 return Count;
1112 }
1113 return std::nullopt;
1114}
1115
1116DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const {
1117 DenseSet<GlobalValue::GUID> R;
1118 if (MDNode *MD = getMetadata(KindID: LLVMContext::MD_prof))
1119 if (MDString *MDS = dyn_cast<MDString>(Val: MD->getOperand(I: 0)))
1120 if (MDS->getString() == MDProfLabels::FunctionEntryCount)
1121 for (unsigned i = 2; i < MD->getNumOperands(); i++)
1122 R.insert(V: mdconst::extract<ConstantInt>(MD: MD->getOperand(I: i))
1123 ->getValue()
1124 .getZExtValue());
1125 return R;
1126}
1127
1128bool Function::nullPointerIsDefined() const {
1129 return hasFnAttribute(Kind: Attribute::NullPointerIsValid);
1130}
1131
1132unsigned Function::getVScaleValue() const {
1133 Attribute Attr = getFnAttribute(Kind: Attribute::VScaleRange);
1134 if (!Attr.isValid())
1135 return 0;
1136
1137 unsigned VScale = Attr.getVScaleRangeMin();
1138 if (VScale && VScale == Attr.getVScaleRangeMax())
1139 return VScale;
1140
1141 return 0;
1142}
1143
1144bool llvm::NullPointerIsDefined(const Function *F, unsigned AS) {
1145 if (F && F->nullPointerIsDefined())
1146 return true;
1147
1148 if (AS != 0)
1149 return true;
1150
1151 return false;
1152}
1153
1154bool llvm::CallingConv::supportsNonVoidReturnType(CallingConv::ID CC) {
1155 switch (CC) {
1156 case CallingConv::C:
1157 case CallingConv::Fast:
1158 case CallingConv::Cold:
1159 case CallingConv::GHC:
1160 case CallingConv::HiPE:
1161 case CallingConv::AnyReg:
1162 case CallingConv::PreserveMost:
1163 case CallingConv::PreserveAll:
1164 case CallingConv::Swift:
1165 case CallingConv::CXX_FAST_TLS:
1166 case CallingConv::Tail:
1167 case CallingConv::CFGuard_Check:
1168 case CallingConv::SwiftTail:
1169 case CallingConv::PreserveNone:
1170 case CallingConv::X86_StdCall:
1171 case CallingConv::X86_FastCall:
1172 case CallingConv::ARM_APCS:
1173 case CallingConv::ARM_AAPCS:
1174 case CallingConv::ARM_AAPCS_VFP:
1175 case CallingConv::MSP430_INTR:
1176 case CallingConv::X86_ThisCall:
1177 case CallingConv::PTX_Device:
1178 case CallingConv::SPIR_FUNC:
1179 case CallingConv::Intel_OCL_BI:
1180 case CallingConv::X86_64_SysV:
1181 case CallingConv::Win64:
1182 case CallingConv::X86_VectorCall:
1183 case CallingConv::DUMMY_HHVM:
1184 case CallingConv::DUMMY_HHVM_C:
1185 case CallingConv::X86_INTR:
1186 case CallingConv::AVR_INTR:
1187 case CallingConv::AVR_SIGNAL:
1188 case CallingConv::AVR_BUILTIN:
1189 return true;
1190 case CallingConv::AMDGPU_KERNEL:
1191 case CallingConv::SPIR_KERNEL:
1192 case CallingConv::AMDGPU_CS_Chain:
1193 case CallingConv::AMDGPU_CS_ChainPreserve:
1194 return false;
1195 case CallingConv::AMDGPU_VS:
1196 case CallingConv::AMDGPU_HS:
1197 case CallingConv::AMDGPU_GS:
1198 case CallingConv::AMDGPU_PS:
1199 case CallingConv::AMDGPU_CS:
1200 case CallingConv::AMDGPU_LS:
1201 case CallingConv::AMDGPU_ES:
1202 case CallingConv::MSP430_BUILTIN:
1203 case CallingConv::AArch64_VectorCall:
1204 case CallingConv::AArch64_SVE_VectorCall:
1205 case CallingConv::WASM_EmscriptenInvoke:
1206 case CallingConv::AMDGPU_Gfx:
1207 case CallingConv::AMDGPU_Gfx_WholeWave:
1208 case CallingConv::M68k_INTR:
1209 case CallingConv::AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0:
1210 case CallingConv::AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2:
1211 case CallingConv::M68k_RTD:
1212 case CallingConv::GRAAL:
1213 case CallingConv::ARM64EC_Thunk_X64:
1214 case CallingConv::ARM64EC_Thunk_Native:
1215 case CallingConv::RISCV_VectorCall:
1216 case CallingConv::AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1:
1217 case CallingConv::RISCV_VLSCall_32:
1218 case CallingConv::RISCV_VLSCall_64:
1219 case CallingConv::RISCV_VLSCall_128:
1220 case CallingConv::RISCV_VLSCall_256:
1221 case CallingConv::RISCV_VLSCall_512:
1222 case CallingConv::RISCV_VLSCall_1024:
1223 case CallingConv::RISCV_VLSCall_2048:
1224 case CallingConv::RISCV_VLSCall_4096:
1225 case CallingConv::RISCV_VLSCall_8192:
1226 case CallingConv::RISCV_VLSCall_16384:
1227 case CallingConv::RISCV_VLSCall_32768:
1228 case CallingConv::RISCV_VLSCall_65536:
1229 return true;
1230 default:
1231 return false;
1232 }
1233
1234 llvm_unreachable("covered callingconv switch");
1235}
1236