diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2014-09-03 23:24:31 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2014-09-03 23:24:31 +0000 |
commit | e1cef6e3beeff51f248651889e257efe7541d13a (patch) | |
tree | 022b60ea39367aaa60b55a6f58f29c46616a0f29 /llvm/lib/IR/Attributes.cpp | |
parent | 3175521844a3625f32ccfd9e20b6a6cc1337f10e (diff) | |
download | llvm-e1cef6e3beeff51f248651889e257efe7541d13a.zip llvm-e1cef6e3beeff51f248651889e257efe7541d13a.tar.gz llvm-e1cef6e3beeff51f248651889e257efe7541d13a.tar.bz2 |
Don't treat 0 as a special value for int attributes.
Split the get() to not use a default value. This way
attributes can be added that have 0 as a legitimate value.
llvm-svn: 217107
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 04545ea..a2f1dd0 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -31,12 +31,31 @@ using namespace llvm; // Attribute Construction Methods //===----------------------------------------------------------------------===// +Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind) { + LLVMContextImpl *pImpl = Context.pImpl; + FoldingSetNodeID ID; + ID.AddInteger(Kind); + + void *InsertPoint; + AttributeImpl *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 EnumAttributeImpl(Kind); + pImpl->AttrsSet.InsertNode(PA, InsertPoint); + } + + // Return the Attribute that we found or created. + return Attribute(PA); +} + Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, uint64_t Val) { LLVMContextImpl *pImpl = Context.pImpl; FoldingSetNodeID ID; ID.AddInteger(Kind); - if (Val) ID.AddInteger(Val); + ID.AddInteger(Val); void *InsertPoint; AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); @@ -44,10 +63,7 @@ Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, if (!PA) { // If we didn't find any existing attributes of the same shape then create a // new one and insert it. - if (!Val) - PA = new EnumAttributeImpl(Kind); - else - PA = new IntAttributeImpl(Kind, Val); + PA = new IntAttributeImpl(Kind, Val); pImpl->AttrsSet.InsertNode(PA, InsertPoint); } |