blob: 7bb666a40a19bd88ba5c3a160727994d3d8f4b7b [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 Carruth0b8c9a82013-01-02 11:36:10 +000020#include "llvm/IR/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 Wendling1bbd6442013-01-05 01:36:54 +000032 LLVMContext &Context;
Bill Wendling7c1683d2012-12-29 12:29:38 +000033 Constant *Data;
Bill Wendling979aff62012-12-30 02:22:16 +000034 SmallVector<Constant*, 0> Vals;
Bill Wendling2c79ecb2012-09-26 21:07:29 +000035public:
Bill Wendling979aff62012-12-30 02:22:16 +000036 explicit AttributeImpl(LLVMContext &C, uint64_t data);
37 explicit AttributeImpl(LLVMContext &C, Attribute::AttrKind data);
38 AttributeImpl(LLVMContext &C, Attribute::AttrKind data,
39 ArrayRef<Constant*> values);
40 AttributeImpl(LLVMContext &C, StringRef data);
41
Bill Wendlinga90a99a2013-01-07 08:24:35 +000042 ArrayRef<Constant*> getValues() const { return Vals; }
Bill Wendling2c79ecb2012-09-26 21:07:29 +000043
Bill Wendling60507d52013-01-04 20:54:35 +000044 bool hasAttribute(Attribute::AttrKind A) const;
Bill Wendling67658342012-10-09 07:45:08 +000045
Bill Wendling8e635db2012-10-08 21:47:17 +000046 bool hasAttributes() const;
Bill Wendling8e635db2012-10-08 21:47:17 +000047
48 uint64_t getAlignment() const;
Bill Wendling1bbd6442013-01-05 01:36:54 +000049 void setAlignment(unsigned Align);
50
Bill Wendling8e635db2012-10-08 21:47:17 +000051 uint64_t getStackAlignment() const;
Bill Wendling1bbd6442013-01-05 01:36:54 +000052 void setStackAlignment(unsigned Align);
Bill Wendling8e635db2012-10-08 21:47:17 +000053
Bill Wendling60507d52013-01-04 20:54:35 +000054 bool operator==(Attribute::AttrKind Kind) const;
55 bool operator!=(Attribute::AttrKind Kind) const;
Bill Wendling529ec712012-12-30 01:38:39 +000056
Bill Wendling60507d52013-01-04 20:54:35 +000057 bool operator==(StringRef Kind) const;
58 bool operator!=(StringRef Kind) const;
Bill Wendling529ec712012-12-30 01:38:39 +000059
Bill Wendlingc966e082012-12-30 01:05:42 +000060 uint64_t getBitMask() const; // FIXME: Remove.
Bill Wendling925bcb12012-10-16 05:57:28 +000061
Bill Wendling60507d52013-01-04 20:54:35 +000062 static uint64_t getAttrMask(Attribute::AttrKind Val);
Bill Wendling2e879bc2012-10-09 09:11:20 +000063
Bill Wendling2c79ecb2012-09-26 21:07:29 +000064 void Profile(FoldingSetNodeID &ID) const {
Bill Wendling979aff62012-12-30 02:22:16 +000065 Profile(ID, Data, Vals);
Bill Wendling2c79ecb2012-09-26 21:07:29 +000066 }
Bill Wendling979aff62012-12-30 02:22:16 +000067 static void Profile(FoldingSetNodeID &ID, Constant *Data,
68 ArrayRef<Constant*> Vals) {
Bill Wendling435654b2012-12-30 01:23:08 +000069 ID.AddPointer(Data);
Bill Wendling979aff62012-12-30 02:22:16 +000070 for (ArrayRef<Constant*>::iterator I = Vals.begin(), E = Vals.end();
71 I != E; ++I)
72 ID.AddPointer(*I);
Bill Wendling435654b2012-12-30 01:23:08 +000073 }
Bill Wendling2c79ecb2012-09-26 21:07:29 +000074};
75
Bill Wendling27107f62012-12-20 21:28:43 +000076//===----------------------------------------------------------------------===//
77/// \class
78/// \brief This class represents a set of attributes.
Bill Wendling18e72112012-12-19 22:42:22 +000079class AttributeSetImpl : public FoldingSetNode {
Bill Wendling60507d52013-01-04 20:54:35 +000080 LLVMContext &Context;
81 SmallVector<AttributeWithIndex, 4> AttrList;
82
Bill Wendling831737d2012-12-30 10:32:01 +000083 // AttributesSet is uniqued, these should not be publicly available.
Bill Wendling18e72112012-12-19 22:42:22 +000084 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
85 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
Bill Wendling0976e002012-11-20 05:09:20 +000086public:
Bill Wendling5f93e2b2012-12-19 23:55:43 +000087 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
Bill Wendling60507d52013-01-04 20:54:35 +000088 : Context(C), AttrList(attrs.begin(), attrs.end()) {}
89
90 LLVMContext &getContext() { return Context; }
91 ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; }
92 unsigned getNumAttributes() const { return AttrList.size(); }
Bill Wendling0976e002012-11-20 05:09:20 +000093
94 void Profile(FoldingSetNodeID &ID) const {
Bill Wendling60507d52013-01-04 20:54:35 +000095 Profile(ID, AttrList);
Bill Wendling0976e002012-11-20 05:09:20 +000096 }
Bill Wendling60507d52013-01-04 20:54:35 +000097 static void Profile(FoldingSetNodeID &ID,
98 ArrayRef<AttributeWithIndex> AttrList){
99 for (unsigned i = 0, e = AttrList.size(); i != e; ++i) {
100 ID.AddInteger(AttrList[i].Index);
101 ID.AddInteger(AttrList[i].Attrs.getBitMask());
Bill Wendling0976e002012-11-20 05:09:20 +0000102 }
103 }
104};
105
Bill Wendling2c79ecb2012-09-26 21:07:29 +0000106} // end llvm namespace
107
108#endif