Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1 | //===-- Attributes.cpp - Implement AttributesList -------------------------===// |
Chris Lattner | 3e13b8c | 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 | // |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 10 | // This file implements the AttributesList class and Attribute utilities. |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Devang Patel | ba3fa6c | 2008-09-23 23:03:40 +0000 | [diff] [blame] | 14 | #include "llvm/Attributes.h" |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 15 | #include "AttributesImpl.h" |
| 16 | #include "LLVMContextImpl.h" |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 17 | #include "llvm/Type.h" |
Dan Gohman | fc42961 | 2008-03-10 23:55:07 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/FoldingSet.h" |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Atomic.h" |
| 21 | #include "llvm/Support/Mutex.h" |
David Greene | f701473 | 2010-01-05 01:29:58 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Debug.h" |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ManagedStatic.h" |
Benjamin Kramer | 1a25d73 | 2009-08-23 11:37:21 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 28 | // Attribute Function Definitions |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 29 | //===----------------------------------------------------------------------===// |
Chris Lattner | d0e1f10 | 2008-01-03 00:10:22 +0000 | [diff] [blame] | 30 | |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame^] | 31 | bool Attributes::hasAddressSafetyAttr() const { |
| 32 | return Bits & Attribute::AddressSafety_i; |
| 33 | } |
| 34 | bool Attributes::hasAlignmentAttr() const { |
| 35 | return Bits & Attribute::Alignment_i; |
| 36 | } |
| 37 | bool Attributes::hasAlwaysInlineAttr() const { |
| 38 | return Bits & Attribute::AlwaysInline_i; |
| 39 | } |
| 40 | bool Attributes::hasByValAttr() const { |
| 41 | return Bits & Attribute::ByVal_i; |
| 42 | } |
| 43 | bool Attributes::hasInlineHintAttr() const { |
| 44 | return Bits & Attribute::InlineHint_i; |
| 45 | } |
| 46 | bool Attributes::hasInRegAttr() const { |
| 47 | return Bits & Attribute::InReg_i; |
| 48 | } |
| 49 | bool Attributes::hasNakedAttr() const { |
| 50 | return Bits & Attribute::Naked_i; |
| 51 | } |
| 52 | bool Attributes::hasNestAttr() const { |
| 53 | return Bits & Attribute::Nest_i; |
| 54 | } |
| 55 | bool Attributes::hasNoAliasAttr() const { |
| 56 | return Bits & Attribute::NoAlias_i; |
| 57 | } |
| 58 | bool Attributes::hasNoCaptureAttr() const { |
| 59 | return Bits & Attribute::NoCapture_i; |
| 60 | } |
| 61 | bool Attributes::hasNoImplicitFloatAttr() const { |
| 62 | return Bits & Attribute::NoImplicitFloat_i; |
| 63 | } |
| 64 | bool Attributes::hasNoInlineAttr() const { |
| 65 | return Bits & Attribute::NoInline_i; |
| 66 | } |
| 67 | bool Attributes::hasNonLazyBindAttr() const { |
| 68 | return Bits & Attribute::NonLazyBind_i; |
| 69 | } |
| 70 | bool Attributes::hasNoRedZoneAttr() const { |
| 71 | return Bits & Attribute::NoRedZone_i; |
| 72 | } |
| 73 | bool Attributes::hasNoReturnAttr() const { |
| 74 | return Bits & Attribute::NoReturn_i; |
| 75 | } |
| 76 | bool Attributes::hasNoUnwindAttr() const { |
| 77 | return Bits & Attribute::NoUnwind_i; |
| 78 | } |
| 79 | bool Attributes::hasOptimizeForSizeAttr() const { |
| 80 | return Bits & Attribute::OptimizeForSize_i; |
| 81 | } |
| 82 | bool Attributes::hasReadNoneAttr() const { |
| 83 | return Bits & Attribute::ReadNone_i; |
| 84 | } |
| 85 | bool Attributes::hasReadOnlyAttr() const { |
| 86 | return Bits & Attribute::ReadOnly_i; |
| 87 | } |
| 88 | bool Attributes::hasReturnsTwiceAttr() const { |
| 89 | return Bits & Attribute::ReturnsTwice_i; |
| 90 | } |
| 91 | bool Attributes::hasSExtAttr() const { |
| 92 | return Bits & Attribute::SExt_i; |
| 93 | } |
| 94 | bool Attributes::hasStackAlignmentAttr() const { |
| 95 | return Bits & Attribute::StackAlignment_i; |
| 96 | } |
| 97 | bool Attributes::hasStackProtectAttr() const { |
| 98 | return Bits & Attribute::StackProtect_i; |
| 99 | } |
| 100 | bool Attributes::hasStackProtectReqAttr() const { |
| 101 | return Bits & Attribute::StackProtectReq_i; |
| 102 | } |
| 103 | bool Attributes::hasStructRetAttr() const { |
| 104 | return Bits & Attribute::StructRet_i; |
| 105 | } |
| 106 | bool Attributes::hasUWTableAttr() const { |
| 107 | return Bits & Attribute::UWTable_i; |
| 108 | } |
| 109 | bool Attributes::hasZExtAttr() const { |
| 110 | return Bits & Attribute::ZExt_i; |
| 111 | } |
| 112 | |
| 113 | /// This returns the alignment field of an attribute as a byte alignment value. |
| 114 | unsigned Attributes::getAlignment() const { |
| 115 | if (!hasAlignmentAttr()) |
| 116 | return 0; |
| 117 | return 1U << (((Bits & Attribute::Alignment_i) >> 16) - 1); |
| 118 | } |
| 119 | |
| 120 | /// This returns the stack alignment field of an attribute as a byte alignment |
| 121 | /// value. |
| 122 | unsigned Attributes::getStackAlignment() const { |
| 123 | if (!hasStackAlignmentAttr()) |
| 124 | return 0; |
| 125 | return 1U << (((Bits & Attribute::StackAlignment_i) >> 26) - 1); |
| 126 | } |
| 127 | |
| 128 | Attributes Attributes::typeIncompatible(Type *Ty) { |
| 129 | Attributes::Builder Incompatible; |
| 130 | |
| 131 | if (!Ty->isIntegerTy()) { |
| 132 | // Attributes that only apply to integers. |
| 133 | Incompatible.addSExtAttr(); |
| 134 | Incompatible.addZExtAttr(); |
| 135 | } |
| 136 | |
| 137 | if (!Ty->isPointerTy()) { |
| 138 | // Attributes that only apply to pointers. |
| 139 | Incompatible.addByValAttr(); |
| 140 | Incompatible.addNestAttr(); |
| 141 | Incompatible.addNoAliasAttr(); |
| 142 | Incompatible.addNoCaptureAttr(); |
| 143 | Incompatible.addStructRetAttr(); |
| 144 | } |
| 145 | |
| 146 | return Attributes(Incompatible.Bits); // FIXME: Use Attributes::get(). |
| 147 | } |
| 148 | |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 149 | std::string Attributes::getAsString() const { |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 150 | std::string Result; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 151 | if (hasZExtAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 152 | Result += "zeroext "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 153 | if (hasSExtAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 154 | Result += "signext "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 155 | if (hasNoReturnAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 156 | Result += "noreturn "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 157 | if (hasNoUnwindAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 158 | Result += "nounwind "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 159 | if (hasUWTableAttr()) |
Rafael Espindola | fc9bae6 | 2011-05-25 03:44:17 +0000 | [diff] [blame] | 160 | Result += "uwtable "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 161 | if (hasReturnsTwiceAttr()) |
Rafael Espindola | cc349c8 | 2011-10-03 14:45:37 +0000 | [diff] [blame] | 162 | Result += "returns_twice "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 163 | if (hasInRegAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 164 | Result += "inreg "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 165 | if (hasNoAliasAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 166 | Result += "noalias "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 167 | if (hasNoCaptureAttr()) |
Nick Lewycky | 8d69f48 | 2008-12-19 09:38:31 +0000 | [diff] [blame] | 168 | Result += "nocapture "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 169 | if (hasStructRetAttr()) |
Anton Korobeynikov | c8ce7b08 | 2009-07-17 18:07:26 +0000 | [diff] [blame] | 170 | Result += "sret "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 171 | if (hasByValAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 172 | Result += "byval "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 173 | if (hasNestAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 174 | Result += "nest "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 175 | if (hasReadNoneAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 176 | Result += "readnone "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 177 | if (hasReadOnlyAttr()) |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 178 | Result += "readonly "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 179 | if (hasOptimizeForSizeAttr()) |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 180 | Result += "optsize "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 181 | if (hasNoInlineAttr()) |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 182 | Result += "noinline "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 183 | if (hasInlineHintAttr()) |
Jakob Stoklund Olesen | 74bb06c | 2010-02-06 01:16:28 +0000 | [diff] [blame] | 184 | Result += "inlinehint "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 185 | if (hasAlwaysInlineAttr()) |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 186 | Result += "alwaysinline "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 187 | if (hasStackProtectAttr()) |
Bill Wendling | ccb67a3d | 2008-11-13 01:02:14 +0000 | [diff] [blame] | 188 | Result += "ssp "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 189 | if (hasStackProtectReqAttr()) |
Bill Wendling | ccb67a3d | 2008-11-13 01:02:14 +0000 | [diff] [blame] | 190 | Result += "sspreq "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 191 | if (hasNoRedZoneAttr()) |
Devang Patel | 72a4d2f | 2009-06-04 22:05:33 +0000 | [diff] [blame] | 192 | Result += "noredzone "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 193 | if (hasNoImplicitFloatAttr()) |
Devang Patel | d1c7d34 | 2009-06-05 21:57:13 +0000 | [diff] [blame] | 194 | Result += "noimplicitfloat "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 195 | if (hasNakedAttr()) |
Anton Korobeynikov | c8ce7b08 | 2009-07-17 18:07:26 +0000 | [diff] [blame] | 196 | Result += "naked "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 197 | if (hasNonLazyBindAttr()) |
John McCall | 4b7a8d6 | 2011-06-15 20:36:13 +0000 | [diff] [blame] | 198 | Result += "nonlazybind "; |
Bill Wendling | de74cf5 | 2012-09-20 14:44:42 +0000 | [diff] [blame] | 199 | if (hasAddressSafetyAttr()) |
Kostya Serebryany | a5054ad | 2012-01-20 17:56:17 +0000 | [diff] [blame] | 200 | Result += "address_safety "; |
Bill Wendling | b4e211c | 2012-09-20 15:20:36 +0000 | [diff] [blame] | 201 | if (hasStackAlignmentAttr()) { |
Charles Davis | be5557e | 2010-02-12 00:31:15 +0000 | [diff] [blame] | 202 | Result += "alignstack("; |
Bill Wendling | 9be7759 | 2012-09-21 15:26:31 +0000 | [diff] [blame] | 203 | Result += utostr(getStackAlignment()); |
Charles Davis | be5557e | 2010-02-12 00:31:15 +0000 | [diff] [blame] | 204 | Result += ") "; |
| 205 | } |
Bill Wendling | b4e211c | 2012-09-20 15:20:36 +0000 | [diff] [blame] | 206 | if (hasAlignmentAttr()) { |
Dale Johannesen | 11a555e | 2008-02-19 23:51:49 +0000 | [diff] [blame] | 207 | Result += "align "; |
Bill Wendling | 9be7759 | 2012-09-21 15:26:31 +0000 | [diff] [blame] | 208 | Result += utostr(getAlignment()); |
Dale Johannesen | 11a555e | 2008-02-19 23:51:49 +0000 | [diff] [blame] | 209 | Result += " "; |
| 210 | } |
Dan Gohman | 1a70bcc | 2008-08-05 15:51:44 +0000 | [diff] [blame] | 211 | // Trim the trailing space. |
Nick Lewycky | 8d69f48 | 2008-12-19 09:38:31 +0000 | [diff] [blame] | 212 | assert(!Result.empty() && "Unknown attribute!"); |
Dan Gohman | 1a70bcc | 2008-08-05 15:51:44 +0000 | [diff] [blame] | 213 | Result.erase(Result.end()-1); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 214 | return Result; |
| 215 | } |
| 216 | |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame^] | 217 | //===----------------------------------------------------------------------===// |
| 218 | // Attributes::Builder Implementation |
| 219 | //===----------------------------------------------------------------------===// |
| 220 | |
| 221 | void Attributes::Builder::addAddressSafetyAttr() { |
| 222 | Bits |= Attribute::AddressSafety_i; |
| 223 | } |
| 224 | void Attributes::Builder::addAlwaysInlineAttr() { |
| 225 | Bits |= Attribute::AlwaysInline_i; |
| 226 | } |
| 227 | void Attributes::Builder::addByValAttr() { |
| 228 | Bits |= Attribute::ByVal_i; |
| 229 | } |
| 230 | void Attributes::Builder::addInlineHintAttr() { |
| 231 | Bits |= Attribute::InlineHint_i; |
| 232 | } |
| 233 | void Attributes::Builder::addInRegAttr() { |
| 234 | Bits |= Attribute::InReg_i; |
| 235 | } |
| 236 | void Attributes::Builder::addNakedAttr() { |
| 237 | Bits |= Attribute::Naked_i; |
| 238 | } |
| 239 | void Attributes::Builder::addNestAttr() { |
| 240 | Bits |= Attribute::Nest_i; |
| 241 | } |
| 242 | void Attributes::Builder::addNoAliasAttr() { |
| 243 | Bits |= Attribute::NoAlias_i; |
| 244 | } |
| 245 | void Attributes::Builder::addNoCaptureAttr() { |
| 246 | Bits |= Attribute::NoCapture_i; |
| 247 | } |
| 248 | void Attributes::Builder::addNoImplicitFloatAttr() { |
| 249 | Bits |= Attribute::NoImplicitFloat_i; |
| 250 | } |
| 251 | void Attributes::Builder::addNoInlineAttr() { |
| 252 | Bits |= Attribute::NoInline_i; |
| 253 | } |
| 254 | void Attributes::Builder::addNonLazyBindAttr() { |
| 255 | Bits |= Attribute::NonLazyBind_i; |
| 256 | } |
| 257 | void Attributes::Builder::addNoRedZoneAttr() { |
| 258 | Bits |= Attribute::NoRedZone_i; |
| 259 | } |
| 260 | void Attributes::Builder::addNoReturnAttr() { |
| 261 | Bits |= Attribute::NoReturn_i; |
| 262 | } |
| 263 | void Attributes::Builder::addNoUnwindAttr() { |
| 264 | Bits |= Attribute::NoUnwind_i; |
| 265 | } |
| 266 | void Attributes::Builder::addOptimizeForSizeAttr() { |
| 267 | Bits |= Attribute::OptimizeForSize_i; |
| 268 | } |
| 269 | void Attributes::Builder::addReadNoneAttr() { |
| 270 | Bits |= Attribute::ReadNone_i; |
| 271 | } |
| 272 | void Attributes::Builder::addReadOnlyAttr() { |
| 273 | Bits |= Attribute::ReadOnly_i; |
| 274 | } |
| 275 | void Attributes::Builder::addReturnsTwiceAttr() { |
| 276 | Bits |= Attribute::ReturnsTwice_i; |
| 277 | } |
| 278 | void Attributes::Builder::addSExtAttr() { |
| 279 | Bits |= Attribute::SExt_i; |
| 280 | } |
| 281 | void Attributes::Builder::addStackProtectAttr() { |
| 282 | Bits |= Attribute::StackProtect_i; |
| 283 | } |
| 284 | void Attributes::Builder::addStackProtectReqAttr() { |
| 285 | Bits |= Attribute::StackProtectReq_i; |
| 286 | } |
| 287 | void Attributes::Builder::addStructRetAttr() { |
| 288 | Bits |= Attribute::StructRet_i; |
| 289 | } |
| 290 | void Attributes::Builder::addUWTableAttr() { |
| 291 | Bits |= Attribute::UWTable_i; |
| 292 | } |
| 293 | void Attributes::Builder::addZExtAttr() { |
| 294 | Bits |= Attribute::ZExt_i; |
| 295 | } |
| 296 | |
| 297 | void Attributes::Builder::addAlignmentAttr(unsigned Align) { |
| 298 | if (Align == 0) return; |
| 299 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 300 | assert(Align <= 0x40000000 && "Alignment too large."); |
| 301 | Bits |= (Log2_32(Align) + 1) << 16; |
| 302 | } |
| 303 | void Attributes::Builder::addStackAlignmentAttr(unsigned Align) { |
| 304 | // Default alignment, allow the target to define how to align it. |
| 305 | if (Align == 0) return; |
| 306 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 307 | assert(Align <= 0x100 && "Alignment too large."); |
| 308 | Bits |= (Log2_32(Align) + 1) << 26; |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 311 | //===----------------------------------------------------------------------===// |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 312 | // AttributeImpl Definition |
| 313 | //===----------------------------------------------------------------------===// |
| 314 | |
| 315 | Attributes::Attributes(AttributesImpl *A) : Bits(0) {} |
| 316 | |
| 317 | Attributes Attributes::get(LLVMContext &Context, Attributes::Builder &B) { |
| 318 | // If there are no attributes, return an empty Attributes class. |
| 319 | if (B.Bits == 0) |
| 320 | return Attributes(); |
| 321 | |
| 322 | // Otherwise, build a key to look up the existing attributes. |
| 323 | LLVMContextImpl *pImpl = Context.pImpl; |
| 324 | FoldingSetNodeID ID; |
| 325 | ID.AddInteger(B.Bits); |
| 326 | |
| 327 | void *InsertPoint; |
| 328 | AttributesImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); |
| 329 | |
| 330 | if (!PA) { |
| 331 | // If we didn't find any existing attributes of the same shape then create a |
| 332 | // new one and insert it. |
| 333 | PA = new AttributesImpl(B.Bits); |
| 334 | pImpl->AttrsSet.InsertNode(PA, InsertPoint); |
| 335 | } |
| 336 | |
| 337 | // Return the AttributesList that we found or created. |
| 338 | return Attributes(PA); |
| 339 | } |
| 340 | |
| 341 | //===----------------------------------------------------------------------===// |
Devang Patel | 0009505 | 2008-09-24 00:29:49 +0000 | [diff] [blame] | 342 | // AttributeListImpl Definition |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 343 | //===----------------------------------------------------------------------===// |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 344 | |
Owen Anderson | 2e83189 | 2010-11-18 18:59:13 +0000 | [diff] [blame] | 345 | namespace llvm { |
| 346 | class AttributeListImpl; |
| 347 | } |
| 348 | |
| 349 | static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists; |
Owen Anderson | 9b14a25 | 2010-11-09 00:27:03 +0000 | [diff] [blame] | 350 | |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 351 | namespace llvm { |
Owen Anderson | 9b14a25 | 2010-11-09 00:27:03 +0000 | [diff] [blame] | 352 | static ManagedStatic<sys::SmartMutex<true> > ALMutex; |
| 353 | |
Devang Patel | 0009505 | 2008-09-24 00:29:49 +0000 | [diff] [blame] | 354 | class AttributeListImpl : public FoldingSetNode { |
Owen Anderson | c1a3a47 | 2009-08-20 19:03:20 +0000 | [diff] [blame] | 355 | sys::cas_flag RefCount; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 356 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 357 | // AttributesList is uniqued, these should not be publicly available. |
Craig Topper | b1d83e8 | 2012-09-18 02:01:41 +0000 | [diff] [blame] | 358 | void operator=(const AttributeListImpl &) LLVM_DELETED_FUNCTION; |
| 359 | AttributeListImpl(const AttributeListImpl &) LLVM_DELETED_FUNCTION; |
Devang Patel | 0009505 | 2008-09-24 00:29:49 +0000 | [diff] [blame] | 360 | ~AttributeListImpl(); // Private implementation |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 361 | public: |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 362 | SmallVector<AttributeWithIndex, 4> Attrs; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 363 | |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 364 | AttributeListImpl(ArrayRef<AttributeWithIndex> attrs) |
| 365 | : Attrs(attrs.begin(), attrs.end()) { |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 366 | RefCount = 0; |
| 367 | } |
| 368 | |
Owen Anderson | 9b14a25 | 2010-11-09 00:27:03 +0000 | [diff] [blame] | 369 | void AddRef() { |
| 370 | sys::SmartScopedLock<true> Lock(*ALMutex); |
| 371 | ++RefCount; |
| 372 | } |
Owen Anderson | c1a3a47 | 2009-08-20 19:03:20 +0000 | [diff] [blame] | 373 | void DropRef() { |
Owen Anderson | 9b14a25 | 2010-11-09 00:27:03 +0000 | [diff] [blame] | 374 | sys::SmartScopedLock<true> Lock(*ALMutex); |
Owen Anderson | 2e83189 | 2010-11-18 18:59:13 +0000 | [diff] [blame] | 375 | if (!AttributesLists.isConstructed()) |
| 376 | return; |
Owen Anderson | 91bfeb1 | 2010-11-09 17:47:10 +0000 | [diff] [blame] | 377 | sys::cas_flag new_val = --RefCount; |
Owen Anderson | 2d33543 | 2010-11-09 17:46:38 +0000 | [diff] [blame] | 378 | if (new_val == 0) |
Owen Anderson | 9b14a25 | 2010-11-09 00:27:03 +0000 | [diff] [blame] | 379 | delete this; |
Owen Anderson | c1a3a47 | 2009-08-20 19:03:20 +0000 | [diff] [blame] | 380 | } |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 381 | |
| 382 | void Profile(FoldingSetNodeID &ID) const { |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 383 | Profile(ID, Attrs); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 384 | } |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 385 | static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){ |
| 386 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { |
| 387 | ID.AddInteger(Attrs[i].Attrs.Raw()); |
| 388 | ID.AddInteger(Attrs[i].Index); |
Kostya Serebryany | a5054ad | 2012-01-20 17:56:17 +0000 | [diff] [blame] | 389 | } |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 390 | } |
| 391 | }; |
| 392 | } |
| 393 | |
Devang Patel | 0009505 | 2008-09-24 00:29:49 +0000 | [diff] [blame] | 394 | AttributeListImpl::~AttributeListImpl() { |
Owen Anderson | 9b14a25 | 2010-11-09 00:27:03 +0000 | [diff] [blame] | 395 | // NOTE: Lock must be acquired by caller. |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 396 | AttributesLists->RemoveNode(this); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 400 | AttrListPtr AttrListPtr::get(ArrayRef<AttributeWithIndex> Attrs) { |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 401 | // If there are no attributes then return a null AttributesList pointer. |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 402 | if (Attrs.empty()) |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 403 | return AttrListPtr(); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 404 | |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 405 | #ifndef NDEBUG |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 406 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { |
Bill Wendling | 9be7759 | 2012-09-21 15:26:31 +0000 | [diff] [blame] | 407 | assert(Attrs[i].Attrs.hasAttributes() && |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 408 | "Pointless attribute!"); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 409 | assert((!i || Attrs[i-1].Index < Attrs[i].Index) && |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 410 | "Misordered AttributesList!"); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 411 | } |
| 412 | #endif |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 413 | |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 414 | // Otherwise, build a key to look up the existing attributes. |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 415 | FoldingSetNodeID ID; |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 416 | AttributeListImpl::Profile(ID, Attrs); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 417 | void *InsertPos; |
Owen Anderson | d91e6b0 | 2009-08-17 17:10:58 +0000 | [diff] [blame] | 418 | |
| 419 | sys::SmartScopedLock<true> Lock(*ALMutex); |
| 420 | |
Devang Patel | 0009505 | 2008-09-24 00:29:49 +0000 | [diff] [blame] | 421 | AttributeListImpl *PAL = |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 422 | AttributesLists->FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 423 | |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 424 | // If we didn't find any existing attributes of the same shape then |
| 425 | // create a new one and insert it. |
| 426 | if (!PAL) { |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 427 | PAL = new AttributeListImpl(Attrs); |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 428 | AttributesLists->InsertNode(PAL, InsertPos); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 429 | } |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 430 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 431 | // Return the AttributesList that we found or created. |
| 432 | return AttrListPtr(PAL); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 435 | |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 436 | //===----------------------------------------------------------------------===// |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 437 | // AttrListPtr Method Implementations |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 438 | //===----------------------------------------------------------------------===// |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 439 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 440 | AttrListPtr::AttrListPtr(AttributeListImpl *LI) : AttrList(LI) { |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 441 | if (LI) LI->AddRef(); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 444 | AttrListPtr::AttrListPtr(const AttrListPtr &P) : AttrList(P.AttrList) { |
| 445 | if (AttrList) AttrList->AddRef(); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 448 | const AttrListPtr &AttrListPtr::operator=(const AttrListPtr &RHS) { |
Owen Anderson | 8dc0b04 | 2010-09-16 00:27:35 +0000 | [diff] [blame] | 449 | sys::SmartScopedLock<true> Lock(*ALMutex); |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 450 | if (AttrList == RHS.AttrList) return *this; |
| 451 | if (AttrList) AttrList->DropRef(); |
| 452 | AttrList = RHS.AttrList; |
| 453 | if (AttrList) AttrList->AddRef(); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 454 | return *this; |
| 455 | } |
| 456 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 457 | AttrListPtr::~AttrListPtr() { |
| 458 | if (AttrList) AttrList->DropRef(); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /// getNumSlots - Return the number of slots used in this attribute list. |
| 462 | /// This is the number of arguments that have an attribute set on them |
| 463 | /// (including the function itself). |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 464 | unsigned AttrListPtr::getNumSlots() const { |
| 465 | return AttrList ? AttrList->Attrs.size() : 0; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 468 | /// getSlot - Return the AttributeWithIndex at the specified slot. This |
| 469 | /// holds a number plus a set of attributes. |
| 470 | const AttributeWithIndex &AttrListPtr::getSlot(unsigned Slot) const { |
| 471 | assert(AttrList && Slot < AttrList->Attrs.size() && "Slot # out of range!"); |
| 472 | return AttrList->Attrs[Slot]; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 476 | /// getAttributes - The attributes for the specified index are |
| 477 | /// returned. Attributes for the result are denoted with Idx = 0. |
Devang Patel | 82fed67 | 2008-09-23 22:35:17 +0000 | [diff] [blame] | 478 | /// Function notes are denoted with idx = ~0. |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 479 | Attributes AttrListPtr::getAttributes(unsigned Idx) const { |
Bill Wendling | 9be7759 | 2012-09-21 15:26:31 +0000 | [diff] [blame] | 480 | if (AttrList == 0) return Attributes(); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 481 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 482 | const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 483 | for (unsigned i = 0, e = Attrs.size(); i != e && Attrs[i].Index <= Idx; ++i) |
| 484 | if (Attrs[i].Index == Idx) |
| 485 | return Attrs[i].Attrs; |
Bill Wendling | 9be7759 | 2012-09-21 15:26:31 +0000 | [diff] [blame] | 486 | |
| 487 | return Attributes(); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /// hasAttrSomewhere - Return true if the specified attribute is set for at |
| 491 | /// least one parameter or for the return value. |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 492 | bool AttrListPtr::hasAttrSomewhere(Attributes Attr) const { |
| 493 | if (AttrList == 0) return false; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 494 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 495 | const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 496 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) |
Bill Wendling | b4e211c | 2012-09-20 15:20:36 +0000 | [diff] [blame] | 497 | if (Attrs[i].Attrs.hasAttributes(Attr)) |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 498 | return true; |
| 499 | return false; |
| 500 | } |
| 501 | |
| 502 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 503 | AttrListPtr AttrListPtr::addAttr(unsigned Idx, Attributes Attrs) const { |
| 504 | Attributes OldAttrs = getAttributes(Idx); |
Dale Johannesen | 11a555e | 2008-02-19 23:51:49 +0000 | [diff] [blame] | 505 | #ifndef NDEBUG |
| 506 | // FIXME it is not obvious how this should work for alignment. |
| 507 | // For now, say we can't change a known alignment. |
Bill Wendling | 9be7759 | 2012-09-21 15:26:31 +0000 | [diff] [blame] | 508 | unsigned OldAlign = OldAttrs.getAlignment(); |
| 509 | unsigned NewAlign = Attrs.getAlignment(); |
Anton Korobeynikov | 18991d7 | 2008-02-20 12:07:57 +0000 | [diff] [blame] | 510 | assert((!OldAlign || !NewAlign || OldAlign == NewAlign) && |
Dale Johannesen | 11a555e | 2008-02-19 23:51:49 +0000 | [diff] [blame] | 511 | "Attempt to change alignment!"); |
| 512 | #endif |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 513 | |
Devang Patel | ba3fa6c | 2008-09-23 23:03:40 +0000 | [diff] [blame] | 514 | Attributes NewAttrs = OldAttrs | Attrs; |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 515 | if (NewAttrs == OldAttrs) |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 516 | return *this; |
| 517 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 518 | SmallVector<AttributeWithIndex, 8> NewAttrList; |
| 519 | if (AttrList == 0) |
| 520 | NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs)); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 521 | else { |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 522 | const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 523 | unsigned i = 0, e = OldAttrList.size(); |
| 524 | // Copy attributes for arguments before this one. |
| 525 | for (; i != e && OldAttrList[i].Index < Idx; ++i) |
| 526 | NewAttrList.push_back(OldAttrList[i]); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 527 | |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 528 | // If there are attributes already at this index, merge them in. |
| 529 | if (i != e && OldAttrList[i].Index == Idx) { |
| 530 | Attrs |= OldAttrList[i].Attrs; |
| 531 | ++i; |
| 532 | } |
| 533 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 534 | NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs)); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 535 | |
| 536 | // Copy attributes for arguments after this one. |
| 537 | NewAttrList.insert(NewAttrList.end(), |
| 538 | OldAttrList.begin()+i, OldAttrList.end()); |
| 539 | } |
| 540 | |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 541 | return get(NewAttrList); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 544 | AttrListPtr AttrListPtr::removeAttr(unsigned Idx, Attributes Attrs) const { |
Dale Johannesen | 11a555e | 2008-02-19 23:51:49 +0000 | [diff] [blame] | 545 | #ifndef NDEBUG |
| 546 | // FIXME it is not obvious how this should work for alignment. |
| 547 | // For now, say we can't pass in alignment, which no current use does. |
Bill Wendling | b4e211c | 2012-09-20 15:20:36 +0000 | [diff] [blame] | 548 | assert(!Attrs.hasAlignmentAttr() && "Attempt to exclude alignment!"); |
Dale Johannesen | 11a555e | 2008-02-19 23:51:49 +0000 | [diff] [blame] | 549 | #endif |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 550 | if (AttrList == 0) return AttrListPtr(); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 551 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 552 | Attributes OldAttrs = getAttributes(Idx); |
Devang Patel | ba3fa6c | 2008-09-23 23:03:40 +0000 | [diff] [blame] | 553 | Attributes NewAttrs = OldAttrs & ~Attrs; |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 554 | if (NewAttrs == OldAttrs) |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 555 | return *this; |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 556 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 557 | SmallVector<AttributeWithIndex, 8> NewAttrList; |
| 558 | const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 559 | unsigned i = 0, e = OldAttrList.size(); |
| 560 | |
| 561 | // Copy attributes for arguments before this one. |
| 562 | for (; i != e && OldAttrList[i].Index < Idx; ++i) |
| 563 | NewAttrList.push_back(OldAttrList[i]); |
| 564 | |
| 565 | // If there are attributes already at this index, merge them in. |
| 566 | assert(OldAttrList[i].Index == Idx && "Attribute isn't set?"); |
| 567 | Attrs = OldAttrList[i].Attrs & ~Attrs; |
| 568 | ++i; |
| 569 | if (Attrs) // If any attributes left for this parameter, add them. |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 570 | NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs)); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 571 | |
| 572 | // Copy attributes for arguments after this one. |
| 573 | NewAttrList.insert(NewAttrList.end(), |
| 574 | OldAttrList.begin()+i, OldAttrList.end()); |
| 575 | |
Chris Lattner | 3cb6f83 | 2012-05-28 01:47:44 +0000 | [diff] [blame] | 576 | return get(NewAttrList); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 579 | void AttrListPtr::dump() const { |
David Greene | f701473 | 2010-01-05 01:29:58 +0000 | [diff] [blame] | 580 | dbgs() << "PAL[ "; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 581 | for (unsigned i = 0; i < getNumSlots(); ++i) { |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 582 | const AttributeWithIndex &PAWI = getSlot(i); |
David Greene | f701473 | 2010-01-05 01:29:58 +0000 | [diff] [blame] | 583 | dbgs() << "{" << PAWI.Index << "," << PAWI.Attrs << "} "; |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 584 | } |
| 585 | |
David Greene | f701473 | 2010-01-05 01:29:58 +0000 | [diff] [blame] | 586 | dbgs() << "]\n"; |
Duncan Sands | 404eb05 | 2008-01-06 18:27:01 +0000 | [diff] [blame] | 587 | } |