From 979aff6399a79d155e98bbbe064f4a183a237f23 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sun, 30 Dec 2012 02:22:16 +0000 Subject: [PATCH] Add a few more c'tors: * One that accepts a single Attribute::AttrKind. * One that accepts an Attribute::AttrKind plus a list of values. This is for attributes defined like this: #1 = attributes { align = 4 } * One that accepts a string, for target-specific attributes like this: #2 = attributes { "cpu=cortex-a8" } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171249 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/AttributeImpl.h | 22 +++++++++++++++++----- lib/VMCore/Attributes.cpp | 12 ++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/VMCore/AttributeImpl.h b/lib/VMCore/AttributeImpl.h index 38eef6f16c3..cab1c94255d 100644 --- a/lib/VMCore/AttributeImpl.h +++ b/lib/VMCore/AttributeImpl.h @@ -27,12 +27,20 @@ class LLVMContext; //===----------------------------------------------------------------------===// /// \class /// \brief This class represents a single, uniqued attribute. That attribute -/// could be a single enum, a tuple, or a string. It uses a discriminated union -/// to distinguish them. +/// could be a single enum, a tuple, or a string. class AttributeImpl : public FoldingSetNode { Constant *Data; + SmallVector Vals; public: - AttributeImpl(LLVMContext &C, uint64_t data); + explicit AttributeImpl(LLVMContext &C, uint64_t data); + explicit AttributeImpl(LLVMContext &C, Attribute::AttrKind data); + AttributeImpl(LLVMContext &C, Attribute::AttrKind data, + ArrayRef values); + AttributeImpl(LLVMContext &C, StringRef data); + + ArrayRef getValues() const { + return Vals; + } bool contains(Attribute::AttrKind Kind) const; bool contains(StringRef Kind) const; @@ -64,10 +72,14 @@ public: static uint64_t getAttrMask(uint64_t Val); void Profile(FoldingSetNodeID &ID) const { - Profile(ID, Data); + Profile(ID, Data, Vals); } - static void Profile(FoldingSetNodeID &ID, Constant *Data) { + static void Profile(FoldingSetNodeID &ID, Constant *Data, + ArrayRef Vals) { ID.AddPointer(Data); + for (ArrayRef::iterator I = Vals.begin(), E = Vals.end(); + I != E; ++I) + ID.AddPointer(*I); } }; diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp index 52405f25ae6..0db1eb5ed44 100644 --- a/lib/VMCore/Attributes.cpp +++ b/lib/VMCore/Attributes.cpp @@ -301,6 +301,18 @@ uint64_t AttrBuilder::getStackAlignment() const { AttributeImpl::AttributeImpl(LLVMContext &C, uint64_t data) { Data = ConstantInt::get(Type::getInt64Ty(C), data); } +AttributeImpl::AttributeImpl(LLVMContext &C, Attribute::AttrKind data) { + Data = ConstantInt::get(Type::getInt64Ty(C), data); +} +AttributeImpl::AttributeImpl(LLVMContext &C, Attribute::AttrKind data, + ArrayRef values) { + Data = ConstantInt::get(Type::getInt64Ty(C), data); + Vals.reserve(values.size()); + Vals.append(values.begin(), values.end()); +} +AttributeImpl::AttributeImpl(LLVMContext &C, StringRef data) { + Data = ConstantDataArray::getString(C, data); +} bool AttributeImpl::contains(Attribute::AttrKind Kind) const { if (ConstantInt *CI = dyn_cast(Data))