AttributeImpl.h revision ff887165bc221c0398c0d4404dc0b22de216dedf
1//===-- AttributeImpl.h - Attribute Internals -------------------*- C++ -*-===// 2// 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//===----------------------------------------------------------------------===// 9/// 10/// \file 11/// \brief This file defines various helper methods and classes used by 12/// LLVMContextImpl for creating and managing attributes. 13/// 14//===----------------------------------------------------------------------===// 15 16#ifndef LLVM_ATTRIBUTESIMPL_H 17#define LLVM_ATTRIBUTESIMPL_H 18 19#include "llvm/ADT/FoldingSet.h" 20#include "llvm/IR/Attributes.h" 21 22namespace llvm { 23 24class Constant; 25class LLVMContext; 26 27//===----------------------------------------------------------------------===// 28/// \class 29/// \brief This class represents a single, uniqued attribute. That attribute 30/// could be a single enum, a tuple, or a string. 31class AttributeImpl : public FoldingSetNode { 32 LLVMContext &Context; 33 Constant *Data; 34 SmallVector<Constant*, 0> Vals; 35public: 36 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 42 ArrayRef<Constant*> getValues() const { return Vals; } 43 44 bool hasAttribute(Attribute::AttrKind A) const; 45 46 bool hasAttributes() const; 47 48 uint64_t getAlignment() const; 49 void setAlignment(unsigned Align); 50 51 uint64_t getStackAlignment() const; 52 void setStackAlignment(unsigned Align); 53 54 bool operator==(Attribute::AttrKind Kind) const; 55 bool operator!=(Attribute::AttrKind Kind) const; 56 57 bool operator==(StringRef Kind) const; 58 bool operator!=(StringRef Kind) const; 59 60 uint64_t getBitMask() const; // FIXME: Remove. 61 62 static uint64_t getAttrMask(Attribute::AttrKind Val); 63 64 void Profile(FoldingSetNodeID &ID) const { 65 Profile(ID, Data, Vals); 66 } 67 static void Profile(FoldingSetNodeID &ID, Constant *Data, 68 ArrayRef<Constant*> Vals); 69}; 70 71//===----------------------------------------------------------------------===// 72/// \class 73/// \brief This class represents a set of attributes. 74class AttributeSetImpl : public FoldingSetNode { 75 LLVMContext &Context; 76 SmallVector<AttributeWithIndex, 4> AttrList; 77 78 // AttributesSet is uniqued, these should not be publicly available. 79 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; 80 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; 81public: 82 AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs) 83 : Context(C), AttrList(attrs.begin(), attrs.end()) {} 84 85 LLVMContext &getContext() { return Context; } 86 ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; } 87 unsigned getNumAttributes() const { return AttrList.size(); } 88 89 void Profile(FoldingSetNodeID &ID) const { 90 Profile(ID, AttrList); 91 } 92 static void Profile(FoldingSetNodeID &ID, 93 ArrayRef<AttributeWithIndex> AttrList){ 94 for (unsigned i = 0, e = AttrList.size(); i != e; ++i) { 95 ID.AddInteger(AttrList[i].Index); 96 ID.AddInteger(AttrList[i].Attrs.getBitMask()); 97 } 98 } 99}; 100 101} // end llvm namespace 102 103#endif 104