253d6e82eb788a380b497c677c68b2de9b35cc90
[oota-llvm.git] / lib / VMCore / 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/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. It uses a discriminated union
31 /// to distinguish them.
32 class AttributeImpl : public FoldingSetNode {
33   Constant *Data;
34 public:
35   AttributeImpl(LLVMContext &C, uint64_t data);
36
37   bool hasAttribute(uint64_t A) const;
38
39   bool hasAttributes() const;
40   bool hasAttributes(const Attribute &A) const;
41
42   uint64_t getAlignment() const;
43   uint64_t getStackAlignment() const;
44
45   uint64_t getBitMask() const;         // FIXME: Remove.
46
47   static uint64_t getAttrMask(uint64_t Val);
48
49   void Profile(FoldingSetNodeID &ID) const {
50     Profile(ID, Data);
51   }
52   static void Profile(FoldingSetNodeID &ID, Constant *Data);
53 };
54
55 //===----------------------------------------------------------------------===//
56 /// \class
57 /// \brief This class represents a set of attributes.
58 class AttributeSetImpl : public FoldingSetNode {
59   // AttributesList is uniqued, these should not be publicly available.
60   void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
61   AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
62 public:
63   LLVMContext &Context;
64   SmallVector<AttributeWithIndex, 4> Attrs;
65
66   AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
67     : Context(C), Attrs(attrs.begin(), attrs.end()) {}
68
69   void Profile(FoldingSetNodeID &ID) const {
70     Profile(ID, Attrs);
71   }
72   static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
73     for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
74       ID.AddInteger(Attrs[i].Attrs.getBitMask());
75       ID.AddInteger(Attrs[i].Index);
76     }
77   }
78 };
79
80 } // end llvm namespace
81
82 #endif