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