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