LLVM  10.0.0svn
Attributes.cpp
Go to the documentation of this file.
1 //===- Attributes.cpp - Implement AttributesList --------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // \file
10 // This file implements the Attribute, AttributeImpl, AttrBuilder,
11 // AttributeListImpl, and AttributeList classes.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/IR/Attributes.h"
16 #include "AttributeImpl.h"
17 #include "LLVMContextImpl.h"
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/FoldingSet.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/ADT/Twine.h"
26 #include "llvm/Config/llvm-config.h"
27 #include "llvm/IR/Function.h"
28 #include "llvm/IR/LLVMContext.h"
29 #include "llvm/IR/Type.h"
30 #include "llvm/Support/Compiler.h"
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 <string>
42 #include <tuple>
43 #include <utility>
44 
45 using namespace llvm;
46 
47 //===----------------------------------------------------------------------===//
48 // Attribute Construction Methods
49 //===----------------------------------------------------------------------===//
50 
51 // allocsize has two integer arguments, but because they're both 32 bits, we can
52 // pack them into one 64-bit value, at the cost of making said value
53 // nonsensical.
54 //
55 // In order to do this, we need to reserve one value of the second (optional)
56 // allocsize argument to signify "not present."
57 static const unsigned AllocSizeNumElemsNotPresent = -1;
58 
59 static uint64_t packAllocSizeArgs(unsigned ElemSizeArg,
60  const Optional<unsigned> &NumElemsArg) {
61  assert((!NumElemsArg.hasValue() ||
62  *NumElemsArg != AllocSizeNumElemsNotPresent) &&
63  "Attempting to pack a reserved value");
64 
65  return uint64_t(ElemSizeArg) << 32 |
66  NumElemsArg.getValueOr(AllocSizeNumElemsNotPresent);
67 }
68 
69 static std::pair<unsigned, Optional<unsigned>>
70 unpackAllocSizeArgs(uint64_t Num) {
71  unsigned NumElems = Num & std::numeric_limits<unsigned>::max();
72  unsigned ElemSizeArg = Num >> 32;
73 
74  Optional<unsigned> NumElemsArg;
75  if (NumElems != AllocSizeNumElemsNotPresent)
76  NumElemsArg = NumElems;
77  return std::make_pair(ElemSizeArg, NumElemsArg);
78 }
79 
81  uint64_t Val) {
82  LLVMContextImpl *pImpl = Context.pImpl;
84  ID.AddInteger(Kind);
85  if (Val) ID.AddInteger(Val);
86 
87  void *InsertPoint;
88  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
89 
90  if (!PA) {
91  // If we didn't find any existing attributes of the same shape then create a
92  // new one and insert it.
93  if (!Val)
94  PA = new EnumAttributeImpl(Kind);
95  else
96  PA = new IntAttributeImpl(Kind, Val);
97  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
98  }
99 
100  // Return the Attribute that we found or created.
101  return Attribute(PA);
102 }
103 
105  LLVMContextImpl *pImpl = Context.pImpl;
107  ID.AddString(Kind);
108  if (!Val.empty()) ID.AddString(Val);
109 
110  void *InsertPoint;
111  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
112 
113  if (!PA) {
114  // If we didn't find any existing attributes of the same shape then create a
115  // new one and insert it.
116  PA = new StringAttributeImpl(Kind, Val);
117  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
118  }
119 
120  // Return the Attribute that we found or created.
121  return Attribute(PA);
122 }
123 
125  Type *Ty) {
126  LLVMContextImpl *pImpl = Context.pImpl;
128  ID.AddInteger(Kind);
129  ID.AddPointer(Ty);
130 
131  void *InsertPoint;
132  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
133 
134  if (!PA) {
135  // If we didn't find any existing attributes of the same shape then create a
136  // new one and insert it.
137  PA = new TypeAttributeImpl(Kind, Ty);
138  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
139  }
140 
141  // Return the Attribute that we found or created.
142  return Attribute(PA);
143 }
144 
146  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
147  assert(Align <= 0x40000000 && "Alignment too large.");
148  return get(Context, Alignment, Align);
149 }
150 
152  uint64_t Align) {
153  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
154  assert(Align <= 0x100 && "Alignment too large.");
155  return get(Context, StackAlignment, Align);
156 }
157 
159  uint64_t Bytes) {
160  assert(Bytes && "Bytes must be non-zero.");
161  return get(Context, Dereferenceable, Bytes);
162 }
163 
165  uint64_t Bytes) {
166  assert(Bytes && "Bytes must be non-zero.");
167  return get(Context, DereferenceableOrNull, Bytes);
168 }
169 
171  return get(Context, ByVal, Ty);
172 }
173 
174 Attribute
176  const Optional<unsigned> &NumElemsArg) {
177  assert(!(ElemSizeArg == 0 && NumElemsArg && *NumElemsArg == 0) &&
178  "Invalid allocsize arguments -- given allocsize(0, 0)");
179  return get(Context, AllocSize, packAllocSizeArgs(ElemSizeArg, NumElemsArg));
180 }
181 
182 //===----------------------------------------------------------------------===//
183 // Attribute Accessor Methods
184 //===----------------------------------------------------------------------===//
185 
187  return pImpl && pImpl->isEnumAttribute();
188 }
189 
191  return pImpl && pImpl->isIntAttribute();
192 }
193 
195  return pImpl && pImpl->isStringAttribute();
196 }
197 
199  return pImpl && pImpl->isTypeAttribute();
200 }
201 
203  if (!pImpl) return None;
205  "Invalid attribute type to get the kind as an enum!");
206  return pImpl->getKindAsEnum();
207 }
208 
209 uint64_t Attribute::getValueAsInt() const {
210  if (!pImpl) return 0;
212  "Expected the attribute to be an integer attribute!");
213  return pImpl->getValueAsInt();
214 }
215 
217  if (!pImpl) return {};
219  "Invalid attribute type to get the kind as a string!");
220  return pImpl->getKindAsString();
221 }
222 
224  if (!pImpl) return {};
226  "Invalid attribute type to get the value as a string!");
227  return pImpl->getValueAsString();
228 }
229 
231  if (!pImpl) return {};
233  "Invalid attribute type to get the value as a type!");
234  return pImpl->getValueAsType();
235 }
236 
237 
239  return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None);
240 }
241 
243  if (!isStringAttribute()) return false;
244  return pImpl && pImpl->hasAttribute(Kind);
245 }
246 
247 unsigned Attribute::getAlignment() const {
248  assert(hasAttribute(Attribute::Alignment) &&
249  "Trying to get alignment from non-alignment attribute!");
250  return pImpl->getValueAsInt();
251 }
252 
254  assert(hasAttribute(Attribute::StackAlignment) &&
255  "Trying to get alignment from non-alignment attribute!");
256  return pImpl->getValueAsInt();
257 }
258 
260  assert(hasAttribute(Attribute::Dereferenceable) &&
261  "Trying to get dereferenceable bytes from "
262  "non-dereferenceable attribute!");
263  return pImpl->getValueAsInt();
264 }
265 
267  assert(hasAttribute(Attribute::DereferenceableOrNull) &&
268  "Trying to get dereferenceable bytes from "
269  "non-dereferenceable attribute!");
270  return pImpl->getValueAsInt();
271 }
272 
273 std::pair<unsigned, Optional<unsigned>> Attribute::getAllocSizeArgs() const {
274  assert(hasAttribute(Attribute::AllocSize) &&
275  "Trying to get allocsize args from non-allocsize attribute");
276  return unpackAllocSizeArgs(pImpl->getValueAsInt());
277 }
278 
279 std::string Attribute::getAsString(bool InAttrGrp) const {
280  if (!pImpl) return {};
281 
282  if (hasAttribute(Attribute::SanitizeAddress))
283  return "sanitize_address";
284  if (hasAttribute(Attribute::SanitizeHWAddress))
285  return "sanitize_hwaddress";
286  if (hasAttribute(Attribute::SanitizeMemTag))
287  return "sanitize_memtag";
288  if (hasAttribute(Attribute::AlwaysInline))
289  return "alwaysinline";
290  if (hasAttribute(Attribute::ArgMemOnly))
291  return "argmemonly";
292  if (hasAttribute(Attribute::Builtin))
293  return "builtin";
295  return "convergent";
296  if (hasAttribute(Attribute::SwiftError))
297  return "swifterror";
298  if (hasAttribute(Attribute::SwiftSelf))
299  return "swiftself";
300  if (hasAttribute(Attribute::InaccessibleMemOnly))
301  return "inaccessiblememonly";
302  if (hasAttribute(Attribute::InaccessibleMemOrArgMemOnly))
303  return "inaccessiblemem_or_argmemonly";
304  if (hasAttribute(Attribute::InAlloca))
305  return "inalloca";
306  if (hasAttribute(Attribute::InlineHint))
307  return "inlinehint";
308  if (hasAttribute(Attribute::InReg))
309  return "inreg";
311  return "jumptable";
312  if (hasAttribute(Attribute::MinSize))
313  return "minsize";
314  if (hasAttribute(Attribute::Naked))
315  return "naked";
316  if (hasAttribute(Attribute::Nest))
317  return "nest";
319  return "noalias";
320  if (hasAttribute(Attribute::NoBuiltin))
321  return "nobuiltin";
322  if (hasAttribute(Attribute::NoCapture))
323  return "nocapture";
324  if (hasAttribute(Attribute::NoDuplicate))
325  return "noduplicate";
326  if (hasAttribute(Attribute::NoFree))
327  return "nofree";
328  if (hasAttribute(Attribute::NoImplicitFloat))
329  return "noimplicitfloat";
330  if (hasAttribute(Attribute::NoInline))
331  return "noinline";
332  if (hasAttribute(Attribute::NonLazyBind))
333  return "nonlazybind";
334  if (hasAttribute(Attribute::NonNull))
335  return "nonnull";
336  if (hasAttribute(Attribute::NoRedZone))
337  return "noredzone";
338  if (hasAttribute(Attribute::NoReturn))
339  return "noreturn";
340  if (hasAttribute(Attribute::NoSync))
341  return "nosync";
342  if (hasAttribute(Attribute::WillReturn))
343  return "willreturn";
344  if (hasAttribute(Attribute::NoCfCheck))
345  return "nocf_check";
346  if (hasAttribute(Attribute::NoRecurse))
347  return "norecurse";
348  if (hasAttribute(Attribute::NoUnwind))
349  return "nounwind";
350  if (hasAttribute(Attribute::OptForFuzzing))
351  return "optforfuzzing";
352  if (hasAttribute(Attribute::OptimizeNone))
353  return "optnone";
354  if (hasAttribute(Attribute::OptimizeForSize))
355  return "optsize";
356  if (hasAttribute(Attribute::ReadNone))
357  return "readnone";
358  if (hasAttribute(Attribute::ReadOnly))
359  return "readonly";
360  if (hasAttribute(Attribute::WriteOnly))
361  return "writeonly";
362  if (hasAttribute(Attribute::Returned))
363  return "returned";
364  if (hasAttribute(Attribute::ReturnsTwice))
365  return "returns_twice";
366  if (hasAttribute(Attribute::SExt))
367  return "signext";
368  if (hasAttribute(Attribute::SpeculativeLoadHardening))
369  return "speculative_load_hardening";
370  if (hasAttribute(Attribute::Speculatable))
371  return "speculatable";
372  if (hasAttribute(Attribute::StackProtect))
373  return "ssp";
374  if (hasAttribute(Attribute::StackProtectReq))
375  return "sspreq";
376  if (hasAttribute(Attribute::StackProtectStrong))
377  return "sspstrong";
378  if (hasAttribute(Attribute::SafeStack))
379  return "safestack";
380  if (hasAttribute(Attribute::ShadowCallStack))
381  return "shadowcallstack";
382  if (hasAttribute(Attribute::StrictFP))
383  return "strictfp";
384  if (hasAttribute(Attribute::StructRet))
385  return "sret";
386  if (hasAttribute(Attribute::SanitizeThread))
387  return "sanitize_thread";
388  if (hasAttribute(Attribute::SanitizeMemory))
389  return "sanitize_memory";
390  if (hasAttribute(Attribute::UWTable))
391  return "uwtable";
392  if (hasAttribute(Attribute::ZExt))
393  return "zeroext";
395  return "cold";
396  if (hasAttribute(Attribute::ImmArg))
397  return "immarg";
398 
399  if (hasAttribute(Attribute::ByVal)) {
400  std::string Result;
401  Result += "byval";
402  if (Type *Ty = getValueAsType()) {
403  raw_string_ostream OS(Result);
404  Result += '(';
405  Ty->print(OS, false, true);
406  OS.flush();
407  Result += ')';
408  }
409  return Result;
410  }
411 
412  // FIXME: These should be output like this:
413  //
414  // align=4
415  // alignstack=8
416  //
417  if (hasAttribute(Attribute::Alignment)) {
418  std::string Result;
419  Result += "align";
420  Result += (InAttrGrp) ? "=" : " ";
421  Result += utostr(getValueAsInt());
422  return Result;
423  }
424 
425  auto AttrWithBytesToString = [&](const char *Name) {
426  std::string Result;
427  Result += Name;
428  if (InAttrGrp) {
429  Result += "=";
430  Result += utostr(getValueAsInt());
431  } else {
432  Result += "(";
433  Result += utostr(getValueAsInt());
434  Result += ")";
435  }
436  return Result;
437  };
438 
439  if (hasAttribute(Attribute::StackAlignment))
440  return AttrWithBytesToString("alignstack");
441 
442  if (hasAttribute(Attribute::Dereferenceable))
443  return AttrWithBytesToString("dereferenceable");
444 
445  if (hasAttribute(Attribute::DereferenceableOrNull))
446  return AttrWithBytesToString("dereferenceable_or_null");
447 
448  if (hasAttribute(Attribute::AllocSize)) {
449  unsigned ElemSize;
450  Optional<unsigned> NumElems;
451  std::tie(ElemSize, NumElems) = getAllocSizeArgs();
452 
453  std::string Result = "allocsize(";
454  Result += utostr(ElemSize);
455  if (NumElems.hasValue()) {
456  Result += ',';
457  Result += utostr(*NumElems);
458  }
459  Result += ')';
460  return Result;
461  }
462 
463  // Convert target-dependent attributes to strings of the form:
464  //
465  // "kind"
466  // "kind" = "value"
467  //
468  if (isStringAttribute()) {
469  std::string Result;
470  Result += (Twine('"') + getKindAsString() + Twine('"')).str();
471 
472  std::string AttrVal = pImpl->getValueAsString();
473  if (AttrVal.empty()) return Result;
474 
475  // Since some attribute strings contain special characters that cannot be
476  // printable, those have to be escaped to make the attribute value printable
477  // as is. e.g. "\01__gnu_mcount_nc"
478  {
479  raw_string_ostream OS(Result);
480  OS << "=\"";
481  printEscapedString(AttrVal, OS);
482  OS << "\"";
483  }
484  return Result;
485  }
486 
487  llvm_unreachable("Unknown attribute");
488 }
489 
491  if (!pImpl && !A.pImpl) return false;
492  if (!pImpl) return true;
493  if (!A.pImpl) return false;
494  return *pImpl < *A.pImpl;
495 }
496 
497 //===----------------------------------------------------------------------===//
498 // AttributeImpl Definition
499 //===----------------------------------------------------------------------===//
500 
501 // Pin the vtables to this file.
503 
504 void EnumAttributeImpl::anchor() {}
505 
506 void IntAttributeImpl::anchor() {}
507 
508 void StringAttributeImpl::anchor() {}
509 
510 void TypeAttributeImpl::anchor() {}
511 
513  if (isStringAttribute()) return false;
514  return getKindAsEnum() == A;
515 }
516 
518  if (!isStringAttribute()) return false;
519  return getKindAsString() == Kind;
520 }
521 
524  return static_cast<const EnumAttributeImpl *>(this)->getEnumKind();
525 }
526 
529  return static_cast<const IntAttributeImpl *>(this)->getValue();
530 }
531 
534  return static_cast<const StringAttributeImpl *>(this)->getStringKind();
535 }
536 
539  return static_cast<const StringAttributeImpl *>(this)->getStringValue();
540 }
541 
544  return static_cast<const TypeAttributeImpl *>(this)->getTypeValue();
545 }
546 
548  // This sorts the attributes with Attribute::AttrKinds coming first (sorted
549  // relative to their enum value) and then strings.
550  if (isEnumAttribute()) {
551  if (AI.isEnumAttribute()) return getKindAsEnum() < AI.getKindAsEnum();
552  if (AI.isIntAttribute()) return true;
553  if (AI.isStringAttribute()) return true;
554  if (AI.isTypeAttribute()) return true;
555  }
556 
557  if (isTypeAttribute()) {
558  if (AI.isEnumAttribute()) return false;
559  if (AI.isTypeAttribute()) {
560  assert(getKindAsEnum() != AI.getKindAsEnum() &&
561  "Comparison of types would be unstable");
562  return getKindAsEnum() < AI.getKindAsEnum();
563  }
564  if (AI.isIntAttribute()) return true;
565  if (AI.isStringAttribute()) return true;
566  }
567 
568  if (isIntAttribute()) {
569  if (AI.isEnumAttribute()) return false;
570  if (AI.isTypeAttribute()) return false;
571  if (AI.isIntAttribute()) {
572  if (getKindAsEnum() == AI.getKindAsEnum())
573  return getValueAsInt() < AI.getValueAsInt();
574  return getKindAsEnum() < AI.getKindAsEnum();
575  }
576  if (AI.isStringAttribute()) return true;
577  }
578 
580  if (AI.isEnumAttribute()) return false;
581  if (AI.isTypeAttribute()) return false;
582  if (AI.isIntAttribute()) return false;
583  if (getKindAsString() == AI.getKindAsString())
584  return getValueAsString() < AI.getValueAsString();
585  return getKindAsString() < AI.getKindAsString();
586 }
587 
588 //===----------------------------------------------------------------------===//
589 // AttributeSet Definition
590 //===----------------------------------------------------------------------===//
591 
593  return AttributeSet(AttributeSetNode::get(C, B));
594 }
595 
597  return AttributeSet(AttributeSetNode::get(C, Attrs));
598 }
599 
601  Attribute::AttrKind Kind) const {
602  if (hasAttribute(Kind)) return *this;
603  AttrBuilder B;
604  B.addAttribute(Kind);
605  return addAttributes(C, AttributeSet::get(C, B));
606 }
607 
609  StringRef Value) const {
610  AttrBuilder B;
611  B.addAttribute(Kind, Value);
612  return addAttributes(C, AttributeSet::get(C, B));
613 }
614 
616  const AttributeSet AS) const {
617  if (!hasAttributes())
618  return AS;
619 
620  if (!AS.hasAttributes())
621  return *this;
622 
623  AttrBuilder B(AS);
624  for (const auto I : *this)
625  B.addAttribute(I);
626 
627  return get(C, B);
628 }
629 
631  Attribute::AttrKind Kind) const {
632  if (!hasAttribute(Kind)) return *this;
633  AttrBuilder B(*this);
634  B.removeAttribute(Kind);
635  return get(C, B);
636 }
637 
639  StringRef Kind) const {
640  if (!hasAttribute(Kind)) return *this;
641  AttrBuilder B(*this);
642  B.removeAttribute(Kind);
643  return get(C, B);
644 }
645 
647  const AttrBuilder &Attrs) const {
648  AttrBuilder B(*this);
649  B.remove(Attrs);
650  return get(C, B);
651 }
652 
654  return SetNode ? SetNode->getNumAttributes() : 0;
655 }
656 
658  return SetNode ? SetNode->hasAttribute(Kind) : false;
659 }
660 
662  return SetNode ? SetNode->hasAttribute(Kind) : false;
663 }
664 
666  return SetNode ? SetNode->getAttribute(Kind) : Attribute();
667 }
668 
670  return SetNode ? SetNode->getAttribute(Kind) : Attribute();
671 }
672 
673 unsigned AttributeSet::getAlignment() const {
674  return SetNode ? SetNode->getAlignment() : 0;
675 }
676 
678  return SetNode ? SetNode->getStackAlignment() : 0;
679 }
680 
682  return SetNode ? SetNode->getDereferenceableBytes() : 0;
683 }
684 
686  return SetNode ? SetNode->getDereferenceableOrNullBytes() : 0;
687 }
688 
690  return SetNode ? SetNode->getByValType() : nullptr;
691 }
692 
693 std::pair<unsigned, Optional<unsigned>> AttributeSet::getAllocSizeArgs() const {
694  return SetNode ? SetNode->getAllocSizeArgs()
695  : std::pair<unsigned, Optional<unsigned>>(0, 0);
696 }
697 
698 std::string AttributeSet::getAsString(bool InAttrGrp) const {
699  return SetNode ? SetNode->getAsString(InAttrGrp) : "";
700 }
701 
703  return SetNode ? SetNode->begin() : nullptr;
704 }
705 
707  return SetNode ? SetNode->end() : nullptr;
708 }
709 
710 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
712  dbgs() << "AS =\n";
713  dbgs() << " { ";
714  dbgs() << getAsString(true) << " }\n";
715 }
716 #endif
717 
718 //===----------------------------------------------------------------------===//
719 // AttributeSetNode Definition
720 //===----------------------------------------------------------------------===//
721 
722 AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
723  : NumAttrs(Attrs.size()) {
724  // There's memory after the node where we can store the entries in.
725  llvm::copy(Attrs, getTrailingObjects<Attribute>());
726 
727  static_assert(Attribute::EndAttrKinds <=
728  sizeof(AvailableAttrs) * CHAR_BIT,
729  "Too many attributes");
730 
731  for (const auto I : *this) {
732  if (!I.isStringAttribute()) {
733  Attribute::AttrKind Kind = I.getKindAsEnum();
734  AvailableAttrs[Kind / 8] |= 1ULL << (Kind % 8);
735  }
736  }
737 }
738 
740  ArrayRef<Attribute> Attrs) {
741  if (Attrs.empty())
742  return nullptr;
743 
744  // Otherwise, build a key to look up the existing attributes.
745  LLVMContextImpl *pImpl = C.pImpl;
747 
748  SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
749  llvm::sort(SortedAttrs);
750 
751  for (const auto Attr : SortedAttrs)
752  Attr.Profile(ID);
753 
754  void *InsertPoint;
755  AttributeSetNode *PA =
756  pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint);
757 
758  // If we didn't find any existing attributes of the same shape then create a
759  // new one and insert it.
760  if (!PA) {
761  // Coallocate entries after the AttributeSetNode itself.
762  void *Mem = ::operator new(totalSizeToAlloc<Attribute>(SortedAttrs.size()));
763  PA = new (Mem) AttributeSetNode(SortedAttrs);
764  pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint);
765  }
766 
767  // Return the AttributeSetNode that we found or created.
768  return PA;
769 }
770 
772  // Add target-independent attributes.
776  if (!B.contains(Kind))
777  continue;
778 
779  Attribute Attr;
780  switch (Kind) {
781  case Attribute::ByVal:
783  break;
784  case Attribute::Alignment:
786  break;
787  case Attribute::StackAlignment:
789  break;
790  case Attribute::Dereferenceable:
792  C, B.getDereferenceableBytes());
793  break;
794  case Attribute::DereferenceableOrNull:
797  break;
798  case Attribute::AllocSize: {
799  auto A = B.getAllocSizeArgs();
800  Attr = Attribute::getWithAllocSizeArgs(C, A.first, A.second);
801  break;
802  }
803  default:
804  Attr = Attribute::get(C, Kind);
805  }
806  Attrs.push_back(Attr);
807  }
808 
809  // Add target-dependent (string) attributes.
810  for (const auto &TDA : B.td_attrs())
811  Attrs.emplace_back(Attribute::get(C, TDA.first, TDA.second));
812 
813  return get(C, Attrs);
814 }
815 
817  for (const auto I : *this)
818  if (I.hasAttribute(Kind))
819  return true;
820  return false;
821 }
822 
824  if (hasAttribute(Kind)) {
825  for (const auto I : *this)
826  if (I.hasAttribute(Kind))
827  return I;
828  }
829  return {};
830 }
831 
833  for (const auto I : *this)
834  if (I.hasAttribute(Kind))
835  return I;
836  return {};
837 }
838 
840  for (const auto I : *this)
841  if (I.hasAttribute(Attribute::Alignment))
842  return I.getAlignment();
843  return 0;
844 }
845 
847  for (const auto I : *this)
848  if (I.hasAttribute(Attribute::StackAlignment))
849  return I.getStackAlignment();
850  return 0;
851 }
852 
854  for (const auto I : *this)
855  if (I.hasAttribute(Attribute::ByVal))
856  return I.getValueAsType();
857  return 0;
858 }
859 
861  for (const auto I : *this)
862  if (I.hasAttribute(Attribute::Dereferenceable))
863  return I.getDereferenceableBytes();
864  return 0;
865 }
866 
868  for (const auto I : *this)
869  if (I.hasAttribute(Attribute::DereferenceableOrNull))
870  return I.getDereferenceableOrNullBytes();
871  return 0;
872 }
873 
874 std::pair<unsigned, Optional<unsigned>>
876  for (const auto I : *this)
877  if (I.hasAttribute(Attribute::AllocSize))
878  return I.getAllocSizeArgs();
879  return std::make_pair(0, 0);
880 }
881 
882 std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
883  std::string Str;
884  for (iterator I = begin(), E = end(); I != E; ++I) {
885  if (I != begin())
886  Str += ' ';
887  Str += I->getAsString(InAttrGrp);
888  }
889  return Str;
890 }
891 
892 //===----------------------------------------------------------------------===//
893 // AttributeListImpl Definition
894 //===----------------------------------------------------------------------===//
895 
896 /// Map from AttributeList index to the internal array index. Adding one happens
897 /// to work, but it relies on unsigned integer wrapping. MSVC warns about
898 /// unsigned wrapping in constexpr functions, so write out the conditional. LLVM
899 /// folds it to add anyway.
900 static constexpr unsigned attrIdxToArrayIdx(unsigned Index) {
901  return Index == AttributeList::FunctionIndex ? 0 : Index + 1;
902 }
903 
906  : Context(C), NumAttrSets(Sets.size()) {
907  assert(!Sets.empty() && "pointless AttributeListImpl");
908 
909  // There's memory after the node where we can store the entries in.
910  llvm::copy(Sets, getTrailingObjects<AttributeSet>());
911 
912  // Initialize AvailableFunctionAttrs summary bitset.
913  static_assert(Attribute::EndAttrKinds <=
914  sizeof(AvailableFunctionAttrs) * CHAR_BIT,
915  "Too many attributes");
916  static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U,
917  "function should be stored in slot 0");
918  for (const auto I : Sets[0]) {
919  if (!I.isStringAttribute()) {
920  Attribute::AttrKind Kind = I.getKindAsEnum();
921  AvailableFunctionAttrs[Kind / 8] |= 1ULL << (Kind % 8);
922  }
923  }
924 }
925 
927  Profile(ID, makeArrayRef(begin(), end()));
928 }
929 
931  ArrayRef<AttributeSet> Sets) {
932  for (const auto &Set : Sets)
933  ID.AddPointer(Set.SetNode);
934 }
935 
936 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
938  AttributeList(const_cast<AttributeListImpl *>(this)).dump();
939 }
940 #endif
941 
942 //===----------------------------------------------------------------------===//
943 // AttributeList Construction and Mutation Methods
944 //===----------------------------------------------------------------------===//
945 
947  ArrayRef<AttributeSet> AttrSets) {
948  assert(!AttrSets.empty() && "pointless AttributeListImpl");
949 
950  LLVMContextImpl *pImpl = C.pImpl;
952  AttributeListImpl::Profile(ID, AttrSets);
953 
954  void *InsertPoint;
955  AttributeListImpl *PA =
956  pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint);
957 
958  // If we didn't find any existing attributes of the same shape then
959  // create a new one and insert it.
960  if (!PA) {
961  // Coallocate entries after the AttributeListImpl itself.
962  void *Mem = ::operator new(
963  AttributeListImpl::totalSizeToAlloc<AttributeSet>(AttrSets.size()));
964  PA = new (Mem) AttributeListImpl(C, AttrSets);
965  pImpl->AttrsLists.InsertNode(PA, InsertPoint);
966  }
967 
968  // Return the AttributesList that we found or created.
969  return AttributeList(PA);
970 }
971 
974  ArrayRef<std::pair<unsigned, Attribute>> Attrs) {
975  // If there are no attributes then return a null AttributesList pointer.
976  if (Attrs.empty())
977  return {};
978 
979  assert(std::is_sorted(Attrs.begin(), Attrs.end(),
980  [](const std::pair<unsigned, Attribute> &LHS,
981  const std::pair<unsigned, Attribute> &RHS) {
982  return LHS.first < RHS.first;
983  }) && "Misordered Attributes list!");
984  assert(llvm::none_of(Attrs,
985  [](const std::pair<unsigned, Attribute> &Pair) {
986  return Pair.second.hasAttribute(Attribute::None);
987  }) &&
988  "Pointless attribute!");
989 
990  // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes
991  // list.
993  for (ArrayRef<std::pair<unsigned, Attribute>>::iterator I = Attrs.begin(),
994  E = Attrs.end(); I != E; ) {
995  unsigned Index = I->first;
997  while (I != E && I->first == Index) {
998  AttrVec.push_back(I->second);
999  ++I;
1000  }
1001 
1002  AttrPairVec.emplace_back(Index, AttributeSet::get(C, AttrVec));
1003  }
1004 
1005  return get(C, AttrPairVec);
1006 }
1007 
1010  ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) {
1011  // If there are no attributes then return a null AttributesList pointer.
1012  if (Attrs.empty())
1013  return {};
1014 
1015  assert(std::is_sorted(Attrs.begin(), Attrs.end(),
1016  [](const std::pair<unsigned, AttributeSet> &LHS,
1017  const std::pair<unsigned, AttributeSet> &RHS) {
1018  return LHS.first < RHS.first;
1019  }) &&
1020  "Misordered Attributes list!");
1021  assert(llvm::none_of(Attrs,
1022  [](const std::pair<unsigned, AttributeSet> &Pair) {
1023  return !Pair.second.hasAttributes();
1024  }) &&
1025  "Pointless attribute!");
1026 
1027  unsigned MaxIndex = Attrs.back().first;
1028  // If the MaxIndex is FunctionIndex and there are other indices in front
1029  // of it, we need to use the largest of those to get the right size.
1030  if (MaxIndex == FunctionIndex && Attrs.size() > 1)
1031  MaxIndex = Attrs[Attrs.size() - 2].first;
1032 
1033  SmallVector<AttributeSet, 4> AttrVec(attrIdxToArrayIdx(MaxIndex) + 1);
1034  for (const auto Pair : Attrs)
1035  AttrVec[attrIdxToArrayIdx(Pair.first)] = Pair.second;
1036 
1037  return getImpl(C, AttrVec);
1038 }
1039 
1041  AttributeSet RetAttrs,
1042  ArrayRef<AttributeSet> ArgAttrs) {
1043  // Scan from the end to find the last argument with attributes. Most
1044  // arguments don't have attributes, so it's nice if we can have fewer unique
1045  // AttributeListImpls by dropping empty attribute sets at the end of the list.
1046  unsigned NumSets = 0;
1047  for (size_t I = ArgAttrs.size(); I != 0; --I) {
1048  if (ArgAttrs[I - 1].hasAttributes()) {
1049  NumSets = I + 2;
1050  break;
1051  }
1052  }
1053  if (NumSets == 0) {
1054  // Check function and return attributes if we didn't have argument
1055  // attributes.
1056  if (RetAttrs.hasAttributes())
1057  NumSets = 2;
1058  else if (FnAttrs.hasAttributes())
1059  NumSets = 1;
1060  }
1061 
1062  // If all attribute sets were empty, we can use the empty attribute list.
1063  if (NumSets == 0)
1064  return {};
1065 
1067  AttrSets.reserve(NumSets);
1068  // If we have any attributes, we always have function attributes.
1069  AttrSets.push_back(FnAttrs);
1070  if (NumSets > 1)
1071  AttrSets.push_back(RetAttrs);
1072  if (NumSets > 2) {
1073  // Drop the empty argument attribute sets at the end.
1074  ArgAttrs = ArgAttrs.take_front(NumSets - 2);
1075  AttrSets.insert(AttrSets.end(), ArgAttrs.begin(), ArgAttrs.end());
1076  }
1077 
1078  return getImpl(C, AttrSets);
1079 }
1080 
1082  const AttrBuilder &B) {
1083  if (!B.hasAttributes())
1084  return {};
1085  Index = attrIdxToArrayIdx(Index);
1086  SmallVector<AttributeSet, 8> AttrSets(Index + 1);
1087  AttrSets[Index] = AttributeSet::get(C, B);
1088  return getImpl(C, AttrSets);
1089 }
1090 
1094  for (const auto K : Kinds)
1095  Attrs.emplace_back(Index, Attribute::get(C, K));
1096  return get(C, Attrs);
1097 }
1098 
1100  ArrayRef<StringRef> Kinds) {
1102  for (const auto K : Kinds)
1103  Attrs.emplace_back(Index, Attribute::get(C, K));
1104  return get(C, Attrs);
1105 }
1106 
1108  ArrayRef<AttributeList> Attrs) {
1109  if (Attrs.empty())
1110  return {};
1111  if (Attrs.size() == 1)
1112  return Attrs[0];
1113 
1114  unsigned MaxSize = 0;
1115  for (const auto List : Attrs)
1116  MaxSize = std::max(MaxSize, List.getNumAttrSets());
1117 
1118  // If every list was empty, there is no point in merging the lists.
1119  if (MaxSize == 0)
1120  return {};
1121 
1122  SmallVector<AttributeSet, 8> NewAttrSets(MaxSize);
1123  for (unsigned I = 0; I < MaxSize; ++I) {
1124  AttrBuilder CurBuilder;
1125  for (const auto List : Attrs)
1126  CurBuilder.merge(List.getAttributes(I - 1));
1127  NewAttrSets[I] = AttributeSet::get(C, CurBuilder);
1128  }
1129 
1130  return getImpl(C, NewAttrSets);
1131 }
1132 
1134  Attribute::AttrKind Kind) const {
1135  if (hasAttribute(Index, Kind)) return *this;
1136  AttrBuilder B;
1137  B.addAttribute(Kind);
1138  return addAttributes(C, Index, B);
1139 }
1140 
1142  StringRef Kind,
1143  StringRef Value) const {
1144  AttrBuilder B;
1145  B.addAttribute(Kind, Value);
1146  return addAttributes(C, Index, B);
1147 }
1148 
1150  Attribute A) const {
1151  AttrBuilder B;
1152  B.addAttribute(A);
1153  return addAttributes(C, Index, B);
1154 }
1155 
1157  const AttrBuilder &B) const {
1158  if (!B.hasAttributes())
1159  return *this;
1160 
1161  if (!pImpl)
1162  return AttributeList::get(C, {{Index, AttributeSet::get(C, B)}});
1163 
1164 #ifndef NDEBUG
1165  // FIXME it is not obvious how this should work for alignment. For now, say
1166  // we can't change a known alignment.
1167  unsigned OldAlign = getAttributes(Index).getAlignment();
1168  unsigned NewAlign = B.getAlignment();
1169  assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
1170  "Attempt to change alignment!");
1171 #endif
1172 
1173  Index = attrIdxToArrayIdx(Index);
1174  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1175  if (Index >= AttrSets.size())
1176  AttrSets.resize(Index + 1);
1177 
1178  AttrBuilder Merged(AttrSets[Index]);
1179  Merged.merge(B);
1180  AttrSets[Index] = AttributeSet::get(C, Merged);
1181 
1182  return getImpl(C, AttrSets);
1183 }
1184 
1186  ArrayRef<unsigned> ArgNos,
1187  Attribute A) const {
1188  assert(std::is_sorted(ArgNos.begin(), ArgNos.end()));
1189 
1190  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1191  unsigned MaxIndex = attrIdxToArrayIdx(ArgNos.back() + FirstArgIndex);
1192  if (MaxIndex >= AttrSets.size())
1193  AttrSets.resize(MaxIndex + 1);
1194 
1195  for (unsigned ArgNo : ArgNos) {
1196  unsigned Index = attrIdxToArrayIdx(ArgNo + FirstArgIndex);
1197  AttrBuilder B(AttrSets[Index]);
1198  B.addAttribute(A);
1199  AttrSets[Index] = AttributeSet::get(C, B);
1200  }
1201 
1202  return getImpl(C, AttrSets);
1203 }
1204 
1206  Attribute::AttrKind Kind) const {
1207  if (!hasAttribute(Index, Kind)) return *this;
1208 
1209  Index = attrIdxToArrayIdx(Index);
1210  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1211  assert(Index < AttrSets.size());
1212 
1213  AttrSets[Index] = AttrSets[Index].removeAttribute(C, Kind);
1214 
1215  return getImpl(C, AttrSets);
1216 }
1217 
1219  StringRef Kind) const {
1220  if (!hasAttribute(Index, Kind)) return *this;
1221 
1222  Index = attrIdxToArrayIdx(Index);
1223  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1224  assert(Index < AttrSets.size());
1225 
1226  AttrSets[Index] = AttrSets[Index].removeAttribute(C, Kind);
1227 
1228  return getImpl(C, AttrSets);
1229 }
1230 
1233  const AttrBuilder &AttrsToRemove) const {
1234  if (!pImpl)
1235  return {};
1236 
1237  Index = attrIdxToArrayIdx(Index);
1238  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1239  if (Index >= AttrSets.size())
1240  AttrSets.resize(Index + 1);
1241 
1242  AttrSets[Index] = AttrSets[Index].removeAttributes(C, AttrsToRemove);
1243 
1244  return getImpl(C, AttrSets);
1245 }
1246 
1248  unsigned WithoutIndex) const {
1249  if (!pImpl)
1250  return {};
1251  WithoutIndex = attrIdxToArrayIdx(WithoutIndex);
1252  if (WithoutIndex >= getNumAttrSets())
1253  return *this;
1254  SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
1255  AttrSets[WithoutIndex] = AttributeSet();
1256  return getImpl(C, AttrSets);
1257 }
1258 
1260  unsigned Index,
1261  uint64_t Bytes) const {
1262  AttrBuilder B;
1263  B.addDereferenceableAttr(Bytes);
1264  return addAttributes(C, Index, B);
1265 }
1266 
1269  uint64_t Bytes) const {
1270  AttrBuilder B;
1272  return addAttributes(C, Index, B);
1273 }
1274 
1277  unsigned ElemSizeArg,
1278  const Optional<unsigned> &NumElemsArg) {
1279  AttrBuilder B;
1280  B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1281  return addAttributes(C, Index, B);
1282 }
1283 
1284 //===----------------------------------------------------------------------===//
1285 // AttributeList Accessor Methods
1286 //===----------------------------------------------------------------------===//
1287 
1288 LLVMContext &AttributeList::getContext() const { return pImpl->getContext(); }
1289 
1291  return getAttributes(ArgNo + FirstArgIndex);
1292 }
1293 
1295  return getAttributes(ReturnIndex);
1296 }
1297 
1299  return getAttributes(FunctionIndex);
1300 }
1301 
1303  Attribute::AttrKind Kind) const {
1304  return getAttributes(Index).hasAttribute(Kind);
1305 }
1306 
1308  return getAttributes(Index).hasAttribute(Kind);
1309 }
1310 
1311 bool AttributeList::hasAttributes(unsigned Index) const {
1312  return getAttributes(Index).hasAttributes();
1313 }
1314 
1316  return pImpl && pImpl->hasFnAttribute(Kind);
1317 }
1318 
1320  return hasAttribute(AttributeList::FunctionIndex, Kind);
1321 }
1322 
1324  Attribute::AttrKind Kind) const {
1325  return hasAttribute(ArgNo + FirstArgIndex, Kind);
1326 }
1327 
1329  unsigned *Index) const {
1330  if (!pImpl) return false;
1331 
1332  for (unsigned I = index_begin(), E = index_end(); I != E; ++I) {
1333  if (hasAttribute(I, Attr)) {
1334  if (Index)
1335  *Index = I;
1336  return true;
1337  }
1338  }
1339 
1340  return false;
1341 }
1342 
1344  Attribute::AttrKind Kind) const {
1345  return getAttributes(Index).getAttribute(Kind);
1346 }
1347 
1349  return getAttributes(Index).getAttribute(Kind);
1350 }
1351 
1353  return getAttributes(ReturnIndex).getAlignment();
1354 }
1355 
1356 unsigned AttributeList::getParamAlignment(unsigned ArgNo) const {
1357  return getAttributes(ArgNo + FirstArgIndex).getAlignment();
1358 }
1359 
1361  return getAttributes(Index+FirstArgIndex).getByValType();
1362 }
1363 
1364 
1365 unsigned AttributeList::getStackAlignment(unsigned Index) const {
1366  return getAttributes(Index).getStackAlignment();
1367 }
1368 
1370  return getAttributes(Index).getDereferenceableBytes();
1371 }
1372 
1375 }
1376 
1377 std::pair<unsigned, Optional<unsigned>>
1379  return getAttributes(Index).getAllocSizeArgs();
1380 }
1381 
1382 std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const {
1383  return getAttributes(Index).getAsString(InAttrGrp);
1384 }
1385 
1387  Index = attrIdxToArrayIdx(Index);
1388  if (!pImpl || Index >= getNumAttrSets())
1389  return {};
1390  return pImpl->begin()[Index];
1391 }
1392 
1394  return pImpl ? pImpl->begin() : nullptr;
1395 }
1396 
1398  return pImpl ? pImpl->end() : nullptr;
1399 }
1400 
1401 //===----------------------------------------------------------------------===//
1402 // AttributeList Introspection Methods
1403 //===----------------------------------------------------------------------===//
1404 
1406  return pImpl ? pImpl->NumAttrSets : 0;
1407 }
1408 
1409 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1411  dbgs() << "PAL[\n";
1412 
1413  for (unsigned i = index_begin(), e = index_end(); i != e; ++i) {
1414  if (getAttributes(i).hasAttributes())
1415  dbgs() << " { " << i << " => " << getAsString(i) << " }\n";
1416  }
1417 
1418  dbgs() << "]\n";
1419 }
1420 #endif
1421 
1422 //===----------------------------------------------------------------------===//
1423 // AttrBuilder Method Implementations
1424 //===----------------------------------------------------------------------===//
1425 
1426 // FIXME: Remove this ctor, use AttributeSet.
1428  AttributeSet AS = AL.getAttributes(Index);
1429  for (const auto &A : AS)
1430  addAttribute(A);
1431 }
1432 
1434  for (const auto &A : AS)
1435  addAttribute(A);
1436 }
1437 
1439  Attrs.reset();
1440  TargetDepAttrs.clear();
1441  Alignment.reset();
1442  StackAlignment.reset();
1443  DerefBytes = DerefOrNullBytes = 0;
1444  AllocSizeArgs = 0;
1445  ByValType = nullptr;
1446 }
1447 
1449  assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1450  assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
1451  Val != Attribute::Dereferenceable && Val != Attribute::AllocSize &&
1452  "Adding integer attribute without adding a value!");
1453  Attrs[Val] = true;
1454  return *this;
1455 }
1456 
1458  if (Attr.isStringAttribute()) {
1459  addAttribute(Attr.getKindAsString(), Attr.getValueAsString());
1460  return *this;
1461  }
1462 
1464  Attrs[Kind] = true;
1465 
1466  if (Kind == Attribute::Alignment)
1467  Alignment = MaybeAlign(Attr.getAlignment());
1468  else if (Kind == Attribute::StackAlignment)
1469  StackAlignment = MaybeAlign(Attr.getStackAlignment());
1470  else if (Kind == Attribute::ByVal)
1471  ByValType = Attr.getValueAsType();
1472  else if (Kind == Attribute::Dereferenceable)
1473  DerefBytes = Attr.getDereferenceableBytes();
1474  else if (Kind == Attribute::DereferenceableOrNull)
1475  DerefOrNullBytes = Attr.getDereferenceableOrNullBytes();
1476  else if (Kind == Attribute::AllocSize)
1477  AllocSizeArgs = Attr.getValueAsInt();
1478  return *this;
1479 }
1480 
1482  TargetDepAttrs[A] = V;
1483  return *this;
1484 }
1485 
1487  assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1488  Attrs[Val] = false;
1489 
1490  if (Val == Attribute::Alignment)
1491  Alignment.reset();
1492  else if (Val == Attribute::StackAlignment)
1493  StackAlignment.reset();
1494  else if (Val == Attribute::ByVal)
1495  ByValType = nullptr;
1496  else if (Val == Attribute::Dereferenceable)
1497  DerefBytes = 0;
1498  else if (Val == Attribute::DereferenceableOrNull)
1499  DerefOrNullBytes = 0;
1500  else if (Val == Attribute::AllocSize)
1501  AllocSizeArgs = 0;
1502 
1503  return *this;
1504 }
1505 
1507  remove(A.getAttributes(Index));
1508  return *this;
1509 }
1510 
1512  auto I = TargetDepAttrs.find(A);
1513  if (I != TargetDepAttrs.end())
1514  TargetDepAttrs.erase(I);
1515  return *this;
1516 }
1517 
1518 std::pair<unsigned, Optional<unsigned>> AttrBuilder::getAllocSizeArgs() const {
1519  return unpackAllocSizeArgs(AllocSizeArgs);
1520 }
1521 
1523  MaybeAlign Align(A);
1524  if (!Align)
1525  return *this;
1526 
1527  assert(*Align <= 0x40000000 && "Alignment too large.");
1528 
1529  Attrs[Attribute::Alignment] = true;
1530  Alignment = Align;
1531  return *this;
1532 }
1533 
1535  MaybeAlign Align(A);
1536  // Default alignment, allow the target to define how to align it.
1537  if (!Align)
1538  return *this;
1539 
1540  assert(*Align <= 0x100 && "Alignment too large.");
1541 
1542  Attrs[Attribute::StackAlignment] = true;
1543  StackAlignment = Align;
1544  return *this;
1545 }
1546 
1548  if (Bytes == 0) return *this;
1549 
1550  Attrs[Attribute::Dereferenceable] = true;
1551  DerefBytes = Bytes;
1552  return *this;
1553 }
1554 
1556  if (Bytes == 0)
1557  return *this;
1558 
1559  Attrs[Attribute::DereferenceableOrNull] = true;
1560  DerefOrNullBytes = Bytes;
1561  return *this;
1562 }
1563 
1565  const Optional<unsigned> &NumElems) {
1566  return addAllocSizeAttrFromRawRepr(packAllocSizeArgs(ElemSize, NumElems));
1567 }
1568 
1570  // (0, 0) is our "not present" value, so we need to check for it here.
1571  assert(RawArgs && "Invalid allocsize arguments -- given allocsize(0, 0)");
1572 
1573  Attrs[Attribute::AllocSize] = true;
1574  // Reuse existing machinery to store this as a single 64-bit integer so we can
1575  // save a few bytes over using a pair<unsigned, Optional<unsigned>>.
1576  AllocSizeArgs = RawArgs;
1577  return *this;
1578 }
1579 
1581  Attrs[Attribute::ByVal] = true;
1582  ByValType = Ty;
1583  return *this;
1584 }
1585 
1587  // FIXME: What if both have alignments, but they don't match?!
1588  if (!Alignment)
1589  Alignment = B.Alignment;
1590 
1591  if (!StackAlignment)
1592  StackAlignment = B.StackAlignment;
1593 
1594  if (!DerefBytes)
1595  DerefBytes = B.DerefBytes;
1596 
1597  if (!DerefOrNullBytes)
1598  DerefOrNullBytes = B.DerefOrNullBytes;
1599 
1600  if (!AllocSizeArgs)
1601  AllocSizeArgs = B.AllocSizeArgs;
1602 
1603  if (!ByValType)
1604  ByValType = B.ByValType;
1605 
1606  Attrs |= B.Attrs;
1607 
1608  for (auto I : B.td_attrs())
1609  TargetDepAttrs[I.first] = I.second;
1610 
1611  return *this;
1612 }
1613 
1615  // FIXME: What if both have alignments, but they don't match?!
1616  if (B.Alignment)
1617  Alignment.reset();
1618 
1619  if (B.StackAlignment)
1620  StackAlignment.reset();
1621 
1622  if (B.DerefBytes)
1623  DerefBytes = 0;
1624 
1625  if (B.DerefOrNullBytes)
1626  DerefOrNullBytes = 0;
1627 
1628  if (B.AllocSizeArgs)
1629  AllocSizeArgs = 0;
1630 
1631  if (B.ByValType)
1632  ByValType = nullptr;
1633 
1634  Attrs &= ~B.Attrs;
1635 
1636  for (auto I : B.td_attrs())
1637  TargetDepAttrs.erase(I.first);
1638 
1639  return *this;
1640 }
1641 
1643  // First check if any of the target independent attributes overlap.
1644  if ((Attrs & B.Attrs).any())
1645  return true;
1646 
1647  // Then check if any target dependent ones do.
1648  for (const auto &I : td_attrs())
1649  if (B.contains(I.first))
1650  return true;
1651 
1652  return false;
1653 }
1654 
1656  return TargetDepAttrs.find(A) != TargetDepAttrs.end();
1657 }
1658 
1660  return !Attrs.none() || !TargetDepAttrs.empty();
1661 }
1662 
1664  AttributeSet AS = AL.getAttributes(Index);
1665 
1666  for (const auto Attr : AS) {
1667  if (Attr.isEnumAttribute() || Attr.isIntAttribute()) {
1668  if (contains(Attr.getKindAsEnum()))
1669  return true;
1670  } else {
1671  assert(Attr.isStringAttribute() && "Invalid attribute kind!");
1672  return contains(Attr.getKindAsString());
1673  }
1674  }
1675 
1676  return false;
1677 }
1678 
1680  return Alignment != 0;
1681 }
1682 
1684  if (Attrs != B.Attrs)
1685  return false;
1686 
1687  for (td_const_iterator I = TargetDepAttrs.begin(),
1688  E = TargetDepAttrs.end(); I != E; ++I)
1689  if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end())
1690  return false;
1691 
1692  return Alignment == B.Alignment && StackAlignment == B.StackAlignment &&
1693  DerefBytes == B.DerefBytes && ByValType == B.ByValType;
1694 }
1695 
1696 //===----------------------------------------------------------------------===//
1697 // AttributeFuncs Function Defintions
1698 //===----------------------------------------------------------------------===//
1699 
1700 /// Which attributes cannot be applied to a type.
1702  AttrBuilder Incompatible;
1703 
1704  if (!Ty->isIntegerTy())
1705  // Attribute that only apply to integers.
1706  Incompatible.addAttribute(Attribute::SExt)
1707  .addAttribute(Attribute::ZExt);
1708 
1709  if (!Ty->isPointerTy())
1710  // Attribute that only apply to pointers.
1711  Incompatible.addAttribute(Attribute::ByVal)
1712  .addAttribute(Attribute::Nest)
1714  .addAttribute(Attribute::NoCapture)
1715  .addAttribute(Attribute::NonNull)
1716  .addDereferenceableAttr(1) // the int here is ignored
1717  .addDereferenceableOrNullAttr(1) // the int here is ignored
1718  .addAttribute(Attribute::ReadNone)
1719  .addAttribute(Attribute::ReadOnly)
1720  .addAttribute(Attribute::StructRet)
1721  .addAttribute(Attribute::InAlloca);
1722 
1723  return Incompatible;
1724 }
1725 
1726 template<typename AttrClass>
1727 static bool isEqual(const Function &Caller, const Function &Callee) {
1728  return Caller.getFnAttribute(AttrClass::getKind()) ==
1729  Callee.getFnAttribute(AttrClass::getKind());
1730 }
1731 
1732 /// Compute the logical AND of the attributes of the caller and the
1733 /// callee.
1734 ///
1735 /// This function sets the caller's attribute to false if the callee's attribute
1736 /// is false.
1737 template<typename AttrClass>
1738 static void setAND(Function &Caller, const Function &Callee) {
1739  if (AttrClass::isSet(Caller, AttrClass::getKind()) &&
1740  !AttrClass::isSet(Callee, AttrClass::getKind()))
1741  AttrClass::set(Caller, AttrClass::getKind(), false);
1742 }
1743 
1744 /// Compute the logical OR of the attributes of the caller and the
1745 /// callee.
1746 ///
1747 /// This function sets the caller's attribute to true if the callee's attribute
1748 /// is true.
1749 template<typename AttrClass>
1750 static void setOR(Function &Caller, const Function &Callee) {
1751  if (!AttrClass::isSet(Caller, AttrClass::getKind()) &&
1752  AttrClass::isSet(Callee, AttrClass::getKind()))
1753  AttrClass::set(Caller, AttrClass::getKind(), true);
1754 }
1755 
1756 /// If the inlined function had a higher stack protection level than the
1757 /// calling function, then bump up the caller's stack protection level.
1758 static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) {
1759  // If upgrading the SSP attribute, clear out the old SSP Attributes first.
1760  // Having multiple SSP attributes doesn't actually hurt, but it adds useless
1761  // clutter to the IR.
1762  AttrBuilder OldSSPAttr;
1763  OldSSPAttr.addAttribute(Attribute::StackProtect)
1764  .addAttribute(Attribute::StackProtectStrong)
1765  .addAttribute(Attribute::StackProtectReq);
1766 
1767  if (Callee.hasFnAttribute(Attribute::StackProtectReq)) {
1768  Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
1769  Caller.addFnAttr(Attribute::StackProtectReq);
1770  } else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
1771  !Caller.hasFnAttribute(Attribute::StackProtectReq)) {
1772  Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
1773  Caller.addFnAttr(Attribute::StackProtectStrong);
1774  } else if (Callee.hasFnAttribute(Attribute::StackProtect) &&
1775  !Caller.hasFnAttribute(Attribute::StackProtectReq) &&
1776  !Caller.hasFnAttribute(Attribute::StackProtectStrong))
1777  Caller.addFnAttr(Attribute::StackProtect);
1778 }
1779 
1780 /// If the inlined function required stack probes, then ensure that
1781 /// the calling function has those too.
1782 static void adjustCallerStackProbes(Function &Caller, const Function &Callee) {
1783  if (!Caller.hasFnAttribute("probe-stack") &&
1784  Callee.hasFnAttribute("probe-stack")) {
1785  Caller.addFnAttr(Callee.getFnAttribute("probe-stack"));
1786  }
1787 }
1788 
1789 /// If the inlined function defines the size of guard region
1790 /// on the stack, then ensure that the calling function defines a guard region
1791 /// that is no larger.
1792 static void
1794  if (Callee.hasFnAttribute("stack-probe-size")) {
1795  uint64_t CalleeStackProbeSize;
1796  Callee.getFnAttribute("stack-probe-size")
1797  .getValueAsString()
1798  .getAsInteger(0, CalleeStackProbeSize);
1799  if (Caller.hasFnAttribute("stack-probe-size")) {
1800  uint64_t CallerStackProbeSize;
1801  Caller.getFnAttribute("stack-probe-size")
1802  .getValueAsString()
1803  .getAsInteger(0, CallerStackProbeSize);
1804  if (CallerStackProbeSize > CalleeStackProbeSize) {
1805  Caller.addFnAttr(Callee.getFnAttribute("stack-probe-size"));
1806  }
1807  } else {
1808  Caller.addFnAttr(Callee.getFnAttribute("stack-probe-size"));
1809  }
1810  }
1811 }
1812 
1813 /// If the inlined function defines a min legal vector width, then ensure
1814 /// the calling function has the same or larger min legal vector width. If the
1815 /// caller has the attribute, but the callee doesn't, we need to remove the
1816 /// attribute from the caller since we can't make any guarantees about the
1817 /// caller's requirements.
1818 /// This function is called after the inlining decision has been made so we have
1819 /// to merge the attribute this way. Heuristics that would use
1820 /// min-legal-vector-width to determine inline compatibility would need to be
1821 /// handled as part of inline cost analysis.
1822 static void
1824  if (Caller.hasFnAttribute("min-legal-vector-width")) {
1825  if (Callee.hasFnAttribute("min-legal-vector-width")) {
1826  uint64_t CallerVectorWidth;
1827  Caller.getFnAttribute("min-legal-vector-width")
1828  .getValueAsString()
1829  .getAsInteger(0, CallerVectorWidth);
1830  uint64_t CalleeVectorWidth;
1831  Callee.getFnAttribute("min-legal-vector-width")
1832  .getValueAsString()
1833  .getAsInteger(0, CalleeVectorWidth);
1834  if (CallerVectorWidth < CalleeVectorWidth)
1835  Caller.addFnAttr(Callee.getFnAttribute("min-legal-vector-width"));
1836  } else {
1837  // If the callee doesn't have the attribute then we don't know anything
1838  // and must drop the attribute from the caller.
1839  Caller.removeFnAttr("min-legal-vector-width");
1840  }
1841  }
1842 }
1843 
1844 /// If the inlined function has "null-pointer-is-valid=true" attribute,
1845 /// set this attribute in the caller post inlining.
1846 static void
1848  if (Callee.nullPointerIsDefined() && !Caller.nullPointerIsDefined()) {
1849  Caller.addFnAttr(Callee.getFnAttribute("null-pointer-is-valid"));
1850  }
1851 }
1852 
1853 #define GET_ATTR_COMPAT_FUNC
1854 #include "AttributesCompatFunc.inc"
1855 
1857  const Function &Callee) {
1858  return hasCompatibleFnAttrs(Caller, Callee);
1859 }
1860 
1862  const Function &Callee) {
1863  mergeFnAttrs(Caller, Callee);
1864 }
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:846
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
Definition: FoldingSet.cpp:51
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:641
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:900
StringRef getKindAsString() const
Return the attribute&#39;s kind as a string.
Definition: Attributes.cpp:216
bool hasAttribute(Attribute::AttrKind A) const
Definition: Attributes.cpp:512
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:211
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Definition: Attributes.cpp:693
LLVMContext & Context
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:157
FoldingSet< AttributeImpl > AttrsSet
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
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:70
This class represents lattice values for constants.
Definition: AllocatorList.h:23
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:476
uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute...
Definition: Attributes.cpp:266
unsigned getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:253
static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:145
iterator begin() const
Definition: ArrayRef.h:136
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:158
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
unsigned getAlignment() const
Definition: Attributes.cpp:839
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:266
iterator begin() const
The two locations do not alias at all.
Definition: AliasAnalysis.h:84
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:823
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:323
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:771
AttributeListImpl(LLVMContext &C, ArrayRef< AttributeSet > Sets)
Definition: Attributes.cpp:904
unsigned getRetAlignment() const
Return the alignment of the return value.
Type * getByValType() const
Retrieve the byval type.
Definition: Attributes.h:793
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
std::string getAsString(bool InAttrGrp) const
Definition: Attributes.cpp:882
void reserve(size_type N)
Definition: SmallVector.h:369
uint64_t getDereferenceableBytes() const
Definition: Attributes.cpp:860
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:926
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:490
uint64_t getDereferenceableOrNullBytes() const
Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists...
Definition: Attributes.h:790
Type * getValueAsType() const
Definition: Attributes.cpp:542
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:685
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:209
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:80
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:194
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:450
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:196
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:164
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:1179
bool isIntAttribute() const
Definition: AttributeImpl.h:59
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:60
AttrBuilder & addByValAttr(Type *Ty)
This turns a byval type into the form used internally in Attribute.
iterator begin() const
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:140
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:677
uint64_t getStackAlignment() const
Retrieve the stack alignment attribute, if it exists.
Definition: Attributes.h:780
Type * getByValType() const
Definition: Attributes.cpp:853
iterator end() const
LLVM_NODISCARD 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.
Type * getValueAsType() const
Return the attribute&#39;s value as a Type.
Definition: Attributes.cpp:230
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:32
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Definition: Attributes.cpp:875
AttrBuilder & remove(const AttrBuilder &B)
Remove the attributes from the builder.
LLVM_NODISCARD AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const
Add attributes to the attribute set.
Definition: Attributes.cpp:615
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:273
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:259
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Definition: Attributes.cpp:657
static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align)
Definition: Attributes.cpp:151
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:305
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:238
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM_NODISCARD AttributeList addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given index.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
Definition: Attributes.cpp:592
std::map< std::string, std::string >::const_iterator td_const_iterator
Definition: Attributes.h:833
bool isTypeAttribute() const
Definition: AttributeImpl.h:61
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:428
LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
Definition: Attributes.h:413
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:64
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:148
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool isStringAttribute() const
Definition: AttributeImpl.h:60
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:223
LLVM_NODISCARD AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
Definition: Attributes.cpp:630
uint64_t getAlignment() const
Retrieve the alignment attribute, if it exists.
Definition: Attributes.h:777
LLVM_NODISCARD AttributeList addAllocSizeAttr(LLVMContext &C, unsigned Index, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Add the allocsize attribute to the attribute set at the given index.
static const unsigned AllocSizeNumElemsNotPresent
Definition: Attributes.cpp:57
unsigned getNumAttributes() const
Return the number of attributes in this set.
Definition: Attributes.cpp:653
iterator begin() const
Definition: Attributes.cpp:702
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:202
bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
Definition: Attributes.cpp:186
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:170
Attribute::AttrKind getKindAsEnum() const
Definition: Attributes.cpp:522
Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
Definition: Attributes.cpp:665
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:547
uint64_t getDereferenceableBytes() const
Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is return...
Definition: Attributes.h:786
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:681
size_t size() const
Definition: SmallVector.h:52
StringRef getKindAsString() const
Definition: Attributes.cpp:532
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:66
LLVM_NODISCARD AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
Definition: Attributes.cpp:600
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1095
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:492
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:698
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:1146
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
Definition: Attributes.h:757
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
Definition: Alignment.h:85
unsigned getAlignment() const
Definition: Attributes.cpp:673
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:837
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:137
bool isTypeAttribute() const
Return true if the attribute is a type attribute.
Definition: Attributes.cpp:198
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:132
void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller&#39;s and callee&#39;s attributes.
unsigned getNumAttrSets() const
amdgpu Simplify well known AMD library false FunctionCallee Callee
bool isEnumAttribute() const
Definition: AttributeImpl.h:58
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:467
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:867
bool isIntAttribute() const
Return true if the attribute is an integer attribute.
Definition: Attributes.cpp:190
bool hasAttribute(Attribute::AttrKind Kind) const
void removeAttributes(unsigned i, const AttrBuilder &Attrs)
removes the attributes from the list of attributes.
Definition: Function.cpp:428
bool hasValue() const
Definition: Optional.h:259
unsigned getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
LLVM_NODISCARD 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:706
unsigned getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:247
LLVM_NODISCARD AttributeList addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:223
LLVM_NODISCARD 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:201
#define I(x, y, z)
Definition: MD5.cpp:58
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:175
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
friend class AttributeList
void AddString(StringRef String)
Definition: FoldingSet.cpp:86
uint64_t getValueAsInt() const
Definition: Attributes.cpp:527
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:80
StringRef getValueAsString() const
Definition: Attributes.cpp:537
Type * getByValType() const
Definition: Attributes.cpp:689
Attribute()=default
td_range td_attrs()
Definition: Attributes.h:843
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
Definition: Function.h:245
LLVM_NODISCARD AttributeSet removeAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const
Remove the specified attributes from this set.
Definition: Attributes.cpp:646
LLVM_NODISCARD 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:279
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
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:274
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:503
void dump() const
Definition: Attributes.cpp:711
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:333
FoldingSet< AttributeSetNode > AttrsSetNodes
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.h:229
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
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:59
bool nullPointerIsDefined() const
Check if null pointer dereferencing is considered undefined behavior for the function.
Definition: Function.cpp:1538
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:1217
Type * getParamByValType(unsigned ArgNo) const
Return the byval type for the specified function parameter.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Definition: Attributes.cpp:973
AttrBuilder()=default
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:143
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:344