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 {
33 SmallVector<Constant*, 0> Vals;
35 explicit AttributeImpl(LLVMContext &C, uint64_t data);
36 explicit AttributeImpl(LLVMContext &C, Attribute::AttrKind data);
37 AttributeImpl(LLVMContext &C, Attribute::AttrKind data,
38 ArrayRef<Constant*> values);
39 AttributeImpl(LLVMContext &C, StringRef data);
41 ArrayRef<Constant*> getValues() const {
45 bool hasAttribute(Attribute::AttrKind A) const;
47 bool hasAttributes() const;
48 bool hasAttributes(const Attribute &A) const;
50 uint64_t getAlignment() const;
51 uint64_t getStackAlignment() const;
53 bool operator==(Attribute::AttrKind Kind) const;
54 bool operator!=(Attribute::AttrKind Kind) const;
56 bool operator==(StringRef Kind) const;
57 bool operator!=(StringRef Kind) const;
59 uint64_t getBitMask() const; // FIXME: Remove.
61 static uint64_t getAttrMask(Attribute::AttrKind Val);
63 void Profile(FoldingSetNodeID &ID) const {
64 Profile(ID, Data, Vals);
66 static void Profile(FoldingSetNodeID &ID, Constant *Data,
67 ArrayRef<Constant*> Vals) {
69 for (ArrayRef<Constant*>::iterator I = Vals.begin(), E = Vals.end();
75 //===----------------------------------------------------------------------===//
77 /// \brief This class represents a set of attributes.
78 class AttributeSetImpl : public FoldingSetNode {
79 // AttributesSet is uniqued, these should not be publicly available.
80 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
81 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
84 SmallVector<AttributeWithIndex, 4> Attrs;
86 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
87 : Context(C), Attrs(attrs.begin(), attrs.end()) {}
89 void Profile(FoldingSetNodeID &ID) const {
92 static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
93 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
94 ID.AddInteger(Attrs[i].Attrs.getBitMask());
95 ID.AddInteger(Attrs[i].Index);
100 } // end llvm namespace