blob: cab1c94255d8d5293c4df51456aa09124269e1f9 [file] [log] [blame]
Bill Wendlingf6670722012-12-20 01:36:59 +00001//===-- AttributeImpl.h - Attribute Internals -------------------*- C++ -*-===//
Bill Wendling2c79ecb2012-09-26 21:07:29 +00002//
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 Wendling27107f62012-12-20 21:28:43 +00009///
10/// \file
11/// \brief This file defines various helper methods and classes used by
12/// LLVMContextImpl for creating and managing attributes.
13///
Bill Wendling2c79ecb2012-09-26 21:07:29 +000014//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_ATTRIBUTESIMPL_H
17#define LLVM_ATTRIBUTESIMPL_H
18
19#include "llvm/ADT/FoldingSet.h"
Chandler Carrutha1514e22012-12-04 07:12:27 +000020#include "llvm/Attributes.h"
Bill Wendling2c79ecb2012-09-26 21:07:29 +000021
22namespace llvm {
23
Bill Wendling7c1683d2012-12-29 12:29:38 +000024class Constant;
Bill Wendling5f93e2b2012-12-19 23:55:43 +000025class LLVMContext;
26
Bill Wendling27107f62012-12-20 21:28:43 +000027//===----------------------------------------------------------------------===//
28/// \class
29/// \brief This class represents a single, uniqued attribute. That attribute
Bill Wendling979aff62012-12-30 02:22:16 +000030/// could be a single enum, a tuple, or a string.
Bill Wendlingf6670722012-12-20 01:36:59 +000031class AttributeImpl : public FoldingSetNode {
Bill Wendling7c1683d2012-12-29 12:29:38 +000032 Constant *Data;
Bill Wendling979aff62012-12-30 02:22:16 +000033 SmallVector<Constant*, 0> Vals;
Bill Wendling2c79ecb2012-09-26 21:07:29 +000034public:
Bill Wendling979aff62012-12-30 02:22:16 +000035 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 Wendling2c79ecb2012-09-26 21:07:29 +000044
Bill Wendling529ec712012-12-30 01:38:39 +000045 bool contains(Attribute::AttrKind Kind) const;
46 bool contains(StringRef Kind) const;
47
Bill Wendling8e635db2012-10-08 21:47:17 +000048 bool hasAttribute(uint64_t A) const;
Bill Wendling67658342012-10-09 07:45:08 +000049
Bill Wendling8e635db2012-10-08 21:47:17 +000050 bool hasAttributes() const;
Bill Wendling034b94b2012-12-19 07:18:57 +000051 bool hasAttributes(const Attribute &A) const;
Bill Wendling8e635db2012-10-08 21:47:17 +000052
53 uint64_t getAlignment() const;
54 uint64_t getStackAlignment() const;
55
Bill Wendling529ec712012-12-30 01:38:39 +000056 bool operator==(Attribute::AttrKind Kind) const {
57 return contains(Kind);
58 }
59 bool operator!=(Attribute::AttrKind Kind) const {
60 return !contains(Kind);
61 }
62
63 bool operator==(StringRef Kind) const {
64 return contains(Kind);
65 }
66 bool operator!=(StringRef Kind) const {
67 return !contains(Kind);
68 }
69
Bill Wendlingc966e082012-12-30 01:05:42 +000070 uint64_t getBitMask() const; // FIXME: Remove.
Bill Wendling925bcb12012-10-16 05:57:28 +000071
Bill Wendling2e879bc2012-10-09 09:11:20 +000072 static uint64_t getAttrMask(uint64_t Val);
73
Bill Wendling2c79ecb2012-09-26 21:07:29 +000074 void Profile(FoldingSetNodeID &ID) const {
Bill Wendling979aff62012-12-30 02:22:16 +000075 Profile(ID, Data, Vals);
Bill Wendling2c79ecb2012-09-26 21:07:29 +000076 }
Bill Wendling979aff62012-12-30 02:22:16 +000077 static void Profile(FoldingSetNodeID &ID, Constant *Data,
78 ArrayRef<Constant*> Vals) {
Bill Wendling435654b2012-12-30 01:23:08 +000079 ID.AddPointer(Data);
Bill Wendling979aff62012-12-30 02:22:16 +000080 for (ArrayRef<Constant*>::iterator I = Vals.begin(), E = Vals.end();
81 I != E; ++I)
82 ID.AddPointer(*I);
Bill Wendling435654b2012-12-30 01:23:08 +000083 }
Bill Wendling2c79ecb2012-09-26 21:07:29 +000084};
85
Bill Wendling27107f62012-12-20 21:28:43 +000086//===----------------------------------------------------------------------===//
87/// \class
88/// \brief This class represents a set of attributes.
Bill Wendling18e72112012-12-19 22:42:22 +000089class AttributeSetImpl : public FoldingSetNode {
Bill Wendling0976e002012-11-20 05:09:20 +000090 // AttributesList is uniqued, these should not be publicly available.
Bill Wendling18e72112012-12-19 22:42:22 +000091 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
92 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
Bill Wendling0976e002012-11-20 05:09:20 +000093public:
Bill Wendling5f93e2b2012-12-19 23:55:43 +000094 LLVMContext &Context;
Bill Wendling0976e002012-11-20 05:09:20 +000095 SmallVector<AttributeWithIndex, 4> Attrs;
96
Bill Wendling5f93e2b2012-12-19 23:55:43 +000097 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
98 : Context(C), Attrs(attrs.begin(), attrs.end()) {}
Bill Wendling0976e002012-11-20 05:09:20 +000099
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 Wendlingc966e082012-12-30 01:05:42 +0000105 ID.AddInteger(Attrs[i].Attrs.getBitMask());
Bill Wendling0976e002012-11-20 05:09:20 +0000106 ID.AddInteger(Attrs[i].Index);
107 }
108 }
109};
110
Bill Wendling2c79ecb2012-09-26 21:07:29 +0000111} // end llvm namespace
112
113#endif