Uniquify the AttributeImpl based on the Constant pointer, since those are
[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     ID.AddPointer(Data);
54   }
55 };
56
57 //===----------------------------------------------------------------------===//
58 /// \class
59 /// \brief This class represents a set of attributes.
60 class AttributeSetImpl : public FoldingSetNode {
61   // AttributesList is uniqued, these should not be publicly available.
62   void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
63   AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
64 public:
65   LLVMContext &Context;
66   SmallVector<AttributeWithIndex, 4> Attrs;
67
68   AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
69     : Context(C), Attrs(attrs.begin(), attrs.end()) {}
70
71   void Profile(FoldingSetNodeID &ID) const {
72     Profile(ID, Attrs);
73   }
74   static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
75     for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
76       ID.AddInteger(Attrs[i].Attrs.getBitMask());
77       ID.AddInteger(Attrs[i].Index);
78     }
79   }
80 };
81
82 } // end llvm namespace
83
84 #endif