1 //===-- AttributeImpl.h - Attribute Internals -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief This file defines various helper methods and classes used by
12 /// LLVMContextImpl for creating and managing attributes.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_ATTRIBUTESIMPL_H
17 #define LLVM_ATTRIBUTESIMPL_H
19 #include "llvm/ADT/FoldingSet.h"
20 #include "llvm/Attributes.h"
27 //===----------------------------------------------------------------------===//
29 /// \brief This class represents a single, uniqued attribute. That attribute
30 /// could be a single enum, a tuple, or a string. It uses a discriminated union
31 /// to distinguish them.
32 class AttributeImpl : public FoldingSetNode {
35 AttributeImpl(LLVMContext &C, uint64_t data);
37 bool contains(Attribute::AttrKind Kind) const;
38 bool contains(StringRef Kind) const;
40 bool hasAttribute(uint64_t A) const;
42 bool hasAttributes() const;
43 bool hasAttributes(const Attribute &A) const;
45 uint64_t getAlignment() const;
46 uint64_t getStackAlignment() const;
48 bool operator==(Attribute::AttrKind Kind) const {
49 return contains(Kind);
51 bool operator!=(Attribute::AttrKind Kind) const {
52 return !contains(Kind);
55 bool operator==(StringRef Kind) const {
56 return contains(Kind);
58 bool operator!=(StringRef Kind) const {
59 return !contains(Kind);
62 uint64_t getBitMask() const; // FIXME: Remove.
64 static uint64_t getAttrMask(uint64_t Val);
66 void Profile(FoldingSetNodeID &ID) const {
69 static void Profile(FoldingSetNodeID &ID, Constant *Data) {
74 //===----------------------------------------------------------------------===//
76 /// \brief This class represents a set of attributes.
77 class AttributeSetImpl : public FoldingSetNode {
78 // AttributesList is uniqued, these should not be publicly available.
79 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
80 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
83 SmallVector<AttributeWithIndex, 4> Attrs;
85 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
86 : Context(C), Attrs(attrs.begin(), attrs.end()) {}
88 void Profile(FoldingSetNodeID &ID) const {
91 static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
92 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
93 ID.AddInteger(Attrs[i].Attrs.getBitMask());
94 ID.AddInteger(Attrs[i].Index);
99 } // end llvm namespace