LLVM  8.0.0svn
Attributes.cpp
Go to the documentation of this file.
1 //===- Attributes.cpp - Implement AttributesList --------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // \file
11 // This file implements the Attribute, AttributeImpl, AttrBuilder,
12 // AttributeListImpl, and AttributeList classes.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "llvm/IR/Attributes.h"
17 #include "AttributeImpl.h"
18 #include "LLVMContextImpl.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/FoldingSet.h"
21 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/STLExtras.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringExtras.h"
25 #include "llvm/ADT/StringRef.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 |
67  NumElemsArg.getValueOr(AllocSizeNumElemsNotPresent);
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 
82  uint64_t Val) {
83  LLVMContextImpl *pImpl = Context.pImpl;
85  ID.AddInteger(Kind);
86  if (Val) ID.AddInteger(Val);
87 
88  void *InsertPoint;
89  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
90 
91  if (!PA) {
92  // If we didn't find any existing attributes of the same shape then create a
93  // new one and insert it.
94  if (!Val)
95  PA = new EnumAttributeImpl(Kind);
96  else
97  PA = new IntAttributeImpl(Kind, Val);
98  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
99  }
100 
101  // Return the Attribute that we found or created.
102  return Attribute(PA);
103 }
104 
106  LLVMContextImpl *pImpl = Context.pImpl;
108  ID.AddString(Kind);
109  if (!Val.empty()) ID.AddString(Val);
110 
111  void *InsertPoint;
112  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
113 
114  if (!PA) {
115  // If we didn't find any existing attributes of the same shape then create a
116  // new one and insert it.
117  PA = new StringAttributeImpl(Kind, Val);
118  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
119  }
120 
121  // Return the Attribute that we found or created.
122  return Attribute(PA);
123 }
124 
126  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
127  assert(Align <= 0x40000000 && "Alignment too large.");
128  return get(Context, Alignment, Align);
129 }
130 
132  uint64_t Align) {
133  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
134  assert(Align <= 0x100 && "Alignment too large.");
135  return get(Context, StackAlignment, Align);
136 }
137 
139  uint64_t Bytes) {
140  assert(Bytes && "Bytes must be non-zero.");
141  return get(Context, Dereferenceable, Bytes);
142 }
143 
145  uint64_t Bytes) {
146  assert(Bytes && "Bytes must be non-zero.");
147  return get(Context, DereferenceableOrNull, Bytes);
148 }
149 
150 Attribute
152  const Optional<unsigned> &NumElemsArg) {
153  assert(!(ElemSizeArg == 0 && NumElemsArg && *NumElemsArg == 0) &&
154  "Invalid allocsize arguments -- given allocsize(0, 0)");
155  return get(Context, AllocSize, packAllocSizeArgs(ElemSizeArg, NumElemsArg));
156 }
157 
158 //===----------------------------------------------------------------------===//
159 // Attribute Accessor Methods
160 //===----------------------------------------------------------------------===//
161 
163  return pImpl && pImpl->isEnumAttribute();
164 }
165 
167  return pImpl && pImpl->isIntAttribute();
168 }
169 
171  return pImpl && pImpl->isStringAttribute();
172 }
173 
175  if (!pImpl) return None;
177  "Invalid attribute type to get the kind as an enum!");
178  return pImpl->getKindAsEnum();
179 }
180 
181 uint64_t Attribute::getValueAsInt() const {
182  if (!pImpl) return 0;
184  "Expected the attribute to be an integer attribute!");
185  return pImpl->getValueAsInt();
186 }
187 
189  if (!pImpl) return {};
191  "Invalid attribute type to get the kind as a string!");
192  return pImpl->getKindAsString();
193 }
194 
196  if (!pImpl) return {};
198  "Invalid attribute type to get the value as a string!");
199  return pImpl->getValueAsString();
200 }
201 
203  return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None);
204 }
205 
207  if (!isStringAttribute()) return false;
208  return pImpl && pImpl->hasAttribute(Kind);
209 }
210 
211 unsigned Attribute::getAlignment() const {
212  assert(hasAttribute(Attribute::Alignment) &&
213  "Trying to get alignment from non-alignment attribute!");
214  return pImpl->getValueAsInt();
215 }
216 
218  assert(hasAttribute(Attribute::StackAlignment) &&
219  "Trying to get alignment from non-alignment attribute!");
220  return pImpl->getValueAsInt();
221 }
222 
224  assert(hasAttribute(Attribute::Dereferenceable) &&
225  "Trying to get dereferenceable bytes from "
226  "non-dereferenceable attribute!");
227  return pImpl->getValueAsInt();
228 }
229 
231  assert(hasAttribute(Attribute::DereferenceableOrNull) &&
232  "Trying to get dereferenceable bytes from "
233  "non-dereferenceable attribute!");
234  return pImpl->getValueAsInt();
235 }
236 
237 std::pair<unsigned, Optional<unsigned>> Attribute::getAllocSizeArgs() const {
238  assert(hasAttribute(Attribute::AllocSize) &&
239  "Trying to get allocsize args from non-allocsize attribute");
240  return unpackAllocSizeArgs(pImpl->getValueAsInt());
241 }
242 
243 std::string Attribute::getAsString(bool InAttrGrp) const {
244  if (!pImpl) return {};
245 
246  if (hasAttribute(Attribute::SanitizeAddress))
247  return "sanitize_address";
248  if (hasAttribute(Attribute::SanitizeHWAddress))
249  return "sanitize_hwaddress";
250  if (hasAttribute(Attribute::AlwaysInline))
251  return "alwaysinline";
252  if (hasAttribute(Attribute::ArgMemOnly))
253  return "argmemonly";
254  if (hasAttribute(Attribute::Builtin))
255  return "builtin";
256  if (hasAttribute(Attribute::ByVal))
257  return "byval";
259  return "convergent";
260  if (hasAttribute(Attribute::SwiftError))
261  return "swifterror";
262  if (hasAttribute(Attribute::SwiftSelf))
263  return "swiftself";
264  if (hasAttribute(Attribute::InaccessibleMemOnly))
265  return "inaccessiblememonly";
266  if (hasAttribute(Attribute::InaccessibleMemOrArgMemOnly))
267  return "inaccessiblemem_or_argmemonly";
268  if (hasAttribute(Attribute::InAlloca))
269  return "inalloca";
270  if (hasAttribute(Attribute::InlineHint))
271  return "inlinehint";
272  if (hasAttribute(Attribute::InReg))
273  return "inreg";
275  return "jumptable";
276  if (hasAttribute(Attribute::MinSize))
277  return "minsize";
278  if (hasAttribute(Attribute::Naked))
279  return "naked";
280  if (hasAttribute(Attribute::Nest))
281  return "nest";
283  return "noalias";
284  if (hasAttribute(Attribute::NoBuiltin))
285  return "nobuiltin";
286  if (hasAttribute(Attribute::NoCapture))
287  return "nocapture";
288  if (hasAttribute(Attribute::NoDuplicate))
289  return "noduplicate";
290  if (hasAttribute(Attribute::NoImplicitFloat))
291  return "noimplicitfloat";
292  if (hasAttribute(Attribute::NoInline))
293  return "noinline";
294  if (hasAttribute(Attribute::NonLazyBind))
295  return "nonlazybind";
296  if (hasAttribute(Attribute::NonNull))
297  return "nonnull";
298  if (hasAttribute(Attribute::NoRedZone))
299  return "noredzone";
300  if (hasAttribute(Attribute::NoReturn))
301  return "noreturn";
302  if (hasAttribute(Attribute::NoCfCheck))
303  return "nocf_check";
304  if (hasAttribute(Attribute::NoRecurse))
305  return "norecurse";
306  if (hasAttribute(Attribute::NoUnwind))
307  return "nounwind";
308  if (hasAttribute(Attribute::OptForFuzzing))
309  return "optforfuzzing";
310  if (hasAttribute(Attribute::OptimizeNone))
311  return "optnone";
312  if (hasAttribute(Attribute::OptimizeForSize))
313  return "optsize";
314  if (hasAttribute(Attribute::ReadNone))
315  return "readnone";
316  if (hasAttribute(Attribute::ReadOnly))
317  return "readonly";
318  if (hasAttribute(Attribute::WriteOnly))
319  return "writeonly";
320  if (hasAttribute(Attribute::Returned))
321  return "returned";
322  if (hasAttribute(Attribute::ReturnsTwice))
323  return "returns_twice";
324  if (hasAttribute(Attribute::SExt))
325  return "signext";
326  if (hasAttribute(Attribute::Speculatable))
327  return "speculatable";
328  if (hasAttribute(Attribute::StackProtect))
329  return "ssp";
330  if (hasAttribute(Attribute::StackProtectReq))
331  return "sspreq";
332  if (hasAttribute(Attribute::StackProtectStrong))
333  return "sspstrong";
334  if (hasAttribute(Attribute::SafeStack))
335  return "safestack";
336  if (hasAttribute(Attribute::ShadowCallStack))
337  return "shadowcallstack";
338  if (hasAttribute(Attribute::StrictFP))
339  return "strictfp";
340  if (hasAttribute(Attribute::StructRet))
341  return "sret";
342  if (hasAttribute(Attribute::SanitizeThread))
343  return "sanitize_thread";
344  if (hasAttribute(Attribute::SanitizeMemory))
345  return "sanitize_memory";
346  if (hasAttribute(Attribute::UWTable))
347  return "uwtable";
348  if (hasAttribute(Attribute::ZExt))
349  return "zeroext";
351  return "cold";
352 
353  // FIXME: These should be output like this:
354  //
355  // align=4
356  // alignstack=8
357  //
358  if (hasAttribute(Attribute::Alignment)) {
359  std::string Result;
360  Result += "align";
361  Result += (InAttrGrp) ? "=" : " ";
362  Result += utostr(getValueAsInt());
363  return Result;
364  }
365 
366  auto AttrWithBytesToString = [&](const char *Name) {
367  std::string Result;
368  Result += Name;
369  if (InAttrGrp) {
370  Result += "=";
371  Result += utostr(getValueAsInt());
372  } else {
373  Result += "(";
374  Result += utostr(getValueAsInt());
375  Result += ")";
376  }
377  return Result;
378  };
379 
380  if (hasAttribute(Attribute::StackAlignment))
381  return AttrWithBytesToString("alignstack");
382 
383  if (hasAttribute(Attribute::Dereferenceable))
384  return AttrWithBytesToString("dereferenceable");
385 
386  if (hasAttribute(Attribute::DereferenceableOrNull))
387  return AttrWithBytesToString("dereferenceable_or_null");
388 
389  if (hasAttribute(Attribute::AllocSize)) {
390  unsigned ElemSize;
391  Optional<unsigned> NumElems;
392  std::tie(ElemSize, NumElems) = getAllocSizeArgs();
393 
394  std::string Result = "allocsize(";
395  Result += utostr(ElemSize);
396  if (NumElems.hasValue()) {
397  Result += ',';
398  Result += utostr(*NumElems);
399  }
400  Result += ')';
401  return Result;
402  }
403 
404  // Convert target-dependent attributes to strings of the form:
405  //
406  // "kind"
407  // "kind" = "value"
408  //
409  if (isStringAttribute()) {
410  std::string Result;
411  Result += (Twine('"') + getKindAsString() + Twine('"')).str();
412 
413  std::string AttrVal = pImpl->getValueAsString();
414  if (AttrVal.empty()) return Result;
415 
416  // Since some attribute strings contain special characters that cannot be
417  // printable, those have to be escaped to make the attribute value printable
418  // as is. e.g. "\01__gnu_mcount_nc"
419  {
420  raw_string_ostream OS(Result);
421  OS << "=\"";
422  printEscapedString(AttrVal, OS);
423  OS << "\"";
424  }
425  return Result;
426  }
427 
428  llvm_unreachable("Unknown attribute");
429 }
430 
432  if (!pImpl && !A.pImpl) return false;
433  if (!pImpl) return true;
434  if (!A.pImpl) return false;
435  return *pImpl < *A.pImpl;
436 }
437 
438 //===----------------------------------------------------------------------===//
439 // AttributeImpl Definition
440 //===----------------------------------------------------------------------===//
441 
442 // Pin the vtables to this file.
444 
445 void EnumAttributeImpl::anchor() {}
446 
447 void IntAttributeImpl::anchor() {}
448 
449 void StringAttributeImpl::anchor() {}
450 
452  if (isStringAttribute()) return false;
453  return getKindAsEnum() == A;
454 }
455 
457  if (!isStringAttribute()) return false;
458  return getKindAsString() == Kind;
459 }
460 
463  return static_cast<const EnumAttributeImpl *>(this)->getEnumKind();
464 }
465 
468  return static_cast<const IntAttributeImpl *>(this)->getValue();
469 }
470 
473  return static_cast<const StringAttributeImpl *>(this)->getStringKind();
474 }
475 
478  return static_cast<const StringAttributeImpl *>(this)->getStringValue();
479 }
480 
482  // This sorts the attributes with Attribute::AttrKinds coming first (sorted
483  // relative to their enum value) and then strings.
484  if (isEnumAttribute()) {
485  if (AI.isEnumAttribute()) return getKindAsEnum() < AI.getKindAsEnum();
486  if (AI.isIntAttribute()) return true;
487  if (AI.isStringAttribute()) return true;
488  }
489 
490  if (isIntAttribute()) {
491  if (AI.isEnumAttribute()) return false;
492  if (AI.isIntAttribute()) {
493  if (getKindAsEnum() == AI.getKindAsEnum())
494  return getValueAsInt() < AI.getValueAsInt();
495  return getKindAsEnum() < AI.getKindAsEnum();
496  }
497  if (AI.isStringAttribute()) return true;
498  }
499 
500  if (AI.isEnumAttribute()) return false;
501  if (AI.isIntAttribute()) return false;
502  if (getKindAsString() == AI.getKindAsString())
503  return getValueAsString() < AI.getValueAsString();
504  return getKindAsString() < AI.getKindAsString();
505 }
506 
507 //===----------------------------------------------------------------------===//
508 // AttributeSet Definition
509 //===----------------------------------------------------------------------===//
510 
512  return AttributeSet(AttributeSetNode::get(C, B));
513 }
514 
516  return AttributeSet(AttributeSetNode::get(C, Attrs));
517 }
518 
520  Attribute::AttrKind Kind) const {
521  if (hasAttribute(Kind)) return *this;
522  AttrBuilder B;
523  B.addAttribute(Kind);
524  return addAttributes(C, AttributeSet::get(C, B));
525 }
526 
528  StringRef Value) const {
529  AttrBuilder B;
530  B.addAttribute(Kind, Value);
531  return addAttributes(C, AttributeSet::get(C, B));
532 }
533 
535  const AttributeSet AS) const {
536  if (!hasAttributes())
537  return AS;
538 
539  if (!AS.hasAttributes())
540  return *this;
541 
542  AttrBuilder B(AS);
543  for (const auto I : *this)
544  B.addAttribute(I);
545 
546  return get(C, B);
547 }
548 
550  Attribute::AttrKind Kind) const {
551  if (!hasAttribute(Kind)) return *this;
552  AttrBuilder B(*this);
553  B.removeAttribute(Kind);
554  return get(C, B);
555 }
556 
558  StringRef Kind) const {
559  if (!hasAttribute(Kind)) return *this;
560  AttrBuilder B(*this);
561  B.removeAttribute(Kind);
562  return get(C, B);
563 }
564 
566  const AttrBuilder &Attrs) const {
567  AttrBuilder B(*this);
568  B.remove(Attrs);
569  return get(C, B);
570 }
571 
573  return SetNode ? SetNode->getNumAttributes() : 0;
574 }
575 
577  return SetNode ? SetNode->hasAttribute(Kind) : false;
578 }
579 
581  return SetNode ? SetNode->hasAttribute(Kind) : false;
582 }
583 
585  return SetNode ? SetNode->getAttribute(Kind) : Attribute();
586 }
587 
589  return SetNode ? SetNode->getAttribute(Kind) : Attribute();
590 }
591 
592 unsigned AttributeSet::getAlignment() const {
593  return SetNode ? SetNode->getAlignment() : 0;
594 }
595 
597  return SetNode ? SetNode->getStackAlignment() : 0;
598 }
599 
601  return SetNode ? SetNode->getDereferenceableBytes() : 0;
602 }
603 
605  return SetNode ? SetNode->getDereferenceableOrNullBytes() : 0;
606 }
607 
608 std::pair<unsigned, Optional<unsigned>> AttributeSet::getAllocSizeArgs() const {
609  return SetNode ? SetNode->getAllocSizeArgs()
610  : std::pair<unsigned, Optional<unsigned>>(0, 0);
611 }
612 
613 std::string AttributeSet::getAsString(bool InAttrGrp) const {
614  return SetNode ? SetNode->getAsString(InAttrGrp) : "";
615 }
616 
618  return SetNode ? SetNode->begin() : nullptr;
619 }
620 
622  return SetNode ? SetNode->end() : nullptr;
623 }
624 
625 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
627  dbgs() << "AS =\n";
628  dbgs() << " { ";
629  dbgs() << getAsString(true) << " }\n";
630 }
631 #endif
632 
633 //===----------------------------------------------------------------------===//
634 // AttributeSetNode Definition
635 //===----------------------------------------------------------------------===//
636 
637 AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
638  : AvailableAttrs(0), NumAttrs(Attrs.size()) {
639  // There's memory after the node where we can store the entries in.
640  std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
641 
642  for (const auto I : *this) {
643  if (!I.isStringAttribute()) {
644  AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
645  }
646  }
647 }
648 
650  ArrayRef<Attribute> Attrs) {
651  if (Attrs.empty())
652  return nullptr;
653 
654  // Otherwise, build a key to look up the existing attributes.
655  LLVMContextImpl *pImpl = C.pImpl;
657 
658  SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
659  llvm::sort(SortedAttrs.begin(), SortedAttrs.end());
660 
661  for (const auto Attr : SortedAttrs)
662  Attr.Profile(ID);
663 
664  void *InsertPoint;
665  AttributeSetNode *PA =
666  pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint);
667 
668  // If we didn't find any existing attributes of the same shape then create a
669  // new one and insert it.
670  if (!PA) {
671  // Coallocate entries after the AttributeSetNode itself.
672  void *Mem = ::operator new(totalSizeToAlloc<Attribute>(SortedAttrs.size()));
673  PA = new (Mem) AttributeSetNode(SortedAttrs);
674  pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint);
675  }
676 
677  // Return the AttributeSetNode that we found or created.
678  return PA;
679 }
680 
682  // Add target-independent attributes.
686  if (!B.contains(Kind))
687  continue;
688 
689  Attribute Attr;
690  switch (Kind) {
691  case Attribute::Alignment:
693  break;
694  case Attribute::StackAlignment:
696  break;
697  case Attribute::Dereferenceable:
699  C, B.getDereferenceableBytes());
700  break;
701  case Attribute::DereferenceableOrNull:
704  break;
705  case Attribute::AllocSize: {
706  auto A = B.getAllocSizeArgs();
707  Attr = Attribute::getWithAllocSizeArgs(C, A.first, A.second);
708  break;
709  }
710  default:
711  Attr = Attribute::get(C, Kind);
712  }
713  Attrs.push_back(Attr);
714  }
715 
716  // Add target-dependent (string) attributes.
717  for (const auto &TDA : B.td_attrs())
718  Attrs.emplace_back(Attribute::get(C, TDA.first, TDA.second));
719 
720  return get(C, Attrs);
721 }
722 
724  for (const auto I : *this)
725  if (I.hasAttribute(Kind))
726  return true;
727  return false;
728 }
729 
731  if (hasAttribute(Kind)) {
732  for (const auto I : *this)
733  if (I.hasAttribute(Kind))
734  return I;
735  }
736  return {};
737 }
738 
740  for (const auto I : *this)
741  if (I.hasAttribute(Kind))
742  return I;
743  return {};
744 }
745 
747  for (const auto I : *this)
748  if (I.hasAttribute(Attribute::Alignment))
749  return I.getAlignment();
750  return 0;
751 }
752 
754  for (const auto I : *this)
755  if (I.hasAttribute(Attribute::StackAlignment))
756  return I.getStackAlignment();
757  return 0;
758 }
759 
761  for (const auto I : *this)
762  if (I.hasAttribute(Attribute::Dereferenceable))
763  return I.getDereferenceableBytes();
764  return 0;
765 }
766 
768  for (const auto I : *this)
769  if (I.hasAttribute(Attribute::DereferenceableOrNull))
770  return I.getDereferenceableOrNullBytes();
771  return 0;
772 }
773 
774 std::pair<unsigned, Optional<unsigned>>
776  for (const auto I : *this)
777  if (I.hasAttribute(Attribute::AllocSize))
778  return I.getAllocSizeArgs();
779  return std::make_pair(0, 0);
780 }
781 
782 std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
783  std::string Str;
784  for (iterator I = begin(), E = end(); I != E; ++I) {
785  if (I != begin())
786  Str += ' ';
787  Str += I->getAsString(InAttrGrp);
788  }
789  return Str;
790 }
791 
792 //===----------------------------------------------------------------------===//
793 // AttributeListImpl Definition
794 //===----------------------------------------------------------------------===//
795 
796 /// Map from AttributeList index to the internal array index. Adding one happens
797 /// to work, but it relies on unsigned integer wrapping. MSVC warns about
798 /// unsigned wrapping in constexpr functions, so write out the conditional. LLVM
799 /// folds it to add anyway.
800 static constexpr unsigned attrIdxToArrayIdx(unsigned Index) {
801  return Index == AttributeList::FunctionIndex ? 0 : Index + 1;
802 }
803 
806  : AvailableFunctionAttrs(0), Context(C), NumAttrSets(Sets.size()) {
807  assert(!Sets.empty() && "pointless AttributeListImpl");
808 
809  // There's memory after the node where we can store the entries in.
810  std::copy(Sets.begin(), Sets.end(), getTrailingObjects<AttributeSet>());
811 
812  // Initialize AvailableFunctionAttrs summary bitset.
813  static_assert(Attribute::EndAttrKinds <=
814  sizeof(AvailableFunctionAttrs) * CHAR_BIT,
815  "Too many attributes");
816  static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U,
817  "function should be stored in slot 0");
818  for (const auto I : Sets[0]) {
819  if (!I.isStringAttribute())
820  AvailableFunctionAttrs |= 1ULL << I.getKindAsEnum();
821  }
822 }
823 
825  Profile(ID, makeArrayRef(begin(), end()));
826 }
827 
829  ArrayRef<AttributeSet> Sets) {
830  for (const auto &Set : Sets)
831  ID.AddPointer(Set.SetNode);
832 }
833 
834 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
836  AttributeList(const_cast<AttributeListImpl *>(this)).dump();
837 }
838 #endif
839 
840 //===----------------------------------------------------------------------===//
841 // AttributeList Construction and Mutation Methods
842 //===----------------------------------------------------------------------===//
843 
845  ArrayRef<AttributeSet> AttrSets) {
846  assert(!AttrSets.empty() && "pointless AttributeListImpl");
847 
848  LLVMContextImpl *pImpl = C.pImpl;
850  AttributeListImpl::Profile(ID, AttrSets);
851 
852  void *InsertPoint;
853  AttributeListImpl *PA =
854  pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint);
855 
856  // If we didn't find any existing attributes of the same shape then
857  // create a new one and insert it.
858  if (!PA) {
859  // Coallocate entries after the AttributeListImpl itself.
860  void *Mem = ::operator new(
861  AttributeListImpl::totalSizeToAlloc<AttributeSet>(AttrSets.size()));
862  PA = new (Mem) AttributeListImpl(C, AttrSets);
863  pImpl->AttrsLists.InsertNode(PA, InsertPoint);
864  }
865 
866  // Return the AttributesList that we found or created.
867  return AttributeList(PA);
868 }
869 
872  ArrayRef<std::pair<unsigned, Attribute>> Attrs) {
873  // If there are no attributes then return a null AttributesList pointer.
874  if (Attrs.empty())
875  return {};
876 
877  assert(std::is_sorted(Attrs.begin(), Attrs.end(),
878  [](const std::pair<unsigned, Attribute> &LHS,
879  const std::pair<unsigned, Attribute> &RHS) {
880  return LHS.first < RHS.first;
881  }) && "Misordered Attributes list!");
882  assert(llvm::none_of(Attrs,
883  [](const std::pair<unsigned, Attribute> &Pair) {
884  return Pair.second.hasAttribute(Attribute::None);
885  }) &&
886  "Pointless attribute!");
887 
888  // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes
889  // list.
891  for (ArrayRef<std::pair<unsigned, Attribute>>::iterator I = Attrs.begin(),
892  E = Attrs.end(); I != E; ) {
893  unsigned Index = I->first;
895  while (I != E && I->first == Index) {
896  AttrVec.push_back(I->second);
897  ++I;
898  }
899 
900  AttrPairVec.emplace_back(Index, AttributeSet::get(C, AttrVec));
901  }
902 
903  return get(C, AttrPairVec);
904 }
905 
908  ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) {
909  // If there are no attributes then return a null AttributesList pointer.
910  if (Attrs.empty())
911  return {};
912 
913  assert(std::is_sorted(Attrs.begin(), Attrs.end(),
914  [](const std::pair<unsigned, AttributeSet> &LHS,
915  const std::pair<unsigned, AttributeSet> &RHS) {
916  return LHS.first < RHS.first;
917  }) &&
918  "Misordered Attributes list!");
919  assert(llvm::none_of(Attrs,
920  [](const std::pair<unsigned, AttributeSet> &Pair) {
921  return !Pair.second.hasAttributes();
922  }) &&
923  "Pointless attribute!");
924 
925  unsigned MaxIndex = Attrs.back().first;
926  // If the MaxIndex is FunctionIndex and there are other indices in front
927  // of it, we need to use the largest of those to get the right size.
928  if (MaxIndex == FunctionIndex && Attrs.size() > 1)
929  MaxIndex = Attrs[Attrs.size() - 2].first;
930 
931  SmallVector<AttributeSet, 4> AttrVec(attrIdxToArrayIdx(MaxIndex) + 1);
932  for (const auto Pair : Attrs)
933  AttrVec[attrIdxToArrayIdx(Pair.first)] = Pair.second;
934 
935  return getImpl(C, AttrVec);
936 }
937 
939  AttributeSet RetAttrs,
940  ArrayRef<AttributeSet> ArgAttrs) {
941  // Scan from the end to find the last argument with attributes. Most
942  // arguments don't have attributes, so it's nice if we can have fewer unique
943  // AttributeListImpls by dropping empty attribute sets at the end of the list.
944  unsigned NumSets = 0;
945  for (size_t I = ArgAttrs.size(); I != 0; --I) {
946  if (ArgAttrs[I - 1].hasAttributes()) {
947  NumSets = I + 2;
948  break;
949  }
950  }
951  if (NumSets == 0) {
952  // Check function and return attributes if we didn't have argument
953  // attributes.
954  if (RetAttrs.hasAttributes())
955  NumSets = 2;
956  else if (FnAttrs.hasAttributes())
957  NumSets = 1;
958  }
959 
960  // If all attribute sets were empty, we can use the empty attribute list.
961  if (NumSets == 0)
962  return {};
963 
965  AttrSets.reserve(NumSets);
966  // If we have any attributes, we always have function attributes.
967  AttrSets.push_back(FnAttrs);
968  if (NumSets > 1)
969  AttrSets.push_back(RetAttrs);
970  if (NumSets > 2) {
971  // Drop the empty argument attribute sets at the end.
972  ArgAttrs = ArgAttrs.take_front(NumSets - 2);
973  AttrSets.insert(AttrSets.end(), ArgAttrs.begin(), ArgAttrs.end());
974  }
975 
976  return getImpl(C, AttrSets);
977 }
978 
980  const AttrBuilder &B) {
981  if (!B.hasAttributes())
982  return {};
983  Index = attrIdxToArrayIdx(Index);
984  SmallVector<AttributeSet, 8> AttrSets(Index + 1);
985  AttrSets[Index] = AttributeSet::get(C, B);
986  return getImpl(C, AttrSets);
987 }
988 
992  for (const auto K : Kinds)
993  Attrs.emplace_back(Index, Attribute::get(C, K));
994  return get(C, Attrs);
995 }
996 
998  ArrayRef<StringRef> Kinds) {
1000  for (const auto K : Kinds)
1001  Attrs.emplace_back(Index, Attribute::get(C, K));
1002  return get(C, Attrs);
1003 }
1004 
1006  ArrayRef<AttributeList> Attrs) {
1007  if (Attrs.empty())
1008  return {};
1009  if (Attrs.size() == 1)
1010  return Attrs[0];
1011 
1012  unsigned MaxSize = 0;
1013  for (const auto List : Attrs)
1014  MaxSize = std::max(MaxSize, List.getNumAttrSets());
1015 
1016  // If every list was empty, there is no point in merging the lists.
1017  if (MaxSize == 0)
1018  return {};
1019 
1020  SmallVector<AttributeSet, 8> NewAttrSets(MaxSize);
1021  for (unsigned I = 0; I < MaxSize; ++I) {
1022  AttrBuilder CurBuilder;
1023  for (const auto List : Attrs)
1024  CurBuilder.merge(List.getAttributes(I - 1));
1025  NewAttrSets[I] = AttributeSet::get(C, CurBuilder);
1026  }
1027 
1028  return getImpl(C, NewAttrSets);
1029 }
1030 
1032  Attribute::AttrKind Kind) const {
1033  if (hasAttribute(Index, Kind)) return *this;
1034  AttrBuilder B;
1035  B.addAttribute(Kind);
1036  return addAttributes(C, Index, B);
1037 }
1038 
1040  StringRef Kind,
1041  StringRef Value) const {
1042  AttrBuilder B;
1043  B.addAttribute(Kind, Value);
1044  return addAttributes(C, Index, B);
1045 }
1046 
1048  Attribute A) const {
1049  AttrBuilder B;
1050  B.addAttribute(A);
1051  return addAttributes(C, Index, B);
1052 }
1053 
1055  const AttrBuilder &B) const {
1056  if (!B.hasAttributes())
1057  return *this;
1058 
1059  if (!pImpl)
1060  return AttributeList::get(C, {{Index, AttributeSet::get(C, B)}});
1061 
1062 #ifndef NDEBUG
1063  // FIXME it is not obvious how this should work for alignment. For now, say
1064  // we can't change a known alignment.
1065  unsigned OldAlign = getAttributes(Index).getAlignment();
1066  unsigned NewAlign = B.getAlignment();
1067  assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
1068  "Attempt to change alignment!");
1069 #endif
1070 
1071  Index = attrIdxToArrayIdx(Index);
1072  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1073  if (Index >= AttrSets.size())
1074  AttrSets.resize(Index + 1);
1075 
1076  AttrBuilder Merged(AttrSets[Index]);
1077  Merged.merge(B);
1078  AttrSets[Index] = AttributeSet::get(C, Merged);
1079 
1080  return getImpl(C, AttrSets);
1081 }
1082 
1084  ArrayRef<unsigned> ArgNos,
1085  Attribute A) const {
1086  assert(std::is_sorted(ArgNos.begin(), ArgNos.end()));
1087 
1088  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1089  unsigned MaxIndex = attrIdxToArrayIdx(ArgNos.back() + FirstArgIndex);
1090  if (MaxIndex >= AttrSets.size())
1091  AttrSets.resize(MaxIndex + 1);
1092 
1093  for (unsigned ArgNo : ArgNos) {
1094  unsigned Index = attrIdxToArrayIdx(ArgNo + FirstArgIndex);
1095  AttrBuilder B(AttrSets[Index]);
1096  B.addAttribute(A);
1097  AttrSets[Index] = AttributeSet::get(C, B);
1098  }
1099 
1100  return getImpl(C, AttrSets);
1101 }
1102 
1104  Attribute::AttrKind Kind) const {
1105  if (!hasAttribute(Index, Kind)) return *this;
1106 
1107  Index = attrIdxToArrayIdx(Index);
1108  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1109  assert(Index < AttrSets.size());
1110 
1111  AttrSets[Index] = AttrSets[Index].removeAttribute(C, Kind);
1112 
1113  return getImpl(C, AttrSets);
1114 }
1115 
1117  StringRef Kind) const {
1118  if (!hasAttribute(Index, Kind)) return *this;
1119 
1120  Index = attrIdxToArrayIdx(Index);
1121  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1122  assert(Index < AttrSets.size());
1123 
1124  AttrSets[Index] = AttrSets[Index].removeAttribute(C, Kind);
1125 
1126  return getImpl(C, AttrSets);
1127 }
1128 
1131  const AttrBuilder &AttrsToRemove) const {
1132  if (!pImpl)
1133  return {};
1134 
1135  Index = attrIdxToArrayIdx(Index);
1136  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1137  if (Index >= AttrSets.size())
1138  AttrSets.resize(Index + 1);
1139 
1140  AttrSets[Index] = AttrSets[Index].removeAttributes(C, AttrsToRemove);
1141 
1142  return getImpl(C, AttrSets);
1143 }
1144 
1146  unsigned WithoutIndex) const {
1147  if (!pImpl)
1148  return {};
1149  WithoutIndex = attrIdxToArrayIdx(WithoutIndex);
1150  if (WithoutIndex >= getNumAttrSets())
1151  return *this;
1152  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1153  AttrSets[WithoutIndex] = AttributeSet();
1154  return getImpl(C, AttrSets);
1155 }
1156 
1158  unsigned Index,
1159  uint64_t Bytes) const {
1160  AttrBuilder B;
1161  B.addDereferenceableAttr(Bytes);
1162  return addAttributes(C, Index, B);
1163 }
1164 
1167  uint64_t Bytes) const {
1168  AttrBuilder B;
1170  return addAttributes(C, Index, B);
1171 }
1172 
1175  unsigned ElemSizeArg,
1176  const Optional<unsigned> &NumElemsArg) {
1177  AttrBuilder B;
1178  B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1179  return addAttributes(C, Index, B);
1180 }
1181 
1182 //===----------------------------------------------------------------------===//
1183 // AttributeList Accessor Methods
1184 //===----------------------------------------------------------------------===//
1185 
1186 LLVMContext &AttributeList::getContext() const { return pImpl->getContext(); }
1187 
1189  return getAttributes(ArgNo + FirstArgIndex);
1190 }
1191 
1193  return getAttributes(ReturnIndex);
1194 }
1195 
1197  return getAttributes(FunctionIndex);
1198 }
1199 
1201  Attribute::AttrKind Kind) const {
1202  return getAttributes(Index).hasAttribute(Kind);
1203 }
1204 
1206  return getAttributes(Index).hasAttribute(Kind);
1207 }
1208 
1209 bool AttributeList::hasAttributes(unsigned Index) const {
1210  return getAttributes(Index).hasAttributes();
1211 }
1212 
1214  return pImpl && pImpl->hasFnAttribute(Kind);
1215 }
1216 
1218  return hasAttribute(AttributeList::FunctionIndex, Kind);
1219 }
1220 
1222  Attribute::AttrKind Kind) const {
1223  return hasAttribute(ArgNo + FirstArgIndex, Kind);
1224 }
1225 
1227  unsigned *Index) const {
1228  if (!pImpl) return false;
1229 
1230  for (unsigned I = index_begin(), E = index_end(); I != E; ++I) {
1231  if (hasAttribute(I, Attr)) {
1232  if (Index)
1233  *Index = I;
1234  return true;
1235  }
1236  }
1237 
1238  return false;
1239 }
1240 
1242  Attribute::AttrKind Kind) const {
1243  return getAttributes(Index).getAttribute(Kind);
1244 }
1245 
1247  return getAttributes(Index).getAttribute(Kind);
1248 }
1249 
1251  return getAttributes(ReturnIndex).getAlignment();
1252 }
1253 
1254 unsigned AttributeList::getParamAlignment(unsigned ArgNo) const {
1255  return getAttributes(ArgNo + FirstArgIndex).getAlignment();
1256 }
1257 
1258 unsigned AttributeList::getStackAlignment(unsigned Index) const {
1259  return getAttributes(Index).getStackAlignment();
1260 }
1261 
1263  return getAttributes(Index).getDereferenceableBytes();
1264 }
1265 
1268 }
1269 
1270 std::pair<unsigned, Optional<unsigned>>
1272  return getAttributes(Index).getAllocSizeArgs();
1273 }
1274 
1275 std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const {
1276  return getAttributes(Index).getAsString(InAttrGrp);
1277 }
1278 
1280  Index = attrIdxToArrayIdx(Index);
1281  if (!pImpl || Index >= getNumAttrSets())
1282  return {};
1283  return pImpl->begin()[Index];
1284 }
1285 
1287  return pImpl ? pImpl->begin() : nullptr;
1288 }
1289 
1291  return pImpl ? pImpl->end() : nullptr;
1292 }
1293 
1294 //===----------------------------------------------------------------------===//
1295 // AttributeList Introspection Methods
1296 //===----------------------------------------------------------------------===//
1297 
1299  return pImpl ? pImpl->NumAttrSets : 0;
1300 }
1301 
1302 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1304  dbgs() << "PAL[\n";
1305 
1306  for (unsigned i = index_begin(), e = index_end(); i != e; ++i) {
1307  if (getAttributes(i).hasAttributes())
1308  dbgs() << " { " << i << " => " << getAsString(i) << " }\n";
1309  }
1310 
1311  dbgs() << "]\n";
1312 }
1313 #endif
1314 
1315 //===----------------------------------------------------------------------===//
1316 // AttrBuilder Method Implementations
1317 //===----------------------------------------------------------------------===//
1318 
1319 // FIXME: Remove this ctor, use AttributeSet.
1321  AttributeSet AS = AL.getAttributes(Index);
1322  for (const auto &A : AS)
1323  addAttribute(A);
1324 }
1325 
1327  for (const auto &A : AS)
1328  addAttribute(A);
1329 }
1330 
1332  Attrs.reset();
1333  TargetDepAttrs.clear();
1334  Alignment = StackAlignment = DerefBytes = DerefOrNullBytes = 0;
1335  AllocSizeArgs = 0;
1336 }
1337 
1339  assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1340  assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
1341  Val != Attribute::Dereferenceable && Val != Attribute::AllocSize &&
1342  "Adding integer attribute without adding a value!");
1343  Attrs[Val] = true;
1344  return *this;
1345 }
1346 
1348  if (Attr.isStringAttribute()) {
1349  addAttribute(Attr.getKindAsString(), Attr.getValueAsString());
1350  return *this;
1351  }
1352 
1354  Attrs[Kind] = true;
1355 
1356  if (Kind == Attribute::Alignment)
1357  Alignment = Attr.getAlignment();
1358  else if (Kind == Attribute::StackAlignment)
1359  StackAlignment = Attr.getStackAlignment();
1360  else if (Kind == Attribute::Dereferenceable)
1361  DerefBytes = Attr.getDereferenceableBytes();
1362  else if (Kind == Attribute::DereferenceableOrNull)
1363  DerefOrNullBytes = Attr.getDereferenceableOrNullBytes();
1364  else if (Kind == Attribute::AllocSize)
1365  AllocSizeArgs = Attr.getValueAsInt();
1366  return *this;
1367 }
1368 
1370  TargetDepAttrs[A] = V;
1371  return *this;
1372 }
1373 
1375  assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1376  Attrs[Val] = false;
1377 
1378  if (Val == Attribute::Alignment)
1379  Alignment = 0;
1380  else if (Val == Attribute::StackAlignment)
1381  StackAlignment = 0;
1382  else if (Val == Attribute::Dereferenceable)
1383  DerefBytes = 0;
1384  else if (Val == Attribute::DereferenceableOrNull)
1385  DerefOrNullBytes = 0;
1386  else if (Val == Attribute::AllocSize)
1387  AllocSizeArgs = 0;
1388 
1389  return *this;
1390 }
1391 
1393  remove(A.getAttributes(Index));
1394  return *this;
1395 }
1396 
1398  auto I = TargetDepAttrs.find(A);
1399  if (I != TargetDepAttrs.end())
1400  TargetDepAttrs.erase(I);
1401  return *this;
1402 }
1403 
1404 std::pair<unsigned, Optional<unsigned>> AttrBuilder::getAllocSizeArgs() const {
1405  return unpackAllocSizeArgs(AllocSizeArgs);
1406 }
1407 
1409  if (Align == 0) return *this;
1410 
1411  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
1412  assert(Align <= 0x40000000 && "Alignment too large.");
1413 
1414  Attrs[Attribute::Alignment] = true;
1415  Alignment = Align;
1416  return *this;
1417 }
1418 
1420  // Default alignment, allow the target to define how to align it.
1421  if (Align == 0) return *this;
1422 
1423  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
1424  assert(Align <= 0x100 && "Alignment too large.");
1425 
1426  Attrs[Attribute::StackAlignment] = true;
1427  StackAlignment = Align;
1428  return *this;
1429 }
1430 
1432  if (Bytes == 0) return *this;
1433 
1434  Attrs[Attribute::Dereferenceable] = true;
1435  DerefBytes = Bytes;
1436  return *this;
1437 }
1438 
1440  if (Bytes == 0)
1441  return *this;
1442 
1443  Attrs[Attribute::DereferenceableOrNull] = true;
1444  DerefOrNullBytes = Bytes;
1445  return *this;
1446 }
1447 
1449  const Optional<unsigned> &NumElems) {
1450  return addAllocSizeAttrFromRawRepr(packAllocSizeArgs(ElemSize, NumElems));
1451 }
1452 
1454  // (0, 0) is our "not present" value, so we need to check for it here.
1455  assert(RawArgs && "Invalid allocsize arguments -- given allocsize(0, 0)");
1456 
1457  Attrs[Attribute::AllocSize] = true;
1458  // Reuse existing machinery to store this as a single 64-bit integer so we can
1459  // save a few bytes over using a pair<unsigned, Optional<unsigned>>.
1460  AllocSizeArgs = RawArgs;
1461  return *this;
1462 }
1463 
1465  // FIXME: What if both have alignments, but they don't match?!
1466  if (!Alignment)
1467  Alignment = B.Alignment;
1468 
1469  if (!StackAlignment)
1470  StackAlignment = B.StackAlignment;
1471 
1472  if (!DerefBytes)
1473  DerefBytes = B.DerefBytes;
1474 
1475  if (!DerefOrNullBytes)
1476  DerefOrNullBytes = B.DerefOrNullBytes;
1477 
1478  if (!AllocSizeArgs)
1479  AllocSizeArgs = B.AllocSizeArgs;
1480 
1481  Attrs |= B.Attrs;
1482 
1483  for (auto I : B.td_attrs())
1484  TargetDepAttrs[I.first] = I.second;
1485 
1486  return *this;
1487 }
1488 
1490  // FIXME: What if both have alignments, but they don't match?!
1491  if (B.Alignment)
1492  Alignment = 0;
1493 
1494  if (B.StackAlignment)
1495  StackAlignment = 0;
1496 
1497  if (B.DerefBytes)
1498  DerefBytes = 0;
1499 
1500  if (B.DerefOrNullBytes)
1501  DerefOrNullBytes = 0;
1502 
1503  if (B.AllocSizeArgs)
1504  AllocSizeArgs = 0;
1505 
1506  Attrs &= ~B.Attrs;
1507 
1508  for (auto I : B.td_attrs())
1509  TargetDepAttrs.erase(I.first);
1510 
1511  return *this;
1512 }
1513 
1515  // First check if any of the target independent attributes overlap.
1516  if ((Attrs & B.Attrs).any())
1517  return true;
1518 
1519  // Then check if any target dependent ones do.
1520  for (const auto &I : td_attrs())
1521  if (B.contains(I.first))
1522  return true;
1523 
1524  return false;
1525 }
1526 
1528  return TargetDepAttrs.find(A) != TargetDepAttrs.end();
1529 }
1530 
1532  return !Attrs.none() || !TargetDepAttrs.empty();
1533 }
1534 
1536  AttributeSet AS = AL.getAttributes(Index);
1537 
1538  for (const auto Attr : AS) {
1539  if (Attr.isEnumAttribute() || Attr.isIntAttribute()) {
1540  if (contains(Attr.getKindAsEnum()))
1541  return true;
1542  } else {
1543  assert(Attr.isStringAttribute() && "Invalid attribute kind!");
1544  return contains(Attr.getKindAsString());
1545  }
1546  }
1547 
1548  return false;
1549 }
1550 
1552  return Alignment != 0;
1553 }
1554 
1556  if (Attrs != B.Attrs)
1557  return false;
1558 
1559  for (td_const_iterator I = TargetDepAttrs.begin(),
1560  E = TargetDepAttrs.end(); I != E; ++I)
1561  if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end())
1562  return false;
1563 
1564  return Alignment == B.Alignment && StackAlignment == B.StackAlignment &&
1565  DerefBytes == B.DerefBytes;
1566 }
1567 
1568 //===----------------------------------------------------------------------===//
1569 // AttributeFuncs Function Defintions
1570 //===----------------------------------------------------------------------===//
1571 
1572 /// Which attributes cannot be applied to a type.
1574  AttrBuilder Incompatible;
1575 
1576  if (!Ty->isIntegerTy())
1577  // Attribute that only apply to integers.
1578  Incompatible.addAttribute(Attribute::SExt)
1579  .addAttribute(Attribute::ZExt);
1580 
1581  if (!Ty->isPointerTy())
1582  // Attribute that only apply to pointers.
1583  Incompatible.addAttribute(Attribute::ByVal)
1584  .addAttribute(Attribute::Nest)
1586  .addAttribute(Attribute::NoCapture)
1587  .addAttribute(Attribute::NonNull)
1588  .addDereferenceableAttr(1) // the int here is ignored
1589  .addDereferenceableOrNullAttr(1) // the int here is ignored
1590  .addAttribute(Attribute::ReadNone)
1591  .addAttribute(Attribute::ReadOnly)
1592  .addAttribute(Attribute::StructRet)
1593  .addAttribute(Attribute::InAlloca);
1594 
1595  return Incompatible;
1596 }
1597 
1598 template<typename AttrClass>
1599 static bool isEqual(const Function &Caller, const Function &Callee) {
1600  return Caller.getFnAttribute(AttrClass::getKind()) ==
1601  Callee.getFnAttribute(AttrClass::getKind());
1602 }
1603 
1604 /// Compute the logical AND of the attributes of the caller and the
1605 /// callee.
1606 ///
1607 /// This function sets the caller's attribute to false if the callee's attribute
1608 /// is false.
1609 template<typename AttrClass>
1610 static void setAND(Function &Caller, const Function &Callee) {
1611  if (AttrClass::isSet(Caller, AttrClass::getKind()) &&
1612  !AttrClass::isSet(Callee, AttrClass::getKind()))
1613  AttrClass::set(Caller, AttrClass::getKind(), false);
1614 }
1615 
1616 /// Compute the logical OR of the attributes of the caller and the
1617 /// callee.
1618 ///
1619 /// This function sets the caller's attribute to true if the callee's attribute
1620 /// is true.
1621 template<typename AttrClass>
1622 static void setOR(Function &Caller, const Function &Callee) {
1623  if (!AttrClass::isSet(Caller, AttrClass::getKind()) &&
1624  AttrClass::isSet(Callee, AttrClass::getKind()))
1625  AttrClass::set(Caller, AttrClass::getKind(), true);
1626 }
1627 
1628 /// If the inlined function had a higher stack protection level than the
1629 /// calling function, then bump up the caller's stack protection level.
1630 static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) {
1631  // If upgrading the SSP attribute, clear out the old SSP Attributes first.
1632  // Having multiple SSP attributes doesn't actually hurt, but it adds useless
1633  // clutter to the IR.
1634  AttrBuilder OldSSPAttr;
1635  OldSSPAttr.addAttribute(Attribute::StackProtect)
1636  .addAttribute(Attribute::StackProtectStrong)
1637  .addAttribute(Attribute::StackProtectReq);
1638 
1639  if (Callee.hasFnAttribute(Attribute::StackProtectReq)) {
1640  Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
1641  Caller.addFnAttr(Attribute::StackProtectReq);
1642  } else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
1643  !Caller.hasFnAttribute(Attribute::StackProtectReq)) {
1644  Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
1645  Caller.addFnAttr(Attribute::StackProtectStrong);
1646  } else if (Callee.hasFnAttribute(Attribute::StackProtect) &&
1647  !Caller.hasFnAttribute(Attribute::StackProtectReq) &&
1648  !Caller.hasFnAttribute(Attribute::StackProtectStrong))
1649  Caller.addFnAttr(Attribute::StackProtect);
1650 }
1651 
1652 /// If the inlined function required stack probes, then ensure that
1653 /// the calling function has those too.
1654 static void adjustCallerStackProbes(Function &Caller, const Function &Callee) {
1655  if (!Caller.hasFnAttribute("probe-stack") &&
1656  Callee.hasFnAttribute("probe-stack")) {
1657  Caller.addFnAttr(Callee.getFnAttribute("probe-stack"));
1658  }
1659 }
1660 
1661 /// If the inlined function defines the size of guard region
1662 /// on the stack, then ensure that the calling function defines a guard region
1663 /// that is no larger.
1664 static void
1666  if (Callee.hasFnAttribute("stack-probe-size")) {
1667  uint64_t CalleeStackProbeSize;
1668  Callee.getFnAttribute("stack-probe-size")
1669  .getValueAsString()
1670  .getAsInteger(0, CalleeStackProbeSize);
1671  if (Caller.hasFnAttribute("stack-probe-size")) {
1672  uint64_t CallerStackProbeSize;
1673  Caller.getFnAttribute("stack-probe-size")
1674  .getValueAsString()
1675  .getAsInteger(0, CallerStackProbeSize);
1676  if (CallerStackProbeSize > CalleeStackProbeSize) {
1677  Caller.addFnAttr(Callee.getFnAttribute("stack-probe-size"));
1678  }
1679  } else {
1680  Caller.addFnAttr(Callee.getFnAttribute("stack-probe-size"));
1681  }
1682  }
1683 }
1684 
1685 /// If the inlined function defines a min legal vector width, then ensure
1686 /// the calling function has the same or larger min legal vector width. This
1687 /// function is called after the inlining decision has been made so we have to
1688 /// merge the attribute this way. Heuristics that would use
1689 /// min-legal-vector-width to determine inline compatibility would need to be
1690 /// handled as part of inline cost analysis.
1691 static void
1693  if (Callee.hasFnAttribute("min-legal-vector-width")) {
1694  uint64_t CalleeVectorWidth;
1695  Callee.getFnAttribute("min-legal-vector-width")
1696  .getValueAsString()
1697  .getAsInteger(0, CalleeVectorWidth);
1698  if (Caller.hasFnAttribute("min-legal-vector-width")) {
1699  uint64_t CallerVectorWidth;
1700  Caller.getFnAttribute("min-legal-vector-width")
1701  .getValueAsString()
1702  .getAsInteger(0, CallerVectorWidth);
1703  if (CallerVectorWidth < CalleeVectorWidth) {
1704  Caller.addFnAttr(Callee.getFnAttribute("min-legal-vector-width"));
1705  }
1706  } else {
1707  Caller.addFnAttr(Callee.getFnAttribute("min-legal-vector-width"));
1708  }
1709  }
1710 }
1711 
1712 /// If the inlined function has "null-pointer-is-valid=true" attribute,
1713 /// set this attribute in the caller post inlining.
1714 static void
1716  if (Callee.nullPointerIsDefined() && !Caller.nullPointerIsDefined()) {
1717  Caller.addFnAttr(Callee.getFnAttribute("null-pointer-is-valid"));
1718  }
1719 }
1720 
1721 #define GET_ATTR_COMPAT_FUNC
1722 #include "AttributesCompatFunc.inc"
1723 
1725  const Function &Callee) {
1726  return hasCompatibleFnAttrs(Caller, Callee);
1727 }
1728 
1730  const Function &Callee) {
1731  mergeFnAttrs(Caller, Callee);
1732 }
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Retrieve the allocsize args, if the allocsize attribute exists.
uint64_t CallInst * C
unsigned getStackAlignment() const
Definition: Attributes.cpp:753
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
Definition: FoldingSet.cpp:52
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:259
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static constexpr unsigned attrIdxToArrayIdx(unsigned Index)
Map from AttributeList index to the internal array index.
Definition: Attributes.cpp:800
StringRef getKindAsString() const
Return the attribute&#39;s kind as a string.
Definition: Attributes.cpp:188
bool hasAttribute(Attribute::AttrKind A) const
Definition: Attributes.cpp:451
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:212
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Definition: Attributes.cpp:608
LLVMContext & Context
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:158
FoldingSet< AttributeImpl > AttrsSet
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:250
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...
static std::pair< unsigned, Optional< unsigned > > unpackAllocSizeArgs(uint64_t Num)
Definition: Attributes.cpp:71
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute...
Definition: Attributes.cpp:230
unsigned getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:217
static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:125
iterator begin() const
Definition: ArrayRef.h:137
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:138
unsigned getAlignment() const
Definition: Attributes.cpp:746
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:190
iterator begin() const
The two locations do not alias at all.
Definition: AliasAnalysis.h:85
void printEscapedString(StringRef Name, raw_ostream &Out)
Print each character of the specified string, escaping it if it is not printable or if it is an escap...
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Attributes.cpp:730
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:307
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
static AttributeSetNode * get(LLVMContext &C, const AttrBuilder &B)
Definition: Attributes.cpp:681
AttributeListImpl(LLVMContext &C, ArrayRef< AttributeSet > Sets)
Definition: Attributes.cpp:804
unsigned getRetAlignment() const
Return the alignment of the return value.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:452
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
std::string getAsString(bool InAttrGrp) const
Definition: Attributes.cpp:782
void reserve(size_type N)
Definition: SmallVector.h:376
uint64_t getDereferenceableBytes() const
Definition: Attributes.cpp:760
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
return AArch64::GPR64RegClass contains(Reg)
void Profile(FoldingSetNodeID &ID) const
Definition: Attributes.cpp:824
bool areInlineCompatible(const Function &Caller, const Function &Callee)
bool operator<(Attribute A) const
Less-than operator. Useful for sorting the attributes list.
Definition: Attributes.cpp:431
uint64_t getDereferenceableOrNullBytes() const
Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists...
Definition: Attributes.h:763
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:604
bool hasAttributes() const
Return true if the builder has IR-level attributes.
bool hasAlignmentAttr() const
Return true if the builder has an alignment attribute.
uint64_t getValueAsInt() const
Return the attribute&#39;s value as an integer.
Definition: Attributes.cpp:181
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:170
uint64_t getDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown).
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
Definition: Attributes.h:397
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:144
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:1044
bool isIntAttribute() const
Definition: AttributeImpl.h:58
AttrBuilder & addAllocSizeAttr(unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
This turns one (or two) ints into the form used internally in Attribute.
This file contains the simple types necessary to represent the attributes associated with functions a...
No attributes have been set.
Definition: Attributes.h:72
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
void AddInteger(signed I)
Definition: FoldingSet.cpp:61
iterator begin() const
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
LLVMContext & getContext() const
Retrieve the LLVM context.
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
unsigned getStackAlignment() const
Definition: Attributes.cpp:596
uint64_t getStackAlignment() const
Retrieve the stack alignment attribute, if it exists.
Definition: Attributes.h:755
iterator end() const
static bool isEqual(const Function &Caller, const Function &Callee)
AttributeList removeAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const
Remove the specified attributes at the specified index from this attribute list.
iterator end() const
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
uint64_t getDereferenceableOrNullBytes(unsigned Index) const
Get the number of dereferenceable_or_null bytes (or zero if unknown).
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Definition: Attributes.cpp:775
AttrBuilder & remove(const AttrBuilder &B)
Remove the attributes from the builder.
AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const
Add attributes to the attribute set.
Definition: Attributes.cpp:534
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:237
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttrBuilder & addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr)
Add an allocsize attribute, using the representation returned by Attribute.getIntValue().
uint64_t getDereferenceableBytes() const
Returns the number of dereferenceable bytes from the dereferenceable attribute.
Definition: Attributes.cpp:223
amdgpu Simplify well known AMD library false Value * Callee
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Definition: Attributes.cpp:576
static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align)
Definition: Attributes.cpp:131
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:306
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...
unsigned getStackAlignment(unsigned Index) const
Get the stack alignment.
bool operator==(const AttrBuilder &B)
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:202
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
AttributeList addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given index.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
Definition: Attributes.cpp:511
std::map< std::string, std::string >::const_iterator td_const_iterator
Definition: Attributes.h:800
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:429
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
static void adjustCallerStackProbes(Function &Caller, const Function &Callee)
If the inlined function required stack probes, then ensure that the calling function has those too...
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool isStringAttribute() const
Definition: AttributeImpl.h:59
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:224
AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
Definition: Attributes.cpp:549
uint64_t getAlignment() const
Retrieve the alignment attribute, if it exists.
Definition: Attributes.h:752
AttributeList addAllocSizeAttr(LLVMContext &C, unsigned Index, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Add the allocsize attribute to the attribute set at the given index.
static const unsigned AllocSizeNumElemsNotPresent
Definition: Attributes.cpp:58
unsigned getNumAttributes() const
Return the number of attributes in this set.
Definition: Attributes.cpp:572
iterator begin() const
Definition: Attributes.cpp:617
This file defines various helper methods and classes used by LLVMContextImpl for creating and managin...
Attribute::AttrKind getKindAsEnum() const
Return the attribute&#39;s kind as an enum (Attribute::AttrKind).
Definition: Attributes.cpp:174
bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
Definition: Attributes.cpp:162
Attribute::AttrKind getKindAsEnum() const
Definition: Attributes.cpp:461
Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
Definition: Attributes.cpp:584
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
Sentinal value useful for loops.
Definition: Attributes.h:75
static void setAND(Function &Caller, const Function &Callee)
Compute the logical AND of the attributes of the caller and the callee.
bool operator<(const AttributeImpl &AI) const
Used when sorting the attributes.
Definition: Attributes.cpp:481
const AMDGPUAS & AS
uint64_t getDereferenceableBytes() const
Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is return...
Definition: Attributes.h:759
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
uint64_t getDereferenceableBytes() const
Definition: Attributes.cpp:600
size_t size() const
Definition: SmallVector.h:53
StringRef getKindAsString() const
Definition: Attributes.cpp:471
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:71
AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
Definition: Attributes.cpp:519
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:969
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:497
static void adjustCallerSSPLevel(Function &Caller, const Function &Callee)
If the inlined function had a higher stack protection level than the calling function, then bump up the caller&#39;s stack protection level.
std::string getAsString(bool InAttrGrp=false) const
Definition: Attributes.cpp:613
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1011
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
Definition: Attributes.h:732
unsigned getAlignment() const
Definition: Attributes.cpp:592
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
AttrBuilder & removeAttributes(AttributeList A, uint64_t WithoutIndex)
Remove the attributes from the builder.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs(unsigned Index) const
Get the allocsize argument numbers (or pair(0, 0) if unknown).
bool overlaps(const AttrBuilder &B) const
Return true if the builder has any attribute that&#39;s in the specified builder.
iterator end() const
Definition: ArrayRef.h:138
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:223
static void adjustNullPointerValidAttr(Function &Caller, const Function &Callee)
If the inlined function has "null-pointer-is-valid=true" attribute, set this attribute in the caller ...
static void setOR(Function &Caller, const Function &Callee)
Compute the logical OR of the attributes of the caller and the callee.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller&#39;s and callee&#39;s attributes.
unsigned getNumAttrSets() const
bool isEnumAttribute() const
Definition: AttributeImpl.h:57
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:478
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:767
bool isIntAttribute() const
Return true if the attribute is an integer attribute.
Definition: Attributes.cpp:166
bool hasAttribute(Attribute::AttrKind Kind) const
void removeAttributes(unsigned i, const AttrBuilder &Attrs)
removes the attributes from the list of attributes.
Definition: Function.cpp:403
bool hasValue() const
Definition: Optional.h:183
unsigned getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:133
AttributeList addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
iterator end() const
Definition: Attributes.cpp:621
unsigned getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:211
AttributeList addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
void emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:652
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:195
AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
const NodeList & List
Definition: RDFGraph.cpp:210
#define I(x, y, z)
Definition: MD5.cpp:58
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:151
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
friend class AttributeList
void AddString(StringRef String)
Definition: FoldingSet.cpp:87
uint64_t getValueAsInt() const
Definition: Attributes.cpp:466
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:81
StringRef getValueAsString() const
Definition: Attributes.cpp:476
Attribute()=default
td_range td_attrs()
Definition: Attributes.h:810
AttributeSet removeAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const
Remove the specified attributes from this set.
Definition: Attributes.cpp:565
AttributeList addAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
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...
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
Definition: Attributes.cpp:243
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
const unsigned Kind
bool hasFnAttribute(Attribute::AttrKind Kind) const
Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but may be faster. ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasAttributes() const
Return true if attributes exists in this set.
Definition: Attributes.h:261
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:477
void dump() const
Definition: Attributes.cpp:626
LLVM Value Representation.
Definition: Value.h:73
virtual ~AttributeImpl()
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
AttributeSet getFnAttributes() const
The function attributes are returned.
AttrBuilder & addStackAlignmentAttr(unsigned Align)
This turns an int stack alignment (which must be a power of 2) into the form used internally in Attri...
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:317
FoldingSet< AttributeSetNode > AttrsSetNodes
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.h:216
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute...
static uint64_t packAllocSizeArgs(unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:60
bool nullPointerIsDefined() const
Check if null pointer dereferencing is considered undefined behavior for the function.
Definition: Function.cpp:1420
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1082
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Definition: Attributes.cpp:871
AttrBuilder()=default
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:70
void resize(size_type N)
Definition: SmallVector.h:351