blob: 0843fd8ac88dd2b86117c762a5717d4180d1c2f1 [file] [log] [blame]
Bill Wendling4607f4b2012-12-20 01:36:59 +00001//===-- AttributeImpl.h - Attribute Internals -------------------*- C++ -*-===//
Bill Wendlinge38b8042012-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 Wendling66e978f2012-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 Wendlinge38b8042012-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 Carruth9fb823b2013-01-02 11:36:10 +000020#include "llvm/IR/Attributes.h"
Bill Wendlinge38b8042012-09-26 21:07:29 +000021
22namespace llvm {
23
Bill Wendling0cd0f7f2012-12-29 12:29:38 +000024class Constant;
Bill Wendling6ad6c3b2012-12-19 23:55:43 +000025class LLVMContext;
26
Bill Wendling66e978f2012-12-20 21:28:43 +000027//===----------------------------------------------------------------------===//
28/// \class
29/// \brief This class represents a single, uniqued attribute. That attribute
Bill Wendling3a554ac2012-12-30 02:22:16 +000030/// could be a single enum, a tuple, or a string.
Bill Wendling4607f4b2012-12-20 01:36:59 +000031class AttributeImpl : public FoldingSetNode {
Bill Wendling960f52a2013-01-05 01:36:54 +000032 LLVMContext &Context;
Bill Wendling0cd0f7f2012-12-29 12:29:38 +000033 Constant *Data;
Bill Wendling3a554ac2012-12-30 02:22:16 +000034 SmallVector<Constant*, 0> Vals;
Bill Wendlinge38b8042012-09-26 21:07:29 +000035public:
Bill Wendling3a554ac2012-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 Wendlingbd4ea162013-01-21 21:57:28 +000042 LLVMContext &getContext() { return Context; }
43
Bill Wendling096f5442013-01-07 08:24:35 +000044 ArrayRef<Constant*> getValues() const { return Vals; }
Bill Wendlinge38b8042012-09-26 21:07:29 +000045
Bill Wendling9ac69f92013-01-04 20:54:35 +000046 bool hasAttribute(Attribute::AttrKind A) const;
Bill Wendlingc9b22d72012-10-09 07:45:08 +000047
Bill Wendling73ea2de2012-10-08 21:47:17 +000048 bool hasAttributes() const;
Bill Wendling73ea2de2012-10-08 21:47:17 +000049
50 uint64_t getAlignment() const;
51 uint64_t getStackAlignment() const;
52
Bill Wendling9ac69f92013-01-04 20:54:35 +000053 bool operator==(Attribute::AttrKind Kind) const;
54 bool operator!=(Attribute::AttrKind Kind) const;
Bill Wendlingb1d12612012-12-30 01:38:39 +000055
Bill Wendling9ac69f92013-01-04 20:54:35 +000056 bool operator==(StringRef Kind) const;
57 bool operator!=(StringRef Kind) const;
Bill Wendlingb1d12612012-12-30 01:38:39 +000058
Bill Wendling3b651872013-01-09 23:36:50 +000059 uint64_t Raw() const; // FIXME: Remove.
Bill Wendling147ee8e2012-10-16 05:57:28 +000060
Bill Wendling9ac69f92013-01-04 20:54:35 +000061 static uint64_t getAttrMask(Attribute::AttrKind Val);
Bill Wendling93f70b72012-10-09 09:11:20 +000062
Bill Wendlinge38b8042012-09-26 21:07:29 +000063 void Profile(FoldingSetNodeID &ID) const {
Bill Wendling3a554ac2012-12-30 02:22:16 +000064 Profile(ID, Data, Vals);
Bill Wendlinge38b8042012-09-26 21:07:29 +000065 }
Bill Wendling3a554ac2012-12-30 02:22:16 +000066 static void Profile(FoldingSetNodeID &ID, Constant *Data,
Bill Wendling69fa5c02013-01-09 00:32:08 +000067 ArrayRef<Constant*> Vals);
Bill Wendlinge38b8042012-09-26 21:07:29 +000068};
69
Bill Wendling66e978f2012-12-20 21:28:43 +000070//===----------------------------------------------------------------------===//
71/// \class
72/// \brief This class represents a set of attributes.
Bill Wendling6848e382012-12-19 22:42:22 +000073class AttributeSetImpl : public FoldingSetNode {
Bill Wendling9ac69f92013-01-04 20:54:35 +000074 LLVMContext &Context;
75 SmallVector<AttributeWithIndex, 4> AttrList;
76
Bill Wendling698e84f2012-12-30 10:32:01 +000077 // AttributesSet is uniqued, these should not be publicly available.
Bill Wendling6848e382012-12-19 22:42:22 +000078 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
79 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
Bill Wendlingf86efb92012-11-20 05:09:20 +000080public:
Bill Wendling6ad6c3b2012-12-19 23:55:43 +000081 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
Bill Wendling9ac69f92013-01-04 20:54:35 +000082 : Context(C), AttrList(attrs.begin(), attrs.end()) {}
83
84 LLVMContext &getContext() { return Context; }
85 ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; }
86 unsigned getNumAttributes() const { return AttrList.size(); }
Bill Wendlingf86efb92012-11-20 05:09:20 +000087
88 void Profile(FoldingSetNodeID &ID) const {
Bill Wendling9ac69f92013-01-04 20:54:35 +000089 Profile(ID, AttrList);
Bill Wendlingf86efb92012-11-20 05:09:20 +000090 }
Bill Wendling9ac69f92013-01-04 20:54:35 +000091 static void Profile(FoldingSetNodeID &ID,
92 ArrayRef<AttributeWithIndex> AttrList){
93 for (unsigned i = 0, e = AttrList.size(); i != e; ++i) {
94 ID.AddInteger(AttrList[i].Index);
Bill Wendling3b651872013-01-09 23:36:50 +000095 ID.AddInteger(AttrList[i].Attrs.Raw());
Bill Wendlingf86efb92012-11-20 05:09:20 +000096 }
97 }
98};
99
Bill Wendlinge38b8042012-09-26 21:07:29 +0000100} // end llvm namespace
101
102#endif