Bill Wendling | f667072 | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 1 | //===-- AttributeImpl.h - Attribute Internals -------------------*- C++ -*-===// |
Bill Wendling | 2c79ecb | 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 | 27107f6 | 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 | 2c79ecb | 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 | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Attributes.h" |
Bill Wendling | 2c79ecb | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | |
Bill Wendling | 7c1683d | 2012-12-29 12:29:38 +0000 | [diff] [blame] | 24 | class Constant; |
Bill Wendling | 5f93e2b | 2012-12-19 23:55:43 +0000 | [diff] [blame] | 25 | class LLVMContext; |
| 26 | |
Bill Wendling | 27107f6 | 2012-12-20 21:28:43 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
| 28 | /// \class |
| 29 | /// \brief This class represents a single, uniqued attribute. That attribute |
Bill Wendling | 979aff6 | 2012-12-30 02:22:16 +0000 | [diff] [blame] | 30 | /// could be a single enum, a tuple, or a string. |
Bill Wendling | f667072 | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 31 | class AttributeImpl : public FoldingSetNode { |
Bill Wendling | 7c1683d | 2012-12-29 12:29:38 +0000 | [diff] [blame] | 32 | Constant *Data; |
Bill Wendling | 979aff6 | 2012-12-30 02:22:16 +0000 | [diff] [blame] | 33 | SmallVector<Constant*, 0> Vals; |
Bill Wendling | 2c79ecb | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 34 | public: |
Bill Wendling | 979aff6 | 2012-12-30 02:22:16 +0000 | [diff] [blame] | 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 | } |
Bill Wendling | 2c79ecb | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 44 | |
Bill Wendling | 22bd641 | 2013-01-03 01:54:39 +0000 | [diff] [blame] | 45 | bool contains(Attribute::AttrKind Kind) const; |
| 46 | bool contains(StringRef Kind) const; |
| 47 | |
Bill Wendling | e5ab1be | 2013-01-03 02:01:50 +0000 | [diff] [blame] | 48 | bool hasAttribute(uint64_t A) const; |
Bill Wendling | 6765834 | 2012-10-09 07:45:08 +0000 | [diff] [blame] | 49 | |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 50 | bool hasAttributes() const; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 51 | bool hasAttributes(const Attribute &A) const; |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 52 | |
| 53 | uint64_t getAlignment() const; |
| 54 | uint64_t getStackAlignment() const; |
| 55 | |
Bill Wendling | 22bd641 | 2013-01-03 01:54:39 +0000 | [diff] [blame] | 56 | bool operator==(Attribute::AttrKind Kind) const { |
| 57 | return contains(Kind); |
| 58 | } |
| 59 | bool operator!=(Attribute::AttrKind Kind) const { |
| 60 | return !contains(Kind); |
| 61 | } |
Bill Wendling | 529ec71 | 2012-12-30 01:38:39 +0000 | [diff] [blame] | 62 | |
Bill Wendling | 22bd641 | 2013-01-03 01:54:39 +0000 | [diff] [blame] | 63 | bool operator==(StringRef Kind) const { |
| 64 | return contains(Kind); |
| 65 | } |
| 66 | bool operator!=(StringRef Kind) const { |
| 67 | return !contains(Kind); |
| 68 | } |
Bill Wendling | 529ec71 | 2012-12-30 01:38:39 +0000 | [diff] [blame] | 69 | |
Bill Wendling | c966e08 | 2012-12-30 01:05:42 +0000 | [diff] [blame] | 70 | uint64_t getBitMask() const; // FIXME: Remove. |
Bill Wendling | 925bcb1 | 2012-10-16 05:57:28 +0000 | [diff] [blame] | 71 | |
Bill Wendling | e5ab1be | 2013-01-03 02:01:50 +0000 | [diff] [blame] | 72 | static uint64_t getAttrMask(uint64_t Val); |
Bill Wendling | 2e879bc | 2012-10-09 09:11:20 +0000 | [diff] [blame] | 73 | |
Bill Wendling | 2c79ecb | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 74 | void Profile(FoldingSetNodeID &ID) const { |
Bill Wendling | 979aff6 | 2012-12-30 02:22:16 +0000 | [diff] [blame] | 75 | Profile(ID, Data, Vals); |
Bill Wendling | 2c79ecb | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 76 | } |
Bill Wendling | 979aff6 | 2012-12-30 02:22:16 +0000 | [diff] [blame] | 77 | static void Profile(FoldingSetNodeID &ID, Constant *Data, |
| 78 | ArrayRef<Constant*> Vals) { |
Bill Wendling | 435654b | 2012-12-30 01:23:08 +0000 | [diff] [blame] | 79 | ID.AddPointer(Data); |
Bill Wendling | 979aff6 | 2012-12-30 02:22:16 +0000 | [diff] [blame] | 80 | for (ArrayRef<Constant*>::iterator I = Vals.begin(), E = Vals.end(); |
| 81 | I != E; ++I) |
| 82 | ID.AddPointer(*I); |
Bill Wendling | 435654b | 2012-12-30 01:23:08 +0000 | [diff] [blame] | 83 | } |
Bill Wendling | 2c79ecb | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Bill Wendling | 27107f6 | 2012-12-20 21:28:43 +0000 | [diff] [blame] | 86 | //===----------------------------------------------------------------------===// |
| 87 | /// \class |
| 88 | /// \brief This class represents a set of attributes. |
Bill Wendling | 18e7211 | 2012-12-19 22:42:22 +0000 | [diff] [blame] | 89 | class AttributeSetImpl : public FoldingSetNode { |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 90 | // AttributesSet is uniqued, these should not be publicly available. |
Bill Wendling | 18e7211 | 2012-12-19 22:42:22 +0000 | [diff] [blame] | 91 | void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; |
| 92 | AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; |
Bill Wendling | 0976e00 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 93 | public: |
Bill Wendling | 5f93e2b | 2012-12-19 23:55:43 +0000 | [diff] [blame] | 94 | LLVMContext &Context; |
Bill Wendling | 0976e00 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 95 | SmallVector<AttributeWithIndex, 4> Attrs; |
| 96 | |
Bill Wendling | 5f93e2b | 2012-12-19 23:55:43 +0000 | [diff] [blame] | 97 | AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs) |
| 98 | : Context(C), Attrs(attrs.begin(), attrs.end()) {} |
Bill Wendling | 0976e00 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 99 | |
| 100 | void Profile(FoldingSetNodeID &ID) const { |
| 101 | Profile(ID, Attrs); |
| 102 | } |
| 103 | static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){ |
| 104 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { |
Bill Wendling | c966e08 | 2012-12-30 01:05:42 +0000 | [diff] [blame] | 105 | ID.AddInteger(Attrs[i].Attrs.getBitMask()); |
Bill Wendling | 0976e00 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 106 | ID.AddInteger(Attrs[i].Index); |
| 107 | } |
| 108 | } |
| 109 | }; |
| 110 | |
Bill Wendling | 2c79ecb | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 111 | } // end llvm namespace |
| 112 | |
| 113 | #endif |