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