summaryrefslogtreecommitdiff
path: root/lib/VMCore/Attributes.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-09-26 21:07:29 +0000
committerBill Wendling <isanbard@gmail.com>2012-09-26 21:07:29 +0000
commit2c79ecbd704c656178ffa43d5a58ebe3ca188b40 (patch)
tree2376c791689ec9579a367128480dc08192caa852 /lib/VMCore/Attributes.cpp
parentb500e9249af1e1104c4a599d9eafc37c307172e2 (diff)
downloadllvm-2c79ecbd704c656178ffa43d5a58ebe3ca188b40.tar.gz
llvm-2c79ecbd704c656178ffa43d5a58ebe3ca188b40.tar.bz2
llvm-2c79ecbd704c656178ffa43d5a58ebe3ca188b40.tar.xz
Initial commit for the AttributesImpl class.
This opaque class will contain all of the attributes. All attribute queries will go through this object. This object will also be uniqued in the LLVMContext. Currently not used, so no implementation change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164722 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Attributes.cpp')
-rw-r--r--lib/VMCore/Attributes.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp
index 453190bbaf..7d3197cb0d 100644
--- a/lib/VMCore/Attributes.cpp
+++ b/lib/VMCore/Attributes.cpp
@@ -12,6 +12,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/Attributes.h"
+#include "AttributesImpl.h"
+#include "LLVMContextImpl.h"
#include "llvm/Type.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/FoldingSet.h"
@@ -110,6 +112,36 @@ Attributes Attributes::typeIncompatible(Type *Ty) {
}
//===----------------------------------------------------------------------===//
+// AttributeImpl Definition
+//===----------------------------------------------------------------------===//
+
+Attributes::Attributes(AttributesImpl *A) : Bits(0) {}
+
+Attributes Attributes::get(LLVMContext &Context, Attributes::Builder &B) {
+ // If there are no attributes, return an empty Attributes class.
+ if (B.Bits == 0)
+ return Attributes();
+
+ // Otherwise, build a key to look up the existing attributes.
+ LLVMContextImpl *pImpl = Context.pImpl;
+ FoldingSetNodeID ID;
+ ID.AddInteger(B.Bits);
+
+ void *InsertPoint;
+ AttributesImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
+
+ if (!PA) {
+ // If we didn't find any existing attributes of the same shape then create a
+ // new one and insert it.
+ PA = new AttributesImpl(B.Bits);
+ pImpl->AttrsSet.InsertNode(PA, InsertPoint);
+ }
+
+ // Return the AttributesList that we found or created.
+ return Attributes(PA);
+}
+
+//===----------------------------------------------------------------------===//
// AttributeListImpl Definition
//===----------------------------------------------------------------------===//