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