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