LLVM  3.7.0
Attributes.cpp
Go to the documentation of this file.
1 //===-- Attributes.cpp - Implement AttributesList -------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // \file
11 // \brief This file implements the Attribute, AttributeImpl, AttrBuilder,
12 // AttributeSetImpl, and AttributeSet classes.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "llvm/IR/Attributes.h"
17 #include "AttributeImpl.h"
18 #include "LLVMContextImpl.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/StringExtras.h"
21 #include "llvm/IR/Type.h"
22 #include "llvm/Support/Atomic.h"
23 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/Mutex.h"
27 #include <algorithm>
28 using namespace llvm;
29 
30 //===----------------------------------------------------------------------===//
31 // Attribute Construction Methods
32 //===----------------------------------------------------------------------===//
33 
35  uint64_t Val) {
36  LLVMContextImpl *pImpl = Context.pImpl;
38  ID.AddInteger(Kind);
39  if (Val) ID.AddInteger(Val);
40 
41  void *InsertPoint;
42  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
43 
44  if (!PA) {
45  // If we didn't find any existing attributes of the same shape then create a
46  // new one and insert it.
47  if (!Val)
48  PA = new EnumAttributeImpl(Kind);
49  else
50  PA = new IntAttributeImpl(Kind, Val);
51  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
52  }
53 
54  // Return the Attribute that we found or created.
55  return Attribute(PA);
56 }
57 
59  LLVMContextImpl *pImpl = Context.pImpl;
61  ID.AddString(Kind);
62  if (!Val.empty()) ID.AddString(Val);
63 
64  void *InsertPoint;
65  AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
66 
67  if (!PA) {
68  // If we didn't find any existing attributes of the same shape then create a
69  // new one and insert it.
70  PA = new StringAttributeImpl(Kind, Val);
71  pImpl->AttrsSet.InsertNode(PA, InsertPoint);
72  }
73 
74  // Return the Attribute that we found or created.
75  return Attribute(PA);
76 }
77 
79  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
80  assert(Align <= 0x40000000 && "Alignment too large.");
81  return get(Context, Alignment, Align);
82 }
83 
85  uint64_t Align) {
86  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
87  assert(Align <= 0x100 && "Alignment too large.");
88  return get(Context, StackAlignment, Align);
89 }
90 
92  uint64_t Bytes) {
93  assert(Bytes && "Bytes must be non-zero.");
94  return get(Context, Dereferenceable, Bytes);
95 }
96 
98  uint64_t Bytes) {
99  assert(Bytes && "Bytes must be non-zero.");
100  return get(Context, DereferenceableOrNull, Bytes);
101 }
102 
103 //===----------------------------------------------------------------------===//
104 // Attribute Accessor Methods
105 //===----------------------------------------------------------------------===//
106 
108  return pImpl && pImpl->isEnumAttribute();
109 }
110 
112  return pImpl && pImpl->isIntAttribute();
113 }
114 
116  return pImpl && pImpl->isStringAttribute();
117 }
118 
120  if (!pImpl) return None;
121  assert((isEnumAttribute() || isIntAttribute()) &&
122  "Invalid attribute type to get the kind as an enum!");
123  return pImpl ? pImpl->getKindAsEnum() : None;
124 }
125 
126 uint64_t Attribute::getValueAsInt() const {
127  if (!pImpl) return 0;
128  assert(isIntAttribute() &&
129  "Expected the attribute to be an integer attribute!");
130  return pImpl ? pImpl->getValueAsInt() : 0;
131 }
132 
134  if (!pImpl) return StringRef();
135  assert(isStringAttribute() &&
136  "Invalid attribute type to get the kind as a string!");
137  return pImpl ? pImpl->getKindAsString() : StringRef();
138 }
139 
141  if (!pImpl) return StringRef();
142  assert(isStringAttribute() &&
143  "Invalid attribute type to get the value as a string!");
144  return pImpl ? pImpl->getValueAsString() : StringRef();
145 }
146 
148  return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None);
149 }
150 
152  if (!isStringAttribute()) return false;
153  return pImpl && pImpl->hasAttribute(Kind);
154 }
155 
156 /// This returns the alignment field of an attribute as a byte alignment value.
157 unsigned Attribute::getAlignment() const {
159  "Trying to get alignment from non-alignment attribute!");
160  return pImpl->getValueAsInt();
161 }
162 
163 /// This returns the stack alignment field of an attribute as a byte alignment
164 /// value.
167  "Trying to get alignment from non-alignment attribute!");
168  return pImpl->getValueAsInt();
169 }
170 
171 /// This returns the number of dereferenceable bytes.
174  "Trying to get dereferenceable bytes from "
175  "non-dereferenceable attribute!");
176  return pImpl->getValueAsInt();
177 }
178 
181  "Trying to get dereferenceable bytes from "
182  "non-dereferenceable attribute!");
183  return pImpl->getValueAsInt();
184 }
185 
186 std::string Attribute::getAsString(bool InAttrGrp) const {
187  if (!pImpl) return "";
188 
190  return "sanitize_address";
192  return "alwaysinline";
194  return "argmemonly";
196  return "builtin";
198  return "byval";
200  return "convergent";
202  return "inalloca";
204  return "inlinehint";
206  return "inreg";
208  return "jumptable";
210  return "minsize";
212  return "naked";
214  return "nest";
216  return "noalias";
218  return "nobuiltin";
220  return "nocapture";
222  return "noduplicate";
224  return "noimplicitfloat";
226  return "noinline";
228  return "nonlazybind";
230  return "nonnull";
232  return "noredzone";
234  return "noreturn";
236  return "nounwind";
238  return "optnone";
240  return "optsize";
242  return "readnone";
244  return "readonly";
246  return "returned";
248  return "returns_twice";
250  return "signext";
252  return "ssp";
254  return "sspreq";
256  return "sspstrong";
258  return "safestack";
260  return "sret";
262  return "sanitize_thread";
264  return "sanitize_memory";
266  return "uwtable";
268  return "zeroext";
270  return "cold";
271 
272  // FIXME: These should be output like this:
273  //
274  // align=4
275  // alignstack=8
276  //
278  std::string Result;
279  Result += "align";
280  Result += (InAttrGrp) ? "=" : " ";
281  Result += utostr(getValueAsInt());
282  return Result;
283  }
284 
285  auto AttrWithBytesToString = [&](const char *Name) {
286  std::string Result;
287  Result += Name;
288  if (InAttrGrp) {
289  Result += "=";
290  Result += utostr(getValueAsInt());
291  } else {
292  Result += "(";
293  Result += utostr(getValueAsInt());
294  Result += ")";
295  }
296  return Result;
297  };
298 
300  return AttrWithBytesToString("alignstack");
301 
303  return AttrWithBytesToString("dereferenceable");
304 
306  return AttrWithBytesToString("dereferenceable_or_null");
307 
308  // Convert target-dependent attributes to strings of the form:
309  //
310  // "kind"
311  // "kind" = "value"
312  //
313  if (isStringAttribute()) {
314  std::string Result;
315  Result += (Twine('"') + getKindAsString() + Twine('"')).str();
316 
317  StringRef Val = pImpl->getValueAsString();
318  if (Val.empty()) return Result;
319 
320  Result += ("=\"" + Val + Twine('"')).str();
321  return Result;
322  }
323 
324  llvm_unreachable("Unknown attribute");
325 }
326 
328  if (!pImpl && !A.pImpl) return false;
329  if (!pImpl) return true;
330  if (!A.pImpl) return false;
331  return *pImpl < *A.pImpl;
332 }
333 
334 //===----------------------------------------------------------------------===//
335 // AttributeImpl Definition
336 //===----------------------------------------------------------------------===//
337 
338 // Pin the vtables to this file.
340 void EnumAttributeImpl::anchor() {}
341 void IntAttributeImpl::anchor() {}
342 void StringAttributeImpl::anchor() {}
343 
345  if (isStringAttribute()) return false;
346  return getKindAsEnum() == A;
347 }
348 
350  if (!isStringAttribute()) return false;
351  return getKindAsString() == Kind;
352 }
353 
355  assert(isEnumAttribute() || isIntAttribute());
356  return static_cast<const EnumAttributeImpl *>(this)->getEnumKind();
357 }
358 
360  assert(isIntAttribute());
361  return static_cast<const IntAttributeImpl *>(this)->getValue();
362 }
363 
365  assert(isStringAttribute());
366  return static_cast<const StringAttributeImpl *>(this)->getStringKind();
367 }
368 
370  assert(isStringAttribute());
371  return static_cast<const StringAttributeImpl *>(this)->getStringValue();
372 }
373 
375  // This sorts the attributes with Attribute::AttrKinds coming first (sorted
376  // relative to their enum value) and then strings.
377  if (isEnumAttribute()) {
378  if (AI.isEnumAttribute()) return getKindAsEnum() < AI.getKindAsEnum();
379  if (AI.isIntAttribute()) return true;
380  if (AI.isStringAttribute()) return true;
381  }
382 
383  if (isIntAttribute()) {
384  if (AI.isEnumAttribute()) return false;
385  if (AI.isIntAttribute()) return getValueAsInt() < AI.getValueAsInt();
386  if (AI.isStringAttribute()) return true;
387  }
388 
389  if (AI.isEnumAttribute()) return false;
390  if (AI.isIntAttribute()) return false;
391  if (getKindAsString() == AI.getKindAsString())
392  return getValueAsString() < AI.getValueAsString();
393  return getKindAsString() < AI.getKindAsString();
394 }
395 
397  // FIXME: Remove this.
398  switch (Val) {
400  llvm_unreachable("Synthetic enumerators which should never get here");
401 
402  case Attribute::None: return 0;
403  case Attribute::ZExt: return 1 << 0;
404  case Attribute::SExt: return 1 << 1;
405  case Attribute::NoReturn: return 1 << 2;
406  case Attribute::InReg: return 1 << 3;
407  case Attribute::StructRet: return 1 << 4;
408  case Attribute::NoUnwind: return 1 << 5;
409  case Attribute::NoAlias: return 1 << 6;
410  case Attribute::ByVal: return 1 << 7;
411  case Attribute::Nest: return 1 << 8;
412  case Attribute::ReadNone: return 1 << 9;
413  case Attribute::ReadOnly: return 1 << 10;
414  case Attribute::NoInline: return 1 << 11;
415  case Attribute::AlwaysInline: return 1 << 12;
416  case Attribute::OptimizeForSize: return 1 << 13;
417  case Attribute::StackProtect: return 1 << 14;
418  case Attribute::StackProtectReq: return 1 << 15;
419  case Attribute::Alignment: return 31 << 16;
420  case Attribute::NoCapture: return 1 << 21;
421  case Attribute::NoRedZone: return 1 << 22;
422  case Attribute::NoImplicitFloat: return 1 << 23;
423  case Attribute::Naked: return 1 << 24;
424  case Attribute::InlineHint: return 1 << 25;
425  case Attribute::StackAlignment: return 7 << 26;
426  case Attribute::ReturnsTwice: return 1 << 29;
427  case Attribute::UWTable: return 1 << 30;
428  case Attribute::NonLazyBind: return 1U << 31;
429  case Attribute::SanitizeAddress: return 1ULL << 32;
430  case Attribute::MinSize: return 1ULL << 33;
431  case Attribute::NoDuplicate: return 1ULL << 34;
432  case Attribute::StackProtectStrong: return 1ULL << 35;
433  case Attribute::SanitizeThread: return 1ULL << 36;
434  case Attribute::SanitizeMemory: return 1ULL << 37;
435  case Attribute::NoBuiltin: return 1ULL << 38;
436  case Attribute::Returned: return 1ULL << 39;
437  case Attribute::Cold: return 1ULL << 40;
438  case Attribute::Builtin: return 1ULL << 41;
439  case Attribute::OptimizeNone: return 1ULL << 42;
440  case Attribute::InAlloca: return 1ULL << 43;
441  case Attribute::NonNull: return 1ULL << 44;
442  case Attribute::JumpTable: return 1ULL << 45;
443  case Attribute::Convergent: return 1ULL << 46;
444  case Attribute::SafeStack: return 1ULL << 47;
446  llvm_unreachable("dereferenceable attribute not supported in raw format");
447  break;
449  llvm_unreachable("dereferenceable_or_null attribute not supported in raw "
450  "format");
451  break;
453  llvm_unreachable("argmemonly attribute not supported in raw format");
454  break;
455  }
456  llvm_unreachable("Unsupported attribute type");
457 }
458 
459 //===----------------------------------------------------------------------===//
460 // AttributeSetNode Definition
461 //===----------------------------------------------------------------------===//
462 
464  ArrayRef<Attribute> Attrs) {
465  if (Attrs.empty())
466  return nullptr;
467 
468  // Otherwise, build a key to look up the existing attributes.
469  LLVMContextImpl *pImpl = C.pImpl;
471 
472  SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
473  array_pod_sort(SortedAttrs.begin(), SortedAttrs.end());
474 
475  for (SmallVectorImpl<Attribute>::iterator I = SortedAttrs.begin(),
476  E = SortedAttrs.end(); I != E; ++I)
477  I->Profile(ID);
478 
479  void *InsertPoint;
480  AttributeSetNode *PA =
481  pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint);
482 
483  // If we didn't find any existing attributes of the same shape then create a
484  // new one and insert it.
485  if (!PA) {
486  // Coallocate entries after the AttributeSetNode itself.
487  void *Mem = ::operator new(sizeof(AttributeSetNode) +
488  sizeof(Attribute) * SortedAttrs.size());
489  PA = new (Mem) AttributeSetNode(SortedAttrs);
490  pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint);
491  }
492 
493  // Return the AttributesListNode that we found or created.
494  return PA;
495 }
496 
498  for (iterator I = begin(), E = end(); I != E; ++I)
499  if (I->hasAttribute(Kind))
500  return true;
501  return false;
502 }
503 
505  for (iterator I = begin(), E = end(); I != E; ++I)
506  if (I->hasAttribute(Kind))
507  return true;
508  return false;
509 }
510 
512  for (iterator I = begin(), E = end(); I != E; ++I)
513  if (I->hasAttribute(Kind))
514  return *I;
515  return Attribute();
516 }
517 
519  for (iterator I = begin(), E = end(); I != E; ++I)
520  if (I->hasAttribute(Kind))
521  return *I;
522  return Attribute();
523 }
524 
526  for (iterator I = begin(), E = end(); I != E; ++I)
527  if (I->hasAttribute(Attribute::Alignment))
528  return I->getAlignment();
529  return 0;
530 }
531 
533  for (iterator I = begin(), E = end(); I != E; ++I)
534  if (I->hasAttribute(Attribute::StackAlignment))
535  return I->getStackAlignment();
536  return 0;
537 }
538 
540  for (iterator I = begin(), E = end(); I != E; ++I)
541  if (I->hasAttribute(Attribute::Dereferenceable))
542  return I->getDereferenceableBytes();
543  return 0;
544 }
545 
547  for (iterator I = begin(), E = end(); I != E; ++I)
548  if (I->hasAttribute(Attribute::DereferenceableOrNull))
549  return I->getDereferenceableOrNullBytes();
550  return 0;
551 }
552 
553 std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
554  std::string Str;
555  for (iterator I = begin(), E = end(); I != E; ++I) {
556  if (I != begin())
557  Str += ' ';
558  Str += I->getAsString(InAttrGrp);
559  }
560  return Str;
561 }
562 
563 //===----------------------------------------------------------------------===//
564 // AttributeSetImpl Definition
565 //===----------------------------------------------------------------------===//
566 
567 uint64_t AttributeSetImpl::Raw(unsigned Index) const {
568  for (unsigned I = 0, E = getNumAttributes(); I != E; ++I) {
569  if (getSlotIndex(I) != Index) continue;
570  const AttributeSetNode *ASN = getSlotNode(I);
571  uint64_t Mask = 0;
572 
573  for (AttributeSetNode::iterator II = ASN->begin(),
574  IE = ASN->end(); II != IE; ++II) {
575  Attribute Attr = *II;
576 
577  // This cannot handle string attributes.
578  if (Attr.isStringAttribute()) continue;
579 
581 
582  if (Kind == Attribute::Alignment)
583  Mask |= (Log2_32(ASN->getAlignment()) + 1) << 16;
584  else if (Kind == Attribute::StackAlignment)
585  Mask |= (Log2_32(ASN->getStackAlignment()) + 1) << 26;
586  else if (Kind == Attribute::Dereferenceable)
587  llvm_unreachable("dereferenceable not supported in bit mask");
588  else
589  Mask |= AttributeImpl::getAttrMask(Kind);
590  }
591 
592  return Mask;
593  }
594 
595  return 0;
596 }
597 
599  AttributeSet(const_cast<AttributeSetImpl *>(this)).dump();
600 }
601 
602 //===----------------------------------------------------------------------===//
603 // AttributeSet Construction and Mutation Methods
604 //===----------------------------------------------------------------------===//
605 
607 AttributeSet::getImpl(LLVMContext &C,
608  ArrayRef<std::pair<unsigned, AttributeSetNode*> > Attrs) {
609  LLVMContextImpl *pImpl = C.pImpl;
611  AttributeSetImpl::Profile(ID, Attrs);
612 
613  void *InsertPoint;
614  AttributeSetImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint);
615 
616  // If we didn't find any existing attributes of the same shape then
617  // create a new one and insert it.
618  if (!PA) {
619  // Coallocate entries after the AttributeSetImpl itself.
620  void *Mem = ::operator new(sizeof(AttributeSetImpl) +
621  sizeof(std::pair<unsigned, AttributeSetNode *>) *
622  Attrs.size());
623  PA = new (Mem) AttributeSetImpl(C, Attrs);
624  pImpl->AttrsLists.InsertNode(PA, InsertPoint);
625  }
626 
627  // Return the AttributesList that we found or created.
628  return AttributeSet(PA);
629 }
630 
631 AttributeSet AttributeSet::get(LLVMContext &C,
632  ArrayRef<std::pair<unsigned, Attribute> > Attrs){
633  // If there are no attributes then return a null AttributesList pointer.
634  if (Attrs.empty())
635  return AttributeSet();
636 
637 #ifndef NDEBUG
638  for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
639  assert((!i || Attrs[i-1].first <= Attrs[i].first) &&
640  "Misordered Attributes list!");
641  assert(!Attrs[i].second.hasAttribute(Attribute::None) &&
642  "Pointless attribute!");
643  }
644 #endif
645 
646  // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes
647  // list.
649  for (ArrayRef<std::pair<unsigned, Attribute> >::iterator I = Attrs.begin(),
650  E = Attrs.end(); I != E; ) {
651  unsigned Index = I->first;
653  while (I != E && I->first == Index) {
654  AttrVec.push_back(I->second);
655  ++I;
656  }
657 
658  AttrPairVec.push_back(std::make_pair(Index,
659  AttributeSetNode::get(C, AttrVec)));
660  }
661 
662  return getImpl(C, AttrPairVec);
663 }
664 
665 AttributeSet AttributeSet::get(LLVMContext &C,
666  ArrayRef<std::pair<unsigned,
667  AttributeSetNode*> > Attrs) {
668  // If there are no attributes then return a null AttributesList pointer.
669  if (Attrs.empty())
670  return AttributeSet();
671 
672  return getImpl(C, Attrs);
673 }
674 
675 AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
676  const AttrBuilder &B) {
677  if (!B.hasAttributes())
678  return AttributeSet();
679 
680  // Add target-independent attributes.
684  if (!B.contains(Kind))
685  continue;
686 
687  if (Kind == Attribute::Alignment)
688  Attrs.push_back(std::make_pair(Index, Attribute::
689  getWithAlignment(C, B.getAlignment())));
690  else if (Kind == Attribute::StackAlignment)
691  Attrs.push_back(std::make_pair(Index, Attribute::
692  getWithStackAlignment(C, B.getStackAlignment())));
693  else if (Kind == Attribute::Dereferenceable)
694  Attrs.push_back(std::make_pair(Index,
698  Attrs.push_back(
699  std::make_pair(Index, Attribute::getWithDereferenceableOrNullBytes(
701  else
702  Attrs.push_back(std::make_pair(Index, Attribute::get(C, Kind)));
703  }
704 
705  // Add target-dependent (string) attributes.
706  for (const AttrBuilder::td_type &TDA : B.td_attrs())
707  Attrs.push_back(
708  std::make_pair(Index, Attribute::get(C, TDA.first, TDA.second)));
709 
710  return get(C, Attrs);
711 }
712 
713 AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
717  E = Kind.end(); I != E; ++I)
718  Attrs.push_back(std::make_pair(Index, Attribute::get(C, *I)));
719  return get(C, Attrs);
720 }
721 
722 AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) {
723  if (Attrs.empty()) return AttributeSet();
724  if (Attrs.size() == 1) return Attrs[0];
725 
727  AttributeSetImpl *A0 = Attrs[0].pImpl;
728  if (A0)
729  AttrNodeVec.append(A0->getNode(0), A0->getNode(A0->getNumAttributes()));
730  // Copy all attributes from Attrs into AttrNodeVec while keeping AttrNodeVec
731  // ordered by index. Because we know that each list in Attrs is ordered by
732  // index we only need to merge each successive list in rather than doing a
733  // full sort.
734  for (unsigned I = 1, E = Attrs.size(); I != E; ++I) {
735  AttributeSetImpl *AS = Attrs[I].pImpl;
736  if (!AS) continue;
738  ANVI = AttrNodeVec.begin(), ANVE;
740  *AI = AS->getNode(0),
741  *AE = AS->getNode(AS->getNumAttributes());
742  AI != AE; ++AI) {
743  ANVE = AttrNodeVec.end();
744  while (ANVI != ANVE && ANVI->first <= AI->first)
745  ++ANVI;
746  ANVI = AttrNodeVec.insert(ANVI, *AI) + 1;
747  }
748  }
749 
750  return getImpl(C, AttrNodeVec);
751 }
752 
754  Attribute::AttrKind Attr) const {
755  if (hasAttribute(Index, Attr)) return *this;
756  return addAttributes(C, Index, AttributeSet::get(C, Index, Attr));
757 }
758 
760  StringRef Kind) const {
762  B.addAttribute(Kind);
763  return addAttributes(C, Index, AttributeSet::get(C, Index, B));
764 }
765 
767  StringRef Kind, StringRef Value) const {
769  B.addAttribute(Kind, Value);
770  return addAttributes(C, Index, AttributeSet::get(C, Index, B));
771 }
772 
774  AttributeSet Attrs) const {
775  if (!pImpl) return Attrs;
776  if (!Attrs.pImpl) return *this;
777 
778 #ifndef NDEBUG
779  // FIXME it is not obvious how this should work for alignment. For now, say
780  // we can't change a known alignment.
781  unsigned OldAlign = getParamAlignment(Index);
782  unsigned NewAlign = Attrs.getParamAlignment(Index);
783  assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
784  "Attempt to change alignment!");
785 #endif
786 
787  // Add the attribute slots before the one we're trying to add.
789  uint64_t NumAttrs = pImpl->getNumAttributes();
790  AttributeSet AS;
791  uint64_t LastIndex = 0;
792  for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
793  if (getSlotIndex(I) >= Index) {
794  if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++);
795  break;
796  }
797  LastIndex = I + 1;
798  AttrSet.push_back(getSlotAttributes(I));
799  }
800 
801  // Now add the attribute into the correct slot. There may already be an
802  // AttributeSet there.
803  AttrBuilder B(AS, Index);
804 
805  for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I)
806  if (Attrs.getSlotIndex(I) == Index) {
807  for (AttributeSetImpl::iterator II = Attrs.pImpl->begin(I),
808  IE = Attrs.pImpl->end(I); II != IE; ++II)
809  B.addAttribute(*II);
810  break;
811  }
812 
813  AttrSet.push_back(AttributeSet::get(C, Index, B));
814 
815  // Add the remaining attribute slots.
816  for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
817  AttrSet.push_back(getSlotAttributes(I));
818 
819  return get(C, AttrSet);
820 }
821 
823  Attribute::AttrKind Attr) const {
824  if (!hasAttribute(Index, Attr)) return *this;
825  return removeAttributes(C, Index, AttributeSet::get(C, Index, Attr));
826 }
827 
829  AttributeSet Attrs) const {
830  if (!pImpl) return AttributeSet();
831  if (!Attrs.pImpl) return *this;
832 
833  // FIXME it is not obvious how this should work for alignment.
834  // For now, say we can't pass in alignment, which no current use does.
835  assert(!Attrs.hasAttribute(Index, Attribute::Alignment) &&
836  "Attempt to change alignment!");
837 
838  // Add the attribute slots before the one we're trying to add.
840  uint64_t NumAttrs = pImpl->getNumAttributes();
841  AttributeSet AS;
842  uint64_t LastIndex = 0;
843  for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
844  if (getSlotIndex(I) >= Index) {
845  if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++);
846  break;
847  }
848  LastIndex = I + 1;
849  AttrSet.push_back(getSlotAttributes(I));
850  }
851 
852  // Now remove the attribute from the correct slot. There may already be an
853  // AttributeSet there.
854  AttrBuilder B(AS, Index);
855 
856  for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I)
857  if (Attrs.getSlotIndex(I) == Index) {
858  B.removeAttributes(Attrs.pImpl->getSlotAttributes(I), Index);
859  break;
860  }
861 
862  AttrSet.push_back(AttributeSet::get(C, Index, B));
863 
864  // Add the remaining attribute slots.
865  for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
866  AttrSet.push_back(getSlotAttributes(I));
867 
868  return get(C, AttrSet);
869 }
870 
872  const AttrBuilder &Attrs) const {
873  if (!pImpl) return AttributeSet();
874 
875  // FIXME it is not obvious how this should work for alignment.
876  // For now, say we can't pass in alignment, which no current use does.
877  assert(!Attrs.hasAlignmentAttr() && "Attempt to change alignment!");
878 
879  // Add the attribute slots before the one we're trying to add.
881  uint64_t NumAttrs = pImpl->getNumAttributes();
882  AttributeSet AS;
883  uint64_t LastIndex = 0;
884  for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
885  if (getSlotIndex(I) >= Index) {
886  if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++);
887  break;
888  }
889  LastIndex = I + 1;
890  AttrSet.push_back(getSlotAttributes(I));
891  }
892 
893  // Now remove the attribute from the correct slot. There may already be an
894  // AttributeSet there.
895  AttrBuilder B(AS, Index);
896  B.remove(Attrs);
897 
898  AttrSet.push_back(AttributeSet::get(C, Index, B));
899 
900  // Add the remaining attribute slots.
901  for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
902  AttrSet.push_back(getSlotAttributes(I));
903 
904  return get(C, AttrSet);
905 }
906 
908  uint64_t Bytes) const {
910  B.addDereferenceableAttr(Bytes);
911  return addAttributes(C, Index, AttributeSet::get(C, Index, B));
912 }
913 
915  unsigned Index,
916  uint64_t Bytes) const {
919  return addAttributes(C, Index, AttributeSet::get(C, Index, B));
920 }
921 
922 //===----------------------------------------------------------------------===//
923 // AttributeSet Accessor Methods
924 //===----------------------------------------------------------------------===//
925 
927  return pImpl->getContext();
928 }
929 
931  return pImpl && hasAttributes(Index) ?
932  AttributeSet::get(pImpl->getContext(),
934  std::make_pair(Index, getAttributes(Index)))) :
935  AttributeSet();
936 }
937 
939  return pImpl && hasAttributes(ReturnIndex) ?
940  AttributeSet::get(pImpl->getContext(),
942  std::make_pair(ReturnIndex,
944  AttributeSet();
945 }
946 
948  return pImpl && hasAttributes(FunctionIndex) ?
949  AttributeSet::get(pImpl->getContext(),
951  std::make_pair(FunctionIndex,
953  AttributeSet();
954 }
955 
957  AttributeSetNode *ASN = getAttributes(Index);
958  return ASN ? ASN->hasAttribute(Kind) : false;
959 }
960 
961 bool AttributeSet::hasAttribute(unsigned Index, StringRef Kind) const {
962  AttributeSetNode *ASN = getAttributes(Index);
963  return ASN ? ASN->hasAttribute(Kind) : false;
964 }
965 
966 bool AttributeSet::hasAttributes(unsigned Index) const {
967  AttributeSetNode *ASN = getAttributes(Index);
968  return ASN ? ASN->hasAttributes() : false;
969 }
970 
971 /// \brief Return true if the specified attribute is set for at least one
972 /// parameter or for the return value.
974  if (!pImpl) return false;
975 
976  for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I)
977  for (AttributeSetImpl::iterator II = pImpl->begin(I),
978  IE = pImpl->end(I); II != IE; ++II)
979  if (II->hasAttribute(Attr))
980  return true;
981 
982  return false;
983 }
984 
986  Attribute::AttrKind Kind) const {
987  AttributeSetNode *ASN = getAttributes(Index);
988  return ASN ? ASN->getAttribute(Kind) : Attribute();
989 }
990 
992  StringRef Kind) const {
993  AttributeSetNode *ASN = getAttributes(Index);
994  return ASN ? ASN->getAttribute(Kind) : Attribute();
995 }
996 
997 unsigned AttributeSet::getParamAlignment(unsigned Index) const {
998  AttributeSetNode *ASN = getAttributes(Index);
999  return ASN ? ASN->getAlignment() : 0;
1000 }
1001 
1002 unsigned AttributeSet::getStackAlignment(unsigned Index) const {
1003  AttributeSetNode *ASN = getAttributes(Index);
1004  return ASN ? ASN->getStackAlignment() : 0;
1005 }
1006 
1007 uint64_t AttributeSet::getDereferenceableBytes(unsigned Index) const {
1008  AttributeSetNode *ASN = getAttributes(Index);
1009  return ASN ? ASN->getDereferenceableBytes() : 0;
1010 }
1011 
1012 uint64_t AttributeSet::getDereferenceableOrNullBytes(unsigned Index) const {
1013  AttributeSetNode *ASN = getAttributes(Index);
1014  return ASN ? ASN->getDereferenceableOrNullBytes() : 0;
1015 }
1016 
1017 std::string AttributeSet::getAsString(unsigned Index,
1018  bool InAttrGrp) const {
1019  AttributeSetNode *ASN = getAttributes(Index);
1020  return ASN ? ASN->getAsString(InAttrGrp) : std::string("");
1021 }
1022 
1023 /// \brief The attributes for the specified index are returned.
1024 AttributeSetNode *AttributeSet::getAttributes(unsigned Index) const {
1025  if (!pImpl) return nullptr;
1026 
1027  // Loop through to find the attribute node we want.
1028  for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I)
1029  if (pImpl->getSlotIndex(I) == Index)
1030  return pImpl->getSlotNode(I);
1031 
1032  return nullptr;
1033 }
1034 
1036  if (!pImpl)
1037  return ArrayRef<Attribute>().begin();
1038  return pImpl->begin(Slot);
1039 }
1040 
1042  if (!pImpl)
1043  return ArrayRef<Attribute>().end();
1044  return pImpl->end(Slot);
1045 }
1046 
1047 //===----------------------------------------------------------------------===//
1048 // AttributeSet Introspection Methods
1049 //===----------------------------------------------------------------------===//
1050 
1051 /// \brief Return the number of slots used in this attribute list. This is the
1052 /// number of arguments that have an attribute set on them (including the
1053 /// function itself).
1054 unsigned AttributeSet::getNumSlots() const {
1055  return pImpl ? pImpl->getNumAttributes() : 0;
1056 }
1057 
1058 unsigned AttributeSet::getSlotIndex(unsigned Slot) const {
1059  assert(pImpl && Slot < pImpl->getNumAttributes() &&
1060  "Slot # out of range!");
1061  return pImpl->getSlotIndex(Slot);
1062 }
1063 
1065  assert(pImpl && Slot < pImpl->getNumAttributes() &&
1066  "Slot # out of range!");
1067  return pImpl->getSlotAttributes(Slot);
1068 }
1069 
1070 uint64_t AttributeSet::Raw(unsigned Index) const {
1071  // FIXME: Remove this.
1072  return pImpl ? pImpl->Raw(Index) : 0;
1073 }
1074 
1075 void AttributeSet::dump() const {
1076  dbgs() << "PAL[\n";
1077 
1078  for (unsigned i = 0, e = getNumSlots(); i < e; ++i) {
1079  uint64_t Index = getSlotIndex(i);
1080  dbgs() << " { ";
1081  if (Index == ~0U)
1082  dbgs() << "~0U";
1083  else
1084  dbgs() << Index;
1085  dbgs() << " => " << getAsString(Index) << " }\n";
1086  }
1087 
1088  dbgs() << "]\n";
1089 }
1090 
1091 //===----------------------------------------------------------------------===//
1092 // AttrBuilder Method Implementations
1093 //===----------------------------------------------------------------------===//
1094 
1096  : Attrs(0), Alignment(0), StackAlignment(0), DerefBytes(0),
1097  DerefOrNullBytes(0) {
1098  AttributeSetImpl *pImpl = AS.pImpl;
1099  if (!pImpl) return;
1100 
1101  for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) {
1102  if (pImpl->getSlotIndex(I) != Index) continue;
1103 
1104  for (AttributeSetImpl::iterator II = pImpl->begin(I),
1105  IE = pImpl->end(I); II != IE; ++II)
1106  addAttribute(*II);
1107 
1108  break;
1109  }
1110 }
1111 
1113  Attrs.reset();
1114  Alignment = StackAlignment = DerefBytes = DerefOrNullBytes = 0;
1115 }
1116 
1118  assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1119  assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
1120  Val != Attribute::Dereferenceable &&
1121  "Adding integer attribute without adding a value!");
1122  Attrs[Val] = true;
1123  return *this;
1124 }
1125 
1127  if (Attr.isStringAttribute()) {
1129  return *this;
1130  }
1131 
1133  Attrs[Kind] = true;
1134 
1135  if (Kind == Attribute::Alignment)
1136  Alignment = Attr.getAlignment();
1137  else if (Kind == Attribute::StackAlignment)
1138  StackAlignment = Attr.getStackAlignment();
1139  else if (Kind == Attribute::Dereferenceable)
1140  DerefBytes = Attr.getDereferenceableBytes();
1141  else if (Kind == Attribute::DereferenceableOrNull)
1142  DerefOrNullBytes = Attr.getDereferenceableOrNullBytes();
1143  return *this;
1144 }
1145 
1147  TargetDepAttrs[A] = V;
1148  return *this;
1149 }
1150 
1152  assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1153  Attrs[Val] = false;
1154 
1155  if (Val == Attribute::Alignment)
1156  Alignment = 0;
1157  else if (Val == Attribute::StackAlignment)
1158  StackAlignment = 0;
1159  else if (Val == Attribute::Dereferenceable)
1160  DerefBytes = 0;
1161  else if (Val == Attribute::DereferenceableOrNull)
1162  DerefOrNullBytes = 0;
1163 
1164  return *this;
1165 }
1166 
1168  unsigned Slot = ~0U;
1169  for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
1170  if (A.getSlotIndex(I) == Index) {
1171  Slot = I;
1172  break;
1173  }
1174 
1175  assert(Slot != ~0U && "Couldn't find index in AttributeSet!");
1176 
1177  for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); I != E; ++I) {
1178  Attribute Attr = *I;
1179  if (Attr.isEnumAttribute() || Attr.isIntAttribute()) {
1180  Attribute::AttrKind Kind = I->getKindAsEnum();
1181  Attrs[Kind] = false;
1182 
1183  if (Kind == Attribute::Alignment)
1184  Alignment = 0;
1185  else if (Kind == Attribute::StackAlignment)
1186  StackAlignment = 0;
1187  else if (Kind == Attribute::Dereferenceable)
1188  DerefBytes = 0;
1189  else if (Kind == Attribute::DereferenceableOrNull)
1190  DerefOrNullBytes = 0;
1191  } else {
1192  assert(Attr.isStringAttribute() && "Invalid attribute type!");
1193  std::map<std::string, std::string>::iterator
1194  Iter = TargetDepAttrs.find(Attr.getKindAsString());
1195  if (Iter != TargetDepAttrs.end())
1196  TargetDepAttrs.erase(Iter);
1197  }
1198  }
1199 
1200  return *this;
1201 }
1202 
1204  std::map<std::string, std::string>::iterator I = TargetDepAttrs.find(A);
1205  if (I != TargetDepAttrs.end())
1206  TargetDepAttrs.erase(I);
1207  return *this;
1208 }
1209 
1211  if (Align == 0) return *this;
1212 
1213  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
1214  assert(Align <= 0x40000000 && "Alignment too large.");
1215 
1216  Attrs[Attribute::Alignment] = true;
1217  Alignment = Align;
1218  return *this;
1219 }
1220 
1222  // Default alignment, allow the target to define how to align it.
1223  if (Align == 0) return *this;
1224 
1225  assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
1226  assert(Align <= 0x100 && "Alignment too large.");
1227 
1228  Attrs[Attribute::StackAlignment] = true;
1229  StackAlignment = Align;
1230  return *this;
1231 }
1232 
1234  if (Bytes == 0) return *this;
1235 
1236  Attrs[Attribute::Dereferenceable] = true;
1237  DerefBytes = Bytes;
1238  return *this;
1239 }
1240 
1242  if (Bytes == 0)
1243  return *this;
1244 
1245  Attrs[Attribute::DereferenceableOrNull] = true;
1246  DerefOrNullBytes = Bytes;
1247  return *this;
1248 }
1249 
1251  // FIXME: What if both have alignments, but they don't match?!
1252  if (!Alignment)
1253  Alignment = B.Alignment;
1254 
1255  if (!StackAlignment)
1256  StackAlignment = B.StackAlignment;
1257 
1258  if (!DerefBytes)
1259  DerefBytes = B.DerefBytes;
1260 
1261  if (!DerefOrNullBytes)
1262  DerefOrNullBytes = B.DerefOrNullBytes;
1263 
1264  Attrs |= B.Attrs;
1265 
1266  for (auto I : B.td_attrs())
1267  TargetDepAttrs[I.first] = I.second;
1268 
1269  return *this;
1270 }
1271 
1273  // FIXME: What if both have alignments, but they don't match?!
1274  if (B.Alignment)
1275  Alignment = 0;
1276 
1277  if (B.StackAlignment)
1278  StackAlignment = 0;
1279 
1280  if (B.DerefBytes)
1281  DerefBytes = 0;
1282 
1283  if (B.DerefOrNullBytes)
1284  DerefOrNullBytes = 0;
1285 
1286  Attrs &= ~B.Attrs;
1287 
1288  for (auto I : B.td_attrs())
1289  TargetDepAttrs.erase(I.first);
1290 
1291  return *this;
1292 }
1293 
1294 bool AttrBuilder::overlaps(const AttrBuilder &B) const {
1295  // First check if any of the target independent attributes overlap.
1296  if ((Attrs & B.Attrs).any())
1297  return true;
1298 
1299  // Then check if any target dependent ones do.
1300  for (auto I : td_attrs())
1301  if (B.contains(I.first))
1302  return true;
1303 
1304  return false;
1305 }
1306 
1308  return TargetDepAttrs.find(A) != TargetDepAttrs.end();
1309 }
1310 
1312  return !Attrs.none() || !TargetDepAttrs.empty();
1313 }
1314 
1315 bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
1316  unsigned Slot = ~0U;
1317  for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
1318  if (A.getSlotIndex(I) == Index) {
1319  Slot = I;
1320  break;
1321  }
1322 
1323  assert(Slot != ~0U && "Couldn't find the index!");
1324 
1325  for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot);
1326  I != E; ++I) {
1327  Attribute Attr = *I;
1328  if (Attr.isEnumAttribute() || Attr.isIntAttribute()) {
1329  if (Attrs[I->getKindAsEnum()])
1330  return true;
1331  } else {
1332  assert(Attr.isStringAttribute() && "Invalid attribute kind!");
1333  return TargetDepAttrs.find(Attr.getKindAsString())!=TargetDepAttrs.end();
1334  }
1335  }
1336 
1337  return false;
1338 }
1339 
1341  return Alignment != 0;
1342 }
1343 
1345  if (Attrs != B.Attrs)
1346  return false;
1347 
1348  for (td_const_iterator I = TargetDepAttrs.begin(),
1349  E = TargetDepAttrs.end(); I != E; ++I)
1350  if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end())
1351  return false;
1352 
1353  return Alignment == B.Alignment && StackAlignment == B.StackAlignment &&
1354  DerefBytes == B.DerefBytes;
1355 }
1356 
1358  // FIXME: Remove this in 4.0.
1359  if (!Val) return *this;
1360 
1362  I = Attribute::AttrKind(I + 1)) {
1363  if (I == Attribute::Dereferenceable ||
1366  continue;
1367  if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) {
1368  Attrs[I] = true;
1369 
1370  if (I == Attribute::Alignment)
1371  Alignment = 1ULL << ((A >> 16) - 1);
1372  else if (I == Attribute::StackAlignment)
1373  StackAlignment = 1ULL << ((A >> 26)-1);
1374  }
1375  }
1376 
1377  return *this;
1378 }
1379 
1380 //===----------------------------------------------------------------------===//
1381 // AttributeFuncs Function Defintions
1382 //===----------------------------------------------------------------------===//
1383 
1384 /// \brief Which attributes cannot be applied to a type.
1386  AttrBuilder Incompatible;
1387 
1388  if (!Ty->isIntegerTy())
1389  // Attribute that only apply to integers.
1390  Incompatible.addAttribute(Attribute::SExt)
1392 
1393  if (!Ty->isPointerTy())
1394  // Attribute that only apply to pointers.
1395  Incompatible.addAttribute(Attribute::ByVal)
1400  .addDereferenceableAttr(1) // the int here is ignored
1401  .addDereferenceableOrNullAttr(1) // the int here is ignored
1406 
1407  return Incompatible;
1408 }
uint64_t getDereferenceableBytes() const
Definition: Attributes.cpp:539
std::string getAsString(bool InAttrGrp) const
Definition: Attributes.cpp:553
FoldingSet< AttributeImpl > AttrsSet
Alignment of stack for function (3 bits) stored as log2 of alignment with +1 bias 0 means unaligned (...
Definition: Attributes.h:106
iterator begin() const
AttributeSet getParamAttributes(unsigned Index) const
The attributes for the specified index are returned.
Definition: Attributes.cpp:930
unsigned getStackAlignment(unsigned Index) const
Get the stack alignment.
Sign extended before/after call.
Definition: Attributes.h:105
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:78
Force argument to be passed in register.
Definition: Attributes.h:78
Function is called early and/or often, so lazy binding isn't worthwhile.
Definition: Attributes.h:89
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:91
Nested function static chain.
Definition: Attributes.h:82
iterator end() const
Definition: ArrayRef.h:123
uint64_t getAlignment() const
Retrieve the alignment attribute, if it exists.
Definition: Attributes.h:509
uint64_t getDereferenceableOrNullBytes() const
Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists...
Definition: Attributes.h:520
uint64_t getValueAsInt() const
Return the attribute's value as an integer.
Definition: Attributes.cpp:126
std::pair< unsigned, AttributeSetNode * > IndexAttrPair
Source said inlining was desirable.
Definition: Attributes.h:77
AttributeSet getSlotAttributes(unsigned Slot) const
Retrieve the attributes for the given "slot" in the AttrNode list.
iterator begin(unsigned Slot) const
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
iterator end() const
unsigned getParamAlignment(unsigned Index) const
Return the alignment for the specified function parameter.
Definition: Attributes.cpp:997
unsigned getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:157
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
void Profile(FoldingSetNodeID &ID) const
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Definition: Attributes.cpp:956
bool hasAlignmentAttr() const
Return true if the builder has an alignment attribute.
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
Definition: Attributes.h:489
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:147
Naked function.
Definition: Attributes.h:81
AttrBuilder & addRawValue(uint64_t Val)
Add the raw value to the internal representation.
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
Definition: Attributes.cpp:938
bool hasAttributes() const
StringRef getKindAsString() const
Return the attribute's kind as a string.
Definition: Attributes.cpp:133
AttributeSet removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Attr) const
Remove the specified attribute at the specified index from this attribute list.
Definition: Attributes.cpp:822
uint64_t getDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown).
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
Definition: Attributes.cpp:186
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
FoldingSet< AttributeSetImpl > AttrsLists
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:97
This file contains the simple types necessary to represent the attributes associated with functions a...
Attribute::AttrKind getKindAsEnum() const
Definition: Attributes.cpp:354
No attributes have been set.
Definition: Attributes.h:66
void AddInteger(signed I)
Definition: FoldingSet.cpp:60
AttributeSet addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
Definition: Attributes.cpp:907
Function must be in a unwind table.
Definition: Attributes.h:118
Function does not access memory.
Definition: Attributes.h:99
Hidden pointer to structure to return.
Definition: Attributes.h:114
friend class AttributeSet
Function creates no aliases of pointer.
Definition: Attributes.h:85
bool operator<(const AttributeImpl &AI) const
Used when sorting the attributes.
Definition: Attributes.cpp:374
uint64_t getDereferenceableBytes() const
Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is return...
Definition: Attributes.h:516
Safe Stack protection.
Definition: Attributes.h:113
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
static std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:93
unsigned getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:165
iterator end(unsigned Slot) const
Pass structure by value.
Definition: Attributes.h:73
AttrBuilder & remove(const AttrBuilder &B)
Remove the attributes from the builder.
Stack protection.
Definition: Attributes.h:110
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:134
Considered to not alias after call.
Definition: Attributes.h:83
StringRef getKindAsString() const
Definition: Attributes.cpp:364
static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align)
Definition: Attributes.cpp:84
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:297
std::pair< std::string, std::string > td_type
Definition: Attributes.h:543
bool hasAttribute(Attribute::AttrKind Kind) const
Definition: Attributes.cpp:497
uint64_t getDereferenceableBytes() const
Returns the number of dereferenceable bytes from the dereferenceable attribute (or zero if unknown)...
Definition: Attributes.cpp:172
unsigned getNumSlots() const
Return the number of slots used in this attribute list.
bool operator==(const AttrBuilder &B)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
Definition: STLExtras.h:287
iterator begin(unsigned Slot) const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
bool isStringAttribute() const
Definition: AttributeImpl.h:53
AttributeSet getSlotAttributes(unsigned Slot) const
Return the attributes at the given slot.
unsigned getSlotIndex(unsigned Slot) const
Get the index of the given "slot" in the AttrNodes list.
Return value is always equal to this argument.
Definition: Attributes.h:103
unsigned getAlignment() const
Definition: Attributes.cpp:525
Pass structure in an alloca.
Definition: Attributes.h:74
uint64_t getDereferenceableOrNullBytes(unsigned Index) const
Get the number of dereferenceable_or_null bytes (or zero if unknown).
uint64_t Raw(unsigned Index) const
Definition: Attributes.cpp:567
This file defines various helper methods and classes used by LLVMContextImpl for creating and managin...
iterator begin() const
Definition: ArrayRef.h:122
Zero extended before/after call.
Definition: Attributes.h:119
bool overlaps(const AttrBuilder &B) const
Return true if the builder has any attribute that's in the specified builder.
Function doesn't unwind stack.
Definition: Attributes.h:96
bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
Definition: Attributes.cpp:107
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:129
Marks function as being in a cold path.
Definition: Attributes.h:75
Sentinal value useful for loops.
Definition: Attributes.h:121
Mark the function as not returning.
Definition: Attributes.h:95
StringRef getValueAsString() const
Definition: Attributes.cpp:369
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:416
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
Definition: Type.h:217
uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute (or ze...
Definition: Attributes.cpp:179
void dump() const
bool isIntAttribute() const
Definition: AttributeImpl.h:52
Call cannot be duplicated.
Definition: Attributes.h:86
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:43
Pointer is known to be not null.
Definition: Attributes.h:91
bool hasAttribute(Attribute::AttrKind A) const
Definition: Attributes.cpp:344
LLVMContext & getContext() const
Retrieve the LLVM context.
Definition: Attributes.cpp:926
uint64_t getValueAsInt() const
Definition: Attributes.cpp:359
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
static uint64_t getAttrMask(Attribute::AttrKind Val)
Definition: Attributes.cpp:396
Callee is recognized as a builtin, despite nobuiltin attribute on its declaration.
Definition: Attributes.h:71
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
Definition: Attributes.cpp:119
iterator end(unsigned Slot) const
bool isIntAttribute() const
Return true if the attribute is an integer attribute.
Definition: Attributes.cpp:111
AttributeSetNode * getSlotNode(unsigned Slot) const
Retrieve the attribute set node for the given "slot" in the AttrNode list.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:123
unsigned Log2_32(uint32_t Value)
Log2_32 - This function returns the floor log base 2 of the specified value, -1 if the value is zero...
Definition: MathExtras.h:468
Alignment of parameter (5 bits) stored as log2 of alignment with +1 bias 0 means unaligned (different...
Definition: Attributes.h:67
AttributeSet removeAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Remove the specified attributes at the specified index from this attribute list.
Definition: Attributes.cpp:828
friend class AttributeSetImpl
Definition: Attributes.h:231
Function must not be optimized.
Definition: Attributes.h:98
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
Definition: Type.h:193
Function only reads from memory.
Definition: Attributes.h:100
static AttributeSetNode * get(LLVMContext &C, ArrayRef< Attribute > Attrs)
Definition: Attributes.cpp:463
std::map< std::string, std::string >::const_iterator td_const_iterator
Definition: Attributes.h:545
unsigned getStackAlignment() const
Definition: Attributes.cpp:532
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:481
bool operator<(Attribute A) const
Less-than operator. Useful for sorting the attributes list.
Definition: Attributes.cpp:327
Disable redzone.
Definition: Attributes.h:94
ThreadSanitizer is on.
Definition: Attributes.h:116
AttributeSet addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Attr) const
Add an attribute to the attribute set at the given index.
Definition: Attributes.cpp:753
bool hasAttrSomewhere(Attribute::AttrKind Attr) const
Return true if the specified attribute is set for at least one parameter or for the return value...
Definition: Attributes.cpp:973
unsigned getSlotIndex(unsigned Slot) const
Return the index for the given slot.
AttributeSet 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:914
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
Definition: Attributes.cpp:966
AttrBuilder typeIncompatible(const Type *Ty)
Which attributes cannot be applied to a type.
Callee isn't recognized as a builtin.
Definition: Attributes.h:84
ArrayRef< Attribute >::iterator iterator
Definition: Attributes.h:364
AddressSanitizer is on.
Definition: Attributes.h:115
#define I(x, y, z)
Definition: MD5.cpp:54
Strong Stack protection.
Definition: Attributes.h:112
bool isEnumAttribute() const
Definition: AttributeImpl.h:51
void AddString(StringRef String)
Definition: FoldingSet.cpp:87
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:115
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:34
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:546
td_range td_attrs()
Definition: Attributes.h:555
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
Funciton can access memory only using pointers based on its arguments.
Definition: Attributes.h:101
AttrBuilder & removeAttributes(AttributeSet A, uint64_t Index)
Remove the attributes from the builder.
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
Definition: Attributes.cpp:985
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:140
Function can return twice.
Definition: Attributes.h:104
const ARM::ArchExtKind Kind
unsigned getNumAttributes() const
Return the number of attributes this AttributeSet contains.
Pointer is known to be dereferenceable.
Definition: Attributes.h:92
LLVM Value Representation.
Definition: Value.h:69
uint64_t Raw(unsigned Index) const
bool hasAttributes() const
Return true if the builder has IR-level attributes.
virtual ~AttributeImpl()
Definition: Attributes.cpp:339
Disable implicit floating point insts.
Definition: Attributes.h:87
AttrBuilder & addStackAlignmentAttr(unsigned Align)
This turns an int stack alignment (which must be a power of 2) into the form used internally in Attri...
FoldingSet< AttributeSetNode > AttrsSetNodes
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
bool isPowerOf2_32(uint32_t Value)
isPowerOf2_32 - This function returns true if the argument is a power of two > 0. ...
Definition: MathExtras.h:354
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute...
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Attributes.cpp:511
AttributeSet addAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Add attributes to the attribute set at the given index.
Definition: Attributes.cpp:773
Can only be moved to control-equivalent blocks.
Definition: Attributes.h:76
Stack protection required.
Definition: Attributes.h:111
MemorySanitizer is on.
Definition: Attributes.h:117
Build jump-instruction tables and replace refs.
Definition: Attributes.h:79
Pointer is either null or dereferenceable.
Definition: Attributes.h:93
uint64_t getStackAlignment() const
Retrieve the stack alignment attribute, if it exists.
Definition: Attributes.h:512
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:64
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110
AttributeSet getFnAttributes() const
The function attributes are returned.
Definition: Attributes.cpp:947
Function must be optimized for size first.
Definition: Attributes.h:80