blob: e27a0297dfa017bc2ea9298da1c3d6346ad20264 [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 Carruth802d7552012-12-04 07:12:27 +000020#include "llvm/Attributes.h"
Bill Wendlinge38b8042012-09-26 21:07:29 +000021
22namespace llvm {
23
Bill Wendling6ad6c3b2012-12-19 23:55:43 +000024class LLVMContext;
25
Bill Wendling66e978f2012-12-20 21:28:43 +000026//===----------------------------------------------------------------------===//
27/// \class
28/// \brief This class represents a single, uniqued attribute. That attribute
29/// could be a single enum, a tuple, or a string. It uses a discriminated union
30/// to distinguish them.
Bill Wendling4607f4b2012-12-20 01:36:59 +000031class AttributeImpl : public FoldingSetNode {
Bill Wendling73ea2de2012-10-08 21:47:17 +000032 uint64_t Bits; // FIXME: We will be expanding this.
Bill Wendlinge38b8042012-09-26 21:07:29 +000033public:
Bill Wendling4607f4b2012-12-20 01:36:59 +000034 AttributeImpl(uint64_t bits) : Bits(bits) {}
Bill Wendlinge38b8042012-09-26 21:07:29 +000035
Bill Wendling73ea2de2012-10-08 21:47:17 +000036 bool hasAttribute(uint64_t A) const;
Bill Wendlingc9b22d72012-10-09 07:45:08 +000037
Bill Wendling73ea2de2012-10-08 21:47:17 +000038 bool hasAttributes() const;
Bill Wendling3d7b0b82012-12-19 07:18:57 +000039 bool hasAttributes(const Attribute &A) const;
Bill Wendling73ea2de2012-10-08 21:47:17 +000040
41 uint64_t getAlignment() const;
42 uint64_t getStackAlignment() const;
43
Bill Wendling147ee8e2012-10-16 05:57:28 +000044 uint64_t Raw() const { return Bits; } // FIXME: Remove.
45
Bill Wendling93f70b72012-10-09 09:11:20 +000046 static uint64_t getAttrMask(uint64_t Val);
47
Bill Wendlinge38b8042012-09-26 21:07:29 +000048 void Profile(FoldingSetNodeID &ID) const {
49 Profile(ID, Bits);
50 }
51 static void Profile(FoldingSetNodeID &ID, uint64_t Bits) {
52 ID.AddInteger(Bits);
53 }
54};
55
Bill Wendling66e978f2012-12-20 21:28:43 +000056//===----------------------------------------------------------------------===//
57/// \class
58/// \brief This class represents a set of attributes.
Bill Wendling6848e382012-12-19 22:42:22 +000059class AttributeSetImpl : public FoldingSetNode {
Bill Wendlingf86efb92012-11-20 05:09:20 +000060 // AttributesList is uniqued, these should not be publicly available.
Bill Wendling6848e382012-12-19 22:42:22 +000061 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
62 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
Bill Wendlingf86efb92012-11-20 05:09:20 +000063public:
Bill Wendling6ad6c3b2012-12-19 23:55:43 +000064 LLVMContext &Context;
Bill Wendlingf86efb92012-11-20 05:09:20 +000065 SmallVector<AttributeWithIndex, 4> Attrs;
66
Bill Wendling6ad6c3b2012-12-19 23:55:43 +000067 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
68 : Context(C), Attrs(attrs.begin(), attrs.end()) {}
Bill Wendlingf86efb92012-11-20 05:09:20 +000069
70 void Profile(FoldingSetNodeID &ID) const {
71 Profile(ID, Attrs);
72 }
73 static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
74 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
75 ID.AddInteger(Attrs[i].Attrs.Raw());
76 ID.AddInteger(Attrs[i].Index);
77 }
78 }
79};
80
Bill Wendlinge38b8042012-09-26 21:07:29 +000081} // end llvm namespace
82
83#endif