Bill Wendling | 87e10df | 2013-01-28 21:55:20 +0000 | [diff] [blame] | 1 | //===-- Attributes.cpp - Implement AttributesList -------------------------===// |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 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 | // |
Bill Wendling | 87e10df | 2013-01-28 21:55:20 +0000 | [diff] [blame] | 10 | // \file |
| 11 | // \brief This file implements the Attribute, AttributeImpl, AttrBuilder, |
Bill Wendling | 18e7211 | 2012-12-19 22:42:22 +0000 | [diff] [blame] | 12 | // AttributeSetImpl, and AttributeSet classes. |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Attributes.h" |
Bill Wendling | f667072 | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 17 | #include "AttributeImpl.h" |
Bill Wendling | 2c79ecb | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 18 | #include "LLVMContextImpl.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringExtras.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Type.h" |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Atomic.h" |
David Greene | ef1894e | 2010-01-05 01:29:58 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Debug.h" |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ManagedStatic.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Mutex.h" |
Benjamin Kramer | cfa6ec9 | 2009-08-23 11:37:21 +0000 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Bill Wendling | 3467e30 | 2013-01-24 00:06:56 +0000 | [diff] [blame] | 26 | #include <algorithm> |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 27 | using namespace llvm; |
| 28 | |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 29 | //===----------------------------------------------------------------------===// |
Bill Wendling | 817abdd | 2013-01-29 00:48:16 +0000 | [diff] [blame] | 30 | // Attribute Construction Methods |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 31 | //===----------------------------------------------------------------------===// |
Chris Lattner | fabfde3 | 2008-01-03 00:10:22 +0000 | [diff] [blame] | 32 | |
Bill Wendling | b96129d | 2013-01-31 01:04:51 +0000 | [diff] [blame] | 33 | Attribute Attribute::get(LLVMContext &Context, AttrKind Kind) { |
| 34 | AttrBuilder B; |
| 35 | return Attribute::get(Context, B.addAttribute(Kind)); |
| 36 | } |
| 37 | |
| 38 | Attribute Attribute::get(LLVMContext &Context, AttrBuilder &B) { |
| 39 | // If there are no attributes, return an empty Attribute class. |
| 40 | if (!B.hasAttributes()) |
| 41 | return Attribute(); |
| 42 | |
| 43 | assert(std::distance(B.begin(), B.end()) == 1 && |
| 44 | "The Attribute object should represent one attribute only!"); |
Bill Wendling | 73dee18 | 2013-01-31 00:29:54 +0000 | [diff] [blame] | 45 | |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 46 | // Otherwise, build a key to look up the existing attributes. |
| 47 | LLVMContextImpl *pImpl = Context.pImpl; |
| 48 | FoldingSetNodeID ID; |
Bill Wendling | b96129d | 2013-01-31 01:04:51 +0000 | [diff] [blame] | 49 | ConstantInt *CI = ConstantInt::get(Type::getInt64Ty(Context), B.Raw()); |
| 50 | ID.AddPointer(CI); |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 51 | |
| 52 | void *InsertPoint; |
Bill Wendling | f667072 | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 53 | AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 54 | |
| 55 | if (!PA) { |
| 56 | // If we didn't find any existing attributes of the same shape then create a |
| 57 | // new one and insert it. |
Bill Wendling | b96129d | 2013-01-31 01:04:51 +0000 | [diff] [blame] | 58 | PA = new AttributeImpl(Context, CI); |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 59 | pImpl->AttrsSet.InsertNode(PA, InsertPoint); |
| 60 | } |
| 61 | |
| 62 | // Return the AttributesList that we found or created. |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 63 | return Attribute(PA); |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Bill Wendling | c08a5ef | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 66 | Attribute Attribute::getWithAlignment(LLVMContext &Context, uint64_t Align) { |
Bill Wendling | b96129d | 2013-01-31 01:04:51 +0000 | [diff] [blame] | 67 | AttrBuilder B; |
| 68 | return get(Context, B.addAlignmentAttr(Align)); |
Bill Wendling | c08a5ef | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | Attribute Attribute::getWithStackAlignment(LLVMContext &Context, |
| 72 | uint64_t Align) { |
Bill Wendling | b96129d | 2013-01-31 01:04:51 +0000 | [diff] [blame] | 73 | AttrBuilder B; |
| 74 | return get(Context, B.addStackAlignmentAttr(Align)); |
Bill Wendling | c08a5ef | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Bill Wendling | 817abdd | 2013-01-29 00:48:16 +0000 | [diff] [blame] | 77 | //===----------------------------------------------------------------------===// |
| 78 | // Attribute Accessor Methods |
| 79 | //===----------------------------------------------------------------------===// |
| 80 | |
Bill Wendling | 629fb82 | 2012-12-22 00:37:52 +0000 | [diff] [blame] | 81 | bool Attribute::hasAttribute(AttrKind Val) const { |
Bill Wendling | 27107f6 | 2012-12-20 21:28:43 +0000 | [diff] [blame] | 82 | return pImpl && pImpl->hasAttribute(Val); |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Bill Wendling | 6dc3781 | 2013-01-29 20:45:34 +0000 | [diff] [blame] | 85 | Constant *Attribute::getAttributeKind() const { |
| 86 | return pImpl ? pImpl->getAttributeKind() : 0; |
| 87 | } |
| 88 | |
| 89 | ArrayRef<Constant*> Attribute::getAttributeValues() const { |
| 90 | return pImpl ? pImpl->getAttributeValues() : ArrayRef<Constant*>(); |
| 91 | } |
| 92 | |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 93 | /// This returns the alignment field of an attribute as a byte alignment value. |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 94 | unsigned Attribute::getAlignment() const { |
| 95 | if (!hasAttribute(Attribute::Alignment)) |
Bill Wendling | 9ef99c9 | 2012-10-09 20:56:48 +0000 | [diff] [blame] | 96 | return 0; |
Bill Wendling | a8ab5fc | 2013-01-23 23:00:05 +0000 | [diff] [blame] | 97 | return pImpl->getAlignment(); |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /// This returns the stack alignment field of an attribute as a byte alignment |
| 101 | /// value. |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 102 | unsigned Attribute::getStackAlignment() const { |
| 103 | if (!hasAttribute(Attribute::StackAlignment)) |
Bill Wendling | 9ef99c9 | 2012-10-09 20:56:48 +0000 | [diff] [blame] | 104 | return 0; |
Bill Wendling | a8ab5fc | 2013-01-23 23:00:05 +0000 | [diff] [blame] | 105 | return pImpl->getStackAlignment(); |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 108 | std::string Attribute::getAsString() const { |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 109 | if (hasAttribute(Attribute::ZExt)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 110 | return "zeroext"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 111 | if (hasAttribute(Attribute::SExt)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 112 | return "signext"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 113 | if (hasAttribute(Attribute::NoReturn)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 114 | return "noreturn"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 115 | if (hasAttribute(Attribute::NoUnwind)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 116 | return "nounwind"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 117 | if (hasAttribute(Attribute::UWTable)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 118 | return "uwtable"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 119 | if (hasAttribute(Attribute::ReturnsTwice)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 120 | return "returns_twice"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 121 | if (hasAttribute(Attribute::InReg)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 122 | return "inreg"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 123 | if (hasAttribute(Attribute::NoAlias)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 124 | return "noalias"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 125 | if (hasAttribute(Attribute::NoCapture)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 126 | return "nocapture"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 127 | if (hasAttribute(Attribute::StructRet)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 128 | return "sret"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 129 | if (hasAttribute(Attribute::ByVal)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 130 | return "byval"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 131 | if (hasAttribute(Attribute::Nest)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 132 | return "nest"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 133 | if (hasAttribute(Attribute::ReadNone)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 134 | return "readnone"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 135 | if (hasAttribute(Attribute::ReadOnly)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 136 | return "readonly"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 137 | if (hasAttribute(Attribute::OptimizeForSize)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 138 | return "optsize"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 139 | if (hasAttribute(Attribute::NoInline)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 140 | return "noinline"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 141 | if (hasAttribute(Attribute::InlineHint)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 142 | return "inlinehint"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 143 | if (hasAttribute(Attribute::AlwaysInline)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 144 | return "alwaysinline"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 145 | if (hasAttribute(Attribute::StackProtect)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 146 | return "ssp"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 147 | if (hasAttribute(Attribute::StackProtectReq)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 148 | return "sspreq"; |
Bill Wendling | 114baee | 2013-01-23 06:41:41 +0000 | [diff] [blame] | 149 | if (hasAttribute(Attribute::StackProtectStrong)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 150 | return "sspstrong"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 151 | if (hasAttribute(Attribute::NoRedZone)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 152 | return "noredzone"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 153 | if (hasAttribute(Attribute::NoImplicitFloat)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 154 | return "noimplicitfloat"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 155 | if (hasAttribute(Attribute::Naked)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 156 | return "naked"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 157 | if (hasAttribute(Attribute::NonLazyBind)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 158 | return "nonlazybind"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 159 | if (hasAttribute(Attribute::AddressSafety)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 160 | return "address_safety"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 161 | if (hasAttribute(Attribute::MinSize)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 162 | return "minsize"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 163 | if (hasAttribute(Attribute::StackAlignment)) { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 164 | std::string Result; |
Charles Davis | 1e063d1 | 2010-02-12 00:31:15 +0000 | [diff] [blame] | 165 | Result += "alignstack("; |
Bill Wendling | ef99fe8 | 2012-09-21 15:26:31 +0000 | [diff] [blame] | 166 | Result += utostr(getStackAlignment()); |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 167 | Result += ")"; |
| 168 | return Result; |
Charles Davis | 1e063d1 | 2010-02-12 00:31:15 +0000 | [diff] [blame] | 169 | } |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 170 | if (hasAttribute(Attribute::Alignment)) { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 171 | std::string Result; |
Dale Johannesen | 6167c3f | 2008-02-19 23:51:49 +0000 | [diff] [blame] | 172 | Result += "align "; |
Bill Wendling | ef99fe8 | 2012-09-21 15:26:31 +0000 | [diff] [blame] | 173 | Result += utostr(getAlignment()); |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 174 | Result += ""; |
| 175 | return Result; |
Dale Johannesen | 6167c3f | 2008-02-19 23:51:49 +0000 | [diff] [blame] | 176 | } |
James Molloy | 67ae135 | 2012-12-20 16:04:27 +0000 | [diff] [blame] | 177 | if (hasAttribute(Attribute::NoDuplicate)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 178 | return "noduplicate"; |
| 179 | |
| 180 | llvm_unreachable("Unknown attribute"); |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 183 | bool Attribute::operator==(AttrKind K) const { |
NAKAMURA Takumi | eddab15 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 184 | return pImpl && *pImpl == K; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 185 | } |
| 186 | bool Attribute::operator!=(AttrKind K) const { |
| 187 | return !(*this == K); |
| 188 | } |
| 189 | |
| 190 | bool Attribute::operator<(Attribute A) const { |
| 191 | if (!pImpl && !A.pImpl) return false; |
| 192 | if (!pImpl) return true; |
| 193 | if (!A.pImpl) return false; |
| 194 | return *pImpl < *A.pImpl; |
| 195 | } |
| 196 | |
| 197 | uint64_t Attribute::Raw() const { |
| 198 | return pImpl ? pImpl->Raw() : 0; |
| 199 | } |
| 200 | |
| 201 | //===----------------------------------------------------------------------===// |
| 202 | // AttributeImpl Definition |
| 203 | //===----------------------------------------------------------------------===// |
| 204 | |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 205 | AttributeImpl::AttributeImpl(LLVMContext &C, Attribute::AttrKind kind) |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 206 | : Context(C) { |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 207 | Kind = ConstantInt::get(Type::getInt64Ty(C), kind); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 208 | } |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 209 | AttributeImpl::AttributeImpl(LLVMContext &C, Attribute::AttrKind kind, |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 210 | ArrayRef<Constant*> values) |
| 211 | : Context(C) { |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 212 | Kind = ConstantInt::get(Type::getInt64Ty(C), kind); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 213 | Vals.reserve(values.size()); |
| 214 | Vals.append(values.begin(), values.end()); |
| 215 | } |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 216 | AttributeImpl::AttributeImpl(LLVMContext &C, StringRef kind) |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 217 | : Context(C) { |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 218 | Kind = ConstantDataArray::getString(C, kind); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const { |
| 222 | return (Raw() & getAttrMask(A)) != 0; |
| 223 | } |
| 224 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 225 | uint64_t AttributeImpl::getAlignment() const { |
| 226 | uint64_t Mask = Raw() & getAttrMask(Attribute::Alignment); |
| 227 | return 1ULL << ((Mask >> 16) - 1); |
| 228 | } |
| 229 | |
| 230 | uint64_t AttributeImpl::getStackAlignment() const { |
| 231 | uint64_t Mask = Raw() & getAttrMask(Attribute::StackAlignment); |
| 232 | return 1ULL << ((Mask >> 26) - 1); |
| 233 | } |
| 234 | |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 235 | bool AttributeImpl::operator==(Attribute::AttrKind kind) const { |
| 236 | if (ConstantInt *CI = dyn_cast<ConstantInt>(Kind)) |
| 237 | return CI->getZExtValue() == kind; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 238 | return false; |
| 239 | } |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 240 | bool AttributeImpl::operator!=(Attribute::AttrKind kind) const { |
| 241 | return !(*this == kind); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 244 | bool AttributeImpl::operator==(StringRef kind) const { |
| 245 | if (ConstantDataArray *CDA = dyn_cast<ConstantDataArray>(Kind)) |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 246 | if (CDA->isString()) |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 247 | return CDA->getAsString() == kind; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 248 | return false; |
| 249 | } |
| 250 | |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 251 | bool AttributeImpl::operator!=(StringRef kind) const { |
| 252 | return !(*this == kind); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | bool AttributeImpl::operator<(const AttributeImpl &AI) const { |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 256 | if (!Kind && !AI.Kind) return false; |
| 257 | if (!Kind && AI.Kind) return true; |
| 258 | if (Kind && !AI.Kind) return false; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 259 | |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 260 | ConstantInt *ThisCI = dyn_cast<ConstantInt>(Kind); |
| 261 | ConstantInt *ThatCI = dyn_cast<ConstantInt>(AI.Kind); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 262 | |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 263 | ConstantDataArray *ThisCDA = dyn_cast<ConstantDataArray>(Kind); |
| 264 | ConstantDataArray *ThatCDA = dyn_cast<ConstantDataArray>(AI.Kind); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 265 | |
| 266 | if (ThisCI && ThatCI) |
| 267 | return ThisCI->getZExtValue() < ThatCI->getZExtValue(); |
| 268 | |
| 269 | if (ThisCI && ThatCDA) |
| 270 | return true; |
| 271 | |
| 272 | if (ThisCDA && ThatCI) |
| 273 | return false; |
| 274 | |
| 275 | return ThisCDA->getAsString() < ThatCDA->getAsString(); |
| 276 | } |
| 277 | |
| 278 | uint64_t AttributeImpl::Raw() const { |
| 279 | // FIXME: Remove this. |
Bill Wendling | 9f175f8 | 2013-01-29 20:37:10 +0000 | [diff] [blame] | 280 | return cast<ConstantInt>(Kind)->getZExtValue(); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) { |
| 284 | // FIXME: Remove this. |
| 285 | switch (Val) { |
| 286 | case Attribute::EndAttrKinds: |
| 287 | case Attribute::AttrKindEmptyKey: |
| 288 | case Attribute::AttrKindTombstoneKey: |
| 289 | llvm_unreachable("Synthetic enumerators which should never get here"); |
| 290 | |
| 291 | case Attribute::None: return 0; |
| 292 | case Attribute::ZExt: return 1 << 0; |
| 293 | case Attribute::SExt: return 1 << 1; |
| 294 | case Attribute::NoReturn: return 1 << 2; |
| 295 | case Attribute::InReg: return 1 << 3; |
| 296 | case Attribute::StructRet: return 1 << 4; |
| 297 | case Attribute::NoUnwind: return 1 << 5; |
| 298 | case Attribute::NoAlias: return 1 << 6; |
| 299 | case Attribute::ByVal: return 1 << 7; |
| 300 | case Attribute::Nest: return 1 << 8; |
| 301 | case Attribute::ReadNone: return 1 << 9; |
| 302 | case Attribute::ReadOnly: return 1 << 10; |
| 303 | case Attribute::NoInline: return 1 << 11; |
| 304 | case Attribute::AlwaysInline: return 1 << 12; |
| 305 | case Attribute::OptimizeForSize: return 1 << 13; |
| 306 | case Attribute::StackProtect: return 1 << 14; |
| 307 | case Attribute::StackProtectReq: return 1 << 15; |
| 308 | case Attribute::Alignment: return 31 << 16; |
| 309 | case Attribute::NoCapture: return 1 << 21; |
| 310 | case Attribute::NoRedZone: return 1 << 22; |
| 311 | case Attribute::NoImplicitFloat: return 1 << 23; |
| 312 | case Attribute::Naked: return 1 << 24; |
| 313 | case Attribute::InlineHint: return 1 << 25; |
| 314 | case Attribute::StackAlignment: return 7 << 26; |
| 315 | case Attribute::ReturnsTwice: return 1 << 29; |
| 316 | case Attribute::UWTable: return 1 << 30; |
| 317 | case Attribute::NonLazyBind: return 1U << 31; |
| 318 | case Attribute::AddressSafety: return 1ULL << 32; |
| 319 | case Attribute::MinSize: return 1ULL << 33; |
| 320 | case Attribute::NoDuplicate: return 1ULL << 34; |
| 321 | case Attribute::StackProtectStrong: return 1ULL << 35; |
| 322 | } |
| 323 | llvm_unreachable("Unsupported attribute type"); |
| 324 | } |
| 325 | |
| 326 | //===----------------------------------------------------------------------===// |
| 327 | // AttributeSetNode Definition |
| 328 | //===----------------------------------------------------------------------===// |
| 329 | |
| 330 | AttributeSetNode *AttributeSetNode::get(LLVMContext &C, |
| 331 | ArrayRef<Attribute> Attrs) { |
| 332 | if (Attrs.empty()) |
| 333 | return 0; |
| 334 | |
| 335 | // Otherwise, build a key to look up the existing attributes. |
| 336 | LLVMContextImpl *pImpl = C.pImpl; |
| 337 | FoldingSetNodeID ID; |
| 338 | |
| 339 | SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end()); |
| 340 | std::sort(SortedAttrs.begin(), SortedAttrs.end()); |
| 341 | |
| 342 | for (SmallVectorImpl<Attribute>::iterator I = SortedAttrs.begin(), |
| 343 | E = SortedAttrs.end(); I != E; ++I) |
| 344 | I->Profile(ID); |
| 345 | |
| 346 | void *InsertPoint; |
| 347 | AttributeSetNode *PA = |
| 348 | pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint); |
| 349 | |
| 350 | // If we didn't find any existing attributes of the same shape then create a |
| 351 | // new one and insert it. |
| 352 | if (!PA) { |
| 353 | PA = new AttributeSetNode(SortedAttrs); |
| 354 | pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint); |
| 355 | } |
| 356 | |
| 357 | // Return the AttributesListNode that we found or created. |
| 358 | return PA; |
| 359 | } |
| 360 | |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 361 | bool AttributeSetNode::hasAttribute(Attribute::AttrKind Kind) const { |
| 362 | for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(), |
| 363 | E = AttrList.end(); I != E; ++I) |
NAKAMURA Takumi | eddab15 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 364 | if (I->hasAttribute(Kind)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 365 | return true; |
| 366 | return false; |
| 367 | } |
| 368 | |
| 369 | unsigned AttributeSetNode::getAlignment() const { |
| 370 | for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(), |
| 371 | E = AttrList.end(); I != E; ++I) |
NAKAMURA Takumi | eddab15 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 372 | if (I->hasAttribute(Attribute::Alignment)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 373 | return I->getAlignment(); |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | unsigned AttributeSetNode::getStackAlignment() const { |
| 378 | for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(), |
| 379 | E = AttrList.end(); I != E; ++I) |
NAKAMURA Takumi | eddab15 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 380 | if (I->hasAttribute(Attribute::StackAlignment)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 381 | return I->getStackAlignment(); |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | std::string AttributeSetNode::getAsString() const { |
| 386 | std::string Str = ""; |
| 387 | for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(), |
| 388 | E = AttrList.end(); I != E; ++I) { |
| 389 | if (I != AttrList.begin()) Str += " "; |
| 390 | Str += I->getAsString(); |
| 391 | } |
| 392 | return Str; |
| 393 | } |
| 394 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 395 | //===----------------------------------------------------------------------===// |
| 396 | // AttributeSetImpl Definition |
| 397 | //===----------------------------------------------------------------------===// |
| 398 | |
| 399 | uint64_t AttributeSetImpl::Raw(uint64_t Index) const { |
| 400 | for (unsigned I = 0, E = getNumAttributes(); I != E; ++I) { |
| 401 | if (getSlotIndex(I) != Index) continue; |
| 402 | const AttributeSetNode *ASN = AttrNodes[I].second; |
| 403 | AttrBuilder B; |
| 404 | |
| 405 | for (AttributeSetNode::const_iterator II = ASN->begin(), |
| 406 | IE = ASN->end(); II != IE; ++II) |
| 407 | B.addAttributes(*II); |
| 408 | return B.Raw(); |
| 409 | } |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | //===----------------------------------------------------------------------===// |
| 415 | // AttributeSet Construction and Mutation Methods |
| 416 | //===----------------------------------------------------------------------===// |
| 417 | |
Bill Wendling | 8232ece | 2013-01-29 01:43:29 +0000 | [diff] [blame] | 418 | AttributeSet |
| 419 | AttributeSet::getImpl(LLVMContext &C, |
| 420 | ArrayRef<std::pair<unsigned, AttributeSetNode*> > Attrs) { |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 421 | LLVMContextImpl *pImpl = C.pImpl; |
| 422 | FoldingSetNodeID ID; |
| 423 | AttributeSetImpl::Profile(ID, Attrs); |
| 424 | |
| 425 | void *InsertPoint; |
| 426 | AttributeSetImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint); |
| 427 | |
| 428 | // If we didn't find any existing attributes of the same shape then |
| 429 | // create a new one and insert it. |
| 430 | if (!PA) { |
| 431 | PA = new AttributeSetImpl(C, Attrs); |
| 432 | pImpl->AttrsLists.InsertNode(PA, InsertPoint); |
| 433 | } |
| 434 | |
| 435 | // Return the AttributesList that we found or created. |
| 436 | return AttributeSet(PA); |
| 437 | } |
| 438 | |
| 439 | AttributeSet AttributeSet::get(LLVMContext &C, |
| 440 | ArrayRef<std::pair<unsigned, Attribute> > Attrs){ |
| 441 | // If there are no attributes then return a null AttributesList pointer. |
| 442 | if (Attrs.empty()) |
| 443 | return AttributeSet(); |
| 444 | |
| 445 | #ifndef NDEBUG |
| 446 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { |
| 447 | assert((!i || Attrs[i-1].first <= Attrs[i].first) && |
| 448 | "Misordered Attributes list!"); |
Bill Wendling | 82aea64 | 2013-01-31 06:22:35 +0000 | [diff] [blame] | 449 | assert(Attrs[i].second != Attribute::None && |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 450 | "Pointless attribute!"); |
| 451 | } |
| 452 | #endif |
| 453 | |
| 454 | // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes |
| 455 | // list. |
| 456 | SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrPairVec; |
| 457 | for (ArrayRef<std::pair<unsigned, Attribute> >::iterator I = Attrs.begin(), |
| 458 | E = Attrs.end(); I != E; ) { |
| 459 | unsigned Index = I->first; |
| 460 | SmallVector<Attribute, 4> AttrVec; |
NAKAMURA Takumi | 3ba51ce | 2013-01-29 15:18:16 +0000 | [diff] [blame] | 461 | while (I != E && I->first == Index) { |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 462 | AttrVec.push_back(I->second); |
| 463 | ++I; |
| 464 | } |
| 465 | |
| 466 | AttrPairVec.push_back(std::make_pair(Index, |
| 467 | AttributeSetNode::get(C, AttrVec))); |
| 468 | } |
| 469 | |
| 470 | return getImpl(C, AttrPairVec); |
| 471 | } |
| 472 | |
| 473 | AttributeSet AttributeSet::get(LLVMContext &C, |
| 474 | ArrayRef<std::pair<unsigned, |
| 475 | AttributeSetNode*> > Attrs) { |
| 476 | // If there are no attributes then return a null AttributesList pointer. |
| 477 | if (Attrs.empty()) |
| 478 | return AttributeSet(); |
| 479 | |
| 480 | return getImpl(C, Attrs); |
| 481 | } |
| 482 | |
| 483 | AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx, AttrBuilder &B) { |
| 484 | if (!B.hasAttributes()) |
| 485 | return AttributeSet(); |
Bill Wendling | 8fbc0c2 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 486 | |
| 487 | SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; |
| 488 | for (AttrBuilder::iterator I = B.begin(), E = B.end(); I != E; ++I) { |
| 489 | Attribute::AttrKind Kind = *I; |
| 490 | if (Kind == Attribute::Alignment) |
| 491 | Attrs.push_back(std::make_pair(Idx, Attribute:: |
| 492 | getWithAlignment(C, B.getAlignment()))); |
| 493 | else if (Kind == Attribute::StackAlignment) |
| 494 | Attrs.push_back(std::make_pair(Idx, Attribute:: |
| 495 | getWithStackAlignment(C, B.getStackAlignment()))); |
| 496 | else |
| 497 | Attrs.push_back(std::make_pair(Idx, Attribute::get(C, Kind))); |
| 498 | } |
| 499 | |
| 500 | return get(C, Attrs); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx, |
| 504 | ArrayRef<Attribute::AttrKind> Kind) { |
| 505 | SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; |
| 506 | for (ArrayRef<Attribute::AttrKind>::iterator I = Kind.begin(), |
| 507 | E = Kind.end(); I != E; ++I) |
| 508 | Attrs.push_back(std::make_pair(Idx, Attribute::get(C, *I))); |
| 509 | return get(C, Attrs); |
| 510 | } |
| 511 | |
| 512 | AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) { |
| 513 | if (Attrs.empty()) return AttributeSet(); |
| 514 | |
| 515 | SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrNodeVec; |
| 516 | for (unsigned I = 0, E = Attrs.size(); I != E; ++I) { |
| 517 | AttributeSet AS = Attrs[I]; |
| 518 | if (!AS.pImpl) continue; |
| 519 | AttrNodeVec.append(AS.pImpl->AttrNodes.begin(), AS.pImpl->AttrNodes.end()); |
| 520 | } |
| 521 | |
| 522 | return getImpl(C, AttrNodeVec); |
| 523 | } |
| 524 | |
| 525 | AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Idx, |
| 526 | Attribute::AttrKind Attr) const { |
| 527 | return addAttributes(C, Idx, AttributeSet::get(C, Idx, Attr)); |
| 528 | } |
| 529 | |
| 530 | AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Idx, |
| 531 | AttributeSet Attrs) const { |
| 532 | if (!pImpl) return Attrs; |
| 533 | if (!Attrs.pImpl) return *this; |
| 534 | |
| 535 | #ifndef NDEBUG |
| 536 | // FIXME it is not obvious how this should work for alignment. For now, say |
| 537 | // we can't change a known alignment. |
| 538 | unsigned OldAlign = getParamAlignment(Idx); |
| 539 | unsigned NewAlign = Attrs.getParamAlignment(Idx); |
| 540 | assert((!OldAlign || !NewAlign || OldAlign == NewAlign) && |
| 541 | "Attempt to change alignment!"); |
| 542 | #endif |
| 543 | |
| 544 | // Add the attribute slots before the one we're trying to add. |
| 545 | SmallVector<AttributeSet, 4> AttrSet; |
| 546 | uint64_t NumAttrs = pImpl->getNumAttributes(); |
| 547 | AttributeSet AS; |
| 548 | uint64_t LastIndex = 0; |
| 549 | for (unsigned I = 0, E = NumAttrs; I != E; ++I) { |
| 550 | if (getSlotIndex(I) >= Idx) { |
| 551 | if (getSlotIndex(I) == Idx) AS = getSlotAttributes(LastIndex++); |
| 552 | break; |
| 553 | } |
| 554 | LastIndex = I + 1; |
| 555 | AttrSet.push_back(getSlotAttributes(I)); |
| 556 | } |
| 557 | |
| 558 | // Now add the attribute into the correct slot. There may already be an |
| 559 | // AttributeSet there. |
| 560 | AttrBuilder B(AS, Idx); |
| 561 | |
| 562 | for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I) |
| 563 | if (Attrs.getSlotIndex(I) == Idx) { |
| 564 | for (AttributeSetImpl::const_iterator II = Attrs.pImpl->begin(I), |
| 565 | IE = Attrs.pImpl->end(I); II != IE; ++II) |
| 566 | B.addAttributes(*II); |
| 567 | break; |
| 568 | } |
| 569 | |
| 570 | AttrSet.push_back(AttributeSet::get(C, Idx, B)); |
| 571 | |
| 572 | // Add the remaining attribute slots. |
| 573 | for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I) |
| 574 | AttrSet.push_back(getSlotAttributes(I)); |
| 575 | |
| 576 | return get(C, AttrSet); |
| 577 | } |
| 578 | |
| 579 | AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Idx, |
| 580 | Attribute::AttrKind Attr) const { |
| 581 | return removeAttributes(C, Idx, AttributeSet::get(C, Idx, Attr)); |
| 582 | } |
| 583 | |
| 584 | AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Idx, |
| 585 | AttributeSet Attrs) const { |
| 586 | if (!pImpl) return AttributeSet(); |
| 587 | if (!Attrs.pImpl) return *this; |
| 588 | |
| 589 | #ifndef NDEBUG |
| 590 | // FIXME it is not obvious how this should work for alignment. |
| 591 | // For now, say we can't pass in alignment, which no current use does. |
| 592 | assert(!Attrs.hasAttribute(Idx, Attribute::Alignment) && |
| 593 | "Attempt to change alignment!"); |
| 594 | #endif |
| 595 | |
| 596 | // Add the attribute slots before the one we're trying to add. |
| 597 | SmallVector<AttributeSet, 4> AttrSet; |
| 598 | uint64_t NumAttrs = pImpl->getNumAttributes(); |
| 599 | AttributeSet AS; |
| 600 | uint64_t LastIndex = 0; |
| 601 | for (unsigned I = 0, E = NumAttrs; I != E; ++I) { |
| 602 | if (getSlotIndex(I) >= Idx) { |
| 603 | if (getSlotIndex(I) == Idx) AS = getSlotAttributes(LastIndex++); |
| 604 | break; |
| 605 | } |
| 606 | LastIndex = I + 1; |
| 607 | AttrSet.push_back(getSlotAttributes(I)); |
| 608 | } |
| 609 | |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 610 | // Now remove the attribute from the correct slot. There may already be an |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 611 | // AttributeSet there. |
| 612 | AttrBuilder B(AS, Idx); |
| 613 | |
| 614 | for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I) |
| 615 | if (Attrs.getSlotIndex(I) == Idx) { |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 616 | B.removeAttributes(Attrs.pImpl->getSlotAttributes(I), Idx); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 617 | break; |
| 618 | } |
| 619 | |
| 620 | AttrSet.push_back(AttributeSet::get(C, Idx, B)); |
| 621 | |
| 622 | // Add the remaining attribute slots. |
| 623 | for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I) |
| 624 | AttrSet.push_back(getSlotAttributes(I)); |
| 625 | |
| 626 | return get(C, AttrSet); |
| 627 | } |
| 628 | |
| 629 | //===----------------------------------------------------------------------===// |
| 630 | // AttributeSet Accessor Methods |
| 631 | //===----------------------------------------------------------------------===// |
| 632 | |
| 633 | AttributeSet AttributeSet::getParamAttributes(unsigned Idx) const { |
| 634 | return pImpl && hasAttributes(Idx) ? |
| 635 | AttributeSet::get(pImpl->getContext(), |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 636 | ArrayRef<std::pair<unsigned, AttributeSetNode*> >( |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 637 | std::make_pair(Idx, getAttributes(Idx)))) : |
| 638 | AttributeSet(); |
| 639 | } |
| 640 | |
| 641 | AttributeSet AttributeSet::getRetAttributes() const { |
| 642 | return pImpl && hasAttributes(ReturnIndex) ? |
| 643 | AttributeSet::get(pImpl->getContext(), |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 644 | ArrayRef<std::pair<unsigned, AttributeSetNode*> >( |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 645 | std::make_pair(ReturnIndex, |
| 646 | getAttributes(ReturnIndex)))) : |
| 647 | AttributeSet(); |
| 648 | } |
| 649 | |
| 650 | AttributeSet AttributeSet::getFnAttributes() const { |
| 651 | return pImpl && hasAttributes(FunctionIndex) ? |
| 652 | AttributeSet::get(pImpl->getContext(), |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 653 | ArrayRef<std::pair<unsigned, AttributeSetNode*> >( |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 654 | std::make_pair(FunctionIndex, |
| 655 | getAttributes(FunctionIndex)))) : |
| 656 | AttributeSet(); |
| 657 | } |
| 658 | |
| 659 | bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{ |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 660 | AttributeSetNode *ASN = getAttributes(Index); |
| 661 | return ASN ? ASN->hasAttribute(Kind) : false; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | bool AttributeSet::hasAttributes(unsigned Index) const { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 665 | AttributeSetNode *ASN = getAttributes(Index); |
| 666 | return ASN ? ASN->hasAttributes() : false; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | /// \brief Return true if the specified attribute is set for at least one |
| 670 | /// parameter or for the return value. |
| 671 | bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const { |
| 672 | if (pImpl == 0) return false; |
| 673 | |
| 674 | for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) |
| 675 | for (AttributeSetImpl::const_iterator II = pImpl->begin(I), |
| 676 | IE = pImpl->end(I); II != IE; ++II) |
NAKAMURA Takumi | eddab15 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 677 | if (II->hasAttribute(Attr)) |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 678 | return true; |
| 679 | |
| 680 | return false; |
| 681 | } |
| 682 | |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 683 | unsigned AttributeSet::getParamAlignment(unsigned Index) const { |
| 684 | AttributeSetNode *ASN = getAttributes(Index); |
| 685 | return ASN ? ASN->getAlignment() : 0; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | unsigned AttributeSet::getStackAlignment(unsigned Index) const { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 689 | AttributeSetNode *ASN = getAttributes(Index); |
| 690 | return ASN ? ASN->getStackAlignment() : 0; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | std::string AttributeSet::getAsString(unsigned Index) const { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 694 | AttributeSetNode *ASN = getAttributes(Index); |
| 695 | return ASN ? ASN->getAsString() : std::string(""); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | /// \brief The attributes for the specified index are returned. |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 699 | AttributeSetNode *AttributeSet::getAttributes(unsigned Idx) const { |
| 700 | if (!pImpl) return 0; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 701 | |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 702 | // Loop through to find the attribute node we want. |
| 703 | for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) |
| 704 | if (pImpl->getSlotIndex(I) == Idx) |
| 705 | return pImpl->getSlotNode(I); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 706 | |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 707 | return 0; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | //===----------------------------------------------------------------------===// |
| 711 | // AttributeSet Introspection Methods |
| 712 | //===----------------------------------------------------------------------===// |
| 713 | |
| 714 | /// \brief Return the number of slots used in this attribute list. This is the |
| 715 | /// number of arguments that have an attribute set on them (including the |
| 716 | /// function itself). |
| 717 | unsigned AttributeSet::getNumSlots() const { |
| 718 | return pImpl ? pImpl->getNumAttributes() : 0; |
| 719 | } |
| 720 | |
| 721 | uint64_t AttributeSet::getSlotIndex(unsigned Slot) const { |
| 722 | assert(pImpl && Slot < pImpl->getNumAttributes() && |
| 723 | "Slot # out of range!"); |
| 724 | return pImpl->getSlotIndex(Slot); |
| 725 | } |
| 726 | |
| 727 | AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const { |
| 728 | assert(pImpl && Slot < pImpl->getNumAttributes() && |
| 729 | "Slot # out of range!"); |
| 730 | return pImpl->getSlotAttributes(Slot); |
| 731 | } |
| 732 | |
| 733 | uint64_t AttributeSet::Raw(unsigned Index) const { |
| 734 | // FIXME: Remove this. |
| 735 | return pImpl ? pImpl->Raw(Index) : 0; |
| 736 | } |
| 737 | |
| 738 | void AttributeSet::dump() const { |
| 739 | dbgs() << "PAL[\n"; |
| 740 | |
| 741 | for (unsigned i = 0, e = getNumSlots(); i < e; ++i) { |
| 742 | uint64_t Index = getSlotIndex(i); |
| 743 | dbgs() << " { "; |
| 744 | if (Index == ~0U) |
| 745 | dbgs() << "~0U"; |
| 746 | else |
| 747 | dbgs() << Index; |
| 748 | dbgs() << " => " << getAsString(Index) << " }\n"; |
| 749 | } |
| 750 | |
| 751 | dbgs() << "]\n"; |
| 752 | } |
| 753 | |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 754 | //===----------------------------------------------------------------------===// |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 755 | // AttrBuilder Method Implementations |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 756 | //===----------------------------------------------------------------------===// |
| 757 | |
Bill Wendling | a90a99a | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 758 | AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Idx) |
| 759 | : Alignment(0), StackAlignment(0) { |
Bill Wendling | ec25898 | 2013-01-27 21:23:46 +0000 | [diff] [blame] | 760 | AttributeSetImpl *pImpl = AS.pImpl; |
Bill Wendling | a90a99a | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 761 | if (!pImpl) return; |
| 762 | |
Bill Wendling | 73bc452 | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 763 | for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) { |
| 764 | if (pImpl->getSlotIndex(I) != Idx) continue; |
Bill Wendling | a90a99a | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 765 | |
Bill Wendling | 383da6b | 2013-01-30 21:22:59 +0000 | [diff] [blame] | 766 | for (AttributeSetImpl::const_iterator II = pImpl->begin(I), |
Bill Wendling | 73bc452 | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 767 | IE = pImpl->end(I); II != IE; ++II) |
Bill Wendling | 383da6b | 2013-01-30 21:22:59 +0000 | [diff] [blame] | 768 | addAttributes(*II); |
Bill Wendling | 73bc452 | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 769 | |
| 770 | break; |
| 771 | } |
Bill Wendling | a90a99a | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 774 | void AttrBuilder::clear() { |
| 775 | Attrs.clear(); |
| 776 | Alignment = StackAlignment = 0; |
| 777 | } |
| 778 | |
| 779 | AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) { |
| 780 | Attrs.insert(Val); |
Bill Wendling | 3a106e6 | 2012-10-09 19:01:18 +0000 | [diff] [blame] | 781 | return *this; |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 784 | AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { |
| 785 | Attrs.erase(Val); |
| 786 | if (Val == Attribute::Alignment) |
| 787 | Alignment = 0; |
| 788 | else if (Val == Attribute::StackAlignment) |
| 789 | StackAlignment = 0; |
| 790 | |
Bill Wendling | a19a530 | 2012-10-14 04:10:01 +0000 | [diff] [blame] | 791 | return *this; |
| 792 | } |
| 793 | |
Bill Wendling | 49f6060 | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 794 | AttrBuilder &AttrBuilder::addAttributes(Attribute Attr) { |
| 795 | uint64_t Mask = Attr.Raw(); |
| 796 | |
| 797 | for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; |
| 798 | I = Attribute::AttrKind(I + 1)) |
| 799 | if ((Mask & AttributeImpl::getAttrMask(I)) != 0) |
| 800 | Attrs.insert(I); |
| 801 | |
| 802 | if (Attr.getAlignment()) |
| 803 | Alignment = Attr.getAlignment(); |
| 804 | if (Attr.getStackAlignment()) |
| 805 | StackAlignment = Attr.getStackAlignment(); |
| 806 | return *this; |
| 807 | } |
| 808 | |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 809 | AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) { |
| 810 | uint64_t Mask = A.Raw(Index); |
Bill Wendling | 49f6060 | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 811 | |
| 812 | for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; |
| 813 | I = Attribute::AttrKind(I + 1)) { |
| 814 | if (Mask & AttributeImpl::getAttrMask(I)) { |
| 815 | Attrs.erase(I); |
| 816 | |
| 817 | if (I == Attribute::Alignment) |
| 818 | Alignment = 0; |
| 819 | else if (I == Attribute::StackAlignment) |
| 820 | StackAlignment = 0; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | return *this; |
| 825 | } |
| 826 | |
Bill Wendling | 702cc91 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 827 | AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) { |
Bill Wendling | da3f9d8 | 2012-10-14 03:58:29 +0000 | [diff] [blame] | 828 | if (Align == 0) return *this; |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 829 | |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 830 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 831 | assert(Align <= 0x40000000 && "Alignment too large."); |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 832 | |
| 833 | Attrs.insert(Attribute::Alignment); |
| 834 | Alignment = Align; |
Bill Wendling | da3f9d8 | 2012-10-14 03:58:29 +0000 | [diff] [blame] | 835 | return *this; |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 838 | AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align) { |
| 839 | // Default alignment, allow the target to define how to align it. |
| 840 | if (Align == 0) return *this; |
| 841 | |
| 842 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 843 | assert(Align <= 0x100 && "Alignment too large."); |
| 844 | |
| 845 | Attrs.insert(Attribute::StackAlignment); |
| 846 | StackAlignment = Align; |
| 847 | return *this; |
| 848 | } |
| 849 | |
Bill Wendling | 22bd641 | 2013-01-03 01:54:39 +0000 | [diff] [blame] | 850 | bool AttrBuilder::contains(Attribute::AttrKind A) const { |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 851 | return Attrs.count(A); |
Bill Wendling | 7d2f249 | 2012-10-10 07:36:45 +0000 | [diff] [blame] | 852 | } |
| 853 | |
Bill Wendling | 702cc91 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 854 | bool AttrBuilder::hasAttributes() const { |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 855 | return !Attrs.empty(); |
Bill Wendling | f385f4c | 2012-10-08 23:27:46 +0000 | [diff] [blame] | 856 | } |
Bill Wendling | 60507d5 | 2013-01-04 20:54:35 +0000 | [diff] [blame] | 857 | |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 858 | bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const { |
| 859 | return Raw() & A.Raw(Index); |
Bill Wendling | 8831c06 | 2012-10-09 00:01:21 +0000 | [diff] [blame] | 860 | } |
Bill Wendling | 60507d5 | 2013-01-04 20:54:35 +0000 | [diff] [blame] | 861 | |
Bill Wendling | 702cc91 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 862 | bool AttrBuilder::hasAlignmentAttr() const { |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 863 | return Alignment != 0; |
Bill Wendling | f385f4c | 2012-10-08 23:27:46 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 866 | bool AttrBuilder::operator==(const AttrBuilder &B) { |
| 867 | SmallVector<Attribute::AttrKind, 8> This(Attrs.begin(), Attrs.end()); |
| 868 | SmallVector<Attribute::AttrKind, 8> That(B.Attrs.begin(), B.Attrs.end()); |
| 869 | return This == That; |
| 870 | } |
| 871 | |
| 872 | AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) { |
Bill Wendling | 8232ece | 2013-01-29 01:43:29 +0000 | [diff] [blame] | 873 | if (!Val) return *this; |
| 874 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 875 | for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; |
| 876 | I = Attribute::AttrKind(I + 1)) { |
| 877 | if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) { |
| 878 | Attrs.insert(I); |
| 879 | |
| 880 | if (I == Attribute::Alignment) |
| 881 | Alignment = 1ULL << ((A >> 16) - 1); |
| 882 | else if (I == Attribute::StackAlignment) |
| 883 | StackAlignment = 1ULL << ((A >> 26)-1); |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | return *this; |
| 888 | } |
| 889 | |
Bill Wendling | 1db9b69 | 2013-01-09 23:36:50 +0000 | [diff] [blame] | 890 | uint64_t AttrBuilder::Raw() const { |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 891 | uint64_t Mask = 0; |
| 892 | |
| 893 | for (DenseSet<Attribute::AttrKind>::const_iterator I = Attrs.begin(), |
| 894 | E = Attrs.end(); I != E; ++I) { |
| 895 | Attribute::AttrKind Kind = *I; |
| 896 | |
| 897 | if (Kind == Attribute::Alignment) |
| 898 | Mask |= (Log2_32(Alignment) + 1) << 16; |
| 899 | else if (Kind == Attribute::StackAlignment) |
| 900 | Mask |= (Log2_32(StackAlignment) + 1) << 26; |
| 901 | else |
| 902 | Mask |= AttributeImpl::getAttrMask(Kind); |
| 903 | } |
| 904 | |
| 905 | return Mask; |
Bill Wendling | f385f4c | 2012-10-08 23:27:46 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 908 | //===----------------------------------------------------------------------===// |
| 909 | // AttributeFuncs Function Defintions |
| 910 | //===----------------------------------------------------------------------===// |
| 911 | |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 912 | AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) { |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 913 | AttrBuilder Incompatible; |
| 914 | |
| 915 | if (!Ty->isIntegerTy()) |
| 916 | // Attribute that only apply to integers. |
| 917 | Incompatible.addAttribute(Attribute::SExt) |
| 918 | .addAttribute(Attribute::ZExt); |
| 919 | |
| 920 | if (!Ty->isPointerTy()) |
| 921 | // Attribute that only apply to pointers. |
| 922 | Incompatible.addAttribute(Attribute::ByVal) |
| 923 | .addAttribute(Attribute::Nest) |
| 924 | .addAttribute(Attribute::NoAlias) |
| 925 | .addAttribute(Attribute::NoCapture) |
| 926 | .addAttribute(Attribute::StructRet); |
| 927 | |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 928 | return AttributeSet::get(Ty->getContext(), Index, Incompatible); |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 929 | } |
| 930 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 931 | /// \brief This returns an integer containing an encoding of all the LLVM |
| 932 | /// attributes found in the given attribute bitset. Any change to this encoding |
| 933 | /// is a breaking change to bitcode compatibility. |
Bill Wendling | 8232ece | 2013-01-29 01:43:29 +0000 | [diff] [blame] | 934 | /// N.B. This should be used only by the bitcode reader! |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 935 | uint64_t AttributeFuncs::encodeLLVMAttributesForBitcode(AttributeSet Attrs, |
| 936 | unsigned Index) { |
| 937 | // FIXME: It doesn't make sense to store the alignment information as an |
| 938 | // expanded out value, we should store it as a log2 value. However, we can't |
| 939 | // just change that here without breaking bitcode compatibility. If this ever |
| 940 | // becomes a problem in practice, we should introduce new tag numbers in the |
| 941 | // bitcode file and have those tags use a more efficiently encoded alignment |
| 942 | // field. |
| 943 | |
| 944 | // Store the alignment in the bitcode as a 16-bit raw value instead of a 5-bit |
| 945 | // log2 encoded value. Shift the bits above the alignment up by 11 bits. |
| 946 | uint64_t EncodedAttrs = Attrs.Raw(Index) & 0xffff; |
| 947 | if (Attrs.hasAttribute(Index, Attribute::Alignment)) |
| 948 | EncodedAttrs |= Attrs.getParamAlignment(Index) << 16; |
| 949 | EncodedAttrs |= (Attrs.Raw(Index) & (0xffffULL << 21)) << 11; |
| 950 | return EncodedAttrs; |
| 951 | } |
| 952 | |
Bill Wendling | 8232ece | 2013-01-29 01:43:29 +0000 | [diff] [blame] | 953 | /// \brief This fills an AttrBuilder object with the LLVM attributes that have |
| 954 | /// been decoded from the given integer. This function must stay in sync with |
| 955 | /// 'encodeLLVMAttributesForBitcode'. |
| 956 | /// N.B. This should be used only by the bitcode reader! |
| 957 | void AttributeFuncs::decodeLLVMAttributesForBitcode(LLVMContext &C, |
| 958 | AttrBuilder &B, |
| 959 | uint64_t EncodedAttrs) { |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 960 | // The alignment is stored as a 16-bit raw value from bits 31--16. We shift |
| 961 | // the bits above 31 down by 11 bits. |
| 962 | unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16; |
| 963 | assert((!Alignment || isPowerOf2_32(Alignment)) && |
| 964 | "Alignment must be a power of two."); |
| 965 | |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 966 | if (Alignment) |
| 967 | B.addAlignmentAttr(Alignment); |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 968 | B.addRawValue(((EncodedAttrs & (0xffffULL << 32)) >> 11) | |
| 969 | (EncodedAttrs & 0xffff)); |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 970 | } |