Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 1 | //===-- AttributeImpl.h - Attribute Internals -------------------*- C++ -*-===// |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Bill Wendling | 66e978f | 2012-12-20 21:28:43 +0000 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
| 11 | /// \brief This file defines various helper methods and classes used by |
| 12 | /// LLVMContextImpl for creating and managing attributes. |
| 13 | /// |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef LLVM_ATTRIBUTESIMPL_H |
| 17 | #define LLVM_ATTRIBUTESIMPL_H |
| 18 | |
| 19 | #include "llvm/ADT/FoldingSet.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 20 | #include "llvm/Attributes.h" |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | |
Bill Wendling | 0cd0f7f | 2012-12-29 12:29:38 +0000 | [diff] [blame] | 24 | class Constant; |
Bill Wendling | 6ad6c3b | 2012-12-19 23:55:43 +0000 | [diff] [blame] | 25 | class LLVMContext; |
| 26 | |
Bill Wendling | 66e978f | 2012-12-20 21:28:43 +0000 | [diff] [blame] | 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. |
Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 32 | class AttributeImpl : public FoldingSetNode { |
Bill Wendling | 0cd0f7f | 2012-12-29 12:29:38 +0000 | [diff] [blame] | 33 | Constant *Data; |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 34 | public: |
Bill Wendling | 0cd0f7f | 2012-12-29 12:29:38 +0000 | [diff] [blame] | 35 | AttributeImpl(LLVMContext &C, uint64_t data); |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 36 | |
Bill Wendling | b1d1261 | 2012-12-30 01:38:39 +0000 | [diff] [blame] | 37 | bool contains(Attribute::AttrKind Kind) const; |
| 38 | bool contains(StringRef Kind) const; |
| 39 | |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 40 | bool hasAttribute(uint64_t A) const; |
Bill Wendling | c9b22d7 | 2012-10-09 07:45:08 +0000 | [diff] [blame] | 41 | |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 42 | bool hasAttributes() const; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 43 | bool hasAttributes(const Attribute &A) const; |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 44 | |
| 45 | uint64_t getAlignment() const; |
| 46 | uint64_t getStackAlignment() const; |
| 47 | |
Bill Wendling | b1d1261 | 2012-12-30 01:38:39 +0000 | [diff] [blame] | 48 | bool operator==(Attribute::AttrKind Kind) const { |
| 49 | return contains(Kind); |
| 50 | } |
| 51 | bool operator!=(Attribute::AttrKind Kind) const { |
| 52 | return !contains(Kind); |
| 53 | } |
| 54 | |
| 55 | bool operator==(StringRef Kind) const { |
| 56 | return contains(Kind); |
| 57 | } |
| 58 | bool operator!=(StringRef Kind) const { |
| 59 | return !contains(Kind); |
| 60 | } |
| 61 | |
Bill Wendling | 3e4c4c9 | 2012-12-30 01:05:42 +0000 | [diff] [blame] | 62 | uint64_t getBitMask() const; // FIXME: Remove. |
Bill Wendling | 147ee8e | 2012-10-16 05:57:28 +0000 | [diff] [blame] | 63 | |
Bill Wendling | 93f70b7 | 2012-10-09 09:11:20 +0000 | [diff] [blame] | 64 | static uint64_t getAttrMask(uint64_t Val); |
| 65 | |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 66 | void Profile(FoldingSetNodeID &ID) const { |
Bill Wendling | 0cd0f7f | 2012-12-29 12:29:38 +0000 | [diff] [blame] | 67 | Profile(ID, Data); |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 68 | } |
Bill Wendling | 5e8ff87 | 2012-12-30 01:23:08 +0000 | [diff] [blame] | 69 | static void Profile(FoldingSetNodeID &ID, Constant *Data) { |
| 70 | ID.AddPointer(Data); |
| 71 | } |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
Bill Wendling | 66e978f | 2012-12-20 21:28:43 +0000 | [diff] [blame] | 74 | //===----------------------------------------------------------------------===// |
| 75 | /// \class |
| 76 | /// \brief This class represents a set of attributes. |
Bill Wendling | 6848e38 | 2012-12-19 22:42:22 +0000 | [diff] [blame] | 77 | class AttributeSetImpl : public FoldingSetNode { |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 78 | // AttributesList is uniqued, these should not be publicly available. |
Bill Wendling | 6848e38 | 2012-12-19 22:42:22 +0000 | [diff] [blame] | 79 | void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; |
| 80 | AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 81 | public: |
Bill Wendling | 6ad6c3b | 2012-12-19 23:55:43 +0000 | [diff] [blame] | 82 | LLVMContext &Context; |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 83 | SmallVector<AttributeWithIndex, 4> Attrs; |
| 84 | |
Bill Wendling | 6ad6c3b | 2012-12-19 23:55:43 +0000 | [diff] [blame] | 85 | AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs) |
| 86 | : Context(C), Attrs(attrs.begin(), attrs.end()) {} |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 87 | |
| 88 | void Profile(FoldingSetNodeID &ID) const { |
| 89 | Profile(ID, Attrs); |
| 90 | } |
| 91 | static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){ |
| 92 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { |
Bill Wendling | 3e4c4c9 | 2012-12-30 01:05:42 +0000 | [diff] [blame] | 93 | ID.AddInteger(Attrs[i].Attrs.getBitMask()); |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 94 | ID.AddInteger(Attrs[i].Index); |
| 95 | } |
| 96 | } |
| 97 | }; |
| 98 | |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 99 | } // end llvm namespace |
| 100 | |
| 101 | #endif |