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 | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 33 | Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, |
| 34 | uint64_t Val) { |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 35 | LLVMContextImpl *pImpl = Context.pImpl; |
| 36 | FoldingSetNodeID ID; |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 37 | ID.AddInteger(Kind); |
| 38 | if (Val) ID.AddInteger(Val); |
| 39 | |
| 40 | void *InsertPoint; |
| 41 | AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); |
| 42 | |
| 43 | if (!PA) { |
| 44 | // If we didn't find any existing attributes of the same shape then create a |
| 45 | // new one and insert it. |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 46 | if (!Val) |
| 47 | PA = new EnumAttributeImpl(Kind); |
| 48 | else |
| 49 | PA = new AlignAttributeImpl(Kind, Val); |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 50 | pImpl->AttrsSet.InsertNode(PA, InsertPoint); |
| 51 | } |
| 52 | |
| 53 | // Return the Attribute that we found or created. |
| 54 | return Attribute(PA); |
| 55 | } |
| 56 | |
| 57 | Attribute Attribute::get(LLVMContext &Context, StringRef Kind, StringRef Val) { |
| 58 | LLVMContextImpl *pImpl = Context.pImpl; |
| 59 | FoldingSetNodeID ID; |
| 60 | ID.AddString(Kind); |
| 61 | if (!Val.empty()) ID.AddString(Val); |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 62 | |
| 63 | void *InsertPoint; |
Bill Wendling | f667072 | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 64 | AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 65 | |
| 66 | if (!PA) { |
| 67 | // If we didn't find any existing attributes of the same shape then create a |
| 68 | // new one and insert it. |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 69 | PA = new StringAttributeImpl(Kind, Val); |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 70 | pImpl->AttrsSet.InsertNode(PA, InsertPoint); |
| 71 | } |
| 72 | |
Bill Wendling | ea59f89 | 2013-02-05 08:09:32 +0000 | [diff] [blame] | 73 | // Return the Attribute that we found or created. |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 74 | return Attribute(PA); |
Bill Wendling | 8e635db | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Bill Wendling | c08a5ef | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 77 | Attribute Attribute::getWithAlignment(LLVMContext &Context, uint64_t Align) { |
Bill Wendling | 169d527 | 2013-01-31 23:16:25 +0000 | [diff] [blame] | 78 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 79 | assert(Align <= 0x40000000 && "Alignment too large."); |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 80 | return get(Context, Alignment, Align); |
Bill Wendling | c08a5ef | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | Attribute Attribute::getWithStackAlignment(LLVMContext &Context, |
| 84 | uint64_t Align) { |
Bill Wendling | 169d527 | 2013-01-31 23:16:25 +0000 | [diff] [blame] | 85 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 86 | assert(Align <= 0x100 && "Alignment too large."); |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 87 | return get(Context, StackAlignment, Align); |
Bill Wendling | c08a5ef | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Bill Wendling | 817abdd | 2013-01-29 00:48:16 +0000 | [diff] [blame] | 90 | //===----------------------------------------------------------------------===// |
| 91 | // Attribute Accessor Methods |
| 92 | //===----------------------------------------------------------------------===// |
| 93 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 94 | bool Attribute::isEnumAttribute() const { |
| 95 | return pImpl && pImpl->isEnumAttribute(); |
| 96 | } |
| 97 | |
| 98 | bool Attribute::isAlignAttribute() const { |
| 99 | return pImpl && pImpl->isAlignAttribute(); |
| 100 | } |
| 101 | |
| 102 | bool Attribute::isStringAttribute() const { |
| 103 | return pImpl && pImpl->isStringAttribute(); |
| 104 | } |
| 105 | |
| 106 | Attribute::AttrKind Attribute::getKindAsEnum() const { |
Bill Wendling | f245ae5 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 107 | if (!pImpl) return None; |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 108 | assert((isEnumAttribute() || isAlignAttribute()) && |
| 109 | "Invalid attribute type to get the kind as an enum!"); |
| 110 | return pImpl ? pImpl->getKindAsEnum() : None; |
| 111 | } |
| 112 | |
| 113 | uint64_t Attribute::getValueAsInt() const { |
Bill Wendling | f245ae5 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 114 | if (!pImpl) return 0; |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 115 | assert(isAlignAttribute() && |
| 116 | "Expected the attribute to be an alignment attribute!"); |
| 117 | return pImpl ? pImpl->getValueAsInt() : 0; |
| 118 | } |
| 119 | |
| 120 | StringRef Attribute::getKindAsString() const { |
Bill Wendling | f245ae5 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 121 | if (!pImpl) return StringRef(); |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 122 | assert(isStringAttribute() && |
| 123 | "Invalid attribute type to get the kind as a string!"); |
| 124 | return pImpl ? pImpl->getKindAsString() : StringRef(); |
| 125 | } |
| 126 | |
| 127 | StringRef Attribute::getValueAsString() const { |
Bill Wendling | f245ae5 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 128 | if (!pImpl) return StringRef(); |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 129 | assert(isStringAttribute() && |
| 130 | "Invalid attribute type to get the value as a string!"); |
| 131 | return pImpl ? pImpl->getValueAsString() : StringRef(); |
| 132 | } |
| 133 | |
Bill Wendling | 64754f4 | 2013-02-05 23:48:36 +0000 | [diff] [blame] | 134 | bool Attribute::hasAttribute(AttrKind Kind) const { |
| 135 | return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None); |
| 136 | } |
| 137 | |
| 138 | bool Attribute::hasAttribute(StringRef Kind) const { |
| 139 | if (!isStringAttribute()) return false; |
| 140 | return pImpl && pImpl->hasAttribute(Kind); |
Bill Wendling | 6dc3781 | 2013-01-29 20:45:34 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 143 | /// 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] | 144 | unsigned Attribute::getAlignment() const { |
Bill Wendling | 7beee28 | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 145 | assert(hasAttribute(Attribute::Alignment) && |
| 146 | "Trying to get alignment from non-alignment attribute!"); |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 147 | return pImpl->getValueAsInt(); |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /// This returns the stack alignment field of an attribute as a byte alignment |
| 151 | /// value. |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 152 | unsigned Attribute::getStackAlignment() const { |
Bill Wendling | 7beee28 | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 153 | assert(hasAttribute(Attribute::StackAlignment) && |
| 154 | "Trying to get alignment from non-alignment attribute!"); |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 155 | return pImpl->getValueAsInt(); |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 158 | std::string Attribute::getAsString(bool InAttrGrp) const { |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 159 | if (!pImpl) return ""; |
| 160 | |
Kostya Serebryany | 8eec41f | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 161 | if (hasAttribute(Attribute::SanitizeAddress)) |
| 162 | return "sanitize_address"; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 163 | if (hasAttribute(Attribute::AlwaysInline)) |
| 164 | return "alwaysinline"; |
Michael Gottesman | 2253a2f | 2013-06-27 00:25:01 +0000 | [diff] [blame] | 165 | if (hasAttribute(Attribute::Builtin)) |
| 166 | return "builtin"; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 167 | if (hasAttribute(Attribute::ByVal)) |
| 168 | return "byval"; |
| 169 | if (hasAttribute(Attribute::InlineHint)) |
| 170 | return "inlinehint"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 171 | if (hasAttribute(Attribute::InReg)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 172 | return "inreg"; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 173 | if (hasAttribute(Attribute::MinSize)) |
| 174 | return "minsize"; |
| 175 | if (hasAttribute(Attribute::Naked)) |
| 176 | return "naked"; |
| 177 | if (hasAttribute(Attribute::Nest)) |
| 178 | return "nest"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 179 | if (hasAttribute(Attribute::NoAlias)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 180 | return "noalias"; |
Bill Wendling | 143d464 | 2013-02-22 00:12:35 +0000 | [diff] [blame] | 181 | if (hasAttribute(Attribute::NoBuiltin)) |
| 182 | return "nobuiltin"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 183 | if (hasAttribute(Attribute::NoCapture)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 184 | return "nocapture"; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 185 | if (hasAttribute(Attribute::NoDuplicate)) |
| 186 | return "noduplicate"; |
| 187 | if (hasAttribute(Attribute::NoImplicitFloat)) |
| 188 | return "noimplicitfloat"; |
| 189 | if (hasAttribute(Attribute::NoInline)) |
| 190 | return "noinline"; |
| 191 | if (hasAttribute(Attribute::NonLazyBind)) |
| 192 | return "nonlazybind"; |
| 193 | if (hasAttribute(Attribute::NoRedZone)) |
| 194 | return "noredzone"; |
| 195 | if (hasAttribute(Attribute::NoReturn)) |
| 196 | return "noreturn"; |
| 197 | if (hasAttribute(Attribute::NoUnwind)) |
| 198 | return "nounwind"; |
| 199 | if (hasAttribute(Attribute::OptimizeForSize)) |
| 200 | return "optsize"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 201 | if (hasAttribute(Attribute::ReadNone)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 202 | return "readnone"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 203 | if (hasAttribute(Attribute::ReadOnly)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 204 | return "readonly"; |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 205 | if (hasAttribute(Attribute::Returned)) |
| 206 | return "returned"; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 207 | if (hasAttribute(Attribute::ReturnsTwice)) |
| 208 | return "returns_twice"; |
| 209 | if (hasAttribute(Attribute::SExt)) |
| 210 | return "signext"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 211 | if (hasAttribute(Attribute::StackProtect)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 212 | return "ssp"; |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 213 | if (hasAttribute(Attribute::StackProtectReq)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 214 | return "sspreq"; |
Bill Wendling | 114baee | 2013-01-23 06:41:41 +0000 | [diff] [blame] | 215 | if (hasAttribute(Attribute::StackProtectStrong)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 216 | return "sspstrong"; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 217 | if (hasAttribute(Attribute::StructRet)) |
| 218 | return "sret"; |
Kostya Serebryany | 8eec41f | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 219 | if (hasAttribute(Attribute::SanitizeThread)) |
| 220 | return "sanitize_thread"; |
| 221 | if (hasAttribute(Attribute::SanitizeMemory)) |
| 222 | return "sanitize_memory"; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 223 | if (hasAttribute(Attribute::UWTable)) |
| 224 | return "uwtable"; |
| 225 | if (hasAttribute(Attribute::ZExt)) |
| 226 | return "zeroext"; |
Diego Novillo | 77226a0 | 2013-05-24 12:26:52 +0000 | [diff] [blame] | 227 | if (hasAttribute(Attribute::Cold)) |
| 228 | return "cold"; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 229 | |
| 230 | // FIXME: These should be output like this: |
| 231 | // |
| 232 | // align=4 |
| 233 | // alignstack=8 |
| 234 | // |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 235 | if (hasAttribute(Attribute::Alignment)) { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 236 | std::string Result; |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 237 | Result += "align"; |
| 238 | Result += (InAttrGrp) ? "=" : " "; |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 239 | Result += utostr(getValueAsInt()); |
| 240 | return Result; |
| 241 | } |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 242 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 243 | if (hasAttribute(Attribute::StackAlignment)) { |
| 244 | std::string Result; |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 245 | Result += "alignstack"; |
| 246 | if (InAttrGrp) { |
| 247 | Result += "="; |
| 248 | Result += utostr(getValueAsInt()); |
| 249 | } else { |
| 250 | Result += "("; |
| 251 | Result += utostr(getValueAsInt()); |
| 252 | Result += ")"; |
| 253 | } |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 254 | return Result; |
Dale Johannesen | 6167c3f | 2008-02-19 23:51:49 +0000 | [diff] [blame] | 255 | } |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 256 | |
| 257 | // Convert target-dependent attributes to strings of the form: |
| 258 | // |
| 259 | // "kind" |
| 260 | // "kind" = "value" |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 261 | // |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 262 | if (isStringAttribute()) { |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 263 | std::string Result; |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 264 | Result += '\"' + getKindAsString().str() + '"'; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 265 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 266 | StringRef Val = pImpl->getValueAsString(); |
| 267 | if (Val.empty()) return Result; |
Bill Wendling | 5a4041e | 2013-02-01 22:32:30 +0000 | [diff] [blame] | 268 | |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 269 | Result += "=\"" + Val.str() + '"'; |
Bill Wendling | 7beee28 | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 270 | return Result; |
Bill Wendling | 14292a6 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 271 | } |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 272 | |
| 273 | llvm_unreachable("Unknown attribute"); |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 276 | bool Attribute::operator<(Attribute A) const { |
| 277 | if (!pImpl && !A.pImpl) return false; |
| 278 | if (!pImpl) return true; |
| 279 | if (!A.pImpl) return false; |
| 280 | return *pImpl < *A.pImpl; |
| 281 | } |
| 282 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 283 | //===----------------------------------------------------------------------===// |
| 284 | // AttributeImpl Definition |
| 285 | //===----------------------------------------------------------------------===// |
| 286 | |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 287 | AttributeImpl::~AttributeImpl() {} |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 288 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 289 | bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const { |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 290 | if (isStringAttribute()) return false; |
| 291 | return getKindAsEnum() == A; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 294 | bool AttributeImpl::hasAttribute(StringRef Kind) const { |
| 295 | if (!isStringAttribute()) return false; |
| 296 | return getKindAsString() == Kind; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 299 | Attribute::AttrKind AttributeImpl::getKindAsEnum() const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 300 | assert(isEnumAttribute() || isAlignAttribute()); |
| 301 | return static_cast<const EnumAttributeImpl *>(this)->getEnumKind(); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 304 | uint64_t AttributeImpl::getValueAsInt() const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 305 | assert(isAlignAttribute()); |
| 306 | return static_cast<const AlignAttributeImpl *>(this)->getAlignment(); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 309 | StringRef AttributeImpl::getKindAsString() const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 310 | assert(isStringAttribute()); |
| 311 | return static_cast<const StringAttributeImpl *>(this)->getStringKind(); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 314 | StringRef AttributeImpl::getValueAsString() const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 315 | assert(isStringAttribute()); |
| 316 | return static_cast<const StringAttributeImpl *>(this)->getStringValue(); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | bool AttributeImpl::operator<(const AttributeImpl &AI) const { |
Bill Wendling | 7beee28 | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 320 | // This sorts the attributes with Attribute::AttrKinds coming first (sorted |
| 321 | // relative to their enum value) and then strings. |
Bill Wendling | 94328f4 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 322 | if (isEnumAttribute()) { |
| 323 | if (AI.isEnumAttribute()) return getKindAsEnum() < AI.getKindAsEnum(); |
| 324 | if (AI.isAlignAttribute()) return true; |
| 325 | if (AI.isStringAttribute()) return true; |
| 326 | } |
Bill Wendling | 7beee28 | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 327 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 328 | if (isAlignAttribute()) { |
Bill Wendling | 94328f4 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 329 | if (AI.isEnumAttribute()) return false; |
| 330 | if (AI.isAlignAttribute()) return getValueAsInt() < AI.getValueAsInt(); |
| 331 | if (AI.isStringAttribute()) return true; |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 332 | } |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 333 | |
Bill Wendling | 94328f4 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 334 | if (AI.isEnumAttribute()) return false; |
| 335 | if (AI.isAlignAttribute()) return false; |
| 336 | if (getKindAsString() == AI.getKindAsString()) |
| 337 | return getValueAsString() < AI.getValueAsString(); |
| 338 | return getKindAsString() < AI.getKindAsString(); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 341 | uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) { |
| 342 | // FIXME: Remove this. |
| 343 | switch (Val) { |
| 344 | case Attribute::EndAttrKinds: |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 345 | llvm_unreachable("Synthetic enumerators which should never get here"); |
| 346 | |
| 347 | case Attribute::None: return 0; |
| 348 | case Attribute::ZExt: return 1 << 0; |
| 349 | case Attribute::SExt: return 1 << 1; |
| 350 | case Attribute::NoReturn: return 1 << 2; |
| 351 | case Attribute::InReg: return 1 << 3; |
| 352 | case Attribute::StructRet: return 1 << 4; |
| 353 | case Attribute::NoUnwind: return 1 << 5; |
| 354 | case Attribute::NoAlias: return 1 << 6; |
| 355 | case Attribute::ByVal: return 1 << 7; |
| 356 | case Attribute::Nest: return 1 << 8; |
| 357 | case Attribute::ReadNone: return 1 << 9; |
| 358 | case Attribute::ReadOnly: return 1 << 10; |
| 359 | case Attribute::NoInline: return 1 << 11; |
| 360 | case Attribute::AlwaysInline: return 1 << 12; |
| 361 | case Attribute::OptimizeForSize: return 1 << 13; |
| 362 | case Attribute::StackProtect: return 1 << 14; |
| 363 | case Attribute::StackProtectReq: return 1 << 15; |
| 364 | case Attribute::Alignment: return 31 << 16; |
| 365 | case Attribute::NoCapture: return 1 << 21; |
| 366 | case Attribute::NoRedZone: return 1 << 22; |
| 367 | case Attribute::NoImplicitFloat: return 1 << 23; |
| 368 | case Attribute::Naked: return 1 << 24; |
| 369 | case Attribute::InlineHint: return 1 << 25; |
| 370 | case Attribute::StackAlignment: return 7 << 26; |
| 371 | case Attribute::ReturnsTwice: return 1 << 29; |
| 372 | case Attribute::UWTable: return 1 << 30; |
| 373 | case Attribute::NonLazyBind: return 1U << 31; |
Kostya Serebryany | 8eec41f | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 374 | case Attribute::SanitizeAddress: return 1ULL << 32; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 375 | case Attribute::MinSize: return 1ULL << 33; |
| 376 | case Attribute::NoDuplicate: return 1ULL << 34; |
| 377 | case Attribute::StackProtectStrong: return 1ULL << 35; |
Kostya Serebryany | 8eec41f | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 378 | case Attribute::SanitizeThread: return 1ULL << 36; |
| 379 | case Attribute::SanitizeMemory: return 1ULL << 37; |
Bill Wendling | d18e0b9 | 2013-02-22 00:40:12 +0000 | [diff] [blame] | 380 | case Attribute::NoBuiltin: return 1ULL << 38; |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 381 | case Attribute::Returned: return 1ULL << 39; |
Diego Novillo | 77226a0 | 2013-05-24 12:26:52 +0000 | [diff] [blame] | 382 | case Attribute::Cold: return 1ULL << 40; |
Michael Gottesman | 2253a2f | 2013-06-27 00:25:01 +0000 | [diff] [blame] | 383 | case Attribute::Builtin: return 1ULL << 41; |
Bill Wendling | bd2acfa | 2013-02-22 00:50:09 +0000 | [diff] [blame] | 384 | } |
| 385 | llvm_unreachable("Unsupported attribute type"); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | //===----------------------------------------------------------------------===// |
| 389 | // AttributeSetNode Definition |
| 390 | //===----------------------------------------------------------------------===// |
| 391 | |
| 392 | AttributeSetNode *AttributeSetNode::get(LLVMContext &C, |
| 393 | ArrayRef<Attribute> Attrs) { |
| 394 | if (Attrs.empty()) |
| 395 | return 0; |
| 396 | |
| 397 | // Otherwise, build a key to look up the existing attributes. |
| 398 | LLVMContextImpl *pImpl = C.pImpl; |
| 399 | FoldingSetNodeID ID; |
| 400 | |
| 401 | SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end()); |
Bill Wendling | f107e6c | 2013-02-13 09:26:26 +0000 | [diff] [blame] | 402 | array_pod_sort(SortedAttrs.begin(), SortedAttrs.end()); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 403 | |
| 404 | for (SmallVectorImpl<Attribute>::iterator I = SortedAttrs.begin(), |
| 405 | E = SortedAttrs.end(); I != E; ++I) |
| 406 | I->Profile(ID); |
| 407 | |
| 408 | void *InsertPoint; |
| 409 | AttributeSetNode *PA = |
| 410 | pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint); |
| 411 | |
| 412 | // If we didn't find any existing attributes of the same shape then create a |
| 413 | // new one and insert it. |
| 414 | if (!PA) { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 415 | // Coallocate entries after the AttributeSetNode itself. |
| 416 | void *Mem = ::operator new(sizeof(AttributeSetNode) + |
| 417 | sizeof(Attribute) * SortedAttrs.size()); |
| 418 | PA = new (Mem) AttributeSetNode(SortedAttrs); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 419 | pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint); |
| 420 | } |
| 421 | |
| 422 | // Return the AttributesListNode that we found or created. |
| 423 | return PA; |
| 424 | } |
| 425 | |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 426 | bool AttributeSetNode::hasAttribute(Attribute::AttrKind Kind) const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 427 | for (iterator I = begin(), E = end(); I != E; ++I) |
NAKAMURA Takumi | eddab15 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 428 | if (I->hasAttribute(Kind)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 429 | return true; |
| 430 | return false; |
| 431 | } |
| 432 | |
Bill Wendling | 0e9d5d0 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 433 | bool AttributeSetNode::hasAttribute(StringRef Kind) const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 434 | for (iterator I = begin(), E = end(); I != E; ++I) |
Bill Wendling | 0e9d5d0 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 435 | if (I->hasAttribute(Kind)) |
| 436 | return true; |
| 437 | return false; |
| 438 | } |
| 439 | |
| 440 | Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 441 | for (iterator I = begin(), E = end(); I != E; ++I) |
Bill Wendling | 0e9d5d0 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 442 | if (I->hasAttribute(Kind)) |
| 443 | return *I; |
| 444 | return Attribute(); |
| 445 | } |
| 446 | |
| 447 | Attribute AttributeSetNode::getAttribute(StringRef Kind) const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 448 | for (iterator I = begin(), E = end(); I != E; ++I) |
Bill Wendling | 0e9d5d0 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 449 | if (I->hasAttribute(Kind)) |
| 450 | return *I; |
| 451 | return Attribute(); |
| 452 | } |
| 453 | |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 454 | unsigned AttributeSetNode::getAlignment() const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 455 | for (iterator I = begin(), E = end(); I != E; ++I) |
NAKAMURA Takumi | eddab15 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 456 | if (I->hasAttribute(Attribute::Alignment)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 457 | return I->getAlignment(); |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | unsigned AttributeSetNode::getStackAlignment() const { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 462 | for (iterator I = begin(), E = end(); I != E; ++I) |
NAKAMURA Takumi | eddab15 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 463 | if (I->hasAttribute(Attribute::StackAlignment)) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 464 | return I->getStackAlignment(); |
| 465 | return 0; |
| 466 | } |
| 467 | |
Rafael Espindola | aae0298 | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 468 | std::string AttributeSetNode::getAsString(bool InAttrGrp) const { |
Benjamin Kramer | e94e4ca | 2013-04-19 11:43:21 +0000 | [diff] [blame] | 469 | std::string Str; |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 470 | for (iterator I = begin(), E = end(); I != E; ++I) { |
| 471 | if (I != begin()) |
Rafael Espindola | aae0298 | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 472 | Str += ' '; |
| 473 | Str += I->getAsString(InAttrGrp); |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 474 | } |
| 475 | return Str; |
| 476 | } |
| 477 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 478 | //===----------------------------------------------------------------------===// |
| 479 | // AttributeSetImpl Definition |
| 480 | //===----------------------------------------------------------------------===// |
| 481 | |
Rafael Espindola | 76f103e | 2013-04-30 16:53:38 +0000 | [diff] [blame] | 482 | uint64_t AttributeSetImpl::Raw(unsigned Index) const { |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 483 | for (unsigned I = 0, E = getNumAttributes(); I != E; ++I) { |
| 484 | if (getSlotIndex(I) != Index) continue; |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 485 | const AttributeSetNode *ASN = getSlotNode(I); |
Bill Wendling | fca0ed2 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 486 | uint64_t Mask = 0; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 487 | |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 488 | for (AttributeSetNode::iterator II = ASN->begin(), |
Bill Wendling | fca0ed2 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 489 | IE = ASN->end(); II != IE; ++II) { |
| 490 | Attribute Attr = *II; |
Bill Wendling | 2153691 | 2013-02-10 23:18:05 +0000 | [diff] [blame] | 491 | |
| 492 | // This cannot handle string attributes. |
| 493 | if (Attr.isStringAttribute()) continue; |
| 494 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 495 | Attribute::AttrKind Kind = Attr.getKindAsEnum(); |
Bill Wendling | fca0ed2 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 496 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 497 | if (Kind == Attribute::Alignment) |
Bill Wendling | fca0ed2 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 498 | Mask |= (Log2_32(ASN->getAlignment()) + 1) << 16; |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 499 | else if (Kind == Attribute::StackAlignment) |
Bill Wendling | fca0ed2 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 500 | Mask |= (Log2_32(ASN->getStackAlignment()) + 1) << 26; |
| 501 | else |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 502 | Mask |= AttributeImpl::getAttrMask(Kind); |
Bill Wendling | fca0ed2 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | return Mask; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | //===----------------------------------------------------------------------===// |
| 512 | // AttributeSet Construction and Mutation Methods |
| 513 | //===----------------------------------------------------------------------===// |
| 514 | |
Bill Wendling | 8232ece | 2013-01-29 01:43:29 +0000 | [diff] [blame] | 515 | AttributeSet |
| 516 | AttributeSet::getImpl(LLVMContext &C, |
| 517 | ArrayRef<std::pair<unsigned, AttributeSetNode*> > Attrs) { |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 518 | LLVMContextImpl *pImpl = C.pImpl; |
| 519 | FoldingSetNodeID ID; |
| 520 | AttributeSetImpl::Profile(ID, Attrs); |
| 521 | |
| 522 | void *InsertPoint; |
| 523 | AttributeSetImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint); |
| 524 | |
| 525 | // If we didn't find any existing attributes of the same shape then |
| 526 | // create a new one and insert it. |
| 527 | if (!PA) { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 528 | // Coallocate entries after the AttributeSetImpl itself. |
| 529 | void *Mem = ::operator new(sizeof(AttributeSetImpl) + |
| 530 | sizeof(std::pair<unsigned, AttributeSetNode *>) * |
| 531 | Attrs.size()); |
| 532 | PA = new (Mem) AttributeSetImpl(C, Attrs); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 533 | pImpl->AttrsLists.InsertNode(PA, InsertPoint); |
| 534 | } |
| 535 | |
| 536 | // Return the AttributesList that we found or created. |
| 537 | return AttributeSet(PA); |
| 538 | } |
| 539 | |
| 540 | AttributeSet AttributeSet::get(LLVMContext &C, |
| 541 | ArrayRef<std::pair<unsigned, Attribute> > Attrs){ |
| 542 | // If there are no attributes then return a null AttributesList pointer. |
| 543 | if (Attrs.empty()) |
| 544 | return AttributeSet(); |
| 545 | |
| 546 | #ifndef NDEBUG |
| 547 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { |
| 548 | assert((!i || Attrs[i-1].first <= Attrs[i].first) && |
| 549 | "Misordered Attributes list!"); |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 550 | assert(!Attrs[i].second.hasAttribute(Attribute::None) && |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 551 | "Pointless attribute!"); |
| 552 | } |
| 553 | #endif |
| 554 | |
| 555 | // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes |
| 556 | // list. |
| 557 | SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrPairVec; |
| 558 | for (ArrayRef<std::pair<unsigned, Attribute> >::iterator I = Attrs.begin(), |
| 559 | E = Attrs.end(); I != E; ) { |
| 560 | unsigned Index = I->first; |
| 561 | SmallVector<Attribute, 4> AttrVec; |
NAKAMURA Takumi | 3ba51ce | 2013-01-29 15:18:16 +0000 | [diff] [blame] | 562 | while (I != E && I->first == Index) { |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 563 | AttrVec.push_back(I->second); |
| 564 | ++I; |
| 565 | } |
| 566 | |
| 567 | AttrPairVec.push_back(std::make_pair(Index, |
| 568 | AttributeSetNode::get(C, AttrVec))); |
| 569 | } |
| 570 | |
| 571 | return getImpl(C, AttrPairVec); |
| 572 | } |
| 573 | |
| 574 | AttributeSet AttributeSet::get(LLVMContext &C, |
| 575 | ArrayRef<std::pair<unsigned, |
| 576 | AttributeSetNode*> > Attrs) { |
| 577 | // If there are no attributes then return a null AttributesList pointer. |
| 578 | if (Attrs.empty()) |
| 579 | return AttributeSet(); |
| 580 | |
| 581 | return getImpl(C, Attrs); |
| 582 | } |
| 583 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 584 | AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, AttrBuilder &B) { |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 585 | if (!B.hasAttributes()) |
| 586 | return AttributeSet(); |
Bill Wendling | 8fbc0c2 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 587 | |
Bill Wendling | 64754f4 | 2013-02-05 23:48:36 +0000 | [diff] [blame] | 588 | // Add target-independent attributes. |
Bill Wendling | 8fbc0c2 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 589 | SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; |
Benjamin Kramer | c835b8c | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 590 | for (Attribute::AttrKind Kind = Attribute::None; |
Benjamin Kramer | 7c14612 | 2013-02-16 19:22:28 +0000 | [diff] [blame] | 591 | Kind != Attribute::EndAttrKinds; Kind = Attribute::AttrKind(Kind + 1)) { |
Benjamin Kramer | c835b8c | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 592 | if (!B.contains(Kind)) |
| 593 | continue; |
| 594 | |
Bill Wendling | 8fbc0c2 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 595 | if (Kind == Attribute::Alignment) |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 596 | Attrs.push_back(std::make_pair(Index, Attribute:: |
Bill Wendling | 8fbc0c2 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 597 | getWithAlignment(C, B.getAlignment()))); |
| 598 | else if (Kind == Attribute::StackAlignment) |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 599 | Attrs.push_back(std::make_pair(Index, Attribute:: |
Bill Wendling | 8fbc0c2 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 600 | getWithStackAlignment(C, B.getStackAlignment()))); |
| 601 | else |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 602 | Attrs.push_back(std::make_pair(Index, Attribute::get(C, Kind))); |
Bill Wendling | 8fbc0c2 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Bill Wendling | 64754f4 | 2013-02-05 23:48:36 +0000 | [diff] [blame] | 605 | // Add target-dependent (string) attributes. |
| 606 | for (AttrBuilder::td_iterator I = B.td_begin(), E = B.td_end(); |
| 607 | I != E; ++I) |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 608 | Attrs.push_back(std::make_pair(Index, Attribute::get(C, I->first,I->second))); |
Bill Wendling | 64754f4 | 2013-02-05 23:48:36 +0000 | [diff] [blame] | 609 | |
Bill Wendling | 8fbc0c2 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 610 | return get(C, Attrs); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 613 | AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 614 | ArrayRef<Attribute::AttrKind> Kind) { |
| 615 | SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; |
| 616 | for (ArrayRef<Attribute::AttrKind>::iterator I = Kind.begin(), |
| 617 | E = Kind.end(); I != E; ++I) |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 618 | Attrs.push_back(std::make_pair(Index, Attribute::get(C, *I))); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 619 | return get(C, Attrs); |
| 620 | } |
| 621 | |
| 622 | AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) { |
| 623 | if (Attrs.empty()) return AttributeSet(); |
Peter Collingbourne | 7bba9c5 | 2013-08-02 22:29:40 +0000 | [diff] [blame^] | 624 | if (Attrs.size() == 1) return Attrs[0]; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 625 | |
| 626 | SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrNodeVec; |
Peter Collingbourne | 7bba9c5 | 2013-08-02 22:29:40 +0000 | [diff] [blame^] | 627 | AttributeSetImpl *A0 = Attrs[0].pImpl; |
| 628 | if (A0) |
| 629 | AttrNodeVec.append(A0->getNode(0), A0->getNode(A0->getNumAttributes())); |
| 630 | // Copy all attributes from Attrs into AttrNodeVec while keeping AttrNodeVec |
| 631 | // ordered by index. Because we know that each list in Attrs is ordered by |
| 632 | // index we only need to merge each successive list in rather than doing a |
| 633 | // full sort. |
| 634 | for (unsigned I = 1, E = Attrs.size(); I != E; ++I) { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 635 | AttributeSetImpl *AS = Attrs[I].pImpl; |
| 636 | if (!AS) continue; |
Peter Collingbourne | 7bba9c5 | 2013-08-02 22:29:40 +0000 | [diff] [blame^] | 637 | SmallVector<std::pair<unsigned, AttributeSetNode *>, 8>::iterator |
| 638 | ANVI = AttrNodeVec.begin(), ANVE; |
| 639 | for (const AttributeSetImpl::IndexAttrPair |
| 640 | *AI = AS->getNode(0), |
| 641 | *AE = AS->getNode(AS->getNumAttributes()); |
| 642 | AI != AE; ++AI) { |
| 643 | ANVE = AttrNodeVec.end(); |
| 644 | while (ANVI != ANVE && ANVI->first <= AI->first) |
| 645 | ++ANVI; |
| 646 | ANVI = AttrNodeVec.insert(ANVI, *AI) + 1; |
| 647 | } |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | return getImpl(C, AttrNodeVec); |
| 651 | } |
| 652 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 653 | AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 654 | Attribute::AttrKind Attr) const { |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 655 | if (hasAttribute(Index, Attr)) return *this; |
| 656 | return addAttributes(C, Index, AttributeSet::get(C, Index, Attr)); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 659 | AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, |
Reed Kotler | 9106f73 | 2013-03-13 20:20:08 +0000 | [diff] [blame] | 660 | StringRef Kind) const { |
| 661 | llvm::AttrBuilder B; |
| 662 | B.addAttribute(Kind); |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 663 | return addAttributes(C, Index, AttributeSet::get(C, Index, B)); |
Reed Kotler | 9106f73 | 2013-03-13 20:20:08 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Bill Wendling | 9e2ef77 | 2013-07-25 18:34:24 +0000 | [diff] [blame] | 666 | AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, |
| 667 | StringRef Kind, StringRef Value) const { |
| 668 | llvm::AttrBuilder B; |
| 669 | B.addAttribute(Kind, Value); |
| 670 | return addAttributes(C, Index, AttributeSet::get(C, Index, B)); |
| 671 | } |
| 672 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 673 | AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Index, |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 674 | AttributeSet Attrs) const { |
| 675 | if (!pImpl) return Attrs; |
| 676 | if (!Attrs.pImpl) return *this; |
| 677 | |
| 678 | #ifndef NDEBUG |
| 679 | // FIXME it is not obvious how this should work for alignment. For now, say |
| 680 | // we can't change a known alignment. |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 681 | unsigned OldAlign = getParamAlignment(Index); |
| 682 | unsigned NewAlign = Attrs.getParamAlignment(Index); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 683 | assert((!OldAlign || !NewAlign || OldAlign == NewAlign) && |
| 684 | "Attempt to change alignment!"); |
| 685 | #endif |
| 686 | |
| 687 | // Add the attribute slots before the one we're trying to add. |
| 688 | SmallVector<AttributeSet, 4> AttrSet; |
| 689 | uint64_t NumAttrs = pImpl->getNumAttributes(); |
| 690 | AttributeSet AS; |
| 691 | uint64_t LastIndex = 0; |
| 692 | for (unsigned I = 0, E = NumAttrs; I != E; ++I) { |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 693 | if (getSlotIndex(I) >= Index) { |
| 694 | if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 695 | break; |
| 696 | } |
| 697 | LastIndex = I + 1; |
| 698 | AttrSet.push_back(getSlotAttributes(I)); |
| 699 | } |
| 700 | |
| 701 | // Now add the attribute into the correct slot. There may already be an |
| 702 | // AttributeSet there. |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 703 | AttrBuilder B(AS, Index); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 704 | |
| 705 | for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I) |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 706 | if (Attrs.getSlotIndex(I) == Index) { |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 707 | for (AttributeSetImpl::iterator II = Attrs.pImpl->begin(I), |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 708 | IE = Attrs.pImpl->end(I); II != IE; ++II) |
Bill Wendling | 39da078 | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 709 | B.addAttribute(*II); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 710 | break; |
| 711 | } |
| 712 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 713 | AttrSet.push_back(AttributeSet::get(C, Index, B)); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 714 | |
| 715 | // Add the remaining attribute slots. |
| 716 | for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I) |
| 717 | AttrSet.push_back(getSlotAttributes(I)); |
| 718 | |
| 719 | return get(C, AttrSet); |
| 720 | } |
| 721 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 722 | AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Index, |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 723 | Attribute::AttrKind Attr) const { |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 724 | if (!hasAttribute(Index, Attr)) return *this; |
| 725 | return removeAttributes(C, Index, AttributeSet::get(C, Index, Attr)); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 728 | AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index, |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 729 | AttributeSet Attrs) const { |
| 730 | if (!pImpl) return AttributeSet(); |
| 731 | if (!Attrs.pImpl) return *this; |
| 732 | |
| 733 | #ifndef NDEBUG |
| 734 | // FIXME it is not obvious how this should work for alignment. |
| 735 | // For now, say we can't pass in alignment, which no current use does. |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 736 | assert(!Attrs.hasAttribute(Index, Attribute::Alignment) && |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 737 | "Attempt to change alignment!"); |
| 738 | #endif |
| 739 | |
| 740 | // Add the attribute slots before the one we're trying to add. |
| 741 | SmallVector<AttributeSet, 4> AttrSet; |
| 742 | uint64_t NumAttrs = pImpl->getNumAttributes(); |
| 743 | AttributeSet AS; |
| 744 | uint64_t LastIndex = 0; |
| 745 | for (unsigned I = 0, E = NumAttrs; I != E; ++I) { |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 746 | if (getSlotIndex(I) >= Index) { |
| 747 | if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 748 | break; |
| 749 | } |
| 750 | LastIndex = I + 1; |
| 751 | AttrSet.push_back(getSlotAttributes(I)); |
| 752 | } |
| 753 | |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 754 | // 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] | 755 | // AttributeSet there. |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 756 | AttrBuilder B(AS, Index); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 757 | |
| 758 | for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I) |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 759 | if (Attrs.getSlotIndex(I) == Index) { |
| 760 | B.removeAttributes(Attrs.pImpl->getSlotAttributes(I), Index); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 761 | break; |
| 762 | } |
| 763 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 764 | AttrSet.push_back(AttributeSet::get(C, Index, B)); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 765 | |
| 766 | // Add the remaining attribute slots. |
| 767 | for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I) |
| 768 | AttrSet.push_back(getSlotAttributes(I)); |
| 769 | |
| 770 | return get(C, AttrSet); |
| 771 | } |
| 772 | |
| 773 | //===----------------------------------------------------------------------===// |
| 774 | // AttributeSet Accessor Methods |
| 775 | //===----------------------------------------------------------------------===// |
| 776 | |
Bill Wendling | 85b3fbe | 2013-02-10 05:00:40 +0000 | [diff] [blame] | 777 | LLVMContext &AttributeSet::getContext() const { |
| 778 | return pImpl->getContext(); |
| 779 | } |
| 780 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 781 | AttributeSet AttributeSet::getParamAttributes(unsigned Index) const { |
| 782 | return pImpl && hasAttributes(Index) ? |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 783 | AttributeSet::get(pImpl->getContext(), |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 784 | ArrayRef<std::pair<unsigned, AttributeSetNode*> >( |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 785 | std::make_pair(Index, getAttributes(Index)))) : |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 786 | AttributeSet(); |
| 787 | } |
| 788 | |
| 789 | AttributeSet AttributeSet::getRetAttributes() const { |
| 790 | return pImpl && hasAttributes(ReturnIndex) ? |
| 791 | AttributeSet::get(pImpl->getContext(), |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 792 | ArrayRef<std::pair<unsigned, AttributeSetNode*> >( |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 793 | std::make_pair(ReturnIndex, |
| 794 | getAttributes(ReturnIndex)))) : |
| 795 | AttributeSet(); |
| 796 | } |
| 797 | |
| 798 | AttributeSet AttributeSet::getFnAttributes() const { |
| 799 | return pImpl && hasAttributes(FunctionIndex) ? |
| 800 | AttributeSet::get(pImpl->getContext(), |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 801 | ArrayRef<std::pair<unsigned, AttributeSetNode*> >( |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 802 | std::make_pair(FunctionIndex, |
| 803 | getAttributes(FunctionIndex)))) : |
| 804 | AttributeSet(); |
| 805 | } |
| 806 | |
| 807 | bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{ |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 808 | AttributeSetNode *ASN = getAttributes(Index); |
| 809 | return ASN ? ASN->hasAttribute(Kind) : false; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Bill Wendling | 0e9d5d0 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 812 | bool AttributeSet::hasAttribute(unsigned Index, StringRef Kind) const { |
| 813 | AttributeSetNode *ASN = getAttributes(Index); |
| 814 | return ASN ? ASN->hasAttribute(Kind) : false; |
| 815 | } |
| 816 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 817 | bool AttributeSet::hasAttributes(unsigned Index) const { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 818 | AttributeSetNode *ASN = getAttributes(Index); |
| 819 | return ASN ? ASN->hasAttributes() : false; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | /// \brief Return true if the specified attribute is set for at least one |
| 823 | /// parameter or for the return value. |
| 824 | bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const { |
| 825 | if (pImpl == 0) return false; |
| 826 | |
| 827 | for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 828 | for (AttributeSetImpl::iterator II = pImpl->begin(I), |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 829 | IE = pImpl->end(I); II != IE; ++II) |
NAKAMURA Takumi | eddab15 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 830 | if (II->hasAttribute(Attr)) |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 831 | return true; |
| 832 | |
| 833 | return false; |
| 834 | } |
| 835 | |
Bill Wendling | 0e9d5d0 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 836 | Attribute AttributeSet::getAttribute(unsigned Index, |
| 837 | Attribute::AttrKind Kind) const { |
| 838 | AttributeSetNode *ASN = getAttributes(Index); |
| 839 | return ASN ? ASN->getAttribute(Kind) : Attribute(); |
| 840 | } |
| 841 | |
| 842 | Attribute AttributeSet::getAttribute(unsigned Index, |
| 843 | StringRef Kind) const { |
| 844 | AttributeSetNode *ASN = getAttributes(Index); |
| 845 | return ASN ? ASN->getAttribute(Kind) : Attribute(); |
| 846 | } |
| 847 | |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 848 | unsigned AttributeSet::getParamAlignment(unsigned Index) const { |
| 849 | AttributeSetNode *ASN = getAttributes(Index); |
| 850 | return ASN ? ASN->getAlignment() : 0; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | unsigned AttributeSet::getStackAlignment(unsigned Index) const { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 854 | AttributeSetNode *ASN = getAttributes(Index); |
| 855 | return ASN ? ASN->getStackAlignment() : 0; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Rafael Espindola | aae0298 | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 858 | std::string AttributeSet::getAsString(unsigned Index, |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 859 | bool InAttrGrp) const { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 860 | AttributeSetNode *ASN = getAttributes(Index); |
Rafael Espindola | aae0298 | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 861 | return ASN ? ASN->getAsString(InAttrGrp) : std::string(""); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | /// \brief The attributes for the specified index are returned. |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 865 | AttributeSetNode *AttributeSet::getAttributes(unsigned Index) const { |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 866 | if (!pImpl) return 0; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 867 | |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 868 | // Loop through to find the attribute node we want. |
| 869 | for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 870 | if (pImpl->getSlotIndex(I) == Index) |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 871 | return pImpl->getSlotNode(I); |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 872 | |
Bill Wendling | 606c8e3 | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 873 | return 0; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 876 | AttributeSet::iterator AttributeSet::begin(unsigned Slot) const { |
Bill Wendling | 16c4b3c | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 877 | if (!pImpl) |
| 878 | return ArrayRef<Attribute>().begin(); |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 879 | return pImpl->begin(Slot); |
Bill Wendling | 16c4b3c | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 880 | } |
| 881 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 882 | AttributeSet::iterator AttributeSet::end(unsigned Slot) const { |
Bill Wendling | 16c4b3c | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 883 | if (!pImpl) |
| 884 | return ArrayRef<Attribute>().end(); |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 885 | return pImpl->end(Slot); |
Bill Wendling | 16c4b3c | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 888 | //===----------------------------------------------------------------------===// |
| 889 | // AttributeSet Introspection Methods |
| 890 | //===----------------------------------------------------------------------===// |
| 891 | |
| 892 | /// \brief Return the number of slots used in this attribute list. This is the |
| 893 | /// number of arguments that have an attribute set on them (including the |
| 894 | /// function itself). |
| 895 | unsigned AttributeSet::getNumSlots() const { |
| 896 | return pImpl ? pImpl->getNumAttributes() : 0; |
| 897 | } |
| 898 | |
Rafael Espindola | 76f103e | 2013-04-30 16:53:38 +0000 | [diff] [blame] | 899 | unsigned AttributeSet::getSlotIndex(unsigned Slot) const { |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 900 | assert(pImpl && Slot < pImpl->getNumAttributes() && |
| 901 | "Slot # out of range!"); |
| 902 | return pImpl->getSlotIndex(Slot); |
| 903 | } |
| 904 | |
| 905 | AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const { |
| 906 | assert(pImpl && Slot < pImpl->getNumAttributes() && |
| 907 | "Slot # out of range!"); |
| 908 | return pImpl->getSlotAttributes(Slot); |
| 909 | } |
| 910 | |
| 911 | uint64_t AttributeSet::Raw(unsigned Index) const { |
| 912 | // FIXME: Remove this. |
| 913 | return pImpl ? pImpl->Raw(Index) : 0; |
| 914 | } |
| 915 | |
| 916 | void AttributeSet::dump() const { |
| 917 | dbgs() << "PAL[\n"; |
| 918 | |
| 919 | for (unsigned i = 0, e = getNumSlots(); i < e; ++i) { |
| 920 | uint64_t Index = getSlotIndex(i); |
| 921 | dbgs() << " { "; |
| 922 | if (Index == ~0U) |
| 923 | dbgs() << "~0U"; |
| 924 | else |
| 925 | dbgs() << Index; |
| 926 | dbgs() << " => " << getAsString(Index) << " }\n"; |
| 927 | } |
| 928 | |
| 929 | dbgs() << "]\n"; |
| 930 | } |
| 931 | |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 932 | //===----------------------------------------------------------------------===// |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 933 | // AttrBuilder Method Implementations |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 934 | //===----------------------------------------------------------------------===// |
| 935 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 936 | AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index) |
Benjamin Kramer | c835b8c | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 937 | : Attrs(0), Alignment(0), StackAlignment(0) { |
Bill Wendling | ec25898 | 2013-01-27 21:23:46 +0000 | [diff] [blame] | 938 | AttributeSetImpl *pImpl = AS.pImpl; |
Bill Wendling | a90a99a | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 939 | if (!pImpl) return; |
| 940 | |
Bill Wendling | 73bc452 | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 941 | for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) { |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 942 | if (pImpl->getSlotIndex(I) != Index) continue; |
Bill Wendling | a90a99a | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 943 | |
Benjamin Kramer | e22cde0 | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 944 | for (AttributeSetImpl::iterator II = pImpl->begin(I), |
Bill Wendling | 73bc452 | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 945 | IE = pImpl->end(I); II != IE; ++II) |
Bill Wendling | 39da078 | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 946 | addAttribute(*II); |
Bill Wendling | 73bc452 | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 947 | |
| 948 | break; |
| 949 | } |
Bill Wendling | a90a99a | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 952 | void AttrBuilder::clear() { |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 953 | Attrs.reset(); |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 954 | Alignment = StackAlignment = 0; |
| 955 | } |
| 956 | |
| 957 | AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) { |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 958 | assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!"); |
Bill Wendling | 169d527 | 2013-01-31 23:16:25 +0000 | [diff] [blame] | 959 | assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment && |
| 960 | "Adding alignment attribute without adding alignment value!"); |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 961 | Attrs[Val] = true; |
Bill Wendling | 3a106e6 | 2012-10-09 19:01:18 +0000 | [diff] [blame] | 962 | return *this; |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 963 | } |
| 964 | |
Bill Wendling | 39da078 | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 965 | AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) { |
Bill Wendling | 09ed910 | 2013-02-10 10:13:23 +0000 | [diff] [blame] | 966 | if (Attr.isStringAttribute()) { |
| 967 | addAttribute(Attr.getKindAsString(), Attr.getValueAsString()); |
| 968 | return *this; |
| 969 | } |
| 970 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 971 | Attribute::AttrKind Kind = Attr.getKindAsEnum(); |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 972 | Attrs[Kind] = true; |
Bill Wendling | 49f6060 | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 973 | |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 974 | if (Kind == Attribute::Alignment) |
Bill Wendling | 49f6060 | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 975 | Alignment = Attr.getAlignment(); |
Bill Wendling | 8c74ecf | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 976 | else if (Kind == Attribute::StackAlignment) |
Bill Wendling | 49f6060 | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 977 | StackAlignment = Attr.getStackAlignment(); |
| 978 | return *this; |
| 979 | } |
| 980 | |
Bill Wendling | ea59f89 | 2013-02-05 08:09:32 +0000 | [diff] [blame] | 981 | AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) { |
| 982 | TargetDepAttrs[A] = V; |
| 983 | return *this; |
| 984 | } |
| 985 | |
Bill Wendling | 39da078 | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 986 | AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 987 | assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!"); |
| 988 | Attrs[Val] = false; |
Bill Wendling | 39da078 | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 989 | |
| 990 | if (Val == Attribute::Alignment) |
| 991 | Alignment = 0; |
| 992 | else if (Val == Attribute::StackAlignment) |
| 993 | StackAlignment = 0; |
| 994 | |
| 995 | return *this; |
| 996 | } |
| 997 | |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 998 | AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) { |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 999 | unsigned Slot = ~0U; |
Bill Wendling | 30d2c76 | 2013-02-01 00:13:50 +0000 | [diff] [blame] | 1000 | for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I) |
| 1001 | if (A.getSlotIndex(I) == Index) { |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1002 | Slot = I; |
Bill Wendling | 30d2c76 | 2013-02-01 00:13:50 +0000 | [diff] [blame] | 1003 | break; |
Bill Wendling | 49f6060 | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1004 | } |
Bill Wendling | 30d2c76 | 2013-02-01 00:13:50 +0000 | [diff] [blame] | 1005 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1006 | assert(Slot != ~0U && "Couldn't find index in AttributeSet!"); |
Bill Wendling | 30d2c76 | 2013-02-01 00:13:50 +0000 | [diff] [blame] | 1007 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1008 | for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); I != E; ++I) { |
Bill Wendling | 74fe825 | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1009 | Attribute Attr = *I; |
| 1010 | if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) { |
| 1011 | Attribute::AttrKind Kind = I->getKindAsEnum(); |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1012 | Attrs[Kind] = false; |
Bill Wendling | 30d2c76 | 2013-02-01 00:13:50 +0000 | [diff] [blame] | 1013 | |
Bill Wendling | 74fe825 | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1014 | if (Kind == Attribute::Alignment) |
| 1015 | Alignment = 0; |
| 1016 | else if (Kind == Attribute::StackAlignment) |
| 1017 | StackAlignment = 0; |
| 1018 | } else { |
| 1019 | assert(Attr.isStringAttribute() && "Invalid attribute type!"); |
| 1020 | std::map<std::string, std::string>::iterator |
| 1021 | Iter = TargetDepAttrs.find(Attr.getKindAsString()); |
| 1022 | if (Iter != TargetDepAttrs.end()) |
| 1023 | TargetDepAttrs.erase(Iter); |
| 1024 | } |
Bill Wendling | 49f6060 | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | return *this; |
| 1028 | } |
| 1029 | |
Bill Wendling | ea59f89 | 2013-02-05 08:09:32 +0000 | [diff] [blame] | 1030 | AttrBuilder &AttrBuilder::removeAttribute(StringRef A) { |
| 1031 | std::map<std::string, std::string>::iterator I = TargetDepAttrs.find(A); |
| 1032 | if (I != TargetDepAttrs.end()) |
| 1033 | TargetDepAttrs.erase(I); |
| 1034 | return *this; |
| 1035 | } |
| 1036 | |
Bill Wendling | 702cc91 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 1037 | AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) { |
Bill Wendling | da3f9d8 | 2012-10-14 03:58:29 +0000 | [diff] [blame] | 1038 | if (Align == 0) return *this; |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1039 | |
Bill Wendling | e66f3d3 | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 1040 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 1041 | assert(Align <= 0x40000000 && "Alignment too large."); |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1042 | |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1043 | Attrs[Attribute::Alignment] = true; |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1044 | Alignment = Align; |
Bill Wendling | da3f9d8 | 2012-10-14 03:58:29 +0000 | [diff] [blame] | 1045 | return *this; |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1048 | AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align) { |
| 1049 | // Default alignment, allow the target to define how to align it. |
| 1050 | if (Align == 0) return *this; |
| 1051 | |
| 1052 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 1053 | assert(Align <= 0x100 && "Alignment too large."); |
| 1054 | |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1055 | Attrs[Attribute::StackAlignment] = true; |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1056 | StackAlignment = Align; |
| 1057 | return *this; |
| 1058 | } |
| 1059 | |
Bill Wendling | 85df6b4 | 2013-02-06 01:16:00 +0000 | [diff] [blame] | 1060 | AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) { |
| 1061 | // FIXME: What if both have alignments, but they don't match?! |
| 1062 | if (!Alignment) |
| 1063 | Alignment = B.Alignment; |
| 1064 | |
| 1065 | if (!StackAlignment) |
| 1066 | StackAlignment = B.StackAlignment; |
| 1067 | |
Benjamin Kramer | c835b8c | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 1068 | Attrs |= B.Attrs; |
Bill Wendling | 85df6b4 | 2013-02-06 01:16:00 +0000 | [diff] [blame] | 1069 | |
| 1070 | for (td_const_iterator I = B.TargetDepAttrs.begin(), |
| 1071 | E = B.TargetDepAttrs.end(); I != E; ++I) |
| 1072 | TargetDepAttrs[I->first] = I->second; |
| 1073 | |
| 1074 | return *this; |
| 1075 | } |
| 1076 | |
Bill Wendling | c342d9d | 2013-02-06 01:33:42 +0000 | [diff] [blame] | 1077 | bool AttrBuilder::contains(StringRef A) const { |
| 1078 | return TargetDepAttrs.find(A) != TargetDepAttrs.end(); |
| 1079 | } |
| 1080 | |
Bill Wendling | 702cc91 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 1081 | bool AttrBuilder::hasAttributes() const { |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1082 | return !Attrs.none() || !TargetDepAttrs.empty(); |
Bill Wendling | f385f4c | 2012-10-08 23:27:46 +0000 | [diff] [blame] | 1083 | } |
Bill Wendling | 60507d5 | 2013-01-04 20:54:35 +0000 | [diff] [blame] | 1084 | |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 1085 | bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const { |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1086 | unsigned Slot = ~0U; |
Bill Wendling | bdcbccc | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1087 | for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I) |
| 1088 | if (A.getSlotIndex(I) == Index) { |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1089 | Slot = I; |
Bill Wendling | bdcbccc | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1090 | break; |
| 1091 | } |
| 1092 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1093 | assert(Slot != ~0U && "Couldn't find the index!"); |
Bill Wendling | bdcbccc | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1094 | |
Bill Wendling | 8a6a7bb | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1095 | for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); |
Bill Wendling | 74fe825 | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1096 | I != E; ++I) { |
| 1097 | Attribute Attr = *I; |
| 1098 | if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) { |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1099 | if (Attrs[I->getKindAsEnum()]) |
Bill Wendling | 74fe825 | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1100 | return true; |
| 1101 | } else { |
| 1102 | assert(Attr.isStringAttribute() && "Invalid attribute kind!"); |
| 1103 | return TargetDepAttrs.find(Attr.getKindAsString())!=TargetDepAttrs.end(); |
| 1104 | } |
| 1105 | } |
Bill Wendling | bdcbccc | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1106 | |
| 1107 | return false; |
Bill Wendling | 8831c06 | 2012-10-09 00:01:21 +0000 | [diff] [blame] | 1108 | } |
Bill Wendling | 60507d5 | 2013-01-04 20:54:35 +0000 | [diff] [blame] | 1109 | |
Bill Wendling | 702cc91 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 1110 | bool AttrBuilder::hasAlignmentAttr() const { |
Bill Wendling | 0319888 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1111 | return Alignment != 0; |
Bill Wendling | f385f4c | 2012-10-08 23:27:46 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1114 | bool AttrBuilder::operator==(const AttrBuilder &B) { |
Benjamin Kramer | c835b8c | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 1115 | if (Attrs != B.Attrs) |
| 1116 | return false; |
Bill Wendling | c342d9d | 2013-02-06 01:33:42 +0000 | [diff] [blame] | 1117 | |
| 1118 | for (td_const_iterator I = TargetDepAttrs.begin(), |
| 1119 | E = TargetDepAttrs.end(); I != E; ++I) |
| 1120 | if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end()) |
| 1121 | return false; |
| 1122 | |
| 1123 | return Alignment == B.Alignment && StackAlignment == B.StackAlignment; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) { |
Bill Wendling | f9271ea | 2013-02-04 23:32:23 +0000 | [diff] [blame] | 1127 | // FIXME: Remove this in 4.0. |
Bill Wendling | 8232ece | 2013-01-29 01:43:29 +0000 | [diff] [blame] | 1128 | if (!Val) return *this; |
| 1129 | |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1130 | for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; |
| 1131 | I = Attribute::AttrKind(I + 1)) { |
| 1132 | if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) { |
Benjamin Kramer | 3f213e7 | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1133 | Attrs[I] = true; |
Bill Wendling | c22f4aa | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1134 | |
| 1135 | if (I == Attribute::Alignment) |
| 1136 | Alignment = 1ULL << ((A >> 16) - 1); |
| 1137 | else if (I == Attribute::StackAlignment) |
| 1138 | StackAlignment = 1ULL << ((A >> 26)-1); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | return *this; |
| 1143 | } |
| 1144 | |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1145 | //===----------------------------------------------------------------------===// |
| 1146 | // AttributeFuncs Function Defintions |
| 1147 | //===----------------------------------------------------------------------===// |
| 1148 | |
Bill Wendling | 7beee28 | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 1149 | /// \brief Which attributes cannot be applied to a type. |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 1150 | AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) { |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1151 | AttrBuilder Incompatible; |
| 1152 | |
| 1153 | if (!Ty->isIntegerTy()) |
| 1154 | // Attribute that only apply to integers. |
| 1155 | Incompatible.addAttribute(Attribute::SExt) |
| 1156 | .addAttribute(Attribute::ZExt); |
| 1157 | |
| 1158 | if (!Ty->isPointerTy()) |
| 1159 | // Attribute that only apply to pointers. |
| 1160 | Incompatible.addAttribute(Attribute::ByVal) |
| 1161 | .addAttribute(Attribute::Nest) |
| 1162 | .addAttribute(Attribute::NoAlias) |
| 1163 | .addAttribute(Attribute::NoCapture) |
Nick Lewycky | dc89737 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 1164 | .addAttribute(Attribute::ReadNone) |
| 1165 | .addAttribute(Attribute::ReadOnly) |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1166 | .addAttribute(Attribute::StructRet); |
| 1167 | |
Bill Wendling | e743654 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 1168 | return AttributeSet::get(Ty->getContext(), Index, Incompatible); |
Bill Wendling | 8e47daf | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1169 | } |