7bb666a40a19bd88ba5c3a160727994d3d8f4b7b
[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   LLVMContext &Context;
33   Constant *Data;
34   SmallVector<Constant*, 0> Vals;
35 public:
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);
41
42   ArrayRef<Constant*> getValues() const { return Vals; }
43
44   bool hasAttribute(Attribute::AttrKind A) const;
45
46   bool hasAttributes() const;
47
48   uint64_t getAlignment() const;
49   void setAlignment(unsigned Align);
50
51   uint64_t getStackAlignment() const;
52   void setStackAlignment(unsigned Align);
53
54   bool operator==(Attribute::AttrKind Kind) const;
55   bool operator!=(Attribute::AttrKind Kind) const;
56
57   bool operator==(StringRef Kind) const;
58   bool operator!=(StringRef Kind) const;
59
60   uint64_t getBitMask() const;         // FIXME: Remove.
61
62   static uint64_t getAttrMask(Attribute::AttrKind Val);
63
64   void Profile(FoldingSetNodeID &ID) const {
65     Profile(ID, Data, Vals);
66   }
67   static void Profile(FoldingSetNodeID &ID, Constant *Data,
68                       ArrayRef<Constant*> Vals) {
69     ID.AddPointer(Data);
70     for (ArrayRef<Constant*>::iterator I = Vals.begin(), E = Vals.end();
71          I != E; ++I)
72       ID.AddPointer(*I);
73   }
74 };
75
76 //===----------------------------------------------------------------------===//
77 /// \class
78 /// \brief This class represents a set of attributes.
79 class AttributeSetImpl : public FoldingSetNode {
80   LLVMContext &Context;
81   SmallVector<AttributeWithIndex, 4> AttrList;
82
83   // AttributesSet is uniqued, these should not be publicly available.
84   void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
85   AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
86 public:
87   AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
88     : Context(C), AttrList(attrs.begin(), attrs.end()) {}
89
90   LLVMContext &getContext() { return Context; }
91   ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; }
92   unsigned getNumAttributes() const { return AttrList.size(); }
93
94   void Profile(FoldingSetNodeID &ID) const {
95     Profile(ID, AttrList);
96   }
97   static void Profile(FoldingSetNodeID &ID,
98                       ArrayRef<AttributeWithIndex> AttrList){
99     for (unsigned i = 0, e = AttrList.size(); i != e; ++i) {
100       ID.AddInteger(AttrList[i].Index);
101       ID.AddInteger(AttrList[i].Attrs.getBitMask());
102     }
103   }
104 };
105
106 } // end llvm namespace
107
108 #endif