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/IR/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.
31 class AttributeImpl : public FoldingSetNode {
34 SmallVector<Constant*, 0> Vals;
36 explicit AttributeImpl(LLVMContext &C, uint64_t data);
37 explicit AttributeImpl(LLVMContext &C, Attribute::AttrKind data);
38 AttributeImpl(LLVMContext &C, Attribute::AttrKind data,
39 ArrayRef<Constant*> values);
40 AttributeImpl(LLVMContext &C, StringRef data);
42 ArrayRef<Constant*> getValues() const {
46 bool hasAttribute(Attribute::AttrKind A) const;
48 bool hasAttributes() const;
50 uint64_t getAlignment() const;
51 void setAlignment(unsigned Align);
53 uint64_t getStackAlignment() const;
54 void setStackAlignment(unsigned Align);
56 bool operator==(Attribute::AttrKind Kind) const;
57 bool operator!=(Attribute::AttrKind Kind) const;
59 bool operator==(StringRef Kind) const;
60 bool operator!=(StringRef Kind) const;
62 uint64_t getBitMask() const; // FIXME: Remove.
64 static uint64_t getAttrMask(Attribute::AttrKind Val);
66 void Profile(FoldingSetNodeID &ID) const {
67 Profile(ID, Data, Vals);
69 static void Profile(FoldingSetNodeID &ID, Constant *Data,
70 ArrayRef<Constant*> Vals) {
72 for (ArrayRef<Constant*>::iterator I = Vals.begin(), E = Vals.end();
78 //===----------------------------------------------------------------------===//
80 /// \brief This class represents a set of attributes.
81 class AttributeSetImpl : public FoldingSetNode {
83 SmallVector<AttributeWithIndex, 4> AttrList;
85 // AttributesSet is uniqued, these should not be publicly available.
86 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
87 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
89 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
90 : Context(C), AttrList(attrs.begin(), attrs.end()) {}
92 LLVMContext &getContext() { return Context; }
93 ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; }
94 unsigned getNumAttributes() const { return AttrList.size(); }
96 void Profile(FoldingSetNodeID &ID) const {
97 Profile(ID, AttrList);
99 static void Profile(FoldingSetNodeID &ID,
100 ArrayRef<AttributeWithIndex> AttrList){
101 for (unsigned i = 0, e = AttrList.size(); i != e; ++i) {
102 ID.AddInteger(AttrList[i].Index);
103 ID.AddInteger(AttrList[i].Attrs.getBitMask());
108 } // end llvm namespace