blob: 3b8f818a17bea240c6c507ae197b8f0bd9e4e049 [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 Carrutha1514e22012-12-04 07:12:27 +000020#include "llvm/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
30/// could be a single enum, a tuple, or a string. It uses a discriminated union
31/// to distinguish them.
Bill Wendlingf6670722012-12-20 01:36:59 +000032class AttributeImpl : public FoldingSetNode {
Bill Wendling7c1683d2012-12-29 12:29:38 +000033 Constant *Data;
Bill Wendling2c79ecb2012-09-26 21:07:29 +000034public:
Bill Wendling7c1683d2012-12-29 12:29:38 +000035 AttributeImpl(LLVMContext &C, uint64_t data);
Bill Wendling2c79ecb2012-09-26 21:07:29 +000036
Bill Wendling8e635db2012-10-08 21:47:17 +000037 bool hasAttribute(uint64_t A) const;
Bill Wendling67658342012-10-09 07:45:08 +000038
Bill Wendling8e635db2012-10-08 21:47:17 +000039 bool hasAttributes() const;
Bill Wendling034b94b2012-12-19 07:18:57 +000040 bool hasAttributes(const Attribute &A) const;
Bill Wendling8e635db2012-10-08 21:47:17 +000041
42 uint64_t getAlignment() const;
43 uint64_t getStackAlignment() const;
44
Bill Wendling7c1683d2012-12-29 12:29:38 +000045 uint64_t Raw() const; // FIXME: Remove.
Bill Wendling925bcb12012-10-16 05:57:28 +000046
Bill Wendling2e879bc2012-10-09 09:11:20 +000047 static uint64_t getAttrMask(uint64_t Val);
48
Bill Wendling2c79ecb2012-09-26 21:07:29 +000049 void Profile(FoldingSetNodeID &ID) const {
Bill Wendling7c1683d2012-12-29 12:29:38 +000050 Profile(ID, Data);
Bill Wendling2c79ecb2012-09-26 21:07:29 +000051 }
Bill Wendling7c1683d2012-12-29 12:29:38 +000052 static void Profile(FoldingSetNodeID &ID, Constant *Data);
Bill Wendling2c79ecb2012-09-26 21:07:29 +000053};
54
Bill Wendling27107f62012-12-20 21:28:43 +000055//===----------------------------------------------------------------------===//
56/// \class
57/// \brief This class represents a set of attributes.
Bill Wendling18e72112012-12-19 22:42:22 +000058class AttributeSetImpl : public FoldingSetNode {
Bill Wendling0976e002012-11-20 05:09:20 +000059 // AttributesList is uniqued, these should not be publicly available.
Bill Wendling18e72112012-12-19 22:42:22 +000060 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
61 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
Bill Wendling0976e002012-11-20 05:09:20 +000062public:
Bill Wendling5f93e2b2012-12-19 23:55:43 +000063 LLVMContext &Context;
Bill Wendling0976e002012-11-20 05:09:20 +000064 SmallVector<AttributeWithIndex, 4> Attrs;
65
Bill Wendling5f93e2b2012-12-19 23:55:43 +000066 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
67 : Context(C), Attrs(attrs.begin(), attrs.end()) {}
Bill Wendling0976e002012-11-20 05:09:20 +000068
69 void Profile(FoldingSetNodeID &ID) const {
70 Profile(ID, Attrs);
71 }
72 static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
73 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
74 ID.AddInteger(Attrs[i].Attrs.Raw());
75 ID.AddInteger(Attrs[i].Index);
76 }
77 }
78};
79
Bill Wendling2c79ecb2012-09-26 21:07:29 +000080} // end llvm namespace
81
82#endif