blob: 42b4fe36b22cd907b7daef5d2070eebff4abe00e [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 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 Wendling60507d52013-01-04 20:54:35 +000045 bool hasAttribute(Attribute::AttrKind A) const;
Bill Wendling67658342012-10-09 07:45:08 +000046
Bill Wendling8e635db2012-10-08 21:47:17 +000047 bool hasAttributes() const;
Bill Wendling8e635db2012-10-08 21:47:17 +000048
49 uint64_t getAlignment() const;
50 uint64_t getStackAlignment() const;
51
Bill Wendling60507d52013-01-04 20:54:35 +000052 bool operator==(Attribute::AttrKind Kind) const;
53 bool operator!=(Attribute::AttrKind Kind) const;
Bill Wendling529ec712012-12-30 01:38:39 +000054
Bill Wendling60507d52013-01-04 20:54:35 +000055 bool operator==(StringRef Kind) const;
56 bool operator!=(StringRef Kind) const;
Bill Wendling529ec712012-12-30 01:38:39 +000057
Bill Wendlingc966e082012-12-30 01:05:42 +000058 uint64_t getBitMask() const; // FIXME: Remove.
Bill Wendling925bcb12012-10-16 05:57:28 +000059
Bill Wendling60507d52013-01-04 20:54:35 +000060 static uint64_t getAttrMask(Attribute::AttrKind Val);
Bill Wendling2e879bc2012-10-09 09:11:20 +000061
Bill Wendling2c79ecb2012-09-26 21:07:29 +000062 void Profile(FoldingSetNodeID &ID) const {
Bill Wendling979aff62012-12-30 02:22:16 +000063 Profile(ID, Data, Vals);
Bill Wendling2c79ecb2012-09-26 21:07:29 +000064 }
Bill Wendling979aff62012-12-30 02:22:16 +000065 static void Profile(FoldingSetNodeID &ID, Constant *Data,
66 ArrayRef<Constant*> Vals) {
Bill Wendling435654b2012-12-30 01:23:08 +000067 ID.AddPointer(Data);
Bill Wendling979aff62012-12-30 02:22:16 +000068 for (ArrayRef<Constant*>::iterator I = Vals.begin(), E = Vals.end();
69 I != E; ++I)
70 ID.AddPointer(*I);
Bill Wendling435654b2012-12-30 01:23:08 +000071 }
Bill Wendling2c79ecb2012-09-26 21:07:29 +000072};
73
Bill Wendling27107f62012-12-20 21:28:43 +000074//===----------------------------------------------------------------------===//
75/// \class
76/// \brief This class represents a set of attributes.
Bill Wendling18e72112012-12-19 22:42:22 +000077class AttributeSetImpl : public FoldingSetNode {
Bill Wendling60507d52013-01-04 20:54:35 +000078 LLVMContext &Context;
79 SmallVector<AttributeWithIndex, 4> AttrList;
80
Bill Wendling831737d2012-12-30 10:32:01 +000081 // AttributesSet is uniqued, these should not be publicly available.
Bill Wendling18e72112012-12-19 22:42:22 +000082 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
83 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
Bill Wendling0976e002012-11-20 05:09:20 +000084public:
Bill Wendling5f93e2b2012-12-19 23:55:43 +000085 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
Bill Wendling60507d52013-01-04 20:54:35 +000086 : Context(C), AttrList(attrs.begin(), attrs.end()) {}
87
88 LLVMContext &getContext() { return Context; }
89 ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; }
90 unsigned getNumAttributes() const { return AttrList.size(); }
Bill Wendling0976e002012-11-20 05:09:20 +000091
92 void Profile(FoldingSetNodeID &ID) const {
Bill Wendling60507d52013-01-04 20:54:35 +000093 Profile(ID, AttrList);
Bill Wendling0976e002012-11-20 05:09:20 +000094 }
Bill Wendling60507d52013-01-04 20:54:35 +000095 static void Profile(FoldingSetNodeID &ID,
96 ArrayRef<AttributeWithIndex> AttrList){
97 for (unsigned i = 0, e = AttrList.size(); i != e; ++i) {
98 ID.AddInteger(AttrList[i].Index);
99 ID.AddInteger(AttrList[i].Attrs.getBitMask());
Bill Wendling0976e002012-11-20 05:09:20 +0000100 }
101 }
102};
103
Bill Wendling2c79ecb2012-09-26 21:07:29 +0000104} // end llvm namespace
105
106#endif