General cleanups.
[oota-llvm.git] / lib / IR / AttributeImpl.h
1 //===-- AttributeImpl.h - Attribute Internals -------------------*- C++ -*-===//
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 defines various helper methods and classes used by
12 /// LLVMContextImpl for creating and managing attributes.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_ATTRIBUTESIMPL_H
17 #define LLVM_ATTRIBUTESIMPL_H
18
19 #include "llvm/ADT/FoldingSet.h"
20 #include "llvm/IR/Attributes.h"
21
22 namespace llvm {
23
24 class Constant;
25 class LLVMContext;
26
27 //===----------------------------------------------------------------------===//
28 /// \class
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 {
32   Constant *Data;
33   SmallVector<Constant*, 0> Vals;
34 public:
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);
40
41   ArrayRef<Constant*> getValues() const {
42     return Vals;
43   }
44
45   bool hasAttribute(Attribute::AttrKind A) const;
46
47   bool hasAttributes() const;
48
49   uint64_t getAlignment() const;
50   uint64_t getStackAlignment() const;
51
52   bool operator==(Attribute::AttrKind Kind) const;
53   bool operator!=(Attribute::AttrKind Kind) const;
54
55   bool operator==(StringRef Kind) const;
56   bool operator!=(StringRef Kind) const;
57
58   uint64_t getBitMask() const;         // FIXME: Remove.
59
60   static uint64_t getAttrMask(Attribute::AttrKind Val);
61
62   void Profile(FoldingSetNodeID &ID) const {
63     Profile(ID, Data, Vals);
64   }
65   static void Profile(FoldingSetNodeID &ID, Constant *Data,
66                       ArrayRef<Constant*> Vals) {
67     ID.AddPointer(Data);
68     for (ArrayRef<Constant*>::iterator I = Vals.begin(), E = Vals.end();
69          I != E; ++I)
70       ID.AddPointer(*I);
71   }
72 };
73
74 //===----------------------------------------------------------------------===//
75 /// \class
76 /// \brief This class represents a set of attributes.
77 class AttributeSetImpl : public FoldingSetNode {
78   LLVMContext &Context;
79   SmallVector<AttributeWithIndex, 4> AttrList;
80
81   // AttributesSet is uniqued, these should not be publicly available.
82   void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
83   AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
84 public:
85   AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
86     : Context(C), AttrList(attrs.begin(), attrs.end()) {}
87
88   LLVMContext &getContext() { return Context; }
89   ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; }
90   unsigned getNumAttributes() const { return AttrList.size(); }
91
92   void Profile(FoldingSetNodeID &ID) const {
93     Profile(ID, AttrList);
94   }
95   static void Profile(FoldingSetNodeID &ID,
96                       ArrayRef<AttributeWithIndex> AttrList){
97     for (unsigned i = 0, e = AttrList.size(); i != e; ++i) {
98       ID.AddInteger(AttrList[i].Index);
99       ID.AddInteger(AttrList[i].Attrs.getBitMask());
100     }
101   }
102 };
103
104 } // end llvm namespace
105
106 #endif