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