blob: 65ac3ea98230e7817ba853f06f2d1cb7842d6f78 [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 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
30/// could be a single enum, a tuple, or a string. It uses a discriminated union
31/// to distinguish them.
Bill Wendling4607f4b2012-12-20 01:36:59 +000032class AttributeImpl : public FoldingSetNode {
Bill Wendling0cd0f7f2012-12-29 12:29:38 +000033 Constant *Data;
Bill Wendlinge38b8042012-09-26 21:07:29 +000034public:
Bill Wendling0cd0f7f2012-12-29 12:29:38 +000035 AttributeImpl(LLVMContext &C, uint64_t data);
Bill Wendlinge38b8042012-09-26 21:07:29 +000036
Bill Wendling73ea2de2012-10-08 21:47:17 +000037 bool hasAttribute(uint64_t A) const;
Bill Wendlingc9b22d72012-10-09 07:45:08 +000038
Bill Wendling73ea2de2012-10-08 21:47:17 +000039 bool hasAttributes() const;
Bill Wendling3d7b0b82012-12-19 07:18:57 +000040 bool hasAttributes(const Attribute &A) const;
Bill Wendling73ea2de2012-10-08 21:47:17 +000041
42 uint64_t getAlignment() const;
43 uint64_t getStackAlignment() const;
44
Bill Wendling3e4c4c92012-12-30 01:05:42 +000045 uint64_t getBitMask() const; // FIXME: Remove.
Bill Wendling147ee8e2012-10-16 05:57:28 +000046
Bill Wendling93f70b72012-10-09 09:11:20 +000047 static uint64_t getAttrMask(uint64_t Val);
48
Bill Wendlinge38b8042012-09-26 21:07:29 +000049 void Profile(FoldingSetNodeID &ID) const {
Bill Wendling0cd0f7f2012-12-29 12:29:38 +000050 Profile(ID, Data);
Bill Wendlinge38b8042012-09-26 21:07:29 +000051 }
Bill Wendling5e8ff872012-12-30 01:23:08 +000052 static void Profile(FoldingSetNodeID &ID, Constant *Data) {
53 ID.AddPointer(Data);
54 }
Bill Wendlinge38b8042012-09-26 21:07:29 +000055};
56
Bill Wendling66e978f2012-12-20 21:28:43 +000057//===----------------------------------------------------------------------===//
58/// \class
59/// \brief This class represents a set of attributes.
Bill Wendling6848e382012-12-19 22:42:22 +000060class AttributeSetImpl : public FoldingSetNode {
Bill Wendlingf86efb92012-11-20 05:09:20 +000061 // AttributesList is uniqued, these should not be publicly available.
Bill Wendling6848e382012-12-19 22:42:22 +000062 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
63 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
Bill Wendlingf86efb92012-11-20 05:09:20 +000064public:
Bill Wendling6ad6c3b2012-12-19 23:55:43 +000065 LLVMContext &Context;
Bill Wendlingf86efb92012-11-20 05:09:20 +000066 SmallVector<AttributeWithIndex, 4> Attrs;
67
Bill Wendling6ad6c3b2012-12-19 23:55:43 +000068 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
69 : Context(C), Attrs(attrs.begin(), attrs.end()) {}
Bill Wendlingf86efb92012-11-20 05:09:20 +000070
71 void Profile(FoldingSetNodeID &ID) const {
72 Profile(ID, Attrs);
73 }
74 static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
75 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
Bill Wendling3e4c4c92012-12-30 01:05:42 +000076 ID.AddInteger(Attrs[i].Attrs.getBitMask());
Bill Wendlingf86efb92012-11-20 05:09:20 +000077 ID.AddInteger(Attrs[i].Index);
78 }
79 }
80};
81
Bill Wendlinge38b8042012-09-26 21:07:29 +000082} // end llvm namespace
83
84#endif