LLVM  6.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 // \brief 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/IR/Function.h"
28 #include "llvm/IR/LLVMContext.h"
29 #include "llvm/IR/Type.h"
30 #include "llvm/Support/Compiler.h"
31 #include "llvm/Support/Debug.h"
35 #include <algorithm>
36 #include <cassert>
37 #include <climits>
38 #include <cstddef>
39 #include <cstdint>
40 #include <limits>
41 #include <map>
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 StringRef();
191  "Invalid attribute type to get the kind as a string!");
192  return pImpl->getKindAsString();
193 }
194 
196  if (!pImpl) return StringRef();
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::AlwaysInline))
249  return "alwaysinline";
250  if (hasAttribute(Attribute::ArgMemOnly))
251  return "argmemonly";
252  if (hasAttribute(Attribute::Builtin))
253  return "builtin";
254  if (hasAttribute(Attribute::ByVal))
255  return "byval";
257  return "convergent";
258  if (hasAttribute(Attribute::SwiftError))
259  return "swifterror";
260  if (hasAttribute(Attribute::SwiftSelf))
261  return "swiftself";
262  if (hasAttribute(Attribute::InaccessibleMemOnly))
263  return "inaccessiblememonly";
264  if (hasAttribute(Attribute::InaccessibleMemOrArgMemOnly))
265  return "inaccessiblemem_or_argmemonly";
266  if (hasAttribute(Attribute::InAlloca))
267  return "inalloca";
268  if (hasAttribute(Attribute::InlineHint))
269  return "inlinehint";
270  if (hasAttribute(Attribute::InReg))
271  return "inreg";
273  return "jumptable";
274  if (hasAttribute(Attribute::MinSize))
275  return "minsize";
276  if (hasAttribute(Attribute::Naked))
277  return "naked";
278  if (hasAttribute(Attribute::Nest))
279  return "nest";
281  return "noalias";
282  if (hasAttribute(Attribute::NoBuiltin))
283  return "nobuiltin";
284  if (hasAttribute(Attribute::NoCapture))
285  return "nocapture";
286  if (hasAttribute(Attribute::NoDuplicate))
287  return "noduplicate";
288  if (hasAttribute(Attribute::NoImplicitFloat))
289  return "noimplicitfloat";
290  if (hasAttribute(Attribute::NoInline))
291  return "noinline";
292  if (hasAttribute(Attribute::NonLazyBind))
293  return "nonlazybind";
294  if (hasAttribute(Attribute::NonNull))
295  return "nonnull";
296  if (hasAttribute(Attribute::NoRedZone))
297  return "noredzone";
298  if (hasAttribute(Attribute::NoReturn))
299  return "noreturn";
300  if (hasAttribute(Attribute::NoRecurse))
301  return "norecurse";
302  if (hasAttribute(Attribute::NoUnwind))
303  return "nounwind";
304  if (hasAttribute(Attribute::OptimizeNone))
305  return "optnone";
306  if (hasAttribute(Attribute::OptimizeForSize))
307  return "optsize";
308  if (hasAttribute(Attribute::ReadNone))
309  return "readnone";
310  if (hasAttribute(Attribute::ReadOnly))
311  return "readonly";
312  if (hasAttribute(Attribute::WriteOnly))
313  return "writeonly";
314  if (hasAttribute(Attribute::Returned))
315  return "returned";
316  if (hasAttribute(Attribute::ReturnsTwice))
317  return "returns_twice";
318  if (hasAttribute(Attribute::SExt))
319  return "signext";
320  if (hasAttribute(Attribute::Speculatable))
321  return "speculatable";
322  if (hasAttribute(Attribute::StackProtect))
323  return "ssp";
324  if (hasAttribute(Attribute::StackProtectReq))
325  return "sspreq";
326  if (hasAttribute(Attribute::StackProtectStrong))
327  return "sspstrong";
328  if (hasAttribute(Attribute::SafeStack))
329  return "safestack";
330  if (hasAttribute(Attribute::StructRet))
331  return "sret";
332  if (hasAttribute(Attribute::SanitizeThread))
333  return "sanitize_thread";
334  if (hasAttribute(Attribute::SanitizeMemory))
335  return "sanitize_memory";
336  if (hasAttribute(Attribute::UWTable))
337  return "uwtable";
338  if (hasAttribute(Attribute::ZExt))
339  return "zeroext";
341  return "cold";
342 
343  // FIXME: These should be output like this:
344  //
345  // align=4
346  // alignstack=8
347  //
348  if (hasAttribute(Attribute::Alignment)) {
349  std::string Result;
350  Result += "align";
351  Result += (InAttrGrp) ? "=" : " ";
352  Result += utostr(getValueAsInt());
353  return Result;
354  }
355 
356  auto AttrWithBytesToString = [&](const char *Name) {
357  std::string Result;
358  Result += Name;
359  if (InAttrGrp) {
360  Result += "=";
361  Result += utostr(getValueAsInt());
362  } else {
363  Result += "(";
364  Result += utostr(getValueAsInt());
365  Result += ")";
366  }
367  return Result;
368  };
369 
370  if (hasAttribute(Attribute::StackAlignment))
371  return AttrWithBytesToString("alignstack");
372 
373  if (hasAttribute(Attribute::Dereferenceable))
374  return AttrWithBytesToString("dereferenceable");
375 
376  if (hasAttribute(Attribute::DereferenceableOrNull))
377  return AttrWithBytesToString("dereferenceable_or_null");
378 
379  if (hasAttribute(Attribute::AllocSize)) {
380  unsigned ElemSize;
381  Optional<unsigned> NumElems;
382  std::tie(ElemSize, NumElems) = getAllocSizeArgs();
383 
384  std::string Result = "allocsize(";
385  Result += utostr(ElemSize);
386  if (NumElems.hasValue()) {
387  Result += ',';
388  Result += utostr(*NumElems);
389  }
390  Result += ')';
391  return Result;
392  }
393 
394  // Convert target-dependent attributes to strings of the form:
395  //
396  // "kind"
397  // "kind" = "value"
398  //
399  if (isStringAttribute()) {
400  std::string Result;
401  Result += (Twine('"') + getKindAsString() + Twine('"')).str();
402 
403  std::string AttrVal = pImpl->getValueAsString();
404  if (AttrVal.empty()) return Result;
405 
406  // Since some attribute strings contain special characters that cannot be
407  // printable, those have to be escaped to make the attribute value printable
408  // as is. e.g. "\01__gnu_mcount_nc"
409  {
410  raw_string_ostream OS(Result);
411  OS << "=\"";
412  PrintEscapedString(AttrVal, OS);
413  OS << "\"";
414  }
415  return Result;
416  }
417 
418  llvm_unreachable("Unknown attribute");
419 }
420 
422  if (!pImpl && !A.pImpl) return false;
423  if (!pImpl) return true;
424  if (!A.pImpl) return false;
425  return *pImpl < *A.pImpl;
426 }
427 
428 //===----------------------------------------------------------------------===//
429 // AttributeImpl Definition
430 //===----------------------------------------------------------------------===//
431 
432 // Pin the vtables to this file.
434 
435 void EnumAttributeImpl::anchor() {}
436 
437 void IntAttributeImpl::anchor() {}
438 
439 void StringAttributeImpl::anchor() {}
440 
442  if (isStringAttribute()) return false;
443  return getKindAsEnum() == A;
444 }
445 
447  if (!isStringAttribute()) return false;
448  return getKindAsString() == Kind;
449 }
450 
453  return static_cast<const EnumAttributeImpl *>(this)->getEnumKind();
454 }
455 
458  return static_cast<const IntAttributeImpl *>(this)->getValue();
459 }
460 
463  return static_cast<const StringAttributeImpl *>(this)->getStringKind();
464 }
465 
468  return static_cast<const StringAttributeImpl *>(this)->getStringValue();
469 }
470 
472  // This sorts the attributes with Attribute::AttrKinds coming first (sorted
473  // relative to their enum value) and then strings.
474  if (isEnumAttribute()) {
475  if (AI.isEnumAttribute()) return getKindAsEnum() < AI.getKindAsEnum();
476  if (AI.isIntAttribute()) return true;
477  if (AI.isStringAttribute()) return true;
478  }
479 
480  if (isIntAttribute()) {
481  if (AI.isEnumAttribute()) return false;
482  if (AI.isIntAttribute()) {
483  if (getKindAsEnum() == AI.getKindAsEnum())
484  return getValueAsInt() < AI.getValueAsInt();
485  return getKindAsEnum() < AI.getKindAsEnum();
486  }
487  if (AI.isStringAttribute()) return true;
488  }
489 
490  if (AI.isEnumAttribute()) return false;
491  if (AI.isIntAttribute()) return false;
492  if (getKindAsString() == AI.getKindAsString())
493  return getValueAsString() < AI.getValueAsString();
494  return getKindAsString() < AI.getKindAsString();
495 }
496 
497 //===----------------------------------------------------------------------===//
498 // AttributeSet Definition
499 //===----------------------------------------------------------------------===//
500 
502  return AttributeSet(AttributeSetNode::get(C, B));
503 }
504 
506  return AttributeSet(AttributeSetNode::get(C, Attrs));
507 }
508 
510  Attribute::AttrKind Kind) const {
511  if (hasAttribute(Kind)) return *this;
512  AttrBuilder B;
513  B.addAttribute(Kind);
514  return addAttributes(C, AttributeSet::get(C, B));
515 }
516 
518  StringRef Value) const {
519  AttrBuilder B;
520  B.addAttribute(Kind, Value);
521  return addAttributes(C, AttributeSet::get(C, B));
522 }
523 
525  const AttributeSet AS) const {
526  if (!hasAttributes())
527  return AS;
528 
529  if (!AS.hasAttributes())
530  return *this;
531 
532  AttrBuilder B(AS);
533  for (Attribute I : *this)
534  B.addAttribute(I);
535 
536  return get(C, B);
537 }
538 
540  Attribute::AttrKind Kind) const {
541  if (!hasAttribute(Kind)) return *this;
542  AttrBuilder B;
543  B.addAttribute(Kind);
544  return removeAttributes(C, B);
545 }
546 
548  StringRef Kind) const {
549  if (!hasAttribute(Kind)) return *this;
550  AttrBuilder B;
551  B.addAttribute(Kind);
552  return removeAttributes(C, B);
553 }
554 
556  const AttrBuilder &Attrs) const {
557 
558  // FIXME it is not obvious how this should work for alignment.
559  // For now, say we can't pass in alignment, which no current use does.
560  assert(!Attrs.hasAlignmentAttr() && "Attempt to change alignment!");
561 
562  AttrBuilder B(*this);
563  B.remove(Attrs);
564  return get(C, B);
565 }
566 
568  return SetNode ? SetNode->getNumAttributes() : 0;
569 }
570 
572  return SetNode ? SetNode->hasAttribute(Kind) : false;
573 }
574 
576  return SetNode ? SetNode->hasAttribute(Kind) : false;
577 }
578 
580  return SetNode ? SetNode->getAttribute(Kind) : Attribute();
581 }
582 
584  return SetNode ? SetNode->getAttribute(Kind) : Attribute();
585 }
586 
587 unsigned AttributeSet::getAlignment() const {
588  return SetNode ? SetNode->getAlignment() : 0;
589 }
590 
592  return SetNode ? SetNode->getStackAlignment() : 0;
593 }
594 
596  return SetNode ? SetNode->getDereferenceableBytes() : 0;
597 }
598 
600  return SetNode ? SetNode->getDereferenceableOrNullBytes() : 0;
601 }
602 
603 std::pair<unsigned, Optional<unsigned>> AttributeSet::getAllocSizeArgs() const {
604  return SetNode ? SetNode->getAllocSizeArgs()
605  : std::pair<unsigned, Optional<unsigned>>(0, 0);
606 }
607 
608 std::string AttributeSet::getAsString(bool InAttrGrp) const {
609  return SetNode ? SetNode->getAsString(InAttrGrp) : "";
610 }
611 
613  return SetNode ? SetNode->begin() : nullptr;
614 }
615 
617  return SetNode ? SetNode->end() : nullptr;
618 }
619 
620 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
622  dbgs() << "AS =\n";
623  dbgs() << " { ";
624  dbgs() << getAsString(true) << " }\n";
625 }
626 #endif
627 
628 //===----------------------------------------------------------------------===//
629 // AttributeSetNode Definition
630 //===----------------------------------------------------------------------===//
631 
632 AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
633  : AvailableAttrs(0), NumAttrs(Attrs.size()) {
634  // There's memory after the node where we can store the entries in.
635  std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
636 
637  for (Attribute I : *this) {
638  if (!I.isStringAttribute()) {
639  AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
640  }
641  }
642 }
643 
645  ArrayRef<Attribute> Attrs) {
646  if (Attrs.empty())
647  return nullptr;
648 
649  // Otherwise, build a key to look up the existing attributes.
650  LLVMContextImpl *pImpl = C.pImpl;
652 
653  SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
654  std::sort(SortedAttrs.begin(), SortedAttrs.end());
655 
656  for (Attribute Attr : SortedAttrs)
657  Attr.Profile(ID);
658 
659  void *InsertPoint;
660  AttributeSetNode *PA =
661  pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint);
662 
663  // If we didn't find any existing attributes of the same shape then create a
664  // new one and insert it.
665  if (!PA) {
666  // Coallocate entries after the AttributeSetNode itself.
667  void *Mem = ::operator new(totalSizeToAlloc<Attribute>(SortedAttrs.size()));
668  PA = new (Mem) AttributeSetNode(SortedAttrs);
669  pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint);
670  }
671 
672  // Return the AttributeSetNode that we found or created.
673  return PA;
674 }
675 
677  // Add target-independent attributes.
681  if (!B.contains(Kind))
682  continue;
683 
684  Attribute Attr;
685  switch (Kind) {
686  case Attribute::Alignment:
688  break;
689  case Attribute::StackAlignment:
691  break;
692  case Attribute::Dereferenceable:
694  C, B.getDereferenceableBytes());
695  break;
696  case Attribute::DereferenceableOrNull:
699  break;
700  case Attribute::AllocSize: {
701  auto A = B.getAllocSizeArgs();
702  Attr = Attribute::getWithAllocSizeArgs(C, A.first, A.second);
703  break;
704  }
705  default:
706  Attr = Attribute::get(C, Kind);
707  }
708  Attrs.push_back(Attr);
709  }
710 
711  // Add target-dependent (string) attributes.
712  for (const auto &TDA : B.td_attrs())
713  Attrs.emplace_back(Attribute::get(C, TDA.first, TDA.second));
714 
715  return get(C, Attrs);
716 }
717 
719  for (Attribute I : *this)
720  if (I.hasAttribute(Kind))
721  return true;
722  return false;
723 }
724 
726  if (hasAttribute(Kind)) {
727  for (Attribute I : *this)
728  if (I.hasAttribute(Kind))
729  return I;
730  }
731  return Attribute();
732 }
733 
735  for (Attribute I : *this)
736  if (I.hasAttribute(Kind))
737  return I;
738  return Attribute();
739 }
740 
742  for (Attribute I : *this)
743  if (I.hasAttribute(Attribute::Alignment))
744  return I.getAlignment();
745  return 0;
746 }
747 
749  for (Attribute I : *this)
750  if (I.hasAttribute(Attribute::StackAlignment))
751  return I.getStackAlignment();
752  return 0;
753 }
754 
756  for (Attribute I : *this)
757  if (I.hasAttribute(Attribute::Dereferenceable))
758  return I.getDereferenceableBytes();
759  return 0;
760 }
761 
763  for (Attribute I : *this)
764  if (I.hasAttribute(Attribute::DereferenceableOrNull))
766  return 0;
767 }
768 
769 std::pair<unsigned, Optional<unsigned>>
771  for (Attribute I : *this)
772  if (I.hasAttribute(Attribute::AllocSize))
773  return I.getAllocSizeArgs();
774  return std::make_pair(0, 0);
775 }
776 
777 std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
778  std::string Str;
779  for (iterator I = begin(), E = end(); I != E; ++I) {
780  if (I != begin())
781  Str += ' ';
782  Str += I->getAsString(InAttrGrp);
783  }
784  return Str;
785 }
786 
787 //===----------------------------------------------------------------------===//
788 // AttributeListImpl Definition
789 //===----------------------------------------------------------------------===//
790 
791 /// Map from AttributeList index to the internal array index. Adding one works:
792 /// FunctionIndex: ~0U -> 0
793 /// ReturnIndex: 0 -> 1
794 /// FirstArgIndex: 1.. -> 2..
795 static constexpr unsigned attrIdxToArrayIdx(unsigned Index) {
796  // MSVC warns about '~0U + 1' wrapping around when this is called on
797  // FunctionIndex, so cast to int first.
798  return static_cast<int>(Index) + 1;
799 }
800 
803  : AvailableFunctionAttrs(0), Context(C), NumAttrSets(Sets.size()) {
804  assert(!Sets.empty() && "pointless AttributeListImpl");
805 
806  // There's memory after the node where we can store the entries in.
807  std::copy(Sets.begin(), Sets.end(), getTrailingObjects<AttributeSet>());
808 
809  // Initialize AvailableFunctionAttrs summary bitset.
810  static_assert(Attribute::EndAttrKinds <=
811  sizeof(AvailableFunctionAttrs) * CHAR_BIT,
812  "Too many attributes");
813  static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U,
814  "function should be stored in slot 0");
815  for (Attribute I : Sets[0]) {
816  if (!I.isStringAttribute())
817  AvailableFunctionAttrs |= 1ULL << I.getKindAsEnum();
818  }
819 }
820 
822  Profile(ID, makeArrayRef(begin(), end()));
823 }
824 
826  ArrayRef<AttributeSet> Sets) {
827  for (const auto &Set : Sets)
828  ID.AddPointer(Set.SetNode);
829 }
830 
831 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
833  AttributeList(const_cast<AttributeListImpl *>(this)).dump();
834 }
835 #endif
836 
837 //===----------------------------------------------------------------------===//
838 // AttributeList Construction and Mutation Methods
839 //===----------------------------------------------------------------------===//
840 
842  ArrayRef<AttributeSet> AttrSets) {
843  assert(!AttrSets.empty() && "pointless AttributeListImpl");
844 
845  LLVMContextImpl *pImpl = C.pImpl;
847  AttributeListImpl::Profile(ID, AttrSets);
848 
849  void *InsertPoint;
850  AttributeListImpl *PA =
851  pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint);
852 
853  // If we didn't find any existing attributes of the same shape then
854  // create a new one and insert it.
855  if (!PA) {
856  // Coallocate entries after the AttributeListImpl itself.
857  void *Mem = ::operator new(
858  AttributeListImpl::totalSizeToAlloc<AttributeSet>(AttrSets.size()));
859  PA = new (Mem) AttributeListImpl(C, AttrSets);
860  pImpl->AttrsLists.InsertNode(PA, InsertPoint);
861  }
862 
863  // Return the AttributesList that we found or created.
864  return AttributeList(PA);
865 }
866 
869  ArrayRef<std::pair<unsigned, Attribute>> Attrs) {
870  // If there are no attributes then return a null AttributesList pointer.
871  if (Attrs.empty())
872  return AttributeList();
873 
874  assert(std::is_sorted(Attrs.begin(), Attrs.end(),
875  [](const std::pair<unsigned, Attribute> &LHS,
876  const std::pair<unsigned, Attribute> &RHS) {
877  return LHS.first < RHS.first;
878  }) && "Misordered Attributes list!");
879  assert(none_of(Attrs,
880  [](const std::pair<unsigned, Attribute> &Pair) {
881  return Pair.second.hasAttribute(Attribute::None);
882  }) &&
883  "Pointless attribute!");
884 
885  // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes
886  // list.
888  for (ArrayRef<std::pair<unsigned, Attribute>>::iterator I = Attrs.begin(),
889  E = Attrs.end(); I != E; ) {
890  unsigned Index = I->first;
892  while (I != E && I->first == Index) {
893  AttrVec.push_back(I->second);
894  ++I;
895  }
896 
897  AttrPairVec.emplace_back(Index, AttributeSet::get(C, AttrVec));
898  }
899 
900  return get(C, AttrPairVec);
901 }
902 
905  ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) {
906  // If there are no attributes then return a null AttributesList pointer.
907  if (Attrs.empty())
908  return AttributeList();
909 
910  assert(std::is_sorted(Attrs.begin(), Attrs.end(),
911  [](const std::pair<unsigned, AttributeSet> &LHS,
912  const std::pair<unsigned, AttributeSet> &RHS) {
913  return LHS.first < RHS.first;
914  }) &&
915  "Misordered Attributes list!");
916  assert(none_of(Attrs,
917  [](const std::pair<unsigned, AttributeSet> &Pair) {
918  return !Pair.second.hasAttributes();
919  }) &&
920  "Pointless attribute!");
921 
922  unsigned MaxIndex = Attrs.back().first;
923 
924  SmallVector<AttributeSet, 4> AttrVec(attrIdxToArrayIdx(MaxIndex) + 1);
925  for (auto Pair : Attrs)
926  AttrVec[attrIdxToArrayIdx(Pair.first)] = Pair.second;
927 
928  return getImpl(C, AttrVec);
929 }
930 
932  AttributeSet RetAttrs,
933  ArrayRef<AttributeSet> ArgAttrs) {
934  // Scan from the end to find the last argument with attributes. Most
935  // arguments don't have attributes, so it's nice if we can have fewer unique
936  // AttributeListImpls by dropping empty attribute sets at the end of the list.
937  unsigned NumSets = 0;
938  for (size_t I = ArgAttrs.size(); I != 0; --I) {
939  if (ArgAttrs[I - 1].hasAttributes()) {
940  NumSets = I + 2;
941  break;
942  }
943  }
944  if (NumSets == 0) {
945  // Check function and return attributes if we didn't have argument
946  // attributes.
947  if (RetAttrs.hasAttributes())
948  NumSets = 2;
949  else if (FnAttrs.hasAttributes())
950  NumSets = 1;
951  }
952 
953  // If all attribute sets were empty, we can use the empty attribute list.
954  if (NumSets == 0)
955  return AttributeList();
956 
958  AttrSets.reserve(NumSets);
959  // If we have any attributes, we always have function attributes.
960  AttrSets.push_back(FnAttrs);
961  if (NumSets > 1)
962  AttrSets.push_back(RetAttrs);
963  if (NumSets > 2) {
964  // Drop the empty argument attribute sets at the end.
965  ArgAttrs = ArgAttrs.take_front(NumSets - 2);
966  AttrSets.insert(AttrSets.end(), ArgAttrs.begin(), ArgAttrs.end());
967  }
968 
969  return getImpl(C, AttrSets);
970 }
971 
973  const AttrBuilder &B) {
974  if (!B.hasAttributes())
975  return AttributeList();
976  Index = attrIdxToArrayIdx(Index);
977  SmallVector<AttributeSet, 8> AttrSets(Index + 1);
978  AttrSets[Index] = AttributeSet::get(C, B);
979  return getImpl(C, AttrSets);
980 }
981 
985  for (Attribute::AttrKind K : Kinds)
986  Attrs.emplace_back(Index, Attribute::get(C, K));
987  return get(C, Attrs);
988 }
989 
991  ArrayRef<StringRef> Kinds) {
993  for (StringRef K : Kinds)
994  Attrs.emplace_back(Index, Attribute::get(C, K));
995  return get(C, Attrs);
996 }
997 
999  ArrayRef<AttributeList> Attrs) {
1000  if (Attrs.empty())
1001  return AttributeList();
1002  if (Attrs.size() == 1)
1003  return Attrs[0];
1004 
1005  unsigned MaxSize = 0;
1006  for (AttributeList List : Attrs)
1007  MaxSize = std::max(MaxSize, List.getNumAttrSets());
1008 
1009  // If every list was empty, there is no point in merging the lists.
1010  if (MaxSize == 0)
1011  return AttributeList();
1012 
1013  SmallVector<AttributeSet, 8> NewAttrSets(MaxSize);
1014  for (unsigned I = 0; I < MaxSize; ++I) {
1015  AttrBuilder CurBuilder;
1016  for (AttributeList List : Attrs)
1017  CurBuilder.merge(List.getAttributes(I - 1));
1018  NewAttrSets[I] = AttributeSet::get(C, CurBuilder);
1019  }
1020 
1021  return getImpl(C, NewAttrSets);
1022 }
1023 
1025  Attribute::AttrKind Kind) const {
1026  if (hasAttribute(Index, Kind)) return *this;
1027  AttrBuilder B;
1028  B.addAttribute(Kind);
1029  return addAttributes(C, Index, B);
1030 }
1031 
1033  StringRef Kind,
1034  StringRef Value) const {
1035  AttrBuilder B;
1036  B.addAttribute(Kind, Value);
1037  return addAttributes(C, Index, B);
1038 }
1039 
1041  Attribute A) const {
1042  AttrBuilder B;
1043  B.addAttribute(A);
1044  return addAttributes(C, Index, B);
1045 }
1046 
1048  const AttrBuilder &B) const {
1049  if (!B.hasAttributes())
1050  return *this;
1051 
1052  if (!pImpl)
1053  return AttributeList::get(C, {{Index, AttributeSet::get(C, B)}});
1054 
1055 #ifndef NDEBUG
1056  // FIXME it is not obvious how this should work for alignment. For now, say
1057  // we can't change a known alignment.
1058  unsigned OldAlign = getAttributes(Index).getAlignment();
1059  unsigned NewAlign = B.getAlignment();
1060  assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
1061  "Attempt to change alignment!");
1062 #endif
1063 
1064  Index = attrIdxToArrayIdx(Index);
1065  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1066  if (Index >= AttrSets.size())
1067  AttrSets.resize(Index + 1);
1068 
1069  AttrBuilder Merged(AttrSets[Index]);
1070  Merged.merge(B);
1071  AttrSets[Index] = AttributeSet::get(C, Merged);
1072 
1073  return getImpl(C, AttrSets);
1074 }
1075 
1077  ArrayRef<unsigned> ArgNos,
1078  Attribute A) const {
1079  assert(std::is_sorted(ArgNos.begin(), ArgNos.end()));
1080 
1081  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1082  unsigned MaxIndex = attrIdxToArrayIdx(ArgNos.back() + FirstArgIndex);
1083  if (MaxIndex >= AttrSets.size())
1084  AttrSets.resize(MaxIndex + 1);
1085 
1086  for (unsigned ArgNo : ArgNos) {
1087  unsigned Index = attrIdxToArrayIdx(ArgNo + FirstArgIndex);
1088  AttrBuilder B(AttrSets[Index]);
1089  B.addAttribute(A);
1090  AttrSets[Index] = AttributeSet::get(C, B);
1091  }
1092 
1093  return getImpl(C, AttrSets);
1094 }
1095 
1097  Attribute::AttrKind Kind) const {
1098  if (!hasAttribute(Index, Kind)) return *this;
1099  AttrBuilder B;
1100  B.addAttribute(Kind);
1101  return removeAttributes(C, Index, B);
1102 }
1103 
1105  StringRef Kind) const {
1106  if (!hasAttribute(Index, Kind)) return *this;
1107  AttrBuilder B;
1108  B.addAttribute(Kind);
1109  return removeAttributes(C, Index, B);
1110 }
1111 
1114  const AttrBuilder &AttrsToRemove) const {
1115  if (!pImpl)
1116  return AttributeList();
1117 
1118  // FIXME it is not obvious how this should work for alignment.
1119  // For now, say we can't pass in alignment, which no current use does.
1120  assert(!AttrsToRemove.hasAlignmentAttr() && "Attempt to change alignment!");
1121 
1122  Index = attrIdxToArrayIdx(Index);
1123  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1124  if (Index >= AttrSets.size())
1125  AttrSets.resize(Index + 1);
1126 
1127  AttrBuilder B(AttrSets[Index]);
1128  B.remove(AttrsToRemove);
1129  AttrSets[Index] = AttributeSet::get(C, B);
1130 
1131  return getImpl(C, AttrSets);
1132 }
1133 
1135  unsigned WithoutIndex) const {
1136  if (!pImpl)
1137  return AttributeList();
1138  WithoutIndex = attrIdxToArrayIdx(WithoutIndex);
1139  if (WithoutIndex >= getNumAttrSets())
1140  return *this;
1141  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1142  AttrSets[WithoutIndex] = AttributeSet();
1143  return getImpl(C, AttrSets);
1144 }
1145 
1147  unsigned Index,
1148  uint64_t Bytes) const {
1149  AttrBuilder B;
1150  B.addDereferenceableAttr(Bytes);
1151  return addAttributes(C, Index, B);
1152 }
1153 
1156  uint64_t Bytes) const {
1157  AttrBuilder B;
1159  return addAttributes(C, Index, B);
1160 }
1161 
1164  unsigned ElemSizeArg,
1165  const Optional<unsigned> &NumElemsArg) {
1166  AttrBuilder B;
1167  B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1168  return addAttributes(C, Index, B);
1169 }
1170 
1171 //===----------------------------------------------------------------------===//
1172 // AttributeList Accessor Methods
1173 //===----------------------------------------------------------------------===//
1174 
1175 LLVMContext &AttributeList::getContext() const { return pImpl->getContext(); }
1176 
1178  return getAttributes(ArgNo + FirstArgIndex);
1179 }
1180 
1182  return getAttributes(ReturnIndex);
1183 }
1184 
1186  return getAttributes(FunctionIndex);
1187 }
1188 
1189 bool AttributeList::hasAttribute(unsigned Index,
1190  Attribute::AttrKind Kind) const {
1191  return getAttributes(Index).hasAttribute(Kind);
1192 }
1193 
1194 bool AttributeList::hasAttribute(unsigned Index, StringRef Kind) const {
1195  return getAttributes(Index).hasAttribute(Kind);
1196 }
1197 
1198 bool AttributeList::hasAttributes(unsigned Index) const {
1199  return getAttributes(Index).hasAttributes();
1200 }
1201 
1203  return pImpl && pImpl->hasFnAttribute(Kind);
1204 }
1205 
1207  return hasAttribute(AttributeList::FunctionIndex, Kind);
1208 }
1209 
1211  Attribute::AttrKind Kind) const {
1212  return hasAttribute(ArgNo + FirstArgIndex, Kind);
1213 }
1214 
1216  unsigned *Index) const {
1217  if (!pImpl) return false;
1218 
1219  for (unsigned I = index_begin(), E = index_end(); I != E; ++I) {
1220  if (hasAttribute(I, Attr)) {
1221  if (Index)
1222  *Index = I;
1223  return true;
1224  }
1225  }
1226 
1227  return false;
1228 }
1229 
1231  Attribute::AttrKind Kind) const {
1232  return getAttributes(Index).getAttribute(Kind);
1233 }
1234 
1236  return getAttributes(Index).getAttribute(Kind);
1237 }
1238 
1240  return getAttributes(ReturnIndex).getAlignment();
1241 }
1242 
1243 unsigned AttributeList::getParamAlignment(unsigned ArgNo) const {
1244  return getAttributes(ArgNo + FirstArgIndex).getAlignment();
1245 }
1246 
1247 unsigned AttributeList::getStackAlignment(unsigned Index) const {
1248  return getAttributes(Index).getStackAlignment();
1249 }
1250 
1251 uint64_t AttributeList::getDereferenceableBytes(unsigned Index) const {
1252  return getAttributes(Index).getDereferenceableBytes();
1253 }
1254 
1255 uint64_t AttributeList::getDereferenceableOrNullBytes(unsigned Index) const {
1257 }
1258 
1259 std::pair<unsigned, Optional<unsigned>>
1260 AttributeList::getAllocSizeArgs(unsigned Index) const {
1261  return getAttributes(Index).getAllocSizeArgs();
1262 }
1263 
1264 std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const {
1265  return getAttributes(Index).getAsString(InAttrGrp);
1266 }
1267 
1269  Index = attrIdxToArrayIdx(Index);
1270  if (!pImpl || Index >= getNumAttrSets())
1271  return AttributeSet();
1272  return pImpl->begin()[Index];
1273 }
1274 
1276  return pImpl ? pImpl->begin() : nullptr;
1277 }
1278 
1280  return pImpl ? pImpl->end() : nullptr;
1281 }
1282 
1283 //===----------------------------------------------------------------------===//
1284 // AttributeList Introspection Methods
1285 //===----------------------------------------------------------------------===//
1286 
1288  return pImpl ? pImpl->NumAttrSets : 0;
1289 }
1290 
1291 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1293  dbgs() << "PAL[\n";
1294 
1295  for (unsigned i = index_begin(), e = index_end(); i != e; ++i) {
1296  if (getAttributes(i).hasAttributes())
1297  dbgs() << " { " << i << " => " << getAsString(i) << " }\n";
1298  }
1299 
1300  dbgs() << "]\n";
1301 }
1302 #endif
1303 
1304 //===----------------------------------------------------------------------===//
1305 // AttrBuilder Method Implementations
1306 //===----------------------------------------------------------------------===//
1307 
1308 // FIXME: Remove this ctor, use AttributeSet.
1310  AttributeSet AS = AL.getAttributes(Index);
1311  for (const Attribute &A : AS)
1312  addAttribute(A);
1313 }
1314 
1316  for (const Attribute &A : AS)
1317  addAttribute(A);
1318 }
1319 
1321  Attrs.reset();
1322  TargetDepAttrs.clear();
1323  Alignment = StackAlignment = DerefBytes = DerefOrNullBytes = 0;
1324  AllocSizeArgs = 0;
1325 }
1326 
1328  assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1329  assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
1330  Val != Attribute::Dereferenceable && Val != Attribute::AllocSize &&
1331  "Adding integer attribute without adding a value!");
1332  Attrs[Val] = true;
1333  return *this;
1334 }
1335 
1337  if (Attr.isStringAttribute()) {
1338  addAttribute(Attr.getKindAsString(), Attr.getValueAsString());
1339  return *this;
1340  }
1341 
1343  Attrs[Kind] = true;
1344 
1345  if (Kind == Attribute::Alignment)
1346  Alignment = Attr.getAlignment();
1347  else if (Kind == Attribute::StackAlignment)
1348  StackAlignment = Attr.getStackAlignment();
1349  else if (Kind == Attribute::Dereferenceable)
1350  DerefBytes = Attr.getDereferenceableBytes();
1351  else if (Kind == Attribute::DereferenceableOrNull)
1352  DerefOrNullBytes = Attr.getDereferenceableOrNullBytes();
1353  else if (Kind == Attribute::AllocSize)
1354  AllocSizeArgs = Attr.getValueAsInt();
1355  return *this;
1356 }
1357 
1359  TargetDepAttrs[A] = V;
1360  return *this;
1361 }
1362 
1364  assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1365  Attrs[Val] = false;
1366 
1367  if (Val == Attribute::Alignment)
1368  Alignment = 0;
1369  else if (Val == Attribute::StackAlignment)
1370  StackAlignment = 0;
1371  else if (Val == Attribute::Dereferenceable)
1372  DerefBytes = 0;
1373  else if (Val == Attribute::DereferenceableOrNull)
1374  DerefOrNullBytes = 0;
1375  else if (Val == Attribute::AllocSize)
1376  AllocSizeArgs = 0;
1377 
1378  return *this;
1379 }
1380 
1382  remove(A.getAttributes(Index));
1383  return *this;
1384 }
1385 
1387  std::map<std::string, std::string>::iterator I = TargetDepAttrs.find(A);
1388  if (I != TargetDepAttrs.end())
1389  TargetDepAttrs.erase(I);
1390  return *this;
1391 }
1392 
1393 std::pair<unsigned, Optional<unsigned>> AttrBuilder::getAllocSizeArgs() const {
1394  return unpackAllocSizeArgs(AllocSizeArgs);
1395 }
1396 
1398  if (Align == 0) return *this;
1399 
1400  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
1401  assert(Align <= 0x40000000 && "Alignment too large.");
1402 
1403  Attrs[Attribute::Alignment] = true;
1404  Alignment = Align;
1405  return *this;
1406 }
1407 
1409  // Default alignment, allow the target to define how to align it.
1410  if (Align == 0) return *this;
1411 
1412  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
1413  assert(Align <= 0x100 && "Alignment too large.");
1414 
1415  Attrs[Attribute::StackAlignment] = true;
1416  StackAlignment = Align;
1417  return *this;
1418 }
1419 
1421  if (Bytes == 0) return *this;
1422 
1423  Attrs[Attribute::Dereferenceable] = true;
1424  DerefBytes = Bytes;
1425  return *this;
1426 }
1427 
1429  if (Bytes == 0)
1430  return *this;
1431 
1432  Attrs[Attribute::DereferenceableOrNull] = true;
1433  DerefOrNullBytes = Bytes;
1434  return *this;
1435 }
1436 
1438  const Optional<unsigned> &NumElems) {
1439  return addAllocSizeAttrFromRawRepr(packAllocSizeArgs(ElemSize, NumElems));
1440 }
1441 
1443  // (0, 0) is our "not present" value, so we need to check for it here.
1444  assert(RawArgs && "Invalid allocsize arguments -- given allocsize(0, 0)");
1445 
1446  Attrs[Attribute::AllocSize] = true;
1447  // Reuse existing machinery to store this as a single 64-bit integer so we can
1448  // save a few bytes over using a pair<unsigned, Optional<unsigned>>.
1449  AllocSizeArgs = RawArgs;
1450  return *this;
1451 }
1452 
1454  // FIXME: What if both have alignments, but they don't match?!
1455  if (!Alignment)
1456  Alignment = B.Alignment;
1457 
1458  if (!StackAlignment)
1459  StackAlignment = B.StackAlignment;
1460 
1461  if (!DerefBytes)
1462  DerefBytes = B.DerefBytes;
1463 
1464  if (!DerefOrNullBytes)
1465  DerefOrNullBytes = B.DerefOrNullBytes;
1466 
1467  if (!AllocSizeArgs)
1468  AllocSizeArgs = B.AllocSizeArgs;
1469 
1470  Attrs |= B.Attrs;
1471 
1472  for (auto I : B.td_attrs())
1473  TargetDepAttrs[I.first] = I.second;
1474 
1475  return *this;
1476 }
1477 
1479  // FIXME: What if both have alignments, but they don't match?!
1480  if (B.Alignment)
1481  Alignment = 0;
1482 
1483  if (B.StackAlignment)
1484  StackAlignment = 0;
1485 
1486  if (B.DerefBytes)
1487  DerefBytes = 0;
1488 
1489  if (B.DerefOrNullBytes)
1490  DerefOrNullBytes = 0;
1491 
1492  if (B.AllocSizeArgs)
1493  AllocSizeArgs = 0;
1494 
1495  Attrs &= ~B.Attrs;
1496 
1497  for (auto I : B.td_attrs())
1498  TargetDepAttrs.erase(I.first);
1499 
1500  return *this;
1501 }
1502 
1504  // First check if any of the target independent attributes overlap.
1505  if ((Attrs & B.Attrs).any())
1506  return true;
1507 
1508  // Then check if any target dependent ones do.
1509  for (const auto &I : td_attrs())
1510  if (B.contains(I.first))
1511  return true;
1512 
1513  return false;
1514 }
1515 
1517  return TargetDepAttrs.find(A) != TargetDepAttrs.end();
1518 }
1519 
1521  return !Attrs.none() || !TargetDepAttrs.empty();
1522 }
1523 
1524 bool AttrBuilder::hasAttributes(AttributeList AL, uint64_t Index) const {
1525  AttributeSet AS = AL.getAttributes(Index);
1526 
1527  for (Attribute Attr : AS) {
1528  if (Attr.isEnumAttribute() || Attr.isIntAttribute()) {
1529  if (contains(Attr.getKindAsEnum()))
1530  return true;
1531  } else {
1532  assert(Attr.isStringAttribute() && "Invalid attribute kind!");
1533  return contains(Attr.getKindAsString());
1534  }
1535  }
1536 
1537  return false;
1538 }
1539 
1541  return Alignment != 0;
1542 }
1543 
1545  if (Attrs != B.Attrs)
1546  return false;
1547 
1548  for (td_const_iterator I = TargetDepAttrs.begin(),
1549  E = TargetDepAttrs.end(); I != E; ++I)
1550  if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end())
1551  return false;
1552 
1553  return Alignment == B.Alignment && StackAlignment == B.StackAlignment &&
1554  DerefBytes == B.DerefBytes;
1555 }
1556 
1557 //===----------------------------------------------------------------------===//
1558 // AttributeFuncs Function Defintions
1559 //===----------------------------------------------------------------------===//
1560 
1561 /// \brief Which attributes cannot be applied to a type.
1563  AttrBuilder Incompatible;
1564 
1565  if (!Ty->isIntegerTy())
1566  // Attribute that only apply to integers.
1567  Incompatible.addAttribute(Attribute::SExt)
1568  .addAttribute(Attribute::ZExt);
1569 
1570  if (!Ty->isPointerTy())
1571  // Attribute that only apply to pointers.
1572  Incompatible.addAttribute(Attribute::ByVal)
1573  .addAttribute(Attribute::Nest)
1575  .addAttribute(Attribute::NoCapture)
1576  .addAttribute(Attribute::NonNull)
1577  .addDereferenceableAttr(1) // the int here is ignored
1578  .addDereferenceableOrNullAttr(1) // the int here is ignored
1579  .addAttribute(Attribute::ReadNone)
1580  .addAttribute(Attribute::ReadOnly)
1581  .addAttribute(Attribute::StructRet)
1582  .addAttribute(Attribute::InAlloca);
1583 
1584  return Incompatible;
1585 }
1586 
1587 template<typename AttrClass>
1588 static bool isEqual(const Function &Caller, const Function &Callee) {
1589  return Caller.getFnAttribute(AttrClass::getKind()) ==
1590  Callee.getFnAttribute(AttrClass::getKind());
1591 }
1592 
1593 /// \brief Compute the logical AND of the attributes of the caller and the
1594 /// callee.
1595 ///
1596 /// This function sets the caller's attribute to false if the callee's attribute
1597 /// is false.
1598 template<typename AttrClass>
1599 static void setAND(Function &Caller, const Function &Callee) {
1600  if (AttrClass::isSet(Caller, AttrClass::getKind()) &&
1601  !AttrClass::isSet(Callee, AttrClass::getKind()))
1602  AttrClass::set(Caller, AttrClass::getKind(), false);
1603 }
1604 
1605 /// \brief Compute the logical OR of the attributes of the caller and the
1606 /// callee.
1607 ///
1608 /// This function sets the caller's attribute to true if the callee's attribute
1609 /// is true.
1610 template<typename AttrClass>
1611 static void setOR(Function &Caller, const Function &Callee) {
1612  if (!AttrClass::isSet(Caller, AttrClass::getKind()) &&
1613  AttrClass::isSet(Callee, AttrClass::getKind()))
1614  AttrClass::set(Caller, AttrClass::getKind(), true);
1615 }
1616 
1617 /// \brief If the inlined function had a higher stack protection level than the
1618 /// calling function, then bump up the caller's stack protection level.
1619 static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) {
1620  // If upgrading the SSP attribute, clear out the old SSP Attributes first.
1621  // Having multiple SSP attributes doesn't actually hurt, but it adds useless
1622  // clutter to the IR.
1623  AttrBuilder OldSSPAttr;
1624  OldSSPAttr.addAttribute(Attribute::StackProtect)
1625  .addAttribute(Attribute::StackProtectStrong)
1626  .addAttribute(Attribute::StackProtectReq);
1627 
1628  if (Callee.hasFnAttribute(Attribute::StackProtectReq)) {
1629  Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
1630  Caller.addFnAttr(Attribute::StackProtectReq);
1631  } else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
1632  !Caller.hasFnAttribute(Attribute::StackProtectReq)) {
1633  Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
1634  Caller.addFnAttr(Attribute::StackProtectStrong);
1635  } else if (Callee.hasFnAttribute(Attribute::StackProtect) &&
1636  !Caller.hasFnAttribute(Attribute::StackProtectReq) &&
1637  !Caller.hasFnAttribute(Attribute::StackProtectStrong))
1638  Caller.addFnAttr(Attribute::StackProtect);
1639 }
1640 
1641 /// \brief If the inlined function required stack probes, then ensure that
1642 /// the calling function has those too.
1643 static void adjustCallerStackProbes(Function &Caller, const Function &Callee) {
1644  if (!Caller.hasFnAttribute("probe-stack") &&
1645  Callee.hasFnAttribute("probe-stack")) {
1646  Caller.addFnAttr(Callee.getFnAttribute("probe-stack"));
1647  }
1648 }
1649 
1650 /// \brief If the inlined function defines the size of guard region
1651 /// on the stack, then ensure that the calling function defines a guard region
1652 /// that is no larger.
1653 static void
1655  if (Callee.hasFnAttribute("stack-probe-size")) {
1656  uint64_t CalleeStackProbeSize;
1657  Callee.getFnAttribute("stack-probe-size")
1658  .getValueAsString()
1659  .getAsInteger(0, CalleeStackProbeSize);
1660  if (Caller.hasFnAttribute("stack-probe-size")) {
1661  uint64_t CallerStackProbeSize;
1662  Caller.getFnAttribute("stack-probe-size")
1663  .getValueAsString()
1664  .getAsInteger(0, CallerStackProbeSize);
1665  if (CallerStackProbeSize > CalleeStackProbeSize) {
1666  Caller.addFnAttr(Callee.getFnAttribute("stack-probe-size"));
1667  }
1668  } else {
1669  Caller.addFnAttr(Callee.getFnAttribute("stack-probe-size"));
1670  }
1671  }
1672 }
1673 
1674 #define GET_ATTR_COMPAT_FUNC
1675 #include "AttributesCompatFunc.inc"
1676 
1678  const Function &Callee) {
1679  return hasCompatibleFnAttrs(Caller, Callee);
1680 }
1681 
1683  const Function &Callee) {
1684  mergeFnAttrs(Caller, Callee);
1685 }
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:748
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:243
static constexpr unsigned attrIdxToArrayIdx(unsigned Index)
Map from AttributeList index to the internal array index.
Definition: Attributes.cpp:795
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:441
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:603
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:234
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
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:449
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
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
void PrintEscapedString(StringRef Name, raw_ostream &Out)
PrintEscapedString - Print each character of the specified string, escaping it if it is not printable...
Definition: AsmWriter.cpp:384
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:138
unsigned getAlignment() const
Definition: Attributes.cpp:741
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:140
iterator begin() const
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Attributes.cpp:725
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:254
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
The two locations do not alias at all.
Definition: AliasAnalysis.h:79
static AttributeSetNode * get(LLVMContext &C, const AttrBuilder &B)
Definition: Attributes.cpp:676
AttributeListImpl(LLVMContext &C, ArrayRef< AttributeSet > Sets)
Definition: Attributes.cpp:801
unsigned getRetAlignment() const
Return the alignment of the return value.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
std::string getAsString(bool InAttrGrp) const
Definition: Attributes.cpp:777
void reserve(size_type N)
Definition: SmallVector.h:380
uint64_t getDereferenceableBytes() const
Definition: Attributes.cpp:755
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:821
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:421
uint64_t getDereferenceableOrNullBytes() const
Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists...
Definition: Attributes.h:762
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:599
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:398
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:832
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:591
uint64_t getStackAlignment() const
Retrieve the stack alignment attribute, if it exists.
Definition: Attributes.h:754
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
static std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:160
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Definition: Attributes.cpp:770
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:524
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
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
const char * Name
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Definition: Attributes.cpp:571
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:311
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.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
bool operator==(const AttrBuilder &B)
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:202
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:501
std::map< std::string, std::string >::const_iterator td_const_iterator
Definition: Attributes.h:799
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:421
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:68
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
bool isStringAttribute() const
Definition: AttributeImpl.h:59
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:221
AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
Definition: Attributes.cpp:539
uint64_t getAlignment() const
Retrieve the alignment attribute, if it exists.
Definition: Attributes.h:751
#define A
Definition: LargeTest.cpp:12
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:567
iterator begin() const
Definition: Attributes.cpp:612
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:451
Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
Definition: Attributes.cpp:579
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:471
const AMDGPUAS & AS
uint64_t getDereferenceableBytes() const
Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is return...
Definition: Attributes.h:758
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:595
StringRef getKindAsString() const
Definition: Attributes.cpp:461
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:70
AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
Definition: Attributes.cpp:509
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:608
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
#define E
Definition: LargeTest.cpp:27
#define B
Definition: LargeTest.cpp:24
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
Definition: Attributes.h:731
unsigned getAlignment() const
Definition: Attributes.cpp:587
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:864
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
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:132
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:482
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:762
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:395
bool hasValue() const
Definition: Optional.h:133
unsigned getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:120
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:616
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:656
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:205
#define I(x, y, z)
Definition: MD5.cpp:58
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:151
friend class AttributeList
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
void AddString(StringRef String)
Definition: FoldingSet.cpp:87
uint64_t getValueAsInt() const
Definition: Attributes.cpp:456
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:466
Attribute()=default
td_range td_attrs()
Definition: Attributes.h:809
AttributeSet removeAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const
Remove the specified attributes from this set.
Definition: Attributes.cpp:555
AttributeList addAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
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:463
void dump() const
Definition: Attributes.cpp:621
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:262
FoldingSet< AttributeSetNode > AttrsSetNodes
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.h:203
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...
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
Definition: Parallel.h:201
static uint64_t packAllocSizeArgs(unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:60
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Definition: Attributes.cpp:868
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:355