LLVM  15.0.0git
Attributes.cpp
Go to the documentation of this file.
1 //===- Attributes.cpp - Implement AttributesList --------------------------===//
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 // \file
10 // This file implements the Attribute, AttributeImpl, AttrBuilder,
11 // AttributeListImpl, and AttributeList classes.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/IR/Attributes.h"
16 #include "AttributeImpl.h"
17 #include "LLVMContextImpl.h"
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/FoldingSet.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/ADT/StringSwitch.h"
26 #include "llvm/Config/llvm-config.h"
27 #include "llvm/IR/Function.h"
28 #include "llvm/IR/LLVMContext.h"
29 #include "llvm/IR/Type.h"
30 #include "llvm/Support/Compiler.h"
33 #include <algorithm>
34 #include <cassert>
35 #include <cstddef>
36 #include <cstdint>
37 #include <limits>
38 #include <string>
39 #include <tuple>
40 #include <utility>
41 
42 using namespace llvm;
43 
44 //===----------------------------------------------------------------------===//
45 // Attribute Construction Methods
46 //===----------------------------------------------------------------------===//
47 
48 // allocsize has two integer arguments, but because they're both 32 bits, we can
49 // pack them into one 64-bit value, at the cost of making said value
50 // nonsensical.
51 //
52 // In order to do this, we need to reserve one value of the second (optional)
53 // allocsize argument to signify "not present."
54 static const unsigned AllocSizeNumElemsNotPresent = -1;
55 
56 static uint64_t packAllocSizeArgs(unsigned ElemSizeArg,
57  const Optional<unsigned> &NumElemsArg) {
58  assert((!NumElemsArg.hasValue() ||
59  *NumElemsArg != AllocSizeNumElemsNotPresent) &&
60  "Attempting to pack a reserved value");
61 
62  return uint64_t(ElemSizeArg) << 32 |
64 }
65 
66 static std::pair<unsigned, Optional<unsigned>>
68  unsigned NumElems = Num & std::numeric_limits<unsigned>::max();
69  unsigned ElemSizeArg = Num >> 32;
70 
71  Optional<unsigned> NumElemsArg;
72  if (NumElems != AllocSizeNumElemsNotPresent)
73  NumElemsArg = NumElems;
74  return std::make_pair(ElemSizeArg, NumElemsArg);
75 }
76 
77 static uint64_t packVScaleRangeArgs(unsigned MinValue,
78  Optional<unsigned> MaxValue) {
79  return uint64_t(MinValue) << 32 | MaxValue.getValueOr(0);
80 }
81 
82 static std::pair<unsigned, Optional<unsigned>>
84  unsigned MaxValue = Value & std::numeric_limits<unsigned>::max();
85  unsigned MinValue = Value >> 32;
86 
87  return std::make_pair(MinValue,
88  MaxValue > 0 ? MaxValue : Optional<unsigned>());
89 }
90 
92  uint64_t Val) {
93  if (Val)
94  assert(Attribute::isIntAttrKind(Kind) && "Not an int attribute");
95  else
96  assert(Attribute::isEnumAttrKind(Kind) && "Not an enum attribute");
97 
98  LLVMContextImpl *pImpl = Context.pImpl;
100  ID.AddInteger(Kind);
101  if (Val) ID.AddInteger(Val);
102 
103  void *InsertPoint;
104  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
105 
106  if (!PA) {
107  // If we didn't find any existing attributes of the same shape then create a
108  // new one and insert it.
109  if (!Val)
110  PA = new (pImpl->Alloc) EnumAttributeImpl(Kind);
111  else
112  PA = new (pImpl->Alloc) IntAttributeImpl(Kind, Val);
113  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
114  }
115 
116  // Return the Attribute that we found or created.
117  return Attribute(PA);
118 }
119 
121  LLVMContextImpl *pImpl = Context.pImpl;
123  ID.AddString(Kind);
124  if (!Val.empty()) ID.AddString(Val);
125 
126  void *InsertPoint;
127  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
128 
129  if (!PA) {
130  // If we didn't find any existing attributes of the same shape then create a
131  // new one and insert it.
132  void *Mem =
134  alignof(StringAttributeImpl));
135  PA = new (Mem) StringAttributeImpl(Kind, Val);
136  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
137  }
138 
139  // Return the Attribute that we found or created.
140  return Attribute(PA);
141 }
142 
144  Type *Ty) {
145  assert(Attribute::isTypeAttrKind(Kind) && "Not a type attribute");
146  LLVMContextImpl *pImpl = Context.pImpl;
148  ID.AddInteger(Kind);
149  ID.AddPointer(Ty);
150 
151  void *InsertPoint;
152  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
153 
154  if (!PA) {
155  // If we didn't find any existing attributes of the same shape then create a
156  // new one and insert it.
157  PA = new (pImpl->Alloc) TypeAttributeImpl(Kind, Ty);
158  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
159  }
160 
161  // Return the Attribute that we found or created.
162  return Attribute(PA);
163 }
164 
166  assert(A <= llvm::Value::MaximumAlignment && "Alignment too large.");
167  return get(Context, Alignment, A.value());
168 }
169 
171  assert(A <= 0x100 && "Alignment too large.");
172  return get(Context, StackAlignment, A.value());
173 }
174 
176  uint64_t Bytes) {
177  assert(Bytes && "Bytes must be non-zero.");
178  return get(Context, Dereferenceable, Bytes);
179 }
180 
182  uint64_t Bytes) {
183  assert(Bytes && "Bytes must be non-zero.");
184  return get(Context, DereferenceableOrNull, Bytes);
185 }
186 
188  return get(Context, ByVal, Ty);
189 }
190 
192  return get(Context, StructRet, Ty);
193 }
194 
196  return get(Context, ByRef, Ty);
197 }
198 
200  return get(Context, Preallocated, Ty);
201 }
202 
204  return get(Context, InAlloca, Ty);
205 }
206 
208  UWTableKind Kind) {
209  return get(Context, UWTable, uint64_t(Kind));
210 }
211 
212 Attribute
214  const Optional<unsigned> &NumElemsArg) {
215  assert(!(ElemSizeArg == 0 && NumElemsArg && *NumElemsArg == 0) &&
216  "Invalid allocsize arguments -- given allocsize(0, 0)");
217  return get(Context, AllocSize, packAllocSizeArgs(ElemSizeArg, NumElemsArg));
218 }
219 
221  unsigned MinValue,
222  unsigned MaxValue) {
223  return get(Context, VScaleRange, packVScaleRangeArgs(MinValue, MaxValue));
224 }
225 
227  return StringSwitch<Attribute::AttrKind>(AttrName)
228 #define GET_ATTR_NAMES
229 #define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
230  .Case(#DISPLAY_NAME, Attribute::ENUM_NAME)
231 #include "llvm/IR/Attributes.inc"
233 }
234 
236  switch (AttrKind) {
237 #define GET_ATTR_NAMES
238 #define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
239  case Attribute::ENUM_NAME: \
240  return #DISPLAY_NAME;
241 #include "llvm/IR/Attributes.inc"
242  case Attribute::None:
243  return "none";
244  default:
245  llvm_unreachable("invalid Kind");
246  }
247 }
248 
250  return StringSwitch<bool>(Name)
251 #define GET_ATTR_NAMES
252 #define ATTRIBUTE_ALL(ENUM_NAME, DISPLAY_NAME) .Case(#DISPLAY_NAME, true)
253 #include "llvm/IR/Attributes.inc"
254  .Default(false);
255 }
256 
257 //===----------------------------------------------------------------------===//
258 // Attribute Accessor Methods
259 //===----------------------------------------------------------------------===//
260 
262  return pImpl && pImpl->isEnumAttribute();
263 }
264 
266  return pImpl && pImpl->isIntAttribute();
267 }
268 
270  return pImpl && pImpl->isStringAttribute();
271 }
272 
274  return pImpl && pImpl->isTypeAttribute();
275 }
276 
278  if (!pImpl) return None;
280  "Invalid attribute type to get the kind as an enum!");
281  return pImpl->getKindAsEnum();
282 }
283 
285  if (!pImpl) return 0;
287  "Expected the attribute to be an integer attribute!");
288  return pImpl->getValueAsInt();
289 }
290 
292  if (!pImpl) return false;
294  "Expected the attribute to be a string attribute!");
295  return pImpl->getValueAsBool();
296 }
297 
299  if (!pImpl) return {};
301  "Invalid attribute type to get the kind as a string!");
302  return pImpl->getKindAsString();
303 }
304 
306  if (!pImpl) return {};
308  "Invalid attribute type to get the value as a string!");
309  return pImpl->getValueAsString();
310 }
311 
313  if (!pImpl) return {};
315  "Invalid attribute type to get the value as a type!");
316  return pImpl->getValueAsType();
317 }
318 
319 
321  return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None);
322 }
323 
325  if (!isStringAttribute()) return false;
326  return pImpl && pImpl->hasAttribute(Kind);
327 }
328 
330  assert(hasAttribute(Attribute::Alignment) &&
331  "Trying to get alignment from non-alignment attribute!");
332  return MaybeAlign(pImpl->getValueAsInt());
333 }
334 
336  assert(hasAttribute(Attribute::StackAlignment) &&
337  "Trying to get alignment from non-alignment attribute!");
338  return MaybeAlign(pImpl->getValueAsInt());
339 }
340 
342  assert(hasAttribute(Attribute::Dereferenceable) &&
343  "Trying to get dereferenceable bytes from "
344  "non-dereferenceable attribute!");
345  return pImpl->getValueAsInt();
346 }
347 
349  assert(hasAttribute(Attribute::DereferenceableOrNull) &&
350  "Trying to get dereferenceable bytes from "
351  "non-dereferenceable attribute!");
352  return pImpl->getValueAsInt();
353 }
354 
355 std::pair<unsigned, Optional<unsigned>> Attribute::getAllocSizeArgs() const {
356  assert(hasAttribute(Attribute::AllocSize) &&
357  "Trying to get allocsize args from non-allocsize attribute");
358  return unpackAllocSizeArgs(pImpl->getValueAsInt());
359 }
360 
362  assert(hasAttribute(Attribute::VScaleRange) &&
363  "Trying to get vscale args from non-vscale attribute");
364  return unpackVScaleRangeArgs(pImpl->getValueAsInt()).first;
365 }
366 
368  assert(hasAttribute(Attribute::VScaleRange) &&
369  "Trying to get vscale args from non-vscale attribute");
370  return unpackVScaleRangeArgs(pImpl->getValueAsInt()).second;
371 }
372 
374  assert(hasAttribute(Attribute::UWTable) &&
375  "Trying to get unwind table kind from non-uwtable attribute");
376  return UWTableKind(pImpl->getValueAsInt());
377 }
378 
379 std::string Attribute::getAsString(bool InAttrGrp) const {
380  if (!pImpl) return {};
381 
382  if (isEnumAttribute())
384 
385  if (isTypeAttribute()) {
386  std::string Result = getNameFromAttrKind(getKindAsEnum()).str();
387  Result += '(';
388  raw_string_ostream OS(Result);
389  getValueAsType()->print(OS, false, true);
390  OS.flush();
391  Result += ')';
392  return Result;
393  }
394 
395  // FIXME: These should be output like this:
396  //
397  // align=4
398  // alignstack=8
399  //
400  if (hasAttribute(Attribute::Alignment))
401  return (InAttrGrp ? "align=" + Twine(getValueAsInt())
402  : "align " + Twine(getValueAsInt()))
403  .str();
404 
405  auto AttrWithBytesToString = [&](const char *Name) {
406  return (InAttrGrp ? Name + ("=" + Twine(getValueAsInt()))
407  : Name + ("(" + Twine(getValueAsInt())) + ")")
408  .str();
409  };
410 
411  if (hasAttribute(Attribute::StackAlignment))
412  return AttrWithBytesToString("alignstack");
413 
414  if (hasAttribute(Attribute::Dereferenceable))
415  return AttrWithBytesToString("dereferenceable");
416 
417  if (hasAttribute(Attribute::DereferenceableOrNull))
418  return AttrWithBytesToString("dereferenceable_or_null");
419 
420  if (hasAttribute(Attribute::AllocSize)) {
421  unsigned ElemSize;
422  Optional<unsigned> NumElems;
423  std::tie(ElemSize, NumElems) = getAllocSizeArgs();
424 
425  return (NumElems
426  ? "allocsize(" + Twine(ElemSize) + "," + Twine(*NumElems) + ")"
427  : "allocsize(" + Twine(ElemSize) + ")")
428  .str();
429  }
430 
431  if (hasAttribute(Attribute::VScaleRange)) {
432  unsigned MinValue = getVScaleRangeMin();
434  return ("vscale_range(" + Twine(MinValue) + "," +
435  Twine(MaxValue.getValueOr(0)) + ")")
436  .str();
437  }
438 
439  if (hasAttribute(Attribute::UWTable)) {
441  if (Kind != UWTableKind::None) {
442  return Kind == UWTableKind::Default
443  ? "uwtable"
444  : ("uwtable(" +
445  Twine(Kind == UWTableKind::Sync ? "sync" : "async") + ")")
446  .str();
447  }
448  }
449 
450  // Convert target-dependent attributes to strings of the form:
451  //
452  // "kind"
453  // "kind" = "value"
454  //
455  if (isStringAttribute()) {
456  std::string Result;
457  {
458  raw_string_ostream OS(Result);
459  OS << '"' << getKindAsString() << '"';
460 
461  // Since some attribute strings contain special characters that cannot be
462  // printable, those have to be escaped to make the attribute value
463  // printable as is. e.g. "\01__gnu_mcount_nc"
464  const auto &AttrVal = pImpl->getValueAsString();
465  if (!AttrVal.empty()) {
466  OS << "=\"";
467  printEscapedString(AttrVal, OS);
468  OS << "\"";
469  }
470  }
471  return Result;
472  }
473 
474  llvm_unreachable("Unknown attribute");
475 }
476 
478  assert(isValid() && "invalid Attribute doesn't refer to any context");
480  pImpl->Profile(ID);
481  void *Unused;
482  return C.pImpl->AttrsSet.FindNodeOrInsertPos(ID, Unused) == pImpl;
483 }
484 
486  if (!pImpl && !A.pImpl) return false;
487  if (!pImpl) return true;
488  if (!A.pImpl) return false;
489  return *pImpl < *A.pImpl;
490 }
491 
493  ID.AddPointer(pImpl);
494 }
495 
497  FnAttr = (1 << 0),
498  ParamAttr = (1 << 1),
499  RetAttr = (1 << 2),
500 };
501 
502 #define GET_ATTR_PROP_TABLE
503 #include "llvm/IR/Attributes.inc"
504 
506  AttributeProperty Prop) {
507  unsigned Index = Kind - 1;
508  assert(Index < sizeof(AttrPropTable) / sizeof(AttrPropTable[0]) &&
509  "Invalid attribute kind");
510  return AttrPropTable[Index] & Prop;
511 }
512 
515 }
516 
519 }
520 
523 }
524 
525 //===----------------------------------------------------------------------===//
526 // AttributeImpl Definition
527 //===----------------------------------------------------------------------===//
528 
530  if (isStringAttribute()) return false;
531  return getKindAsEnum() == A;
532 }
533 
535  if (!isStringAttribute()) return false;
536  return getKindAsString() == Kind;
537 }
538 
541  return static_cast<const EnumAttributeImpl *>(this)->getEnumKind();
542 }
543 
546  return static_cast<const IntAttributeImpl *>(this)->getValue();
547 }
548 
550  assert(getValueAsString().empty() || getValueAsString() == "false" || getValueAsString() == "true");
551  return getValueAsString() == "true";
552 }
553 
556  return static_cast<const StringAttributeImpl *>(this)->getStringKind();
557 }
558 
561  return static_cast<const StringAttributeImpl *>(this)->getStringValue();
562 }
563 
566  return static_cast<const TypeAttributeImpl *>(this)->getTypeValue();
567 }
568 
570  if (this == &AI)
571  return false;
572 
573  // This sorts the attributes with Attribute::AttrKinds coming first (sorted
574  // relative to their enum value) and then strings.
575  if (!isStringAttribute()) {
576  if (AI.isStringAttribute())
577  return true;
578  if (getKindAsEnum() != AI.getKindAsEnum())
579  return getKindAsEnum() < AI.getKindAsEnum();
580  assert(!AI.isEnumAttribute() && "Non-unique attribute");
581  assert(!AI.isTypeAttribute() && "Comparison of types would be unstable");
582  // TODO: Is this actually needed?
583  assert(AI.isIntAttribute() && "Only possibility left");
584  return getValueAsInt() < AI.getValueAsInt();
585  }
586 
587  if (!AI.isStringAttribute())
588  return false;
589  if (getKindAsString() == AI.getKindAsString())
590  return getValueAsString() < AI.getValueAsString();
591  return getKindAsString() < AI.getKindAsString();
592 }
593 
594 //===----------------------------------------------------------------------===//
595 // AttributeSet Definition
596 //===----------------------------------------------------------------------===//
597 
600 }
601 
604 }
605 
607  Attribute::AttrKind Kind) const {
608  if (hasAttribute(Kind)) return *this;
609  AttrBuilder B(C);
610  B.addAttribute(Kind);
611  return addAttributes(C, AttributeSet::get(C, B));
612 }
613 
615  StringRef Value) const {
616  AttrBuilder B(C);
617  B.addAttribute(Kind, Value);
618  return addAttributes(C, AttributeSet::get(C, B));
619 }
620 
622  const AttributeSet AS) const {
623  if (!hasAttributes())
624  return AS;
625 
626  if (!AS.hasAttributes())
627  return *this;
628 
629  AttrBuilder B(C, *this);
630  B.merge(AttrBuilder(C, AS));
631  return get(C, B);
632 }
633 
635  Attribute::AttrKind Kind) const {
636  if (!hasAttribute(Kind)) return *this;
637  AttrBuilder B(C, *this);
638  B.removeAttribute(Kind);
639  return get(C, B);
640 }
641 
643  StringRef Kind) const {
644  if (!hasAttribute(Kind)) return *this;
645  AttrBuilder B(C, *this);
646  B.removeAttribute(Kind);
647  return get(C, B);
648 }
649 
651  const AttributeMask &Attrs) const {
652  AttrBuilder B(C, *this);
653  // If there is nothing to remove, directly return the original set.
654  if (!B.overlaps(Attrs))
655  return *this;
656 
657  B.remove(Attrs);
658  return get(C, B);
659 }
660 
662  return SetNode ? SetNode->getNumAttributes() : 0;
663 }
664 
666  return SetNode ? SetNode->hasAttribute(Kind) : false;
667 }
668 
670  return SetNode ? SetNode->hasAttribute(Kind) : false;
671 }
672 
674  return SetNode ? SetNode->getAttribute(Kind) : Attribute();
675 }
676 
678  return SetNode ? SetNode->getAttribute(Kind) : Attribute();
679 }
680 
682  return SetNode ? SetNode->getAlignment() : None;
683 }
684 
686  return SetNode ? SetNode->getStackAlignment() : None;
687 }
688 
690  return SetNode ? SetNode->getDereferenceableBytes() : 0;
691 }
692 
694  return SetNode ? SetNode->getDereferenceableOrNullBytes() : 0;
695 }
696 
698  return SetNode ? SetNode->getAttributeType(Attribute::ByRef) : nullptr;
699 }
700 
702  return SetNode ? SetNode->getAttributeType(Attribute::ByVal) : nullptr;
703 }
704 
706  return SetNode ? SetNode->getAttributeType(Attribute::StructRet) : nullptr;
707 }
708 
710  return SetNode ? SetNode->getAttributeType(Attribute::Preallocated) : nullptr;
711 }
712 
714  return SetNode ? SetNode->getAttributeType(Attribute::InAlloca) : nullptr;
715 }
716 
718  return SetNode ? SetNode->getAttributeType(Attribute::ElementType) : nullptr;
719 }
720 
721 std::pair<unsigned, Optional<unsigned>> AttributeSet::getAllocSizeArgs() const {
722  return SetNode ? SetNode->getAllocSizeArgs()
723  : std::pair<unsigned, Optional<unsigned>>(0, 0);
724 }
725 
727  return SetNode ? SetNode->getVScaleRangeMin() : 1;
728 }
729 
731  return SetNode ? SetNode->getVScaleRangeMax() : None;
732 }
733 
735  return SetNode ? SetNode->getUWTableKind() : UWTableKind::None;
736 }
737 
738 std::string AttributeSet::getAsString(bool InAttrGrp) const {
739  return SetNode ? SetNode->getAsString(InAttrGrp) : "";
740 }
741 
743  assert(hasAttributes() && "empty AttributeSet doesn't refer to any context");
745  SetNode->Profile(ID);
746  void *Unused;
747  return C.pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, Unused) == SetNode;
748 }
749 
751  return SetNode ? SetNode->begin() : nullptr;
752 }
753 
755  return SetNode ? SetNode->end() : nullptr;
756 }
757 
758 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
760  dbgs() << "AS =\n";
761  dbgs() << " { ";
762  dbgs() << getAsString(true) << " }\n";
763 }
764 #endif
765 
766 //===----------------------------------------------------------------------===//
767 // AttributeSetNode Definition
768 //===----------------------------------------------------------------------===//
769 
770 AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
771  : NumAttrs(Attrs.size()) {
772  // There's memory after the node where we can store the entries in.
773  llvm::copy(Attrs, getTrailingObjects<Attribute>());
774 
775  for (const auto &I : *this) {
776  if (I.isStringAttribute())
777  StringAttrs.insert({ I.getKindAsString(), I });
778  else
779  AvailableAttrs.addAttribute(I.getKindAsEnum());
780  }
781 }
782 
785  SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
786  llvm::sort(SortedAttrs);
787  return getSorted(C, SortedAttrs);
788 }
789 
790 AttributeSetNode *AttributeSetNode::getSorted(LLVMContext &C,
791  ArrayRef<Attribute> SortedAttrs) {
792  if (SortedAttrs.empty())
793  return nullptr;
794 
795  // Build a key to look up the existing attributes.
796  LLVMContextImpl *pImpl = C.pImpl;
798 
799  assert(llvm::is_sorted(SortedAttrs) && "Expected sorted attributes!");
800  for (const auto &Attr : SortedAttrs)
801  Attr.Profile(ID);
802 
803  void *InsertPoint;
804  AttributeSetNode *PA =
805  pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint);
806 
807  // If we didn't find any existing attributes of the same shape then create a
808  // new one and insert it.
809  if (!PA) {
810  // Coallocate entries after the AttributeSetNode itself.
811  void *Mem = ::operator new(totalSizeToAlloc<Attribute>(SortedAttrs.size()));
812  PA = new (Mem) AttributeSetNode(SortedAttrs);
813  pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint);
814  }
815 
816  // Return the AttributeSetNode that we found or created.
817  return PA;
818 }
819 
821  return getSorted(C, B.attrs());
822 }
823 
825  return StringAttrs.count(Kind);
826 }
827 
829 AttributeSetNode::findEnumAttribute(Attribute::AttrKind Kind) const {
830  // Do a quick presence check.
831  if (!hasAttribute(Kind))
832  return None;
833 
834  // Attributes in a set are sorted by enum value, followed by string
835  // attributes. Binary search the one we want.
836  const Attribute *I =
837  std::lower_bound(begin(), end() - StringAttrs.size(), Kind,
839  return A.getKindAsEnum() < Kind;
840  });
841  assert(I != end() && I->hasAttribute(Kind) && "Presence check failed?");
842  return *I;
843 }
844 
846  if (auto A = findEnumAttribute(Kind))
847  return *A;
848  return {};
849 }
850 
852  return StringAttrs.lookup(Kind);
853 }
854 
856  if (auto A = findEnumAttribute(Attribute::Alignment))
857  return A->getAlignment();
858  return None;
859 }
860 
862  if (auto A = findEnumAttribute(Attribute::StackAlignment))
863  return A->getStackAlignment();
864  return None;
865 }
866 
868  if (auto A = findEnumAttribute(Kind))
869  return A->getValueAsType();
870  return nullptr;
871 }
872 
874  if (auto A = findEnumAttribute(Attribute::Dereferenceable))
875  return A->getDereferenceableBytes();
876  return 0;
877 }
878 
880  if (auto A = findEnumAttribute(Attribute::DereferenceableOrNull))
881  return A->getDereferenceableOrNullBytes();
882  return 0;
883 }
884 
885 std::pair<unsigned, Optional<unsigned>>
887  if (auto A = findEnumAttribute(Attribute::AllocSize))
888  return A->getAllocSizeArgs();
889  return std::make_pair(0, 0);
890 }
891 
893  if (auto A = findEnumAttribute(Attribute::VScaleRange))
894  return A->getVScaleRangeMin();
895  return 1;
896 }
897 
899  if (auto A = findEnumAttribute(Attribute::VScaleRange))
900  return A->getVScaleRangeMax();
901  return None;
902 }
903 
905  if (auto A = findEnumAttribute(Attribute::UWTable))
906  return A->getUWTableKind();
907  return UWTableKind::None;
908 }
909 
910 std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
911  std::string Str;
912  for (iterator I = begin(), E = end(); I != E; ++I) {
913  if (I != begin())
914  Str += ' ';
915  Str += I->getAsString(InAttrGrp);
916  }
917  return Str;
918 }
919 
920 //===----------------------------------------------------------------------===//
921 // AttributeListImpl Definition
922 //===----------------------------------------------------------------------===//
923 
924 /// Map from AttributeList index to the internal array index. Adding one happens
925 /// to work, because -1 wraps around to 0.
926 static unsigned attrIdxToArrayIdx(unsigned Index) {
927  return Index + 1;
928 }
929 
931  : NumAttrSets(Sets.size()) {
932  assert(!Sets.empty() && "pointless AttributeListImpl");
933 
934  // There's memory after the node where we can store the entries in.
935  llvm::copy(Sets, getTrailingObjects<AttributeSet>());
936 
937  // Initialize AvailableFunctionAttrs and AvailableSomewhereAttrs
938  // summary bitsets.
939  for (const auto &I : Sets[attrIdxToArrayIdx(AttributeList::FunctionIndex)])
940  if (!I.isStringAttribute())
941  AvailableFunctionAttrs.addAttribute(I.getKindAsEnum());
942 
943  for (const auto &Set : Sets)
944  for (const auto &I : Set)
945  if (!I.isStringAttribute())
946  AvailableSomewhereAttrs.addAttribute(I.getKindAsEnum());
947 }
948 
950  Profile(ID, makeArrayRef(begin(), end()));
951 }
952 
954  ArrayRef<AttributeSet> Sets) {
955  for (const auto &Set : Sets)
956  ID.AddPointer(Set.SetNode);
957 }
958 
960  unsigned *Index) const {
961  if (!AvailableSomewhereAttrs.hasAttribute(Kind))
962  return false;
963 
964  if (Index) {
965  for (unsigned I = 0, E = NumAttrSets; I != E; ++I) {
966  if (begin()[I].hasAttribute(Kind)) {
967  *Index = I - 1;
968  break;
969  }
970  }
971  }
972 
973  return true;
974 }
975 
976 
977 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
979  AttributeList(const_cast<AttributeListImpl *>(this)).dump();
980 }
981 #endif
982 
983 //===----------------------------------------------------------------------===//
984 // AttributeList Construction and Mutation Methods
985 //===----------------------------------------------------------------------===//
986 
988  ArrayRef<AttributeSet> AttrSets) {
989  assert(!AttrSets.empty() && "pointless AttributeListImpl");
990 
991  LLVMContextImpl *pImpl = C.pImpl;
993  AttributeListImpl::Profile(ID, AttrSets);
994 
995  void *InsertPoint;
996  AttributeListImpl *PA =
997  pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint);
998 
999  // If we didn't find any existing attributes of the same shape then
1000  // create a new one and insert it.
1001  if (!PA) {
1002  // Coallocate entries after the AttributeListImpl itself.
1003  void *Mem = pImpl->Alloc.Allocate(
1004  AttributeListImpl::totalSizeToAlloc<AttributeSet>(AttrSets.size()),
1005  alignof(AttributeListImpl));
1006  PA = new (Mem) AttributeListImpl(AttrSets);
1007  pImpl->AttrsLists.InsertNode(PA, InsertPoint);
1008  }
1009 
1010  // Return the AttributesList that we found or created.
1011  return AttributeList(PA);
1012 }
1013 
1016  ArrayRef<std::pair<unsigned, Attribute>> Attrs) {
1017  // If there are no attributes then return a null AttributesList pointer.
1018  if (Attrs.empty())
1019  return {};
1020 
1022  [](const std::pair<unsigned, Attribute> &LHS,
1023  const std::pair<unsigned, Attribute> &RHS) {
1024  return LHS.first < RHS.first;
1025  }) &&
1026  "Misordered Attributes list!");
1028  [](const std::pair<unsigned, Attribute> &Pair) {
1029  return Pair.second.isValid();
1030  }) &&
1031  "Pointless attribute!");
1032 
1033  // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes
1034  // list.
1036  for (ArrayRef<std::pair<unsigned, Attribute>>::iterator I = Attrs.begin(),
1037  E = Attrs.end(); I != E; ) {
1038  unsigned Index = I->first;
1039  SmallVector<Attribute, 4> AttrVec;
1040  while (I != E && I->first == Index) {
1041  AttrVec.push_back(I->second);
1042  ++I;
1043  }
1044 
1045  AttrPairVec.emplace_back(Index, AttributeSet::get(C, AttrVec));
1046  }
1047 
1048  return get(C, AttrPairVec);
1049 }
1050 
1053  ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) {
1054  // If there are no attributes then return a null AttributesList pointer.
1055  if (Attrs.empty())
1056  return {};
1057 
1059  [](const std::pair<unsigned, AttributeSet> &LHS,
1060  const std::pair<unsigned, AttributeSet> &RHS) {
1061  return LHS.first < RHS.first;
1062  }) &&
1063  "Misordered Attributes list!");
1065  [](const std::pair<unsigned, AttributeSet> &Pair) {
1066  return !Pair.second.hasAttributes();
1067  }) &&
1068  "Pointless attribute!");
1069 
1070  unsigned MaxIndex = Attrs.back().first;
1071  // If the MaxIndex is FunctionIndex and there are other indices in front
1072  // of it, we need to use the largest of those to get the right size.
1073  if (MaxIndex == FunctionIndex && Attrs.size() > 1)
1074  MaxIndex = Attrs[Attrs.size() - 2].first;
1075 
1076  SmallVector<AttributeSet, 4> AttrVec(attrIdxToArrayIdx(MaxIndex) + 1);
1077  for (const auto &Pair : Attrs)
1078  AttrVec[attrIdxToArrayIdx(Pair.first)] = Pair.second;
1079 
1080  return getImpl(C, AttrVec);
1081 }
1082 
1084  AttributeSet RetAttrs,
1085  ArrayRef<AttributeSet> ArgAttrs) {
1086  // Scan from the end to find the last argument with attributes. Most
1087  // arguments don't have attributes, so it's nice if we can have fewer unique
1088  // AttributeListImpls by dropping empty attribute sets at the end of the list.
1089  unsigned NumSets = 0;
1090  for (size_t I = ArgAttrs.size(); I != 0; --I) {
1091  if (ArgAttrs[I - 1].hasAttributes()) {
1092  NumSets = I + 2;
1093  break;
1094  }
1095  }
1096  if (NumSets == 0) {
1097  // Check function and return attributes if we didn't have argument
1098  // attributes.
1099  if (RetAttrs.hasAttributes())
1100  NumSets = 2;
1101  else if (FnAttrs.hasAttributes())
1102  NumSets = 1;
1103  }
1104 
1105  // If all attribute sets were empty, we can use the empty attribute list.
1106  if (NumSets == 0)
1107  return {};
1108 
1110  AttrSets.reserve(NumSets);
1111  // If we have any attributes, we always have function attributes.
1112  AttrSets.push_back(FnAttrs);
1113  if (NumSets > 1)
1114  AttrSets.push_back(RetAttrs);
1115  if (NumSets > 2) {
1116  // Drop the empty argument attribute sets at the end.
1117  ArgAttrs = ArgAttrs.take_front(NumSets - 2);
1118  llvm::append_range(AttrSets, ArgAttrs);
1119  }
1120 
1121  return getImpl(C, AttrSets);
1122 }
1123 
1125  AttributeSet Attrs) {
1126  if (!Attrs.hasAttributes())
1127  return {};
1129  SmallVector<AttributeSet, 8> AttrSets(Index + 1);
1130  AttrSets[Index] = Attrs;
1131  return getImpl(C, AttrSets);
1132 }
1133 
1135  const AttrBuilder &B) {
1136  return get(C, Index, AttributeSet::get(C, B));
1137 }
1138 
1142  for (const auto K : Kinds)
1143  Attrs.emplace_back(Index, Attribute::get(C, K));
1144  return get(C, Attrs);
1145 }
1146 
1149  ArrayRef<uint64_t> Values) {
1150  assert(Kinds.size() == Values.size() && "Mismatched attribute values.");
1152  auto VI = Values.begin();
1153  for (const auto K : Kinds)
1154  Attrs.emplace_back(Index, Attribute::get(C, K, *VI++));
1155  return get(C, Attrs);
1156 }
1157 
1159  ArrayRef<StringRef> Kinds) {
1161  for (const auto &K : Kinds)
1162  Attrs.emplace_back(Index, Attribute::get(C, K));
1163  return get(C, Attrs);
1164 }
1165 
1168  if (Attrs.empty())
1169  return {};
1170  if (Attrs.size() == 1)
1171  return Attrs[0];
1172 
1173  unsigned MaxSize = 0;
1174  for (const auto &List : Attrs)
1175  MaxSize = std::max(MaxSize, List.getNumAttrSets());
1176 
1177  // If every list was empty, there is no point in merging the lists.
1178  if (MaxSize == 0)
1179  return {};
1180 
1181  SmallVector<AttributeSet, 8> NewAttrSets(MaxSize);
1182  for (unsigned I = 0; I < MaxSize; ++I) {
1183  AttrBuilder CurBuilder(C);
1184  for (const auto &List : Attrs)
1185  CurBuilder.merge(AttrBuilder(C, List.getAttributes(I - 1)));
1186  NewAttrSets[I] = AttributeSet::get(C, CurBuilder);
1187  }
1188 
1189  return getImpl(C, NewAttrSets);
1190 }
1191 
1194  Attribute::AttrKind Kind) const {
1196  return *this;
1198  // TODO: Insert at correct position and avoid sort.
1200  NewAttrs.push_back(Attribute::get(C, Kind));
1201  return setAttributesAtIndex(C, Index, AttributeSet::get(C, NewAttrs));
1202 }
1203 
1205  StringRef Kind,
1206  StringRef Value) const {
1207  AttrBuilder B(C);
1208  B.addAttribute(Kind, Value);
1209  return addAttributesAtIndex(C, Index, B);
1210 }
1211 
1213  Attribute A) const {
1214  AttrBuilder B(C);
1215  B.addAttribute(A);
1216  return addAttributesAtIndex(C, Index, B);
1217 }
1218 
1219 AttributeList AttributeList::setAttributesAtIndex(LLVMContext &C,
1220  unsigned Index,
1221  AttributeSet Attrs) const {
1223  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1224  if (Index >= AttrSets.size())
1225  AttrSets.resize(Index + 1);
1226  AttrSets[Index] = Attrs;
1227  return AttributeList::getImpl(C, AttrSets);
1228 }
1229 
1231  unsigned Index,
1232  const AttrBuilder &B) const {
1233  if (!B.hasAttributes())
1234  return *this;
1235 
1236  if (!pImpl)
1237  return AttributeList::get(C, {{Index, AttributeSet::get(C, B)}});
1238 
1239  AttrBuilder Merged(C, getAttributes(Index));
1240  Merged.merge(B);
1241  return setAttributesAtIndex(C, Index, AttributeSet::get(C, Merged));
1242 }
1243 
1245  ArrayRef<unsigned> ArgNos,
1246  Attribute A) const {
1247  assert(llvm::is_sorted(ArgNos));
1248 
1249  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1250  unsigned MaxIndex = attrIdxToArrayIdx(ArgNos.back() + FirstArgIndex);
1251  if (MaxIndex >= AttrSets.size())
1252  AttrSets.resize(MaxIndex + 1);
1253 
1254  for (unsigned ArgNo : ArgNos) {
1255  unsigned Index = attrIdxToArrayIdx(ArgNo + FirstArgIndex);
1256  AttrBuilder B(C, AttrSets[Index]);
1257  B.addAttribute(A);
1258  AttrSets[Index] = AttributeSet::get(C, B);
1259  }
1260 
1261  return getImpl(C, AttrSets);
1262 }
1263 
1266  Attribute::AttrKind Kind) const {
1268  return *this;
1269 
1271  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1272  assert(Index < AttrSets.size());
1273 
1274  AttrSets[Index] = AttrSets[Index].removeAttribute(C, Kind);
1275 
1276  return getImpl(C, AttrSets);
1277 }
1278 
1280  unsigned Index,
1281  StringRef Kind) const {
1283  return *this;
1284 
1286  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1287  assert(Index < AttrSets.size());
1288 
1289  AttrSets[Index] = AttrSets[Index].removeAttribute(C, Kind);
1290 
1291  return getImpl(C, AttrSets);
1292 }
1293 
1295  LLVMContext &C, unsigned Index, const AttributeMask &AttrsToRemove) const {
1297  AttributeSet NewAttrs = Attrs.removeAttributes(C, AttrsToRemove);
1298  // If nothing was removed, return the original list.
1299  if (Attrs == NewAttrs)
1300  return *this;
1301  return setAttributesAtIndex(C, Index, NewAttrs);
1302 }
1303 
1306  unsigned WithoutIndex) const {
1307  if (!pImpl)
1308  return {};
1309  WithoutIndex = attrIdxToArrayIdx(WithoutIndex);
1310  if (WithoutIndex >= getNumAttrSets())
1311  return *this;
1312  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1313  AttrSets[WithoutIndex] = AttributeSet();
1314  return getImpl(C, AttrSets);
1315 }
1316 
1318  uint64_t Bytes) const {
1319  AttrBuilder B(C);
1320  B.addDereferenceableAttr(Bytes);
1321  return addRetAttributes(C, B);
1322 }
1323 
1325  unsigned Index,
1326  uint64_t Bytes) const {
1327  AttrBuilder B(C);
1328  B.addDereferenceableAttr(Bytes);
1329  return addParamAttributes(C, Index, B);
1330 }
1331 
1334  uint64_t Bytes) const {
1335  AttrBuilder B(C);
1336  B.addDereferenceableOrNullAttr(Bytes);
1337  return addParamAttributes(C, Index, B);
1338 }
1339 
1342  unsigned ElemSizeArg,
1343  const Optional<unsigned> &NumElemsArg) {
1344  AttrBuilder B(C);
1345  B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1346  return addParamAttributes(C, Index, B);
1347 }
1348 
1349 //===----------------------------------------------------------------------===//
1350 // AttributeList Accessor Methods
1351 //===----------------------------------------------------------------------===//
1352 
1354  return getAttributes(ArgNo + FirstArgIndex);
1355 }
1356 
1358  return getAttributes(ReturnIndex);
1359 }
1360 
1362  return getAttributes(FunctionIndex);
1363 }
1364 
1366  Attribute::AttrKind Kind) const {
1368 }
1369 
1372 }
1373 
1375  return getAttributes(Index).hasAttributes();
1376 }
1377 
1379  return pImpl && pImpl->hasFnAttribute(Kind);
1380 }
1381 
1384 }
1385 
1387  unsigned *Index) const {
1388  return pImpl && pImpl->hasAttrSomewhere(Attr, Index);
1389 }
1390 
1392  Attribute::AttrKind Kind) const {
1394 }
1395 
1397  StringRef Kind) const {
1399 }
1400 
1403 }
1404 
1406  return getAttributes(ArgNo + FirstArgIndex).getAlignment();
1407 }
1408 
1410  return getAttributes(ArgNo + FirstArgIndex).getStackAlignment();
1411 }
1412 
1415 }
1416 
1419 }
1420 
1423 }
1424 
1427 }
1428 
1431 }
1432 
1435 }
1436 
1438  return getFnAttrs().getStackAlignment();
1439 }
1440 
1442  return getRetAttrs().getStackAlignment();
1443 }
1444 
1447 }
1448 
1451 }
1452 
1455 }
1456 
1457 uint64_t
1460 }
1461 
1463  return getFnAttrs().getUWTableKind();
1464 }
1465 
1466 std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const {
1467  return getAttributes(Index).getAsString(InAttrGrp);
1468 }
1469 
1472  if (!pImpl || Index >= getNumAttrSets())
1473  return {};
1474  return pImpl->begin()[Index];
1475 }
1476 
1478  assert(!isEmpty() && "an empty attribute list has no parent context");
1480  pImpl->Profile(ID);
1481  void *Unused;
1482  return C.pImpl->AttrsLists.FindNodeOrInsertPos(ID, Unused) == pImpl;
1483 }
1484 
1486  return pImpl ? pImpl->begin() : nullptr;
1487 }
1488 
1490  return pImpl ? pImpl->end() : nullptr;
1491 }
1492 
1493 //===----------------------------------------------------------------------===//
1494 // AttributeList Introspection Methods
1495 //===----------------------------------------------------------------------===//
1496 
1498  return pImpl ? pImpl->NumAttrSets : 0;
1499 }
1500 
1502  O << "AttributeList[\n";
1503 
1504  for (unsigned i : indexes()) {
1505  if (!getAttributes(i).hasAttributes())
1506  continue;
1507  O << " { ";
1508  switch (i) {
1509  case AttrIndex::ReturnIndex:
1510  O << "return";
1511  break;
1512  case AttrIndex::FunctionIndex:
1513  O << "function";
1514  break;
1515  default:
1516  O << "arg(" << i - AttrIndex::FirstArgIndex << ")";
1517  }
1518  O << " => " << getAsString(i) << " }\n";
1519  }
1520 
1521  O << "]\n";
1522 }
1523 
1524 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1526 #endif
1527 
1528 //===----------------------------------------------------------------------===//
1529 // AttrBuilder Method Implementations
1530 //===----------------------------------------------------------------------===//
1531 
1533  append_range(Attrs, AS);
1534  assert(is_sorted(Attrs) && "AttributeSet should be sorted");
1535 }
1536 
1537 void AttrBuilder::clear() { Attrs.clear(); }
1538 
1539 /// Attribute comparator that only compares attribute keys. Enum attributes are
1540 /// sorted before string attributes.
1542  bool operator()(Attribute A0, Attribute A1) const {
1543  bool A0IsString = A0.isStringAttribute();
1544  bool A1IsString = A1.isStringAttribute();
1545  if (A0IsString) {
1546  if (A1IsString)
1547  return A0.getKindAsString() < A1.getKindAsString();
1548  else
1549  return false;
1550  }
1551  if (A1IsString)
1552  return true;
1553  return A0.getKindAsEnum() < A1.getKindAsEnum();
1554  }
1556  if (A0.isStringAttribute())
1557  return false;
1558  return A0.getKindAsEnum() < Kind;
1559  }
1561  if (A0.isStringAttribute())
1562  return A0.getKindAsString() < Kind;
1563  return true;
1564  }
1565 };
1566 
1567 template <typename K>
1569  Attribute Attr) {
1570  auto It = lower_bound(Attrs, Kind, AttributeComparator());
1571  if (It != Attrs.end() && It->hasAttribute(Kind))
1572  std::swap(*It, Attr);
1573  else
1574  Attrs.insert(It, Attr);
1575 }
1576 
1578  if (Attr.isStringAttribute())
1579  addAttributeImpl(Attrs, Attr.getKindAsString(), Attr);
1580  else
1581  addAttributeImpl(Attrs, Attr.getKindAsEnum(), Attr);
1582  return *this;
1583 }
1584 
1586  addAttributeImpl(Attrs, Kind, Attribute::get(Ctx, Kind));
1587  return *this;
1588 }
1589 
1591  addAttributeImpl(Attrs, A, Attribute::get(Ctx, A, V));
1592  return *this;
1593 }
1594 
1596  assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1597  auto It = lower_bound(Attrs, Val, AttributeComparator());
1598  if (It != Attrs.end() && It->hasAttribute(Val))
1599  Attrs.erase(It);
1600  return *this;
1601 }
1602 
1604  auto It = lower_bound(Attrs, A, AttributeComparator());
1605  if (It != Attrs.end() && It->hasAttribute(A))
1606  Attrs.erase(It);
1607  return *this;
1608 }
1609 
1611  assert(Attribute::isIntAttrKind(Kind) && "Not an int attribute");
1613  return A.isValid() ? A.getValueAsInt() : 0;
1614 }
1615 
1617  uint64_t Value) {
1618  return addAttribute(Attribute::get(Ctx, Kind, Value));
1619 }
1620 
1621 std::pair<unsigned, Optional<unsigned>> AttrBuilder::getAllocSizeArgs() const {
1622  return unpackAllocSizeArgs(getRawIntAttr(Attribute::AllocSize));
1623 }
1624 
1626  return unpackVScaleRangeArgs(getRawIntAttr(Attribute::VScaleRange)).first;
1627 }
1628 
1630  return unpackVScaleRangeArgs(getRawIntAttr(Attribute::VScaleRange)).second;
1631 }
1632 
1634  if (!Align)
1635  return *this;
1636 
1637  assert(*Align <= llvm::Value::MaximumAlignment && "Alignment too large.");
1638  return addRawIntAttr(Attribute::Alignment, Align->value());
1639 }
1640 
1642  // Default alignment, allow the target to define how to align it.
1643  if (!Align)
1644  return *this;
1645 
1646  assert(*Align <= 0x100 && "Alignment too large.");
1647  return addRawIntAttr(Attribute::StackAlignment, Align->value());
1648 }
1649 
1651  if (Bytes == 0) return *this;
1652 
1653  return addRawIntAttr(Attribute::Dereferenceable, Bytes);
1654 }
1655 
1657  if (Bytes == 0)
1658  return *this;
1659 
1660  return addRawIntAttr(Attribute::DereferenceableOrNull, Bytes);
1661 }
1662 
1664  const Optional<unsigned> &NumElems) {
1665  return addAllocSizeAttrFromRawRepr(packAllocSizeArgs(ElemSize, NumElems));
1666 }
1667 
1669  // (0, 0) is our "not present" value, so we need to check for it here.
1670  assert(RawArgs && "Invalid allocsize arguments -- given allocsize(0, 0)");
1671  return addRawIntAttr(Attribute::AllocSize, RawArgs);
1672 }
1673 
1675  Optional<unsigned> MaxValue) {
1676  return addVScaleRangeAttrFromRawRepr(packVScaleRangeArgs(MinValue, MaxValue));
1677 }
1678 
1680  // (0, 0) is not present hence ignore this case
1681  if (RawArgs == 0)
1682  return *this;
1683 
1684  return addRawIntAttr(Attribute::VScaleRange, RawArgs);
1685 }
1686 
1688  if (Kind == UWTableKind::None)
1689  return *this;
1690  return addRawIntAttr(Attribute::UWTable, uint64_t(Kind));
1691 }
1692 
1694  assert(Attribute::isTypeAttrKind(Kind) && "Not a type attribute");
1696  return A.isValid() ? A.getValueAsType() : nullptr;
1697 }
1698 
1700  return addAttribute(Attribute::get(Ctx, Kind, Ty));
1701 }
1702 
1704  return addTypeAttr(Attribute::ByVal, Ty);
1705 }
1706 
1708  return addTypeAttr(Attribute::StructRet, Ty);
1709 }
1710 
1712  return addTypeAttr(Attribute::ByRef, Ty);
1713 }
1714 
1716  return addTypeAttr(Attribute::Preallocated, Ty);
1717 }
1718 
1720  return addTypeAttr(Attribute::InAlloca, Ty);
1721 }
1722 
1724  // TODO: Could make this O(n) as we're merging two sorted lists.
1725  for (const auto &I : B.attrs())
1726  addAttribute(I);
1727 
1728  return *this;
1729 }
1730 
1732  erase_if(Attrs, [&](Attribute A) { return AM.contains(A); });
1733  return *this;
1734 }
1735 
1736 bool AttrBuilder::overlaps(const AttributeMask &AM) const {
1737  return any_of(Attrs, [&](Attribute A) { return AM.contains(A); });
1738 }
1739 
1741  assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!");
1742  auto It = lower_bound(Attrs, A, AttributeComparator());
1743  if (It != Attrs.end() && It->hasAttribute(A))
1744  return *It;
1745  return {};
1746 }
1747 
1749  auto It = lower_bound(Attrs, A, AttributeComparator());
1750  if (It != Attrs.end() && It->hasAttribute(A))
1751  return *It;
1752  return {};
1753 }
1754 
1756  return getAttribute(A).isValid();
1757 }
1758 
1760  return getAttribute(A).isValid();
1761 }
1762 
1764  return getRawIntAttr(Attribute::Alignment) != 0;
1765 }
1766 
1768  return Attrs == B.Attrs;
1769 }
1770 
1771 //===----------------------------------------------------------------------===//
1772 // AttributeFuncs Function Defintions
1773 //===----------------------------------------------------------------------===//
1774 
1775 /// Which attributes cannot be applied to a type.
1777  AttributeSafetyKind ASK) {
1778  AttributeMask Incompatible;
1779 
1780  if (!Ty->isIntegerTy()) {
1781  // Attributes that only apply to integers.
1782  if (ASK & ASK_SAFE_TO_DROP)
1783  Incompatible.addAttribute(Attribute::AllocAlign);
1784  if (ASK & ASK_UNSAFE_TO_DROP)
1785  Incompatible.addAttribute(Attribute::SExt).addAttribute(Attribute::ZExt);
1786  }
1787 
1788  if (!Ty->isPointerTy()) {
1789  // Attributes that only apply to pointers.
1790  if (ASK & ASK_SAFE_TO_DROP)
1791  Incompatible.addAttribute(Attribute::NoAlias)
1792  .addAttribute(Attribute::NoCapture)
1793  .addAttribute(Attribute::NonNull)
1794  .addAttribute(Attribute::ReadNone)
1795  .addAttribute(Attribute::ReadOnly)
1796  .addAttribute(Attribute::Dereferenceable)
1797  .addAttribute(Attribute::DereferenceableOrNull);
1798  if (ASK & ASK_UNSAFE_TO_DROP)
1799  Incompatible.addAttribute(Attribute::Nest)
1800  .addAttribute(Attribute::SwiftError)
1801  .addAttribute(Attribute::Preallocated)
1802  .addAttribute(Attribute::InAlloca)
1803  .addAttribute(Attribute::ByVal)
1804  .addAttribute(Attribute::StructRet)
1805  .addAttribute(Attribute::ByRef)
1806  .addAttribute(Attribute::ElementType)
1807  .addAttribute(Attribute::AllocatedPointer);
1808  }
1809 
1810  // Attributes that only apply to pointers or vectors of pointers.
1811  if (!Ty->isPtrOrPtrVectorTy()) {
1812  if (ASK & ASK_SAFE_TO_DROP)
1813  Incompatible.addAttribute(Attribute::Alignment);
1814  }
1815 
1816  // Some attributes can apply to all "values" but there are no `void` values.
1817  if (Ty->isVoidTy()) {
1818  if (ASK & ASK_SAFE_TO_DROP)
1819  Incompatible.addAttribute(Attribute::NoUndef);
1820  }
1821 
1822  return Incompatible;
1823 }
1824 
1826  AttributeMask AM;
1827  AM.addAttribute(Attribute::NoUndef);
1828  AM.addAttribute(Attribute::Dereferenceable);
1829  AM.addAttribute(Attribute::DereferenceableOrNull);
1830  return AM;
1831 }
1832 
1833 template<typename AttrClass>
1834 static bool isEqual(const Function &Caller, const Function &Callee) {
1835  return Caller.getFnAttribute(AttrClass::getKind()) ==
1836  Callee.getFnAttribute(AttrClass::getKind());
1837 }
1838 
1839 /// Compute the logical AND of the attributes of the caller and the
1840 /// callee.
1841 ///
1842 /// This function sets the caller's attribute to false if the callee's attribute
1843 /// is false.
1844 template<typename AttrClass>
1845 static void setAND(Function &Caller, const Function &Callee) {
1846  if (AttrClass::isSet(Caller, AttrClass::getKind()) &&
1847  !AttrClass::isSet(Callee, AttrClass::getKind()))
1848  AttrClass::set(Caller, AttrClass::getKind(), false);
1849 }
1850 
1851 /// Compute the logical OR of the attributes of the caller and the
1852 /// callee.
1853 ///
1854 /// This function sets the caller's attribute to true if the callee's attribute
1855 /// is true.
1856 template<typename AttrClass>
1857 static void setOR(Function &Caller, const Function &Callee) {
1858  if (!AttrClass::isSet(Caller, AttrClass::getKind()) &&
1859  AttrClass::isSet(Callee, AttrClass::getKind()))
1860  AttrClass::set(Caller, AttrClass::getKind(), true);
1861 }
1862 
1863 /// If the inlined function had a higher stack protection level than the
1864 /// calling function, then bump up the caller's stack protection level.
1865 static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) {
1866  // If the calling function has *no* stack protection level (e.g. it was built
1867  // with Clang's -fno-stack-protector or no_stack_protector attribute), don't
1868  // change it as that could change the program's semantics.
1869  if (!Caller.hasStackProtectorFnAttr())
1870  return;
1871 
1872  // If upgrading the SSP attribute, clear out the old SSP Attributes first.
1873  // Having multiple SSP attributes doesn't actually hurt, but it adds useless
1874  // clutter to the IR.
1875  AttributeMask OldSSPAttr;
1876  OldSSPAttr.addAttribute(Attribute::StackProtect)
1877  .addAttribute(Attribute::StackProtectStrong)
1878  .addAttribute(Attribute::StackProtectReq);
1879 
1880  if (Callee.hasFnAttribute(Attribute::StackProtectReq)) {
1881  Caller.removeFnAttrs(OldSSPAttr);
1882  Caller.addFnAttr(Attribute::StackProtectReq);
1883  } else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
1884  !Caller.hasFnAttribute(Attribute::StackProtectReq)) {
1885  Caller.removeFnAttrs(OldSSPAttr);
1886  Caller.addFnAttr(Attribute::StackProtectStrong);
1887  } else if (Callee.hasFnAttribute(Attribute::StackProtect) &&
1888  !Caller.hasFnAttribute(Attribute::StackProtectReq) &&
1889  !Caller.hasFnAttribute(Attribute::StackProtectStrong))
1890  Caller.addFnAttr(Attribute::StackProtect);
1891 }
1892 
1893 /// If the inlined function required stack probes, then ensure that
1894 /// the calling function has those too.
1895 static void adjustCallerStackProbes(Function &Caller, const Function &Callee) {
1896  if (!Caller.hasFnAttribute("probe-stack") &&
1897  Callee.hasFnAttribute("probe-stack")) {
1898  Caller.addFnAttr(Callee.getFnAttribute("probe-stack"));
1899  }
1900 }
1901 
1902 /// If the inlined function defines the size of guard region
1903 /// on the stack, then ensure that the calling function defines a guard region
1904 /// that is no larger.
1905 static void
1907  Attribute CalleeAttr = Callee.getFnAttribute("stack-probe-size");
1908  if (CalleeAttr.isValid()) {
1909  Attribute CallerAttr = Caller.getFnAttribute("stack-probe-size");
1910  if (CallerAttr.isValid()) {
1911  uint64_t CallerStackProbeSize, CalleeStackProbeSize;
1912  CallerAttr.getValueAsString().getAsInteger(0, CallerStackProbeSize);
1913  CalleeAttr.getValueAsString().getAsInteger(0, CalleeStackProbeSize);
1914 
1915  if (CallerStackProbeSize > CalleeStackProbeSize) {
1916  Caller.addFnAttr(CalleeAttr);
1917  }
1918  } else {
1919  Caller.addFnAttr(CalleeAttr);
1920  }
1921  }
1922 }
1923 
1924 /// If the inlined function defines a min legal vector width, then ensure
1925 /// the calling function has the same or larger min legal vector width. If the
1926 /// caller has the attribute, but the callee doesn't, we need to remove the
1927 /// attribute from the caller since we can't make any guarantees about the
1928 /// caller's requirements.
1929 /// This function is called after the inlining decision has been made so we have
1930 /// to merge the attribute this way. Heuristics that would use
1931 /// min-legal-vector-width to determine inline compatibility would need to be
1932 /// handled as part of inline cost analysis.
1933 static void
1935  Attribute CallerAttr = Caller.getFnAttribute("min-legal-vector-width");
1936  if (CallerAttr.isValid()) {
1937  Attribute CalleeAttr = Callee.getFnAttribute("min-legal-vector-width");
1938  if (CalleeAttr.isValid()) {
1939  uint64_t CallerVectorWidth, CalleeVectorWidth;
1940  CallerAttr.getValueAsString().getAsInteger(0, CallerVectorWidth);
1941  CalleeAttr.getValueAsString().getAsInteger(0, CalleeVectorWidth);
1942  if (CallerVectorWidth < CalleeVectorWidth)
1943  Caller.addFnAttr(CalleeAttr);
1944  } else {
1945  // If the callee doesn't have the attribute then we don't know anything
1946  // and must drop the attribute from the caller.
1947  Caller.removeFnAttr("min-legal-vector-width");
1948  }
1949  }
1950 }
1951 
1952 /// If the inlined function has null_pointer_is_valid attribute,
1953 /// set this attribute in the caller post inlining.
1954 static void
1956  if (Callee.nullPointerIsDefined() && !Caller.nullPointerIsDefined()) {
1957  Caller.addFnAttr(Attribute::NullPointerIsValid);
1958  }
1959 }
1960 
1961 struct EnumAttr {
1962  static bool isSet(const Function &Fn,
1964  return Fn.hasFnAttribute(Kind);
1965  }
1966 
1967  static void set(Function &Fn,
1968  Attribute::AttrKind Kind, bool Val) {
1969  if (Val)
1970  Fn.addFnAttr(Kind);
1971  else
1972  Fn.removeFnAttr(Kind);
1973  }
1974 };
1975 
1976 struct StrBoolAttr {
1977  static bool isSet(const Function &Fn,
1978  StringRef Kind) {
1979  auto A = Fn.getFnAttribute(Kind);
1980  return A.getValueAsString().equals("true");
1981  }
1982 
1983  static void set(Function &Fn,
1984  StringRef Kind, bool Val) {
1985  Fn.addFnAttr(Kind, Val ? "true" : "false");
1986  }
1987 };
1988 
1989 #define GET_ATTR_NAMES
1990 #define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
1991  struct ENUM_NAME##Attr : EnumAttr { \
1992  static enum Attribute::AttrKind getKind() { \
1993  return llvm::Attribute::ENUM_NAME; \
1994  } \
1995  };
1996 #define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
1997  struct ENUM_NAME##Attr : StrBoolAttr { \
1998  static StringRef getKind() { return #DISPLAY_NAME; } \
1999  };
2000 #include "llvm/IR/Attributes.inc"
2001 
2002 #define GET_ATTR_COMPAT_FUNC
2003 #include "llvm/IR/Attributes.inc"
2004 
2006  const Function &Callee) {
2007  return hasCompatibleFnAttrs(Caller, Callee);
2008 }
2009 
2011  const Function &B) {
2012  return hasCompatibleFnAttrs(A, B);
2013 }
2014 
2016  const Function &Callee) {
2017  mergeFnAttrs(Caller, Callee);
2018 }
2019 
2021  const Function &ToMerge) {
2022 
2023  // We merge functions so that they meet the most general case.
2024  // For example, if the NoNansFPMathAttr is set in one function, but not in
2025  // the other, in the merged function we can say that the NoNansFPMathAttr
2026  // is not set.
2027  // However if we have the SpeculativeLoadHardeningAttr set true in one
2028  // function, but not the other, we make sure that the function retains
2029  // that aspect in the merged function.
2030  mergeFnAttrs(Base, ToMerge);
2031 }
2032 
2034  uint64_t Width) {
2035  Attribute Attr = Fn.getFnAttribute("min-legal-vector-width");
2036  if (Attr.isValid()) {
2037  uint64_t OldWidth;
2038  Attr.getValueAsString().getAsInteger(0, OldWidth);
2039  if (Width > OldWidth)
2040  Fn.addFnAttr("min-legal-vector-width", llvm::utostr(Width));
2041  }
2042 }
llvm::AttributeList::removeAttributeAtIndex
LLVM_NODISCARD AttributeList removeAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
Definition: Attributes.cpp:1265
llvm::AttrBuilder::addDereferenceableOrNullAttr
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute.
Definition: Attributes.cpp:1656
llvm::AttributeList::getRetDereferenceableOrNullBytes
uint64_t getRetDereferenceableOrNullBytes() const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of the return value.
Definition: Attributes.cpp:1453
i
i
Definition: README.txt:29
llvm::AttributeList::getParamInAllocaType
Type * getParamInAllocaType(unsigned ArgNo) const
Return the inalloca type for the specified function parameter.
Definition: Attributes.cpp:1429
llvm::AttributeList::print
void print(raw_ostream &O) const
Definition: Attributes.cpp:1501
llvm::Attribute::getWithPreallocatedType
static Attribute getWithPreallocatedType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:199
llvm::LLVMContextImpl::Alloc
BumpPtrAllocator Alloc
Definition: LLVMContextImpl.h:1471
llvm::AttributeList::removeAttributesAtIndex
LLVM_NODISCARD AttributeList removeAttributesAtIndex(LLVMContext &C, unsigned Index, const AttributeMask &AttrsToRemove) const
Remove the specified attributes at the specified index from this attribute list.
Definition: Attributes.cpp:1294
llvm::Attribute::EndAttrKinds
@ EndAttrKinds
Sentinal value useful for loops.
Definition: Attributes.h:76
set
We currently generate a but we really shouldn eax ecx xorl edx divl ecx eax divl ecx movl eax ret A similar code sequence works for division We currently compile i32 v2 eax eax jo LBB1_2 atomic and others It is also currently not done for read modify write instructions It is also current not done if the OF or CF flags are needed The shift operators have the complication that when the shift count is EFLAGS is not set
Definition: README.txt:1277
llvm::LLVMContext::pImpl
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:70
llvm::AttributeImpl
Definition: AttributeImpl.h:39
llvm::AttributeSet::AttributeSet
AttributeSet()=default
AttributeSet is a trivially copyable value type.
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::AttrBuilder::getAttribute
Attribute getAttribute(Attribute::AttrKind Kind) const
Return Attribute with the given Kind.
Definition: Attributes.cpp:1740
llvm::AttributeFuncs::mergeAttributesForOutlining
void mergeAttributesForOutlining(Function &Base, const Function &ToMerge)
Merges the functions attributes from ToMerge into function Base.
Definition: Attributes.cpp:2020
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:494
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::Attribute::isEnumAttribute
bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
Definition: Attributes.cpp:261
llvm::AttributeList::addRetAttributes
LLVM_NODISCARD AttributeList addRetAttributes(LLVMContext &C, const AttrBuilder &B) const
Add a return value attribute to the list.
Definition: Attributes.h:537
llvm::Attribute::isValid
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:169
llvm::AttributeList::addDereferenceableParamAttr
LLVM_NODISCARD AttributeList addDereferenceableParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given arg index.
Definition: Attributes.cpp:1324
llvm::AttrBuilder::AttrBuilder
AttrBuilder(LLVMContext &Ctx)
Definition: Attributes.h:1010
llvm::AttributeSet::hasAttributes
bool hasAttributes() const
Return true if attributes exists in this set.
Definition: Attributes.h:334
llvm::AttrBuilder::addUWTableAttr
AttrBuilder & addUWTableAttr(UWTableKind Kind)
This turns the unwind table kind into the form used internally in Attribute.
Definition: Attributes.cpp:1687
llvm::yaml::getStringValue
static StringRef getStringValue(IO &IO, const char *Key)
Definition: ELFYAML.cpp:1484
llvm::none_of
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1619
llvm::AttributeList::hasAttributesAtIndex
bool hasAttributesAtIndex(unsigned Index) const
Return true if attribute exists at the given index.
Definition: Attributes.cpp:1374
Optional.h
attrIdxToArrayIdx
static unsigned attrIdxToArrayIdx(unsigned Index)
Map from AttributeList index to the internal array index.
Definition: Attributes.cpp:926
llvm::AttrBuilder::hasAlignmentAttr
bool hasAlignmentAttr() const
Return true if the builder has an alignment attribute.
Definition: Attributes.cpp:1763
llvm::Attribute::getStackAlignment
MaybeAlign getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:335
llvm::Attribute::getWithAllocSizeArgs
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:213
llvm::Function::end
iterator end()
Definition: Function.h:727
llvm::AttributeList::hasAttrSomewhere
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value.
Definition: Attributes.cpp:1386
llvm::Value::MaximumAlignment
static constexpr uint64_t MaximumAlignment
Definition: Value.h:793
llvm::AttributeListImpl::end
iterator end() const
Definition: AttributeImpl.h:319
llvm::AttrBuilder::addTypeAttr
AttrBuilder & addTypeAttr(Attribute::AttrKind Kind, Type *Ty)
Add a type attribute with the given type.
Definition: Attributes.cpp:1699
llvm::Type::isPointerTy
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:218
llvm::AttributeSet::getDereferenceableOrNullBytes
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:693
llvm::Function::empty
bool empty() const
Definition: Function.h:731
llvm::Attribute::hasAttribute
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:320
llvm::AttributeList::AttributeList
AttributeList()=default
llvm::Function
Definition: Function.h:60
llvm::Attribute
Definition: Attributes.h:52
llvm::lower_bound
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1724
StringRef.h
llvm::AttributeFuncs::ASK_UNSAFE_TO_DROP
@ ASK_UNSAFE_TO_DROP
Definition: Attributes.h:1216
llvm::AttributeSetNode::getNumAttributes
unsigned getNumAttributes() const
Return the number of attributes this AttributeList contains.
Definition: AttributeImpl.h:240
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:183
EnumAttr::set
static void set(Function &Fn, Attribute::AttrKind Kind, bool Val)
Definition: Attributes.cpp:1967
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:632
llvm::AttributeList::getParamPreallocatedType
Type * getParamPreallocatedType(unsigned ArgNo) const
Return the preallocated type for the specified function parameter.
Definition: Attributes.cpp:1425
llvm::AttributeMask::contains
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
Definition: Attributes.h:982
llvm::Attribute::getAttrKindFromName
static Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
Definition: Attributes.cpp:226
llvm::Attribute::get
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:91
llvm::Attribute::isTypeAttribute
bool isTypeAttribute() const
Return true if the attribute is a type attribute.
Definition: Attributes.cpp:273
llvm::Attribute::isIntAttrKind
static bool isIntAttrKind(AttrKind Kind)
Definition: Attributes.h:87
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::UWTableKind::None
@ None
No unwind table requested.
getImpl
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const Module *M)
This lazily constructs the LazyValueInfoImpl.
Definition: LazyValueInfo.cpp:1514
llvm::AttributeList::addParamAttribute
LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
Definition: Attributes.h:544
llvm::AttributeList::getUWTableKind
UWTableKind getUWTableKind() const
Get the unwind table kind requested for the function.
Definition: Attributes.cpp:1462
adjustCallerStackProbes
static void adjustCallerStackProbes(Function &Caller, const Function &Callee)
If the inlined function required stack probes, then ensure that the calling function has those too.
Definition: Attributes.cpp:1895
ErrorHandling.h
llvm::AttributeSet::addAttributes
LLVM_NODISCARD AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const
Add attributes to the attribute set.
Definition: Attributes.cpp:621
llvm::erase_if
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition: STLExtras.h:1795
llvm::AttributeFuncs::getUBImplyingAttributes
AttributeMask getUBImplyingAttributes()
Get param/return attributes which imply immediate undefined behavior if an invalid value is passed.
Definition: Attributes.cpp:1825
llvm::AttributeList::end
iterator end() const
Definition: Attributes.cpp:1489
llvm::AttributeList::get
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Definition: Attributes.cpp:1015
AllocSizeNumElemsNotPresent
static const unsigned AllocSizeNumElemsNotPresent
Definition: Attributes.cpp:54
llvm::Attribute::getWithStackAlignment
static Attribute getWithStackAlignment(LLVMContext &Context, Align Alignment)
Definition: Attributes.cpp:170
setOR
static void setOR(Function &Caller, const Function &Callee)
Compute the logical OR of the attributes of the caller and the callee.
Definition: Attributes.cpp:1857
llvm::AttributeList::getParamByValType
Type * getParamByValType(unsigned ArgNo) const
Return the byval type for the specified function parameter.
Definition: Attributes.cpp:1413
llvm::UWTableKind::Default
@ Default
llvm::AttrBuilder::addAllocSizeAttr
AttrBuilder & addAllocSizeAttr(unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
This turns one (or two) ints into the form used internally in Attribute.
Definition: Attributes.cpp:1663
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::Attribute::getWithVScaleRangeArgs
static Attribute getWithVScaleRangeArgs(LLVMContext &Context, unsigned MinValue, unsigned MaxValue)
Definition: Attributes.cpp:220
llvm::AttributeList
Definition: Attributes.h:408
llvm::AttributeMask
Definition: Attributes.h:944
llvm::AttributeList::addDereferenceableRetAttr
LLVM_NODISCARD AttributeList addDereferenceableRetAttr(LLVMContext &C, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
Definition: Attributes.cpp:1317
llvm::Attribute::isTypeAttrKind
static bool isTypeAttrKind(AttrKind Kind)
Definition: Attributes.h:90
llvm::AttrBuilder::getVScaleRangeMin
unsigned getVScaleRangeMin() const
Retrieve the minimum value of 'vscale_range'.
Definition: Attributes.cpp:1625
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1656
llvm::AttributeList::getFnAttrs
AttributeSet getFnAttrs() const
The function attributes are returned.
Definition: Attributes.cpp:1361
llvm::TypeAttributeImpl
Definition: AttributeImpl.h:182
llvm::Optional< unsigned >
llvm::AttributeBitSet::hasAttribute
bool hasAttribute(Attribute::AttrKind Kind) const
Definition: AttributeImpl.h:199
packVScaleRangeArgs
static uint64_t packVScaleRangeArgs(unsigned MinValue, Optional< unsigned > MaxValue)
Definition: Attributes.cpp:77
llvm::AttributeSet::getVScaleRangeMin
unsigned getVScaleRangeMin() const
Definition: Attributes.cpp:726
llvm::AttrBuilder::addPreallocatedAttr
AttrBuilder & addPreallocatedAttr(Type *Ty)
This turns a preallocated type into the form used internally in Attribute.
Definition: Attributes.cpp:1715
setAND
static void setAND(Function &Caller, const Function &Callee)
Compute the logical AND of the attributes of the caller and the callee.
Definition: Attributes.cpp:1845
llvm::Attribute::getAlignment
MaybeAlign getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:329
llvm::AttributeListImpl::begin
iterator begin() const
Definition: AttributeImpl.h:318
adjustMinLegalVectorWidth
static void adjustMinLegalVectorWidth(Function &Caller, const Function &Callee)
If the inlined function defines a min legal vector width, then ensure the calling function has the sa...
Definition: Attributes.cpp:1934
llvm::AttrBuilder::addRawIntAttr
AttrBuilder & addRawIntAttr(Attribute::AttrKind Kind, uint64_t Value)
Add integer attribute with raw value (packed/encoded if necessary).
Definition: Attributes.cpp:1616
llvm::AttributeSetNode::getDereferenceableBytes
uint64_t getDereferenceableBytes() const
Definition: Attributes.cpp:873
STLExtras.h
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::AttrBuilder::merge
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
Definition: Attributes.cpp:1723
llvm::Attribute::getValueAsBool
bool getValueAsBool() const
Return the attribute's value as a boolean.
Definition: Attributes.cpp:291
adjustNullPointerValidAttr
static void adjustNullPointerValidAttr(Function &Caller, const Function &Callee)
If the inlined function has null_pointer_is_valid attribute, set this attribute in the caller post in...
Definition: Attributes.cpp:1955
llvm::isEqual
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
Definition: GCNRegPressure.cpp:55
llvm::LLVMContextImpl::AttrsSet
FoldingSet< AttributeImpl > AttrsSet
Definition: LLVMContextImpl.h:1409
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
llvm::dwarf::Attribute
Attribute
Attributes.
Definition: Dwarf.h:125
adjustCallerSSPLevel
static void adjustCallerSSPLevel(Function &Caller, const Function &Callee)
If the inlined function had a higher stack protection level than the calling function,...
Definition: Attributes.cpp:1865
llvm::AttrBuilder::removeAttribute
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
Definition: Attributes.cpp:1595
llvm::AttributeSetNode::getAlignment
MaybeAlign getAlignment() const
Definition: Attributes.cpp:855
unpackVScaleRangeArgs
static std::pair< unsigned, Optional< unsigned > > unpackVScaleRangeArgs(uint64_t Value)
Definition: Attributes.cpp:83
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:283
llvm::AttributeList::getParamDereferenceableBytes
uint64_t getParamDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown) of an arg.
Definition: Attributes.cpp:1449
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::AttrBuilder::remove
AttrBuilder & remove(const AttributeMask &AM)
Remove the attributes from the builder.
Definition: Attributes.cpp:1731
llvm::AttributeList::getParamStackAlignment
MaybeAlign getParamStackAlignment(unsigned ArgNo) const
Return the stack alignment for the specified function parameter.
Definition: Attributes.cpp:1409
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::Attribute::getValueAsInt
uint64_t getValueAsInt() const
Return the attribute's value as an integer.
Definition: Attributes.cpp:284
llvm::AttributeSet::addAttribute
LLVM_NODISCARD AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
Definition: Attributes.cpp:606
llvm::AttributeList::hasAttributeAtIndex
bool hasAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Definition: Attributes.cpp:1365
llvm::all_of
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:1605
llvm::UWTableKind
UWTableKind
Definition: CodeGen.h:100
llvm::ArrayRef::back
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:173
llvm::Attribute::getWithInAllocaType
static Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:203
llvm::AttrBuilder::getRawIntAttr
uint64_t getRawIntAttr(Attribute::AttrKind Kind) const
Return raw (possibly packed/encoded) value of integer attribute or 0 if not set.
Definition: Attributes.cpp:1610
llvm::AttrBuilder::getTypeAttr
Type * getTypeAttr(Attribute::AttrKind Kind) const
Retrieve type for the given type attribute.
Definition: Attributes.cpp:1693
llvm::AttributeList::hasParentContext
bool hasParentContext(LLVMContext &C) const
Return true if this attribute list belongs to the LLVMContext.
Definition: Attributes.cpp:1477
llvm::AttributeListImpl
Definition: AttributeImpl.h:281
addAttributeImpl
static void addAttributeImpl(SmallVectorImpl< Attribute > &Attrs, K Kind, Attribute Attr)
Definition: Attributes.cpp:1568
llvm::AttrBuilder::addByValAttr
AttrBuilder & addByValAttr(Type *Ty)
This turns a byval type into the form used internally in Attribute.
Definition: Attributes.cpp:1703
llvm::AttributeSet::getAsString
std::string getAsString(bool InAttrGrp=false) const
Definition: Attributes.cpp:738
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::AttributeList::begin
iterator begin() const
Definition: Attributes.cpp:1485
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::AttributeList::getParamDereferenceableOrNullBytes
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of an arg.
Definition: Attributes.cpp:1458
llvm::LLVMContextImpl
Definition: LLVMContextImpl.h:1354
llvm::AttributeSet::hasAttribute
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Definition: Attributes.cpp:665
llvm::AttributeImpl::isEnumAttribute
bool isEnumAttribute() const
Definition: AttributeImpl.h:57
llvm::AttrBuilder::operator==
bool operator==(const AttrBuilder &B) const
Definition: Attributes.cpp:1767
llvm::AttributeImpl::getKindAsString
StringRef getKindAsString() const
Definition: Attributes.cpp:554
llvm::Type::print
void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
Definition: AsmWriter.cpp:4553
StrBoolAttr::set
static void set(Function &Fn, StringRef Kind, bool Val)
Definition: Attributes.cpp:1983
llvm::IntAttributeImpl
Definition: AttributeImpl.h:133
llvm::AttributeImpl::hasAttribute
bool hasAttribute(Attribute::AttrKind A) const
Definition: Attributes.cpp:529
llvm::AttributeImpl::getKindAsEnum
Attribute::AttrKind getKindAsEnum() const
Definition: Attributes.cpp:539
llvm::Optional::getValueOr
constexpr T getValueOr(U &&value) const &
Definition: Optional.h:289
llvm::AttributeImpl::isIntAttribute
bool isIntAttribute() const
Definition: AttributeImpl.h:58
llvm::AttributeSet::getDereferenceableBytes
uint64_t getDereferenceableBytes() const
Definition: Attributes.cpp:689
llvm::AttributeFuncs::areOutlineCompatible
bool areOutlineCompatible(const Function &A, const Function &B)
Checks if there are any incompatible function attributes between A and B.
Definition: Attributes.cpp:2010
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::Function::getFnAttribute
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.cpp:651
llvm::Attribute::getVScaleRangeMin
unsigned getVScaleRangeMin() const
Returns the minimum value for the vscale_range attribute.
Definition: Attributes.cpp:361
AttributeProperty
AttributeProperty
Definition: Attributes.cpp:496
llvm::AttributeList::hasFnAttr
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the function.
Definition: Attributes.cpp:1378
LLVMContextImpl.h
llvm::AttributeSetNode::hasAttribute
bool hasAttribute(Attribute::AttrKind Kind) const
Definition: AttributeImpl.h:242
StrBoolAttr::isSet
static bool isSet(const Function &Fn, StringRef Kind)
Definition: Attributes.cpp:1977
llvm::AttributeList::getAttributes
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
Definition: Attributes.cpp:1470
llvm::AttributeList::getRetAlignment
MaybeAlign getRetAlignment() const
Return the alignment of the return value.
Definition: Attributes.cpp:1401
packAllocSizeArgs
static uint64_t packAllocSizeArgs(unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:56
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition: SmallVector.h:619
llvm::raw_ostream::flush
void flush()
Definition: raw_ostream.h:187
llvm::AttributeSet::getInAllocaType
Type * getInAllocaType() const
Definition: Attributes.cpp:713
llvm::Attribute::getKindAsString
StringRef getKindAsString() const
Return the attribute's kind as a string.
Definition: Attributes.cpp:298
llvm::Attribute::isStringAttribute
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:269
llvm::AttributeList::getParamElementType
Type * getParamElementType(unsigned ArgNo) const
Return the elementtype type for the specified function parameter.
Definition: Attributes.cpp:1433
llvm::AttributeList::addDereferenceableOrNullParamAttr
LLVM_NODISCARD AttributeList addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given arg index.
Definition: Attributes.cpp:1333
StrBoolAttr
Definition: Attributes.cpp:1976
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::Attribute::getWithStructRetType
static Attribute getWithStructRetType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:191
llvm::AttrBuilder::clear
void clear()
Definition: Attributes.cpp:1537
llvm::StringRef::str
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:245
llvm::Attribute::isEnumAttrKind
static bool isEnumAttrKind(AttrKind Kind)
Definition: Attributes.h:84
hasAttributeProperty
static bool hasAttributeProperty(Attribute::AttrKind Kind, AttributeProperty Prop)
Definition: Attributes.cpp:505
llvm::Attribute::getValueAsString
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:305
llvm::StringRef::getAsInteger
std::enable_if_t< std::numeric_limits< T >::is_signed, bool > getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:510
llvm::None
const NoneType None
Definition: None.h:24
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::AttrBuilder::addAlignmentAttr
AttrBuilder & addAlignmentAttr(MaybeAlign Align)
This turns an alignment into the form used internally in Attribute.
Definition: Attributes.cpp:1633
Type.h
llvm::AttributeSetNode::begin
iterator begin() const
Definition: AttributeImpl.h:264
llvm::AttributeFuncs::AttributeSafetyKind
AttributeSafetyKind
Definition: Attributes.h:1214
llvm::AttributeSet::end
iterator end() const
Definition: Attributes.cpp:754
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:191
llvm::AttrBuilder::addAttribute
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
Definition: Attributes.cpp:1585
llvm::AttributeSet::getUWTableKind
UWTableKind getUWTableKind() const
Definition: Attributes.cpp:734
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:625
llvm::AttributeList::ReturnIndex
@ ReturnIndex
Definition: Attributes.h:411
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:239
llvm::AttributeList::getRetAttrs
AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
Definition: Attributes.cpp:1357
VI
@ VI
Definition: SIInstrInfo.cpp:7829
llvm::AttrBuilder::addStackAlignmentAttr
AttrBuilder & addStackAlignmentAttr(MaybeAlign Align)
This turns a stack alignment into the form used internally in Attribute.
Definition: Attributes.cpp:1641
llvm::Attribute::canUseAsFnAttr
static bool canUseAsFnAttr(AttrKind Kind)
Definition: Attributes.cpp:513
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
Index
uint32_t Index
Definition: ELFObjHandler.cpp:82
EnumAttr
Definition: Attributes.cpp:1961
llvm::Attribute::getVScaleRangeMax
Optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or None when unknown.
Definition: Attributes.cpp:367
uint64_t
llvm::AttrBuilder::getVScaleRangeMax
Optional< unsigned > getVScaleRangeMax() const
Retrieve the maximum value of 'vscale_range' or None when unknown.
Definition: Attributes.cpp:1629
llvm::Attribute::None
@ None
No attributes have been set.
Definition: Attributes.h:73
llvm::AttributeList::getRetDereferenceableBytes
uint64_t getRetDereferenceableBytes() const
Get the number of dereferenceable bytes (or zero if unknown) of the return value.
Definition: Attributes.cpp:1445
ParamAttr
@ ParamAttr
Definition: Attributes.cpp:498
llvm::AttributeListImpl::AttributeList
friend class AttributeList
Definition: AttributeImpl.h:284
llvm::AttrBuilder::addVScaleRangeAttrFromRawRepr
AttrBuilder & addVScaleRangeAttrFromRawRepr(uint64_t RawVScaleRangeRepr)
Add a vscale_range attribute, using the representation returned by Attribute.getIntValue().
Definition: Attributes.cpp:1679
llvm::AttributeList::addParamAttributes
LLVM_NODISCARD AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &B) const
Add an argument attribute to the list.
Definition: Attributes.h:565
llvm::AttributeListImpl::dump
void dump() const
Definition: Attributes.cpp:978
llvm::AttributeSet::get
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
Definition: Attributes.cpp:598
llvm::AttrBuilder::addInAllocaAttr
AttrBuilder & addInAllocaAttr(Type *Ty)
This turns an inalloca type into the form used internally in Attribute.
Definition: Attributes.cpp:1719
llvm::AttributeFuncs::ASK_SAFE_TO_DROP
@ ASK_SAFE_TO_DROP
Definition: Attributes.h:1215
llvm::Attribute::getWithUWTableKind
static Attribute getWithUWTableKind(LLVMContext &Context, UWTableKind Kind)
Definition: Attributes.cpp:207
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::AttributeList::getAsString
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
Definition: Attributes.cpp:1466
llvm::AttributeList::dump
void dump() const
Definition: Attributes.cpp:1525
llvm::AttributeSetNode::getAttributeType
Type * getAttributeType(Attribute::AttrKind Kind) const
Definition: Attributes.cpp:867
llvm::Attribute::getKindAsEnum
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
Definition: Attributes.cpp:277
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::AttrBuilder
Definition: Attributes.h:1005
StringExtras.h
llvm::Attribute::AttrKind
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:71
llvm::Attribute::getWithDereferenceableBytes
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:175
llvm::AttributeSetNode::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: AttributeImpl.h:267
llvm::AttributeList::getParamAlignment
MaybeAlign getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
Definition: Attributes.cpp:1405
ArrayRef.h
llvm::AttributeSet::getVScaleRangeMax
Optional< unsigned > getVScaleRangeMax() const
Definition: Attributes.cpp:730
llvm::Attribute::canUseAsParamAttr
static bool canUseAsParamAttr(AttrKind Kind)
Definition: Attributes.cpp:517
llvm::AttributeImpl::getValueAsString
StringRef getValueAsString() const
Definition: Attributes.cpp:559
llvm::AttributeSet::removeAttributes
LLVM_NODISCARD AttributeSet removeAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attributes from this set.
Definition: Attributes.cpp:650
llvm::AttributeSet::hasParentContext
bool hasParentContext(LLVMContext &C) const
Return true if this attribute set belongs to the LLVMContext.
Definition: Attributes.cpp:742
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AttrBuilder::addByRefAttr
AttrBuilder & addByRefAttr(Type *Ty)
This turns a byref type into the form used internally in Attribute.
Definition: Attributes.cpp:1711
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:853
llvm::Attribute::getAsString
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
Definition: Attributes.cpp:379
llvm::AttributeSetNode::getDereferenceableOrNullBytes
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:879
llvm::LLVMContextImpl::AttrsLists
FoldingSet< AttributeListImpl > AttrsLists
Definition: LLVMContextImpl.h:1410
AttributeComparator
Attribute comparator that only compares attribute keys.
Definition: Attributes.cpp:1541
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
llvm::AttributeSet::removeAttribute
LLVM_NODISCARD AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
Definition: Attributes.cpp:634
llvm::AttrBuilder::contains
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
Definition: Attributes.cpp:1755
FnAttr
@ FnAttr
Definition: Attributes.cpp:497
llvm::AttributeImpl::isTypeAttribute
bool isTypeAttribute() const
Definition: AttributeImpl.h:60
llvm::AttributeSet::getNumAttributes
unsigned getNumAttributes() const
Return the number of attributes in this set.
Definition: Attributes.cpp:661
llvm::AttributeSetNode::getStackAlignment
MaybeAlign getStackAlignment() const
Definition: Attributes.cpp:861
llvm::StringAttributeImpl
Definition: AttributeImpl.h:146
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1586
AttributeImpl.h
llvm::AttributeImpl::operator<
bool operator<(const AttributeImpl &AI) const
Used when sorting the attributes.
Definition: Attributes.cpp:569
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::AttributeList::AttributeListImpl
friend class AttributeListImpl
Definition: Attributes.h:418
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1612
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::AttributeSetNode::getAttribute
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Attributes.cpp:845
llvm::AttributeSet::dump
void dump() const
Definition: Attributes.cpp:759
A
* A
Definition: README_ALTIVEC.txt:89
llvm::UWTableKind::Sync
@ Sync
"Synchronous" unwind tables
llvm::Attribute::getDereferenceableOrNullBytes
uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute.
Definition: Attributes.cpp:348
Compiler.h
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1811
llvm::AttributeList::getParamByRefType
Type * getParamByRefType(unsigned ArgNo) const
Return the byref type for the specified function parameter.
Definition: Attributes.cpp:1421
llvm::FoldingSetNodeID
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:317
llvm::AttributeFuncs::updateMinLegalVectorWidthAttr
void updateMinLegalVectorWidthAttr(Function &Fn, uint64_t Width)
Update min-legal-vector-width if it is in Attribute and less than Width.
Definition: Attributes.cpp:2033
llvm::Attribute::getUWTableKind
UWTableKind getUWTableKind() const
Definition: Attributes.cpp:373
llvm::AttributeSetNode
Definition: AttributeImpl.h:212
adjustCallerStackProbeSize
static void adjustCallerStackProbeSize(Function &Caller, const Function &Callee)
If the inlined function defines the size of guard region on the stack, then ensure that the calling f...
Definition: Attributes.cpp:1906
llvm::Type::isPtrOrPtrVectorTy
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:224
llvm::AttrBuilder::addAllocSizeAttrFromRawRepr
AttrBuilder & addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr)
Add an allocsize attribute, using the representation returned by Attribute.getIntValue().
Definition: Attributes.cpp:1668
llvm::AttributeSetNode::getUWTableKind
UWTableKind getUWTableKind() const
Definition: Attributes.cpp:904
llvm::AttributeSet::getAllocSizeArgs
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Definition: Attributes.cpp:721
llvm::Attribute::getWithDereferenceableOrNullBytes
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:181
llvm::AttributeList::getRetStackAlignment
MaybeAlign getRetStackAlignment() const
Get the stack alignment of the return value.
Definition: Attributes.cpp:1441
AttributeComparator::operator()
bool operator()(Attribute A0, StringRef Kind) const
Definition: Attributes.cpp:1560
llvm::AttributeListImpl::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Attributes.cpp:949
llvm::StringAttributeImpl::totalSizeToAlloc
static size_t totalSizeToAlloc(StringRef Kind, StringRef Val)
Definition: AttributeImpl.h:176
unpackAllocSizeArgs
static std::pair< unsigned, Optional< unsigned > > unpackAllocSizeArgs(uint64_t Num)
Definition: Attributes.cpp:67
llvm::Function::begin
iterator begin()
Definition: Function.h:725
FoldingSet.h
llvm::AttrBuilder::addStructRetAttr
AttrBuilder & addStructRetAttr(Type *Ty)
This turns a sret type into the form used internally in Attribute.
Definition: Attributes.cpp:1707
llvm::AttributeList::addAttributesAtIndex
LLVM_NODISCARD AttributeList addAttributesAtIndex(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
Definition: Attributes.cpp:1230
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:186
llvm::Attribute::getWithAlignment
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:165
Attributes.h
llvm::AttributeImpl::getValueAsBool
bool getValueAsBool() const
Definition: Attributes.cpp:549
llvm::Attribute::getDereferenceableBytes
uint64_t getDereferenceableBytes() const
Returns the number of dereferenceable bytes from the dereferenceable attribute.
Definition: Attributes.cpp:341
llvm::Attribute::hasParentContext
bool hasParentContext(LLVMContext &C) const
Return true if this attribute belongs to the LLVMContext.
Definition: Attributes.cpp:477
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::AttributeListImpl::AttributeListImpl
AttributeListImpl(ArrayRef< AttributeSet > Sets)
Definition: Attributes.cpp:930
llvm::AttributeSet::getPreallocatedType
Type * getPreallocatedType() const
Definition: Attributes.cpp:709
llvm::empty
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Definition: STLExtras.h:268
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::AttributeSet::getByRefType
Type * getByRefType() const
Definition: Attributes.cpp:697
llvm::Attribute::isExistingAttribute
static bool isExistingAttribute(StringRef Name)
Return true if the provided string matches the IR name of an attribute.
Definition: Attributes.cpp:249
llvm::EnumAttributeImpl
Definition: AttributeImpl.h:116
llvm::Attribute::Attribute
Attribute()=default
llvm::AttributeSet::getByValType
Type * getByValType() const
Definition: Attributes.cpp:701
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:152
llvm::ArrayRef::take_front
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:227
llvm::Align::value
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
llvm::Function::back
const BasicBlock & back() const
Definition: Function.h:734
llvm::BumpPtrAllocatorImpl::Allocate
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:146
llvm::AttributeList::getParamStructRetType
Type * getParamStructRetType(unsigned ArgNo) const
Return the sret type for the specified function parameter.
Definition: Attributes.cpp:1417
llvm::Attribute::getValueAsType
Type * getValueAsType() const
Return the attribute's value as a Type.
Definition: Attributes.cpp:312
Function.h
AttributeComparator::operator()
bool operator()(Attribute A0, Attribute::AttrKind Kind) const
Definition: Attributes.cpp:1555
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1550
llvm::is_sorted
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition: STLExtras.h:1685
llvm::AttributeList::getNumAttrSets
unsigned getNumAttrSets() const
Definition: Attributes.cpp:1497
llvm::AttributeFuncs::typeIncompatible
AttributeMask typeIncompatible(Type *Ty, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
Definition: Attributes.cpp:1776
llvm::AttributeSet::begin
iterator begin() const
Definition: Attributes.cpp:750
llvm::LLVMContextImpl::AttrsSetNodes
FoldingSet< AttributeSetNode > AttrsSetNodes
Definition: LLVMContextImpl.h:1411
llvm::AttributeList::getAttributeAtIndex
Attribute getAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
Definition: Attributes.cpp:1391
llvm::AttributeSet::getElementType
Type * getElementType() const
Definition: Attributes.cpp:717
StringSwitch.h
llvm::AttributeList::addAllocSizeParamAttr
LLVM_NODISCARD AttributeList addAllocSizeParamAttr(LLVMContext &C, unsigned ArgNo, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Add the allocsize attribute to the attribute set at the given arg index.
Definition: Attributes.cpp:1341
llvm::AttributeSetNode::end
iterator end() const
Definition: AttributeImpl.h:265
llvm::AMDGPU::Hwreg::Width
Width
Definition: SIDefines.h:432
AttributeComparator::operator()
bool operator()(Attribute A0, Attribute A1) const
Definition: Attributes.cpp:1542
llvm::AttrBuilder::addDereferenceableAttr
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
Definition: Attributes.cpp:1650
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::Attribute::getWithByRefType
static Attribute getWithByRefType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:195
llvm::AttributeList::FunctionIndex
@ FunctionIndex
Definition: Attributes.h:412
llvm::Attribute::getNameFromAttrKind
static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
Definition: Attributes.cpp:235
llvm::AttributeFuncs::areInlineCompatible
bool areInlineCompatible(const Function &Caller, const Function &Callee)
Definition: Attributes.cpp:2005
llvm::AttributeSet
Definition: Attributes.h:274
RetAttr
@ RetAttr
Definition: Attributes.cpp:499
SmallVector.h
llvm::AttributeSet::getAttribute
Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
Definition: Attributes.cpp:673
List
const NodeList & List
Definition: RDFGraph.cpp:199
llvm::AttributeSetNode::getAsString
std::string getAsString(bool InAttrGrp) const
Definition: Attributes.cpp:910
llvm::Function::removeFnAttr
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
Definition: Function.cpp:583
llvm::AttributeBitSet::addAttribute
void addAttribute(Attribute::AttrKind Kind)
Definition: AttributeImpl.h:203
llvm::AttributeSetNode::getVScaleRangeMax
Optional< unsigned > getVScaleRangeMax() const
Definition: Attributes.cpp:898
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::Function::addFnAttr
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.cpp:535
llvm::AttributeList::indexes
index_iterator indexes() const
Use this to iterate over the valid attribute indexes.
Definition: Attributes.h:895
llvm::AttributeList::AttributeSet
friend class AttributeSet
Definition: Attributes.h:419
llvm::AttributeList::AttrBuilder
friend class AttrBuilder
Definition: Attributes.h:417
llvm::AttributeList::addAttributeAtIndex
LLVM_NODISCARD AttributeList addAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
Definition: Attributes.cpp:1193
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::AttributeImpl::getValueAsType
Type * getValueAsType() const
Definition: Attributes.cpp:564
llvm::Attribute::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: Attributes.cpp:492
llvm::AttributeSet::getStackAlignment
MaybeAlign getStackAlignment() const
Definition: Attributes.cpp:685
llvm::Attribute::isIntAttribute
bool isIntAttribute() const
Return true if the attribute is an integer attribute.
Definition: Attributes.cpp:265
llvm::AttributeSet::getStructRetType
Type * getStructRetType() const
Definition: Attributes.cpp:705
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
llvm::AttrBuilder::addVScaleRangeAttr
AttrBuilder & addVScaleRangeAttr(unsigned MinValue, Optional< unsigned > MaxValue)
This turns two ints into the form used internally in Attribute.
Definition: Attributes.cpp:1674
LLVMContext.h
llvm::AttributeFuncs::mergeAttributesForInlining
void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller's and callee's attributes.
Definition: Attributes.cpp:2015
llvm::AttributeMask::addAttribute
AttributeMask & addAttribute(Attribute::AttrKind Val)
Add an attribute to the mask.
Definition: Attributes.h:959
llvm::AttributeImpl::Profile
void Profile(FoldingSetNodeID &ID) const
Definition: AttributeImpl.h:77
raw_ostream.h
llvm::AttributeSet::getAlignment
MaybeAlign getAlignment() const
Definition: Attributes.cpp:681
llvm::Attribute::getWithByValType
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:187
llvm::AttributeList::getParamAttrs
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
Definition: Attributes.cpp:1353
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:644
llvm::AttrBuilder::getAllocSizeArgs
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Retrieve the allocsize args, if the allocsize attribute exists.
Definition: Attributes.cpp:1621
llvm::AttrBuilder::overlaps
bool overlaps(const AttributeMask &AM) const
Return true if the builder has any attribute that's in the specified builder.
Definition: Attributes.cpp:1736
llvm::AttributeListImpl::hasAttrSomewhere
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value.
Definition: Attributes.cpp:959
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::AttributeList::FirstArgIndex
@ FirstArgIndex
Definition: Attributes.h:413
llvm::AttributeImpl::isStringAttribute
bool isStringAttribute() const
Definition: AttributeImpl.h:59
EnumAttr::isSet
static bool isSet(const Function &Fn, Attribute::AttrKind Kind)
Definition: Attributes.cpp:1962
llvm::Attribute::operator<
bool operator<(Attribute A) const
Less-than operator. Useful for sorting the attributes list.
Definition: Attributes.cpp:485
llvm::AttributeList::isEmpty
bool isEmpty() const
Return true if there are no attributes.
Definition: Attributes.h:907
llvm::AttributeImpl::getValueAsInt
uint64_t getValueAsInt() const
Definition: Attributes.cpp:544
llvm::AttributeSetNode::get
static AttributeSetNode * get(LLVMContext &C, const AttrBuilder &B)
Definition: Attributes.cpp:820
llvm::AttributeSetNode::getVScaleRangeMin
unsigned getVScaleRangeMin() const
Definition: Attributes.cpp:892
llvm::Attribute::canUseAsRetAttr
static bool canUseAsRetAttr(AttrKind Kind)
Definition: Attributes.cpp:521
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::Attribute::getAllocSizeArgs
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute (or pair(0, 0) if not known).
Definition: Attributes.cpp:355
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:927
llvm::Function::size
size_t size() const
Definition: Function.h:730
llvm::AttributeList::getFnStackAlignment
MaybeAlign getFnStackAlignment() const
Get the stack alignment of the function.
Definition: Attributes.cpp:1437
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
llvm::AttributeSetNode::getAllocSizeArgs
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Definition: Attributes.cpp:886