LLVM 20.0.0git
Function.cpp
Go to the documentation of this file.
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"
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/ADT/BitVector.h"
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringRef.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"
28#include "llvm/IR/Constants.h"
30#include "llvm/IR/GlobalValue.h"
32#include "llvm/IR/Instruction.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"
41#include "llvm/IR/Type.h"
42#include "llvm/IR/Use.h"
43#include "llvm/IR/User.h"
44#include "llvm/IR/Value.h"
50#include "llvm/Support/ModRef.h"
51#include <cassert>
52#include <cstddef>
53#include <cstdint>
54#include <cstring>
55#include <string>
56
57using namespace llvm;
59
60// Explicit instantiations of SymbolTableListTraits since some of the methods
61// are not in the public header file...
63
65 "non-global-value-max-name-size", cl::Hidden, cl::init(1024),
66 cl::desc("Maximum size for the name of non-global values."));
67
69
70void Function::renumberBlocks() {
71 validateBlockNumbers();
72
73 NextBlockNum = 0;
74 for (auto &BB : *this)
75 BB.Number = NextBlockNum++;
76 BlockNumEpoch++;
77}
78
79void Function::validateBlockNumbers() const {
80#ifndef NDEBUG
81 BitVector Numbers(NextBlockNum);
82 for (const auto &BB : *this) {
83 unsigned Num = BB.getNumber();
84 assert(Num < NextBlockNum && "out of range block number");
85 assert(!Numbers[Num] && "duplicate block numbers");
86 Numbers.set(Num);
87 }
88#endif
89}
90
91void Function::convertToNewDbgValues() {
92 IsNewDbgInfoFormat = true;
93 for (auto &BB : *this) {
94 BB.convertToNewDbgValues();
95 }
96}
97
98void Function::convertFromNewDbgValues() {
99 IsNewDbgInfoFormat = false;
100 for (auto &BB : *this) {
101 BB.convertFromNewDbgValues();
102 }
103}
104
105void Function::setIsNewDbgInfoFormat(bool NewFlag) {
106 if (NewFlag && !IsNewDbgInfoFormat)
107 convertToNewDbgValues();
108 else if (!NewFlag && IsNewDbgInfoFormat)
109 convertFromNewDbgValues();
110}
111void Function::setNewDbgInfoFormatFlag(bool NewFlag) {
112 for (auto &BB : *this) {
113 BB.setNewDbgInfoFormatFlag(NewFlag);
114 }
115 IsNewDbgInfoFormat = NewFlag;
116}
117
118//===----------------------------------------------------------------------===//
119// Argument Implementation
120//===----------------------------------------------------------------------===//
121
122Argument::Argument(Type *Ty, const Twine &Name, Function *Par, unsigned ArgNo)
123 : Value(Ty, Value::ArgumentVal), Parent(Par), ArgNo(ArgNo) {
124 setName(Name);
125}
126
127void Argument::setParent(Function *parent) {
128 Parent = parent;
129}
130
131bool Argument::hasNonNullAttr(bool AllowUndefOrPoison) const {
132 if (!getType()->isPointerTy()) return false;
133 if (getParent()->hasParamAttribute(getArgNo(), Attribute::NonNull) &&
134 (AllowUndefOrPoison ||
135 getParent()->hasParamAttribute(getArgNo(), Attribute::NoUndef)))
136 return true;
137 else if (getDereferenceableBytes() > 0 &&
140 return true;
141 return false;
142}
143
144bool Argument::hasByValAttr() const {
145 if (!getType()->isPointerTy()) return false;
146 return hasAttribute(Attribute::ByVal);
147}
148
149bool Argument::hasByRefAttr() const {
150 if (!getType()->isPointerTy())
151 return false;
152 return hasAttribute(Attribute::ByRef);
153}
154
155bool Argument::hasSwiftSelfAttr() const {
156 return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftSelf);
157}
158
159bool Argument::hasSwiftErrorAttr() const {
160 return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftError);
161}
162
163bool Argument::hasInAllocaAttr() const {
164 if (!getType()->isPointerTy()) return false;
165 return hasAttribute(Attribute::InAlloca);
166}
167
168bool Argument::hasPreallocatedAttr() const {
169 if (!getType()->isPointerTy())
170 return false;
171 return hasAttribute(Attribute::Preallocated);
172}
173
174bool Argument::hasPassPointeeByValueCopyAttr() const {
175 if (!getType()->isPointerTy()) return false;
176 AttributeList Attrs = getParent()->getAttributes();
177 return Attrs.hasParamAttr(getArgNo(), Attribute::ByVal) ||
178 Attrs.hasParamAttr(getArgNo(), Attribute::InAlloca) ||
179 Attrs.hasParamAttr(getArgNo(), Attribute::Preallocated);
180}
181
182bool Argument::hasPointeeInMemoryValueAttr() const {
183 if (!getType()->isPointerTy())
184 return false;
185 AttributeList Attrs = getParent()->getAttributes();
186 return Attrs.hasParamAttr(getArgNo(), Attribute::ByVal) ||
187 Attrs.hasParamAttr(getArgNo(), Attribute::StructRet) ||
188 Attrs.hasParamAttr(getArgNo(), Attribute::InAlloca) ||
189 Attrs.hasParamAttr(getArgNo(), Attribute::Preallocated) ||
190 Attrs.hasParamAttr(getArgNo(), Attribute::ByRef);
191}
192
193/// For a byval, sret, inalloca, or preallocated parameter, get the in-memory
194/// parameter type.
195static Type *getMemoryParamAllocType(AttributeSet ParamAttrs) {
196 // FIXME: All the type carrying attributes are mutually exclusive, so there
197 // should be a single query to get the stored type that handles any of them.
198 if (Type *ByValTy = ParamAttrs.getByValType())
199 return ByValTy;
200 if (Type *ByRefTy = ParamAttrs.getByRefType())
201 return ByRefTy;
202 if (Type *PreAllocTy = ParamAttrs.getPreallocatedType())
203 return PreAllocTy;
204 if (Type *InAllocaTy = ParamAttrs.getInAllocaType())
205 return InAllocaTy;
206 if (Type *SRetTy = ParamAttrs.getStructRetType())
207 return SRetTy;
208
209 return nullptr;
210}
211
212uint64_t Argument::getPassPointeeByValueCopySize(const DataLayout &DL) const {
213 AttributeSet ParamAttrs =
214 getParent()->getAttributes().getParamAttrs(getArgNo());
215 if (Type *MemTy = getMemoryParamAllocType(ParamAttrs))
216 return DL.getTypeAllocSize(MemTy);
217 return 0;
218}
219
220Type *Argument::getPointeeInMemoryValueType() const {
221 AttributeSet ParamAttrs =
222 getParent()->getAttributes().getParamAttrs(getArgNo());
223 return getMemoryParamAllocType(ParamAttrs);
224}
225
226MaybeAlign Argument::getParamAlign() const {
227 assert(getType()->isPointerTy() && "Only pointers have alignments");
228 return getParent()->getParamAlign(getArgNo());
229}
230
231MaybeAlign Argument::getParamStackAlign() const {
232 return getParent()->getParamStackAlign(getArgNo());
233}
234
235Type *Argument::getParamByValType() const {
236 assert(getType()->isPointerTy() && "Only pointers have byval types");
237 return getParent()->getParamByValType(getArgNo());
238}
239
240Type *Argument::getParamStructRetType() const {
241 assert(getType()->isPointerTy() && "Only pointers have sret types");
242 return getParent()->getParamStructRetType(getArgNo());
243}
244
245Type *Argument::getParamByRefType() const {
246 assert(getType()->isPointerTy() && "Only pointers have byref types");
247 return getParent()->getParamByRefType(getArgNo());
248}
249
250Type *Argument::getParamInAllocaType() const {
251 assert(getType()->isPointerTy() && "Only pointers have inalloca types");
252 return getParent()->getParamInAllocaType(getArgNo());
253}
254
255uint64_t Argument::getDereferenceableBytes() const {
257 "Only pointers have dereferenceable bytes");
258 return getParent()->getParamDereferenceableBytes(getArgNo());
259}
260
261uint64_t Argument::getDereferenceableOrNullBytes() const {
263 "Only pointers have dereferenceable bytes");
264 return getParent()->getParamDereferenceableOrNullBytes(getArgNo());
265}
266
267FPClassTest Argument::getNoFPClass() const {
268 return getParent()->getParamNoFPClass(getArgNo());
269}
270
271std::optional<ConstantRange> Argument::getRange() const {
272 const Attribute RangeAttr = getAttribute(llvm::Attribute::Range);
273 if (RangeAttr.isValid())
274 return RangeAttr.getRange();
275 return std::nullopt;
276}
277
278bool Argument::hasNestAttr() const {
279 if (!getType()->isPointerTy()) return false;
280 return hasAttribute(Attribute::Nest);
281}
282
283bool Argument::hasNoAliasAttr() const {
284 if (!getType()->isPointerTy()) return false;
285 return hasAttribute(Attribute::NoAlias);
286}
287
288bool Argument::hasNoCaptureAttr() const {
289 if (!getType()->isPointerTy()) return false;
290 return hasAttribute(Attribute::NoCapture);
291}
292
293bool Argument::hasNoFreeAttr() const {
294 if (!getType()->isPointerTy()) return false;
295 return hasAttribute(Attribute::NoFree);
296}
297
298bool Argument::hasStructRetAttr() const {
299 if (!getType()->isPointerTy()) return false;
300 return hasAttribute(Attribute::StructRet);
301}
302
303bool Argument::hasInRegAttr() const {
304 return hasAttribute(Attribute::InReg);
305}
306
307bool Argument::hasReturnedAttr() const {
308 return hasAttribute(Attribute::Returned);
309}
310
311bool Argument::hasZExtAttr() const {
312 return hasAttribute(Attribute::ZExt);
313}
314
315bool Argument::hasSExtAttr() const {
316 return hasAttribute(Attribute::SExt);
317}
318
319bool Argument::onlyReadsMemory() const {
320 AttributeList Attrs = getParent()->getAttributes();
321 return Attrs.hasParamAttr(getArgNo(), Attribute::ReadOnly) ||
322 Attrs.hasParamAttr(getArgNo(), Attribute::ReadNone);
323}
324
325void Argument::addAttrs(AttrBuilder &B) {
326 AttributeList AL = getParent()->getAttributes();
327 AL = AL.addParamAttributes(Parent->getContext(), getArgNo(), B);
328 getParent()->setAttributes(AL);
329}
330
331void Argument::addAttr(Attribute::AttrKind Kind) {
332 getParent()->addParamAttr(getArgNo(), Kind);
333}
334
335void Argument::addAttr(Attribute Attr) {
336 getParent()->addParamAttr(getArgNo(), Attr);
337}
338
339void Argument::removeAttr(Attribute::AttrKind Kind) {
340 getParent()->removeParamAttr(getArgNo(), Kind);
341}
342
343void Argument::removeAttrs(const AttributeMask &AM) {
344 AttributeList AL = getParent()->getAttributes();
345 AL = AL.removeParamAttributes(Parent->getContext(), getArgNo(), AM);
346 getParent()->setAttributes(AL);
347}
348
349bool Argument::hasAttribute(Attribute::AttrKind Kind) const {
350 return getParent()->hasParamAttribute(getArgNo(), Kind);
351}
352
353bool Argument::hasAttribute(StringRef Kind) const {
354 return getParent()->hasParamAttribute(getArgNo(), Kind);
355}
356
357Attribute Argument::getAttribute(Attribute::AttrKind Kind) const {
358 return getParent()->getParamAttribute(getArgNo(), Kind);
359}
360
361AttributeSet Argument::getAttributes() const {
362 return getParent()->getAttributes().getParamAttrs(getArgNo());
363}
364
365//===----------------------------------------------------------------------===//
366// Helper Methods in Function
367//===----------------------------------------------------------------------===//
368
369LLVMContext &Function::getContext() const {
370 return getType()->getContext();
371}
372
373const DataLayout &Function::getDataLayout() const {
374 return getParent()->getDataLayout();
375}
376
377unsigned Function::getInstructionCount() const {
378 unsigned NumInstrs = 0;
379 for (const BasicBlock &BB : BasicBlocks)
380 NumInstrs += std::distance(BB.instructionsWithoutDebug().begin(),
381 BB.instructionsWithoutDebug().end());
382 return NumInstrs;
383}
384
385Function *Function::Create(FunctionType *Ty, LinkageTypes Linkage,
386 const Twine &N, Module &M) {
387 return Create(Ty, Linkage, M.getDataLayout().getProgramAddressSpace(), N, &M);
388}
389
390Function *Function::createWithDefaultAttr(FunctionType *Ty,
391 LinkageTypes Linkage,
392 unsigned AddrSpace, const Twine &N,
393 Module *M) {
394 auto *F = new (AllocMarker) Function(Ty, Linkage, AddrSpace, N, M);
395 AttrBuilder B(F->getContext());
396 UWTableKind UWTable = M->getUwtable();
397 if (UWTable != UWTableKind::None)
398 B.addUWTableAttr(UWTable);
399 switch (M->getFramePointer()) {
400 case FramePointerKind::None:
401 // 0 ("none") is the default.
402 break;
403 case FramePointerKind::Reserved:
404 B.addAttribute("frame-pointer", "reserved");
405 break;
406 case FramePointerKind::NonLeaf:
407 B.addAttribute("frame-pointer", "non-leaf");
408 break;
409 case FramePointerKind::All:
410 B.addAttribute("frame-pointer", "all");
411 break;
412 }
413 if (M->getModuleFlag("function_return_thunk_extern"))
414 B.addAttribute(Attribute::FnRetThunkExtern);
415 StringRef DefaultCPU = F->getContext().getDefaultTargetCPU();
416 if (!DefaultCPU.empty())
417 B.addAttribute("target-cpu", DefaultCPU);
418 StringRef DefaultFeatures = F->getContext().getDefaultTargetFeatures();
419 if (!DefaultFeatures.empty())
420 B.addAttribute("target-features", DefaultFeatures);
421
422 // Check if the module attribute is present and not zero.
423 auto isModuleAttributeSet = [&](const StringRef &ModAttr) -> bool {
424 const auto *Attr =
425 mdconst::extract_or_null<ConstantInt>(M->getModuleFlag(ModAttr));
426 return Attr && !Attr->isZero();
427 };
428
429 auto AddAttributeIfSet = [&](const StringRef &ModAttr) {
430 if (isModuleAttributeSet(ModAttr))
431 B.addAttribute(ModAttr);
432 };
433
434 StringRef SignType = "none";
435 if (isModuleAttributeSet("sign-return-address"))
436 SignType = "non-leaf";
437 if (isModuleAttributeSet("sign-return-address-all"))
438 SignType = "all";
439 if (SignType != "none") {
440 B.addAttribute("sign-return-address", SignType);
441 B.addAttribute("sign-return-address-key",
442 isModuleAttributeSet("sign-return-address-with-bkey")
443 ? "b_key"
444 : "a_key");
445 }
446 AddAttributeIfSet("branch-target-enforcement");
447 AddAttributeIfSet("branch-protection-pauth-lr");
448 AddAttributeIfSet("guarded-control-stack");
449
450 F->addFnAttrs(B);
451 return F;
452}
453
454void Function::removeFromParent() {
455 getParent()->getFunctionList().remove(getIterator());
456}
457
458void Function::eraseFromParent() {
459 getParent()->getFunctionList().erase(getIterator());
460}
461
462void Function::splice(Function::iterator ToIt, Function *FromF,
463 Function::iterator FromBeginIt,
464 Function::iterator FromEndIt) {
465#ifdef EXPENSIVE_CHECKS
466 // Check that FromBeginIt is before FromEndIt.
467 auto FromFEnd = FromF->end();
468 for (auto It = FromBeginIt; It != FromEndIt; ++It)
469 assert(It != FromFEnd && "FromBeginIt not before FromEndIt!");
470#endif // EXPENSIVE_CHECKS
471 BasicBlocks.splice(ToIt, FromF->BasicBlocks, FromBeginIt, FromEndIt);
472}
473
474Function::iterator Function::erase(Function::iterator FromIt,
475 Function::iterator ToIt) {
476 return BasicBlocks.erase(FromIt, ToIt);
477}
478
479//===----------------------------------------------------------------------===//
480// Function Implementation
481//===----------------------------------------------------------------------===//
482
483static unsigned computeAddrSpace(unsigned AddrSpace, Module *M) {
484 // If AS == -1 and we are passed a valid module pointer we place the function
485 // in the program address space. Otherwise we default to AS0.
486 if (AddrSpace == static_cast<unsigned>(-1))
487 return M ? M->getDataLayout().getProgramAddressSpace() : 0;
488 return AddrSpace;
489}
490
491Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
492 const Twine &name, Module *ParentModule)
493 : GlobalObject(Ty, Value::FunctionVal, AllocMarker, Linkage, name,
494 computeAddrSpace(AddrSpace, ParentModule)),
495 NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
496 assert(FunctionType::isValidReturnType(getReturnType()) &&
497 "invalid return type");
498 setGlobalObjectSubClassData(0);
499
500 // We only need a symbol table for a function if the context keeps value names
501 if (!getContext().shouldDiscardValueNames())
502 SymTab = std::make_unique<ValueSymbolTable>(NonGlobalValueMaxNameSize);
503
504 // If the function has arguments, mark them as lazily built.
505 if (Ty->getNumParams())
506 setValueSubclassData(1); // Set the "has lazy arguments" bit.
507
508 if (ParentModule) {
509 ParentModule->getFunctionList().push_back(this);
510 IsNewDbgInfoFormat = ParentModule->IsNewDbgInfoFormat;
511 }
512
513 HasLLVMReservedName = getName().starts_with("llvm.");
514 // Ensure intrinsics have the right parameter attributes.
515 // Note, the IntID field will have been set in Value::setName if this function
516 // name is a valid intrinsic ID.
517 if (IntID)
518 setAttributes(Intrinsic::getAttributes(getContext(), IntID));
519}
520
521Function::~Function() {
522 validateBlockNumbers();
523
524 dropAllReferences(); // After this it is safe to delete instructions.
525
526 // Delete all of the method arguments and unlink from symbol table...
527 if (Arguments)
528 clearArguments();
529
530 // Remove the function from the on-the-side GC table.
531 clearGC();
532}
533
534void Function::BuildLazyArguments() const {
535 // Create the arguments vector, all arguments start out unnamed.
536 auto *FT = getFunctionType();
537 if (NumArgs > 0) {
538 Arguments = std::allocator<Argument>().allocate(NumArgs);
539 for (unsigned i = 0, e = NumArgs; i != e; ++i) {
540 Type *ArgTy = FT->getParamType(i);
541 assert(!ArgTy->isVoidTy() && "Cannot have void typed arguments!");
542 new (Arguments + i) Argument(ArgTy, "", const_cast<Function *>(this), i);
543 }
544 }
545
546 // Clear the lazy arguments bit.
547 unsigned SDC = getSubclassDataFromValue();
548 SDC &= ~(1 << 0);
549 const_cast<Function*>(this)->setValueSubclassData(SDC);
550 assert(!hasLazyArguments());
551}
552
553static MutableArrayRef<Argument> makeArgArray(Argument *Args, size_t Count) {
554 return MutableArrayRef<Argument>(Args, Count);
555}
556
557bool Function::isConstrainedFPIntrinsic() const {
558 return Intrinsic::isConstrainedFPIntrinsic(getIntrinsicID());
559}
560
561void Function::clearArguments() {
562 for (Argument &A : makeArgArray(Arguments, NumArgs)) {
563 A.setName("");
564 A.~Argument();
565 }
566 std::allocator<Argument>().deallocate(Arguments, NumArgs);
567 Arguments = nullptr;
568}
569
570void Function::stealArgumentListFrom(Function &Src) {
571 assert(isDeclaration() && "Expected no references to current arguments");
572
573 // Drop the current arguments, if any, and set the lazy argument bit.
574 if (!hasLazyArguments()) {
576 [](const Argument &A) { return A.use_empty(); }) &&
577 "Expected arguments to be unused in declaration");
578 clearArguments();
579 setValueSubclassData(getSubclassDataFromValue() | (1 << 0));
580 }
581
582 // Nothing to steal if Src has lazy arguments.
583 if (Src.hasLazyArguments())
584 return;
585
586 // Steal arguments from Src, and fix the lazy argument bits.
587 assert(arg_size() == Src.arg_size());
588 Arguments = Src.Arguments;
589 Src.Arguments = nullptr;
590 for (Argument &A : makeArgArray(Arguments, NumArgs)) {
591 // FIXME: This does the work of transferNodesFromList inefficiently.
593 if (A.hasName())
594 Name = A.getName();
595 if (!Name.empty())
596 A.setName("");
597 A.setParent(this);
598 if (!Name.empty())
599 A.setName(Name);
600 }
601
602 setValueSubclassData(getSubclassDataFromValue() & ~(1 << 0));
603 assert(!hasLazyArguments());
604 Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0));
605}
606
607void Function::deleteBodyImpl(bool ShouldDrop) {
608 setIsMaterializable(false);
609
610 for (BasicBlock &BB : *this)
612
613 // Delete all basic blocks. They are now unused, except possibly by
614 // blockaddresses, but BasicBlock's destructor takes care of those.
615 while (!BasicBlocks.empty())
616 BasicBlocks.begin()->eraseFromParent();
617
618 if (getNumOperands()) {
619 if (ShouldDrop) {
620 // Drop uses of any optional data (real or placeholder).
621 User::dropAllReferences();
622 setNumHungOffUseOperands(0);
623 } else {
624 // The code needs to match Function::allocHungoffUselist().
625 auto *CPN = ConstantPointerNull::get(PointerType::get(getContext(), 0));
626 Op<0>().set(CPN);
627 Op<1>().set(CPN);
628 Op<2>().set(CPN);
629 }
630 setValueSubclassData(getSubclassDataFromValue() & ~0xe);
631 }
632
633 // Metadata is stored in a side-table.
634 clearMetadata();
635}
636
637void Function::addAttributeAtIndex(unsigned i, Attribute Attr) {
638 AttributeSets = AttributeSets.addAttributeAtIndex(getContext(), i, Attr);
639}
640
641void Function::addFnAttr(Attribute::AttrKind Kind) {
642 AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind);
643}
644
645void Function::addFnAttr(StringRef Kind, StringRef Val) {
646 AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind, Val);
647}
648
649void Function::addFnAttr(Attribute Attr) {
650 AttributeSets = AttributeSets.addFnAttribute(getContext(), Attr);
651}
652
653void Function::addFnAttrs(const AttrBuilder &Attrs) {
654 AttributeSets = AttributeSets.addFnAttributes(getContext(), Attrs);
655}
656
657void Function::addRetAttr(Attribute::AttrKind Kind) {
658 AttributeSets = AttributeSets.addRetAttribute(getContext(), Kind);
659}
660
661void Function::addRetAttr(Attribute Attr) {
662 AttributeSets = AttributeSets.addRetAttribute(getContext(), Attr);
663}
664
665void Function::addRetAttrs(const AttrBuilder &Attrs) {
666 AttributeSets = AttributeSets.addRetAttributes(getContext(), Attrs);
667}
668
669void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
670 AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Kind);
671}
672
673void Function::addParamAttr(unsigned ArgNo, Attribute Attr) {
674 AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Attr);
675}
676
677void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {
678 AttributeSets = AttributeSets.addParamAttributes(getContext(), ArgNo, Attrs);
679}
680
681void Function::removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) {
682 AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind);
683}
684
685void Function::removeAttributeAtIndex(unsigned i, StringRef Kind) {
686 AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind);
687}
688
689void Function::removeFnAttr(Attribute::AttrKind Kind) {
690 AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind);
691}
692
693void Function::removeFnAttr(StringRef Kind) {
694 AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind);
695}
696
697void Function::removeFnAttrs(const AttributeMask &AM) {
698 AttributeSets = AttributeSets.removeFnAttributes(getContext(), AM);
699}
700
701void Function::removeRetAttr(Attribute::AttrKind Kind) {
702 AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind);
703}
704
705void Function::removeRetAttr(StringRef Kind) {
706 AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind);
707}
708
709void Function::removeRetAttrs(const AttributeMask &Attrs) {
710 AttributeSets = AttributeSets.removeRetAttributes(getContext(), Attrs);
711}
712
713void Function::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
714 AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind);
715}
716
717void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) {
718 AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind);
719}
720
721void Function::removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs) {
722 AttributeSets =
723 AttributeSets.removeParamAttributes(getContext(), ArgNo, Attrs);
724}
725
726void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) {
727 AttributeSets =
728 AttributeSets.addDereferenceableParamAttr(getContext(), ArgNo, Bytes);
729}
730
731bool Function::hasFnAttribute(Attribute::AttrKind Kind) const {
732 return AttributeSets.hasFnAttr(Kind);
733}
734
735bool Function::hasFnAttribute(StringRef Kind) const {
736 return AttributeSets.hasFnAttr(Kind);
737}
738
739bool Function::hasRetAttribute(Attribute::AttrKind Kind) const {
740 return AttributeSets.hasRetAttr(Kind);
741}
742
743bool Function::hasParamAttribute(unsigned ArgNo,
744 Attribute::AttrKind Kind) const {
745 return AttributeSets.hasParamAttr(ArgNo, Kind);
746}
747
748bool Function::hasParamAttribute(unsigned ArgNo, StringRef Kind) const {
749 return AttributeSets.hasParamAttr(ArgNo, Kind);
750}
751
752Attribute Function::getAttributeAtIndex(unsigned i,
753 Attribute::AttrKind Kind) const {
754 return AttributeSets.getAttributeAtIndex(i, Kind);
755}
756
757Attribute Function::getAttributeAtIndex(unsigned i, StringRef Kind) const {
758 return AttributeSets.getAttributeAtIndex(i, Kind);
759}
760
761bool Function::hasAttributeAtIndex(unsigned Idx,
762 Attribute::AttrKind Kind) const {
763 return AttributeSets.hasAttributeAtIndex(Idx, Kind);
764}
765
766Attribute Function::getFnAttribute(Attribute::AttrKind Kind) const {
767 return AttributeSets.getFnAttr(Kind);
768}
769
770Attribute Function::getFnAttribute(StringRef Kind) const {
771 return AttributeSets.getFnAttr(Kind);
772}
773
774Attribute Function::getRetAttribute(Attribute::AttrKind Kind) const {
775 return AttributeSets.getRetAttr(Kind);
776}
777
778uint64_t Function::getFnAttributeAsParsedInteger(StringRef Name,
779 uint64_t Default) const {
780 Attribute A = getFnAttribute(Name);
782 if (A.isStringAttribute()) {
783 StringRef Str = A.getValueAsString();
784 if (Str.getAsInteger(0, Result))
785 getContext().emitError("cannot parse integer attribute " + Name);
786 }
787
788 return Result;
789}
790
791/// gets the specified attribute from the list of attributes.
792Attribute Function::getParamAttribute(unsigned ArgNo,
793 Attribute::AttrKind Kind) const {
794 return AttributeSets.getParamAttr(ArgNo, Kind);
795}
796
797void Function::addDereferenceableOrNullParamAttr(unsigned ArgNo,
798 uint64_t Bytes) {
799 AttributeSets = AttributeSets.addDereferenceableOrNullParamAttr(getContext(),
800 ArgNo, Bytes);
801}
802
803void Function::addRangeRetAttr(const ConstantRange &CR) {
804 AttributeSets = AttributeSets.addRangeRetAttr(getContext(), CR);
805}
806
807DenormalMode Function::getDenormalMode(const fltSemantics &FPType) const {
808 if (&FPType == &APFloat::IEEEsingle()) {
809 DenormalMode Mode = getDenormalModeF32Raw();
810 // If the f32 variant of the attribute isn't specified, try to use the
811 // generic one.
812 if (Mode.isValid())
813 return Mode;
814 }
815
816 return getDenormalModeRaw();
817}
818
819DenormalMode Function::getDenormalModeRaw() const {
820 Attribute Attr = getFnAttribute("denormal-fp-math");
821 StringRef Val = Attr.getValueAsString();
822 return parseDenormalFPAttribute(Val);
823}
824
825DenormalMode Function::getDenormalModeF32Raw() const {
826 Attribute Attr = getFnAttribute("denormal-fp-math-f32");
827 if (Attr.isValid()) {
828 StringRef Val = Attr.getValueAsString();
829 return parseDenormalFPAttribute(Val);
830 }
831
832 return DenormalMode::getInvalid();
833}
834
835const std::string &Function::getGC() const {
836 assert(hasGC() && "Function has no collector");
837 return getContext().getGC(*this);
838}
839
840void Function::setGC(std::string Str) {
841 setValueSubclassDataBit(14, !Str.empty());
842 getContext().setGC(*this, std::move(Str));
843}
844
845void Function::clearGC() {
846 if (!hasGC())
847 return;
848 getContext().deleteGC(*this);
849 setValueSubclassDataBit(14, false);
850}
851
852bool Function::hasStackProtectorFnAttr() const {
853 return hasFnAttribute(Attribute::StackProtect) ||
854 hasFnAttribute(Attribute::StackProtectStrong) ||
855 hasFnAttribute(Attribute::StackProtectReq);
856}
857
858/// Copy all additional attributes (those not needed to create a Function) from
859/// the Function Src to this one.
860void Function::copyAttributesFrom(const Function *Src) {
861 GlobalObject::copyAttributesFrom(Src);
862 setCallingConv(Src->getCallingConv());
863 setAttributes(Src->getAttributes());
864 if (Src->hasGC())
865 setGC(Src->getGC());
866 else
867 clearGC();
868 if (Src->hasPersonalityFn())
869 setPersonalityFn(Src->getPersonalityFn());
870 if (Src->hasPrefixData())
871 setPrefixData(Src->getPrefixData());
872 if (Src->hasPrologueData())
873 setPrologueData(Src->getPrologueData());
874}
875
876MemoryEffects Function::getMemoryEffects() const {
878}
879void Function::setMemoryEffects(MemoryEffects ME) {
880 addFnAttr(Attribute::getWithMemoryEffects(getContext(), ME));
881}
882
883/// Determine if the function does not access memory.
884bool Function::doesNotAccessMemory() const {
885 return getMemoryEffects().doesNotAccessMemory();
886}
887void Function::setDoesNotAccessMemory() {
888 setMemoryEffects(MemoryEffects::none());
889}
890
891/// Determine if the function does not access or only reads memory.
892bool Function::onlyReadsMemory() const {
893 return getMemoryEffects().onlyReadsMemory();
894}
895void Function::setOnlyReadsMemory() {
896 setMemoryEffects(getMemoryEffects() & MemoryEffects::readOnly());
897}
898
899/// Determine if the function does not access or only writes memory.
900bool Function::onlyWritesMemory() const {
901 return getMemoryEffects().onlyWritesMemory();
902}
903void Function::setOnlyWritesMemory() {
904 setMemoryEffects(getMemoryEffects() & MemoryEffects::writeOnly());
905}
906
907/// Determine if the call can access memmory only using pointers based
908/// on its arguments.
909bool Function::onlyAccessesArgMemory() const {
910 return getMemoryEffects().onlyAccessesArgPointees();
911}
912void Function::setOnlyAccessesArgMemory() {
913 setMemoryEffects(getMemoryEffects() & MemoryEffects::argMemOnly());
914}
915
916/// Determine if the function may only access memory that is
917/// inaccessible from the IR.
918bool Function::onlyAccessesInaccessibleMemory() const {
919 return getMemoryEffects().onlyAccessesInaccessibleMem();
920}
921void Function::setOnlyAccessesInaccessibleMemory() {
922 setMemoryEffects(getMemoryEffects() & MemoryEffects::inaccessibleMemOnly());
923}
924
925/// Determine if the function may only access memory that is
926/// either inaccessible from the IR or pointed to by its arguments.
927bool Function::onlyAccessesInaccessibleMemOrArgMem() const {
928 return getMemoryEffects().onlyAccessesInaccessibleOrArgMem();
929}
930void Function::setOnlyAccessesInaccessibleMemOrArgMem() {
931 setMemoryEffects(getMemoryEffects() &
932 MemoryEffects::inaccessibleOrArgMemOnly());
933}
934
935bool Function::isTargetIntrinsic() const {
936 return Intrinsic::isTargetIntrinsic(IntID);
937}
938
939void Function::updateAfterNameChange() {
940 LibFuncCache = UnknownLibFunc;
942 if (!Name.starts_with("llvm.")) {
943 HasLLVMReservedName = false;
944 IntID = Intrinsic::not_intrinsic;
945 return;
946 }
947 HasLLVMReservedName = true;
948 IntID = Intrinsic::lookupIntrinsicID(Name);
949}
950
951/// hasAddressTaken - returns true if there are any uses of this function
952/// other than direct calls or invokes to it. Optionally ignores callback
953/// uses, assume like pointer annotation calls, and references in llvm.used
954/// and llvm.compiler.used variables.
955bool Function::hasAddressTaken(const User **PutOffender,
956 bool IgnoreCallbackUses,
957 bool IgnoreAssumeLikeCalls, bool IgnoreLLVMUsed,
958 bool IgnoreARCAttachedCall,
959 bool IgnoreCastedDirectCall) const {
960 for (const Use &U : uses()) {
961 const User *FU = U.getUser();
962 if (isa<BlockAddress>(FU))
963 continue;
964
965 if (IgnoreCallbackUses) {
966 AbstractCallSite ACS(&U);
967 if (ACS && ACS.isCallbackCall())
968 continue;
969 }
970
971 const auto *Call = dyn_cast<CallBase>(FU);
972 if (!Call) {
973 if (IgnoreAssumeLikeCalls &&
974 isa<BitCastOperator, AddrSpaceCastOperator>(FU) &&
975 all_of(FU->users(), [](const User *U) {
976 if (const auto *I = dyn_cast<IntrinsicInst>(U))
977 return I->isAssumeLikeIntrinsic();
978 return false;
979 })) {
980 continue;
981 }
982
983 if (IgnoreLLVMUsed && !FU->user_empty()) {
984 const User *FUU = FU;
985 if (isa<BitCastOperator, AddrSpaceCastOperator>(FU) &&
986 FU->hasOneUse() && !FU->user_begin()->user_empty())
987 FUU = *FU->user_begin();
988 if (llvm::all_of(FUU->users(), [](const User *U) {
989 if (const auto *GV = dyn_cast<GlobalVariable>(U))
990 return GV->hasName() &&
991 (GV->getName() == "llvm.compiler.used" ||
992 GV->getName() == "llvm.used");
993 return false;
994 }))
995 continue;
996 }
997 if (PutOffender)
998 *PutOffender = FU;
999 return true;
1000 }
1001
1002 if (IgnoreAssumeLikeCalls) {
1003 if (const auto *I = dyn_cast<IntrinsicInst>(Call))
1004 if (I->isAssumeLikeIntrinsic())
1005 continue;
1006 }
1007
1008 if (!Call->isCallee(&U) || (!IgnoreCastedDirectCall &&
1009 Call->getFunctionType() != getFunctionType())) {
1010 if (IgnoreARCAttachedCall &&
1011 Call->isOperandBundleOfType(LLVMContext::OB_clang_arc_attachedcall,
1012 U.getOperandNo()))
1013 continue;
1014
1015 if (PutOffender)
1016 *PutOffender = FU;
1017 return true;
1018 }
1019 }
1020 return false;
1021}
1022
1023bool Function::isDefTriviallyDead() const {
1024 // Check the linkage
1025 if (!hasLinkOnceLinkage() && !hasLocalLinkage() &&
1026 !hasAvailableExternallyLinkage())
1027 return false;
1028
1029 // Check if the function is used by anything other than a blockaddress.
1030 for (const User *U : users())
1031 if (!isa<BlockAddress>(U))
1032 return false;
1033
1034 return true;
1035}
1036
1037/// callsFunctionThatReturnsTwice - Return true if the function has a call to
1038/// setjmp or other function that gcc recognizes as "returning twice".
1039bool Function::callsFunctionThatReturnsTwice() const {
1040 for (const Instruction &I : instructions(this))
1041 if (const auto *Call = dyn_cast<CallBase>(&I))
1042 if (Call->hasFnAttr(Attribute::ReturnsTwice))
1043 return true;
1044
1045 return false;
1046}
1047
1048Constant *Function::getPersonalityFn() const {
1049 assert(hasPersonalityFn() && getNumOperands());
1050 return cast<Constant>(Op<0>());
1051}
1052
1053void Function::setPersonalityFn(Constant *Fn) {
1054 setHungoffOperand<0>(Fn);
1055 setValueSubclassDataBit(3, Fn != nullptr);
1056}
1057
1058Constant *Function::getPrefixData() const {
1059 assert(hasPrefixData() && getNumOperands());
1060 return cast<Constant>(Op<1>());
1061}
1062
1063void Function::setPrefixData(Constant *PrefixData) {
1064 setHungoffOperand<1>(PrefixData);
1065 setValueSubclassDataBit(1, PrefixData != nullptr);
1066}
1067
1068Constant *Function::getPrologueData() const {
1069 assert(hasPrologueData() && getNumOperands());
1070 return cast<Constant>(Op<2>());
1071}
1072
1073void Function::setPrologueData(Constant *PrologueData) {
1074 setHungoffOperand<2>(PrologueData);
1075 setValueSubclassDataBit(2, PrologueData != nullptr);
1076}
1077
1078void Function::allocHungoffUselist() {
1079 // If we've already allocated a uselist, stop here.
1080 if (getNumOperands())
1081 return;
1082
1083 allocHungoffUses(3, /*IsPhi=*/ false);
1084 setNumHungOffUseOperands(3);
1085
1086 // Initialize the uselist with placeholder operands to allow traversal.
1087 auto *CPN = ConstantPointerNull::get(PointerType::get(getContext(), 0));
1088 Op<0>().set(CPN);
1089 Op<1>().set(CPN);
1090 Op<2>().set(CPN);
1091}
1092
1093template <int Idx>
1094void Function::setHungoffOperand(Constant *C) {
1095 if (C) {
1096 allocHungoffUselist();
1097 Op<Idx>().set(C);
1098 } else if (getNumOperands()) {
1099 Op<Idx>().set(ConstantPointerNull::get(PointerType::get(getContext(), 0)));
1100 }
1101}
1102
1103void Function::setValueSubclassDataBit(unsigned Bit, bool On) {
1104 assert(Bit < 16 && "SubclassData contains only 16 bits");
1105 if (On)
1106 setValueSubclassData(getSubclassDataFromValue() | (1 << Bit));
1107 else
1108 setValueSubclassData(getSubclassDataFromValue() & ~(1 << Bit));
1109}
1110
1111void Function::setEntryCount(ProfileCount Count,
1112 const DenseSet<GlobalValue::GUID> *S) {
1113#if !defined(NDEBUG)
1114 auto PrevCount = getEntryCount();
1115 assert(!PrevCount || PrevCount->getType() == Count.getType());
1116#endif
1117
1118 auto ImportGUIDs = getImportGUIDs();
1119 if (S == nullptr && ImportGUIDs.size())
1120 S = &ImportGUIDs;
1121
1122 MDBuilder MDB(getContext());
1123 setMetadata(
1124 LLVMContext::MD_prof,
1125 MDB.createFunctionEntryCount(Count.getCount(), Count.isSynthetic(), S));
1126}
1127
1128void Function::setEntryCount(uint64_t Count, Function::ProfileCountType Type,
1129 const DenseSet<GlobalValue::GUID> *Imports) {
1130 setEntryCount(ProfileCount(Count, Type), Imports);
1131}
1132
1133std::optional<ProfileCount> Function::getEntryCount(bool AllowSynthetic) const {
1134 MDNode *MD = getMetadata(LLVMContext::MD_prof);
1135 if (MD && MD->getOperand(0))
1136 if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) {
1137 if (MDS->getString() == "function_entry_count") {
1138 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
1139 uint64_t Count = CI->getValue().getZExtValue();
1140 // A value of -1 is used for SamplePGO when there were no samples.
1141 // Treat this the same as unknown.
1142 if (Count == (uint64_t)-1)
1143 return std::nullopt;
1144 return ProfileCount(Count, PCT_Real);
1145 } else if (AllowSynthetic &&
1146 MDS->getString() == "synthetic_function_entry_count") {
1147 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
1148 uint64_t Count = CI->getValue().getZExtValue();
1149 return ProfileCount(Count, PCT_Synthetic);
1150 }
1151 }
1152 return std::nullopt;
1153}
1154
1155DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const {
1157 if (MDNode *MD = getMetadata(LLVMContext::MD_prof))
1158 if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0)))
1159 if (MDS->getString() == "function_entry_count")
1160 for (unsigned i = 2; i < MD->getNumOperands(); i++)
1161 R.insert(mdconst::extract<ConstantInt>(MD->getOperand(i))
1162 ->getValue()
1163 .getZExtValue());
1164 return R;
1165}
1166
1167void Function::setSectionPrefix(StringRef Prefix) {
1168 MDBuilder MDB(getContext());
1169 setMetadata(LLVMContext::MD_section_prefix,
1170 MDB.createFunctionSectionPrefix(Prefix));
1171}
1172
1173std::optional<StringRef> Function::getSectionPrefix() const {
1174 if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) {
1175 assert(cast<MDString>(MD->getOperand(0))->getString() ==
1176 "function_section_prefix" &&
1177 "Metadata not match");
1178 return cast<MDString>(MD->getOperand(1))->getString();
1179 }
1180 return std::nullopt;
1181}
1182
1183bool Function::nullPointerIsDefined() const {
1184 return hasFnAttribute(Attribute::NullPointerIsValid);
1185}
1186
1187bool llvm::NullPointerIsDefined(const Function *F, unsigned AS) {
1188 if (F && F->nullPointerIsDefined())
1189 return true;
1190
1191 if (AS != 0)
1192 return true;
1193
1194 return false;
1195}
static unsigned getIntrinsicID(const SDNode *N)
AMDGPU Lower Kernel Arguments
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
This file contains the simple types necessary to represent the attributes associated with functions a...
static const Function * getParent(const Value *V)
This file implements the BitVector class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DXIL Finalize Linkage
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Given that RA is a live propagate it s liveness to any other values it uses(according to Uses). void DeadArgumentEliminationPass
This file defines the DenseSet and SmallDenseSet classes.
@ Default
Definition: DwarfDebug.cpp:87
std::string Name
Module.h This file contains the declarations for the Module class.
This defines the Use class.
iv users
Definition: IVUsers.cpp:48
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Function::ProfileCount ProfileCount
This file contains the declarations for metadata subclasses.
llvm::cl::opt< bool > UseNewDbgInfoFormat
static StringRef getName(Value *V)
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char * name
Definition: SMEABIPass.cpp:46
This file contains some templates that are useful if you are working with the STL at all.
static Type * getMemoryParamAllocType(AttributeSet ParamAttrs)
For a byval, sret, inalloca, or preallocated parameter, get the in-memory parameter type.
Definition: Function.cpp:195
static cl::opt< int > NonGlobalValueMaxNameSize("non-global-value-max-name-size", cl::Hidden, cl::init(1024), cl::desc("Maximum size for the name of non-global values."))
static MutableArrayRef< Argument > makeArgArray(Argument *Args, size_t Count)
Definition: Function.cpp:553
static unsigned computeAddrSpace(unsigned AddrSpace, Module *M)
Definition: Function.cpp:483
This file defines the SmallString class.
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
Definition: TapiFile.cpp:39
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1520
AbstractCallSite.
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
MemoryEffects getMemoryEffects() const
Returns memory effects of the function.
Type * getInAllocaType() const
Type * getByValType() const
Type * getStructRetType() const
Type * getPreallocatedType() const
Type * getByRefType() const
const ConstantRange & getRange() const
Returns the value of the range attribute.
Definition: Attributes.cpp:496
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:392
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:86
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:208
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:454
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:148
This class represents a range of values.
Definition: ConstantRange.h:47
This is an important base class in LLVM.
Definition: Constant.h:42
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
Class to represent profile counts.
Definition: Function.h:292
uint64_t getCount() const
Definition: Function.h:300
ProfileCountType getType() const
Definition: Function.h:301
BasicBlockListType::iterator iterator
Definition: Function.h:68
iterator end()
Definition: Function.h:855
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Metadata node.
Definition: Metadata.h:1069
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1430
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1436
A single uniqued string.
Definition: Metadata.h:720
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
bool IsNewDbgInfoFormat
Is this Module using intrinsics to record the position of debugging information, or non-intrinsic rec...
Definition: Module.h:217
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Definition: Module.h:614
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:310
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
LLVM Value Representation.
Definition: Value.h:74
user_iterator user_begin()
Definition: Value.h:397
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition: Value.h:434
iterator_range< user_iterator > users()
Definition: Value.h:421
bool user_empty() const
Definition: Value.h:385
void push_back(pointer val)
Definition: ilist.h:250
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
constexpr double e
Definition: MathExtras.h:47
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1739
unsigned getPointerAddressSpace(const Type *T)
Definition: SPIRVUtils.h:256
UWTableKind
Definition: CodeGen.h:120
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
Definition: Function.cpp:1187
bool isPointerTy(const Type *T)
Definition: SPIRVUtils.h:250
DenormalMode parseDenormalFPAttribute(StringRef Str)
Returns the denormal mode to use for inputs and outputs.
#define N
Represent subnormal handling kind for floating point instruction inputs and outputs.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117